Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,496 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,706 people online right now. Registration is fast and FREE... Join Now!




Fortran read character

 
Reply to this topicStart new topic

Fortran read character

krogen
4 Mar, 2008 - 12:57 PM
Post #1

New D.I.C Head
*

Joined: 4 Mar, 2008
Posts: 1

Hello,

I'm trying to do something very simple.
CODE

character*1 w,a,s,d
character*5 input
read *, input
if (input.eq.w) then
(execute something here)
if (input.eq.a) then
(something here)
(repeated for s and d)
end if

Looks right, doesn't it? So why on earth a program will not execute a the 'then (something here)' if the input is w,a,s,d?

Execution:
w
(program ended)

When it should be:
w
(executed something here)
(program ended)

The above code will work with integers, why won't it work with characters? I added another line to see what the input of "read *, input" is:
CODE

read *, input
print *, 'The input is ', input
if (input.eq.w) print *, 'great'

Guess what's the outcome?
w
w
(line not executed)

If input is w and w.eq.w why won't it execute the print statement?!?! This is so frustrating. This works with integers without a problem but does not want to work with characters, for whatever reason.

User is offlineProfile CardPM
+Quote Post

pbl
RE: Fortran Read Character
6 Mar, 2008 - 01:11 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,120



Thanked: 203 times
Dream Kudos: 75
My Contributions
CODE

character*1 w,a,s,d
character*5 input
read *, input

c--- so input equals "w    "

c--- input qhich contains "w    " surely not equals w which is not initialized
c--- an even if w was containing "w" :  "w" is not equals to "w     "

if (input.eq.w) then
(execute something here)

c--- neither a which is not initilialized neither
if (input.eq.a) then
(something here)
(repeated for s and d)
end if


User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 08:02PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month