From 72b924d43e17ad90529da023327c11e75488b999 Mon Sep 17 00:00:00 2001
From: lhausamm <loic_hausammann@hotmail.com>
Date: Tue, 3 Apr 2018 00:23:48 +0200
Subject: [PATCH] Move output field filename from cmd line to parameters

---
 examples/main.c                | 17 +++++------------
 examples/parameter_example.yml |  1 +
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/examples/main.c b/examples/main.c
index e439c17fe6..5adadfd266 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -90,8 +90,6 @@ void print_help_message(void) {
   printf("  %2s %14s %s\n", "-n", "{int}",
          "Execute a fixed number of time steps. When unset use the time_end "
          "parameter to stop.");
-  printf("  %2s %14s %s\n", "-o", "",
-         "Filename of the output fields parameters.");
   printf("  %2s %14s %s\n", "-P", "{sec:par:val}",
          "Set parameter value and overwrites values read from the parameters "
          "file. Can be used more than once.");
@@ -200,12 +198,11 @@ int main(int argc, char *argv[]) {
   char *cmdparams[PARSER_MAX_NO_OF_PARAMS];
   char paramFileName[200] = "";
   char restart_file[200] = "";
-  char outputFieldsFileName[200] = "";
   unsigned long long cpufreq = 0;
 
   /* Parse the parameters */
   int c;
-  while ((c = getopt(argc, argv, "acCdDef:FgGhMn:o:P:rsSt:Tv:y:Y:")) != -1)
+  while ((c = getopt(argc, argv, "acCdDef:FgGhMn:P:rsSt:Tv:y:Y:")) != -1)
     switch (c) {
       case 'a':
 #if defined(HAVE_SETAFFINITY) && defined(HAVE_LIBNUMA)
@@ -262,14 +259,6 @@ int main(int argc, char *argv[]) {
           return 1;
         }
         break;
-      case 'o':
-        if (sscanf(optarg, "%s", outputFieldsFileName) != 1) {
-          if (myrank == 0) {
-            printf("Error parsing output fields filename");
-            print_help_message();
-          }
-        }
-        break;
       case 'P':
         cmdparams[nparams] = optarg;
         nparams++;
@@ -473,6 +462,10 @@ int main(int argc, char *argv[]) {
       (struct swift_params *)malloc(sizeof(struct swift_params));
   if (output_fields == NULL)
     error("Error allocating memory for the output fields file.");
+
+  char outputFieldsFileName[200];
+  parser_get_opt_param_string(params, "Snapshots:FieldsFilename",
+			      outputFieldsFileName, "");
   if (myrank == 0) {
     message("Reading runtime output fields from file '%s'",
             outputFieldsFileName);
diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml
index 791db27582..75df3f7e86 100644
--- a/examples/parameter_example.yml
+++ b/examples/parameter_example.yml
@@ -78,6 +78,7 @@ Snapshots:
   UnitVelocity_in_cgs: 1  # (Optional) Unit system for the outputs (Centimeters per second)
   UnitCurrent_in_cgs:  1  # (Optional) Unit system for the outputs (Amperes)
   UnitTemp_in_cgs:     1  # (Optional) Unit system for the outputs (Kelvin)
+  FieldsFilename:      output_fields_example.yml # (Optional) File defining output fields
 
 # Parameters governing the conserved quantities statistics
 Statistics:
-- 
GitLab