R语言hdf5依赖h5 packge手动安装

服务器有网络限制,必须用离线方式去安装

HDF指一种为存储和处理大容量科学数据设计的文件格式及相应库文件。HDF最早由NCSA开发,在气象数据,高频数据存储方面应用较多。当前流行的版本是HDF5。 HDF5文件数据结构包括Datagroup和DataSet。 DataGroup:类似文件夹,可以包含多个数据集或下级群组。DataSet:类似字典,存储内容。

有什么包

R有些包可以处理hdf5,有的已经从cran仓库移除了。rhdf5可以在线安装。离线安装最后选择cran仓库的h5 package

Packages on CRAN and Bioconductor supporting the HDF5 fileformat.

Package Repository First Release Status

h5r CRAN 2011-10-23 Archived

ncdf4 CRAN 2010-02-24 Active

rgdal CRAN 2003-11-24 Active

hdf5(即h5) CRAN 2000-02-02 Archived

rhdf5 BioC > 10.5 Years Active

https://cran.r-project.org/web/packages/h5/vignettes/h5-Intro.html

手动安装

从cran下载包手动安装,https://cran.r-project.org/web/packages/h5/index.html

依赖Rcpp和libhdf5(≥1.8.12)

1.手动安装 Rcpp https://cran.r-project.org/web/packages/Rcpp/index.html

  • install.pakages("Rcpp.tar.gz",repos=NULL)

或者直接用命令行装 R CMD INSTALL Rcpp.tar.gz

2.安装libhdf5

For CentOS

yum -y install hdf5-devel

The current version is (which will get installed) 1.8.12


For Ubuntu:

sudo apt-get install libhdf5-dev

查看版本 h5cc -showconfig

 

3.手动安装h5

遇到问题,libhdf5镜像安装的版本比较老,是1.8.5,所以选择比较早的h5版本安装,试下来h5_0.9.1是可以的

下载h5的tar包 https://cran.r-project.org/src/contrib/Archive/h5/

R CMD INSTALL h5_0.9.1.tar.gz —enable-cxx=yes

 

用法

网上资料已经没有了,h5_0.9.1和在线文档用法有差异,用R命令查看文档

?h5close

看到H5File创建和dataset的赋值方式与新版本相比略有差异。

library(h5)

myfile <- H5File('test.h5','a') //创建新文件

a <- matrix(rnom(16),nrow=4,ncol=4)

myfile['data','a'] <- a    //赋给‘data’ group, ‘a’ dataset

read_a <- readDataSet(myfile['data','a'])

h5close(myfile)

注意,dataset接受的类型有vector, array, matrix,存储charactor类型,数据量过大时会遇到CreateDataset paramter size not defined的错误,最好存储数值型,数值型存千万数据没有问题。

 

 

