#  ncep.gui - last revision: October 12, 1997
#
#  Sample widget script for the NCEP/NCAR Re-analysis CDROM. 
#  Modify the first line ("chdir") for the location of your CDROM drive.
#
#  How to invoke this script:
#
#  At startup. Set the enviroment variable GAGUI with the
#  name of the script file, e.g., 
#
#  % setenv GAGUI ncep.gui
#
#  At the GrADS command line prompt. Simply type
#
#  ga> gui ncep.gui
#
#  Of course, you must have a version of GrADS built with
#  Athena Widgets support.
#
#  --
#   (c) 1997 by Arlindo da Silva
#
#   Permission is granted to any individual or institution to use,
#   copy, or redistribute this software so long as it is not sold for
#   profit, and provided this notice is retained. 
#
#  See also sample.gui, sample2.gui.
#.........................................................................


#  Mofify this for the location of your CDROM
#  Win32 Users: Use //d to indicate drive d:
#  ------------------------------------------
   chdir("//d/")    
   

#  Most "exec" commands are supported
#  ----------------------------------
   reinit
   set gxout shaded

   
# A "label" is an inactive widget which display some text, 
# e.g., an informative  title. The first argument, "root"
# in this case, is the name you give to the widget so that
# you can refer to it later on
# -------------------------------------------------------
  MakeLabel(root,"NCEP/NCAR Re-analysis CDROM")

# This command creates a dropdown menu called " File "
# as usual, the first argument "file" is the name of the
# widget
# -------------------------------------------------------
  MakeMenu ( file, " File " )


# Once you make a memu, you create its items. For the first item:
# --------------------------------------------------------------
      MakeMenuItem(open,  file, "Open",             Load,    "open")

# The parameters this particular item are:
#     open    the name of the item widget
#     file    the menu the item belongs to (see MakeMenu above)
#     "Open"  This is the text it displays on the screen
#     Load    this is the callback name, i.e., the widget invokes
#             this function when pressed. This particular callback
#             pops up a "file finder" widget, and after the user
#             clicks on a file name it executes the grads command
#             "open" (see last argument) on this file. A list
#             of the other available callbacks can be found in the
#             end of this file.
#     "open"  Argument to be passed to the callback. In this 
#             particular case, it is the GrADS command to be
#             executed on the file.
#  The definition of the other items in this menu follows.
      MakeMenuItem(sdf,   file, "SDF Open",         Load,    "sdfopen")
      MakeMenuItem(xdf,   file, "XDF Open",         Load,    "xdfopen")
      MakeMenuItem(fsel,  file, "File Selection ",  FileSel, NULL )
      MakeMenuItem(browse,file, "View Text File",   Browse,  NULL)
      MakeMenuItem(junk,  file, "_______________",  NULL,    NULL )
      MakeMenuItem(exec,  file, "Exec",             Load,    "exec")
      MakeMenuItem(run,   file, "Run",              Load,    "run")
      MakeMenuItem(gui,   file, "GUI",              Load,    "gui")
      MakeMenuItem(junk,  file, "_______________",  NULL,    NULL )
      MakeMenuItem(fresh, file, "Refresh",          Cmd,     "  ")
      MakeMenuItem(init,  file, "Reinit",           Cmd,     "reinit")
      MakeMenuItem(exit,  file, "Exit",             Cmd,     "quit")


# A menu for gx metafile printing related commands
# ------------------------------------------------
  MakeMenu ( print, " Print " )
      MakeMenuItem(printit, print, "Print",         Cmd,   "print")
      MakeMenuItem(enable,  print, "Enable  Print", Load,  "enable print")
      MakeMenuItem(disable, print, "Disable Print", Cmd,   "disable print")

# A menu with assorted internal options
# -------------------------------------
  MakeMenu ( options, " Options " )
      MakeMenuItem(shade,  options, "Shaded",      Cmd, "set gxout shaded" )
      MakeMenuItem(cont,   options, "Contour",     Cmd, "set gxout contour" )
      MakeMenuItem(grfill, options, "Grid Fill",   Cmd, "set gxout grfill" )
      MakeMenuItem(grvals, options, "Grid Values", Cmd, "set gxout grid" )
      MakeMenuItem(vec,    options, "Vector",      Cmd, "set gxout vector" )
      MakeMenuItem(strm,   options, "Streamlines", Cmd, "set gxout stream" )
      MakeMenuItem(bar,    options, "Bar Chart",   Cmd, "set gxout bar" )
      MakeMenuItem(line,   options, "Line Plot",   Cmd, "set gxout line" )
      MakeMenuItem(barb,   options, "Wind Barbs",  Cmd, "set gxout  barb" )
      MakeMenuItem(junk,   options, "_______________",  NULL, NULL )
      MakeMenuItem(ci,     options, "Contour Interval",  CmdStr, "set cint" )
      MakeMenuItem(tit,    options, "Draw Title", CmdStr, "draw title " )
      MakeMenuItem(cbar,   options, "Color Bar",  Cmd, "run cbarn" )


