| 1 | #include "machdefs.h" | 
|---|
| 2 |  | 
|---|
| 3 | #include <stdio.h> | 
|---|
| 4 | #include <string.h> | 
|---|
| 5 | #include <iostream> | 
|---|
| 6 | #include <typeinfo> | 
|---|
| 7 |  | 
|---|
| 8 | #include "histerr.h" | 
|---|
| 9 | #include "hist2err.h" | 
|---|
| 10 |  | 
|---|
| 11 | #include "fitsblkrw.h" | 
|---|
| 12 | #include "fitshandler.h" | 
|---|
| 13 |  | 
|---|
| 14 | namespace SOPHYA { | 
|---|
| 15 |  | 
|---|
| 16 | /////////////////////////////////////////////////////////////////////////// | 
|---|
| 17 | ///////////////////////// Histo , HProf , HistoErr //////////////////////// | 
|---|
| 18 | /////////////////////////////////////////////////////////////////////////// | 
|---|
| 19 |  | 
|---|
| 20 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
| 21 | int FitsHandler<HistoErr>::CheckReadability(FitsInOutFile& is) | 
|---|
| 22 | { | 
|---|
| 23 | if (is.CurrentHDUType() == IMAGE_HDU ) return 0; | 
|---|
| 24 | string key = "SOPCLSNM"; | 
|---|
| 25 | string clsnm = is.KeyValue(key); | 
|---|
| 26 | if(clsnm == "SOPHYA::HistoErr") return 2; | 
|---|
| 27 | return 0; | 
|---|
| 28 | } | 
|---|
| 29 |  | 
|---|
| 30 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
| 31 | int FitsHandler<HistoErr>::CheckHandling(AnyDataObj & o) | 
|---|
| 32 | { | 
|---|
| 33 | if (typeid(o) == typeid(HistoErr)) return 2; | 
|---|
| 34 | HistoErr * po = dynamic_cast< HistoErr * >(& o); | 
|---|
| 35 | if (po != NULL) return 2; | 
|---|
| 36 | return 0; | 
|---|
| 37 | } | 
|---|
| 38 |  | 
|---|
| 39 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
| 40 | void FitsHandler<HistoErr>::Write(FitsInOutFile& os) | 
|---|
| 41 | { | 
|---|
| 42 | if(dobj==NULL) | 
|---|
| 43 | throw NullPtrError("FitsHandler<HistoErr>::Write() NULL dobj pointer "); | 
|---|
| 44 |  | 
|---|
| 45 | //--- Le type d'objet et son pointeur | 
|---|
| 46 | HistoErr* he = dynamic_cast< HistoErr *> (dobj); | 
|---|
| 47 |  | 
|---|
| 48 | //--- Les noms de colonnes | 
|---|
| 49 | int tbltyp = os.GetDef_TableType(); | 
|---|
| 50 | vector<string> colnames, tform, tunit; | 
|---|
| 51 | // les valeurs du bin | 
|---|
| 52 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D"); | 
|---|
| 53 | colnames.push_back("val"); | 
|---|
| 54 | tunit.push_back(""); | 
|---|
| 55 | // Les erreurs | 
|---|
| 56 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D"); | 
|---|
| 57 | colnames.push_back("e2"); | 
|---|
| 58 | tunit.push_back(""); | 
|---|
| 59 | // Le nombre d'entrees dans le bin | 
|---|
| 60 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D"); | 
|---|
| 61 | colnames.push_back("nb"); | 
|---|
| 62 | tunit.push_back(""); | 
|---|
| 63 |  | 
|---|
| 64 | //--- On cree la table | 
|---|
| 65 | string extname = os.NextExtensionName(); | 
|---|
| 66 | os.CreateTable(os.GetDef_TableType(),extname,colnames,tform, tunit); | 
|---|
| 67 |  | 
|---|
| 68 | // Ecriture des donnees des colonnes | 
|---|
| 69 | int n = he->NBins(); | 
|---|
| 70 | if(n>0) { | 
|---|
| 71 | FitsBlockRW<r_8>::WriteColumnData(os,1,1,1,&(he->data_(0)),n); | 
|---|
| 72 | FitsBlockRW<r_8>::WriteColumnData(os,2,1,1,&(he->err2_(0)),n); | 
|---|
| 73 | FitsBlockRW<r_8>::WriteColumnData(os,3,1,1,&(he->ndata_(0)),n); | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | // Ecriture des clefs fits | 
|---|
| 77 | MuTyV mtv; | 
|---|
| 78 |  | 
|---|
| 79 | mtv = "SOPHYA::HistoErr"; | 
|---|
| 80 | os.WriteKey("SOPCLSNM",mtv," SOPHYA class name"); | 
|---|
| 81 |  | 
|---|
| 82 | mtv = "HistoErr"; | 
|---|
| 83 | os.WriteKey("CONTENT",mtv," name of SOPHYA object"); | 
|---|
| 84 |  | 
|---|
| 85 | mtv = he->NBins(); | 
|---|
| 86 | os.WriteKey("NBIN",mtv," number of bins"); | 
|---|
| 87 |  | 
|---|
| 88 | mtv = he->XMin(); | 
|---|
| 89 | os.WriteKey("XMIN",mtv," absc of beginning of 1srt bin"); | 
|---|
| 90 |  | 
|---|
| 91 | mtv = he->XMax(); | 
|---|
| 92 | os.WriteKey("XMAX",mtv," absc of end of last bin"); | 
|---|
| 93 |  | 
|---|
| 94 | mtv = he->BinWidth(); | 
|---|
| 95 | os.WriteKey("WBIN",mtv," bin width"); | 
|---|
| 96 |  | 
|---|
| 97 | mtv = he->mMean; | 
|---|
| 98 | os.WriteKey("NMEAN",mtv," number of Mean/Variance calls"); | 
|---|
| 99 |  | 
|---|
| 100 | return; | 
|---|
| 101 | } | 
|---|
| 102 |  | 
|---|
| 103 |  | 
|---|
| 104 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
| 105 | void FitsHandler<HistoErr>::Read(FitsInOutFile& is) | 
|---|
| 106 | { | 
|---|
| 107 | int hdutyp = is.CurrentHDUType(); | 
|---|
| 108 | if( (hdutyp != BINARY_TBL ) && (hdutyp != ASCII_TBL) ) | 
|---|
| 109 | throw FitsIOException("FitsHandler<HistoErr>::Read() Not a binary or ascii table HDU"); | 
|---|
| 110 |  | 
|---|
| 111 | //--- Nb de lignes et de colonnes | 
|---|
| 112 | vector<string> colnames; | 
|---|
| 113 | vector<int> coltypes; | 
|---|
| 114 | vector<LONGLONG> repcnt, width; | 
|---|
| 115 | is.GetColInfo(colnames,coltypes,repcnt,width); | 
|---|
| 116 | long ncol = colnames.size(); | 
|---|
| 117 | if(ncol<=0) | 
|---|
| 118 | throw FitsIOException("FitsHandler<HistoErr>::Read() bad number of table columns"); | 
|---|
| 119 | long nbrows = is.GetNbRows(); | 
|---|
| 120 | if(nbrows<=0) | 
|---|
| 121 | throw FitsIOException("FitsHandler<HistoErr>::Read() number of rows is zero, no reading"); | 
|---|
| 122 |  | 
|---|
| 123 | //--- Lecture entete FITS | 
|---|
| 124 | string key = "SOPCLSNM"; string clsnm = is.KeyValue(key); | 
|---|
| 125 | DVList dvl; is.GetHeaderRecords(dvl,true,false); | 
|---|
| 126 |  | 
|---|
| 127 | int_4 nbin = dvl.GetI("NBIN",-1); | 
|---|
| 128 | if(nbin<=0 && nbin!=nbrows) | 
|---|
| 129 | throw FitsIOException("FitsHandler<HistoErr>::Read() number of bins is zero or bad, no reading"); | 
|---|
| 130 |  | 
|---|
| 131 | r_8 xmin = dvl.GetD("XMIN",-1.); | 
|---|
| 132 | r_8 xmax = dvl.GetD("XMAX",+1.); | 
|---|
| 133 |  | 
|---|
| 134 | //--- Creation de l'objet si necessaire | 
|---|
| 135 | if(dobj == NULL) { | 
|---|
| 136 | if(clsnm == "SOPHYA::HistoErr") dobj = new HistoErr; | 
|---|
| 137 | } | 
|---|
| 138 |  | 
|---|
| 139 | //--- Type de l'histo | 
|---|
| 140 | HistoErr* he = dynamic_cast< HistoErr *> (dobj); | 
|---|
| 141 |  | 
|---|
| 142 | //--- Allocation pour histo | 
|---|
| 143 | if(he && (clsnm=="SOPHYA::HistoErr")) { | 
|---|
| 144 | if(ncol<3) | 
|---|
| 145 | throw FitsIOException("FitsHandler<HistoErr>::Read() wrong number of columns for HistoErr"); | 
|---|
| 146 | he->CreateOrResize(xmin,xmax,nbin); | 
|---|
| 147 | } else { | 
|---|
| 148 | throw FitsIOException("FitsHandler<HistoErr>::Read() No assocaition classe/fits_header"); | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | //--- remplissage des variables d'entete | 
|---|
| 152 | he->mMean = dvl.GetI("NMEAN",0); | 
|---|
| 153 |  | 
|---|
| 154 | //--- remplissage de l'histo | 
|---|
| 155 | FitsBlockRW<r_8>::ReadColumnData(is,1,1,1,&(he->data_(0)),nbin); | 
|---|
| 156 | FitsBlockRW<r_8>::ReadColumnData(is,2,1,1,&(he->err2_(0)),nbin); | 
|---|
| 157 | FitsBlockRW<r_8>::ReadColumnData(is,3,1,1,&(he->ndata_(0)),nbin); | 
|---|
| 158 |  | 
|---|
| 159 | return; | 
|---|
| 160 | } | 
|---|
| 161 |  | 
|---|
| 162 |  | 
|---|
| 163 | /////////////////////////////////////////////////////////////////////////// | 
|---|
| 164 | /////////////////////////////// Histo2DErr //////////////////////////////// | 
|---|
| 165 | /////////////////////////////////////////////////////////////////////////// | 
|---|
| 166 |  | 
|---|
| 167 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
| 168 | int FitsHandler<Histo2DErr>::CheckReadability(FitsInOutFile& is) | 
|---|
| 169 | { | 
|---|
| 170 | if (is.CurrentHDUType() == IMAGE_HDU ) return 0; | 
|---|
| 171 | string key = "SOPCLSNM"; | 
|---|
| 172 | string clsnm = is.KeyValue(key); | 
|---|
| 173 | if( clsnm == "SOPHYA::Histo2DErr") return 2; | 
|---|
| 174 | return 0; | 
|---|
| 175 | } | 
|---|
| 176 |  | 
|---|
| 177 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
| 178 | int FitsHandler<Histo2DErr>::CheckHandling(AnyDataObj & o) | 
|---|
| 179 | { | 
|---|
| 180 | if (typeid(o) == typeid(Histo2DErr)) return 2; | 
|---|
| 181 | Histo2DErr * po = dynamic_cast< Histo2DErr * >(& o); | 
|---|
| 182 | if (po != NULL) return 2; | 
|---|
| 183 | return 0; | 
|---|
| 184 | } | 
|---|
| 185 |  | 
|---|
| 186 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
| 187 | void FitsHandler<Histo2DErr>::Write(FitsInOutFile& os) | 
|---|
| 188 | { | 
|---|
| 189 | if(dobj==NULL) | 
|---|
| 190 | throw NullPtrError("FitsHandler<Histo2DErr>::Write() NULL dobj pointer "); | 
|---|
| 191 |  | 
|---|
| 192 | //--- Le type d'objet et son pointeur | 
|---|
| 193 | Histo2DErr* he2 = dynamic_cast< Histo2DErr *> (dobj); | 
|---|
| 194 |  | 
|---|
| 195 | //--- Les noms de colonnes | 
|---|
| 196 | int tbltyp = os.GetDef_TableType(); | 
|---|
| 197 | vector<string> colnames, tform, tunit; | 
|---|
| 198 | // les valeurs du bin | 
|---|
| 199 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D"); | 
|---|
| 200 | colnames.push_back("val"); | 
|---|
| 201 | tunit.push_back(""); | 
|---|
| 202 | // Les erreurs | 
|---|
| 203 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D"); | 
|---|
| 204 | colnames.push_back("e2"); | 
|---|
| 205 | tunit.push_back(""); | 
|---|
| 206 | // Les nombres d'entrees | 
|---|
| 207 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D"); | 
|---|
| 208 | colnames.push_back("nb"); | 
|---|
| 209 | tunit.push_back(""); | 
|---|
| 210 |  | 
|---|
| 211 | //--- On cree la table | 
|---|
| 212 | string extname = os.NextExtensionName(); | 
|---|
| 213 | os.CreateTable(os.GetDef_TableType(),extname,colnames,tform, tunit); | 
|---|
| 214 |  | 
|---|
| 215 | // Ecriture des donnees des colonnes | 
|---|
| 216 | long n = he2->NBinX()*he2->NBinY(); | 
|---|
| 217 | if(n>0) { | 
|---|
| 218 | FitsBlockRW<r_8>::WriteColumnData(os,1,1,1,&(he2->data_(0,0)),n); | 
|---|
| 219 | FitsBlockRW<r_8>::WriteColumnData(os,2,1,1,&(he2->err2_(0,0)),n); | 
|---|
| 220 | FitsBlockRW<r_8>::WriteColumnData(os,3,1,1,&(he2->ndata_(0,0)),n); | 
|---|
| 221 | } | 
|---|
| 222 |  | 
|---|
| 223 | // Ecriture des clefs fits | 
|---|
| 224 | MuTyV mtv; | 
|---|
| 225 |  | 
|---|
| 226 | mtv = "SOPHYA::Histo2DErr"; | 
|---|
| 227 | os.WriteKey("SOPCLSNM",mtv," SOPHYA class name"); | 
|---|
| 228 |  | 
|---|
| 229 | mtv = "Histo2DErr"; | 
|---|
| 230 | os.WriteKey("CONTENT",mtv," name of SOPHYA object"); | 
|---|
| 231 |  | 
|---|
| 232 | mtv = he2->NBinX(); | 
|---|
| 233 | os.WriteKey("NBINX",mtv," number of bins in X"); | 
|---|
| 234 | mtv = he2->NBinY(); | 
|---|
| 235 | os.WriteKey("NBINY",mtv," number of bins in Y"); | 
|---|
| 236 | mtv = he2->NBinX()*he2->NBinY(); | 
|---|
| 237 | os.WriteKey("NBINXY",mtv," (i,j): fits_row=i*NY+j 0<=i<NX 0<=j<NY"); | 
|---|
| 238 |  | 
|---|
| 239 | mtv = he2->XMin(); | 
|---|
| 240 | os.WriteKey("XMIN",mtv," absc of beginning of 1srt bin in X"); | 
|---|
| 241 | mtv = he2->XMax(); | 
|---|
| 242 | os.WriteKey("XMAX",mtv," absc of end of last bin in X"); | 
|---|
| 243 | mtv = he2->YMin(); | 
|---|
| 244 | os.WriteKey("YMIN",mtv," absc of beginning of 1srt bin in Y"); | 
|---|
| 245 | mtv = he2->YMax(); | 
|---|
| 246 | os.WriteKey("YMAX",mtv," absc of end of last bin in Y"); | 
|---|
| 247 |  | 
|---|
| 248 | mtv = he2->WBinX(); | 
|---|
| 249 | os.WriteKey("WBINX",mtv," bin width in X"); | 
|---|
| 250 | mtv = he2->WBinY(); | 
|---|
| 251 | os.WriteKey("WBINY",mtv," bin width in Y"); | 
|---|
| 252 |  | 
|---|
| 253 | mtv = he2->mMean; | 
|---|
| 254 | os.WriteKey("NMEAN",mtv," number of Mean/Variance calls"); | 
|---|
| 255 |  | 
|---|
| 256 | return; | 
|---|
| 257 | } | 
|---|
| 258 |  | 
|---|
| 259 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
| 260 | void FitsHandler<Histo2DErr>::Read(FitsInOutFile& is) | 
|---|
| 261 | { | 
|---|
| 262 | int hdutyp = is.CurrentHDUType(); | 
|---|
| 263 | if( (hdutyp != BINARY_TBL ) && (hdutyp != ASCII_TBL) ) | 
|---|
| 264 | throw FitsIOException("FitsHandler<Histo2DErr>::Read() Not a binary or ascii table HDU"); | 
|---|
| 265 |  | 
|---|
| 266 | //--- Nb de lignes et de colonnes | 
|---|
| 267 | vector<string> colnames; vector<int> coltypes; vector<LONGLONG> repcnt, width; | 
|---|
| 268 | is.GetColInfo(colnames,coltypes,repcnt,width); | 
|---|
| 269 | long ncol = colnames.size(); | 
|---|
| 270 | if(ncol<=0) | 
|---|
| 271 | throw FitsIOException("FitsHandler<Histo2DErr>::Read() bad number of table columns"); | 
|---|
| 272 | long nbrows = is.GetNbRows(); | 
|---|
| 273 | if(nbrows<=0) | 
|---|
| 274 | throw FitsIOException("FitsHandler<Histo2DErr>::Read() number of rows is zero, no reading"); | 
|---|
| 275 |  | 
|---|
| 276 | //--- Lecture entete FITS | 
|---|
| 277 | DVList dvl; is.GetHeaderRecords(dvl,true,false); | 
|---|
| 278 |  | 
|---|
| 279 | int_4 nbinx = dvl.GetI("NBINX",-1); | 
|---|
| 280 | int_4 nbiny = dvl.GetI("NBINY",-1); | 
|---|
| 281 | int_8 nbinxy = nbinx*nbiny; | 
|---|
| 282 | if(nbinx<=0 || nbiny<=0 || nbinxy!=nbrows) | 
|---|
| 283 | throw FitsIOException("FitsHandler<Histo2DErr>::Read() number of bins is zero or bad, no reading"); | 
|---|
| 284 |  | 
|---|
| 285 | r_8 xmin = dvl.GetD("XMIN",-1.); | 
|---|
| 286 | r_8 xmax = dvl.GetD("XMAX",1.); | 
|---|
| 287 | r_8 ymin = dvl.GetD("YMIN",-1.); | 
|---|
| 288 | r_8 ymax = dvl.GetD("YMAX",1.); | 
|---|
| 289 |  | 
|---|
| 290 | //--- Creation de l'objet | 
|---|
| 291 | if(dobj == NULL) dobj = new Histo2DErr; | 
|---|
| 292 | dobj->CreateOrResize(xmin,xmax,nbinx,ymin,ymax,nbiny); | 
|---|
| 293 |  | 
|---|
| 294 | //--- remplissage des variables d'entete | 
|---|
| 295 | dobj->mMean = dvl.GetI("NMEAN",0); | 
|---|
| 296 |  | 
|---|
| 297 | //--- remplissage de l'histo | 
|---|
| 298 | FitsBlockRW<r_8>::ReadColumnData(is,1,1,1,&(dobj->data_(0,0)),nbinxy); | 
|---|
| 299 | FitsBlockRW<r_8>::ReadColumnData(is,2,1,1,&(dobj->err2_(0,0)),nbinxy); | 
|---|
| 300 | FitsBlockRW<r_8>::ReadColumnData(is,3,1,1,&(dobj->ndata_(0,0)),nbinxy); | 
|---|
| 301 |  | 
|---|
| 302 | return; | 
|---|
| 303 | } | 
|---|
| 304 |  | 
|---|
| 305 | } // FIN namespace SOPHYA | 
|---|