SpectraRust/CLAUDE.md
2026-03-19 14:05:33 +08:00

81 lines
2.6 KiB
Markdown

# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Overview
Fortran stellar atmosphere modeling suite being refactored to Rust. Strategy: **split Fortran into modules first, then incrementally rewrite in Rust**.
- **TLUSTY 208**: Non-LTE stellar atmosphere calculator (50,009 lines → 304 modules)
- **SYNSPEC 54**: Synthetic spectrum evaluator (23,917 lines → 168 modules)
## Environment Variables
```bash
export TL208=/home/fmq/program/tlusty
export TLUSTY=$TL208/tl208-s54
export LINELIST=$TL208/linelist
export IRON=$TL208/irondata
export OPTABLES=$TL208/optables
```
## Build Commands
```bash
# Production (single file)
gfortran -O3 -fno-automatic -mcmodel=large -o tlusty/tlusty.exe tlusty/tlusty208.f
gfortran -O3 -fno-automatic -mcmodel=large -o synspec/synspec.exe synspec/synspec54.f
# Development (modular)
python3 extract_fortran.py tlusty/tlusty208.f tlusty/extracted/
cp tlusty/*.FOR tlusty/extracted/
cd tlusty/extracted && make # Output: build/tlusty_extracted
```
**Compile flags:**
- `-mcmodel=large`: Required for large COMMON blocks (>2GB address space)
- `-fno-automatic`: Static storage (old Fortran compatibility)
- **Never use** `-ffixed-line-length-none`: Breaks columns 73-80 handling
## Running Tests
```bash
# TLUSTY: H-He model test
cd tests/tlusty/hhe
$TLUSTY/tlusty/tlusty.exe < hhe35lt.5 > hhe35lt.6
cp fort.7 hhe35lt.7
diff hhe35lt.7 hhe35lt.7.bak # Verify against expected
# SYNSPEC: spectrum test
cd tests/synspec/hhe
ln -sf $TLUSTY/data data # MUST be symlink, not file
cp hhe35nl.7 fort.8
ln -sf fort.55.con fort.55
$TLUSTY/synspec/synspec.exe < hhe35nl.5
# Output: fort.7 (spectrum), fort.17 (continuum)
```
## Module Extraction
`extract_fortran.py` splits monolithic Fortran into individual `.f` files:
- Generates Makefile with correct flags
- Analyzes COMMON block dependencies
- Identifies pure functions (no COMMON) for independent testing
- Handles unnamed BLOCK DATA units
## Key Architecture
**TLUSTY include files** define COMMON blocks shared across subroutines:
- `BASICS.FOR`: Array dimensions (`MDEPTH`=100, `MFREQ`=135000, `MLEVEL`=1134)
- `ATOMIC.FOR`: Atomic masses, abundances, energy levels
- `MODELQ.FOR`: Temperature, density, populations
- `ARRAY1.FOR`: Main linear equation arrays
**SYNSPEC** reads model atmosphere from `fort.8`, outputs spectrum to `fort.7`.
## Refactoring Notes
- Pure functions (no COMMON dependency) can be rewritten independently
- TLUSTY has 195 pure units, SYNSPEC has 93
- See `memory/MEMORY.md` for detailed extraction results and test procedures