Re: Adding new variable to existing NetCDF file

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Tue Oct 23 2012 - 14:16:18 MDT

Wei showed how to do this. I added his and my examples
to the addfile documentation (Examples 5 and 6)

http://www.ncl.ucar.edu/Document/Functions/Built-in/addfile.shtml
reload if necessary

NCL will *automatically* add the attributes associated with spd
to the netCDF file

  spd = sqrt(u^2 + v^2)

   spd@long_name = "Wind Speed"
   spd@short_name = "Speed"
   spd@units = "ft/s"

On 10/23/12 2:12 PM, Patrick C. Campbell wrote:
> OK Thanks.
>
> I will follow what Dennis said, and create a new NetCDF file with the new computed variable in it. Thus I understand that I don't need NCKS when doing this.
>
> But, where do I set the attributes for the new variable in the new NetCDF file? Do I use filevardef?
>
> Thanks for all your help,
>
> Patrick
>
>
> ________________________________________
> From: Wei Huang [huangwei@ucar.edu]
> Sent: Tuesday, October 23, 2012 2:03 PM
> To: Patrick C. Campbell
> Cc: Dennis Shea; ncl-talk@ucar.edu
> Subject: Re: Adding new variable to existing NetCDF file
>
> Patrick,
>
> "ncks" is a NetCDF utility tool.
>
> You can use it if you you want/need to.
>
> For your question here, you do not need it.
> As NCL can easily overwrite a variable,
> and add a new variable.
>
> Wei
>
> huangwei@ucar.edu
> VETS/CISL
> National Center for Atmospheric Research
> P.O. Box 3000 (1850 Table Mesa Dr.)
> Boulder, CO 80307-3000 USA
> (303) 497-8924
>
>
>
>
>
>
> On Oct 23, 2012, at 1:49 PM, Patrick C. Campbell wrote:
>
>> 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
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Oct 23 14:16:37 2012

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