Re: How to convert integers to characters?
- From: "Craig Dedo" <cdedo@xxxxxxxxx>
- Date: Fri, 28 Sep 2007 23:16:47 -0500
"hermitian" <iamwuxin@xxxxxxxxx> wrote in message news:1191025165.820407.47400@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Is there any functions to convert integers to characters?
For example:
real::a=123.4 ! a is a real number
character(len=30)::b ! b is a character
!How can I convert a to b as a character, i.e. b would be 123.4, but b
is a character.
Moreover, is there any other functions can reverse the conversion?
i.e. from characters to numbers.
character(len=30)::b="123.4"
real::a
how can I assign 123.4 to a as a real number?
Many thanks!
In Fortran, you do not use functions for this operation, unlike in the C-like languages. Instead, you use "Internal I/O" statements, more specifically as "Internal Write" and "Internal Read" statements.
An internal read converts from character to binary. An internal write converts from binary to character.
Internal read and write statements work just like their counterparts that read from and write to external files. The only significant difference from the programmer's perspective is that you use a CHARACTER variable or array element in place of the Logical Unit Number (LUN). Everything else is the same, including format specifications and all of the other I/O keywords.
Using your example, here is what you would do:
Write (Unit=B, FMT="(F5.1)") A ! Converts value of A into CHARACTER variable B using F5.1 format edit descriptor.
Read (Unit=B, FMT=*) A ! Converts from CHARACTER variable B into REAL variable A using list-directed formatting.
Please read your Fortran documentation and/or textbook for further details on how this works.
--
Craig Dedo
17130 W. Burleigh Place
P. O. Box 423
Brookfield, WI 53008-0423
Voice: (262) 783-5869
Fax: (262) 783-5928
Mobile: (414) 412-5869
E-mail: <cdedo@xxxxxxxxx> or <craig@xxxxxxxxxx>
.
- Follow-Ups:
- Re: How to convert integers to characters?
- From: Richard Maine
- Re: How to convert integers to characters?
- References:
- How to convert integers to characters?
- From: hermitian
- How to convert integers to characters?
- Prev by Date: Re: How to convert integers to characters?
- Next by Date: Re: How to convert integers to characters?
- Previous by thread: Re: How to convert integers to characters?
- Next by thread: Re: How to convert integers to characters?
- Index(es):
Relevant Pages
|