# Creates simple buttons. Buttons work pretty much like menu items
# but they do not belong to any menu and are directly clickable.
# ------------------------------------------------------------------
  MakeButton( clear,  "Clear",      Cmd,      "clear" )
  MakeButton( quit,   "Quit",       Cmd,      "quit" )
  MakeButton( prompt, " ga> ",  CmdWin,  NULL )
  MakeButton( rein, "Reinit", Cmd,     "reinit")

# A menu for defining GrADS dimensions. This is very crude right now.
# I will be developing a specific callback with rubber bands
# etc. for these functions. Stay tuned. 
# ------------------------------------------------------------------
  MakeMenu( dim, "Dim")
      MakeMenuItem(lat,  dim, "Latitude",  CmdStr, "set lat " )
      MakeMenuItem(lon,  dim, "Longitude", CmdStr, "set lon " )
      MakeMenuItem(lev,  dim, "Level",     CmdStr, "set lev " )
      MakeMenuItem(time, dim, "Time",      CmdStr, "set time " )
      MakeMenuItem(junk, dim, "_________", NULL,   NULL )
      MakeMenuItem(x,    dim, "x",         CmdStr, "set x " )
      MakeMenuItem(y,    dim, "y",         CmdStr, "set y " )
      MakeMenuItem(z,    dim, "z",         CmdStr, "set z " )
      MakeMenuItem(t,    dim, "t",         CmdStr, "set t " )

# Frequently used buttons (and toggle)
# -----------------------------------
  MakeButton( var,  "Var",    VarSel,  NULL )
  MakeToggle( hold, "Hold",   FALSE,  NULL, Toggle,  "hold" )
  MakeButton( prev, " << ",   Display, "<<" )
  MakeButton( play, "Display",   Display, "DISPLAY" )
  MakeButton( next, " >> ",   Display, ">>" )


