!23456
      program climatology

      integer irec

!!!!!!!! DECLARE ALL ARRAYS(VECTORS) THAT WE PLAN TO USE

      real tmp(1140), pci(1140), tmp_ano(552), pci_ano(552),
     &       c_tmp_1(12),   c_tmp_2(12),   c_pci_1(12),   c_pci_2(12),
     &     sum_tmp_1(12), sum_tmp_2(12), sum_pci_1(12), sum_pci_2(12),
     &       sum_tmp(12),   sum_pci(12),     c_tmp(12),     c_pci(12)


!!!!!!!! DATA THAT WE'LL READ INTO PROGRAM
      open (20, file='amazon.txt', form='formatted', status='old')

!!!!!!!! PLACE TO PUT DATA THAT WE CALCULATE
      open (22, file='anom.txt',
     &                 form='formatted', status='unknown')

!!!!!!!! PLACE TO PUT DATA SO THAT WE CAN VIEW IT IN GRADS
      open (23,FILE='anom.dat',FORM='UNFORMATTED',status='unknown',
     &                 ACCESS='DIRECT',RECL=1)

      irec=1
!!!!!!!! READ THE DATA, SO THAT WE CAN USE IT

      do k=1,1140
         read(20,10) tmp(k), pci(k)
      enddo
 10   format(f6.2, 2x, f10.7)


!!!!!!!! **** 1950-1995 climatology (46 years)

      do k = 1, 46
        do i=1, 12
          sum_tmp(i) = sum_tmp(i) + tmp( 588 + (k-1)*12 + i )
          sum_pci(i) = sum_pci(i) + pci( 588 + (k-1)*12 + i )
        enddo
      enddo

      do k=1, 12
        c_tmp(k) = sum_tmp(k) / 46.
        c_pci(k) = sum_pci(k) / 46.
      enddo

!!!!!!!! **** 1950-1995 temperature and precipitation anomalies

       do k=1, 46
        do i=1, 12
          tmp_ano(irec) = tmp( 588 + (k-1)*12 + i) - c_tmp(i)
          pci_ano(irec) = pci( 588 + (k-1)*12 + i) - c_pci(i)
          write(22,22) k+1949, i, tmp_ano, pci_ano
          write(23,REC=IREC) tmp_ano(irec)
	  irec=irec+1
        enddo
       enddo

 22   format(i4,1x,i2,1x,f7.3,1x,f10.7)

      stop
      end