*                          log.gs

*  The purpose of this GrADS script is to create a a log of GrADS commands
*  entered from the console in interactive mode, until the command "stop"
*  is encountered.

*  The log will be saved as a script file called grads.log or
*  another name of your choice.

*  The script variable 'rc' is given the return code from the GrADS command.
*  (This will always be an integer value).

*  The log file should be edited later to weed out any invalid GrADS commands
*  which you typed.

say 'Save a list of commands to be generated to a file.'

say '3 choices for naming the file the grads commands will be saved to:'
say 'WARNING: There is no check if you will be over-writing an existing file.'
say ''
say 'Enter "<cr>"                   to choose the default file name grads.log'
say ''
say 'Enter   "n"   or   "name"      to choose a complete file name.'
say ''
say 'Enter   "p"   or   "-"         to choose a prefix to the name grads.log.'

pull choice

if (choice = '' | choice = 'n' | choice = 'name' | choice = 'p' | choice = '-')
say ''
else
say 'Improper choice of file name. Error Exit from log.gs. Try again.'
return
endif

if (choice = '')
filename = 'grads.log'
endif

if (choice = 'n' | choice = 'name')
say 'Enter complete name of the file you wish to save the grads commannds to:'
pull filename
endif

if (choice = 'p' | choice = '-')
say 'Enter prefix to grads.log'
pull prefix
filename = prefix'_grads.log'
endif

say ''
say 'Enter your list of commands.'
say 'Type the command "stop", to terminate the command list and exit log.gs.'
say ''

while (1)
  say 'ga> '
  pull cmd
  if (cmd='stop'); break; endif;
  cmd
  say result
  cmd2 = ''''%cmd%''''
  rc = write (filename,cmd2)
endwhile


say 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
say 'All commands typed in so far during this GrADS log.gs session '
say 'have been saved to a file called 'filename
say 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
