Re: modifying netcdf files in ncl

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Apr 22 2013 - 10:54:51 MDT

On Apr 22, 2013, at 6:23 AM, Marston Johnston wrote:

> Hi,
>
> I'm trying to regrid a netcdf variable and then, instead of writing a new netcdf file, append the new variable to the old netcdf file.
> How do I add the new dimensions to the netcdf file?

You can add the new dimensions and variables to the existing file much in the same way that you do for a new file.

There's the easy way, where if your regridded variable (call it "T_regrid") already has the necessary metadata, you can simply write it to the existing file with:

;---Open file in read/write mode
  f = addfile("thefile.nc","w")
. . .
;---Write new variable (and its metadata) to file
  f->T_regrid = T_regrid

The above will also write coordinate arrays, if any, to the file.

If T_regrid is on a curvilinear or unstructured grid, then you will additionally need to write the latitude and longitude arrays separately:

 f->latnew = lat_regrid
 f->lonnew = lon_regrid

where "lat_regrid" and "lon_regrid" should be replaced by whatever the variables are called in your script, and "latnew" and "lonnew" are what you want them called on the file.

If you have big arrays, and/or want to write lots of new variables to the file, then see our "efficient" page on writing netCDF:

Even though the example creates a new file, the same code should work for an existing file.

You have to be careful to give your new lat/lon arrays different dimension names.

--Mary

>
> /M
>
> --
> Only the fruitful thing is true!
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Apr 22 10:55:02 2013

This archive was generated by hypermail 2.1.8 : Tue Apr 23 2013 - 12:54:13 MDT