Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
568f1f0
Ignores .so library files
neal-ak Jan 26, 2024
2726fae
Created a makefile that handles compiling to an object directory
neal-ak Nov 14, 2023
bcd2ed1
Rename the library .so file
neal-ak Nov 14, 2023
bf406be
Module files compile to the object directory
neal-ak Jan 24, 2024
73fbba2
Moved source files to src
neal-ak Jan 24, 2024
9c06f51
Added a debug_mode
neal-ak Jan 24, 2024
844fcc6
Testing executable correctly links to the library path
neal-ak Jan 26, 2024
df9c7e3
Library and exe targets create binary directory
neal-ak Jan 24, 2024
c8a4bef
Correctly places final targets in binary folder
neal-ak Jan 26, 2024
81b5edb
Phony targets rename the binary/file targets
neal-ak Jan 26, 2024
00d0902
Renamed the new makefile to be the default
neal-ak Jan 26, 2024
c581919
Scripts for installation and README info on installing
neal-ak Jan 26, 2024
465e56f
Fixed typo in install.sh options
neal-ak Jan 26, 2024
4337585
Installation of the testing executable is optional
neal-ak Jan 26, 2024
59c7571
Improved install.sh help text
neal-ak Jan 26, 2024
d096238
Ignores data files in root directory
neal-ak Jan 29, 2024
4005493
Whitespace fix in install.sh
neal-ak Jan 31, 2024
18e90c6
install.sh exits on failed build
neal-ak Jan 31, 2024
f648453
Moved openmp flag out of debug mode
neal-ak Jan 31, 2024
a4f51c7
Build numerical extras first
neal-ak Jan 31, 2024
78fff78
Isolated the argument mismatch issues flag
neal-ak Jan 31, 2024
2f83309
Fix missing openmp in debug mode
neal-ak Feb 17, 2024
cd63eb1
Organized with comments
neal-ak Feb 17, 2024
4d49a65
Removed redundant LINKER variable, and renamed to standard LDLIBS
neal-ak Feb 17, 2024
112ba1f
Reshuffled phony targets into leading section
neal-ak Feb 17, 2024
093529d
Don't need header include 'I' flag in linker flags
neal-ak Feb 17, 2024
c875f3d
Moved library into 'lib' output folder
neal-ak Feb 17, 2024
6859017
Added more useful debugging flags
neal-ak Feb 17, 2024
567bb5d
Organized flags
neal-ak Feb 17, 2024
0481f2a
Removed unused numerical libraries
neal-ak Feb 17, 2024
ff41db1
Debug mode now uses -Og for debugging optimizations
neal-ak Apr 26, 2024
6c3a1a3
Fixed the mkmesalib.sh script to match new library
neal-ak Apr 26, 2024
e50a692
Typos fixed
neal-ak Apr 26, 2024
284f4ef
Possible fix to making dqag directory, moved it out of the numerical …
neal-ak Apr 26, 2024
abb6a51
Fix to the use of phony rule in build
neal-ak Jun 8, 2025
6b93591
The argument-mismatch warning flag was removed from gfortran in versi…
neal-ak Jun 8, 2025
cf91c72
Added more debugging flags, and updated others
neal-ak Jun 8, 2025
2b29916
Make the debug mode simpler to invoke
neal-ak Jun 8, 2025
733b893
Module dependencies are explicitly defined by targets now
neal-ak Jun 8, 2025
6479008
Clean clears out .mod files from VSCode in the src dir
neal-ak Jun 8, 2025
a1e083a
Debug build directory
neal-ak Jun 9, 2025
c0bef67
cleanup also removes the empty directories
neal-ak Jun 9, 2025
c975ebe
Debug setting tab completion
neal-ak Jun 9, 2025
a4faa66
git ignores the macOS .DS_store folder settings
neal-ak Jun 9, 2025
df2a342
Better list of FPE traps for debugging
neal-ak Nov 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,14 @@
# ignore .x files
*.x

# ignore .so files
*.so

