replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Reading the numbers with a comma instead of dot
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 

Reading the numbers with a comma instead of dot

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



Joined: 25 Apr 2008
Posts: 29
Location: Gdynia-TriCity

PostPosted: Tue Jun 28, 2011 6:59 am    Post subject: Reading the numbers with a comma instead of dot Reply with quote

How to read a number in Fortran from a text file that its has comma instead of dot in its notation, for example: 6,4941406 e-002.

Regards

Leo
Back to top
View user's profile Send private message Send e-mail
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Tue Jun 28, 2011 8:09 am    Post subject: Reply with quote

I think you sould read the lines of the file as character strings, then replace commas by decimal points, then read the numbers from the modified string like here:

Code:
       character*120  string

100    read(10,'(A)',err=200,end=200)string
       do i = 1,120
         if (string(i:i) .eq. ',') string(i:i) = '.'
       end do
       read(string,*,err=...)nr_1(,nr_2,...)
       goto 100

200    close(10)

Regards - Wilfried
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Thu Jun 30, 2011 5:29 pm    Post subject: Reply with quote

Fortran 2003 has DECIMAL='COMMA' and DECIMAL='POINT' which you can use in the OPEN statement, or in READ and WRITE statements.

But in Fortran 95 you will need to do what Wilfried says, use a character variable to do the I/O then change comma to point (for reads) and point to comma for writes.
Back to top
View user's profile Send private message
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