pro nd ;Created 8/98 by C.See ;This program plots the filter response from 2 cal files (filter vs. reference). ;The user is prompted for the input calibration files (filter scan & reference). ;It can be run from their common directory (which allows short names). ;It optionally creates an output file named by the Cal File name +filter_data.out. ;By default the program is set to reject detector reading of less that 1e-15, ;this threshold can be set below (~line 29). ;The arrays are sized for scans of less than 350 lines. For longer scans increase ;max_lines variable below (~line 30). ;This program calls: ; /users/csee/idl_programs/sstr.pro (shorten string function) ; /users/csee/idl_programs/filtzero.pro (removes 0,0 data points for ploting) ;_______________________________________________________________________ ;Setup... ;read in file names... file1='' & file2='' & type='' Print,'____________________________________' Print,"What is the filter's scan cal file?:" Read,file1 Print,string(10B),'What is the reference scan cal file?: ' Read,file2 Read,'What type of filter is this? ',type print,'filter: ', file1 print,'ref: ', file2 Threshold=1.e-15 ;Threshold for valid detector data max_lines=350 ;max number of lines in scan file vis_filt=fltarr(max_lines,2) ;wave,signal,reference,ratio,ND ir_filt=fltarr(max_lines,2) vis_ref=fltarr(max_lines,2) ir_ref=fltarr(max_lines,2) rec=0 wave=0.0 SI=0.0 GER=0.0 gain=0 hardcopy=0 ;_______________________________________________________________________ ;Read in the data... ;Read in the filter's data... header='' file_check=findfile(file1, count = nfiles) ;check to see if file exists if nfiles ne 1 then begin print,string(10B),'With searching comes loss, and the presence of absence: ',$ string(10B),file1,' was not found. Please try again.',string(10B) goto,exit endif openr,1,sstr(file1) readf,1,header readf,1,header n=0 ;n counts the number of good data points in filter file. while not eof(1) do begin readf,1,rec,wave,SI,GER,gain if wave le 0 or gain eq 10 then goto,next1 ;skips some of the meaningless data if SI gt Threshold then vis_filt(n,0:1)=[wave,SI] if GER gt Threshold then ir_filt(n,0:1)=[wave,GER] n=n+1 if n ge max_lines then print,string(7B),string(10B),$ 'We wish to hold the whole sky, but we never will.',string(10B),$ 'The number of lines in the filter scan is ',$ 'greater than the max array size specified.',string(10B),$ 'You must increase the value of max_lines in nd.pro. I will crash now...',string(10B) next1: endwhile ;Read in the Reference data... file_check=findfile(file2, count = nfiles) ;check to see if file exists if nfiles ne 1 then begin print,string(10B),'With searching comes loss, and the presence of absence: ',$ string(10B),file2,' was not found. Please try again.',string(10B) goto,exit endif openr,2,sstr(file2) readf,2,header readf,2,header oldwave=0 & oldSI=0 & oldGER=0 m=0 ;m counts the number of good data points in ref file. while not eof(2) do begin readf,2,rec,wave,SI,GER,gain if wave le 0 or gain eq 10 then goto,next2 ;skips some of the meaningless data ;eliminate duplicated data by averaging results... if wave eq oldwave then begin if SI gt 0 and oldSI gt 0 then vis_ref(m-1,1)=(SI+oldSI)/2. if GER gt 0 and oldGER gt 0 then ir_ref(m-1,1)=(GER+oldGER)/2. goto,next2 endif oldwave=wave & oldSI=SI & oldGER=GER if SI gt Threshold then vis_ref(m,0:1)=[wave,SI] if GER gt Threshold then ir_ref(m,0:1)=[wave,GER] m=m+1 if m ge max_lines then print,string(7B),string(10B),$ 'We wish to hold the whole sky, but we never will.',string(10B),$ 'The number of lines in the reference scan is ',$ 'greater than the max array size specified.',string(10B),$ 'You must increase the value of max_lines in nd.pro. I will crash now...',string(10B) next2: endwhile ;_______________________________________________________________________ ;plot the inputed data... !p.ticklen=1 ;creates gridlines !x.gridstyle=1 ;dotted gridlines !y.gridstyle=1 ;dotted gridlines ;Plot of Filter File... Print,'Filter Scan..." ;;!X.range=[min(vis_filt(*,0)),max(ir_filt(*,0))] !X.range=[300,max(ir_filt(*,0) or vis_filt(*,0))] !Y.range=[min([vis_filt(*,1),ir_filt(*,1)]),max([vis_filt(*,1),ir_filt(*,1)])] !x.title='Wavelength (nm)' !y.title='Detector Response' x=vis_filt(*,0) y=vis_filt(*,1) filtzero,x,y plot,x,y,Title=type+' Scan Data from '+sstr(file1) x=ir_filt(*,0) y=ir_filt(*,1) filtzero,x,y oplot,x,y ans='' read,'Do you wish to continue (y or n)?: ',ans if ans eq 'n' then goto,exit ;Plot of Reference File... Print,'Reference Scan..." ;;!X.range=[min(vis_ref(*,0) or ir_ref(*,0)),max(vis_ref(*,0) or ir_ref(*,0))] !X.range=[300,max(vis_ref(*,0) or ir_ref(*,0))] !Y.range=[min([vis_ref(*,1),ir_ref(*,1)]),max([vis_ref(*,1),ir_ref(*,1)])] !x.title='Wavelength (nm)' !y.title='Detector Response' x=vis_ref(*,0) y=vis_ref(*,1) filtzero,x,y plot,x,y,Title='Reference Scan Data from '+sstr(file2) x=ir_ref(*,0) y=ir_ref(*,1) filtzero,x,y oplot,x,y ans='' read,'Do you wish to continue (y or n)?: ',ans if ans eq 'n' then goto,exit ;_______________________________________________________________________ ;calculate ratios and OD factors... ;visible... ;clean up filter data... vis_ref_min=min(vis_ref(where(vis_ref(*,0) gt 0))) ;the minimum, positive, nonzero wavelength vis_ref_max=max(vis_ref(where(vis_ref(*,0) gt 0))) ;the maximum, positive, nonzero wavelength for i=0,max_lines-1 do begin if vis_filt(i,0) lt vis_ref_min then vis_filt(i,1)=0 ;sets data that is out of range to 0 if vis_filt(i,0) gt vis_ref_max then vis_filt(i,1)=0 ;sets data that is out of range to 0 endfor vis_filt(where(vis_filt(*,1) le 0),0)=0 ;sets the wavelengths to 0 where the data is 0 ;filter out 0,0 datasets... x=vis_filt(*,0) y=vis_filt(*,1) filtzero,x,y,n if n eq 0 then begin ;when there is no visible scan. vis_filt=fltarr(1,5) ;sets all fields to zero goto,next3 endif vis_filt=fltarr(n,5) ;columns = wave,signal,reference,ratio,ND vis_filt(*,0)=x vis_filt(*,1)=y ;clean up reference data... vis_ref(where(vis_ref(*,1) le 0),0)=0 ;sets the wavelengths to 0 where the data is 0 ;filter out 0,0 datasets... x=vis_ref(*,0) y=vis_ref(*,1) filtzero,x,y,n if n eq 0 then begin ;when there is no visible reference data. vis_ref=fltarr(1,5) ;sets all fields to zero goto,next3 ;skips calculations endif vis_ref=fltarr(n,2) vis_ref(*,0)=x vis_ref(*,1)=y ;interpolate the reference data for each filter wavelength... vis_filt(*,2)=interpol(vis_ref(*,1),vis_ref(*,0),vis_filt(*,0)) ;calculate the ratio and OD factors... vis_filt(*,3)=vis_filt(*,1)/vis_filt(*,2) ;Ratio vis_filt(*,4)=ALog10(1./vis_filt(*,3)) ;OD factor next3: ;The IR Data... ;clean up filter data... ir_ref_min=min(ir_ref(where(ir_ref(*,0) gt 0))) ;the minimum, positive, nonzero wavelength ir_ref_max=max(ir_ref(where(ir_ref(*,0) gt 0))) ;the maximum, positive, nonzero wavelength for i=0,max_lines-1 do begin if ir_filt(i,0) lt ir_ref_min then ir_filt(i,1)=0 ;sets data that is out of range to 0 if ir_filt(i,0) gt ir_ref_max then ir_filt(i,1)=0 ;sets data that is out of range to 0 endfor ir_filt(where(ir_filt(*,1) eq 0),0)=0 ;sets the wavelengths to 0 where the data is 0 ;filter out 0,0 datasets... x=ir_filt(*,0) y=ir_filt(*,1) filtzero,x,y,n if n eq 0 then begin ;when there is no ir scan. ir_filt=fltarr(1,5) ;sets all fields to zero goto,next4 ;skips calculations endif ir_filt=fltarr(n,5) ;columns = wave,signal,reference,ratio,ND ir_filt(*,0)=x ir_filt(*,1)=y ;clean up reference data... ir_ref(where(ir_ref(*,1) eq 0),0)=0 ;sets the wavelengths to 0 where the data is 0 ;filter out 0,0 datasets... x=ir_ref(*,0) y=ir_ref(*,1) filtzero,x,y,n if n eq 0 then begin ;when there is no visible reference data. ir_ref=fltarr(1,5) ;sets all fields to zero goto,next4 ;skips calculations endif ir_ref=fltarr(n,2) ir_ref(*,0)=x ir_ref(*,1)=y ;interpolate the reference data for each filter wavelength... ir_filt(*,2)=interpol(ir_ref(*,1),ir_ref(*,0),ir_filt(*,0)) ;calculate the ratio and OD factors... ir_filt(*,3)=ir_filt(*,1)/ir_filt(*,2) ;Ratio ir_filt(*,4)=ALog10(1./ir_filt(*,3)) ;OD factor next4: Print: ;_______________________________________________________________________ ;Plot data... ;ratio data... !x.title='Wavelength (nm)' !y.title='Transmission Ratio of Filter/Reference' ;;!X.range=[min(vis_filt(*,0) or ir_filt(*,0)),max(ir_filt(*,0) or vis_filt(*,0))] !Y.range=[min([vis_filt(*,3),ir_filt(*,3)]),max([vis_filt(*,3),ir_filt(*,3)])] name=strmid(file1,strpos(file1,'.cal')-8,8) ;cal file name ;visible range data... i=where(vis_filt(*,3) eq 0.) ;where the ratio is zero s=size(i) If s(0) eq 0 then goto,next5 ;no zero data points vis_filt(i,0)=0 ;set unused data to 0 next5: x=vis_filt(*,0) ;visible wavelengths y=vis_filt(*,3) ;visible data filtzero,x,y,n_vis ;removes 0,0 data for plotting !X.range=[min(x),max(ir_filt(*,0) or vis_filt(*,0))] plot,x,y,Title=type+' Scan Data from: '+name,thick=2 ;ir range data... i=where(ir_filt(*,3) eq 0.) ;where the ratio is zero s=size(i) If s(0) eq 0 then goto,next6 ;no zero data points ir_filt(i,0)=0 ;set unused data to 0 next6: x=ir_filt(*,0) ;wavelengths y=ir_filt(*,3) ;ir data filtzero,x,y,n_ir ;removes 0,0 data for plotting oplot,x,y,thick=2 if hardcopy eq 0 then read,'Hit Return to continue',ans ;OD data... !x.title='Wavelength (nm)' !y.title='OD Factor of Filter/Reference' ;;!X.range=[min(vis_filt(*,0) or ir_filt(*,0)),max(ir_filt(*,0) or vis_filt(*,0))] !Y.range=[min([vis_filt(*,4),ir_filt(*,4)]),max([vis_filt(*,4),ir_filt(*,4)])] ;visible range data... x=vis_filt(*,0) ;visible wavelengths y=vis_filt(*,4) ;visible data filtzero,x,y ;removes 0,0 data for plotting !X.range=[min(x),max(ir_filt(*,0) or vis_filt(*,0))] plot,x,y,Title=type+' Scan Data from: '+name,thick=2 ;ir range data... x=ir_filt(*,0) ;wavelengths y=ir_filt(*,4) ;ir data filtzero,x,y ;removes 0,0 data for plotting oplot,x,y,thick=2 !X.range=[0,0] !Y.range=[0,0] ;_______________________________________________________________________ ;Hardcopy?... if hardcopy eq 0 then read,'Do you want print-outs of the plots (y or n)?; ',ans if ans eq 'y' then begin hardcopy=1 & ans='' !p.multi=[0,1,2] ;two plots per page !p.font=0 ;device fonts (printer default) set_plot,'ps' device,filename = '~/idl.ps',/palatino,/portrait,xsize=7.2,ysize=9.5,yoffset=0.8,/inches goto,print endif If hardcopy eq 1 then begin xyouts,.01,.00,'Reference: '+file2,/norm device,/close_file spawn,'lp ~/idl.ps' set_plot,'x' ;returns to X windows environment !p.multi=[0,1,1] ;return to one plots per page !p.font=-1 ;return to vector drawn fonts endif ;_______________________________________________________________________ ;Output file?... dir='' cd,'',current=cdir & cd,cdir print,'The current directory is:',cdir read,'Do you want to create an output file (y or n)?: ',ans if ans eq 'y' then begin read,'In what directory? (for current hit return): ',dir if dir eq '' then dir=cdir name=strmid(file1,strpos(file1,'.cal')-8,8) openw,3,dir+'/'+name+'_filter_data.out' printf,3,'This is the scaned filter data from: ',file1 printf,3,'The reference scan is: ',file2 printf,3,'The type of filter is: ',type printf,3,'The current Log is: ',cdir printf,3,'Today is: ',systime(0) printf,3,string(10B),'The visible scan data...' printf,3,' Wavelength Filter Reference Transmission Optical' printf,3,' (nm) Signal Signal Ratio Density',string(10B) for i=0,n_vis-1 do printf,3,vis_filt(i,*),format='(f12.2,2g12.3,2f12.3)' printf,3,string(10B),'The IR scan data...' printf,3,' Wavelength Filter Reference Transmission Optical' printf,3,' (nm) Signal Signal Ratio Density',string(10B) for i=0,n_ir-1 do printf,3,ir_filt(i,*),format='(f12.2,2g12.3,2f12.3)' close,3 endif ;_______________________________________________________________________ ;Outta here... exit: !p.ticklen=.02 ;returns to no grid !x.gridstyle=0 ;solid gridlines !y.gridstyle=0 ;solid gridlines !p.multi=[0,1,1] !X.range=[0,0] !Y.range=[0,0] close,/all end