source: grass/trunk/raster3d/r3.flow/test_main.c

Last change on this file was 69372, checked in by wenzeslaus, 8 years ago

r3.flow: add unit test keyword to test.r3flow (as in test.raster3d.lib), remove hydrology keywords

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 2.8 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <math.h>
5#include <grass/raster3d.h>
6#include <grass/gis.h>
7#include <grass/raster.h>
8#include <grass/vector.h>
9#include <grass/glocale.h>
10
11#include "r3flow_structs.h"
12#include "flowline.h"
13#include "interpolate.h"
14
15static void test_interpolation(RASTER3D_Region * region,
16 RASTER3D_Map ** input_maps, double north,
17 double east, double top)
18{
19 double interpolated[3];
20
21 if (interpolate_velocity(region, input_maps, north, east, top,
22 &interpolated[0], &interpolated[1],
23 &interpolated[2]) < 0) {
24 fprintf(stdout, "return=-1\n");
25 }
26 else
27 fprintf(stdout, "return=0\nvalues=%.10f,%.10f,%.10f\n",
28 interpolated[0], interpolated[1], interpolated[2]);
29
30}
31
32int main(int argc, char *argv[])
33{
34 int i;
35 struct GModule *module;
36 struct Option *test_opt, *coordinates_opt, *input_opt;
37 RASTER3D_Region region;
38 RASTER3D_Map *input_3drasters[3];
39 double coordinates[3];
40
41 G_gisinit(argv[0]);
42 module = G_define_module();
43 G_add_keyword(_("raster3d"));
44 G_add_keyword(_("unit test"));
45 module->description = _("Testing flow lines.");
46
47 test_opt = G_define_option();
48 test_opt->key = "test";
49 test_opt->required = YES;
50 test_opt->type = TYPE_STRING;
51 test_opt->options = "interpolation,gradient";
52 test_opt->description = "Select what is tested";
53
54 coordinates_opt = G_define_option();
55 coordinates_opt->key = "coordinates";
56 coordinates_opt->required = NO;
57 coordinates_opt->type = TYPE_DOUBLE;
58 coordinates_opt->multiple = YES;
59 coordinates_opt->description = "x,y,z coordinates";
60
61 input_opt = G_define_standard_option(G_OPT_R3_INPUTS);
62 input_opt->required = NO;
63
64 if (G_parser(argc, argv))
65 exit(EXIT_FAILURE);
66
67 Rast3d_init_defaults();
68 Rast3d_get_window(&region);
69
70 if (strcmp(test_opt->answer, "interpolation") == 0) {
71
72
73 if (input_opt->answers) {
74 for (i = 0; i < 3; i++) {
75 input_3drasters[i] =
76 Rast3d_open_cell_old(input_opt->answers[i],
77 G_find_raster3d(input_opt->
78 answers[i], ""),
79 &region, RASTER3D_TILE_SAME_AS_FILE,
80 RASTER3D_USE_CACHE_DEFAULT);
81 if (input_3drasters[i] == NULL)
82 Rast3d_fatal_error(_("Unable to open 3D raster map <%s>"),
83 input_opt->answers[i]);
84 }
85 }
86 else
87 G_fatal_error("No input map for interpolation test");
88 if (coordinates_opt->answers) {
89 for (i = 0; i < 3; i++) {
90 if (coordinates_opt->answers[i]) {
91 coordinates[i] = atof(coordinates_opt->answers[i]);
92 }
93 else
94 G_fatal_error("Provide 3 coordinates");
95 }
96 }
97 else
98 G_fatal_error("No coordinates for interpolation test");
99 test_interpolation(&region, input_3drasters, coordinates[1],
100 coordinates[0], coordinates[2]);
101 }
102
103 return EXIT_SUCCESS;
104}
Note: See TracBrowser for help on using the repository browser.