Skip to content

Commit

Permalink
basic c version working.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannorein committed Aug 23, 2023
1 parent 28e69c6 commit fb496f5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/binarydiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ void reb_binary_diff(char* buf1, size_t size1, char* buf2, size_t size2, char**
reb_binary_diff_with_options(buf1, size1, buf2, size2, bufp, sizep, 0);
}

// Result does not need to be freed.
char* reb_name_for_binary_field_type_const(int type){
char needle[256];
sprintf(needle, " %d ", type);
char* result = strstr(reb_binary_field_type_reverse, needle);
result += strlen(needle);
return result;

}
// Result needs to be freed.
char* reb_name_for_binary_field_type(int type){
char* result = reb_name_for_binary_field_type_const(type);
if (!result) return NULL;
char* result2 = strstr(result, " ");
char* name = malloc(sizeof(char)*(result2-result));
strncpy(name, result, result2-result);
return name;

}

int reb_binary_diff_with_options(char* buf1, size_t size1, char* buf2, size_t size2, char** bufp, size_t* sizep, int output_option){
if (!buf1 || !buf2 || size1<64 || size2<64){
printf("Cannot read input buffers.\n");
Expand Down Expand Up @@ -127,7 +147,11 @@ int reb_binary_diff_with_options(char* buf1, size_t size1, char* buf2, size_t si
reb_output_stream_write(bufp, &allocatedsize, sizep, &field1,sizeof(struct reb_binary_field));
break;
case 1:
printf("Field %d not in simulation 2.\n",field1.type);
{
char* name = reb_name_for_binary_field_type(field1.type);
printf("Field \"%s\" (type=%d) not in simulation 2.\n",name, field1.type);
free(name);
}
break;
default:
break;
Expand Down Expand Up @@ -171,7 +195,11 @@ int reb_binary_diff_with_options(char* buf1, size_t size1, char* buf2, size_t si
reb_output_stream_write(bufp, &allocatedsize, sizep, buf2+pos2,field2.size);
break;
case 1:
printf("Field %d differs.\n",field1.type);
{
char* name = reb_name_for_binary_field_type(field1.type);
printf("Field \"%s\" (type=%d) differs.\n",name, field1.type);
free(name);
}
break;
default:
break;
Expand Down Expand Up @@ -236,7 +264,11 @@ int reb_binary_diff_with_options(char* buf1, size_t size1, char* buf2, size_t si
reb_output_stream_write(bufp, &allocatedsize, sizep, buf2+pos2,field2.size);
break;
case 1:
printf("Field %d not in simulation 1.\n",field2.type);
{
char* name = reb_name_for_binary_field_type(field1.type);
printf("Field \"%s\" (type=%d) not in simulation 1.\n",name, field1.type);
free(name);
}
break;
default:
break;
Expand Down
7 changes: 7 additions & 0 deletions src/rebound.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,3 +936,10 @@ const char* reb_logo[26] = {
" `-/oyyyssosssyso+/. ",
" ``....` ",
};


// Recreate following with
// grep REB_BINARY_FIELD_TYPE_ src/rebound.h | awk -F 'REB_BINARY_FIELD_TYPE_|=|,' '{print $3, $2}' | xarg
// Add space at beginning and end.
const char* reb_binary_field_type_reverse =
" 0 T 1 G 2 SOFTENING 3 DT 4 N 5 NVAR 6 VARCONFIGN 7 NACTIVE 8 TESTPARTICLETYPE 9 HASHCTR 10 OPENINGANGLE2 11 STATUS 12 EXACTFINISHTIME 13 FORCEISVELOCITYDEP 14 GRAVITYIGNORETERMS 15 OUTPUTTIMINGLAST 16 SAVEMESSAGES 17 EXITMAXDISTANCE 18 EXITMINDISTANCE 19 USLEEP 20 TRACKENERGYOFFSET 21 ENERGYOFFSET 22 BOXSIZE 23 BOXSIZEMAX 24 ROOTSIZE 25 ROOTN 26 ROOTNX 27 ROOTNY 28 ROOTNZ 29 NGHOSTX 30 NGHOSTY 31 NGHOSTZ 32 COLLISIONRESOLVEKEEPSORTED 33 MINIMUMCOLLISIONVELOCITY 34 COLLISIONSPLOG 35 MAXRADIUS 36 COLLISIONSNLOG 37 CALCULATEMEGNO 38 MEGNOYS 39 MEGNOYSS 40 MEGNOCOVYT 41 MEGNOVART 42 MEGNOMEANT 43 MEGNOMEANY 44 MEGNON 45 SASIZEFIRST 46 SASIZESNAPSHOT 47 SAAUTOINTERVAL 102 SAAUTOWALLTIME 48 SANEXT 50 COLLISION 51 INTEGRATOR 52 BOUNDARY 53 GRAVITY 54 SEI_OMEGA 55 SEI_OMEGAZ 56 SEI_LASTDT 57 SEI_SINDT 58 SEI_TANDT 59 SEI_SINDTZ 60 SEI_TANDTZ 61 WHFAST_CORRECTOR 62 WHFAST_RECALCJAC 63 WHFAST_SAFEMODE 64 WHFAST_KEEPUNSYNC 65 WHFAST_ISSYNCHRON 66 WHFAST_TIMESTEPWARN 69 IAS15_EPSILON 70 IAS15_MINDT 71 IAS15_EPSILONGLOBAL 72 IAS15_ITERATIONSMAX 85 PARTICLES 86 VARCONFIG 87 FUNCTIONPOINTERS 88 IAS15_ALLOCATEDN 89 IAS15_AT 90 IAS15_X0 91 IAS15_V0 92 IAS15_A0 93 IAS15_CSX 94 IAS15_CSV 95 IAS15_CSA0 96 IAS15_G 97 IAS15_B 98 IAS15_CSB 99 IAS15_E 100 IAS15_BR 101 IAS15_ER 104 WHFAST_PJ 107 VISUALIZATION 110 JANUS_ALLOCATEDN 112 JANUS_PINT 113 JANUS_SCALEPOS 114 JANUS_SCALEVEL 115 JANUS_ORDER 116 JANUS_RECALC 117 WHFAST_COORDINATES 118 MERCURIUS_HILLFAC 119 MERCURIUS_SAFEMODE 120 MERCURIUS_ISSYNCHRON 122 MERCURIUS_DCRIT 123 MERCURIUS_RECALCULATE_COORD 125 SAVERSION 126 WALLTIME 130 PYTHON_UNIT_L 131 PYTHON_UNIT_M 132 PYTHON_UNIT_T 133 MERCURIUS_COMPOS 134 MERCURIUS_COMVEL 135 SAAUTOSTEP 136 SANEXTSTEP 137 STEPSDONE 140 SABA_SAFEMODE 141 SABA_ISSYNCHRON 143 WHFAST_CORRECTOR2 144 WHFAST_KERNEL 145 DTLASTDONE 146 SABA_TYPE 147 SABA_KEEPUNSYNC 148 EOS_PHI0 149 EOS_PHI1 150 EOS_N 151 EOS_SAFEMODE 152 EOS_ISSYNCHRON 154 RAND_SEED 155 TESTPARTICLEHIDEWARNINGS 156 BS_EPSABS 157 BS_EPSREL 158 BS_MINDT 159 BS_MAXDT 160 BS_FIRSTORLASTSTEP 161 BS_PREVIOUSREJECTED 162 BS_TARGETITER 163 VARRESCALEWARNING 300 TES_DQ_MAX 301 TES_RECTI_PER_ORBIT 302 TES_EPSILON 303 TES_PERIOD 304 TES_ALLOCATED_N 305 TES_PARTICLES_DH 306 TES_SV_LEN 307 TES_SV_SIZE 308 TES_CV_LEN 309 TES_CV_SIZE 310 TES_MASS 311 TES_X_DH 312 TES_COM 313 TES_COM_DOT 314 TES_MASS_STAR_LAST 320 TES_UVARS_SV_SIZE 321 TES_UVARS_CV_SIZE 322 TES_UVARS_T0 323 TES_UVARS_TLAST 324 TES_UVARS_CSQ 325 TES_UVARS_CSP 326 TES_UVARS_CSV 327 TES_UVARS_Q0 328 TES_UVARS_V0 329 TES_UVARS_P0 330 TES_UVARS_Q1 331 TES_UVARS_V1 332 TES_UVARS_P1 333 TES_UVARS_X 334 TES_UVARS_Q0_NORM 335 TES_UVARS_BETA 336 TES_UVARS_ETA 337 TES_UVARS_ZETA 338 TES_UVARS_PERIOD 339 TES_UVARS_XPERIOD 340 TES_UVARS_STUMPF_C0 341 TES_UVARS_STUMPF_C1 342 TES_UVARS_STUMPF_C2 343 TES_UVARS_STUMPF_C3 344 TES_UVARS_MU 350 TES_RADAU_DX 351 TES_RADAU_XOUT 352 TES_RADAU_RECTI_ARRAY 353 TES_RADAU_PREDICTORS 354 TES_RADAU_DSTATE0 355 TES_RADAU_DDSTATE0 356 TES_RADAU_DSTATE 357 TES_RADAU_DDSTATE 358 TES_RADAU_CS_DSTATE0 359 TES_RADAU_CS_DDSTATE0 360 TES_RADAU_CS_DSTATE 361 TES_RADAU_CS_DDSTATE 362 TES_RADAU_CS_DX 363 TES_RADAU_FCALLS 364 TES_RADAU_RECTIS 365 TES_RADAU_ITERS 366 TES_RADAU_B6 367 TES_RADAU_B 368 TES_RADAU_BLAST 369 TES_RADAU_B_1ST 370 TES_RADAU_BLAST_1ST 371 TES_RADAU_CS_B 372 TES_RADAU_CS_B_1ST 373 TES_RADAU_G 374 TES_RADAU_G_1ST 380 TES_DHEM_XOSC_STORE 381 TES_DHEM_XOSC_PRED_STORE 382 TES_DHEM_XOSC_CS_STORE 383 TES_DHEM_XOSC_DOT_STORE 384 TES_DHEM_X 385 TES_DHEM_M_INV 386 TES_DHEM_M_TOTAL 387 TES_DHEM_RECTI_TIME 388 TES_DHEM_RECTI_PERIOD 390 WHFAST512_KEEPUNSYNC 391 WHFAST512_ISSYNCHRON 392 WHFAST512_GRPOTENTIAL 393 WHFAST512_ALLOCATEDN 394 WHFAST512_PJH 395 WHFAST512_PJH0 1329743186 HEADER 9998 SABLOB 9999 END ";
3 changes: 3 additions & 0 deletions src/rebound.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ extern const char* reb_build_str; ///< Date and time build string.
extern const char* reb_version_str; ///< Version string.
extern const char* reb_githash_str; ///< Current git hash.
extern const char* reb_logo[26]; ///< Logo of rebound.
extern const char* reb_binary_field_type_reverse; ///< Dictionary to allow for reverse lookup of names of REB_BINARY_FIELD_TYPE
extern volatile sig_atomic_t reb_sigint; ///< Graceful global interrupt handler

// Forward declarations
Expand Down Expand Up @@ -1050,6 +1051,8 @@ void reb_binary_diff(char* buf1, size_t size1, char* buf2, size_t size2, char**
// output_option If set to 0, the differences are written to bufp. If set to 1, printed on the screen. If set to 2, then only the return value indicates any differences.
// returns 0 is returned if the simulations do not differ (are equal). 1 is return if they differ.
int reb_binary_diff_with_options(char* buf1, size_t size1, char* buf2, size_t size2, char** bufp, size_t* sizep, int output_option);
// Returns the name fora given binary field type
char* reb_name_for_binary_field_type(int type);

// Input functions
struct reb_simulation* reb_create_simulation_from_binary(char* filename);
Expand Down

0 comments on commit fb496f5

Please sign in to comment.