	program histhssal1d
c .......................................................Dec 2020
C Histogram of occurrence AE(HSS)	1101*72 array @ HSS/kp storms
C for 1996-2018
C
c
	DIMENSION ikp(0:99),icn(0:99),ind(0:71)
c	+,idv(0:3),ivs(0:3),iap(0:3),iaa(0:3)
c	+,iae(0:3),ids(0:3),twp(0:3)
c	+,nkp(0:3),ndv(0:3),nvs(0:3),nap(0:3),naa(0:3)
c 	+,nae(0:3),nds(0:3),nwp(0:3)
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
	CHARACTER*64,infile,outfile
Ckp	DATA ikp/0,3,7,10,13,17,20,23,27,30,33,37,40,43,47,50,53,57,60,63  !kp
Ckp	+,67,70,73,77,80,83,87,90/										   !kp
Cap	DATA ikp/0,2,3,4,5,6,7,9,12,15,18,22,27,32,39,48,56,67,80,94	   !ap
Cap	+, 111, 132, 154, 179, 207, 236, 300, 400/						   !ap
Caa	DATA ikp/0,5,12,16,24,32
Caa	+,46,58,67,80,81   !aa
Caa     +,100,120,166,198,268,354,400,600/						   !aa
C
	CALL DATE_AND_TIME(DATE=DD,TIME=TT,ZONE=ZZ)
      TT(5:)='      '
      WRITE(*,*) 'PC Date: Year,Month,Day = ',DD,'Time = ',TT
C
		  outfile='histhss1d.res'
	OPEN(11,FILE=OUTFILE,ACCESS='APPEND')
C
   36	format(72(1X,I5))

C
C-	infile='hsskp1m.txt'				! kp
C-	infile='hssap1m.txt'				! ap
C-	infile='hssaa1m.txt'				! aa
C-	infile='hsssw1m.txt'				! sw
	infile='hssal1d.txt'				! AL
		OPEN(10,FILE=infile,ACTION='READ')
	write(*,*) infile
	write(11,*) infile

C	read(10,*) txt ! title line
C
 	icntot=0 ! count of dPch
C++	do kk=0,19
	isw=30
	ikp(0)=30
	icn(0)=0
	do kk=1,99
	icn(kk)=0
	if (isw.gt.-250) then
	isw=isw-10
	else
	if (isw.gt.-800) then
	isw=isw-20
	else
	isw=isw-50
      endif      
	endif
	ikp(kk)=isw
	enddo
C
       iswmin=1000.
	iswmax=0.
	DO 51 iev=1,444
   1	read(10,36,end=155) (ind(k),k=0,71)
      icntot=icntot+72
C
      DO kk=0,71
	kp=ind(kk)
C++	do ii=1,19
	do ii=1,99
	if (ind(ii).lt.iswmin) iswmin=ind(ii)
      if (ind(ii).gt.iswmax) iswmax=ind(ii)
C++	if (kp.eq.ikp(19)) then
      if (kp.le.ikp(99)) then
C++	 icn(19)=icn(19)+1
	 icn(99)=icn(99)+1
	endif
	if ((kp.le.ikp(ii-1)).and.(kp.gt.ikp(ii))) then 
	 icn(ii-1)=icn(ii-1)+1
	endif
	enddo
	ENDDO
   51	CONTINUE      
C
 155  CLOSE(unit=10)
C++      do ii=0,19
C-       icntot=85320
	cntot=float(icntot)
       write(*,*)icntot,iswmin,iswmax
	sum=0
      do ii=0,99
	per=float(icn(ii))/cntot*100. !%
	sum=sum+per
C kp
	write(*,790) ikp(ii),icn(ii),per
	write(11,790) ikp(ii),icn(ii),per
	enddo
 790  format(1X,I5,1X,I6,1X,F6.2)
C  %
c   
	CLOSE(unit=11)
	goto 900
    2 CONTINUE
           write(*,*) 'INPUT FILE IS NOT IN YOUR DIRECTORY '
  900 pause ' '
      STOP
      END

