Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to Intel Fortran 9.1 and Visual Studio 2005 4

Status
Not open for further replies.

MechProg

Technical User
Oct 4, 2010
6
GB
Hello all,

I am new to programming and fortran, I have Intel Fortran 9.1 and using this via Microsoft Visual Studio 2005. To start with I have found a simple exmaple from the a Intel Fortran 90 book. I seem to be able to run a debug, but can't seem to create an executable? Its my first time using Visual Studio and Fortran. Any help would be appreciated.

PROGRAM Sum_and_Average
!
! This program reads in three numbers and sums and averages them
!
IMPLICIT NONE
REAL :: N1,N2,N3,Average = 0.0, Total = 0.0
INTEGER :: N = 3
PRINT *, 'Type in three numbers, seperated by spaces or commas'
READ *,N1,N2,N3
Total= N1+N2+N3
Average=Total/N
PRINT *,'Total of numbers is ',Total
PRINT *,'Average of the numbers is ',Average
END PROGRAM Sum_and_Average

For example the Intel Visual Fortran Compiler Documentation provides this information, but no more on how to do this... can anyone help?

"Creating Fortran Executables
The simplest way to build an application is to compile all of your Intel® Fortran source files and then link the resulting object files into a single executable file. You can build single-file executables using the ifort command from the command line. For Windows*, you can also use the visual development environment.

The executable file you build with this method contains all of the code needed to execute the program, including the run-time library. Because the program resides in a single file, it is easy to copy or install. However, the project contains all of the source and object files for the routines that you used to build the application. If you need to use some of these routines in other projects, you must link all of them again.

Exceptions to this are as follows:

If you are using shared libraries, all code will not be contained in the executable file.

On Mac OS* X, the object files contain debug information and would need to be copied along with the executable."

 
Can anyone offer any advice on this? Thanks
 
Sorry : I don't use Microsoft Visual Studio.

But if you want to test your program without Visual studio, then I could help you a little bit.

Open a command window (in running the instruction "cmd.exe")

In that window, you have to got to the right directory containing the source file, and you can compile, link and run your program as follows :

Code:
cd c:\soure_directory
ifort Sum_and_Average.f90
Sum_and_Average

Possibly, the command ifort is unknown at this stage. If you get a message like "ifort : command not found", then you have to activate it as follows (always in the command window) :

Code:
call "c:\program files\intel\compiler\fortran\9.1\ia32\bin\ifortvars.bat"

And then try again the ifort command.

Check also that the file "ifortvars.bat" exists in your file system. Possibly, the intel software is not installed exactly at the location I have provided.

At last, it is possible to create a shortcut for "cmd.exe" activating automatically the Fortran Compiler when opening the command window.
 
First create a project

File/New Project

In the dialog box, select Fortran, choose a console project

Give the project a name etc. and click OK.

Either modify the example program given or delete the example program and add in your own. Then from the menu, select build followed by Build Solution and that's it.

This will create the executable in the project directory/Debug. You can create an optimized version by choosing to build the Release version. That will go into the project directory/Release.

 
Thank-you so much FJacq and xwb. The info from xwb was very helpful and worked.

Only one other thing, when ever I run the executable and run the programme, when I type the numbers and press enter the executable immediately closes down, do I need another line of code to print out the answer and then stay open? What would this code be?

Thanks again
 
A quick-'n'-(very)-dirty way of doing it would be to add the following to the part of the code where you want it to pause:

Code:
read *

I'm not sure that would work with all compilers, though.

Effectively, it just waits for user input before carrying on, and it "reads" an input value, but doesn't do anything with it.

--------------------------------------
Background: Chemical engineer, familiar mostly with MATLAB, but now branching out into real programming.
 
Yes, it actually works thanks, but I wonder that the other codes are for this?
 
Hi MechProg and NickFort

The "pause" statement should do the same thing, and is not as "quick-'n'dirty" as "read *"
 
When I replace READ * with PAUSE *, I get build errors.
 
HI MechProg

"Pause *" is incorrect, use only "Pause".
The pause statement is an old Fortran statement and still works on most compilers ... I think.
 
That works, thanks, except now I have a message in my executable which says

"Fortran Pause - Enter command<CR> or <CR> to continue"

Not sure how do get rid of that?
 
You may try

PAUSE 'My text here'

I vaguely remember that PAUSE has been taken away from the fortran standard. I think it doesn't work anymore in some free compilers like gfortran.

Why should PAUSE be more elegant than

WRITE(*,*)'My text here'
READ(*,*)

anyway?
 
Pause" is a deleted feature as for Fortran 95 ( -- I'm sure that most compilers still support it, but what is the new official way of doing this? There must be some sort of modern Fortran replacement for it.

--------------------------------------
Background: Chemical engineer, familiar mostly with MATLAB, but now branching out into real programming.
 
* "as of", not "as for" in my post above.

What I would like is a "Press any button to continue" sort of feature. With "read *", you must press return/enter/whatever you want to call it.

--------------------------------------
Background: Chemical engineer, familiar mostly with MATLAB, but now branching out into real programming.
 
Hm, I did that decades ago in Pascal and used a library for it.

What you are looking for is something called GetKey or InKey or so and it's not standard fortran. Some compilers have something like that included, but it would be compiler dependent of course.

 
GerritGroot said:
You may try
PAUSE 'My text here'..
NickFort said:
"Pause" is a deleted feature ..
OK, when pause is no more available in Fortran, you can use pause from your favorite OpSys. For example in Windows this works:
Code:
[COLOR=#a020f0]program[/color] [COLOR=#804040][b]pause[/b][/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Hello World'[/color]
  [COLOR=#008080]call[/color] subr_pause 
[COLOR=#a020f0]end prograM[/color] [COLOR=#804040][b]pause[/b][/color]

[COLOR=#a020f0]subroutine[/color] subr_pause
  [COLOR=#2e8b57][b]integer[/b][/color] :: cmd_rc [COLOR=#0000ff]! command return code[/color]
  [COLOR=#2e8b57][b]character[/b][/color]([COLOR=#804040][b]*[/b][/color]), [COLOR=#2e8b57][b]parameter[/b][/color] :: cmd_string [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"pause"[/color]
  [COLOR=#008080]call[/color] system (cmd_string, cmd_rc)
[COLOR=#a020f0]end subroutine[/color] subr_pause
Code:
$ g95 pause.f95 -o pause
$ pause
 Hello World
Press any key to continue . . .
 
$
[/code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top