Index: src/dicomdict.cpp
===================================================================
--- src/dicomdict.cpp	(revision 8784)
+++ src/dicomdict.cpp	(working copy)
@@ -5,6 +5,9 @@
  *
  * Many thanks to Judd Storrs, who wrote most of the code in this
  * file. Anything ugly or wrong, I added later. Andy
+ *
+ * Minor changes Copyright Kris Thielemans 2011:
+ *  make dicomdict('get') and dicomdict('set',filename) work properly and add doc-string
  * 
  * The GNU Octave dicom package is free software: you can redistribute 
  * it and/or modify it under the terms of the GNU General Public 
@@ -24,9 +27,9 @@
 #include "octave/oct.h"
 #include "load-path.h"
 
-#include "gdcmDict.h"
-#include "gdcmVR.h"
-#include "gdcmVM.h"
+#include "gdcm-2.0/gdcmDict.h"
+#include "gdcm-2.0/gdcmVR.h"
+#include "gdcm-2.0/gdcmVM.h"
 
 #include "dicomdict.h"
 
@@ -35,6 +38,7 @@
 #define QUOTED(x) QUOTED_(x)
 
 const char * factory_dicom_dict_filename="octavedicom.dic";
+static std::string dic_filename(factory_dicom_dict_filename);
 
 std::map<gdcm::Tag, std::string> tagmap ;
 std::map<std::string, gdcm::Tag> keymap ;
@@ -46,13 +50,20 @@
 	dict[k] = e ;
 }
 
-void load_dict(const char *filename);
 
 DEFUN_DLD (OCT_FN_NAME, args, nargout,
-"TODO: write help\n\
-Finds dictionary files anywhere in the path.\n") {
+		"-*- texinfo -*- \n\
+@deftypefn {Loadable Function} {@var{dictionary_name} =} "QUOTED(OCT_FN_NAME)" (@code{get}) \n\
+@deftypefnx {Loadable Function} {} "QUOTED(OCT_FN_NAME)" (@code{factory}) \n\
+@deftypefnx {Loadable Function} {} "QUOTED(OCT_FN_NAME)" (@code{set}, @var{dictionary_name}) \n\
+The first usage returns the filename of the dictionary that is currently being used.\n\
+Using @code{factory} resets the dictionary to the default.\n\
+Using @code{set} allows setting the dictionary for future operations.\n\
+In this case, the dictionary file @var{dictionary_name} can be anywhere in the path.\n\
+\n\
+@seealso{dicomread, dicomwrite}\n\
+@end deftypefn \n") {
 	octave_value_list retval;  // create object to store return values
-	static std::string dic_filename(factory_dicom_dict_filename);
 	if (args.length()>2 || args.length()<1) {
 		error(QUOTED(OCT_FN_NAME)": takes 1 or 2 arguments, got %i.",args.length ());
 		return retval; 
@@ -77,7 +88,7 @@
 			
 			return retval;
 		} else {
-			error(QUOTED(OCT_FN_NAME)": single arg must either be 'set' or 'factory'.",args.length ());
+			error(QUOTED(OCT_FN_NAME)": single arg must either be 'get' or 'factory'.",args.length ());
 			return retval; 
 		}
 	}
@@ -92,6 +103,7 @@
 		error(QUOTED(OCT_FN_NAME)": when 2 args are given, the first must be 'set'.",args.length ());
 		return retval; 
 	}
+	load_dict(arg1str.c_str());
 	//if (octave_dicom_dict == NULL) octave_dicom_dict = new OctaveDicomDict(); //TODO where should this be freed?
 	//octave_dicom_dict.load_file(arg1str.c_str()); // second arg is filename
 	return retval;
@@ -231,6 +243,9 @@
   }
 };
 
+const char * const get_current_dict() {
+  return dic_filename.c_str();
+}
 
 void load_dict(const char * filename) {
 	// reset, if required
@@ -239,7 +254,7 @@
 		keymap.clear() ;
 		dict.clear() ;
 	}
-	
+
 	// find dic if it is anywhere in the search path (same path as for m-files etc)
 	std::string resolved_filename=load_path::find_file(std::string(filename)) ;
 
@@ -305,6 +320,8 @@
 			} while ( ++elem ) ;
 		} while ( ++group ) ;
 	}
