; ; This program processes a scalar variable ; Pro scalar_variable,dataname common ncdf_file, oldcdfname,cdfid,twoD,time_dim_name,height_dim_name,$ height_var_name,ovpfilename common old_grid, num_times,num_heights,base_time,time_offset,height common new_grid, numtimes,newtimes,numtemptimes,newtemptimes,$ newnumheights,newheights,timespacing,heightspacing common bracket, startref,startflag,endref,endflag,startbst,plot_time common data, newdata ; ; Open the netcdf file ; cdf_id=ncdf_open(oldcdfname) ; ; Get the variable id ; data_id=ncdf_varid(cdf_id,dataname) if data_id ne -1 then begin print,'Processing scalar ',dataname ; ; Get the variable ; ncdf_varget,cdf_id,data_id,data ; ; Inquire about the variable ; datainfo=ncdf_varinq(cdf_id, data_id) ; ; Number of attributes assigned to the variable ; numatts=datainfo.natts ; ; Store the attribute names ; dataatr=strarr(numatts) ;string array to hold attribute names for i=0,numatts-1 do begin dataatr[i]=ncdf_attname(cdf_id, data_id, i) ;Returns the name of the attribute endfor ; ; Open the netcdf file ; ovp_id=ncdf_open(ovpfilename, /write) ; ; Put the netcdf file into define mode ; ncdf_control, ovp_id, /redef ; ; Define variable ; newdata_id=ncdf_vardef(ovp_id, dataname) ; ; Define attributes ; for i=0,numatts-1 do begin nowatt=dataatr[i] mytry=ncdf_attcopy(cdf_id, data_id, nowatt, ovp_id, newdata_id) endfor ncdf_attput, ovp_id, newdata_id, 'original data source file ',oldcdfname ; ; Change from define mode to data mode ; ncdf_control, ovp_id, /endef ; ; Write variable ; ncdf_varput, ovp_id, newdata_id, data ; ; Close the netcdf file ; ncdf_close, ovp_id endif ;variable does exist in the file ncdf_close, cdf_id return end