summaryrefslogtreecommitdiffstats
path: root/test/flush1.c
blob: d9a55ed9b1534016d0e9211ca7492a35f753b64c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
 * access to either file, you may request a copy from help@hdfgroup.org.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 * Programmer:  Robb Matzke <matzke@llnl.gov>
 *              Friday, October 23, 1998
 *
 * Purpose:	This is the first half of a two-part test that makes sure
 *		that a file can be read after an application crashes as long
 *		as the file was flushed first.  We simulate a crash by
 *		calling _exit(0) since this doesn't flush HDF5 caches but
 *		still exits with success.
 */
#include "h5test.h"

const char *FILENAME[] = {
    "flush",
    "noflush",
    "noflush_extend",
    NULL
};

static double	the_data[100][100];

/*-------------------------------------------------------------------------
 * Function:	create_file
 *
 * Purpose:	Creates files used in part 1 of the test
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Leon Arber
 *              Sept. 26, 2006
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static hid_t
create_file(char* name, hid_t fapl)
{
    hid_t	file, dcpl, space, dset, groups, grp;
    hsize_t	ds_size[2] = {100, 100};
    hsize_t	ch_size[2] = {5, 5};
    size_t	i, j;

    if((file = H5Fcreate(name, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) FAIL_STACK_ERROR

    /* Create a chunked dataset */
    if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) FAIL_STACK_ERROR
    if(H5Pset_chunk(dcpl, 2, ch_size) < 0) FAIL_STACK_ERROR
    if((space = H5Screate_simple(2, ds_size, NULL)) < 0) FAIL_STACK_ERROR
    if((dset = H5Dcreate2(file, "dset", H5T_NATIVE_FLOAT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR

    /* Write some data */
    for(i = 0; i < ds_size[0]; i++)
	/*
	 * The extra cast in the following statement is a bug workaround
	 * for the Win32 version 5.0 compiler.
	 * 1998-11-06 ptl
	 */
        for(j = 0; j < (size_t)ds_size[1]; j++)
	    the_data[i][j] = (double)(hssize_t)i/(hssize_t)(j+1);
    if(H5Dwrite(dset, H5T_NATIVE_DOUBLE, space, space, H5P_DEFAULT, the_data) < 0) FAIL_STACK_ERROR

    /* Create some groups */
    if((groups = H5Gcreate2(file, "some_groups", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
    for(i = 0; i < 100; i++) {
	sprintf(name, "grp%02u", (unsigned)i);
	if((grp = H5Gcreate2(groups, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
	if(H5Gclose(grp) < 0) FAIL_STACK_ERROR
    } /* end for */

    return file;

error:
    HD_exit(1);
}


/*-------------------------------------------------------------------------
 * Function:	extend_file
 *
 * Purpose:	Add a small dataset to the file.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Leon Arber
 *              Oct. 4, 2006
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static hid_t
extend_file(hid_t file)
{
    hid_t	dcpl, space, dset;
    hsize_t	ds_size[2] = {100, 100};
    hsize_t	ch_size[2] = {5, 5};
    size_t	i, j;

    /* Create a chunked dataset */
    if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error;
    if(H5Pset_chunk(dcpl, 2, ch_size) < 0) goto error;
    if((space = H5Screate_simple(2, ds_size, NULL)) < 0) goto error;
    if((dset = H5Dcreate2(file, "dset2", H5T_NATIVE_FLOAT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
	goto error;

    /* Write some data */
    for (i=0; i<ds_size[0]; i++) {
	/*
	 * The extra cast in the following statement is a bug workaround
	 * for the Win32 version 5.0 compiler.
	 * 1998-11-06 ptl
	 */
	for (j=0; j<(size_t)ds_size[1]; j++) {
	    the_data[i][j] = (double)(hssize_t)i/(hssize_t)(j+1);
	}
    }
    if (H5Dwrite(dset, H5T_NATIVE_DOUBLE, space, space, H5P_DEFAULT,
		the_data) < 0) goto error;


    return file;

error:
        HD_exit(1);

}

/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	Part 1 of a two-part H5Fflush() test.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Robb Matzke
 *              Friday, October 23, 1998
 *
 * Modifications:
 * 		Leon Arber
 * 		Sept. 26, 2006, expand test to check for failure if H5Fflush is not called.
 * 		Oct. 4 2006, expand test to check for partial failure in case file is flushed, but then
 * 				new datasets are created after the flush.
 *
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    hid_t file, fapl;
    char	name[1024];
    const char  *envval = NULL;

    h5_reset();
    fapl = h5_fileaccess();

    TESTING("H5Fflush (part1)");
    envval = HDgetenv("HDF5_DRIVER");
    if (envval == NULL)
        envval = "nomatch";
    if (HDstrcmp(envval, "split")) {
	/* Create the file */
	h5_fixname(FILENAME[0], fapl, name, sizeof name);
	file = create_file(name, fapl);
	/* Flush and exit without closing the library */
	if (H5Fflush(file, H5F_SCOPE_GLOBAL) < 0) goto error;

	/* Create the file */
	h5_fixname(FILENAME[2], fapl, name, sizeof name);
	file = create_file(name, fapl);
	/* Flush and exit without closing the library */
	if(H5Fflush(file, H5F_SCOPE_GLOBAL) < 0) goto error;
	/* Add a bit to the file and don't flush the new part */
	extend_file(file);

	/* Create the other file which will not be flushed */
	h5_fixname(FILENAME[1], fapl, name, sizeof name);
	file = create_file(name, fapl);


	PASSED();
	fflush(stdout);
	fflush(stderr);
    }
    else
    {
        SKIPPED();
        puts("    Test not compatible with current Virtual File Driver");
    }

    HD_exit(0);

    error:
        HD_exit(1);
        return 1;

}
tran/examples hdf5build_examples.bat InstallExamples.bat HDF5 examples: Simple HDF5 C/C++/Fortran and High level C/Fortran examples ======================================================================== Section II: How To Build Examples (Optional) ======================================================================== Simple examples have been provided for users to test HDF5 C/C++/Fortran and High level C/Fortran library and tools. Note: 1) To build HDF5 C++ examples, HDF5 C++ library must have been installed in Step I. 2) To build HDF5 Fortran or HL Fortran examples, please see Section VI, Step 3. 3) To build HDF5 High Level C examples, HDF5 High level library must have been installed in step I. 4) By default, the HDF5 binary distribution only includes the release versions of HDF5 C/C++ libraries and DLLs. To build and test HDF5 C examples: ---------------------------------- 1. Invoke Microsoft Visual Studio, go to "File" and select the "Open Solution" option. Then open the solution c:\MyHDFstuff\hdf5examples\windows\examples\allexamples\allexamples.sln. 2. Select "Build", and "Configuration Manager". To build release versions of C examples. In "Active Solution Configuration", select "Release". Select "Close". Select "Build" -> "Build Solution" or "Rebuild Solution" to build release version of project "allexamples". When the release build is done, there should be the following subdirectories in c:\MyHDFstuff\hdf5examples\examples\ attributetest attributetestdll chunkread chunkreaddll compoundtest compoundtestdll extendwritetest extendwritetestdll grouptest grouptestdll readtest readtestdll selectest selectestdll writetest writetestdll 3. Invoke a command prompt window and run the batch file InstallExamples.bat which resides in the top level directory (c:\MyHDFstuff\hdf5examples). This file creates new directories, examplesREL, examplesRELDLL in the c:\MyHDFstuff\hdf5examples\examples directory and places all the executables in it. 4. We provide a batch file named testExamples.bat and an expected examples tests output file named testExamples_exp_output.txt in c:\MyHDFstuff\hdf5\examples directory for you to test HDF5 C examples. testExamples.bat batch file has options: testExamples release -- for release version testExamples release dll -- for release DLL version Invoke a command prompt and run testExamples.bat with appropriate options. You should get "All HDF5 C examples tests passed." when the C examples are built successfully. Otherwise, the difference between the expected outputs and actual outputs will be given. To build and test HDF5 C++ examples: ------------------------------------ 1. Invoke Microsoft Visual Studio, go to "File" and select the "Open Solution" option. Then open the solution c:\MyHDFstuff\hdf5examples\windows\examples\allexamples\allcppexamples.sln. 2. Select "Build", and "Configuration Manager". To build release versions of C examples. In "Active Solution Configuration", select "Release". Select "Close". Select "Build" -> "Build Solution" or "Rebuild Solution" to build release version of project "allcppexamples". When the release build is done, there should be the following subdirectories in c:\MyHDFstuff\hdf5examples\c++\examples\ chunks chunksdll compound compounddll create createdll extend_ds extend_dsll h5group h5groupdll readdata readdatadll writedata writedatadll 3. Invoke a command prompt window and run the batch file InstallcppExamples.bat which resides in the top level directory (c:\MyHDFstuff\hdf5examples). This file creates new directories, cppexamplesREL, cppexamplesRELDLL in the c:\MyHDFstuff\hdf5examples\c++\examples directory and places all the executables in it. 4. We provide a batch file named testcppExamples.bat in c:\MyHDFstuff\hdf5examples\c++\examples directory for you to test HDF5 C++ examples. testcppExamples.bat batch file has options: testcppExamples release -- for release version testcppExamples release dll -- for release DLL version Invoke a command prompt and run testcppExamples.bat with appropriate options. You should get "All HDF5 C++ examples tests passed." when the C++ examples are built successfully. Otherwise, the difference between the expected outputs and actual outputs will be given. To build and test HDF5 High Level C examples: --------------------------------------------- 1. Invoke Microsoft Visual Studio, go to "File" and select the "Open Solution" option. Then open the solution c:\MyHDFstuff\hdf5examples\windows\hl\examples\allhlcexamples\allhlcexamples.sln 2. Select "Build", and "Configuration Manager". To build release versions of C examples. In "Active Solution Configuration", select "Release". Select "Close". Select "Build" -> "Build Solution" or "Rebuild Solution" to build release version of project "allhlcexamples". When the release build is done, binaries will be built in the following subdirectories of c:\MyHDFstuff\hdf5\examples\ ex_image[1-2](dll) ex_lite1(dll) ex_table[01-12](dll) ex_ds1(dll) ptExample[FL+VL](dll) 3. Invoke a command prompt and run the batch file Install_hlcexamples.bat which resides in the top level directory (c:\MyHDFstuff\hdf5examples). This file creates new directories, HLCexamplesRELEASE, HLCexamplesRELEASEDLL in the c:\MyHDFstuff\hdf5examples\hl\examples directory and places all the executables in it. 4. We provide a batch file named test_hl_cexamples.bat in c:\MyHDFstuff\hdf5examples\hl\examples directory for you to test HDF5 high level C examples. test_hl_cexamples.bat batch file has options: Options purpose test_hl_cexamples release -- for release version test_hl_cexamples release dll -- for release DLL version Invoke a command prompt window and run test_hl_cexamples with appropriate options. Invoke a command prompt and run testExamples.bat with appropriate options. You should get "All of the HL C Examples Passed!" when the HL C examples are built successfully. Otherwise, the difference between the expected outputs and actual outputs will be given. ======================================================================== Section III: Building an application using the HDF5 library or DLL ======================================================================== Waring: The instructions below will only describe how to build an application using the release version of the HDF5 library or DLL. To use the debug version of the HDF5 library or DLL, you need to substitute the release version of the HDF5 library or DLL with the debug version. To build an application that uses the HDF5 static library the following locations will need to be specified for locating header files and linking with the HDF static library, for example: c:\MyHDFstuff\hdf5\hdf5lib\release\include c:\MyHDFstuff\hdf5\hdf5lib\release\lib We assume that you will use Zlib and Szip compression with HDF5 library. 1. Specifying Include Directories To specify the include directories in the settings for your Visual Studio project, you may choose one of the following two methods. Method One: Project-wide Settings 1. Open your project in Microsoft Visual Studio and make sure it is the active project. 2. Go to the Project menu and chose the "Properties" option. 3. Choose the build configuration you would like to modify in the drop down menu labeled "Configuration:" 4. Choose the "C/C++" tab, and select "General". 5. In a text-area labeled with "Additional Include Directories:", add HDF5, Zlib, and Szip header files directories. For example: c:\MyHDFstuff\hdf5\hdf5lib\release\include c:\zlib\include c:\szip\include Then click OK. 6. (Optional) To use HDF5 Fortran static library, the location of Fortran module files should be specified by following Project-> Settings->Fortran->Preprocessor, and in the text-area labeled "Additional Include Directories", add HDF5 Fortran module files directories. For example: c:\MyHDFstuff\hdf5\hdf5lib\release\include Method Two: Visual Studio Settings 1. In Visual STudio, go to Tools->Options->Projects-> VC++ Directories. Under "Show Directories For", select "Include files" 2. Insert the correct HDF5, Zlib, Szip paths for headers(include). For example, c:\MyHDFstuff\hdf5\hdf5lib\release\include c:\zlib\include c:\szip\include 2. Specifying Library Directories To specify the library directories in the settings for your Visual Studio project, you may choose one of the following two methods. Method One: Project-wide Settings 1. Open your project in Microsoft Visual Studio and make sure it is the active project. 2. Go to the Project menu and chose the "Properties" option. 3. Choose the build configuration you would like to modify in the drop down menu labeled "Configuration:" 4. Choose the "Linker" tab, and select "General". 5. In a text-area labeled with "Additional Library Directories:", add HDF5, Zlib, and Szip library files directories. For example: c:\MyHDFstuff\hdf5\hdf5lib\release\lib c:\zlib\dll c:\szip\dll Note: To link with HDF5 DLLs rathern that static libraries, simply specify the "dll" directory rather than "lib", and link with the corresponding DLL link library below. Then click OK. Method Two: Visual Studio Settings 1. In Visual STudio, go to Tools->Options->Projects-> VC++ Directories. Under "Show Directories For", select "Library files" 2. Insert the correct HDF5, Zlib, Szip paths for link libraries. For example, c:\MyHDFstuff\hdf5\hdf5lib\release\lib c:\zlib\dll c:\szip\dll Note: To link with HDF5 DLLs rathern that static libraries, simply specify the "dll" directory rather than "lib", and link with the corresponding DLL link library below. 3. Specifying Libraries to Link To link the HDF5 static library with your application: 1. In Visual Studio, go to the Project menu and choose "Properties". 2. Find the "Link" option and "Input" category. In the "Additional Dependencies" field, insert "zlib.lib, libszip.lib, hdf5.lib". 3. (Optional) Also insert "hdf5_cpp.lib" if you want to use HDF5 C++ static library. 4. (Optional) Also insert "hdf5_fortran.lib" if you want to use HDF5 Fortran static library. 5. (Optional) Also insert "hdf5_hl.lib" if you want to use HDF5 high level static library. 6. (Optional) Also insert "hdf5_hl_cpp.lib" if you want to use HDF5 High Level C++ static library. 7. (Optional) Also insert "hdf5_hl_fortran.lib" if you want to use HDF5 High Level Fortran static library. To link the HDF5 DLL library with your application: 1. Follow the steps for linking the HDF5 static library as shown above, except now link the export library that is created with the DLL. The export library is called hdf5dll.lib for HDF5 C libray, hdf5_cppdll.lib for HDF5 C++ library, and hdf5_fortrandll.lib for HDF5 Fortran library. 2. In the Project Properties dialog, go to the C/C++ > Preprocessor subsection. In the "Preprocessor Definitions" box, add "_HDF5USEDLL_" to the list. 3. (Optional) Also add HDF5CPP_USEDLL to use HDF5 C++ DLL. 4. (Optional) Also add _HDF5USEHLDLL_ to use HDF5 high level DLL. 5. (Optional) Also add HDF5USE_HLCPPDLL use HDF5 high level C++ DLL. 6. (Optional) Follow Project->Settings->Fortran->Category->General-> Predefined Preprocess or Symbols, and add "HDF5F90_WINDOWS" to use HDF5 Fortran DLL. 7. Place the DLLs in a location that Windows will be able to locate. The searched path and order for DLL's is a) The directory where the executable module for the current process is located. b) The current directory. c} The Windows system directory. The GetSystemDirectory function retrieves the path of this directory. d) The Windows directory. The GetWindowsDirectory function retrieves the path of this directory. e) The directories listed in the PATH environment variable. ======================================================================== Section IV: How to build HDF5 for 64-bit Windows ======================================================================== HDF5 is available for 64-bit Windows in Visual Studio 2008. Prerequisites: 1. A 64-bit Windows machine. 2. Microsoft Visual Studio 2008 installed with x64 Extensions. Building: Building 64-bit Windows binaries is very similar to the process for 32-bit. Therefore, you may follow the instructions in Section II with the following modifications. 1. The x64 platform must be selected in the build configuration for debug and release versions. Before building, go to "Build", "Configuration Manager". In the "Active solution platform" box, select "x64", and press "Close". 2. 64-bit HDF5 applications must be built with 64-bit external libraries. You must add the include and library paths for x64 configurations as you have in the "Prerequisites" section. This is also true for Intel Fortran if Fortran libraries are to be built. ======================================================================== Section V: How to build HDF5 applications using Visual Studio 2010 ======================================================================== Building with Visual Studio 2010 is very similar to building with Visual Studio 2008, with some minor changes. Therefore, follow the build instructions above, with the following considerations: 1. Visual Studio 2010 uses a new format for project files, but Visual Studio 2008 project files can be converted. The HDF5 project files will need to be converted on first use. To do so: 1.1. Open the HDF5 Visual Studio 2008 solution file as in Section II (all.sln) NOTE. Intel Fortran 11.1 currently does not integrate with Visual Studio 2010. 1.2. You will be prompted with an automatic conversion wizard. Click through, accepting the default values. You may choose to create backups of the project files, although it isn't necessary. 1.3. When it is finished, it should state that all projects were converted successfully with no errors. Warnings can be ignored. 2. Once the project files have been converted you will need to create project property sheets for the library and include paths. Then build and test normally. Note that the converted project files aren't backwards compatible with previous versions of Visual Studio. ======================================================================== Section VI: Misc. ======================================================================== 1. Helpful Pointers Here are some helpful notes if you are not familiar with using the Visual C++ Development Environment. 1.1 Project name and location issues: It is recommended that you use the given directory structure for building HDF5 Examples. However, it is possible to create your own structure. If you must install all.sln and all.vcproj in another directory, relative to hdf5 directory, you will be asked to locate the sub-project files, when you open the project all.sln. If you want to rename "all" (the entire project), you will need to modify two files all.sln and all.vcproj as text (contrary to the explicit warnings in the files). 1.2 Settings... details: If you create your own project, the necessary settings can be read from the all.vcproj file (as text), or from the Project Settings in the Visual Studio project settings dialog. 1.3 FAQ Many other common questions and hints are located online and being updated in the HDF5 FAQ. For Windows-specific questions, please see: http://www.hdfgroup.uiuc.edu/windows/faq.html For all other general questions, you can look in the general FAQ: http://hdfgroup.org/HDF5-FAQ.html ************************************************************************ Please send email to help@hdfgroup.org for further assistance.