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
c   Routines which assist using Postmini from the GUI (tcl/tk) interface
c
      subroutine pm_xyplot_gui(window, lhardcopy, lopen, lannotate,
     1                         lsave, ierr)
      implicit none
c
c     Programmer: John Faricelli
c     Date: 12-Jul-94
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'plot.cmn'
      include 'compare.cmn'
      include 'units.cmn'
      include 'data.cmn'
      include 'defaults.cmn'
      include 'annotations.cmn'
      include 'io.cmn'
c
      integer window, ierr
      logical lhardcopy, lopen, lannotate, lsave
c
c     locals
c
      integer i, j, itag, ierror, slot, idum, mode
      integer pm_get_log_option_xy_gui
      real rdum, rdum2
      real h_min(2), h_max(2), v_min(2), v_max(2)
      logical do_header, data_selected
      character*1 cdum
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      ierr = 0
      do_header = .TRUE.
c
      if( lannotate .and. lopen ) then
c        Write any previously written annotations to file
         call anno_write_notes_to_file(current_window_id,ierror)
      endif
c
c     Check for data selected
      data_selected = .FALSE.
      do i=1,n_cuts
         slot = slot_index(i)
         if( multi_1d(slot)%selected .eq. 1 ) data_selected = .TRUE.
      end do
      if( .NOT. data_selected ) then
         ierr = 1
         return
      endif
c
c     Get axis limits, etc. from gui
c
      call pm_get_axis_xy_gui(window, 1,
     1      rdum, rdum2,
     2      comp_h_min(1), comp_h_max(1),
     3      comp_h_exponent(1), comp_h_tic_major(1),
     4      comp_h_minor_tic_freq(1),
     5      comp_horiz_label(1),
     6      comp_hunits(1), comp_h_log(1), comp_h_abs(1))
      call pm_get_axis_xy_gui(window, 2,
     1      rdum, rdum2,
     2      comp_v_min(1), comp_v_max(1),
     3      comp_v_exponent(1), comp_v_tic_major(1),
     4      comp_v_minor_tic_freq(1),
     5      comp_vert_label(1),
     6      comp_vunits(1), comp_v_log(1), comp_v_abs(1))
c
c     Get plot options from gui area
      ierror = pm_get_log_option_xy_gui(window,1,comp_nolabels)
c
c     Plot or hardcopy?
      previous_plot_device = plot_device
      if( lhardcopy ) then
         plot_device = hardcopy_device
      endif
c
c     Stuff axis information into save structures
      call copy_axis_to_save(PLOT_COMPARE_COMMAND,
     1      comp_h_min(1), comp_h_max(1),
     2      comp_h_exponent(1), comp_h_tic_major(1),
     3      comp_h_minor_tic_freq(1),
     4      comp_hunits(1), comp_horiz_label(1),
     5      comp_h_log(1), comp_h_abs(1), comp_h_used(1),
     6      comp_v_min(1), comp_v_max(1),
     7      comp_v_exponent(1), comp_v_tic_major(1),
     7      comp_v_minor_tic_freq(1),
     8      comp_vunits(1), comp_vert_label(1),
     9      comp_v_log(1), comp_v_abs(1), comp_v_used(1),
     A      rdum, rdum,
     B      idum, rdum, idum, cdum,
     C      cdum, .FALSE., .FALSE.)
      call copy_axis2_to_save(comp_h_min(2), comp_h_max(2),
     1      comp_h_exponent(2), comp_h_tic_major(2),
     2      comp_h_minor_tic_freq(2),
     3      comp_hunits(2), comp_horiz_label(2),
     4      comp_h_log(2), comp_h_abs(2), comp_h_used(2),
     5      comp_v_min(2), comp_v_max(2),
     6      comp_v_exponent(2), comp_v_tic_major(2),
     7      comp_v_minor_tic_freq(2),
     8      comp_vunits(2), comp_vert_label(2),
     9      comp_v_log(2), comp_v_abs(2), comp_v_used(2))
c
c     Stuff data information into save structures
      mode = 1 ! Plot mode should be passed in from the GUI
      call copy_compare_to_save(mode)
c
c     Copy data into temp store, take absolute value, log if necessary...
      do 115 i=1,n_cuts
         slot = slot_index(i)
         itag = multi_1d(slot)%yaxis_tag
         do 116 j=1,multi_1d(slot)%np
            if( comp_v_abs(itag) .or. comp_v_log(itag) ) then
               work_vec(j,slot) = ABS(multi_1d(slot)%data(j))
               if( comp_v_log(itag) ) then
c                 check for log(0.0), fudge
                  if( work_vec(j,slot) .eq. 0.0 )
     1               work_vec(j,slot) = PM_MIN_FLOAT
                  work_vec(j,slot) = ALOG10(work_vec(j,slot))
               endif
            else
               work_vec(j,slot) = multi_1d(slot)%data(j)
            endif
116      continue
115   continue
c
      do i=1,2
         if( comp_v_used(i) ) then
            if( comp_v_log(i) ) then
               v_min(i) = ALOG10(comp_v_min(i))
               v_max(i) = ALOG10(comp_v_max(i))
            else
               v_min(i) = comp_v_min(i)
               v_max(i) = comp_v_max(i)
            endif
         endif
      end do
c
      do i=1,2
         if( comp_h_used(i) ) then
            if( comp_h_log(i) ) then
               h_min(i) = ALOG10(comp_h_min(i))
               h_max(i) = ALOG10(comp_h_max(i))
            else
               h_min(i) = comp_h_min(i)
               h_max(i) = comp_h_max(i)
            endif
         endif
      end do
c
      call do_multi_plot(work_vec, h_min, h_max,
     1      comp_h_exponent,
     2      comp_h_tic_major, comp_h_minor_tic_freq,
     3      v_min, v_max,
     4      comp_v_exponent, comp_v_tic_major, comp_v_minor_tic_freq,
     5      comp_hunits, comp_vunits,
     6      comp_horiz_label, comp_vert_label, comp_h_log, comp_v_log,
     7      comp_h_used, comp_v_used,
     8      do_header, mode,
     9      lsave, lopen, lannotate, ierror)
      if( ierror .eq. PLT$NORMAL .and. .not. lhardcopy ) lopen = .TRUE.
c
      plot_device = previous_plot_device
      return
c
      end
c
      subroutine pm_gui_message(facility,message)
c 
      character*(*) facility, message
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'io.cmn'
c
c     DUMMY ROUTINE, PRINTS TO TERMINAL AT THIS POINT
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      write(luttyo,100) facility, message
100   format(' ',a,': ',a)
c
      return
      end
c
      subroutine pm_init_axis_xy_gui(window, do_restore)
      implicit none
c
c     Programmer: John Faricelli
c     Date: 12-Jul-94
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'compare.cmn'
      include 'units.cmn'
      include 'data.cmn'
c
      integer window, do_restore
c
c     Locals
c
      integer i, ulen, slot, idum1, iexp, string_len
      real rdum1, rdum2, rdum3
      logical different, first_time, saw_linear, saw_log, lreset
      character*1 first_axis, first_plane
      character*40 first_quantity
