c
c     Copyright (c) 1999,2000, Compaq Computer Corporation
c
c     See the file "license.terms" for information on usage and redistribution
c     of this file, and for a DISCLAIMER OF ALL WARRANTIES.
c
      subroutine pmcomp(rreal, iint, llog, cchar,
     1                  nreal, nint, nlog, nchar,
     2                  ctitle, ctext,
     3                  nferrl, linter,
     4                  pmfile)
      implicit none
c
c     Callable interface to the compare plot subsystem of Postmini
c
c     Programmer: John Faricelli
c     Callable interface
c     Date:    12-May-92
c
c     Input arguments:
c
c     RREAL  (real)     Real    information array
c     IINT   (integer)  Integer information array
c     LLOG   (logical)  Logical information array
c     CCHAR  (char*(*)) Character information array
c     NREAL  (integer)  Size of RREAL
c     NINT   (integer)  Size of IINT
c     NLOG   (integer)  Size of LLOG
c     NCHAR  (integer)  Size of CCHAR
c     CTITLE (character) Title for plot
c     NFERRL (integer) FORTRAN logical unit number to be used for all
c                      output messages if Postmini is run non-interactively
c     LINTER (logical) If .TRUE., Postmini is assumed to be called
c                      from an interactive program.
c                      If .FALSE., Postmini is assumed to be called from
c                      a program running without user intervention (batch)
c     PMFILE (character) Name of Postmini command file (optional, see below)
c
c     Output parameters:
c
c     PMFILE (character) Name of the Postmini save file that was last explicitly
c                        written by the user with a "SAVE" command.
c                        If no file was explicitly saved, the default file
c                        POSTMINI.PMI is returned.
c
c     Interaction of PMFILE with LINTER:
c
c     If LINTER is .TRUE.
c        If PMFILE is all blanks, then Postmini runs in interactive mode.
c        Else, interpret PMFILE, execute plot to screen, and return.
c
c     If LINTER is .FALSE.
c        If PMFILE is all blanks, then output a plot
c           to a file given by parameter CTEXT (with extension .PS) and return.
c           The default 'hardcopy' device is used (hardcoded to PostScript)
c        Else, interpret PMFILE, output plot to a file given by parameter
c           CTEXT, and return. The 'hardcopy' device may be specified in
c           PMFILE. An appropriate extension is added depending on the hardcopy
c           device.
c
c     The following are optional. NOTE: if you need to specify CCHAR(4)
c     then you must also specify CCHAR(1),CCHAR(2),CCHAR(3)
c     CCHAR(1) - X axis title
c     CCHAR(2) - Y axis title
c     CCHAR(3) - X axis units
c     CCHAR(4) - Y axis units
c
c     LLOG(1)  - If .TRUE., go directly to plot menu on first entry
c     LLOG(2)  - If .TRUE., then do not write .PMI file
c
c     NOTE: The arrays RREAL, IINT may not be used.
c           They are included in the calling sequence for future expansion.
c
c     Note: we declare the one dimensional arrays as (*), so that
c     we don't crash if the corresponding size is input as zero.
c
      integer nreal, nint, nlog, nchar, nferrl
c     Actual size: nreal
      real    rreal(*)
c     Actual size: nint
      integer iint(*)
c     Actual size: nlog
      logical llog(*)
      logical linter
c     Actual size: nchar
      character*(*) cchar(*)
      character*(*) pmfile, ctitle, ctext
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'mesh.cmn'
      include 'data.cmn'
      include 'io.cmn'
      include 'plot.cmn'
      include 'compare.cmn'
      include 'units.cmn'
      include 'annotations.cmn'
      include 'defaults.cmn'
      include 'save.cmn'
      include 'callable.cmn'
      include 'version.cmn'
c
c     local variables
c
      logical invalid, err, batchmode, do_pmi
      integer string_len, mode
      character*10 answer, ext
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
c     init_defaults will only allow one initialization, so it's safe to
c     call anywhere.
      call init_defaults(luttyo, linter)
      call menu_set_logical_units(luttyi, luttyo)
c
      call date(date_string)
