source: Sophya/trunk/ArchTOIPipe/Kernel/piotoirdr.cc

Last change on this file was 2461, checked in by aubourg, 22 years ago

format %ld

File size: 3.5 KB
Line 
1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
5// $Id: piotoirdr.cc,v 1.12 2003-11-22 21:59:00 aubourg Exp $
6
7#include "piotoirdr.h"
8
9extern void fits_lock();
10extern void fits_unlock();
11
12//char** environ; // For darwin dylibs with piolib
13
14PIOTOIReader::PIOTOIReader(string grp, string obj, string flg) {
15 group = grp;
16 object = obj;
17 flagdef = flg;
18 pioGroup = NULL;
19
20}
21
22PIOTOIReader::~PIOTOIReader() {
23 if (pioGroup != NULL) {
24 // ??
25 }
26}
27
28void PIOTOIReader::init() {
29 fits_lock();
30 char groupname[128];
31 strcpy(groupname, group.c_str());
32 pioGroup = PIOOpenTOI(groupname, "r");
33
34 if (pioGroup == NULL) {
35 cerr << " ERROR in PIOOpenTOI cannnot open " << groupname << endl;
36 abort();
37 }
38 fits_unlock();
39 cout << "pioGroup : "<< pioGroup << endl;
40 readBounds();
41 bufferSize = 1000;
42 cout << "PIOTOIReader : opened " << groupname
43 << " " << snBegin << " - " << snEnd << ": " << pioGroup << endl;
44 if (flagdef != "") {
45 cout << " with flagdef = " << flagdef << endl;
46 }
47
48 declareOutput(object);
49}
50
51void PIOTOIReader::readBounds() {
52 PIOSTRING* flgName;
53 PIOINT nbFlg;
54 PIOSTRING* toiType;
55 PIOSTRING* toiName;
56 PIOLONG* beginIndex;
57 PIOLONG* endIndex;
58 PIOINT nbTOI;
59 PIOSTRING ROIGroup;
60
61 fits_lock();
62 PIOInfoTOI(&flgName,
63 &nbFlg,
64 &toiType,
65 &toiName,
66 &beginIndex,
67 &endIndex,
68 &nbTOI,
69 ROIGroup,
70 pioGroup);
71
72 // On recupere un tableau de beginIndex, il faut retrouver celui qui nous concerne
73 for (int i=0; i<nbTOI; i++) {
74 cout << toiName[i] << endl;
75 if (object == toiName[i]) {
76 snBegin = beginIndex[i];
77 snEnd = endIndex[i];
78 cout << snBegin << " " << snEnd << endl;
79 break;
80 }
81 }
82
83 PIOFreeInfoTOI(flgName,
84 toiType,
85 toiName,
86 beginIndex,
87 endIndex);
88 fits_unlock();
89}
90
91void PIOTOIReader::run() {
92 cout << "PIOTOIReader run " << group << "[" << object << "] "
93 << snBegin << " " << snEnd << endl;
94
95 for (long snb = snBegin; snb <= snEnd; snb += bufferSize) {
96 long sne = snb + bufferSize - 1;
97 if (sne > snEnd) sne=snEnd;
98 // TBD : check if PIODOUBLE != double;
99 char command[128];
100 sprintf(command, "Begin=%ld; End=%ld", snb, sne);
101 double* data = NULL;
102 uint_8* flags = NULL;
103 PIOBYTE* pioflags = NULL;
104 fits_lock();
105 char objname[128];
106 strcpy(objname, object.c_str());
107 PIOLONG n = PIOReadTOI((void**) &data,
108 objname,
109 "PIODOUBLE",
110 command,
111 pioGroup);
112 if ( n<0) {
113 cout << " PIOReadTOI " << command << ": " << n << endl;
114 abort();
115 }
116 if (flagdef != "") {
117 char flagname[128];
118 strcpy(flagname, flagdef.c_str());
119 PIOLONG nf = PIOReadFLGObjectMask(&pioflags,
120 flagname,
121 command,
122 pioGroup);
123 if (nf != n) {
124 cerr << "*** PIO Error, inconsistent read, data " << n << " flags "
125 << nf << endl;
126 abort();
127 }
128 flags = new uint_8[nf];
129 for (int i=0; i<nf; i++) flags[i] = (uint_8)pioflags[i];
130 PIODeleteFLG(pioflags, pioGroup);
131 }
132 fits_unlock();
133
134
135 if (flags != NULL) {
136 putData(0, snb, sne-snb+1, data, flags);
137 } else {
138 putData(0, snb, sne-snb+1, data);
139 }
140
141 fits_lock();
142 PIODeleteTOI(data, pioGroup);
143 // if (flags != NULL) PIODeleteFLG(flags, pioGroup); // PB !
144 if (flags != NULL) delete[] flags;
145 fits_unlock();
146 }
147 PIOCloseTOI(pioGroup);
148}
Note: See TracBrowser for help on using the repository browser.