Viewing contents of file '../idllib/iuedac/iuelib/pro/addcom.pro'
;************************************************************************
;+
;*NAME:
;
;  	ADDCOM      8/6/93
;  
;*CLASS:
;
;	File Conversion 
;  
;*CATEGORY:
;  
;*PURPOSE:
;
;       Adds information stored in input text file to the input FITS header.
;  
;*CALLING SEQUENCE:
;
;  	ADDCOM,HEADER,FNAME,KEYW,newhd
;  
;*PARAMETERS:
;
;       HEADER  (REQ) (IO) (1) (S)
;               FITS header to be updated. Existing entries are 
;               preserved and text from FNAME is added.
;
;       FNAME   (REQ) (I) (0) (S)
;               full name of input text file. The 1st 72 bytes from each line
;               will be extracted, appended with the FIT keyword KEYW, and
;               added to HEADER.
;
;       KEYW    (REQ) (I) (0) (S)
;               Keyword to precede ascii extracted from fname.
;
;       NEWHD   (OPT) (O) (1) (S)
;               If specified, output header is written to NEWHD rather
;               than input header.
;                
;
;*SYSTEM VARIABLES USED:
;
;	none
;  
;*INTERACTIVE INPUT:
;  
;*SUBROUTINES CALLED:
;
;    	PARCHECK
;  
;*FILES USED:
;  
;        FNAME - input text file.
;  
;*SIDE EFFECTS:
;  
;*RESTRICTIONS:
;  
;*NOTES:
;
;*PROCEDURE:
;
;        Reads FNAME, extract 72 bytes from each line, adds KEYW and
;        append to HEADER. Original END keyword is deleted from HEADER 
;        and appended after text from FNAME.
;  
;*I_HELP nn:
;  
;*EXAMPLES:
;  
;*MODIFICATION HISTORY:
;
;      	Written by R. Thompson 8/6/93
;
;-
;************************************************************************
 pro addcom,header,fname,keyw,newhd
;
 npar = n_params(0)
 if npar eq 0 then begin
    print,' ADDCOM,HEADER,FNAME,KEYW,newhd'
    retall
 endif  ; npar
 parcheck,npar,[2,3,4],'ADDCOM'
;
; initialize parameters
;
a = ''
i = 0
hd = strarr(900)                     ; one fits record of keywords
hform = string(bytarr(80) + 32b)
endkw = hform 
strput,endkw,'END',0
;
; read text file 
; add KEYW keyword to each line and 'END' at end
;
openr,lu1,fname,/get_lun
;hform = string(bytarr(80) + 32b)
strput,hform,strupcase(keyw),0
while not eof(lu1) do begin
    tempa = hform
    readf,lu1,a
    strput,tempa,a,9                       ; store in string array
    hd(i) = tempa
    i = i + 1
endwhile  ; not eof
free_lun,lu1
hd(i) = endkw
;
; merge with input header
; remove END keyword first and add at end
;
n1 = n_elements(header)
tot = n1 + i + 2
newhd = strarr(tot)
newhd(0) = header
delpar,newhd,'END'
newhd(n1) = hd(0:i)
;
; write new header over input header
;
if (npar lt 4) then header = newhd
;
return  
end  ; addcom