~ubuntu-branches/debian/stretch/cfitsio/stretch

« back to all changes in this revision

Viewing changes to getcol.c

  • Committer: Bazaar Package Importer
  • Author(s): Gopal Narayanan
  • Date: 2002-02-26 11:27:29 UTC
  • Revision ID: james.westby@ubuntu.com-20020226112729-3q2o993rhh81ipp4
Tags: upstream-2.401
ImportĀ upstreamĀ versionĀ 2.401

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*  This file, getcol.c, contains routines that read data elements from    */
 
3
/*  a FITS image or table.  There are generic datatype routines.           */
 
4
 
 
5
/*  The FITSIO software was written by William Pence at the High Energy    */
 
6
/*  Astrophysic Science Archive Research Center (HEASARC) at the NASA      */
 
7
/*  Goddard Space Flight Center.                                           */
 
8
 
 
9
#include <stdlib.h>
 
10
#include "fitsio2.h"
 
11
/*--------------------------------------------------------------------------*/
 
12
int ffgpxv( fitsfile *fptr,   /* I - FITS file pointer                       */
 
13
            int  datatype,    /* I - datatype of the value                   */
 
14
            long *firstpix,   /* I - coord of first pixel to read (1s based) */
 
15
            long nelem,       /* I - number of values to read                */
 
16
            void *nulval,     /* I - value for undefined pixels              */
 
17
            void *array,      /* O - array of values that are returned       */
 
18
            int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
19
            int  *status)     /* IO - error status                           */
 
20
/*
 
21
  Read an array of values from the primary array. The datatype of the
 
22
  input array is defined by the 2nd argument.  Data conversion
 
23
  and scaling will be performed if necessary (e.g, if the datatype of
 
24
  the FITS array is not the same as the array being read).
 
25
  Undefined elements will be set equal to NULVAL, unless NULVAL=0
 
26
  in which case no checking for undefined values will be performed.
 
27
  ANYNUL is returned with a value of .true. if any pixels are undefined.
 
28
*/
 
29
{
 
30
    int naxis, ii;
 
31
    long naxes[9];
 
32
    OFF_T dimsize = 1, firstelem;
 
33
 
 
34
    if (*status > 0 || nelem == 0)   /* inherit input status value if > 0 */
 
35
        return(*status);
 
36
 
 
37
    /* get the size of the image */
 
38
    ffgidm(fptr, &naxis, status);
 
39
    ffgisz(fptr, 9, naxes, status);
 
40
 
 
41
    /* calculate the position of the first element in the array */
 
42
    firstelem = 0;
 
43
    for (ii=0; ii < naxis; ii++)
 
44
    {
 
45
        firstelem += ((firstpix[ii] - 1) * dimsize);
 
46
        dimsize *= naxes[ii];
 
47
    }
 
48
    firstelem++;
 
49
 
 
50
    /*
 
51
      the primary array is represented as a binary table:
 
52
      each group of the primary array is a row in the table,
 
53
      where the first column contains the group parameters
 
54
      and the second column contains the image itself.
 
55
    */
 
56
 
 
57
    if (datatype == TBYTE)
 
58
    {
 
59
      if (nulval == 0)
 
60
        ffgpvb(fptr, 1, firstelem, nelem, 0,
 
61
               (unsigned char *) array, anynul, status);
 
62
      else
 
63
        ffgpvb(fptr, 1, firstelem, nelem, *(unsigned char *) nulval,
 
64
               (unsigned char *) array, anynul, status);
 
65
    }
 
66
    else if (datatype == TUSHORT)
 
67
    {
 
68
      if (nulval == 0)
 
69
        ffgpvui(fptr, 1, firstelem, nelem, 0,
 
70
               (unsigned short *) array, anynul, status);
 
71
      else
 
72
        ffgpvui(fptr, 1, firstelem, nelem, *(unsigned short *) nulval,
 
73
               (unsigned short *) array, anynul, status);
 
74
    }
 
75
    else if (datatype == TSHORT)
 
76
    {
 
77
      if (nulval == 0)
 
78
        ffgpvi(fptr, 1, firstelem, nelem, 0,
 
79
               (short *) array, anynul, status);
 
80
      else
 
81
        ffgpvi(fptr, 1, firstelem, nelem, *(short *) nulval,
 
82
               (short *) array, anynul, status);
 
83
    }
 
84
    else if (datatype == TUINT)
 
85
    {
 
86
      if (nulval == 0)
 
87
        ffgpvuk(fptr, 1, firstelem, nelem, 0,
 
88
               (unsigned int *) array, anynul, status);
 
89
      else
 
90
        ffgpvuk(fptr, 1, firstelem, nelem, *(unsigned int *) nulval,
 
91
               (unsigned int *) array, anynul, status);
 
92
    }
 
93
    else if (datatype == TINT)
 
94
    {
 
95
      if (nulval == 0)
 
96
        ffgpvk(fptr, 1, firstelem, nelem, 0,
 
97
               (int *) array, anynul, status);
 
98
      else
 
99
        ffgpvk(fptr, 1, firstelem, nelem, *(int *) nulval,
 
100
               (int *) array, anynul, status);
 
101
    }
 
102
    else if (datatype == TULONG)
 
103
    {
 
104
      if (nulval == 0)
 
105
        ffgpvuj(fptr, 1, firstelem, nelem, 0,
 
106
               (unsigned long *) array, anynul, status);
 
107
      else
 
108
        ffgpvuj(fptr, 1, firstelem, nelem, *(unsigned long *) nulval,
 
109
               (unsigned long *) array, anynul, status);
 
110
    }
 
111
    else if (datatype == TLONG)
 
112
    {
 
113
      if (nulval == 0)
 
114
        ffgpvj(fptr, 1, firstelem, nelem, 0,
 
115
               (long *) array, anynul, status);
 
116
      else
 
117
        ffgpvj(fptr, 1, firstelem, nelem, *(long *) nulval,
 
118
               (long *) array, anynul, status);
 
119
    }
 
120
    else if (datatype == TLONGLONG)
 
121
    {
 
122
      if (nulval == 0)
 
123
        ffgpvjj(fptr, 1, firstelem, nelem, 0,
 
124
               (LONGLONG *) array, anynul, status);
 
125
      else
 
126
        ffgpvjj(fptr, 1, firstelem, nelem, *(LONGLONG *) nulval,
 
127
               (LONGLONG *) array, anynul, status);
 
128
    }
 
129
    else if (datatype == TFLOAT)
 
130
    {
 
131
      if (nulval == 0)
 
132
        ffgpve(fptr, 1, firstelem, nelem, 0,
 
133
               (float *) array, anynul, status);
 
134
      else
 
135
        ffgpve(fptr, 1, firstelem, nelem, *(float *) nulval,
 
136
               (float *) array, anynul, status);
 
137
    }
 
138
    else if (datatype == TDOUBLE)
 
139
    {
 
140
      if (nulval == 0)
 
141
        ffgpvd(fptr, 1, firstelem, nelem, 0,
 
142
               (double *) array, anynul, status);
 
143
      else
 
144
      {
 
145
        ffgpvd(fptr, 1, firstelem, nelem, *(double *) nulval,
 
146
               (double *) array, anynul, status);
 
147
      }
 
148
    }
 
149
    else
 
150
      *status = BAD_DATATYPE;
 
151
 
 
152
    return(*status);
 
153
}
 
