PDA

View Full Version : Fortran: Word input rather than number?


gmcke1
Sep3-11, 12:38 AM
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

uart
Sep3-11, 09:35 AM
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.


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 ==

gmcke1
Sep4-11, 09:13 PM
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