X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=energy.c;h=54c73faff22786536eabcbf66a3d76f6af863869;hb=651274dc0845b6f1a5922268b479ab1c9b41c0e6;hp=d673c14ea2820fd7e8e59b45678f486a842572a0;hpb=04d38304c34c5cac06e7fed4c20e3fe108330b7b;p=moebius2.git diff --git a/energy.c b/energy.c index d673c14..54c73fa 100644 --- a/energy.c +++ b/energy.c @@ -9,8 +9,8 @@ #include #include -#define BEST_F "best" -#define INITIAL_F "initial" +static const char *input_file, *output_file; +static char *output_file_tmp; static double edgewise_vertex_displacement_cost(const Vertices vertices); static double noncircular_rim_cost(const Vertices vertices); @@ -41,10 +41,10 @@ static double compute_energy(const Vertices vertices) { printf(" BEST"); - best_f= fopen(BEST_F ".new","wb"); if (!best_f) diee("fopen new best"); + best_f= fopen(output_file_tmp,"wb"); if (!best_f) diee("fopen new out"); r= fwrite(vertices,sizeof(Vertices),1,best_f); if (r!=1) diee("fwrite"); if (fclose(best_f)) diee("fclose new best"); - if (rename(BEST_F ".new", BEST_F)) diee("rename install new best"); + if (rename(output_file_tmp,output_file)) diee("rename install new best"); best_energy= energy; } @@ -129,7 +129,12 @@ int main(int argc, const char *const *argv) { gsl_vector initial_gsl, step_size_gsl; int r, v, k; - if (argc>1) { fputs("takes no arguments\n",stderr); exit(8); } + if (argc!=3 || argv[1][0]=='-' || strncmp(argv[2],"-o",2)) + { fputs("usage: minimise -o