      SUBROUTINE RD1SEC(IUNIT,FN,STN,ABB,GGLAT,GGLONG,IYS,MHS,IDS,IHS,
     +IMINS,IH,IMIN,ISEC,H,D,Z,F,MDATA,NDATA,ICON)
* *** This subroutine reads text file for geomagnetic 1 second values
* *** obtained from WDC-C2 Kyoto Home page.
*  ** Made on Nov. 17, 1997
*  ** Arguments:
*   * INPUT:
*     IUNIT: Unit number to be used in this subroutine.
*     FN: Input file name, CHARACTER*(*)
*     MDATA: Array size.
*   * OUTPUT:
*     STN,ABB: Name and ABBCODE of the observatory, CHARACTER*(*)
*     GGLAT,GGLONG: Geographic latitude and longitude of the observatory.
*     IYS,MHS,IDS,IHS,IMINS: Start year,month(1-12),day, hour and min.
*     IH,IMIN,ISEC: Hour, min. and sec. of each data point,
*         Integer array of size MDATA.
*     H,D,Z,F: 1-Sec. values (UNIT: nT for H,Z,F, minite for D),
*         Double Precision array of size MDATA.
*       !!! Accuracy of the single precision array is not enough !!!
*       !!!  in most systems.                                    !!!
*       !!! DATA MISSING=> 999999.D0                             !!!
*     NDATA: Number of inputted data.
*     ICON: Condition code of this subroutine.
*           0          : Normal end.
*           1          : MDATA is too small.
*           20000      : File open error.
*           21000-25000: File read error.
*
*
      CHARACTER FN*(*),STN*(*),ABB*(*),BUF*44,CMON(12)*3,MON*3,CDG*4
      DOUBLE PRECISION H(MDATA),D(MDATA),Z(MDATA),F(MDATA)
      DOUBLE PRECISION DMISS,VIGN,DMW
      INTEGER IH(MDATA),IMIN(MDATA),ISEC(MDATA)
      DATA CMON/'JAN','FEB','MAR','APR','MAY','JUN',
     +          'JUL','AUG','SEP','OCT','NOV','DEC'/
      DATA DMISS,IVIGN,VIGN/999999.D0,998,99999.98D0/
*   * Preparation *
      NDATA=0
      DO 10 I=1,MDATA
      H(I)=DMISS
      D(I)=DMISS
      Z(I)=DMISS
      F(I)=DMISS
   10 CONTINUE
*   * File open *
      OPEN(IUNIT,FILE=FN,STATUS='OLD',IOSTAT=IOS)
      IF(IOS.NE.0) THEN
       ICON=20000
       RETURN
      END IF
*   * Information of the observatory *
      ICON=21000
      READ(IUNIT,'(A)',IOSTAT=IOS) BUF
      IF(IOS.NE.0) GO TO 99
      IP=INDEX(BUF,'(')
      IF(IP.LE.0) GO TO 99
      STN=BUF(1:IP-1)
      ABB=BUF(IP+1:IP+3)
      READ(IUNIT,'(A)',IOSTAT=IOS) BUF
      IF(IOS.NE.0) GO TO 99
      IP=INDEX(BUF,'GGLAT.:')
      IF(IP.LE.0) GO TO 99
      READ(BUF(IP+7:IP+14),'(F8.0)',IOSTAT=IOS) GGLAT
      IF(IOS.NE.0) GO TO 99
      IP=INDEX(BUF,'GGLONG.:')
      IF(IP.LE.0) GO TO 99
      READ(BUF(IP+8:IP+15),'(F8.0)',IOSTAT=IOS) GGLONG
      IF(IOS.NE.0) GO TO 99
*   * Start time *
      ICON=22000
      READ(IUNIT,'(A)',IOSTAT=IOS) BUF
      IF(IOS.NE.0) GO TO 99
      IP=INDEX(BUF,'START TIME:')
      IF(IP.LE.0) GO TO 99
      READ(BUF(12:),'(I2,1X,I2,7X,I2,1X,I4)',IOSTAT=IOS)
     +IHS,IMINS,IDS,IYS
      IF(IOS.NE.0) GO TO 99
      MON=BUF(20:22)
      DO 20 MHS=1,12
      IF(MON.EQ.CMON(MHS)) GO TO 1
   20 CONTINUE
      GO TO 99
    1 CONTINUE
      ICON=23000
    2 CONTINUE
*   * Skip records *
      READ(IUNIT,'(A)',IOSTAT=IOS) BUF
      IF(IOS.NE.0) GO TO 99
      IF(INDEX(BUF,'HHMMSS').EQ.0) GO TO 2
*   * Data records *
    3 CONTINUE
      ICON=24000
      READ(IUNIT,'(A)',IOSTAT=IOS) BUF
      IF(IOS.NE.0) THEN
       IF(IOS.LT.0) ICON=0
       GO TO 99
      END IF
      IF(NDATA.GE.MDATA) THEN
       ICON=1
       GO TO 99
      END IF
      ICON=25000
      I=NDATA+1
      CDG=BUF(16:19)
      READ(BUF,301,IOSTAT=IOS) IH(I),IMIN(I),ISEC(I),
     +H(I),IDW,DMW,Z(I),F(I)
  301 FORMAT(3I2,D9.0,I4,1X,D6.0,2D9.0)
      IF(IOS.NE.0) GO TO 99
      NDATA=I
      IDSIGN=1
      IF(INDEX(CDG,'-').NE.0) IDSIGN=-1
      IF(IDW.GT.IVIGN) THEN
       D(I)=DMISS
      ELSE
       D(I)=DBLE(IDW)*60.D0+DBLE(IDSIGN)*DMW
      END IF
      IF(H(I).GT.VIGN) H(I)=DMISS
      IF(Z(I).GT.VIGN) Z(I)=DMISS
      IF(F(I).GT.VIGN) F(I)=DMISS
      GO TO 3
   99 CONTINUE
*   * File close and return *
      CLOSE(IUNIT,IOSTAT=IOS)
      RETURN
      END
