Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

changing .f90 files to .for

mechprog
Beginner
3,456 Views
Hello all,

When I write a subroutine in Intel Fortran 10.1 (through Visual Studio 2008), it saves the file as a .f90 however I need to file type to be .for. However when I go to file - save as - and type filename.for, it seems to green out all the code. This seems to be causing me problems with my code.I have attached both files to this post.Is there a more efficient and reliable way to change my .f90 files to .for? I need the .for file types ofso I can use them withanother programming which reads .for subroutines.

Thank-you very much.

0 Kudos
17 Replies
mecej4
Honored Contributor III
3,454 Views
I do not usually create source files using Visual Studio, but I do not see why you should have any problems.
I created a new, empty console project, to which I added (i) a new fixed format Fortran file and (ii) a new free format Fortran file. The editor gave each the proper suffix, and showed the syntax highlighting properly. The project was trivial to build, compile and run.
The two files that you attached are both free format, regardless of the suffixes used; they are identical in content. Neither file contains valid Fortran source in free format or fixed format.
0 Kudos
Anonymous66
Valued Contributor I
3,456 Views

Hello mechprog,

This is because .for files are fixed format Fortran files, and the first five rows should generally be left blank in fixed format Fortran. The following article has more information about fixed format Fortan -http://software.intel.com/sites/products/documentation/hpc/composerxe/en-us/2011Update/fortran/win/lref_for/source_files/pgbsfixd.htm

Regards, Annalee

0 Kudos
mechprog
Beginner
3,456 Views
Thanks for your reply, what do you recommend in terms of creating fortran code? I was not aware of fixed and free format fortan files. I would like to use some software to help me produce valid .for code. I am and engineer new to programming. Thanks again.
0 Kudos
Les_Neilson
Valued Contributor II
3,455 Views

Why do you need "valid .for code"? .f90 files are just as valid.

Fixed format means :
column 1 to 5 used for statement label
column 6 used for continuation indicator
column 7 to 72 used for program statements

Free format means these restrictions do not apply. Statements are not limited to specific column positions in a source file.

See the help (under Contents -> Language Reference -> Program Structure -> Source Forms

As you are new to programming I would reccommend as a starting point
(a) use free format it is less error prone.
(b) ALWAYS have "implicit none" in your routines.
(c) learn the modern Fortran language style (rather than F77 style) for example you can use whole array operations instead of do-loops
(d) learn about modules, they are another great means of reducing errors.

Hope this helps
Les

0 Kudos
mechprog
Beginner
3,457 Views
Hi Les,

Thanks for your feedback, as I am currently really stuck with these fortran coding problems.
I am rather restricted as I am trying to use fortran subroutines with an engineering program called Abaqus. The following restrictions apply:
1) Abaqus can only read .for or .obj user subroutine files
2) I need to use Intel Fortan 10.1 compiler
I am 100% sure that the problems are currently with my fortran code. Can anyone recommend a suitable method for writing .for code successfully?
Thanks
0 Kudos
Arjen_Markus
Honored Contributor II
3,457 Views
You can useseveral approaches:

1. As Fortran source files (either in fixed on in free form) are simply ordinary text files,
you can use your favourite text editor to create and edit them. Once you are done,
you can either import them into Visual Studio or use the command-line mode to
compile them. This will give you the opportunity to correct syntactical and other
mistakes.

(I find the command-line mode to be very useful for small projects - one or two
source files, say, because Visual Studio, while wonderful for large ones,tends to
be a bit of a burden if you only have a single source file.)

2. You can use free form source code instead. Perhaps you need to read up on this
type of files, but I find free form to be easier to work with myself. There are
plenty of online resources and books on paper to fill you in on these and other
aspect of Fortran 90 and later standards.

Regards,

Arjen
0 Kudos
mechprog
Beginner
3,457 Views
Thanks for your input Arjen,

Unfortunetly I need to only use .for files (as I understand so far, this is only fixed type). I am not sure why Abaqus can only read this type of code?

I have checked to ensure there are no problems in the configuration between the Intel Fortran compiler and Abaqus and there is no issue. All the checks passed.

I have attached an updated .for file to this post, is the syntax now corrected? Am I still missing something here?

Thanks again for everyone help!
0 Kudos
Arjen_Markus
Honored Contributor II
3,457 Views
Hi mechprog,

continuation is done using a non-space, non-zero character in the sixth column and you have it
in the seventh (this counting is one aspect of fixed form that makes it cumbersome to use).
Compiling the source (outside the Abaqus environment) will quickly give you the information
on syntax errors and such.

Regards,

Arjen
0 Kudos
Les_Neilson
Valued Contributor II
3,457 Views
Lines 2 and 5 you have a "1" to indicate continuation. That "1" should be in column 6

Les
0 Kudos
mechprog
Beginner
3,456 Views
Problem now solved, thanks everyone! I can see the programming world builds on of those love-hate relationships...

