File: DefineGDflds.c

package info (click to toggle)
hdf-eos4 3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,960 kB
  • sloc: ansic: 43,570; sh: 11,324; fortran: 9,649; makefile: 261
file content (167 lines) | stat: -rw-r--r-- 4,363 bytes parent folder | download | duplicates (5)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "hdf.h"
#include "HdfEosDef.h"

/*
 * In this example we will (1) open the "GridFile" HDF file, (2) attach to
 * the "Grid1" grid, and (3) define the grid fields.
 */


main()
{

    intn            status, i, j;
    int32           gdfid, GDid1, GDid2, GDid3, nflds;
    int32           dims[8], start[8], count[8];
    
    float32         fillval1=-7.0, fillval2=-9999.0, f32;
    float32         datbuf[100000];
    
    char            fieldlist[255];
    

    /*
     * We first open the HDF grid file, "GridFile.hdf".  Because this file
     * already exist and we wish to write to it, we use the DFACC_RDWR access
     * code in the open statement.  The GDopen routine returns the grid file
     * id, gdfid, which is used to identify the file in subsequent routines.
     */

    gdfid = GDopen("GridFile_created_with_hadeos_sample_file_writer_of_HDFEOS2_version_219_or_higher_release.hdf", DFACC_RDWR);


    /*
     * If the grid file cannot be found, GDopen will return -1 for the file
     * handle (gdfid).  We there check that this is not the case before
     * proceeding with the other routines.
     * 
     * The GDattach routine returns the handle to the existing grid "Grid1",
     * GDid.  If the grid is not found, GDattach returns -1 for the handle.
     */

    if (gdfid != -1)
    {

	GDid1 = GDattach(gdfid, "UTMGrid");
	if (GDid1 == -1)
	  {
	    printf("\t\tError: Cannot attach to grid \"UTMGrid\"\n");
	    return -1;
	  }

	status = GDdeffield(GDid1, "Pollution", "Time,YDim,XDim",
			    DFNT_FLOAT32, HDFE_NOMERGE);
	if (status == -1)
	  {
	    printf("\t\tError: Cannot define field \"Pollution\"\n");
	    return -1;
	  }
	status = GDdeffield(GDid1, "Vegetation", "YDim,XDim",
			    DFNT_FLOAT32, HDFE_NOMERGE);
	if (status == -1)
	  {
	    printf("\t\tError: Cannot define field \"Vegetation\"\n");
	    return -1;
	  }
	status = GDwritefieldmeta(GDid1, "Extern", "YDim,XDim",
				  DFNT_FLOAT32);
	if (status == -1)
	  {
	    printf("\t\tError: Cannot define external field \"Extern\"\n");
	    return -1;
	  }
	status = GDsetfillvalue(GDid1, "Pollution", &fillval1);
	if (status == -1)
	  {
	    printf("\t\tError: Cannot set fill value for \"Pollution\"\n");
	    return -1;
	  }

	

	GDid2 = GDattach(gdfid, "PolarGrid");
	if (GDid2 == -1)
	  {
	    printf("\t\tError: Cannot attach to grid \"PolarGrid\"\n");
	    return -1;
	  }
	status = GDdeffield(GDid2, "Temperature", "YDim,XDim",
			    DFNT_FLOAT32, HDFE_AUTOMERGE);
	if (status == -1)
	  {
	    printf("\t\tError: Cannot define field \"Temperature\"\n");
	    return -1;
	  }
	status = GDdeffield(GDid2, "Pressure", "YDim,XDim",
			    DFNT_FLOAT32, HDFE_AUTOMERGE);
	if (status == -1)
	  {
	    printf("\t\tError: Cannot define field \"Pressure\"\n");
	    return -1;
	  }
	status = GDdeffield(GDid2, "Soil Dryness", "YDim,XDim",
				DFNT_FLOAT32, HDFE_NOMERGE);
	if (status == -1)
	  {
	    printf("\t\tError: Cannot define field \"Soil Dryness\"\n");
	    return -1;
	  }
	status = GDdeffield(GDid2, "Spectra", "Bands,YDim,XDim",
			    DFNT_FLOAT64, HDFE_AUTOMERGE);
	if (status == -1)
	  {
	    printf("\t\tError: Cannot define field \"Spectra\"\n");
	    return -1;
	  }
	status = GDsetfillvalue(GDid2, "Pressure", &fillval2);
	if (status == -1)
	  {
	    printf("\t\tError: Cannot define fill value for field \"Pressure\"\n");
	    return -1;
	  }
    }

    GDdetach(GDid1);
    GDdetach(GDid2);

    GDid2 = GDattach(gdfid, "PolarGrid");
    if (GDid2 == -1)
      {
	printf("\t\tError: Cannot attach to grid \"PolarGrid\"\n");
	return -1;
      }
    status = GDreadfield(GDid2, "Pressure", NULL, NULL, NULL, datbuf);
    if (status == -1)
      {
	printf("\t\tError: Cannot read field \"Pressure\"\n");
	return -1;
      }
    GDdetach(GDid2);



    GDid3 = GDattach(gdfid, "GEOGrid");
    if (GDid3 == -1)
      {
	printf("\t\tError: Cannot attach to grid \"GEOGrid\"\n");
	return -1;
      }
    status = GDdeffield(GDid3, "GeoSpectra", "YDim,XDim",
			DFNT_FLOAT64, HDFE_AUTOMERGE);
    if (status == -1)
      {
	printf("\t\tError: Cannot define field \"GeoSpectra\"\n");
	return -1;
      }
    status = GDsetfillvalue(GDid3, "GeoSpectra", &fillval2);
    if (status == -1)
      {
	printf("\t\tError: Cannot define fill value for field \"Pressure\"\n");
	return -1;
      }

    GDdetach(GDid3);
    GDclose(gdfid);

    return 0;
}