[ismrmrd] 73/281: working on matlab interface, xmlheader class

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:00:58 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag ismrmrd0.5
in repository ismrmrd.

commit c85a564caa78e45fbd461c0cd9cfdcf207c2fd93
Author: Souheil Inati <souheil.inati at nih.gov>
Date:   Fri Jan 18 21:57:00 2013 -0500

    working on matlab interface, xmlheader class
---
 matlab/+ismrmrd/XMLHeader.m      | 37 ++++++++++++++++++++++++
 matlab/+ismrmrd/file.m           | 21 ++++++++++++--
 matlab/+ismrmrd/headerToString.m | 15 ----------
 matlab/+ismrmrd/stringToHeader.m | 12 --------
 matlab/README.txt                | 61 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 117 insertions(+), 29 deletions(-)

diff --git a/matlab/+ismrmrd/XMLHeader.m b/matlab/+ismrmrd/XMLHeader.m
new file mode 100644
index 0000000..9d064f7
--- /dev/null
+++ b/matlab/+ismrmrd/XMLHeader.m
@@ -0,0 +1,37 @@
+% XMLHeader
+classdef XMLHeader
+
+    properties
+        factory = []
+    end
+
+    methods
+
+        function obj = XMLHeader()
+            obj.factory = org.ismrm.ismrmrd.xmlhdr.ObjectFactory(); 
+        end
+
+        function hdr = fromString(obj,xmlstring)
+            import javax.xml.bind.*
+            jc = JAXBContext.newInstance('org.ismrm.ismrmrd.xmlhdr', obj.factory.getClass().getClassLoader());
+            u  = jc.createUnmarshaller();
+            jstr = java.lang.String(xmlstring);
+            hdr = u.unmarshal(java.io.ByteArrayInputStream(jstr.getBytes()));
+
+        end
+
+        function xmlstring = toString(obj)
+            import javax.xml.bind.*
+            jc = JAXBContext.newInstance('org.ismrm.ismrmrd.xmlhdr', obj.factory.getClass().getClassLoader());
+            m  = jc.createMarshaller();
+            m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, 'http://www.ismrm.org/ISMRMD ismrmrd.xsd');
+
+            strbuff = java.io.StringWriter();
+            m.marshal(hdr, strbuff);
+            xmlstring = strbuff.toString();
+
+        end
+
+    end
+
+end
diff --git a/matlab/+ismrmrd/file.m b/matlab/+ismrmrd/file.m
index 79d42ef..ff71db1 100644
--- a/matlab/+ismrmrd/file.m
+++ b/matlab/+ismrmrd/file.m
@@ -1,4 +1,4 @@
-% Acquisition
+% File
 classdef file
 
     properties
@@ -6,6 +6,7 @@ classdef file
         filename = '';
         datapath = '';
         xmlpath = '';
+        xmlhdr = [];
     end
     
     methods
@@ -22,6 +23,9 @@ classdef file
                 H5P.close(fcpl);
             end
             
+            % Set the filename
+            obj.filename = filename;
+            
             % Set the group name
             %   default is dataset
             if nargin == 1
@@ -33,17 +37,27 @@ classdef file
             obj.datapath  = ['/' groupname '/data'];
             
             % Check if the group exists
-            %   if it does not exist, create it
             lapl_id=H5P.create('H5P_LINK_ACCESS');
             if (H5L.exists(obj.fid,grouppath,lapl_id) == 0)
+                % group does not exist, create it and set a default header
                 group_id = H5G.create(obj.fid, grouppath, 0);
                 H5G.close(group_id);
+                % create a default xml header object
+                obj.xmlhdr = ismrmrd.XMLHeader();
+            else
+                % group exists, read the xml header
+                % and create a new convert it to an xml header object
+                obj.xmlhdr = ismrmrd.XMLHeader().stringToHeader(obj.readxml());
             end
             H5P.close(lapl_id);
         
         end
         
         function obj = close(obj)
+            % synchronize the xml header
+            xmlstring = ismrmrd.XMLHeader.headerToString(obj.xmlhdr);
+            obj.writexml(xmlstring);
+            % close the file
             H5F.close(obj.fid);
         end
         
@@ -82,6 +96,9 @@ classdef file
             % No validation is performed.  You're on your own.
             
             % TODO: add error checking on the write and return a status
+            % TODO: if the matlab variable length string bug is resolved
+            % then we should change this logic to just modify the length
+            % and overwrite.
             
             % Check if the XML header exists
             %   if it does not exist, create it
