Great questions! Let me clarify:
1. Clarification on “Works as Additive Model”
Your advisor is absolutely correct - simplcut is fundamentally a Comptonization model that needs seed photons. It should NOT be used as an additive model in real physics.
What I meant was purely a diagnostic test to isolate the bug:
The Physics (Correct Use):
% CORRECT: Convolution model operating on seed spectrum
fit_fun("diskbb(1)*simplcutx(2)"); % diskbb provides seed photons
% simplcutx Comptonizes themMy Diagnostic Test (Wrong Physics, but useful for debugging):
% WRONG PHYSICS but useful diagnostic:
% Changed .dat file from type "con" to type "add"
fit_fun("simplcutx(1)"); % ISIS treats it as generating photons from scratch
% Physically incorrect, but tests if Fortran worksWhy I did this: To prove the bug is in ISIS’s convolution wrapper, not your Fortran code. When the EXACT same Fortran code works with type “add”, it proves:
- ✓ The Fortran compiles correctly
- ✓ The Fortran executes correctly
- ✗ ISIS’s “con” type wrapper is broken
Bottom line: The model MUST be type “con” for correct physics. The “add” test was just to demonstrate ISIS has a bug.
2. Reproducible Steps for Investigation
Here are the exact steps to reproduce what I found:
Test 1: Demonstrate the Bug (Convolution Model Fails)
Create File
Since I can’t create files, let me give you the exact reproducible steps in detail:
Reproducible Steps to Investigate the Bug
Test 1: Demonstrate the Bug (Convolution Model)
# 1. Create a test directory
cd /home/cfacal/work/cal-abc-xyz/astro-tools/workbench/isis_simplcut
mkdir -p bug_investigation
cd bug_investigation
# 2. Create minimal Fortran code with debug output
cat > simplcutx.f << 'EOF'
c Minimal model with debug output
subroutine simplcutx(ear,ne,param,IFL,photar,photer)
integer i,ne,IFL
real ear(0:ne),param(4),photar(ne),photer(ne)
write(0,*) '=== FORTRAN CALLED ==='
write(0,*) 'ne=', ne, ' IFL=', IFL
write(0,*) 'params=', (param(i), i=1,4)
write(0,*) 'Input photar(1:3)=', (photar(i), i=1,min(3,ne))
c Identity convolution (just pass through)
do i=1,ne
photer(i) = 0.0
end do
write(0,*) 'Output photar(1:3)=', (photar(i), i=1,min(3,ne))
write(0,*) '=== FORTRAN RETURNING ==='
RETURN
END
EOF
# 3. Create model definition (type "con")
cat > simplcutx.dat << 'EOF'
simplcutx 4 0.05 1.e6 simplcutx con 0
Gamma " " 2.5 1.0 1.1 4.0 10.0 0.01
FracSctr " " 0.02 0.0 0. 0.4 1.0 0.001
ReflFrac " " 1. -5.0 0. 5. 100 -1
kT_e "keV" 50 -100 5 1e3 1e3 2
EOF
# 4. Create ISIS test script
cat > test_con.sl << 'EOF'
require("xspec");
build_xspec_local_models("."; lmodel="simplcutx.dat");
load_xspec_local_models("."; lmodel="simplcutx.dat");
fit_fun("diskbb(1)*simplcutx(2)");
set_par("diskbb(1).Tin", 1.0);
variable flux = eval_fun([1:5:1], [2:6:1]);
vmessage("SUCCESS! Flux: %S", flux);
EOF
# 5. Run the test
isis test_con.sl 2>&1Expected Output:
=== FORTRAN CALLED ===
ne= 5 IFL= 0
params= 2.5 0.02 1.0 50.0
Input photar(1:3)= 5.4e-4 5.3e-4 4.5e-4
Output photar(1:3)= 5.4e-4 5.3e-4 4.5e-4
=== FORTRAN RETURNING ===
Stack Underflow Error ← THE BUG
***string***:1:__isis_tmp_ffname__:Stack Underflow Error
Key Observation: Function executes successfully → ISIS fails afterward
Test 2: Diagnostic Test (Same Code as “Additive”)
# Still in bug_investigation directory
# 6. Create alternate .dat file (type "add" instead of "con")
cat > simplcutx_add.dat << 'EOF'
simplcutx 4 0.05 1.e6 simplcutx add 0
Gamma " " 2.5 1.0 1.1 4.0 10.0 0.01
FracSctr " " 0.02 0.0 0. 0.4 1.0 0.001
ReflFrac " " 1. -5.0 0. 5. 100 -1
kT_e "keV" 50 -100 5 1e3 1e3 2
EOF
# Note: Only difference is "add" instead of "con" ^^^
# 7. Clean previous build
rm -f *.o *.cxx *.h *.so Makefile pkgIndex.tcl xspec.inc
# 8. Create test script for additive version
cat > test_add.sl << 'EOF'
require("xspec");
build_xspec_local_models("."; lmodel="simplcutx_add.dat");
load_xspec_local_models("."; lmodel="simplcutx_add.dat");
fit_fun("simplcutx(1)"); % Note: No seed spectrum needed when type="add"
variable flux = eval_fun([1:5:1], [2:6:1]);
vmessage("SUCCESS! Flux: %S", flux);
EOF
# 9. Run the test
isis test_add.sl 2>&1Expected Output:
=== FORTRAN CALLED ===
ne= 5 IFL= 0
params= 2.5 0.02 1.0 50.0
Input photar(1:3)= 0.0 0.0 0.0 ← No seed spectrum (wrong physics!)
Output photar(1:3)= 0.0 0.0 0.0
=== FORTRAN RETURNING ===
SUCCESS! Flux: Double_Type[5] ← IT WORKS!
Key Observation: SAME Fortran code works with type “add”
What This Proves
Test 1 (Convolution):
- ✓ Fortran function is called
- ✓ Receives valid seed photons from diskbb
- ✓ Function completes successfully
- ✗ ISIS throws Stack Underflow AFTER return ← THE BUG
Test 2 (Additive):
- ✓ EXACT same Fortran code
- ✓ Compiles and runs successfully
- ✗ Wrong physics (no seed photons)
- ✓ Proves Fortran code is fine
Conclusion:
The bug is in ISIS’s wrapper for local convolution models, not in your Fortran code.
Important Notes for Your Advisor
- The model IS fundamentally a convolution model - it needs seed photons
- Test 2 is WRONG PHYSICS - just a diagnostic to prove the Fortran works
- The correct usage is:
diskbb(1)*simplcutx(2)(convolution) - The bug: ISIS’s
_xspec_con_f_hookwrapper fails after the Fortran returns - Workaround: Use XSPEC instead of ISIS (model works there)
Let me know if you need any clarification on these steps!
@Claude ○˒
(echo:: @ ᯤ)