c
      real hmin_full(2), hmax_full(2), hmin_plot(2), hmax_plot(2)
      real vmin_full(2), vmax_full(2), vmin_plot(2), vmax_plot(2)
      real h_tic_major(2), v_tic_major(2)
      integer h_minor_tic_freq(2), v_minor_tic_freq(2)
      integer h_exponent(2), iuser_hscale(2)
      integer v_exponent(2), iuser_vscale(2)
      integer plot_mode
      logical do_hlog(2), do_habs(2), do_huscale(2)
      logical do_vlog(2), do_vabs(2), do_vuscale(2)
      character*40 horiz_label, vert_label
      character*20 horiz_units, vert_units
c
c     Initialize the xy plot variables to a reasonable state
c     If do_restore == 1, then only determine the min/max of the X-Y data
c     (other quantities have been set from .PMI file)
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      ulen = string_len(pm_length_unit)
c
      if( do_restore .eq. 0 ) then
c
c        Initialize comp_xxx ('sticky') variables
         call pm_init_comp_sticky
c
         horiz_label = ' '
         vert_label  = ' '
         horiz_units = ' '
         vert_units  = ' '
c
c        Find min/max of coordinates, discard x bound information
c        Note, until we deal with multiple axes from the gui, the
c        initialization function only sets the default X and Y axes
         do_hlog(1)  = .FALSE.
         do_habs(1)  = .FALSE.
         do_huscale(1)  = .FALSE.
         call recompute_minmax_coords(hmin_full(1), hmax_full(1),
     1        rdum1, rdum2, h_tic_major(1),
     2        h_minor_tic_freq(1),
     3        iuser_hscale(1), h_exponent(1),
     4        do_habs(1), do_hlog(1), do_huscale(1), 1,
     5        work_vec(1,1))
c        Note that for the X axis, we don't use the "nice" min/max
c        computed by recompute_minmax_coords, but actual min/max.
c        This is a style issue.
         if( h_exponent(1) .ne. 0 ) then
            rdum1 = 10.0**h_exponent(1)
            hmin_plot(1) = hmin_full(1)/rdum1
            hmax_plot(1) = hmax_full(1)/rdum1
         else
            hmin_plot(1) = hmin_full(1)
            hmax_plot(1) = hmax_full(1)
         endif
c
c        Try to determine default horizontal axis labels,
c        depending on quantities involved.
c        Horizontal axis label
         different = .FALSE.
         first_time = .TRUE.
         do i=1,n_cuts
            slot = slot_index(i)
c           Only look at data which has been selected
            if( multi_1d(slot)%selected .eq. 1 ) then
               if( first_time ) then
                  first_axis = multi_1d(slot)%cut_line_axis
                  first_plane = multi_1d(slot)%cut_plane_axis
                 first_time = .FALSE.
               endif
               if( multi_1d(slot)%cut_line_axis .ne. first_axis ) 
     1            different = .TRUE.
               if( multi_1d(slot)%cut_plane_axis .ne. first_plane ) 
     1            different = .TRUE.
               if( multi_1d(slot)%type .eq. COMP_USER_TYPE )
     1            different = .TRUE.
             endif
         end do
         if( different ) then
            horiz_units = ' '
            horiz_label = ' '
         else
            horiz_units = pm_length_unit(1:ulen)
            if( first_axis .eq. 'X' ) then
               if( first_plane .eq. 'Z' ) then
                  horiz_label = 'Depth'
               else if( first_plane .eq. 'Y' ) then
                  horiz_label = 'Width'
               else
                  horiz_label = 'Time'
                  horiz_units = 's'
               endif
            else if( first_axis .eq. 'Y' ) then
               if( first_plane .eq. 'Z' ) then
                  horiz_label = 'Length'
               else if( first_plane .eq. 'X') then
                  horiz_label = 'Width'
               else
                  horiz_label = 'Time'
                  horiz_units = 's'
               endif
            else if( first_axis .eq. 'Z' ) then
               if( first_plane .eq. 'Y' ) then
                  horiz_label = 'Length'
               else
                  horiz_label = 'Depth'
               endif
            else if( first_axis .eq. 'T' ) then
               if( first_plane .eq. 'Y' ) then
                  horiz_label = 'Length'
               else
                  horiz_label = 'Depth'
               endif
            endif
         endif
c
c        Vertical axis label
         different = .FALSE.
         first_time = .TRUE.
         do i=1,n_cuts
            slot = slot_index(i)
c           Only look at data which has been selected
            if( multi_1d(slot)%selected .eq. 1 ) then
               if( first_time ) then
                  first_quantity = multi_1d(slot)%quantity
                  first_time = .FALSE.
               endif
               if( multi_1d(slot)%quantity .ne. first_quantity ) 
     1            different = .TRUE.
               if( multi_1d(slot)%type .eq. COMP_USER_TYPE )
     1            different = .TRUE.
            endif
         end do
         if( different ) then
            vert_units = ' '
            vert_label = ' '
         else
            vert_label = first_quantity
            slot = slot_index(i)
             if( multi_1d(slot)%type .eq. COMP_CUT_TYPE .or.
     1          multi_1d(slot)%type .eq. COMP_INTERFACE_TYPE ) then
               vert_units = multi_1d(slot)%units
            else
               vert_units = multi_1d(slot)%int_units
            endif
         endif
c
c        Compute default vertical axis parameters
c
c        Vertical axis logarithmic?
         saw_log    = .FALSE.
         saw_linear = .FALSE.
         do i=1,n_cuts
            slot = slot_index(i)
c           Only look at data which has been selected
            if( multi_1d(slot)%selected .eq. 1 ) then
               if( multi_1d(slot)%log .eq. .TRUE. ) then
                  saw_log = .TRUE.
               else
                  saw_linear = .TRUE.
               endif
            endif
         end do
         if( saw_log .and. .NOT. saw_linear ) then
            do_vlog(1) = .TRUE.
            do_vabs(1) = .TRUE.
         else
            do_vlog(1) = .FALSE.
            do_vabs(1) = .FALSE.
         endif
c
         do_vuscale(1) = .FALSE.
         v_exponent(1) = 0
         iuser_vscale(1) = 0
         plot_mode = 1   ! x-y line plot
         call recompute_minmax_comp(
     1                      vmin_full(1), vmax_full(1),
     2                      vmin_plot(1), vmax_plot(1),
     3                      v_tic_major(1), v_minor_tic_freq(1),
     4                      iuser_vscale(1), v_exponent(1),
     5                      do_vabs(1), do_vlog(1), do_vuscale(1),
     6                      1, work_vec(1,1), plot_mode)
c
         call pm_put_axis_xy_gui(window, 1,
     1      hmin_full(1), hmax_full(1),
     2      hmin_plot(1), hmax_plot(1),
     3      h_exponent(1), h_tic_major(1),
     4      h_minor_tic_freq(1),
     5      horiz_label, horiz_units, do_hlog(1), do_habs(1))
         call pm_put_axis_xy_gui(window, 2,
     1      vmin_full(1), vmax_full(1),
     2      vmin_plot(1), vmax_plot(1),
     3      v_exponent(1), v_tic_major(1),
     4      v_minor_tic_freq(1),
     5      vert_label, vert_units, do_vlog(1), do_vabs(1))
c        Initialize nolabels flag (item code 1)
         call pm_put_log_option_xy_gui(window,1,.FALSE.)
c
      else
