- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Hi,
1) I'm relative new to Fortran and I have a series of questions to fortran that may
seem very simple to your experts. I'm aware that this line of questions may seem
inappropiate for this forum in the meaning "too simple". If you believe this is true,
can you guide me to another forum where I can ask this line of questions?
2) If I'm calling a subroutine or a Function within another subroutine or function; should
I then make an interface/End interface section in each subroutine/function from which I'm
calling a another subroutine/function?
3) I have made a simple .F90 file with a number of functions and subroutines. Is it possible to have
several .F90 files and then call these subroutines/functions from the different .F90 files? For instance,
to call FunctionB in file2.F90 from FunctionA in file1.F90 ?
링크가 복사됨
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Your questions are indeed rather general, so a forum dedicated to a particular compiler may not be quite appropriate. An alternative where you definitely can ask such general questions is comp.lang.fortran.
I can answer your questions though:
ad 2: Interfaces are not always required, but the rules are confusing if you are new to Fortran (basically they are not needed if the routine's interface follows the FORTRAN 77 standard, but even then they are desirable, IMO). The easiest way to avoid having to introduce interfaces all over the place is using modules. The code for your routines should be contained in a module and the calling code then "imports" the routines - and along with that the exact interface to them - via "use statements":
module mycode
contains
subroutine mysub( a, b, c )
...
end subroutine
end module
program myprogram
use mycode
call mysub( a, b ) ! <== The call is incorrect - missing argument c and the compiler will complain
end program myprogram
ad 3. This is done by combining various compiled source files into a single executable. There are several ways in which to do that, but if you use the command-line method, you can do something along these lines:
> ifort -c file1.f90 file2.f90
> ifort mymain.f90 file1.obj file2.obj
The first command compiles two source files, producing so-called object files with the extension .obj. The second compiles a third source file, takes the two object files and combines the three object files into a single program called mymain.exe. You have a large number of options at your disposal to vary on this theme.
If you have Visual Studio, you can do the above via a graphical user-interface. It takes some getting used to, but it is worth the trouble.
This is just a very concise introduction into the world of building a program via a compiler/linker system. There is a lot more to it, but this ought to get you started.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Hans-henrik F. wrote:
Hi,
1) I'm relative new to Fortran and I have a series of questions to fortran that may
seem very simple to your experts. I'm aware that this line of questions may seem
inappropiate for this forum in the meaning "too simple". If you believe this is true,
can you guide me to another forum where I can ask this line of questions?..
Depending on your plans on working with Fortran and your level of interest, you may wish to review some good books on Fortran. It can help you gain a sound footing and a good overall perspective that would be rather difficult to obtain from forum postings. If you decide to pursue this further, I recommend "Fortran 90 for Scientists and Engineers" by Nyhoff and Leestma as an excellent book to start the introduction to Fortran: ssee http://www.amazon.com/FORTRAN-Engineers-Scientists-Larry-Nyhoff/dp/0135197295/ref=asap_bc?ie=UTF8. followed by all the suggestions by Dr Fortran in his blog - https://software.intel.com/en-us/blogs/2013/12/30/doctor-fortran-in-its-a-modern-fortran-world.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
I've written a couple of articles on explicit interfaces - here and here. The best practice is to not write INTERFACE blocks for Fortran routines but to use modules or contained procedures instead. (You do need INTERFACE to declare a generic, but can use PROCEDURE to name the module procedure rather than redeclaring the interface.)
You're welcome to ask general Fortran questions here if you like.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
OP has reminded me of a question I have been musing about for some time. We all learn how to build a program from a handful of source files, a library or two and so on, using tools like make or Visual Studio, learning a peculiarities of the compiler and the linker. But I have never seen (or otherwise I have completely erased it from memory) an expose on how this all works, from the point of view of the programmer. I mean: there are countless books on most popular programming languages and these discuss the syntax and semantics, but I have not seen any similar discussion on actually building the program from its components. Maybe I am not expressing my question clear enough, so in concise form: if you are new to Fortran or other compiled programming languages, how do you learn the craft of building programs other than just doing it or having others help you? Is there any book or tutorial out there that could guide you?
(Needless to say it is not for myself - I have learned this craft the long and hard way ;))
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Typically you would read the documentation for the particular compiler you are using. Intel Fortran has an extensive "getting started" section laying out the steps for building programs from the command line or, in the case of Windows, Visual Studio. Not all compilers have this sort of information, instead simply giving you compile command syntax and leaving you to puzzle out how to use it.
If I were new to a tool of any kind, I would look for "getting started" text and worked examples to familiarize myself with the usage.
