My boss passed me some Fortran code and wanted me to add some new features to it. He initially used Fortran 90 under the Compaq fortran compiler. All the source files are .F90 files. It used IMSL but I have to wait a while before IMSL can be installed on my computer. I tried to see how far I can go but got a lot of errors not related to IMSL. Here are the problems I found and I am seeking advice.
1. The files has project files with extension .dsp and .dsw. When I tried to open the .dsp or .dsw, a dialog box said 'The project file .dsp has been corrupted and cannot be opened'.
2. So I build a 'solution' and under the solution a 'project'. Then I add all the .F90 files under the 'Source Files'. After that, I add the source file folder to the 'Libraries' and 'Includes' at Tools->Options->Intel Visual Fortran->Compilers. Then I hit the 'Build Solution'. At the Output window, I saw following output:
1>------ Rebuild All started: Project: proj1, Configuration: Debug Win32 ------ 1>Deleting intermediate files and output files for project 'proj1', configuration 'Debug|Win32'. 1>Compiling with Intel Visual Fortran 11.1.048 [IA-32]... 1>tr.f90
and the output window froze at this step. If I click Build->Cancel there will be a lot of error lines in the output window. One of the typical errors I found is that: 1>\\tr.f90(49): error #7002: Error in opening the compiled module file. Check INCLUDE paths. [MDEFAULTS]
The line 49 of tr.f90 is: 49 USE MDEFAULTS !program wide default parameters, common.f90
The solution I found is to right click on common.f90 and choose 'Compile'. If I compiled the common.90 first, then there is no the above error. Additionally I reorganized the source code by moving the position of a specific module in a file (There are several modules in a .f90 file, is this allowed and to be concerned?) to correct errors like: math.f90(1221): error #5515: Declaration of module 'ABCD' comes after the use of that module. A module's declaration must precede its use.
I am new to Fortran, is there a compiling order for the source code files in a project? Does the Module declaration has to appear before the 'USE' statement? If there is and order, how do I arrange the files in the order? Thanks.
As I noted above, and as the compiler properly complained, the language requires that the target of a pointer assignment either be a pointer itself or have the TARGET attribute. Here, ABCD is not a POINTER nor does it have TARGET, nor is component EF a pointer. (A component cannot be given the TARGET attribute directly.) The simplest solution is to change the declaration of ABCD to:
TYPE(ABCDTYPE), INTENT(INOUT), TARGET :: ABCD
However... because ABCD is a dummy argument, adding the TARGET attribute requires that the caller of the procedure have an explicit interface visible for the procedure. So let's say ABCD is an argument of subroutine SUB1. The caller of SUB1 must be able to see an explicit interface for SUB1. The explicit interface may come from SUB1 being in a module, or being a contained procedure, or there may be an INTERFACE block for SUB1 that the caller can see. So if there is not an existing explicit interface, you will have to add one.
Again, this is a situation where CVF did not detect your error but Intel Fortran did.
Take out the source file folder where you added it under "Libraries" and "Includes". It doesn't belong there. Libraries is for additional locations of .lib files used by the linker, and Includes is for additional locations for include and module files. If you create a new project and add Fortran sources to it, the modules created by compiling those sources is automatically used.
You should not have to define the compilation order - just make sure that if a module and USE of that module are in the same source file, that the module comes first.
After you correct the erroneous addition of directories, try a Build > Clean Solution, then Build > Rebuild and see if that solves the problem.
.dsp/.dsw files are from Compaq Visual Fortran. Sometimes that error about them being corrupted occurs and the simplest thing is to do what you did and create a new project.
Steve, Thanks for the advice. I removed the source code folders I added into the 'Libraries' and
'Includes' and it did not worsen the case. I still stuck at the exact same errors. I looked at the Debug folder and found that the tr.obj (the same tr.f90 in initial post) is 0 Kb. Looks like I have to compile all the .f90 files whose modules was used in the tr.f90 and create the corresponding valid (>0kB) .obj file before I can pass the compiling of tr.f90. I am new to Fortran, so is it possible that the source code used a obsolete grammar? Or should I split the source code files so that each one f90 file contains only one module? Another thought is that all .f90 files together is about 900kB. How long will the fortran compiler take to compile it? The longest I waited was 3~5 minutes, and could it be too short for the compiler to finish the job? The compiler has nothing new to output for such long makes me feel something goes wrong and I just canceled it every time.
900KB is certainly a large file - 3-5 minutes is not unreasonable to compile a file that size. I do recommend splitting each module into its own source. Try that and see how it goes. It may be that the way your sources are constructued are such that the compiler can't determine a proper build order.
Steve, I upgraded the compiler from 11.1.048 to 11.1.067, installed the IMSL and made the setting change according to the IMSL release code. The compiler does not freeze anymore. I believe it is the new version of the compiler that solved the problem. Now I continue to deal with the incompatibility grammar between compaq fortran and intel. Thanks for your help.
Steve, I am very new to Fortran and I am still learning it. So far this is the first one:
1. MODULE MPCH lines of codes ...... ENDMODULE MPCH
USE MPCH
I found that if the 'USE MPCH' above the 'MODULE MPCH', I would have the error "error #5515:
Declaration of module 'MPCH' comes after the use of that module. A module's
declaration must precede its use." In the Compaq fortran, there is no such issue.
I am still working one the second imcompatibility to singulate the code out. Will post after I've done so.
This is a case of Compaq Fortran not warning you of a mistake but Intel Fortran does. In Compaq Fortran, what you would silently get is the module from an earlier compilation. We added an error to alert you to this.
The Intel compiler is derived from the same Fortran-language processing code as the Compaq compiler, so any correct Fortran program accepted by the Compaq compiler will be accepted by the Intel compiler. We have added a lot in the way of error detection, which may give you issues if you have coding errors.
Steve, The last errors I understand. But this one I have no clue at all. In the following line, ABCD is a structure, EF is an element, ABCDEF is a pointer of EF type.
ABCDEF => ABCD%EF
error #6796: The variable must have the TARGET attribute or be a subobject of an object with the TARGET attribute, or it must have the POINTER attribute. [ABCD]
Do you know what is the reason or where I should check for the problem?
As I noted above, and as the compiler properly complained, the language requires that the target of a pointer assignment either be a pointer itself or have the TARGET attribute. Here, ABCD is not a POINTER nor does it have TARGET, nor is component EF a pointer. (A component cannot be given the TARGET attribute directly.) The simplest solution is to change the declaration of ABCD to:
TYPE(ABCDTYPE), INTENT(INOUT), TARGET :: ABCD
However... because ABCD is a dummy argument, adding the TARGET attribute requires that the caller of the procedure have an explicit interface visible for the procedure. So let's say ABCD is an argument of subroutine SUB1. The caller of SUB1 must be able to see an explicit interface for SUB1. The explicit interface may come from SUB1 being in a module, or being a contained procedure, or there may be an INTERFACE block for SUB1 that the caller can see. So if there is not an existing explicit interface, you will have to add one.
Again, this is a situation where CVF did not detect your error but Intel Fortran did.