~ubuntu-branches/ubuntu/wily/pyfits/wily-proposed

« back to all changes in this revision

Viewing changes to cextern/cfitsio/getcole.c

  • Committer: Package Import Robot
  • Author(s): Aurelien Jarno
  • Date: 2013-12-07 16:18:48 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20131207161848-mcw0saz0iprjhbju
Tags: 1:3.2-1
* New upstream version.
* Bump Standards-Version to 3.9.5 (no changes).
* Remove build-depends on zlib1g-dev and remove patches/01-zlib.diff.
* Add build-depends on libcfitsio3-dev and add 
  patches/01-system-cfitsio.diff.
* Update debian/copyright.
* Install upstream changelog now that it is provided in the upstream
  tarball.
* Don't compress the binary packages with xz, it's no the dpkg's default.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  This file, getcole.c, contains routines that read data elements from   */
 
2
/*  a FITS image or table, with float datatype                             */
 
3
 
 
4
/*  The FITSIO software was written by William Pence at the High Energy    */
 
5
/*  Astrophysic Science Archive Research Center (HEASARC) at the NASA      */
 
6
/*  Goddard Space Flight Center.                                           */
 
7
 
 
8
#include <math.h>
 
9
#include <stdlib.h>
 
10
#include <limits.h>
 
11
#include <string.h>
 
12
#include "fitsio2.h"
 
13
 
 
14
/*--------------------------------------------------------------------------*/
 
15
int ffgpve( fitsfile *fptr,   /* I - FITS file pointer                       */
 
16
            long  group,      /* I - group to read (1 = 1st group)           */
 
17
            LONGLONG  firstelem,  /* I - first vector element to read (1 = 1st)  */
 
18
            LONGLONG  nelem,      /* I - number of values to read                */
 
19
            float nulval,     /* I - value for undefined pixels              */
 
20
            float *array,     /* O - array of values that are returned       */
 
21
            int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
22
            int  *status)     /* IO - error status                           */
 
23
/*
 
24
  Read an array of values from the primary array. Data conversion
 
25
  and scaling will be performed if necessary (e.g, if the datatype of
 
26
  the FITS array is not the same as the array being read).
 
27
  Undefined elements will be set equal to NULVAL, unless NULVAL=0
 
28
  in which case no checking for undefined values will be performed.
 
29
  ANYNUL is returned with a value of .true. if any pixels are undefined.
 
30
*/
 
31
{
 
32
    long row;
 
33
    char cdummy;
 
34
    int nullcheck = 1;
 
35
    float nullvalue;
 
36
 
 
37
    if (fits_is_compressed_image(fptr, status))
 
38
    {
 
39
        /* this is a compressed image in a binary table */
 
40
         nullvalue = nulval;  /* set local variable */
 
41
 
 
42
        fits_read_compressed_pixels(fptr, TFLOAT, firstelem, nelem,
 
43
            nullcheck, &nullvalue, array, NULL, anynul, status);
 
44
        return(*status);
 
45
    }
 
46
 
 
47
    /*
 
48
      the primary array is represented as a binary table:
 
49
      each group of the primary array is a row in the table,
 
50
      where the first column contains the group parameters
 
51
      and the second column contains the image itself.
 
52
    */
 
53
 
 
54
    row=maxvalue(1,group);
 
55
 
 
56
    ffgcle(fptr, 2, row, firstelem, nelem, 1, 1, nulval,
 
57
               array, &cdummy, anynul, status);
 
58
    return(*status);
 
59
}
 
60
/*--------------------------------------------------------------------------*/
 
61
int ffgpfe( fitsfile *fptr,   /* I - FITS file pointer                       */
 
62
            long  group,      /* I - group to read (1 = 1st group)           */
 
63
            LONGLONG  firstelem,  /* I - first vector element to read (1 = 1st)  */
 
64
            LONGLONG  nelem,      /* I - number of values to read                */
 
65
            float *array,     /* O - array of values that are returned       */
 
66
            char *nularray,   /* O - array of null pixel flags               */
 
67
            int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
68
            int  *status)     /* IO - error status                           */
 
69
/*
 
70
  Read an array of values from the primary array. Data conversion
 
71
  and scaling will be performed if necessary (e.g, if the datatype of
 
72
  the FITS array is not the same as the array being read).
 
73
  Any undefined pixels in the returned array will be set = 0 and the 
 
74
  corresponding nularray value will be set = 1.
 
75
  ANYNUL is returned with a value of .true. if any pixels are undefined.
 
76
*/
 
77
{
 
78
    long row;
 
79
    int nullcheck = 2;
 
80
 
 
81
    if (fits_is_compressed_image(fptr, status))
 
82
    {
 
83
        /* this is a compressed image in a binary table */
 
84
 
 
85
        fits_read_compressed_pixels(fptr, TFLOAT, firstelem, nelem,
 
86
            nullcheck, NULL, array, nularray, anynul, status);
 
87
        return(*status);
 
88
    }
 
89
 
 
90
    /*
 
91
      the primary array is represented as a binary table:
 
92
      each group of the primary array is a row in the table,
 
93
      where the first column contains the group parameters
 
94
      and the second column contains the image itself.
 
95
    */
 
96
 
 
97
    row=maxvalue(1,group);
 
98
 
 
99
    ffgcle(fptr, 2, row, firstelem, nelem, 1, 2, 0.F,
 
100
               array, nularray, anynul, status);
 
101
    return(*status);
 
102
}
 
103
/*--------------------------------------------------------------------------*/
 
104
int ffg2de(fitsfile *fptr,  /* I - FITS file pointer                       */
 
105
           long  group,     /* I - group to read (1 = 1st group)           */
 
106
           float nulval,    /* set undefined pixels equal to this          */
 
107
           LONGLONG  ncols,     /* I - number of pixels in each row of array   */
 
108
           LONGLONG  naxis1,    /* I - FITS image NAXIS1 value                 */
 
109
           LONGLONG  naxis2,    /* I - FITS image NAXIS2 value                 */
 
110
           float *array,    /* O - array to be filled and returned         */
 
111
           int  *anynul,    /* O - set to 1 if any values are null; else 0 */
 
112
           int  *status)    /* IO - error status                           */
 
113
/*
 
114
  Read an entire 2-D array of values to the primary array. Data conversion
 
115
  and scaling will be performed if necessary (e.g, if the datatype of the
 
116
  FITS array is not the same as the array being read).  Any null
 
117
  values in the array will be set equal to the value of nulval, unless
 
118
  nulval = 0 in which case no null checking will be performed.
 
119
*/
 
120
{
 
121
    /* call the 3D reading routine, with the 3rd dimension = 1 */
 
122
 
 
123
    ffg3de(fptr, group, nulval, ncols, naxis2, naxis1, naxis2, 1, array, 
 
124
           anynul, status);
 
125
 
 
126
    return(*status);
 
127
}
 
128
/*--------------------------------------------------------------------------*/
 
129
int ffg3de(fitsfile *fptr,  /* I - FITS file pointer                       */
 
130
           long  group,     /* I - group to read (1 = 1st group)           */
 
131
           float nulval,    /* set undefined pixels equal to this          */
 
132
           LONGLONG  ncols,     /* I - number of pixels in each row of array   */
 
133
           LONGLONG  nrows,     /* I - number of rows in each plane of array   */
 
134
           LONGLONG  naxis1,    /* I - FITS image NAXIS1 value                 */
 
135
           LONGLONG  naxis2,    /* I - FITS image NAXIS2 value                 */
 
136
           LONGLONG  naxis3,    /* I - FITS image NAXIS3 value                 */
 
137
           float *array,    /* O - array to be filled and returned         */
 
138
           int  *anynul,    /* O - set to 1 if any values are null; else 0 */
 
139
           int  *status)    /* IO - error status                           */
 
140
/*
 
141
  Read an entire 3-D array of values to the primary array. Data conversion
 
142
  and scaling will be performed if necessary (e.g, if the datatype of the
 
143
  FITS array is not the same as the array being read).  Any null
 
144
  values in the array will be set equal to the value of nulval, unless
 
145
  nulval = 0 in which case no null checking will be performed.
 
146
*/
 
147
{
 
148
    long tablerow, ii, jj;
 
149
    LONGLONG narray, nfits;
 
150
    char cdummy;
 
151
    int nullcheck = 1;
 
152
    long inc[] = {1,1,1};
 
153
    LONGLONG fpixel[] = {1,1,1};
 
154
    LONGLONG lpixel[3];
 
155
    float nullvalue;
 
156
 
 
157
    if (fits_is_compressed_image(fptr, status))
 
158
    {
 
159
        /* this is a compressed image in a binary table */
 
160
 
 
161
        lpixel[0] = ncols;
 
162
        lpixel[1] = nrows;
 
163
        lpixel[2] = naxis3;
 
164
        nullvalue = nulval;  /* set local variable */
 
165
 
 
166
        fits_read_compressed_img(fptr, TFLOAT, fpixel, lpixel, inc,
 
167
            nullcheck, &nullvalue, array, NULL, anynul, status);
 
168
        return(*status);
 
169
    }
 
170
 
 
171
    /*
 
172
      the primary array is represented as a binary table:
 
173
      each group of the primary array is a row in the table,
 
174
      where the first column contains the group parameters
 
175
      and the second column contains the image itself.
 
176
    */
 
177
    tablerow=maxvalue(1,group);
 
178
 
 
179
    if (ncols == naxis1 && nrows == naxis2)  /* arrays have same size? */
 
180
    {
 
181
       /* all the image pixels are contiguous, so read all at once */
 
182
       ffgcle(fptr, 2, tablerow, 1, naxis1 * naxis2 * naxis3, 1, 1, nulval,
 
183
               array, &cdummy, anynul, status);
 
184
       return(*status);
 
185
    }
 
186
 
 
187
    if (ncols < naxis1 || nrows < naxis2)
 
188
       return(*status = BAD_DIMEN);
 
189
 
 
190
    nfits = 1;   /* next pixel in FITS image to read */
 
191
    narray = 0;  /* next pixel in output array to be filled */
 
192
 
 
193
    /* loop over naxis3 planes in the data cube */
 
194
    for (jj = 0; jj < naxis3; jj++)
 
195
    {
 
196
      /* loop over the naxis2 rows in the FITS image, */
 
197
      /* reading naxis1 pixels to each row            */
 
198
 
 
199
      for (ii = 0; ii < naxis2; ii++)
 
200
      {
 
201
       if (ffgcle(fptr, 2, tablerow, nfits, naxis1, 1, 1, nulval,
 
202
          &array[narray], &cdummy, anynul, status) > 0)
 
203
          return(*status);
 
204
 
 
205
       nfits += naxis1;
 
206
       narray += ncols;
 
207
      }
 
208
      narray += (nrows - naxis2) * ncols;
 
209
    }
 
210
 
 
211
    return(*status);
 
212
}
 
