int main(int argc, char *argv[]) { const char *space_file = "space.txt"; // 書き出すファイル double dt = 1.0; // 時刻の刻み幅 const double stop_time = 400; // 実行時間 FILE *fp; int c; // オプション指定 int i; double t = 0; if ((fp = fopen(space_file, "w")) == NULL) { fprintf(stderr, "error: cannot open %s.\n", space_file); return 1; } // コマンドライン引数の読み込み for (i = 0; i < argc; i++) { if (strcmp(argv[i], "-d") == 0) { if (i + 1 < argc) dt = atof(argv[i + 1]); // 刻み幅 } } // 繰り返し for (i = 0; t <= stop_time; i++, t += dt) { update_velocities(dt); update_positions(dt); if (i % 10 == 0) { plot_stars(fp, t); } } fclose(fp); }
int main(int argc, char *argv[]) { const char *space_file = "space.txt"; FILE *fp; if ((fp = fopen(space_file, "w")) == NULL) { fprintf(stderr, "error: cannot open %s.\n", space_file); return 1; } double dt; const double stop_time = 400; int c; while((c = getopt(argc,argv,"t:h")) != -1){ switch(c){ case 't': dt = atof(optarg); break; case 'h': printf ("enter dt\n"); break; } } int i; double t = 0; for (i = 0; t <= stop_time; i++, t += dt) { update_velocities(dt); update_positions(dt); if (i % 10 == 0) { plot_stars(fp, t); } } fclose(fp); }
int main() { const char *space_file = "space.txt"; FILE *fp; if ((fp = fopen(space_file, "w")) == NULL) { fprintf(stderr, "error: cannot open %s.\n", space_file); return 1; } const double dt = 1.0; const double stop_time = 400; int i; double t = 0; for (i = 0; t <= stop_time; i++, t += dt) { update_velocities(dt); update_positions(dt); if (i % 10 == 0) { plot_stars(fp, t); } } fclose(fp); }