Bin Guan's GrADS Script Library1

Newly added: legend.gs.

Script
Usage2 (Notation: <>: required arguments; [<>]: optional arguments.)
All-in-One.tar.gz
  Download all.
astudt.gs
  Two-tailed Student t-test.

  Usage: astudt <dof> <p> [<t>]
     <dof>: degree of freedom.
     <p>: probability.
     <t>: t-statistic. Defaults to astudtout.

  Dependencies: studt.gs

  See also studt.gs
day2pen.gs
  Daily-to-pentadal regridding.

  Usage: day2pen -v <var1> [<var2>...] [-n <name1> [<name2>...]] [-u <undef>] [-o <file>] [-p <path>]
     <var>: daily variable.
     <name>: name for pentadal variable. Same as <var> if unset.
     <undef>: undef value for .dat and .ctl. Defaults to the value found in ctlinfo.
     <file>: common name for output .dat and .ctl pair. No file output if unset.
     <path>: path to output files. Do NOT include trailing "/". Defaults to current path.

  Dependencies: parsestr.gsf, parseopt.gsf, qdims.gsf
deseason365.gs
  Take out seasonal cycle from a daily or other sub-monthly time series.

  Usage: deseason365 <input> [<output> [<climatology> [<clim_start> [<clim_end>]]]]
     <input>: input field.
     <output>: output field. Defaults to <input>.
     <climatology>: climatology.
     <clim_start>: climatology is defined over the period of <clim_start> to <clim_end>. Specified in world coordinate, such as MMMYYYY.
     <clim_end>: climatology is defined over the period of <clim_start> to <clim_end>. Specified in world coordinate, such as MMMYYYY.

  Note: 365_day_calendar option must be used in data file.

  Dependencies: setclim365.gs, qdims.gsf
deseason.gs
  Take out seasonal cycle from a monthly/seasonal time series.

  Usage: deseason <input> [<output> [<climatology> [<clim_start> [<clim_end>]]]]
     <input>: input field.
     <output>: output field. Defaults to <input>.
     <climatology>: climatology.
     <clim_start>: climatology is defined over the period of <clim_start> to <clim_end>. Specified in world coordinate, such as MMMYYYY.
     <clim_end>: climatology is defined over the period of <clim_start> to <clim_end>. Specified in world coordinate, such as MMMYYYY.

  Dependencies: qdims.gsf
drawbox.gs

Plot: 1
  Draw an unfilled "box" under any map projection.

  Usage: drawbox <lon1> <lon2> <lat1> <lat2>
     <lon1>: Beginning longitude.
     <lon2>: Ending longitude. Must be >= <lon1>.
     <lat1>: Beginning latitude.
     <lat2>: Ending latitude. Must be >= <lat1>.
drawline.gs

Plot: 1
  Draw lines in specified locations.

  Usage: drawline Lon|Lat|Lev|Val|Time <coordinate> [<coordinate>...] [Lon|Lat|Lev|Val|Time <coordinate> [<coordinate>...]] ...
    <coordinate>: world coordinate conforming to GrADS convention. E.g., time should be specified as HH:MMZDDMMMYYYY, MMMYYYY, etc.

  Example 1: drawline Lon 180 Lat 0
             Draw international date line and equator in a 2-D map.

  Example 2: drawline Val -1 0 1
             Draw three lines with values -1, 0 and 1 in a line graph.

  Note: Proper capitalization MUST be used for key words Lon, Lat, Lev, Val and Time.
drawstr.gs

Plot: 1
  Annotate a plot.

  Usage 1: drawstr -t <text1> [<text2>...] [-p <position1> [<position2>...]] [-xo <xoffset1> [<xoffset2>...]] [-yo <yoffset1> [<yoffset2>...]]
  Usage 2: drawstr -T <title1> [<title2>...] [-xo <xoffset1> [<xoffset2>...]] [-yo <yoffset1> [<yoffset2>...]] [-scale <scalingfactor>]
     <text>: Panel labels. Text beginning with a minus sign or containing spaces must be double quoted.
     <position>: Position of text. Refer to schematic below. Defaults to "1 2 3...".
     <xoffset>: Horizontal offset to default position. Defaults to 0.
     <yoffset>: Vertical offset to default position. Defaults to 0.
     <title>: Title for a whole column. Refer to schematic below. Text beginning with a minus sign or containing spaces must be double quoted.
     <scalingfactor>: scaling factor. Defaults to 1.
                <title>
