Advanced Multi-Physics (AMP)
On-Line Documentation
helper_string.h
Go to the documentation of this file.
1
12// These are helper functions for the SDK samples (string parsing, timers, etc)
13#ifndef STRING_HELPER_H
14#define STRING_HELPER_H
15
16#include <fstream>
17#include <stdio.h>
18#include <stdlib.h>
19#include <string>
20
21#include <cuda.h>
22#include <cuda_runtime.h>
23
24#if defined( WIN32 ) || defined( _WIN32 ) || defined( WIN64 ) || defined( _WIN64 )
25 #ifndef _CRT_SECURE_NO_DEPRECATE
26 #define _CRT_SECURE_NO_DEPRECATE
27 #endif
28 #ifndef STRCASECMP
29 #define STRCASECMP _stricmp
30 #endif
31 #ifndef STRNCASECMP
32 #define STRNCASECMP _strnicmp
33 #endif
34 #ifndef STRCPY
35 #define STRCPY( sFilePath, nLength, sPath ) strcpy_s( sFilePath, nLength, sPath )
36 #endif
37
38 #ifndef FOPEN
39 #define FOPEN( fHandle, filename, mode ) fopen_s( &fHandle, filename, mode )
40 #endif
41 #ifndef FOPEN_FAIL
42 #define FOPEN_FAIL( result ) ( result != 0 )
43 #endif
44 #ifndef SSCANF
45 #define SSCANF sscanf_s
46 #endif
47#else // Linux Includes
48 #include <string.h>
49 #include <strings.h>
50
51 #ifndef STRCASECMP
52 #define STRCASECMP strcasecmp
53 #endif
54 #ifndef STRNCASECMP
55 #define STRNCASECMP strncasecmp
56 #endif
57 #ifndef STRCPY
58 #define STRCPY( sFilePath, nLength, sPath ) strcpy( sFilePath, sPath )
59 #endif
60
61 #ifndef FOPEN
62 #define FOPEN( fHandle, filename, mode ) ( fHandle = fopen( filename, mode ) )
63 #endif
64 #ifndef FOPEN_FAIL
65 #define FOPEN_FAIL( result ) ( result == NULL )
66 #endif
67 #ifndef SSCANF
68 #define SSCANF sscanf
69 #endif
70#endif
71
72#ifndef EXIT_WAIVED
73 #define EXIT_WAIVED 2
74#endif
75
76// CUDA Utility Helper Functions
77inline int stringRemoveDelimiter( char delimiter, const char *string )
78{
79 int string_start = 0;
80
81 while ( string[string_start] == delimiter ) {
82 string_start++;
83 }
84
85 if ( string_start >= (int) strlen( string ) - 1 ) {
86 return 0;
87 }
88
89 return string_start;
90}
91
92inline int getFileExtension( char *filename, char **extension )
93{
94 int string_length = (int) strlen( filename );
95
96 while ( filename[string_length--] != '.' ) {
97 if ( string_length == 0 )
98 break;
99 }
100
101 if ( string_length > 0 )
102 string_length += 2;
103
104 if ( string_length == 0 )
105 *extension = NULL;
106 else
107 *extension = &filename[string_length];
108
109 return string_length;
110}
111
112
113inline bool checkCmdLineFlag( const int argc, const char **argv, const char *string_ref )
114{
115 bool bFound = false;
116
117 if ( argc >= 1 ) {
118 for ( int i = 1; i < argc; i++ ) {
119 int string_start = stringRemoveDelimiter( '-', argv[i] );
120 const char *string_argv = &argv[i][string_start];
121
122 const char *equal_pos = strchr( string_argv, '=' );
123 int argv_length =
124 (int) ( equal_pos == 0 ? strlen( string_argv ) : equal_pos - string_argv );
125
126 int length = (int) strlen( string_ref );
127
128 if ( length == argv_length && !STRNCASECMP( string_argv, string_ref, length ) ) {
129 bFound = true;
130 continue;
131 }
132 }
133 }
134
135 return bFound;
136}
137
138// This function wraps the CUDA Driver API into a template function
139template<class T>
140inline bool
141getCmdLineArgumentValue( const int argc, const char **argv, const char *string_ref, T *value )
142{
143 bool bFound = false;
144
145 if ( argc >= 1 ) {
146 for ( int i = 1; i < argc; i++ ) {
147 int string_start = stringRemoveDelimiter( '-', argv[i] );
148 const char *string_argv = &argv[i][string_start];
149 int length = (int) strlen( string_ref );
150
151 if ( !STRNCASECMP( string_argv, string_ref, length ) ) {
152 if ( length + 1 <= (int) strlen( string_argv ) ) {
153 int auto_inc = ( string_argv[length] == '=' ) ? 1 : 0;
154 *value = (T) atoi( &string_argv[length + auto_inc] );
155 }
156
157 bFound = true;
158 i = argc;
159 }
160 }
161 }
162
163 return bFound;
164}
165
166inline int getCmdLineArgumentInt( const int argc, const char **argv, const char *string_ref )
167{
168 bool bFound = false;
169 int value = -1;
170
171 if ( argc >= 1 ) {
172 for ( int i = 1; i < argc; i++ ) {
173 int string_start = stringRemoveDelimiter( '-', argv[i] );
174 const char *string_argv = &argv[i][string_start];
175 int length = (int) strlen( string_ref );
176
177 if ( !STRNCASECMP( string_argv, string_ref, length ) ) {
178 if ( length + 1 <= (int) strlen( string_argv ) ) {
179 int auto_inc = ( string_argv[length] == '=' ) ? 1 : 0;
180 value = atoi( &string_argv[length + auto_inc] );
181 } else {
182 value = 0;
183 }
184
185 bFound = true;
186 continue;
187 }
188 }
189 }
190
191 if ( bFound ) {
192 return value;
193 } else {
194 return 0;
195 }
196}
197
198inline float getCmdLineArgumentFloat( const int argc, const char **argv, const char *string_ref )
199{
200 bool bFound = false;
201 float value = -1;
202
203 if ( argc >= 1 ) {
204 for ( int i = 1; i < argc; i++ ) {
205 int string_start = stringRemoveDelimiter( '-', argv[i] );
206 const char *string_argv = &argv[i][string_start];
207 int length = (int) strlen( string_ref );
208
209 if ( !STRNCASECMP( string_argv, string_ref, length ) ) {
210 if ( length + 1 <= (int) strlen( string_argv ) ) {
211 int auto_inc = ( string_argv[length] == '=' ) ? 1 : 0;
212 value = (float) atof( &string_argv[length + auto_inc] );
213 } else {
214 value = 0.f;
215 }
216
217 bFound = true;
218 continue;
219 }
220 }
221 }
222
223 if ( bFound ) {
224 return value;
225 } else {
226 return 0;
227 }
228}
229
230inline bool getCmdLineArgumentString( const int argc,
231 const char **argv,
232 const char *string_ref,
233 char **string_retval )
234{
235 bool bFound = false;
236
237 if ( argc >= 1 ) {
238 for ( int i = 1; i < argc; i++ ) {
239 int string_start = stringRemoveDelimiter( '-', argv[i] );
240 char *string_argv = (char *) &argv[i][string_start];
241 int length = (int) strlen( string_ref );
242
243 if ( !STRNCASECMP( string_argv, string_ref, length ) ) {
244 *string_retval = &string_argv[length + 1];
245 bFound = true;
246 continue;
247 }
248 }
249 }
250
251 if ( !bFound ) {
252 *string_retval = NULL;
253 }
254
255 return bFound;
256}
257
266inline char *sdkFindFilePath( const char *filename, const char *executable_path )
267{
268 // <executable_name> defines a variable that is replaced with the name of the executable
269
270 // Typical relative search paths to locate needed companion files (e.g. sample input data, or
271 // JIT source files)
272 // The origin for the relative search may be the .exe file, a .bat file launching an .exe, a
273 // browser .exe launching the .exe or .bat, etc
274 const char *searchPath[] = {
275 "./", // same dir
276 "./common/", // "/common/" subdir
277 "./common/data/", // "/common/data/" subdir
278 "./data/", // "/data/" subdir
279 "./src/", // "/src/" subdir
280 "./src/<executable_name>/data/", // "/src/<executable_name>/data/" subdir
281 "./inc/", // "/inc/" subdir
282 "./0_Simple/", // "/0_Simple/" subdir
283 "./1_Utilities/", // "/1_Utilities/" subdir
284 "./2_Graphics/", // "/2_Graphics/" subdir
285 "./3_Imaging/", // "/3_Imaging/" subdir
286 "./4_Finance/", // "/4_Finance/" subdir
287 "./5_Simulations/", // "/5_Simulations/" subdir
288 "./6_Advanced/", // "/6_Advanced/" subdir
289 "./7_CUDALibraries/", // "/7_CUDALibraries/" subdir
290 "./8_Android/", // "/8_Android/" subdir
291 "./samples/", // "/samples/" subdir
292
293 "./0_Simple/<executable_name>/data/", // "/0_Simple/<executable_name>/data/" subdir
294 "./1_Utilities/<executable_name>/data/", // "/1_Utilities/<executable_name>/data/" subdir
295 "./2_Graphics/<executable_name>/data/", // "/2_Graphics/<executable_name>/data/" subdir
296 "./3_Imaging/<executable_name>/data/", // "/3_Imaging/<executable_name>/data/" subdir
297 "./4_Finance/<executable_name>/data/", // "/4_Finance/<executable_name>/data/" subdir
298 "./5_Simulations/<executable_name>/data/", // "/5_Simulations/<executable_name>/data/"
299 // subdir
300 "./6_Advanced/<executable_name>/data/", // "/6_Advanced/<executable_name>/data/" subdir
301 "./7_CUDALibraries/<executable_name>/", // "/7_CUDALibraries/<executable_name>/" subdir
302 "./7_CUDALibraries/<executable_name>/data/", // "/7_CUDALibraries/<executable_name>/data/"
303 // subdir
304
305 "../", // up 1 in tree
306 "../common/", // up 1 in tree, "/common/" subdir
307 "../common/data/", // up 1 in tree, "/common/data/" subdir
308 "../data/", // up 1 in tree, "/data/" subdir
309 "../src/", // up 1 in tree, "/src/" subdir
310 "../inc/", // up 1 in tree, "/inc/" subdir
311
312 "../0_Simple/<executable_name>/data/", // up 1 in tree, "/0_Simple/<executable_name>/"
313 // subdir
314 "../1_Utilities/<executable_name>/data/", // up 1 in tree, "/1_Utilities/<executable_name>/"
315 // subdir
316 "../2_Graphics/<executable_name>/data/", // up 1 in tree, "/2_Graphics/<executable_name>/"
317 // subdir
318 "../3_Imaging/<executable_name>/data/", // up 1 in tree, "/3_Imaging/<executable_name>/"
319 // subdir
320 "../4_Finance/<executable_name>/data/", // up 1 in tree, "/4_Finance/<executable_name>/"
321 // subdir
322 "../5_Simulations/<executable_name>/data/", // up 1 in tree,
323 // "/5_Simulations/<executable_name>/" subdir
324 "../6_Advanced/<executable_name>/data/", // up 1 in tree, "/6_Advanced/<executable_name>/"
325 // subdir
326 "../7_CUDALibraries/<executable_name>/data/", // up 1 in tree,
327 // "/7_CUDALibraries/<executable_name>/"
328 // subdir
329 "../8_Android/<executable_name>/data/", // up 1 in tree, "/8_Android/<executable_name>/"
330 // subdir
331 "../samples/<executable_name>/data/", // up 1 in tree, "/samples/<executable_name>/" subdir
332 "../../", // up 2 in tree
333 "../../common/", // up 2 in tree, "/common/" subdir
334 "../../common/data/", // up 2 in tree, "/common/data/" subdir
335 "../../data/", // up 2 in tree, "/data/" subdir
336 "../../src/", // up 2 in tree, "/src/" subdir
337 "../../inc/", // up 2 in tree, "/inc/" subdir
338 "../../sandbox/<executable_name>/data/", // up 2 in tree, "/sandbox/<executable_name>/"
339 // subdir
340 "../../0_Simple/<executable_name>/data/", // up 2 in tree, "/0_Simple/<executable_name>/"
341 // subdir
342 "../../1_Utilities/<executable_name>/data/", // up 2 in tree,
343 // "/1_Utilities/<executable_name>/" subdir
344 "../../2_Graphics/<executable_name>/data/", // up 2 in tree,
345 // "/2_Graphics/<executable_name>/" subdir
346 "../../3_Imaging/<executable_name>/data/", // up 2 in tree, "/3_Imaging/<executable_name>/"
347 // subdir
348 "../../4_Finance/<executable_name>/data/", // up 2 in tree, "/4_Finance/<executable_name>/"
349 // subdir
350 "../../5_Simulations/<executable_name>/data/", // up 2 in tree,
351 // "/5_Simulations/<executable_name>/" subdir
352 "../../6_Advanced/<executable_name>/data/", // up 2 in tree,
353 // "/6_Advanced/<executable_name>/" subdir
354 "../../7_CUDALibraries/<executable_name>/data/", // up 2 in tree,
355 // "/7_CUDALibraries/<executable_name>/"
356 // subdir
357 "../../8_Android/<executable_name>/data/", // up 2 in tree, "/8_Android/<executable_name>/"
358 // subdir
359 "../../samples/<executable_name>/data/", // up 2 in tree, "/samples/<executable_name>/"
360 // subdir
361 "../../../", // up 3 in tree
362 "../../../src/<executable_name>/", // up 3 in tree, "/src/<executable_name>/" subdir
363 "../../../src/<executable_name>/data/", // up 3 in tree, "/src/<executable_name>/data/"
364 // subdir
365 "../../../src/<executable_name>/src/", // up 3 in tree, "/src/<executable_name>/src/" subdir
366 "../../../src/<executable_name>/inc/", // up 3 in tree, "/src/<executable_name>/inc/" subdir
367 "../../../sandbox/<executable_name>/", // up 3 in tree, "/sandbox/<executable_name>/" subdir
368 "../../../sandbox/<executable_name>/data/", // up 3 in tree,
369 // "/sandbox/<executable_name>/data/" subdir
370 "../../../sandbox/<executable_name>/src/", // up 3 in tree,
371 // "/sandbox/<executable_name>/src/" subdir
372 "../../../sandbox/<executable_name>/inc/", // up 3 in tree,
373 // "/sandbox/<executable_name>/inc/" subdir
374 "../../../0_Simple/<executable_name>/data/", // up 3 in tree, "/0_Simple/<executable_name>/"
375 // subdir
376 "../../../1_Utilities/<executable_name>/data/", // up 3 in tree,
377 // "/1_Utilities/<executable_name>/" subdir
378 "../../../2_Graphics/<executable_name>/data/", // up 3 in tree,
379 // "/2_Graphics/<executable_name>/" subdir
380 "../../../3_Imaging/<executable_name>/data/", // up 3 in tree,
381 // "/3_Imaging/<executable_name>/" subdir
382 "../../../4_Finance/<executable_name>/data/", // up 3 in tree,
383 // "/4_Finance/<executable_name>/" subdir
384 "../../../5_Simulations/<executable_name>/data/", // up 3 in tree,
385 // "/5_Simulations/<executable_name>/"
386 // subdir
387 "../../../6_Advanced/<executable_name>/data/", // up 3 in tree,
388 // "/6_Advanced/<executable_name>/" subdir
389 "../../../7_CUDALibraries/<executable_name>/data/", // up 3 in tree,
390 // "/7_CUDALibraries/<executable_name>/"
391 // subdir
392 "../../../8_Android/<executable_name>/data/", // up 3 in tree,
393 // "/8_Android/<executable_name>/" subdir
394 "../../../0_Simple/<executable_name>/", // up 3 in tree, "/0_Simple/<executable_name>/"
395 // subdir
396 "../../../1_Utilities/<executable_name>/", // up 3 in tree,
397 // "/1_Utilities/<executable_name>/" subdir
398 "../../../2_Graphics/<executable_name>/", // up 3 in tree, "/2_Graphics/<executable_name>/"
399 // subdir
400 "../../../3_Imaging/<executable_name>/", // up 3 in tree, "/3_Imaging/<executable_name>/"
401 // subdir
402 "../../../4_Finance/<executable_name>/", // up 3 in tree, "/4_Finance/<executable_name>/"
403 // subdir
404 "../../../5_Simulations/<executable_name>/", // up 3 in tree,
405 // "/5_Simulations/<executable_name>/" subdir
406 "../../../6_Advanced/<executable_name>/", // up 3 in tree, "/6_Advanced/<executable_name>/"
407 // subdir
408 "../../../7_CUDALibraries/<executable_name>/", // up 3 in tree,
409 // "/7_CUDALibraries/<executable_name>/"
410 // subdir
411 "../../../8_Android/<executable_name>/", // up 3 in tree, "/8_Android/<executable_name>/"
412 // subdir
413 "../../../samples/<executable_name>/data/", // up 3 in tree, "/samples/<executable_name>/"
414 // subdir
415 "../../../common/", // up 3 in tree, "../../../common/" subdir
416 "../../../common/data/", // up 3 in tree, "../../../common/data/" subdir
417 "../../../data/", // up 3 in tree, "../../../data/" subdir
418 "../../../../", // up 4 in tree
419 "../../../../src/<executable_name>/", // up 4 in tree, "/src/<executable_name>/" subdir
420 "../../../../src/<executable_name>/data/", // up 4 in tree, "/src/<executable_name>/data/"
421 // subdir
422 "../../../../src/<executable_name>/src/", // up 4 in tree, "/src/<executable_name>/src/"
423 // subdir
424 "../../../../src/<executable_name>/inc/", // up 4 in tree, "/src/<executable_name>/inc/"
425 // subdir
426 "../../../../sandbox/<executable_name>/", // up 4 in tree, "/sandbox/<executable_name>/"
427 // subdir
428 "../../../../sandbox/<executable_name>/data/", // up 4 in tree,
429 // "/sandbox/<executable_name>/data/" subdir
430 "../../../../sandbox/<executable_name>/src/", // up 4 in tree,
431 // "/sandbox/<executable_name>/src/" subdir
432 "../../../../sandbox/<executable_name>/inc/", // up 4 in tree,
433 // "/sandbox/<executable_name>/inc/" subdir
434 "../../../../0_Simple/<executable_name>/data/", // up 4 in tree,
435 // "/0_Simple/<executable_name>/" subdir
436 "../../../../1_Utilities/<executable_name>/data/", // up 4 in tree,
437 // "/1_Utilities/<executable_name>/"
438 // subdir
439 "../../../../2_Graphics/<executable_name>/data/", // up 4 in tree,
440 // "/2_Graphics/<executable_name>/" subdir
441 "../../../../3_Imaging/<executable_name>/data/", // up 4 in tree,
442 // "/3_Imaging/<executable_name>/" subdir
443 "../../../../4_Finance/<executable_name>/data/", // up 4 in tree,
444 // "/4_Finance/<executable_name>/" subdir
445 "../../../../5_Simulations/<executable_name>/data/", // up 4 in tree,
446 // "/5_Simulations/<executable_name>/"
447 // subdir
448 "../../../../6_Advanced/<executable_name>/data/", // up 4 in tree,
449 // "/6_Advanced/<executable_name>/" subdir
450 "../../../../7_CUDALibraries/<executable_name>/data/", // up 4 in tree,
451 // "/7_CUDALibraries/<executable_name>/"
452 // subdir
453 "../../../../8_Android/<executable_name>/data/", // up 4 in tree,
454 // "/8_Android/<executable_name>/" subdir
455 "../../../../0_Simple/<executable_name>/", // up 4 in tree, "/0_Simple/<executable_name>/"
456 // subdir
457 "../../../../1_Utilities/<executable_name>/", // up 4 in tree,
458 // "/1_Utilities/<executable_name>/" subdir
459 "../../../../2_Graphics/<executable_name>/", // up 4 in tree,
460 // "/2_Graphics/<executable_name>/" subdir
461 "../../../../3_Imaging/<executable_name>/", // up 4 in tree, "/3_Imaging/<executable_name>/"
462 // subdir
463 "../../../../4_Finance/<executable_name>/", // up 4 in tree, "/4_Finance/<executable_name>/"
464 // subdir
465 "../../../../5_Simulations/<executable_name>/", // up 4 in tree,
466 // "/5_Simulations/<executable_name>/"
467 // subdir
468 "../../../../6_Advanced/<executable_name>/", // up 4 in tree,
469 // "/6_Advanced/<executable_name>/" subdir
470 "../../../../7_CUDALibraries/<executable_name>/", // up 4 in tree,
471 // "/7_CUDALibraries/<executable_name>/"
472 // subdir
473 "../../../../8_Android/<executable_name>/", // up 4 in tree, "/8_Android/<executable_name>/"
474 // subdir
475 "../../../../samples/<executable_name>/data/", // up 4 in tree,
476 // "/samples/<executable_name>/" subdir
477 "../../../../common/", // up 4 in tree, "../../../common/" subdir
478 "../../../../common/data/", // up 4 in tree, "../../../common/data/" subdir
479 "../../../../data/", // up 4 in tree, "../../../data/" subdir
480 "../../../../../", // up 5 in tree
481 "../../../../../src/<executable_name>/", // up 5 in tree, "/src/<executable_name>/" subdir
482 "../../../../../src/<executable_name>/data/", // up 5 in tree,
483 // "/src/<executable_name>/data/" subdir
484 "../../../../../src/<executable_name>/src/", // up 5 in tree, "/src/<executable_name>/src/"
485 // subdir
486 "../../../../../src/<executable_name>/inc/", // up 5 in tree, "/src/<executable_name>/inc/"
487 // subdir
488 "../../../../../sandbox/<executable_name>/", // up 5 in tree, "/sandbox/<executable_name>/"
489 // subdir
490 "../../../../../sandbox/<executable_name>/data/", // up 5 in tree,
491 // "/sandbox/<executable_name>/data/"
492 // subdir
493 "../../../../../sandbox/<executable_name>/src/", // up 5 in tree,
494 // "/sandbox/<executable_name>/src/" subdir
495 "../../../../../sandbox/<executable_name>/inc/", // up 5 in tree,
496 // "/sandbox/<executable_name>/inc/" subdir
497 "../../../../../0_Simple/<executable_name>/data/", // up 5 in tree,
498 // "/0_Simple/<executable_name>/" subdir
499 "../../../../../1_Utilities/<executable_name>/data/", // up 5 in tree,
500 // "/1_Utilities/<executable_name>/"
501 // subdir
502 "../../../../../2_Graphics/<executable_name>/data/", // up 5 in tree,
503 // "/2_Graphics/<executable_name>/"
504 // subdir
505 "../../../../../3_Imaging/<executable_name>/data/", // up 5 in tree,
506 // "/3_Imaging/<executable_name>/"
507 // subdir
508 "../../../../../4_Finance/<executable_name>/data/", // up 5 in tree,
509 // "/4_Finance/<executable_name>/"
510 // subdir
511 "../../../../../5_Simulations/<executable_name>/data/", // up 5 in tree,
512 // "/5_Simulations/<executable_name>/"
513 // subdir
514 "../../../../../6_Advanced/<executable_name>/data/", // up 5 in tree,
515 // "/6_Advanced/<executable_name>/"
516 // subdir
517 "../../../../../7_CUDALibraries/<executable_name>/data/", // up 5 in tree,
518 // "/7_CUDALibraries/<executable_name>/"
519 // subdir
520 "../../../../../8_Android/<executable_name>/data/", // up 5 in tree,
521 // "/8_Android/<executable_name>/"
522 // subdir
523 "../../../../../samples/<executable_name>/data/", // up 5 in tree,
524 // "/samples/<executable_name>/" subdir
525 "../../../../../common/", // up 5 in tree, "../../../common/" subdir
526 "../../../../../common/data/", // up 5 in tree, "../../../common/data/" subdir
527 };
528
529 // Extract the executable name
530 std::string executable_name;
531
532 if ( executable_path != 0 ) {
533 executable_name = std::string( executable_path );
534
535#if defined( WIN32 ) || defined( _WIN32 ) || defined( WIN64 ) || defined( _WIN64 )
536 // Windows path delimiter
537 size_t delimiter_pos = executable_name.find_last_of( '\\' );
538 executable_name.erase( 0, delimiter_pos + 1 );
539
540 if ( executable_name.rfind( ".exe" ) != std::string::npos ) {
541 // we strip .exe, only if the .exe is found
542 executable_name.resize( executable_name.size() - 4 );
543 }
544
545#else
546 // Linux & OSX path delimiter
547 size_t delimiter_pos = executable_name.find_last_of( '/' );
548 executable_name.erase( 0, delimiter_pos + 1 );
549#endif
550 }
551
552 // Loop over all search paths and return the first hit
553 for ( unsigned int i = 0; i < sizeof( searchPath ) / sizeof( char * ); ++i ) {
554 std::string path( searchPath[i] );
555 size_t executable_name_pos = path.find( "<executable_name>" );
556
557 // If there is executable_name variable in the searchPath
558 // replace it with the value
559 if ( executable_name_pos != std::string::npos ) {
560 if ( executable_path != 0 ) {
561 path.replace( executable_name_pos, strlen( "<executable_name>" ), executable_name );
562 } else {
563 // Skip this path entry if no executable argument is given
564 continue;
565 }
566 }
567
568#ifdef _DEBUG
569 printf( "sdkFindFilePath <%s> in %s\n", filename, path.c_str() );
570#endif
571
572 // Test if the file exists
573 path.append( filename );
574 FILE *fp;
575 FOPEN( fp, path.c_str(), "rb" );
576
577 if ( fp != NULL ) {
578 fclose( fp );
579 // File found
580 // returning an allocated array here for backwards compatibility reasons
581 char *file_path = (char *) malloc( path.length() + 1 );
582 STRCPY( file_path, path.length() + 1, path.c_str() );
583 return file_path;
584 }
585
586 if ( fp ) {
587 fclose( fp );
588 }
589 }
590
591 // File not found
592 return 0;
593}
594
595#endif
bool getCmdLineArgumentString(const int argc, const char **argv, const char *string_ref, char **string_retval)
char * sdkFindFilePath(const char *filename, const char *executable_path)
float getCmdLineArgumentFloat(const int argc, const char **argv, const char *string_ref)
int getFileExtension(char *filename, char **extension)
#define STRCPY(sFilePath, nLength, sPath)
bool getCmdLineArgumentValue(const int argc, const char **argv, const char *string_ref, T *value)
#define FOPEN(fHandle, filename, mode)
#define STRNCASECMP
bool checkCmdLineFlag(const int argc, const char **argv, const char *string_ref)
int stringRemoveDelimiter(char delimiter, const char *string)
int getCmdLineArgumentInt(const int argc, const char **argv, const char *string_ref)



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page