     	SUBROUTINE MAPLOT_MAIN
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY   JULY-1985
C
C	MAIN ROUTINE OF CONTOUR PLOT.
C
    	INCLUDE		'MAPLOT.CBS'
     	DIMENSION	RP(2)
C
C  INITIALIZE PLOT PARAMETERS...
C
     	CALL MAPLOT_INIT( 0 )
C
C  CHECK DCL COMMAND LINE INPUT...
C
     	CALL MAPLOT_DCL( KEY )
     	IF( KEY.NE.0 ) GOTO 333
C
C  CONDUCT THE DIALOGUE...
C
  222	CALL MAPLOT_MENU( KEY )
     	IF( KEY.NE.0 ) GOTO 999
C
C  CARRY OUT THE PLOTTING...
C
  333	CALL MAPLOT_PLOT
C
C  PRESENT LOCAL COMMAND MENU...
C
  444	CALL IFANSI_VIDEO(30)
     	WRITE(6,555)
  555	FORMAT(' MAPLOT_MENU (Please press a desired function code): ')
     	CALL IFANSI_VIDEO(47)
     	WRITE(6,556)
  556	FORMAT(' 0>Exit 1>Hardcopy 2>Layout 3>Dialog',
     +' 4>Zoom 5>Cursor 6>Redraw ?>Help ...')
     	CALL IFANSI_CURSOR(0,27)
  445	CALL IFQIOW_KEY( KEY )

     	IF( KEY.EQ.26 .OR. KEY.EQ.48 ) GOTO 999
     	IF( KEY.EQ.13 ) KEY = 51
     	IF( KEY.EQ.49 ) THEN		!HARDCOPY WITH PAGESETUP
     	    CALL IFCOPY( HPAR(1), PLOTID )
     	    CALL MAPLOT_SETUP( 0, PARNAM )
     	    CALL IFINIT_LINE( -3 )
     	ELSE IF( KEY.EQ.80 ) THEN	!HARDCOPY WITHOUT PAGE SETUP
     	    CALL IFANSI_CURSOR(0,-20)
     	    CALL IFFEED( HPAR(1), PLOTID, ' ' )
     	ELSE IF( KEY.EQ.50 ) THEN		!LAYOUT
     	    IF( DESNAM.EQ.' ' ) THEN
     		DESNAM = DATNAM
     		CALL IFMISC_NAMEXT( DESNAM, '.DES' )
     	    ENDIF
     	    CALL LAYOUT_MAIN( 2, XORG, YORG, DESNAM )
     	ELSE IF( KEY.EQ.51 .OR. KEY.EQ.82 ) THEN
     	    GOTO 222				!DIALOGUE MENU
     	ELSE IF( KEY.EQ.52 ) THEN		!ZOOM
     	    KEY = MAPLOT_ZOOM()
     	    IF( KEY.NE.0 ) GOTO 333
     	ELSE IF( KEY.EQ.53 ) THEN		!GIN
     	    CALL MAPLOT_GIN( RP, RP )
     	ELSE IF( KEY.EQ.54 ) THEN
     	    GOTO 333				!REDRAW THE PLOT
     	ELSE IF( KEY.EQ.63 .OR. KEY.EQ.81 ) THEN
     	    KEY = IFMISC_TYPE('GRAFIT$HLP:MAPLOT_HELP.HLP','MENU',-2)
     	    IF( KEY.GT.0 ) THEN
     		CALL IFANSI_VIDEO(70)
     		WRITE(6,777)
  777		FORMAT('_oops: Help file is not available.')
     		CALL IFANSI_VIDEO(47)
     	    ENDIF
     	ELSE IF( KEY.EQ.36 .OR. KEY.EQ.83 ) THEN	!SPAWN
     	    CALL IFMISC_SPAWN( '$', 0 )
     	    CALL IFINIT_LINE( -3 )
     	ELSE
     	    GOTO 445
     	ENDIF
    	GOTO 444
C
C  RETURN TO THE MAIN MENU...
C
  999	RETURN
	END

     	SUBROUTINE MAPLOT_DCL( ICODE )
C
C	THIS ROUTINE CHECKS THE INPUT COMMAND LINE.
C
     	INCLUDE 'MAPLOT.CBS'
C
C  IS THERE A FILE IN THE LINE...
C
     	ICODE = 0
     	CALL IF_DCL_NFILE( NFLS )
     	IF( NFLS.EQ.0 ) RETURN
C
C  GET MAP DATA FILE...
C
     	CALL IF_DCL_FILE( 1, ADDNAM )
     	IERR = MAPLOT_DATA( 1, ADDNAM )
     	IF( IERR.GT.0 ) GOTO 999
     	DATNAM = ADDNAM
     	IF( NFLS.GT.1 ) THEN
     	    CALL IF_DCL_FILE( 2, ADDNAM )
     	    IERR = MAPLOT_DATA( 2, ADDNAM )
     	    IF( IERR.GT.0 ) GOTO 999
     	ENDIF
     	CALL IF_DCL_SETUP( PARNAM )
     	IF( PARNAM.EQ.' ' ) THEN
     	    PARNAM = DATNAM
     	    CALL IFMISC_NAMEXT( PARNAM, '.PAR' )
     	ENDIF
     	CALL IF_DCL_LAYOUT( DESNAM )
     	IF( DESNAM.EQ.' ' ) THEN
     	    DESNAM = DATNAM
     	    CALL IFMISC_NAMEXT( DESNAM, '.DES' )
     	ENDIF
C
C  SCALE THE DATA...
C
     	CALL MAPLOT_INIT(1)
     	IERR = MAPLOT_SETUP( 1, PARNAM )
     	IF( IERR.EQ.0 ) THEN
     	    DO  I=1, 4
     		CALL MAPLOT_SCALE(I)
     	    ENDDO
     	ENDIF
     	ICODE = 1
     	IF( .NOT.IF_DCL_HARDCOPY() ) RETURN
C
C  MAKE THE HARDCOPY...
C
     	CALL MAPLOT_PLOT
     	CALL IFCOPY( HPAR(1), PLOTID )
     	GOTO 888
C
C  ERROR FROM READING A DATA_FILE...
C
999	IF( IERR.EQ.1 ) WRITE(6,1001) ADDNAM
     	IF( IERR.EQ.2 ) WRITE(6,1002) ADDNAM
     	IF( IERR.EQ.3 ) WRITE(6,1003) ADDNAM
     	IF( IERR.EQ.4 ) WRITE(6,1004) ADDNAM
     	IF( IERR.EQ.5 ) WRITE(6,1005) ADDNAM
1001	FORMAT(' %MAPLOT_DCL: can not open file ',A32)
1002	FORMAT(' %MAPLOT_DCL: no data found in file ',A32)
1003	FORMAT(' %MAPLOT_DCL: invalid data format in file ',A32)
1004	FORMAT(' %MAPLOT_DCL: map grid overflows in file ',A32)
1005	FORMAT(' %MAPLOT_DCL: map grid is different in file ',A32)
     	IF( .NOT.IF_DCL_HARDCOPY() ) RETURN
888	CALL EXIT
     	END

