      INTEGER FUNCTION NC4TO8(CHO4) 
C 
C     * THIS FUNCTION IS USED TO ENSURE THE LENGTH OF HOLLERITH STRING
C     * IS THE SAME AS THAT FOR THE DEFAULT INTEGER. IT IS MAINLY USED
C     * TO FIX "4H" HOLLERITH FOR "KIND" AND "NAME".
C
C     * MAR 02/1994 - F.MAJAESS
C     * AUG 08/2001 - M.VALIN F() STYLE BIG/LITTLE ENDIAN VERSION
C     * APR 29/2003 - F.MAJAESS (MAJOR RECODING TO FIX BIG/LITTLE ENDIAN
C     *                          SUPPORT, IMPROVE EFFICIENCY AND 
C     *                          HARMONIZE WITH OTHER LIBRARY MODULES)
C
      IMPLICIT NONE
      LOGICAL LENDIAN,FRSTCLL
      CHARACTER*4 CHO4,CBLANK,C4(2)
      INTEGER   I8, I8S, I1C, I, IFLAG, IORDR(4)
      INTEGER   K,KUPPR,KSTRT,KFNSH,KINCR
      INTEGER   MACHINE,INTSIZE,ME32O64,INTEFLT,IDUMMY
      COMMON /MACHTYP/ MACHINE,INTSIZE
      SAVE FRSTCLL,IFLAG,IORDR,KUPPR,KSTRT,KFNSH,KINCR
      DATA CBLANK/'    '/
C-----------------------------------------------------------------------
C     INITIALIZE "KUPPR","KSTRT","KFNSH","KINCR" VARIABLES AND "IORDER" 
C     ARRAY UPON INITIAL CALL TO "NC4TO8" FUNCTION.

      IF (FRSTCLL .OR. IFLAG.NE.-99) THEN
        MACHINE = ME32O64(IDUMMY)
        INTSIZE = INTEFLT(IDUMMY)

C       * SETUP "KUPPR" VALUE BASED ON INTEGER SIZE OF
C       * 4 OR 8 BYTES.

        IF (MACHINE.EQ.1 .AND. INTSIZE.EQ.1) THEN

C        * TWO 4-BYTES CASE
         KUPPR=2

        ELSE

C        * JUST ONE 4-BYTES CASE
         KUPPR=1

        ENDIF

C-----------------------------------------------------------------------
C       * SETUP IN "IORDER" ARRAY THE ORDER IN WHICH INDIVIDUAL BYTES 
C       *                   WITHIN THE 4-BYTES ARE PROCESSED, 
C       *   AND IN "KSTRT","KFNSH","KINCR" THE DO LOOP PARAMETERS 
C       *                   CONTROLLING THE 4-BYTES ORDER OF PROCESSING.

        IF (LENDIAN()) THEN
C        * LITTLE-ENDIAN CASE
         IORDR(1)=4
         IORDR(2)=3
         IORDR(3)=2
         IORDR(4)=1
         KSTRT=KUPPR
         KFNSH=1
         KINCR=-1
        ELSE
C        * BIG-ENDIAN CASE
         IORDR(1)=1
         IORDR(2)=2
         IORDR(3)=3
         IORDR(4)=4
         KSTRT=1
         KFNSH=KUPPR
         KINCR=1
        ENDIF

C       * INITIALIZE "IFLAG/FRSTCLL" SO THAT THE ABOVE
C       * INITIALIZATION BLOCK IS SKIPPED ON SUBSEQUENT
C       * CALLS TO "NC4TO8".

        IFLAG=-99
        FRSTCLL=.FALSE.
      ENDIF 
     
      C4(2)=CBLANK
      C4(1)=CHO4
      I8S=8
      I8=0
      DO K=KSTRT,KFNSH,KINCR
       DO I = 1,4
        I1C=ICHAR(C4(K)(IORDR(I):IORDR(I)))
        I8=ISHFT(I8,I8S)
        I8=IOR(I8,I1C)
       ENDDO
      ENDDO

      NC4TO8=I8

      RETURN
      END