213
/*--------------------------------------------------------------------------*/
 
214
int ffgsve(fitsfile *fptr, /* I - FITS file pointer                         */
 
215
           int  colnum,    /* I - number of the column to read (1 = 1st)    */
 
216
           int naxis,      /* I - number of dimensions in the FITS array    */
 
217
           long  *naxes,   /* I - size of each dimension                    */
 
218
           long  *blc,     /* I - 'bottom left corner' of the subsection    */
 
219
           long  *trc,     /* I - 'top right corner' of the subsection      */
 
220
           long  *inc,     /* I - increment to be applied in each dimension */
 
221
           float nulval,   /* I - value to set undefined pixels             */
 
222
           float *array,   /* O - array to be filled and returned           */
 
223
           int  *anynul,   /* O - set to 1 if any values are null; else 0   */
 
224
           int  *status)   /* IO - error status                             */
 
225
/*
 
226
  Read a subsection of data values from an image or a table column.
 
227
  This routine is set up to handle a maximum of nine dimensions.
 
228
*/
 
229
{
 
230
    long ii,i0, i1,i2,i3,i4,i5,i6,i7,i8,row,rstr,rstp,rinc;
 
231
    long str[9],stp[9],incr[9],dir[9];
 
232
    long nelem, nultyp, ninc, numcol;
 
233
    LONGLONG felem, dsize[10], blcll[9], trcll[9];
 
234
    int hdutype, anyf;
 
235
    char ldummy, msg[FLEN_ERRMSG];
 
236
    int nullcheck = 1;
 
237
    float nullvalue;
 
238
 
 
239
    if (naxis < 1 || naxis > 9)
 
240
    {
 
241
        sprintf(msg, "NAXIS = %d in call to ffgsve is out of range", naxis);
 
242
        ffpmsg(msg);
 
243
        return(*status = BAD_DIMEN);
 
244
    }
 
245
 
 
246
    if (fits_is_compressed_image(fptr, status))
 
247
    {
 
248
        /* this is a compressed image in a binary table */
 
249
 
 
250
        for (ii=0; ii < naxis; ii++) {
 
251
            blcll[ii] = blc[ii];
 
252
            trcll[ii] = trc[ii];
 
253
        }
 
254
 
 
255
        nullvalue = nulval;  /* set local variable */
 
256
 
 
257
        fits_read_compressed_img(fptr, TFLOAT, blcll, trcll, inc,
 
258
            nullcheck, &nullvalue, array, NULL, anynul, status);
 
259
        return(*status);
 
260
    }
 
261
 
 
262
/*
 
263
    if this is a primary array, then the input COLNUM parameter should
 
264
    be interpreted as the row number, and we will alway read the image
 
265
    data from column 2 (any group parameters are in column 1).
 
266
*/
 
267
    if (ffghdt(fptr, &hdutype, status) > 0)
 
268
        return(*status);
 
269
 
 
270
    if (hdutype == IMAGE_HDU)
 
271
    {
 
272
        /* this is a primary array, or image extension */
 
273
        if (colnum == 0)
 
274
        {
 
275
            rstr = 1;
 
276
            rstp = 1;
 
277
        }
 
278
        else
 
279
        {
 
280
            rstr = colnum;
 
281
            rstp = colnum;
 
282
        }
 
283
        rinc = 1;
 
284
        numcol = 2;
 
285
    }
 
286
    else
 
287
    {
 
288
        /* this is a table, so the row info is in the (naxis+1) elements */
 
289
        rstr = blc[naxis];
 
290
        rstp = trc[naxis];
 
291
        rinc = inc[naxis];
 
292
        numcol = colnum;
 
293
    }
 
294
 
 
295
    nultyp = 1;
 
296
    if (anynul)
 
297
        *anynul = FALSE;
 
298
 
 
299
    i0 = 0;
 
300
    for (ii = 0; ii < 9; ii++)
 
301
    {
 
302
        str[ii] = 1;
 
303
        stp[ii] = 1;
 
304
        incr[ii] = 1;
 
305
        dsize[ii] = 1;
 
306
        dir[ii] = 1;
 
307
    }
 
308
 
 
309
    for (ii = 0; ii < naxis; ii++)
 
310
    {
 
311
      if (trc[ii] < blc[ii])
 
312
      {
 
313
        if (hdutype == IMAGE_HDU)
 
314
        {
 
315
           dir[ii] = -1;
 
316
        }
 
317
        else
 
318
        {
 
319
          sprintf(msg, "ffgsve: illegal range specified for axis %ld", ii + 1);
 
320
          ffpmsg(msg);
 
321
          return(*status = BAD_PIX_NUM);
 
322
        }
 
323
      }
 
324
 
 
325
      str[ii] = blc[ii];
 
326
      stp[ii] = trc[ii];
 
327
      incr[ii] = inc[ii];
 
328
      dsize[ii + 1] = dsize[ii] * naxes[ii];
 
329
      dsize[ii] = dsize[ii] * dir[ii];
 
330
    }
 
331
    dsize[naxis] = dsize[naxis] * dir[naxis];
 
332
 
 
333
    if (naxis == 1 && naxes[0] == 1)
 
334
    {
 
335
      /* This is not a vector column, so read all the rows at once */
 
336
      nelem = (rstp - rstr) / rinc + 1;
 
337
      ninc = rinc;
 
338
      rstp = rstr;
 
339
    }
 
340
    else
 
341
    {
 
342
      /* have to read each row individually, in all dimensions */
 
343
      nelem = (stp[0]*dir[0] - str[0]*dir[0]) / inc[0] + 1;
 
344
      ninc = incr[0] * dir[0];
 
345
    }
 
346
 
 
347
    for (row = rstr; row <= rstp; row += rinc)
 
348
    {
 
349
     for (i8 = str[8]*dir[8]; i8 <= stp[8]*dir[8]; i8 += incr[8])
 
350
     {
 
351
      for (i7 = str[7]*dir[7]; i7 <= stp[7]*dir[7]; i7 += incr[7])
 
352
      {
 
353
       for (i6 = str[6]*dir[6]; i6 <= stp[6]*dir[6]; i6 += incr[6])
 
354
       {
 
355
        for (i5 = str[5]*dir[5]; i5 <= stp[5]*dir[5]; i5 += incr[5])
 
356
        {
 
357
         for (i4 = str[4]*dir[4]; i4 <= stp[4]*dir[4]; i4 += incr[4])
 
358
         {
 
359
          for (i3 = str[3]*dir[3]; i3 <= stp[3]*dir[3]; i3 += incr[3])
 
360
          {
 
361
           for (i2 = str[2]*dir[2]; i2 <= stp[2]*dir[2]; i2 += incr[2])
 
362
           {
 
363
            for (i1 = str[1]*dir[1]; i1 <= stp[1]*dir[1]; i1 += incr[1])
 
364
            {
 
365
 
 
366
              felem=str[0] + (i1 - dir[1]) * dsize[1] + (i2 - dir[2]) * dsize[2] + 
 
367
                             (i3 - dir[3]) * dsize[3] + (i4 - dir[4]) * dsize[4] +
 
368
                             (i5 - dir[5]) * dsize[5] + (i6 - dir[6]) * dsize[6] +
 
369
                             (i7 - dir[7]) * dsize[7] + (i8 - dir[8]) * dsize[8];
 
370
 
 
371
              if ( ffgcle(fptr, numcol, row, felem, nelem, ninc, nultyp,
 
372
                   nulval, &array[i0], &ldummy, &anyf, status) > 0)
 
373
                   return(*status);
 
374
 
 
375
              if (anyf && anynul)
 
376
                  *anynul = TRUE;
 
377
 
 
378
              i0 += nelem;
 
379
            }
 
380
           }
 
381
          }
 
382
         }
 
383
        }
 
384
       }
 
385
      }
 
386
     }
 
387
    }
 
388
    return(*status);
 
389
}
 
390
/*--------------------------------------------------------------------------*/
 
391
int ffgsfe(fitsfile *fptr, /* I - FITS file pointer                         */
 
392
           int  colnum,    /* I - number of the column to read (1 = 1st)    */
 
393
           int naxis,      /* I - number of dimensions in the FITS array    */
 
394
           long  *naxes,   /* I - size of each dimension                    */
 
395
           long  *blc,     /* I - 'bottom left corner' of the subsection    */
 
396
           long  *trc,     /* I - 'top right corner' of the subsection      */
 
397
           long  *inc,     /* I - increment to be applied in each dimension */
 
398
           float *array,   /* O - array to be filled and returned           */
 
399
           char *flagval,  /* O - set to 1 if corresponding value is null   */
 
400
           int  *anynul,   /* O - set to 1 if any values are null; else 0   */
 
401
           int  *status)   /* IO - error status                             */
 
402
/*
 
403
  Read a subsection of data values from an image or a table column.
 
404
  This routine is set up to handle a maximum of nine dimensions.
 
405
*/
 
