Re: How to convert integers to characters?



In message 29 Sep
hermitian <iamwuxin@xxxxxxxxx> wrote:

Is there any functions to convert integers to characters?
[snip]

Moreover, is there any other functions can reverse the conversion?
[snip]

Have a look at these two functions. You should be able to do the reverse.

* atodbl: converts string to real*8 using internal file

function atodbl(str)

implicit none

c paramater declarations
include "misc.h"

c global declarations
character str*(*)
real*8 atodbl

c external declarations
integer*2 strlen

c local declarations
character cnvstr*(MAXSTRLEN),tmpstr*(MAXSTRLEN)
logical*1 nodp
integer*2 i,l
real*8 tmp

c begin

tmpstr = str

c.....check for decimal points
l = strlen(str)
i = 1
nodp = .true.
do while (i.le.l)
nodp = nodp.and.(str(i:i).ne.'.')
i = i + 1
enddo

if (nodp) then
write(cnvstr,CHRFMT) tmpstr(1:l)//'.'
else
write(cnvstr,CHRFMT) tmpstr
endif
read(cnvstr,DBLFMT) tmp
atodbl = tmp

return
end

* atoint: converts string to integer*2 using internal file

function atoint(str)

implicit none

c parameter declarations
include "misc.h"

c global declarations
character str*(*)
integer*2 atoint

c local declarations
character cnvstr*(MAXSTRLEN)
integer*2 tmp

c begin

write(cnvstr,CHRFMT) str
read(cnvstr,INTFMT) tmp
atoint = tmp


return
end

Hope this helps.

Cheers,
--
Regards,
Terry Duell

.



Relevant Pages

  • Re: newbie question for reading input file
    ... Declarations are *VERY* important. ... feature is using a real variable to store character values. ... You have to use an explicit format with an appropriate "A" edit ... unused data edit descriptors at the end of the format are ignored, ...
    (comp.lang.fortran)
  • RE: size_t ?
    ... > chapters and once and for all understand character types in Windows. ... > just a char type and the hell with where TCHAR comes from. ... > iLenght = strlen; ... > search and I did not find the following declarations)?: ...
    (microsoft.public.vc.language)
  • Re: TRIM
    ... Dick Hendrickson wrote: ... > CHARACTER ... ANY OTHER NEEDED DECLARATIONS ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)
  • Re: TRIM
    ... Dick Hendrickson wrote: ... > CHARACTER ... ANY OTHER NEEDED DECLARATIONS ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)
  • Re: size_t ?
    ... >and personally, I think Windows got complicated, but probably had no choice ... >the string stored at the location of pc. ... "Hello" is an 8-bit character string, ... declarations are in both files: ...
    (microsoft.public.vc.language)