39 #include <sys/param.h> 41 #include <sys/sysctl.h> 45 #include "TObjArray.h" 46 #include "TObjString.h" 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" 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" 123 enum Type {
INPUT,
OUTPUT,
TAG,
FIRST,
LAST,
DEBUG,
COMPRESS,
TOP,
BAUDLINE,
OBSERVATORY,
DATATYPE,
FILTER,
ACCESS};
135 void StrCat(
char **oldbuf,
char *more);
137 double FrVectMax(FrVect *vect,
int chId);
140 int StartBaudline(
int gpsSec,
int gpsNSec,
double scale,
double sampleRate,
char* chname,
int nchannel,
char* params);
147 void FrFileDumpBinary(FrFile* file,
int fp,
double* scale,
int nchannel,
double sampleRate);
163 #define MIN_TIME_GAP 256 166 int main(
int argc,
char **argv)
177 double tStart, tEnd, gtime,
start, len;
179 double sampleRate = 0.;
182 double scale[3]={0.,0.,0.};
189 gettimeofday(&tv, NULL);
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);}
199 if(OS==
"Linux")
sprintf(cmd,
"mkdir -p /dev/shm/%s",getlogin());
200 if(OS==
"Darwin")
sprintf(cmd,
"mkdir -p /tmp/%s",getlogin());
207 sprintf(sworkdir,
"%s",getenv(
"FRDISPLAY_WORKDIR"));
210 sprintf(sworksite,
"%s",getenv(
"FRDISPLAY_WORKSITE"));
220 FrLibSetLvl(
Par.debug-3);
221 file = FrFileINew(
Par.name);
223 {
fprintf(stderr,
"Cannot open input file %s\n %s",
224 Par.name, FrErrorGetHistory());
226 file->compress =
Par.comp;
227 file->chkSumFrFlag = FR_YES;
232 {FrFileIDumpT(file, stdout,
Par.debug+1,
Par.tag,
Par.ftime,
Par.ltime );
239 {frame = FrameReadT(file,
Par.ftime);
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());
254 if(((
Par.dType &
ADC) != 0) && (frame->rawData != NULL)) {
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);
263 free((
char*)(
Par.tag));
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);
282 free((
char*)(
Par.tag));
297 while(frame != NULL) {
299 FrFileH *fileH=file->current;
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;
309 if(
Par.tag != NULL) FrameTag(frame,
Par.tag);
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;
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);}}}
331 {FrameDump(frame, stdout,
Par.debug);
332 if(
Par.comp != 0) FrameCompDump(frame, stdout,
Par.debug);}
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)) {
340 for(xadc = frame->rawData->firstAdc; xadc != NULL; xadc=xadc->next) {
342 {
printf(
"Multichannel with num channel gt 3 not allowed !!!\n");
exit(1);}
344 size = xadc->data->nData;
346 if(size!=xadc->data->nData)
347 {
printf(
"Multichannel with different size not allowed !!!\n");
exit(1);}
350 sampleRate = xadc->sampleRate;
352 if(sampleRate!=xadc->sampleRate)
353 {
printf(
"Multichannel with different sampleRates not allowed !!!\n");
exit(1);}
356 if(
Par.filter!=NULL &&
filter[nchannel]==NULL) {
358 sprintf(sratepar,
" -s %f ",sampleRate);
360 filter[nchannel] =
new CWB::Filter(
Par.filter);
362 scale[nchannel]=
FrVectMax(xadc->data,nchannel);
363 if(scale[nchannel]>0) scale[nchannel]=32768./scale[nchannel];
366 sprintf(chname,
"%s",xadc->name);
368 sprintf(chname,
"%s %s",chname,xadc->name);
374 {
printf(
"The request channel is not present in the frame !!!\n");
exit(1);}
380 for(
int j=0;
j<nchannel;
j++) scale[
j]=32768./scale[
j];
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);
390 for(adc = frame->rawData->firstAdc; adc != NULL; adc=adc->next) {
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;
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);
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);}}
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);}}
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);}}
425 if((fp==0) && (
Par.debug > 2)) {
428 for(proc = frame->procData; proc != NULL; proc = proc->next) {
429 printf(
"Reconstructed Data: %s\n", proc->name);
431 {
printf(
"Multichannel with num channel gt 3 not allowed !!!\n");
exit(1);}
433 size = proc->data->nData;
435 if(size!=proc->data->nData)
436 {
printf(
"Multichannel with different size not allowed !!!\n");
exit(1);}
439 if(proc->data->dx[0] < 1) sampleRate = 1./proc->data->dx[0];
440 else {
printf(
"sampleRate not allowed !!!\n");
exit(1);}
442 if(sampleRate!=1./proc->data->dx[0])
443 {
printf(
"Multichannel with different sampleRates not allowed !!!\n");
exit(1);}
446 if(
Par.filter!=NULL &&
filter[nchannel]==NULL) {
448 sprintf(sratepar,
" -s %f ",sampleRate);
450 filter[nchannel] =
new CWB::Filter(
Par.filter);
452 scale[nchannel]=
FrVectMax(proc->data,nchannel);
453 if(scale[nchannel]>0) scale[nchannel]=32768./scale[nchannel];
456 sprintf(chname,
"%s",proc->name);
458 sprintf(chname,
"%s %s",chname,proc->name);
464 {
printf(
"The request channel is not present in the frame !!!\n");
exit(1);}
470 for(
int j=0;
j<nchannel;
j++) scale[
j]=32768./scale[
j];
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);
480 for(proc = frame->procData; proc != NULL; proc = proc->next) {
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;
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);
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);}}
503 if(
Par.debug > 1) FrameStat(frame, stdout);
505 if(
Par.nTop != -2) FrameDumpTopADC(frame, stdout,
Par.nTop,
Par.comp);
511 frame = FrameRead(file);
519 FrFileIStat(file, stdout);
522 printf(
"\n\nhit Ctrl-C\n\n");
529 void FrFileDumpBinary(FrFile* file,
int fp,
double* scale,
int nchannel,
double sampleRate) {
533 FrFileH *fileH=file->fileH;
535 cout << fileH->fileName << endl;
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;
548 if(tCurrent!=0 && nVect==0) {
549 if(cStart!=tCurrent) {
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);
562 cout <<
"Error : data not contiguous !!!" << endl;
569 outVect[nVect]=FrFileIGetVectF(cfile,
chnames[nVect], cStart, clength);
570 float* dF = (
float *) outVect[nVect]->data;
572 for(
int i=0;
i<outVect[nVect]->nData;
i++)
573 dF[
i]=
filter[nVect]->Arma((
double)dF[
i]);
578 FrVect* dumpVect = FrVectNew1D(const_cast<char*>(
"dumpVect"), FR_VECT_4R, nchannel*outVect[0]->nData, 0, NULL, NULL);
579 float* buffer = (
float*)dumpVect->data;
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);
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);}
629 for (i=1; i<argc; i++)
630 {
if (strcmp(argv[i],
"-h") == 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;}
663 {
Par.ftime = atof(argv[i]);}
664 else {
Par.frun =
Par.ftime;
665 Par.fframe = atoi(argv[i]);}}
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]);}
673 if(type ==
TOP) {
Par.nTop = atoi(argv[i]);}
689 if(
Par.filter!=NULL) {
690 if(strstr(
Par.filter,
"help")!=NULL) {
691 printf(
"filter help !!!\n");
699 if(
Par.baudline!=NULL) {
700 if(strstr(
Par.baudline,
"help")!=NULL) {
701 printf(
"baudline help !!!\n");
704 if(getenv(
"BAUDLINE_CMD")!=NULL) {
705 printf(
"BAUDLINE_CMD : %s\n",getenv(
"BAUDLINE_CMD"));
706 sprintf(baudline,
"%s",getenv(
"BAUDLINE_CMD"));}
708 {
printf(
"Cannot get BAUDLINE_CMD env\n");
exit(1);}
710 sprintf(cmd,
"%s -help",baudline);
720 if(
Par.baudline!=NULL) {
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();
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);}
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());
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());
758 int estat = gSystem->GetPathInfo(baudline_rc_path,&
id,&size,&flags,&mt);
762 in.open(baudline_rc_path,
ios::in);
763 if (!in.good()) {cout <<
"Error Opening File : " << baudline_rc_path << endl;
exit(1);}
766 out.open(baudline_rc_tmp_path,
ios::out);
767 if (!out.good()) {cout <<
"Error Opening File : " << baudline_rc_tmp_path << endl;
exit(1);}
773 in.getline(line,256);
774 if (!in.good())
break;
777 if(sline.Contains(
"downmix")) {out <<
"downmix " << downmix << endl;flag=
true;}
778 else out << sline.Data() << endl;
780 if(!flag) {out <<
"downmix " << downmix << endl;}
785 sprintf(cmd,
"mv %s %s",baudline_rc_tmp_path,baudline_rc_path);
796 if((
Par.name!=NULL)&&(
TString(
Par.name).Contains(
".ffl"))==1) {
798 TString ffl_file_path = gSystem->ExpandPathName(
Par.name);
801 in.open(ffl_file_path.Data(),
ios::in);
802 if (!in.good()) {cout <<
"Error Opening File : " << ffl_file_path.Data() << endl;
exit(1);}
808 if (!out.good()) {cout <<
"Error Opening File : " <<
baudline_FFL << endl;
exit(1);}
813 double dummy1,dummy2;
815 in >> file_path >> start >> lenght >> dummy1 >> dummy2;
816 if (!in.good())
break;
819 if((start>=
Par.ftime)&&(start<=
Par.ltime)) {
821 out << file_path <<
" " << start <<
" " << lenght <<
" " << dummy1 <<
" " << dummy2 << endl;
826 free((
char*)(
Par.name));
833 if((
Par.name!=NULL)&&(strcmp(
Par.name,
"ldf"))==0) {
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 ");
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);}
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);
859 Long_t xid,xsize,xflags,xmt;
860 int xestat = gSystem->GetPathInfo(
baudline_FFL,&xid,&xsize,&xflags,&xmt);
861 if (xestat!=0 || xsize==0) {
872 free((
char*)(
Par.name));
884 {
fprintf(stderr,
" Please provide at least one input file\n");
890 if(
Par.ltime <
Par.ftime)
Par.ltime +=
Par.ftime -1.e-6;
893 {
printf(
"-----------Parameters used--------------\n");
896 printf(
" First frame : %d %d (GPS=%.1f)\n",
898 if(
Par.ltime < 100000000)
900 else printf(
" Last frame : %d %d (GPS=%.1f)\n",
902 printf(
" Debug level : %d\n",
Par.debug);
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");}
923 lenMore = strlen(more);
926 {*oldbuf = (
char*)malloc(strlen(more) + 1);
930 newbuf = (
char*)malloc( strlen(*oldbuf) + lenMore + 2);
931 sprintf(newbuf,
"%s %s",*oldbuf, more);
939 double sampleRate,
char* chname,
int nchannel,
char* params) {
943 printf(
"date : %s - chname : %s\n",sbdate,chname);
944 printf(
"sampleRate %f - scale %e\n",sampleRate,scale);
950 if(getenv(
"BAUDLINE_CMD")!=NULL) {
951 printf(
"BAUDLINE_CMD : %s\n",getenv(
"BAUDLINE_CMD"));
952 sprintf(baudline,
"%s",getenv(
"BAUDLINE_CMD"));}
954 {
printf(
"Cannot get BAUDLINE_CMD env\n");
exit(1);}
957 if(getenv(
"BAUDLINE_PALETTE")!=NULL) {
958 printf(
"BAUDLINE_PALETTE : %s\n",getenv(
"BAUDLINE_PALETTE"));
959 sprintf(palette,
"%s",getenv(
"BAUDLINE_PALETTE"));}
961 {
printf(
"Cannot get BAUDLINE_PALETTE env\n");
exit(1);}
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);}
972 if(OS==
"Linux")
sprintf(cmd,
"mknod %s p",pipe_name);
973 if(OS==
"Darwin")
sprintf(cmd,
"mkfifo %s",pipe_name);
977 if(params==NULL)
StrCat(&(params),const_cast<char*>(
""));
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);
992 printf(
"Baudline pid : %d\n",pid);
998 int fp =
open(pipe_name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | O_NONBLOCK);
1000 {
fprintf(stderr,
"Cannot open output pipe %s\n %s", pipe_name, FrErrorGetHistory());
1008 printf(
"gpsSec %d - gpsNSec %d\n",gpsSec,gpsNSec);
1009 printf(
"UTC : %s\n",FrStrUTC(gpsSec,0));
1011 time_t unix_date_sec = FrGPS2UTC(gpsSec, 0);
1012 int us = gpsNSec/1000;
1014 struct tm* tp = gmtime(&unix_date_sec);
1016 int ss = tp->tm_sec;
1017 int mm = tp->tm_min;
1018 int hh = tp->tm_hour;
1019 int DD = tp->tm_mday;
1020 int MM = tp->tm_mon+1;
1021 int YY = tp->tm_year;
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);
1035 printf(
"Baudline Date Format : %s\n",sbdate);
1043 extern char **environ;
1045 if (command == NULL) {
printf(
"System : NULL Command\n");
exit(1);}
1047 if (pid == -1) {
printf(
"System : Fork Failed\n");
exit(1);}
1050 argv[0] =
const_cast<char*
>(
"sh");
1051 argv[1] =
const_cast<char*
>(
"-c");
1052 argv[2] = (
char*)command;
1054 execve(
"/bin/sh", argv, environ);
1058 if (waitpid(pid, &status, 0) == -1) {
1059 if (errno != EINTR) {
printf(
"System : waitpid error %d\n",errno);
exit(1);}
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);}
1074 signal(sig, SIG_IGN);
1075 printf(
"Do you really want to quit? [y/n] or save? [s] ");
1077 if (c ==
'y' || c ==
'Y') {
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");
1090 }
else if (c ==
's' || c ==
'S') {
1091 printf(
"click window to be saved\n");
1111 {FRULONG
i, nData, inValid;
1119 unsigned short *dUS;
1124 if(vect == NULL)
return NULL;
1125 if(debugLvl < 1)
return NULL;
1129 nData = vect->nData;
1154 FrVect* outVect=NULL;
1155 if(vect->compress == 0) {
1156 if(vect->type == FR_VECT_4R) {
1157 dF = (
float *) vect->data;
1159 outVect = FrVectNew1D(vect->name, FR_VECT_4R, nData, 0, NULL, NULL);
1160 float* buffer = (
float*)outVect->data;
1162 for(i=0; i<nData; i++) buffer[i]=
filter[chId]->Arma((
double)dF[
i]);
1164 for(i=0; i<nData; i++) buffer[i]=dF[i];
1166 write(ofp, buffer,
sizeof(
float)*nData);
1167 FrVectFree(outVect);outVect=NULL;
1171 else if(vect->type == FR_VECT_8R) {
1172 dD = (
double *) vect->data;
1173 fprintf(fp,
"(double) %s\n",FrVectStat(vect));
1175 outVect = FrVectNew1D(vect->name, FR_VECT_4R, nData, 0, NULL, NULL);
1176 float* buffer = (
float*)outVect->data;
1178 for(i=0; i<nData; i++) buffer[i]=
filter[chId]->Arma(dD[i]);
1180 for(i=0; i<nData; i++) buffer[i]=dD[i];
1182 write(ofp, buffer,
sizeof(
float)*nData);
1183 FrVectFree(outVect);outVect=NULL;
1187 else if(vect->type == FR_VECT_C)
1189 fprintf(fp,
"(byte) %s\n",FrVectStat(vect));
1191 {
for(i=0; i<nData; i++)
1192 {
if(i%20 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1196 else if(vect->type == FR_VECT_2S)
1197 {dS = (
short *) vect->data;
1198 fprintf(fp,
"(short) %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_8S)
1206 {dL = (FRLONG *) vect->data;
1207 fprintf(fp,
"(8S) %s\n",FrVectStat(vect));
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]);}
1214 else if(vect->type == FR_VECT_4S)
1215 {dI = (
int *) vect->data;
1216 fprintf(fp,
"(int) %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_1U)
1224 {dU = (
unsigned char *)vect->dataU;
1225 fprintf(fp,
"(1U) %s\n",FrVectStat(vect));
1227 {
for(i=0; i<nData; i++)
1228 {
if(i%20 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1232 else if(vect->type == FR_VECT_2U)
1233 {dUS = (
unsigned short *) vect->data;
1234 fprintf(fp,
"(2U) %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_8U)
1242 {dUL = (FRULONG *) vect->data;
1243 fprintf(fp,
"(8U) %s\n",FrVectStat(vect));
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]);}
1250 else if(vect->type == FR_VECT_4U)
1251 {dUI = (
unsigned int *) vect->data;
1252 fprintf(fp,
"(4U) %s\n",FrVectStat(vect));
1254 {
for(i=0; i<nData; i++)
1255 {
if(i%10 == 0)
fprintf(fp,
"\n%d\"FRLLD\":",i);
1259 else if(vect->type == FR_VECT_8C)
1260 {dF = (
float *) vect->data;
1261 fprintf(fp,
"(8C) %s\n", FrVectStat(vect));
1263 {
fprintf(fp,
" (%g,%g)", dF[0],dF[1]);
1264 if(nData > 1)
fprintf(fp,
" (%g,%g) ...", dF[2],dF[3]);
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]);}
1272 else if(vect->type == FR_VECT_16C)
1273 {dD = (
double *) vect->data;
1274 fprintf(fp,
"(16C) %s\n", FrVectStat(vect));
1276 {
fprintf(fp,
" (%g,%g)",dD[0],dD[1]);
1277 if(nData > 1)
fprintf(fp,
" (%g,%g) ...",dD[2],dD[3]);
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]);}
1285 else if(vect->type == FR_VECT_8H)
1286 {dF = (
float *) vect->data;
1287 fprintf(fp,
"(8H) %s\n", FrVectStat(vect));
1290 if(nData > 1)
fprintf(fp,
", (%g,%g) ...", dF[1],dF[nData-1]);
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]);
1300 else if(vect->type == FR_VECT_16H)
1301 {dD = (
double *) vect->data;
1302 fprintf(fp,
"(16H) %s\n", FrVectStat(vect));
1305 if(nData > 1)
fprintf(fp,
", (%g,%g) ...\n",dD[1],dD[nData-1]);
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]);
1315 else if(vect->type == FR_VECT_STRING)
1316 {dSt = (
char **) vect->data;
1318 if(dSt[0] != NULL)
fprintf(fp,
" \"%s\"", dSt[0]);
1319 if(dSt[1] != NULL)
fprintf(fp,
" \"%s\"", dSt[1]);
1322 {
fprintf(fp,
" unknown type: %d \n",vect->type );}}
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);}
1328 if(vect->next != NULL)
1329 {
fprintf(fp,
" Attached information:\n");
1330 FrVectDump(vect->next, fp, debugLvl) ;}
1344 if(vect == NULL)
return(1);
1345 if(vect->nData == 0)
return(1);
1347 double min = 1.e+37;
1348 double max =-1.e+37;
1349 if(FrVectIsValid(vect) != 0)
return(2);
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++) {
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;
1368 value = vect->dataD[
i];
1369 if(value > max) max =
value;
1370 if(value < min) min =
value;
1373 else if(vect->type == FR_VECT_4R)
1374 {
for(i=0; i<vect->nData; i++) {
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;
1382 value = vect->dataF[
i];
1383 if(value > max) max =
value;
1384 if(value < min) min =
value;
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)
1397 else if(vect->type == FR_VECT_16C)
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;}}
1418 if(min > max) max =
min;
1424 vector<std::string> ifileList;
1425 vector<std::string> ipathList;
1426 vector<std::string> ofileList;
1427 vector<std::string> opathList;
1430 in.open(ifile.Data());
1432 cout <<
"FrDisplay - getUniqueFileList : Error Opening Input File : " << ifile.Data() << endl;
1439 in.getline(istring,1024);
1440 if (!in.good())
break;
1443 TObjString* stoken =(TObjString*)token->At(token->GetEntries()-1);
1446 ipathList.push_back(istring);
1447 ifileList.push_back(fName.Data());
1452 for(
int i=0;
i<(
int)ifileList.size();
i++) {
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;}
1458 ofileList.push_back(ifileList[
i]);
1459 opathList.push_back(ipathList[i]);
1469 cout <<
"FrDisplay - getUniqueFileList : Error Opening Output File : " << ofile.Data() << endl;
1473 for(
int i=0;
i<(
int)ofileList.size();
i++) {
1474 out << opathList[
i] << endl;
int GpsToGpsLeaps(int gpsSec)
double min(double x, double y)
pid_t getProcessId(const char *csProcessName)
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
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)
printf("total live time: non-zero lags = %10.1f \, liveTot)
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)