Getting Started with Fortran: Questions & Answers

  • Fortran
  • Thread starter Dgrosser
  • Start date
  • Tags
    Fortran
In summary: If you want to use a parameter to hold a value that changes during the run of the program, you can't. You'll need to use a variable.
  • #1
Dgrosser
3
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
  • #2
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.
 

1. What is Fortran and why should I learn it?

Fortran is a high-level programming language that is commonly used in scientific and engineering applications. It is particularly well-suited for numerical computations and has been used for decades in fields such as weather forecasting, computational physics, and aerospace engineering. Learning Fortran can open up many opportunities in these and other fields.

2. How do I install Fortran on my computer?

The process of installing Fortran will vary depending on your operating system and the specific Fortran compiler you are using. However, most compilers provide detailed installation instructions on their website. It is recommended to follow these instructions carefully to ensure a successful installation.

3. What are the basic syntax and structure of a Fortran program?

A Fortran program is made up of a series of statements, each ending with a semicolon. The main program begins with the PROGRAM statement and ends with the END PROGRAM statement. The WRITE statement is commonly used to print output to the screen, while the READ statement is used to receive input from the user.

4. How do I debug my Fortran code?

Debugging in Fortran is similar to other programming languages. The most common approach is to use print statements to check the values of variables at different points in the code. Additionally, many Fortran compilers have debugging tools that can help identify and fix errors in the code.

5. Are there any good resources for learning Fortran?

Yes, there are many resources available for learning Fortran, including online tutorials, textbooks, and forums. Some popular resources include the official Fortran website, Fortran Wiki, and various online courses. It can also be helpful to seek guidance from experienced Fortran programmers or join a Fortran community to ask questions and get support.

Similar threads

  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
464
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
19
Views
5K
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
22
Views
4K
  • Programming and Computer Science
Replies
13
Views
2K
Back
Top