406
{
 
407
    long ii,i0, i1,i2,i3,i4,i5,i6,i7,i8,row,rstr,rstp,rinc;
 
408
    long str[9],stp[9],incr[9],dsize[10];
 
409
    LONGLONG blcll[9], trcll[9];
 
410
    long felem, nelem, nultyp, ninc, numcol;
 
411
    int hdutype, anyf;
 
412
    float nulval = 0;
 
413
    char msg[FLEN_ERRMSG];
 
414
    int nullcheck = 2;
 
415
 
 
416
    if (naxis < 1 || naxis > 9)
 
417
    {
 
418
        sprintf(msg, "NAXIS = %d in call to ffgsve is out of range", naxis);
 
419
        ffpmsg(msg);
 
420
        return(*status = BAD_DIMEN);
 
421
    }
 
422
 
 
423
    if (fits_is_compressed_image(fptr, status))
 
424
    {
 
425
        /* this is a compressed image in a binary table */
 
426
 
 
427
        for (ii=0; ii < naxis; ii++) {
 
428
            blcll[ii] = blc[ii];
 
429
            trcll[ii] = trc[ii];
 
430
        }
 
431
 
 
432
        fits_read_compressed_img(fptr, TFLOAT, blcll, trcll, inc,
 
433
            nullcheck, NULL, array, flagval, anynul, status);
 
434
        return(*status);
 
435
    }
 
436
 
 
437
/*
 
438
    if this is a primary array, then the input COLNUM parameter should
 
439
    be interpreted as the row number, and we will alway read the image
 
440
    data from column 2 (any group parameters are in column 1).
 
441
*/
 
442
    if (ffghdt(fptr, &hdutype, status) > 0)
 
443
        return(*status);
 
444
 
 
445
    if (hdutype == IMAGE_HDU)
 
446
    {
 
447
        /* this is a primary array, or image extension */
 
448
        if (colnum == 0)
 
449
        {
 
450
            rstr = 1;
 
451
            rstp = 1;
 
452
        }
 
453
        else
 
454
        {
 
455
            rstr = colnum;
 
456
            rstp = colnum;
 
457
        }
 
458
        rinc = 1;
 
459
        numcol = 2;
 
460
    }
 
461
    else
 
462
    {
 
463
        /* this is a table, so the row info is in the (naxis+1) elements */
 
464
        rstr = blc[naxis];
 
465
        rstp = trc[naxis];
 
466
        rinc = inc[naxis];
 
467
        numcol = colnum;
 
468
    }
 
469
 
 
470
    nultyp = 2;
 
471
    if (anynul)
 
472
        *anynul = FALSE;
 
473
 
 
474
    i0 = 0;
 
475
    for (ii = 0; ii < 9; ii++)
 
476
    {
 
477
        str[ii] = 1;
 
478
        stp[ii] = 1;
 
479
        incr[ii] = 1;
 
480
        dsize[ii] = 1;
 
481
    }
 
482
 
 
483
    for (ii = 0; ii < naxis; ii++)
 
484
    {
 
485
      if (trc[ii] < blc[ii])
 
486
      {
 
487
        sprintf(msg, "ffgsve: illegal range specified for axis %ld", ii + 1);
 
488
        ffpmsg(msg);
 
489
        return(*status = BAD_PIX_NUM);
 
490
      }
 
491
 
 
492
      str[ii] = blc[ii];
 
493
      stp[ii] = trc[ii];
 
494
      incr[ii] = inc[ii];
 
495
      dsize[ii + 1] = dsize[ii] * naxes[ii];
 
496
    }
 
497
 
 
498
    if (naxis == 1 && naxes[0] == 1)
 
499
    {
 
500
      /* This is not a vector column, so read all the rows at once */
 
501
      nelem = (rstp - rstr) / rinc + 1;
 
502
      ninc = rinc;
 
503
      rstp = rstr;
 
504
    }
 
505
    else
 
506
    {
 
507
      /* have to read each row individually, in all dimensions */
 
508
      nelem = (stp[0] - str[0]) / inc[0] + 1;
 
509
      ninc = incr[0];
 
510
    }
 
511
 
 
512
    for (row = rstr; row <= rstp; row += rinc)
 
513
    {
 
514
     for (i8 = str[8]; i8 <= stp[8]; i8 += incr[8])
 
515
     {
 
516
      for (i7 = str[7]; i7 <= stp[7]; i7 += incr[7])
 
517
      {
 
518
       for (i6 = str[6]; i6 <= stp[6]; i6 += incr[6])
 
519
       {
 
520
        for (i5 = str[5]; i5 <= stp[5]; i5 += incr[5])
 
521
        {
 
522
         for (i4 = str[4]; i4 <= stp[4]; i4 += incr[4])
 
523
         {
 
524
          for (i3 = str[3]; i3 <= stp[3]; i3 += incr[3])
 
525
          {
 
526
           for (i2 = str[2]; i2 <= stp[2]; i2 += incr[2])
 
527
           {
 
528
            for (i1 = str[1]; i1 <= stp[1]; i1 += incr[1])
 
529
            {
 
530
              felem=str[0] + (i1 - 1) * dsize[1] + (i2 - 1) * dsize[2] + 
 
531
                             (i3 - 1) * dsize[3] + (i4 - 1) * dsize[4] +
 
532
                             (i5 - 1) * dsize[5] + (i6 - 1) * dsize[6] +
 
533
                             (i7 - 1) * dsize[7] + (i8 - 1) * dsize[8];
 
534
 
 
535
              if ( ffgcle(fptr, numcol, row, felem, nelem, ninc, nultyp,
 
536
                   nulval, &array[i0], &flagval[i0], &anyf, status) > 0)
 
537
                   return(*status);
 
538
 
 
539
              if (anyf && anynul)
 
540
                  *anynul = TRUE;
 
541
 
 
542
              i0 += nelem;
 
543
            }
 
544
           }
 
545
          }
 
546
         }
 
547
        }
 
548
       }
 
549
      }
 
550
     }
 
551
    }
 
552
    return(*status);
 
553
}
 
554
/*--------------------------------------------------------------------------*/
 
555
int ffggpe( fitsfile *fptr,   /* I - FITS file pointer                       */
 
556
            long  group,      /* I - group to read (1 = 1st group)           */
 
557
            long  firstelem,  /* I - first vector element to read (1 = 1st)  */
 
558
            long  nelem,      /* I - number of values to read                */
 
559
            float *array,     /* O - array of values that are returned       */
 
560
            int  *status)     /* IO - error status                           */
 
561
/*
 
562
  Read an array of group parameters from the primary array. Data conversion
 
563
  and scaling will be performed if necessary (e.g, if the datatype of
 
564
  the FITS array is not the same as the array being read).
 
565
*/
 
566
{
 
567
    long row;
 
568
    int idummy;
 
569
    char cdummy;
 
570
    /*
 
571
      the primary array is represented as a binary table:
 
572
      each group of the primary array is a row in the table,
 
573
      where the first column contains the group parameters
 
574
      and the second column contains the image itself.
 
575
    */
 
576
 
 
577
    row=maxvalue(1,group);
 
578
 
 
579
    ffgcle(fptr, 1, row, firstelem, nelem, 1, 1, 0.F,
 
580
               array, &cdummy, &idummy, status);
 
581
    return(*status);
 
582
}
 
583
/*--------------------------------------------------------------------------*/
 
584
int ffgcve(fitsfile *fptr,   /* I - FITS file pointer                       */
 
585
           int  colnum,      /* I - number of column to read (1 = 1st col)  */
 
586
           LONGLONG  firstrow,   /* I - first row to read (1 = 1st row)         */
 
587
           LONGLONG  firstelem,  /* I - first vector element to read (1 = 1st)  */
 
588
           LONGLONG  nelem,      /* I - number of values to read                */
 
589
           float nulval,     /* I - value for null pixels                   */
 
590
           float *array,     /* O - array of values that are read           */
 
591
           int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
592
           int  *status)     /* IO - error status                           */
 
593
/*
 
594
  Read an array of values from a column in the current FITS HDU. Automatic
 
595
  datatype conversion will be performed if the datatype of the column does not
 
596
  match the datatype of the array parameter. The output values will be scaled 
 
597
  by the FITS TSCALn and TZEROn values if these values have been defined.
 
598
  Any undefined pixels will be set equal to the value of 'nulval' unless
 
599
  nulval = 0 in which case no checks for undefined pixels will be made.
 
600
*/
 
601
{
 
602
    char cdummy;
 
603
 
 
604
    ffgcle(fptr, colnum, firstrow, firstelem, nelem, 1, 1, nulval,
 
605
           array, &cdummy, anynul, status);
 
606
    return(*status);
 
607
}
 
608
/*--------------------------------------------------------------------------*/
 
609
int ffgcvc(fitsfile *fptr,   /* I - FITS file pointer                       */
 
610
           int  colnum,      /* I - number of column to read (1 = 1st col)  */
 
611
           LONGLONG  firstrow,   /* I - first row to read (1 = 1st row)         */
 
612
           LONGLONG  firstelem,  /* I - first vector element to read (1 = 1st)  */
 
613
           LONGLONG  nelem,      /* I - number of values to read                */
 
614
           float nulval,     /* I - value for null pixels                   */
 
615
           float *array,     /* O - array of values that are read           */
 
616
           int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
617
           int  *status)     /* IO - error status                           */
 
618
/*
 
619
  Read an array of values from a column in the current FITS HDU. Automatic
 
620
  datatype conversion will be performed if the datatype of the column does not
 
621
  match the datatype of the array parameter. The output values will be scaled 
 
622
  by the FITS TSCALn and TZEROn values if these values have been defined.
 
623
  Any undefined pixels will be set equal to the value of 'nulval' unless
 
624
  nulval = 0 in which case no checks for undefined pixels will be made.
 
625
 
 
626
  TSCAL and ZERO should not be used with complex values. 
 
627
*/
 
628
{
 
629
    char cdummy;
 
630
 
 
631
    /* a complex value is interpreted as a pair of float values, thus */
 
632
    /* need to multiply the first element and number of elements by 2 */
 
633
 
 
634
    ffgcle(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem *2,
 
635
           1, 1, nulval, array, &cdummy, anynul, status);
 
636
    return(*status);
 
637
}
 