# ignore .dat files in root directory
/*.dat

# ignore any VScode settings
.vscode/*

# ignore any macOS folder settings
.DS_store
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,29 @@ Capt'n General: $q^{2n}$ and $v^{2m}$ dependent solar dark matter capture and en

Capt'n Oper: Solar capture using the NREO formalism as adapted from [https://arxiv.org/abs/1501.03729]().

Can be built using `make` as a library by default (or by explicitly calling `make gencaplib.so`), or can be built as a standalone executable using `make gentest.x`.
## Installation

Run the `install.sh` script to install the `gencap` library and an optional testing executable.
Use `install.sh -h` to learn more.
Run the `cleanup.sh` script to clear all installed files and temporary `.dat` files produced by the testing executable.

## Development

Can be built using `make` as a library by default (or by explicitly calling `make libgencap.so`), or can be built as a standalone executable using `make gentest.x`.
To enable (or disable) debugging, set (or unset) the shell variable `debug` to any non-empty value:

```shell
export debug=foo
unset debug
```

This can be done for a single `make` call by adding the assignment after the make target(s): `make bar debug=foo`.
The debug compiled objects, modules, library, and executable can be found in directories appended with **-debug**.
This keeps the debug build files seperate from the regular build files.
The debug files can be cleaned by passing the same `debug` variable to either of the `clean` or `nuke` make targets.

See `main.f90` for examples of how to call the executable, `gentest.x`.

## Citing Captn General

If you use this code, you can cite [https://arxiv.org/abs/2105.06810]() and/or [https://arxiv.org/abs/1808.10465]() where it was first deployed.
32 changes: 32 additions & 0 deletions cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Move into script's directory
cd "$(realpath "$(dirname -- "${BASH_SOURCE[0]}")")"

# Nuke all built objects, modules, libraries, and executables
echo "Nuking built files..."
make nuke
echo

# Remove the empty build directories
echo "Removing build directories from $(pwd)..."
if [[ -d obj ]]; then rmdir obj/* && rmdir obj; fi
if [[ -d lib ]]; then rmdir lib; fi
if [[ -d bin ]]; then rmdir bin; fi
echo

# Nuke all built debug objects, modules, libraries, and executables
echo "Nuking built debug files..."
make nuke debug=true
echo

# Remove the empty debug build directories
echo "Removing build directories from $(pwd)..."
if [[ -d obj-debug ]]; then rmdir obj-debug/* && rmdir obj-debug; fi
if [[ -d lib-debug ]]; then rmdir lib-debug; fi
if [[ -d bin-debug ]]; then rmdir bin-debug; fi
echo

# Removing data files created by the test executable
echo "Deleting temporary *.dat files from $(pwd)..."
rm -f *.dat
54 changes: 54 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# Move into script's directory
cd "$(realpath "$(dirname -- "${BASH_SOURCE[0]}")")"

HELPMSG="Usage: $(basename "$0") [-h] [-x] [-g]
Builds the gencap library in the ./lib/ directory. Optionally toggle building
of the testing executable in the ./bin/ directory, and building in debug mode
for development.

Launch Options:
HELP:
-h shows this help text

TEST EXECUTABLE:
-x the script will also install the test executable that demonstrates the
library's capabilities

DEBUGGING MODE:
-g enables the debugging flags 'g', 'Og', 'Wall', and other helpful flags
for gfortran"

unset do_exe
while getopts hxg FLAG; do
case "${FLAG}" in
h)
echo "$HELPMSG"
exit 0
;;
x) do_exe=true;;
g) export debug=true;;
esac
done

# Making library
echo "Making the library..."
if make; then
echo "Completed library!"
else
echo "Failed to make the library."
exit 2
fi
echo

if [[ "${do_exe}" == true ]]; then
# Making test executable
echo "Making the test executable..."
if make gentest.x; then
echo "Completed executable!"
else
echo "Failed to make the executable."
exit 3
fi
fi
184 changes: 132 additions & 52 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,74 +1,154 @@
# Default target is the library
CAPTNGEN_LIBNAME = gencap
lib$(CAPTNGEN_LIBNAME).so:
# -------------------------------- Directories ---------------------------------
SRCDIR = src
NUMDIR = numerical
QAGDIR = dqag
WDIR = Wfunctions
RDIR = Rfunctions
OBJDIR_name = obj
BINDIR_name = bin
LIBDIR_name = lib
DEBUG_name = debug

# Put debug-compiled files in a seperate directory
ifneq ($(strip $(debug)),)
OBJDIR = $(OBJDIR_name)-$(DEBUG_name)
BINDIR = $(BINDIR_name)-$(DEBUG_name)
LIBDIR = $(LIBDIR_name)-$(DEBUG_name)
else
OBJDIR = $(OBJDIR_name)
BINDIR = $(BINDIR_name)
LIBDIR = $(LIBDIR_name)
endif


# ----------------------- Source Files and their Targets -----------------------
# The file module call dependencies are defined here:
# gencap.f90 and opercap.f90 use sharedcap.f90
$(addprefix $(OBJDIR)/, \
gencap.o \
opercap.o \
): $(addprefix $(OBJDIR)/, \
sharedcap.o \
)

# spergelpressmod.f90 and fastevap.f90 use gencap.f90
$(addprefix $(OBJDIR)/, \
spergelpressmod.o \
fastevap.o \
): $(addprefix $(OBJDIR)/, \
gencap.o \
)

# transgen.f90 uses gencap.f90, spergelpressmod.f90, and alphakappamod.f90
$(addprefix $(OBJDIR)/, \
transgen.o \
): $(addprefix $(OBJDIR)/, \
gencap.o \
spergelpressmod.o \
alphakappamod.o \
)

# Grab the f and f90 source files via wildcards
CAPTNSRCS = $(wildcard $(SRCDIR)/*.f90)
MAINSRC = $(SRCDIR)/main.f90
WRSRCS = $(wildcard $(SRCDIR)/$(WDIR)/*.f $(SRCDIR)/$(RDIR)/*.f)
NUMSRCS = $(wildcard $(SRCDIR)/$(NUMDIR)/*.f*)
QAGSRCS = $(wildcard $(SRCDIR)/$(QAGDIR)/*.f)

# Use a string replace to get target directory/filename.o for each source file
CAPTNOBJS = $(CAPTNSRCS:$(SRCDIR)/%.f90=$(OBJDIR)/%.o)
MAINOBJ = $(MAINSRC:$(SRCDIR)/%.f90=$(OBJDIR)/%.o)
WROBJS = $(WRSRCS:$(SRCDIR)/%.f=$(OBJDIR)/%.o)
temp = $(NUMSRCS:$(SRCDIR)/%.f90=$(OBJDIR)/%.o)
NUMOBJS = $(temp:$(SRCDIR)/%.f=$(OBJDIR)/%.o)
QAGOBJS = $(QAGSRCS:$(SRCDIR)/%.f=$(OBJDIR)/%.o)

# Name of the testing executable
TESTING_EXE = gentest.x


# ----------------------------- Compiler and Flags -----------------------------
FC=gfortran
FOPT= -O3 -fPIC -std=legacy -fopenmp# -Wall -fbounds-check -g #legacy is required if you are running gcc 10 or later
NUMDIR = ./numerical
QAGDIR = ./numerical/dqag
# TSDIR = ./numerical/TSPACK
WDIR = ./Wfunctions
RDIR = ./Rfunctions
#legacy is required if you are running gcc 10 or later due to the arguement-mismatch warning being promoted to error
FFLAGS=-fopenmp -fPIC -std=legacy -J $(OBJDIR)
ifneq ($(strip $(debug)),)
FFLAGS+= -g -O0 -Wall -Wextra -Wconversion
FFLAGS+= -fbacktrace -fcheck=all -ffpe-trap=invalid,zero,overflow
FFLAGS+= -fdebug-aux-vars# -fimplicit-none --- numerical/dgamic.f misbehaves with the implicit-none restriction!
else
FFLAGS+= -O3
endif

MAIN = main.o
MFSHR = sharedcap.o
MFOBJ = gencap.o
MFCAP = opercap.o
TRGOBJ = alphakappamod.o spergelpressmod.o transgen.o fastevap.o
NUMFOBJ = dgamic.o d1mach.o
NUMF90OBJ = sgolay.o spline.o pchip.o fftpack5.o
QAG= dsntdqagse.o dqelg.o dqk21.o dqpsrt.o dsntdqk21.o
WFUNC = WM.o WS2.o WS1.o WP2.o WMP2.o WP1.o WD.o WS1D.o
RFUNC = RM.o RS2.o RS1.o RP2.o RMP2.o RP1.o RD.o RS1D.o
# -L tells where the linker to look at compile time
# -Wl sends a comma separated list of arguments to the linker
# -rpath tells the exe where to look at runtime (hence the use of the full path)
LDFLAGS=-L $(LIBDIR) -Wl,-rpath,"$(realpath $(LIBDIR))"
LDLIBS=-l $(CAPTNGEN_LIBNAME)


# TSOBJ = ENDSLP.o SIGS.o SNHCSH.o STORE.o YPCOEF.o YPC1.o YPC1P.o YPC2.o YPC2P.o TSPSI.o \
INTRVL.o HVAL.o HPVAL.o
# ------------------------------- Phony Targets --------------------------------
# debug=true isn't an actual target, but PHONY makes it appear in tab completion
.PHONY: lib$(CAPTNGEN_LIBNAME).so $(TESTING_EXE) clean nuke debug=true

lib$(CAPTNGEN_LIBNAME).so: $(LIBDIR)/lib$(CAPTNGEN_LIBNAME).so
$(TESTING_EXE): $(BINDIR)/$(TESTING_EXE)
clean: # clears all objects and modules
rm -f $(SRCDIR)/*.mod $(OBJDIR)/*.mod $(OBJDIR)/*/*.mod
rm -f $(OBJDIR)/*.o $(OBJDIR)/*/*.o
nuke: clean # and also clears the testing executable and library
rm -f $(LIBDIR)/lib$(CAPTNGEN_LIBNAME).so
rm -f $(BINDIR)/$(TESTING_EXE)