1 2 3
---------------------------------
| |
| |
| |
9| plot |10
| |
| |
|4 5|
---------------------------------
6
7 8
  Note: The "-T" and "-t" options cannot be used together.

  Dependencies: parsestr.gsf, parseopt.gsf
fcorr.gs
  Point-by-point correlations between two fields.

  Usage: fcorr <input1> <input2> [<output>]
     <input1>: Input field 1.
     <input2>: Input field 2.
     <output>: Output field. Defaults to "fcorrout".

  Dependencies: qdims.gsf
hist.gs
  Histogram.

  Usage: hist <input> <output> <left_edge> <right_edge> <bin_size>
     <input>: input field (can have horizontal dimensions; NO vertical dimension).
     <output>: histogram.
     <left_edge>: left edge.
     <right_edge>: right edge.
     <bin_size>: bin size.

  Example: set time Jan1901 Dec2000
                  hist precip preciphist -2 2 0.25
                  set time Jan1901
                  set lev -2 2
                  set xyrev on
                  display preciphist

  Dependencies: qdims.gsf
lagcorr.gs
  Lag correlations between two variables.

  Usage: lagcorr <input1> <input2> [<output> [<lag_start> [<lag_end>]]]
     <input1>: Independent variable. Can have a vertical dimension. NO horizontal dimensions.
     <input2>: Dependent variable. Can have a vertical dimension and/or up to two horizontal dimensions.
     <output>: Output variable. Defaults to "lagcorrout".
               E.g., "set t 0" and then <output>(t-3) will be lag correlation when <input2> leads <input1> by 3 time steps.
     <lag_start>: Beginning lag. E.g., <lag1>=-3 for <input2> leading <input1> by 3 time steps. Defaults to 0.
     <lag_end>: Ending lag. E.g., <lag2>=3 for <input2> lagging <input2> by 3 time steps. Defaults to 0.

  Note: Do NOT use <output>(t=number), instead, "set t 0" and use <output>(t+number) to get the value for Lag(number).
        To use/plot all lags at once, simply "set t <lag1> <lag2>".

  Dependencies: qdims.gsf
lagregr.gs
  Lag regressions between two variables.

  Usage: lagregr <input1> <input2> [<output> [<lag_start> [<lag_end>]]]
     <input1>: Independent variable. Can have a vertical dimension. NO horizontal dimensions.
     <input2>: Dependent variable. Can have a vertical dimension and/or up to two horizontal dimensions.
     <output>: Output variable. Defaults to "lagregrout".
               E.g., "set t 0" and then <output>(t-3) will be lag regression when <input2> leads <input1> by 3 time steps.
     <lag_start>: Beginning lag. E.g., <lag1>=-3 for <input2> leading <input1> by 3 time steps. Defaults to 0.
     <lag_end>: Ending lag. E.g., <lag2>=3 for <input2> lagging <input2> by 3 time steps. Defaults to 0.

  Note: Do NOT use <output>(t=number), instead, "set t 0" and use <output>(t+number) to get the value for Lag(number).
        To use/plot all lags at once, simply "set t <lag1> <lag2>".

  Dependencies: qdims.gsf
legend.gs

Plot: 1
  Draw legend for a line graph (which must have been produced by plot.gs).

  Usage: legend [-orient v|h] [-xo <xoffset>] [-yo <yoffset>] [-scale <scalingfactor>]
     -orient h: use for horizontal oriention. Default is vertical.
     <xoffset>: Horizontal offset to default position (i.e., top-left). Defaults to 0.
     <yoffset>: Vertical offset to default position (i.e., top-left). Defaults to 0.
     <scalingfactor>: scaling factor for mark size. Will NOT affect string size (Use "set strsiz" for that). Defaults to 1.

  "legend help" prints this usage information.

  Dependencies: parsestr.gsf, parseopt.gsf

  See also: plot.gs
