| [3049] | 1 | #include "machdefs.h" | 
|---|
|  | 2 |  | 
|---|
|  | 3 | #include <stdio.h> | 
|---|
|  | 4 | #include <string.h> | 
|---|
|  | 5 | #include <iostream> | 
|---|
|  | 6 | #include <typeinfo> | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #include "histos.h" | 
|---|
|  | 9 | #include "hisprof.h" | 
|---|
|  | 10 | #include "histos2.h" | 
|---|
| [3054] | 11 |  | 
|---|
| [3049] | 12 | #include "fitsblkrw.h" | 
|---|
|  | 13 | #include "fitshandler.h" | 
|---|
|  | 14 |  | 
|---|
| [3237] | 15 | namespace SOPHYA { | 
|---|
| [3049] | 16 |  | 
|---|
| [3123] | 17 | //////////////////////////////////////////////////////////////// | 
|---|
|  | 18 | ///////////////////////// Histo , HProf //////////////////////// | 
|---|
|  | 19 | //////////////////////////////////////////////////////////////// | 
|---|
| [3049] | 20 |  | 
|---|
|  | 21 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
|  | 22 | int FitsHandler<Histo>::CheckReadability(FitsInOutFile& is) | 
|---|
|  | 23 | { | 
|---|
|  | 24 | if (is.CurrentHDUType() == IMAGE_HDU ) return 0; | 
|---|
|  | 25 | string key = "SOPCLSNM"; | 
|---|
|  | 26 | string clsnm = is.KeyValue(key); | 
|---|
|  | 27 | if ( (clsnm == "SOPHYA::Histo") | 
|---|
| [3123] | 28 | || (clsnm == "SOPHYA::HProf") ) return 2; | 
|---|
| [3049] | 29 | return 0; | 
|---|
|  | 30 | } | 
|---|
|  | 31 |  | 
|---|
|  | 32 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
|  | 33 | int FitsHandler<Histo>::CheckHandling(AnyDataObj & o) | 
|---|
|  | 34 | { | 
|---|
|  | 35 | if (typeid(o) == typeid(Histo)) return 2; | 
|---|
|  | 36 | Histo * po = dynamic_cast< Histo * >(& o); | 
|---|
|  | 37 | if (po != NULL) return 2; | 
|---|
|  | 38 | return 0; | 
|---|
|  | 39 | } | 
|---|
|  | 40 |  | 
|---|
|  | 41 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
|  | 42 | void FitsHandler<Histo>::Write(FitsInOutFile& os) | 
|---|
|  | 43 | { | 
|---|
|  | 44 | if(dobj==NULL) | 
|---|
|  | 45 | throw NullPtrError("FitsHandler<Histo>::Write() NULL dobj pointer "); | 
|---|
|  | 46 |  | 
|---|
|  | 47 | //--- Le type d'objet et son pointeur | 
|---|
|  | 48 | Histo*    h  = dynamic_cast< Histo *> (dobj); | 
|---|
|  | 49 | HProf*    hp = dynamic_cast< HProf *> (dobj); | 
|---|
|  | 50 |  | 
|---|
|  | 51 | //--- Les noms de colonnes | 
|---|
|  | 52 | int tbltyp = os.GetDef_TableType(); | 
|---|
|  | 53 | vector<string> colnames, tform, tunit; | 
|---|
|  | 54 | // les valeurs du bin | 
|---|
|  | 55 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D"); | 
|---|
|  | 56 | colnames.push_back("val"); | 
|---|
|  | 57 | tunit.push_back(""); | 
|---|
|  | 58 | // Les erreurs | 
|---|
|  | 59 | if(h->mErr2) { | 
|---|
|  | 60 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D"); | 
|---|
|  | 61 | colnames.push_back("e2"); | 
|---|
|  | 62 | tunit.push_back(""); | 
|---|
|  | 63 | } | 
|---|
|  | 64 | // Le nombre d'entrees dans le bin | 
|---|
| [3123] | 65 | if(hp!=NULL) { | 
|---|
| [3049] | 66 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D"); | 
|---|
|  | 67 | colnames.push_back("nb"); | 
|---|
|  | 68 | tunit.push_back(""); | 
|---|
|  | 69 | } | 
|---|
|  | 70 |  | 
|---|
|  | 71 | //--- On cree la table | 
|---|
|  | 72 | string extname = os.NextExtensionName(); | 
|---|
|  | 73 | os.CreateTable(os.GetDef_TableType(),extname,colnames,tform, tunit); | 
|---|
|  | 74 |  | 
|---|
|  | 75 | // Ecriture des donnees des colonnes | 
|---|
|  | 76 | int n = h->NBins(); | 
|---|
|  | 77 | if(n>0) { | 
|---|
| [3054] | 78 | if(hp) hp->UpdateHisto(); | 
|---|
| [3049] | 79 | FitsBlockRW<r_8>::WriteColumnData(os,1,1,1,h->mData,n); | 
|---|
|  | 80 | if(h->mErr2) FitsBlockRW<r_8>::WriteColumnData(os,2,1,1,h->mErr2,n); | 
|---|
| [3054] | 81 | if(hp!=NULL) FitsBlockRW<r_8>::WriteColumnData(os,3,1,1,hp->mSumW,n); | 
|---|
| [3049] | 82 | } | 
|---|
|  | 83 |  | 
|---|
|  | 84 | // Ecriture des clefs fits | 
|---|
|  | 85 | MuTyV mtv; | 
|---|
|  | 86 |  | 
|---|
|  | 87 | mtv = "SOPHYA::Histo"; | 
|---|
|  | 88 | if(hp) mtv = "SOPHYA::HProf"; | 
|---|
|  | 89 | os.WriteKey("SOPCLSNM",mtv," SOPHYA class name"); | 
|---|
|  | 90 |  | 
|---|
|  | 91 | mtv = "Histo"; | 
|---|
|  | 92 | if(hp) mtv = "HProf"; | 
|---|
|  | 93 | os.WriteKey("CONTENT",mtv," name of SOPHYA object"); | 
|---|
|  | 94 |  | 
|---|
|  | 95 | mtv = h->mBins; | 
|---|
|  | 96 | os.WriteKey("NBIN",mtv," number of bins"); | 
|---|
|  | 97 |  | 
|---|
|  | 98 | mtv = h->mMin; | 
|---|
|  | 99 | os.WriteKey("XMIN",mtv," absc of beginning of 1srt bin"); | 
|---|
|  | 100 |  | 
|---|
|  | 101 | mtv = h->mMax; | 
|---|
|  | 102 | os.WriteKey("XMAX",mtv," absc of end of last bin"); | 
|---|
|  | 103 |  | 
|---|
|  | 104 | mtv = h->binWidth; | 
|---|
|  | 105 | os.WriteKey("WBIN",mtv," bin width"); | 
|---|
|  | 106 |  | 
|---|
|  | 107 | mtv = h->mUnder; | 
|---|
|  | 108 | os.WriteKey("UNDER",mtv," number of bins"); | 
|---|
|  | 109 |  | 
|---|
|  | 110 | mtv = h->mOver; | 
|---|
|  | 111 | os.WriteKey("OVER",mtv," underflow"); | 
|---|
|  | 112 |  | 
|---|
|  | 113 | mtv = h->nHist; | 
|---|
|  | 114 | os.WriteKey("NHIST",mtv," entries weighted somme"); | 
|---|
|  | 115 |  | 
|---|
|  | 116 | double x = h->nEntries; mtv = x; | 
|---|
|  | 117 | os.WriteKey("NENTRIES",mtv," number of entries"); | 
|---|
|  | 118 |  | 
|---|
|  | 119 | int_4 haserr =(h->mErr2) ? 1: 0; | 
|---|
|  | 120 | mtv = haserr; | 
|---|
|  | 121 | os.WriteKey("HASERR2",mtv," square errors associated"); | 
|---|
|  | 122 |  | 
|---|
|  | 123 | if(hp) { | 
|---|
| [3056] | 124 | int_4 ok = (hp->mOk)? 1: 0; | 
|---|
| [3049] | 125 | mtv = ok; | 
|---|
|  | 126 | os.WriteKey("UPDOK",mtv," update status flag"); | 
|---|
|  | 127 |  | 
|---|
| [3056] | 128 | mtv = (int_4)hp->mOpt; | 
|---|
| [3054] | 129 | os.WriteKey("SIGOPT",mtv," sigma statistic flag"); | 
|---|
|  | 130 |  | 
|---|
| [3056] | 131 | mtv = hp->mYMin; | 
|---|
| [3049] | 132 | os.WriteKey("YMIN",mtv," sum low limit"); | 
|---|
|  | 133 |  | 
|---|
| [3056] | 134 | mtv = hp->mYMax; | 
|---|
| [3049] | 135 | os.WriteKey("YMAX",mtv," sum high limit"); | 
|---|
|  | 136 | } | 
|---|
|  | 137 |  | 
|---|
| [3059] | 138 | return; | 
|---|
| [3049] | 139 | } | 
|---|
|  | 140 |  | 
|---|
|  | 141 |  | 
|---|
|  | 142 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
|  | 143 | void FitsHandler<Histo>::Read(FitsInOutFile& is) | 
|---|
|  | 144 | { | 
|---|
|  | 145 | int hdutyp = is.CurrentHDUType(); | 
|---|
|  | 146 | if( (hdutyp != BINARY_TBL ) && (hdutyp != ASCII_TBL) ) | 
|---|
|  | 147 | throw FitsIOException("FitsHandler<Histo>::Read() Not a binary or ascii table HDU"); | 
|---|
|  | 148 |  | 
|---|
|  | 149 | //--- Nb de lignes et de colonnes | 
|---|
|  | 150 | vector<string> colnames; | 
|---|
|  | 151 | vector<int> coltypes; | 
|---|
| [3167] | 152 | vector<LONGLONG> repcnt, width; | 
|---|
| [3049] | 153 | is.GetColInfo(colnames,coltypes,repcnt,width); | 
|---|
|  | 154 | long ncol = colnames.size(); | 
|---|
|  | 155 | if(ncol<=0) | 
|---|
|  | 156 | throw FitsIOException("FitsHandler<Histo>::Read() bad number of table columns"); | 
|---|
|  | 157 | long nbrows = is.GetNbRows(); | 
|---|
|  | 158 | if(nbrows<=0) | 
|---|
|  | 159 | throw FitsIOException("FitsHandler<Histo>::Read() number of rows is zero, no reading"); | 
|---|
|  | 160 |  | 
|---|
|  | 161 | //--- Lecture entete FITS | 
|---|
|  | 162 | string key = "SOPCLSNM"; string clsnm = is.KeyValue(key); | 
|---|
| [3054] | 163 | DVList dvl; is.GetHeaderRecords(dvl,true,false); | 
|---|
| [3049] | 164 |  | 
|---|
|  | 165 | int_4 nbin = dvl.GetI("NBIN",-1); | 
|---|
|  | 166 | if(nbin<=0 && nbin!=nbrows) | 
|---|
|  | 167 | throw FitsIOException("FitsHandler<Histo>::Read() number of bins is zero or bad, no reading"); | 
|---|
|  | 168 |  | 
|---|
|  | 169 | r_8 xmin = dvl.GetD("XMIN",-1.); | 
|---|
|  | 170 | r_8 xmax = dvl.GetD("XMAX",+1.); | 
|---|
|  | 171 |  | 
|---|
| [3054] | 172 | //--- Creation de l'objet si necessaire | 
|---|
|  | 173 | if(dobj == NULL) { | 
|---|
|  | 174 | if(clsnm == "SOPHYA::Histo") dobj = new Histo; | 
|---|
|  | 175 | else if(clsnm == "SOPHYA::HProf") dobj = new HProf; | 
|---|
| [3049] | 176 | } | 
|---|
|  | 177 |  | 
|---|
|  | 178 | //--- Type de l'histo | 
|---|
|  | 179 | Histo*    h  = dynamic_cast< Histo *> (dobj); | 
|---|
|  | 180 | HProf*    hp = dynamic_cast< HProf *> (dobj); | 
|---|
|  | 181 |  | 
|---|
| [3054] | 182 | //--- Allocation pour histo | 
|---|
| [3123] | 183 | if(hp&& (clsnm=="SOPHYA::HProf")) { | 
|---|
| [3054] | 184 | if(ncol<3) | 
|---|
|  | 185 | throw FitsIOException("FitsHandler<Histo>::Read() wrong number of columns for HProf"); | 
|---|
|  | 186 | r_8 ymin = dvl.GetD("YMIN",1.); | 
|---|
|  | 187 | r_8 ymax = dvl.GetD("YMAX",-1.); | 
|---|
|  | 188 | hp->CreateOrResize(xmin,xmax,nbin,ymin,ymax); | 
|---|
|  | 189 | } else if(h && clsnm == "SOPHYA::Histo" ) { | 
|---|
|  | 190 | h->CreateOrResize(xmin,xmax,nbin); | 
|---|
|  | 191 | int_4 haserr2 = dvl.GetI("HASERR2",0); | 
|---|
|  | 192 | if(ncol>1 && haserr2>0) h->Errors(); | 
|---|
|  | 193 | } else { | 
|---|
|  | 194 | throw FitsIOException("FitsHandler<Histo>::Read() No assocaition classe/fits_header"); | 
|---|
|  | 195 | } | 
|---|
|  | 196 |  | 
|---|
| [3049] | 197 | //--- remplissage des variables d'entete | 
|---|
|  | 198 | h->mUnder = dvl.GetD("UNDER",0.); | 
|---|
|  | 199 | h->mOver = dvl.GetD("OVER",0.); | 
|---|
|  | 200 | h->nHist = dvl.GetD("NHIST",0.); | 
|---|
|  | 201 | double x = dvl.GetD("NENTRIES",0.); h->nEntries = uint_8(x); | 
|---|
|  | 202 |  | 
|---|
|  | 203 | if(hp) { | 
|---|
| [3056] | 204 | int_4 ok = dvl.GetI("UPDOK",0); hp->mOk = (ok)? true : false; | 
|---|
|  | 205 | hp->mOpt = (uint_2)dvl.GetI("SIGOPT",0); | 
|---|
|  | 206 | hp->mYMin = dvl.GetD("YMIN",1.); | 
|---|
|  | 207 | hp->mYMax = dvl.GetD("YMAX",-1.); | 
|---|
| [3049] | 208 | } | 
|---|
|  | 209 |  | 
|---|
|  | 210 | //--- remplissage de l'histo | 
|---|
|  | 211 | FitsBlockRW<r_8>::ReadColumnData(is,1,1,1,h->mData,nbin); | 
|---|
|  | 212 | if(h->mErr2) FitsBlockRW<r_8>::ReadColumnData(is,2,1,1,h->mErr2,nbin); | 
|---|
| [3054] | 213 | if(hp) FitsBlockRW<r_8>::ReadColumnData(is,3,1,1,hp->mSumW,nbin); | 
|---|
| [3049] | 214 |  | 
|---|
| [3059] | 215 | return; | 
|---|
| [3049] | 216 | } | 
|---|
|  | 217 |  | 
|---|
|  | 218 |  | 
|---|
|  | 219 | /////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 220 | ///////////////////////////////// Histo2D  //////////////////////////////// | 
|---|
|  | 221 | /////////////////////////////////////////////////////////////////////////// | 
|---|
|  | 222 |  | 
|---|
|  | 223 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
|  | 224 | int FitsHandler<Histo2D>::CheckReadability(FitsInOutFile& is) | 
|---|
|  | 225 | { | 
|---|
| [3054] | 226 | if (is.CurrentHDUType() == IMAGE_HDU ) return 0; | 
|---|
| [3049] | 227 | string key = "SOPCLSNM"; | 
|---|
|  | 228 | string clsnm = is.KeyValue(key); | 
|---|
| [3054] | 229 | if( clsnm == "SOPHYA::Histo2D") return 2; | 
|---|
| [3049] | 230 | return 0; | 
|---|
|  | 231 | } | 
|---|
|  | 232 |  | 
|---|
|  | 233 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
|  | 234 | int FitsHandler<Histo2D>::CheckHandling(AnyDataObj & o) | 
|---|
|  | 235 | { | 
|---|
|  | 236 | if (typeid(o) == typeid(Histo2D)) return 2; | 
|---|
|  | 237 | Histo2D * po = dynamic_cast< Histo2D * >(& o); | 
|---|
|  | 238 | if (po != NULL) return 2; | 
|---|
|  | 239 | return 0; | 
|---|
|  | 240 | } | 
|---|
|  | 241 |  | 
|---|
|  | 242 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
|  | 243 | void FitsHandler<Histo2D>::Write(FitsInOutFile& os) | 
|---|
|  | 244 | { | 
|---|
|  | 245 | if(dobj==NULL) | 
|---|
|  | 246 | throw NullPtrError("FitsHandler<Histo2D>::Write() NULL dobj pointer "); | 
|---|
|  | 247 |  | 
|---|
|  | 248 | //--- Le type d'objet et son pointeur | 
|---|
| [3059] | 249 | Histo2D* h2 = dynamic_cast< Histo2D *> (dobj); | 
|---|
| [3049] | 250 |  | 
|---|
|  | 251 | //--- Les noms de colonnes | 
|---|
|  | 252 | int tbltyp = os.GetDef_TableType(); | 
|---|
|  | 253 | vector<string> colnames, tform, tunit; | 
|---|
|  | 254 | // les valeurs du bin | 
|---|
|  | 255 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D"); | 
|---|
|  | 256 | colnames.push_back("val"); | 
|---|
|  | 257 | tunit.push_back(""); | 
|---|
|  | 258 | // Les erreurs | 
|---|
| [3059] | 259 | if(h2->mErr2) { | 
|---|
| [3049] | 260 | if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D"); | 
|---|
|  | 261 | colnames.push_back("e2"); | 
|---|
|  | 262 | tunit.push_back(""); | 
|---|
|  | 263 | } | 
|---|
|  | 264 |  | 
|---|
|  | 265 | //--- On cree la table | 
|---|
|  | 266 | string extname = os.NextExtensionName(); | 
|---|
|  | 267 | os.CreateTable(os.GetDef_TableType(),extname,colnames,tform, tunit); | 
|---|
|  | 268 |  | 
|---|
|  | 269 | // Ecriture des donnees des colonnes | 
|---|
| [3059] | 270 | long n = h2->mNxy; | 
|---|
| [3049] | 271 | if(n>0) { | 
|---|
| [3059] | 272 | FitsBlockRW<r_8>::WriteColumnData(os,1,1,1,h2->mData,n); | 
|---|
|  | 273 | if(h2->mErr2) FitsBlockRW<r_8>::WriteColumnData(os,2,1,1,h2->mErr2,n); | 
|---|
| [3049] | 274 | } | 
|---|
|  | 275 |  | 
|---|
|  | 276 | // Ecriture des clefs fits | 
|---|
|  | 277 | MuTyV mtv; | 
|---|
|  | 278 |  | 
|---|
|  | 279 | mtv = "SOPHYA::Histo2D"; | 
|---|
|  | 280 | os.WriteKey("SOPCLSNM",mtv," SOPHYA class name"); | 
|---|
|  | 281 |  | 
|---|
|  | 282 | mtv = "Histo2D"; | 
|---|
|  | 283 | os.WriteKey("CONTENT",mtv," name of SOPHYA object"); | 
|---|
|  | 284 |  | 
|---|
| [3059] | 285 | mtv = h2->mNx; | 
|---|
| [3049] | 286 | os.WriteKey("NBINX",mtv," number of bins in X"); | 
|---|
| [3059] | 287 | mtv = h2->mNy; | 
|---|
| [3049] | 288 | os.WriteKey("NBINY",mtv," number of bins in Y"); | 
|---|
| [3059] | 289 | mtv = h2->mNxy; | 
|---|
| [3049] | 290 | os.WriteKey("NBINXY",mtv," number of elements"); | 
|---|
|  | 291 |  | 
|---|
| [3059] | 292 | mtv = h2->mXmin; | 
|---|
| [3049] | 293 | os.WriteKey("XMIN",mtv," absc of beginning of 1srt bin in X"); | 
|---|
| [3059] | 294 | mtv = h2->mXmax; | 
|---|
| [3049] | 295 | os.WriteKey("XMAX",mtv," absc of end of last bin in X"); | 
|---|
| [3059] | 296 | mtv = h2->mYmin; | 
|---|
| [3049] | 297 | os.WriteKey("YMIN",mtv," absc of beginning of 1srt bin in Y"); | 
|---|
| [3059] | 298 | mtv = h2->mYmax; | 
|---|
| [3049] | 299 | os.WriteKey("YMAX",mtv," absc of end of last bin in Y"); | 
|---|
|  | 300 |  | 
|---|
| [3059] | 301 | mtv = h2->mWBinx; | 
|---|
| [3049] | 302 | os.WriteKey("WBINX",mtv," bin width in X"); | 
|---|
| [3059] | 303 | mtv = h2->mWBiny; | 
|---|
| [3049] | 304 | os.WriteKey("WBINY",mtv," bin width in Y"); | 
|---|
|  | 305 |  | 
|---|
|  | 306 | for(int i=0;i<3;i++) for(int j=0;j<3;j++) { | 
|---|
|  | 307 | char str[16]; sprintf(str,"OUT%1d%1d",i,j); | 
|---|
| [3059] | 308 | mtv = h2->mOver[i][j]; | 
|---|
| [3049] | 309 | os.WriteKey(str,mtv," under/over X/Y"); | 
|---|
|  | 310 | } | 
|---|
|  | 311 |  | 
|---|
| [3059] | 312 | mtv = h2->nHist; | 
|---|
| [3049] | 313 | os.WriteKey("NHIST",mtv," entries weighted somme"); | 
|---|
|  | 314 |  | 
|---|
| [3059] | 315 | mtv = h2->nEntries; | 
|---|
| [3049] | 316 | os.WriteKey("NENTRIES",mtv," number of entries"); | 
|---|
|  | 317 |  | 
|---|
| [3059] | 318 | int_4 haserr =(h2->mErr2) ? 1: 0; | 
|---|
| [3049] | 319 | mtv = haserr; | 
|---|
|  | 320 | os.WriteKey("HASERR2",mtv," square errors associated"); | 
|---|
|  | 321 |  | 
|---|
| [3059] | 322 |  | 
|---|
|  | 323 |  | 
|---|
|  | 324 | //------------------------------------------------------------- | 
|---|
|  | 325 | //------ Gestion des Histo1D de projx/y bandx/t slicex/y ------ | 
|---|
|  | 326 | //------------------------------------------------------------- | 
|---|
|  | 327 |  | 
|---|
|  | 328 | int_4 nrel = 0; | 
|---|
|  | 329 | if(h2->HProjX()) {nrel++; mtv=nrel; os.WriteKey("PROJX",mtv," relative HDU with HProjX");} | 
|---|
|  | 330 | if(h2->HProjY()) {nrel++; mtv=nrel; os.WriteKey("PROJY",mtv," relative HDU with HProjY");} | 
|---|
|  | 331 | if(h2->NSliX()>0) { | 
|---|
|  | 332 | mtv=h2->NSliX(); os.WriteKey("NSLICEX",mtv," number of SliX"); | 
|---|
|  | 333 | nrel++; | 
|---|
|  | 334 | mtv=nrel; os.WriteKey("SLICEX",mtv," relative HDU with first SliX"); | 
|---|
|  | 335 | nrel += h2->NSliX()-1; | 
|---|
|  | 336 | } | 
|---|
|  | 337 | if(h2->NSliY()>0) { | 
|---|
|  | 338 | mtv=h2->NSliY(); os.WriteKey("NSLICEY",mtv," number of SliY"); | 
|---|
|  | 339 | nrel++; | 
|---|
|  | 340 | mtv=nrel; os.WriteKey("SLICEY",mtv," relative HDU with first SliY"); | 
|---|
|  | 341 | nrel += h2->NSliY()-1; | 
|---|
|  | 342 | } | 
|---|
|  | 343 | if(h2->NBandX()>0) { | 
|---|
|  | 344 | mtv=h2->NBandX(); os.WriteKey("NBANDEX",mtv," number of BandX"); | 
|---|
|  | 345 | nrel++; | 
|---|
|  | 346 | mtv=nrel; os.WriteKey("BANDEX",mtv," relative HDU with first BandX"); | 
|---|
|  | 347 | nrel += h2->NBandX()-1; | 
|---|
|  | 348 | for(int i=0;i<h2->NBandX();i++) { | 
|---|
|  | 349 | char str[32]; r_8 vmin,vmax; | 
|---|
|  | 350 | h2->GetBandX(i,vmin,vmax); | 
|---|
|  | 351 | sprintf(str,"BXL%d",i); | 
|---|
|  | 352 | mtv = vmin; os.WriteKey(str,mtv," low Y limit for BandX"); | 
|---|
|  | 353 | sprintf(str,"BXH%d",i); | 
|---|
|  | 354 | mtv = vmax; os.WriteKey(str,mtv," high Y limit for BandX"); | 
|---|
|  | 355 | } | 
|---|
|  | 356 | } | 
|---|
|  | 357 | if(h2->NBandY()>0) { | 
|---|
|  | 358 | mtv=h2->NBandY(); os.WriteKey("NBANDEY",mtv," number of BandY"); | 
|---|
|  | 359 | nrel++; | 
|---|
|  | 360 | mtv=nrel; os.WriteKey("BANDEY",mtv," relative HDU with first BandY"); | 
|---|
|  | 361 | nrel += h2->NBandY()-1; | 
|---|
|  | 362 | for(int i=0;i<h2->NBandY();i++) { | 
|---|
|  | 363 | char str[32]; r_8 vmin,vmax; | 
|---|
|  | 364 | h2->GetBandY(i,vmin,vmax); | 
|---|
|  | 365 | sprintf(str,"BYL%d",i); | 
|---|
|  | 366 | mtv = vmin; os.WriteKey(str,mtv," low X limit for BandY"); | 
|---|
|  | 367 | sprintf(str,"BYH%d",i); | 
|---|
|  | 368 | mtv = vmax; os.WriteKey(str,mtv," high X limit for BandY"); | 
|---|
|  | 369 | } | 
|---|
|  | 370 | } | 
|---|
|  | 371 | mtv=nrel; os.WriteKey("NH1ASS",mtv," number of associated Histo1D"); | 
|---|
|  | 372 |  | 
|---|
|  | 373 | if(h2->HProjX()) {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HProjX()))); fio.Write(os);} | 
|---|
|  | 374 | if(h2->HProjY()) {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HProjY()))); fio.Write(os);} | 
|---|
|  | 375 | if(h2->NSliX()>0) for(int i=0;i<h2->NSliX();i++) | 
|---|
|  | 376 | {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HSliX(i)))); fio.Write(os);} | 
|---|
|  | 377 | if(h2->NSliY()>0) for(int i=0;i<h2->NSliY();i++) | 
|---|
|  | 378 | {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HSliY(i)))); fio.Write(os);} | 
|---|
|  | 379 | if(h2->NBandX()>0) for(int i=0;i<h2->NBandX();i++) | 
|---|
|  | 380 | {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HBandX(i)))); fio.Write(os);} | 
|---|
|  | 381 | if(h2->NBandY()>0) for(int i=0;i<h2->NBandY();i++) | 
|---|
|  | 382 | {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HBandY(i)))); fio.Write(os);} | 
|---|
|  | 383 |  | 
|---|
|  | 384 | return; | 
|---|
| [3049] | 385 | } | 
|---|
|  | 386 |  | 
|---|
|  | 387 | DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */ | 
|---|
|  | 388 | void FitsHandler<Histo2D>::Read(FitsInOutFile& is) | 
|---|
|  | 389 | { | 
|---|
|  | 390 | int hdutyp = is.CurrentHDUType(); | 
|---|
|  | 391 | if( (hdutyp != BINARY_TBL ) && (hdutyp != ASCII_TBL) ) | 
|---|
|  | 392 | throw FitsIOException("FitsHandler<Histo2D>::Read() Not a binary or ascii table HDU"); | 
|---|
|  | 393 |  | 
|---|
|  | 394 | //--- Nb de lignes et de colonnes | 
|---|
| [3167] | 395 | vector<string> colnames; vector<int> coltypes; vector<LONGLONG> repcnt, width; | 
|---|
| [3049] | 396 | is.GetColInfo(colnames,coltypes,repcnt,width); | 
|---|
|  | 397 | long ncol = colnames.size(); | 
|---|
|  | 398 | if(ncol<=0) | 
|---|
|  | 399 | throw FitsIOException("FitsHandler<Histo2D>::Read() bad number of table columns"); | 
|---|
|  | 400 | long nbrows = is.GetNbRows(); | 
|---|
|  | 401 | if(nbrows<=0) | 
|---|
|  | 402 | throw FitsIOException("FitsHandler<Histo2D>::Read() number of rows is zero, no reading"); | 
|---|
|  | 403 |  | 
|---|
|  | 404 | //--- Lecture entete FITS | 
|---|
| [3054] | 405 | DVList dvl; is.GetHeaderRecords(dvl,true,false); | 
|---|
| [3049] | 406 |  | 
|---|
|  | 407 | int_4 nbinx = dvl.GetI("NBINX",-1); | 
|---|
|  | 408 | int_4 nbiny = dvl.GetI("NBINY",-1); | 
|---|
|  | 409 | int_8 nbinxy = nbinx*nbiny; | 
|---|
|  | 410 | if(nbinx<=0 || nbiny<=0 || nbinxy!=nbrows) | 
|---|
|  | 411 | throw FitsIOException("FitsHandler<Histo2D>::Read() number of bins is zero or bad, no reading"); | 
|---|
|  | 412 |  | 
|---|
|  | 413 | r_8 xmin = dvl.GetD("XMIN",-1.); | 
|---|
|  | 414 | r_8 xmax = dvl.GetD("XMAX",1.); | 
|---|
|  | 415 | r_8 ymin = dvl.GetD("YMIN",-1.); | 
|---|
|  | 416 | r_8 ymax = dvl.GetD("YMAX",1.); | 
|---|
|  | 417 |  | 
|---|
|  | 418 | //--- Creation de l'objet | 
|---|
| [3054] | 419 | if(dobj == NULL) dobj = new Histo2D; | 
|---|
|  | 420 | dobj->CreateOrResize(xmin,xmax,nbinx,ymin,ymax,nbiny); | 
|---|
|  | 421 | int_4 haserr2 = dvl.GetI("HASERR2",0); | 
|---|
|  | 422 | if(ncol>1 && haserr2>0) dobj->Errors(); | 
|---|
| [3049] | 423 |  | 
|---|
|  | 424 | //--- remplissage des variables d'entete | 
|---|
| [3054] | 425 | dobj->nHist = dvl.GetD("NHIST",0.); | 
|---|
|  | 426 | dobj->nEntries = dvl.GetI("NENTRIES",0); | 
|---|
| [3049] | 427 |  | 
|---|
|  | 428 | for(int i=0;i<3;i++) for(int j=0;j<3;j++) { | 
|---|
|  | 429 | char str[16]; sprintf(str,"OUT%1d%1d",i,j); | 
|---|
| [3054] | 430 | dobj->mOver[i][j] = dvl.GetD(str,0.); | 
|---|
| [3049] | 431 | } | 
|---|
|  | 432 |  | 
|---|
|  | 433 | //--- remplissage de l'histo | 
|---|
| [3054] | 434 | FitsBlockRW<r_8>::ReadColumnData(is,1,1,1,dobj->mData,nbinxy); | 
|---|
|  | 435 | if(dobj->mErr2) FitsBlockRW<r_8>::ReadColumnData(is,2,1,1,dobj->mErr2,nbinxy); | 
|---|
| [3049] | 436 |  | 
|---|
| [3059] | 437 |  | 
|---|
|  | 438 |  | 
|---|
|  | 439 | //------------------------------------------------------------- | 
|---|
|  | 440 | //------ Gestion des Histo1D de projx/y bandx/t slicex/y ------ | 
|---|
|  | 441 | //------------------------------------------------------------- | 
|---|
|  | 442 |  | 
|---|
|  | 443 | int_4 nh1ass = dvl.GetI("NH1ASS",-1); | 
|---|
|  | 444 | if(nh1ass<=0) return; | 
|---|
|  | 445 | int hducur = is.CurrentHDU(); | 
|---|
|  | 446 |  | 
|---|
|  | 447 | try {  // ProjX | 
|---|
|  | 448 | int_4 ipr = dvl.GetI("PROJX",-1); | 
|---|
|  | 449 | is.MoveAbsToHDU(hducur+ipr); | 
|---|
|  | 450 | dobj->SetProjX(); | 
|---|
|  | 451 | Histo *h = dobj->HProjX(); | 
|---|
|  | 452 | FitsHandler<Histo> fio(*h); fio.Read(is); | 
|---|
|  | 453 | if(h->NBins()!=dobj->NBinX()) | 
|---|
|  | 454 | throw FitsIOException("unmatched bin number"); | 
|---|
|  | 455 | } catch (...) { | 
|---|
|  | 456 | dobj->DelProjX(); | 
|---|
|  | 457 | cout<<"FitsHandler<Histo2D>::Read: Error reading PROJX"<<endl; | 
|---|
|  | 458 | } | 
|---|
|  | 459 |  | 
|---|
|  | 460 | try {  // ProjY | 
|---|
|  | 461 | int_4 ipr = dvl.GetI("PROJY",-1); | 
|---|
|  | 462 | is.MoveAbsToHDU(hducur+ipr); | 
|---|
|  | 463 | dobj->SetProjY(); | 
|---|
|  | 464 | Histo *h = dobj->HProjY(); | 
|---|
|  | 465 | FitsHandler<Histo> fio(*h); fio.Read(is); | 
|---|
|  | 466 | if(h->NBins()!=dobj->NBinY()) | 
|---|
|  | 467 | throw FitsIOException("unmatched bin number"); | 
|---|
|  | 468 | } catch (...) { | 
|---|
|  | 469 | dobj->DelProjY(); | 
|---|
|  | 470 | cout<<"FitsHandler<Histo2D>::Read: Error reading PROJY"<<endl; | 
|---|
|  | 471 | } | 
|---|
|  | 472 |  | 
|---|
|  | 473 | try {  // SliX | 
|---|
|  | 474 | int_4 nb = dvl.GetI("NSLICEX",-1); | 
|---|
|  | 475 | int_4 ipr = dvl.GetI("SLICEX",-1); | 
|---|
|  | 476 | dobj->SetSliX(nb); | 
|---|
|  | 477 | for(int i=0;i<nb;i++) { | 
|---|
|  | 478 | is.MoveAbsToHDU(hducur+ipr+i); | 
|---|
|  | 479 | Histo *h = dobj->HSliX(i); | 
|---|
|  | 480 | FitsHandler<Histo> fio(*h); fio.Read(is); | 
|---|
|  | 481 | if(h->NBins()!=dobj->NBinX()) | 
|---|
|  | 482 | throw FitsIOException("unmatched bin number"); | 
|---|
|  | 483 | } | 
|---|
|  | 484 | } catch (...) { | 
|---|
|  | 485 | dobj->DelSliX(); | 
|---|
|  | 486 | cout<<"FitsHandler<Histo2D>::Read: Error reading SLICEX"<<endl; | 
|---|
|  | 487 | } | 
|---|
|  | 488 |  | 
|---|
|  | 489 | try {  // SliY | 
|---|
|  | 490 | int_4 nb = dvl.GetI("NSLICEY",-1); | 
|---|
|  | 491 | int_4 ipr = dvl.GetI("SLICEY",-1); | 
|---|
|  | 492 | dobj->SetSliY(nb); | 
|---|
|  | 493 | for(int i=0;i<nb;i++) { | 
|---|
|  | 494 | is.MoveAbsToHDU(hducur+ipr+i); | 
|---|
|  | 495 | Histo *h = dobj->HSliY(i); | 
|---|
|  | 496 | FitsHandler<Histo> fio(*h); fio.Read(is); | 
|---|
|  | 497 | if(h->NBins()!=dobj->NBinY()) | 
|---|
|  | 498 | throw FitsIOException("unmatched bin number"); | 
|---|
|  | 499 | } | 
|---|
|  | 500 | } catch (...) { | 
|---|
|  | 501 | dobj->DelSliY(); | 
|---|
|  | 502 | cout<<"FitsHandler<Histo2D>::Read: Error reading SLICEY"<<endl; | 
|---|
|  | 503 | } | 
|---|
|  | 504 |  | 
|---|
|  | 505 | try {  // BandeX | 
|---|
|  | 506 | int_4 nb = dvl.GetI("NBANDEX",-1); | 
|---|
|  | 507 | int_4 ipr = dvl.GetI("BANDEX",-1); | 
|---|
|  | 508 | for(int i=0;i<nb;i++) { | 
|---|
|  | 509 | char str[32]; | 
|---|
|  | 510 | sprintf(str,"BXL%d",i); r_8 vmin = dvl.GetD(str,0.); | 
|---|
|  | 511 | sprintf(str,"BXH%d",i); r_8 vmax = dvl.GetD(str,0.); | 
|---|
|  | 512 | dobj->SetBandX(vmin,vmax); | 
|---|
|  | 513 | is.MoveAbsToHDU(hducur+ipr+i); | 
|---|
|  | 514 | Histo *h = dobj->HBandX(i); | 
|---|
|  | 515 | FitsHandler<Histo> fio(*h); fio.Read(is); | 
|---|
|  | 516 | if(h->NBins()!=dobj->NBinX()) | 
|---|
|  | 517 | throw FitsIOException("unmatched bin number"); | 
|---|
|  | 518 | } | 
|---|
|  | 519 | } catch (...) { | 
|---|
|  | 520 | dobj->DelBandX(); | 
|---|
|  | 521 | cout<<"FitsHandler<Histo2D>::Read: Error reading BANDEX"<<endl; | 
|---|
|  | 522 | } | 
|---|
|  | 523 |  | 
|---|
|  | 524 | try {  // BandeY | 
|---|
|  | 525 | int_4 nb = dvl.GetI("NBANDEY",-1); | 
|---|
|  | 526 | int_4 ipr = dvl.GetI("BANDEY",-1); | 
|---|
|  | 527 | for(int i=0;i<nb;i++) { | 
|---|
|  | 528 | char str[32]; | 
|---|
|  | 529 | sprintf(str,"BYL%d",i); r_8 vmin = dvl.GetD(str,0.); | 
|---|
|  | 530 | sprintf(str,"BYH%d",i); r_8 vmax = dvl.GetD(str,0.); | 
|---|
|  | 531 | dobj->SetBandY(vmin,vmax); | 
|---|
|  | 532 | is.MoveAbsToHDU(hducur+ipr+i); | 
|---|
|  | 533 | Histo *h = dobj->HBandY(i); | 
|---|
|  | 534 | FitsHandler<Histo> fio(*h); fio.Read(is); | 
|---|
|  | 535 | if(h->NBins()!=dobj->NBinY()) | 
|---|
|  | 536 | throw FitsIOException("unmatched bin number"); | 
|---|
|  | 537 | } | 
|---|
|  | 538 | } catch (...) { | 
|---|
|  | 539 | dobj->DelBandY(); | 
|---|
|  | 540 | cout<<"FitsHandler<Histo2D>::Read: Error reading BANDEY"<<endl; | 
|---|
|  | 541 | } | 
|---|
|  | 542 |  | 
|---|
|  | 543 | return; | 
|---|
| [3049] | 544 | } | 
|---|
| [3237] | 545 |  | 
|---|
|  | 546 | } // FIN namespace SOPHYA | 
|---|