fortran 'call' vs 'include' - include

I see that Fortran has 'call' and 'include' statements. what is the difference between the two? Does the .i filetype have some significance?
i.e:
include 'somefile.i'
call 'somesubroutine.f'
Thanks!

INCLUDE statement lets you include source from some other file, as if it was in the file in which the statement is located. Its usefulness in organizing code is somewhat dubious, but some swear by it.
In F77 it was a common extension (from MIL-STD 1971, I believe), in F90 it made it into the Standard.
Filetypes have no significance. As the matter of fact, in fortran most filetypes (even the more common ones as f77, f90 and such) have no significance. Most compilers merely use them to automatically "detect" and differentiate free form from fixed form source code, but they also allow for other.
CALL statement is used for calling subroutines. It is of the form CALL subroutine_name(list-of-arguments). Subroutines are one of the more simple ways of structuring and dividing your program into logical sub-units.
But this is all relatively basic, and covered in every Fortran tutorial out there. Some are better, some are worse. A few good starting points for learners would be the Wikipedia page (not perfect, but not that bad either), FortranWiki and two books. One IRO-bot already mentioned, other would be Chapman's Fortran 95/2003 for scientists and engineers. It is generally considered more suitable for beginners, having an easy going approach and a plethora of practical examples, while Metcalf is aiming to be more of a reference book as well.

In general, file extensions don't have special meaning for the compiler. You can include any file, not just .i. Common extension for Fortran source files is .inc though.
include statement literally inserts a specified file into the source code.
call statement is very different, and it is used to call a Fortran subroutine.
These are very basic concepts. Before all, you should look up an introductory Fortran tutorial online (just try googleing it). Or get one of several great books on Fortran programming, e.g. Metcalf and Reid.

Related

Visual Studio Obfuscation

I am trying to test different obfuscators. Before obfuscating I used Reko decompiler. It seems that the exe is already obfuscated - please look at the screen shot. Can someone please explain - why all the methods and variables seems as if the exe is already obfuscated?
Symbol names are not compiled into executable machine code.
They can be preserved, but in this case they are saved in separate .pdb file. If you don't generate it during build, or don't make available to debugger/decompiler, it cannot figure out variables and function names (except for the imported/exported ones)
High level constructs, like for or while are implemented with jumps and conditional jumps, so it is not possible to figure out if a loop was implemented via for or goto or if a conditional was if statement or ternary operator.
Optimization hugely transforms code, throwing away unnecessary parts, making some operations at compile time, etc.

Make: Uses of static pattern rules in make

I would like to know the Uses of static pattern rules against normal rules in make. I an new to make and gone through some tutorials. I want to know when do we use this static pattern rules ? Could you please explain in brief ?
Thanks in Advance.
Your question is mostly a matter of opinion. Notice that there are several build automation tools (not only GNU make), e.g. also ninja, scons, omake, etc...
When you code in C (or in C++....) some project, you could have some C (or C++) files which are generated from something else (e.g. by lemon or by your own utility...). For such cases (pedantically you could call them metaprogramming), pattern rules could be useful (in particular if you have several such cases in a project). In other cases you generate other files (than object files) from C source (e.g. generating documentation with doxygen), and then pattern rules are also very useful.
An example of a large C++ project with many C++ code generators is the GCC compiler. And back when (in 2009) GCC was coded in C, it already had a dozen of specialized code generator programs emitting some C code. For these cases, pattern rules could be convenient.
Of course, pattern rules are a luxury. You could in principle generate your Makefile and have it contain a simple rule for each individual file. (in GCC, the Makefile-s are generated by autoconf and automake based things...)
If you observe and study the source code of most large free software projects, you'll find out that most of them do have generators for C (or C++) files. So generating C code is a usual practice (the original Unix from late 1970s did that already). Today, some software projects have most or even all (e.g. CAIA) of their C code generated.

