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