C This software MAN_CAL.FOR is part of the Visual Fortran kit.
C
C This software is provided as an example that demonstrates a particular
C feature/function of the licensed product. The software is not intended to
C provide a complete solution to any application problem but rather is provided
C as a teaching mechanism.
C
C Users may incorporate any part of this sample into their own source after 
C making appropriate changes to make it suitable for the intended application.
C

C	 ++
C	 FACILITY:
C
C	   Mandelbrot software
C
C	 ABSTRACT:
C
C	   Contains the acutal Mandelbrot Set calculation algorithm
C
C	 AUTHORS:
C
C	   PSW
C
C	 CREATION DATE: 25 May 1992
C
C	 MODIFICATION HISTORY:
C	--

C
C	cal_man - Mandelbrot Calculation
C
C	Perform the Mandelbrot calculation with the initial complex parameters
C	C given by CR and CI, Z0 given by Z0R and Z0I, using a cutoff
C	value of CUTOFF.
C
C	Return -1 if the point was found to be in the Set, 0 if the iteration
C	count was exceeded, or a the number of iterations performed before
C	determining that the point was not in the Set.
C
	integer*4 function cal_man_(cutoff, cr, ci, z0r, z0i)
	!dec$ if defined(_X86_)
	!DEC$ ATTRIBUTES stdcall :: cal_man_
	!dec$ else
	!DEC$ ATTRIBUTES alias: "cal_man_" :: cal_man_
	!dec$ endif
	integer*4 cutoff
	!dec$ attributes reference :: cutoff
	real*8 cr
	!dec$ attributes reference :: cr
	real*8 ci
	!dec$ attributes reference :: ci
	real*8 z0r
	!dec$ attributes reference :: z0r
	real*8 z0i
	!dec$ attributes reference :: z0i

	integer*4 co
	integer*4 n
	real*8 zr, ztr, zr2
	real*8 zi, zti, zi2
	real*8 temp,tr,ti

	co = cutoff
	n = 0
	zr = z0r
	zi = z0i
	ztr = zr
	zti = zi
10	continue
	zr2 = ztr * ztr
	zi2 = zti * zti
	zi = 2 * ztr * zti + ci
	zr = zr2 - zi2 + cr
	temp = zr2 + zi2
	zr2 = zr * zr
	zi2 = zi * zi
	ti = 2 * zr * zi
	tr = zr2 - zi2
	n = n + 1
	if (temp .ge. 4.0) goto 200
	temp = zr2 + zi2
	if (zr .eq. ztr) goto 150
15	continue
	ztr = tr + cr
	zti = ti + ci
	if (n .gt. co) goto 100
	n = n + 1
	if (temp .ge. 4.0) goto 200
	if (zr .eq. ztr) goto 170
16	continue
	if (n .le. co) goto 10
C
C	iteration count exceeded
C
100	continue
	cal_man_ = 0
	return
C
C	Tests for point in set
C
150	continue
	if (zi .ne. zti) goto 15
C
C	value unchanged--in Set
C
160	continue
	cal_man_ = -1
C	Return 0 as being in set.
C	cal_man_ = 0
	return

170	if (zi .ne. zti) goto 16
	goto 160
C
C	not in Set
C
200	continue
	cal_man_ = n 
	return
	end

