Personal tools
You are here: Home CDAT Tips and Tricks File I/O Tips Writing data to NetCDF (extract from one file and write to another).
Document Actions

Writing data to NetCDF (extract from one file and write to another).

by Renata McCoy last modified 2007-05-01 13:47

  Table of Contents Previous Next
Contents Previous Next

Goal: Learn how to write data in CDAT.

Writing data in CDAT is very easy, just define a variable you want to save to a file, open file to write and enter command to write data. The output file will be a NetCDF file with the variable data and it's annotation.

import cdms 
f = cdms.open('sample.nc')
u =f('u')    # read data from an input file
f.close()

# write the variable u to a new file
g = cdms.open('sample2.nc','w')
# The 'w' option in the above command means
# the file is opened write-enabled and if the
# file name did not exist, a new file was created.
g.write(u)
g.close() # close the new file

  Table of Contents Previous Next
Contents Previous Next

Powered by Plone