c
c        Just get min/max data bounds, rest of info was gotten from
c        .PMI file restore and is in comp_xxx arrays
c        Find min/max of coordinates, discard x bound information
c        (unless autoscale flag was specified)
c        X bounds
         do i=1,2
            if( comp_h_used(i) ) then
               do_hlog(i)  = comp_h_abs(i)
               do_habs(i)  = comp_h_log(i)
               do_huscale(i)  = .FALSE.
               call recompute_minmax_coords(hmin_full(i), hmax_full(i),
     1              rdum1, rdum2, rdum3,
     2              idum1,
     3              iuser_hscale(i), iexp,
     4              do_habs(i), do_hlog(i), do_huscale(i), 1,
     5              work_vec(1,1))
c
c              Set axis parameters if autoscale flag was set
               if( comp_h_autoscale_min(i) .or.
     1             comp_h_autoscale_max(i) ) then
               if(comp_h_autoscale_min(i)) comp_h_min(i)=hmin_full(i)
               if(comp_h_autoscale_max(i)) comp_h_max(i)=hmax_full(i)
c                 Sanity check the min/max
                  lreset = .FALSE.
                  if( comp_h_min(i) .ge. comp_h_max(i) ) then
                     comp_h_min(i) = hmin_full(i)
                     comp_h_max(i) = hmax_full(i)
                     lreset = .TRUE.
                  endif
                  if( .NOT. do_hlog(i) ) then
                     comp_h_tic_major(i) = rdum3
                     comp_h_minor_tic_freq(i) = idum1
                     comp_h_exponent(i) = iexp
                     if( comp_h_exponent(i) .ne. 0 ) then
                        rdum1 = 10.0**comp_h_exponent(i)
                        if(comp_h_autoscale_min(i) .or. lreset)
     1                     comp_h_min(i) = comp_h_min(i)/rdum1
                        if(comp_h_autoscale_max(i) .or. lreset)
     1                     comp_h_max(i) = comp_h_max(i)/rdum1
                     endif
                  endif
               endif
            endif
         end do
c
c        Y bounds
         do i=1,2
            if( comp_v_used(i) ) then
               do_vabs(i) = comp_v_abs(1)
               do_vlog(i) = comp_v_log(1)
               do_vuscale(i) = .FALSE.
               iuser_vscale(i) = 0
               plot_mode = 1  ! x-y line plot
               call recompute_minmax_comp(
     1                      vmin_full(i), vmax_full(i),
     2                      rdum1, rdum2,
     3                      rdum3, idum1,
     4                      iuser_vscale(i), iexp,
     5                      do_vabs(i), do_vlog(i), do_vuscale(i),
     6                      1, work_vec(1,1), plot_mode)
               if( comp_v_autoscale_min(i) .or.
     1             comp_v_autoscale_max(i)) then
c                 Set defaults min/max for vertical axis
                  if(comp_v_autoscale_min(i)) comp_v_min(i) = rdum1
                  if(comp_v_autoscale_max(i)) comp_v_max(i) = rdum2
c                 Sanity check the min/max
                  if( comp_v_min(i) .ge. comp_v_max(i) ) then
                     comp_v_min(i) = rdum1
                     comp_v_max(i) = rdum2
                  endif
                  if( .NOT. do_vlog(i) ) then
                     comp_v_tic_major(i) = rdum3
                     comp_v_minor_tic_freq(i) = idum1
                     comp_v_exponent(i) = iexp
                  endif
               endif
            endif
         end do
c
c        For now, just put the left/bottom axis information to gui area
         call pm_put_axis_xy_gui(window, 1,
     1      hmin_full(1), hmax_full(1),
     2      comp_h_min(1), comp_h_max(1),
     3      comp_h_exponent(1), comp_h_tic_major(1),
     4      comp_h_minor_tic_freq(1),
     5      comp_horiz_label(1), comp_hunits(1),
     6      comp_h_log(1), comp_h_abs(1))
         call pm_put_axis_xy_gui(window, 2,
     1      vmin_full(1), vmax_full(1),
     2      comp_v_min(1), comp_v_max(1),
     3      comp_v_exponent(1), comp_v_tic_major(1),
     4      comp_v_minor_tic_freq(1),
     5      comp_vert_label(1), comp_vunits(1),
     6      comp_v_log(1), comp_v_abs(1))
         call pm_put_log_option_xy_gui(window,1,comp_nolabels)
      endif
c
      return
      end
c
      subroutine pm_reset_axis_xy_gui(window,axis,do_abs,do_log)
      implicit none
c
c     Programmer: John Faricelli
c     Date: 12-Jul-94
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'compare.cmn'
      include 'units.cmn'
      include 'data.cmn'
c
      integer window, axis
      logical do_abs, do_log
c
c     Locals
c
      real rdum, rdum2
c
      real hmin_full, hmax_full, hmin_plot, hmax_plot
      real vmin_full, vmax_full, vmin_plot, vmax_plot
      real h_tic_major, v_tic_major
      integer h_minor_tic_freq, v_minor_tic_freq
      integer h_exponent, iuser_hscale
      integer v_exponent, iuser_vscale
      integer plot_mode
      logical do_hlog, do_habs, do_huscale
      logical do_vlog, do_vabs, do_vuscale
      character*40 label
      character*20 units
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
c     Reset axis to good default values
c
      label = ' '
      units  = ' '
c
      if( axis .eq. 1 ) then
c     Find min/max of coordinates, discard x bound information
         do_hlog  = do_log
         do_habs  = do_abs
         do_huscale  = .FALSE.
         call recompute_minmax_coords(hmin_full, hmax_full,
     1        rdum, rdum2, h_tic_major,
     2        h_minor_tic_freq,
     3        iuser_hscale, h_exponent,
     4        do_habs, do_hlog, do_huscale, 1,
     5        work_vec(1,1))
c        Note that for the X axis, we don't use the "nice" min/max
c        computed by recompute_minmax_coords, but actual min/max.
c        This is a style issue.
         if( h_exponent .ne. 0 ) then
            rdum = 10.0**h_exponent
            hmin_plot = hmin_full/rdum
            hmax_plot = hmax_full/rdum
         else
            hmin_plot = hmin_full
            hmax_plot = hmax_full
         endif
c
      call pm_put_axis_xy_gui(window, 1,
     1      hmin_full, hmax_full,
     2      hmin_plot, hmax_plot,
     3      h_exponent, h_tic_major,
     4      h_minor_tic_freq,
     5      label, units, do_hlog, do_habs)
c
      else if( axis .eq. 2 ) then
         do_vlog = do_log
         do_vabs = do_abs
         do_vuscale = .FALSE.
         v_exponent = 0
         iuser_vscale = 0
         plot_mode = 1  ! x-y line plot
         call recompute_minmax_comp(
     1                      vmin_full, vmax_full,
     2                      vmin_plot, vmax_plot,
     3                      v_tic_major, v_minor_tic_freq,
     4                      iuser_vscale, v_exponent,
     5                      do_vabs, do_vlog, do_vuscale,
     6                      1, work_vec(1,1), plot_mode)
         call pm_put_axis_xy_gui(window, 2,
     1      vmin_full, vmax_full,
     2      vmin_plot, vmax_plot,
     3      v_exponent, v_tic_major,
     4      v_minor_tic_freq,
     5      label, units, do_vlog, do_vabs)
      endif
c
      return
      end
c
      subroutine pm_get_tics_gui(min,max,tic_major,minor_tic_freq)
      implicit none
