c.....  file name dud_mod.for
	SUBROUTINE DUDNEY(ipass,ff,hh)
C	DUDENEY N(H) PROFILE S/R FOR USE WITH Jones RAYTRACING PROG
c	calculate the parameters x,pxpr etc corresponding to a 
c	height hh above the surface of the earth, for a wave freq ff.
C	SEE  JATP 40(2), 1978, PG 195
C	LEO MCNAMARA  APRIL 1981    
c
c	copied from dud-jones.for 20-jul-87
c	modified 20-jul-87 to include an E-F valley slab, yms wide
c
c-----  LAST MODIFIED 20-jul-87
c
C.....REQUIRES S/R DIMSOL & FUNCTIONS HMAX,YMAX (DUDENEY S/RS)
C	
C	S/R IS ESSENTIALLY THE SAME AS DUDENEY'S FUNCTION FN(H), EXCEPT
C	THAT THE SLOPE PXPR IS ALSO CALCULATED
C........................................................................
C	
c 	IPASS = 0 to calculate Dudeney parameters; set=1 afterwards
C........................................................................
C	FOF2  F2 LAYER CRITICAL                MANDATORY
C	FOF1  F1 LAYER CRITICAL                NO F1 GENERATED IF <=0
C	FOE    E LAYER CRITICAL                SET=.6 IF <=0
C	HFF2  MIN F2 VIRTUAL HEIGHT            MANDATORY IF YMF2<=0
C	M3000 M(3000)F2                        MANDATORY IF HMF2<=0
C	HME   E REGION PEAK HEIGHT             SET=100 IF <=0
C	YME   E REGION SEMITHICKNESS           SET=20 IF <=0
C	HMF2  F REGION PEAK HEIGHT             CALCULATED IF <=0
C	YMF2  F REGION SEMITHICKNESS           CALCULATED IF <=0
C	H0    BASE HEIGHT OF IONOSPHERE        E LAYER IF XD<=0
C	XD    D REGION TANGENT TO E LAYER AT XD*FOE
C	DV    E-F FRACTIONAL VALLEY DEPTH
C........................................................................
C	
	REAL M3000
	real*8 x,pxpr,pxpth,pxpph,pxpt,hmax,ff,hh
	character*8 modx
C	
C	DUDENEY'S LABELLED COMMON - OUTPUT FROM DIMSOL
	COMMON / PARMS / BETA,HT,FT,A,HF,AD,TAU,HD
c	the extra parameters yms & hms
	common / slabparms / hms,yms
C	JONES CODE
	COMMON / XX / MODX(2),X,PXPR,PXPTH,PXPPH,PXPT,HMAX
c
	common / iondat / fof2,fof1,foe,hff2,m3000,hme,yme,
     a  hmf2,ymf2,h0,xd,dv
c
	data modx / 'DUDNEY','  ' /
	DATA PI,C1 / 3.141592654,1. /
C	
	fn=0.
	X=0.d0
	PXPR=0.d0
	PXPTH=0.d0
	PXPPH=0.d0
	h = sngl (hh)
	f = sngl (ff)
	yms = 20.
	hms = hme + yms
c
C	FIRST CALL TO S/R - IPASS=0 - CALCULATE DUDENEY PROFILE
	IF(IPASS.EQ.1) GO TO 10
	CALL DIMSOL(IERROR)
	HMAX= dble(HMF2)
	IF(IERROR.EQ.0) GO TO 10
	PRINT 200,IERROR
200	FORMAT(//5X,'*DIMSOL RETURNED ERROR CODE*',I3//)
	STOP 200
10	continue
C	
C	CHECK TO SEE IF POINT IS BELOW BASE HEIGHT
	IF(H.LE.H0) RETURN
C	
C	D-REGION SEGMENT
	IF(H.GT.HD) GO TO 20
	FN=TAU/ALOG(AD/(H-H0))
	DFNDH=FN*FN/TAU/(H-H0)
	GO TO 60
C	
C	E-REGION SEGMENT   DUDENEY EQN 5
20	IF(H.GT.HME) GO TO 22
	CON1=(HME-H)/YME
	CON2=SQRT(C1-CON1*CON1)
	FN=FOE*CON2
	DFNDH=FOE*CON1/CON2/YME
	GO TO 60
c
c	E-F full valley
22	if(h.gt.hms) go to 25
	fn = foe 
	dfndh = 0.
	if(ipass.eq.0) type*,' yms,hms,foe,h,fn,dfndh ',
     a                         yms,hms,foe,h,fn,dfndh
	go to 60
c
25	continue
C	F1-REGION SEGMENT   APPROX DUDENEY EQN 12
	IF(H.GT.HT) GO TO 40
	ANG1=2.*PI*(H-hms)/(HT-hms)
	ANG2=(H-hms)/BETA/YMF2
	COS1=COS(ANG1)
	SIN1=SIN(ANG1)
	COS2=COS(ANG2)
	SIN2=SIN(ANG2)
	FN=FOE*(A*(C1-COS1)+C1/COS2)
	DFNDH=2.*PI*A/(HT-hms)*SIN1+C1/BETA/YMF2/COS2/COS2*SIN2
	DFNDH=FOE*DFNDH
	GO TO 60
C	
C	F2-REGION   DUDENEY EQN 1
C	TOPSIDE DENSITY DROPS TO ZERO AT H=HMF2+(PI/2)*YMF2
40	IF(H.GT.HMF2+(PI/2.)*YMF2) RETURN
	ANG=(HMF2-H)/YMF2
	FN=FOF2*COS(ANG)
	DFNDH=FOF2*SIN(ANG)/YMF2
C	
C	CONVERT FROM FN TO X AND FROM DFNDH TO PXPR (for Jones prog)
60	F2=F*F
	X= dble (FN*FN/F2)
	PXPR= dble (2.*FN*DFNDH/F2)
C	
	RETURN
	END
