Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include "dataio.h"

#define PEDESTAL      255

int main(int argc, char **argv) {

  char fname[200]= {"tmp.out"};
  int type;
  time_t t;

  if(argc<2) {
    printf("Not enough arguments!\n");
    return -1;
  } else {
    sprintf(fname,"%s",argv[1]);
    type=atoi(argv[2]);
  }

  FILE *fp= fopen(fname,"ab");

  switch(type) {
    case RUNREC_ID:
      if(argc<9) {
        printf("Not enough arguments!\n");
      } else {
        RUNREC runrec;  // start header: appears once at the start of the file
        runrec.id = RUNREC_ID;
        runrec.len = sizeof(runrec);
        runrec.fver = 0x10000;
        time(&t);
        runrec.time=t;
        runrec.nev = atoi(argv[3]);
        runrec.ped = PEDESTAL;
        runrec.nx = atoi(argv[4]);
        runrec.x0 = atoi(argv[5]);
        runrec.dx = atoi(argv[6]);
        runrec.ny = atoi(argv[7]);
        runrec.y0 = atoi(argv[8]);
        runrec.dy = atoi(argv[9]);
        printf("Writing header to file %s\n",fname);
        printf("RECID = %u\n",runrec.id);
        printf("Length = %u\n",runrec.len);
        printf("File version = %u\n",runrec.fver);
        printf("Time = %u\n",runrec.time);
        printf("Number of events per step = %u\n",runrec.nev);
        printf("Pedestal = %u\n",runrec.ped);
        printf("Number of steps in X = %d\n",runrec.nx);
        printf("Start position X = %d\n",runrec.x0);
        printf("Step size direction X = %d\n",runrec.dx);
        printf("Number of steps in Y = %d\n",runrec.ny);
        printf("Start position Y = %d\n",runrec.y0);
        printf("Step size direction Y = %d\n",runrec.dy);
        if (fp) fwrite(&runrec, runrec.len,1,fp);
      }
      break;
    case ENDREC_ID:
      ENDREC endrec;  // end header: appears once at the end of the file
      endrec.id = ENDREC_ID;
      endrec.len = sizeof(endrec);
      time(&t);
      endrec.time=t;
      printf("Writing header to file %s\n",fname);
      printf("RECID = %u\n",endrec.id);
      printf("Length = %u\n",endrec.len);
      printf("Time = %u\n",endrec.time);
      if (fp) fwrite(&endrec, endrec.len,1,fp);
      break;
    case POSREC_ID:
      if(argc<8) {
        printf("Not enough arguments!\n");
      } else {
        POSREC posrec;  // position header: appears at every change of position
        posrec.id = POSREC_ID;
        posrec.len = sizeof(posrec);
        time(&t);
        posrec.time=t;
        posrec.ix = atoi(argv[3]);
        posrec.x = atoi(argv[4]);
        posrec.xset = atoi(argv[5]);
        posrec.iy = atoi(argv[6]);
        posrec.y = atoi(argv[7]);
        posrec.yset = atoi(argv[8]);
        printf("Writing header to file %s\n",fname);
        printf("RECID = %u\n",posrec.id);
        printf("Length = %u\n",posrec.len);
        printf("Time = %u\n",posrec.time);
        printf("Iteration X = %d\n",posrec.ix);
        printf("MIKRO Position X = %d\n",posrec.x);
        printf("Set position X = %d\n",posrec.xset);
        printf("Iteration Y = %d\n",posrec.iy);
        printf("MIKRO Position Y = %d\n",posrec.y);
        printf("Set position Y = %d\n",posrec.yset);
        if (fp) fwrite(&posrec, posrec.len,1,fp);
      }
      break;
  }
  fclose(fp);
  return 0;
}