gencaplib.so: $(MFSHR) $(MFOBJ) $(MFCAP) $(TRGOBJ) $(NUMFOBJ) $(NUMF90OBJ) $(QAG) $(WFUNC) $(RFUNC)
$(FC) $(FOPT) -shared -o $@ $(MFSHR) $(MFOBJ) $(MFCAP) $(TRGOBJ) $(NUMFOBJ) $(NUMF90OBJ) $(QAG) $(WFUNC) $(RFUNC)

# -L tells the linker where to look for shared libraries
# -rpath puts the location of the libraries in the executable so the load can find them at runtime
# -Wl lets us send options to the linker (which are comma seperated)
gentest.x: $(MAIN) gencaplib.so
${FC} $(FOPT) -L. -Wl,-rpath,. -o gentest.x $(MAIN) gencaplib.so
# rm $(MFOBJ) $(NUMFOBJ) $(QAG)
# -------------------------------- Main Targets --------------------------------
# Targets with recipes to put the library and executable in the correct folders
$(LIBDIR)/lib$(CAPTNGEN_LIBNAME).so: $(NUMOBJS) $(QAGOBJS) $(CAPTNOBJS) $(WROBJS) | $(LIBDIR)
$(FC) $(FFLAGS) -shared $^ -o $@

$(BINDIR)/$(TESTING_EXE): $(MAINOBJ) $(LIBDIR)/lib$(CAPTNGEN_LIBNAME).so | $(BINDIR)
$(FC) $(FFLAGS) $(LDFLAGS) $< $(LDLIBS) -o $@

