      SUBROUTINE GWRITE(N,FHOUR,IDATE,Z,Q,TE,DI,ZE,RQ,SL,SI,GZ,Z00)
CJPB
      CHARACTER*4 LAB,CHARS
CJPB  INTEGER*4 DIGITS(3)
      CHARACTER*1 DIGITS(3)
CJPB  COMPLEX*8
      COMPLEX
     1  Z( 289   ),GZ( 289 ),
     2 Q( 289   ),
     3 TE( 289   , 7 ),DI( 289   , 7 ),ZE( 289   , 7 ),
     4 RQ( 289   , 6 )
      DIMENSION IDATE(4),SI( 8 ),SL( 7 )
CJPB  COMMON /LAB8/LAB(8),/LAB9/KDATE(4),IFINAL
CJPB
      CHARACTER*8 LAB12
CJPB  INTEGER*4 LAB1(2)/'SIGI','SIGG'/
      CHARACTER*4 LAB1(2)
CJPB  INTEGER*4 LAB2(4)/'NIB2','N6B2','E6B2','ESB2'/
      CHARACTER*4 LAB2(4)
      COMMON /LAB8/LAB(8),/LAB9/KDATE(4),IFINAL
      EQUIVALENCE (LAB12,LAB(1))
      DATA        LAB1   /'SIGI','SIGG'/
      DATA        LAB2   /'NIB2','N6B2','E6B2','ESB2'/
CJPB
      IF(IFINAL)600,600,500
500   IHOUR=FHOUR+0.5
      IF(IHOUR.GT.100)IHOUR=IHOUR-100
      IF(IHOUR.GT.100)IHOUR=IHOUR-100
      LAB(1)=LAB1(1)
      IF(IHOUR.EQ.6)LAB(1)=LAB1(2)
      IF(IHOUR.EQ.0.AND.(IDATE(1).EQ.0.OR.IDATE(1).EQ.12))
     1 LAB(2)=LAB2(1)
      IF(IHOUR.EQ.0.AND.(IDATE(1).EQ.6.OR.IDATE(1).EQ.18))
     1 LAB(2)=LAB2(2)
      IF(IHOUR.EQ.6.AND.(IDATE(1).EQ.0.OR.IDATE(1).EQ.12))
     1 LAB(2)=LAB2(3)
      IF(IHOUR.EQ.6.AND.(IDATE(1).EQ.6.OR.IDATE(1).EQ.18))
     1 LAB(2)=LAB2(4)
      GO TO 900
600   IHOUR=FHOUR+0.5
CJPB  CALL ENCODE (CHARS, 4)
CJPB  WRITE (99,103) IHOUR
      WRITE (CHARS,103) IHOUR
103   FORMAT (I4)
CJPB  CALL DECODE (CHARS, 4)
CJPB  READ (99,105) DIGITS
      READ (CHARS,105) DIGITS
CJPB105   FORMAT (1X, 3I1)
105   FORMAT (1X, 3A1)
CJPB  CALL ENCODE (LAB(1), 8)
CJPB  WRITE (99,107) DIGITS
      WRITE (LAB12,107) DIGITS
CJPB107   FORMAT ('SMS', 3I1, 'B2')
107   FORMAT ('SMS', 3A1, 'B2')
900   CONTINUE
      WRITE(N)LAB
      WRITE(6,3000)KDATE,LAB
CJPB3000  FORMAT(1H0,'GWRITE KDATE ',4I4,2X,2A4,2X,3Z8,2X,3A4)
3000  FORMAT(1H0,'GWRITE KDATE ',4I4,2X,2A4,2X,3A4,2X,3A4)
      WRITE(N)FHOUR,IDATE,SI,SL
C***  COMPUTE TOPOG. FROM ITS LAPLACIAN
      ASQ= 6370000. * 6370000. / 9.8
      K=0
      DO 50 I=2, 17
      K=K+1
      FACT=ASQ/(K*(K+1.))
      Z(I)=CMPLX(FACT*REAL(GZ(I)),FACT*AIMAG(GZ(I)))
50    CONTINUE
      DO 51 LL=2, 17
      K=LL-2
      DO 51 I=1, 17
      K=K+1
      FACT=ASQ/(K*(K+1.))
       Z((LL-1)* 17 +I)=CMPLX(
     1 FACT* REAL(GZ((LL-1)* 17 +I)),
     1 FACT*AIMAG(GZ((LL-1)* 17 +I)))
51    CONTINUE
      Z(1)=CMPLX(Z00,0.)
C***
      WRITE(N)Z
      WRITE (N) Q
      DO 15 K=1, 7
      WRITE(N) (TE(I,K),I=1, 289   )
15    CONTINUE
      DO 20 K=1, 7
      WRITE(N)(DI(I,K),I=1, 289   )
      WRITE(N)(ZE(I,K),I=1, 289   )
20    CONTINUE
       XRH = 0.9
      K=1
      DO 23 I=1,  289
      Z(I)=CMPLX(REAL(RQ(I,K))/XRH,AIMAG(RQ(I,K))/XRH)
23    CONTINUE
      WRITE(N)(Z(I),I=1, 289 )
      DO 25 K=2, 6
      WRITE (N) (RQ(I,K),I=1, 289 )
25    CONTINUE
      WRITE(6,3001)FHOUR,IDATE,N
3001   FORMAT(1H0,'GWRITE FHOUR=',F6.2,2X,4I4,2X,'N=',I2)
      RETURN
      END
