      program calwuwlstd
C
C............................................................Oct 2021
C Statistics reliability for 9 training set and 4 testing set.
C
      real wu(9,20),wl(9,20),wuav(20),wlav(20),stdwu(9),stdwl(9)
	CHARACTER*64 infileav,infilenn,outfile,txt1,txt2
	CHARACTER*2 ANN
C
C      infileav='medtrai.txt'  ! training set
      infileav='medtest.txt'  ! testing set
	infilenn='wulephasNNav.txt'
	outfile=infileav
	outfile(9:11)='res'
C
	OPEN(11,file=infileav,action='READ')
	read(11,*) txt1
       wumav=0.
	do k=1,20
	read(11,*) wuav(k)
	wumav=wumav+wuav(k)
	enddo
	wumav=wumav/20.
C
	read(11,*) txt2
       wlmav=0.
	do k=1,20
	read(11,*) wlav(k)
	wlmav=wlmav+wlav(k)
	enddo
	wlmav=wlmav/20.
      close(unit=11)
C
	OPEN(10,file=outfile,access='APPEND')
C
      DO 50 nn=23,26      ! Testing set
C      DO 50 nn=31,39      ! Training set
C	n1=nn-30			 ! Training set
	n1=nn-22			! Testing set
	call blet2(nn,ANN)
	infilenn(9:10)=ANN
C
	OPEN(12,file=infilenn,action='READ')
        do kk=1,20
	read(12,*) fi,wu(n1,kk),wl(n1,kk),we
	  enddo
	close(unit=12)
   50	CONTINUE
C
C std
C       nk=9			   ! Training set
       nk=4			   ! Testing set
       stdavwu=0.0
       stdavwl=0.0
      DO 51 nn=1,nk      ! Training set
       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
      stdavwu=stdavwu/nk
	stdavwl=stdavwl/nk
	write(*,30) nk,wumav,stdavwu,wlmav,stdavwl
      write(10,30) nk, wumav,stdavwu,wlmav,stdavwl
	close(unit=10)
   30 FORMAT(1X,I2,2(1X,F5.2,1X,F7.3))
	pause ' '
	STOP
	END
