×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

I have a file of almost 5000 lines

I have a file of almost 5000 lines

I have a file of almost 5000 lines

(OP)
I have a file of almost 5000 lines of code, made up of a series of subroutines.

I note that almost all the subroutines have the

CODE --> Fortran

include 'parm.h' 
instruction. I can see the need of this between files but is this required in each subroutine contained within the same file?

The very first line of code is also

CODE --> Fortran

include 'parm.h' 
; should this not suffice for the entire file?

RE: I have a file of almost 5000 lines

(OP)
Thank you, I was aware of the purpose of the contents and you are correct, it contains a series of variables required across the program. :)

My question is that in other languages you can include library files in the same way and the library contents are then available across the whole code, subroutines and all; everything contained within that file.
I was wondering if Fortran was the same. The link you shared was useful but wasn't clear on this. :(

Please do read the above with a smile; I cannot phrase the first line without it sounding condescending and that is NOT my intention at all. Hence the smiley face at the end (just in case). :)

RE: I have a file of almost 5000 lines

This is a scoping problem. There is no "outer block" as such so including a file at the top level will not make the variables visible to everything below. Fotran's concept of global variables is common blocks. The libraries normally contain functions but not common blocks and declarations.

The other common use is module declarations but it is normally better to use an interface declaration even though it looks a bit long winded.

RE: I have a file of almost 5000 lines

(OP)
Resurrecting this one because I am exploring the use of parma.h and xvar.h further.

These two files contain definitions of a set of variables and common names for a group of variables; including arrays (1 and 2 dimensional).

Both files are called repeatedly throughout the one file, yet in each instance only a few of the variables are required.

I am unsure of the benefit of doing it this way and, from a space point of view, I can see a really good reason NOT to do it this way.

Looking at the one routine where they appear I can see the following...

CODE --> fortran

C-
      include 'parm.h'
      include 'xvar.h'
      INTEGER     IE(ME+1),jp(6)
      CHARACTER*1 CS(2)
      CHARACTER*3 CE(ME+1)
      REAL*8      DE(6)
      DATA MODWRT/0/
      DATA CS/'*',' '/
      DATA CE/'HYD',' D ','Li ','He4','Stb',' C ',' N ',' O ','dG ',    &
     &        ' R '/
      DATA IE/1,2,3,4,8,5,6,7,9,10/
      DATA ifirst/0/
      save
C 

Now, if the save is simply a declaration to cause ALL variables defined within this subroutine (regardless of where they appear) as static (and I am assuming this means those included within the 2 files) then this means that a whole series of variables that are not even used in this subroutine are created and stored. Surely the following is true...?

  • the save command would be best placed at the beginning, since its position has no real relevance and it shows clear intent from the outset?
  • I should shift into the subroutine only those variables that are required by the subroutine into the subroutine itself; reducing the number of variables being stored in memory?[/indent]
  • If common means common across the whole program then a better way of conveying data from one subroutine to another is through the use of parameters?
Sorry if this is a lot of questions for one query but I'm really keen to explore the concept of Fortran as quickly as possible and re-develop this code, since I am convinced it is wasting space and time.

RE: I have a file of almost 5000 lines

Save saves all local variables. If the variables defined in the .h files belong to common blocks, then they are not 'saved'.

In the old days (1950s-1970s), there were 2 implementations.

1) When a subroutine/function was re-entered, all the local variables had random values
2) When a subroutine/function was re-entered, the values of all the local variables were 'remembered' from the last run (static variables in C, own variables in Algol 60). Data statements are only applicable when the subroutine is first called.

In F77, by default, #1 applies. Use save for #2

There isn't any rule on where save should be placed. You can specify variable names after the save to indicate that those are the only ones to be saved e.g.

CODE

save CE, ifirst 
would only save CE and ifirst. Save has no effect in the main program.

Common doesn't mean common across the whole program. It means common across the subroutines that have it. For instance you could have

CODE

subroutine AB
common /A/ ...
common /B/ ...
! C not required
...
end subroutine AB

subroutine BC
! A not required
common /B/ ...
common /C/ ...
...
end subroutine BC

subroutine CA
common /C/...
common /A/...
! B not required
...
end subroutine CA 
Later versions of Fortran no longer use common blocks. They use module level variables instead. This can be quite confusing as it is like statics in classes in C++. There are no "instances".

It is swings and roundabouts when you start playing with module level variables vs parameters vs type variables. I prefer using type variables - bung everything in the variable and pass it around. The subroutines can pick up whichever fields they require.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close