      SUBROUTINE RECPUT(NF,IBUF)                      
C                                 
C     * JUL 07/03 - A.IRWIN,F.MAJAESS (REVISED FOR F90 AND LINUX PLATFORMS)
C     * NOV 02/92 - E.CHAN   (REPLACE WRITES WITH CALLS TO WRTBUF)
C     * JUL 23/92 - E.CHAN   (ENSURE THAT DATA RECORD IS WRITTEN OUT
C     *                       BEGINNING AT WORD 9 OF IBUF)
C     * APR 21/92 - J.STACEY (REVISED TO IMPLEMENT PORTABILITY ACROSS
C     *                       BOTH 32- AND 64-BIT MACHINES)
C     * FEB 11/81 - J.D.HENDERSON.                   
C
C     * WRITES RECORD IMAGE IN IBUF TO FILE NF.    
C     * LABEL IS IN IBUF(1-8) FOLLOWED BY THE DATA (POSSIBLY PACKED).
C                                                                   
      IMPLICIT REAL (A-H,O-Z),
     +INTEGER (I-N)
      LOGICAL OK, LENDIAN
      INTEGER IBUF(*),JBUF(16),JBUFPT(8,2)
      COMMON /MACHTYP/ MACHINE,INTSIZE
      DATA    JBUFPT/1,2,3,4,5,6,7,8,1,4,5,8,10,12,14,16/
C     DATA    JBLANK/4H    /
C---------------------------------------------------------------------
      JBLANK=NC4TO8("    ")
C     * GET RECORD LENGTH.
C                        
      CALL LBLCHK(LEN,NWDS,NPACK,IBUF)

      IF(LENDIAN()) THEN
C        CALCULATE THIS BASED ON RESULTS FOR WRTBUF ARGUMENT BELOW.
        IMAX = LEN - (8*MACHINE) + 8
        IF(IBUF(1).EQ.NC4TO8("LABL").OR.IBUF(1).EQ.NC4TO8("CHAR")) THEN
C          IN THE OVERALL CONVERSION FROM LITTLE-ENDIAN UNFORMATTED RECORDS TO
C          BIG ENDIAN, HOLLERITH CONSTANTS WILL BE INAPPROPRIATELY
C          REVERSED.  REVERSE THEM BACK.
          DO 300 I = 9,IMAX
            IF(MACHINE.EQ.2) THEN
              CALL REVERSE(IBUF(I),4)
            ELSE
              CALL REVERSE(IBUF(I),8)
            ENDIF
  300     CONTINUE
        ELSEIF(INTSIZE.EQ.2.AND.(NPACK.EQ.0.OR.NPACK.EQ.1)) THEN
C          IN THE OVERALL CONVERSION FROM LITTLE-ENDIAN UNFORMATTED RECORDS TO
C          BIG ENDIAN FOR INTSIZE = 2, THE BYTE-REVERSAL WILL BE DONE
C          FOR INDIVIDUAL 4-BYTE WORDS RATHER THAN THE 8-BYTE WORDS CONTAINING
C          FLOATING-POINT NUMBERS.  TO GET THOSE 8-BYTE NUMBERS IN THE
C          CORRECT ORDER MUST SWAP EVERY SECOND WORD.
          DO 310 I = 9,IMAX-1,2
            ISWAP = IBUF(I)
            IBUF(I) = IBUF(I+1)
            IBUF(I+1) = ISWAP
  310     CONTINUE
        ELSEIF(NPACK.NE.0.AND.NPACK.NE.1) THEN
          IMAX3 = 8+4
          IF(IBUF(1).EQ.NC4TO8("SPEC")) IMAX3 = IMAX3 + 2
          IF(INTSIZE.EQ.2) THEN
C            IN THE OVERALL CONVERSION FROM LITTLE-ENDIAN UNFORMATTED RECORDS TO
C            BIG ENDIAN FOR INTSIZE = 2, THE BYTE-REVERSAL WILL BE DONE
C            FOR INDIVIDUAL 4-BYTE WORDS RATHER THAN THE 8-BYTE WORDS CONTAINING
C            FLOATING-POINT NUMBERS.  TO GET THOSE 8-BYTE NUMBERS IN THE
C            CORRECT ORDER MUST SWAP EVERY SECOND WORD.
            DO 320 I = 9,IMAX3-1,2
              ISWAP = IBUF(I)
              IBUF(I) = IBUF(I+1)
              IBUF(I+1) = ISWAP
  320       CONTINUE
          ENDIF
