C---------------------------------------------------------------------- subroutine ftgcli(iunit,colnum,frow,felem,nelem,eincr, & nultyp,nulval,array,flgval,anynul,status) C read an array of integer*2 data values from the specified column of C the table. C This general purpose routine will handle null values in one C of two ways: if nultyp=1, then undefined array elements will be C set equal to the input value of NULVAL. Else if nultyp=2, then C undefined array elements will have the corresponding FLGVAL element C set equal to .TRUE. If NULTYP=1 and NULVAL=0, then no checks for C undefined values will be made, for maximum efficiency. C iunit i fortran unit number C colnum i number of the column to read from C frow i first row to read C felem i first element within the row to read C nelem i number of elements to read C eincr i element increment C nultyp i input code indicating how to handle undefined values C nulval i*2 value that undefined pixels will be set to (if nultyp=1) C array i*2 array of data values that are read from the FITS file C flgval l set .true. if corresponding element undefined (if nultyp=2) C anynul l set to .true. if any of the returned values are undefined C status i output error status C C written by Wm Pence, HEASARC/GSFC, June 1991 integer iunit,colnum,frow,felem,nelem,eincr,nultyp,status integer*2 array(*),nulval logical flgval(*),anynul integer ibuff,twidth,tcode,maxpix,startp integer estart,incre,repeat,lenrow,hdtype integer nulchk,i4null,rskip integer bstart,i1,ntodo,itodo,rstart,ival double precision scale,zero,dval logical tofits,trans integer*2 i2null character sval*30,sform*13,snull*16,i1null*1,messge*80 integer maxi2,mini2 double precision i2max,i2min parameter (i2max=3.276749D+04) parameter (i2min=-3.276849D+04) parameter (maxi2=32767) parameter (mini2=-32768) character*1 chbuff(32000) common/ftheap/chbuff integer buffer(8000) common/fttemp/buffer if (status .gt. 0)return call ftgcpr(iunit,colnum,frow,felem,nelem,0, & ibuff,scale,zero,sform,twidth,tcode,maxpix,startp, & estart,incre,repeat,lenrow,hdtype,i4null,snull,status) if (status .gt. 0 .or. nelem .eq. 0)return C multiply incre to just get every nth pixel incre = incre * eincr C determine if we have to check for null values nulchk = nultyp if (nultyp .eq. 1 .and. nulval .eq. 0)then C user doesn't want to check for nulls nulchk=0 else C user does want to check for null values if (tcode .le. 41)then C check if null value is defined for integer column if (i4null .eq. 123454321)then nulchk=0 else if (tcode .eq. 11)then i1null=char(i4null) else if (tcode .eq. 21)then i2null=i4null end if end if end if end if C check for important special case: no datatype conversion required if (tcode .eq. 21 .and. nulchk .eq. 0 .and. & scale .eq. 1.D00 .and. zero .eq. 0.D00)then trans=.false. else trans=.true. end if sval=' ' i1=1 ntodo=nelem rstart=0 anynul=.false. C the data are being scaled from FITS to internal format tofits=.false. C process as many contiguous pixels as possible, up to buffer size 20 itodo=min(ntodo,(repeat-estart-1)/eincr+1,maxpix) C move the i/o pointer to the start of the sequence of pixels bstart=startp+(rstart * lenrow) + (estart * incre / eincr) call ftmbyt(iunit,bstart,.false.,status) C read the data from FITS file, doing datatype conversion and scaling if (tcode .eq. 21)then C column data type is I (I*2) C read the data and do any machine dependent data conversion C note that we can use the input array directly call ftgi2b(iunit,itodo,incre,array(i1),status) C check for null values, and do scaling and datatype conversion if (trans)then call fti2i2(array(i1),itodo,scale,zero,tofits,nulchk, & i2null,nulval,flgval(i1),anynul,array(i1),status) end if else if (tcode .eq. 41)then C column data type is J (I*4) C read the data and do any machine dependent data conversion call ftgi4b(iunit,itodo,incre,buffer,status) C check for null values, and do scaling and datatype conversion call fti4i2(buffer,itodo,scale,zero,tofits, & nulchk,i4null,nulval,flgval(i1),anynul,array(i1),status) else if (tcode .eq. 42)then C column data type is E (R*4) C read the data and do any machine dependent data conversion call ftgr4b(iunit,itodo,incre,buffer,status) C check for null values, and do scaling and datatype conversion call ftr4i2(buffer,itodo,scale,zero,tofits, & nulchk,nulval,flgval(i1),anynul,array(i1),status) else if (tcode .eq. 82)then C column data type is D (R*8) C read the data and do any machine dependent data conversion call ftgr8b(iunit,itodo,incre,buffer,status) C check for null values, and do scaling and datatype conversion call ftr8i2(buffer,itodo,scale,zero,tofits, & nulchk,nulval,flgval(i1),anynul,array(i1),status) else if (tcode .eq. 11)then C column data type is B (byte) C read the data and do any machine dependent data conversion call ftgi1b(iunit,itodo,incre,chbuff,status) C check for null values, and do scaling and datatype conversion call fti1i2(chbuff,itodo,scale,zero,tofits, & nulchk,i1null,nulval,flgval(i1),anynul,array(i1),status) else C this is an ASCII table column; get the character string call ftgcbf(iunit,twidth,sval,status) if (status .gt. 0)return C check for null value if (sval(1:16) .eq. snull)then anynul=.true. if (nultyp .eq. 1)then array(i1)=nulval else if (nultyp .eq. 2)then flgval(i1)=.true. end if else C read the value, then do scaling and datatype conversion if (sform(5:5) .eq. 'I')then read(sval,sform,err=900)ival dval=ival*scale+zero else read(sval,sform,err=900)dval dval=dval*scale+zero end if C trap any values that overflow the I*2 range if (dval .lt. i2max .and. dval .gt. i2min)then array(i1)=dval else if (dval .ge. i2max)then status=-11 array(i1)=maxi2 else status=-11 array(i1)=mini2 end if end if end if C find number of pixels left to do, and quit if none left ntodo=ntodo-itodo if (status .gt. 0)then write(messge,1001)i1,i1+itodo-1 1001 format('Error reading elements',i9,' thru',i9, & ' of data array (FTGCLI).') call ftpmsg(messge) return end if if (ntodo .gt. 0)then C increment the pointers i1=i1+itodo estart=estart+itodo*eincr if (estart .ge. repeat)then rskip=estart/repeat rstart=rstart+rskip estart=estart-rskip*repeat end if go to 20 end if C check for any overflows if (status .eq. -11)then status=412 messge='Numerical overflow during type '// & 'conversion while reading FITS data.' call ftpmsg(messge) end if return 900 continue C error reading formatted data value from ASCII table write(messge,1002)colnum,rstart+frow 1002 format('Error reading column',i4,', row',i9, & ' of the ASCII Table.') call ftpmsg(messge) call ftpmsg('Tried to read value with format '//sform) status=315 end