Simple fortran help

  • Fortran
  • Thread starter Dgrosser
  • Start date
  • #1
3
0

Main Question or Discussion Point

I am ust beginning a fortran assignment, where I need to get a users input, to get numbers and a true/false statement. These I'm hoping will be able to translate to parameters for a bigger program. So far my code looks like:

integer N,l,Tsteps
logical PBC
print*,"Input Number"
read (*,*) N
print*,"Number=", N
print*,"Input Square Grid Size (one number; LXL)"
read (*,*) l
print*,"Grid length and width is ", l !Want this to say l x l; is there a way to do it? Again, I'm new at this.
print*,"Input time"
read (*,*) T
print*,"Time =", T
print *, "True or False?"
read (*,*) PBC ! How do I get this so that it recognize .true. or .false. from this statement?

Integer,parameter :: n=N ! Will this work?
integer, parameter :: L = l
integer, parameter :: t=T
logical, parameter :: pbc = .PBC.

So in summar the 3 questions are:
1) how do i output something to say " * and * "
2) How do I get a user input statement to be recognized into a logical term?
3) how do I get integers to transform into parameters (or can I just have the input already be in parameter form?)

Thank you for your help
 

Answers and Replies

  • #2
33,505
5,191
I am ust beginning a fortran assignment, where I need to get a users input, to get numbers and a true/false statement. These I'm hoping will be able to translate to parameters for a bigger program. So far my code looks like:

integer N,l,Tsteps
logical PBC
print*,"Input Number"
read (*,*) N
print*,"Number=", N
print*,"Input Square Grid Size (one number; LXL)"
read (*,*) l
print*,"Grid length and width is ", l !Want this to say l x l; is there a way to do it? Again, I'm new at this.
print*,"Input time"
read (*,*) T
print*,"Time =", T
print *, "True or False?"
read (*,*) PBC ! How do I get this so that it recognize .true. or .false. from this statement?

Integer,parameter :: n=N ! Will this work?
integer, parameter :: L = l
integer, parameter :: t=T
logical, parameter :: pbc = .PBC.
No, these won't work. A parameter is a constant. N, l, and T are variables. I don't know what .PBC. is.
So in summar the 3 questions are:
1) how do i output something to say " * and * "
print *, " * and * "
2) How do I get a user input statement to be recognized into a logical term?
Pretty much, you can't. Anything a user types on the keyboard is a string of one or more characters. You can ask the user to press the 'T' character to signify true and the 'F' character to signify false, and then use logic in your program (if ... then block) to compare what the user typed to the characters 'T' or 'F'. If you want to get a little more robust, you can also compare to lower case characters 't' and 'f'.
3) how do I get integers to transform into parameters (or can I just have the input already be in parameter form?)
Not sure I understand what you're asking, although you can pass values as parameters of functions or subroutines.
 

Related Threads on Simple fortran help

Replies
1
Views
8K
Replies
1
Views
2K
Replies
2
Views
2K
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
2
Views
2K
Top