ltrend.gs   Linear trend (least-squares fitting).

  Usage: ltrend <input> [<output> [<slope> [<rmse>]]]
    <input>: input field.
    <output>: output field, i.e., the fitted trend. Defaults to <input>.
    <slope>: slope of the fitted trend, i.e., change of <input> per time step.
    <rmse>: root mean square error.

  Dependencies: qdims.gsf
mon2ssn.gs
  Monthly-to-seasonal regridding.

  Usage: mon2ssn -v <var1> [<var2>...] [-n <name1> [<name2>...]] [-u <undef>] [-o <file>] [-p <path>]
     <var>: monthly variable.
     <name>: name for seasonal variable. Same as <var> if unset.
     <undef>: undef value for .dat and .ctl. Defaults to the value found in ctlinfo.
     <file>: common name for output .dat and .ctl pair. No file output if unset.
     <path>: path to output files. Do NOT include trailing "/". Defaults to current path.

  Dependencies: parsestr.gsf, parseopt.gsf, qdims.gsf
mon2yr
  Monthly-to-yearly regridding.

  Usage: mon2yr -v <var1> [<var2>...] [-n <name1> [<name2>...]] [-c <centered_on>] [-u <undef>] [-o <file>] [-p <path>]
     <var>: monthly variable.
     <name>: name for yearly variable. Same as <var> if unset.
     <centered_on>: one of the calendar months (JAN, FEB, MAR, etc.) to put the annual mean value. Defaults to JAN.
     <undef>: undef value for .dat and .ctl. Defaults to the value found in ctlinfo.
     <file>: common name for output .dat and .ctl pair. No file output if unset.
     <path>: path to output files. Do NOT include trailing "/". Defaults to current path.

  Dependencies: parsestr.gsf, parseopt.gsf, qdims.gsf 
norm.gs
  Normalization of a time series.

  Usage: norm <input> [<output> [<mean> [<std> [<base_period_start> [<base_period_end>]]]]]
     <input>: input time series.
     <output>: output time series. Defaults to <input>.
     <mean>: sample mean.
     <std>: sample standard deviation.
     <base_period_start>: Normalization is over the period of <base_period_start> to <base_period_end>. Specified in world coordinate, e.g., Jan1960.
     <base_period_end>: Normalization is over the period of <base_period_start> to <base_period_end>. Specified in world coordinate, e.g., Dec1990.

  Dependencies: qdims.gsf
one2one.gs
  One-two-one smoothing of a time series.

  USAGE: one2one <input> [<output> [<iterations> [<option>]]]
     <input>: input field.
     <output>: output field. Defaults to <input>.
               If <output> = DISPLAY, only a graph will be displayed.
     <iterations>: number of iterations. Defaults to 1.
                   If <iterations> <=0, no smoothing will be performed.
     <option>: set to "interannual" to smooth over the same calendar months/seasons."

  Dependencies: qdims.gsf
parseopt.gsf
  Ancillary script
parsestr.gsf
  Ancillary script
plot.gs
  Draw a line graph.

  Usage: plot -v <var1> [<var2>...] [-r <range_from> <range_to>] [-m <mark1> [<mark2>...]] [-s <style1> [<style2>...]] [-c <color1> [<color2>...]] [-k <thick1> [<thick2>...]] [-t <text1> [<text2>...]]
     <var>: variable to be plotted.
     <range_from>, <range_to>: set the axis limit. Defaults to the minimum and maximum values.
     <mark>: Defaults to "2 3 4...", i.e., open circle, closed circle, open square, closed square, and so on.
     <style>: Defaults to current GrADS setting.
     <color>: Defaults to "1 2 3...", i.e., foreground color, red, green, dark blue, and so on.
     <thick>: Defaults to current GrADS setting.
     <text>: Text to be shown in the legend (use "legend.gs"). Text beginning with a minus sign or containing spaces must be double quoted.

  Dependencies: parsestr.gsf, parseopt.gsf, qdims.gsf