c
CC    NOT FOR CALLABLE INTERFACE
CC      call get_command_line_args
c
c     Set batch mode (non-interactive) if asked by calling procedure.
      lrestore = .FALSE.
      if( linter ) then
         lbatch = .FALSE.
c        If we are passed in a PMI file, then execute and return
         if( string_len(pmfile) .ne. 0 ) then
            lrestore = .TRUE.
         endif
      else
         lbatch = .TRUE.
         luttyo = nferrl
         call mathmode_set_lun(luttyo)
      endif
c
c     Load data passed in to Postmini arrays (PROTOTYPE CODE, this is a dummy
c     routine!!)
      batchmode = .FALSE.
      call load_callable_xy_data(batchmode,err)
      if( err ) return
c     Set filename for use with making hardcopy files
      binfilestem = ctext
c
c     Reset autoscaling flags (callable only)
      comp_lfirst   = .TRUE.
      lfirst_read   = .TRUE.
c     Set title
      plot_title    = ctitle
c     Set axis information
      call set_axis_callable(rreal, iint, llog, cchar,
     1     nreal, nint, nlog, nchar)
c
c     If non-interactive run, call restore and then return
c
      if( lbatch ) then
         lplotfile = .TRUE.
         call get_plotfile_extension(default_hc_name,ext)
         call make_plotfile_name(given_plotfilename,ctext,ext)
         if( string_len(pmfile) .eq. 0 ) then
c           Perform default plot
            mode = 1
            call compare_plot(.FALSE.,.FALSE.,mode)
         else
            call do_restore_plot(pmfile,err)
         endif
         return
      else
         lplotfile = .FALSE.
      endif
c
c     If 'lrestore' mode run, call restore and then return
c
      if( lrestore ) then
         call do_restore_plot(pmfile,err)
         return
      endif
c
c     Check for 'initial plot' flag...
      if( nlog .ge. 1 ) then
         if( llog(1) ) then
            mode = 1
            call compare_plot(.FALSE.,.FALSE.,mode)
         endif
      endif
c
c     Else it's full interative. Put up main menu...
c
400   call clear_screen
      write(luttyo,300) version_string
300   format(' ','POSTMINI X-Y plot subsystem (',a,')'//
     1    ' ','Add       - Select a 1D cut to plot'/
     1    ' ','Clear     - Delete all 1D data entries'/
     1    ' ','Delete    - Delete a 1D data entry'/
     1    ' ','Exit      - Return to main menu'/
     1    ' ','List      - List all current data entries'/
     1    ' ','Plot      - Plot all current data entries'/
     1    ' ','Modify    - Change the plot attributes for an entry'/
     1    ' ','Quit      - Return to main menu (same as exit)'/
     1    ' ','Read      - Read new data file'/
     1    ' ','SHOw      - Print information about a 1D entry'//
     1    ' ','DEFault   - Modify default plot characteristics'/
     1    ' ','Save      - Save plot information in a file '/
     1    ' ','SHEll     - Run operating system commands'/
     1    ' ','Window    - Manage windows on workstation')
410   write(luttyo,305)
305   format(/' ','Request? ',$)
      read(luttyi,310,end=10100) answer
310   format(a)
      call upcase(answer)
c
c     switch on answer
c
      invalid = .FALSE.
      if( answer(1:1) .eq. 'A' ) then
          call compare_add
      else if( answer(1:1) .eq. 'C' ) then
          call compare_clear
      else if( answer(1:3) .eq. 'DEF' ) then
          call change_defaults
      else if( answer(1:1) .eq. 'D' ) then
          call compare_delete
      else if( answer(1:1) .eq. 'E' ) then
          goto 10100
      else if( answer(1:1) .eq. 'H' ) then
          mode = 2
          call compare_plot(.FALSE.,.FALSE.,mode)
      else if( answer(1:1) .eq. 'L' ) then
          call compare_list
      else if( answer(1:1) .eq. 'M' ) then
          call compare_modify
      else if( answer(1:1) .eq. 'P' ) then
          mode = 1
          call compare_plot(.FALSE.,.FALSE.,mode)
      else if( answer(1:1) .eq. 'Q' ) then
         goto 10100
      else if( answer(1:1) .eq. 'Q' ) then
         goto 10100
      else if( answer(1:1) .eq. 'S' ) then
         if( answer(1:2) .eq. 'SH' ) then
            if( answer(3:3) .eq. 'O' ) then
               call compare_show
            elseif ( answer(3:3) .eq. 'E' ) then
               call spawn_subprocess('POSTMINI', 'Postmini> ')
            else
               invalid = .TRUE.
            endif
         else
            call save_plot
         endif
      else if( answer(1:1) .eq. 'W' ) then
          call vs_window_manager
      else
         invalid = .TRUE.
      endif
