<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 = "/Volumes/tas/"</div><div style="font-size:14px"> fili = systemfunc ("ls " + diri + "tas_Amon_*")</div><div style="font-size:14px"><div> out_template = "/Volumes/out/tas_FMA_MODEL_EX<wbr>PERIMENT.nc"</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, "/")</div><div> name2 = str_get_field (infile, nitems, "/")</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, "_")</div><div> expt = str_get_field (name2, 4, "_")</div><div><br></div><div>; Make output file name using template.</div><div><br></div><div> outfile = str_sub_str (out_template, "MODEL", model)</div><div> outfile = str_sub_str (outfile, "EXPERIMENT", expt)</div><div><br></div><div> print ("")</div><div> print (infile+"")</div><div> print (outfile+"")</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"><<a href="mailto:cary.lynch@pnnl.gov" target="_blank">cary.lynch@pnnl.gov</a>></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 "$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/gsn_code.ncl"</div>
<div style="font-size:11px;font-family:Menlo">load "$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/gsn_csm.ncl"</div>
<div style="font-size:11px;font-family:Menlo">load "$NCARG_ROOT/lib/ncarg/<wbr>nclscripts/csm/contributed.<wbr>ncl"</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 = "/Volumes/tas/"</div>
<div style="font-size:11px;font-family:Menlo"> diro = "/Volumes/out/"</div>
<div style="font-size:11px;font-family:Menlo"><br>
</div>
<div style="font-size:11px;font-family:Menlo"> fili = systemfunc("ls " + diri + "tas_Amon_*")</div>
<div style="font-size:11px;font-family:Menlo"> filo = fili + "_<a href="http://x.nc" target="_blank">x.nc</a>"</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),"r")</div>
<div style="font-size:11px;font-family:Menlo"> tsi = in1->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,"FMA")</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("/bin/rm -f " + filo(k))</div>
<div style="font-size:11px;font-family:Menlo">; out = addfile(diro+filo(k),"c")</div>
<div style="font-size:11px;font-family:Menlo"> out = addfile(filo(k),"c")</div>
<div style="font-size:11px;font-family:Menlo"> out->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 -- 's/Amon/FMA/g' /Volumes/out/_<a href="http://x.nc" target="_blank">x.nc</a></div>
<div>sed -i -- 's/r1i1p1//g' /Volumes/out/_<a href="http://x.nc" target="_blank">x.nc</a></div>
<div>sed -i -- 's/.<a href="http://nc_x.nc/.nc/g" target="_blank">nc_x.nc/.nc/g</a>' /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>