Changeset 3059 in Sophya for trunk/SophyaExt/FitsIOServer


Ignore:
Timestamp:
Aug 13, 2006, 3:17:33 PM (19 years ago)
Author:
cmv
Message:

Gestion des IO des projections associees a un Histo2D dans FITS multihdu (ecriture et lecture) cmv 13/8/2006

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaExt/FitsIOServer/fitshistos.cc

    r3056 r3059  
    147147  }
    148148
     149  return;
    149150}
    150151
     
    232233  if(he) FitsBlockRW<r_8>::ReadColumnData(is,3,1,1,he->mNData,nbin);
    233234
     235  return;
    234236}
    235237
     
    265267
    266268  //--- Le type d'objet et son pointeur
    267   Histo2D* h = dynamic_cast< Histo2D *> (dobj);
     269  Histo2D* h2 = dynamic_cast< Histo2D *> (dobj);
    268270
    269271  //--- Les noms de colonnes
     
    275277  tunit.push_back("");
    276278  // Les erreurs
    277   if(h->mErr2) {
     279  if(h2->mErr2) {
    278280    if(tbltyp==ASCII_TBL) tform.push_back("D15.8"); else tform.push_back("D");
    279281    colnames.push_back("e2");
     
    286288
    287289  // Ecriture des donnees des colonnes
    288   long n = h->mNxy;
     290  long n = h2->mNxy;
    289291  if(n>0) {
    290     FitsBlockRW<r_8>::WriteColumnData(os,1,1,1,h->mData,n);
    291     if(h->mErr2) FitsBlockRW<r_8>::WriteColumnData(os,2,1,1,h->mErr2,n);
     292    FitsBlockRW<r_8>::WriteColumnData(os,1,1,1,h2->mData,n);
     293    if(h2->mErr2) FitsBlockRW<r_8>::WriteColumnData(os,2,1,1,h2->mErr2,n);
    292294  }
    293295
     
    301303  os.WriteKey("CONTENT",mtv," name of SOPHYA object");
    302304
    303   mtv = h->mNx;
     305  mtv = h2->mNx;
    304306  os.WriteKey("NBINX",mtv," number of bins in X");
    305   mtv = h->mNy;
     307  mtv = h2->mNy;
    306308  os.WriteKey("NBINY",mtv," number of bins in Y");
    307   mtv = h->mNxy;
     309  mtv = h2->mNxy;
    308310  os.WriteKey("NBINXY",mtv," number of elements");
    309311
    310   mtv = h->mXmin;
     312  mtv = h2->mXmin;
    311313  os.WriteKey("XMIN",mtv," absc of beginning of 1srt bin in X");
    312   mtv = h->mXmax;
     314  mtv = h2->mXmax;
    313315  os.WriteKey("XMAX",mtv," absc of end of last bin in X");
    314   mtv = h->mYmin;
     316  mtv = h2->mYmin;
    315317  os.WriteKey("YMIN",mtv," absc of beginning of 1srt bin in Y");
    316   mtv = h->mYmax;
     318  mtv = h2->mYmax;
    317319  os.WriteKey("YMAX",mtv," absc of end of last bin in Y");
    318320
    319   mtv = h->mWBinx;
     321  mtv = h2->mWBinx;
    320322  os.WriteKey("WBINX",mtv," bin width in X");
    321   mtv = h->mWBiny;
     323  mtv = h2->mWBiny;
    322324  os.WriteKey("WBINY",mtv," bin width in Y");
    323325
    324326  for(int i=0;i<3;i++) for(int j=0;j<3;j++) {
    325327    char str[16]; sprintf(str,"OUT%1d%1d",i,j);
    326     mtv = h->mOver[i][j];
     328    mtv = h2->mOver[i][j];
    327329    os.WriteKey(str,mtv," under/over X/Y");
    328330  }
    329331
    330   mtv = h->nHist;
     332  mtv = h2->nHist;
    331333  os.WriteKey("NHIST",mtv," entries weighted somme");
    332334
    333   mtv = h->nEntries;
     335  mtv = h2->nEntries;
    334336  os.WriteKey("NENTRIES",mtv," number of entries");
    335337
    336   int_4 haserr =(h->mErr2) ? 1: 0;
     338  int_4 haserr =(h2->mErr2) ? 1: 0;
    337339  mtv = haserr;
    338340  os.WriteKey("HASERR2",mtv," square errors associated");
    339341
     342
     343
     344  //-------------------------------------------------------------
     345  //------ Gestion des Histo1D de projx/y bandx/t slicex/y ------
     346  //-------------------------------------------------------------
     347
     348  int_4 nrel = 0;
     349  if(h2->HProjX()) {nrel++; mtv=nrel; os.WriteKey("PROJX",mtv," relative HDU with HProjX");}
     350  if(h2->HProjY()) {nrel++; mtv=nrel; os.WriteKey("PROJY",mtv," relative HDU with HProjY");}
     351  if(h2->NSliX()>0) {
     352    mtv=h2->NSliX(); os.WriteKey("NSLICEX",mtv," number of SliX");
     353    nrel++;
     354    mtv=nrel; os.WriteKey("SLICEX",mtv," relative HDU with first SliX");
     355    nrel += h2->NSliX()-1;
     356  }
     357  if(h2->NSliY()>0) {
     358    mtv=h2->NSliY(); os.WriteKey("NSLICEY",mtv," number of SliY");
     359    nrel++;
     360    mtv=nrel; os.WriteKey("SLICEY",mtv," relative HDU with first SliY");
     361    nrel += h2->NSliY()-1;
     362  }
     363  if(h2->NBandX()>0) {
     364    mtv=h2->NBandX(); os.WriteKey("NBANDEX",mtv," number of BandX");
     365    nrel++;
     366    mtv=nrel; os.WriteKey("BANDEX",mtv," relative HDU with first BandX");
     367    nrel += h2->NBandX()-1;
     368    for(int i=0;i<h2->NBandX();i++) {
     369      char str[32]; r_8 vmin,vmax;
     370      h2->GetBandX(i,vmin,vmax);
     371      sprintf(str,"BXL%d",i);
     372      mtv = vmin; os.WriteKey(str,mtv," low Y limit for BandX");
     373      sprintf(str,"BXH%d",i);
     374      mtv = vmax; os.WriteKey(str,mtv," high Y limit for BandX");
     375    }
     376  }
     377  if(h2->NBandY()>0) {
     378    mtv=h2->NBandY(); os.WriteKey("NBANDEY",mtv," number of BandY");
     379    nrel++;
     380    mtv=nrel; os.WriteKey("BANDEY",mtv," relative HDU with first BandY");
     381    nrel += h2->NBandY()-1;
     382    for(int i=0;i<h2->NBandY();i++) {
     383      char str[32]; r_8 vmin,vmax;
     384      h2->GetBandY(i,vmin,vmax);
     385      sprintf(str,"BYL%d",i);
     386      mtv = vmin; os.WriteKey(str,mtv," low X limit for BandY");
     387      sprintf(str,"BYH%d",i);
     388      mtv = vmax; os.WriteKey(str,mtv," high X limit for BandY");
     389    }
     390  }
     391  mtv=nrel; os.WriteKey("NH1ASS",mtv," number of associated Histo1D");
     392
     393  if(h2->HProjX()) {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HProjX()))); fio.Write(os);}
     394  if(h2->HProjY()) {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HProjY()))); fio.Write(os);}
     395  if(h2->NSliX()>0) for(int i=0;i<h2->NSliX();i++)
     396    {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HSliX(i)))); fio.Write(os);}
     397  if(h2->NSliY()>0) for(int i=0;i<h2->NSliY();i++)
     398    {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HSliY(i)))); fio.Write(os);}
     399  if(h2->NBandX()>0) for(int i=0;i<h2->NBandX();i++)
     400    {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HBandX(i)))); fio.Write(os);}
     401  if(h2->NBandY()>0) for(int i=0;i<h2->NBandY();i++)
     402    {FitsHandler<Histo> fio(const_cast<Histo &>(*(h2->HBandY(i)))); fio.Write(os);}
     403
     404  return;
    340405}
    341406
     
    390455  if(dobj->mErr2) FitsBlockRW<r_8>::ReadColumnData(is,2,1,1,dobj->mErr2,nbinxy);
    391456
    392 }
     457
     458
     459  //-------------------------------------------------------------
     460  //------ Gestion des Histo1D de projx/y bandx/t slicex/y ------
     461  //-------------------------------------------------------------
     462
     463  int_4 nh1ass = dvl.GetI("NH1ASS",-1);
     464  if(nh1ass<=0) return;
     465  int hducur = is.CurrentHDU();
     466
     467  try {  // ProjX
     468    int_4 ipr = dvl.GetI("PROJX",-1);
     469    is.MoveAbsToHDU(hducur+ipr);
     470    dobj->SetProjX();
     471    Histo *h = dobj->HProjX();
     472    FitsHandler<Histo> fio(*h); fio.Read(is);
     473    if(h->NBins()!=dobj->NBinX())
     474      throw FitsIOException("unmatched bin number");
     475  } catch (...) {
     476    dobj->DelProjX();
     477    cout<<"FitsHandler<Histo2D>::Read: Error reading PROJX"<<endl;
     478  }
     479
     480  try {  // ProjY
     481    int_4 ipr = dvl.GetI("PROJY",-1);
     482    is.MoveAbsToHDU(hducur+ipr);
     483    dobj->SetProjY();
     484    Histo *h = dobj->HProjY();
     485    FitsHandler<Histo> fio(*h); fio.Read(is);
     486    if(h->NBins()!=dobj->NBinY())
     487      throw FitsIOException("unmatched bin number");
     488  } catch (...) {
     489    dobj->DelProjY();
     490    cout<<"FitsHandler<Histo2D>::Read: Error reading PROJY"<<endl;
     491  }
     492
     493  try {  // SliX
     494    int_4 nb = dvl.GetI("NSLICEX",-1);
     495    int_4 ipr = dvl.GetI("SLICEX",-1);
     496    dobj->SetSliX(nb);
     497    for(int i=0;i<nb;i++) {
     498      is.MoveAbsToHDU(hducur+ipr+i);
     499      Histo *h = dobj->HSliX(i);
     500      FitsHandler<Histo> fio(*h); fio.Read(is);
     501      if(h->NBins()!=dobj->NBinX())
     502        throw FitsIOException("unmatched bin number");
     503    }
     504  } catch (...) {
     505    dobj->DelSliX();
     506    cout<<"FitsHandler<Histo2D>::Read: Error reading SLICEX"<<endl;
     507  }
     508
     509  try {  // SliY
     510    int_4 nb = dvl.GetI("NSLICEY",-1);
     511    int_4 ipr = dvl.GetI("SLICEY",-1);
     512    dobj->SetSliY(nb);
     513    for(int i=0;i<nb;i++) {
     514      is.MoveAbsToHDU(hducur+ipr+i);
     515      Histo *h = dobj->HSliY(i);
     516      FitsHandler<Histo> fio(*h); fio.Read(is);
     517      if(h->NBins()!=dobj->NBinY())
     518        throw FitsIOException("unmatched bin number");
     519    }
     520  } catch (...) {
     521    dobj->DelSliY();
     522    cout<<"FitsHandler<Histo2D>::Read: Error reading SLICEY"<<endl;
     523  }
     524
     525  try {  // BandeX
     526    int_4 nb = dvl.GetI("NBANDEX",-1);
     527    int_4 ipr = dvl.GetI("BANDEX",-1);
     528    for(int i=0;i<nb;i++) {
     529      char str[32];
     530      sprintf(str,"BXL%d",i); r_8 vmin = dvl.GetD(str,0.);
     531      sprintf(str,"BXH%d",i); r_8 vmax = dvl.GetD(str,0.);
     532      dobj->SetBandX(vmin,vmax);
     533      is.MoveAbsToHDU(hducur+ipr+i);
     534      Histo *h = dobj->HBandX(i);
     535      FitsHandler<Histo> fio(*h); fio.Read(is);
     536      if(h->NBins()!=dobj->NBinX())
     537        throw FitsIOException("unmatched bin number");
     538    }
     539  } catch (...) {
     540    dobj->DelBandX();
     541    cout<<"FitsHandler<Histo2D>::Read: Error reading BANDEX"<<endl;
     542  }
     543
     544  try {  // BandeY
     545    int_4 nb = dvl.GetI("NBANDEY",-1);
     546    int_4 ipr = dvl.GetI("BANDEY",-1);
     547    for(int i=0;i<nb;i++) {
     548      char str[32];
     549      sprintf(str,"BYL%d",i); r_8 vmin = dvl.GetD(str,0.);
     550      sprintf(str,"BYH%d",i); r_8 vmax = dvl.GetD(str,0.);
     551      dobj->SetBandY(vmin,vmax);
     552      is.MoveAbsToHDU(hducur+ipr+i);
     553      Histo *h = dobj->HBandY(i);
     554      FitsHandler<Histo> fio(*h); fio.Read(is);
     555      if(h->NBins()!=dobj->NBinY())
     556        throw FitsIOException("unmatched bin number");
     557    }
     558  } catch (...) {
     559    dobj->DelBandY();
     560    cout<<"FitsHandler<Histo2D>::Read: Error reading BANDEY"<<endl;
     561  }
     562
     563  return;
     564}
Note: See TracChangeset for help on using the changeset viewer.