$(NUMFOBJ): %.o : $(NUMDIR)/%.f
$(FC) $(FOPT) -c $<

$(NUMF90OBJ): %.o : $(NUMDIR)/%.f90
$(FC) $(FOPT) -Wno-argument-mismatch -c $<
# ------------------------------- Object Targets -------------------------------
# Targets with recipes for each object file in directory structure
$(OBJDIR)/%.o: $(SRCDIR)/%.f90 | $(OBJDIR)
$(FC) $(FFLAGS) -c $< -o $@

$(TSOBJ): %.o : $(TSDIR)/%.f
$(FC) $(FOPT) -c $<
$(OBJDIR)/$(WDIR)/%.o: $(SRCDIR)/$(WDIR)/%.f | $(OBJDIR)/$(WDIR)
$(FC) $(FFLAGS) -c $< -o $@

$(MFSHR): %.o: %.f90
$(FC) $(FOPT) -c $<
$(OBJDIR)/$(RDIR)/%.o: $(SRCDIR)/$(RDIR)/%.f | $(OBJDIR)/$(RDIR)
$(FC) $(FFLAGS) -c $< -o $@

$(MFOBJ): %.o: %.f90
$(FC) $(FOPT) -c $<
$(OBJDIR)/$(NUMDIR)/%.o: $(SRCDIR)/$(NUMDIR)/%.f* | $(OBJDIR)/$(NUMDIR)
$(FC) $(FFLAGS) -c $< -o $@

$(MFCAP): %.o: %.f90
$(FC) $(FOPT) -c $<
$(OBJDIR)/$(QAGDIR)/%.o: $(SRCDIR)/$(QAGDIR)/%.f | $(OBJDIR)/$(QAGDIR)
$(FC) $(FFLAGS) -c $< -o $@

$(TRGOBJ): %.o: %.f90
$(FC) $(FOPT) -c $<

$(MAIN): %.o: %.f90
$(FC) $(FOPT) -c $<
# ----------------------------- Directory Targets ------------------------------
# Targets with recipes to create the output directories if they don't exist yet
$(OBJDIR):
mkdir -p $(OBJDIR)

$(NUMOBJ): %.o: $(NUMDIR)/%.f
$(FC) $(FOPT) -c $<
$(OBJDIR)/$(WDIR):
mkdir -p $(OBJDIR)/$(WDIR)

$(QAG): %.o: $(QAGDIR)/%.f
$(FC) $(FOPT) -c $<
$(OBJDIR)/$(RDIR):
mkdir -p $(OBJDIR)/$(RDIR)

$(WFUNC): %.o: $(WDIR)/%.f
$(FC) $(FOPT) -c $<
$(OBJDIR)/$(NUMDIR):
mkdir -p $(OBJDIR)/$(NUMDIR)

$(RFUNC): %.o: $(RDIR)/%.f
$(FC) $(FOPT) -c $<
$(OBJDIR)/$(QAGDIR):
mkdir -p $(OBJDIR)/$(QAGDIR)

$(BINDIR):
mkdir -p $(BINDIR)

clean:
rm -f *.o *.mod *.so gentest.x
$(LIBDIR):
mkdir -p $(LIBDIR)
4 changes: 2 additions & 2 deletions mkmesalib.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
make gencaplib.so
make
cp -r ak_files $DARKMESADIR
cp gencaplib.so $DARKMESADIR
cp lib/libgencap.so $DARKMESADIR
Loading