Silverfrost Forums

Welcome to our forums

Integer to character problems

3 Sep 2008 7:50 #3777

Hi, to try to convert an integer to character, as a string, that is, the integer 2 to the string '2', I create the following program:

program internal_files implicit none

integer, dimension(17)::arpas character(len=3),dimension(17)charpas integeri

arpas = (/ 0,1,0,7,0,21,0,35,0,35,0,21,0,7,0,1,0 /)

print*,arpas

do i=1,size(arpas) write(charpas(i),*) arpas(i) !internal file used here enddo

print*,charpas !character array with zeros

where (charpas.eq.' 0') charpas = '' end where

print*,charpas !character array without zeros

end program internal_files

The point is that I get a error:

Error 67, Character buffer too small INTERNAL_FILES - in file internalfiles.f95 at line 13 [+0197]

It´s not clear to me which is the origin of this problem, any clue???

Thanks in advance Best regards

RCA

3 Sep 2008 8:59 #3778

Try a format, such as

write(charpas(i),fmt='(i0)') arpas(i) !internal file used here

This will left justify the integer. You could use fmt='(i3)' for right justify.

There are lots of format options, rather than *, which is basically I13

program internal_files 
implicit none 

integer, dimension(17)::arpas 
character(len=3),dimension(17)::charpas 
integer::i 

arpas = (/ 0,1,0,7,0,21,0,35,0,35,0,21,0,7,0,1,0 /) 

print*,arpas 

do i=1,size(arpas) 
write(*,*) arpas(i) !internal file used here 
write(charpas(i),fmt='(i0)') arpas(i) !internal file used here 
end do 

print*,charpas !character array with zeros 

do i=1,size(arpas) 
if (arpas(i) == 0) charpas(i) = '' 
end do

print*,charpas !character array without zeros 

end program internal_files 
3 Sep 2008 9:35 #3779

Thanks very much!!!!

that really solves it!

Best regards

Please login to reply.