Fortran Getting Started with Fortran: Questions & Answers

  • Thread starter Thread starter Dgrosser
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
The discussion focuses on a Fortran assignment involving user input for numbers and a true/false statement, which are intended to be used as parameters in a larger program. Key points include the need to format output correctly, specifically how to display a grid size as "l x l." For logical input, it is suggested that the user should input characters like 'T' or 'F' to represent true or false, as user input is treated as strings. The conversation clarifies that parameters in Fortran must be constants, meaning that variables like N, l, and T cannot be declared as parameters directly. Instead, it is recommended to pass values as parameters within functions or subroutines.
Dgrosser
Messages
3
Reaction score
0
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
 
Technology news on Phys.org
Dgrosser said:
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.
Dgrosser said:
So in summar the 3 questions are:
1) how do i output something to say " * and * "
print *, " * and * "
Dgrosser said:
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'.
Dgrosser said:
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
4
Views
2K
Replies
19
Views
6K
Replies
13
Views
3K
Replies
22
Views
5K
Replies
8
Views
2K
Replies
5
Views
2K
Back
Top