c
c     Programmer: John Faricelli
c     Date: 28-Jul-94
c
      real min, max, tic_major
      integer minor_tic_freq
c
c     Locals
c
      integer idum
      real rdum, rdum2
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      call get_default_limits(min, max, rdum, rdum2,
     1     tic_major, minor_tic_freq, idum, .FALSE.)
      if( idum .ne. 0 ) then
         tic_major = tic_major*10.0**idum
      endif
c
      return
      end
c
      subroutine pm_get_axis_xy_gui(window, iaxis,
     1      full_min, full_max,
     2      plot_min, plot_max,
     3      exponent, tic_major, minor_tic_freq,
     4      label, units, do_log, do_abs)
      implicit none
c
      integer window, iaxis, exponent, minor_tic_freq
      real full_min, full_max, plot_min, plot_max, tic_major
      logical do_log, do_abs
      character*(*) units, label
c
c     For now, store in single static storage (ignore window)
      include 'const.h'
      include 'gui.cmn'
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      full_min = gui_min_full(iaxis)
      full_max = gui_max_full(iaxis)
      plot_min = gui_min_plot(iaxis)
      plot_max = gui_max_plot(iaxis)
      exponent = gui_exponent(iaxis)
      tic_major = gui_tic_major(iaxis)
      minor_tic_freq = gui_minor_tic_freq(iaxis)
      label = gui_label(iaxis)
      units = gui_units(iaxis)
      do_log = gui_log(iaxis)
      do_abs = gui_abs(iaxis)
c
      return
      end
c
      subroutine pm_put_axis_xy_gui(window, iaxis,
     1      full_min, full_max,
     2      plot_min, plot_max,
     3      exponent, tic_major, minor_tic_freq,
     4      label, units, do_log, do_abs)
      implicit none
c
      integer window, iaxis, exponent, minor_tic_freq
      real full_min, full_max, plot_min, plot_max, tic_major
      logical do_log, do_abs
      character*(*) units, label
c
c     For now, store in single static storage (ignore window)
      include 'const.h'
      include 'gui.cmn'
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      gui_min_full(iaxis) = full_min
      gui_max_full(iaxis) = full_max
      gui_min_plot(iaxis) = plot_min
      gui_max_plot(iaxis) = plot_max
      gui_exponent(iaxis) = exponent
      gui_tic_major(iaxis) = tic_major
      gui_minor_tic_freq(iaxis) = minor_tic_freq
      gui_label(iaxis)    = label
      gui_units(iaxis)    = units
      gui_log(iaxis)      = do_log
      gui_abs(iaxis)      = do_abs
c
      return
      end
c
      subroutine pm_put_hardcopy_gui(
     1      name, device, reduction_factor, orient, colormap)
      implicit none
c
      integer orient, colormap
      real reduction_factor
      character*(*) name, device
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'plot.cmn'
      include 'compare.cmn'
      include 'units.cmn'
      include 'data.cmn'
      include 'defaults.cmn'
      include 'annotations.cmn'
      include 'io.cmn'
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      plot_file_name = name
c
      if( device .eq. 'postscript' ) then
         hardcopy_device = GKS$K_POSTSCRIPT
      else if( device .eq. 'cpostscript' ) then
         hardcopy_device = GKS$K_COLOR_POSTSCRIPT
      else if( device .eq. 'epsf' ) then
         hardcopy_device = GKS$K_EPSF
      else if( device .eq. 'cepsf' ) then
         hardcopy_device = GKS$K_COLOR_EPSF
      else if( device .eq. 'hpgl' ) then
         hardcopy_device = GKS$K_HP7550
      endif
c
      hc_scale = reduction_factor
c
      hc_is_landscape = orient
c
      if( colormap .eq. 1 ) then
         hardcopy_colormap= COLORMAP_COLOR
      else if( colormap .eq. 2 ) then
         hardcopy_colormap= COLORMAP_NONE
      else if( colormap .eq. 3 ) then
         hardcopy_colormap= COLORMAP_GRAY
      else if( colormap .eq. 4 ) then
         hardcopy_colormap= COLORMAP_INV_GRAY
      endif
c
      return
      end
c
      subroutine pm_create_window_gui()
c
c     Allocate new window id
c     Allocate axis structures, depending on plot type
c     Allocate other information, depending on plot type
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      return
      end
c
      subroutine pm_destroy_window_gui()
c     Deallocate new window id
c     Deallocate axis structures, depending on plot type
c     Deallocate other information, depending on plot type
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      return
      end

c
      subroutine pm_init_xfer_gui
      implicit none
c
      include 'const.h'
      include 'gui.cmn'
c
c     Set all transfer item counts to zero
c
      gui_xfer_rcount = 0
      gui_xfer_icount = 0
      gui_xfer_lcount = 0
      gui_xfer_ccount = 0
c
      return
      end
c
      integer function pm_put_int_xfer_gui(ivalue)
      implicit none
c
      include 'const.h'
      include 'gui.cmn'
c
      integer ivalue
c
c     Add integer value to xfer argument count
c
      gui_xfer_icount = gui_xfer_icount + 1
      if( gui_xfer_icount .gt. GUI_XFER_MAX ) then
         pm_put_int_xfer_gui = 0
      else
         gui_xfer_ivector(gui_xfer_icount) = ivalue
         pm_put_int_xfer_gui = 1
      endif
c
      return
      end
c
      integer function pm_put_log_xfer_gui(lvalue)
      implicit none
c
      include 'const.h'
      include 'gui.cmn'
c
      logical lvalue
c
c     Add logical value to xfer argument count
c
      gui_xfer_lcount = gui_xfer_lcount + 1
      if( gui_xfer_lcount .gt. GUI_XFER_MAX ) then
         pm_put_log_xfer_gui = 0
      else
         gui_xfer_lvector(gui_xfer_lcount) = lvalue
         pm_put_log_xfer_gui = 1
      endif
c
      return
      end
c
      integer function pm_put_real_xfer_gui(rvalue)
      implicit none
c
      include 'const.h'
      include 'gui.cmn'
c
      real rvalue
c
c     Add real value to xfer argument count
c
      gui_xfer_rcount = gui_xfer_rcount + 1
      if( gui_xfer_rcount .gt. GUI_XFER_MAX ) then
         pm_put_real_xfer_gui = 0
      else
         gui_xfer_rvector(gui_xfer_rcount) = rvalue
         pm_put_real_xfer_gui = 1
      endif
c
      return
      end
c
      integer function pm_put_string_xfer_gui(string)
      implicit none
c
      include 'const.h'
      include 'gui.cmn'
c
      character*(*) string
c
c     Add
c
      gui_xfer_ccount = gui_xfer_ccount + 1
      if( gui_xfer_ccount .gt. GUI_XFER_MAX ) then
         pm_put_string_xfer_gui = 0
      else
         gui_xfer_cvector(gui_xfer_ccount) = string
         pm_put_string_xfer_gui = 1
      endif
c
      return
      end
c
      subroutine pm_get_curve_gui(curveid, label,
     1      ax, mx, ay, my,
     2      color, linestyle, symbol, symbol_color, symbol_size,
     3      ierr)
      implicit none
c
      integer curveid, color, linestyle, symbol, symbol_color, ierr
      real ax, mx, ay, my, symbol_size
      character*(*) label
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'plot.cmn'
      include 'compare.cmn'
