I have revived @FortranTip after letting it be dormant since June 2022 and plan to tweet at a frequency between daily and weekly. Several tweets have been “ripped from the [Fortran Discourse] headlines”. If you think a Fortran project would be of wide interest and has not been mentioned yet, please post here or message me. For example, projects for plotting, automatic differentiation, numerical optimization, and machine learning could be covered.
Before I was mostly tweeting about features of the Fortran language, but I need to learn about newer features like coarrays before tweeting about them. It will be fun to post about Fortran 2023 features as they become available in compilers.
I choose not to give any more cycles to Xitter than are absolutely necessary. There’s quite a sizable Fortran/HPC community on Mastodon, with the mast.hpc.social server being popular.
Twitter now is very hard to use if you’re not logged in. I dont know if it’s common knowledge or not: you can replace twitter.com with nitter.net and get a mirror that works better, ie https://nitter.net/fortrantip
Very useful. Thanks for creating this collection of tips. It would have saved me countless hours.
Here are my two cents to the topic. Among the tips that would have been useful to me I can site:
And I do not know if you consider preprocessing has an intrinsic part of the language, but I had a deep dive into fpp recently and here is what I found out: Gotchas
Only named variables can be substituted:
#define f(x) sqrt(x)
f([1.0d0, 2.0d0]) !does not work
!but
x = [1.0d0, 2.0d0]
f(x) !works
Even commented defined macros are substituted:
!f(x) will be changed to !sqrt(x)
Trick
Macro can be used to simulate array accessor. Since arrays in fortran require all the elements to have the same size it is quite common to use a wrapper. The most common case is probably the use of array of deferred length strings:
type string_t
character(:), allocatable :: string
end type
type(string_t), allocatable :: strings(:)
allocate(strings(2))
strings(1)%string = "string"
strings(2)%string = "another string"
Being familiar with other languages I would have love to see the possibility to overload array accessor of derived types (i.e. having strings(1) = “string”). It’s not perfect but this can be mimicked with a macro
I think this one is dangerous (and likely not standard conforming). If actual(..) is a non-contiguous array, then actual_array(:) won’t access the right elements.
I agree, it should come with a big warning (or not been discussed at all). But i still found it useful in my case because it transforms rank(0) to a rank(1)-array and then I only deal with arrays.
This is very true. So, for those of us who are not (mandarin-pronounced) Xitting, why couldn’t the FortranTips appear also on our Discourse, as a separate topic, possibly w/o comments allowed, or very limited?
As I wrote earlier, many FortranTips will be based on discussions here, in which case it will be redundant to post them. Today I did tweet an independent tip –