Re: command line variable string

From: Andrea N. Hahmann <ahah_at_nyahnyahspammersnyahnyah>
Date: Fri Feb 03 2012 - 06:54:29 MST

Dear David

You can rewrite your loop to pass the right file name, but it is better to pass the variable name as a environment variable instead:

foreach I (*.nc)
   setenv FILE $I
   ncl plot_aice.ncl
end

Then, in the NCL script you have a line

   fname = getenv("FILE")

Hope this helps,
Andrea

From: David Hebert <david.hebert@nrlssc.navy.mil<mailto:david.hebert@nrlssc.navy.mil>>
Date: Fri, 3 Feb 2012 14:19:36 +0100
To: "ncl-talk@ucar.edu<mailto:ncl-talk@ucar.edu>" <ncl-talk@ucar.edu<mailto:ncl-talk@ucar.edu>>
Subject: command line variable string

I have a bunch of daily output netcdf files I would like to make plots of. For short

700_cice.2011-12-29.nc
700_cice.2011-12-30.nc
700_cice.2011-12-31.nc

My original intent was to pass the file name as a command line variable, then parse for dtg. When I do the following:

foreach i (*.nc)
    echo $i
    ncl plot_aice.ncl fname=$i
end

I get an error:

 700_cice.2011-12-29.nc (from echo $i)

 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.
fatal:syntax error: line 1 in file /tmp/ncl951.ncl before or near _cice
fname=700_cice
-------------^
fatal:(missing) has no file extension, can't determine type of file to open
fatal:Either file (f) isn't defined or variable (aice) is not a variable in the file
fatal:Execute: Error occurred at or near line 30 in file plot_aice.ncl

I don't think that underscore or dot are special characters that require backslash. Is there a better way to pass the file name on the command line? I see on the NCL website that one can use single quotes, but that will prevent the shell from expanding the variable $i.

Thanks for any suggestions!
David

--
David A. Hebert
Naval Research Lab
Stennis Space Center, MS 39529
david.hebert@nrlssc.navy.mil<mailto:david.hebert@nrlssc.navy.mil>
Phone: (228) 688-5846
Fax: (228) 688-4759

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Feb 3 06:54:35 2012

This archive was generated by hypermail 2.1.8 : Mon Feb 06 2012 - 14:24:56 MST