ahay/src/authoring-sf-programs-f77

Claude Code and agent skill by ahay/src

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when authoring a Madagascar sf* main program in Fortran 77.

Install

npx vskill@latest install ahay/src/authoring-sf-programs-f77

SKILL.md

When to use

Use this skill for Madagascar processing programs in Fortran 77 fixed-format (file extension .f, program named M<Name>.f). Typical scenarios: maintaining legacy fixed-format code, porting existing F77 algorithms, or working with research groups that standardize on gfortran -std=legacy or ifort.

F77 vs F90 key differences:

AspectF77F90
Source formatFixed-format; code starts at column 7Free-format
ContinuationAny non-space/zero char in column 6& at end of line
File extensionM<name>.fM<name>.f90
CommentsC or * in column 1! anywhere
Loopsdo 10 i=1,n … 10 continuedo i=1,n … end do

For shared conventions (SConstruct rules, self-doc headers, naming) see skills/authoring-sf-programs/.


Skeleton

Minimal F77 program derived from api/f77/Testfile.f and api/f77/test/clip.f. Columns 1-6 are reserved; statement body starts at column 7; continuation marker goes in column 6.

fortran
C Mclip.f -- clip float data to +/- clip
program Clipit
implicit none
integer*8 in, out
integer*8 sf_input, sf_output, sf_leftsize
logical sf_getfloat, sf_histint
integer n1, n2, i1, i2
real clip, trace(1000)
call sf_init()
in = sf_input("in")
out = sf_output("out")
if (.not. sf_histint(in,"n1",n1))
& call sf_error("No n1= in input")
if (.not. sf_getfloat("clip",clip))
& call sf_error("Need clip=")
n2 = sf_leftsize(in,1)
do 10 i2=1, n2
call sf_floatread(trace, n1, in)
do 20 i1=1, n1
if (trace(i1) .gt. clip) trace(i1) = clip
if (trace(i1) .lt. -clip) trace(i1) = -clip
20 continue
call sf_floatwrite(trace, n1, out)
10 continue
stop
end

Column layout reminder:

123456789...
C comment (C in col 1)
statement (col 7+)
&continuation (col 6)
10 label (cols 1-5)

API cheat sheet

All calls go through the librsff wrapper (fortran.c + cfortran.h). Functions returning a value must be declared with the appropriate Fortran type.

Init and file handles — declare file handles as integer*8:

CallReturnsPurpose
call sf_init()—Initialize Madagascar (must be first)
sf_input("in")integer*8Open named input RSF file
sf_output("out")integer*8Open named output RSF file
call sf_fileclose(f)—Close file handle
call sf_close()—Finalize I/O

History reads — declare as logical; .false. means key absent:

CallPurpose
sf_histint(f,"n1",i)Read integer header key
sf_histfloat(f,"d1",x)Read float header key
sf_histbool(f,"key",b)Read logical header key
sf_histstring(f,"label")Read string (function returning character*)

History writes (call subroutines, no return value):

CallPurpose
call sf_putint(f,"n2",i)Write integer to output header
call sf_putfloat(f,"d2",x)Write float
call sf_putstring(f,"label",str)Write string

Command-line param reads — declare as logical; .true. if key found:

CallPurpose
sf_getint("niter",i)Read integer param
sf_getfloat("clip",x)Read float param
sf_getfloats("d",xv,n)Read n floats
sf_getbool("verb",b)Read yes/no param
sf_getstring("tag")Read string (function)

Data I/O (call subroutines):

CallPurpose
call sf_floatread(buf, n, f)Read n floats from f
call sf_floatwrite(buf, n, f)Write n floats to f
call sf_intread(buf, n, f)Read n integers
call sf_intwrite(buf, n, f)Write n integers
call sf_complexread(buf, n, f)Read n complex values
call sf_complexwrite(buf, n, f)Write n complex values

Utility:

CallReturnsPurpose
sf_leftsize(f, dim)integer*8Elements past dimension dim
sf_gettype(f)integerData type code (3 = float)
call sf_error("msg")—Print and abort
call sf_warning("msg")—Print, continue

Build integration

The F77 API builds only when f77 appears in the SCons API list (api/f77/SConstruct):

  1. Detects compiler via env.get('F77'); sets -DGFORTRAN or

-DINTEL_COMPILER accordingly.

  1. Compiles fortran.c (with cfortran.h) into fortran.o.
  2. Bundles into librsff.a (static library) and installs to lib/.
  3. User programs link against both librsff and core librsf.

Typical user SConstruct snippet:

python
env.Append(LIBS=['rsff', 'rsf'])
env.Program('sfclip', ['Mclip.f'])
# For strict fixed-format:
env.Replace(F77FLAGS='-std=legacy -ffixed-form')

cfortran.h handles name-mangling: gfortran (single underscore) vs f2c-style (double underscore) via compile-time defines.


Pointers

Files in /Users/jgoai/m8r/src/api/f77/:

FileDescription
fortran.cC wrapper; FCALLSC* macros expose every sf_* function to F77
cfortran.hThird-party (Burkhard Burow/DESY) Fortran↔C name-mangling header
Testfile.fSmoke-test: open in/out, read 100-float traces, write them back
Testgetpar.fExercises all param-read calls (sf_getint, sf_getfloat, etc.)
SConstructBuilds librsff.a, installs to lib/, compiles test programs
test/clip.fComplete real program: float clipping with header inspection
test/SConstructSCons build for the test/ example programs

Shared conventions

General Madagascar conventions (self-documentation strings, parameter help, SCons Program builder, installation targets) are in:

skills/authoring-sf-programs/

F77-specific reminders:

  • Declare sf_input, sf_output, sf_leftsize, sf_filesize as integer*8

— file handles and offsets are 64-bit on modern systems.

  • Declare param-query functions (sf_getint, sf_histfloat, …) as logical

to test them in if (.not. …) guards.

  • Use implicit none — F77 implicit typing silently maps i-n to integer

and the rest to real, hiding declaration bugs.

  • Continuation: place the continuation character in column 6 only.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
352
Repository forks
191
7-day trend score
29

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/ahay/src/authoring-sf-programs-f77/badge)](https://verified-skill.com/skills/ahay/src/authoring-sf-programs-f77)

Something wrong with this skill or its page? Tell us.