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

Fortran 95

  1. Feb 3, 2009 #1
    Fortran 95!!!!

    Does anyone know how to program with Fortan 95? I need some help!
     
  2. jcsd
  3. Feb 3, 2009 #2

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

  4. Feb 3, 2009 #3
    Re: Fortran 95!!!!

    Something specific:
    I'm trying to write a program in Fortan 95. I need to find the distance between 2 points (x1,y1) and (x2,y2) on a Cartesian coordinate plane given by the equation:
    d=sqrt[(x1-x2)^2+(y1-y2)^2].
    I want to use the points (-1,1) and (6,2).

    This is the copy of what I am doing:
    program distance
    !kathryn, Assignment 2-21, calculate distance between two points.
    implicit none
    real::x1 !This is the x from the first ordered pair.
    real::y1 !This is the y from the first ordered pair.
    real::x2 !This is the x from the second ordered pair.
    real::y2 !This is the y from the second ordered pair.
    real:: d !This is the distance we are trying to find.
    write(*,*) 'This program calculates the distance between two points
    + on a Cartesian coordinate plane.'
    read(*,*) d
    d=sqrt((x1-x2)^2+(y1-y2)^2) !Calculation
    read(*,*) 'The distance between any two points ,'(x1,y1)', and ,'(x2,y2)', is ,'d
    end


    My problem is that when I compile, I get errors. Where am I going wrong?
     
  5. Feb 3, 2009 #4

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    Re: Fortran 95!!!!

    I don't know f90 but what are the error messages ?
     
  6. Feb 3, 2009 #5
    Re: Fortran 95!!!!

    i don't know right off hand, but it's f95.
     
  7. Feb 3, 2009 #6

    mgb_phys

    User Avatar
    Science Advisor
    Homework Helper

    Re: Fortran 95!!!!

    Theres no real difference, between Fortran90 and Fortran95,
    The compiler error should at least tell you which line the problem is on.

    Is ^ a new operator in f95 It used to be '**' in f77 ?
     
  8. Feb 3, 2009 #7
    Re: Fortran 95!!!!

    Ok, well I could try it again. I can't run it on my comp. I'll have to try a different one.
     
  9. Feb 4, 2009 #8
    Re: Fortran 95!!!!

    I think there are two bugs:

    (1) The exponentiation operator is (**) in F95, not (^)
    (2)The read statement before end program should be write instead
     
  10. Feb 4, 2009 #9
    Re: Fortran 95!!!!

    Ok, I'll try those, but I still got errors. Is the last read statement fine other than the write?
     
  11. Feb 4, 2009 #10
    Re: Fortran 95!!!!

    Hi kathrynag

    It looks like that there are some synatax errors and a logical one actually.

    (1) In your code you wrote

    Code (Text):
    write(*,*) 'This program calculates the distance between two points
    + on a Cartesian coordinate plane.'
    The continuation operator in Fortran is "&" not "+", so a valid statement is
    Code (Text):
    write(*,*) 'This program calculates the distance between two points &
     & on a Cartesian coordinate plane.'
    (2) A logical error in this statement:

    Code (Text):
    read(*,*) d
    You are supposed to ask the user to enter the coordinates x1,x2,y1,y2 , not the distance . After all your code should calculate the distance when the user enters the coordinates. So a valid statement should be

    Code (Text):
    read(*,*) x1, y1, x2,y2

    (3) This statment has some syntax erros:
    Code (Text):
    read(*,*) 'The distance between any two points ,'(x1,y1)', and ,'(x2,y2)', is ,'d
     
    A better one is :
    Code (Text):
    write(*,*)'The distance between any two points ,',x1,y1,', and ,',x2,y2,', is ,',d
    Compare them.

    (4) Finally, if you are using fixed format file, make sure that none of the lines is longer than 80 columns. If any is longer, use the continuation operator "&"

    Hope that works for you
     
  12. Feb 4, 2009 #11
    Re: Fortran 95!!!!

    Ok, I'll try those and let you know what happens.
    should I do read(*,*) x1,x2,y1,y2 or seperate lines for each variable?
     
  13. Feb 4, 2009 #12
    Re: Fortran 95!!!!

    It is fine as you wrote it.
     
  14. Feb 4, 2009 #13
    Re: Fortran 95!!!!

    I got it all figured out except for the extension of a line. It works fine if I don't extend a line.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Fortran 95
Loading...