Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

work around to not use the __file__ constant #235

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions spotpy/examples/hymod_unix/hymod_cython/hymod.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def excess(x_loss,cmax,bexp,Pval,PETval):
return ER1,ER2,xn


cdef public void hymod_run():
cdef public void hymod_run(owd):
if not hasattr(sys, 'argv'):
sys.argv = ['']
if len(sys.argv) != 6:
Expand All @@ -102,7 +102,9 @@ cdef public void hymod_run():
x = sys.argv
x.pop(0)

owd = os.path.dirname(os.path.realpath(__file__))
# try to use path provided from cpp
# owd = os.path.dirname(os.path.realpath(__file__))

hymod_path = owd + os.sep + 'hymod_input.csv'
Precip, PET = [], []

Expand Down
16 changes: 15 additions & 1 deletion spotpy/examples/hymod_unix/hymod_cython/main_hymod.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>
#include "Python.h"
#include "hymod.h"
#include <unistd.h>

int main(int argc, char *argv[])
{
Expand All @@ -27,9 +28,22 @@ int main(int argc, char *argv[])
Py_Finalize();
return -1; //error
}

/*const std::filesystem::path owd;
std::filesystem::current_path(&owd);

hymod_run();
getcwd(cwd, sizeof(cwd))*/

char cwd[256];
if (getcwd(cwd, sizeof(cwd)) == NULL)
{
std::cout << "Error in getcwd" << std::endl;
Py_Finalize();
return -2; //error
}

PyObject *py_cwd = Py_BuildValue("s", cwd);
hymod_run(py_cwd);

Py_Finalize(); //Needed!

Expand Down