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