@@ -321,50 +321,32 @@ int main(int argc, char *argv[])
321
321
322
322
G_get_set_window (& cellhd );
323
323
324
+ Geometry geometry = {0 };
325
+ Settings settings = {0 };
326
+ Setup setup = {0 };
327
+ Simulation sim = {0 };
328
+ settings .hhmax = settings .halpha = settings .hbeta = 0 ;
329
+ settings .ts = false;
330
+
324
331
WaterParams_init (& wp );
325
332
326
- wp .conv = G_database_units_to_meters_factor ();
327
-
328
- wp .mixx = cellhd .west * wp .conv ;
329
- wp .maxx = cellhd .east * wp .conv ;
330
- wp .miyy = cellhd .south * wp .conv ;
331
- wp .mayy = cellhd .north * wp .conv ;
332
-
333
- wp .stepx = cellhd .ew_res * wp .conv ;
334
- wp .stepy = cellhd .ns_res * wp .conv ;
335
- /* wp.step = amin1(wp.stepx,wp.stepy); */
336
- wp .step = (wp .stepx + wp .stepy ) / 2. ;
337
- wp .mx = cellhd .cols ;
338
- wp .my = cellhd .rows ;
339
- wp .xmin = 0. ;
340
- wp .ymin = 0. ;
341
- wp .xp0 = wp .xmin + wp .stepx / 2. ;
342
- wp .yp0 = wp .ymin + wp .stepy / 2. ;
343
- wp .xmax = wp .xmin + wp .stepx * (float )wp .mx ;
344
- wp .ymax = wp .ymin + wp .stepy * (float )wp .my ;
345
- wp .hhc = wp .hhmax = 0. ;
346
-
347
- #if 0
348
- wp .bxmi = 2093113. * wp .conv ;
349
- wp .bymi = 731331. * wp .conv ;
350
- wp .bxma = 2093461. * wp .conv ;
351
- wp .byma = 731529. * wp .conv ;
352
- wp .bresx = 2. * wp .conv ;
353
- wp .bresy = 2. * wp .conv ;
354
- wp .maxwab = 100000 ;
355
-
356
- wp .mx2o = (int )((wp .bxma - wp .bxmi ) / wp .bresx );
357
- wp .my2o = (int )((wp .byma - wp .bymi ) / wp .bresy );
358
-
359
- /* relative small box coordinates: leave 1 grid layer for overlap */
360
-
361
- wp .bxmi = wp .bxmi - wp .mixx + wp .stepx ;
362
- wp .bymi = wp .bymi - wp .miyy + wp .stepy ;
363
- wp .bxma = wp .bxma - wp .mixx - wp .stepx ;
364
- wp .byma = wp .byma - wp .miyy - wp .stepy ;
365
- wp .mx2 = wp .mx2o - 2 * ((int )(wp .stepx / wp .bresx ));
366
- wp .my2 = wp .my2o - 2 * ((int )(wp .stepy / wp .bresy ));
367
- #endif
333
+ geometry .conv = G_database_units_to_meters_factor ();
334
+
335
+ geometry .mixx = cellhd .west * geometry .conv ;
336
+ geometry .miyy = cellhd .south * geometry .conv ;
337
+
338
+ geometry .stepx = cellhd .ew_res * geometry .conv ;
339
+ geometry .stepy = cellhd .ns_res * geometry .conv ;
340
+ /* geometry.step = amin1(geometry.stepx,geometry.stepy); */
341
+ geometry .step = (geometry .stepx + geometry .stepy ) / 2. ;
342
+ geometry .mx = cellhd .cols ;
343
+ geometry .my = cellhd .rows ;
344
+ geometry .xmin = 0. ;
345
+ geometry .ymin = 0. ;
346
+ geometry .xp0 = geometry .xmin + geometry .stepx / 2. ;
347
+ geometry .yp0 = geometry .ymin + geometry .stepy / 2. ;
348
+ geometry .xmax = geometry .xmin + geometry .stepx * (float )geometry .mx ;
349
+ geometry .ymax = geometry .ymin + geometry .stepy * (float )geometry .my ;
368
350
369
351
wp .elevin = parm .elevin -> answer ;
370
352
wp .wdepth = parm .wdepth -> answer ;
@@ -400,35 +382,35 @@ int main(int argc, char *argv[])
400
382
G_message (_ ("Number of threads: %d" ), threads );
401
383
402
384
/* sscanf(parm.nwalk->answer, "%d", &wp.maxwa); */
403
- sscanf (parm .niter -> answer , "%d" , & wp .timesec );
404
- sscanf (parm .mintimestep -> answer , "%lf " , & wp . mintimestep );
405
- sscanf (parm .outiter -> answer , "%d " , & wp . iterout );
385
+ sscanf (parm .niter -> answer , "%d" , & settings .timesec );
386
+ sscanf (parm .outiter -> answer , "%d " , & settings . iterout );
387
+ sscanf (parm .mintimestep -> answer , "%lf " , & settings . mintimestep );
406
388
/* sscanf(parm.density->answer, "%d", &wp.ldemo); */
407
- sscanf (parm .diffc -> answer , "%lf" , & wp .frac );
389
+ sscanf (parm .diffc -> answer , "%lf" , & settings .frac );
408
390
sscanf (parm .maninval -> answer , "%lf" , & wp .manin_val );
409
391
410
392
/* Recompute timesec from user input in minutes
411
393
* to real timesec in seconds */
412
- wp .timesec = wp .timesec * 60 ;
413
- wp .iterout = wp .iterout * 60 ;
414
- if ((wp .timesec / wp .iterout ) > 100 )
394
+ settings .timesec = settings .timesec * 60 ;
395
+ settings .iterout = settings .iterout * 60 ;
396
+ if ((settings .timesec / settings .iterout ) > 100 )
415
397
G_message (_ ("More than 100 files are going to be created !!!!!" ));
416
398
417
399
/* compute how big the raster is and set this to appr 2 walkers per cell */
418
400
if (parm .nwalk -> answer == NULL ) {
419
- wp .maxwa = wp .mx * wp .my * 2 ;
420
- wp .rwalk = (double )(wp .mx * wp .my * 2. );
421
- G_message (_ ("default nwalk=%d, rwalk=%f" ), wp .maxwa , wp .rwalk );
401
+ sim .maxwa = geometry .mx * geometry .my * 2 ;
402
+ sim .rwalk = (double )(geometry .mx * geometry .my * 2. );
403
+ G_message (_ ("default nwalk=%d, rwalk=%f" ), sim .maxwa , sim .rwalk );
422
404
}
423
405
else {
424
- sscanf (parm .nwalk -> answer , "%d" , & wp .maxwa );
425
- wp .rwalk = (double )wp .maxwa ;
406
+ sscanf (parm .nwalk -> answer , "%d" , & sim .maxwa );
407
+ sim .rwalk = (double )sim .maxwa ;
426
408
}
427
409
/*rwalk = (double) maxwa; */
428
410
429
- if (wp .conv != 1.0 )
430
- G_message (_ ("Using metric conversion factor %f, step=%f" ), wp . conv ,
431
- wp .step );
411
+ if (geometry .conv != 1.0 )
412
+ G_message (_ ("Using metric conversion factor %f, step=%f" ),
413
+ geometry . conv , geometry .step );
432
414
433
415
wp .observation = parm .observation -> answer ;
434
416
wp .logfile = parm .logfile -> answer ;
@@ -437,24 +419,24 @@ int main(int argc, char *argv[])
437
419
if ((wp .tc == NULL ) && (wp .et == NULL ) && (wp .conc == NULL ) &&
438
420
(wp .flux == NULL ) && (wp .erdep == NULL ))
439
421
G_warning (_ ("You are not outputting any raster or site files" ));
440
- ret_val = input_data ();
422
+ ret_val = input_data (geometry . my , geometry . mx , & sim );
441
423
if (ret_val != 1 )
442
424
G_fatal_error (_ ("Input failed" ));
443
425
444
- alloc_grids_sediment ();
426
+ alloc_grids_sediment (& geometry );
445
427
446
- grad_check ();
447
- init_grids_sediment ();
428
+ grad_check (& setup , & geometry , & settings );
429
+ init_grids_sediment (& setup , & geometry );
448
430
/* treba dat output pre topoerdep */
449
- main_loop ();
431
+ main_loop (& setup , & geometry , & settings , & sim );
450
432
451
433
/* always true for sediment? */
452
434
if (wp .tserie == NULL ) {
453
- ii = output_data (0 , 1. );
435
+ ii = output_data (0 , 1. , & setup , & geometry , & settings , & sim );
454
436
if (ii != 1 )
455
437
G_fatal_error (_ ("Cannot write raster maps" ));
456
438
}
457
- free_walkers ();
439
+ free_walkers (& sim );
458
440
459
441
/* Exit with Success */
460
442
exit (EXIT_SUCCESS );
0 commit comments