Debian Codegraph @

libsrc/st/scp.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2009 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /*+++++++++++++++++++++++++ SC interface module SCP +++++++++++++++++++++++
29 .LANGUAGE C
30 .IDENTIFICATION Module SCP
31 .AUTHOR K. Banse ESO - Garching
32 .KEYWORDS standard interfaces, data frames
33 .ENVIRONMENT VMS and UNIX
34 .COMMENTS holds SCPGET, SCPPUT
35 .VERSION [1.00] 950622: creation
36
37 090403 last modif
38 -----------------------------------------------------------------------------*/
39
40 #include <fileexts.h> /* includes <midas_def.h> */
41
42 /*
43
44 */
45
46 int SCPGET(imno,plandir,planno,bufadr)
47
48 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
49 .PURPOSE
50 get a plane along a major axis of a cube
51 .ALGORITHM
52 .RETURNS
53 return status ( ERR_NORMAL (=0) means o.k. )
54 .REMARKS
55 --------------------------------------------------------------------------*/
56
57 int imno; /* IN: file no. of data cube */
58 int plandir; /* IN: direction of plane (x, y or z) */
59 int planno; /* IN: no. of plane, starting with 1 */
60 char *bufadr; /* IN: address of data buffer */
61
62
63 {
64 int unit, nullo, status;
65 int iav, xyplansiz, linsiz, felem, mm, first;
66 register int nr, nrr;
67
68 char *inpntr;
69
70 struct FCT_STRUCT *fctpntr;
71
72 static int old_imno = -1;
73 static int naxis, npi[3];
74
75
76 /* get descriptors NAXIS + NPIX */
77
78 if (imno != old_imno)
79 {
80 naxis = npi[0] = npi[1] = npi[2] = 0;
81
82 (void) SCDRDI(imno,"NAXIS",1,1,&iav,&naxis,&unit,&nullo);
83 if (naxis == 0) MID_E2(12,imno,"NAXIS",ERR_INPINV,1);
84
85 if (naxis != 3)
86 {
87 if ((naxis == 2) && (plandir == X_Y_PLANE) && (planno == 1))
88 npi[2] = 1;
89 else
90 MID_E2(12,imno,"NAXIS",ERR_INPINV,1);
91 }
92
93 (void) SCDRDI(imno,"NPIX",1,naxis,&iav,npi,&unit,&nullo);
94 if (npi[0] == 0) MID_E2(12,imno,"NPIX",ERR_INPINV,1);
95
96 old_imno = imno;
97 }
98
99 status = ERR_NORMAL;
100 if (plandir == X_Y_PLANE)
101 mm = 2;
102 else if (plandir == X_Z_PLANE)
103 mm = 1;
104 else if (plandir == Z_Y_PLANE)
105 mm = 0;
106 else
107 {
108 MID_E2(12,imno,"plandir ",ERR_INPINV,1);
109 return ERR_INPINV;
110 }
111
112 if ( (planno > npi[mm]) || (planno < 1) )
113 MID_E2(12,imno,"planno ",ERR_INPINV,1);
114
115
116 xyplansiz = npi[0] * npi[1];
117 fctpntr = FCT.ENTRIES + imno;
118
119 switch (plandir)
120 {
121 case X_Y_PLANE: /* get x-y plane of data cube */
122 first = (planno-1)*xyplansiz + 1;
123
124 status = SCFGET(imno,first,xyplansiz,&iav,bufadr);
125 break;
126
127 case X_Z_PLANE: /* get x-z plane of data cube */
128 linsiz = npi[0];
129 first = (planno-1)*npi[0] + 1;
130 inpntr = bufadr;
131
132 for (nr=0; nr<npi[2]; nr++)
133 {
134 status = SCFGET(imno,first,linsiz,&iav,inpntr);
135 inpntr += linsiz*fctpntr->NOBYTE;
136 first += xyplansiz;
137 }
138 break;
139
140 case Z_Y_PLANE: /* get z-y plane of data cube */
141 felem = planno;
142 inpntr = bufadr;
143
144 if (fctpntr->FILTYP > 0)
145 { /* FITS file */
146 for (nr=0; nr<npi[1]; nr++)
147 {
148 first = felem;
149 for (nrr=0; nrr<npi[2]; nrr++)
150 {
151 status = SCFGET(imno,first,1,&iav,inpntr);
152 inpntr += fctpntr->NOBYTE;
153 first += xyplansiz;
154 }
155 felem += npi[0];
156 }
157 }
158
159 else
160 {
161 if (fctpntr->DATTYP != fctpntr->FORMAT)
162 {
163 int nobytes;
164 char dummy[24], *oldpntr;
165
166 oldpntr = dummy;
167 nobytes = get_byte(fctpntr->DATTYP);
168
169 for (nr=0; nr<npi[1]; nr++)
170 {
171 first = felem;
172 for (nrr=0; nrr<npi[2]; nrr++)
173 {
174 status = rddisk(imno,first,1,&iav,oldpntr);
175 conv_pix(inpntr,oldpntr,fctpntr->DATTYP,fctpntr->FORMAT,1);
176 inpntr += nobytes;
177 first += xyplansiz;
178 }
179 felem += npi[0];
180 }
181 }
182 else
183 {
184 for (nr=0; nr<npi[1]; nr++)
185 {
186 first = felem;
187 for (nrr=0; nrr<npi[2]; nrr++)
188 {
189 status = rddisk(imno,first,1,&iav,inpntr);
190 inpntr += fctpntr->NOBYTE;
191 first += xyplansiz;
192 }
193 felem += npi[0];
194 }
195 }
196 }
197 }
198
199 return status;
200 }
201 /*
202
203 */
204
205 int SCPPUT(imno,plandir,planno,bufadr)
206
207 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
208 .PURPOSE
209 write a plane along a major axis of a cube
210 .ALGORITHM
211 .RETURNS
212 return status ( ERR_NORMAL (=0) means o.k. )
213 .REMARKS
214 --------------------------------------------------------------------------*/
215
216 int imno; /* IN: file no. of data cube */
217 int plandir; /* IN: direction of plane (x, y or z) */
218 int planno; /* IN: no. of plane, starting with 1 */
219 char *bufadr; /* IN: address of data buffer */
220
221 {
222 int unit, nullo, status;
223 int iav, xyplansiz, linsiz, felem, mm, first;
224 register int nr, nrr;
225
226 char *inpntr;
227
228 struct FCT_STRUCT *fctpntr;
229
230 static int old_imno = -1;
231 static int naxis, npi[3];
232
233
234
235 /* get descriptors NAXIS + NPIX */
236
237 status = ERR_NORMAL;
238 if (imno != old_imno)
239 {
240 naxis = npi[0] = npi[1] = npi[2] = 0;
241
242 (void) SCDRDI(imno,"NAXIS",1,1,&iav,&naxis,&unit,&nullo);
243 if (naxis == 0) MID_E2(13,imno,"NAXIS",ERR_INPINV,1);
244
245 if (naxis != 3)
246 {
247 if ((naxis == 2) && (plandir == X_Y_PLANE) && (planno == 1))
248 npi[2] = 1;
249 else
250 MID_E2(12,imno,"NAXIS",ERR_INPINV,1);
251 }
252
253 (void) SCDRDI(imno,"NPIX",1,naxis,&iav,npi,&unit,&nullo);
254 if (npi[0] == 0) MID_E2(13,imno,"NPIX",ERR_INPINV,1);
255
256 old_imno = imno;
257 }
258
259 if (plandir == X_Y_PLANE)
260 mm = 2;
261 else if (plandir == X_Z_PLANE)
262 mm = 1;
263 else if (plandir == Z_Y_PLANE)
264 mm = 0;
265 else
266 {
267 MID_E2(13,imno,"plandir ",ERR_INPINV,1);
268 return ERR_INPINV;
269 }
270
271 if ( (planno > npi[mm]) || (planno < 1) )
272 MID_E2(13,imno,"planno ",ERR_INPINV,1);
273
274
275 xyplansiz = npi[0] * npi[1];
276 fctpntr = FCT.ENTRIES + imno;
277
278 switch (plandir)
279 {
280 case X_Y_PLANE: /* put x-y plane of data cube */
281 first = (planno-1)*xyplansiz + 1;
282 status = SCFPUT(imno,first,xyplansiz,bufadr);
283 break;
284
285 case X_Z_PLANE: /* put x-z plane of data cube */
286 linsiz = npi[0];
287 first = (planno-1)*npi[0] + 1;
288 inpntr = bufadr;
289
290 for (nr=0; nr<npi[2]; nr++)
291 {
292 status = SCFPUT(imno,first,linsiz,inpntr);
293 inpntr += linsiz*fctpntr->NOBYTE;
294 first += xyplansiz;
295 }
296 break;
297
298 case Z_Y_PLANE: /* put z-y plane of data cube */
299 felem = planno;
300 inpntr = bufadr;
301
302 if (fctpntr->FILTYP > 0)
303 { /* FITS file */
304 for (nr=0; nr<npi[1]; nr++)
305 {
306 first = felem;
307 for (nrr=0; nrr<npi[2]; nrr++)
308 {
309 status = SCFPUT(imno,first,1,inpntr);
310 inpntr += fctpntr->NOBYTE;
311 first += xyplansiz;
312 }
313 felem += npi[0];
314 }
315 }
316
317 else
318 {
319 if (fctpntr->DATTYP != fctpntr->FORMAT)
320 {
321 int nobytes;
322 char dummy[24], *newpntr;
323
324 newpntr = dummy;
325 nobytes = get_byte(fctpntr->DATTYP);
326
327 for (nr=0; nr<npi[1]; nr++)
328 {
329 first = felem;
330 for (nrr=0; nrr<npi[2]; nrr++)
331 {
332 conv_pix(newpntr,inpntr,fctpntr->FORMAT,fctpntr->DATTYP,1);
333 status = wrdisk(imno,first,1,newpntr);
334 inpntr += nobytes;
335 first += xyplansiz;
336 }
337 felem += npi[0];
338 }
339 }
340 else
341 {
342 for (nr=0; nr<npi[1]; nr++)
343 {
344 first = felem;
345 for (nrr=0; nrr<npi[2]; nrr++)
346 {
347 status = wrdisk(imno,first,1,inpntr);
348 inpntr += fctpntr->NOBYTE;
349 first += xyplansiz;
350 }
351 felem += npi[0];
352 }
353 }
354 }
355 }
356
357 return status;
358 }