	Program Read_wuwlwem1
C...................................................Nov 2021
C Read WUn,WLn, WEn (North) & WUs, WLs, WEs (south) & WU, WL, WE global from magn maps
C...................................................May 2021
C Read WU, WL,WE 15min for storms 01...24 only for SC23 SC24 (nn=9,...,24)
C
       DIMENSION wup(3,0:95),wln(3,0:95),wer(3,0:95)
C-	+,resu(0:191),resl(0:191),rese(0:191)
	 CHARACTER*64 infile,infiwu,infiwl,infiwe,outfile,txt
	CHARACTER*2 AYR,ANN,CYR,CMN1
     +,CDY1,CMN2,CDY2,CMN3,CDY3
	CHARACTER*4 AYEAR
	CHARACTER*1 gns  ! global, north, south
C
	infile='d:\Arts\Storm\Shub\Data\testreadnn.txt'
	outfile='testwuwlwnx.txt'
	infiwu='d:\web\grif\datw\wupYRx.txt'
	infiwl='d:\web\grif\datw\wlnYRx.txt'
	infiwe='d:\web\grif\datw\werYRx.txt'
C
   1      write(*,*) 'Enter m, n, s for input:'
	read(*,*) gns
	infiwu(23:23)=gns
	infiwl(23:23)=gns
	infiwe(23:23)=gns
	outfile(11:11)=gns
C
C-	DO 50 nn=12,24            ! 15min for 2000-2017
C	DO 50 nn=9,10   		  !Testing set
C+        nn=13            !2000.07.15-17
        nn=23            !2015.03.17-19
	call blet2(nn,ANN)
	infile(33:34)=ANN
C
	OPEN(10,file=infile,action='READ')
	read(10,101) ayear,kmn,kdy,kut,kmm,isym,rfi
	close(unit=10)
C
	AYR=AYEAR(3:4)
	read(AYR,*) ryr
	kyr=int(ryr)
      lda=ndoy(kyr,kmn,kdy)
C
	infiwu(21:22)=AYR
	infiwl(21:22)=AYR
	infiwe(21:22)=AYR
      OPEN(11,file=infiwu,action='READ')
	OPEN(12,file=infiwl,action='READ')
	OPEN(13,file=infiwe,action='READ')
	read(11,*) txt
	read(12,*) txt
	read(13,*) txt
C
	outfile(9:10)=ANN
      OPEN(14,file=outfile)
C
  21  format(3A2,24(1X,F4.2))		   !TG
	DO kk=1,lda
	read(11,21,end=61) cyr,cmn1,cdy1,(wup(1,k),k=0,23)
	read(12,21,end=62) cyr,cmn1,cdy1,(wln(1,k),k=0,23)
	read(13,21,end=63) cyr,cmn1,cdy1,(wer(1,k),k=0,23)
	ENDDO
	read(11,21,end=61) cyr,cmn2,cdy2,(wup(2,k),k=0,23)
	read(12,21,end=62) cyr,cmn2,cdy2,(wln(2,k),k=0,23)
	read(13,21,end=63) cyr,cmn2,cdy2,(wer(2,k),k=0,23)
	read(11,21,end=61) cyr,cmn3,cdy3,(wup(3,k),k=0,23)
	read(12,21,end=62) cyr,cmn3,cdy3,(wln(3,k),k=0,23)
	read(13,21,end=63) cyr,cmn3,cdy3,(wer(3,k),k=0,23)
   61	close(unit=11)
   62	close(unit=12)
   63	close(unit=13)
C
C Select output values:
C-      utout=kut+kmm/60.
      utout=float(kut)
C-	jn=kut*4-1
	jn=kut-1
C
C      jj=0,192
       jj=0
	iflag=0
C?	j2=0
   39	iflag=iflag+1
      if (iflag.gt.1) then
	 jn=-1
	utout=0.0
	endif
   40	jn=jn+1
	if (iflag.eq.1) then			!1
      resu=wup(1,jn)
	resl=wln(1,jn)
	rese=wer(1,jn)
	write(*,102) ayear,cmn1,cdy1,utout,resu,resl,rese
	write(14,102) ayear,cmn1,cdy1,utout,resu,resl,rese
       jj=jj+1
C	utout=utout+0.25
	utout=utout+1.0
	   if (utout.lt.24.0) then		 !2
	   goto 40
	                 else		 !2
         goto 39
	                 endif		 !2			      
	else						 !1
	if (iflag.eq.2) then         !3
      resu=wup(2,jn)
	resl=wln(2,jn)
	rese=wer(2,jn)
	write(*,102) ayear,cmn2,cdy2,utout,resu,resl,rese
	write(14,102) ayear,cmn2,cdy2,utout,resu,resl,rese
       jj=jj+1
C	utout=utout+0.25
	utout=utout+1.0
	   if (utout.lt.24.0) then		 !4
	   goto 40
	                 else		 !4
         goto 39
	                 endif		 !4			      
	                                   else   !3
C	if (iflag.eq.3) then
C	      if (jj.lt.192) then          !5
	      if (jj.lt.48) then          !5
	      resu=wup(3,jn)
      	  resl=wln(3,jn)
            rese=wer(3,jn)
	write(*,102) ayear,cmn3,cdy3,utout,resu,resl,rese
	write(14,102) ayear,cmn3,cdy3,utout,resu,resl,rese
       jj=jj+1
C	utout=utout+0.25
	utout=utout+1.0
	 goto 40
	                    endif		 !5
	                                      endif !3
             endif                 !1
c	
      close(unit=14)
   50 CONTINUE                ! END tests files
        if (gns.eq.'s') then
      pause ' '
	       else
	goto 1
	  endif
	stop
  20  format(i4,4(1x,i2.2),2x,f5.1,1x,i3,3x,4(3x,f7.2))
 100  format(1x,'Day Month Year      UT     SYM_H')
 101  format(1X,A4,4(1X,I2),1X,I4,1X,F6.3)
 102  format(1X,A4,2(1X,A2),1X,F5.2,3(1X,F6.3))
	end			