; ; This program appends variables to an existing average netcdf file ; command line: append_average_monthly,site,time interval,date,number of days ; Sample command line: ; append_average_monthly, sgp, 5, 20000920, 1 ; possible sites: sgp, nsa, twpc1, twpc2 ; enter time interval in minutes ; pro append_average_monthly, 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 and site 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.' ; ; Open the netcdf file that holds the previously averaged data ; mypath='/home/sbenson/Average/Daily/' avgfilename=mypath+site+'.average.'+stimesp+curdate+'.000000.cdf' avgfilename = strcompress(avgfilename, /REMOVE_ALL) print,'opening file to be appended to',avgfilename avg_id=ncdf_open(avgfilename, /write) 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/' ;******************************************************************** ; Process DnsastretC1.Mace.20000928.000000.Dong_flux.cdf ; Data measurement interval time is 5min ; and interval height is 90 meters. ;******************************************************************** ; ; If you want to include stret files in the averaged ; file then set do_stret='yes'. ; do_stret='no' if do_stret eq 'yes' then begin if site eq 'sgp' then begin ;no stret as of yet endif else if site eq 'nsa' then begin datastream='DnsastretC1.Dong/' armfile='DnsastretC1.Mace.'+searchdate+ '.cd*' endif else if site eq 'twpc1' then begin ;no stret as of yet endif else if site eq 'twpc2' then begin ;no stret as of yet 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='height' ;netcdf height dimension name time_dim_name='time' ;netcdf time dimension name height_var_name='height' ;netcdf height variable name twoD='yes' ;indicates that netcdf file has two dimensions old_new_grid ; ; Process variables ; one_dimensional_variable3,'N_mean' two_dimensional_variable3,'lwc' ; ; 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_stret eq yes ;******************************************************************** ; Process *MergedMomentsC1.a1* for column cloud fraction ; data measurement interval is 60 seconds ;******************************************************************** ; ; If you want to include total column cloud fraction in the average ; file then set do_cfrac='yes'. ; do_cfrac='yes' if do_cfrac 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 ; ; Process variables ; one_dimensional_variable_column_cfrac ; ; 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_cfrac eq yes stop ;******************************************************************** ; Process ***mwravgC1.c1.20000105.000000.cdf ; Data measurement interval time is 60 seconds and ; there is no height dependence. ;******************************************************************** ;MWR = Microwave Radiometer domwr='yes' if domwr eq 'yes' then begin if site eq 'sgp' then begin datastream='sgp1mwravgC1.c1/' armfile='sgp1mwravgC1.c1.'+searchdate+'.cd*' endif else if site eq 'nsa' then begin datastream='nsamwrlosC1.a1/' armfile='nsamwrlosC1.a1.'+searchdate+'.cd*' endif else if site eq 'twpc1' then begin datastream='twpmwrlosC1.b2/' armfile='twpmwrlosC1.b2.'+searchdate+ '.cd*' endif else if site eq 'twpc2' then begin datastream='twpmwrlosC2.b2/' armfile='twpmwrlosC2.b2.'+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. Uses IDL program file_check_all.pro ; 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='none' time_dim_name='time' height_var_name='none' twoD='no' old_new_grid ; ; Process variables ; one_dimensional_variable2,'liq' one_dimensional_variable2,'vap' ; ; 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_mwr ; ; Move the output file to the output directory ; unix_command='mv '+avgfilename+' '+mypath+'Hourly' spawn,unix_command print, unix_command ; ; Write the filename to avg_netcdf_file.dat to tell the plotting program ; which file to plot ; openw,40,'avg_netcdf_file.dat' printf,40,avgfilename close,40 end