638
/*--------------------------------------------------------------------------*/
 
639
int ffgcfe(fitsfile *fptr,   /* I - FITS file pointer                       */
 
640
           int  colnum,      /* I - number of column to read (1 = 1st col)  */
 
641
           LONGLONG  firstrow,   /* I - first row to read (1 = 1st row)         */
 
642
           LONGLONG  firstelem,  /* I - first vector element to read (1 = 1st)  */
 
643
           LONGLONG  nelem,      /* I - number of values to read                */
 
644
           float *array,     /* O - array of values that are read           */
 
645
           char *nularray,   /* O - array of flags: 1 if null pixel; else 0 */
 
646
           int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
647
           int  *status)     /* IO - error status                           */
 
648
/*
 
649
  Read an array of values from a column in the current FITS HDU. Automatic
 
650
  datatype conversion will be performed if the datatype of the column does not
 
651
  match the datatype of the array parameter. The output values will be scaled 
 
652
  by the FITS TSCALn and TZEROn values if these values have been defined.
 
653
  Nularray will be set = 1 if the corresponding array pixel is undefined, 
 
654
  otherwise nularray will = 0.
 
655
*/
 
656
{
 
657
    float dummy = 0;
 
658
 
 
659
    ffgcle(fptr, colnum, firstrow, firstelem, nelem, 1, 2, dummy,
 
660
           array, nularray, anynul, status);
 
661
    return(*status);
 
662
}
 
663
/*--------------------------------------------------------------------------*/
 
664
int ffgcfc(fitsfile *fptr,   /* I - FITS file pointer                       */
 
665
           int  colnum,      /* I - number of column to read (1 = 1st col)  */
 
666
           LONGLONG  firstrow,   /* I - first row to read (1 = 1st row)         */
 
667
           LONGLONG  firstelem,  /* I - first vector element to read (1 = 1st)  */
 
668
           LONGLONG  nelem,      /* I - number of values to read                */
 
669
           float *array,     /* O - array of values that are read           */
 
670
           char *nularray,   /* O - array of flags: 1 if null pixel; else 0 */
 
671
           int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
672
           int  *status)     /* IO - error status                           */
 
673
/*
 
674
  Read an array of values from a column in the current FITS HDU. Automatic
 
675
  datatype conversion will be performed if the datatype of the column does not
 
676
  match the datatype of the array parameter. The output values will be scaled 
 
677
  by the FITS TSCALn and TZEROn values if these values have been defined.
 
678
  Nularray will be set = 1 if the corresponding array pixel is undefined, 
 
679
  otherwise nularray will = 0.
 
680
 
 
681
  TSCAL and ZERO should not be used with complex values. 
 
682
*/
 
683
{
 
684
    long ii, jj;
 
685
    float dummy = 0;
 
686
    char *carray;
 
687
 
 
688
    /* a complex value is interpreted as a pair of float values, thus */
 
689
    /* need to multiply the first element and number of elements by 2 */
 
690
    
 
691
    /* allocate temporary array */
 
692
    carray = (char *) calloc( (size_t) (nelem * 2), 1); 
 
693
 
 
694
    ffgcle(fptr, colnum, firstrow, (firstelem - 1) * 2 + 1, nelem * 2,
 
695
           1, 2, dummy, array, carray, anynul, status);
 
696
 
 
697
    for (ii = 0, jj = 0; jj < nelem; ii += 2, jj++)
 
698
    {
 
699
       if (carray[ii] || carray[ii + 1])
 
700
          nularray[jj] = 1;
 
701
       else
 
702
          nularray[jj] = 0;
 
703
    }
 
704
 
 
705
    free(carray);    
 
706
    return(*status);
 
707
}
 
708
/*--------------------------------------------------------------------------*/
 
709
int ffgcle( fitsfile *fptr,   /* I - FITS file pointer                       */
 
710
            int  colnum,      /* I - number of column to read (1 = 1st col)  */
 
711
            LONGLONG  firstrow,   /* I - first row to read (1 = 1st row)         */
 
712
            LONGLONG firstelem,  /* I - first vector element to read (1 = 1st)  */
 
713
            LONGLONG  nelem,      /* I - number of values to read                */
 
714
            long  elemincre,  /* I - pixel increment; e.g., 2 = every other  */
 
715
            int   nultyp,     /* I - null value handling code:               */
 
716
                              /*     1: set undefined pixels = nulval        */
 
717
                              /*     2: set nularray=1 for undefined pixels  */
 
718
            float nulval,     /* I - value for null pixels if nultyp = 1     */
 
719
            float *array,     /* O - array of values that are read           */
 
720
            char *nularray,   /* O - array of flags = 1 if nultyp = 2        */
 
721
            int  *anynul,     /* O - set to 1 if any values are null; else 0 */
 
722
            int  *status)     /* IO - error status                           */
 
723
/*
 
724
  Read an array of values from a column in the current FITS HDU.
 
725
  The column number may refer to a real column in an ASCII or binary table, 
 
726
  or it may refer be a virtual column in a 1 or more grouped FITS primary
 
727
  array or image extension.  FITSIO treats a primary array as a binary table
 
728
  with 2 vector columns: the first column contains the group parameters (often
 
729
  with length = 0) and the second column contains the array of image pixels.
 
730
  Each row of the table represents a group in the case of multigroup FITS
 
731
  images.
 
732
 
 
733
  The output array of values will be converted from the datatype of the column 
 
734
  and will be scaled by the FITS TSCALn and TZEROn values if necessary.
 
735
*/
 