154
/*--------------------------------------------------------------------------*/
 
155
int ffgpxf( fitsfile *fptr,   /* I - FITS file pointer                       */
 
156
            int  datatype,    /* I - datatype of the value                   */
 
157
            long *firstpix,   /* I - coord of first pixel to read (1s based) */
 
158
            long nelem,       /* I - number of values to read                */
 
159
            void *array,      /* O - array of values that are returned       */
 
160
            char *nullarray,  /* O - returned array of null value flags      */
 
161
            int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
162
            int  *status)     /* IO - error status                           */
 
163
/*
 
164
  Read an array of values from the primary array. The datatype of the
 
165
  input array is defined by the 2nd argument.  Data conversion
 
166
  and scaling will be performed if necessary (e.g, if the datatype of
 
167
  the FITS array is not the same as the array being read).
 
168
  The nullarray values will = 1 if the corresponding array value is null.
 
169
  ANYNUL is returned with a value of .true. if any pixels are undefined.
 
170
*/
 
171
{
 
172
    int naxis, ii;
 
173
    long naxes[9];
 
174
    OFF_T dimsize = 1, firstelem;
 
175
 
 
176
    if (*status > 0 || nelem == 0)   /* inherit input status value if > 0 */
 
177
        return(*status);
 
178
 
 
179
    /* get the size of the image */
 
180
    ffgidm(fptr, &naxis, status);
 
181
    ffgisz(fptr, 9, naxes, status);
 
182
 
 
183
    /* calculate the position of the first element in the array */
 
184
    firstelem = 0;
 
185
    for (ii=0; ii < naxis; ii++)
 
186
    {
 
187
        firstelem += ((firstpix[ii] - 1) * dimsize);
 
188
        dimsize *= naxes[ii];
 
189
    }
 
190
    firstelem++;
 
191
 
 
192
    /*
 
193
      the primary array is represented as a binary table:
 
194
      each group of the primary array is a row in the table,
 
195
      where the first column contains the group parameters
 
196
      and the second column contains the image itself.
 
197
    */
 
198
 
 
199
    if (datatype == TBYTE)
 
200
    {
 
201
        ffgpfb(fptr, 1, firstelem, nelem, 
 
202
               (unsigned char *) array, nullarray, anynul, status);
 
203
    }
 
204
    else if (datatype == TUSHORT)
 
205
    {
 
206
        ffgpfui(fptr, 1, firstelem, nelem, 
 
207
               (unsigned short *) array, nullarray, anynul, status);
 
208
    }
 
209
    else if (datatype == TSHORT)
 
210
    {
 
211
        ffgpfi(fptr, 1, firstelem, nelem, 
 
212
               (short *) array, nullarray, anynul, status);
 
213
    }
 
214
    else if (datatype == TUINT)
 
215
    {
 
216
        ffgpfuk(fptr, 1, firstelem, nelem, 
 
217
               (unsigned int *) array, nullarray, anynul, status);
 
218
    }
 
219
    else if (datatype == TINT)
 
220
    {
 
221
        ffgpfk(fptr, 1, firstelem, nelem, 
 
222
               (int *) array, nullarray, anynul, status);
 
223
    }
 
224
    else if (datatype == TULONG)
 
225
    {
 
226
        ffgpfuj(fptr, 1, firstelem, nelem, 
 
227
               (unsigned long *) array, nullarray, anynul, status);
 
228
    }
 
229
    else if (datatype == TLONG)
 
230
    {
 
231
        ffgpfj(fptr, 1, firstelem, nelem,
 
232
               (long *) array, nullarray, anynul, status);
 
233
    }
 
234
    else if (datatype == TLONGLONG)
 
235
    {
 
236
        ffgpfjj(fptr, 1, firstelem, nelem,
 
237
               (LONGLONG *) array, nullarray, anynul, status);
 
238
    }
 
239
    else if (datatype == TFLOAT)
 
240
    {
 
241
        ffgpfe(fptr, 1, firstelem, nelem, 
 
242
               (float *) array, nullarray, anynul, status);
 
243
    }
 
244
    else if (datatype == TDOUBLE)
 
245
    {
 
246
        ffgpfd(fptr, 1, firstelem, nelem,
 
247
               (double *) array, nullarray, anynul, status);
 
248
    }
 
249
    else
 
250
      *status = BAD_DATATYPE;
 
251
 
 
252
    return(*status);
 
253
}
 
