Skip to content
This repository
Browse code

wxml/wcml: Add fx%extended_data and use for wcml

In order to implement validity constraints imposed by the
CML schema and compchem convention without breaking
applications that already use FoX_wcml we need a way to
allow FoX_wcml to change behaviour depending on how it
is used. This ability could be useful for other
'writer' modules.

In FoX_wcml add an optional logical input argument to
cmlStartCml which (1) adds two extra namespace declarations
needed for the compchem convention and (2) uses this
namespace to put prefixes on the UUID metadata and convention
values. In future this could also turn on some limited
run-time valididity checking.

In order to keep track of if this is on or off add a
new integer member to the xmlf_t. This is 0 by default
and by stuffing some other number in it the useing
module is expected to change its own behaviour. This
member is accessed by a new function xmlf_GetExtendedData
(which takes a single xmlf_t argument and returns an integer)
and set by a new subroutine, xmlf_SetExtendedData (which takes
two arguments, the xmlf_t type and and integer value to set).

Finally, add a test to show that this actually does something and
update the documentation.
  • Loading branch information...
commit d9bb999a7cb34544dea0d44b0656df52f1cc264d 1 parent 6ae5a66
Andrew Walker authored April 24, 2012
3  DoX/FoX_wcml.md
Source Rendered
@@ -175,7 +175,8 @@ and then output all our properties and parameters with `dictRef="siesta:somethin
175 175
 
176 176
 * `cmlStartCml`  
177 177
 (**fileId**) *string* *scalar*: name of originating file.  (default: current filename)  
178  
-(**version**) *string* *scalar*: version of CML in use.  (default: 2.4)
  178
+(**version**) *string* *scalar*: version of CML in use.  (default: 2.4)  
  179
+(**compchem**) *logical* *scalar*: add extra namespace declarations needed by the recent compchem CML convention. This provides a minimum level of infrastructure needed to create valid compchem documents. (default: false)
179 180
 
180 181
 * `cmlEndCml`
181 182
 
19  wcml/m_wcml_core.F90
@@ -11,6 +11,7 @@ module m_wcml_core
11 11
   use FoX_wxml, only: xml_NewElement, xml_AddAttribute
12 12
   use FoX_wxml, only: xml_EndElement, xml_DeclareNamespace
13 13
   use FoX_wxml, only: xmlf_Name, xmlf_OpenTag
  14
+  use FoX_wxml, only: xmlf_GetExtendedData, xmlf_SetExtendedData
14 15
 
15 16
   use m_wcml_metadata, only: cmlAddMetadata
16 17
 #endif
@@ -69,7 +70,7 @@ subroutine cmlAddNamespace(xf, prefix, URI)
69 70
   end subroutine cmlAddNamespace
70 71
 
71 72
 
72  
-  subroutine cmlStartCml(xf, id, title, convention, dictref, fileId, version)
  73
+  subroutine cmlStartCml(xf, id, title, convention, dictref, fileId, version, compchem)
73 74
     type(xmlf_t), intent(inout) :: xf
74 75
     character(len=*), intent(in), optional :: id
75 76
     character(len=*), intent(in), optional :: title
@@ -77,6 +78,7 @@ subroutine cmlStartCml(xf, id, title, convention, dictref, fileId, version)
77 78
     character(len=*), intent(in), optional :: dictref
78 79
     character(len=*), intent(in), optional :: fileId
79 80
     character(len=*), intent(in), optional :: version
  81
+    logical, intent(in), optional          :: compchem
80 82
 
81 83
 #ifndef DUMMYLIB
82 84
     call xml_DeclareNamespace(xf, 'http://www.xml-cml.org/schema')
@@ -87,6 +89,13 @@ subroutine cmlStartCml(xf, id, title, convention, dictref, fileId, version)
87 89
     call xml_DeclareNamespace(xf, 'http://www.xml-cml.org/units/units', 'cmlUnits')
88 90
     call xml_DeclareNamespace(xf, 'http://www.xml-cml.org/units/siUnits', 'siUnits')
89 91
     call xml_DeclareNamespace(xf, 'http://www.xml-cml.org/units/atomic', 'atomicUnits')
  92
+    if (present(compchem)) then
  93
+      if (compchem) then
  94
+        call xmlf_SetExtendedData(xf, 20)
  95
+        call xml_DeclareNamespace(xf, 'http://www.xml-cml.org/convention/', 'convention')
  96
+        call xml_DeclareNamespace(xf, 'http://www.xml-cml.org/dictionary/compchem/', 'compchem')
  97
+      endif
  98
+    endif
90 99
 ! FIXME TOHW we may want other namespaces in here - particularly for units
91 100
 ! once PMR has stabilized that.
92 101
 
@@ -96,6 +105,8 @@ subroutine cmlStartCml(xf, id, title, convention, dictref, fileId, version)
96 105
     if (present(dictref)) call xml_AddAttribute(xf, 'dictRef', dictref)
97 106
     if (present(convention)) then
98 107
       call xml_AddAttribute(xf, 'convention', convention)
  108
+    elseif (xmlf_GetExtendedData(xf).eq.20) then
  109
+      call xml_AddAttribute(xf, 'convention', 'convention:compchem')
99 110
     else
100 111
       call xml_AddAttribute(xf, 'convention', 'CMLComp')
101 112
     endif
@@ -108,7 +119,11 @@ subroutine cmlStartCml(xf, id, title, convention, dictref, fileId, version)
108 119
       call xml_AddAttribute(xf, 'version', version)
109 120
     endif
110 121
 
111  
-    call cmlAddMetadata(xf, name='UUID', content=generate_uuid(1))
  122
+    if (xmlf_GetExtendedData(xf).eq.20) then
  123
+      call cmlAddMetadata(xf, name='compchem:UUID', content=generate_uuid(1))
  124
+    else
  125
+      call cmlAddMetadata(xf, name='UUID', content=generate_uuid(1))
  126
+    endif
112 127
 #endif
113 128
 
114 129
   end subroutine cmlStartCml
13  wcml/test/test_cmlStartCml_4.f90
... ...
@@ -0,0 +1,13 @@
  1
+program test
  2
+
  3
+  use FoX_wcml
  4
+  implicit none
  5
+
  6
+  character(len=*), parameter :: filename = 'test.xml'
  7
+  type(xmlf_t) :: xf
  8
+
  9
+  call cmlBeginFile(xf, filename, unit=-1)
  10
+  call cmlStartCml(xf, compchem=.true.)
  11
+  call cmlFinishFile(xf)
  12
+
  13
+end program test
3  wcml/test/test_cmlStartCml_4.xml
... ...
@@ -0,0 +1,3 @@
  1
+<?xml version="1.0" encoding="UTF-8"?>
  2
+<cml convention="convention:compchem" fileId="test.xml" xmlns="http://www.xml-cml.org/schema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:fpx="http://www.uszla.me.uk/fpx" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:units="http://www.uszla.me.uk/FoX/units" xmlns:cmlUnits="http://www.xml-cml.org/units/units" xmlns:siUnits="http://www.xml-cml.org/units/siUnits" xmlns:atomicUnits="http://www.xml-cml.org/units/atomic" xmlns:convention="http://www.xml-cml.org/convention/" xmlns:compchem="http://www.xml-cml.org/dictionary/compchem/">
  3
+</cml>
2  wxml/FoX_wxml.f90
@@ -36,6 +36,8 @@ module FoX_wxml
36 36
 
37 37
   public :: xmlf_GetPretty_print
38 38
   public :: xmlf_SetPretty_print
  39
+  public :: xmlf_GetExtendedData
  40
+  public :: xmlf_SetExtendedData
39 41
 
40 42
   public :: xmlf_Name
41 43
   public :: xmlf_OpenTag
29  wxml/m_wxml_core.F90
@@ -87,6 +87,9 @@ module m_wxml_core
87 87
     integer                   :: state_1 = -1
88 88
     integer                   :: state_2 = -1
89 89
     integer                   :: state_3 = -1
  90
+    ! Holder for extra information for other writers. See
  91
+    ! table with getter and setter below:
  92
+    integer                   :: extended_data = 0
90 93
     logical                   :: minimize_overrun = .true.
91 94
     logical                   :: pretty_print = .false.
92 95
     logical                   :: canonical = .false.
@@ -128,6 +131,8 @@ module m_wxml_core
128 131
 
129 132
   public :: xmlf_SetPretty_print
130 133
   public :: xmlf_GetPretty_print
  134
+  public :: xmlf_SetExtendedData
  135
+  public :: xmlf_GetExtendedData
131 136
 
132 137
   interface xml_AddCharacters
133 138
     module procedure xml_AddCharacters_Ch
@@ -1653,6 +1658,30 @@ pure function xmlf_GetPretty_print(xf) result(value)
1653 1658
 #endif
1654 1659
   end function xmlf_GetPretty_print
1655 1660
 
  1661
+! xf%extended data is an integer so that writers
  1662
+! can change there behaviour depending on some 
  1663
+! stored information. Currently only used for 
  1664
+! wcml 'validate' argument (which is intended to 
  1665
+! check some of the more troublesome aspects of
  1666
+! the CML schema
  1667
+  subroutine xmlf_SetExtendedData(xf, new_value)
  1668
+    type(xmlf_t), intent(inout) :: xf
  1669
+    integer, intent(in)         :: new_value
  1670
+#ifndef DUMMYLIB
  1671
+    xf%extended_data = new_value
  1672
+#endif
  1673
+  end subroutine xmlf_SetExtendedData
  1674
+
  1675
+  pure function xmlf_GetExtendedData(xf) result(value)
  1676
+    integer :: value
  1677
+    type(xmlf_t), intent(in) :: xf
  1678
+#ifdef DUMMYLIB
  1679
+    value = .false.
  1680
+#else
  1681
+    value = xf%extended_data
  1682
+#endif
  1683
+  end function xmlf_GetExtendedData
  1684
+
1656 1685
   pure function xmlf_name(xf) result(fn)
1657 1686
     type (xmlf_t), intent(in) :: xf
1658 1687
 #ifdef DUMMYLIB

0 notes on commit d9bb999

Please sign in to comment.
Something went wrong with that request. Please try again.