xmlf_write_xml_primitives.f90 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. ! write_xml_prims.f90 - Write routines for primitive data
  2. !
  3. ! $Id: write_xml_prims.f90,v 1.2 2007/12/27 05:13:59 arjenmarkus Exp $
  4. !
  5. ! Arjen Markus
  6. !
  7. ! General information:
  8. ! This module is part of the XML-Fortran library. Its
  9. ! purpose is to write individual items to an XML
  10. ! file using the right tag. It is used by the code generated
  11. ! by the make_xml_reader program.
  12. !
  13. module xmlf_write_xml_primitives
  14. use xmlf_parse
  15. implicit none
  16. ! interface write_to_xml
  17. ! module procedure write_to_xml_integers
  18. ! module procedure write_to_xml_reals
  19. ! module procedure write_to_xml_doubles
  20. ! module procedure write_to_xml_logicals
  21. ! module procedure write_to_xml_words
  22. ! end interface
  23. interface write_to_xml_word
  24. module procedure write_to_xml_string
  25. end interface
  26. interface write_to_xml_line
  27. module procedure write_to_xml_string
  28. end interface
  29. contains
  30. ! write_to_xml_integer --
  31. ! Routine to write a single integer to the XML file
  32. !
  33. ! Arguments:
  34. ! info XML parser structure
  35. ! tag The tag in question
  36. ! indent Number of spaces for indentation
  37. ! value Value to be written
  38. !
  39. subroutine write_to_xml_integer( info, tag, indent, value )
  40. type(XML_PARSE), intent(in) :: info
  41. character(len=*), intent(in) :: tag
  42. integer, intent(in) :: indent
  43. integer, intent(in) :: value
  44. character(len=100) :: indentation
  45. indentation = ' '
  46. write( info%lun, '(4a,i0,3a)' ) indentation(1:min(indent,100)), &
  47. '<', trim(tag), '>', value, '</', trim(tag), '>'
  48. end subroutine write_to_xml_integer
  49. ! write_to_xml_integer_1dim --
  50. ! Routine to write an array of integers to the XML file
  51. !
  52. ! Arguments:
  53. ! info XML parser structure
  54. ! tag The tag in question
  55. ! indent Number of spaces for indentation
  56. ! values Values to be written
  57. !
  58. subroutine write_to_xml_integer_1dim( info, tag, indent, values )
  59. type(XML_PARSE), intent(in) :: info
  60. character(len=*), intent(in) :: tag
  61. integer, intent(in) :: indent
  62. integer, dimension(:), intent(in) :: values
  63. integer :: i
  64. do i = 1,size(values)
  65. call write_to_xml_integer( info, tag, indent, values(i) )
  66. enddo
  67. end subroutine write_to_xml_integer_1dim
  68. ! write_to_xml_real --
  69. ! Routine to write a single real value (single precision) to the XML file
  70. !
  71. ! Arguments:
  72. ! info XML parser structure
  73. ! tag The tag in question
  74. ! indent Number of spaces for indentation
  75. ! value Value to be written
  76. !
  77. subroutine write_to_xml_real( info, tag, indent, value )
  78. type(XML_PARSE), intent(in) :: info
  79. character(len=*), intent(in) :: tag
  80. integer, intent(in) :: indent
  81. real, intent(in) :: value
  82. character(len=100) :: indentation
  83. character(len=12) :: buffer
  84. indentation = ' '
  85. write( buffer, '(1pg12.4)' ) value
  86. write( info%lun, '(8a)' ) indentation(1:min(indent,100)), &
  87. '<', trim(tag), '>', trim(adjustl(buffer)), '</', trim(tag), '>'
  88. end subroutine write_to_xml_real
  89. ! write_to_xml_real_1dim --
  90. ! Routine to write an array of reals to the XML file
  91. !
  92. ! Arguments:
  93. ! info XML parser structure
  94. ! tag The tag in question
  95. ! indent Number of spaces for indentation
  96. ! values Values to be written
  97. !
  98. subroutine write_to_xml_real_1dim( info, tag, indent, values )
  99. type(XML_PARSE), intent(in) :: info
  100. character(len=*), intent(in) :: tag
  101. integer, intent(in) :: indent
  102. real, dimension(:), intent(in) :: values
  103. integer :: i
  104. do i = 1,size(values)
  105. call write_to_xml_real( info, tag, indent, values(i) )
  106. enddo
  107. end subroutine write_to_xml_real_1dim
  108. ! write_to_xml_double --
  109. ! Routine to write one real value (double precision) to the XML file
  110. !
  111. ! Arguments:
  112. ! info XML parser structure
  113. ! tag The tag in question
  114. ! indent Number of spaces for indentation
  115. ! value Value to be written
  116. !
  117. subroutine write_to_xml_double( info, tag, indent, value )
  118. type(XML_PARSE), intent(in) :: info
  119. character(len=*), intent(in) :: tag
  120. integer, intent(in) :: indent
  121. real(kind=kind(1.0d0)), intent(in) :: value
  122. character(len=100) :: indentation
  123. character(len=16) :: buffer
  124. indentation = ' '
  125. write( buffer, '(1pg16.7)' ) value
  126. write( info%lun, '(8a)' ) indentation(1:min(indent,100)), &
  127. '<', trim(tag), '>', trim(adjustl(buffer)), '</', trim(tag), '>'
  128. end subroutine write_to_xml_double
  129. ! write_to_xml_double_1dim --
  130. ! Routine to write an array of double precision reals to the XML file
  131. !
  132. ! Arguments:
  133. ! info XML parser structure
  134. ! tag The tag in question
  135. ! indent Number of spaces for indentation
  136. ! values Values to be written
  137. !
  138. subroutine write_to_xml_double_1dim( info, tag, indent, values )
  139. type(XML_PARSE), intent(in) :: info
  140. character(len=*), intent(in) :: tag
  141. integer, intent(in) :: indent
  142. real(kind=kind(1.0d00)), dimension(:), intent(in) :: values
  143. integer :: i
  144. do i = 1,size(values)
  145. call write_to_xml_double( info, tag, indent, values(i) )
  146. enddo
  147. end subroutine write_to_xml_double_1dim
  148. ! write_to_xml_string --
  149. ! Routine to write one string to the XML file
  150. !
  151. ! Arguments:
  152. ! info XML parser structure
  153. ! tag The tag in question
  154. ! indent Number of spaces for indentation
  155. ! value Value to be written
  156. !
  157. subroutine write_to_xml_string( info, tag, indent, value )
  158. type(XML_PARSE), intent(in) :: info
  159. character(len=*), intent(in) :: tag
  160. integer, intent(in) :: indent
  161. character(len=*), intent(in) :: value
  162. character(len=100) :: indentation
  163. !
  164. ! NOTE: No guards against <, >, & and " yet!
  165. ! NOTE: difference needed between words and lines?
  166. !
  167. indentation = ' '
  168. write( info%lun, '(8a)' ) indentation(1:min(indent,100)), &
  169. '<', trim(tag), '>', trim(value), '</', trim(tag), '>'
  170. end subroutine write_to_xml_string
  171. ! write_to_xml_word_1dim --
  172. ! Routine to write an array of single words to the XML file
  173. !
  174. ! Arguments:
  175. ! info XML parser structure
  176. ! tag The tag in question
  177. ! indent Number of spaces for indentation
  178. ! value Value to be written
  179. !
  180. subroutine write_to_xml_word_1dim( info, tag, indent, values )
  181. type(XML_PARSE), intent(in) :: info
  182. character(len=*), intent(in) :: tag
  183. integer, intent(in) :: indent
  184. character(len=*), dimension(:), intent(in) :: values
  185. integer :: i
  186. do i = 1,size(values)
  187. call write_to_xml_string( info, tag, indent, values(i) )
  188. enddo
  189. end subroutine write_to_xml_word_1dim
  190. ! write_to_xml_string_1dim --
  191. ! Routine to write an array of strings to the XML file
  192. !
  193. ! Arguments:
  194. ! info XML parser structure
  195. ! tag The tag in question
  196. ! indent Number of spaces for indentation
  197. ! values Values to be written
  198. !
  199. subroutine write_to_xml_string_1dim( info, tag, indent, values )
  200. type(XML_PARSE), intent(in) :: info
  201. character(len=*), intent(in) :: tag
  202. integer, intent(in) :: indent
  203. character(len=*), dimension(:), intent(in) :: values
  204. integer :: i
  205. do i = 1,size(values)
  206. call write_to_xml_string( info, tag, indent, values(i) )
  207. enddo
  208. end subroutine write_to_xml_string_1dim
  209. ! write_to_xml_logical --
  210. ! Routine to write one logical to the XML file
  211. !
  212. ! Arguments:
  213. ! info XML parser structure
  214. ! tag The tag in question
  215. ! indent Number of spaces for indentation
  216. ! value Value to be written
  217. !
  218. subroutine write_to_xml_logical( info, tag, indent, value )
  219. type(XML_PARSE), intent(in) :: info
  220. character(len=*), intent(in) :: tag
  221. integer, intent(in) :: indent
  222. logical, intent(in) :: value
  223. character(len=100) :: indentation
  224. indentation = ' '
  225. if ( value ) then
  226. write( info%lun, '(8a)' ) indentation(1:min(indent,100)), &
  227. '<', trim(tag), '>true</', trim(tag), '>'
  228. else
  229. write( info%lun, '(8a)' ) indentation(1:min(indent,100)), &
  230. '<', trim(tag), '>false</', trim(tag), '>'
  231. endif
  232. end subroutine write_to_xml_logical
  233. ! write_to_xml_logical_1dim --
  234. ! Routine to write an array of logicals to the XML file
  235. !
  236. ! Arguments:
  237. ! info XML parser structure
  238. ! tag The tag in question
  239. ! indent Number of spaces for indentation
  240. ! values Values to be written
  241. !
  242. subroutine write_to_xml_logical_1dim( info, tag, indent, values )
  243. type(XML_PARSE), intent(in) :: info
  244. character(len=*), intent(in) :: tag
  245. integer, intent(in) :: indent
  246. logical, dimension(:), intent(in) :: values
  247. integer :: i
  248. do i = 1,size(values)
  249. call write_to_xml_logical( info, tag, indent, values(i) )
  250. enddo
  251. end subroutine write_to_xml_logical_1dim
  252. ! write_to_xml_integer_array --
  253. ! Routine to write an array of integers to the XML file
  254. !
  255. ! Arguments:
  256. ! info XML parser structure
  257. ! tag The tag in question
  258. ! indent Number of spaces for indentation
  259. ! array Values to be written
  260. !
  261. subroutine write_to_xml_integer_array( info, tag, indent, array )
  262. type(XML_PARSE), intent(in) :: info
  263. character(len=*), intent(in) :: tag
  264. integer, intent(in) :: indent
  265. integer, dimension(:), intent(in) :: array
  266. character(len=100) :: indentation
  267. integer :: i, i2, j
  268. indentation = ' '
  269. write( info%lun, '(4a)' ) indentation(1:min(indent,100)), &
  270. '<', trim(tag), '>'
  271. do i = 1,size(array),10
  272. i2 = min( i + 9, size(array) )
  273. write( info%lun, '(a,10i12)' ) indentation(1:min(indent+4,100)), &
  274. ( array(j) ,j = i,i2 )
  275. enddo
  276. write( info%lun, '(4a)' ) indentation(1:min(indent,100)), &
  277. '</', trim(tag), '>'
  278. end subroutine write_to_xml_integer_array
  279. ! write_to_xml_real_array --
  280. ! Routine to write an array of single precision reals to the XML file
  281. !
  282. ! Arguments:
  283. ! info XML parser structure
  284. ! tag The tag in question
  285. ! indent Number of spaces for indentation
  286. ! array Values to be written
  287. !
  288. subroutine write_to_xml_real_array( info, tag, indent, array )
  289. type(XML_PARSE), intent(in) :: info
  290. character(len=*), intent(in) :: tag
  291. integer, intent(in) :: indent
  292. real, dimension(:), intent(in) :: array
  293. character(len=100) :: indentation
  294. integer :: i, i2, j
  295. indentation = ' '
  296. write( info%lun, '(4a)' ) indentation(1:min(indent,100)), &
  297. '<', trim(tag), '>'
  298. do i = 1,size(array),10
  299. i2 = min( i + 9, size(array) )
  300. write( info%lun, '(a,10g12.4)' ) indentation(1:min(indent+4,100)), &
  301. ( array(j) ,j = i,i2 )
  302. enddo
  303. write( info%lun, '(4a)' ) indentation(1:min(indent,100)), &
  304. '</', trim(tag), '>'
  305. end subroutine write_to_xml_real_array
  306. ! write_to_xml_double_array --
  307. ! Routine to write an array of double precision reals to the XML file
  308. !
  309. ! Arguments:
  310. ! info XML parser structure
  311. ! tag The tag in question
  312. ! indent Number of spaces for indentation
  313. ! array Values to be written
  314. !
  315. subroutine write_to_xml_double_array( info, tag, indent, array )
  316. type(XML_PARSE), intent(in) :: info
  317. character(len=*), intent(in) :: tag
  318. integer, intent(in) :: indent
  319. real(kind=kind(1.0d0)), dimension(:), intent(in) :: array
  320. character(len=100) :: indentation
  321. integer :: i, i2, j
  322. indentation = ' '
  323. write( info%lun, '(4a)' ) indentation(1:min(indent,100)), &
  324. '<', trim(tag), '>'
  325. do i = 1,size(array),5
  326. i2 = min( i + 4, size(array) )
  327. write( info%lun, '(a,5g20.7)' ) indentation(1:min(indent+4,100)), &
  328. ( array(j) ,j = i,i2 )
  329. enddo
  330. write( info%lun, '(4a)' ) indentation(1:min(indent,100)), &
  331. '</', trim(tag), '>'
  332. end subroutine write_to_xml_double_array
  333. ! write_to_xml_logical_array --
  334. ! Routine to write an array of logicals to the XML file
  335. !
  336. ! Arguments:
  337. ! info XML parser structure
  338. ! tag The tag in question
  339. ! indent Number of spaces for indentation
  340. ! array Values to be written
  341. !
  342. subroutine write_to_xml_logical_array( info, tag, indent, array )
  343. type(XML_PARSE), intent(in) :: info
  344. character(len=*), intent(in) :: tag
  345. integer, intent(in) :: indent
  346. logical, dimension(:), intent(in) :: array
  347. character(len=100) :: indentation
  348. integer :: i, i2, j
  349. indentation = ' '
  350. write( info%lun, '(4a)' ) indentation(1:min(indent,100)), &
  351. '<', trim(tag), '>'
  352. do i = 1,size(array),10
  353. i2 = min( i + 9, size(array) )
  354. write( info%lun, '(a,10a)' ) indentation(1:min(indent+4,100)), &
  355. ( merge('true ', 'false ', array(j)) ,j = i,i2 )
  356. enddo
  357. write( info%lun, '(4a)' ) indentation(1:min(indent,100)), &
  358. '</', trim(tag), '>'
  359. end subroutine write_to_xml_logical_array
  360. ! write_to_xml_word_array --
  361. ! Routine to write an array of words to the XML file
  362. !
  363. ! Arguments:
  364. ! info XML parser structure
  365. ! tag The tag in question
  366. ! indent Number of spaces for indentation
  367. ! array Values to be written
  368. !
  369. subroutine write_to_xml_word_array( info, tag, indent, array )
  370. type(XML_PARSE), intent(in) :: info
  371. character(len=*), intent(in) :: tag
  372. integer, intent(in) :: indent
  373. character(len=*), dimension(:), intent(in) :: array
  374. character(len=100) :: indentation
  375. integer :: i, i2, j
  376. indentation = ' '
  377. write( info%lun, '(4a)' ) indentation(1:min(indent,100)), &
  378. '<', trim(tag), '>'
  379. do i = 1,size(array),10
  380. i2 = min( i + 9, size(array) )
  381. write( info%lun, '(a,20a)' ) indentation(1:min(indent+4,100)), &
  382. ( trim(array(j)) , ' ' ,j = i,i2 )
  383. enddo
  384. write( info%lun, '(4a)' ) indentation(1:min(indent,100)), &
  385. '</', trim(tag), '>'
  386. end subroutine write_to_xml_word_array
  387. ! write_to_xml_line_array --
  388. ! Routine to write an array of lines to the XML file
  389. !
  390. ! Arguments:
  391. ! info XML parser structure
  392. ! tag The tag in question
  393. ! indent Number of spaces for indentation
  394. ! array Values to be written
  395. !
  396. subroutine write_to_xml_line_array( info, tag, indent, array )
  397. type(XML_PARSE), intent(in) :: info
  398. character(len=*), intent(in) :: tag
  399. integer, intent(in) :: indent
  400. logical, dimension(:), intent(in) :: array
  401. character(len=100) :: indentation
  402. integer :: i, i2, j
  403. indentation = ' '
  404. write( info%lun, '(4a)' ) indentation(1:min(indent,100)), &
  405. '<', trim(tag), '>'
  406. do i = 1,size(array)
  407. write( info%lun, '(a)' ) indentation(1:min(indent+4,100)), &
  408. array(i)
  409. enddo
  410. write( info%lun, '(4a)' ) indentation(1:min(indent,100)), &
  411. '</', trim(tag), '>'
  412. end subroutine write_to_xml_line_array
  413. end module xmlf_write_xml_primitives