Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

143 lines (111 sloc) 4.581 kb
module m_wcml_core
use FoX_wxml, only: xmlf_t
#ifndef DUMMYLIB
use m_common_error, only: FoX_error
use FoX_common, only: FoX_version
use FoX_utils, only: generate_uuid
use FoX_wxml, only: xml_OpenFile, xml_Close
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
implicit none
public :: cmlBeginFile
public :: cmlFinishFile
public :: cmlAddNamespace
public :: cmlStartCml
public :: cmlEndCml
subroutine cmlBeginFile(xf, filename, unit, replace)
type(xmlf_t), intent(out) :: xf
character(len=*), intent(in) :: filename
integer, intent(in) :: unit
logical, intent(in), optional :: replace
#ifndef DUMMYLIB
if (unit==-1) then
call xml_OpenFile(filename, xf, preserve_whitespace=.false., replace=replace)
call xml_OpenFile(filename, xf, preserve_whitespace=.false., unit=unit, replace=replace)
end subroutine cmlBeginFile
subroutine cmlFinishFile(xf)
type(xmlf_t), intent(inout) :: xf
#ifndef DUMMYLIB
call xml_Close(xf)
end subroutine cmlFinishFile
subroutine cmlAddNamespace(xf, prefix, URI)
type(xmlf_t), intent(inout) :: xf
character(len=*), intent(in) :: prefix
character(len=*), intent(in) :: URI
#ifndef DUMMYLIB
if (xmlf_OpenTag(xf) /= "") &
call FoX_error("Cannot do cmlAddNamespace after starting CML output")
call xml_DeclareNamespace(xf, URI, prefix)
end subroutine cmlAddNamespace
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, '')
call xml_DeclareNamespace(xf, '', 'xsd')
call xml_DeclareNamespace(xf, '', 'fpx')
call xml_DeclareNamespace(xf, '', 'dc')
call xml_DeclareNamespace(xf, '', 'units')
call xml_DeclareNamespace(xf, '', 'cmlUnits')
call xml_DeclareNamespace(xf, '', 'siUnits')
call xml_DeclareNamespace(xf, '', 'atomicUnits')
if (present(compchem)) then
if (compchem) then
call xmlf_SetExtendedData(xf, 20)
call xml_DeclareNamespace(xf, '', 'convention')
call xml_DeclareNamespace(xf, '', 'compchem')
! FIXME TOHW we may want other namespaces in here - particularly for units
! once PMR has stabilized that.
call xml_NewElement(xf, 'cml')
if (present(id)) call xml_AddAttribute(xf, 'id', id)
if (present(title)) call xml_AddAttribute(xf, 'title', title)
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')
call xml_AddAttribute(xf, 'convention', 'CMLComp')
if (present(fileId)) then
call xml_AddAttribute(xf, 'fileId', fileId)
call xml_AddAttribute(xf, 'fileId', xmlf_Name(xf))
if (present(version)) then
call xml_AddAttribute(xf, 'version', version)
if (xmlf_GetExtendedData(xf).eq.20) then
call cmlAddMetadata(xf, name='compchem:UUID', content=generate_uuid(1))
call cmlAddMetadata(xf, name='UUID', content=generate_uuid(1))
end subroutine cmlStartCml
subroutine cmlEndCml(xf)
type(xmlf_t), intent(inout) :: xf
#ifndef DUMMYLIB
call cmlAddMetadata(xf, name='dc:contributor', content='FoX-'//FoX_version//' (')
call xml_EndElement(xf, 'cml')
end subroutine cmlEndCml
end module m_wcml_core
Jump to Line
Something went wrong with that request. Please try again.