Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

Using a fixed-form program inside a free-form program

taataa
Beginner
2,797 Views
I chose free-form (*.f90) for my program, and now I have to join it with another program which uses fixed-form (*.for). I have 2 ways: I can use my program as a subroutine in this program or I can use a new program and join them as subroutines, and of course with some changes in both, as they include iterative process.
This program has about 7000 lines, thus converting it to free-form needs a program itself! Also my program has about 4000 lines.
I want to know is there way that I can do this? Maybe something like using fix-form program file as an external subroutine or something like it.
For clearance let me explain my algorithm simply: (let's call the fixed-form program FIX and my program FREE)
1- input data
2- Call INITIAL (some initial processes for creating geometry and initial conditions)
3- In each time step process is something like this:
1- Call FIX (outputs are arrays)
2- Call FREE (some of Inputs are outputs of FIX)
3- Call PRINT

It's not this simple but something like it.
0 Kudos
11 Replies
mecej4
Honored Contributor III
2,797 Views
I think that you have paid undue attention to the format of the source code.

You may break up the code into several files, some of which may be fixed format and some free format. Each file must be either fixed or free format in its entirety, and may contain any number of modules and subprograms, but with one restriction: there may be only one main program, regardless of file format. In particular, having one main program in a fixed format file and another main program in free format is prohibited.

Thus, there is absolutely no need to convert from fixed to free or vice versa.

However, if you wish to do the conversion nevertheless, there are a few tools available,e.g., Michel Olagnon's.
0 Kudos
TimP
Honored Contributor III
2,797 Views
If you don't use the file suffix method of specifying which file is free or fixed format, you must compile the free and fixed format files separately. There aren't many compilers left which can't handle a mixture of .f (or .for) fixed format and .f90 free format in a single compile command, if that's your goal.
0 Kudos
taataa
Beginner
2,797 Views
mecej4 thanks for your quick answer.
I want to know how to link a file and call them in program, therefore I can compile them togather.

Thanks for the program, I will try to find it.
0 Kudos
taataa
Beginner
2,797 Views
tim18 thanks for your quick answer.
like I said I want to know if there is way for linking to FIX file in my free-form program, so it just act like a subroutine that I can call it but it compiles separately.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
2,797 Views
If you are using Intel Visual Fortran in Visual Studio, just add both (.f90 and .for) source files to the project (Project/Add new item...), and build the solutin.

If you are using another compiler, well, then tell us what it is.
0 Kudos
taataa
Beginner
2,797 Views
Jugoslav Dujic I'm using latest version of Intel Visual Fortran (64 bit), I added these files, but I have 2 questions:
1- when I add these file to source files, after compileing two errors shown:
1- error LNK2005: MAIN__ already defined in FREE.obj
2- fatal error LNK1169: one or more multiply defined symbols found
2- If I can succefully join the FIX file to mine (FREE), how can I call it?
Press ENTER to look up in Wiktionary or CTRL+ENTER to look up in Wikipedia
0 Kudos
Les_Neilson
Valued Contributor II
2,797 Views
Quoting taataa
Jugoslav Dujic I'm using latest version of Intel Visual Fortran (64 bit), I added these files, but I have 2 questions:
1- when I add these file to source files, after compileing two errors shown:
1- error LNK2005: MAIN__ already defined in FREE.obj
2- fatal error LNK1169: one or more multiply defined symbols found
2- If I can succefully join the FIX file to mine (FREE), how can I call it?
Press ENTER to look up in Wiktionary or CTRL+ENTER to look up in Wikipedia

You misunderstood what Jugoslav is saying.

It is Visual STUDIO where you can mix the files together.

Are you using Microsoft Visual Studio as your development environment?
Or are you building from the command line (or using amakefile) ?

Les
0 Kudos
Jugoslav_Dujic
Valued Contributor II
2,797 Views
That means that you have two main programs, and you may have only one. You probably have something like:

FILE1.f90
[fortran]Program free
..
call fix
...
end
[/fortran]
FILE2.for
[bash]Program something
...
end

subroutine Fix
...
end
[/bash]
You should get rid of the second PROGRAM block.

Note that keyword "PROGRAM" may be omitted (although I think it is an ugly style) -- if you have just a piece of code without any heading, it is treated as a main program.
0 Kudos
taataa
Beginner
2,797 Views
Neilson, yes I use visual studio. When Jugoslav said tha I can add file to my program, I added it like shown in the picture, in sources:
My Program Structure
VOF WISE is my Program which I used free-form. and WISE is the program that later I had to use it in my program and is in the fix-form.
Jugoslav if I can add link WISE successfully, my program structure will have a structure like this:

Program VOF_WISE
....
Do Step=1, N
Link to WISE(I don't know the command)
......
Call VOF
......
Call PRNT
End Do

Contains
Subroutine VOF
.....
End

.....

Subroutine PRNT
.....
End

My program structure is in this form except calling WISE.
Press ENTER to look up in Wiktionary or CTRL+ENTER to look up in Wikipedia
0 Kudos
Les_Neilson
Valued Contributor II
2,797 Views
If I understand correctly then all you need to do is :
replace "Link to WISE" with a call to whatever it is in wise you wish to call
call wise(...)
it's as simple as that - or should be :-)

BUT if, as Jugoslav pointed out, your wise.for contains a "main" program then you will have to change it to a subroutine that can be called.

It would help us if you could attach the file wise.for

Les
0 Kudos
taataa
Beginner
2,797 Views
Neilson
Thanks a lot, for your suggestion, I think it'll work, I substitute "program" in WISE to "subroutine" and the errors solved. Now I'm working on it, to get the right output data.
0 Kudos
Reply