| 1 | // Test des classes FitsBTColRead
 | 
|---|
| 2 | #include "machdefs.h"
 | 
|---|
| 3 | #include <typeinfo>
 | 
|---|
| 4 | #include <stdio.h>
 | 
|---|
| 5 | #include <stdlib.h>
 | 
|---|
| 6 | #include <iostream.h>
 | 
|---|
| 7 | #include <values.h>
 | 
|---|
| 8 | #include <string.h>
 | 
|---|
| 9 | #include <string>
 | 
|---|
| 10 | #include <unistd.h>
 | 
|---|
| 11 | #include "sophyainit.h"
 | 
|---|
| 12 | #include "pexceptions.h"
 | 
|---|
| 13 | #include "fabtcolread.h"
 | 
|---|
| 14 | #include "fabtwriter.h"
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #define NO_VECTOR
 | 
|---|
| 17 | #define USE_EXCEPT
 | 
|---|
| 18 | 
 | 
|---|
| 19 | int main(int narg,char *arg[])
 | 
|---|
| 20 | {
 | 
|---|
| 21 |  SophyaInit();
 | 
|---|
| 22 |  char *colname = "";
 | 
|---|
| 23 |  int colnum = -1;
 | 
|---|
| 24 |  int ihdu = 0;
 | 
|---|
| 25 |  long blen = 100;
 | 
|---|
| 26 |  long bsens = 1;
 | 
|---|
| 27 |  long lpmod=1;
 | 
|---|
| 28 |  double vs1,vs2; bool vsearch=false;
 | 
|---|
| 29 |  char c;
 | 
|---|
| 30 |  while((c = getopt(narg,arg,"hb:s:H:i:c:m:v:")) != -1) {
 | 
|---|
| 31 |    switch (c) {
 | 
|---|
| 32 |    case 'b' :
 | 
|---|
| 33 |      sscanf(optarg,"%ld",&blen);
 | 
|---|
| 34 |      break;
 | 
|---|
| 35 |    case 's' :
 | 
|---|
| 36 |      sscanf(optarg,"%ld",&bsens);
 | 
|---|
| 37 |      break;
 | 
|---|
| 38 |    case 'H' :
 | 
|---|
| 39 |      sscanf(optarg,"%d",&ihdu);
 | 
|---|
| 40 |      break;
 | 
|---|
| 41 |    case 'i' :
 | 
|---|
| 42 |      sscanf(optarg,"%d",&colnum);
 | 
|---|
| 43 |      break;
 | 
|---|
| 44 |    case 'c' :
 | 
|---|
| 45 |      colname = optarg;
 | 
|---|
| 46 |      break;
 | 
|---|
| 47 |    case 'm' :
 | 
|---|
| 48 |      sscanf(optarg,"%ld",&lpmod);
 | 
|---|
| 49 |      if(lpmod<=0) lpmod = 1;
 | 
|---|
| 50 |      break;
 | 
|---|
| 51 |    case 'v' :
 | 
|---|
| 52 |      sscanf(optarg,"%lf,%lf",&vs1,&vs2);
 | 
|---|
| 53 |      vsearch=true;
 | 
|---|
| 54 |      break;
 | 
|---|
| 55 |    case 'h' :
 | 
|---|
| 56 |    default :
 | 
|---|
| 57 |      cout<<"cmvcolread -b buflen -s sens -H hdu -m print_modulo"
 | 
|---|
| 58 |          <<" -i colnum -c colname -v vsearch1,vsearch2"
 | 
|---|
| 59 |          <<" fitsread fitswrite"<<endl;
 | 
|---|
| 60 |      return -1;
 | 
|---|
| 61 |    }
 | 
|---|
| 62 |  }
 | 
|---|
| 63 |  if(optind>=narg) {
 | 
|---|
| 64 |    cout<<"Donnez un nom de fichier fits"<<endl;
 | 
|---|
| 65 |    return -1;
 | 
|---|
| 66 |  }
 | 
|---|
| 67 |  char * fitsname = arg[optind];
 | 
|---|
| 68 |  char * fitswrit = NULL;
 | 
|---|
| 69 |  if(optind+1<narg) fitswrit = arg[optind+1];
 | 
|---|
| 70 | 
 | 
|---|
| 71 |  FitsABTColRead* fbt=NULL;
 | 
|---|
| 72 |  FitsABTWriter*  fbtw=NULL;
 | 
|---|
| 73 |  if(fitswrit)
 | 
|---|
| 74 |    fbtw = new FitsABTWriter(fitswrit,BINARY_TBL,3);
 | 
|---|
| 75 | 
 | 
|---|
| 76 | #ifdef USE_EXCEPT
 | 
|---|
| 77 | try {
 | 
|---|
| 78 | #endif
 | 
|---|
| 79 | 
 | 
|---|
| 80 |   if(strlen(colname)>0)
 | 
|---|
| 81 |     fbt = new FitsABTColRead(fitsname,colname,ihdu,blen,bsens,3);
 | 
|---|
| 82 |   else
 | 
|---|
| 83 |     fbt = new FitsABTColRead(fitsname,colnum,ihdu,blen,bsens,3);
 | 
|---|
| 84 |   fbt->SetDebug(3);
 | 
|---|
| 85 |   fbt->Print(3);
 | 
|---|
| 86 |   cout<<"ReadFirstRow : "<<fbt->ReadFirstRow()<<endl;
 | 
|---|
| 87 |   cout<<"ReadLastRow  : "<<fbt->ReadLastRow()<<endl;
 | 
|---|
| 88 | 
 | 
|---|
| 89 |   if(fbtw) {
 | 
|---|
| 90 |     fbtw->SetExtName("MON_EXTENSION");
 | 
|---|
| 91 |     fbtw->AddCol("xshort",NULL,"unitS",TSHORT);
 | 
|---|
| 92 |     fbtw->AddCol("xlong",NULL,"unitL",TLONG);
 | 
|---|
| 93 |     fbtw->AddCol("xfloat",NULL,"unitF",TFLOAT);
 | 
|---|
| 94 |     fbtw->AddCol("xdouble",NULL,"unitD",TDOUBLE);
 | 
|---|
| 95 |     fbtw->AddCol("xshort2",NULL,"unitS",TSHORT);
 | 
|---|
| 96 |     fbtw->SetDebug(3);
 | 
|---|
| 97 |   }
 | 
|---|
| 98 | 
 | 
|---|
| 99 |   if(vsearch) {
 | 
|---|
| 100 |     long mid = fbt->GetNbLine()/2;
 | 
|---|
| 101 |     cout<<"Search vs1="<<vs1<<" vs2="<<vs2<<endl;
 | 
|---|
| 102 |     cout<<"FirstRow: "<<fbt->FirstRow(vs1,vs2,-1)<<endl;
 | 
|---|
| 103 |     cout<<"LastRow : "<<fbt->LastRow(vs1,vs2,-1)<<endl;
 | 
|---|
| 104 |     cout<<"FirstRow from middle: "<<fbt->FirstRow(vs1,vs2,mid)<<endl;
 | 
|---|
| 105 |     cout<<"LastRow  from middle: "<<fbt->LastRow(vs1,vs2,mid)<<endl;
 | 
|---|
| 106 |   }
 | 
|---|
| 107 | 
 | 
|---|
| 108 | #ifdef NO_VECTOR
 | 
|---|
| 109 |   cout<<"Writting element by elements"<<endl;
 | 
|---|
| 110 |   for(long i=0;i<fbt->GetNbLine();i++) {
 | 
|---|
| 111 |     double x = fbt->Read(i);
 | 
|---|
| 112 |     if(i%lpmod==0) cout<<i<<": "<<x<<endl;
 | 
|---|
| 113 |     if(fbtw) {
 | 
|---|
| 114 |       fbtw->Write(0,i,x); // Si overflow la conversion est faite par cfitsio
 | 
|---|
| 115 |       fbtw->Write(1,i,x);
 | 
|---|
| 116 |       fbtw->Write(2,i,x);
 | 
|---|
| 117 |       fbtw->Write(3,i,x);
 | 
|---|
| 118 |       fbtw->Write(4,i,(short)x); // Si overflow la conversion est faite par le system
 | 
|---|
| 119 |     }
 | 
|---|
| 120 |   }
 | 
|---|
| 121 | #else
 | 
|---|
| 122 |   cout<<"Writting with vectors"<<endl;
 | 
|---|
| 123 |   TVector<double> data;
 | 
|---|
| 124 |   TVector<float> dataf;
 | 
|---|
| 125 |   TVector<int_4> datal;
 | 
|---|
| 126 |   long istep = fbt->GetNbLine()/10; if(istep>1000) istep=1000;
 | 
|---|
| 127 |   for(long i=0;i<fbt->GetNbLine();i+=istep) {
 | 
|---|
| 128 |     long i2=i+istep-1; if(i2>=fbt->GetNbLine()) i2=fbt->GetNbLine()-1;
 | 
|---|
| 129 |     long n = fbt->Read(i,i2,data);
 | 
|---|
| 130 |     fbt->Read(i,i2,dataf);
 | 
|---|
| 131 |     fbt->Read(i,i2,datal);
 | 
|---|
| 132 |     cout<<i<<" n="<<n<<" ("<<data.Size()<<")"
 | 
|---|
| 133 |         <<" d="<<data(0)<<","<<data(n-1)
 | 
|---|
| 134 |         <<" f="<<dataf(0)<<","<<dataf(n-1)
 | 
|---|
| 135 |         <<" l="<<datal(0)<<","<<datal(n-1)
 | 
|---|
| 136 |         <<endl;
 | 
|---|
| 137 |     if(fbtw) {
 | 
|---|
| 138 |       fbtw->Write(1,i,datal);
 | 
|---|
| 139 |       fbtw->Write(2,i,dataf);
 | 
|---|
| 140 |       fbtw->Write(3,i,data);
 | 
|---|
| 141 |     }
 | 
|---|
| 142 |   }
 | 
|---|
| 143 | #endif
 | 
|---|
| 144 | 
 | 
|---|
| 145 |   fbt->Print(3);
 | 
|---|
| 146 | 
 | 
|---|
| 147 |   //FitsABTColRead fbt2(*fbt);
 | 
|---|
| 148 |   //fbt2.SetDebug(3);
 | 
|---|
| 149 |   //fbt2.Print(3);
 | 
|---|
| 150 |   //cout<<"Read(0):   "<<fbt2.Read(0)<<endl;
 | 
|---|
| 151 |   //cout<<"Read(n-1): "<<fbt2.Read(fbt2.GetNbLine()-1)<<endl;
 | 
|---|
| 152 |   //fbt2.Print(3);
 | 
|---|
| 153 | 
 | 
|---|
| 154 |   if(fbt) delete fbt;
 | 
|---|
| 155 |   if(fbtw) {
 | 
|---|
| 156 |     cout<<"Number of Overflows when writing: "<<fbtw->GetNOverFlow()<<endl;
 | 
|---|
| 157 |     delete fbtw;
 | 
|---|
| 158 |   }
 | 
|---|
| 159 | 
 | 
|---|
| 160 | #ifdef USE_EXCEPT
 | 
|---|
| 161 | } catch (PThrowable & exc) {
 | 
|---|
| 162 |   cout<<"Exception : "<<(string)typeid(exc).name()
 | 
|---|
| 163 |       <<" - Msg= "<<exc.Msg()<<endl;
 | 
|---|
| 164 |   if(fbt) delete fbt;
 | 
|---|
| 165 |   if(fbtw) delete fbtw;
 | 
|---|
| 166 |   return -2;
 | 
|---|
| 167 | 
 | 
|---|
| 168 | } catch (...) {
 | 
|---|
| 169 |   cout<<" some other exception was caught !"<<endl;
 | 
|---|
| 170 |   if(fbt) delete fbt;
 | 
|---|
| 171 |   if(fbtw) delete fbtw;
 | 
|---|
| 172 |   return -2;
 | 
|---|
| 173 | }
 | 
|---|
| 174 | #endif
 | 
|---|
| 175 | 
 | 
|---|
| 176 |  return 0;
 | 
|---|
| 177 | }
 | 
|---|