[1661] | 1 | /* Lecteur Fits de bolometre */
|
---|
[2615] | 2 | #include "sopnamsp.h"
|
---|
[1661] | 3 | #include "machdefs.h"
|
---|
| 4 | #include <stdlib.h>
|
---|
| 5 | #include <stdio.h>
|
---|
| 6 | #include "pexceptions.h"
|
---|
| 7 | #include "fboloread.h"
|
---|
| 8 |
|
---|
| 9 | #define _NCOL_BOLO_MIN_ 5
|
---|
| 10 |
|
---|
| 11 | /*!
|
---|
| 12 | \class SOPHYA::FitsBoloRead
|
---|
| 13 | \ingroup FitsIOServer
|
---|
| 14 | Class for defining a bolometer by connecting columns out FITS files
|
---|
| 15 | \verbatim
|
---|
| 16 | -- Exemple:
|
---|
[4029] | 17 | FitsBoloRead fbr;
|
---|
[1661] | 18 | fbr.SetDebug(2);
|
---|
| 19 |
|
---|
| 20 | fbr.SetBolo("bolomuv","bolo.fits",0);
|
---|
| 21 | fbr.SetFlag("flag");
|
---|
| 22 | fbr.SetSNum("samplenum");
|
---|
| 23 | fbr.SetAlpha("alpha","alpha.fits",0);
|
---|
| 24 | fbr.SetDelta("delta");
|
---|
| 25 | int col1 = fbr.AddCol("altitude","other_file.fits");
|
---|
| 26 | fbr.Print(2);
|
---|
| 27 | cout<<"NRows= "<<fbr.GetNbLine()<<endl;
|
---|
| 28 |
|
---|
| 29 | cout<<"Reading element by elements"<<endl;
|
---|
[3128] | 30 | for(LONGLONG i=0; i<fbr.GetNbLine(); i++) {
|
---|
[1661] | 31 | double a = fbr.GetAlpha(i);
|
---|
| 32 | double d = fbr.GetDelta(i);
|
---|
| 33 | double b = fbr.GetBolo(i);
|
---|
| 34 | double s = fbr.GetSNum(i);
|
---|
| 35 | double f = fbr.GetFlag(i);
|
---|
| 36 | double c1 = fbr.GetCol(col1,i);
|
---|
| 37 | cout<<i<<" s="<<(long long)s<<" b="<<b<<" f="<<f
|
---|
| 38 | <<" a="<<a<<" d="<<d<<" c1="c1<<endl;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | cout<<"Reading with vectors"<<endl;
|
---|
| 42 | TVector<double> Va,Vd,Vb,Vf;
|
---|
| 43 | TVector<float> Vc1;
|
---|
| 44 | TVector<int_4> Vs;
|
---|
[3128] | 45 | for(LONGLONG i=0, istep=1000; i<fbr.GetNbLine(); i+=istep) {
|
---|
| 46 | LONGLONG i2=i+istep-1; if(i2>=fbr.GetNbLine()) i2=fbr.GetNbLine()-1;
|
---|
[1661] | 47 | fbr.GetSNum(i,i2,Vs);
|
---|
| 48 | fbr.GetBolo(i,i2,Vb);
|
---|
| 49 | fbr.GetFlag(i,i2,Vf);
|
---|
| 50 | fbr.GetAlpha(i,i2,Va);
|
---|
| 51 | fbr.GetDelta(i,i2,Vd);
|
---|
| 52 | fbr.GetCol(col1,i,i2,Vc1);
|
---|
| 53 | }
|
---|
| 54 | \endverbatim
|
---|
| 55 | */
|
---|
| 56 |
|
---|
| 57 | //////////////////////////////////////////////////////////////
|
---|
| 58 | /*!
|
---|
| 59 | Constructor. Define the structure of the bolometer columns connector.
|
---|
| 60 | */
|
---|
[4029] | 61 | FitsBoloRead::FitsBoloRead(void)
|
---|
| 62 | : NBline(0), DbgLevel(0)
|
---|
[1661] | 63 | {
|
---|
| 64 | for(int i=0;i<_NCOL_BOLO_MIN_;i++) {
|
---|
| 65 | mFName.push_back("");
|
---|
| 66 | mLabel.push_back("");
|
---|
| 67 | mHDU.push_back(0);
|
---|
| 68 | mFABT.push_back(NULL);
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /*! Destructor */
|
---|
| 73 | FitsBoloRead::~FitsBoloRead(void)
|
---|
| 74 | {
|
---|
| 75 | for(int i=0; i<(int)mFABT.size(); i++)
|
---|
| 76 | if(mFABT[i]!=NULL) {delete mFABT[i]; mFABT[i]=NULL;}
|
---|
| 77 | // NBline=0; mFABT.resize(_NCOL_BOLO_MIN_);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | //////////////////////////////////////////////////////////////
|
---|
| 81 | /*!
|
---|
| 82 | Add the column number "col" to the bolometer connector.
|
---|
| 83 | Protected method. Do not use directly but read the doc.
|
---|
| 84 | \param col : number of the column to be added
|
---|
| 85 | \param label : label of the column
|
---|
| 86 | \param fname : FITS file name containing the column
|
---|
| 87 | \param ihdu : FITS HDU containing the column
|
---|
| 88 | \verbatim
|
---|
| 89 | - col<0 : add a new column
|
---|
| 90 | col<size : fill a new column
|
---|
| 91 | col>=size : throw exception
|
---|
| 92 | - The method also set the number of rows of the Bolometer connector
|
---|
| 93 | as the smallest number of rows of the connected columns.
|
---|
| 94 | That could be changed by using the SetNbLine() method.
|
---|
| 95 | -----------------------------------------------------------------
|
---|
| 96 | It is very boring to define all the fits file names and hdu for
|
---|
| 97 | the predefined TOI SNum,Bolo,Flag,Alpha,Delta as some of them
|
---|
| 98 | are in the same FITS file (and HDU).
|
---|
| 99 | The connector pre-defined a logic as follow:
|
---|
| 100 | ... if fname_Bolo=="" try fname_SNum
|
---|
| 101 | ... if fname_SNum=="" try fname_Bolo
|
---|
| 102 | ... if fname_Flag=="" try fname_Bolo first
|
---|
| 103 | ... fname_SNum second.
|
---|
| 104 | ... if fname_Alpha=="" try fname_Delta first
|
---|
| 105 | ... fname_Bolo second
|
---|
| 106 | ... fname_SNum third
|
---|
| 107 | ... if fname_Delta=="" try fname_Alpha first
|
---|
| 108 | ... fname_Bolo second
|
---|
| 109 | ... fname_SNum third
|
---|
| 110 | Of course, the decision differs depending on the order
|
---|
| 111 | of calling the addcol() method.
|
---|
| 112 | -----------------------------------------------------------------
|
---|
| 113 | \endverbatim
|
---|
| 114 | \warning ihdu[1,nhdu], col=[0,nrow-1]
|
---|
| 115 | \return The number of the column added in the FitsBoloRead connector.
|
---|
| 116 | */
|
---|
| 117 | int FitsBoloRead::addcol(int col,const char *label,const char* fname,int ihdu)
|
---|
| 118 | {
|
---|
| 119 | if(col>=(int)mFABT.size()) // Not an existing column
|
---|
| 120 | throw ParmError("FitsBoloRead::addcol: column number not existing\n");
|
---|
| 121 |
|
---|
| 122 | if(col>=0) { // Already filled column
|
---|
[2087] | 123 | if(mFABT[col]!=NULL) {delete mFABT[col]; mFABT[col]=NULL;}
|
---|
[1661] | 124 | } else { // Prepare for new column
|
---|
| 125 | col=mFABT.size();
|
---|
| 126 | mFName.push_back("");
|
---|
| 127 | mLabel.push_back("");
|
---|
| 128 | mHDU.push_back(0);
|
---|
| 129 | mFABT.push_back(NULL);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | if(fname) mFName[col] = fname; else mFName[col] = "";
|
---|
| 133 | mLabel[col] = label;
|
---|
| 134 | mHDU[col] = ihdu;
|
---|
| 135 | // Try to guess the fname and ihdu if not defined
|
---|
| 136 | Gess_If_Not_Define(col);
|
---|
| 137 |
|
---|
| 138 | mFABT[col] =
|
---|
[4029] | 139 | new FitsABTColRead(mFName[col].c_str(),mLabel[col].c_str(),mHDU[col],(int)DbgLevel);
|
---|
[1661] | 140 |
|
---|
| 141 | // Set the number of rows as the smallest of for connected columns
|
---|
[3128] | 142 | LONGLONG nrows = mFABT[col]->GetNbLine();
|
---|
[1661] | 143 | if(NBline==0) NBline = nrows;
|
---|
| 144 | else if(nrows<NBline) NBline = nrows;
|
---|
| 145 |
|
---|
| 146 | return col;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | /*!
|
---|
| 150 | Guess what are the File name and HDU if they are not explicitly defined.
|
---|
| 151 | (See addcol() doc)
|
---|
| 152 | */
|
---|
| 153 | void FitsBoloRead::Gess_If_Not_Define(int col)
|
---|
| 154 | {
|
---|
| 155 | if(col<0 || col>=_NCOL_BOLO_MIN_) return; // Pas une colonne predefinie
|
---|
| 156 | if(mFName[col].size()>0) return; // definition explicite
|
---|
| 157 |
|
---|
| 158 | if(col==ColSNum) { // Cas du Sample Number
|
---|
| 159 | if(mFName[ColBolo].size()>0)
|
---|
| 160 | {mFName[col]=mFName[ColBolo]; mHDU[col]=mHDU[ColBolo]; return;}
|
---|
| 161 |
|
---|
| 162 | } else if(col==ColBolo) { // Cas du Bolo
|
---|
| 163 | if(mFName[ColSNum].size()>0)
|
---|
| 164 | {mFName[col]=mFName[ColSNum]; mHDU[col]=mHDU[ColSNum]; return;}
|
---|
| 165 |
|
---|
| 166 | } else if(col==ColFlag) { // Cas du Flag
|
---|
| 167 | if(mFName[ColBolo].size()>0)
|
---|
| 168 | {mFName[col]=mFName[ColBolo]; mHDU[col]=mHDU[ColBolo]; return;}
|
---|
| 169 | if(mFName[ColSNum].size()>0)
|
---|
| 170 | {mFName[col]=mFName[ColSNum]; mHDU[col]=mHDU[ColSNum]; return;}
|
---|
| 171 |
|
---|
| 172 | } else if(col==ColAlpha) { // Cas du Alpha
|
---|
| 173 | if(mFName[ColDelta].size()>0)
|
---|
| 174 | {mFName[col]=mFName[ColDelta]; mHDU[col]=mHDU[ColDelta]; return;}
|
---|
| 175 | if(mFName[ColBolo].size()>0)
|
---|
| 176 | {mFName[col]=mFName[ColBolo]; mHDU[col]=mHDU[ColBolo]; return;}
|
---|
| 177 | if(mFName[ColSNum].size()>0)
|
---|
| 178 | {mFName[col]=mFName[ColSNum]; mHDU[col]=mHDU[ColSNum]; return;}
|
---|
| 179 |
|
---|
| 180 | } else if(col==ColDelta) { // Cas du Delta
|
---|
| 181 | if(mFName[ColAlpha].size()>0)
|
---|
| 182 | {mFName[col]=mFName[ColAlpha]; mHDU[col]=mHDU[ColAlpha]; return;}
|
---|
| 183 | if(mFName[ColBolo].size()>0)
|
---|
| 184 | {mFName[col]=mFName[ColBolo]; mHDU[col]=mHDU[ColBolo]; return;}
|
---|
| 185 | if(mFName[ColSNum].size()>0)
|
---|
| 186 | {mFName[col]=mFName[ColSNum]; mHDU[col]=mHDU[ColSNum]; return;}
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | //////////////////////////////////////////////////////////////
|
---|
| 191 | /*! Set the number of rows for that class, choosing column "col"
|
---|
| 192 | \param col : number of the column giving the number of rows
|
---|
| 193 | \verbatim
|
---|
| 194 | col : <0 set nrows to the smallest of all connected columns
|
---|
| 195 | col : [0,ncol-1] set nrows to the number of rows of column "col"
|
---|
| 196 | col : >=ncol trow exception
|
---|
| 197 | \endverbatim
|
---|
| 198 | \warning By default, the number of rows is set to the smallest of all connected columns
|
---|
| 199 | */
|
---|
| 200 | void FitsBoloRead::SetNbLine(int col)
|
---|
| 201 | {
|
---|
| 202 | if(col>=(int)mFABT.size()) // Bad column number
|
---|
| 203 | throw ParmError("FitsBoloRead::SetNbLine: bad column number\n");
|
---|
| 204 |
|
---|
| 205 | if(col>=0) { // existing column, return its NbLine
|
---|
| 206 | if(mFABT[col]==NULL)
|
---|
| 207 | throw NullPtrError("FitsBoloRead::SetNbLine: column not connected\n");
|
---|
| 208 | NBline = mFABT[col]->GetNbLine();
|
---|
[2087] | 209 | return;
|
---|
[1661] | 210 | }
|
---|
| 211 |
|
---|
| 212 | // take the smallest NbLine for all columns
|
---|
| 213 | NBline = 0;
|
---|
| 214 | for(col=0; col<(int)mFABT.size(); col++) {
|
---|
| 215 | if(mFABT[col]==NULL) continue;
|
---|
[3128] | 216 | LONGLONG nbl = mFABT[col]->GetNbLine();
|
---|
[1661] | 217 | if(nbl==0) continue;
|
---|
| 218 | if(NBline==0 || nbl<NBline) NBline = nbl;
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | //////////////////////////////////////////////////////////////
|
---|
| 223 | /*! Print */
|
---|
| 224 | void FitsBoloRead::Print(ostream& os,int lp) const
|
---|
| 225 | {
|
---|
| 226 | os<<"FitsBoloRead::Print: NBline="<<NBline<<" NCol="<<GetNbCol()<<endl;
|
---|
| 227 | for(int i=0; i<(int)mFABT.size(); i++) {
|
---|
| 228 | if(mFABT[i]==NULL) {
|
---|
| 229 | cout<<"...Col "<<i<<" not connected"<<endl;
|
---|
| 230 | continue;
|
---|
| 231 | } else {
|
---|
| 232 | cout<<"--> Col "<<i<<" label="<<mLabel[i]<<" hdu="<<mHDU[i]
|
---|
| 233 | <<" FName="<<mFName[i]<<endl;
|
---|
| 234 | if(lp>0) mFABT[i]->Print(os,lp);
|
---|
| 235 | }
|
---|
| 236 | }
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | #undef _NCOL_BOLO_MIN_
|
---|