; ; Creates a new averaged one dimensional variable by dividing two previously processed ; averaged variables. SolarRatio=psp2/twsflux_clearskyfit ; pro one_dimensional_derived, dataname,dataname1, dataname2 common ncdf_file, oldcdfname,twoD,time_dim_name,height_dim_name,$ height_var_name,avgfilename common old_grid, num_times,num_heights,base_time,time_offset,height,site common new_grid, numtimes,newtimes, numheights,newheights,$ timespacing,heightspacing common bracket, startbst ; ; Open the netcdf file ; cdf_id=ncdf_open(avgfilename) ; ; Get the variable id ; data1_id=ncdf_varid(cdf_id,dataname1) data2_id=ncdf_varid(cdf_id,dataname2) if data1_id ne -1 and data2_id ne -1 then begin print,'Processing 2-D ',dataname ; ; Get the variable ; ncdf_varget, cdf_id, data1_id, data1 data1=transpose(data1) ncdf_varget, cdf_id, data2_id, data2 data2=transpose(data2) ; ; Calculate the new variable ; data=make_array(numtimes,/float,value=-9999) result=where(data1 ne -9999 and data2 ne -9999, count) if count ne 0 then data[result]=data1[result]/data2[result] ; ; Flag out of range SolarRatio values as bad ; if dataname eq 'SolarRatio' then begin result=where(data gt 1 or data lt 0, count) if count ne 0 then data[result]=-9999 endif ; ; Open the netcdf file ; avg_id=ncdf_open(avgfilename, /write) ; ; Get the variable dimension ; time_id=ncdf_dimid(avg_id,'time') ; ; Put the netcdf file into define mode ; ncdf_control, avg_id, /redef ; ; Define variable ; data_id=ncdf_vardef(avg_id, dataname, time_id) ; ; Define attributes ; if dataname eq 'SolarRatio' then ncdf_attput, avg_id, data_id, 'long_name', 'solar ratio' if dataname eq 'SurfaceAlbedo' then ncdf_attput, avg_id, data_id, 'long_name', 'surface albedo' ncdf_attput, avg_id, data_id, 'original data source file ',oldcdfname ; ; Change from define mode to data mode ; ncdf_control, avg_id, /endef ; ; Write variable ; ;data=transpose(data) ;transpose for writing to netcdf ncdf_varput, avg_id, data_id, data ;data=transpose(data) ;return to original form for plotting ; ; Close the netcdf file ; ncdf_close, avg_id endif ;variable does exist in the file ncdf_close, cdf_id return end