I'm Having a lot of Problems with Fortran (77)

  • Fortran
  • Thread starter womfalcs3
  • Start date
  • Tags
    Fortran
In summary, the new programmer is having difficulty compiling and running programs. They have installed Photran and used Eclipse, but have had problems with building and running the programs. They have finally found a compiler that will work, but have run into issues with integrating it with Eclipse. They have followed a Fortran book as to how to input the program inputs, but have run into a problem with the data line following the end statement. They have fixed the issue by removing the line for requesting input and making a comment for information.
  • #1
womfalcs3
62
5
I'm new to this language, and my programming experience is limited (I've only done Assembly). My issues do not necessarily lie in the coding itself, but in the compiling and building.

I'm using Eclipse, on which I installed Photran. The syntax recognition and formatting of the GUI is very nice.

I've tried many compilers. From G77, to GCC 4.3.3 with Fortran, and others (BCF12b, and so on).

Eclipse never builds or runs though. It sometimes brings up binary parser errors, and I don't see a makefile anywhere in the navigation bar.

I wrote and saved my relatively simple *.f file (Simpson's 1/3 Rule). I just need to run it and see if it works.

Thank you.
 
Technology news on Phys.org
  • #2
My suggestion is to compile and run a simple program (like printing "hello world!") onto the screen and see if it works. If it doesn't, then you have some configuration work to do.
Alternatively you can post your simpson's ruel program (probably 15 lines) and see if there is an inherent problem. There are less and less people using F77. Many have converted to later versions.
 
  • #3
I don't think it's the program; I have it shown below. Sure it's not the most memory-efficient, but that's not my objective right now. I'm just trying to get a simple program to work.

I was finally able to get a makefile generated automatically, but now it can't launch it whenever I use the program in conjunction with any of the compiles mentioned above.

I realize people have moved on from F77, but that's what I'm using since I was instructed it would be sufficient for what I am doing.

2cy00ae.jpg
 
  • #4
Forgot to mention, I still use F77, although I use other languages as well. I have nothing against an established language that is efficient, as long as its capability is not limited for what I need to do.
If you have not run the program yet, make a copy of simpson.txt before you do so. Your code declares the file as new, so it will most probably erase the old one and replace an empty one. By the time you try to read from it, it will probably fail, or read garbage, or read zeroes (most unlikely for Fortran).
If the file simpson.txt is existing, Fortran expects status='old'.
I did not check the rest of the code, but I think you should be sailing smoothly after that.
Wait...
A Statement Function in Fortran is defined with an argument:
not with f=sin(y)
An example follows:
Code:
      REAL*8 A,B,H,FUN,X
C     following is a statement function definition
      FUN(X)=SIN(X)
      READ(*,*)A,B,H
...   do your Simpson's rule programme here using FUN(X) instead of sin(x)
...   print results
      STOP
      END
Also, the variable int defaults to integer, as all variables commencing with A-H, O-Z are real*4, and I-N are integers. If you write
IMPLICIT REAL(A-H, O-Z), INTEGER(I-N)
at the beginning of all your programs, you will not forget the default prefix letter convention.
I usually use SUM, which defaults to REAL.
If you want to use double precision by default, write the following at the beginning.
IMPLICIT REAL*8(A-H, O-Z), INTEGER(I-N)

Hope that helps you to get started.
 
  • #5
Thanks a lot. I really appreciate it.
 
  • #6
If you don't mind to provide further assistance, I would appreciate it if you checked over my program again.

I finally found a compiler that will work. It's standalone though. I can't seem to integrate it with Eclipse. It gives back a message saying I have 1 severe error.

I'm trying to follow a Fortran book as to how to enter the inputs from within the program rather than using an external text file. It just shows a data card after the "end" command in which it has the inputs. Is that correct?

jpzg9x.jpg
 
  • #7
Your program looks OK, except for a couple of minor errors.
The older fortran compilers ran on punched cards, so data would immediately follow the program, sometimes separated by a separator card, such as /* (end of program) or // (end of input).
So your data line that follows the end statement will cause a compiler error because modern compilers do not expect data following immediately the program.
What you'll need to do is to remove that line, or make a C in column 1 to make it a comment (so the line will stay for information).
Back to the program:
the line for requesting input would preferably be
READ(*,*)A,B,N
which will request input in free format, so you don't have to respect the number of spaces between data when you type in your data on the screen. The format statement can be used for output as you have done, but the I3 at the end can be changed for I5 to leave spaces before the integer (100 needs three characters).
There is an error for the calculation of y inside the two loops, see if you can find what is the correct coding.
The answer for area should be 0.99999 or around there, depending on the compiler and precision.
If you cannot find the error for calculation of y inside the loops, post the formula for simpson's rule and check again according to the formula you found.
Keep it up, you are just a couple of lines away!
 
  • #8
It gives me problems with the function. "Assignment operation illegal to external procedure fun" Then it gives me the line in which the function is written.

I went online to find examples of how to input functions in F77, but other methods I've tried resulted in more errors in relation to the function.

Also, I believe I have fixed the error of which you speak in relation to the y-value. I can deal with computational errors right now though. I just need to get the program to work. If the solution is wrong, I can go back and work it out by hand then translate that over to the source file.
 
Last edited:
  • #9
"Assignment operation illegal to external procedure fun"
Sorry, I forgot to mention that the definition of the statement function
fun(y)=sin(y)
must be placed before any executable statement. In your case, a safe bet would be to place it after the declaration of variables (i.e. after real a,b,h...).
 
  • #10
Thanks a lot! Your help was great.

It worked. I had to also include a "go to" statement so that the *.exe file generated wouldn't close on me immediately after the solutions were output. I also added some "print" statements to simplify input and data recognition.

Good results too. Here were some results with varied number of intervals:


2v8n9k3.jpg
 
  • #11
Good job, efforts (almost) always pay off!
:-)
 
  • #12
By the way Math, what compiler do you use?

For this initial practice run, I spent a lot of time going through compilers. I ran into this one called PGI Fortran Workstation. It's the one I used for this program.

In just one command line in Command Prompt, it gave me an executable file. Which is what I needed. It's a really really awesome compiler.

The problem is, this PGI application costs 500 dollars + subscription. I used the trial version.

I've been examining Open Watcom F77. It compiles into *.obj files, and there doesn't seem any option to build an *.exe file.

I have 14 days on the trial version, and I don't know if I'll end up spending that much money on it. I was looking for a free alternative.
 
  • #13
The one I use is not free, it's a very respectable compiler called Lahey. They have been in the business for a very long time, namely providing Fortran compilers on PC's. (http://www.lahey.com/)

The following link lists a number of free fortran compilers, I have heard of people using the G77 compiler, but haven't had much feedback. Be aware: read the contract carefully for each compiler you want to try. Sometimes they are not as free as one thinks.
http://www.thefreecountry.com/compilers/fortran.shtml

Other than that, you can start a new thread asking for opinions of others. There are many Fortran users around here.
 

1. What is Fortran 77 and how is it used in scientific research?

Fortran 77 is a programming language that was developed specifically for scientific computing. It is used to write programs and algorithms for solving mathematical and scientific problems, such as data analysis, simulations, and numerical computations.

2. Can you explain the main differences between Fortran 77 and newer versions like Fortran 90 or 95?

The main difference between Fortran 77 and newer versions is the incorporation of modern programming features, such as dynamic memory allocation, modules, and object-oriented programming. Fortran 90 and 95 also have improved support for array operations, making it easier to write efficient code for scientific applications.

3. What are some common problems that arise when using Fortran 77?

Some common problems with Fortran 77 include difficulties with debugging and maintaining code, limitations in features and functionality compared to newer versions, and compatibility issues with modern operating systems and hardware.

4. How can I improve my skills in using Fortran 77?

One of the best ways to improve your skills in Fortran 77 is to practice writing code and solving problems. There are also many resources available online, such as tutorials, forums, and online courses, that can help you learn and improve your skills.

5. Is Fortran 77 still relevant in modern scientific research?

While newer versions of Fortran have become more popular, Fortran 77 is still widely used in scientific research, particularly in fields such as physics, chemistry, and engineering. Many legacy codes and libraries are also written in Fortran 77, making it necessary for researchers to have knowledge of this language.

Similar threads

  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
2
Views
5K
  • Programming and Computer Science
Replies
4
Views
13K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Programming and Computer Science
Replies
5
Views
9K
  • Programming and Computer Science
Replies
5
Views
3K
Back
Top