Re: puzzled with using getenv for getting shell environment variable

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Tue Nov 01 2011 - 12:33:24 MDT

Hi Eric,
In your shell script you have made FILI into an environment variable, but fil is only a shell variable. That is why NCL cannot see it. In your 'for' loop you need to export $fil before calling ncl.
 -dave

On Nov 1, 2011, at 10:45 AM, Erik N wrote:

> I'm having difficulty with passing a shell environment variable to the
> ncl script with the getenv command.
> The environment variable is "fil."
> The shell script works fine.
> But when I look at the ncl output using the print statement, the
> string is missing. It is supposed to say "ncep2_grid_Experiment_.... "
> Is this expected?
>
> -Erik
>
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; shell script
> [nobleeu@Erik-Nobles-iMac] ncep2_grid $ cat loop_ncl_script.sh
>
> #!/usr/bin/env bash
> # loop through set of files with a ncl script
> export WORKDIR=$HOME/myWorkDir/POST_PROCESSING/20km_CAM_6_hour/winds/ncep2_grid
> export SCRIPTDIR=.$HOME/myWorkDir/myScripts/ncl/
>
> # List Files
> cd $WORKDIR
> echo $PWD
> export FILI="ls ncep2_grid_Experiment_*"
> echo $FILI
> # Loop through list of files
> for fil in $FILI
> do
> if [ ! -e "$fil" ] # Check if file exists.
> then
> echo "$fil does not exist."; echo
> continue # On to next.
> fi
> # echo "Extract Variable from $fil . "
> # Execute script <- make sure that ncl script reads env. variable $fil
> time ncl test.ncl
> done
> echo "Finished."
> exit 0
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;NCL CODE
> ;;test.ncl
>
> file_in = getenv("fil")
> print(file_in)
>
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;TERMINAL OUTPUT when executing shell script
>
> [nobleeu@Erik-Nobles-iMac] ncep2_grid $ ./loop_ncl_script.sh
> /Users/nobleeu/myWorkDir/POST_PROCESSING/20km_CAM_6_hour/winds/ncep2_grid
> ls ncep2_grid_Experiment_01_UV.nc ncep2_grid_Experiment_02_UV.nc
> ncep2_grid_Experiment_03_UV.nc ncep2_grid_Experiment_04_UV.nc
> ncep2_grid_Experiment_05_UV.nc ncep2_grid_Experiment_06_UV.nc
> ncep2_grid_Experiment_07_UV.nc ncep2_grid_Experiment_08_UV.nc
> ncep2_grid_Experiment_09_UV.nc ncep2_grid_Experiment_10_UV.nc
> ncep2_grid_Experiment_11_UV.nc ncep2_grid_Experiment_12_UV.nc
> ncep2_grid_Experiment_13_UV.nc ncep2_grid_Experiment_14_UV.nc
> ncep2_grid_Experiment_15_UV.nc ncep2_grid_Experiment_16_UV.nc
> ncep2_grid_Experiment_17_UV.nc ncep2_grid_Experiment_18_UV.nc
> ncep2_grid_Experiment_19_UV.nc ncep2_grid_Experiment_20_UV.nc
> ncep2_grid_Experiment_21_UV.nc ncep2_grid_Experiment_22_UV.nc
> ncep2_grid_Experiment_23_UV.nc ncep2_grid_Experiment_24_UV.nc
> ncep2_grid_Experiment_25_UV.nc ncep2_grid_Experiment_26_UV.nc
> ncep2_grid_Experiment_27_UV.nc ncep2_grid_Experiment_28_UV.nc
> ncep2_grid_Experiment_29_UV.nc ncep2_grid_Experiment_30_UV.nc
> ncep2_grid_Experiment_31_UV.nc ncep2_grid_Experiment_32_UV.nc
> ls does not exist.
>
> Working on ncep2_grid_Experiment_01_UV.nc
> Copyright (C) 1995-2011 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 6.0.0
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
>
>
> Variable: file_in
> Type: string
> Total Size: 8 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : missing
> (0) missing
>
> real 0m0.173s
> user 0m0.011s
> sys 0m0.008s
>
> <snip>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Nov 1 12:33:30 2011

This archive was generated by hypermail 2.1.8 : Tue Nov 01 2011 - 13:43:04 MDT