254
/*--------------------------------------------------------------------------*/
 
255
int ffgsv(  fitsfile *fptr,   /* I - FITS file pointer                       */
 
256
            int  datatype,    /* I - datatype of the value                   */
 
257
            long *blc,        /* I - 'bottom left corner' of the subsection  */
 
258
            long *trc ,       /* I - 'top right corner' of the subsection    */
 
259
            long *inc,        /* I - increment to be applied in each dim.    */
 
260
            void *nulval,     /* I - value for undefined pixels              */
 
261
            void *array,      /* O - array of values that are returned       */
 
262
            int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
263
            int  *status)     /* IO - error status                           */
 
264
/*
 
265
  Read an section of values from the primary array. The datatype of the
 
266
  input array is defined by the 2nd argument.  Data conversion
 
267
  and scaling will be performed if necessary (e.g, if the datatype of
 
268
  the FITS array is not the same as the array being read).
 
269
  Undefined elements will be set equal to NULVAL, unless NULVAL=0
 
270
  in which case no checking for undefined values will be performed.
 
271
  ANYNUL is returned with a value of .true. if any pixels are undefined.
 
272
*/
 
273
{
 
274
    int naxis;
 
275
    long naxes[9];
 
276
 
 
277
    if (*status > 0)   /* inherit input status value if > 0 */
 
278
        return(*status);
 
279
 
 
280
    /* get the size of the image */
 
281
    ffgidm(fptr, &naxis, status);
 
282
    ffgisz(fptr, 9, naxes, status);
 
283
 
 
284
    if (datatype == TBYTE)
 
285
    {
 
286
      if (nulval == 0)
 
287
        ffgsvb(fptr, 1, naxis, naxes, blc, trc, inc, 0,
 
288
               (unsigned char *) array, anynul, status);
 
289
      else
 
290
        ffgsvb(fptr, 1, naxis, naxes, blc, trc, inc, *(unsigned char *) nulval,
 
291
               (unsigned char *) array, anynul, status);
 
292
    }
 
293
    else if (datatype == TUSHORT)
 
294
    {
 
295
      if (nulval == 0)
 
296
        ffgsvui(fptr, 1, naxis, naxes, blc, trc, inc, 0,
 
297
               (unsigned short *) array, anynul, status);
 
298
      else
 
299
        ffgsvui(fptr, 1, naxis, naxes,blc, trc, inc, *(unsigned short *) nulval,
 
300
               (unsigned short *) array, anynul, status);
 
301
    }
 
302
    else if (datatype == TSHORT)
 
303
    {
 
304
      if (nulval == 0)
 
305
        ffgsvi(fptr, 1, naxis, naxes, blc, trc, inc, 0,
 
306
               (short *) array, anynul, status);
 
307
      else
 
308
        ffgsvi(fptr, 1, naxis, naxes, blc, trc, inc, *(short *) nulval,
 
309
               (short *) array, anynul, status);
 
310
    }
 
311
    else if (datatype == TUINT)
 
312
    {
 
313
      if (nulval == 0)
 
314
        ffgsvuk(fptr, 1, naxis, naxes, blc, trc, inc, 0,
 
315
               (unsigned int *) array, anynul, status);
 
316
      else
 
317
        ffgsvuk(fptr, 1, naxis, naxes, blc, trc, inc, *(unsigned int *) nulval,
 
318
               (unsigned int *) array, anynul, status);
 
319
    }
 
320
    else if (datatype == TINT)
 
321
    {
 
322
      if (nulval == 0)
 
323
        ffgsvk(fptr, 1, naxis, naxes, blc, trc, inc, 0,
 
324
               (int *) array, anynul, status);
 
325
      else
 
326
        ffgsvk(fptr, 1, naxis, naxes, blc, trc, inc, *(int *) nulval,
 
327
               (int *) array, anynul, status);
 
328
    }
 
329
    else if (datatype == TULONG)
 
330
    {
 
331
      if (nulval == 0)
 
332
        ffgsvuj(fptr, 1, naxis, naxes, blc, trc, inc, 0,
 
333
               (unsigned long *) array, anynul, status);
 
334
      else
 
335
        ffgsvuj(fptr, 1, naxis, naxes, blc, trc, inc, *(unsigned long *) nulval,
 
336
               (unsigned long *) array, anynul, status);
 
337
    }
 
338
    else if (datatype == TLONG)
 
339
    {
 
340
      if (nulval == 0)
 
341
        ffgsvj(fptr, 1, naxis, naxes, blc, trc, inc, 0,
 
342
               (long *) array, anynul, status);
 
343
      else
 
344
        ffgsvj(fptr, 1, naxis, naxes, blc, trc, inc, *(long *) nulval,
 
345
               (long *) array, anynul, status);
 
346
    }
 
347
    else if (datatype == TLONGLONG)
 
348
    {
 
349
      if (nulval == 0)
 
350
        ffgsvjj(fptr, 1, naxis, naxes, blc, trc, inc, 0,
 
351
               (LONGLONG *) array, anynul, status);
 
352
      else
 
353
        ffgsvjj(fptr, 1, naxis, naxes, blc, trc, inc, *(LONGLONG *) nulval,
 
354
               (LONGLONG *) array, anynul, status);
 
355
    }
 
356
    else if (datatype == TFLOAT)
 
357
    {
 
358
      if (nulval == 0)
 
359
        ffgsve(fptr, 1, naxis, naxes, blc, trc, inc, 0,
 
360
               (float *) array, anynul, status);
 
361
      else
 
362
        ffgsve(fptr, 1, naxis, naxes, blc, trc, inc, *(float *) nulval,
 
363
               (float *) array, anynul, status);
 
364
    }
 
365
    else if (datatype == TDOUBLE)
 
366
    {
 
367
      if (nulval == 0)
 
368
        ffgsvd(fptr, 1, naxis, naxes, blc, trc, inc, 0,
 
369
               (double *) array, anynul, status);
 
370
      else
 
371
        ffgsvd(fptr, 1, naxis, naxes, blc, trc, inc, *(double *) nulval,
 
372
               (double *) array, anynul, status);
 
373
    }
 
374
    else
 
375
      *status = BAD_DATATYPE;
 
376
 
 
377
    return(*status);
 
378
}
 
