[ncl-talk] creating new netcdf file with dimensions

Alan Brammer abrammer at albany.edu
Mon Nov 2 16:39:38 MST 2015


Not going to be an exhaustive reply but some starting points.

NCL is case sensitive for variables.  You're defining "time" but wrf has
the dimension as "Time" these are not the same.

 T2_AV has no metadata so ncl doesn't know what to associate it with.
Either define T2_AV in the filevardef section, with correct coordinates, as
will be done in the example io scripts, or define the coordinates in the
script. e.g.
T2_AV!0 = "Time"
T2_AV!1 = "south_north"
T2_AV!2 = "west_east"
These three lines would get you quite far.

When done correctly you should only have 3 dimensions in your netcdf.
 time,lat,lon named whatever you want; just be consistent.

Guess the next rhetorical question is why not just do the NCO operation in
the ncl script and only output the desired data.

Good luck,
Alan.


On Mon, Nov 2, 2015 at 2:22 PM, Ashish Sharma <asharma7 at nd.edu> wrote:

> 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
>
> *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
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151102/3990cd04/attachment.html 


More information about the ncl-talk mailing list