<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">Think Rick + Dennis answered the reversed question. To pass a value out of NCL you probably need to write it to a file or some form. </div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">When you call system or systemfunc NCL launches a sub shell, so environment variables will disappear as soon as the call is finished. </div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">To stick with the bash loop, writing the variables to a text file would be the simplest solution. Then set the bash variables to the contents of the text file(s). </div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><div class="gmail_default"> asciiwrite("w1", w1 )<br></div><div class="gmail_default"> asciiwrite("dw1", dw1)</div><div class="gmail_default">....</div><div class="gmail_default">....</div><div class="gmail_default"> w1=$(cat w1)</div><div class="gmail_default"> dw1=$(cat dw1)</div><div class="gmail_default"><br></div></div><div class="gmail_default" style="font-family:verdana,sans-serif"><div class="gmail_default">Currently though, you're appending the ncl script to opti.error.ncl on each loop. Which doesn't seem right. Also it seems cleaner, given the pseudocode, to just do the loop within NCL and define the main script as a function with the w1, dw1 arguments. </div><div class="gmail_default"><br></div><div class="gmail_default"><br></div></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 1, 2017 at 8:59 AM, Rick Brownrigg <span dir="ltr"><<a href="mailto:brownrig@ucar.edu" target="_blank">brownrig@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div>Hi,<br><br></div>If I understand correctly, you can pass in the values on the command-line invocation of NCL as:<br><br></div> ncl w1=X dw1=Y<br><br></div>where X and Y are the actual values. To pass in string arguments, we tell people to place quotes around the whole var=value pair, like:<br><br></div> ncl 'myStringVar="foo"'<br><br></div>You can find more info about passing in arguments at:<br><br> <a href="http://ncl.ucar.edu/Document/Manuals/Ref_Manual/NclCLO.shtml" target="_blank">http://ncl.ucar.edu/Document/<wbr>Manuals/Ref_Manual/NclCLO.<wbr>shtml</a><br><br></div>Hope that helps...<br></div>Rick<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Wed, Mar 1, 2017 at 12:20 AM, Abheera Hazra <span dir="ltr"><<a href="mailto:hazra.abheera@gmail.com" target="_blank">hazra.abheera@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hi,<div><br></div><div>I am using NCL to calculate a few terms for an optimization algorithm and I am calling the NCL function from within a 'while loop' in a bash script. The 'while loop' runs till a certain condition is met and for the condition to be met, the bash script needs to accept a new value for an existing variable from the NCL script. I have tried using system, systemfunc with even the export command but nothing seems to work. The code looks as follows:</div><div><br></div><div>------------------------------<wbr>------------</div><div>#!/bin/bash<br></div><div><br></div><div><div>w1=0.4</div><div>dw1=0.1</div></div><div>inc=0.001</div><div><br></div><div>while awk 'BEGIN { if ('$dw1'<'$inc') {exit 1}}'; do<br></div><div><br></div><div><div>cat <<'EOF' >> opti.error.ncl</div></div><div><br></div><div>;;;;Perform certain computations on w1 and update the w1 and dw1</div><div>w1=nw1</div><div>dw1=ndw1</div><div><br></div><div><div> system("w1=" + w1)</div><div> system("dw1=" + dw1)</div></div><div><br></div><div>;;;;w1 and dw1 need to be passed to the bash script</div><div><br></div><div>EOF</div><div><br></div><div><br></div><div> ncl k1=${w1} dw11=${dw1} opti.error.ncl<br></div><div><br></div><div>echo $w1</div><div>echo $dw1</div><div><br></div><div>done</div><div>------------------------------<wbr>------------<br></div><div><br></div><div>But this does not update w1 and dw1 values. Any input would be greatly appreciated.</div><div><br></div><div>Thanks,</div><div>Abheera</div><div><br></div><div><br></div></div>
<br></div></div>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailma<wbr>n/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
<br>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/<wbr>mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>