- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hello, all
I write a simple program for writing real variable.
But case1 and case 2 has some space in front of the number.
Then I tried using 0PF0.4 format, but it removed the number zero.
Finally I changed real variable to character and print it.
Is there any other way to remove the space before number with number zero?
-------------------------------------------
PROGRAM TEST
REAL :: e=0.1425
CHARACTER(LEN=10) :: rstr1
write (*,*) e !case1
write (*,"(f10.4)") e !case2
write (*,"(0PF0.4)") e !case3
write (rstr1,"(0PF10.4)") e
write(*,*) rstr1
write (*,'(a)') trim(adjustl(rstr1)) !case4
END PROGRAM TEST
-------------------------------------------
> ./a.out
0.1425000
0.1425
.1425
0.1425
0.1425
-------------------------------------------
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try
WRITE(*,'(*(g0))') e
List-directed formatted writes always put that leading space in there just in case you are outputting to a 1960s-style IBM printer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Repeat Offender wrote:
Try
WRITE(*,'(*(g0))') e
List-directed formatted writes always put that leading space in there just in case you are outputting to a 1960s-style IBM printer.
Perhaps we can ask a large automobile company to write us a Fortran compiler using which we can produce software that can sense when it is connected to a line-printer and output spaces only if it is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Way back when postscript was introduced, it was accompanied by filters (a2ps, enscript) to translate the legacy line formatting. Those are still available, and could be adapted if you find that an easier path than explicit formats.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
mecej4 wrote:
..
Perhaps we can ask a large automobile company to write us a Fortran compiler using which we can produce software that can sense when it is connected to a line-printer and output spaces only if it is.
And when the company is from the most prosperous part of the old continent, the software will work perfectly when mecej4 is using it to test but said sensors will be turned off when ordinary users try to run it :-)))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Repeat Offender wrote:
Try
WRITE(*,'(*(g0))') e
List-directed formatted writes always put that leading space in there just in case you are outputting to a 1960s-style IBM printer.
Thanks for your kind answer.
I tried this format, but it still didn't have zero before decimal point...
------------------result---------------------
.1425000

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