[Thread Prev][Thread Next][Index]

RE: [ferret_users] Checking the argument in Go script



Thanks for your help.  This is some really good information and this should help with my GO scripts.  For the moment I can get an immediate readout to the screen as suggested by Ryo, but no doubt will use your ideas in future.

 

Mark

 

From: owner-ferret_users@xxxxxxxx <owner-ferret_users@xxxxxxxx> On Behalf Of Ansley Manke
Sent: Thursday, 22 December 2022 6:02 AM
To: ferret_users@xxxxxxxx
Subject: Re: [ferret_users] Checking the argument in Go script

 

Here's a good discussion about arguments to jnl scripts:

https://ferret.pmel.noaa.gov/Ferret/documentation/users-guide/introduction/GO-FILES#_VPINDEXENTRY_126, especially the section "Arguments to GO tools".  Arguments are Ferret symbols, so symbol parsing and substitution syntax works here.

One thing I often want to do is to check whether the argument has been given, and if so, does it have a valid value.  Says I'm expecting a value for the year in argument 1.

This says, assign the value of the argument to a variable. If they didn't send in a value, then assign 0 to my variable. Then the script can check to see if that's a valid value. (The parentheses are optional.)

   let year = ($1%0%)
   if `year gt 2020` then ...

 Or do something like this:

   if `($1%0%) LT 2015 or ($1%0%) GT 2023` THEN
      say argument 1 is not in the valid range of years: $1
      exit/script
   endif

The QUERY command lets you do this kind of checking, and issue an error message if needed, without the IF statements, but it doesn't do anything you couldn't do with an  IF-THEN-ENDIF sequence.  See it in some of the scripts included with PyFerret:

yes? go/help land.jnl

 

On 12/21/2022 3:28 AM, William Kessler - NOAA Federal wrote:

 

I've never heard of QUERY either, but there are some situations when using the $n arguments fail. For instance using them to write filenames when two of these in sequence ($1$2), or with an underscore before it.

 

I just define regular symbols for them:

def sym dol1 `$1`

def sym dol2 `$2`

 

These can be used freely.

 

You can also have a script define a default value that the argument will take if the command that calls the script doesn't include a value:

 

def sym symbol_name $1"default_value"

 

Billy

 

 

On Tue, Dec 20, 2022 at 10:03 PM Ryo Furue <furue@xxxxxxxxxx> wrote:

Dear Mark,

 

I have a very simple question.  I want to check the value of arguments in GO scripts, e.g. $1 $2 and so on when a program is running.

 

I suppose you want to print out the values on your screen.  If so,

 

\cancel mode verify

say 1st arg = ($1)

say 2nd arg = ($2)

set mode/last verify

 

(Switching off and on of the verify mode is optional.)

 

 

If I include the command QUERY $1 in a GO script the value is returned to the terminal but the program stops.

 

Because I've never heard of QUERY, I'll leave this issue for more knowledgeable people.

 

Ryo

 


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement