View previous topic :: View next topic |
Author |
Message |
leszpol
Joined: 25 Apr 2008 Posts: 29 Location: Gdynia-TriCity
|
Posted: Tue Jun 28, 2011 6:59 am Post subject: Reading the numbers with a comma instead of dot |
|
|
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 |
|
 |
Wilfried Linder
Joined: 14 Nov 2007 Posts: 314 Location: D�sseldorf, Germany
|
Posted: Tue Jun 28, 2011 8:09 am Post subject: |
|
|
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Thu Jun 30, 2011 5:29 pm Post subject: |
|
|
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 |
|
 |
|