- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
Link Copied
11 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
If you are using another compiler, well, then tell us what it is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That means that you have two main programs, and you may have only one. You probably have something like:
FILE1.f90
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.
FILE1.f90
[fortran]Program free .. call fix ... end [/fortran]FILE2.for
[bash]Program something ... end subroutine Fix ... endYou should get rid of the second PROGRAM block.
[/bash]
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:

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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page