Re: how to get user input

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue, 9 Sep 2008 20:34:20 -0600

Dennis is right, there's no way to have NCL directly prompt for user
input.

However, you can create a shell script that prompts for user input,
and then pass this input
to an NCL script via command line options that Dennis mentioned in his
email.

Here's a sample example of a C-shell script that prompts for a
filename and a year, and passes
this information to the NCL script. Assume this script is called
"run_ncl.csh":

#!/bin/csh -f

echo -n "Input year: "
set year = $<

echo -n "Input filename: "
set fname = $<

eval ncl year=$year 'fname=\""$fname"\"' test.ncl

Make sure this file is executable:

  chmod gou+x run_ncl.csh

Then, your NCL script (call it "test.ncl") would look something like
this:

begin
  if(.not.isvar("year")) then
    year = 2000 ; Set a default
  end if

  if(.not.isvar("fname")) then
    fname = "temp.nc" ; Set a default
    exit
  end if

  print("filename = '" + fname + "'")
  print("year = " + year)

; Do some more stuff in your NCL script...

end

To run the shell script, type:

./run _ncl.csh

This will prompt you for a year and a filename, and the NCL script
will echo these values. You can do
this with any scripting language you want, like tcsh, bash, or even
Python.

--Mary

On Sep 9, 2008, at 5:23 PM, Joe Grim wrote:

> Hi,
>
> This probably seems like a simple question, but I can't find an
> answer to this problem anywhere on the NCL page. When running an
> NCL program, how does one ask the user for a value? For example, my
> program reads in a field for 5 seasons, but I want it to ask the
> user which season to plot. In FORTRAN I would just use the read
> function, but I can't find its equivalent for NCL. Could you help
> me out here?
>
> Thanks a lot!
>
> Joe Grim
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Sep 09 2008 - 20:34:20 MDT

This archive was generated by hypermail 2.2.0 : Wed Sep 10 2008 - 07:38:41 MDT