<div dir="ltr"><div class="gmail_default" style="font-size:small">Tosa,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">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.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">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.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">This particular code snippet will copy the file to a new file, and then write the new variable to the new file:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">The code would look something like this:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">;---WRF output file to read from. </font><span style="font-family:monospace,monospace">filename = "wrfout_d01_2003-07-15_00:00:00"</span></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">;---Copy this file to a new file so we don't overwrite it </font><span style="font-family:monospace,monospace">filename_write = filename + "_NEW"</span></div><div class="gmail_default"><font face="monospace, monospace"> system("cp " + filename + " " + filename_write)</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace"> a = addfile(filename_write + ".nc", "w")</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace"> P = a->P ; perturbation </font><span style="font-family:monospace,monospace">Pb = a->PB ; base state pressure </span><span style="font-family:monospace,monospace">P = P + Pb ; total pressure </span><span style="font-family:monospace,monospace">theta = a->T ; perturbation potential temperature (theta-t0) </span><span style="font-family:monospace,monospace">theta = theta + 300.</span></div><div class="gmail_default"><span style="font-family:monospace,monospace"> tk = wrf_tk (P, theta)</span><br></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace"> print("Writing TK to " + filename_write)</font></div><div class="gmail_default"><font face="monospace, monospace"> a->TK = tk ; Write local variable "tk" to file </font> </div><div class="gmail_default"><br></div></div><div class="gmail_default"><div class="gmail_default">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.</div></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">--Mary</div><div class="gmail_default" style="font-size:small"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 17, 2017 at 2:56 PM, Tosa, Yasunari CTR (VOLPE) <span dir="ltr"><<a href="mailto:Yasunari.Tosa.CTR@dot.gov" target="_blank">Yasunari.Tosa.CTR@dot.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="m_5875198820959967373WordSection1">
<p class="MsoNormal">Hi, <u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Is there a way to add a variable created by a script to the original file?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">What I mean is that WRF_TK creates the standard temperature TK.
<u></u><u></u></p>
<p class="MsoNormal">I want to create a file with the calculated TK variable added to the original file content.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thank you.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Tosa<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Yasunari Tosa, Ph.D.<u></u><u></u></p>
<p class="MsoNormal">IT Senior Engineer, SGT/SOFITS Contract<u></u><u></u></p>
<p class="MsoNormal">John A. Volpe National Transportation System Center<u></u><u></u></p>
<p class="MsoNormal">55 Broadway, V-90P, Bldg 3-223<u></u><u></u></p>
<p class="MsoNormal">Cambridge, MA 02142-1093<u></u><u></u></p>
<p class="MsoNormal"><a href="tel:(617)%20494-2178" value="+16174942178" target="_blank">(617) 494-2178</a> (office)<u></u><u></u></p>
<p class="MsoNormal"><a href="mailto:Yasunari.Tosa.Ctr@dot.gov" target="_blank">Yasunari.Tosa.Ctr@dot.gov</a><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<br>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/<wbr>mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>