ppp.gs
  Produce image output in EPS and other formats.

  Usage: ppp <outfile> [<format1>] [<format2>]...
    <outfile>: full path of output file. Do NOT include the suffix (e.g., use mypath/myfile, instead of mypath/myfile.eps).
    <format>: currently eps, eps.clip, pdf and png are supported; defaults to eps. The only difference between eps and eps.clip is that the former has a timestamp in the header (for printing purpose).

  Note: png format requires eps2png. See http://search.cpan.org/~jv/eps2png/ for more information.
qdims.gsf
  Ancillary script
rmean.gs
  Running mean of a time series.

  USAGE 1: rmean <input> <window> [<output>]

           Calculate running mean using the given length of window and assign result to <output>.

  USAGE 2: rmean <input> <start> <end> [<output>]

           Calculate running mean using the window specified by <start> and <end>, and assign
           result to <output>.

           If not specified, <output> defaults to <input>.
           If <output> = DISPLAY, the result is displayed and not defined in a variable.

  EXAMPLE 1: rmean sst 4 sst4trmn
             Successively averages the field sst over 4 time steps t-2, t-1, t, t+1 and
             defines the  result as sst4trmn.

  EXAMPLE 2: rmean sst -2 1 DISPLAY
             Successively averages the field sst over 4 time steps t-2, t-1, t, t+1 and
             displays the  result. 
rms.gs
  Root mean squares of a time series.

  Usage: rms <input> [<rms>]
     <input>: input time series.
     <rms>: root mean squares. Defaults to "rmsout".

  Dependencies: qdims.gsf
save.gs
  Save variables to .dat and .ctl pair.

  USAGE: save -v <var1> [<var2>...] [-n <name1> [<name2>...]] [-u <undef>] [-o <file>] [-p <path>]
     <var>: variable to be saved.
     <name>: name for a variable in saved .ctl file. Original name will be used if unset.
     <undef>: undef value for .dat and .ctl. Defaults to the value found in ctlinfo.
     <file>: common name for .dat and .ctl pair. Defaults to saveout.
     <path>: path to saved files. Do NOT include trailing "/". Defaults to current path.

  Dependencies: parsestr.gsf, parseopt.gsf, qdims.gsf
setclim365.gs
  Dependencies: qdims.gsf
shadcon.gs
  Plot a 2-D graph using shading and/or contours.

  USAGE: shadcon <colormap>[<option>] <var> <cint> [<blackout> [<blackout2>]]
     <colormap>: Available color maps: blue2red, red2blue, brown2green.
     <option>: If unset, the number of colors used by the color map will depend on the min/max value of the field to
               be plotted as well as the contour interval/shreshold. Set to any integer >=1 if a common color map,
               consisting of <option> colors on either side of zero, is to be shared by multiple plots. Set to 0 to
               use all colors pre-defined for the specific color map.
     <var>: variable to be plotted.
     <cint>: shading/contour interval.
     <blackout>: values between -<blackout>*<cint> to <blackout>*<cint> will NOT be shaded. Must be a non-negative integer.
                 All values will be shaded if <blackout>=0. No values will be shaded if <blackout>=inf. Defaults to 1.
     <blackout2>: values between -<blackout>*<cint> to <blackout>*<cint> will NOT be contoured. Must be a non-negative integer.
                  All values will be shaded if <blackout>=0. No values will be shaded if <blackout>=inf. Defaults to <blackout>.

  EXAMPLE 1: shadcon blue2red sst 0.1
             This will plot the variable sst using a blue-to-red color map. The number of colors used will
             be dynamically determined. Shading/contouring interval/shreshold is 0.1.

  EXAMPLE 2: shadcon brown2green5 precip 0.05 2
             This will plot the variable precip using a brown-to-green color map consisting of 5+5=10 colors.
             Shading/contouring interval (shreshold) is 0.05x2=0.1.

  EXAMPLE 3: shadcon brown2green0 precip 0.05 2 1
             As EXAMPLE 2, except (a) using all pre-defined colors for the brown-to-green color map, and (b) contouring shreshold is 0.05x1=0.05.

  EXAMPLE 4: shadcon brown2green0 precip 0.05 2 inf
             As EXAMPLE 3, except without contours.

  EXAMPLE 5: shadcon brown2green0 precip 0.05 inf 1
             As EXAMPLE 3, except without shading.

  Dependencies: qdims.gsf
