How Users Read on the Web

博客指出用户很少逐字读网页,多采用扫描方式。网页文本应采用可扫描形式,如突出关键字、有深度子标题等。提高网页可信度可借助高质量图片、好文笔和超链接,用户讨厌商业口号。通过对同一网站不同版本测试,发现不同书写风格能显著提升可用性。
 一篇没有翻译完的,但是大概已经有一些了,希望对web UI有帮助

How Users Read on the Web

They don't.

People rarely read Web pages word by word; instead, they scan the page, picking out individual words and sentences. In a recent study John Morkes and I found that 79 percent of our test users always scanned any new page they came across; only 16 percent read word-by-word.

用户很少逐字逐句读一个网页(16%的人这么做),大多数人采用扫描的方式去读(占79%

As a result, Web pages have to employ scannable text, using

  • highlighted keywords (hypertext links serve as one form of highlighting; typeface variations and color are others)
  • meaningful sub-headings (not "clever" ones)
  • bulleted lists
  • one idea per paragraph (users will skip over any additional ideas if they are not caught by the first few words in the paragraph)
  • the inverted pyramid style, starting with the conclusion.
  • half the word count (or less) than conventional writing

结果表明:网页的文本应该是能被扫描的:

  • 突出的关键字(包含超链接,字体和颜色的变化,与众不同)
  • 有深度的子标题(而不是肤浅的)
  • 圆点列表
  • 每段一个主题(如果一段的前几句话没有吸引住用户,他们往往跳过其他的内容)
  • 倒金字塔结构,从结论开始
  • 用传统方式下一半或更少的字

We found that credibility is important for Web users, since it is unclear who is behind information on the Web and whether a page can be trusted. Credibility can be increased by high-quality graphics, good writing, and use of outbound hypertext links. Links to other sites show that the authors have done their homework and are not afraid to let readers visit other sites.

对于Web读者,可信度是最重要的,因为他们不清楚信息的幕后是谁,这个网页是否可以相信。提高可信度的办法有:高质量的图片、好文笔、以及连出去的超链接。不要担心读者访问别人的网站,连到别人的站上让读者看到作者是尽职尽责的。

 

Users detested "marketese"; the promotional writing style with boastful subjective claims ("hottest ever") that currently is prevalent on the Web. Web users are busy: they want to get the straight facts. Also, credibility suffers when users clearly see that the site exaggerates.

用户讨厌商业口号。现在很流行在网站上写“真诚到永远”之类的主观的口号。用户很忙,他们想得到直接的事实。所以他们看到夸张的行为时,站点的可信度就降低了。

Measuring the Effect of Improved Web Writing

改善网站书写的效果评测

To measure the effect of some of the content guidelines we had identified, we developed five different versions of the same website (same basic information; different wording; same site navigation). We then had users perform the same tasks with the different sites. As shown in the table, measured usability was dramatically higher for the concise version (58% better) and for the scannable version (47% better). And when we combined three ideas for improved writing style into a single site, the result was truly stellar: 124% better usability.

 

为了评测一下我们确定的一些网站内容指导方针,我们为同一个网站(同样的内容,不同的措辞,同样的站点导航)做了五个不同的版本。然后我们让用户在不同的站上做相同的事情。正如下表显示的,简单版本的可用性提高了58%,可扫描版本提高了47%。当我们把三种写作风格用在一个网站上之后,可用性提高了124%

 

Site Version

Sample Paragraph

Usability Improvement
(relative to control condition)

Promotional writing (control condition)
using the "marketese" found on many commercial websites

Nebraska is filled with internationally recognized attractions that draw large crowds of people every year, without fail. In 1996, some of the most popular places were Fort Robinson State Park (355,000 visitors), Scotts Bluff National Monument (132,166), Arbor Lodge State Historical Park & Museum (100,000), Carhenge (86,598), Stuhr Museum of the Prairie Pioneer (60,002), and Buffalo Bill Ranch State Historical Park (28,446).

0%
(by definition)

Concise text
with about half the word count as the control condition

In 1996, six of the best-attended attractions in Nebraska were Fort Robinson State Park, Scotts Bluff National Monument, Arbor Lodge State Historical Park & Museum, Carhenge, Stuhr Museum of the Prairie Pioneer, and Buffalo Bill Ranch State Historical Park.

58%

Scannable layout
using the same text as the control condition in a layout that facilitated scanning

Nebraska is filled with internationally recognized attractions that draw large crowds of people every year, without fail. In 1996, some of the most popular places were:

  • Fort Robinson State Park (355,000 visitors)
  • Scotts Bluff National Monument (132,166)
  • Arbor Lodge State Historical Park & Museum (100,000)
  • Carhenge (86,598)
  • Stuhr Museum of the Prairie Pioneer (60,002)
  • Buffalo Bill Ranch State Historical Park (28,446).

47%

Objective language
using neutral rather than subjective, boastful, or exaggerated language (otherwise the same as the control condition)

Nebraska has several attractions. In 1996, some of the most-visited places were Fort Robinson State Park (355,000 visitors), Scotts Bluff National Monument (132,166), Arbor Lodge State Historical Park & Museum (100,000), Carhenge (86,598), Stuhr Museum of the Prairie Pioneer (60,002), and Buffalo Bill Ranch State Historical Park (28,446).

27%

Combined version
using all three improvements in writing style together: concise, scannable, and objective

In 1996, six of the most-visited places in Nebraska were:

  • Fort Robinson State Park
  • Scotts Bluff National Monument
  • Arbor Lodge State Historical Park & Museum
  • Carhenge
  • Stuhr Museum of the Prairie Pioneer
  • Buffalo Bill Ranch State Historical Park

124%

It was somewhat surprising to us that usability was improved by a good deal in the objective language version (27% better). We had expected that users would like this version better than the promotional site (as indeed they did), but we thought that the performance metrics would have been the same for both kinds of language. As it turned out, our four performance measures (time, errors, memory, and site structure) were also better for the objective version than for the promotional version. Our conjecture to explain this finding is that promotional language imposes a cognitive burden on users who have to spend resources on filtering out the hyperbole to get at the facts. When people read a paragraph that starts "Nebraska is filled with internationally recognized attractions," their first reaction is no, it's not, and this thought slows them down and distracts them from using the site.

 

我的感想:网站内容最好的书写方式看来就和写自己的简历差不多
传送带损坏与对象检测数据集 一、基础信息 • 数据集名称:传送带损坏与对象检测数据集 • 图片数量: 训练集:645张图片 验证集:185张图片 测试集:92张图片 总计:922张工业监控图片 • 训练集:645张图片 • 验证集:185张图片 • 测试集:92张图片 • 总计:922张工业监控图片 • 分类类别: Hole(孔洞):传送带表面的孔洞损坏。 Human(人类):工作区域中的人类,用于安全监控。 Other Objects(其他对象):非预期对象,可能引起故障。 Puncture(刺穿):传送带被刺穿的损坏。 Roller(滚筒):传送带滚筒部件。 Tear(撕裂):传送带撕裂损坏。 impact damage(冲击损坏):由于冲击导致的损坏。 patch work(修补工作):已修补的区域。 • Hole(孔洞):传送带表面的孔洞损坏。 • Human(人类):工作区域中的人类,用于安全监控。 • Other Objects(其他对象):非预期对象,可能引起故障。 • Puncture(刺穿):传送带被刺穿的损坏。 • Roller(滚筒):传送带滚筒部件。 • Tear(撕裂):传送带撕裂损坏。 • impact damage(冲击损坏):由于冲击导致的损坏。 • patch work(修补工作):已修补的区域。 • 标注格式:YOLO格式,包含边界框和类别标签,适用于目标检测任务。 • 数据格式:图像数据来源于工业监控系统,适用于计算机视觉分析。 二、适用场景 • 工业自动化检测系统开发:用于构建自动检测传送带损坏和异物的AI模型,实现实时监控和预防性维护,减少停机时间。 • 安全监控应用:识别人类和其他对象,提升工业环境的安全性,避免事故和人员伤害。 • 学术研究与创新:支持计算机视觉在制造业、物流和自动化领域的应用研究,促进AI技术与工业实践的融合。 • 教育与培训:可用于培训AI模型或作为工业工程和自动化教育的案例数据,帮助学习者理解实际应用场景。 三、数据集优势 • 多样化的类别覆盖:包含8个关键类别,涵盖多种损坏类型和对象,确保模型能够处理各种实际工业场景,提升泛化能力。 • 精准的标注质量:采用YOLO格式,边界框标注准确,由专业标注人员完成,保证数据可靠性和模型训练效果。 • 强大的任务适配性:兼容主流深度学习框架(如YOLO、TensorFlow、PyTorch),可直接用于目标检测任务,并支持扩展至其他视觉任务需求。 • 突出的工业价值:专注于工业传送带系统的实际需求,帮助提升生产效率、降低维护成本,并增强工作场所安全,具有较高的实际应用价值。
一、基础信息 • 数据集名称:垃圾废弃物目标检测数据集 • 图片数量: 训练集:1124张图片 验证集:375张图片 总计:1499张图片 • 训练集:1124张图片 • 验证集:375张图片 • 总计:1499张图片 • 分类类别:包含60多个垃圾和废弃物类别,如气溶胶、铝泡罩包装、电池、破碎玻璃、卡片泡罩包装、香烟、透明塑料瓶、瓦楞纸箱、薯片袋、一次性食品容器、一次性塑料杯、饮料罐、饮料纸盒、鸡蛋盒、泡沫杯、泡沫食品容器、食品罐、食物垃圾、垃圾袋、玻璃瓶、玻璃杯、玻璃罐、杂志纸、餐盒、金属瓶盖、金属盖、普通纸、其他纸箱、其他塑料、其他塑料瓶、其他塑料容器、其他塑料杯、其他塑料包装、纸袋、纸杯、纸吸管、披萨盒、塑料瓶盖、塑料薄膜、塑料手套、塑料盖、塑料吸管、塑料餐具、聚丙烯袋、拉环、绳子、废金属、鞋子、一次性购物袋、六罐环、涂抹管、可挤压管、泡沫塑料片、纸巾、厕纸管、特百惠、未标记垃圾、包装纸等。 • 标注格式:YOLO格式,包含边界框和类别标签,适用于目标检测任务。 • 数据格式:图片来源于实际场景,细节清晰。 二、适用场景 • 垃圾自动分类系统开发:数据集支持目标检测任务,帮助构建能够自动识别和分类垃圾物品的AI模型,用于智能垃圾桶或回收系统,提升废弃物管理效率。 • 环保应用研发:集成至环保和废弃物管理应用,提供实时垃圾识别功能,促进回收和环境保护,支持可持续发展倡议。 • 学术研究与创新:支持计算机视觉与环保领域的交叉研究,助力发表垃圾识别和AI技术相关学术论文,推动技术创新。 • 教育与培训:可用于学校或培训机构,作为垃圾分类和AI目标检测教学的重要资源,培养环保意识和技术能力。 三、数据集优势 • 精准标注与多样性:每张图片经过准确标注,确保边界框定位精确;包含多种垃圾类别,覆盖常见废弃物,提升模型的泛化能力和鲁棒性。 • 任务适配性强:标注兼容主流深度学习框架(如YOLO等),可直接用于目标检测任务,并支持扩展到其他视觉任务,如分类或分割。 • 实际应用价值:专注于垃圾识别,为环保、废弃物管理和回收提供重要数据支撑,有助于减少污染和促进循环经济。
水下垃圾实例分割数据集 一、基础信息 • 数据集名称:水下垃圾实例分割数据集 • 图片数量: 训练集:1049张图片 验证集:300张图片 测试集:150张图片 总计:1499张图片 • 训练集:1049张图片 • 验证集:300张图片 • 测试集:150张图片 • 总计:1499张图片 • 分类类别: Aerosol(气溶胶罐) Aluminium blister pack(铝泡罩包装) Aluminium foil(铝箔) Battery(电池) Broken glass(碎玻璃) Carded blister pack(卡式泡罩包装) Cigarette(香烟) Clear plastic bottle(透明塑料瓶) Corrugated carton(瓦楞纸箱) Crisp packet(薯片袋) Disposable food container(一次性食品容器) Disposable plastic cup(一次性塑料杯) Drink can(饮料罐) Drink carton(饮料纸盒) Egg carton(鸡蛋盒) Foam cup(泡沫杯) Foam food container(泡沫食品容器) Food Can(食品罐) Food waste(食物垃圾) Garbage bag(垃圾袋) Glass bottle(玻璃瓶) Glass cup(玻璃杯) Glass jar(玻璃罐) Magazine paper(杂志纸) Meal carton(餐盒) Metal bottle cap(金属瓶盖) Metal lid(金属盖子) Normal paper(普通纸) Other carton(其他纸盒) Other plastic(其他塑料) Other plastic bottle(其他塑料瓶) Other plastic container(其他塑料容器) Other plastic cup(其他塑料杯) Other plastic wrapper(其他塑料包装) Paper bag(纸袋) Paper cup(纸杯) Paper straw(纸吸管) Pizza box(披萨盒) Plastic bottle cap(塑料瓶盖) Plastic film(塑料薄膜) Plastic gloves(塑料手套) Plastic lid(塑料盖子) Plastic straw(塑料吸管) Plastic utensils(塑料餐具) Polypropylene bag(聚丙烯袋) Pop tab(易拉罐拉环) Rope - strings(绳子-字符串) Scrap metal(废金属) Shoe(鞋子) Single-use carrier bag(一次性购物袋) Six pack rings(六罐环) Spread tub(涂抹桶) Squeezable tube(可挤压管) Styrofoam piece(泡沫塑料片) Tissues(纸巾) Toilet tube(卫生纸卷) Tupperware(特百惠) Unlabeled litter(未标记垃圾) Wrapping paper(包装纸) • Aerosol(气溶胶罐) • Aluminium blister pack(铝泡罩包装) • Aluminium foil(铝箔) • Battery(电池) • Broken glass(碎玻璃) • Carded blister pack(卡式泡罩包装) • Cigarette(香烟) • Clear plastic bottle(透明塑料瓶) • Corrugated carton(瓦楞纸箱) • Crisp packet(薯片袋) • Disposable food container(一次性食品容器) • Disposable plastic cup(一次性塑料杯) • Drink can(饮料罐) • Drink carton(饮料纸盒) • Egg carton(鸡蛋盒) • Foam cup(泡沫杯) • Foam food container(泡沫食品容器) • Food Can(食品罐) • Food waste(食物垃圾) • Garbage bag(垃圾袋) • Glass bottle(玻璃瓶) • Glass cup(玻璃杯) • Glass jar(玻璃罐) • Magazine paper(杂志纸) • Meal carton(餐盒) • Metal bottle cap(金属瓶盖) • Metal lid(金属盖子) • Normal paper(普通纸) • Other carton(其他纸盒) • Other plastic(其他塑料) • Other pl
************************************************************************ * Build and Install HDF5 Applications with CMake * ************************************************************************ Notes: This short instruction is written for users who want to quickly build HDF5 applications using the CMake tools. Users can adapt these instructions for their own applications. For more information, see the "Minimum C Project Files for CMake" section. 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 HDF5 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 HDF5 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. 3. See the appendix at the bottom of this file for an example of using a ctest script for building and testing. See INSTALL_CMake.txt for more information. 4. See https://cmake.org/cmake/help/latest/command/find_package.html for more information on the CMake "Config Mode Search Procedure". ======================================================================== I. Preconditions ======================================================================== 1. We suggest you obtain the latest CMake for your platform from the Kitware web site. The HDF5 1.12.x product requires a minimum CMake version of 3.12. If you are using VS2019, the minimum version is 3.15. For VS2022, the minimum version is 3.21. 2. You have installed the HDF5 library built with CMake, by executing the HDF Install Utility (the *.msi file in the binary package for Windows or the *.sh on Linux). You can obtain pre-built binaries from The HDF Group's website at www.hdfgroup.org. 3. Set the HDF5_ROOT CMake variable, -DHDF5_ROOT=<install_path> or environment variable, set(ENV{HDF5_ROOT} "<install_path>") to the installed location of HDF5. On Windows: HDF5_ROOT=C:/Program Files/HDF_Group/HDF5/1.12.x/ On unix: HDF5_ROOT=<install root folder>/HDF_Group/HDF5/1.12.x/ If you are using shared libraries, you may need to add to the path environment variable. Set the path environment variable to the installed location of the library files for HDF5. On Windows (*.dll): PATH=%PATH%;C:/Program Files/HDF_Group/HDF5/1.12.x/bin On unix (*.so): LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<install root folder>/HDF_Group/HDF5/1.12.x/lib If you are using filter plugin libraries, you will need to set the HDF5_PLUGIN_PATH environment variable. On Windows: HDF5_PLUGIN_PATH=C:/Program Files/HDF_Group/HDF5/1.12.x/lib/plugin On unix: HDF5_PLUGIN_PATH=<install root folder>/HDF_Group/HDF5/1.12.x/lib/plugin (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) 5. Created a CMakeLists.txt file(s) for your source. See Section III below. ======================================================================== II. Building HDF5 Applications with CMake ======================================================================== Go through these steps to build HDF5 applications with CMake. (The application must support building with CMake.) 1. Run CMake 2. Configure the cache settings 3. Build HDF5 Applications 4. Test HDF5 Applications 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\hdf5, then use c:\MyHDFstuff\hdf5\build or c:\MyHDFstuff\build\hdf5 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 "<generator>" [-D<options>] <sourcepath> Where <generator> is * MinGW Makefiles * NMake Makefiles * Unix Makefiles * Visual Studio 14 2015 * Visual Studio 14 2015 Win64 * Visual Studio 15 2017 * Visual Studio 15 2017 Win64 * Visual Studio 16 2019 * ... in addition VS2019 will need to set the "-A" option, * ... [Win32, x64, ARM, ARM64] * Visual Studio 17 2022 * ... in addition VS2022 will need to set the "-A" option, * ... [Win32, x64, ARM, ARM64] <options> is: * BUILD_TESTING:BOOL=ON * BUILD_SHARED_LIBS:BOOL=[ON | OFF] 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 14 2015 Win64). CMake will read in the CMakeLists.txt files from the source directory and display options for the HDF5 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\hdf5\build directory: cmake -G "Visual Studio 14 2015 Win64" -DBUILD_TESTING:BOOL=ON .. 3. Build HDF5 Applications On Windows, you can build HDF5 applications 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 HDF5 Applications 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. Minimum C Project Files for CMake ======================================================================== Given the preconditions in section I, create a CMakeLists.txt file at the source root. Include the following text in the file: ########################################################## cmake_minimum_required (VERSION 3.12) project (HDF5MyApp C CXX) set (LIB_TYPE STATIC) # or SHARED string(TOLOWER ${LIB_TYPE} SEARCH_TYPE) find_package (HDF5 NAMES hdf5 COMPONENTS C ${SEARCH_TYPE}) # find_package (HDF5) # Find non-cmake built HDF5 set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES "${HDF5_INCLUDE_DIR}") set (LINK_LIBS ${LINK_LIBS} ${HDF5_C_${LIB_TYPE}_LIBRARY}) set (example hdf_example) add_executable (${example} ${PROJECT_SOURCE_DIR}/${example}.c) TARGET_C_PROPERTIES (${example} PRIVATE ${LIB_TYPE}) target_link_libraries (${example} ${LINK_LIBS}) enable_testing () include (CTest) add_test (NAME test_example COMMAND ${example}) ########################################################## ======================================================================== IV. APPENDIX ======================================================================== Below is an example of a ctest script that can be used to build the examples. Adjust the values as necessary. Note that the defaults can be entered on the command line and the build folder is created as a sub-folder. Windows should adjust the forward slash to double backslashes, except for the HDF_DIR environment variable. NOTE: this file is available at the HDF web site: https://portal.hdfgroup.org/display/support/Building+HDF5+with+CMake HDF5_Examples.cmake HDF5_Examples_options.cmake Also available at the HDF web site is a CMake application framework template. You can quickly add files to the framework and execute the script to compile your application with an installed HDF5 binary. ======================================================================== For further assistance, send email to help@hdfgroup.org ========================================================================
06-27
<think>我们正在解决的是在Windows上使用CMake配置HDF5应用程序的问题。用户提供的CMakeLists.txt中,HDF5的配置不成功,无法生成HDF5.mod文件。根据引用[1]中的示例,我们可以调整HDF5的配置方式。关键点:1.使用`find_package`来查找HDF5,并确保指定了CONFIG模式(因为HDF5提供了CMake配置文件)。2.设置HDF5的安装路径(HDF5_ROOT)以帮助CMake找到它。3.在链接时,需要将HDF5的库链接到目标,同时添加必要的编译定义(如`H5_BUILT_AS_DYNAMIC_LIB`如果使用动态库)。4.对于Fortran项目,需要确保HDF5的Fortran组件也被找到。根据用户之前的CMakeLists.txt,他们尝试使用ExternalProject_Add来构建HDF5,但可能没有正确设置后续的find_package。我们调整策略:1.如果已经预先编译了HDF5,则设置HDF5_ROOT环境变量指向安装目录,然后使用find_package。2.或者,使用ExternalProject_Add来构建HDF5,然后使用导出的配置(但这一步比较复杂,因为需要等待构建完成并生成配置文件)。考虑到用户希望生成HDF5.mod(Fortran模块文件),我们必须确保HDF5的Fortran库被正确构建和安装。步骤:1.确保HDF5的构建包含Fortran支持(在配置时添加--enable-fortran)。2.在构建并安装HDF5后,使用find_package(HDF5COMPONENTSFortranREQUIRED)来查找Fortran组件。修改CMakeLists.txt中关于HDF5的部分:由于用户使用ExternalProject_Add构建HDF5,我们需要等待构建完成,然后设置HDF5的路径。但是,ExternalProject_Add在构建期间不会使HDF5的配置文件立即可用,因此我们可能需要使用一个自定义的脚本来设置变量。另一种方法是预先构建HDF5(按照引用[3]中的方法),然后设置HDF5_ROOT。这里我们提供两种方案:方案一:预先构建HDF5,然后在CMake中设置HDF5_ROOT。方案二:在CMake中使用ExternalProject_Add构建HDF5,然后通过设置变量来使用它(需要知道构建产物的位置)。考虑到用户已经尝试了方案二但没有成功,我们尝试方案一,并给出方案二的改进方法。我们先给出一个简化的指南,包括配置、构建和测试HDF5应用程序。注意:用户的项目是SWMM5+,它需要HDF5的Fortran支持。以下步骤以Windows为例(用户的环境是Windows):步骤1:下载并安装HDF5-从HDFGroup官网下载预编译的Windows版本(包含Fortran支持)[^2]。-或者,从源代码构建HDF5(使用CMake):-下载HDF5源代码(如1.12.2版本)-使用CMake配置,生成VisualStudio工程,注意勾选Fortran支持(BUILD_FORTRAN=ON)和生成共享库(BUILD_SHARED_LIBS=ON或OFF根据需求)[^3]。-编译并安装。步骤2:设置环境变量HDF5_ROOT指向HDF5的安装目录(例如:C:/hdf5/install)。步骤3:修改SWMM5+的CMakeLists.txt,使用find_package来查找HDF5(包括Fortran组件)。修改后的HDF5配置部分:```cmake#查找HDF5,要求Fortran组件find_package(HDF5COMPONENTSFortranREQUIREDCONFIG)#添加HDF5的头文件目录include_directories(${HDF5_INCLUDE_DIRS})#添加HDF5的库目录(如果必要)link_directories(${HDF5_LIBRARY_DIRS})#在目标SWMM5p上链接HDF5库target_link_libraries(SWMM5pPRIVATE${HDF5_Fortran_LIBRARIES}${HDF5_LIBRARIES})#如果使用动态库,可能需要添加定义target_compile_definitions(SWMM5pPRIVATEH5_BUILT_AS_DYNAMIC_LIB)```注意:如果HDF5是静态库,则不需要定义`H5_BUILT_AS_DYNAMIC_LIB`。步骤4:构建项目。步骤5:测试(如果配置了测试)。如果用户希望完全在CMake中构建HDF5,可以使用ExternalProject,但需要正确设置依赖和路径。以下是一个示例:```cmake#使用ExternalProject构建HDF5include(ExternalProject)ExternalProject_Add(hdf5_projectURL"https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.2/src/hdf5-1.12.2.tar.gz"CMAKE_ARGS-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>-DBUILD_SHARED_LIBS=OFF-DHDF5_BUILD_FORTRAN=ON-DHDF5_BUILD_CPP_LIB=OFF-DHDF5_BUILD_HL_LIB=ON-DHDF5_BUILD_TOOLS=OFF-DHDF5_BUILD_EXAMPLES=OFF-DHDF5_ENABLE_Z_LIB_SUPPORT=OFF-DCMAKE_BUILD_TYPE=Release-G"VisualStudio172022"-Ax64BUILD_COMMANDcmake--build.--configReleaseINSTALL_COMMANDcmake--install.--configRelease)#获取安装目录ExternalProject_Get_Property(hdf5_projectINSTALL_DIR)#设置HDF5_ROOTset(HDF5_ROOT${INSTALL_DIR})set(HDF5_DIR${INSTALL_DIR}/share/cmake/hdf5)#由于ExternalProject在构建阶段不会影响当前项目的配置阶段,我们需要将目标SWMM5p依赖于hdf5_project,并在配置后使用find_package#注意:必须在add_executable之后,并在target_link_libraries之前,使用find_packageadd_dependencies(SWMM5phdf5_project)#然后使用find_package(在hdf5_project构建并安装后,HDF5的配置文件就可用)find_package(HDF5COMPONENTSFortranREQUIREDCONFIGHINTS${HDF5_DIR})```但是,这种方法在配置阶段可能无法立即找到HDF5,因为ExternalProject_Add的构建和安装发生在构建阶段。因此,我们通常建议预先构建HDF5。针对用户的具体问题,他们无法生成HDF5.mod,这通常是因为Fortran模块文件没有被正确安装或包含路径不对。使用find_package(HDF5COMPONENTSFortran)会设置变量`HDF5_Fortran_INCLUDE_DIRS`,其中包含.mod文件所在的目录。我们需要将这个目录添加到Fortran的包含路径中。在CMakeLists.txt中,添加:```cmakeif(HDF5_Fortran_FOUND)include_directories(${HDF5_Fortran_INCLUDE_DIRS})endif()```或者使用target_include_directories:```cmaketarget_include_directories(SWMM5pPRIVATE${HDF5_Fortran_INCLUDE_DIRS})```这样,Fortran编译器就能找到HDF5.mod文件。总结修改步骤:1.确保HDF5已安装(包含Fortran支持)并设置HDF5_ROOT。2.使用find_package(HDF5COMPONENTSFortranREQUIREDCONFIG)来查找。3.将HDF5的Fortran包含目录添加到目标。4.链接HDF5的Fortran库。根据用户的CMakeLists.txt,我们修改如下:在`add_executable(SWMM5p...)`之后:```cmake#查找HDF5(Fortran组件)find_package(HDF5COMPONENTSFortranREQUIREDCONFIG)#添加HDF5Fortran的包含目录(包含HDF5.mod)target_include_directories(SWMM5pPRIVATE${HDF5_Fortran_INCLUDE_DIRS})#添加HDF5的库目录(如果需要)target_link_directories(SWMM5pPRIVATE${HDF5_LIBRARY_DIRS})#链接HDF5库target_link_libraries(SWMM5pPRIVATE${HDF5_Fortran_LIBRARIES}${HDF5_LIBRARIES})```注意:如果HDF5是动态链接,则需要复制相应的dll到可执行文件目录。如果用户希望完全在CMake中构建HDF5,那么需要采用ExternalProject_Add,并确保在构建目标SWMM5p之前完成HDF5的构建和安装,同时正确设置find_package的路径。由于用户之前已经使用了ExternalProject_Add,但未成功,我们可以调整他们的ExternalProject_Add部分,并确保使用了Fortran支持。修改用户原来的ExternalProject_Add部分:```cmakeExternalProject_Add(hdf5SOURCE_DIR"${hdf5_SOURCE_DIR}"CMAKE_ARGS-DCMAKE_INSTALL_PREFIX=${hdf5_BINARY_DIR}/install-DBUILD_SHARED_LIBS=OFF-DHDF5_BUILD_FORTRAN=ON-DHDF5_BUILD_CPP_LIB=OFF-DHDF5_BUILD_HL_LIB=ON-DHDF5_BUILD_TOOLS=OFF-DHDF5_BUILD_EXAMPLES=OFF-DHDF5_ENABLE_Z_LIB_SUPPORT=OFF-G"VisualStudio172022"-Ax64BUILD_COMMAND${CMAKE_COMMAND}--build.--configReleaseINSTALL_COMMAND${CMAKE_COMMAND}--install.--configRelease)```然后设置:```cmakeset(HDF5_DIR${hdf5_BINARY_DIR}/install/share/cmake/hdf5)set(HDF5_ROOT${hdf5_BINARY_DIR}/install)```然后在后面使用:```cmakefind_package(HDF5COMPONENTSFortranREQUIREDCONFIGHINTS${HDF5_DIR})```注意:在配置阶段,ExternalProject_Add还没有构建,所以第一次运行cmake时,find_package会失败。因此,我们需要将find_package放在可以延迟执行的位置,或者使用两次cmake(第一次配置主项目,然后构建ExternalProject,然后再次cmake配置主项目以使find_package生效)。这通常很麻烦,所以推荐预先构建HDF5。考虑到用户的问题,我们建议采用预先构建HDF5的方式。最后,我们给出一个完整的示例指南:###使用CMake构建和安装HDF5应用程序(含Fortran)的指南####1.配置-下载HDF5源代码(例如1.12.2版本)或预编译包(含Fortran支持)。-如果使用预编译包,设置环境变量`HDF5_ROOT`指向安装目录(例如:`C:/hdf5/install`)。-在CMakeLists.txt中,使用`find_package`查找HDF5的Fortran组件:```cmakefind_package(HDF5COMPONENTSFortranREQUIREDCONFIG)```####2.构建-在CMakeLists.txt中,将HDF5的包含目录和库链接到目标:```cmakeadd_executable(my_hdf5_fortranmain.f90)target_include_directories(my_hdf5_fortranPRIVATE${HDF5_Fortran_INCLUDE_DIRS})target_link_libraries(my_hdf5_fortranPRIVATE${HDF5_Fortran_LIBRARIES})```-如果使用动态库,添加编译定义:```cmaketarget_compile_definitions(my_hdf5_fortranPRIVATEH5_BUILT_AS_DYNAMIC_LIB)```####3.测试-编写测试程序(例如main.f90):```fortranprogramtest_hdf5usehdf5implicitnoneinteger::errorcallh5open_f(error)print*,"HDF5version:",H5_VERS_INFOcallh5close_f(error)endprogramtest_hdf5```-使用CTest添加测试:```cmakeenable_testing()add_test(NAMEtest_hdf5COMMANDmy_hdf5_fortran)```####4.示例-完整CMakeLists.txt示例:```cmakecmake_minimum_required(VERSION3.20)project(my_hdf5_fortran_testFortran)#设置HDF5_ROOT(也可以在命令行设置)#set(HDF5_ROOT"C:/hdf5/install")find_package(HDF5COMPONENTSFortranREQUIREDCONFIG)add_executable(my_hdf5_fortranmain.f90)target_include_directories(my_hdf5_fortranPRIVATE${HDF5_Fortran_INCLUDE_DIRS})target_link_libraries(my_hdf5_fortranPRIVATE${HDF5_Fortran_LIBRARIES})target_compile_definitions(my_hdf5_fortranPRIVATEH5_BUILT_AS_DYNAMIC_LIB)enable_testing()add_test(NAMEtest_hdf5COMMANDmy_hdf5_fortran)```按照此指南,用户应能成功生成HDF5.mod并构建Fortran程序。§§相关问题§§1.如何在Windows上编译支持Fortran的HDF5库?2.CMake中`find_package`的CONFIG模式和MODULE模式有什么区别?3.如何解决CMake找不到HDF5的问题?4.如何在CMake中使用ExternalProject_Add管理依赖项?</think>### 使用 CMake 构建和安装 HDF5 应用程序完整指南 以下是配置、构建和测试 HDF5 应用程序的完整流程,特别针对 Windows 平台优化: #### 1. 配置阶段 ```cmake cmake_minimum_required(VERSION 3.20) project(MyHDF5App Fortran C) # 设置 HDF5 安装路径 set(HDF5_ROOT "C:/hdf5/install" CACHE PATH "HDF5 安装目录") # 查找 HDF5 库(包含 Fortran 支持) find_package(HDF5 REQUIRED COMPONENTS Fortran CONFIG) # 检查是否找到 HDF5 if(HDF5_FOUND) message(STATUS "HDF5 版本: ${HDF5_VERSION}") message(STATUS "HDF5 Fortran 包含目录: ${HDF5_Fortran_INCLUDE_DIRS}") else() message(FATAL_ERROR "HDF5 库未找到!请检查 HDF5_ROOT 路径") endif() # 添加可执行文件 add_executable(my_hdf5_app src/main.f90 src/data_processing.f90 ) # 添加 HDF5 头文件目录 target_include_directories(my_hdf5_app PRIVATE ${HDF5_INCLUDE_DIRS} ${HDF5_Fortran_INCLUDE_DIRS} ) # 添加必要的编译定义 target_compile_definitions(my_hdf5_app PRIVATE H5_BUILT_AS_DYNAMIC_LIB ) # 链接 HDF5 库 target_link_libraries(my_hdf5_app PRIVATE ${HDF5_Fortran_LIBRARIES} ${HDF5_LIBRARIES} ) ``` #### 2. 构建阶段 1. **创建构建目录**: ```bash mkdir build cd build ``` 2. **生成构建系统**(Windows 示例): ```bash cmake .. -G "Visual Studio 17 2022" -A x64 -DHDF5_ROOT="C:/hdf5/install" ``` 3. **编译项目**: ```bash cmake --build . --config Release ``` #### 3. 测试阶段 ```cmake # 启用测试 enable_testing() # 添加测试用例 add_test(NAME BasicHDF5Test COMMAND my_hdf5_app test_input.h5 ) # 添加带验证的测试 add_test(NAME OutputValidation COMMAND ${Python3_EXECUTABLE} validate_results.py ) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ``` #### 4. 完整示例:HDF5 Fortran 程序 `src/main.f90` 示例代码: ```fortran program hdf5_demo use hdf5 implicit none integer :: error integer(hid_t) :: file_id ! 初始化 HDF5 库 call h5open_f(error) ! 创建新文件 call h5fcreate_f("data.h5", H5F_ACC_TRUNC_F, file_id, error) ! 在此添加数据处理代码... ! 关闭文件 call h5fclose_f(file_id, error) ! 关闭 HDF5 库 call h5close_f(error) print *, "HDF5 文件创建成功!" end program hdf5_demo ``` #### 5. 安装部署 ```cmake # 安装可执行文件 install(TARGETS my_hdf5_app RUNTIME DESTINATION bin ) # 安装依赖的 DLL(Windows 专用) install(FILES ${HDF5_Fortran_LIBRARIES} DESTINATION bin ) ``` #### 常见问题解决 1. **HDF5.mod 文件找不到**: - 确保安装的 HDF5 包含 Fortran 支持 - 检查 `HDF5_Fortran_INCLUDE_DIRS` 路径是否正确 - 添加路径到 Fortran 模块搜索路径: ```cmake set(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/modules) include_directories(${HDF5_Fortran_INCLUDE_DIRS}) ``` 2. **链接错误**: ```cmake # 添加额外的系统库(Windows 需要) target_link_libraries(my_hdf5_app PRIVATE ws2_32.lib dbghelp.lib ) ``` 3. **配置验证**: ```cmake # 打印详细配置信息 message(STATUS "HDF5 库路径: ${HDF5_LIBRARIES}") message(STATUS "HDF5 Fortran 模块路径: ${HDF5_Fortran_INCLUDE_DIRS}") ``` #### 测试脚本示例 `validate_results.py` ```python import h5py def validate_hdf5(file_path): try: with h5py.File(file_path, 'r') as f: print("HDF5 文件结构:") print(list(f.keys())) return 0 except Exception as e: print(f"验证失败: {str(e)}") return 1 if __name__ == "__main__": import sys sys.exit(validate_hdf5(sys.argv[1])) ``` [^1]
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值