replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Integer to character problems
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Integer to character problems

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
kingkastle



Joined: 22 May 2008
Posts: 20

PostPosted: Wed Sep 03, 2008 8:50 am    Post subject: Integer to character problems Reply with quote

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
View user's profile Send private message Send e-mail
JohnCampbell



Joined: 16 Feb 2006
Posts: 2620
Location: Sydney

PostPosted: Wed Sep 03, 2008 9:59 am    Post subject: Reply with quote

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
View user's profile Send private message
kingkastle



Joined: 22 May 2008
Posts: 20

PostPosted: Wed Sep 03, 2008 10:35 am    Post subject: Reply with quote

Thanks very much!!!!

that really solves it!

Best regards
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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