
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 nc4_wrt_string.nc"):
Example pages containing:
tips |
resources |
functions/procedures
>
write netCDF
NCL: Write netCDF4 string 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 string data.
Read NetCDF4 string data from a file generated from NetCDF string example code.
fn = "$NCARGTEST/nclscripts/nc4_files/strings.nc" fori= addfile(fn, "r") ;print(fori) ;printVarSummary(fori) strs = fori->universal_declaration_of_human_rights ;print(strs)
Create a file to write NetCDF4 string data.
;=================================================================== setfileoption("nc", "Format", "NetCDF4") fn = "nc4_wrt_string.nc" system("/bin/rm -f " + fn) fo = addfile(fn, "c")
Define some file attributes:
;=================================================================== fAtt = True fAtt@title = "NCL generated netCDF 4 file" fAtt@source_file = fn fAtt@Conventions = "None" fAtt@creation_date = systemfunc("date") ;print(fAtt) fileattdef(fo, fAtt)
Define dimensions:
;=================================================================== nstrs = dimsizes(strs) dimNames = (/"Sentence"/) dimSizes = (/ nstrs /) dimUnlim = (/ False /) filedimdef(fo, dimNames, dimSizes, dimUnlim)
Define the variable:
;=================================================================== strsdims = getvardims(strs) strsdims = "Sentence" filevardef(fo, "nc4_string", typeof(strs), strsdims)
Write the compound data out, and close the file:
;=================================================================== fo->nc4_string = (/strs/) delete(fo)
This script produced (use "ncl_filedump nc4_wrt_string.nc"):
Variable: f Type: file filename: nc4_wrt_string path: nc4_wrt_string.nc attributes: creation_date : Mon Jan 28 10:21:01 MST 2013 Conventions : None source_file : nc4_wrt_string.nc title : NCL generated netCDF 4 file dimensions: Sentence = 30 variables: nc4_string:[ 30 ]