
NCL Home>
Application examples>
File IO ||
Data files for some examples
Support for NetCDF-4 files is in beta-testing in V6.1.1.
We encourage people to test it out and give us feedback on our ncl-talk email list.
Create a file to write NetCDF4 string data.
Define some file attributes:
Define dimensions:
Define the variable:
Write the compound data out, and close the file:
This script produced (use "ncl_filedump ncl_wrt_opaque.nc"):
Example pages containing:
tips |
resources |
functions/procedures
>
write netCDF
NCL: Write netCDF4 opaque data
Support for NetCDF-4 files is in beta-testing in V6.1.1.
We encourage people to test it out and give us feedback on our ncl-talk email list.
Below is a script which demonstrates how to read/write NetCDF4 opaque data.
Read NetCDF4 opaque data from a file generated from NetCDF opaque example code.
fn = "$NCARGTEST/nclscripts/nc4_files/opaque.nc" fori = addfile(fn, "r") ;print(fori) ;printVarSummary(fori) ori_v = fori->var_defined_by_netcdf_user ori_nv = dimsizes(ori_v) ;print(ori_nv) ;print(ori_v) var_size = 1 do n = 1, dimsizes(ori_nv) - 1 var_size = ori_nv(n) * var_size end do ;print(var_size)
Create a file to write NetCDF4 string data.
;=================================================================== setfileoption("nc", "Format", "NetCDF4") fn = "ncl_wrt_opaque.nc" system("/bin/rm -f " + fn) fo = addfile(fn, "c")
Define some file attributes:
;=================================================================== fAtt = True ; assign file attributes fAtt@title = "NCL generated netCDF file with enum" fAtt@source_file = fn fAtt@Conventions = "None" fAtt@creation_date = systemfunc("date") ;print(fAtt) fileattdef(fo, fAtt)
Define dimensions:
;=================================================================== nvals = ori_nv(0) dimNames = (/"opaque_base_size"/) dimSizes = (/ nvals /) dimUnlim = (/ False /) filedimdef(fo, dimNames, dimSizes, dimUnlim)
Define the variable:
;=================================================================== var_name = "opaque_variable" fileopaquedef(fo, "opaque_type", var_name, var_size, dimNames)
Write the compound data out, and close the file:
;=================================================================== fo->$var_name$ = (/ori_v/) delete(fo)
This script produced (use "ncl_filedump ncl_wrt_opaque.nc"):
Variable: f Type: file filename: ncl_wrt_opaque path: ncl_wrt_opaque.nc User Defined Types: opaque_type { }; attributes: creation_date : Mon Jan 28 15:22:13 MST 2013 Conventions : None source_file : ncl_wrt_opaque.nc title : NCL generated netCDF file with enum dimensions: opaque_base_size = 3 variables: opaque_variable:[ 3 ]