file_hdf_s.F90 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. module file_hdf_s
  2. implicit none
  3. ! --- in/out --------------------------
  4. private
  5. public :: ReadData, WriteData
  6. public :: ReadAttribute, CheckAttribute
  7. public :: WriteAttribute
  8. ! --- const ----------------------------
  9. include "hdf.f90"
  10. character(len=*), parameter :: mname = 'file_hdf_s'
  11. ! --- interfaces ------------------------
  12. interface ReadData
  13. module procedure sds_ReadData_s_1d
  14. module procedure sds_ReadData_s_2d
  15. end interface
  16. interface WriteData
  17. module procedure sds_WriteData_s_1d
  18. module procedure sds_WriteData_s_2d
  19. end interface
  20. interface ReadAttribute
  21. module procedure obj_ReadAttribute_s_0d
  22. module procedure obj_ReadAttribute_s_1d
  23. !
  24. module procedure sds_ReadAttribute_s_0d
  25. module procedure sds_ReadAttribute_s_1d
  26. !
  27. module procedure dim_ReadAttribute_s_0d
  28. module procedure dim_ReadAttribute_s_1d
  29. !
  30. module procedure hdf_ReadAttribute_s_0d
  31. module procedure hdf_ReadAttribute_s_1d
  32. end interface
  33. interface CheckAttribute
  34. module procedure obj_CheckAttribute_s_0d
  35. module procedure obj_CheckAttribute_s_1d
  36. !
  37. module procedure sds_CheckAttribute_s_0d
  38. module procedure sds_CheckAttribute_s_1d
  39. !
  40. module procedure dim_CheckAttribute_s_0d
  41. module procedure dim_CheckAttribute_s_1d
  42. !
  43. module procedure hdf_CheckAttribute_s_0d
  44. module procedure hdf_CheckAttribute_s_1d
  45. end interface
  46. interface WriteAttribute
  47. module procedure obj_WriteAttribute_s_0d
  48. module procedure obj_WriteAttribute_s_1d
  49. !
  50. module procedure sds_WriteAttribute_s_0d
  51. module procedure sds_WriteAttribute_s_1d
  52. !
  53. module procedure dim_WriteAttribute_s_0d
  54. module procedure dim_WriteAttribute_s_1d
  55. !
  56. module procedure hdf_WriteAttribute_s_0d
  57. module procedure hdf_WriteAttribute_s_1d
  58. end interface
  59. contains
  60. ! ############################################################
  61. ! ###
  62. ! ### objects
  63. ! ###
  64. ! ############################################################
  65. ! ================================================================
  66. ! ===
  67. ! === read attributes
  68. ! ===
  69. ! ================================================================
  70. subroutine obj_ReadAttribute_s_0d( obj_id, name, s, status )
  71. use file_hdf_base, only : wpi
  72. use file_hdf_base, only : FindAttribute, CheckAttributeInfo, GetAttributeInfo
  73. ! --- in/out -------------------------
  74. integer(wpi), intent(in) :: obj_id
  75. character(len=*), intent(in) :: name
  76. character(len=*), intent(inout) :: s
  77. integer, intent(out) :: status
  78. ! --- const -------------------------------
  79. character(len=*), parameter :: rname = mname//'/obj_ReadAttribute_s_0d'
  80. ! --- local -------------------------------
  81. integer :: attr_index, data_type
  82. integer :: n_values, n
  83. character(len=len(s)) :: sdum
  84. ! --- external ----------------------------
  85. integer(wpi), external :: sfRCAtt
  86. ! --- begin -------------------------------
  87. call FindAttribute( obj_id, name, attr_index, status )
  88. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  89. call GetAttributeInfo( obj_id, attr_index, status, n_values=n_values )
  90. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  91. n = min( n_values, len(s) )
  92. ! extract value:
  93. call GetAttributeInfo( obj_id, attr_index, status, data_type=data_type )
  94. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  95. ! read:
  96. select case ( data_type )
  97. case ( DFNT_CHAR )
  98. status = sfRCAtt( obj_id, attr_index, sdum )
  99. s = trim(sdum(1:n))
  100. case default
  101. write (*,'("ERROR - not implemented for data type ",i6)') data_type
  102. write (*,'("ERROR in ",a)') rname; status=1; return
  103. end select
  104. if ( status /= SUCCEED ) then
  105. write (*,'("ERROR - reading attribute : ",a)') trim(name)
  106. write (*,'("ERROR in ",a)') rname; status=1; return
  107. end if
  108. ! ok
  109. status = 0
  110. end subroutine obj_ReadAttribute_s_0d
  111. ! ***
  112. subroutine obj_ReadAttribute_s_1d( obj_id, name, s, status )
  113. use file_hdf_base, only : wpi
  114. use file_hdf_base, only : FindAttribute, CheckAttributeInfo, GetAttributeInfo
  115. ! --- in/out -------------------------
  116. integer(wpi), intent(in) :: obj_id
  117. character(len=*), intent(in) :: name
  118. character(len=*), intent(out) :: s(:)
  119. integer, intent(out) :: status
  120. ! --- const -------------------------------
  121. character(len=*), parameter :: rname = mname//'/obj_ReadAttribute_s_1d'
  122. ! --- local -------------------------------
  123. integer :: attr_index, data_type
  124. ! --- external ----------------------------
  125. integer(wpi), external :: sfRCAtt
  126. ! --- begin -------------------------------
  127. call FindAttribute( obj_id, name, attr_index, status )
  128. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  129. !call CheckAttributeInfo( obj_id, attr_index, n_values=len(s)*size(s) )
  130. !if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  131. ! extract value:
  132. call GetAttributeInfo( obj_id, attr_index, status, data_type=data_type )
  133. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  134. ! read:
  135. select case ( data_type )
  136. case ( DFNT_CHAR )
  137. status = sfRCAtt( obj_id, attr_index, s )
  138. case default
  139. write (*,'("ERROR - not implemented for data type ",i6)') data_type
  140. write (*,'("ERROR in ",a)') rname; status=1; return
  141. end select
  142. if ( status /= SUCCEED ) then
  143. write (*,'("ERROR - reading attribute : ",a)') trim(name)
  144. write (*,'("ERROR in ",a)') rname; status=1; return
  145. end if
  146. ! ok
  147. status = 0
  148. end subroutine obj_ReadAttribute_s_1d
  149. ! ================================================================
  150. ! ===
  151. ! === check attributes
  152. ! ===
  153. ! ================================================================
  154. subroutine obj_CheckAttribute_s_0d( obj_id, name, s, status )
  155. use file_hdf_base, only : wpi
  156. ! --- in/out -------------------------
  157. integer(wpi), intent(in) :: obj_id
  158. character(len=*), intent(in) :: name
  159. character(len=*), intent(in) :: s
  160. integer, intent(inout) :: status
  161. ! --- const -------------------------------
  162. character(len=*), parameter :: rname = mname//'/obj_CheckAttribute_s_0d'
  163. ! --- local -------------------------------
  164. logical :: verbose
  165. character(len=len(s)) :: attr_s
  166. ! --- begin -------------------------------
  167. ! write error messages ?
  168. verbose = status == 0
  169. call ReadAttribute( obj_id, name, attr_s, status )
  170. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  171. ! check:
  172. if ( attr_s /= s ) then
  173. if (verbose) then
  174. write (*,'("ERROR - foud different attribute values:")')
  175. write (*,'("ERROR - attr name : ",a)') trim(name)
  176. write (*,'("ERROR - requested : ",a)') trim(s)
  177. write (*,'("ERROR - found : ",a)') trim(attr_s)
  178. write (*,'("ERROR in ",a)') rname
  179. end if
  180. status=-1; return
  181. end if
  182. ! ok
  183. status = 0
  184. end subroutine obj_CheckAttribute_s_0d
  185. ! ***
  186. subroutine obj_CheckAttribute_s_1d( obj_id, name, s, status )
  187. use file_hdf_base, only : wpi
  188. ! --- in/out -------------------------
  189. integer(wpi), intent(in) :: obj_id
  190. character(len=*), intent(in) :: name
  191. character(len=*), intent(in) :: s(:)
  192. integer, intent(inout) :: status
  193. ! --- const -------------------------------
  194. character(len=*), parameter :: rname = mname//'/obj_CheckAttribute_s_1d'
  195. ! --- local -------------------------------
  196. logical :: verbose
  197. character(len=len(s)) :: attr_s(size(s))
  198. ! --- begin -------------------------------
  199. ! write error messages ?
  200. verbose = status == 0
  201. call ReadAttribute( obj_id, name, attr_s, status )
  202. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  203. ! check
  204. if ( any( attr_s /= s ) ) then
  205. if (verbose) then
  206. write (*,'("ERROR - foud different attribute values:")')
  207. write (*,'("ERROR - attr name : ",a)') trim(name)
  208. write (*,'("ERROR - requested : ",a," ...")') trim(s(1))
  209. write (*,'("ERROR - found : ",a," ...")') trim(attr_s(1))
  210. write (*,'("ERROR in ",a)') rname
  211. end if
  212. status=-1; return
  213. end if
  214. ! ok
  215. status = 0
  216. end subroutine obj_CheckAttribute_s_1d
  217. ! ================================================================
  218. ! ===
  219. ! === write attributes
  220. ! ===
  221. ! ================================================================
  222. subroutine obj_WriteAttribute_s_0d( obj_id, name, s, status )
  223. use file_hdf_base, only : wpi
  224. ! --- in/out -------------------------
  225. integer(wpi), intent(in) :: obj_id
  226. character(len=*), intent(in) :: name
  227. character(len=*), intent(in) :: s
  228. integer, intent(out) :: status
  229. ! --- const -------------------------------
  230. character(len=*), parameter :: rname = mname//'/obj_WriteAttribute_s_0d'
  231. ! --- external ----------------------------
  232. integer(wpi), external :: sfSCAtt
  233. ! --- begin -------------------------------
  234. status = sfSCAtt( obj_id, name, DFNT_CHAR, len(s), s )
  235. if ( status /= SUCCEED ) then
  236. write (*,'("ERROR - error writing attribute ",a)') trim(name)
  237. write (*,'("ERROR in ",a)') rname; status=1; return
  238. end if
  239. ! ok
  240. status = 0
  241. end subroutine obj_WriteAttribute_s_0d
  242. ! ***
  243. subroutine obj_WriteAttribute_s_1d( obj_id, name, s, status )
  244. use file_hdf_base, only : wpi
  245. ! --- in/out -------------------------
  246. integer(wpi), intent(in) :: obj_id
  247. character(len=*), intent(in) :: name
  248. character(len=*), intent(in) :: s(:)
  249. integer, intent(out) :: status
  250. ! --- const -------------------------------
  251. character(len=*), parameter :: rname = mname//'/obj_WriteAttribute_s_1d'
  252. ! --- external ----------------------------
  253. integer(wpi), external :: sfSCAtt
  254. ! --- begin -------------------------------
  255. status = sfSCAtt( obj_id, name, DFNT_CHAR, len(s)*size(s), s )
  256. if ( status /= SUCCEED ) then
  257. write (*,'("ERROR - error writing attribute ",a)') trim(name)
  258. write (*,'("ERROR in ",a)') rname; status=1; return
  259. end if
  260. ! ok
  261. status = 0
  262. end subroutine obj_WriteAttribute_s_1d
  263. ! ############################################################
  264. ! ###
  265. ! ### scientific data sets
  266. ! ###
  267. ! ############################################################
  268. ! ================================================================
  269. ! get attributes
  270. ! ================================================================
  271. subroutine sds_ReadAttribute_s_0d( sds, name, s, status )
  272. use file_hdf_base, only : TSds
  273. ! --- in/out -------------------------
  274. type(Tsds), intent(in) :: sds
  275. character(len=*), intent(in) :: name
  276. character(len=*), intent(inout) :: s
  277. integer, intent(out) :: status
  278. ! --- const -------------------------------
  279. character(len=*), parameter :: rname = mname//'/sds_ReadAttribute_s_0d'
  280. ! --- begin -------------------------------
  281. call ReadAttribute( sds%id, name, s, status )
  282. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  283. ! ok
  284. status = 0
  285. end subroutine sds_ReadAttribute_s_0d
  286. ! ***
  287. subroutine sds_ReadAttribute_s_1d( sds, name, s, status )
  288. use file_hdf_base, only : TSds
  289. ! --- in/out -------------------------
  290. type(Tsds), intent(in) :: sds
  291. character(len=*), intent(in) :: name
  292. character(len=*), intent(out) :: s(:)
  293. integer, intent(inout) :: status
  294. ! --- const -------------------------------
  295. character(len=*), parameter :: rname = mname//'/sds_ReadAttribute_s_1d'
  296. ! --- begin -------------------------------
  297. call ReadAttribute( sds%id, name, s, status )
  298. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  299. ! ok
  300. status = 0
  301. end subroutine sds_ReadAttribute_s_1d
  302. ! =============================================================
  303. ! === check attributes
  304. ! =============================================================
  305. subroutine sds_CheckAttribute_s_0d( sds, name, s, status )
  306. use file_hdf_base, only : TSds
  307. ! --- in/out -------------------------
  308. type(TSds), intent(in) :: sds
  309. character(len=*), intent(in) :: name
  310. character(len=*), intent(in) :: s
  311. integer, intent(inout) :: status
  312. ! --- const -------------------------------
  313. character(len=*), parameter :: rname = mname//'/sds_CheckAttribute_s_0d'
  314. ! --- local ------------------------------
  315. logical :: verbose
  316. ! --- begin ---------------------------
  317. ! write error messages ?
  318. verbose = status == 0
  319. call CheckAttribute( sds%id, name, s, status )
  320. if (status>0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  321. if (status<0) then
  322. if (verbose) write (*,'("ERROR in ",a)') rname
  323. status=-1; return
  324. end if
  325. ! ok
  326. status = 0
  327. end subroutine sds_CheckAttribute_s_0d
  328. ! ***
  329. subroutine sds_CheckAttribute_s_1d( sds, name, s, status )
  330. use file_hdf_base, only : TSds
  331. ! --- in/out -------------------------
  332. type(TSds), intent(in) :: sds
  333. character(len=*), intent(in) :: name
  334. character(len=*), intent(in) :: s(:)
  335. integer, intent(inout) :: status
  336. ! --- const -------------------------------
  337. character(len=*), parameter :: rname = mname//'/sds_CheckAttribute_s_1d'
  338. ! --- local ------------------------------
  339. logical :: verbose
  340. ! --- begin ---------------------------
  341. ! write error messages ?
  342. verbose = status == 0
  343. call CheckAttribute( sds%id, name, s, status )
  344. if (status>0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  345. if (status<0) then
  346. if (verbose) write (*,'("ERROR in ",a)') rname
  347. status=-1; return
  348. end if
  349. ! ok
  350. status = 0
  351. end subroutine sds_CheckAttribute_s_1d
  352. ! ================================================================
  353. ! write attributes
  354. ! ================================================================
  355. subroutine sds_WriteAttribute_s_0d( sds, name, s, status )
  356. use file_hdf_base, only : TSds
  357. ! --- in/out -------------------------
  358. type(Tsds), intent(in) :: sds
  359. character(len=*), intent(in) :: name
  360. character(len=*), intent(in) :: s
  361. integer, intent(out) :: status
  362. ! --- const -------------------------------
  363. character(len=*), parameter :: rname = mname//'/sds_WriteAttribute_s_0d'
  364. ! --- begin -------------------------------
  365. call WriteAttribute( sds%id, name, s, status )
  366. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  367. ! ok
  368. status = 0
  369. end subroutine sds_WriteAttribute_s_0d
  370. ! ***
  371. subroutine sds_WriteAttribute_s_1d( sds, name, s, status )
  372. use file_hdf_base, only : TSds
  373. ! --- in/out -------------------------
  374. type(Tsds), intent(in) :: sds
  375. character(len=*), intent(in) :: name
  376. character(len=*), intent(in) :: s(:)
  377. integer, intent(out) :: status
  378. ! --- const -------------------------------
  379. character(len=*), parameter :: rname = mname//'/sds_WriteAttribute_s_1d'
  380. ! --- begin -------------------------------
  381. call WriteAttribute( sds%id, name, s, status )
  382. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  383. ! ok
  384. status = 0
  385. end subroutine sds_WriteAttribute_s_1d
  386. ! =============================================================
  387. ! === read data
  388. ! =============================================================
  389. subroutine sds_ReadData_s_1d( sds, data, status, start, stride )
  390. use file_hdf_base, only : wpi
  391. use file_hdf_base, only : TSds
  392. use file_hdf_base, only : CheckInfo, GetInfo
  393. ! --- const ------------------------------
  394. character(len=*), parameter :: rname = mname//'/sds_ReadData_s_1d'
  395. integer, parameter :: rank = 1
  396. ! --- in/out ----------------------------
  397. type(TSds), intent(in) :: sds
  398. character(len=*), intent(out) :: data
  399. integer, intent(out) :: status
  400. integer, intent(in), optional :: start(rank)
  401. integer, intent(in), optional :: stride(rank)
  402. ! --- local -------------------------------
  403. integer :: data_type
  404. integer :: the_start(rank)
  405. integer :: the_stride(rank)
  406. integer :: data_dims(rank)
  407. ! --- external ----------------------------
  408. integer(wpi), external :: sfRData
  409. ! --- begin -------------------------------
  410. ! check data rank and shape:
  411. !call CheckInfo( sds, data_rank=rank, data_dims=shape(data) )
  412. ! set dims etc
  413. the_start = 0; if ( present(start ) ) the_start = start
  414. the_stride = 1; if ( present(stride) ) the_stride = stride
  415. data_dims = (/len(data)/)
  416. ! read data of specified kind:
  417. call GetInfo( sds, status, data_type=data_type )
  418. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  419. ! read
  420. select case ( data_type )
  421. case ( DFNT_CHAR )
  422. status = sfRData( sds%id, the_start, the_stride, data_dims, data )
  423. case default
  424. write (*,'("ERROR - not implemented for data type ",i6)') data_type
  425. write (*,'("ERROR in ",a)') rname; status=1; return
  426. end select
  427. if ( status == FAIL ) then
  428. write (*,'("ERROR - reading data `",a,"`")') trim(sds%name)
  429. write (*,'("ERROR in ",a)') rname; status=1; return
  430. end if
  431. ! ok
  432. status = 0
  433. end subroutine sds_ReadData_s_1d
  434. ! ***
  435. subroutine sds_ReadData_s_2d( sds, data, status, start, stride )
  436. use file_hdf_base, only : wpi
  437. use file_hdf_base, only : TSds
  438. use file_hdf_base, only : wp_int8, wp_int16, wp_int32, wp_int64
  439. use file_hdf_base, only : CheckInfo, GetInfo
  440. ! --- const ------------------------------
  441. character(len=*), parameter :: rname = mname//'/sds_ReadData_s_2d'
  442. integer, parameter :: rank = 2
  443. ! --- in/out ----------------------------
  444. type(TSds), intent(in) :: sds
  445. character(len=*), intent(out) :: data(:)
  446. integer, intent(out) :: status
  447. integer, intent(in), optional :: start(rank)
  448. integer, intent(in), optional :: stride(rank)
  449. ! --- local -------------------------------
  450. integer :: data_type
  451. integer :: the_start(rank)
  452. integer :: the_stride(rank)
  453. integer :: data_dims(rank)
  454. ! --- external ----------------------------
  455. integer(wpi), external :: sfRData
  456. ! --- begin -------------------------------
  457. ! check data rank and shape:
  458. !call CheckInfo( sds, data_rank=rank, data_dims=shape(data) )
  459. ! set dims etc
  460. the_start = 0; if ( present(start ) ) the_start = start
  461. the_stride = 1; if ( present(stride) ) the_stride = stride
  462. data_dims = (/len(data),shape(data)/)
  463. ! read data of specified kind:
  464. call GetInfo( sds, status, data_type=data_type )
  465. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  466. ! read
  467. select case ( data_type )
  468. case ( DFNT_CHAR )
  469. status = sfRData( sds%id, the_start, the_stride, data_dims, data )
  470. case default
  471. write (*,'("ERROR - not implemented for data type ",i6)') data_type
  472. write (*,'("ERROR in ",a)') rname; status=1; return
  473. end select
  474. if ( status == FAIL ) then
  475. write (*,'("ERROR - reading data `",a,"`")') trim(sds%name)
  476. write (*,'("ERROR in ",a)') rname; status=1; return
  477. end if
  478. ! ok
  479. status = 0
  480. end subroutine sds_ReadData_s_2d
  481. ! =============================================================
  482. ! === Write data
  483. ! =============================================================
  484. subroutine sds_WriteData_s_1d( sds, data, status, start, stride )
  485. use file_hdf_base, only : wpi
  486. use file_hdf_base, only : TSds
  487. ! --- const --------------------------
  488. character(len=*), parameter :: rname = mname//'/sds_WriteData_s_1d'
  489. integer, parameter :: rank = 1
  490. ! --- in/out -------------------------
  491. type(TSds), intent(in) :: sds
  492. character(len=*), intent(in) :: data
  493. integer, intent(out) :: status
  494. integer, intent(in), optional :: start(rank)
  495. integer, intent(in), optional :: stride(rank)
  496. ! --- local -------------------------------
  497. integer :: the_start(rank), the_stride(rank)
  498. integer :: data_dims(rank)
  499. ! --- external ----------------------------
  500. integer(wpi), external :: sfWData
  501. ! --- begin -------------------------------
  502. !! check shape
  503. !if ( any( shape(data) /= sds%shp(1:sds%rnk) ) ) then
  504. ! print *, 'Shape of data does not match shape specified during creation:'
  505. ! print *, ' data : ', shape(data)
  506. ! print *, ' created for : ', sds%shp(1:sds%rnk)
  507. ! stop 'FATAL ERROR IN sds_WriteData_i<wp>_1d'
  508. !end if
  509. ! write data:
  510. the_start = 0; if ( present(start ) ) the_start = start
  511. the_stride = 1; if ( present(stride) ) the_stride = stride
  512. data_dims = (/len(data)/)
  513. select case ( sds%typ )
  514. case ( 'chr' )
  515. status = sfWData( sds%id, the_start, the_stride, data_dims, data )
  516. case default
  517. write (*,'("ERROR - unknown sds%typ `",a,"`")') sds%typ
  518. write (*,'("ERROR in ",a)') rname; status=1; return
  519. end select
  520. if ( status == FAIL ) then
  521. write (*,'("ERROR - error writing data `",a,"`")') trim(sds%name)
  522. write (*,'("ERROR in ",a)') rname; status=1; return
  523. end if
  524. ! ok
  525. status = 0
  526. end subroutine sds_WriteData_s_1d
  527. ! ***
  528. subroutine sds_WriteData_s_2d( sds, data, status, start, stride )
  529. use file_hdf_base, only : wpi
  530. use file_hdf_base, only : TSds
  531. ! --- const --------------------------
  532. character(len=*), parameter :: rname = mname//'/sds_WriteData_s_2d'
  533. integer, parameter :: rank = 2
  534. ! --- in/out -------------------------
  535. type(TSds), intent(in) :: sds
  536. character(len=*), intent(in) :: data(:)
  537. integer, intent(out) :: status
  538. integer, intent(in), optional :: start(rank)
  539. integer, intent(in), optional :: stride(rank)
  540. ! --- local -------------------------------
  541. integer :: the_start(rank), the_stride(rank)
  542. integer :: data_dims(rank)
  543. ! --- external ----------------------------
  544. integer(wpi), external :: sfWData
  545. ! --- begin -------------------------------
  546. !! check shape
  547. !if ( any( shape(data) /= sds%shp(1:sds%rnk) ) ) then
  548. ! print *, 'Shape of data does not match shape specified during creation:'
  549. ! print *, ' data : ', shape(data)
  550. ! print *, ' created for : ', sds%shp(1:sds%rnk)
  551. ! stop 'FATAL ERROR IN sds_WriteData_i<wp>_2d'
  552. !end if
  553. ! write data:
  554. the_start = 0; if ( present(start ) ) the_start = start
  555. the_stride = 1; if ( present(stride) ) the_stride = stride
  556. data_dims = (/len(data),shape(data)/)
  557. select case ( sds%typ )
  558. case ( 'chr' )
  559. status = sfWData( sds%id, the_start, the_stride, data_dims, data )
  560. case default
  561. write (*,'("ERROR - unknown sds%typ `",a,"`")') sds%typ
  562. write (*,'("ERROR in ",a)') rname; status=1; return
  563. end select
  564. if ( status == FAIL ) then
  565. write (*,'("ERROR - error writing data `",a,"`")') trim(sds%name)
  566. write (*,'("ERROR in ",a)') rname; status=1; return
  567. end if
  568. ! ok
  569. status = 0
  570. end subroutine sds_WriteData_s_2d
  571. ! ############################################################
  572. ! ###
  573. ! ### dimensions
  574. ! ###
  575. ! ############################################################
  576. ! ================================================================
  577. ! get attributes
  578. ! ================================================================
  579. subroutine dim_ReadAttribute_s_0d( sdim, name, s, status )
  580. use file_hdf_base, only : TSdsDim
  581. ! --- in/out -------------------------
  582. type(TSdsDim), intent(in) :: sdim
  583. character(len=*), intent(in) :: name
  584. character(len=*), intent(inout) :: s
  585. integer, intent(out) :: status
  586. ! --- const --------------------------
  587. character(len=*), parameter :: rname = mname//'/dim_ReadAttribute_s_0d'
  588. ! --- begin -------------------------------
  589. call ReadAttribute( sdim%id, name, s, status )
  590. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  591. ! ok
  592. status = 0
  593. end subroutine dim_ReadAttribute_s_0d
  594. ! ***
  595. subroutine dim_ReadAttribute_s_1d( sdim, name, s, status )
  596. use file_hdf_base, only : TSdsDim
  597. ! --- in/out -------------------------
  598. type(TSdsDim), intent(in) :: sdim
  599. character(len=*), intent(in) :: name
  600. character(len=*), intent(out) :: s(:)
  601. integer, intent(out) :: status
  602. ! --- const --------------------------
  603. character(len=*), parameter :: rname = mname//'/dim_ReadAttribute_s_1d'
  604. ! --- begin -------------------------------
  605. call ReadAttribute( sdim%id, name, s, status )
  606. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  607. ! ok
  608. status = 0
  609. end subroutine dim_ReadAttribute_s_1d
  610. ! =============================================================
  611. ! === check attributes
  612. ! =============================================================
  613. subroutine dim_CheckAttribute_s_0d( sdim, name, s, status )
  614. use file_hdf_base, only : TSdsDim
  615. ! --- in/out -------------------------
  616. type(TSdsDim), intent(in) :: sdim
  617. character(len=*), intent(in) :: name
  618. character(len=*), intent(in) :: s
  619. integer, intent(inout) :: status
  620. ! --- const --------------------------
  621. character(len=*), parameter :: rname = mname//'/dim_CheckAttribute_s_0d'
  622. ! --- local ------------------------------
  623. logical :: verbose
  624. ! --- begin ---------------------------
  625. ! write error messages ?
  626. verbose = status == 0
  627. call CheckAttribute( sdim%id, name, s, status )
  628. if (status>0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  629. if (status<0) then
  630. if (verbose) write (*,'("ERROR in ",a)') rname
  631. status=-1; return
  632. end if
  633. ! ok
  634. status = 0
  635. end subroutine dim_CheckAttribute_s_0d
  636. ! ***
  637. subroutine dim_CheckAttribute_s_1d( sdim, name, s, status )
  638. use file_hdf_base, only : TSdsDim
  639. ! --- in/out -------------------------
  640. type(TSdsDim), intent(in) :: sdim
  641. character(len=*), intent(in) :: name
  642. character(len=*), intent(in) :: s(:)
  643. integer, intent(inout) :: status
  644. ! --- const --------------------------
  645. character(len=*), parameter :: rname = mname//'/dim_CheckAttribute_s_1d'
  646. ! --- local ------------------------------
  647. logical :: verbose
  648. ! --- begin ---------------------------
  649. ! write error messages ?
  650. verbose = status == 0
  651. call CheckAttribute( sdim%id, name, s, status )
  652. if (status>0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  653. if (status<0) then
  654. if (verbose) write (*,'("ERROR in ",a)') rname
  655. status=-1; return
  656. end if
  657. ! ok
  658. status = 0
  659. end subroutine dim_CheckAttribute_s_1d
  660. ! ================================================================
  661. ! write attributes
  662. ! ================================================================
  663. subroutine dim_WriteAttribute_s_0d( sdim, name, s, status )
  664. use file_hdf_base, only : TSdsDim
  665. ! --- in/out -------------------------
  666. type(TSdsDim), intent(in) :: sdim
  667. character(len=*), intent(in) :: name
  668. character(len=*), intent(in) :: s
  669. integer, intent(out) :: status
  670. ! --- const --------------------------
  671. character(len=*), parameter :: rname = mname//'/dim_WriteAttribute_s_0d'
  672. ! --- begin -------------------------------
  673. call WriteAttribute( sdim%id, name, s, status )
  674. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  675. ! ok
  676. status = 0
  677. end subroutine dim_WriteAttribute_s_0d
  678. ! ***
  679. subroutine dim_WriteAttribute_s_1d( sdim, name, s, status )
  680. use file_hdf_base, only : TSdsDim
  681. ! --- in/out -------------------------
  682. type(TSdsDim), intent(in) :: sdim
  683. character(len=*), intent(in) :: name
  684. character(len=*), intent(in) :: s(:)
  685. integer, intent(out) :: status
  686. ! --- const --------------------------
  687. character(len=*), parameter :: rname = mname//'/dim_WriteAttribute_s_1d'
  688. ! --- begin -------------------------------
  689. call WriteAttribute( sdim%id, name, s, status )
  690. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  691. ! ok
  692. status = 0
  693. end subroutine dim_WriteAttribute_s_1d
  694. ! ############################################################
  695. ! ###
  696. ! ### hdf files
  697. ! ###
  698. ! ############################################################
  699. ! ================================================================
  700. ! get attributes
  701. ! ================================================================
  702. subroutine hdf_ReadAttribute_s_0d( hdf, name, s, status )
  703. use file_hdf_base, only : THdfFile
  704. ! --- in/out -------------------------
  705. type(THdfFile), intent(in) :: hdf
  706. character(len=*), intent(in) :: name
  707. character(len=*), intent(inout) :: s
  708. integer, intent(out) :: status
  709. ! --- const --------------------------
  710. character(len=*), parameter :: rname = mname//'/hdf_ReadAttribute_s_0d'
  711. ! --- begin -------------------------------
  712. call ReadAttribute( hdf%id, name, s, status )
  713. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  714. ! ok
  715. status = 0
  716. end subroutine hdf_ReadAttribute_s_0d
  717. ! ***
  718. subroutine hdf_ReadAttribute_s_1d( hdf, name, s, status )
  719. use file_hdf_base, only : THdfFile
  720. ! --- in/out -------------------------
  721. type(THdfFile), intent(in) :: hdf
  722. character(len=*), intent(in) :: name
  723. character(len=*), intent(out) :: s(:)
  724. integer, intent(out) :: status
  725. ! --- const --------------------------
  726. character(len=*), parameter :: rname = mname//'/hdf_ReadAttribute_s_1d'
  727. ! --- begin -------------------------------
  728. call ReadAttribute( hdf%id, name, s, status )
  729. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  730. ! ok
  731. status = 0
  732. end subroutine hdf_ReadAttribute_s_1d
  733. ! =============================================================
  734. ! === check attributes
  735. ! =============================================================
  736. subroutine hdf_CheckAttribute_s_0d( hdf, name, s, status )
  737. use file_hdf_base, only : THdfFile
  738. ! --- in/out -------------------------
  739. type(THdfFile), intent(in) :: hdf
  740. character(len=*), intent(in) :: name
  741. character(len=*), intent(in) :: s
  742. integer, intent(inout) :: status
  743. ! --- const --------------------------
  744. character(len=*), parameter :: rname = mname//'/hdf_CheckAttribute_s_0d'
  745. ! --- local ------------------------------
  746. logical :: verbose
  747. ! --- begin ---------------------------
  748. ! write error messages ?
  749. verbose = status == 0
  750. call CheckAttribute( hdf%id, name, s, status )
  751. if (status>0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  752. if (status<0) then
  753. if (verbose) write (*,'("ERROR in ",a)') rname
  754. status=-1; return
  755. end if
  756. ! ok
  757. status = 0
  758. end subroutine hdf_CheckAttribute_s_0d
  759. ! ***
  760. subroutine hdf_CheckAttribute_s_1d( hdf, name, s, status )
  761. use file_hdf_base, only : THdfFile
  762. ! --- in/out -------------------------
  763. type(THdfFile), intent(in) :: hdf
  764. character(len=*), intent(in) :: name
  765. character(len=*), intent(in) :: s(:)
  766. integer, intent(inout) :: status
  767. ! --- const --------------------------
  768. character(len=*), parameter :: rname = mname//'/hdf_CheckAttribute_s_1d'
  769. ! --- local ------------------------------
  770. logical :: verbose
  771. ! --- begin ---------------------------
  772. ! write error messages ?
  773. verbose = status == 0
  774. call CheckAttribute( hdf%id, name, s, status )
  775. if (status>0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  776. if (status<0) then
  777. if (verbose) write (*,'("ERROR in ",a)') rname
  778. status=-1; return
  779. end if
  780. ! ok
  781. status = 0
  782. end subroutine hdf_CheckAttribute_s_1d
  783. ! ================================================================
  784. ! write attributes
  785. ! ================================================================
  786. subroutine hdf_WriteAttribute_s_0d( hdf, name, s, status )
  787. use file_hdf_base, only : THdfFile
  788. ! --- in/out -------------------------
  789. type(THdfFile), intent(in) :: hdf
  790. character(len=*), intent(in) :: name
  791. character(len=*), intent(in) :: s
  792. integer, intent(out) :: status
  793. ! --- const --------------------------
  794. character(len=*), parameter :: rname = mname//'/hdf_WriteAttribute_s_0d'
  795. ! --- begin -------------------------------
  796. call WriteAttribute( hdf%id, name, s, status )
  797. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  798. ! ok
  799. status = 0
  800. end subroutine hdf_WriteAttribute_s_0d
  801. ! ***
  802. subroutine hdf_WriteAttribute_s_1d( hdf, name, s, status )
  803. use file_hdf_base, only : THdfFile
  804. ! --- in/out -------------------------
  805. type(THdfFile), intent(in) :: hdf
  806. character(len=*), intent(in) :: name
  807. character(len=*), intent(in) :: s(:)
  808. integer, intent(out) :: status
  809. ! --- const --------------------------
  810. character(len=*), parameter :: rname = mname//'/hdf_WriteAttribute_s_1d'
  811. ! --- begin -------------------------------
  812. call WriteAttribute( hdf%id, name, s, status )
  813. if (status/=0) then; write (*,'("ERROR in ",a)') rname; status=1; return; end if
  814. ! ok
  815. status = 0
  816. end subroutine hdf_WriteAttribute_s_1d
  817. end module file_hdf_s