Starlink / ast

Starlink AST Library
GNU Lesser General Public License v3.0
12 stars 11 forks source link

calling AST from Fortran 90 #22

Open jvo203 opened 4 months ago

jvo203 commented 4 months ago

It seems the Fortran bindings in AST are terribly, terribly outdated and cannot be used together with, for example, Fortran 90 or newer.

The 'AST_PAR' file uses old fixed-form FORTRAN 77. Even after converting it to newer free-form Fortran 90 and including it in a new Modern Fortran 2018 project, the AST functions cannot be called from within Fortran.

Frankly, the entire Fortran interface to AST needs a complete overhaul to make use of modern C <--> Fortran 2018 interoperability, each AST function should have a proper interface to C with all the function arguments listed explicitly etc., instead of being plain INTEGER types, and the Fortran interface file should be made a Fortran module.

It is a lot of work for the AST team but, as things stand at the moment, it is impossible to use Starlink AST in Fortran right now. I've been trying to switch from WCSLIB to AST in my Fortran 2018 code but had to give up.

Is Fortran not loved anymore? Surely this is not the case.

jvo203 commented 4 months ago

FYI, Fortran 2003 defines ISO C Binding: https://fortranwiki.org/fortran/show/iso_c_binding An example: https://fortranwiki.org/fortran/show/c_interface_module

Just as you did with the F77 interface file, it should be possible to programmatically generate a Modern Fortran interface module file ast.f90 from a C header file (there are just too many functions to convert manually). One needs to be careful about passing function arguments by value or reference as and when required.

Then for legacy F77 systems one would use the existing INCLUDE 'AST_PAR', and for Fortran 2003 and newer (there is already Fortran 2023) simply use the new ast module defined in ast.f90, i.e. USE ast .

timj commented 4 months ago

This seems like a great idea. Unfortunately I'm not sure if there is any effort available to do any of it. I don't think EAO have any use of or experience of Fortran 90 that would motivate them to do this. I don't think any Starlink contributor knows any of the new Fortran dialects either.

jvo203 commented 4 months ago

Yeah, that's the problem! Insufficient resources and a general decline in the use of Fortran these days. Younger people are not inclined to learn Fortran anymore...