diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d1feb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +Makefile.inc +dstar/Makefile.inc +**/*.o +**/*.a +starev +dstar/Normalisation +dstar/SeBa +**/*.data + diff --git a/Makefile b/Makefile index 290352b..810d999 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CXXFLAGS += -I./include -I./include/star -DHAVE_CONFIG_H -DTOOLBOX -Wconversion +CXXFLAGS += -I./include -I./include/star -DHAVE_CONFIG_H -Wconversion LDLIBS += -Lsstar -lsstar -Lnode -lnode -Lstd -lstd -lm CFLAGS += -O CXXFLAGS += -O @@ -16,6 +16,12 @@ test: Makefile.inc: Makefile.inc.conf @sed s#__BASE__#$(PWD)#g Makefile.inc.conf >Makefile.inc +starev.o: starev.C + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -DTOOLBOX -c -o $@ $^ + +starev: starev.o + $(CXX) -o $@ $(LDFLAGS) $< $(LDLIBS) + lib: Makefile.inc @for d in $(DIRS) ; do echo '\nmake' $@ in $$d; make -C $$d $@ ; done diff --git a/dstar/Makefile b/dstar/Makefile index 8db9c17..6febd45 100755 --- a/dstar/Makefile +++ b/dstar/Makefile @@ -1,6 +1,6 @@ CXXFLAGS += -I../include -I../include/star \ -D_SRC_='"no_source_available"' \ - -DHAVE_CONFIG_H -DTOOLBOX + -DHAVE_CONFIG_H LDLIBS += \ -L. -ldstar \ -L../sstar -lsstar \ @@ -17,6 +17,15 @@ DIRS = init io starclass stardyn util all: lib $(EXE) +%.o: %.C + $(CXX) -o $@ $(CPPFLAGS) $(CXXFLAGS) -DTOOLBOX -c $< + +SeBa: SeBa.o + $(CXX) -o $@ $(LDFLAGS) $^ $(LDLIBS) + +Normalisation: Normalisation.o + $(CXX) -o $@ $(LDFLAGS) $^ $(LDLIBS) + Makefile.inc: Makefile.inc.conf @sed s#__BASE__#$(PWD)#g Makefile.inc.conf >Makefile.inc diff --git a/dstar/SeBa.C b/dstar/SeBa.C index c6bd16e..3cff4d8 100644 --- a/dstar/SeBa.C +++ b/dstar/SeBa.C @@ -146,7 +146,7 @@ local bool evolve_binary(dyn * bi, real start_time, real end_time, bool stop_at_merger_or_disruption, bool stop_at_remnant_formation, - char* SeBa_outfile) { + const char* SeBa_outfile) { double_star* ds = dynamic_cast(double_star*, @@ -251,10 +251,9 @@ int main(int argc, char ** argv) { real start_time = 0; real end_time = 13500;//35; - char* input_filename; - char* output_filename; + const char* input_filename; + const char* output_filename; output_filename = "SeBa.data"; - //char output_filename = new char "SeBa.data"; int input_seed=0; char seedlog[64]; diff --git a/dstar/init/initdouble.C b/dstar/init/initdouble.C index 395057c..f171125 100644 --- a/dstar/init/initdouble.C +++ b/dstar/init/initdouble.C @@ -641,7 +641,7 @@ void adddouble(node * b, real dyn_time, real e_min, real e_max) { if (REPORT_ADD_DOUBLE) { - int p = cerr.precision(HIGH_PRECISION); + std::streamsize p = cerr.precision(HIGH_PRECISION); cerr<<"adddouble: "<pretty_print_tree(cerr); cerr << " a=" << sma << " e=" << ecc << endl; @@ -204,7 +204,7 @@ local void do_the_adding(hdyn *bi, real stellar_time, // bi is binary CM new_double->set_star_story(old_story); if (REPORT_ADD_DOUBLE) { - int p = cerr.precision(HIGH_PRECISION); + std::streamsize p = cerr.precision(HIGH_PRECISION); cerr<<"After adddouble: at "<dump(cerr); od->get_kepler()->print_all(cerr); @@ -231,7 +231,7 @@ void adddouble(hdyn *b, // b is binary CM real e_min, real e_max) { if (REPORT_ADD_DOUBLE) { - int p = cerr.precision(HIGH_PRECISION); + std::streamsize p = cerr.precision(HIGH_PRECISION); cerr<<"adddouble: "<get_oldest_daughter() != NULL && - has_dstar(bi->get_oldest_daughter())) { - - bst = make_state(bi); - if(bst.type==which) { - N_total++; - content[bst.primary.type].stypes[bst.secondary.type]++; - } - } - - int N_row = 0; - if(N_total>0) { - - // cerr << " "; - // for (int j=0; j0) { - cerr << " " << type_short_string((stellar_type)k); - - // for (int i = 0; i < no_of_stellar_type-1; i++) - // cerr << " " << content[i].stypes[k]; - // cerr << endl; - for (int i=0; i<=dynamic_cast(int, Super_Giant); i++) - cerr << " " << content[i].stypes[k]; - cerr << " "; - for (int i=Carbon_Star; iget_oldest_daughter() - ->get_starbase()->get_star_story(), "Type")) { - addstar(b, // Note that T_start and - b->get_system_time(), // Main_Sequence are - Main_Sequence, // defaults. They are - true); // ignored if a star - - b->set_use_sstar(true); - - adddouble(b, b->get_system_time()); - - b->set_use_dstar(true); - } - - if (i++ > 0) cerr << endl; - dstar_stats(b, mass_spectrum, zero, verbose); - - if (out) put_hdyn(b); - rmtree(b); - } -} - -#endif diff --git a/dstar/util/makedouble.C b/dstar/util/makedouble.C index 1c90958..655a8e7 100644 --- a/dstar/util/makedouble.C +++ b/dstar/util/makedouble.C @@ -86,7 +86,7 @@ local void evolve_the_stellar_system(node* b, real time) { } } -void main(int argc, char ** argv) { +int main(int argc, char ** argv) { bool A_flag = false; bool a_flag = false; diff --git a/include/dyn.h b/include/dyn.h index 472aa6c..8fcfc1c 100644 --- a/include/dyn.h +++ b/include/dyn.h @@ -658,7 +658,7 @@ bool parse_sys_stats_main(int argc, char *argv[], bool &n_sq, bool &out, int &verbose, - char *cvs_id, char *source); + const char *cvs_id, const char *source); void check_addstar(dyn* b); /// General statistics and diagnostics on an N-body system. @@ -811,7 +811,7 @@ bool parse_scale_main(int argc, char *argv[], bool& q_flag, real& q, bool& r_flag, real& r, bool& debug, - char *cvs_id, char *source); + const char *cvs_id, const char *source); /// Scale masses, radii, and velocities according to various criteria. diff --git a/include/star/double_star.h b/include/star/double_star.h index 3b53e62..df4db30 100644 --- a/include/star/double_star.h +++ b/include/star/double_star.h @@ -198,7 +198,7 @@ class double_star : public star // I/O functions. void dump(ostream &, bool brief = true); - void dump(char*, bool); + void dump(const char*, bool); void put_element(); void print_status(); void print_roche(); diff --git a/include/star/single_star.h b/include/star/single_star.h index 7333150..2dd1d9e 100644 --- a/include/star/single_star.h +++ b/include/star/single_star.h @@ -26,6 +26,9 @@ #include "star.h" #include "star_state.h" +#include + + /*----------------------------------------------------------------------------- * star -- the standard class for stellar evolution, with core and envelope *----------------------------------------------------------------------------- @@ -47,7 +50,7 @@ class single_star : public star // AMUSE real time_offset; // AMUSE - real CHE_flag; // (AD Oct 4 2022) + bool CHE_flag; // (AD Oct 4 2022) real relative_mass; real relative_helium_mass; @@ -207,7 +210,7 @@ class single_star : public star void read_element(); void put_element(); void dump(ostream&, bool brief = true); - void dump(char*, bool brief = true); + void dump(const char*, bool brief = true); void print_status(); void print_roche(); void put_state(); @@ -234,9 +237,9 @@ class single_star : public star const real x_guess, const real y_value, const real z = 0, const real xmin = cnsts.parameters(minimum_main_sequence), const real xmax = cnsts.parameters(maximum_main_sequence)); - real update_core_and_envelope_mass(const real m_core); - real update_core_and_envelope_mass_TPAGB(const real m_core); - real update_COcore_mass(const real mco_core); + bool update_core_and_envelope_mass(const real m_core); + bool update_core_and_envelope_mass_TPAGB(const real m_core); + bool update_COcore_mass(const real mco_core); // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -362,10 +365,20 @@ class single_star : public star // real small_envelope_core_luminosity(){return 0;}; // real small_envelope_core_radius(){return 0;}; // real helium_core_radius(){return 0;}; - - virtual real small_envelope_core_luminosity(){}; - virtual real small_envelope_core_radius(){}; - virtual real helium_core_radius(){}; +// don't do this either, as it returns an arbitrary value that could mess up your result: +// real small_envelope_core_luminosity() {}; +// real small_envelope_core_radius() {}; +// real helium_core_radius() {}; + + virtual real small_envelope_core_luminosity() { + throw std::logic_error("Invalid call to small_envelope_core_luminosity()"); + }; + virtual real small_envelope_core_radius() { + throw std::logic_error("Invalid call to small_envelope_core_radius()"); + }; + virtual real helium_core_radius() { + throw std::logic_error("Invalid call to helium_core_radius()"); + }; //white dwarf diff --git a/include/star/star.h b/include/star/star.h index 44d4598..009db22 100644 --- a/include/star/star.h +++ b/include/star/star.h @@ -252,7 +252,7 @@ class star : public starbase // output virtual void dump(ostream &, bool brief = true){} - virtual void dump(char*, bool brief = true){} + virtual void dump(const char*, bool brief = true){} virtual void print_status(){} virtual void print_roche(){} virtual void put_state(){} diff --git a/include/star/star_cluster_HPT2000.h b/include/star/star_cluster_HPT2000.h index 4e15c04..1650eff 100644 --- a/include/star/star_cluster_HPT2000.h +++ b/include/star/star_cluster_HPT2000.h @@ -130,7 +130,7 @@ class star_cluster void put_state(); void put_hrd(ostream &); void dump(ostream &); //char*); - void dump(char*); //char*); + void dump(const char*); //char*); void test_maxwellian_velocities(); // Profiler diff --git a/include/star/star_state.h b/include/star/star_state.h index 909382b..f466c4e 100644 --- a/include/star/star_state.h +++ b/include/star/star_state.h @@ -120,7 +120,7 @@ struct star_state { void put_state(star_state, ostream & s=cerr); void put_short_state(star_state, ostream & s=cerr); -char* type_dominant_state(star_state); +const char* type_dominant_state(star_state); void print_star(starbase*, ostream & s=cerr); void pretty_print_star(starbase*, int depth_level, ostream & s=cerr); void pretty_print_star(starbase*, ostream & s=cerr); diff --git a/include/star/star_support.h b/include/star/star_support.h index 8797919..556c7ab 100644 --- a/include/star/star_support.h +++ b/include/star/star_support.h @@ -63,18 +63,18 @@ enum supernova_type {NAT=0, SN_Ia, SN_Ib, SN_Ic, SN_II, SN_IIL, SN_IIP, SN_IV, no_of_supernova_type}; -char * type_string(stellar_type); -char * type_string(stellar_type_summary); -char * type_string(spectral_class); -char * type_string(luminosity_class); -char * type_string(star_type_spec); -char * type_string(mass_transfer_type); -char * type_string(supernova_type sn_type); -char * type_short_string(star_type_spec); -char * type_short_string(stellar_type); -char * type_short_string(stellar_type_summary); -char * type_short_string(mass_transfer_type); -char * type_short_string(spectral_class); +const char * type_string(stellar_type); +const char * type_string(stellar_type_summary); +const char * type_string(spectral_class); +const char * type_string(luminosity_class); +const char * type_string(star_type_spec); +const char * type_string(mass_transfer_type); +const char * type_string(supernova_type sn_type); +const char * type_short_string(star_type_spec); +const char * type_short_string(stellar_type); +const char * type_short_string(stellar_type_summary); +const char * type_short_string(mass_transfer_type); +const char * type_short_string(spectral_class); stellar_type extract_stellar_type_string(char*); star_type_spec extract_stellar_spec_summary_string(char*); diff --git a/include/stdinc.h b/include/stdinc.h index a95df43..d783123 100644 --- a/include/stdinc.h +++ b/include/stdinc.h @@ -229,9 +229,9 @@ typedef double real; // we also want the quantity // -VERY_LARGE_INTEGER to be legal -#define SETBIT(i, n) ((i) |= (1 << (n))) // set bit n of i -#define GETBIT(i, n) ((i) & (1 << (n))) // get bit n of i -#define CLRBIT(i, n) ((i) &= ~(1 << (n))) // clear bit n of i +#define SETBIT(i, n) ((i) |= (1u << (n))) // set bit n of i +#define GETBIT(i, n) ((i) & (1u << (n))) // get bit n of i +#define CLRBIT(i, n) ((i) &= ~(1u << (n))) // clear bit n of i void printbits(unsigned int i); // print significant nonzero bits //============================================================================= @@ -421,7 +421,7 @@ real cpu_time(); void starlab_wait(int iwait); -int set_starlab_precision(ostream&); +std::streamsize set_starlab_precision(ostream&); int adjust_starlab_precision(int p); int get_starlab_precision(); diff --git a/node/dyn/init/addstoa.C b/node/dyn/init/addstoa.C index 9911189..b9253a4 100644 --- a/node/dyn/init/addstoa.C +++ b/node/dyn/init/addstoa.C @@ -55,7 +55,7 @@ local void addstoa(dyn * b, int m_flag) } } -main(int argc, char ** argv) +int main(int argc, char ** argv) { int m_flag = false; extern char *poptarg; diff --git a/node/dyn/init/apply_plummer.C b/node/dyn/init/apply_plummer.C index 0b53596..6183913 100644 --- a/node/dyn/init/apply_plummer.C +++ b/node/dyn/init/apply_plummer.C @@ -86,7 +86,7 @@ local void addplummer(dyn * b, real mfrac, real rfrac) b->to_com(); } -main(int argc, char ** argv) +int main(int argc, char ** argv) { int random_seed; real mfrac = MFRAC_DEFAULT; diff --git a/node/dyn/init/make_aniso_king.C b/node/dyn/init/make_aniso_king.C index 9697250..1f0ed5f 100644 --- a/node/dyn/init/make_aniso_king.C +++ b/node/dyn/init/make_aniso_king.C @@ -253,7 +253,7 @@ local void make_aniso_king(dyn * b, int n, real w0, real alpha1, real alpha3, ((4*M_PI*RHO_G + 2*(OORT_A*OORT_A - OORT_B*OORT_B)) \ / (-4*OORT_A*(OORT_A-OORT_B))) -main(int argc, char ** argv) +int main(int argc, char ** argv) { real w0; int n = 0; diff --git a/node/dyn/init/makecube.C b/node/dyn/init/makecube.C index 5a493d7..92e5213 100644 --- a/node/dyn/init/makecube.C +++ b/node/dyn/init/makecube.C @@ -84,7 +84,7 @@ local void makecube(dyn *root, int n, #define SEED_STRING_LENGTH 60 -main(int argc, char ** argv) { +int main(int argc, char ** argv) { int i; int n; int input_seed, actual_seed; diff --git a/node/dyn/init/makedisk.C b/node/dyn/init/makedisk.C index 9f0134d..5ebb0bb 100644 --- a/node/dyn/init/makedisk.C +++ b/node/dyn/init/makedisk.C @@ -120,7 +120,7 @@ local void makedisk(dyn* b, int n, #define SEED_STRING_LENGTH 60 -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool c_flag = false; bool C_flag = false; diff --git a/node/dyn/init/makeking.C b/node/dyn/init/makeking.C index 0004b61..6af8629 100644 --- a/node/dyn/init/makeking.C +++ b/node/dyn/init/makeking.C @@ -59,10 +59,9 @@ char tmp_string[SEED_STRING_LENGTH]; // Global stuff: // ------------ -real pi = M_PI; -real twopi = 2.0 * pi; -real four3pi = 4.0 * pi / 3.0; -real fourpi = 4.0 * pi; +real twopi = 2.0 * M_PI; +real four3pi = 4.0 * M_PI / 3.0; +real fourpi = 4.0 * M_PI; real zero = 0.0; real one = 1.0; real quarter = 0.25; @@ -847,7 +846,7 @@ local void makeking(dyn * b, int n, real w0, bool n_flag, bool u_flag, int test) } } -main(int argc, char ** argv) +int main(int argc, char ** argv) { int n; int input_seed, actual_seed; diff --git a/node/dyn/init/makeplummer.C b/node/dyn/init/makeplummer.C index e75965e..71e1f32 100644 --- a/node/dyn/init/makeplummer.C +++ b/node/dyn/init/makeplummer.C @@ -280,7 +280,7 @@ local void reshuffle_all(dyn* b, int n) // the extent of the Plummer realization. //----------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { int i; int n; diff --git a/node/dyn/init/makepyth.C b/node/dyn/init/makepyth.C index ea2eba6..e7781d2 100644 --- a/node/dyn/init/makepyth.C +++ b/node/dyn/init/makepyth.C @@ -31,7 +31,7 @@ #ifdef TOOLBOX -main(int argc, char ** argv) +int main(int argc, char ** argv) { int i; bool c_flag = FALSE; diff --git a/node/dyn/init/makesphere.C b/node/dyn/init/makesphere.C index 3f07f69..1e401ad 100644 --- a/node/dyn/init/makesphere.C +++ b/node/dyn/init/makesphere.C @@ -131,7 +131,7 @@ void makesphere(dyn *root, int n, #define SEED_STRING_LENGTH 60 -main(int argc, char ** argv) { +int main(int argc, char ** argv) { int i; int n; int input_seed, actual_seed; diff --git a/node/dyn/init/makewrite.C b/node/dyn/init/makewrite.C index 7beca69..ff5c920 100644 --- a/node/dyn/init/makewrite.C +++ b/node/dyn/init/makewrite.C @@ -30,7 +30,7 @@ #define SCALE_FACTOR 0.1 -main(int argc, char ** argv) +int main(int argc, char ** argv) { char *comment; bool c_flag = false; diff --git a/node/dyn/init/readstoa.C b/node/dyn/init/readstoa.C index 6520659..5b028ee 100644 --- a/node/dyn/init/readstoa.C +++ b/node/dyn/init/readstoa.C @@ -34,6 +34,12 @@ #ifdef TOOLBOX +local void scanf_check(char const * format, void * value) { + int err = scanf(format, value); + if (err != 0) + throw std::runtime_error("Invalid stoa file detected"); +} + local dyn* read_stoa(bool i_flag) { dyn *root, *by, *bo; @@ -43,9 +49,9 @@ local dyn* read_stoa(bool i_flag) { root = new dyn(); if (i_flag) root->set_label(0); - int n; scanf("%d", &n); PRL(n); - int ndim; scanf("%d", &ndim); PRL(ndim); - real time; scanf("%lf", &time); PRL(time); + int n; scanf_check("%d", &n); PRL(n); + int ndim; scanf_check("%d", &ndim); PRL(ndim); + real time; scanf_check("%lf", &time); PRL(time); root->set_system_time(time); // Create first daughter node. diff --git a/node/dyn/init/split_particle.C b/node/dyn/init/split_particle.C index 5dbd4a3..8949894 100644 --- a/node/dyn/init/split_particle.C +++ b/node/dyn/init/split_particle.C @@ -137,7 +137,7 @@ local void scale_energy(real energy, int N, real M, real E) //---------------------------------------------------------------------- -void main(int argc, char ** argv) +int main(int argc, char ** argv) { real energy = 0.0; real eccentricity = -1; @@ -202,7 +202,7 @@ void main(int argc, char ** argv) // Thus, if the total system energy is known, 'energy' is specified // in "kT" units. If not, 'energy' is the binary kinetic energy. - char* energy_string = "initial_total_energy"; + const char* energy_string = "initial_total_energy"; if (find_qmatch(b->get_log_story(), energy_string)) scale_energy(energy, b->n_daughters(), b->get_mass(), diff --git a/node/dyn/kepler/kepler.C b/node/dyn/kepler/kepler.C index 7795b6b..d518588 100644 --- a/node/dyn/kepler/kepler.C +++ b/node/dyn/kepler/kepler.C @@ -143,7 +143,7 @@ local int check_trig_limit(kepler* k, real &c, const char *s) } } else { if (print_trig_warning) { - int p = cerr.precision(HIGH_PRECISION); + std::streamsize p = cerr.precision(HIGH_PRECISION); cerr << "warning: " << s << ": c = " << c << endl; cerr.precision(p); } @@ -477,7 +477,7 @@ void kepler::kep_to_dyn_story(story * s) void kepler::print_all(ostream & s) { - int p = s.precision(HIGH_PRECISION); + std::streamsize p = s.precision(HIGH_PRECISION); s << " time = " << time << endl; s.precision(8); @@ -526,7 +526,7 @@ void kepler::print_dyn(ostream & s) void kepler::print_elements(ostream & s) { - int p = s.precision(8); + std::streamsize p = s.precision(8); s << " time = " << time << endl; s << " separation = " << separation << endl; @@ -1665,7 +1665,7 @@ local void rr(real r) k.print_dyn(); } -main(int argc, char **argv) +int main(int argc, char **argv) { check_help(); pgetopt(argc, argv, "", "$Revision: 1.17 $", _SRC_); diff --git a/node/dyn/util/add_plummer.C b/node/dyn/util/add_plummer.C index d29f2a2..134bb2b 100644 --- a/node/dyn/util/add_plummer.C +++ b/node/dyn/util/add_plummer.C @@ -59,7 +59,7 @@ void add_plummer(dyn *b, #else -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { bool c_flag = false; char *comment; // comment string diff --git a/node/dyn/util/add_power_law.C b/node/dyn/util/add_power_law.C index 36d6f85..faaf439 100644 --- a/node/dyn/util/add_power_law.C +++ b/node/dyn/util/add_power_law.C @@ -162,7 +162,7 @@ void add_power_law(dyn *b, #else -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { bool c_flag = false; char *comment; // comment string diff --git a/node/dyn/util/add_tidal.C b/node/dyn/util/add_tidal.C index 5517ce2..fcd39f0 100644 --- a/node/dyn/util/add_tidal.C +++ b/node/dyn/util/add_tidal.C @@ -32,7 +32,7 @@ #include "dyn.h" -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { bool c_flag = false; char *comment; // comment string diff --git a/node/dyn/util/compute_com.C b/node/dyn/util/compute_com.C index 0fd1024..78f08f4 100644 --- a/node/dyn/util/compute_com.C +++ b/node/dyn/util/compute_com.C @@ -98,7 +98,7 @@ void compute_com(dyn *b) // main -- driver to use compute_com() as a tool //----------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { char *comment; dyn *b; diff --git a/node/dyn/util/compute_density.C b/node/dyn/util/compute_density.C index f936edf..72574c9 100644 --- a/node/dyn/util/compute_density.C +++ b/node/dyn/util/compute_density.C @@ -116,8 +116,8 @@ void compute_density(dyn * b, // pointer to N-body system or node return; } - neighbor_dist_sq = new real[k+1]; - neighbor_mass = new real[k+1]; + neighbor_dist_sq = new real[static_cast(k+1)]; + neighbor_mass = new real[static_cast(k+1)]; // Set first body d for which density is to be computed. @@ -240,7 +240,7 @@ void compute_density(dyn * b, // pointer to N-body system or node #else -main(int argc, char ** argv) +int main(int argc, char ** argv) { int k = 12; // default diff --git a/node/dyn/util/compute_max_cod.C b/node/dyn/util/compute_max_cod.C index 6ac0afa..d35e303 100644 --- a/node/dyn/util/compute_max_cod.C +++ b/node/dyn/util/compute_max_cod.C @@ -124,7 +124,7 @@ void compute_max_cod(dyn *b) * main -- driver to use compute_max_cod() as a tool *----------------------------------------------------------------------------- */ -main(int argc, char ** argv) +int main(int argc, char ** argv) { char *comment; dyn * b; diff --git a/node/dyn/util/compute_mcom.C b/node/dyn/util/compute_mcom.C index 57cab76..c983d9a 100644 --- a/node/dyn/util/compute_mcom.C +++ b/node/dyn/util/compute_mcom.C @@ -89,7 +89,7 @@ void compute_mcom(dyn *b, int n = 0; for_all_daughters(dyn, b, bb) n++; - rp_pair_ptr rp = new rp_pair[n]; + rp_pair_ptr rp = new rp_pair[static_cast(n)]; if (rp == NULL) { cerr << "compute_mcom: " @@ -179,7 +179,7 @@ void compute_mcom(dyn *b, // main -- driver to use compute_mcom() as a tool //----------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { char *comment; dyn * b; diff --git a/node/dyn/util/compute_mean_cod.C b/node/dyn/util/compute_mean_cod.C index a7bb465..589e0f1 100644 --- a/node/dyn/util/compute_mean_cod.C +++ b/node/dyn/util/compute_mean_cod.C @@ -88,7 +88,7 @@ void compute_mean_cod(dyn *b, vec& pos, vec& vel) && !twiddles(dens_time, (real) b->get_system_time(), TTOL)) { warning("compute_mean_cod: using out-of-date densities."); PRL(d->format_label()); - int p = cerr.precision(HIGH_PRECISION); + std::streamsize p = cerr.precision(HIGH_PRECISION); PRL(b->get_system_time()); PRL(dens_time); cerr.precision(p); @@ -140,7 +140,7 @@ void compute_mean_cod(dyn *b) // main -- driver to use compute_mean_cod() as a tool //----------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { char *comment; dyn * b; diff --git a/node/dyn/util/dumbp.C b/node/dyn/util/dumbp.C index 46c469a..d6ba064 100644 --- a/node/dyn/util/dumbp.C +++ b/node/dyn/util/dumbp.C @@ -24,7 +24,7 @@ #ifdef TOOLBOX -main(int argc, char** argv) +int main(int argc, char** argv) { check_help(); diff --git a/node/dyn/util/dyn_io.C b/node/dyn/util/dyn_io.C index c7d0143..b723f95 100644 --- a/node/dyn/util/dyn_io.C +++ b/node/dyn/util/dyn_io.C @@ -148,7 +148,7 @@ bool dyn::check_and_correct_node(bool verbose) // default = false istream & dyn::scan_dyn_story(istream& s) { char input_line[MAX_INPUT_LINE_LENGTH]; - real last_real = false; + bool last_real = false; while (get_line(s,input_line), !matchbracket(END_DYNAMICS, input_line)) { @@ -294,6 +294,7 @@ dyn *get_dyn(istream & s, // default = cin format = ungetc(getc(ifp), ifp) == '(' ? DYN : COL; return get_dyn(s, the_hbpfp, the_sbpfp, use_stories); } + return NULL; } // Called by get_dyn when input format is columns of numbers. @@ -455,7 +456,7 @@ void put_col(dyn* root, ostream& s, bool put_time) { } else { - int oldp = s.precision(p); + std::streamsize oldp = s.precision(p); // Special treatment to preserve the root node member data // and Log and Dyn stories. @@ -488,7 +489,7 @@ void put_col(dyn* root, ostream& s, bool put_time) { #else -main(int argc, char** argv) +int main(int argc, char** argv) { check_help(); pgetopt(argc, argv, "", "$Revision: 1.32 $", _SRC_); diff --git a/node/dyn/util/dyn_stats.C b/node/dyn/util/dyn_stats.C index 6c5c4ef..9bdf691 100644 --- a/node/dyn/util/dyn_stats.C +++ b/node/dyn/util/dyn_stats.C @@ -27,6 +27,9 @@ #include "dyn.h" +#include + + real print_binary_params(kepler* k, real m1, real kT, real dist_from_center, bool verbose, // default = true @@ -52,7 +55,7 @@ real print_binary_params(kepler* k, real m1, real kT, if (!long_binary_output) { - int p = cerr.precision(LOW_PRECISION); + std::streamsize p = cerr.precision(LOW_PRECISION); cerr << "a= " << k->get_semi_major_axis() << " e= " << k->get_eccentricity() @@ -205,8 +208,8 @@ void print_binary_from_dyn_pair(dyn* bi, dyn* bj, real dist_from_center = abs(primary->get_pos() - center); - int init_indent = 11 - strlen(bi->format_label()); - init_indent -= strlen(bj->format_label()) ; + int init_indent = 11 - static_cast(strlen(bi->format_label())); + init_indent -= static_cast(strlen(bj->format_label())); print_binary_params(&k, primary->get_mass(), kT, dist_from_center, verbose, long_binary_output, @@ -253,7 +256,7 @@ real print_structure_recursive(dyn* bi, else cerr << " U "; cerr << bi->format_label(); - init_indent -= 4 + strlen(bi->format_label()) + indent; + init_indent -= 4 + static_cast(strlen(bi->format_label())) + indent; } real dist_from_center = abs(primary->get_pos() - center); diff --git a/node/dyn/util/dyndiff.C b/node/dyn/util/dyndiff.C index bf98e86..451b4e3 100644 --- a/node/dyn/util/dyndiff.C +++ b/node/dyn/util/dyndiff.C @@ -79,7 +79,7 @@ real dyndiff(dyn * b1, dyn * b2, bool r_flag) return sqrt(sum_sq_diff / (6 * n1)); } -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool r_flag = FALSE; // if TRUE: check only spatial differences diff --git a/node/dyn/util/dyndist.C b/node/dyn/util/dyndist.C index b535868..df6564c 100644 --- a/node/dyn/util/dyndist.C +++ b/node/dyn/util/dyndist.C @@ -137,7 +137,7 @@ void dist_stats(dyn * b1, dyn * b2, int n_intervals) print_sqrt_n_tiles(veldists, n_intervals, n1); } -main(int argc, char ** argv) +int main(int argc, char ** argv) { int n_intervals; bool n_flag = FALSE; diff --git a/node/dyn/util/energy.C b/node/dyn/util/energy.C index c65846c..8921631 100644 --- a/node/dyn/util/energy.C +++ b/node/dyn/util/energy.C @@ -24,7 +24,7 @@ #ifdef TOOLBOX -main(int argc, char **argv) +int main(int argc, char **argv) { dyn *root; int e_flag = 0; diff --git a/node/dyn/util/extract_snap.C b/node/dyn/util/extract_snap.C index 93bd39c..c77bd30 100644 --- a/node/dyn/util/extract_snap.C +++ b/node/dyn/util/extract_snap.C @@ -29,7 +29,7 @@ #ifdef TOOLBOX -main(int argc, char ** argv) +int main(int argc, char ** argv) { char *comment; bool c_flag = FALSE; // if TRUE, a comment given on command line diff --git a/node/dyn/util/flatten.C b/node/dyn/util/flatten.C index d70d119..9196be5 100644 --- a/node/dyn/util/flatten.C +++ b/node/dyn/util/flatten.C @@ -117,7 +117,7 @@ int dyn::flatten_node() // main -- driver to use flatten_node() as a tool. //----------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool c_flag = false; bool C_flag = false; diff --git a/node/dyn/util/freeze.C b/node/dyn/util/freeze.C index acf5bd0..f28b112 100644 --- a/node/dyn/util/freeze.C +++ b/node/dyn/util/freeze.C @@ -33,7 +33,7 @@ local void freeze(dyn * b, real fac) bi->scale_vel(fac); } -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool c_flag = FALSE; char *comment; diff --git a/node/dyn/util/freezebin.C b/node/dyn/util/freezebin.C index 4c297dd..5401305 100644 --- a/node/dyn/util/freezebin.C +++ b/node/dyn/util/freezebin.C @@ -33,7 +33,7 @@ local void freezebin(dyn * b, real fac) if (bi->is_parent()) bi->scale_vel(fac); } -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool c_flag = FALSE; char *comment; diff --git a/node/dyn/util/get_std_center.C b/node/dyn/util/get_std_center.C index b76e394..28b6b7c 100644 --- a/node/dyn/util/get_std_center.C +++ b/node/dyn/util/get_std_center.C @@ -118,7 +118,7 @@ int get_std_center(dyn *b, // main -- driver to use get_std_center() as a tool //----------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { char *comment; dyn * b; diff --git a/node/dyn/util/getsnap.C b/node/dyn/util/getsnap.C index 4c06498..1af1d8b 100644 --- a/node/dyn/util/getsnap.C +++ b/node/dyn/util/getsnap.C @@ -22,6 +22,8 @@ // version 1: July 2002 Simon Portieges Zwart +#ifdef TOOLBOX + #include "dyn.h" /*----------------------------------------------------------------------------- @@ -71,4 +73,6 @@ int main(int argc, char ** argv) } } +#endif + /* endof: snapprune.c */ diff --git a/node/dyn/util/hop.C b/node/dyn/util/hop.C deleted file mode 100644 index 45b41ca..0000000 --- a/node/dyn/util/hop.C +++ /dev/null @@ -1,229 +0,0 @@ - - //=======================================================// _\|/_ - // __ _____ ___ ___ // /|\ ~ - // / | ^ | \ | ^ | \ // _\|/_ - // \__ | / \ |___/ | / \ |___/ // /|\ ~ - // \ | /___\ | \ | /___\ | \ // _\|/_ - // ___/ | / \ | \ |____ / \ |___/ // /|\ ~ - // // _\|/_ -//=======================================================// /|\ ~ - -//// Group-finding tool based on the HOP algorithm for N-body systems -//// (Eisenstein, D.J. & Hut, P., 1998, ApJ 498, 137). This version -//// partitions particles according to HOP, but doesn't merge groups -//// or apply a density threshhold. -//// -//// The algorithm requires that particles have densities associated -//// with them. If none are found, they will be computed internally -//// (*without* using GRAPE!): use get_densities on a GRAPE-enabled -//// machine for a faster computation. -//// -//// Usage: hop < input_snapshot > list_of_clump_memberships -//// -//// Options: -i number the particles sequentially [don't number] -//// -n number of neighbors searched for density extremum -//// -v write snapshot at end [no] -//// -//// Written by Simon Portegies Zwart. - -// Version 1.0: Simon Portegies Zwart, Hamilton, Aug 2004 -// Adapted to starlab: -// Version 1.1: Simon Portegies Zwart, Haarlem, Mar 2005 -// Modified by Steve McMillan, Philadelphia, Sep 2006 - -#ifndef TOOLBOX - -#else - -#include "hop.h" - -dyn* hop::densest_nth_nn(dyn *b) -{ - // Return a pointer to the node with the greatest density - // among the nn_search nearest neighbors of b. - - nearest_neighbor *nn = new nearest_neighbor[nn_search]; - - for_all_daughters(dyn, b->get_root(), bb) { - real sep2 = square(bb->get_pos() - b->get_pos()); - for (int i = 0; i < nn_search; i++) { - if (sep2 < nn[i].d_nn_sq) { - for (int j = nn_search-1; j > i; j--) { - nn[j] = nn[j-1]; - } - nn[i].nn = bb; - nn[i].d_nn_sq = sep2; - break; - } - } - } - real d, dmax = -VERY_LARGE_NUMBER; - int imax; - for (int i = 0; i < nn_search; i++) { - d = getrq(nn[i].nn->get_dyn_story(), "density"); - if (d > dmax) { - dmax = d; - imax = i; - } - } - - return nn[imax].nn; -} - -void hop::add_cluster_center(dyn* bc, dyn *bi) -{ - // Create/update the cluster labeled by the center bc, found - // following the search starting from node bi. - - vector::iterator ic; - bool already_known = false; - - for (ic = cl.begin(); ic < cl.end(); ic++) - if (ic->get_h() == bc) { - already_known = true; - break; - } - - if (already_known) - ic->increment(bi); - else { - cluster ccl(bc, bi); - cl.push_back(ccl); - } -} - -void hop::find_clump_center(dyn *bi) -{ - // Follow the density gradient to the densest neighbor of bi; - // add it to the list of cluster centers if not already on it. - - // cerr << "Finding clump center for i = " << bi->get_index() << endl; - - dyn *onnd, *nnd = bi; - do { - onnd = nnd; - nnd = densest_nth_nn(onnd); - } - while (onnd != nnd); - - // cerr << "clump center id = " << nnd->get_index() << endl; - - // Put the clump center on the list of clumps, update clump - // properties, and associate bi with the clump. - - add_cluster_center(nnd, bi); - putiq(bi->get_dyn_story(), "hop_clump_center_id", nnd->get_index()); -} - -void hop::find_primary_cluster(dyn *b) -{ - if(!nn_search) - nn_search = int(3*sqrt((real)b->n_daughters())); - - for_all_daughters(dyn, b, bi) - find_clump_center(bi); - - // Need an extra routine to merge clumps, as in Eisenstein & Hut. -} - -int main(int argc, char ** argv) -{ - int nth_neighbor = -1; - bool use_nsqrt = true; - - extern char *poptarg; - int c; - const char *param_string = "in:v"; - - check_help(); - - bool i_flag = false; - bool v_flag = false; - - while ((c = pgetopt(argc, argv, param_string)) != -1) - switch(c) { - - case 'i': i_flag = true; - break; - case 'n': nth_neighbor = atoi(poptarg); - use_nsqrt = false; - break; - case 'v': v_flag = true; - break; - case '?': params_to_usage(cerr, argv[0], param_string); - exit(1); - } - - if (use_nsqrt) - cerr << "hop: no nn-th neighbor specified, using sqrt(3n)" << endl; - - bool first = true; - int i = 0; - - dyn* b; - hop *h; - - while((b = get_dyn())) { - - // cerr << "hop: read snapshot #" << i++ << endl; - - if(use_nsqrt) - nth_neighbor = int(3*sqrt((real)b->n_daughters())); - - // See if we need densities (use 12th nearest neighbor of we do). - - bool compute_dens = true; - story *s = b->get_oldest_daughter()->get_dyn_story(); - if (find_qmatch(s, "density_time")) - if (getrq(s, "density_time") == b->get_system_time()) - compute_dens = false; - - if (compute_dens) { - cerr << "hop: computing densities..." << endl; - compute_density(b, 12); - } - - h = new hop(); - h->set_nn_search(nth_neighbor); - - h->find_primary_cluster(b); // decompose system into clums - h->put(); // print out info on the clumps - - - //------------------------------------------------------------- - - // *** Detailed info on the members of each clump is available - // *** as follows: - - vector cl = h->get_cl(); // the list of clusters - vector::iterator i; - - for (i = cl.begin(); i != cl.end(); i++) { - - cluster c = *i; // the current cluster; has - // mass, nstar, pos, vel, and - // a list of nodes in "clump" - - vector clump = c.get_clump(); - vector::iterator ci; - - for (ci = clump.begin(); ci != clump.end(); ci++) { - - dyn *bi = *ci; // current clump member - -// PRC(ci-clump.begin()); // counter -// PRL(bi->get_index()); // (etc.) - } - } - - //------------------------------------------------------------- - - delete h; - - if (v_flag) - put_dyn(b); - } -} - -#endif -/* end of: hop.C */ diff --git a/node/dyn/util/jiggle.C b/node/dyn/util/jiggle.C index 60d5155..6849899 100644 --- a/node/dyn/util/jiggle.C +++ b/node/dyn/util/jiggle.C @@ -55,7 +55,7 @@ local void jiggle(dyn * b, real f) } } -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool c_flag = false, s_flag = false; char *comment; diff --git a/node/dyn/util/lagrad.C b/node/dyn/util/lagrad.C index 0874d11..3c6ec16 100644 --- a/node/dyn/util/lagrad.C +++ b/node/dyn/util/lagrad.C @@ -109,9 +109,9 @@ bool compute_general_mass_radii(dyn * b, char lagr_string[64] = "geometric center"; - int n = 0; + std::size_t n = 0; if (bf == NULL) - n = b->n_daughters(); + n = static_cast(b->n_daughters()); else { for_all_daughters(dyn, b, bb) if ((*bf)(bb)) n++; @@ -171,7 +171,7 @@ bool compute_general_mass_radii(dyn * b, int nmass = nzones - 1; if (nzones < 2) nmass = n_lagr; - real* mass_percent = new real[nmass]; + real* mass_percent = new real[static_cast(nmass)]; if (mass_percent == NULL) { if (verbose) cerr << endl << " " << func @@ -189,7 +189,7 @@ bool compute_general_mass_radii(dyn * b, mass_percent[k] = nonlin_masses[k] * total_mass; } - real *rlagr = new real[nmass]; + real *rlagr = new real[static_cast(nmass)]; if (rlagr == NULL) { if (verbose) cerr << endl << " " << func @@ -304,7 +304,8 @@ void reset_lagr_cutoff_mass(dyn *b, // Lower limit: - int nf = (int)(f_low*m.size()) - 1, i = nf; + std::size_t nf = static_cast((f_low * static_cast(m.size())) - 1); + std::size_t i = nf; if (nf < 0) cutoff_mass_low = 0; else { @@ -317,7 +318,8 @@ void reset_lagr_cutoff_mass(dyn *b, // Upper limit (same procedure, for now): - nf = (int)(f_high*m.size()) - 1, i = nf; + nf = static_cast((f_high * static_cast(m.size())) - 1); + i = nf; if (nf < 0) cutoff_mass_high = 0; else { @@ -441,8 +443,8 @@ real print_lagrangian_radii(dyn* b, cerr << " selected percentiles: "; } - int n_lagr = getiq(b->get_dyn_story(), "n_lagr"); // should be nl - 1 - real *r_lagr = new real[n_lagr]; + int n_lagr = getiq(b->get_dyn_story(), "n_lagr"); // should be nl - 1 + real *r_lagr = new real[static_cast(n_lagr)]; getra(b->get_dyn_story(), "r_lagr", r_lagr, n_lagr); @@ -489,7 +491,7 @@ real compute_lagrangian_radii(dyn* b, // Work with copies... - if (lagr_array == NULL) lagr_array = new real[narr]; + if (lagr_array == NULL) lagr_array = new real[static_cast(narr)]; for (int k = 0; k < narr; k++) lagr_array[k] = arr[k]; n_lagr = narr; @@ -536,7 +538,7 @@ real compute_lagrangian_radii(dyn* b, // main -- driver to use compute_mass_radii() as a tool //----------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { char *comment; int n = 0; diff --git a/node/dyn/util/lagradplot.C b/node/dyn/util/lagradplot.C index 842cc40..839719b 100644 --- a/node/dyn/util/lagradplot.C +++ b/node/dyn/util/lagradplot.C @@ -583,7 +583,7 @@ void plot_mass_radii_in_percentages(dyn * b, int width_factor) // main -- driver to use plot_mass_radii() as a tool //----------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { char *comment; bool c_flag = FALSE; /* if TRUE: a comment given on command line */ diff --git a/node/dyn/util/lagradplotsmooth.C b/node/dyn/util/lagradplotsmooth.C index 303207d..7c6e5f9 100644 --- a/node/dyn/util/lagradplotsmooth.C +++ b/node/dyn/util/lagradplotsmooth.C @@ -240,7 +240,7 @@ char in_screen[MAX_NUMBER_OF_INPUT_LINES][MAX_NUMBER_OF_COLUMNS], int w) // main //----------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { char *comment; bool c_flag = FALSE; /* if TRUE: a comment given on command line */ @@ -298,7 +298,7 @@ main(int argc, char ** argv) c = getchar(); while (c != '\n' && c != EOF) { - in_screen[i][j++] = c; + in_screen[i][j++] = static_cast(c); c = getchar(); } i++; diff --git a/node/dyn/util/list_snap.C b/node/dyn/util/list_snap.C index e70e2c2..5e34747 100644 --- a/node/dyn/util/list_snap.C +++ b/node/dyn/util/list_snap.C @@ -23,7 +23,7 @@ #ifdef TOOLBOX -main(int argc, char ** argv) +int main(int argc, char ** argv) { check_help(); pgetopt(argc, argv, "", "$Revision: 1.5 $", _SRC_); diff --git a/node/dyn/util/merge_low.C b/node/dyn/util/merge_low.C index a9e44c4..89c4127 100644 --- a/node/dyn/util/merge_low.C +++ b/node/dyn/util/merge_low.C @@ -80,7 +80,7 @@ void merge_low_level_nodes(dyn * b, // root node // main -- driver to use flatten_node() as a tool. //----------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool c_flag = FALSE; char *comment; diff --git a/node/dyn/util/merge_snaps.C b/node/dyn/util/merge_snaps.C index 90ec740..e0af55e 100644 --- a/node/dyn/util/merge_snaps.C +++ b/node/dyn/util/merge_snaps.C @@ -26,7 +26,7 @@ #ifdef TOOLBOX -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool renumber = true; check_help(); diff --git a/node/dyn/util/molecules.C b/node/dyn/util/molecules.C index 801fec9..902b3c5 100644 --- a/node/dyn/util/molecules.C +++ b/node/dyn/util/molecules.C @@ -28,6 +28,7 @@ //............................................................................. #include "dyn.h" +#include #ifdef TOOLBOX @@ -1540,7 +1541,7 @@ local void print_binary_parameters(char node_report[BUFF_LENGTH], real struct_table[NNODE_MAX][N_STRUCT], int member) { - int offset_in_node_report; + std::ptrdiff_t offset_in_node_report; real semimajor_axis; offset_in_node_report = end_of_string(node_report) - node_report; @@ -1613,7 +1614,7 @@ local void print_binary_parameters(char node_report[BUFF_LENGTH], local void print_radius(char node_report[BUFF_LENGTH], real struct_table[NNODE_MAX][N_STRUCT], int member) { - int offset_in_node_report; + std::ptrdiff_t offset_in_node_report; real r_node; offset_in_node_report = end_of_string(node_report) - node_report; @@ -2034,7 +2035,7 @@ local void wrap_string(char substring[BUFF_LENGTH], substring[++i] = '\0'; } -main(int argc, char ** argv) +int main(int argc, char ** argv) { check_help(); pgetopt(argc, argv, "", "$Revision: 1.8 $", _SRC_); diff --git a/node/dyn/util/plot_stars.C b/node/dyn/util/plot_stars.C index 600a582..6d96e55 100644 --- a/node/dyn/util/plot_stars.C +++ b/node/dyn/util/plot_stars.C @@ -27,7 +27,7 @@ local real find_neighbors(dyn *bi, dyn **list, int n) // note: this n is n+1! { dyn *root = bi->get_root(); - real *dr2 = new real[n]; + real *dr2 = new real[static_cast(n)]; for (int i = 0; i < n; i++) { list[i] = NULL; dr2[i] = VERY_LARGE_NUMBER; @@ -75,7 +75,7 @@ void plot_stars(dyn * bi, // Make a list of the n (actual, not projected) nearest neighbors of bi. // Convenient to keep bi at location 0. - dyn **list = new dynptr[n+1]; + dyn **list = new dynptr[static_cast(n+1)]; real scale = find_neighbors(bi, list, n+1); if (scale <= 0) return; @@ -139,9 +139,9 @@ void plot_stars(dyn * bi, || i == 0 || i == HBINS-1 || j == 0 || j == VBINS-1) { if (m < 10) - disp[i][j] = '0' + m; + disp[i][j] = '0' + static_cast(m); else - disp[i][j] = 'a' + m - 10; + disp[i][j] = 'a' - 10 + static_cast(m); } else disp[i][j] = '*'; @@ -224,7 +224,7 @@ void plot_stars(dyn * bi, PRL(nnodes); - dyn ** nodes = new dynptr[nnodes]; + dyn ** nodes = new dynptr[static_cast(nnodes)]; int i = 0; for (m = 0; m <= n; m++) { @@ -238,7 +238,7 @@ void plot_stars(dyn * bi, // Label placement is Steve's aesthetic judgement (6/00)... - int len = strlen(nodes[i]->format_label()); + int len = static_cast(strlen(nodes[i]->format_label())); if (len > 9) len = 9; int ind = 7-len; if (len > 3) ind = 6 - (1+len)/2; @@ -268,7 +268,7 @@ void plot_stars(dyn * bi, #else -main(int argc, char ** argv) +int main(int argc, char ** argv) { int k = 3; int n = 5; diff --git a/node/dyn/util/print_radii.C b/node/dyn/util/print_radii.C index 4b45c54..b8a9c4b 100644 --- a/node/dyn/util/print_radii.C +++ b/node/dyn/util/print_radii.C @@ -24,7 +24,7 @@ #ifdef TOOLBOX -main(int argc, char** argv) +int main(int argc, char** argv) { dyn *root, *ni; diff --git a/node/dyn/util/print_time.C b/node/dyn/util/print_time.C index c5807e6..dcc39ab 100644 --- a/node/dyn/util/print_time.C +++ b/node/dyn/util/print_time.C @@ -12,7 +12,7 @@ #ifdef TOOLBOX -main(int argc, char ** argv) +int main(int argc, char ** argv) { check_help(); diff --git a/node/dyn/util/radial_density.C b/node/dyn/util/radial_density.C index 7ba5c73..70fad26 100644 --- a/node/dyn/util/radial_density.C +++ b/node/dyn/util/radial_density.C @@ -78,7 +78,7 @@ vector& get_radial_densities(dyn *b, vec cpos, vector& r, vector& rho = *(new vector(r.size())); real rj2 = r[0]*r[0]; - for (int i = 0, j = 0; i < table->size(); i++) { + for (std::size_t i = 0u, j = 0u; i < table->size(); i++) { real ri_sq = (*table)[i].r_sq; while (ri_sq > rj2) { if (++j >= r.size()) break; @@ -91,7 +91,7 @@ vector& get_radial_densities(dyn *b, vec cpos, vector& r, // Convert from mass to density. real v0 = 0; // assume that the first zone extends in to r = 0 - for (int j = 0; j < r.size(); j++) { + for (std::size_t j = 0u; j < r.size(); j++) { real v1 = pow(r[j], 3); rho[j] /= (4*M_PI/3) * (v1 - v0); // dM --> dM/dV v0 = v1; @@ -107,7 +107,7 @@ vector& get_radial_densities(dyn *b, vec cpos, vector& r, #define N_DEFAULT 100 -main(int argc, char ** argv) +int main(int argc, char ** argv) { int n_zones = N_DEFAULT; real r_max = 0; diff --git a/node/dyn/util/radial_numdensity.C b/node/dyn/util/radial_numdensity.C index 588b2f4..623f804 100644 --- a/node/dyn/util/radial_numdensity.C +++ b/node/dyn/util/radial_numdensity.C @@ -78,7 +78,7 @@ vector& get_radial_numdensities(dyn *b, vec cpos, vector& r, vector& rho = *(new vector(r.size())); real rj2 = r[0]*r[0]; - for (int i = 0, j = 0; i < table->size(); i++) { + for (std::size_t i = 0u, j = 0u; i < table->size(); i++) { real ri_sq = (*table)[i].r_sq; while (ri_sq > rj2) { if (++j >= r.size()) break; @@ -90,7 +90,7 @@ vector& get_radial_numdensities(dyn *b, vec cpos, vector& r, delete table; real v0 = 0; // assume that the first zone extends in to r = 0 - for (int j = 0; j < r.size(); j++) { + for (std::size_t j = 0u; j < r.size(); j++) { real v1 = pow(r[j], 3); rho[j] /= (4*M_PI/3) * (v1 - v0); // dM --> dM/dV v0 = v1; @@ -106,7 +106,7 @@ vector& get_radial_numdensities(dyn *b, vec cpos, vector& r, #define N_DEFAULT 100 -main(int argc, char ** argv) +int main(int argc, char ** argv) { int n_zones = N_DEFAULT; real r_max = 0; diff --git a/node/dyn/util/radial_profile.C b/node/dyn/util/radial_profile.C index 7c869f6..06f2eb3 100644 --- a/node/dyn/util/radial_profile.C +++ b/node/dyn/util/radial_profile.C @@ -212,7 +212,7 @@ real Q3(dyn *b) // vr^2 typedef real (*qfn)(dyn*); -main(int argc, char ** argv) +int main(int argc, char ** argv) { int n_zones = N_DEFAULT; int option = 0; diff --git a/node/dyn/util/radial_vdisp.C b/node/dyn/util/radial_vdisp.C index 5e8b023..9cf1a08 100644 --- a/node/dyn/util/radial_vdisp.C +++ b/node/dyn/util/radial_vdisp.C @@ -67,7 +67,7 @@ int get_radial_vdisp(dyn *b, vec cpos, vec cvel, // Set up an array of (r_sq, mass, vel) triples. - int n = b->n_daughters(); // (NB implicit loop through the entire system) + std::size_t n = static_cast(b->n_daughters()); // (NB implicit loop through the entire system) // Would be possible to determine n and set up the array simultaneously // using malloc and realloc. Not so easy with new... @@ -132,7 +132,7 @@ int get_radial_vdisp(dyn *b, vec cpos, vec cvel, #define N_DEFAULT 100 -main(int argc, char ** argv) +int main(int argc, char ** argv) { int n_zones = N_DEFAULT; real r_max = 0; diff --git a/node/dyn/util/reflect_velocities.C b/node/dyn/util/reflect_velocities.C index 816c530..9e19ebc 100644 --- a/node/dyn/util/reflect_velocities.C +++ b/node/dyn/util/reflect_velocities.C @@ -37,7 +37,7 @@ local void flip_velocities(dyn * b) } -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool c_flag = FALSE; char *comment; diff --git a/node/dyn/util/scale.C b/node/dyn/util/scale.C index efcc5aa..c02b5e7 100644 --- a/node/dyn/util/scale.C +++ b/node/dyn/util/scale.C @@ -586,7 +586,7 @@ bool parse_scale_main(int argc, char *argv[], #else -main(int argc, char ** argv) +int main(int argc, char ** argv) { check_help(); diff --git a/node/dyn/util/set_com.C b/node/dyn/util/set_com.C index 36574e4..4f94b94 100644 --- a/node/dyn/util/set_com.C +++ b/node/dyn/util/set_com.C @@ -124,7 +124,7 @@ void dyn::offset_com() #else -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool c_flag = FALSE; char *comment; diff --git a/node/dyn/util/set_ignore_internal.C b/node/dyn/util/set_ignore_internal.C index 4ba52bb..d921d1f 100644 --- a/node/dyn/util/set_ignore_internal.C +++ b/node/dyn/util/set_ignore_internal.C @@ -26,7 +26,7 @@ #ifdef TOOLBOX -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { check_help(); pgetopt(argc, argv, "", "$Revision: 1.6 $", _SRC_); diff --git a/node/dyn/util/snap2speck.C b/node/dyn/util/snap2speck.C index 930bd5c..417e7be 100644 --- a/node/dyn/util/snap2speck.C +++ b/node/dyn/util/snap2speck.C @@ -24,7 +24,7 @@ #ifdef TOOLBOX -main(int argc, char** argv) +int main(int argc, char** argv) { dyn *root; diff --git a/node/dyn/util/starplot.C b/node/dyn/util/starplot.C index e60c28b..bd17936 100644 --- a/node/dyn/util/starplot.C +++ b/node/dyn/util/starplot.C @@ -56,7 +56,7 @@ void starplot(dyn * b, int k, real lmax, int nlines) { int n; int kx, ky; // the coordinates projected onto the x- and y-axes - register int i, j; + int i, j; real lvmax; char screen[VBINS][HBINS]; // pixels on the screen dyn *bi; @@ -220,7 +220,7 @@ void starplot(dyn * b, int k, real lmax, int nlines) // number of lines on the screen. //----------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { int k; int nlines; diff --git a/node/dyn/util/sys_stats.C b/node/dyn/util/sys_stats.C index 0a5e741..abbc672 100644 --- a/node/dyn/util/sys_stats.C +++ b/node/dyn/util/sys_stats.C @@ -212,10 +212,10 @@ local void print_numbers_and_masses_by_radial_zone(dyn* b, int which) // Make a list of previously computed lagrangian radii. - int n_lagr = getiq(b->get_dyn_story(), "n_lagr"); + std::size_t n_lagr = static_cast(getiq(b->get_dyn_story(), "n_lagr")); real *r_lagr = new real[n_lagr]; - getra(b->get_dyn_story(), "r_lagr", r_lagr, n_lagr); + getra(b->get_dyn_story(), "r_lagr", r_lagr, static_cast(n_lagr)); // Numbers of top-level nodes (leaves in multiple case): @@ -271,7 +271,7 @@ local void print_numbers_and_masses_by_radial_zone(dyn* b, int which) // Find which zone we are in. - int i = which_zone(bi, center_pos, n_lagr, r_lagr); + int i = which_zone(bi, center_pos, static_cast(n_lagr), r_lagr); // Update statistics. @@ -339,9 +339,9 @@ local void print_anisotropy_by_radial_zone(dyn* b, int which) // Make a list of previously computed lagrangian radii. - int n_lagr = getiq(b->get_dyn_story(), "n_lagr"); + std::size_t n_lagr = static_cast(getiq(b->get_dyn_story(), "n_lagr")); real *r_lagr = new real[n_lagr]; - getra(b->get_dyn_story(), "r_lagr", r_lagr, n_lagr); + getra(b->get_dyn_story(), "r_lagr", r_lagr, static_cast(n_lagr)); real *total_weight = new real[n_lagr+1]; real *vr2_sum = new real[n_lagr+1]; @@ -388,7 +388,7 @@ local void print_anisotropy_by_radial_zone(dyn* b, int which) // Find which zone we are in. - int i = which_zone(bi, center_pos, n_lagr, r_lagr); + int i = which_zone(bi, center_pos, static_cast(n_lagr), r_lagr); // Update statistics. @@ -523,7 +523,7 @@ local void print_energies(dyn* b, real external_pot = get_external_pot(b); e_total = total_int_energy + external_pot; - int ppp = cerr.precision(STD_PRECISION); + std::streamsize ppp = cerr.precision(STD_PRECISION); vec com_pos, com_vel; compute_com(b, com_pos, com_vel); @@ -539,7 +539,7 @@ local void print_energies(dyn* b, com_vel -= b->get_vel(); real pot_int = potential_energy, kin_int = kinetic_energy; - kT = kin_int / (1.5*b->n_daughters()); + kT = kin_int / (1.5*static_cast(b->n_daughters())); real virial_ratio = -kin_int / (pot_int + get_external_virial(b)); real pot_tot = potential_energy, kin_tot = kinetic_energy; @@ -562,13 +562,13 @@ local void print_energies(dyn* b, kin_tot += kin_com; e_total += external_pot + kin_com; - int p = cerr.precision(INT_PRECISION); + std::streamsize p = cerr.precision(INT_PRECISION); cerr << endl << " Energies: " << pot_tot << " " << kin_tot << " " << e_total << endl; cerr.precision(p); - if (external_pot) { + if (external_pot != 0.0) { cerr << " external potential = " << external_pot << " ("; print_external(b->get_external_field()); cerr << ")" << endl; @@ -862,7 +862,7 @@ local void print_binaries(dyn* b, real kT, cerr << bi->format_label(); } - int init_indent = BIN_INDENT - 4 - strlen(bi->format_label()); + int init_indent = BIN_INDENT - 4 - static_cast(strlen(bi->format_label())); if (bi->n_leaves() > 2) { @@ -1056,7 +1056,7 @@ local void print_dominated_lagrangian_radii(dyn* b, dyn* b_dom) if (!b_dom) return; - int n = 0; + std::size_t n = 0; { for_all_daughters(dyn, b, bi) if (bi != b_dom) n++; } @@ -1259,7 +1259,7 @@ void sys_stats(dyn* b, // other hdyn programs. { - int p = cerr.precision(STD_PRECISION); + std::streamsize p = cerr.precision(STD_PRECISION); if (print_time) { @@ -1586,7 +1586,7 @@ void sys_stats(dyn* b, #else -main(int argc, char **argv) +int main(int argc, char **argv) { check_help(); diff --git a/node/dyn/util/test_util.C b/node/dyn/util/test_util.C index ab6661c..3e7a75c 100644 --- a/node/dyn/util/test_util.C +++ b/node/dyn/util/test_util.C @@ -27,6 +27,8 @@ //// //// Report bugs to steve@physics.drexel.edu. +#ifdef TOOLBOX + #include "dyn.h" #include #include @@ -84,3 +86,6 @@ int main(int argc, char *argv[]) rmtree(b); } } + +#endif + diff --git a/node/dyn/util/to_com.C b/node/dyn/util/to_com.C index feb0f26..16d6faa 100644 --- a/node/dyn/util/to_com.C +++ b/node/dyn/util/to_com.C @@ -38,7 +38,7 @@ void dyn::to_com() // function is a special case of set_com #else -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool c_flag = FALSE; char *comment; diff --git a/node/util/add_daughter_node.C b/node/util/add_daughter_node.C index 91cb5d1..cf62b49 100644 --- a/node/util/add_daughter_node.C +++ b/node/util/add_daughter_node.C @@ -36,7 +36,7 @@ // main -- driver to directly add one extra daughter node. //------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { int i; int j; diff --git a/node/util/display_subtrees.C b/node/util/display_subtrees.C index 813f983..0da4639 100644 --- a/node/util/display_subtrees.C +++ b/node/util/display_subtrees.C @@ -32,7 +32,7 @@ * main -- driver, to directly display subtrees. *----------------------------------------------------------------------------- */ -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool c_flag = FALSE; char *comment; diff --git a/node/util/m_bar.C b/node/util/m_bar.C index fa81289..3612012 100644 --- a/node/util/m_bar.C +++ b/node/util/m_bar.C @@ -27,7 +27,7 @@ #ifdef TOOLBOX -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { real ml = -1.0, mu = -1.0, x = -2.35, factor = 1; bool verbose = 0; diff --git a/node/util/make_single_node.C b/node/util/make_single_node.C index fc9bd33..b67cd18 100644 --- a/node/util/make_single_node.C +++ b/node/util/make_single_node.C @@ -37,7 +37,7 @@ * main -- driver to create directly a single node *----------------------------------------------------------------------------- */ -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool c_flag = FALSE; bool i_flag = FALSE; diff --git a/node/util/node_io.C b/node/util/node_io.C index dc0ea8c..9171926 100644 --- a/node/util/node_io.C +++ b/node/util/node_io.C @@ -107,7 +107,7 @@ ostream& node::print_dyn_story(ostream& s, #else -main(int argc, char** argv) +int main(int argc, char** argv) { check_help(); pgetopt(argc, argv, "", "$Revision: 1.13 $", _SRC_); diff --git a/node/util/node_tt.C b/node/util/node_tt.C index 7dd98ab..3b96eca 100644 --- a/node/util/node_tt.C +++ b/node/util/node_tt.C @@ -306,7 +306,7 @@ local char * alt_construct_merger_label(node * ni, node * nj) // Decode the names and combine them to make the new name. // Not very efficiently written, but... (Steve, 12/98) - static char new_name[1024]; + static char new_name[1040]; int count_i = string_count(string_index_of_node(ni)); int count_j = string_count(string_index_of_node(nj)); diff --git a/node/util/pretty_print_tree.C b/node/util/pretty_print_tree.C index 465c067..4855255 100644 --- a/node/util/pretty_print_tree.C +++ b/node/util/pretty_print_tree.C @@ -29,7 +29,7 @@ // main -- driver to directly print out a tree structure //--------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { node *root; // root node diff --git a/node/util/print_normal.C b/node/util/print_normal.C index 67936c2..6d40704 100644 --- a/node/util/print_normal.C +++ b/node/util/print_normal.C @@ -72,7 +72,7 @@ void construct_node_name(node* b) for_all_daughters(node, b, b1) construct_node_name(b1); - char** list = new char*[b->n_daughters()]; + char** list = new char*[static_cast(b->n_daughters())]; int n = 0; for_all_daughters(node, b, b2) { @@ -95,12 +95,12 @@ void construct_node_name(node* b) temp[0] = '('; temp[1] = '\0'; - int length = 2; + std::size_t length = 2; for (int i = 0; i < n; i++) { - int sl = strlen(list[i]); - if (length + sl > 1024) + std::size_t sl = strlen(list[i]); + if (length + sl > 1024u) err_exit("construct_node: buffer overflow."); strcat(temp, list[i]); @@ -134,7 +134,7 @@ char* get_normal_form(node* b) // Unused... * main -- driver to directly print out a tree structure *----------------------------------------------------------------------------- */ -main(int argc, char ** argv) +int main(int argc, char ** argv) { int i = 0; node *root; // root node diff --git a/node/util/renumber.C b/node/util/renumber.C index 210749d..3a3e18a 100644 --- a/node/util/renumber.C +++ b/node/util/renumber.C @@ -71,7 +71,7 @@ void renumber(node* b, int istart, bool mass_order, // Highest mass gets smallest number (strange choise, but). int n = b->n_leaves(); - nm_pair_ptr nm_table = new nm_pair[n]; + nm_pair_ptr nm_table = new nm_pair[static_cast(n)]; if (nm_table == NULL) { cerr << "renumber: " << "not enough memory left for nm_table\n"; diff --git a/node/util/rmq.C b/node/util/rmq.C index b0287d5..24c4bec 100644 --- a/node/util/rmq.C +++ b/node/util/rmq.C @@ -75,7 +75,7 @@ void rm_all_star_q(node * n, char * qname) * -s option: "rmq -s -q name" removes quantity from hydro story *----------------------------------------------------------------------------- */ -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool h_flag = FALSE; bool s_flag = FALSE; diff --git a/node/util/snapprune.C b/node/util/snapprune.C index 34d720a..3821601 100644 --- a/node/util/snapprune.C +++ b/node/util/snapprune.C @@ -24,6 +24,8 @@ // version 1: Nov 1994 Piet Hut +#ifdef TOOLBOX + #include "node.h" /*----------------------------------------------------------------------------- @@ -90,4 +92,6 @@ int main(int argc, char ** argv) return 0; } +#endif + /* endof: snapprune.c */ diff --git a/node/util/starbase_init.C b/node/util/starbase_init.C index 868eb93..4ff6a79 100644 --- a/node/util/starbase_init.C +++ b/node/util/starbase_init.C @@ -126,7 +126,7 @@ starbase::starbase(starbase& sb) #else -void main() +int main() { cerr << "Seems to work..." << endl; } diff --git a/node/util/tree_io.C b/node/util/tree_io.C index 798ed3b..886e512 100644 --- a/node/util/tree_io.C +++ b/node/util/tree_io.C @@ -39,11 +39,11 @@ void node::log_history(int argc, char ** argv) // with the "col" output format, which is line oriented. // Rather than rewrite gethist, split the line here... - int n = strlen(hist); - if (n > 0) { + std::size_t n = strlen(hist); + if (n > 0u) { char *tmp = new char[n+1]; - int j = 0; - for (int i = 0; i < strlen(hist); i++) { + std::size_t j = 0u; + for (std::size_t i = 0u; i < strlen(hist); i++) { if (hist[i] == '\n') { strncpy(tmp, hist+j, i-j); tmp[i-j] = '\0'; @@ -53,9 +53,9 @@ void node::log_history(int argc, char ** argv) } if (j < n) add_story_line(log_story, hist+j); - delete tmp; + delete[] tmp; } - delete hist; + delete[] hist; } } @@ -334,7 +334,7 @@ local node *get_node_recursive(istream& s, if (val) { if (!strcmp("i",keyword)) { - int index = strtol(val, NULL, 10); + int index = atoi(val); b->set_label(index); } else if (!strcmp("name",keyword)) { char cptr[MAX_INPUT_LINE_LENGTH]; diff --git a/rdc/list_sdumb.C b/rdc/list_sdumb.C index 8041d82..b2df36e 100644 --- a/rdc/list_sdumb.C +++ b/rdc/list_sdumb.C @@ -331,7 +331,7 @@ local void print_integrated_cluster(hdyn *b, vec dc_pos, } } -main(int argc, char ** argv) +int main(int argc, char ** argv) { check_help(); diff --git a/rdc/make_ccd.C b/rdc/make_ccd.C index 00a9091..ecc9d9e 100644 --- a/rdc/make_ccd.C +++ b/rdc/make_ccd.C @@ -736,7 +736,7 @@ local void mk_ccd(dyn* b, vec dc_pos, int project, wavelength band, // -v verbose, prints stars and positions to cerr [false] // // -main(int argc, char ** argv) { +int main(int argc, char ** argv) { check_help(); wavelength band = F; diff --git a/rdc/makepovfile.C b/rdc/makepovfile.C index 77142f4..0c0045c 100644 --- a/rdc/makepovfile.C +++ b/rdc/makepovfile.C @@ -1164,7 +1164,7 @@ void rdc_and_wrt_movie(dyn *b, bool povray, real scale_L, real mmax, //----------------------------------------------------------------------------- enum SF_base_type {No_base=0, StTr_station, SW_ISD}; -main(int argc, char ** argv) +int main(int argc, char ** argv) { bool c_flag = false; // if TRUE: a comment given on command line bool v_flag = false; // if TRUE: a comment given on command line diff --git a/rdc/rs_birthrate.C b/rdc/rs_birthrate.C index b78c662..b67c0f6 100644 --- a/rdc/rs_birthrate.C +++ b/rdc/rs_birthrate.C @@ -311,7 +311,7 @@ local int extract_population(SeBa_hist *hi, real snap_time, // main -- driver to reduce SeBa short dump data //---------------------------------------------------------------------------- -main(int argc, char ** argv) { +int main(int argc, char ** argv) { real normalize = -1; real snap_time = 0; diff --git a/rdc/rs_countsn.C b/rdc/rs_countsn.C index 1661abe..bab5d29 100644 --- a/rdc/rs_countsn.C +++ b/rdc/rs_countsn.C @@ -98,7 +98,7 @@ local int count_supernova_types(SeBa_hist *hi, bool normalize) { // main -- driver to reduce SeBa short dump data //---------------------------------------------------------------------------- -main(int argc, char ** argv) { +int main(int argc, char ** argv) { bool normalize = false; real snap_time = 0; diff --git a/rdc/rs_findtype.C b/rdc/rs_findtype.C index a9d9ae8..92892e6 100644 --- a/rdc/rs_findtype.C +++ b/rdc/rs_findtype.C @@ -142,7 +142,7 @@ local void extract_binary_on_stellar_types(SeBa_hist *ha, //----------------------------------------------------------------------------- -main(int argc, char ** argv) { +int main(int argc, char ** argv) { bool c_flag = false; bool v_flag = false; diff --git a/rdc/rs_population.C b/rdc/rs_population.C index dfa8e2c..78087f3 100644 --- a/rdc/rs_population.C +++ b/rdc/rs_population.C @@ -305,7 +305,7 @@ local int extract_population(SeBa_hist *hi, real snap_time, // main -- driver to reduce SeBa short dump data //---------------------------------------------------------------------------- -main(int argc, char ** argv) { +int main(int argc, char ** argv) { real normalize = -1; real snap_time = 0; diff --git a/rdc/rs_reorder.C b/rdc/rs_reorder.C index a9c6ca5..f0614b6 100644 --- a/rdc/rs_reorder.C +++ b/rdc/rs_reorder.C @@ -149,7 +149,7 @@ local int reorder_binaries(SeBa_hist *hi, const real end_time) { // main -- driver to reduce SeBa short dump data //---------------------------------------------------------------------------- -main(int argc, char ** argv) { +int main(int argc, char ** argv) { real end_time = VERY_LARGE_NUMBER; diff --git a/rdc/rs_scenarios.C b/rdc/rs_scenarios.C index f39b7fb..0065f79 100644 --- a/rdc/rs_scenarios.C +++ b/rdc/rs_scenarios.C @@ -114,7 +114,7 @@ local int extract_scenarios(SeBa_hist *hi, const real end_time) { // main -- driver to reduce SeBa short dump data //---------------------------------------------------------------------------- -main(int argc, char ** argv) { +int main(int argc, char ** argv) { real end_time = VERY_LARGE_NUMBER; diff --git a/rdc/rs_snapshot.C b/rdc/rs_snapshot.C index 0995b10..c8f0304 100644 --- a/rdc/rs_snapshot.C +++ b/rdc/rs_snapshot.C @@ -295,7 +295,7 @@ cerr<<"assuming solar metallicity in extract_snapshot in rs_snapshot.C"< + bool scenarios_identical(SeBa_hist* hi, SeBa_hist* ha) { @@ -129,6 +132,8 @@ real SeBa_hist::get_parameter(binary_parameter param) { break; case mass_ratio: return m_sec/m_prim; break; + default: + throw std::logic_error("Invalid parameter"); } } diff --git a/sstar/init/add_star.C b/sstar/init/add_star.C index 4b74769..7788913 100644 --- a/sstar/init/add_star.C +++ b/sstar/init/add_star.C @@ -222,7 +222,7 @@ void addstar(node * b, real t_current, stellar_type type, real z,int id, #else -main(int argc, char ** argv) +int main(int argc, char ** argv) { int c; bool t_flag = FALSE; diff --git a/sstar/io/extract_star_story.C b/sstar/io/extract_star_story.C index 5516607..9fb3df6 100644 --- a/sstar/io/extract_star_story.C +++ b/sstar/io/extract_star_story.C @@ -20,7 +20,6 @@ #include "main_sequence.h" #include "util_io.h" -#ifndef TOOLBOX void dump_line_text(ostream& str, story& s) { @@ -188,13 +187,13 @@ void addstar1(node * b, real t_rel, stellar_type type, # define FALSE 0 # define TRUE 1 -#else +#ifdef TOOLBOX /*----------------------------------------------------------------------------- * main -- *----------------------------------------------------------------------------- */ -main(int argc, char ** argv) +int main(int argc, char ** argv) { int c; bool t_flag = FALSE; diff --git a/sstar/starclass/Makefile b/sstar/starclass/Makefile index 292f315..d2d150f 100644 --- a/sstar/starclass/Makefile +++ b/sstar/starclass/Makefile @@ -6,7 +6,7 @@ LIB = ../libsstar.a lib: $(LIB)($(OBJ)) -$(LIB)($(OBJ)): $(OBJ) +$(LIB): $(OBJ) ar -cr $(LIB) $(OBJ) clean: diff --git a/sstar/starclass/brown_dwarf.C b/sstar/starclass/brown_dwarf.C index f11e9a7..8f8fd5d 100644 --- a/sstar/starclass/brown_dwarf.C +++ b/sstar/starclass/brown_dwarf.C @@ -181,7 +181,7 @@ star* brown_dwarf::merge_elements(star* str) { real merger_core = str->get_core_mass(); add_mass_to_accretor(str->get_envelope_mass(), - cnsts.parameters(spiral_in_time), str->hydrogen_envelope_star()); + cnsts.parameters(spiral_in_time) != 0.0, str->hydrogen_envelope_star()); if (relative_mass < get_total_mass() + merger_core) relative_mass=get_total_mass() + merger_core; diff --git a/sstar/starclass/main_sequence.C b/sstar/starclass/main_sequence.C index a0e78ca..9f58a1d 100644 --- a/sstar/starclass/main_sequence.C +++ b/sstar/starclass/main_sequence.C @@ -1038,9 +1038,15 @@ void main_sequence::instantaneous_element() { // if (relative_age > 0.2*main_sequence_time()){// to force entering CHE // rotation_period = cnsts.mathematics(pi)/critical_angular_freq;} - if ((cnsts.parameters(include_CHE)) && get_rotation_period() != 0 && relative_mass >= 20 && angular_freq >= critical_angular_freq && relative_age < 0.3 * main_sequence_time()){ + if ( + (cnsts.parameters(include_CHE) != 0.0) && + get_rotation_period() != 0 && + relative_mass >= 20 && + angular_freq >= critical_angular_freq && + relative_age < 0.3 * main_sequence_time() + ) { CHE_flag = true; - } + } if (CHE_flag){ luminosity = max(luminosity, main_sequence_luminosity(0, relative_mass, metalicity)); diff --git a/sstar/starclass/neutron_star.C b/sstar/starclass/neutron_star.C index 0f9f4e1..8735213 100644 --- a/sstar/starclass/neutron_star.C +++ b/sstar/starclass/neutron_star.C @@ -628,7 +628,7 @@ bool neutron_star::propeller(const real mdot, const real dt) { if (DEBUG) cerr<<"neutron_star::propeller"<propeller_limit*dt) - propellor=FALSE; + propellor=false; } if (DEBUG) diff --git a/sstar/starclass/single_star.C b/sstar/starclass/single_star.C index 91714eb..c44c8ca 100644 --- a/sstar/starclass/single_star.C +++ b/sstar/starclass/single_star.C @@ -546,7 +546,7 @@ void single_star::dump(ostream & s, bool brief) { } } -void single_star::dump(char * filename, bool brief) { +void single_star::dump(const char * filename, bool brief) { ofstream s(filename, ios::app|ios::out); if (!s) cerr << "error: couldn't create file "<=COcore_mass- cnsts.safety(tiny) && diff --git a/sstar/starclass/star_state.C b/sstar/starclass/star_state.C index 0895d01..8e897b3 100644 --- a/sstar/starclass/star_state.C +++ b/sstar/starclass/star_state.C @@ -273,7 +273,7 @@ void put_short_state(star_state st, ostream & s) { } } -char* type_dominant_state(star_state sts) { +const char* type_dominant_state(star_state sts) { if (sts.class_spec[Blue_Straggler]) return type_string(Blue_Straggler); diff --git a/sstar/starclass/star_support.C b/sstar/starclass/star_support.C index 52f81b5..3b0db64 100644 --- a/sstar/starclass/star_support.C +++ b/sstar/starclass/star_support.C @@ -4,7 +4,7 @@ #include "star_support.h" -char* type_string(stellar_type tpe) { +const char* type_string(stellar_type tpe) { switch(tpe) { case Static_Star: return "static_star"; @@ -36,7 +36,7 @@ char* type_string(stellar_type tpe) { } } -char* type_short_string(stellar_type tpe) { +const char* type_short_string(stellar_type tpe) { switch(tpe) { case Static_Star: return "SS"; @@ -68,7 +68,7 @@ char* type_short_string(stellar_type tpe) { } } -char* type_string(stellar_type_summary tpe) { +const char* type_string(stellar_type_summary tpe) { switch(tpe) { case ZAMS: return "ZAMS"; @@ -84,7 +84,7 @@ char* type_string(stellar_type_summary tpe) { } } -char* type_short_string(stellar_type_summary tpe) { +const char* type_short_string(stellar_type_summary tpe) { switch(tpe) { case ZAMS: return "ms"; @@ -141,7 +141,7 @@ stellar_type_summary summarize_stellar_type(stellar_type tpe) { } } -char* type_string(spectral_class class_tpe) { +const char* type_string(spectral_class class_tpe) { switch(class_tpe) { case O5: return "O5"; @@ -196,7 +196,7 @@ char* type_string(spectral_class class_tpe) { } -char* type_short_string(spectral_class class_tpe) { +const char* type_short_string(spectral_class class_tpe) { switch(class_tpe) { case O5: @@ -250,7 +250,7 @@ char* type_short_string(spectral_class class_tpe) { } } -char* type_string(luminosity_class lum_c) { +const char* type_string(luminosity_class lum_c) { switch(lum_c) { case I: return "I"; @@ -262,7 +262,7 @@ char* type_string(luminosity_class lum_c) { } } -char* type_string(star_type_spec spec) { +const char* type_string(star_type_spec spec) { switch(spec) { case NAC: return ""; @@ -278,7 +278,7 @@ char* type_string(star_type_spec spec) { } } -char* type_short_string(star_type_spec spec) { +const char* type_short_string(star_type_spec spec) { switch(spec) { case NAC: return ""; @@ -520,7 +520,7 @@ star_type_spec extract_stellar_spec_summary_string(char* star_spec_string) { } -char* type_string(mass_transfer_type type) { +const char* type_string(mass_transfer_type type) { switch(type) { case Unknown: return "Unknown"; @@ -533,7 +533,7 @@ char* type_string(mass_transfer_type type) { } } -char* type_short_string(mass_transfer_type type) { +const char* type_short_string(mass_transfer_type type) { switch(type) { case Unknown: return "?"; @@ -588,7 +588,7 @@ supernova_type type_of_supernova(stellar_type progenitor) { return ns_type; } -char *type_string(supernova_type sn_type) { +const char *type_string(supernova_type sn_type) { switch(sn_type) { case NAT: return "nat"; diff --git a/sstar/starclass/stdfunc.C b/sstar/starclass/stdfunc.C index 9a6820e..9e80fa3 100644 --- a/sstar/starclass/stdfunc.C +++ b/sstar/starclass/stdfunc.C @@ -799,7 +799,7 @@ real *vector(long nl, long nh) { real *v; - v=(real *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(real))); + v=(real *)malloc((static_cast(nh-nl+1+NR_END)*sizeof(real))); if (!v) cerr<<"allocation failure in vector()"; return v-nl+NR_END; } @@ -837,7 +837,7 @@ real dynamic_timescale(const real mass, #else -void main() { +int main() { real v_disp = 8; // km/s // real v_disp = 4; // km/s diff --git a/std/gethist.C b/std/gethist.C index 06ea82f..432b633 100644 --- a/std/gethist.C +++ b/std/gethist.C @@ -55,7 +55,7 @@ local bool contains_white(char * s) * eff_length("hi there") = 10 *----------------------------------------------------------------------------- */ -local int eff_length(char * s) +local std::size_t eff_length(char * s) { if (contains_white(s)) return(strlen(s) + 2); @@ -108,7 +108,7 @@ local int eff_length(char * s) char *gethist(int argc, char ** argv) { int i, j, k; - int n; + std::size_t n; long int clock; /* will contain time in seconds since 1970 */ char *hist_string; /* will point to newly allocated string */ /* @@ -117,13 +117,13 @@ char *gethist(int argc, char ** argv) n = DATE_TOT_LENGTH; for (i = 0; i < argc; i++) /* total length, apart from the white */ n += eff_length(argv[i]); /* spaces separating the commands */ - n += argc; /* one for each white space delimiter, */ + n += static_cast(argc); /* one for each white space delimiter, */ /* and a final NULL to end the hist_string */ // Added by Steve (7/01): char *user_part = getenv("USER"); - int user_length = 0; + std::size_t user_length = 0u; if (user_part) user_length = strlen(user_part) + strlen(USER_HEAD) + 1; // ')' @@ -167,7 +167,7 @@ char *gethist(int argc, char ** argv) /* * write the command line: */ - j = DATE_TOT_LENGTH + user_length; + j = static_cast(DATE_TOT_LENGTH + user_length); for (i = 0; i < argc; i++) { k = 0; @@ -197,7 +197,7 @@ char *gethist(int argc, char ** argv) // gethist these are words "but this is a single string" //----------------------------------------------------------------------------- -main(int argc, char ** argv) +int main(int argc, char ** argv) { check_help(); pgetopt(argc, argv, "", "$Revision: 1.5 $", _SRC_); diff --git a/std/pgetopt.C b/std/pgetopt.C index b18a460..5984105 100644 --- a/std/pgetopt.C +++ b/std/pgetopt.C @@ -84,6 +84,7 @@ //............................................................................. #include "stdinc.h" +#include #ifndef TOOLBOX @@ -120,7 +121,7 @@ local inline char *get_version(const char *cvs_id) while (*end > ' ') end++; if (*end == ' ') { - int n = end-start+1; + std::size_t n = static_cast(end-start+1); char *version = new char[n]; strncpy(version, start, n-1); version[n-1] = 0; @@ -152,7 +153,7 @@ local inline char *get_name(const char *source) if (end < start) return NULL; - int n = end-start+2; + std::size_t n = static_cast(end-start+2); char *name = new char[n]; strncpy(name, start, n-1); name[n-1] = 0; diff --git a/std/precision.C b/std/precision.C index 1fa873b..f150076 100644 --- a/std/precision.C +++ b/std/precision.C @@ -64,7 +64,7 @@ local void get_default_precision() precision = 18; } -int set_starlab_precision(ostream &s) +std::streamsize set_starlab_precision(ostream &s) { if (precision < 0) get_default_precision(); return s.precision(precision); // convenient to return the @@ -83,7 +83,7 @@ int adjust_starlab_precision(int p) #else -main(int argc, char** argv) +int main(int argc, char** argv) { check_help(); pgetopt(argc, argv, "", "$Revision: 1.4 $", _SRC_); diff --git a/std/randinter.C b/std/randinter.C index c52a615..99a4a61 100644 --- a/std/randinter.C +++ b/std/randinter.C @@ -353,7 +353,7 @@ real gausrand(real mean, real sdev) // is given, a random seed is used; otherwise the second argument // is used as the seed for the random number generator. -main(int argc, char **argv) { +int main(int argc, char **argv) { check_help(); extern char *poptarg; diff --git a/std/runtime_help.C b/std/runtime_help.C index 6205543..3d38611 100644 --- a/std/runtime_help.C +++ b/std/runtime_help.C @@ -99,7 +99,9 @@ void get_runtime_help(const char* source_file, // or "//++ " (level 2). // PRL(cmd); - system(cmd); + if (system(cmd) != 0) { + cout << "ERROR: grep or sed not available"; + } cout<< endl; // Now check for level-2 help. @@ -109,7 +111,9 @@ void get_runtime_help(const char* source_file, strcat(cmd, src); strcat(cmd, " | sed s%//++%\" + \"%"); - system(cmd); + if (system(cmd) != 0) { + cout << "ERROR: grep or sed not available"; + } cerr << endl; } @@ -132,7 +136,7 @@ void check_runtime_help(int argc, char** argv, #else -main(int argc, char** argv) +int main(int argc, char** argv) { check_help(); extern char *poptarg; diff --git a/std/story.C b/std/story.C index 49d0a68..3fab005 100644 --- a/std/story.C +++ b/std/story.C @@ -187,11 +187,6 @@ story* get_chapter(istream& str, const char* line) add_story_line(chap, new_line); } - if (new_line == NULL) { - cerr << "get_chapter: new_line == NULL before end of chapter\n"; - exit(1); - } - if (!streq(new_line+1, chap->get_text())) { cerr << "get_chapter: closing title ``" << new_line+1 << "'' differs from opening title ``" << chap->get_text() @@ -371,7 +366,7 @@ local void write_iq(story * a_story_line, const char * name, if (!a_story_line || !name) return; char * new_string; - int new_string_length; + std::size_t new_string_length; new_string_length = EXTRA_LENGTH + strlen(name) + SAFE_INT_LENGTH; new_string = new char[new_string_length]; @@ -392,7 +387,7 @@ local void write_ulq(story * a_story_line, const char * name, if (!a_story_line || !name) return; char * new_string; - int new_string_length; + std::size_t new_string_length; new_string_length = EXTRA_LENGTH + strlen(name) + SAFE_INT_LENGTH; new_string = new char[new_string_length]; @@ -413,7 +408,7 @@ local void write_ullq(story * a_story_line, const char * name, if (!a_story_line || !name) return; char * new_string; - int new_string_length; + std::size_t new_string_length; new_string_length = EXTRA_LENGTH + strlen(name) + SAFE_INT_LENGTH; new_string = new char[new_string_length]; @@ -434,7 +429,7 @@ local void write_rq(story * a_story_line, const char * name, real value, if (!a_story_line || !name) return; char * new_string; - int new_string_length; + std::size_t new_string_length; char format[128]; new_string_length = EXTRA_LENGTH + strlen(name) + SAFE_REAL_LENGTH; @@ -461,7 +456,7 @@ local void write_sq(story * a_story_line, const char * name, if (!a_story_line || !name) return; char * new_string; - int new_string_length; + std::size_t new_string_length; new_string_length = EXTRA_LENGTH + strlen(name) + strlen(value) + SAFE_STRING_LENGTH; @@ -489,7 +484,7 @@ local void write_vq(story * a_story_line, const char * name, vec & value, if (!a_story_line || !name) return; char * new_string; - int new_string_length; + std::size_t new_string_length; char format[128]; new_string_length = EXTRA_LENGTH + strlen(name) + SAFE_VECTOR_LENGTH; @@ -531,12 +526,12 @@ local void write_vq(story * a_story_line, const char * name, vec & value, *----------------------------------------------------------------------------- */ local void write_ra(story * a_story_line, const char * name, - real * value, int n) + real * value, std::size_t n) { if (!a_story_line || !name) return; char *new_string, *tmp; - int new_string_length; + std::size_t new_string_length; new_string_length = EXTRA_LENGTH + strlen(name) + n * (SAFE_REAL_LENGTH + 2); @@ -563,12 +558,12 @@ local void write_ra(story * a_story_line, const char * name, *----------------------------------------------------------------------------- */ local void write_ia(story * a_story_line, const char * name, - int * value, int n) + int * value, std::size_t n) { if (!a_story_line || !name) return; char *new_string, *tmp; - int new_string_length; + std::size_t new_string_length; new_string_length = EXTRA_LENGTH + strlen(name) + n * (SAFE_INT_LENGTH + 2); @@ -594,12 +589,12 @@ local void write_ia(story * a_story_line, const char * name, *----------------------------------------------------------------------------- */ local void write_ia(story * a_story_line, const char * name, - unsigned long * value, int n) + unsigned long * value, std::size_t n) { if (!a_story_line || !name) return; char *new_string, *tmp; - int new_string_length; + std::size_t new_string_length; new_string_length = EXTRA_LENGTH + strlen(name) + n * (SAFE_INT_LENGTH + 2); @@ -610,7 +605,7 @@ local void write_ia(story * a_story_line, const char * name, for (int i = 0; i < n; i++) { - sprintf(tmp, " %d", value[i]); + sprintf(tmp, " %lu", value[i]); strcat(new_string, tmp); } @@ -625,12 +620,12 @@ local void write_ia(story * a_story_line, const char * name, *----------------------------------------------------------------------------- */ local void write_ia(story * a_story_line, const char * name, - unsigned long long * value, int n) + unsigned long long * value, std::size_t n) { if (!a_story_line || !name) return; char *new_string, *tmp; - int new_string_length; + std::size_t new_string_length; new_string_length = EXTRA_LENGTH + strlen(name) + n * (SAFE_INT_LENGTH + 2); @@ -641,7 +636,7 @@ local void write_ia(story * a_story_line, const char * name, for (int i = 0; i < n; i++) { - sprintf(tmp, " %d", value[i]); + sprintf(tmp, " %llu", value[i]); strcat(new_string, tmp); } @@ -975,7 +970,7 @@ local void get_array(char * sin, unsigned long * x, int n) // overloaded! char save = *s2; *s2 = '\0'; - x[i++] = atoi(s1); // <-- only change! + x[i++] = static_cast(atoi(s1)); // <-- only change! *s2 = save; if (i >= n) break; @@ -1203,7 +1198,7 @@ void putrq(story * a_story, const char * name, real value, * overwrite the line containing that quantity. *----------------------------------------------------------------------------- */ -void putra(story * a_story, const char * name, real * value, int n) +void putra(story * a_story, const char * name, real * value, std::size_t n) { if (!a_story || !name) return; @@ -1224,7 +1219,7 @@ void putra(story * a_story, const char * name, real * value, int n) * overwrite the line containing that quantity. *----------------------------------------------------------------------------- */ -void putia(story * a_story, const char * name, int * value, int n) +void putia(story * a_story, const char * name, int * value, std::size_t n) { if (!a_story || !name) return; @@ -1245,7 +1240,7 @@ void putia(story * a_story, const char * name, int * value, int n) * overwrite the line containing that quantity. *----------------------------------------------------------------------------- */ -void putia(story * a_story, const char * name, unsigned long * value, int n) +void putia(story * a_story, const char * name, unsigned long * value, std::size_t n) { if (!a_story || !name) return; @@ -1266,7 +1261,7 @@ void putia(story * a_story, const char * name, unsigned long * value, int n) * overwrite the line containing that quantity. *----------------------------------------------------------------------------- */ -void putia(story * a_story, const char * name, unsigned long long * value, int n) +void putia(story * a_story, const char * name, unsigned long long * value, std::size_t n) { if (!a_story || !name) return; @@ -1335,7 +1330,7 @@ int rmq(story * a_story, const char * name) story * story_line; - if (story_line = find_qmatch(a_story, name)) { + if ((story_line = find_qmatch(a_story, name))) { rm_daughter_story(a_story, story_line); return 1; } else @@ -1362,7 +1357,7 @@ int is_quantity_name(story * a_story, const char * name) #else -main(int argc, char** argv) +int main(int argc, char** argv) { check_help(); pgetopt(argc, argv, "", "$Revision: 1.15 $", _SRC_); diff --git a/std/time.C b/std/time.C index 2612deb..1f2ed58 100644 --- a/std/time.C +++ b/std/time.C @@ -59,8 +59,8 @@ real cpu_time() cpu_init(); times(&buffer); - return ((real) (buffer.tms_utime + buffer.tms_stime - initial_cpu)) - / ticks_per_sec; + return (static_cast(buffer.tms_utime + buffer.tms_stime) - initial_cpu) + / static_cast(ticks_per_sec); #else return 0; #endif diff --git a/std/util_io.C b/std/util_io.C index 6767587..a3f2839 100644 --- a/std/util_io.C +++ b/std/util_io.C @@ -36,7 +36,7 @@ int get_line(istream & s, char * line) while (s.get(c)) if (c == '\n') break; - return strlen(line); + return static_cast(strlen(line)); } int check_input_line(istream &s, const char* reference_string) @@ -233,7 +233,7 @@ void put_real_number(ostream & s, const char * label, real x) // is essentially that used with the obsolete BAD_GNU_IO macro, // but this has *nothing* to do with that ancient G++ bug. - int old_precision = set_starlab_precision(s); + std::streamsize old_precision = set_starlab_precision(s); #ifdef BAD_GNU_IO @@ -291,7 +291,7 @@ void put_real_number(ostream & s, const char * label, real x) if (!outstring) { nout = p+10; - outstring = new char[nout]; + outstring = new char[static_cast(nout)]; } // Finally, create the string... @@ -318,7 +318,7 @@ void put_real_vector(ostream & s, const char * label, vec v) { // See various notes in put_real_number above... - int old_precision = set_starlab_precision(s); + std::streamsize old_precision = set_starlab_precision(s); #ifdef BAD_GNU_IO @@ -368,7 +368,7 @@ void put_real_vector(ostream & s, const char * label, vec v) if (!outstring) { nout = 3*p+30; - outstring = new char[nout]; + outstring = new char[static_cast(nout)]; } // Finally, create the string... diff --git a/std/util_unformatted_io.C b/std/util_unformatted_io.C index 1d24943..2c142a0 100644 --- a/std/util_unformatted_io.C +++ b/std/util_unformatted_io.C @@ -36,7 +36,7 @@ void write_unformatted_real( ostream & s, real v ) void write_unformatted32_real( ostream & s, real v ) { - float f = v; + float f = static_cast(v); #if WORDS_BIGENDIAN s.write( (char *)&f, 4 ); #else diff --git a/std/xreal.C b/std/xreal.C index ce0b74c..44400ba 100644 --- a/std/xreal.C +++ b/std/xreal.C @@ -552,7 +552,7 @@ void identify_xreal(ostream &s) // default = cerr #else -main() +int main() { identify_xreal();