#include <stdio.h>
#include <time.h>
#include <signal.h>
+#include <string.h> // For parsing arguments
#include "nbody.h"
#include "graphics.h"
// --- Function forward declarations --- //
void HandleArguments(int argc, char ** argv); //Interprets program arguments and sets up the "options" variable
-void UnsignedArgument(unsigned * i, int argc, char ** argv, unsigned * store); //Helper function to get switch value for unsigned
+unsigned UnsignedArgument(unsigned * i, int argc, char ** argv, unsigned * store, unsigned * store2); //Helper function to get switch value for unsigned
void FloatArgument(unsigned * i, int argc, char ** argv, float * store); //Helper function to get switch value for float
void DisplayStatistics(); //Called on exit of program, displays information about computation time, steps computed, etc
void Interrupt(int dummy); // Interrupt handler function, called when SIGINT (Ctrl-C) is sent to program
options.input = NULL;
options.output = NULL;
options.num_threads = 0;
+ options.nested_threads = 0;
options.num_steps = 0;
options.timeout = 0;
options.draw_graphics = true;
+ options.pedantic_graphics = false;
options.print_positions = false;
options.verbosity = 0;
}
options.start_clock = clock(); //Get CPU cycles executed before simulation starts
- Simulation_Run(); // Start the simulation
- Graphics_Run(argc, argv); //Start the graphics loop
-
+ Simulation_Run(argc, argv); // Start the simulation
+
+ //printf("Got here!\n");
exit(EXIT_FAILURE); //Should never get to this line
}
switch (argv[i][1]) //The argument is a switch if we get here
{
case 'n': //Number of threads switch
- UnsignedArgument(&i, argc, argv, &(options.num_threads));
+ UnsignedArgument(&i, argc, argv, &(options.num_threads), &(options.nested_threads));
#ifdef SINGLE_THREADED
fprintf(stderr, "Warning: -%c switch has no effect in the single-threaded program.\n", argv[i][1]);
- options.num_threads = 1;
+
#endif //SINGLE_THREADED
break;
case 's': //Number of steps switch
- UnsignedArgument(&i, argc, argv, &(options.num_steps));
+ UnsignedArgument(&i, argc, argv, &(options.num_steps), NULL);
break;
case 't': //Timeout switch (in seconds)
- UnsignedArgument(&i, argc, argv, &(options.timeout));
+ UnsignedArgument(&i, argc, argv, &(options.timeout), NULL);
break;
case 'g': //Graphics switch
options.draw_graphics = !options.draw_graphics;
break;
case 'v': //Verbosity switch
- UnsignedArgument(&i, argc, argv, &(options.verbosity));
+ UnsignedArgument(&i, argc, argv, &(options.verbosity), NULL);
+ break;
+
+ case '-':
+ if (strcmp(argv[i]+1, "pedantic-graphics"))
+ {
+ options.pedantic_graphics = true;
+ #ifdef SINGLE_THREADED
+ fprintf(stderr, "Warning: %s switch has no effect in the single threaded program.\n", argv[i]);
+ #endif //SINGLE_THREADED
+ }
+ else if (strcmp(argv[i]+1, "fast-graphics"))
+ {
+ options.pedantic_graphics = false;
+ #ifdef SINGLE_THREADED
+ fprintf(stderr, "Warning: %s switch has no effect in the single threaded program.\n", argv[i]);
+ #endif //SINGLE_THREADED
+
+ }
+ else
+ {
+ fprintf(stderr, "Unrecognised switch -%s\n", argv[i]);
+ exit(EXIT_FAILURE);
+ }
break;
+
default:
fprintf(stderr, "Unrecognised switch -%c\n", argv[i][1]);
exit(EXIT_FAILURE);
* @param argc - number of arguments
* @param argv - argument strings
* @param store - pointer to unsigned to store result in
+ * @param store2 - pointer to second unsigned
+ * @returns 1 if store was filled, 2 if both store1 and store2 were filled
*/
-void UnsignedArgument(unsigned * i, int argc, char ** argv, unsigned * store)
+unsigned UnsignedArgument(unsigned * i, int argc, char ** argv, unsigned * store, unsigned * store2)
{
if (*i >= argc-1)
{
fprintf(stderr,"Supply a positive integer for the -%c switch.\n", argv[*i][1]);
exit(EXIT_FAILURE);
}
+
+ char * seperator = strstr(argv[*i+1], ":");
+ if (seperator != NULL)
+ {
+ if (store2 == NULL)
+ {
+ fprintf(stderr,"Supply a positive integer for the -%c switch.\n", argv[*i][1]);
+ exit(EXIT_FAILURE);
+ }
+ int val = atoi(seperator+1);
+ if (val <= 0)
+ {
+ fprintf(stderr,"Supply a positive integer for the -%c switch.\n", argv[*i][1]);
+ exit(EXIT_FAILURE);
+ }
+ *store2 = (unsigned)val;
+
+ *seperator = '\0';
+ }
+
int val = atoi(argv[*i+1]);
if (val <= 0)
{
fprintf(stderr,"Supply a positive integer for the -%c switch. %s is invalid.\n", argv[*i][1], argv[*i+1]);
exit(EXIT_FAILURE);
}
- *store = val;
+ *store = (unsigned)val;
*i += 1;
+
+ return (seperator == NULL) ? 1 : 2;
}
/**
* @function FloatArgument