      SUBROUTINE ABQMAIN
C====================================================================
C This program must be compiled and linked with the command:
C     abaqus make job=frad
C Run the program using the command:
C     abaqus frad
C====================================================================
C
C  PURPOSE:
C     This program reads the results file and outputs the radiation 
C     viewfactors, and facet areas associated with different facets
C     in a cavity. 
C
C  PROMPTS:
C     1. 'Enter the name of the results file (w/o .fil):'
C
C====================================================================
C
C  INPUT  FILE ---- 'FNAME'.fil
C  OUTPUT FILE ----  vfout
C
C====================================================================
C
      INCLUDE 'aba_param.inc'
      DIMENSION ARRAY(513),JRRAY(NPRECD,513),LRUNIT(2,1)
      EQUIVALENCE (ARRAY(1),JRRAY(1,1))
      DIMENSION COORD(3),TRACT(3),CLEAR(3)
C
      CHARACTER*80 FNAME,OUTFILE,TEMP
      CHARACTER*8  TEMP1
      CHARACTER*3 NULL
      LOGICAL STRNCMP
      PARAMETER (ZERO=0.0D0,ONE=1.0D0,TWO=2.0D0,NULL='   ')
C------------------------------------------------------------
C     NRU          Number of results files (*.fil) to be read
C     LRUNIT(1,*)  Unit number of results file
C     LRUNIT(2,*)  Format of input file (1 = ASCII, 2 = BINARY)
C     LOUTF        Format of output file (not needed here)
C     COORD(*)     Stores the nodal coordinates
C     IXX          Record length
C     KEY          Record key
C     LSTEPA       Step Number
C     LINCA        Increment Number
C------------------------------------------------------------
C
C--- Initialize File ---------------------------------------
      NRU = 1
      LRUNIT(1,NRU) = 8
      LRUNIT(2,NRU) = 2
      LOUTF   = 0
      OUTFILE = 'vfout'
      FNAME   = NULL
C--- Change below to set to desired step and increment when 
C--- requesting restricted output; Default is for all steps 
C--- and increments available in the results file

      LSTEPA  = 1
      LINCA   = 1
C---
C
C Get the name of the results (.fil) file
C
C------------------------------------------------------------
        WRITE(6,*) ' Enter the name of the results file (w/o .fil): '
        READ (5,'(A)', IOSTAT=J) FNAME
        IF (J .NE. 0) WRITE(*,*) 'ERROR IN READING INPUT DATA'
C
C
C Access ABAQUS libraries and open input file
C------------------------------------------------------------

        CALL INITPF(FNAME, NRU, LRUNIT, LOUTF)
        OPEN(UNIT=15,FILE=OUTFILE,STATUS='UNKNOWN')
        JUNIT = LRUNIT(1,NRU)
        CALL DBRNU(JUNIT)
C------------------------------------------------------------
C End access
C
        CALL DBFILE(0, ARRAY, JRCD)
        if (jrcd .ne. 0) write(15,*) 'ERROR IN FILE-ACCESS'
        DO WHILE (JRCD .EQ. 0)
C
C IXX = Record length
C
           IXX = JRRAY(1,1)
C
C KEY = Record type key
C
         KEY = JRRAY(1,2)
C
C Output Request Definition
C

        IF(KEY .EQ. 2000) THEN
         LINC = JRRAY(1,9)
         LSTEP= JRRAY(1,8)
        END IF

C Output desired quantities to the output file
C
C-----------------------------------------------------------
C Uncomment below to get output for specific increment/step. 
C Default output is for all increments available in the file.
C-----------------------------------------------------------
C        IF((LINC .EQ. LINCA) .AND. (LSTEP .EQ. LSTEPA)) THEN

         IF (KEY .EQ. 2000) THEN
         WRITE(15,'(/,1X,A,1X,I6,1X,A,I6)')'STEP NUMBER', LSTEP,
     1            'INCREMENT',LINC
         WRITE(*,'(/,1X,A,1X,I6,1X,A,I6)') 'WRITING OUTPUT FOR STEP', 
     1                        LSTEP, 'INCREMENT', LINC
         END IF
         
           IF(KEY .EQ. 1605)THEN
              NUMFACETS = JRRAY(1,3)
              WRITE(TEMP,'(A)') ARRAY(4)
              WRITE(15,30)TEMP,NUMFACETS
 30           FORMAT(//,1X,'CAVITY NAME:',1X,A,/,
     1               1X,'NUMBER OF FACETS:',1X,I6)
           ELSEIF(KEY .EQ. 1609) THEN
              MVFLEN = JRRAY(1,3)
              MATRIXSIZE = INT(SQRT(REAL(MVFLEN)))
            ELSEIF( KEY .EQ. 1606 ) THEN
              WRITE(15,'(/,1X,A)')'VIEWFACTOR MATRIX (ROW - COLUMN)'
              WRITE(15,40) (ARRAY(I),I=3,JRRAY(1,1))
 40           FORMAT(1X,1PE14.6,', ')
            ELSEIF(KEY .EQ. 1607) THEN
              WRITE(15,'(/,1X,A)') 'FACET AREA'
              WRITE(15,50)(ARRAY(I),I=3,JRRAY(1,1))
 50           FORMAT(1X,1PE14.6,', ')
           ENDIF

C        ENDIF

        CALL DBFILE(0, ARRAY, JRCD)
      
      ENDDO
      RETURN
      END




