<div dir="ltr"><div>Here is a method using only standard out, and no temp file. The leading colons (:) are needed in this case, to ensure unique match strings.</div><div><br></div><div>program.ncl:</div><div><br></div><div> ;;Perform certain computations ...</div><div> print (":w1_out=" + w1)</div><div><div> print (":dw1_out=" + dw1)</div></div><div> exit</div><div><br></div><div>loop.sh:</div><div><br></div><div> ncl_out="`ncl k1=${w1} dw11=${dw1} opti.error.ncl`"</div><div> w1=`echo "$ncl_out" | grep :w1_out= | cut -f2 -d=`</div><div><div> dw1=`echo "$ncl_out" | grep :dw1_out= | cut -f2 -d=`</div></div><div><br></div><div> echo $w1</div><div> echo $dw1</div><div><br></div><div>--Dave</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 1, 2017 at 8:38 AM, Alan Brammer <span dir="ltr"><<a href="mailto:abrammer@albany.edu" target="_blank">abrammer@albany.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div 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 style="font-family:verdana,sans-serif"><br></div><div 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 style="font-family:verdana,sans-serif"><br></div><div 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 style="font-family:verdana,sans-serif"><br></div><div style="font-family:verdana,sans-serif"><div> asciiwrite("w1", w1 )<br></div><div> asciiwrite("dw1", dw1)</div><div>....</div><div>....</div><div> w1=$(cat w1)</div><div> dw1=$(cat dw1)</div><div><br></div></div><div style="font-family:verdana,sans-serif"><div>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><br></div></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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style: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/M<wbr>anuals/Ref_Manual/NclCLO.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="m_3568698625610078477gmail-m_3851461249003171213h5">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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="m_3568698625610078477gmail-m_3851461249003171213h5"><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></div></div></blockquote></div></div></blockquote></div></div>
</blockquote></div><br></div></div>