PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Modules/HDF5Wrap.c

#
C | 609 lines | 473 code | 37 blank | 99 comment | 16 complexity | fcb03aadfde91b4af37bb4925121ce45 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, BSD-3-Clause
  1. /*
  2. This code is part of the MondoSCF suite of programs for linear scaling
  3. electronic structure theory and ab initio molecular dynamics.
  4. Copyright (2004). The Regents of the University of California. This
  5. material was produced under U.S. Government contract W-7405-ENG-36
  6. for Los Alamos National Laboratory, which is operated by the University
  7. of California for the U.S. Department of Energy. The U.S. Government has
  8. rights to use, reproduce, and distribute this software. NEITHER THE
  9. GOVERNMENT NOR THE UNIVERSITY MAKES ANY WARRANTY, EXPRESS OR IMPLIED,
  10. OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE.
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by the
  13. Free Software Foundation; either version 2 of the License, or (at your
  14. option) any later version. Accordingly, this program is distributed in
  15. the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
  16. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  17. PURPOSE. See the GNU General Public License at www.gnu.org for details.
  18. While you may do as you like with this software, the GNU license requires
  19. that you clearly mark derivative software. In addition, you are encouraged
  20. to return derivative works to the MondoSCF group for review, and possible
  21. disemination in future releases.
  22. */
  23. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  24. /* F90 interface to the C HDF5 API */
  25. /* Author: Matt Challacombe and CK Gan */
  26. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include "config.h"
  30. #if defined (HAVE_INTERNAL_HDF5)
  31. #include "hdf5.h"
  32. #else
  33. #include <hdf5.h>
  34. #endif
  35. #include <string.h>
  36. #include <sys/types.h>
  37. #include <regex.h>
  38. /*
  39. THESE TURN ON VARIOUS LEVELS OF DEBUG
  40. #define debug_interface
  41. #define debug_all
  42. */
  43. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  44. /* */
  45. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  46. char* IntToChar(int* NC, int* IntArray)
  47. {
  48. int j;
  49. char* VarName;
  50. VarName = (char*) malloc((*NC+1)*sizeof(char));
  51. for(j=0; j < *NC; j++) { VarName[j] = (char) IntArray[j]; }
  52. VarName[*NC] = '\0';
  53. return VarName;
  54. }
  55. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  56. /* */
  57. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  58. int hdf5createfile_(int* NC, int* IChr)
  59. {
  60. char* filename;
  61. hid_t fid;
  62. int FileID;
  63. filename = IntToChar(NC, IChr);
  64. #ifdef debug_interface
  65. printf("IN CREATE_HDF5_FILE: Creating %s \n",filename);
  66. #endif
  67. fid=H5Fcreate(filename,H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
  68. #ifdef debug_interface
  69. #ifdef debug_all
  70. printf("IN CREATE_HDF5_FILE: FileID = %d \n",fid);
  71. #endif
  72. #endif
  73. FileID=fid;
  74. free(filename);
  75. return FileID;
  76. }
  77. int hdf5createfile(int* NC, int* IChr){return hdf5createfile_(NC,IChr);}
  78. int hdf5createfile__(int* NC, int* IChr){return hdf5createfile_(NC,IChr);}
  79. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  80. /* */
  81. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  82. int hdf5openfile_(int* NC, int* IChr)
  83. {
  84. char* filename;
  85. hid_t fid;
  86. int FileID;
  87. filename = IntToChar(NC,IChr);
  88. #ifdef debug_interface
  89. printf("IN OPEN_HDF5_FILE: Opening <%s> \n", filename);
  90. #endif
  91. H5Eset_auto(H5E_DEFAULT, NULL, NULL);
  92. fid=H5Fopen(filename,H5F_ACC_RDWR,H5P_DEFAULT);
  93. #ifdef debug_interface
  94. #ifdef debug_all
  95. printf("IN OPEN_HDF5_FILE: FileID = %d \n",fid);
  96. #endif
  97. #endif
  98. FileID=fid;
  99. free(filename);
  100. return FileID;
  101. }
  102. int hdf5openfile(int* NC, int* IChr){return hdf5openfile_(NC,IChr);}
  103. int hdf5openfile__(int* NC, int* IChr){return hdf5openfile_(NC,IChr);}
  104. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  105. /* */
  106. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  107. int hdf5closefile_(int* FileID)
  108. {
  109. herr_t stat;
  110. hid_t fid;
  111. int STATUS;
  112. fid=*FileID;
  113. #ifdef debug_interface
  114. #ifdef debug_all
  115. printf("IN CLOSE_HDF5_FILE: Flushing FileID= %d \n",FileID);
  116. #endif
  117. #endif
  118. stat=H5Fflush(fid,H5F_SCOPE_GLOBAL);
  119. #ifdef debug_interface
  120. #ifdef debug_all
  121. printf("IN CLOSE_HDF5_FILE: Closing FileID= %d \n",FileID);
  122. #endif
  123. #endif
  124. stat=H5Fclose(fid);
  125. if(stat==-1){STATUS=stat; return STATUS;}
  126. /*printf("HDF5CloseFile: Could not close FileID= %d \n",*FileID);}*/
  127. stat=H5close();
  128. #ifdef debug_interface
  129. #ifdef debug_all
  130. printf("IN CLOSE_HDF5_FILE: STATUS = %d \n",stat);
  131. #endif
  132. #endif
  133. STATUS=stat;
  134. return STATUS;
  135. }
  136. int hdf5closefile(int* FileID){return hdf5closefile_(FileID);}
  137. int hdf5closefile__(int* FileID){return hdf5closefile_(FileID);}
  138. /*=================================================================================*/
  139. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  140. /* */
  141. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  142. int hdf5creategroup_(int* FileID, int* NC, int* IChr)
  143. {
  144. char* filename;
  145. hid_t fid;
  146. hid_t gid;
  147. int GroupID;
  148. filename = IntToChar(NC,IChr);
  149. #ifdef debug_interface
  150. printf("IN CREATE_HDF5_GROUP: Creating %s \n",filename);
  151. #endif
  152. fid=*FileID;
  153. gid=H5Gcreate1(fid,filename,0);
  154. #ifdef debug_interface
  155. #ifdef debug_all
  156. printf("IN CREATE_HDF5_GROUP: FileID = %d, GroupID= %d \n",fid,gid);
  157. #endif
  158. #endif
  159. GroupID=gid;
  160. free(filename);
  161. return GroupID;
  162. }
  163. int hdf5creategroup(int* FileID, int* NC, int* IChr){return hdf5creategroup_(FileID,NC,IChr);}
  164. int hdf5creategroup__(int* FileID, int* NC, int* IChr){return hdf5creategroup_(FileID,NC,IChr);}
  165. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  166. /* */
  167. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  168. int hdf5opengroup_(int* FileID, int* NC, int* IChr)
  169. {
  170. char* filename;
  171. hid_t fid;
  172. hid_t gid;
  173. int GroupID;
  174. filename = IntToChar(NC,IChr);
  175. #ifdef debug_interface
  176. printf("IN OPEN_HDF5_GROUP: Opening <%s> \n",filename);
  177. #endif
  178. fid=*FileID;
  179. H5Eset_auto(H5E_DEFAULT, NULL, NULL);
  180. gid=H5Gopen1(fid,filename);
  181. #ifdef debug_interface
  182. #ifdef debug_all
  183. printf("IN OPEN_HDF5_GROUP: FileID = %d, GroupID = %d \n",fid,gid);
  184. #endif
  185. #endif
  186. GroupID=gid;
  187. free(filename);
  188. return GroupID;
  189. }
  190. int hdf5opengroup(int* FileID, int* NC, int* IChr){return hdf5opengroup_(FileID,NC,IChr);}
  191. int hdf5opengroup__(int* FileID, int* NC, int* IChr){return hdf5opengroup_(FileID,NC,IChr);}
  192. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  193. /* */
  194. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  195. int hdf5closegroup_(int* GroupID)
  196. {
  197. herr_t stat;
  198. int STATUS;
  199. hid_t gid;
  200. gid=*GroupID;
  201. #ifdef debug_interface
  202. #ifdef debug_all
  203. printf("IN CLOSE_HDF5_GROUP: Flushing GroupID= %d \n",GroupID);
  204. #endif
  205. #endif
  206. #ifdef debug_interface
  207. #ifdef debug_all
  208. printf("IN CLOSE_HDF5_GROUP: Closing GroupID= %d \n",GroupID);
  209. #endif
  210. #endif
  211. stat=H5Gclose(gid);
  212. #ifdef debug_interface
  213. #ifdef debug_all
  214. printf("IN CLOSE_HDF5_GROUP: STATUS = %d \n",stat);
  215. #endif
  216. #endif
  217. STATUS=stat;
  218. return STATUS;
  219. }
  220. int hdf5closegroup(int* GroupID){return hdf5closegroup_(GroupID);}
  221. int hdf5closegroup__(int* GroupID){return hdf5closegroup_(GroupID);}
  222. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  223. /* */
  224. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  225. void hdf5opendata_(int* FileID, int* NC, int* IChr, int* DataId, int* DataSpc)
  226. {
  227. char* filename;
  228. hid_t fid,did,dspc;
  229. fid=*FileID;
  230. filename = IntToChar(NC,IChr);
  231. #ifdef debug_interface
  232. #ifdef debug_all
  233. printf("OPEN_HDF5_DATA: FileID = %d \n",fid);
  234. #endif
  235. printf("OPEN_HDF5_DATA: VarName= <%s> \n",filename);
  236. #endif
  237. did=H5Dopen1(fid,filename);
  238. dspc=H5Dget_space(did);
  239. #ifdef debug_interface
  240. #ifdef debug_all
  241. printf("OPEN_HDF5_DATA: DataId = %d \n",did);
  242. printf("OPEN_HDF5_DATA: DataSpc= %d \n",dspc);
  243. #endif
  244. #endif
  245. free(filename);
  246. *DataId=did;
  247. *DataSpc=dspc;
  248. }
  249. void hdf5opendata(int* FileID, int* NC, int* IChr, int* DataId, int* DataSpc)
  250. {hdf5opendata_(FileID,NC,IChr,DataId,DataSpc);}
  251. void hdf5opendata__(int* FileID, int* NC, int* IChr, int* DataId, int* DataSpc)
  252. {hdf5opendata_(FileID,NC,IChr,DataId,DataSpc);}
  253. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  254. /* */
  255. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  256. void hdf5extenddata_(int* DataId, int* DataSpc, int* N)
  257. {
  258. hid_t did,dspc;
  259. hsize_t siz[1];
  260. siz[0]=*N;
  261. did=*DataId;
  262. dspc=*DataSpc;
  263. #ifdef debug_interface
  264. printf("EXTEND_HDF5_DATA: DataId = %d \n",did);
  265. printf("EXTEND_HDF5_DATA: NewSiz = %d \n",siz[0]);
  266. #endif
  267. H5Dextend(did,siz);
  268. H5Sclose(dspc);
  269. dspc=H5Dget_space(did);
  270. *DataSpc=dspc;
  271. #ifdef debug_interface
  272. printf("EXTEND_HDF5_DATA: Old DataSpc = %d \n",dspc);
  273. printf("EXTEND_HDF5_DATA: New DataSpc = %d \n",dspc);
  274. #endif
  275. }
  276. void hdf5extenddata(int* DataId, int* DataSpc, int* N)
  277. {hdf5extenddata_(DataId,DataSpc,N);}
  278. void hdf5extenddata__(int* DataId, int* DataSpc, int* N)
  279. {hdf5extenddata_(DataId,DataSpc,N);}
  280. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  281. /* */
  282. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  283. void hdf5selectdata_(int* DataId, int* DataSpc, int* NewSize)
  284. {
  285. hid_t did,dspc;
  286. hsize_t cnt[1];
  287. hsize_t off[1];
  288. did=*DataId;
  289. dspc=*DataSpc;
  290. off[0]=0;
  291. cnt[0]=*NewSize;
  292. H5Sselect_hyperslab(dspc,H5S_SELECT_SET,off,NULL,cnt,NULL);
  293. }
  294. void hdf5selectdata(int* DataId, int* DataSpc, int* NewSize)
  295. {hdf5selectdata_(DataId,DataSpc,NewSize);}
  296. void hdf5selectdata__(int* DataId, int* DataSpc, int* NewSize)
  297. {hdf5selectdata_(DataId,DataSpc,NewSize);}
  298. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  299. /* */
  300. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  301. int hdf5closedata_(int* DataId,int* DataSpc)
  302. {
  303. hid_t did,dspc;
  304. herr_t stat1,stat2;
  305. int STATUS;
  306. did=*DataId;
  307. dspc=*DataSpc;
  308. #ifdef debug_interface
  309. #ifdef debug_all
  310. printf("CLOSE_HDF5_DATA: DataId = %d \n",did);
  311. printf("CLOSE_HDF5_DATA: DataSpc= %d \n",dspc);
  312. #endif
  313. #endif
  314. stat1=H5Dclose(did);
  315. stat2=H5Sclose(dspc);
  316. STATUS=stat1||stat2;
  317. return STATUS;
  318. }
  319. int hdf5closedata(int* DataId,int* DataSpc){return hdf5closedata_(DataId,DataSpc);}
  320. int hdf5closedata__(int* DataId,int* DataSpc){return hdf5closedata_(DataId,DataSpc);}
  321. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  322. /* */
  323. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  324. void hdf5createdata_(int* FileID,int* Type,int* N,int* NC,int* IChr,int* ULimit, int* DataId, int* DataSpc)
  325. {
  326. char* filename;
  327. hsize_t dms[1],mxdms[1],chnk[1];
  328. hid_t fid,did,dtyp,dspc,dprp,stat;
  329. filename = IntToChar(NC,IChr);
  330. fid=*FileID;
  331. dms[0]=*N;
  332. #ifdef debug_interface
  333. #ifdef debug_all
  334. printf("IN CREATE_HDF5_DATA: FileID = %d \n",fid);
  335. printf("IN CREATE_HDF5_DATA: N = %d \n",dms[0]);
  336. #endif
  337. #endif
  338. if(*Type==24){dtyp=H5T_NATIVE_INT;}
  339. else if(*Type==6){dtyp=H5T_NATIVE_DOUBLE;}
  340. else{printf("Waring, unknown type = %d in HDF5DataId!",*Type); *DataId=-1; return;}
  341. dprp=H5Pcreate(H5P_DATASET_CREATE);
  342. if(*ULimit==1)
  343. {
  344. mxdms[0]=H5S_UNLIMITED;
  345. dspc=H5Screate_simple(1,dms,mxdms);
  346. chnk[0]=8192; /* 2048; */ /* 512; */
  347. stat=H5Pset_chunk(dprp,1,chnk);
  348. #ifdef debug_interface
  349. printf("IN CREATE_HDF5_DATA: UNLIMITED DIMENSION = %d\n",dms[0]);
  350. printf("IN CREATE_HDF5_DATA: CHUNKING SIZE = %d\n",chnk[0]);
  351. #endif
  352. if(stat==-1){*DataId=-1; return;}
  353. }
  354. else
  355. {dspc=H5Screate_simple(1,dms,NULL);
  356. #ifdef debug_interface
  357. #ifdef debug_all
  358. printf("IN CREATE_HDF5_DATA: DIMENSIONS LIMITED TO %d\n",dms[0]);
  359. #endif
  360. #endif
  361. }
  362. did=H5Dcreate1(fid,filename,dtyp,dspc,dprp);
  363. #ifdef debug_interface
  364. printf("IN CREATE_HDF5_DATA: VarName =<%s> \n",filename);
  365. printf("IN CREATE_HDF5_DATA: DataId = %d \n",did);
  366. #ifdef debug_all
  367. printf("IN CREATE_HDF5_DATA: DataTyp = %d \n",dtyp);
  368. printf("IN CREATE_HDF5_DATA: DataSpc = %d \n",dspc);
  369. printf("IN CREATE_HDF5_DATA: DataProp= %d \n",dprp);
  370. #endif
  371. #endif
  372. *DataId=did;
  373. *DataSpc=dspc;
  374. free(filename);
  375. }
  376. void hdf5createdata(int* FileID,int* Type,int* N,int* NC,int* IChr,int* ULimit, int* DataId, int* DataSpc)
  377. {hdf5createdata_(FileID,Type,N,NC,IChr,ULimit,DataId,DataSpc);}
  378. void hdf5createdata__(int* FileID,int* Type,int* N,int* NC,int* IChr,int* ULimit, int* DataId, int* DataSpc)
  379. {hdf5createdata_(FileID,Type,N,NC,IChr,ULimit,DataId,DataSpc);}
  380. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  381. /* */
  382. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  383. int hdf5sizeofdata_(int* DataSpc)
  384. {
  385. hid_t dspc;
  386. hsize_t dsiz;
  387. int DataSize;
  388. dspc=*DataSpc;
  389. #ifdef debug_interface
  390. #ifdef debug_all
  391. printf("IN SIZE_OF_DATA: DataSpc = %d \n",*DataSpc);
  392. #endif
  393. #endif
  394. dsiz=H5Sget_simple_extent_npoints(dspc);
  395. #ifdef debug_interface
  396. #ifdef debug_all
  397. printf("IN SIZE_OF_DATA: DataSiz = %d \n",dsiz);
  398. #endif
  399. #endif
  400. DataSize=dsiz;
  401. return DataSize;
  402. }
  403. int hdf5sizeofdata(int* DataSpc)
  404. {return hdf5sizeofdata_(DataSpc);}
  405. int hdf5sizeofdata__(int* DataSpc)
  406. {return hdf5sizeofdata_(DataSpc);}
  407. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  408. /* */
  409. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  410. int hdf5writeintegervector_(int* DataId, int* DataSpc, int* Data)
  411. {
  412. hid_t did,dspc;
  413. herr_t stat;
  414. int STATUS;
  415. did=*DataId;
  416. dspc=*DataSpc;
  417. stat=H5Dwrite(did,H5T_NATIVE_INT,H5S_ALL,dspc,H5P_DEFAULT,Data);
  418. STATUS=stat;
  419. return STATUS;
  420. }
  421. int hdf5writeintegervector(int* DataId, int* DataSpc, int* Data)
  422. {return hdf5writeintegervector_(DataId,DataSpc,Data);}
  423. int hdf5writeintegervector__(int* DataId, int* DataSpc, int* Data)
  424. {return hdf5writeintegervector_(DataId,DataSpc,Data);}
  425. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  426. /* */
  427. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  428. int hdf5writedoublevector_(int* DataId, int* DataSpc, double* Data)
  429. {
  430. hid_t did,dspc;
  431. herr_t stat;
  432. int STATUS;
  433. did=*DataId;
  434. dspc=*DataSpc;
  435. stat=H5Dwrite(did,H5T_NATIVE_DOUBLE,H5S_ALL,dspc,H5P_DEFAULT,Data);
  436. STATUS=stat;
  437. return STATUS;
  438. }
  439. int hdf5writedoublevector(int* DataId, int* DataSpc, double* Data)
  440. {return hdf5writedoublevector_(DataId,DataSpc,Data);}
  441. int hdf5writedoublevector__(int* DataId, int* DataSpc, double* Data)
  442. {return hdf5writedoublevector_(DataId,DataSpc,Data);}
  443. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  444. /* */
  445. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  446. int hdf5readintegervector_(int* DataId, int* DataSpc, int* Data)
  447. {
  448. hid_t did,dspc;
  449. herr_t stat;
  450. int STATUS;
  451. did=*DataId;
  452. dspc=*DataSpc;
  453. stat=H5Dread(did,H5T_NATIVE_INT,H5S_ALL,dspc,H5P_DEFAULT,Data);
  454. STATUS=stat;
  455. return STATUS;
  456. }
  457. int hdf5readintegervector(int* DataId, int* DataSpc, int* Data)
  458. {return hdf5readintegervector_(DataId,DataSpc,Data);}
  459. int hdf5readintegervector__(int* DataId, int* DataSpc, int* Data)
  460. {return hdf5readintegervector_(DataId,DataSpc,Data);}
  461. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  462. /* */
  463. /*+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/
  464. int hdf5readdoublevector_(int* DataId, int* DataSpc, double* Data)
  465. {
  466. hid_t did,dspc;
  467. herr_t stat;
  468. int STATUS;
  469. did=*DataId;
  470. dspc=*DataSpc;
  471. stat=H5Dread(did,H5T_NATIVE_DOUBLE,H5S_ALL,dspc,H5P_DEFAULT,Data);
  472. STATUS=stat;
  473. return STATUS;
  474. }
  475. int hdf5readdoublevector(int* DataId, int* DataSpc, double* Data)
  476. {return hdf5readdoublevector_(DataId,DataSpc,Data);}
  477. int hdf5readdoublevector__(int* DataId, int* DataSpc, double* Data)
  478. {return hdf5readdoublevector_(DataId,DataSpc,Data);}
  479. /* Get the library version. */
  480. int
  481. hdf5version (unsigned *majnum, unsigned *minnum, unsigned *relnum)
  482. {
  483. return H5get_libversion(majnum, minnum, relnum);
  484. }
  485. int
  486. hdf5version_ (unsigned *majnum, unsigned *minnum, unsigned *relnum)
  487. {
  488. return hdf5version(majnum, minnum, relnum);
  489. }
  490. typedef struct op_data_t
  491. {
  492. hid_t hdfID;
  493. regex_t pattern;
  494. }
  495. op_data_t;
  496. /* Deletes object from group given a name. The name can contain wildcards. */
  497. herr_t
  498. hdf5delete_op (hid_t groupID, const char *name, const H5L_info_t *info, void *op_data_arg)
  499. {
  500. struct op_data_t *op_data = (struct op_data_t*) op_data_arg;
  501. int result;
  502. /* Debugging output. */
  503. fprintf(stderr, "[hdf5delete_op] group ID %i, hdf ID %i, object name = %s... ", groupID, op_data->hdfID, name);
  504. /* Match link name with objectName pattern. */
  505. result = regexec(&(op_data->pattern), name, 0, NULL, 0);
  506. if (result == 0)
  507. {
  508. fprintf(stderr, "found match... deleting object... ");
  509. fprintf(stderr, "link type %i... ", info->type);
  510. if ((result = H5Ldelete(op_data->hdfID, name, H5P_DEFAULT)) < 0)
  511. {
  512. fprintf(stderr, "%s:%i error\n", __FILE__, __LINE__);
  513. H5Eprint(H5Eget_current_stack(), stderr);
  514. }
  515. else
  516. {
  517. fprintf(stderr, "ok\n");
  518. return result;
  519. }
  520. }
  521. else if (result == REG_ESPACE)
  522. {
  523. fprintf(stderr, "ran out of memory\n");
  524. }
  525. else
  526. {
  527. fprintf(stderr, "no match\n");
  528. }
  529. /* Return an error. */
  530. return -1;
  531. }
  532. int
  533. hdf5delete (int* id, int* groupNameN, int* groupNameC, int* objectNameN, int* objectNameC)
  534. {
  535. char *groupName = IntToChar(groupNameN, groupNameC);
  536. char *objectName = IntToChar(objectNameN, objectNameC);
  537. hid_t *hdfID = (hid_t*) id;
  538. herr_t result;
  539. hsize_t index = 0;
  540. struct op_data_t op_data;
  541. /* Set some data. */
  542. op_data.hdfID = *hdfID;
  543. fprintf(stderr, "[hdf5delete] hdfID %i\n", *hdfID);
  544. fprintf(stderr, "[hdf5delete] searching for objects in group \"%s\"\n", groupName);
  545. fprintf(stderr, "[hdf5delete] object name filter \"%s\"\n", objectName);
  546. /* Compile regular expression pattern. */
  547. if (regcomp(&(op_data.pattern), objectName, 0) != 0)
  548. {
  549. fprintf(stderr, "[hdf5delete] error compiling pattern %s\n", objectName);
  550. exit(1);
  551. }
  552. /* More debugging. */
  553. //fprintf(stderr, "[hdf5delete] pattern.allocated = %u\n", op_data.pattern.allocated);
  554. /* Start to search. */
  555. while ((result = H5Literate_by_name(*hdfID, groupName, H5_INDEX_NAME,
  556. H5_ITER_NATIVE, &index, hdf5delete_op, (void*) &op_data, H5P_DEFAULT)) >= 0)
  557. {}
  558. exit(1);
  559. /* Clean up memory. */
  560. free(groupName);
  561. free(objectName);
  562. /* Return. */
  563. return 0;
  564. }
  565. int
  566. hdf5delete_ (int* id, int* groupNameN, int* groupNameC, int* objectNameN, int* objectNameC)
  567. {
  568. return hdf5delete(id, groupNameN, groupNameC, objectNameN, objectNameC);
  569. }