12
12
static const char * batch_opt_string = "c:h?" ;
13
13
static const struct option long_batch_options [] = {{"config_file" , required_argument , NULL , 'c' }};
14
14
15
+ #define eikonal_opt_string batch_opt_string
16
+ #define long_eikonal_options long_batch_options
17
+
15
18
static const char * conversion_opt_string = "i:o:c:h?" ;
16
19
static const struct option long_conversion_options [] = {{"input" , required_argument , NULL , 'i' },
17
20
{"output" , required_argument , NULL , 'o' },
@@ -134,6 +137,15 @@ void display_batch_usage(char **argv) {
134
137
exit (EXIT_FAILURE );
135
138
}
136
139
140
+ void display_eikonal_usage (char * * argv ) {
141
+
142
+ printf ("Usage: %s [options]\n\n" , argv [0 ]);
143
+ printf ("Options:\n" );
144
+ printf ("--config_file | -c [configuration_file_path]. Eikonal solver configuration file. Default NULL.\n" );
145
+ printf ("--help | -h. Shows this help and exit \n" );
146
+ exit (EXIT_FAILURE );
147
+ }
148
+
137
149
void display_conversion_usage (char * * argv ) {
138
150
139
151
printf ("Usage: %s [options]\n\n" , argv [0 ]);
@@ -168,7 +180,7 @@ void display_visualization_usage(char **argv) {
168
180
exit (EXIT_FAILURE );
169
181
}
170
182
171
- void maybe_issue_overwrite_warning (const char * var , const char * section , const char * old_value , const char * new_value , const char * config_file ) {
183
+ static void maybe_issue_overwrite_warning (const char * var , const char * section , const char * old_value , const char * new_value , const char * config_file ) {
172
184
if (strcmp (old_value , new_value ) != 0 ) {
173
185
fprintf (stderr ,
174
186
"WARNING: option %s in %s was set in the file %s to %s and is being overwritten "
@@ -177,6 +189,26 @@ void maybe_issue_overwrite_warning(const char *var, const char *section, const c
177
189
}
178
190
}
179
191
192
+ struct eikonal_options * new_eikonal_options () {
193
+ struct eikonal_options * user_args = (struct eikonal_options * )calloc (1 , sizeof (struct eikonal_options ));
194
+
195
+ user_args -> stim_configs = NULL ;
196
+ sh_new_arena (user_args -> stim_configs );
197
+ shdefault (user_args -> stim_configs , NULL );
198
+
199
+ user_args -> domain_config = NULL ;
200
+ user_args -> save_mesh_config = NULL ;
201
+
202
+ return user_args ;
203
+ }
204
+
205
+ void free_eikonal_options (struct eikonal_options * options ) {
206
+ shfree (options -> stim_configs );
207
+ free_config_data (options -> domain_config );
208
+ free_config_data (options -> save_mesh_config );
209
+ free (options );
210
+ }
211
+
180
212
struct batch_options * new_batch_options () {
181
213
struct batch_options * user_args = (struct batch_options * )calloc (1 , sizeof (struct batch_options ));
182
214
sh_new_arena (user_args -> config_to_change );
@@ -1022,7 +1054,7 @@ void parse_batch_options(int argc, char **argv, struct batch_options *user_args)
1022
1054
while (opt != -1 ) {
1023
1055
switch (opt ) {
1024
1056
case 'c' :
1025
- user_args -> batch_config_file = strdup (optarg );
1057
+ user_args -> config_file = strdup (optarg );
1026
1058
break ;
1027
1059
case 'h' : /* fall-through is intentional */
1028
1060
case '?' :
@@ -1037,6 +1069,31 @@ void parse_batch_options(int argc, char **argv, struct batch_options *user_args)
1037
1069
}
1038
1070
}
1039
1071
1072
+ void parse_eikonal_options (int argc , char * * argv , struct eikonal_options * user_args ) {
1073
+
1074
+ int opt = 0 ;
1075
+ int option_index ;
1076
+
1077
+ opt = getopt_long_only (argc , argv , eikonal_opt_string , long_eikonal_options , & option_index );
1078
+
1079
+ while (opt != -1 ) {
1080
+ switch (opt ) {
1081
+ case 'c' :
1082
+ user_args -> config_file = strdup (optarg );
1083
+ break ;
1084
+ case 'h' : /* fall-through is intentional */
1085
+ case '?' :
1086
+ display_eikonal_usage (argv );
1087
+ break ;
1088
+ default :
1089
+ /* You won't actually get here. */
1090
+ break ;
1091
+ }
1092
+
1093
+ opt = getopt_long (argc , argv , eikonal_opt_string , long_eikonal_options , & option_index );
1094
+ }
1095
+ }
1096
+
1040
1097
void parse_conversion_options (int argc , char * * argv , struct conversion_options * user_args ) {
1041
1098
1042
1099
int opt = 0 ;
@@ -1799,6 +1856,53 @@ int parse_config_file(void *user, const char *section, const char *name, const c
1799
1856
return 1 ;
1800
1857
}
1801
1858
1859
+ int parse_eikonal_config_file (void * options , const char * section , const char * name , const char * value ) {
1860
+
1861
+ struct eikonal_options * pconfig = (struct eikonal_options * )options ;
1862
+
1863
+ if (SECTION_STARTS_WITH (STIM_SECTION )) {
1864
+
1865
+ struct config * tmp = (struct config * )shget (pconfig -> stim_configs , section );
1866
+
1867
+ if (tmp == NULL ) {
1868
+ tmp = alloc_and_init_config_data ();
1869
+ shput (pconfig -> stim_configs , section , tmp );
1870
+ }
1871
+
1872
+ if (MATCH_NAME ("name" )) {
1873
+ fprintf (stderr ,
1874
+ "name is a reserved word and should not be used inside a stimulus config section. Found in %s. "
1875
+ "Exiting!\n" ,
1876
+ section );
1877
+ exit (EXIT_FAILURE );
1878
+ } else {
1879
+ set_common_data (tmp , name , value );
1880
+ }
1881
+
1882
+ } else if (MATCH_SECTION (DOMAIN_SECTION )) {
1883
+
1884
+ if (pconfig -> domain_config == NULL ) {
1885
+ pconfig -> domain_config = alloc_and_init_config_data ();
1886
+ }
1887
+
1888
+ set_common_data (pconfig -> domain_config , name , value );
1889
+ } else if (MATCH_SECTION (SAVE_RESULT_SECTION )) {
1890
+
1891
+ if (pconfig -> save_mesh_config == NULL ) {
1892
+ pconfig -> save_mesh_config = alloc_and_init_config_data ();
1893
+ }
1894
+
1895
+ set_common_data (pconfig -> save_mesh_config , name , value );
1896
+
1897
+ } else {
1898
+
1899
+ fprintf (stderr , "\033[33;5;7mInvalid name %s in section %s on the config file!\033[0m\n" , name , section );
1900
+ return 0 ;
1901
+ }
1902
+
1903
+ return 1 ;
1904
+ }
1905
+
1802
1906
int parse_preprocessor_config (void * user , const char * section , const char * name , const char * value ) {
1803
1907
1804
1908
static int function_counter = 0 ;
@@ -1832,6 +1936,8 @@ int parse_preprocessor_config(void *user, const char *section, const char *name,
1832
1936
return 1 ;
1833
1937
}
1834
1938
1939
+
1940
+
1835
1941
#define WRITE_INI_SECTION (SECTION ) fprintf(ini_file, "[%s]\n", SECTION)
1836
1942
1837
1943
#define WRITE_NAME_VALUE_WITHOUT_CHECK (NAME , VALUE , SPECIFIER ) fprintf(ini_file, "%s = %" SPECIFIER "\n", NAME, VALUE)
0 commit comments