- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyon in the forum,
according to the lat post to achieve my goal, i was checking how the command FORMAT works but i do not know how to restrict the values.
One of the examples i have tryed :
WRITE(6,20) COM
FORMAT (I
Message Edited by patuco on 04-25-200602:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
First of all FORMAT is not a "command".
It might be useful for you to think offormat as a "template" which is used by the write statement(s) to describe how the variables on the write statement are to be presented.
To takea simplified example as put in your first message you have your REAL*8 variable to print out:
real*8 rvar
.... code to set value of rvar somehow ...
if (rvar .lt 1.0d0) then
write (6,20) rvar
else if (rvar .ge. 1.0d0 .and. rvar .le. 9.0d0) then
write (6,21) rvar
else
write (6,22) rvar
endif
20 format(something suitable for numbers less than 1.0)
21 format(for numbers between 1 and 9)
22 format( for numbers greater than 9)
As for your second question. I am not sure I understand correctly. Do you have a character variable which contains the character representation of a real number? for example:
character*10 cvar
cvar = " 1.0000000"
if so then all you need to do is an "internal read" for example:
integer ivar
real rvar
read(cvar,"(F10.0)") rvar ! read the number from the character variable
ivar = nint(rvar) ! Get the nearest integer number to rvar and assign to ivar
hope this helps
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you explainin moredetail what you mean "limit the size of a real number" ? What is the problem you are trying to solve?
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I assume you mean output the real number to a fileor to thescreen?
OK This is where formats apply. You should really read the online manual or get a Fortran book for the full explanation of the format Edit Descriptors (D,E,F,G for real numbers), but here is the simplified version :
real rvar
rvar = 1.119999964457385E-001
write(6,20) rvar
20 format(f10.4)
In the format (f10.4) the "10" says the size of the output is 10 characters in total, and the "4" says output with 4 decimal places. I this case the output would be " 0.1120"
10 characters totalwith 4leading spaces.
Example (F20.10) would be 20 characters total with 10 decimal places, and so on.
Les
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page