736
{
 
737
    double scale, zero, power = 1., dtemp;
 
738
    int tcode, maxelem2, hdutype, xcode, decimals;
 
739
    long twidth, incre;
 
740
    long ii, xwidth, ntodo;
 
741
    int convert, nulcheck, readcheck = 0;
 
742
    LONGLONG repeat, startpos, elemnum, readptr, tnull;
 
743
    LONGLONG rowlen, rownum, remain, next, rowincre, maxelem;
 
744
    char tform[20];
 
745
    char message[81];
 
746
    char snull[20];   /*  the FITS null value if reading from ASCII table  */
 
747
 
 
748
    double cbuff[DBUFFSIZE / sizeof(double)]; /* align cbuff on word boundary */
 
749
    void *buffer;
 
750
 
 
751
    if (*status > 0 || nelem == 0)  /* inherit input status value if > 0 */
 
752
        return(*status);
 
753
 
 
754
    buffer = cbuff;
 
755
 
 
756
    if (anynul)
 
757
       *anynul = 0;
 
758
 
 
759
    if (nultyp == 2)
 
760
        memset(nularray, 0, (size_t) nelem);   /* initialize nullarray */
 
761
 
 
762
    /*---------------------------------------------------*/
 
763
    /*  Check input and get parameters about the column: */
 
764
    /*---------------------------------------------------*/
 
765
    if (elemincre < 0)
 
766
        readcheck = -1;  /* don't do range checking in this case */
 
767
 
 
768
    if ( ffgcprll( fptr, colnum, firstrow, firstelem, nelem, readcheck, &scale, &zero,
 
769
         tform, &twidth, &tcode, &maxelem2, &startpos, &elemnum, &incre,
 
770
         &repeat, &rowlen, &hdutype, &tnull, snull, status) > 0 )
 
771
         return(*status);
 
772
    maxelem = maxelem2;
 
773
 
 
774
    incre *= elemincre;   /* multiply incre to just get every nth pixel */
 
775
 
 
776
    if (tcode == TSTRING)    /* setup for ASCII tables */
 
777
    {
 
778
      /* get the number of implied decimal places if no explicit decmal point */
 
779
      ffasfm(tform, &xcode, &xwidth, &decimals, status); 
 
780
      for(ii = 0; ii < decimals; ii++)
 
781
        power *= 10.;
 
782
    }
 
783
 
 
784
    /*------------------------------------------------------------------*/
 
785
    /*  Decide whether to check for null values in the input FITS file: */
 
786
    /*------------------------------------------------------------------*/
 
787
    nulcheck = nultyp; /* by default check for null values in the FITS file */
 
788
 
 
789
    if (nultyp == 1 && nulval == 0)
 
790
       nulcheck = 0;    /* calling routine does not want to check for nulls */
 
791
 
 
792
    else if (tcode%10 == 1 &&        /* if reading an integer column, and  */ 
 
793
            tnull == NULL_UNDEFINED) /* if a null value is not defined,    */
 
794
            nulcheck = 0;            /* then do not check for null values. */
 
795
 
 
796
    else if (tcode == TSHORT && (tnull > SHRT_MAX || tnull < SHRT_MIN) )
 
797
            nulcheck = 0;            /* Impossible null value */
 
798
 
 
799
    else if (tcode == TBYTE && (tnull > 255 || tnull < 0) )
 
800
            nulcheck = 0;            /* Impossible null value */
 
801
 
 
802
    else if (tcode == TSTRING && snull[0] == ASCII_NULL_UNDEFINED)
 
803
         nulcheck = 0;
 
804
 
 
805
    /*----------------------------------------------------------------------*/
 
806
    /*  If FITS column and output data array have same datatype, then we do */
 
807
    /*  not need to use a temporary buffer to store intermediate datatype.  */
 
808
    /*----------------------------------------------------------------------*/
 
809
    convert = 1;
 
810
    if (tcode == TFLOAT) /* Special Case:                        */
 
811
    {                             /* no type convertion required, so read */
 
812
        maxelem = nelem;          /* data directly into output buffer.    */
 
813
 
 
814
        if (nulcheck == 0 && scale == 1. && zero == 0.)
 
815
            convert = 0;  /* no need to scale data or find nulls */
 
816
    }
 
817
 
 
818
    /*---------------------------------------------------------------------*/
 
819
    /*  Now read the pixels from the FITS column. If the column does not   */
 
820
    /*  have the same datatype as the output array, then we have to read   */
 
821
    /*  the raw values into a temporary buffer (of limited size).  In      */
 
822
    /*  the case of a vector colum read only 1 vector of values at a time  */
 
823
    /*  then skip to the next row if more values need to be read.          */
 
824
    /*  After reading the raw values, then call the fffXXYY routine to (1) */
 
825
    /*  test for undefined values, (2) convert the datatype if necessary,  */
 
826
    /*  and (3) scale the values by the FITS TSCALn and TZEROn linear      */
 
827
    /*  scaling parameters.                                                */
 
828
    /*---------------------------------------------------------------------*/
 
829
    remain = nelem;           /* remaining number of values to read */
 
830
    next = 0;                 /* next element in array to be read   */
 
831
    rownum = 0;               /* row number, relative to firstrow   */
 
832
 
 
833
    while (remain)
 
834
    {
 
835
        /* limit the number of pixels to read at one time to the number that
 
836
           will fit in the buffer or to the number of pixels that remain in
 
837
           the current vector, which ever is smaller.
 
838
        */
 
839
        ntodo = (long) minvalue(remain, maxelem);
 
840
        if (elemincre >= 0)
 
841
        {
 
842
          ntodo = (long) minvalue(ntodo, ((repeat - elemnum - 1)/elemincre +1));
 
843
        }
 
844
        else
 
845
        {
 
846
          ntodo = (long) minvalue(ntodo, (elemnum/(-elemincre) +1));
 
847
        }
 
848
 
 
849
        readptr = startpos + ((LONGLONG)rownum * rowlen) + (elemnum * (incre / elemincre));
 
850
 
 
851
        switch (tcode) 
 
852
        {
 
853
            case (TFLOAT):
 
854
                ffgr4b(fptr, readptr, ntodo, incre, &array[next], status);
 
855
                if (convert)
 
856
                    fffr4r4(&array[next], ntodo, scale, zero, nulcheck, 
 
857
                           nulval, &nularray[next], anynul, 
 
858
                           &array[next], status);
 
859
                break;
 
860
            case (TBYTE):
 
861
                ffgi1b(fptr, readptr, ntodo, incre, (unsigned char *) buffer,
 
862
                       status);
 
863
                fffi1r4((unsigned char *) buffer, ntodo, scale, zero, nulcheck, 
 
864
                    (unsigned char) tnull, nulval, &nularray[next], anynul, 
 
865
                     &array[next], status);
 
866
                break;
 
867
            case (TSHORT):
 
868
                ffgi2b(fptr, readptr, ntodo, incre, (short  *) buffer, status);
 
869
                fffi2r4((short  *) buffer, ntodo, scale, zero, nulcheck, 
 
870
                       (short) tnull, nulval, &nularray[next], anynul, 
 
871
                       &array[next], status);
 
872
                break;
 
873
            case (TLONG):
 
874
                ffgi4b(fptr, readptr, ntodo, incre, (INT32BIT *) buffer,
 
875
                       status);
 
876
                fffi4r4((INT32BIT *) buffer, ntodo, scale, zero, nulcheck, 
 
877
                       (INT32BIT) tnull, nulval, &nularray[next], anynul, 
 
878
                       &array[next], status);
 
879
                break;
 
880
 
 
881
            case (TLONGLONG):
 
882
                ffgi8b(fptr, readptr, ntodo, incre, (long *) buffer, status);
 
883
                fffi8r4( (LONGLONG *) buffer, ntodo, scale, zero, 
 
884
                           nulcheck, tnull, nulval, &nularray[next], 
 
885
                            anynul, &array[next], status);
 
886
                break;
 
887
            case (TDOUBLE):
 
888
                ffgr8b(fptr, readptr, ntodo, incre, (double *) buffer, status);
 
889
                fffr8r4((double *) buffer, ntodo, scale, zero, nulcheck, 
 
890
                          nulval, &nularray[next], anynul, 
 
891
                          &array[next], status);
 
892
                break;
 
893
            case (TSTRING):
 
894
                ffmbyt(fptr, readptr, REPORT_EOF, status);
 
895
       
 
896
                if (incre == twidth)    /* contiguous bytes */
 
897
                     ffgbyt(fptr, ntodo * twidth, buffer, status);
 
898
                else
 
899
                     ffgbytoff(fptr, twidth, ntodo, incre - twidth, buffer,
 
900
                               status);
 
901
 
 
902
                fffstrr4((char *) buffer, ntodo, scale, zero, twidth, power,
 
903
                     nulcheck, snull, nulval, &nularray[next], anynul,
 
904
                     &array[next], status);
 
905
                break;
 
906
 
 
907
 
 
908
            default:  /*  error trap for invalid column format */
 
909
                sprintf(message, 
 
910
                   "Cannot read numbers from column %d which has format %s",
 
911
                    colnum, tform);
 
912
                ffpmsg(message);
 
913
                if (hdutype == ASCII_TBL)
 
914
                    return(*status = BAD_ATABLE_FORMAT);
 
915
                else
 
916
                    return(*status = BAD_BTABLE_FORMAT);
 
917
 
 
918
        } /* End of switch block */
 
919
 
 
920
        /*-------------------------*/
 
921
        /*  Check for fatal error  */
 
922
        /*-------------------------*/
 
923
        if (*status > 0)  /* test for error during previous read operation */
 
924
        {
 
925
          dtemp = (double) next;
 
926
          if (hdutype > 0)
 
927
            sprintf(message,
 
928
            "Error reading elements %.0f thru %.0f from column %d (ffgcle).",
 
929
              dtemp+1., dtemp+ntodo, colnum);
 
930
          else
 
931
            sprintf(message,
 
932
            "Error reading elements %.0f thru %.0f from image (ffgcle).",
 
933
              dtemp+1., dtemp+ntodo);
 
934
 
 
935
          ffpmsg(message);
 
936
          return(*status);
 
937
        }
 
938
 
 
939
        /*--------------------------------------------*/
 
940
        /*  increment the counters for the next loop  */
 
941
        /*--------------------------------------------*/
 
942
        remain -= ntodo;
 
943
        if (remain)
 
944
        {
 
945
            next += ntodo;
 
946
            elemnum = elemnum + (ntodo * elemincre);
 
947
 
 
948
            if (elemnum >= repeat)  /* completed a row; start on later row */
 
949
            {
 
950
                rowincre = elemnum / repeat;
 
951
                rownum += rowincre;
 
952
                elemnum = elemnum - (rowincre * repeat);
 
953
            }
 
954
            else if (elemnum < 0)  /* completed a row; start on a previous row */
 
955
            {
 
956
                rowincre = (-elemnum - 1) / repeat + 1;
 
957
                rownum -= rowincre;
 
958
                elemnum = (rowincre * repeat) + elemnum;
 
959
            }
 
960
        }
 
961
    }  /*  End of main while Loop  */
 
962
 
 
963
 
 
964
    /*--------------------------------*/
 
965
    /*  check for numerical overflow  */
 
966
    /*--------------------------------*/
 
967
    if (*status == OVERFLOW_ERR)
 
968
    {
 
969
        ffpmsg(
 
970
        "Numerical overflow during type conversion while reading FITS data.");
 
971
        *status = NUM_OVERFLOW;
 
972
    }
 
973
 
 
974
    return(*status);
 
975
}
 
976
/*--------------------------------------------------------------------------*/
 
977
int fffi1r4(unsigned char *input, /* I - array of values to be converted     */
 
978
            long ntodo,           /* I - number of elements in the array     */
 
979
            double scale,         /* I - FITS TSCALn or BSCALE value         */
 
980
            double zero,          /* I - FITS TZEROn or BZERO  value         */
 
981
            int nullcheck,        /* I - null checking code; 0 = don't check */
 
982
                                  /*     1:set null pixels = nullval         */
 
983
                                  /*     2: if null pixel, set nullarray = 1 */
 
984
            unsigned char tnull,  /* I - value of FITS TNULLn keyword if any */
 
985
            float nullval,        /* I - set null pixels, if nullcheck = 1   */
 
986
            char *nullarray,      /* I - bad pixel array, if nullcheck = 2   */
 
987
            int  *anynull,        /* O - set to 1 if any pixels are null     */
 
988
            float *output,        /* O - array of converted pixels           */
 
989
            int *status)          /* IO - error status                       */
 
990
/*
 
991
  Copy input to output following reading of the input from a FITS file.
 
992
  Check for null values and do datatype conversion and scaling if required.
 
993
  The nullcheck code value determines how any null values in the input array
 
994
  are treated.  A null value is an input pixel that is equal to tnull.  If 
 
995
  nullcheck = 0, then no checking for nulls is performed and any null values
 
996
  will be transformed just like any other pixel.  If nullcheck = 1, then the
 
997
  output pixel will be set = nullval if the corresponding input pixel is null.
 
998
  If nullcheck = 2, then if the pixel is null then the corresponding value of
 
999
  nullarray will be set to 1; the value of nullarray for non-null pixels 
 
1000
  will = 0.  The anynull parameter will be set = 1 if any of the returned
 
1001
  pixels are null, otherwise anynull will be returned with a value = 0;
 
1002
*/
 
