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
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF. The full HDF copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdlib.h>
#include "mfhdf.h"
#define FILE2_NAME "SDSfloat2.hdf"
#define FILE3_NAME "SDSfloat3.hdf"
#define SDS1_NAME "SDStemplate"
#define SDS2_NAME "SDStemplate again"
#define X_LENGTH 6
#define Y_LENGTH 9
#define Z_LENGTH 2
#define RANK2 2 /* Number of dimensions of the SDS */
#define RANK3 3 /* Number of dimensions of the SDS */
int
main()
{
/************************* Variable declaration ************************/
int32 sd2_id, sd3_id, sds1_id, sds2_id;
int32 dim2_sizes[2]; /* sizes of the 2-dim SDS dimensions */
int32 dim3_sizes[3]; /* sizes of the 3-dim SDS dimensions */
int32 start2[2], start3[3]; /* start arrays for both SDSs */
float32 in2_data[X_LENGTH][Y_LENGTH] = {/* input for 2-dim SDS */
{100.0, 100.0, 200.0, 200.0, 300.0, 400.0, 100.0, 100.0, 200.0},
{200.0, 300.0, 400.0, 100.0, 100.0, 200.0, 200.0, 300.0, 400.0},
{300.0, 300.0, 0.0, 400.0, 300.0, 400.0, 300.0, 300.0, 0.0},
{400.0, 300.0, 400.0, 300.0, 300.0, 0.0, 400.0, 300.0, 400.0},
{0.0, 0.0, 600.0, 600.0, 300.0, 400.0, 500.0, 500.0, 600.0},
{600.0, 300.0, 400.0, 0.0, 0.0, 600.0, 600.0, 300.0, 400.0}};
float32 in3_data[X_LENGTH][Y_LENGTH][Z_LENGTH] = {/* input for 3-dim SDS */
{{100.0, 100.0},
{200.0, 200.0},
{300.0, 400.0},
{100.0, 100.0},
{200.0, 200.0},
{300.0, 400.0},
{100.0, 100.0},
{200.0, 200.0},
{300.0, 400.0}},
{{300.0, 300.0},
{0.0, 400.0},
{300.0, 400.0},
{300.0, 300.0},
{0.0, 400.0},
{300.0, 400.0},
{300.0, 300.0},
{0.0, 400.0},
{300.0, 400.0}},
{{0.0, 0.0},
{600.0, 600.0},
{300.0, 400.0},
{500.0, 500.0},
{600.0, 600.0},
{300.0, 400.0},
{0.0, 0.0},
{600.0, 600.0},
{300.0, 400.0}},
{{1.0, 1.0},
{2.0, 2.0},
{3.0, 4.0},
{1.0, 1.0},
{2.0, 2.0},
{3.0, 4.0},
{1.0, 1.0},
{2.0, 2.0},
{3.0, 4.0}},
{{3.0, 3.0},
{0.0, 4.0},
{3.0, 4.0},
{3.0, 3.0},
{0.0, 4.0},
{3.0, 4.0},
{3.0, 3.0},
{0.0, 4.0},
{3.0, 4.0}},
{{0.0, 0.0},
{6.0, 6.0},
{3.0, 4.0},
{5.0, 5.0},
{6.0, 6.0},
{3.0, 4.0},
{0.0, 0.0},
{6.0, 6.0},
{3.0, 4.0}}};
/********************* End of variable declaration ***********************/
/*
* Create the files and initialize the SD interface.
*/
sd2_id = SDstart(FILE2_NAME, DFACC_CREATE);
sd3_id = SDstart(FILE3_NAME, DFACC_CREATE);
/*
* Define the dimensions/origins of the two SDSs to be created.
*/
dim2_sizes[0] = Y_LENGTH;
dim2_sizes[1] = X_LENGTH;
dim3_sizes[0] = Z_LENGTH;
dim3_sizes[1] = Y_LENGTH;
dim3_sizes[2] = X_LENGTH;
start2[0] = start2[1] = 0;
start3[0] = start3[1] = start3[2] = 0;
/*
* Create two data sets, SDS1_NAME and SDS2_NAME, with type DFNT_FLOAT32
* in the two files, FILE2_NAME and FILE3_NAME.
*/
sds1_id = SDcreate(sd2_id, SDS1_NAME, DFNT_FLOAT32, RANK2, dim2_sizes);
sds2_id = SDcreate(sd3_id, SDS2_NAME, DFNT_FLOAT32, RANK3, dim3_sizes);
/* Write data to the SDSs */
SDwritedata(sds1_id, start2, NULL, dim2_sizes, (void *)in2_data);
SDwritedata(sds2_id, start3, NULL, dim3_sizes, (void *)in3_data);
/*
* Terminate access to the data sets.
*/
SDendaccess(sds1_id);
SDendaccess(sds2_id);
/*
* Terminate access to the SD interface and close the files.
*/
SDend(sd2_id);
SDend(sd3_id);
return EXIT_SUCCESS;
}
|