<div dir="ltr"><div>Hi Rick, <br></div><div>Thank you for the explanation.</div><div>I will look into the suggested link.</div><div>Best regards,</div><div>Jayant<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 17, 2022 at 11:18 PM Rick Brownrigg <<a href="mailto:brownrig@ucar.edu">brownrig@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>HI Jayant,</div><div><br></div><div>I don't think that is going to work. There's a hierarchy of system processes going on there: your outer shell process, which invokes ncl as a process, which in turn invokes an "inner" shell process with the system() command. The environment variable gets set in that inner process, which promptly terminates. There's no way to pass environment settings back up the hierarchy that I am aware of.</div><div><br></div><div>I'm not a bash wizard, but what comes to mind is to write a file from ncl, and have your outer shell read that. So for example, print() the values you need and invoke ncl as:</div><div><br></div><div> ncl -nQ myscript.ncl >myvars.txt. (the -n keeps ncl from enumerating its output lines, and the -Q keeps it from printing the copyright stuff)</div><div><br></div><div>Then do something in your bash script similar to that described with this link:</div><div><br></div><div> <a href="https://www.cyberciti.biz/faq/unix-howto-read-line-by-line-from-file/" target="_blank">https://www.cyberciti.biz/faq/unix-howto-read-line-by-line-from-file/</a></div><div><br></div><div>I hope that helps...</div><div>Rick</div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 17, 2022 at 6:40 PM Jayant via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi! <br></div><div>I have a shell script to start with where some variables (year, month,tstep,variable name) are defined and passed to a ncl script. Next, the ncl script performs further analysis (reading variables, analyzing). The dimensionality (2-d or 3-d or 4-d) of the variable is determined inside the ncl script, but I need this information back in the shell script. Is it possible to get it? Roughly, I tried this</div><div>----------------------</div><div><span style="font-family:monospace">myscript.ncl</span></div><div><span style="font-family:monospace">yr=toint(getenv("YEAR"))</span></div><div><span style="font-family:monospace">mn=toint(getenv("MON"))</span></div><div><span style="font-family:monospace">varin=getenv("VNAME")</span></div><div><span style="font-family:monospace">...</span></div><div><span style="font-family:monospace">finp=addfile("modelout_"+yr+"_"+mn+".bin","r")</span></div><div><span style="font-family:monospace">vinp=finp->varin<br></span></div><div><span style="font-family:monospace">...</span></div><div><span style="font-family:monospace">vdimin=dimsizes(varin)</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace"><b>system("export VDIMS="+vdimin) ; is it the correct way?</b><br></span></div><div><span style="font-family:monospace">...<br></span></div><div><span style="font-family:monospace">----------------------</span></div><div><span style="font-family:monospace">run_ncl.sh<br></span></div><div><span style="font-family:monospace">#!/bin/sh</span></div><div><span style="font-family:monospace">export YEAR=2019</span></div><div><span style="font-family:monospace">export MON=8</span></div><div><span style="font-family:monospace">export TSTEP=6</span></div><div><span style="font-family:monospace">export VNAME="PREC"</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">ncl myscript.ncl</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace"><b>echo $VDIMS ; returning empty ???</b><br></span></div><div><span style="font-family:monospace">-----------------------------</span></div><div><br></div><div><br></div></div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote></div>
</blockquote></div>