Logo coherent WaveBurst  
Library Reference Guide
Logo
FrDisplay.cc
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Gabriele Vedovato
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 /*---------------------------------------------------------------------------*/
20 /* File: FrDisplay.c Last update: Jun 26, 2011 */
21 /* */
22 /* Copyright (C) 2011, G.Vedovato */
23 /* For the licensing terms see the LICENSE file. */
24 /* For the list of contributors see the history section of the documentation */
25 /*---------------------------------------------------------------------------*/
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <limits.h>
29 #include "FrameL.h"
30 #include <fcntl.h>
31 #include <sys/stat.h>
32 #include <math.h>
33 #include <sys/wait.h>
34 #include <errno.h>
35 #include <unistd.h>
36 #include <sys/time.h>
37 #include <stdio.h>
38 #include <signal.h>
39 #include <sys/param.h>
40 #include <sys/user.h>
41 #include <sys/sysctl.h>
42 #include "Filter.hh"
43 #include "TSystem.h"
44 #include "TString.h"
45 #include "TObjArray.h"
46 #include "TObjString.h"
47 
48 void Help()
49 {
50  printf(" \n"
51  " This program reads frames from one or more input files, and print \n"
52  " the requested information. \n"
53  "-------------------------------------------------------------------- \n"
54  " Syntax is: FrDisplay -i <input file / ldf> \n"
55  " -f <first frame: (run # frame #) or (GPS time)> \n"
56  " -l <last frame: (run # frame #) or (GPS time)> \n"
57  " or length in second \n"
58  " -t <list of tag channels> \n"
59  " -d <debug level> \n"
60  " -c -1 to leave the data uncompressed \n"
61  " -top <number of ADC in the hit-parade> \n"
62  " -x <baudline parameters list> \n"
63  " -o <ldf observatory parameter> \n"
64  " -s <ldf data type parameter> \n"
65  " -k <filter parameters list> \n"
66  " -a <file access mode [s(sequential)/r(random)]> \n"
67  " -h (to get this help) \n"
68  " If one of the next option is there, we do only a partial frame dump\n"
69  " -adc to dump only the FrAdcData information \n"
70  " -sms to dump only the FrSerData information \n"
71  " -proc to dump only the FrProcData information \n"
72  " -sim to dump only the FrSimData information \n"
73  " -sum to dump only the FrSummary information \n"
74  " -stat to dump only the static information \n"
75  " -raw to dump only the raw data information \n"
76  " -event to dump only the FrEvent and FrSimEvent \n"
77  "-------------------------------------------------------------------- \n"
78  " Remarks: \n"
79  " -i : Argument can be one or more file names \n"
80  " -t : Tag is a channel list with wild cards like: ADC122 ADC5* \n"
81  " If a name start by - it is interpreted as an anti-tag \n"
82  " -f -l:These options works only with the debug level > 2 \n"
83  " -d 0: One line per file based on the TOC information \n"
84  " First frame time, file length, time of the first/last event, \n"
85  " -d 1: A few lines per file based on the TOC information \n"
86  " First/last frame time, number of frame in file, missing frame \n"
87  " Count the number of frame elements like ADC, Proc, Sim, Event \n"
88  " Gives the name of few of them and the typical event amplitude \n"
89  " -d 2: More lines per file based on the TOC information \n"
90  " Same as -d 1 plus the full list of channels, event \n"
91  " -d 3: Read the frame to print information \n"
92  " Print the list of all frame (time, length, quality word) \n"
93  " -d 4: Read the frame to print information with more info \n"
94  " Same as -d 3 plus summary information for all channels \n"
95  " Print frame history \n"
96  " -d 5: Read the frame to print information with more info \n"
97  " Same as -d 4 plus a full dump of the channel content... \n"
98  "-------------------------------------------------------------------- \n"
99  "\n");
100 }
101 
102 struct Parameters{
103  char *name; /* input file name */
104  char *tag; /* output tag */
105  char *baudline; /* baudline parameters */
106  char *observatory; /* ldf observatory par */
107  char *datatype; /* ldf data type par */
108  char *filter; /* filter parameters */
109  char *access; /* file access mode */
110  int frun; /* first run to copy */
111  int fframe; /* first frame to copy */
112  int lrun; /* last run to copy */
113  int lframe; /* last frame to copy */
114  double ftime; /* time for the first frame */
115  double ltime; /* time for the last frame */
116  int dType; /* type of dump */
117  int debug; /* debug level */
118  int comp; /* compression level */
119  int nTop; /* number of ADC for the hit parade */
120 };
121 
124 #define UNSET -999
125 #define ADC 0x1
126 #define SMS 0x2
127 #define SIM 0x4
128 #define STAT 0x8
129 #define EVENT 0x10
130 #define SUM 0x20
131 #define RAW 0x40
132 #define PROC 0x80
133 
134 void ReadParameters(int argc, char **argv);
135 void StrCat(char **oldbuf, char *more);
136 
137 double FrVectMax(FrVect *vect, int chId);
138 FrVect* FrVectDumpBinary(FrVect *vect, int fp, int chId, int debugLvl);
139 
140 int StartBaudline(int gpsSec, int gpsNSec, double scale, double sampleRate, char* chname, int nchannel, char* params);
141 void GetBaudlineDateFormat(int gpsSec, int gpsNSec, char* sbdate);
142 int GpsToUnixTime(int gpsSec);
143 int GpsToGpsLeaps(int gpsSec);
144 int System(const char *command);
145 void INThandler(int);
146 pid_t getProcessId(const char * csProcessName);
147 void FrFileDumpBinary(FrFile* file, int fp, double* scale, int nchannel, double sampleRate);
149 
150 struct Parameters Par;
152 char baudline_wNAME[256];
154 char baudline_FFL[256];
155 CWB::Filter* filter[3]={NULL,NULL,NULL};
156 int iglobal[3]={0,0,0};
157 float uscaleby=1;
161 char chnames[3][64]={"","",""};
162 
163 #define MIN_TIME_GAP 256
164 
165 /*--------------------------------------------------------- Main ------------*/
166 int main(int argc, char **argv)
167 /*---------------------------------------------------------------------------*/
168 {FrFile *file;
169  FrameH *frame;
170  FrAdcData *adc;
171  FrSerData *sms;
172  FrProcData *proc;
173  FrSimEvent *simE;
174  FrEvent *evt;
175  FrSimData *sim;
176  FrSummary *sum;
177  double tStart, tEnd, gtime, start, len;
178  double tCurrent=0;
179  double sampleRate = 0.;
180  int fp=0;
181 
182  double scale[3]={0.,0.,0.};
183  int nchannel=0;
184  baudline_rnID=0;
185  baudline_nP=0;
186  signal(SIGINT, INThandler);
187 
188  struct timeval tv;
189  gettimeofday(&tv, NULL);
190  srand(tv.tv_usec);
191  baudline_rnID = rand(); // random name ID
192 
193  TString OS = "";
194  if(TString(gSystem->GetBuildArch()).Contains("linux")) OS="Linux";
195  if(TString(gSystem->GetBuildArch()).Contains("macos")) OS="Darwin";
196  if(OS=="") {cout << "Error : Operative System not supported!!! " << endl;exit(1);}
197 
198  char cmd[256];
199  if(OS=="Linux") sprintf(cmd,"mkdir -p /dev/shm/%s",getlogin());
200  if(OS=="Darwin") sprintf(cmd,"mkdir -p /tmp/%s",getlogin()); //MAC
201  //printf("%s\n",cmd);
202  System(cmd);
203 
204 // workdir=TString(gSystem->Getenv("FRDISPLAY_WORKDIR"));
205 // worksite=TString(gSystem->Getenv("FRDISPLAY_WORKSITE"));
206  char sworkdir[256];
207  sprintf(sworkdir,"%s",getenv("FRDISPLAY_WORKDIR"));
208  workdir=TString(sworkdir);
209  char sworksite[256];
210  sprintf(sworksite,"%s",getenv("FRDISPLAY_WORKSITE"));
211  worksite=TString(sworksite);
212  worksite.ToUpper();
213 
214  /*----------------- Read input arguments -------------------------*/
215 
216  ReadParameters(argc, argv);
217 
218  /*---------------------------- Open the input file(s) ------------*/
219 
220  FrLibSetLvl(Par.debug-3);
221  file = FrFileINew(Par.name);
222  if(file == NULL)
223  {fprintf(stderr,"Cannot open input file %s\n %s",
224  Par.name, FrErrorGetHistory());
225  return(0);}
226  file->compress = Par.comp;
227  file->chkSumFrFlag = FR_YES;
228 
229  /*------------- Table Of Content dump if debugLevel <2 ------------*/
230 
231  if(Par.debug < 3)
232  {FrFileIDumpT(file, stdout, Par.debug+1, Par.tag, Par.ftime, Par.ltime );
233  return(0);}
234  Par.debug -= 2;
235 
236  /*-------------- set the input file(s) to the first frames -------*/
237 
238  if(Par.ftime != 0)
239  {frame = FrameReadT(file, Par.ftime);
240  if(frame == NULL) /* search for the next frame in the requested range */
241  {tStart = FrFileITNextFrame(file, Par.ftime);
242  if(Par.ltime > 100000000) tEnd = Par.ltime;
243  else tEnd = Par.ftime + Par.ltime;
244  if(tStart < tEnd) frame = FrameReadT(file, tStart);}}
245  else if((Par.frun > 0) || (Par.fframe > 0))
246  {frame = FrameReadN(file, Par.frun, Par.fframe);}
247  else{frame = FrameRead(file);}
248  if(frame == NULL) fprintf(stderr,
249  " Cannot read a frame\n %s", FrErrorGetHistory());
250 
251  /*----------------List Channels ----------------------------*/
252 
253  if(Par.debug>2) {
254  if(((Par.dType & ADC) != 0) && (frame->rawData != NULL)) {
255  int nadc=1;
256  for(adc = frame->rawData->firstAdc; adc != NULL; adc=adc->next) {
257  if(adc->sampleRate>50) {
258  if(Par.tag == NULL) {
259  fprintf(stdout," ADC-%4d: %32s - rate: %15.2f - size: %10lu\n",
260  nadc,adc->name,adc->sampleRate,adc->data->nData);
261  } else if (TString(Par.tag).IsDigit()) {
262  if(TString(Par.tag).Atoi()==nadc) {
263  free((char*)(Par.tag));
264  Par.tag=0;
265  StrCat(&(Par.tag),adc->name);
266  }
267  }
268  nadc++;
269  }
270  }
271  if(Par.tag == NULL) exit(0);
272  }
273  if((Par.dType & PROC) != 0) {
274  int nproc=1;
275  for(proc = frame->procData; proc != NULL; proc = proc->next) {
276  if(Par.tag == NULL) {
277  if(proc->data->dx[0]>0)
278  fprintf(stdout," PROC-%4d: %32s - rate: %15.2f - size: %10lu\n",
279  nproc,proc->name,1./proc->data->dx[0],proc->data->nData);
280  } else if (TString(Par.tag).IsDigit()) {
281  if(TString(Par.tag).Atoi()==nproc) {
282  free((char*)(Par.tag));
283  Par.tag=0;
284  StrCat(&(Par.tag),proc->name);
285  }
286  }
287  nproc++;
288  }
289  if(Par.tag == NULL) exit(0);
290  }
291  }
292 
293  /*----------------Start the Main loop ----------------------------*/
294 
295  int cnt=0;
296  TString cfileName="";
297  while(frame != NULL) {
298 
299  FrFileH *fileH=file->current;
300 
301  /*-------------- Check that we are in the limits -----------------*/
302 
303  if(frame->GTimeS+1.e-9*frame->GTimeN > Par.ltime) break;
304  if(frame->run > Par.lrun) break;
305  if((frame->run == Par.lrun ) && (frame->frame > Par.lframe)) break;
306 
307  /*--------------- Output frame with some tag ---------------------*/
308 
309  if(Par.tag != NULL) FrameTag(frame, Par.tag);
310 
311  /*---------------- Zoom the vectors if needed ---------------------*/
312 
313  if(Par.debug > 2)
314  {gtime = frame->GTimeS+1.e-9*frame->GTimeN;
315  if(Par.ftime > gtime || Par.ltime < gtime+frame->dt)
316  {if(Par.ftime > gtime) start = Par.ftime - gtime;
317  else start = 0;
318  if(Par.ltime < gtime+frame->dt) len = Par.ltime - gtime - start;
319  else len = frame->dt - start;
320  if(frame->rawData != NULL)
321  {for(adc = frame->rawData->firstAdc; adc != NULL; adc=adc->next)
322  {FrVectZoomIn(adc->data, start, len);}}
323  for(proc = frame->procData; proc != NULL; proc = proc->next)
324  {FrVectZoomIn(proc->data, start, len);}
325  for(sim = frame->simData; sim != NULL; sim = sim->next)
326  {FrVectZoomIn(sim->data, start, len);}}}
327 
328  /*---------------- Dump the data ----------------------------------*/
329 
330  if(Par.dType == 0)
331  {FrameDump(frame, stdout, Par.debug);
332  if(Par.comp != 0) FrameCompDump(frame, stdout, Par.debug);}
333  else
334  {printf("Frame %d/%d GTimeS=%d\n",frame->run,frame->frame,frame->GTimeS);
335  if(((Par.dType & ADC) != 0) && (frame->rawData != NULL)) {
336  if((fp==0) && (Par.debug > 2)) {
337  int size=0;
338  char chname[64]="";
339  FrAdcData *xadc;
340  for(xadc = frame->rawData->firstAdc; xadc != NULL; xadc=xadc->next) {
341  if(nchannel>2)
342  {printf("Multichannel with num channel gt 3 not allowed !!!\n");exit(1);}
343  if(size==0) {
344  size = xadc->data->nData;
345  } else {
346  if(size!=xadc->data->nData)
347  {printf("Multichannel with different size not allowed !!!\n");exit(1);}
348  }
349  if(sampleRate==0) {
350  sampleRate = xadc->sampleRate;
351  } else {
352  if(sampleRate!=xadc->sampleRate)
353  {printf("Multichannel with different sampleRates not allowed !!!\n");exit(1);}
354  }
355  /*----------------- Init Filter -------------------------*/
356  if(Par.filter!=NULL && filter[nchannel]==NULL) {
357  char sratepar[32];
358  sprintf(sratepar," -s %f ",sampleRate);
359  StrCat(&(Par.filter),sratepar);
360  filter[nchannel] = new CWB::Filter(Par.filter);
361  }
362  scale[nchannel]=FrVectMax(xadc->data,nchannel);
363  if(scale[nchannel]>0) scale[nchannel]=32768./scale[nchannel];
364  for(int j=0;j<nchannel;j++) if(filter[j]!=NULL) filter[j]->Reset();
365  if(nchannel==0)
366  sprintf(chname,"%s",xadc->name);
367  else
368  sprintf(chname,"%s %s",chname,xadc->name);
369 
370  sprintf(chnames[nchannel],"%s",xadc->name);
371  nchannel++;
372  }
373  if(nchannel==0)
374  {printf("The request channel is not present in the frame !!!\n");exit(1);}
375  double scaleby;
376  if(nchannel==1) {
377  scaleby=scale[0]/4.; // (1./4.) to avoid amplitude cut -> glitches
378  scale[0]=1.;
379  } else {
380  for(int j=0;j<nchannel;j++) scale[j]=32768./scale[j];
381  scaleby=32768./4.;
382  }
383  scaleby*=uscaleby;
384  printf("sampleRate %f - scale %e - chname %s - nchannel %d\n",sampleRate,scaleby,chname,nchannel);
385  fp=StartBaudline(frame->GTimeS, frame->GTimeN, scaleby, sampleRate, chname, nchannel, Par.baudline);
386  }
387  if(fAccess==RANDOM) goto END;
388  int nVect=0;
389  FrVect* outVect[3];
390  for(adc = frame->rawData->firstAdc; adc != NULL; adc=adc->next) {
391  outVect[nVect]=FrVectDumpBinary(adc->data, 0, nVect, Par.debug);
392  nVect++;
393  }
394  if(nchannel!=0 && nVect!=nchannel)
395  {printf("Multichannel : num of channels is changed !!!\n");exit(1);}
396  FrVect* dumpVect = FrVectNew1D(const_cast<char*>("dumpVect"), FR_VECT_4R, nVect*outVect[0]->nData, 0, NULL, NULL);
397  float* buffer = (float*)dumpVect->data;
398  //for(int j=0;j<nVect;j++) cout << j << " scale : " << scale[j] << endl;
399  for(int i=0;i<outVect[0]->nData;i++)
400  for(int j=0;j<nVect;j++)
401  buffer[nVect*i+j]=(((float*)outVect[j]->data)[i])/scale[j];
402  for(int j=0;j<nVect;j++) FrVectFree(outVect[j]);
403  write(fp, buffer, sizeof(float)*dumpVect->nData);
404  FrVectFree(dumpVect);
405  }
406  if(((Par.dType & SMS) != 0) && (frame->rawData != NULL))
407  {for(sms = frame->rawData->firstSer; sms != NULL; sms = sms->next)
408  {printf(" SMS: %s Data:%30s\n", sms->name, sms->data);}}
409  if((Par.dType & STAT) != 0)
410  {if(frame->detectProc != NULL)
411  {printf("Detector used for reconstruction:\n");
412  FrDetectorDump(frame->detectProc, stdout, Par.debug);}
413  if(frame->detectSim != NULL)
414  {printf("Detector used for simulation:\n");
415  FrDetectorDump(frame->detectSim, stdout, Par.debug);}}
416  if((Par.dType & SIM) != 0)
417  {for(sim = frame->simData; sim != NULL; sim = sim->next)
418  {FrSimDataDump(sim, stdout, Par.debug);}}
419  if((Par.dType & EVENT) != 0)
420  {for(simE = frame->simEvent; simE != NULL; simE = simE->next)
421  {FrSimEventDump(simE, stdout,Par.debug);}
422  for(evt = frame->event; evt != NULL; evt = evt->next)
423  {FrEventDump(evt, stdout, Par.debug);}}
424  if((Par.dType & PROC) != 0) {
425  if((fp==0) && (Par.debug > 2)) {
426  int size=0;
427  char chname[64]="";
428  for(proc = frame->procData; proc != NULL; proc = proc->next) {
429  printf("Reconstructed Data: %s\n", proc->name);
430  if(nchannel>2)
431  {printf("Multichannel with num channel gt 3 not allowed !!!\n");exit(1);}
432  if(size==0) {
433  size = proc->data->nData;
434  } else {
435  if(size!=proc->data->nData)
436  {printf("Multichannel with different size not allowed !!!\n");exit(1);}
437  }
438  if(sampleRate==0) {
439  if(proc->data->dx[0] < 1) sampleRate = 1./proc->data->dx[0];
440  else {printf("sampleRate not allowed !!!\n");exit(1);}
441  } else {
442  if(sampleRate!=1./proc->data->dx[0])
443  {printf("Multichannel with different sampleRates not allowed !!!\n");exit(1);}
444  }
445  /*----------------- Init Filter -------------------------*/
446  if(Par.filter!=NULL && filter[nchannel]==NULL) {
447  char sratepar[32];
448  sprintf(sratepar," -s %f ",sampleRate);
449  StrCat(&(Par.filter),sratepar);
450  filter[nchannel] = new CWB::Filter(Par.filter);
451  }
452  scale[nchannel]=FrVectMax(proc->data,nchannel);
453  if(scale[nchannel]>0) scale[nchannel]=32768./scale[nchannel];
454  for(int j=0;j<nchannel;j++) if(filter[j]!=NULL) filter[j]->Reset();
455  if(nchannel==0)
456  sprintf(chname,"%s",proc->name);
457  else
458  sprintf(chname,"%s %s",chname,proc->name);
459 
460  sprintf(chnames[nchannel],"%s",proc->name);
461  nchannel++;
462  }
463  if(nchannel==0)
464  {printf("The request channel is not present in the frame !!!\n");exit(1);}
465  double scaleby;
466  if(nchannel==1) {
467  scaleby=scale[0]/4.; // (1./4.) to avoid amplitude cut -> glitches
468  scale[0]=1.;
469  } else {
470  for(int j=0;j<nchannel;j++) scale[j]=32768./scale[j];
471  scaleby=32768./4.;
472  }
473  scaleby*=uscaleby;
474  printf("sampleRate %f - scale %e - chname %s - nchannel %d\n",sampleRate,scaleby,chname,nchannel);
475  fp=StartBaudline(frame->GTimeS, frame->GTimeN, scaleby, sampleRate, chname, nchannel, Par.baudline);
476  }
477  if(fAccess==RANDOM) goto END;
478  int nVect=0;
479  FrVect* outVect[3];
480  for(proc = frame->procData; proc != NULL; proc = proc->next) {
481  outVect[nVect]=FrVectDumpBinary(proc->data, 0, nVect, Par.debug);
482  nVect++;
483  }
484  if(nchannel!=0 && nVect!=nchannel)
485  {printf("Multichannel : num of channels is changed !!!\n");exit(1);}
486  FrVect* dumpVect = FrVectNew1D(const_cast<char*>("dumpVect"), FR_VECT_4R, nVect*outVect[0]->nData, 0, NULL, NULL);
487  float* buffer = (float*)dumpVect->data;
488  //for(int j=0;j<nVect;j++) cout << j << " scale : " << scale[j] << endl;
489  for(int i=0;i<outVect[0]->nData;i++)
490  for(int j=0;j<nVect;j++)
491  buffer[nVect*i+j]=(((float*)outVect[j]->data)[i])/scale[j];
492  for(int j=0;j<nVect;j++) FrVectFree(outVect[j]);
493  write(fp, buffer, sizeof(float)*dumpVect->nData);
494  FrVectFree(dumpVect);
495  }
496  if((Par.dType & SUM) != 0)
497  {for(sum = frame->summaryData; sum != NULL; sum = sum->next)
498  {printf("Summary: %s %s \n",sum->name, sum->comment);
499  FrVectDump( sum->moments, stdout, Par.debug);}}
500  if((Par.dType & RAW) != 0)
501  {FrRawDataDump(frame->rawData, stdout, Par.debug);}}
502 
503  if(Par.debug > 1) FrameStat(frame, stdout);
504 
505  if(Par.nTop != -2) FrameDumpTopADC(frame, stdout, Par.nTop, Par.comp);
506 
507  FrameFree(frame);
508 
509  /*---------------------- read the next frame --------------------*/
510 
511  frame = FrameRead(file);
512 
513  /*------------------End the Main loop ----------------------------*/
514  }
515 
516 END:
517  if(fAccess==RANDOM) FrFileDumpBinary(file,fp,scale,nchannel,sampleRate);
518 
519  FrFileIStat(file, stdout);
520 
521  if(Par.debug > 2) {
522  printf("\n\nhit Ctrl-C\n\n");
523  while (1) pause();
524  }
525  exit(0);
526 }
527 
528  /*------------------Read file in random mode --------------------*/
529 void FrFileDumpBinary(FrFile* file, int fp, double* scale,int nchannel,double sampleRate) {
530 
531  double tCurrent=0;
532 
533  FrFileH *fileH=file->fileH;
534  while(fileH!=NULL) {
535  cout << fileH->fileName << endl;
536 
537  FrVect* outVect[3];
538  for(int nVect=0;nVect<nchannel;nVect++) {
539  FrFile* cfile=FrFileINew(fileH->fileName);
540  FrTOCFFLBuild(cfile);
541  FrFileH *cfileH=cfile->current;
542  double cStart=cfileH->tStart;
543  double cEnd=cfileH->tStart+cfileH->length;
544  if(Par.ftime>cStart) cStart=Par.ftime;
545  if(Par.ltime<cEnd) cEnd=Par.ltime;
546  double clength=cEnd-cStart;
547 
548  if(tCurrent!=0 && nVect==0) {
549  if(cStart!=tCurrent) {
550  cout.precision(14);
551  cout << "tCurrent " << tCurrent << endl;
552  cout << "cStart " << cStart << endl;
553  cout << "cEnd " << cEnd << endl;
554  int nullSize=(cStart-tCurrent)*sampleRate;
555  if(((cStart-tCurrent)<=MIN_TIME_GAP)&&((cStart-tCurrent)>0)) {
556  FrVect* nullVect = FrVectNew1D(const_cast<char*>("NULL"), FR_VECT_4R, nullSize, 0, NULL, NULL);
557  float* dF = (float*)nullVect->data;
558  for(int i=0; i<nullSize; i++) dF[i]-0;;
559  write(fp, dF, sizeof(float)*nullSize);
560  FrVectFree(nullVect);
561  } else {
562  cout << "Error : data not contiguous !!!" << endl;
563  exit(1);
564  }
565  }
566  }
567  tCurrent=cEnd;
568 
569  outVect[nVect]=FrFileIGetVectF(cfile, chnames[nVect], cStart, clength);
570  float* dF = (float *) outVect[nVect]->data;
571  if(filter[nVect]!=NULL) {
572  for(int i=0; i<outVect[nVect]->nData; i++)
573  dF[i]=filter[nVect]->Arma((double)dF[i]);
574  }
575  FrFileIClose(cfile);
576  }
577 
578  FrVect* dumpVect = FrVectNew1D(const_cast<char*>("dumpVect"), FR_VECT_4R, nchannel*outVect[0]->nData, 0, NULL, NULL);
579  float* buffer = (float*)dumpVect->data;
580  //for(int j=0;j<nVect;j++) cout << j << " scale : " << scale[j] << endl;
581  for(int i=0;i<outVect[0]->nData;i++)
582  for(int j=0;j<nchannel;j++)
583  buffer[nchannel*i+j]=(((float*)outVect[j]->data)[i])/scale[j];
584  for(int j=0;j<nchannel;j++) FrVectFree(outVect[j]);
585  write(fp, buffer, sizeof(float)*dumpVect->nData);
586  FrVectFree(dumpVect);
587 
588  fileH=fileH->next;
589  }
590 
591  return;
592 }
593 
594 /*------------------------------------------------------ SetParameters ------*/
595 void ReadParameters(int argc, char **argv)
596 /*---------------------------------------------------------------------------*/
597 {int type, i;
598  char cmd[256];
599 
600  if (argc == 1)
601  {Help();
602  exit(0);}
603 
604  /*-------------------- Get Operative System Type -----------------*/
605 
606  TString OS = "";
607  if(TString(gSystem->GetBuildArch()).Contains("linux")) OS="Linux";
608  if(TString(gSystem->GetBuildArch()).Contains("macos")) OS="Darwin";
609  if(OS=="") {cout << "Error : Operative System not supported!!! " << endl;exit(1);}
610 
611  /*-------------------- Default values ----------------------------*/
612 
613  Par.name = NULL;
614  Par.tag = NULL;
615  Par.debug = 1;
616  Par.comp = 0;
617  Par.ftime = UNSET;
618  Par.ltime = UNSET;
619  Par.frun = UNSET;
620  Par.lrun = UNSET;
621  Par.fframe = UNSET;
622  Par.lframe = UNSET;
623  Par.nTop = -2;
624 
625  /*------------------- Loop over the parameters -------------------*/
626 
627  type = UNSET;
628 
629  for (i=1; i<argc; i++)
630  {if (strcmp(argv[i],"-h") == 0)
631  {Help();
632  exit(0);}
633  else if (strcmp(argv[i],"-i") == 0) {type = INPUT;}
634  else if (strcmp(argv[i],"-t") == 0) {type = TAG;}
635  else if (strcmp(argv[i],"-f") == 0) {type = FIRST;}
636  else if (strcmp(argv[i],"-l") == 0) {type = LAST;}
637  else if (strcmp(argv[i],"-d") == 0) {type = DEBUG;}
638  else if (strcmp(argv[i],"-c") == 0) {type = COMPRESS;}
639  else if (strcmp(argv[i],"-x") == 0) {type = BAUDLINE;}
640  else if (strcmp(argv[i],"-o") == 0) {type = OBSERVATORY;}
641  else if (strcmp(argv[i],"-s") == 0) {type = DATATYPE;}
642  else if (strcmp(argv[i],"-k") == 0) {type = FILTER;}
643  else if (strcmp(argv[i],"-a") == 0) {type = ACCESS;}
644  else if (strcmp(argv[i],"-top") == 0) {type = TOP;}
645  else if (strcmp(argv[i],"-adc") == 0) {Par.dType = Par.dType | ADC;}
646  else if (strcmp(argv[i],"-sms") == 0) {Par.dType = Par.dType | SMS;}
647  else if (strcmp(argv[i],"-stat") == 0) {Par.dType = Par.dType | STAT;}
648  else if (strcmp(argv[i],"-sim") == 0) {Par.dType = Par.dType | SIM;}
649  else if (strcmp(argv[i],"-event") == 0) {Par.dType = Par.dType | EVENT;}
650  else if (strcmp(argv[i],"-proc") == 0) {Par.dType = Par.dType | PROC;}
651  else if (strcmp(argv[i],"-sum") == 0) {Par.dType = Par.dType | SUM;}
652  else if (strcmp(argv[i],"-raw") == 0) {Par.dType = Par.dType | RAW;}
653  else
654  {if(type == INPUT) {StrCat(&(Par.name),argv[i]);}
655  if(type == TAG) {StrCat(&(Par.tag),argv[i]);}
656  if(type == BAUDLINE) {StrCat(&(Par.baudline),argv[i]);}
657  if(type == OBSERVATORY) {StrCat(&(Par.observatory),argv[i]);}
658  if(type == DATATYPE) {StrCat(&(Par.datatype),argv[i]);}
659  if(type == FILTER) {StrCat(&(Par.filter),argv[i]);}
660  if(type == ACCESS) {StrCat(&(Par.access),argv[i]);}
661  if(type == FIRST)
662  {if(Par.ftime == UNSET)
663  {Par.ftime = atof(argv[i]);}
664  else {Par.frun = Par.ftime;
665  Par.fframe = atoi(argv[i]);}}
666  if(type == LAST)
667  {if(Par.ltime == UNSET)
668  {Par.ltime = atof(argv[i]);}
669  else {Par.lrun = Par.ltime;
670  Par.lframe = atoi(argv[i]);}}
671  if(type == DEBUG) {Par.debug = atoi(argv[i]);}
672  if(type == COMPRESS) {Par.comp = atoi(argv[i]);}
673  if(type == TOP) {Par.nTop = atoi(argv[i]);}
674  }}
675 
676  /*------------------ Check start/stop parameters------------------*/
677 
678  if(Par.fframe != UNSET) Par.ftime = 0.;
679  if(Par.lframe != UNSET) Par.ltime = 1.e+12;
680  if(Par.frun == UNSET) Par.frun = 0;
681  if(Par.lrun == UNSET) Par.lrun = INT_MAX;
682  if(Par.fframe == UNSET) Par.fframe = 0;
683  if(Par.lframe == UNSET) Par.lframe = INT_MAX;
684  if(Par.ftime == UNSET) Par.ftime = 0;
685  if(Par.ltime == UNSET) Par.ltime = INT_MAX;
686 
687  /*---------------------------- Check filter help --------------*/
688 
689  if(Par.filter!=NULL) {
690  if(strstr(Par.filter,"help")!=NULL) {
691  printf("filter help !!!\n");
692  CWBFilterHelp();
693  exit(0);
694  }
695  }
696 
697  /*---------------------------- Check baudline help --------------*/
698 
699  if(Par.baudline!=NULL) {
700  if(strstr(Par.baudline,"help")!=NULL) {
701  printf("baudline help !!!\n");
702 
703  char baudline[256];
704  if(getenv("BAUDLINE_CMD")!=NULL) {
705  printf("BAUDLINE_CMD : %s\n",getenv("BAUDLINE_CMD"));
706  sprintf(baudline,"%s",getenv("BAUDLINE_CMD"));}
707  else
708  {printf("Cannot get BAUDLINE_CMD env\n");exit(1);}
709 
710  sprintf(cmd,"%s -help",baudline);
711  printf("%s\n",cmd);
712  System(cmd);
713  exit(0);
714  }
715  }
716 
717  /*---------------------------- Set baudline_rc --------------*/
718 
719  int downmix=0;
720  if(Par.baudline!=NULL) {
721  TObjArray* token = TString(Par.baudline).Tokenize(TString(' '));
722  for(int i=0;i<token->GetEntries();i++) {
723  TObjString* tok = (TObjString*)token->At(i);
724  TString stok = tok->GetString();
725  if(stok.CompareTo("-downmix")==0) {
726  if(i==token->GetEntries()-1) {cout << "error : downmix par without value" << endl;exit(1);}
727  TObjString* vtok = (TObjString*)token->At(i+1);
728  TString svtok = vtok->GetString();
729  if(!svtok.IsFloat()) {cout << "error : downmix par not digit" << endl;exit(1);}
730  downmix = svtok.Atoi();
731  }
732  if(stok.CompareTo("-uscaleby")==0) {
733  if(i==token->GetEntries()-1) {cout << "error : scaleby par without value" << endl;exit(1);}
734  TObjString* vtok = (TObjString*)token->At(i+1);
735  TString svtok = vtok->GetString();
736  if(!svtok.IsFloat()) {cout << "error : scaleby par not digit" << endl;exit(1);}
737  uscaleby = svtok.Atof();
738  // remove scaleby from bauline input string
739  sprintf(Par.baudline,"%s","");
740  for(int j=0;j<token->GetEntries();j++) {
741  TObjString* tok = (TObjString*)token->At(j);
742  TString stok = tok->GetString();
743  if(j!=i && j!=i+1) sprintf(Par.baudline,"%s %s",Par.baudline,stok.Data());
744  }
745  }
746  }
747  }
748 
749  //UserGroup_t* uinfo = gSystem->GetUserInfo();
750  //TString uname = uinfo->fUser;
751  TString uhome=TString(gSystem->Getenv("HOME"));
752  char baudline_rc_path[256];
753  sprintf(baudline_rc_path,"%s/.baudline/baudline_rc",uhome.Data());
754  char baudline_rc_tmp_path[256];
755  sprintf(baudline_rc_tmp_path,"%s/.baudline/baudline_rc.tmp",uhome.Data());
756 
757  Long_t id,size,flags,mt;
758  int estat = gSystem->GetPathInfo(baudline_rc_path,&id,&size,&flags,&mt);
759  if (estat==0) {
760 
761  ifstream in;
762  in.open(baudline_rc_path,ios::in);
763  if (!in.good()) {cout << "Error Opening File : " << baudline_rc_path << endl;exit(1);}
764 
765  ofstream out;
766  out.open(baudline_rc_tmp_path,ios::out);
767  if (!out.good()) {cout << "Error Opening File : " << baudline_rc_tmp_path << endl;exit(1);}
768 
769  bool flag=false;
770  char line[256];
771  int cnt=1;
772  while (1) {
773  in.getline(line,256);
774  if (!in.good()) break;
775  //cout << line << endl;
776  TString sline(line);
777  if(sline.Contains("downmix")) {out << "downmix " << downmix << endl;flag=true;}
778  else out << sline.Data() << endl;
779  }
780  if(!flag) {out << "downmix " << downmix << endl;}
781  in.close();
782  out.close();
783 
784  char cmd[256];
785  sprintf(cmd,"mv %s %s",baudline_rc_tmp_path,baudline_rc_path);
786  gSystem->Exec(cmd);
787  }
788 
789  /*---------------------------- Check access file mode ------------*/
790 
791  if((Par.access!=NULL)&&(strcmp(Par.access,"s"))==0) fAccess=SEQUENTIAL;
792  if((Par.access!=NULL)&&(strcmp(Par.access,"r"))==0) fAccess=RANDOM;
793 
794  /*---------------------------- Check if input is an ffl file -----*/
795 
796  if((Par.name!=NULL)&&(TString(Par.name).Contains(".ffl"))==1) {
797 
798  TString ffl_file_path = gSystem->ExpandPathName(Par.name);
799 
800  ifstream in;
801  in.open(ffl_file_path.Data(),ios::in);
802  if (!in.good()) {cout << "Error Opening File : " << ffl_file_path.Data() << endl;exit(1);}
803 
804  ofstream out;
805  if(OS=="Linux") sprintf(baudline_FFL,"/dev/shm/%s/%d.ffl",getlogin(),baudline_rnID);
806  if(OS=="Darwin") sprintf(baudline_FFL,"/tmp/%s/%d.ffl",getlogin(),baudline_rnID); //MAC
807  out.open(baudline_FFL,ios::out);
808  if (!out.good()) {cout << "Error Opening File : " << baudline_FFL << endl;exit(1);}
809 
810  char file_path[1024];
811  double start;
812  double lenght;
813  double dummy1,dummy2;
814  while (1) {
815  in >> file_path >> start >> lenght >> dummy1 >> dummy2;
816  if (!in.good()) break;
817  out.precision(14);
818  cout.precision(14);
819  if((start>=Par.ftime)&&(start<=Par.ltime)) {
820  //cout << file_path << " " << start << " " << lenght << endl;
821  out << file_path << " " << start << " " << lenght << " " << dummy1 << " " << dummy2 << endl;
822  }
823  }
824  in.close();
825 
826  free((char*)(Par.name));
827  Par.name=0;
828  StrCat(&(Par.name),baudline_FFL);
829  }
830 
831  /*---------------------------- Check gw_data_find --------------*/
832 
833  if((Par.name!=NULL)&&(strcmp(Par.name,"ldf"))==0) {
834  // check if gw_data_find is available
835  int ret=gSystem->Exec("gw_data_find -v");
836  if(ret!=0) {printf("gw_data_find is not available !!!\n");exit(1);}
837  if(Par.datatype!=0) {
838  if(strstr(Par.datatype,"help")!=NULL) {
839  sprintf(cmd,"gw_data_find --show-types ");
840  printf("%s\n",cmd);
841  System(cmd);
842  exit(0);
843  }
844  }
845 
846  if(Par.observatory==0) {printf("parameter observatory -o not defined !!!\n");exit(1);}
847  if(Par.ftime==0) {printf("parameter GPS start -f not defined !!!\n");exit(1);}
848  if(Par.ltime==0) {printf("parameter GPS stop -l not defined !!!\n");exit(1);}
849  if(Par.datatype==0) {printf("parameter data type -s not defined !!!\n");exit(1);}
850 
851  if(OS=="Linux") sprintf(baudline_FFL,"/dev/shm/%s/%d.ffl",getlogin(),baudline_rnID);
852  if(OS=="Darwin") sprintf(baudline_FFL,"/tmp/%s/%d.ffl",getlogin(),baudline_rnID); //MAC
853 
854  sprintf(cmd,"gw_data_find --observatory=%s --type=%s --gps-start-time=%d --gps-end-time=%d --url-type=file | sed -e \'s/file:\\/\\/localhost//g\' > %s",Par.observatory,Par.datatype,(int)Par.ftime,(int)Par.ltime,baudline_FFL);
855  printf("%s\n",cmd);
856  int pid=System(cmd);
857 
858  // check if output command file is empty
859  Long_t xid,xsize,xflags,xmt;
860  int xestat = gSystem->GetPathInfo(baudline_FFL,&xid,&xsize,&xflags,&xmt);
861  if (xestat!=0 || xsize==0) { // if empty then remove temporary file
862  sprintf(cmd,"/bin/rm %s",baudline_FFL);
863  gSystem->Exec(cmd);
864  gSystem->Exit(1);
865  }
866 
867  // get rid of duplicate file names
869 
870  printf("pid %d\n",pid);
871 
872  free((char*)(Par.name));
873  Par.name=0;
874  StrCat(&(Par.name),baudline_FFL);
875  }
876 
877 /*
878  if((Par.tag == NULL)&&(Par.debug>4))
879  {fprintf(stderr," Please provide at least one channel name\n");
880  Help();
881  exit(0);}
882 */
883  if(Par.name == NULL)
884  {fprintf(stderr," Please provide at least one input file\n");
885  Help();
886  exit(0);}
887 
888  /*-------------------------- Dump parameters ---------------------*/
889 
890  if(Par.ltime < Par.ftime) Par.ltime += Par.ftime -1.e-6;
891 
892  if (Par.debug>0)
893  {printf("-----------Parameters used--------------\n");
894  printf(" Input Files: %s\n", Par.name);
895  if(Par.tag != NULL) printf(" Tag : %s\n",Par.tag);
896  printf(" First frame : %d %d (GPS=%.1f)\n",
897  Par.frun,Par.fframe,Par.ftime);
898  if(Par.ltime < 100000000)
899  printf(" Lenght : %.1fs\n", Par.ltime);
900  else printf(" Last frame : %d %d (GPS=%.1f)\n",
901  Par.lrun,Par.lframe,Par.ltime);
902  printf(" Debug level : %d\n", Par.debug);
903  if((Par.dType & ADC) != 0) printf(" Dump adc info\n");
904  if((Par.dType & SMS) != 0) printf(" Dump sms info\n");
905  if((Par.dType & STAT) != 0) printf(" Dump Stat info\n");
906  if((Par.dType & SIM) != 0) printf(" Dump sim info\n");
907  if((Par.dType & EVENT) != 0) printf(" Dump event info\n");
908  if((Par.dType & PROC) != 0) printf(" Dump proc info\n");
909  if((Par.dType & SUM) != 0) printf(" Dump summary info\n");
910  if((Par.dType & RAW) != 0) printf(" Dump raw data info\n");
911  if( Par.dType == 0) printf(" Dump all Frame info\n");
912  printf("----------------------------------------\n");}
913 
914  return;
915 }
916 
917 /*----------------------------------------------------------------- StrCat --*/
918 void StrCat(char **oldbuf, char *more)
919 /*---------------------------------------------------------------------------*/
920 {int lenMore;
921  char *newbuf;
922 
923  lenMore = strlen(more);
924 
925  if(*oldbuf == NULL)
926  {*oldbuf = (char*)malloc(strlen(more) + 1);
927  strcpy(*oldbuf, more);
928  return;}
929 
930  newbuf = (char*)malloc( strlen(*oldbuf) + lenMore + 2);
931  sprintf(newbuf,"%s %s",*oldbuf, more);
932  free(*oldbuf);
933  *oldbuf = newbuf;
934 
935  return;}
936 
937 /*---------------------------------------------------------- StartBaudline --*/
938 int StartBaudline(int gpsSec, int gpsNSec, double scale,
939  double sampleRate, char* chname, int nchannel, char* params) {
940 /*---------------------------------------------------------------------------*/
941  char sbdate[256];
942  GetBaudlineDateFormat(gpsSec, gpsNSec, sbdate);
943  printf("date : %s - chname : %s\n",sbdate,chname);
944  printf("sampleRate %f - scale %e\n",sampleRate,scale);
945 
946  char cmd[1024];
947  int pid;
948 
949  char baudline[256];
950  if(getenv("BAUDLINE_CMD")!=NULL) {
951  printf("BAUDLINE_CMD : %s\n",getenv("BAUDLINE_CMD"));
952  sprintf(baudline,"%s",getenv("BAUDLINE_CMD"));}
953  else
954  {printf("Cannot get BAUDLINE_CMD env\n");exit(1);}
955 
956  char palette[256];
957  if(getenv("BAUDLINE_PALETTE")!=NULL) {
958  printf("BAUDLINE_PALETTE : %s\n",getenv("BAUDLINE_PALETTE"));
959  sprintf(palette,"%s",getenv("BAUDLINE_PALETTE"));}
960  else
961  {printf("Cannot get BAUDLINE_PALETTE env\n");exit(1);}
962 
963  TString OS = "";
964  if(TString(gSystem->GetBuildArch()).Contains("linux")) OS="Linux";
965  if(TString(gSystem->GetBuildArch()).Contains("macos")) OS="Darwin";
966  if(OS=="") {cout << "Error : Operative System not supported!!! " << endl;exit(1);}
967 
968  char pipe_name[256];
969  if(OS=="Linux") sprintf(pipe_name,"/dev/shm/%s/cwb-pipe-%d",getlogin(),baudline_rnID);
970  if(OS=="Darwin") sprintf(pipe_name,"/tmp/%s/cwb-pipe-%d",getlogin(),baudline_rnID); //MAC
971  printf("%s\n",pipe_name);
972  if(OS=="Linux") sprintf(cmd,"mknod %s p",pipe_name);
973  if(OS=="Darwin") sprintf(cmd,"mkfifo %s",pipe_name);
974  printf("%s\n",cmd);
975  pid = System(cmd);
976 
977  if(params==NULL) StrCat(&(params),const_cast<char*>(""));
978 
979  char tsession[256];
980  sprintf(tsession,"\"%s - %s - ID%d\"",chname,FrStrUTC(gpsSec,0),baudline_rnID);
981 
982  sprintf(baudline_wNAME,"%s-%s-ID%d",chname,FrStrUTC(gpsSec,0),baudline_rnID);
983  int i;
984  for(i=0;i<strlen(baudline_wNAME);i++) if(baudline_wNAME[i]==' ') baudline_wNAME[i]='_';
985  for(i=0;i<strlen(baudline_wNAME);i++) if(baudline_wNAME[i]==':') baudline_wNAME[i]='_';
986  for(i=0;i<strlen(baudline_wNAME);i++) if(baudline_wNAME[i]=='-') baudline_wNAME[i]='_';
987  printf("%s\n",baudline_wNAME);
988 
989  sprintf(cmd,"cat %s | %s -utc %s -spacebar recordpause -basefrequency 0 -decimateby 1 -psd -format le32f -stdin -overlap 100 -samplerate %f -scaleby %e -average.savepsd -record -memory 10 -reversetimeaxis -tsession %s -overlays 1 -channels %d -palette %s -fftsize 65536 %s&", pipe_name,baudline,sbdate,sampleRate,scale,tsession,nchannel,palette,params);
990  printf("%s\n",cmd);
991  pid = System(cmd);
992  printf("Baudline pid : %d\n",pid);
993 
994  sprintf(cmd,"ps -ef | grep baudline | grep ID%d | awk \'{print $2}\'",baudline_rnID);
995  printf("%s\n",cmd);
996  System(cmd);
997 
998  int fp = open(pipe_name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | O_NONBLOCK);
999  if(fp <= 0)
1000  {fprintf(stderr,"Cannot open output pipe %s\n %s", pipe_name, FrErrorGetHistory());
1001  exit(1);}
1002 
1003  return fp;
1004 }
1005 
1006 void GetBaudlineDateFormat(int gpsSec, int gpsNSec, char* sbdate) {
1007 
1008  printf("gpsSec %d - gpsNSec %d\n",gpsSec,gpsNSec);
1009  printf("UTC : %s\n",FrStrUTC(gpsSec,0));
1010 
1011  time_t unix_date_sec = FrGPS2UTC(gpsSec, 0);
1012  int us = gpsNSec/1000;
1013 
1014  struct tm* tp = gmtime(&unix_date_sec);
1015 
1016  int ss = tp->tm_sec; // seconds 0:59
1017  int mm = tp->tm_min; // minutes 0:59
1018  int hh = tp->tm_hour; // hours 0:23
1019  int DD = tp->tm_mday; // day of the month 1:31
1020  int MM = tp->tm_mon+1; // month 0:11
1021  int YY = tp->tm_year; // year since 1900
1022 
1023  char bdate[32]="00:00:00-00:00:00.000000";
1024  char tmp[32];int len=0;
1025  sprintf(tmp,"%d",YY);len=strlen(tmp);
1026  if(len==3) strncpy(bdate+2-len+1,tmp+1,len-1); else strncpy(bdate+2-len,tmp,len);
1027  sprintf(tmp,"%d",MM);len=strlen(tmp);strncpy(bdate+5-len,tmp,len);
1028  sprintf(tmp,"%d",DD);len=strlen(tmp);strncpy(bdate+8-len,tmp,len);
1029  sprintf(tmp,"%d",hh);len=strlen(tmp);strncpy(bdate+11-len,tmp,len);
1030  sprintf(tmp,"%d",mm);len=strlen(tmp);strncpy(bdate+14-len,tmp,len);
1031  sprintf(tmp,"%d",ss);len=strlen(tmp);strncpy(bdate+17-len,tmp,len);
1032  sprintf(tmp,"%d",us);len=strlen(tmp);strncpy(bdate+24-len,tmp,len);
1033 
1034  strcpy(sbdate,bdate);
1035  printf("Baudline Date Format : %s\n",sbdate);
1036 
1037  return;
1038 }
1039 
1040 int System(const char *command) {
1041 
1042  int pid, status;
1043  extern char **environ;
1044 
1045  if (command == NULL) {printf("System : NULL Command\n");exit(1);}
1046  pid = fork();
1047  if (pid == -1) {printf("System : Fork Failed\n");exit(1);}
1048  if (pid == 0) {
1049  char *argv[4];
1050  argv[0] = const_cast<char*>("sh");
1051  argv[1] = const_cast<char*>("-c");
1052  argv[2] = (char*)command;
1053  argv[3] = 0;
1054  execve("/bin/sh", argv, environ);
1055  exit(127);
1056  }
1057  do {
1058  if (waitpid(pid, &status, 0) == -1) {
1059  if (errno != EINTR) {printf("System : waitpid error %d\n",errno);exit(1);}
1060  } else
1061  return pid;
1062  } while(1);
1063 }
1064 
1065 void INThandler(int sig) {
1066 
1067  char c;
1068 
1069  TString OS = "";
1070  if(TString(gSystem->GetBuildArch()).Contains("linux")) OS="Linux";
1071  if(TString(gSystem->GetBuildArch()).Contains("macos")) OS="Darwin";
1072  if(OS=="") {cout << "Error : Operative System not supported!!! " << endl;exit(1);}
1073 
1074  signal(sig, SIG_IGN);
1075  printf("Do you really want to quit? [y/n] or save? [s] ");
1076  c = getchar();
1077  if (c == 'y' || c == 'Y') {
1078  char cmd[256];
1079  //sprintf(cmd,"ps -ef | grep baudline | grep ID%d | awk \'{print $2}\' | xargs kill",baudline_rnID);
1080  if(OS=="Linux") sprintf(cmd,"ps | grep baudline | awk \'{print $1}\' | xargs kill");
1081  if(OS=="Darwin") sprintf(cmd,"ps | grep baudline | awk \'{print $1}\' | xargs kill");
1082  printf("%s\n",cmd);
1083  System(cmd);
1084 
1085  // remove temporary frame file list
1086  sprintf(cmd,"/bin/rm %s",Par.name);
1087  //gSystem->Exec(cmd);
1088 
1089  exit(0);
1090  } else if (c == 's' || c == 'S') {
1091  printf("click window to be saved\n");
1092  char cmd[256];
1093  sprintf(cmd,"import -frame %s/%s_P%d.png",workdir.Data(),baudline_wNAME,baudline_nP++);
1094  printf("%s\n",cmd);
1095  System(cmd);
1096  fflush(stdout);
1097  signal(SIGINT, INThandler);
1098  } else {
1099  fflush(stdout);
1100  signal(SIGINT, INThandler);
1101  }
1102 }
1103 
1104 
1105 /*---------------------------------------------------------FrVectDumpBinary--*/
1106 FrVect* FrVectDumpBinary(FrVect *vect,
1107  int ofp,
1108  int chId,
1109  int debugLvl)
1110 /*---------------------------------------------------------------------------*/
1111 {FRULONG i, nData, inValid;
1112  char *dC, **dSt;
1113  short *dS;
1114  int *dI;
1115  FRLONG *dL;
1116  float *dF, ratio;
1117  double *dD;
1118  unsigned char *dU;
1119  unsigned short *dUS;
1120  unsigned int *dUI;
1121  FRULONG *dUL;
1122 
1123 // if(ofp <= 0) return NULL;
1124  if(vect == NULL) return NULL;
1125  if(debugLvl < 1) return NULL;
1126 
1127  FILE* fp = stdin;
1128 
1129  nData = vect->nData;
1130 /*
1131  if(vect->name == NULL)
1132  {fprintf(fp," Vector:- ndata=%"FRLLD, nData);}
1133  else {fprintf(fp," Vector:%s ndata=%"FRLLD, vect->name, nData);}
1134 
1135  if(vect->GTime != 0) fprintf(fp," GTime=%.5f",vect->GTime);
1136 
1137  if(vect->unitY != NULL)
1138  {fprintf(fp," unitY=%s", vect->unitY);}
1139 
1140  if(vect->nDim == 1)
1141  {if(vect->unitX[0] != NULL) fprintf(fp," unitX=%s", vect->unitX[0]);
1142  fprintf(fp," startX=%g dx=%g\n", vect->startX[0], vect->dx[0]);}
1143  else
1144  {fprintf(fp," nDim=%d\n", vect->nDim);
1145  for(i=0; i<vect->nDim; i++)
1146  {fprintf(fp," Dimension=%"FRLLD" nx=%10"FRLLD" startX=%.2g dx=%g",
1147  i,vect->nx[i], vect->startX[i], vect->dx[i]);
1148  if(vect->unitX[i] != NULL) fprintf(fp," unit=%s\n", vect->unitX[i]);
1149  else fprintf(fp,"\n");}}
1150  fprintf(fp," Data");
1151 */
1152 
1153  /*-------------------------------------- data part ---------------*/
1154  FrVect* outVect=NULL;
1155  if(vect->compress == 0) {
1156  if(vect->type == FR_VECT_4R) { /*----------------- float-------------*/
1157  dF = (float *) vect->data;
1158  if(debugLvl >2) {
1159  outVect = FrVectNew1D(vect->name, FR_VECT_4R, nData, 0, NULL, NULL);
1160  float* buffer = (float*)outVect->data;
1161  if(filter[chId]!=NULL)
1162  for(i=0; i<nData; i++) buffer[i]=filter[chId]->Arma((double)dF[i]);
1163  else
1164  for(i=0; i<nData; i++) buffer[i]=dF[i];
1165  if(ofp!=0) {
1166  write(ofp, buffer, sizeof(float)*nData);
1167  FrVectFree(outVect);outVect=NULL;
1168  }
1169  }
1170  }
1171  else if(vect->type == FR_VECT_8R) { /*---------------- double ------------*/
1172  dD = (double *) vect->data;
1173  fprintf(fp,"(double) %s\n",FrVectStat(vect));
1174  if(debugLvl >2) {
1175  outVect = FrVectNew1D(vect->name, FR_VECT_4R, nData, 0, NULL, NULL);
1176  float* buffer = (float*)outVect->data;
1177  if(filter[chId]!=NULL)
1178  for(i=0; i<nData; i++) buffer[i]=filter[chId]->Arma(dD[i]);
1179  else
1180  for(i=0; i<nData; i++) buffer[i]=dD[i];
1181  if(ofp!=0) {
1182  write(ofp, buffer, sizeof(float)*nData);
1183  FrVectFree(outVect);outVect=NULL;
1184  }
1185  }
1186  }
1187  else if(vect->type == FR_VECT_C) /*---------------one byte integer-----*/
1188  {dC = vect->data;
1189  fprintf(fp,"(byte) %s\n",FrVectStat(vect));
1190  if(debugLvl > 2)
1191  {for(i=0; i<nData; i++)
1192  {if(i%20 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1193  fprintf(fp,"%4d",dC[i]);}
1194  fprintf(fp,"\n");}}
1195 
1196  else if(vect->type == FR_VECT_2S) /*-------------- short integer -------*/
1197  {dS = (short *) vect->data;
1198  fprintf(fp,"(short) %s\n",FrVectStat(vect));
1199  if(debugLvl > 2)
1200  {for(i=0; i<nData; i++)
1201  {if(i%10 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1202  fprintf(fp," %6d",dS[i]);}
1203  fprintf(fp,"\n");}}
1204 
1205  else if(vect->type == FR_VECT_8S) /*---------------long integer---------*/
1206  {dL = (FRLONG *) vect->data;
1207  fprintf(fp,"(8S) %s\n",FrVectStat(vect));
1208  if(debugLvl > 2)
1209  {for(i=0; i<nData; i++)
1210  {if(i%10 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1211  fprintf(fp," %d\"FRLLD\"",dL[i]);}
1212  fprintf(fp,"\n");}}
1213 
1214  else if(vect->type == FR_VECT_4S) /*------------- signed integer -------*/
1215  {dI = (int *) vect->data;
1216  fprintf(fp,"(int) %s\n",FrVectStat(vect));
1217  if(debugLvl > 2)
1218  {for(i=0; i<nData; i++)
1219  {if(i%10 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1220  fprintf(fp," %8d",dI[i]);}
1221  fprintf(fp,"\n");}}
1222 
1223  else if(vect->type == FR_VECT_1U) /*--------- unsigned character----*/
1224  {dU = (unsigned char *)vect->dataU;
1225  fprintf(fp,"(1U) %s\n",FrVectStat(vect));
1226  if(debugLvl > 2)
1227  {for(i=0; i<nData; i++)
1228  {if(i%20 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1229  fprintf(fp," %4d",dU[i]);}
1230  fprintf(fp,"\n");}}
1231 
1232  else if(vect->type == FR_VECT_2U) /*-------------unsigned short -----*/
1233  {dUS = (unsigned short *) vect->data;
1234  fprintf(fp,"(2U) %s\n",FrVectStat(vect));
1235  if(debugLvl > 2)
1236  {for(i=0; i<nData; i++)
1237  {if(i%10 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1238  fprintf(fp," %6d",dUS[i]);}
1239  fprintf(fp,"\n");}}
1240 
1241  else if(vect->type == FR_VECT_8U)
1242  {dUL = (FRULONG *) vect->data;
1243  fprintf(fp,"(8U) %s\n",FrVectStat(vect));
1244  if(debugLvl > 2)
1245  {for(i=0; i<nData; i++)
1246  {if(i%10 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1247  fprintf(fp," %d\"FRLLD\"",dUL[i]);}
1248  fprintf(fp,"\n");}}
1249 
1250  else if(vect->type == FR_VECT_4U)
1251  {dUI = (unsigned int *) vect->data;
1252  fprintf(fp,"(4U) %s\n",FrVectStat(vect));
1253  if(debugLvl > 2)
1254  {for(i=0; i<nData; i++)
1255  {if(i%10 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1256  fprintf(fp," %12d",dUI[i]);}
1257  fprintf(fp,"\n");}}
1258 
1259  else if(vect->type == FR_VECT_8C) /*------------- complex float ------*/
1260  {dF = (float *) vect->data;
1261  fprintf(fp,"(8C) %s\n", FrVectStat(vect));
1262  if(debugLvl <3)
1263  {fprintf(fp," (%g,%g)", dF[0],dF[1]);
1264  if(nData > 1) fprintf(fp," (%g,%g) ...", dF[2],dF[3]);
1265  fprintf(fp,"\n");}
1266  else
1267  {for(i=0; i<nData; i++)
1268  {if(i%4 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1269  fprintf(fp,"(%12g %12g)",dF[2*i],dF[2*i+1]);}
1270  fprintf(fp,"\n");}}
1271 
1272  else if(vect->type == FR_VECT_16C) /*------------- complex double ------*/
1273  {dD = (double *) vect->data;
1274  fprintf(fp,"(16C) %s\n", FrVectStat(vect));
1275  if(debugLvl <3)
1276  {fprintf(fp," (%g,%g)",dD[0],dD[1]);
1277  if(nData > 1) fprintf(fp," (%g,%g) ...",dD[2],dD[3]);
1278  fprintf(fp,"\n");}
1279  else
1280  {for(i=0; i<nData; i++)
1281  {if(i%4 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1282  fprintf(fp,"(%12g %12g)",dD[2*i],dD[2*i+1]);}
1283  fprintf(fp,"\n");}}
1284 
1285  else if(vect->type == FR_VECT_8H) /*-------half complex float -------*/
1286  {dF = (float *) vect->data;
1287  fprintf(fp,"(8H) %s\n", FrVectStat(vect));
1288  if(debugLvl <3)
1289  {fprintf(fp," %g ", dF[0]);
1290  if(nData > 1) fprintf(fp,", (%g,%g) ...", dF[1],dF[nData-1]);
1291  fprintf(fp,"\n");}
1292  else
1293  {fprintf(fp,"%6d:(%12g %12g)", 0, dF[0], 0.);
1294  for(i=1; i<nData/2; i++)
1295  {if(i%4 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1296  fprintf(fp,"(%12g %12g)",dF[i],dF[nData-i]);}
1297  if(nData%2 == 0) fprintf(fp,"(%12g 0.)",dF[nData/2]);
1298  fprintf(fp,"\n");}}
1299 
1300  else if(vect->type == FR_VECT_16H) /*----half complex double -------*/
1301  {dD = (double *) vect->data;
1302  fprintf(fp,"(16H) %s\n", FrVectStat(vect));
1303  if(debugLvl <3)
1304  {fprintf(fp," %g",dD[0]);
1305  if(nData > 1) fprintf(fp,", (%g,%g) ...\n",dD[1],dD[nData-1]);
1306  fprintf(fp,"\n");}
1307  else
1308  {fprintf(fp,"%6d:(%12g %12g)", 0, dD[0], 0.);
1309  for(i=1; i<nData/2; i++)
1310  {if(i%4 == 0) fprintf(fp,"\n%d\"FRLLD\":",i);
1311  fprintf(fp,"(%12g %12g)",dD[i],dD[nData-i]);}
1312  if(nData%2 == 0) fprintf(fp,"(%12g 0.)",dD[nData/2]);
1313  fprintf(fp,"\n");}}
1314 
1315  else if(vect->type == FR_VECT_STRING)
1316  {dSt = (char **) vect->data;
1317  fprintf(fp,"(STRING)");
1318  if(dSt[0] != NULL) fprintf(fp," \"%s\"", dSt[0]);
1319  if(dSt[1] != NULL) fprintf(fp," \"%s\"", dSt[1]);
1320  fprintf(fp,"...\n");}
1321  else
1322  {fprintf(fp," unknown type: %d \n",vect->type );}}
1323  else
1324  {ratio = (nData*vect->wSize)/(float) vect->nBytes;
1325  fprintf(fp,"\n the vector is %.2f compressed (%x) nBytes=%d\"FRLLD\" wSize=%d\n",
1326  ratio,vect->compress,vect->nBytes, vect->wSize);}
1327 
1328  if(vect->next != NULL)
1329  {fprintf(fp," Attached information:\n");
1330  FrVectDump(vect->next, fp, debugLvl) ;}
1331 
1332  return outVect;}
1333 
1334 
1335 /*-------------------------------------------------------------FrVectMinMax--*/
1336 double FrVectMax(FrVect *vect, int chId)
1337 /*---------------------------------------------------------------------------*/
1338 /* This function computes the min and max value of the input vector vect. */
1339 /* It returns 1 in case of failure or 0 in case of success. */
1340 /*---------------------------------------------------------------------------*/
1341 {int i;
1342  double value;
1343 
1344  if(vect == NULL) return(1);
1345  if(vect->nData == 0) return(1);
1346 
1347  double min = 1.e+37;
1348  double max =-1.e+37;
1349  if(FrVectIsValid(vect) != 0) return(2);
1350 
1351  if(vect->type == FR_VECT_C)
1352  {for(i=0; i<vect->nData; i++) {value = vect->data[i];
1353  if(value > max) max = value;
1354  if(value < min) min = value;}}
1355  else if(vect->type == FR_VECT_2S)
1356  {for(i=0; i<vect->nData; i++) {value = vect->dataS[i];
1357  if(value > max) max = value;
1358  if(value < min) min = value;}}
1359  else if(vect->type == FR_VECT_8R)
1360  {for(i=0; i<vect->nData; i++) {
1361  if(filter[chId]!=NULL) {
1362  value=filter[chId]->Arma(vect->dataD[i]);
1363  if(i>vect->nData/2) {
1364  if(value > max) max = value;
1365  if(value < min) min = value;
1366  }
1367  } else {
1368  value = vect->dataD[i];
1369  if(value > max) max = value;
1370  if(value < min) min = value;
1371  }
1372  }}
1373  else if(vect->type == FR_VECT_4R)
1374  {for(i=0; i<vect->nData; i++) {
1375  if(filter[chId]!=NULL) {
1376  value=filter[chId]->Arma((double)vect->dataF[i]);
1377  if(i>vect->nData/2) {
1378  if(value > max) max = value;
1379  if(value < min) min = value;
1380  }
1381  } else {
1382  value = vect->dataF[i];
1383  if(value > max) max = value;
1384  if(value < min) min = value;
1385  }
1386  }}
1387  else if(vect->type == FR_VECT_4S)
1388  {for(i=0; i<vect->nData; i++) {value = vect->dataI[i];
1389  if(value > max) max = value;
1390  if(value < min) min = value;}}
1391  else if(vect->type == FR_VECT_8S)
1392  {for(i=0; i<vect->nData; i++) {value = vect->dataL[i];
1393  if(value > max) max = value;
1394  if(value < min) min = value;}}
1395  else if(vect->type == FR_VECT_8C)
1396  {return(0);}
1397  else if(vect->type == FR_VECT_16C)
1398  {return(0);}
1399  else if(vect->type == FR_VECT_2U)
1400  {for(i=0; i<vect->nData; i++) {value = vect->dataUS[i];
1401  if(value > max) max = value;
1402  if(value < min) min = value;}}
1403  else if(vect->type == FR_VECT_4U)
1404  {for(i=0; i<vect->nData; i++) {value = vect->dataUI[i];
1405  if(value > max) max = value;
1406  if(value < min) min = value;}}
1407  else if(vect->type == FR_VECT_8U)
1408  {for(i=0; i<vect->nData; i++) {value = vect->dataUL[i];
1409  if(value > max) max = value;
1410  if(value < min) min = value;}}
1411  else if(vect->type == FR_VECT_1U)
1412  {for(i=0; i<vect->nData; i++) {value = vect->dataU[i];
1413  if(value > max) max = value;
1414  if(value < min) min = value;}}
1415 
1416  min = fabs(min);
1417  max = fabs(max);
1418  if(min > max) max = min;
1419  return(max);}
1420 
1421 
1423 
1424  vector<std::string> ifileList;
1425  vector<std::string> ipathList;
1426  vector<std::string> ofileList;
1427  vector<std::string> opathList;
1428 
1429  ifstream in;
1430  in.open(ifile.Data());
1431  if(!in.good()) {
1432  cout << "FrDisplay - getUniqueFileList : Error Opening Input File : " << ifile.Data() << endl;
1433  gSystem->Exit(1);
1434  }
1435 
1436  // read file list
1437  char istring[1024];
1438  while(1) {
1439  in.getline(istring,1024);
1440  if (!in.good()) break;
1441  TObjArray* token = TString(istring).Tokenize(TString('/'));
1442  // extract last entry -> file name
1443  TObjString* stoken =(TObjString*)token->At(token->GetEntries()-1);
1444  TString fName = stoken->GetString();
1445  //cout << fName.Data() << endl;
1446  ipathList.push_back(istring);
1447  ifileList.push_back(fName.Data());
1448  }
1449  in.close();
1450 
1451  // extract unique file list
1452  for(int i=0;i<(int)ifileList.size();i++) {
1453  bool check=false;
1454  for(int j=0;j<(int)ofileList.size();j++) {
1455  if(TString(ofileList[j].c_str())==TString(ifileList[i].c_str())) {check=true;break;}
1456  }
1457  if(!check) {
1458  ofileList.push_back(ifileList[i]);
1459  opathList.push_back(ipathList[i]);
1460  }
1461  //cout << i << " " << ipathList[i] << endl;
1462  //cout << i << " " << ifileList[i] << endl;
1463  }
1464 
1465  // write unique file list
1466  ofstream out;
1467  out.open(ofile.Data(),ios::out);
1468  if(!out.good()) {
1469  cout << "FrDisplay - getUniqueFileList : Error Opening Output File : " << ofile.Data() << endl;
1470  gSystem->Exit(1);
1471  }
1472 
1473  for(int i=0;i<(int)ofileList.size();i++) {
1474  out << opathList[i] << endl;
1475  //cout << i << " " << opathList[i] << endl;
1476  //cout << i << " " << ofileList[i] << endl;
1477  }
1478 
1479  out.close();
1480 
1481  return;
1482 }
1483 
1484 
char ofile[1024]
int GpsToGpsLeaps(int gpsSec)
void INThandler(int)
Definition: FrDisplay.cc:1065
TChain sim("waveburst")
char baudline_wNAME[256]
Definition: FrDisplay.cc:152
par [0] value
TString file_path
double min(double x, double y)
Definition: eBBH.cc:31
char chnames[3][64]
Definition: FrDisplay.cc:161
int fAccess
Definition: FrDisplay.cc:160
pid_t getProcessId(const char *csProcessName)
par [0] name
int baudline_nP
Definition: FrDisplay.cc:153
TString("c")
int palette
Definition: DrawGnetwork2.C:17
int System(const char *command)
Definition: FrDisplay.cc:1040
FileAccess
Definition: FrDisplay.cc:122
int GpsToUnixTime(int gpsSec)
ofstream out
Definition: cwb_merge.C:214
int baudline_rnID
Definition: FrDisplay.cc:151
#define PROC
Definition: FrDisplay.cc:132
void FrFileDumpBinary(FrFile *file, int fp, double *scale, int nchannel, double sampleRate)
Definition: FrDisplay.cc:529
CWB::Filter * filter[3]
Definition: FrDisplay.cc:155
Long_t flags
void GetBaudlineDateFormat(int gpsSec, int gpsNSec, char *sbdate)
Definition: FrDisplay.cc:1006
#define SMS
Definition: FrDisplay.cc:126
#define ADC
Definition: FrDisplay.cc:125
cout<< "baudline_FFL : "<< baudline_FFL<< endl;ofstream out;out.open(baudline_FFL, ios::out);if(!out.good()) {cout<< "Error Opening File : "<< baudline_FFL<< endl;exit(1);} ifstream in;in.open(frFiles[ifoID], ios::in);if(!in.good()) {cout<< "Error Opening File : "<< frFiles[ifoID]<< endl;exit(1);} TString pfile_path="";char istring[1024];while(1) { in > istring
Long_t size
char command[1024]
Definition: cwb_compile.C:44
int j
Definition: cwb_net.C:28
i drho i
wavearray< double > hh
Definition: Regression_H1.C:73
cout<< "Selected Pixels : "<< nPix<< endl;wc.cluster(1, 1);SSeries< double > ss
int debug
Definition: cWB_conf.py:39
fprintf(stdout,"start=%f duration=%f rate=%f\, x.start(), x.size()/x.rate(), x.rate())
int StartBaudline(int gpsSec, int gpsNSec, double scale, double sampleRate, char *chname, int nchannel, char *params)
Definition: FrDisplay.cc:938
#define EVENT
Definition: FrDisplay.cc:129
void Help()
Definition: FrDisplay.cc:48
#define RAW
Definition: FrDisplay.cc:131
int iglobal[3]
Definition: FrDisplay.cc:156
i() int(T_cor *100))
double * tmp
Definition: testWDM_5.C:31
TString worksite
Definition: FrDisplay.cc:159
printf("total live time: non-zero lags = %10.1f \, liveTot)
TString workdir
Definition: FrDisplay.cc:158
#define SIM
Definition: FrDisplay.cc:127
TObjArray * token
TFile * ifile
char tag[256]
Definition: cwb_merge.C:92
#define STAT
Definition: FrDisplay.cc:128
FrVect * FrVectDumpBinary(FrVect *vect, int fp, int chId, int debugLvl)
Definition: FrDisplay.cc:1106
#define MIN_TIME_GAP
Definition: FrDisplay.cc:163
ifstream in
int main(int argc, char **argv)
Definition: FrDisplay.cc:166
void ReadParameters(int argc, char **argv)
Definition: FrDisplay.cc:595
#define SUM
Definition: FrDisplay.cc:130
double fabs(const Complex &x)
Definition: numpy.cc:55
char cmd[1024]
int estat
strcpy(RunLabel, RUN_LABEL)
TString OS
Definition: cwb_rootlogon.C:25
int cnt
in open(HEN_LIST, ios::in)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
Long_t mt
Long_t id
float uscaleby
Definition: FrDisplay.cc:157
char line[1024]
#define UNSET
Definition: FrDisplay.cc:124
char fName[256]
int check
double FrVectMax(FrVect *vect, int chId)
Definition: FrDisplay.cc:1336
void getUniqueFileList(TString ifile, TString ofile)
Definition: FrDisplay.cc:1422
Type
Definition: FrDisplay.cc:123
void StrCat(char **oldbuf, char *more)
Definition: FrDisplay.cc:918
wavearray< double > sig
struct Parameters Par
Definition: FrDisplay.cc:150
exit(0)
char baudline_FFL[256]
Definition: FrDisplay.cc:154