I have an old .f90 FORTRAN code (gfortran). I am trying to run the code from Visual Studio but I see some errors. I have the following tools/ compilers in my windows 7 64 bit system,
Visual Studio 2013 premium
Visual FORTRAN Compiler XE 14.0 Update 3
I could run the code(s) from the command prompt using gfortran compiler. I want to run the same code in visual studio so that I can edit and debug the code easily (I am new to Visual Studio though).
I added the below in the Visual studio directory in Tools > Options > Intel Composer XE > Visual Fortran > Compilers,
I couldn’t open the .f90 script in visual studio (File > Open > Project) as it is not seeing any .f90 files from my folder. But I could create new FORTRAN .f90 code (File > New > Project >Intel ® Visual Fortran > Console Application > Main Program Code) and execute “Hello World” program successfully. I tried copy the main code and overwrite the hello world program with the main code and added all the other files path from Project > Add Existing Item, and below are the errors I got,
Error 1 error #8284: If the actual argument is scalar, the dummy argument shall be scalar unless the actual argument is of type character or is an element of an array that is not assumed shape, pointer, or polymorphic. [XNEW] C:\Users\S267564\Desktop\sCO2 Codes\sel_sco2_brayton_model\Netlib\subplex\simplx.f 161
Error 2 error #8284: If the actual argument is scalar, the dummy argument shall be scalar unless the actual argument is of type character or is an element of an array that is not assumed shape, pointer, or polymorphic. [XNEW] C:\Users\S267564\Desktop\sCO2 Codes\sel_sco2_brayton_model\Netlib\subplex\simplx.f 175
Error 3 Compilation Aborted (code 1) C:\Users\S267564\Desktop\sCO2 Codes\sel_sco2_brayton_model\Netlib\subplex\simplx.f 1
Error 4 error #7421: A constant or general expression must appear in a format list in this context. [AI] C:\Users\S267564\Desktop\sCO2 Codes\sel_sco2_brayton_model\example_fortran_program.f90 91
Error 5 error #6185: This constant is out-of-range in a format list.  C:\Users\S267564\Desktop\sCO2 Codes\sel_sco2_brayton_model\example_fortran_program.f90 91
Error 6 error #6181: An extra comma appears in the format list. [,A,F] C:\Users\S267564\Desktop\sCO2 Codes\sel_sco2_brayton_model\example_fortran_program.f90 91
Error 7 error #7421: A constant or general expression must appear in a format list in this context. [AI] C:\Users\S267564\Desktop\sCO2 Codes\sel_sco2_brayton_model\example_fortran_program.f90 95
Error 8 error #6185: This constant is out-of-range in a format list.  C:\Users\S267564\Desktop\sCO2 Codes\sel_sco2_brayton_model\example_fortran_program.f90 95
Error 9 error #6181: An extra comma appears in the format list. [,A,F] C:\Users\S267564\Desktop\sCO2 Codes\sel_sco2_brayton_model\example_fortran_program.f90 95
Error 10 Compilation Aborted (code 1) C:\Users\S267564\Desktop\sCO2 Codes\sel_sco2_brayton_model\example_fortran_program.f90 1
I don’t understand the errors while it is successfully running in command prompt using gfortran compiler.
Please help me to find the errors. Also please advise me why I couldn’t able to open .f90 file directly in visual studio (File > Open > Project).
Without actually seeing the code it is impossible for us to explain the error you are seeing. From the error text I can only guess that there is a mismatch in the actual and dummy arguments. The reason that gfortran may accept the code and Intel Fortran does not is, that Intel Fortran has a feature where the interfaces are automatically generated. This enables the compiler to do more extensive error checking. Older code used to assume a lot of things that nowadays is flagged as unsafe.
To make some progress, please show the relevant code.
Your first two errors were there because you used a scalar as a placeholder actual argument for an array dummy argument. This kind of thing was common in f77 days when there was no such thing as OPTIONAL arguments, or explicit interfaces that enabled the programmer to deploy them. But ifort was able to catch it; I don't know if gfortran can do so across different files. The solution I would recommend is to change 'dum' to 'dum(1)' in the 3 places it occurs in simplx.f. The first place, in line 81, declares dum as an array instead of a scalar, and the other two places, at lines 162 and 176, it passes an element of the array, which is OK as both a scalar dummy argument or an array dummy argument through the magic of sequence association.
The last set of errors was there because you had "AI0" instead of "A,I0" in a format list. Go back and compile
gfortran -c -std=f2008 example_fortran_program.f90
and gfortran will give you a nice error message about that.
call newpt (ns,-beta,s(1,icent),s(1,itemp), .false.,dum,small) ... subroutine newpt (ns,coef,xbase,xold,new,xnew,small) integer ns double precision coef,xbase(ns),xold(ns),xnew(*) logical new,small ------ call newpt ( ns, ! integer ns -beta, ! double precision coef s(1,icent), ! *** double precision xbase(ns) s(1,itemp), ! *** double precision xold(ns) .false., ! logical new dum, ! *** double precision xnew(*) small) ! logical small
The lines marked with *** are passing in scalar references instead of array references
You could turn off interface checking, but I strongly suggest you correct the call statements
double precision dumArray(ns) call newpt ( ns, ! integer ns -beta, ! double precision coef s(1:ns,icent), ! double precision xbase(ns) s(1:ns,itemp), ! double precision xold(ns) .false., ! logical new dumArray, ! double precision xnew(*) *** not used with new==.false. small) ! logical small
Thank you for your advice. I have changed the "AI0" of "A,I0" in example_fortran_program.f90, changed the dum to dum(1) in both subplx.f (line # 100,194) and simplx.f (line # 81,162,176).
I got the below three errors after these corrections. I think the reason for these errors are also similar however I am not sure how to rectify. It would be great if you can help me to change the following two lines in subplx.f
call dcopy (n,scl,0,work,1)
call dcopy (n,scl,0,work(istptr),1)
Error 1 error #8284: If the actual argument is scalar, the dummy argument shall be scalar unless the actual argument is of type character or is an element of an array that is not assumed shape, pointer, or polymorphic. [DX] C:\Users\S267564\Desktop\Final_sco2\sel_sco2_brayton_model\Netlib\subplex\subplx.f 168
I believe that it is probably a waste of time for you to take old Fortran 77 codes from Netlib and other code that is known to work correctly and then check them for correct interface usage. Simply turn off interface checking in your project settings. I compiled all your source files at the command line using IFort 16.0.4. The program ran and gave cycle efficiency = 0.465.
Let's see... hopefully you also changed 'dum' to 'dum(1)' in subplx.f. But that error with DX looks like a bad one. Try changing
call dcopy (n,scl,0,work,1) call dcopy (n,scl,0,work(istptr),1)
if(n > 1) then write(*,*) 'Big problem here...' stop end if call dcopy (n,[scl],0,work,1) call dcopy (n,[scl],0,work(istptr),1)
If the program stops with the error above printed out, something has to be fixed. Otherwise it will be OK.
EDIT: I just checked and there are other places where this usage happens. I you want, try fixing them one by one until the errors stop.
Because you are new to Fortran, you might not quite understand why [scl] works where scl without square brackets does not. In Fortran 's are used as an array constructor: [1,2,3] constructs a nameless array of integers, [A, 1.2, B] constructs an array of real (assuming A and B are real).
The error message you received for this statement was the same as what I posted in #5. It is an exercise for yourself to make correlations of mismatched arguments and correct in a similar manner.
I would also add to Jims comment at #9 that any array constructed with  within a call statement is a temporary so it can be used within the call but cannot be modified or passed back in any way.
As you had to do with DUM in simplx.f, you may change the declaration of SCL to SCL(1) in subplx.f.
There is a subtle error in module_CO2_properties.f90, on line 94. At present you have
real(dp), parameter :: P_upper_limit = 60000_dp
If your Fortran compiler uses kind numbers for integers and reals with overlap, for example, dp = 2, the constant 60000_2 will be seen as INTEGER(KIND=2); if the corresponding INTEGER type is a 2-byte integer, 60000 > 32767, so integer overflow will occur!
To avoid all these problems, add a decimal point, making line 94 become
real(dp), parameter :: P_upper_limit = 60000._dp
Thank you for all your responses.
I finally fixed the problem by changing the dummy to an array as suggested.
It would be great if someone can help me on the reason for not being able to open the .f90 file directly from the folder (always I am opening a new project and replacing the default hello world program with the main script)
Is it something to do with the visual studio settings?
Thank you for your response.
I see the files in the solution explorer after I manually add all the relevant files to the project (i created a new project and replaced the content of default program with my main program code). But the thing is that I couldn't open the main script from the visual studio by using File > Open>Project/solution as it is not showing any .f90 files. (it is looking *.vfproj type files).
Can I open the existing code (.f90) directly to the visual studio?
If you right click on the project (vfprodj) entry in solution explorer and then from the pop up menu add>existing files > and then pick the fortran files. they become part of the project then and edit by clicking on them in solution explorer.
The hierarchy might be confusing here. Let me give you a very basic description (for you experts out there, yes, I'm simplifying!)
A "solution" contains one or more projects, and is stored in a file with extension .sln.
A "project" tells how to build something tangible, such as an executable or shared library. A project contains one or more source files that are compiled into that tangible output. A project also contains all the command line options that are required to build the source files. Projects are stored in files with the extension .vfproj.
Finally, your source code is in a "file". You can add those into a project using the Project->Add New Item or Project->Add Existing Item option from the menu.
if you simply want to look at a file, but not include it in your project (for example, if it's a data file or a README) you can use File->Open->File to open that file.
I hope this helps --
One thing that often confuses newcomers to Visual Studio is that simply opening a file in VS isn't enough to build it into an application. As Lorri says, you need to create a project (of the appropriate Fortran application type, "Console Application" is most common) and add the file to the project. If you just open or create a source file, outside of a project, and try to build it, nothing will happen.
If you have an existing source, the typical workflow is to create a new, empty project of the right kind and then add your source to it. You can do the add with Project > Add to project > Files..., or you can simply drag-and-drop the source files from a Windows Explorer window onto the "Source Files" icon in "Solution Explorer" in Visual Studio.
Another way to do it from scratch is File > New > Fortran Project from Existing Code. This can be handy if you have a large number of files to add. Your choices are a bit more limited here - "Application" creates a Console Application. There's also DLL and Static Library.
Lastly, if you just want Windows to open a Fortran file in Visual Studio so that you can see it, this is usually set by default when you install Intel Parallel Studio but sometimes you have to fix it up yourself. Right click on a Fortran file (.f, .f90, etc.) Select Open With > Choose another app. If it shows the default as "" /dde, leave it as it is as that should work if you just double-click the source file to open it. Otherwise you can select the Visual Studio version you want and check the box to make that the default.
I prefer to think of Solutions as a collection of related projects which, when built together, create some sort of deliverable (application or library.)