[ncl-talk] Passing a variable value from NCL to bash Script [SEC=UNCLASSIFIED]

Abheera Hazra hazra.abheera at gmail.com
Wed Mar 1 22:21:38 MST 2017


Thanks for the input Griffith, I shall try to code better next time.

Best,
Abheera

On Wed, Mar 1, 2017 at 5:43 PM, Griffith Young <griffith.young at bom.gov.au>
wrote:

> Hello Abheera,
>
>                 Apart from the obvious errors in your script, the main
> problem you have is that NCL cannot effect the environment of calling bash
> script.
>
>
>
>                 For example:
>
>                                 $ echo ${GRIFF}
>
>
>
>                                 $ ncl
>
>                                 Copyright (C) 1995-2013 - All Rights
> Reserved
>
>                                 University Corporation for Atmospheric
> Research
>
>                                 NCAR Command Language Version 6.1.2
>
>                                 The use of this software is governed by a
> License Agreement.
>
>                                 See http://www.ncl.ucar.edu/ for more
> details.
>
>                                 ncl 0> system("export GRIFF=GRIFF")
>
>                                 ncl 1>
>
>
>
>                                 $ echo ${GRIFF}
>
>
>
>                                 $ export GRIFF=GRIFF
>
>                                 $ echo ${GRIFF}
>
>                                 GRIFF
>
>
>
>                 You may be able to scan the output of your NCL script for
> the values you need, but that seems an incredibly convoluted approach.
>
>
>
>                 For example:
>
>                                 $ ncl << EOF > output.txt
>
>                                 > print("Output: Result; 1, 2, 3")
>
>                                 > EOF
>
>
>
>                                 $ grep Output output.txt
>
>                                 (0)     Output: Result; 1, 2, 3
>
>
>
>                                 $ result=$(grep Output output.txt)
>
>
>
>                                 $ echo ${result}
>
>                                 (0) Output: Result; 1, 2, 3
>
>
>
>                                 $ echo ${result##*;}
>
>                                 1, 2, 3
>
>
>
>                                 $ more output.txt
>
>                                  Copyright (C) 1995-2013 - All Rights
> Reserved
>
>                                 University Corporation for Atmospheric
> Research
>
>                                 NCAR Command Language Version 6.1.2
>
>                                 The use of this software is governed by a
> License Agreement.
>
>                                 See http://www.ncl.ucar.edu/ for more
> details.
>
>                                 (0)     Output: Result; 1, 2, 3
>
>
>
>                 Hope this is helpful.
>
>
>
> Regards,
>
>                 Griff.
>
>
>
>
>
> *From:* ncl-talk-bounces at ucar.edu [mailto:ncl-talk-bounces at ucar.edu] *On
> Behalf Of *Abheera Hazra
> *Sent:* Wednesday, 1 March 2017 6:21 PM
> *To:* ncl-talk at ucar.edu
> *Subject:* [ncl-talk] Passing a variable value from NCL to bash Script
>
>
>
> Hi,
>
>
>
> 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:
>
>
>
> ------------------------------------------
>
> #!/bin/bash
>
>
>
> w1=0.4
>
> dw1=0.1
>
> inc=0.001
>
>
>
> while awk 'BEGIN { if ('$dw1'<'$inc') {exit 1}}'; do
>
>
>
> cat <<'EOF' >> opti.error.ncl
>
>
>
> ;;;;Perform certain computations on w1 and update the w1 and dw1
>
> w1=nw1
>
> dw1=ndw1
>
>
>
>       system("w1=" + w1)
>
>       system("dw1=" + dw1)
>
>
>
> ;;;;w1 and dw1 need to be passed to the bash script
>
>
>
> EOF
>
>
>
>
>
>  ncl k1=${w1}  dw11=${dw1}  opti.error.ncl
>
>
>
> echo $w1
>
> echo $dw1
>
>
>
> done
>
> ------------------------------------------
>
>
>
> But this does not update w1 and dw1 values. Any input would be greatly
> appreciated.
>
>
>
> Thanks,
>
> Abheera
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170302/faac1720/attachment.html 


More information about the ncl-talk mailing list