Intel Fortran to GNU Fortran Conversion [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am working on a custom CFD Solver written in Fortran 90 and MPI.
The code contain 15+ Modules and was initially designed to work with the Intel Fortran compiler. Now since i do not have access to the Intel compiler I need to make it work using the GNU Fortran Compiler.
I made changes in the Makefile that initially had flags suitable for the ifort.
I am using it on Ubuntu with GNU Fortran and Openmpi
I am sorry I am unable to put in anything from the code structure or terminal output due to IP restrictions of my university. Nevertheless,I will try to best describe the issues
So now when I compile the code I am having some strange issues.
The GNU Fortran is not able to read lines that are too long and I get errors during compilation. As a result I have to break it into multiple lines using the '&' symbol
A module D.f90 contains all the Global variables declared. However, now I during compilation i get error is in module B.F90.
The error I get is 'Unclassified Statement Error', I was able to fix it in some subroutines and functions by locally declaring the variables again.
I am not the most experienced person in Fortran, but I thought that the change in compiler should not be a reason for new found syntax errors.
The errors described above so far could be remedied but considering the expanse of the code it is impractical.
I was hoping if anyone could share views on this matter and provide guidance on how to tackle it.
You should start reading three pieces of documentation:
The Fortran 90 standard (alternatively, other versions), which tells you what is legal, standard Fortran and what is not. Whenever you find some error, look at your code and check if what you are doing is legal, standard Fortran. Likely, the code in question will either be completely nonstandard (e.g. REAL*8, although that extension is fairly well understood) or rely on unspecified behaviour that Intel Fortran and GFortran are interpreting in different ways.
The GFortran manual for your version, which tells you how GFortran decides such unspecified cases, what intrinsic functions are available, how to change some options/flags, etc. This would tell you that your problem with the line lengths would be solved by adding -ffree-line-length-none.
The Intel Fortran manual for your version, which in cases of non-standard or unspecified behaviour, will allow you to know what the code you are reading was written to do, e.g. the behaviour that you would expect. In particular, it will allow you to decipher what the compiler flags that are currently being used mean. They may or may not need translation to GFortran, e.g. /Qsave will need to become -f-no-automatic.
A concrete example of interpretative differences within the range allowed be the standard: until Fortran 2003, the units for the "record length" in random access record files were left unspecified. Intel Fortran used "one machine word" (4 bytes in x86) while GFortran used 1 byte. Both were compliant with the standard letter, but incompatible.
Furthermore, even when coding "to standard", you may hit a wall if the compiler does not implement part of the Fnn standard, or it is buggy. Case in point: Intel Fortran 12.0 (old, but it's what I work with) does not the implement the ALLOCATE(y, SOURCE=x) construct for polymorphic x (the "clone allocation"). On the other hand, GFortran has not completely implemented FINAL type-bound procedures (destructors).
In both cases, you will need to find workarounds. For example, for the first issue you can use a special form of the INQUIRE statement (kudos to #haraldkl). In other cases, the workaround might even involve using some kind of feature detection (see autoconf, CMake, etc.) and storing the results as PARAMETER variables in a config.f90 file that is included by your code. Your code would then take decisions based on it, as in:
! config.f90.in (things in #x# would get subtituted by automake, for example)
INTEGER, PARAMETER :: RECORD_LEN_BYTES = #RECORD_LEN_BYTES#
! Some other file which opens a file
INCLUDE "config.f90"
!...
OPEN(u, FILE='DE430.BIN', ACCESS='direct', FORM='unformatted', RECL=56 / RECORD_LEN_BYTES)
People have been having complaints about following the standard since at least the 60s. But those cDEC$ features were put in a for good reasons...
It is valuable to cross compile though and you usually have things caught in one compiler or the other.
For you question #1 "The GNU Fortran is not able to read lines that are too long and I get errors during compilation. As a result I have to break it into multiple lines using the '&' symbol"
In the days of old there was:
options/extended_source
SUBROUTINE...
In fort it is -132, but I have not found a gfortran equivalent to -132 . It may be -ffixed-line-length-n -ffixed-line-length-none -ffree-line-length-n -ffree-line-length-none per the link: http://www.math.uni-leipzig.de/~hellmund/Vorlesung/gfortran.html#SEC8
Also the ifort standard for .f90 and .f95 is the the compiler switch '-free' '-fixed' is the standard <.f90... However one can use -fixed with .f90 and use column 6 and 'D' in column #1... Which is handy with '-D_lines' or '-DD'.
Per the link: https://software.intel.com/sites/default/files/m/f/8/5/8/0/6366-ifort.txt
For you question #2: "A module D.f90 contains all the Global variables declared. However, now I during compilation i get error is in module B.F90. The error I get is 'Unclassified Statement Error', I was able to fix it in some subroutines and functions by locally declaring the variables again."
You probably need to put in the offending line, if you can get an IP waiver.
Making variables local if they are expected to be shared in a /common/ or shared in a module will not work.
If there were in /common/ or PUBLIC then they are shared.
If they are local then they are PRIVATE.
it would be easy to get that error if a PRIVATE statement was in the wrong place, or a USE statement was omitted.

How to refactor dynamic languages safely?

For example I decided to fuse two classes. The problem with JS or LUA is that it gets very hard to find implicit problems, for example it shows you a error only when your runtime actually executes the piece of code you are trying to implement. The advantage of strict languages like Haxe or C++ is that your code won't compile until you fix everything.
Does anyone know what are the best practices for refactoring dynamic languages?
The problem isn't really specific to "refactoring".
It is that "it (the dynamic language interpreter) shows you a error only when your runtime actually executes the piece of code which is wrong (and sometimes not even then)". This is probably the major defect of dynamic languages.
What is needed is a tool that can reason deeply about your code to decide statically, where practical, if executing it might produce a runtime error or a useless computation. Such tools are pretty hard to find.
The discussion here is instructive: Programming Language Properties that facilitate refactoring?

C++ library: .hpp + .inl (separate definitions and declarations) vs .hpp only (in-class body code)

I'm rewriting my Windows C++ Native Library (an ongoing effort since 2002) with public release in mind. For the past 10 years I've been the sole beneficiary of those 150+ KLOC and I feel others might find good uses for it also.
Currently the entire library is quite-templated and header only. That means all code is in the body of the classes. It's not very easy to manage but it's OK.
I'm VERY tempted, after reading several C++ library coding guidelines, to break it into .hpp + .inl files. Experimentally done so for a few classes and it does increase readability and makes it easier for others to deal with. I know where everything is at any given time. But other users might want to a quick overview of a classes declaration... and the definition only if necessary (debugging).
QUESTION:
What are the pros/cons of splitting the member definitions from the class' definition for a class template? Is there a commonly accepted practice.
This is important for me because it's a one way road. I can't refactor it the other way later on so any feedback matters...
I've found my answer in another question.
Question: When should I consider making a library header-only? - and answer is here^.
And the answer is I will break it into .cpp and .hpp files and make it ready to compiler both as header only and static library or DLL.
#Steve Jessop:
If you think your non-template library could be header-only, consider dividing it into two files anyway, then providing a third file that includes both the .h and the .cpp (with an include guard).
Then anyone who uses your library in a lot of different TUs, and suspects that this might be costing a lot of compile time, can easily make the change to test it.
^ this is an awesome idea. It will take a bit more work but it's SO versatile.
UPDATE
It's important to explicitly instantiate^ the templated classes in the .cpp files.

Resources