Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fractal code

Status
Not open for further replies.

j0zn

Programmer
Jul 19, 2013
36
BR
Hi guys! I am trying to make a mandelbrot code in fortran and I am having some problems
I have just started and I'd like to know what is wrong until now.
Thank you in advance
links that can help us

PROGRAM MANDELBROT
IMPLICIT NONE
REAL :: C_REAL, C_IMAG, Z_REAL, Z_IMAG, Z_REAL2, Z_IMAG_2
INTEGER I, ABOUT_OPEN
CHARACTER(LEN=80) :: FILE_OUT
INTEGER, PARAMETER :: OKAY = 0, UNIT_OUT = 17, MAX_INTERATIONS=300
LOGICAL :: BELONG

WRITE(FILE_OUT, 17)
17 FORMAT(i3,"MANDEL_CORDINATES")
OPEN(UNIT = UNIT_OUT, FILE = FILE_OUT, &
&STATUS="new", ACTION="write", IOSTAT=ABOUT_OPEN)

IF(ABOUT_OPEN == ok)THEN
BELONG = .TRUE.
DO I=1,N
C_REAL ! I do not know how start C_REAL
C_IMAG ! AND C_IMAG
END DO
Z_REAL=C_REAL
Z_IMAG=CI
Z_REAL2=ZR*ZR
Z_IMAG2=Z_IMAG*Z_IMAG

DO I=0, MAX_INTERATIONS
IF ((ZRS + ZIS) <= 4.0)THEN
Z_REAL2 = Z_REAL * Z_REAL
Z_IMAG2 = Z_IMAG * Z_IMAG
Z_IMAG = 2.0 * Z_REAL * Z_IMAG + C_IMAG
Z_REAL = Z_REAL2 - Z_IMAG2 + C_REAL
END IF

WRITE(UNIT=UNIT_OUT, FMT=*)Z_REAL, Z_IMAG
END DO
END IF
CLOSE(unit=UNIT_OUT)
END PROGRAM MANDELBROT
 
Why not use complex numbers instead of having real and imag separately.
 
Thank you gullipe!Congratulations for your code!
I'd like to create a postscript file instead ppm picture. How to do this?

Xwb thank for your tip, I'll try.
 
There are libraries for plotting from within Fortran (plplot, dslin, etc), I used to do that; since, I have opted to stop plotting directly from Fortran and, instead, just output minimal data and plot outside with, say, python/matplotlib...this way, should somebody want to make a different plot, annotations, arrows, colors, etc...I don't have to re-compile the program and re-run or anything...besides, it is best to learn how to use one plotting program well than having to learn one for Fortran, one for C, one for...get the point? If you learn how to use one program well, you can plot data no matter where the data is coming from. Also, if somebody else does not like your plot, you can give them the data and let them plot it with their favorite program, the one THEY know how to use well, etc.
 
I am trying to find out what is the problem and I can't. I am going create the graph using Grace but when I look what I've printed I see just parallel lines. Please, tell me what is happen!! Thank you in advance guys


PROGRAM mandelbrot_set
IMPLICIT none
INTEGER :: iterations_max, hor_x_resolution, hor_y_resolution, my_open
REAL :: value_max, part_real_c, part_imag_c, z_real, z_imag, z_sqrt
REAL :: z_real2, z_imag2 , z_real_w
INTEGER :: iteracoes, hx, hy, a
INTEGER, PARAMETER :: ok=0, unit_out= 20
CHARACTER(len=30) :: file_out

WRITE(file_out, 20)a
20 FORMAT(i3,"MANDEL_TEST_.dat")

iterations_max = 10000 ! max of interation for the do
value_max = 4.0 ! |z|^2 hightest than this it breakout
part_real_c = -0.9462 !real part of c in z^2=z^2+c
part_imag_c = 0.00009000 ! imaginary part z^2=z^2+c

OPEN(unit= unit_out,file=file_out, status="new", &
action="write", iostat= my_open)
IF(my_open == ok)THEN

z_real_w = part_real_c
z_imag = part_imag_c
DO iteracoes = 1, iterations_max

z_imag = 2.0 * z_real * z_imag + part_imag_c
z_real_w = z_real * z_real - z_imag * z_imag + part_real_c
z_real = z_real_w
z_sqrt = z_real_w*z_real_w + z_imag*z_imag

IF (z_sqrt .lt. value_max) then

WRITE(unit = unit_out, fmt= *) z_real_w, z_imag
end if
END DO

ELSE
PRINT *, " You have a problem"
END IF
CLOSE(unit = unit_out)
END PROGRAM mandelbrot_set
 
In line 22, are you sure you meant
z_real_w = part_real_c
and not
z_real = part_real_c?

Because doing "z_real_w = part_real_c" is not doing you any good as the very next time you use z_real_w is on the left hand side of the equal side in line 27.
 
I was trying to do something like this:
z_real = part_real_c
z_imag = part_imag_c
DO iteracoes = 1, iterations_max
z_sqrt = z_real*z_real + z_imag*z_imag

IF (z_sqrt .lt. value_max) exit
WRITE(unit = unit_out, fmt= *) z_real, z_imag

z_imag = 2.0 * z_real * z_imag + part_imag_c
z_real = z_real * z_real - z_imag * z_imag + part_real_c

But my program is not working yet
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top