<div dir="ltr">Will,<div><br></div><div>If the junk time array has the correct variable name and dimension name (probably both "time"), and a data type with sufficient precision, then the simplest method is to just overwrite the junk time coordinate values with correct time coordinates that you calculate in NCL. I have found that trying to swap a new coordinate variable in place of an old one is very troublesome.</div><div><br></div><div>As a side note, I just ran very simple tests on NCL 6.3.0 on Mac. The following program easily added a new 1-D variable, to both netcdf-3 and netcdf-4 test files with unlimited time dimension. In short, I do not see why your program crashed.</div><div><br></div> f = addfile ("<a href="http://test.nc" target="_blank">test.nc</a>", "w")<br> t3 = f->time ; note both time and t3 are double in this case<br> f->t3 = t3 ; both have single dimension "time"<br> exit<br><br>--Dave<br><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 29, 2016 at 3:45 PM, Will Hobbs <span dir="ltr"><<a href="mailto:will.hobbs@utas.edu.au" target="_blank">will.hobbs@utas.edu.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="white" lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="m_-4082474141422240194m_-8179188469462145622WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">Hi all<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I am working with some model output monthly files (one year for each file, with filename t.<year>.nc), which have a junk time array, and which I am trying to fix. I was hoping to create a new time array, add
the values to each file’s time array, and update the variable attributes using NCO:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">>Begin<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">yrst = 1979<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">yren=2014<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">vNam = “t”<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">;create new time array<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">ydum = new(12, integer)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">mdum = ispan(1,12,1)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> ddum = conform_dims(12,15,-1)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> tdum = conform_dims(12,0,-1)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> opt = 1<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> opt@calendar = "standard"<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> tunits = "days after 1-1-1"<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">;loop through each year<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> do yy = yrst, yren<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> ;create time array<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> ydum = yy<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> ntime = cd_inv_calendar(ydum,mdum,ddum<wbr>,tdum,tdum,tdum,tunits,opt)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> ;add time to file<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> fil =systemfunc("ls "+vNam+"."+yy+".nc")<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> fi = addfile(fil,"w")<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> fi->time = (/ntime/)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">;update attributes<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> CMD = “ncatted –a time,units,o,c,”+tunits+” “+fil<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">system(CMD)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">end do<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Unfortunately when I try and write the data to file (i.e. fi->time = (/ntime/) ) I get a segmentation fault:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Segmentation fault: 11<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I’ve checked the file permissions and it doesn’t seem to be that. I ‘speculate’ that netCDF won’t allow me to update the record dimension – is this the case? If so, presumably I will need rewrite each file
from scratch with new time arrays.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Many thanks,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Will</span></p></div></div></blockquote></div></div></div>