forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Query on procedures and modules in FTN95

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
Anonymous
Guest





PostPosted: Wed May 03, 2006 12:26 am    Post subject: Query on procedures and modules in FTN95 Reply with quote

Greetings to the kind soul who can hopefully answer my question.

Delving - for the first time - into the object oriented features of FTN95,
I am wondering what advantage is it to write a subroutine within a
main program or module (following a CONTAINS statement and
before the END PROGRAM or END MODULE statement? Why is this
better than just listing main prog and subroutines after ne another
in one file?

With many thanks,
Ludwig

Ludwig

Ludwig
Back to top
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5419
Location: Salford, UK

PostPosted: Wed May 03, 2006 1:25 am    Post subject: Query on procedures and modules in FTN95 Reply with quote

Ludwig

Using internal procedures (CONTAINS) within a main program allows procedures to share variables that appear in the main program. You do not need to pass them as arguments.

Modules and module procedures (CONTAINS within a MODULE) are the Fortran 90/95 way of introducing a degree of object orientation into Fortran. An object oriented strategy is simply to cluster your data together with the procedures that act upon the data. So in Fortran you put the data and the procedures associated with a given object into one module. This simplifies the structure of the program and aids maintenance.

Back to top
View user's profile Send private message
Anonymous
Guest





PostPosted: Wed May 03, 2006 9:16 am    Post subject: Query on procedures and modules in FTN95 Reply with quote

Dear Paul,

Thank you very much for your help. Your answer really clears things up for me.
May I trouble you with three more questions?

1.) Can procedures be declared PUBLIC/PRIVATE in addition to variables, or is
every procedure referenced with a USE statement accessible to the referring
program unit?

2.) Depending on the answer to Q1, can a PUBLIC/PRIVATE statement be put
before each subprogram name within a module, or should you use just one
PUBLIC/PRIVATE statement (listing all relevant procedures) at the beginning
of the module?

3.) True/False? -> In a module USE-ed by another program unit, arguments are
only used for functions but not for subroutines.

With many thanks and best regards,
Ludwig


Ludwig
Back to top
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 5419
Location: Salford, UK

PostPosted: Wed May 03, 2006 9:34 am    Post subject: Query on procedures and modules in FTN95 Reply with quote

1) Yes they can.

2) Everything is PUBLIC by default.
Putting PRIVATE at the start makes everything PRIVATE.
PUBLIC can then be followed by a list of variables and procedures.
There are other ways. Details can be found in a standard Fortran text.

3) False. You can pass arguments to subroutines.

Please refer to a standard Fortran text book for further details.
Back to top
View user's profile Send private message
Anonymous
Guest





PostPosted: Wed May 03, 2006 1:13 pm    Post subject: Query on procedures and modules in FTN95 Reply with quote

Dear Paul,

Thank you again. I have now ordered
a text on amazon.com - will refer to it.

I appreciate your kind help.

Best wishes,
Ludwig


Ludwig
Back to top
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Fri May 05, 2006 9:05 am    Post subject: Query on procedures and modules in FTN95 Reply with quote

The best Fortran 95 text I have come across and used is the following:

Fortran 90/95 Explained - Metcalf and Reid

This is available from Amazon (UK) at:

http://www.amazon.co.uk/exec/obidos/ASIN/0198505582/qid=1146841329/sr=8-2/ref=sr_8_xs_ap_i2_xgl/203-4084555-5478340

There is a more recent version with input from Malcolm Cohen with the 2003 standard, but as most compilers do not fully support this (FTN95 supports just a few small features) then I would stick with the older text so as not to confuse matters.

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group