Thanks again. I am sure I will be posting on here again soon. Apparently I am "green-belt", thank you Sensai Intel :-)
0 Kudos
Arjen_Markus
Honored Contributor II
3,456 Views
Don't worry, we all go through such processes ;)

Regards,

Arjen
0 Kudos
jimdempseyatthecove
Honored Contributor III
3,456 Views
Also note, some editors will convert multi-space line indentation into tab and/or tab space indentation which you will not see the difference in your editor. The compiler is counting character posistions as to the first 5 characters on the line and the position of the 6'th and 7'th characters. Visual Studion integration (should) colorhighlight these positions when editing a xxx.for file. The color highlighting may help you to identify errors.

Fixed form can at times hide syntax errors and coding errors. i.e. the compiler will not detect/report error due to the programming error looking like valid statements considering what is in/(not in) columns 1:6.

If you prefer to use your favorite editor, I would suggest you write a GREP or other text file filtering program to find lines with TAB's on them and which you then replace the TAB with the appropriate number of spaces.

Then filter to find lines with non-space in column 6. Visually assert that these are proper continuation lines. (and have either a numeric or * character)

Then filter to find lines to find lines with non-space/non-numeric characters in columns 1:5 (these are in error)

Then filter to find lines without spaces as the first5 characters. These should be all numeric. Inspect these lines to assert that they are valid continuation lines.

*** Note

I do not use ABACUS so I do not know what it is looking for in your .FOR files. If it is looking for data/common declarations then you might get by with compiling as .f90, copy/rename appropriate file(s) to .FOR, then process file with ABACUS. If ABACUS is generating the .FOR files then these should be proper F77 .FOR files suitable for use by IVF.

Jim Dempsey
0 Kudos
JohnNichols
Valued Contributor III
3,452 Views
Ihave found the NOTEPAD++ editor is good for reviewing Fortran .FOR files. It does the syntax nicely and would show you your errors. It is free.

JMN
0 Kudos
j_clausen
Beginner
3,457 Views
Hi all

Regarding Abaqus and fixed/free form. In the file abaqus_v6.env you can find the compiler directives used for compiling Fortran source files to use with Abaqus. The line lookes like this:

compile_fortran=['ifort', '/c','/DABQ_WIN86_64', '/recursive', '/Qauto-scalar', '/QxW', '/nologo', '/Od', '/include:%I']

If you add the compiler directive /free to this line, you can use free form source code with Abaqus, e.g.

compile_fortran=['ifort', '/c','/DABQ_WIN86_64', '/recursive', '/Qauto-scalar','/free', '/QxW', '/nologo', '/Od', '/include:%I']

abaqus_v6.env is found in C:\\SIMULIA\\Abaqus\\6.10-2\\site

I never use the command line for compiling, so I don't know if any of the other directives could be changed to improve performance.

Unfortunately I never found a way to use modules with myFortran source code inAbaqus. Maybe some changes in the compiler directives can make this possible... Does anyone have any experience with this?

j_clausen
0 Kudos
mechprog
Beginner
3,456 Views
Thanks j_clausen

This is such a useful post for fortran-abaqus users. Thanks for taking the time to post this. I am assuming you need to select either fixed or free format and stick with that?

With regards to the use of modules, do you mean developing functions or subroutines within the primary subroutine? I am not sure about that? I am having enough of a challenging dealing with one subroutine alone :-) I look also forward to input from others on this.
0 Kudos
j_clausen
Beginner
3,456 Views
What I was thinking about regarding usingmodules with my Abaqus-Fortran sources: As it is now, all the subroutines I use with Abaqus are gathered in a single file which is not a module (i.e. the first line is not "module module_name"). This means that the Fortran compiler does not do interface checking, which has caused me quite some trouble over the years. I have now begun to add explicit interfaces, but that is hell to maintain, as I call a lot of subroutines from within other subroutines.

So a question I have is if anyone outthere have managed to use modules from Abaqus?

Another thing: Do any of the Fortran Experts out there have any general comments on the default compiler directives used in Abaqus (shown in my previous post). Do they look good for the task, or are any of them odd?

Best regards
j_clausen
0 Kudos
Arjen_Markus
Honored Contributor II
3,456 Views

I am no expert on Abaqus, but a workaround (if I understand the interfacing correctly) would be:

module your_modules

... all the code you need in one or more modules

end module your_modules


subroutineentry_from_abaqus( ...)

use your_modules

... thin layer tocall the module procedures

end subroutine entry_from_abaqus

(Adjust for fixed form or use the compile option to treat .for files as free form)

The basic idea is to let Abaqus call a subroutine that lives outside any module which then
calls the routines that do live in modules. That way you get most of the benefits of modules.

Regards,

Arjen

0 Kudos
Reply