Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Mar 20, 2009 #1
    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.
     
  2. jcsd
  3. Mar 21, 2009 #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.
     
  4. Mar 21, 2009 #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
     
  5. Mar 21, 2009 #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 (Text):

          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.
     
  6. Mar 21, 2009 #5
    Thanks a lot. I really appreciate it.
     
  7. Mar 22, 2009 #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
     
  8. Mar 22, 2009 #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 statment 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!
     
  9. Mar 22, 2009 #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: Mar 22, 2009
  10. Mar 22, 2009 #9
    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....).
     
  11. Mar 22, 2009 #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
     
  12. Mar 22, 2009 #11
    Good job, efforts (almost) always pay off!
    :-)
     
  13. Mar 22, 2009 #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.
     
  14. Mar 22, 2009 #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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: I'm Having a lot of Problems with Fortran (77)
  1. Fortran 77 problem! (Replies: 7)

  2. Fortran 77 (Replies: 1)

Loading...