fortran-lang / webpage

New Fortran webpage
https://fortran-lang.org/en
MIT License
45 stars 38 forks source link

Fortran Best Practice: Multidimensional Arrays #91

Open awvwgk opened 2 years ago

awvwgk commented 2 years ago

The chapter Multidimensional Arrays should explain performance implications by the choice of indexing.

nbehrnd commented 1 year ago

@awvwgk At present apparently absent (and perceived missing) is an example to showcase the definition and subsequent use of a multidimensional allocatable array for the purpose of reading a tabulator separated/comma separated input file for subsequent computations on matrix level.

Because your background includes chemistry, Panagiotopoulos's example of an input file reporting structures with atom's charges and (x,y,z) coordinates (link) might serve as source for inspiration. I'm aware that an alternative approach perhaps could be the definition of a new data type (e.g., mission_type in the discussion about How to read CSV data with fields that contain spaces?), but this likely requires even more advanced comprehension of Fortran's working.

awvwgk commented 1 year ago

Because your background includes chemistry, Panagiotopoulos's example of an input file reporting structures with atom's charges and (x,y,z) coordinates (link) might serve as source for inspiration.

Then I'm not the best person to write such an example for sure. I actually have written a bunch of readers for atomic geometries and even made them available as an fpm project (mctc-lib).

Checkout one of the simplest formats available, like xmol, the implementation is already surprisingly complex:

https://github.com/grimme-lab/mctc-lib/blob/main/src/mctc/io/read/xyz.f90

I understand that we are looking for a toy-example, but I wouldn't like to advertise a non-robust implementation for atomic geometries in a best practice guide. There are already too many broken readers with poor error handling for those around.