Include statement in Fortran

  • Fortran
  • Thread starter luonganh89
  • Start date
  • Tags
    Fortran
In summary: F [1.9.22_1171]please wait... Rating: 3.0/5 (1 vote cast)In summary, Luong Anh wants to transfer a list of variables between two subroutines in his program, but he is unsuccessful.
  • #1
luonganh89
12
0
hi all !

I want to ask about Include Statement in fortran example: Include 'D:\XXX.f'
in my XXX.f have some subroutines and want to call these subroutine in Main program but i show error . someone does like me can share me some experience !
 
Technology news on Phys.org
  • #3
I have never included the drive letter or anything else other than the file name itself into the include statement...typically, you tell the compiler where to find include files via compiler option (-I, I think) and then you simply write "include 'xxx.f' " in your program.

I typically do not use *.f extension on files that are meant to be included into others; instead, I use *.inc, for include. I have my reasons to use a different extension for files to be included...they do not need to be compiled! And so, my make files can tell them apart from the ones with *.f extension that do need to be compiled.
 
  • #4
Without seeing the error message, I guess there are two basic options

1. The compiler could't find your file (i.e the file name or directory was wrong, or you forgot to put then name in quotes, or whatever)

2. You are including the contents of the file in the wrong place. For example if you want to include a complete subroutine for some reason, you can't have the suibroutine "nested" insude anouther routine or the main program. The compiler just inserts the contents of the include file at the place where the "include" statement was. It's your responsibility to make sure that produces a valid complete program. The compiler doesn't do any "magic" to sort that out for you.
 
Last edited:
  • #5
thank everybody !
i've set up succesfully my include link. I see that Include statement can put everywhere in my code - it means that when we call include statement with file fortran it will replace the codes in this file.

but i find new problem is transferring data between 2 subroutine in my programme
c
C Flow variable arrays
C
REAL(8),ALLOCATABLE,DIMENSION(:,:,:):: RHO,U,V,W,
. US,VS,WS,TMP,TMPS,FVX,FVY,FVZ,P,DDDT,D,DS,Q,
& MUL,MUT,CSD,PRD,LLM,LMM,PPR,QPR

I have two subroutine - one is pre-process, one is process. But i must transfer a list of variable which you can see. but it don't run as well as i can. I read in internet, we can use common block but i try but unsuccessful , can help me again my friends ?thank a lot

Luong Anh
VN
 

1. What is an "include statement" in Fortran?

An include statement in Fortran is a way to insert external code into your main program. This is useful for reusing common code or organizing your program into multiple files. It allows you to write code in separate files and include them in your main program without having to copy and paste the code every time.

2. How do you use an include statement in Fortran?

To use an include statement in Fortran, you need to first create a separate file containing the code you want to include. Then, in your main program, you use the statement "include 'filename'" to insert the code from that file into your program. Make sure to include the file extension in the filename.

3. What is the syntax for an include statement in Fortran?

The syntax for an include statement in Fortran is "include 'filename'". The filename should be enclosed in single quotes and can also include a path to the file if it is located in a different directory.

4. Can you include multiple files in a Fortran program?

Yes, you can include multiple files in a Fortran program. You can use multiple include statements in your main program to insert code from different files. However, it is important to avoid circular dependencies, where one file includes another file that also includes the first file.

5. Are there any limitations to using include statements in Fortran?

Yes, there are some limitations to using include statements in Fortran. The included files cannot contain any program control statements, such as END, RETURN, or STOP. They also cannot contain any program units, such as SUBROUTINE or FUNCTION. Additionally, the included files must have valid Fortran syntax and must be included in the same compilation unit as the main program.

Similar threads

  • Programming and Computer Science
Replies
0
Views
19
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
2
Replies
59
Views
9K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
4
Views
602
  • Programming and Computer Science
2
Replies
62
Views
10K
  • Programming and Computer Science
Replies
9
Views
3K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
17
Views
4K
Back
Top