48 HDF4Cmd(
int cmd) : m_command(cmd) { m_result.asInt32 = 0; }
88 std::vector<ArgUnion> m_args;
97 std::list<HDF4Cmd*> HDF4::sm_cmdQueue;
99 pthread_t HDF4::sm_id = 0;
100 int HDF4::sm_counter = 0;
102 #endif // USE_PTHREADS
111 std::cout <<
"HDF4::init()" << std::endl;
121 pthread_attr_init(&attr);
122 pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
123 pthread_create(&sm_id, &attr, HDF4::Entry, NULL);
124 pthread_attr_destroy(&attr);
125 #endif // USE_PTHREADS
131 std::cout <<
"HDF4::finalize()" << std::endl;
141 pthread_join(sm_id, &retval);
144 #endif // USE_PTHREADS
157 std::cout <<
"HDF4::Hishdf" << std::endl;
161 HDF4Cmd c(HDF4Cmd::Hishdf);
165 c.m_args[0].asCharP =
const_cast<char*
>(filename);
171 return c.m_result.asIntn;
173 return ::Hishdf(filename);
174 #endif // USE_PTHREADS
180 std::cout <<
"HDF4::SDstart( filename == " << filename <<
", accessMode == " << accessMode <<
" )" << std::endl;
183 HDF4Cmd c(HDF4Cmd::SDstart);
186 c.m_args[0].asCharP =
const_cast<char*
>(filename);
187 c.m_args[1].asInt32 = accessMode;
194 return c.m_result.asInt32;
196 return ::SDstart(filename, accessMode);
197 #endif // USE_PTHREADS
203 std::cout <<
"HDF4::SDend" << std::endl;
206 HDF4Cmd c(HDF4Cmd::SDend);
209 c.m_args[0].asInt32 = sd_id;
213 return c.m_result.asIntn;
215 return ::SDend(sd_id);
216 #endif // USE_PTHREADS
222 std::cout <<
"HDF4::SDfileinfo" << std::endl;
225 HDF4Cmd c(HDF4Cmd::SDfileinfo);
228 c.m_args[0].asInt32 =
id;
229 c.m_args[1].asInt32P = dsCount;
230 c.m_args[2].asInt32P = nAttrs;
233 std::cout <<
" Posting command" << std::endl;
237 std::cout <<
" Returning" << std::endl;
238 return c.m_result.asIntn;
240 return ::SDfileinfo(
id, dsCount, nAttrs);
241 #endif // USE_PTHREADS
248 std::cout <<
"HDF4::SDcreate" << std::endl;
251 HDF4Cmd c(HDF4Cmd::SDcreate);
254 c.m_args[0].asInt32 = sds_id;
255 c.m_args[1].asCharP =
const_cast<char*
>(name);
256 c.m_args[2].asInt32 = dType;
257 c.m_args[3].asInt32 =
rank;
258 c.m_args[4].asInt32P = size;
262 return c.m_result.asIntn;
264 return ::SDcreate(sds_id, name, dType, rank, size);
265 #endif // USE_PTHREADS
271 std::cout <<
"HDF4::SDselect( sd_id == " << sd_id <<
", index == " << index <<
" )" << std::endl;
274 HDF4Cmd c(HDF4Cmd::SDselect);
277 c.m_args[0].asInt32 = sd_id;
278 c.m_args[1].asInt32 = index;
282 return c.m_result.asInt32;
284 return ::SDselect(sd_id, index);
285 #endif // USE_PTHREADS
291 std::cout <<
"HDF4::SDendaccess" << std::endl;
294 HDF4Cmd c(HDF4Cmd::SDendaccess);
297 c.m_args[0].asInt32 = sds_id;
301 return c.m_result.asIntn;
303 return ::SDendaccess(sds_id);
304 #endif // USE_PTHREADS
310 std::cout <<
"HDF4::SDfindattr" << std::endl;
313 HDF4Cmd c(HDF4Cmd::SDfindattr);
316 c.m_args[0].asInt32 =
id;
317 c.m_args[1].asCharP =
const_cast<char*
>(attrName);
321 return c.m_result.asInt32;
323 return ::SDfindattr(
id, attrName);
324 #endif // USE_PTHREADS
328 int32* dType, int32* nAttrs)
331 std::cout <<
"HDF4::SDgetinfo" << std::endl;
334 HDF4Cmd c(HDF4Cmd::SDgetinfo);
337 c.m_args[0].asInt32 = sds_id;
338 c.m_args[1].asCharP = name;
339 c.m_args[2].asInt32P =
rank;
340 c.m_args[3].asInt32P = size;
341 c.m_args[4].asInt32P = dType;
342 c.m_args[5].asInt32P = nAttrs;
346 return c.m_result.asIntn;
348 return ::SDgetinfo(sds_id, name, rank, size, dType, nAttrs);
349 #endif // USE_PTHREADS
353 const char* format,
const char* coordsys)
356 std::cout <<
"HDF4::SDsetdatastrs" << std::endl;
359 HDF4Cmd c(HDF4Cmd::SDsetdatastrs);
362 c.m_args[0].asInt32 = sds_id;
363 c.m_args[1].asCharP =
const_cast<char*
>(label);
364 c.m_args[2].asCharP =
const_cast<char*
>(units);
365 c.m_args[3].asCharP =
const_cast<char*
>(format);
366 c.m_args[4].asCharP =
const_cast<char*
>(coordsys);
370 return c.m_result.asIntn;
372 return ::SDsetdatastrs(sds_id, label, units, format, coordsys);
373 #endif // USE_PTHREADS
377 char* coordsys, intn
length)
380 std::cout <<
"HDF4::SDgetdatastrs" << std::endl;
383 HDF4Cmd c(HDF4Cmd::SDgetdatastrs);
386 c.m_args[0].asInt32 = sds_id;
387 c.m_args[1].asCharP = label;
388 c.m_args[2].asCharP = units;
389 c.m_args[3].asCharP = format;
390 c.m_args[4].asCharP = coordsys;
391 c.m_args[5].asIntn =
length;
395 return c.m_result.asIntn;
397 return ::SDgetdatastrs(sds_id, label, units, format, coordsys, length);
398 #endif // USE_PTHREADS
404 std::cout <<
"HDF4::SDsetrange" << std::endl;
407 HDF4Cmd c(HDF4Cmd::SDsetrange);
410 c.m_args[0].asInt32 = sds_id;
411 c.m_args[1].asVOIDP =
max;
412 c.m_args[2].asVOIDP =
min;
416 return c.m_result.asIntn;
418 return ::SDsetrange(sds_id, max, min);
419 #endif // USE_PTHREADS
425 std::cout <<
"HDF4::SDgetrange" << std::endl;
428 HDF4Cmd c(HDF4Cmd::SDgetrange);
431 c.m_args[0].asInt32 = sds_id;
432 c.m_args[1].asVOIDP =
max;
433 c.m_args[2].asVOIDP =
min;
437 return c.m_result.asIntn;
439 return ::SDgetrange(sds_id, max, min);
440 #endif // USE_PTHREADS
447 std::cout <<
"HDF4::SDwritedata" << std::endl;
450 HDF4Cmd c(HDF4Cmd::SDwritedata);
453 c.m_args[0].asInt32 = sds_id;
454 c.m_args[1].asInt32P = start;
455 c.m_args[2].asInt32P = stripe;
456 c.m_args[3].asInt32P = end;
457 c.m_args[4].asVOIDP = data;
461 return c.m_result.asIntn;
463 return ::SDwritedata(sds_id, start, stripe, end, data);
464 #endif // USE_PTHREADS
471 std::cout <<
"HDF4::SDreaddata" << std::endl;
474 HDF4Cmd c(HDF4Cmd::SDreaddata);
477 c.m_args[0].asInt32 = sds_id;
478 c.m_args[1].asInt32P = start;
479 c.m_args[2].asInt32P = stripe;
480 c.m_args[3].asInt32P = end;
481 c.m_args[4].asVOIDP = data;
485 return c.m_result.asIntn;
487 return ::SDreaddata(sds_id, start, stripe, end, data);
488 #endif // USE_PTHREADS
494 std::cout <<
"HDF4::DFSDsetdims" << std::endl;
497 HDF4Cmd c(HDF4Cmd::DFSDsetdims);
500 c.m_args[0].asIntn =
rank;
501 c.m_args[1].asInt32P = dimsizes;
505 return c.m_result.asIntn;
507 return ::DFSDsetdims(rank, dimsizes);
508 #endif // USE_PTHREADS
514 std::cout <<
"HDF4::DFSDsetNT" << std::endl;
517 HDF4Cmd c(HDF4Cmd::DFSDsetNT);
520 c.m_args[0].asInt32 = numbertype;
524 return c.m_result.asIntn;
526 return ::DFSDsetNT(numbertype);
527 #endif // USE_PTHREADS
531 const char* format,
const char* coordsys)
534 std::cout <<
"HDF4::DFSDsetdatastrs" << std::endl;
537 HDF4Cmd c(HDF4Cmd::DFSDsetdatastrs);
540 c.m_args[0].asCharP =
const_cast<char*
>(label);
541 c.m_args[1].asCharP =
const_cast<char*
>(unit);
542 c.m_args[2].asCharP =
const_cast<char*
>(format);
543 c.m_args[3].asCharP =
const_cast<char*
>(coordsys);
547 return c.m_result.asIntn;
549 return ::DFSDsetdatastrs(label, unit, format, coordsys);
550 #endif // USE_PTHREADS
556 std::cout <<
"HDF4::DFSDsetrange" << std::endl;
559 HDF4Cmd c(HDF4Cmd::DFSDsetrange);
562 c.m_args[0].asVOIDP = maxi;
563 c.m_args[1].asVOIDP = mini;
567 return c.m_result.asIntn;
569 return ::DFSDsetrange(maxi, mini);
570 #endif // USE_PTHREADS
577 std::cout <<
"HDF4::DFSDadddata" << std::endl;
580 HDF4Cmd c(HDF4Cmd::DFSDadddata);
583 c.m_args[0].asCharP =
const_cast<char*
>(filename);
584 c.m_args[1].asIntn =
rank;
585 c.m_args[2].asInt32P = dimsizes;
586 c.m_args[3].asVOIDP = data;
590 return c.m_result.asIntn;
592 return ::DFSDadddata(filename, rank, dimsizes, data);
593 #endif // USE_PTHREADS
600 std::cout <<
"HDF4::DFSDputdata" << std::endl;
603 HDF4Cmd c(HDF4Cmd::DFSDputdata);
606 c.m_args[0].asCharP =
const_cast<char*
>(filename);
607 c.m_args[1].asIntn =
rank;
608 c.m_args[2].asInt32P = dimsizes;
609 c.m_args[3].asVOIDP = data;
613 return c.m_result.asIntn;
615 return ::DFSDputdata(filename, rank, dimsizes, data);
616 #endif // USE_PTHREADS
628 std::cout <<
"HDF4::Terminate()" << std::endl;
634 HDF4Cmd c(HDF4Cmd::Terminate);
639 #endif // USE_PTHREADS
643 void HDF4::PostCommand(HDF4Cmd* pCmd)
646 sm_cmdQueue.push_back(pCmd);
655 pCmd->m_semaphore.Wait();
657 #endif // USE_PTHREADS
676 int32* size, int32* dType, int32* nAttrs, int32 dsCount)
679 std::cout <<
"HDF4::Select" << std::endl;
692 while (index < dsCount) {
695 if (sds_id == FAIL) {
696 std::cerr <<
"HDF4::Select(): unable to select dataset " << index
703 if (status == FAIL) {
704 std::cerr <<
"HDF4::Select(): SDgetinfo() failed for dataset "
705 << index <<
'.' << std::endl;
710 if (strncmp(name,
"fakeDim", 7) != 0)
733 std::cout <<
"HDF4::SIZEOF" << std::endl;
783 void* HDF4::Entry(
void*)
786 std::cout <<
"HDF4::ENTRY" << std::endl;
788 std::cout <<
"HDF4 I/O thread started!" << std::endl;
793 if (!sm_pending.Wait()) {
794 std::cerr <<
"HDF4::Entry(): semaphore error." << std::endl;
798 if (sm_cmdQueue.empty())
803 c = sm_cmdQueue.front();
804 sm_cmdQueue.pop_front();
808 switch (c->m_command) {
809 case HDF4Cmd::Hishdf:
810 c->m_result.asIntn =
::Hishdf(c->m_args[0].asCharP);
813 case HDF4Cmd::SDstart:
814 c->m_result.asInt32 =
::SDstart(c->m_args[0].asCharP,
815 c->m_args[1].asInt32);
819 c->m_result.asIntn =
::SDend(c->m_args[0].asInt32);
822 case HDF4Cmd::SDfileinfo:
824 c->m_args[1].asInt32P,
825 c->m_args[2].asInt32P);
828 case HDF4Cmd::SDcreate:
829 c->m_result.asIntn =
::SDcreate(c->m_args[0].asInt32,
830 c->m_args[1].asCharP,
831 c->m_args[2].asInt32,
832 c->m_args[3].asInt32,
833 c->m_args[4].asInt32P);
836 case HDF4Cmd::SDselect:
837 c->m_result.asInt32 =
::SDselect(c->m_args[0].asInt32,
838 c->m_args[1].asInt32);
841 case HDF4Cmd::SDendaccess:
845 case HDF4Cmd::SDfindattr:
846 c->m_result.asInt32 =
::SDfindattr(c->m_args[0].asInt32,
847 c->m_args[1].asCharP);
850 case HDF4Cmd::SDgetinfo:
851 c->m_result.asIntn =
::SDgetinfo(c->m_args[0].asInt32,
852 c->m_args[1].asCharP,
853 c->m_args[2].asInt32P,
854 c->m_args[3].asInt32P,
855 c->m_args[4].asInt32P,
856 c->m_args[5].asInt32P);
859 case HDF4Cmd::SDsetdatastrs:
861 c->m_args[1].asCharP,
862 c->m_args[2].asCharP,
863 c->m_args[3].asCharP,
864 c->m_args[4].asCharP);
867 case HDF4Cmd::SDgetdatastrs:
869 c->m_args[1].asCharP,
870 c->m_args[2].asCharP,
871 c->m_args[3].asCharP,
872 c->m_args[4].asCharP,
873 c->m_args[5].asIntn);
876 case HDF4Cmd::SDsetrange:
878 c->m_args[1].asVOIDP,
879 c->m_args[2].asVOIDP);
882 case HDF4Cmd::SDgetrange:
884 c->m_args[1].asVOIDP,
885 c->m_args[2].asVOIDP);
888 case HDF4Cmd::SDwritedata:
890 c->m_args[1].asInt32P,
891 c->m_args[2].asInt32P,
892 c->m_args[3].asInt32P,
893 c->m_args[4].asVOIDP);
896 case HDF4Cmd::SDreaddata:
898 c->m_args[1].asInt32P,
899 c->m_args[2].asInt32P,
900 c->m_args[3].asInt32P,
901 c->m_args[4].asVOIDP);
904 case HDF4Cmd::DFSDsetdims:
906 c->m_args[1].asInt32P);
909 case HDF4Cmd::DFSDsetNT:
910 c->m_result.asIntn =
::DFSDsetNT(c->m_args[0].asInt32);
913 case HDF4Cmd::DFSDsetdatastrs:
915 c->m_args[1].asCharP,
916 c->m_args[2].asCharP,
917 c->m_args[3].asCharP);
920 case HDF4Cmd::DFSDsetrange:
922 c->m_args[1].asVOIDP);
925 case HDF4Cmd::DFSDadddata:
928 c->m_args[2].asInt32P,
929 c->m_args[3].asVOIDP);
932 case HDF4Cmd::DFSDputdata:
935 c->m_args[2].asInt32P,
936 c->m_args[3].asVOIDP);
939 case HDF4Cmd::Terminate:
943 std::cerr <<
"HDF4::Entry: ignoring unrecognised command ("
944 << c->m_command <<
')' << std::endl;
949 c->m_semaphore.Post();
952 }
while (c->m_command != HDF4Cmd::Terminate);
955 std::cout <<
"HDF4 I/O thread exiting!" << std::endl;
959 #endif // USE_PTHREADS
962 return HEstring((hdf_err_code_t)HEvalue(1));
static int32 SDselect(int32 sd_id, int32 index)
static int32 SDfindattr(int32 id, const char *attrName)
static intn SDwritedata(int32 sds_id, int32 *start, int32 *stride, int32 *end, VOIDP data)
static intn SDgetinfo(int32 sds_id, char *name, int32 *rank, int32 *size, int32 *dType, int32 *nAttrs)
static intn SDend(int32 sd_id)
static intn SDendaccess(int32 sds_id)
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
static intn DFSDsetdims(intn rank, int32 dimsizes[])
Single file interface.
static int32 SDcreate(int32 sd_id, const char *name, int32 dType, int32 rank, int32 *size)
static intn DFSDadddata(const char *filename, intn rank, int32 dimsizes[], VOIDP data)
static intn SDgetrange(int32 sds_id, VOIDP max, VOIDP min)
static int SizeOf(int32 dType)
Get the size in bytes of an HDF data type.
double length(Vector3D *const v, int n)
static intn SDsetrange(int32 sds_id, VOIDP max, VOIDP min)
static std::string error_msg()
return error message
static void init()
Create and start the I/O thread.
static intn DFSDsetNT(int32 numbertype)
static intn SDsetdatastrs(int32 sds_id, const char *label, const char *units, const char *format, const char *coordsys)
static int32 Select(int32 sd_id, int32 &index, char *name, int32 *rank, int32 *size, int32 *dType, int32 *nAttrs, int32 dsCount=-1)
"Open" and "close" HDF files efficiently.
static intn SDreaddata(int32 sds_id, int32 *start, int32 *stride, int32 *end, VOIDP data)
static void Terminate()
Terminate the I/O thread.
static intn Hishdf(const char *filename)
HDF4 wrapper functions.
static intn SDfileinfo(int32 id, int32 *dsCount, int32 *nAttrs)
static intn DFSDputdata(const char *filename, intn rank, int32 dimsizes[], VOIDP data)
static void finalize()
Destroy the I/O thread.
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
unsigned long id(const Leda_like_handle &x)
static int32 SDstart(const char *filename, int32 accessMode)
static intn DFSDsetrange(VOIDP maxi, VOIDP mini)
static intn SDgetdatastrs(int32 sds_id, char *label, char *units, char *format, char *coordsys, intn length)
static intn DFSDsetdatastrs(const char *label, const char *unit, const char *format, const char *coordsys)