Help with fortran code

  • Fortran
  • Thread starter 1994Bhaskar
  • Start date
  • #1
134
0

Main Question or Discussion Point

Hey everybody, I am a mechanical engineer and new to Fortran(I have decent experience in programming in C, Matlab and understand languages similar to them). However the Fortran programming structure is new to me. Hence I am facing problems debugging a Fortran code.
Here is the link of the code which I want to run.

http://www2.meteo.uni-bonn.de/forschung/gruppen/tgwww/people/abott/fortran/coad1d.f

I am using a Plato Fortran Compiler.

The error message i get is :
" error 399 - Unrecognised statement, did you forget to add /FIXED_FORMAT? "

It comes for line no 10 which is :

c dt : time step (input in sec)

Can anyone please explain what's the reason of this message and is this the correct way of declaring variables in fortran ???

In case if you are unable to view the code then i shall post it in the reply thread.
Thanks for any help in advance !!!
 

Answers and Replies

  • #2
jtbell
Mentor
15,501
3,296
I suggest you try adding the /FIXED_FORMAT option when compiling, as the error message suggests. I've never used the Plato compiler, so I can't tell you how to actually do it.

The code that you posted clearly uses the old-style "fixed format" which was once standard for Fortran:

  • A C in character position 1 indicates that the line is a "comment" which is not to be compiled.
  • Statements start in position 7.
  • Positions 1-5 are for the occasionally-used "statement numbers".
  • Position 6 is for a "continuation character" that signals that this line is a continuation of the previous statement.
 
  • #3
1,065
53
Yes, what jtbell said.

Don't know anything about Plato, either, but a quick google says something about FTN95...so, you may need to look into your user's manual and see how Plato supports Fortran 77 source code.

It could be that the first indication to the compiler of Fortran 77 source file is its file extension; you may need to set to *.f77 or *.for...maybe *.f alone does the trick; to be sure, do not make it *.f90

Also, I see a large number of continuation marks ('&' in column 6); in Fortran 77, there is a default value for the maximum number of continuation marks...don't remember what that is ...about 20 or 50...just watch out for it if it complains...you may need another compiler flag to extend this limit.
 
  • #4
SteamKing
Staff Emeritus
Science Advisor
Homework Helper
12,798
1,666
Also, I see a large number of continuation marks ('&' in column 6); in Fortran 77, there is a default value for the maximum number of continuation marks...don't remember what that is ...about 20 or 50...just watch out for it if it complains...you may need another compiler flag to extend this limit.
The original Fortran 77 standard allowed for a maximum of 19 continuation lines. Some compilers allow the maximum number of continuation lines to be set with a compiler option.
 
  • #5
134
0
Sorry for again disturbing all of you guys, but there seems to be another problem in the program.
It runs initially, but when I enter the values initially asked, the program stops mid-way showing an error:
Run-time Error
*** Error 112, Reference to undefined variable, array element or function result (/UNDEF)

COURANT - in file help.for at line 149 [+01de]

main - in file help.for at line 45 [+05dc]

So there is an error in the Courant subroutine or error in calling it. Again i am a little unfamiliar to fortran subroutines but is it possible for you to also check what the problem here is ???
As far as i could see the variables inside the subroutine were declared beforehand. And the logic looks correct.
Also is the declaration line 45 calling courant subroutine done correctly ???

Any help is appreciated. I have already received awesome help from you all here.
 
  • #6
33,169
4,853
In the Courant subroutine, the line shown below in red seems to have a typo.
Code:
do i=1,n
      do j=i,n
         x0=e(i)+e(j)
         do k=j,n
            if (e(k).ge.x0.and.e(k-1).lt.x0) then
               [color="red"]if (c(i,j).lt.1.-1.d-08) then[/color]
                  kk=k-1
                  c(i,j)=dlog(x0/e(k-1))/(3.d0*dlnr)
               else
                  c(i,j)=0.
                  kk=k
               endif
               ima(i,j)=min(n-1,kk)
               go to 2000
            endif
         enddo
 2000    continue
         c(j,i)=c(i,j)
         ima(j,i)=ima(i,j)
      enddo
      enddo
Possibly that line should be:
Code:
if (c(i,j).lt.1.d-08) then
 
  • #7
