; ; Command line: ; regrid_average_monthly, sgp, 5, 20000920, 1 ; possible sites: sgp, nsa, twpc1, twpc2 ; pro regrid_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 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='/home/sbenson/Average/' avgfilename=mypath+site+'.average.'+stimesp+curdate+'.000000.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 ; ;old clutter method ;two_dimensional_mode4,'qc_ReflectivityClutterFlag' if year eq 1997 and month le 3 then begin two_dimensional_variable_ireg_heights,'ReflectivityBestEstimate' two_dimensional_clutter_artifact_ireg_heights,$ 'qc_ReflectivityClutterFlag',$ 'qc_RadarArtifacts' two_dimensional_variable_ireg_heights,'MeanDopplerVelocity' two_dimensional_variable_ireg_heights,'SpectralWidth' endif else begin two_dimensional_variable2,'ReflectivityBestEstimate' two_dimensional_clutter_artifact,'qc_ReflectivityClutterFlag',$ 'qc_RadarArtifacts' two_dimensional_variable2,'MeanDopplerVelocity' two_dimensional_variable2,'SpectralWidth' endelse one_dimensional_variable,'CloudBaseBestEstimate' one_dimensional_mode2,'CloudBaseBestEstimate' one_dimensional_variable,'RadarFirstTop' one_dimensional_mode2,'RadarFirstTop' ; ; 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 ;******************************************************************** ; Process Dsgp.C1.yyyymmdd.hhmmss.merged_sounding.cdf ; data measurement interval is 60 seconds ;******************************************************************** ; ; If you want to include Merged Sounding files in the averaged ; file then set do_merge_sound='yes'. ; do_merge_sound='yes' if do_merge_sound eq 'yes' then begin if site eq 'sgp' then begin datastream='sgp_merged_sounding/' armfile='Dsgp.C1.' +searchdate+'.merged_sounding.cd*' endif else if site eq 'nsa' then begin datastream='nsa.C1.merged_sounding/' armfile='nsa.C1.'+searchdate+'.merged_sounding.cd*' endif else if site eq 'twpc1' then begin datastream='twp.C1.merged_sounding/' armfile='Dtwp.C1.'+searchdate+'.merged_sounding.cd*' endif else if site eq 'twpc2' then begin datastream='twp.C2.merged_sounding/' armfile='Dtwp.C2.'+searchdate+'.merged_sounding.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='height' time_dim_name='time' height_var_name='height' twoD='yes' 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 ; one_dimensional_variable,'sfc_pressure' two_dimensional_interpolate2,'temp' two_dimensional_interpolate2,'pressure' two_dimensional_derived2,'layers','ReflectivityBestEstimate',$ 'temp','qc_ReflectivityClutterFlagMode' two_dimensional_derived2_generic,'layers','pressure' ; ; 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_sound eq yes ;******************************************************************** ; Process ***mwravgC1.c1.yyyymmdd.hhmmss.cdf ; Data measurement interval time is 60 seconds and ; there is no height dependence. ;******************************************************************** ; ; If you want to include Microwave Radiometer files in the averaged ; file then set domwr='yes'. ; domwr='yes' if domwr eq 'yes' then begin if site eq 'sgp' then begin datastream='sgp1mwravgC1.c1/' armfile='sgp1mwravgC1.c1.'+searchdate+'.cd*' ;xdong's reprocessed mwr files ;armfile='sgpmwrlosreproC1.a1.'+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. ; 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 ; ; 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 ; one_dimensional_variable,'liq' one_dimensional_variable,'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 ;domwr ;******************************************************************** ; Process sgpbsrnC1.a1.yyyymmdd.hhmmss.cdf ; data measurement interval is 60 seconds and ; there is no height dependence. ;******************************************************************** ; ; If you want to include BSRN (Baseline Surface Radiation Network) ; files in the averaged file then set do_bsrn='yes'. ; BSRN only exists for sgp do_bsrn='no' if do_bsrn eq 'yes' then begin if site eq 'sgp' then begin ;only process for sgp datastream='sgpbsrnC1.a1/' armfile='sgpbsrnC1.a1.'+searchdate+ '.cd*' 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='none' time_dim_name='time' height_var_name='none' twoD='no' 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 ; one_dimensional_variable,'psp2' ; day before is repeated if it doesn't exist one_dimensional_variable,'twsflux_clearskyfit' ; day before is also repeated one_dimensional_variable,'solar_zenith_angle' one_dimensional_derived2,'SolarRatio','psp2','twsflux_clearskyfit' ; ; 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 is sgp site endif ;end of do_bsrn ;******************************************************************** ; Process sgpsirsC1.a1.yyyymmdd.hhmmss.cdf ; Data measurement interval is 60 seconds and ; there is no height dependence. ;******************************************************************** ; ; If you want to include SIRS files in the averaged file then ; set do_sirs='yes'. ; SIRS only exists for sgp ; do_sirs='yes' if do_sirs eq 'yes' then begin if site eq 'sgp' then begin ;only process for sgp datastream='sgpsirsC1.a1/' armfile='sgpsirsC1.a1.'+searchdate+ '.cd*' 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='none' time_dim_name='time' height_var_name='none' twoD='no' 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 ; one_dimensional_variable,'down_short_hemisp' one_dimensional_variable,'up_short_hemisp' one_dimensional_variable,'down_long_hemisp' one_dimensional_variable,'up_long_hemisp' one_dimensional_variable,'twsflux_clearskyfit' one_dimensional_variable,'solar_zenith_angle' one_dimensional_derived2,'SolarRatio','down_short','twsflux_clearskyfit' one_dimensional_derived2,'SurfaceAlbedo','up_short','down_short' ; ; 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 ;process sirs only for sgp site endif ;end of do_sirs eq yes ;******************************************************************** ; Process ***skyrad60sC1.b1.yyyymmdd.hhmmss.cdf ; data measurement interval is 60 seconds and ; there is no height dependence. ;******************************************************************** ; ; If you want to include skyrad files in the averaged file then ; set do_skyrad='yes'. ; skyrad only exists for nsa and twp ; do_skyrad='yes' if do_skyrad eq 'yes' then begin if site eq 'nsa' or site eq 'twpc1' or site eq 'twpc2' then begin if site eq 'nsa' then begin datastream='nsaskyrad60sC1.b1/' armfile='nsaskyrad60sC1.b1.'+searchdate + '.cd*' endif else if site eq 'twpc1' then begin datastream='twpskyrad60sC1.b2/' armfile='twpskyrad60sC1.b2.'+searchdate+ '.cd*' endif else if site eq 'twpc2' then begin datastream='twpskyrad60sC2.b2/' armfile='twpskyrad60sC2.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. ; 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 ; ; 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 ; one_dimensional_variable,'psp1_mean' one_dimensional_variable,'pir1_mean' ; day before is repeated if it doesn't exist one_dimensional_variable,'twsflux_clearskyfit' ; day before is also repeated one_dimensional_variable,'solar_zenith_angle' one_dimensional_derived2,'SolarRatio','down_short','twsflux_clearskyfit' ; ; 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 ;process skyrad for nsa and twp sites only endif ;end of do_skyrad ;******************************************************************** ; Process ***gndrad60sC1.b1.yyyymmdd.hhmmss.cdf ; Data measurement interval is 60 seconds and ; there is no height dependence. ;******************************************************************** ; ; If you want to include groundrad files in the averaged file then ; set do_gndrad='yes'. ; groundrad only exists for nsa and twp ; do_gndrad='yes' if do_gndrad eq 'yes' then begin if site eq 'nsa' or site eq 'twpc1' or site eq 'twpc2' then begin if site eq 'nsa' then begin datastream='nsagndrad60sC1.b1/' armfile='nsagndrad60sC1.b1.'+searchdate+ '.cd*' endif else if site eq 'twpc1' then begin datastream='twpgndrad60sC1.b2/' armfile='twpgndrad60sC1.b2.'+searchdate+ '.cd*' endif else if site eq 'twpc2' then begin datastream='twpgndrad60sC2.b2/' armfile='twpgndrad60sC2.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. ; 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 ; ; 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 ; one_dimensional_variable,'psp1_mean' one_dimensional_variable,'pir1_mean' one_dimensional_derived2,'SurfaceAlbedo','up_short','down_short' ; ; 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 ;process gndrad for nsa and twp only endif ;end of do_gndrad ;******************************************************************** ; Process viasela ceilometer ; Data measurement interval is 30 seconds and ; there is no height dependence. ;******************************************************************** ; ; If you want to include viasela celiometer files in the averaged ; file then set do_vceil='yes'. ; The viasela celiometer is replaced by the blc for the early ; years of sgp ; do_vceil='yes' if do_vceil eq 'yes' then begin if site eq 'sgp' then begin if (year le 1999) or (year eq 2000 and month lt 6) then $ datastream='sgpblcC1.a1/' $ else datastream='sgpvceil25kC1.a1/' if (year le 1999) or (year eq 2000 and month lt 6) then $ armfile='sgpblcC1.a1.' +searchdate+ '.cd*' $ else armfile='sgpvceil25kC1.a1.' +searchdate+ '.cd*' endif else if site eq 'nsa' then begin datastream='nsavceil25kC1.a1/' armfile='nsavceil25kC1.a1.'+searchdate+ '.cd*' endif else if site eq 'twpc1' then begin datastream='twpvceil25kC1.b2/' armfile='twpvceil25kC1.b2.'+searchdate+ '.cd*' endif else if site eq 'twpc2' then begin datastream='twpvceil25kC2.b2/' armfile='twpvceil25kC2.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. ; 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 ; ; 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 ; ;for blc if ((year le 1999) or (year eq 2000 and month lt 6)) and $ (site eq 'sgp') then one_dimensional_variable,'cloud1' $ ;viasela else one_dimensional_variable,'first_cbh' ; ; 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_vceil ; ; Move the eos output file to the output directory ; unix_command='mv '+avgfilename+' '+mypath+'Daily' ;unix_command='mv '+avgfilename+' '+mypath+'Output' 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