Fortran
1957fraglethistoricalimperativestructured.f.f90.f95.f03.f08
docker run --rm --platform="linux/amd64" 100hellos/fortran:latest
MCP + fragletc
MCPstdinargs
This language supports code execution via MCP and the fragletc CLI. Stdin piping and argument passing are both supported.
Install fragletc →Fortran is a historical imperative and structured language first appearing in 1957.
Hello World
program hello
! BEGIN_FRAGLET
print *, "Hello World!"
! END_FRAGLET
end program helloCoding Guide
Language Version
Fortran (GNU Fortran compiler, gfortran)
Execution Model
- Compiled language using gfortran (GNU Fortran compiler)
- Code is compiled to a binary, then executed
- Standard Fortran execution model with
programblock
Key Characteristics
- Statically typed
- Case-insensitive
- Column-based formatting (free-form in Fortran 90+)
- Requires explicit compilation step
- Uses gfortran compiler (GCC-based Fortran compiler)
Fragment Authoring
Write valid Fortran statements. Your fragment becomes the program body, so do not include program/end program. You can include use statements at the top of your fragment.
Available Modules
Standard Fortran modules are available:
print *for formatted output- Standard Fortran intrinsic functions
iargc()andgetarg(i, arg)for command-line arguments
Common Patterns
- Output:
print *, "message" - Variables:
integer :: x = 10 - Arrays:
integer, dimension(10) :: arr - Loops:
do i = 1, 10 ... end do - Conditionals:
if (condition) then ... end if - Functions:
function name(x) result(y) ... end function - Subroutines:
subroutine name(x) ... end subroutine
Examples
! Simple output
print *, "Hello from fragment!"
! Variables and calculations
integer :: a = 5
integer :: b = 10
print *, "Sum:", a + b
! Loops
integer :: i
do i = 1, 5
print *, "Count:", i
end do
! Arrays
integer, dimension(5) :: numbers = [1, 2, 3, 4, 5]
integer :: sum = 0
integer :: i
do i = 1, 5
sum = sum + numbers(i)
end do
print *, "Array sum:", sumCaveats
- Fragments must be valid Fortran code that compiles
- Fortran is case-insensitive
- Use
print *,for output (the*means default formatting) - Variables must be declared before use (or use implicit typing)
- The code is compiled fresh each time, so compilation errors will fail execution
- Fortran uses 1-based array indexing by default
- String concatenation uses
//operator - Integer division truncates (use
realfor floating-point division)
Fraglet Scripts
Echo Args
#!/usr/bin/env -S fragletc --vein=fortran
integer :: n, i
character(256) :: arg
n = iargc()
write(*, '(a)', advance='no') 'Args:'
do i = 1, n
call getarg(i, arg)
write(*, '(a)', advance='no') ' ' // trim(arg)
end do
print *Stdin Upper
#!/usr/bin/env -S fragletc --vein=fortran
character(256) :: line
integer :: io, ci
read(*, '(a)', iostat=io) line
do while (io == 0)
do ci = 1, len_trim(line)
if (line(ci:ci) >= 'a' .and. line(ci:ci) <= 'z') line(ci:ci) = achar(iachar(line(ci:ci)) - 32)
end do
print *, trim(line)
read(*, '(a)', iostat=io) line
end doTest
#!/usr/bin/env -S fragletc --vein=fortran
print *, "Hello World!"