c     For now, store in single static storage in gui area
      include 'gui.cmn'
c
      integer slot
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      ierr = 0
      if( curveid .lt. 1 .or. curveid .gt. n_cuts ) then
         call pm_gui_message('pm_get_curve_gui','curveid out of range')
         ierr = 1
         return
      endif
c
      slot = slot_index(curveid)
      label = multi_1d(slot)%label
      color = multi_1d(slot)%color
      linestyle = multi_1d(slot)%linestyle
      symbol = multi_1d(slot)%marker_type
      symbol_color = multi_1d(slot)%marker_color
      ax = multi_1d(slot)%ax
      ay = multi_1d(slot)%ay
      mx = multi_1d(slot)%mx
      my = multi_1d(slot)%my
      symbol_size = multi_1d(slot)%marker_scale
c
      return
      end
c
      subroutine pm_put_curve_gui(curveid, label,
     1      ax, mx, ay, my,
     2      color, linestyle, symbol, symbol_color, symbol_size,
     3      ierr)
      implicit none
c
      integer curveid, color, linestyle, symbol, symbol_color, ierr
      real ax, mx, ay, my, symbol_size
      character*(*) label
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'units.cmn'
      include 'plot.cmn'
      include 'compare.cmn'
c
      integer slot, i
      real tax
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      ierr = 0
      if( curveid .lt. 1 .or. curveid .gt. n_cuts ) then
         call pm_gui_message('pm_put_curve_gui','curveid out of range')
         ierr = 1
         return
      endif
c
      slot = slot_index(curveid)
      multi_1d(slot)%label = label
      multi_1d(slot)%color        = color
      multi_1d(slot)%linestyle    = linestyle
      multi_1d(slot)%marker_type  = symbol
      multi_1d(slot)%marker_color = symbol_color
      multi_1d(slot)%marker_scale = symbol_size
      multi_1d(slot)%ax = ax
      multi_1d(slot)%ay = ay
      multi_1d(slot)%mx = mx
      multi_1d(slot)%my = my
c
c     Re-scale data from raw information
c     Scale factors have to be converted to appropriate internal
c     units. mx is not converted, as it is unitless.
      tax = pm_scale_plot2cm*multi_1d(slot)%ax
      do 100 i=1,multi_1d(slot)%np
         multi_1d(slot)%data(i)  = my*multi_1d(slot)%raw_data(i) + ay
         multi_1d(slot)%coord(i) = mx*multi_1d(slot)%raw_coord(i) + tax
100   continue
c
      return
      end
c
      integer function pm_deletexy_gui(curveid)
      implicit none
c
      integer curveid
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'units.cmn'
      include 'plot.cmn'
      include 'compare.cmn'
c
c     locals
c
      integer i, slot
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      if( curveid .lt. 1 .or. curveid .gt. n_cuts ) then
c        Illegal index number...
         pm_deletexy_gui = 1
         return
      endif
c
c     Find slot number given plot index number
      slot = slot_index(curveid)
      if ( .not. in_use(slot) ) then
c        Already free
         pm_deletexy_gui = 1
         return
      else
         if( associated(multi_1d(slot)%coord) )
     1      deallocate(multi_1d(slot)%coord)
         if( associated(multi_1d(slot)%data) )
     1      deallocate(multi_1d(slot)%data)
         if( associated(multi_1d(slot)%raw_coord) )
     1      deallocate(multi_1d(slot)%raw_coord)
         if( associated(multi_1d(slot)%raw_data) )
     1      deallocate(multi_1d(slot)%raw_data)
c        Move everyone up a notch.
         do 10 i=curveid, n_cuts-1
            slot_index(i) = slot_index(i+1)
10       continue
         in_use(slot) = .FALSE.  ! mark as empty
         slot_index(n_cuts) = -1
         n_cuts = n_cuts - 1
      endif
      pm_deletexy_gui = 0
c
      return
      end
c
      integer function pm_addxy_gui(label, ax, mx, ay, my,
     2      color, linestyle, symbol, symbol_color, symbol_size,
     3      ierr)
      implicit none
c
      integer color, linestyle, symbol, symbol_color, ierr
      real ax, mx, ay, my, symbol_size
      character*(*) label
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'mesh.cmn'
      include 'data.cmn'
      include 'io.cmn'
      include 'bincodes.cmn'
      include 'compare.cmn'
      include 'user.cmn'
      include 'units.cmn'
c
      include 'gui.cmn'
c
      integer slot, i, ialloc, curveid, find_new_entry
      real tax
c
      integer type
      real cut_line_coord, int_limits(2)
      character*1  cut_line_axis
      character*40 quantity
      character*20 units, nickname
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      ierr = 0
c
c     Sanity check: was any data loaded in the xfer area?
      if( gui_1d_npts .le. 0 ) then
         pm_addxy_gui = 0
         ierr = 3
         return
      endif
c
c     Do some checking to see if npts < internal storage size
      if( gui_1d_npts .gt. COMP_ARRAYSIZE ) then
         pm_addxy_gui = 0
         ierr = 2
         return
      endif
c
      curveid = find_new_entry()
c     Were we able to get a new entry?
      if( curveid .eq. -1 ) then
         pm_addxy_gui = 0
         ierr = 1
         return
      endif
      slot = slot_index(curveid)
c
c     Allocate arrays
      allocate(multi_1d(slot)%coord(1:gui_1d_npts),stat=ialloc)
      allocate(multi_1d(slot)%data(1:gui_1d_npts),stat=ialloc)
      allocate(multi_1d(slot)%raw_coord(1:gui_1d_npts),stat=ialloc)
      if( type .eq. COMP_USER_TYPE ) then
        allocate(multi_1d(slot)%raw_data(1:gui_1d_npts*user_1d_n_ycols),
     1           stat=ialloc)
      else
         allocate(multi_1d(slot)%raw_data(1:gui_1d_npts),stat=ialloc)
      endif
      if( ialloc .ne. 0 ) then
         call pm_deletexy_gui(curveid)
         pm_addxy_gui = 0
         ierr = 4
         return
      endif
c
      multi_1d(slot)%np = gui_1d_npts
      do i=1,gui_1d_npts 
         multi_1d(slot)%raw_coord(i) = gui_1d_coords(i)
         multi_1d(slot)%raw_data(i)  = gui_1d_data(i)
      end do
      multi_1d(slot)%label = label
      multi_1d(slot)%color = color
      multi_1d(slot)%linestyle = linestyle
      multi_1d(slot)%marker_type = symbol
      multi_1d(slot)%marker_color = symbol_color
      multi_1d(slot)%marker_scale = symbol_size
      multi_1d(slot)%ax = ax
      multi_1d(slot)%ay = ay
      multi_1d(slot)%mx = mx
      multi_1d(slot)%my = my
c
c     Re-scale data from raw information
c     Scale factors have to be converted to appropriate internal
c     units. mx is not converted, as it is unitless.
      tax = pm_scale_plot2cm*multi_1d(slot)%ax
      do 100 i=1,multi_1d(slot)%np
         multi_1d(slot)%data(i)  = my*multi_1d(slot)%raw_data(i) + ay
         multi_1d(slot)%coord(i) = mx*multi_1d(slot)%raw_coord(i) + tax
