1 | #include "pexceptions.h"
|
---|
2 | #include "fitsbntbllineRW.h"
|
---|
3 | #include "utils.h"
|
---|
4 | ///////////////////////////////////////////////////////////
|
---|
5 | //
|
---|
6 | //
|
---|
7 | ///////////////////////////////////////////////////////////
|
---|
8 |
|
---|
9 |
|
---|
10 | #define LONNOM 31
|
---|
11 |
|
---|
12 |
|
---|
13 | FITS_BntblLineReader::FITS_BntblLineReader()
|
---|
14 | {
|
---|
15 | InitNull();
|
---|
16 | }
|
---|
17 |
|
---|
18 | FITS_BntblLineReader::FITS_BntblLineReader(char inputfile[],int hdunum)
|
---|
19 |
|
---|
20 | {
|
---|
21 | InitNull();
|
---|
22 | inFits_ = new FitsInFile (inputfile);
|
---|
23 | inFits_->ReadFInit(hdunum);
|
---|
24 |
|
---|
25 | // if (!fn->IsFitsTable())
|
---|
26 | if (!inFits_->IsFitsTable())
|
---|
27 | {
|
---|
28 | throw PException("FITS_BntblLineReader: the fits file seems not to be a bintable nor ASCII table");
|
---|
29 | }
|
---|
30 |
|
---|
31 | //
|
---|
32 | int nbcols, nbentries;
|
---|
33 | // nbcols = fn->NbColsFromFits();
|
---|
34 | nbcols = inFits_->NbColsFromFits();
|
---|
35 | nbentries = 0;
|
---|
36 | int k;
|
---|
37 | // for (k=0; k<nbcols; k++) nbentries=max( nbentries, fn->NentriesFromFits(k) );
|
---|
38 | for (k=0; k<nbcols; k++) nbentries=max( nbentries, inFits_->NentriesFromFits(k) );
|
---|
39 |
|
---|
40 | //
|
---|
41 | // pour mettre les colonnes dans l'ordre double, float, int, char :
|
---|
42 | // tableau de correspondance
|
---|
43 | // DfitsCol(j)= numero dans le fichier fits de la jeme variable double du
|
---|
44 | // xntuple;
|
---|
45 | // FfitsCol(j)= numero dans le fichier fits de la jeme variable float du
|
---|
46 | // xntuple;
|
---|
47 | // etc.
|
---|
48 | vector<int> DfitsCol;
|
---|
49 | vector<int> FfitsCol;
|
---|
50 | vector<int> IfitsCol;
|
---|
51 | vector<int> SfitsCol;
|
---|
52 | for (k=0; k<nbcols;k++)
|
---|
53 | {
|
---|
54 | // char ss= fn->ColTypeFromFits(k);
|
---|
55 | char ss= inFits_->ColTypeFromFits(k);
|
---|
56 | if (ss == 'D') DfitsCol.push_back(k);
|
---|
57 | else if (ss == 'E') FfitsCol.push_back(k);
|
---|
58 | else if (ss == 'I') IfitsCol.push_back(k);
|
---|
59 | else if (ss == 'S') SfitsCol.push_back(k);
|
---|
60 | else {
|
---|
61 | cout << " FITS_XNTuple: colonne fits " << k << " type= " << ss << endl;
|
---|
62 | throw IOExc("type de champ inconnu");
|
---|
63 | }
|
---|
64 | }
|
---|
65 | vector<string> ColN(nbcols);
|
---|
66 | int compt=0;
|
---|
67 | for (k=0; k<DfitsCol.size(); k++)
|
---|
68 | {
|
---|
69 | ColN[compt++] = inFits_->ColNameFromFits(DfitsCol[k]);
|
---|
70 | }
|
---|
71 | for (k=0; k<FfitsCol.size(); k++)
|
---|
72 | {
|
---|
73 | ColN[compt++] = inFits_->ColNameFromFits(FfitsCol[k]);
|
---|
74 | }
|
---|
75 | for (k=0; k<IfitsCol.size(); k++)
|
---|
76 | {
|
---|
77 | ColN[compt++] = inFits_->ColNameFromFits(IfitsCol[k]);
|
---|
78 | }
|
---|
79 | for (k=0; k<SfitsCol.size(); k++)
|
---|
80 | {
|
---|
81 | ColN[compt++] = inFits_->ColNameFromFits(SfitsCol[k]);
|
---|
82 | }
|
---|
83 |
|
---|
84 | ligne_.setFormat(DfitsCol.size(), FfitsCol.size(), IfitsCol.size(), SfitsCol.size(), ColN);
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | FITS_BntblLineReader::~FITS_BntblLineReader()
|
---|
89 | {
|
---|
90 | if (inFits_ != NULL) delete inFits_;
|
---|
91 | }
|
---|
92 |
|
---|
93 | BnTblLine& FITS_BntblLineReader::ReadNextLine()
|
---|
94 | {
|
---|
95 | inFits_->GetBinTabLine(nextLineToBeRead_++, ligne_);
|
---|
96 | return ligne_;
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 |
|
---|
102 | FITS_BntblLineWriter::FITS_BntblLineWriter(char inputfile[],int dc, int fc,int ic, int cc, vector<string> names,DVList& dvl, WriteMode wrm)
|
---|
103 | {
|
---|
104 | int k;
|
---|
105 | int nbcols = dc+fc+ic+cc;
|
---|
106 | if (nbcols != names.size())
|
---|
107 | {
|
---|
108 | cout << " WARNING: BnTblLineWriter:: length of vector of column names not equal to total number of columns" << endl;
|
---|
109 | }
|
---|
110 | InitNull();
|
---|
111 | outFits_ = new FitsOutFile (inputfile, wrm);
|
---|
112 | string types;
|
---|
113 | vector<int> StringSizes(cc);
|
---|
114 | for (k=0; k<dc;k++)
|
---|
115 | {
|
---|
116 | types+='D';
|
---|
117 | }
|
---|
118 | for (k=0; k<fc;k++)
|
---|
119 | {
|
---|
120 | types+='E';
|
---|
121 | }
|
---|
122 | for (k=0; k<ic;k++)
|
---|
123 | {
|
---|
124 | types+='I';
|
---|
125 | }
|
---|
126 | for (k=0; k<cc;k++)
|
---|
127 | {
|
---|
128 | types+='A';
|
---|
129 | StringSizes[k] = names[dc+fc+ic+k].length();
|
---|
130 | }
|
---|
131 | string extname("Lines_on_Binary_tbl");
|
---|
132 |
|
---|
133 | outFits_->makeHeaderBntblOnFits(types, names, 1, nbcols, dvl, extname,StringSizes);
|
---|
134 | ligne_.setFormat(dc, fc, ic, cc, names);
|
---|
135 |
|
---|
136 | }
|
---|
137 |
|
---|
138 | FITS_BntblLineWriter::~FITS_BntblLineWriter()
|
---|
139 | {
|
---|
140 | if (dvl_ != NULL) delete dvl_;
|
---|
141 | if (outFits_ != NULL) delete outFits_;
|
---|
142 | }
|
---|
143 |
|
---|
144 | void FITS_BntblLineWriter::WriteNextLine( BnTblLine& WorkLine)
|
---|
145 | {
|
---|
146 | if (! ligne_.sameFormat(WorkLine) )
|
---|
147 | {
|
---|
148 | throw PException(" FITS_BntblLineWriter:: line to be written does not match the header");
|
---|
149 | }
|
---|
150 | outFits_->PutBinTabLine(nextLineToBeWritten_++, WorkLine);
|
---|
151 |
|
---|
152 | }
|
---|