Permalink
Browse files

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...
1 parent 6ae5a66 commit d9bb999a7cb34544dea0d44b0656df52f1cc264d @andreww committed Apr 24, 2012
Showing with 66 additions and 3 deletions.
  1. +2 −1 DoX/FoX_wcml.md
  2. +17 −2 wcml/m_wcml_core.F90
  3. +13 −0 wcml/test/test_cmlStartCml_4.f90
  4. +3 −0 wcml/test/test_cmlStartCml_4.xml
  5. +2 −0 wxml/FoX_wxml.f90
  6. +29 −0 wxml/m_wxml_core.F90
View
@@ -175,7 +175,8 @@ and then output all our properties and parameters with `dictRef="siesta:somethin
* `cmlStartCml`
(**fileId**) *string* *scalar*: name of originating file. (default: current filename)
-(**version**) *string* *scalar*: version of CML in use. (default: 2.4)
+(**version**) *string* *scalar*: version of CML in use. (default: 2.4)
+(**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)
* `cmlEndCml`
View
@@ -11,6 +11,7 @@ module m_wcml_core
use FoX_wxml, only: xml_NewElement, xml_AddAttribute
use FoX_wxml, only: xml_EndElement, xml_DeclareNamespace
use FoX_wxml, only: xmlf_Name, xmlf_OpenTag
+ use FoX_wxml, only: xmlf_GetExtendedData, xmlf_SetExtendedData
use m_wcml_metadata, only: cmlAddMetadata
#endif
@@ -69,14 +70,15 @@ subroutine cmlAddNamespace(xf, prefix, URI)
end subroutine cmlAddNamespace
- subroutine cmlStartCml(xf, id, title, convention, dictref, fileId, version)
+ subroutine cmlStartCml(xf, id, title, convention, dictref, fileId, version, compchem)
type(xmlf_t), intent(inout) :: xf
character(len=*), intent(in), optional :: id
character(len=*), intent(in), optional :: title
character(len=*), intent(in), optional :: convention
character(len=*), intent(in), optional :: dictref
character(len=*), intent(in), optional :: fileId
character(len=*), intent(in), optional :: version
+ logical, intent(in), optional :: compchem
#ifndef DUMMYLIB
call xml_DeclareNamespace(xf, 'http://www.xml-cml.org/schema')
@@ -87,6 +89,13 @@ subroutine cmlStartCml(xf, id, title, convention, dictref, fileId, version)
call xml_DeclareNamespace(xf, 'http://www.xml-cml.org/units/units', 'cmlUnits')
call xml_DeclareNamespace(xf, 'http://www.xml-cml.org/units/siUnits', 'siUnits')
call xml_DeclareNamespace(xf, 'http://www.xml-cml.org/units/atomic', 'atomicUnits')
+ if (present(compchem)) then
+ if (compchem) then
+ call xmlf_SetExtendedData(xf, 20)
+ call xml_DeclareNamespace(xf, 'http://www.xml-cml.org/convention/', 'convention')
+ call xml_DeclareNamespace(xf, 'http://www.xml-cml.org/dictionary/compchem/', 'compchem')
+ endif
+ endif
! FIXME TOHW we may want other namespaces in here - particularly for units
! once PMR has stabilized that.
@@ -96,6 +105,8 @@ subroutine cmlStartCml(xf, id, title, convention, dictref, fileId, version)
if (present(dictref)) call xml_AddAttribute(xf, 'dictRef', dictref)
if (present(convention)) then
call xml_AddAttribute(xf, 'convention', convention)
+ elseif (xmlf_GetExtendedData(xf).eq.20) then
+ call xml_AddAttribute(xf, 'convention', 'convention:compchem')
else
call xml_AddAttribute(xf, 'convention', 'CMLComp')
endif
@@ -108,7 +119,11 @@ subroutine cmlStartCml(xf, id, title, convention, dictref, fileId, version)
call xml_AddAttribute(xf, 'version', version)
endif
- call cmlAddMetadata(xf, name='UUID', content=generate_uuid(1))
+ if (xmlf_GetExtendedData(xf).eq.20) then
+ call cmlAddMetadata(xf, name='compchem:UUID', content=generate_uuid(1))
+ else
+ call cmlAddMetadata(xf, name='UUID', content=generate_uuid(1))
+ endif
#endif
end subroutine cmlStartCml
@@ -0,0 +1,13 @@
+program test
+
+ use FoX_wcml
+ implicit none
+
+ character(len=*), parameter :: filename = 'test.xml'
+ type(xmlf_t) :: xf
+
+ call cmlBeginFile(xf, filename, unit=-1)
+ call cmlStartCml(xf, compchem=.true.)
+ call cmlFinishFile(xf)
+
+end program test
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/">
+</cml>
View
@@ -36,6 +36,8 @@ module FoX_wxml
public :: xmlf_GetPretty_print
public :: xmlf_SetPretty_print
+ public :: xmlf_GetExtendedData
+ public :: xmlf_SetExtendedData
public :: xmlf_Name
public :: xmlf_OpenTag
View
@@ -87,6 +87,9 @@ module m_wxml_core
integer :: state_1 = -1
integer :: state_2 = -1
integer :: state_3 = -1
+ ! Holder for extra information for other writers. See
+ ! table with getter and setter below:
+ integer :: extended_data = 0
logical :: minimize_overrun = .true.
logical :: pretty_print = .false.
logical :: canonical = .false.
@@ -128,6 +131,8 @@ module m_wxml_core
public :: xmlf_SetPretty_print
public :: xmlf_GetPretty_print
+ public :: xmlf_SetExtendedData
+ public :: xmlf_GetExtendedData
interface xml_AddCharacters
module procedure xml_AddCharacters_Ch
@@ -1653,6 +1658,30 @@ pure function xmlf_GetPretty_print(xf) result(value)
#endif
end function xmlf_GetPretty_print
+! xf%extended data is an integer so that writers
+! can change there behaviour depending on some
+! stored information. Currently only used for
+! wcml 'validate' argument (which is intended to
+! check some of the more troublesome aspects of
+! the CML schema
+ subroutine xmlf_SetExtendedData(xf, new_value)
+ type(xmlf_t), intent(inout) :: xf
+ integer, intent(in) :: new_value
+#ifndef DUMMYLIB
+ xf%extended_data = new_value
+#endif
+ end subroutine xmlf_SetExtendedData
+
+ pure function xmlf_GetExtendedData(xf) result(value)
+ integer :: value
+ type(xmlf_t), intent(in) :: xf
+#ifdef DUMMYLIB
+ value = .false.
+#else
+ value = xf%extended_data
+#endif
+ end function xmlf_GetExtendedData
+
pure function xmlf_name(xf) result(fn)
type (xmlf_t), intent(in) :: xf
#ifdef DUMMYLIB

0 comments on commit d9bb999

Please sign in to comment.