379
/*--------------------------------------------------------------------------*/
 
380
int ffgpv(  fitsfile *fptr,   /* I - FITS file pointer                       */
 
381
            int  datatype,    /* I - datatype of the value                   */
 
382
            long firstelem,   /* I - first vector element to read (1 = 1st)  */
 
383
            long nelem,       /* I - number of values to read                */
 
384
            void *nulval,     /* I - value for undefined pixels              */
 
385
            void *array,      /* O - array of values that are returned       */
 
386
            int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
387
            int  *status)     /* IO - error status                           */
 
388
/*
 
389
  Read an array of values from the primary array. The datatype of the
 
390
  input array is defined by the 2nd argument.  Data conversion
 
391
  and scaling will be performed if necessary (e.g, if the datatype of
 
392
  the FITS array is not the same as the array being read).
 
393
  Undefined elements will be set equal to NULVAL, unless NULVAL=0
 
394
  in which case no checking for undefined values will be performed.
 
395
  ANYNUL is returned with a value of .true. if any pixels are undefined.
 
396
*/
 
397
{
 
398
 
 
399
    if (*status > 0 || nelem == 0)   /* inherit input status value if > 0 */
 
400
        return(*status);
 
401
 
 
402
    /*
 
403
      the primary array is represented as a binary table:
 
404
      each group of the primary array is a row in the table,
 
405
      where the first column contains the group parameters
 
406
      and the second column contains the image itself.
 
407
    */
 
408
 
 
409
    if (datatype == TBYTE)
 
410
    {
 
411
      if (nulval == 0)
 
412
        ffgpvb(fptr, 1, firstelem, nelem, 0,
 
413
               (unsigned char *) array, anynul, status);
 
414
      else
 
415
        ffgpvb(fptr, 1, firstelem, nelem, *(unsigned char *) nulval,
 
416
               (unsigned char *) array, anynul, status);
 
417
    }
 
418
    else if (datatype == TUSHORT)
 
419
    {
 
420
      if (nulval == 0)
 
421
        ffgpvui(fptr, 1, firstelem, nelem, 0,
 
422
               (unsigned short *) array, anynul, status);
 
423
      else
 
424
        ffgpvui(fptr, 1, firstelem, nelem, *(unsigned short *) nulval,
 
425
               (unsigned short *) array, anynul, status);
 
426
    }
 
427
    else if (datatype == TSHORT)
 
428
    {
 
429
      if (nulval == 0)
 
430
        ffgpvi(fptr, 1, firstelem, nelem, 0,
 
431
               (short *) array, anynul, status);
 
432
      else
 
433
        ffgpvi(fptr, 1, firstelem, nelem, *(short *) nulval,
 
434
               (short *) array, anynul, status);
 
435
    }
 
436
    else if (datatype == TUINT)
 
437
    {
 
438
      if (nulval == 0)
 
439
        ffgpvuk(fptr, 1, firstelem, nelem, 0,
 
440
               (unsigned int *) array, anynul, status);
 
441
      else
 
442
        ffgpvuk(fptr, 1, firstelem, nelem, *(unsigned int *) nulval,
 
443
               (unsigned int *) array, anynul, status);
 
444
    }
 
445
    else if (datatype == TINT)
 
446
    {
 
447
      if (nulval == 0)
 
448
        ffgpvk(fptr, 1, firstelem, nelem, 0,
 
449
               (int *) array, anynul, status);
 
450
      else
 
451
        ffgpvk(fptr, 1, firstelem, nelem, *(int *) nulval,
 
452
               (int *) array, anynul, status);
 
453
    }
 
454
    else if (datatype == TULONG)
 
455
    {
 
456
      if (nulval == 0)
 
457
        ffgpvuj(fptr, 1, firstelem, nelem, 0,
 
458
               (unsigned long *) array, anynul, status);
 
459
      else
 
460
        ffgpvuj(fptr, 1, firstelem, nelem, *(unsigned long *) nulval,
 
461
               (unsigned long *) array, anynul, status);
 
462
    }
 
463
    else if (datatype == TLONG)
 
464
    {
 
465
      if (nulval == 0)
 
466
        ffgpvj(fptr, 1, firstelem, nelem, 0,
 
467
               (long *) array, anynul, status);
 
468
      else
 
469
        ffgpvj(fptr, 1, firstelem, nelem, *(long *) nulval,
 
470
               (long *) array, anynul, status);
 
471
    }
 
472
    else if (datatype == TLONGLONG)
 
473
    {
 
474
      if (nulval == 0)
 
475
        ffgpvjj(fptr, 1, firstelem, nelem, 0,
 
476
               (LONGLONG *) array, anynul, status);
 
477
      else
 
478
        ffgpvjj(fptr, 1, firstelem, nelem, *(LONGLONG *) nulval,
 
479
               (LONGLONG *) array, anynul, status);
 
480
    }
 
481
    else if (datatype == TFLOAT)
 
482
    {
 
483
      if (nulval == 0)
 
484
        ffgpve(fptr, 1, firstelem, nelem, 0,
 
485
               (float *) array, anynul, status);
 
486
      else
 
487
        ffgpve(fptr, 1, firstelem, nelem, *(float *) nulval,
 
488
               (float *) array, anynul, status);
 
489
    }
 
490
    else if (datatype == TDOUBLE)
 
491
    {
 
492
      if (nulval == 0)
 
493
        ffgpvd(fptr, 1, firstelem, nelem, 0,
 
494
               (double *) array, anynul, status);
 
495
      else
 
496
      {
 
497
        ffgpvd(fptr, 1, firstelem, nelem, *(double *) nulval,
 
498
               (double *) array, anynul, status);
 
499
      }
 
500
    }
 
501
    else
 
502
      *status = BAD_DATATYPE;
 
503
 
 
504
    return(*status);
 
505
}
 
