Skip to content

Commit dafe7cb

Browse files
authored
Refactor default file search, allow config filepath var to be (#25)
passed at compile time.
1 parent 06bfdcc commit dafe7cb

File tree

2 files changed

+66
-54
lines changed

2 files changed

+66
-54
lines changed

GNUmakefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ ifeq ($(which_site), unknown)
116116
# everything into the /usr/local tree.
117117
INCLUDE_LOCATIONS += /usr/local/include
118118
LIBRARY_LOCATIONS += /usr/local/lib
119-
119+
120120
# if dependencies installed via macport, everything symlinks
121121
# to /opt/local/
122122
INCLUDE_LOCATIONS += /opt/local/include
123123
LIBRARY_LOCATIONS += /opt/local/lib
124-
124+
125125
# on macOS X11 is installed into the /opt tree
126126
INCLUDE_LOCATIONS += /opt/X11/include
127127
LIBRARY_LOCATIONS += /opt/X11/lib
@@ -180,6 +180,9 @@ endif
180180
#DEFINES += -DSCROLLBARERROR
181181
#DEFINES += -DFIXDENORMALS
182182

183+
ifdef CONFIG_FILEPATH
184+
DEFINES += -DAMRVIS_CONFIG_FILEPATH='"${CONFIG_FILEPATH}"'
185+
endif
183186
############################################### float fix
184187
# if we are using float override FOPTF which sets -real_size 64
185188
ifeq ($(PRECISION), FLOAT)

GlobalUtilities.cpp

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ bool AVGlobals::ReadLightingFile(const string &lightdefaultsFile,
176176

177177
ws(defs);
178178
defs.getline(buffer, Amrvis::BUFSIZE, '\n');
179-
179+
180180
while( ! defs.eof()) {
181181
sscanf(buffer,"%s", defaultString);
182-
182+
183183
if(defaultString[0] != '#') { // a comment starts with #
184184
if(strcmp(defaultString,"ambient") == 0) {
185185
sscanf(buffer, "%s%s", defaultString, cRealIn);
@@ -275,50 +275,59 @@ void AVGlobals::GetDefaults(const string &defaultsFile) {
275275
bShowBody = true;
276276
startWithValueModel = false;
277277

278+
278279
// try to find the defaultsFile
280+
279281
string fullDefaultsFile;
282+
const string homePath = getenv("HOME");
283+
284+
std::vector<string> fullDefaultsFileList;
285+
#ifdef AMRVIS_CONFIG_FILEPATH
286+
string configFilepath(AMRVIS_CONFIG_FILEPATH);
287+
fullDefaultsFileList.push_back(configFilepath + "/" + defaultsFile);
288+
#endif
289+
fullDefaultsFileList.push_back("./" + defaultsFile);
290+
fullDefaultsFileList.push_back(homePath + "/" + defaultsFile);
291+
fullDefaultsFileList.push_back(homePath + "/." + defaultsFile);
280292

281-
fullDefaultsFile = "./" + defaultsFile; // try dot first
282293
ifstream defs;
283-
defs.open(fullDefaultsFile.c_str());
284294

285-
if(defs.fail()) { // try ~ (tilde)
286-
if(ParallelDescriptor::IOProcessor()) {
287-
cout << "Cannot find amrvis defaults file: " << fullDefaultsFile << endl;
288-
}
289-
fullDefaultsFile = getenv("HOME");
290-
fullDefaultsFile += "/";
291-
fullDefaultsFile += defaultsFile;
292-
defs.clear(); // must do this to clear the fail bit
293-
defs.open(fullDefaultsFile.c_str());
294-
if(defs.fail()) { // try ~/. (hidden file)
295-
if(ParallelDescriptor::IOProcessor()) {
296-
cout << "Cannot find amrvis defaults file: " << fullDefaultsFile << endl;
297-
}
298-
fullDefaultsFile = getenv("HOME");
299-
fullDefaultsFile += "/.";
300-
fullDefaultsFile += defaultsFile;
295+
bool fileFound = false;
296+
297+
for (string const& fileLoc : fullDefaultsFileList){
298+
301299
defs.clear(); // must do this to clear the fail bit
302-
defs.open(fullDefaultsFile.c_str());
303-
if(defs.fail()) { // punt
300+
defs.open(fileLoc.c_str());
301+
if(defs.fail()) {
304302
if(ParallelDescriptor::IOProcessor()) {
305-
cout << "Cannot find amrvis defaults file: " << fullDefaultsFile << endl;
306-
cout << "Using standard defaults." << endl;
307-
}
308-
return;
303+
cout << "Cannot find amrvis defaults file: " << fileLoc << endl;
304+
}
305+
} else {
306+
fullDefaultsFile = fileLoc;
307+
fileFound = true;
308+
break;
309309
}
310+
}
311+
312+
if (!fileFound) {
313+
if(ParallelDescriptor::IOProcessor()) {
314+
cout << "Cannot find amrvis defaults file: " << fullDefaultsFile << endl;
315+
cout << "Using standard defaults." << endl;
310316
}
317+
return;
311318
}
319+
312320
if(ParallelDescriptor::IOProcessor()) {
313321
cout << "Reading defaults from: " << fullDefaultsFile << endl;
314322
}
315323

324+
316325
ws(defs);
317326
defs.getline(buffer, Amrvis::BUFSIZE, '\n');
318-
327+
319328
while( ! defs.eof()) {
320329
sscanf(buffer,"%s", defaultString);
321-
330+
322331
if(defaultString[0] != '#') { // a comment starts with #
323332
if(strcmp(defaultString,"palette") == 0) {
324333
sscanf(buffer, "%s%s",defaultString, tempString);
@@ -541,19 +550,19 @@ void PrintUsage(char *exname) {
541550
cout << '\n';
542551

543552

544-
cout << " -help print help and exit." << '\n';
553+
cout << " -help print help and exit." << '\n';
545554
cout << " file type flags: -fab [-fb], -multifab [-mf], -profdata, -newplt (default)" << '\n';
546-
cout << " -v verbose." << '\n';
555+
cout << " -v verbose." << '\n';
547556
cout << " -maxpixmapsize n specify maximum allowed picture size in pixels."
548557
<< '\n';
549558
cout << " -subdomain _box_ specify subdomain box (on finest level)." << '\n';
550559
cout << " _box_ format: lox loy loz hix hiy hiz." << '\n';
551-
cout << " -skippltlines n skip n lines at head of the plt file." << '\n';
552-
cout << " -boxcolor n set volumetric box color value [0,255]." << '\n';
560+
cout << " -skippltlines n skip n lines at head of the plt file." << '\n';
561+
cout << " -boxcolor n set volumetric box color value [0,255]." << '\n';
553562
#if(BL_SPACEDIM != 3)
554-
cout << " -a load files as an animation." << '\n';
555-
cout << " -aa load files as an animation with annotations." << '\n';
556-
cout << " -anc load files as an animation, dont cache frames." << '\n';
563+
cout << " -a load files as an animation." << '\n';
564+
cout << " -aa load files as an animation with annotations." << '\n';
565+
cout << " -anc load files as an animation, dont cache frames." << '\n';
557566
#endif
558567
//cout << " -sleep n specify sleep time (for attaching parallel debuggers)." << '\n';
559568
cout << " -setvelnames xname yname (zname) specify velocity names for" << '\n';
@@ -563,14 +572,14 @@ void PrintUsage(char *exname) {
563572
cout << " -fabiosize nbits write fabs with nbits (valid values are 1 (ascii), 8 or 32." << '\n';
564573
cout << " the default is native (usually 64)." << '\n';
565574
cout << " -maxlev n specify the maximum drawn level." << '\n';
566-
cout << " -palette palname set the initial palette." << '\n';
567-
cout << " -lightingfile name set the initial lighting parameter file." << '\n';
568-
cout << " -maxmenuitems n set the max menu items per column to n." << '\n';
569-
cout << " -initialderived dername set the initial derived to dername." << '\n';
570-
cout << " -initialscale n set the initial scale to n." << '\n';
571-
cout << " -showboxes tf show boxes (the value of tf is true or false)." << '\n';
572-
cout << " -showbody tf show cartGrid body as body cells (def is true)." << '\n';
573-
cout << " -numberformat fmt set the initial format to fmt (ex: %4.2f)." << '\n';
575+
cout << " -palette palname set the initial palette." << '\n';
576+
cout << " -lightingfile name set the initial lighting parameter file." << '\n';
577+
cout << " -maxmenuitems n set the max menu items per column to n." << '\n';
578+
cout << " -initialderived dername set the initial derived to dername." << '\n';
579+
cout << " -initialscale n set the initial scale to n." << '\n';
580+
cout << " -showboxes tf show boxes (the value of tf is true or false)." << '\n';
581+
cout << " -showbody tf show cartGrid body as body cells (def is true)." << '\n';
582+
cout << " -numberformat fmt set the initial format to fmt (ex: %4.2f)." << '\n';
574583
cout << " -lowblack sets the lowest color in the palette to black." << '\n';
575584
#ifdef BL_OPTIO
576585
cout << " -useperstreams tf use vismf persistent streams." << '\n';
@@ -590,11 +599,11 @@ void PrintUsage(char *exname) {
590599

591600
cout << '\n';
592601
cout << "-------------------------------------------------------- batch functions" << '\n';
593-
cout << " -xslice n write a fab slice at x = n (n at the finest level)." << '\n';
594-
cout << " -yslice n write a fab slice at y = n (n at the finest level)." << '\n';
595-
cout << " -zslice n write a fab slice at z = n (n at the finest level)." << '\n';
596-
cout << " -sliceallvars write all fab variables instead of just initialderived." << '\n';
597-
cout << " -boxslice _box_ write a fab on the box (box at the finest level)." << '\n';
602+
cout << " -xslice n write a fab slice at x = n (n at the finest level)." << '\n';
603+
cout << " -yslice n write a fab slice at y = n (n at the finest level)." << '\n';
604+
cout << " -zslice n write a fab slice at z = n (n at the finest level)." << '\n';
605+
cout << " -sliceallvars write all fab variables instead of just initialderived." << '\n';
606+
cout << " -boxslice _box_ write a fab on the box (box at the finest level)." << '\n';
598607
cout << " _box_ format: lox loy (loz) hix hiy (hiz)." << '\n';
599608
cout << " example: -boxslice 0 0 0 120 42 200." << '\n';
600609
#ifdef BL_VOLUMERENDER
@@ -710,15 +719,15 @@ void AVGlobals::ParseCommandLine(int argc, char *argv[]) {
710719
++i;
711720
# if (BL_SPACEDIM != 3)
712721
} else if(strcmp(argv[i],"-a") == 0) {
713-
bAnimation = true;
722+
bAnimation = true;
714723
bAnnotated = false;
715724
bCacheAnimFrames = true;
716725
} else if(strcmp(argv[i],"-aa") == 0) {
717-
bAnimation = true;
726+
bAnimation = true;
718727
bAnnotated = true;
719728
bCacheAnimFrames = true;
720729
} else if(strcmp(argv[i],"-anc") == 0) {
721-
bAnimation = true;
730+
bAnimation = true;
722731
bCacheAnimFrames = false;
723732
bAnnotated = false;
724733
# endif
@@ -1071,7 +1080,7 @@ void AVGlobals::ParseCommandLine(int argc, char *argv[]) {
10711080
comlinebox.setBig(Amrvis::XDIR, atoi(clbx));
10721081
comlinebox.setBig(Amrvis::YDIR, atoi(clby));
10731082
#else
1074-
if(atoi(clsx) > atoi(clbx) || atoi(clsy) > atoi(clby) ||
1083+
if(atoi(clsx) > atoi(clbx) || atoi(clsy) > atoi(clby) ||
10751084
atoi(clsz) > atoi(clbz))
10761085
{
10771086
if(ParallelDescriptor::IOProcessor()) {

0 commit comments

Comments
 (0)