!*********************************************************************72
! COPYRIGHT 2011,2012 ANTON SHTERENLIKHT, UNIVERSITY OF BRISTOL, UK.
! ALL RIGHTS RESERVED.
!
! REDISTRIBUTION AND USE IN SOURCE AND BINARY FORMS, WITH OR
! WITHOUT MODIFICATION, ARE PERMITTED PROVIDED THAT THE FOLLOWING
! CONDITIONS ARE MET:
!  1. REDISTRIBUTIONS OF SOURCE CODE MUST RETAIN THE ABOVE COPYRIGHT
!     NOTICE, THIS LIST OF CONDITIONS AND THE FOLLOWING DISCLAIMER.
!  2. REDISTRIBUTIONS IN BINARY FORM MUST REPRODUCE THE ABOVE
!     COPYRIGHT NOTICE, THIS LIST OF CONDITIONS AND THE FOLLOWING
!     DISCLAIMER IN THE DOCUMENTATION AND/OR OTHER MATERIALS
!     PROVIDED WITH THE DISTRIBUTION.
!
! THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
! EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
! THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
! (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
! GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
! NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
! THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
!*********************************************************************72
!
! THIS FORTRAN FILE IS IN FREE FORMAT.
! IT SHOULD CONFORM TO FORTRAN 2008 STANDARD, ISO/IEC 1539-1:2010
!
! FTP://FTP.NAG.CO.UK/SC22WG5/N1801-N1850/N1830.PDF
!
!*********************************************************************72

SUBROUTINE ABQMAIN

! MUST HAVE THESE LINES
 INCLUDE 'ABA_PARAM.INC'
 DIMENSION  ARRAY(513), JRRAY(NPRECD,513), LRUNIT(2,1)
 EQUIVALENCE (ARRAY(1), JRRAY(1,1))

 CHARACTER*80 FNAME

! FILE INITIALISATION

 FNAME="gtn-st-1fer-abq" ! THE *.FIL FILE TO READ, NO EXTENSION
 NRU=1                   ! NUMBER OF FILES TO READ, JUST 1
 LRUNIT(1,1)=8           ! UNIT NUMBER, 8 ASSUMES EXTENSION .FIL
 LRUNIT(2,1)=2           ! 2-BINARY, 1-ASCII
 LOUTF=0                 ! WILL NOT WRITE ANOTHER RES. FILE

 ! OPEN THE *.FIL FILE FOR READING
 CALL INITPF(TRIM(FNAME),NRU,LRUNIT,LOUTF)

! SET A UNIT NUMBER FOR A FILE

 JUNIT=8                 ! USE 8 FOR *.FIL
 CALL DBRNU(JUNIT)       ! SET THE UNIT NUMBER

! LOOP ON ALL RECORDS IN RESULTS FILE

 DO
   LOP=0                   ! READ THE NEXT RECORD FROM *FIL
   CALL DBFILE(LOP,ARRAY,JRCD)
   IF (JRCD.NE.0) EXIT
   KEY = JRRAY(1,2)

   ! HEADING
   IF (KEY .EQ. 1922) WRITE(*,"(1X,10A8)") (ARRAY(IXX),IXX=3,12) ! HEADING

   ! INCREMENT START RECORD
   IF (KEY .EQ. 2000) WRITE(*,"(1X,'** STEP ',I2,' INCREMENT ',I3)") &
     JRRAY(1,8), JRRAY(1,9)

1001 FORMAT(A5,TR1,ES12.5)

   ! STRESS
   IF (KEY .EQ. 11) THEN
     WRITE(*,1001)"S11",ARRAY(3)
     WRITE(*,1001)"S22",ARRAY(4)
     WRITE(*,1001)"S33",ARRAY(5)
     WRITE(*,1001)"S12",ARRAY(6)
     WRITE(*,1001)"S13",ARRAY(7)
     WRITE(*,1001)"S23",ARRAY(8)
   END IF

   ! STRESS INVARIANTS
   IF (KEY .EQ. 12) THEN
     WRITE(*,1001)"MISES",ARRAY(3)
     WRITE(*,1001)"PRESS",ARRAY(5)
   END IF

   ! LOG STRAINS
   IF (KEY .EQ. 89) THEN
     WRITE(*,1001)"LE11",ARRAY(3)
     WRITE(*,1001)"LE22",ARRAY(4)
     WRITE(*,1001)"LE33",ARRAY(5)
     WRITE(*,1001)"LE12",ARRAY(6)
     WRITE(*,1001)"LE13",ARRAY(7)
     WRITE(*,1001)"LE23",ARRAY(8)
   END IF

   ! ELASTIC STRAINS
   IF (KEY .EQ. 25) THEN
     WRITE(*,1001)"EE11",ARRAY(3)
     WRITE(*,1001)"EE22",ARRAY(4)
     WRITE(*,1001)"EE33",ARRAY(5)
     WRITE(*,1001)"EE12",ARRAY(6)
     WRITE(*,1001)"EE13",ARRAY(7)
     WRITE(*,1001)"EE23",ARRAY(8)
   END IF

   ! PLASTIC STRAINS
   IF (KEY .EQ. 22) THEN
     WRITE(*,1001)"PE11",ARRAY(3)
     WRITE(*,1001)"PE22",ARRAY(4)
     WRITE(*,1001)"PE33",ARRAY(5)
     WRITE(*,1001)"PE12",ARRAY(6)
     WRITE(*,1001)"PE13",ARRAY(7)
     WRITE(*,1001)"PE23",ARRAY(8)
     WRITE(*,1001)"PEEQ",ARRAY(9)
   END IF

   ! VVF
   IF (KEY .EQ. 413) THEN
     WRITE(*,1001)"VVF", ARRAY(3)
   END IF

   ! VVFN
   IF (KEY .EQ. 415) THEN
     WRITE(*,1001)"VVFN", ARRAY(3)
   END IF

   ! VVFG
   IF (KEY .EQ. 414) THEN
     WRITE(*,1001)"VVFG", ARRAY(3)
   END IF

   ! ENERGY DENSITIES
   IF (KEY .EQ. 14) THEN
     WRITE(*,1001)"SENER",ARRAY(3)
     WRITE(*,1001)"PENER",ARRAY(4)
   END IF

   ! ENERGIES
   IF (KEY .EQ. 19) THEN
     WRITE(*,1001)"ELSE",ARRAY(4)
     WRITE(*,1001)"ELPD",ARRAY(5)
     WRITE(*,1001)"ELASE",ARRAY(9)
   END IF

 END DO

END SUBROUTINE ABQMAIN
