/************************************************************ This example shows how to set the fill value for a dataset. The program first sets the fill value to FILLVAL, creates a dataset with dimensions of DIM0xDIM1, reads from the uninitialized dataset, and outputs the contents to the screen. Next, it writes integers to the dataset, reads the data back, and outputs it to the screen. Finally it extends the dataset, reads from it, and outputs the result to the screen. ************************************************************/ #include "hdf5.h" #include #include #include #define FILE1 "h5ex_d_fillval1.h5" #define FILE2 "h5ex_d_fillval2.h5" #define DATASET "DS1" #define DIM0 4 #define DIM1 7 #define EDIM0 6 #define EDIM1 10 #define CHUNK0 4 #define CHUNK1 4 #define FILLVAL 99 #define MAX_THREADS 2 DWORD WINAPI myFunction(LPVOID lpParam); struct myData { hid_t file; }; struct myData dataArray[MAX_THREADS]; DWORD WINAPI myFunction(hid_t file) { printf("in thread\n"); // something is going wrong with extracting the args //struct myData *my_data; //my_data = (struct myData*)lpParam; hsize_t dims[2] = { DIM0, DIM1 }; hsize_t maxdims[2] = { H5S_UNLIMITED, H5S_UNLIMITED }; hsize_t chunk[2] = { CHUNK0, CHUNK1 }; //hid_t file = my_data->file; int rdata[DIM0][DIM1]; int wdata[DIM0][DIM1]; printf(file); /* * Initialize data. */ for (int i = 0; i < DIM0; i++) for (int j = 0; j < DIM1; j++) wdata[i][j] = i * j - j; printf("generated data\n"); /* * Create dataspace with unlimited dimensions. */ int space = H5Screate_simple(2, dims, maxdims); /* * Create the dataset creation property list, and set the chunk * size. */ int dcpl = H5Pcreate(H5P_DATASET_CREATE); herr_t status = H5Pset_chunk(dcpl, 2, chunk); /* * Set the fill value for the dataset. */ int fillval = FILLVAL; status = H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval); /* * Set the allocation time to "early". This way we can be sure * that reading from the dataset immediately after creation will * return the fill value. */ status = H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY); /* * Create the dataset using the dataset creation property list. */ int dset = H5Dcreate(file, DATASET, H5T_STD_I32LE, space, H5P_DEFAULT, dcpl, H5P_DEFAULT); /* * Read values from the dataset, which has not been written to yet. */ status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata[0]); /* * Output the data to the screen. */ printf("Dataset before being written to:\n"); for (int i = 0; i < dims[0]; i++) { printf(" ["); for (int j = 0; j < dims[1]; j++) printf(" %3d", rdata[i][j]); printf("]\n"); } /* * Write the data to the dataset. */ status = H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata[0]); /* * Read the data back. */ status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata[0]); /* * Output the data to the screen. */ printf("\nDataset after being written to:\n"); for (int i = 0; i < dims[0]; i++) { printf(" ["); for (int j = 0; j < dims[1]; j++) printf(" %3d", rdata[i][j]); printf("]\n"); } /* * Extend the dataset. */ // status = H5Dset_extent(dset, extdims); /* * Read from the extended dataset. */ // status = H5Dread(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, // rdata2[0]); /* * Output the data to the screen. */ //printf("\nDataset after extension:\n"); //for (i = 0; i < extdims[0]; i++) { //printf(" ["); //for (j = 0; j < extdims[1]; j++) //printf(" %3d", rdata2[i][j]); //printf("]\n"); //} /* * Close and release resources. */ status = H5Pclose(dcpl); status = H5Dclose(dset); status = H5Sclose(space); status = H5Fclose(file); return 0; } int main(void) { hid_t file1, file2, space, dset, dcpl; /* Handles */ herr_t status; hsize_t dims[2] = { DIM0, DIM1 }, extdims[2] = { EDIM0, EDIM1 }, maxdims[2] = { H5S_UNLIMITED, H5S_UNLIMITED }, chunk[2] = { CHUNK0, CHUNK1 }; int wdata[DIM0][DIM1], /* Write buffer */ rdata[DIM0][DIM1], /* Read buffer */ rdata2[EDIM0][EDIM1], /* Read buffer for extenstion */ fillval; hsize_t i, j; HANDLE hThreads[MAX_THREADS]; DWORD dwThreadIdArray[MAX_THREADS]; /* * Initialize data. */ //for (i = 0; i < DIM0; i++) // for (j = 0; j < DIM1; j++) // wdata[i][j] = i * j - j; //printf("made data\n"); /* * Create a new file using the default properties. */ file1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); file2 = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); printf("created both files\n"); hid_t files[2] = { file1, file2 }; for (int i = 0; i < MAX_THREADS; i++) { dataArray[i].file = files[i]; hThreads[i] = CreateThread( NULL, 0, myFunction, &files[i], 0, &dwThreadIdArray[i] ); if (hThreads[i] == NULL) { printf("CreateThread error: %d\n", GetLastError()); return; } } WaitForMultipleObjects(MAX_THREADS, hThreads, TRUE, INFINITE); printf("Closing threads\n"); for (int i = 0; i < MAX_THREADS; i++) { CloseHandle(hThreads[i]); } }