Skip to content

Commit

Permalink
config.nml paths can replace @GEMINI_SIMROOT@ with env var path
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Mar 16, 2021
1 parent b4379a5 commit f0d71af
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
14 changes: 14 additions & 0 deletions +gemini3d/+fileio/expand_simroot.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function p = expand_simroot(p)

key = "@GEMINI_SIMROOT@";

if startsWith(p, key)
r = getenv(extractBetween(key, 2, strlength(key)-1));
if isempty(r)
error("gemini3d:fileio:read_nml", p + " refers to undefined environment variable GEMINI_SIMROOT. Set it to location to store/load Gemini3D simulations.")
end

p = fullfile(r, extractAfter(p, key));
end

end
6 changes: 5 additions & 1 deletion +gemini3d/+fileio/make_valid_paths.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
function folder = make_valid_folder(folder, top)
import gemini3d.fileio.*

folder = gemini3d.fileio.expand_simroot(folder);

folder = expanduser(folder);
% in case absolute path was specified

if ~isfolder(folder) && ~is_absolute_path(folder)
if ~isfolder(folder) && ~is_absolute_path(folder)
folder = fullfile(top, folder);
end

Expand All @@ -57,6 +59,8 @@

function filename = make_valid_filename(filename, top)

filename = gemini3d.fileio.expand_simroot(filename);

filename = gemini3d.fileio.expanduser(filename);
% in case absolute path was specified

Expand Down
15 changes: 15 additions & 0 deletions +gemini3d/+tests/TestAUnit.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ function test_path_tail(tc)
end
end

function test_nml_gemini_simroot(tc)
old = getenv("GEMINI_SIMROOT");

setenv("GEMINI_SIMROOT", "abc123")

out = gemini3d.fileio.expand_simroot("@GEMINI_SIMROOT@/foo");

setenv("GEMINI_SIMROOT", old)

tc.verifyEqual(out, fullfile("abc123", "foo"))


end


function test_grid1d(tc)

x = gemini3d.grid.grid1d(100., 5);
Expand Down

0 comments on commit f0d71af

Please sign in to comment.