      SUBROUTINE PUTSPNR(NF,G,LA,
     1                  LSRTOTAL,LATOTAL,LMTOTAL,GLL,
     2                  JBUF,MAXJ,IPIOSW,OK)

C     * MAY 01/18 - S.KHARIN.  WRITE RE-ORDERED FIELDS.
C     * OCT 11/06 - F.MAJAESS (REPLACE DIRECT BINARY "DATA" RECORD
C     *                        WRITES BY "PUTFLD2" CALLS).
C     * NOV 04/03 - M.LAZARE. NEW VERSION TO SUPPORT MPI, WHICH USES
C     *                       NEW SWITCH "IPIOSW" AND WORK ARRAY "GLL".
C
C     * SAVES GLOBAL SPECTRAL FORECAST ON RESTART FILE.
C     * ALL FIELDS ARE WRITTEN UNPACKED.
C
      IMPLICIT REAL (A-H,O-Z),
     +INTEGER (I-N)

      COMPLEX G(LA)
      COMPLEX GLL(LATOTAL),FLL(LATOTAL)

      INTEGER LSRTOTAL(2,LMTOTAL+1)
      INTEGER JBUF(8)

      INTEGER*4 MYNODE
      COMMON /MPINFO/ MYNODE

      INTEGER*4 NNODE, AGCM_COMMWRLD, MY_CMPLX_TYPE, MY_REAL_TYPE
      INTEGER*4 MY_INT_TYPE
      COMMON /MPICOMM/ NNODE, AGCM_COMMWRLD, MY_CMPLX_TYPE,MY_REAL_TYPE,
     1                 MY_INT_TYPE

      INTEGER*4 SZ, MASTER, IERR

      LOGICAL OK

C     * ICOM IS A SHARED I/O AREA. IT MUST BE LARGE ENOUGH
C     * FOR AN 8 WORD LABEL FOLLOWED BY A PACKED GAUSSIAN GRID.
C
      COMMON /ICOM/ IBUF(8),IDAT(1)
C--------------------------------------------------------------------


      IF (NNODE.GT.1 .AND. IPIOSW.EQ.0) THEN
C
C       * MPI CALL TO GATHER DATA IN LOAD-BALANCED (NON-TRIANGULAR) ORDER.
C
        MASTER =  0
        SZ     =  LA
        CALL WRAP_GATHER(G,      SZ,            MY_CMPLX_TYPE,
     1                   GLL,    SZ,            MY_CMPLX_TYPE,
     2                   MASTER, AGCM_COMMWRLD, IERR)

        IF(MYNODE.EQ.0) THEN

          IBUF(1:8)=JBUF(1:8)
          IBUF(5)  =LATOTAL
          MAXX=2*LATOTAL
          CALL REC2TRI(FLL,GLL,LATOTAL,LSRTOTAL,LMTOTAL)
          CALL PUTFLD2(NF,FLL,IBUF,MAXX)

        ENDIF

      ELSE

         IBUF(1:8)=JBUF(1:8)
         IBUF(5)=LA
         MAXX=2*LA
         CALL PUTFLD2(NF,G,IBUF,MAXX)

      ENDIF
C
      RETURN
      END