c
      if( invalid ) then
         write(luttyo,390) answer
390      format(' ','Invaid request: ''',a,'''')
         goto 410
      else
         goto 400
      endif
c
c     the end of the road...
c
10100 continue
c
c     Write save file
      if( nlog .ge. 2 ) then
         do_pmi = .NOT. llog(2)
      else
         do_pmi = .TRUE.
      endif
      if( save_plot_type .ne. PLOT_NULL_COMMAND .and.
     1    gks_is_open .and. do_pmi ) then
c        Third argument says to create a new file (VMS only)
         call write_savefile('POSTMINI.PMI',current_window_id,
     1                       .FALSE.,err)
         pmfile = savefilename
      else
         pmfile = ' '
      endif
c
CC      if( gks_is_open ) call close_gks
c
      return
      end
c
      subroutine pmplxy(rreal, iint, llog, cchar,
     1                  nreal, nint, nlog, nchar,
     2                  ctitle, ctext,
     3                  nferrl, linter,
     4                  pmfile)
      implicit none
c
c     Callable interface to the compare plot subsystem of Postmini
c     Call goes directly to plot menu of compare plot
c
c     Programmer: John Faricelli
c     Callable interface
c     Date:    8-Mar-93
c
c     Input arguments:
c
c     RREAL  (real)     Real    information array
c     IINT   (integer)  Integer information array
c     LLOG   (logical)  Logical information array
c     CCHAR  (char*(*)) Character information array
c     NREAL  (integer)  Size of RREAL
c     NINT   (integer)  Size of IINT
c     NLOG   (integer)  Size of LLOG
c     NCHAR  (integer)  Size of CCHAR
c     CTITLE (character) Title for plot
c     NFERRL (integer) FORTRAN logical unit number to be used for all
c                      output messages if Postmini is run non-interactively
c     LINTER (logical) If .TRUE., Postmini is assumed to be called
c                      from an interactive program.
c                      If .FALSE., Postmini is assumed to be called from
c                      a program running without user intervention (batch)
c     PMFILE (character) Name of Postmini command file (optional, see below)
c
c     Output parameters:
c
c     PMFILE (character) Name of the Postmini save file that was last explicitly
c                        written by the user with a "SAVE" command.
c                        If no file was explicitly saved, the default file
c                        POSTMINI.PMI is returned.
c
c     Interaction of PMFILE with LINTER:
c
c     If LINTER is .TRUE.
c        If PMFILE is all blanks, then Postmini runs in interactive mode.
c        Else, interpret PMFILE, execute plot to screen, and return.
c
c     If LINTER is .FALSE.
c        If PMFILE is all blanks, then output a plot
c           to a file given by parameter CTEXT (with extension .PS) and return.
c           The default 'hardcopy' device is used (hardcoded to PostScript)
c        Else, interpret PMFILE, output plot to a file given by parameter
c           CTEXT, and return. The 'hardcopy' device may be specified in
c           PMFILE. An appropriate extension is added depending on the hardcopy
c           device.
c
c     The following are optional. NOTE: if you need to specify CCHAR(4)
c     then you must also specify CCHAR(1),CCHAR(2),CCHAR(3)
c     CCHAR(1) - X axis title
c     CCHAR(2) - Y axis title
c     CCHAR(3) - X axis units
c     CCHAR(4) - Y axis units
c
c     LLOG(1)  - Make plot immediately upon entry to subroutine,
c                then wait for user input (only in interactive mode)
c     LLOG(2)  - Make X axis logarithmic
c     LLOG(3)  - Make Y axis logarithmic
c     LLOG(4)  - If .TRUE., then do not output .PMI file
c
c     NOTE: The arrays RREAL, IINT may not be used.
c           They are included in the calling sequence for future expansion.
c
c     Note: we declare the one dimensional arrays as (*), so that
c     we don't crash if the corresponding size is input as zero.
c
      integer nreal, nint, nlog, nchar, nferrl
c     Actual size: nreal
      real    rreal(*)
c     Actual size: nint
      integer iint(*)
c     Actual size: nlog
      logical llog(*)
      logical linter
c     Actual size: nchar
      character*(*) cchar(*)
      character*(*) pmfile, ctitle, ctext
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'mesh.cmn'
      include 'data.cmn'
      include 'io.cmn'
      include 'plot.cmn'
      include 'compare.cmn'
      include 'units.cmn'
      include 'annotations.cmn'
      include 'defaults.cmn'
      include 'save.cmn'
      include 'callable.cmn'
      include 'version.cmn'
c
c     local variables
c
      logical err, batchmode, lfirstplot, do_pmi
      integer string_len, mode
      character*10 ext
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
c     init_defaults will only allow one initialization, so it's safe to
c     call anywhere.
      call init_defaults(luttyo, linter)
c
      call date(date_string)
c
CC    NOT FOR CALLABLE INTERFACE
CC      call get_command_line_args
c
c     Set batch mode (non-interactive) if asked by calling procedure.
      lrestore = .FALSE.
      if( linter ) then
         lbatch = .FALSE.
c        If we are passed in a PMI file, then execute and return
         if( string_len(pmfile) .ne. 0 ) then
            lrestore = .TRUE.
         endif
      else
         lbatch = .TRUE.
         luttyo = nferrl
         call mathmode_set_lun(luttyo)
      endif
c
c     Load data passed in to Postmini arrays (PROTOTYPE CODE, this is a dummy
c     routine!!)
      batchmode = .FALSE.
      call load_callable_xy_data(batchmode,err)
      if( err ) return
c     Set filename for use with making hardcopy files
      call get_filestem(ctext,binfilename)
c
c     Reset autoscaling flags (callable only)
      comp_lfirst   = .TRUE.
      lfirst_read   = .TRUE.
c     Set title
      plot_title    = ctitle
c     Set axis information
      call set_axis_callable(rreal, iint, llog, cchar,
     1     nreal, nint, nlog, nchar)
c
c     If non-interactive run, call restore and then return
c
      if( lbatch ) then
         lplotfile = .TRUE.
c        Check to see if ctext has an extension. If not, append one
c        from default hardcopy filename.
         call get_extension(ctext,ext)
         if( string_len(ext) .eq. 0 ) then
           call get_plotfile_extension(default_hc_name,ext)
         endif
         call make_plotfile_name(given_plotfilename,binfilename,ext)
         if( string_len(pmfile) .eq. 0 ) then
c           Perform default plot
            mode = 1
            call compare_plot(.FALSE.,.FALSE.,mode)
         else
            call do_restore_plot(pmfile,err)
         endif
         return
      else
         lplotfile = .FALSE.
      endif
c
c     If 'lrestore' mode run, call restore and then return
c
      if( lrestore ) then
         call do_restore_plot(pmfile,err)
         return
      endif
c
c     Else it's full interative. Bring up compare plot menu
      if( nlog .ge. 1 ) then
         lfirstplot = llog(1)
      else
         lfirstplot = .FALSE.
      endif
      mode = 1
      call compare_plot(.FALSE.,lfirstplot,mode)
c
c     the end of the road...
c
10100 continue
c
c     Write save file
      if( nlog .ge. 4 ) then
         do_pmi = .NOT. llog(4)
      else
         do_pmi = .TRUE.
      endif
      if( save_plot_type .ne. PLOT_NULL_COMMAND .and.
     1    gks_is_open .and. do_pmi ) then
c        Third argument says to overwrite current PMI file
         call write_savefile('POSTMINI.PMI',current_window_id,
     1                       .TRUE.,err)
         pmfile = savefilename
      else
         pmfile = ' '
      endif
c
CC      if( gks_is_open ) call close_gks
c
      return
      end
