Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Print and Read on a line

anishtain4
Beginner
1,316 Views
I want to print something on the screen and then read something while the cursor is at the same line, how should I do this?
0 Kudos
1 Solution
Robert_van_Amerongen
New Contributor III
1,316 Views
Maybe you can use something like

WRITE(*,'("Give a value =>: ")',ADVANCE='NO')
READ(*,*) value

Robert

View solution in original post

0 Kudos
6 Replies
Robert_van_Amerongen
New Contributor III
1,317 Views
Maybe you can use something like

WRITE(*,'("Give a value =>: ")',ADVANCE='NO')
READ(*,*) value

Robert
0 Kudos
Steven_L_Intel1
Employee
1,316 Views
No, that doesn't work - at least in our implementation. You have to use an extension:

write (*,'($,A)') "Number please: "
read (*,*) number
write (*,*) number, " is your lucky number"
end

There is a feature request in to make the version using non-advancing I/O work as desired here. The standard doesn't require it, but some other implementations do it.
0 Kudos
Arjen_Markus
Honored Contributor II
1,316 Views
I thought it would work with F2003's flush statement (and output_unit from iso_fortran_env),
but it doesn't. The flush statement "flush( output_unit )"causes the message that unit 6 is not
connected.

Regards,

Arjen
0 Kudos
Robert_van_Amerongen
New Contributor III
1,316 Views
Steve,

I am a little confused by your remark. The "ADVANCE" specifier works fine and is a FORTRAN feature (see Metcalf , par. 9.11, Non-advancing I/O)

[fortran]  PROGRAM adv
  IMPLICIT none
! 
  REAL :: value
!
  WRITE(*,'("Enter a value =>: ")', ADVANCE='NO')
  READ(*,*) value
  WRITE(*,*) "You give the value:", value
!
  WRITE(*,'($,A)') "Enter a value =>: "
  READ(*,*) value
  WRITE(*,*) "You give the value:", value
!
  STOP
  END PROGRAM adv  [/fortran]



Or do I miss the essence of your remark?


Robert
0 Kudos
Steven_L_Intel1
Employee
1,316 Views
Well, no, I made an error. I was confusing this with the issue where people who want to use non-advancing I/O for a progress bar can't get it working on Intel Fortran. You are correct that it works fine for the "prompt" case. Thanks for picking up on that and I apologize for the mistake.
0 Kudos
anishtain4
Beginner
1,316 Views
Thanks you both. both methods works fine
0 Kudos
Reply