+	// save filename
+	dic_filename = resolved_filename;
 }
 
 void lookup_keyword(std::string & keyword, const gdcm::Tag & tag) {
Index: src/dicomdict.h
===================================================================
--- src/dicomdict.h	(revision 8784)
+++ src/dicomdict.h	(working copy)
@@ -17,6 +17,8 @@
  * Public License version 3.
  * 
  */
+void load_dict(const char *filename);
+const char * const get_current_dict();
 
 void lookup_keyword(std::string & keyword, const gdcm::Tag & tag);
 void lookup_tag(gdcm::Tag & tag, const std::string & keyword);
Index: src/dicomlookup.cpp
===================================================================
--- src/dicomlookup.cpp	(revision 8784)
+++ src/dicomlookup.cpp	(working copy)
@@ -20,9 +20,9 @@
 
 #include "octave/oct.h"
 
-#include "gdcmDict.h"
-#include "gdcmVR.h"
-#include "gdcmVM.h"
+#include "gdcm-2.0/gdcmDict.h"
+#include "gdcm-2.0/gdcmVR.h"
+#include "gdcm-2.0/gdcmVM.h"
 
 #include "dicomdict.h"
 
@@ -71,4 +71,4 @@
 	}
 	error(QUOTED(OCT_FN_NAME_LU)": takes 1 or 2 arguments, got %i. see help",args.length ());
 	return retval;
-}
\ No newline at end of file
+}
Index: src/dicomwrite.cpp
===================================================================
--- src/dicomwrite.cpp	(revision 8784)
+++ src/dicomwrite.cpp	(working copy)
@@ -21,11 +21,11 @@
 #include "octave/oct.h"
 #include "octave/ov-struct.h"
 
-#include "gdcmDictEntry.h"
-#include "gdcmImage.h"
-#include "gdcmImageWriter.h"
-#include "gdcmFileDerivation.h"
-#include "gdcmUIDGenerator.h"
+#include "gdcm-2.0/gdcmDictEntry.h"
+#include "gdcm-2.0/gdcmImage.h"
+#include "gdcm-2.0/gdcmImageWriter.h"
+#include "gdcm-2.0/gdcmFileDerivation.h"
+#include "gdcm-2.0/gdcmUIDGenerator.h"
               
 #include "dicomdict.h"
               
@@ -388,4 +388,4 @@
 	w->SetFile( fd.GetFile() );
 
 	return ;
-}
\ No newline at end of file
+}
Index: src/dicominfo.cpp
===================================================================
--- src/dicominfo.cpp	(revision 8784)
+++ src/dicominfo.cpp	(working copy)
@@ -3,12 +3,22 @@
  * Contact: blondandy using the sf.net system, 
  * <https://sourceforge.net/sendmessage.php?touser=1760416>
  * 
+ * Changes Copyright Kris Thielemans 2011:
+ * - support usage dicominfo(filename, 'dictionary', dictname)
+ * - support FL, FD and SL VRs, which means that many more fields are now read correctly from the dicom file.
+ * - check if the VR in the file is the same as the one in the dictionary. If not, issue a warning but use the VR from the file.
+ * - assign values to private dicom fields, just like with others
+ * - changed convention for private fields to use lower-case for the hexadecimal numbers to be compatible with Matlab
+ * - if an entry is not in the dictionary, determine its VR from the file (if possible) and assign anyway.
+ * - updated doc-string
+ *
+ *
  * The GNU Octave dicom package is free software: you can redistribute 
  * it and/or modify it under the terms of the GNU General Public 
  * License as published by the Free Software Foundation, either 
  * version 3 of the License, or (at your option) any later version.
  * 
- * The GNU Octave dicom packag is distributed in the hope that it 
+ * The GNU Octave dicom package is distributed in the hope that it 
  * will be useful, but WITHOUT ANY WARRANTY; without even the 
  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
  * PURPOSE.  See the GNU General Public License for more details.
@@ -32,18 +42,18 @@
 #include "octave/oct.h"
 #include "octave/ov-struct.h"
 