smth9x.gsf
  Ancillary script
ssn2day.gs
  Seasonal-to-daily regridding.

  Usage: ssn2day -v <var1> [<var2>...] [-n <name1> [<name2>...]] [-u <undef>] [-o <file>] [-p <path>]
     <var>: seasonal variable.
     <name>: name for daily variable. Same as <var> if unset.
     <undef>: undef value for .dat and .ctl. Defaults to the value found in ctlinfo.
     <file>: common name for output .dat and .ctl pair. No file output if unset.
     <path>: path to output files. Do NOT include trailing "/". Defaults to current path.

  Note: Input data MUST be 3-month means centered on Jan, Apr, Jul and Oct, and the first (last) time step MUST be Jan (Oct).
        Output data will start from 01Jan and ends at 31Dec (the last Dec always has missing values).

  Dependencies: parsestr.gsf, parseopt.gsf, qdims.gsf
ssn2mon.gs
  Seasonal-to-monthly regridding.

  Usage: ssn2mon -v <var1> [<var2>...] [-n <name1> [<name2>...]] [-u <undef>] [-o <file>] [-p <path>]
     <var>: seasonal variable.
     <name>: name for monthly variable. Same as <var> if unset.
     <undef>: undef value for .dat and .ctl. Defaults to the value found in ctlinfo.
     <file>: common name for output .dat and .ctl pair. No file output if unset.
     <path>: path to output files. Do NOT include trailing "/". Defaults to current path.

  Note: Input data MUST be 3-month means centered on Jan, Apr, Jul and Oct, and the first (last) time step MUST be Jan (Oct).
        Output data will start from Jan and ends at Dec (the last Dec always has missing values).

  Dependencies: parsestr.gsf, parseopt.gsf, qdims.gsf
studt.gs
  Two-tailed Student t-test.

  Usage: studt <dof> <t> [<p>]
         <dof>: degree of freedom.
         <t>: t-statistic.
         <p>: probability. Defaults to studtout.

  See also astudt.gs
subplot.gs

Plot: 1 2 3
  Make multi-panel plot.

  USAGE: subplot <ntot> <idx> [<ncol>] [-tall 0|1] [-tight 0|1] [-xtight 0|1] [-ytight 0|1] [-scale <scalingfactor>] [-xy <xyratio>] [-xs <xspacing>] [-ys <yspacing>] [-xp <xpadding>] [-yp <ypadding>] [-sameh2left 0|1] [-samey2left 0|1]
     <ntot>: total number of panels to be plotted; no preset limit. Do NOT have to be # of rows times # of columns; will be rounded up to that value.
     <idx>: index of the panel to be plotted, numbered column-wise, from top to bottom, then left to right.
            In each row/column, panels with smaller <idx> MUST be plotted earlier; no constraints otherwise.
     <ncol>: number of columns; no preset limit. Defaults to 2 (even if <ntot>=1).
     -tall 1: use if the plot is so tall that cannot otherwise be fitted into one page.
     -tight 1: use if no spaces are wanted between panels.
     -xtight 1: use if no horizontal spaces are wanted between panels.
     -ytight 1: use if no vertical spaces are wanted between panels.
     <scalingfactor>: scaling factor. Defaults to 1.
     <xyratio>: aspect ratio of the plotting area. Defaults to 1.667. An optimal value will be calculated for latlon map projections.
     <xspacing>: horizontal spacing (in addition to initial value 0). Defaults to 0.
     <yspacing>: vertical spacing (in addition to initial value 0). Defaults to 0.
     <xpadding>: horizontal padding (in addition to initial value 0.33). Defaults to 0.
     <ypadding>: vertical padding (in addition to initial value 0.22). Defaults to 0.
     -sameh2left 1: to set panel height the same to the immediate left panel.
     -samey2left 1: to align panel top to the immediate left panel.

  Note: Spacing refers to blank space between virtual pages; can be any value.
        Padding refers to space between virtual page boundaries and plotting area; cannot be negative values.

  Dependencies: parsestr.gsf, parseopt.gsf, qdims.gsf
