Logo coherent WaveBurst  
Library Reference Guide
Logo
SymmArray.cc
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Sergey Klimenko, Valentin Necula
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 #include "SymmArray.hh"
20 
21 
22 ClassImp(SymmArray<double>)
23 
24 
25 template <class Record>
27 { //printf("Hello SymmArray::SymmArray, n=%d\n", n);
28  Size = 2*n+1; //mind the plus
29  rec = new Record[Size];
30  zero = rec+n;
31  recSize = sizeof(Record);
32  if(rec ==0 )printf("SymmArray::SymmArray : memory not allocated\n");
33 }
34 
35 template <class Record>
37 { zero = rec = 0;
38  *this=a;
39 }
40 
41 template <class Record>
43 { recSize = other.recSize;
44  Resize0(other.Size);
45  for(int i=0; i<Size; ++i)rec[i] = other.rec[i];
46  zero = rec + Size/2;
47  return *this;
48 }
49 
50 template <class Record>
52 { delete [] rec;
53 }
54 
55 template <class Record>
57 { Resize0(sz = 2*sz+1);
58 }
59 
60 template <class Record>
62 { if(sz==Size)return;
63  delete [] rec;
64  Size = sz;
65  rec = new Record[Size];
66  zero = rec + Size/2;
67 }
68 
69 template <class Record>
71 { fwrite(&Size, sizeof(int), 1, f);
72  fwrite(&recSize, sizeof(int), 1, f);
73  if(Size)fwrite(rec, recSize, Size, f);
74 }
75 
76 template <class Record>
78 { int newSize, newRecSz;
79  fread(&newSize, sizeof(int), 1, f);
80  fread(&newRecSz, sizeof(int), 1, f);
81  if(newRecSz!=recSize){
82  printf("Array::Read abort b/c different record size %d %d\n", newRecSz,
83  recSize);
84  return;
85  }
86  if(newSize != Size){
87  if(Size)delete [] rec;
88  Size = newSize;
89  rec = new Record[Size];
90  zero = rec + Size/2;
91  }
92  fread(rec, recSize, Size, f);
93  //printf("cool\n");
94 }
95 
96 template <class Record>
98 { for(int i=0; i<Size; ++i)rec[i] = x;
99 }
100 
101 template class SymmArray<int>;
102 template class SymmArray<float>;
103 template class SymmArray<double>;
virtual ~SymmArray()
Definition: SymmArray.cc:51
int Size
Definition: SymmArray.hh:46
wavearray< double > a(hp.size())
int n
Definition: cwb_net.C:28
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\ layers : "<< nLAYERS<< "\ dF(hz) : "<< dF<< "\ dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1) *itime+ifreq;double time=itime *dT;double freq=(ifreq >0) ? ifreq *dF :dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
SymmArray(unsigned int n=0)
Definition: SymmArray.cc:26
i drho i
Record * rec
Definition: SymmArray.hh:47
void Resize(int sz)
Definition: SymmArray.cc:56
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
Definition: ComputeSNR.C:75
printf("total live time: non-zero lags = %10.1f \, liveTot)
void Init(Record x)
Definition: SymmArray.cc:97
void Resize0(int sz)
Definition: SymmArray.cc:61
SymmArray & operator=(const SymmArray &other)
Definition: SymmArray.cc:42
void Write(FILE *f)
Definition: SymmArray.cc:70
void Read(FILE *f)
Definition: SymmArray.cc:77
int recSize
Definition: SymmArray.hh:49