      PROGRAM GRAFIT
C----------------------------------------------------------------
C
C     AUTHOR: RONG-SHENG ZHOU
C
C     NEW YORK STATE COLLEGE OF CERAMICS
C     ALFRED UNIVERSITY (GRADUATE STUDENT, 1984-1988).
C     CHEMISTRY DEPARTMENT
C     BOSTON COLLEGE    (POST-DOC FELLOW,  1988-1989).
C     COPYRIGHT BY RONG-SHENG ZHOU.
C
C-----------------------------------------------------------------
C
C     PROGRAM LANGUAGE  : DEC VAX/VMS FORTRAN.
C     INITIALLY WRITTEN : JUNE, 1986.
C     PROGRAM STATUS    : DEVELOPMENTAL.
C
C     PROGRAM FUNCTION:
C     -----------------
C     A 2-D SCIENTIFIC INTERACTIVE GRAPHICS PACKAGE.
C     THE DIALOGUE SCHEME IS DESIGNED MAINLY FOR VT100
C     COMPATIBLE TERMINALS, THE SCREEN GRAPHICS MAINLY
C     FOR TEKTRONIX-4100'S.
C
C-----------------------------------------------------------------
      PARAMETER (ITEM= 17)
      CHARACTER MENU(ITEM)*20
      DIMENSION IC(ITEM), IL(ITEM)
      DATA IC / 17,17,17,17,17,17,17,17,45,45,45,45,45,45,45,45,17 /
      DATA IL / 7,8,9,10,11,12,13,14,7,8,9,10,11,12,13,14,15 /
      DATA MENU( 1) / '1> XY Plot' /
      DATA MENU( 2) / '2> Layout Plot' /
      DATA MENU( 3) / '3> Contour Plot' /
      DATA MENU( 4) / '4> Histogram Plot' /
      DATA MENU( 5) / '5> Piechart Plot' /
      DATA MENU( 6) / '6> Text Plot' /
      DATA MENU( 7) / '7> Function Plot' /
      DATA MENU( 8) / '8> Digitization' /
      DATA MENU( 9) / 'A> C3DCON' /
      DATA MENU(10) / 'B> ORTEP' /
      DATA MENU(11) / 'C> STRCON' /
      DATA MENU(12) / 'D> PLOT1' /
      DATA MENU(13) / 'E> Phi/Psi Plot' /
      DATA MENU(14) / 'F> Luzzati Plot' /
      DATA MENU(15) / 'G> Torsion Plot' /
      DATA MENU(16) / 'H> ' /
      DATA MENU(17) / '0> Exit' /
C
C  PARSE THE ACTIVATING DCL COMMAND LINE...
C
      KEY = IF_DCL_PUT( 'GRAFIT' )
      IF( KEY.LT.0 ) GOTO 999
      IF( KEY.GT.0 ) GOTO 222
C
C  LAYOUT THE MAIN MENU...
C
      CALL GRAFIT_MENU( IL, IC, MENU )
