 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
kingkastle
Joined: 22 May 2008 Posts: 20
|
Posted: Wed Sep 03, 2008 8:50 am Post subject: Integer to character problems |
|
|
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
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(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 |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2620 Location: Sydney
|
Posted: Wed Sep 03, 2008 9:59 am Post subject: |
|
|
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
Code: |
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
|
|
|
Back to top |
|
 |
kingkastle
Joined: 22 May 2008 Posts: 20
|
Posted: Wed Sep 03, 2008 10:35 am Post subject: |
|
|
Thanks very much!!!!
that really solves it!
Best regards |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|