1003
{
 
1004
    long ii;
 
1005
 
 
1006
    if (nullcheck == 0)     /* no null checking required */
 
1007
    {
 
1008
        if (scale == 1. && zero == 0.)      /* no scaling */
 
1009
        {       
 
1010
            for (ii = 0; ii < ntodo; ii++)
 
1011
                output[ii] = (float) input[ii];  /* copy input to output */
 
1012
        }
 
1013
        else             /* must scale the data */
 
1014
        {
 
1015
            for (ii = 0; ii < ntodo; ii++)
 
1016
            {
 
1017
                output[ii] = (float) (( (double) input[ii] ) * scale + zero);
 
1018
            }
 
1019
        }
 
1020
    }
 
1021
    else        /* must check for null values */
 
1022
    {
 
1023
        if (scale == 1. && zero == 0.)  /* no scaling */
 
1024
        {       
 
1025
            for (ii = 0; ii < ntodo; ii++)
 
1026
            {
 
1027
                if (input[ii] == tnull)
 
1028
                {
 
1029
                    *anynull = 1;
 
1030
                    if (nullcheck == 1)
 
1031
                        output[ii] = nullval;
 
1032
                    else
 
1033
                        nullarray[ii] = 1;
 
1034
                }
 
1035
                else
 
1036
                    output[ii] = (float) input[ii];
 
1037
            }
 
1038
        }
 
1039
        else                  /* must scale the data */
 
1040
        {
 
1041
            for (ii = 0; ii < ntodo; ii++)
 
1042
            {
 
1043
                if (input[ii] == tnull)
 
1044
                {
 
1045
                    *anynull = 1;
 
1046
                    if (nullcheck == 1)
 
1047
                        output[ii] = nullval;
 
1048
                    else
 
1049
                        nullarray[ii] = 1;
 
1050
                }
 
1051
                else
 
1052
                {
 
1053
                    output[ii] = (float) (( (double) input[ii] ) * scale + zero);
 
1054
                }
 
1055
            }
 
1056
        }
 
1057
    }
 
1058
    return(*status);
 
1059
}
 
1060
/*--------------------------------------------------------------------------*/
 
1061
int fffi2r4(short *input,         /* I - array of values to be converted     */
 
1062
            long ntodo,           /* I - number of elements in the array     */
 
1063
            double scale,         /* I - FITS TSCALn or BSCALE value         */
 
1064
            double zero,          /* I - FITS TZEROn or BZERO  value         */
 
1065
            int nullcheck,        /* I - null checking code; 0 = don't check */
 
1066
                                  /*     1:set null pixels = nullval         */
 
1067
                                  /*     2: if null pixel, set nullarray = 1 */
 
1068
            short tnull,          /* I - value of FITS TNULLn keyword if any */
 
1069
            float nullval,        /* I - set null pixels, if nullcheck = 1   */
 
1070
            char *nullarray,      /* I - bad pixel array, if nullcheck = 2   */
 
1071
            int  *anynull,        /* O - set to 1 if any pixels are null     */
 
1072
            float *output,        /* O - array of converted pixels           */
 
1073
            int *status)          /* IO - error status                       */
 
1074
/*
 
1075
  Copy input to output following reading of the input from a FITS file.
 
1076
  Check for null values and do datatype conversion and scaling if required.
 
1077
  The nullcheck code value determines how any null values in the input array
 
1078
  are treated.  A null value is an input pixel that is equal to tnull.  If 
 
1079
  nullcheck = 0, then no checking for nulls is performed and any null values
 
1080
  will be transformed just like any other pixel.  If nullcheck = 1, then the
 
1081
  output pixel will be set = nullval if the corresponding input pixel is null.
 
1082
  If nullcheck = 2, then if the pixel is null then the corresponding value of
 
1083
  nullarray will be set to 1; the value of nullarray for non-null pixels 
 
1084
  will = 0.  The anynull parameter will be set = 1 if any of the returned
 
1085
  pixels are null, otherwise anynull will be returned with a value = 0;
 
1086
*/
 
1087
{
 
1088
    long ii;
 
1089
 
 
1090
    if (nullcheck == 0)     /* no null checking required */
 
1091
    {
 
1092
        if (scale == 1. && zero == 0.)      /* no scaling */
 
1093
        {       
 
1094
            for (ii = 0; ii < ntodo; ii++)
 
1095
                output[ii] = (float) input[ii];  /* copy input to output */
 
1096
        }
 
1097
        else             /* must scale the data */
 
1098
        {
 
1099
            for (ii = 0; ii < ntodo; ii++)
 
1100
            {
 
1101
                output[ii] = (float) (input[ii] * scale + zero);
 
1102
            }
 
1103
        }
 
1104
    }
 
1105
    else        /* must check for null values */
 
1106
    {
 
1107
        if (scale == 1. && zero == 0.)  /* no scaling */
 
1108
        {       
 
1109
            for (ii = 0; ii < ntodo; ii++)
 
1110
            {
 
1111
                if (input[ii] == tnull)
 
1112
                {
 
1113
                    *anynull = 1;
 
1114
                    if (nullcheck == 1)
 
1115
                        output[ii] = nullval;
 
1116
                    else
 
1117
                        nullarray[ii] = 1;
 
1118
                }
 
1119
                else
 
1120
                    output[ii] = (float) input[ii];
 
1121
            }
 
1122
        }
 
1123
        else                  /* must scale the data */
 
1124
        {
 
1125
            for (ii = 0; ii < ntodo; ii++)
 
1126
            {
 
1127
                if (input[ii] == tnull)
 
1128
                {
 
1129
                    *anynull = 1;
 
1130
                    if (nullcheck == 1)
 
1131
                        output[ii] = nullval;
 
1132
                    else
 
1133
                        nullarray[ii] = 1;
 
1134
                }
 
1135
                else
 
1136
                {
 
1137
                    output[ii] = (float) (input[ii] * scale + zero);
 
1138
                }
 
1139
            }
 
1140
        }
 
1141
    }
 
1142
    return(*status);
 
1143
}
 
1144
/*--------------------------------------------------------------------------*/
 
1145
int fffi4r4(INT32BIT *input,      /* I - array of values to be converted     */
 
1146
            long ntodo,           /* I - number of elements in the array     */
 
1147
            double scale,         /* I - FITS TSCALn or BSCALE value         */
 
1148
            double zero,          /* I - FITS TZEROn or BZERO  value         */
 
1149
            int nullcheck,        /* I - null checking code; 0 = don't check */
 
1150
                                  /*     1:set null pixels = nullval         */
 
1151
                                  /*     2: if null pixel, set nullarray = 1 */
 
1152
            INT32BIT tnull,       /* I - value of FITS TNULLn keyword if any */
 
1153
            float nullval,        /* I - set null pixels, if nullcheck = 1   */
 
1154
            char *nullarray,      /* I - bad pixel array, if nullcheck = 2   */
 
1155
            int  *anynull,        /* O - set to 1 if any pixels are null     */
 
1156
            float *output,        /* O - array of converted pixels           */
 
1157
            int *status)          /* IO - error status                       */
 
1158
/*
 
1159
  Copy input to output following reading of the input from a FITS file.
 
1160
  Check for null values and do datatype conversion and scaling if required.
 
1161
  The nullcheck code value determines how any null values in the input array
 
1162
  are treated.  A null value is an input pixel that is equal to tnull.  If 
 
1163
  nullcheck = 0, then no checking for nulls is performed and any null values
 
1164
  will be transformed just like any other pixel.  If nullcheck = 1, then the
 
1165
  output pixel will be set = nullval if the corresponding input pixel is null.
 
1166
  If nullcheck = 2, then if the pixel is null then the corresponding value of
 
1167
  nullarray will be set to 1; the value of nullarray for non-null pixels 
 
1168
  will = 0.  The anynull parameter will be set = 1 if any of the returned
 
1169
  pixels are null, otherwise anynull will be returned with a value = 0;
 
1170
*/
 
1171
{
 
1172
    long ii;
 
1173
 
 
1174
    if (nullcheck == 0)     /* no null checking required */
 
1175
    {
 
1176
        if (scale == 1. && zero == 0.)      /* no scaling */
 
1177
        {       
 
1178
            for (ii = 0; ii < ntodo; ii++)
 
1179
                output[ii] = (float) input[ii];  /* copy input to output */
 
1180
        }
 
1181
        else             /* must scale the data */
 
1182
        {
 
1183
            for (ii = 0; ii < ntodo; ii++)
 
1184
            {
 
1185
                output[ii] = (float) (input[ii] * scale + zero);
 
1186
            }
 
1187
        }
 
1188
    }
 
1189
    else        /* must check for null values */
 
1190
    {
 
1191
        if (scale == 1. && zero == 0.)  /* no scaling */
 
1192
        {       
 
1193
            for (ii = 0; ii < ntodo; ii++)
 
1194
            {
 
1195
                if (input[ii] == tnull)
 
1196
                {
 
1197
                    *anynull = 1;
 
1198
                    if (nullcheck == 1)
 
1199
                        output[ii] = nullval;
 
1200
                    else
 
1201
                        nullarray[ii] = 1;
 
1202
                }
 
1203
                else
 
1204
                    output[ii] = (float) input[ii];
 
1205
            }
 
1206
        }
 
1207
        else                  /* must scale the data */
 
1208
        {
 
1209
            for (ii = 0; ii < ntodo; ii++)
 
1210
            {
 
1211
                if (input[ii] == tnull)
 
1212
                {
 
1213
                    *anynull = 1;
 
1214
                    if (nullcheck == 1)
 
1215
                        output[ii] = nullval;
 
1216
                    else
 
1217
                        nullarray[ii] = 1;
 
1218
                }
 
1219
                else
 
1220
                {
 
1221
                    output[ii] = (float) (input[ii] * scale + zero);
 
1222
                }
 
1223
            }
 
1224
        }
 
1225
    }
 
1226
    return(*status);
 
1227
}
 
1228
/*--------------------------------------------------------------------------*/
 
1229
int fffi8r4(LONGLONG *input,      /* I - array of values to be converted     */
 
1230
            long ntodo,           /* I - number of elements in the array     */
 
1231
            double scale,         /* I - FITS TSCALn or BSCALE value         */
 
1232
            double zero,          /* I - FITS TZEROn or BZERO  value         */
 
1233
            int nullcheck,        /* I - null checking code; 0 = don't check */
 
1234
                                  /*     1:set null pixels = nullval         */
 
1235
                                  /*     2: if null pixel, set nullarray = 1 */
 
1236
            LONGLONG tnull,       /* I - value of FITS TNULLn keyword if any */
 
1237
            float nullval,        /* I - set null pixels, if nullcheck = 1   */
 
1238
            char *nullarray,      /* I - bad pixel array, if nullcheck = 2   */
 
1239
            int  *anynull,        /* O - set to 1 if any pixels are null     */
 
1240
            float *output,        /* O - array of converted pixels           */
 
1241
            int *status)          /* IO - error status                       */
 