C
C  GET THE FUNCTION TO PERFORM...
C
  111 CALL IFQIOW_KEY( KEY )
      IF( KEY.EQ.26 .OR. KEY.EQ.32 .OR. KEY.EQ.48 ) GOTO 999
      KEY = KEY-48
      IF( KEY.GT.8 ) THEN
          KEY = KEY - 8
          IF( KEY.LT.8 ) GOTO 333
      ENDIF
      IF( KEY.LT.1 .OR. KEY.GT.ITEM-2 ) GOTO 333
      CALL IFANSI_CURSOR(IL(ITEM)+1,1)
      CALL IFANSI_CLEAR(6)
      NCHS=IFMISC_LENG( MENU(KEY) ) - 1
      CALL IFANSI_VIDEO(30)
      CALL IFANSI_TEXT( MENU(KEY)(3:), NCHS, IL(KEY), IC(KEY)+2 )
      CALL IFANSI_VIDEO(47)
  222 IF( KEY.EQ.1 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_XYPLOT.EXE' )
      ELSE IF( KEY.EQ.2 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_C2DCAD.EXE' )
      ELSE IF( KEY.EQ.3 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_MAPLOT.EXE' )
      ELSE IF( KEY.EQ.4 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_BARPLT.EXE' )
      ELSE IF( KEY.EQ.5 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_PIEPLT.EXE' )
      ELSE IF( KEY.EQ.6 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_TXTPLT.EXE' )
      ELSE IF( KEY.EQ.7 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_FUNPLT.EXE' )
      ELSE IF( KEY.EQ.8 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_DIGITI.EXE' )
      ELSE IF( KEY.EQ.9 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_C3DCON.EXE' )
      ELSE IF( KEY.EQ.10 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_ZORTEP.EXE' )
      ELSE IF( KEY.EQ.11 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_STRCON.EXE' )
      ELSE IF( KEY.EQ.12 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_PLOT1Z.EXE' )
      ELSE IF( KEY.EQ.13 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_PHIPSI.EXE' )
      ELSE IF( KEY.EQ.14 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_LUZATI.EXE' )
      ELSE IF( KEY.EQ.15 ) THEN
          KEY = LIB$RUN_PROGRAM( 'GRAFIT$EXE:GRAFIT_TORSIO.EXE' )
      ENDIF
      IF( .NOT.KEY ) CALL LIB$SIGNAL( %VAL(KEY) )
      GOTO 999
  333 CALL IFANSI_TEXT('>>> Invalid Key Pressed <<<',27,IL(ITEM)+1,26)
      CALL IFANSI_CURSOR(IL(ITEM),IC(ITEM))
      GOTO 111
  999 CALL IFANSI_CLEAR(2)
      CALL EXIT
      END

      SUBROUTINE GRAFIT_MENU( IL, IC, MENU )
C
C     THIS ROUTINE LAYOUTS GRAFIT'S MAIN FUNCTION MENU.
C
      PARAMETER (ITEM= 17)
      CHARACTER TEXT*80, MENU(ITEM)*20
      DIMENSION IC(ITEM), IL(ITEM)
C
C  LAYOUT GRAFIT MENU...
C
      CALL IFANSI_CLEAR(0)
      CALL IFANSI_MARGIN(0,0)
      CALL IFANSI_VIDEO(30)
      CALL IFANSI_VIDEO(80)
      TEXT = '   GRAFIT: A General Graphics Package (VS:06/90)'
      CALL IFANSI_TEXT( TEXT, 51, 3, 14 )
      CALL IFANSI_VIDEO(47)
      CALL IFANSI_VIDEO(80)
      CALL IFANSI_VIDEO(90)
      TEXT = '        M A I N   F U N C T I O N   M E N U'
      CALL IFANSI_TEXT( TEXT, 51, 5, 14 )
      CALL IFANSI_VIDEO(47)
      DO I=1, ITEM
         NCHS = IFMISC_LENG( MENU(I) )
         IF(NCHS.GT.0) CALL IFANSI_TEXT(MENU(I),NCHS,IL(I),IC(I))
      ENDDO
      CALL IFANSI_VIDEO(30)
      TEXT = '       Please press a desired function key'
      CALL IFANSI_TEXT( TEXT, 51, 17, 14 )
      CALL IFANSI_VIDEO(47)
      TEXT = '* File types BC,DI,HP,PS,IM,PAR are reserved.'
      CALL IFANSI_TEXT( TEXT, 45, 18, 17 )
      TEXT = '* Press SPACEBAR to take the default branch.'
      CALL IFANSI_TEXT( TEXT, 44, 19, 17 )
      TEXT = '* Press CTRL/Z wherever you wish to exit.'
      CALL IFANSI_TEXT( TEXT, 41, 20, 17 )
      CALL IFANSI_CURSOR(IL(ITEM),IC(ITEM))
      RETURN
      END