# CDROM specific menu's
# ---------------------
  MakeMenu(cc, "Climate")
      MakeMenuItem(c1, cc, "Z u v T q ...", Open, "open climate/prflcl" )
      MakeMenuItem(c2, cc, "Heat Fluxes", Open, "open climate/heatcl" )
      MakeMenuItem(c3, cc, "Potential Vorticity", Open, "open climate/ipvcl" )

  MakeMenu(mm, "Monthly")
      MakeMenuItem(m1, mm, "Z u v T q ...",  Open, "open monthly/prfl" )
      MakeMenuItem(m2, mm, "Potential Vorticity",  Open, "open monthly/ipv" )

  MakeMenu(hd, "Z")
      MakeMenuItem(xxx, hd, "  Daily",  NULL, NULL )
      MakeMenuItem(xxx, hd, "_________",  NULL, NULL )
      MakeMenuItem(hd5, hd, "Z  30 hPa", Open, "open daily/z30" )
      MakeMenuItem(hd4, hd, "Z 200 hPa", Open, "open daily/z200" )
      MakeMenuItem(hd3, hd, "Z 500 hPa", Open, "open daily/z500" )
      MakeMenuItem(hd2, hd, "Z 700 hPa", Open, "open daily/z700" )
      MakeMenuItem(hd1, hd, "Z 850 hPa", Open, "open daily/z850" )

  MakeMenu(ud, "u")
      MakeMenuItem(xxx, ud, "  Daily",  NULL, NULL )
      MakeMenuItem(xxx, ud, "_________",  NULL, NULL )
      MakeMenuItem(ud5, ud, "U  30 hPa", Open, "open daily/u30" )
      MakeMenuItem(ud4, ud, "U 200 hPa", Open, "open daily/u200" )
      MakeMenuItem(ud3, ud, "U 500 hPa", Open, "open daily/u500" )
      MakeMenuItem(ud2, ud, "U 700 hPa", Open, "open daily/u700" )
      MakeMenuItem(ud1, ud, "U 850 hPa", Open, "open daily/u850" )

  MakeMenu(vd, "v")
      MakeMenuItem(xxx, vd, "  Daily",  NULL, NULL )
      MakeMenuItem(xxx, vd, "_________",  NULL, NULL )
      MakeMenuItem(vd5, vd, "V  30 hPa", Open, "open daily/v30" )
      MakeMenuItem(vd4, vd, "V 200 hPa", Open, "open daily/v200" )
      MakeMenuItem(vd3, vd, "V 500 hPa", Open, "open daily/v500" )
      MakeMenuItem(vd2, vd, "V 700 hPa", Open, "open daily/v700" )
      MakeMenuItem(vd1, vd, "V 850 hPa", Open, "open daily/v850" )

  MakeMenu(td, "T")
      MakeMenuItem(xxx, td, "  Daily",  NULL, NULL )
      MakeMenuItem(xxx, td, "_________",  NULL, NULL )
      MakeMenuItem(td5, td, "T  30 hPa", Open, "open daily/t30" )
      MakeMenuItem(td4, td, "T 200 hPa", Open, "open daily/t200" )
      MakeMenuItem(td3, td, "T 500 hPa", Open, "open daily/t500" )
      MakeMenuItem(td2, td, "T 700 hPa", Open, "open daily/t700" )
      MakeMenuItem(td1, td, "T 850 hPa", Open, "open daily/t850" )
      MakeMenuItem(td0, td, "T at 2m", Open, "open daily/t2m" )

  MakeMenu(qd, "q")
      MakeMenuItem(xxx, qd, "  Daily",  NULL, NULL )
      MakeMenuItem(xxx, qd, "_________",  NULL, NULL )
      MakeMenuItem(qd3, qd, "Q 500 hPa", Open, "open daily/q500" )
      MakeMenuItem(qd2, qd, "Q 700 hPa", Open, "open daily/q700" )
      MakeMenuItem(qd1, qd, "Q 850 hPa", Open, "open daily/q850" )
      MakeMenuItem(qd0, qd, "Q at 2m", Open, "open daily/q2m" )

  MakeMenu(sd, "Sfc")
      MakeMenuItem(xxx,  sd, "     Daily",  NULL, NULL )
      MakeMenuItem(xxx,  sd,"__________________",  NULL, NULL )
      MakeMenuItem(sd1,  sd, "Sea Level Pressure",  Open, "open daily/mslp" )
      MakeMenuItem(sd2,  sd, "10 meter u-wind",  Open, "open daily/u10m" )
      MakeMenuItem(sd3,  sd, "10 meter v-wind",  Open, "open daily/v10m" )
      MakeMenuItem(sd4,  sd, "Zonal stress",  Open, "open daily/uflx" )
      MakeMenuItem(sd5,  sd, "Meridional stress", Open, "open daily/vflx" )
      MakeMenuItem(xxx,  sd,"__________________",  NULL, NULL )
      MakeMenuItem(sd6,  sd, "Precipitation",  Open, "open daily/prate" )
      MakeMenuItem(sd7,  sd, "Latent Heat Flux",  Open, "open daily/lhtfl" )
      MakeMenuItem(sd8,  sd, "Sensible Heat Flux",  Open, "open daily/" )
      MakeMenuItem(xxx, sd,"__________________",  NULL, NULL )
      MakeMenuItem(sd9, sd, "Shortwave  [down]",  Open, "open daily/dswrfsfc" )
      MakeMenuItem(sda1, sd, "Longwave  [down]",  Open, "open daily/dlwrfsfc" )
      MakeMenuItem(sda2, sd, "Shortwave [up]",  Open, "open daily/uswrfsfc" )
      MakeMenuItem(sda3, sd, "Longwave  [up]",  Open, "open daily/ulwrfsfc" )

  MakeMenu(hh, "Help")
      MakeMenuItem(h1, hh, "About this Software", NULL, NULL )
      MakeMenuItem(h2, hh, "About this CDROM", Browse, "read.ams")
      MakeMenuItem(h3, hh, "BAMS Article", Browse, "paper/bamspapr.asc")


# Once you define buttons and menus you may want to enforce their
# relative position. The very first button is always placed at the
# upper left corner.
# ----------------------------------------------------------------

  # First row 
  SetWidgetPos(file,    PLACE_UNDER, root, NO_CARE,     NULL)
  SetWidgetPos(print,   PLACE_UNDER, root, PLACE_RIGHT, file )
  SetWidgetPos(options, PLACE_UNDER, root, PLACE_RIGHT, print )
  SetWidgetPos(dim,     PLACE_UNDER, root, PLACE_RIGHT, options )
  SetWidgetPos(rein,    PLACE_UNDER, root, PLACE_RIGHT, dim )
  SetWidgetPos(prompt,  PLACE_UNDER, root, PLACE_RIGHT, rein )

  # Second row
  SetWidgetPos(cc, PLACE_UNDER, file, NO_CARE,     NULL)
  SetWidgetPos(mm, PLACE_UNDER, file, PLACE_RIGHT, cc)
  SetWidgetPos(hd, PLACE_UNDER, file, PLACE_RIGHT, mm)
  SetWidgetPos(ud, PLACE_UNDER, file, PLACE_RIGHT, hd)
  SetWidgetPos(vd, PLACE_UNDER, file, PLACE_RIGHT, ud)
  SetWidgetPos(td, PLACE_UNDER, file, PLACE_RIGHT, vd)
  SetWidgetPos(qd, PLACE_UNDER, file, PLACE_RIGHT, td)
  SetWidgetPos(sd, PLACE_UNDER, file, PLACE_RIGHT, qd)
  SetWidgetPos(hh, PLACE_UNDER, file, PLACE_RIGHT, sd)

  # third row
  SetWidgetPos(hold,  PLACE_UNDER, cc, NO_CARE,     NULL)
  SetWidgetPos(var,   PLACE_UNDER, cc, PLACE_RIGHT, hold )
  SetWidgetPos(prev,  PLACE_UNDER, cc, PLACE_RIGHT, var )
  SetWidgetPos(play,  PLACE_UNDER, cc, PLACE_RIGHT, prev )
  SetWidgetPos(next,  PLACE_UNDER, cc, PLACE_RIGHT, play )
  SetWidgetPos(clear, PLACE_UNDER, cc, PLACE_RIGHT, next )
  SetWidgetPos(quit,  PLACE_UNDER, cc, PLACE_RIGHT, clear )


