How to Use Include Statement in Fortran?

  • Context: Fortran 
  • Thread starter Thread starter luonganh89
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary

Discussion Overview

The discussion focuses on the use of the Include statement in Fortran, particularly regarding its implementation and issues encountered when trying to include subroutines in a main program. Participants also explore challenges related to data transfer between subroutines.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant seeks help on using the Include statement with a specific file path and mentions encountering an error.
  • Another participant provides a link to documentation for the Include statement in HP Fortran compilers and requests to see the code and error message for more specific assistance.
  • A different participant shares their practice of not including drive letters in the Include statement and suggests using a different file extension for include files to distinguish them from compiled files.
  • Another participant outlines potential reasons for errors, including incorrect file paths or improper placement of the Include statement within the code structure.
  • The original poster reports successfully setting up the Include statement but encounters a new issue related to transferring data between two subroutines, mentioning the use of common blocks without success.

Areas of Agreement / Disagreement

Participants express differing opinions on the correct usage of the Include statement, particularly regarding file paths and naming conventions. The discussion remains unresolved regarding the best approach to transfer data between subroutines.

Contextual Notes

Participants have not reached a consensus on the most effective method for using the Include statement or transferring data between subroutines. There are also unresolved issues regarding the specific error messages encountered.

luonganh89
Messages
12
Reaction score
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
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.
 
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:
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
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 59 ·
2
Replies
59
Views
12K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 17 ·
Replies
17
Views
7K
  • · Replies 4 ·
Replies
4
Views
3K