pro rd_global,jd,nfilt,filters,gparms,geparms,chipz,ascolor,xglob,zdb=zdb
; This routine opens the file ZDBASE/survey/glob_parms?.asc,
; where ? = [1,2,3] depending on the camera being used at the time, and hence
; on the input Julian date jd.  The routine then reads from the file
; the values of the global magnitude-fitting parameters for each filter.
; On return,
;  nfilt = number of filters for which there are data
;  filters = string array containing names of the filters, left justified
;            and blank-padded to 9 characters length
;  gparms(2,nfilt) = global fitting parameters:
;                    gparms(0,*) = transformation constants, ie, term
;                          proportional to nearby color
;                    gparms(1,*) = 2nd-order color coeffs.
;  geparms(2,nfilt) = default extinction parameters, for use when fits
;                   are not available.
;                    geparms(0,*) = zero-point correction
;                    geparms(1,*) = color-independent extinction correction
;  chipz(3,nfilt) = corrections to chip zero points for each color,
;                   for chips 2,3,4 relative to chip 1
;  ascolor(nfilt) = typical nearby color for randomly-chosen stars.
;  xglob = typical airmass value for our observations

;constants
zdbase=getenv('ZDBASE')
if(keyword_set(zdb)) then zdbase=zdb
gfilepre=zdbase+'/survey/glob_parms'
gfilepost='.asc'
                                                                                
; make the filename
scam=strtrim(string(icamera(jd)),2)
gfile=gfilepre+scam+gfilepost

; read the data
openr,iun,gfile,/get_lun
readf,iun,nfilt
nfilt=fix(nfilt)
filters=strarr(nfilt)
gparms=fltarr(2,nfilt)
geparms=fltarr(2,nfilt)
ascolor=fltarr(nfilt)
chipz=fltarr(3,nfilt)
ss=''

readf,iun,xglob

for i=0,nfilt-1 do begin
  readf,iun,ss,format='(1a9)'
  readf,iun,v1,v2
  readf,iun,w1,w2
  readf,iun,u1,u2,u3
  readf,iun,v3
  filters(i)=ss
  gparms(*,i)=[v1,v2]
  geparms(*,i)=[w1,w2]
  ascolor(i)=v3
  chipz(*,i)=[u1,u2,u3]
endfor

close,iun
free_lun,iun

end