int main(int argc, string argv[]) { initparam(argv, defv); // initialize param access headline = defv[0] + 1; // use default headline startrun(); // get params & input data startoutput(); // activate output code if (nstep == 0) { // if data just initialized treeforce(); // calculate initial forces output(); // generate initial output } if (dtime != 0.0) // if time steps requested while (tstop - tnow > 0.01 * dtime) { // while not past tstop stepsystem(); // advance step by step output(); // output results each time } return (0); // end with proper status }
int main(int argc, string argv[]) { initparam(argv, defv); // initialize param access headline = defv[0] + 1; // use default headline startrun(); // get params & input data startoutput(); // activate output code if (nstep == 0) { // if data just initialized treeforce_initial_0 = wtime(); treeforce(); // calculate initial forces treeforce_initial_1 = wtime(); output(); // generate initial output } if (dtime != 0.0) // if time steps requested // TODO: make this work in timesteps? treeforce_0 = wtime(); while (nstep <= timesteps) { // while not past tstop stepsystem(); // advance step by step output(); // output results each time } // while (tstop - tnow > 0.01 * dtime) { // while not past tstop // stepsystem(); // advance step by step // output(); // output results each time // } treeforce_1 = wtime(); finaloutput(); bodyptr p; bodyptr q; float phi = 0.0f; for (p = bodytab; p < bodytab+nbody; p++) {// loop over all bodies for (q = bodytab; q < bodytab+nbody; q++) {// loop over all bodies // printf("Pos(p) = (%.8f,%.8f,%.8f)\n", Pos(p)[0], Pos(p)[1], Pos(p)[2]); // printf("Pos(q) = (%.8f,%.8f,%.8f)\n", Pos(q)[0], Pos(q)[1], Pos(q)[2]); float rx = Pos(q)[0] - Pos(p)[0]; float ry = Pos(q)[1] - Pos(p)[1]; float rz = Pos(q)[2] - Pos(p)[2]; float r2 = rx*rx + ry*ry + rz*rz + eps; float r2inv = 1.0 / sqrt(r2); float r6inv = r2inv * r2inv * r2inv; float mass = Mass(q); phi += mass * r6inv; } } printf(" Answer = %f\n", phi); return (0); // end with proper status }
void runinput(void) { int c; bol = 1; for(;;){ c = getnext(); if(c < 0) break; if((c == dot || c == tick) && bol){ inrequest = 1; dotline(c); bol = 1; inrequest = 0; }else if(c == '\n'){ newline(); itrap(); linepos = 0; }else{ outtrap(); startoutput(); showihtml(); if(c == '\t'){ /* XXX do better */ outrune(' '); while(++linepos%4) outrune(' '); }else{ outrune(c); linepos++; } bol = 0; } } }