fortran90 - Converting string to real or double -


in f90 need encode 30 character string real/double , recover in different place real/double number. how that? thanks, mark

i wouldn't use doubles, i'd use integers. array of integers. , intrinsic functions ichar , achar convert character ascii equivalent , (respectively).

you whip easily:

program string_to_int    implicit none    integer :: mystring_int(30),    character(len=30) :: mystring     mystring = "fortran best language!!"    i=1,30       mystring_int(i) = ichar(mystring(i:i))    enddo    print *,mystring_int     call read_back_int(mystring_int)  contains    subroutine read_back_int(cvar)      integer, intent(in) :: cvar(:)      character(len=size(cvar)) :: substring      integer ::      i=1,size(cvar)         substring(i:i) = achar(cvar(i))      enddo      print *,substring     end subroutine read_back_int  end program string_to_int 

using (intrinsic) function sizeof, shows me character string 30 bytes while integer array 120 bytes. if really want use double, replacing integer real(kind=c_double) (which requires iso_c_binding module) trick too.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -