INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Compiling

Compiling

(OP)
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!

RE: Compiling

Can you show us a bit of code? Maybe the first 10 lines where the error is happening

Have you got tabs or spaces in the code?

Are you sure you want to use -ffree-form? That is for F90 type programs.

RE: Compiling

(OP)
I believe the issue comes with the existing comments:

c ---

c --- blah

c --- blah

c --- blah

c --- blah

c ---


Do you know if the original files were compiled in F77 F90 or F95?

I'm using gfortran.

RE: Compiling

Looks like F77. In that case remove -ffree-form and you should be OK.

In F90, the comment character is !. In F77, a comment is any character in column 1. So you could have

CODE

One day this will work 
as a comment, as long as it starts in column 1.

RE: Compiling

(OP)
Hi xwb,

thanks for your help.

That seems to have resolved some of the errors, now I receive the following messages:

filename.f:42.72:

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


What does this warning show?


Another error apepras
filename.f:427.19:

subroutine function(x,y)
2
Error: COMMON block 'function' at (1) uses the same global identifier as entity at (2)


Thanks

RE: Compiling

The two message are quite explicit :

- PAUSE is an old statement which does not belong to the language anymore. But this is just a warning...

- you cannot have simultaneously a subroutine and a common block having the same name. This is really an error. Fix it please...

Fran├žois Jacq

RE: Compiling

(OP)
Hi FJacq,

from the above posts, this is a F77 program. I'm sure it worked at some point without error.

filename.f:427.19:

subroutine myownfxn(x,y)
2
Error: COMMON block 'myownfxn' at (1) uses the same global identifier as entity at (2)
---------------------------------------------------
Do I declare it as a subroutine or a function?

function myownfxn(variable1,variable2)
or
SUBROUTINE myownfxn(variable1,variable2)

What I am trying to do is integrate a function.

RE: Compiling

What it is telling you is that you have a function and a common block with the same name. It is possible that the original compiler was not as strict.

RE: Compiling

Could you please show us an exact piece of your source file including spaces : you have an icon enabling to display the source code correctly.

Fran├žois Jacq

RE: Compiling

(OP)
gfortran testcode.exe testcode.f

program HelloWorld
write (*,*) 'Hello, world!' ! This is an inline comment
end program HelloWorld

I get the following:

testcode.f:1.2:

program HelloWorld
1
Error: Non-numeric character in statement label at (1)
testcode.f:1.2:

program HelloWorld
1
Error: Unclassifiable statement at (1)
testcode.f:2.4:

write (*,*) 'Hello, world!' ! This is an inline comment
1
Error: Non-numeric character in statement label at (1)
testcode.f:2.4:

write (*,*) 'Hello, world!' ! This is an inline comment
1
Error: Unclassifiable statement at (1)
testcode.f:3.2:

end program HelloWorld
1
Error: Non-numeric character in statement label at (1)
testcode.f:3.2:

end program HelloWorld
1
Error: Unclassifiable statement at (1)

RE: Compiling

Do they start in column 7? In F77 the first 5 columns are for a statement label like a format statement the 6th column indicates a continuation and 7 and above is where the code goes.

Bill
Lead Application Developer
New York State, USA

RE: Compiling

(OP)
Does what start in column 7?

I am using Gedit, at the bottom right hand side it says Fortran 95.

There is no option for Fortran 77.

Do you advise indenting my code?

RE: Compiling

(OP)
So back to the other posts:

I should remove all the 'pause' statements and recompile without free form.

And back to the other error:
filename.f:395.16:

common/op/help,constant1,constant2,a1,b1,a2,b2,n2
1

I will paste part of the source code as expected:


subroutine function(id)

implicit real*8(a-h,o-z)

dimension help(900),xvariable(900),yvariable(900),constant1(900),constant2(900)

dimension fxn1(900),fxn2(900)

common/op/help,constant1,constant2,a1,b1,a2,b2,n2