-#include "gdcmSystem.h"
-#include "gdcmReader.h"
-#include "gdcmWriter.h"
-#include "gdcmAttribute.h"
-#include "gdcmDataSet.h"
-#include "gdcmGlobal.h"
-#include "gdcmDicts.h"
-#include "gdcmDict.h"
-#include "gdcmCSAHeader.h"
-#include "gdcmPrivateTag.h"
-#include "gdcmVR.h"
-#include "gdcmSequenceOfItems.h"
+#include "gdcm-2.0/gdcmSystem.h"
+#include "gdcm-2.0/gdcmReader.h"
+#include "gdcm-2.0/gdcmWriter.h"
+#include "gdcm-2.0/gdcmAttribute.h"
+#include "gdcm-2.0/gdcmDataSet.h"
+#include "gdcm-2.0/gdcmGlobal.h"
+#include "gdcm-2.0/gdcmDicts.h"
+#include "gdcm-2.0/gdcmDict.h"
+#include "gdcm-2.0/gdcmCSAHeader.h"
+#include "gdcm-2.0/gdcmPrivateTag.h"
+#include "gdcm-2.0/gdcmVR.h"
+#include "gdcm-2.0/gdcmSequenceOfItems.h"
  
 #include "dicomdict.h" 
  
@@ -82,22 +92,26 @@
 #else
 DEFUN_DLD (OCT_FN_NAME, args, nargout,
 		"-*- texinfo -*- \n\
- @deftypefn  {Loadable Function} {} "QUOTED(OCT_FN_NAME)" (@var{filename}) \n\
- @deftypefnx {Loadable Function} {} @var{info} = "QUOTED(OCT_FN_NAME)" (@var{filename}) \n\
+ @deftypefn {Loadable Function} {@var{info}} = "QUOTED(OCT_FN_NAME)" (@var{filename}) \n\
+ @deftypefnx {Loadable Function} {@var{info}} = "QUOTED(OCT_FN_NAME)" (@var{filename}, @code{dictionary}, @var{dictionary-name}) \n\
+ @deftypefnx  {Loadable Function} {} "QUOTED(OCT_FN_NAME)" (@var{filename}, @var{options}) \n\
  @deftypefnx {Command} {} "QUOTED(OCT_FN_NAME)" @var{filename} \n\
- @deftypefnx {Command} {} "QUOTED(OCT_FN_NAME)" @var{filename} @var{option} \n\
+ @deftypefnx {Command} {} "QUOTED(OCT_FN_NAME)" @var{filename} @var{options} \n\
  Get all data from a DICOM file, excluding any actual image. \n\
  @var{info} is a nested struct containing the data. \n\
  \n\
  If no return argument is given, then there will be output similar to \n\
  a DICOM dump. \n\
  \n\
- @var{option}:\n\
- truncate=n\n\
- where n is the number of characters to limit the dump output display to \
+ If the @code{dictionary} argument is used, the given @var{dictionary-name} is used for this operation, \n\
+ otherwise, the dictionary set by @code{dicomdict} is used.\n\
+ \n\
+ @var{options}:\n\
+ @code{truncate=n}\n\
+ where n is the number of characters to limit the dump output display to @code{n}\
  for each value. \n\
 \n\
- @seealso{dicomread} \n\
+ @seealso{dicomread, dicomdict} \n\
  @end deftypefn \n\
 		") {
 	octave_value_list retval;  // create object to store return values
@@ -112,7 +126,13 @@
 		return retval; 
 	}
 	std::string filename = ch.row_as_string (0);
-	
+
+	std::string current_dict = get_current_dict();
+	// TODO the dictionary can be set by the code below
+	// we really need to catch any errors in this function
+	// and reset the dictionary to current_dict.
+	// Currently that's only done when no error occured.
+
 	int i; // parse any additional args
 	for (i=1; i<args.length(); i++) {
 		charMatrix chex = args(i).char_matrix_value();
@@ -121,7 +141,21 @@
 			return retval; 
 		}
 		std::string argex = chex.row_as_string (0);
