2
*********************************************************
3
* FILE: he5_sw_threads-2.c *
4
* PURPOSE: To test thread-safe version of *
5
* HDF-EOS5 Swath library *
6
* Author: A. Muslimov, Emergent IT Inc. *
9
*********************************************************
12
#include <HE5_HdfEosDef.h>
14
#define NUM_THREADS 30
16
typedef struct ThreadInfo_tag
25
void *HE5_SwathTest(void *arg);
33
ThreadInfo_t threadInfo[NUM_THREADS];
34
pthread_t threadArray[NUM_THREADS];
35
pthread_attr_t threadAttr;
37
/* Open HDF-EOS Swath file */
38
/* ----------------------- */
39
fid = HE5_SWopen("swath.h5",H5F_ACC_RDWR);
42
printf( "*ERROR: unable to open \"swath.h5\" file. \n");
46
/* Execute the loop to the NUM_THREADS times */
47
/* to assign one function to each thread afterwards */
48
/* ------------------------------------------------ */
49
for (loopCount = 0; loopCount < NUM_THREADS; loopCount++)
51
threadInfo[loopCount].threadNum = loopCount+1;
52
threadInfo[loopCount].fid = fid;
53
threadInfo[loopCount].swid = FAIL;
54
sprintf(threadInfo[loopCount].swathName,"SWATH_%d",loopCount);
56
pthread_attr_init(&threadAttr);
57
pthread_attr_setscope(&threadAttr,PTHREAD_SCOPE_SYSTEM);
58
status = pthread_create(&threadArray[loopCount],&threadAttr,HE5_SwathTest,&threadInfo[loopCount]);
61
printf("\nERROR: problem starting thread %d, error val: %d\n",loopCount,status);
64
pthread_join(threadArray[loopCount],NULL);
67
ret = HE5_SWclose(fid);
70
printf( "*ERROR: unable to close file. \n");
77
void *HE5_SwathTest(void *arg)
86
ThreadInfo_t *tag = (ThreadInfo_t *) arg;
88
printf("Starting thread %d\n",tag->threadNum);
90
tag->swid = HE5_SWattach(tag->fid,tag->swathName);
91
if (tag->swid == FAIL)
93
printf( "*ERROR: unable to attach to %s swath. \n",tag->swathName);
97
plane = (double *)calloc(12000, sizeof(double));
100
printf( "*ERROR: unable to allocate memory. \n");
104
for (j = 0; j < 12000; j++)
105
plane[j] = (double)j;
107
start[0] = 0; count[0] = 15;
108
start[1] = 0; count[1] = 40;
109
start[2] = 0; count[2] = 20;
111
status = HE5_SWwritefield(tag->swid, "Spectra", start, NULL, count, plane);
114
printf( "*ERROR: unable to write data for \"Spectra\" field in %s swath. \n",tag->swathName);
120
status = HE5_SWdetach(tag->swid);
123
printf( "*ERROR: unable to detach from %s swath. \n",tag->swathName);
127
tag->swid = HE5_SWattach(tag->fid,tag->swathName);
128
if (tag->swid == FAIL)
130
printf( "*ERROR: unable to attach to %s swath. \n",tag->swathName);
134
outbuf = (double *)calloc(12000, sizeof(double));
137
printf( "*ERROR: unable to allocate memory. \n");
141
start[0] = 0; count[0] = 15;
142
start[1] = 0; count[1] = 40;
143
start[2] = 0; count[2] = 20;
145
status = HE5_SWreadfield(tag->swid, "Spectra", start, NULL, count, outbuf);
148
printf( "*ERROR: unable to read data from \"Spectra\" field in %s swath. \n",tag->swathName);
154
status = HE5_SWdetach(tag->swid);
157
printf( "*ERROR: unable to detach from %s swath. \n",tag->swathName);