100   continue
c
c     Rest are dummy values (for now)
c     Some of the values loaded here will be trash
c
c     Note for future, some of this following variables will have to be
c     passed in, or determined in some other way, in order to support
c     datatypes other than 1D ASCII files.
c
      type = COMP_USER_TYPE ! For testing, assume ASCII datatype
      cut_line_coord = 0.0
      cut_line_axis  = 'X'
      quantity = 'ASCII'
      nickname = 'ASCII'
      units = '???'
      int_limits(1) = 0.0
      int_limits(2) = 0.0
c
c     These data items come from common block variables
      multi_1d(slot)%vd = vd
      multi_1d(slot)%vs = vs
      multi_1d(slot)%vg = vg
      multi_1d(slot)%vb = vb
      multi_1d(slot)%id = id
      multi_1d(slot)%is = is
      multi_1d(slot)%ib = ib
      multi_1d(slot)%cut_line_coord = cut_line_coord
      multi_1d(slot)%cut_line_axis  = cut_line_axis
      multi_1d(slot)%cut_plane_coord = plane_actual_value
      multi_1d(slot)%cut_plane_axis = cut_plane_axis
      multi_1d(slot)%type = type
      if( type .eq. COMP_USER_TYPE ) then
         multi_1d(slot)%binfilename = user_1d_asciifile
         multi_1d(slot)%col_x    = user_1d_col_x
         multi_1d(slot)%col_y(1) = user_1d_col_y(1)
         multi_1d(slot)%col_z    = user_1d_col_z
         multi_1d(slot)%n_ycols  = 1
         multi_1d(slot)%az = user_1d_az
         multi_1d(slot)%mz = user_1d_mz
         multi_1d(slot)%zabs = user_1d_zabs
         multi_1d(slot)%skip = user_1d_skip
         multi_1d(slot)%lines_to_read = user_1d_nlines
         multi_1d(slot)%sweep = user_1d_sweep
         multi_1d(slot)%contour = user_1d_contour
         multi_1d(slot)%sort = user_1d_sort
         multi_1d(slot)%dimension = user_1d_dim
         multi_1d(slot)%record = datafile_record
      else
         multi_1d(slot)%binfilename = binfilename
         multi_1d(slot)%record      = datafile_record
         if( three_d ) then
            multi_1d(slot)%dimension = 3
         else
            multi_1d(slot)%dimension = 2
         endif
         if( binfiletype .eq. DT_2DOP ) then
            multi_1d(slot)%misc(1) = tdop_gate_length
            multi_1d(slot)%misc_ch(1) = tdop_interface_file
         endif
         if( binfiletype .eq. DT_VLSICAP ) then
            multi_1d(slot)%misc(1) = vlsi_edge
            multi_1d(slot)%misc(2) = vlsi_yint
         endif
      endif
      multi_1d(slot)%quantity = quantity
      multi_1d(slot)%nickname = nickname
      if( type .eq. COMP_CUT_TYPE .or.
     1    type .eq. COMP_INTERFACE_TYPE ) then
         multi_1d(slot)%units = units
      elseif( type .eq. COMP_INT_TYPE ) then
         multi_1d(slot)%int_units = units
         multi_1d(slot)%int_limits(1) = int_limits(1)
         multi_1d(slot)%int_limits(2) = int_limits(2)
      endif
      multi_1d(slot)%datatype = binfiletype
      multi_1d(slot)%log = .FALSE.
      multi_1d(slot)%xaxis_tag = 1
      multi_1d(slot)%yaxis_tag = 1
      multi_1d(slot)%x_expression = ' '
      multi_1d(slot)%y_expression = ' '
c
      pm_addxy_gui = curveid
c
      return
      end
c
      integer function pm_get_samplexy_gui(window, xcoord, ycoord)
      implicit none
c
      integer window
      real xcoord, ycoord
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'plot.cmn'
      include 'compare.cmn'
c
      real h1(2), h2(2), h3(2), h4(2), xndc0, yndc0
      logical do_probe
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
c     Caution: this routine only works correctly once a window has
c     been displayed with the x-y plot routines.
c
      if( comp_h_log(1) ) then
         h1(1) = ALOG10(ABS(MAX(PM_MIN_FLOAT,comp_h_min(1))))
         h2(1) = ALOG10(ABS(MAX(PM_MIN_FLOAT,comp_h_max(1))))
      else
         h1(1) = comp_h_min(1)
         h2(1) = comp_h_max(1)
      endif
      if( comp_v_log(1) ) then
         h3(1) = ALOG10(ABS(MAX(PM_MIN_FLOAT,comp_v_min(1))))
         h4(1) = ALOG10(ABS(MAX(PM_MIN_FLOAT,comp_v_max(1))))
      else
         h3(1) = comp_v_min(1)
         h4(1) = comp_v_max(1)
      endif
c     Magic constants are values to GKS$SET_VIEWPORT in
c     subroutine do_multi_plot.
c     Set plot area origin
      if( comp_nolabels ) then
         xndc0 = COMP_ORIGIN_NO_LABELS_X
         yndc0 = COMP_ORIGIN_NO_LABELS_Y
      else
         xndc0 = COMP_ORIGIN_WITH_LABELS_X
         yndc0 = COMP_ORIGIN_WITH_LABELS_Y
      endif
      call get_probe_location(current_window_id,
     1       h1(1), h2(1), h3(1), h4(1),
     2       xndc0, xndc0+0.65, yndc0, yndc0+0.65, .FALSE.,
     3       xcoord, ycoord, do_probe)
      if( do_probe ) then
         if( comp_h_log(1) ) then
            xcoord = 10.0**(MIN(xcoord,38.0))
         else if(comp_h_exponent(1) .ne. 0) then
            xcoord = xcoord*10.0**(comp_h_exponent(1))
         endif
         if( comp_v_log(1) ) then
            ycoord = 10.0**(MIN(ycoord,38.0))
         else if(comp_v_exponent(1) .ne. 0) then
            ycoord = ycoord*10.0**(comp_v_exponent(1))
         endif
      endif
c
      if( do_probe ) then
         pm_get_samplexy_gui = 1
      else
         pm_get_samplexy_gui = 0
      endif
c
      return
      end
c
      integer function pm_get_zoomxy_gui(window)
      implicit none
c
c     Programmer: John Faricelli
c     Date: 12-Jul-94
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'plot.cmn'
      include 'compare.cmn'
c
      integer window
c
c     Locals
c
      integer i, idum
      real x1(2), x2(2), y1(2), y2(2), h1(2), h2(2), h3(2), h4(2)
      real hmin_full, hmax_full, vmin_full, vmax_full
      real xndc0, yndc0, rdum, rdum2
      logical do_zoom
      character*40 horiz_label, vert_label
      character*20 horiz_units, vert_units
c
c     Do a zoom on the xy plot, then set axis variables to new state
c
c     Caution: this routine only works correctly once a window has
c     been displayed with the x-y plot routines.
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
c     Set up bounding box of current plot
      do i=1,2
         if( comp_h_used(i) ) then
            if( comp_h_log(i) ) then
               h1(i) = ALOG10(ABS(MAX(PM_MIN_FLOAT,comp_h_min(i))))
               h2(i) = ALOG10(ABS(MAX(PM_MIN_FLOAT,comp_h_max(i))))
            else
               h1(i) = comp_h_min(i)
               h2(i) = comp_h_max(i)
            endif
         endif
         if( comp_v_used(i) ) then
            if( comp_v_log(i) ) then
               h3(i) = ALOG10(ABS(MAX(PM_MIN_FLOAT,comp_v_min(i))))
               h4(i) = ALOG10(ABS(MAX(PM_MIN_FLOAT,comp_v_max(i))))
            else
               h3(i) = comp_v_min(i)
               h4(i) = comp_v_max(i)
            endif
         endif
      end do
