tAdded command line argument parsing - ns2dfd - 2D finite difference Navier Stokes solver for fluid dynamics
(HTM) git clone git://src.adamsgaard.dk/ns2dfd
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 712b7d25f92ae5ecd752f39c2d1578a39d973457
(DIR) parent 323315d2db64d9b54393d45009b1f8ad3c75930c
(HTM) Author: Anders Damsgaard <anders.damsgaard@geo.au.dk>
Date: Sun, 2 Mar 2014 20:31:10 +0100
Added command line argument parsing
Diffstat:
M src/main.c | 47 ++++++++++++++++++++++++++++---
1 file changed, 43 insertions(+), 4 deletions(-)
---
(DIR) diff --git a/src/main.c b/src/main.c
t@@ -1,7 +1,12 @@
#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <unistd.h>
#include "file_io.h"
#include "utility.h"
+#define VERSION 0.1
+
int main(int argc, char** argv)
{
double t, t_end, tau;
t@@ -13,10 +18,44 @@ int main(int argc, char** argv)
int nx, ny;
double **P, **U, **V;
- read_file("unnamed.dat", &t, &t_end, &tau, &itermax,
- &epsilon, &omega, &gamma,
- &gx, &gy, &re, &w_left, &w_right, &w_top, &w_bottom,
- &dx, &dy, &nx, &ny, &P, &U, &V);
+ int c;
+ while ((c = getopt(argc, argv, "hv")) != -1)
+ switch (c)
+ {
+ case 'h':
+ printf("usage: %s [OPTIONS] FILENAME\n"
+ "where FILENAME is a valid input file.\n"
+ "-h\tDisplay help\n"
+ "-v\tDisplay version information\n", argv[0]);
+ return 0;
+ break;
+ case 'v':
+ printf("%s: Navier Stokes solver in 2D using finite differences, "
+ "version %.1f\n"
+ "Written by Anders Damsgaard, "
+ "https://github.com/anders-dc/ns2dfd\n", argv[0], VERSION);
+ return 0;
+ break;
+ case '?':
+ if (isprint(optopt))
+ fprintf(stderr, "Unknown option `-%c`.\n", optopt);
+ else
+ fprintf(stderr, "Unknown option character `\\x%x`.\n", optopt);
+ return 1;
+
+ default:
+ abort();
+ }
+
+ if (optind == argc - 1) {
+ read_file(argv[optind], &t, &t_end, &tau, &itermax,
+ &epsilon, &omega, &gamma,
+ &gx, &gy, &re, &w_left, &w_right, &w_top, &w_bottom,
+ &dx, &dy, &nx, &ny, &P, &U, &V);
+ } else {
+ fprintf(stderr, "%s: no input file specified.\n", argv[0]);
+ return 1;
+ }
printf("omega = %f\n", omega);
printf("P[0][0] = %f\n", P[0][0]);