21 #include <sys/param.h>
23 #include <sys/sysctl.h>
27 #include "TObjArray.h"
28 #include "TObjString.h"
33 " This program reads frames from one or more input files, and print \n"
34 " the requested information. \n"
35 "-------------------------------------------------------------------- \n"
36 " Syntax is: FrDisplay -i <input file / ldf> \n"
37 " -f <first frame: (run # frame #) or (GPS time)> \n"
38 " -l <last frame: (run # frame #) or (GPS time)> \n"
39 " or length in second \n"
40 " -t <list of tag channels> \n"
41 " -d <debug level> \n"
42 " -c -1 to leave the data uncompressed \n"
43 " -top <number of ADC in the hit-parade> \n"
44 " -x <baudline parameters list> \n"
45 " -o <ldf observatory parameter> \n"
46 " -s <ldf data type parameter> \n"
47 " -k <filter parameters list> \n"
48 " -a <file access mode [s(sequential)/r(random)]> \n"
49 " -h (to get this help) \n"
50 " If one of the next option is there, we do only a partial frame dump\n"
51 " -adc to dump only the FrAdcData information \n"
52 " -sms to dump only the FrSerData information \n"
53 " -proc to dump only the FrProcData information \n"
54 " -sim to dump only the FrSimData information \n"
55 " -sum to dump only the FrSummary information \n"
56 " -stat to dump only the static information \n"
57 " -raw to dump only the raw data information \n"
58 " -event to dump only the FrEvent and FrSimEvent \n"
59 "-------------------------------------------------------------------- \n"
61 " -i : Argument can be one or more file names \n"
62 " -t : Tag is a channel list with wild cards like: ADC122 ADC5* \n"
63 " If a name start by - it is interpreted as an anti-tag \n"
64 " -f -l:These options works only with the debug level > 2 \n"
65 " -d 0: One line per file based on the TOC information \n"
66 " First frame time, file length, time of the first/last event, \n"
67 " -d 1: A few lines per file based on the TOC information \n"
68 " First/last frame time, number of frame in file, missing frame \n"
69 " Count the number of frame elements like ADC, Proc, Sim, Event \n"
70 " Gives the name of few of them and the typical event amplitude \n"
71 " -d 2: More lines per file based on the TOC information \n"
72 " Same as -d 1 plus the full list of channels, event \n"
73 " -d 3: Read the frame to print information \n"
74 " Print the list of all frame (time, length, quality word) \n"
75 " -d 4: Read the frame to print information with more info \n"
76 " Same as -d 3 plus summary information for all channels \n"
77 " Print frame history \n"
78 " -d 5: Read the frame to print information with more info \n"
79 " Same as -d 4 plus a full dump of the channel content... \n"
80 "-------------------------------------------------------------------- \n"
105 enum Type {
INPUT,
OUTPUT,
TAG,
FIRST,
LAST,
DEBUG,
COMPRESS,
TOP,
BAUDLINE,
OBSERVATORY,
DATATYPE,
FILTER,
ACCESS};
117 void StrCat(
char **oldbuf,
char *more);
119 double FrVectMax(FrVect *vect,
int chId);
122 int StartBaudline(
int gpsSec,
int gpsNSec,
double scale,
double sampleRate,
char* chname,
int nchannel,
char* params);
145 #define MIN_TIME_GAP 256
148 int main(
int argc,
char **argv)
159 double tStart, tEnd, gtime,
start, len;
161 double sampleRate = 0.;
164 double scale[3]={0.,0.,0.};
171 gettimeofday(&tv, NULL);
176 if(
TString(gSystem->GetBuildArch()).Contains(
"linux")) OS=
"Linux";
177 if(
TString(gSystem->GetBuildArch()).Contains(
"macos")) OS=
"Darwin";
178 if(OS==
"") {cout <<
"Error : Operative System not supported!!! " << endl;
exit(1);}
181 if(OS==
"Linux")
sprintf(cmd,
"mkdir -p /dev/shm/%s",getlogin());
182 if(OS==
"Darwin")
sprintf(cmd,
"mkdir -p /tmp/%s",getlogin());
189 sprintf(sworkdir,
"%s",getenv(
"FRDISPLAY_WORKDIR"));
192 sprintf(sworksite,
"%s",getenv(
"FRDISPLAY_WORKSITE"));
202 FrLibSetLvl(
Par.debug-3);
203 file = FrFileINew(
Par.name);
205 {
fprintf(stderr,
"Cannot open input file %s\n %s",
206 Par.name, FrErrorGetHistory());
208 file->compress =
Par.comp;
209 file->chkSumFrFlag = FR_YES;
214 {FrFileIDumpT(file, stdout,
Par.debug+1,
Par.tag,
Par.ftime,
Par.ltime );
221 {frame = FrameReadT(file,
Par.ftime);
223 {tStart = FrFileITNextFrame(file,
Par.ftime);
224 if(
Par.ltime > 100000000) tEnd =
Par.ltime;
225 else tEnd =
Par.ftime +
Par.ltime;
226 if(tStart < tEnd) frame = FrameReadT(file, tStart);}}
227 else if((
Par.frun > 0) || (
Par.fframe > 0))
228 {frame = FrameReadN(file,
Par.frun,
Par.fframe);}
229 else{frame = FrameRead(file);}
230 if(frame == NULL)
fprintf(stderr,
231 " Cannot read a frame\n %s", FrErrorGetHistory());
236 if(((
Par.dType &
ADC) != 0) && (frame->rawData != NULL)) {
238 for(adc = frame->rawData->firstAdc; adc != NULL; adc=adc->next) {
239 if(adc->sampleRate>50) {
240 if(
Par.tag == NULL) {
241 fprintf(stdout,
" ADC-%4d: %32s - rate: %15.2f - size: %10lu\n",
242 nadc,adc->name,adc->sampleRate,adc->data->nData);
245 free((
char*)(
Par.tag));
257 for(proc = frame->procData; proc != NULL; proc = proc->next) {
258 if(
Par.tag == NULL) {
259 if(proc->data->dx[0]>0)
260 fprintf(stdout,
" PROC-%4d: %32s - rate: %15.2f - size: %10lu\n",
261 nproc,proc->name,1./proc->data->dx[0],proc->data->nData);
264 free((
char*)(
Par.tag));
279 while(frame != NULL) {
281 FrFileH *fileH=file->current;
285 if(frame->GTimeS+1.e-9*frame->GTimeN >
Par.ltime)
break;
286 if(frame->run >
Par.lrun)
break;
287 if((frame->run ==
Par.lrun ) && (frame->frame >
Par.lframe))
break;
291 if(
Par.tag != NULL) FrameTag(frame,
Par.tag);
296 {gtime = frame->GTimeS+1.e-9*frame->GTimeN;
297 if(
Par.ftime > gtime ||
Par.ltime < gtime+frame->dt)
298 {
if(
Par.ftime > gtime) start =
Par.ftime - gtime;
300 if(
Par.ltime < gtime+frame->dt) len =
Par.ltime - gtime -
start;
301 else len = frame->dt -
start;
302 if(frame->rawData != NULL)
303 {
for(adc = frame->rawData->firstAdc; adc != NULL; adc=adc->next)
304 {FrVectZoomIn(adc->data, start, len);}}
305 for(proc = frame->procData; proc != NULL; proc = proc->next)
306 {FrVectZoomIn(proc->data, start, len);}
307 for(sim = frame->simData; sim != NULL; sim = sim->next)
308 {FrVectZoomIn(sim->data, start, len);}}}
313 {FrameDump(frame, stdout,
Par.debug);
314 if(
Par.comp != 0) FrameCompDump(frame, stdout,
Par.debug);}
316 {
printf(
"Frame %d/%d GTimeS=%d\n",frame->run,frame->frame,frame->GTimeS);
317 if(((
Par.dType &
ADC) != 0) && (frame->rawData != NULL)) {
318 if((fp==0) && (
Par.debug > 2)) {
322 for(xadc = frame->rawData->firstAdc; xadc != NULL; xadc=xadc->next) {
324 {
printf(
"Multichannel with num channel gt 3 not allowed !!!\n");
exit(1);}
326 size = xadc->data->nData;
328 if(size!=xadc->data->nData)
329 {
printf(
"Multichannel with different size not allowed !!!\n");
exit(1);}
332 sampleRate = xadc->sampleRate;
334 if(sampleRate!=xadc->sampleRate)
335 {
printf(
"Multichannel with different sampleRates not allowed !!!\n");
exit(1);}
338 if(
Par.filter!=NULL &&
filter[nchannel]==NULL) {
340 sprintf(sratepar,
" -s %f ",sampleRate);
342 filter[nchannel] =
new CWB::Filter(
Par.filter);
344 scale[nchannel]=
FrVectMax(xadc->data,nchannel);
345 if(scale[nchannel]>0) scale[nchannel]=32768./scale[nchannel];
348 sprintf(chname,
"%s",xadc->name);
350 sprintf(chname,
"%s %s",chname,xadc->name);
356 {
printf(
"The request channel is not present in the frame !!!\n");
exit(1);}
362 for(
int j=0;
j<nchannel;
j++) scale[
j]=32768./scale[
j];
366 printf(
"sampleRate %f - scale %e - chname %s - nchannel %d\n",sampleRate,scaleby,chname,nchannel);
367 fp=
StartBaudline(frame->GTimeS, frame->GTimeN, scaleby, sampleRate, chname, nchannel,
Par.baudline);
372 for(adc = frame->rawData->firstAdc; adc != NULL; adc=adc->next) {
376 if(nchannel!=0 && nVect!=nchannel)
377 {
printf(
"Multichannel : num of channels is changed !!!\n");
exit(1);}
378 FrVect* dumpVect = FrVectNew1D(
const_cast<char*>(
"dumpVect"), FR_VECT_4R, nVect*outVect[0]->nData, 0, NULL, NULL);
379 float* buffer = (
float*)dumpVect->data;
381 for(
int i=0;
i<outVect[0]->nData;
i++)
382 for(
int j=0;
j<nVect;
j++)
383 buffer[nVect*
i+
j]=(((
float*)outVect[
j]->data)[
i])/scale[
j];
384 for(
int j=0;
j<nVect;
j++) FrVectFree(outVect[
j]);
385 write(fp, buffer,
sizeof(
float)*dumpVect->nData);
386 FrVectFree(dumpVect);
388 if(((
Par.dType &
SMS) != 0) && (frame->rawData != NULL))
389 {
for(sms = frame->rawData->firstSer; sms != NULL; sms = sms->next)
390 {
printf(
" SMS: %s Data:%30s\n", sms->name, sms->data);}}
392 {
if(frame->detectProc != NULL)
393 {
printf(
"Detector used for reconstruction:\n");
394 FrDetectorDump(frame->detectProc, stdout,
Par.debug);}
395 if(frame->detectSim != NULL)
396 {
printf(
"Detector used for simulation:\n");
397 FrDetectorDump(frame->detectSim, stdout,
Par.debug);}}
398 if((
Par.dType &
SIM) != 0)
399 {
for(sim = frame->simData; sim != NULL; sim = sim->next)
400 {FrSimDataDump(sim, stdout,
Par.debug);}}
402 {
for(simE = frame->simEvent; simE != NULL; simE = simE->next)
403 {FrSimEventDump(simE, stdout,
Par.debug);}
404 for(evt = frame->event; evt != NULL; evt = evt->next)
405 {FrEventDump(evt, stdout,
Par.debug);}}
407 if((fp==0) && (
Par.debug > 2)) {
410 for(proc = frame->procData; proc != NULL; proc = proc->next) {
411 printf(
"Reconstructed Data: %s\n", proc->name);
413 {
printf(
"Multichannel with num channel gt 3 not allowed !!!\n");
exit(1);}
415 size = proc->data->nData;
417 if(size!=proc->data->nData)
418 {
printf(
"Multichannel with different size not allowed !!!\n");
exit(1);}
421 if(proc->data->dx[0] < 1) sampleRate = 1./proc->data->dx[0];
422 else {
printf(
"sampleRate not allowed !!!\n");
exit(1);}
424 if(sampleRate!=1./proc->data->dx[0])
425 {
printf(
"Multichannel with different sampleRates not allowed !!!\n");
exit(1);}
428 if(
Par.filter!=NULL &&
filter[nchannel]==NULL) {
430 sprintf(sratepar,
" -s %f ",sampleRate);
432 filter[nchannel] =
new CWB::Filter(
Par.filter);
434 scale[nchannel]=
FrVectMax(proc->data,nchannel);
435 if(scale[nchannel]>0) scale[nchannel]=32768./scale[nchannel];
438 sprintf(chname,
"%s",proc->name);
440 sprintf(chname,
"%s %s",chname,proc->name);
446 {
printf(
"The request channel is not present in the frame !!!\n");
exit(1);}
452 for(
int j=0;
j<nchannel;
j++) scale[
j]=32768./scale[
j];
456 printf(
"sampleRate %f - scale %e - chname %s - nchannel %d\n",sampleRate,scaleby,chname,nchannel);
457 fp=
StartBaudline(frame->GTimeS, frame->GTimeN, scaleby, sampleRate, chname, nchannel,
Par.baudline);
462 for(proc = frame->procData; proc != NULL; proc = proc->next) {
466 if(nchannel!=0 && nVect!=nchannel)
467 {
printf(
"Multichannel : num of channels is changed !!!\n");
exit(1);}
468 FrVect* dumpVect = FrVectNew1D(
const_cast<char*>(
"dumpVect"), FR_VECT_4R, nVect*outVect[0]->nData, 0, NULL, NULL);
469 float* buffer = (
float*)dumpVect->data;
471 for(
int i=0;
i<outVect[0]->nData;
i++)
472 for(
int j=0;
j<nVect;
j++)
473 buffer[nVect*
i+
j]=(((
float*)outVect[
j]->data)[
i])/scale[
j];
474 for(
int j=0;
j<nVect;
j++) FrVectFree(outVect[
j]);
475 write(fp, buffer,
sizeof(
float)*dumpVect->nData);
476 FrVectFree(dumpVect);
478 if((
Par.dType &
SUM) != 0)
479 {
for(sum = frame->summaryData; sum != NULL; sum = sum->next)
480 {
printf(
"Summary: %s %s \n",sum->name, sum->comment);
481 FrVectDump( sum->moments, stdout,
Par.debug);}}
482 if((
Par.dType &
RAW) != 0)
483 {FrRawDataDump(frame->rawData, stdout,
Par.debug);}}
485 if(
Par.debug > 1) FrameStat(frame, stdout);
487 if(
Par.nTop != -2) FrameDumpTopADC(frame, stdout,
Par.nTop,
Par.comp);
493 frame = FrameRead(file);
501 FrFileIStat(file, stdout);
504 printf(
"\n\nhit Ctrl-C\n\n");
515 FrFileH *fileH=file->fileH;
517 cout << fileH->fileName << endl;
520 for(
int nVect=0;nVect<nchannel;nVect++) {
521 FrFile* cfile=FrFileINew(fileH->fileName);
522 FrTOCFFLBuild(cfile);
523 FrFileH *cfileH=cfile->current;
524 double cStart=cfileH->tStart;
525 double cEnd=cfileH->tStart+cfileH->length;
526 if(
Par.ftime>cStart) cStart=
Par.ftime;
527 if(
Par.ltime<cEnd) cEnd=
Par.ltime;
528 double clength=cEnd-cStart;
530 if(tCurrent!=0 && nVect==0) {
531 if(cStart!=tCurrent) {
533 cout <<
"tCurrent " << tCurrent << endl;
534 cout <<
"cStart " << cStart << endl;
535 cout <<
"cEnd " << cEnd << endl;
536 int nullSize=(cStart-tCurrent)*sampleRate;
537 if(((cStart-tCurrent)<=
MIN_TIME_GAP)&&((cStart-tCurrent)>0)) {
538 FrVect* nullVect = FrVectNew1D(
const_cast<char*>(
"NULL"), FR_VECT_4R, nullSize, 0, NULL, NULL);
539 float* dF = (
float*)nullVect->data;
540 for(
int i=0;
i<nullSize;
i++) dF[
i]-0;;
541 write(fp, dF,
sizeof(
float)*nullSize);
542 FrVectFree(nullVect);
544 cout <<
"Error : data not contiguous !!!" << endl;
551 outVect[nVect]=FrFileIGetVectF(cfile,
chnames[nVect], cStart, clength);
552 float* dF = (
float *) outVect[nVect]->data;
554 for(
int i=0;
i<outVect[nVect]->nData;
i++)
555 dF[
i]=
filter[nVect]->Arma((
double)dF[
i]);
560 FrVect* dumpVect = FrVectNew1D(
const_cast<char*>(
"dumpVect"), FR_VECT_4R, nchannel*outVect[0]->nData, 0, NULL, NULL);
561 float* buffer = (
float*)dumpVect->data;
563 for(
int i=0;
i<outVect[0]->nData;
i++)
564 for(
int j=0;
j<nchannel;
j++)
565 buffer[nchannel*
i+
j]=(((
float*)outVect[
j]->data)[
i])/scale[
j];
566 for(
int j=0;
j<nchannel;
j++) FrVectFree(outVect[
j]);
567 write(fp, buffer,
sizeof(
float)*dumpVect->nData);
568 FrVectFree(dumpVect);
589 if(
TString(gSystem->GetBuildArch()).Contains(
"linux")) OS=
"Linux";
590 if(
TString(gSystem->GetBuildArch()).Contains(
"macos")) OS=
"Darwin";
591 if(OS==
"") {cout <<
"Error : Operative System not supported!!! " << endl;
exit(1);}
611 for (i=1; i<argc; i++)
612 {
if (strcmp(argv[i],
"-h") == 0)
615 else if (strcmp(argv[i],
"-i") == 0) {type =
INPUT;}
616 else if (strcmp(argv[i],
"-t") == 0) {type =
TAG;}
617 else if (strcmp(argv[i],
"-f") == 0) {type =
FIRST;}
618 else if (strcmp(argv[i],
"-l") == 0) {type =
LAST;}
619 else if (strcmp(argv[i],
"-d") == 0) {type =
DEBUG;}
620 else if (strcmp(argv[i],
"-c") == 0) {type =
COMPRESS;}
621 else if (strcmp(argv[i],
"-x") == 0) {type =
BAUDLINE;}
622 else if (strcmp(argv[i],
"-o") == 0) {type =
OBSERVATORY;}
623 else if (strcmp(argv[i],
"-s") == 0) {type =
DATATYPE;}
624 else if (strcmp(argv[i],
"-k") == 0) {type =
FILTER;}
625 else if (strcmp(argv[i],
"-a") == 0) {type =
ACCESS;}
626 else if (strcmp(argv[i],
"-top") == 0) {type =
TOP;}
627 else if (strcmp(argv[i],
"-adc") == 0) {
Par.dType =
Par.dType |
ADC;}
628 else if (strcmp(argv[i],
"-sms") == 0) {
Par.dType =
Par.dType |
SMS;}
629 else if (strcmp(argv[i],
"-stat") == 0) {
Par.dType =
Par.dType |
STAT;}
630 else if (strcmp(argv[i],
"-sim") == 0) {
Par.dType =
Par.dType |
SIM;}
631 else if (strcmp(argv[i],
"-event") == 0) {
Par.dType =
Par.dType |
EVENT;}
632 else if (strcmp(argv[i],
"-proc") == 0) {
Par.dType =
Par.dType |
PROC;}
633 else if (strcmp(argv[i],
"-sum") == 0) {
Par.dType =
Par.dType |
SUM;}
634 else if (strcmp(argv[i],
"-raw") == 0) {
Par.dType =
Par.dType |
RAW;}
645 {
Par.ftime = atof(argv[i]);}
646 else {
Par.frun =
Par.ftime;
647 Par.fframe = atoi(argv[i]);}}
650 {
Par.ltime = atof(argv[i]);}
651 else {
Par.lrun =
Par.ltime;
652 Par.lframe = atoi(argv[i]);}}
653 if(type ==
DEBUG) {
Par.debug = atoi(argv[i]);}
655 if(type ==
TOP) {
Par.nTop = atoi(argv[i]);}
671 if(
Par.filter!=NULL) {
672 if(strstr(
Par.filter,
"help")!=NULL) {
673 printf(
"filter help !!!\n");
681 if(
Par.baudline!=NULL) {
682 if(strstr(
Par.baudline,
"help")!=NULL) {
683 printf(
"baudline help !!!\n");
686 if(getenv(
"BAUDLINE_CMD")!=NULL) {
687 printf(
"BAUDLINE_CMD : %s\n",getenv(
"BAUDLINE_CMD"));
688 sprintf(baudline,
"%s",getenv(
"BAUDLINE_CMD"));}
690 {
printf(
"Cannot get BAUDLINE_CMD env\n");
exit(1);}
692 sprintf(cmd,
"%s -help",baudline);
702 if(
Par.baudline!=NULL) {
704 for(
int i=0;i<token->GetEntries();i++) {
705 TObjString* tok = (TObjString*)token->At(i);
706 TString stok = tok->GetString();
707 if(stok.CompareTo(
"-downmix")==0) {
708 if(i==token->GetEntries()-1) {cout <<
"error : downmix par without value" << endl;
exit(1);}
709 TObjString* vtok = (TObjString*)token->At(i+1);
710 TString svtok = vtok->GetString();
711 if(!svtok.IsFloat()) {cout <<
"error : downmix par not digit" << endl;
exit(1);}
712 downmix = svtok.Atoi();
714 if(stok.CompareTo(
"-uscaleby")==0) {
715 if(i==token->GetEntries()-1) {cout <<
"error : scaleby par without value" << endl;
exit(1);}
716 TObjString* vtok = (TObjString*)token->At(i+1);
717 TString svtok = vtok->GetString();
718 if(!svtok.IsFloat()) {cout <<
"error : scaleby par not digit" << endl;
exit(1);}
722 for(
int j=0;
j<token->GetEntries();
j++) {
723 TObjString* tok = (TObjString*)token->At(
j);
724 TString stok = tok->GetString();
725 if(
j!=i &&
j!=i+1)
sprintf(
Par.baudline,
"%s %s",
Par.baudline,stok.Data());
734 char baudline_rc_path[256];
735 sprintf(baudline_rc_path,
"%s/.baudline/baudline_rc",uhome.Data());
736 char baudline_rc_tmp_path[256];
737 sprintf(baudline_rc_tmp_path,
"%s/.baudline/baudline_rc.tmp",uhome.Data());
740 int estat = gSystem->GetPathInfo(baudline_rc_path,&
id,&size,&flags,&mt);
744 in.open(baudline_rc_path,
ios::in);
745 if (!in.good()) {cout <<
"Error Opening File : " << baudline_rc_path << endl;
exit(1);}
748 out.open(baudline_rc_tmp_path,
ios::out);
749 if (!out.good()) {cout <<
"Error Opening File : " << baudline_rc_tmp_path << endl;
exit(1);}
755 in.getline(line,256);
756 if (!in.good())
break;
759 if(sline.Contains(
"downmix")) {out <<
"downmix " << downmix << endl;flag=
true;}
760 else out << sline.Data() << endl;
762 if(!flag) {out <<
"downmix " << downmix << endl;}
767 sprintf(cmd,
"mv %s %s",baudline_rc_tmp_path,baudline_rc_path);
778 if((
Par.name!=NULL)&&(
TString(
Par.name).Contains(
".ffl"))==1) {
780 TString ffl_file_path = gSystem->ExpandPathName(
Par.name);
783 in.open(ffl_file_path.Data(),
ios::in);
784 if (!in.good()) {cout <<
"Error Opening File : " << ffl_file_path.Data() << endl;
exit(1);}
790 if (!out.good()) {cout <<
"Error Opening File : " <<
baudline_FFL << endl;
exit(1);}
795 double dummy1,dummy2;
797 in >> file_path >> start >> lenght >> dummy1 >> dummy2;
798 if (!in.good())
break;
801 if((start>=
Par.ftime)&&(start<=
Par.ltime)) {
803 out << file_path <<
" " << start <<
" " << lenght <<
" " << dummy1 <<
" " << dummy2 << endl;
808 free((
char*)(
Par.name));
815 if((
Par.name!=NULL)&&(strcmp(
Par.name,
"ldf"))==0) {
817 int ret=gSystem->Exec(
"gw_data_find -v");
818 if(ret!=0) {
printf(
"gw_data_find is not available !!!\n");
exit(1);}
819 if(
Par.datatype!=0) {
820 if(strstr(
Par.datatype,
"help")!=NULL) {
821 sprintf(cmd,
"gw_data_find --show-types ");
828 if(
Par.observatory==0) {
printf(
"parameter observatory -o not defined !!!\n");
exit(1);}
829 if(
Par.ftime==0) {
printf(
"parameter GPS start -f not defined !!!\n");
exit(1);}
830 if(
Par.ltime==0) {
printf(
"parameter GPS stop -l not defined !!!\n");
exit(1);}
831 if(
Par.datatype==0) {
printf(
"parameter data type -s not defined !!!\n");
exit(1);}
836 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);
841 Long_t xid,xsize,xflags,xmt;
842 int xestat = gSystem->GetPathInfo(
baudline_FFL,&xid,&xsize,&xflags,&xmt);
843 if (xestat!=0 || xsize==0) {
854 free((
char*)(
Par.name));
866 {
fprintf(stderr,
" Please provide at least one input file\n");
872 if(
Par.ltime <
Par.ftime)
Par.ltime +=
Par.ftime -1.e-6;
875 {
printf(
"-----------Parameters used--------------\n");
878 printf(
" First frame : %d %d (GPS=%.1f)\n",
880 if(
Par.ltime < 100000000)
882 else printf(
" Last frame : %d %d (GPS=%.1f)\n",
884 printf(
" Debug level : %d\n",
Par.debug);
891 if((
Par.dType &
SUM) != 0)
printf(
" Dump summary info\n");
892 if((
Par.dType &
RAW) != 0)
printf(
" Dump raw data info\n");
893 if(
Par.dType == 0)
printf(
" Dump all Frame info\n");
894 printf(
"----------------------------------------\n");}
905 lenMore = strlen(more);
908 {*oldbuf = (
char*)malloc(strlen(more) + 1);
912 newbuf = (
char*)malloc( strlen(*oldbuf) + lenMore + 2);
913 sprintf(newbuf,
"%s %s",*oldbuf, more);
921 double sampleRate,
char* chname,
int nchannel,
char* params) {
925 printf(
"date : %s - chname : %s\n",sbdate,chname);
926 printf(
"sampleRate %f - scale %e\n",sampleRate,scale);
932 if(getenv(
"BAUDLINE_CMD")!=NULL) {
933 printf(
"BAUDLINE_CMD : %s\n",getenv(
"BAUDLINE_CMD"));
934 sprintf(baudline,
"%s",getenv(
"BAUDLINE_CMD"));}
936 {
printf(
"Cannot get BAUDLINE_CMD env\n");
exit(1);}
939 if(getenv(
"BAUDLINE_PALETTE")!=NULL) {
940 printf(
"BAUDLINE_PALETTE : %s\n",getenv(
"BAUDLINE_PALETTE"));
941 sprintf(palette,
"%s",getenv(
"BAUDLINE_PALETTE"));}
943 {
printf(
"Cannot get BAUDLINE_PALETTE env\n");
exit(1);}
946 if(
TString(gSystem->GetBuildArch()).Contains(
"linux")) OS=
"Linux";
947 if(
TString(gSystem->GetBuildArch()).Contains(
"macos")) OS=
"Darwin";
948 if(OS==
"") {cout <<
"Error : Operative System not supported!!! " << endl;
exit(1);}
954 if(OS==
"Linux")
sprintf(cmd,
"mknod %s p",pipe_name);
955 if(OS==
"Darwin")
sprintf(cmd,
"mkfifo %s",pipe_name);
971 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);
974 printf(
"Baudline pid : %d\n",pid);
980 int fp =
open(pipe_name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | O_NONBLOCK);
982 {
fprintf(stderr,
"Cannot open output pipe %s\n %s", pipe_name, FrErrorGetHistory());
990 printf(
"gpsSec %d - gpsNSec %d\n",gpsSec,gpsNSec);
991 printf(
"UTC : %s\n",FrStrUTC(gpsSec,0));
993 time_t unix_date_sec = FrGPS2UTC(gpsSec, 0);
994 int us = gpsNSec/1000;
996 struct tm* tp = gmtime(&unix_date_sec);
1000 int hh = tp->tm_hour;
1001 int DD = tp->tm_mday;
1002 int MM = tp->tm_mon+1;
1003 int YY = tp->tm_year;
1005 char bdate[32]=
"00:00:00-00:00:00.000000";
1006 char tmp[32];
int len=0;
1007 sprintf(tmp,
"%d",YY);len=strlen(tmp);
1008 if(len==3) strncpy(bdate+2-len+1,tmp+1,len-1);
else strncpy(bdate+2-len,tmp,len);
1009 sprintf(tmp,
"%d",MM);len=strlen(tmp);strncpy(bdate+5-len,tmp,len);
1010 sprintf(tmp,
"%d",DD);len=strlen(tmp);strncpy(bdate+8-len,tmp,len);
1011 sprintf(tmp,
"%d",hh);len=strlen(tmp);strncpy(bdate+11-len,tmp,len);
1012 sprintf(tmp,
"%d",mm);len=strlen(tmp);strncpy(bdate+14-len,tmp,len);
1013 sprintf(tmp,
"%d",ss);len=strlen(tmp);strncpy(bdate+17-len,tmp,len);
1014 sprintf(tmp,
"%d",us);len=strlen(tmp);strncpy(bdate+24-len,tmp,len);
1017 printf(
"Baudline Date Format : %s\n",sbdate);
1025 extern char **environ;
1027 if (command == NULL) {
printf(
"System : NULL Command\n");
exit(1);}
1029 if (pid == -1) {
printf(
"System : Fork Failed\n");
exit(1);}
1032 argv[0] =
const_cast<char*
>(
"sh");
1033 argv[1] =
const_cast<char*
>(
"-c");
1034 argv[2] = (
char*)command;
1036 execve(
"/bin/sh", argv, environ);
1040 if (waitpid(pid, &status, 0) == -1) {
1041 if (errno != EINTR) {
printf(
"System : waitpid error %d\n",errno);
exit(1);}
1052 if(
TString(gSystem->GetBuildArch()).Contains(
"linux")) OS=
"Linux";
1053 if(
TString(gSystem->GetBuildArch()).Contains(
"macos")) OS=
"Darwin";
1054 if(OS==
"") {cout <<
"Error : Operative System not supported!!! " << endl;
exit(1);}
1056 signal(sig, SIG_IGN);
1057 printf(
"Do you really want to quit? [y/n] or save? [s] ");
1059 if (c ==
'y' || c ==
'Y') {
1062 if(OS==
"Linux")
sprintf(cmd,
"ps | grep baudline | awk \'{print $1}\' | xargs kill");
1063 if(OS==
"Darwin")
sprintf(cmd,
"ps | grep baudline | awk \'{print $1}\' | xargs kill");
1072 }
else if (c ==
's' || c ==
'S') {
1073 printf(
"click window to be saved\n");
1093 {FRULONG
i, nData, inValid;
1101 unsigned short *dUS;
1106 if(vect == NULL)
return NULL;
1107 if(debugLvl < 1)
return NULL;
1111 nData = vect->nData;
1136 FrVect* outVect=NULL;
1137 if(vect->compress == 0) {
1138 if(vect->type == FR_VECT_4R) {
1139 dF = (
float *) vect->data;
1141 outVect = FrVectNew1D(vect->name, FR_VECT_4R, nData, 0, NULL, NULL);
1142 float* buffer = (
float*)outVect->data;
1144 for(i=0; i<nData; i++) buffer[i]=
filter[chId]->Arma((
double)dF[
i]);
1146 for(i=0; i<nData; i++) buffer[i]=dF[i];
1148 write(ofp, buffer,
sizeof(
float)*nData);
1149 FrVectFree(outVect);outVect=NULL;
1153 else if(vect->type == FR_VECT_8R) {
1154 dD = (
double *) vect->data;
1155 fprintf(fp,
"(double) %s\n",FrVectStat(vect));
1157 outVect = FrVectNew1D(vect->name, FR_VECT_4R, nData, 0, NULL, NULL);
1158 float* buffer = (
float*)outVect->data;
1160 for(i=0; i<nData; i++) buffer[i]=
filter[chId]->Arma(dD[i]);
1162 for(i=0; i<nData; i++) buffer[i]=dD[i];
1164 write(ofp, buffer,
sizeof(
float)*nData);
1165 FrVectFree(outVect);outVect=NULL;
1169 else if(vect->type == FR_VECT_C)
1171 fprintf(fp,
"(byte) %s\n",FrVectStat(vect));
1173 {
for(i=0; i<nData; i++)
1174 {
if(i%20 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1178 else if(vect->type == FR_VECT_2S)
1179 {dS = (
short *) vect->data;
1180 fprintf(fp,
"(short) %s\n",FrVectStat(vect));
1182 {
for(i=0; i<nData; i++)
1183 {
if(i%10 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1187 else if(vect->type == FR_VECT_8S)
1188 {dL = (FRLONG *) vect->data;
1189 fprintf(fp,
"(8S) %s\n",FrVectStat(vect));
1191 {
for(i=0; i<nData; i++)
1192 {
if(i%10 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1193 fprintf(fp,
" %d\"FRLLD\"",dL[i]);}
1196 else if(vect->type == FR_VECT_4S)
1197 {dI = (
int *) vect->data;
1198 fprintf(fp,
"(int) %s\n",FrVectStat(vect));
1200 {
for(i=0; i<nData; i++)
1201 {
if(i%10 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1205 else if(vect->type == FR_VECT_1U)
1206 {dU = (
unsigned char *)vect->dataU;
1207 fprintf(fp,
"(1U) %s\n",FrVectStat(vect));
1209 {
for(i=0; i<nData; i++)
1210 {
if(i%20 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1214 else if(vect->type == FR_VECT_2U)
1215 {dUS = (
unsigned short *) vect->data;
1216 fprintf(fp,
"(2U) %s\n",FrVectStat(vect));
1218 {
for(i=0; i<nData; i++)
1219 {
if(i%10 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1223 else if(vect->type == FR_VECT_8U)
1224 {dUL = (FRULONG *) vect->data;
1225 fprintf(fp,
"(8U) %s\n",FrVectStat(vect));
1227 {
for(i=0; i<nData; i++)
1228 {
if(i%10 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1229 fprintf(fp,
" %d\"FRLLD\"",dUL[i]);}
1232 else if(vect->type == FR_VECT_4U)
1233 {dUI = (
unsigned int *) vect->data;
1234 fprintf(fp,
"(4U) %s\n",FrVectStat(vect));
1236 {
for(i=0; i<nData; i++)
1237 {
if(i%10 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1241 else if(vect->type == FR_VECT_8C)
1242 {dF = (
float *) vect->data;
1243 fprintf(fp,
"(8C) %s\n", FrVectStat(vect));
1245 {
fprintf(fp,
" (%g,%g)", dF[0],dF[1]);
1246 if(nData > 1)
fprintf(fp,
" (%g,%g) ...", dF[2],dF[3]);
1249 {
for(i=0; i<nData; i++)
1250 {
if(i%4 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1251 fprintf(fp,
"(%12g %12g)",dF[2*i],dF[2*i+1]);}
1254 else if(vect->type == FR_VECT_16C)
1255 {dD = (
double *) vect->data;
1256 fprintf(fp,
"(16C) %s\n", FrVectStat(vect));
1258 {
fprintf(fp,
" (%g,%g)",dD[0],dD[1]);
1259 if(nData > 1)
fprintf(fp,
" (%g,%g) ...",dD[2],dD[3]);
1262 {
for(i=0; i<nData; i++)
1263 {
if(i%4 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1264 fprintf(fp,
"(%12g %12g)",dD[2*i],dD[2*i+1]);}
1267 else if(vect->type == FR_VECT_8H)
1268 {dF = (
float *) vect->data;
1269 fprintf(fp,
"(8H) %s\n", FrVectStat(vect));
1272 if(nData > 1)
fprintf(fp,
", (%g,%g) ...", dF[1],dF[nData-1]);
1275 {
fprintf(fp,
"%6d:(%12g %12g)", 0, dF[0], 0.);
1276 for(i=1; i<nData/2; i++)
1277 {
if(i%4 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1278 fprintf(fp,
"(%12g %12g)",dF[i],dF[nData-i]);}
1279 if(nData%2 == 0)
fprintf(fp,
"(%12g 0.)",dF[nData/2]);
1282 else if(vect->type == FR_VECT_16H)
1283 {dD = (
double *) vect->data;
1284 fprintf(fp,
"(16H) %s\n", FrVectStat(vect));
1287 if(nData > 1)
fprintf(fp,
", (%g,%g) ...\n",dD[1],dD[nData-1]);
1290 {
fprintf(fp,
"%6d:(%12g %12g)", 0, dD[0], 0.);
1291 for(i=1; i<nData/2; i++)
1292 {
if(i%4 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1293 fprintf(fp,
"(%12g %12g)",dD[i],dD[nData-i]);}
1294 if(nData%2 == 0)
fprintf(fp,
"(%12g 0.)",dD[nData/2]);
1297 else if(vect->type == FR_VECT_STRING)
1298 {dSt = (
char **) vect->data;
1300 if(dSt[0] != NULL)
fprintf(fp,
" \"%s\"", dSt[0]);
1301 if(dSt[1] != NULL)
fprintf(fp,
" \"%s\"", dSt[1]);
1304 {
fprintf(fp,
" unknown type: %d \n",vect->type );}}
1306 {ratio = (nData*vect->wSize)/(
float) vect->nBytes;
1307 fprintf(fp,
"\n the vector is %.2f compressed (%x) nBytes=%d\"FRLLD\" wSize=%d\n",
1308 ratio,vect->compress,vect->nBytes, vect->wSize);}
1310 if(vect->next != NULL)
1311 {
fprintf(fp,
" Attached information:\n");
1312 FrVectDump(vect->next, fp, debugLvl) ;}
1326 if(vect == NULL)
return(1);
1327 if(vect->nData == 0)
return(1);
1329 double min = 1.e+37;
1330 double max =-1.e+37;
1331 if(FrVectIsValid(vect) != 0)
return(2);
1333 if(vect->type == FR_VECT_C)
1334 {
for(i=0; i<vect->nData; i++) {value = vect->data[
i];
1335 if(value > max) max =
value;
1336 if(value < min) min =
value;}}
1337 else if(vect->type == FR_VECT_2S)
1338 {
for(i=0; i<vect->nData; i++) {value = vect->dataS[
i];
1339 if(value > max) max =
value;
1340 if(value < min) min =
value;}}
1341 else if(vect->type == FR_VECT_8R)
1342 {
for(i=0; i<vect->nData; i++) {
1344 value=
filter[chId]->Arma(vect->dataD[i]);
1345 if(i>vect->nData/2) {
1346 if(value > max) max =
value;
1347 if(value < min) min =
value;
1350 value = vect->dataD[
i];
1351 if(value > max) max =
value;
1352 if(value < min) min =
value;
1355 else if(vect->type == FR_VECT_4R)
1356 {
for(i=0; i<vect->nData; i++) {
1358 value=
filter[chId]->Arma((
double)vect->dataF[i]);
1359 if(i>vect->nData/2) {
1360 if(value > max) max =
value;
1361 if(value < min) min =
value;
1364 value = vect->dataF[
i];
1365 if(value > max) max =
value;
1366 if(value < min) min =
value;
1369 else if(vect->type == FR_VECT_4S)
1370 {
for(i=0; i<vect->nData; i++) {value = vect->dataI[
i];
1371 if(value > max) max =
value;
1372 if(value < min) min =
value;}}
1373 else if(vect->type == FR_VECT_8S)
1374 {
for(i=0; i<vect->nData; i++) {value = vect->dataL[
i];
1375 if(value > max) max =
value;
1376 if(value < min) min =
value;}}
1377 else if(vect->type == FR_VECT_8C)
1379 else if(vect->type == FR_VECT_16C)
1381 else if(vect->type == FR_VECT_2U)
1382 {
for(i=0; i<vect->nData; i++) {value = vect->dataUS[
i];
1383 if(value > max) max =
value;
1384 if(value < min) min =
value;}}
1385 else if(vect->type == FR_VECT_4U)
1386 {
for(i=0; i<vect->nData; i++) {value = vect->dataUI[
i];
1387 if(value > max) max =
value;
1388 if(value < min) min =
value;}}
1389 else if(vect->type == FR_VECT_8U)
1390 {
for(i=0; i<vect->nData; i++) {value = vect->dataUL[
i];
1391 if(value > max) max =
value;
1392 if(value < min) min =
value;}}
1393 else if(vect->type == FR_VECT_1U)
1394 {
for(i=0; i<vect->nData; i++) {value = vect->dataU[
i];
1395 if(value > max) max =
value;
1396 if(value < min) min =
value;}}
1400 if(min > max) max =
min;
1406 vector<std::string> ifileList;
1407 vector<std::string> ipathList;
1408 vector<std::string> ofileList;
1409 vector<std::string> opathList;
1412 in.open(ifile.Data());
1414 cout <<
"FrDisplay - getUniqueFileList : Error Opening Input File : " << ifile.Data() << endl;
1421 in.getline(istring,1024);
1422 if (!in.good())
break;
1425 TObjString* stoken =(TObjString*)token->At(token->GetEntries()-1);
1428 ipathList.push_back(istring);
1429 ifileList.push_back(fName.Data());
1434 for(
int i=0;
i<(
int)ifileList.size();
i++) {
1436 for(
int j=0;
j<(
int)ofileList.size();
j++) {
1437 if(
TString(ofileList[
j].c_str())==
TString(ifileList[
i].c_str())) {check=
true;
break;}
1440 ofileList.push_back(ifileList[
i]);
1441 opathList.push_back(ipathList[i]);
1451 cout <<
"FrDisplay - getUniqueFileList : Error Opening Output File : " << ofile.Data() << endl;
1455 for(
int i=0;
i<(
int)ofileList.size();
i++) {
1456 out << opathList[
i] << endl;
int GpsToGpsLeaps(int gpsSec)
printf("total live time: non-zero lags = %10.1f \n", liveTot)
fprintf(stdout,"start=%f duration=%f rate=%f\n", x.start(), x.size()/x.rate(), x.rate())
double min(double x, double y)
pid_t getProcessId(const char *csProcessName)
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
int System(const char *command)
int GpsToUnixTime(int gpsSec)
void FrFileDumpBinary(FrFile *file, int fp, double *scale, int nchannel, double sampleRate)
void GetBaudlineDateFormat(int gpsSec, int gpsNSec, char *sbdate)
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
cout<< "Selected Pixels : "<< nPix<< endl;wc.cluster(1, 1);SSeries< double > ss
int StartBaudline(int gpsSec, int gpsNSec, double scale, double sampleRate, char *chname, int nchannel, char *params)
FrVect * FrVectDumpBinary(FrVect *vect, int fp, int chId, int debugLvl)
int main(int argc, char **argv)
void ReadParameters(int argc, char **argv)
double fabs(const Complex &x)
strcpy(RunLabel, RUN_LABEL)
in open(HEN_LIST, ios::in)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
double FrVectMax(FrVect *vect, int chId)
void getUniqueFileList(TString ifile, TString ofile)
void StrCat(char **oldbuf, char *more)