Does anyone know how to program with Fortan 95?

  • Context: Fortran 
  • Thread starter Thread starter kathrynag
  • Start date Start date
  • Tags Tags
    Program
Click For Summary

Discussion Overview

The discussion revolves around programming in Fortran 95, specifically focusing on writing a program to calculate the distance between two points on a Cartesian coordinate plane. Participants seek help with coding errors and syntax issues related to their Fortran 95 implementation.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant requests assistance with programming in Fortran 95, mentioning a specific task of calculating distance between two points.
  • Another participant questions whether the issue is specific to Fortran 95 or if it relates to Fortran 90, providing a link to a tutorial.
  • Several participants identify potential bugs in the provided code, including the use of the wrong exponentiation operator (^) instead of (**), and suggest corrections to the read and write statements.
  • One participant points out that the continuation operator should be (&) instead of (+) in a specific write statement.
  • Another participant emphasizes that the user should input the coordinates rather than the distance, suggesting a change in the read statement.
  • There is a discussion about whether to read multiple variables in one line or separate lines, with one participant confirming that the original format is acceptable.
  • A participant mentions that the program works fine without extending a line, indicating a possible limitation in handling line extensions.

Areas of Agreement / Disagreement

Participants generally agree on the identification of syntax and logical errors in the code, but there is no consensus on the best practices for handling line extensions and input formatting.

Contextual Notes

Participants express uncertainty about specific compiler error messages and the differences between Fortran 90 and Fortran 95, indicating a need for clarification on these points.

kathrynag
Messages
595
Reaction score
0
Fortran 95!

Does anyone know how to program with Fortan 95? I need some help!
 
Technology news on Phys.org


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?
 


I don't know f90 but what are the error messages ?
 


mgb_phys said:
I don't know f90 but what are the error messages ?

i don't know right off hand, but it's f95.
 


kathrynag said:
i don't know right off hand, but it's f95.
there's 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 ?
 


Ok, well I could try it again. I can't run it on my comp. I'll have to try a different one.
 


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
 


Useful nucleus said:
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

Ok, I'll try those, but I still got errors. Is the last read statement fine other than the write?
 
  • #10


Hi kathrynag

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

(1) In your code you wrote

Code:
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:
write(*,*) 'This program calculates the distance between two points &
 & on a Cartesian coordinate plane.'

(2) A logical error in this statement:

Code:
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:
read(*,*) x1, y1, x2,y2


(3) This statement has some syntax erros:
Code:
read(*,*) 'The distance between any two points ,'(x1,y1)', and ,'(x2,y2)', is ,'d

A better one is :
Code:
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
 
  • #11


Ok, I'll try those and let you know what happens.
should I do read(*,*) x1,x2,y1,y2 or separate lines for each variable?
 
  • #12


kathrynag said:
Ok, I'll try those and let you know what happens.
should I do read(*,*) x1,x2,y1,y2 or separate lines for each variable?

It is fine as you wrote it.
 
  • #13


I got it all figured out except for the extension of a line. It works fine if I don't extend a line.
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 5 ·
Replies
5
Views
5K
Replies
16
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 13 ·
Replies
13
Views
3K