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!

Modules and Codeblocks

Status
Not open for further replies.

mcneilyee

Technical User
Jun 19, 2013
1
AU
Hi, After trawling google, I was wondering if anyone could direct me in the right direction on here.

Basically I have been writing extremely long programs to write a series of packages (ascii text files) that are used in a 3rd party software package. I want to be able to do this:

(This is my main program where I assign parameter arrays)
program hello
implicit none
real(kind(0d0)) :: tmpdate
tmpdate = 23.2
print *, 'Hello World! Calling Module'
use hello2
end program hello

I want to call a series of modules to write out the arrays specified in the Main program.... e.g.

module hello2
implicit none
real(kind(0d0)) :: tmpdate
tmpdate = 23.2
write(*,*)tmpdate
end module hello2

The modules will saved as separate f90 files. e.g. write_file1.f90, write_file2.f90... Im assuming I need to create a new 'Fortran Application' project in codeblocks.

Is this possible? Because from what I've seen, I'm only able to calculate values in the module, and then process them in the main program... Or am I being silly?

Help would be muchly appreciated.
Cheers
 
Not sure about codeblocks. I've only ever used it for C/C++ in a Linux environment. Never used it with Fortran or in a Windows environment. The syntax or possibly your understanding of modules in FORTRAN programs is incorrect. A module contains a list of related variables, functions and subroutines. A module is not a replacement for a subroutine.

It should look something like this
Code:
program hello 
! The use statement is before executables
use hello2 
implicit none 
real(kind(0d0)) :: tmpdate 
tmpdate = 23.2
print *, 'Hello World! Calling Module'
! This is the routine from hello2
call hello2sub
end program hello

Code:
module hello2 
! Contains needed
contains
! Subroutine header
subroutine hello2sub
implicit none 
real(kind(0d0)) :: tmpdate 
tmpdate = 23.2 
write(*,*)tmpdate 
end subroutine hello2sub
end module hello2

The alternative is to use F77 then you won't need to use modules but then you have need to use fixed format. If you don't do array processing and dynamic storage allocation, the only advantage that f95 has over f77 is free format but the price you pay is additional syntax and decoration that goes around the subroutines. In order to compile as F77, just use the extension .f or .for instead of .f90 or .f95.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top