- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use the 0 length :
write(Str,"('NUM:', I0)") INT(Y)
It will produce : NUM:xxx
write(Str,"('NUM:', I0)") INT(Y)
It will produce : NUM:xxx
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use the 0 length :
write(Str,"('NUM:', I0)") INT(Y)
It will produce : NUM:xxx
write(Str,"('NUM:', I0)") INT(Y)
It will produce : NUM:xxx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - gvautier
Use the 0 length :
write(Str,"('NUM:', I0)") INT(Y)
It will produce : NUM:xxx
write(Str,"('NUM:', I0)") INT(Y)
It will produce : NUM:xxx
Or use I7.7 format to get
NUM:0000500
etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Many Thanks!
-Kulachi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page