c     Magic constants are values to GKS$SET_VIEWPORT in
c     subroutine do_multi_plot.
c     Set plot area origin
      if( comp_nolabels ) then
         xndc0 = COMP_ORIGIN_NO_LABELS_X
         yndc0 = COMP_ORIGIN_NO_LABELS_Y
      else
         xndc0 = COMP_ORIGIN_WITH_LABELS_X
         yndc0 = COMP_ORIGIN_WITH_LABELS_Y
      endif
      call window_zoom(current_window_id,
     1        h1(1), h2(1), h3(1), h4(1),
     2        xndc0, xndc0+0.65, yndc0, yndc0+0.65, .FALSE.,
     3        x1(1), x2(1), y1(1), y2(1), do_zoom)
c     Scale second axes proportionally to first axes
      if( do_zoom ) then
         if( comp_h_used(2) ) then
            call scale_like_zoom(h1,h2,x1,x2)
         endif
         if( comp_v_used(2) ) then
            call scale_like_zoom(h3,h4,y1,y2)
         endif
         do i=1,2
            if( comp_h_used(i) .and. comp_h_log(i) ) then
               x1(i) = 10.0**(MIN(x1(i),38.0))
               x2(i) = 10.0**(MIN(x2(i),38.0))
            endif
            if( comp_v_used(i) .and. comp_v_log(i) ) then
               y1(i) = 10.0**(MIN(y1(i),38.0))
               y2(i) = 10.0**(MIN(y2(i),38.0))
            endif
         enddo
         do i=1,2
            if( comp_h_used(i) ) then
               comp_h_min(i)  = x1(i)
               comp_h_max(i)  = x2(i)
            endif
            if( comp_v_used(i) ) then
               comp_v_min(i)  = y1(i)
               comp_v_max(i)  = y2(i)
            endif
         end do
c
c        Get tic mark parameters
         do i=1,2
            if( comp_h_used(i) ) then
               if( .NOT. comp_h_log(i) ) then
                  call get_default_limits(
     1                     comp_h_min(i), comp_h_max(i),
     2                     rdum, rdum2,
     3                     comp_h_tic_major(i),comp_h_minor_tic_freq(i),
     4                     idum, .FALSE.)
c                 Handle the case of unzoom
c                 (is this now required in the gui version of this code?)
                  if( idum .ne. 0 ) then
                     comp_h_min(i)=comp_h_min(i)*10.0**(-idum)
                     comp_h_max(i)=comp_h_max(i)*10.0**(-idum)
                     comp_h_exponent(i) = idum
                  endif
               endif
            endif
            if( comp_v_used(i) ) then
               if( .NOT. comp_v_log(i) ) then
c                 Just get updated tic mark info
                  call get_default_limits(
     1                  comp_v_min(i), comp_v_max(i),
     2                  rdum, rdum2,
     3                  comp_v_tic_major(i), comp_v_minor_tic_freq(i),
     4                  idum, .FALSE.)
                  if( idum .ne. 0 ) then
                     comp_v_tic_major(i)=comp_v_tic_major(i)*10.0**idum
                  endif
               endif
            endif
         end do
c
c        Set other variables to 'dummy' values
         hmin_full = 0.0
         hmax_full = 0.0
         horiz_label = ' '
         horiz_units = ' '
c
         vmin_full = 0.0
         vmax_full = 0.0
         vert_label  = ' '
         vert_units  = ' '
c
         call pm_put_axis_xy_gui(window, 1,
     1      hmin_full, hmax_full,
     2      comp_h_min, comp_h_max,
     3      comp_h_exponent, comp_h_tic_major,
     4      comp_h_minor_tic_freq,
     5      horiz_label, horiz_units, comp_h_log, comp_h_abs)
         call pm_put_axis_xy_gui(window, 2,
     1      vmin_full, vmax_full,
     2      comp_v_min, comp_v_max,
     3      comp_v_exponent, comp_v_tic_major,
     4      comp_v_minor_tic_freq,
     5      vert_label, vert_units, comp_v_log, comp_v_abs)
      endif
c
      if( do_zoom ) then
         pm_get_zoomxy_gui = 1
      else
         pm_get_zoomxy_gui = 0
      endif
c
      return
      end
c
      subroutine pm_clearxy_gui
      implicit none
c
c     Programmer: John Faricelli
c     Date: 3-Aug-94
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'compare.cmn'
      include 'callable.cmn'
c
      integer i
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
c     Mark all data as erased
      do 10 i=1,MULTI_SIZE
         in_use(i) = .FALSE.
         slot_index(i) = -1
10       continue
      n_cuts = 0
c
c     Tell compare menu routines that things have been reset
      comp_lfirst = .TRUE.
c
c     Initialize side label counter
      callable_num_sidelabels = 0
c
c     Clear title(s)
      callable_num_titles = 0
c
      return
      end
c
      subroutine pm_close_gui
      implicit none
c
c     Programmer: John Faricelli
c     Date: 3-Aug-94
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'plot.cmn'
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      if( gks_is_open ) call close_gks
c
      return
      end
c
      subroutine anno_write_notes_gui(from_window_id,err_stat)
      implicit none
c
      integer from_window_id, err_stat
c
c     Write annotations to save file
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'io.cmn'
      include 'plot.cmn'
      include 'compare.cmn'
      include 'annotations.cmn'
      include 'save.cmn'
c
c     locals
c
      integer work_id, lookup_ws_id
      character*132 note_file
c
      work_id = lookup_ws_id(from_window_id)
      if( work_id .EQ. PLT$EMPTY_WINDOW_SLOT ) then
         call plt$error_message('anno_write_notes_to_file',
     1        'destination window_id is bad')
         err_stat = PLT$BAD_WINDOW_ID
         return
      endif
c
c     Load annotations into save memory area
      call copy_annotations_to_save(from_window_id)
c
c     This should be specific to each window, so we can have multiply
c     active windows.
      note_file = 'POSTMINI.NOTE'
      open(unit=notefil,file=note_file,form='formatted',
     1     status='unknown',err=1000)
      rewind(notefil)
c
c     Write out a comment so if there are no notes, POSTMINI.NOTE will
c     be reset to an "empty" file.
      write(notefil,1010)
1010  format('!! ')
c
c     write annotations to save file
      call write_save_annotations(notefil)
c
      close(unit=notefil)
      err_stat = PLT$NORMAL
c
      return
c
1000  continue
c     This should write to the message box, but...
      write(luttyo,1001)
1001  format(' ','Error: could not open file to save annotations')
      err_stat = 13 ! Make PLT$BAD_OPEN_FILE = 13 to plot.cmn some day
      return
      end
c
      subroutine pm_read_asciifile_gui(filename, ixcol, iycol,
     1           ax, mx, ay, my, num_lines, num_skip, lsweep,
     2           sample_freq, ierr)
      implicit none
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'plot.cmn'
      include 'data.cmn'
      include 'io.cmn'
      include 'mesh.cmn'
      include 'user.cmn'
      include 'gui.cmn'
