<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<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 style="font-variant-ligatures: no-common-ligatures;">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-variant-ligatures: no-common-ligatures; font-size: 12px;"><font face="Consolas"><br>
</font></span></div>
<div style="color: rgb(0, 0, 0);"><span style="font-variant-ligatures: no-common-ligatures; 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 style="font-variant-ligatures: no-common-ligatures;">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-variant-ligatures: no-common-ligatures; font-size: 12px;"><font face="Consolas"><br>
</font></span></div>
<div style="color: rgb(0, 0, 0);"><span style="font-variant-ligatures: no-common-ligatures; 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; font-variant-ligatures: no-common-ligatures;"><br>
</span></div>
<div style="color: rgb(0, 0, 0);"><span style="font-variant-ligatures: no-common-ligatures;">
<div style="font-size: 11px; font-family: Menlo;">;**************************************</div>
<div style="font-size: 11px; font-family: Menlo;">; systemfunc to rename files</div>
<div style="font-size: 11px; font-family: Menlo;">;**************************************</div>
<div style="font-size: 11px; font-family: Menlo;">load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"</div>
<div style="font-size: 11px; font-family: Menlo;">load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"</div>
<div style="font-size: 11px; font-family: Menlo;">load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"</div>
<div style="font-size: 11px; font-family: Menlo;">;**************************************</div>
<div style="font-size: 11px; font-family: Menlo;">begin</div>
<div style="font-size: 11px; font-family: Menlo;">;****************************************</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 + "_x.nc"</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;">~</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/*_x.nc /Volumes/out/.</div>
<div>sed -i -- 's/Amon/FMA/g' /Volumes/out/_x.nc</div>
<div>sed -i -- 's/r1i1p1//g' /Volumes/out/_x.nc</div>
<div>sed -i -- 's/.nc_x.nc/.nc/g' /Volumes/out/_x.nc</div>
</div>
<div style="font-size: 11px; font-family: Menlo;"><br>
</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>
</body>
</html>