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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
|
/*
----------------------------------------------------------------------------
| Copyright (C) 1999 Emergent IT Inc. and Raytheon Systems Company |
----------------------------------------------------------------------------
*/
#include <HE5_HdfEosDef.h>
typedef struct
{
double Time;
float Conc[4];
char Spc[8];
} CmpData_1;
typedef struct
{
char Label[16];
double Lon;
double Lat;
int Date;
char Id[8];
} CmpData_2;
typedef struct
{
double Time;
float Rain;
float Temp;
char Id[8];
} CmpData_3;
typedef struct
{
char Label[10];
int Date;
int Weight;
char Id[8];
} CmpData_4;
typedef struct
{
double Time;
double Lon;
double Lat;
float Rain;
float Temp;
char Id[8];
} CmpData_5;
#define NAMEBUF_SIZE 100
int main()
{
FILE *fp;
herr_t status = FAIL;
int n, date, wgt, IntAttr = 9999;
hid_t ptfid = FAIL, PTid = FAIL;
hsize_t count[1];
size_t datasize = 0;
float conc[4], rain, temp, flt = -7.5;
double time, lon, lat;
char spc[8], desc[16], id[ 6 ];
char namebuf[NAMEBUF_SIZE];
char *srcdir;
CmpData_1 datbuf_1[20];
CmpData_2 datbuf_2[5];
CmpData_3 datbuf_3[25];
CmpData_4 datbuf_4[5];
CmpData_5 datbuf_5[30];
/* Open the HDF-EOS file, "Point.h5" */
/* --------------------------------- */
ptfid = HE5_PTopen("Point.h5", H5F_ACC_RDWR);
/* Write to Simple Point */
/* --------------------- */
PTid = HE5_PTattach(ptfid, "Simple Point");
/* Open input data file */
/* -------------------- */
/* Set up path if the input file is in another directory */
srcdir = getenv("srcdir");
if(srcdir != NULL && (strlen(srcdir) + strlen("simple.txt") + 2) <= NAMEBUF_SIZE)
{
strcpy(namebuf, srcdir);
strcat(namebuf, "/simple.txt");
}
else
{
strcpy(namebuf, "simple.txt");
}
fp = fopen(namebuf, "rb");
n = 0;
while(fscanf(fp, "%lf %f %f %f %f %s", &time, &conc[0], &conc[1], &conc[2], &conc[3], spc) != -1)
{
datbuf_1[n].Time = time;
datbuf_1[n].Conc[0] = conc[0];
datbuf_1[n].Conc[1] = conc[1];
datbuf_1[n].Conc[2] = conc[2];
datbuf_1[n].Conc[3] = conc[3];
memmove(datbuf_1[n].Spc, spc, sizeof(char)*strlen(spc));
datbuf_1[n].Spc[strlen(spc)] = 0;
n++;
}
fclose(fp);
datasize = (size_t)sizeof(CmpData_1);
count[0] = n;
status = HE5_PTwritelevel(PTid, 0, count, &datasize, datbuf_1);
printf("Status returned by HE5_PTwritelevel() : %d \n", status);
status = HE5_PTdetach(PTid);
printf("Status returned by HE5_PTdetach() : %d \n", status);
/* Write to Fixed Buoy Point */
/* ------------------------- */
PTid = HE5_PTattach(ptfid, "FixedBuoy Point");
/* Write First (0th) Level */
/* ----------------------- */
/* Set up path if the input file is in another directory */
srcdir = getenv("srcdir");
if(srcdir != NULL && (strlen(srcdir) + strlen("simple.txt") + 2) <= NAMEBUF_SIZE)
{
strcpy(namebuf, srcdir);
strcat(namebuf, "/fixedBuoy0.txt");
}
else
{
strcpy(namebuf, "fixedBuoy0.txt");
}
fp = fopen(namebuf, "r");
n = 0;
while(fscanf(fp, "%s %lf %lf %d %s", desc, &lon, &lat, &date, id) != -1)
{
strcpy(datbuf_2[n].Label, desc);
datbuf_2[n].Lon = lon;
datbuf_2[n].Lat = lat;
datbuf_2[n].Date = date;
memmove(datbuf_2[n].Id, id, sizeof(char)*strlen(id));
datbuf_2[n].Id[strlen(id)] = 0;
n++;
}
fclose(fp);
datasize = (size_t)sizeof(CmpData_2);
count[0] = n;
status = HE5_PTwritelevel(PTid, 0, count, &datasize, datbuf_2);
printf("Status returned by HE5_PTwritelevel() : %d \n", status);
/* Write Second (1th) Level */
/* ------------------------ */
/* Set up path if the input file is in another directory */
srcdir = getenv("srcdir");
if(srcdir != NULL && (strlen(srcdir) + strlen("simple.txt") + 2) <= NAMEBUF_SIZE)
{
strcpy(namebuf, srcdir);
strcat(namebuf, "/fixedBuoy1.txt");
}
else
{
strcpy(namebuf, "fixedBuoy1.txt");
}
fp = fopen(namebuf, "r");
n = 0;
while(fscanf(fp, "%lf %f %f %s", &time, &rain, &temp, id) != -1)
{
datbuf_3[n].Time = time;
datbuf_3[n].Rain = rain;
datbuf_3[n].Temp = temp;
memmove(datbuf_3[n].Id, id, sizeof(char)*strlen(id));
datbuf_3[n].Id[strlen(id)] = 0;
n++;
}
fclose(fp);
datasize = (size_t)sizeof(CmpData_3);
count[0] = n;
status = HE5_PTwritelevel(PTid, 1, count, &datasize, datbuf_3);
printf("Status returned by HE5_PTwritelevel() : %d \n", status);
count[0] = 1;
status = HE5_PTwriteattr(PTid, "GlobalAttr_Integer", H5T_NATIVE_INT, count, &IntAttr);
printf("Status returned by HE5_PTwriteattr() : %d \n", status);
status = HE5_PTdetach(PTid);
printf("Status returned by HE5_PTdetach() : %d \n", status);
/* Write to Floating Buoy Point */
/* ---------------------------- */
PTid = HE5_PTattach(ptfid, "FloatBuoy Point");
/* Write First (0th) Level */
/* ----------------------- */
/* Set up path if the input file is in another directory */
srcdir = getenv("srcdir");
if(srcdir != NULL && (strlen(srcdir) + strlen("simple.txt") + 2) <= NAMEBUF_SIZE)
{
strcpy(namebuf, srcdir);
strcat(namebuf, "/floatBuoy0.txt");
}
else
{
strcpy(namebuf, "floatBuoy0.txt");
}
fp = fopen(namebuf, "r");
n = 0;
while(fscanf(fp, "%s %d %d %s", desc, &date, &wgt, id) != -1)
{
strcpy(datbuf_4[n].Label, desc);
datbuf_4[n].Date = date;
datbuf_4[n].Weight = wgt;
memmove(datbuf_4[n].Id, id, sizeof(char)*strlen(id));
datbuf_4[n].Id[strlen(id)] = 0;
n++;
}
fclose(fp);
datasize = (size_t)sizeof(CmpData_4);
count[0] = n;
status = HE5_PTwritelevel(PTid, 0, count, &datasize, datbuf_4);
printf("Status returned by HE5_PTwritelevel() : %d \n", status);
/* Write Second (1th) Level */
/* ------------------------ */
/* Set up path if the input file is in another directory */
srcdir = getenv("srcdir");
if(srcdir != NULL && (strlen(srcdir) + strlen("simple.txt") + 2) <= NAMEBUF_SIZE)
{
strcpy(namebuf, srcdir);
strcat(namebuf, "/floatBuoy1.txt");
}
else
{
strcpy(namebuf, "floatBuoy1.txt");
}
fp = fopen(namebuf, "r");
n = 0;
while(fscanf(fp, "%lf %lf %lf %f %f %s", &time, &lon, &lat, &rain, &temp, id) != -1)
{
datbuf_5[n].Time = time;
datbuf_5[n].Lon = lon;
datbuf_5[n].Lat = lat;
datbuf_5[n].Rain = rain;
datbuf_5[n].Temp = temp;
memmove(datbuf_5[n].Id, id,sizeof(char)*strlen(id));
datbuf_5[n].Id[strlen(id)] = 0;
n++;
}
fclose(fp);
datasize = (size_t)sizeof(CmpData_5);
count[0] = n;
status = HE5_PTwritelevel(PTid, 1, count, &datasize, datbuf_5);
printf("Status returned by HE5_PTwritelevel() : %d \n", status);
count[0] = 1;
status = HE5_PTwriteattr(PTid, "GlobalAttr", H5T_NATIVE_FLOAT, count, &flt);
printf("Status returned by HE5_PTwriteattr() : %d \n", status);
status = HE5_PTdetach(PTid);
printf("Status returned by HE5_PTdetach() : %d \n", status);
status = HE5_PTclose(ptfid);
printf("Status returned by HE5_PTclose() : %d \n", status);
return 0;
}
|