Skip to content

Instantly share code, notes, and snippets.

@v1kko
v1kko / hello_world.f90
Last active February 2, 2022 12:23
code_1
subroutine hello_world(name)
write(*,*) "Hello World: ", name
end subroutine
@v1kko
v1kko / compile.sh
Created February 2, 2022 12:25
code_2
> gfortran main.f90 hello_world.f90 -o hello_world
> ./hello_world
Hello World 544567129
@v1kko
v1kko / signature.f90
Created February 2, 2022 12:27
code_3
subroutine hello_world(name : character(len=*))
@v1kko
v1kko / compile.rst
Last active February 2, 2022 12:35
code_4
> gfortran -fimplicit-none -Werror=implicit-interface main.f90 hello_world.f90 -o hello_world
 main.f90:2:31:

   2 |   call hello_world("You there")
     |                               1
 Error: Procedure ‘hello_world’ called with an implicit interface at (1) [-Werror=implicit-interface]
@v1kko
v1kko / main.f90
Last active February 2, 2022 12:40
code_5
program main
implicit none
call hello_world("You there")
contains
include 'hello_world.f90'
end program
@v1kko
v1kko / main.f90
Created February 2, 2022 12:40
code_6
program main
interface
subroutine hello_world(name)
character(len=*) :: name
end subroutine
end interface
implicit none
call hello_world("You there")
end program
module hello_world_mod
contains
subroutine hello_world(name)
implicit none
write(*,*) "Hello World: ", name
end subroutine
end module
@v1kko
v1kko / compile.rst
Last active February 2, 2022 12:48
code_8
# We will come back to the -fimplicit-none later
> gfortran -c -Werror=implicit-interface hello_world.f90
> gfortran -Werror=implicit-interface main.f90 -o hello_world
main.f90:3:31:

  3 |   call hello_world("You there")
    |                               1
Error: Type mismatch in argument ‘name’ at (1); passed CHARACTER(1) to INTEGER(4)
@v1kko
v1kko / hello_world.f90
Created February 2, 2022 12:44
code_9
module hello_world_mod
contains
subroutine hello_world(name)
implicit none ! This should be present in all procedures
character(len=*) :: name
write(*,*) "Hello World: ", name
end subroutine
end module
@v1kko
v1kko / compile.rst
Last active February 2, 2022 12:46
code_10
# create hello_world_mod.mod and hello_world.o
> gfortran -c -fimplicit-none -Werror=implicit-interface hello_world.f90
# create main.o
> gfortran -c -fimplicit-none -Werror=implicit-interface main.f90
# link and create hello_world binary
> gfortran main.o hello_world.o -o hello_world
# Execute the program
> ./hello_world