      subroutine subimfsw(ldar,AYEAR,eb1,bs1,db1,bz1,sw1,dsw1,anp1
	+,atp1,dtp1)
C...................................................................May 2016
C read IMF and Sol Wind indices for given day of year:
C B =>db1, (calculate dB/dt => db1)  Bz => bz1, Tp => anp1, Np =>anp1, dVsw/dt =>sw1)
	dimension eb1(0:26),db1(0:26),bz1(0:26),sw1(0:26),dsw1(0:26)
	+,anp1(0:26),atp1(0:26),bs1(0:26),dtp1(0:26)
      CHARACTER*4 AYEAR
	CHARACTER*65 infile,txt
C	CHARACTER*6 YYMMDD
C
	infile='d:/apkp/OMNI/swYEAR.txt' !OMNI file
C
  137 format(I4,1X,I3,1X,I2,2(1X,F5.1),1X,F8.0,1X,F5.1,1X,F5.0) ! 
   31 format(A65)
C
	read(ayear,*) ryear
	 	iyear=int(ryear)
			if(int(ryear/4.)*4.eq.iyear) THEN 
	ndr=366
	                          ELSE
	ndr=365
	ENDIF
C
     	infile(16:19)=AYEAR
	OPEN(10,FILE=infile,action='READ')
	do k=1,13
	read(10,31) txt ! extra lines
	enddo
	do idd=1,ldar
	do ii=0,23
	read(10,137,end=139) jyear,jlda,jut,eb1(ii),bz1(ii)
	+,atp1(ii),anp1(ii),sw1(ii)
	enddo
	enddo
C      
 139	kacnt=0 
      if (ldar.lt.ndr) then
      do ka=1,3
	k1=ka+23
	read(10,137,end=21) jyear,jlda,jut,eb1(k1),bz1(k1)
	+,atp1(k1),anp1(k1),sw1(k1)
	 kacnt=kacnt+1
	 enddo
	      close(unit=10)
        goto 25
	  endif
   21	close(unit=10)
	iyear=iyear+1		!next year
	call blet4(iyear,AYEAR)
     	infile(16:19)=AYEAR
	OPEN(10,FILE=infile,action='READ') !next year
	do k=1,13
	read(10,31) txt ! extra lines
	enddo
	knext=kacnt+1
	do ka=knext,3
	k1=ka+23
		read(10,137) jyear,jlda,jut,eb1(k1),bz1(k1)
     +,atp1(k1),anp1(k1),sw1(k1)
	 enddo
      close(unit=10)

C      Bstep, dB/dt, dVsw/dt
  25	do ii=0,23
	if (eb1(ii).gt.999.) eb1(ii)=AMIN1(eb1(ii-1),eb1(ii+1)
	+,eb1(ii+2),eb1(ii+3))
	if (eb1(ii+1).gt.999.) eb1(ii+1)=eb1(ii)
	if (eb1(ii+2).gt.999.) eb1(ii+2)=eb1(ii+1)
	if (eb1(ii+3).gt.999.) eb1(ii+3)=eb1(ii+2)
	db1(ii)=eb1(ii+1)-eb1(ii)
	bmin=AMIN1(eb1(ii),eb1(ii+1),eb1(ii+2),eb1(ii+3))
	bmax=AMAX1(eb1(ii),eb1(ii+1),eb1(ii+2),eb1(ii+3))
	bs1(ii)=bmax-bmin
	do k=ii,ii+3
	if (eb1(k).eq.bmin) kmin=k
	if (eb1(k).eq.bmax) kmax=k
	enddo
	if (kmin.gt.kmax) bs1(ii)=-bs1(ii)
C
      	if (bz1(ii).gt.999.) bz1(ii)=0.0
	if (atp1(ii).gt.9999998.) atp1(ii)=AMIN1(atp1(ii-1),atp1(ii+1))
	if (atp1(ii+1).gt.9999998.) atp1(ii+1)=atp1(ii)
	if (anp1(ii).gt.999.) anp1(ii)=AMIN1(anp1(ii-1),anp1(ii+1))
	if (sw1(ii).gt.9998.) sw1(ii)=AMIN1(sw1(ii-1),sw1(ii+1))
	if (sw1(ii+1).gt.999.) sw1(ii+1)=sw1(ii)
	dsw1(ii)=sw1(ii+1)-sw1(ii)
	dtp1(ii)=atp1(ii+1)-atp1(ii)
	enddo
C      
	RETURN
	END