- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The format i4.4 would print the integer number 12 as "0012". What format would print the real number 12.3 as "0012.3"?
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is no Fortran format that will do this - sorry. If you need this, you'll have to write into a character variable using internal write and then "post-process" the string replacing leading blanks with zeroes.
Steve
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve
Can users define new formats?
I can print the real number x = 12.3 as "0012.3" by doing
write(*, '(i4.4,f2.1)') floor(x), x - floor(x).
Can I define a format MY_FORMAT so as to
achieve the same result with
write(*, MY_FORMAT) x?
Can users define new formats?
I can print the real number x = 12.3 as "0012.3" by doing
write(*, '(i4.4,f2.1)') floor(x), x - floor(x).
Can I define a format MY_FORMAT so as to
achieve the same result with
write(*, MY_FORMAT) x?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can set a character variable to your format code and reference the character string as your format statement.
(It's in the LRM).
Keith
(It's in the LRM).
Keith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks kdkeefer,
I am afraid your message does address
the issue I am raising.
Note that the format '(i4.4,f2.1)' takes two
inputs, which in my usage happen to be related.
The format MY_FORMAT I am seeking would achieve
the same result with just one input.
(By the way, what is LRM; what does this acronym mean?)
I am afraid your message does address
the issue I am raising.
Note that the format '(i4.4,f2.1)' takes two
inputs, which in my usage happen to be related.
The format MY_FORMAT I am seeking would achieve
the same result with just one input.
(By the way, what is LRM; what does this acronym mean?)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
LRM = Language Reference Manual.
No, you cannot invent your own format codes. You could write a function that returns a character result with the value formatted as you like (then display it with the A format.)
Steve
No, you cannot invent your own format codes. You could write a function that returns a character result with the value formatted as you like (then display it with the A format.)
Steve
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