[ncl-talk] Saving a script created variable added to the original to be saved
Mary Haley
haley at ucar.edu
Fri Aug 18 11:24:20 MDT 2017
Tosa,
If you are talking about a NetCDF file, then you can simply open the file
as you normally do with "addfile", but open it in "w" mode (for "write").
You can then write the variable to the file.
I highly recommend not overwriting the original file! You want to make
sure you can get it back if you make a mistake in the script.
This particular code snippet will copy the file to a new file, and then
write the new variable to the new file:
The code would look something like this:
;---WRF output file to read from.
filename = "wrfout_d01_2003-07-15_00:00:00"
;---Copy this file to a new file so we don't overwrite it
filename_write = filename + "_NEW"
system("cp " + filename + " " + filename_write)
a = addfile(filename_write + ".nc", "w")
P = a->P ; perturbation
Pb = a->PB ; base state pressure
P = P + Pb ; total pressure
theta = a->T ;
perturbation potential temperature (theta-t0) theta = theta +
300.
tk = wrf_tk (P, theta)
print("Writing TK to " + filename_write)
a->TK = tk ; Write local variable "tk" to file
You may want to include more metadata to "tk" before writing it to the
file, because it will only have a description and units attributes. Its
metadata should follow the same style as the other variables on the file.
--Mary
On Thu, Aug 17, 2017 at 2:56 PM, Tosa, Yasunari CTR (VOLPE) <
Yasunari.Tosa.CTR at dot.gov> wrote:
> Hi,
>
>
>
> Is there a way to add a variable created by a script to the original file?
>
>
>
> What I mean is that WRF_TK creates the standard temperature TK.
>
> I want to create a file with the calculated TK variable added to the
> original file content.
>
>
>
> Thank you.
>
>
>
> Tosa
>
>
>
> Yasunari Tosa, Ph.D.
>
> IT Senior Engineer, SGT/SOFITS Contract
>
> John A. Volpe National Transportation System Center
>
> 55 Broadway, V-90P, Bldg 3-223
>
> Cambridge, MA 02142-1093
>
> (617) 494-2178 (office)
>
> Yasunari.Tosa.Ctr at dot.gov
>
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170818/73c85c07/attachment.html
More information about the ncl-talk
mailing list