[ncl-talk] creating new netcdf file with dimensions
Ashish Sharma
asharma7 at nd.edu
Mon Nov 2 12:22:00 MST 2015
Hello,
I created a netcdf output file. But I am not able to get proper dimensions. I think I need proper dimensions to perform nco operations on the .nc file. I saw an NCL page on creating the output file, but it assumes the output variables already have dimensions and no meta data. https://www.ncl.ucar.edu/Applications/o-netcdf.shtml <https://www.ncl.ucar.edu/Applications/o-netcdf.shtml>
Here I need to create dimensions and meta data.
Could you please help me to get proper dimensions with the output variable, so that I can use NCO tool. I have attached ncl code, ncdump file and NCO script for suggestion.
Here is my code:
;================================================;
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRF_contributed.ncl"
; ================================================;
begin
;=================================================;
datadir_00 = "/glade/scratch/sharmaa/BLUE_WATERS_PROJECT/nco_wrf2000/"
FILES_00 = systemfunc ("ls -1 " + datadir_00 + "2000d01_day00* " )
numFILES_00 = dimsizes(FILES_00)
print(FILES_00)
sn = 515
we = 599
dailyT2maxS_00 = new((/numFILES_00,sn,we/),float)
dailyT2minS_00 = new((/numFILES_00,sn,we/),float)
dailyT2avS_00 = new((/numFILES_00,sn,we/),float)
do ifil = 0,numFILES_00-1
a_00 = addfile(FILES_00(ifil)+".nc","r") ; Open the next file
temp_00 = a_00->T2 ; perturbation potential temperature (theta)
temp_00 = temp_00 - 273.15
dailyT2maxS_00(ifil,:,:) = dim_max_n_Wrap(temp_00,0)
dailyT2minS_00(ifil,:,:) = dim_min_n_Wrap(temp_00,0)
dailyT2avS_00(ifil,:,:) = (dailyT2maxS_00(ifil,:,:)+dailyT2minS_00(ifil,:,:))/2
end do
;=================================================;
f1 = addfile("YEARd01_day001.nc","r")
LAT = f1->XLAT(0,:,:)
LON = f1->XLONG(0,:,:)
;=================================================;
;=================================================;
;OPEN NEW NETCDF FOR WRITING
;-------------------------------------------------
system("/bin/rm -f WRF_T2_d01_2000_test.nc") ; remove any pre-existing file
fout = addfile("WRF_T2_d01_2000_test.nc" ,"c") ; open output netCDF file
;===================================================================
; create global attributes of the file (optional)
;===================================================================
fAtt = True ; assign file attributes
fAtt at title = "NCL Simple Approach to netCDF Creation"
fAtt at source_file = "original-file.nc"
fAtt at Conventions = "None"
fAtt at creation_date = systemfunc ("date")
fileattdef( fout, fAtt ) ; copy file attributes
;===================================================================
; make time an UNLIMITED dimension; recommended for most applications
;===================================================================
filedimdef(fout,"time",-1,True)
;===================================================================
; output variables directly; NCL will call appropriate functions
; to write the meta data associated with each variable
;===================================================================
XLAT = f1->XLAT
XLONG = f1->XLONG
fout->XLAT = XLAT
fout->XLONG = XLONG
fout->T2_AV = dailyT2avS_00
end
Here is the ncdump file:
[sharmaa at yslogin1 T2_SIM]$ ncdump -h WRF_T2_d01_2000_test.nc
netcdf WRF_T2_d01_2000_test {
dimensions:
time = UNLIMITED ; // (0 currently)
Time = 24 ;
south_north = 515 ;
west_east = 599 ;
ncl4 = 9 ;
ncl5 = 515 ;
ncl6 = 599 ;
variables:
float XLAT(Time, south_north, west_east) ;
XLAT:FieldType = 104 ;
XLAT:MemoryOrder = "XY " ;
XLAT:description = "LATITUDE, SOUTH IS NEGATIVE" ;
XLAT:units = "degree_north" ;
XLAT:stagger = "" ;
float XLONG(Time, south_north, west_east) ;
XLONG:FieldType = 104 ;
XLONG:MemoryOrder = "XY " ;
XLONG:description = "LONGITUDE, WEST IS NEGATIVE" ;
XLONG:units = "degree_east" ;
XLONG:stagger = "" ;
float T2_AV(ncl4, ncl5, ncl6) ;
T2_AV:_FillValue = 9.96921e+36f ;
// global attributes:
:creation_date = "Mon Nov 2 12:12:21 MST 2015" ;
:Conventions = "None" ;
:source_file = "original-file.nc" ;
Here is the issue with NCO operation:
[sharmaa at yslogin1 T2_SIM]$ ncrcat -d ncl4,1,5 -v T2_AV WRF_T2_d01_2000_test.nc test.nc
ncrcat: ERROR no variables fit criteria for processing
ncrcat: HINT Extraction list must contain a record variable which to concatenate
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151102/77b74034/attachment.html
More information about the ncl-talk
mailing list