Commit 95e1944a authored by Daniel Wortmann's avatar Daniel Wortmann

Added command line switch to modify inp.xml

For example one can now say
-xmlXPath /fleurInput/cell/bulkLattice/\@scale=1.01
to scale the systems lattice by 1%
parent f42c1ce3
...@@ -170,6 +170,32 @@ extern const unsigned char* getXMLAttributeValue(const unsigned char* xPathExpre ...@@ -170,6 +170,32 @@ extern const unsigned char* getXMLAttributeValue(const unsigned char* xPathExpre
} }
int setXMLAttributeValue(const unsigned char* xPathExpression,const unsigned char * value)
{
if (xPathCtxt == NULL)
{
fprintf(stderr, "Error: xPathCtxt is null in getAttributeValue(...)");
return 1;
}
xPathObj = xmlXPathEvalExpression(xPathExpression, xPathCtxt);
if (xPathObj == NULL)
{
fprintf(stderr, "Error: xPathObj is null in getAttributeValue(...)");
return 1;
}
xmlNodeSetPtr nodes = xPathObj->nodesetval;
if (nodes == NULL)
{
fprintf(stderr, "Error: nodes is null in getAttributeValue(...)");
return 1;
}
// return NULL;
xmlNodeSetContent(nodes->nodeTab[0],value);
return 0;
}
int freeXMLResources() int freeXMLResources()
{ {
xmlCleanupParser(); xmlCleanupParser();
......
...@@ -15,7 +15,34 @@ MODULE m_xmlIntWrapFort ...@@ -15,7 +15,34 @@ MODULE m_xmlIntWrapFort
USE m_juDFT USE m_juDFT
PRIVATE :: init_from_command_line
CONTAINS CONTAINS
SUBROUTINE init_from_command_line()
IMPLICIT NONE
CHARACTER(len=1000)::xpath
INTEGER:: i,ii
IF (judft_was_argument("-xmlXPath")) THEN
xpath=judft_string_for_argument("-xmlXPath")
DO WHILE(INDEX(xpath,"=")>0)
i=INDEX(xpath,"=")
ii=INDEX(xpath,":")
IF (ii==0) ii=LEN(TRIM(xpath))+1
IF (i>100.OR.ii-i>100) CALL judft_error("Too long xmlXPath argument",calledby="xmlIntWarpFort.f90")
CALL xmlSetAttributeValue(xpath(:i-1),xpath(i+1:ii-1))
WRITE(*,*) "Set from command line:",TRIM(xpath(:i-1)),"=",TRIM(xpath(i+1:ii-1))
IF (ii+1<len(xpath))THEN
xpath=xpath(ii+1:)
ELSE
xpath=""
ENDIF
END DO
END IF
END SUBROUTINE init_from_command_line
SUBROUTINE xmlInitInterface() SUBROUTINE xmlInitInterface()
USE iso_c_binding USE iso_c_binding
...@@ -139,7 +166,7 @@ SUBROUTINE xmlInitXPath() ...@@ -139,7 +166,7 @@ SUBROUTINE xmlInitXPath()
IF(errorStatus.NE.0) THEN IF(errorStatus.NE.0) THEN
CALL juDFT_error("Could not initialize XPath.",calledby="xmlInitXPath") CALL juDFT_error("Could not initialize XPath.",calledby="xmlInitXPath")
END IF END IF
CALL init_from_command_line()
END SUBROUTINE xmlInitXPath END SUBROUTINE xmlInitXPath
FUNCTION xmlGetNumberOfNodes(xPath) FUNCTION xmlGetNumberOfNodes(xPath)
...@@ -188,6 +215,8 @@ FUNCTION xmlGetAttributeValue(xPath) ...@@ -188,6 +215,8 @@ FUNCTION xmlGetAttributeValue(xPath)
end function getXMLAttributeValue end function getXMLAttributeValue
end interface end interface
c_string = getXMLAttributeValue(TRIM(ADJUSTL(xPath))//C_NULL_CHAR) c_string = getXMLAttributeValue(TRIM(ADJUSTL(xPath))//C_NULL_CHAR)
CALL C_F_POINTER(c_string, valueFromC, [ 255 ]) CALL C_F_POINTER(c_string, valueFromC, [ 255 ])
...@@ -209,6 +238,38 @@ FUNCTION xmlGetAttributeValue(xPath) ...@@ -209,6 +238,38 @@ FUNCTION xmlGetAttributeValue(xPath)
END FUNCTION xmlGetAttributeValue END FUNCTION xmlGetAttributeValue
SUBROUTINE xmlSetAttributeValue(xPath,VALUE)
USE iso_c_binding
USE m_types
IMPLICIT NONE
CHARACTER(LEN=*, KIND=c_char), INTENT(IN) :: xPath
CHARACTER(len=*, KIND=c_char), INTENT(IN) :: value
INTEGER :: errorStatus
INTERFACE
FUNCTION setXMLAttributeValue(xPathExpression,valueExpression) BIND(C, name="setXMLAttributeValue")
use iso_c_binding
CHARACTER(KIND=c_char) :: xPathExpression(*)
CHARACTER(KIND=c_char) :: valueExpression(*)
INTEGER(c_int) :: setXMLAttributeValue
END FUNCTION setXMLAttributeValue
END INTERFACE
errorStatus = setXMLAttributeValue(TRIM(ADJUSTL(xPath))//C_NULL_CHAR,TRIM(ADJUSTL(VALUE))//C_NULL_CHAR)
IF (errorStatus.ne.0) THEN
WRITE(*,*) 'Error in trying to setting attribute value from XPath:'
WRITE(*,*) TRIM(ADJUSTL(xPath))
WRITE(*,*) TRIM(ADJUSTL(VALUE))
CALL juDFT_error("Attribute value could not be set.",calledby="xmlSetAttributeValue")
END IF
END SUBROUTINE xmlSetAttributeValue
SUBROUTINE xmlFreeResources() SUBROUTINE xmlFreeResources()
USE iso_c_binding USE iso_c_binding
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment