xmlf_read_xml_array.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ! Part of XML-Fortran library:
  2. !
  3. ! $Id: read_xml_array.inc,v 1.3 2007/02/26 20:33:38 arjenmarkus Exp $
  4. !
  5. type(XML_PARSE), intent(inout) :: info
  6. character(len=*), intent(in) :: tag
  7. logical, intent(inout) :: endtag
  8. character(len=*), dimension(:,:), intent(in) :: attribs
  9. integer, intent(in) :: noattribs
  10. character(len=*), dimension(:), intent(in) :: data
  11. integer, intent(in) :: nodata
  12. logical, intent(inout) :: has_var
  13. integer, intent(out) :: status
  14. character(len=len(attribs(1,1))) :: buffer
  15. integer :: idx
  16. !
  17. ! The big trick:
  18. ! A string long enough to hold all data strings
  19. !
  20. character(len=nodata*(len(data(1))+1)) :: bufferd
  21. integer :: start
  22. !
  23. ! The value can be stored in an attribute values="..." or in
  24. ! the data
  25. !
  26. has_var = .false.
  27. idx = xml_find_attrib( attribs, noattribs, 'values', buffer )
  28. if ( idx .gt. 0 ) then
  29. call read_from_buffer( buffer, var, status )
  30. if ( buffer .ne. ' ' ) then
  31. has_var = .true.
  32. endif
  33. else
  34. bufferd = ' '
  35. start = 1
  36. do idx = 1,nodata
  37. if ( data(idx) .ne. ' ' ) then
  38. bufferd(start:) = data(idx)
  39. start = start + len(data(idx)) + 1
  40. endif
  41. enddo
  42. call read_from_buffer( bufferd, var, status )
  43. if ( bufferd .ne. ' ' ) then
  44. has_var = .true.
  45. endif
  46. endif
  47. if ( status .ne. 0 ) then
  48. write(*,*) 'Error reading variable - tag = ', trim(tag)
  49. has_var = .false.
  50. endif