-		if (!argex.compare(0,9,"truncate=")) {
+		if (!argex.compare("dictionary") || !argex.compare("Dictionary")) {
+		        if (i+1==args.length()) {
+			      error(QUOTED(OCT_FN_NAME)": Dictionary needs another argument");
+			      return retval;
+			}
+			if (!args(i+1).is_string()) {
+			      error(QUOTED(OCT_FN_NAME)": Dictionary needs a string argument");
+			      return retval;
+			}
+			std::string dictionary = args(i+1).string_value();
+			load_dict(dictionary.c_str());
+			// ignore dictionary argument for further arg processing
+			++i;
+		}
+		else if (!argex.compare(0,9,"truncate=")) {
 			dicom_truncate_numchar=atoi(argex.substr(9).c_str());
 		} else {
 			warning(QUOTED(OCT_FN_NAME)": arg not understood: %s", argex.c_str());
@@ -130,6 +164,8 @@
 	
 	Octave_map om=dump(filename.c_str(),chatty);
 	retval(0)=om;
+
+	load_dict(current_dict.c_str());
 	return retval;
 }
 #endif
@@ -197,18 +233,29 @@
 	// skip "Group Length" tags. note: these are deprecated in DICOM 2008
 	if(tag.GetElement() == (uint16_t)0 || elem->GetByteValue() == NULL) return DICOM_NOTHING_ASSIGNED;
 	//const gdcm::DictEntry dictEntry = dicts.GetDictEntry(tag,(const char*)0);
+
+	gdcm::VR vr = elem->GetVR(); // value representation. ie DICOM 
+
 	gdcm::DictEntry dictEntry ;
 	if (!is_present(tag)) {
 		char fallbackVarname[64];
-		snprintf(fallbackVarname,63,"Private_%04X_%04X",tag.GetGroup(),tag.GetElement());
+		snprintf(fallbackVarname,63,"Private_%04x_%04x",tag.GetGroup(),tag.GetElement());
 		varname=std::string(fallbackVarname);
+#if 0
 		*ov=std::string("");
 		warning(QUOTED(OCT_FN_NAME)": %s", fallbackVarname);
 		return DICOM_NOTHING_ASSIGNED; //TODO maybe could carry on, if we know the VR
+#endif
 	}
-	lookup_entry(dictEntry, tag);
-	const gdcm::VR vr= dictEntry.GetVR(); // value representation. ie DICOM type.
-	varname=dictEntry.GetName();
+	else {
+	        lookup_entry(dictEntry, tag);
+		varname=dictEntry.GetName();
+		const gdcm::VR dictvr= dictEntry.GetVR(); // value representation. ie DICOM 	
+		if (dictvr != vr) {
+		  warning(QUOTED(OCT_FN_NAME)": %s has different VR from dictionary. Using VR from file", varname.c_str());
+		}
+	}
+
 	
 	//int tagVarNameBufLen=127;
 	//char *keyword=(char *)malloc((tagVarNameBufLen+1)*sizeof(char));
@@ -271,6 +318,21 @@
 		memcpy(&usval, elem->GetByteValue()->GetPointer(), 2);
 		*ov=usval;
 		if(chatty) octave_stdout << '[' << usval << "]\n";
+	} else if (vr & gdcm::VR::FL) {// float
+		float val ; 
+		memcpy(&val, elem->GetByteValue()->GetPointer(), 4);
+		*ov=val;
+		if(chatty) octave_stdout << '[' << val << "]\n";
+	} else if (vr & gdcm::VR::FD) {// double
+		double val ; 
+		memcpy(&val, elem->GetByteValue()->GetPointer(), sizeof(val));
+		*ov=val;
+		if(chatty) octave_stdout << '[' << val << "]\n";
+	} else if (vr & gdcm::VR::SL) {// signed long
+		int32_t val ; 
+		memcpy(&val, elem->GetByteValue()->GetPointer(), 4);
+		*ov=val;
+		if(chatty) octave_stdout << '[' << val << "]\n";
 	} else if (vr & gdcm::VR::OB) {// other byte
 		if (tag==gdcm::Tag(0x7FE0,0x0010)) { // PixelData
 			if(chatty) octave_stdout  << "skipping, leave for dicomread\n";
Index: src/dicomread.cpp
===================================================================
--- src/dicomread.cpp	(revision 8784)
+++ src/dicomread.cpp	(working copy)
@@ -19,8 +19,8 @@
  */
 
 #include "octave/oct.h"
-
-#include "gdcmImageReader.h"
+#include <octave/ov-struct.h>
+#include "gdcm-2.0/gdcmImageReader.h"
               
 #define DICOM_ERR -1
 #define DICOM_OK 0
@@ -32,9 +32,13 @@
 DEFUN_DLD (OCT_FN_NAME, args, nargout,
 		"-*- texinfo -*- \n\
  @deftypefn {Loadable Function} {} @var{image} = "QUOTED(OCT_FN_NAME)" (@var{filename}) \n\
+ @deftypefnx {Loadable Function} {} @var{image} = "QUOTED(OCT_FN_NAME)" (@var{structure}) \n\
+ \n\
  Load the image from a DICOM file. \n\
+ @var{filename} is a string (giving the filename).\n\
+ @var{structure} is a structure with a field @code{Filename} (such as returned by @code{dicominfo}).\n\
  @var{image} may be two or three dimensional, depending on the content of the file. \n\
- An integer matrix will be returned, the number of bits will depend on the file. \n\
+ An integer or float matrix will be returned, the number of bits will depend on the file. \n\
 \n\
  @seealso{dicominfo} \n\
  @end deftypefn \n\
@@ -44,13 +48,28 @@
 		error(QUOTED(OCT_FN_NAME)": one arg required: dicom filename");
 		return retval; 
 	}
-	charMatrix ch = args(0).char_matrix_value ();
-	if (ch.rows()!=1) {
-		error(QUOTED(OCT_FN_NAME)": arg should be a filename, 1 row of chars");
+
+	std::string filename;
+	// argument processing
+	// check if 1st argument is a string or a struct with field Filename
+	// If so, assign to filename variable, otherwise exit.
+	if (args(0).is_string()) {
+	  filename = args(0).string_value();
+	}
+	else {
+	  octave_scalar_map arg0 = args(0).scalar_map_value ();
+          if (error_state) {
+	        error(QUOTED(OCT_FN_NAME)": arg should be a filename, 1 row of chars, or a struct returned by dicominfo");
 		return retval; 
+	  }
+	  if (!arg0.contains("Filename")) {
+	        error(QUOTED(OCT_FN_NAME)": if arg is a struct, it should have the Filename field");
+		return retval; 
+	  }
+	  octave_value tmp = arg0.getfield ("Filename");
+	  filename = tmp.string_value();
 	}
 		
-	std::string filename = ch.row_as_string(0);
 	
 #if 0 /* TODO support 'frames' stuff, see Matlab docs for dicomread */
 	int i; // parse any additional args
Index: src/_gendicomdict.cpp
===================================================================
--- src/_gendicomdict.cpp	(revision 8784)
+++ src/_gendicomdict.cpp	(working copy)
@@ -28,17 +28,17 @@
 
 #include "octave/oct.h"
 
-#include "gdcmSystem.h"
-#include "gdcmReader.h"
-#include "gdcmWriter.h"
-#include "gdcmAttribute.h"
-#include "gdcmDataSet.h"
-#include "gdcmGlobal.h"
-#include "gdcmDicts.h"
-#include "gdcmDict.h"
-#include "gdcmCSAHeader.h"
-#include "gdcmPrivateTag.h"
-#include "gdcmVR.h"
+#include "gdcm-2.0/gdcmSystem.h"
+#include "gdcm-2.0/gdcmReader.h"
+#include "gdcm-2.0/gdcmWriter.h"
+#include "gdcm-2.0/gdcmAttribute.h"
+#include "gdcm-2.0/gdcmDataSet.h"
+#include "gdcm-2.0/gdcmGlobal.h"
+#include "gdcm-2.0/gdcmDicts.h"
+#include "gdcm-2.0/gdcmDict.h"
+#include "gdcm-2.0/gdcmCSAHeader.h"
+#include "gdcm-2.0/gdcmPrivateTag.h"
+#include "gdcm-2.0/gdcmVR.h"
 
 #define OCT_FN_NAME _gendicomdict
 #define QUOTED_(x) #x
@@ -134,4 +134,4 @@
 	}
 	*tl = '\0';
 	return d;
-}
\ No newline at end of file
+}
Index: src/Makefile
===================================================================
--- src/Makefile	(revision 8784)
+++ src/Makefile	(working copy)
@@ -17,10 +17,10 @@
   
  
 
-INCDIRFLAGS =	-I/usr/local/include/gdcm-2.0/
+INCDIRFLAGS =	
 LIBDIRFLAGS =	-L/usr/local/lib
-GDCMLIBFLAGS =	-lgdcmcharls -lgdcmzlib -lgdcmjpeg8 -lgdcmjpeg12 \
--lgdcmjpeg16 -lgdcmexpat -lgdcmopenjpeg -lgdcmCommon \
+GDCMLIBFLAGS =	-lgdcmcharls  -lgdcmjpeg8 -lgdcmjpeg12 \
+-lgdcmjpeg16 -lgdcmCommon \
 -lgdcmDICT -lgdcmDSED -lgdcmIOD -lgdcmMSFF  
 DEBUGFLAG =	-g
 
@@ -60,4 +60,4 @@
 	mkoctfile -c $(INCDIRFLAGS) $(DEBUGFLAG) dicomlookup.cpp
 
 clean:
-	rm *.o *.oct *~
+	rm -f *.o *.oct *~
