/************************************************************ This example shows how to read data from a LOSC data file using C. LOSC data can be found at: https://losc.ligo.org This example was adopted from example code on the HDF Group web site: http://www.hdfgroup.org See the HDF Group web site for more information. This file is intended for use with HDF5 Library version 1.6 Adopted by Jonah Kanner, September 2014 ************************************************************/ #include "hdf5.h" #include #include /* LOSC data files may be downloaded from the LOSC web site: https://losc.ligo.org */ #define FILE "H-H2_LOSC_4_V1-842665984-4096.hdf5" #define DATASET "/quality/simple/DQmask" #define S_DATASET "/strain/Strain" #define DIM0 1 #define DIM1 4096 #define DIM2 16777216 int main (void) { hid_t file, dset; /* Handles */ herr_t status; unsigned dq_data[DIM1]; double * strain_data = malloc(DIM2 * sizeof(double)); int j; /* ------------------------ * * Read in the DQ bitmask * * ------------------------ */ // Open file and dataset using the default properties file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT); dset = H5Dopen (file, DATASET); // Read the DQ bit mask status = H5Dread (dset, H5T_NATIVE_UINT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dq_data); // Output the first few DQ bit mask values printf ("%s:\n", DATASET); printf (" ["); for (j=0; j<10; j++) { printf (" %3d", dq_data[j]); } printf (" ... ]\n"); // Calculate the livetime int livetime = 0; for (j=0; j 0) { livetime++; } } printf ("The total live time for this 4096 s file is: %d seconds\n", livetime); // Close and release resources. status = H5Dclose (dset); /* ------------------------ * * Read in the strain data * * ------------------------ */ // Open the data set dset = H5Dopen (file, S_DATASET); // Read in the strain data status = H5Dread (dset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, strain_data); // Print the first few strain values printf ("%s:\n", S_DATASET); printf (" ["); for (j=0; j<10; j++) { printf (" %e", strain_data[j]); } printf (" ... ]\n"); /* Close up and go home */ status = H5Dclose (dset); status = H5Fclose (file); return 0; }