Skip to content

Commit

Permalink
Merge pull request #235 from bees4ever/hymod-unix-no-file
Browse files Browse the repository at this point in the history
work around to not use the __file__ constant
  • Loading branch information
thouska authored Oct 2, 2019
2 parents 86c528f + 9dd5858 commit 34d1ad3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
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

0 comments on commit 34d1ad3

Please sign in to comment.