pro Optimize,alt,ModNum ;CSee 26Feb07 ;This program finds the optimum match between Lyn's model data and the Titan ; descent data. It processes all models in the Model_directory (or a single ; model if designated by ModNum) and minimizes the standard deviation of the ; difference between calculated data numbers (using SA_sim.pro) and the actual ; Titan descent data (dark subtracted), in a 3 dimensional parameter space of ; Azimuth (Az), Tip toward the sun (T1), and Tip perpendicular to T1 (T2). ; ;The sign convention is Az positive CCW (from top) relative to the sun, T1 ; positive for the + probe spin axis tipping away from the sun, and T2 positive ; is the probe spin axis tipping southwestward (RHR). Note: a positive T1 or ; and/or T2 results in a westward tip, i.e. the opposite sign from Erich's ; convention. ; ;Input parameters... ; Alt=target altitude for analysis in KM (floating) ; ModNum=Sequential number for running just an individual number (integer) ; ;Approach... ;1) Make a list of the parameters (specifically altitude, but also temperatures, ; azimuths, and E/W tip) from the available Titan descent data. ;2) Define initial point using Az from header, Ti=T2=0 ;3) Create a grid of values using a range of +/- 15 deg and 5 points. ;4) Keep the two bounding the minimum (RMS deviation) as range endpoints and repeat 3 ;5) Interpolate between two points bounding the min and compare to the min in 4, ; use the least of these two. (10 calls to model) ;6) Repeat in this order: T1,T2,Az (30 calls to model) ;7) Repeat 2 thru 6 with new start point (60 calls total) ;8) Save Model, Az, T1, T2, Min_RMS_dev ;9) Repeat for next model. ;Initilaization... model_dir='Y:\Titan_ULVS_models\Model_772' ;directory containing models data_dir='Z:\Log\stream_524a_alt_az_5-8-2006\DB\Solar' Log='Z:\Log\stream_524a_alt_az_5-8-2006' dir='D:\Documents\disr\SA_simulator' ;working directory (files + output) common saved,model_name_old,alt_old,tables_read,wavl,solar_zen_angle, $ theta,phi,idnc,zeniths_blue_vertical,azimuths_blue_vertical, $ zeniths_blue_horizontal,azimuths_blue_horizontal ; These common block variables must be initialized model_name_old='' alt_old=-1.0 tables_read=0 ; Set variables for the call model_name='Y:\Titan_ULVS_models\Model_759\INTENSI.OUT' az=0.0 alt=60.4481 probe_tip=0.0 solar_az=336.0 solar_zen_angle=36.0 ; The components are the tip angle are computed from the nominal probe tip here orthogonal_tip=asin(sin(!dtor*probe_tip)*sin(!dtor*solar_az))/!dtor tip_away_from_sun=-acos(cos(!dtor*probe_tip)/cos(!dtor*orthogonal_tip))/!dtor print,'Calling SA_incident_intensities the first time...' wait,0.5 ; First call takes longer because it must read the model SA_incident_intensities,model_name,alt,az,tip_away_from_sun, $ orthogonal_tip,intensity1,dir print,'Calling SA_incident_intensities the second time...' wait,0.5 ; Subsequent calls are faster because the model has already been read az=30.0 SA_incident_intensities,model_name,alt,az,tip_away_from_sun, $ orthogonal_tip,intensity2,dir stupid=1 print,'Looking for Models...' wait,0.5 ;Which models to do... model=file_search(model_dir,'INTENSI_*.OUT',count=Nmodels) ;search for model names m1=0 m2=Nmodels-1 ;to do just one model... if n_params() eq 2 then begin m1=modnum & m2=modnum endif ;for modno=m1,m2 do begin ;loop on models print,'Finding Descent Data...' wait,0.5 ;find which Descent data to use... files=file_search(data_dir,'*MMX*',count=nfiles) array_sort,files ;sorts 'files' into assending order seqno=0 ; sequence number of current data file altdata=0.0 ; The altitude of current data file for fileno=0,nfiles-1 do begin d_read,files(fileno),h,p if d_value(h,102) ne '0000' then goto,nextfile curralt=d_value(h,98)/1000. currseqno=d_value(h,87) ;start from top of descent and work down if curralt gt alt then begin high=curralt ; above target altitude hsqn=currseqno goto,nextfile endif else begin low=curralt ; below target altitude lsqn=currseqno goto,findclosest ;quit after first dataset below target altitude endelse nextfile: endfor ;loop on files findclosest: if high-alt gt alt-low then begin ;i.e. the lower one is closer to target alt=low ;the sellected altitude seqno=lsqn ;sequence number of the sellected dataset endif else begin alt=high seqno=hsqn fileno=fileno-1 ;move up on from the lower dataset endelse ;Now that we have the right dataset lets get some details... d_read,files(fileno),h,p cols=d_value(h,6) ;h6=cols ;24 rows=d_value(h,7) ;h7=rows ;50 Tccd=d_value(h,22) ;h22=ccd_chip Etime=d_value(h,36) ;h36=exptime Mtime=d_value(h,88) ;h88=mission_time_sec cycleno=d_value(h,89) ;h89=cycle_no az=d_value(h,101) ;h101=actual_azimuth Toptics=otemp(Mtime,Log) ;returns the optics temperature from HK data if alt ne d_value(h,98)/1000. then stop ;h98=altitude_meteres if seqno ne d_value(h,87) then stop ;h87=seq# if d_value(h,102) ne'0000' then stop ;h102=lamp_state temps=[Tccd,Toptics] DN=dnpersec(intensity1,temps,wavl) PixelMaskBV=intarr(6,50) pixelmaskbv(*)=1 ;pixels with errors over 5%... pixelmaskbv(0,22)=0 pixelmaskbv(1,46)=0 pixelmaskbv(1,48)=0 pixelmaskbv(4,0)=0 pixelmaskbv(5,0)=0 pixelmaskbv(5,46)=0 pixelmaskbv(5,47)=0 pixelmaskbv(5,49)=0 stop end