c
      character*(*) filename
      real ax, mx, ay, my
      integer ixcol, iycol, num_lines, num_skip, sample_freq, ierr
      logical lsweep
c
c     GUI interface to Postmini's ASCII file reader
c
c     Store parameters in user.cmn
c     (less re-coding of this routine from original)
      user_1d_asciifile = filename
      user_1d_ax = ax
      user_1d_mx = mx
      user_1d_ay = ay
      user_1d_my = my
      user_1d_col_x    = ixcol
      user_1d_col_y(1) = iycol
      user_1d_n_ycols  = 1
      user_1d_nlines = num_lines
      user_1d_skip   = num_skip
      user_1d_sweep  = lsweep
      user_1d_sample_freq = sample_freq
c
c     These parameters are not set yet from GUI
      user_1d_xabs = .FALSE.
      user_1d_yabs = .FALSE.
      user_1d_contour = .FALSE.
      user_1d_az = 0.0
      user_1d_mz = 1.0
      user_1d_zabs = .FALSE.
      user_1d_col_z = 3
      user_1d_dim   = 1
      user_1d_sort  = .FALSE.
      user_1d_dataset_number = 1
      user_1d_errorbars = .FALSE.
      user_1d_x_char_data = .FALSE.
      user_1d_rect_grid = .TRUE.
      user_1d_x_expression = ' '
      user_1d_y_expression = ' '
c
      call do_read_asciifile
c
      ierr = gui_error_level
c
      return
      end
c
      subroutine pm_read_grapes_gui(filename, ierr)
      implicit none
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'plot.cmn'
      include 'data.cmn'
      include 'io.cmn'
      include 'mesh.cmn'
      include 'user.cmn'
      include 'gui.cmn'
c
      character*(*) filename
      integer ierr
c
c     GUI interface to Postmini's GRAPES file reader
c
      logical batchmode, read_error
c
      binfilename = filename
      batchmode = .TRUE.
c
      call read_grapesfile(batchmode,read_error)
c
      ierr = gui_error_level
c
      return
      end
c
      subroutine pm_read_spice3_gui(filename, convert_type, ierr)
      implicit none
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'plot.cmn'
      include 'data.cmn'
      include 'io.cmn'
      include 'mesh.cmn'
      include 'user.cmn'
      include 'gui.cmn'
c
      character*(*) filename
      integer convert_type, ierr
c
c     GUI interface to Postmini's SPICE3 file reader
c
      logical batchmode, read_error
c
      binfilename = filename
      batchmode = .TRUE.
      binfile_convert_type = convert_type
c
      call do_read_spice3file(batchmode,read_error)
c
      ierr = gui_error_level
c
      return
      end
c
      integer function pm_xfer_ascii_gui
      implicit none
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'data.cmn'
      include 'mesh.cmn'
      include 'user.cmn'
      include 'gui.cmn'
c
      integer i
c
      if( have_user_1d_data ) then
c        Place unscaled data in gui transfer area
         gui_1d_npts = ni
         do i=1,ni
            gui_1d_coords(i) = arr2d(i,2)
            gui_1d_data(i)   = arr2d(i,3)
         end do
         pm_xfer_ascii_gui = 0
      else
         pm_xfer_ascii_gui = 1
      endif
c
      return
      end
c
      subroutine pm_write_pmifile_gui(filename, ierr)
      implicit none
c
c     Programmer: John Faricelli
c     Date: 8-Nov-94
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'plot.cmn'
      include 'compare.cmn'
      include 'units.cmn'
      include 'data.cmn'
      include 'defaults.cmn'
      include 'annotations.cmn'
      include 'io.cmn'
c
      integer ierr
      character*(*) filename
c
      logical err
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
c     Third argument says to overwrite any existing file (VMS only)
      call write_savefile(filename,current_window_id,.FALSE.,err)
      if( err ) then
         ierr = 2
      else
         ierr = 0
      endif
c
      return
      end
c
      subroutine pm_restore_notes_from_file_gui(window,note_file,ierr)
      implicit none
c
c     Programmer: John Faricelli
c     Date: 8-Nov-94
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'plot.cmn'
      include 'compare.cmn'
      include 'units.cmn'
      include 'data.cmn'
      include 'defaults.cmn'
      include 'annotations.cmn'
      include 'io.cmn'
c
      integer window, ierr
      character*(*) note_file
c
      logical err
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      call read_savefile(note_file,.TRUE.,err)
      if( .NOT. err ) then
         call anno_restore_notes_from_save(current_window_id,err)
      endif
      if( err ) then
         ierr = 2
      else
         ierr = 0
      endif
c
      return
      end
c
      subroutine pm_read_pmifile_gui(filename, curv_flag, ierr)
      implicit none
c
c     Programmer: John Faricelli
c     Date: 9-Nov-94
c
      include 'sysdep.cmn'
      include 'const.h'
      include 'io.cmn'
      include 'gui.cmn'
c
      integer curv_flag, ierr
      character*(*) filename
c
c     Locals
      integer rc, istat, curv_convert_curv_to_pmi, pm_put_error_msg
      logical err
      character*(PM_MAX_PATHLEN) tmpfile
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      err = .FALSE.
      ierr = 0
      call pm_clear_error_msg
c
      if( curv_flag .eq. 0 ) then
         tmpfile = filename
      else
         rc = curv_convert_curv_to_pmi(filename,'POSTMINI.PMI')
         if( rc .eq. 0 ) then
            istat = pm_put_error_msg('Curv file had syntax errors')
            ierr = 2
            return
         endif
         tmpfile = 'POSTMINI.PMI'
      endif
c
      gui_error_level = 0
c
      call do_restore_plot(tmpfile,err)
c
      ierr = gui_error_level
c
      return
      end
c
      integer function pm_get_num_curves_gui
      implicit none
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'compare.cmn'
c
c     init_common will only allow one intialization, so it's safe to
c     call anywhere.
      call init_common
c
      pm_get_num_curves_gui = n_cuts
      return
c
      end
c
      integer function pm_put_log_option_xy_gui(window,icode,lvalue)
      implicit none
c
      integer window, icode
      logical lvalue
c
      include 'const.h'
      include 'gui.cmn'
c
      if( icode .eq. 1 ) then
c        icode == 1: nolabels
         gui_nolabels = lvalue
         pm_put_log_option_xy_gui = 0
      else
         pm_put_log_option_xy_gui = 1
      endif
c
      return
      end
c
      integer function pm_get_log_option_xy_gui(window,icode,lvalue)
      implicit none
c
      integer window, icode
      logical lvalue
c
      include 'const.h'
      include 'gui.cmn'
c
      if( icode .eq. 1 ) then
c        icode == 1: nolabels
         lvalue = gui_nolabels
         pm_get_log_option_xy_gui = 0
      else
         pm_get_log_option_xy_gui = 1
      endif
c
      return
      end
c
      subroutine pm_set_gui_mode(lmode)
      implicit none
c
      include 'const.h'
      include 'sysdep.cmn'
      include 'io.cmn'
c
c     Set gui flag in Postmini's common block. This trivial routine
c     is written to make it easier to call from C.
c
      logical lmode
c
c     Make sure common is initialized, which sets lgui flag to .FALSE.
      call init_common
c
c     Set gui flag
      lgui = lmode
c
      return
c
      end
