Re: Adding new variable to existing NetCDF file

From: Patrick C. Campbell <pcampbe2_at_nyahnyahspammersnyahnyah>
Date: Tue Oct 23 2012 - 13:49:10 MDT

Thank you David.

So if I understand correctly, the following statements

  filo = "AddVar.nc"
    system("/bin/rm -f "+filo) ; rm any pre-existing file
    ncdf = addfile(filo ,"c") ; open output netCDF file
    filedimdef(ncdf,"time",-1,True)
    ncdf->VAR1 = T ; 4D
    ncdf->VAR2 = PS ; 3D

are used to to create a new file, define its dimensions, and add variables to it. However, where do we define the new variable's units, long_name etc? Should I use the example statement

 filevardef(f, "SPD", typeof(u), getvardims(u))

 that Wei Huang suggested?

Then, if I further understand correctly, the following NCKS statements
   
 NCKS = "ncks -A "+filo+" "+orig.nc ; A ==> append
    print("NCKS: "+NCKS)
    system(NCKS)

will add the new variables to the original file if need be?

Thanks again!

Patrick
________________________________________
From: Dennis Shea [shea@ucar.edu]
Sent: Tuesday, October 23, 2012 12:15 PM
To: Patrick C. Campbell
Cc: ncl-talk@ucar.edu
Subject: Re: Adding new variable to existing NetCDF file

I *think* NCL can do this via the "w" on addfile.

However, the most efficient method is to write a
netCDF file containing only the new variable(s)

    filo = "AddVar.nc"
    system("/bin/rm -f "+filo) ; rm any pre-existing file
    ncdf = addfile(filo ,"c") ; open output netCDF file
    filedimdef(ncdf,"time",-1,True)
    ncdf->VAR1 = T ; 4D
    ncdf->VAR2 = PS ; 3D

Then use ncks to merge the 2 files. Let orig.nc be the file
to which you want to add the new variables:

    NCKS = "ncks -A "+filo+" "+orig.nc ; A ==> append
    print("NCKS: "+NCKS)
    system(NCKS)

On 10/23/12 11:52 AM, Patrick C. Campbell wrote:
> Hello,
>
> Rather simple question that I haven't found many examples of.
>
> If I have calculated a new variable, does anyone have any information on
> how to add this variable using NCL, to an existing NetCDF file (same
> dimensions)?
>
> Regards,
>
> Patrick
>
>
> _______________________________________________
> 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 Tue Oct 23 13:49:28 2012

This archive was generated by hypermail 2.1.8 : Wed Oct 31 2012 - 09:14:12 MDT