Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rdfr.cc
Go to the documentation of this file.
1 
2 
3 /*---------------------------------------------------------------------
4 
5  */
6 // Function Read transparently reads both WAT-compressed
7 // and standard-compressed ADC data from single frame file.
8 // tlen - length of data in seconds,
9 // tskip - skip time from the begining of the file, in seconds
10 // *cname - ADC channel name
11 // *fname - frame file name
12 // seek - if true then it is allowed to seek data continuation
13 // in next file which name the function will try to guess
14 #include <iostream>
15 #include "rdfr.hh"
16 template<class X> wavearray<X>* rdfrm(double tlen, char *cname, char *fname, double tskip);
17 wavearray<float>* rdfrmF(double ten, char *cnme, char *name, double skip);
18 wavearray<double>* rdfrmD(double len, char *came, char *fame, double tkip);
19 
20 
21 template<class X> wavearray<X>* rdfrm(double tlen, char *cname, char *fname, double tskip)
22 {
23  FrFile *iFile = FrFileINew(fname);
24  if(iFile == NULL)
25  {
26  printf(" rdfrm(): cannot open the input file %s\n", fname);
27  return NULL;
28  }
29 
30  unsigned long int i;
31  if (tskip<0) tskip=0.0;
32  double ra=0.0,gt0,gts,gte,ntlen=tskip+tlen;
33  gts = FrFileITStart(iFile);
34  gte = FrFileITEnd(iFile);
35  gt0 = gts; // GPS time of data begin
36  if ((gt0 + ntlen) > gte)
37  {
38  gte=gt0 + ntlen - gte;
39  printf("readfrm error:You are trying to access %f seconds more than are available in this file\n",gte);
40  return NULL;
41  }
42  FrVect *adc=NULL;
43  adc = FrFileIGetV(iFile, cname, 0.0,ntlen);
44  if (adc == NULL || adc->data ==NULL)
45  {
46  printf(" ReadFrFile() error: channel %s is not found in file %s\n", cname, fname);
47  return NULL;
48  }
49 
50  wavearray<X> *out=new wavearray<X>(adc->nData);
51  switch(adc->type)
52  {
53  case FR_VECT_C : //vector of char
54  for(i=0;i<adc->nData;i++)out->data[i]=adc->data[i];
55  break;
56  case FR_VECT_1U : //vector of unsigned char
57  for(i=0;i<adc->nData;i++)out->data[i]=adc->dataU[i];
58  break;
59  case FR_VECT_2U : //vector of unsigned short
60  for(i=0;i<adc->nData;i++)out->data[i]=adc->dataUS[i];
61  break;
62  case FR_VECT_2S : //vector of short
63  for(i=0;i<adc->nData;i++)out->data[i]=adc->dataS[i];
64  break;
65  case FR_VECT_4U : //vector of unsigned int
66  for(i=0;i<adc->nData;i++)out->data[i]=adc->dataUI[i];
67  break;
68  case FR_VECT_4R : //vector of float
69  for(i=0;i<adc->nData;i++)out->data[i]=adc->dataF[i];
70  break;
71  case FR_VECT_4S : //vector of int
72  for(i=0;i<adc->nData;i++)out->data[i]=adc->dataI[i];
73  break;
74  case FR_VECT_8U : //vector of unsigned long
75  for(i=0;i<adc->nData;i++)out->data[i]=adc->dataUL[i];
76  break;
77  case FR_VECT_8R : //vector of double
78  for(i=0;i<adc->nData;i++)out->data[i]=adc->dataD[i];
79  break;
80  case FR_VECT_8S : //vector of long
81  for(i=0;i<adc->nData;i++)out->data[i]=adc->dataL[i];
82  break;
83  default:
84  cout<<"Can't find the type of FrVect data"<<endl;
85  out=NULL;
86  }
87 
88  ra=double(adc->nData/ntlen);
89  FrVectFree(adc);
90  FrFileIEnd(iFile);
91 
92 
93  wavearray<X> *lout=new wavearray<X>(size_t(tlen*ra));
94  for(i=0;i<lout->size();i++)lout->data[i]=out->data[i+int(tskip*ra)];
95  lout->rate(ra);
96  lout->start(gt0);
97  return lout;
98 }
99 
100 
101 wavearray<float>* rdfrmF(double ten, char *cnme, char *name, double skip)
102 {
103  wavearray<float> *bib=rdfrm<float>(ten,cnme,name,skip);
104  return bib;
105 }
106 wavearray<double>* rdfrmD(double len, char *came, char *fame, double tkip)
107 {
108  wavearray<double> *bb=rdfrm<double>(len,came,fame,tkip);
109  return bb;
110 }
111 
112 
wavearray< X > * rdfrm(double tlen, char *cname, char *fname, double tskip)
Definition: rdfr.cc:21
virtual size_t size() const
Definition: wavearray.hh:127
printf("total live time: non-zero lags = %10.1f \n", liveTot)
virtual void rate(double r)
Definition: wavearray.hh:123
par[0] name
virtual void start(double s)
Definition: wavearray.hh:119
i drho i
ofstream out
Definition: cwb_merge.C:196
wavearray< double > * rdfrmD(double len, char *came, char *fame, double tkip)
Definition: rdfr.cc:106
double ra
Definition: ConvertGWGC.C:46
char fname[1024]
wavearray< float > * rdfrmF(double ten, char *cnme, char *name, double skip)
Definition: rdfr.cc:101
DataType_t * data
Definition: wavearray.hh:301