      program instrument
      implicit none

c -----
c maximum number of thermometer
      integer NPMAX
      parameter (NPMAX=32)

c number of data
      integer NDAT
      parameter (NDAT=121)

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

c IO
      integer IFILE
      parameter (IFILE=21)

c number of data for extimating instrumental error
      integer NE
      parameter (NE=16)

c -----
c data
      character*8  HHMMSS
      real    t, wd, ws
      real    tmean(NPMAX)
      integer nmean(NPMAX)
      real    tall
      integer np
      real    dT

c loop control
      integer i, j

c -----
c set initial
      j = 0
      tall = 0.0
      np = 0

      open(IFILE,file='datafile')
 220  continue
      read(IFILE,*,end=240)
      read(IFILE,*)
      read(IFILE,*)
      read(IFILE,*)
      read(IFILE,*)
      read(IFILE,*)
c set initial
      j = j + 1
      tmean(j) = 0.0
      nmean(j) = 0
c read data
      do 230 i = 1, NDAT
        read(IFILE,*) HHMMSS, t, wd, ws
        if (t.ne.MISS) then
c            if (i.le.NE) then
                tmean(j) = tmean(j) + t
                nmean(j) = nmean(j) + 1
c            end if
        end if
 230  continue
c calculate mean
      if (nmean(j).gt.0) then
          tmean(j) = tmean(j) / nmean(j)
          tall = tall + tmean(j)
          np = np + 1
        else
          tmean(j) = MISS
      end if
c output
c      write(*,*) tmean(j)
      go to 220
 240  continue
      close(IFILE)

c output
      tall = tall / np
c      write(*,*) np, tall
      do 310 i = 1, j
        if (t.ne.MISS) then
            dT = tmean(i) - tall
            write(*,*) i, dT, tmean(i)
        end if
 310  continue


      stop
      end
