Basics
Hello
Program and Implicit None
Every Fortran source has a program unit. implicit none disables Fortran's legacy implicit typing, so every name must be declared.
Program
Play the program to watch a character name flow into a greeting and print.
hello.f90
Replay: real traced execution (multi-file project)
program hello
implicit none
character(len=20) :: name
name = "Ada"
print '(A)', "Hello, " // trim(name) // "!"
end program hello
name ← Ada
3character(len=20) :: name4name = "Ada"5print '(A)', "Hello, " // trim(name) // "!"values this stepAdanameprint '(A)', "Hello, " // trim(name) // "!"
4 name = "Ada"5 print '(A)', "Hello, " // trim(name) // "!"6end program hellooutputHello, Ada!values this stepAdaname
Follow the Greeting
- The program declares
nameas a character value with room for 20 characters. name = "Ada"stores the textAda.trim(name)removes the unused blank space afterAda.- The pieces join into
Hello, Ada!. printwrites that greeting. | piece | value | | --- | --- | |name| Ada | |trim(name)| Ada | | printed text | Hello, Ada! |
program
`program ... end program` wraps the main entry point.
implicit none
`implicit none` forces every variable to be explicitly declared.
// and trim
`//` concatenates strings; `trim` removes trailing blanks.
Exercise: hello.f90
Reproduce the printed greeting Hello, Ada!, then change the name and predict the exact greeting before running it.