Commit 4aa293b5 authored by Thomas White's avatar Thomas White
Browse files

Options processing

parent c275432a
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <getopt.h>
#include "image.h" #include "image.h"
#include "diffraction.h" #include "diffraction.h"
...@@ -30,11 +31,21 @@ ...@@ -30,11 +31,21 @@
#define CRYSTAL_SIZE (500.0e-9) #define CRYSTAL_SIZE (500.0e-9)
static void main_show_help(const char *s) static void show_help(const char *s)
{ {
printf("Syntax: %s <file1.h5> <file2.h5> [...]\n\n", s); printf("Syntax: %s\n\n", s);
printf("Simulate diffraction patterns\n\n"); printf("Simulate diffraction patterns from small crystals\n");
printf(" -h Display this help message\n"); printf(" probed with femosecond pulses from a free electron laser\n\n");
printf(" -h, --help Display this help message\n");
printf(" --simulation-details Show details of the simulation\n");
}
static void show_details(const char *s)
{
printf("%s: Simulation Details\n\n", s);
printf("Simulates diffraction patterns from small crystals\n");
printf("probed with femtosecond pulses from a free electron laser\n\n");
} }
...@@ -44,20 +55,38 @@ int main(int argc, char *argv[]) ...@@ -44,20 +55,38 @@ int main(int argc, char *argv[])
struct image image; struct image image;
char filename[1024]; char filename[1024];
int number = 1; int number = 1;
int config_simdetails = 0;
const struct option longopts[] = {
{"help", 0, NULL, 'h'},
{"simulation-details", 0, &config_simdetails, 1},
{0, 0, NULL, 0}
};
while ((c = getopt(argc, argv, "h")) != -1) { while ((c = getopt_long(argc, argv, "h", longopts, NULL)) != -1) {
switch ( c ) { switch (c) {
case 'h' : {
show_help(argv[0]);
return 0;
}
case 'h' : { case 0 : {
main_show_help(argv[0]); break;
return 0; }
}
default : {
return 1;
}
} }
} }
if ( config_simdetails ) {
show_details(argv[0]);
return 0;
}
/* Define image parameters */ /* Define image parameters */
image.width = 1024; image.width = 1024;
image.height = 1024; image.height = 1024;
......
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