File: tst_h_endian_float.c

package info (click to toggle)
netcdf 1:4.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 104,952 kB
  • sloc: ansic: 228,683; sh: 10,980; yacc: 2,561; makefile: 1,319; lex: 1,173; xml: 173; awk: 2
file content (83 lines) | stat: -rw-r--r-- 2,434 bytes parent folder | download | duplicates (3)
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
/* This is part of the netCDF package.
   Copyright 2018 University Corporation for Atmospheric Research/Unidata
   See COPYRIGHT file for conditions of use.

   Test HDF5 file code. These are not intended to be exhaustive tests,
   but they use HDF5 the same way that netCDF-4 does, so if these
   tests don't work, than netCDF-4 won't work either.

   This files tests dataset creation and writing.
*/

#include "h5_err_macros.h"
#include <hdf5.h>

#define FILE_NAME "tst_h_endian_float.h5"
#define GRP_NAME "Henry_V"
#define VAR_BOOL_NAME "Southhamptons_Battle_Record"
#define GRP2_NAME "Some_3D_Met_Data"
#define DIM1_LEN 3
#define MAX_DIMS 255

int
main()
{
  hid_t fileid, grpid, spaceid, datasetid;
  int bool_out[DIM1_LEN] = {0, 1, 0};
  hsize_t dims[1];

  printf("*** Checking HDF5 endianness control...");

#define NATIVE_VAR_NAME "native_var"
#define LE_VAR_NAME "le_var"
#define BE_VAR_NAME "be_var"
  #define LAT_LEN 2
#define LON_LEN 3
#define NDIMS 3
#define LAT_NAME "Lat"
#define LON_NAME "Lon"
#define TIME_NAME "Time"
#define PRES_NAME "Pressure"
#define TEMP_NAME "Temperature"
  {
    int data[DIM1_LEN], data_in[DIM1_LEN];
    hid_t typeid, native_typeid;
    hid_t native_did, le_did, be_did;
    H5T_order_t order;
    htri_t equal;
    int i;
    float float_data_out[LAT_LEN][LON_LEN];
    int lat, lon;

   for (lat = 0; lat < LAT_LEN; lat++)
	 for (lon = 0; lon < LON_LEN; lon++)
	    float_data_out[lat][lon] = -666.666;

    /* Open file and create group. */
    if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT,
                            H5P_DEFAULT)) < 0) ERR;
    if ((grpid = H5Gcreate(fileid, GRP_NAME, 0)) < 0) ERR;

    /* Create a dataset of native endian. */
    dims[0] = DIM1_LEN;
    if ((spaceid = H5Screate_simple(1, dims, dims)) < 0) ERR;
    if ((native_did = H5Dcreate(grpid, NATIVE_VAR_NAME, H5T_STD_I32BE,
                                spaceid, H5P_DEFAULT)) < 0) ERR;
    if ((le_did = H5Dcreate(grpid, LE_VAR_NAME, H5T_IEEE_F32LE,
                            spaceid, H5P_DEFAULT)) < 0) ERR;
    if ((be_did = H5Dcreate(grpid, BE_VAR_NAME, H5T_IEEE_F32BE,
                            spaceid, H5P_DEFAULT)) < 0) ERR;

    if (H5Dclose(native_did) < 0 ||
        H5Dclose(le_did) < 0 ||
        H5Dclose(be_did) < 0 ||
        H5Sclose(spaceid) < 0 ||
        H5Gclose(grpid) < 0 ||
        H5Fclose(fileid) < 0)
      ERR;

  }

  SUMMARIZE_ERR;
  FINAL_RESULTS;
}