      program calcmean
      implicit none

c -----
c for dTdt, NDAT should be -1
c number of data
      integer NDAT
      parameter (NDAT=120)

c missing value
      real    MISS
      parameter (MISS=-999.)

c IO
      integer IFILE
      parameter (IFILE=21)

c -----
c time
      character*8  HHMMSS(NDAT)

c number of data, temperature
      integer nobs(NDAT)
      real    dTdt(NDAT), dTdtsd(NDAT)

c data
      real    dt

c loop control
      integer i, j

c -----
c calculate mean temperature
c -initialization
      do 210 i = 1, NDAT
        nobs(i) = 0
        dTdt(i) = 0.0
 210  continue
c -read data
      open(IFILE,file='dTdtall.dat')
 220  continue
      do 230 i = 1, NDAT
        read(IFILE,*,end=240) HHMMSS(i), dt
        if (dt.ne.MISS) then
            nobs(i) = nobs(i) + 1
            dTdt(i) = dTdt(i) + dt
        end if
 230  continue
      go to 220
 240  continue
      close(IFILE)
c -calculate mean
      do 250 i = 1, NDAT
        dTdt(i) = dTdt(i) / nobs(i)
c        write(*,*) i, dTdt(i)
 250  continue

c calculate standard deviation of temperature
c -initialization
      do 260 i = 1, NDAT
        nobs(i) = 0
        dTdtsd(i)  = 0.0
 260  continue
c -read data
      open(IFILE,file='dTdtall.dat')
 270  continue
      do 280 i = 1, NDAT
        read(IFILE,*,end=290) HHMMSS(i), dt
        if (dt.ne.MISS) then
            nobs(i) = nobs(i) + 1
            dTdtsd(i)  = dTdtsd(i)  + (dt - dTdt(i))**2
        end if
 280  continue
      go to 270
 290  continue
      close(IFILE)
c -calculate standard deviation
      do 300 i = 1, NDAT
        dTdtsd(i) = ( dTdtsd(i) / nobs(i) )**(0.5)
 300  continue


c output
      do 410 i = 1, NDAT
        write(*,*) HHMMSS(i), nobs(i), dTdt(i), dTdtsd(i)
 410  continue


      stop
      end
