function den2standard, den, red=red, day=day, plot=plot, new=new, $ reset=reset, logt=logt, noback=noback @compile_opt.pro ; On error, return to caller ;+ ; NAME: ; DEN2STANDARD ; PURPOSE: ; Calculates the exposure time needed to produce a specified density on ; a standard image. ; CALLING SEQUENCE: ; result = den2standard, den, red=red, day=day, plot=plot, new=new, $ ; reset=reset, logt=logt, noback=noback ; INPUTS: ; den array of density values to be converted to standard exposure ; times ; /red indicates red line densities (default is green line) ; day=day standard conversions are available for DOY 285 and 294. ; `day' selects which conversion is to be used ; /plot plot the conversion results ; /new display in new window (fed to TWIN) ; /reset reread the file `standard.txt' containing the conversion ; data (read automatically the first time, or whenever the ; logt or noback setting is different from the previous call) ; /logt the standard conversion data are by default fitted by a ; natural spline to t (exposure) and d (density). ; if /logt is set the fit is to log(t) and d ; /noback by default a background fog is subtracted from each of the ; standard images (slightly different for each image) before ; doing the interpolation. Setting `noback' suppresses this ; background subtraction (equivalent to using a constant ; for all standard images used in the calibration. ; OUTPUTS: ; result array of standard exposure times ; CALLS: ; nr_splint, nr_spline ; PROCEDURE: ; > the returned times are the exposure times needed to produce the ; input densities in a standard image ; > the exposure times are obtained by interpolated between calibration ; data obtained from a sequence of standard images at exposures of ; 2,4,8,16 and 32 sec. ; > the calibration data for two days (DOY 285 and 294 are stored in the ; file x$aux:standard.txt ; MODIFICATION HISTORY: ; APR-1995, Paul Hick (UCSD) ; COMMON BLOCKS: common savestandards, d285g, d294g, d285r, d294r, $ b285g, b294g, b285r, b294r, $ t285g, t294g, t285r, t294r, $ y285g, y294g, y285r, y294r, logtnow, backnow ;- red = keyword_set(red) plot = keyword_set(plot) reset = keyword_set(reset) logt = keyword_set(logt) back = 1-keyword_set(noback) if n_elements(logtnow) eq 0 then logtnow = 0 if n_elements(backnow) eq 0 then backnow = 0 if n_elements(day) eq 0 then day = 294 if (where(day eq [285,294]))(0) eq -1 then begin help, day message, 'standards only available for DOY 285 and 294 endif if n_elements(t285g) eq 0 or reset or logt ne logtnow or back ne backnow then begin stat = flt_read( filepath(root=getenv('SYS'),'standard.txt'),a,/silent) t285g = a(1, 0: 3) t294g = a(1, 4: 7) t285r = a(1, 9:12) t294r = a(1,13:14) if logt then begin t285g = alog10(t285g) t294g = alog10(t294g) t285r = alog10(t285r) t294r = alog10(t294r) endif b285g = back*a(8, 0: 3) b294g = back*a(8, 4: 7) b285r = back*a(8, 9:12) b294r = back*a(8,13:14) d285g = a(6, 0: 3) d294g = a(6, 4: 7) d285r = a(6, 9:12) d294r = a(6,13:14) y285g = nr_spline(d285g-b285g,t285g) y294g = nr_spline(d294g-b294g,t294g) y285r = nr_spline(d285r-b285r,t285r) y294r = nr_spline(d294r-b294r,t294r) logtnow = logt backnow = back endif case red of 0: begin case day of 285: begin d = d285g & b = b285g & t = t285g & y2 = y285g & end 294: begin d = d294g & b = b294g & t = t294g & y2 = y294g & end endcase end 1: begin case day of 285: begin d = d285r & b = b285r & t = t285r & y2 = y285r & end 294: begin d = d294r & b = b294r & t = t294r & y2 = y294r & end endcase end endcase bav = total(b)/n_elements(b) tden = nr_splint(d-b,t,y2,den-bav) if logtnow then tden = 10^tden if plot then begin dmin = min(den-bav,nmin) & dmax = max(den-bav,nmax) twin,/show,xs=300,ys=300,new=new xr = [min([min(d-b),dmin]),max([max(d-b),dmax])] ds = xr(0)+(xr(1)-xr(0))/100.*findgen(101) ts = nr_splint(d-b,t,y2,ds) & if logtnow then ts = 10^ts plot,ds,ts,/ynozero,xrange=xr,xst=1,xtitle='density',ytitle='exposure', $ title=(['GREEN','RED'])(red)+', DOY '+strcompress(day,/rem) ts = t & if logtnow then ts = 10^ts & oplot,d-b,ts,psym=1 n = n_elements(tden) & nlim = 10 if n lt nlim then $ n = indgen(n) $ else $ n = ((n/nlim)*lindgen(nlim)) < (n-1) oplot,den(n)-bav,tden(n),psym=2 oplot,[dmin,dmax],tden([nmin,nmax]),psym=6 endif message, /info, 'Using '+(['GREEN','RED'])(red)+' standard of DOY '+strcompress(day,/rem) return, tden & end