PRO reafits,fil,ar,hea,swap=swap ; ; This procedure should read 1D-3D FITS files stored ; ONLY as BYTE (8) or INTEGER (16) data type. ; Preliminary version, 16 Nov 93, Michal ; 1 and 3D arrays enabled, automatic read, 9 Jul 01, Michal ; Long headers (multiples of 2880) allowed, 10 Dec 01, Michal ; ;INPUT: FITS file with filename 'FIL' ;OUTPUTS: data array AR, header string HEA (optional) ;KEYWORD: SWAP - byte swapping ;EXAMPLES: ; REAFITS,'file.fits',array ; REAFITS,'file.fits',array,/swap ; REAFITS,'file.fits',array,header ; REAFITS,'file.fits',array,header,/swap on_error,1 ;reading header - how many 2880B blocks? Looking for END keyword openr,1,fil he=bytarr(2880) mult=0 readhead: mult=mult+1 if mult gt 10 then begin print,'No "END" found in the header' print,'Try a simple 2880 header (y) or give up (n) ?' if get_kbrd(1) eq 'y' then begin mult=1 goto,readall endif else begin close,1 message,'GIVING UP' endelse endif readu,1,he if strpos(string(he),'END') lt 0 then goto,readhead ; print,'Header',mult,' * 2880 B long' ;comment when working OK ; readall: close,1 ;reading complete header ... and the rest openr,1,fil he=bytarr(mult*2880) readu,1,he hea=strcompress(string(he)) ; print,hea ;comment when working OK ; bi=strpos(hea,'BITPIX') sb=strmid(hea,bi+9,2) bi=fix(sb) if bi ne 8 and bi ne 16 then message,'This is not BYTE or INTEGER !!' nax=strpos(hea,'NAXIS') sn=strmid(hea,nax+8,1) nax=fix(sn) if nax lt 1 or nax gt 3 then message,'NAXIS differs from 1,2,3 !!' n1=strpos(hea,'NAXIS1') sn1=strmid(hea,n1+9,4) n1=fix(sn1) if nax eq 2 or nax eq 3 then begin n2=strpos(hea,'NAXIS2') sn2=strmid(hea,n2+9,4) n2=fix(sn2) endif if nax eq 3 then begin n3=strpos(hea,'NAXIS3') sn3=strmid(hea,n3+9,4) n3=fix(sn3) endif ;defining data array if nax eq 1 then $ if bi eq 8 then ar=bytarr(n1) else ar=intarr(n1) if nax eq 2 then $ if bi eq 8 then ar=bytarr(n1,n2) else ar=intarr(n1,n2) if nax eq 3 then $ if bi eq 8 then ar=bytarr(n1,n2,n3) else ar=intarr(n1,n2,n3) readu,1,ar ;reading data close,1 if keyword_set(swap) then byteorder,ar END