source: Sophya/trunk/SophyaExt/FitsIOServer/fitsbntbllineRW.cc@ 1209

Last change on this file since 1209 was 1209, checked in by ansari, 25 years ago

ecriture ligne a ligne

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