This is not a very exciting problem or solution, but I shall post it anyway.
I was trying to read formatted data from a file like this:
0 9.99929445e-01
1 6.46409406e-05
2 3.80249651e-06
3 1.03999904e-06
4 4.24499610e-07
5 2.23999794e-07
I first tried the following:
integer :: myint(5)
real(kind = 10) :: myreal(5)
open(unit=2,file=filepath,status='OLD',action='READ')
do i = 1,5
read(2,20) myint(i),myreal(i)
end do
close(2)
20 format(I6,E15.8E3)
The I6 refers to the field width of the integer column. But alas, the output was this:
0 0.99992944E+001
1 0.64640941E+001
2 0.38024965E+001
3 0.10399990E+001
4 0.42449961E+001
5 0.22399979E+001
Oddly enough, everything was in order except that it would round powers from e-01 to e-09 up to E+001, and e-10 to e-19 became E+000 etc. Most odd. The solution was to change the format statement to skip the 2 blank spaces between the columns, which I had forgotten to do:
20 format(I6,2X,E15.8E3)
Simple really, but I don't know why it gives such a strange behaviour.
Tuesday, 16 September 2008
Monday, 8 September 2008
Oh Fortran, how I love thee.
Fortran's logical operators that operate on integers happen to be bitwise. I didn't care about this until now. Here's a summary for two integers, a and b, which can take values 0 or 1.
logical AND:
logical OR:
logical XOR:
logical NOT:
WTF? I have been bitten by the bitwise bear! In order to get zeros and ones, I must use ieor(1,a) instead of not(a). Pah.
Also, the tables in this post look all shit in my browser but I can't be bothered to fix them when I have Fortran to do instead.
Today's post was brought to you by the numbers 0 and 1 and the letter F.
logical AND:
(ab) | iand(a,b) |
00 | 0 |
01 | 0 |
10 | 0 |
11 | 1 |
logical OR:
(ab) | ior(a,b) |
00 | 0 |
01 | 1 |
10 | 1 |
11 | 1 |
logical XOR:
(ab) | ieor(a,b) |
00 | 0 |
01 | 1 |
10 | 1 |
11 | 0 |
logical NOT:
(a) | not(a) |
0 | -1 |
1 | -2 |
WTF? I have been bitten by the bitwise bear! In order to get zeros and ones, I must use ieor(1,a) instead of not(a). Pah.
Also, the tables in this post look all shit in my browser but I can't be bothered to fix them when I have Fortran to do instead.
Today's post was brought to you by the numbers 0 and 1 and the letter F.
Subscribe to:
Posts (Atom)