Skip to content

Commit

Permalink
Refactor default file search, allow config filepath var to be (#25)
Browse files Browse the repository at this point in the history
passed at compile time.
  • Loading branch information
etpalmer63 authored May 31, 2022
1 parent 06bfdcc commit dafe7cb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 54 deletions.
7 changes: 5 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ ifeq ($(which_site), unknown)
# everything into the /usr/local tree.
INCLUDE_LOCATIONS += /usr/local/include
LIBRARY_LOCATIONS += /usr/local/lib

# if dependencies installed via macport, everything symlinks
# to /opt/local/
INCLUDE_LOCATIONS += /opt/local/include
LIBRARY_LOCATIONS += /opt/local/lib

# on macOS X11 is installed into the /opt tree
INCLUDE_LOCATIONS += /opt/X11/include
LIBRARY_LOCATIONS += /opt/X11/lib
Expand Down Expand Up @@ -180,6 +180,9 @@ endif
#DEFINES += -DSCROLLBARERROR
#DEFINES += -DFIXDENORMALS

ifdef CONFIG_FILEPATH
DEFINES += -DAMRVIS_CONFIG_FILEPATH='"${CONFIG_FILEPATH}"'
endif
############################################### float fix
# if we are using float override FOPTF which sets -real_size 64
ifeq ($(PRECISION), FLOAT)
Expand Down
113 changes: 61 additions & 52 deletions GlobalUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ bool AVGlobals::ReadLightingFile(const string &lightdefaultsFile,

ws(defs);
defs.getline(buffer, Amrvis::BUFSIZE, '\n');

while( ! defs.eof()) {
sscanf(buffer,"%s", defaultString);

if(defaultString[0] != '#') { // a comment starts with #
if(strcmp(defaultString,"ambient") == 0) {
sscanf(buffer, "%s%s", defaultString, cRealIn);
Expand Down Expand Up @@ -275,50 +275,59 @@ void AVGlobals::GetDefaults(const string &defaultsFile) {
bShowBody = true;
startWithValueModel = false;


// try to find the defaultsFile

string fullDefaultsFile;
const string homePath = getenv("HOME");

std::vector<string> fullDefaultsFileList;
#ifdef AMRVIS_CONFIG_FILEPATH
string configFilepath(AMRVIS_CONFIG_FILEPATH);
fullDefaultsFileList.push_back(configFilepath + "/" + defaultsFile);
#endif
fullDefaultsFileList.push_back("./" + defaultsFile);
fullDefaultsFileList.push_back(homePath + "/" + defaultsFile);
fullDefaultsFileList.push_back(homePath + "/." + defaultsFile);

fullDefaultsFile = "./" + defaultsFile; // try dot first
ifstream defs;
defs.open(fullDefaultsFile.c_str());

if(defs.fail()) { // try ~ (tilde)
if(ParallelDescriptor::IOProcessor()) {
cout << "Cannot find amrvis defaults file: " << fullDefaultsFile << endl;
}
fullDefaultsFile = getenv("HOME");
fullDefaultsFile += "/";
fullDefaultsFile += defaultsFile;
defs.clear(); // must do this to clear the fail bit
defs.open(fullDefaultsFile.c_str());
if(defs.fail()) { // try ~/. (hidden file)
if(ParallelDescriptor::IOProcessor()) {
cout << "Cannot find amrvis defaults file: " << fullDefaultsFile << endl;
}
fullDefaultsFile = getenv("HOME");
fullDefaultsFile += "/.";
fullDefaultsFile += defaultsFile;
bool fileFound = false;

for (string const& fileLoc : fullDefaultsFileList){

defs.clear(); // must do this to clear the fail bit
defs.open(fullDefaultsFile.c_str());
if(defs.fail()) { // punt
defs.open(fileLoc.c_str());
if(defs.fail()) {
if(ParallelDescriptor::IOProcessor()) {
cout << "Cannot find amrvis defaults file: " << fullDefaultsFile << endl;
cout << "Using standard defaults." << endl;
}
return;
cout << "Cannot find amrvis defaults file: " << fileLoc << endl;
}
} else {
fullDefaultsFile = fileLoc;
fileFound = true;
break;
}
}

if (!fileFound) {
if(ParallelDescriptor::IOProcessor()) {
cout << "Cannot find amrvis defaults file: " << fullDefaultsFile << endl;
cout << "Using standard defaults." << endl;
}
return;
}

if(ParallelDescriptor::IOProcessor()) {
cout << "Reading defaults from: " << fullDefaultsFile << endl;
}


ws(defs);
defs.getline(buffer, Amrvis::BUFSIZE, '\n');

while( ! defs.eof()) {
sscanf(buffer,"%s", defaultString);

if(defaultString[0] != '#') { // a comment starts with #
if(strcmp(defaultString,"palette") == 0) {
sscanf(buffer, "%s%s",defaultString, tempString);
Expand Down Expand Up @@ -541,19 +550,19 @@ void PrintUsage(char *exname) {
cout << '\n';


cout << " -help print help and exit." << '\n';
cout << " -help print help and exit." << '\n';
cout << " file type flags: -fab [-fb], -multifab [-mf], -profdata, -newplt (default)" << '\n';
cout << " -v verbose." << '\n';
cout << " -v verbose." << '\n';
cout << " -maxpixmapsize n specify maximum allowed picture size in pixels."
<< '\n';
cout << " -subdomain _box_ specify subdomain box (on finest level)." << '\n';
cout << " _box_ format: lox loy loz hix hiy hiz." << '\n';
cout << " -skippltlines n skip n lines at head of the plt file." << '\n';
cout << " -boxcolor n set volumetric box color value [0,255]." << '\n';
cout << " -skippltlines n skip n lines at head of the plt file." << '\n';
cout << " -boxcolor n set volumetric box color value [0,255]." << '\n';
#if(BL_SPACEDIM != 3)
cout << " -a load files as an animation." << '\n';
cout << " -aa load files as an animation with annotations." << '\n';
cout << " -anc load files as an animation, dont cache frames." << '\n';
cout << " -a load files as an animation." << '\n';
cout << " -aa load files as an animation with annotations." << '\n';
cout << " -anc load files as an animation, dont cache frames." << '\n';
#endif
//cout << " -sleep n specify sleep time (for attaching parallel debuggers)." << '\n';
cout << " -setvelnames xname yname (zname) specify velocity names for" << '\n';
Expand All @@ -563,14 +572,14 @@ void PrintUsage(char *exname) {
cout << " -fabiosize nbits write fabs with nbits (valid values are 1 (ascii), 8 or 32." << '\n';
cout << " the default is native (usually 64)." << '\n';
cout << " -maxlev n specify the maximum drawn level." << '\n';
cout << " -palette palname set the initial palette." << '\n';
cout << " -lightingfile name set the initial lighting parameter file." << '\n';
cout << " -maxmenuitems n set the max menu items per column to n." << '\n';
cout << " -initialderived dername set the initial derived to dername." << '\n';
cout << " -initialscale n set the initial scale to n." << '\n';
cout << " -showboxes tf show boxes (the value of tf is true or false)." << '\n';
cout << " -showbody tf show cartGrid body as body cells (def is true)." << '\n';
cout << " -numberformat fmt set the initial format to fmt (ex: %4.2f)." << '\n';
cout << " -palette palname set the initial palette." << '\n';
cout << " -lightingfile name set the initial lighting parameter file." << '\n';
cout << " -maxmenuitems n set the max menu items per column to n." << '\n';
cout << " -initialderived dername set the initial derived to dername." << '\n';
cout << " -initialscale n set the initial scale to n." << '\n';
cout << " -showboxes tf show boxes (the value of tf is true or false)." << '\n';
cout << " -showbody tf show cartGrid body as body cells (def is true)." << '\n';
cout << " -numberformat fmt set the initial format to fmt (ex: %4.2f)." << '\n';
cout << " -lowblack sets the lowest color in the palette to black." << '\n';
#ifdef BL_OPTIO
cout << " -useperstreams tf use vismf persistent streams." << '\n';
Expand All @@ -590,11 +599,11 @@ void PrintUsage(char *exname) {

cout << '\n';
cout << "-------------------------------------------------------- batch functions" << '\n';
cout << " -xslice n write a fab slice at x = n (n at the finest level)." << '\n';
cout << " -yslice n write a fab slice at y = n (n at the finest level)." << '\n';
cout << " -zslice n write a fab slice at z = n (n at the finest level)." << '\n';
cout << " -sliceallvars write all fab variables instead of just initialderived." << '\n';
cout << " -boxslice _box_ write a fab on the box (box at the finest level)." << '\n';
cout << " -xslice n write a fab slice at x = n (n at the finest level)." << '\n';
cout << " -yslice n write a fab slice at y = n (n at the finest level)." << '\n';
cout << " -zslice n write a fab slice at z = n (n at the finest level)." << '\n';
cout << " -sliceallvars write all fab variables instead of just initialderived." << '\n';
cout << " -boxslice _box_ write a fab on the box (box at the finest level)." << '\n';
cout << " _box_ format: lox loy (loz) hix hiy (hiz)." << '\n';
cout << " example: -boxslice 0 0 0 120 42 200." << '\n';
#ifdef BL_VOLUMERENDER
Expand Down Expand Up @@ -710,15 +719,15 @@ void AVGlobals::ParseCommandLine(int argc, char *argv[]) {
++i;
# if (BL_SPACEDIM != 3)
} else if(strcmp(argv[i],"-a") == 0) {
bAnimation = true;
bAnimation = true;
bAnnotated = false;
bCacheAnimFrames = true;
} else if(strcmp(argv[i],"-aa") == 0) {
bAnimation = true;
bAnimation = true;
bAnnotated = true;
bCacheAnimFrames = true;
} else if(strcmp(argv[i],"-anc") == 0) {
bAnimation = true;
bAnimation = true;
bCacheAnimFrames = false;
bAnnotated = false;
# endif
Expand Down Expand Up @@ -1071,7 +1080,7 @@ void AVGlobals::ParseCommandLine(int argc, char *argv[]) {
comlinebox.setBig(Amrvis::XDIR, atoi(clbx));
comlinebox.setBig(Amrvis::YDIR, atoi(clby));
#else
if(atoi(clsx) > atoi(clbx) || atoi(clsy) > atoi(clby) ||
if(atoi(clsx) > atoi(clbx) || atoi(clsy) > atoi(clby) ||
atoi(clsz) > atoi(clbz))
{
if(ParallelDescriptor::IOProcessor()) {
Expand Down

0 comments on commit dafe7cb

Please sign in to comment.