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