diff --git a/CMakeInstallation.cmake b/CMakeInstallation.cmake index 7404287b9e..a99bebdd92 100644 --- a/CMakeInstallation.cmake +++ b/CMakeInstallation.cmake @@ -148,53 +148,8 @@ if (HDF4_PACK_EXAMPLES) COMPONENT hdfdocuments ) - option (EXAMPLES_DOWNLOAD "Download to use released examples files" OFF) - if (EXAMPLES_DOWNLOAD) - option (EXAMPLES_USE_RELEASE_NAME "Use the released examples artifact name" OFF) - if (EXAMPLES_USE_RELEASE_NAME) - set (EXAMPLES_NAME ${EXAMPLES_TGZ_ORIGNAME}) - else () - set (EXAMPLES_NAME ${HDF4_EXAMPLES_COMPRESSED}) - endif () - if (NOT EXAMPLES_USE_LOCALCONTENT) - set (EXAMPLES_URL ${EXAMPLES_TGZ_ORIGPATH}/${EXAMPLES_NAME}) - file (DOWNLOAD ${EXAMPLES_URL} ${HDF4_BINARY_DIR}/${HDF4_EXAMPLES_COMPRESSED} STATUS EX_DL) - message (STATUS "Examples file is ${EXAMPLES_URL} STATUS=${EX_DL}") - else () - set (EXAMPLES_URL ${TGZPATH}/${EXAMPLES_NAME}) - file (COPY_FILE ${EXAMPLES_URL} ${HDF4_BINARY_DIR}/${HDF4_EXAMPLES_COMPRESSED} RESULT EX_DL) - message (STATUS "Examples file is ${EXAMPLES_URL} RESULT=${EX_DL}") - endif () - if (EXISTS "${HDF4_BINARY_DIR}/${HDF4_EXAMPLES_COMPRESSED}") - execute_process( - COMMAND ${CMAKE_COMMAND} -E tar xzf ${HDF4_EXAMPLES_COMPRESSED} - WORKING_DIRECTORY ${HDF4_BINARY_DIR} - COMMAND_ECHO STDOUT - ) - endif () - else () - if (EXISTS "${HDF4_EXAMPLES_COMPRESSED_DIR}/${HDF4_EXAMPLES_COMPRESSED}") - execute_process( - COMMAND ${CMAKE_COMMAND} -E tar xzf ${HDF4_EXAMPLES_COMPRESSED_DIR}/${HDF4_EXAMPLES_COMPRESSED} - WORKING_DIRECTORY ${HDF4_BINARY_DIR} - COMMAND_ECHO STDOUT - ) - endif () - endif () - get_filename_component (EX_LAST_EXT ${HDF4_EXAMPLES_COMPRESSED} LAST_EXT) - if (${EX_LAST_EXT} STREQUAL ".zip") - get_filename_component (EX_DIR_NAME ${HDF4_EXAMPLES_COMPRESSED} NAME_WLE) - else () - get_filename_component (EX_DIR_NAME ${HDF4_EXAMPLES_COMPRESSED} NAME_WLE) - get_filename_component (EX_DIR_NAME ${EX_DIR_NAME} NAME_WLE) - endif () - execute_process( - COMMAND ${CMAKE_COMMAND} -E rename ${EX_DIR_NAME} HDF4Examples - WORKING_DIRECTORY ${HDF4_BINARY_DIR} - COMMAND_ECHO STDOUT - ) install ( - DIRECTORY ${HDF4_BINARY_DIR}/HDF4Examples + DIRECTORY ${HDF4_SOURCE_DIR}/HDF4Examples DESTINATION ${HDF4_INSTALL_DATA_DIR} USE_SOURCE_PERMISSIONS COMPONENT hdfdocuments diff --git a/CMakeLists.txt b/CMakeLists.txt index 4250dca9b1..01b8608d07 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,6 +263,13 @@ set (HDF4_PACKAGE_BUGREPORT "help@hdfgroup.org") set (HDF4_PACKAGE_SOVERSION "${H4_VERS_MAJOR}.${H4_VERS_RELEASE}.${H4_VERS_MINOR}") set (HDF4_PACKAGE_SOVERSION_MAJOR "${H4_VERS_MAJOR}") +#----------------------------------------------------------------------------- +# Set variables needed for installation +#----------------------------------------------------------------------------- +set (HDF4_VERSION_STRING ${HDF4_PACKAGE_VERSION}) +set (HDF4_VERSION_MAJOR ${HDF4_PACKAGE_VERSION_MAJOR}) +set (HDF4_VERSION_MINOR ${HDF4_PACKAGE_VERSION_MINOR}) + #----------------------------------------------------------------------------- # Include some macros for reusable code #----------------------------------------------------------------------------- @@ -447,7 +454,7 @@ if (MSVC) endif () include (${HDF_RESOURCES_DIR}/HDFCompilerFlags.cmake) -set (CMAKE_MODULE_PATH ${HDF_RESOURCES_DIR} ${HDF_RESOURCES_DIR} ${CMAKE_MODULE_PATH}) +set (CMAKE_MODULE_PATH ${HDF_RESOURCES_DIR} ${CMAKE_MODULE_PATH}) #----------------------------------------------------------------------------- # Include user macros @@ -601,26 +608,6 @@ endif () add_subdirectory (hdf) add_subdirectory (mfhdf) -#----------------------------------------------------------------------------- -# Option to build HDF4 Examples -#----------------------------------------------------------------------------- -if (EXISTS "${HDF4_SOURCE_DIR}/mfhdf/examples" AND IS_DIRECTORY "${HDF4_SOURCE_DIR}/mfhdf/examples") - option (HDF4_BUILD_EXAMPLES "Build HDF4 Examples" OFF) - if (HDF4_BUILD_EXAMPLES) - if (HDF4_BUILD_FORTRAN) - if (EXISTS "${HDF4_SOURCE_DIR}/hdf/fortran/examples" AND IS_DIRECTORY "${HDF4_SOURCE_DIR}/hdf/fortran/examples") - add_subdirectory (hdf/fortran/examples) - endif () - if (EXISTS "${HDF4_SOURCE_DIR}/mfhdf/fortran/examples" AND IS_DIRECTORY "${HDF4_SOURCE_DIR}/mfhdf/fortran/examples") - add_subdirectory (mfhdf/fortran/examples) - endif () - endif () - - add_subdirectory (hdf/examples) - add_subdirectory (mfhdf/examples) - endif () -endif () - #----------------------------------------------------------------------------- # Option to build HDF4 Java Library #----------------------------------------------------------------------------- @@ -631,6 +618,18 @@ if (EXISTS "${HDF4_SOURCE_DIR}/java" AND IS_DIRECTORY "${HDF4_SOURCE_DIR}/java") endif () endif () +#----------------------------------------------------------------------------- +# Option to build HDF4 Examples +#----------------------------------------------------------------------------- +if (EXISTS "${HDF4_SOURCE_DIR}/HDF4Examples" AND IS_DIRECTORY "${HDF4_SOURCE_DIR}/HDF4Examples") + option (HDF4_BUILD_EXAMPLES "Build HDF4 Library Examples" ON) + if (HDF4_BUILD_EXAMPLES) + include (${HDF_RESOURCES_DIR}/HDF4ExampleCache.cmake) + set (HDF4_VERSION ${HDF4_PACKAGE_VERSION}) + add_subdirectory (HDF4Examples) + endif () +endif () + #----------------------------------------------------------------------------- # Generate the H4config.h file containing user settings needed by compilation #----------------------------------------------------------------------------- diff --git a/HDF4Examples/CMakeLists.txt b/HDF4Examples/CMakeLists.txt new file mode 100644 index 0000000000..2b3c0923ed --- /dev/null +++ b/HDF4Examples/CMakeLists.txt @@ -0,0 +1,102 @@ +cmake_minimum_required (VERSION 3.12) +project (H4EXAMPLES C) + +#----------------------------------------------------------------------------- +# Define some CMake variables for use later in the project +#----------------------------------------------------------------------------- +set (HDF4EX_HDFSRC_DIR ${H4EXAMPLES_SOURCE_DIR}/hdf) +set (HDF4EX_HDF_FORTRAN_DIR ${H4EXAMPLES_SOURCE_DIR}/hdf/fortran) +set (HDF4EX_MFHDFSRC_DIR ${H4EXAMPLES_SOURCE_DIR}/mfhdf) +set (HDF4EX_MFHDF_FORTRAN_DIR ${H4EXAMPLES_SOURCE_DIR}/mfhdf/fortran) +set (HDF4EX_JAVA_DIR ${H4EXAMPLES_SOURCE_DIR}/JAVA) +set (HDF4EX_RESOURCES_DIR ${H4EXAMPLES_SOURCE_DIR}/config/cmake) + +#----------------------------------------------------------------------------- +# Basic HDF4Examples stuff here +#----------------------------------------------------------------------------- +include (${HDF4EX_RESOURCES_DIR}/HDFMacros.cmake) +include (${HDF4EX_RESOURCES_DIR}/HDFExampleMacros.cmake) +set (CMAKE_JAVA_INCLUDE_PATH "") + +SET_HDF_BUILD_TYPE() + +BASIC_SETTINGS (EXAMPLES) + +#----------------------------------------------------------------------------- +# HDF4 support +#----------------------------------------------------------------------------- +HDF4_SUPPORT (TRUE) +message (STATUS "HDF4 link libs: ${H4EX_HDF4_LINK_LIBS}") + +if (WIN32) + set(CMAKE_TEST_LIB_DIRECTORY "${HDF4_TOOLS_DIR}") +else () + set(CMAKE_TEST_LIB_DIRECTORY "${HDF4_LIBRARY_PATH}") +endif () + +#----------------------------------------------------------------------------- +# All examples need the main include directories +#----------------------------------------------------------------------------- +INCLUDE_DIRECTORIES (${H4EX_HDF4_INCLUDE_DIRS}) + +#----------------------------------------------------------------------------- +# Dashboard and Testing Settings +#----------------------------------------------------------------------------- +option (H4EX_BUILD_TESTING "Build HDF4 Example Testing" OFF) +if (H4EX_BUILD_TESTING) + set (DART_TESTING_TIMEOUT 1200 CACHE STRING + "Timeout in seconds for each test (default 1200=20minutes)" + ) + enable_testing () + include (CTest) + include (${PROJECT_SOURCE_DIR}/CTestConfig.cmake) + configure_file (${HDF4EX_RESOURCES_DIR}/CTestCustom.cmake ${PROJECT_BINARY_DIR}/CTestCustom.ctest @ONLY) +endif () + +#----------------------------------------------------------------------------- +# Option to build Fortran examples +# Make sure this appears before the CONFIGURE_FILE step +# so that fortran name mangling is detected before writing H4config.h +#----------------------------------------------------------------------------- +# Set default name mangling : overridden by Fortran detection in fortran dir +set (H4_F77_FUNC "H4_F77_FUNC(name,NAME) name ## _") +set (H4_F77_FUNC_ "H4_F77_FUNC_(name,NAME) name ## __") +if (EXISTS "${H4EXAMPLES_SOURCE_DIR}/mfhdf/fortran" AND IS_DIRECTORY "${H4EXAMPLES_SOURCE_DIR}/mfhdf/fortran") + option (HDF_BUILD_FORTRAN "Build FORTRAN support" OFF) + if (HDF_BUILD_FORTRAN AND HDF4_BUILD_FORTRAN) + set (H4EX_LINK_Fortran_LIBS ${H4EX_HDF4_LINK_LIBS}) + + if (WIN32) + set (H4_F77_FUNC "H4_F77_FUNC(name,NAME) NAME") + set (H4_F77_FUNC_ "H4_F77_FUNC_(name,NAME) NAME") + endif () + else () + set (HDF_BUILD_FORTRAN OFF CACHE BOOL "Build examples FORTRAN support" FORCE) + endif () +else () + set (HDF_BUILD_FORTRAN OFF CACHE BOOL "Build examples FORTRAN support" FORCE) +endif () + +#----------------------------------------------------------------------------- +# Option to build JAVA examples +#----------------------------------------------------------------------------- +if (EXISTS "${H4EXAMPLES_SOURCE_DIR}/JAVA" AND IS_DIRECTORY "${H4EXAMPLES_SOURCE_DIR}/JAVA") + option (HDF_BUILD_JAVA "Build JAVA support" OFF) +else () + set (HDF_BUILD_JAVA OFF CACHE BOOL "Build examples JAVA support" FORCE) +endif () + +#----------------------------------------------------------------------------- +# Build examples +#----------------------------------------------------------------------------- +if (HDF_BUILD_C) + add_subdirectory (hdf/examples) + add_subdirectory (mfhdf/examples) +endif () +if (HDF_BUILD_FORTRAN AND HDF4_BUILD_FORTRAN) + add_subdirectory (mfhdf/fortran) + add_subdirectory (hdf/fortran) +endif () +if (HDF_BUILD_JAVA AND HDF4_BUILD_JAVA) + add_subdirectory (JAVA) +endif () diff --git a/HDF4Examples/CMakePresets.json b/HDF4Examples/CMakePresets.json new file mode 100644 index 0000000000..ff07f8eb42 --- /dev/null +++ b/HDF4Examples/CMakePresets.json @@ -0,0 +1,173 @@ +{ + "version": 6, + "include": [ + "config/cmake-presets/hidden-presets.json" + ], + "configurePresets": [ + { + "name": "ci-base-examples", + "hidden": true, + "cacheVariables": { + "CPACK_PACKAGE_VERSION": "3.10.2", + "HDF4_NAMESPACE": {"type": "STRING", "value": "hdf4::"}, + "HDF4_PACKAGE_NAME": {"type": "STRING", "value": "hdf4"}, + "H4EX_BUILD_TESTING": "ON" + } + }, + { + "name": "ci-StdJava", + "hidden": true, + "cacheVariables": { + "HDF_BUILD_JAVA": "ON" + } + }, + { + "name": "ci-StdFortran", + "hidden": true, + "cacheVariables": { + "HDF_BUILD_FORTRAN": "OFF" + } + }, + { + "name": "ci-StdShar", + "hidden": true, + "inherits": ["ci-base", "ci-base-examples"], + "cacheVariables": { + "BUILD_SHARED_LIBS": "ON", + "USE_SHARED_LIBS": "ON" + } + }, + { + "name": "ci-StdShar-MSVC", + "description": "MSVC Standard Config for x64 (Release)", + "inherits": [ + "ci-x64-Release-MSVC", + "ci-StdShar" + ] + }, + { + "name": "ci-StdShar-Clang", + "description": "Clang Standard Config for x64 (Release)", + "inherits": [ + "ci-x64-Release-Clang", + "ci-StdShar" + ] + }, + { + "name": "ci-StdShar-GNUC", + "description": "GNUC Standard Config for x64 (Release)", + "inherits": [ + "ci-x64-Release-GNUC", + "ci-StdShar" + ] + }, + { + "name": "ci-StdShar-Intel", + "description": "Intel Standard Config for x64 (Release)", + "inherits": [ + "ci-x64-Release-Intel", + "ci-StdShar" + ] + } + ], + "buildPresets": [ + { + "name": "ci-StdShar-MSVC", + "description": "MSVC Standard Build for x64 (Release)", + "configurePreset": "ci-StdShar-MSVC", + "inherits": [ + "ci-x64-Release-MSVC" + ] + }, + { + "name": "ci-StdShar-Clang", + "description": "Clang Standard Build for x64 (Release)", + "configurePreset": "ci-StdShar-Clang", + "inherits": [ + "ci-x64-Release-Clang" + ] + }, + { + "name": "ci-StdShar-GNUC", + "description": "GNUC Standard Build for x64 (Release)", + "configurePreset": "ci-StdShar-GNUC", + "verbose": false, + "inherits": [ + "ci-x64-Release-GNUC" + ] + }, + { + "name": "ci-StdShar-Intel", + "description": "Intel Standard Build for x64 (Release)", + "configurePreset": "ci-StdShar-Intel", + "verbose": false, + "inherits": [ + "ci-x64-Release-Intel" + ] + } + ], + "testPresets": [ + { + "name": "ci-StdShar-MSVC", + "configurePreset": "ci-StdShar-MSVC", + "inherits": [ + "ci-x64-Release-MSVC" + ] + }, + { + "name": "ci-StdShar-Clang", + "configurePreset": "ci-StdShar-Clang", + "inherits": [ + "ci-x64-Release-Clang" + ] + }, + { + "name": "ci-StdShar-GNUC", + "configurePreset": "ci-StdShar-GNUC", + "inherits": [ + "ci-x64-Release-GNUC" + ] + }, + { + "name": "ci-StdShar-Intel", + "configurePreset": "ci-StdShar-Intel", + "inherits": [ + "ci-x64-Release-Intel" + ] + } + ], + "workflowPresets": [ + { + "name": "ci-StdShar-MSVC", + "steps": [ + {"type": "configure", "name": "ci-StdShar-MSVC"}, + {"type": "build", "name": "ci-StdShar-MSVC"}, + {"type": "test", "name": "ci-StdShar-MSVC"} + ] + }, + { + "name": "ci-StdShar-Clang", + "steps": [ + {"type": "configure", "name": "ci-StdShar-Clang"}, + {"type": "build", "name": "ci-StdShar-Clang"}, + {"type": "test", "name": "ci-StdShar-Clang"} + ] + }, + { + "name": "ci-StdShar-GNUC", + "steps": [ + {"type": "configure", "name": "ci-StdShar-GNUC"}, + {"type": "build", "name": "ci-StdShar-GNUC"}, + {"type": "test", "name": "ci-StdShar-GNUC"} + ] + }, + { + "name": "ci-StdShar-Intel", + "steps": [ + {"type": "configure", "name": "ci-StdShar-Intel"}, + {"type": "build", "name": "ci-StdShar-Intel"}, + {"type": "test", "name": "ci-StdShar-Intel"} + ] + } + ] +} diff --git a/HDF4Examples/CMakeUserPresets.json b/HDF4Examples/CMakeUserPresets.json new file mode 100644 index 0000000000..94c96121d4 --- /dev/null +++ b/HDF4Examples/CMakeUserPresets.json @@ -0,0 +1,240 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "my-HDF4216", + "hidden": true, + "environment": { + "HDF4_ROOT": "${sourceParentDir}/temp/HDF_Group/HDF/4.2.16", + }, + "cacheVariables": { + "HDF4_ROOT": {"type": "STRING", "value": "${sourceParentDir}/temp/HDF_Group/HDF/4.2.16"}, + "HDF_BUILD_FORTRAN": "ON", + "HDF_BUILD_JAVA": "ON", + "H4EX_BUILD_TESTING": "ON" + } + }, + { + "name": "my-HDF4Dev", + "hidden": true, + "environment": { + "HDF4_ROOT": "${sourceParentDir}/temp/HDF_Group/HDF/4.2.17", + }, + "cacheVariables": { + "HDF4_ROOT": {"type": "STRING", "value": "${sourceParentDir}/temp/HDF_Group/HDF/4.2.17"}, + "HDF_BUILD_FORTRAN": "ON", + "HDF_BUILD_JAVA": "ON", + "H4EX_BUILD_TESTING": "ON" + } + }, + { + "name": "my-StdShar", + "hidden": true, + "inherits": ["ci-base", "ci-base-examples", "ci-StdPlugins"], + "cacheVariables": { + "BUILD_SHARED_LIBS": "ON", + "USE_SHARED_LIBS": "ON" + } + }, + { + "name": "my-StdShar-MSVC", + "description": "MSVC Standard Config for x64 (Release)", + "inherits": [ + "ci-x64-Release-MSVC", + "my-StdShar", + "my-HDF4Dev" + ] + }, + { + "name": "my-StdShar-Clang", + "description": "Clang Standard Config for x64 (Release)", + "inherits": [ + "ci-x64-Release-Clang", + "my-StdShar", + "my-HDF4Dev" + ] + }, + { + "name": "my-StdShar-GNUC", + "description": "GNUC Standard Config for x64 (Release)", + "inherits": [ + "ci-x64-Release-GNUC", + "my-StdShar", + "my-HDF4Dev" + ] + }, + { + "name": "my-4216Shar-MSVC", + "description": "MSVC 4.2.16 Config for x64 (Release)", + "inherits": [ + "ci-x64-Release-MSVC", + "my-StdShar", + "my-HDF4216" + ] + }, + { + "name": "my-4216Shar-Clang", + "description": "Clang 4.2.16 Config for x64 (Release)", + "inherits": [ + "ci-x64-Release-Clang", + "my-StdShar", + "my-HDF4216" + ] + }, + { + "name": "my-4216Shar-GNUC", + "description": "GNUC 4.2.16 Config for x64 (Release)", + "inherits": [ + "ci-x64-Release-GNUC", + "my-StdShar", + "my-HDF4216" + ] + } + ], + "buildPresets": [ + { + "name": "my-StdShar-MSVC", + "description": "MSVC Standard Build for x64 (Release)", + "configurePreset": "my-StdShar-MSVC", + "inherits": [ + "ci-x64-Release-MSVC" + ] + }, + { + "name": "my-StdShar-Clang", + "description": "Clang Standard Build for x64 (Release)", + "configurePreset": "my-StdShar-Clang", + "inherits": [ + "ci-x64-Release-Clang" + ] + }, + { + "name": "my-StdShar-GNUC", + "description": "GNUC Standard Build for x64 (Release)", + "configurePreset": "my-StdShar-GNUC", + "verbose": true, + "inherits": [ + "ci-x64-Release-GNUC" + ] + }, + { + "name": "my-4216Shar-MSVC", + "description": "MSVC 4.2.16 Build for x64 (Release)", + "configurePreset": "my-4216Shar-MSVC", + "inherits": [ + "ci-x64-Release-MSVC" + ] + }, + { + "name": "my-4216Shar-Clang", + "description": "Clang 4.2.16 Build for x64 (Release)", + "configurePreset": "my-4216Shar-Clang", + "inherits": [ + "ci-x64-Release-Clang" + ] + }, + { + "name": "my-4216Shar-GNUC", + "description": "GNUC 4.2.16 Build for x64 (Release)", + "configurePreset": "my-4216Shar-GNUC", + "verbose": true, + "inherits": [ + "ci-x64-Release-GNUC" + ] + } + ], + "testPresets": [ + { + "name": "my-StdShar-MSVC", + "configurePreset": "my-StdShar-MSVC", + "inherits": [ + "ci-x64-Release-MSVC" + ] + }, + { + "name": "my-StdShar-Clang", + "configurePreset": "my-StdShar-Clang", + "inherits": [ + "ci-x64-Release-Clang" + ] + }, + { + "name": "my-StdShar-GNUC", + "configurePreset": "my-StdShar-GNUC", + "inherits": [ + "ci-x64-Release-GNUC" + ] + }, + { + "name": "my-4216Shar-MSVC", + "configurePreset": "my-4216Shar-MSVC", + "inherits": [ + "ci-x64-Release-MSVC" + ] + }, + { + "name": "my-4216Shar-Clang", + "configurePreset": "my-4216Shar-Clang", + "inherits": [ + "ci-x64-Release-Clang" + ] + }, + { + "name": "my-4216Shar-GNUC", + "configurePreset": "my-4216Shar-GNUC", + "inherits": [ + "ci-x64-Release-GNUC" + ] + } + ], + "workflowPresets": [ + { + "name": "my-StdShar-MSVC", + "steps": [ + {"type": "configure", "name": "my-StdShar-MSVC"}, + {"type": "build", "name": "my-StdShar-MSVC"}, + {"type": "test", "name": "my-StdShar-MSVC"} + ] + }, + { + "name": "my-StdShar-Clang", + "steps": [ + {"type": "configure", "name": "my-StdShar-Clang"}, + {"type": "build", "name": "my-StdShar-Clang"}, + {"type": "test", "name": "my-StdShar-Clang"} + ] + }, + { + "name": "my-StdShar-GNUC", + "steps": [ + {"type": "configure", "name": "my-StdShar-GNUC"}, + {"type": "build", "name": "my-StdShar-GNUC"}, + {"type": "test", "name": "my-StdShar-GNUC"} + ] + }, + { + "name": "my-4216Shar-MSVC", + "steps": [ + {"type": "configure", "name": "my-4216Shar-MSVC"}, + {"type": "build", "name": "my-4216Shar-MSVC"}, + {"type": "test", "name": "my-4216Shar-MSVC"} + ] + }, + { + "name": "my-4216Shar-Clang", + "steps": [ + {"type": "configure", "name": "my-4216Shar-Clang"}, + {"type": "build", "name": "my-4216Shar-Clang"}, + {"type": "test", "name": "my-4216Shar-Clang"} + ] + }, + { + "name": "my-4216Shar-GNUC", + "steps": [ + {"type": "configure", "name": "my-4216Shar-GNUC"}, + {"type": "build", "name": "my-4216Shar-GNUC"}, + {"type": "test", "name": "my-4216Shar-GNUC"} + ] + } + ] +} \ No newline at end of file diff --git a/HDF4Examples/COPYING b/HDF4Examples/COPYING new file mode 100644 index 0000000000..ecd09c01fc --- /dev/null +++ b/HDF4Examples/COPYING @@ -0,0 +1,57 @@ + +Copyright Notice and License Terms for +Hierarchical Data Format (HDF) Software Library and Utilities +--------------------------------------------------------------------------- + +Hierarchical Data Format (HDF) Software Library and Utilities +Copyright 2006-2016 by The HDF Group. + +NCSA Hierarchical Data Format (HDF) Software Library and Utilities +Copyright 1988-2006 by the Board of Trustees of the University of Illinois. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted for any purpose (including commercial purposes) +provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions, and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions, and the following disclaimer in the documentation + and/or materials provided with the distribution. + +3. In addition, redistributions of modified forms of the source or binary + code must carry prominent notices stating that the original code was + changed and the date of the change. + +4. All publications or advertising materials mentioning features or use of + this software are asked, but not required, to acknowledge that it was + developed by The HDF Group and by the National Center for Supercomputing + Applications at the University of Illinois at Urbana-Champaign and + credit the contributors. + +5. Neither the name of The HDF Group, the name of the University, nor the + name of any Contributor may be used to endorse or promote products derived + from this software without specific prior written permission from The HDF + Group, the University, or the Contributor, respectively. + +DISCLAIMER: +THIS SOFTWARE IS PROVIDED BY THE HDF GROUP AND THE CONTRIBUTORS "AS IS" +WITH NO WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED. In no event +shall The HDF Group or the Contributors be liable for any damages suffered +by the users arising out of the use of this software, even if advised of +the possibility of such damage. + +--------------------------------------------------------------------------- +--------------------------------------------------------------------------- + +Contributors: National Center for Supercomputing Applications (NCSA) at +the University of Illinois, Fortner Software, Unidata Program Center (netCDF), +The Independent JPEG Group (JPEG), Jean-loup Gailly and Mark Adler (gzip), +and Digital Equipment Corporation (DEC). + +--------------------------------------------------------------------------- + + diff --git a/HDF4Examples/CTestConfig.cmake b/HDF4Examples/CTestConfig.cmake new file mode 100644 index 0000000000..cbd0cc7737 --- /dev/null +++ b/HDF4Examples/CTestConfig.cmake @@ -0,0 +1,35 @@ +## This file should be placed in the root directory of your project. +## Then modify the CMakeLists.txt file in the root directory of your +## project to incorporate the testing dashboard. +## # The following are required to uses Dart and the Cdash dashboard +## ENABLE_TESTING() +## INCLUDE(CTest) +set (CTEST_PROJECT_NAME "HDF4EXAMPLES") +set (CTEST_NIGHTLY_START_TIME "18:00:00 CST") + +set (CTEST_DROP_METHOD "https") +if (CTEST_DROP_SITE_INIT) + set (CTEST_DROP_SITE "${CTEST_DROP_SITE_INIT}") +else () + set (CTEST_DROP_SITE "cdash.hdfgroup.org") +endif () +if (CTEST_DROP_LOCATION_INIT) + set (CTEST_DROP_LOCATION "${CTEST_DROP_LOCATION_INIT}") +else () + set (CTEST_DROP_LOCATION "/submit.php?project=HDF4EXAMPLES") +endif () +set (CTEST_DROP_SITE_CDASH TRUE) + +set(CTEST_LABELS_FOR_SUBPROJECTS HDF MFHDF JAVA) + +set (UPDATE_TYPE git) +set (VALGRIND_COMMAND "/usr/bin/valgrind") +set (VALGRIND_COMMAND_OPTIONS "-v --tool=memcheck --leak-check=full --track-fds=yes --num-callers=50 --show-reachable=yes --track-origins=yes --malloc-fill=0xff --free-fill=0xfe") + +set (CTEST_TEST_TIMEOUT 3600 CACHE STRING + "Maximum time allowed before CTest will kill the test.") +set (DART_TESTING_TIMEOUT 3600 CACHE STRING + "Maximum time allowed before CTest will kill the test." FORCE) + +set (CTEST_SUBMIT_RETRY_DELAY 20 CACHE STRING + "How long to wait between timed-out CTest submissions.") diff --git a/HDF4Examples/JAVA/CMakeLists.txt b/HDF4Examples/JAVA/CMakeLists.txt new file mode 100644 index 0000000000..b4823cb79b --- /dev/null +++ b/HDF4Examples/JAVA/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_JAVA) + +#----------------------------------------------------------------------------- +# Build the hdf examples +#----------------------------------------------------------------------------- +add_subdirectory (exAN) +add_subdirectory (exGR) +add_subdirectory (exVD) +add_subdirectory (exSD) diff --git a/HDF4Examples/JAVA/exAN/CMakeLists.txt b/HDF4Examples/JAVA/exAN/CMakeLists.txt new file mode 100644 index 0000000000..e1284ca4b2 --- /dev/null +++ b/HDF4Examples/JAVA/exAN/CMakeLists.txt @@ -0,0 +1,98 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_JAVA_AN Java) + +set (CMAKE_VERBOSE_MAKEFILE 1) + +set_directory_properties(PROPERTIES + INCLUDE_DIRECTORIES + "${HDFJAVA_LIB_DIR};${JAVA_INCLUDE_PATH};${JAVA_INCLUDE_PATH2}" +) + +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +include (Java_sourcefiles.cmake) + +if (WIN32) + set (CMAKE_JAVA_INCLUDE_FLAG_SEP ";") +else () + set (CMAKE_JAVA_INCLUDE_FLAG_SEP ":") +endif () + +set (CMAKE_JAVA_INCLUDE_PATH "${HDF4_JAVA_INCLUDE_DIRS}") +set (CMD_ARGS "-Dhdf.hdflib.HDFLibrary.loadLibraryName=${H4EX_JAVA_LIBRARY}$<$:${CMAKE_DEBUG_POSTFIX}>;") + +set (CMAKE_JAVA_CLASSPATH ".") +foreach (CMAKE_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH}) + set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${CMAKE_INCLUDE_PATH}") +endforeach () + +foreach (HCP_JAR ${CMAKE_JAVA_INCLUDE_PATH}) + get_filename_component (_HCP_FILE ${HCP_JAR} NAME) + set (HDFJAVA_CLASSJARS "${_HCP_FILE} ${HDFJAVA_CLASSJARS}") +endforeach () + +foreach (example ${HDF_JAVA_EXAMPLES}) + get_filename_component (example_name ${example} NAME_WE) + file (WRITE ${PROJECT_BINARY_DIR}/${example_name}_Manifest.txt + "Main-Class: ${example_name} +Class-Path: ${HDFJAVA_CLASSJARS} +" + ) + add_jar (${EXAMPLE_VARNAME}_${example_name} + SOURCES ${example} + MANIFEST ${PROJECT_BINARY_DIR}/${example_name}_Manifest.txt + ) + get_target_property (${EXAMPLE_VARNAME}_${example_name}_JAR_FILE ${EXAMPLE_VARNAME}_${example_name} JAR_FILE) + get_target_property (${EXAMPLE_VARNAME}_${example_name}_CLASSPATH ${EXAMPLE_VARNAME}_${example_name} CLASSDIR) + add_dependencies (${EXAMPLE_VARNAME}_${example_name} ${H4EX_JAVA_LIBRARIES}) +endforeach () + +if (H4EX_BUILD_TESTING) + macro (ADD_H4_TEST resultfile resultcode) + add_test ( + NAME ${EXAMPLE_VARNAME}_jnative-h4-${resultfile} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_TESTER=${CMAKE_Java_RUNTIME};${CMAKE_Java_RUNTIME_FLAGS}" + -D "TEST_PROGRAM=${resultfile}" + -D "TEST_ARGS:STRING=${ARGN};${CMD_ARGS}" + -D "TEST_CLASSPATH:STRING=${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${${EXAMPLE_VARNAME}_${resultfile}_JAR_FILE}" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_OUTPUT=${PROJECT_BINARY_DIR}/${resultfile}.out" + -D "TEST_REFERENCE=${resultfile}.txt" + -D "TEST_EXPECT=${resultcode}" + -D "TEST_SKIP_COMPARE=TRUE" + -P "${${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR}/jrunTest.cmake" + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (${EXAMPLE_VARNAME}_jnative-h4-${resultfile} PROPERTIES DEPENDS ${last_test}) + endif () + set (last_test "${EXAMPLE_VARNAME}_jnative-h4-${resultfile}") + endmacro () + + foreach (example ${HDF_JAVA_EXAMPLES}) + get_filename_component (example_name ${example} NAME_WE) + add_test ( + NAME ${EXAMPLE_VARNAME}_jnative-h4-${example_name}-clearall-objects + COMMAND ${CMAKE_COMMAND} + -E remove + ${PROJECT_BINARY_DIR}/${example_name}.hdf + ${example_name}.out + ${example_name}.out.err + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (${EXAMPLE_VARNAME}_jnative-h4-${example_name}-clearall-objects PROPERTIES DEPENDS ${last_test}) + endif () + add_test ( + NAME ${EXAMPLE_VARNAME}_jnative-h4-${example_name}-copy-objects + COMMAND ${CMAKE_COMMAND} + -E copy_if_different + ${PROJECT_SOURCE_DIR}/testfiles/${example_name}.txt + ${PROJECT_BINARY_DIR}/${example_name}.txt + ) + set_tests_properties (${EXAMPLE_VARNAME}_jnative-h4-${example_name}-copy-objects PROPERTIES DEPENDS ${EXAMPLE_VARNAME}_jnative-h4-${example_name}-clearall-objects) + set (last_test "${EXAMPLE_VARNAME}_jnative-h4-${example_name}-copy-objects") + ADD_H4_TEST (${example_name} 0) + endforeach () +endif () diff --git a/HDF4Examples/JAVA/exAN/Java_sourcefiles.cmake b/HDF4Examples/JAVA/exAN/Java_sourcefiles.cmake new file mode 100644 index 0000000000..571ea16067 --- /dev/null +++ b/HDF4Examples/JAVA/exAN/Java_sourcefiles.cmake @@ -0,0 +1,6 @@ +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +set (HDF_JAVA_EXAMPLES + h4jex_AN_create_annotation.java +) diff --git a/HDF4Examples/JAVA/exAN/h4jex_AN_create_annotation.java b/HDF4Examples/JAVA/exAN/h4jex_AN_create_annotation.java new file mode 100644 index 0000000000..45b785ed5c --- /dev/null +++ b/HDF4Examples/JAVA/exAN/h4jex_AN_create_annotation.java @@ -0,0 +1,170 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF Products. The full HDF copyright * + * notice, including terms governing use, modification, and redistribution, * + * is contained in the file, COPYING. COPYING can be found at the root of * + * the source code distribution tree. You can also access it online at * + * http://www.hdfgroup.org/products/licenses.html. If you do not have * + * access to the file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +import hdf.hdflib.HDFConstants; +import hdf.hdflib.HDFLibrary; + +public class h4jex_AN_create_annotation { + + private static String FILE_NAME = "h4jex_AN_create_annotation.hdf"; + private static String VG_NAME = "AN Vgroup"; + private static String FILE_LABEL_TXT = "General HDF objects"; + private static String FILE_DESC_TXT = "This is an HDF file that contains general HDF objects"; + private static String DATA_LABEL_TXT = "Common AN Vgroup"; + private static String DATA_DESC_TXT = "This is a vgroup that is used to test data annotations"; + + public static void main(String args[]) throws Exception + { + //************************* Variable declaration ************************** + + long file_id; // HDF file identifier + long an_id; // AN interface identifier + long file_label_id; // file label identifier + long file_desc_id; // file description identifier + long data_label_id; // data label identifier + long data_desc_id; // data description identifier + long vgroup_id; + int vgroup_tag; + int vgroup_ref; + + //********************** End of variable declaration ********************** + + // Create the HDF file. + try { + file_id = HDFLibrary.Hopen(FILE_NAME, HDFConstants.DFACC_CREATE); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Unable to open file " + FILE_NAME + "for writing."); + return; + } + // Initialize the AN interface. + try { + an_id = HDFLibrary.ANstart(file_id); + try { + // Create the file label. + file_label_id = HDFLibrary.ANcreatef(an_id, HDFConstants.AN_FILE_LABEL); + try { + // Write the annotations to the file label. + HDFLibrary.ANwriteann(file_label_id, FILE_LABEL_TXT, FILE_LABEL_TXT.length()); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Failed to write label annotation."); + } + try { + // Create file description. + file_desc_id = HDFLibrary.ANcreatef(an_id, HDFConstants.AN_FILE_DESC); + try { + // Write the annotation to the file description. + HDFLibrary.ANwriteann(file_desc_id, FILE_DESC_TXT, FILE_DESC_TXT.length()); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Failed to write description annotation."); + } + try { + // Create a vgroup in the V interface. Note that the vgroup's ref number + // is set to -1 for creating and the access mode is "w" for writing. + HDFLibrary.Vstart(file_id); + try { + vgroup_id = HDFLibrary.Vattach(file_id, -1, "w"); + try { + HDFLibrary.Vsetname(vgroup_id, VG_NAME); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Could not name group."); + } + try { + // Obtain the tag and ref number of the vgroup for subsequent + // references. + vgroup_tag = HDFLibrary.VQuerytag(vgroup_id); + vgroup_ref = HDFLibrary.VQueryref(vgroup_id); + + // Create the data label for the vgroup identified by its tag + // and ref number. + data_label_id = HDFLibrary.ANcreate( + an_id, (short)vgroup_tag, (short)vgroup_ref, HDFConstants.AN_DATA_LABEL); + try { + // Write the annotation text to the data label. + + HDFLibrary.ANwriteann(data_label_id, DATA_LABEL_TXT, + DATA_LABEL_TXT.length()); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Failed to write data label annotation."); + } + try { + // Create the data description for the vgroup identified by its tag + // and ref number. + data_desc_id = + HDFLibrary.ANcreate(an_id, (short)vgroup_tag, (short)vgroup_ref, + HDFConstants.AN_DATA_DESC); + try { + // Write the annotation text to the data description. + HDFLibrary.ANwriteann(data_desc_id, DATA_DESC_TXT, + DATA_DESC_TXT.length()); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Failed to write data description annotation."); + } + HDFLibrary.ANendaccess(data_desc_id); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("annot create a new data description annotation."); + } + HDFLibrary.ANendaccess(data_label_id); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Cannot create a new data label annotation."); + } + // Terminate access to the vgroup and to the V interface. + HDFLibrary.Vdetach(vgroup_id); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Could not attach to VGroup interface"); + } + HDFLibrary.Vend(file_id); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Could not start VGroup interface"); + } + HDFLibrary.ANendaccess(file_desc_id); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Cannot create a new file description annotation."); + } + HDFLibrary.ANendaccess(file_label_id); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Cannot create a new file label annotation."); + } + // Terminate access to the AN interface and close the HDF file. + HDFLibrary.ANend(an_id); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Cannot start annotation handling on the file " + FILE_NAME); + } + HDFLibrary.Hclose(file_id); + System.out.println("AN_create_annotation done"); + } +} diff --git a/HDF4Examples/JAVA/exAN/testfiles/h4jex_AN_create_annotation.txt b/HDF4Examples/JAVA/exAN/testfiles/h4jex_AN_create_annotation.txt new file mode 100644 index 0000000000..90fc504fe5 --- /dev/null +++ b/HDF4Examples/JAVA/exAN/testfiles/h4jex_AN_create_annotation.txt @@ -0,0 +1 @@ +AN_create_annotation done diff --git a/HDF4Examples/JAVA/exGR/CMakeLists.txt b/HDF4Examples/JAVA/exGR/CMakeLists.txt new file mode 100644 index 0000000000..7ceb445ce2 --- /dev/null +++ b/HDF4Examples/JAVA/exGR/CMakeLists.txt @@ -0,0 +1,98 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_JAVA_GR Java) + +set (CMAKE_VERBOSE_MAKEFILE 1) + +set_directory_properties(PROPERTIES + INCLUDE_DIRECTORIES + "${HDFJAVA_LIB_DIR};${JAVA_INCLUDE_PATH};${JAVA_INCLUDE_PATH2}" +) + +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +include (Java_sourcefiles.cmake) + +if (WIN32) + set (CMAKE_JAVA_INCLUDE_FLAG_SEP ";") +else () + set (CMAKE_JAVA_INCLUDE_FLAG_SEP ":") +endif () + +set (CMAKE_JAVA_INCLUDE_PATH "${HDF4_JAVA_INCLUDE_DIRS}") +set (CMD_ARGS "-Dhdf.hdflib.HDFLibrary.loadLibraryName=${H4EX_JAVA_LIBRARY}$<$:${CMAKE_DEBUG_POSTFIX}>;") + +set (CMAKE_JAVA_CLASSPATH ".") +foreach (CMAKE_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH}) + set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${CMAKE_INCLUDE_PATH}") +endforeach () + +foreach (HCP_JAR ${CMAKE_JAVA_INCLUDE_PATH}) + get_filename_component (_HCP_FILE ${HCP_JAR} NAME) + set (HDFJAVA_CLASSJARS "${_HCP_FILE} ${HDFJAVA_CLASSJARS}") +endforeach () + +foreach (example ${HDF_JAVA_EXAMPLES}) + get_filename_component (example_name ${example} NAME_WE) + file (WRITE ${PROJECT_BINARY_DIR}/${example_name}_Manifest.txt + "Main-Class: ${example_name} +Class-Path: ${HDFJAVA_CLASSJARS} +" + ) + add_jar (${EXAMPLE_VARNAME}_${example_name} + SOURCES ${example} + MANIFEST ${PROJECT_BINARY_DIR}/${example_name}_Manifest.txt + ) + get_target_property (${EXAMPLE_VARNAME}_${example_name}_JAR_FILE ${EXAMPLE_VARNAME}_${example_name} JAR_FILE) + get_target_property (${EXAMPLE_VARNAME}_${example_name}_CLASSPATH ${EXAMPLE_VARNAME}_${example_name} CLASSDIR) + add_dependencies (${EXAMPLE_VARNAME}_${example_name} ${H4EX_JAVA_LIBRARIES}) +endforeach () + +if (H4EX_BUILD_TESTING) + macro (ADD_H4_TEST resultfile resultcode) + add_test ( + NAME ${EXAMPLE_VARNAME}_jnative-h4-${resultfile} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_TESTER=${CMAKE_Java_RUNTIME};${CMAKE_Java_RUNTIME_FLAGS}" + -D "TEST_PROGRAM=${resultfile}" + -D "TEST_ARGS:STRING=${ARGN};${CMD_ARGS}" + -D "TEST_CLASSPATH:STRING=${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${${EXAMPLE_VARNAME}_${resultfile}_JAR_FILE}" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_OUTPUT=${PROJECT_BINARY_DIR}/${resultfile}.out" + -D "TEST_REFERENCE=${resultfile}.txt" + -D "TEST_EXPECT=${resultcode}" + -D "TEST_SKIP_COMPARE=TRUE" + -P "${${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR}/jrunTest.cmake" + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (${EXAMPLE_VARNAME}_jnative-h4-${resultfile} PROPERTIES DEPENDS ${last_test}) + endif () + set (last_test "${EXAMPLE_VARNAME}_jnative-h4-${resultfile}") + endmacro () + + foreach (example ${HDF_JAVA_EXAMPLES}) + get_filename_component (example_name ${example} NAME_WE) + add_test ( + NAME ${EXAMPLE_VARNAME}_jnative-h4-${example_name}-clearall-objects + COMMAND ${CMAKE_COMMAND} + -E remove + ${PROJECT_BINARY_DIR}/${example_name}.hdf + ${example_name}.out + ${example_name}.out.err + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (${EXAMPLE_VARNAME}_jnative-h4-${example_name}-clearall-objects PROPERTIES DEPENDS ${last_test}) + endif () + add_test ( + NAME ${EXAMPLE_VARNAME}_jnative-h4-${example_name}-copy-objects + COMMAND ${CMAKE_COMMAND} + -E copy_if_different + ${PROJECT_SOURCE_DIR}/testfiles/${example_name}.txt + ${PROJECT_BINARY_DIR}/${example_name}.txt + ) + set_tests_properties (${EXAMPLE_VARNAME}_jnative-h4-${example_name}-copy-objects PROPERTIES DEPENDS ${EXAMPLE_VARNAME}_jnative-h4-${example_name}-clearall-objects) + set (last_test "${EXAMPLE_VARNAME}_jnative-h4-${example_name}-copy-objects") + ADD_H4_TEST (${example_name} 0) + endforeach () +endif () diff --git a/HDF4Examples/JAVA/exGR/Java_sourcefiles.cmake b/HDF4Examples/JAVA/exGR/Java_sourcefiles.cmake new file mode 100644 index 0000000000..f5fe1d21d3 --- /dev/null +++ b/HDF4Examples/JAVA/exGR/Java_sourcefiles.cmake @@ -0,0 +1,6 @@ +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +set (HDF_JAVA_EXAMPLES + h4jex_GR_create_and_write_image.java +) diff --git a/HDF4Examples/JAVA/exGR/h4jex_GR_create_and_write_image.java b/HDF4Examples/JAVA/exGR/h4jex_GR_create_and_write_image.java new file mode 100644 index 0000000000..90f077583a --- /dev/null +++ b/HDF4Examples/JAVA/exGR/h4jex_GR_create_and_write_image.java @@ -0,0 +1,102 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF Products. The full HDF copyright * + * notice, including terms governing use, modification, and redistribution, * + * is contained in the file, COPYING. COPYING can be found at the root of * + * the source code distribution tree. You can also access it online at * + * http://www.hdfgroup.org/products/licenses.html. If you do not have * + * access to the file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +import hdf.hdflib.HDFConstants; +import hdf.hdflib.HDFLibrary; + +public class h4jex_GR_create_and_write_image { + + private static String FILE_NAME = "h4ex_GR_create_and_write_image.hdf"; + private static String IMAGE_NAME = "Image Array 1"; + private static int X_LENGTH = 10; // number of columns in the image + private static int Y_LENGTH = 5; // number of rows in the image + private static int N_COMPS = 2; // number of components in the image + + public static void main(String args[]) throws Exception + { + //************************* Variable declaration ************************** + + long file_id; // HDF file identifier + long gr_id; // GR interface identifier + long ri_id; // raster image identifier + int[] start = new int[2]; // start position to write for each dimension + int[] edges = new int[2]; // number of elements to be written along each dimension + int[] dim_sizes = new int[2]; // dimension sizes of the image array + int interlace_mode; // interlace mode of the image + int data_type; // data type of the image data + short[][][] image_buf = new short[Y_LENGTH][X_LENGTH][N_COMPS]; + + //********************** End of variable declaration ********************** + + // Create and open the file. + try { + file_id = HDFLibrary.Hopen(FILE_NAME, HDFConstants.DFACC_CREATE); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Unable to open file " + FILE_NAME + "for writing."); + return; + } + + // Initialize the GR interface. + try { + gr_id = HDFLibrary.GRstart(file_id); + + // Set the data type, interlace mode, and dimensions of the image. + data_type = HDFConstants.DFNT_INT16; + interlace_mode = HDFConstants.MFGR_INTERLACE_PIXEL; + dim_sizes[0] = X_LENGTH; + dim_sizes[1] = Y_LENGTH; + try { + // Create the raster image array. + ri_id = HDFLibrary.GRcreate(gr_id, IMAGE_NAME, N_COMPS, data_type, interlace_mode, dim_sizes); + + // Fill the image data buffer with values. + for (int i = 0; i < Y_LENGTH; i++) { + for (int j = 0; j < X_LENGTH; j++) { + image_buf[i][j][0] = (short)((i + j) + 1); // first component + image_buf[i][j][1] = (short)((i + j) + 1); // second component + } + } + + // Define the size of the data to be written, i.e., start from the origin + // and go as long as the length of each dimension. + start[0] = start[1] = 0; + edges[0] = X_LENGTH; + edges[1] = Y_LENGTH; + + // Write the data in the buffer into the image array. + try { + HDFLibrary.GRwriteimage(ri_id, start, null, edges, image_buf); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Unable to create the raster image array"); + } + // Terminate access to the raster image + HDFLibrary.GRendaccess(ri_id); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Unable to create the raster image array"); + } + // Terminate access to the GR interface + HDFLibrary.GRend(gr_id); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Cannot start GR interface handling on the file " + FILE_NAME); + } + HDFLibrary.Hclose(file_id); + System.out.println("GR_create_and_write_image done"); + } +} diff --git a/HDF4Examples/JAVA/exGR/testfiles/h4jex_GR_create_and_write_image.txt b/HDF4Examples/JAVA/exGR/testfiles/h4jex_GR_create_and_write_image.txt new file mode 100644 index 0000000000..3e6b776972 --- /dev/null +++ b/HDF4Examples/JAVA/exGR/testfiles/h4jex_GR_create_and_write_image.txt @@ -0,0 +1 @@ +GR_create_and_write_image done diff --git a/HDF4Examples/JAVA/exSD/CMakeLists.txt b/HDF4Examples/JAVA/exSD/CMakeLists.txt new file mode 100644 index 0000000000..8eef5cfddd --- /dev/null +++ b/HDF4Examples/JAVA/exSD/CMakeLists.txt @@ -0,0 +1,98 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_JAVA_SD Java) + +set (CMAKE_VERBOSE_MAKEFILE 1) + +set_directory_properties(PROPERTIES + INCLUDE_DIRECTORIES + "${HDFJAVA_LIB_DIR};${JAVA_INCLUDE_PATH};${JAVA_INCLUDE_PATH2}" +) + +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +include (Java_sourcefiles.cmake) + +if (WIN32) + set (CMAKE_JAVA_INCLUDE_FLAG_SEP ";") +else () + set (CMAKE_JAVA_INCLUDE_FLAG_SEP ":") +endif () + +set (CMAKE_JAVA_INCLUDE_PATH "${HDF4_JAVA_INCLUDE_DIRS}") +set (CMD_ARGS "-Dhdf.hdflib.HDFLibrary.loadLibraryName=${H4EX_JAVA_LIBRARY}$<$:${CMAKE_DEBUG_POSTFIX}>;") + +set (CMAKE_JAVA_CLASSPATH ".") +foreach (CMAKE_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH}) + set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${CMAKE_INCLUDE_PATH}") +endforeach () + +foreach (HCP_JAR ${CMAKE_JAVA_INCLUDE_PATH}) + get_filename_component (_HCP_FILE ${HCP_JAR} NAME) + set (HDFJAVA_CLASSJARS "${_HCP_FILE} ${HDFJAVA_CLASSJARS}") +endforeach () + +foreach (example ${HDF_JAVA_EXAMPLES}) + get_filename_component (example_name ${example} NAME_WE) + file (WRITE ${PROJECT_BINARY_DIR}/${example_name}_Manifest.txt + "Main-Class: ${example_name} +Class-Path: ${HDFJAVA_CLASSJARS} +" + ) + add_jar (${EXAMPLE_VARNAME}_${example_name} + SOURCES ${example} + MANIFEST ${PROJECT_BINARY_DIR}/${example_name}_Manifest.txt + ) + get_target_property (${EXAMPLE_VARNAME}_${example_name}_JAR_FILE ${EXAMPLE_VARNAME}_${example_name} JAR_FILE) + get_target_property (${EXAMPLE_VARNAME}_${example_name}_CLASSPATH ${EXAMPLE_VARNAME}_${example_name} CLASSDIR) + add_dependencies (${EXAMPLE_VARNAME}_${example_name} ${H4EX_JAVA_LIBRARIES}) +endforeach () + +if (H4EX_BUILD_TESTING) + macro (ADD_H4_TEST resultfile resultcode) + add_test ( + NAME ${EXAMPLE_VARNAME}_jnative-h4-${resultfile} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_TESTER=${CMAKE_Java_RUNTIME};${CMAKE_Java_RUNTIME_FLAGS}" + -D "TEST_PROGRAM=${resultfile}" + -D "TEST_ARGS:STRING=${ARGN};${CMD_ARGS}" + -D "TEST_CLASSPATH:STRING=${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${${EXAMPLE_VARNAME}_${resultfile}_JAR_FILE}" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_OUTPUT=${PROJECT_BINARY_DIR}/${resultfile}.out" + -D "TEST_REFERENCE=${resultfile}.txt" + -D "TEST_EXPECT=${resultcode}" + -D "TEST_SKIP_COMPARE=TRUE" + -P "${${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR}/jrunTest.cmake" + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (${EXAMPLE_VARNAME}_jnative-h4-${resultfile} PROPERTIES DEPENDS ${last_test}) + endif () + set (last_test "${EXAMPLE_VARNAME}_jnative-h4-${resultfile}") + endmacro () + + foreach (example ${HDF_JAVA_EXAMPLES}) + get_filename_component (example_name ${example} NAME_WE) + add_test ( + NAME ${EXAMPLE_VARNAME}_jnative-h4-${example_name}-clearall-objects + COMMAND ${CMAKE_COMMAND} + -E remove + ${PROJECT_BINARY_DIR}/${example_name}.hdf + ${example_name}.out + ${example_name}.out.err + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (${EXAMPLE_VARNAME}_jnative-h4-${example_name}-clearall-objects PROPERTIES DEPENDS ${last_test}) + endif () + add_test ( + NAME ${EXAMPLE_VARNAME}_jnative-h4-${example_name}-copy-objects + COMMAND ${CMAKE_COMMAND} + -E copy_if_different + ${PROJECT_SOURCE_DIR}/testfiles/${example_name}.txt + ${PROJECT_BINARY_DIR}/${example_name}.txt + ) + set_tests_properties (${EXAMPLE_VARNAME}_jnative-h4-${example_name}-copy-objects PROPERTIES DEPENDS ${EXAMPLE_VARNAME}_jnative-h4-${example_name}-clearall-objects) + set (last_test "${EXAMPLE_VARNAME}_jnative-h4-${example_name}-copy-objects") + ADD_H4_TEST (${example_name} 0) + endforeach () +endif () diff --git a/HDF4Examples/JAVA/exSD/Java_sourcefiles.cmake b/HDF4Examples/JAVA/exSD/Java_sourcefiles.cmake new file mode 100644 index 0000000000..f7e178afea --- /dev/null +++ b/HDF4Examples/JAVA/exSD/Java_sourcefiles.cmake @@ -0,0 +1,6 @@ +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +set (HDF_JAVA_EXAMPLES + h4jex_SD_unlimited_sds.java +) diff --git a/HDF4Examples/JAVA/exSD/h4jex_SD_unlimited_sds.java b/HDF4Examples/JAVA/exSD/h4jex_SD_unlimited_sds.java new file mode 100644 index 0000000000..238dbb547f --- /dev/null +++ b/HDF4Examples/JAVA/exSD/h4jex_SD_unlimited_sds.java @@ -0,0 +1,144 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF Products. The full HDF copyright * + * notice, including terms governing use, modification, and redistribution, * + * is contained in the file, COPYING. COPYING can be found at the root of * + * the source code distribution tree. You can also access it online at * + * http://www.hdfgroup.org/products/licenses.html. If you do not have * + * access to the file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +import hdf.hdflib.HDFConstants; +import hdf.hdflib.HDFLibrary; + +public class h4jex_SD_unlimited_sds { + + private static String FILE_NAME = "h4jex_SD_unlimited_sds.hdf"; + private static String SDS_NAME = "AppendableData"; + private static int X_LENGTH = 10; + private static int Y_LENGTH = 10; + private static int RANK = 2; + + public static void main(String args[]) throws Exception + { + //************************* Variable declaration ************************** + + long sd_id; + long sds_id; + int sds_index; + int[] dim_sizes = new int[2]; + int[][] data = new int[Y_LENGTH][X_LENGTH]; + int[] append_data = new int[X_LENGTH]; + int[] start = new int[2]; + int[] edges = new int[2]; + + //********************** End of variable declaration ********************** + + // Data initialization. + for (int j = 0; j < Y_LENGTH; j++) { + for (int i = 0; i < X_LENGTH; i++) + data[j][i] = (i + 1) + (j + 1); + } + + // Create the file and initialize the SD interface. + try { + sd_id = HDFLibrary.SDstart(FILE_NAME, HDFConstants.DFACC_CREATE); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Unable to open file " + FILE_NAME + "for writing."); + return; + } + + // Define dimensions of the array. Make the first dimension + // appendable by defining its length to be unlimited. + dim_sizes[0] = HDFConstants.SD_UNLIMITED; + dim_sizes[1] = X_LENGTH; + + try { + // Create the array data set. + sds_id = HDFLibrary.SDcreate(sd_id, SDS_NAME, HDFConstants.DFNT_INT32, RANK, dim_sizes); + + // Define the location and the size of the data to be written + // to the data set. + start[0] = start[1] = 0; + edges[0] = Y_LENGTH; + edges[1] = X_LENGTH; + + try { + // Write the data. + HDFLibrary.SDwritedata(sds_id, start, null, edges, data); + try { + // Terminate access to the array data set, terminate access + // to the SD interface, and close the file. + HDFLibrary.SDendaccess(sds_id); + HDFLibrary.SDend(sd_id); + + // Store the array values to be appended to the data set. + for (int i = 0; i < X_LENGTH; i++) + append_data[i] = 1000 + i; + + try { + // Reopen the file and initialize the SD interface. + sd_id = HDFLibrary.SDstart(FILE_NAME, HDFConstants.DFACC_WRITE); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Unable to reopen file " + FILE_NAME + "for writing."); + return; + } + + // Select the first data set. + sds_index = 0; + try { + sds_id = HDFLibrary.SDselect(sd_id, sds_index); + + // Check if selected SDS is unlimited. If it is not, then terminate access + // to the SD interface and close the file. + if (HDFLibrary.SDisrecord(sds_id)) { + // Define the location of the append to start at the first column + // of the 11th row of the data set and to stop at the end of the + // eleventh row. + start[0] = Y_LENGTH; + start[1] = 0; + edges[0] = 1; + edges[1] = X_LENGTH; + try { + // Append data to the data set. + HDFLibrary.SDwritedata(sds_id, start, null, edges, append_data); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Failed to append data."); + } + } + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Could not select the first data set"); + } + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Failed to terminate access."); + } + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Failed to write data."); + } + // Terminate access to the data set. + HDFLibrary.SDendaccess(sds_id); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Cannot create the array data set " + SDS_NAME); + } + // Terminate access to the SD interface and close the HDF file. + HDFLibrary.SDend(sd_id); + + System.out.println("SD_unlimited_sds done"); + } +} diff --git a/HDF4Examples/JAVA/exSD/testfiles/h4jex_SD_unlimited_sds.txt b/HDF4Examples/JAVA/exSD/testfiles/h4jex_SD_unlimited_sds.txt new file mode 100644 index 0000000000..c4ad59403a --- /dev/null +++ b/HDF4Examples/JAVA/exSD/testfiles/h4jex_SD_unlimited_sds.txt @@ -0,0 +1 @@ +SD_unlimited_sds done diff --git a/HDF4Examples/JAVA/exVD/CMakeLists.txt b/HDF4Examples/JAVA/exVD/CMakeLists.txt new file mode 100644 index 0000000000..e9d81442bd --- /dev/null +++ b/HDF4Examples/JAVA/exVD/CMakeLists.txt @@ -0,0 +1,98 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_JAVA_VD Java) + +set (CMAKE_VERBOSE_MAKEFILE 1) + +set_directory_properties(PROPERTIES + INCLUDE_DIRECTORIES + "${HDFJAVA_LIB_DIR};${JAVA_INCLUDE_PATH};${JAVA_INCLUDE_PATH2}" +) + +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +include (Java_sourcefiles.cmake) + +if (WIN32) + set (CMAKE_JAVA_INCLUDE_FLAG_SEP ";") +else () + set (CMAKE_JAVA_INCLUDE_FLAG_SEP ":") +endif () + +set (CMAKE_JAVA_INCLUDE_PATH "${HDF4_JAVA_INCLUDE_DIRS}") +set (CMD_ARGS "-Dhdf.hdflib.HDFLibrary.loadLibraryName=${H4EX_JAVA_LIBRARY}$<$:${CMAKE_DEBUG_POSTFIX}>;") + +set (CMAKE_JAVA_CLASSPATH ".") +foreach (CMAKE_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH}) + set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${CMAKE_INCLUDE_PATH}") +endforeach () + +foreach (HCP_JAR ${CMAKE_JAVA_INCLUDE_PATH}) + get_filename_component (_HCP_FILE ${HCP_JAR} NAME) + set (HDFJAVA_CLASSJARS "${_HCP_FILE} ${HDFJAVA_CLASSJARS}") +endforeach () + +foreach (example ${HDF_JAVA_EXAMPLES}) + get_filename_component (example_name ${example} NAME_WE) + file (WRITE ${PROJECT_BINARY_DIR}/${example_name}_Manifest.txt + "Main-Class: ${example_name} +Class-Path: ${HDFJAVA_CLASSJARS} +" + ) + add_jar (${EXAMPLE_VARNAME}_${example_name} + SOURCES ${example} + MANIFEST ${PROJECT_BINARY_DIR}/${example_name}_Manifest.txt + ) + get_target_property (${EXAMPLE_VARNAME}_${example_name}_JAR_FILE ${EXAMPLE_VARNAME}_${example_name} JAR_FILE) + get_target_property (${EXAMPLE_VARNAME}_${example_name}_CLASSPATH ${EXAMPLE_VARNAME}_${example_name} CLASSDIR) + add_dependencies (${EXAMPLE_VARNAME}_${example_name} ${H4EX_JAVA_LIBRARIES}) +endforeach () + +if (H4EX_BUILD_TESTING) + macro (ADD_H4_TEST resultfile resultcode) + add_test ( + NAME ${EXAMPLE_VARNAME}_jnative-h4-${resultfile} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_TESTER=${CMAKE_Java_RUNTIME};${CMAKE_Java_RUNTIME_FLAGS}" + -D "TEST_PROGRAM=${resultfile}" + -D "TEST_ARGS:STRING=${ARGN};${CMD_ARGS}" + -D "TEST_CLASSPATH:STRING=${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${${EXAMPLE_VARNAME}_${resultfile}_JAR_FILE}" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_OUTPUT=${PROJECT_BINARY_DIR}/${resultfile}.out" + -D "TEST_REFERENCE=${resultfile}.txt" + -D "TEST_EXPECT=${resultcode}" + -D "TEST_SKIP_COMPARE=TRUE" + -P "${${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR}/jrunTest.cmake" + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (${EXAMPLE_VARNAME}_jnative-h4-${resultfile} PROPERTIES DEPENDS ${last_test}) + endif () + set (last_test "${EXAMPLE_VARNAME}_jnative-h4-${resultfile}") + endmacro () + + foreach (example ${HDF_JAVA_EXAMPLES}) + get_filename_component (example_name ${example} NAME_WE) + add_test ( + NAME ${EXAMPLE_VARNAME}_jnative-h4-${example_name}-clearall-objects + COMMAND ${CMAKE_COMMAND} + -E remove + ${PROJECT_BINARY_DIR}/${example_name}.hdf + ${example_name}.out + ${example_name}.out.err + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (${EXAMPLE_VARNAME}_jnative-h4-${example_name}-clearall-objects PROPERTIES DEPENDS ${last_test}) + endif () + add_test ( + NAME ${EXAMPLE_VARNAME}_jnative-h4-${example_name}-copy-objects + COMMAND ${CMAKE_COMMAND} + -E copy_if_different + ${PROJECT_SOURCE_DIR}/testfiles/${example_name}.txt + ${PROJECT_BINARY_DIR}/${example_name}.txt + ) + set_tests_properties (${EXAMPLE_VARNAME}_jnative-h4-${example_name}-copy-objects PROPERTIES DEPENDS ${EXAMPLE_VARNAME}_jnative-h4-${example_name}-clearall-objects) + set (last_test "${EXAMPLE_VARNAME}_jnative-h4-${example_name}-copy-objects") + ADD_H4_TEST (${example_name} 0) + endforeach () +endif () diff --git a/HDF4Examples/JAVA/exVD/Java_sourcefiles.cmake b/HDF4Examples/JAVA/exVD/Java_sourcefiles.cmake new file mode 100644 index 0000000000..558082ca1f --- /dev/null +++ b/HDF4Examples/JAVA/exVD/Java_sourcefiles.cmake @@ -0,0 +1,6 @@ +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +set (HDF_JAVA_EXAMPLES + h4jex_VD_create_onefield_vdatas.java +) diff --git a/HDF4Examples/JAVA/exVD/h4jex_VD_create_onefield_vdatas.java b/HDF4Examples/JAVA/exVD/h4jex_VD_create_onefield_vdatas.java new file mode 100644 index 0000000000..f0d189f471 --- /dev/null +++ b/HDF4Examples/JAVA/exVD/h4jex_VD_create_onefield_vdatas.java @@ -0,0 +1,149 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF Products. The full HDF copyright * + * notice, including terms governing use, modification, and redistribution, * + * is contained in the file, COPYING. COPYING can be found at the root of * + * the source code distribution tree. You can also access it online at * + * http://www.hdfgroup.org/products/licenses.html. If you do not have * + * access to the file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +import hdf.hdflib.HDFConstants; +import hdf.hdflib.HDFLibrary; + +public class h4jex_VD_create_onefield_vdatas { + private static String FILE_NAME = "h4jex_VD_create_onefield_vdatas.hdf"; + private static String CLASS1_NAME = "5x1 Array"; + private static String CLASS2_NAME = "6x4 Array"; + private static String VDATA1_NAME = "First Vdata"; + private static String VDATA2_NAME = "Second Vdata"; + private static String FIELD1_NAME = "Single-component Field"; + private static String FIELD2_NAME = "Multi-component Field"; + private static String VDATA_NAME = "Vdata 1"; + private static String VDATA_CLASS = "Empty Vdatas"; + private static int N_RECORDS_1 = 5; // number of records the first vdata contains + private static int N_RECORDS_2 = 6; // number of records the second vdata contains + private static int ORDER_2 = 4; // order of the field in the second vdata + // Note that the order of the field in the first vdata is 1 + + public static void main(String args[]) throws Exception + { + //************************* Variable declaration ************************** + + long file_id, vdata1_ref, vdata2_ref; + + // Define an array to buffer the data of the first vdata. + byte[] vdata1_buf = {'V', 'D', 'A', 'T', 'A'}; + + // Define an array to buffer the data of the second vdata. + int[] vdata2_buf = {1, 2, 3, 4, 2, 4, 6, 8, 3, 6, 9, 12, 4, 8, 12, 16, 5, 10, 15, 20, 6, 12, 18, 24}; + + //********************** End of variable declaration ********************** + + // create file + VD_create_vdatas(); + + // Open the HDF file for writing. + try { + file_id = HDFLibrary.Hopen(FILE_NAME, HDFConstants.DFACC_WRITE); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Unable to open file " + FILE_NAME + "for writing."); + return; + } + + try { + // Initialize the VS interface. + HDFLibrary.Vstart(file_id); + try { + // Create the first vdata and populate it with data from the vdata1_buf + // array. + vdata1_ref = HDFLibrary.VHstoredata(file_id, FIELD1_NAME, vdata1_buf, N_RECORDS_1, + HDFConstants.DFNT_CHAR8, VDATA1_NAME, CLASS1_NAME); + + // Create the second vdata and populate it with data from the vdata2_buf array. + vdata2_ref = + HDFLibrary.VHstoredatam(file_id, FIELD2_NAME, vdata2_buf, N_RECORDS_2, + HDFConstants.DFNT_INT32, VDATA2_NAME, CLASS2_NAME, ORDER_2); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Cannot populate data"); + } + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Cannot start V interface handling on the file " + FILE_NAME); + } + + // Terminate access to the VS interface and close the HDF file. + try { + if (file_id >= 0) { + HDFLibrary.Vend(file_id); + HDFLibrary.Hclose(file_id); + } + } + catch (Exception e) { + e.printStackTrace(); + } + System.out.println("VD_create_onefield_vdatas done"); + } + + public static void VD_create_vdatas() throws Exception + { + long file_id = -1; + long subvgroup_id = -1; + long vgroup_id1 = -1; + + // Create a new file using default properties. + try { + file_id = HDFLibrary.Hopen(FILE_NAME, HDFConstants.DFACC_CREATE); + // Initialize the V interface. + if (file_id >= 0) + HDFLibrary.Vstart(file_id); + } + catch (Exception e) { + e.printStackTrace(); + System.err.println("Failed to create file:" + FILE_NAME); + return; + } + + try { + // Create the vgroup. Note that the vgroup reference number is set + // to -1 for creating and the access mode is "w" for writing. + if (file_id >= 0) { + vgroup_id1 = HDFLibrary.VSattach(file_id, -1, "w"); + if (vgroup_id1 >= 0) { + HDFLibrary.VSsetname(vgroup_id1, VDATA_NAME); + HDFLibrary.VSsetclass(vgroup_id1, VDATA_CLASS); + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + + // Close the group. + try { + if (vgroup_id1 >= 0) + HDFLibrary.VSdetach(vgroup_id1); + } + catch (Exception e) { + e.printStackTrace(); + } + + // Close the file. + try { + if (file_id >= 0) { + HDFLibrary.Vend(file_id); + HDFLibrary.Hclose(file_id); + } + } + catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/HDF4Examples/JAVA/exVD/testfiles/h4jex_VD_create_onefield_vdatas.txt b/HDF4Examples/JAVA/exVD/testfiles/h4jex_VD_create_onefield_vdatas.txt new file mode 100644 index 0000000000..a5b4493486 --- /dev/null +++ b/HDF4Examples/JAVA/exVD/testfiles/h4jex_VD_create_onefield_vdatas.txt @@ -0,0 +1 @@ +VD_create_onefield_vdatas done diff --git a/HDF4Examples/Using_CMake.txt b/HDF4Examples/Using_CMake.txt new file mode 100644 index 0000000000..ce861920e8 --- /dev/null +++ b/HDF4Examples/Using_CMake.txt @@ -0,0 +1,197 @@ +************************************************************************ +* Build and Test HDF4 Examples with CMake * +************************************************************************ + +Notes: This short instruction is written for users who want to quickly build + HDF4 Examples using the HDF4 binary package using the CMake tools. + + More information about using CMake can be found at the KitWare + site, www.cmake.org. + + CMake uses the command line; however, the visual CMake tool is + available for the configuration step. The steps are similar for + all of the operating systems supported by CMake. + + NOTES: + 1. Using CMake for building and using HDF4 is under active + development. While we have attempted to provide error-free + files, please understand that development with CMake has not + been extensively tested outside of HDF. The CMake specific + files may change before the next release. + + 2. CMake for HDF4 development should be usable on any system + where CMake is supported. Please send us any comments on how + CMake support can be improved on any system. + + +======================================================================== +I. Preconditions +======================================================================== + + 1. We suggest you obtain the latest CMake for windows from the Kitware + web site. The HDF 4.2.x product requires a minimum CMake version + of 3.12. + + 2. You have installed the HDF4 library built with CMake, by executing + the HDF Install Utility (the *.msi file in the binary package for + Windows or the *.sh on Linux). If you are using a Windows platform, + you can obtain a pre-built Windows binary from The HDF Group's website + at www.hdfgroup.org. + + 3. Set the environment variable HDF4_DIR to the installed location of + the config files for HDF4. On Windows: + HDF4_ROOT=C:/Program Files/HDF_Group/HDF/4.2.x/ + + (Note there are no quote characters used on Windows and all platforms + use forward slashes) + + 4. Created separate source and build directories. + (CMake commands are executed in the build directory) + + + +======================================================================== +II. Building HDF4 Examples with CMake +======================================================================== + +Go through these steps to build HDF4 applications with CMake. + + 1. Run CMake + 2. Configure the cache settings + 3. Build HDF4 Examples + 4. Test HDF4 Examples. + +These steps are described in more detail below. + + + + 1. Run CMake + + The visual CMake executable is named "cmake-gui.exe" on Windows and should be + available in your Start menu. For Linux, UNIX, and Mac users the + executable is named "cmake-gui" and can be found where CMake was + installed. + + Specify the source and build directories. Make the build and source + directories different. For example on Windows, if the source is at + c:\MyHDFstuff\HDF4Examples, then use c:\MyHDFstuff\HDF4Examples\build or + c:\MyHDFstuff\build\HDF4Examples for the build directory. + + PREFERRED: + Users can perform the configuration step without using the visual + cmake-gui program. The following is an example command line + configuration step executed within the build directory: + + cmake -G "" [-D] + + Where is + * Borland Makefiles + * MSYS Makefiles + * MinGW Makefiles + * NMake Makefiles + * Unix Makefiles + * Visual Studio 15 + * Visual Studio 15 Win64 + * Visual Studio 17 + * Visual Studio 17 Win64 + * Visual Studio 19 + + is: + * H4EX_BUILD_TESTING:BOOL=ON + * BUILD_SHARED_LIBS:BOOL=[ON | OFF] + * HDF_BUILD_FORTRAN:BOOL=[ON | OFF] + * HDF_BUILD_JAVA:BOOL=[ON | OFF] + + if the hdf4 library was built with a namespace (i.e. "hdf4::") add: + -D HDF4_NAMESPACE:STRING=hdf4:: + + 2. Configure the cache settings + + 2.1 Visual CMake users, click the Configure button. If this is the first time you are + running cmake-gui in this directory, you will be prompted for the + generator you wish to use (for example on Windows, Visual Studio 15). + CMake will read in the CMakeLists.txt files from the source directory and + display options for the HDF4 Examples project. After the first configure you + can adjust the cache settings and/or specify locations of other programs. + + Any conflicts or new values will be highlighted by the configure + process in red. Once you are happy with all the settings and there are no + more values in red, click the Generate button to produce the appropriate + build files. + + On Windows, if you are using a Visual Studio generator, the solution and + project files will be created in the build folder. + + On linux, if you are using the Unix Makefiles generator, the Makefiles will + be created in the build folder. + + 2.2 Alternative command line example on Windows in c:\MyHDFstuff\HDF4Examples\build directory: + + cmake -G "Visual Studio 19" -DH4EX_BUILD_TESTING:BOOL=ON -DBUILD_SHARED_LIBS:BOOL=ON .. + + 3. Build HDF4 examples + + On Windows, you can build HDF4 examples using either the Visual Studio Environment + or the command line. The command line is normally used on linux, Unix, and Mac. + + To build from the command line, navigate to your build directory and + execute the following: + + cmake --build . --config {Debug | Release} + + NOTE: "--config {Debug | Release}" may be optional on your platform. We + recommend choosing either Debug or Release on Windows. If you are + using the pre-built binaries from HDF, use Release. + + 3.1 If you wish to use the Visual Studio environment, open the solution + file in your build directory. Be sure to select either Debug or + Release and build the solution. + + 4. Test HDF4 Examples. + + To test the build, navigate to your build directory and execute: + + ctest . -C {Debug | Release} + + NOTE: "-C {Debug | Release}" may be optional on your platform. We + recommend choosing either Debug or Release to match the build + step on Windows. + + 5. The files that support building with CMake are all of the files in the + config/cmake folder, the CMakeLists.txt files in each source folder, and + CTestConfig.cmake. CTestConfig.cmake is specific to the internal testing + performed by The HDF Group. It should be altered for the user's + installation and needs. The cacheinit.cmake file settings are used by + The HDF Group for daily testing. It should be altered/ignored for the user's + installation and needs. + + + +======================================================================== +III. Using HDF4 Libraries with Visual Studio 2008 (no longer supported) +======================================================================== + + 1. Set up path for external libraries and headers + + Invoke Microsoft Visual Studio and go to "Tools" and select "Options", + find "Projects", and then "VC++ Directories". + + 1.1 If you are building on 64-bit Windows, find the "Platform" dropdown + and select "x64". + + 1.2 Find the box "Show directories for", choose "Include files", add the + header path (i.e. c:\Program Files\HDF Group\HDF4\hdf4.2.x\include) + to the included directories. + + 1.3 Find the box "Show directories for", choose "Library files", add the + library path (i.e. c:\Program Files\HDF Group\HDF4\hdf4.2.x\lib) + to the library directories. + + 1.4 If using Fortran libraries, you will also need to setup the path + for the Intel Fortran compiler. + + +************************************************************************ + +Need further assistance, send email to help@hdfgroup.org + diff --git a/HDF4Examples/config/cmake-presets/hidden-presets.json b/HDF4Examples/config/cmake-presets/hidden-presets.json new file mode 100644 index 0000000000..40aaf288a7 --- /dev/null +++ b/HDF4Examples/config/cmake-presets/hidden-presets.json @@ -0,0 +1,531 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "ci-base", + "displayName": "Basic Config", + "description": "Basic build using Ninja generator", + "generator": "Ninja", + "hidden": true, + "binaryDir": "${sourceParentDir}/build/${presetName}", + "installDir": "${sourceParentDir}/install/${presetName}" + }, + { + "name": "ci-x64", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "hidden": true + }, + { + "name": "ci-x86", + "architecture": { + "value": "x86", + "strategy": "external" + }, + "hidden": true + }, + { + "name": "ci-Debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + }, + "hidden": true + }, + { + "name": "ci-Release", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "HDF4_BUILD_DOC": "ON" + }, + "hidden": true + }, + { + "name": "ci-MSVC", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "cl", + "CMAKE_CXX_COMPILER": "cl" + }, + "toolset": { + "value": "host=x64", + "strategy": "external" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "ci-Clang", + "hidden": true, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "config/toolchain/clang.cmake" + }, + "toolset": { + "value": "host=x64", + "strategy": "external" + } + }, + { + "name": "ci-GNUC", + "hidden": true, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "config/toolchain/gcc.cmake" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + }, + "toolset": { + "value": "host=x64", + "strategy": "external" + } + }, + { + "name": "ci-Intel", + "hidden": true, + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "config/toolchain/intel.cmake" + }, + "toolset": { + "value": "host=x64", + "strategy": "external" + } + }, + { + "name": "ci-Java", + "hidden": true, + "cacheVariables": { + "HDF4_BUILD_JAVA": "ON" + }, + "toolset": { + "value": "host=x64", + "strategy": "external" + } + }, + { + "name": "ci-x64-Debug-MSVC", + "description": "MSVC for x64 (Debug)", + "hidden": true, + "inherits": [ + "ci-base", + "ci-x64", + "ci-Debug", + "ci-MSVC" + ] + }, + { + "name": "ci-x64-Release-MSVC", + "description": "MSVC for x64 (Release)", + "hidden": true, + "inherits": [ + "ci-base", + "ci-x64", + "ci-Release", + "ci-MSVC" + ] + }, + { + "name": "ci-x64-Debug-Clang", + "description": "Clang/LLVM for x64 (Debug)", + "hidden": true, + "inherits": [ + "ci-base", + "ci-x64", + "ci-Debug", + "ci-Clang" + ] + }, + { + "name": "ci-x64-Release-Clang", + "description": "Clang/LLVM for x64 (Release)", + "hidden": true, + "inherits": [ + "ci-base", + "ci-x64", + "ci-Release", + "ci-Clang" + ] + }, + { + "name": "ci-x64-Debug-GNUC", + "description": "GNUC for x64 (Debug)", + "hidden": true, + "inherits": [ + "ci-base", + "ci-x64", + "ci-Debug", + "ci-GNUC" + ] + }, + { + "name": "ci-x64-Release-GNUC", + "description": "GNUC for x64 (Release)", + "hidden": true, + "inherits": [ + "ci-base", + "ci-x64", + "ci-Release", + "ci-GNUC" + ] + }, + { + "name": "ci-x64-Debug-Intel", + "description": "Intel for x64 (Debug)", + "hidden": true, + "inherits": [ + "ci-base", + "ci-x64", + "ci-Debug", + "ci-Intel" + ] + }, + { + "name": "ci-x64-Release-Intel", + "description": "Intel for x64 (Release)", + "hidden": true, + "inherits": [ + "ci-base", + "ci-x64", + "ci-Release", + "ci-Intel" + ] + }, + { + "name": "ci-x64-Debug-MSVC-asan", + "description": "x64-Debug-MSVC with /fsanitize=address", + "hidden": true, + "inherits": "ci-x64-Debug-MSVC", + "cacheVariables": { + "USE_SANITIZER": "Address", + "HDF4_ENABLE_SANITIZERS": "ON" + } + }, + { + "name": "ci-x64-Debug-GNUC-asan", + "hidden": true, + "inherits": "ci-x64-Debug-GNUC", + "cacheVariables": { + "USE_SANITIZER": "Address", + "HDF4_ENABLE_SANITIZERS": "ON" + } + }, + { + "name": "ci-x64-Debug-GNUC-tsan", + "hidden": true, + "inherits": "ci-x64-Debug-GNUC", + "cacheVariables": { + "USE_SANITIZER": "Thread", + "HDF4_ENABLE_SANITIZERS": "ON" + } + }, + { + "name": "ci-x64-Debug-GNUC-lsan", + "hidden": true, + "inherits": "ci-x64-Debug-GNUC", + "cacheVariables": { + "USE_SANITIZER": "Leak", + "HDF4_ENABLE_SANITIZERS": "ON" + } + }, + { + "name": "ci-x64-Debug-GNUC-ubsan", + "hidden": true, + "inherits": "ci-x64-Debug-GNUC", + "cacheVariables": { + "USE_SANITIZER": "Undefined", + "HDF4_ENABLE_SANITIZERS": "ON" + } + } + ], + "buildPresets": [ + { + "name": "ci-base", + "configurePreset": "ci-base", + "hidden": true, + "verbose": true, + "jobs": 8 + }, + { + "name": "ci-x64-Debug-MSVC", + "configurePreset": "ci-x64-Debug-MSVC", + "hidden": true, + "inherits": [ + "ci-base" + ], + "configuration": "Debug" + }, + { + "name": "ci-x64-Release-MSVC", + "configurePreset": "ci-x64-Release-MSVC", + "hidden": true, + "inherits": [ + "ci-base" + ], + "configuration": "RelWithDebInfo" + }, + { + "name": "ci-x64-Debug-Clang", + "configurePreset": "ci-x64-Debug-Clang", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Release-Clang", + "configurePreset": "ci-x64-Release-Clang", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Debug-GNUC", + "configurePreset": "ci-x64-Debug-GNUC", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Release-GNUC", + "configurePreset": "ci-x64-Release-GNUC", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Debug-Intel", + "configurePreset": "ci-x64-Debug-Intel", + "hidden": true, + "inherits": [ + "ci-base" + ], + "configuration": "Debug" + }, + { + "name": "ci-x64-Release-Intel", + "configurePreset": "ci-x64-Release-Intel", + "hidden": true, + "inherits": [ + "ci-base" + ], + "configuration": "RelWithDebInfo" + }, + { + "name": "ci-x64-Debug-MSVC-asan", + "configurePreset": "ci-x64-Debug-MSVC-asan", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Debug-GNUC-asan", + "configurePreset": "ci-x64-Debug-GNUC-asan", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Debug-GNUC-tsan", + "configurePreset": "ci-x64-Debug-GNUC-tsan", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Debug-GNUC-lsan", + "configurePreset": "ci-x64-Debug-GNUC-lsan", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Debug-GNUC-ubsan", + "configurePreset": "ci-x64-Debug-GNUC-ubsan", + "hidden": true, + "inherits": [ + "ci-base" + ] + } + ], + "testPresets": [ + { + "name": "ci-base", + "configurePreset": "ci-base", + "output": { + "outputOnFailure": false, + "shortProgress": true, + "verbosity": "verbose" + }, + "hidden": true, + "execution": { + "noTestsAction": "error", + "timeout": 180, + "jobs": 8 + } + }, + { + "name": "ci-x64-Debug-MSVC", + "configurePreset": "ci-x64-Debug-MSVC", + "hidden": true, + "inherits": [ + "ci-base" + ], + "configuration": "Debug" + }, + { + "name": "ci-x64-Release-MSVC", + "configurePreset": "ci-x64-Release-MSVC", + "hidden": true, + "inherits": [ + "ci-base" + ], + "configuration": "RelWithDebInfo" + }, + { + "name": "ci-x64-Debug-Clang", + "configurePreset": "ci-x64-Debug-Clang", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Release-Clang", + "configurePreset": "ci-x64-Release-Clang", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Debug-GNUC", + "configurePreset": "ci-x64-Debug-GNUC", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Release-GNUC", + "configurePreset": "ci-x64-Release-GNUC", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Debug-Intel", + "configurePreset": "ci-x64-Debug-Intel", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Release-Intel", + "configurePreset": "ci-x64-Release-Intel", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Debug-MSVC-asan", + "configurePreset": "ci-x64-Debug-MSVC-asan", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Debug-GNUC-asan", + "configurePreset": "ci-x64-Debug-GNUC-asan", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Debug-GNUC-tsan", + "configurePreset": "ci-x64-Debug-GNUC-tsan", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Debug-GNUC-lsan", + "configurePreset": "ci-x64-Debug-GNUC-lsan", + "hidden": true, + "inherits": [ + "ci-base" + ] + }, + { + "name": "ci-x64-Debug-GNUC-ubsan", + "configurePreset": "ci-x64-Debug-GNUC-ubsan", + "inherits": [ + "ci-base" + ] + } + ], + "packagePresets": [ + { + "name": "ci-base", + "hidden": true, + "output": { + "verbose": true + } + }, + { + "name": "ci-x64-Release-MSVC", + "configurePreset": "ci-x64-Release-MSVC", + "hidden": true, + "inherits": "ci-base", + "generators": [ + "ZIP" + ], + "configurations": ["RelWithDebInfo"] + }, + { + "name": "ci-x64-Release-Clang", + "configurePreset": "ci-x64-Release-Clang", + "hidden": true, + "inherits": "ci-base", + "generators": [ + "TGZ" + ] + }, + { + "name": "ci-x64-Release-GNUC", + "configurePreset": "ci-x64-Release-GNUC", + "hidden": true, + "inherits": "ci-base", + "generators": [ + "TGZ" + ] + }, + { + "name": "ci-x64-Release-Intel", + "configurePreset": "ci-x64-Release-Intel", + "hidden": true, + "inherits": "ci-base", + "generators": [ + "TGZ" + ] + } + ] +} + diff --git a/HDF4Examples/config/cmake/CMakeFindJavaCommon.cmake b/HDF4Examples/config/cmake/CMakeFindJavaCommon.cmake new file mode 100644 index 0000000000..528791d273 --- /dev/null +++ b/HDF4Examples/config/cmake/CMakeFindJavaCommon.cmake @@ -0,0 +1,30 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See https://cmake.org/licensing for details. + + +# Do not include this module directly from code outside CMake! +set(_JAVA_HOME "") +if(JAVA_HOME AND IS_DIRECTORY "${JAVA_HOME}") + set(_JAVA_HOME "${JAVA_HOME}") + set(_JAVA_HOME_EXPLICIT 1) +else() + set(_ENV_JAVA_HOME "") + if(DEFINED ENV{JAVA_HOME}) + file(TO_CMAKE_PATH "$ENV{JAVA_HOME}" _ENV_JAVA_HOME) + endif() + if(_ENV_JAVA_HOME AND IS_DIRECTORY "${_ENV_JAVA_HOME}") + set(_JAVA_HOME "${_ENV_JAVA_HOME}") + set(_JAVA_HOME_EXPLICIT 1) + else() + set(_CMD_JAVA_HOME "") + if(APPLE AND EXISTS "/usr/libexec/java_home") + execute_process(COMMAND /usr/libexec/java_home + OUTPUT_VARIABLE _CMD_JAVA_HOME OUTPUT_STRIP_TRAILING_WHITESPACE) + endif() + if(_CMD_JAVA_HOME AND IS_DIRECTORY "${_CMD_JAVA_HOME}") + set(_JAVA_HOME "${_CMD_JAVA_HOME}") + set(_JAVA_HOME_EXPLICIT 0) + endif() + unset(_CMD_JAVA_HOME) + endif() + unset(_ENV_JAVA_HOME) +endif() diff --git a/HDF4Examples/config/cmake/CTestCustom.cmake b/HDF4Examples/config/cmake/CTestCustom.cmake new file mode 100644 index 0000000000..50253fdb70 --- /dev/null +++ b/HDF4Examples/config/cmake/CTestCustom.cmake @@ -0,0 +1,18 @@ +set (CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS 1500) + +set (CTEST_CUSTOM_WARNING_EXCEPTION + ${CTEST_CUSTOM_WARNING_EXCEPTION} + "SZIP.src.*:[ \t]*warning" + "jpeg.src.*:[ \t]*warning" + "POSIX name for this item is deprecated" + "disabling jobserver mode" + "config.cmake.xlatefile.c" +) + + +set (CTEST_CUSTOM_MEMCHECK_IGNORE + ${CTEST_CUSTOM_MEMCHECK_IGNORE} + HDF_FORTRAN_EXAMPLES-clearall-objects + MFHDF_EXAMPLES-clearall-objects + MFHDF_TEST-clearall-objects +) \ No newline at end of file diff --git a/HDF4Examples/config/cmake/HDF4UseFortran.cmake b/HDF4Examples/config/cmake/HDF4UseFortran.cmake new file mode 100644 index 0000000000..0a7c04291a --- /dev/null +++ b/HDF4Examples/config/cmake/HDF4UseFortran.cmake @@ -0,0 +1,192 @@ +# +# This file provides functions for Fortran support. +# +#------------------------------------------------------------------------------- +enable_language (Fortran) +set (HDF_PREFIX "H4") + +#------------------------------------------------------------------------------- +# Fix Fortran flags if we are compiling statically on Windows using +# Windows_MT.cmake from config/cmake/UserMacros +#------------------------------------------------------------------------------- +if (BUILD_STATIC_CRT_LIBS) + TARGET_STATIC_CRT_FLAGS () +endif () + +#----------------------------------------------------------------------------- +# Detect name mangling convention used between Fortran and C +#----------------------------------------------------------------------------- +include (FortranCInterface) +FortranCInterface_HEADER ( + ${CMAKE_BINARY_DIR}/F77Mangle.h + MACRO_NAMESPACE "H4_F77_" + SYMBOL_NAMESPACE "H4_F77_" + SYMBOLS mysub mymod:my_sub +) + +file (STRINGS ${CMAKE_BINARY_DIR}/F77Mangle.h CONTENTS REGEX "H4_F77_GLOBAL\\(.*,.*\\) +(.*)") +string (REGEX MATCH "H4_F77_GLOBAL\\(.*,.*\\) +(.*)" RESULT ${CONTENTS}) +set (H4_F77_FUNC "H4_F77_FUNC(name,NAME) ${CMAKE_MATCH_1}") + +file (STRINGS ${CMAKE_BINARY_DIR}/F77Mangle.h CONTENTS REGEX "H4_F77_GLOBAL_\\(.*,.*\\) +(.*)") +string (REGEX MATCH "H4_F77_GLOBAL_\\(.*,.*\\) +(.*)" RESULT ${CONTENTS}) +set (H4_F77_FUNC_ "H4_F77_FUNC_(name,NAME) ${CMAKE_MATCH_1}") + +#----------------------------------------------------------------------------- +# The provided CMake Fortran macros don't provide a general check function +# so this one is used for a sizeof test. +#----------------------------------------------------------------------------- +macro (CHECK_FORTRAN_FEATURE FUNCTION CODE VARIABLE) + message (STATUS "Testing Fortran ${FUNCTION}") + if (HDF4_REQUIRED_LIBRARIES) + set (CHECK_FUNCTION_EXISTS_ADD_LIBRARIES + "-DLINK_LIBRARIES:STRING=${HDF4_REQUIRED_LIBRARIES}") + else () + set (CHECK_FUNCTION_EXISTS_ADD_LIBRARIES) + endif () + file (WRITE + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f + "${CODE}" + ) + TRY_COMPILE (RESULT_VAR + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testFortranCompiler.f + CMAKE_FLAGS "${CHECK_FUNCTION_EXISTS_ADD_LIBRARIES}" + OUTPUT_VARIABLE OUTPUT + ) + +# message ( "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ") +# message ( "Test result ${OUTPUT}") +# message ( "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ") + + if (${RESULT_VAR}) + set (${VARIABLE} 1 CACHE INTERNAL "Have Fortran function ${FUNCTION}") + message (STATUS "Testing Fortran ${FUNCTION} - OK") + file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Determining if the Fortran ${FUNCTION} exists passed with the following output:\n" + "${OUTPUT}\n\n" + ) + else () + message (STATUS "Testing Fortran ${FUNCTION} - Fail") + set (${VARIABLE} 0 CACHE INTERNAL "Have Fortran function ${FUNCTION}") + file (APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the Fortran ${FUNCTION} exists failed with the following output:\n" + "${OUTPUT}\n\n") + endif () +endmacro () + +#----------------------------------------------------------------------------- +# Configure Checks which require Fortran compilation must go in here +# not in the main ConfigureChecks.cmake files, because if the user has +# no Fortran compiler, problems arise. +# +# Be careful with leading spaces here, do not remove them. +#----------------------------------------------------------------------------- + +# Check for Non-standard extension intrinsic function SIZEOF +set (${HDF_PREFIX}_FORTRAN_HAVE_SIZEOF FALSE) +CHECK_FORTRAN_FEATURE(sizeof + " + PROGRAM main + i = sizeof(x) + END PROGRAM + " + ${HDF_PREFIX}_FORTRAN_HAVE_SIZEOF +) + +# Check for F2008 standard intrinsic function C_SIZEOF +set (${HDF_PREFIX}_FORTRAN_HAVE_C_SIZEOF FALSE) +CHECK_FORTRAN_FEATURE(c_sizeof + " + PROGRAM main + USE ISO_C_BINDING + INTEGER(C_INT) :: a + INTEGER(C_SIZE_T) :: result + result = c_sizeof(a) + END PROGRAM + " + ${HDF_PREFIX}_FORTRAN_HAVE_C_SIZEOF +) + +# Check for F2008 standard intrinsic function STORAGE_SIZE +CHECK_FORTRAN_FEATURE(storage_size + " + PROGRAM main + INTEGER :: a + INTEGER :: result + result = storage_size(a) + END PROGRAM + " + ${HDF_PREFIX}_FORTRAN_HAVE_STORAGE_SIZE +) + +# Check for F2008 standard intrinsic module "ISO_FORTRAN_ENV" +set (${HDF_PREFIX}_HAVE_ISO_FORTRAN_ENV FALSE) +CHECK_FORTRAN_FEATURE(ISO_FORTRAN_ENV + " + PROGRAM main + USE, INTRINSIC :: ISO_FORTRAN_ENV + END PROGRAM + " + ${HDF_PREFIX}_HAVE_ISO_FORTRAN_ENV +) + +set (${HDF_PREFIX}_FORTRAN_DEFAULT_REAL_NOT_DOUBLE FALSE) +CHECK_FORTRAN_FEATURE(RealIsNotDouble + " + MODULE type_mod + INTERFACE h4t + MODULE PROCEDURE h4t_real + MODULE PROCEDURE h4t_dble + END INTERFACE + CONTAINS + SUBROUTINE h4t_real(r) + REAL :: r + END SUBROUTINE h4t_real + SUBROUTINE h4t_dble(d) + DOUBLE PRECISION :: d + END SUBROUTINE h4t_dble + END MODULE type_mod + PROGRAM main + USE type_mod + REAL :: r + DOUBLE PRECISION :: d + CALL h4t(r) + CALL h4t(d) + END PROGRAM main + " + ${HDF_PREFIX}_FORTRAN_DEFAULT_REAL_NOT_DOUBLE +) + +#----------------------------------------------------------------------------- +# Checks if the ISO_C_BINDING module meets all the requirements +#----------------------------------------------------------------------------- +set (${HDF_PREFIX}_FORTRAN_HAVE_ISO_C_BINDING FALSE) +CHECK_FORTRAN_FEATURE(iso_c_binding + " + PROGRAM main + USE iso_c_binding + IMPLICIT NONE + TYPE(C_PTR) :: ptr + TYPE(C_FUNPTR) :: funptr + INTEGER(C_INT64_T) :: c_int64_type + CHARACTER(LEN=80, KIND=c_char), TARGET :: ichr + ptr = C_LOC(ichr(1:1)) + END PROGRAM + " + ${HDF_PREFIX}_FORTRAN_HAVE_ISO_C_BINDING +) + +#----------------------------------------------------------------------------- +# Add debug information (intel Fortran : JB) +#----------------------------------------------------------------------------- +if (CMAKE_Fortran_COMPILER MATCHES ifort) + if (WIN32) + set (CMAKE_Fortran_FLAGS_DEBUG "/debug:full /dbglibs " CACHE STRING "flags" FORCE) + set (CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG" CACHE STRING "flags" FORCE) + endif () +endif () + +if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0) + set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch") +endif () diff --git a/HDF4Examples/config/cmake/HDFExampleMacros.cmake b/HDF4Examples/config/cmake/HDFExampleMacros.cmake new file mode 100644 index 0000000000..b549da22ee --- /dev/null +++ b/HDF4Examples/config/cmake/HDFExampleMacros.cmake @@ -0,0 +1,331 @@ +#------------------------------------------------------------------------------- +macro (BASIC_SETTINGS varname) + string (TOUPPER ${varname} EXAMPLE_PACKAGE_VARNAME) + string (TOLOWER ${varname} EXAMPLE_VARNAME) + set (H4${EXAMPLE_PACKAGE_VARNAME}_PACKAGE "h4${EXAMPLE_VARNAME}") + set (H4${EXAMPLE_PACKAGE_VARNAME}_PACKAGE_NAME "h4${EXAMPLE_VARNAME}") + string (TOUPPER ${H4${EXAMPLE_PACKAGE_VARNAME}_PACKAGE_NAME} EXAMPLE_PACKAGE_NAME) + string (TOLOWER ${H4${EXAMPLE_PACKAGE_VARNAME}_PACKAGE_NAME} EXAMPLE_NAME) + set (CMAKE_NO_SYSTEM_FROM_IMPORTED 1) + + #----------------------------------------------------------------------------- + # Define some CMake variables for use later in the project + #----------------------------------------------------------------------------- + set (${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR ${${EXAMPLE_PACKAGE_NAME}_SOURCE_DIR}/config/cmake) + set (${EXAMPLE_PACKAGE_NAME}_SRC_DIR ${${EXAMPLE_PACKAGE_NAME}_SOURCE_DIR}/src) + + #----------------------------------------------------------------------------- + # Setup output Directories + #----------------------------------------------------------------------------- + SET_HDF_OUTPUT_DIRS(${EXAMPLE_PACKAGE_NAME}) + + #----------------------------------------------------------------------------- + # Option to use Shared/Static libs, default is static + #----------------------------------------------------------------------------- + set (LIB_TYPE STATIC) + if (BUILD_SHARED_LIBS) + set (LIB_TYPE SHARED) + endif () + set (CMAKE_POSITION_INDEPENDENT_CODE ON) + + if (MSVC) + set (CMAKE_MFC_FLAG 0) + endif () + + set (CMAKE_C_STANDARD 99) + set (CMAKE_C_STANDARD_REQUIRED TRUE) + + if (HDF_BUILD_CPP_LIB) + ENABLE_LANGUAGE (CXX) + + set (CMAKE_CXX_STANDARD 98) + set (CMAKE_CXX_STANDARD_REQUIRED TRUE) + set (CMAKE_CXX_EXTENSIONS OFF) + endif () + + #----------------------------------------------------------------------------- + # Compiler specific flags : Shouldn't there be compiler tests for these + #----------------------------------------------------------------------------- + if (CMAKE_COMPILER_IS_GNUCC) + set (CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS} -std=c99 -fomit-frame-pointer -finline-functions -fno-common") + endif () + if (CMAKE_CXX_COMPILER_LOADED AND CMAKE_COMPILER_IS_GNUCXX) + set (CMAKE_CXX_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_CXX_FLAGS} -fomit-frame-pointer -finline-functions -fno-common") + endif () + + #----------------------------------------------------------------------------- + # This is in here to help some of the GCC based IDES like Eclipse + # and code blocks parse the compiler errors and warnings better. + #----------------------------------------------------------------------------- + if (CMAKE_COMPILER_IS_GNUCC) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fmessage-length=0") + endif () + if (CMAKE_CXX_COMPILER_LOADED AND CMAKE_COMPILER_IS_GNUCXX) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmessage-length=0") + endif () + + #----------------------------------------------------------------------------- + # Option to allow the user to disable compiler warnings + #----------------------------------------------------------------------------- + option (HDF_DISABLE_COMPILER_WARNINGS "Disable compiler warnings" OFF) + if (HDF_DISABLE_COMPILER_WARNINGS) + # MSVC uses /w to suppress warnings. It also complains if another + # warning level is given, so remove it. + if (MSVC) + set (HDF_WARNINGS_BLOCKED 1) + string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /w") + if (CMAKE_CXX_COMPILER_LOADED AND CMAKE_COMPILER_IS_GNUCXX) + string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w") + endif () + endif () + if (WIN32) + add_definitions (-D_CRT_SECURE_NO_WARNINGS) + endif () + # Borland uses -w- to suppress warnings. + if (BORLAND) + set (HDF_WARNINGS_BLOCKED 1) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-") + endif () + + # Most compilers use -w to suppress warnings. + if (NOT HDF_WARNINGS_BLOCKED) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") + if (CMAKE_CXX_COMPILER_LOADED AND CMAKE_COMPILER_IS_GNUCXX) + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w") + endif () + endif () + endif () + + #----------------------------------------------------------------------------- + # Set includes needed for build + #----------------------------------------------------------------------------- + set (${EXAMPLE_PACKAGE_NAME}_INCLUDES_BUILD_TIME + ${${EXAMPLE_PACKAGE_NAME}_SRC_DIR} ${${EXAMPLE_PACKAGE_NAME}_BINARY_DIR} + ) + + #----------------------------------------------------------------------------- + # Option to build JAVA examples + #----------------------------------------------------------------------------- + option (HDF_BUILD_JAVA "Build JAVA support" OFF) + if (HDF_BUILD_JAVA) + find_package (Java) + INCLUDE_DIRECTORIES ( + ${JAVA_INCLUDE_PATH} + ${JAVA_INCLUDE_PATH2} + ) + + include (${${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR}/UseJava.cmake) + endif () +endmacro () + +macro (HDF4_SUPPORT) + set (CMAKE_MODULE_PATH ${${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR} ${CMAKE_MODULE_PATH}) + option (USE_SHARED_LIBS "Use Shared Libraries" ON) + + if (NOT H4EX_HDF4_HEADER) + if (USE_SHARED_LIBS) + set (FIND_HDF_COMPONENTS C shared) + else () + set (FIND_HDF_COMPONENTS C static) + set (HDF_BUILD_JAVA OFF CACHE BOOL "Build Java support" FORCE) + message (STATUS "Using static HDF4 - disable build of Java examples") + endif () + if (HDF_BUILD_FORTRAN) + set (FIND_HDF_COMPONENTS ${FIND_HDF_COMPONENTS} Fortran) + endif () + if (HDF_BUILD_JAVA) + set (FIND_HDF_COMPONENTS ${FIND_HDF_COMPONENTS} Java) + set (HDF4_Java_FOUND 1) #default setting for 4.2.14 and earlier + endif () + message (STATUS "HDF4 find comps: ${FIND_HDF_COMPONENTS}") + set (SEARCH_PACKAGE_NAME ${HDF4_PACKAGE_NAME}) + + find_package (HDF4 NAMES ${SEARCH_PACKAGE_NAME} COMPONENTS ${FIND_HDF_COMPONENTS}) + message (STATUS "HDF4 C libs:${HDF4_FOUND} static:${HDF4_static_C_FOUND} and shared:${HDF4_shared_C_FOUND}") + message (STATUS "HDF4 Fortran libs: static:${HDF4_static_Fortran_FOUND} and shared:${HDF4_shared_Fortran_FOUND}") + message (STATUS "HDF4 Java libs: ${HDF4_Java_FOUND}") + if (HDF4_FOUND) + if (USE_SHARED_LIBS) + if (NOT TARGET ${HDF4_NAMESPACE}hdp-shared) + add_executable (${HDF4_NAMESPACE}hdp-shared IMPORTED) + endif () + set (H4EX_HDF4_DUMP_EXECUTABLE $) + else () + if (NOT TARGET ${HDF4_NAMESPACE}hdp) + add_executable (${HDF4_NAMESPACE}hdp IMPORTED) + endif() + set (H4EX_HDF4_DUMP_EXECUTABLE $) + endif() + + if (NOT HDF4_static_C_FOUND AND NOT HDF4_shared_C_FOUND) + #find library from non-dual-binary package + set (FIND_HDF_COMPONENTS C) + if (HDF_BUILD_FORTRAN) + set (FIND_HDF_COMPONENTS ${FIND_HDF_COMPONENTS} Fortran) + endif () + if (HDF_BUILD_JAVA) + set (FIND_HDF_COMPONENTS ${FIND_HDF_COMPONENTS} Java) + endif () + message (STATUS "HDF4 find comps: ${FIND_HDF_COMPONENTS}") + + find_package (HDF4 NAMES ${SEARCH_PACKAGE_NAME} COMPONENTS ${FIND_HDF_COMPONENTS}) + message (STATUS "HDF4 libs:${HDF4_FOUND} C:${HDF4_C_FOUND} Fortran:${HDF4_Fortran_FOUND} Java:${HDF4_Java_FOUND}") + set (H4EX_HDF4_LINK_LIBS ${H4EX_HDF4_LINK_LIBS} ${HDF4_LIBRARIES}) + if (HDF4_BUILD_SHARED_LIBS) + add_definitions (-DH4_BUILT_AS_DYNAMIC_LIB) + else () + add_definitions (-DH4_BUILT_AS_STATIC_LIB) + endif () + if (USE_SHARED_LIBS AND WIN32) + set_property (TARGET ${HDF4_NAMESPACE}hdp PROPERTY IMPORTED_LOCATION "${HDF4_TOOLS_DIR}/hdpdll") + else () + set_property (TARGET ${HDF4_NAMESPACE}hdp PROPERTY IMPORTED_LOCATION "${HDF4_TOOLS_DIR}/hdp") + endif () + if (HDF_BUILD_JAVA) + set (CMAKE_JAVA_INCLUDE_PATH "${CMAKE_JAVA_INCLUDE_PATH};${HDF4_JAVA_INCLUDE_DIRS}") + message (STATUS "HDF4 jars:${HDF4_JAVA_INCLUDE_DIRS}") + endif () + set (H4EX_HDF4_DUMP_EXECUTABLE $) + else () + if (USE_SHARED_LIBS AND HDF4_shared_C_FOUND) + set (H4EX_HDF4_LINK_LIBS ${H4EX_HDF4_LINK_LIBS} ${HDF4_C_SHARED_LIBRARY}) + set (HDF4_LIBRARY_PATH ${PACKAGE_PREFIX_DIR}/lib) + set_property (TARGET ${HDF4_NAMESPACE}hdp-shared PROPERTY IMPORTED_LOCATION "${HDF4_TOOLS_DIR}/hdp-shared") + else () + set (H4EX_HDF4_LINK_LIBS ${H4EX_HDF4_LINK_LIBS} ${HDF4_C_STATIC_LIBRARY}) + set_property (TARGET ${HDF4_NAMESPACE}hdp PROPERTY IMPORTED_LOCATION "${HDF4_TOOLS_DIR}/hdp") + endif () + if (HDF_BUILD_FORTRAN AND ${HDF4_BUILD_FORTRAN}) + if (BUILD_SHARED_LIBS AND HDF4_shared_Fortran_FOUND) + set (H4EX_HDF4_LINK_LIBS ${H4EX_HDF4_LINK_LIBS} ${HDF4_FORTRAN_SHARED_LIBRARY}) + elseif (HDF4_static_Fortran_FOUND) + set (H4EX_HDF4_LINK_LIBS ${H4EX_HDF4_LINK_LIBS} ${HDF4_FORTRAN_STATIC_LIBRARY}) + else () + set (HDF_BUILD_FORTRAN OFF CACHE BOOL "Build FORTRAN support" FORCE) + message (STATUS "HDF4 Fortran libs not found - disable build of Fortran examples") + endif () + else () + set (HDF_BUILD_FORTRAN OFF CACHE BOOL "Build FORTRAN support" FORCE) + message (STATUS "HDF4 Fortran libs not found - disable build of Fortran examples") + endif () + if (HDF_BUILD_JAVA) + if (${HDF4_BUILD_JAVA} AND HDF4_Java_FOUND) + set (CMAKE_JAVA_INCLUDE_PATH "${CMAKE_JAVA_INCLUDE_PATH};${HDF4_JAVA_INCLUDE_DIRS}") + set (H4EX_JAVA_LIBRARY ${HDF4_JAVA_LIBRARY}) + set (H4EX_JAVA_LIBRARIES ${HDF4_JAVA_LIBRARY}) + message (STATUS "HDF4 jars:${HDF4_JAVA_INCLUDE_DIRS}}") + else () + set (HDF_BUILD_JAVA OFF CACHE BOOL "Build Java support" FORCE) + message (STATUS "HDF4 Java libs not found - disable build of Java examples") + endif () + else () + set (HDF_BUILD_JAVA OFF CACHE BOOL "Build Java support" FORCE) + endif () + endif () + else () + find_package (HDF4) # Legacy find + #Legacy find_package does not set HDF4_TOOLS_DIR, so we set it here + set (HDF4_TOOLS_DIR ${HDF4_LIBRARY_DIRS}/../bin) + #Legacy find_package does not set HDF4_BUILD_SHARED_LIBS, so we set it here + if (USE_SHARED_LIBS AND EXISTS "${HDF4_LIBRARY_DIRS}/libhdf4.so") + set (HDF4_BUILD_SHARED_LIBS 1) + else () + set (HDF4_BUILD_SHARED_LIBS 0) + endif () + set (H4EX_HDF4_LINK_LIBS ${H4EX_HDF4_LINK_LIBS} ${HDF4_LIBRARIES}) + add_executable (${HDF4_NAMESPACE}hdp IMPORTED) + set_property (TARGET ${HDF4_NAMESPACE}hdp PROPERTY IMPORTED_LOCATION "${HDF4_TOOLS_DIR}/hdp") + set (H4EX_HDF4_DUMP_EXECUTABLE $) + endif () + + set (HDF4_PACKAGE_NAME ${SEARCH_PACKAGE_NAME}) + + if (HDF4_FOUND) + set (H4EX_HDF4_INCLUDE_DIRS ${HDF4_INCLUDE_DIR}) + set (H4EX_HDF4_HAVE_HDF_H 1) + set (H4EX_HDF4_HAVE_HDF4 1) + set (H4EX_HDF4_HEADER "hdf.h") + message (STATUS "HDF4-${HDF4_VERSION_STRING} found: INC=${HDF4_INCLUDE_DIR} TOOLS=${HDF4_TOOLS_DIR}") + else () + message (FATAL_ERROR " HDF4 is Required for HDF4 Examples") + endif () + else () + # This project is being called from within another and HDF4 is already configured + set (H4EX_HDF4_HAVE_HDF_H 1) + set (H4EX_HDF4_HAVE_HDF4 1) + set (H4EX_HDF4_LINK_LIBS ${H4EX_HDF4_LINK_LIBS} ${HDF4_LINK_LIBS}) + endif () + if (HDF_BUILD_FORTRAN) + list (APPEND H4EX_HDF4_INCLUDE_DIRS ${HDF4_INCLUDE_DIR_FORTRAN}) + endif () + message (STATUS "HDF4 link libs: ${H4EX_HDF4_LINK_LIBS} Includes: ${H4EX_HDF4_INCLUDE_DIRS}") + + if (USE_SHARED_LIBS) + set (H4_LIB_TYPE SHARED) + else () + set (H4_LIB_TYPE STATIC) + endif () +endmacro () + +#------------------------------------------------------------------------------- +macro (SET_HDF_BUILD_TYPE) + get_property (_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if (_isMultiConfig) + # HDF_CFG_BUILD_TYPE is used in the Fortran install commands for the build location of the .mod files + set (HDF_CFG_BUILD_TYPE \${CMAKE_INSTALL_CONFIG_NAME}) + if (CMAKE_BUILD_TYPE) + # set the default to the specified command line define + set (HDF_CFG_NAME ${CMAKE_BUILD_TYPE}) + else () + # set the default to the MultiConfig variable + set (HDF_CFG_NAME "$") + endif () + else () + set (HDF_CFG_BUILD_TYPE ".") + if (CMAKE_BUILD_TYPE) + set (HDF_CFG_NAME ${CMAKE_BUILD_TYPE}) + else () + set (HDF_CFG_NAME "Release") + endif () + endif () +endmacro () + +#------------------------------------------------------------------------------- +macro (TARGET_C_PROPERTIES wintarget libtype) + target_compile_options(${wintarget} PRIVATE + "$<$:${WIN_COMPILE_FLAGS}>" + ) + if(MSVC) + set_property(TARGET ${wintarget} APPEND PROPERTY LINK_FLAGS "${WIN_LINK_FLAGS}") + endif() +endmacro () + +macro (HDFTEST_COPY_FILE src dest target) + add_custom_command( + OUTPUT "${dest}" + COMMAND "${CMAKE_COMMAND}" + ARGS -E copy_if_different "${src}" "${dest}" + DEPENDS "${src}" + ) + list (APPEND ${target}_list "${dest}") +endmacro () + +macro (ADD_H4_FLAGS h4_flag_var infile) + file (STRINGS ${infile} TEST_FLAG_STREAM) + #message (TRACE "TEST_FLAG_STREAM=${TEST_FLAG_STREAM}") + list (LENGTH TEST_FLAG_STREAM len_flag) + if (len_flag GREATER 0) + math (EXPR _FP_LEN "${len_flag} - 1") + foreach (line RANGE 0 ${_FP_LEN}) + list (GET TEST_FLAG_STREAM ${line} str_flag) + string (REGEX REPLACE "^#.*" "" str_flag "${str_flag}") + #message (TRACE "str_flag=${str_flag}") + if (str_flag) + list (APPEND ${h4_flag_var} "${str_flag}") + endif () + endforeach () + endif () + #message (TRACE "h4_flag_var=${${h4_flag_var}}") +endmacro () diff --git a/HDF4Examples/config/cmake/HDFMacros.cmake b/HDF4Examples/config/cmake/HDFMacros.cmake new file mode 100644 index 0000000000..08c93ea65a --- /dev/null +++ b/HDF4Examples/config/cmake/HDFMacros.cmake @@ -0,0 +1,215 @@ +# + +#------------------------------------------------------------------------------- +# Setup output Directories +#----------------------------------------------------------------------------- +macro (SET_HDF_OUTPUT_DIRS package_prefix) + if (NOT ${package_prefix}_EXTERNALLY_CONFIGURED) + set (CMAKE_RUNTIME_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all Executables." + ) + set (CMAKE_LIBRARY_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all Libraries" + ) + set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all static libraries." + ) + set (CMAKE_Fortran_MODULE_DIRECTORY + ${PROJECT_BINARY_DIR}/mod CACHE PATH "Single Directory for all fortran modules." + ) + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(_isMultiConfig) + set (CMAKE_TEST_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${HDF_CFG_NAME}) + set (CMAKE_PDB_OUTPUT_DIRECTORY + ${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all pdb files." + ) + else () + set (CMAKE_TEST_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + endif () + else () + # if we are externally configured, but the project uses old cmake scripts + # this may not be set and some utilities may fail + if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) + set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) + endif () + endif () +endmacro () + +#------------------------------------------------------------------------------- +macro (SET_HDF_BUILD_TYPE) + get_property (_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if (_isMultiConfig) + # HDF_CFG_BUILD_TYPE is used in the Fortran install commands for the build location of the .mod files + set (HDF_CFG_BUILD_TYPE \${CMAKE_INSTALL_CONFIG_NAME}) + if (CMAKE_BUILD_TYPE) + # set the default to the specified command line define + set (HDF_CFG_NAME ${CMAKE_BUILD_TYPE}) + else () + # set the default to the MultiConfig variable + set (HDF_CFG_NAME "$") + endif () + else () + set (HDF_CFG_BUILD_TYPE ".") + if (CMAKE_BUILD_TYPE) + set (HDF_CFG_NAME ${CMAKE_BUILD_TYPE}) + else () + set (HDF_CFG_NAME "Release") + endif () + endif () +endmacro () + +#------------------------------------------------------------------------------- +macro (TARGET_C_PROPERTIES wintarget libtype) + target_compile_options(${wintarget} PRIVATE + "$<$:${WIN_COMPILE_FLAGS}>" + "$<$:${WIN_COMPILE_FLAGS}>" + ) + if(MSVC) + set_property(TARGET ${wintarget} APPEND PROPERTY LINK_FLAGS "${WIN_LINK_FLAGS}") + endif() +endmacro () + +macro (HDFTEST_COPY_FILE src dest target) + add_custom_command( + OUTPUT "${dest}" + COMMAND "${CMAKE_COMMAND}" + ARGS -E copy_if_different "${src}" "${dest}" + DEPENDS "${src}" + ) + list (APPEND ${target}_list "${dest}") +endmacro () + +macro (HDF_DIR_PATHS package_prefix) + option (H4EX_USE_GNU_DIRS "TRUE to use GNU Coding Standard install directory variables, FALSE to use historical settings" FALSE) + if (H4EX_USE_GNU_DIRS) + include(GNUInstallDirs) + if (NOT ${package_prefix}_INSTALL_BIN_DIR) + set (${package_prefix}_INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR}) + endif () + if (NOT ${package_prefix}_INSTALL_LIB_DIR) + set (${package_prefix}_INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR}) + endif () + if (NOT ${package_prefix}_INSTALL_JAR_DIR) + set (${package_prefix}_INSTALL_JAR_DIR ${CMAKE_INSTALL_LIBDIR}) + endif () + if (NOT ${package_prefix}_INSTALL_INCLUDE_DIR) + set (${package_prefix}_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}) + endif () + if (NOT ${package_prefix}_INSTALL_MODULE_DIR) + set (${package_prefix}_INSTALL_MODULE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/mod) + endif () + if (NOT ${package_prefix}_INSTALL_DATA_DIR) + set (${package_prefix}_INSTALL_DATA_DIR ${CMAKE_INSTALL_DATADIR}) + endif () + if (NOT ${package_prefix}_INSTALL_CMAKE_DIR) + set (${package_prefix}_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake) + endif () + if (NOT ${package_prefix}_INSTALL_DOC_DIR) + set (${package_prefix}_INSTALL_DOC_DIR ${CMAKE_INSTALL_DOCDIR}) + endif () + message(STATUS "GNU: ${${package_prefix}_INSTALL_DOC_DIR}") + endif () + + if (APPLE) + option (${package_prefix}_BUILD_FRAMEWORKS "TRUE to build as frameworks libraries, FALSE to build according to BUILD_SHARED_LIBS" FALSE) + endif () + + if (NOT ${package_prefix}_INSTALL_BIN_DIR) + set (${package_prefix}_INSTALL_BIN_DIR bin) + endif () + if (NOT ${package_prefix}_INSTALL_LIB_DIR) + if (APPLE) + if (${package_prefix}_BUILD_FRAMEWORKS) + set (${package_prefix}_INSTALL_JAR_DIR ../Java) + else () + set (${package_prefix}_INSTALL_JAR_DIR lib) + endif () + set (${package_prefix}_INSTALL_FMWK_DIR ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) + else () + set (${package_prefix}_INSTALL_JAR_DIR lib) + endif () + set (${package_prefix}_INSTALL_LIB_DIR lib) + endif () + if (NOT ${package_prefix}_INSTALL_INCLUDE_DIR) + set (${package_prefix}_INSTALL_INCLUDE_DIR include) + endif () + if (NOT ${package_prefix}_INSTALL_MODULE_DIR) + set (${package_prefix}_INSTALL_MODULE_DIR mod) + endif () + if (NOT ${package_prefix}_INSTALL_DATA_DIR) + if (NOT MSVC) + if (APPLE) + if (${package_prefix}_BUILD_FRAMEWORKS) + set (${package_prefix}_INSTALL_EXTRA_DIR ../SharedSupport) + else () + set (${package_prefix}_INSTALL_EXTRA_DIR share) + endif () + set (${package_prefix}_INSTALL_FWRK_DIR ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) + endif () + set (${package_prefix}_INSTALL_DATA_DIR share) + else () + set (${package_prefix}_INSTALL_DATA_DIR ".") + endif () + endif () + if (NOT ${package_prefix}_INSTALL_CMAKE_DIR) + set (${package_prefix}_INSTALL_CMAKE_DIR cmake) + endif () + if (NOT ${package_prefix}_INSTALL_DOC_DIR) + set (${package_prefix}_INSTALL_DOC_DIR ${${package_prefix}_INSTALL_DATA_DIR}) + endif () + message(STATUS "Final: ${${package_prefix}_INSTALL_DOC_DIR}") + + # Always use full RPATH, i.e. don't skip the full RPATH for the build tree + set (CMAKE_SKIP_BUILD_RPATH FALSE) + # when building, don't use the install RPATH already + # (but later on when installing) + set (CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE) + # add the automatically determined parts of the RPATH + # which point to directories outside the build tree to the install RPATH + set (CMAKE_BUILD_WITH_INSTALL_RPATH ON) + if (APPLE) + set (CMAKE_INSTALL_NAME_DIR "@rpath") + set (CMAKE_INSTALL_RPATH + "@executable_path/../${${package_prefix}_INSTALL_LIB_DIR}" + "@executable_path/" + "@loader_path/../${${package_prefix}_INSTALL_LIB_DIR}" + "@loader_path/" + ) + else () + set (CMAKE_INSTALL_RPATH "\$ORIGIN/../${${package_prefix}_INSTALL_LIB_DIR}:\$ORIGIN/") + endif () + + if (DEFINED ADDITIONAL_CMAKE_PREFIX_PATH AND EXISTS "${ADDITIONAL_CMAKE_PREFIX_PATH}") + set (CMAKE_PREFIX_PATH ${ADDITIONAL_CMAKE_PREFIX_PATH} ${CMAKE_PREFIX_PATH}) + endif () + + #set the default debug suffix for all library targets + if(NOT CMAKE_DEBUG_POSTFIX) + if (WIN32) + set (CMAKE_DEBUG_POSTFIX "_D") + else () + set (CMAKE_DEBUG_POSTFIX "_debug") + endif () + endif () + + SET_HDF_BUILD_TYPE() + + SET_HDF_OUTPUT_DIRS(${package_prefix}) + + include (FetchContent) +endmacro () + +macro (ADD_H4_FLAGS h4_flag_var infile) + file (STRINGS ${infile} TEST_FLAG_STREAM) + list (LENGTH TEST_FLAG_STREAM len_flag) + if (len_flag GREATER 0) + math (EXPR _FP_LEN "${len_flag} - 1") + foreach (line RANGE 0 ${_FP_LEN}) + list (GET TEST_FLAG_STREAM ${line} str_flag) + string (REGEX REPLACE "^#.*" "" str_flag "${str_flag}") + if (str_flag) + list (APPEND ${h4_flag_var} "${str_flag}") + endif () + endforeach () + endif () +endmacro () diff --git a/HDF4Examples/config/cmake/UseJava.cmake b/HDF4Examples/config/cmake/UseJava.cmake new file mode 100644 index 0000000000..b4af653740 --- /dev/null +++ b/HDF4Examples/config/cmake/UseJava.cmake @@ -0,0 +1,1747 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +UseJava +------- + +This file provides support for ``Java``. It is assumed that +:module:`FindJava` has already been loaded. See :module:`FindJava` for +information on how to load Java into your CMake project. + +Synopsis +^^^^^^^^ + +.. parsed-literal:: + + `Creating and Installing JARS`_ + `add_jar`_ ( [SOURCES] [...] ...) + `install_jar`_ ( DESTINATION [COMPONENT ]) + `install_jni_symlink`_ ( DESTINATION [COMPONENT ]) + + `Header Generation`_ + `create_javah`_ ((TARGET | GENERATED_FILES ) CLASSES ... ...) + + `Exporting JAR Targets`_ + `install_jar_exports`_ (TARGETS ... FILE DESTINATION ...) + `export_jars`_ (TARGETS ... [NAMESPACE ] FILE ) + + `Finding JARs`_ + `find_jar`_ ( NAMES [...] [PATHS [... ENV ]] ...) + + `Creating Java Documentation`_ + `create_javadoc`_ ( (PACKAGES [...] | FILES [...]) ...) + +Creating And Installing JARs +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. _add_jar: + +.. command:: add_jar + + Creates a jar file containing java objects and, optionally, resources:: + + add_jar( + [SOURCES] [...] [...] + [RESOURCES NAMESPACE ... [NAMESPACE ...]... ] + [INCLUDE_JARS [...]] + [ENTRY_POINT ] + [VERSION ] + [MANIFEST ] + [OUTPUT_NAME ] + [OUTPUT_DIR ] + [GENERATE_NATIVE_HEADERS + [DESTINATION (|INSTALL [BUILD ])]] + ) + + This command creates a ``.jar``. It compiles the given + ```` files and adds the given ```` files to + the jar file. Source files can be java files or listing files + (prefixed by ``@``). If only resource files are given then just a jar file + is created. + + ``SOURCES`` + Compiles the specified source files and adds the result in the jar file. + + .. versionadded:: 3.4 + Support for response files, prefixed by ``@``. + + ``RESOURCES`` + .. versionadded:: 3.21 + + Adds the named ```` files to the jar by stripping the source file + path and placing the file beneath ```` within the jar. + + For example:: + + RESOURCES NAMESPACE "/com/my/namespace" "a/path/to/resource.txt" + + results in a resource accessible via ``/com/my/namespace/resource.txt`` + within the jar. + + Resources may be added without adjusting the namespace by adding them to + the list of ``SOURCES`` (original behavior), in this case, resource + paths must be relative to ``CMAKE_CURRENT_SOURCE_DIR``. Adding resources + without using the ``RESOURCES`` parameter in out of source builds will + almost certainly result in confusion. + + .. note:: + + Adding resources via the ``SOURCES`` parameter relies upon a hard-coded + list of file extensions which are tested to determine whether they + compile (e.g. File.java). ``SOURCES`` files which match the extensions + are compiled. Files which do not match are treated as resources. To + include uncompiled resources matching those file extensions use + the ``RESOURCES`` parameter. + + ``INCLUDE_JARS`` + The list of jars are added to the classpath when compiling the java sources + and also to the dependencies of the target. ``INCLUDE_JARS`` also accepts + other target names created by ``add_jar()``. For backwards compatibility, + jar files listed as sources are ignored (as they have been since the first + version of this module). + + ``ENTRY_POINT`` + Defines an entry point in the jar file. + + ``VERSION`` + Adds a version to the target output name. + + The following example will create a jar file with the name + ``shibboleet-1.2.0.jar`` and will create a symlink ``shibboleet.jar`` + pointing to the jar with the version information. + + .. code-block:: cmake + + add_jar(shibboleet shibbotleet.java VERSION 1.2.0) + + ``MANIFEST`` + Defines a custom manifest for the jar. + + ``OUTPUT_NAME`` + Specify a different output name for the target. + + ``OUTPUT_DIR`` + Sets the directory where the jar file will be generated. If not specified, + :variable:`CMAKE_CURRENT_BINARY_DIR` is used as the output directory. + + ``GENERATE_NATIVE_HEADERS`` + .. versionadded:: 3.11 + + Generates native header files for methods declared as native. These files + provide the connective glue that allow your Java and C code to interact. + An INTERFACE target will be created for an easy usage of generated files. + Sub-option ``DESTINATION`` can be used to specify the output directory for + generated header files. + + This option requires, at least, version 1.8 of the JDK. + + For an optimum usage of this option, it is recommended to include module + JNI before any call to ``add_jar()``. The produced target for native + headers can then be used to compile C/C++ sources with the + :command:`target_link_libraries` command. + + .. code-block:: cmake + + find_package(JNI) + add_jar(foo foo.java GENERATE_NATIVE_HEADERS foo-native) + add_library(bar bar.cpp) + target_link_libraries(bar PRIVATE foo-native) + + .. versionadded:: 3.20 + ``DESTINATION`` sub-option now supports the possibility to specify + different output directories for ``BUILD`` and ``INSTALL`` steps. If + ``BUILD`` directory is not specified, a default directory will be used. + + To export the interface target generated by ``GENERATE_NATIVE_HEADERS`` + option, sub-option ``INSTALL`` of ``DESTINATION`` is required: + + .. code-block:: cmake + + add_jar(foo foo.java GENERATE_NATIVE_HEADERS foo-native + DESTINATION INSTALL include) + install(TARGETS foo-native EXPORT native) + install(DIRECTORY "$/" + DESTINATION include) + install(EXPORT native DESTINATION /to/export NAMESPACE foo) + + Some variables can be set to customize the behavior of ``add_jar()`` as well + as the java compiler: + + ``CMAKE_JAVA_COMPILE_FLAGS`` + Specify additional flags to java compiler. + + ``CMAKE_JAVA_INCLUDE_PATH`` + Specify additional paths to the class path. + + ``CMAKE_JNI_TARGET`` + If the target is a JNI library, sets this boolean variable to ``TRUE`` to + enable creation of a JNI symbolic link (see also + :ref:`install_jni_symlink() `). + + ``CMAKE_JAR_CLASSES_PREFIX`` + If multiple jars should be produced from the same java source filetree, + to prevent the accumulation of duplicate class files in subsequent jars, + set/reset ``CMAKE_JAR_CLASSES_PREFIX`` prior to calling the ``add_jar()``: + + .. code-block:: cmake + + set(CMAKE_JAR_CLASSES_PREFIX com/redhat/foo) + add_jar(foo foo.java) + + set(CMAKE_JAR_CLASSES_PREFIX com/redhat/bar) + add_jar(bar bar.java) + + The ``add_jar()`` function sets the following target properties on + ````: + + ``INSTALL_FILES`` + The files which should be installed. This is used by + :ref:`install_jar() `. + ``JNI_SYMLINK`` + The JNI symlink which should be installed. This is used by + :ref:`install_jni_symlink() `. + ``JAR_FILE`` + The location of the jar file so that you can include it. + ``CLASSDIR`` + The directory where the class files can be found. For example to use them + with ``javah``. + ``NATIVE_HEADERS_DIRECTORY`` + .. versionadded:: 3.20 + + The directory where native headers are generated. Defined when option + ``GENERATE_NATIVE_HEADERS`` is specified. + +.. _install_jar: + +.. command:: install_jar + + This command installs the jar file to the given destination:: + + install_jar( ) + install_jar( DESTINATION [COMPONENT ]) + + This command installs the ```` file to the given + ````. It should be called in the same scope as + :ref:`add_jar() ` or it will fail. + + .. versionadded:: 3.4 + The second signature with ``DESTINATION`` and ``COMPONENT`` options. + + ``DESTINATION`` + Specify the directory on disk to which a file will be installed. + + ``COMPONENT`` + Specify an installation component name with which the install rule is + associated, such as "runtime" or "development". + + The ``install_jar()`` command sets the following target properties + on ````: + + ``INSTALL_DESTINATION`` + Holds the ```` as described above, and is used by + :ref:`install_jar_exports() `. + +.. _install_jni_symlink: + +.. command:: install_jni_symlink + + Installs JNI symlinks for target generated by :ref:`add_jar() `:: + + install_jni_symlink( ) + install_jni_symlink( DESTINATION [COMPONENT ]) + + This command installs the ```` JNI symlinks to the given + ````. It should be called in the same scope as + :ref:`add_jar() ` or it will fail. + + .. versionadded:: 3.4 + The second signature with ``DESTINATION`` and ``COMPONENT`` options. + + ``DESTINATION`` + Specify the directory on disk to which a file will be installed. + + ``COMPONENT`` + Specify an installation component name with which the install rule is + associated, such as "runtime" or "development". + + Utilize the following commands to create a JNI symbolic link: + + .. code-block:: cmake + + set(CMAKE_JNI_TARGET TRUE) + add_jar(shibboleet shibbotleet.java VERSION 1.2.0) + install_jar(shibboleet ${LIB_INSTALL_DIR}/shibboleet) + install_jni_symlink(shibboleet ${JAVA_LIB_INSTALL_DIR}) + +Header Generation +^^^^^^^^^^^^^^^^^ + +.. _create_javah: + +.. command:: create_javah + + .. versionadded:: 3.4 + + Generates C header files for java classes:: + + create_javah(TARGET | GENERATED_FILES + CLASSES ... + [CLASSPATH ...] + [DEPENDS ...] + [OUTPUT_NAME |OUTPUT_DIR ] + ) + + .. deprecated:: 3.11 + This command will no longer be supported starting with version 10 of the JDK + due to the `suppression of javah tool `_. + The :ref:`add_jar(GENERATE_NATIVE_HEADERS) ` command should be + used instead. + + Create C header files from java classes. These files provide the connective + glue that allow your Java and C code to interact. + + There are two main signatures for ``create_javah()``. The first signature + returns generated files through variable specified by the ``GENERATED_FILES`` + option. For example: + + .. code-block:: cmake + + create_javah(GENERATED_FILES files_headers + CLASSES org.cmake.HelloWorld + CLASSPATH hello.jar + ) + + The second signature for ``create_javah()`` creates a target which + encapsulates header files generation. E.g. + + .. code-block:: cmake + + create_javah(TARGET target_headers + CLASSES org.cmake.HelloWorld + CLASSPATH hello.jar + ) + + Both signatures share same options. + + ``CLASSES`` + Specifies Java classes used to generate headers. + + ``CLASSPATH`` + Specifies various paths to look up classes. Here ``.class`` files, jar + files or targets created by command add_jar can be used. + + ``DEPENDS`` + Targets on which the javah target depends. + + ``OUTPUT_NAME`` + Concatenates the resulting header files for all the classes listed by + option ``CLASSES`` into ````. Same behavior as option ``-o`` of + ``javah`` tool. + + ``OUTPUT_DIR`` + Sets the directory where the header files will be generated. Same behavior + as option ``-d`` of ``javah`` tool. If not specified, + :variable:`CMAKE_CURRENT_BINARY_DIR` is used as the output directory. + +Exporting JAR Targets +^^^^^^^^^^^^^^^^^^^^^ + +.. _install_jar_exports: + +.. command:: install_jar_exports + + .. versionadded:: 3.7 + + Installs a target export file:: + + install_jar_exports(TARGETS ... + [NAMESPACE ] + FILE + DESTINATION [COMPONENT ]) + + This command installs a target export file ```` for the named jar + targets to the given ```` directory. Its function is similar to + that of :command:`install(EXPORT)`. + + ``TARGETS`` + List of targets created by :ref:`add_jar() ` command. + + ``NAMESPACE`` + .. versionadded:: 3.9 + + The ```` value will be prepend to the target names as they are + written to the import file. + + ``FILE`` + Specify name of the export file. + + + ``DESTINATION`` + Specify the directory on disk to which a file will be installed. + + ``COMPONENT`` + Specify an installation component name with which the install rule is + associated, such as "runtime" or "development". + +.. _export_jars: + +.. command:: export_jars + + .. versionadded:: 3.7 + + Writes a target export file:: + + export_jars(TARGETS ... + [NAMESPACE ] + FILE ) + + This command writes a target export file ```` for the named ```` + targets. Its function is similar to that of :command:`export`. + + ``TARGETS`` + List of targets created by :ref:`add_jar() ` command. + + ``NAMESPACE`` + .. versionadded:: 3.9 + + The ```` value will be prepend to the target names as they are + written to the import file. + + ``FILE`` + Specify name of the export file. + +Finding JARs +^^^^^^^^^^^^ + +.. _find_jar: + +.. command:: find_jar + + Finds the specified jar file:: + + find_jar( + | NAMES [...] + [PATHS [... ENV ]] + [VERSIONS []] + [DOC "cache documentation string"] + ) + + This command is used to find a full path to the named jar. A cache + entry named by ```` is created to store the result of this command. + If the full path to a jar is found the result is stored in the + variable and the search will not repeated unless the variable is + cleared. If nothing is found, the result will be ``-NOTFOUND``, and + the search will be attempted again next time ``find_jar()`` is invoked with + the same variable. + + ``NAMES`` + Specify one or more possible names for the jar file. + + ``PATHS`` + Specify directories to search in addition to the default locations. + The ``ENV`` var sub-option reads paths from a system environment variable. + + ``VERSIONS`` + Specify jar versions. + + ``DOC`` + Specify the documentation string for the ```` cache entry. + +Creating Java Documentation +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. _create_javadoc: + +.. command:: create_javadoc + + Creates java documentation based on files and packages:: + + create_javadoc( + (PACKAGES [...] | FILES [...]) + [SOURCEPATH ] + [CLASSPATH ] + [INSTALLPATH ] + [DOCTITLE ] + [WINDOWTITLE ] + [AUTHOR (TRUE|FALSE)] + [USE (TRUE|FALSE)] + [VERSION (TRUE|FALSE)] + ) + + The ``create_javadoc()`` command can be used to create java documentation. + There are two main signatures for ``create_javadoc()``. + + The first signature works with package names on a path with source files: + + .. code-block:: cmake + + create_javadoc(my_example_doc + PACKAGES com.example.foo com.example.bar + SOURCEPATH "${CMAKE_CURRENT_SOURCE_DIR}" + CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH} + WINDOWTITLE "My example" + DOCTITLE "

My example

" + AUTHOR TRUE + USE TRUE + VERSION TRUE + ) + + The second signature for ``create_javadoc()`` works on a given list of files: + + .. code-block:: cmake + + create_javadoc(my_example_doc + FILES java/A.java java/B.java + CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH} + WINDOWTITLE "My example" + DOCTITLE "

My example

" + AUTHOR TRUE + USE TRUE + VERSION TRUE + ) + + Both signatures share most of the options. For more details please read the + javadoc manpage. + + ``PACKAGES`` + Specify java packages. + + ``FILES`` + Specify java source files. If relative paths are specified, they are + relative to :variable:`CMAKE_CURRENT_SOURCE_DIR`. + + ``SOURCEPATH`` + Specify the directory where to look for packages. By default, + :variable:`CMAKE_CURRENT_SOURCE_DIR` directory is used. + + ``CLASSPATH`` + Specify where to find user class files. Same behavior as option + ``-classpath`` of ``javadoc`` tool. + + ``INSTALLPATH`` + Specify where to install the java documentation. If you specified, the + documentation will be installed to + ``${CMAKE_INSTALL_PREFIX}/share/javadoc/``. + + ``DOCTITLE`` + Specify the title to place near the top of the overview summary file. + Same behavior as option ``-doctitle`` of ``javadoc`` tool. + + ``WINDOWTITLE`` + Specify the title to be placed in the HTML ```` tag. Same behavior + as option ``-windowtitle`` of ``javadoc`` tool. + + ``AUTHOR`` + When value ``TRUE`` is specified, includes the ``@author`` text in the + generated docs. Same behavior as option ``-author`` of ``javadoc`` tool. + + ``USE`` + When value ``TRUE`` is specified, creates class and package usage pages. + Includes one Use page for each documented class and package. Same behavior + as option ``-use`` of ``javadoc`` tool. + + ``VERSION`` + When value ``TRUE`` is specified, includes the version text in the + generated docs. Same behavior as option ``-version`` of ``javadoc`` tool. +#]=======================================================================] + +include(CMakeParseArguments) + +function (__java_copy_file src dest comment) + add_custom_command( + OUTPUT ${dest} + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ARGS ${src} + ${dest} + DEPENDS ${src} + COMMENT ${comment} + VERBATIM + ) +endfunction () + +function(__java_lcat VAR) + foreach(_line IN LISTS ARGN) + string(APPEND ${VAR} "${_line}\n") + endforeach() + + set(${VAR} "${${VAR}}" PARENT_SCOPE) +endfunction() + +function(__java_export_jar VAR TARGET PATH) + get_target_property(_jarpath ${TARGET} JAR_FILE) + get_filename_component(_jarname ${_jarpath} NAME) + set(_target "${_jar_NAMESPACE}${TARGET}") + __java_lcat(${VAR} + "# Create imported target ${_target}" + "add_library(${_target} IMPORTED STATIC)" + "set_target_properties(${_target} PROPERTIES" + " IMPORTED_LOCATION \"${PATH}/${_jarname}\"" + " JAR_FILE \"${PATH}/${_jarname}\")" + "" + ) + set(${VAR} "${${VAR}}" PARENT_SCOPE) +endfunction() + +function(__java_copy_resource_namespaces VAR DEST JAVA_RESOURCE_FILES JAVA_RESOURCE_FILES_RELATIVE) + + set(_ns_ID "") + set(_ns_VAL "") + + foreach(_item IN LISTS VAR) + if(NOT _ns_ID) + if(NOT _item STREQUAL "NAMESPACE") + message(FATAL_ERROR "UseJava: Expecting \"NAMESPACE\", got\t\"${_item}\"") + return() + endif() + endif() + + if(_item STREQUAL "NAMESPACE") + set(_ns_VAL "") # Prepare for next namespace + set(_ns_ID "${_item}") + continue() + endif() + + if( NOT _ns_VAL) + # we're expecting the next token to be a namespace value + # whatever it is, we're treating it like a namespace + set(_ns_VAL "${_item}") + continue() + endif() + + if(_ns_ID AND _ns_VAL) + # We're expecting a file name, check to see if we got one + cmake_path(ABSOLUTE_PATH _item OUTPUT_VARIABLE _test_file_name) + if (NOT EXISTS "${_test_file_name}") + message(FATAL_ERROR "UseJava: File does not exist:\t${_item}") + return() + endif() + endif() + + cmake_path(ABSOLUTE_PATH _item OUTPUT_VARIABLE _abs_file_name) + cmake_path(GET _item FILENAME _resource_file_name) + set(_dest_resource_file_name "${_ns_VAL}/${_resource_file_name}" ) + + __java_copy_file( ${_abs_file_name} + ${DEST}/${_dest_resource_file_name} + "Copying ${_item} to the build directory") + + list(APPEND RESOURCE_FILES_LIST ${DEST}/${_dest_resource_file_name}) + list(APPEND RELATIVE_RESOURCE_FILES_LIST ${_dest_resource_file_name}) + + endforeach() + + set(${JAVA_RESOURCE_FILES} "${RESOURCE_FILES_LIST}" PARENT_SCOPE) + set(${JAVA_RESOURCE_FILES_RELATIVE} "${RELATIVE_RESOURCE_FILES_LIST}" PARENT_SCOPE) +endfunction() + +# define helper scripts +set(_JAVA_EXPORT_TARGETS_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/javaTargets.cmake.in) +set(_JAVA_CLASS_FILELIST_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaClassFilelist.cmake) +set(_JAVA_SYMLINK_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaSymlinks.cmake) + +if (CMAKE_HOST_WIN32 AND NOT CYGWIN AND CMAKE_HOST_SYSTEM_NAME MATCHES "Windows") + set(_UseJava_PATH_SEP "$<SEMICOLON>") +else () + set(_UseJava_PATH_SEP ":") +endif() + +function(add_jar _TARGET_NAME) + + cmake_parse_arguments(_add_jar + "" + "VERSION;OUTPUT_DIR;OUTPUT_NAME;ENTRY_POINT;MANIFEST" + "SOURCES;INCLUDE_JARS;GENERATE_NATIVE_HEADERS" + ${ARGN} + ) + + # In CMake < 2.8.12, add_jar used variables which were set prior to calling + # add_jar for customizing the behavior of add_jar. In order to be backwards + # compatible, check if any of those variables are set, and use them to + # initialize values of the named arguments. (Giving the corresponding named + # argument will override the value set here.) + # + # New features should use named arguments only. + if(NOT DEFINED _add_jar_VERSION AND DEFINED CMAKE_JAVA_TARGET_VERSION) + set(_add_jar_VERSION "${CMAKE_JAVA_TARGET_VERSION}") + endif() + if(NOT DEFINED _add_jar_OUTPUT_DIR AND DEFINED CMAKE_JAVA_TARGET_OUTPUT_DIR) + set(_add_jar_OUTPUT_DIR "${CMAKE_JAVA_TARGET_OUTPUT_DIR}") + endif() + if(NOT DEFINED _add_jar_OUTPUT_NAME AND DEFINED CMAKE_JAVA_TARGET_OUTPUT_NAME) + set(_add_jar_OUTPUT_NAME "${CMAKE_JAVA_TARGET_OUTPUT_NAME}") + # reset + set(CMAKE_JAVA_TARGET_OUTPUT_NAME) + endif() + if(NOT DEFINED _add_jar_ENTRY_POINT AND DEFINED CMAKE_JAVA_JAR_ENTRY_POINT) + set(_add_jar_ENTRY_POINT "${CMAKE_JAVA_JAR_ENTRY_POINT}") + endif() + + # This *should* still work if <resources1>... are included without a + # named RESOURCES argument. In that case, the old behavior of potentially + # misplacing the within the Jar will behave as previously (incorrectly) + set(_JAVA_SOURCE_FILES ${_add_jar_SOURCES} ${_add_jar_UNPARSED_ARGUMENTS}) + + if (NOT DEFINED _add_jar_OUTPUT_DIR) + set(_add_jar_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) + else() + get_filename_component(_add_jar_OUTPUT_DIR ${_add_jar_OUTPUT_DIR} ABSOLUTE) + endif() + # ensure output directory exists + file (MAKE_DIRECTORY "${_add_jar_OUTPUT_DIR}") + + if (_add_jar_ENTRY_POINT) + set(_ENTRY_POINT_OPTION e) + set(_ENTRY_POINT_VALUE ${_add_jar_ENTRY_POINT}) + endif () + + if (_add_jar_MANIFEST) + set(_MANIFEST_OPTION m) + get_filename_component (_MANIFEST_VALUE "${_add_jar_MANIFEST}" ABSOLUTE) + endif () + + unset (_GENERATE_NATIVE_HEADERS) + if (_add_jar_GENERATE_NATIVE_HEADERS) + # Raise an error if JDK version is less than 1.8 because javac -h is not supported + # by earlier versions. + if (Java_VERSION VERSION_LESS 1.8) + message (FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS is not supported with this version of Java.") + endif() + + unset (_GENERATE_NATIVE_HEADERS_OUTPUT_DESC) + + cmake_parse_arguments (_add_jar_GENERATE_NATIVE_HEADERS "" "" "DESTINATION" ${_add_jar_GENERATE_NATIVE_HEADERS}) + if (NOT _add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS) + message (FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS: missing required argument.") + endif() + list (LENGTH _add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS length) + if (length GREATER 1) + list (REMOVE_AT _add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS 0) + message (FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS: ${_add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS}: unexpected argument(s).") + endif() + if (NOT _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION) + set (_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir/native_headers") + else() + list (LENGTH _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION length) + if (NOT length EQUAL 1) + cmake_parse_arguments (_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION "" "BUILD;INSTALL" "" "${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION}") + if (_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_UNPARSED_ARGUMENTS) + message (FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS: DESTINATION: ${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_UNPARSED_ARGUMENTS}: unexpected argument(s).") + endif() + if (NOT _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_INSTALL) + message (FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS: DESTINATION: INSTALL sub-option is required.") + endif() + if (NOT _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_BUILD) + set(_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_BUILD "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir/native_headers") + endif() + set(_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION "${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_BUILD}") + set(_GENERATE_NATIVE_HEADERS_OUTPUT_DESC "$<BUILD_INTERFACE:${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_BUILD}>" "$<INSTALL_INTERFACE:${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_INSTALL}>") + endif() + endif() + + set (_GENERATE_NATIVE_HEADERS_TARGET ${_add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS}) + set (_GENERATE_NATIVE_HEADERS_OUTPUT_DIR "${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION}") + set (_GENERATE_NATIVE_HEADERS -h "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}") + if(NOT _GENERATE_NATIVE_HEADERS_OUTPUT_DESC) + set(_GENERATE_NATIVE_HEADERS_OUTPUT_DESC "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}") + endif() + endif() + + if (LIBRARY_OUTPUT_PATH) + set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH}) + else () + set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${_add_jar_OUTPUT_DIR}) + endif () + + set(CMAKE_JAVA_INCLUDE_PATH + ${CMAKE_JAVA_INCLUDE_PATH} + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_JAVA_OBJECT_OUTPUT_PATH} + ${CMAKE_JAVA_LIBRARY_OUTPUT_PATH} + ) + + foreach (JAVA_INCLUDE_DIR IN LISTS CMAKE_JAVA_INCLUDE_PATH) + string(APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL "${_UseJava_PATH_SEP}${JAVA_INCLUDE_DIR}") + endforeach() + + set(CMAKE_JAVA_CLASS_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir") + + set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}.jar") + if (_add_jar_OUTPUT_NAME AND _add_jar_VERSION) + set(_JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}-${_add_jar_VERSION}.jar") + set(_JAVA_TARGET_OUTPUT_LINK "${_add_jar_OUTPUT_NAME}.jar") + elseif (_add_jar_VERSION) + set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}-${_add_jar_VERSION}.jar") + set(_JAVA_TARGET_OUTPUT_LINK "${_TARGET_NAME}.jar") + elseif (_add_jar_OUTPUT_NAME) + set(_JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}.jar") + endif () + + set(_JAVA_CLASS_FILES) + set(_JAVA_COMPILE_FILES) + set(_JAVA_COMPILE_FILELISTS) + set(_JAVA_DEPENDS) + set(_JAVA_COMPILE_DEPENDS) + set(_JAVA_RESOURCE_FILES) + set(_JAVA_RESOURCE_FILES_RELATIVE) + foreach(_JAVA_SOURCE_FILE IN LISTS _JAVA_SOURCE_FILES) + get_filename_component(_JAVA_EXT ${_JAVA_SOURCE_FILE} EXT) + get_filename_component(_JAVA_FILE ${_JAVA_SOURCE_FILE} NAME_WE) + get_filename_component(_JAVA_PATH ${_JAVA_SOURCE_FILE} PATH) + get_filename_component(_JAVA_FULL ${_JAVA_SOURCE_FILE} ABSOLUTE) + + if (_JAVA_SOURCE_FILE MATCHES "^@(.+)$") + get_filename_component(_JAVA_FULL ${CMAKE_MATCH_1} ABSOLUTE) + list(APPEND _JAVA_COMPILE_FILELISTS ${_JAVA_FULL}) + + elseif (_JAVA_EXT MATCHES ".java") + file(RELATIVE_PATH _JAVA_REL_BINARY_PATH ${CMAKE_CURRENT_BINARY_DIR} ${_JAVA_FULL}) + file(RELATIVE_PATH _JAVA_REL_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${_JAVA_FULL}) + string(LENGTH ${_JAVA_REL_BINARY_PATH} _BIN_LEN) + string(LENGTH ${_JAVA_REL_SOURCE_PATH} _SRC_LEN) + if (_BIN_LEN LESS _SRC_LEN) + set(_JAVA_REL_PATH ${_JAVA_REL_BINARY_PATH}) + else () + set(_JAVA_REL_PATH ${_JAVA_REL_SOURCE_PATH}) + endif () + get_filename_component(_JAVA_REL_PATH ${_JAVA_REL_PATH} PATH) + + list(APPEND _JAVA_COMPILE_FILES ${_JAVA_SOURCE_FILE}) + set(_JAVA_CLASS_FILE "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_REL_PATH}/${_JAVA_FILE}.class") + set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES} ${_JAVA_CLASS_FILE}) + + elseif (_JAVA_EXT MATCHES ".jar" + OR _JAVA_EXT MATCHES ".war" + OR _JAVA_EXT MATCHES ".ear" + OR _JAVA_EXT MATCHES ".sar") + # Ignored for backward compatibility + + elseif (_JAVA_EXT STREQUAL "") + list(APPEND CMAKE_JAVA_INCLUDE_PATH ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}} ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}_CLASSPATH}) + list(APPEND _JAVA_DEPENDS ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}}) + + else () + __java_copy_file(${CMAKE_CURRENT_SOURCE_DIR}/${_JAVA_SOURCE_FILE} + ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_SOURCE_FILE} + "Copying ${_JAVA_SOURCE_FILE} to the build directory") + list(APPEND _JAVA_RESOURCE_FILES ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_SOURCE_FILE}) + list(APPEND _JAVA_RESOURCE_FILES_RELATIVE ${_JAVA_SOURCE_FILE}) + endif () + endforeach() + + if(_add_jar_RESOURCES) # Process RESOURCES if it exists + __java_copy_resource_namespaces("${_add_jar_RESOURCES}" + ${CMAKE_JAVA_CLASS_OUTPUT_PATH} + _JAVA_RESOURCE_FILES + _JAVA_RESOURCE_FILES_RELATIVE) + endif() + + foreach(_JAVA_INCLUDE_JAR IN LISTS _add_jar_INCLUDE_JARS) + if (TARGET ${_JAVA_INCLUDE_JAR}) + get_target_property(_JAVA_JAR_PATH ${_JAVA_INCLUDE_JAR} JAR_FILE) + if (_JAVA_JAR_PATH) + string(APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL "${_UseJava_PATH_SEP}${_JAVA_JAR_PATH}") + list(APPEND CMAKE_JAVA_INCLUDE_PATH ${_JAVA_JAR_PATH}) + list(APPEND _JAVA_DEPENDS ${_JAVA_INCLUDE_JAR}) + list(APPEND _JAVA_COMPILE_DEPENDS ${_JAVA_JAR_PATH}) + else () + message(SEND_ERROR "add_jar: INCLUDE_JARS target ${_JAVA_INCLUDE_JAR} is not a jar") + endif () + else () + string(APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL "${_UseJava_PATH_SEP}${_JAVA_INCLUDE_JAR}") + list(APPEND CMAKE_JAVA_INCLUDE_PATH "${_JAVA_INCLUDE_JAR}") + list(APPEND _JAVA_DEPENDS "${_JAVA_INCLUDE_JAR}") + list(APPEND _JAVA_COMPILE_DEPENDS "${_JAVA_INCLUDE_JAR}") + endif () + endforeach() + + if (_JAVA_COMPILE_FILES OR _JAVA_COMPILE_FILELISTS) + set (_JAVA_SOURCES_FILELISTS) + + if (_JAVA_COMPILE_FILES) + # Create the list of files to compile. + set(_JAVA_SOURCES_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_sources) + string(REPLACE ";" "\"\n\"" _JAVA_COMPILE_STRING "\"${_JAVA_COMPILE_FILES}\"") + file(WRITE ${_JAVA_SOURCES_FILE} ${_JAVA_COMPILE_STRING}) + list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_SOURCES_FILE}") + endif() + if (_JAVA_COMPILE_FILELISTS) + foreach (_JAVA_FILELIST IN LISTS _JAVA_COMPILE_FILELISTS) + list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_FILELIST}") + endforeach() + endif() + + # Compile the java files and create a list of class files + add_custom_command( + # NOTE: this command generates an artificial dependency file + OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME} + COMMAND ${Java_JAVAC_EXECUTABLE} + ${CMAKE_JAVA_COMPILE_FLAGS} + -classpath "${CMAKE_JAVA_INCLUDE_PATH_FINAL}" + -d ${CMAKE_JAVA_CLASS_OUTPUT_PATH} + ${_GENERATE_NATIVE_HEADERS} + ${_JAVA_SOURCES_FILELISTS} + COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME} + DEPENDS ${_JAVA_COMPILE_FILES} ${_JAVA_COMPILE_FILELISTS} ${_JAVA_COMPILE_DEPENDS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Building Java objects for ${_TARGET_NAME}.jar" + VERBATIM + ) + add_custom_command( + OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist + COMMAND ${CMAKE_COMMAND} + -DCMAKE_JAVA_CLASS_OUTPUT_PATH=${CMAKE_JAVA_CLASS_OUTPUT_PATH} + -DCMAKE_JAR_CLASSES_PREFIX=${CMAKE_JAR_CLASSES_PREFIX} + -P ${_JAVA_CLASS_FILELIST_SCRIPT} + DEPENDS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + VERBATIM + ) + else () + # create an empty java_class_filelist + if (NOT EXISTS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist) + file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "") + endif() + endif () + + # create the jar file + set(_JAVA_JAR_OUTPUT_PATH + "${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_NAME}") + if (CMAKE_JNI_TARGET) + add_custom_command( + OUTPUT ${_JAVA_JAR_OUTPUT_PATH} + COMMAND ${Java_JAR_EXECUTABLE} + -cf${_ENTRY_POINT_OPTION}${_MANIFEST_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_MANIFEST_VALUE} + ${_JAVA_RESOURCE_FILES_RELATIVE} @java_class_filelist + COMMAND ${CMAKE_COMMAND} + -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR} + -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME} + -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK} + -P ${_JAVA_SYMLINK_SCRIPT} + COMMAND ${CMAKE_COMMAND} + -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR} + -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_JAR_OUTPUT_PATH} + -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK} + -P ${_JAVA_SYMLINK_SCRIPT} + DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist + WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH} + COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}" + VERBATIM + ) + else () + add_custom_command( + OUTPUT ${_JAVA_JAR_OUTPUT_PATH} + COMMAND ${Java_JAR_EXECUTABLE} + -cf${_ENTRY_POINT_OPTION}${_MANIFEST_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_MANIFEST_VALUE} + ${_JAVA_RESOURCE_FILES_RELATIVE} @java_class_filelist + COMMAND ${CMAKE_COMMAND} + -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR} + -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME} + -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK} + -P ${_JAVA_SYMLINK_SCRIPT} + WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH} + DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist + COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}" + VERBATIM + ) + endif () + + # Add the target and make sure we have the latest resource files. + add_custom_target(${_TARGET_NAME} ALL DEPENDS ${_JAVA_JAR_OUTPUT_PATH}) + + set_property( + TARGET + ${_TARGET_NAME} + PROPERTY + INSTALL_FILES + ${_JAVA_JAR_OUTPUT_PATH} + ) + + if (_JAVA_TARGET_OUTPUT_LINK) + set_property( + TARGET + ${_TARGET_NAME} + PROPERTY + INSTALL_FILES + ${_JAVA_JAR_OUTPUT_PATH} + ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK} + ) + + if (CMAKE_JNI_TARGET) + set_property( + TARGET + ${_TARGET_NAME} + PROPERTY + JNI_SYMLINK + ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK} + ) + endif () + endif () + + set_property( + TARGET + ${_TARGET_NAME} + PROPERTY + JAR_FILE + ${_JAVA_JAR_OUTPUT_PATH} + ) + + set_property( + TARGET + ${_TARGET_NAME} + PROPERTY + CLASSDIR + ${CMAKE_JAVA_CLASS_OUTPUT_PATH} + ) + + if (_GENERATE_NATIVE_HEADERS) + # create an INTERFACE library encapsulating include directory for generated headers + add_library (${_GENERATE_NATIVE_HEADERS_TARGET} INTERFACE) + target_include_directories (${_GENERATE_NATIVE_HEADERS_TARGET} INTERFACE + "${_GENERATE_NATIVE_HEADERS_OUTPUT_DESC}" + ${JNI_INCLUDE_DIRS}) + set_property(TARGET ${_GENERATE_NATIVE_HEADERS_TARGET} PROPERTY NATIVE_HEADERS_DIRECTORY "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}") + # this INTERFACE library depends on jar generation + add_dependencies (${_GENERATE_NATIVE_HEADERS_TARGET} ${_TARGET_NAME}) + + set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES + "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}") + endif() +endfunction() + +function(INSTALL_JAR _TARGET_NAME) + if (ARGC EQUAL 2) + set (_DESTINATION ${ARGV1}) + else() + cmake_parse_arguments(_install_jar + "" + "DESTINATION;COMPONENT" + "" + ${ARGN}) + if (_install_jar_DESTINATION) + set (_DESTINATION ${_install_jar_DESTINATION}) + else() + message(SEND_ERROR "install_jar: ${_TARGET_NAME}: DESTINATION must be specified.") + endif() + + if (_install_jar_COMPONENT) + set (_COMPONENT COMPONENT ${_install_jar_COMPONENT}) + endif() + endif() + + get_property(__FILES + TARGET + ${_TARGET_NAME} + PROPERTY + INSTALL_FILES + ) + set_property( + TARGET + ${_TARGET_NAME} + PROPERTY + INSTALL_DESTINATION + ${_DESTINATION} + ) + + if (__FILES) + install( + FILES + ${__FILES} + DESTINATION + ${_DESTINATION} + ${_COMPONENT} + ) + else () + message(SEND_ERROR "install_jar: The target ${_TARGET_NAME} is not known in this scope.") + endif () +endfunction() + +function(INSTALL_JNI_SYMLINK _TARGET_NAME) + if (ARGC EQUAL 2) + set (_DESTINATION ${ARGV1}) + else() + cmake_parse_arguments(_install_jni_symlink + "" + "DESTINATION;COMPONENT" + "" + ${ARGN}) + if (_install_jni_symlink_DESTINATION) + set (_DESTINATION ${_install_jni_symlink_DESTINATION}) + else() + message(SEND_ERROR "install_jni_symlink: ${_TARGET_NAME}: DESTINATION must be specified.") + endif() + + if (_install_jni_symlink_COMPONENT) + set (_COMPONENT COMPONENT ${_install_jni_symlink_COMPONENT}) + endif() + endif() + + get_property(__SYMLINK + TARGET + ${_TARGET_NAME} + PROPERTY + JNI_SYMLINK + ) + + if (__SYMLINK) + install( + FILES + ${__SYMLINK} + DESTINATION + ${_DESTINATION} + ${_COMPONENT} + ) + else () + message(SEND_ERROR "install_jni_symlink: The target ${_TARGET_NAME} is not known in this scope.") + endif () +endfunction() + +function (find_jar VARIABLE) + set(_jar_names) + set(_jar_files) + set(_jar_versions) + set(_jar_paths + /usr/share/java/ + /usr/local/share/java/ + ${Java_JAR_PATHS}) + set(_jar_doc "NOTSET") + + set(_state "name") + + foreach (arg IN LISTS ARGN) + if (_state STREQUAL "name") + if (arg STREQUAL "VERSIONS") + set(_state "versions") + elseif (arg STREQUAL "NAMES") + set(_state "names") + elseif (arg STREQUAL "PATHS") + set(_state "paths") + elseif (arg STREQUAL "DOC") + set(_state "doc") + else () + set(_jar_names ${arg}) + if (_jar_doc STREQUAL "NOTSET") + set(_jar_doc "Finding ${arg} jar") + endif () + endif () + elseif (_state STREQUAL "versions") + if (arg STREQUAL "NAMES") + set(_state "names") + elseif (arg STREQUAL "PATHS") + set(_state "paths") + elseif (arg STREQUAL "DOC") + set(_state "doc") + else () + set(_jar_versions ${_jar_versions} ${arg}) + endif () + elseif (_state STREQUAL "names") + if (arg STREQUAL "VERSIONS") + set(_state "versions") + elseif (arg STREQUAL "PATHS") + set(_state "paths") + elseif (arg STREQUAL "DOC") + set(_state "doc") + else () + set(_jar_names ${_jar_names} ${arg}) + if (_jar_doc STREQUAL "NOTSET") + set(_jar_doc "Finding ${arg} jar") + endif () + endif () + elseif (_state STREQUAL "paths") + if (arg STREQUAL "VERSIONS") + set(_state "versions") + elseif (arg STREQUAL "NAMES") + set(_state "names") + elseif (arg STREQUAL "DOC") + set(_state "doc") + else () + set(_jar_paths ${_jar_paths} ${arg}) + endif () + elseif (_state STREQUAL "doc") + if (arg STREQUAL "VERSIONS") + set(_state "versions") + elseif (arg STREQUAL "NAMES") + set(_state "names") + elseif (arg STREQUAL "PATHS") + set(_state "paths") + else () + set(_jar_doc ${arg}) + endif () + endif () + endforeach () + + if (NOT _jar_names) + message(FATAL_ERROR "find_jar: No name to search for given") + endif () + + foreach (jar_name IN LISTS _jar_names) + foreach (version IN LISTS _jar_versions) + set(_jar_files ${_jar_files} ${jar_name}-${version}.jar) + endforeach () + set(_jar_files ${_jar_files} ${jar_name}.jar) + endforeach () + + find_file(${VARIABLE} + NAMES ${_jar_files} + PATHS ${_jar_paths} + DOC ${_jar_doc} + NO_DEFAULT_PATH) +endfunction () + +function(create_javadoc _target) + set(_javadoc_packages) + set(_javadoc_files) + set(_javadoc_overview) + set(_javadoc_sourcepath) + set(_javadoc_classpath) + set(_javadoc_installpath "${CMAKE_INSTALL_PREFIX}/share/javadoc") + set(_javadoc_doctitle) + set(_javadoc_windowtitle) + set(_javadoc_author FALSE) + set(_javadoc_version FALSE) + set(_javadoc_use FALSE) + + set(_state "package") + + foreach (arg IN LISTS ARGN) + if (_state STREQUAL "package") + if (arg STREQUAL "PACKAGES") + set(_state "packages") + elseif (arg STREQUAL "FILES") + set(_state "files") + elseif (arg STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (arg STREQUAL "OVERVIEW") + set(_state "overview") + elseif (arg STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (arg STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (arg STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (arg STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (arg STREQUAL "AUTHOR") + set(_state "author") + elseif (arg STREQUAL "USE") + set(_state "use") + elseif (arg STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_packages ${arg}) + set(_state "packages") + endif () + elseif (_state STREQUAL "packages") + if (arg STREQUAL "FILES") + set(_state "files") + elseif (arg STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (arg STREQUAL "OVERVIEW") + set(_state "overview") + elseif (arg STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (arg STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (arg STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (arg STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (arg STREQUAL "AUTHOR") + set(_state "author") + elseif (arg STREQUAL "USE") + set(_state "use") + elseif (arg STREQUAL "VERSION") + set(_state "version") + else () + list(APPEND _javadoc_packages ${arg}) + endif () + elseif (_state STREQUAL "files") + if (arg STREQUAL "PACKAGES") + set(_state "packages") + elseif (arg STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (arg STREQUAL "OVERVIEW") + set(_state "overview") + elseif (arg STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (arg STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (arg STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (arg STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (arg STREQUAL "AUTHOR") + set(_state "author") + elseif (arg STREQUAL "USE") + set(_state "use") + elseif (arg STREQUAL "VERSION") + set(_state "version") + else () + list(APPEND _javadoc_files ${arg}) + endif () + elseif (_state STREQUAL "sourcepath") + if (arg STREQUAL "PACKAGES") + set(_state "packages") + elseif (arg STREQUAL "FILES") + set(_state "files") + elseif (arg STREQUAL "OVERVIEW") + set(_state "overview") + elseif (arg STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (arg STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (arg STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (arg STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (arg STREQUAL "AUTHOR") + set(_state "author") + elseif (arg STREQUAL "USE") + set(_state "use") + elseif (arg STREQUAL "VERSION") + set(_state "version") + else () + list(APPEND _javadoc_sourcepath ${arg}) + endif () + elseif (_state STREQUAL "classpath") + if (arg STREQUAL "PACKAGES") + set(_state "packages") + elseif (arg STREQUAL "FILES") + set(_state "files") + elseif (arg STREQUAL "OVERVIEW") + set(_state "overview") + elseif (arg STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (arg STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (arg STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (arg STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (arg STREQUAL "AUTHOR") + set(_state "author") + elseif (arg STREQUAL "USE") + set(_state "use") + elseif (arg STREQUAL "VERSION") + set(_state "version") + else () + list(APPEND _javadoc_classpath ${arg}) + endif () + elseif (_state STREQUAL "installpath") + if (arg STREQUAL "PACKAGES") + set(_state "packages") + elseif (arg STREQUAL "FILES") + set(_state "files") + elseif (arg STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (arg STREQUAL "OVERVIEW") + set(_state "overview") + elseif (arg STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (arg STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (arg STREQUAL "AUTHOR") + set(_state "author") + elseif (arg STREQUAL "USE") + set(_state "use") + elseif (arg STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_installpath ${arg}) + endif () + elseif (_state STREQUAL "doctitle") + if (${arg} STREQUAL "PACKAGES") + set(_state "packages") + elseif (arg STREQUAL "FILES") + set(_state "files") + elseif (arg STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (arg STREQUAL "OVERVIEW") + set(_state "overview") + elseif (arg STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (arg STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (arg STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (arg STREQUAL "AUTHOR") + set(_state "author") + elseif (arg STREQUAL "USE") + set(_state "use") + elseif (arg STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_doctitle ${arg}) + endif () + elseif (_state STREQUAL "windowtitle") + if (${arg} STREQUAL "PACKAGES") + set(_state "packages") + elseif (arg STREQUAL "FILES") + set(_state "files") + elseif (arg STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (arg STREQUAL "OVERVIEW") + set(_state "overview") + elseif (arg STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (arg STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (arg STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (arg STREQUAL "AUTHOR") + set(_state "author") + elseif (arg STREQUAL "USE") + set(_state "use") + elseif (arg STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_windowtitle ${arg}) + endif () + elseif (_state STREQUAL "author") + if (arg STREQUAL "PACKAGES") + set(_state "packages") + elseif (arg STREQUAL "FILES") + set(_state "files") + elseif (arg STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (arg STREQUAL "OVERVIEW") + set(_state "overview") + elseif (arg STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (arg STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (arg STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (arg STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (arg STREQUAL "AUTHOR") + set(_state "author") + elseif (arg STREQUAL "USE") + set(_state "use") + elseif (arg STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_author ${arg}) + endif () + elseif (_state STREQUAL "use") + if (arg STREQUAL "PACKAGES") + set(_state "packages") + elseif (arg STREQUAL "FILES") + set(_state "files") + elseif (arg STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (arg STREQUAL "OVERVIEW") + set(_state "overview") + elseif (arg STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (arg STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (arg STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (arg STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (arg STREQUAL "AUTHOR") + set(_state "author") + elseif (arg STREQUAL "USE") + set(_state "use") + elseif (arg STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_use ${arg}) + endif () + elseif (_state STREQUAL "version") + if (arg STREQUAL "PACKAGES") + set(_state "packages") + elseif (arg STREQUAL "FILES") + set(_state "files") + elseif (arg STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (arg STREQUAL "OVERVIEW") + set(_state "overview") + elseif (arg STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (arg STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (arg STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (arg STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (arg STREQUAL "AUTHOR") + set(_state "author") + elseif (arg STREQUAL "USE") + set(_state "use") + elseif (arg STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_version ${arg}) + endif () + elseif (_state STREQUAL "overview") + if (arg STREQUAL "PACKAGES") + set(_state "packages") + elseif (arg STREQUAL "FILES") + set(_state "files") + elseif (arg STREQUAL "SOURCEPATH") + set(_state "sourcepath") + elseif (arg STREQUAL "CLASSPATH") + set(_state "classpath") + elseif (arg STREQUAL "INSTALLPATH") + set(_state "installpath") + elseif (arg STREQUAL "DOCTITLE") + set(_state "doctitle") + elseif (arg STREQUAL "WINDOWTITLE") + set(_state "windowtitle") + elseif (arg STREQUAL "AUTHOR") + set(_state "author") + elseif (arg STREQUAL "USE") + set(_state "use") + elseif (arg STREQUAL "VERSION") + set(_state "version") + else () + set(_javadoc_overview ${arg}) + endif () + endif () + endforeach () + + set(_javadoc_builddir ${CMAKE_CURRENT_BINARY_DIR}/javadoc/${_target}) + set(_javadoc_options -d ${_javadoc_builddir}) + + if (_javadoc_sourcepath) + list(JOIN _javadoc_sourcepath "${_UseJava_PATH_SEP}" _javadoc_sourcepath) + list(APPEND _javadoc_options -sourcepath "\"${_javadoc_sourcepath}\"") + endif () + + if (_javadoc_overview) + list(JOIN _javadoc_overview "${_UseJava_PATH_SEP}" _javadoc_overview) + list(APPEND _javadoc_options -overview "\"${_javadoc_overview}\"") + endif () + + if (_javadoc_classpath) + list(JOIN _javadoc_classpath "${_UseJava_PATH_SEP}" _javadoc_classpath) + list(APPEND _javadoc_options -classpath "\"${_javadoc_classpath}\"") + endif () + + if (_javadoc_doctitle) + list(APPEND _javadoc_options -doctitle '${_javadoc_doctitle}') + endif () + + if (_javadoc_windowtitle) + list(APPEND _javadoc_options -windowtitle '${_javadoc_windowtitle}') + endif () + + if (_javadoc_author) + list(APPEND _javadoc_options -author) + endif () + + if (_javadoc_use) + list(APPEND _javadoc_options -use) + endif () + + if (_javadoc_version) + list(APPEND _javadoc_options -version) + endif () + + add_custom_target(${_target}_javadoc ALL + COMMAND ${Java_JAVADOC_EXECUTABLE} + -Xdoclint:none + ${_javadoc_options} + ${_javadoc_files} + ${_javadoc_packages} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + install( + DIRECTORY ${_javadoc_builddir} + DESTINATION ${_javadoc_installpath} + ) +endfunction() + +function (create_javah) + if (Java_VERSION VERSION_GREATER_EQUAL 10) + message (FATAL_ERROR "create_javah: not supported with this Java version. Use add_jar(GENERATE_NATIVE_HEADERS) instead.") + elseif (Java_VERSION VERSION_GREATER_EQUAL 1.8) + message (DEPRECATION "create_javah: this command will no longer be supported starting with version 10 of JDK. Update your project by using command add_jar(GENERATE_NATIVE_HEADERS) instead.") + endif() + + cmake_parse_arguments(_create_javah + "" + "TARGET;GENERATED_FILES;OUTPUT_NAME;OUTPUT_DIR" + "CLASSES;CLASSPATH;DEPENDS" + ${ARGN}) + + # check parameters + if (NOT _create_javah_TARGET AND NOT _create_javah_GENERATED_FILES) + message (FATAL_ERROR "create_javah: TARGET or GENERATED_FILES must be specified.") + endif() + if (_create_javah_OUTPUT_NAME AND _create_javah_OUTPUT_DIR) + message (FATAL_ERROR "create_javah: OUTPUT_NAME and OUTPUT_DIR are mutually exclusive.") + endif() + + if (NOT _create_javah_CLASSES) + message (FATAL_ERROR "create_javah: CLASSES is a required parameter.") + endif() + + set (_output_files) + + # handle javah options + set (_javah_options) + + if (_create_javah_CLASSPATH) + # CLASSPATH can specify directories, jar files or targets created with add_jar command + set (_classpath) + foreach (_path IN LISTS _create_javah_CLASSPATH) + if (TARGET ${_path}) + get_target_property (_jar_path ${_path} JAR_FILE) + if (_jar_path) + list (APPEND _classpath "${_jar_path}") + list (APPEND _create_javah_DEPENDS "${_path}") + else() + message(SEND_ERROR "create_javah: CLASSPATH target ${_path} is not a jar.") + endif() + elseif (EXISTS "${_path}") + list (APPEND _classpath "${_path}") + if (NOT IS_DIRECTORY "${_path}") + list (APPEND _create_javah_DEPENDS "${_path}") + endif() + else() + message(SEND_ERROR "create_javah: CLASSPATH entry ${_path} does not exist.") + endif() + endforeach() + string (REPLACE ";" "${_UseJava_PATH_SEP}" _classpath "${_classpath}") + list (APPEND _javah_options -classpath "${_classpath}") + endif() + + if (_create_javah_OUTPUT_DIR) + list (APPEND _javah_options -d "${_create_javah_OUTPUT_DIR}") + endif() + + if (_create_javah_OUTPUT_NAME) + list (APPEND _javah_options -o "${_create_javah_OUTPUT_NAME}") + set (_output_files "${_create_javah_OUTPUT_NAME}") + + get_filename_component (_create_javah_OUTPUT_DIR "${_create_javah_OUTPUT_NAME}" DIRECTORY) + get_filename_component (_create_javah_OUTPUT_DIR "${_create_javah_OUTPUT_DIR}" ABSOLUTE) + endif() + + if (NOT _create_javah_OUTPUT_DIR) + set (_create_javah_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}") + endif() + + if (NOT _create_javah_OUTPUT_NAME) + # compute output names + foreach (_class IN LISTS _create_javah_CLASSES) + string (REPLACE "." "_" _c_header "${_class}") + set (_c_header "${_create_javah_OUTPUT_DIR}/${_c_header}.h") + list (APPEND _output_files "${_c_header}") + endforeach() + endif() + + # finalize custom command arguments + if (_create_javah_DEPENDS) + list (INSERT _create_javah_DEPENDS 0 DEPENDS) + endif() + + add_custom_command (OUTPUT ${_output_files} + COMMAND "${Java_JAVAH_EXECUTABLE}" ${_javah_options} -jni ${_create_javah_CLASSES} + ${_create_javah_DEPENDS} + WORKING_DIRECTORY ${_create_javah_OUTPUT_DIR} + COMMENT "Building C header files from classes...") + + if (_create_javah_TARGET) + add_custom_target (${_create_javah_TARGET} ALL DEPENDS ${_output_files}) + endif() + if (_create_javah_GENERATED_FILES) + set (${_create_javah_GENERATED_FILES} ${_output_files} PARENT_SCOPE) + endif() +endfunction() + +function(export_jars) + # Parse and validate arguments + cmake_parse_arguments(_export_jars + "" + "FILE;NAMESPACE" + "TARGETS" + ${ARGN} + ) + if (NOT _export_jars_FILE) + message(SEND_ERROR "export_jars: FILE must be specified.") + endif() + if (NOT _export_jars_TARGETS) + message(SEND_ERROR "export_jars: TARGETS must be specified.") + endif() + set(_jar_NAMESPACE "${_export_jars_NAMESPACE}") + + # Set content of generated exports file + string(REPLACE ";" " " __targets__ "${_export_jars_TARGETS}") + set(__targetdefs__ "") + foreach(_target IN LISTS _export_jars_TARGETS) + get_target_property(_jarpath ${_target} JAR_FILE) + get_filename_component(_jarpath ${_jarpath} PATH) + __java_export_jar(__targetdefs__ ${_target} "${_jarpath}") + endforeach() + + # Generate exports file + configure_file( + ${_JAVA_EXPORT_TARGETS_SCRIPT} + ${_export_jars_FILE} + @ONLY + ) +endfunction() + +function(install_jar_exports) + # Parse and validate arguments + cmake_parse_arguments(_install_jar_exports + "" + "FILE;DESTINATION;COMPONENT;NAMESPACE" + "TARGETS" + ${ARGN} + ) + if (NOT _install_jar_exports_FILE) + message(SEND_ERROR "install_jar_exports: FILE must be specified.") + endif() + if (NOT _install_jar_exports_DESTINATION) + message(SEND_ERROR "install_jar_exports: DESTINATION must be specified.") + endif() + if (NOT _install_jar_exports_TARGETS) + message(SEND_ERROR "install_jar_exports: TARGETS must be specified.") + endif() + set(_jar_NAMESPACE "${_install_jar_exports_NAMESPACE}") + + if (_install_jar_exports_COMPONENT) + set (_COMPONENT COMPONENT ${_install_jar_exports_COMPONENT}) + endif() + + # Determine relative path from installed export file to install prefix + if(IS_ABSOLUTE "${_install_jar_exports_DESTINATION}") + file(RELATIVE_PATH _relpath + ${_install_jar_exports_DESTINATION} + ${CMAKE_INSTALL_PREFIX} + ) + else() + file(RELATIVE_PATH _relpath + ${CMAKE_INSTALL_PREFIX}/${_install_jar_exports_DESTINATION} + ${CMAKE_INSTALL_PREFIX} + ) + endif() + + # Set up unique location for generated exports file + string(SHA256 _hash "${_install_jar_exports_DESTINATION}") + set(_tmpdir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/JavaExports/${_hash}) + + # Set content of generated exports file + string(REPLACE ";" " " __targets__ "${_install_jar_exports_TARGETS}") + set(__targetdefs__ "set(_prefix \${CMAKE_CURRENT_LIST_DIR}/${_relpath})\n\n") + foreach(_target IN LISTS _install_jar_exports_TARGETS) + get_target_property(_dir ${_target} INSTALL_DESTINATION) + __java_export_jar(__targetdefs__ ${_target} "\${_prefix}/${_dir}") + endforeach() + __java_lcat(__targetdefs__ "\nunset(_prefix)") + + # Generate and install exports file + configure_file( + ${_JAVA_EXPORT_TARGETS_SCRIPT} + ${_tmpdir}/${_install_jar_exports_FILE} + @ONLY + ) + install(FILES ${_tmpdir}/${_install_jar_exports_FILE} + DESTINATION ${_install_jar_exports_DESTINATION} + ${_COMPONENT}) +endfunction() diff --git a/HDF4Examples/config/cmake/UseJavaClassFilelist.cmake b/HDF4Examples/config/cmake/UseJavaClassFilelist.cmake new file mode 100644 index 0000000000..d90ca489fc --- /dev/null +++ b/HDF4Examples/config/cmake/UseJavaClassFilelist.cmake @@ -0,0 +1,39 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See https://cmake.org/licensing for details. + +# This script creates a list of compiled Java class files to be added to +# a jar file. This avoids including cmake files which get created in +# the binary directory. + +if (CMAKE_JAVA_CLASS_OUTPUT_PATH) + if (EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}") + + set(_JAVA_GLOBBED_FILES) + if (CMAKE_JAR_CLASSES_PREFIX) + foreach(JAR_CLASS_PREFIX ${CMAKE_JAR_CLASSES_PREFIX}) + message(STATUS "JAR_CLASS_PREFIX: ${JAR_CLASS_PREFIX}") + + file(GLOB_RECURSE _JAVA_GLOBBED_TMP_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${JAR_CLASS_PREFIX}/*.class") + if (_JAVA_GLOBBED_TMP_FILES) + list(APPEND _JAVA_GLOBBED_FILES ${_JAVA_GLOBBED_TMP_FILES}) + endif () + endforeach() + else() + file(GLOB_RECURSE _JAVA_GLOBBED_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/*.class") + endif () + + set(_JAVA_CLASS_FILES) + # file(GLOB_RECURSE foo RELATIVE) is broken so we need this. + foreach(_JAVA_GLOBBED_FILE ${_JAVA_GLOBBED_FILES}) + file(RELATIVE_PATH _JAVA_CLASS_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH} ${_JAVA_GLOBBED_FILE}) + set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES}${_JAVA_CLASS_FILE}\n) + endforeach() + + # write to file + file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist ${_JAVA_CLASS_FILES}) + + else () + message(SEND_ERROR "FATAL: Java class output path doesn't exist") + endif () +else () + message(SEND_ERROR "FATAL: Can't find CMAKE_JAVA_CLASS_OUTPUT_PATH") +endif () diff --git a/HDF4Examples/config/cmake/UseJavaSymlinks.cmake b/HDF4Examples/config/cmake/UseJavaSymlinks.cmake new file mode 100644 index 0000000000..183a744885 --- /dev/null +++ b/HDF4Examples/config/cmake/UseJavaSymlinks.cmake @@ -0,0 +1,16 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See https://cmake.org/licensing for details. + +# Helper script for UseJava.cmake + +if (UNIX AND _JAVA_TARGET_OUTPUT_LINK) + if (_JAVA_TARGET_OUTPUT_NAME) + find_program(LN_EXECUTABLE NAMES ln) + + execute_process( + COMMAND ${LN_EXECUTABLE} -sf "${_JAVA_TARGET_OUTPUT_NAME}" "${_JAVA_TARGET_OUTPUT_LINK}" + WORKING_DIRECTORY ${_JAVA_TARGET_DIR} + ) + else () + message(SEND_ERROR "FATAL: Can't find _JAVA_TARGET_OUTPUT_NAME") + endif () +endif () diff --git a/HDF4Examples/config/cmake/cacheinit.cmake b/HDF4Examples/config/cmake/cacheinit.cmake new file mode 100755 index 0000000000..1e251b22b7 --- /dev/null +++ b/HDF4Examples/config/cmake/cacheinit.cmake @@ -0,0 +1,25 @@ +# This is the CMakeCache file. + +######################## +# EXTERNAL cache entries +######################## + +set (BUILD_SHARED_LIBS OFF CACHE BOOL "Build Shared Libraries" FORCE) + +set (H4EX_BUILD_TESTING ON CACHE BOOL "Build HDF4 Unit Testing" FORCE) + +set (COMPARE_TESTING ON CACHE BOOL "Compare HDF4 Unit Testing to Reference" FORCE) + +set (PACK_EXAMPLE_SOURCE ON CACHE BOOL "Package the source" FORCE) + +set (HDF_BUILD_C ON CACHE BOOL "Build C support" FORCE) + +set (HDF_BUILD_FORTRAN OFF CACHE BOOL "Build FORTRAN support" FORCE) + +set (HDF_BUILD_JAVA ON CACHE BOOL "Build Java support" FORCE) + +set (HDF4_PACKAGE_NAME "hdf4" CACHE STRING "Name of HDF4 package" FORCE) + +set (HDF4_NAMESPACE "hdf4::" CACHE STRING "Name space of HDF4 library" FORCE) + +set (CPACK_PACKAGE_VERSION "0.3.10" CACHE STRING "Version of HDF4 source package" FORCE) diff --git a/HDF4Examples/config/cmake/grepTest.cmake b/HDF4Examples/config/cmake/grepTest.cmake new file mode 100644 index 0000000000..f5d66ee9e1 --- /dev/null +++ b/HDF4Examples/config/cmake/grepTest.cmake @@ -0,0 +1,204 @@ +# grepTest.cmake executes a command and captures the output in a file. File is then compared +# against a reference file. Exit status of command can also be compared. + +# arguments checking +if (NOT TEST_PROGRAM) + message (FATAL_ERROR "Require TEST_PROGRAM to be defined") +endif () +if (NOT TEST_FOLDER) + message (FATAL_ERROR "Require TEST_FOLDER to be defined") +endif () +if (NOT TEST_OUTPUT) + message (FATAL_ERROR "Require TEST_OUTPUT to be defined") +endif () +if (NOT TEST_FILTER) + message (STATUS "Optional TEST_FILTER to be defined") +endif () +if (NOT TEST_REFERENCE) + message (FATAL_ERROR "Require TEST_REFERENCE to be defined") +endif () + +if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}") + file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT}) +endif () + +if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}.err") + file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT}.err) +endif () + +message (STATUS "COMMAND: ${TEST_EMULATOR} ${TEST_PROGRAM} ${TEST_ARGS}") + +if (TEST_LIBRARY_DIRECTORY) + if (WIN32) + set (ENV{PATH} "$ENV{PATH};${TEST_LIBRARY_DIRECTORY}") + elseif (APPLE) + set (ENV{DYLD_LIBRARY_PATH} "$ENV{DYLD_LIBRARY_PATH}:${TEST_LIBRARY_DIRECTORY}") + else () + set (ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH}:${TEST_LIBRARY_DIRECTORY}") + endif () +endif () + +if (TEST_ENV_VAR) + set (ENV{${TEST_ENV_VAR}} "${TEST_ENV_VALUE}") + if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0") + message (TRACE "ENV:${TEST_ENV_VAR}=$ENV{${TEST_ENV_VAR}}") + endif () +endif () + +# run the test program, capture the stdout/stderr and the result var +execute_process ( + COMMAND ${TEST_EMULATOR} ${TEST_PROGRAM} ${TEST_ARGS} + WORKING_DIRECTORY ${TEST_FOLDER} + RESULT_VARIABLE TEST_RESULT + OUTPUT_FILE ${TEST_OUTPUT} + ERROR_FILE ${TEST_OUTPUT}.err + OUTPUT_VARIABLE TEST_OUT + ERROR_VARIABLE TEST_ERROR +) + +message (STATUS "COMMAND Result: ${TEST_RESULT}") + +message (STATUS "COMMAND Error: ${TEST_ERROR}") + +# remove special output +file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) +string (FIND TEST_STREAM "_pmi_alps" TEST_FIND_RESULT) +if (TEST_FIND_RESULT GREATER -1) + string (REGEX REPLACE "^.*_pmi_alps[^\n]+\n" "" TEST_STREAM "${TEST_STREAM}") + file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} ${TEST_STREAM}) +endif () + +# if the TEST_ERRREF exists grep the error output with the error reference +set (TEST_ERRREF_RESULT 0) +if (TEST_ERRREF) + # if the .err file exists grep the error output with the error reference before comparing stdout + if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}.err") + file (READ ${TEST_FOLDER}/${TEST_OUTPUT}.err TEST_ERR_STREAM) + list (LENGTH TEST_ERR_STREAM test_len) + if (test_len GREATER 0) + # TEST_ERRREF should always be matched + string (REGEX MATCH "${TEST_ERRREF}" TEST_MATCH ${TEST_ERR_STREAM}) + string (COMPARE EQUAL "${TEST_ERRREF}" "${TEST_MATCH}" TEST_ERRREF_RESULT) + if (NOT TEST_ERRREF_RESULT) + message (FATAL_ERROR "Failed: The error output of ${TEST_PROGRAM} did not contain ${TEST_ERRREF}") + endif () + endif () + endif () + + #always compare output file to reference unless this must be skipped + set (TEST_COMPARE_RESULT 0) + if (NOT TEST_SKIP_COMPARE) + if (EXISTS "${TEST_FOLDER}/${TEST_REFERENCE}") + file (READ ${TEST_FOLDER}/${TEST_REFERENCE} TEST_STREAM) + list (LENGTH TEST_STREAM test_len) + if (test_len GREATER 0) + if (WIN32) + configure_file(${TEST_FOLDER}/${TEST_REFERENCE} ${TEST_FOLDER}/${TEST_REFERENCE}.tmp NEWLINE_STYLE CRLF) + if (EXISTS "${TEST_FOLDER}/${TEST_REFERENCE}.tmp") + file(RENAME ${TEST_FOLDER}/${TEST_REFERENCE}.tmp ${TEST_FOLDER}/${TEST_REFERENCE}) + endif () + #file (READ ${TEST_FOLDER}/${TEST_REFERENCE} TEST_STREAM) + #file (WRITE ${TEST_FOLDER}/${TEST_REFERENCE} "${TEST_STREAM}") + endif () + if (NOT TEST_SORT_COMPARE) + # now compare the output with the reference + execute_process ( + COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_IGNORE_EOL} ${TEST_FOLDER}/${TEST_OUTPUT} ${TEST_FOLDER}/${TEST_REFERENCE} + RESULT_VARIABLE TEST_COMPARE_RESULT + ) + else () + file (STRINGS ${TEST_FOLDER}/${TEST_OUTPUT} v1) + file (STRINGS ${TEST_FOLDER}/${TEST_REFERENCE} v2) + list (SORT v1) + list (SORT v2) + if (NOT v1 STREQUAL v2) + set(TEST_COMPARE_RESULT 1) + endif () + endif () + + if (TEST_COMPARE_RESULT) + set (TEST_COMPARE_RESULT 0) + file (STRINGS ${TEST_FOLDER}/${TEST_OUTPUT} test_act) + list (LENGTH test_act len_act) + file (STRINGS ${TEST_FOLDER}/${TEST_REFERENCE} test_ref) + list (LENGTH test_ref len_ref) + if (len_act GREATER 0 AND len_ref GREATER 0) + math (EXPR _FP_LEN "${len_ref} - 1") + foreach (line RANGE 0 ${_FP_LEN}) + list (GET test_act ${line} str_act) + list (GET test_ref ${line} str_ref) + if (NOT str_act STREQUAL str_ref) + if (str_act) + set (TEST_COMPARE_RESULT 1) + message (STATUS "line = ${line}\n***ACTUAL: ${str_act}\n****REFER: ${str_ref}\n") + endif () + endif () + endforeach () + else () + if (len_act EQUAL 0) + message (STATUS "COMPARE Failed: ${TEST_FOLDER}/${TEST_OUTPUT} is empty") + endif () + if (len_ref EQUAL 0) + message (STATUS "COMPARE Failed: ${TEST_FOLDER}/${TEST_REFERENCE} is empty") + endif () + endif () + if (NOT len_act EQUAL len_ref) + set (TEST_COMPARE_RESULT 1) + endif () + endif () + endif () + + message (STATUS "COMPARE Result: ${TEST_COMPARE_RESULT}") + + # again, if return value is !=0 scream and shout + if (TEST_COMPARE_RESULT) + message (FATAL_ERROR "Failed: The output of ${TEST_OUTPUT} did not match ${TEST_REFERENCE}") + endif () + endif () + endif () +else () + # else grep the output with the reference + set (TEST_GREP_RESULT 0) + file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) + list (LENGTH TEST_STREAM test_len) + if (test_len GREATER 0) + # TEST_REFERENCE should always be matched + string (REGEX MATCH "${TEST_REFERENCE}" TEST_MATCH ${TEST_STREAM}) + string (COMPARE EQUAL "${TEST_REFERENCE}" "${TEST_MATCH}" TEST_GREP_RESULT) + if (NOT TEST_GREP_RESULT) + message (FATAL_ERROR "Failed: The output of ${TEST_PROGRAM} did not contain ${TEST_REFERENCE}") + endif () + endif () +endif () + + +if (TEST_FILTER) + string (REGEX MATCH "${TEST_FILTER}" TEST_MATCH ${TEST_STREAM}) + if (TEST_EXPECT) + # TEST_EXPECT (1) interprets TEST_FILTER as; NOT to match + string (LENGTH "${TEST_MATCH}" TEST_GREP_RESULT) + if (TEST_GREP_RESULT) + message (FATAL_ERROR "Failed: The output of ${TEST_PROGRAM} did contain ${TEST_FILTER}") + endif () + endif () +endif () + +if (NOT DEFINED ENV{HDF4_NOCLEANUP}) + if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}") + file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT}) + endif () + + if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}.err") + file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT}.err) + endif () + + if (TEST_DELETE_LIST) + foreach (dfile in ${TEST_DELETE_LIST}) + file (REMOVE ${dfile}) + endforeach () + endif () +endif () + +# everything went fine... +message (STATUS "Passed: The output of ${TEST_PROGRAM} matched") + diff --git a/HDF4Examples/config/cmake/javaTargets.cmake.in b/HDF4Examples/config/cmake/javaTargets.cmake.in new file mode 100644 index 0000000000..6e14256a13 --- /dev/null +++ b/HDF4Examples/config/cmake/javaTargets.cmake.in @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 2.8.12) +cmake_policy(PUSH) +cmake_policy(VERSION 2.8) + +#---------------------------------------------------------------- +# Generated CMake Java target import file. +#---------------------------------------------------------------- + +# Protect against multiple inclusion, which would fail when already imported targets are added once more. +set(_targetsDefined) +set(_targetsNotDefined) +set(_expectedTargets) +foreach(_expectedTarget @__targets__@) + list(APPEND _expectedTargets ${_expectedTarget}) + if(TARGET ${_expectedTarget}) + list(APPEND _targetsDefined ${_expectedTarget}) + else() + list(APPEND _targetsNotDefined ${_expectedTarget}) + endif() +endforeach() +if("%${_targetsDefined}" STREQUAL "%${_expectedTargets}") + unset(_targetsDefined) + unset(_targetsNotDefined) + unset(_expectedTargets) + cmake_policy(POP) + return() +endif() +if(NOT "${_targetsDefined}" STREQUAL "") + message(FATAL_ERROR + "Some (but not all) targets in this export set were already defined.\n" + "Targets Defined: ${_targetsDefined}\n" + "Targets not yet defined: ${_targetsNotDefined}\n") +endif() +unset(_targetsDefined) +unset(_targetsNotDefined) +unset(_expectedTargets) + +@__targetdefs__@ +cmake_policy(POP) diff --git a/HDF4Examples/config/cmake/jrunTest.cmake b/HDF4Examples/config/cmake/jrunTest.cmake new file mode 100644 index 0000000000..21ce16b2b9 --- /dev/null +++ b/HDF4Examples/config/cmake/jrunTest.cmake @@ -0,0 +1,303 @@ +# jrunTest.cmake executes a command and captures the output in a file. File is then compared +# against a reference file. Exit status of command can also be compared. +cmake_policy(SET CMP0007 NEW) + +# arguments checking +if (NOT TEST_TESTER) + message (FATAL_ERROR "Require TEST_TESTER to be defined") +endif () +if (NOT TEST_PROGRAM) + message (FATAL_ERROR "Require TEST_PROGRAM to be defined") +endif () +if (NOT TEST_LIBRARY_DIRECTORY) + message (STATUS "Require TEST_LIBRARY_DIRECTORY to be defined") +endif () +if (NOT TEST_FOLDER) + message (FATAL_ERROR "Require TEST_FOLDER to be defined") +endif () +if (NOT TEST_OUTPUT) + message (FATAL_ERROR "Require TEST_OUTPUT to be defined") +endif () +if (NOT TEST_CLASSPATH) + message (STATUS "Require TEST_CLASSPATH to be defined") +endif () + +if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}") + file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT}) +endif () + +if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}.err") + file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT}.err) +endif () + +if (NOT TEST_LOG_LEVEL) + set (LOG_LEVEL "info") +else () + set (LOG_LEVEL "${TEST_LOG_LEVEL}") +endif () + +message (STATUS "COMMAND: ${TEST_TESTER} -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=${LOG_LEVEL} -Djava.library.path=\"${TEST_LIBRARY_DIRECTORY}\" -cp \"${TEST_CLASSPATH}\" ${TEST_ARGS} ${TEST_PROGRAM} ${ARGN}") + +if (WIN32) + set (ENV{PATH} "$ENV{PATH}\\;${TEST_LIBRARY_DIRECTORY}") +elseif (APPLE) + set (ENV{DYLD_LIBRARY_PATH} "$ENV{DYLD_LIBRARY_PATH}:${TEST_LIBRARY_DIRECTORY}") +else () + set (ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH}:${TEST_LIBRARY_DIRECTORY}") +endif () + +# run the test program, capture the stdout/stderr and the result var +execute_process ( + COMMAND ${TEST_TESTER} -Xmx1024M + -Dorg.slf4j.simpleLogger.defaultLogLevel=${LOG_LEVEL} + -Djava.library.path=${TEST_LIBRARY_DIRECTORY} + -cp "${TEST_CLASSPATH}" ${TEST_ARGS} ${TEST_PROGRAM} + ${ARGN} + WORKING_DIRECTORY ${TEST_FOLDER} + RESULT_VARIABLE TEST_RESULT + OUTPUT_FILE ${TEST_OUTPUT} + ERROR_FILE ${TEST_OUTPUT}.err + OUTPUT_VARIABLE TEST_OUT + ERROR_VARIABLE TEST_ERROR +) + +message (STATUS "COMMAND Result: ${TEST_RESULT}") + +# if the .err file exists and ERRROR_APPEND is enabled +if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}.err") + file (READ ${TEST_FOLDER}/${TEST_OUTPUT}.err TEST_STREAM) + list (LENGTH TEST_STREAM test_len) + if (test_len GREATER 0) + if (TEST_MASK_FILE) + STRING(REGEX REPLACE "CurrentDir is [^\n]+\n" "CurrentDir is (dir name)\n" TEST_STREAM "${TEST_STREAM}") + endif () + + if (NOT ERROR_APPEND) + # write back to original .err file + file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT}.err "${TEST_STREAM}") + else () + # append error output to the stdout output file + file (APPEND ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}") + endif () + endif () +endif () + +# if the output file or the .err file needs to mask out error stack info +if (TEST_MASK_ERROR) + if (NOT TEST_ERRREF) + # the error stack has been appended to the output file + file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) + else () + # the error stack remains in the .err file + file (READ ${TEST_FOLDER}/${TEST_OUTPUT}.err TEST_STREAM) + endif () + string (REGEX REPLACE "Time:[^\n]+\n" "Time: XXXX\n" TEST_STREAM "${TEST_STREAM}") + string (REGEX REPLACE "thread [0-9]*:" "thread (IDs):" TEST_STREAM "${TEST_STREAM}") + string (REGEX REPLACE ": ([^\n]*)[.]c " ": (file name) " TEST_STREAM "${TEST_STREAM}") + string (REGEX REPLACE " line [0-9]*" " line (number)" TEST_STREAM "${TEST_STREAM}") + #string (REGEX REPLACE "v[1-9]*[.][0-9]*[.]" "version (number)." TEST_STREAM "${TEST_STREAM}") + string (REGEX REPLACE "HDF4 .[1-9]*[.][0-9]*[.][0-9]*[^)]*" "HDF4 (version (number)" TEST_STREAM "${TEST_STREAM}") + # write back the changes to the original files + if (NOT TEST_ERRREF) + file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}") + else () + file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT}.err "${TEST_STREAM}") + endif () +endif () + +# if the return value is !=expected bail out +if (NOT TEST_RESULT EQUAL TEST_EXPECT) + message (STATUS "ERROR OUTPUT: ${TEST_STREAM}") + message (FATAL_ERROR "Failed: Test program ${TEST_PROGRAM} exited != 0.\n${TEST_ERROR}") +endif () + +message (STATUS "COMMAND Error: ${TEST_ERROR}") + +# compare output files to references unless this must be skipped +set (TEST_COMPARE_RESULT 0) +if (NOT TEST_SKIP_COMPARE) + if (EXISTS "${TEST_FOLDER}/${TEST_REFERENCE}") + file (READ ${TEST_FOLDER}/${TEST_REFERENCE} TEST_STREAM) + list (LENGTH TEST_STREAM test_len) + if (test_len GREATER 0) + if (WIN32) + configure_file(${TEST_FOLDER}/${TEST_REFERENCE} ${TEST_FOLDER}/${TEST_REFERENCE}.tmp NEWLINE_STYLE CRLF) + if (EXISTS "${TEST_FOLDER}/${TEST_REFERENCE}.tmp") + file(RENAME ${TEST_FOLDER}/${TEST_REFERENCE}.tmp ${TEST_FOLDER}/${TEST_REFERENCE}) + endif () + #file (READ ${TEST_FOLDER}/${TEST_REFERENCE} TEST_STREAM) + #file (WRITE ${TEST_FOLDER}/${TEST_REFERENCE} "${TEST_STREAM}") + endif () + + if (NOT TEST_SORT_COMPARE) + # now compare the output with the reference + execute_process ( + COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_IGNORE_EOL} ${TEST_FOLDER}/${TEST_OUTPUT} ${TEST_FOLDER}/${TEST_REFERENCE} + RESULT_VARIABLE TEST_COMPARE_RESULT + ) + else () + file (STRINGS ${TEST_FOLDER}/${TEST_OUTPUT} v1) + file (STRINGS ${TEST_FOLDER}/${TEST_REFERENCE} v2) + list (SORT v1) + list (SORT v2) + if (NOT v1 STREQUAL v2) + set(TEST_COMPARE_RESULT 1) + endif () + endif () + + if (TEST_COMPARE_RESULT) + set (TEST_COMPARE_RESULT 0) + file (STRINGS ${TEST_FOLDER}/${TEST_OUTPUT} test_act) + list (LENGTH test_act len_act) + file (STRINGS ${TEST_FOLDER}/${TEST_REFERENCE} test_ref) + list (LENGTH test_ref len_ref) + if (len_act GREATER 0 AND len_ref GREATER 0) + math (EXPR _FP_LEN "${len_ref} - 1") + foreach (line RANGE 0 ${_FP_LEN}) + list (GET test_act ${line} str_act) + list (GET test_ref ${line} str_ref) + if (NOT str_act STREQUAL str_ref) + if (str_act) + set (TEST_COMPARE_RESULT 1) + message (STATUS "line = ${line}\n***ACTUAL: ${str_act}\n****REFER: ${str_ref}\n") + endif () + endif () + endforeach () + else () + if (len_act EQUAL 0) + message (STATUS "COMPARE Failed: ${TEST_FOLDER}/${TEST_OUTPUT} is empty") + endif () + if (len_ref EQUAL 0) + message (STATUS "COMPARE Failed: ${TEST_FOLDER}/${TEST_REFERENCE} is empty") + endif () + endif () + if (NOT len_act EQUAL len_ref) + set (TEST_COMPARE_RESULT 1) + endif () + endif () + endif () + + message (STATUS "COMPARE Result: ${TEST_COMPARE_RESULT}") + + # again, if return value is !=0 scream and shout + if (TEST_COMPARE_RESULT) + message (FATAL_ERROR "Failed: The output of ${TEST_OUTPUT} did not match ${TEST_REFERENCE}") + endif () + endif () + + # now compare the .err file with the error reference, if supplied + set (TEST_ERRREF_RESULT 0) + if (TEST_ERRREF) + file (READ ${TEST_FOLDER}/${TEST_ERRREF} TEST_STREAM) + list (LENGTH TEST_STREAM test_len) + if (test_len GREATER 0) + if (WIN32) + configure_file(${TEST_FOLDER}/${TEST_ERRREF} ${TEST_FOLDER}/${TEST_ERRREF}.tmp NEWLINE_STYLE CRLF) + if (EXISTS "${TEST_FOLDER}/${TEST_ERRREF}.tmp") + file(RENAME ${TEST_FOLDER}/${TEST_ERRREF}.tmp ${TEST_FOLDER}/${TEST_ERRREF}) + endif () + #file (READ ${TEST_FOLDER}/${TEST_ERRREF} TEST_STREAM) + #file (WRITE ${TEST_FOLDER}/${TEST_ERRREF} "${TEST_STREAM}") + endif () + + # now compare the error output with the error reference + execute_process ( + COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_IGNORE_EOL} ${TEST_FOLDER}/${TEST_OUTPUT}.err ${TEST_FOLDER}/${TEST_ERRREF} + RESULT_VARIABLE TEST_ERRREF_RESULT + ) + if (TEST_ERRREF_RESULT) + set (TEST_ERRREF_RESULT 0) + file (STRINGS ${TEST_FOLDER}/${TEST_OUTPUT}.err test_act) + list (LENGTH test_act len_act) + file (STRINGS ${TEST_FOLDER}/${TEST_ERRREF} test_ref) + list (LENGTH test_ref len_ref) + math (EXPR _FP_LEN "${len_ref} - 1") + if (len_act GREATER 0 AND len_ref GREATER 0) + math (EXPR _FP_LEN "${len_ref} - 1") + foreach (line RANGE 0 ${_FP_LEN}) + list (GET test_act ${line} str_act) + list (GET test_ref ${line} str_ref) + if (NOT str_act STREQUAL str_ref) + if (str_act) + set (TEST_ERRREF_RESULT 1) + message (STATUS "line = ${line}\n***ACTUAL: ${str_act}\n****REFER: ${str_ref}\n") + endif () + endif () + endforeach () + else () + if (len_act EQUAL 0) + message (STATUS "COMPARE Failed: ${TEST_FOLDER}/${TEST_OUTPUT}.err is empty") + endif () + if (len_ref EQUAL 0) + message (STATUS "COMPARE Failed: ${TEST_FOLDER}/${TEST_ERRREF} is empty") + endif () + endif () + if (NOT len_act EQUAL len_ref) + set (TEST_ERRREF_RESULT 1) + endif () + endif () + endif () + + message (STATUS "COMPARE Result: ${TEST_ERRREF_RESULT}") + + # again, if return value is !=0 scream and shout + if (TEST_ERRREF_RESULT) + message (FATAL_ERROR "Failed: The error output of ${TEST_OUTPUT}.err did not match ${TEST_ERRREF}") + endif () + endif () +endif () + +set (TEST_GREP_RESULT 0) +if (TEST_GREP_COMPARE) + # now grep the output with the reference + file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) + list (LENGTH TEST_STREAM test_len) + if (test_len GREATER 0) + # TEST_REFERENCE should always be matched + string (REGEX MATCH "${TEST_REFERENCE}" TEST_MATCH ${TEST_STREAM}) + string (COMPARE EQUAL "${TEST_REFERENCE}" "${TEST_MATCH}" TEST_GREP_RESULT) + if (NOT TEST_GREP_RESULT) + message (FATAL_ERROR "Failed: The output of ${TEST_PROGRAM} did not contain ${TEST_REFERENCE}") + endif () + + string (REGEX MATCH "${TEST_FILTER}" TEST_MATCH ${TEST_STREAM}) + if (TEST_EXPECT) + # TEST_EXPECT (1) interprets TEST_FILTER as; NOT to match + string (LENGTH "${TEST_MATCH}" TEST_GREP_RESULT) + if (TEST_GREP_RESULT) + message (FATAL_ERROR "Failed: The output of ${TEST_PROGRAM} did contain ${TEST_FILTER}") + endif () + endif () + endif () +endif () + +# dump the output unless nodisplay option is set +if (TEST_SKIP_COMPARE AND NOT TEST_NO_DISPLAY) + if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}") + file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) + execute_process ( + COMMAND ${CMAKE_COMMAND} -E echo ${TEST_STREAM} + RESULT_VARIABLE TEST_RESULT + ) + endif () +endif () + +if (NOT DEFINED ENV{HDF4_NOCLEANUP}) + if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}") + file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT}) + endif () + + if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}.err") + file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT}.err) + endif () + + if (TEST_DELETE_LIST) + foreach (dfile in ${TEST_DELETE_LIST}) + file (REMOVE ${dfile}) + endforeach () + endif () +endif () + +# everything went fine... +message (STATUS "${TEST_PROGRAM} Passed") + diff --git a/HDF4Examples/config/cmake/runTest.cmake b/HDF4Examples/config/cmake/runTest.cmake new file mode 100644 index 0000000000..2deb4ab434 --- /dev/null +++ b/HDF4Examples/config/cmake/runTest.cmake @@ -0,0 +1,390 @@ +# runTest.cmake executes a command and captures the output in a file. File is then compared +# against a reference file. Exit status of command can also be compared. +cmake_policy(SET CMP0007 NEW) + +# arguments checking +if (NOT TEST_PROGRAM) + message (FATAL_ERROR "Require TEST_PROGRAM to be defined") +endif () +if (NOT TEST_FOLDER) + message (FATAL_ERROR "Require TEST_FOLDER to be defined") +endif () +if (NOT TEST_OUTPUT) + message (FATAL_ERROR "Require TEST_OUTPUT to be defined") +endif () +if (NOT TEST_EXPECT) + message (STATUS "Require TEST_EXPECT to be defined") +endif () + +if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}") + file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT}) +endif () + +if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}.err") + file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT}.err) +endif () + +message (STATUS "COMMAND: ${TEST_EMULATOR} ${TEST_PROGRAM} ${TEST_ARGS}") + +if (TEST_LIBRARY_DIRECTORY) + if (WIN32) + set (ENV{PATH} "$ENV{PATH};${TEST_LIBRARY_DIRECTORY}") + elseif (APPLE) + set (ENV{DYLD_LIBRARY_PATH} "$ENV{DYLD_LIBRARY_PATH}:${TEST_LIBRARY_DIRECTORY}") + else () + set (ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH}:${TEST_LIBRARY_DIRECTORY}") + endif () +endif () + +if (TEST_ENV_VAR) + set (ENV{${TEST_ENV_VAR}} "${TEST_ENV_VALUE}") + #message (STATUS "ENV:${TEST_ENV_VAR}=$ENV{${TEST_ENV_VAR}}") +endif () + +if (NOT TEST_INPUT) + # run the test program, capture the stdout/stderr and the result var + execute_process ( + COMMAND ${TEST_EMULATOR} ${TEST_PROGRAM} ${TEST_ARGS} + WORKING_DIRECTORY ${TEST_FOLDER} + RESULT_VARIABLE TEST_RESULT + OUTPUT_FILE ${TEST_OUTPUT} + ERROR_FILE ${TEST_OUTPUT}.err + OUTPUT_VARIABLE TEST_OUT + ERROR_VARIABLE TEST_ERROR + ) +else () + # run the test program with stdin, capture the stdout/stderr and the result var + execute_process ( + COMMAND ${TEST_EMULATOR} ${TEST_PROGRAM} ${TEST_ARGS} + WORKING_DIRECTORY ${TEST_FOLDER} + RESULT_VARIABLE TEST_RESULT + INPUT_FILE ${TEST_INPUT} + OUTPUT_FILE ${TEST_OUTPUT} + ERROR_FILE ${TEST_OUTPUT}.err + OUTPUT_VARIABLE TEST_OUT + ERROR_VARIABLE TEST_ERROR + ) +endif () + +if (TEST_REGEX) + # TEST_REGEX should always be matched + file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) + string (REGEX MATCH "${TEST_REGEX}" REGEX_MATCH ${TEST_STREAM}) + string (COMPARE EQUAL "${REGEX_MATCH}" "${TEST_MATCH}" REGEX_RESULT) + if (NOT REGEX_RESULT) + message (STATUS "Failed: The output of ${TEST_PROGRAM} did not contain ${TEST_MATCH}") + endif () +endif () + +message (STATUS "COMMAND Result: ${TEST_RESULT}") + +# if the .err file exists and ERRROR_APPEND is enabled +if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}.err") + file (READ ${TEST_FOLDER}/${TEST_OUTPUT}.err TEST_STREAM) + list (LENGTH TEST_STREAM test_len) + if (test_len GREATER 0) + if (TEST_MASK_FILE) + STRING(REGEX REPLACE "CurrentDir is [^\n]+\n" "CurrentDir is (dir name)\n" TEST_STREAM "${TEST_STREAM}") + endif () + # remove special output + string (REGEX REPLACE "^.*_pmi_alps[^\n]+\n" "" TEST_STREAM "${TEST_STREAM}") + + if (NOT ERROR_APPEND) + # write back to original .err file + file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT}.err "${TEST_STREAM}") + else () + # append error output to the stdout output file + file (APPEND ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}") + endif () + endif () +endif () + +# append the test result status with a predefined text +if (TEST_APPEND) + file (APPEND ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_APPEND} ${TEST_RESULT}\n") +endif () + +# if the return value is !=${TEST_EXPECT} bail out +if (NOT TEST_RESULT EQUAL TEST_EXPECT) + if (NOT TEST_NOERRDISPLAY) + if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}") + file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) + message (STATUS "Output :\n${TEST_STREAM}") + endif () + if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}.err") + file (READ ${TEST_FOLDER}/${TEST_OUTPUT}.err TEST_STREAM) + message (STATUS "Error Output :\n${TEST_STREAM}") + endif () + endif () + message (FATAL_ERROR "Failed: Test program ${TEST_PROGRAM} exited != ${TEST_EXPECT}.\n${TEST_ERROR}") +endif () + +message (STATUS "COMMAND Error: ${TEST_ERROR}") + +# remove special output +file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) +string (FIND TEST_STREAM "_pmi_alps" TEST_FIND_RESULT) +if (TEST_FIND_RESULT GREATER -1) + string (REGEX REPLACE "^.*_pmi_alps[^\n]+\n" "" TEST_STREAM "${TEST_STREAM}") + file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} ${TEST_STREAM}) +endif () + +# remove special error output +if (NOT TEST_ERRREF) + # the error stack has been appended to the output file + file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) +else () + # the error stack remains in the .err file + file (READ ${TEST_FOLDER}/${TEST_OUTPUT}.err TEST_STREAM) +endif () +string (FIND TEST_STREAM "no version information available" TEST_FIND_RESULT) +if (TEST_FIND_RESULT GREATER -1) + string (REGEX REPLACE "^.*no version information available[^\n]+\n" "" TEST_STREAM "${TEST_STREAM}") + # write back the changes to the original files + if (NOT TEST_ERRREF) + file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}") + else () + file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT}.err "${TEST_STREAM}") + endif () +endif () + +# if the output file needs Storage text removed +if (TEST_MASK) + file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) + string (REGEX REPLACE "Storage:[^\n]+\n" "Storage: <details removed for portability>\n" TEST_STREAM "${TEST_STREAM}") + file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}") +endif () + +# if the output file needs Modified text removed +if (TEST_MASK_MOD) + file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) + string (REGEX REPLACE "Modified:[^\n]+\n" "Modified: XXXX-XX-XX XX:XX:XX XXX\n" TEST_STREAM "${TEST_STREAM}") + file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}") +endif () + +# if the output file or the .err file needs to mask out error stack info +if (TEST_MASK_ERROR) + if (NOT TEST_ERRREF) + # the error stack has been appended to the output file + file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) + else () + # the error stack remains in the .err file + file (READ ${TEST_FOLDER}/${TEST_OUTPUT}.err TEST_STREAM) + endif () + string (REGEX REPLACE "thread [0-9]*:" "thread (IDs):" TEST_STREAM "${TEST_STREAM}") + string (REGEX REPLACE ": ([^\n]*)[.]c " ": (file name) " TEST_STREAM "${TEST_STREAM}") + string (REGEX REPLACE " line [0-9]*" " line (number)" TEST_STREAM "${TEST_STREAM}") + string (REGEX REPLACE "v[1-9]*[.][0-9]*[.]" "version (number)." TEST_STREAM "${TEST_STREAM}") + string (REGEX REPLACE "[1-9]*[.][0-9]*[.][0-9]*[^)]*" "version (number)" TEST_STREAM "${TEST_STREAM}") + # write back the changes to the original files + if (NOT TEST_ERRREF) + file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}") + else () + file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT}.err "${TEST_STREAM}") + endif () +endif () + +# remove text from the output file +if (TEST_FILTER) + file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) + string (REGEX REPLACE "${TEST_FILTER}" "${TEST_FILTER_REPLACE}" TEST_STREAM "${TEST_STREAM}") + file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}") +endif () + +if (TEST_REF_FILTER) + #message (STATUS "TEST_REF_FILTER: ${TEST_APPEND}${TEST_REF_FILTER}") + file (READ ${TEST_FOLDER}/${TEST_REFERENCE} TEST_STREAM) + string (REGEX REPLACE "${TEST_REF_APPEND}" "${TEST_REF_FILTER}" TEST_STREAM "${TEST_STREAM}") + file (WRITE ${TEST_FOLDER}/${TEST_REFERENCE} "${TEST_STREAM}") +endif () + +# compare output files to references unless this must be skipped +set (TEST_COMPARE_RESULT 0) +if (NOT TEST_SKIP_COMPARE) + if (EXISTS "${TEST_FOLDER}/${TEST_REFERENCE}") + file (READ ${TEST_FOLDER}/${TEST_REFERENCE} TEST_STREAM) + list (LENGTH TEST_STREAM test_len) + if (test_len GREATER 0) + if (WIN32) + configure_file(${TEST_FOLDER}/${TEST_REFERENCE} ${TEST_FOLDER}/${TEST_REFERENCE}.tmp NEWLINE_STYLE CRLF) + if (EXISTS "${TEST_FOLDER}/${TEST_REFERENCE}.tmp") + file(RENAME ${TEST_FOLDER}/${TEST_REFERENCE}.tmp ${TEST_FOLDER}/${TEST_REFERENCE}) + endif () + #file (READ ${TEST_FOLDER}/${TEST_REFERENCE} TEST_STREAM) + #file (WRITE ${TEST_FOLDER}/${TEST_REFERENCE} "${TEST_STREAM}") + endif () + + if (NOT TEST_SORT_COMPARE) + # now compare the output with the reference + execute_process ( + COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_IGNORE_EOL} ${TEST_FOLDER}/${TEST_OUTPUT} ${TEST_FOLDER}/${TEST_REFERENCE} + RESULT_VARIABLE TEST_COMPARE_RESULT + ) + else () + file (STRINGS ${TEST_FOLDER}/${TEST_OUTPUT} v1) + file (STRINGS ${TEST_FOLDER}/${TEST_REFERENCE} v2) + list (SORT v1) + list (SORT v2) + if (NOT v1 STREQUAL v2) + set (TEST_COMPARE_RESULT 1) + endif () + endif () + + if (TEST_COMPARE_RESULT) + set (TEST_COMPARE_RESULT 0) + file (STRINGS ${TEST_FOLDER}/${TEST_OUTPUT} test_act) + list (LENGTH test_act len_act) + file (STRINGS ${TEST_FOLDER}/${TEST_REFERENCE} test_ref) + list (LENGTH test_ref len_ref) + if (NOT len_act EQUAL len_ref) + set (TEST_COMPARE_RESULT 1) + endif () + if (len_act GREATER 0 AND len_ref GREATER 0) + if (TEST_SORT_COMPARE) + list (SORT test_act) + list (SORT test_ref) + endif () + math (EXPR _FP_LEN "${len_ref} - 1") + foreach (line RANGE 0 ${_FP_LEN}) + list (GET test_act ${line} str_act) + list (GET test_ref ${line} str_ref) + if (NOT str_act STREQUAL str_ref) + if (str_act) + set (TEST_COMPARE_RESULT 1) + message (STATUS "line = ${line}\n***ACTUAL: ${str_act}\n****REFER: ${str_ref}\n") + endif () + endif () + endforeach () + else () + if (len_act EQUAL 0) + message (STATUS "COMPARE Failed: ${TEST_FOLDER}/${TEST_OUTPUT} is empty") + endif () + if (len_ref EQUAL 0) + message (STATUS "COMPARE Failed: ${TEST_FOLDER}/${TEST_REFERENCE} is empty") + endif () + endif () + endif () + endif () + + message (STATUS "COMPARE Result: ${TEST_COMPARE_RESULT}") + + # again, if return value is !=0 scream and shout + if (TEST_COMPARE_RESULT) + message (FATAL_ERROR "Failed: The output of ${TEST_OUTPUT} did not match ${TEST_REFERENCE}") + endif () + endif () + + # now compare the .err file with the error reference, if supplied + set (TEST_ERRREF_RESULT 0) + if (TEST_ERRREF) + file (READ ${TEST_FOLDER}/${TEST_ERRREF} TEST_STREAM) + list (LENGTH TEST_STREAM test_len) + if (test_len GREATER 0) + if (WIN32) + configure_file(${TEST_FOLDER}/${TEST_ERRREF} ${TEST_FOLDER}/${TEST_ERRREF}.tmp NEWLINE_STYLE CRLF) + if (EXISTS "${TEST_FOLDER}/${TEST_ERRREF}.tmp") + file(RENAME ${TEST_FOLDER}/${TEST_ERRREF}.tmp ${TEST_FOLDER}/${TEST_ERRREF}) + endif () + #file (READ ${TEST_FOLDER}/${TEST_ERRREF} TEST_STREAM) + #file (WRITE ${TEST_FOLDER}/${TEST_ERRREF} "${TEST_STREAM}") + endif () + + # now compare the error output with the error reference + execute_process ( + COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_IGNORE_EOL} ${TEST_FOLDER}/${TEST_OUTPUT}.err ${TEST_FOLDER}/${TEST_ERRREF} + RESULT_VARIABLE TEST_ERRREF_RESULT + ) + if (TEST_ERRREF_RESULT) + set (TEST_ERRREF_RESULT 0) + file (STRINGS ${TEST_FOLDER}/${TEST_OUTPUT}.err test_act) + list (LENGTH test_act len_act) + file (STRINGS ${TEST_FOLDER}/${TEST_ERRREF} test_ref) + list (LENGTH test_ref len_ref) + math (EXPR _FP_LEN "${len_ref} - 1") + if (len_act GREATER 0 AND len_ref GREATER 0) + math (EXPR _FP_LEN "${len_ref} - 1") + foreach (line RANGE 0 ${_FP_LEN}) + list (GET test_act ${line} str_act) + list (GET test_ref ${line} str_ref) + if (NOT str_act STREQUAL str_ref) + if (str_act) + set (TEST_ERRREF_RESULT 1) + message (STATUS "line = ${line}\n***ACTUAL: ${str_act}\n****REFER: ${str_ref}\n") + endif () + endif () + endforeach () + else () + if (len_act EQUAL 0) + message (STATUS "COMPARE Failed: ${TEST_FOLDER}/${TEST_OUTPUT}.err is empty") + endif () + if (len_ref EQUAL 0) + message (STATUS "COMPARE Failed: ${TEST_FOLDER}/${TEST_ERRREF} is empty") + endif () + endif () + if (NOT len_act EQUAL len_ref) + set (TEST_ERRREF_RESULT 1) + endif () + endif () + endif () + + message (STATUS "COMPARE Result: ${TEST_ERRREF_RESULT}") + + # again, if return value is !=0 scream and shout + if (TEST_ERRREF_RESULT) + message (FATAL_ERROR "Failed: The error output of ${TEST_OUTPUT}.err did not match ${TEST_ERRREF}") + endif () + endif () +endif () + +set (TEST_GREP_RESULT 0) +if (TEST_GREP_COMPARE) + # now grep the output with the reference + file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) + list (LENGTH TEST_STREAM test_len) + if (test_len GREATER 0) + # TEST_REFERENCE should always be matched + string (REGEX MATCH "${TEST_REFERENCE}" TEST_MATCH ${TEST_STREAM}) + string (COMPARE EQUAL "${TEST_REFERENCE}" "${TEST_MATCH}" TEST_GREP_RESULT) + if (NOT TEST_GREP_RESULT) + message (FATAL_ERROR "Failed: The output of ${TEST_PROGRAM} did not contain ${TEST_REFERENCE}") + endif () + + string (REGEX MATCH "${TEST_FILTER}" TEST_MATCH ${TEST_STREAM}) + if (TEST_EXPECT) + # TEST_EXPECT (1) interprets TEST_FILTER as; NOT to match + string (LENGTH "${TEST_MATCH}" TEST_GREP_RESULT) + if (TEST_GREP_RESULT) + message (FATAL_ERROR "Failed: The output of ${TEST_PROGRAM} did contain ${TEST_FILTER}") + endif () + endif () + endif () +endif () + +# dump the output unless nodisplay option is set +if (TEST_SKIP_COMPARE AND NOT TEST_NO_DISPLAY) + file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM) + execute_process ( + COMMAND ${CMAKE_COMMAND} -E echo ${TEST_STREAM} + RESULT_VARIABLE TEST_RESULT + ) +endif () + +if (NOT DEFINED ENV{HDF4_NOCLEANUP}) + if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}" AND NOT TEST_SAVE) + file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT}) + endif () + + if (EXISTS "${TEST_FOLDER}/${TEST_OUTPUT}.err") + file (REMOVE ${TEST_FOLDER}/${TEST_OUTPUT}.err) + endif () + + if (TEST_DELETE_LIST) + foreach (dfile in ${TEST_DELETE_LIST}) + file (REMOVE ${dfile}) + endforeach () + endif () +endif () + +# everything went fine... +message (STATUS "${TEST_PROGRAM} Passed") + diff --git a/HDF4Examples/config/toolchain/aarch64.cmake b/HDF4Examples/config/toolchain/aarch64.cmake new file mode 100644 index 0000000000..03f4e5e9f5 --- /dev/null +++ b/HDF4Examples/config/toolchain/aarch64.cmake @@ -0,0 +1,17 @@ +set(TOOLCHAIN_PREFIX aarch64-linux-gnu) +set(ANDROID_NDK /opt/android-ndk-linux) +set (CMAKE_SYSTEM_NAME Android) +set (CMAKE_ANDROID_ARCH_ABI x86_64) +#set (CMAKE_ANDROID_STANDALONE_TOOLCHAIN ${ANDROID_NDK}/build/cmake/android.toolchain.cmake) +set (CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set (CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +#set (CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) +set (CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran) +set (CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set (CMAKE_CROSSCOMPILING_EMULATOR qemu-aarch64) + +include_directories(/usr/${TOOLCHAIN_PREFIX}/include) + diff --git a/HDF4Examples/config/toolchain/build32.cmake b/HDF4Examples/config/toolchain/build32.cmake new file mode 100644 index 0000000000..f636ea845f --- /dev/null +++ b/HDF4Examples/config/toolchain/build32.cmake @@ -0,0 +1,79 @@ +if (WIN32) + set (CMAKE_SYSTEM_NAME Windows) + set (CMAKE_GENERATOR_PLATFORM "x86") +elseif(APPLE) + set (CMAKE_OSX_ARCHITECTURES "i386") +elseif(MINGW) + set (CMAKE_SYSTEM_NAME Windows) + set (TOOLCHAIN_PREFIX i686-w64-mingw32) + set (CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) + set (CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) + set (CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) + set (CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran) + + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "c flags") + + set (LIB32 /usr/lib) # Fedora + + if (EXISTS "/usr/lib32") + set (LIB32 /usr/lib32) # Arch, Solus + endif () + + set (CMAKE_SYSTEM_LIBRARY_PATH ${LIB32} CACHE STRING "system library search path" FORCE) + set (CMAKE_LIBRARY_PATH ${LIB32} CACHE STRING "library search path" FORCE) + + # this is probably unlikely to be needed, but just in case + set (CMAKE_EXE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "executable linker flags" FORCE) + set (CMAKE_SHARED_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "shared library linker flags" FORCE) + set (CMAKE_MODULE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "module linker flags" FORCE) + + # on Fedora and Arch and similar, point pkgconfig at 32 bit .pc files. We have + # to include the regular system .pc files as well (at the end), because some + # are not always present in the 32 bit directory + if (EXISTS "${LIB32}/pkgconfig") + set (ENV{PKG_CONFIG_LIBDIR} ${LIB32}/pkgconfig:/usr/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib64/pkgconfig) + endif () + + set (CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) + set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + set (CMAKE_CROSSCOMPILING_EMULATOR wine) + + include_directories(/usr/${TOOLCHAIN_PREFIX}/include) + set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS On CACHE BOOL "Export windows symbols") +else () + set (CMAKE_SYSTEM_NAME Linux) + + set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "c++ flags") + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "c flags") + + set (LIB32 /usr/lib) # Fedora + + if (EXISTS "/usr/lib32") + set (LIB32 /usr/lib32) # Arch, Solus + endif () + + set (CMAKE_SYSTEM_LIBRARY_PATH ${LIB32} CACHE STRING "system library search path" FORCE) + set (CMAKE_LIBRARY_PATH ${LIB32} CACHE STRING "library search path" FORCE) + + # this is probably unlikely to be needed, but just in case + set (CMAKE_EXE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "executable linker flags" FORCE) + set (CMAKE_SHARED_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "shared library linker flags" FORCE) + set (CMAKE_MODULE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "module linker flags" FORCE) + + # on Fedora and Arch and similar, point pkgconfig at 32 bit .pc files. We have + # to include the regular system .pc files as well (at the end), because some + # are not always present in the 32 bit directory + if (EXISTS "${LIB32}/pkgconfig") + set (ENV{PKG_CONFIG_LIBDIR} ${LIB32}/pkgconfig:/usr/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib64/pkgconfig) + endif () +# where is the target environment + set (CMAKE_FIND_ROOT_PATH ${LIB32}) +# search for programs in the build host directories + set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +# for libraries and headers in the target directories + set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) + set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +endif () diff --git a/HDF4Examples/config/toolchain/clang.cmake b/HDF4Examples/config/toolchain/clang.cmake new file mode 100644 index 0000000000..2d35641a14 --- /dev/null +++ b/HDF4Examples/config/toolchain/clang.cmake @@ -0,0 +1,16 @@ +# Uncomment the following to use cross-compiling +#set (CMAKE_SYSTEM_NAME Linux) + +set (CMAKE_COMPILER_VENDOR "clang") + +if(WIN32) + set (CMAKE_C_COMPILER clang-cl) + set (CMAKE_CXX_COMPILER clang-cl) +else() + set (CMAKE_C_COMPILER clang) + set (CMAKE_CXX_COMPILER clang++) +endif() +set (CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# the following is used if cross-compiling +set (CMAKE_CROSSCOMPILING_EMULATOR "") diff --git a/HDF4Examples/config/toolchain/crayle.cmake b/HDF4Examples/config/toolchain/crayle.cmake new file mode 100644 index 0000000000..02df8ffb9d --- /dev/null +++ b/HDF4Examples/config/toolchain/crayle.cmake @@ -0,0 +1,10 @@ +# The following line will use cross-compiling +set (CMAKE_SYSTEM_NAME Linux) + +set (CMAKE_COMPILER_VENDOR "CrayLinuxEnvironment") + +set (CMAKE_C_COMPILER cc) +set (CMAKE_Fortran_COMPILER ftn) + +# the following is used if cross-compiling +set (CMAKE_CROSSCOMPILING_EMULATOR "") diff --git a/HDF4Examples/config/toolchain/gcc.cmake b/HDF4Examples/config/toolchain/gcc.cmake new file mode 100644 index 0000000000..f0771edb67 --- /dev/null +++ b/HDF4Examples/config/toolchain/gcc.cmake @@ -0,0 +1,11 @@ +# Uncomment the following line and the correct system name to use cross-compiling +#set (CMAKE_SYSTEM_NAME Linux) + +set (CMAKE_COMPILER_VENDOR "GCC") + +set (CMAKE_C_COMPILER cc) +set (CMAKE_CXX_COMPILER c++) +set (CMAKE_Fortran_COMPILER gfortran) + +# the following is used if cross-compiling +set (CMAKE_CROSSCOMPILING_EMULATOR "") diff --git a/HDF4Examples/config/toolchain/icc.cmake b/HDF4Examples/config/toolchain/icc.cmake new file mode 100644 index 0000000000..97f6a64985 --- /dev/null +++ b/HDF4Examples/config/toolchain/icc.cmake @@ -0,0 +1,11 @@ +# Uncomment the following to use cross-compiling +#set(CMAKE_SYSTEM_NAME Linux) + +set(CMAKE_COMPILER_VENDOR "intel") + +set(CMAKE_C_COMPILER icc) +set(CMAKE_CXX_COMPILER icpc) +set(CMAKE_Fortran_COMPILER ifort) + +# the following is used if cross-compiling +set(CMAKE_CROSSCOMPILING_EMULATOR "") diff --git a/HDF4Examples/config/toolchain/intel.cmake b/HDF4Examples/config/toolchain/intel.cmake new file mode 100644 index 0000000000..f8f60b28b4 --- /dev/null +++ b/HDF4Examples/config/toolchain/intel.cmake @@ -0,0 +1,11 @@ +# Uncomment the following to use cross-compiling +#set(CMAKE_SYSTEM_NAME Linux) + +set(CMAKE_COMPILER_VENDOR "intel") + +set(CMAKE_C_COMPILER icx) +set(CMAKE_CXX_COMPILER icpx) +set(CMAKE_Fortran_COMPILER ifx) + +# the following is used if cross-compiling +set(CMAKE_CROSSCOMPILING_EMULATOR "") diff --git a/HDF4Examples/config/toolchain/mingw64.cmake b/HDF4Examples/config/toolchain/mingw64.cmake new file mode 100644 index 0000000000..1b13891908 --- /dev/null +++ b/HDF4Examples/config/toolchain/mingw64.cmake @@ -0,0 +1,14 @@ +set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) +set (CMAKE_SYSTEM_NAME Windows) +set (CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set (CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set (CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) +set (CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran) +set (CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set (CMAKE_CROSSCOMPILING_EMULATOR wine64) + +include_directories(/usr/${TOOLCHAIN_PREFIX}/include) +set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS On CACHE BOOL "Export windows symbols") diff --git a/HDF4Examples/config/toolchain/pgi.cmake b/HDF4Examples/config/toolchain/pgi.cmake new file mode 100644 index 0000000000..ff2f048575 --- /dev/null +++ b/HDF4Examples/config/toolchain/pgi.cmake @@ -0,0 +1,11 @@ +# Uncomment the following to use cross-compiling +#set (CMAKE_SYSTEM_NAME Linux) + +set (CMAKE_COMPILER_VENDOR "PGI") + +set (CMAKE_C_COMPILER pgcc) +set (CMAKE_CXX_COMPILER pgc++) +set (CMAKE_Fortran_COMPILER pgf90) + +# the following is used if cross-compiling +set (CMAKE_CROSSCOMPILING_EMULATOR "") diff --git a/HDF4Examples/hdf/CMakeLists.txt b/HDF4Examples/hdf/CMakeLists.txt new file mode 100644 index 0000000000..57e49fdbb2 --- /dev/null +++ b/HDF4Examples/hdf/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_HDF) + +#----------------------------------------------------------------------------- +# Build the hdf examples +#----------------------------------------------------------------------------- +add_subdirectory (examples) +if (HDF_BUILD_FORTRAN) + add_subdirectory (fortran) +endif () diff --git a/HDF4Examples/hdf/examples/AN/CMakeLists.txt b/HDF4Examples/hdf/examples/AN/CMakeLists.txt new file mode 100644 index 0000000000..613f7886a4 --- /dev/null +++ b/HDF4Examples/hdf/examples/AN/CMakeLists.txt @@ -0,0 +1,118 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_HDF_AN C) + +#----------------------------------------------------------------------------- +# Define Sources +#----------------------------------------------------------------------------- +include (C_sourcefiles.cmake) + +foreach (example ${h4examples}) + get_filename_component (example_name ${example} NAME_WE) + add_executable (hdf_${example_name} ${PROJECT_SOURCE_DIR}/${example}) + target_link_libraries (hdf_${example_name} ${H4EX_HDF4_LINK_LIBS}) +endforeach () + +foreach (example ${h4examples_use}) + get_filename_component (example_name ${example} NAME_WE) + add_executable (hdf_${example_name} ${PROJECT_SOURCE_DIR}/${example}) + target_link_libraries (hdf_${example_name} ${H4EX_HDF4_LINK_LIBS}) +endforeach () + +if (H4EX_BUILD_TESTING) + macro (ADD_H4_TEST testname testcreate) + add_test ( + NAME hdf_${testname}-clearall + COMMAND ${CMAKE_COMMAND} + -E remove + ${testname}.hdf + ) + add_test ( + NAME hdf_${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:hdf_${testname}>" + -D "TEST_ARGS:STRING=" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_EXPECT=0" + -D "TEST_OUTPUT=${testname}.out" + -D "TEST_REFERENCE=${testname}.tst" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -P "${HDF4EX_RESOURCES_DIR}/runTest.cmake" + ) + set_tests_properties (hdf_${testname} PROPERTIES DEPENDS hdf_${testname}-clearall) + if (HDF4_BUILD_TOOLS AND ${testcreate} STREQUAL "1") + add_test ( + NAME hdf_HDP-${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=${H4EX_HDF4_DUMP_EXECUTABLE}" + -D "TEST_ARGS:STRING=${ARGN};${testname}.hdf" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_OUTPUT=${testname}.ddl.out" + -D "TEST_EXPECT=0" + -D "TEST_REFERENCE=${testname}.ddl" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -P "${HDF4EX_RESOURCES_DIR}/runTest.cmake" + ) + set_tests_properties (hdf_HDP-${testname} PROPERTIES DEPENDS hdf_${testname}) + endif () + endmacro () + + foreach (example ${h4examples}) + get_filename_component (example_name ${example} NAME_WE) + set (testsrc "${PROJECT_SOURCE_DIR}/testfiles/${example_name}") + set (testdest "${PROJECT_BINARY_DIR}/${example_name}") + add_custom_command ( + OUTPUT "${testdest}.tst" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}.tst" "${testdest}.tst" + DEPENDS "${testsrc}.tst" + ) + list (APPEND HDF4Examples_HDF_AN_TEST_FILES "${testdest}.tst") + if (HDF4_BUILD_TOOLS) + add_custom_command ( + OUTPUT "${testdest}.ddl" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}.ddl" "${testdest}.ddl" + DEPENDS "${testsrc}.ddl" + ) + list (APPEND HDF4Examples_HDF_AN_TEST_FILES "${testdest}.ddl") + endif () + endforeach () + + foreach (example ${h4examples_use}) + get_filename_component (example_name ${example} NAME_WE) + set (testsrc "${PROJECT_SOURCE_DIR}/testfiles/${example_name}") + set (testdest "${PROJECT_BINARY_DIR}/${example_name}") + add_custom_command ( + OUTPUT "${testdest}.tst" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}.tst" "${testdest}.tst" + DEPENDS "${testsrc}.tst" + ) + list (APPEND HDF4Examples_HDF_AN_TEST_FILES "${testdest}.tst") + endforeach () + + foreach (ex_file ${h4examples_files}) + set (testsrc "${PROJECT_SOURCE_DIR}/testfiles/${ex_file}") + set (testdest "${PROJECT_BINARY_DIR}/${ex_file}") + add_custom_command ( + OUTPUT "${testdest}" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}" "${testdest}" + DEPENDS "${testsrc}" + ) + list (APPEND HDF4Examples_HDF_AN_TEST_FILES "${testdest}") + endforeach () + + add_custom_target (HDF4Examples_HDF_AN-files ALL COMMENT "Copying files needed by AN tests" + DEPENDS ${HDF4Examples_HDF_AN_TEST_FILES}) + + foreach (example ${h4examples}) + get_filename_component (example_name ${example} NAME_WE) + ADD_H4_TEST (${example_name} 1 dumpvg) + endforeach () + + foreach (example ${h4examples_use}) + get_filename_component (example_name ${example} NAME_WE) + ADD_H4_TEST (${example_name} 0 dumpvg) + endforeach () +endif () diff --git a/HDF4Examples/hdf/examples/AN/C_sourcefiles.cmake b/HDF4Examples/hdf/examples/AN/C_sourcefiles.cmake new file mode 100644 index 0000000000..2b600ba675 --- /dev/null +++ b/HDF4Examples/hdf/examples/AN/C_sourcefiles.cmake @@ -0,0 +1,13 @@ +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +set (h4examples + h4ex_AN_create_annotation.c +) +set (h4examples_use + h4ex_AN_get_annotation_info.c + h4ex_AN_read_annotation.c +) +set (h4examples_files + General_HDFobjects.hdf +) diff --git a/HDF4Examples/hdf/examples/AN/h4ex_AN_create_annotation.c b/HDF4Examples/hdf/examples/AN/h4ex_AN_create_annotation.c new file mode 100644 index 0000000000..e5576f0b26 --- /dev/null +++ b/HDF4Examples/hdf/examples/AN/h4ex_AN_create_annotation.c @@ -0,0 +1,155 @@ +#include "hdf.h" + +#define FILE_NAME "h4ex_AN_create_annotation.hdf" +#define VG_NAME "AN Vgroup" +#define FILE_LABEL_TXT "General HDF objects" +#define FILE_DESC_TXT "This is an HDF file that contains general HDF objects" +#define DATA_LABEL_TXT "Common AN Vgroup" +#define DATA_DESC_TXT "This is a vgroup that is used to test data annotations" + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32; /* returned status for functions returning an int32 */ + int32 file_id; /* HDF file identifier */ + int32 an_id; /* AN interface identifier */ + int32 file_label_id; /* file label identifier */ + int32 file_desc_id; /* file description identifier */ + int32 data_label_id; /* data label identifier */ + int32 data_desc_id; /* data description identifier */ + int32 vgroup_id; + uint16 vgroup_tag; + uint16 vgroup_ref; + int ret_val = FAIL; + + /********************** End of variable declaration **********************/ + + /* + * Create the HDF file. + */ + file_id = Hopen(FILE_NAME, DFACC_CREATE, 0); + if (file_id == FAIL) + printf("\nUnable to open file %s for writing.\n", FILE_NAME); + else { + /* + * Initialize the AN interface. + */ + an_id = ANstart(file_id); + if (an_id == FAIL) + printf("\nCannot start annotation handling on the file %s.\n", FILE_NAME); + else { + /* + * Create the file label. + */ + file_label_id = ANcreatef(an_id, AN_FILE_LABEL); + if (file_label_id == FAIL) + printf("\nCannot create a new file label annotation.\n"); + else { + /* + * Write the annotations to the file label. + */ + status_32 = ANwriteann(file_label_id, FILE_LABEL_TXT, (int32)strlen(FILE_LABEL_TXT)); + if (status_32 == FAIL) + printf("\nFailed to write label annotation.\n"); + + /* + * Create file description. + */ + file_desc_id = ANcreatef(an_id, AN_FILE_DESC); + if (file_desc_id == FAIL) + printf("\nCannot create a new file description annotation.\n"); + else { + /* + * Write the annotation to the file description. + */ + status_32 = ANwriteann(file_desc_id, FILE_DESC_TXT, (int32)strlen(FILE_DESC_TXT)); + if (status_32 == FAIL) + printf("\nFailed to write description annotation.\n"); + + /* + * Create a vgroup in the V interface. Note that the vgroup's ref number + * is set to -1 for creating and the access mode is "w" for writing. + */ + status_n = Vstart(file_id); + if (status_n == FAIL) + printf("\nCould not start VGroup interface\n"); + else { + vgroup_id = Vattach(file_id, -1, "w"); + if (vgroup_id == FAIL) + printf("\nCould not attach to VGroup interface\n"); + else { + status_32 = Vsetname(vgroup_id, VG_NAME); + if (status_32 == FAIL) + printf("\nCould not name group.\n"); + + /* + * Obtain the tag and ref number of the vgroup for subsequent + * references. + */ + vgroup_tag = (uint16)VQuerytag(vgroup_id); + vgroup_ref = (uint16)VQueryref(vgroup_id); + + /* + * Create the data label for the vgroup identified by its tag + * and ref number. + */ + data_label_id = ANcreate(an_id, vgroup_tag, vgroup_ref, AN_DATA_LABEL); + if (data_label_id == FAIL) + printf("\nCannot create a new data label annotation.\n"); + else { + /* + * Write the annotation text to the data label. + */ + status_32 = + ANwriteann(data_label_id, DATA_LABEL_TXT, (int32)strlen(DATA_LABEL_TXT)); + if (status_32 == FAIL) + printf("\nFailed to write data label annotation.\n"); + + /* + * Create the data description for the vgroup identified by its tag + * and ref number. + */ + data_desc_id = ANcreate(an_id, vgroup_tag, vgroup_ref, AN_DATA_DESC); + if (data_desc_id == FAIL) + printf("\nCannot create a new data description annotation.\n"); + else { + /* + * Write the annotation text to the data description. + */ + status_32 = + ANwriteann(data_desc_id, DATA_DESC_TXT, strlen(DATA_DESC_TXT)); + if (status_32 == FAIL) { + printf("\nFailed to write data description annotation.\n"); + } + else { + ret_val = SUCCEED; + } + status_n = ANendaccess(data_desc_id); + } + status_n = ANendaccess(data_label_id); + } + /* + * Terminate access to the vgroup and to the V interface. + */ + status_32 = Vdetach(vgroup_id); + } + status_n = Vend(file_id); + } + status_n = ANendaccess(file_desc_id); + } + status_n = ANendaccess(file_label_id); + } + /* + * Terminate access to the AN interface and close the HDF file. + */ + status_32 = ANend(an_id); + } + status_n = Hclose(file_id); + } + if (ret_val == SUCCEED) + printf("\nSuccessful!\n"); + return ret_val; +} diff --git a/HDF4Examples/hdf/examples/AN/h4ex_AN_get_annotation_info.c b/HDF4Examples/hdf/examples/AN/h4ex_AN_get_annotation_info.c new file mode 100644 index 0000000000..45fd54fb5e --- /dev/null +++ b/HDF4Examples/hdf/examples/AN/h4ex_AN_get_annotation_info.c @@ -0,0 +1,137 @@ +#include "hdf.h" + +#define FILE_NAME "General_HDFobjects.hdf" +#define VG_NAME "AN Vgroup" + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32*/ + file_id, an_id, n_annots, /* number of annotations */ + *ann_list, /* list of annotation identifiers */ + vgroup_ref, /* reference number of the vgroup */ + index; /* index of an annotation in the annotation list */ + ann_type annot_type = AN_DATA_DESC; /* annotation to be obtained*/ + uint16 ann_tag, ann_ref, /* tag/ref number of an annotation */ + vgroup_tag = DFTAG_VG; /* tag of the vgroup */ + int ret_val = FAIL; + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file. + */ + file_id = Hopen(FILE_NAME, DFACC_READ, 0); + if (file_id == FAIL) + printf("\nUnable to open file %s for reading.\n", FILE_NAME); + else { + /* + * Initialize the AN interface and obtain an interface id. + */ + an_id = ANstart(file_id); + if (an_id == FAIL) + printf("\nCannot start annotation handling on the file %s.\n", FILE_NAME); + else { + /* + * Initialize the V interface. + */ + status_n = Vstart(file_id); + if (status_n == FAIL) + printf("\nCould not start VGroup interface\n"); + else { + + /* + * Get the vgroup named VG_NAME. + */ + vgroup_ref = Vfind(file_id, VG_NAME); + + /* + * Get the number of object descriptions. Note that, since ANnumann takes + * the tag and reference number as being of type unit16, vgroup_ref must be + * safely cast to uint16 by checking for FAIL value first. + */ + if (vgroup_ref != FAIL) { + n_annots = ANnumann(an_id, annot_type, vgroup_tag, (uint16)vgroup_ref); + if (n_annots == FAIL) { + printf("\nCannot get number of annotation ids.\n"); + } + else { + /* + * Allocate space to hold the annotation identifiers. + */ + ann_list = malloc(n_annots * sizeof(int32)); + if (ann_list) { + /* + * Get the list of identifiers of the annotations attached to the + * vgroup and of type annot_type. + */ + n_annots = ANannlist(an_id, annot_type, vgroup_tag, (uint16)vgroup_ref, ann_list); + if (n_annots == FAIL) { + printf("\nCannot get list of annotation ids.\n"); + } + else { + ret_val = SUCCEED; + /* + * Get each annotation identifier from the list then display the + * tag/ref number pair of the corresponding annotation. + */ + printf("List of annotations of type AN_DATA_DESC:\n"); + for (index = 0; index < n_annots; index++) { + /* + * Get and display the ref number of the annotation from + * its identifier. + */ + status_32 = ANid2tagref(ann_list[index], &ann_tag, &ann_ref); + if (status_32 == FAIL) { + printf("\nCannot the ref number of the annotation.\n"); + ret_val = FAIL; + } + else { + printf("Annotation index %d: tag = %s\nreference number= %d\n", index, + ann_tag == DFTAG_DIA ? "DFTAG_DIA (data description)" + : "Incorrect", + ann_ref); + } + } /* for */ + } + /* + * Free the space allocated for the annotation identifier list. + */ + free(ann_list); + } + else { + printf("\nAllocation failure\n"); + } + } + } + status_n = Vend(file_id); + } + + /* + * Get and display an annotation type from an annotation tag. + */ + annot_type = ANtag2atype(DFTAG_FID); + printf("\nAnnotation type of DFTAG_FID (file label) is %s\n", + annot_type == AN_FILE_LABEL ? "AN_FILE_LABEL" : "Incorrect"); + + /* + * Get and display an annotation tag from an annotation type. + */ + ann_tag = ANatype2tag(AN_DATA_LABEL); + printf("\nAnnotation tag of AN_DATA_LABEL is %s\n", + ann_tag == DFTAG_DIL ? "DFTAG_DIL (data label)" : "Incorrect"); + + /* + * Terminate access to the AN interface and close the HDF file. + */ + status_32 = ANend(an_id); + } + status_n = Hclose(file_id); + } + if (ret_val == SUCCEED) + printf("\nSuccessful!\n"); + return ret_val; +} diff --git a/HDF4Examples/hdf/examples/AN/h4ex_AN_read_annotation.c b/HDF4Examples/hdf/examples/AN/h4ex_AN_read_annotation.c new file mode 100644 index 0000000000..f0e072b4b8 --- /dev/null +++ b/HDF4Examples/hdf/examples/AN/h4ex_AN_read_annotation.c @@ -0,0 +1,124 @@ +#include "hdf.h" + +#define FILE_NAME "General_HDFobjects.hdf" + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32; /* returned status for functions returning an int32 */ + int32 file_id; /* HDF file identifier */ + int32 an_id; /* AN interface identifier */ + int32 ann_id; /* an annotation identifier */ + int32 index; /* position of an annotation in all of the same type*/ + int32 ann_length; /* length of the text in an annotation */ + int32 n_file_labels; + int32 n_file_descs; + int32 n_data_labels; + int32 n_data_descs; + char *ann_buf; /* buffer to hold the read annotation */ + int ret_val = FAIL; + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file. + */ + file_id = Hopen(FILE_NAME, DFACC_READ, 0); + if (file_id == FAIL) + printf("\nUnable to open file %s for reading.\n", FILE_NAME); + else { + /* + * Initialize the AN interface. + */ + an_id = ANstart(file_id); + if (an_id == FAIL) + printf("\nCannot start annotation handling on the file %s.\n", FILE_NAME); + else { + /* + * Get the annotation information, e.g., the numbers of file labels, file + * descriptions, data labels, and data descriptions. + */ + status_n = ANfileinfo(an_id, &n_file_labels, &n_file_descs, &n_data_labels, &n_data_descs); + if (status_n == FAIL) + printf("\nCould not get the annotation information\n"); + else { + /* + * Get the data labels. Note that this for loop can be used to + * obtain the contents of each kind of annotation with the appropriate + * number of annotations and the type of annotation, i.e., replace + * n_data_labels with n_file_labels, n_file_descs, or n_data_descs, and + * AN_DATA_LABEL with AN_FILE_LABEL, AN_FILE_DESC, or AN_DATA_DESC, + * respectively. + */ + ret_val = SUCCEED; + for (index = 0; index < n_data_labels; index++) { + /* + * Get the identifier of the current data label. + */ + ann_id = ANselect(an_id, index, AN_DATA_LABEL); + if (ann_id == FAIL) { + printf("\nCannot get the identifier of the current data label.\n"); + ret_val = FAIL; + } + else { + /* + * Get the length of the data label. + */ + ann_length = ANannlen(ann_id); + if (ann_id == FAIL) { + printf("\nCannot read annotation length.\n"); + ret_val = FAIL; + } + else { + /* + * Allocate space for the buffer to hold the data label text. + */ + ann_buf = malloc((ann_length + 1) * sizeof(char)); + if (ann_buf) { + /* + * Read and display the data label. Note that the size of the buffer, + * i.e., the third parameter, is 1 character more than the length of + * the data label; that is for the null character. It is not the case + * when a description is retrieved because the description does not + * necessarily end with a null character. + * + */ + status_32 = ANreadann(ann_id, ann_buf, ann_length + 1); + if (status_32 == FAIL) { + printf("\nCannot read annotation.\n"); + ret_val = FAIL; + } + else { + printf("Data label index: %d\n", index); + printf("Data label contents: %s\n", ann_buf); + } + /* + * Free the space allocated for the annotation buffer. + */ + free(ann_buf); + } + else { + printf("\nAllocation failure\n"); + } + } + /* + * Terminate access to the current data label. + */ + status_n = ANendaccess(ann_id); + } + } /* for */ + } + /* + * Terminate access to the AN interface and close the HDF file. + */ + status_32 = ANend(an_id); + } + status_n = Hclose(file_id); + } + if (ret_val == SUCCEED) + printf("\nSuccessful!\n"); + return ret_val; +} diff --git a/HDF4Examples/hdf/examples/AN/testfiles/General_HDFobjects.hdf b/HDF4Examples/hdf/examples/AN/testfiles/General_HDFobjects.hdf new file mode 100644 index 0000000000..f4d8fa5110 Binary files /dev/null and b/HDF4Examples/hdf/examples/AN/testfiles/General_HDFobjects.hdf differ diff --git a/HDF4Examples/hdf/examples/AN/testfiles/h4ex_AN_create_annotation.ddl b/HDF4Examples/hdf/examples/AN/testfiles/h4ex_AN_create_annotation.ddl new file mode 100644 index 0000000000..2901797be0 --- /dev/null +++ b/HDF4Examples/hdf/examples/AN/testfiles/h4ex_AN_create_annotation.ddl @@ -0,0 +1,21 @@ +File name: h4ex_AN_create_annotation.hdf +File Label #0: General HDF objects +File description #0: This is an HDF file that contains general HDF objects + + +Vgroup:0 + tag = 1965; reference = 2; + name = AN Vgroup; class = <Undefined>; + number of entries = 0; + number of attributes = 0 + Name/Label=Common AN Vgroup + Description=This is a vgroup that is used to test data annotations +Entries:- + None. + + +Graphical representation of the file:- +(vg#: vgroup; vd: vdata) + + vg0 + diff --git a/HDF4Examples/hdf/examples/AN/testfiles/h4ex_AN_create_annotation.tst b/HDF4Examples/hdf/examples/AN/testfiles/h4ex_AN_create_annotation.tst new file mode 100644 index 0000000000..04cdffc985 --- /dev/null +++ b/HDF4Examples/hdf/examples/AN/testfiles/h4ex_AN_create_annotation.tst @@ -0,0 +1,2 @@ + +Successful! diff --git a/HDF4Examples/hdf/examples/AN/testfiles/h4ex_AN_get_annotation_info.tst b/HDF4Examples/hdf/examples/AN/testfiles/h4ex_AN_get_annotation_info.tst new file mode 100644 index 0000000000..39cec6f697 --- /dev/null +++ b/HDF4Examples/hdf/examples/AN/testfiles/h4ex_AN_get_annotation_info.tst @@ -0,0 +1,9 @@ +List of annotations of type AN_DATA_DESC: +Annotation index 0: tag = DFTAG_DIA (data description) +reference number= 1 + +Annotation type of DFTAG_FID (file label) is AN_FILE_LABEL + +Annotation tag of AN_DATA_LABEL is DFTAG_DIL (data label) + +Successful! diff --git a/HDF4Examples/hdf/examples/AN/testfiles/h4ex_AN_read_annotation.tst b/HDF4Examples/hdf/examples/AN/testfiles/h4ex_AN_read_annotation.tst new file mode 100644 index 0000000000..d2e9202f27 --- /dev/null +++ b/HDF4Examples/hdf/examples/AN/testfiles/h4ex_AN_read_annotation.tst @@ -0,0 +1,4 @@ +Data label index: 0 +Data label contents: Common AN Vgroup + +Successful! diff --git a/HDF4Examples/hdf/examples/CMakeLists.txt b/HDF4Examples/hdf/examples/CMakeLists.txt new file mode 100644 index 0000000000..7f9fcb192d --- /dev/null +++ b/HDF4Examples/hdf/examples/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_HDF C CXX) + +#----------------------------------------------------------------------------- +# Define Sources +#----------------------------------------------------------------------------- +add_subdirectory (AN) +add_subdirectory (GR) +add_subdirectory (VD) +add_subdirectory (VG) diff --git a/HDF4Examples/hdf/examples/GR/CMakeLists.txt b/HDF4Examples/hdf/examples/GR/CMakeLists.txt new file mode 100644 index 0000000000..9822212ca9 --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/CMakeLists.txt @@ -0,0 +1,118 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_HDF_GR C) + +#----------------------------------------------------------------------------- +# Define Sources +#----------------------------------------------------------------------------- +include (C_sourcefiles.cmake) + +foreach (example ${h4examples}) + get_filename_component (example_name ${example} NAME_WE) + add_executable (hdf_${example_name} ${PROJECT_SOURCE_DIR}/${example}) + target_link_libraries (hdf_${example_name} ${H4EX_HDF4_LINK_LIBS}) +endforeach () + +foreach (example ${h4examples_use}) + get_filename_component (example_name ${example} NAME_WE) + add_executable (hdf_${example_name} ${PROJECT_SOURCE_DIR}/${example}) + target_link_libraries (hdf_${example_name} ${H4EX_HDF4_LINK_LIBS}) +endforeach () + +if (H4EX_BUILD_TESTING) + macro (ADD_H4_TEST testname testcreate) + add_test ( + NAME hdf_${testname}-clearall + COMMAND ${CMAKE_COMMAND} + -E remove + ${testname}.hdf + ) + add_test ( + NAME hdf_${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:hdf_${testname}>" + -D "TEST_ARGS:STRING=" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_EXPECT=0" + -D "TEST_OUTPUT=${testname}.out" + -D "TEST_REFERENCE=${testname}.tst" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -P "${HDF4EX_RESOURCES_DIR}/runTest.cmake" + ) + set_tests_properties (hdf_${testname} PROPERTIES DEPENDS hdf_${testname}-clearall) + if (HDF4_BUILD_TOOLS AND ${testcreate} STREQUAL "1") + add_test ( + NAME hdf_HDP-${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=${H4EX_HDF4_DUMP_EXECUTABLE}" + -D "TEST_ARGS:STRING=${ARGN};${testname}.hdf" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_OUTPUT=${testname}.ddl.out" + -D "TEST_EXPECT=0" + -D "TEST_REFERENCE=${testname}.ddl" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -P "${HDF4EX_RESOURCES_DIR}/runTest.cmake" + ) + set_tests_properties (hdf_HDP-${testname} PROPERTIES DEPENDS hdf_${testname}) + endif () + endmacro () + + foreach (example ${h4examples}) + get_filename_component (example_name ${example} NAME_WE) + set (testsrc "${PROJECT_SOURCE_DIR}/testfiles/${example_name}") + set (testdest "${PROJECT_BINARY_DIR}/${example_name}") + add_custom_command ( + OUTPUT "${testdest}.tst" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}.tst" "${testdest}.tst" + DEPENDS "${testsrc}.tst" + ) + list (APPEND HDF4Examples_HDF_GR_TEST_FILES "${testdest}.tst") + if (HDF4_BUILD_TOOLS) + add_custom_command ( + OUTPUT "${testdest}.ddl" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}.ddl" "${testdest}.ddl" + DEPENDS "${testsrc}.ddl" + ) + list (APPEND HDF4Examples_HDF_GR_TEST_FILES "${testdest}.ddl") + endif () + endforeach () + + foreach (example ${h4examples_use}) + get_filename_component (example_name ${example} NAME_WE) + set (testsrc "${PROJECT_SOURCE_DIR}/testfiles/${example_name}") + set (testdest "${PROJECT_BINARY_DIR}/${example_name}") + add_custom_command ( + OUTPUT "${testdest}.tst" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}.tst" "${testdest}.tst" + DEPENDS "${testsrc}.tst" + ) + list (APPEND HDF4Examples_HDF_GR_TEST_FILES "${testdest}.tst") + endforeach () + + foreach (ex_file ${h4examples_files}) + set (testsrc "${PROJECT_SOURCE_DIR}/testfiles/${ex_file}") + set (testdest "${PROJECT_BINARY_DIR}/${ex_file}") + add_custom_command ( + OUTPUT "${testdest}" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}" "${testdest}" + DEPENDS "${testsrc}" + ) + list (APPEND HDF4Examples_HDF_GR_TEST_FILES "${testdest}") + endforeach () + + add_custom_target (HDF4Examples_HDF_GR-files ALL COMMENT "Copying files needed by GR tests" + DEPENDS ${HDF4Examples_HDF_GR_TEST_FILES}) + + foreach (example ${h4examples}) + get_filename_component (example_name ${example} NAME_WE) + ADD_H4_TEST (${example_name} 1 dumpvg) + endforeach () + + foreach (example ${h4examples_use}) + get_filename_component (example_name ${example} NAME_WE) + ADD_H4_TEST (${example_name} 0 dumpvg) + endforeach () +endif () diff --git a/HDF4Examples/hdf/examples/GR/C_sourcefiles.cmake b/HDF4Examples/hdf/examples/GR/C_sourcefiles.cmake new file mode 100644 index 0000000000..7d552cd718 --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/C_sourcefiles.cmake @@ -0,0 +1,23 @@ +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +set (h4examples + h4ex_GR_create_and_write_chunked_image.c + h4ex_GR_create_and_write_image.c + h4ex_GR_write_palette.c +) +set (h4examples_use + h4ex_GR_get_attribute.c + h4ex_GR_image_info.c + h4ex_GR_modify_image.c + h4ex_GR_read_image.c + h4ex_GR_read_palette.c + h4ex_GR_set_attribute.c +) +set (h4examples_files + General_RImages.hdf + General_RImages2.hdf + General_RImages3.hdf + General_RImages4.hdf + Image_with_Palette.hdf +) diff --git a/HDF4Examples/hdf/examples/GR/h4ex_GR_create_and_write_chunked_image.c b/HDF4Examples/hdf/examples/GR/h4ex_GR_create_and_write_chunked_image.c new file mode 100644 index 0000000000..4fedde7e15 --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/h4ex_GR_create_and_write_chunked_image.c @@ -0,0 +1,74 @@ +#include "hdf.h" +#define FILE_NAME "h4ex_GR_create_and_write_chunked_image.hdf" +#define IMAGE_NAME "gzip_comp_data" +#define X_LENGTH 6 /* number of rows in the image */ +#define Y_LENGTH 10 /* number of columns in the image */ +#define NCOMPS 3 /* number of components in the image */ +main() +{ + /************************* Variable declaration **************************/ + intn status; /* status for functions returning an intn */ + int32 file_id, /* HDF file identifier */ + gr_id, /* GR interface identifier */ + ri_id, /* raster image identifier */ + dims[2], /* dimension sizes of the image array */ + start[2]; /* interlace mode of the image */ + HDF_CHUNK_DEF chunk_def; /* Chunk definition set */ + int32 chunk00[] = {110, 111, 112, 120, 121, 122, 130, 131, 132, + 140, 141, 142, 150, 151, 152, 160, 161, 162}; + int32 chunk01[] = {210, 211, 212, 220, 221, 222, 230, 231, 232, + 240, 241, 242, 250, 251, 252, 260, 261, 262}; + int32 chunk14[] = {1010, 1011, 1012, 1020, 1021, 1022, 1030, 1031, 1032, + 1040, 1041, 1042, 1050, 1051, 1052, 1060, 1061, 1062}; + /********************** End of variable declaration **********************/ + /* + * Create and open the file. + */ + file_id = Hopen(FILE_NAME, DFACC_CREATE, 0); + /* + * Initialize the GR interface. + */ + gr_id = GRstart(file_id); + /* + * Set dimensions of the image. + */ + dims[0] = X_LENGTH; + dims[1] = Y_LENGTH; + /* + * Create the raster image array. + */ + ri_id = GRcreate(gr_id, IMAGE_NAME, NCOMPS, DFNT_INT32, MFGR_INTERLACE_PIXEL, dims); + /* + * Define chunked image. + */ + chunk_def.comp.comp_type = COMP_CODE_DEFLATE; + chunk_def.comp.cinfo.deflate.level = 6; + chunk_def.comp.chunk_lengths[0] = 3; + chunk_def.comp.chunk_lengths[1] = 2; + status = GRsetchunk(ri_id, chunk_def, HDF_CHUNK | HDF_COMP); + /* + * Write first chunk (0,0). + */ + start[0] = 0; + start[1] = 0; + status = GRwritechunk(ri_id, start, (VOIDP)chunk00); + /* + * Write second chunk (0,1). + */ + start[0] = 0; + start[1] = 1; + status = GRwritechunk(ri_id, start, (VOIDP)chunk01); + /* + * Write third chunk (1,4). + */ + start[0] = 1; + start[1] = 4; + status = GRwritechunk(ri_id, start, (VOIDP)chunk14); + /* + * Terminate access to the raster image and to the GR interface and, + * close the HDF file. + */ + status = GRendaccess(ri_id); + status = GRend(gr_id); + status = Hclose(file_id); +} diff --git a/HDF4Examples/hdf/examples/GR/h4ex_GR_create_and_write_image.c b/HDF4Examples/hdf/examples/GR/h4ex_GR_create_and_write_image.c new file mode 100644 index 0000000000..06a34c0540 --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/h4ex_GR_create_and_write_image.c @@ -0,0 +1,84 @@ +#include "hdf.h" + +#define FILE_NAME "h4ex_GR_create_and_write_image.hdf" +#define IMAGE_NAME "Image Array 1" +#define X_LENGTH 10 /* number of columns in the image */ +#define Y_LENGTH 5 /* number of rows in the image */ +#define N_COMPS 2 /* number of components in the image */ + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status; /* status for functions returning an intn */ + int32 file_id, /* HDF file identifier */ + gr_id, /* GR interface identifier */ + ri_id, /* raster image identifier */ + start[2], /* start position to write for each dimension */ + edges[2], /* number of elements to be written + along each dimension */ + dim_sizes[2], /* dimension sizes of the image array */ + interlace_mode, /* interlace mode of the image */ + data_type, /* data type of the image data */ + i, j; + int16 image_buf[Y_LENGTH][X_LENGTH][N_COMPS]; + + /********************** End of variable declaration **********************/ + + /* + * Create and open the file. + */ + file_id = Hopen(FILE_NAME, DFACC_CREATE, 0); + + /* + * Initialize the GR interface. + */ + gr_id = GRstart(file_id); + + /* + * Set the data type, interlace mode, and dimensions of the image. + */ + data_type = DFNT_INT16; + interlace_mode = MFGR_INTERLACE_PIXEL; + dim_sizes[0] = X_LENGTH; + dim_sizes[1] = Y_LENGTH; + + /* + * Create the raster image array. + */ + ri_id = GRcreate(gr_id, IMAGE_NAME, N_COMPS, data_type, interlace_mode, dim_sizes); + + /* + * Fill the image data buffer with values. + */ + for (i = 0; i < Y_LENGTH; i++) { + for (j = 0; j < X_LENGTH; j++) { + image_buf[i][j][0] = (int16)(i + j) + 1; /* first component */ + image_buf[i][j][1] = (int16)(i + j) + 1; /* second component */ + } + } + + /* + * Define the size of the data to be written, i.e., start from the origin + * and go as long as the length of each dimension. + */ + start[0] = start[1] = 0; + edges[0] = X_LENGTH; + edges[1] = Y_LENGTH; + + /* + * Write the data in the buffer into the image array. + */ + status = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_buf); + + /* + * Terminate access to the raster image and to the GR interface and, + * close the HDF file. + */ + status = GRendaccess(ri_id); + status = GRend(gr_id); + status = Hclose(file_id); + printf("GR_create_and_write_image.c done\n"); + return 0; +} diff --git a/HDF4Examples/hdf/examples/GR/h4ex_GR_get_attribute.c b/HDF4Examples/hdf/examples/GR/h4ex_GR_get_attribute.c new file mode 100644 index 0000000000..69584c56ed --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/h4ex_GR_get_attribute.c @@ -0,0 +1,135 @@ +#include "hdf.h" + +#define FILE_NAME "General_RImages.hdf" +#define RI_ATTR_NAME "Image Attribute 2" + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status; /* status for functions returning an intn */ + int32 gr_id, ri_id, file_id, f_att_index, /* index of file attributes */ + ri_att_index, /* index of raster image attributes */ + data_type, /* image data type */ + n_values, /* number of values in an attribute */ + value_index, /* index of values in an attribute */ + n_rimages, /* number of raster images in the file */ + n_file_attrs; /* number of file attributes */ + char attr_name[H4_MAX_GR_NAME]; /* buffer to hold the attribute name */ + VOIDP data_buf; /* buffer to hold the attribute values */ + int16 *int_ptr; /* int16 pointer to point to a void data buffer */ + char8 *char_ptr; /* char8 pointer to point to a void data buffer */ + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file. + */ + file_id = Hopen(FILE_NAME, DFACC_READ, 0); + + /* + * Initialize the GR interface. + */ + gr_id = GRstart(file_id); + + /* + * Determine the number of attributes in the file. + */ + status = GRfileinfo(gr_id, &n_rimages, &n_file_attrs); + if (status != FAIL && n_file_attrs > 0) { + for (f_att_index = 0; f_att_index < n_file_attrs; f_att_index++) { + /* + * Get information about the current file attribute. + */ + status = GRattrinfo(gr_id, f_att_index, attr_name, &data_type, &n_values); + + /* + * Allocate a buffer to hold the file attribute data. In this example, + * knowledge about the data type is assumed to be available from + * the previous example for simplicity. In reality, the size + * of the type must be determined based on the machine where the + * program resides. + */ + if (data_type == DFNT_CHAR8) { + data_buf = malloc(n_values * sizeof(char8)); + if (data_buf == NULL) { + printf("Unable to allocate space for attribute data.\n"); + exit(1); + } + } + else { + printf("Unable to determine data type to allocate data buffer.\n"); + exit(1); + } + + /* + * Read and display the attribute values. + */ + status = GRgetattr(gr_id, f_att_index, (VOIDP)data_buf); + + char_ptr = (char8 *)data_buf; + printf("Attribute %s: ", attr_name); + for (value_index = 0; value_index < n_values; value_index++) + printf("%c", char_ptr[value_index]); + printf("\n"); + + /* + * Free the space allocated for the data buffer. + */ + + free(data_buf); + + } /* for */ + } /* if */ + + /* + * Select the second image in the file. + */ + ri_id = GRselect(gr_id, 1); + + /* + * Find the image attribute named RI_ATTR_NAME. + */ + ri_att_index = GRfindattr(ri_id, RI_ATTR_NAME); + + /* + * Get information about the attribute. + */ + status = GRattrinfo(ri_id, ri_att_index, attr_name, &data_type, &n_values); + + /* + * Allocate a buffer to hold the file attribute data. As mentioned above, + * knowledge about the data type is assumed to be available from + * the previous example for simplicity. In reality, the size of the + * type must be determined based on the machine where the program resides. + */ + if (data_type == DFNT_INT16) + data_buf = malloc(n_values * sizeof(int16)); + + /* + * Read and display the attribute values. + */ + status = GRgetattr(ri_id, ri_att_index, (VOIDP)data_buf); + + printf("\nAttribute %s: ", RI_ATTR_NAME); + int_ptr = (int16 *)data_buf; + for (value_index = 0; value_index < n_values; value_index++) + printf("%d ", int_ptr[value_index]); + printf("\n"); + + /* + * Free the space allocated for the data buffer. + */ + free(data_buf); + + /* + * Terminate access to the raster image and to the GR interface, and + * close the file. + */ + + status = GRendaccess(ri_id); + status = GRend(gr_id); + status = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/GR/h4ex_GR_image_info.c b/HDF4Examples/hdf/examples/GR/h4ex_GR_image_info.c new file mode 100644 index 0000000000..c7a86e1ee0 --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/h4ex_GR_image_info.c @@ -0,0 +1,96 @@ +#include "hdf.h" + +#define FILE_NAME "General_RImages3.hdf" + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status; /* status for functions returning an intn */ + int32 file_id, gr_id, ri_id, n_rimages, /* number of raster images in the file */ + n_file_attrs, /* number of file attributes */ + ri_index, /* index of a image */ + dim_sizes[2], /* dimensions of an image */ + n_comps, /* number of components an image contains */ + interlace_mode, /* interlace mode of an image */ + data_type, /* number type of an image */ + n_attrs; /* number of attributes belong to an image */ + char name[H4_MAX_GR_NAME], /* name of an image */ + *type_string, /* mapped text of a number type */ + *interlace_string; /* mapped text of an interlace mode */ + + /********************** End of variable declaration **********************/ + + /* + * Open the file for reading. + */ + file_id = Hopen(FILE_NAME, DFACC_READ, 0); + + /* + * Initialize the GR interface. + */ + gr_id = GRstart(file_id); + + /* + * Determine the contents of the file. + */ + status = GRfileinfo(gr_id, &n_rimages, &n_file_attrs); + + /* + * For each image in the file, get and display the image information. + */ + printf("RI# Name Components Type Interlace \ + Dimensions Attributes\n\n"); + for (ri_index = 0; ri_index < n_rimages; ri_index++) { + ri_id = GRselect(gr_id, ri_index); + status = GRgetiminfo(ri_id, name, &n_comps, &data_type, &interlace_mode, dim_sizes, &n_attrs); + /* + * Map the number type and interlace mode into text strings for output + * readability. Note that, in this example, only two possible types + * are considered because of the simplicity of the example. For real + * problems, all possible types should be checked and, if reading the + * data is desired, the size of the type must be determined based on the + * machine where the program resides. + */ + if (data_type == DFNT_CHAR8) + type_string = "Char8"; + else if (data_type == DFNT_INT16) + type_string = "Int16"; + else + type_string = "Unknown"; + + switch (interlace_mode) { + case MFGR_INTERLACE_PIXEL: + interlace_string = "MFGR_INTERLACE_PIXEL"; + break; + case MFGR_INTERLACE_LINE: + interlace_string = "MFGR_INTERLACE_LINE"; + break; + case MFGR_INTERLACE_COMPONENT: + interlace_string = "MFGR_INTERLACE_COMPONENT"; + break; + default: + interlace_string = "Unknown"; + break; + } /* switch */ + + /* + * Display the image information for the current raster image. + */ + printf("%d %s %d %s %s %2d,%2d %d\n", ri_index, name, n_comps, type_string, + interlace_string, dim_sizes[0], dim_sizes[1], n_attrs); + + /* + * Terminate access to the current raster image. + */ + status = GRendaccess(ri_id); + } + + /* + * Terminate access to the GR interface and close the HDF file. + */ + status = GRend(gr_id); + status = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/GR/h4ex_GR_modify_image.c b/HDF4Examples/hdf/examples/GR/h4ex_GR_modify_image.c new file mode 100644 index 0000000000..8953dafbd4 --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/h4ex_GR_modify_image.c @@ -0,0 +1,127 @@ +#include "hdf.h" + +#define FILE_NAME "General_RImages2.hdf" +#define X1_LENGTH \ + 5 /* number of columns in the first image \ + being modified */ +#define Y1_LENGTH \ + 2 /* number of rows in the first image \ + being modified */ +#define N1_COMPS 2 /* number of components in the first image */ +#define IMAGE1_NAME "Image Array 1" +#define IMAGE2_NAME "Image Array 2" +#define X2_LENGTH 6 /* number of columns in the second image */ +#define Y2_LENGTH 4 /* number of rows in the second image */ +#define N2_COMPS 3 /* number of components in the second image */ + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status; /* status for functions returning an intn */ + int32 file_id, /* HDF file identifier */ + gr_id, /* GR interface identifier */ + ri1_id, /* raster image identifier */ + start1[2], /* start position to write for each dimension */ + edges1[2], /* number of elements to be written along + each dimension */ + ri2_id, /* raster image identifier */ + start2[2], /* start position to write for each dimension */ + edges2[2], /* number of elements to be written along + each dimension */ + dims_sizes[2], /* sizes of the two dimensions of the image array */ + data_type, /* data type of the image data */ + interlace_mode; /* interlace mode of the image */ + int16 i, j; /* indices for the dimensions */ + int16 image1_buf[Y1_LENGTH][X1_LENGTH][N1_COMPS]; /* data of first image */ + char image2_buf[Y2_LENGTH][X2_LENGTH][N2_COMPS]; /* data of second image*/ + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file for writing. + */ + file_id = Hopen(FILE_NAME, DFACC_WRITE, 0); + + /* + * Initialize the GR interface. + */ + gr_id = GRstart(file_id); + + /* + * Select the first raster image in the file. + */ + ri1_id = GRselect(gr_id, 0); + + /* + * Fill the first image data buffer with values. + */ + for (i = 0; i < Y1_LENGTH; i++) { + for (j = 0; j < X1_LENGTH; j++) { + image1_buf[i][j][0] = 0; /* first component */ + image1_buf[i][j][1] = 0; /* second component */ + } + } + + /* + * Define the size of the data to be written, i.e., start from the origin + * and go as long as the length of each dimension. + */ + start1[0] = start1[1] = 0; + edges1[0] = X1_LENGTH; + edges1[1] = Y1_LENGTH; + + /* + * Write the data in the buffer into the image array. + */ + status = GRwriteimage(ri1_id, start1, NULL, edges1, (VOIDP)image1_buf); + + /* + * Set the interlace mode and dimensions of the second image. + */ + data_type = DFNT_CHAR8; + interlace_mode = MFGR_INTERLACE_PIXEL; + dims_sizes[0] = X2_LENGTH; + dims_sizes[1] = Y2_LENGTH; + + /* + * Create the second image in the file. + */ + ri2_id = GRcreate(gr_id, IMAGE2_NAME, N2_COMPS, data_type, interlace_mode, dims_sizes); + + /* + * Fill the second image data buffer with values. + */ + for (i = 0; i < Y2_LENGTH; i++) { + for (j = 0; j < X2_LENGTH; j++) { + image2_buf[i][j][0] = 'A'; /* first component */ + image2_buf[i][j][1] = 'B'; /* second component */ + image2_buf[i][j][2] = 'C'; /* third component */ + } + } + + /* + * Define the size of the data to be written, i.e., start from the origin + * and go as long as the length of each dimension. + */ + for (i = 0; i < 2; i++) { + start2[i] = 0; + edges2[i] = dims_sizes[i]; + } + + /* + * Write the data in the buffer into the second image array. + */ + status = GRwriteimage(ri2_id, start2, NULL, edges2, (VOIDP)image2_buf); + + /* + * Terminate access to the raster images and to the GR interface, and + * close the HDF file. + */ + status = GRendaccess(ri1_id); + status = GRendaccess(ri2_id); + status = GRend(gr_id); + status = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/GR/h4ex_GR_read_image.c b/HDF4Examples/hdf/examples/GR/h4ex_GR_read_image.c new file mode 100644 index 0000000000..14d6d900ec --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/h4ex_GR_read_image.c @@ -0,0 +1,127 @@ +#include "hdf.h" + +#define FILE_NAME "General_RImages.hdf" +#define N_COMPS 2 +#define X_LENGTH 10 /* number of columns of the entire image */ +#define Y_LENGTH 5 /* number of rows of the entire image */ +#define PART_COLS 2 /* number of columns read for partial image */ +#define PART_ROWS 3 /* number of rows read for partial image */ +#define SKIP_COLS 5 /* number of columns read for skipped image */ +#define SKIP_ROWS 3 /* number of rows read for skipped image */ +#define COLS_PART_START 3 /* starting column to read partial image */ +#define ROWS_PART_START 1 /* starting row to read partial image */ +#define COLS_SKIP_START 1 /* starting column to read skipped image */ +#define ROWS_SKIP_START 0 /* starting row to read skipped image */ +#define N_STRIDES 2 /* number of elements to skip on each dim. */ + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status; /* status for functions returning an intn */ + int32 file_id, gr_id, ri_id, start[2], /* start position to write for each dimension */ + edges[2], /* number of elements to bewritten along each dimension */ + stride[2]; /* dimension sizes of the image array */ + int16 entire_image[Y_LENGTH][X_LENGTH][N_COMPS], partial_image[PART_ROWS][PART_COLS][N_COMPS], + skipped_image[SKIP_ROWS][SKIP_COLS][N_COMPS]; + int32 i, j; + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file for reading. + */ + file_id = Hopen(FILE_NAME, DFACC_READ, 0); + + /* + * Initialize the GR interface. + */ + gr_id = GRstart(file_id); + + /* + * Select the first raster image in the file. + */ + ri_id = GRselect(gr_id, 0); + + /* + * Define the size of the data to be read, i.e., start from the origin + * and go as long as the length of each dimension. + */ + start[0] = start[1] = 0; + edges[0] = X_LENGTH; + edges[1] = Y_LENGTH; + + /* + * Read the data from the raster image array. + */ + status = GRreadimage(ri_id, start, NULL, edges, (VOIDP)entire_image); + + /* + * Display only the first component of the image since the two components + * have the same data in this example. + */ + printf("First component of the entire image:\n"); + for (i = 0; i < Y_LENGTH; i++) { + for (j = 0; j < X_LENGTH; j++) + printf("%d ", entire_image[i][j][0]); + printf("\n"); + } + + /* + * Define the size of the data to be read. + */ + start[0] = COLS_PART_START; + start[1] = ROWS_PART_START; + edges[0] = PART_COLS; + edges[1] = PART_ROWS; + + /* + * Read a subset of the raster image array. + */ + status = GRreadimage(ri_id, start, NULL, edges, (VOIDP)partial_image); + + /* + * Display the first component of the read sample. + */ + printf("\nThree rows & two cols at 2nd row and 4th column"); + printf(" of the first component:\n"); + for (i = 0; i < PART_ROWS; i++) { + for (j = 0; j < PART_COLS; j++) + printf("%d ", partial_image[i][j][0]); + printf("\n"); + } + + /* + * Define the size and the pattern to read the data. + */ + start[0] = COLS_SKIP_START; + start[1] = ROWS_SKIP_START; + edges[0] = SKIP_COLS; + edges[1] = SKIP_ROWS; + stride[0] = stride[1] = N_STRIDES; + + /* + * Read all the odd rows and even columns of the image. + */ + status = GRreadimage(ri_id, start, stride, edges, (VOIDP)skipped_image); + + /* + * Display the first component of the read sample. + */ + printf("\nAll odd rows and even columns of the first component:\n"); + for (i = 0; i < SKIP_ROWS; i++) { + for (j = 0; j < SKIP_COLS; j++) + printf("%d ", skipped_image[i][j][0]); + printf("\n"); + } + + /* + * Terminate access to the raster image and to the GR interface, and + * close the HDF file. + */ + status = GRendaccess(ri_id); + status = GRend(gr_id); + status = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/GR/h4ex_GR_read_palette.c b/HDF4Examples/hdf/examples/GR/h4ex_GR_read_palette.c new file mode 100644 index 0000000000..055c18b9dc --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/h4ex_GR_read_palette.c @@ -0,0 +1,80 @@ +#include "hdf.h" + +#define FILE_NAME "Image_with_Palette.hdf" +#define IMAGE_NAME "Image with Palette" +#define N_ENTRIES 256 /* number of elements of each color */ + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status, /* status for functions returning an intn */ + i, j; + int32 file_id, gr_id, ri_id, pal_id, ri_index; + int32 data_type, n_comps, n_entries, interlace_mode; + uint8 palette_data[N_ENTRIES][3]; /* static because of fixed size */ + + /************************* Variable declaration **************************/ + + /* + * Open the file. + */ + file_id = Hopen(FILE_NAME, DFACC_READ, 0); + + /* + * Initiate the GR interface. + */ + gr_id = GRstart(file_id); + + /* + * Get the index of the image IMAGR_NAME. + */ + ri_index = GRnametoindex(gr_id, IMAGE_NAME); + + /* + * Get image identifier. + */ + ri_id = GRselect(gr_id, ri_index); + + /* + * Get the identifier of the palette attached to the image. + */ + pal_id = GRgetlutid(ri_id, ri_index); + + /* + * Obtain and display information about the palette. + */ + status = GRgetlutinfo(pal_id, &n_comps, &data_type, &interlace_mode, &n_entries); + printf("Palette: %d components; %d entries\n", n_comps, n_entries); + + /* + * Read the palette data. + */ + status = GRreadlut(pal_id, (VOIDP)palette_data); + + /* + * Display the palette data. Recall that HDF supports only 256 colors. + * Each color is defined by its 3 components. Therefore, + * verifying the value of n_entries and n_comps is not necessary and + * the buffer to hold the palette data can be static. However, + * if more values or colors are added to the model, these parameters + * must be checked to allocate sufficient space when reading a palette. + */ + printf(" Palette Data: \n"); + for (i = 0; i < n_entries; i++) { + for (j = 0; j < n_comps; j++) + printf("%i ", palette_data[i][j]); + printf("\n"); + } + printf("\n"); + + /* + * Terminate access to the image and to the GR interface, and + * close the HDF file. + */ + status = GRendaccess(ri_id); + status = GRend(gr_id); + status = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/GR/h4ex_GR_set_attribute.c b/HDF4Examples/hdf/examples/GR/h4ex_GR_set_attribute.c new file mode 100644 index 0000000000..2a554be8f5 --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/h4ex_GR_set_attribute.c @@ -0,0 +1,72 @@ +#include "hdf.h" + +#define FILE_NAME "General_RImages4.hdf" +#define IMAGE_NAME "Image Array 2" +#define F_ATT1_NAME "File Attribute 1" +#define F_ATT2_NAME "File Attribute 2" +#define RI_ATT1_NAME "Image Attribute 1" +#define RI_ATT2_NAME "Image Attribute 2" +#define F_ATT1_VAL "Contents of First FILE Attribute" +#define F_ATT2_VAL "Contents of Second FILE Attribute" +#define F_ATT1_N_VALUES 32 +#define F_ATT2_N_VALUES 33 +#define RI_ATT1_VAL "Contents of IMAGE's First Attribute" +#define RI_ATT1_N_VALUES 35 +#define RI_ATT2_N_VALUES 6 + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status; /* status for functions returning an intn */ + int32 gr_id, ri_id, file_id, ri_index; + int16 ri_attr_2[RI_ATT2_N_VALUES] = {1, 2, 3, 4, 5, 6}; + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file. + */ + file_id = Hopen(FILE_NAME, DFACC_WRITE, 0); + + /* + * Initialize the GR interface. + */ + gr_id = GRstart(file_id); + + /* + * Set two file attributes to the file with names, data types, numbers of + * values, and values of the attributes specified. + */ + status = GRsetattr(gr_id, F_ATT1_NAME, DFNT_CHAR8, F_ATT1_N_VALUES, (VOIDP)F_ATT1_VAL); + + status = GRsetattr(gr_id, F_ATT2_NAME, DFNT_CHAR8, F_ATT2_N_VALUES, (VOIDP)F_ATT2_VAL); + + /* + * Obtain the index of the image named IMAGE_NAME. + */ + ri_index = GRnametoindex(gr_id, IMAGE_NAME); + + /* + * Obtain the identifier of this image. + */ + ri_id = GRselect(gr_id, ri_index); + + /* + * Set two attributes to the image with names, data types, numbers of + * values, and values of the attributes specified. + */ + status = GRsetattr(ri_id, RI_ATT1_NAME, DFNT_CHAR8, RI_ATT1_N_VALUES, (VOIDP)RI_ATT1_VAL); + + status = GRsetattr(ri_id, RI_ATT2_NAME, DFNT_INT16, RI_ATT2_N_VALUES, (VOIDP)ri_attr_2); + + /* + * Terminate access to the image and to the GR interface, and close the + * HDF file. + */ + status = GRendaccess(ri_id); + status = GRend(gr_id); + status = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/GR/h4ex_GR_write_palette.c b/HDF4Examples/hdf/examples/GR/h4ex_GR_write_palette.c new file mode 100644 index 0000000000..623f4f3b2c --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/h4ex_GR_write_palette.c @@ -0,0 +1,104 @@ +#include "hdf.h" + +#define FILE_NAME "h4ex_GR_write_palette.hdf" +#define NEW_IMAGE_NAME "Image with Palette" +#define N_COMPS_IMG 2 /* number of image components */ +#define X_LENGTH 5 +#define Y_LENGTH 5 +#define N_ENTRIES 256 /* number of entries in the palette */ +#define N_COMPS_PAL 3 /* number of palette's components */ + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status, /* status for functions returning an intn */ + i, j; + int32 file_id, gr_id, ri_id, pal_id, interlace_mode, + start[2], /* holds where to start to write for each dimension */ + edges[2], /* holds how long to write for each dimension */ + dim_sizes[2]; /* sizes of the two dimensions of the image array */ + uint8 image_buf[Y_LENGTH][X_LENGTH][N_COMPS_IMG]; /* data of first image */ + uint8 palette_buf[N_ENTRIES][N_COMPS_PAL]; + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file. + */ + file_id = Hopen(FILE_NAME, DFACC_CREATE, 0); + + /* + * Initialize the GR interface. + */ + gr_id = GRstart(file_id); + + /* + * Define the dimensions and interlace mode of the image. + */ + dim_sizes[0] = X_LENGTH; + dim_sizes[1] = Y_LENGTH; + interlace_mode = MFGR_INTERLACE_PIXEL; + + /* + * Create the image named NEW_IMAGE_NAME. + */ + ri_id = GRcreate(gr_id, NEW_IMAGE_NAME, N_COMPS_IMG, DFNT_UINT8, interlace_mode, dim_sizes); + + /* + * Fill the image data buffer with values. + */ + for (i = 0; i < Y_LENGTH; i++) { + for (j = 0; j < X_LENGTH; j++) { + image_buf[i][j][0] = (i + j) + 1; + image_buf[i][j][1] = (i + j) + 2; + } + } + + /* + * Define the size of the data to be written, i.e., start from the origin + * and go as long as the length of each dimension. + */ + start[0] = start[1] = 0; + edges[0] = X_LENGTH; + edges[1] = Y_LENGTH; + + /* + * Write the data in the buffer into the image array. + */ + status = GRwriteimage(ri_id, start, NULL, edges, (VOIDP)image_buf); + + /* + * Initialize the palette to grayscale. + */ + for (i = 0; i < N_ENTRIES; i++) { + palette_buf[i][0] = i; + palette_buf[i][1] = i; + palette_buf[i][2] = i; + } + + /* + * Define palette interlace mode. + */ + interlace_mode = MFGR_INTERLACE_PIXEL; + + /* + * Get the identifier of the palette attached to the image NEW_IMAGE_NAME. + */ + pal_id = GRgetlutid(ri_id, 0); + + /* + * Write data to the palette. + */ + status = GRwritelut(pal_id, N_COMPS_PAL, DFNT_UINT8, interlace_mode, N_ENTRIES, (VOIDP)palette_buf); + + /* + * Terminate access to the image and to the GR interface, and + * close the HDF file. + */ + status = GRendaccess(ri_id); + status = GRend(gr_id); + status = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/GR/testfiles/General_RImages.hdf b/HDF4Examples/hdf/examples/GR/testfiles/General_RImages.hdf new file mode 100644 index 0000000000..8a41da41b9 Binary files /dev/null and b/HDF4Examples/hdf/examples/GR/testfiles/General_RImages.hdf differ diff --git a/HDF4Examples/hdf/examples/GR/testfiles/General_RImages2.hdf b/HDF4Examples/hdf/examples/GR/testfiles/General_RImages2.hdf new file mode 100644 index 0000000000..8a41da41b9 Binary files /dev/null and b/HDF4Examples/hdf/examples/GR/testfiles/General_RImages2.hdf differ diff --git a/HDF4Examples/hdf/examples/GR/testfiles/General_RImages3.hdf b/HDF4Examples/hdf/examples/GR/testfiles/General_RImages3.hdf new file mode 100644 index 0000000000..8a41da41b9 Binary files /dev/null and b/HDF4Examples/hdf/examples/GR/testfiles/General_RImages3.hdf differ diff --git a/HDF4Examples/hdf/examples/GR/testfiles/General_RImages4.hdf b/HDF4Examples/hdf/examples/GR/testfiles/General_RImages4.hdf new file mode 100644 index 0000000000..8a41da41b9 Binary files /dev/null and b/HDF4Examples/hdf/examples/GR/testfiles/General_RImages4.hdf differ diff --git a/HDF4Examples/hdf/examples/GR/testfiles/Image_with_Palette.hdf b/HDF4Examples/hdf/examples/GR/testfiles/Image_with_Palette.hdf new file mode 100644 index 0000000000..5894f23f43 Binary files /dev/null and b/HDF4Examples/hdf/examples/GR/testfiles/Image_with_Palette.hdf differ diff --git a/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_create_and_write_chunked_image.ddl b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_create_and_write_chunked_image.ddl new file mode 100644 index 0000000000..2440514b37 --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_create_and_write_chunked_image.ddl @@ -0,0 +1,37 @@ +File name: h4ex_GR_create_and_write_chunked_image.hdf + + +Vgroup:0 + tag = 1965; reference = 2; + name = gzip_comp_data; class = RI0.0; + number of entries = 2; + number of attributes = 0 +Entries:- + #0 (Image Dimensions) + tag = 300; reference = 1; + #1 (Raster Image Data) + tag = 302; reference = 1; + + +Vgroup:1 + tag = 1965; reference = 4; + name = RIG0.0; class = RIG0.0; + number of entries = 1; + number of attributes = 0 +Entries:- + #0 (Vgroup) + tag = 1965; reference = 2; + number of entries = 2; + name = gzip_comp_data; class = RI0.0 + number of attributes = 0 + + +Graphical representation of the file:- +(vg#: vgroup; vd: vdata) + + vg0 -- Image Dimensions + -- Raster Image Data + + vg1 -- vg0 -- Image Dimensions + -- Raster Image Data + diff --git a/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_create_and_write_chunked_image.tst b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_create_and_write_chunked_image.tst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_create_and_write_image.ddl b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_create_and_write_image.ddl new file mode 100644 index 0000000000..897ed8e57f --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_create_and_write_image.ddl @@ -0,0 +1,37 @@ +File name: h4ex_GR_create_and_write_image.hdf + + +Vgroup:0 + tag = 1965; reference = 2; + name = Image Array 1; class = RI0.0; + number of entries = 2; + number of attributes = 0 +Entries:- + #0 (Image Dimensions) + tag = 300; reference = 1; + #1 (Raster Image Data) + tag = 302; reference = 1; + + +Vgroup:1 + tag = 1965; reference = 3; + name = RIG0.0; class = RIG0.0; + number of entries = 1; + number of attributes = 0 +Entries:- + #0 (Vgroup) + tag = 1965; reference = 2; + number of entries = 2; + name = Image Array 1; class = RI0.0 + number of attributes = 0 + + +Graphical representation of the file:- +(vg#: vgroup; vd: vdata) + + vg0 -- Image Dimensions + -- Raster Image Data + + vg1 -- vg0 -- Image Dimensions + -- Raster Image Data + diff --git a/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_create_and_write_image.tst b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_create_and_write_image.tst new file mode 100644 index 0000000000..8ddec3815d --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_create_and_write_image.tst @@ -0,0 +1 @@ +GR_create_and_write_image.c done diff --git a/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_get_attribute.tst b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_get_attribute.tst new file mode 100644 index 0000000000..edb140b3ba --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_get_attribute.tst @@ -0,0 +1,4 @@ +Attribute File Attribute 1: Contents of First FILE Attribute +Attribute File Attribute 2: Contents of Second FILE Attribute + +Attribute Image Attribute 2: 1 2 3 4 5 6 diff --git a/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_image_info.tst b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_image_info.tst new file mode 100644 index 0000000000..44a9f8c3b7 --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_image_info.tst @@ -0,0 +1,4 @@ +RI# Name Components Type Interlace Dimensions Attributes + +0 Image Array 1 2 Int16 MFGR_INTERLACE_PIXEL 10, 5 0 +1 Image Array 2 3 Char8 MFGR_INTERLACE_PIXEL 6, 4 2 diff --git a/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_modify_image.tst b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_modify_image.tst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_read_image.tst b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_read_image.tst new file mode 100644 index 0000000000..c6db5a496c --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_read_image.tst @@ -0,0 +1,16 @@ +First component of the entire image: +0 0 0 0 0 6 7 8 9 10 +0 0 0 0 0 7 8 9 10 11 +3 4 5 6 7 8 9 10 11 12 +4 5 6 7 8 9 10 11 12 13 +5 6 7 8 9 10 11 12 13 14 + +Three rows & two cols at 2nd row and 4th column of the first component: +0 0 +6 7 +7 8 + +All odd rows and even columns of the first component: +0 0 6 8 10 +4 6 8 10 12 +6 8 10 12 14 diff --git a/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_read_palette.tst b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_read_palette.tst new file mode 100644 index 0000000000..3c536cc9a3 --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_read_palette.tst @@ -0,0 +1,259 @@ +Palette: 3 components; 256 entries + Palette Data: +0 0 0 +1 1 1 +2 2 2 +3 3 3 +4 4 4 +5 5 5 +6 6 6 +7 7 7 +8 8 8 +9 9 9 +10 10 10 +11 11 11 +12 12 12 +13 13 13 +14 14 14 +15 15 15 +16 16 16 +17 17 17 +18 18 18 +19 19 19 +20 20 20 +21 21 21 +22 22 22 +23 23 23 +24 24 24 +25 25 25 +26 26 26 +27 27 27 +28 28 28 +29 29 29 +30 30 30 +31 31 31 +32 32 32 +33 33 33 +34 34 34 +35 35 35 +36 36 36 +37 37 37 +38 38 38 +39 39 39 +40 40 40 +41 41 41 +42 42 42 +43 43 43 +44 44 44 +45 45 45 +46 46 46 +47 47 47 +48 48 48 +49 49 49 +50 50 50 +51 51 51 +52 52 52 +53 53 53 +54 54 54 +55 55 55 +56 56 56 +57 57 57 +58 58 58 +59 59 59 +60 60 60 +61 61 61 +62 62 62 +63 63 63 +64 64 64 +65 65 65 +66 66 66 +67 67 67 +68 68 68 +69 69 69 +70 70 70 +71 71 71 +72 72 72 +73 73 73 +74 74 74 +75 75 75 +76 76 76 +77 77 77 +78 78 78 +79 79 79 +80 80 80 +81 81 81 +82 82 82 +83 83 83 +84 84 84 +85 85 85 +86 86 86 +87 87 87 +88 88 88 +89 89 89 +90 90 90 +91 91 91 +92 92 92 +93 93 93 +94 94 94 +95 95 95 +96 96 96 +97 97 97 +98 98 98 +99 99 99 +100 100 100 +101 101 101 +102 102 102 +103 103 103 +104 104 104 +105 105 105 +106 106 106 +107 107 107 +108 108 108 +109 109 109 +110 110 110 +111 111 111 +112 112 112 +113 113 113 +114 114 114 +115 115 115 +116 116 116 +117 117 117 +118 118 118 +119 119 119 +120 120 120 +121 121 121 +122 122 122 +123 123 123 +124 124 124 +125 125 125 +126 126 126 +127 127 127 +128 128 128 +129 129 129 +130 130 130 +131 131 131 +132 132 132 +133 133 133 +134 134 134 +135 135 135 +136 136 136 +137 137 137 +138 138 138 +139 139 139 +140 140 140 +141 141 141 +142 142 142 +143 143 143 +144 144 144 +145 145 145 +146 146 146 +147 147 147 +148 148 148 +149 149 149 +150 150 150 +151 151 151 +152 152 152 +153 153 153 +154 154 154 +155 155 155 +156 156 156 +157 157 157 +158 158 158 +159 159 159 +160 160 160 +161 161 161 +162 162 162 +163 163 163 +164 164 164 +165 165 165 +166 166 166 +167 167 167 +168 168 168 +169 169 169 +170 170 170 +171 171 171 +172 172 172 +173 173 173 +174 174 174 +175 175 175 +176 176 176 +177 177 177 +178 178 178 +179 179 179 +180 180 180 +181 181 181 +182 182 182 +183 183 183 +184 184 184 +185 185 185 +186 186 186 +187 187 187 +188 188 188 +189 189 189 +190 190 190 +191 191 191 +192 192 192 +193 193 193 +194 194 194 +195 195 195 +196 196 196 +197 197 197 +198 198 198 +199 199 199 +200 200 200 +201 201 201 +202 202 202 +203 203 203 +204 204 204 +205 205 205 +206 206 206 +207 207 207 +208 208 208 +209 209 209 +210 210 210 +211 211 211 +212 212 212 +213 213 213 +214 214 214 +215 215 215 +216 216 216 +217 217 217 +218 218 218 +219 219 219 +220 220 220 +221 221 221 +222 222 222 +223 223 223 +224 224 224 +225 225 225 +226 226 226 +227 227 227 +228 228 228 +229 229 229 +230 230 230 +231 231 231 +232 232 232 +233 233 233 +234 234 234 +235 235 235 +236 236 236 +237 237 237 +238 238 238 +239 239 239 +240 240 240 +241 241 241 +242 242 242 +243 243 243 +244 244 244 +245 245 245 +246 246 246 +247 247 247 +248 248 248 +249 249 249 +250 250 250 +251 251 251 +252 252 252 +253 253 253 +254 254 254 +255 255 255 + diff --git a/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_set_attribute.tst b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_set_attribute.tst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_write_palette.ddl b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_write_palette.ddl new file mode 100644 index 0000000000..79e0579b8c --- /dev/null +++ b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_write_palette.ddl @@ -0,0 +1,45 @@ +File name: h4ex_GR_write_palette.hdf + + +Vgroup:0 + tag = 1965; reference = 2; + name = Image with Palette; class = RI0.0; + number of entries = 4; + number of attributes = 0 +Entries:- + #0 (Image Dimensions) + tag = 300; reference = 1; + #1 (Raster Image Data) + tag = 302; reference = 1; + #2 (Palette Dimension) + tag = 307; reference = 1; + #3 (Image Palette) + tag = 301; reference = 1; + + +Vgroup:1 + tag = 1965; reference = 3; + name = RIG0.0; class = RIG0.0; + number of entries = 1; + number of attributes = 0 +Entries:- + #0 (Vgroup) + tag = 1965; reference = 2; + number of entries = 4; + name = Image with Palette; class = RI0.0 + number of attributes = 0 + + +Graphical representation of the file:- +(vg#: vgroup; vd: vdata) + + vg0 -- Image Dimensions + -- Raster Image Data + -- Palette Dimension + -- Image Palette + + vg1 -- vg0 -- Image Dimensions + -- Raster Image Data + -- Palette Dimension + -- Image Palette + diff --git a/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_write_palette.tst b/HDF4Examples/hdf/examples/GR/testfiles/h4ex_GR_write_palette.tst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/HDF4Examples/hdf/examples/Makefile.am b/HDF4Examples/hdf/examples/Makefile.am new file mode 100644 index 0000000000..07bd40e5b1 --- /dev/null +++ b/HDF4Examples/hdf/examples/Makefile.am @@ -0,0 +1,81 @@ +############################################################################# +## Setup for building programs ## +############################################################################# + +include $(top_srcdir)/config/commence.am + +DEFINES=-DNDEBUG -DHDF + +############################################################################# +## Programs to build ## +############################################################################# + +TEST_PROG = h4ex_VD_create_vdatas h4ex_VD_write_mixed_vdata \ + h4ex_VD_write_mixed_vdata_struct h4ex_VD_write_to_vdata \ + h4ex_VD_read_from_vdata h4ex_VD_read_mixed_vdata \ + h4ex_VD_set_get_vdata_attr h4ex_VD_create_onefield_vdatas \ + h4ex_VD_get_vdata_info h4ex_VD_locate_vdata h4ex_VG_create_vgroup \ + h4ex_VG_add_sds_to_vgroup h4ex_VG_insert_vdatas_to_vgroup \ + h4ex_VG_set_get_vgroup_attr h4ex_VG_vgroup_contents \ + h4ex_VG_get_vgroup_info h4ex_GR_create_and_write_image \ + h4ex_GR_modify_image h4ex_GR_set_attribute h4ex_GR_get_attribute \ + h4ex_GR_write_palette h4ex_GR_image_info h4ex_GR_read_image \ + h4ex_AN_create_annotation h4ex_AN_get_annotation_info h4ex_AN_read_annotation + +# These are the C example files to be installed +INSTALL_FILES= h4ex_VD_create_vdatas.c h4ex_VD_write_mixed_vdata.c \ + h4ex_VD_write_mixed_vdata_struct.c h4ex_VD_write_to_vdata.c \ + h4ex_VD_read_from_vdata.c h4ex_VD_read_mixed_vdata.c \ + h4ex_VD_set_get_vdata_attr.c h4ex_VD_create_onefield_vdatas.c \ + h4ex_VD_get_vdata_info.c h4ex_VD_locate_vdata.c h4ex_VG_create_vgroup.c \ + h4ex_VG_add_sds_to_vgroup.c h4ex_VG_insert_vdatas_to_vgroup.c \ + h4ex_VG_set_get_vgroup_attr.c h4ex_VG_vgroup_contents.c \ + h4ex_VG_get_vgroup_info.c h4ex_GR_create_and_write_image.c \ + h4ex_GR_modify_image.c h4ex_GR_set_attribute.c h4ex_GR_get_attribute.c \ + h4ex_GR_write_palette.c h4ex_GR_image_info.c h4ex_GR_read_image.c \ + h4ex_AN_create_annotation.c h4ex_AN_get_annotation_info.c h4ex_AN_read_annotation.c + +# Where to install example files +EXAMPLEDIR=$(prefix)/examples/hdf + +# How to build C programs using h4cc +$(EXTRA_PROG): $(H4CC) + $(H4CC) $(H4CCFLAGS) $(CFLAGS) -o $@ $(srcdir)/$@.c; + +# List dependencies for each program. Normally, automake would take +# care of this for us, but if we tell automake about the programs it +# will try to build them with the normal C compiler, not h4cc. + +# C Programs +h4ex_VD_read_from_vdata: $(srcdir)/h4ex_VD_read_from_vdata.c +h4ex_VD_read_mixed_vdata: $(srcdir)/h4ex_VD_read_mixed_vdata.c +h4ex_VD_set_get_vdata_attr: $(srcdir)/h4ex_VD_set_get_vdata_attr.c +h4ex_VD_write_mixed_vdata: $(srcdir)/h4ex_VD_write_mixed_vdata.c +h4ex_VD_write_mixed_vdata_struct: $(srcdir)/h4ex_VD_write_mixed_vdata_struct.c +h4ex_VD_write_to_vdata: $(srcdir)/h4ex_VD_write_to_vdata.c +h4ex_VD_create_onefield_vdatas: $(srcdir)/h4ex_VD_create_onefield_vdatas.c +h4ex_VD_create_vdatas: $(srcdir)/h4ex_VD_create_vdatas.c +h4ex_VD_get_vdata_info: $(srcdir)/h4ex_VD_get_vdata_info.c +h4ex_VD_locate_vdata: $(srcdir)/h4ex_VD_locate_vdata.c +h4ex_VG_insert_vdatas_to_vgroup: $(srcdir)/h4ex_VG_insert_vdatas_to_vgroup.c +h4ex_VG_set_get_vgroup_attr: $(srcdir)/h4ex_VG_set_get_vgroup_attr.c +h4ex_VG_vgroup_contents: $(srcdir)/h4ex_VG_vgroup_contents.c +h4ex_VG_add_sds_to_vgroup: $(srcdir)/h4ex_VG_add_sds_to_vgroup.c +h4ex_VG_create_vgroup: $(srcdir)/h4ex_VG_create_vgroup.c +h4ex_VG_get_vgroup_info: $(srcdir)/h4ex_VG_get_vgroup_info.c +h4ex_GR_create_and_write_image: $(srcdir)/h4ex_GR_create_and_write_image.c +h4ex_GR_get_attribute: $(srcdir)/h4ex_GR_get_attribute.c +h4ex_GR_image_info: $(srcdir)/h4ex_GR_image_info.c +h4ex_GR_modify_image: $(srcdir)/h4ex_GR_modify_image.c +h4ex_GR_read_image: $(srcdir)/h4ex_GR_read_image.c +h4ex_GR_read_palette: $(srcdir)/h4ex_GR_read_palette.c +h4ex_GR_set_attribute: $(srcdir)/h4ex_GR_set_attribute.c +h4ex_GR_write_palette: $(srcdir)/h4ex_GR_write_palette.c +h4ex_AN_create_annotation: $(srcdir)/h4ex_AN_create_annotation.c +h4ex_N_get_annotation_info: $(srcdir)/h4ex_AN_get_annotation_info.c +h4ex_AN_read_annotation: $(srcdir)/h4ex_AN_read_annotation.c + +include $(top_srcdir)/config/examples.am +include $(top_srcdir)/config/conclude.am + +DISTCLEANFILES = *.chkexe *.chklog diff --git a/HDF4Examples/hdf/examples/VD/CMakeLists.txt b/HDF4Examples/hdf/examples/VD/CMakeLists.txt new file mode 100644 index 0000000000..ce6a78018c --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/CMakeLists.txt @@ -0,0 +1,118 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_HDF_VD C) + +#----------------------------------------------------------------------------- +# Define Sources +#----------------------------------------------------------------------------- +include (C_sourcefiles.cmake) + +foreach (example ${h4examples}) + get_filename_component (example_name ${example} NAME_WE) + add_executable (hdf_${example_name} ${PROJECT_SOURCE_DIR}/${example}) + target_link_libraries (hdf_${example_name} ${H4EX_HDF4_LINK_LIBS}) +endforeach () + +foreach (example ${h4examples_use}) + get_filename_component (example_name ${example} NAME_WE) + add_executable (hdf_${example_name} ${PROJECT_SOURCE_DIR}/${example}) + target_link_libraries (hdf_${example_name} ${H4EX_HDF4_LINK_LIBS}) +endforeach () + +if (H4EX_BUILD_TESTING) + macro (ADD_H4_TEST testname testcreate) + add_test ( + NAME hdf_${testname}-clearall + COMMAND ${CMAKE_COMMAND} + -E remove + ${testname}.hdf + ) + add_test ( + NAME hdf_${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:hdf_${testname}>" + -D "TEST_ARGS:STRING=" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_EXPECT=0" + -D "TEST_OUTPUT=${testname}.out" + -D "TEST_REFERENCE=${testname}.tst" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -P "${HDF4EX_RESOURCES_DIR}/runTest.cmake" + ) + set_tests_properties (hdf_${testname} PROPERTIES DEPENDS hdf_${testname}-clearall) + if (HDF4_BUILD_TOOLS AND ${testcreate} STREQUAL "1") + add_test ( + NAME hdf_HDP-${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=${H4EX_HDF4_DUMP_EXECUTABLE}" + -D "TEST_ARGS:STRING=${ARGN};${testname}.hdf" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_OUTPUT=${testname}.ddl.out" + -D "TEST_EXPECT=0" + -D "TEST_REFERENCE=${testname}.ddl" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -P "${HDF4EX_RESOURCES_DIR}/runTest.cmake" + ) + set_tests_properties (hdf_HDP-${testname} PROPERTIES DEPENDS hdf_${testname}) + endif () + endmacro () + + foreach (example ${h4examples}) + get_filename_component (example_name ${example} NAME_WE) + set (testsrc "${PROJECT_SOURCE_DIR}/testfiles/${example_name}") + set (testdest "${PROJECT_BINARY_DIR}/${example_name}") + add_custom_command ( + OUTPUT "${testdest}.tst" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}.tst" "${testdest}.tst" + DEPENDS "${testsrc}.tst" + ) + list (APPEND HDF4Examples_HDF_VD_TEST_FILES "${testdest}.tst") + if (HDF4_BUILD_TOOLS) + add_custom_command ( + OUTPUT "${testdest}.ddl" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}.ddl" "${testdest}.ddl" + DEPENDS "${testsrc}.ddl" + ) + list (APPEND HDF4Examples_HDF_VD_TEST_FILES "${testdest}.ddl") + endif () + endforeach () + + foreach (example ${h4examples_use}) + get_filename_component (example_name ${example} NAME_WE) + set (testsrc "${PROJECT_SOURCE_DIR}/testfiles/${example_name}") + set (testdest "${PROJECT_BINARY_DIR}/${example_name}") + add_custom_command ( + OUTPUT "${testdest}.tst" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}.tst" "${testdest}.tst" + DEPENDS "${testsrc}.tst" + ) + list (APPEND HDF4Examples_HDF_VD_TEST_FILES "${testdest}.tst") + endforeach () + + foreach (ex_file ${h4examples_files}) + set (testsrc "${PROJECT_SOURCE_DIR}/testfiles/${ex_file}") + set (testdest "${PROJECT_BINARY_DIR}/${ex_file}") + add_custom_command ( + OUTPUT "${testdest}" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}" "${testdest}" + DEPENDS "${testsrc}" + ) + list (APPEND HDF4Examples_HDF_VD_TEST_FILES "${testdest}") + endforeach () + + add_custom_target (HDF4Examples_HDF_VD-files ALL COMMENT "Copying files needed by VD tests" + DEPENDS ${HDF4Examples_HDF_VD_TEST_FILES}) + + foreach (example ${h4examples}) + get_filename_component (example_name ${example} NAME_WE) + ADD_H4_TEST (${example_name} 1 dumpvg) + endforeach () + + foreach (example ${h4examples_use}) + get_filename_component (example_name ${example} NAME_WE) + ADD_H4_TEST (${example_name} 0 dumpvg) + endforeach () +endif () diff --git a/HDF4Examples/hdf/examples/VD/C_sourcefiles.cmake b/HDF4Examples/hdf/examples/VD/C_sourcefiles.cmake new file mode 100644 index 0000000000..f9533a9d7e --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/C_sourcefiles.cmake @@ -0,0 +1,24 @@ +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +set (h4examples + h4ex_VD_create_onefield_vdatas.c + h4ex_VD_create_vdatas.c + h4ex_VD_write_mixed_vdata_struct.c + h4ex_VD_write_mixed_vdata.c +) +set (h4examples_use + h4ex_VD_get_vdata_info.c + h4ex_VD_locate_vdata.c +# h4ex_VD_read_from_vdata.c #program will fail + h4ex_VD_read_mixed_vdata.c +# h4ex_VD_set_get_vdata_attr.c + h4ex_VD_write_to_vdata.c +) +set (h4examples_files + General_Vdatas.hdf + General_Vdatas2.hdf + General_Vdatas3.hdf + Packed_Vdata.hdf + Two_Vdatas.hdf +) diff --git a/HDF4Examples/hdf/examples/VD/h4ex_VD_create_onefield_vdatas.c b/HDF4Examples/hdf/examples/VD/h4ex_VD_create_onefield_vdatas.c new file mode 100644 index 0000000000..b3937851e9 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/h4ex_VD_create_onefield_vdatas.c @@ -0,0 +1,68 @@ +#include "hdf.h" + +#define FILE_NAME "h4ex_VD_create_onefield_vdatas.hdf" +#define CLASS1_NAME "5x1 Array" +#define CLASS2_NAME "6x4 Array" +#define VDATA1_NAME "First Vdata" +#define VDATA2_NAME "Second Vdata" +#define FIELD1_NAME "Single-component Field" +#define FIELD2_NAME "Multi-component Field" +#define N_RECORDS_1 5 /* number of records the first vdata contains */ +#define N_RECORDS_2 6 /* number of records the second vdata contains */ +#define ORDER_2 4 /* order of the field in the second vdata */ + /* Note that the order of the field in the first vdata is 1 */ + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32; /* returned status for functions returning an int32 */ + int32 file_id, vdata1_ref, vdata2_ref; + + /* + * Define an array to buffer the data of the first vdata. + */ + char8 vdata1_buf[N_RECORDS_1] = {'V', 'D', 'A', 'T', 'A'}; + + /* + * Define an array to buffer the data of the second vdata. + */ + int32 vdata2_buf[N_RECORDS_2][ORDER_2] = {{1, 2, 3, 4}, {2, 4, 6, 8}, {3, 6, 9, 12}, + {4, 8, 12, 16}, {5, 10, 15, 20}, {6, 12, 18, 24}}; + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file for writing. + */ + file_id = Hopen(FILE_NAME, DFACC_WRITE, 0); + + /* + * Initialize the VS interface. + */ + status_n = Vstart(file_id); + + /* + * Create the first vdata and populate it with data from the vdata1_buf + * array. Note that the buffer vdata1_buf is cast to (uint8 *) for the + * benefit of generic data type. + */ + vdata1_ref = VHstoredata(file_id, FIELD1_NAME, (uint8 *)vdata1_buf, N_RECORDS_1, DFNT_CHAR8, VDATA1_NAME, + CLASS1_NAME); + + /* + * Create the second vdata and populate it with data from the vdata2_buf + * array. + */ + vdata2_ref = VHstoredatam(file_id, FIELD2_NAME, (uint8 *)vdata2_buf, N_RECORDS_2, DFNT_INT32, VDATA2_NAME, + CLASS2_NAME, ORDER_2); + + /* + * Terminate access to the VS interface and close the HDF file. + */ + status_n = Vend(file_id); + status_32 = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VD/h4ex_VD_create_vdatas.c b/HDF4Examples/hdf/examples/VD/h4ex_VD_create_vdatas.c new file mode 100644 index 0000000000..af3b803e00 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/h4ex_VD_create_vdatas.c @@ -0,0 +1,116 @@ +#include "hdf.h" + +#define FILE1_NAME "h4ex_VD_create_vdatas.hdf" +#define FILE2_NAME "Two_Vdatas.hdf" +#define VDATA_NAME "Vdata 1" +#define VDATA_CLASS "Empty Vdatas" + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + file1_id, file2_id, vdata_id, vdata1_id, vdata2_id, + vdata_ref = -1; /* ref number of a vdata, set to -1 to create */ + + /********************** End of variable declaration **********************/ + + /* + * Create the first HDF file. + */ + file1_id = Hopen(FILE1_NAME, DFACC_CREATE, 0); + + /* + * Initialize the VS interface associated with the first HDF file. + */ + status_n = Vstart(file1_id); + + /* + * Create a vdata in the first HDF file. + */ + vdata_id = VSattach(file1_id, vdata_ref, "w"); + + /* + * Assign a name to the vdata. + */ + status_32 = VSsetname(vdata_id, VDATA_NAME); + + /* + * Other operations on the vdata identified by vdata_id can be carried + * out starting from this point. + */ + + /* + * Create the second HDF file. + */ + file2_id = Hopen(FILE2_NAME, DFACC_CREATE, 0); + + /* + * Initialize the VS interface associated with the second HDF file. + */ + status_n = Vstart(file2_id); + + /* + * Create the first vdata in the second HDF file. + */ + vdata1_id = VSattach(file2_id, vdata_ref, "w"); + + /* + * Create the second vdata in the second HDF file. + */ + vdata2_id = VSattach(file2_id, vdata_ref, "w"); + + /* + * Assign a class name to these vdatas. + */ + status_32 = VSsetclass(vdata1_id, VDATA_CLASS); + status_32 = VSsetclass(vdata2_id, VDATA_CLASS); + + /* + * Other operations on the vdatas identified by vdata1_id and vdata2_id + * can be carried out starting from this point. + */ + + /* + * Terminate access to the first vdata in the second HDF file. + */ + status_32 = VSdetach(vdata1_id); + + /* + * Terminate access to the second vdata in the second HDF file. + */ + status_32 = VSdetach(vdata2_id); + + /* + * From this point on, any operations on the vdatas identified by vdata1_id + and vdata2_id are invalid but not on the vdata identified by vdata_id. + */ + + /* + * Terminate access to the VS interface associated with the second HDF file. + */ + status_n = Vend(file2_id); + + /* + * Close the second HDF file. + */ + status_n = Hclose(file2_id); + + /* + * Terminate access to the vdata in the first HDF file. + */ + status_32 = VSdetach(vdata_id); + + /* + * Terminate access to the VS interface associated with the first HDF file. + */ + status_n = Vend(file1_id); + + /* + * Close the first HDF file. + */ + status_n = Hclose(file1_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VD/h4ex_VD_get_vdata_info.c b/HDF4Examples/hdf/examples/VD/h4ex_VD_get_vdata_info.c new file mode 100644 index 0000000000..bfae7da1c4 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/h4ex_VD_get_vdata_info.c @@ -0,0 +1,73 @@ +#include "hdf.h" + +#define FILE_NAME "General_Vdatas.hdf" +#define FIELD_SIZE 80 /* maximum length of all the field names */ + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + n_records, /* to retrieve the number of records in the vdata */ + interlace_mode, /* to retrieve the interlace mode of the vdata */ + vdata_size, /* to retrieve the size of all specified fields */ + file_id, vdata_ref, vdata_id; + char fieldname_list[FIELD_SIZE], /* buffer to retrieve the vdata data */ + vdata_name[VSNAMELENMAX]; /* buffer to retrieve the vdata name */ + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file for reading. + */ + file_id = Hopen(FILE_NAME, DFACC_READ, 0); + + /* + * Initialize the VS interface. + */ + status_n = Vstart(file_id); + + /* + * Set vdata_ref to -1 to start the search from the beginning of file. + */ + vdata_ref = -1; + + /* + * Use VSgetid to obtain each vdata by its reference number then attach + * to the vdata and get its information. The loop terminates when + * the last vdata is reached. + */ + while ((vdata_ref = VSgetid(file_id, vdata_ref)) != FAIL) { + /* + * Attach to the current vdata for reading. + */ + vdata_id = VSattach(file_id, vdata_ref, "r"); + + /* + * Test whether the current vdata is not a storage of an attribute, then + * obtain and display its information. + */ + if (VSisattr(vdata_id) != TRUE) { + status_n = + VSinquire(vdata_id, &n_records, &interlace_mode, fieldname_list, &vdata_size, vdata_name); + printf("Vdata %s: - contains %d records\n\tInterlace mode: %s \ + \n\tFields: %s - %d bytes\n\t\n", + vdata_name, n_records, interlace_mode == FULL_INTERLACE ? "FULL" : "NONE", fieldname_list, + vdata_size); + } + + /* + * Detach from the current vdata. + */ + status_32 = VSdetach(vdata_id); + } /* while */ + + /* + * Terminate access to the VS interface and close the HDF file. + */ + status_n = Vend(file_id); + status_32 = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VD/h4ex_VD_locate_vdata.c b/HDF4Examples/hdf/examples/VD/h4ex_VD_locate_vdata.c new file mode 100644 index 0000000000..adbfd9b13a --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/h4ex_VD_locate_vdata.c @@ -0,0 +1,77 @@ +#include "hdf.h" + +#define FILE_NAME "General_Vdatas.hdf" +#define SEARCHED_FIELDS "Position,Temperature" + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + file_id, vdata_id, vdata_ref, index = 0; /* index of the vdata in the file - manually kept */ + int8 found_fields; /* TRUE if the specified fields exist in the vdata */ + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file for reading. + */ + file_id = Hopen(FILE_NAME, DFACC_READ, 0); + + /* + * Initialize the VS interface. + */ + status_n = Vstart(file_id); + + /* + * Set the reference number to -1 to start the search from + * the beginning of file. + */ + vdata_ref = -1; + + /* + * Assume that the specified fields are not found in the current vdata. + */ + found_fields = FALSE; + + /* + * Use VSgetid to obtain each vdata by its reference number then + * attach to the vdata and search for the fields. The loop + * terminates when the last vdata is reached or when a vdata which + * contains the fields listed in SEARCHED_FIELDS is found. + */ + while ((vdata_ref = VSgetid(file_id, vdata_ref)) != FAIL) { + vdata_id = VSattach(file_id, vdata_ref, "r"); + if ((status_n = VSfexist(vdata_id, SEARCHED_FIELDS)) != FAIL) { + found_fields = TRUE; + break; + } + + /* + * Detach from the current vdata before continuing searching. + */ + status_32 = VSdetach(vdata_id); + + index++; /* advance the index by 1 for the next vdata */ + } + + /* + * Print the index of the vdata containing the fields or a "not found" + * message if no such vdata is found. Also detach from the vdata found. + */ + if (!found_fields) + printf("Fields Position and Temperature were not found.\n"); + else { + printf("Fields Position and Temperature found in the vdata at position %d\n", index); + status_32 = VSdetach(vdata_id); + } + + /* + * Terminate access to the VS interface and close the HDF file. + */ + status_n = Vend(file_id); + status_32 = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VD/h4ex_VD_read_from_vdata.c b/HDF4Examples/hdf/examples/VD/h4ex_VD_read_from_vdata.c new file mode 100644 index 0000000000..4229fd38b7 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/h4ex_VD_read_from_vdata.c @@ -0,0 +1,86 @@ +#include "hdf.h" + +#define FILE_NAME "General_Vdatas.hdf" +#define VDATA_NAME "Solid Particle" +#define N_RECORDS 5 /* number of records the vdata contains */ +#define RECORD_INDEX 3 /* position where reading starts - 4th record */ +#define ORDER_1 3 /* order of first field to be read */ +#define ORDER_2 2 /* order of second field to be read */ +#define FIELDNAME_LIST "Position,Temperature" /* only two fields are read */ +#define N_VALS_PER_REC (ORDER_1 + ORDER_2) +/* number of values per record */ + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + file_id, vdata_id, vdata_ref, /* vdata's reference number */ + num_of_records, /* number of records actually written to the vdata */ + record_pos; /* position of the current record */ + int16 rec_num; /* current record number in the vdata */ + float32 databuf[N_RECORDS][N_VALS_PER_REC]; /* buffer for vdata values */ + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file for reading. + */ + file_id = Hopen(FILE_NAME, DFACC_READ, 0); + + /* + * Initialize the VS interface. + */ + status_n = Vstart(file_id); + + /* + * Get the reference number of the vdata, whose name is specified in + * VDATA_NAME, using VSfind, which will be discussed in Section 4.7.3. + */ + vdata_ref = VSfind(file_id, VDATA_NAME); + + /* + * Attach to the vdata for reading if it is found, otherwise + * exit the program. + */ + if (vdata_ref == 0) + exit(1); + vdata_id = VSattach(file_id, vdata_ref, "r"); + + /* + * Specify the fields that will be read. + */ + status_n = VSsetfields(vdata_id, FIELDNAME_LIST); + + /* + * Place the current point to the position specified in RECORD_INDEX. + */ + record_pos = VSseek(vdata_id, RECORD_INDEX); + + /* + * Read the next N_RECORDS records from the vdata and store the data + * in the buffer databuf with fully interlaced mode. + */ + num_of_records = VSread(vdata_id, (uint8 *)databuf, N_RECORDS, FULL_INTERLACE); + + /* + * Display the read data as many records as the number of records + * returned by VSread. + */ + printf("\n Particle Position Temperature Range\n\n"); + for (rec_num = 0; rec_num < num_of_records; rec_num++) { + printf(" %6.2f, %6.2f, %6.2f %6.2f, %6.2f\n", databuf[rec_num][0], databuf[rec_num][1], + databuf[rec_num][2], databuf[rec_num][3], databuf[rec_num][4]); + } + + /* + * Terminate access to the vdata and to the VS interface, then close + * the HDF file. + */ + status_32 = VSdetach(vdata_id); + status_n = Vend(file_id); + status_32 = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VD/h4ex_VD_read_mixed_vdata.c b/HDF4Examples/hdf/examples/VD/h4ex_VD_read_mixed_vdata.c new file mode 100644 index 0000000000..a555b61cf3 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/h4ex_VD_read_mixed_vdata.c @@ -0,0 +1,92 @@ +#include "hdf.h" + +#define N_RECORDS 20 /* number of records to be read */ +#define N_FIELDS 2 /* number of fields to be read */ +#define FILE_NAME "Packed_Vdata.hdf" +#define VDATA_NAME "Mixed Data Vdata" +#define FIELDNAME_LIST "Temp,Ident" + +/* number of bytes of the data to be read */ +#define BUFFER_SIZE (sizeof(float32) + sizeof(char)) * N_RECORDS + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + file_id, vdata_id, num_of_records, /* number of records actually read */ + vdata_ref; /* number of bytes the vdata can hold */ + float32 itemp[N_RECORDS]; /* buffer to hold values of first field */ + char idents[N_RECORDS]; /* buffer to hold values of fourth field */ + uint8 databuf[BUFFER_SIZE]; /* buffer to hold read data, still packed */ + VOIDP fldbufptrs[N_FIELDS]; /*pointers to be pointing to the field buffers*/ + int i; + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file for reading. + */ + file_id = Hopen(FILE_NAME, DFACC_READ, 0); + + /* + * Initialize the VS interface. + */ + status_n = Vstart(file_id); + + /* + * Get the reference number of the vdata, whose name is specified in + * VDATA_NAME, using VSfind, which will be discussed in Section 4.7.3. + */ + vdata_ref = VSfind(file_id, VDATA_NAME); + + /* + * Attach to the vdata for reading. + */ + vdata_id = VSattach(file_id, vdata_ref, "r"); + + /* + * Specify the fields that will be read. + */ + status_n = VSsetfields(vdata_id, FIELDNAME_LIST); + + /* + * Read N_RECORDS records of the vdata and store the values into the + * buffer databuf. + */ + num_of_records = VSread(vdata_id, (uint8 *)databuf, N_RECORDS, FULL_INTERLACE); + + /* + * Build an array of pointers each of which points to an array that + * will hold all values of a field after being unpacked. + */ + fldbufptrs[0] = &itemp[0]; + fldbufptrs[1] = &idents[0]; + + /* + * Unpack the data from the buffer databuf and store the values into the + * appropriate field buffers pointed to by the set of pointers fldbufptrs. + * Note that the second parameter is _HDF_VSUNPACK for unpacking and the + * number of records is the one returned by VSread. + */ + status_n = VSfpack(vdata_id, _HDF_VSUNPACK, FIELDNAME_LIST, (VOIDP)databuf, BUFFER_SIZE, num_of_records, + NULL, (VOIDP)fldbufptrs); + + /* + * Display the read data being stored in the field buffers. + */ + printf("\n Temp Ident\n"); + for (i = 0; i < num_of_records; i++) + printf(" %6.2f %c\n", itemp[i], idents[i]); + + /* + * Terminate access to the vdata and the VS interface, then close + * the HDF file. + */ + status_32 = VSdetach(vdata_id); + status_n = Vend(file_id); + status_32 = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VD/h4ex_VD_set_get_vdata_attr.c b/HDF4Examples/hdf/examples/VD/h4ex_VD_set_get_vdata_attr.c new file mode 100644 index 0000000000..35d05b8fd4 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/h4ex_VD_set_get_vdata_attr.c @@ -0,0 +1,124 @@ +#include "hdf.h" + +#define FILE_NAME "General_Vdatas2.hdf" +#define VDATA_NAME "Solid Particle" +#define FIELD_NAME "Mass" +#define VATTR_NAME "Site Ident" /* name of the vdata attribute */ +#define FATTR_NAME "Scales" /* name of the field attribute */ +#define VATTR_N_VALUES 3 /* number of values in the vdata attribute */ +#define FATTR_N_VALUES 4 /* number of values in the field attribute */ + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + file_id, vdata_ref, vdata_id, field_index, /* index of a field within the vdata */ + n_vdattrs, /* number of vdata attributes */ + n_fldattrs, /* number of field attributes */ + vdata_type, /* to hold the type of vdata's attribute */ + vdata_n_values, /* to hold the number of vdata's attribute values */ + vdata_size, /* to hold the size of vdata's attribute values */ + field_type, /* to hold the type of field's attribute */ + field_n_values, /* to hold the number of field's attribute values */ + field_size; /* to hold the size of field's attribute values */ + char vd_attr[VATTR_N_VALUES] = {'A', 'B', 'C'}; /* vdata attribute values*/ + int32 fld_attr[FATTR_N_VALUES] = {2, 4, 6, 8}; /* field attribute values*/ + char vattr_buf[VATTR_N_VALUES]; /* to hold vdata attribute's values */ + int32 fattr_buf[FATTR_N_VALUES]; /* to hold field attribute's values */ + char vattr_name[30], /* name of vdata attribute */ + fattr_name[30]; /* name of field attribute */ + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file for writing. + */ + file_id = Hopen(FILE_NAME, DFACC_WRITE, 0); + + /* + * Initialize the VS interface. + */ + status_n = Vstart(file_id); + + /* + * Get the reference number of the vdata named VDATA_NAME. + */ + vdata_ref = VSfind(file_id, VDATA_NAME); + + /* + * Attach to the vdata for writing. + */ + vdata_id = VSattach(file_id, vdata_ref, "w"); + + /* + * Attach an attribute to the vdata, i.e., indicated by the second parameter. + */ + status_n = VSsetattr(vdata_id, _HDF_VDATA, VATTR_NAME, DFNT_CHAR, VATTR_N_VALUES, vd_attr); + + /* + * Get the index of the field FIELD_NAME within the vdata. + */ + status_n = VSfindex(vdata_id, FIELD_NAME, &field_index); + + /* + * Attach an attribute to the field field_index. + */ + status_n = VSsetattr(vdata_id, field_index, FATTR_NAME, DFNT_INT32, FATTR_N_VALUES, fld_attr); + + /* + * Get the number of attributes attached to the vdata's first + * field - should be 0. + */ + n_fldattrs = VSfnattrs(vdata_id, 0); + printf("Number of attributes of the first field of the vdata: %d\n", n_fldattrs); + + /* + * Get the number of attributes attached to the field specified by + * field_index - should be 1. + */ + n_fldattrs = VSfnattrs(vdata_id, field_index); + printf("Number of attributes of field %s: %d\n", FIELD_NAME, n_fldattrs); + + /* + * Get the total number of the field's and vdata's attributes - should be 2. + */ + n_vdattrs = VSnattrs(vdata_id); + printf("Number of attributes of the vdata and its fields: %d\n", n_vdattrs); + + /* + * Get information about the vdata's first attribute, indicated + * by the third parameter which is the index of the attribute. + */ + status_n = VSattrinfo(vdata_id, _HDF_VDATA, 0, vattr_name, &vdata_type, &vdata_n_values, &vdata_size); + + /* + * Get information about the first attribute of the field specified by + * field_index. + */ + status_n = VSattrinfo(vdata_id, field_index, 0, fattr_name, &field_type, &field_n_values, &field_size); + + /* + * Get the vdata's first attribute. + */ + status_n = VSgetattr(vdata_id, _HDF_VDATA, 0, vattr_buf); + printf("Values of the vdata attribute = %c %c %c\n", vattr_buf[0], vattr_buf[1], vattr_buf[2]); + + /* + * Get the first attribute of the field specified by field_index. + */ + status_n = VSgetattr(vdata_id, field_index, 0, fattr_buf); + printf("Values of the field attribute = %d %d %d %d\n", fattr_buf[0], fattr_buf[1], fattr_buf[2], + fattr_buf[3]); + + /* + * Terminate access to the vdata and to the VS interface, then close + * the HDF file. + */ + status_32 = VSdetach(vdata_id); + status_n = Vend(file_id); + status_32 = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VD/h4ex_VD_write_mixed_vdata.c b/HDF4Examples/hdf/examples/VD/h4ex_VD_write_mixed_vdata.c new file mode 100644 index 0000000000..d85a5ac61e --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/h4ex_VD_write_mixed_vdata.c @@ -0,0 +1,113 @@ +#include "hdf.h" + +#define FILE_NAME "h4ex_VD_write_mixed_vdata.hdf" +#define VDATA_NAME "Mixed Data Vdata" +#define CLASS_NAME "General Data Class" +#define FIELD1_NAME "Temp" +#define FIELD2_NAME "Height" +#define FIELD3_NAME "Speed" +#define FIELD4_NAME "Ident" +#define ORDER 1 /* number of values in the field */ +#define N_RECORDS 20 /* number of records the vdata contains */ +#define N_FIELDS 4 /* number of fields in the vdata */ +#define FIELDNAME_LIST "Temp,Height,Speed,Ident" /* No spaces b/w names */ + +/* number of bytes of the data to be written, i.e., the size of all the + field values combined times the number of records */ +#define BUF_SIZE (2 * sizeof(float32) + sizeof(int16) + sizeof(char)) * N_RECORDS + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + file_id, vdata_id, vdata_ref = -1, /* vdata's reference number, set to -1 to create */ + num_of_records; /* number of records actually written to the vdata */ + float32 temp[N_RECORDS]; /* buffer to hold values of first field */ + int16 height[N_RECORDS]; /* buffer to hold values of second field */ + float32 speed[N_RECORDS]; /* buffer to hold values of third field */ + char8 ident[N_RECORDS]; /* buffer to hold values of fourth field */ + VOIDP fldbufptrs[N_FIELDS]; /*pointers to be pointing to the field buffers*/ + uint16 databuf[BUF_SIZE]; /* buffer to hold the data after being packed*/ + int i; + + /********************** End of variable declaration **********************/ + + /* + * Create an HDF file. + */ + file_id = Hopen(FILE_NAME, DFACC_CREATE, 0); + + /* + * Initialize the VS interface. + */ + status_n = Vstart(file_id); + + /* + * Create a new vdata. + */ + vdata_id = VSattach(file_id, vdata_ref, "w"); + + /* + * Set name and class name of the vdata. + */ + status_32 = VSsetname(vdata_id, VDATA_NAME); + status_32 = VSsetclass(vdata_id, CLASS_NAME); + + /* + * Introduce each field's name, data type, and order. This is the first + * part in defining a vdata field. + */ + status_n = VSfdefine(vdata_id, FIELD1_NAME, DFNT_FLOAT32, ORDER); + status_n = VSfdefine(vdata_id, FIELD2_NAME, DFNT_INT16, ORDER); + status_n = VSfdefine(vdata_id, FIELD3_NAME, DFNT_FLOAT32, ORDER); + status_n = VSfdefine(vdata_id, FIELD4_NAME, DFNT_CHAR8, ORDER); + + /* + * Finalize the definition of the fields of the vdata. + */ + status_n = VSsetfields(vdata_id, FIELDNAME_LIST); + + /* + * Enter data values into the field buffers by the records. + */ + for (i = 0; i < N_RECORDS; i++) { + temp[i] = (float32)(1.11 * (i + 1)); + height[i] = i; + speed[i] = (float32)(1.11 * (i + 1)); + ident[i] = 'A' + i; + } + + /* + * Build an array of pointers each of which points to a field buffer that + * holds all values of the field. + */ + fldbufptrs[0] = &temp[0]; + fldbufptrs[1] = &height[0]; + fldbufptrs[2] = &speed[0]; + fldbufptrs[3] = &ident[0]; + + /* + * Pack all data in the field buffers that are pointed to by the set of + * pointers fldbufptrs, and store the packed data into the buffer + * databuf. Note that the second parameter is _HDF_VSPACK for packing. + */ + status_n = + VSfpack(vdata_id, _HDF_VSPACK, NULL, (VOIDP)databuf, BUF_SIZE, N_RECORDS, NULL, (VOIDP)fldbufptrs); + + /* + * Write all records of the packed data to the vdata. + */ + num_of_records = VSwrite(vdata_id, (uint8 *)databuf, N_RECORDS, FULL_INTERLACE); + + /* + * Terminate access to the vdata and the VS interface, then close + * the HDF file. + */ + status_32 = VSdetach(vdata_id); + status_n = Vend(file_id); + status_32 = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VD/h4ex_VD_write_mixed_vdata_struct.c b/HDF4Examples/hdf/examples/VD/h4ex_VD_write_mixed_vdata_struct.c new file mode 100644 index 0000000000..4f3f664392 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/h4ex_VD_write_mixed_vdata_struct.c @@ -0,0 +1,152 @@ +/* Example 4_struct. Writing a multi-field and mixed-type vdata +with packing - using struct instead of array to buffer field values. + +This example illustrates the use of VSfpack and VSwrite to write a +vdata with data of different types. The problem in this example is +identical to that in Example 4 of Chapter Vdata in the User's Guide. +However, the two programs differ in the implementation of the +data structures that hold the user's data. + +In this example, the program creates an HDF file named +"Packed_Vdata.hdf" then defines a vdata, which is named "Mixed +Data Vdata" and belongs to class "General Data Class". The vdata +contains four order-1 fields, "Temp", "Height", "Speed", and "Ident" of +type float32, int16, float32, and char, respectively. The program then +packs the data in fully interlaced mode into a buffer and writes the +packed data to the vdata. Note that, in this example, each VSfpack +call packs 1 record while in Example 4, a VSfpack call packs all +N_RECORDS. This difference is the result of using an array of +structs in this example to hold the field values instead of +individual arrays as in Example 4. */ + +#include "hdf.h" + +#define FILE_NAME "h4ex_VD_write_mixed_vdata_struct.hdf" +#define VDATA_NAME "Mixed Data Vdata" +#define CLASS_NAME "General Data Class" +#define N_RECORDS 20 /* number of records the vdata contains */ +#define N_FIELDS 4 /* number of fields in the vdata */ +#define FIELD1_NAME "Temp" +#define FIELD2_NAME "Height" +#define FIELD3_NAME "Speed" +#define FIELD4_NAME "Ident" +#define FIELDNAME_LIST "Temp,Height,Speed,Ident" /* No spaces b/w names */ + +/* RECORD_SIZE is the number of bytes of all the field values combined and + BUFFER_SIZE is the number of bytes of data to be written */ +#define RECORD_SIZE (2 * sizeof(float32) + sizeof(int16) + sizeof(char)) +#define BUFFER_SIZE (RECORD_SIZE * N_RECORDS) + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + file_id, vdata_id, num_of_records; /* number of records actually written to the vdata */ + uint8 databuf[BUFFER_SIZE]; /* buffer to hold the data after being packed */ + uint8 *pntr; /* pointer pointing to the current record in the data buffer*/ + int16 rec_num; /* current record number */ + + struct { + float32 temp; /* to hold value of the first field of the vdata */ + int16 height; /* to hold value of the second field of the vdata */ + float32 speed; /* to hold value of the third field of the vdata */ + char ident; /* to hold value of the fourth field of the vdata */ + } source[N_RECORDS]; + + /* pointers to be pointing to the fields in the struct buffer */ + VOIDP fldbufptrs[N_FIELDS]; + + /********************** End of variable declaration **********************/ + + /* + * Create the HDF file. + */ + file_id = Hopen(FILE_NAME, DFACC_CREATE, 0); + + /* + * Initialize the VS interface. + */ + status_n = Vstart(file_id); + + /* + * Create a new vdata. + */ + vdata_id = VSattach(file_id, -1, "w"); + + /* + * Set name and class name of the vdata. + */ + status_32 = VSsetname(vdata_id, VDATA_NAME); + status_32 = VSsetclass(vdata_id, CLASS_NAME); + + /* + * Introduce each field's name, data type, and order. This is the first + * part in defining a vdata field. + */ + status_n = VSfdefine(vdata_id, FIELD1_NAME, DFNT_FLOAT32, 1); + status_n = VSfdefine(vdata_id, FIELD2_NAME, DFNT_INT16, 1); + status_n = VSfdefine(vdata_id, FIELD3_NAME, DFNT_FLOAT32, 1); + status_n = VSfdefine(vdata_id, FIELD4_NAME, DFNT_CHAR8, 1); + + /* + * Finalize the definition of the fields to be written to. + */ + status_n = VSsetfields(vdata_id, FIELDNAME_LIST); + + /* + * Initialize pointer for traversing the buffer to pack each record. + */ + pntr = &databuf[0]; + + /* + * Enter data values into each record. + */ + for (rec_num = 0; rec_num < N_RECORDS; rec_num++) { + source[rec_num].temp = (float32)(1.11 * (rec_num + 1)); + source[rec_num].height = rec_num; + source[rec_num].speed = (float32)(1.11 * (rec_num + 1)); + source[rec_num].ident = 'A' + rec_num; + } + + /* + * Pack one record at a time. + */ + for (rec_num = 0; rec_num < N_RECORDS; rec_num++) { + /* + * Build an array of pointers each of which points to a space that + * holds the value of the corresponding field in this record. + */ + fldbufptrs[0] = &source[rec_num].temp; + fldbufptrs[1] = &source[rec_num].height; + fldbufptrs[2] = &source[rec_num].speed; + fldbufptrs[3] = &source[rec_num].ident; + + /* + * Pack the data in the field buffers into the data buffer at the + * current record, i.e. indicated by "pntr". + */ + status_n = VSfpack(vdata_id, _HDF_VSPACK, NULL, (VOIDP)pntr, RECORD_SIZE, 1, NULL, fldbufptrs); + + /* + * Advance the current position in the buffer. + */ + pntr = pntr + RECORD_SIZE; + } + + /* + * Write all records of the packed data to the vdata. + */ + num_of_records = VSwrite(vdata_id, (uint8 *)databuf, N_RECORDS, FULL_INTERLACE); + + /* + * Terminate access to the Vdata and the VS interface, + * then close the HDF file. + */ + status_32 = VSdetach(vdata_id); + status_n = Vend(file_id); + status_32 = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VD/h4ex_VD_write_to_vdata.c b/HDF4Examples/hdf/examples/VD/h4ex_VD_write_to_vdata.c new file mode 100644 index 0000000000..f82f92c46d --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/h4ex_VD_write_to_vdata.c @@ -0,0 +1,94 @@ +#include "hdf.h" + +#define FILE_NAME "General_Vdatas3.hdf" +#define N_RECORDS 10 /* number of records the vdata contains */ +#define ORDER_1 3 /* order of first field */ +#define ORDER_2 1 /* order of second field */ +#define ORDER_3 2 /* order of third field */ +#define CLASS_NAME "Particle Data" +#define VDATA_NAME "Solid Particle" +#define FIELD1_NAME "Position" /* contains x, y, z values */ +#define FIELD2_NAME "Mass" /* contains weight values */ +#define FIELD3_NAME "Temperature" /* contains min and max values */ +#define FIELDNAME_LIST "Position,Mass,Temperature" /* No spaces b/w names */ + +/* number of values per record */ +#define N_VALS_PER_REC (ORDER_1 + ORDER_2 + ORDER_3) + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + file_id, vdata_id, vdata_ref = -1, /* ref number of a vdata, set to -1 to create */ + num_of_records; /* number of records actually written to vdata */ + int16 rec_num; /* current record number */ + float32 data_buf[N_RECORDS][N_VALS_PER_REC]; /* buffer for vdata values */ + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file for writing. + */ + file_id = Hopen(FILE_NAME, DFACC_WRITE, 0); + + /* + * Initialize the VS interface. + */ + status_n = Vstart(file_id); + + /* + * Create a new vdata. + */ + vdata_id = VSattach(file_id, vdata_ref, "w"); + + /* + * Set name and class name of the vdata. + */ + status_32 = VSsetname(vdata_id, VDATA_NAME); + status_32 = VSsetclass(vdata_id, CLASS_NAME); + + /* + * Introduce each field's name, data type, and order. This is the first + * part in defining a field. + */ + status_n = VSfdefine(vdata_id, FIELD1_NAME, DFNT_FLOAT32, ORDER_1); + status_n = VSfdefine(vdata_id, FIELD2_NAME, DFNT_FLOAT32, ORDER_2); + status_n = VSfdefine(vdata_id, FIELD3_NAME, DFNT_FLOAT32, ORDER_3); + + /* + * Finalize the definition of the fields. + */ + status_n = VSsetfields(vdata_id, FIELDNAME_LIST); + + /* + * Buffer the data by the record for fully interlaced mode. Note that the + * first three elements contain the three values of the first field, the + * fourth element contains the value of the second field, and the last two + * elements contain the two values of the third field. + */ + for (rec_num = 0; rec_num < N_RECORDS; rec_num++) { + data_buf[rec_num][0] = (float32)(1.0 * rec_num); + data_buf[rec_num][1] = (float32)(2.0 * rec_num); + data_buf[rec_num][2] = (float32)(3.0 * rec_num); + data_buf[rec_num][3] = (float32)(0.1 + rec_num); + data_buf[rec_num][4] = (float32)(0.0); + data_buf[rec_num][5] = (float32)(65.0); + } + + /* + * Write the data from data_buf to the vdata with full interlacing mode. + */ + num_of_records = VSwrite(vdata_id, (uint8 *)data_buf, N_RECORDS, FULL_INTERLACE); + + /* + * Terminate access to the vdata and to the VS interface, then close + * the HDF file. + */ + status_32 = VSdetach(vdata_id); + status_n = Vend(file_id); + status_32 = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VD/testfiles/General_Vdatas.hdf b/HDF4Examples/hdf/examples/VD/testfiles/General_Vdatas.hdf new file mode 100644 index 0000000000..c75b1c0d76 Binary files /dev/null and b/HDF4Examples/hdf/examples/VD/testfiles/General_Vdatas.hdf differ diff --git a/HDF4Examples/hdf/examples/VD/testfiles/General_Vdatas2.hdf b/HDF4Examples/hdf/examples/VD/testfiles/General_Vdatas2.hdf new file mode 100644 index 0000000000..c75b1c0d76 Binary files /dev/null and b/HDF4Examples/hdf/examples/VD/testfiles/General_Vdatas2.hdf differ diff --git a/HDF4Examples/hdf/examples/VD/testfiles/General_Vdatas3.hdf b/HDF4Examples/hdf/examples/VD/testfiles/General_Vdatas3.hdf new file mode 100644 index 0000000000..c75b1c0d76 Binary files /dev/null and b/HDF4Examples/hdf/examples/VD/testfiles/General_Vdatas3.hdf differ diff --git a/HDF4Examples/hdf/examples/VD/testfiles/Packed_Vdata.hdf b/HDF4Examples/hdf/examples/VD/testfiles/Packed_Vdata.hdf new file mode 100644 index 0000000000..d9bdbbd39a Binary files /dev/null and b/HDF4Examples/hdf/examples/VD/testfiles/Packed_Vdata.hdf differ diff --git a/HDF4Examples/hdf/examples/VD/testfiles/Two_Vdatas.hdf b/HDF4Examples/hdf/examples/VD/testfiles/Two_Vdatas.hdf new file mode 100644 index 0000000000..5be531acc7 Binary files /dev/null and b/HDF4Examples/hdf/examples/VD/testfiles/Two_Vdatas.hdf differ diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_GR_image_info.tst b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_GR_image_info.tst new file mode 100644 index 0000000000..cd024b60ca --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_GR_image_info.tst @@ -0,0 +1,8 @@ +RI# Name Components Type Interlace Dimensions Attributes + +0 Image Array 1 2 Int16 MFGR_INTERLACE_PIXEL 10, 5 0 +1 Image Array 2 3 Char8 MFGR_INTERLACE_PIXEL 6, 4 2 +2 Image Array 2 3 Char8 MFGR_INTERLACE_PIXEL 6, 4 0 +3 Image Array 2 3 Char8 MFGR_INTERLACE_PIXEL 6, 4 0 +4 Image Array 2 3 Char8 MFGR_INTERLACE_PIXEL 6, 4 0 +5 Image Array 2 3 Char8 MFGR_INTERLACE_PIXEL 6, 4 0 diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_create_onefield_vdatas.ddl b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_create_onefield_vdatas.ddl new file mode 100644 index 0000000000..94f8286828 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_create_onefield_vdatas.ddl @@ -0,0 +1,6 @@ +File name: h4ex_VD_create_onefield_vdatas.hdf + + +Graphical representation of the file:- +(vg#: vgroup; vd: vdata) + diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_create_onefield_vdatas.tst b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_create_onefield_vdatas.tst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_create_vdatas.ddl b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_create_vdatas.ddl new file mode 100644 index 0000000000..96262fe2a8 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_create_vdatas.ddl @@ -0,0 +1,6 @@ +File name: h4ex_VD_create_vdatas.hdf + + +Graphical representation of the file:- +(vg#: vgroup; vd: vdata) + diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_create_vdatas.tst b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_create_vdatas.tst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_get_vdata_info.tst b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_get_vdata_info.tst new file mode 100644 index 0000000000..ac66fa1a91 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_get_vdata_info.tst @@ -0,0 +1,8 @@ +Vdata First Vdata: - contains 5 records + Interlace mode: FULL + Fields: Single-component Field - 1 bytes + +Vdata Second Vdata: - contains 6 records + Interlace mode: FULL + Fields: Multi-component Field - 16 bytes + diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_locate_vdata.tst b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_locate_vdata.tst new file mode 100644 index 0000000000..8d685cc647 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_locate_vdata.tst @@ -0,0 +1 @@ +Fields Position and Temperature were not found. diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_read_from_vdata.tst b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_read_from_vdata.tst new file mode 100644 index 0000000000..24dd6752ef --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_read_from_vdata.tst @@ -0,0 +1,3 @@ + + Particle Position Temperature Range + diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_read_mixed_vdata.tst b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_read_mixed_vdata.tst new file mode 100644 index 0000000000..1ebd9f1892 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_read_mixed_vdata.tst @@ -0,0 +1,22 @@ + + Temp Ident + 1.11 A + 2.22 B + 3.33 C + 4.44 D + 5.55 E + 6.66 F + 7.77 G + 8.88 H + 9.99 I + 11.10 J + 12.21 K + 13.32 L + 14.43 M + 15.54 N + 16.65 O + 17.76 P + 18.87 Q + 19.98 R + 21.09 S + 22.20 T diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_set_get_vdata_attr.tst b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_set_get_vdata_attr.tst new file mode 100644 index 0000000000..6c2f345140 Binary files /dev/null and b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_set_get_vdata_attr.tst differ diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_write_mixed_vdata.ddl b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_write_mixed_vdata.ddl new file mode 100644 index 0000000000..201c4ae387 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_write_mixed_vdata.ddl @@ -0,0 +1,6 @@ +File name: h4ex_VD_write_mixed_vdata.hdf + + +Graphical representation of the file:- +(vg#: vgroup; vd: vdata) + diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_write_mixed_vdata.tst b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_write_mixed_vdata.tst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_write_mixed_vdata_struct.ddl b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_write_mixed_vdata_struct.ddl new file mode 100644 index 0000000000..849b69be90 --- /dev/null +++ b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_write_mixed_vdata_struct.ddl @@ -0,0 +1,6 @@ +File name: h4ex_VD_write_mixed_vdata_struct.hdf + + +Graphical representation of the file:- +(vg#: vgroup; vd: vdata) + diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_write_mixed_vdata_struct.tst b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_write_mixed_vdata_struct.tst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_write_to_vdata.tst b/HDF4Examples/hdf/examples/VD/testfiles/h4ex_VD_write_to_vdata.tst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/HDF4Examples/hdf/examples/VG/CMakeLists.txt b/HDF4Examples/hdf/examples/VG/CMakeLists.txt new file mode 100644 index 0000000000..90eaddc299 --- /dev/null +++ b/HDF4Examples/hdf/examples/VG/CMakeLists.txt @@ -0,0 +1,118 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_HDF_VG C) + +#----------------------------------------------------------------------------- +# Define Sources +#----------------------------------------------------------------------------- +include (C_sourcefiles.cmake) + +foreach (example ${h4examples}) + get_filename_component (example_name ${example} NAME_WE) + add_executable (hdf_${example_name} ${PROJECT_SOURCE_DIR}/${example}) + target_link_libraries (hdf_${example_name} ${H4EX_HDF4_LINK_LIBS}) +endforeach () + +foreach (example ${h4examples_use}) + get_filename_component (example_name ${example} NAME_WE) + add_executable (hdf_${example_name} ${PROJECT_SOURCE_DIR}/${example}) + target_link_libraries (hdf_${example_name} ${H4EX_HDF4_LINK_LIBS}) +endforeach () + +if (H4EX_BUILD_TESTING) + macro (ADD_H4_TEST testname testcreate) + add_test ( + NAME hdf_${testname}-clearall + COMMAND ${CMAKE_COMMAND} + -E remove + ${testname}.hdf + ) + add_test ( + NAME hdf_${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:hdf_${testname}>" + -D "TEST_ARGS:STRING=" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_EXPECT=0" + -D "TEST_OUTPUT=${testname}.out" + -D "TEST_REFERENCE=${testname}.tst" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -P "${HDF4EX_RESOURCES_DIR}/runTest.cmake" + ) + set_tests_properties (hdf_${testname} PROPERTIES DEPENDS hdf_${testname}-clearall) + if (HDF4_BUILD_TOOLS AND ${testcreate} STREQUAL "1") + add_test ( + NAME hdf_HDP-${testname} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=${H4EX_HDF4_DUMP_EXECUTABLE}" + -D "TEST_ARGS:STRING=${ARGN};${testname}.hdf" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_OUTPUT=${testname}.ddl.out" + -D "TEST_EXPECT=0" + -D "TEST_REFERENCE=${testname}.ddl" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -P "${HDF4EX_RESOURCES_DIR}/runTest.cmake" + ) + set_tests_properties (hdf_HDP-${testname} PROPERTIES DEPENDS hdf_${testname}) + endif () + endmacro () + + foreach (example ${h4examples}) + get_filename_component (example_name ${example} NAME_WE) + set (testsrc "${PROJECT_SOURCE_DIR}/testfiles/${example_name}") + set (testdest "${PROJECT_BINARY_DIR}/${example_name}") + add_custom_command ( + OUTPUT "${testdest}.tst" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}.tst" "${testdest}.tst" + DEPENDS "${testsrc}.tst" + ) + list (APPEND HDF4Examples_HDF_VG_TEST_FILES "${testdest}.tst") + if (HDF4_BUILD_TOOLS) + add_custom_command ( + OUTPUT "${testdest}.ddl" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}.ddl" "${testdest}.ddl" + DEPENDS "${testsrc}.ddl" + ) + list (APPEND HDF4Examples_HDF_VG_TEST_FILES "${testdest}.ddl") + endif () + endforeach () + + foreach (example ${h4examples_use}) + get_filename_component (example_name ${example} NAME_WE) + set (testsrc "${PROJECT_SOURCE_DIR}/testfiles/${example_name}") + set (testdest "${PROJECT_BINARY_DIR}/${example_name}") + add_custom_command ( + OUTPUT "${testdest}.tst" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}.tst" "${testdest}.tst" + DEPENDS "${testsrc}.tst" + ) + list (APPEND HDF4Examples_HDF_VG_TEST_FILES "${testdest}.tst") + endforeach () + + foreach (ex_file ${h4examples_files}) + set (testsrc "${PROJECT_SOURCE_DIR}/testfiles/${ex_file}") + set (testdest "${PROJECT_BINARY_DIR}/${ex_file}") + add_custom_command ( + OUTPUT "${testdest}" + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different "${testsrc}" "${testdest}" + DEPENDS "${testsrc}" + ) + list (APPEND HDF4Examples_HDF_VG_TEST_FILES "${testdest}") + endforeach () + + add_custom_target (HDF4Examples_HDF_VG-files ALL COMMENT "Copying files needed by VG tests" + DEPENDS ${HDF4Examples_HDF_VG_TEST_FILES}) + + foreach (example ${h4examples}) + get_filename_component (example_name ${example} NAME_WE) + ADD_H4_TEST (${example_name} 1 dumpvg) + endforeach () + + foreach (example ${h4examples_use}) + get_filename_component (example_name ${example} NAME_WE) + ADD_H4_TEST (${example_name} 0 dumpvg) + endforeach () +endif () diff --git a/HDF4Examples/hdf/examples/VG/C_sourcefiles.cmake b/HDF4Examples/hdf/examples/VG/C_sourcefiles.cmake new file mode 100644 index 0000000000..b8cbe366e9 --- /dev/null +++ b/HDF4Examples/hdf/examples/VG/C_sourcefiles.cmake @@ -0,0 +1,19 @@ +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +set (h4examples + h4ex_VG_add_sds_to_vgroup.c + h4ex_VG_create_vgroup.c +) +set (h4examples_use + h4ex_VG_get_vgroup_info.c + h4ex_VG_insert_vdatas_to_vgroup.c + #h4ex_VG_set_get_vgroup_attr.c + h4ex_VG_vgroup_contents.c +) +set (h4examples_files + General_Vgroups.hdf + General_Vgroups2.hdf + General_Vgroups3.hdf + General_Vgroups4.hdf +) diff --git a/HDF4Examples/hdf/examples/VG/h4ex_VG_add_sds_to_vgroup.c b/HDF4Examples/hdf/examples/VG/h4ex_VG_add_sds_to_vgroup.c new file mode 100644 index 0000000000..7bf739219f --- /dev/null +++ b/HDF4Examples/hdf/examples/VG/h4ex_VG_add_sds_to_vgroup.c @@ -0,0 +1,83 @@ +#include "hdf.h" /* Note: in this example, hdf.h can be omitted...*/ +#include "mfhdf.h" /* ...since mfhdf.h already includes hdf.h */ + +#define FILE_NAME "h4ex_VG_add_sds_to_vgroup.hdf" +#define SDS_NAME "Test SD" +#define VG_NAME "SD Vgroup" +#define VG_CLASS "Common Vgroups" + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + sd_id, /* SD interface identifier */ + sds_id, /* data set identifier */ + sds_ref, /* reference number of the data set */ + dim_sizes[1], /* dimension of the data set - only one */ + rank = 1, /* rank of the data set array */ + vgroup_id, /* vgroup identifier */ + file_id; /* HDF file identifier, same for V interface */ + + /********************** End of variable declaration **********************/ + + /* + * Create the HDF file. + */ + file_id = Hopen(FILE_NAME, DFACC_CREATE, 0); + + /* + * Initialize the V interface. + */ + status_n = Vstart(file_id); + + /* + * Initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_WRITE); + + /* + * Set the size of the SDS's dimension. + */ + dim_sizes[0] = 10; + + /* + * Create the SDS. + */ + sds_id = SDcreate(sd_id, SDS_NAME, DFNT_INT32, rank, dim_sizes); + + /* + * Create a vgroup and set its name and class. + */ + vgroup_id = Vattach(file_id, -1, "w"); + status_32 = Vsetname(vgroup_id, VG_NAME); + status_32 = Vsetclass(vgroup_id, VG_CLASS); + + /* + * Obtain the reference number of the SDS using its identifier. + */ + sds_ref = SDidtoref(sds_id); + + /* + * Add the SDS to the vgroup. Note: the tag DFTAG_NDG is used + * when adding an SDS. Refer to Appendix A for the entire list of tags. + */ + status_32 = Vaddtagref(vgroup_id, DFTAG_NDG, sds_ref); + + /* + * Terminate access to the SDS and to the SD interface. + */ + status_n = SDendaccess(sds_id); + status_n = SDend(sd_id); + + /* + * Terminate access to the vgroup and to the V interface, and + * close the HDF file. + */ + status_32 = Vdetach(vgroup_id); + status_n = Vend(file_id); + status_n = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VG/h4ex_VG_create_vgroup.c b/HDF4Examples/hdf/examples/VG/h4ex_VG_create_vgroup.c new file mode 100644 index 0000000000..79c9b3854d --- /dev/null +++ b/HDF4Examples/hdf/examples/VG/h4ex_VG_create_vgroup.c @@ -0,0 +1,57 @@ +#include "hdf.h" + +#define FILE_NAME "h4ex_VG_create_vgroup.hdf" + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + vgroup_ref = -1, vgroup1_id, vgroup2_id, file_id; + + /********************** End of variable declaration **********************/ + + /* + * Create the HDF file. + */ + file_id = Hopen(FILE_NAME, DFACC_CREATE, 0); + + /* + * Initialize the V interface. + */ + status_n = Vstart(file_id); + + /* + * Create the first vgroup. Note that the vgroup reference number is set + * to -1 for creating and the access mode is "w" for writing. + */ + vgroup1_id = Vattach(file_id, vgroup_ref, "w"); + + /* + * Create the second vgroup. + */ + vgroup2_id = Vattach(file_id, vgroup_ref, "w"); + + /* + * Any operations on the vgroups. + */ + + /* + * Terminate access to the first vgroup. + */ + status_32 = Vdetach(vgroup1_id); + + /* + * Terminate access to the second vgroup. + */ + status_32 = Vdetach(vgroup2_id); + + /* + * Terminate access to the V interface and close the HDF file. + */ + status_n = Vend(file_id); + status_n = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VG/h4ex_VG_get_vgroup_info.c b/HDF4Examples/hdf/examples/VG/h4ex_VG_get_vgroup_info.c new file mode 100644 index 0000000000..fac66276d7 --- /dev/null +++ b/HDF4Examples/hdf/examples/VG/h4ex_VG_get_vgroup_info.c @@ -0,0 +1,100 @@ +#include "hdf.h" + +#define FILE_NAME "General_Vgroups.hdf" + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + file_id, vgroup_id; + int32 lone_vg_number, /* current lone vgroup number */ + num_of_lones = 0; /* number of lone vgroups */ + int32 *ref_array; /* buffer to hold the ref numbers of lone vgroups */ + char *vgroup_name, *vgroup_class; + uint16 name_len; + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file for reading. + */ + file_id = Hopen(FILE_NAME, DFACC_READ, 0); + + /* + * Initialize the V interface. + */ + status_n = Vstart(file_id); + + /* + * Get and print the names and class names of all the lone vgroups. + * First, call Vlone with num_of_lones set to 0 to get the number of + * lone vgroups in the file, but not to get their reference numbers. + */ + num_of_lones = Vlone(file_id, NULL, num_of_lones); + + /* + * Then, if there are any lone vgroups, + */ + if (num_of_lones > 0) { + /* + * use the num_of_lones returned to allocate sufficient space for the + * buffer ref_array to hold the reference numbers of all lone vgroups, + */ + ref_array = (int32 *)malloc(sizeof(int32) * num_of_lones); + + /* + * and call Vlone again to retrieve the reference numbers into + * the buffer ref_array. + */ + num_of_lones = Vlone(file_id, ref_array, num_of_lones); + + /* + * Display the name and class of each lone vgroup. + */ + printf("Lone vgroups in this file are:\n"); + for (lone_vg_number = 0; lone_vg_number < num_of_lones; lone_vg_number++) { + /* + * Attach to the current vgroup then get and display its + * name and class. Note: the current vgroup must be detached before + * moving to the next. + */ + vgroup_id = Vattach(file_id, ref_array[lone_vg_number], "r"); + status_32 = Vgetnamelen(vgroup_id, &name_len); + vgroup_name = (char *)HDmalloc(sizeof(char *) * (name_len + 1)); + if (vgroup_name == NULL) { + fprintf(stderr, "Not enough memory for vgroup_name!\n"); + exit(1); + } + status_32 = Vgetname(vgroup_id, vgroup_name); + + status_32 = Vgetclassnamelen(vgroup_id, &name_len); + vgroup_class = (char *)HDmalloc(sizeof(char *) * (name_len + 1)); + if (vgroup_class == NULL) { + fprintf(stderr, "Not enough memory for vgroup_class!\n"); + exit(1); + } + status_32 = Vgetclass(vgroup_id, vgroup_class); + printf(" Vgroup name %s and class %s\n", vgroup_name, vgroup_class); + status_32 = Vdetach(vgroup_id); + if (vgroup_name != NULL) + HDfree(vgroup_name); + if (vgroup_class != NULL) + HDfree(vgroup_class); + } /* for */ + } /* if */ + + /* + * Terminate access to the V interface and close the file. + */ + status_n = Vend(file_id); + status_n = Hclose(file_id); + + /* + * Free the space allocated by this program. + */ + free(ref_array); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VG/h4ex_VG_insert_vdatas_to_vgroup.c b/HDF4Examples/hdf/examples/VG/h4ex_VG_insert_vdatas_to_vgroup.c new file mode 100644 index 0000000000..4614d58619 --- /dev/null +++ b/HDF4Examples/hdf/examples/VG/h4ex_VG_insert_vdatas_to_vgroup.c @@ -0,0 +1,141 @@ +#include "hdf.h" + +#define FILE_NAME "General_Vgroups3.hdf" +#define N_RECORDS 30 /* number of records in the vdatas */ +#define ORDER 3 /* order of field FIELD_VD2 */ +#define VG_NAME "Vertices" +#define VG_CLASS "Vertex Set" +#define VD1_NAME "X,Y Coordinates" /* first vdata to hold X,Y...*/ +#define VD1_CLASS "Position" /*...values of the vertices */ +#define VD2_NAME "Temperature" /* second vdata to hold the...*/ +#define VD2_CLASS "Property List" /*...temperature field */ +#define VD3_NAME "Node List" /* third vdata to hold...*/ +#define VD3_CLASS "Mesh" /*...the list of nodes */ +#define FIELD1_VD1 "PX" /* first field of first vdata - X values */ +#define FIELD2_VD1 "PY" /* second field of first vdata - Y values */ +#define FIELD_VD2 "TMP" /* field of third vdata */ +#define FIELD_VD3 "PLIST" /* field of second vdata */ +#define FIELDNAME_LIST "PX,PY" /* field name list for first vdata */ +/* Note that the second and third vdatas can use the field names as + the field name lists unless more fields are added to a vdata. + Then a field name list is needed for that vdata */ + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + file_id, vgroup_id, vdata1_id, vdata2_id, vdata3_id; + int32 num_of_records, /* number of records actually written */ + vd_index; /* position of a vdata in the vgroup */ + int8 i, j, k = 0; + float32 pxy[N_RECORDS][2] = /* buffer for data of the first vdata */ + {-1.5, 2.3, -1.5, 1.98, -2.4, .67, -3.4, 1.46, -.65, 3.1, -.62, 1.23, -.4, 3.8, -3.55, + 2.3, -1.43, 2.44, .23, 1.13, -1.4, 5.43, -1.4, 5.8, -3.4, 3.85, -.55, .3, -.21, 1.22, + -1.44, 1.9, -1.4, 2.8, .94, 1.78, -.4, 2.32, -.87, 1.99, -.54, 4.11, -1.5, 1.35, -1.4, + 2.21, -.22, 1.8, -1.1, 4.55, -.44, .54, -1.11, 3.93, -.76, 1.9, -2.34, 1.7, -2.2, 1.21}; + float32 tmp[N_RECORDS]; /* buffer for data of the second vdata */ + int16 plist[N_RECORDS][3]; /* buffer for data of the third vdata */ + + /********************** End of variable declaration ***********************/ + + /* + * Open the HDF file for writing. + */ + file_id = Hopen(FILE_NAME, DFACC_WRITE, 0); + + /* + * Initialize the V interface. + */ + status_n = Vstart(file_id); + + /* + * Buffer the data for the second and third vdatas. + */ + for (i = 0; i < N_RECORDS; i++) + for (j = 0; j < ORDER; j++) + plist[i][j] = ++k; + + for (i = 0; i < N_RECORDS; i++) + tmp[i] = (float32)(i * 10.0); + + /* + * Create the vgroup then set its name and class. Note that the vgroup's + * reference number is set to -1 for creating and the access mode is "w" for + * writing. + */ + vgroup_id = Vattach(file_id, -1, "w"); + status_32 = Vsetname(vgroup_id, VG_NAME); + status_32 = Vsetclass(vgroup_id, VG_CLASS); + + /* + * Create the first vdata then set its name and class. Note that the vdata's + * reference number is set to -1 for creating and the access mode is "w" for + * writing. + */ + vdata1_id = VSattach(file_id, -1, "w"); + status_32 = VSsetname(vdata1_id, VD1_NAME); + status_32 = VSsetclass(vdata1_id, VD1_CLASS); + + /* + * Introduce and define the fields of the first vdata. + */ + status_n = VSfdefine(vdata1_id, FIELD1_VD1, DFNT_FLOAT32, 1); + status_n = VSfdefine(vdata1_id, FIELD2_VD1, DFNT_FLOAT32, 1); + status_n = VSsetfields(vdata1_id, FIELDNAME_LIST); + + /* + * Write the buffered data into the first vdata with full interlace mode. + */ + num_of_records = VSwrite(vdata1_id, (uint8 *)pxy, N_RECORDS, FULL_INTERLACE); + + /* + * Insert the vdata into the vgroup using its identifier. + */ + vd_index = Vinsert(vgroup_id, vdata1_id); + + /* + * Detach from the first vdata. + */ + status_32 = VSdetach(vdata1_id); + + /* + * Create, write, and insert the second vdata to the vgroup using + * steps similar to those used for the first vdata. + */ + vdata2_id = VSattach(file_id, -1, "w"); + status_32 = VSsetname(vdata2_id, VD2_NAME); + status_32 = VSsetclass(vdata2_id, VD2_CLASS); + status_n = VSfdefine(vdata2_id, FIELD_VD2, DFNT_FLOAT32, 1); + status_n = VSsetfields(vdata2_id, FIELD_VD2); + num_of_records = VSwrite(vdata2_id, (uint8 *)tmp, N_RECORDS, FULL_INTERLACE); + vd_index = Vinsert(vgroup_id, vdata2_id); + status_32 = VSdetach(vdata2_id); + + /* + * Create, write, and insert the third vdata to the vgroup using + * steps similar to those used for the first and second vdatas. + */ + vdata3_id = VSattach(file_id, -1, "w"); + status_32 = VSsetname(vdata3_id, VD3_NAME); + status_32 = VSsetclass(vdata3_id, VD3_CLASS); + status_n = VSfdefine(vdata3_id, FIELD_VD3, DFNT_INT16, 3); + status_n = VSsetfields(vdata3_id, FIELD_VD3); + num_of_records = VSwrite(vdata3_id, (uint8 *)plist, N_RECORDS, FULL_INTERLACE); + vd_index = Vinsert(vgroup_id, vdata3_id); + status_32 = VSdetach(vdata3_id); + + /* + * Terminate access to the vgroup "Vertices". + */ + status_32 = Vdetach(vgroup_id); + + /* + * Terminate access to the V interface and close the HDF file. + */ + status_n = Vend(file_id); + status_n = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VG/h4ex_VG_set_get_vgroup_attr.c b/HDF4Examples/hdf/examples/VG/h4ex_VG_set_get_vgroup_attr.c new file mode 100644 index 0000000000..e5426a06b9 --- /dev/null +++ b/HDF4Examples/hdf/examples/VG/h4ex_VG_set_get_vgroup_attr.c @@ -0,0 +1,97 @@ +#include "hdf.h" + +#define FILE_NAME "General_Vgroups2.hdf" +#define VGROUP_NAME "SD Vgroup" +#define VGATTR_NAME "First Attribute" +#define N_ATT_VALUES 7 /* number of values in the attribute */ + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n, /* returned status for functions returning an intn */ + n_attrs; /* number of attributes of the vgroup */ + int32 status_32, /* returned status for functions returning an int32 */ + file_id, vgroup_ref, vgroup_id, attr_index, i, vg_version, data_type, n_values, size; + char vg_attr[N_ATT_VALUES] = {'v', 'g', 'r', 'o', 'u', 'p', '\0'}; + char vgattr_buf[N_ATT_VALUES], attr_name[30]; + + /********************** End of variable declaration **********************/ + + /* + * Open the HDF file for writing. + */ + file_id = Hopen(FILE_NAME, DFACC_WRITE, 0); + + /* + * Initialize the V interface. + */ + status_n = Vstart(file_id); + + /* + * Get the reference number of the vgroup named VGROUP_NAME. + */ + vgroup_ref = Vfind(file_id, VGROUP_NAME); + + /* + * Attach to the vgroup found. + */ + vgroup_id = Vattach(file_id, vgroup_ref, "w"); + + /* + * Get and display the version of the attached vgroup. + */ + vg_version = Vgetversion(vgroup_id); + switch (vg_version) { + case VSET_NEW_VERSION: + printf("\nVgroup %s is of the newest version, version 4\n", VGROUP_NAME); + break; + case VSET_VERSION: + printf("Vgroup %s is of a version between 3.2 and 4.0r2\n", VGROUP_NAME); + break; + case VSET_OLD_VERSION: + printf("Vgroup %s is of version before 3.2\n", VGROUP_NAME); + break; + default: + printf("Unknown version = %d\n", vg_version); + } /* switch */ + + /* + * Add the attribute named VGATTR_NAME to the vgroup. + */ + status_n = Vsetattr(vgroup_id, VGATTR_NAME, DFNT_CHAR, N_ATT_VALUES, vg_attr); + + /* + * Get and display the number of attributes attached to this vgroup. + */ + n_attrs = Vnattrs(vgroup_id); + printf("\nThis vgroup has %d attribute(s)\n", n_attrs); + + /* + * Get and display the name and the number of values of each attribute. + * Note that the fourth and last parameters are set to NULL because the type + * and the size of the attribute are not desired. + */ + for (attr_index = 0; attr_index < n_attrs; attr_index++) { + status_n = Vattrinfo(vgroup_id, attr_index, attr_name, NULL, &n_values, NULL); + printf("\nAttribute #%d is named %s and has %d values: ", attr_index + 1, attr_name, n_values); + + /* + * Get and display the attribute values. + */ + status_n = Vgetattr(vgroup_id, attr_index, vgattr_buf); + for (i = 0; i < n_values; i++) + printf("%c ", vgattr_buf[i]); + printf("\n"); + } + + /* + * Terminate access to the vgroup and to the V interface, and close + * the HDF file. + */ + status_32 = Vdetach(vgroup_id); + status_n = Vend(file_id); + status_n = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VG/h4ex_VG_vgroup_contents.c b/HDF4Examples/hdf/examples/VG/h4ex_VG_vgroup_contents.c new file mode 100644 index 0000000000..6588e3a7dc --- /dev/null +++ b/HDF4Examples/hdf/examples/VG/h4ex_VG_vgroup_contents.c @@ -0,0 +1,102 @@ +#include "hdf.h" + +#define FILE_NAME "General_Vgroups4.hdf" + +int +main() +{ + /************************* Variable declaration **************************/ + + intn status_n; /* returned status for functions returning an intn */ + int32 status_32, /* returned status for functions returning an int32 */ + file_id, vgroup_id, vgroup_ref, obj_index, /* index of an object within a vgroup */ + num_of_pairs, /* number of tag/ref number pairs, i.e., objects */ + obj_tag, obj_ref, /* tag/ref number of an HDF object */ + vgroup_pos = 0; /* position of a vgroup in the file */ + + /********************** End of variable declaration ***********************/ + + /* + * Open the HDF file for reading. + */ + file_id = Hopen(FILE_NAME, DFACC_READ, 0); + + /* + * Initialize the V interface. + */ + status_n = Vstart(file_id); + + /* + * Obtain each vgroup in the file by its reference number, get the + * number of objects in the vgroup, and display the information about + * that vgroup. + */ + vgroup_ref = -1; /* set to -1 to search from the beginning of file */ + while (TRUE) { + /* + * Get the reference number of the next vgroup in the file. + */ + vgroup_ref = Vgetid(file_id, vgroup_ref); + + /* + * Attach to the vgroup for reading or exit the loop if no more vgroups + * are found. + */ + if (vgroup_ref == -1) + break; + vgroup_id = Vattach(file_id, vgroup_ref, "r"); + + /* + * Get the total number of objects in the vgroup. + */ + num_of_pairs = Vntagrefs(vgroup_id); + + /* + * If the vgroup contains any object, print the tag/ref number + * pair of each object in the vgroup, in the order they appear in the + * file, and indicate whether the object is a vdata, vgroup, or neither. + */ + if (num_of_pairs > 0) { + printf("\nVgroup #%d contains:\n", vgroup_pos); + for (obj_index = 0; obj_index < num_of_pairs; obj_index++) { + /* + * Get the tag/ref number pair of the object specified + * by its index, obj_index, and display them. + */ + status_n = Vgettagref(vgroup_id, obj_index, &obj_tag, &obj_ref); + printf("tag = %d, ref = %d", obj_tag, obj_ref); + + /* + * State whether the HDF object referred to by obj_ref is a vdata, + * a vgroup, or neither. + */ + if (Visvg(vgroup_id, obj_ref)) + printf(" <-- is a vgroup\n"); + else if (Visvs(vgroup_id, obj_ref)) + printf(" <-- is a vdata\n"); + else + printf(" <-- neither vdata nor vgroup\n"); + } /* for */ + } /* if */ + + else + printf("Vgroup #%d contains no HDF objects\n", vgroup_pos); + + /* + * Terminate access to the current vgroup. + */ + status_32 = Vdetach(vgroup_id); + + /* + * Move to the next vgroup position. + */ + vgroup_pos++; + } /* while */ + + /* + * Terminate access to the V interface and close the file. + */ + status_n = Vend(file_id); + status_n = Hclose(file_id); + return 0; +} diff --git a/HDF4Examples/hdf/examples/VG/testfiles/General_Vgroups.hdf b/HDF4Examples/hdf/examples/VG/testfiles/General_Vgroups.hdf new file mode 100644 index 0000000000..1f5fa6a6b6 Binary files /dev/null and b/HDF4Examples/hdf/examples/VG/testfiles/General_Vgroups.hdf differ diff --git a/HDF4Examples/hdf/examples/VG/testfiles/General_Vgroups2.hdf b/HDF4Examples/hdf/examples/VG/testfiles/General_Vgroups2.hdf new file mode 100644 index 0000000000..1f5fa6a6b6 Binary files /dev/null and b/HDF4Examples/hdf/examples/VG/testfiles/General_Vgroups2.hdf differ diff --git a/HDF4Examples/hdf/examples/VG/testfiles/General_Vgroups3.hdf b/HDF4Examples/hdf/examples/VG/testfiles/General_Vgroups3.hdf new file mode 100644 index 0000000000..1f5fa6a6b6 Binary files /dev/null and b/HDF4Examples/hdf/examples/VG/testfiles/General_Vgroups3.hdf differ diff --git a/HDF4Examples/hdf/examples/VG/testfiles/General_Vgroups4.hdf b/HDF4Examples/hdf/examples/VG/testfiles/General_Vgroups4.hdf new file mode 100644 index 0000000000..1f5fa6a6b6 Binary files /dev/null and b/HDF4Examples/hdf/examples/VG/testfiles/General_Vgroups4.hdf differ diff --git a/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_add_sds_to_vgroup.ddl b/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_add_sds_to_vgroup.ddl new file mode 100644 index 0000000000..c2b80a492c --- /dev/null +++ b/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_add_sds_to_vgroup.ddl @@ -0,0 +1,92 @@ +File name: h4ex_VG_add_sds_to_vgroup.hdf + + +Vgroup:0 + tag = 1965; reference = 3; + name = SD Vgroup; class = Common Vgroups; + number of entries = 1; + number of attributes = 0 +Entries:- + #0 (Numeric Data Group) + tag = 720; reference = 2; + + +Vgroup:1 + tag = 1965; reference = 5; + name = fakeDim0; class = Dim0.0; + number of entries = 1; + number of attributes = 0 +Entries:- + #0 (Vdata) + tag = 1962; reference = 4; + number of records = 1; interlace = 0; + fields = [Values]; + record size (in bytes) = 4; + name = fakeDim0; class = DimVal0.1; + total number of attributes = 0. + + +Vgroup:2 + tag = 1965; reference = 8; + name = Test SD; class = Var0.0; + number of entries = 5; + number of attributes = 0 +Entries:- + #0 (Vgroup) + tag = 1965; reference = 5; + number of entries = 1; + name = fakeDim0; class = Dim0.0 + number of attributes = 0 + #1 (Vdata) + tag = 1962; reference = 6; + number of records = 0; interlace = 0; + fields = [SDS variable]; + record size (in bytes) = 4; + name = <Undefined>; class = SDSVar; + total number of attributes = 0. + #2 (Number type) + tag = 106; reference = 7; + #3 (SciData dimension record) + tag = 701; reference = 7; + #4 (Numeric Data Group) + tag = 720; reference = 2; + + +Vgroup:3 + tag = 1965; reference = 9; + name = h4ex_VG_add_sds_to_vgroup.hdf; class = CDF0.0; + number of entries = 2; + number of attributes = 0 +Entries:- + #0 (Vgroup) + tag = 1965; reference = 5; + number of entries = 1; + name = fakeDim0; class = Dim0.0 + number of attributes = 0 + #1 (Vgroup) + tag = 1965; reference = 8; + number of entries = 5; + name = Test SD; class = Var0.0 + number of attributes = 0 + + +Graphical representation of the file:- +(vg#: vgroup; vd: vdata) + + vg0 -- Numeric Data Group + + vg1 -- vd + + vg2 -- vg1 -- vd + -- vd + -- Number type + -- SciData dimension record + -- Numeric Data Group + + vg3 -- vg1 -- vd + -- vg2 -- vg1 -- vd + -- vd + -- Number type + -- SciData dimension record + -- Numeric Data Group + diff --git a/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_add_sds_to_vgroup.tst b/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_add_sds_to_vgroup.tst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_create_vgroup.ddl b/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_create_vgroup.ddl new file mode 100644 index 0000000000..896343e984 --- /dev/null +++ b/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_create_vgroup.ddl @@ -0,0 +1,28 @@ +File name: h4ex_VG_create_vgroup.hdf + + +Vgroup:0 + tag = 1965; reference = 2; + name = <Undefined>; class = <Undefined>; + number of entries = 0; + number of attributes = 0 +Entries:- + None. + + +Vgroup:1 + tag = 1965; reference = 3; + name = <Undefined>; class = <Undefined>; + number of entries = 0; + number of attributes = 0 +Entries:- + None. + + +Graphical representation of the file:- +(vg#: vgroup; vd: vdata) + + vg0 + + vg1 + diff --git a/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_create_vgroup.tst b/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_create_vgroup.tst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_get_vgroup_info.tst b/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_get_vgroup_info.tst new file mode 100644 index 0000000000..63e3e5e215 --- /dev/null +++ b/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_get_vgroup_info.tst @@ -0,0 +1,3 @@ +Lone vgroups in this file are: + Vgroup name SD Vgroup and class Common Vgroups + Vgroup name h4ex_VG_add_sds_to_vgroup.hdf and class CDF0.0 diff --git a/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_insert_vdatas_to_vgroup.tst b/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_insert_vdatas_to_vgroup.tst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_set_get_vgroup_attr.tst b/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_set_get_vgroup_attr.tst new file mode 100644 index 0000000000..c7bf9f6477 Binary files /dev/null and b/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_set_get_vgroup_attr.tst differ diff --git a/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_vgroup_contents.tst b/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_vgroup_contents.tst new file mode 100644 index 0000000000..05f0ef4d5d --- /dev/null +++ b/HDF4Examples/hdf/examples/VG/testfiles/h4ex_VG_vgroup_contents.tst @@ -0,0 +1,17 @@ + +Vgroup #0 contains: +tag = 720, ref = 2 <-- neither vdata nor vgroup + +Vgroup #1 contains: +tag = 1962, ref = 4 <-- is a vdata + +Vgroup #2 contains: +tag = 1965, ref = 5 <-- is a vgroup +tag = 1962, ref = 6 <-- is a vdata +tag = 106, ref = 7 <-- neither vdata nor vgroup +tag = 701, ref = 7 <-- neither vdata nor vgroup +tag = 720, ref = 2 <-- neither vdata nor vgroup + +Vgroup #3 contains: +tag = 1965, ref = 5 <-- is a vgroup +tag = 1965, ref = 8 <-- is a vgroup diff --git a/HDF4Examples/hdf/fortran/CMakeLists.txt b/HDF4Examples/hdf/fortran/CMakeLists.txt new file mode 100644 index 0000000000..ad020fbb38 --- /dev/null +++ b/HDF4Examples/hdf/fortran/CMakeLists.txt @@ -0,0 +1,120 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_HDF_FORTRAN Fortran) +# -------------------------------------------------------------------- +# Notes: When creating examples they should be prefixed +# with "f_ex_". This allows for easier filtering of the examples. +# -------------------------------------------------------------------- + +if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0) + set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch") +endif () + +#----------------------------------------------------------------------------- +# Add debug information (intel Fortran : JB) +#----------------------------------------------------------------------------- +if (CMAKE_Fortran_COMPILER MATCHES ifort) + if (WIN32) + set (CMAKE_Fortran_FLAGS_DEBUG "/debug:full /dbglibs " CACHE STRING "flags" FORCE) + set (CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG" CACHE STRING "flags" FORCE) + endif () +endif () + +#----------------------------------------------------------------------------- +# Setup include Directories +#----------------------------------------------------------------------------- +INCLUDE_DIRECTORIES ( + ${CMAKE_Fortran_MODULE_DIRECTORY}${HDF_MOD_EXT} + ${PROJECT_BINARY_DIR} + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} +) + +#----------------------------------------------------------------------------- +# Define Sources +#----------------------------------------------------------------------------- +include (Fortran_sourcefiles.cmake) + +# Remove any output file left over from previous test run +add_test ( + NAME HDF_FORTRAN_EXAMPLES-clearall-objects + COMMAND ${CMAKE_COMMAND} + -E remove + General_HDFobjects.hdf + General_RImages.hdf + General_Vdatas.hdf + General_Vgroups.hdf + Image_with_Palette.hdf + Packed_Vdata.hdf + Two_Vdatas.hdf + Two_Vgroups.hdf +) +if (NOT "${last_test}" STREQUAL "") + set_tests_properties (HDF_FORTRAN_EXAMPLES-clearall-objects PROPERTIES DEPENDS ${last_test} LABELS EXAMPLES) +else () + set_tests_properties (HDF_FORTRAN_EXAMPLES-clearall-objects PROPERTIES LABELS EXAMPLES) +endif () +set (last_test "HDF_FORTRAN_EXAMPLES-clearall-objects") + +foreach (example ${examples}) + get_filename_component(example_name ${example} NAME_WE) + add_executable (${EXAMPLE_VARNAME}_f_ex_${example_name} ${PROJECT_SOURCE_DIR}/${example}) + set_target_properties (${EXAMPLE_VARNAME}_f_ex_${example_name} PROPERTIES LINKER_LANGUAGE Fortran) + target_link_libraries (${EXAMPLE_VARNAME}_f_ex_${example_name} ${H4EX_HDF4_LINK_LIBS}) + if (H4EX_BUILD_TESTING) + add_test ( + NAME ${EXAMPLE_VARNAME}_f_extest_${example_name} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:${EXAMPLE_VARNAME}_f_ex_${example_name}>" + -D "TEST_ARGS:STRING=" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_EXPECT=0" + -D "TEST_SKIP_COMPARE=TRUE" + -D "TEST_OUTPUT=${testname}.out" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -P "${${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR}/runTest.cmake" + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (${EXAMPLE_VARNAME}_f_extest_${example_name} PROPERTIES DEPENDS ${last_test} LABELS EXAMPLES) + else () + set_tests_properties (${EXAMPLE_VARNAME}_f_extest_${example_name} PROPERTIES LABELS EXAMPLES) + endif () + set (last_test "${EXAMPLE_VARNAME}_f_extest_${example_name}") + endif () +endforeach () + +add_executable (f_ex_h4ex_VG_add_sds_to_vgroup ${PROJECT_SOURCE_DIR}/h4ex_VG_add_sds_to_vgroup.f) +set_target_properties (f_ex_h4ex_VG_add_sds_to_vgroup PROPERTIES LINKER_LANGUAGE Fortran) +target_link_libraries (f_ex_h4ex_VG_add_sds_to_vgroup ${H4EX_HDF4_LINK_LIBS}) + +if (BUILD_TESTING) + add_test ( + NAME f_extest_h4ex_VG_add_sds_to_vgroup + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:f_ex_h4ex_VG_add_sds_to_vgroup>" + -D "TEST_ARGS:STRING=" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_EXPECT=0" + -D "TEST_SKIP_COMPARE=TRUE" + -D "TEST_OUTPUT=${testname}.out" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -P "${${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR}/runTest.cmake" + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (f_extest_h4ex_VG_add_sds_to_vgroup PROPERTIES DEPENDS ${last_test} LABELS EXAMPLES) + else () + set_tests_properties (f_extest_h4ex_VG_add_sds_to_vgroup PROPERTIES LABELS EXAMPLES) + endif () + set (last_test "f_extest_h4ex_VG_add_sds_to_vgroup") +endif () + +foreach (example ${skip_examples}) + get_filename_component(example_name ${example} NAME_WE) + add_executable (f_ex_${example_name} ${PROJECT_SOURCE_DIR}/${example}) + set_target_properties (f_ex_${example_name} PROPERTIES LINKER_LANGUAGE Fortran) + target_link_libraries (f_ex_${example_name} ${H4EX_HDF4_LINK_LIBS}) + if (BUILD_TESTING) + add_test ( + NAME f_extest_${example_name} + COMMAND ${CMAKE_COMMAND} -E echo "SKIP f_extest_${example_name}" + ) + endif () +endforeach () diff --git a/HDF4Examples/hdf/fortran/Fortran_sourcefiles.cmake b/HDF4Examples/hdf/fortran/Fortran_sourcefiles.cmake new file mode 100644 index 0000000000..ed2db18ba5 --- /dev/null +++ b/HDF4Examples/hdf/fortran/Fortran_sourcefiles.cmake @@ -0,0 +1,37 @@ +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +set (examples + h4ex_VD_create_vdatas.f + h4ex_VD_write_mixed_vdata.f + h4ex_VD_write_to_vdata.f + h4ex_VD_create_onefield_vdatas.f + h4ex_VD_read_from_vdata.f + h4ex_VD_read_mixed_vdata.f + h4ex_VD_get_vdata_info.f + h4ex_VD_locate_vdata.f + h4ex_VG_create_vgroup.f +# h4ex_VG_add_sds_to_vgroup.f + h4ex_VG_insert_vdatas_to_vgroup.f + h4ex_VG_set_get_vgroup_attr.f + h4ex_VG_vgroup_contents.f + h4ex_VG_get_vgroup_info.f + h4ex_GR_create_and_write_image.f + h4ex_GR_create_and_write_chunked_image.f + h4ex_GR_modify_image.f + h4ex_GR_set_attribute.f + h4ex_GR_get_attribute.f + h4ex_GR_write_palette.f + h4ex_GR_image_info.f + h4ex_GR_read_image.f + h4ex_AN_create_annotation.f + h4ex_AN_get_annotation_info.f + h4ex_AN_read_annotation.f + #h4ex_VD_set_get_vdata_attr.f +) +set (mf_examples + h4ex_VG_add_sds_to_vgroup.f +) +set (skip_examples + h4ex_VD_set_get_vdata_attr.f +) diff --git a/HDF4Examples/hdf/fortran/Makefile.am b/HDF4Examples/hdf/fortran/Makefile.am new file mode 100644 index 0000000000..e7e69bd1a9 --- /dev/null +++ b/HDF4Examples/hdf/fortran/Makefile.am @@ -0,0 +1,82 @@ +############################################################################# +## Setup for building programs ## +############################################################################# + +include $(top_srcdir)/config/commence.am + +DEFINES=-DNDEBUG -DHDF + +############################################################################# +## Programs to build ## +############################################################################# + +TEST_PROG = h4ex_VD_create_vdatas h4ex_VD_write_mixed_vdata \ + h4ex_VD_write_to_vdata h4ex_VD_create_onefield_vdatas \ + h4ex_VD_read_from_vdata h4ex_VD_read_mixed_vdata \ + h4ex_VD_get_vdata_info h4ex_VD_locate_vdata h4ex_VG_create_vgroup \ + h4ex_VG_add_sds_to_vgroup h4ex_VG_insert_vdatas_to_vgroup \ + h4ex_VG_set_get_vgroup_attr h4ex_VG_vgroup_contents \ + h4ex_VG_get_vgroup_info h4ex_GR_create_and_write_image \ + h4ex_GR_modify_image h4ex_GR_set_attribute h4ex_GR_get_attribute \ + h4ex_GR_write_palette h4ex_GR_image_info h4ex_GR_read_image \ + h4ex_AN_create_annotation h4ex_AN_get_annotation_info h4ex_AN_read_annotation + # h4ex_VD_set_get_vdata_attr + +# These are the Fortran example files to be installed +INSTALL_FILES= h4ex_VD_read_from_vdata.f h4ex_VD_read_mixed_vdata.f \ + h4ex_VD_write_mixed_vdata.f h4ex_VD_write_to_vdata.f \ + h4ex_VD_create_onefield_vdatas.f h4ex_VD_create_vdatas.f \ + h4ex_VD_get_vdata_info.f h4ex_VD_locate_vdata.f \ + h4ex_VG_insert_vdatas_to_vgroup.f h4ex_VG_set_get_vgroup_attr.f \ + h4ex_VG_vgroup_contents.f h4ex_VG_add_sds_to_vgroup.f \ + h4ex_VG_create_vgroup.f h4ex_VG_get_vgroup_info.f \ + h4ex_GR_create_and_write_image.f h4ex_GR_get_attribute.f \ + h4ex_GR_image_info.f h4ex_GR_modify_image.f h4ex_GR_read_image.f \ + h4ex_GR_read_palette.f h4ex_GR_set_attribute.f \ + h4ex_GR_write_palette.f h4ex_AN_create_annotation.f \ + h4ex_AN_get_annotation_info.f h4ex_AN_read_annotation.f \ + #h4ex_VD_set_get_vdata_attr.f + +# Where to install Fortran example files +EXAMPLEDIR=$(prefix)/examples/fortran + +# How to build Fortran programs using h4fc +$(EXTRA_PROG): $(H4FC) + $(H4FC) $(H4FCFLAGS) $(FFLAGS) -o $@ $(srcdir)/$@.f; + +# List dependencies for each program. Normally, automake would take +# care of this for us, but if we tell automake about the programs it +# will try to build them with the normal Fortran compiler, not h4fc. + +# Fortran Programs +h4ex_VD_read_from_vdata: $(srcdir)/h4ex_VD_read_from_vdata.f +h4ex_VD_read_mixed_vdata: $(srcdir)/h4ex_VD_read_mixed_vdata.f +#h4ex_VD_set_get_vdata_attr: $(srcdir)/h4ex_VD_set_get_vdata_attr.f +h4ex_VD_write_mixed_vdata: $(srcdir)/h4ex_VD_write_mixed_vdata.f +h4ex_VD_write_to_vdata: $(srcdir)/h4ex_VD_write_to_vdata.f +h4ex_VD_create_onefield_vdatas: $(srcdir)/h4ex_VD_create_onefield_vdatas.f +h4ex_VD_create_vdatas: $(srcdir)/h4ex_VD_create_vdatas.f +h4ex_VD_get_vdata_info: $(srcdir)/h4ex_VD_get_vdata_info.f +h4ex_VD_locate_vdata: $(srcdir)/h4ex_VD_locate_vdata.f +h4ex_VG_insert_vdatas_to_vgroup: $(srcdir)/h4ex_VG_insert_vdatas_to_vgroup.f +h4ex_VG_set_get_vgroup_attr: $(srcdir)/h4ex_VG_set_get_vgroup_attr.f +h4ex_VG_vgroup_contents: $(srcdir)/h4ex_VG_vgroup_contents.f +h4ex_VG_add_sds_to_vgroup: $(srcdir)/h4ex_VG_add_sds_to_vgroup.f +h4ex_VG_create_vgroup: $(srcdir)/h4ex_VG_create_vgroup.f +h4ex_VG_get_vgroup_info: $(srcdir)/h4ex_VG_get_vgroup_info.f +h4ex_GR_create_and_write_image: $(srcdir)/h4ex_GR_create_and_write_image.f +h4ex_GR_get_attribute: $(srcdir)/h4ex_GR_get_attribute.f +h4ex_GR_image_info: $(srcdir)/h4ex_GR_image_info.f +h4ex_GR_modify_image: $(srcdir)/h4ex_GR_modify_image.f +h4ex_GR_read_image: $(srcdir)/h4ex_GR_read_image.f +h4ex_GR_read_palette: $(srcdir)/h4ex_GR_read_palette.f +h4ex_GR_set_attribute: $(srcdir)/h4ex_GR_set_attribute.f +h4ex_GR_write_palette: $(srcdir)/h4ex_GR_write_palette.f +h4ex_AN_create_annotation: $(srcdir)/h4ex_AN_create_annotation.f +h4ex_AN_get_annotation_info: $(srcdir)/h4ex_AN_get_annotation_info.f +h4ex_AN_read_annotation: $(srcdir)/h4ex_AN_read_annotation.f + +include $(top_srcdir)/config/examples.am +include $(top_srcdir)/config/conclude.am + +DISTCLEANFILES = *.chkexe *.chklog diff --git a/HDF4Examples/hdf/fortran/h4ex_AN_create_annotation.f b/HDF4Examples/hdf/fortran/h4ex_AN_create_annotation.f new file mode 100644 index 0000000000..16cce27033 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_AN_create_annotation.f @@ -0,0 +1,125 @@ + program create_annotation + implicit none +C +C Parameter declaration +C + character*22 FILE_NAME + character*9 VG_NAME + character*19 FILE_LABEL_TXT + character*53 FILE_DESC_TXT + character*16 DATA_LABEL_TXT + character*54 DATA_DESC_TXT +C + parameter (FILE_NAME = 'General_HDFobjects.hdf', + + VG_NAME = 'AN Vgroup', + + FILE_LABEL_TXT = 'General HDF objects', + + DATA_LABEL_TXT = 'Common AN Vgroup', + + FILE_DESC_TXT = + + 'This is an HDF file that contains general HDF objects', + + DATA_DESC_TXT = + + 'This is a vgroup that is used to test data annotations') + integer DFACC_CREATE + parameter (DFACC_CREATE = 4) + integer AN_FILE_LABEL, AN_FILE_DESC, AN_DATA_LABEL, AN_DATA_DESC + parameter (AN_FILE_LABEL = 2, + + AN_FILE_DESC = 3, + + AN_DATA_LABEL = 0, + + AN_DATA_DESC = 1) +C +C Function declaration +C + integer hopen, hclose + integer afstart, affcreate, afwriteann, afcreate, + + afendaccess, afend + integer vfstart, vfatch, vfsnam, vqref, vqtag, vfdtch, vfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id, an_id + integer file_label_id, file_desc_id + integer data_label_id, data_desc_id + integer vgroup_id, vgroup_tag, vgroup_ref +C +C**** End of variable declaration ************************************ +C +C +C Create the HDF file. +C + file_id = hopen(FILE_NAME, DFACC_CREATE, 0) +C +C Initialize the AN interface. +C + an_id = afstart(file_id) +C +C Create the file label. +C + file_label_id = affcreate(an_id, AN_FILE_LABEL) +C +C Write the annotation to the file label. +C + status = afwriteann(file_label_id, FILE_LABEL_TXT, + + len(FILE_LABEL_TXT)) +C +C Create file description. +C + file_desc_id = affcreate(an_id, AN_FILE_DESC) +C +C Write the annotation to the file description. +C + status = afwriteann(file_desc_id, FILE_DESC_TXT, + + len(FILE_DESC_TXT)) +C +C Create a vgroup in the file. Note that the vgroup's ref number is +C set to -1 for creating and the access mode is 'w' for writing. +C + status = vfstart(file_id) + vgroup_id = vfatch(file_id, -1, 'w') + status = vfsnam(vgroup_id, VG_NAME) +C +C Obtain the tag and reference number of the vgroup for subsequent +C references. +C + vgroup_ref = vqref(vgroup_id) + vgroup_tag = vqtag(vgroup_id) +C +C Create the data label for the vgroup identified by its tag and ref +C number. +C + data_label_id = afcreate(an_id, vgroup_tag, vgroup_ref, + + AN_DATA_LABEL) +C +C Write the annotation text to the data label. +C + status = afwriteann(data_label_id, DATA_LABEL_TXT, + + len(DATA_LABEL_TXT)) + +C +C Create the data description for the vgroup identified by its tag and ref. +C + data_desc_id = afcreate(an_id, vgroup_tag, vgroup_ref, + + AN_DATA_DESC) +C +C Write the annotation text to the data description. +C + status = afwriteann(data_desc_id, DATA_DESC_TXT, + + len(DATA_DESC_TXT)) +C +C Terminate access to the vgroup and to the V interface. +C + status = vfdtch(vgroup_id) + status = vfend(file_id) +C +C Terminate access to each annotation explicitly. +C + status = afendaccess(file_label_id) + status = afendaccess(file_desc_id) + status = afendaccess(data_label_id) + status = afendaccess(data_desc_id) +C +C Terminate access to the AN interface and close the HDF file. +C + status = afend(an_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_AN_get_annotation_info.f b/HDF4Examples/hdf/fortran/h4ex_AN_get_annotation_info.f new file mode 100644 index 0000000000..ea72148f44 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_AN_get_annotation_info.f @@ -0,0 +1,121 @@ + program annotation_info + implicit none +C +C Parameter declaration +C + character*22 FILE_NAME + character*9 VG_NAME +C + parameter (FILE_NAME = 'General_HDFobjects.hdf', + + VG_NAME = 'AN Vgroup') + integer DFACC_READ + parameter (DFACC_READ = 1) + integer AN_FILE_LABEL, AN_DATA_LABEL, AN_DATA_DESC + parameter (AN_FILE_LABEL = 2, + + AN_DATA_LABEL = 0, + + AN_DATA_DESC = 1) + integer DFTAG_DIA, DFTAG_FID, DFTAG_DIL + parameter (DFTAG_DIA = 105, + + DFTAG_FID = 100, + + DFTAG_DIL = 104) + integer DFTAG_VG + parameter (DFTAG_VG = 1965) +C +C Function declaration +C + integer hopen, hclose + integer afstart, afnumann, afannlist, afidtagref, aftagatype, + + afatypetag, afend + integer vfstart, vfind + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id, an_id + integer n_annots, ann_index, annot_type, ann_tag, ann_ref + integer ann_list(10) + integer vgroup_tag, vgroup_ref +C +C**** End of variable declaration ************************************ +C + annot_type = AN_DATA_DESC + vgroup_tag = DFTAG_VG +C +C Open the HDF file for reading. +C + file_id = hopen(FILE_NAME, DFACC_READ, 0) +C +C Initialize the V interface. +C + status = vfstart(file_id) +C +C Get the group named VG_NAME. +C + vgroup_ref = vfind(file_id, VG_NAME) +C +C Initialize the AN interface. +C + an_id = afstart(file_id) + +C +C Get the number of object descriptions. +C + if (vgroup_ref .eq. -1) goto 100 + n_annots = afnumann(an_id, annot_type, vgroup_tag, vgroup_ref) +C +C Get the list of identifiers of the annotations attached to the +C vgroup and of type annot_type. Identifiers are read into ann_list +C buffer. One has to make sure that ann_list has the size big enough +C to hold the list of identifiers. +C + n_annots = afannlist(an_id, annot_type, vgroup_tag, vgroup_ref, + + ann_list) +C +C Get each annotation identifier from the list then display the +C tag/ref number pair of the corresponding annotation. +C + write(*,*) 'List of annotations of type AN_DATA_DESC' + do 10 ann_index = 0, n_annots - 1 +C +C Get and display the ref number of the annotation from its +C identifier. +C + status = afidtagref(ann_list(ann_index+1), ann_tag, ann_ref) + write(*,*) 'Annotation index: ', ann_index + if (ann_tag .eq. DFTAG_DIA) then + write(*,*) 'tag = DFTAG_DIA (data description)' + else + write(*,*) ' tag = Incorrect' + endif + write(*,*) 'reference number = ', ann_ref +10 continue +C +C Get and display an annotation type from an annotation tag. +C + annot_type = aftagatype(DFTAG_FID) + if (annot_type .eq. AN_FILE_LABEL) then + write(*,*) 'Annotation type of DFTAG_FID (file label) is ', + + 'AN_FILE_LABEL ' + else + write(*,*) 'Annotation type of DFTAG_FID (file label) is ', + + 'Incorrect' + endif +C +C Get and display an annotation tag from an annotation type. +C + ann_tag = afatypetag(AN_DATA_LABEL) + if (ann_tag .eq. DFTAG_DIL ) then + write(*,*) 'Annotation tag of AN_DATA_LABEL is ', + + 'DFTAG_DIL (data label)' + else + write(*,*) 'Annotation type of DFTAG_FID (file label) is ', + + 'Incorrect' + endif +C +C Terminate access to the AN interface and close the HDF file. +C +100 continue + status = afend(an_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_AN_read_annotation.f b/HDF4Examples/hdf/fortran/h4ex_AN_read_annotation.f new file mode 100644 index 0000000000..6f4f49fa50 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_AN_read_annotation.f @@ -0,0 +1,82 @@ + program read_annotation + implicit none +C +C Parameter declaration +C + character*22 FILE_NAME +C + parameter (FILE_NAME = 'General_HDFobjects.hdf') + integer DFACC_READ + parameter (DFACC_READ = 1) + integer AN_DATA_LABEL + parameter (AN_DATA_LABEL = 0) +C +C Function declaration +C + integer hopen, hclose + integer afstart, affileinfo, afselect, afannlen, afreadann, + + afendaccess, afend +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id, an_id, ann_id + integer index, ann_length + integer n_file_labels, n_file_descs, n_data_labels, n_data_descs + character*256 ann_buf +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for reading. +C + file_id = hopen(FILE_NAME, DFACC_READ, 0) +C +C Initialize the AN interface. +C + an_id = afstart(file_id) +C +C Get the annotation information, i.e., the number of file labels, +C file descriptions, data labels, and data descriptions. +C + status = affileinfo(an_id, n_file_labels, n_file_descs, + + n_data_labels, n_data_descs) +C +C Get the data labels. Note that this DO loop can be used to obtain +C the contents of each kind of annotation with the appropriate number +C of annotations and the type of annotation, i.e., replace +C n_data_labels with n_file_labels, n_files_descs, or n_data_descs, and +C AN_DATA_LABEL with AN_FILE_LABEL, AN_FILE_DESC, or AN_DATA_DESC, +C respectively. +C + do 10 index = 0, n_data_labels-1 +C +C Get the identifier of the current data label. +C + ann_id = afselect(an_id, index, AN_DATA_LABEL) +C +C Get the length of the data label. +C + ann_length = afannlen(ann_id) +C +C Read and display the data label. The data label is read into buffer +C ann_buf. One has to make sure that ann_buf has sufficient size to hold +C the data label. Also note, that the third argument to afreadann is +C 1 greater that the actual length of the data label (see comment to +C C example). +C + status = afreadann(ann_id, ann_buf, ann_length+1) + write(*,*) 'Data label index: ', index + write(*,*) 'Data label contents: ', ann_buf(1:ann_length) +10 continue +C +C Terminate access to the current data label. +C + status = afendaccess(ann_id) +C +C Terminate access to the AN interface and close the HDF file. +C + status = afend(an_id) + status = hclose(file_id) + end + diff --git a/HDF4Examples/hdf/fortran/h4ex_GR_create_and_write_chunked_image.f b/HDF4Examples/hdf/fortran/h4ex_GR_create_and_write_chunked_image.f new file mode 100644 index 0000000000..34301dba46 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_GR_create_and_write_chunked_image.f @@ -0,0 +1,127 @@ + program gr_chunking_example + implicit none +C +C Parameter declaraction +C + character*14 FILE_NAME + character*14 DATASET_NAME + parameter (FILE_NAME = 'gr_chunked.hdf', + . DATASET_NAME = 'gzip_comp_data') + integer NCOMP, MFGR_INTERLACE_PIXEL + parameter(NCOMP = 3, MFGR_INTERLACE_PIXEL = 0) + integer DFACC_CREATE, DFACC_READ, DFACC_WRITE + parameter (DFACC_CREATE = 4, + . DFACC_READ = 1, + . DFACC_WRITE = 2) + integer DFNT_INT32 + parameter (DFNT_INT32 = 24) + integer X_LENGTH, Y_LENGTH, X_CH_LENGTH, Y_CH_LENGTH + parameter (X_LENGTH = 6, + . Y_LENGTH = 10, + . X_CH_LENGTH = 3, + . Y_CH_LENGTH = 2) +C +C Compression parameters. +C + integer COMP_CODE_DEFLATE, DEFLATE_LEVEL + parameter( COMP_CODE_DEFLATE = 4, DEFLATE_LEVEL = 6) +C +C Function declaration. +C + integer mgstart, mgcreat, mgendac, mgend + integer mgwchnk, mgschnk + integer hopen, hclose +C +C**** Variable declaration ************************************************* +C + integer ri_id, gr_id, file_id + integer dims(2), start(2) + integer status, il + integer comp_prm(1), comp_type +C +C Data buffers. +C + integer*4 chunk11(NCOMP* X_CH_LENGTH*Y_CH_LENGTH) + integer*4 chunk21(NCOMP* X_CH_LENGTH*Y_CH_LENGTH) + integer*4 chunk52(NCOMP* X_CH_LENGTH*Y_CH_LENGTH) +C +C Chunking dimension arrays +C + integer ch_dims(2) +C +C**** End of variable declaration ****************************************** +C +C +C Data initialization +C + data chunk11 / 110, 111, 112, 120, 121, 122, + . 130, 131, 132, 140, 141, 142, + . 150, 151, 152, 160, 161, 162 + . /, + . chunk21 / + . 210, 211, 212, 220, 221, 222, + . 230, 231, 232, 240, 241, 242, + . 250, 251, 252, 260, 261, 262 + . /, + . chunk52 / + . 1010, 1011, 1012, 1020, 1021, 1022, + . 1030, 1031, 1032, 1040, 1041, 1042, + . 1050, 1051, 1052, 1060, 1061, 1062 + . / +C +C Define chunk dimensions. +C + ch_dims(1) = Y_CH_LENGTH + ch_dims(2) = X_CH_LENGTH +C +C Create and open the file and initiate GR interface.. +C + file_id = hopen(FILE_NAME, DFACC_CREATE, 0) + gr_id = mgstart(file_id) +C +C Define the number of components and dimensions of the image. +C + il = MFGR_INTERLACE_PIXEL + dims(1) = X_LENGTH + dims(2) = Y_LENGTH +C +C Create GR dataset. +C + ri_id = mgcreat(gr_id, DATASET_NAME, NCOMP, DFNT_INT32, il, dims) +C +C Define chunked GR dataset using GZIP compression. +C + comp_prm(1) = DEFLATE_LEVEL + comp_type = COMP_CODE_DEFLATE + status = mgschnk (ri_id, ch_dims, comp_type, comp_prm) +C +C Define the location of the first chunk and write the data. +C + start(1) = 1 + start(2) = 1 + status = mgwchnk(ri_id, start, chunk11) +C +C Define the location of the second chunk and write the data. +C + start(1) = 2 + start(2) = 1 + status = mgwchnk(ri_id, start, chunk21) +C +C Define the location of the third and write the data. +C + start(1) = 5 + start(2) = 2 + status = mgwchnk(ri_id, start, chunk52) +C +C Terminate access to the array. +C + status = mgendac(ri_id) +C +C Terminate access to the GR interface. +C + status = mgend(gr_id) +C +C Close the file. +C + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_GR_create_and_write_image.f b/HDF4Examples/hdf/fortran/h4ex_GR_create_and_write_image.f new file mode 100644 index 0000000000..9fed2dbbc8 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_GR_create_and_write_image.f @@ -0,0 +1,92 @@ + program create_raster_image + implicit none +C +C Parameter declaration +C + character*19 FILE_NAME + character*13 IMAGE_NAME + integer X_LENGTH + integer Y_LENGTH + integer N_COMPS +C + parameter (FILE_NAME = 'General_RImages.hdf', + + IMAGE_NAME = 'Image Array 1', + + X_LENGTH = 10, + + Y_LENGTH = 5, + + N_COMPS = 2) + integer DFACC_CREATE, DFNT_INT16, MFGR_INTERLACE_PIXEL + parameter (DFACC_CREATE = 4, + + DFNT_INT16 = 22, + + MFGR_INTERLACE_PIXEL = 0) +C +C Function declaration +C + integer hopen, hclose + integer mgstart, mgcreat, mgwrimg, mgendac, mgend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id + integer gr_id, ri_id, num_type, interlace_mode + integer start(2), stride(2), edges(2), dimsizes(2) + integer i, j, k + integer*2 image_buf(N_COMPS, X_LENGTH, Y_LENGTH) +C +C**** End of variable declaration ************************************ +C +C +C Create and open the file. +C + file_id = hopen(FILE_NAME, DFACC_CREATE, 0) +C +C Initialize the GR interface. +C + gr_id = mgstart(file_id) +C +C Set the number type, interlace mode, and dimensions of the image. +C + num_type = DFNT_INT16 + interlace_mode = MFGR_INTERLACE_PIXEL + dimsizes(1) = X_LENGTH + dimsizes(2) = Y_lENGTH +C +C Create the raster image array. +C + ri_id = mgcreat(gr_id, IMAGE_NAME, N_COMPS, num_type, + + interlace_mode, dimsizes) +C +C Fill the image data buffer with values. +C + do 30 i = 1, Y_LENGTH + do 20 j = 1, X_LENGTH + do 10 k = 1, N_COMPS + image_buf(k,j,i) = (i+j) - 1 +10 continue +20 continue +30 continue + +C +C Define the size of the data to be written, i.e., start from the origin +C and go as long as the length of each dimension. +C + start(1) = 0 + start(2) = 0 + edges(1) = X_LENGTH + edges(2) = Y_LENGTH + stride(1) = 1 + stride(2) = 1 +C +C Write the data in the buffer into the image array. +C + status = mgwrimg(ri_id, start, stride, edges, image_buf) + +C +C Terminate access to the raster image and to the GR interface, +C and close the HDF file. +C + status = mgendac(ri_id) + status = mgend(gr_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_GR_get_attribute.f b/HDF4Examples/hdf/fortran/h4ex_GR_get_attribute.f new file mode 100644 index 0000000000..061c52d120 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_GR_get_attribute.f @@ -0,0 +1,99 @@ + program get_attribute + implicit none +C +C Parameter declaration +C + character*19 FILE_NAME + character*17 RI_ATTR_NAME +C + parameter (FILE_NAME = 'General_RImages.hdf', + + RI_ATTR_NAME = 'Image Attribute 2') + integer DFACC_READ, DFNT_INT16, DFNT_CHAR8 + parameter (DFACC_READ = 1, + + DFNT_CHAR8 = 4, + + DFNT_INT16 = 22) +C +C Function declaration +C + integer hopen, hclose + integer mgstart, mgfinfo, mgatinf, mggcatt, mggnatt , mgfndat, + + mgselct, mgendac, mgend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id, gr_id, ri_id + integer f_att_index, ri_att_index, data_type, n_values + integer n_rimages, n_file_attrs + integer*2 int_buf(10) + character*17 attr_name + character*80 char_buf + integer i +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file. +C + file_id = hopen(FILE_NAME, DFACC_READ, 0) +C +C Initialize the GR interface. +C + gr_id = mgstart(file_id) +C +C Determine the number of attributes in the file. +C + status = mgfinfo(gr_id, n_rimages, n_file_attrs) + if ((status .NE. -1) .AND. (n_file_attrs .GT. 0)) then + + do 10 f_att_index = 0, n_file_attrs-1 +C +C Get information about the current file attribute. +C + status = mgatinf(gr_id, f_att_index, attr_name, data_type, + + n_values) +C +C Check whether data type is DFNT_CHAR8 in order to use allocated buffer. +C + if(data_type .NE. DFNT_CHAR8) then + write(*,*) + + 'Unable to determine data type to use allocated buffer' + else +C +C Read and display the attribute values. +C + status = mggcatt(gr_id, f_att_index, char_buf) + write(*,*) 'Attribute ', attr_name, ' : ', + + char_buf(1:n_values) + endif +10 continue + + endif + +C +C Select the second image in the file. +C + ri_id = mgselct(gr_id, 1) +C +C Find the image attribute named RI_ATTR_NAME. +C + ri_att_index = mgfndat(ri_id, RI_ATTR_NAME) +C +C Get information about the attribute. +C + status = mgatinf(ri_id, ri_att_index, attr_name, data_type, + + n_values) +C +C Read and display attribute values. +C + status = mggnatt(ri_id, ri_att_index, int_buf) + write(*,*) 'Attributes :', (int_buf(i), i = 1, n_values) +C +C Terminate access to the image and to the GR interface, +C and close the HDF file. +C + status = mgendac(ri_id) + status = mgend(gr_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_GR_image_info.f b/HDF4Examples/hdf/fortran/h4ex_GR_image_info.f new file mode 100644 index 0000000000..c0fb436db2 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_GR_image_info.f @@ -0,0 +1,90 @@ + program image_info + implicit none +C +C Parameter declaration +C + character*19 FILE_NAME +C + parameter (FILE_NAME = 'General_RImages.hdf') + integer DFACC_READ + parameter (DFACC_READ = 1) +C +C Function declaration +C + integer hopen, hclose + integer mgstart, mgselct, mgfinfo, mggiinf, mgendac, mgend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id, gr_id, ri_id + integer n_rimages, n_file_attrs, ri_index + integer n_comps, interlace_mode, n_attrs, data_type + integer dim_sizes(2) + character*10 type_string + character*24 interlace_string + character*64 name +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for reading. +C + file_id = hopen(FILE_NAME, DFACC_READ, 0) +C +C Initialize the GR interface. +C + gr_id = mgstart(file_id) +C +C Determine the contents of the file. +C + status = mgfinfo(gr_id, n_rimages, n_file_attrs) +C +C For each image in the file, get and display image information. +C + do 100 ri_index = 0, n_rimages-1 + ri_id = mgselct(gr_id, ri_index) + status = mggiinf(ri_id, name, n_comps, data_type, + + interlace_mode, dim_sizes, n_attrs) +C +C Map the number type and interlace mode into text strings for +C output readability. +C + if(data_type .eq. 4) then + type_string = 'DFNT_CHAR8' + else if(data_type .eq. 22) then + type_string = 'DFNT_INT16' + else + type_string = 'Unknown' + endif + if (interlace_mode .eq. 0) then + interlace_string = 'MFGR_INTERLACE_PIXEL' + else if(interlace_mode .eq. 1) then + interlace_string = 'MFGR_INTERLACE_LINE' + else if(interlace_mode .eq. 2) then + interlace_string = 'MFGR_INTERLACE_COMPONENT' + else + interlace_string = 'Unknown' + endif +C +C Display the image information for the current image. +C + write(*,*) 'Image index: ', ri_index + write(*,*) 'Image name: ', name + write(*,*) 'Number of components: ', n_comps + write(*,*) 'Number type: ', type_string + write(*,*) 'Interlace mode: ', interlace_string + write(*,*) 'Dimnesions: ', dim_sizes(1), dim_sizes(2) + write(*,*) 'Number of image attributes: ', n_attrs + write(*,*) +C +C Terminate access to the current raster image. +C + status = mgendac(ri_id) +100 continue +C +C Terminate access to the GR interface and close the HDF file. + status = mgend(gr_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_GR_modify_image.f b/HDF4Examples/hdf/fortran/h4ex_GR_modify_image.f new file mode 100644 index 0000000000..684b1c2d70 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_GR_modify_image.f @@ -0,0 +1,133 @@ + program modify_image + implicit none +C +C Parameter declaration +C + character*19 FILE_NAME + character*13 IMAGE1_NAME + integer X1_LENGTH + integer Y1_LENGTH + integer N1_COMPS + character*13 IMAGE2_NAME + integer X2_LENGTH + integer Y2_LENGTH + integer N2_COMPS +C + parameter (FILE_NAME = 'General_RImages.hdf', + + IMAGE1_NAME = 'Image Array 1', + + IMAGE2_NAME = 'Image Array 2', + + X1_LENGTH = 5, + + Y1_LENGTH = 2, + + N1_COMPS = 2, + + X2_LENGTH = 6, + + Y2_LENGTH = 4, + + N2_COMPS = 3) + integer DFACC_WRITE, DFNT_INT16, DFNT_CHAR8, + + MFGR_INTERLACE_PIXEL + parameter (DFACC_WRITE = 2, + + DFNT_CHAR8 = 4, + + DFNT_INT16 = 22, + + MFGR_INTERLACE_PIXEL = 0) +C +C Function declaration +C + integer hopen, hclose + integer mgstart, mgselct, mgcreat, mgwrimg, mgendac, mgend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id + integer gr_id, ri1_id, ri2_id, data_type, interlace_mode + integer start1(2), stride1(2), edges1(2) + integer start2(2), stride2(2), edges2(2), dim_sizes(2) + integer i, j, k + integer*2 image1_buf(N1_COMPS, X1_LENGTH, Y1_LENGTH) + character image2_buf(N2_COMPS, X2_LENGTH, Y2_LENGTH) +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for writing. +C + file_id = hopen(FILE_NAME, DFACC_WRITE, 0) +C +C Initialize the GR interface. +C + gr_id = mgstart(file_id) +C +C Select the first raster image in the file. +C + ri1_id = mgselct(gr_id, 0) +C +C Fill the buffer with values. +C + do 20 i = 1, Y1_LENGTH + do 10 j = 1, X1_LENGTH + image1_buf(1,j,i) = 0 + image1_buf(2,j,i) = 0 +10 continue +20 continue +C +C Define the part of the data in the first image that will be overwritten +C with the new values from image1_buf. +C + start1(1) = 0 + start1(2) = 0 + edges1(1) = X1_LENGTH + edges1(2) = Y1_LENGTH + stride1(1) = 1 + stride1(2) = 1 +C +C Write the data in the buffer into the image array. +C + status = mgwrimg(ri1_id, start1, stride1, edges1, image1_buf) + +C +C Set the number type, interlace mode, and dimensions of the second image. +C + data_type = DFNT_CHAR8 + interlace_mode = MFGR_INTERLACE_PIXEL + dim_sizes(1) = X2_LENGTH + dim_sizes(2) = Y2_LENGTH +C +C Create the second image in the file. +C + ri2_id = mgcreat(gr_id, IMAGE2_NAME, N2_COMPS, data_type, + + interlace_mode, dim_sizes) +C +C Fill the image data buffer with values. +C + do 60 i = 1, Y2_LENGTH + do 50 j = 1, X2_LENGTH + do 40 k = 1, N2_COMPS + image2_buf(k,j,i) = char(65 + k - 1) +40 continue +50 continue +60 continue + +C +C Define the size of the data to be written, i.e., start from the origin +C and go as long as the length of each dimension. +C + start2(1) = 0 + start2(2) = 0 + edges2(1) = dim_sizes(1) + edges2(2) = dim_sizes(2) + stride2(1) = 1 + stride2(2) = 1 +C +C Write the data in the buffer into the image array. +C + status = mgwrimg(ri2_id, start2, stride2, edges2, image2_buf) + +C +C Terminate access to the raster images and to the GR interface, +C and close the HDF file. +C + status = mgendac(ri1_id) + status = mgendac(ri2_id) + status = mgend(gr_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_GR_read_image.f b/HDF4Examples/hdf/fortran/h4ex_GR_read_image.f new file mode 100644 index 0000000000..fccbfe52ad --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_GR_read_image.f @@ -0,0 +1,136 @@ + program read_raster_image + implicit none +C +C Parameter declaration +C + character*19 FILE_NAME + integer X_LENGTH + integer Y_LENGTH + integer N_COMPS +C + parameter (FILE_NAME = 'General_RImages.hdf', + + X_LENGTH = 10, + + Y_LENGTH = 5, + + N_COMPS = 2) + integer PART_COLS, PART_ROWS, SKIP_COLS, SKIP_ROWS + integer COLS_PART_START, ROWS_PART_START + integer COLS_SKIP_START, ROWS_SKIP_START + integer N_STRIDES + parameter (PART_COLS = 3, PART_ROWS = 2, + + SKIP_COLS = 3, SKIP_ROWS = 5, + + COLS_PART_START = 1, ROWS_PART_START = 3, + + COLS_SKIP_START = 0, ROWS_SKIP_START = 1, + + N_STRIDES = 2) + integer DFACC_READ + parameter (DFACC_READ = 1) +C +C Function declaration +C + integer hopen, hclose + integer mgstart, mgselct, mgrdimg, mgendac, mgend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id + integer gr_id, ri_id + integer start(2), stride(2), edges(2) + integer i, j + integer*2 entire_image(N_COMPS, X_LENGTH, Y_LENGTH) + integer*2 partial_image(N_COMPS, PART_ROWS, PART_COLS) + integer*2 skipped_image(N_COMPS, SKIP_ROWS, SKIP_COLS) +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for reading. +C + file_id = hopen(FILE_NAME, DFACC_READ, 0) +C +C Initialize the GR interface. +C + gr_id = mgstart(file_id) +C +C Select the first raster image in the file. +C + ri_id = mgselct(gr_id, 0) +C +C Define the size of the data to be read, i.e., start from the origin +C and go as long as the length of each dimension. +C + start(1) = 0 + start(2) = 0 + edges(1) = X_LENGTH + edges(2) = Y_LENGTH + stride(1) = 1 + stride(2) = 1 +C +C Read the data from the raster image array. +C + status = mgrdimg(ri_id, start, stride, edges, entire_image) +C +C Display only the first component of the image since the two components +C have the same data in this example. +C + write(*,*) 'First component of the entire image' + write(*,*) + do 10 i = 1, X_LENGTH + write(*,1000) (entire_image(1,i,j), j = 1, Y_LENGTH) +10 continue + write(*,*) +C +C Define the size of the data to be read. +C + start(1) = ROWS_PART_START + start(2) = COLS_PART_START + edges(1) = PART_ROWS + edges(2) = PART_COLS + stride(1) = 1 + stride(2) = 1 +C +C Read a subset of the raster image array. +C + status = mgrdimg(ri_id, start, stride, edges, partial_image) +C +C Display only the first component of the read sample. +C + write(*,*) + + 'Two rows and three columns at 4th row and 2nd column', + + ' of the first component' + write(*,*) + do 20 i = 1, PART_ROWS + write(*,1000) (partial_image(1,i,j), j = 1, PART_COLS) +20 continue + write(*,*) +C +C Define the size and the pattern to read the data. +C + start(1) = ROWS_SKIP_START + start(2) = COLS_SKIP_START + edges(1) = SKIP_ROWS + edges(2) = SKIP_COLS + stride(1) = N_STRIDES + stride(2) = N_STRIDES +C +C Read all the odd rows and even columns of the image. +C + status = mgrdimg(ri_id, start, stride, edges, skipped_image) +C +C Display only the first component of the read sample. +C + write(*,*) 'All even rows and odd columns of the first component' + write(*,*) + do 30 i = 1, SKIP_ROWS + write(*,1000) (skipped_image(1,i,j), j = 1, SKIP_COLS) +30 continue + write(*,*) +C +C Terminate access to the raster image and to the GR interface, +C and close the HDF file. +C + status = mgendac(ri_id) + status = mgend(gr_id) + status = hclose(file_id) +1000 format(1x, 5(I4)) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_GR_read_palette.f b/HDF4Examples/hdf/fortran/h4ex_GR_read_palette.f new file mode 100644 index 0000000000..0120480959 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_GR_read_palette.f @@ -0,0 +1,84 @@ + program read_palette + implicit none +C +C Parameter declaration +C + character*22 FILE_NAME + character*18 IMAGE_NAME + integer N_ENTRIES + integer N_COMPS_PAL +C + parameter (FILE_NAME = 'Image_with_Palette.hdf', + + IMAGE_NAME = 'Image with Palette', + + N_COMPS_PAL = 3, + + N_ENTRIES = 256) + integer DFACC_READ, DFNT_CHAR8, DFNT_UINT8, MFGR_INTERLACE_PIXEL + parameter (DFACC_READ = 1, + + DFNT_CHAR8 = 4, + + DFNT_UINT8 = 21, + + MFGR_INTERLACE_PIXEL = 0) +C +C Function declaration +C + integer hopen, hclose + integer mgstart, mgn2ndx, mgselct, mggltid, mgglinf, + + mgrclut, mgendac, mgend +C +C**** Variable declaration ******************************************* +C + integer file_id, gr_id, ri_id, ri_index, pal_id, pal_index + integer interlace_mode + integer data_type, n_comps, n_entries_out + integer status + integer i, j + character palette_data(N_COMPS_PAL, N_ENTRIES) +C +C**** End of variable declaration ************************************ +C +C +C Open the file. +C + file_id = hopen(FILE_NAME, DFACC_READ, 0) +C +C Initialize the GR interface. +C + gr_id = mgstart(file_id) +C +C Get the index of the image IMAGE_NAME. +C + ri_index = mgn2ndx(gr_id, IMAGE_NAME) +C +C Get the image identifier. +C + ri_id = mgselct(gr_id, 0) +C +C Get the identifier of the palette attached to the image. +C + pal_index = 0 + pal_id = mggltid(ri_id, pal_index) +C +C Obtain information about the palette. +C + status = mgglinf(pal_id, n_comps, data_type, interlace_mode, + + n_entries_out) + write(*,*) ' Palette: ', n_comps, ' components; ', + + n_entries_out, ' entries' +C +C Read the palette. +C + status = mgrclut(pal_id, palette_data) +C +C Display the palette data. +C + write(*,*) "Palette data" + do 10 i = 1, n_entries_out + write(*,*) (ichar(palette_data(j,i)), j = 1, n_comps) +10 continue +C +C Terminate access to the raster image and to the GR interface, +C and close the HDF file. +C + status = mgendac(ri_id) + status = mgend(gr_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_GR_set_attribute.f b/HDF4Examples/hdf/fortran/h4ex_GR_set_attribute.f new file mode 100644 index 0000000000..d8e6387fcf --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_GR_set_attribute.f @@ -0,0 +1,97 @@ + program set_attribute + implicit none +C +C Parameter declaration +C + character*19 FILE_NAME + character*13 IMAGE_NAME + character*16 F_ATT1_NAME + character*16 F_ATT2_NAME + character*17 RI_ATT1_NAME + character*17 RI_ATT2_NAME + character*32 F_ATT1_VAL + character*33 F_ATT2_VAL + integer F_ATT1_N_VALUES + integer F_ATT2_N_VALUES + character*35 RI_ATT1_VAL + integer RI_ATT1_N_VALUES + integer RI_ATT2_N_VALUES +C + parameter (FILE_NAME = 'General_RImages.hdf', + + IMAGE_NAME = 'Image Array 2', + + F_ATT1_NAME = 'File Attribute 1', + + F_ATT2_NAME = 'File Attribute 2', + + RI_ATT1_NAME = 'Image Attribute 1', + + RI_ATT2_NAME = 'Image Attribute 2', + + F_ATT1_VAL = 'Contents of First FILE Attribute', + + F_ATT2_VAL = 'Contents of Second FILE Attribute', + + F_ATT1_N_VALUES = 32, + + F_ATT2_N_VALUES = 33, + + RI_ATT1_VAL = 'Contents of IMAGE''s First Attribute', + + RI_ATT1_N_VALUES = 35, + + RI_ATT2_N_VALUES = 6) + integer DFACC_WRITE, DFNT_INT16, DFNT_CHAR8 + parameter (DFACC_WRITE = 2, + + DFNT_CHAR8 = 4, + + DFNT_INT16 = 22) +C +C Function declaration +C + integer hopen, hclose + integer mgstart, mgscatt, mgsnatt , mgn2ndx, + + mgselct, mgendac, mgend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id, gr_id, ri_id, ri_index + integer*2 ri_attr_2(RI_ATT2_N_VALUES) + integer i + + do 10 i = 1, RI_ATT2_N_VALUES + ri_attr_2(i) = i +10 continue +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file. +C + file_id = hopen(FILE_NAME, DFACC_WRITE, 0) +C +C Initialize the GR interface. +C + gr_id = mgstart(file_id) +C +C Set two file attributes to the file with names, data type, numbers of +C values, and values of attributes specified. +C + status = mgscatt(gr_id, F_ATT1_NAME, DFNT_CHAR8, + + F_ATT1_N_VALUES, F_ATT1_VAL) + status = mgscatt(gr_id, F_ATT2_NAME, DFNT_CHAR8, + + F_ATT2_N_VALUES, F_ATT2_VAL) +C +C Obtain the index of the image named IMAGE_NAMR. +C + ri_index = mgn2ndx(gr_id, IMAGE_NAME) +C +C Obtain the identifier of this image. +C + ri_id = mgselct(gr_id, ri_index) +C +C Set two attributes of the image with names, data types, number of +C values, and values of the attributes specified. +C + status = mgscatt(ri_id, RI_ATT1_NAME, DFNT_CHAR8, + + RI_ATT1_N_VALUES, RI_ATT1_VAL) + status = mgsnatt(ri_id, RI_ATT2_NAME, DFNT_INT16, + + RI_ATT2_N_VALUES, ri_attr_2) +C +C Terminate access to the image and to the GR interface, +C and close the HDF file. +C + status = mgendac(ri_id) + status = mgend(gr_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_GR_write_palette.f b/HDF4Examples/hdf/fortran/h4ex_GR_write_palette.f new file mode 100644 index 0000000000..a3e1e4bb0c --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_GR_write_palette.f @@ -0,0 +1,116 @@ + program write_palette + implicit none +C +C Parameter declaration +C + character*22 FILE_NAME + character*18 NEW_IMAGE_NAME + integer X_LENGTH + integer Y_LENGTH + integer N_ENTRIES + integer N_COMPS_IMG + integer N_COMPS_PAL +C + parameter (FILE_NAME = 'Image_with_Palette.hdf', + + NEW_IMAGE_NAME = 'Image with Palette', + + X_LENGTH = 5, + + Y_LENGTH = 5, + + N_ENTRIES = 256, + + N_COMPS_IMG = 2, + + N_COMPS_PAL = 3) + integer DFACC_CREATE, DFNT_CHAR8, DFNT_UINT8, MFGR_INTERLACE_PIXEL + parameter (DFACC_CREATE = 4, + + DFNT_CHAR8 = 4, + + DFNT_UINT8 = 21, + + MFGR_INTERLACE_PIXEL = 0) +C +C Function declaration +C + integer hopen, hclose + integer mgstart, mgcreat, mgwcimg, mggltid, mgwclut, + + mgendac, mgend +C +C**** Variable declaration ******************************************* +C + integer file_id, gr_id, ri_id, pal_id + integer interlace_mode + integer start(2), stride(2), edges(2), dim_sizes(2) + integer status + integer i, j + character image_buf(N_COMPS_IMG, X_LENGTH, Y_LENGTH) + character palette_buf(N_COMPS_PAL, N_ENTRIES) +C +C**** End of variable declaration ************************************ +C +C +C Create and open the file. +C + file_id = hopen(FILE_NAME, DFACC_CREATE, 0) +C +C Initialize the GR interface. +C + gr_id = mgstart(file_id) +C +C Define interlace mode and dimensions of the image. +C + interlace_mode = MFGR_INTERLACE_PIXEL + dim_sizes(1) = X_LENGTH + dim_sizes(2) = Y_lENGTH +C +C Create the raster image array. +C + ri_id = mgcreat(gr_id, NEW_IMAGE_NAME, N_COMPS_IMG, DFNT_CHAR8, + + interlace_mode, dim_sizes) +C +C Fill the image data buffer with values. +C + do 20 i = 1, Y_LENGTH + do 10 j = 1, X_LENGTH + image_buf(1,j,i) = char(i + j - 1 ) + image_buf(2,j,i) = char(i + j) +10 continue +20 continue + +C +C Define the size of the data to be written, i.e., start from the origin +C and go as long as the length of each dimension. +C + start(1) = 0 + start(2) = 0 + edges(1) = X_LENGTH + edges(2) = Y_LENGTH + stride(1) = 1 + stride(2) = 1 +C +C Write the data in the buffer into the image array. +C + status = mgwcimg(ri_id, start, stride, edges, image_buf) +C +C Initilaize the palette buffer to grayscale. +C + do 40 i = 1, N_ENTRIES + do 30 j = 1, N_COMPS_PAL + palette_buf(j,i) = char(i) +30 continue +40 continue +C +C Get the identifier of the palette attached to the image NEW_IMAGE_NAME. +C + pal_id = mggltid(ri_id, 0) +C +C Set palette interlace mode. +C + interlace_mode = MFGR_INTERLACE_PIXEL +C +C Write data to the palette. +C + status = mgwclut(pal_id, N_COMPS_PAL, DFNT_UINT8, interlace_mode, + + N_ENTRIES, palette_buf) +C +C Terminate access to the raster image and to the GR interface, +C and close the HDF file. +C + status = mgendac(ri_id) + status = mgend(gr_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VD_create_onefield_vdatas.f b/HDF4Examples/hdf/fortran/h4ex_VD_create_onefield_vdatas.f new file mode 100644 index 0000000000..22e16e0be7 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VD_create_onefield_vdatas.f @@ -0,0 +1,79 @@ + program create_onefield_vdatas + implicit none +C +C Parameter declaration +C + character*18 FILE_NAME + character*9 CLASS1_NAME + character*9 CLASS2_NAME + character*11 VDATA1_NAME + character*12 VDATA2_NAME + character*22 FIELD1_NAME + character*21 FIELD2_NAME + integer N_RECORDS_1, N_RECORDS_2 + integer ORDER_2 +C + parameter (FILE_NAME = 'General_Vdatas.hdf', + + CLASS1_NAME = '5x1 Array', + + CLASS2_NAME = '6x4 Array', + + VDATA1_NAME = 'First Vdata', + + VDATA2_NAME = 'Second Vdata', + + FIELD1_NAME = 'Single-component Field', + + FIELD2_NAME = 'Multi-component Field') + parameter (N_RECORDS_1 = 5, + + N_RECORDS_2 = 6, + + ORDER_2 = 4) + + integer DFACC_WRITE, DFNT_CHAR8, DFNT_INT32 + parameter (DFACC_WRITE = 2, + + DFNT_CHAR8 = 4, + + DFNT_INT32 = 24) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vhfscd, vhfsdm, vfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id + integer vdata1_ref, vdata2_ref + character vdata1_buf(N_RECORDS_1) + integer vdata2_buf(ORDER_2, N_RECORDS_2) + data vdata1_buf /'V','D','A','T','A'/ + data vdata2_buf / 1, 2, 3, 4, + + 2, 4, 6, 8, + + 3, 6, 9, 12, + + 4, 8, 12, 16, + + 5, 10, 15, 20, + + 6, 12, 18, 24/ +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for writing. +C + file_id = hopen(FILE_NAME, DFACC_WRITE, 0) +C +C Initialize the VS interface. +C + status = vfstart(file_id) +C +C Create the first vdata and populate it with data from vdata1_buf array. +C + vdata1_ref = vhfscd(file_id, FIELD1_NAME, vdata1_buf, N_RECORDS_1, + + DFNT_CHAR8, VDATA1_NAME, CLASS1_NAME) +C +C Create the second vdata and populate it with data from vdata2_buf array. +C + vdata2_ref = vhfsdm(file_id, FIELD2_NAME, vdata2_buf, N_RECORDS_2, + + DFNT_INT32, VDATA2_NAME, CLASS2_NAME, + + ORDER_2) +C +C Terminate access to the VS interface and close the HDF file. +C + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VD_create_vdatas.f b/HDF4Examples/hdf/fortran/h4ex_VD_create_vdatas.f new file mode 100644 index 0000000000..c7894751d7 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VD_create_vdatas.f @@ -0,0 +1,106 @@ + program create_vdatas + implicit none +C +C Parameter declaration +C + character*18 FILE1_NAME + character*14 FILE2_NAME + character*7 VDATA_NAME + character*12 VDATA_CLASS +C + parameter (FILE1_NAME = 'General_Vdatas.hdf', + + FILE2_NAME = 'Two_Vdatas.hdf', + + VDATA_NAME = 'Vdata 1', + + VDATA_CLASS = 'Empty Vdatas') + integer DFACC_CREATE + parameter (DFACC_CREATE = 4) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vsfatch, vsfsnam, vsfscls, vsfdtch, vfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file1_id, file2_id + integer vdata_id, vdata1_id, vdata2_id + integer vdata_ref +C +C**** End of variable declaration ************************************ +C +C +C Create the first HDF file. +C + file1_id = hopen(FILE1_NAME, DFACC_CREATE, 0) +C +C Initialize the VS interface associated with the first HDF file. +C + status = vfstart(file1_id) +C +C Create a vdata in the first HDF file. +C + vdata_ref = -1 + vdata_id = vsfatch(file1_id, vdata_ref, 'w') +C +C Assign a name to the vdata. +C + status = vsfsnam(vdata_id, VDATA_NAME) +C +C Other operations on the vdata identified by vdata_id can be carried out +C starting from this point. +C +C Create the second HDF file. +C + file2_id = hopen(FILE2_NAME, DFACC_CREATE, 0) +C +C Initialize the VS interface associated with the second HDF file. +C + status = vfstart(file2_id) +C +C Create the first vdata in the second HDF file. +C + vdata1_id = vsfatch(file2_id, vdata_ref, 'w') +C +C Create the second vdata in the second HDF file. +C + vdata2_id = vsfatch(file2_id, vdata_ref, 'w') +C +C Assign a class name to these vdatas. +C + status = vsfscls(vdata1_id, VDATA_CLASS) + status = vsfscls(vdata2_id, VDATA_CLASS) +C +C Other operations on the vdatas identified by vdata1_id and vdata2_id +C can be carried out starting from this point. +C +C +C Terminate access to the first vdata in the second HDF file. +C + status = vsfdtch(vdata1_id) +C +C Terminate access to the second vdata in the second HDF file. +C + status = vsfdtch(vdata2_id) +C +C Terminate access to the VS interface associated with the second HDF file. +C + status = vfend(file2_id) +C +C Close the second HDF file. +C + status = hclose(file2_id) +C +C Terminate access to the vdata in the first HDF file. +C + status = vsfdtch(vdata_id) +C +C terminate access to the VS interface associated with the first HDF file. +C + status = vfend(file1_id) +C +C Close the first HDF file. +C + status = hclose(file1_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VD_get_vdata_info.f b/HDF4Examples/hdf/fortran/h4ex_VD_get_vdata_info.f new file mode 100644 index 0000000000..3f1e8ae9d0 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VD_get_vdata_info.f @@ -0,0 +1,88 @@ + program vdata_info + implicit none +C +C Parameter declaration +C + character*18 FILE_NAME + integer DFACC_READ, FULL_INTERLACE + integer FIELD_SIZE +C + parameter (FILE_NAME = 'General_Vdatas.hdf', + + DFACC_READ = 1, + + FULL_INTERLACE = 0, + + FIELD_SIZE = 80) + +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vsfatch, vsfgid, vsfinq, + + vsfisat, vsfdtch, vfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id, vdata_id, vdata_ref + integer n_records, interlace_mode, vdata_size + character*64 vdata_name + character*80 fieldname_list +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for reading. +C + file_id = hopen(FILE_NAME, DFACC_READ, 0) +C +C Initialize the VS interface. +C + status = vfstart(file_id) +C +C Set the reference number to -1 to start the search from the beginning +C of the file. +C + vdata_ref = -1 +10 continue +C +C Use vsfgid to obtain each vdata by its reference number then +C attach to the vdata and get information. The loop terminates +C when the last vdata is reached. +C + vdata_ref = vsfgid(file_id, vdata_ref) + if (vdata_ref .eq. -1) goto 100 +C +C Attach to the current vdata for reading. +C + vdata_id = vsfatch(file_id, vdata_ref, 'r') +C +C Test whether the current vdata is not a storage for an attribute, +C then obtain and display its information. + if (vsfisat(vdata_id) .ne. 1) then + status = vsfinq(vdata_id, n_records, interlace_mode, + + fieldname_list, vdata_size, vdata_name) + write(*,*) 'Vdata: ', vdata_name + write(*,*) 'contains ', n_records, ' records' + if (interlace_mode .eq. 0) then + write(*,*) 'Interlace mode: FULL' + else + write(*,*) 'Interlace mode: NONE' + endif + write(*,*) 'Fields: ', fieldname_list(1:30) + write(*,*) 'Vdata record size in bytes :', vdata_size + write(*,*) + endif +C +C Detach from the current vdata. +C + status = vsfdtch(vdata_id) + goto 10 +100 continue +C +C Terminate access to the vdata and to the VS interface, and +C close the HDF file. +C + status = vsfdtch(vdata_id) + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VD_locate_vdata.f b/HDF4Examples/hdf/fortran/h4ex_VD_locate_vdata.f new file mode 100644 index 0000000000..4861a641c6 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VD_locate_vdata.f @@ -0,0 +1,87 @@ + program locate_vdata + implicit none +C +C Parameter declaration +C + character*18 FILE_NAME + character*20 SEARCHED_FIELDS +C + parameter (FILE_NAME = 'General_Vdatas.hdf', + + SEARCHED_FIELDS = 'Position,Temperature') + integer DFACC_READ + parameter (DFACC_READ = 1) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vsfatch, vsfgid, vsfex, vsfdtch, vfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id, vdata_id, vdata_ref + integer index + logical found_fields +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for reading. +C + file_id = hopen(FILE_NAME, DFACC_READ, 0) +C +C Initialize the VS interface. +C + status = vfstart(file_id) + index = 0 +C +C Set the reference number to -1 to start the search from the beginning +C of the file. +C + vdata_ref = -1 +C +C Assume that the specified fields are not found in the current vdata. +C + found_fields = .FALSE. +10 continue +C +C Use vsfgid to obtain each vdata by its reference number then +C attach to the vdata and search for the fields. The loop terminates +C when the last vdata is reached or when a vdata which contains the +C fields listed in SEARCHED_FIELDS is found. +C + vdata_ref = vsfgid(file_id, vdata_ref) + if (vdata_ref .eq. -1) goto 100 + vdata_id = vsfatch(file_id, vdata_ref, 'r') + status = vsfex(vdata_id, SEARCHED_FIELDS) + if (status .ne. -1) then + found_fields = .TRUE. + goto 100 + endif + status = vsfdtch(vdata_id) + index = index + 1 + goto 10 +100 continue +C +C Print the index of the vdata containing the fields or a 'not found' +C message if no such vdata is found. Also detach from the vdata found. +C + if(.NOT.found_fields) then + write(*,*) 'Fields Positions and Temperature were not found' + else + write(*,*) + + 'Fields Positions and Temperature were found in the vdata', + + ' at position ', index +C +C Terminate access to the vdata +C + status = vsfdtch(vdata_id) + endif +C +C Terminate access to the VS interface and close the HDF file. +C + status = vsfdtch(vdata_id) + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VD_read_from_vdata.f b/HDF4Examples/hdf/fortran/h4ex_VD_read_from_vdata.f new file mode 100644 index 0000000000..17d6abac7c --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VD_read_from_vdata.f @@ -0,0 +1,93 @@ + program read_from_vdata + implicit none +C +C Parameter declaration +C + character*18 FILE_NAME + character*14 VDATA_NAME + character*20 FIELDNAME_LIST + integer N_RECORDS, RECORD_INDEX + integer ORDER_1, ORDER_2 + integer N_VALS_PER_REC +C + parameter (FILE_NAME = 'General_Vdatas.hdf', + + VDATA_NAME = 'Solid Particle', + + FIELDNAME_LIST = 'Position,Temperature') + parameter (N_RECORDS = 5, + + RECORD_INDEX = 3, + + ORDER_1 = 3, + + ORDER_2 = 2, + + N_VALS_PER_REC = ORDER_1 + ORDER_2 ) + + integer DFACC_READ, FULL_INTERLACE + parameter (DFACC_READ = 1, + + FULL_INTERLACE = 0) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vsffnd, vsfatch, vsfsfld, vsfrd, vsfseek, + + vsfdtch, vfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id, vdata_id + integer vdata_ref, rec_num, num_of_records, rec_pos + real databuf(N_VALS_PER_REC, N_RECORDS) + integer i +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for reading. +C + file_id = hopen(FILE_NAME, DFACC_READ, 0) +C +C Initialize the VS interface. +C + status = vfstart(file_id) +C +C Get the reference number of the vdata, whose name is specified in +C VDATA_NAME, using vsffnd, which will be discussed in Section 4.7.3. +C + vdata_ref = vsffnd(file_id, VDATA_NAME) +C +C Attach to the vdata for reading if it is found, +C otherwise exit the program. +C + if (vdata_ref .eq. 0) stop + vdata_id = vsfatch(file_id, vdata_ref, 'r') +C +C Specify the fields that will be read. +C + status = vsfsfld(vdata_id, FIELDNAME_LIST) +C +C Place the current point to the position specified in RECORD_INDEX. +C + rec_pos = vsfseek(vdata_id, RECORD_INDEX) +C +C Read the next N_RECORDS from the vdata and store the data in the buffer +C databuf with fully interlace mode. +C + num_of_records = vsfrd(vdata_id, databuf, N_RECORDS, + + FULL_INTERLACE) +C +C Display the read data as many records as the number of records returned +C by vsfrd. +C + write(*,*) ' Particle Position Temperature Range' + write(*,*) + do 10 rec_num = 1, num_of_records + write(*,1000) (databuf(i, rec_num), i = 1, N_VALS_PER_REC) +10 continue +1000 format(1x,3(f6.2), 8x,2(f6.2)) +C +C Terminate access to the vdata and to the VS interface, and +C close the HDF file. +C + status = vsfdtch(vdata_id) + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VD_read_mixed_vdata.f b/HDF4Examples/hdf/fortran/h4ex_VD_read_mixed_vdata.f new file mode 100644 index 0000000000..b08ab73734 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VD_read_mixed_vdata.f @@ -0,0 +1,106 @@ + program read_mixed_vdata + implicit none +C +C Parameter declaration +C + character*16 FILE_NAME + character*16 VDATA_NAME + character*4 FIELD1_NAME + character*5 FIELD2_NAME + character*10 FIELDNAME_LIST + integer N_RECORDS, N_FIELDS + integer BUFFER_SIZE +C + parameter (FILE_NAME = 'Packed_Vdata.hdf', + + VDATA_NAME = 'Mixed Data Vdata', + + FIELD1_NAME = 'Temp', + + FIELD2_NAME = 'Ident', + + FIELDNAME_LIST = 'Temp,Ident') + parameter (N_RECORDS = 20, + + N_FIELDS = 2, + + BUFFER_SIZE = (4 + 1)*N_RECORDS) + + integer DFACC_READ, DFNT_FLOAT32, DFNT_CHAR8, + + FULL_INTERLACE, HDF_VSUNPACK + parameter (DFACC_READ = 1, + + DFNT_FLOAT32 = 5, + + DFNT_CHAR8 = 4, + + FULL_INTERLACE = 0, + + HDF_VSUNPACK = 1) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vsfatch, vsffnd, vsfsfld, + + vsfnpak, vsfcpak, vsfread, vsfdtch, vfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id, vdata_id + integer vdata_ref, num_of_records + real temp(N_RECORDS) + character ident(N_RECORDS) + integer i +C +C Buffer for read packed data should be big enough to hold N_RECORDS. +C + integer databuf(BUFFER_SIZE/4 + 1) +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for reading. +C + file_id = hopen(FILE_NAME, DFACC_READ, 0) +C +C Initialize the VS interface. +C + status = vfstart(file_id) +C +C Get the reference number of the vdata, whose name is specified in +C VDATA_NAME, using vsffnd, which will be discussed in Section 4.7.3. +C + vdata_ref = vsffnd(file_id, VDATA_NAME) +C +C Attach to the vdata for reading if it is found, +C otherwise exit the program. +C + if (vdata_ref .eq. 0) stop + vdata_id = vsfatch(file_id, vdata_ref, 'r') +C +C Specify the fields that will be read. +C + status = vsfsfld(vdata_id, FIELDNAME_LIST) + +C +C Read N_RECORDS records of the vdata and store the values into the databuf. +C + num_of_records = vsfread(vdata_id, databuf, N_RECORDS, + + FULL_INTERLACE) +C +C Unpack N_RECORDS from databuf into temp and ident arrays. +C In Fortran, each field is unpacked using separate calls to +C vsfnpak or vsfcpak. +C + status = vsfnpak(vdata_id, HDF_VSUNPACK, FIELDNAME_LIST, databuf, + + BUFFER_SIZE, num_of_records, FIELD1_NAME, temp) + status = vsfcpak(vdata_id, HDF_VSUNPACK, FIELDNAME_LIST, databuf, + + BUFFER_SIZE, num_of_records, FIELD2_NAME, ident) +C +C Display the read data being stored in the field databufs. +C + write (*,*) ' Temp Ident' + do 10 i = 1, num_of_records + write(*,1000) temp(i), ident(i) +10 continue +1000 format (3x,F6.2, 4x, a) +C +C Terminate access to the vdata and to the VS interface, and +C close the HDF file. +C + status = vsfdtch(vdata_id) + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VD_set_get_vdata_attr.f b/HDF4Examples/hdf/fortran/h4ex_VD_set_get_vdata_attr.f new file mode 100644 index 0000000000..ffdbf73782 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VD_set_get_vdata_attr.f @@ -0,0 +1,134 @@ + program vdata_attributes + implicit none +C +C Parameter declaration +C + character*18 FILE_NAME + character*14 VDATA_NAME + character*4 FIELD_NAME + character*10 VATTR_NAME + character*6 FATTR_NAME + integer VATTR_N_VALUES, FATTR_N_VALUES +C + parameter (FILE_NAME = 'General_Vdatas.hdf', + + VDATA_NAME = 'Solid Particle', + + FIELD_NAME = 'Mass', + + VATTR_NAME = 'Site Ident', + + FATTR_NAME = 'Scales') + parameter (VATTR_N_VALUES = 3, + + FATTR_N_VALUES = 4) + + integer DFACC_WRITE, FULL_INTERLACE, HDF_VDATA + integer DFNT_INT32, DFNT_CHAR8 + parameter (DFACC_WRITE = 2, + + FULL_INTERLACE = 0, + + HDF_VDATA = -1, + + DFNT_INT32 = 24, + + DFNT_CHAR8 = 4) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vsffnd, vsfatch, vsfscat, vsfsnat, + + vsffnas, vsffidx, vsfnats, vsfainf, vsfgcat, vsfgnat, + + vsfdtch, vfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id, vdata_id, vdata_ref + integer field_index, n_vdattrs, n_fldattrs + integer vdata_type, vdata_n_values, vdata_size + integer field_type, field_n_values, field_size + character vd_attr(VATTR_N_VALUES) + integer fld_attr(FATTR_N_VALUES) + character vattr_buf(VATTR_N_VALUES) + integer fattr_buf(FATTR_N_VALUES) + character vattr_name_out(30), fattr_name_out(30) + data vd_attr /'A', 'B', 'C'/ + data fld_attr /2, 4, 6, 8/ +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for writing. +C + file_id = hopen(FILE_NAME, DFACC_WRITE, 0) +C +C Initialize the VS interface. +C + status = vfstart(file_id) +C +C Get the reference number of the vdata named VDATA_NAME. +C + vdata_ref = vsffnd(file_id, VDATA_NAME) +C +C Attach to the vdata for writing. +C + vdata_id = vsfatch(file_id, vdata_ref, 'w') +C +C Attach an attribute to the vdata, as it is indicated by second parameter. +C + status = vsfscat(vdata_id, HDF_VDATA, VATTR_NAME, DFNT_CHAR8, + + VATTR_N_VALUES, vd_attr) +C +C Get the index of the field FIELD_NAME within the vdata. +C + status = vsffidx(vdata_id, FIELD_NAME, field_index) +C +C Attach an attribute to the field with the index field_index. +C + status = vsfsnat(vdata_id, field_index, FATTR_NAME, DFNT_INT32, + + FATTR_N_VALUES, fld_attr) + +C +C Get the number of attributes attached to the vdata's first +C field - should be 0. +C + n_fldattrs = vsffnas(vdata_id, 0) + write(*,*) 'Number of attributes of the first field' + write(*,*) ' of the vdata: ', n_fldattrs +C +C Get the number of the attributes attached to the field specified by +C index field_index - should be 1. +C + n_fldattrs = vsffnas(vdata_id, field_index) + write(*,*) 'Number of attributes of field ', FIELD_NAME, + + n_fldattrs +C +C Get the total number of the field's and vdata's attributes - should be 2. +C + n_vdattrs = vsfnats(vdata_id) + write(*,*) 'Number of attributes of the vdata and its fields: ', + + n_vdattrs +C +C Get information about the vdata's first attribute, indicated by +C the third parameter, which is the index of the attribute. +C + status = vsfainf(vdata_id, HDF_VDATA, 0, vattr_name_out, + + vdata_type, vdata_n_values, vdata_size) +C +C Get information about the first attribute of the field specified by +C field_index. +C + status = vsfainf(vdata_id, field_index, 0, fattr_name_out, + + field_type, field_n_values, field_size) +C +C Get the vdata's first attribute. +C + status = vsfgcat(vdata_id, HDF_VDATA, 0, vattr_buf) + write(*,*) 'Values of vdata attribute ', vattr_buf +C +C Get the first attribute of the field specified by field_index. +C + status = vsfgnat(vdata_id, field_index, 0, fattr_buf) + write(*,*) 'Values of the field attribute = ', fattr_buf +C +C Terminate access to the vdata and to the VS interface, and +C close the HDF file. +C + status = vsfdtch(vdata_id) + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VD_write_mixed_vdata.f b/HDF4Examples/hdf/fortran/h4ex_VD_write_mixed_vdata.f new file mode 100644 index 0000000000..76e1e02dfe --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VD_write_mixed_vdata.f @@ -0,0 +1,126 @@ + program write_mixed_vdata + implicit none +C +C Parameter declaration +C + character*16 FILE_NAME + character*18 CLASS_NAME + character*16 VDATA_NAME + character*4 FIELD1_NAME + character*6 FIELD2_NAME + character*5 FIELD3_NAME + character*5 FIELD4_NAME + character*23 FIELDNAME_LIST + integer N_RECORDS, N_FIELDS, ORDER + integer BUF_SIZE +C + parameter (FILE_NAME = 'Packed_Vdata.hdf', + + CLASS_NAME = 'General Data Class', + + VDATA_NAME = 'Mixed Data Vdata', + + FIELD1_NAME = 'Temp', + + FIELD2_NAME = 'Height', + + FIELD3_NAME = 'Speed', + + FIELD4_NAME = 'Ident', + + FIELDNAME_LIST = 'Temp,Height,Speed,Ident') + parameter (N_RECORDS = 20, + + N_FIELDS = 4, + + ORDER = 1, + + BUF_SIZE = (4 + 2 + 4 + 1)*N_RECORDS) + + integer DFACC_WRITE, DFNT_FLOAT32, DFNT_INT16, DFNT_CHAR8, + + FULL_INTERLACE, HDF_VSPACK + parameter (DFACC_WRITE = 2, + + DFNT_FLOAT32 = 5, + + DFNT_INT16 = 22, + + DFNT_CHAR8 = 4, + + FULL_INTERLACE = 0, + + HDF_VSPACK = 0) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vsfatch, vsfsnam, vsfscls, vsffdef, vsfsfld, + + vsfnpak, vsfcpak, vsfwrit, vsfdtch, vfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id, vdata_id + integer vdata_ref, num_of_records + real temp(N_RECORDS) + integer*2 height(N_RECORDS) + real speed(N_RECORDS) + character ident(N_RECORDS) + integer i +C +C Buffer for packed data should be big enough to hold N_RECORDS. +C + integer databuf(BUF_SIZE/4 + 1) +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for writing. +C + file_id = hopen(FILE_NAME, DFACC_WRITE, 0) +C +C Initialize the VS interface. +C + status = vfstart(file_id) +C +C Create a new vdata. +C + vdata_ref = -1 + vdata_id = vsfatch(file_id, vdata_ref, 'w') +C +C Set name and class name of the vdata. +C + status = vsfsnam(vdata_id, VDATA_NAME) + status = vsfscls(vdata_id, CLASS_NAME) +C +C Introduce each field's name, data type, and order. This is the +C first part in defining a field. +C + status = vsffdef(vdata_id, FIELD1_NAME, DFNT_FLOAT32, ORDER) + status = vsffdef(vdata_id, FIELD2_NAME, DFNT_INT16, ORDER) + status = vsffdef(vdata_id, FIELD3_NAME, DFNT_FLOAT32, ORDER) + status = vsffdef(vdata_id, FIELD4_NAME, DFNT_CHAR8, ORDER) +C +C Finalize the definition of the fields. +C + status = vsfsfld(vdata_id, FIELDNAME_LIST) +C +C Enter data values into the field databufs by the records. +C + do 10 i = 1, N_RECORDS + temp(i) = 1.11 * i + height(i) = i - 1 + speed(i) = 1.11 * i + ident(i) = char(64+i) +10 continue +C +C Pack N_RECORDS of data into databuf. In Fortran, each field is packed +C using separate calls to vsfnpak or vsfcpak. +C + status = vsfnpak(vdata_id, HDF_VSPACK, ' ', databuf, BUF_SIZE, + + N_RECORDS, FIELD1_NAME, temp) + status = vsfnpak(vdata_id, HDF_VSPACK, ' ', databuf, BUF_SIZE, + + N_RECORDS, FIELD2_NAME, height) + status = vsfnpak(vdata_id, HDF_VSPACK, ' ', databuf, BUF_SIZE, + + N_RECORDS, FIELD3_NAME, speed) + status = vsfcpak(vdata_id, HDF_VSPACK, ' ', databuf, BUF_SIZE, + + N_RECORDS, FIELD4_NAME, ident) +C +C Write all the records of the packed data to the vdata. +C + num_of_records = vsfwrit(vdata_id, databuf, N_RECORDS, + + FULL_INTERLACE) +C +C Terminate access to the vdata and to the VS interface, and +C close the HDF file. +C + status = vsfdtch(vdata_id) + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VD_write_to_vdata.f b/HDF4Examples/hdf/fortran/h4ex_VD_write_to_vdata.f new file mode 100644 index 0000000000..f6ac90b3c7 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VD_write_to_vdata.f @@ -0,0 +1,106 @@ + program write_to_vdata + implicit none +C +C Parameter declaration +C + character*18 FILE_NAME + character*13 CLASS_NAME + character*14 VDATA_NAME + character*8 FIELD1_NAME + character*4 FIELD2_NAME + character*11 FIELD3_NAME + character*27 FIELDNAME_LIST + integer N_RECORDS + integer ORDER_1, ORDER_2, ORDER_3 + integer N_VALS_PER_REC +C + parameter (FILE_NAME = 'General_Vdatas.hdf', + + CLASS_NAME = 'Particle Data', + + VDATA_NAME = 'Solid Particle', + + FIELD1_NAME = 'Position', + + FIELD2_NAME = 'Mass', + + FIELD3_NAME = 'Temperature', + + FIELDNAME_LIST = 'Position,Mass,Temperature') + parameter (N_RECORDS = 10, + + ORDER_1 = 3, + + ORDER_2 = 1, + + ORDER_3 = 2, + + N_VALS_PER_REC = ORDER_1 + ORDER_2 + ORDER_3) + + integer DFACC_WRITE, DFNT_FLOAT32, FULL_INTERLACE + parameter (DFACC_WRITE = 2, + + DFNT_FLOAT32 = 5, + + FULL_INTERLACE = 0) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vsfatch, vsfsnam, vsfscls, vsffdef, vsfsfld, + + vsfwrt, vsfdtch, vfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id, vdata_id + integer vdata_ref, rec_num, num_of_records + real data_buf(N_VALS_PER_REC, N_RECORDS) +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for writing. +C + file_id = hopen(FILE_NAME, DFACC_WRITE, 0) +C +C Initialize the VS interface. +C + status = vfstart(file_id) +C +C Create a new vdata. +C + vdata_ref = -1 + vdata_id = vsfatch(file_id, vdata_ref, 'w') +C +C Set name and class name of the vdata. +C + status = vsfsnam(vdata_id, VDATA_NAME) + status = vsfscls(vdata_id, CLASS_NAME) +C +C Introduce each field's name, data type, and order. This is the +C first part in defining a field. +C + status = vsffdef(vdata_id, FIELD1_NAME, DFNT_FLOAT32, ORDER_1) + status = vsffdef(vdata_id, FIELD2_NAME, DFNT_FLOAT32, ORDER_2) + status = vsffdef(vdata_id, FIELD3_NAME, DFNT_FLOAT32, ORDER_3) +C +C Finalize the definition of the fields. +C + status = vsfsfld(vdata_id, FIELDNAME_LIST) +C +C Buffer the data by the record for fully interlaced mode. Note that the +C first three elements contain the three values of the first field, +C the forth element contains the value of the second field, and the last two +C elements contain the two values of the third field. +C + do 10 rec_num = 1, N_RECORDS + data_buf(1, rec_num) = 1.0 * rec_num + data_buf(2, rec_num) = 2.0 * rec_num + data_buf(3, rec_num) = 3.0 * rec_num + data_buf(4, rec_num) = 0.1 + rec_num + data_buf(5, rec_num) = 0.0 + data_buf(6, rec_num) = 65.0 +10 continue +C +C Write the data from data_buf to the vdata with the full interlacing mode. +C + num_of_records = vsfwrt(vdata_id, data_buf, N_RECORDS, + + FULL_INTERLACE) +C +C Terminate access to the vdata and to the VS interface, and +C close the HDF file. +C + status = vsfdtch(vdata_id) + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VG_add_sds_to_vgroup.f b/HDF4Examples/hdf/fortran/h4ex_VG_add_sds_to_vgroup.f new file mode 100644 index 0000000000..9f0063ad72 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VG_add_sds_to_vgroup.f @@ -0,0 +1,91 @@ + program add_SDS_to_a_vgroup + implicit none +C +C Parameter declaration +C + character*19 FILE_NAME + character*7 SDS_NAME + character*9 VG_NAME + character*13 VG_CLASS +C + parameter (FILE_NAME = 'General_Vgroups.hdf', + + SDS_NAME = 'Test SD', + + VG_NAME = 'SD Vgroup', + + VG_CLASS = 'Common Vgroups') + integer DFACC_CREATE, DFACC_WRITE + parameter (DFACC_CREATE = 4, DFACC_WRITE = 2) + integer DFNT_INT32 + parameter (DFNT_INT32 = 24) + integer DFTAG_NDG + parameter (DFTAG_NDG = 720) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vfatch, vfsnam, vfscls, vfadtr, vfdtch, vfend + integer sfstart, sfcreate, sfid2ref, sfendacc, sfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id + integer vgroup_id + integer sd_id, sds_id, sds_ref + integer dim_sizes(1), rank +C +C**** End of variable declaration ************************************ +C +C +C Create the HDF file. +C + file_id = hopen(FILE_NAME, DFACC_CREATE, 0) +C +C Initialize the V interface. +C + status = vfstart(file_id) + +C +C Initialize SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_WRITE) +C +C Set the rank and the size of SDS's dimension. +C + rank = 1 + dim_sizes(1) = 10 +C +C Create the SDS. +C + sds_id = sfcreate(sd_id, SDS_NAME, DFNT_INT32, rank, dim_sizes) +C +C Create a vgroup and set its name and class. +C + vgroup_id = vfatch(file_id, -1 , 'w') + status = vfsnam(vgroup_id, VG_NAME) + status = vfscls(vgroup_id, VG_CLASS) +C +C Obtain the reference number of the SDS using its identifier. +C + sds_ref = sfid2ref(sds_id) +C +C Add the SDS to the vgroup. Note: the tag DFTAG_NDG is used +C when adding an SDS. Refer to HDF Reference Manual, Section III, Table 3K, +C for the entire list of tags. +C + status = vfadtr(vgroup_id, DFTAG_NDG, sds_ref) +C +C Terminate access to the SDS and to the SD interface. +C + status = sfendacc(sds_id) + status = sfend(sd_id) +C +C Terminate access to the vgroup. +C + status = vfdtch(vgroup_id) +C +C Terminate access to the V interface and close the HDF file. +C + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VG_create_vgroup.f b/HDF4Examples/hdf/fortran/h4ex_VG_create_vgroup.f new file mode 100644 index 0000000000..bb894ca155 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VG_create_vgroup.f @@ -0,0 +1,61 @@ + program create_vgroup + implicit none +C +C Parameter declaration +C + character*15 FILE_NAME +C + parameter (FILE_NAME = 'Two_Vgroups.hdf') + integer DFACC_CREATE + parameter (DFACC_CREATE = 4) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vfatch, vfdtch, vfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id + integer vgroup1_id, vgroup2_id, vgroup_ref +C +C**** End of variable declaration ************************************ +C +C +C Create the HDF file. +C + file_id = hopen(FILE_NAME, DFACC_CREATE, 0) +C +C Initialize the V interface. +C + status = vfstart(file_id) +C +C Create the first vgroup. Note that the vgroup reference number is set +C to -1 for creating and the access mode is 'w' for writing. +C + vgroup_ref = -1 + vgroup1_id = vfatch(file_id, vgroup_ref, 'w') +C +C Create the second vgroup. +C + vgroup2_id = vfatch(file_id, vgroup_ref, 'w') +C +C Any operations on the vgroups. +C +C .............................. +C +C Terminate access to the first vgroup. +C + status = vfdtch(vgroup1_id) +C +C Terminate access to the second vgroup. +C + status = vfdtch(vgroup2_id) +C +C Terminate access to the V interface and close the HDF file. +C + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VG_get_vgroup_info.f b/HDF4Examples/hdf/fortran/h4ex_VG_get_vgroup_info.f new file mode 100644 index 0000000000..40cc1d4463 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VG_get_vgroup_info.f @@ -0,0 +1,97 @@ + program getinfo_about_vgroup + implicit none +C +C Parameter declaration +C + character*19 FILE_NAME +C + parameter (FILE_NAME = 'General_Vgroups.hdf') + integer DFACC_READ + parameter (DFACC_READ = 1) + integer SIZE + parameter(SIZE = 10) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vfatch, vfgnam, vfgcls, vflone, vfdtch, vfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id + integer vgroup_id + integer lone_vg_number, num_of_lones + character*64 vgroup_name, vgroup_class + integer ref_array(SIZE) + integer i +C +C**** End of variable declaration ************************************ +C +C +C Initialize ref_array. +C + do 10 i = 1, SIZE + ref_array(i) = 0 +10 continue +C +C Open the HDF file for reading. +C + file_id = hopen(FILE_NAME, DFACC_READ, 0) +C +C Initialize the V interface. +C + status = vfstart(file_id) +C +C Get and print the name and class name of all lone vgroups. +C First, call vflone with num_of_lones set to 0 to get the number of +C lone vgroups in the file and check whether size of ref_array is +C big enough to hold reference numbers of ALL lone groups. +C If ref_array is not big enough, exit the program after displaying an +C informative message. +C + num_of_lones = 0 + num_of_lones = vflone(file_id, ref_array, num_of_lones) + if (num_of_lones .gt. SIZE) then + write(*,*) num_of_lones, 'lone vgroups is found' + write(*,*) 'increase the size of ref_array to hold reference ' + write(*,*) 'numbers of all lone vgroups in the file' + stop + endif +C +C If there are any lone groups in the file, +C + if (num_of_lones .gt. 0) then +C +C call vflone again to retrieve the reference numbers into ref_array. +C + num_of_lones = vflone(file_id, ref_array, num_of_lones) +C +C Display the name and class of each vgroup. +C + write(*,*) 'Lone vgroups in the file are:' + + do 20 lone_vg_number = 1, num_of_lones +C +C Attach to the current vgroup, then get and display its name and class. +C Note: the current vgroup must be detached before moving to the next. +C + vgroup_name = ' ' + vgroup_class = ' ' + vgroup_id = vfatch(file_id, ref_array(lone_vg_number), 'r') + status = vfgnam(vgroup_id, vgroup_name) + status = vfgcls(vgroup_id, vgroup_class) + write(*,*) 'Vgroup name ' , vgroup_name + write(*,*) 'Vgroup class ' , vgroup_class + write(*,*) + status = vfdtch(vgroup_id) +20 continue + + endif +C +C Terminate access to the V interface and close the HDF file. +C + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VG_insert_vdatas_to_vgroup.f b/HDF4Examples/hdf/fortran/h4ex_VG_insert_vdatas_to_vgroup.f new file mode 100644 index 0000000000..57258cc4c9 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VG_insert_vdatas_to_vgroup.f @@ -0,0 +1,167 @@ + program add_vdatas_to_a_vgroup + implicit none +C +C Parameter declaration +C + character*19 FILE_NAME + character*8 VG_NAME + character*10 VG_CLASS + character*15 VD1_NAME + character*8 VD1_CLASS + character*11 VD2_NAME + character*13 VD2_CLASS + character*9 VD3_NAME + character*4 VD3_CLASS +C + parameter (FILE_NAME = 'General_Vgroups.hdf', + + VG_NAME = 'Vertices', + + VG_CLASS = 'Vertex Set') + parameter (VD1_NAME = 'X,Y Coordinates', + + VD2_NAME = 'Temperature', + + VD3_NAME = 'Node List') + parameter (VD1_CLASS = 'Position', + + VD2_CLASS = 'Property List', + + VD3_CLASS = 'Mesh') + character*2 FIELD1_VD1 + character*2 FIELD2_VD1 + character*3 FIELD_VD2 + character*4 FIELD_VD3 + character*5 FIELDNAME_LIST + parameter (FIELD1_VD1 = 'PX', + + FIELD2_VD1 = 'PY', + + FIELD_VD2 = 'TMP', + + FIELD_VD3 = 'PLIST', + + FIELDNAME_LIST = 'PX,PY') + integer N_RECORDS + parameter (N_RECORDS = 30) + + integer DFACC_WRITE + parameter (DFACC_WRITE = 2) + integer DFNT_FLOAT32, DFNT_INT16 + parameter (DFNT_FLOAT32 = 5, DFNT_INT16 = 22) + integer FULL_INTERLACE + parameter (FULL_INTERLACE = 0) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vfatch, vfsnam, vfscls, vfinsrt, vfdtch, vfend + integer vsfatch, vsfsnam, vsfscls, vsffdef, vsfsfld, + + vsfwrt, vsfwrtc, vsfdtch + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id + integer vgroup_id + integer vdata1_id, vdata2_id, vdata3_id, vd_index + integer num_of_records + integer i, j, k + real pxy(2,N_RECORDS), tmp(N_RECORDS) + integer plist(3,N_RECORDS) + data pxy /-1.5, 2.3, -1.5, 1.98, -2.4, .67, + + -3.4, 1.46, -.65, 3.1, -.62, 1.23, + + -.4, 3.8, -3.55, 2.3, -1.43, 2.44, + + .23, 1.13, -1.4, 5.43, -1.4, 5.8, + + -3.4, 3.85, -.55, .3, -.21, 1.22, + + -1.44, 1.9, -1.4, 2.8, .94, 1.78, + + -.4, 2.32, -.87, 1.99, -.54, 4.11, + + -1.5, 1.35, -1.4, 2.21, -.22, 1.8, + + -1.1, 4.55, -.44, .54, -1.11, 3.93, + + -.76, 1.9, -2.34, 1.7, -2.2, 1.21/ +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for writing. +C + file_id = hopen(FILE_NAME, DFACC_WRITE, 0) +C +C Initialize the V interface. +C + status = vfstart(file_id) +C +C Buffer the data for the third and second vdatas. +C + do 20 i = 1, N_RECORDS + do 10 j = 1, 3 + plist(j,i) = k + k = k+1 +10 continue +20 continue + do 30 i = 1, N_RECORDS + tmp(i) = (i-1) * 10.0 +30 continue +C +C Create a vgroup and set its name and class. +C Note that the vgroup's reference number is set to -1 for creating +C and the access mode is 'w' for writing. +C + vgroup_id = vfatch(file_id, -1 , 'w') + status = vfsnam(vgroup_id, VG_NAME) + status = vfscls(vgroup_id, VG_CLASS) +C +C Create the first vdata then set its name and class. Note that the vdata's +C reference number is set to -1 for creating and the access mode is 'w' for +C writing. +C + vdata1_id = vsfatch(file_id, -1, 'w') + status = vsfsnam(vdata1_id, VD1_NAME) + status = vsfscls(vdata1_id, VD1_CLASS) +C +C Introduce and define the fields of the first vdata. +C + status = vsffdef(vdata1_id, FIELD1_VD1, DFNT_FLOAT32, 1) + status = vsffdef(vdata1_id, FIELD2_VD1, DFNT_FLOAT32, 1) + status = vsfsfld(vdata1_id, FIELDNAME_LIST) +C +C Write the buffered data into the first vdata. +C + num_of_records = vsfwrt(vdata1_id, pxy, N_RECORDS, + + FULL_INTERLACE) +C +C Insert the vdata into the vgroup using its identifier. +C + vd_index = vfinsrt(vgroup_id, vdata1_id) +C +C Detach from the first vdata. +C + status = vsfdtch(vdata1_id) +C +C Create, write, and insert the second vdata to the vgroup using +C steps similar to those used for the first vdata. +C + vdata2_id = vsfatch(file_id, -1, 'w') + status = vsfsnam(vdata2_id, VD2_NAME) + status = vsfscls(vdata2_id, VD2_CLASS) + status = vsffdef(vdata2_id, FIELD_VD2, DFNT_FLOAT32, 1) + status = vsfsfld(vdata2_id, FIELD_VD2) + num_of_records = vsfwrt(vdata2_id, tmp, N_RECORDS, + + FULL_INTERLACE) + vd_index = vfinsrt(vgroup_id, vdata2_id) + status = vsfdtch(vdata2_id) +C +C Create, write, and insert the third vdata to the vgroup using +C steps similar to those used for the first and second vdatas. +C + vdata3_id = vsfatch(file_id, -1, 'w') + status = vsfsnam(vdata3_id, VD3_NAME) + status = vsfscls(vdata3_id, VD3_CLASS) + status = vsffdef(vdata3_id, FIELD_VD3, DFNT_INT16, 3) + status = vsfsfld(vdata3_id, FIELD_VD3) + num_of_records = vsfwrtc(vdata3_id, plist, N_RECORDS, + + FULL_INTERLACE) + vd_index = vfinsrt(vgroup_id, vdata3_id) + status = vsfdtch(vdata3_id) + +C +C Terminate access to the vgroup 'Vertices'. +C + status = vfdtch(vgroup_id) +C +C Terminate access to the V interface and close the HDF file. +C + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VG_set_get_vgroup_attr.f b/HDF4Examples/hdf/fortran/h4ex_VG_set_get_vgroup_attr.f new file mode 100644 index 0000000000..cb14aa1ec1 --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VG_set_get_vgroup_attr.f @@ -0,0 +1,106 @@ + program vgroup_attribute + implicit none +C +C Parameter declaration +C + character*19 FILE_NAME + character*9 VGROUP_NAME + character*15 VGATTR_NAME +C + parameter (FILE_NAME = 'General_Vgroups.hdf', + + VGROUP_NAME = 'SD Vgroup', + + VGATTR_NAME = 'First Attribute') + integer VSET_NEW_VERSION, VSET_VERSION, VSET_OLD_VERSION + parameter (VSET_NEW_VERSION = 4, + + VSET_VERSION = 3, + + VSET_OLD_VERSION = 2) + integer DFACC_WRITE + parameter (DFACC_WRITE = 2) + integer DFNT_CHAR + parameter (DFNT_CHAR = 4) + integer N_ATT_VALUES + parameter (N_ATT_VALUES = 6) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vfatch, vfgver, vfscatt, vfnatts, vfainfo, + + vfind, vfgcatt, vfdtch, vfend +C +C**** Variable declaration ******************************************* +C + integer status, n_attrs + integer file_id + integer vgroup_id, vgroup_ref, vg_version + integer attr_index, i + integer data_type, n_values, size + character vg_attr(N_ATT_VALUES) + character vgattr_buf(N_ATT_VALUES), attr_name(30) + data vg_attr /'v','g','r','o','u','p'/ +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for reading/writing. +C + file_id = hopen(FILE_NAME, DFACC_WRITE, 0) +C +C Initialize the V interface. +C + status = vfstart(file_id) +C +C Get the reference number of the vgroup named VGROUP_NAME. +C + vgroup_ref = vfind(file_id, VGROUP_NAME) +C +C Attach to the vgroup found. +C + vgroup_id = vfatch(file_id, vgroup_ref , 'w') +C +C Get and display the version of the attached vgroup. +C + vg_version = vfgver(vgroup_id) + if (vg_version .eq. VSET_NEW_VERSION) write(*,*) + + VGROUP_NAME, ' is of the newest version, version 4' + if (vg_version .eq. VSET_VERSION) write(*,*) + + VGROUP_NAME, ' is of a version between 3.2 and 4.0r2' + if(vg_version .eq. VSET_OLD_VERSION) write(*,*) + + VGROUP_NAME, ' is of version before 3.2' + if ((vg_version .ne. VSET_NEW_VERSION) .and. + + (vg_version .ne. VSET_VERSION) .and. + + (vg_version .ne. VSET_OLD_VERSION)) write(*,*) + + 'Unknown version' +C +C Add the attribute named VGATTR_NAME to the vgroup. +C + status = vfscatt(vgroup_id, VGATTR_NAME, DFNT_CHAR, N_ATT_VALUES, + + vg_attr) +C +C Get and display the number of attributes attached to this group. +C + n_attrs = vfnatts(vgroup_id) + write(*,*) 'This group has', n_attrs, ' attributes' +C +C Get and display the name and the number of values of each attribute. +C + do 10 attr_index=1, n_attrs + status = vfainfo(vgroup_id, attr_index-1, attr_name, data_type, + + n_values, size) + write(*,*) 'Attribute #', attr_index-1, ' is named ', attr_name + write(*,*) 'and has', n_values, ' values: ' +C +C Get and display the attribute values. +C + status = vfgcatt(vgroup_id, attr_index-1, vgattr_buf) + write(*,*) (vgattr_buf(i), i=1,n_values) +10 continue +C +C Terminate access to the vgroup. +C + status = vfdtch(vgroup_id) +C +C Terminate accessto the V interface and close the HDF file. +C + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/hdf/fortran/h4ex_VG_vgroup_contents.f b/HDF4Examples/hdf/fortran/h4ex_VG_vgroup_contents.f new file mode 100644 index 0000000000..336fa1487b --- /dev/null +++ b/HDF4Examples/hdf/fortran/h4ex_VG_vgroup_contents.f @@ -0,0 +1,102 @@ + program vgroup_contents + implicit none +C +C Parameter declaration +C + character*19 FILE_NAME +C + parameter (FILE_NAME = 'General_Vgroups.hdf') + integer DFACC_ READ + parameter (DFACC_READ = 1) +C +C Function declaration +C + integer hopen, hclose + integer vfstart, vfatch, vfgid, vntrc, vfgttr, vfisvg, + + vfisvs, vfdtch, vfend + +C +C**** Variable declaration ******************************************* +C + integer status + integer file_id + integer vgroup_id, vgroup_ref, vgroup_pos + integer obj_index, num_of_pairs + integer obj_tag, obj_ref +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file for reading. +C + file_id = hopen(FILE_NAME, DFACC_READ, 0) +C +C Initialize the V interface. +C + status = vfstart(file_id) +C +C Obtain each vgroup in the file by its reference number, get the +C number of objects in the vgroup, and display the information +C about that vgroup. +C + vgroup_ref = -1 + vgroup_pos = 0 +10 continue +C +C Get the reference number of the next vgroup in the file. +C + vgroup_ref = vfgid(file_id, vgroup_ref) +C +C Attach to the vgroup or go to the end if no additional vgroup is found. +C + if(vgroup_ref. eq. -1) goto 100 + vgroup_id = vfatch(file_id, vgroup_ref , 'r') +C +C Get the total number of objects in the vgroup. +C + num_of_pairs = vntrc(vgroup_id) +C +C If the vgroup contains any object, print the tag/ref number +C pair of each object in vgroup, in the order they appear in the +C file, and indicate whether the object is a vdata, vgroup, or neither. +C + if (num_of_pairs .gt. 0) then + write(*,*) 'Vgroup # ', vgroup_pos, ' contains:' + do 20 obj_index = 1, num_of_pairs +C +C Get the tag/ref number pair of the object specified by its index +C and display them. +C + status = vfgttr(vgroup_id, obj_index-1, obj_tag, obj_ref) +C +C State whether the HDF object referred to by obj_ref is a vdata, +C a vgroup, or neither. +C + if( vfisvg(vgroup_id, obj_ref) .eq. 1) then + write(*,*) 'tag = ', obj_tag, ' ref = ', obj_ref, + + ' <--- is a vgroup ' + else if ( vfisvs(vgroup_id, obj_ref) .eq. 1) then + write(*,*) 'tag = ', obj_tag, ' ref = ', obj_ref, + + ' <--- is a vdata ' + else + write(*,*) 'tag = ', obj_tag, ' ref = ', obj_ref, + + ' <--- neither vdata nor vgroup ' + endif +20 continue + else + write (*,*) 'Vgroup #', vgroup_pos, ' contains no HDF objects' + endif + write(*,*) + vgroup_pos = vgroup_pos + 1 + goto 10 +100 continue +C +C Terminate access to the vgroup. +C + status = vfdtch(vgroup_id) +C +C Terminate access to the V interface and close the HDF file. +C + status = vfend(file_id) + status = hclose(file_id) + end diff --git a/HDF4Examples/mfhdf/CMakeLists.txt b/HDF4Examples/mfhdf/CMakeLists.txt new file mode 100644 index 0000000000..996a0eae89 --- /dev/null +++ b/HDF4Examples/mfhdf/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_MFHDF) + +#----------------------------------------------------------------------------- +# Build the mfhdf examples +#----------------------------------------------------------------------------- +add_subdirectory (examples) +if (HDF_BUILD_FORTRAN) + add_subdirectory (fortran) +endif (HDF_BUILD_FORTRAN) diff --git a/HDF4Examples/mfhdf/examples/CMakeLists.txt b/HDF4Examples/mfhdf/examples/CMakeLists.txt new file mode 100644 index 0000000000..f96360857b --- /dev/null +++ b/HDF4Examples/mfhdf/examples/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_MFHDF C) + +#----------------------------------------------------------------------------- +# Define Sources +#----------------------------------------------------------------------------- +include (C_sourcefiles.cmake) + +if (H4EX_BUILD_TESTING) + # Remove any output file left over from previous test run + add_test ( + NAME MFHDF_EXAMPLES-clearall-objects + COMMAND ${CMAKE_COMMAND} + -E remove + SDS.hdf + SDSchunked.hdf + SDScompressed.hdf + SDSUNLIMITED.hdf + SLABS.hdf + ExternalSDS + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (MFHDF_EXAMPLES-clearall-objects PROPERTIES DEPENDS ${last_test} LABELS ${PROJECT_NAME}) + else () + set_tests_properties (MFHDF_EXAMPLES-clearall-objects PROPERTIES LABELS ${PROJECT_NAME}) + endif () + set (last_test "MFHDF_EXAMPLES-clearall-objects") +endif () + +foreach (example ${examples}) + get_filename_component (example_name ${example} NAME_WE) + add_executable (mf_${example_name} ${PROJECT_SOURCE_DIR}/${example}) + target_link_libraries (mf_${example_name} ${H4EX_HDF4_LINK_LIBS}) + if (H4EX_BUILD_TESTING) + add_test ( + NAME mftest_${example_name} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:mf_${example_name}>" + -D "TEST_ARGS:STRING=" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_EXPECT=0" + -D "TEST_SKIP_COMPARE=TRUE" + -D "TEST_OUTPUT=${example_name}.out" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -P "${HDF4EX_RESOURCES_DIR}/runTest.cmake" + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (mftest_${example_name} PROPERTIES DEPENDS ${last_test} LABELS ${PROJECT_NAME}) + else () + set_tests_properties (mftest_${example_name} PROPERTIES LABELS ${PROJECT_NAME}) + endif () + set (last_test "mftest_${example_name}") + endif () +endforeach () diff --git a/HDF4Examples/mfhdf/examples/C_sourcefiles.cmake b/HDF4Examples/mfhdf/examples/C_sourcefiles.cmake new file mode 100644 index 0000000000..55a28bf3cf --- /dev/null +++ b/HDF4Examples/mfhdf/examples/C_sourcefiles.cmake @@ -0,0 +1,21 @@ +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +set (examples + h4ex_SD_create_sds.c + h4ex_SD_write_to_sds.c + h4ex_SD_write_slab.c + h4ex_SD_alter_sds_values.c + h4ex_SD_unlimited_sds.c + h4ex_SD_compress_sds.c + h4ex_SD_mv_sds_to_external.c + h4ex_SD_read_from_sds.c + h4ex_SD_read_subsets.c + h4ex_SD_get_info.c + h4ex_SD_find_sds_by_name.c + h4ex_SD_set_get_dim_info.c + h4ex_SD_dimscale_vs_sds.c + h4ex_SD_set_attr.c + h4ex_SD_get_attr.c + h4ex_SD_chunking_example.c +) diff --git a/HDF4Examples/mfhdf/examples/Makefile.am b/HDF4Examples/mfhdf/examples/Makefile.am new file mode 100644 index 0000000000..524ed8ed8d --- /dev/null +++ b/HDF4Examples/mfhdf/examples/Makefile.am @@ -0,0 +1,55 @@ +############################################################################# +## Setup for building programs ## +############################################################################# + +include $(top_srcdir)/config/commence.am + +DEFINES=-DNDEBUG -DHDF + +############################################################################# +## Programs to build ## +############################################################################# + +TEST_PROG = h4ex_SD_create_sds h4ex_SD_write_to_sds h4ex_SD_write_slab \ + h4ex_SD_alter_sds_values h4ex_SD_unlimited_sds h4ex_SD_compress_sds \ + h4ex_SD_mv_sds_to_external h4ex_SD_read_from_sds h4ex_SD_read_subsets \ + h4ex_SD_get_info h4ex_SD_find_sds_by_name h4ex_SD_set_get_dim_info \ + h4ex_SD_dimscale_vs_sds h4ex_SD_set_attr h4ex_SD_get_attr h4ex_SD_chunking_example + +INSTALL_FILES = h4ex_SD_create_sds.c h4ex_SD_write_to_sds.c h4ex_SD_write_slab.c \ + h4ex_SD_alter_sds_values.c h4ex_SD_unlimited_sds.c h4ex_SD_compress_sds.c \ + h4ex_SD_mv_sds_to_external.c h4ex_SD_read_from_sds.c h4ex_SD_read_subsets.c \ + h4ex_SD_get_info.c h4ex_SD_find_sds_by_name.c h4ex_SD_set_get_dim_info.c \ + h4ex_SD_dimscale_vs_sds.c h4ex_SD_set_attr.c h4ex_SD_get_attr.c h4ex_SD_chunking_example.c + +EXAMPLEDIR=$(prefix)/examples/c + +# How to build programs using h4cc +$(EXTRA_PROG): $(H4CC) + $(H4CC) $(H4CCFLAGS) $(CFLAGS) -o $@ $(srcdir)/$@.c; + +# List dependencies for each program. Normally, automake would take +# care of this for us, but if we tell automake about the programs it +# will try to build them with the normal C++ compiler, not h4cc. This is +# an inelegant way of solving the problem, unfortunately. +create_sds: $(srcdir)/h4ex_SD_create_sds.c +write_to_sds: $(srcdir)/h4ex_SD_write_to_sds.c +write_slab: $(srcdir)/h4ex_SD_write_slab.c +alter_sds_values: $(srcdir)/h4ex_SD_alter_sds_values.c +unlimited_sds: $(srcdir)/h4ex_SD_unlimited_sds.c +compress_sds: $(srcdir)/h4ex_SD_compress_sds.c +mv_sds_to_external: $(srcdir)/h4ex_SD_mv_sds_to_external.c +read_from_sds: $(srcdir)/h4ex_SD_read_from_sds.c +read_subsets: $(srcdir)/h4ex_SD_read_subsets.c +get_info: $(srcdir)/h4ex_SD_get_info.c +find_sds_by_name: $(srcdir)/h4ex_SD_find_sds_by_name.c +set_get_dim_info: $(srcdir)/h4ex_SD_set_get_dim_info.c +dimscale_vs_sds: $(srcdir)/h4ex_SD_dimscale_vs_sds.c +set_attr: $(srcdir)/h4ex_SD_set_attr.c +get_attr: $(srcdir)/h4ex_SD_get_attr.c +chunking_example: $(srcdir)/h4ex_SD_chunking_example.c + +include $(top_srcdir)/config/examples.am +include $(top_srcdir)/config/conclude.am + +DISTCLEANFILES = *.chklog *.chkexe ExternalSDS .deps diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_alter_sds_values.c b/HDF4Examples/mfhdf/examples/h4ex_SD_alter_sds_values.c new file mode 100644 index 0000000000..97e7a45fbf --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_alter_sds_values.c @@ -0,0 +1,57 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDS.hdf" + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id, sds_index; + intn status; + int32 start[2], edges[2]; + int32 new_data[2]; + + /********************* End of variable declaration ***********************/ + /* + * Open the file and initialize the SD interface with write access. + */ + sd_id = SDstart(FILE_NAME, DFACC_WRITE); + + /* + * Select the first data set. + */ + sds_index = 0; + sds_id = SDselect(sd_id, sds_index); + + /* + * Set up the start and edge parameters to write new element values + * into 10th row, 2nd column place, and 11th row, 2nd column place. + */ + start[0] = 9; /* starting at 10th row */ + start[1] = 1; /* starting at 2nd column */ + edges[0] = 2; /* rows 10th and 11th */ + edges[1] = 1; /* column 2nd only */ + + /* + * Initialize buffer with the new values to be written. + */ + new_data[0] = new_data[1] = 1000; + + /* + * Write the new values. + */ + status = SDwritedata(sds_id, start, NULL, edges, (VOIDP)new_data); + + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_chunking_example.c b/HDF4Examples/mfhdf/examples/h4ex_SD_chunking_example.c new file mode 100755 index 0000000000..3cce2410e6 --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_chunking_example.c @@ -0,0 +1,285 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDSchunked.hdf" +#define SDS_NAME "ChunkedData" +#define RANK 2 + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id, sds_index; + intn status; + int32 flag, maxcache, new_maxcache; + int32 dim_sizes[2], origin[2]; + HDF_CHUNK_DEF c_def, c_def_out; /* Chunking definitions */ + int32 comp_flag, c_flags; + int16 all_data[9][4]; + int32 start[2], edges[2]; + int16 chunk_out[3][2]; + int16 row[2] = {5, 5}; + int16 column[3] = {4, 4, 4}; + int16 fill_value = 0; /* Fill value */ + int i, j; + /* + * Declare chunks data type and initialize some of them. + */ + int16 chunk1[3][2] = {1, 1, 1, 1, 1, 1}; + + int16 chunk2[3][2] = {2, 2, 2, 2, 2, 2}; + + int16 chunk3[3][2] = {3, 3, 3, 3, 3, 3}; + + int16 chunk6[3][2] = {6, 6, 6, 6, 6, 6}; + + /********************* End of variable declaration ***********************/ + /* + * Define chunk's dimensions. + * + * In this example we do not use compression. + * To use chunking with RLE, Skipping Huffman, and GZIP + * compression, initialize + * + * c_def.comp.chunk_lengths[0] = 3; + * c_def.comp.chunk_lengths[1] = 2; + * + * To use chunking with NBIT, initialize + * + * c_def.nbit.chunk_lengths[0] = 3; + * c_def.nbit.chunk_lengths[1] = 2; + * + */ + c_def.chunk_lengths[0] = 3; + c_def.chunk_lengths[1] = 2; + + /* + * Create the file and initialize SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_CREATE); + + /* + * Create 9x4 SDS. + */ + dim_sizes[0] = 9; + dim_sizes[1] = 4; + sds_id = SDcreate(sd_id, SDS_NAME, DFNT_INT16, RANK, dim_sizes); + + /* + * Fill the SDS array with the fill value. + */ + status = SDsetfillvalue(sds_id, (VOIDP)&fill_value); + + /* + * Create chunked SDS. + * In this example we do not use compression ( third + * parameter of SDsetchunk is set to HDF_CHUNK). + * + * To use RLE compression, set compression type and flag + * + * c_def.comp.comp_type = COMP_CODE_RLE; + * comp_flag = HDF_CHUNK | HDF_COMP; + * + * To use Skipping Huffman compression, set compression type, flag + * and skipping size skp_size + * + * c_def.comp.comp_type = COMP_CODE_SKPHUFF; + * c_def.comp.cinfo.skphuff.skp_size = value; + * comp_flag = HDF_CHUNK | HDF_COMP; + * + * To use GZIP compression, set compression type, flag and + * deflate level + * + * c_def.comp.comp_type = COMP_CODE_DEFLATE; + * c_def.comp.cinfo.deflate.level = value; + * comp_flag = HDF_CHUNK | HDF_COMP; + * + * To use NBIT compression, set compression flag and + * compression parameters + * + * comp_flag = HDF_CHUNK | HDF_NBIT; + * c_def.nbit.start_bit = value1; + * c_def.nbit.bit_len = value2; + * c_def.nbit.sign_ext = value3; + * c_def.nbit.fill_one = value4; + */ + comp_flag = HDF_CHUNK; + status = SDsetchunk(sds_id, c_def, comp_flag); + + /* + * Set chunk cache to hold maximum of 3 chunks. + */ + maxcache = 3; + flag = 0; + new_maxcache = SDsetchunkcache(sds_id, maxcache, flag); + + /* + * Write chunks using SDwritechunk function. + * Chunks can be written in any order. + */ + + /* + * Write the chunk with the coordinates (0,0). + */ + origin[0] = 0; + origin[1] = 0; + status = SDwritechunk(sds_id, origin, (VOIDP)chunk1); + + /* + * Write the chunk with the coordinates (1,0). + */ + origin[0] = 1; + origin[1] = 0; + status = SDwritechunk(sds_id, origin, (VOIDP)chunk3); + + /* + * Write the chunk with the coordinates (0,1). + */ + origin[0] = 0; + origin[1] = 1; + status = SDwritechunk(sds_id, origin, (VOIDP)chunk2); + + /* + * Write chunk with the coordinates (1,2) using + * SDwritedata function. + */ + start[0] = 6; + start[1] = 2; + edges[0] = 3; + edges[1] = 2; + status = SDwritedata(sds_id, start, NULL, edges, (VOIDP)chunk6); + + /* + * Fill second column in the chunk with the coordinates (1,1) + * using SDwritedata function. + */ + start[0] = 3; + start[1] = 3; + edges[0] = 3; + edges[1] = 1; + status = SDwritedata(sds_id, start, NULL, edges, (VOIDP)column); + + /* + * Fill second row in the chunk with the coordinates (0,2) + * using SDwritedata function. + */ + start[0] = 7; + start[1] = 0; + edges[0] = 1; + edges[1] = 2; + status = SDwritedata(sds_id, start, NULL, edges, (VOIDP)row); + + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + /* + * Reopen the file and access the first data set. + */ + sd_id = SDstart(FILE_NAME, DFACC_READ); + sds_index = 0; + sds_id = SDselect(sd_id, sds_index); + + /* + * Get information about the SDS. Only chunk lengths and compression + * flag can be returned. Compression information is not available if + * NBIT, Skipping Huffman, or GZIP compression is used. + */ + status = SDgetchunkinfo(sds_id, &c_def_out, &c_flags); + if (c_flags == HDF_CHUNK) + printf(" SDS is chunked\nChunk's dimensions %dx%d\n", c_def_out.chunk_lengths[0], + c_def_out.chunk_lengths[1]); + else if (c_flags == (HDF_CHUNK | HDF_COMP)) + printf("SDS is chunked and compressed\nChunk's dimensions %dx%d\n", c_def_out.comp.chunk_lengths[0], + c_def_out.comp.chunk_lengths[1]); + else if (c_flags == (HDF_CHUNK | HDF_NBIT)) + printf("SDS is chunked (NBIT)\nChunk's dimensions %dx%d\n", c_def_out.nbit.chunk_lengths[0], + c_def_out.nbit.chunk_lengths[1]); + + /* + * Read the entire data set using SDreaddata function. + */ + start[0] = 0; + start[1] = 0; + edges[0] = 9; + edges[1] = 4; + status = SDreaddata(sds_id, start, NULL, edges, (VOIDP)all_data); + + /* + * Print out what we have read. + * The following information should be displayed: + * + * SDS is chunked + * Chunk's dimensions 3x2 + * 1 1 2 + * 1 1 2 2 + * 1 1 2 2 + * 3 3 0 4 + * 3 3 0 4 + * 3 3 0 4 + * 0 0 6 6 + * 5 5 6 6 + * 0 0 6 6 + */ + for (j = 0; j < 9; j++) { + for (i = 0; i < 4; i++) + printf(" %d", all_data[j][i]); + printf("\n"); + } + + /* + * Read chunk with the coordinates (2,0) and display it. + */ + origin[0] = 2; + origin[1] = 0; + status = SDreadchunk(sds_id, origin, chunk_out); + printf(" Chunk (2,0) \n"); + for (j = 0; j < 3; j++) { + for (i = 0; i < 2; i++) + printf(" %d", chunk_out[j][i]); + printf("\n"); + } + + /* + * Read chunk with the coordinates (1,1) and display it. + */ + origin[0] = 1; + origin[1] = 1; + status = SDreadchunk(sds_id, origin, chunk_out); + printf(" Chunk (1,1) \n"); + for (j = 0; j < 3; j++) { + for (i = 0; i < 2; i++) + printf(" %d", chunk_out[j][i]); + printf("\n"); + } + + /* The following information is displayed: + * + * Chunk (2,0) + * 0 0 + * 5 5 + * 0 0 + * Chunk (1,1) + * 0 4 + * 0 4 + * 0 4 + */ + + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_compress_sds.c b/HDF4Examples/mfhdf/examples/h4ex_SD_compress_sds.c new file mode 100644 index 0000000000..2408c1913e --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_compress_sds.c @@ -0,0 +1,87 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDScompressed.hdf" +#define SDS_NAME "SDSgzip" +#define X_LENGTH 5 +#define Y_LENGTH 16 +#define RANK 2 + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id; + intn status; + int32 comp_type; /* Compression flag */ + comp_info c_info; /* Compression structure */ + int32 start[2], edges[2], dim_sizes[2]; + int32 data[Y_LENGTH][X_LENGTH]; + int i, j; + + /********************* End of variable declaration ***********************/ + + /* + * Buffer array data and define array dimensions. + */ + for (j = 0; j < Y_LENGTH; j++) { + for (i = 0; i < X_LENGTH; i++) + data[j][i] = (i + j) + 1; + } + dim_sizes[0] = Y_LENGTH; + dim_sizes[1] = X_LENGTH; + + /* + * Create the file and initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_CREATE); + + /* + * Create the data set with the name defined in SDS_NAME. + */ + sds_id = SDcreate(sd_id, SDS_NAME, DFNT_INT32, RANK, dim_sizes); + + /* + * Ininitialize compression structure element and compression + * flag for GZIP compression and call SDsetcompress. + * + * To use the Skipping Huffman compression method, initialize + * comp_type = COMP_CODE_SKPHUFF + * c_info.skphuff.skp_size = value + * + * To use the RLE compression method, initialize + * comp_type = COMP_CODE_RLE + * No structure element needs to be initialized. + */ + comp_type = COMP_CODE_DEFLATE; + c_info.deflate.level = 6; + status = SDsetcompress(sds_id, comp_type, &c_info); + + /* + * Define the location and size of the data set + * to be written to the file. + */ + start[0] = 0; + start[1] = 0; + edges[0] = Y_LENGTH; + edges[1] = X_LENGTH; + + /* + * Write the stored data to the data set. The last argument + * must be explicitly cast to a generic pointer since SDwritedata + * is designed to write generic data. + */ + status = SDwritedata(sds_id, start, NULL, edges, (VOIDP)data); + + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_create_sds.c b/HDF4Examples/mfhdf/examples/h4ex_SD_create_sds.c new file mode 100644 index 0000000000..2a4e1719e4 --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_create_sds.c @@ -0,0 +1,51 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDS.hdf" +#define SDS_NAME "SDStemplate" +#define X_LENGTH 5 +#define Y_LENGTH 16 +#define RANK 2 /* Number of dimensions of the SDS */ + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id; /* SD interface and data set identifiers */ + int32 dim_sizes[2]; /* sizes of the SDS dimensions */ + intn status; /* status returned by some routines; has value + SUCCEED or FAIL */ + + /********************* End of variable declaration ***********************/ + + /* + * Create the file and initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_CREATE); + + /* + * Define the dimensions of the array to be created. + */ + dim_sizes[0] = Y_LENGTH; + dim_sizes[1] = X_LENGTH; + + /* + * Create the data set with the name defined in SDS_NAME. Note that + * DFNT_INT32 indicates that the SDS data is of type int32. Refer to + * Table 2F, "Standard HDF Data Types and Flags," for definitions of + * other types. + */ + sds_id = SDcreate(sd_id, SDS_NAME, DFNT_INT32, RANK, dim_sizes); + + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_dimscale_vs_sds.c b/HDF4Examples/mfhdf/examples/h4ex_SD_dimscale_vs_sds.c new file mode 100644 index 0000000000..c1351da955 --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_dimscale_vs_sds.c @@ -0,0 +1,58 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDS.hdf" + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id, sds_index; + intn status; + int32 rank, data_type, dim_sizes[H4_MAX_VAR_DIMS]; + int32 n_datasets, n_file_attr, n_attrs; + char sds_name[H4_MAX_NC_NAME]; + + /********************* End of variable declaration ***********************/ + + /* + * Open the file and initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_READ); + + /* + * Obtain information about the file. + */ + status = SDfileinfo(sd_id, &n_datasets, &n_file_attr); + + /* Get information about each SDS in the file. + * Check whether it is a coordinate variable, then display retrieved + * information. + * Output displayed: + * + * SDS array with the name SDStemplate + * Coordinate variable with the name Y_Axis + * Coordinate variable with the name X_Axis + * + */ + for (sds_index = 0; sds_index < n_datasets; sds_index++) { + sds_id = SDselect(sd_id, sds_index); + status = SDgetinfo(sds_id, sds_name, &rank, dim_sizes, &data_type, &n_attrs); + if (SDiscoordvar(sds_id)) + printf(" Coordinate variable with the name %s\n", sds_name); + else + printf(" SDS array with the name %s\n", sds_name); + + /* + * Terminate access to the selected data set. + */ + status = SDendaccess(sds_id); + } + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_find_sds_by_name.c b/HDF4Examples/mfhdf/examples/h4ex_SD_find_sds_by_name.c new file mode 100644 index 0000000000..4cd7a85023 --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_find_sds_by_name.c @@ -0,0 +1,78 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDS.hdf" +#define SDS_NAME "SDStemplate" +#define WRONG_NAME "WrongName" +#define X_LENGTH 5 +#define Y_LENGTH 16 + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id, sds_index; + intn status; + int32 start[2], edges[2]; + int32 data[Y_LENGTH][X_LENGTH]; + int j; + + /********************* End of variable declaration ***********************/ + + /* + * Open the file for reading and initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_READ); + + /* + * Find index of the data set with the name specified in WRONG_NAME. + * Error condition occurs, since the data set with that name does not exist + * in the file. + */ + sds_index = SDnametoindex(sd_id, WRONG_NAME); + if (sds_index == FAIL) + printf("Data set with the name \"WrongName\" does not exist\n"); + + /* + * Find index of the data set with the name specified in SDS_NAME and use + * the index to select the data set. + */ + sds_index = SDnametoindex(sd_id, SDS_NAME); + sds_id = SDselect(sd_id, sds_index); + + /* + * Set elements of the array start to 0, elements of the array edges to + * SDS dimensions, and use NULL for stride argument in SDreaddata to read + * the entire data. + */ + start[0] = 0; + start[1] = 0; + edges[0] = Y_LENGTH; + edges[1] = X_LENGTH; + + /* + * Read the entire data into the buffer named data. + */ + status = SDreaddata(sds_id, start, NULL, edges, (VOIDP)data); + + /* + * Print 10th row; the following numbers should be displayed: + * + * 10 1000 12 13 14 + */ + for (j = 0; j < X_LENGTH; j++) + printf("%d ", data[9][j]); + printf("\n"); + + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_get_attr.c b/HDF4Examples/mfhdf/examples/h4ex_SD_get_attr.c new file mode 100644 index 0000000000..0ca5c103b8 --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_get_attr.c @@ -0,0 +1,144 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDS.hdf" +#define FILE_ATTR_NAME "File_contents" +#define SDS_ATTR_NAME "Valid_range" +#define DIM_ATTR_NAME "Dim_metric" + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id, dim_id; + intn status; + int32 attr_index, data_type, n_values; + char attr_name[H4_MAX_NC_NAME]; + int8 *file_data; + int8 *dim_data; + float32 *sds_data; + int i; + + /********************* End of variable declaration ***********************/ + + /* + * Open the file and initialize SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_READ); + + /* + * Find the file attribute defined by FILE_ATTR_NAME. + */ + attr_index = SDfindattr(sd_id, FILE_ATTR_NAME); + + /* + * Get information about the file attribute. Note that the first + * parameter is an SD interface identifier. + */ + status = SDattrinfo(sd_id, attr_index, attr_name, &data_type, &n_values); + + /* + * Allocate a buffer to hold the attribute data. + */ + file_data = (int8 *)malloc(n_values * sizeof(data_type)); + + /* + * Read the file attribute data. + */ + status = SDreadattr(sd_id, attr_index, file_data); + + /* + * Print out file attribute value. + */ + printf("File attribute value is : %s\n", file_data); + + /* + * Select the first data set. + */ + sds_id = SDselect(sd_id, 0); + + /* + * Find the data set attribute defined by SDS_ATTR_NAME. Note that the + * first parameter is a data set identifier. + */ + attr_index = SDfindattr(sds_id, SDS_ATTR_NAME); + + /* + * Get information about the data set attribute. + */ + status = SDattrinfo(sds_id, attr_index, attr_name, &data_type, &n_values); + + /* + * Allocate a buffer to hold the data set attribute data. + */ + sds_data = (float32 *)malloc(n_values * sizeof(data_type)); + + /* + * Read the SDS attribute data. + */ + status = SDreadattr(sds_id, attr_index, sds_data); + + /* + * Print out SDS attribute data type and values. + */ + if (data_type == DFNT_FLOAT32) + printf("SDS attribute data type is : float32\n"); + printf("SDS attribute values are : "); + for (i = 0; i < n_values; i++) + printf(" %f", sds_data[i]); + printf("\n"); + + /* + * Get the identifier for the second dimension of the SDS. + */ + dim_id = SDgetdimid(sds_id, 1); + + /* + * Find dimension attribute defined by DIM_ATTR_NAME. + */ + attr_index = SDfindattr(dim_id, DIM_ATTR_NAME); + + /* + * Get information about the dimension attribute. + */ + status = SDattrinfo(dim_id, attr_index, attr_name, &data_type, &n_values); + + /* + * Allocate a buffer to hold the dimension attribute data. + */ + dim_data = (int8 *)malloc(n_values * sizeof(data_type)); + + /* + * Read the dimension attribute data. + */ + status = SDreadattr(dim_id, attr_index, dim_data); + + /* + * Print out dimension attribute value. + */ + printf("Dimensional attribute values is : %s\n", dim_data); + + /* + * Terminate access to the data set and to the SD interface and + * close the file. + */ + status = SDendaccess(sds_id); + status = SDend(sd_id); + + /* + * Free all buffers. + */ + free(dim_data); + free(sds_data); + free(file_data); + + /* Output of this program is : + * + * File attribute value is : Storm_track_data + * SDS attribute data type is : float32 + * SDS attribute values are : 2.000000 10.000000 + * Dimensional attribute values is : Seconds + */ + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_get_info.c b/HDF4Examples/mfhdf/examples/h4ex_SD_get_info.c new file mode 100644 index 0000000000..dd072d0051 --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_get_info.c @@ -0,0 +1,67 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDS.hdf" + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id; + intn status; + int32 n_datasets, n_file_attrs, index; + int32 dim_sizes[H4_MAX_VAR_DIMS]; + int32 rank, data_type, n_attrs; + char name[H4_MAX_NC_NAME]; + int i; + + /********************* End of variable declaration ***********************/ + + /* + * Open the file and initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_READ); + + /* + * Determine the number of data sets in the file and the number + * of file attributes. + */ + status = SDfileinfo(sd_id, &n_datasets, &n_file_attrs); + + /* + * Access every data set and print its name, rank, dimension sizes, + * data type, and number of attributes. + * The following information should be displayed: + * + * name = SDStemplate + * rank = 2 + * dimension sizes are : 16 5 + * data type is 24 + * number of attributes is 0 + */ + for (index = 0; index < n_datasets; index++) { + sds_id = SDselect(sd_id, index); + status = SDgetinfo(sds_id, name, &rank, dim_sizes, &data_type, &n_attrs); + + printf("name = %s\n", name); + printf("rank = %d\n", rank); + printf("dimension sizes are : "); + for (i = 0; i < rank; i++) + printf("%d ", dim_sizes[i]); + printf("\n"); + printf("data type is %d\n", data_type); + printf("number of attributes is %d\n", n_attrs); + + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + } + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_mv_sds_to_external.c b/HDF4Examples/mfhdf/examples/h4ex_SD_mv_sds_to_external.c new file mode 100644 index 0000000000..a12c5a50e5 --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_mv_sds_to_external.c @@ -0,0 +1,42 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDS.hdf" +#define EXT_FILE_NAME "ExternalSDS" +#define OFFSET 24 + +int +main() +{ + + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id, sds_index; + intn status; + + /********************* End of variable declaration ***********************/ + + /* + * Open the file and initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_WRITE); + + /* + * Select the first data set. + */ + sds_index = 0; + sds_id = SDselect(sd_id, sds_index); + + /* + * Create a file with the name EXT_FILE_NAME and move the data set + * values into it, starting at byte location OFFSET. + */ + status = SDsetexternalfile(sds_id, EXT_FILE_NAME, OFFSET); + + /* + * Terminate access to the data set, SD interface, and file. + */ + status = SDendaccess(sds_id); + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_read_from_sds.c b/HDF4Examples/mfhdf/examples/h4ex_SD_read_from_sds.c new file mode 100644 index 0000000000..73e707af1d --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_read_from_sds.c @@ -0,0 +1,66 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDS.hdf" +#define X_LENGTH 5 +#define Y_LENGTH 16 + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id, sds_index; + intn status; + int32 start[2], edges[2]; + int32 data[Y_LENGTH][X_LENGTH]; + int j; + + /********************* End of variable declaration ***********************/ + + /* + * Open the file for reading and initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_READ); + + /* + * Select the first data set. + */ + sds_index = 0; + sds_id = SDselect(sd_id, sds_index); + + /* + * Set elements of array start to 0, elements of array edges + * to SDS dimensions,and use NULL for the argument stride in SDreaddata + * to read the entire data. + */ + start[0] = 0; + start[1] = 0; + edges[0] = Y_LENGTH; + edges[1] = X_LENGTH; + + /* + * Read entire data into data array. + */ + status = SDreaddata(sds_id, start, NULL, edges, (VOIDP)data); + + /* + * Print 10th row; the following numbers should be displayed. + * + * 10 1000 12 13 14 + */ + for (j = 0; j < X_LENGTH; j++) + printf("%d ", data[9][j]); + printf("\n"); + + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_read_subsets.c b/HDF4Examples/mfhdf/examples/h4ex_SD_read_subsets.c new file mode 100644 index 0000000000..b6f3850383 --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_read_subsets.c @@ -0,0 +1,131 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDS.hdf" +#define SUB1_LENGTH 5 +#define SUB2_LENGTH 4 +#define SUB3_LENGTH1 2 +#define SUB3_LENGTH2 3 + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id, sds_index; + intn status; + int32 start[2], edges[2], stride[2]; + int32 sub1_data[SUB1_LENGTH]; + int32 sub2_data[SUB2_LENGTH]; + int32 sub3_data[SUB3_LENGTH2][SUB3_LENGTH1]; + int i, j; + + /********************* End of variable declaration ***********************/ + + /* + * Open the file for reading and initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_READ); + + /* + * Select the first data set. + */ + sds_index = 0; + sds_id = SDselect(sd_id, sds_index); + /* + * Reading the first subset. + * + * Set elements of start, edges, and stride arrays to read + * every 3rd element in the 2nd column starting at 4th row. + */ + start[0] = 3; /* 4th row */ + start[1] = 1; /* 2nd column */ + edges[0] = SUB1_LENGTH; /* SUB1_LENGTH elements are read along 2nd column*/ + edges[1] = 1; + stride[0] = 3; /* every 3rd element is read along 2nd column */ + stride[1] = 1; + + /* + * Read the data from the file into sub1_data array. + */ + status = SDreaddata(sds_id, start, stride, edges, (VOIDP)sub1_data); + + /* + * Print what we have just read; the following numbers should be displayed: + * + * 5 8 1000 14 17 + */ + for (j = 0; j < SUB1_LENGTH; j++) + printf("%d ", sub1_data[j]); + printf("\n"); + + /* + * Reading the second subset. + * + * Set elements of start and edges arrays to read + * first 4 elements of the 10th row. + */ + start[0] = 9; /* 10th row */ + start[1] = 0; /* 1st column */ + edges[0] = 1; + edges[1] = SUB2_LENGTH; /* SUB2_LENGTH elements are read along 10th row */ + + /* + * Read data from the file into sub2_data array. Note that the third + * parameter is set to NULL for contiguous reading. + */ + status = SDreaddata(sds_id, start, NULL, edges, (VOIDP)sub2_data); + + /* + * Print what we have just read; the following numbers should be displayed: + * + * 10 1000 12 13 + */ + for (j = 0; j < SUB2_LENGTH; j++) + printf("%d ", sub2_data[j]); + printf("\n"); + + /* + * Reading the third subset. + * + * Set elements of the arrays start, edges, and stride to read + * every 6th element in the column and 4th element in the row + * starting at 1st column, 3d row. + */ + start[0] = 2; /* 3d row */ + start[1] = 0; /* 1st column */ + edges[0] = SUB3_LENGTH2; /* SUB3_LENGTH2 elements are read along + each column */ + edges[1] = SUB3_LENGTH1; /* SUB3_LENGTH1 elements are read along + each row */ + stride[0] = 6; /* read every 6th element along each column */ + stride[1] = 4; /* read every 4th element along each row */ + + /* + * Read the data from the file into sub3_data array. + */ + status = SDreaddata(sds_id, start, stride, edges, (VOIDP)sub3_data); + + /* + * Print what we have just read; the following numbers should be displayed: + * + * 3 7 + * 9 13 + * 15 19 + */ + for (j = 0; j < SUB3_LENGTH2; j++) { + for (i = 0; i < SUB3_LENGTH1; i++) + printf("%d ", sub3_data[j][i]); + printf("\n"); + } + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_set_attr.c b/HDF4Examples/mfhdf/examples/h4ex_SD_set_attr.c new file mode 100644 index 0000000000..af38830b02 --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_set_attr.c @@ -0,0 +1,74 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDS.hdf" +#define FILE_ATTR_NAME "File_contents" +#define SDS_ATTR_NAME "Valid_range" +#define DIM_ATTR_NAME "Dim_metric" + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id, sds_index; + intn status; + int32 dim_id, dim_index; + int32 n_values; /* number of values of the file, SDS or + dimension attribute */ + char8 file_values[] = "Storm_track_data"; + /* values of the file attribute */ + float32 sds_values[2] = {2., 10.}; + /* values of the SDS attribute */ + char8 dim_values[] = "Seconds"; + /* values of the dimension attribute */ + + /********************* End of variable declaration ***********************/ + + /* + * Open the file and initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_WRITE); + + /* + * Set an attribute that describes the file contents. + */ + n_values = 16; + status = SDsetattr(sd_id, FILE_ATTR_NAME, DFNT_CHAR8, n_values, (VOIDP)file_values); + + /* + * Select the first data set. + */ + sds_index = 0; + sds_id = SDselect(sd_id, sds_index); + + /* + * Assign attribute to the first SDS. Note that attribute values + * may have different data type than SDS data. + */ + n_values = 2; + status = SDsetattr(sds_id, SDS_ATTR_NAME, DFNT_FLOAT32, n_values, (VOIDP)sds_values); + + /* + * Get the the second dimension identifier of the SDS. + */ + dim_index = 1; + dim_id = SDgetdimid(sds_id, dim_index); + + /* + * Set an attribute of the dimension that specifies the dimension metric. + */ + n_values = 7; + status = SDsetattr(dim_id, DIM_ATTR_NAME, DFNT_CHAR8, n_values, (VOIDP)dim_values); + + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_set_get_dim_info.c b/HDF4Examples/mfhdf/examples/h4ex_SD_set_get_dim_info.c new file mode 100644 index 0000000000..0ec9618038 --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_set_get_dim_info.c @@ -0,0 +1,152 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDS.hdf" +#define SDS_NAME "SDStemplate" +#define DIM_NAME_X "X_Axis" +#define DIM_NAME_Y "Y_Axis" +#define NAME_LENGTH 6 +#define X_LENGTH 5 +#define Y_LENGTH 16 +#define RANK 2 + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id, sds_index; + intn status; + int32 dim_index, dim_id; + int32 n_values, data_type, n_attrs; + int16 data_X[X_LENGTH]; /* X dimension dimension scale */ + int16 data_X_out[X_LENGTH]; + float64 data_Y[Y_LENGTH]; /* Y dimension dimension scale */ + float64 data_Y_out[Y_LENGTH]; + char dim_name[NAME_LENGTH + 1]; + int i, j, nrow; + + /********************* End of variable declaration ***********************/ + + /* + * Initialize dimension scales. + */ + for (i = 0; i < X_LENGTH; i++) + data_X[i] = i; + for (i = 0; i < Y_LENGTH; i++) + data_Y[i] = 0.1 * i; + + /* + * Open the file and initialize SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_WRITE); + + /* + * Get the index of the data set specified in SDS_NAME. + */ + sds_index = SDnametoindex(sd_id, SDS_NAME); + + /* + * Select the data set corresponding to the returned index. + */ + sds_id = SDselect(sd_id, sds_index); + + /* For each dimension of the data set specified in SDS_NAME, + * get its dimension identifier and set dimension name + * and dimension scale. Note that data type of dimension scale + * can be different between dimensions and can be different from + * SDS data type. + */ + for (dim_index = 0; dim_index < RANK; dim_index++) { + /* + * Select the dimension at position dim_index. + */ + dim_id = SDgetdimid(sds_id, dim_index); + + /* + * Assign name and dimension scale to selected dimension. + */ + switch (dim_index) { + case 0: + status = SDsetdimname(dim_id, DIM_NAME_Y); + n_values = Y_LENGTH; + status = SDsetdimscale(dim_id, n_values, DFNT_FLOAT64, (VOIDP)data_Y); + break; + case 1: + status = SDsetdimname(dim_id, DIM_NAME_X); + n_values = X_LENGTH; + status = SDsetdimscale(dim_id, n_values, DFNT_INT16, (VOIDP)data_X); + break; + default: + break; + } + + /* + * Get and display info about the dimension and its scale values. + * The following information is displayed: + * + * Information about 1 dimension: + * dimension name is Y_Axis + * number of scale values is 16 + * dimension scale data type is float64 + * number of dimension attributes is 0 + * + * Scale values are : + * 0.000 0.100 0.200 0.300 + * 0.400 0.500 0.600 0.700 + * 0.800 0.900 1.000 1.100 + * 1.200 1.300 1.400 1.500 + * + * Information about 2 dimension: + * dimension name is X_Axis + * number of scale values is 5 + * dimension scale data type is int16 + * number of dimension attributes is 0 + * + * Scale values are : + * 0 1 2 3 4 + */ + + status = SDdiminfo(dim_id, dim_name, &n_values, &data_type, &n_attrs); + printf("Information about %d dimension:\n", dim_index + 1); + printf("dimension name is %s\n", dim_name); + printf("number of scale values is %d\n", n_values); + if (data_type == DFNT_FLOAT64) + printf("dimension scale data type is float64\n"); + if (data_type == DFNT_INT16) + printf("dimension scale data type is int16\n"); + printf("number of dimension attributes is %d\n", n_attrs); + printf("\n"); + printf("Scale values are :\n"); + switch (dim_index) { + case 0: + status = SDgetdimscale(dim_id, (VOIDP)data_Y_out); + nrow = 4; + for (i = 0; i < n_values / nrow; i++) { + for (j = 0; j < nrow; j++) + printf(" %-6.3f", data_Y_out[i * nrow + j]); + printf("\n"); + } + break; + case 1: + status = SDgetdimscale(dim_id, (VOIDP)data_X_out); + for (i = 0; i < n_values; i++) + printf(" %d", data_X_out[i]); + break; + default: + break; + } + printf("\n"); + } /*for dim_index */ + + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_unlimited_sds.c b/HDF4Examples/mfhdf/examples/h4ex_SD_unlimited_sds.c new file mode 100644 index 0000000000..05c006015c --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_unlimited_sds.c @@ -0,0 +1,118 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDSUNLIMITED.hdf" +#define SDS_NAME "AppendableData" +#define X_LENGTH 10 +#define Y_LENGTH 10 +#define RANK 2 + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id, sds_index; + intn status; + int32 dim_sizes[2]; + int32 data[Y_LENGTH][X_LENGTH], append_data[X_LENGTH]; + int32 start[2], edges[2]; + int i, j; + + /********************* End of variable declaration ***********************/ + + /* + * Data initialization. + */ + for (j = 0; j < Y_LENGTH; j++) { + for (i = 0; i < X_LENGTH; i++) + data[j][i] = (i + 1) + (j + 1); + } + + /* + * Create the file and initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_CREATE); + + /* + * Define dimensions of the array. Make the first dimension + * appendable by defining its length to be unlimited. + */ + dim_sizes[0] = SD_UNLIMITED; + dim_sizes[1] = X_LENGTH; + + /* + * Create the array data set. + */ + sds_id = SDcreate(sd_id, SDS_NAME, DFNT_INT32, RANK, dim_sizes); + + /* + * Define the location and the size of the data to be written + * to the data set. + */ + start[0] = start[1] = 0; + edges[0] = Y_LENGTH; + edges[1] = X_LENGTH; + + /* + * Write the data. + */ + status = SDwritedata(sds_id, start, NULL, edges, (VOIDP)data); + + /* + * Terminate access to the array data set, terminate access + * to the SD interface, and close the file. + */ + status = SDendaccess(sds_id); + status = SDend(sd_id); + + /* + * Store the array values to be appended to the data set. + */ + for (i = 0; i < X_LENGTH; i++) + append_data[i] = 1000 + i; + + /* + * Reopen the file and initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_WRITE); + + /* + * Select the first data set. + */ + sds_index = 0; + sds_id = SDselect(sd_id, sds_index); + + /* + * Check if selected SDS is unlimited. If it is not, then terminate access + * to the SD interface and close the file. + */ + if (SDisrecord(sds_id)) { + + /* + * Define the location of the append to start at the first column + * of the 11th row of the data set and to stop at the end of the + * eleventh row. + */ + start[0] = Y_LENGTH; + start[1] = 0; + edges[0] = 1; + edges[1] = X_LENGTH; + + /* + * Append data to the data set. + */ + status = SDwritedata(sds_id, start, NULL, edges, (VOIDP)append_data); + } + + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_write_slab.c b/HDF4Examples/mfhdf/examples/h4ex_SD_write_slab.c new file mode 100644 index 0000000000..578adfec6c --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_write_slab.c @@ -0,0 +1,92 @@ +#include "mfhdf.h" + +#define FILE_NAME "SLABS.hdf" +#define SDS_NAME "FilledBySlabs" +#define X_LENGTH 4 +#define Y_LENGTH 5 +#define Z_LENGTH 6 +#define RANK 3 + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id; + intn status; + int32 dim_sizes[3], start[3], edges[3]; + int32 data[Z_LENGTH][Y_LENGTH][X_LENGTH]; + int32 zx_data[Z_LENGTH][X_LENGTH]; + int i, j, k; + + /********************* End of variable declaration ***********************/ + + /* + * Data initialization. + */ + for (k = 0; k < Z_LENGTH; k++) + for (j = 0; j < Y_LENGTH; j++) + for (i = 0; i < X_LENGTH; i++) + data[k][j][i] = (i + 1) + (j + 1) + (k + 1); + + /* + * Create the file and initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_CREATE); + + /* + * Define dimensions of the array to be created. + */ + dim_sizes[0] = Z_LENGTH; + dim_sizes[1] = Y_LENGTH; + dim_sizes[2] = X_LENGTH; + + /* + * Create the array with the name defined in SDS_NAME. + */ + sds_id = SDcreate(sd_id, SDS_NAME, DFNT_INT32, RANK, dim_sizes); + + /* + * Set the parameters start and edges to write + * a 6x4 element slab of data to the data set; note + * that edges[1] is set to 1 to define a 2-dimensional slab + * parallel to the ZX plane. + * start[1] (slab position in the array) is initialized inside + * the for loop. + */ + edges[0] = Z_LENGTH; + edges[1] = 1; + edges[2] = X_LENGTH; + start[0] = start[2] = 0; + for (j = 0; j < Y_LENGTH; j++) { + start[1] = j; + + /* + * Initialize zx_data buffer (data slab). + */ + for (k = 0; k < Z_LENGTH; k++) { + for (i = 0; i < X_LENGTH; i++) { + zx_data[k][i] = data[k][j][i]; + } + } + + /* + * Write the data slab into the SDS array defined in SDS_NAME. + * Note that the 3rd parameter is NULL which indicates that consecutive + * slabs in the Y direction are written. + */ + status = SDwritedata(sds_id, start, NULL, edges, (VOIDP)zx_data); + } + + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/h4ex_SD_write_to_sds.c b/HDF4Examples/mfhdf/examples/h4ex_SD_write_to_sds.c new file mode 100644 index 0000000000..ba4fa6f47b --- /dev/null +++ b/HDF4Examples/mfhdf/examples/h4ex_SD_write_to_sds.c @@ -0,0 +1,66 @@ +#include "mfhdf.h" + +#define FILE_NAME "SDS.hdf" +#define X_LENGTH 5 +#define Y_LENGTH 16 + +int +main() +{ + /************************* Variable declaration **************************/ + + int32 sd_id, sds_id, sds_index; + intn status; + int32 start[2], edges[2]; + int32 data[Y_LENGTH][X_LENGTH]; + int i, j; + + /********************* End of variable declaration ***********************/ + + /* + * Data set data initialization. + */ + for (j = 0; j < Y_LENGTH; j++) { + for (i = 0; i < X_LENGTH; i++) + data[j][i] = (i + j) + 1; + } + + /* + * Open the file and initialize the SD interface. + */ + sd_id = SDstart(FILE_NAME, DFACC_WRITE); + + /* + * Attach to the first data set. + */ + sds_index = 0; + sds_id = SDselect(sd_id, sds_index); + + /* + * Define the location and size of the data to be written to the data set. + */ + start[0] = 0; + start[1] = 0; + edges[0] = Y_LENGTH; + edges[1] = X_LENGTH; + + /* + * Write the stored data to the data set. The third argument is set to NULL + * to specify contiguous data elements. The last argument must + * be explicitly cast to a generic pointer since SDwritedata is designed + * to write generic data. + */ + status = SDwritedata(sds_id, start, NULL, edges, (VOIDP)data); + + /* + * Terminate access to the data set. + */ + status = SDendaccess(sds_id); + + /* + * Terminate access to the SD interface and close the file. + */ + status = SDend(sd_id); + + return 0; +} diff --git a/HDF4Examples/mfhdf/examples/testexamples.sh.in b/HDF4Examples/mfhdf/examples/testexamples.sh.in new file mode 100644 index 0000000000..f3bd51e968 --- /dev/null +++ b/HDF4Examples/mfhdf/examples/testexamples.sh.in @@ -0,0 +1,18 @@ +# This test script only runs all the examples right now. It needs +# a lot of work. It should use h4cc to build the examples too. +./create_sds +./write_to_sds +./write_slab +./read_from_sds +./alter_sds_values +./chunking_example +./compress_sds +./dimscale_vs_sds +./find_sds_by_name +./set_attr +./get_attr +./get_info +./mv_sds_to_external +./read_subsets +./set_get_dim_info +./unlimited_sds diff --git a/HDF4Examples/mfhdf/fortran/CMakeLists.txt b/HDF4Examples/mfhdf/fortran/CMakeLists.txt new file mode 100644 index 0000000000..12562bd8a3 --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/CMakeLists.txt @@ -0,0 +1,84 @@ +cmake_minimum_required (VERSION 3.12) +project (HDF4Examples_MFHDF_FORTRAN Fortran) +# -------------------------------------------------------------------- +# Notes: When creating examples they should be prefixed +# with "f_ex_". This allows for easier filtering of the examples. +# -------------------------------------------------------------------- + +if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0) + set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch") +endif () + +#----------------------------------------------------------------------------- +# Setup include Directories +#----------------------------------------------------------------------------- +INCLUDE_DIRECTORIES ( + ${CMAKE_Fortran_MODULE_DIRECTORY}${HDF_MOD_EXT} + ${PROJECT_BINARY_DIR} + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} +) + +#----------------------------------------------------------------------------- +# Define Sources +#----------------------------------------------------------------------------- +include (Fortran_sourcefiles.cmake) + +if (H4EX_BUILD_TESTING) + # Remove any output file left over from previous test run + add_test ( + NAME MFHDF_FORTRAN_EXAMPLES-clearall-objects + COMMAND ${CMAKE_COMMAND} + -E remove + SDS.hdf + SDSchunked.hdf + SDScompressed.hdf + SDSUNLIMITED.hdf + SLABS.hdf + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (MFHDF_FORTRAN_EXAMPLES-clearall-objects PROPERTIES DEPENDS ${last_test} LABELS ${PROJECT_NAME}) + else () + set_tests_properties (MFHDF_FORTRAN_EXAMPLES-clearall-objects PROPERTIES LABELS ${PROJECT_NAME}) + endif () + set (last_test "MFHDF_FORTRAN_EXAMPLES-clearall-objects") +endif () + +foreach (example ${examples}) + get_filename_component(example_name ${example} NAME_WE) + add_executable (f_exmf_${example_name} ${PROJECT_SOURCE_DIR}/${example}) + set_target_properties (f_exmf_${example_name} PROPERTIES LINKER_LANGUAGE Fortran) + target_link_libraries (f_exmf_${example_name} ${H4EX_HDF4_LINK_LIBS}) + if (BUILD_TESTING) + add_test ( + NAME f_exmftest_${example_name} + COMMAND "${CMAKE_COMMAND}" + -D "TEST_PROGRAM=$<TARGET_FILE:f_exmf_${example_name}>" + -D "TEST_ARGS:STRING=" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" + -D "TEST_EXPECT=0" + -D "TEST_SKIP_COMPARE=TRUE" + -D "TEST_OUTPUT=${testname}.out" + -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}" + -P "${HDF4EX_RESOURCES_DIR}/runTest.cmake" + ) + if (NOT "${last_test}" STREQUAL "") + set_tests_properties (f_exmftest_${example_name} PROPERTIES DEPENDS ${last_test} LABELS ${PROJECT_NAME}) + else () + set_tests_properties (f_exmftest_${example_name} PROPERTIES LABELS ${PROJECT_NAME}) + endif () + set (last_test "f_exmftest_${example_name}") + endif () +endforeach () + +foreach (example ${skip_examples}) + get_filename_component(example_name ${example} NAME_WE) + add_executable (f_exmf_${example_name} ${PROJECT_SOURCE_DIR}/${example}) + set_target_properties (f_exmf_${example_name} PROPERTIES LINKER_LANGUAGE Fortran) + target_link_libraries (f_exmf_${example_name} ${H4EX_HDF4_LINK_LIBS}) + if (BUILD_TESTING) + add_test ( + NAME f_exmftest_${example_name} + COMMAND ${CMAKE_COMMAND} -E echo "SKIP f_exmftest_${example_name}" + ) + endif () +endforeach () diff --git a/HDF4Examples/mfhdf/fortran/Fortran_sourcefiles.cmake b/HDF4Examples/mfhdf/fortran/Fortran_sourcefiles.cmake new file mode 100644 index 0000000000..b941a2b0f7 --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/Fortran_sourcefiles.cmake @@ -0,0 +1,26 @@ +#----------------------------------------------------------------------------- +# Define Sources, one file per application +#----------------------------------------------------------------------------- +set (examples + h4ex_SD_create_sds.f + h4ex_SD_write_to_sds.f + h4ex_SD_write_slab.f + h4ex_SD_alter_sds_values.f + h4ex_SD_unlimited_sds.f + h4ex_SD_mv_sds_to_external.f + h4ex_SD_read_from_sds.f + h4ex_SD_read_subsets.f + #h4ex_SD_get_info.f + h4ex_SD_find_sds_by_name.f + h4ex_SD_set_get_dim_info.f + #h4ex_SD_dimscale_vs_sds.f + h4ex_SD_set_attr.f + #h4ex_SD_get_attr.f + h4ex_SD_compress_sds.f + h4ex_SD_chunking_example.f +) +set (skip_examples + h4ex_SD_get_info.f + h4ex_SD_dimscale_vs_sds.f + h4ex_SD_get_attr.f +) diff --git a/HDF4Examples/mfhdf/fortran/Makefile.am b/HDF4Examples/mfhdf/fortran/Makefile.am new file mode 100644 index 0000000000..f0b7206c90 --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/Makefile.am @@ -0,0 +1,55 @@ +############################################################################# +## Setup for building programs ## +############################################################################# + +include $(top_srcdir)/config/commence.am + +DEFINES=-DNDEBUG -DHDF + +############################################################################# +## Programs to build ## +############################################################################# + +# These are the Fortran test programs to build. +TEST_PROG=h4ex_SD_create_sds h4ex_SD_write_to_sds h4ex_SD_write_slab h4ex_SD_alter_sds_values h4ex_SD_unlimited_sds \ + h4ex_SD_mv_sds_to_external h4ex_SD_read_from_sds h4ex_SD_read_subsets h4ex_SD_get_info \ + h4ex_SD_find_sds_by_name h4ex_SD_set_get_dim_info h4ex_SD_dimscale_vs_sds h4ex_SD_set_attr \ + h4ex_SD_get_attr h4ex_SD_compress_sds h4ex_SD_chunking_example + +# These are the Fortran example files to be installed +INSTALL_FILES=h4ex_SD_create_sds.f h4ex_SD_write_to_sds.f h4ex_SD_write_slab.f h4ex_SD_alter_sds_values.f \ + h4ex_SD_unlimited_sds.f h4ex_SD_mv_sds_to_external.f h4ex_SD_read_from_sds.f h4ex_SD_read_subsets.f \ + h4ex_SD_get_info.f h4ex_SD_find_sds_by_name.f h4ex_SD_set_get_dim_info.f h4ex_SD_dimscale_vs_sds.f \ + h4ex_SD_set_attr.f h4ex_SD_get_attr.f h4ex_SD_compress_sds.f h4ex_SD_chunking_example.f + +# Where to install example files +EXAMPLEDIR=$(prefix)/examples/fortran + +# How to build Fortran programs using h4fc +$(EXTRA_PROG): $(H4FC) + $(H4FC) $(H4FCFLAGS) $(FCFLAGS) -o $@ $(srcdir)/$@.f; + +# List dependencies for each program. Normally, automake would take +# care of this for us, but if we tell automake about the programs it +# will try to build them with the normal Fortran compiler, not h4fc. +h4ex_SD_create_sds: $(srcdir)/h4ex_SD_create_sds.f +h4ex_SD_write_to_sds: $(srcdir)/h4ex_SD_write_to_sds.f +h4ex_SD_write_slab: $(srcdir)/h4ex_SD_write_slab.f +h4ex_SD_alter_sds_values: $(srcdir)/h4ex_SD_alter_sds_values.f +h4ex_SD_unlimited_sds: $(srcdir)/h4ex_SD_unlimited_sds.f +h4ex_SD_mv_sds_to_external: $(srcdir)/h4ex_SD_mv_sds_to_external.f +h4ex_SD_read_from_sds: $(srcdir)/h4ex_SD_read_from_sds.f +h4ex_SD_read_subsets: $(srcdir)/h4ex_SD_read_subsets.f +h4ex_SD_get_info: $(srcdir)/h4ex_SD_get_info.f +h4ex_SD_find_sds_by_name: $(srcdir)/h4ex_SD_find_sds_by_name.f +h4ex_SD_set_get_dim_info: $(srcdir)/h4ex_SD_set_get_dim_info.f +h4ex_SD_dimscale_vs_sds: $(srcdir)/h4ex_SD_dimscale_vs_sds.f +h4ex_SD_set_attr: $(srcdir)/h4ex_SD_set_attr.f +h4ex_SD_get_attr: $(srcdir)/h4ex_SD_get_attr.f +h4ex_SD_compress_sds: $(srcdir)/h4ex_SD_compress_sds.f +h4ex_SD_chunking_example: $(srcdir)/h4ex_SD_chunking_example.f + +include $(top_srcdir)/config/examples.am +include $(top_srcdir)/config/conclude.am + +DISTCLEANFILES = *.chkexe *.chklog ExternalSDS diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_alter_sds_values.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_alter_sds_values.f new file mode 100644 index 0000000000..8233885c5b --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_alter_sds_values.f @@ -0,0 +1,71 @@ + program alter_data + implicit none +C +C Parameter declaration. +C + character*7 FILE_NAME + integer DFACC_WRITE + parameter (FILE_NAME = 'SDS.hdf', + + DFACC_WRITE = 2) +C +C Function declaration. +C + integer sfstart, sfselect, sfwdata, sfendacc, sfend +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, sds_index + integer start(2), edges(2), stride(2) + integer status + integer new_data(2) +C +C**** End of variable declaration ************************************ +C + +C +C Open the file and initialize the SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_WRITE) +C +C Select the first data set. +C + sds_index = 0 + sds_id = sfselect(sd_id, sds_index) + +C +C Initialize the start, edge, and stride parameters to write +C two elements into 2nd row, 10th column and 11th column places. +C +C Specify 2nd row. +C + start(1) = 1 +C +C Specify 10th column. +C + start(2) = 9 + edges(1) = 1 +C +C Two elements are written along 2nd row. +C + edges(2) = 2 + stride(1) = 1 + stride(2) = 1 +C +C Initialize the new values to be written. +C + new_data(1) = 1000 + new_data(2) = 1000 +C +C Write the new values. +C + status = sfwdata(sds_id, start, stride, edges, new_data) +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_chunking_example.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_chunking_example.f new file mode 100644 index 0000000000..8266dfc55c --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_chunking_example.f @@ -0,0 +1,289 @@ + program chunk_examples + implicit none +C +C Parameter declaration. +C + character*14 FILE_NAME + character*11 SDS_NAME + integer RANK + parameter (FILE_NAME = 'SDSchunked.hdf', + + SDS_NAME = 'ChunkedData', + + RANK = 2) + integer DFACC_CREATE, DFACC_READ, DFNT_INT16 + parameter (DFACC_CREATE = 4, + + DFACC_READ = 1, + + DFNT_INT16 = 22) + integer COMP_CODE_NONE + parameter (COMP_CODE_NONE = 0) +C +C This example does not use compression. +C +C To use RLE compression, declare: +C +C integer COMP_CODE_RLE +C parameter (COMP_CODE_RLE = 1) +C +C To use NBIT compression, declare: +C +C integer COMP_CODE_NBIT +C parameter (COMP_CODE_NBIT = 2) +C +C To use Skipping Huffman compression, declare: +C +C integer COMP_CODE_SKPHUFF +C parameter (COMP_CODE_SKPHUFF = 3) +C +C To use GZIP compression, declare: +C +C integer COMP_CODE_DEFLATE +C parameter (COMP_CODE_DEFLATE = 4) +C +C +C Function declaration. +C + integer sfstart, sfcreate, sfendacc, sfend, + + sfselect, sfsfill, sfschnk, sfwchnk, + + sfrchnk, sfgichnk, sfwdata, sfrdata, + + sfscchnk +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, sds_index, status + integer dim_sizes(2), origin(2) + integer fill_value, maxcache, new_maxcache, flag + integer start(2), edges(2), stride(2) + integer*2 all_data(4,9) + integer*2 row(3), column(2) + integer*2 chunk_out(2,3) + integer*2 chunk1(2,3), + + chunk2(2,3), + + chunk3(2,3), + + chunk6(2,3) + integer i, j +C +C Compression flag and parameters. +C + integer comp_type, comp_flag, comp_prm(4) +C +C Chunk's dimensions. +C + integer dim_length(2), dim_length_out(2) +C +C Initialize four chunks +C + data chunk1 /6*1/ + data chunk2 /6*2/ + data chunk3 /6*3/ + data chunk6 /6*6/ +C +C Initialize row and column arrays. +C + data row /3*4/ + data column /2*5/ +C +C**** End of variable declaration ************************************ +C +C +C Define chunk's dimensions. +C + dim_length(1) = 2 + dim_length(2) = 3 +C +C Create the file and initialize SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_CREATE) + +C +C Create 4x9 SDS +C + dim_sizes(1) = 4 + dim_sizes(2) = 9 + sds_id = sfcreate(sd_id, SDS_NAME, DFNT_INT16, + + RANK, dim_sizes) +C +C Fill SDS array with the fill value. +C + fill_value = 0 + status = sfsfill( sds_id, fill_value) +C +C Create chunked SDS. +C +C In this example we do not use compression. +C +C To use RLE compression, initialize comp_type parameter +C before the call to sfschnk function. +C comp_type = COMP_CODE_RLE +C +C To use NBIT, Skipping Huffman, or GZIP compression, +C initialize comp_prm array and comp type parameter +C before call to sfschnk function +C +C NBIT: +C comp_prm(1) = value_of(sign_ext) +C comp_prm(2) = value_of(fill_one) +C comp_prm(3) = value_of(start_bit) +C comp_prm(4) = value_of(bit_len) +C comp_type = COMP_CODE_NBIT +C +C Skipping Huffman: +C comp_prm(1) = value_of(skp_size) +C comp_type = COMP_CODE_SKPHUFF +C +C GZIP: +C comp_prm(1) = value_of(deflate_level) +C comp_type = COMP_CODE_DEFLATE +C +C + comp_type = COMP_CODE_NONE + status = sfschnk(sds_id, dim_length, comp_type, comp_prm) +C +C Set chunk cache to hold maximum 2 chunks. +C + flag = 0 + maxcache = 2 + new_maxcache = sfscchnk(sds_id, maxcache, flag) +C +C Write chunks using SDwritechunk function. +C Chunks can be written in any order. +C +C Write chunk with the coordinates (1,1). +C + origin(1) = 1 + origin(2) = 1 + status = sfwchnk(sds_id, origin, chunk1) +C +C Write chunk with the coordinates (1,2). +C + origin(1) = 1 + origin(2) = 2 + status = sfwchnk(sds_id, origin, chunk3) +C +C Write chunk with the coordinates (2,1). +C + origin(1) = 2 + origin(2) = 1 + status = sfwchnk(sds_id, origin, chunk2) +C +C Write chunk with the coordinates (2,3). +C + origin(1) = 2 + origin(2) = 3 + status = sfwchnk(sds_id, origin, chunk6) +C +C Fill second row in the chunk with the coordinates (2,2). +C + start(1) = 3 + start(2) = 3 + edges(1) = 1 + edges(2) = 3 + stride(1) = 1 + stride(2) = 1 + status = sfwdata(sds_id, start, stride, edges, row) +C +C Fill second column in the chunk with the coordinates (1,3). +C + start(1) = 0 + start(2) = 7 + edges(1) = 2 + edges(2) = 1 + stride(1) = 1 + stride(2) = 1 + status = sfwdata(sds_id, start, stride, edges, column) +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) +C +C Reopen the file and access the first data set. +C + sd_id = sfstart(FILE_NAME, DFACC_READ) + sds_index = 0 + sds_id = sfselect(sd_id, sds_index) +C +C Get information about the SDS. +C + status = sfgichnk(sds_id, dim_length_out, comp_flag) + if (comp_flag .eq. 0) then + write(*,*) 'SDS is chunked' + endif + if (comp_flag .eq. 1) then + write(*,*) 'SDS is chunked and compressed' + endif + if (comp_flag .eq. 2) then + write(*,*) 'SDS is chunked and NBIT compressed' + endif + write(*,*) 'Chunks dimensions are ', dim_length_out(1), + + ' x' ,dim_length_out(2) +C +C Read the whole SDS using sfrdata function and display +C what we have read. The following information will be displayed: +C +C +C SDS is chunked +C Chunks dimensions are 2 x 3 +C +C 1 1 1 3 3 3 0 5 0 +C 1 1 1 3 3 3 0 5 0 +C 2 2 2 0 0 0 6 6 6 +C 2 2 2 4 4 4 6 6 6 +C + start(1) = 0 + start(2) = 0 + edges(1) = 4 + edges(2) = 9 + stride(1) = 1 + stride(2) = 1 + status = sfrdata(sds_id, start, stride, edges, all_data) +C +C Display the SDS. +C + write(*,*) + do 10 i = 1,4 + write(*,*) (all_data(i,j), j=1,9) +10 continue +C +C Read chunks with the coordinates (2,2) and (1,3) and display. +C The following information will be shown: +C +C Chunk (2,2) +C +C 0 0 0 +C 4 4 4 +C +C Chunk (1,3) +C +C 0 5 0 +C 0 5 0 +C + origin(1) = 2 + origin(2) = 2 + status = sfrchnk(sds_id, origin, chunk_out) + write(*,*) + write(*,*) 'Chunk (2,2)' + write(*,*) + do 20 i = 1,2 + write(*,*) (chunk_out(i,j), j=1,3) +20 continue +C + origin(1) = 1 + origin(2) = 3 + status = sfrchnk(sds_id, origin, chunk_out) + write(*,*) + write(*,*) 'Chunk (1,3)' + write(*,*) + do 30 i = 1,2 + write(*,*) (chunk_out(i,j), j=1,3) +30 continue +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_compress_sds.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_compress_sds.f new file mode 100644 index 0000000000..52612a1a72 --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_compress_sds.f @@ -0,0 +1,95 @@ + program write_compressed_data + implicit none +C +C Parameter declaration. +C + character*17 FILE_NAME + character*7 SDS_NAME + integer X_LENGTH, Y_LENGTH, RANK + parameter (FILE_NAME = 'SDScompressed.hdf', + + SDS_NAME = 'SDSgzip', + + X_LENGTH = 5, + + Y_LENGTH = 16, + + RANK = 2) + integer DFACC_CREATE, DFNT_INT32 + parameter (DFACC_CREATE = 4, + + DFNT_INT32 = 24) + integer COMP_CODE_DEFLATE + parameter (COMP_CODE_DEFLATE = 4) + integer DEFLATE_LEVEL + parameter (DEFLATE_LEVEL = 6) +C To use Skipping Huffman compression method, declare +C integer COMP_CODE_SKPHUFF +C parameter(COMP_CODE_SKPHUFF = 3) +C To use RLE compression method, declare +C integer COMP_CODE_RLE +C parameter(COMP_CODE_RLE = 1) +C +C +C Function declaration. +C + integer sfstart, sfcreate, sfwdata, sfendacc, sfend, + + sfscompress +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, status + integer start(2), edges(2), stride(2), dim_sizes(2) + integer comp_type + integer comp_prm(1) + integer data(X_LENGTH, Y_LENGTH) + integer i, j +C +C**** End of variable declaration ************************************ +C +C +C Buffer array data and define array dimensions. +C + do 20 j = 1, Y_LENGTH + do 10 i = 1, X_LENGTH + data(i, j) = i + j - 1 +10 continue +20 continue + dim_sizes(1) = X_LENGTH + dim_sizes(2) = Y_LENGTH +C +C Open the file and initialize the SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_CREATE) +C +C Create the data set with the name SDS_NAME. +C + sds_id = sfcreate(sd_id, SDS_NAME, DFNT_INT32, RANK, dim_sizes) +C +C Initialize compression parameter (deflate level) +C and call sfscompress function +C For Skipping Huffman compression, comp_prm(1) should be set +C to skipping sizes value (skp_size). +C + comp_type = COMP_CODE_DEFLATE + comp_prm(1) = deflate_level + status = sfscompress(sds_id, comp_type, comp_prm(1)) +C +C Define the location and size of the data that will be written to +C the data set. +C + start(1) = 0 + start(2) = 0 + edges(1) = X_LENGTH + edges(2) = Y_LENGTH + stride(1) = 1 + stride(2) = 1 +C +C Write the stored data to the data set. +C + status = sfwdata(sds_id, start, stride, edges, data) +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_create_sds.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_create_sds.f new file mode 100644 index 0000000000..0280fada7c --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_create_sds.f @@ -0,0 +1,54 @@ + program create_SDS + implicit none +C +C Parameter declaration. +C + character*7 FILE_NAME + character*11 SDS_NAME + integer X_LENGTH, Y_LENGTH, RANK + parameter (FILE_NAME = 'SDS.hdf', + + SDS_NAME = 'SDStemplate', + + X_LENGTH = 5, + + Y_LENGTH = 16, + + RANK = 2) + integer DFACC_CREATE, DFNT_INT32 + parameter (DFACC_CREATE = 4, + + DFNT_INT32 = 24) +C +C Function declaration. +C + integer sfstart, sfcreate, sfendacc, sfend +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, dim_sizes(2) + integer status +C +C**** End of variable declaration ************************************ +C +C +C Create the file and initialize the SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_CREATE) +C +C Define dimensions of the array to be created. +C + dim_sizes(1) = X_LENGTH + dim_sizes(2) = Y_LENGTH +C +C Create the array with the name defined in SDS_NAME. +C Note that DFNT_INT32 indicates that the SDS data is of type +C integer. Refer to Tables 2E and 2I for the definition of other types. +C + sds_id = sfcreate(sd_id, SDS_NAME, DFNT_INT32, RANK, + . dim_sizes) +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_dimscale_vs_sds.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_dimscale_vs_sds.f new file mode 100644 index 0000000000..e06040adc5 --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_dimscale_vs_sds.f @@ -0,0 +1,68 @@ + program sds_vrs_coordvar + implicit none +C +C Parameter declaration. +C + character*7 FILE_NAME + parameter (FILE_NAME = 'SDS.hdf') + integer DFACC_READ, DFNT_INT32 + parameter (DFACC_READ = 1, + + DFNT_INT32 = 24) + integer MAX_VAR_DIMS + parameter (MAX_VAR_DIMS = 32) +C +C Function declaration. +C + integer sfstart, sfselect, sfiscvar, sffinfo, sfginfo + integer sfendacc, sfend +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, sds_index, status + integer rank, data_type + integer n_datasets, n_file_attrs, n_attrs + integer dim_sizes(MAX_VAR_DIMS) + character*256 sds_name +C +C**** End of variable declaration ************************************ +C +C +C Open the file and initialize the SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_READ) +C +C Obtain information about the file. +C + status = sffinfo(sd_id, n_datasets, n_file_attrs) +C +C Get information about each SDS in the file. +C Check whether it is a coordinate variable, then display retrieved +C information. +C Output displayed: +C +C SDS array with the name SDStemplate +C Coordinate variable with the name X_Axis +C Coordinate variable with the name Y_Axis +C + do 10 sds_index = 0, n_datasets-1 + sds_id = sfselect(sd_id, sds_index) + status = sfginfo(sds_id, sds_name, rank, dim_sizes, + + data_type, n_attrs) + status = sfiscvar(sds_id) + if (status .eq. 1) then + write(*,*) "Coordinate variable with the name ", + + sds_name(1:6) + else + write(*,*) "SDS array with the name ", + + sds_name(1:11) + endif +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +10 continue +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_find_sds_by_name.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_find_sds_by_name.f new file mode 100644 index 0000000000..c3ac62bd60 --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_find_sds_by_name.f @@ -0,0 +1,82 @@ + program locate_by_name + implicit none +C +C Parameter declaration. +C + character*7 FILE_NAME + character*11 SDS_NAME + character*9 WRONG_NAME + integer X_LENGTH, Y_LENGTH + parameter (FILE_NAME = 'SDS.hdf', + + SDS_NAME = 'SDStemplate', + + WRONG_NAME = 'WrongName', + + X_LENGTH = 5, + + Y_LENGTH = 16) + integer DFACC_READ, DFNT_INT32 + parameter (DFACC_READ = 1, + + DFNT_INT32 = 24) + +C +C Function declaration. +C + integer sfstart, sfn2index, sfselect, sfrdata, sfendacc, sfend +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, sds_index, status + integer start(2), edges(2), stride(2) + integer data(X_LENGTH, Y_LENGTH) + integer j +C +C**** End of variable declaration ************************************ +C +C +C Open the file and initialize the SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_READ) +C +C Find index of the data set with the name specified in WRONG_NAME. +C Error condition occurs, since a data set with this name +C does not exist in the file. +C + sds_index = sfn2index(sd_id, WRONG_NAME) + if (sds_index .eq. -1) then + write(*,*) "Data set with the name ", WRONG_NAME, + + " does not exist" + endif +C +C Find index of the data set with the name specified in SDS_NAME +C and use the index to attach to the data set. +C + sds_index = sfn2index(sd_id, SDS_NAME) + sds_id = sfselect(sd_id, sds_index) +C +C Set elements of start array to 0, elements of edges array +C to SDS dimensions, and elements of stride array to 1 to read entire data. +C + start(1) = 0 + start(2) = 0 + edges(1) = X_LENGTH + edges(2) = Y_LENGTH + stride(1) = 1 + stride(2) = 1 +C +C Read entire data into array named data. +C + status = sfrdata(sds_id, start, stride, edges, data) +C +C Print 10th column; the following numbers should be displayed: +C +C 10 1000 12 13 14 +C + write(*,*) (data(j,10), j = 1, X_LENGTH) +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_get_attr.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_get_attr.f new file mode 100644 index 0000000000..73cbb64458 --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_get_attr.f @@ -0,0 +1,125 @@ + program attr_info + implicit none +C +C Parameter declaration. +C + character*7 FILE_NAME + character*13 FILE_ATTR_NAME + character*11 SDS_ATTR_NAME + character*10 DIM_ATTR_NAME + parameter (FILE_NAME = 'SDS.hdf', + + FILE_ATTR_NAME = 'File_contents', + + SDS_ATTR_NAME = 'Valid_range', + + DIM_ATTR_NAME = 'Dim_metric') + integer DFACC_READ, DFNT_FLOAT32 + parameter (DFACC_READ = 1, + + DFNT_FLOAT32 = 5) + +C +C Function declaration. +C + integer sfstart, sffattr, sfgainfo, sfrattr, sfselect + integer sfdimid, sfendacc, sfend +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, dim_id + integer attr_index, data_type, n_values, status + real sds_data(2) + character*20 attr_name + character*16 file_data + character*7 dim_data + integer i +C +C**** End of variable declaration ************************************ +C +C +C Open the file and initialize SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_READ) +C +C Find the file attribute defined by FILE_ATTR_NAME. +C Note that the first parameter is an SD interface identifier. +C + attr_index = sffattr(sd_id, FILE_ATTR_NAME) +C +C Get information about the file attribute. +C + status = sfgainfo(sd_id, attr_index, attr_name, data_type, + + n_values) +C +C Read the file attribute data. +C + status = sfrattr(sd_id, attr_index, file_data) +C +C Print file attribute value. +C + write(*,*) "File attribute value is : ", file_data +C +C Select the first data set. +C + sds_id = sfselect(sd_id, 0) +C +C Find the data set attribute defined by SDS_ATTR_NAME. +C Note that the first parameter is a data set identifier. +C + attr_index = sffattr(sds_id, SDS_ATTR_NAME) +C +C Get information about the data set attribute. +C + status = sfgainfo(sds_id, attr_index, attr_name, data_type, + + n_values) +C +C Read the SDS attribute data. +C + status = sfrattr(sds_id, attr_index, sds_data) + +C +C Print SDS attribute data type and values. +C + if (data_type .eq. DFNT_FLOAT32) then + write(*,*) "SDS attribute data type is : float32 " + endif + write(*,*) "SDS attribute values are : " + write(*,*) (sds_data(i), i=1, n_values) +C +C Get the identifier for the first dimension of the SDS. +C + dim_id = sfdimid(sds_id, 0) +C +C Find the dimensional attribute defined by DIM_ATTR_NAME. +C Note that the first parameter is a dimension identifier. +C + attr_index = sffattr(dim_id, DIM_ATTR_NAME) +C +C Get information about dimension attribute. +C + status = sfgainfo(dim_id, attr_index, attr_name, data_type, + + n_values) +C +C Read the dimension attribute data. +C + status = sfrattr(dim_id, attr_index, dim_data) +C +C Print dimension attribute value. +C + write(*,*) "Dimensional attribute value is : ", dim_data +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) +C +C Output of this program is : +C +C +C File attribute value is : Storm_track_data +C SDS attribute data type is : float32 +C SDS attribute values are : +C 2.00000 10.00000 +C Dimensional attribute value is : Seconds +C + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_get_info.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_get_info.f new file mode 100644 index 0000000000..dfc70dbebb --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_get_info.f @@ -0,0 +1,71 @@ + program get_data_set_info + implicit none +C +C Parameter declaration. +C + character*7 FILE_NAME + parameter (FILE_NAME = 'SDS.hdf') + integer DFACC_READ, DFNT_INT32 + parameter (DFACC_READ = 1, + + DFNT_INT32 = 24) + integer MAX_NC_NAME, MAX_VAR_DIMS + parameter (MAX_NC_NAME = 256, + + MAX_VAR_DIMS = 32) +C +C Function declaration. +C + integer sfstart, sffinfo, sfselect, sfginfo + integer sfendacc, sfend +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id + integer n_datasets, n_file_attrs, index + integer status, n_attrs + integer rank, data_type + integer dim_sizes(MAX_VAR_DIMS) + character name *(MAX_NC_NAME) + integer i +C +C**** End of variable declaration ************************************ +C +C +C Open the file and initialize the SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_READ) +C +C Determine the number of data sets in the file and the number of +C file attributes. +C + status = sffinfo(sd_id, n_datasets, n_file_attrs) +C +C Access every data set in the file and print its name, rank, +C dimension sizes, data type, and number of attributes. +C The following information should be displayed: +C +C name = SDStemplate +C rank = 2 +C dimension sizes are : 5 16 +C data type is 24 +C number of attributes is 0 +C + do 10 index = 0, n_datasets - 1 + sds_id = sfselect(sd_id, index) + status = sfginfo(sds_id, name, rank, dim_sizes, data_type, + . n_attrs) + write(*,*) "name = ", name(1:15) + write(*,*) "rank = ", rank + write(*,*) "dimension sizes are : ", (dim_sizes(i), i=1, rank) + write(*,*) "data type is ", data_type + write(*,*) "number of attributes is ", n_attrs +C +C Terminate access to the current data set. +C + status = sfendacc(sds_id) +10 continue +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_mv_sds_to_external.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_mv_sds_to_external.f new file mode 100644 index 0000000000..5d25aa3486 --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_mv_sds_to_external.f @@ -0,0 +1,50 @@ + program write_extfile + implicit none +C +C Parameter declaration. +C + character*7 FILE_NAME + character*11 EXT_FILE_NAME + integer OFFSET + integer DFACC_WRITE + parameter (FILE_NAME = 'SDS.hdf', + + EXT_FILE_NAME = 'ExternalSDS', + + OFFSET = 24, + + DFACC_WRITE = 2) + +C +C Function declaration. +C + integer sfstart, sfselect, sfsextf, sfendacc, sfend +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, sds_index + integer status +C +C**** End of variable declaration ************************************ +C +C +C Open the HDF file and initialize the SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_WRITE) +C +C Select the first data set. +C + sds_index = 0 + sds_id = sfselect(sd_id, sds_index) +C +C Create a file with the name EXT_FILE_NAME and move the data set +C into it, starting at byte location OFFSET. +C + status = sfsextf(sds_id, EXT_FILE_NAME, OFFSET) +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_read_from_sds.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_read_from_sds.f new file mode 100644 index 0000000000..50e2d7b297 --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_read_from_sds.f @@ -0,0 +1,72 @@ + program read_data + implicit none +C +C Parameter declaration. +C + character*7 FILE_NAME + integer X_LENGTH, Y_LENGTH + parameter (FILE_NAME = 'SDS.hdf', + + X_LENGTH = 5, + + Y_LENGTH = 16) + integer DFACC_READ, DFNT_INT32 + parameter (DFACC_READ = 1, + + DFNT_INT32 = 24) + +C +C Function declaration. +C + integer sfstart, sfselect, sfrdata, sfendacc, sfend +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, sds_index, status + integer start(2), edges(2), stride(2) + integer data(X_LENGTH, Y_LENGTH) + integer j +C +C**** End of variable declaration ************************************ +C +C +C Open the file and initialize the SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_READ) + +C +C Select the first data set. +C + sds_index = 0 + sds_id = sfselect(sd_id, sds_index) + +C +C Set elements of the array start to 0, elements of the array edges to +C SDS dimensions, and elements of the array stride to 1 to read the +C entire data. +C + start(1) = 0 + start(2) = 0 + edges(1) = X_LENGTH + edges(2) = Y_LENGTH + stride(1) = 1 + stride(2) = 1 +C +C Read entire data into data array. Note that sfrdata is used +C to read the numeric data. +C + status = sfrdata(sds_id, start, stride, edges, data) + +C +C Print 10th column; the following numbers are displayed: +C +C 10 1000 12 13 14 +C + write(*,*) (data(j,10), j = 1, X_LENGTH) +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_read_subsets.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_read_subsets.f new file mode 100644 index 0000000000..17d96e9b25 --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_read_subsets.f @@ -0,0 +1,125 @@ + program read_subsets + implicit none +C +C Parameter declaration. +C + character*7 FILE_NAME + parameter (FILE_NAME = 'SDS.hdf') + integer DFACC_READ, DFNT_INT32 + parameter (DFACC_READ = 1, + + DFNT_INT32 = 24) + integer SUB1_LENGTH, SUB2_LENGTH, SUB3_LENGTH1, + + SUB3_LENGTH2 + parameter (SUB1_LENGTH = 5, + + SUB2_LENGTH = 4, + + SUB3_LENGTH1 = 2, + + SUB3_LENGTH2 = 3) + +C +C Function declaration. +C + integer sfstart, sfselect, sfrdata, sfendacc, sfend +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, sds_index, status + integer start(2), edges(2), stride(2) + integer sub1_data(SUB1_LENGTH) + integer sub2_data(SUB2_LENGTH) + integer sub3_data(SUB3_LENGTH1,SUB3_LENGTH2) + integer i, j +C +C**** End of variable declaration ************************************ +C +C +C Open the file and initialize the SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_READ) +C +C Select the first data set. +C + sds_index = 0 + sds_id =sfselect(sd_id, sds_index) +C +C Reading the first subset. +C +C Set elements of start, stride, and edges arrays to read +C every 3d element in in the 2nd row starting in the 4th column. +C + start(1) = 1 + start(2) = 3 + edges(1) = 1 + edges(2) = SUB1_LENGTH + stride(1) = 1 + stride(2) = 3 +C +C Read the data from sub1_data array. +C + status = sfrdata(sds_id, start, stride, edges, sub1_data) + +C +C Print what we have just read, the following numbers should be displayed: +C +C 5 8 1000 14 17 +C + write(*,*) (sub1_data(j), j = 1, SUB1_LENGTH) +C +C Reading the second subset. +C +C Set elements of start, stride, and edges arrays to read +C first 4 elements of 10th column. +C + start(1) = 0 + start(2) = 9 + edges(1) = SUB2_LENGTH + edges(2) = 1 + stride(1) = 1 + stride(2) = 1 +C +C Read the data into sub2_data array. +C + status = sfrdata(sds_id, start, stride, edges, sub2_data) + +C +C Print what we have just read; the following numbers should be displayed: +C +C 10 1000 12 13 +C + write(*,*) (sub2_data(j), j = 1, SUB2_LENGTH) +C +C Reading the third subset. +C +C Set elements of start, stride and edges arrays to read +C every 6th element in the row and every 4th element in the column +C starting at 1st row, 3rd column. +C + start(1) = 0 + start(2) = 2 + edges(1) = SUB3_LENGTH1 + edges(2) = SUB3_LENGTH2 + stride(1) = 4 + stride(2) = 6 +C +C Read the data from the file into sub3_data array. +C + status = sfrdata(sds_id, start, stride, edges, sub3_data) + +C +C Print what we have just read; the following numbers should be displayed: +C +C 3 9 15 +C 7 13 19 +C + do 50 i = 1, SUB3_LENGTH1 + write(*,*) (sub3_data(i,j), j = 1, SUB3_LENGTH2) +50 continue +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_set_attr.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_set_attr.f new file mode 100644 index 0000000000..a813c64c49 --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_set_attr.f @@ -0,0 +1,82 @@ + program set_attribs + implicit none +C +C Parameter declaration. +C + character*7 FILE_NAME + character*13 FILE_ATTR_NAME + character*11 SDS_ATTR_NAME + character*10 DIM_ATTR_NAME + parameter (FILE_NAME = 'SDS.hdf', + + FILE_ATTR_NAME = 'File_contents', + + SDS_ATTR_NAME = 'Valid_range', + + DIM_ATTR_NAME = 'Dim_metric') + integer DFACC_WRITE, DFNT_CHAR8, DFNT_FLOAT32 + parameter (DFACC_WRITE = 2, + + DFNT_CHAR8 = 4, + + DFNT_FLOAT32 = 5) +C +C Function declaration. +C + integer sfstart, sfscatt, sfsnatt, sfselect, sfdimid + integer sfendacc, sfend +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, sds_index, status + integer dim_id, dim_index + integer n_values + character*16 file_values + real sds_values(2) + character*7 dim_values + file_values = 'Storm_track_data' + sds_values(1) = 2. + sds_values(2) = 10. + dim_values = 'Seconds' +C +C**** End of variable declaration ************************************ +C +C +C Open the file and initialize the SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_WRITE) +C +C Set an attribute that describes the file contents. +C + n_values = 16 + status = sfscatt(sd_id, FILE_ATTR_NAME, DFNT_CHAR8, n_values, + + file_values) +C +C Select the first data set. +C + sds_index = 0 + sds_id = sfselect(sd_id, sds_index) +C +C Assign attribute to the first SDS. Note that attribute values +C may have different data type than SDS data. +C + n_values = 2 + status = sfsnatt(sds_id, SDS_ATTR_NAME, DFNT_FLOAT32, n_values, + + sds_values) +C +C Get the identifier for the first dimension. +C + dim_index = 0 + dim_id = sfdimid(sds_id, dim_index) +C +C Set an attribute to the dimension that specifies the +C dimension metric. +C + n_values = 7 + status = sfscatt(dim_id, DIM_ATTR_NAME, DFNT_CHAR8, n_values, + + dim_values) +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_set_get_dim_info.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_set_get_dim_info.f new file mode 100644 index 0000000000..7466be685d --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_set_get_dim_info.f @@ -0,0 +1,147 @@ + program dimension_info + implicit none +C +C Parameter declaration. +C + character*7 FILE_NAME + character*11 SDS_NAME + character*6 DIM_NAME_X + character*6 DIM_NAME_Y + integer X_LENGTH, Y_LENGTH, RANK + parameter (FILE_NAME = 'SDS.hdf', + + SDS_NAME = 'SDStemplate', + + DIM_NAME_X = 'X_Axis', + + DIM_NAME_Y = 'Y_Axis', + + X_LENGTH = 5, + + Y_LENGTH = 16, + + RANK = 2) + integer DFACC_WRITE, DFNT_INT16, DFNT_FLOAT64 + parameter (DFACC_WRITE = 2, + + DFNT_INT16 = 22, + + DFNT_FLOAT64 = 6) + +C +C Function declaration. +C + integer sfstart, sfn2index, sfdimid, sfgdinfo + integer sfsdscale, sfgdscale, sfsdmname, sfendacc + integer sfend, sfselect +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, sds_index, status + integer dim_index, dim_id + integer n_values, n_attrs, data_type + integer*2 data_X(X_LENGTH) + integer*2 data_X_out(X_LENGTH) + real*8 data_Y(Y_LENGTH) + real*8 data_Y_out(Y_LENGTH) + character*6 dim_name + integer i +C +C**** End of variable declaration ************************************ +C +C +C Initialize dimension scales. +C + do 10 i = 1, X_LENGTH + data_X(i) = i - 1 +10 continue + + do 20 i = 1, Y_LENGTH + data_Y(i) = 0.1 * (i - 1) +20 continue +C +C Open the file and initialize SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_WRITE) +C +C Get the index of the data set with the name specified in SDS_NAME. +C + sds_index = sfn2index(sd_id, SDS_NAME) +C +C Select the data set corresponding to the returned index. +C + sds_id = sfselect(sd_id, sds_index) +C +C For each dimension of the data set, +C get its dimension identifier and set dimension name +C and dimension scales. Note that data type of dimension scale can +C be different between dimensions and can be different from SDS data type. +C + do 30 dim_index = 0, RANK - 1 +C +C Select the dimension at position dim_index. +C + dim_id = sfdimid(sds_id, dim_index) +C +C Assign name and dimension scale to the dimension. +C + if (dim_index .eq. 0) then + status = sfsdmname(dim_id, DIM_NAME_X) + n_values = X_LENGTH + status = sfsdscale(dim_id, n_values, DFNT_INT16, data_X) + end if + if (dim_index .eq. 1) then + status = sfsdmname(dim_id, DIM_NAME_Y) + n_values = Y_LENGTH + status = sfsdscale(dim_id, n_values, DFNT_FLOAT64, data_Y) + end if +C +C Get and display information about dimension and its scale values. +C The following information is displayed: +C +C Information about 1 dimension : +C dimension name is X_Axis +C number of scale values is 5 +C dimension scale data type is int16 +C +C number of dimension attributes is 0 +C Scale values are: +C 0 1 2 3 4 +C +C Information about 2 dimension : +C dimension name is Y_Axis +C number of scale values is 16 +C dimension scale data type is float64 +C number of dimension attributes is 0 +C +C Scale values are: +C 0.000 0.100 0.200 0.300 +C 0.400 0.500 0.600 0.700 +C 0.800 0.900 1.000 1.100 +C 1.200 1.300 1.400 1.500 +C + status = sfgdinfo(dim_id, dim_name, n_values, data_type, n_attrs) +C + write(*,*) "Information about ", dim_index+1," dimension :" + write(*,*) "dimension name is ", dim_name + write(*,*) "number of scale values is", n_values + if (data_type. eq. 22) then + write(*,*) "dimension scale data type is int16" + endif + if (data_type. eq. 6) then + write(*,*) "dimension scale data type is float64" + endif + write(*,*) "number of dimension attributes is ", n_attrs +C + write(*,*) "Scale values are:" + if (dim_index .eq. 0) then + status = sfgdscale(dim_id, data_X_out) + write(*,*) (data_X_out(i), i= 1, X_LENGTH) + endif + if (dim_index .eq. 1) then + status = sfgdscale(dim_id, data_Y_out) + write(*,100) (data_Y_out(i), i= 1, Y_LENGTH) +100 format(4(1x,f10.3)/) + endif +30 continue +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_unlimited_sds.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_unlimited_sds.f new file mode 100644 index 0000000000..de637fbc85 --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_unlimited_sds.f @@ -0,0 +1,115 @@ + program append_sds + implicit none +C +C Parameter declaration. +C + character*16 FILE_NAME + character*14 SDS_NAME + integer X_LENGTH, Y_LENGTH, RANK + parameter (FILE_NAME = 'SDSUNLIMITED.hdf', + + SDS_NAME = 'AppendableData', + + X_LENGTH = 10, + + Y_LENGTH = 10, + + RANK = 2) + integer DFACC_CREATE, DFACC_WRITE, SD_UNLIMITED, + + DFNT_INT32 + parameter (DFACC_CREATE = 4, + + DFACC_WRITE = 2, + + SD_UNLIMITED = 0, + + DFNT_INT32 = 24) +C +C Function declaration. +C + integer sfstart, sfcreate, sfwdata, sfselect + integer sfendacc, sfend +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, sds_index, status + integer dim_sizes(2) + integer start(2), edges(2), stride(2) + integer i, j + integer data (X_LENGTH, Y_LENGTH), append_data(X_LENGTH) +C +C**** End of variable declaration ************************************ +C +C +C Data initialization. +C + do 20 j = 1, Y_LENGTH + do 10 i = 1, X_LENGTH + data(i, j) = i + j +10 continue +20 continue +C +C Create the file and initialize the SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_CREATE) +C +C Define dimensions of the array. Make the +C last dimension appendable by defining its length as unlimited. +C + dim_sizes(1) = X_LENGTH + dim_sizes(2) = SD_UNLIMITED + +C Create the array data set. + sds_id = sfcreate(sd_id, SDS_NAME, DFNT_INT32, RANK, + . dim_sizes) +C +C Define the location and the size of the data to be written +C to the data set. Note that the elements of array stride are +C set to 1 for contiguous writing. +C + start(1) = 0 + start(2) = 0 + edges(1) = X_LENGTH + edges(2) = Y_LENGTH + stride(1) = 1 + stride(2) = 1 +C +C Write the data. +C + status = sfwdata(sds_id, start, stride, edges, data) +C +C Terminate access to the data set, terminate access +C to the SD interface, and close the file. +C + status = sfendacc(sds_id) + status = sfend(sd_id) +C +C Store the array values to be appended to the data set. +C + do 30 i = 1, X_LENGTH + append_data(i) = 1000 + i - 1 +30 continue +C +C Reopen the file and initialize the SD. +C + sd_id = sfstart(FILE_NAME, DFACC_WRITE) +C +C Select the first data set. +C + sds_index = 0 + sds_id = sfselect(sd_id, sds_index) +C +C Define the location of the append to start at the 11th +C column of the 1st row and to stop at the end of the 10th row. +C + start(1) = 0 + start(2) = Y_LENGTH + edges(1) = X_LENGTH + edges(2) = 1 +C +C Append the data to the data set. +C + status = sfwdata(sds_id, start, stride, edges, append_data) +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_write_slab.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_write_slab.f new file mode 100644 index 0000000000..61608295ce --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_write_slab.f @@ -0,0 +1,101 @@ + program write_slab + implicit none +C +C Parameter declaration. +C + character*9 FILE_NAME + character*13 SDS_NAME + integer X_LENGTH, Y_LENGTH, Z_LENGTH, RANK + parameter (FILE_NAME = 'SLABS.hdf', + + SDS_NAME = 'FilledBySlabs', + + X_LENGTH = 4, + + Y_LENGTH = 5, + + Z_LENGTH = 6, + + RANK = 3) + integer DFACC_CREATE, DFNT_INT32 + parameter (DFACC_CREATE = 4, + + DFNT_INT32 = 24) +C +C Function declaration. +C + integer sfstart, sfcreate, sfwdata, sfendacc, sfend +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id + integer dim_sizes(3), start(3), edges(3), stride(3) + integer i, j, k, status + integer data(X_LENGTH, Y_LENGTH, Z_LENGTH) + integer xz_data(X_LENGTH, Z_LENGTH) +C +C**** End of variable declaration ************************************ +C +C +C Data initialization. +C + do 30 k = 1, Z_LENGTH + do 20 j = 1, Y_LENGTH + do 10 i = 1, X_LENGTH + data(i, j, k) = i + j + k +10 continue +20 continue +30 continue +C +C Create the file and initialize the SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_CREATE) +C +C Define dimensions of the array to be created. +C + dim_sizes(1) = X_LENGTH + dim_sizes(2) = Y_LENGTH + dim_sizes(3) = Z_LENGTH +C +C Create the data set with the name defined in SDS_NAME. +C + sds_id = sfcreate(sd_id, SDS_NAME, DFNT_INT32, RANK, + . dim_sizes) +C +C Set the parameters start and edges to write +C a 4x6 element slab of data to the data set; +C note that edges(2) is set to 1 to define a 2 dimensional slab +C parallel to the XZ plane; +C start(2) (slab position in the array) is initialized inside the +C for loop. +C + edges(1) = X_LENGTH + edges(2) = 1 + edges(3) = Z_LENGTH + start(1) = 0 + start(3) = 0 + stride(1) = 1 + stride(2) = 1 + stride(3) = 1 + + do 60 j = 1, Y_LENGTH + start(2) = j - 1 +C +C Initialize the buffer xz_data (data slab). +C + do 50 k = 1, Z_LENGTH + do 40 i = 1, X_LENGTH + xz_data(i, k) = data(i, j, k) +40 continue +50 continue +C +C Write the data slab into SDS array defined in SDS_NAME. +C Note that the elements of array stride are set to 1 to +C specify that the consecutive slabs in the Y direction are written. +C + status = sfwdata(sds_id, start, stride, edges, xz_data) +60 continue +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + + end diff --git a/HDF4Examples/mfhdf/fortran/h4ex_SD_write_to_sds.f b/HDF4Examples/mfhdf/fortran/h4ex_SD_write_to_sds.f new file mode 100644 index 0000000000..7f548c7bae --- /dev/null +++ b/HDF4Examples/mfhdf/fortran/h4ex_SD_write_to_sds.f @@ -0,0 +1,79 @@ + program write_data + implicit none +C +C Parameter declaration. +C + character*7 FILE_NAME + character*11 SDS_NAME + integer X_LENGTH, Y_LENGTH, RANK + parameter (FILE_NAME = 'SDS.hdf', + + SDS_NAME = 'SDStemplate', + + X_LENGTH = 5, + + Y_LENGTH = 16, + + RANK = 2) + integer DFACC_WRITE, DFNT_INT32 + parameter (DFACC_WRITE = 2, + + DFNT_INT32 = 24) +C +C Function declaration. +C + + integer sfstart, sfselect, sfwdata, sfendacc, sfend +C +C**** Variable declaration ******************************************* +C + integer sd_id, sds_id, sds_index, status + integer start(2), edges(2), stride(2) + integer i, j + integer data(X_LENGTH, Y_LENGTH) +C +C**** End of variable declaration ************************************ +C + +C +C Data set data initialization. +C + do 20 j = 1, Y_LENGTH + do 10 i = 1, X_LENGTH + data(i, j) = i + j - 1 +10 continue +20 continue + +C +C Open the file and initialize the SD interface. +C + sd_id = sfstart(FILE_NAME, DFACC_WRITE) + +C +C Attach to the first data set. +C + sds_index = 0 + sds_id = sfselect(sd_id, sds_index) + +C +C Define the location and size of the data to be written +C to the data set. Note that setting values of the array stride to 1 +C specifies the contiguous writing of data. +C + start(1) = 0 + start(2) = 0 + edges(1) = X_LENGTH + edges(2) = Y_LENGTH + stride(1) = 1 + stride(2) = 1 +C +C Write the stored data to the data set named in SDS_NAME. +C Note that the routine sfwdata is used instead of sfwcdata +C to write the numeric data. +C + status = sfwdata(sds_id, start, stride, edges, data) +C +C Terminate access to the data set. +C + status = sfendacc(sds_id) +C +C Terminate access to the SD interface and close the file. +C + status = sfend(sd_id) + + end diff --git a/config/cmake/HDF4ExampleCache.cmake b/config/cmake/HDF4ExampleCache.cmake new file mode 100644 index 0000000000..13fc1ef80d --- /dev/null +++ b/config/cmake/HDF4ExampleCache.cmake @@ -0,0 +1,46 @@ +# CMake cache file for examples + +######################### +# EXTERNAL cache entries +######################### + +# set example options to match build options +set (H4EX_BUILD_TESTING ${BUILD_TESTING} CACHE BOOL "Enable examples testing" FORCE) +set (H4EX_BUILD_EXAMPLES ${HDF4_BUILD_EXAMPLES} CACHE BOOL "Build Examples" FORCE) +set (HDF_BUILD_FORTRAN ${HDF4_BUILD_FORTRAN} CACHE BOOL "Build examples FORTRAN support" FORCE) +set (HDF_BUILD_JAVA ${HDF4_BUILD_JAVA} CACHE BOOL "Build examples JAVA support" FORCE) +set (H4EX_USE_GNU_DIRS ${HDF4_USE_GNU_DIRS} CACHE BOOL "TRUE to use GNU Coding Standard install directory variables, FALSE to use historical settings" FORCE) + +#preset HDF4 cache vars to this projects libraries instead of searching +set (H4EX_HDF4_HEADER "H4config.h" CACHE STRING "Name of HDF4 header" FORCE) +#set (H4EX_HDF4_INCLUDE_DIRS $<TARGET_PROPERTY:${HDF4_LIBSH_TARGET},INCLUDE_DIRECTORIES> CACHE PATH "HDF4 include dirs" FORCE) +set (H4EX_HDF4_INCLUDE_DIRS "${HDF4_SRC_INCLUDE_DIRS};${HDF4_SRC_BINARY_DIR}" CACHE PATH "HDF4 include dirs" FORCE) +set (H4EX_HDF4_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE STRING "HDF4 build folder" FORCE) +set (EXAMPLES_EXTERNALLY_CONFIGURED ON CACHE BOOL "Examples build is used in another project" FORCE) + +if (NOT BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS) + set (USE_SHARED_LIBS OFF CACHE BOOL "Use Shared Libraries for Examples" FORCE) + set (H4EX_HDF4_LINK_LIBS ${HDF4_LIB_TARGET} CACHE STRING "HDF4 target" FORCE) + if (HDF4_BUILD_FORTRAN) + set (H4EX_HDF4_LINK_LIBS ${H4EX_HDF4_LINK_LIBS} ${HDF4_F90_LIB_TARGET}) + set (HDF_MOD_EXT "/static" CACHE STRING "Use Static Modules for Examples" FORCE) + endif () +else () + set (USE_SHARED_LIBS ON CACHE BOOL "Use Shared Libraries for Examples" FORCE) + set (H4EX_HDF4_LINK_LIBS ${HDF4_LIBSH_TARGET} CACHE STRING "HDF4 target" FORCE) + if (HDF4_BUILD_FORTRAN) + set (H4EX_HDF4_LINK_LIBS ${H4EX_HDF4_LINK_LIBS} ${HDF4_F90_LIBSH_TARGET}) + set (HDF_MOD_EXT "/shared" CACHE STRING "Use Shared Modules for Examples" FORCE) + endif () + if (HDF4_BUILD_JAVA) + set (HDF4_JAVA_INCLUDE_DIRS ${HDF4_JAVA_JARS} ${HDF4_JAVA_LOGGING_JAR}) + set (H4EX_JAVA_LIBRARY ${HDF4_JAVA_JNI_LIB_TARGET}) + set (H4EX_JAVA_LIBRARIES ${HDF4_JAVA_HDF_LIB_TARGET} ${HDF4_JAVA_JNI_LIB_TARGET}) + set (HDF4_LIBRARY_PATH ${CMAKE_TEST_OUTPUT_DIRECTORY}) + message (STATUS "HDF4 Example java lib: ${H4EX_JAVA_LIBRARY} jars: ${HDF4_JAVA_INCLUDE_DIRS}") + endif () +endif () +message (STATUS "HDF4 Example link libs: ${H4EX_HDF4_LINK_LIBS} Includes: ${H4EX_HDF4_INCLUDE_DIRS}") + +set (HDF4_TOOLS_DIR ${CMAKE_TEST_OUTPUT_DIRECTORY} CACHE STRING "HDF4 Directory for all Executables" FORCE) +set (H4EX_HDF4_DUMP_EXECUTABLE $<TARGET_FILE:hdp${tgt_file_ext}> CACHE STRING "HDF4 hdp target" FORCE) diff --git a/config/cmake/HDFMacros.cmake b/config/cmake/HDFMacros.cmake index 048bb8ff75..5e5629c5d1 100644 --- a/config/cmake/HDFMacros.cmake +++ b/config/cmake/HDFMacros.cmake @@ -28,7 +28,7 @@ macro (SET_HDF_OUTPUT_DIRS package_prefix) endif () else () # if we are externally configured, but the project uses old cmake scripts - # this may not be set and utilities like H5detect will fail + # this may not be set and some utilities may fail if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}) endif () diff --git a/release_notes/RELEASE.txt b/release_notes/RELEASE.txt index 0a63b83807..9300354a0c 100644 --- a/release_notes/RELEASE.txt +++ b/release_notes/RELEASE.txt @@ -38,6 +38,22 @@ New features and changes ======================== Configuration: ------------- + - Incorporated HDF4 examples repository into HDF4 library. + + The HDF4Examples folder is equivalent to the repository hdf4-examples. + As such it can build and test the examples during library build or after + the library is installed. Previously, the hdf4-repository archives were + downloaded for packaging with the library. Now the examples can be built + and tested without a packaged install of the library. + + However to maintain the ability to use the HDF4Examples with an installed + library, it is necessary to translate or synch the option names from those + used by the library to those used by the examples. The typical pattern is: + <example option> = <library option> + HDF_BUILD_JAVA = ${HDF4_BUILD_JAVA} + + (ADB - 2023/12/13) + - Autotools and CMake target added to produce doxygen generated documentation The default is OFF or disabled.