506
/*--------------------------------------------------------------------------*/
 
507
int ffgpf(  fitsfile *fptr,   /* I - FITS file pointer                       */
 
508
            int  datatype,    /* I - datatype of the value                   */
 
509
            long firstelem,   /* I - first vector element to read (1 = 1st)  */
 
510
            long nelem,       /* I - number of values to read                */
 
511
            void *array,      /* O - array of values that are returned       */
 
512
            char *nullarray,  /* O - array of null value flags               */
 
513
            int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
514
            int  *status)     /* IO - error status                           */
 
515
/*
 
516
  Read an array of values from the primary array. The datatype of the
 
517
  input array is defined by the 2nd argument.  Data conversion
 
518
  and scaling will be performed if necessary (e.g, if the datatype of
 
519
  the FITS array is not the same as the array being read).
 
520
  The nullarray values will = 1 if the corresponding array value is null.
 
521
  ANYNUL is returned with a value of .true. if any pixels are undefined.
 
522
*/
 
523
{
 
524
 
 
525
    if (*status > 0 || nelem == 0)   /* inherit input status value if > 0 */
 
526
        return(*status);
 
527
 
 
528
    /*
 
529
      the primary array is represented as a binary table:
 
530
      each group of the primary array is a row in the table,
 
531
      where the first column contains the group parameters
 
532
      and the second column contains the image itself.
 
533
    */
 
534
 
 
535
    if (datatype == TBYTE)
 
536
    {
 
537
        ffgpfb(fptr, 1, firstelem, nelem, 
 
538
               (unsigned char *) array, nullarray, anynul, status);
 
539
    }
 
540
    else if (datatype == TUSHORT)
 
541
    {
 
542
        ffgpfui(fptr, 1, firstelem, nelem, 
 
543
               (unsigned short *) array, nullarray, anynul, status);
 
544
    }
 
545
    else if (datatype == TSHORT)
 
546
    {
 
547
        ffgpfi(fptr, 1, firstelem, nelem, 
 
548
               (short *) array, nullarray, anynul, status);
 
549
    }
 
550
    else if (datatype == TUINT)
 
551
    {
 
552
        ffgpfuk(fptr, 1, firstelem, nelem, 
 
553
               (unsigned int *) array, nullarray, anynul, status);
 
554
    }
 
555
    else if (datatype == TINT)
 
556
    {
 
557
        ffgpfk(fptr, 1, firstelem, nelem, 
 
558
               (int *) array, nullarray, anynul, status);
 
559
    }
 
560
    else if (datatype == TULONG)
 
561
    {
 
562
        ffgpfuj(fptr, 1, firstelem, nelem, 
 
563
               (unsigned long *) array, nullarray, anynul, status);
 
564
    }
 
565
    else if (datatype == TLONG)
 
566
    {
 
567
        ffgpfj(fptr, 1, firstelem, nelem,
 
568
               (long *) array, nullarray, anynul, status);
 
569
    }
 
570
    else if (datatype == TLONGLONG)
 
571
    {
 
572
        ffgpfjj(fptr, 1, firstelem, nelem,
 
573
               (LONGLONG *) array, nullarray, anynul, status);
 
574
    }
 
575
    else if (datatype == TFLOAT)
 
576
    {
 
577
        ffgpfe(fptr, 1, firstelem, nelem, 
 
578
               (float *) array, nullarray, anynul, status);
 
579
    }
 
580
    else if (datatype == TDOUBLE)
 
581
    {
 
582
        ffgpfd(fptr, 1, firstelem, nelem,
 
583
               (double *) array, nullarray, anynul, status);
 
584
    }
 
585
    else
 
586
      *status = BAD_DATATYPE;
 
587
 
 
588
    return(*status);
 
589
}
 
