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

Internal WRITE Specification

kulachi
Beginner
642 Views
Hi,

I need to write a REAL into a string as INTEGER. The value of REAL may range from 1 to 1000000. My problem is that I don't want any spaces (blanks) in the string. Consider the following code:

---------------------------------------------------
PROGRAM Test
IMPLICIT NONE

REAL :: Y = 500.00
CHARACTER(20) :: Str = ''

write(Str,"('NUM:', I)") INT(Y)

write(*,*) Str

END PROGRAM Test
---------------------------------------------------

This gives me an out of:
NUM: 500

I want it as:
NUM:500

That is, no spaces. In other words I am looking for something that should serve as TRIM() here.

-Kulachi





0 Kudos
1 Solution
GVautier
New Contributor III
642 Views
Use the 0 length :

write(Str,"('NUM:', I0)") INT(Y)

It will produce : NUM:xxx

View solution in original post

0 Kudos
4 Replies
GVautier
New Contributor III
643 Views
Use the 0 length :

write(Str,"('NUM:', I0)") INT(Y)

It will produce : NUM:xxx
0 Kudos
DavidWhite
Valued Contributor II
643 Views
Quoting - gvautier
Use the 0 length :

write(Str,"('NUM:', I0)") INT(Y)

It will produce : NUM:xxx

Or use I7.7 format to get
NUM:0000500

etc.

0 Kudos
kulachi
Beginner
643 Views

Many Thanks!

-Kulachi
0 Kudos
John4
Valued Contributor I
643 Views
What about using the ADJUSTL intrinsic (followed by TRIM, if you want), as in:

write(Str,"(I)") INT(Y)
Str = 'NUM:'//ADJUSTL(Str)
write(*,*) TRIM(Str)

This one also works with reals.
0 Kudos
Reply