Commit 3d9b5eaa authored by Thomas White's avatar Thomas White
Browse files

pattern_sim: Configurable output filename

parent 7d097392
......@@ -50,6 +50,12 @@ static void show_help(const char *s)
" --near-bragg Output h,k,l,I near Bragg conditions.\n"
" -n, --number=<N> Generate N images. Default 1.\n"
" --no-images Do not output any HDF5 files.\n"
" -o, --output=<filename> Output HDF5 filename. Default: sim.h5.\n"
" If you choose to simulate more than one pattern,\n"
" the filename given will be postfixed with a\n"
" hyphen, the image number and '.h5'. In this\n"
" case, the default value is 'sim', such that the\n"
" files produced are sim-1.h5, sim-2.h5 and so on.\n"
" -r, --random-orientation Use a randomly generated orientation\n"
" (a new orientation will be used for each image).\n"
" --powder Write a summed pattern of all images simulated by\n"
......@@ -171,6 +177,7 @@ int main(int argc, char *argv[])
int config_powder = 0;
char *filename = NULL;
char *grad_str = NULL;
char *outfile = NULL;
GradientMethod grad;
int ndone = 0; /* Number of simulations done (images or not) */
int number = 1; /* Number used for filename of image */
......@@ -194,11 +201,12 @@ int main(int argc, char *argv[])
{"powder", 0, &config_powder, 1},
{"gradients", 1, NULL, 'g'},
{"pdb", 1, NULL, 'p'},
{"output", 1, NULL, 'o'},
{0, 0, NULL, 0}
};
/* Short options */
while ((c = getopt_long(argc, argv, "hrn:i:g:p:", longopts, NULL)) != -1) {
while ((c = getopt_long(argc, argv, "hrn:i:g:p:o:", longopts, NULL)) != -1) {
switch (c) {
case 'h' : {
......@@ -231,6 +239,11 @@ int main(int argc, char *argv[])
break;
}
case 'o' : {
outfile = strdup(optarg);
break;
}
case 0 : {
break;
}
......@@ -246,6 +259,14 @@ int main(int argc, char *argv[])
filename = strdup("molecule.pdb");
}
if ( outfile == NULL ) {
if ( n_images == 1 ) {
outfile = strdup("sim.h5");
} else {
outfile = strdup("sim");
}
}
if ( config_simdetails ) {
show_details();
return 0;
......@@ -386,7 +407,13 @@ int main(int argc, char *argv[])
char filename[1024];
snprintf(filename, 1023, "results/sim-%i.h5", number);
if ( n_images != 1 ) {
snprintf(filename, 1023, "%s-%i.h5",
outfile, number);
} else {
strncpy(filename, outfile, 1023);
}
number++;
/* Write the output file */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment