Pages

Thursday, May 16, 2013

Some tips on running GrADS from the Windows Command Line and .bat scripts

If you are using GrADS through a linux operating system, chances are you are familiar with running GrADS from the command line, so this post is mostly aimed at the Windows users. This post will go through the basic instructions for running GrADS from your command line along with arguments and options. So lets first begin with a question.

Why would you want to run GrADS from the command line if your mouse is perfectly capable of opening GrADS via the "double click?"

The best answer that I can give you is that running GrADS from the command line vs. double clicking gives you the option to include arguments. Furthermore, the command syntax used is the same used in .bat scripts.

Now, there are a number of different options available that you can include on the command line when you open the program. The most important is the -help option. So if you type:

'grads -help'

Into the command line, you will get a whole list of options you can include when you run the program.

The options I have found to have been the most useful are these:

-l/p: Choosing to open GrADS in landscape or portrait mode

-b: running GrADS as a batch process (program is hidden from view)

-c: Allows you to execute a command (likely a script)

-x: Exits GrADS automatically after executing your command

There are other options that you can see with the -help command, but these are the ones I have found most useful.

Example: grads -lcx 'run script.gs'

This example would open GrADS in landscape mode and run the file "script.gs" and then exit after it was done.

Now, you can actually carry this command line method over to a Windows batch (.bat) script. Basically, a batch script is similar to a GrADS script, in that it is a file that can execute a bunch of Windows commands at once. Now, you can include a command to run GrADS with options within your batch script.

Now, this can be very useful as this way you can actually pass arguments from your windows script into your GrADS script. For example, if you wanted to set your lat/lon boundaries in your windows script, or your display color, you can do that. All you need to do, is set these variables inside your batch script, and call GrADS with the arguments attached.

Now, what you see in the GrADS script, that may be new to you, is the function declaration at the top. This is required if you want your script to read in the arguments that you laid out in the batch script. All this line does, is essentially tell GrADS that you are looking for arguments. You also see in the batch script you have spaces between each argument denoted by the ' '. This allows you to separate your arguments in GrADS using the subwrd() function.

But the ability to pass arguments from the windows script into the GrADS script can be very helpful, especially if you are running scripts that need variable input (e.g., date or time). As this method could allow you to run GrADS without having to constantly change the script around.

In any case, I just wanted to provide a few tips on running GrADS from the command line in Windows. I didn't go too in depth into windows scripting (I leave that to brighter minds), but hopefully you have an idea as to how to run GrADS in a batch script as well as how to pass arguments from one to the other.

how to run script in open grad recently i start working on open grad i have to run my own script because i want to find out the precipitation rate but everytime i face errors and my script is not working properly kindly help me or suggest me any portal so i will be able to learn about it.reply soon.