Commit 1d616e81 authored by Michael Dunphy's avatar Michael Dunphy Committed by Christopher Subich
Browse files

Embed the case file source in the SPINS binary.

The case file source code is embedded into the binary at compile time.
At runtime, the source code is printed to spinscase.cpp. This eliminates
the need to maintain a copy of the case file alongside the binary.
parent c6a0c6d5
...@@ -8,8 +8,16 @@ using namespace NSIntegrator; ...@@ -8,8 +8,16 @@ using namespace NSIntegrator;
using blitz::Array; using blitz::Array;
using std::vector; using std::vector;
/* Implementation of non-abstract methods in BaseCase */ /* Call the source code writing function in the constructor */
extern "C" {
void WriteCaseFileSource(void);
}
BaseCase::BaseCase(void)
{
if (master()) WriteCaseFileSource();
}
/* Implementation of non-abstract methods in BaseCase */
int BaseCase::numActive() const { return 0; } int BaseCase::numActive() const { return 0; }
int BaseCase::numPassive() const { return 0; } int BaseCase::numPassive() const { return 0; }
int BaseCase::numtracers() const { /* total number of tracers */ int BaseCase::numtracers() const { /* total number of tracers */
......
...@@ -19,6 +19,9 @@ class BaseCase { ...@@ -19,6 +19,9 @@ class BaseCase {
only passive tracers */ only passive tracers */
public: public:
/* Constructor */
BaseCase();
/* Tracers */ /* Tracers */
virtual int numActive() const; // Number of active tracers virtual int numActive() const; // Number of active tracers
virtual int numPassive() const; // Number of passive tracers virtual int numPassive() const; // Number of passive tracers
......
#include <stdio.h>
/* Write the source code of the case to spinscase.cpp */
void WriteCaseFileSource(void)
{
FILE* fid;
fid=fopen("spinscase.cpp","w");
fprintf(fid,"/* %s */\n%s",casefilename,casefilesource);
fclose(fid);
}
...@@ -48,34 +48,43 @@ all: tests/test_deriv_x tests/test_write_x tests/test_esolve_x tests/test_heat_x ...@@ -48,34 +48,43 @@ all: tests/test_deriv_x tests/test_write_x tests/test_esolve_x tests/test_heat_x
.PHONY: clean .PHONY: clean
clean: clean:
rm -f *.o tests/*.o cases/*.o rm -f *.o tests/*.o cases/*.o cases/*.src.? tests/*.src.?
objfiles: $(shell ls *.cpp | sed -e 's/cpp/o/g') objfiles: $(shell ls *.cpp | sed -e 's/cpp/o/g')
NSIntegrator.o: NSIntegrator.cpp NSIntegrator_impl.cc NSIntegrator.o: NSIntegrator.cpp NSIntegrator_impl.cc
tests/test%.o: tests/tests%.cpp tests/test%.o: tests/test%.cpp
$(MPICXX) $(CFLAGS) -o $@ -c $< $(MPICXX) $(CFLAGS) -o $@ -c $<
tests/test%_x: tests/test%.o TArray.o Parformer.o T_util.o ESolver.o Timestep.o NSIntegrator.o BaseCase.o Science.o Splits.o Par_util.o Split_reader.o gmres.o gmres_1d_solver.o gmres_2d_solver.o grad.o multigrid.o Options.o tests/test%_x: tests/test%.o tests/test%.src.o TArray.o Parformer.o T_util.o ESolver.o Timestep.o NSIntegrator.o BaseCase.o Science.o Splits.o Par_util.o Split_reader.o gmres.o gmres_1d_solver.o gmres_2d_solver.o grad.o multigrid.o Options.o
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
cases/%.o: cases/%.cpp NSIntegrator_impl.cc NSIntegrator.hpp cases/%.o: cases/%.cpp NSIntegrator_impl.cc NSIntegrator.hpp
$(MPICXX) $(CFLAGS) -o $@ -c $< $(MPICXX) $(CFLAGS) -o $@ -c $<
nonhydro_x: nonhydro_sw.o TArray.o T_util.o Parformer.o Splits.o Par_util.o Split_reader.o nonhydro_x: nonhydro_sw.o TArray.o T_util.o Parformer.o Splits.o Par_util.o Split_reader.o
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
derek_x: derek.o TArray.o T_util.o Parformer.o ESolver.o Timestep.o Splits.o Par_util.o Split_reader.o gmres.o gmres_1d_solver.o gmres_2d_solver.o grad.o multigrid.o derek_x: derek.o TArray.o T_util.o Parformer.o ESolver.o Timestep.o Splits.o Par_util.o Split_reader.o gmres.o gmres_1d_solver.o gmres_2d_solver.o grad.o multigrid.o
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
cases/%.x: cases/%.o TArray.o T_util.o Parformer.o ESolver.o Timestep.o NSIntegrator.o BaseCase.o Science.o Splits.o Par_util.o Split_reader.o gmres.o gmres_1d_solver.o gmres_2d_solver.o grad.o multigrid.o Options.o cases/%.x: cases/%.o cases/%.src.o TArray.o T_util.o Parformer.o ESolver.o Timestep.o NSIntegrator.o BaseCase.o Science.o Splits.o Par_util.o Split_reader.o gmres.o gmres_1d_solver.o gmres_2d_solver.o grad.o multigrid.o Options.o
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
cases/%_x: cases/%.o TArray.o T_util.o Parformer.o ESolver.o Timestep.o NSIntegrator.o BaseCase.o Science.o Splits.o Par_util.o Split_reader.o gmres.o gmres_1d_solver.o gmres_2d_solver.o grad.o multigrid.o Options.o cases/%_x: cases/%.o cases/%.src.o TArray.o T_util.o Parformer.o ESolver.o Timestep.o NSIntegrator.o BaseCase.o Science.o Splits.o Par_util.o Split_reader.o gmres.o gmres_1d_solver.o gmres_2d_solver.o grad.o multigrid.o Options.o
$(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
tests/test%.src.c: tests/test%.cpp CaseFileSource.c
echo "const char casefilesource[] = {`xxd -i < $<`, 0x00};" > $@
echo "const char casefilename[] = \"$<\";" >> $@
cat CaseFileSource.c >> $@
cases/%.src.c: cases/%.cpp CaseFileSource.c
echo "const char casefilesource[] = {`xxd -i < $<`, 0x00};" > $@
echo "const char casefilename[] = \"$<\";" >> $@
cat CaseFileSource.c >> $@
%.o: %.cpp *.hpp %.o: %.cpp *.hpp
$(MPICXX) $(CFLAGS) -o $@ -c $< $(MPICXX) $(CFLAGS) -o $@ -c $<
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment