pro write_dz_twaters, fname, hgt_bins, log_total_water_bins, dz_twater_total ; check to see if the file exists OPENR, 1, fname, ERROR = err if err eq 0 then begin close, 1 ; file exists, read the data cdfid=ncdf_open(fname,/write) print, 'writing to ',fname dz_twater_total_id=ncdf_varid(cdfid, 'dz_twater_total') ncdf_varput, cdfid, dz_twater_total_id, dz_twater_total endif else begin ;OPENR, 1, fname, ERROR = err ; file does not exist, create it cdfid=ncdf_create(fname,/clobber) print, 'created ',fname base_bins_did=ncdf_dimdef(cdfid,'base_bins',n_elements(hgt_bins)) top_bins_did=ncdf_dimdef(cdfid,'top_bins',n_elements(hgt_bins)) log_total_water_bins_did=ncdf_dimdef(cdfid,'log_total_water_bins',n_elements(log_total_water_bins)) hgt_bins_id=ncdf_vardef(cdfid,'hgt_bins',$ [base_bins_did],/float) log_total_water_bins_id=ncdf_vardef(cdfid,'log_total_water_bins',$ [log_total_water_bins_did],/float) dz_twater_total_id=ncdf_vardef(cdfid,'dz_twater_total',$ [base_bins_did,top_bins_did,log_total_water_bins_did],/long) ncdf_control, cdfid, /endef ncdf_varput, cdfid, hgt_bins_id, hgt_bins ncdf_varput, cdfid, log_total_water_bins_id, log_total_water_bins ncdf_varput, cdfid, dz_twater_total_id, dz_twater_total endelse ;OPENR, 1, fname, ERROR = err NCDF_CLOSE, cdfid return end