Skip to content

Commit

Permalink
Adds windows build, heclib log redirect
Browse files Browse the repository at this point in the history
Support to build pyheclib in windows requires
MS Visual C++ 14 build tools & intel fotran compiler
in version 6 dss files outputs log message even after
setting log level to 0. To avoid this Output redirecton
is added to suppress log messages from heclib.
  • Loading branch information
nzahasan committed Sep 17, 2020
1 parent ef3daec commit e6c9085
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#[ignore build dirs files]
#[ignore build dirs & binary files]
build
pyheclib.*.so
pyheclib.*.pyd

#[ignore editor specific]
.vscode
Expand Down
14 changes: 12 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,25 @@

libraries_list = ['gcc','m','dl','gfortran']

if sys.platform.lower()=='windows':
elif sys.platform.lower().startswith('win'):

# requires:
# * Intel fortran compiler
# * Microsoft visual c++ 14 build tools

print("*** Platform *** WINDOWS ***")



extra_objects_list = [
os.path.join(root,'heclib\windows\Release64\heclib_c_v6v7.lib'),
os.path.join(root,'heclib\windows\Release64\heclib_f_v6v7.lib')
]

library_dirs_list =[
# intel fortran compiler library location
'C:\\Program Files (x86)\\IntelSWTools\\compilers_and_libraries_2020\\windows\\compiler\\lib\\intel64_win'
]



extension = [
Expand Down
30 changes: 22 additions & 8 deletions src/pyheclib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'''


import os, sys
import numpy as np
cimport numpy as np
from pandas import DataFrame
Expand Down Expand Up @@ -69,6 +70,21 @@ cpdef enum granularity:




'''
Dss version 6 outputs log messages
even after explicitly setting message level
source: https://stackoverflow.com/questions/5081657/
'''

sys.stdout.flush()
newstdout = os.dup(1)
devnull = os.open(os.devnull, os.O_WRONLY)
os.dup2(devnull, 1)
os.close(devnull)
sys.stdout = os.fdopen(newstdout, 'w')


# log file
# zl_status = zopenLog(bytes("/dev/null",encoding="ascii"));

Expand All @@ -79,8 +95,6 @@ cdef int rec_data_type(np.ndarray[long long, mode="c"] ifltab,char* pathname):





''' ** healper funcions ** '''


Expand Down Expand Up @@ -125,8 +139,8 @@ cdef int check_path(str full_path) except? -99:


''' ** controlling message level ** '''

zset(str2b("mess"),str2b("general"),0)
# in windows this function oddly outputs a newline
# zset(str2b("mess"),str2b("general"),0)


''' ** wrapper for hec-dss C functions ** '''
Expand Down Expand Up @@ -194,7 +208,7 @@ cdef zStructTimeSeries* gen_double_iregts_struct(char* pathname,

cdef zStructCatalog* dss_catalog(np.ndarray[long long, mode="c"] ifltab,
char* search_path) except? NULL:
print(search_path)
# print(search_path)
cdef:
zStructCatalog* catalog_ptr = zstructCatalogNew()
int status = zcatalog(&ifltab[0],search_path,catalog_ptr,1)
Expand Down Expand Up @@ -281,12 +295,12 @@ cdef int read_gridded(np.ndarray[long long, mode="c"] ifltab, char * rec_path_na
int status = 0


print(gird_ptr.pathname )
# print(gird_ptr.pathname )

status = zspatialGridRetrieve(&ifltab[0], gird_ptr, 1)

if status != STATUS_OKAY:
print("failed")
# if status != STATUS_OKAY:
# print("failed")


return status
Expand Down

0 comments on commit e6c9085

Please sign in to comment.