# You can optionally select a font for ALL widgets
# ------------------------------------------------
# GetFont(font,"-*-helvetica-bold-o-normal--*-*-*-*-*-*-*-*" )
  GetFont(font,"-*-helvetica-bold-o-normal--12-*-*-*-*-*-*-*" )
  AllWidgetFont(font)

  GetFont(font,"-*-helvetica-bold-o-normal--14-*-*-*-*-*-*-*" )
  SetWidgetFont(root,myfont)


# In order to make your widgets appear on the screen you *must*
# issue this command.
# -------------------------------------------------------------
  ShowDisplay()
  

# After your widgets appear on the screen, you can set the color 
# of your widgets. The following colors are pre-defined:
# white, back, red, green, blue, yellow.
# --------------------------------------------------------------
  GetNamedColor(gray,"grey")
  GetNamedColor(Blue,"LightSkyBlue")
  GetNamedColor(pink,"gold")         # pink is actually gold, get it?
  AllFgColor(black)
  AllBgColor(Blue)
  SetBgColor(root,white)
  SetFgColor(root,red)
  SetFgColor(prompt,yellow)
  SetBgColor(prompt,red)
  SetBgColor(prev,pink)
  SetBgColor(play,pink)
  SetBgColor(next,pink)
  SetBgColor(hold,gray)
  SetBgColor(var,gray)
  SetBgColor(clear,gray)
  SetBgColor(rein,gray)
  SetBgColor(quit,gray)


# And you must call this function at the end of your first GUI script.
# This instructs the X Toolkit to enter an infinite loop, monitoring
# keyboard and mouse events. Repeating: you *must* call MainLoop().
# -------------------------------------------------------------------
  MainLoop()

#........................................................................
#
# APPENDIX: Currently available callback functions
#
#     Browse    Opens a text file, such as a help file, on a separate
#               window.
#     Cmd       Executes a generic GrADS command
#     CmdStr    Like Cmd, but the user is prompted for an additional
#               string to be appended to the GrADS command.
#     CmdWin    Invokes a window for GrADS command line interface.
#               User can click on past commands from a list.
#     CmdLine   Invokes the standard GrADS command line interface.
#               When the command line is active the other widgets
#               are not available (may be fixed in the future).
#     Display   A generic callback for displaying the current variable
#               (or expression) set with VarSel. The options are:
#                  <<    decrements time and executes display
#                 PLAY   starts animation from current to last time
#                DISPLAY just executes display
#                  >>    increments time and  executes display
#               If the "hold" toggle state is OFF (the default),
#               the screen is cleared before displaying.
#     Edit      Like browse, but the user can edit the file. This simple
#               text editor is integrated with GrADS, providing a very
#               elementary Integrated Development Enviroment (IDE) for
#               GrADS scripts. In particular, the script being edited
#               can be executed by clicking on a button (not
#               implemented yet).
#     FileSel   Pops up a scrollable list and asks the user to selected
#               a file among the currently opened GrADS files (including
#               SDFs). The selected file becomes the default.
#     Load      Pops up a "file finder" widget, and after the user
#               clicks on a file name it executes a GrADS command
#               specified as the last argument. In case of "open" or 
#               "sdfopen" the files becomes the default, and the
#               user is asked to select a variable from this file.
#     Open      Similar to Load, but the file name must be specified.
#     Toggle    Turn internal options ON/OFF. The only internal
#               option currently supported is "hold". This callback is
#               usually used with MakeToggle(), see example above.
#     VarSel    Pops up a scrollable list and asks the user to selected
#               a variable from the default file. The user can also
#               type a generic GrADS expression instead of selecting
#               a single variable.
#     NULL      Does not do anything, used for inactive buttons.
#
#........................................................................


