fivemack: (Default)
[personal profile] fivemack
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?

Date: 2007-07-02 01:27 pm (UTC)
fanf: (Default)
From: [personal profile] fanf
If you want to borrow my copy of the F programming language, feel free to pop round and pick it up. F is a fairly sane subset of Fortran 90; there are F-specific compilers available, but you can also use it as a style guide for using Fortran in a modern style. (The most obvious oddity is that they omitted DO WHILE (?!) but some others are mentioned in http://www.swcp.com/~walt/FJ/9611/issue.html#giants)

Date: 2007-07-03 07:02 am (UTC)
From: [identity profile] tau-iota-mu-c.livejournal.com
Behind the times! The intel compiler at least support the [ ] anonymous array construction method of Fortran2003, instead of having to use that god awful \( \) or is it (\ \) or (\ )\ or \( )\ (I can never remember, but now that it's been several years...) method! :)


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.

March 2024

S M T W T F S
     12
3456789
10111213141516
17181920212223
24 252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 25th, 2025 11:18 pm
Powered by Dreamwidth Studios