~ubuntu-branches/ubuntu/utopic/hdf-eos4/utopic-proposed

« back to all changes in this revision

Viewing changes to samples/WriteAllDimscaleGrid.c

  • Committer: Package Import Robot
  • Author(s): Alastair McKinstry
  • Date: 2014-07-17 19:41:00 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140717194100-nun00p57u3zvdu0i
Tags: 2.19v1.00+dfsg.1-1
* New upstream release. Closes: #754467.
* Now at Standards-Version: 3.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "hdf.h"
 
2
#include "HdfEosDef.h"
 
3
 
 
4
/*
 
5
 * In this example we will (1) open the "GridFile" HDF file, (2) attach to
 
6
 * the "Grid1" grid, and (3) set dimension scale for a dimension in all filed of a grid.
 
7
 */
 
8
 
 
9
 
 
10
main()
 
11
{
 
12
 
 
13
    intn            status, i, j;
 
14
    int32           gdfid, GDid1, GDid2, GDid3;
 
15
    int32           xdim, ydim;
 
16
    int32           ntime;
 
17
    int32           nbands;
 
18
    int32           data[10]={3,6,9,12,15,18,23,26,29,32};
 
19
    int32           bands[10]={12,14,18};
 
20
    char            label[16];
 
21
    char            unit[16];
 
22
    char            format[16];
 
23
 
 
24
    /*
 
25
     * We first open the HDF grid file, "GridFile.hdf".  Because this file
 
26
     * already exist and we wish to write to it, we use the DFACC_RDWR access
 
27
     * code in the open statement.  The GDopen routine returns the grid file
 
28
     * id, gdfid, which is used to identify the file in subsequent routines.
 
29
     */
 
30
 
 
31
    gdfid = GDopen("GridFile_created_with_hadeos_sample_file_writer_of_HDFEOS2_version_219_or_higher_release.hdf", DFACC_RDWR);
 
32
 
 
33
 
 
34
    /*
 
35
     * If the grid file cannot be found, GDopen will return -1 for the file
 
36
     * handle (gdfid).  We there check that this is not the case before
 
37
     * proceeding with the other routines.
 
38
     * 
 
39
     * The GDattach routine returns the handle to the existing grid "Grid1",
 
40
     * GDid.  If the grid is not found, GDattach returns -1 for the handle.
 
41
     */
 
42
 
 
43
    if (gdfid != -1)
 
44
    {
 
45
        /* the field Pollution has Time,YDim,XDim dimensions. 
 
46
           see SetupGrid.c and DefineGDflds.c 
 
47
           xdim = 120;
 
48
           ydim = 200;
 
49
           Time dim is set to 10
 
50
        */
 
51
 
 
52
        GDid1 = GDattach(gdfid, "UTMGrid");
 
53
        if (GDid1 == -1)
 
54
          {
 
55
            printf("\t\tError: Cannot attach to grid \"UTMGrid\"\n");
 
56
            GDclose(gdfid);
 
57
            return -1;
 
58
          }
 
59
 
 
60
        xdim = 120;
 
61
        ntime = 10;
 
62
        
 
63
        status = GDdefdimscale(GDid1, "XDim", xdim, DFNT_FLOAT64, NULL);
 
64
        if (status == -1)
 
65
          {
 
66
            printf("\t\tError: Cannot set Dimension Scale for XDim dimemnsion in field \"Pollution\"\n");
 
67
            GDdetach(GDid1);
 
68
            GDclose(gdfid);
 
69
            return -1;
 
70
          }
 
71
 
 
72
        status = GDdefdimscale(GDid1, "Time", ntime, DFNT_INT32, data);
 
73
        if (status == -1)
 
74
          {
 
75
            printf("\t\tError: Cannot set Dimension Scale for Time dimemnsion in field \"Pollution\"\n");
 
76
            GDdetach(GDid1);
 
77
            GDclose(gdfid);
 
78
            return -1;
 
79
          }
 
80
 
 
81
        strcpy(label, "X Dimension");
 
82
        strcpy(unit, "meters");
 
83
        strcpy(format, "F7.2");
 
84
 
 
85
        status = GDdefdimstrs(GDid1, "XDim", label, unit, format);
 
86
        if (status == -1)
 
87
          {
 
88
            printf("\t\tError: Cannot set Dimension Scale strs for XDim dimemnsion in field \"Pollution\"\n");
 
89
            GDdetach(GDid1);
 
90
            GDclose(gdfid);
 
91
            return -1;
 
92
          }
 
93
 
 
94
        strcpy(label, "Time Dim");
 
95
        strcpy(unit, "s");
 
96
        strcpy(format, "I3");
 
97
 
 
98
        status = GDdefdimstrs(GDid1, "Time", label, unit, format);
 
99
        if (status == -1)
 
100
          {
 
101
            printf("\t\tError: Cannot set Dimension Scale strs for Time dimemnsion in field \"Pollution\"\n");
 
102
            GDdetach(GDid1);
 
103
            GDclose(gdfid);
 
104
            return -1;
 
105
          }
 
106
 
 
107
        GDdetach(GDid1);
 
108
 
 
109
        /* the field Spectra has Bands,YDim,XDim dimensions. 
 
110
           see SetupGrid.c and DefineGDflds.c
 
111
           xdim = 100;
 
112
           ydim = 100;
 
113
           Bands dim is set to 3
 
114
        */
 
115
        
 
116
        GDid2 = GDattach(gdfid, "PolarGrid");
 
117
        if (GDid2 == -1)
 
118
          {
 
119
            printf("\t\tError: Cannot attach to grid \"PolarGrid\"\n");
 
120
            GDclose(gdfid);
 
121
            return -1;
 
122
          }
 
123
        
 
124
        ydim = 100;
 
125
        nbands = 3;
 
126
        
 
127
        status = GDdefdimscale(GDid2, "YDim", ydim, DFNT_FLOAT64, NULL);
 
128
        if (status == -1)
 
129
          {
 
130
            printf("\t\tError: Cannot set Dimension Scale for YDim dimemnsion in field \"Spectra\"\n");
 
131
            GDdetach(GDid2);
 
132
            GDclose(gdfid);
 
133
            return -1;
 
134
          }
 
135
 
 
136
 
 
137
        status = GDdefdimscale(GDid2, "Bands", nbands, DFNT_INT32, bands);
 
138
        if (status == -1)
 
139
          {
 
140
            printf("\t\tError: Cannot set Dimension Scale for Bands dimemnsion in field \"Spectra\"\n");
 
141
            GDdetach(GDid2);
 
142
            GDclose(gdfid);
 
143
            return -1;
 
144
          }
 
145
 
 
146
 
 
147
        strcpy(label, "Y Dimension");
 
148
        strcpy(unit, "meters");
 
149
        strcpy(format, "F7.2");
 
150
 
 
151
        status = GDdefdimstrs(GDid2, "YDim", label, unit, format);
 
152
        if (status == -1)
 
153
          {
 
154
            printf("\t\tError: Cannot set Dimension Scale strs for YDim dimemnsion in field \"Spectra\"\n");
 
155
            GDdetach(GDid2);
 
156
            GDclose(gdfid);
 
157
            return -1;
 
158
          }
 
159
 
 
160
        strcpy(label, "Bands");
 
161
        strcpy(unit, "None");
 
162
        strcpy(format, "I2");
 
163
 
 
164
        status = GDdefdimstrs(GDid2, "Bands", label, unit, format);
 
165
        if (status == -1)
 
166
          {
 
167
            printf("\t\tError: Cannot set Dimension Scale strs for Bands dimemnsion in field \"Spectra\"\n");
 
168
            GDdetach(GDid2);
 
169
            GDclose(gdfid);
 
170
            return -1;
 
171
          }
 
172
 
 
173
    }
 
174
 
 
175
        GDdetach(GDid2);
 
176
 
 
177
    /* the field GeoSpectra has YDim,XDim dimensions. 
 
178
       see SetupGrid.c and DefineGDflds.c
 
179
       xdim = 100;
 
180
       ydim = 100;
 
181
       Bands dim is set to 3
 
182
    */
 
183
 
 
184
    xdim = 60;
 
185
    ydim = 40;
 
186
 
 
187
    GDid3 = GDattach(gdfid, "GEOGrid");
 
188
    if (GDid3 == -1)
 
189
      {
 
190
        printf("\t\tError: Cannot attach to grid \"GEOGrid\"\n");
 
191
        GDclose(gdfid);
 
192
        return -1;
 
193
      }
 
194
    status = GDdefdimscale(GDid3, "YDim", ydim, DFNT_FLOAT64, NULL);
 
195
    if (status == -1)
 
196
      {
 
197
        printf("\t\tError: Cannot set Dimension Scale for YDim dimemnsion in field \"GeoSpectra\"\n");
 
198
        GDdetach(GDid3);
 
199
        GDclose(gdfid);
 
200
        return -1;
 
201
      }
 
202
    
 
203
    strcpy(label, "Y Dimension");
 
204
    strcpy(unit, "Decimal Degrees");
 
205
    strcpy(format, "F7.2");
 
206
    
 
207
    status = GDdefdimstrs(GDid3, "YDim", label, unit, format);
 
208
    if (status == -1)
 
209
      {
 
210
        printf("\t\tError: Cannot set Dimension Scale strs for YDim dimemnsion in field \"GeoSpectra\"\n");
 
211
        GDdetach(GDid3);
 
212
        GDclose(gdfid);
 
213
        return -1;
 
214
      }
 
215
    
 
216
 
 
217
    GDdetach(GDid3);
 
218
    GDclose(gdfid);
 
219
 
 
220
    return 0;
 
221
}