![]() |
HDF User’s GuideVersion 4.2r4 |
[Top] [Prev][Next] |
dfsd_ex1.c#include "hdf.h" #define LENGTH 3 #define HEIGHT 2 #define WIDTH 5 main( ) { /* Create data array - store dimensions in array 'dims' */ static float64 scien_data[LENGTH][HEIGHT][WIDTH] = { 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. }; intn status; int32 dims[3] = {LENGTH, HEIGHT, WIDTH}; /* Set number type to 64-bit float */ status = DFSDsetNT(DFNT_FLOAT64); /* Write the data to file */ status = DFSDadddata("Example1.hdf", 3, dims, scien_data); }dfsd_ex1.fPROGRAM WRITE SDS integer dsadata, dssnt, dims(3), status real*8 sci_data(5,2,3) C Create array called 'sci_data'; store dimensions in array 'dims'. data sci_data/ 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./ data dims /3,2,5/ C Set number type to 64-bit float status = dssnt(6) C Write the data to file status = dsadata('Example1.hdf', 3, dims, sci_data) enddfsd_ex2.c#include "hdf.h" #define LENGTH 3 #define HEIGHT 2 #define WIDTH 5 main( ) { float64 scien_data[LENGTH][HEIGHT][WIDTH]; int32 number_type; intn rank, status; int32 dims[3]; /* Get the dimensions and number type of the array */ status = DFSDgetdims("Example1.hdf", &rank, dims, 3); status = DFSDgetNT(&number_type); /* Read the array if the dimensions are correct */ if (dims[0] <= LENGTH && dims[1] <= HEIGHT && dims[2] <= WIDTH) status = DFSDgetdata("Example1.hdf", rank, dims, scien_data); }dfsd_ex2.fPROGRAM READ SDS integer dsgdata, dsgdims, dsgnt, dims(3), status integer rank, num_type real*8 sci_data(5, 2, 3) C Get the dimensions and number type of the array. status = dsgdims('Example1.hdf', rank, dims, 3) status = dsgnt(num_type) C Read the array if the dimensions are correct. if ((dims(1) .eq. 3) .and. (dims(2) .eq. 2) .and. + (dims(3) .eq. 5)) then status = dsgdata('Example1.hdf', rank, dims, sci_data) endif enddfsd_ex3.c#include "hdf.h" /* * Write an array of floating point values representing * pressure in a 3x2x5 array. */ main( ) { float32 data[3][2][5]; int32 dimsizes[3]; float32 max, min; intn status, rank; int i, j, k; /* Set the rank and dimension sizes. */ rank = 3; dimsizes[0] = 3; dimsizes[1] = 2; dimsizes[2] = 5; /* Set the dimensions, to define the beginning of a data set. */ status = DFSDsetdims(rank, dimsizes); /* Set the maximum string length to 50. */ status = DFSDsetlengths(50, 50, 50, 50); /* Define the attribute strings and values. */ status = DFSDsetdatastrs("Pressure Data", "Millibars", "F5.5", "None"); max = 1500.0; min = 0.0; status = DFSDsetrange(&max, &min); /* Set the rank to 3. */ rank = 3; /* Calculate the data values. */ for (i = 0; i < 3; i++) for (j = 0; j < 2; j++) for (k = 0; k < 5; k++) data[i][j][k] = i*100.0 + j*10.0 + k; /* Write the data set and its attributes to file. */ status = DFSDadddata("Example3.hdf", rank, dimsizes, data); }dfsd_ex3.fPROGRAM SET ATTRIBS real*8 data(5, 2, 3), max, min, i, j, k integer*4 dimsizes(3) integer status, rank integer dsslens, dssdast, dssrang, dsadata integer dssdims character*13 label /"Pressure Data"/ character*9 unit /"Millibars"/ character*4 format /"F5.5"/ character*4 coordsys /"None"/ C Set the dimensions, to define the beginning of a data set. rank = 3 dimsizes(1) = 5 dimsizes(2) = 2 dimsizes(3) = 3 status = dssdims(rank, dimsizes) C Set the maximum string lengths to 50. status = dsslens(50, 50, 50, 50) C Define the attribute strings and values. status = dssdast(label, unit, format, coordsys) max = 1500.0 min = 0.0 status = dssrang(max, min) C Fill the data array with values. do 30 k = 1, 3 do 20 j = 1, 2 do 10 i = 1, 5 data(i, j, k) = i*100.0 + j*10.0 + k 10 continue 20 continue 30 continue C Write the data set and its attributes to file. status = dsadata("Example3.hdf", rank, dimsizes, data) enddfsd_ex4.c#include "hdf.h" main( ) { intn rank, maxrank, status; int32 dimsizes[3]; char datalabel[50], dataunit[50], datafmt[50], coordsys[50]; float64 data[3][2][5]; maxrank = 3; status = DFSDgetdims("Example3.hdf", &rank, dimsizes, maxrank); status = DFSDgetdatastrs(datalabel, dataunit, datafmt, coordsys); status = DFSDgetdata("Example3.hdf", rank, dimsizes, data); }dfsd_ex4.fPROGRAM READ SD INFO integer dsgdata, dsgdast, dsgdims integer*4 dimsizes(3) integer status, rank, maxrank character*50 datalabel, dataunit, datafmt character*10 coordsys real*8 data(5, 2, 3) maxrank = 3 status = dsgdims('Example3.hdf', rank, dimsizes, maxrank) status = dsgdast(datalabel, dataunit, datafmt, coordsys) status = dsgdata('Example3.hdf', rank, dimsizes, data) end
HDF4.2r4 - February 2009 Copyright |
The HDF Group www.hdfgroup.org ![]() |