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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compiling

Status
Not open for further replies.

Nusc

Programmer
May 9, 2015
11
CA
Hi all, it's been a long time since I touched Fortran.

I am trying to compile old Fortran (.f) files.

I am using Gygwin executing the following command:

gfortran -ffree-form -o filename.exe filename.f

I get the following error over 25 times:

Error: Unclassifiable statement at (1)

I'm not sure what's wrong. If you can help me out that would be great.

Thank you!

 
If I want to pause the running code, what is the command to do this? They took out the PAUSE function.
If you are on windows you can use the pause command using the fortran system() subroutine
Code:
C:\>help pause
Suspends processing of a batch program and displays the message
    Press any key to continue . . .

For example: look at the subroutine subr_pause in the program tstread.f95 in this thread
 
If ou are on Unix or Linux, you could use this read command in the fortran system() subroutine:
Code:
$ read -p "Press ENTER to continue ..."
 
I just want to enter a pause statement in the code without using terminal so I can verify values for variables, etc. Like the use of the exclamation mark in MATLAB.

Is there no such thing?
 
Btw in gfortran pause works.

I get only the warning from the compiler
Code:
$ gfortran pause_test.f95 -o pause_test
pause_test.f95:13.7:

  pause
       1
Warning: Deleted feature: PAUSE statement at (1)

But when I run the program it works so:
Code:
$ pause_test
 Doing j =           1 ...
 Doing j =           2 ...
 Doing j =           3 ...
 Doing j =           4 ...
 Doing j =           5 ...
 Doing j =           6 ...
 Doing j =           7 ...
 Doing j =           8 ...
 Doing j =           9 ...
 Doing j =          10 ...
[COLOR=blue]PAUSE
To resume execution, type go.  Other input will terminate the job.[/color]

and now when I type go then the program continues...

Code:
 ...
 Doing j =          10 ...
[COLOR=blue]PAUSE
To resume execution, type go.  Other input will terminate the job.
[b]go[/b][/color]
RESUMED
 Doing j =          11 ...
 Doing j =          12 ...
 ...
 
Nusc said:
I just want to enter a pause statement in the code without using terminal so I can verify values for variables, etc. Like the use of the exclamation mark in MATLAB.

Without using terminal ?
And how do you want to verify the values of the variables?
IMO the simplest way is writing their values to the terminal ...
As you have seen above the original deprecated pause statement used terminal too.

I don't know what is exclamation mark in MATLAB :)

Is there no such thing?
Yes, there are more options, how to do it and they are easy to code.
Here I have 3 subroutines, which work with my Mingw/MSYS gfortran compiler:

pause_test
Code:
[COLOR=#a020f0]program[/color] pause_test
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
  
  [COLOR=#2e8b57][b]integer[/b][/color] :: j

  [COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], [COLOR=#ff00ff]10[/color]
    [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Doing j ='[/color], j, [COLOR=#ff00ff]'...'[/color]
  [COLOR=#804040][b]end do[/b][/color]
  [COLOR=#0000ff]! pause[/color]
  [COLOR=#008080]call[/color] pause_fortran([COLOR=#ff00ff]"Press <ENTER KEY> to continue ..."[/color])
  [COLOR=#008080]call[/color] pause_windows
  [COLOR=#008080]call[/color] pause_unix
  [COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]11[/color], [COLOR=#ff00ff]20[/color]
    [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Doing j ='[/color], j, [COLOR=#ff00ff]'...'[/color]
  [COLOR=#804040][b]end do[/b][/color]   
[COLOR=#a020f0]end program[/color] pause_test

[COLOR=#a020f0]subroutine[/color] pause_windows
  [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] pause_windows

[COLOR=#a020f0]subroutine[/color] pause_unix
  [COLOR=#2e8b57][b]integer[/b][/color] :: cmd_rc [COLOR=#0000ff]! command return code[/color]
  [COLOR=#2e8b57][b]character[/b][/color]([COLOR=#ff00ff]80[/color]) :: cmd_string
  [COLOR=#0000ff]! this should work in Unix[/color]
  [COLOR=#0000ff]!cmd_string = 'read -p "Press ENTER to continue ..."'[/color]
  [COLOR=#0000ff]! this works in MingW / MSYS[/color]
  cmd_string [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'sh -c "read -p \"Press ENTER to continue ...\""'[/color]
  [COLOR=#008080]call[/color] system (cmd_string, cmd_rc)
[COLOR=#a020f0]end subroutine[/color] pause_unix

[COLOR=#a020f0]subroutine[/color] pause_fortran(prompt)
  [COLOR=#2e8b57][b]character[/b][/color]([COLOR=#804040][b]*[/b][/color]), [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: prompt
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(A)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) prompt
  [COLOR=#804040][b]read[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])
[COLOR=#a020f0]end subroutine[/color] pause_fortran


Output:
Code:
$ gfortran pause_test.f95 -o pause_test

$ pause_test
 Doing j =           1 ...
 Doing j =           2 ...
 Doing j =           3 ...
 Doing j =           4 ...
 Doing j =           5 ...
 Doing j =           6 ...
 Doing j =           7 ...
 Doing j =           8 ...
 Doing j =           9 ...
 Doing j =          10 ...
Press <ENTER KEY> to continue ...
Press any key to continue . . .
Press ENTER to continue ...
 Doing j =          11 ...
 Doing j =          12 ...
 Doing j =          13 ...
 Doing j =          14 ...
 Doing j =          15 ...
 Doing j =          16 ...
 Doing j =          17 ...
 Doing j =          18 ...
 Doing j =          19 ...
 Doing j =          20 ...







 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top