include(FetchContent) include(ExternalProject) cmake_minimum_required(VERSION 3.16.0) project(SWMM5Plus VERSION 1.0.2) enable_language (Fortran) find_package (Python3 COMPONENTS Interpreter) set(testing_available ON) set(CPACK_SET_DESTDIR ON) function(check_python_dependencies module) message(STATUS "Looking for Python module '${module}'") execute_process(COMMAND pip show ${module} OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE EXIT_CODE_PIPSHOW ) if (NOT ${EXIT_CODE_PIPSHOW} EQUAL 0) set(testing_available OFF PARENT_SCOPE) message(WARNING "\nMissing Python module '${module}'\n**Testing unavailable**\nPlease run python_dependencies.sh\n") else() message(STATUS "'${module}' found") endif() endfunction() if (NOT (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" OR CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")) message(FATAL_ERROR "Intel Fortran compiler not found. Found ${CMAKE_Fortran_COMPILER_ID} instead. This project supports Intel Fortran (ifort) and IntelLLVM (ifx).") else() message(STATUS "Detected Intel Fortran compiler: ${CMAKE_Fortran_COMPILER_ID}") endif() function(commentout IN_FILE line_num) file (STRINGS ${IN_FILE} LINES) file(WRITE ${IN_FILE} "") set(line_counter 1) foreach(LINE IN LISTS LINES) if (${line_counter} STREQUAL line_num) string(PREPEND LINE "//") endif() MATH(EXPR line_counter "${line_counter}+1") file(APPEND ${IN_FILE} "${LINE}\n") endforeach() endfunction() get_filename_component(build_configuration ${CMAKE_BINARY_DIR} NAME) if (build_configuration STREQUAL "build") set(default_build_type "Release") message(STATUS "Building inside '${build_configuration}' named folder, setting configuration as '${default_build_type}'") elseif (build_configuration STREQUAL "dwflow") set(default_build_type "Release") message(STATUS "Building inside '${build_configuration}' named folder, setting configuration as '${default_build_type}'") message(WARNING "Lines [249-252] will be commented out from 'interface/src/dwflow.c'") elseif(build_configuration STREQUAL "debug") set(default_build_type "Debug") message(STATUS "Building inside '${build_configuration}' named folder, setting configuration as '${default_build_type}'") set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g -traceback -debug extended") endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -lm -lpthread -shared -fcommon") #set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -coarray=distributed -ldl") set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -coarray=shared -fPIC -traceback") set(FETCHCONTENT_QUIET OFF) set(BUILD_COARRAY_NUM_IMAGES 1 CACHE STRING "Set up the number of processors to use for parallel SWMM5+.") set(BUILD_HDF5 "C:/Users/Admin/gw20250625/SWMM5plus-v-1.0.2/build/_deps/hdf5-src") set(hdf5_SOURCE_DIR "C:/Users/Admin/gw20250625/SWMM5plus-v-1.0.2/build/_deps/hdf5-src") set(HDF5_INCLUDE_DIR "C:/Users/Admin/gw20250625/SWMM5plus-v-1.0.2/build/_deps/hdf5-src/include") set(HDF5_LIB_DIR "C:/Users/Admin/gw20250625/SWMM5plus-v-1.0.2/build/_deps/hdf5-src/lib") set(json_fortran_SOURCE_DIR "C:/Users/Admin/gw20250625/SWMM5plus-v-1.0.2/build/json-fortran-src") if (DEFINED ENV{HDF5_DIR}) set(BUILD_HDF5 $ENV{HDF5_DIR}) endif() FetchContent_Declare( epaswmm5 URL https://github.com/USEPA/Stormwater-Management-Model/archive/v5.1.13.tar.gz ) FetchContent_Declare( json_fortran GIT_REPOSITORY https://github.com/jacobwilliams/json-fortran.git GIT_TAG 3ab8f98209871875325c6985dd0e50085d1c82c2 #Release 8.3.0 GIT_PROGRESS ON ) FetchContent_Declare( hdf5 GIT_REPOSITORY https://github.com/HDFGroup/hdf5.git GIT_TAG 3e847e003632bdd5fdc189ccbffe25ad2661e16f #Release 1.12.2 GIT_PROGRESS ON ) Fetchcontent_MakeAvailable(epaswmm5) FetchContent_GetProperties(json_fortran hdf5) if(NOT json_fortran_POPULATED) FetchContent_Populate(json_fortran) endif() FetchContent_Populate(hdf5) ExternalProject_Add(hdf5 SOURCE_DIR "C:/Users/Admin/gw20250625/SWMM5plus-v-1.0.2/build/_deps/hdf5-src" CONFIGURE_COMMAND FC=ifort ${hdf5_SOURCE_DIR}/configure --enable-fortran --without-zlib BINARY_DIR ${hdf5_BINARY_DIR} BUILD_COMMAND ${MAKE} COMMAND make install) set(HDF5_LIB_DIR ${hdf5_BINARY_DIR}/hdf5/lib/) set(HDF5_INCLUDE_DIR ${hdf5_BINARY_DIR}/hdf5/include/) set(HDF5_LIBRARIES ${hdf5_BINARY_DIR}/hdf5/lib/libhdf5hl_fortran.a ${hdf5_BINARY_DIR}/hdf5/lib/libhdf5_hl.a ${hdf5_BINARY_DIR}/hdf5/lib/libhdf5_fortran.a ${hdf5_BINARY_DIR}/hdf5/lib/libhdf5.a) set(BUILD_HDF5 ${hdf5_BINARY_DIR}) set(HDF5_FOUND ON) #Following sh script file(COPY ${epaswmm5_SOURCE_DIR}/src/ DESTINATION ${CMAKE_SOURCE_DIR}/interface/src) file(COPY ${CMAKE_SOURCE_DIR}/interface/api.h DESTINATION ${CMAKE_SOURCE_DIR}/interface/src) file(COPY ${CMAKE_SOURCE_DIR}/interface/api.c DESTINATION ${CMAKE_SOURCE_DIR}/interface/src) file(COPY ${CMAKE_SOURCE_DIR}/interface/api_error.h DESTINATION ${CMAKE_SOURCE_DIR}/interface/src) file(COPY ${CMAKE_SOURCE_DIR}/interface/api_error.c DESTINATION ${CMAKE_SOURCE_DIR}/interface/src) file(READ ${CMAKE_SOURCE_DIR}/interface/add_to_controls.c CONTROLS) file(READ ${CMAKE_SOURCE_DIR}/interface/add_to_funcs.h FUNCS) file(APPEND ${CMAKE_SOURCE_DIR}/interface/src/controls.c "${CONTROLS}") file(APPEND ${CMAKE_SOURCE_DIR}/interface/src/funcs.h "${FUNCS}") message(STATUS "Appended to controls.c and funcs.h") file(READ ${CMAKE_SOURCE_DIR}/interface/add_to_lid.c LIDC) file(READ ${CMAKE_SOURCE_DIR}/interface/add_to_lid.h LIDH) file(APPEND ${CMAKE_SOURCE_DIR}/interface/src/lid.c "${LIDC}") file(APPEND ${CMAKE_SOURCE_DIR}/interface/src/lid.h "${LIDH}") message(STATUS "Appended to lid.c and lid.h") if (build_configuration STREQUAL "dwflow") commentout(${CMAKE_SOURCE_DIR}/interface/src/dwflow.c 248) commentout(${CMAKE_SOURCE_DIR}/interface/src/dwflow.c 249) commentout(${CMAKE_SOURCE_DIR}/interface/src/dwflow.c 250) commentout(${CMAKE_SOURCE_DIR}/interface/src/dwflow.c 251) commentout(${CMAKE_SOURCE_DIR}/interface/src/dwflow.c 252) message(STATUS "Commented out lines [248-252] from 'interface/src/dwflow.c'") endif() file(GLOB SWMM_SOURCES ${CMAKE_SOURCE_DIR}/interface/src/*.c ${CMAKE_SOURCE_DIR}/interface/src/*.h ) file(GLOB SWMM5X_SOURCES ${json_fortran_SOURCE_DIR}/src/json_kinds.F90 ${json_fortran_SOURCE_DIR}/src/json_parameters.F90 ${json_fortran_SOURCE_DIR}/src/json_string_utilities.F90 ${json_fortran_SOURCE_DIR}/src/json_value_module.F90 ${json_fortran_SOURCE_DIR}/src/json_file_module.F90 ${json_fortran_SOURCE_DIR}/src/json_module.F90 ${CMAKE_SOURCE_DIR}/utility/*.f90 ${CMAKE_SOURCE_DIR}/special_elements/*.f90 ${CMAKE_SOURCE_DIR}/definitions/*.f90 ${CMAKE_SOURCE_DIR}/interface/c_library.f90 ${CMAKE_SOURCE_DIR}/interface/interface.f90 ${CMAKE_SOURCE_DIR}/initialization/*.f90 ${CMAKE_SOURCE_DIR}/geometry/*.f90 ${CMAKE_SOURCE_DIR}/timeloop/*.f90 ${CMAKE_SOURCE_DIR}/output/*.f90 ${CMAKE_SOURCE_DIR}/finalization/*.f90 ${CMAKE_SOURCE_DIR}/main/*.f90 ) #Targets #add_library(swmm5 SHARED # ${SWMM_SOURCES} #) set_target_properties(swmm5 PROPERTIES LINKER_LANGUAGE C CXX_STANDARD 14) add_executable(SWMM5p ${SWMM5X_SOURCES} ) target_include_directories(SWMM5p PUBLIC ${HDF5_INCLUDE_DIR} ) target_link_directories(SWMM5p PUBLIC ${HDF5_LIB_DIR} ) target_link_libraries(SWMM5p PUBLIC ${HDF5_LIBRARIES} ) add_dependencies(SWMM5p hdf5) #Testing check_python_dependencies(tornado) check_python_dependencies(tabulate) check_python_dependencies(h5py) check_python_dependencies(swmmtoolbox) # Tests defined in separate file: ctest/CMakeLists.txt if (testing_available) enable_testing() message(STATUS "Making tests available") add_subdirectory(ctest) endif() #INSTALLATION install(TARGETS SWMM5p DESTINATION bin) install(TARGETS swmm5 DESTINATION lib) #cpack set(CPACK_PACKAGE_CONTACT "NCIMM") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "NCIMM") set(CPACK_DEBIAN_PACKAGE_DEPENDS "intel-hpckit") include(CPack) 以上是我配置swmm5+的CMakeLists.txt,这样配置后,HDF5配置不成功,不能生成 HDF5.mod 文件
06-27
(base) C:\Users\HS>cd C:\Users\HS\Desktop\raw转hdf5 (base) C:\Users\HS\Desktop\raw转hdf5>pip install . Processing c:\users\hs\desktop\raw转hdf5 Preparing metadata (setup.py) ... done Building wheels for collected packages: hdf5maker DEPRECATION: Building 'hdf5maker' using the legacy setup.py bdist_wheel mechanism, which will be removed in a future version. pip 25.3 will enforce this behaviour change. A possible replacement is to use the standardized build interface by setting the `--use-pep517` option, (possibly combined with `--no-build-isolation`), or adding a `pyproject.toml` file to the source tree of 'hdf5maker'. Discussion can be found at https://github.com/pypa/pip/issues/6334 Building wheel for hdf5maker (setup.py) ... error error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [43 lines of output] C:\Users\HS\Desktop\raw转hdf5\hdf5maker\version.py:8: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81. import pkg_resources D:\anaconda3\Lib\site-packages\setuptools\dist.py:759: SetuptoolsDeprecationWarning: License classifiers are deprecated. !! ******************************************************************************** Please consider removing the following classifiers in favor of a SPDX license expression: License :: OSI Approved :: GPL License See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details. ******************************************************************************** !! self._finalize_license_expression() running bdist_wheel running build running build_py creating build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\cmd_line.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\compare_speed.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\convert_file_mpi.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\formatting.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\hdf5_file.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\io.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\make_mask.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\plots.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\raw_data_file.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\raw_file_reader.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\raw_master_file.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\read_quad.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\single_m3_read.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\timed_read.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\tools.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\version.py -> build\lib.win-amd64-cpython-313\hdf5maker copying hdf5maker\__init__.py -> build\lib.win-amd64-cpython-313\hdf5maker running build_ext building '_hdf5maker' extension creating build\temp.win-amd64-cpython-313\Release\src "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -ID:\anaconda3\Lib\site-packages\numpy\_core\include -ID:\anaconda3\include -ID:\anaconda3\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.26100.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.26100.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.26100.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.26100.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.26100.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /Tcsrc/hdf5maker.c /Fobuild\temp.win-amd64-cpython-313\Release\src\hdf5maker.obj hdf5maker.c src/hdf5maker.c(9): fatal error C1083: 无法打开包括文件: “unistd.h”: No such file or directory error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.44.35207\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for hdf5maker Running setup.py clean for hdf5maker Failed to build hdf5maker error: failed-wheel-build-for-install × Failed to build installable wheels for some pyproject.toml based projects出现此报错应该怎么办
最新发布
08-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值