      program calwuwlstdp
C
C............................................................Oct 2021
C Statistics reliability for 9 training set and 4 testing set.
C
      real wu(13,20),wl(13,20),wuav(20),wlav(20),stdwu(13),stdwl(13)
	+,fik(20)
	CHARACTER*64 infilenn,outfile
	CHARACTER*2 ANN
C
	infilenn='wulephasNNav.txt'
	outfile='wuwlstdp.res'
C
	do k=1,20
	wuav(k)=0.0
	wlav(k)=0.0
	enddo
C
	OPEN(10,file=outfile,access='APPEND')
C
        n1=0
	n2=9
      DO 50 nn=23,39      ! Testing set 23-25 + training set: 31-39
	if ((nn.gt.26).and.(nn.lt.31)) goto 50
C                                      Good corr. 
	if ((nn.eq.23).or.((nn.gt.30).and.nn.ne.33)) then			!<<<<<<<<<<<
	n1=n1+1			! Good corr n1=1,...9
	n3=n1
	                                else
      n2=n2+1
	n3=n2
	                       endif
	call blet2(nn,ANN)
	infilenn(9:10)=ANN
C
	OPEN(12,file=infilenn,action='READ')
        do kk=1,20
	read(12,*) fik(kk),wu(n3,kk),wl(n3,kk),we
	  enddo
	close(unit=12)
   50	CONTINUE
C
   32 format(' 9',1X,F5.2,2(1X,F7.2))    
   33 format(' 4',1X,F5.2,2(1X,F7.2))    
C std
       n1=1			   ! Good corr
	n2=9			   ! Good corr
      wuav9=0.
	wlav9=0.
       do k=1,20
	do nn=n1,n2
	wuav(k)=wuav(k)+wu(nn,k)
	wlav(k)=wlav(k)+wl(nn,k)
      enddo
	wuav(k)=wuav(k)/9.0
	wlav(k)=wlav(k)/9.0
	wuav9=wuav9+wuav(k)
	wlav9=wlav9+wlav(k)
C+	write(*,32) fik(k),wuav(k),wlav(k)
C+	write(10,32) fik(k),wuav(k),wlav(k)
	 enddo
	wuav9=wuav9/20.0
	wlav9=wlav9/20.0
       n1=10			   ! Bad corr
       n2=13			   ! Bad corr
      wuav4=0.
	wlav4=0.
       do k=1,20
	do nn=n1,n2
	wuav(k)=wuav(k)+wu(nn,k)
	wlav(k)=wlav(k)+wl(nn,k)
      enddo
	wuav(k)=wuav(k)/4.0
	wlav(k)=wlav(k)/4.0
	wuav4=wuav4+wuav(k)
	wlav4=wlav4+wlav(k)
	write(*,33) fik(k),wuav(k),wlav(k)
	write(10,33) fik(k),wuav(k),wlav(k)
	 enddo
	wuav4=wuav4/20.0
	wlav4=wlav4/20.0
C
       stdavwu=0.0
       stdavwl=0.0
       n1=1			   ! Good corr
	n2=9			   ! Good corr
      DO 51 nn=n1,n2      ! Good corr
       sumwu=0.0
       sumwl=0.0
       do j=1,20
	delu=(wu(nn,j)-wuav(j))**2.
	sumwu=sumwu+delu
	dell=(wl(nn,j)-wlav(j))**2.
	sumwl=sumwl+dell
	 enddo
	stdwu(nn)=sqrt(sumwu/20.)
	stdwl(nn)=sqrt(sumwl/20.)
	stdavwu=stdavwu+stdwu(nn)
	stdavwl=stdavwl+stdwl(nn)
   51	CONTINUE
      stdavwu9=stdavwu/9.0
	stdavwl9=stdavwl/9.0
C
       stdavwu=0.0
       stdavwl=0.0
       n1=10			   ! Bad corr
	n2=13			   ! Bad corr
      DO 52 nn=n1,n2      ! Bad corr
       sumwu=0.0
       sumwl=0.0
       do j=1,20
	delu=(wu(nn,j)-wuav(j))**2.
	sumwu=sumwu+delu
	dell=(wl(nn,j)-wlav(j))**2.
	sumwl=sumwl+dell
	 enddo
	stdwu(nn)=sqrt(sumwu/20.)
	stdwl(nn)=sqrt(sumwl/20.)
	stdavwu=stdavwu+stdwu(nn)
	stdavwl=stdavwl+stdwl(nn)
   52	CONTINUE
      stdavwu4=stdavwu/4.0
	stdavwl4=stdavwl/4.0

	write(*,30) wuav9,stdavwu9,wlav9,stdavwl9
      write(10,30) wuav9,stdavwu9,wlav9,stdavwl9
	write(*,30) wuav4,stdavwu4,wlav4,stdavwl4
      write(10,30) wuav4,stdavwu4,wlav4,stdavwl4
	close(unit=10)
   30 FORMAT(2(1X,F7.2,1X,F7.3))
	pause ' '
	STOP
	END
