      program sortwjm
C...............................................May 2022
C Sort WUmax(Kp), WLmin(Kp), WEmax(Kp), SumKp 
C Exclude repeated output for cur and prec days
C
C Selected WUmax 
C Selected WLmin 
C Selected WEmax
C Separate catalogues to x=1 (nonevent) x=2 (event) at WL <-4.0
C
      CHARACTER*64 infile,outfile
C
      infile='wulessn0kp3jm.res'
	outfile='wulessn0kp3jm.dat'
C
       OPEN(10,file=infile,action='READ')
       OPEN(11,file=outfile)
C
	xkp_pre=4.9
	wu_pre=2.01
	wl_pre=-2.67
	we_pre=4.68
	ndy=0
CC
        iflag=0
CC
	DO 41 iev=1,664
    1	read(10,32,end=50) ryear,lda,imn,idy,iut,xkpmax,jtwu,wumax,jtwl
     +,wlmin,jtwe,wemax,isumkp,nn
	 if (iev.eq.1) GOTO 43
C
      IF ((wumax.eq.wu_pre).and.(wlmin.eq.wl_pre).and.(wemax.eq.we_pre))
	+ THEN
	 if (xkpmax.gt.xkp_pre) then
	iflag=-1
	        else
	GOTO 42
	                        endif

	 ENDIF
C
C Output
 43   CONTINUE
C-	if ((wumax.ge.4.5).and.(wlmin.le.-4.0)) GOTO 44
C-	if ((wumax.ge.4.5).or.(wlmin.le.-4.0)) GOTO 42 ! Exclude such points
	if (iflag.eq.0) then
C-	 ndy1=ndy1+1
      ndy=ndy+1
	else
			backspace(11)
	endif
      write(*,32) ryear,lda,imn,idy,iut,xkpmax,jtwu,wumax,jtwl,wlmin
	+,jtwe,wemax,isumkp,ndy
	write(11,32) ryear,lda,imn,idy,iut,xkpmax,jtwu,wumax,jtwl,wlmin
	+,jtwe,wemax,isumkp,ndy
	 goto 42
	                  
C-  44	if ((wumax.lt.4.5).or.(wlmin.gt.-4.0)) GOTO 42 ! Exclude such points
c-      if (iflag.eq.0) then
c-	ndy2=ndy2+1
c-	else
c-		backspace(12)
c-      endif
c-      write(*,32) ryear,lda,imn,idy,iut,xkpmax,jtwu,wumax,jtwl,wlmin
c-	+,jtwe,wemax,ndy2
c-	write(12,32) ryear,lda,imn,idy,iut,xkpmax,jtwu,wumax,jtwl,wlmin
c-	+,jtwe,wemax,ndy2
C
   42	xkp_pre=xkpmax
	wu_pre=wumax
	wl_pre=wlmin
	we_pre=wemax
	iflag=0
   41 continue
C
   32 format(1X,F8.3,1X,I3,3(1X,I2),1X,F4.1,3(1X,I3,1X,F6.2),1X,I3
     +,1X,I4)
C
   50	close(unit=10)
	close(unit=11)
	close(unit=12)
	pause ' '
	STOP
	END