; ; old_new_grid.pro reads in the old grid from the ; netcdf file and constructs the new, averaged, grid ; pro old_new_grid common ncdf_file, oldcdfname,twoD,time_dim_name,height_dim_name,$ height_var_name,avgfilename,curdate common old_grid, num_times,num_heights,base_time,time_offset,height,$ site,files,num_files,num_days common new_grid, numtimes,newtimes,numheights,newheights,$ timespacing,heightspacing common bracket, startbst ;********************************************************* ; Read in the old time and height grid ;********************************************************* ; ; Loop through all the matching files in the directory ; for i = 0,num_files - 1 do begin ; ; Don't try to process any gif or png files that may be in the directory ; if strpos(files[i],'gif') eq -1 and $ strpos(files[i],'png') eq -1 then begin ; ; Open the old netcdf file ; cdfid=ncdf_open(files[i]) ; ; Get the dimension id's ; time_did=ncdf_dimid(cdfid,time_dim_name) if twoD eq 'yes' then height_did=ncdf_dimid(cdfid,height_dim_name) ; ; Get the size of the dimensions ; ncdf_diminq,cdfid,time_did,char_string,num_times if twoD eq 'yes' then ncdf_diminq,cdfid,height_did,char_string,num_heights ; ; Get the variable id's ; base_time_id=ncdf_varid(cdfid,'base_time') time_offset_id=ncdf_varid(cdfid,'time_offset') if twoD eq 'yes' then height_id=ncdf_varid(cdfid,height_var_name) ; ; Get the variables ; ncdf_varget,cdfid,base_time_id,base_time ncdf_varget,cdfid,time_offset_id,time_offset if twoD eq 'yes' then ncdf_varget,cdfid,height_id,height ; ; Close the old netcdf file ; ncdf_close,cdfid ; ; If it is the first file ; if i eq 0 then begin combined_btto=long(base_time)+long(time_offset) if twoD eq 'yes' then first_height=height ; ; If it is not the first file ; endif else begin combined_btto=[long(combined_btto),long(base_time)+long(time_offset)] ; ; Make sure that the height grids of the files are consistent ; if twoD eq 'yes' then begin for j=0,n_elements(height)-1 do begin if height[j] ne first_height[j] then begin print,'Height grids do not match up' if first_height[j] eq 0 then first_height[j]=height[j] if first_height[j] ne height[j] and height[j] ne 0 and $ first_height[j] ne 0 then stop endif ;end of heights don't match endfor ;end of loop through heights endif ;end of this file is two dimensional endelse ;end of not the first file endif ;end of not a gif file endfor ;end of loop through matching files ; ; Get new parameters of the array of old data ; base_time=long(combined_btto[0]) ;base time time_offset=long(combined_btto)-long(base_time) ;time offset array num_times=n_elements(time_offset) ;number of datapoints if twoD eq 'yes' then height=first_height ;height array num_heights=n_elements(height) ;number of heights ; ; Convert heights in merged moments files from MSL to AGL. ; Convert heights in merged sounding files from MSL to AGL ; if twoD eq 'yes' then begin if site eq 'sgp' then height=height-318. if site eq 'nsa' then height=height-7. if site eq 'twpc1' then height=height-3. if site eq 'twpc2' then height=height-6. endif ;***************************************************** ; Construct the new height and time grid ;***************************************************** ; ; Convert time_offset to be relative to the new grid's base time, startbst ; deltas=base_time-startbst time_offset=time_offset+deltas ; ; Create the time array for the new grid ; numtimes=num_days*86400./timespacing newtimes=fltarr(numtimes) ; ; Create the values for the new time array ; j=findgen(numtimes) newtimes=long(j)*long(timespacing) ; ; Print the starting and ending times of the files ; standard_date_time,base_time,stayr,stamm,stadd,stahh,stami,stass print,'old file starts at ',stadd,' ',stahh,':',stami standard_date_time,(base_time+time_offset[num_times-1]-deltas),$ stayr,stamm,stadd,stahh,stami,stass print,'old file ends at ',stadd,' ',stahh,':',stami standard_date_time,startbst,stayr,stamm,stadd,stahh,stami,stass print,'averged file starts at ',stadd,' ',stahh,':',stami standard_date_time,(startbst+newtimes[numtimes-1]),stayr,stamm,$ stadd,stahh,stami,stass print,'averged file ends at ',stadd,' ',stahh,':',stami ; ; The mmcrMergedMoments height will be the averaged height grid ; The new height grid is AGL. if twoD eq 'yes' then begin heightspacing=90 ;meters between height levels startheight=105 ;first height (agl) if site eq 'sgp' then begin numheights=167 ;number of height levels endif if site eq 'twpc1' then begin numheights=226 endif if site eq 'twpc2' then begin numheights=226 endif if site eq 'nsa' then begin numheights=149 endif k=findgen(numheights) newheights=startheight+heightspacing*k endif return end