tmskt365.gs
  Mask out certain calendar days (or pentads, depending on the time resolution) of a time series.

  Usage 1 (for daily time series): tmskt <input> <start> <end> [<output>]
     <input>: input daily time series.
     <start>: the first Julian day not to mask out, e.g., 32 for Feb 1.
     <end>: the last Julian day not to mask out, e.g., 59 for Feb 28.
     <output>: output daily time series. Defaults to <input>.
               If <output> = DISPLAY, only a graph will be displayed.

  Example: tmskt sst 32 59
           This would set all days but Feb 1-28 to missing values for the variable sst.

  Usage 2 (for pentad time series): tmskt <input> <start> <end> [<output>]
     <input>: input pentad time series.
     <start>: the first Julian pentad not to mask out.
     <end>: the last Julian pentad not to mask out.
     <output>: output pentad time series. Defaults to <input>.
               If <output> = DISPLAY, only a graph will be displayed.

  Dependencies: setclim365.gs, qdims.gsf
tmskt.gs

Plot: 1
  Mask out certain calendar months (or seasons/years, depending on the time resolution) of a time series.

  Usage 1 (for monthly time series): tmskt <input> <start> <end> [<output>]
     <input>: input monthly time series.
     <start>: the first calendar month not to mask out, e.g., 12 for December.
     <end>: the last calendar month not to mask out, e.g., 2 for Feburary.
     <output>: output monthly time series. Defaults to <input>.
                    If <output> = DISPLAY, only a graph will be displayed.

  Example: tmskt sst 12 2
           This would set all months but December, January and February to missing values for the variable sst.

  Usage 2 (for seasonal time series): tmskt <input> <start> <end> [<output>]
     <input>: input seasonal time series.
     <start>: the first calendar season not to mask out, e.g., 1 for winter.
     <end>: the last calendar season not to mask out, e.g., 4 for fall.
     <output>: output seasonal time series. Defaults to <input>.
                    If <output> = DISPLAY, only a graph will be displayed.

  Example: tmskt sst 1 1 sstwin
             This would set all seasons but winter to missing values for the variable sst, and store the new time series in sstwin.

  Usage 3 (for yearly time series): tmskt <input> <start> <end> [<output>]
     <input>: input yearly time series.
     <start>: the first calendar year not to mask out, e.g., 1901.
     <end>: the last calendar year not to mask out, e.g., 2000.
     <output>: output yearly time series. Defaults to <input>.
                    If <output> = DISPLAY, only a graph will be displayed.

  Example: tmskt sst 1901 2000 sst20c
             This would set all years but 1901-2000 to missing values for the variable sst, and store the new time series in sst20c.

  Dependencies: qdims.gsf

1 All scripts have been tested for GrADS version 1.9b3/b4 under GNU/Linux. Some scripts need modifications in order to run in Window$.
2 The usage information shown here is for preview purpose and may not be up-to-date. Run any script without arguments will print the most current information.

Disclaimer: The computer programs contained in this web page are Copyright (C) 2004-2008 Bin Guan. The programs are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Permission is granted to copy, distribute and/or modify these programs under the terms of the GNU General Public License (GPL). A copy of the GNU GPL is available at http://www.gnu.org/licenses/gpl.html.