<div dir="ltr"><span style="font-size:14px">Cary,</span><div style="font-size:14px"><br></div><div style="font-size:14px">begin</div><div style="font-size:14px">  diri = &quot;/Volumes/tas/&quot;</div><div style="font-size:14px">  fili = systemfunc (&quot;ls &quot; + diri + &quot;tas_Amon_*&quot;)</div><div style="font-size:14px"><div>  out_template = &quot;/Volumes/out/tas_FMA_MODEL_EX<wbr>PERIMENT.nc&quot;</div><div>  </div><div>  do k = 0, dimsizes(fili)-1</div><div>    infile = fili(k)</div><div><br></div><div>; Remove directories, isolate the base file name.</div><div><br></div><div>    nitems = str_fields_count (infile, &quot;/&quot;)</div><div>    name2  = str_get_field (infile, nitems, &quot;/&quot;)</div><div><br></div><div>; Isolate selected parts of the file name.  Pattern:</div><div>; tas_Amon_[model]_[experiment]_<wbr>[realization]_[years].nc</div><div><br></div><div>    model = str_get_field (name2, 3, &quot;_&quot;)</div><div>    expt  = str_get_field (name2, 4, &quot;_&quot;)</div><div><br></div><div>; Make output file name using template.</div><div><br></div><div>    outfile = str_sub_str (out_template, &quot;MODEL&quot;, model)</div><div>    outfile = str_sub_str (outfile, &quot;EXPERIMENT&quot;, expt)</div><div><br></div><div>    print (&quot;&quot;)</div><div>    print (infile+&quot;&quot;)</div><div>    print (outfile+&quot;&quot;)</div><div>  end do</div></div><div style="font-size:14px">end</div><div class="gmail_extra" style="font-size:14px"><br></div><div class="gmail_extra" style="font-size:14px">--Dave</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 10, 2016 at 1:14 PM, Lynch, Cary D <span dir="ltr">&lt;<a href="mailto:cary.lynch@pnnl.gov" target="_blank">cary.lynch@pnnl.gov</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div style="word-wrap:break-word">
<div style="color:rgb(0,0,0)"><font style="font-size:12px" face="Consolas">NCL-TALK:</font></div>
<div style="color:rgb(0,0,0)"><font style="font-size:12px" face="Consolas"><br>
</font></div>
<div style="color:rgb(0,0,0)"><font style="font-size:12px" face="Consolas">I am trying to rename and move output files using the systemfunc and/or system command within a NCL script.  Currently
<span>I hard code output names; use a separate shell script; and/or use CDO commands.</span></font></div>
<div style="color:rgb(0,0,0)"><span style="font-size:12px"><font face="Consolas"><br>
</font></span></div>
<div style="color:rgb(0,0,0)"><span style="font-size:12px"><font face="Consolas">Input file name(s) look something like this: tas_ Amon_ [model]_ [experiment]_ [realization, etc]_ [years].nc</font></span></div>
<div style="color:rgb(0,0,0)"><font style="font-size:12px" face="Consolas"><span>I want them to look like this:  </span>tas_ FMA_ [model]_ [experiment].nc  </font></div>
<div><font style="font-size:12px" face="Consolas">And I want them to be located in a new directory.</font></div>
<div style="color:rgb(0,0,0)"><span style="font-size:12px"><font face="Consolas"><br>
</font></span></div>
<div style="color:rgb(0,0,0)"><span style="font-size:12px"><font face="Consolas">The below script works, but requires me to use a shell script to move and rename output files using Unix and sed commands.</font></span></div>
<div style="color:rgb(0,0,0);font-family:Calibri,sans-serif;font-size:14px">
<span style="font-family:Menlo;font-size:11px"><br>
</span></div>
<div style="color:rgb(0,0,0)"><span>
<div style="font-size:11px;font-family:Menlo">;*****************************<wbr>*********</div>
<div style="font-size:11px;font-family:Menlo">; systemfunc to rename files</div>
<div style="font-size:11px;font-family:Menlo">;*****************************<wbr>*********</div>
<div style="font-size:11px;font-family:Menlo">load &quot;$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/gsn_code.ncl&quot;</div>
<div style="font-size:11px;font-family:Menlo">load &quot;$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/gsn_csm.ncl&quot;</div>
<div style="font-size:11px;font-family:Menlo">load &quot;$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/contributed.<wbr>ncl&quot;</div>
<div style="font-size:11px;font-family:Menlo">;*****************************<wbr>*********</div>
<div style="font-size:11px;font-family:Menlo">begin</div>
<div style="font-size:11px;font-family:Menlo">;*****************************<wbr>***********</div>
<div style="font-size:11px;font-family:Menlo"><br>
</div>
<div style="font-size:11px;font-family:Menlo">  diri = &quot;/Volumes/tas/&quot;</div>
<div style="font-size:11px;font-family:Menlo">  diro = &quot;/Volumes/out/&quot;</div>
<div style="font-size:11px;font-family:Menlo"><br>
</div>
<div style="font-size:11px;font-family:Menlo">  fili = systemfunc(&quot;ls &quot; + diri + &quot;tas_Amon_*&quot;)</div>
<div style="font-size:11px;font-family:Menlo">  filo = fili + &quot;_<a href="http://x.nc" target="_blank">x.nc</a>&quot;</div>
<div style="font-size:11px;font-family:Menlo"><br>
</div>
<div style="font-size:11px;font-family:Menlo">; read in all data files</div>
<div style="font-size:11px;font-family:Menlo"><br>
</div>
<div style="font-size:11px;font-family:Menlo">  do k = 0,dimsizes(fili)-1</div>
<div style="font-size:11px;font-family:Menlo">  in1  = addfile(fili(k),&quot;r&quot;)</div>
<div style="font-size:11px;font-family:Menlo">  tsi = in1-&gt;tas</div>
<div style="font-size:11px;font-family:Menlo"><br>
</div>
<div style="font-size:11px;font-family:Menlo">; do seasonal average then average over time dim</div>
<div style="font-size:11px;font-family:Menlo"><br>
</div>
<div style="font-size:11px;font-family:Menlo">  atsi = month_to_season(tsi,&quot;FMA&quot;)</div>
<div style="font-size:11px;font-family:Menlo">  climi = dim_avg_n_Wrap(atsi,0)</div>
<div style="font-size:11px;font-family:Menlo"><br>
</div>
<div style="font-size:11px;font-family:Menlo">; write out data files</div>
<div style="font-size:11px;font-family:Menlo"><br>
</div>
<div style="font-size:11px;font-family:Menlo">  system(&quot;/bin/rm -f &quot; + filo(k))</div>
<div style="font-size:11px;font-family:Menlo">;  out = addfile(diro+filo(k),&quot;c&quot;)</div>
<div style="font-size:11px;font-family:Menlo">  out = addfile(filo(k),&quot;c&quot;)</div>
<div style="font-size:11px;font-family:Menlo">  out-&gt;climate = climi</div>
<div style="font-size:11px;font-family:Menlo">  delete([/tsi,atsi,climi/])</div>
<div style="font-size:11px;font-family:Menlo"><br>
</div>
<div style="font-size:11px;font-family:Menlo">  end do</div>
<div style="font-size:11px;font-family:Menlo"><br>
</div>
<div style="font-size:11px;font-family:Menlo">End</div>
<div style="font-size:11px;font-family:Menlo">~</div>
<div style="font-size:11px;font-family:Menlo"><br>
</div>
<div><font style="font-size:12px" face="Consolas">Then I use the following shell:</font></div>
<div style="font-size:11px;font-family:Menlo"><br>
</div>
<div style="font-size:11px;font-family:Menlo">
<div>mv /Volumes/tas/*_<a href="http://x.nc" target="_blank">x.nc</a> /Volumes/out/.</div>
<div>sed -i -- &#39;s/Amon/FMA/g&#39; /Volumes/out/_<a href="http://x.nc" target="_blank">x.nc</a></div>
<div>sed -i -- &#39;s/r1i1p1//g&#39; /Volumes/out/_<a href="http://x.nc" target="_blank">x.nc</a></div>
<div>sed -i -- &#39;s/.<a href="http://nc_x.nc/.nc/g" target="_blank">nc_x.nc/.nc/g</a>&#39; /Volumes/out/_<a href="http://x.nc" target="_blank">x.nc</a></div>
</div>
<div style="font-size:11px;font-family:Menlo"><br></div>
<div><font style="font-size:12px" face="Consolas">Thank you.</font></div></span></div></div></blockquote></div></div></div>