590
/*--------------------------------------------------------------------------*/
 
591
int ffgcv(  fitsfile *fptr,   /* I - FITS file pointer                       */
 
592
            int  datatype,    /* I - datatype of the value                   */
 
593
            int  colnum,      /* I - number of column to write (1 = 1st col) */
 
594
            long  firstrow,   /* I - first row to write (1 = 1st row)        */
 
595
            long  firstelem,  /* I - first vector element to read (1 = 1st)  */
 
596
            long nelem,       /* I - number of values to read                */
 
597
            void *nulval,     /* I - value for undefined pixels              */
 
598
            void *array,      /* O - array of values that are returned       */
 
599
            int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
600
            int  *status)     /* IO - error status                           */
 
601
/*
 
602
  Read an array of values from a table column. The datatype of the
 
603
  input array is defined by the 2nd argument.  Data conversion
 
604
  and scaling will be performed if necessary (e.g, if the datatype of
 
605
  the FITS array is not the same as the array being read).
 
606
  Undefined elements will be set equal to NULVAL, unless NULVAL=0
 
607
  in which case no checking for undefined values will be performed.
 
608
  ANYNUL is returned with a value of true if any pixels are undefined.
 
609
*/
 
610
{
 
611
    char cdummy[2];
 
612
 
 
613
    if (*status > 0)           /* inherit input status value if > 0 */
 
614
        return(*status);
 
615
 
 
616
    if (datatype == TBIT)
 
617
    {
 
618
      ffgcx(fptr, colnum, firstrow, firstelem, nelem, (char *) array, status);
 
619
    }
 
620
    else if (datatype == TBYTE)
 
621
    {
 
622
      if (nulval == 0)
 
623
        ffgclb(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
 
624
              (unsigned char *) array, cdummy, anynul, status);
 
625
      else
 
626
       ffgclb(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(unsigned char *)
 
627
              nulval, (unsigned char *) array, cdummy, anynul, status);
 
628
    }
 
629
    else if (datatype == TUSHORT)
 
630
    {
 
631
      if (nulval == 0)
 
632
        ffgclui(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
 
633
               (unsigned short *) array, cdummy, anynul, status);
 
634
      else
 
635
        ffgclui(fptr, colnum, firstrow, firstelem, nelem, 1, 1,
 
636
               *(unsigned short *) nulval,
 
637
               (unsigned short *) array, cdummy, anynul, status);
 
638
    }
 
639
    else if (datatype == TSHORT)
 
640
    {
 
641
      if (nulval == 0)
 
642
        ffgcli(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
 
643
              (short *) array, cdummy, anynul, status);
 
644
      else
 
645
        ffgcli(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(short *)
 
646
              nulval, (short *) array, cdummy, anynul, status);
 
647
    }
 
648
    else if (datatype == TUINT)
 
649
    {
 
650
      if (nulval == 0)
 
651
        ffgcluk(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
 
652
              (unsigned int *) array, cdummy, anynul, status);
 
653
      else
 
654
        ffgcluk(fptr, colnum, firstrow, firstelem, nelem, 1, 1,
 
655
         *(unsigned int *) nulval, (unsigned int *) array, cdummy, anynul,
 
656
         status);
 
657
    }
 
658
    else if (datatype == TINT)
 
659
    {
 
660
      if (nulval == 0)
 
661
        ffgclk(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
 
662
              (int *) array, cdummy, anynul, status);
 
663
      else
 
664
        ffgclk(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(int *)
 
665
            nulval, (int *) array, cdummy, anynul, status);
 
666
    }
 
667
    else if (datatype == TULONG)
 
668
    {
 
669
      if (nulval == 0)
 
670
        ffgcluj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
 
671
               (unsigned long *) array, cdummy, anynul, status);
 
672
      else
 
673
        ffgcluj(fptr, colnum, firstrow, firstelem, nelem, 1, 1,
 
674
               *(unsigned long *) nulval, 
 
675
               (unsigned long *) array, cdummy, anynul, status);
 
676
    }
 
