I often use Compiler Explorer to test out new Fortran ideas. Today I’ve just discovered that the C include mechanism can also be used to fetch files at internet locations.
To demonstrate this, I’ve attached to this post a module with the following contents:
module greetings_mod
contains
subroutine greetings()
print *, "Greetings from Fortran Discourse"
end subroutine
end module
greetings_mod.f90.txt (122 Bytes)
When you click on the attachment, you actually get redirected to the address,
https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/free1/uploads/fortran_lang/original/2X/f/fb79e1b65ec5e698fdbd1cd5be536ad878b3f252.txt
(I used the webpage WhereGoes to figure this out)
Now you can include this file by using the C preprocessor,
! In Compiler Explorer
#include "https://cdck-file-uploads-canada1.s3.dualstack.ca-central-1.amazonaws.com/free1/uploads/fortran_lang/original/2X/f/fb79e1b65ec5e698fdbd1cd5be536ad878b3f252.txt"
program main
use greetings_mod
call greetings()
end program
To see the output, visit Compiler Explorer.
Here is a demo of fetching a file from Fortran stdlib:
! In Compiler Explorer
#include "https://raw.githubusercontent.com/fortran-lang/stdlib/refs/heads/master/src/stdlib_system.F90"
program main
use stdlib_system, only: sleep
print *, "Sleeeeeeping..."
call sleep(millisec=2000)
print *, "Woken up."
end program
If you like Compiler Explorer, please consider becoming a sponsor or a contributor. (This is just my personal endorsement.)
Have fun!