Fortran Fortran: Word input rather than number?

  • Thread starter Thread starter gmcke1
  • Start date Start date
  • Tags Tags
    Fortran Input
AI Thread Summary
To input a word in Fortran instead of a number, users can utilize the `read` statement to capture string input. For example, declaring a character variable and using `read` allows for string comparison. The provided code snippet demonstrates how to prompt for a name and respond based on the input. In Fortran 95, the equality operator can be `==`, while earlier versions may require `.EQ.` for comparisons. This approach effectively enables the use of words as input in Fortran programs.
gmcke1
Messages
9
Reaction score
0
I would like to input a word in the fortran command line rather than a number. For example, if I wanted to exit a program with the word 'exit' how would that be done?

Thanks for the help :D

-Glenn
 
Technology news on Phys.org
in the fortran command line
Do you really mean "command line" here, as in "command line parameter". Or are you actually inquiring about reading (and comparing) strings.

I don't think there is a way to access command line parameters in standard fortran (at least up to F95) so I assume you mean the latter.

Code:
character(20) name

print "(a$)", 'Enter your name> '
read *, name
if (name == 'uart') print *,'Cool name dude.'

The above works for me in Fortran 95 (the gnu g95 compiler). In earlier Fortran versions you might have to use .EQ. instead of ==
 
That is exactly what I was looking for. I didn't know how to use words as input for Fortran until now :DDDDDDDDDDDDDD Thank you so much.

-Glenn
 
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...

Similar threads

Replies
8
Views
1K
Replies
25
Views
3K
Replies
20
Views
4K
Replies
8
Views
4K
Replies
59
Views
11K
Replies
19
Views
6K
Replies
3
Views
2K
Back
Top