|
|
Up |
|
|
  |
Author: fm2766fm2766 Date: Aug 29, 2008 07:28
Hello, I have to convert integers in characters; for example: from
number i=123456 to string c="123456".
I could write in a file the variable "i", and later read it as a
variable "c", but this method seems to me very inefficient.
Some suggestions?
|
| |
|
| | 22 Comments |
|
  |
Author: michaelmetcalfmichaelmetcalf Date: Aug 29, 2008 07:56
On Aug 29, 4:28 pm, fm2766 wrote:
> Hello, I have to convert integers in characters; for example: from
> number i=123456 to string c="123456".
> I could write in a file the variable "i", and later read it as a
> variable "c", but this method seems to me very inefficient.
> Some suggestions?
Well, that's almost what you do, however, not to an external file but
to an 'internal' one as defined by your c, as in:
write(c, '(i6)') i
HTH,
Mike Metcalf
|
| |
|
| | no comments |
|
  |
Author: Sebastian GallinatSebastian Gallinat Date: Aug 29, 2008 08:06
fm2766 schrieb:
> Hello, I have to convert integers in characters; for example: from
> number i=123456 to string c="123456".
> I could write in a file the variable "i", and later read it as a
> variable "c", but this method seems to me very inefficient.
> Some suggestions?
First, declare a character variable which is long enough to hold your
bigest integer number:
character(len=15):: iBuf
Second, use the write-statement performing an internal write to the
character variable:
write(unit=iBuf, fmt=*) i
If needed, do something for adjusting the characters:
iBuf = adjustl(iBuf)
If you have some docs for the used compiler by hand, you will find this
feature under internal write statement. Hope, this helps,
Sebastian.
|
| |
| no comments |
|
  |
Author: Paul van DelstPaul van Delst Date: Aug 29, 2008 08:18
> On Aug 29, 4:28 pm, fm2766 wrote:
>> Hello, I have to convert integers in characters; for example: from
>> number i=123456 to string c="123456".
>> I could write in a file the variable "i", and later read it as a
>> variable "c", but this method seems to me very inefficient.
>> Some suggestions?
>
> Well, that's almost what you do, however, not to an external file but
> to an 'internal' one as defined by your c, as in:
>
> write(c, '(i6)') i
Maybe some thought should be given to giving this process an additional, more intuitive,
name. It's such a common question and "Internal file writing and reading" sure isn't the
first thing a newcomer thinks of when they want to convert int->character or vice versa.
cheers,
paulv
|
| |
| no comments |
|
  |
Author: e p chandlere p chandler Date: Aug 29, 2008 14:52
Paul van Delst wrote:
>> On Aug 29, 4:28 pm, fm2766 wrote:
>>> Hello, I have to convert integers in characters; for example: from
>>> number i=123456 to string c="123456".
>>> I could write in a file the variable "i", and later read it as a
>>> variable "c", but this method seems to me very inefficient.
>>> Some suggestions?
>>
>> Well, that's almost what you do, however, not to an external file but
>> to an 'internal' one as defined by your c, as in:
>>
>> write(c, '(i6)') i
>
> Maybe some thought should be given to giving this process an additional, more intuitive,
> name. It's such a common question and "Internal file writing and reading" sure isn't the
> first thing a newcomer thinks of when they want to convert int->character...
|
| Show full article (1.03Kb) |
| no comments |
|
  |
Author: Ron FordRon Ford Date: Aug 29, 2008 19:05
On Fri, 29 Aug 2008 14:52:52 -0700 (PDT), e p chandler posted:
> Paul van Delst wrote:
>>> On Aug 29, 4:28 pm, fm2766 wrote:
>>>> Hello, I have to convert integers in characters; for example: from
>>>> number...
|
| Show full article (1.53Kb) |
| no comments |
|
  |
Author: Gary ScottGary Scott Date: Aug 29, 2008 19:35
Ron Ford wrote:
> On Fri, 29 Aug 2008 14:52:52 -0700 (PDT), e p chandler posted:
>
>
>>Paul van Delst wrote:
>>
>>>>On Aug 29, 4:28 pm, fm2766 wrote:
>>>>
>>>>>Hello, I have to convert integers in characters; for example: from
>>>>>number i=123456 to string c="123456".
>>>>>I could write in a file the variable "i", and later read it as a
>>>>>variable "c", but this method seems to me very inefficient.
>>>>>Some suggestions?
>>>>
>>>>Well, that's almost what you do, however, not to an external file but
>>>>to an 'internal' one as defined by your c, as in:
>>>>
>>>>write(c, '(i6)') i ...
|
| Show full article (1.87Kb) |
| no comments |
|
  |
Author: nospamnospam Date: Aug 29, 2008 21:36
Gary Scott sbcglobal.net> wrote:
> Ron Ford wrote:
>> What I don't see is a file. By "file," do people mean "whatever internal
>> variables you used to read the data?"
> It's an abstract concept...the character variable is a substitute for a
> "file".
And that's really, really how you want to think of it. Because if you
think of it that way, most other things about its usage pretty much
follow (ok, not all of them, but most of the basics). For a very
particular example, it is "obvious" when you want to do an internal read
versus an internal write. If that isn't obvious, then I'd say you aren't
yet really thinking about the character variable as a substitute for a
file. If you don't think of it that way, then you'll be like all the
other people who just try to memorize when to use read versus write, and
who guess wrong pretty much 50%% of the time.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
|
| |
| no comments |
|
  |
Author: nospamnospam Date: Aug 29, 2008 21:43
Richard Maine wrote:
> Gary Scott sbcglobal.net> wrote:
>
>> Ron Ford wrote:
>
>>> What I don't see is a file. By "file," do people mean "whatever internal
>>> variables you used to read the data?"
>...
|
| Show full article (1.85Kb) |
| no comments |
|
  |
|
|
  |
Author: e p chandlere p chandler Date: Aug 29, 2008 22:37
Ron Ford wrote:
> On Fri, 29 Aug 2008 14:52:52 -0700 (PDT), e p chandler posted:
>
>> Paul van Delst wrote:
>>>> On Aug 29, 4:28 pm, fm2766 wrote:
>>>>> Hello, I have to convert integers in characters; for example: from
>>>>> number i=123456 to string c="123456".
>>>>> I could write in a file the variable "i", and later read it as a
>>>>> variable "c", but this method seems to me very inefficient.
>>>>> Some suggestions?
>>>>
>>>> Well, that's almost what you do, however, not to an external file but
>>>> to an 'internal' one as defined by your c, as in:
>>>>
>>>> write(c, '(i6)') i
>>>
>>> Maybe some thought should be given to giving this process an additional, more intuitive,
>>> name. It's such a common question and "Internal file writing and reading" sure isn't the
>>> first thing a newcomer thinks of when they want to convert int->character or vice versa. ...
|
| Show full article (2.16Kb) |
| no comments |
|
RELATED THREADS |
  |
|
|
|
|
|