1242
/*
 
1243
  Copy input to output following reading of the input from a FITS file.
 
1244
  Check for null values and do datatype conversion and scaling if required.
 
1245
  The nullcheck code value determines how any null values in the input array
 
1246
  are treated.  A null value is an input pixel that is equal to tnull.  If 
 
1247
  nullcheck = 0, then no checking for nulls is performed and any null values
 
1248
  will be transformed just like any other pixel.  If nullcheck = 1, then the
 
1249
  output pixel will be set = nullval if the corresponding input pixel is null.
 
1250
  If nullcheck = 2, then if the pixel is null then the corresponding value of
 
1251
  nullarray will be set to 1; the value of nullarray for non-null pixels 
 
1252
  will = 0.  The anynull parameter will be set = 1 if any of the returned
 
1253
  pixels are null, otherwise anynull will be returned with a value = 0;
 
1254
*/
 
1255
{
 
1256
    long ii;
 
1257
 
 
1258
    if (nullcheck == 0)     /* no null checking required */
 
1259
    {
 
1260
        if (scale == 1. && zero == 0.)      /* no scaling */
 
1261
        {       
 
1262
            for (ii = 0; ii < ntodo; ii++)
 
1263
                output[ii] = (float) input[ii];  /* copy input to output */
 
1264
        }
 
1265
        else             /* must scale the data */
 
1266
        {
 
1267
            for (ii = 0; ii < ntodo; ii++)
 
1268
            {
 
1269
                output[ii] = (float) (input[ii] * scale + zero);
 
1270
            }
 
1271
        }
 
1272
    }
 
1273
    else        /* must check for null values */
 
1274
    {
 
1275
        if (scale == 1. && zero == 0.)  /* no scaling */
 
1276
        {       
 
1277
            for (ii = 0; ii < ntodo; ii++)
 
1278
            {
 
1279
                if (input[ii] == tnull)
 
1280
                {
 
1281
                    *anynull = 1;
 
1282
                    if (nullcheck == 1)
 
1283
                        output[ii] = nullval;
 
1284
                    else
 
1285
                        nullarray[ii] = 1;
 
1286
                }
 
1287
                else
 
1288
                    output[ii] = (float) input[ii];
 
1289
            }
 
1290
        }
 
1291
        else                  /* must scale the data */
 
1292
        {
 
1293
            for (ii = 0; ii < ntodo; ii++)
 
1294
            {
 
1295
                if (input[ii] == tnull)
 
1296
                {
 
1297
                    *anynull = 1;
 
1298
                    if (nullcheck == 1)
 
1299
                        output[ii] = nullval;
 
1300
                    else
 
1301
                        nullarray[ii] = 1;
 
1302
                }
 
1303
                else
 
1304
                {
 
1305
                    output[ii] = (float) (input[ii] * scale + zero);
 
1306
                }
 
1307
            }
 
1308
        }
 
1309
    }
 
1310
    return(*status);
 
1311
}
 
1312
/*--------------------------------------------------------------------------*/
 
1313
int fffr4r4(float *input,         /* I - array of values to be converted     */
 
1314
            long ntodo,           /* I - number of elements in the array     */
 
1315
            double scale,         /* I - FITS TSCALn or BSCALE value         */
 
1316
            double zero,          /* I - FITS TZEROn or BZERO  value         */
 
1317
            int nullcheck,        /* I - null checking code; 0 = don't check */
 
1318
                                  /*     1:set null pixels = nullval         */
 
1319
                                  /*     2: if null pixel, set nullarray = 1 */
 
1320
            float nullval,        /* I - set null pixels, if nullcheck = 1   */
 
1321
            char *nullarray,      /* I - bad pixel array, if nullcheck = 2   */
 
1322
            int  *anynull,        /* O - set to 1 if any pixels are null     */
 
1323
            float *output,        /* O - array of converted pixels           */
 
1324
            int *status)          /* IO - error status                       */
 
1325
/*
 
1326
  Copy input to output following reading of the input from a FITS file.
 
1327
  Check for null values and do datatype conversion and scaling if required.
 
1328
  The nullcheck code value determines how any null values in the input array
 
1329
  are treated.  A null value is an input pixel that is equal to NaN.  If 
 
1330
  nullcheck = 0, then no checking for nulls is performed and any null values
 
1331
  will be transformed just like any other pixel.  If nullcheck = 1, then the
 
1332
  output pixel will be set = nullval if the corresponding input pixel is null.
 
1333
  If nullcheck = 2, then if the pixel is null then the corresponding value of
 
1334
  nullarray will be set to 1; the value of nullarray for non-null pixels 
 
1335
  will = 0.  The anynull parameter will be set = 1 if any of the returned
 
1336
  pixels are null, otherwise anynull will be returned with a value = 0;
 
1337
*/
 
1338
{
 
1339
    long ii;
 
1340
    short *sptr, iret;
 
1341
 
 
1342
    if (nullcheck == 0)     /* no null checking required */
 
1343
    {
 
1344
        if (scale == 1. && zero == 0.)      /* no scaling */
 
1345
        {       
 
1346
            memcpy(output, input, ntodo * sizeof(float) );
 
1347
        }
 
1348
        else             /* must scale the data */
 
1349
        {
 
1350
            for (ii = 0; ii < ntodo; ii++)
 
1351
            {
 
1352
                output[ii] = (float) (input[ii] * scale + zero);
 
1353
            }
 
1354
        }
 
1355
    }
 
1356
    else        /* must check for null values */
 
1357
    {
 
1358
        sptr = (short *) input;
 
1359
 
 
1360
#if BYTESWAPPED && MACHINE != VAXVMS && MACHINE != ALPHAVMS
 
1361
        sptr++;       /* point to MSBs */
 
1362
#endif
 
1363
 
 
1364
        if (scale == 1. && zero == 0.)  /* no scaling */
 
1365
        {       
 
1366
            for (ii = 0; ii < ntodo; ii++, sptr += 2)
 
1367
            {
 
1368
              if (0 != (iret = fnan(*sptr) ) )  /* test for NaN or underflow */
 
1369
              {
 
1370
                  if (iret == 1)  /* is it a NaN? */
 
1371
                  {
 
1372
                    *anynull = 1;
 
1373
                    if (nullcheck == 1)
 
1374
                        output[ii] = nullval;
 
1375
                    else
 
1376
                    {
 
1377
                        nullarray[ii] = 1;
 
1378
                       /* explicitly set value in case output contains a NaN */
 
1379
                        output[ii] = FLOATNULLVALUE;
 
1380
                    }
 
1381
                  }
 
1382
                  else            /* it's an underflow */
 
1383
                     output[ii] = 0;
 
1384
              }
 
1385
              else
 
1386
                output[ii] = input[ii];
 
1387
            }
 
1388
        }
 
1389
        else                  /* must scale the data */
 
1390
        {
 
1391
            for (ii = 0; ii < ntodo; ii++, sptr += 2)
 
1392
            {
 
1393
              if (0 != (iret = fnan(*sptr) ) )  /* test for NaN or underflow */
 
1394
              {
 
1395
                  if (iret == 1)  /* is it a NaN? */
 
1396
                  {  
 
1397
                    *anynull = 1;
 
1398
                    if (nullcheck == 1)
 
1399
                        output[ii] = nullval;
 
1400
                    else
 
1401
                    {
 
1402
                        nullarray[ii] = 1;
 
1403
                       /* explicitly set value in case output contains a NaN */
 
1404
                        output[ii] = FLOATNULLVALUE;
 
1405
                    }
 
1406
                  }
 
1407
                  else            /* it's an underflow */
 
1408
                     output[ii] = (float) zero;
 
1409
              }
 
1410
              else
 
1411
                  output[ii] = (float) (input[ii] * scale + zero);
 
1412
            }
 
1413
        }
 
1414
    }
 
1415
    return(*status);
 
1416
}
 
1417
/*--------------------------------------------------------------------------*/
 
1418
int fffr8r4(double *input,        /* I - array of values to be converted     */
 
1419
            long ntodo,           /* I - number of elements in the array     */
 
1420
            double scale,         /* I - FITS TSCALn or BSCALE value         */
 
1421
            double zero,          /* I - FITS TZEROn or BZERO  value         */
 
1422
            int nullcheck,        /* I - null checking code; 0 = don't check */
 
1423
                                  /*     1:set null pixels = nullval         */
 
1424
                                  /*     2: if null pixel, set nullarray = 1 */
 
1425
            float nullval,        /* I - set null pixels, if nullcheck = 1   */
 
1426
            char *nullarray,      /* I - bad pixel array, if nullcheck = 2   */
 
1427
            int  *anynull,        /* O - set to 1 if any pixels are null     */
 
1428
            float *output,        /* O - array of converted pixels           */
 
1429
            int *status)          /* IO - error status                       */
 
1430
/*
 
1431
  Copy input to output following reading of the input from a FITS file.
 
1432
  Check for null values and do datatype conversion and scaling if required.
 
1433
  The nullcheck code value determines how any null values in the input array
 
1434
  are treated.  A null value is an input pixel that is equal to NaN.  If 
 
1435
  nullcheck = 0, then no checking for nulls is performed and any null values
 
1436
  will be transformed just like any other pixel.  If nullcheck = 1, then the
 
1437
  output pixel will be set = nullval if the corresponding input pixel is null.
 
1438
  If nullcheck = 2, then if the pixel is null then the corresponding value of
 
1439
  nullarray will be set to 1; the value of nullarray for non-null pixels 
 
1440
  will = 0.  The anynull parameter will be set = 1 if any of the returned
 
1441
  pixels are null, otherwise anynull will be returned with a value = 0;
 
1442
*/
 
