Fortran read character

liunx

Guest
Hello,<br /><br />I'm trying to do something very simple.<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><br />character*1 w,a,s,d<br />character*5 input<br />read *, input<br />if (input.eq.w) then<br />(execute something here)<br />if (input.eq.a) then<br />(something here)<br />(repeated for s and d)<br />end if<br /><!--c2--></div><!--ec2--><br />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?<br /><br />Execution:<br />w<br />(program ended)<br /><br />When it should be:<br />w<br />(executed something here)<br />(program ended)<br /><br />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:<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><br />read *, input<br />print *, 'The input is ', input<br />if (input.eq.w) print *, 'great'<br /><!--c2--></div><!--ec2--><br />Guess what's the outcome?<br />w<br />w<br />(line not executed)<br /><br />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.<br />
</div>
 
Back
Top