[gradsusr] if else statement with string arguments

James T. Potemra jimp at hawaii.edu
Mon Nov 26 15:48:35 EST 2018


Hi Tracey,

It should work.  Maybe it's how you're converting from an argument to a 
variable.  This little script is an example:

function main(arg)
  if ( arg = "" )
   say "You need to supply an arg"
  else
   region = subwrd(arg,1)
   if ( region = 'conus' ); say "Cont US"; endif
  endif
return

With the examples:

ga-> sample_script
You need to supply an arg
ga-> sample_script conus
Cont US
ga-> sample_script pacific
ga->

On 11/26/18 10:21 AM, Tracey wrote:
> Hi Bill,
>
> It still doesn't seem to work even when I take out the parentheses.  
> Appreciate your suggestion though!  Can GrADS handle argument strings 
> in if/else statements?
>
> Thanks,
> Tracey
>
> On Mon, Nov 26, 2018 at 3:08 PM Bill Reilly 
> <bill_reilly at compuserve.com <mailto:bill_reilly at compuserve.com>> wrote:
>
>     Tracey:
>
>     Try taking out the parentheses () and see if it works.
>
>     Bill
>
>     --
>
>     Bill Reilly
>
>     (+34) 686-110-748
>
>     bill at passageweather.com  <mailto:bill at passageweather.com>
>     www.passageweather.com  <http://www.passageweather.com>
>
>     bill at brwebworks.com  <mailto:bill at brwebworks.com>
>     www.brwebworks.com  <http://www.brwebworks.com>  
>
>     On 26/11/2018 20:18, Tracey wrote:
>>     Hi Jeff,
>>
>>     The input string is being read into the script correctly, as I've
>>     put a "say region" into the script right before the if statement
>>     and it is correctly outputting "conus."  So it seems to be the
>>     actual if statement that is not working for some reason.
>>
>>     Thanks,
>>     Tracey
>>
>>     On Mon, Nov 26, 2018 at 2:03 PM Jeff Duda <jeffduda319 at gmail.com
>>     <mailto:jeffduda319 at gmail.com>> wrote:
>>
>>         First test whether the input string is being read into the
>>         script correctly. Then check to see if the if block is being
>>         tripped by inserting print statements.
>>
>>         Jeff Duda
>>
>>         On Mon, Nov 26, 2018 at 11:56 AM Tracey <tdorian10 at gmail.com
>>         <mailto:tdorian10 at gmail.com>> wrote:
>>
>>             Hi,
>>
>>             I was wondering if any GrADS users could help me with
>>             this issue I am having. In my GrADS script, I have:
>>
>>             if (region ='conus')
>>               'set lat 25 58'
>>               'set lon 230 297'
>>             endif
>>
>>             But the above lines are not working. When I run the GrADS
>>             script, I input a "region" as an argument.  I want to say
>>             if the region is "conus", then set the longitudes and
>>             latitudes to these set numbers.  No matter how I change
>>             the quotations and the spaces, it doesn't seem to be
>>             re-setting the latitudes and longitudes.  What am I doing
>>             wrong?
>>
>>             Thank you,
>>             Tracey
>>             _______________________________________________
>>             gradsusr mailing list
>>             gradsusr at gradsusr.org <mailto:gradsusr at gradsusr.org>
>>             http://gradsusr.org/mailman/listinfo/gradsusr
>>
>>
>>
>>         -- 
>>         Jeff Duda, Research Scientist
>>         University of Colorado Boulder
>>         Cooperative Institute for Research in Environmental Sciences
>>         NOAA/OAR/ESRL/Global Systems Division
>>         Boulder, CO
>>         _______________________________________________
>>         gradsusr mailing list
>>         gradsusr at gradsusr.org <mailto:gradsusr at gradsusr.org>
>>         http://gradsusr.org/mailman/listinfo/gradsusr
>>
>>
>>
>>     _______________________________________________
>>     gradsusr mailing list
>>     gradsusr at gradsusr.org  <mailto:gradsusr at gradsusr.org>
>>     http://gradsusr.org/mailman/listinfo/gradsusr
>
>     _______________________________________________
>     gradsusr mailing list
>     gradsusr at gradsusr.org <mailto:gradsusr at gradsusr.org>
>     http://gradsusr.org/mailman/listinfo/gradsusr
>
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gradsusr.org/pipermail/gradsusr/attachments/20181126/03f0a3c0/attachment-0001.html>


More information about the gradsusr mailing list