diff --git a/matlab/+ismrmrd/headerToString.m b/matlab/+ismrmrd/headerToString.m
deleted file mode 100644
index 93453bd..0000000
--- a/matlab/+ismrmrd/headerToString.m
+++ /dev/null
@@ -1,15 +0,0 @@
-function xmlstring = headerToString(hdr)
-
-    jpath = fileparts(mfilename('fullpath'));
-    javaaddpath({fullfile(jpath,'ismrmrdxml.jar')});
-    import javax.xml.bind.*
-
-    jc = JAXBContext.newInstance('ismrmrdxml', hdr.getClass().getClassLoader());
-    m  = jc.createMarshaller();
-    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, 'http://www.ismrm.org/ISMRMD ismrmrd.xsd');
-
-    strbuff = java.io.StringWriter();
-    m.marshal(hdr, strbuff);
-    xmlstring = strbuff.toString();
-
-end
diff --git a/matlab/+ismrmrd/stringToHeader.m b/matlab/+ismrmrd/stringToHeader.m
deleted file mode 100644
index 6d4d791..0000000
--- a/matlab/+ismrmrd/stringToHeader.m
+++ /dev/null
@@ -1,12 +0,0 @@
-function hdr = stringToHeader(xmlstring)
-
-    jpath = fileparts(mfilename('fullpath'));
-    javaaddpath({fullfile(jpath,'ismrmrdxml.jar')});
-    import javax.xml.bind.*
-    of = ismrmrdxml.ObjectFactory();
-    jc = JAXBContext.newInstance('ismrmrdxml', of.getClass().getClassLoader());
-    u  = jc.createUnmarshaller();
-    jstr = java.lang.String(xmlstring);
-    hdr = u.unmarshal(java.io.ByteArrayInputStream(jstr.getBytes()));
-    
-end
diff --git a/matlab/README.txt b/matlab/README.txt
new file mode 100644
index 0000000..e664a18
--- /dev/null
+++ b/matlab/README.txt
@@ -0,0 +1,61 @@
+The ISMRMRD Matlab Interface
+============================
+
+XML Header Interface
+--------------------
+The two methods, readxml and writexml, read and write a XML header
+from an ISMRMRD dataset: readxml returns a string writexml takes a
+string as input This provides the user with the flexibility to use
+whatever tools they prefer to create or modify the XML header string.
+
+Unfortunately, working with XML directly can be difficult and is
+error-prone, therefore, the ISMRMRD Matlab interface class provides a
+JAVA class for a convient way to interact with the XML header.  This
+class is automatically generated from the XML schema describing the
+XML header and is therefore guaranteed to be valid.  The examples
+provided use this feature to manipulate the XML header.  If you want
+to use this feature, then you must have a version that is compiled for
+the version of JAVA that your Matlab installation is using.
+
+Installation
+------------
+The matlab interface consists of a package in a directory called
+"+ismrmrd". Warning, the name and the plus sign are important.
+Put the +ismrmrd folder somewhere, for example in
+/home/jane/ismrmrd/matlab, then add that somewhere to your matlab
+search path.
+
+Installing with the Pre-Compiled XML Header Bindings
+---------------------------------------------------- 
+The compiled XML header JAVA class bundle must be installed and the
+Matlab JAVA classpath.  Copy the compiled java class bundle
+(xmlhdr.jar) somewhere on your system, for example into the folder
+/home/jane/ismrmrd/matlab/+ismrmrd.  The specific location doesn't
+matter, but it's important to keep things tidy.  Then modify your
+static java classpath.  For example, if you are running R2012b on
+linux, create (or edit) the file ~/.matlab/R2012b/javaclasspath.txt
+and add the following line:
+  /home/jane/ismrmrd/matlab/+ismrmrd/xmlhdr.jar 
+Note that you must restart Matlab for the changes to take
+effect. Please refer to the Matlab documentation for more information
+on the java class path.
+
+Compiling the JAVA bindings to the XML Header
+--------------------------------------------- 
+Assuming the ismrmrd library was installed in ${ISMRMRD_HOME}, the JAVA interface to the XML header can be created from the XML schema using the JAXB bindings in the following way: 
+  cd ${ISMRMRD_HOME}/matlab/+ismrmrd
+  xjc -p org.ismrm.ismrmrd.xmlhdr ${ISMRMRD_HOME}/schema/ismrmrd.xsd
+  javac org/ismrm/ismrmrd/xmlhdr/*.java
+  jar -cvf xmlhdr.jar org/ismrm/ismrmrd/xmlhdr/*.class 
+  rm -rf org
+
+
+Modify your Matlab java classpath as described in previous
+section. You will need to make sure that you are using the same
+version of the java compiler as the jre that matlab is using.  A
+description of how Matlab works with the JAVA runtime (JRE) is beyond
+the scope of this document.  Please refer to the matlab documentation
+for details. Two good starting points are:
+  http://www.mathworks.com/help/matlab/ref/version.html
+  http://www.mathworks.com/support/solutions/en/data/1-1812J/
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/ismrmrd.git



More information about the debian-science-commits mailing list