C          IN THE OVERALL CONVERSION FROM LITTLE-ENDIAN UNFORMATTED RECORDS TO
C          BIG ENDIAN FOR MACHINE = 1, THE BYTE-REVERSAL WILL BE DONE
C          FOR INDIVIDUAL 8-BYTE WORDS RATHER THAN THE 4-BYTE WORDS THAT
C          ARE THE STANDARD FOR PACKED DATA.  HOWEVER, IN THIS SAME CASE
C          (LITTLE-ENDIAN, MACHINE=1, SEE SBYTESB TO VERIFY THIS) SBYTESB
C          EFFECTIVELY WORD SWAPS SO EVERYTHING WORKS OUT AND THERE IS NO
C          NEED FOR ADDITIONAL WORD SWAPPING HERE.
        ENDIF
C        IN THE OVERALL CONVERSION FROM LITTLE-ENDIAN UNFORMATTED RECORDS TO
C        BIG ENDIAN, HOLLERITH CONSTANTS WILL BE INAPPROPRIATELY
C        REVERSED.  REVERSE THEM BEFOREHAND TO COMPENSATE.
        IF(MACHINE.EQ.2) THEN
          CALL REVERSE(IBUF(1),4)
          CALL REVERSE(IBUF(3),4)
        ELSE
          CALL REVERSE(IBUF(1),8)
          CALL REVERSE(IBUF(3),8)
        ENDIF
      ENDIF
C
C     * REARRANGE HEADER DATA INTO CCRD/N STANDARD FORMAT.  BE SURE TO
C     * FILL ALL THE 32-BIT PARTS OF EACH 64-BIT WORD IF MACHINE IS A
C     * 32-BIT MACHINE.  ON 64' MACHINES WE SAVE IBUF(I), THEN SET IT
C     * TO ZERO, THEN SET IT TO 4 BLANKS, BEFORE SETTING IT TO ITEMP.  ON 32'
C     * MACHINES THE SAME OPERATIONS SETS THE HIGH ORDER 32-BITS OF THE 8 8-BYTE
C     * HEADER WORDS TO ZERO, THE LOW-ORDER 32-BITS TO BLANKS, THEN INITIALIZES
C     * THE APPROPRIATE PARTS OF THE HEADER WITH HOLLERITH AND INTEGER DATA AS
C     * APPROPRIATE.
C
      DO 5 I=8,1,-1
        JTEMP                     = IBUF(I)
        JBUF((I-1)*MACHINE+1)     = 0      !CLEAR IBUF(I)/HI-ORDER 32'
        JBUF(I*MACHINE)           = JBLANK !LO-ORDER 32' SET TO BLANKS.
        JBUF(JBUFPT(I,MACHINE))   = JTEMP
    5 CONTINUE
C
C     * WRITE THE HEADER AND DATA RECORD IN TWO-RECORD FORMAT.
C
      LHEAD = 8 * MACHINE
      CALL WRTBUF(NF,JBUF,LHEAD,OK)
      IF(LENDIAN()) THEN
C        RESTORE HEADER (IN CASE OF EXTERNAL RE-USE) TO LITTLE-ENDIAN FORM.
        IF(MACHINE.EQ.2) THEN
          CALL REVERSE(IBUF(1),4)
          CALL REVERSE(IBUF(3),4)
        ELSE
          CALL REVERSE(IBUF(1),8)
          CALL REVERSE(IBUF(3),8)
        ENDIF
      ENDIF
      IF (.NOT. OK)                             CALL XIT('RECPUT',-1)
      CALL WRTBUF(NF,IBUF(9),LEN-LHEAD,OK)
      IF(LENDIAN()) THEN
C        RESTORE DATA RECORD (IN CASE OF EXTERNAL RE-USE) TO
C        LITTLE-ENDIAN FORM.
C        REVERSE DO LOOPS FOR CACHE EFFICIENCY.
        IF(IBUF(1).EQ.NC4TO8("LABL").OR.IBUF(1).EQ.NC4TO8("CHAR")) THEN
          DO 400 I = IMAX,9,-1
            IF(MACHINE.EQ.2) THEN
              CALL REVERSE(IBUF(I),4)
            ELSE
              CALL REVERSE(IBUF(I),8)
            ENDIF
  400     CONTINUE
        ELSEIF(INTSIZE.EQ.2.AND.(NPACK.EQ.0.OR.NPACK.EQ.1)) THEN
          DO 410 I = IMAX-1,9,-2
            ISWAP = IBUF(I)
            IBUF(I) = IBUF(I+1)
            IBUF(I+1) = ISWAP
  410     CONTINUE
        ELSEIF(NPACK.NE.0.AND.NPACK.NE.1) THEN
          IF(INTSIZE.EQ.2) THEN
            DO 420 I = 9,IMAX3-1,2
              ISWAP = IBUF(I)
              IBUF(I) = IBUF(I+1)
              IBUF(I+1) = ISWAP
  420       CONTINUE
          ENDIF
        ENDIF
      ENDIF
      IF (.NOT. OK)                             CALL XIT('RECPUT',-2)
      RETURN   
      END     
