Becoming a Proper Scientific Programmer
Jul. 2nd, 2007 02:03 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
This week, I am mostly learning Fortran 90.
It's a language which nicely matches the sort of code I like to write; arrays as really first-class language elements are good, and the DWIM read() and write() statements avoid some of the more tiresome boilerplate that typed languages attach to I/O.
I assume there are Fortranophones among my readers; is there a nicer way to write
atomcounts(fooi(1),fooi(2),fooi(3)) = &
1+atomcounts(fooi(1),fooi(2),fooi(3))
?
The obvious
atomcounts(fooi) = atomcounts(fooi)+1
translates as
atomcounts(fooi(1)) = 1+atomcounts(fooi(1))
atomcounts(fooi(2)) = 1+atomcounts(fooi(2))
atomcounts(fooi(3)) = 1+atomcounts(fooi(3))
which is a rank error since atomcounts is a 3D array; also, is there an increment-in-place procedure that I'm missing?
It's a language which nicely matches the sort of code I like to write; arrays as really first-class language elements are good, and the DWIM read() and write() statements avoid some of the more tiresome boilerplate that typed languages attach to I/O.
I assume there are Fortranophones among my readers; is there a nicer way to write
atomcounts(fooi(1),fooi(2),fooi(3)) = &
1+atomcounts(fooi(1),fooi(2),fooi(3))
?
The obvious
atomcounts(fooi) = atomcounts(fooi)+1
translates as
atomcounts(fooi(1)) = 1+atomcounts(fooi(1))
atomcounts(fooi(2)) = 1+atomcounts(fooi(2))
atomcounts(fooi(3)) = 1+atomcounts(fooi(3))
which is a rank error since atomcounts is a 3D array; also, is there an increment-in-place procedure that I'm missing?
no subject
Date: 2007-07-02 01:27 pm (UTC)no subject
Date: 2007-07-03 07:02 am (UTC)Are you only trying to increment the one value in the 3D array?
The whole point of the matrix operations is to enable the compiler to optimise operations on the entire array, so you will likely find a statement that can add 1 to every element in the 3d array all in one go[1], and it'll pick the order to minimise cache misses.
If you are just trying to pick and choose element (foo(1),foo(2),foo(3)) to increment, then there's not going to be a statement to do that.
[1] Wouldn't that be something like a(1:na,1:nb,1:nc) = a(1:na,1:nb,1:nc) + 1 for an array subset or simply a=a+1 for the entire array? I don't have a compiler or Fortran book handy.