677
    else if (datatype == TLONG)
 
678
    {
 
679
      if (nulval == 0)
 
680
        ffgclj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
 
681
              (long *) array, cdummy, anynul, status);
 
682
      else
 
683
        ffgclj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(long *)
 
684
              nulval, (long *) array, cdummy, anynul, status);
 
685
    }
 
686
    else if (datatype == TLONGLONG)
 
687
    {
 
688
      if (nulval == 0)
 
689
        ffgcljj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0,
 
690
              (LONGLONG *) array, cdummy, anynul, status);
 
691
      else
 
692
        ffgcljj(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(LONGLONG *)
 
693
              nulval, (LONGLONG *) array, cdummy, anynul, status);
 
694
    }
 
695
    else if (datatype == TFLOAT)
 
696
    {
 
697
      if (nulval == 0)
 
698
        ffgcle(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0.,
 
699
              (float *) array, cdummy, anynul, status);
 
700
      else
 
701
      ffgcle(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(float *)
 
702
               nulval,(float *) array, cdummy, anynul, status);
 
703
    }
 
704
    else if (datatype == TDOUBLE)
 
705
    {
 
706
      if (nulval == 0)
 
707
        ffgcld(fptr, colnum, firstrow, firstelem, nelem, 1, 1, 0.,
 
708
              (double *) array, cdummy, anynul, status);
 
709
      else
 
710
        ffgcld(fptr, colnum, firstrow, firstelem, nelem, 1, 1, *(double *)
 
711
              nulval, (double *) array, cdummy, anynul, status);
 
712
    }
 
713
    else if (datatype == TCOMPLEX)
 
714
    {
 
715
      if (nulval == 0)
 
716
        ffgcle(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
 
717
           1, 1, 0., (float *) array, cdummy, anynul, status);
 
718
      else
 
719
        ffgcle(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
 
720
           1, 1, *(float *) nulval, (float *) array, cdummy, anynul, status);
 
721
    }
 
722
    else if (datatype == TDBLCOMPLEX)
 
723
    {
 
724
      if (nulval == 0)
 
725
        ffgcld(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2, 
 
726
         1, 1, 0., (double *) array, cdummy, anynul, status);
 
727
      else
 
728
        ffgcld(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2, 
 
729
         1, 1, *(double *) nulval, (double *) array, cdummy, anynul, status);
 
730
    }
 
731
 
 
732
    else if (datatype == TLOGICAL)
 
733
    {
 
734
      if (nulval == 0)
 
735
        ffgcll(fptr, colnum, firstrow, firstelem, nelem, 1, 0,
 
736
          (char *) array, cdummy, anynul, status);
 
737
      else
 
738
        ffgcll(fptr, colnum, firstrow, firstelem, nelem, 1, *(char *) nulval,
 
739
          (char *) array, cdummy, anynul, status);
 
740
    }
 
741
    else if (datatype == TSTRING)
 
742
    {
 
743
      if (nulval == 0)
 
744
      {
 
745
        cdummy[0] = '\0';
 
746
        ffgcls(fptr, colnum, firstrow, firstelem, nelem, 1, 
 
747
             cdummy, (char **) array, cdummy, anynul, status);
 
748
      }
 
749
      else
 
750
        ffgcls(fptr, colnum, firstrow, firstelem, nelem, 1, (char *)
 
751
             nulval, (char **) array, cdummy, anynul, status);
 
752
    }
 
753
    else
 
754
      *status = BAD_DATATYPE;
 
755
 
 
756
    return(*status);
 
757
}
 
758
/*--------------------------------------------------------------------------*/
 
759
int ffgcf(  fitsfile *fptr,   /* I - FITS file pointer                       */
 
760
            int  datatype,    /* I - datatype of the value                   */
 
761
            int  colnum,      /* I - number of column to write (1 = 1st col) */
 
762
            long  firstrow,   /* I - first row to write (1 = 1st row)        */
 
763
            long  firstelem,  /* I - first vector element to read (1 = 1st)  */
 
764
            long nelem,       /* I - number of values to read                */
 
765
            void *array,      /* O - array of values that are returned       */
 
766
            char *nullarray,  /* O - array of null value flags               */
 
767
            int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
768
            int  *status)     /* IO - error status                           */
 