134
0
Sorry, but i am unable to see the difference ... where did you exactly change ???
 
  • #8
33,169
4,853
The original code has c(i,j) .lt. 1.-1.d-08

The part in bold above is a typo, I believe, and should be removed.

One reason it's difficult to make sense of is that Fortran programmers seem unaware of the benefits of using white space to make the code more readable. For example, the line above the one I marked in red contains this code:
Code:
(e(k).ge.x0.and.e(k-1).lt.x0)
There is not a single space character here, making it much more difficult to spot anything that might be incorrect.
 
  • #9
134
0
Mark44 : Even after i correct as per your possible typo, the same error comes.
Just curious, what made you think of the typo ???
 
  • #10
134
0
In case if you guys are running the code, here are the sample values:
dt:1
r0:10
xmw:1
scal:2
isw:2
 
  • #11
33,169
4,853
Mark44 : Even after i correct as per your possible typo, the same error comes.
Just curious, what made you think of the typo ???
I just looked at your Courant routine and spotted it.

Nothing else in that routine jumps out at me, so I would suggest you use a debugger to find out what's going on to produce that error.
 
  • #12
AlephZero
Science Advisor
Homework Helper
6,993
291
In the Courant subroutine, the line shown below in red seems to have a typo.
Code:
[color="red"]if (c(i,j).lt.1.-1.d-08) then[/color]
Possibly that line should be:
Code:
if (c(i,j).lt.1.d-08) then
It might not be a typo. The programmer might have thought it was easier to read than
Code:
if (c(i,j).lt.0.9999999d0) then
 
  • #13
134
0
Do any of you guys have experience with f2c program ???
I was wondering whether I could translate the given FORTRAN code to C, which will make debugging and changing code easier.
 
  • #14
33,169
4,853
Just my opinion, but I don't think translating this code to C is a good idea.

After taking another look at your courant subroutine, this line of code might be causing problems if the argument to dlog happens to be ≤ 0.
Code:
c(i,j)=dlog(x0/e(k-1))/(3.d0*dlnr)
To determine whether this line is the culprit, put a write statement before that line, having it print the values of x0, e(k - 1), and x0/e(k - 1). In any case, you don't want to be trying to take the log of zero or a negative number.

If this is what's happening, you can guard against this occurring by placing the assignment statement that I listed inside a suitable if statement.

The logic might be something like this:
if |e(k - 1)| < 1.0 d-08 .or. x0/e(k - 1) < 1.0 d-08 then set c(i, j) to 0.0
endif
 
  • #15
134
0
Hey Mark44, that's a great idea. I did, as you said and added the print statement.
print*, x0, e(k-1), x0/(e(k-1)
Well none of the values were equal to 0 or negative, hence i don't think that was the error in code.
But it's a start in debugging, and I would love to hear more such checks from you and rest of the guys here.
 
  • #16
134
0
Just a thought, do you guys see a possible error in this line???
open (16,file='boplot00.out',status='old')
write (16,6100) rri,eei
6100 format (5e16.8)
Is the correct way to open a new file for storing results ???
 
  • #17
DrClaude
Mentor
7,079
3,223
Just a thought, do you guys see a possible error in this line???
open (16,file='boplot00.out',status='old')
write (16,6100) rri,eei
6100 format (5e16.8)
Is the correct way to open a new file for storing results ???
Not a new file, as it explicitly mention that the status be 'old', meaning an already existing file. Since the file is used only for output, you can change the line to
Code:
      open (16,file='boplot00.out')
Otherwise, the program runs fine when I try it with the input data you gave in post #10, and without the modification of Mark44.
 
  • #18
134
0
Yup, well that was the error.
Thank you all of you, this program has been fun to debug. I don't know why the compiler didn't show this error or why the hell it was pointing to courant sub routine. I had to find this one manually by reading it.
 

Related Threads for: Help with fortran code

  • Last Post
Replies
4
Views
1K
Replies
7
Views
2K
Replies
4
Views
4K
  • Last Post
Replies
2
Views
4K
Replies
6
Views
2K
Replies
1
Views
3K
Replies
3
Views
2K
Replies
4
Views
10K
Top