; ; Command line: ; regrid_ctrue, sgp, 5, 20000920, 1 ; possible sites: sgp, nsa, twpc1, twpc2 ; pro regrid_ctrue, thissite, thistimesp, start_date, n_days 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 common data, avg_data ; ; Read in the date of the file to be averaged ; Commented portion read in the date from the file date.dat ; Currently it is passed in the date through the program call. ; ;openr, 8, 'date.dat' ;readf, 8, year,month,day ;close,8 site=thissite ; ; Create a string of the date to be used when deriving file names. ; curdate = (strcompress(start_date, /REMOVE_ALL)) ;removes extra whitespace syear=strmid(curdate,0,4) year=fix(syear) smonth = strmid(curdate,4,2) month=fix(smonth) sday= strmid(curdate,6,2) day=fix(sday) ; ; Create a string of the date to be used when deriving file names. ; num_days=fix(n_days) if num_days eq 1 then begin ;want just one day averaged searchdate=curdate+'*' endif else begin ;want one month averaged searchdate=syear+smonth+'*' ;string for searching for matching files endelse searchdate=strcompress(searchdate,/remove_all) print, 'file date',curdate print, 'search date', searchdate ; ; Convert the date to seconds since 1-1-1970 ; using the IDL function num_sec_ep.pro ; print,'file date and start time',year,month,day,' 00:00:00' startbst=num_sec_ep(year,month,day,0,0,0) print,'file date and start time ', startbst, 'seconds since 1-1-1970' ; ; Convert the time interval to seconds ; timespacing=fix(strcompress(thistimesp,/remove_all)) ;input in minutes timespacing=timespacing*60. ;convert to seconds ; ; Create a string for the filename to indicate the time interval ; if timespacing lt 3600. then stimesp=strcompress(string(fix(timespacing/60.)))+'min.' if timespacing ge 3600. then stimesp=strcompress(string(fix(timespacing/60./60.)))+'hr.' ; ; Create the netcdf file to hold the averaged data ; mypath='/data/mace4/sbenson/Robin_hogan/' avgfilename=mypath+site+'.robin.hogan.'+stimesp+curdate+'.cdf' avgfilename = strcompress(avgfilename, /REMOVE_ALL) print,'Writing to file ',avgfilename avg_id=ncdf_create(avgfilename, /clobber) ncdf_close,avg_id ; ; Establish the directory where the data for the site resides ; if site eq 'sgp' then armdatadir='/data/mace3/arm_data/sgp/' if site eq 'nsa' then armdatadir='/data/mace2/arm_data/nsa/' if site eq 'twpc1' then armdatadir='/data/mace/arm_data/twp/Manus_C1/' if site eq 'twpc2' then armdatadir='/data/mace/arm_data/twp/Nauru_C2/' ; ; Variable that indicates if the new averaged time height ; grid has been created yet. ; grid_created='no' ;******************************************************************** ; Process ***mmcrMergedMomentsC1.a1.yyyymmdd.hhmmss.cdf ; Data measurement time interval is 36 or 37 seconds ; and height interval is 90 meters. ;******************************************************************** ; ; If you want to include Merged Moments files in the averaged ; file then set do_merge_mom='yes'. ; do_merge_mom='yes' if do_merge_mom eq 'yes' then begin if site eq 'sgp' then begin datastream='sgpmmcrcalC1.a1/' armfile='sgpmmcrMergedMomentsC1.a1.'+searchdate+ '.cd*' endif else if site eq 'nsa' then begin datastream='nsammcrcalC1.a1/' armfile='nsammcrMergedMomentsC1.a1.'+searchdate+ '.cd*' endif else if site eq 'twpc1' then begin datastream='twpmmcrcalC1.a1/' armfile='twpmmcrMergedMomentsC1.a1.'+searchdate+ '.cd*' endif else if site eq 'twpc2' then begin datastream='twpmmcrcalC2.a1/' armfile='twpmmcrMergedMomentsC2.a1.'+searchdate+ '.cd*' endif armfile=armdatadir+datastream+armfile spawn,'gunzip -fq ' + armfile files=findfile(armfile,count=num_files) ; ; Check to make sure the file exists. If it does exist, ; continue processing. ; if num_files ge 1 then begin ;continue processing ; ; Read in the old time and height grid and construct ; the new time and height grid. ; height_dim_name='nheights' ;netcdf height dimension name time_dim_name='time' ;netcdf time dimension name height_var_name='Heights' ;netcdf height variable name twoD='yes' ;indicates that netcdf file has two dimensions old_new_grid ; ; Write the new time and height grid to the output cdf file ; print,'grid created ? ',grid_created if grid_created eq 'no' then write_new_grid,grid_created ; ; Process variables ; ;ctrue_heights ctrue_cmin_cmax_crand3 ;ctrue_cmin_cmax_crand2 ; ; Zip up the files ; unix_command='gzip -fq '+armfile ;zip the data files spawn,unix_command unix_command='gunzip -fq *gif.gz' ;unzip any gif files unintentionally zipped spawn,unix_command unix_command='chmod 664 '+armfile ;change permissions spawn,unix_command unix_command='chgrp met-mace '+armfile ;change group spawn,unix_command endif ;file exists endif ;end of do_merge_mom eq yes ; ; Move the eos output file to the output directory ; ;unix_command='mv '+avgfilename+$ ; ' /home/sbenson/Arm_data/Graphics/Robin_hogan' ;spawn,unix_command ;print, unix_command end