ewParam.cpp 6.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <utilits.h>
#include "easywave.h"

struct EWPARAMS Par;


int ewParam( int argc, char **argv )
// Process command line arguments and/or use default
{
  int argn,ierr;

  /* TODO: optimize argument handling */

  // Obligatory command line parameters

  // Bathymetry
  if( ( argn = utlCheckCommandLineOption( argc, argv, "grid", 4 ) ) != 0 ) {
	/* TODO: strdup not necessary here because all arguments in argv reside until program exit -> memory leak */
    Par.fileBathymetry = strdup( argv[argn+1] );
  }
  else return -1;

  // Source: Okada faults or Surfer grid
  if( ( argn = utlCheckCommandLineOption( argc, argv, "source", 6 ) ) != 0 ) {
    Par.fileSource = strdup( argv[argn+1] );
  }
  else return -1;

  // Simulation time, [sec]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "time", 4 ) ) != 0 ) {
    Par.timeMax = atoi( argv[argn+1] );
    Par.timeMax *= 60;
  }
  else return -1;


  // Optional parameters or their default values

  // Model name
  if( ( argn = utlCheckCommandLineOption( argc, argv, "label", 3 ) ) != 0 ) {
    Par.modelName = strdup( argv[argn+1] );
  }
  else Par.modelName = strdup( "eWave" );

  // Deactivate logging
  if( ( argn = utlCheckCommandLineOption( argc, argv, "nolog", 5 ) ) != 0 )
    ;
  else {
    Log.start( "easywave.log" );
    Log.timestamp_disable();
  }

  // Use Coriolis force
  if( ( argn = utlCheckCommandLineOption( argc, argv, "coriolis", 3 ) ) != 0 )
    Par.coriolis = 1;
  else Par.coriolis = 0;

  // Periodic dumping of mariograms and cumulative 2D-plots (wavemax, arrival times), [sec]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "dump", 4 ) ) != 0 )
  Par.outDump = atoi( argv[argn+1] );
  else Par.outDump = 0;

  // Reporting simulation progress, [sec model time]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "progress", 4 ) ) != 0 )
    Par.outProgress = (int)(atof(argv[argn+1])*60);
  else Par.outProgress = 600;

  // 2D-wave propagation output, [sec model time]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "propagation", 4 ) ) != 0 )
    Par.outPropagation = (int)(atof(argv[argn+1])*60);
  else Par.outPropagation = 300;

  // minimal calculation depth, [m]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "min_depth", 9 ) ) != 0 )
    Par.dmin = (float)atof(argv[argn+1]);
  else Par.dmin = 10.;

  // timestep, [sec]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "step", 4 ) ) != 0 )
    Par.dt = atoi(argv[argn+1]);
  else Par.dt = 0;  // will be estimated automatically

  // Initial uplift: relative threshold
  if( ( argn = utlCheckCommandLineOption( argc, argv, "ssh0_rel", 8 ) ) != 0 )
    Par.ssh0ThresholdRel = (float)atof(argv[argn+1]);
  else Par.ssh0ThresholdRel = 0.01;

  // Initial uplift: absolute threshold, [m]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "ssh0_abs", 8 ) ) != 0 )
    Par.ssh0ThresholdAbs = (float)atof(argv[argn+1]);
  else Par.ssh0ThresholdAbs = 0.0;

  // Threshold for 2-D arrival time (0 - do not calculate), [m]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "ssh_arrival", 9 ) ) != 0 )
    Par.sshArrivalThreshold = (float)atof(argv[argn+1]);
  else Par.sshArrivalThreshold = 0.001;

  // Threshold for clipping of expanding computational area, [m]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "ssh_clip", 8 ) ) != 0 )
    Par.sshClipThreshold = (float)atof(argv[argn+1]);
  else Par.sshClipThreshold = 1.e-4;

  // Threshold for resetting the small ssh (keep expanding area from unnesessary growing), [m]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "ssh_zero", 8 ) ) != 0 )
    Par.sshZeroThreshold = (float)atof(argv[argn+1]);
  else Par.sshZeroThreshold = 1.e-5;

  // Threshold for transparency (for png-output), [m]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "ssh_transparency", 8 ) ) != 0 )
    Par.sshTransparencyThreshold = (float)atof(argv[argn+1]);
  else Par.sshTransparencyThreshold = 0.0;

  // Points Of Interest (POIs) input file
  if( ( argn = utlCheckCommandLineOption( argc, argv, "poi", 3 ) ) != 0 ) {
    Par.filePOIs = strdup( argv[argn+1] );
  }
  else Par.filePOIs = NULL;

  // POI fitting: max search distance, [km]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "poi_search_dist", 15 ) ) != 0 )
    Par.poiDistMax = (float)atof(argv[argn+1]);
  else Par.poiDistMax = 10.0;
  Par.poiDistMax *= 1000.;

  // POI fitting: min depth, [m]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "poi_min_depth", 13 ) ) != 0 )
    Par.poiDepthMin = (float)atof(argv[argn+1]);
  else Par.poiDepthMin = 1.0;

  // POI fitting: max depth, [m]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "poi_max_depth", 13 ) ) != 0 )
    Par.poiDepthMax = (float)atof(argv[argn+1]);
  else Par.poiDepthMax = 10000.0;

  // report of POI loading
  if( ( argn = utlCheckCommandLineOption( argc, argv, "poi_report", 7 ) ) != 0 )
    Par.poiReport = 1;
  else Par.poiReport = 0;

  // POI output interval, [sec]
  if( ( argn = utlCheckCommandLineOption( argc, argv, "poi_dt_out", 10 ) ) != 0 )
    Par.poiDt = atoi(argv[argn+1]);
  else Par.poiDt = 30;

  if( ( argn = utlCheckCommandLineOption( argc, argv, "gpu", 3 ) ) != 0 )
	Par.gpu = true;
  else
    Par.gpu = false;

  if( ( argn = utlCheckCommandLineOption( argc, argv, "adjust_ztop", 11 ) ) != 0 )
	Par.adjustZtop = true;
  else
	Par.adjustZtop = false;

  if( ( argn = utlCheckCommandLineOption( argc, argv, "verbose", 7 ) ) != 0 )
	Par.verbose = true;
  else
	Par.verbose = false;

  return 0;
}


void ewLogParams(void)
{
  Log.print("\nModel parameters for this simulation:");
  Log.print("timestep: %d sec", Par.dt);
  Log.print("max time: %g min", (float)Par.timeMax/60);
  Log.print("poi_dt_out: %d sec", Par.poiDt);
  Log.print("poi_report: %s", (Par.poiReport ? "yes" : "no") );
  Log.print("poi_search_dist: %g km", Par.poiDistMax/1000.);
  Log.print("poi_min_depth: %g m", Par.poiDepthMin);
  Log.print("poi_max_depth: %g m", Par.poiDepthMax);
  Log.print("coriolis: %s", (Par.coriolis ? "yes" : "no") );
  Log.print("min_depth: %g m", Par.dmin);
  Log.print("ssh0_rel: %g", Par.ssh0ThresholdRel);
  Log.print("ssh0_abs: %g m", Par.ssh0ThresholdAbs);
  Log.print("ssh_arrival: %g m", Par.sshArrivalThreshold);
  Log.print("ssh_clip: %g m", Par.sshClipThreshold);
  Log.print("ssh_zero: %g m", Par.sshZeroThreshold);
  Log.print("ssh_transparency: %g m\n", Par.sshTransparencyThreshold);

  return;
}