The second error is:

filename.f:427.19:

subroutine function(k,conc1)
2
Error: COMMON block 'function' at (1) uses the same global identifier as entity at (2)

Source code:


subroutine function(k,conc1)

implicit real*8(a-h,o-k)

dimension help(600),c1(600),c2(600)

common/op/help,constant1,constant2,a1,b1,a2,b2,n2

Thirdly, I don't understand the line:

implicit real*8(a-h,o-k)

What is a-h and o-k?




RE: Compiling

(OP)

CODE --> FORTRAN

subroutine function(id)

implicit real*8(a-h,o-z)

dimension alt(900),xvariable(900),yvariable(900),constant1(900),constant2(900)

dimension fxn1(900),fxn2(900)

common/op/alt,constant1,constant2,a1,b1,a2,b2,n2 

gives:
filename.f:395.16:

common/op/alt,constant1,constant2,a1,b1,a2,b2,n2
1


CODE --> FORTRAN

subroutine function(k,conc1)

implicit real*8(a-h,o-k)

dimension alt(900),constant1(900),constant2(900)

common/op/alt,constant1,constant2,a1,b1,a2,b2,n2 

filename.f:427.19:

subroutine function(k,conc1)
2
Error: COMMON block 'function' at (1) uses the same global identifier as entity at (2)

xwb said the original compiler was not as strict. What must I do to remove these messages?

RE: Compiling

CHANGE THE NAME OF THE BLOCK OR THE FUNCTION. Your choice.

Bill
Lead Application Developer
New York State, USA

RE: Compiling

(OP)
I have removed all lines containing common and the code compiles.

#1. Is common a redundant feature?

#2. I get results but with error:

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:


#3.

write(6,*) '======================='
1
Error: Syntax error in WRITE statement at (1)

What's wrong with this statement? I have another line of code with the same syntax which does not produce an error.

RE: Compiling

You can't get rid of the common statements. They indicate a common variable memory location for the various routines. Just change one of the invalid block or function names to something else.

Bill
Lead Application Developer
New York State, USA

RE: Compiling

(OP)
If I want to pause the running code, what is the command to do this? They took out the PAUSE function.

RE: Compiling

Quote:


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
http://www.tek-tips.com/viewthread.cfm?qid=1662044

RE: Compiling

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 ..." 

RE: Compiling

(OP)
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?

RE: Compiling

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 ...
PAUSE
To resume execution, type go.  Other input will terminate the job. 

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

CODE

...
 Doing j =          10 ...
PAUSE
To resume execution, type go.  Other input will terminate the job.
go
RESUMED
 Doing j =          11 ...
 Doing j =          12 ...
 ... 

RE: Compiling

Quote (Nusc)


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 smile

Quote:


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

program pause_test
  implicit none
  
  integer :: j

  do j=1, 10
    write(*,*) 'Doing j =', j, '...'
  end do
  ! pause
  call pause_fortran("Press <ENTER KEY> to continue ...")
  call pause_windows
  call pause_unix
  do j=11, 20
    write(*,*) 'Doing j =', j, '...'
  end do   
end program pause_test

subroutine pause_windows
  integer :: cmd_rc ! command return code
  character(*), parameter :: cmd_string = "pause"
  call system (cmd_string, cmd_rc)
end subroutine pause_windows

subroutine pause_unix
  integer :: cmd_rc ! command return code
  character(80) :: cmd_string
  ! this should work in Unix
  !cmd_string = 'read -p "Press ENTER to continue ..."'
  ! this works in MingW / MSYS
  cmd_string = 'sh -c "read -p \"Press ENTER to continue ...\""'
  call system (cmd_string, cmd_rc)
end subroutine pause_unix

subroutine pause_fortran(prompt)
  character(*), intent(in) :: prompt
  write(*,'(A)',advance='no') prompt
  read(*,*)
end subroutine 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 ... 







Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close