      program calrsquared3
C...............................................  Nov 2023
C   R**2 between 90 Apo(tau) storm indices
	DIMENSION xx(744),yy(744)
	CHARACTER*28 infilex,infiley,outfile
C      CHARACTER*6 YYMMDDx,YYMMDDy
	CHARACTER*4 NAMEX,NAMEY
C	CHARACTER*2 aa
C++		CHARACTER*1 xfor
      outfile='rmser2tau6.out'
C	
C
c++      infiley='gh2302.hrs'  !
      infiley='catsn27cvlymg90.txt'  ! ,Apo(6), SSN(7).COV(8),Lym(9), MgII(10)
C	NAMEX=' COV'  !(1) TEMP
C	NAMEX='Lyma'  !(2) TEMP
C	NAMEX='MgII'  !(3) TEMP
	NAMEX='Apo6'  !(3) TEMP
	NAMEY='SSN2'
   1	OPEN(10,file=outfile,access='APPEND') 
C	YYMM=infiley(3:6)
	kk1=1
C
        nhrs=90         !90 events
      kk2=nhrs
C	
C
C
CREM	infilex='ga2303.hrs' ! IRI-Plas1 
       iyear=2023
	iyr=23
C        
C
	DO ii=1,744     ! 
	xx(ii)=0.
	yy(ii)=0.
	  ENDDO
C
CREM      	OPEN(11,file=infilex,action='read')
	OPEN(12,file=infiley,action='read')
C
C
       ncnt=nhrs						   !predict
	do 101 kk=1,nhrs
  133	read(12,*,end=51) rYEAR,lda,kMN,kDD,kUT,apo,ssn,cov,cly,cmg  !
	yy(kk)=ssn        !Y
C	xx(kk)=cov        ! X	 TEMP(1)
C	xx(kk)=cly        ! X	 TEMP(2)
C	xx(kk)=cmg        ! X	 TEMP(3)
	xx(kk)=apo        ! X	 TEMP(4)
  101	continue
   51 close(11)

  139 format(2X,F4.0,1X,F5.2,1X,F6.2)
CC	do 102 kk=1,nhrs
CC  134	read(12,131,end=52) 	 !predict
CC  102	continue
CC   52 close(12)
C
      yav=0.
	kk2=ncnt		!predict
	dhrs=float(ncnt)  !predict
C	
	DO m=1,nhrs		! month
	yav=yav+yy(m)
	ENDDO
	yav=yav/dhrs
C
      sum1=0.
	sum2=0.
C	
       	DO m=1,nhrs
	sum1=sum1+(xx(m)-yy(m))**2
	sum2=sum2+(yav-yy(m))**2
	ENDDO
C
	r2=1.0-(sum1/sum2)
	rmse=sqrt(sum1/dhrs)
	write(*,32) NAMEX,NAMEY,r2
	write(10,32) NAMEX,NAMEY,r2
	close(10)
C	     GOTO 1
	pause ' '
  131 FORMAT(3I2,1X,I2,1X,F5.2)
C  131 FORMAT(1X,I4,3(1X,I2),1X,F5.2)	  !predict
   31 FORMAT(A6,1X,A2,1X,F5.2)
   32 FORMAT(2(1X,A4),1X,F10.3)
   	STOP
	END