1443
{
 
1444
    long ii;
 
1445
    short *sptr, iret;
 
1446
 
 
1447
    if (nullcheck == 0)     /* no null checking required */
 
1448
    {
 
1449
        if (scale == 1. && zero == 0.)      /* no scaling */
 
1450
        {       
 
1451
            for (ii = 0; ii < ntodo; ii++)
 
1452
                output[ii] = (float) input[ii]; /* copy input to output */
 
1453
        }
 
1454
        else             /* must scale the data */
 
1455
        {
 
1456
            for (ii = 0; ii < ntodo; ii++)
 
1457
            {
 
1458
                output[ii] = (float) (input[ii] * scale + zero);
 
1459
            }
 
1460
        }
 
1461
    }
 
1462
    else        /* must check for null values */
 
1463
    {
 
1464
        sptr = (short *) input;
 
1465
 
 
1466
#if BYTESWAPPED && MACHINE != VAXVMS && MACHINE != ALPHAVMS
 
1467
        sptr += 3;       /* point to MSBs */
 
1468
#endif
 
1469
        if (scale == 1. && zero == 0.)  /* no scaling */
 
1470
        {       
 
1471
            for (ii = 0; ii < ntodo; ii++, sptr += 4)
 
1472
            {
 
1473
              if (0 != (iret = dnan(*sptr)) )  /* test for NaN or underflow */
 
1474
              {
 
1475
                  if (iret == 1)  /* is it a NaN? */
 
1476
                  {
 
1477
                    *anynull = 1;
 
1478
                    if (nullcheck == 1)
 
1479
                        output[ii] = nullval;
 
1480
                    else
 
1481
                        nullarray[ii] = 1;
 
1482
                  }
 
1483
                  else            /* it's an underflow */
 
1484
                     output[ii] = 0;
 
1485
              }
 
1486
              else
 
1487
                  output[ii] = (float) input[ii];
 
1488
            }
 
1489
        }
 
1490
        else                  /* must scale the data */
 
1491
        {
 
1492
            for (ii = 0; ii < ntodo; ii++, sptr += 4)
 
1493
            {
 
1494
              if (0 != (iret = dnan(*sptr)) )  /* test for NaN or underflow */
 
1495
              {
 
1496
                  if (iret == 1)  /* is it a NaN? */
 
1497
                  {  
 
1498
                    *anynull = 1;
 
1499
                    if (nullcheck == 1)
 
1500
                        output[ii] = nullval;
 
1501
                    else
 
1502
                        nullarray[ii] = 1;
 
1503
                  }
 
1504
                  else            /* it's an underflow */
 
1505
                     output[ii] = (float) zero;
 
1506
              }
 
1507
              else
 
1508
                  output[ii] = (float) (input[ii] * scale + zero);
 
1509
            }
 
1510
        }
 
1511
    }
 
1512
    return(*status);
 
1513
}
 
1514
/*--------------------------------------------------------------------------*/
 
1515
int fffstrr4(char *input,         /* I - array of values to be converted     */
 
1516
            long ntodo,           /* I - number of elements in the array     */
 
1517
            double scale,         /* I - FITS TSCALn or BSCALE value         */
 
1518
            double zero,          /* I - FITS TZEROn or BZERO  value         */
 
1519
            long twidth,          /* I - width of each substring of chars    */
 
1520
            double implipower,    /* I - power of 10 of implied decimal      */
 
1521
            int nullcheck,        /* I - null checking code; 0 = don't check */
 
1522
                                  /*     1:set null pixels = nullval         */
 
1523
                                  /*     2: if null pixel, set nullarray = 1 */
 
1524
            char  *snull,         /* I - value of FITS null string, if any   */
 
1525
            float nullval,        /* I - set null pixels, if nullcheck = 1   */
 
1526
            char *nullarray,      /* I - bad pixel array, if nullcheck = 2   */
 
1527
            int  *anynull,        /* O - set to 1 if any pixels are null     */
 
1528
            float *output,        /* O - array of converted pixels           */
 
1529
            int *status)          /* IO - error status                       */
 
1530
/*
 
1531
  Copy input to output following reading of the input from a FITS file. Check
 
1532
  for null values and do scaling if required. The nullcheck code value
 
1533
  determines how any null values in the input array are treated. A null
 
1534
  value is an input pixel that is equal to snull.  If nullcheck= 0, then
 
1535
  no special checking for nulls is performed.  If nullcheck = 1, then the
 
1536
  output pixel will be set = nullval if the corresponding input pixel is null.
 
1537
  If nullcheck = 2, then if the pixel is null then the corresponding value of
 
1538
  nullarray will be set to 1; the value of nullarray for non-null pixels 
 
1539
  will = 0.  The anynull parameter will be set = 1 if any of the returned
 
1540
  pixels are null, otherwise anynull will be returned with a value = 0;
 
1541
*/
 
1542
{
 
1543
    int nullen;
 
1544
    long ii;
 
1545
    double dvalue;
 
1546
    char *cstring, message[81];
 
1547
    char *cptr, *tpos;
 
1548
    char tempstore, chrzero = '0';
 
1549
    double val, power;
 
1550
    int exponent, sign, esign, decpt;
 
1551
 
 
1552
    nullen = strlen(snull);
 
1553
    cptr = input;  /* pointer to start of input string */
 
1554
    for (ii = 0; ii < ntodo; ii++)
 
1555
    {
 
1556
      cstring = cptr;
 
1557
      /* temporarily insert a null terminator at end of the string */
 
1558
      tpos = cptr + twidth;
 
1559
      tempstore = *tpos;
 
1560
      *tpos = 0;
 
1561
 
 
1562
      /* check if null value is defined, and if the    */
 
1563
      /* column string is identical to the null string */
 
1564
      if (snull[0] != ASCII_NULL_UNDEFINED && 
 
1565
         !strncmp(snull, cptr, nullen) )
 
1566
      {
 
1567
        if (nullcheck)  
 
1568
        {
 
1569
          *anynull = 1;    
 
1570
          if (nullcheck == 1)
 
1571
            output[ii] = nullval;
 
1572
          else
 
1573
            nullarray[ii] = 1;
 
1574
        }
 
1575
        cptr += twidth;
 
1576
      }
 
1577
      else
 
1578
      {
 
1579
        /* value is not the null value, so decode it */
 
1580
        /* remove any embedded blank characters from the string */
 
1581
 
 
1582
        decpt = 0;
 
1583
        sign = 1;
 
1584
        val  = 0.;
 
1585
        power = 1.;
 
1586
        exponent = 0;
 
1587
        esign = 1;
 
1588
 
 
1589
        while (*cptr == ' ')               /* skip leading blanks */
 
1590
           cptr++;
 
1591
 
 
1592
        if (*cptr == '-' || *cptr == '+')  /* check for leading sign */
 
1593
        {
 
1594
          if (*cptr == '-')
 
1595
             sign = -1;
 
1596
 
 
1597
          cptr++;
 
1598
 
 
1599
          while (*cptr == ' ')         /* skip blanks between sign and value */
 
1600
            cptr++;
 
1601
        }
 
1602
 
 
1603
        while (*cptr >= '0' && *cptr <= '9')
 
1604
        {
 
1605
          val = val * 10. + *cptr - chrzero;  /* accumulate the value */
 
1606
          cptr++;
 
1607
 
 
1608
          while (*cptr == ' ')         /* skip embedded blanks in the value */
 
1609
            cptr++;
 
1610
        }
 
1611
 
 
1612
        if (*cptr == '.' || *cptr == ',')       /* check for decimal point */
 
1613
        {
 
1614
          decpt = 1;       /* set flag to show there was a decimal point */
 
1615
          cptr++;
 
1616
          while (*cptr == ' ')         /* skip any blanks */
 
1617
            cptr++;
 
1618
 
 
1619
          while (*cptr >= '0' && *cptr <= '9')
 
1620
          {
 
1621
            val = val * 10. + *cptr - chrzero;  /* accumulate the value */
 
1622
            power = power * 10.;
 
1623
            cptr++;
 
1624
 
 
1625
            while (*cptr == ' ')         /* skip embedded blanks in the value */
 
1626
              cptr++;
 
1627
          }
 
1628
        }
 
1629
 
 
1630
        if (*cptr == 'E' || *cptr == 'D')  /* check for exponent */
 
1631
        {
 
1632
          cptr++;
 
1633
          while (*cptr == ' ')         /* skip blanks */
 
1634
              cptr++;
 
1635
  
 
1636
          if (*cptr == '-' || *cptr == '+')  /* check for exponent sign */
 
1637
          {
 
1638
            if (*cptr == '-')
 
1639
               esign = -1;
 
1640
 
 
1641
            cptr++;
 
1642
 
 
1643
            while (*cptr == ' ')        /* skip blanks between sign and exp */
 
1644
              cptr++;
 
1645
          }
 
1646
 
 
1647
          while (*cptr >= '0' && *cptr <= '9')
 
1648
          {
 
1649
            exponent = exponent * 10 + *cptr - chrzero;  /* accumulate exp */
 
1650
            cptr++;
 
1651
 
 
1652
            while (*cptr == ' ')         /* skip embedded blanks */
 
1653
              cptr++;
 
1654
          }
 
1655
        }
 
1656
 
 
1657
        if (*cptr  != 0)  /* should end up at the null terminator */
 
1658
        {
 
1659
          sprintf(message, "Cannot read number from ASCII table");
 
1660
          ffpmsg(message);
 
1661
          sprintf(message, "Column field = %s.", cstring);
 
1662
          ffpmsg(message);
 
1663
          /* restore the char that was overwritten by the null */
 
1664
          *tpos = tempstore;
 
1665
          return(*status = BAD_C2D);
 
1666
        }
 
1667
 
 
1668
        if (!decpt)  /* if no explicit decimal, use implied */
 
1669
           power = implipower;
 
1670
 
 
1671
        dvalue = (sign * val / power) * pow(10., (double) (esign * exponent));
 
1672
 
 
1673
        output[ii] = (float) (dvalue * scale + zero);   /* apply the scaling */
 
1674
 
 
1675
      }
 
1676
      /* restore the char that was overwritten by the null */
 
1677
      *tpos = tempstore;
 
1678
    }
 
1679
    return(*status);
 
1680
}