NCL Website header
NCL Home> Application examples> File IO || Data files for some examples

Example pages containing: tips | resources | functions/procedures > output netCDF

Output netCDF4 vlen(variable LENgth array) 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 vlen data.

Read NetCDF4 vlen data from a file generated from NetCDF vlen example code.

 fn = "$NCARGTEST/nclscripts/nc4_files/vlen.nc"

 fa = addfile(fn, "r")

;printVarSummary(fa)
;print(fa)

 var = fa->var

 ne = ListCount(var)
 print("Number of Elements = " + ne)

 delete(fa)



Create a file to write NetCDF4 vlen data.
;===================================================================
 setfileoption("nc", "format", "NETCDF4")
 fn = "nc4_vl.nc"
 system("/bin/rm -f " + fn)
 fo = addfile(fn, "c")



Define some file attributes:
;===================================================================
 fAtt               = True
 fAtt@title         = "NCL generated netCDF file"
 fAtt@source_file   = fn
 fAtt@Conventions   = "None"
 fAtt@creation_date = systemfunc("date")

 fileattdef(fo, fAtt)



Define dimensions:
;===================================================================
 dimNames = (/"vldim"/)
 dimSizes = (/ ne /)
 dimUnlim = (/ False /)
 filedimdef(fo, dimNames, dimSizes, dimUnlim)



Define the variable:
;===================================================================
 vlen_name = "vlen"
 var_name = "var"
 filevlendef(fo, vlen_name, var_name, "integer", dimNames)

;printVarSummary(var)



Write the compound data out, and close the file:
;===================================================================
 fo->$var_name$ = (/var/)

 delete(fo)




This script produced (use "ncl_filedump nc4_vl.nc"):
Variable: f
Type: file
filename:       nc4_vl
path:   nc4_vl.nc
User Defined Types:
    vlen
    {
    };

attributes:
    creation_date       :       Mon Jan 28 10:11:40 MST 2013
    Conventions :       None
    source_file :       nc4_vl.nc
    title       :       NCL generated netCDF file"

dimensions:
    vldim       = 3

variables:
    var:  [ 3  ]