SofaScientist
SofaScientist

Reputation: 53

Print, write statement in Fortran module, subroutine

I am making a program 'maths.f90' that contains a few definitions:(r,n) that are sent to a fortran module 'geometry.f90' to simply calculate area of circle. Within that module there is a subroutine that does the bulk of calculations. The problem is: that subroutine does not print out the data and the same data is not generated and written to data.dat file. Both scripts are attached below, and are launched with makefile. Thank you in advance!!!

program maths

use geometry

implicit none

real :: r

integer:: n


r = 20.0

n = 5


print *, 'pi and r', pi, r

print*,'area from module',area_calc


end program math

module geometry

 implicit none 

 double precision :: pi= 4.*atan(1.), area_calc ! declaring uncangeble const

 public :: area_calc , pi



 contains

subroutine area(r,n)

   real, intent(in) :: r,n

 integer :: i


 open(unit=10,file='data.dat')

 do i=1,5

   area_calc = n*pi*r*r*i

    write(10,*)area_calc,i

   print*, 'sequence module',area_calc,i

   write(*,*) 'area within module',area_calc,i

 end do

  close (10)


end subroutine area

end module geometry

makefile

FC =gfortran

FFLAGS = -o3 -Wall -Wextra -std=f2008

SRC = geometry.f90 maths.f90

OBJ=${SRC:.f90=.o} # replacing source variable .f90 with .o 

%.o: %.f90 # any time i see a .o file it depends on the corres .f90

    $(FC) $(FFLAGS) -o $@ -c $<  #  $@ everything to the left the column

maths: ${OBJ}
    
    $(FC) $(FFLAGS) -o $@ $(OBJ) 

clean: 
     -rm -f *.mod *.o 

Upvotes: 0

Views: 71

Answers (0)

Related Questions