769
/*
 
770
  Read an array of values from a table column. The datatype of the
 
771
  input array is defined by the 2nd argument.  Data conversion
 
772
  and scaling will be performed if necessary (e.g, if the datatype of
 
773
  the FITS array is not the same as the array being read).
 
774
  ANYNUL is returned with a value of true if any pixels are undefined.
 
775
*/
 
776
{
 
777
    void *nulval;         /* dummy argument */
 
778
    double dnulval = 0.;
 
779
 
 
780
    if (*status > 0)           /* inherit input status value if > 0 */
 
781
        return(*status);
 
782
 
 
783
    nulval = &dnulval;  /* set to a harmless value; this is never used */
 
784
 
 
785
    if (datatype == TBIT)
 
786
    {
 
787
      ffgcx(fptr, colnum, firstrow, firstelem, nelem, (char *) array, status);
 
788
    }
 
789
    else if (datatype == TBYTE)
 
790
    {
 
791
       ffgclb(fptr, colnum, firstrow, firstelem, nelem, 1, 2, *(unsigned char *)
 
792
              nulval, (unsigned char *) array, nullarray, anynul, status);
 
793
    }
 
794
    else if (datatype == TUSHORT)
 
795
    {
 
796
        ffgclui(fptr, colnum, firstrow, firstelem, nelem, 1, 2,
 
797
               *(unsigned short *) nulval,
 
798
               (unsigned short *) array, nullarray, anynul, status);
 
799
    }
 
800
    else if (datatype == TSHORT)
 
801
    {
 
802
        ffgcli(fptr, colnum, firstrow, firstelem, nelem, 1, 2, *(short *)
 
803
              nulval, (short *) array, nullarray, anynul, status);
 
804
    }
 
805
    else if (datatype == TUINT)
 
806
    {
 
807
        ffgcluk(fptr, colnum, firstrow, firstelem, nelem, 1, 2,
 
808
         *(unsigned int *) nulval, (unsigned int *) array, nullarray, anynul,
 
809
         status);
 
810
    }
 
811
    else if (datatype == TINT)
 
812
    {
 
813
        ffgclk(fptr, colnum, firstrow, firstelem, nelem, 1, 2, *(int *)
 
814
            nulval, (int *) array, nullarray, anynul, status);
 
815
    }
 
816
    else if (datatype == TULONG)
 
817
    {
 
818
        ffgcluj(fptr, colnum, firstrow, firstelem, nelem, 1, 2,
 
819
               *(unsigned long *) nulval, 
 
820
               (unsigned long *) array, nullarray, anynul, status);
 
821
    }
 
822
    else if (datatype == TLONG)
 
823
    {
 
824
        ffgclj(fptr, colnum, firstrow, firstelem, nelem, 1, 2, *(long *)
 
825
              nulval, (long *) array, nullarray, anynul, status);
 
826
    }
 
827
    else if (datatype == TLONGLONG)
 
828
    {
 
829
        ffgcljj(fptr, colnum, firstrow, firstelem, nelem, 1, 2, *(LONGLONG *)
 
830
              nulval, (LONGLONG *) array, nullarray, anynul, status);
 
831
    }
 
832
    else if (datatype == TFLOAT)
 
833
    {
 
834
      ffgcle(fptr, colnum, firstrow, firstelem, nelem, 1, 2, *(float *)
 
835
               nulval,(float *) array, nullarray, anynul, status);
 
836
    }
 
837
    else if (datatype == TDOUBLE)
 
838
    {
 
839
        ffgcld(fptr, colnum, firstrow, firstelem, nelem, 1, 2, *(double *)
 
840
              nulval, (double *) array, nullarray, anynul, status);
 
841
    }
 
842
    else if (datatype == TCOMPLEX)
 
843
    {
 
844
        ffgcle(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
 
845
           1, 2, *(float *) nulval, (float *) array, nullarray, anynul, status);
 
846
    }
 
847
    else if (datatype == TDBLCOMPLEX)
 
848
    {
 
849
        ffgcld(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2, 
 
850
         1, 2, *(double *) nulval, (double *) array, nullarray, anynul, status);
 
851
    }
 
852
 
 
853
    else if (datatype == TLOGICAL)
 
854
    {
 
855
        ffgcll(fptr, colnum, firstrow, firstelem, nelem, 2, *(char *) nulval,
 
856
          (char *) array, nullarray, anynul, status);
 
857
    }
 
858
    else if (datatype == TSTRING)
 
859
    {
 
860
        ffgcls(fptr, colnum, firstrow, firstelem, nelem, 2, (char *)
 
861
             nulval, (char **) array, nullarray, anynul, status);
 
862
    }
 
863
    else
 
864
      *status = BAD_DATATYPE;
 
865
 
 
866
    return(*status);
 
867
}
 
868