[ncl-talk] writing netCDF file

Dipti Sharma sdipti596 at gmail.com
Thu Jun 29 17:12:55 MDT 2017


Hi Mary,

Thank you. It worked now. I also made file name little shorter then that
worked.

ncdf=addfile("/Users/Downloads/New\ folder/MERRA_19950830.nc","c")
but one thing, when I do printVarSummay(var) I get the var info with
2dimensions

Number of Dimensions: 2
Dimensions and sizes:   [time | 8] x [lev | 72]
Coordinates:
            time: [0..1260]
            lev: [   1..  72]
Number Of Attributes: 13
  lon : -112.5
  lat :   42
  valid_range : ( -1e+15, 1e+15 )
  vmin :        -1e+15
  vmax :        1e+15
  standard_name :       air_density
  add_offset :   0
  scale_factor :         1
  fmissing_value :      1e+15
  missing_value :       1e+15
  _FillValue :  1e+15
  units :       kg m-3

But for wc, when I do printVarSummay(wc)
Variable: wc
Type: float
Total Size: 2304 bytes
            576 values
Number of Dimensions: 2
Dimensions and sizes:   [8] x [72]; There is different format so how to get
this like ' [time | 8] x [lev | 72]'?

Coordinates:
Number Of Attributes: 1
  _FillValue :  1e+15
(0)
(0)     min=-0.0658635   max=0.0909946

ALSO, my necdf file is not looking with correct attributes,

netcdf file:/C:/Users/Downloads/New%20folder/MERRA2_19950830.nc {
  dimensions:
    ncl0 = 8; should be time=8;
    ncl1 = 72;lev=72; etc.
    ncl2 = 8;
    ncl3 = 72;
  variables:
    int time(ncl0=8);

    double lev(ncl1=72);

    float data2(ncl2=8, ncl3=72);

}


Thank you so much again.

Dipti


On Thu, Jun 29, 2017 at 11:49 AM, Mary Haley <haley at ucar.edu> wrote:

> Hi Dipti,
>
> I'm not sure that addfile can recognize Windows type of directory paths
> with "C:\....".
>
> Try using UNIX-style paths:
>
> ncdf=addfile("/Users/Downloads/New\ folder/MERRA2_200.inst3_3d_asm
> _Nv.19950830.nc <http://merra2_200.inst3_3d_asm_nv.19950830.nc/>","c")
>
> Note that I used forward slashes ('/') instead of backward slashes ('\').
> However, since you have a space in one of your directory names----"New
> folder"---I put a backward slash in front of the space, just in case.
>
> --Mary
>
>
> On Wed, Jun 28, 2017 at 5:55 PM, Dipti Sharma <sdipti596 at gmail.com> wrote:
>
>> Dear NCL,
>>
>> I am trying to write netCDF file for selected variable (wc, the vertical
>> velocity here in this example) from MERRA-2 wind data. However, I always
>> get an error message saying that
>>  " fatal:Could not create (C:\Users\Downloads\New folder\
>> MERRA2_200.inst3_3d_asm_Nv.19950830.nc)
>>
>> Could someone please help me how to write the output file in netCDF. I
>> want to have wc (time,lev) 2D data from 4D (time, lev,lat,lon). I just want
>> the data at 1 location (1 lat and 1 lon).
>>
>> Thank you very much in advance for your help.
>>
>> Regards,
>>
>> Dipti
>>
>> Attached is the script that I used to read the data.
>>
>>
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>>
>> ; setfileoption("nc", "FileStructure", "Advanced")
>>
>> fn = "C:\Users\Downloads\New folder\MERRA2_200.inst3_3d_asm
>> _Nv.19950830.nc4"
>> fn1 = "C:\Users\Downloads\New folder\MERRA2_200.inst3_3d_gas
>> _Nv.19950830.nc4"
>>
>>  fi = addfile(fn, "r")
>> fi1= addfile(fn1, "r")
>>
>> ; setfileoption("nc", "Format",  "NetCDF4Classic")
>>
>>  printVarSummary(fi)
>> ;print(fi)
>>
>>  time = fi->time
>>  lev = fi->lev
>>  lat = fi->lat
>>  lon = fi->lon
>>  u = fi->U;(:,:,269,101)
>>  v = fi->V;(:,:,269,101)
>>  w=fi->OMEGA;(:,:,269,101)
>>  p=fi->PL;(:,:,269,101)
>> den=fi1->AIRDENS;(:,:,269,101)
>> uh=u(:,:,269,101)
>> uv=v(:,:,269,101)
>> wv=w(:,:,269,101)
>> pv=PL(:,:,269,101)
>> denv=den(:,:,269,101)
>> ;printVarSummary(u)
>> printVarSummary(denv)
>> printVarSummary(wv)
>> printMinMax(wv,True)
>> ;calculate vertical velocity
>> wc=(wv/(-9.8*denv))
>> printVarSummary(wc)
>> printMinMax(wc,True)
>> wc!0="time"
>> wc!1="lev"
>> ;wc!2="lat"
>> ;wc!3="lon"
>> datad = wc;(time|:,lev|:)
>> printVarSummary(datad)
>>
>> ;Writeout new netCDF file
>>
>> wc&time = time
>> wc&lev = lev
>> ncdf=addfile("C:\Users\Downloads\New folder\MERRA2_200.inst3_3d_asm
>> _Nv.19950830.nc","c")
>> ncdf->time= (/time/)
>> ncdf->lev=  (/lev/)
>> ncdf->data=(/datad/)
>> return
>> end
>>
>>
>>
>> _______________________________________________
>> 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/20170629/0bbbe3d6/attachment.html 


More information about the ncl-talk mailing list