!  Form RMA10 input files
!
      PROGRAM RMA10PRP
!
      USE WINTERACTER

      USE RESID
      USE BLK1
      USE BLKRM10
      USE IFPORT
!
      IMPLICIT NONE
!
      INTEGER, PARAMETER :: MFPS      = 30        ! Maximum frames per second
      REAL   , PARAMETER :: PI        = 3.1415926
      REAL   , PARAMETER :: AngleStep = PI/30.
      REAL, PARAMETER    :: DEFDIST = 5.0
!
      REAL               :: ViewAngle = 0.0
      REAL               :: SHIFT=0.0
      REAL               :: ROTH=0.0
      REAL               :: ROTV=0.0
      REAL               :: ROT=0.0
      INTEGER            :: ITYPE,K,JRGB,JTIMES,N,IHSW,IER,LENNAME
      INTEGER            :: IHBITMAP,ITYPIMAGE
      INTEGER , DIMENSION(5) :: WIDSTAT
      TYPE(WIN_STYLE)    :: WINDOW
      TYPE(WIN_MESSAGE)  :: MESSAGE
      LOGICAL            :: CHANGED,ONEC,EXISTD
      CHARACTER(LEN=50)   :: STBAR
      ITYPIMAGE=4
      JTIMES=1
      ONEC=.FALSE.
!
!  Initialise Winteracter
!
      CALL WInitialise()
!
!  Open root window - keep it fixed in size for sake of this example
!
      CALL WindowOpen(FLAGS  =SysMenuOn+MinButton+MaxButton+StatusBar,     &
                   MENUID=IDM_MENU1,                               &
                   TOOLID=(/0,IDT_TOOLBAR1,0,0/),                  &
                      TITLE  ='View RMA 10 model files', &
                      NCOL256=128)
!                             +FixedSizeWin, &
!                      WIDTH  =500,          &
!                      HEIGHT =500,          &
!
!  Create a bitmap of same size as window and draw initial frame
!
      WIDSTAT(1) = 1000
      WIDSTAT(2) = 2000
      WIDSTAT(3) = 1000
      WIDSTAT(4) = 1000
      WIDSTAT(5) = 6000
      CALL WindowStatusBarParts(5, WIDSTAT)
      CALL WindowOutStatusBar(4, '  Active File Name')
      CALL WindowOutStatusBar(5,NAMEFL)
      
      CALL WBitmapCreate(IHBITMAP,WInfoWindow(WindowWidth), &
                                  WInfoWindow(WindowHeight))
      IER=GETCWD(HELPDIR)
      DO K=255,1,-1
        LENNAME=K
        IF(HELPDIR(K:K) .NE. ' ') EXIT
       ENDDO
       HELPDIR(K+1:K+5)='\HELP'
       CALL DEFAULTS
       CALL DEFAULTCN

!
!
!  Main Message loop, keep asking for and processing
!  messages until the user selects the Exit option.
!
      DO
        CALL WindowOutStatusBar(5,NAMEFL)
        CALL WMessage(ITYPE,MESSAGE)
        SELECT CASE (ITYPE)
          CASE (KeyDown)
            IF (MESSAGE%VALUE1==KeyEscape) EXIT

          CASE (MenuSelect)              ! Menu item selected
            SELECT CASE (MESSAGE%VALUE1)
            CASE (ID_OPENRM2)
              CALL READRM10
            CASE (ID_BUTTON8)
              CALL READRM10
            CASE (ID_CONVERT)
              CALL CONVERT
            CASE (ID_BUTTON4)
              CALL CONVERT
            CASE (ID_ITEM21)
              CALL FORMFILE
            CASE (ID_BUTTON5)
              CALL FORMFILE
            CASE (ID_ITEM16)
              CALL SHOWFILES
            CASE (ID_CP1)
              CALL SHOWCNTRL(1)
            CASE (ID_CP2)
              CALL SHOWCNTRL(2)
            CASE (ID_CP3)
              CALL SHOWCNTRL(3)
            CASE (ID_CP4)
              CALL SHOWCNTRL(4)
!              DO N=3,17
!              WRITE(155,*) N,INTG(N)
!              ENDDO
!              DO N=1,11
!                WRITE(155,*) N,RLDAT(N)
!              ENDDO
!              DO N=1,NMAT
!                WRITE(155,*) N,ORT(N,1),ORT(N,5),ORT(N,7)
!              ENDDO
            CASE (ID_ITEM6)
              CALL SHOWTIMESTP(JTIMES)
            CASE (ID_RUNRMA2)
              CALL RUNRMA10
            CASE (ID_HELP)
              IHSW=1
              CALL HELP10(IHSW)
            CASE (ID_HELPUSER)
              IHSW=99
              CALL HELP10(IHSW)
            CASE (ID_MENUITEM)
              IHSW=98
              CALL HELP10(IHSW)
            CASE (ID_ABOUT)
              IHSW=97
              CALL HELP10(IHSW)
            CASE (ID_EXIT)
              EXIT
            CASE (ID_EX)
              EXIT
            ENDSELECT
          CASE (CloseRequest)
            EXIT
        END SELECT
      END DO
!
      CALL WindowClose()
      STOP
      END
!
