[med-svn] [mricron] 03/05: Imported Upstream version 0.20140704.1~dfsg.1

Michael Hanke mih at moszumanska.debian.org
Fri Oct 3 09:09:48 UTC 2014


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

mih pushed a commit to branch master
in repository mricron.

commit 945448a1e3c775bd2c171bb46b57690156e948ac
Author: Michael Hanke <michael.hanke at gmail.com>
Date:   Thu Oct 2 13:55:11 2014 +0200

    Imported Upstream version 0.20140704.1~dfsg.1
---
 ReadInt.lfm                                        |   24 +-
 ReadInt.lrs                                        |   26 +-
 common/GraphicsMathLibrary.pas                     |    4 +-
 common/define_types.pas                            |   12 +-
 common/nifti_foreign.pas                           |   24 +-
 dcm2nii/PARtoNRRD_Philips_RelX.zip                 |  Bin 16690 -> 0 bytes
 dcm2nii/bvec.pas                                   |   79 +
 dcm2nii/convert.pas                                |  261 +-
 .../dcm2niigui.app}/Contents/Info.plist            |    6 +-
 dcm2nii/dcm2niigui.app/Contents/MacOS/dcm2niigui   |    1 +
 .../dcm2niigui.app}/Contents/PkgInfo               |    0
 dcm2nii/dcm2niigui.lpi                             |  592 +-
 dcm2nii/parconvert.pas                             |  105 +-
 dcm2nii/{philips_bvec.pas => philips_bvec_old.pas} |   28 +-
 dcm2nii/pref_form.dfm                              |  Bin 3630 -> 3848 bytes
 dcm2nii/pref_form.lfm                              |   52 +-
 dcm2nii/pref_form.lrs                              |   38 +-
 dcm2nii/pref_form.pas                              |   12 +-
 dcm2nii_prePARRECDTI/LibTar.pas                    |  914 ---
 dcm2nii_prePARRECDTI/PARtoNRRD_Philips_RelX.zip    |  Bin 16690 -> 0 bytes
 dcm2nii_prePARRECDTI/SelectFolder.pas              |   97 -
 dcm2nii_prePARRECDTI/convert.pas                   | 1734 ------
 dcm2nii_prePARRECDTI/convertsimple.pas             |  258 -
 dcm2nii_prePARRECDTI/csaread.pas                   |  247 -
 .../dcm2nii.app/Contents/MacOS/dcm2nii             |    1 -
 dcm2nii_prePARRECDTI/dcm2nii.cfg                   |   39 -
 dcm2nii_prePARRECDTI/dcm2nii.dof                   |  143 -
 dcm2nii_prePARRECDTI/dcm2nii.dpr                   |   33 -
 dcm2nii_prePARRECDTI/dcm2nii.ico                   |  Bin 766 -> 0 bytes
 dcm2nii_prePARRECDTI/dcm2nii.ini                   |   50 -
 dcm2nii_prePARRECDTI/dcm2nii.lpi                   |  434 --
 dcm2nii_prePARRECDTI/dcm2nii.lpr                   |   73 -
 dcm2nii_prePARRECDTI/dcm2nii.res                   |  Bin 1656 -> 0 bytes
 dcm2nii_prePARRECDTI/dcm2nii48.ico                 |  Bin 17542 -> 0 bytes
 dcm2nii_prePARRECDTI/dcm2niigui.cfg                |   39 -
 dcm2nii_prePARRECDTI/dcm2niigui.dof                |  144 -
 dcm2nii_prePARRECDTI/dcm2niigui.dpr                |   20 -
 dcm2nii_prePARRECDTI/dcm2niigui.ico                |  Bin 17542 -> 0 bytes
 dcm2nii_prePARRECDTI/dcm2niigui.ini                |   45 -
 dcm2nii_prePARRECDTI/dcm2niigui.lpi                |  575 --
 dcm2nii_prePARRECDTI/dcm2niigui.lpr                |   25 -
 dcm2nii_prePARRECDTI/dcm2niigui.lrs                |  732 ---
 dcm2nii_prePARRECDTI/dcm2niigui.manifest           |   17 -
 dcm2nii_prePARRECDTI/dcm2niigui.rc                 |    7 -
 dcm2nii_prePARRECDTI/dcm2niigui.res                |  Bin 18404 -> 0 bytes
 dcm2nii_prePARRECDTI/dicom.pas                     |   32 -
 dcm2nii_prePARRECDTI/dicomcompat.pas               | 6432 --------------------
 dcm2nii_prePARRECDTI/dicomfast.pas                 |  512 --
 dcm2nii_prePARRECDTI/dicomfastread.pas             |  540 --
 dcm2nii_prePARRECDTI/dicomtypes.pas                |  735 ---
 dcm2nii_prePARRECDTI/diskfree.pas                  |  352 --
 dcm2nii_prePARRECDTI/extrafpc.cfg                  |    4 -
 dcm2nii_prePARRECDTI/filename.pas                  |  200 -
 dcm2nii_prePARRECDTI/gui.dfm                       |  Bin 2463 -> 0 bytes
 dcm2nii_prePARRECDTI/gui.lfm                       |  152 -
 dcm2nii_prePARRECDTI/gui.lrs                       |   47 -
 dcm2nii_prePARRECDTI/gui.pas                       | 1166 ----
 dcm2nii_prePARRECDTI/guii.lrs                      |   36 -
 dcm2nii_prePARRECDTI/lsjpeg.pas                    |  777 ---
 dcm2nii_prePARRECDTI/nifti_form.dfm                |  Bin 2791 -> 0 bytes
 dcm2nii_prePARRECDTI/nifti_form.lfm                |  226 -
 dcm2nii_prePARRECDTI/nifti_form.lrs                |   62 -
 dcm2nii_prePARRECDTI/nifti_form.pas                |  134 -
 dcm2nii_prePARRECDTI/niftiutil.pas                 | 1905 ------
 dcm2nii_prePARRECDTI/nii_3dto4d.pas                |  456 --
 dcm2nii_prePARRECDTI/nii_4dto3d.pas                |  458 --
 dcm2nii_prePARRECDTI/nii_asl.pas                   |  605 --
 dcm2nii_prePARRECDTI/nii_crop.pas                  | 1003 ---
 dcm2nii_prePARRECDTI/nii_math.pas                  |  600 --
 dcm2nii_prePARRECDTI/nii_orient.pas                |  726 ---
 dcm2nii_prePARRECDTI/nii_reslice.pas               |  449 --
 dcm2nii_prePARRECDTI/notes.txt                     |  180 -
 dcm2nii_prePARRECDTI/paramstrs.pas                 |  381 --
 dcm2nii_prePARRECDTI/parconvert.pas                | 1201 ----
 dcm2nii_prePARRECDTI/pref_form.dfm                 |  Bin 3630 -> 0 bytes
 dcm2nii_prePARRECDTI/pref_form.lfm                 |  189 -
 dcm2nii_prePARRECDTI/pref_form.lrs                 |   56 -
 dcm2nii_prePARRECDTI/pref_form.pas                 |  192 -
 dcm2nii_prePARRECDTI/prefs.pas                     |  276 -
 dcm2nii_prePARRECDTI/readint.dfm                   |  Bin 644 -> 0 bytes
 dcm2nii_prePARRECDTI/readint.lrs                   |   14 -
 dcm2nii_prePARRECDTI/readint.pas                   |   54 -
 dcm2nii_prePARRECDTI/sortdicom.pas                 |  499 --
 dcm2nii_prePARRECDTI/untar.pas                     |  357 --
 dcm2nii_prePARRECDTI/userdir.pas                   |  220 -
 dcm2nii_prePARRECDTI/windowsxp.res                 |  Bin 736 -> 0 bytes
 dcm2nii_prePARRECDTI/zconf.inc                     |   24 -
 drop.patch                                         |    0
 drop_patch.txt                                     |    0
 mricron.lpi                                        | 1030 ++--
 nifti_img.pas                                      |   28 +-
 nifti_img_view.lfm                                 |   40 +-
 nifti_img_view.lrs                                 | 1402 +++--
 nifti_img_view.pas                                 |   47 +-
 npm/npm.app/Contents/Info.plist                    |    0
 npm/npm.app/Contents/MacOS/npm                     |    0
 npm/npm.app/Contents/PkgInfo                       |    0
 npm/npm.lpi                                        |   56 +-
 npm/spread.pas                                     |    8 +-
 prefs.lfm                                          |   45 +-
 prefs.lrs                                          |   60 +-
 prefs.pas                                          |    4 +-
 render.lfm                                         |   35 +-
 render.lrs                                         |  364 +-
 render.pas                                         |   39 +-
 105 files changed, 2226 insertions(+), 29075 deletions(-)

diff --git a/ReadInt.lfm b/ReadInt.lfm
index dc8c679..72ebadf 100755
--- a/ReadInt.lfm
+++ b/ReadInt.lfm
@@ -2,41 +2,41 @@ object ReadIntForm: TReadIntForm
   Left = 334
   Height = 95
   Top = 206
-  Width = 465
+  Width = 600
   ActiveControl = ReadIntEdit
   BorderStyle = bsDialog
   Caption = 'Integer required'
   ClientHeight = 95
-  ClientWidth = 465
+  ClientWidth = 600
   Constraints.MaxHeight = 95
-  Constraints.MaxWidth = 465
+  Constraints.MaxWidth = 600
   Constraints.MinHeight = 95
-  Constraints.MinWidth = 465
+  Constraints.MinWidth = 600
   Font.Name = 'MS Sans Serif'
   OnCreate = FormCreate
   OnShow = FormShow
   Position = poScreenCenter
-  LCLVersion = '0.9.29'
+  LCLVersion = '1.0.12.0'
   object ReadIntLabel: TLabel
-    Left = 16
+    Left = 8
     Height = 14
     Top = 15
-    Width = 336
+    Width = 448
     Alignment = taRightJustify
     AutoSize = False
     Caption = 'Enter a number'
     ParentColor = False
   end
   object ReadIntEdit: TSpinEdit
-    Left = 360
-    Height = 24
+    Left = 472
+    Height = 16
     Top = 12
-    Width = 93
+    Width = 120
     MaxValue = 0
     TabOrder = 1
   end
   object OKBtn: TButton
-    Left = 368
+    Left = 472
     Height = 25
     Top = 55
     Width = 75
@@ -45,4 +45,4 @@ object ReadIntForm: TReadIntForm
     OnClick = OKBtnClick
     TabOrder = 0
   end
-end
+end
\ No newline at end of file
diff --git a/ReadInt.lrs b/ReadInt.lrs
index faced82..c592b80 100755
--- a/ReadInt.lrs
+++ b/ReadInt.lrs
@@ -2,17 +2,17 @@
 
 LazarusResources.Add('TReadIntForm','FORMDATA',[
   'TPF0'#12'TReadIntForm'#11'ReadIntForm'#4'Left'#3'N'#1#6'Height'#2'_'#3'Top'#3
-  +#206#0#5'Width'#3#209#1#13'ActiveControl'#7#11'ReadIntEdit'#11'BorderStyle'#7
+  +#206#0#5'Width'#3'X'#2#13'ActiveControl'#7#11'ReadIntEdit'#11'BorderStyle'#7
   +#8'bsDialog'#7'Caption'#6#16'Integer required'#12'ClientHeight'#2'_'#11'Clie'
-  +'ntWidth'#3#209#1#21'Constraints.MaxHeight'#2'_'#20'Constraints.MaxWidth'#3
-  +#209#1#21'Constraints.MinHeight'#2'_'#20'Constraints.MinWidth'#3#209#1#9'Fon'
-  +'t.Name'#6#13'MS Sans Serif'#8'OnCreate'#7#10'FormCreate'#6'OnShow'#7#8'Form'
-  +'Show'#8'Position'#7#14'poScreenCenter'#10'LCLVersion'#6#6'0.9.29'#0#6'TLabe'
-  +'l'#12'ReadIntLabel'#4'Left'#2#16#6'Height'#2#14#3'Top'#2#15#5'Width'#3'P'#1
-  +#9'Alignment'#7#14'taRightJustify'#8'AutoSize'#8#7'Caption'#6#14'Enter a num'
-  +'ber'#11'ParentColor'#8#0#0#9'TSpinEdit'#11'ReadIntEdit'#4'Left'#3'h'#1#6'He'
-  +'ight'#2#24#3'Top'#2#12#5'Width'#2']'#8'MaxValue'#2#0#8'TabOrder'#2#1#0#0#7
-  +'TButton'#5'OKBtn'#4'Left'#3'p'#1#6'Height'#2#25#3'Top'#2'7'#5'Width'#2'K'#25
-  +'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#2'OK'#7'OnClick'#7#10'OKBtnClic'
-  +'k'#8'TabOrder'#2#0#0#0#0
-]);
+  +'ntWidth'#3'X'#2#21'Constraints.MaxHeight'#2'_'#20'Constraints.MaxWidth'#3'X'
+  +#2#21'Constraints.MinHeight'#2'_'#20'Constraints.MinWidth'#3'X'#2#9'Font.Nam'
+  +'e'#6#13'MS Sans Serif'#8'OnCreate'#7#10'FormCreate'#6'OnShow'#7#8'FormShow'
+  +#8'Position'#7#14'poScreenCenter'#10'LCLVersion'#6#8'1.0.12.0'#0#6'TLabel'#12
+  +'ReadIntLabel'#4'Left'#2#8#6'Height'#2#14#3'Top'#2#15#5'Width'#3#192#1#9'Ali'
+  +'gnment'#7#14'taRightJustify'#8'AutoSize'#8#7'Caption'#6#14'Enter a number'
+  +#11'ParentColor'#8#0#0#9'TSpinEdit'#11'ReadIntEdit'#4'Left'#3#216#1#6'Height'
+  +#2#16#3'Top'#2#12#5'Width'#2'x'#8'MaxValue'#2#0#8'TabOrder'#2#1#0#0#7'TButto'
+  +'n'#5'OKBtn'#4'Left'#3#216#1#6'Height'#2#25#3'Top'#2'7'#5'Width'#2'K'#25'Bor'
+  +'derSpacing.InnerBorder'#2#4#7'Caption'#6#2'OK'#7'OnClick'#7#10'OKBtnClick'#8
+  +'TabOrder'#2#0#0#0#0
+]);
\ No newline at end of file
diff --git a/common/GraphicsMathLibrary.pas b/common/GraphicsMathLibrary.pas
index 02a6229..1c6f55e 100755
--- a/common/GraphicsMathLibrary.pas
+++ b/common/GraphicsMathLibrary.pas
@@ -175,7 +175,7 @@ begin
       END;
       RESULT.vector[a.size] := 1.0 {assume homogeneous coordinate}
     END
-    ELSE raise EMatrixError.Create('Transform multiply error')
+    ELSE raise EMatrixError.Create('Transform multiply error'+inttostr(a.size)+' '+inttostr(u.size))
   END {Transform};
 
 
@@ -1113,4 +1113,4 @@ END;
 INITIALIZATION
  fuzz := 1.0E-6;
 
-END. {GraphicsMath UNIT}
+END. {GraphicsMath UNIT}
\ No newline at end of file
diff --git a/common/define_types.pas b/common/define_types.pas
index 5ba7b5f..589205f 100755
--- a/common/define_types.pas
+++ b/common/define_types.pas
@@ -18,11 +18,15 @@ interface
         SysUtils,classes,IniFiles,
         {$IFDEF GUI} forms,userdir, dialogs{$ELSE}dialogsx{$ENDIF};
 const
-     kMRIcronVersDate = '3/3/2014';
-     {$ifdef CPU32}
-     kMRIcronVers = kMRIcronVersDate+' 32bit BSD License';
+     kMRIcronVersDate = '4JULY2014';
+     {$IFDEF FPC}
+      {$ifdef CPU32}
+      kMRIcronVers = kMRIcronVersDate+' 32bit BSD License';
+      {$ELSE}
+      kMRIcronVers = kMRIcronVersDate+' 64bit BSD License';
+      {$ENDIF}
      {$ELSE}
-     kMRIcronVers = kMRIcronVersDate+' 64bit BSD License';
+      kMRIcronVers = kMRIcronVersDate+' 32bit BSD License';
      {$ENDIF}
 
      NaN : double = 1/0;
diff --git a/common/nifti_foreign.pas b/common/nifti_foreign.pas
index 1913822..584d2bd 100755
--- a/common/nifti_foreign.pas
+++ b/common/nifti_foreign.pas
@@ -864,6 +864,15 @@ begin
   result := true;
 end;//MHA
 
+Function StrToFloatSafe(Const S : String) : single;
+begin
+  try
+   result := strtofloat(S);
+   except on EConvertError do
+          result := 1/0
+   end;//except
+end;
+
 function readNRRDHeader (var fname: string; var nhdr: TNIFTIhdr; var gzBytes: int64; var swapEndian: boolean): boolean;
 //http://www.sci.utah.edu/~gk/DTI-data/
 //http://teem.sourceforge.net/nrrd/format.html
@@ -874,7 +883,7 @@ var
   ch: char;
   mArray: TStringList;
   str,tagName,elementNames: string;
-  i,s,nItems,headerSize,matElements,fileposBytes: integer;
+  i,j,s,nItems,headerSize,matElements,fileposBytes: integer;
   mat: mat33;
   isDetachedFile,isFirstLine: boolean;
   offset: array[0..3] of single;
@@ -936,10 +945,15 @@ begin
       for i:=0 to (nItems-1) do
           nhdr.dim[i+1] := strtoint(mArray.Strings[i]);
     end else if AnsiContainsText(tagName, 'space directions') then begin
-      if (nItems > 12) then nItems :=12;
+      j := 0;
+      while (j <  nItems) and (StrToFloatSafe( mArray.Strings[j]) = 1/0) do
+            j := j + 1;
+
+      if ((nItems-j) >= 12) then begin
+      if ((nItems+j) > 12) then nItems :=(12+j);
       matElements :=nItems;
       for i:=0 to (nItems-1) do
-          transformMatrix[i] :=strtofloat(mArray.Strings[i]);
+          transformMatrix[i] :=strtofloat(mArray.Strings[i+j]);
       if (matElements >= 12) then
           LOAD_MAT33(mat, transformMatrix[0],transformMatrix[1],transformMatrix[2],
                      transformMatrix[4],transformMatrix[5],transformMatrix[6],
@@ -948,6 +962,7 @@ begin
           LOAD_MAT33(mat, transformMatrix[0],transformMatrix[1],transformMatrix[2],
                      transformMatrix[3],transformMatrix[4],transformMatrix[5],
                      transformMatrix[6],transformMatrix[7],transformMatrix[8]);
+      end; //if false
     end else if AnsiContainsText(tagName, 'type') then begin
       if AnsiContainsText(mArray.Strings[0], 'uchar') or
           AnsiContainsText(mArray.Strings[0], 'uint8') or
@@ -962,6 +977,9 @@ begin
       else if AnsiContainsText(mArray.Strings[0], 'unsigned')
                and (nItems > 1) and AnsiContainsText(mArray.Strings[1], 'char') then
           nhdr.datatype := kDT_UINT8 //DT_UINT8
+       else if AnsiContainsText(mArray.Strings[0], 'unsigned')
+               and (nItems > 1) and AnsiContainsText(mArray.Strings[1], 'short') then
+          nhdr.datatype := kDT_UINT16 //DT_UINT16
       else if AnsiContainsText(mArray.Strings[0], 'unsigned') and
                (nItems > 1) and AnsiContainsText(mArray.Strings[1], 'int') then
           nhdr.datatype := kDT_INT32 //
diff --git a/dcm2nii/PARtoNRRD_Philips_RelX.zip b/dcm2nii/PARtoNRRD_Philips_RelX.zip
deleted file mode 100755
index 1568f67..0000000
Binary files a/dcm2nii/PARtoNRRD_Philips_RelX.zip and /dev/null differ
diff --git a/dcm2nii/bvec.pas b/dcm2nii/bvec.pas
new file mode 100755
index 0000000..c71bffc
--- /dev/null
+++ b/dcm2nii/bvec.pas
@@ -0,0 +1,79 @@
+unit bvec;
+{$ifdef fpc}{$mode delphi}{$endif}
+{$H+}
+interface
+uses
+  //StrUtils,
+  Classes, SysUtils, define_types, dicomtypes, dialogsx,GraphicsMathLibrary,dialogs_msg;
+//{$DEFINE VERBOSE_BVEC}
+
+
+procedure siemensPhilipsCorrectBvecs (var lDICOMdata:dicomdata; var lDTIra: TDTIra; nVec: integer; lSliceOrientMosaicNegativeDeterminant: boolean);
+
+implementation
+
+(*function VV (lLabel: string; var lV: TVector): string;
+begin
+     result := lLabel +' =['+ floattostr(lV.x)+','+floattostr(lV.y)+','+ floattostr(lV.z)+']'';';
+end;
+
+procedure VTX (var bvecs_old,slice_dir,read_dir,phase_dir: TVector);
+var  lStr : string;
+begin
+      lStr := '';
+      lStr := lStr + VV('bvecs_old',bvecs_old);
+      lStr := lStr + VV('slice_dir',slice_dir);
+      lStr := lStr + VV('read_dir',read_dir);
+      lStr := lStr + VV('phase_dir',phase_dir);
+      dcmMsg(lStr);
+end;  *)
+
+procedure siemensPhilipsCorrectBvecs (var lDICOMdata:dicomdata; var lDTIra: TDTIra; nVec: integer; lSliceOrientMosaicNegativeDeterminant: boolean);
+    //see Matthew Robson's  http://users.fmrib.ox.ac.uk/~robson/internal/Dicom2Nifti111.m
+    //convert DTI vectors from scanner coordinates to image frame of reference
+    //Uses 6 orient values from ImageOrientationPatient  (0020,0037)
+    // requires PatientPosition 0018,5100 is HFS (head first supine)
+var
+   lI: integer;
+   read_vector ,phase_vector,slice_vector,bvecs_old,bvecs_new: TVector;
+begin
+     if nVec < 1 then exit;
+     if (length(lDicomData.PatientPos) >= 3) and (lDicomData.PatientPos[1] = 'H') and (lDicomData.PatientPos[2] = 'F') and (lDicomData.PatientPos[3] = 'S') then
+     else begin
+          dcmMsg('DTI vector error: Position is not head first supine');
+          exit;
+     end;
+    read_vector := Vector3D(lDICOMData.Orient[1],lDICOMData.Orient[2],lDICOMData.Orient[3]);
+    phase_vector := Vector3D(lDICOMData.Orient[4],lDICOMData.Orient[5],lDICOMData.Orient[6]);
+    slice_vector := CrossProduct(read_vector ,phase_vector);
+
+    NormalizeVector(read_vector);
+    NormalizeVector(phase_vector);
+    NormalizeVector(slice_vector);
+    for lI := 1 to nVec do begin
+        //afx('test',lDTIra[lI],lI);
+        if (lDTIra[lI].bval <= 0) or  ((lDTIra[lI].v1 = 0) and (lDTIra[lI].v2 = 0) and (lDTIra[lI].v3 = 0)) then begin
+            lDTIra[lI].v1 := 0;
+            lDTIra[lI].v2 := 0;
+            lDTIra[lI].v3 := 0;
+        end else begin
+            bvecs_old := Vector3D(lDTIra[lI].v1,lDTIra[lI].v2,lDTIra[lI].v3);
+            //VTX (bvecs_old,slice_vector,read_vector,phase_vector );
+            bvecs_new :=Vector3D(DotProduct(bvecs_old,read_vector),DotProduct(bvecs_old,phase_vector),DotProduct(bvecs_old,slice_vector) );
+            bvecs_new.y := - bvecs_new.y;
+            NormalizeVector(bvecs_new);
+            lDTIra[lI].v1 := bvecs_new.x;
+            if  lSliceOrientMosaicNegativeDeterminant then
+                lDTIra[lI].v2 := -bvecs_new.y
+            else
+                lDTIra[lI].v2 := bvecs_new.y;
+            lDTIra[lI].v3 := bvecs_new.z;
+        end;
+    end;//for each bvec
+    if  lSliceOrientMosaicNegativeDeterminant then
+        dcmmsg('WARNING: please validate DTI vectors (matrix had a negative determinant, perhaps Siemens sagittal).');
+
+end;//PhilipsSiemensCorrectBvecs
+
+end.
+
diff --git a/dcm2nii/convert.pas b/dcm2nii/convert.pas
index 0042bf9..f714609 100755
--- a/dcm2nii/convert.pas
+++ b/dcm2nii/convert.pas
@@ -12,11 +12,11 @@ gzio2,
 {$ENDIF}
 filename,define_types,classes,SysUtils,dicom,dicomtypes, nifti_types,
 niftiutil,GraphicsMathLibrary,  userdir,csaread,dialogs_msg, math,
-nii_4dto3d,nii_orient,nii_crop,prefs,lsjpeg;
+nii_4dto3d,nii_orient,nii_crop,prefs,lsjpeg, bvec;
 function Dicom2NII(var lDICOMra: TDICOMrap; lFirstDICOM, lLastDICOM: integer; var lOutDirOrig: string; var lPrefs: TPrefs; lVols: integer): boolean;
 implementation
 uses
-sortdicom,dialogsx, philips_bvec;
+sortdicom,dialogsx;
 
 function getDeterminant(r: TMatrix): double;
 var
@@ -91,7 +91,7 @@ FUNCTION Diag3D (CONST m1,m2,m3,m4:  DOUBLE):  TMatrix;
 	END
 END {Diag3D};
 
-procedure AdjMosaic (var Q: TMatrix; var lDicomData: DicomData);
+(*procedure AdjMosaic (var Q: TMatrix; var lDicomData: DicomData);
 //Changes suggested by Antonin Skoch" <ansk at medicon.cz<mailto:ansk at medicon.cz>>
 // September 23, 2011 10:38:05 AM
 var
@@ -103,16 +103,8 @@ begin
    Q.matrix[1,4] :=(Q.matrix[1,1]*lFactorX)+(Q.matrix[1,2]*lFactorY)+Q.matrix[1,4];
    Q.matrix[2,4] :=(Q.matrix[2,1]*lFactorX)+(Q.matrix[2,2]*lFactorY)+Q.matrix[2,4];
    Q.matrix[3,4] :=(Q.matrix[3,1]*lFactorX)+(Q.matrix[3,2]*lFactorY)+Q.matrix[3,4];
-end;
-(*procedure AdjMosaic (var Q: TMatrix; var lDicomData: DicomData);
-var
-	lFactor: double;
-begin
-	lFactor := (lDicomData.XYZdim[1] - (lDicomData.XYZdim[1]/lDicomData.SiemensMosaicX)   )/2;
-	Q.matrix[1,4] := (Q.matrix[1,1]*lFactor)+(Q.matrix[1,2]*lFactor){+(Q.matrix[1,3])}+Q.matrix[1,4];
-	Q.matrix[2,4] := (Q.matrix[2,1]*lFactor)+(Q.matrix[2,2]*lFactor){+(Q.matrix[1,3])}+Q.matrix[2,4];
-	Q.matrix[3,4] := (Q.matrix[3,1]*lFactor)+(Q.matrix[3,2]*lFactor){+(Q.matrix[1,3])}+Q.matrix[3,4];
-end;  *)
+end; *)
+
 
 (*procedure get_numaris4_val(lFilename,lTagName1,lTagName2: string; var lnmosaic: integer; var lv1,lv2,lv3:single); // spm_dicom_convert
 label 121;
@@ -245,8 +237,8 @@ begin
               lDicomData.Orient[3],lDicomData.Orient[6],lv3);
      if  nifti_mat33_determ(Q) < 0 then begin
 
-     dcmMsg('Note: raw slice order R>>L (Siemens convention), dcm2niiprior to 2014 stored these as L>>R, NIfTI convention). Benefit: simpler slice timing correction (ascending is 1..N, descending is N..1)');
-     //result := true;
+         //dcmMsg('Note: raw slice order R>>L (Siemens convention), dcm2niiprior to 2014 stored these as L>>R, NIfTI convention). Benefit: simpler slice timing correction (ascending is 1..N, descending is N..1)');
+         result := true;
      end;
      lMosaicSlices := lnmos;
 end;
@@ -276,6 +268,61 @@ begin
      //fx(lDTI.bval);
 end;
 
+(*procedure ReportMatrix(s: string; q: TMatrix);
+begin
+     dcmmsg(s+Format('=[ %g %g %g %g; %g %g %g %g; %g %g %g %g; 0 0 0 1]',  [
+     q.matrix[1,1],q.matrix[1,2],q.matrix[1,3],q.matrix[1,4]  ,
+     q.matrix[2,1],q.matrix[2,2],q.matrix[2,3],q.matrix[2,4] ,
+     q.matrix[3,1],q.matrix[3,2],q.matrix[3,3],q.matrix[3,4]]));
+end;
+
+procedure ReportMat33(s: string; q: TMatrix);
+begin
+     dcmmsg(s+Format('=[ %g %g %g; %g %g %g; %g %g %g]',  [
+     q.matrix[1,1],q.matrix[1,2],q.matrix[1,3]  ,
+     q.matrix[2,1],q.matrix[2,2],q.matrix[2,3] ,
+     q.matrix[3,1],q.matrix[3,2],q.matrix[3,3]]));
+end;   *)
+
+procedure dicom_2_niftiMosaic(var Q44: TMatrix; var d: DicomData; var lHdr: TNiftiHdr ; lMosaicSlices: integer; var lFlipMosaic: boolean);
+var
+  det: TMatrix;
+  nRowCol,lFactorX,lFactorY: double;
+  c,r: integer;
+  v,vO: TVector;
+begin
+     nRowCol := ceil(sqrt(lMosaicSlices));
+     lFactorX := (d.xyzDim[1] -(d.xyzDim[1]/nRowCol)   )/2.0;
+     lFactorY := (d.xyzDim[2] -(d.xyzDim[2]/nRowCol)   )/2.0;
+     Q44.matrix[1,4] :=(Q44.matrix[1,1]*lFactorX)+(Q44.matrix[1,2]*lFactorY)+Q44.matrix[1,4];
+     Q44.matrix[2,4] :=(Q44.matrix[2,1]*lFactorX)+(Q44.matrix[2,2]*lFactorY)+Q44.matrix[2,4];
+     Q44.matrix[3,4] :=(Q44.matrix[3,1]*lFactorX)+(Q44.matrix[3,2]*lFactorY)+Q44.matrix[3,4];
+     Q44.size := size3D;
+     //ReportMatrix('mega',Q44);
+     for c:=1 to 2 do
+         for r := 1 to 4 do
+             Q44.matrix[c,r] := -Q44.matrix[c,r];
+
+      if lFlipMosaic then begin
+         det := Diag3D(1,1,-1,1);
+         Q44 := MultiplyMatrices(Q44,det);
+      end;
+      //next we have flipped images on the Y dimension
+      vO := Vector3D(0,lHdr.dim[2]-1,0); //find coordinate of new origin voxel - located on opposite side of Y-dimension
+      for r := 1 to 3 do begin
+        v.vector[r] := 0;
+        for  c :=1 to 4 do
+            v.vector[r] := v.vector[r] + (Q44.matrix[r,c]*vO.vector[c]);
+      end;
+      det := Diag3D(1,-1,1,1);
+      Q44 := MultiplyMatrices(Q44,det);
+      Q44.matrix[1,4] := v.x;
+      Q44.matrix[2,4] := v.y;
+      Q44.matrix[3,4] := v.z;
+
+
+end;
+
 procedure dicom_2_nifti(var lDicomData: DicomData; var lHdr: TNiftiHdr ; lMosaicSlices: integer; var lFlipMosaic: boolean);
 var
   Q,res,diagVox,patient_to_tal,analyze_to_dicom: TMatrix;
@@ -292,6 +339,7 @@ begin
    Q := Diag3D(1,1,1,1);//set column 4 and row 4 to zeros, except [4,4]
    Q.matrix[1,1] :=lDicomData.Orient[1] ; Q.matrix[1,2] := lDicomData.Orient[2] ; Q.matrix[1,3] := lDicomData.Orient[3] ; //* load Q */
    Q.matrix[2,1] := lDicomData.Orient[4] ; Q.matrix[2,2] := lDicomData.Orient[5] ; Q.matrix[2,3] := lDicomData.Orient[6] ;
+   //ReportMatrix('bar',Q);
    // normalize row 1
    val := Q.matrix[1,1]*Q.matrix[1,1] + Q.matrix[1,2]*Q.matrix[1,2] + Q.matrix[1,3]*Q.matrix[1,3] ;
    if( val > 0.0 ) then begin
@@ -308,6 +356,7 @@ begin
    end else begin
 	 Q.matrix[2,1] := 0.0 ; Q.matrix[2,2] := 1.0 ; Q.matrix[2,3] := 0.0 ;
    end;
+   //ReportMat33('norm',Q);
    //row 3 is cross product of previous rows
    Q.matrix[3,1] := Q.matrix[1,2]*Q.matrix[2,3] - Q.matrix[1,3]*Q.matrix[2,2] ;
    Q.matrix[3,2] := Q.matrix[1,3]*Q.matrix[2,1] - Q.matrix[1,1]*Q.matrix[2,3] ;
@@ -325,20 +374,28 @@ begin
 	   Q.matrix[2,3] := -Q.matrix[2,3];
 	   Q.matrix[3,3] := -Q.matrix[3,3];
    end;
+   //reportMatrix('preScale',Q);
    //next scale matrix
    diagVox := Diag2D(lDicomData.XYZmm[1],lDicomData.XYZmm[2],lDicomData.XYZmm[3]);
    Q.size := size2D;
    Q := MultiplyMatrices(Q,diagVox);
+   //reportMatrix('postScale',Q);
    //next - add translations
    Q.matrix[1,4] := lDicomData.PatientPosX;
    Q.matrix[2,4] := lDicomData.PatientPosY;
    Q.matrix[3,4] := lDicomData.PatientPosZ;
-   val := lDicomData.XYZdim[2];
+   //reportMatrix('postOffset',Q);
    if (lDICOMdata.SiemensMosaicX > 1) or (lDICOMdata.SiemensMosaicY > 1) then begin
+        dicom_2_niftiMosaic(Q, lDicomData, lHdr, lMosaicSlices, lFlipMosaic);
+
+
+   end else begin
+   val := lDicomData.XYZdim[2];
+   (*if (lDICOMdata.SiemensMosaicX > 1) or (lDICOMdata.SiemensMosaicY > 1) then begin
 	AdjMosaic(Q,lDICOMdata);
 	val := lDicomData.XYZdim[2]/lDICOMdata.SiemensMosaicY;
         //lFlipMosaic := IsNormalMosaic(lDicomData,lMosaicSlices,lFilename);
-   end;
+   end; *)
    Q.matrix[4,1] := 0;
    Q.matrix[4,2] := 0;
    Q.matrix[4,3] := 0;
@@ -357,6 +414,7 @@ begin
    //reportmatrix('p2tal',patient_to_tal);
    //reportMatrix('a2d',analyze_to_dicom);
    Q := MultiplyMatrices(patient_to_tal,Q);
+   //reportMatrix('postTal',Q);
    Q := MultiplyMatrices(Q,analyze_to_dicom);
    //reportMatrix('mat',Q);
    //Q now equals 'mat' in spm_dicom_convert
@@ -367,14 +425,18 @@ begin
 	0, 0,1,1,
 	0, 0, 0, 1);
    Q := MultiplyMatrices(Q,analyze_to_dicom);//not used for flips
-   if ((lDICOMdata.SiemensMosaicX > 1) or (lDICOMdata.SiemensMosaicY > 1)) and (lFlipMosaic) then begin
-     //reportmatrix('QmosaicIn',Q);
-            patient_to_tal   := diag3D(1, 1, 1,1);
-            patient_to_tal.matrix[3,4] := 1-lMosaicSlices;
+  (*if ((lDICOMdata.SiemensMosaicX > 1) or (lDICOMdata.SiemensMosaicY > 1)) and (lFlipMosaic) then begin
+
+              patient_to_tal   := diag3D(1, 1, 1,1);
+              patient_to_tal.matrix[3,4] := 1-lMosaicSlices;
+              Q := MultiplyMatrices(Q,patient_to_tal);
+     end else if ((lDICOMdata.SiemensMosaicX > 1) or (lDICOMdata.SiemensMosaicY > 1)) and (getDeterminant(Q) < 0)  then begin
+            //patient_to_tal   := diag3D(1, 1, 1,1);
+            //patient_to_tal.matrix[3,4] := 1-lMosaicSlices;
+        patient_to_tal   := diag3D(1, 1, -1,1);
             Q := MultiplyMatrices(Q,patient_to_tal);
-     //reportmatrix('r',patient_to_tal);
-     //reportmatrix('QmosaicOut',Q);
-   end;
+   end;  *)
+     end;  //if mosaic else not mosaic
    //if (lDICOMdata.SiemensMosaicX = 1) and (lDICOMdata.SiemensMosaicY = 1) then
    //reportmatrix('final',Q);
    //mat44_to_quatern(Q); *)
@@ -701,7 +763,6 @@ end;
 procedure DeMosaic (var lBuffer: bytep;lmosX,lmosY,lSlices: integer; lFlip: boolean; var lDicomData: DICOMdata);
 //unMosaic
 var
-	//lImgBytes,
         lPos,lH,lW,lnMos,lMos,lMosW,lMosH, lStripBytes,lPanelBytes,lStartOffset: integer;
 	lTempBuffer: ByteP;
 begin
@@ -721,10 +782,11 @@ begin
 	lPos := 0;
 if  lFlip then begin
 
-dcmmsg('*** WARNING: CSA "ProtocolSliceNumber" SUGGESTS MOSAIC SLICE ORDER REVERSED. SPATIAL AND DTI COORDINATES UNTESTED ****');
+dcmmsg('*** WARNING: CSA "ProtocolSliceNumber" SUGGESTS REVERSED SLICE ORDER: SPATIAL AND DTI COORDINATES UNTESTED ****');
 dcmmsg('*** SOLUTION: open sequence on scanner, go to System tab, select Miscellaneous sub-tab, set default image numbering (F>>H, R>>L, A>>P');
 dcmmsg('***  If this is impossible and you wish to use these sequences for DTI please conduct DTI validation described on the dcm2nii web page');
-for lMos :=  lnMos downto 1 do begin
+end;
+     (* for lMos :=  lnMos downto 1 do begin
             lStartOffset := ((lMos-1) mod lmosX)*lStripBytes+ ( ((lMos-1) div lmosX)* (lPanelBytes*lMosH));
 	    for lH := 1 to lMosH do begin
 	        for lW := 1 to lStripBytes do begin
@@ -735,7 +797,7 @@ for lMos :=  lnMos downto 1 do begin
 		lStartOffset := lStartOffset + lPanelBytes;
 	    end;
 	end;
-end else begin
+end else *)begin
 	for lMos := 1 to lnMos do begin
             lStartOffset := ((lMos-1) mod lmosX)*lStripBytes+ ( ((lMos-1) div lMosX)* (lPanelBytes*lMosH));
 	    for lH := 1 to lMosH do begin
@@ -753,7 +815,6 @@ end;
 	lDicomData.XYZdim[1] := lMosW;
 	lDicomData.XYZdim[2] := lMosH;
 	lDicomData.XYZdim[3] := lnMos;
-
 	FlipTB (lDICOMdata, lBuffer);
 end;
 
@@ -800,60 +861,6 @@ begin
      result := result + lFirstDICOM;
 end;
 
-function VV (lLabel: string; var lV: TVector): string;
-begin
-     result := lLabel +' =['+ floattostr(lV.x)+','+floattostr(lV.y)+','+ floattostr(lV.z)+']'';';
-end;
-
-procedure VTX (var bvecs_old,slice_dir,read_dir,phase_dir: TVector);
-var  lStr : string;
-begin
-      lStr := '';
-      lStr := lStr + VV('bvecs_old',bvecs_old);
-      lStr := lStr + VV('slice_dir',slice_dir);
-      lStr := lStr + VV('read_dir',read_dir);
-      lStr := lStr + VV('phase_dir',phase_dir);
-      dcmMsg(lStr);
-
-end;
-
-procedure SiemensCorrectBvecs (var lDICOMdata:dicomdata; var lDTIra: TDTIra; nVec: integer);
-//see  http://users.fmrib.ox.ac.uk/~robson/internal/Dicom2Nifti111.m
-var
-   lI: integer;
-   read_vector ,phase_vector,slice_vector,bvecs_old,bvecs_new: TVector;
-begin
-     if nVec < 1 then exit;
-     if (length(lDicomData.PatientPos) >= 3) and (lDicomData.PatientPos[1] = 'H') and (lDicomData.PatientPos[2] = 'F') and (lDicomData.PatientPos[3] = 'S') then
-     else begin
-          dcmMsg('DTI vector error: Position is not head first supine');
-          exit;
-     end;
-    read_vector := Vector3D(lDICOMData.Orient[1],lDICOMData.Orient[2],lDICOMData.Orient[3]);
-    phase_vector := Vector3D(lDICOMData.Orient[4],lDICOMData.Orient[5],lDICOMData.Orient[6]);
-    slice_vector := CrossProduct(read_vector ,phase_vector);
-
-    NormalizeVector(read_vector);
-    NormalizeVector(phase_vector);
-    NormalizeVector(slice_vector);
-    for lI := 1 to nVec do begin
-        if (lDTIra[lI].bval <= 0) or  ((lDTIra[lI].v1 = 0) and (lDTIra[lI].v2 = 0) and (lDTIra[lI].v3 = 0)) then begin
-            lDTIra[lI].v1 := 0;
-            lDTIra[lI].v2 := 0;
-            lDTIra[lI].v3 := 0;
-        end else begin
-            bvecs_old := Vector3D(lDTIra[lI].v1,lDTIra[lI].v2,lDTIra[lI].v3);
-            VTX (bvecs_old,slice_vector,read_vector,phase_vector );
-            bvecs_new :=Vector3D(DotProduct(bvecs_old,read_vector),DotProduct(bvecs_old,phase_vector),DotProduct(bvecs_old,slice_vector) );
-            bvecs_new.y := - bvecs_new.y;
-            NormalizeVector(bvecs_new);
-            lDTIra[lI].v1 := bvecs_new.x;
-            lDTIra[lI].v2 := bvecs_new.y;
-            lDTIra[lI].v3 := bvecs_new.z;
-        end;
-    end;//for each bvec
-end;
-
 procedure SiemensFlipYBvecs (var lDTIra: TDTIra; nVec: integer);
 var
    lI: integer;
@@ -881,15 +888,13 @@ begin
 end;
 
 procedure GECorrectBvecs (var lDICOMdata:dicomdata; var lDTIra: TDTIra; nVec: integer);
+//0018,1312 phase encoding is either in row or column direction
 //0043,1039 (or 0043,a039). b value (as the first number in the string).
-//0019,10bb (or 0019,a0bb). X diffusion direction
-//0019,10bc (or 0019,a0bc). Y diffusion direction
-//0019,10bd (or 0019,a0bd). Z diffusion direction
-//These directions are relative to freq,phase,slice, so although no
-//transformations are required, you need to check the direction of the
-//phase encoding. This is in DICOM message 0018,1312. If this has value
-//COL then if swap the x and y value and reverse the sign on the z value.
-//If the phase encoding is not COL, then just reverse the sign on the x value.
+//0019,10bb (or 0019,a0bb). Phase-gradient diffusion direction
+//0019,10bc (or 0019,a0bc). Frequency-gradient diffusion direction
+//0019,10bd (or 0019,a0bd). Slice diffusion direction
+//If 0018,1312 = Col then X=-x0bb,  Y=x0bc, Z=x0bd,
+//If 0018,1312 = Row then X=-x0bc,  Y=-x0bb, Z=x0bd,
 var
    lI: integer;
    lCol: boolean;
@@ -901,27 +906,30 @@ begin
           dcmMsg('DTI vector error: Position is not head first supine');
           exit;
      end;
-     if  (length(lDicomData.PhaseEncoding) >= 3)  and (lDicomData.PhaseEncoding[1] = 'C') and (lDicomData.PatientPos[2] = 'O') and (lDicomData.PatientPos[3] = 'L') then
+     if  (length(lDicomData.PhaseEncoding) >= 3)  and (upcase(lDicomData.PhaseEncoding[1]) = 'C')  then
         lCol := true
      else
          lCol := false;
-    for lI := 1 to nVec do begin
-        if (lDTIra[lI].bval <= 0) or  ((lDTIra[lI].v1 = 0) and (lDTIra[lI].v2 = 0) and (lDTIra[lI].v3 = 0)) then begin
+     //dcmMsg('>>>>'+lDicomData.PhaseEncoding[1]+lDicomData.PhaseEncoding[2]+lDicomData.PhaseEncoding[3]+'<<<'+inttostr(length(lDicomData.PhaseEncoding)));
+     for lI := 1 to nVec do begin
+         lDTIra[lI].v3 := lDTIra[lI].v3;
+         if (lDTIra[lI].bval <= 0) or  ((lDTIra[lI].v1 = 0) and (lDTIra[lI].v2 = 0) and (lDTIra[lI].v3 = 0)) then begin
             lDTIra[lI].v1 := 0;
             lDTIra[lI].v2 := 0;
             lDTIra[lI].v3 := 0;
         end else begin  //if bval=0 or null vector, else real vector
             if lCol then begin
-               lSwap := lDTIra[lI].v1;
-               lDTIra[lI].v1 := lDTIra[lI].v2;
-               lDTIra[lI].v2 := lSwap;
-               lDTIra[lI].v3 := -lDTIra[lI].v3;
+            lDTIra[lI].v1 := -lDTIra[lI].v1;
+            lDTIra[lI].v2 := lDTIra[lI].v2;
             end else begin
-               lDTIra[lI].v1 := -lDTIra[lI].v1;
-               lDTIra[lI].v2 := lDTIra[lI].v2;
-               lDTIra[lI].v3 := lDTIra[lI].v3;
+                lSwap := lDTIra[lI].v1;
+                lDTIra[lI].v1 := -lDTIra[lI].v2;
+                lDTIra[lI].v2 := -lSwap;
             end;
         end; //real vector  - not 0,0,0
+        if (lDTIra[lI].v1 = -0.0) then lDTIra[lI].v1 := 0.0;
+        if (lDTIra[lI].v2 = -0.0) then lDTIra[lI].v2 := 0.0;
+        if (lDTIra[lI].v3 = -0.0) then lDTIra[lI].v3 := 0.0;
     end;//for each bvec
 end;
 
@@ -977,15 +985,7 @@ begin
   result := true;
 end;
 
-procedure afx(lDICOMImgName: string; lDTI:TDTI; Pos: integer);
-begin
-   dcmMsg(extractfilename(lDicomImgName)+':'
-             +floattostr(lDTI.bval)+': '
-             +floattostr(lDTI.v1)+': '
-             +floattostr(lDTI.v2)+': '
-             +floattostr(lDTI.v3)+ ' @ '
-             +inttostr(Pos));
-end;
+
 
 function ImageScalingOrIntensityVaries(var lDICOMra: TDICOMrap; lFirstDICOM, lLastDICOM: integer): boolean;
 var
@@ -1103,7 +1103,7 @@ var
 begin
   result := 1;
   if length(lSliceTImes) < 1 then exit;
-  s := '  MosaicRefAcqTimes (Slice Time Correction) ';
+  s := '  MosaicRefAcqTimes ('+inttostr(length(lSliceTimes))+' values for Slice Time Correction) ';
   for i := 0 to (length(lSliceTimes)-1) do
      s := s+kTab+floattostr(lSliceTImes[i]);
   dcmmsg(s);
@@ -1111,7 +1111,7 @@ begin
      if SameValue(lSliceTImes[i], lSliceTImes[0]) then
         inc(result);
   if (result > 1) then
-     dcmmsg('Slice Timing Note: multiband factor x'+inttostr(result));
+     dcmmsg(' These values suggest a multiband factor of '+inttostr(result));
 end;
 
 
@@ -1179,7 +1179,7 @@ var
  lTextF: TextFile;
  lOutF,lInF: File;
  lvBuffer,lsBuffer: bytep;
- lOldFlipMosaic,lFlippedMosaic: boolean;
+ lFlipMosaicMatrix,lFlipMosaic: boolean;
 begin
      lDicomImgName := lDICOMra^[lFirstDICOM].Filename;
      lDicomData := lDICOMra^[lFirstDICOM];
@@ -1196,7 +1196,7 @@ begin
   lmosX := 1;
   lmosY := 1;
   lSecondDICOM := lFirstDICOM+1;
-
+  lFlipMosaicMatrix := false;
   lInterleaved := false;
 
   lnSeries :=  (lLastDICOM+1) -lFirstDICOM; //e.g. first=10, last=10 means 1 image
@@ -1277,8 +1277,9 @@ begin
         lDTIdir := 0;
 
         IsSiemensDTI(lDicomData,lDTIra[1], lDicomImgName, lPrefs);//see if this is a Siemens DTI image - mosaics in B13, non-mosaic in B12
-	if (lDICOMdata.SiemensMosaicX > 1) or (lDICOMdata.SiemensMosaicY > 1) then begin
-           lOldFlipMosaic := IsNormalMosaic(lDicomData,lMosaicSlices, lDicomImgName);
+
+        if (lDICOMdata.SiemensMosaicX > 1) or (lDICOMdata.SiemensMosaicY > 1) then begin
+           lFlipMosaicMatrix := IsNormalMosaic(lDicomData,lMosaicSlices, lDicomImgName);
 	   lAHdr.dim[1] := lDicomData.XYZdim[1] div lDICOMdata.SiemensMosaicX;
 	   lAHdr.dim[2] := lDicomData.XYZdim[2] div lDICOMdata.SiemensMosaicY;
            lmosX := lDICOMdata.SiemensMosaicX;
@@ -1319,7 +1320,7 @@ begin
            if lAHdr.slice_code <> kNIFTI_SLICE_SEQ_UNKNOWN then begin
            //read final not first image https://github.com/eauerbach/CMRR-MB/issues/29
            //DecodeCSA2 (lDicomImgName, lDicomData.CSAImageHeaderInfoPos,lDicomData.CSAImageHeaderInfoSz, lCSA, lSliceTimes, lFlippedMosaic);
-           DecodeCSA2 (lDICOMra^[lLastDICOM].Filename, lDICOMra^[lLastDICOM].CSAImageHeaderInfoPos,lDICOMra^[lLastDICOM].CSAImageHeaderInfoSz, lCSA, lSliceTimes, lFlippedMosaic);
+           DecodeCSA2 (lDICOMra^[lLastDICOM].Filename, lDICOMra^[lLastDICOM].CSAImageHeaderInfoPos,lDICOMra^[lLastDICOM].CSAImageHeaderInfoSz, lCSA, lSliceTimes, lFlipMosaic);
            reportSliceTimes(lSliceTimes);
            SetNiiStr(lAHdr, lStr, lDICOMra^[lLastDICOM].ImageComments);
            if (lCSA.PhaseDirectionPositive = 1) then
@@ -1339,7 +1340,6 @@ begin
               if (lDICOMdata.PhaseEncoding[1]='C') then begin//columns
                  lAHdr.pixdim[6] :=  1000/lDICOMdata.BandwidthPerPixelPhaseEncode/lAHdr.dim[2];
                  lAHdr.slice_duration:= lAHdr.pixdim[6] * lAHdr.dim[2];
-                 dcmMsg(inttostr(lAHdr.dim[2]));
               end else begin  //rows
                   lAHdr.pixdim[6] :=  1000/lDICOMdata.BandwidthPerPixelPhaseEncode/lAHdr.dim[1];
                   lAHdr.slice_duration:= lAHdr.pixdim[6] * lAHdr.dim[1];
@@ -1367,7 +1367,7 @@ lFlip := false;
            lAHdr.pixdim[3]  := lDX;
         end;
   end;
-	dicom_2_nifti(lDICOMdata,lAHdr,lMosaicSlices,lFlippedMosaic);
+  dicom_2_nifti(lDICOMdata,lAHdr,lMosaicSlices,lFlipMosaicMatrix);
   //all slices in a NIFTI image must be of the same precision and have the same scaling intercept and slope - see if this applies
   (*lBaseIntenScale := lDICOMdata.IntenScale;
   lBaseIntenIntercept := lDICOMdata.IntenIntercept;
@@ -1394,7 +1394,7 @@ lFlip := false;
 
                 msgfx(lSeries, lDICOMdata.DTI[1].v1,lDICOMdata.DTI[1].v2,lDICOMdata.DTI[1].v3);
   end; *)
-  //exit;//get out of here - crucial critical -- last chance before data saved to disk
+ // exit;//get out of here - crucial critical -- last chance before data saved to disk
      
     if (lAHdr.bitpix = 8) and (lDicomData.SamplesPerPixel = 3) then begin
        if (lIntenScaleVaries) then begin
@@ -1546,7 +1546,7 @@ lFlip := false;
                   if (lDICOMdata.PlanarConfig = 0) and (lDicomData.SamplesPerPixel = 3) then
                        MakePlanar(lsBuffer,lDICOMdata);
                   if (lMosX > 1) or (lMosY > 1) then begin
-			                  DeMosaic(lsBuffer,lmosX,lmosY,lMosaicSlices,lFlippedMosaic,lDICOMdata);
+			                  DeMosaic(lsBuffer,lmosX,lmosY,lMosaicSlices,lFlipMosaic,lDICOMdata);
                         lSliceBytesOut :=lAHdr.dim[1]*lAHdr.dim[2]*lAHdr.dim[3]*trunc((lAHdr.bitpix+7)/8);
 		              end else
 			              FlipTB(lDICOMdata,lsBuffer);
@@ -1595,19 +1595,20 @@ lFlip := false;
               lOutDTIname := lOutImgName;
               dcmMsg('Number of diffusion directions = '+inttostr(lDTIdir));
               if lDicomData.ManufacturerID = kSiemensID then begin
-                 dcmMsg('Note: detected Siemens Software version [0018:1020] = '+inttostr(lDicomData.Vers0018_1020) );
-                 dcmMsg('  -Will use 0019:000E or 0019:100E instead of 0029:1020 if version >= ' +inttostr(lPrefs.SiemensDTIUse0019If00181020atleast));
-                 dcmMsg('  -Will stack across Acquisitions if version >=' +inttostr(lPrefs.SiemensDTIStackIf00181020atleast));
-                 dcmMsg('  -No slice angulation correction of vectors if version >=' +inttostr(lPRefs.SiemensDTINoAngulationCorrectionIf00181020atleast));
-                 dcmMsg('  To adjust, edit '+IniName );
                  if lDicomData.Vers0018_1020 = 13 then
                     dcmMsg('  *Warning: some Siemens VB13 set DiffusionGradientDirection incorrectly. Please check manually validate');                    
-                 if lDicomData.Vers0018_1020 >= lPrefs.SiemensDTINoAngulationCorrectionIf00181020atleast  then 
+                 if lDicomData.Vers0018_1020 >= lPrefs.SiemensDTINoAngulationCorrectionIf00181020atleast  then begin
+                    dcmMsg('Note: detected Siemens Software version [0018:1020] = '+inttostr(lDicomData.Vers0018_1020) );
+                    dcmMsg('  -Will use 0019:000E or 0019:100E instead of 0029:1020 if version >= ' +inttostr(lPrefs.SiemensDTIUse0019If00181020atleast));
+                    dcmMsg('  -Will stack across Acquisitions if version >=' +inttostr(lPrefs.SiemensDTIStackIf00181020atleast));
+                    dcmMsg('  -No slice angulation correction of vectors if version >=' +inttostr(lPRefs.SiemensDTINoAngulationCorrectionIf00181020atleast));
+                    dcmMsg('  To adjust, edit '+IniName );
                     SiemensFlipYBvecs(lDTIra,lDTIdir)
-                 else
-                     SiemensCorrectBvecs(lDicomData,lDTIra,lDTIdir);
+                 end else
+                     siemensPhilipsCorrectBvecs(lDicomData,lDTIra,lDTIdir, lFlipMosaicMatrix);
               end else if lDicomData.ManufacturerID = kPhilipsID then begin
-                   PhilipsCorrectBvecs(lDicomData,lDTIra,lDTIdir);
+                   //-->PhilipsCorrectBvecs(lDicomData,lDTIra,lDTIdir);
+                 siemensPhilipsCorrectBvecs(lDicomData,lDTIra,lDTIdir,false);
                    //next: philips scans can include DWI images with bval>0 and v1=0,v2=0,v3=0 - we want to exclude these
                    //for lIndex := lDTIdir downto 1 do
                    //    msg(inttostr(lIndex)+ kTab+floattostr(lDTIra[lIndex].bval)+kTab+floattostr(lDTIra[lIndex].v1)+kTab+floattostr(lDTIra[lIndex].v2)+kTab+floattostr(lDTIra[lIndex].v3));
diff --git a/dcm2nii_prePARRECDTI/dcm2nii.app/Contents/Info.plist b/dcm2nii/dcm2niigui.app/Contents/Info.plist
old mode 100755
new mode 100644
similarity index 91%
rename from dcm2nii_prePARRECDTI/dcm2nii.app/Contents/Info.plist
rename to dcm2nii/dcm2niigui.app/Contents/Info.plist
index f964ff6..327b516
--- a/dcm2nii_prePARRECDTI/dcm2nii.app/Contents/Info.plist
+++ b/dcm2nii/dcm2niigui.app/Contents/Info.plist
@@ -5,11 +5,11 @@
   <key>CFBundleDevelopmentRegion</key>
   <string>English</string>
   <key>CFBundleExecutable</key>
-  <string>dcm2nii</string>
+  <string>dcm2niigui</string>
   <key>CFBundleName</key>
-  <string>dcm2nii</string>
+  <string>dcm2niigui.exe</string>
   <key>CFBundleIdentifier</key>
-  <string>com.company.dcm2nii</string>
+  <string>com.company.dcm2niigui</string>
   <key>CFBundleInfoDictionaryVersion</key>
   <string>6.0</string>
   <key>CFBundlePackageType</key>
diff --git a/dcm2nii/dcm2niigui.app/Contents/MacOS/dcm2niigui b/dcm2nii/dcm2niigui.app/Contents/MacOS/dcm2niigui
new file mode 120000
index 0000000..eb6cf9b
--- /dev/null
+++ b/dcm2nii/dcm2niigui.app/Contents/MacOS/dcm2niigui
@@ -0,0 +1 @@
+../../../dcm2niigui
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/dcm2nii.app/Contents/PkgInfo b/dcm2nii/dcm2niigui.app/Contents/PkgInfo
old mode 100755
new mode 100644
similarity index 100%
rename from dcm2nii_prePARRECDTI/dcm2nii.app/Contents/PkgInfo
rename to dcm2nii/dcm2niigui.app/Contents/PkgInfo
diff --git a/dcm2nii/dcm2niigui.lpi b/dcm2nii/dcm2niigui.lpi
index 3518472..10d105b 100755
--- a/dcm2nii/dcm2niigui.lpi
+++ b/dcm2nii/dcm2niigui.lpi
@@ -33,14 +33,14 @@
         <PackageName Value="LCL"/>
       </Item1>
     </RequiredPackages>
-    <Units Count="52">
+    <Units Count="25">
       <Unit0>
         <Filename Value="dcm2niigui.lpr"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="dcm2niigui"/>
         <TopLine Value="1"/>
         <CursorPos X="2" Y="1"/>
-        <UsageCount Value="167"/>
+        <UsageCount Value="206"/>
       </Unit0>
       <Unit1>
         <Filename Value="gui.pas"/>
@@ -52,16 +52,10 @@
         <WindowIndex Value="0"/>
         <TopLine Value="955"/>
         <CursorPos X="26" Y="961"/>
-        <UsageCount Value="167"/>
+        <UsageCount Value="206"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
       </Unit1>
       <Unit2>
-        <Filename Value="dcm2niigui.lrs"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="1"/>
-        <UsageCount Value="10"/>
-      </Unit2>
-      <Unit3>
         <Filename Value="nifti_form.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="NIfTIForm"/>
@@ -71,562 +65,340 @@
         <WindowIndex Value="0"/>
         <TopLine Value="66"/>
         <CursorPos X="26" Y="73"/>
-        <UsageCount Value="167"/>
+        <UsageCount Value="206"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit3>
-      <Unit4>
+      </Unit2>
+      <Unit3>
         <Filename Value="pref_form.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="PrefsForm"/>
         <HasResources Value="True"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="pref_form"/>
-        <EditorIndex Value="7"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="69"/>
-        <CursorPos X="33" Y="82"/>
-        <UsageCount Value="167"/>
-        <Loaded Value="True"/>
+        <TopLine Value="132"/>
+        <CursorPos X="34" Y="158"/>
+        <UsageCount Value="206"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit4>
-      <Unit5>
-        <Filename Value="parconvert.pas"/>
-        <UnitName Value="parconvert"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="128" Y="6"/>
-        <UsageCount Value="16"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit5>
-      <Unit6>
-        <Filename Value="pref_form.lrs"/>
-        <TopLine Value="1"/>
-        <CursorPos X="4" Y="36"/>
-        <UsageCount Value="1"/>
-      </Unit6>
-      <Unit7>
-        <Filename Value="..\..\lcl\lresources.pp"/>
-        <UnitName Value="LResources"/>
-        <TopLine Value="2628"/>
-        <CursorPos X="21" Y="2642"/>
-        <UsageCount Value="10"/>
-      </Unit7>
-      <Unit8>
-        <Filename Value="dialogsx.pas"/>
-        <UnitName Value="dialogsx"/>
-        <TopLine Value="1"/>
-        <CursorPos X="33" Y="9"/>
-        <UsageCount Value="1"/>
-      </Unit8>
-      <Unit9>
-        <Filename Value="readint.pas"/>
-        <UnitName Value="readint"/>
-        <TopLine Value="1"/>
-        <CursorPos X="15" Y="7"/>
-        <UsageCount Value="1"/>
-      </Unit9>
-      <Unit10>
-        <Filename Value="readint.lrs"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="1"/>
-        <UsageCount Value="1"/>
-      </Unit10>
-      <Unit11>
-        <Filename Value="usr\local\share\lazarus\lcl\nonwin32\messages.pp"/>
-        <UnitName Value="Messages"/>
-        <TopLine Value="1"/>
-        <CursorPos X="90" Y="12"/>
-        <UsageCount Value="10"/>
-      </Unit11>
-      <Unit12>
-        <Filename Value="define_types.pas"/>
-        <UnitName Value="define_types"/>
-        <TopLine Value="1"/>
-        <CursorPos X="40" Y="2"/>
-        <UsageCount Value="1"/>
-      </Unit12>
-      <Unit13>
-        <Filename Value="paramstrs.pas"/>
-        <UnitName Value="paramstrs"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="316"/>
-        <CursorPos X="16" Y="342"/>
-        <UsageCount Value="16"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit13>
-      <Unit14>
+      </Unit3>
+      <Unit4>
         <Filename Value="niftiutil.pas"/>
         <UnitName Value="niftiutil"/>
-        <EditorIndex Value="9"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="992"/>
+        <TopLine Value="993"/>
         <CursorPos X="13" Y="1001"/>
-        <UsageCount Value="41"/>
-        <Loaded Value="True"/>
+        <UsageCount Value="77"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit14>
-      <Unit15>
+      </Unit4>
+      <Unit5>
         <Filename Value="prefs.pas"/>
         <UnitName Value="prefs"/>
-        <EditorIndex Value="8"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="74" Y="22"/>
-        <UsageCount Value="46"/>
-        <Loaded Value="True"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit15>
-      <Unit16>
-        <Filename Value="dicom.pas"/>
-        <UnitName Value="dicom"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="23" Y="6"/>
-        <UsageCount Value="11"/>
+        <TopLine Value="229"/>
+        <CursorPos X="90" Y="240"/>
+        <UsageCount Value="105"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit16>
-      <Unit17>
+      </Unit5>
+      <Unit6>
         <Filename Value="dicomtypes.pas"/>
         <UnitName Value="dicomtypes"/>
-        <EditorIndex Value="6"/>
+        <EditorIndex Value="4"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="68" Y="59"/>
-        <UsageCount Value="60"/>
+        <TopLine Value="655"/>
+        <CursorPos X="48" Y="673"/>
+        <UsageCount Value="104"/>
         <Loaded Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit17>
-      <Unit18>
-        <Filename Value="filename.pas"/>
-        <UnitName Value="filename"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="120"/>
-        <CursorPos X="41" Y="133"/>
-        <UsageCount Value="6"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit18>
-      <Unit19>
-        <Filename Value="userdir.pas"/>
-        <UnitName Value="userdir"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="3"/>
-        <UsageCount Value="2"/>
-      </Unit19>
-      <Unit20>
-        <Filename Value="gzio2.pas"/>
-        <UnitName Value="gzio2"/>
-        <TopLine Value="762"/>
-        <CursorPos X="26" Y="788"/>
-        <UsageCount Value="10"/>
-      </Unit20>
-      <Unit21>
-        <Filename Value="nii_crop.pas"/>
-        <UnitName Value="nii_crop"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="31" Y="26"/>
-        <UsageCount Value="5"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit21>
-      <Unit22>
-        <Filename Value="..\common\userdir.pas"/>
-        <UnitName Value="userdir"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="15"/>
-        <UsageCount Value="6"/>
-      </Unit22>
-      <Unit23>
+      </Unit6>
+      <Unit7>
         <Filename Value="..\common\define_types.pas"/>
         <UnitName Value="define_types"/>
-        <EditorIndex Value="3"/>
+        <EditorIndex Value="2"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="51"/>
-        <CursorPos X="21" Y="67"/>
-        <UsageCount Value="55"/>
+        <TopLine Value="1"/>
+        <CursorPos X="26" Y="23"/>
+        <UsageCount Value="113"/>
         <Loaded Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit23>
-      <Unit24>
-        <Filename Value="..\common\gziod.pas"/>
-        <UnitName Value="gziod"/>
-        <TopLine Value="311"/>
-        <CursorPos X="98" Y="322"/>
-        <UsageCount Value="10"/>
-      </Unit24>
-      <Unit25>
+      </Unit7>
+      <Unit8>
         <Filename Value="convert.pas"/>
         <UnitName Value="convert"/>
-        <IsVisibleTab Value="True"/>
-        <EditorIndex Value="2"/>
+        <EditorIndex Value="0"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="1309"/>
-        <CursorPos X="42" Y="1313"/>
-        <UsageCount Value="69"/>
+        <TopLine Value="1595"/>
+        <CursorPos X="93" Y="1608"/>
+        <UsageCount Value="115"/>
         <Loaded Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit25>
-      <Unit26>
+      </Unit8>
+      <Unit9>
         <Filename Value="..\common\gzio2.pas"/>
         <UnitName Value="gzio2"/>
-        <EditorIndex Value="0"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="53"/>
-        <CursorPos X="1" Y="71"/>
-        <UsageCount Value="43"/>
-        <Loaded Value="True"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit26>
-      <Unit27>
-        <Filename Value="nii_asl.pas"/>
-        <UnitName Value="nii_asl"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="525"/>
-        <CursorPos X="42" Y="539"/>
-        <UsageCount Value="6"/>
+        <TopLine Value="1"/>
+        <CursorPos X="114" Y="1"/>
+        <UsageCount Value="82"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit27>
-      <Unit28>
+      </Unit9>
+      <Unit10>
         <Filename Value="..\common\GraphicsMathLibrary.pas"/>
         <UnitName Value="GraphicsMathLibrary"/>
-        <EditorIndex Value="4"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="809"/>
-        <CursorPos X="11" Y="825"/>
-        <UsageCount Value="32"/>
-        <Loaded Value="True"/>
+        <TopLine Value="592"/>
+        <CursorPos X="27" Y="585"/>
+        <UsageCount Value="113"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit28>
-      <Unit29>
+      </Unit10>
+      <Unit11>
         <Filename Value="..\common\dialogsx.pas"/>
         <UnitName Value="dialogsx"/>
         <WindowIndex Value="0"/>
         <TopLine Value="53"/>
         <CursorPos X="52" Y="60"/>
-        <UsageCount Value="27"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit29>
-      <Unit30>
-        <Filename Value="LibTar.pas"/>
-        <UnitName Value="LibTar"/>
-        <TopLine Value="246"/>
-        <CursorPos X="35" Y="272"/>
-        <UsageCount Value="10"/>
-      </Unit30>
-      <Unit31>
-        <Filename Value="untar.pas"/>
-        <UnitName Value="untar"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="44" Y="11"/>
-        <UsageCount Value="5"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit31>
-      <Unit32>
-        <Filename Value="dicomfastread.pas"/>
-        <UnitName Value="dicomfastread"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="418"/>
-        <CursorPos X="57" Y="431"/>
-        <UsageCount Value="14"/>
+        <UsageCount Value="7"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit32>
-      <Unit33>
+      </Unit11>
+      <Unit12>
         <Filename Value="dicomcompat.pas"/>
         <UnitName Value="dicomcompat"/>
-        <EditorIndex Value="10"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="4784"/>
-        <CursorPos X="42" Y="4799"/>
-        <UsageCount Value="70"/>
-        <Loaded Value="True"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit33>
-      <Unit34>
-        <Filename Value="lsjpeg.pas"/>
-        <UnitName Value="lsjpeg"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="22" Y="10"/>
-        <UsageCount Value="8"/>
+        <TopLine Value="5360"/>
+        <CursorPos X="77" Y="5365"/>
+        <UsageCount Value="114"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit34>
-      <Unit35>
+      </Unit12>
+      <Unit13>
         <Filename Value="sortdicom.pas"/>
         <UnitName Value="sortdicom"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="93" Y="7"/>
-        <UsageCount Value="8"/>
+        <TopLine Value="180"/>
+        <CursorPos X="50" Y="189"/>
+        <UsageCount Value="49"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit35>
-      <Unit36>
+      </Unit13>
+      <Unit14>
         <Filename Value="philips_bvec.pas"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="philips_bvec"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="187"/>
-        <CursorPos X="38" Y="199"/>
-        <UsageCount Value="122"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit36>
-      <Unit37>
-        <Filename Value="nii_orient.pas"/>
-        <UnitName Value="nii_orient"/>
-        <WindowIndex Value="0"/>
         <TopLine Value="1"/>
-        <CursorPos X="83" Y="9"/>
-        <UsageCount Value="5"/>
+        <CursorPos X="117" Y="248"/>
+        <UsageCount Value="214"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit37>
-      <Unit38>
-        <Filename Value="gui.lrs"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="3"/>
-        <UsageCount Value="2"/>
-      </Unit38>
-      <Unit39>
-        <Filename Value="nii_math.pas"/>
-        <UnitName Value="nii_math"/>
-        <TopLine Value="576"/>
-        <CursorPos X="78" Y="592"/>
-        <UsageCount Value="2"/>
-      </Unit39>
-      <Unit40>
-        <Filename Value="C:\Documents and Settings\chris\Desktop\scripter\unit1.pas"/>
-        <ComponentName Value="Form1"/>
-        <ResourceBaseClass Value="Form"/>
-        <UnitName Value="Unit1"/>
-        <TopLine Value="34"/>
-        <CursorPos X="1" Y="35"/>
-        <UsageCount Value="12"/>
-      </Unit40>
-      <Unit41>
-        <Filename Value="..\common\nifti_hdr.pas"/>
-        <UnitName Value="nifti_hdr"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="3"/>
-        <CursorPos X="94" Y="9"/>
-        <UsageCount Value="7"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit41>
-      <Unit42>
+      </Unit14>
+      <Unit15>
         <Filename Value="..\common\isgui.inc"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="10" Y="1"/>
-        <UsageCount Value="22"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit42>
-      <Unit43>
+      </Unit15>
+      <Unit16>
         <Filename Value="csaread.pas"/>
         <UnitName Value="csaread"/>
-        <EditorIndex Value="5"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="376"/>
-        <CursorPos X="20" Y="384"/>
-        <UsageCount Value="58"/>
-        <Loaded Value="True"/>
+        <TopLine Value="41"/>
+        <CursorPos X="31" Y="53"/>
+        <UsageCount Value="104"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit43>
-      <Unit44>
+      </Unit16>
+      <Unit17>
         <Filename Value="dialogs_msg.pas"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="dialogs_msg"/>
         <WindowIndex Value="0"/>
         <TopLine Value="7"/>
         <CursorPos X="11" Y="9"/>
-        <UsageCount Value="86"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit44>
-      <Unit45>
-        <Filename Value="nii_4dto3d.pas"/>
-        <UnitName Value="nii_4dto3d"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="26" Y="19"/>
-        <UsageCount Value="5"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit45>
-      <Unit46>
-        <Filename Value="convertsimple.pas"/>
-        <UnitName Value="convertsimple"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="26" Y="11"/>
-        <UsageCount Value="5"/>
+        <UsageCount Value="208"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit46>
-      <Unit47>
-        <Filename Value="dicomfast.pas"/>
-        <UnitName Value="dicomfast"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="56" Y="21"/>
-        <UsageCount Value="5"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit47>
-      <Unit48>
-        <Filename Value="nii_reslice.pas"/>
-        <UnitName Value="nii_reslice"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="65" Y="5"/>
-        <UsageCount Value="5"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit48>
-      <Unit49>
-        <Filename Value="nii_3dto4d.pas"/>
-        <UnitName Value="nii_3dto4d"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="71" Y="9"/>
-        <UsageCount Value="5"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit49>
-      <Unit50>
+      </Unit17>
+      <Unit18>
         <Filename Value="..\common\nifti_types.pas"/>
         <UnitName Value="nifti_types"/>
-        <EditorIndex Value="1"/>
         <WindowIndex Value="0"/>
         <TopLine Value="72"/>
         <CursorPos X="72" Y="86"/>
-        <UsageCount Value="37"/>
-        <Loaded Value="True"/>
+        <UsageCount Value="100"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit50>
-      <Unit51>
+      </Unit18>
+      <Unit19>
         <Filename Value="..\common\nifti_foreign.pas"/>
         <UnitName Value="nifti_foreign"/>
-        <EditorIndex Value="11"/>
         <WindowIndex Value="0"/>
         <TopLine Value="416"/>
-        <CursorPos X="6" Y="420"/>
-        <UsageCount Value="37"/>
+        <CursorPos X="74" Y="419"/>
+        <UsageCount Value="73"/>
+        <DefaultSyntaxHighlighter Value="Delphi"/>
+      </Unit19>
+      <Unit20>
+        <Filename Value="parconvert.pas"/>
+        <UnitName Value="parconvert"/>
+        <IsVisibleTab Value="True"/>
+        <EditorIndex Value="3"/>
+        <WindowIndex Value="0"/>
+        <TopLine Value="1127"/>
+        <CursorPos X="89" Y="1140"/>
+        <UsageCount Value="26"/>
+        <Loaded Value="True"/>
+        <DefaultSyntaxHighlighter Value="Delphi"/>
+      </Unit20>
+      <Unit21>
+        <Filename Value="bvec.pas"/>
+        <UnitName Value="bvec"/>
+        <EditorIndex Value="1"/>
+        <WindowIndex Value="0"/>
+        <TopLine Value="53"/>
+        <CursorPos X="46" Y="67"/>
+        <UsageCount Value="26"/>
         <Loaded Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit51>
+      </Unit21>
+      <Unit22>
+        <Filename Value="..\..\..\..\..\..\Developer\lazarus\lcl\include\customform.inc"/>
+        <WindowIndex Value="0"/>
+        <TopLine Value="2535"/>
+        <CursorPos X="60" Y="2545"/>
+        <UsageCount Value="24"/>
+      </Unit22>
+      <Unit23>
+        <Filename Value="..\..\..\..\..\..\Developer\lazarus\lcl\include\menuitem.inc"/>
+        <WindowIndex Value="0"/>
+        <TopLine Value="1"/>
+        <CursorPos X="50" Y="1"/>
+        <UsageCount Value="8"/>
+      </Unit23>
+      <Unit24>
+        <Filename Value="dicom.pas"/>
+        <UnitName Value="dicom"/>
+        <WindowIndex Value="0"/>
+        <TopLine Value="1"/>
+        <CursorPos X="29" Y="6"/>
+        <UsageCount Value="10"/>
+        <DefaultSyntaxHighlighter Value="Delphi"/>
+      </Unit24>
     </Units>
     <JumpHistory Count="30" HistoryIndex="29">
       <Position1>
-        <Filename Value="dicomcompat.pas"/>
-        <Caret Line="5948" Column="93" TopLine="5947"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="143" Column="7" TopLine="123"/>
       </Position1>
       <Position2>
-        <Filename Value="dicomcompat.pas"/>
-        <Caret Line="131" Column="156" TopLine="131"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="148" Column="10" TopLine="128"/>
       </Position2>
       <Position3>
-        <Filename Value="dicomcompat.pas"/>
-        <Caret Line="1241" Column="39" TopLine="1223"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="3" Column="114" TopLine="1"/>
       </Position3>
       <Position4>
-        <Filename Value="dicomcompat.pas"/>
-        <Caret Line="1255" Column="22" TopLine="1237"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1116" Column="42" TopLine="1109"/>
       </Position4>
       <Position5>
-        <Filename Value="dicomcompat.pas"/>
-        <Caret Line="1257" Column="47" TopLine="1239"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1117" Column="34" TopLine="1109"/>
       </Position5>
       <Position6>
-        <Filename Value="dicomcompat.pas"/>
-        <Caret Line="1258" Column="86" TopLine="1240"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1123" Column="129" TopLine="1109"/>
       </Position6>
       <Position7>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="1005" Column="77" TopLine="996"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1277" Column="97" TopLine="1258"/>
       </Position7>
       <Position8>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="3" Column="140" TopLine="1"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1279" Column="103" TopLine="1260"/>
       </Position8>
       <Position9>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="1002" Column="51" TopLine="995"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1280" Column="63" TopLine="1269"/>
       </Position9>
       <Position10>
-        <Filename Value="convert.pas"/>
-        <Caret Line="3" Column="138" TopLine="1"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1281" Column="57" TopLine="1269"/>
       </Position10>
       <Position11>
-        <Filename Value="convert.pas"/>
-        <Caret Line="125" Column="137" TopLine="123"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1060" Column="57" TopLine="1056"/>
       </Position11>
       <Position12>
-        <Filename Value="convert.pas"/>
-        <Caret Line="1144" Column="24" TopLine="1134"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1050" Column="29" TopLine="1049"/>
       </Position12>
       <Position13>
-        <Filename Value="convert.pas"/>
-        <Caret Line="1155" Column="7" TopLine="1141"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1105" Column="17" TopLine="1086"/>
       </Position13>
       <Position14>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="170" Column="138" TopLine="168"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1108" Column="35" TopLine="1089"/>
       </Position14>
       <Position15>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="5" Column="136" TopLine="1"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1110" Column="36" TopLine="1091"/>
       </Position15>
       <Position16>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="929" Column="21" TopLine="905"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1111" Column="43" TopLine="1092"/>
       </Position16>
       <Position17>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="976" Column="39" TopLine="953"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1113" Column="16" TopLine="1094"/>
       </Position17>
       <Position18>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="978" Column="53" TopLine="955"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1120" Column="29" TopLine="1109"/>
       </Position18>
       <Position19>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="981" Column="20" TopLine="959"/>
+        <Filename Value="bvec.pas"/>
+        <Caret Line="74" Column="12" TopLine="50"/>
       </Position19>
       <Position20>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="1003" Column="25" TopLine="991"/>
+        <Filename Value="convert.pas"/>
+        <Caret Line="1611" Column="44" TopLine="1587"/>
       </Position20>
       <Position21>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="1002" Column="92" TopLine="991"/>
+        <Filename Value="convert.pas"/>
+        <Caret Line="67" Column="108" TopLine="66"/>
       </Position21>
       <Position22>
-        <Filename Value="csaread.pas"/>
-        <Caret Line="15" Column="28" TopLine="6"/>
+        <Filename Value="convert.pas"/>
+        <Caret Line="242" Column="51" TopLine="223"/>
       </Position22>
       <Position23>
-        <Filename Value="csaread.pas"/>
-        <Caret Line="203" Column="9" TopLine="197"/>
+        <Filename Value="convert.pas"/>
+        <Caret Line="397" Column="40" TopLine="375"/>
       </Position23>
       <Position24>
         <Filename Value="convert.pas"/>
-        <Caret Line="1135" Column="30" TopLine="1130"/>
+        <Caret Line="1181" Column="29" TopLine="1176"/>
       </Position24>
       <Position25>
         <Filename Value="convert.pas"/>
-        <Caret Line="13" Column="62" TopLine="1"/>
+        <Caret Line="1182" Column="19" TopLine="1176"/>
       </Position25>
       <Position26>
         <Filename Value="convert.pas"/>
-        <Caret Line="1098" Column="26" TopLine="1099"/>
+        <Caret Line="1199" Column="30" TopLine="1181"/>
       </Position26>
       <Position27>
         <Filename Value="convert.pas"/>
-        <Caret Line="1159" Column="21" TopLine="1147"/>
+        <Caret Line="1282" Column="29" TopLine="1260"/>
       </Position27>
       <Position28>
         <Filename Value="convert.pas"/>
-        <Caret Line="1162" Column="16" TopLine="1153"/>
+        <Caret Line="1370" Column="65" TopLine="1348"/>
       </Position28>
       <Position29>
-        <Filename Value="convert.pas"/>
-        <Caret Line="1175" Column="79" TopLine="1153"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1282" Column="64" TopLine="1272"/>
       </Position29>
       <Position30>
-        <Filename Value="csaread.pas"/>
-        <Caret Line="262" Column="69" TopLine="259"/>
+        <Filename Value="parconvert.pas"/>
+        <Caret Line="1024" Column="61" TopLine="1021"/>
       </Position30>
     </JumpHistory>
   </ProjectOptions>
diff --git a/dcm2nii/parconvert.pas b/dcm2nii/parconvert.pas
index 97e2377..2d25220 100755
--- a/dcm2nii/parconvert.pas
+++ b/dcm2nii/parconvert.pas
@@ -2,12 +2,12 @@ unit parconvert;
 {$H+}
 interface
 uses
-{$IFDEF FPC}gzio2, {$ENDIF}
-define_types,SysUtils,dicom,dicomtypes,filename,nii_4dto3d,niftiutil,nii_orient, nii_crop,GraphicsMathLibrary,prefs,dialogs_msg, nifti_types;
+{$IFDEF FPC}gzio2, {$ELSE} gziod,{$ENDIF}
+math, bvec,define_types,SysUtils,dicom,dicomtypes,filename,nii_4dto3d,niftiutil,nii_orient, nii_crop,GraphicsMathLibrary,prefs,dialogs_msg, nifti_types;
 
 function LoadFileListPARREC  (var lInFilename, lOutDir: string; var lPrefs: TPrefs): boolean;
 implementation
-uses dialogsx, philips_bvec;
+uses dialogsx;
 
 
 procedure PAR2DICOMstudyDate(var lDicomData: DICOMdata);
@@ -133,7 +133,7 @@ end;
     ELSE dcmMsg('MultiplyMatrices error: '+inttostr(a.size)+' <> '+inttostr(b.size))
   END {MultiplyMatrices};
 
-  function RealToStr(lR: double {was extended}; lDec: integer): string;
+ (* function RealToStr(lR: double {was extended}; lDec: integer): string;
 begin
 	 RealTOStr := FloatToStrF(lR, ffFixed,7,lDec);
 end;
@@ -145,7 +145,7 @@ begin
 	dcmMsg(	RealToStr(lM.matrix[2,1],6)+','+RealToStr(lM.matrix[2,2],6)+','+RealToStr(lM.matrix[2,3],6)+','+RealToStr(lM.matrix[2,4],6));
 	dcmMsg(	RealToStr(lM.matrix[3,1],6)+','+RealToStr(lM.matrix[3,2],6)+','+RealToStr(lM.matrix[3,3],6)+','+RealToStr(lM.matrix[3,4],6));
 	dcmMsg(	RealToStr(lM.matrix[4,1],6)+','+RealToStr(lM.matrix[4,2],6)+','+RealToStr(lM.matrix[4,3],6)+','+RealToStr(lM.matrix[4,4],6));
-end;
+end;   *)
 
 FUNCTION Diag3D (CONST m1,m2,m3,m4:  DOUBLE):  TMatrix;
   BEGIN
@@ -384,7 +384,7 @@ begin
 end;// funct DTItextfiles
 
 
-procedure read_PAR2NII(var lNHdr: TNIftIHdr; var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK,lPrecise:boolean;  var lDynStr: string;var lFileName: string; lReadOffsetTables: boolean; var lOffset_pos_table: LongIntp; var lOffsetTableEntries,lRescaleEntries: integer;  var lSlopeRA,lInterceptRA: Singlep; var lnum4Ddatasets: integer; var lDTIra: TDTIra);
+procedure read_PAR2NII(var lNHdr: TNIftIHdr; var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK,lPrecise:boolean;  var lDynStr: string;var lFileName: string; lReadOffsetTables: boolean; var lOffset_pos_table: LongIntp; var lOffsetTableEntries,lRescaleEntries: integer;  var lSlopeRA,lInterceptRA: Singlep; var lnum4Ddatasets, lSliceOrient: integer; var lDTIra: TDTIra);
 label 333; //1384 now reads up to 8 dimensional data....
 type tRange = record
      Min,Val,Max: double; //some vals are ints, others floats
@@ -553,7 +553,7 @@ begin
               lIsParVers3 := false;
               lIsParVers41 := true;
               lIsParVers42 := true;
-              dcmMsg('PAR v4.2 : DTI bval/bvec support still experimental')
+              //dcmMsg('PAR v4.2 : DTI bval/bvec support still experimental')
            end else
                dcmMsg('Warning: unknown PAR version '+lUpCaseStr);
 
@@ -685,12 +685,14 @@ begin
                               for lHdrPos := 48 to 49 do
 				lSliceHeaderRA[lHdrPos] := readparfloat;
                               //fx(lSliceInfoCount,lSliceHeaderRA[46],lSliceHeaderRA[47],lSliceHeaderRA[48]);
+                              lSliceOrient :=  round(lSliceHeaderRA[26]);
                               lDTIraDyn[lSliceInfoCount].bval := round(lSliceHeaderRA[34]);
                               //# diffusion (ap, fh, rl) (3*float) 46=AP=Y,47=FH=Z,48=RL=X
                               lDTIraDyn[lSliceInfoCount].v1 := lSliceHeaderRA[48];
                               lDTIraDyn[lSliceInfoCount].v2 := lSliceHeaderRA[46];
                               lDTIraDyn[lSliceInfoCount].v3 := lSliceHeaderRA[47];
                               MinMaxTRange(lRangeRA[kCardiac], ({cardiac}lSliceHeaderRA[49]*100)+ ({asl}lSliceHeaderRA[4]) );
+
                            end; //PAR42
 
                         end; //PAR41
@@ -977,17 +979,82 @@ begin
       lInStr := lPathWName+chr(lInc)+lExt;
 end;
 
+type
+TiVec = array[1..3] of integer;
+const
+     kSliceOrientTra = 1;
+     kSliceOrientSag = 2;
+     kSliceOrientCor = 3;
+
+procedure nifti_mat33_reorder_cols(var  m: TMatrix; v: TiVec ) ;
+var
+  inMat : TMatrix;
+  r,c: integer;
+begin
+    // matlab equivalent ret = m(:, v); where v is 1,2,3 [INDEXED FROM ONE!!!!]
+    InMat := m;
+    for r := 1 to 3 do
+        for c := 1 to 3 do
+            m.matrix[r,c] := InMat.matrix[r,v[c]];
+//v[c]
+
+end; //nifti_mat33_reorder_cols()
+
+procedure computeOrient(var d: dicomdata; lSliceOrients: integer);
+var
+  ang1, ang2,ang3: double;
+  ca, sa: TVector;
+  rx,ry,rz,R: TMatrix;
+  row,col: integer;
+  ixyz: TiVec;
+begin
+ //see Xiangrui Li 's dicm2nii (also BSD license)
+    // http://www.mathworks.com/matlabcentral/fileexchange/42997-dicom-to-nifti-converter
+    // Rotation order and signs are figured out by try and err, not 100% sure
+    ang1 := d.AngulationRL;
+    ang2 := d.AngulationAP;
+    ang3 := d.AngulationFH;
+    ca := Vector3D(cos(DegToRad(ang1)),cos(DegToRad(ang2)),cos(DegToRad(ang3)));
+    sa := Vector3D(sin(DegToRad(ang1)),sin(DegToRad(ang2)),sin(DegToRad(ang3)));
+
+    rx := Matrix2D(1.0, 0.0, 0.0, 0.0, ca.vector[1], -sa.vector[1], 0.0, sa.vector[1], ca.vector[1]);
+    ry := Matrix2D(ca.vector[2], 0.0, sa.vector[2], 0.0, 1.0, 0.0, -sa.vector[2], 0.0, ca.vector[2]);
+    rz := Matrix2D(ca.vector[3], -sa.vector[3], 0.0, sa.vector[3], ca.vector[3], 0.0, 0.0, 0.0, 1.0);
+    R := MultiplyMatrices(rx,ry );
+    R := MultiplyMatrices(R,rz );
+    //ReportMatrix('mult',R);
+    ixyz[1]:= 1; ixyz[2] := 2; ixyz[3] := 3; //axial slice order ijk = xyz
+    if (lSliceOrients = kSliceOrientSag) then begin//(d.sliceOrient == kSliceOrientSag) {
+            ixyz[1]:= 2; ixyz[2] := 3; ixyz[3] := 1;
+            for row := 1 to 3 do
+                for col := 1 to 3 do begin
+                    if (col <> 2) then
+                       R.matrix[row,col] :=  -R.matrix[row,col]; //invert first and final columns
+                end;
+            nifti_mat33_reorder_cols(R,ixyz);
+    end else if (lSliceOrients = kSliceOrientCor) then begin //(d.sliceOrient == kSliceOrientCor) {
+             ixyz[1]:= 1; ixyz[2] := 3; ixyz[3] := 2;
+             for row := 1 to 3 do
+                 R.matrix[row,3] :=  -R.matrix[row,3];
+             nifti_mat33_reorder_cols(R,ixyz);
+    end;
+    d.orient[1] := R.matrix[1,1]; d.orient[2] := R.matrix[2,1]; d.orient[3] := R.matrix[3,1];
+    d.orient[4] := R.matrix[1,2]; d.orient[5] := R.matrix[2,2]; d.orient[6] := R.matrix[3,2];
+    //ReportMatrix('x',R);
+    //dcmmsg(Format('v = %g %g %g %g %g %g', [d.Orient[1], d.Orient[2], d.Orient[3], d.Orient[4], d.Orient[5], d.Orient[6] ])) ;
+ end;
+
 function ConvertPhilipsPARtoAnalyze (var lInFilename, lOutDir: string; var lPrefs: TPrefs): boolean;
 label
 	 678;
 var
    //lVaryingScaleFactorsTableEntries,
    lLines,lColBytes,lRows,lRowsdiv2,lSwap,lInc,l4Doffset,lcurrent4Dvol,lnum4Ddatasets,lSlicePixelsx, lnSlicesx,
-   lSliceSzOutx,lSLiceSzx,lRescaleEntries, lPos,lOffsetTableEntries: longint;
+   lSliceSzOutx,lSLiceSzx,lRescaleEntries, lPos,lOffsetTableEntries,lSliceOrient: longint;
    lOutF,lInF: File;
    lNHdr,lAHdr: TNIFTIhdr;
    lP,lBuffer : Bytep;
-   lFileName,lRECFilename,lOutImgName,lOutHdrName,lDynStr,lOutDirPath: String;
+   lFileName,lRECFilename,lOutImgName,lOutHdrName,lOutHdrNameGz,lDynStr,lOutDirPath: String;
    lDICOMdata: dicomdata;
    lScaleFactorVariesInThis4DVolume,lAbort,lHdrOK, lImageFormatOK: boolean;
    lSlopeRA,lInterceptRA,
@@ -996,6 +1063,7 @@ var
    lDTIra: TDTIra;
 begin
      result := false;
+     lSliceOrient := kSliceOrientTra;
      lFileName := lInFilename;
   if (lOutDir = '') then
 	lOutDirPath := ExtractFilePath(lFileName)//ExtractFileDirWithPathDelim(lFilename)//ExtractFilePath(lFileName)
@@ -1017,7 +1085,7 @@ begin
 	if not fileexists(lRecFilename) then
 		dcmMsg('Unable to find REC image data file named '+lRecFileName)
 	else if fileexists(lRecFilename) and fileexists(lFilename) then begin //convert
-		read_par2NII(lNHdr,lDICOMdata,lHdrOK,lImageFormatOK,lPRefs.PhilipsPrecise, lDynStr,lFileName,true,lOffset_pos_table,lOffsetTableEntries,lRescaleEntries, lSlopeRA,lInterceptRA,lnum4Ddatasets,lDTIra);
+		read_par2NII(lNHdr,lDICOMdata,lHdrOK,lImageFormatOK,lPRefs.PhilipsPrecise, lDynStr,lFileName,true,lOffset_pos_table,lOffsetTableEntries,lRescaleEntries, lSlopeRA,lInterceptRA,lnum4Ddatasets,lSliceOrient,lDTIra);
 	 if (lnum4Ddatasets > 1) and ((lDicomData.XYZdim[4] mod lnum4Ddatasets) = 0) then  //break 5D files into separate 4D files
 		lDicomData.XYZdim[4] := lDicomData.XYZdim[4] div lnum4Ddatasets
 	 else
@@ -1046,9 +1114,9 @@ begin
 				lOutImgName := lOutHdrName;
 			end;
 	if (lPrefs.SingleNIIFile) and (lPrefs.GZip) then begin
-		lOutHdrName := lOutHdrName+'.gz';
-		if (not UniqueFileName(lOutHdrName))  then begin
-			dcmMsg('File already exists '+lOutImgName+' '+lOutHdrName);
+		lOutHdrNameGz := lOutHdrName+'.gz';
+		if (not UniqueFileName(lOutHdrNameGz))  then begin
+			dcmMsg('File already exists '+lOutImgName+' '+lOutHdrNameGz);
 			exit;
 		end;
 
@@ -1068,7 +1136,8 @@ begin
            while (lInc <= lDicomData.XYZdim[4]) and (lDTIra[lInc].bval = lDTIra[1].bval) and (lDTIra[lInc].v1 = lDTIra[1].v1) do
                  inc(lInc);
            if (lInc <= lDicomData.XYZdim[4]) then begin//bvec or bval vary
-              PhilipsCorrectBvecs(lDICOMdata, lDTIra, lDicomData.XYZdim[4]);
+              computeOrient(lDICOMData,lSliceOrient);
+              siemensPhilipsCorrectBvecs(lDICOMdata, lDTIra, lDicomData.XYZdim[4], false);
               DTItextfiles (lOutImgName, lDTIra, lDicomData.XYZdim[4]);
            end;
         end; //if 4D: save DTI data
@@ -1208,10 +1277,10 @@ begin
                 //   Clip4D(lOutHdrName, lAHdr, false,lPrefs.SPM2,lPrefs.SingleNIIFile,lPrefs.GZip,true, lPrefs.StartClip,lPrefs.EndClip);
                 (*if (not lPrefs.FourD) and (lAHdr.dim[4] > 1) then begin
                    Convert4Dto3D(lOutImgName, lAHdr, false,lPrefs.SPM2,lPrefs.SingleNIIFile, lPrefs.Gzip);
-                end else if lPrefs.SingleNIIFile and lPrefs.Gzip then
-                   GZipFile(lOutImgName,lOutImgName+'.gz',true);*)
-
-                if ((not lPrefs.FourD) and (lAHdr.dim[4] > 1)) {or ((lPrefs.SingleNIIFile) and (lPrefs.Gzip))} then
+                end else*)
+                if lPrefs.SingleNIIFile and lPrefs.Gzip then
+                   GZipFile(lOutImgName,lOutImgName+'.gz',true)
+                else if ((not lPrefs.FourD) and (lAHdr.dim[4] > 1)) {or ((lPrefs.SingleNIIFile) and (lPrefs.Gzip))} then
                    if ChangeNIfTISubformat(lOutImgName, lAHdr,lPrefs) then begin
                       deleteFile(lOutImgName);//11/2007 : delete original
                    end;
diff --git a/dcm2nii/philips_bvec.pas b/dcm2nii/philips_bvec_old.pas
similarity index 87%
rename from dcm2nii/philips_bvec.pas
rename to dcm2nii/philips_bvec_old.pas
index d18a2e9..4189b0b 100755
--- a/dcm2nii/philips_bvec.pas
+++ b/dcm2nii/philips_bvec_old.pas
@@ -12,6 +12,15 @@ procedure PhilipsCorrectBvecs(var lDICOMdata:dicomdata; var lDTIra: TDTIRA; nVec
 
 implementation
 
+procedure ReportMatrix(s: string; q: TMatrix);
+begin
+     dcmmsg(s+Format('=[ %g %g %g %g; %g %g %g %g; %g %g %g %g; 0 0 0 1]',  [
+     q.matrix[1,1],q.matrix[1,2],q.matrix[1,3],q.matrix[1,4]  ,
+     q.matrix[2,1],q.matrix[2,2],q.matrix[2,3],q.matrix[2,4] ,
+     q.matrix[3,1],q.matrix[3,2],q.matrix[3,3],q.matrix[3,4]]));
+end;
+
+
 //Next routines for PhilipsBVec
   FUNCTION Vector2D  (CONST xValue, yValue, zValue:  DOUBLE):  TVector;
   BEGIN
@@ -77,8 +86,8 @@ procedure PhilipsCorrectBvecs(var lDICOMdata:dicomdata; var lDTIra: TDTIRA; nVec
 //0018,5100. patient orientation - 'HFS'
 //2001,100B Philips slice orientation (TRANSVERSAL, AXIAL, SAGITTAL)
 //2005,1071. Philips AP angulation : -8.74086
-//2005,1072. Philips RL angulation : -3.53147
-//2005,1073. Philips FH angulation -0.387372
+//2005,1072. Philips FH angulation : -3.53147
+//2005,1073. Philips RL angulation -0.387372
 (* 3/2008: updated to correct for a bug in the Johns Hopkins code:
 % July 20, 2007 | I corrected a small bug with the rotation matrices for
 % slice angulation.  I had multiplied 3 matrices in the incorrect order.
@@ -165,6 +174,7 @@ FFS = Feet First-Supine
      end;
      lrev_tpo := revMat(ltpo);
      dcmMsg('Reorienting vectors for patient position ('+lDicomData.PatientPos+'). Please validate if you conduct DTI processing.');
+
      (*
     //Assume supine
     ltpo := Matrix2D (1,0,0,  0,1,0, 0,0,1  );
@@ -178,12 +188,13 @@ FFS = Feet First-Supine
     lfh := lDicomData.AngulationFH  * PI /180;
     lrl := lDicomData.AngulationRL  * PI /180;
     {$IFDEF  VERBOSE_BVEC}
-    msg('ap/fh/rl'+kTab+floattostr(lDicomData.AngulationAP)+kTab+floattostr(lDicomData.AngulationFH)+kTab+floattostr(lDicomData.AngulationRL));
+    dcmmsg('ap/fh/rl'+kTab+floattostr(lDicomData.AngulationAP)+kTab+floattostr(lDicomData.AngulationFH)+kTab+floattostr(lDicomData.AngulationRL));
     for lI := 1 to nVec do
-      msg(inttostr(lI)+ kTab+floattostr(lDTIra[lI].bval)+kTab+floattostr(lDTIra[lI].v1)+kTab+floattostr(lDTIra[lI].v2)+kTab+floattostr(lDTIra[lI].v3));
+      dcmmsg(inttostr(lI)+ kTab+floattostr(lDTIra[lI].bval)+kTab+floattostr(lDTIra[lI].v1)+kTab+floattostr(lDTIra[lI].v2)+kTab+floattostr(lDTIra[lI].v3));
 
     {$ENDIF}
     //lAP:=-0.152557;  lFH:=-0.0616358;  lRL := -0.00676092;
+     //dcmmsg('ap/fh/rl'+kTab+floattostr(lap)+kTab+floattostr(lfh)+kTab+floattostr(lrl));
 
     ltrl := Matrix2D (1,0,0,                0,cos(lrl),-sin(lrl),  0,sin(lrl),cos(lrl));
     ltap := Matrix2D (cos(lap),0,sin(lap),  0,1,0,                 -sin(lap),0,cos(lap));
@@ -192,6 +203,7 @@ FFS = Feet First-Supine
     lrev_tap := revMat(ltap);
     lrev_tfh := revMat(ltfh);
     lmtemp1 := MultiplyMatrices( ltrl, ltap );
+
     ltang := MultiplyMatrices( lmtemp1, ltfh );
     lmtemp1 := MultiplyMatrices( lrev_tfh, lrev_tap );
     lrev_tang := MultiplyMatrices( lmtemp1, lrev_trl );
@@ -205,9 +217,13 @@ FFS = Feet First-Supine
     ldtiextra := Matrix2D (0,-1,0,  -1,0,0, 0,0,1 );
     lmtemp2 := MultiplyMatrices( ldtiextra, lrev_tsom );
     lmtemp1 := MultiplyMatrices (lmtemp2, lrev_tang);
+    ReportMatrix('lmtemp1',lmtemp1);
 
     for lI := 1 to nVec do begin
+      {$IFDEF  VERBOSE_BVEC}
+      //dcmmsg(realtostr(lDTIra[lI].v1,5)+kTab+realtostr(lDTIra[lI].v2,5)+kTab+realtostr(lDTIra[lI].v3,5) );
 
+      {$ENDIF}
         if (lDTIra[lI].bval <= 0) or  ((lDTIra[lI].v1 = 0) and (lDTIra[lI].v2 = 0) and (lDTIra[lI].v3 = 0)) then begin
             lDTIra[lI].v1 := 0;
             lDTIra[lI].v2 := 0;
@@ -219,13 +235,17 @@ FFS = Feet First-Supine
             lout := VecMatMult (lin,lmtemp1);
             NormalizeVector(lout);
             lDTIra[lI].v1 := lOut.x;
+            lDTIra[lI].v2 := lOut.y;
+            {2014: dcm2nii flips physically images in AP direction, so do not change sign
             if lOut.y = 0 then
                 lDTIra[lI].v2 := lOut.y //people dislike seeing -0
             else
                 lDTIra[lI].v2 := -lOut.y; //flip Y component
+            }
             lDTIra[lI].v3 := lOut.z;
         end;
     end; //for each vector
+    dcmmsg('Note: dcm2nii since 2014 flips sign of DTI y-component for FSL tools. Please validate for yur system.');
 end;
 
 end.
diff --git a/dcm2nii/pref_form.dfm b/dcm2nii/pref_form.dfm
index d300a3e..7bf0b0c 100755
Binary files a/dcm2nii/pref_form.dfm and b/dcm2nii/pref_form.dfm differ
diff --git a/dcm2nii/pref_form.lfm b/dcm2nii/pref_form.lfm
index b4542d1..918de0e 100755
--- a/dcm2nii/pref_form.lfm
+++ b/dcm2nii/pref_form.lfm
@@ -1,7 +1,7 @@
 object PrefsForm: TPrefsForm
-  Left = 570
+  Left = 466
   Height = 332
-  Top = 216
+  Top = 176
   Width = 600
   HorzScrollBar.Page = 463
   VertScrollBar.Page = 323
@@ -17,29 +17,29 @@ object PrefsForm: TPrefsForm
   Position = poDesktopCenter
   LCLVersion = '1.0.12.0'
   object Label1: TLabel
-    Left = 120
+    Left = 112
     Height = 17
-    Top = 184
+    Top = 200
     Width = 188
     Caption = 'Recursive folder search depth'
     ParentColor = False
   end
   object OutDirLabel: TLabel
-    Left = 24
+    Left = 16
     Height = 17
-    Top = 256
+    Top = 264
     Width = 19
     Caption = 'c:\'
     ParentColor = False
   end
   object FilenameBox: TGroupBox
     Left = 8
-    Height = 160
+    Height = 176
     Top = 8
-    Width = 184
+    Width = 232
     Caption = 'Output Filename'
-    ClientHeight = 138
-    ClientWidth = 176
+    ClientHeight = 154
+    ClientWidth = 224
     TabOrder = 0
     object DateCheck: TCheckBox
       Left = 22
@@ -108,33 +108,33 @@ object PrefsForm: TPrefsForm
     TabOrder = 2
   end
   object NotAnonymizeCheck: TCheckBox
-    Left = 202
+    Left = 248
     Height = 18
-    Top = 16
+    Top = 24
     Width = 233
     Caption = 'Save patient name in NIfTI header'
     TabOrder = 3
   end
   object ReorientCheck: TCheckBox
-    Left = 202
+    Left = 248
     Height = 18
-    Top = 80
+    Top = 88
     Width = 336
     Caption = 'Reorient large images to nearest orthogonal plane'
     TabOrder = 4
   end
   object RecursiveSpin: TSpinEdit
-    Left = 24
+    Left = 16
     Height = 16
-    Top = 184
+    Top = 200
     Width = 77
     MaxValue = 10
     TabOrder = 5
   end
   object OutputCombo: TComboBox
-    Left = 24
+    Left = 16
     Height = 20
-    Top = 216
+    Top = 232
     Width = 296
     ItemHeight = 0
     Items.Strings = (
@@ -148,19 +148,19 @@ object PrefsForm: TPrefsForm
     TabOrder = 6
   end
   object CollapseCheck: TCheckBox
-    Left = 202
+    Left = 248
     Height = 18
     Hint = 'Sort images regardless of source directory. Slower, required if series segmented across folders'
-    Top = 112
+    Top = 120
     Width = 121
     Caption = 'Collapse folders'
     TabOrder = 7
   end
   object Stack3DImagesWithSameAcqNum: TCheckBox
-    Left = 202
+    Left = 248
     Height = 18
     Hint = 'Sort images regardless of source directory. Slower, required if series segmented across folders'
-    Top = 144
+    Top = 152
     Width = 314
     Caption = 'Stack 3D images with same acquistion number'
     TabOrder = 8
@@ -176,9 +176,9 @@ object PrefsForm: TPrefsForm
     TabOrder = 9
   end
   object WritePrefsOnQuit: TCheckBox
-    Left = 344
+    Left = 390
     Height = 18
-    Top = 112
+    Top = 120
     Width = 138
     Caption = 'Write prefs on quit'
     Checked = True
@@ -187,9 +187,9 @@ object PrefsForm: TPrefsForm
     Visible = False
   end
   object TxtReportCheck: TCheckBox
-    Left = 202
+    Left = 248
     Height = 18
-    Top = 48
+    Top = 56
     Width = 282
     Caption = 'Save text report (scan and patient details)'
     TabOrder = 11
diff --git a/dcm2nii/pref_form.lrs b/dcm2nii/pref_form.lrs
index c6cdb9f..273f533 100755
--- a/dcm2nii/pref_form.lrs
+++ b/dcm2nii/pref_form.lrs
@@ -1,19 +1,19 @@
 { This is an automatically generated lazarus resource file }
 
 LazarusResources.Add('TPrefsForm','FORMDATA',[
-  'TPF0'#10'TPrefsForm'#9'PrefsForm'#4'Left'#3':'#2#6'Height'#3'L'#1#3'Top'#3
-  +#216#0#5'Width'#3'X'#2#18'HorzScrollBar.Page'#3#207#1#18'VertScrollBar.Page'
+  'TPF0'#10'TPrefsForm'#9'PrefsForm'#4'Left'#3#210#1#6'Height'#3'L'#1#3'Top'#3
+  +#176#0#5'Width'#3'X'#2#18'HorzScrollBar.Page'#3#207#1#18'VertScrollBar.Page'
   +#3'C'#1#13'ActiveControl'#7#9'DateCheck'#11'BorderIcons'#11#12'biSystemMenu'
   +#0#7'Caption'#6#11'Preferences'#12'ClientHeight'#3'L'#1#11'ClientWidth'#3'X'
   +#2#21'Constraints.MaxHeight'#3'L'#1#20'Constraints.MaxWidth'#3'X'#2#21'Const'
   +'raints.MinHeight'#3'L'#1#20'Constraints.MinWidth'#3'X'#2#8'Position'#7#15'p'
   +'oDesktopCenter'#10'LCLVersion'#6#8'1.0.12.0'#0#6'TLabel'#6'Label1'#4'Left'#2
-  +'x'#6'Height'#2#17#3'Top'#3#184#0#5'Width'#3#188#0#7'Caption'#6#29'Recursive'
+  +'p'#6'Height'#2#17#3'Top'#3#200#0#5'Width'#3#188#0#7'Caption'#6#29'Recursive'
   +' folder search depth'#11'ParentColor'#8#0#0#6'TLabel'#11'OutDirLabel'#4'Lef'
-  +'t'#2#24#6'Height'#2#17#3'Top'#3#0#1#5'Width'#2#19#7'Caption'#6#3'c:\'#11'Pa'
-  +'rentColor'#8#0#0#9'TGroupBox'#11'FilenameBox'#4'Left'#2#8#6'Height'#3#160#0
-  +#3'Top'#2#8#5'Width'#3#184#0#7'Caption'#6#15'Output Filename'#12'ClientHeigh'
-  +'t'#3#138#0#11'ClientWidth'#3#176#0#8'TabOrder'#2#0#0#9'TCheckBox'#9'DateChe'
+  +'t'#2#16#6'Height'#2#17#3'Top'#3#8#1#5'Width'#2#19#7'Caption'#6#3'c:\'#11'Pa'
+  +'rentColor'#8#0#0#9'TGroupBox'#11'FilenameBox'#4'Left'#2#8#6'Height'#3#176#0
+  +#3'Top'#2#8#5'Width'#3#232#0#7'Caption'#6#15'Output Filename'#12'ClientHeigh'
+  +'t'#3#154#0#11'ClientWidth'#3#224#0#8'TabOrder'#2#0#0#9'TCheckBox'#9'DateChe'
   +'ck'#4'Left'#2#22#6'Height'#2#18#3'Top'#2#8#5'Width'#2'|'#7'Caption'#6#16'Ac'
   +'quisition Date'#8'OnChange'#7#14'FilenameChecks'#8'TabOrder'#2#0#0#0#9'TChe'
   +'ckBox'#14'InputNameCheck'#4'Left'#2#22#6'Height'#2#18#3'Top'#2'!'#5'Width'#2
@@ -30,30 +30,30 @@ LazarusResources.Add('TPrefsForm','FORMDATA',[
   +#1#8'TabOrder'#2#1#0#0#7'TButton'#9'CancelBtn'#4'Left'#3#144#1#6'Height'#2#25
   +#3'Top'#3' '#1#5'Width'#2'K'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#6
   +'Cancel'#11'ModalResult'#2#2#8'TabOrder'#2#2#0#0#9'TCheckBox'#17'NotAnonymiz'
-  +'eCheck'#4'Left'#3#202#0#6'Height'#2#18#3'Top'#2#16#5'Width'#3#233#0#7'Capti'
+  +'eCheck'#4'Left'#3#248#0#6'Height'#2#18#3'Top'#2#24#5'Width'#3#233#0#7'Capti'
   +'on'#6'!Save patient name in NIfTI header'#8'TabOrder'#2#3#0#0#9'TCheckBox'
-  +#13'ReorientCheck'#4'Left'#3#202#0#6'Height'#2#18#3'Top'#2'P'#5'Width'#3'P'#1
+  +#13'ReorientCheck'#4'Left'#3#248#0#6'Height'#2#18#3'Top'#2'X'#5'Width'#3'P'#1
   +#7'Caption'#6'1Reorient large images to nearest orthogonal plane'#8'TabOrder'
-  +#2#4#0#0#9'TSpinEdit'#13'RecursiveSpin'#4'Left'#2#24#6'Height'#2#16#3'Top'#3
-  +#184#0#5'Width'#2'M'#8'MaxValue'#2#10#8'TabOrder'#2#5#0#0#9'TComboBox'#11'Ou'
-  +'tputCombo'#4'Left'#2#24#6'Height'#2#20#3'Top'#3#216#0#5'Width'#3'('#1#10'It'
+  +#2#4#0#0#9'TSpinEdit'#13'RecursiveSpin'#4'Left'#2#16#6'Height'#2#16#3'Top'#3
+  +#200#0#5'Width'#2'M'#8'MaxValue'#2#10#8'TabOrder'#2#5#0#0#9'TComboBox'#11'Ou'
+  +'tputCombo'#4'Left'#2#16#6'Height'#2#20#3'Top'#3#232#0#5'Width'#3'('#1#10'It'
   +'emHeight'#2#0#13'Items.Strings'#1#6#21'Save to source folder'#6#29'Prompt u'
   +'ser for output folder'#6#17'Always save to...'#0#8'OnChange'#7#17'OutputCom'
   +'boChange'#9'OnMouseUp'#7#18'OutputComboMouseUp'#5'Style'#7#14'csDropDownLis'
-  +'t'#8'TabOrder'#2#6#0#0#9'TCheckBox'#13'CollapseCheck'#4'Left'#3#202#0#6'Hei'
+  +'t'#8'TabOrder'#2#6#0#0#9'TCheckBox'#13'CollapseCheck'#4'Left'#3#248#0#6'Hei'
   +'ght'#2#18#4'Hint'#6'_Sort images regardless of source directory. Slower, re'
-  +'quired if series segmented across folders'#3'Top'#2'p'#5'Width'#2'y'#7'Capt'
+  +'quired if series segmented across folders'#3'Top'#2'x'#5'Width'#2'y'#7'Capt'
   +'ion'#6#16'Collapse folders'#8'TabOrder'#2#7#0#0#9'TCheckBox'#27'Stack3DImag'
-  +'esWithSameAcqNum'#4'Left'#3#202#0#6'Height'#2#18#4'Hint'#6'_Sort images reg'
+  +'esWithSameAcqNum'#4'Left'#3#248#0#6'Height'#2#18#4'Hint'#6'_Sort images reg'
   +'ardless of source directory. Slower, required if series segmented across fo'
-  +'lders'#3'Top'#3#144#0#5'Width'#3':'#1#7'Caption'#6'+Stack 3D images with sa'
+  +'lders'#3'Top'#3#152#0#5'Width'#3':'#1#7'Caption'#6'+Stack 3D images with sa'
   +'me acquistion number'#8'TabOrder'#2#8#0#0#7'TButton'#13'TextEditorBtn'#4'Le'
   +'ft'#2#8#6'Height'#2#25#3'Top'#3' '#1#5'Width'#2'{'#25'BorderSpacing.InnerBo'
   +'rder'#2#4#7'Caption'#6#9'Text Edit'#7'OnClick'#7#18'TextEditorBtnClick'#8'T'
-  +'abOrder'#2#9#0#0#9'TCheckBox'#16'WritePrefsOnQuit'#4'Left'#3'X'#1#6'Height'
-  +#2#18#3'Top'#2'p'#5'Width'#3#138#0#7'Caption'#6#19'Write prefs on quit'#7'Ch'
+  +'abOrder'#2#9#0#0#9'TCheckBox'#16'WritePrefsOnQuit'#4'Left'#3#134#1#6'Height'
+  +#2#18#3'Top'#2'x'#5'Width'#3#138#0#7'Caption'#6#19'Write prefs on quit'#7'Ch'
   +'ecked'#9#5'State'#7#9'cbChecked'#8'TabOrder'#2#10#7'Visible'#8#0#0#9'TCheck'
-  +'Box'#14'TxtReportCheck'#4'Left'#3#202#0#6'Height'#2#18#3'Top'#2'0'#5'Width'
+  +'Box'#14'TxtReportCheck'#4'Left'#3#248#0#6'Height'#2#18#3'Top'#2'8'#5'Width'
   +#3#26#1#7'Caption'#6'+Save text report (scan and patient details)'#8'TabOrde'
   +'r'#2#11#0#0#0
 ]);
diff --git a/dcm2nii/pref_form.pas b/dcm2nii/pref_form.pas
index c1af936..7a514b8 100755
--- a/dcm2nii/pref_form.pas
+++ b/dcm2nii/pref_form.pas
@@ -14,7 +14,7 @@ type
 {$H+}
   { TPrefsForm }
   TPrefsForm = class(TForm)
-    TxtReportCheck: TCheckBox;
+   // TxtReportCheck: TCheckBox;
    // WritePrefsOnQuit: TCheckBox;
    // TextEditorBtn: TButton;
     Stack3DImagesWithSameAcqNum: TCheckBox;
@@ -35,6 +35,7 @@ type
     Label1: TLabel;
     TextEditorBtn: TButton;
     WritePrefsOnQuit: TCheckBox;
+    TxtReportCheck: TCheckBox;
     //Stack3DImagesWithSameAcqNum: TCheckBox;
     //CollapseCheck: TCheckBox;
     procedure FilenameChecks(Sender: TObject);
@@ -156,12 +157,11 @@ begin
    SetDefaultPrefs (lPrefs);
    ReadPrefs(lPrefs);
   clear_dicom_data(lDicomData);
-   lDICOMImgName:= 'IM_0160';
-   //lDicomData.StudyDate := '1/1/1970';
-   lDicomData.PatientName := 'JOHNDOE';
-   lDicomData.ProtocolName := 'AnatT1';
+   lDICOMImgName:= 'IM60';
+   lDicomData.PatientName := 'JOHN_DOE';
+   lDicomData.ProtocolName := 'T1';
    //FilenameBox.Caption := 'Output Filename ('+  OutputFilename(lDicomImgName,lDicomData,lPrefs.AppendDate,lPrefs.AppendAcqSeries,lPrefs.AppendProtocolName,lPrefs.AppendPatientName,lPrefs.FourD,lPrefs.AppendFilename)+')';
-   FilenameBox.Caption := 'Output Filename ('+  OutputFilename(lDicomImgName,lDicomData,lPrefs)+')';
+   Caption := 'Output: '+  OutputFilename(lDicomImgName,lDicomData,lPrefs);
 end;
 
 
diff --git a/dcm2nii_prePARRECDTI/LibTar.pas b/dcm2nii_prePARRECDTI/LibTar.pas
deleted file mode 100755
index 20a52fd..0000000
--- a/dcm2nii_prePARRECDTI/LibTar.pas
+++ /dev/null
@@ -1,914 +0,0 @@
-(*Name    : LibTar
-===============================================================================================
-Subject : Handling of "tar" files
-===============================================================================================
-Author  : Stefan Heymann
-          Eschenweg 3
-          72076 T�bingen
-          GERMANY
-
-E-Mail:   stefan at destructor.de
-Web:      www.destructor.de
-
-===============================================================================================
-TTarArchive Usage
------------------
-- Choose a constructor
-- Make an instance of TTarArchive                  TA := TTarArchive.Create (Filename);
-- Scan through the archive                         TA.Reset;
-                                                   WHILE TA.FindNext (DirRec) DO BEGIN
-- Evaluate the DirRec for each file                  ListBox.Items.Add (DirRec.Name);
-- Read out the current file                          TA.ReadFile (DestFilename);
-  (You can ommit this if you want to
-  read in the directory only)                        END;
-- You're done                                      TA.Free;
-
-
-TTarWriter Usage
-----------------
-- Choose a constructor
-- Make an instance of TTarWriter                   TW := TTarWriter.Create ('my.tar');
-- Add a file to the tar archive                    TW.AddFile ('foobar.txt');
-- Add a string as a file                           TW.AddString (SL.Text, 'joe.txt', Now);
-- Destroy TarWriter instance                       TW.Free;
-- Now your tar file is ready.
-
-
-Source, Legals ("Licence")
---------------------------
-The official site to get this code is http://www.destructor.de/
-
-Usage and Distribution of this Source Code is ruled by the
-"Destructor.de Source code Licence" (DSL) which comes with this file or
-can be downloaded at http://www.destructor.de/
-
-IN SHORT: Usage and distribution of this source code is free.
-          You use it completely on your own risk.
-
-Donateware
-----------
-If you like this code, you are free to donate
-http://www.destructor.de/donateware.htm
-
-===============================================================================================
-!!!  All parts of this code which are not finished or known to be buggy
-     are marked with three exclamation marks
-===============================================================================================
-Date        Author Changes
------------------------------------------------------------------------------------------------
-2001-04-26  HeySt  0.0.1 Start
-2001-04-28  HeySt  1.0.0 First Release
-2001-06-19  HeySt  2.0.0 Finished TTarWriter
-2001-09-06  HeySt  2.0.1 Bugfix in TTarArchive.FindNext: FBytesToGo must sometimes be 0
-2001-10-25  HeySt  2.0.2 Introduced the ClearDirRec procedure
-2001-11-13  HeySt  2.0.3 Bugfix: Take out ClearDirRec call from WriteTarHeader
-                         Bug Reported by Tony BenBrahim
-2001-12-25  HeySt  2.0.4 WriteTarHeader: Fill Rec with zero bytes before filling it
-2002-05-18  HeySt  2.0.5 Kylix awareness: Thanks to Kerry L. Davison for the canges
-2005-09-03  HeySt  2.0.6 TTarArchive.FindNext: Don't access SourceStream.Size
-                         (for compressed streams, which don't know their .Size)
-2006-03-13  HeySt  2.0.7 Bugfix in ReadFile (Buffer : POINTER)
-2007-05-16  HeySt  2.0.8 Bugfix in TTarWriter.AddFile (Convertfilename in the ELSE branch)
-                         Bug Reported by Chris Rorden
-*)
-UNIT LibTar;
-INTERFACE
-
-USES
-{$ifdef fpc}  {$MODE Delphi} {$H+} {$endif}
-{$ifdef Unix} 
-  BaseUnix, Unix,
-{$else}
-Windows,  
-{$endif}
-  SysUtils, Classes;
-TYPE
-  // --- File Access Permissions
-  TTarPermission  = (tpReadByOwner, tpWriteByOwner, tpExecuteByOwner,
-                     tpReadByGroup, tpWriteByGroup, tpExecuteByGroup,
-                     tpReadByOther, tpWriteByOther, tpExecuteByOther);
-  TTarPermissions = SET OF TTarPermission;
-
-  // --- Type of File
-  TFileType = (ftNormal,          // Regular file
-               ftLink,            // Link to another, previously archived, file (LinkName)
-               ftSymbolicLink,    // Symbolic link to another file              (LinkName)
-               ftCharacter,       // Character special files
-               ftBlock,           // Block special files
-               ftDirectory,       // Directory entry. Size is zero (unlimited) or max. number of bytes
-               ftFifo,            // FIFO special file. No data stored in the archive.
-               ftContiguous,      // Contiguous file, if supported by OS
-               ftDumpDir,         // List of files
-               ftMultiVolume,     // Multi-volume file part
-               ftVolumeHeader);   // Volume header. Can appear only as first record in the archive
-
-  // --- Mode
-  TTarMode  = (tmSetUid, tmSetGid, tmSaveText);
-  TTarModes = SET OF TTarMode;
-
-  // --- Record for a Directory Entry
-  //     Adjust the ClearDirRec procedure when this record changes!
-  TTarDirRec  = RECORD
-                  Name        : STRING;            // File path and name
-                  Size        : INT64;             // File size in Bytes
-                  DateTime    : TDateTime;         // Last modification date and time
-                  Permissions : TTarPermissions;   // Access permissions
-                  FileType    : TFileType;         // Type of file
-                  LinkName    : STRING;            // Name of linked file (for ftLink, ftSymbolicLink)
-                  UID         : INTEGER;           // User ID
-                  GID         : INTEGER;           // Group ID
-                  UserName    : STRING;            // User name
-                  GroupName   : STRING;            // Group name
-                  ChecksumOK  : BOOLEAN;           // Checksum was OK
-                  Mode        : TTarModes;         // Mode
-                  Magic       : STRING;            // Contents of the "Magic" field
-                  MajorDevNo  : INTEGER;           // Major Device No. for ftCharacter and ftBlock
-                  MinorDevNo  : INTEGER;           // Minor Device No. for ftCharacter and ftBlock
-                  FilePos     : INT64;             // Position in TAR file
-                END;
-
-  // --- The TAR Archive CLASS
-  TTarArchive = CLASS
-                PROTECTED
-                  FStream     : TStream;   // Internal Stream
-                  FOwnsStream : BOOLEAN;   // True if FStream is owned by the TTarArchive instance
-                  FBytesToGo  : INT64;     // Bytes until the next Header Record
-                PUBLIC
-                  CONSTRUCTOR Create (Stream   : TStream);                                OVERLOAD;
-                  CONSTRUCTOR Create (Filename : STRING;
-                                      FileMode : WORD = fmOpenRead OR fmShareDenyWrite);  OVERLOAD;
-                  DESTRUCTOR Destroy;                                       OVERRIDE;
-                  PROCEDURE Reset;                                         // Reset File Pointer
-                  FUNCTION  FindNext (VAR DirRec : TTarDirRec) : BOOLEAN;  // Reads next Directory Info Record. FALSE if EOF reached
-                  PROCEDURE ReadFile (Buffer   : POINTER); OVERLOAD;       // Reads file data for last Directory Record
-                  PROCEDURE ReadFile (Stream   : TStream); OVERLOAD;       // -;-
-                  PROCEDURE ReadFile (Filename : STRING);  OVERLOAD;       // -;-
-                  FUNCTION  ReadFile : STRING;           OVERLOAD;         // -;-
-
-                  PROCEDURE GetFilePos (VAR Current, Size : INT64);        // Current File Position
-                  PROCEDURE SetFilePos (NewPos : INT64);                   // Set new Current File Position
-                END;
-
-  // --- The TAR Archive Writer CLASS
-  TTarWriter = CLASS
-               PROTECTED
-                 FStream      : TStream;
-                 FOwnsStream  : BOOLEAN;
-                 FFinalized   : BOOLEAN;
-                                                   // --- Used at the next "Add" method call: ---
-                 FPermissions : TTarPermissions;   // Access permissions
-                 FUID         : INTEGER;           // User ID
-                 FGID         : INTEGER;           // Group ID
-                 FUserName    : STRING;            // User name
-                 FGroupName   : STRING;            // Group name
-                 FMode        : TTarModes;         // Mode
-                 FMagic       : STRING;            // Contents of the "Magic" field
-                 CONSTRUCTOR CreateEmpty;
-               PUBLIC
-                 CONSTRUCTOR Create (TargetStream   : TStream);                            OVERLOAD;
-                 CONSTRUCTOR Create (TargetFilename : STRING; Mode : INTEGER = fmCreate);  OVERLOAD;
-                 DESTRUCTOR Destroy; OVERRIDE;                   // Writes End-Of-File Tag
-                 PROCEDURE AddFile   (Filename : STRING;  TarFilename : STRING = '');
-                 PROCEDURE AddStream (Stream   : TStream; TarFilename : STRING; FileDateGmt : TDateTime);
-                 PROCEDURE AddString (Contents : STRING;  TarFilename : STRING; FileDateGmt : TDateTime);
-                 PROCEDURE AddDir          (Dirname            : STRING; DateGmt : TDateTime; MaxDirSize : INT64 = 0);
-                 PROCEDURE AddSymbolicLink (Filename, Linkname : STRING; DateGmt : TDateTime);
-                 PROCEDURE AddLink         (Filename, Linkname : STRING; DateGmt : TDateTime);
-                 PROCEDURE AddVolumeHeader (VolumeId           : STRING; DateGmt : TDateTime);
-                 PROCEDURE Finalize;
-                 PROPERTY Permissions : TTarPermissions READ FPermissions WRITE FPermissions;   // Access permissions
-                 PROPERTY UID         : INTEGER         READ FUID         WRITE FUID;           // User ID
-                 PROPERTY GID         : INTEGER         READ FGID         WRITE FGID;           // Group ID
-                 PROPERTY UserName    : STRING          READ FUserName    WRITE FUserName;      // User name
-                 PROPERTY GroupName   : STRING          READ FGroupName   WRITE FGroupName;     // Group name
-                 PROPERTY Mode        : TTarModes       READ FMode        WRITE FMode;          // Mode
-                 PROPERTY Magic       : STRING          READ FMagic       WRITE FMagic;         // Contents of the "Magic" field
-               END;
-// --- Some useful constants
-CONST
-  FILETYPE_NAME : ARRAY [TFileType] OF STRING =
-                  ('Regular', 'Link', 'Symbolic Link', 'Char File', 'Block File',
-                   'Directory', 'FIFO File', 'Contiguous', 'Dir Dump', 'Multivol', 'Volume Header');
-
-  ALL_PERMISSIONS     = [tpReadByOwner, tpWriteByOwner, tpExecuteByOwner,
-                         tpReadByGroup, tpWriteByGroup, tpExecuteByGroup,
-                         tpReadByOther, tpWriteByOther, tpExecuteByOther];
-  READ_PERMISSIONS    = [tpReadByOwner, tpReadByGroup,  tpReadByOther];
-  WRITE_PERMISSIONS   = [tpWriteByOwner, tpWriteByGroup, tpWriteByOther];
-  EXECUTE_PERMISSIONS = [tpExecuteByOwner, tpExecuteByGroup, tpExecuteByOther];
-
-
-FUNCTION  PermissionString      (Permissions : TTarPermissions) : STRING;
-FUNCTION  ConvertFilename       (Filename    : STRING)          : STRING;
-FUNCTION  FileTimeGMT           (FileName    : STRING)          : TDateTime;  OVERLOAD;
-FUNCTION  FileTimeGMT           (SearchRec   : TSearchRec)      : TDateTime;  OVERLOAD;
-PROCEDURE ClearDirRec           (VAR DirRec  : TTarDirRec);
-
-IMPLEMENTATION
-
-FUNCTION PermissionString (Permissions : TTarPermissions) : STRING;
-BEGIN
-  Result := '';
-  IF tpReadByOwner    IN Permissions THEN Result := Result + 'r' ELSE Result := Result + '-';
-  IF tpWriteByOwner   IN Permissions THEN Result := Result + 'w' ELSE Result := Result + '-';
-  IF tpExecuteByOwner IN Permissions THEN Result := Result + 'x' ELSE Result := Result + '-';
-  IF tpReadByGroup    IN Permissions THEN Result := Result + 'r' ELSE Result := Result + '-';
-  IF tpWriteByGroup   IN Permissions THEN Result := Result + 'w' ELSE Result := Result + '-';
-  IF tpExecuteByGroup IN Permissions THEN Result := Result + 'x' ELSE Result := Result + '-';
-  IF tpReadByOther    IN Permissions THEN Result := Result + 'r' ELSE Result := Result + '-';
-  IF tpWriteByOther   IN Permissions THEN Result := Result + 'w' ELSE Result := Result + '-';
-  IF tpExecuteByOther IN Permissions THEN Result := Result + 'x' ELSE Result := Result + '-';
-END;
-
-
-FUNCTION ConvertFilename  (Filename : STRING) : STRING;
-         // Converts the filename to Unix conventions
-BEGIN
-  {$IFDEF LINUX}
-  Result := Filename;
-  {$ELSE}
-  Result := StringReplace (Filename, '\', '/', [rfReplaceAll]);
-  {$ENDIF}
-END;
-
-
-FUNCTION FileTimeGMT (FileName: STRING): TDateTime;
-         // Returns the Date and Time of the last modification of the given File
-         // The Result is zero if the file could not be found
-         // The Result is given in UTC (GMT) time zone
-VAR
-  SR : TSearchRec;
-BEGIN
-  Result := 0.0;
-  IF FindFirst (FileName, faAnyFile, SR) = 0 THEN
-    Result := FileTimeGMT (SR);
-  FindClose (SR);
-END;
-
-
-FUNCTION FileTimeGMT (SearchRec : TSearchRec) : TDateTime;
-{$IFNDEF UNIX}
-VAR
-  SystemFileTime: TSystemTime;
-{$ELSE}
-VAR
-  TimeVal  : TTimeVal;
-  TimeZone : TTimeZone;
-{$ENDIF}
-BEGIN
-  Result := 0.0;
-  {$IFNDEF UNIX}
-  {$WARNINGS OFF}
-    IF (SearchRec.FindData.dwFileAttributes AND faDirectory) = 0 THEN
-      IF FileTimeToSystemTime (SearchRec.FindData.ftLastWriteTime, SystemFileTime) THEN
-        Result := EncodeDate (SystemFileTime.wYear, SystemFileTime.wMonth, SystemFileTime.wDay)
-                + EncodeTime (SystemFileTime.wHour, SystemFileTime.wMinute, SystemFileTime.wSecond, SystemFileTime.wMilliseconds);
-  {$WARNINGS ON}
-  {$ELSE}
-     IF SearchRec.Attr AND faDirectory = 0 THEN BEGIN
-       Result := FileDateToDateTime (SearchRec.Time);
-       fpGetTimeOfDay (@TimeVal, @TimeZone);
-       Result := Result + TimeZone.tz_minuteswest / (60 * 24);
-       END;
-  {$ENDIF}
-end;
-
-
-PROCEDURE ClearDirRec (VAR DirRec : TTarDirRec);
-          // This is included because a FillChar (DirRec, SizeOf (DirRec), 0)
-          // will destroy the long string pointers, leading to strange bugs
-BEGIN
-  WITH DirRec DO BEGIN
-    Name        := '';
-    Size        := 0;
-    DateTime    := 0.0;
-    Permissions := [];
-    FileType    := TFileType (0);
-    LinkName    := '';
-    UID         := 0;
-    GID         := 0;
-    UserName    := '';
-    GroupName   := '';
-    ChecksumOK  := FALSE;
-    Mode        := [];
-    Magic       := '';
-    MajorDevNo  := 0;
-    MinorDevNo  := 0;
-    FilePos     := 0;
-    END;
-END;
-
-CONST
-  RECORDSIZE = 512;
-  NAMSIZ     = 100;
-  TUNMLEN    =  32;
-  TGNMLEN    =  32;
-  CHKBLANKS  = #32#32#32#32#32#32#32#32;
-
-TYPE
-  TTarHeader = PACKED RECORD
-                 Name     : ARRAY [0..NAMSIZ-1] OF CHAR;
-                 Mode     : ARRAY [0..7] OF CHAR;
-                 UID      : ARRAY [0..7] OF CHAR;
-                 GID      : ARRAY [0..7] OF CHAR;
-                 Size     : ARRAY [0..11] OF CHAR;
-                 MTime    : ARRAY [0..11] OF CHAR;
-                 ChkSum   : ARRAY [0..7] OF CHAR;
-                 LinkFlag : CHAR;
-                 LinkName : ARRAY [0..NAMSIZ-1] OF CHAR;
-                 Magic    : ARRAY [0..7] OF CHAR;
-                 UName    : ARRAY [0..TUNMLEN-1] OF CHAR;
-                 GName    : ARRAY [0..TGNMLEN-1] OF CHAR;
-                 DevMajor : ARRAY [0..7] OF CHAR;
-                 DevMinor : ARRAY [0..7] OF CHAR;
-               END;
-
-FUNCTION ExtractText (P : PChar) : STRING;
-BEGIN
-  Result := STRING (P);
-END;
-
-
-FUNCTION ExtractNumber (P : PChar) : INTEGER; OVERLOAD;
-VAR
-  Strg : STRING;
-BEGIN
-  Strg := Trim (StrPas (P));
-  P := PChar (Strg);
-  Result := 0;
-  WHILE (P^ <> #32) AND (P^ <> #0) DO BEGIN
-    Result := (ORD (P^) - ORD ('0')) OR (Result SHL 3);
-    INC (P);
-    END;
-END;
-
-FUNCTION ExtractNumber64 (P : PChar) : INT64; OVERLOAD;
-VAR
-  Strg : STRING;
-BEGIN
-  Strg := Trim (StrPas (P));
-  P := PChar (Strg);
-  Result := 0;
-  WHILE (P^ <> #32) AND (P^ <> #0) DO BEGIN
-    Result := (ORD (P^) - ORD ('0')) OR (Result SHL 3);
-    INC (P);
-    END;
-END;
-
-FUNCTION ExtractNumber (P : PChar; MaxLen : INTEGER) : INTEGER; OVERLOAD;
-VAR
-  S0   : ARRAY [0..255] OF CHAR;
-  Strg : STRING;
-BEGIN
-  StrLCopy (S0, P, MaxLen);
-  Strg := Trim (StrPas (S0));
-  P := PChar (Strg);
-  Result := 0;
-  WHILE (P^ <> #32) AND (P^ <> #0) DO BEGIN
-    Result := (ORD (P^) - ORD ('0')) OR (Result SHL 3);
-    INC (P);
-    END;
-END;
-
-
-FUNCTION ExtractNumber64 (P : PChar; MaxLen : INTEGER) : INT64; OVERLOAD;
-VAR
-  S0   : ARRAY [0..255] OF CHAR;
-  Strg : STRING;
-BEGIN
-  StrLCopy (S0, P, MaxLen);
-  Strg := Trim (StrPas (S0));
-  P := PChar (Strg);
-  Result := 0;
-  WHILE (P^ <> #32) AND (P^ <> #0) DO BEGIN
-    Result := (ORD (P^) - ORD ('0')) OR (Result SHL 3);
-    INC (P);
-    END;
-END;
-
-
-FUNCTION Records (Bytes : INT64) : INT64;
-BEGIN
-  Result := Bytes DIV RECORDSIZE;
-  IF Bytes MOD RECORDSIZE > 0 THEN
-    INC (Result);
-END;
-
-
-PROCEDURE Octal (N : INTEGER; P : PChar; Len : INTEGER);
-         // Makes a string of octal digits
-         // The string will always be "Len" characters long
-VAR
-  I     : INTEGER;
-BEGIN
-  FOR I := Len-2 DOWNTO 0 DO BEGIN
-    (P+I)^ := CHR (ORD ('0') + ORD (N AND $07));
-    N := N SHR 3;
-    END;
-  FOR I := 0 TO Len-3 DO
-    IF (P+I)^ = '0'
-      THEN (P+I)^ := #32
-      ELSE BREAK;
-  (P+Len-1)^ := #32;
-END;
-
-
-PROCEDURE Octal64 (N : INT64; P : PChar; Len : INTEGER);
-         // Makes a string of octal digits
-         // The string will always be "Len" characters long
-VAR
-  I     : INTEGER;
-BEGIN
-  FOR I := Len-2 DOWNTO 0 DO BEGIN
-    (P+I)^ := CHR (ORD ('0') + ORD (N AND $07));
-    N := N SHR 3;
-    END;
-  FOR I := 0 TO Len-3 DO
-    IF (P+I)^ = '0'
-      THEN (P+I)^ := #32
-      ELSE BREAK;
-  (P+Len-1)^ := #32;
-END;
-
-
-PROCEDURE OctalN (N : INTEGER; P : PChar; Len : INTEGER);
-BEGIN
-  Octal (N, P, Len-1);
-  (P+Len-1)^ := #0;
-END;
-
-
-PROCEDURE WriteTarHeader (Dest : TStream; DirRec : TTarDirRec);
-VAR
-  Rec      : ARRAY [0..RECORDSIZE-1] OF CHAR;
-  TH       : TTarHeader ABSOLUTE Rec;
-  Mode     : INTEGER;
-  NullDate : TDateTime;
-  Checksum : CARDINAL;
-  I        : INTEGER;
-BEGIN
-  FillChar (Rec, RECORDSIZE, 0);
-  StrLCopy (TH.Name, PChar (DirRec.Name), NAMSIZ);
-  Mode := 0;
-  IF tmSaveText IN DirRec.Mode THEN Mode := Mode OR $0200;
-  IF tmSetGid   IN DirRec.Mode THEN Mode := Mode OR $0400;
-  IF tmSetUid   IN DirRec.Mode THEN Mode := Mode OR $0800;
-  IF tpReadByOwner    IN DirRec.Permissions THEN Mode := Mode OR $0100;
-  IF tpWriteByOwner   IN DirRec.Permissions THEN Mode := Mode OR $0080;
-  IF tpExecuteByOwner IN DirRec.Permissions THEN Mode := Mode OR $0040;
-  IF tpReadByGroup    IN DirRec.Permissions THEN Mode := Mode OR $0020;
-  IF tpWriteByGroup   IN DirRec.Permissions THEN Mode := Mode OR $0010;
-  IF tpExecuteByGroup IN DirRec.Permissions THEN Mode := Mode OR $0008;
-  IF tpReadByOther    IN DirRec.Permissions THEN Mode := Mode OR $0004;
-  IF tpWriteByOther   IN DirRec.Permissions THEN Mode := Mode OR $0002;
-  IF tpExecuteByOther IN DirRec.Permissions THEN Mode := Mode OR $0001;
-  OctalN (Mode, @TH.Mode, 8);
-  OctalN (DirRec.UID, @TH.UID, 8);
-  OctalN (DirRec.GID, @TH.GID, 8);
-  Octal64 (DirRec.Size, @TH.Size, 12);
-  NullDate := EncodeDate (1970, 1, 1);
-  IF DirRec.DateTime >= NullDate
-    THEN Octal (Trunc ((DirRec.DateTime - NullDate) * 86400.0), @TH.MTime, 12)
-    ELSE Octal (Trunc (                   NullDate  * 86400.0), @TH.MTime, 12);
-  CASE DirRec.FileType OF
-    ftNormal       : TH.LinkFlag := '0';
-    ftLink         : TH.LinkFlag := '1';
-    ftSymbolicLink : TH.LinkFlag := '2';
-    ftCharacter    : TH.LinkFlag := '3';
-    ftBlock        : TH.LinkFlag := '4';
-    ftDirectory    : TH.LinkFlag := '5';
-    ftFifo         : TH.LinkFlag := '6';
-    ftContiguous   : TH.LinkFlag := '7';
-    ftDumpDir      : TH.LinkFlag := 'D';
-    ftMultiVolume  : TH.LinkFlag := 'M';
-    ftVolumeHeader : TH.LinkFlag := 'V';
-    END;
-  StrLCopy (TH.LinkName, PChar (DirRec.LinkName), NAMSIZ);
-  StrLCopy (TH.Magic, PChar (DirRec.Magic + #32#32#32#32#32#32#32#32), 8);
-  StrLCopy (TH.UName, PChar (DirRec.UserName), TUNMLEN);
-  StrLCopy (TH.GName, PChar (DirRec.GroupName), TGNMLEN);
-  OctalN (DirRec.MajorDevNo, @TH.DevMajor, 8);
-  OctalN (DirRec.MinorDevNo, @TH.DevMinor, 8);
-  StrMove (TH.ChkSum, CHKBLANKS, 8);
-
-  CheckSum := 0;
-  FOR I := 0 TO SizeOf (TTarHeader)-1 DO
-    INC (CheckSum, INTEGER (ORD (Rec [I])));
-  OctalN (CheckSum, @TH.ChkSum, 8);
-
-  Dest.Write (TH, RECORDSIZE);
-END;
-
-CONSTRUCTOR TTarArchive.Create (Stream : TStream);
-BEGIN
-  INHERITED Create;
-  FStream     := Stream;
-  FOwnsStream := FALSE;
-  Reset;
-END;
-
-CONSTRUCTOR TTarArchive.Create (Filename : STRING; FileMode : WORD);
-BEGIN
-  INHERITED Create;
-  FStream     := TFileStream.Create (Filename, FileMode);
-  FOwnsStream := TRUE;
-  Reset;
-END;
-
-DESTRUCTOR TTarArchive.Destroy;
-BEGIN
-  IF FOwnsStream THEN
-    FStream.Free;
-  INHERITED Destroy;
-END;
-
-PROCEDURE TTarArchive.Reset;
-          // Reset File Pointer
-BEGIN
-  FStream.Position := 0;
-  FBytesToGo       := 0;
-END;
-
-FUNCTION  TTarArchive.FindNext (VAR DirRec : TTarDirRec) : BOOLEAN;
-          // Reads next Directory Info Record
-          // The Stream pointer must point to the first byte of the tar header
-VAR
-  Rec          : ARRAY [0..RECORDSIZE-1] OF CHAR;
-  CurFilePos   : INTEGER;
-  Header       : TTarHeader ABSOLUTE Rec;
-  I            : INTEGER;
-  HeaderChkSum : WORD;
-  Checksum     : CARDINAL;
-BEGIN
-  // --- Scan until next pointer
-  IF FBytesToGo > 0 THEN
-    FStream.Seek (Records (FBytesToGo) * RECORDSIZE, soFromCurrent);
-
-  // --- EOF reached?
-  Result := FALSE;
-  CurFilePos := FStream.Position;
-  TRY
-    FStream.ReadBuffer (Rec, RECORDSIZE);
-    if Rec [0] = #0 THEN EXIT;   // EOF reached
-  EXCEPT
-    EXIT;   // EOF reached, too
-    END;
-  Result := TRUE;
-
-  ClearDirRec (DirRec);
-
-  DirRec.FilePos := CurFilePos;
-  DirRec.Name := ExtractText (Header.Name);
-  DirRec.Size := ExtractNumber64 (@Header.Size, 12);
-  DirRec.DateTime := EncodeDate (1970, 1, 1) + (ExtractNumber (@Header.MTime, 12) / 86400.0);
-  I := ExtractNumber (@Header.Mode);
-  IF I AND $0100 <> 0 THEN Include (DirRec.Permissions, tpReadByOwner);
-  IF I AND $0080 <> 0 THEN Include (DirRec.Permissions, tpWriteByOwner);
-  IF I AND $0040 <> 0 THEN Include (DirRec.Permissions, tpExecuteByOwner);
-  IF I AND $0020 <> 0 THEN Include (DirRec.Permissions, tpReadByGroup);
-  IF I AND $0010 <> 0 THEN Include (DirRec.Permissions, tpWriteByGroup);
-  IF I AND $0008 <> 0 THEN Include (DirRec.Permissions, tpExecuteByGroup);
-  IF I AND $0004 <> 0 THEN Include (DirRec.Permissions, tpReadByOther);
-  IF I AND $0002 <> 0 THEN Include (DirRec.Permissions, tpWriteByOther);
-  IF I AND $0001 <> 0 THEN Include (DirRec.Permissions, tpExecuteByOther);
-  IF I AND $0200 <> 0 THEN Include (DirRec.Mode, tmSaveText);
-  IF I AND $0400 <> 0 THEN Include (DirRec.Mode, tmSetGid);
-  IF I AND $0800 <> 0 THEN Include (DirRec.Mode, tmSetUid);
-  CASE Header.LinkFlag OF
-    #0, '0' : DirRec.FileType := ftNormal;
-    '1'     : DirRec.FileType := ftLink;
-    '2'     : DirRec.FileType := ftSymbolicLink;
-    '3'     : DirRec.FileType := ftCharacter;
-    '4'     : DirRec.FileType := ftBlock;
-    '5'     : DirRec.FileType := ftDirectory;
-    '6'     : DirRec.FileType := ftFifo;
-    '7'     : DirRec.FileType := ftContiguous;
-    'D'     : DirRec.FileType := ftDumpDir;
-    'M'     : DirRec.FileType := ftMultiVolume;
-    'V'     : DirRec.FileType := ftVolumeHeader;
-    END;
-  DirRec.LinkName   := ExtractText (Header.LinkName);
-  DirRec.UID        := ExtractNumber (@Header.UID);
-  DirRec.GID        := ExtractNumber (@Header.GID);
-  DirRec.UserName   := ExtractText (Header.UName);
-  DirRec.GroupName  := ExtractText (Header.GName);
-  DirRec.Magic      := Trim (ExtractText (Header.Magic));
-  DirRec.MajorDevNo := ExtractNumber (@Header.DevMajor);
-  DirRec.MinorDevNo := ExtractNumber (@Header.DevMinor);
-
-  HeaderChkSum := ExtractNumber (@Header.ChkSum);   // Calc Checksum
-  CheckSum := 0;
-  StrMove (Header.ChkSum, CHKBLANKS, 8);
-  FOR I := 0 TO SizeOf (TTarHeader)-1 DO
-    INC (CheckSum, INTEGER (ORD (Rec [I])));
-  DirRec.CheckSumOK := WORD (CheckSum) = WORD (HeaderChkSum);
-
-  IF DirRec.FileType in [ftLink, ftSymbolicLink, ftDirectory, ftFifo, ftVolumeHeader]
-    THEN FBytesToGo := 0
-    ELSE FBytesToGo := DirRec.Size;
-END;
-
-
-PROCEDURE TTarArchive.ReadFile (Buffer : POINTER);
-          // Reads file data for the last Directory Record. The entire file is read into the buffer.
-          // The buffer must be large enough to take up the whole file.
-VAR
-  RestBytes : INTEGER;
-BEGIN
-  IF FBytesToGo = 0 THEN EXIT;
-  RestBytes := Records (FBytesToGo) * RECORDSIZE - FBytesToGo;
-  FStream.ReadBuffer (Buffer^, FBytesToGo);
-  FStream.Seek (RestBytes, soFromCurrent);
-  FBytesToGo := 0;
-END;
-
-
-PROCEDURE TTarArchive.ReadFile (Stream : TStream);
-          // Reads file data for the last Directory Record.
-          // The entire file is written out to the stream.
-          // The stream is left at its current position prior to writing
-VAR
-  RestBytes : INTEGER;
-BEGIN
-  IF FBytesToGo = 0 THEN EXIT;
-  RestBytes := Records (FBytesToGo) * RECORDSIZE - FBytesToGo;
-  Stream.CopyFrom (FStream, FBytesToGo);
-  FStream.Seek (RestBytes, soFromCurrent);
-  FBytesToGo := 0;
-END;
-
-
-PROCEDURE TTarArchive.ReadFile (Filename : STRING);
-          // Reads file data for the last Directory Record.
-          // The entire file is saved in the given Filename
-VAR
-  FS : TFileStream;
-BEGIN
-  FS := TFileStream.Create (Filename, fmCreate);
-  TRY
-    ReadFile (FS);
-  FINALLY
-    FS.Free;
-    END;
-END;
-
-
-FUNCTION  TTarArchive.ReadFile : STRING;
-          // Reads file data for the last Directory Record. The entire file is returned
-          // as a large ANSI string.
-VAR
-  RestBytes : INTEGER;
-BEGIN
-  IF FBytesToGo = 0 THEN EXIT;
-  RestBytes := Records (FBytesToGo) * RECORDSIZE - FBytesToGo;
-  SetLength (Result, FBytesToGo);
-  FStream.ReadBuffer (PChar (Result)^, FBytesToGo);
-  FStream.Seek (RestBytes, soFromCurrent);
-  FBytesToGo := 0;
-END;
-
-
-PROCEDURE TTarArchive.GetFilePos (VAR Current, Size : INT64);
-          // Returns the Current Position in the TAR stream
-BEGIN
-  Current := FStream.Position;
-  Size    := FStream.Size;
-END;
-
-
-PROCEDURE TTarArchive.SetFilePos (NewPos : INT64);                   // Set new Current File Position
-BEGIN
-  IF NewPos < FStream.Size THEN
-    FStream.Seek (NewPos, soFromBeginning);
-END;
-
-
-CONSTRUCTOR TTarWriter.CreateEmpty;
-VAR
-  TP : TTarPermission;
-BEGIN
-  INHERITED Create;
-  FOwnsStream  := FALSE;
-  FFinalized   := FALSE;
-  FPermissions := [];
-  FOR TP := Low (TP) TO High (TP) DO
-    Include (FPermissions, TP);
-  FUID       := 0;
-  FGID       := 0;
-  FUserName  := '';
-  FGroupName := '';
-  FMode      := [];
-  FMagic     := 'ustar';
-END;
-
-CONSTRUCTOR TTarWriter.Create (TargetStream   : TStream);
-BEGIN
-  CreateEmpty;
-  FStream     := TargetStream;
-  FOwnsStream := FALSE;
-END;
-
-
-CONSTRUCTOR TTarWriter.Create (TargetFilename : STRING; Mode : INTEGER = fmCreate);
-BEGIN
-  CreateEmpty;
-  FStream     := TFileStream.Create (TargetFilename, Mode);
-  FOwnsStream := TRUE;
-END;
-
-
-DESTRUCTOR TTarWriter.Destroy;
-BEGIN
-  IF NOT FFinalized THEN BEGIN
-    Finalize;
-    FFinalized := TRUE;
-    END;
-  IF FOwnsStream THEN
-    FStream.Free;
-  INHERITED Destroy;
-END;
-
-
-PROCEDURE TTarWriter.AddFile   (Filename : STRING;  TarFilename : STRING = '');
-VAR
-  S    : TFileStream;
-  Date : TDateTime;
-BEGIN
-  Date := FileTimeGMT (Filename);
-  IF TarFilename = ''
-    THEN TarFilename := ConvertFilename (Filename)
-    ELSE TarFilename := ConvertFilename (TarFilename);
-  S := TFileStream.Create (Filename, fmOpenRead OR fmShareDenyWrite);
-  TRY
-    AddStream (S, TarFilename, Date);
-  FINALLY
-    S.Free
-    END;
-END;
-
-
-PROCEDURE TTarWriter.AddStream (Stream : TStream; TarFilename : STRING; FileDateGmt : TDateTime);
-VAR
-  DirRec      : TTarDirRec;
-  Rec         : ARRAY [0..RECORDSIZE-1] OF CHAR;
-  BytesToRead : INT64;      // Bytes to read from the Source Stream
-  BlockSize   : INT64;      // Bytes to write out for the current record
-BEGIN
-  ClearDirRec (DirRec);
-  DirRec.Name        := TarFilename;
-  DirRec.Size        := Stream.Size - Stream.Position;
-  DirRec.DateTime    := FileDateGmt;
-  DirRec.Permissions := FPermissions;
-  DirRec.FileType    := ftNormal;
-  DirRec.LinkName    := '';
-  DirRec.UID         := FUID;
-  DirRec.GID         := FGID;
-  DirRec.UserName    := FUserName;
-  DirRec.GroupName   := FGroupName;
-  DirRec.ChecksumOK  := TRUE;
-  DirRec.Mode        := FMode;
-  DirRec.Magic       := FMagic;
-  DirRec.MajorDevNo  := 0;
-  DirRec.MinorDevNo  := 0;
-
-  WriteTarHeader (FStream, DirRec);
-  BytesToRead := DirRec.Size;
-  WHILE BytesToRead > 0 DO BEGIN
-    BlockSize := BytesToRead;
-    IF BlockSize > RECORDSIZE THEN BlockSize := RECORDSIZE;
-    FillChar (Rec, RECORDSIZE, 0);
-    Stream.Read (Rec, BlockSize);
-    FStream.Write (Rec, RECORDSIZE);
-    DEC (BytesToRead, BlockSize);
-    END;
-END;
-
-
-PROCEDURE TTarWriter.AddString (Contents : STRING; TarFilename : STRING; FileDateGmt : TDateTime);
-VAR
-  S : TStringStream;
-BEGIN
-  S := TStringStream.Create (Contents);
-  TRY
-    AddStream (S, TarFilename, FileDateGmt);
-  FINALLY
-    S.Free
-    END
-END;
-
-
-PROCEDURE TTarWriter.AddDir (Dirname : STRING; DateGmt : TDateTime; MaxDirSize : INT64 = 0);
-VAR
-  DirRec      : TTarDirRec;
-BEGIN
-  ClearDirRec (DirRec);
-  DirRec.Name        := Dirname;
-  DirRec.Size        := MaxDirSize;
-  DirRec.DateTime    := DateGmt;
-  DirRec.Permissions := FPermissions;
-  DirRec.FileType    := ftDirectory;
-  DirRec.LinkName    := '';
-  DirRec.UID         := FUID;
-  DirRec.GID         := FGID;
-  DirRec.UserName    := FUserName;
-  DirRec.GroupName   := FGroupName;
-  DirRec.ChecksumOK  := TRUE;
-  DirRec.Mode        := FMode;
-  DirRec.Magic       := FMagic;
-  DirRec.MajorDevNo  := 0;
-  DirRec.MinorDevNo  := 0;
-
-  WriteTarHeader (FStream, DirRec);
-END;
-
-
-PROCEDURE TTarWriter.AddSymbolicLink (Filename, Linkname : STRING; DateGmt : TDateTime);
-VAR
-  DirRec : TTarDirRec;
-BEGIN
-  ClearDirRec (DirRec);
-  DirRec.Name        := Filename;
-  DirRec.Size        := 0;
-  DirRec.DateTime    := DateGmt;
-  DirRec.Permissions := FPermissions;
-  DirRec.FileType    := ftSymbolicLink;
-  DirRec.LinkName    := Linkname;
-  DirRec.UID         := FUID;
-  DirRec.GID         := FGID;
-  DirRec.UserName    := FUserName;
-  DirRec.GroupName   := FGroupName;
-  DirRec.ChecksumOK  := TRUE;
-  DirRec.Mode        := FMode;
-  DirRec.Magic       := FMagic;
-  DirRec.MajorDevNo  := 0;
-  DirRec.MinorDevNo  := 0;
-
-  WriteTarHeader (FStream, DirRec);
-END;
-
-
-PROCEDURE TTarWriter.AddLink (Filename, Linkname : STRING; DateGmt : TDateTime);
-VAR
-  DirRec : TTarDirRec;
-BEGIN
-  ClearDirRec (DirRec);
-  DirRec.Name        := Filename;
-  DirRec.Size        := 0;
-  DirRec.DateTime    := DateGmt;
-  DirRec.Permissions := FPermissions;
-  DirRec.FileType    := ftLink;
-  DirRec.LinkName    := Linkname;
-  DirRec.UID         := FUID;
-  DirRec.GID         := FGID;
-  DirRec.UserName    := FUserName;
-  DirRec.GroupName   := FGroupName;
-  DirRec.ChecksumOK  := TRUE;
-  DirRec.Mode        := FMode;
-  DirRec.Magic       := FMagic;
-  DirRec.MajorDevNo  := 0;
-  DirRec.MinorDevNo  := 0;
-
-  WriteTarHeader (FStream, DirRec);
-END;
-
-
-PROCEDURE TTarWriter.AddVolumeHeader (VolumeId           : STRING; DateGmt : TDateTime);
-VAR
-  DirRec : TTarDirRec;
-BEGIN
-  ClearDirRec (DirRec);
-  DirRec.Name        := VolumeId;
-  DirRec.Size        := 0;
-  DirRec.DateTime    := DateGmt;
-  DirRec.Permissions := FPermissions;
-  DirRec.FileType    := ftVolumeHeader;
-  DirRec.LinkName    := '';
-  DirRec.UID         := FUID;
-  DirRec.GID         := FGID;
-  DirRec.UserName    := FUserName;
-  DirRec.GroupName   := FGroupName;
-  DirRec.ChecksumOK  := TRUE;
-  DirRec.Mode        := FMode;
-  DirRec.Magic       := FMagic;
-  DirRec.MajorDevNo  := 0;
-  DirRec.MinorDevNo  := 0;
-
-  WriteTarHeader (FStream, DirRec);
-END;
-
-
-PROCEDURE TTarWriter.Finalize;
-          // Writes the End-Of-File Tag
-          // Data after this tag will be ignored
-          // The destructor calls this automatically if you didn't do it before
-VAR
-  Rec : ARRAY [0..RECORDSIZE-1] OF CHAR;
-BEGIN
-  FillChar (Rec, SizeOf (Rec), 0);
-  FStream.Write (Rec, RECORDSIZE);
-  FFinalized := TRUE;
-END;
-
-
-END.
-
diff --git a/dcm2nii_prePARRECDTI/PARtoNRRD_Philips_RelX.zip b/dcm2nii_prePARRECDTI/PARtoNRRD_Philips_RelX.zip
deleted file mode 100755
index 1568f67..0000000
Binary files a/dcm2nii_prePARRECDTI/PARtoNRRD_Philips_RelX.zip and /dev/null differ
diff --git a/dcm2nii_prePARRECDTI/SelectFolder.pas b/dcm2nii_prePARRECDTI/SelectFolder.pas
deleted file mode 100755
index 406d3b1..0000000
--- a/dcm2nii_prePARRECDTI/SelectFolder.pas
+++ /dev/null
@@ -1,97 +0,0 @@
-unit SelectFolder;
-
-interface
-
-function BrowseForFolder(const browseTitle: String;
-  const initialFolder: String = '';
-  mayCreateNewFolder: Boolean = False): String;
-
-function SelectDirectoryDelphi(const browseTitle: String; var Folder: String; mayCreateNewFolder: Boolean = False): boolean;
-implementation
-
-uses
-  Windows, Forms, shlobj;
-
-function SelectDirectoryDelphi(const browseTitle: String; var Folder: String; mayCreateNewFolder: Boolean = False): boolean;
-var
-   lTemp: string;
-begin
-     result := false;
-     lTemp := BrowseForFolder(browseTitle, Folder, mayCreateNewFolder);
-     if (lTemp <> '') then begin
-         Folder := lTemp;
-         result := true;
-     end;
-//
-end;
-
-var
-  lg_StartFolder: String;
-
-
-
-// With later versions of Delphi you may not need these constants.
-const
-  BIF_NEWDIALOGSTYLE=$40;
-  BIF_NONEWFOLDERBUTTON=$200;
-
-////////////////////////////////////////////////////////////////////////
-// Call back function used to set the initial browse directory.
-////////////////////////////////////////////////////////////////////////
-function BrowseForFolderCallBack(Wnd: HWND; uMsg: UINT; lParam,
-lpData: LPARAM): Integer stdcall;
-begin
-  if uMsg = BFFM_INITIALIZED then
-    SendMessage(Wnd,BFFM_SETSELECTION, 1, Integer(@lg_StartFolder[1]));
-  result := 0;
-end;
-
-////////////////////////////////////////////////////////////////////////
-// This function allows the user to browse for a folder
-//
-// Arguments:-
-//         browseTitle : The title to display on the browse dialog.
-//       initialFolder : Optional argument. Use to specify the folder
-//                       initially selected when the dialog opens.
-//  mayCreateNewFolder : Flag indicating whether the user can create a
-//                       new folder.
-//
-// Returns: The empty string if no folder was selected (i.e. if the user
-//          clicked cancel), otherwise the full folder path.
-////////////////////////////////////////////////////////////////////////
-function BrowseForFolder(const browseTitle: String;
-  const initialFolder: String ='';
-  mayCreateNewFolder: Boolean = False): String;
-var
-  browse_info: TBrowseInfo;
-  folder: array[0..MAX_PATH] of char;
-  find_context: PItemIDList;
-begin
-  //--------------------------
-  // Initialise the structure.
-  //--------------------------
-  FillChar(browse_info,SizeOf(browse_info),#0);
-  lg_StartFolder := initialFolder;
-  browse_info.pszDisplayName := @folder[0];
-  browse_info.lpszTitle := PChar(browseTitle);
-  browse_info.ulFlags := BIF_RETURNONLYFSDIRS or BIF_NEWDIALOGSTYLE;
-  if not mayCreateNewFolder then
-    browse_info.ulFlags := browse_info.ulFlags or BIF_NONEWFOLDERBUTTON;
-
-  browse_info.hwndOwner := Application.Handle;
-  if initialFolder <> '' then
-    browse_info.lpfn := BrowseForFolderCallBack;
-  find_context := SHBrowseForFolder(browse_info);
-  if Assigned(find_context) then
-  begin
-    if SHGetPathFromIDList(find_context,folder) then
-      result := folder
-    else
-      result := '';
-    GlobalFreePtr(find_context);
-  end
-  else
-    result := '';
-end;
-
-end.
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/convert.pas b/dcm2nii_prePARRECDTI/convert.pas
deleted file mode 100755
index f6095da..0000000
--- a/dcm2nii_prePARRECDTI/convert.pas
+++ /dev/null
@@ -1,1734 +0,0 @@
-unit convert;
-{$H+}
-interface
-uses
-{$IFNDEF UNIX}
-Windows,
-{$ENDIF}
-{$IFDEF FPC}
-gzio2,
-{$ELSE}
-
-{$ENDIF}
-filename,define_types,classes,SysUtils,dicom,dicomtypes,
-niftiutil,GraphicsMathLibrary,  userdir,csaread,
-nii_4dto3d,nii_orient,nii_crop,prefs,lsjpeg;
-function Dicom2NII(var lDICOMra: TDICOMrap; lFirstDICOM, lLastDICOM: integer; var lOutDirOrig: string; var lPrefs: TPrefs; lVols: integer): boolean;
-implementation
-uses
-sortdicom,dialogsx;
-
-function getDeterminant(r: TMatrix): double;
-var
-r11,r12,r13,r21,r22,r23,r31,r32,r33: double;
-begin
-	   r11 := r.matrix[1,1];//[0][0];
-	   r12 := r.matrix[1,2];//r[0][1];
-	   r13 := r.matrix[1,3];//r[0][2];
-	   r21 := r.matrix[2,1];//[0][0];
-	   r22 := r.matrix[2,2];//r[0][1];
-	   r23 := r.matrix[2,3];//r[0][2];
-	   r31 := r.matrix[3,1];//[0][0];
-	   r32 := r.matrix[3,2];//r[0][1];
-	   r33 := r.matrix[3,3];//r[0][2];
-	  result := r11*r22*r33 - r11*r32*r23 - r21*r12*r33 +
-		 r21*r32*r13 + r31*r12*r23 - r31*r22*r13;
-end;
-
-function RealToStr(lR: double ; lDec: integer): string;
-begin
-	 RealTOStr := FloatToStrF(lR, ffFixed,7,lDec);
-end;
-
-function UniqueFileName (var lInStr: string): boolean;
-var
-  lInc: integer;
-  lPathWName,lExt: string;
-begin
-	result := true;
-	if not Fileexists(lInStr) then exit;
-	ExtractFileParts(lInStr,lPathWName,lExt);
-	lInc := ord('A');
-	while (lInc <= ord('Z')) and ( Fileexists(lPathWName+chr(lInc)+lExt))  do
-	  inc(lInc);
-	if lInc > ord('Z') then
-	  result := false
-	else
-	  lInStr := lPathWName+chr(lInc)+lExt;
-end;
-
-FUNCTION Diag2D (CONST m1,m2,m3:  DOUBLE):  TMatrix;
-  BEGIN
-	WITH RESULT DO
-	BEGIN
-	  matrix[1,1] := m1; matrix[1,2] := 0;
-	  matrix[1,3] := 0;
-
-	  matrix[2,1] := 0; matrix[2,2] := m2;
-	  matrix[2,3] := 0;
-
-	  matrix[3,1] := 0; matrix[3,2] := 0;
-	  matrix[3,3] := m3;
-	  size := size2D
-	END
-  END {Diag2D};
-FUNCTION Diag3D (CONST m1,m2,m3,m4:  DOUBLE):  TMatrix;
-  BEGIN
-	WITH RESULT DO
-	BEGIN
-	  matrix[1,1] := m1; matrix[1,2] := 0;
-	  matrix[1,3] := 0; matrix[1,4] := 0;
-
-	  matrix[2,1] := 0; matrix[2,2] := m2;
-	  matrix[2,3] := 0; matrix[2,4] := 0;
-
-	  matrix[3,1] := 0; matrix[3,2] := 0;
-	  matrix[3,3] := m3; matrix[3,4] := 0;
-
-	  matrix[4,1] := 0; matrix[4,2] := 0;
-	  matrix[4,3] := 0; matrix[4,4] := m4;
-	  size := size3D
-	END
-END {Diag3D};
-
-procedure AdjMosaic (var Q: TMatrix; var lDicomData: DicomData);
-//Changes suggested by Antonin Skoch" <ansk at medicon.cz<mailto:ansk at medicon.cz>>
-// September 23, 2011 10:38:05 AM
-var
-   lFactorX: double;
-   lFactorY: double;
-begin
-   lFactorX := (lDicomData.XYZdim[1] -(lDicomData.XYZdim[1]/lDicomData.SiemensMosaicX)   )/2;
-   lFactorY := (lDicomData.XYZdim[2] -(lDicomData.XYZdim[2]/lDicomData.SiemensMosaicY)   )/2;
-   Q.matrix[1,4] :=(Q.matrix[1,1]*lFactorX)+(Q.matrix[1,2]*lFactorY)+Q.matrix[1,4];
-   Q.matrix[2,4] :=(Q.matrix[2,1]*lFactorX)+(Q.matrix[2,2]*lFactorY)+Q.matrix[2,4];
-   Q.matrix[3,4] :=(Q.matrix[3,1]*lFactorX)+(Q.matrix[3,2]*lFactorY)+Q.matrix[3,4];
-end;
-(*procedure AdjMosaic (var Q: TMatrix; var lDicomData: DicomData);
-var
-	lFactor: double;
-begin
-	lFactor := (lDicomData.XYZdim[1] - (lDicomData.XYZdim[1]/lDicomData.SiemensMosaicX)   )/2;
-	Q.matrix[1,4] := (Q.matrix[1,1]*lFactor)+(Q.matrix[1,2]*lFactor){+(Q.matrix[1,3])}+Q.matrix[1,4];
-	Q.matrix[2,4] := (Q.matrix[2,1]*lFactor)+(Q.matrix[2,2]*lFactor){+(Q.matrix[1,3])}+Q.matrix[2,4];
-	Q.matrix[3,4] := (Q.matrix[3,1]*lFactor)+(Q.matrix[3,2]*lFactor){+(Q.matrix[1,3])}+Q.matrix[3,4];
-end;  *)
-
-(*procedure get_numaris4_val(lFilename,lTagName1,lTagName2: string; var lnmosaic: integer; var lv1,lv2,lv3:single); // spm_dicom_convert
-label 121;
-const
-     kMaxHdrSz = 24000;
-var
-   lHdr  : array [1..kMaxHdrSz] of Char;
-   lTagName,lStr: string;
-   lLoop,lFileSz,lFilePos,lTagLen,lSubLoop,lnSubloop: integer;
-   lFile: file;
-function IsTag: boolean;
-var
-   lTagPos: integer;
-begin
-    result := false;
-    for lTagPos := 1 to lTagLen do
-        if lHdr[lFilePos+lTagPos-1] <> lTagName[lTagPos] then
-           exit;
-    result := true;
-end;
-
-function IsNumber: boolean;
-begin
-     if lHdr[lFilePos] in ['-','.','0'..'9'] then
-           result := true
-     else
-         result := false;
-end;
-
-begin
-  lnmosaic := 0;//detect if function found header
-  if not fileexists(lFilename) then
-     exit;
-
-  FileMode := 0; //set to readonly
-  AssignFile(lFile, lFileName);
-  Reset(lFile, 1);
-  lFileSz := FileSize(lFile);
-  if lFileSz > kMaxHdrSz then
-     lFileSz := kMaxHdrSz;
-  if lFilesz < (2000) then begin
-        //to small to be DICOM mosaic
-        CloseFile(lFile);
-        Filemode := 2;
-        exit;
-  end;
-  BlockRead(lFile, lHdr, lFileSz*SizeOf(Char));
-  FileMode := 0; //set to readonly
-  CloseFile(lFile);
-  lFilePos := 1;
-for lLoop := 1 to 2 do begin
-    if lLoop = 1 then begin
-       lnSubloop := 1;
-       lTagName := lTagName1;
-    end else begin
-        lnSubloop := 3;
-        lTagName := lTagName2;
-    end;
-  lTagLen := length (lTagName);
-  while (lFilePos < (lFileSz-lTagLen)) and (not (IsTag)) do
-        inc(lFilePos);
-  if (lFilePos >= (lFileSz-lTagLen)) then
-     exit;
-  lFilePos := lFilePos + 72; //lots of space between name and value
-for lSubloop := 1 to lnSubloop do begin
-  while (lFilePos < (lFileSz)) and (not (IsNumber)) do
-        inc(lFilePos);
-  if (lFilePos >= (lFileSz-lTagLen)) then
-     exit;
-  lStr :='';// lHdr[lFilePos];
-  while (lFilePos < (lFileSz)) and  (IsNumber) do begin
-        lStr := lStr+lHdr[lFilePos];
-        inc(lFilePos);
-  end;
-  if lStr = '' then
-     exit;
-  if lLoop = 1 then
-     lnmosaic := strtoint(lStr)
-  else begin
-      case lSubloop of
-           1: lv1 := strtofloat(lStr);
-           2: lv2 := strtofloat(lStr);
-           3: lv3 := strtofloat(lStr);
-      end; //case
-  end; //else
-end; //sublooop
-end; //loop
-end;    *)
-
-
-
-function IsNormalMosaic(var lDicomData: DicomData; var lMosaicSlices: integer; var lFilename: string): boolean;
-var
-   Q: TMatrix;
-   lX,lY,lnmos,lImagesPerRow: integer;
-   lv1,lv2,lv3: double;
-begin
-     lX := lDICOMdata.SiemensMosaicX;
-     lY := lDICOMdata.SiemensMosaicY;
-     result := false;
-     lMosaicSlices := lDICOMdata.SiemensSlices;
-     if lMosaicSlices = 0 then
-        lMosaicSlices := lDICOMdata.SiemensMosaicX*lDICOMdata.SiemensMosaicY;
-
-     if (lDICOMdata.SiemensMosaicX < 1) then
-        exit; //not mosaic
-     if (lDICOMdata.SiemensSlices > 0) then
-        exit; //pre-Trio Siemens Mosaic Data
-     if not GetCSAImageHeaderInfo (lFilename, lDicomData.CSAImageHeaderInfoPos ,lDicomData.CSAImageHeaderInfoSz, lnmos,lDicomData.SiemensMosaicX,lDicomData.SiemensMosaicY, lv1,lv2,lv3) then begin
-        lDICOMdata.SiemensMosaicX := lX;
-        lDICOMdata.SiemensMosaicY := lY;
-        lMosaicSlices := lX * lY;
-        exit;
-     end;
-     if lnmos < 1 then
-        exit;
-     //4/4/2008 I used to read AcquisitionMatrixText from CSA Image Header... however this is a problem if the images are interpolated
-     lImagesPerRow := 1;
-     while sqr(lImagesPerRow) < lnMos do
-           inc(lImagesPerRow);
-     lDICOMdata.SiemensMosaicX := lDicomData.XYZdim[1] div lImagesPerRow;
-     lDICOMdata.SiemensMosaicY := lDicomData.XYZdim[2] div lImagesPerRow;  //29Sept2008
-     //fx(lDicomData.XYZdim[1],lDicomData.XYZdim[2],lnmos,lDICOMdata.SiemensMosaicY);
-     lDicomData.SiemensMosaicX := lDicomData.XYZdim[1] div lDICOMdata.SiemensMosaicX;
-     lDicomData.SiemensMosaicY := lDicomData.XYZdim[2] div lDICOMdata.SiemensMosaicY;
-     //get_numaris4_val(lFilename,'NumberOfImagesInMosaic','SliceNormalVector',lnmos,lv1,lv2,lv3);
-     //b13
-     Q := Matrix2D(lDicomData.Orient[1], lDicomData.Orient[4],lv1,
-              lDicomData.Orient[2],lDicomData.Orient[5],lv2,
-              lDicomData.Orient[3],lDicomData.Orient[6],lv3);
-     if  nifti_mat33_determ(Q) < 0 then begin
-        result := true;
-        //lDicomData.SiemensFlipMosaic := true;
-        //reportmatrix('mosaic FLIPPED:'+lFilename,Q);
-     end;
-     lMosaicSlices := lnmos;
-end;
-
-
-function IsSiemensDTI(var lDicomData: DicomData;  var lDTI: TDTI;var lFilename: string; var lPrefs: TPrefs): boolean;
-begin
-     result := false;
-     if (lDICOMdata.SiemensDICOMDTI) and (lDICOMdata.DTI[1].bval >= 0) and (lDicomData.Vers0018_1020 {ImplementationVersion} >= lPrefs.SiemensDTIUse0019If00181020atleast {IgnoreDTIRotationsIf_0002_0013_atleast}) then begin
-        lDTI.Bval := lDICOMdata.DTI[1].bval;
-        ldti.v1 := lDicomData.DTI[1].v1;
-        ldti.v2 := lDicomData.DTI[1].v2;
-        ldti.v3 := lDicomData.DTI[1].v3;
-        result := true;
-        exit;
-     end;
-     if (lDICOMdata.ManufacturerID <> kSiemensID) then
-        exit;
-
-     if not GetCSAImageHeaderInfoDTI (lFilename, lDicomData.CSAImageHeaderInfoPos ,lDicomData.CSAImageHeaderInfoSz,lDTI.Bval,ldti.v1,ldti.v2,ldti.v3) then
-     //if not GetCSAImageHeaderInfoDTI (lFilename, lDicomData.CSAImageHeaderInfoPos ,lDicomData.CSAImageHeaderInfoSz, lDTI.Bval, ldti.v1,ldti.v2,ldti.v3) then
-        exit;
-     if lDTI.bval >= 0 then begin
-      result := true;
-      lDicomData.SiemensDICOMDTICSA := true;
-     end;
-     //fx(lDTI.bval);
-end;
-
-procedure dicom_2_nifti(var lDicomData: DicomData; var lHdr: TNiftiHdr ; lMosaicSlices: integer; var lFlipMosaic: boolean);
-var
-  Q,res,diagVox,patient_to_tal,analyze_to_dicom: TMatrix;
-  lx,ly: integer;
-  val: double;
-  dx,dy,dz: single;
-  lOK: boolean;
-begin
-   lHdr.sform_code := kNIFTI_XFORM_UNKNOWN;
-   lOK := false;
-   for lx := 1 to 6 do
-		if lDicomData.Orient[lx] <> 0 then lOK := true;
-   if not lOK then exit;
-   Q := Diag3D(1,1,1,1);//set column 4 and row 4 to zeros, except [4,4]
-   Q.matrix[1,1] :=lDicomData.Orient[1] ; Q.matrix[1,2] := lDicomData.Orient[2] ; Q.matrix[1,3] := lDicomData.Orient[3] ; //* load Q */
-   Q.matrix[2,1] := lDicomData.Orient[4] ; Q.matrix[2,2] := lDicomData.Orient[5] ; Q.matrix[2,3] := lDicomData.Orient[6] ;
-   // normalize row 1
-   val := Q.matrix[1,1]*Q.matrix[1,1] + Q.matrix[1,2]*Q.matrix[1,2] + Q.matrix[1,3]*Q.matrix[1,3] ;
-   if( val > 0.0 ) then begin
-	 val := 1.0 / sqrt(val) ;
-	 Q.matrix[1,1] := Q.matrix[1,1]* val ; Q.matrix[1,2] := Q.matrix[1,2]* val ; Q.matrix[1,3] := Q.matrix[1,3]* val ;
-   end else begin
-	 Q.matrix[1,1] := 1.0 ; Q.matrix[1,2] := 0.0 ; Q.matrix[1,3] := 0.0 ;
-   end;
-   // normalize row 2
-   val := Q.matrix[2,1]*Q.matrix[2,1] + Q.matrix[2,2]*Q.matrix[2,2] + Q.matrix[2,3]*Q.matrix[2,3] ;
-   if( val > 0.0 ) then begin
-	 val := 1.0 / sqrt(val) ;
-	 Q.matrix[2,1] := Q.matrix[2,1]* val ; Q.matrix[2,2] := Q.matrix[2,2]* val ; Q.matrix[2,3] := Q.matrix[2,3]* val ;
-   end else begin
-	 Q.matrix[2,1] := 0.0 ; Q.matrix[2,2] := 1.0 ; Q.matrix[2,3] := 0.0 ;
-   end;
-   //row 3 is cross product of previous rows
-   Q.matrix[3,1] := Q.matrix[1,2]*Q.matrix[2,3] - Q.matrix[1,3]*Q.matrix[2,2] ;
-   Q.matrix[3,2] := Q.matrix[1,3]*Q.matrix[2,1] - Q.matrix[1,1]*Q.matrix[2,3] ;
-   Q.matrix[3,3] := Q.matrix[1,1]*Q.matrix[2,2] - Q.matrix[1,2]*Q.matrix[2,1] ;
-   res := Diag3D(1,1,1,1); //set forth column/row
-   //next: transpose matrix
-   for lx := 1 to 3 do
-		for ly := 1 to 3 do
-			res.matrix[lx,ly] := Q.matrix[ly,lx];
-   Q := res;
-   //next if det(orient)<0, orient(:,3) = -orient(:,3); end;
-   //showmessage(realtostr(getDeterminant(Q),2));
-   if getDeterminant(Q) < 0 then begin
-	   Q.matrix[1,3] := -Q.matrix[1,3];
-	   Q.matrix[2,3] := -Q.matrix[2,3];
-	   Q.matrix[3,3] := -Q.matrix[3,3];
-   end;
-   //next scale matrix
-   diagVox := Diag2D(lDicomData.XYZmm[1],lDicomData.XYZmm[2],lDicomData.XYZmm[3]);
-   Q.size := size2D;
-   Q := MultiplyMatrices(Q,diagVox);
-   //next - add translations
-   Q.matrix[1,4] := lDicomData.PatientPosX;
-   Q.matrix[2,4] := lDicomData.PatientPosY;
-   Q.matrix[3,4] := lDicomData.PatientPosZ;
-   val := lDicomData.XYZdim[2];
-   if (lDICOMdata.SiemensMosaicX > 1) or (lDICOMdata.SiemensMosaicY > 1) then begin
-	AdjMosaic(Q,lDICOMdata);
-	val := lDicomData.XYZdim[2]/lDICOMdata.SiemensMosaicY;
-        //lFlipMosaic := IsNormalMosaic(lDicomData,lMosaicSlices,lFilename);
-   end;
-   Q.matrix[4,1] := 0;
-   Q.matrix[4,2] := 0;
-   Q.matrix[4,3] := 0;
-   Q.matrix[4,4] := 1;
-   Q.size := size3D;
-   //Q now equals 'dicom_to_patient' in spm_dicom_convert
-   //result := q; exit; //escape to compare with SPM
-   //next - convert space
-   patient_to_tal   := diag3D(-1, -1, 1,1);
-   analyze_to_dicom := Matrix3D (
-	1, 0, 0,-1,
-	0,-1, 0, val,
-	0, 0, 1,-1,
-	0, 0, 0, 1);
-   //reportMatrix('d2pat',Q);
-   //reportmatrix('p2tal',patient_to_tal);
-   //reportMatrix('a2d',analyze_to_dicom);
-   Q := MultiplyMatrices(patient_to_tal,Q);
-   Q := MultiplyMatrices(Q,analyze_to_dicom);
-   //reportMatrix('mat',Q);
-   //Q now equals 'mat' in spm_dicom_convert
-   //subasgn.m in SPM5 translates by one voxel...
-   analyze_to_dicom := Matrix3D (
-	1, 0, 0,1,
-	0,1, 0, 1,
-	0, 0,1,1,
-	0, 0, 0, 1);
-   Q := MultiplyMatrices(Q,analyze_to_dicom);//not used for flips
-   if ((lDICOMdata.SiemensMosaicX > 1) or (lDICOMdata.SiemensMosaicY > 1)) and (lFlipMosaic) then begin
-     //reportmatrix('QmosaicIn',Q);
-            patient_to_tal   := diag3D(1, 1, 1,1);
-            patient_to_tal.matrix[3,4] := 1-lMosaicSlices;
-            Q := MultiplyMatrices(Q,patient_to_tal);
-     //reportmatrix('r',patient_to_tal);
-     //reportmatrix('QmosaicOut',Q);
-   end;
-   //if (lDICOMdata.SiemensMosaicX = 1) and (lDICOMdata.SiemensMosaicY = 1) then
-   //reportmatrix('final',Q);
-   //mat44_to_quatern(Q); *)
-   //reportMatrix('nii',Q);
-   lHdr.sform_code := kNIFTI_XFORM_SCANNER_ANAT;
-   lHdr.srow_x[0] := Q.matrix[1,1];
-   lHdr.srow_x[1] := Q.matrix[1,2];
-   lHdr.srow_x[2] := Q.matrix[1,3];
-   lHdr.srow_x[3] := Q.matrix[1,4];
-   lHdr.srow_y[0] := Q.matrix[2,1];
-   lHdr.srow_y[1] := Q.matrix[2,2];
-   lHdr.srow_y[2] := Q.matrix[2,3];
-   lHdr.srow_y[3] := Q.matrix[2,4];
-   lHdr.srow_z[0] := Q.matrix[3,1];
-   lHdr.srow_z[1] := Q.matrix[3,2];
-   lHdr.srow_z[2] := Q.matrix[3,3];
-   lHdr.srow_z[3] := Q.matrix[3,4];
-   //finally, create Quat from matrix
-   lHdr.qform_code := kNIFTI_XFORM_SCANNER_ANAT;
-   nifti_mat44_to_quatern( Q,
-   lHdr.quatern_b,lHdr.quatern_c,lHdr.quatern_d,
-   lHdr.qoffset_x,lHdr.qoffset_y,lHdr.qoffset_z,
-                             dx, dy, dz, lHdr.pixdim[0]{QFac});
-
-   //msgq(lHdr.quatern_b,lHdr.quatern_c,lHdr.quatern_d,lHdr.qoffset_x,lHdr.qoffset_y,lHdr.qoffset_z);
-end;
-
-(*function CountOrders(var lDICOMdata: dicomdata): integer;
-//for 4D files, if you have 'M'agnitude and 'Phase' maps in order M M P P M P this will return 1 1 2 2 1 2
-const
-     kTypes = 10;
-var
-   ltype,i: integer;
-   noveltype: array [1..kTypes] of boolean;
-begin
-     result := 0;
-     for i := 1 to kTypes do
-         noveltype[i] := true;
-     for i := 1 to lDICOMdata.nOrder do begin
-         ltype := lDICOMdata.order[i];
-         if (ltype < 1) or (lType > kTypes) then
-            lType := 1;
-         if (noveltype[ltype])then
-            inc(result); //we found a new order...
-         noveltype[ltype] := false;
-     end;
-end;*)
-
-(*function SortOrders(var lDICOMdata: dicomdata; var lImageOrder: bytep): integer;
-//for 4D files, if you have 'M'agnitude and 'Phase' maps in order M M P P M P this will return 1 1 2 2 1 2
-const
-     kTypes = 10;
-var
-   ltype,i: integer;
-   noveltype: array [1..kTypes] of boolean;
-begin
-     result := 0;
-     for i := 1 to kTypes do
-         noveltype[i] := true;
-     getmem(lImageOrder,lDICOMdata.nOrder);
-     for i := 1 to lDICOMdata.nOrder do begin
-         ltype := lDICOMdata.order[i];
-         if (ltype < 1) or (lType > kTypes) then
-            lType := 1;
-         lImageOrder^[i] := lType;
-         if (noveltype[ltype])then
-            inc(result); //we found a new order...
-         noveltype[ltype] := false;
-     end;
-end;
-
-function CountOrders(var lDICOMdata: dicomdata): integer;
-var
-   lImageOrder: bytep;
-begin
-     if (lDICOMdata.nOrder < 1) then
-        exit;
-    result := SortOrders(lDICOMdata,lImageOrder);
-    freemem(lImageOrder);
-end;
-
-function ParseOrder(var lDICOMdataAllTypes,lDICOMdataSelectedType: dicomdata; lSelectedType: integer): integer;
-var
-   lnTypes: integer;
-   lImageOrder: bytep;
-begin
-     lDICOMdataSelectedType := lDICOMdataAllTypes;
-     if (lDICOMdataAllTypes.nOrder < 1) then
-        exit;
-    lnTypes := SortOrders(lDICOMdataAllTypes,lImageOrder);
-    if lnTypes <= lSelectedType then begin
-          TDTIRA = array [1..kMaxDTIDir] of TDTI;//TDICOM;//unsigned 8-bit int
-  TOrder= array [1..kMaxOrderVal] of byte;
-
-    end;
-    freemem(lImageOrder);
-end;  *)
-
-
-///321
-function MultiOrder(var lDICOMdata: dicomdata): integer;
-//how many slices are of the same type [magnitude, phase, etc]
-//returns 0 if all types are the same
-var
-   i: integer;
-begin
-     result := 0;
-     if (lDICOMdata.nOrder < 1) then
-        exit;
-     if (lDicomData.XYZdim[3] > kMaxOrderVal) then
-        exit;
-     result := 0;
-     for i := 1 to lDICOMdata.nOrder do begin
-         if lDICOMdata.order[i] = lDICOMdata.order[1] then
-            inc(result); //count how many have the same order as first...
-     end;
-     if result = lDICOMdata.nOrder then
-        result := 0; //all are like the first
-end;
-
-function CompressMultiOrder(var lDICOMdata: dicomdata): integer;
-//convert multiorder so values are 1..n,
-//e.g. if the values were 2,3,4 it would be converted to 1..3
-//e.g. if the values are 3,4 it will be converted to 1..2
-var
-   min,max,i,j: integer;
-   SlotUsed: boolean;
-begin
-     result := 1;
-     if (lDICOMdata.nOrder < 1) then
-        exit;
-     if (lDicomData.XYZdim[3] > kMaxOrderVal) then
-        exit;
-     min := lDICOMdata.order[1];
-     for i := 1 to lDICOMdata.nOrder do
-         if lDICOMdata.order[i] < min then
-            min := lDICOMdata.order[i]; //count how many have the same order as first...
-     max := lDICOMdata.order[1];
-     for i := 1 to lDICOMdata.nOrder do
-         if lDICOMdata.order[i] > max then
-            max := lDICOMdata.order[i]; //count how many have the same order as first...
-     result := 1;
-     for j := min to max do begin
-         SlotUsed := false;
-         for i := 1 to lDICOMdata.nOrder do begin
-             if lDICOMdata.order[i] = j then begin
-                SlotUsed := true;
-                lDICOMdata.order[i] := result;
-             end;
-         end;//for each value
-         if SLotUsed then
-            inc(result);
-     end;
-     result := result - 1;
-end;
-
-(*procedure msx (a,b,c,d: integer);
-begin
-     msg(inttostr(a)+'x'+inttostr(b)+'x'+inttostr(c)+'x'+inttostr(d));
-end;*)
-procedure SwapTimeMultiOrder (var lDICOMdata: dicomdata; var lBuffer: bytep);
-//data is stored X,Y,T,Z+some order effect (e.g. magnitude and phase stroed in the same 4D image) - swap to O,X,Y,Z,T
-var
-   Order,nOrders,lSlicesPerOrder,lSlice,l4DBytes,lSliceBytes,lZo,lTo,lZmax,lTmax,lOrderVol:integer;
-   lTempBuffer: ByteP;
-begin
-     lSlicesPerOrder := MultiOrder(lDICOMdata);
-     if (lSlicesPerOrder = 0) then
-        exit;
-     nOrders := CompressMultiOrder(lDICOMdata);
-     Msg('Swizzling with multiple ComplexImageComponents: '+inttostr(lSlicesPerOrder)+' slices per order, total '+inttostr(lDicomData.XYZdim[3])+' slices');
-     if not lDICOMdata.file4D then
-        exit;
-     lTMax := lDicomData.XYZdim[3] div lDICOMdata.SlicesPer3DVol div nOrders;
-     lZMax := lDICOMdata.SlicesPer3DVol;
-     l4DBytes :=  lDicomData.XYZdim[1]*lDicomData.XYZdim[2]*lDicomData.XYZdim[3]*trunc(((lDicomData.Allocbits_per_pixel)+7)/8);
-     lSliceBytes := lDicomData.XYZdim[1]*lDicomData.XYZdim[2]*trunc(((lDicomData.Allocbits_per_pixel)+7)/8);
-     GetMem(lTempBuffer,l4DBytes);
-     Move(lBuffer^,lTempBuffer^,l4DBytes); //move(src,dest,sz)
-     fillchar(lBuffer^,l4DBytes,0);//abba
-     lZo := 0;
-     lTo := 0;
-     lOrderVol := 0;
-     //for lSlice := 1 to lDicomData.XYZdim[3] do
-     //msg(inttostr(lDICOMdata.order[lSLice]));
-     for Order := 1 to nOrders do begin
-         for lSlice := 1 to lDicomData.XYZdim[3] do begin
-             if lDICOMdata.order[lSLice] = Order then begin
-                Move(lTempBuffer[((lSlice-1)*lSliceBytes)+1],lBuffer[(lZo*lSliceBytes)+((lOrderVol+lTo)*lZMax*lSliceBytes)+1],lSliceBytes);
-                inc(lTo);
-                if lTo >= lTMax then begin
-                   lTo := 0;
-                   inc(lZo);
-                end;
-             end; //desired order
-         end;
-         lOrderVol := lOrderVol + lTMax;
-         lZo := 0;
-     end;
-     freemem(lTempBuffer);
-end;
-
-procedure SwapTime (var lDICOMdata: dicomdata; var lBuffer: bytep);
-//data is stored X,Y,T,Z - swap to X,Y,Z,T
-var
-   lSlice,l4DBytes,lSliceBytes,lZo,lTo,lZmax,lTmax:integer;
-   lTempBuffer: ByteP;
-begin
-     if lDicomData.XYZdim[4] < 2 then
-        exit;
-     if MultiOrder(lDICOMdata) <> 0 then begin
-         SwapTimeMultiOrder (lDICOMdata,lBuffer);
-         exit;
-     end;
-     Msg('Swizzling: XYTZ -> XYZT');
-     if not lDICOMdata.file4D then
-        exit;
-     lTMax := lDicomData.XYZdim[3] div lDICOMdata.SlicesPer3DVol;
-     lZMax := lDICOMdata.SlicesPer3DVol;
-     l4DBytes :=  lDicomData.XYZdim[1]*lDicomData.XYZdim[2]*lDicomData.XYZdim[3]*trunc(((lDicomData.Allocbits_per_pixel)+7)/8);
-     lSliceBytes := lDicomData.XYZdim[1]*lDicomData.XYZdim[2]*trunc(((lDicomData.Allocbits_per_pixel)+7)/8);
-     GetMem(lTempBuffer,l4DBytes);
-     Move(lBuffer^,lTempBuffer^,l4DBytes); //move(src,dest,sz)
-     lZo := 0;
-     lTo := 0;
-     for lSlice := 1 to lDicomData.XYZdim[3] do begin
-         Move(lTempBuffer[((lSlice-1)*lSliceBytes)+1],lBuffer[(lZo*lSliceBytes)+(lTo*lZMax*lSliceBytes)+1],lSliceBytes);
-         inc(lTo);
-         if lTo >= lTMax then begin
-            lTo := 0;
-            inc(lZo);
-         end;
-     end;
-     freemem(lTempBuffer);
-end;
-
-procedure FlipTB (var lDICOMdata: dicomdata; var lBuffer: bytep);
-var
-  l16Buf : SmallIntP;
-  l32Buf : SingleP;
-  lSwap16: SmallInt;
-  lSwap32: Single;
-  lSwap8: byte;
- lXPos,lYPos,lZPos,lX,lY,lZ,lHlfY,lDecLineOffset,lLineOffset: integer;
-begin
-  lX := lDicomData.XYZdim[1];
-  lY := lDicomData.XYZdim[2];
-  lZ := lDicomData.XYZdim[3];
-  if lDicomData.SamplesPerPixel = 3 then
-     lZ := lZ * 3;
-  if  (lY < 2) then exit;
-  lHlfY := lY div 2;
-  if lDicomData.Allocbits_per_pixel = 8 then begin
-	for lZPos := 1 to lZ do begin
-		lLineOffset := (lZPos-1)*(lX*lY);
-		lDecLineOffset := lLineOffset+(lX*lY)-lX;
-	  for lYPos := 1 to lHlfY do begin
-		  for lXPos := 1 to lX do begin
-			  lSwap8 := lBuffer^[lXPos+lLineOffset];
-			  lBuffer^[lXPos+lLineOffset] := lBuffer^[lXPos+lDecLineOffset];
-			  lBuffer^[lXPos+lDecLineOffset] := lSwap8;
-		  end; //for X
-		  lLineOffset := lLineOffset + lX;
-		  lDecLineOffset := lDecLineOffset - lX;
-	  end; //for Y
-	end; //for Z
-  end else if lDicomData.Allocbits_per_pixel = 32 then begin
-	l32Buf := SingleP(lBuffer);
-	for lZPos := 1 to lZ do begin
-		lLineOffset := (lZPos-1)*(lX*lY);
-		lDecLineOffset := lLineOffset+(lX*lY)-lX;
-	  for lYPos := 1 to lHlfY do begin
-		  for lXPos := 1 to lX do begin
-			  lSwap32 := l32Buf^[lXPos+lLineOffset];
-			  l32Buf^[lXPos+lLineOffset] := l32Buf^[lXPos+lDecLineOffset];
-			  l32Buf^[lXPos+lDecLineOffset] := lSwap32;
-		  end; //for X
-		  lLineOffset := lLineOffset + lX;
-		  lDecLineOffset := lDecLineOffset - lX;
-	  end; //for Y
-	end; //for Z
-  end else begin
-	l16Buf := SmallIntP(lBuffer);
-	for lZPos := 1 to lZ do begin
-		lLineOffset := (lZPos-1)*(lX*lY);
-		lDecLineOffset := lLineOffset+(lX*lY)-lX;
-	  for lYPos := 1 to lHlfY do begin
-		  for lXPos := 1 to lX do begin
-			  lSwap16 := l16Buf^[lXPos+lLineOffset];
-			  l16Buf^[lXPos+lLineOffset] := l16Buf^[lXPos+lDecLineOffset];
-			  l16Buf^[lXPos+lDecLineOffset] := lSwap16;
-		  end; //for X
-		  lLineOffset := lLineOffset + lX;
-		  lDecLineOffset := lDecLineOffset - lX;
-	  end; //for Y
-	end; //for Z
-  end;
-end; //proc FlipTB
-
-procedure MakePlanar (var lBuffer: bytep; var lDicomData: DICOMdata);
-//data is saved as RGBRGBRGB - convert to RRRR GGGG BBBB
-var
-   lRA: bytep;
-   lPix,lnPix,lSlice,lI: integer;
-begin
-     if (lDicomData.XYZdim[1] < 1) or (lDicomData.XYZdim[2] < 1) or (lDicomData.XYZdim[3] < 1) then exit;
-     lnPix := lDicomData.XYZdim[1]*lDicomData.XYZdim[2]; //*lDicomData.XYZdim[3]
-     GetMem(lRA,3*lnPix);   //*3 as red, green, blue
-     for lSlice := 1 to lDicomData.XYZdim[3] do begin
-         lI := 1 + ((lSlice-1)* (3*lnPix)); //data from input slice
-         for lPix := 1 to lnPix do begin
-             lRA^[lPix] := lBuffer^[lI]; //red plane
-             inc(lI);
-             lRA^[lPix+lnPix] := lBuffer^[lI]; //green plane
-             inc(lI);
-             lRA^[lPix+lnPix+lnPix] := lBuffer^[lI]; //blue plane
-             inc(lI);
-         end;
-         Move(lRA^,lBuffer^[1 + ((lSlice-1)* (3*lnPix))],3*lnPix);
-     end;
-     Freemem(lRA);
-end;
-
-procedure DeMosaic (var lBuffer: bytep;lmosX,lmosY,lSlices: integer; lFlip: boolean; var lDicomData: DICOMdata);
-//unMosaic
-var
-	//lImgBytes,
-        lPos,lH,lW,lnMos,lMos,lMosW,lMosH, lStripBytes,lPanelBytes,lStartOffset: integer;
-	lTempBuffer: ByteP;
-begin
-	lnMos := lSlices;// lDICOMdata.SiemensMosaicX*lDICOMdata.SiemensMosaicY;
-	if (lmosX < 2) and (lmosY < 2) then exit;
-        if ((lmosX*lmosY) < lSlices) then begin
-            msg('This '+inttostr(lmosx)+'*'+inttostr(lmosy)+' mosaic can not hold '+inttostr(lSlices)+' slices.');
-            exit;
-        end;
-	lMosW := lDICOMdata.XYZdim[1] div lmosX;
-	lMosH := lDICOMdata.XYZdim[2] div lmosY;
-	lStripBytes := lMosW*trunc(((lDicomData.Allocbits_per_pixel)+7)/8);
-	lPanelBytes := lDICOMdata.XYZdim[1] *trunc(((lDicomData.Allocbits_per_pixel)+7)/8);
-	GetMem(lTempBuffer,lPanelBytes*lDICOMdata.XYZdim[2]);
-	Move(lBuffer^,lTempBuffer^,lPanelBytes*lDICOMdata.XYZdim[2]);
-        //lImgBytes := (lPanelBytes*lDICOMdata.XYZdim[2]);
-	lPos := 0;
-if  lFlip then begin
- //Msg('...Flip mosaic');
- for lMos :=  lnMos downto 1 do begin
-            lStartOffset := ((lMos-1) mod lmosX)*lStripBytes+ ( ((lMos-1) div lmosX)* (lPanelBytes*lMosH));
-	    for lH := 1 to lMosH do begin
-	        for lW := 1 to lStripBytes do begin
-		    inc(lPos);
-		    lBuffer^[lPos] := lTempBuffer^[lStartOffset+lW ];
-		end;
-		//lBuffer^[lPos-1] := 255;//crx
-		lStartOffset := lStartOffset + lPanelBytes;
-	    end;
-	end;
-end else begin
-	for lMos := 1 to lnMos do begin
-            lStartOffset := ((lMos-1) mod lmosX)*lStripBytes+ ( ((lMos-1) div lMosX)* (lPanelBytes*lMosH));
-	    for lH := 1 to lMosH do begin
-	        for lW := 1 to lStripBytes do begin
-		    inc(lPos);
-		    lBuffer^[lPos] := lTempBuffer^[lStartOffset+lW ];
-		end;
-		//lBuffer^[lPos-1] := 255;//crx
-		lStartOffset := lStartOffset + lPanelBytes;
-	    end;
-	end;
-end;
-  	FreeMem(lTempBuffer);
-	//FlipTB needs new coordinates
-	lDicomData.XYZdim[1] := lMosW;
-	lDicomData.XYZdim[2] := lMosH;
-	lDicomData.XYZdim[3] := lnMos;
-
-	FlipTB (lDICOMdata, lBuffer);
-end;
-
-function UnInterleaved (lVal, ln3D,ln4D: integer;lFLip: boolean): integer;
-var
-	lVol,lSlice,lOut: integer;
-begin
-	lSlice := ((lVal-1) mod ln3D) ;
-	lVol := ((lVal-1) div ln3D) ;
-	if lFlip then lSlice := ln3D-lSlice-1;
-	lOut := (lSlice*ln4D)+lVol;
-	//if lVol = 1 then Msg(inttostr(lSlice)+'  '+inttostr(lVol)+'  '+inttostr(lOut));
-	result := lOut;
-end;
-
-function UnFlip (lVal, ln3D: integer): integer;
-var
-	lVol: integer;
-begin
-	lVol := ((lVal-1) div ln3D);
-        result := lVal-((lVol)*ln3d);//{ln3D -} (lVal-((lVol-1)*ln3d));
-        result := ((lVol+1)*ln3D) - result;
-end;
-
-function CheckSliceDirection( var lD1,lD2: dicomdata):boolean;
-var
-	lFloat: single;
-begin
-	result := false;
-	lFloat := (ld2.PatientPosX-ld1.PatientPosX)-(ld2.PatientPosY-ld1.PatientPosY)-(ld2.PatientPosZ-ld1.PatientPosZ);
-	if lFloat > 0 then
-		result := true;
-	//if result then Msg('yikes'+floattostr(ld2.PatientPosX-ld1.PatientPosX)+'y'+floattostr(ld2.PatientPosY-ld1.PatientPosY)+'z'+floattostr(ld2.PatientPosZ-ld1.PatientPosZ) );
-end;
-
-function Index (lSeries,lFirstDICOM: integer; lInterleaved,lFlip: boolean; var lAHdr: TNIFTIhdr ): integer;
-begin
-     if lInterleaved then
-        result := UnInterleaved (lSeries, lAHdr.dim[3],lAHdr.dim[4],lFlip)
-     else if not lFlip then
-          result := lSeries-1
-     else
-         result := UnFlip (lSeries, lAHdr.dim[3]);
-     result := result + lFirstDICOM;
-end;
-
-//Next routines for PhilipsBVec
-  FUNCTION Vector2D  (CONST xValue, yValue, zValue:  DOUBLE):  TVector;
-  BEGIN
-    WITH RESULT DO
-    BEGIN
-      x    := xValue;
-      y    := yValue;
-      z    := zValue;
-      size := size2D
-    END
-  END; //Vector2D
-
-    // Assume vector contains 'extra' homogeneous coordinate -- ignore it.
-  procedure NormalizeVector2D(var u:  TVector);
-  var
-     lSum: double;
-  BEGIN
-      lSum := sqrt((u.x*u.x)+(u.y*u.y)+(u.z*u.z));
-      if lSum <> 0 then
-         u := Vector2D( u.x/lSum,
-                         u.y/lSum,
-                          u.z/lSum)
-  END; //NormalizeVector2D
-
-FUNCTION revMat  (CONST Input:TMatrix):  TMatrix;//Transpose Matrix
-var
-   i,j: integer;
-begin
- result.size := Input.size;
- for i := 1 to Input.size do
-     for j := 1 to Input.size do
-         result.matrix[i,j] := input.matrix[j,i];
-end;
-
-
- FUNCTION VecMatMult (CONST u:  TVector; CONST a:  TMatrix):  TVector;
-    VAR
-      i,k :  TIndex;
-      temp:  DOUBLE;
-  BEGIN
-    RESULT.size := a.size;
-    IF  a.size = u.size
-    THEN BEGIN
-      FOR i := 1 TO a.size DO
-      BEGIN
-        temp := 0.0;
-        FOR k := 1 TO a.size DO
-        BEGIN
-          temp := temp + u.vector[k]*a.matrix[i,k];
-        END;
-        RESULT.vector[i] := Defuzz(temp)
-      END;
-    END
-    ELSE raise EMatrixError.Create('VecMatMult error')
-  END;//VecMatMult
-
-(*procedure mx(lstr: string;lm: tmatrix);
-begin
-msg(lStr);
-fx(lm.matrix[1,1],lm.matrix[1,2],lm.matrix[1,3]);
-fx(lm.matrix[2,1],lm.matrix[2,2],lm.matrix[2,3]);
-fx(lm.matrix[3,1],lm.matrix[3,2],lm.matrix[3,3]);
-end;*)
-
-procedure PhilipsCorrectBvecs(var lDICOMdata:dicomdata; var lDTIra: TDTIRA; nVec: integer);
-//Test lIn.x := 0.499997615814209; lIn.y :=  0.499997615814209; lIn.z := 0.707110166549683;
-//Philips DICOM data stored in patient (LPH) space, regardless of settings in Philips user interface
-//algorithm inspired by CATNAP http://godzilla.kennedykrieger.org/~jfarrell/software_web.htm
-//http://iacl.ece.jhu.edu/~bennett/catnap/catnap.shtml
-//0018,5100. patient orientation - 'HFS'
-//2001,100B Philips slice orientation (TRANSVERSAL, AXIAL, SAGITTAL)
-//2005,1071. Philips AP angulation : -8.74086
-//2005,1072. Philips RL angulation : -3.53147
-//2005,1073. Philips FH angulation -0.387372
-(* 3/2008: updated to correct for a bug in the Johns Hopkins code:
-% July 20, 2007 | I corrected a small bug with the rotation matrices for
-% slice angulation.  I had multiplied 3 matrices in the incorrect order.
-
-% A colleague (Harsh Agarwal) pointed this out while aligning different
-% MRI contrasts using the angulation parameters and the transformation
-% matrices given in the Philips document.
-%I originally had Tang = Tfh*Tap*Trl
-%    which is now Tang = Trl*Tap*Tfh;
-%I originally had rev_Tang = rev_Trl*rev_Tap*rev_Tfh;
-%which is now     rev_Tang = rev_Tfh*rev_Tap*rev_Trl;
-% I double checked the Philips code and this seems to be correct now.
-% I also double checked the impact on fiber tracking. The fiber tracking
-% looks good in both instances (even though the gradient tables are
-% slightly different).  If 2 angulation values are zero (i.e. [AP,FH,RL]
-=
-% [0,0,20], then the old and new equations give the same result.  Only
-if
-% two or more elements are non zero is the result different.  I did some
-% testing with very large angulations of 20 degrees [20,20,0], [20,0,20]
-
-% and [0,20,20]and found that the fiber tracking results were almost
-% indistinguishable. THIS FIX ONLY affects yes overplus and
-% user-defined gradient tables. No overplus tables are not subject to
-% slice angulation changes
-*)
-
-var
-   lIn,lOut: TVector;
-   ltpp,lrev_tpp,ltpom,lrev_tpom,ltpo,lrev_tpo,ltrl,ltap,ltfh,
-   lmtemp1,lmtemp2 ,ltang,lrev_tang,
-   lrev_trl, lrev_tap, lrev_tfh,
-   lrev_tsom,ldtiextra: TMatrix;
-   lI: Integer;
-   lap,lfh,lrl: double;
-begin
-
-    if nVec < 1 then exit;
-    //require HFS - head first supine. See Catnap for alternate body orientations
-     if (length(lDicomData.PatientPos) >= 3) and (lDicomData.PatientPos[1] = 'H') and (lDicomData.PatientPos[2] = 'F') and (lDicomData.PatientPos[3] = 'S') then
-     else begin
-          Msg('DTI vector error: Position is not head first supine');
-          exit;
-     end;
-    //Assume supine
-    ltpo := Matrix2D (1,0,0,  0,1,0, 0,0,1  );
-    lrev_tpo := revMat(ltpo);
-    //Assume head first
-    ltpp := Matrix2D (0,1,0,  -1,0,0, 0,0,-1);
-    lrev_tpp := revMat(ltpp);
-    ltpom := MultiplyMatrices( ltpo, ltpp);
-    lrev_tpom := MultiplyMatrices( lrev_tpp,lrev_tpo  );
-    lap := lDicomData.AngulationAP  * PI /180;
-    lfh := lDicomData.AngulationFH  * PI /180;
-    lrl := lDicomData.AngulationRL  * PI /180;
-    //lAP:=-0.152557;  lFH:=-0.0616358;  lRL := -0.00676092;
-
-    ltrl := Matrix2D (1,0,0,                0,cos(lrl),-sin(lrl),  0,sin(lrl),cos(lrl));
-    ltap := Matrix2D (cos(lap),0,sin(lap),  0,1,0,                 -sin(lap),0,cos(lap));
-    ltfh := Matrix2D (cos(lfh),-sin(lfh),0, sin(lfh),cos(lfh),0,    0,0,1);
-    lrev_trl := revMat(ltrl);
-    lrev_tap := revMat(ltap);
-    lrev_tfh := revMat(ltfh);
-    lmtemp1 := MultiplyMatrices( ltrl, ltap );
-    ltang := MultiplyMatrices( lmtemp1, ltfh );
-    lmtemp1 := MultiplyMatrices( lrev_tfh, lrev_tap );
-    lrev_tang := MultiplyMatrices( lmtemp1, lrev_trl );
-
-    if (lDicomData.PhilipsSliceOrient[1] = 'S') then //SAGITTAL
-       lrev_tsom := Matrix2D (0,0,1,  0,-1,0, -1,0,0 )
-    else if (lDicomData.PhilipsSliceOrient[1] = 'C') then //CORONAL
-         lrev_tsom := Matrix2D (0,0,1,  -1,0,0, 0,1,0 )
-    else //TRANSVERSAL = AXIAL
-        lrev_tsom := Matrix2D (0,-1,0,  -1,0,0, 0,0,1 );
-    ldtiextra := Matrix2D (0,-1,0,  -1,0,0, 0,0,1 );
-    lmtemp2 := MultiplyMatrices( ldtiextra, lrev_tsom );
-    lmtemp1 := MultiplyMatrices (lmtemp2, lrev_tang);
-
-    for lI := 1 to nVec do begin
-
-        if (lDTIra[lI].bval <= 0) or  ((lDTIra[lI].v1 = 0) and (lDTIra[lI].v2 = 0) and (lDTIra[lI].v3 = 0)) then begin
-            lDTIra[lI].v1 := 0;
-            lDTIra[lI].v2 := 0;
-            lDTIra[lI].v3 := 0;
-        end else begin
-            //lIn := Vector2D(0.7071, -0.7071, -0.0000);
-            lIn := Vector2D(-lDTIra[lI].v1,-lDTIra[lI].v2,-lDTIra[lI].v3);
-            NormalizeVector2D(lIn);
-            lout := VecMatMult (lin,lmtemp1);
-            NormalizeVector(lout);
-            lDTIra[lI].v1 := lOut.x;
-            if lOut.y = 0 then
-                lDTIra[lI].v2 := lOut.y //people dislike seeing -0
-            else
-                lDTIra[lI].v2 := -lOut.y; //flip Y component
-            lDTIra[lI].v3 := lOut.z;
-        end;
-    end; //for each vector
-end;
-
-function VV (lLabel: string; var lV: TVector): string;
-begin
-     result := lLabel +' =['+ floattostr(lV.x)+','+floattostr(lV.y)+','+ floattostr(lV.z)+']'';';
-end;
-
-procedure VTX (var bvecs_old,slice_dir,read_dir,phase_dir: TVector);
-var  lStr : string;
-begin
-      lStr := '';
-      lStr := lStr + VV('bvecs_old',bvecs_old);
-      lStr := lStr + VV('slice_dir',slice_dir);
-      lStr := lStr + VV('read_dir',read_dir);
-      lStr := lStr + VV('phase_dir',phase_dir);
-      msg(lStr);
-
-end;
-
-procedure SiemensCorrectBvecs (var lDICOMdata:dicomdata; var lDTIra: TDTIra; nVec: integer);
-//see  http://users.fmrib.ox.ac.uk/~robson/internal/Dicom2Nifti111.m
-var
-   lI: integer;
-   read_vector ,phase_vector,slice_vector,bvecs_old,bvecs_new: TVector;
-begin
-     if nVec < 1 then exit;
-     if (length(lDicomData.PatientPos) >= 3) and (lDicomData.PatientPos[1] = 'H') and (lDicomData.PatientPos[2] = 'F') and (lDicomData.PatientPos[3] = 'S') then
-     else begin
-          Msg('DTI vector error: Position is not head first supine');
-          exit;
-     end;
-    //fx(lDTI.v1,lDTI.v2,lDTI.v3);
-    read_vector := Vector3D(lDICOMData.Orient[1],lDICOMData.Orient[2],lDICOMData.Orient[3]);
-    phase_vector := Vector3D(lDICOMData.Orient[4],lDICOMData.Orient[5],lDICOMData.Orient[6]);
-    slice_vector := CrossProduct(read_vector ,phase_vector);
-
-    NormalizeVector(read_vector);
-    NormalizeVector(phase_vector);
-    NormalizeVector(slice_vector);
-    for lI := 1 to nVec do begin
-        if (lDTIra[lI].bval <= 0) or  ((lDTIra[lI].v1 = 0) and (lDTIra[lI].v2 = 0) and (lDTIra[lI].v3 = 0)) then begin
-            lDTIra[lI].v1 := 0;
-            lDTIra[lI].v2 := 0;
-            lDTIra[lI].v3 := 0;
-        end else begin
-            bvecs_old := Vector3D(lDTIra[lI].v1,lDTIra[lI].v2,lDTIra[lI].v3);
-            VTX (bvecs_old,slice_vector,read_vector,phase_vector );
-            bvecs_new :=Vector3D(DotProduct(bvecs_old,read_vector),DotProduct(bvecs_old,phase_vector),DotProduct(bvecs_old,slice_vector) );
-            bvecs_new.y := - bvecs_new.y;
-            NormalizeVector(bvecs_new);
-            lDTIra[lI].v1 := bvecs_new.x;
-            lDTIra[lI].v2 := bvecs_new.y;
-            lDTIra[lI].v3 := bvecs_new.z;
-        end;
-    end;//for each bvec
-end;
-
-procedure SiemensFlipYBvecs (var lDTIra: TDTIra; nVec: integer);
-var
-   lI: integer;
-   V: double;
-begin
-     if nVec < 1 then exit;
-    for lI := 1 to nVec do begin
-        if lDTIra[lI].v2 <> 0 then //people do not like seeing -0, even though this is a valid ieee value
-           lDTIra[lI].v2 := -lDTIra[lI].v2;
-    end;
-    //next: normalize
-    for lI := 1 to nVec do begin
-
-        V := sqr(lDTIra[lI].v1)+ sqr(lDTIra[lI].v2)+sqr(lDTIra[lI].v3);
-        if V = 0 then
-           V := 1
-        else
-            V := sqrt(V);
-
-        lDTIra[lI].v1 := lDTIra[lI].v1/V;
-        lDTIra[lI].v2 := lDTIra[lI].v2/V;
-        lDTIra[lI].v3 := lDTIra[lI].v3/V;
-    end;
-
-end;
-
-procedure GECorrectBvecs (var lDICOMdata:dicomdata; var lDTIra: TDTIra; nVec: integer);
-//0043,1039 (or 0043,a039). b value (as the first number in the string).
-//0019,10bb (or 0019,a0bb). X diffusion direction
-//0019,10bc (or 0019,a0bc). Y diffusion direction
-//0019,10bd (or 0019,a0bd). Z diffusion direction
-//These directions are relative to freq,phase,slice, so although no
-//transformations are required, you need to check the direction of the
-//phase encoding. This is in DICOM message 0018,1312. If this has value
-//COL then if swap the x and y value and reverse the sign on the z value.
-//If the phase encoding is not COL, then just reverse the sign on the x value.
-var
-   lI: integer;
-   lCol: boolean;
-   lSwap: double;
-begin
-     if nVec < 1 then exit;
-     if (length(lDicomData.PatientPos) >= 3) and (lDicomData.PatientPos[1] = 'H') and (lDicomData.PatientPos[2] = 'F') and (lDicomData.PatientPos[3] = 'S') then
-     else begin
-          Msg('DTI vector error: Position is not head first supine');
-          exit;
-     end;
-     if  (length(lDicomData.PhaseEncoding) >= 3)  and (lDicomData.PhaseEncoding[1] = 'C') and (lDicomData.PatientPos[2] = 'O') and (lDicomData.PatientPos[3] = 'L') then
-        lCol := true
-     else
-         lCol := false;
-    for lI := 1 to nVec do begin
-        if (lDTIra[lI].bval <= 0) or  ((lDTIra[lI].v1 = 0) and (lDTIra[lI].v2 = 0) and (lDTIra[lI].v3 = 0)) then begin
-            lDTIra[lI].v1 := 0;
-            lDTIra[lI].v2 := 0;
-            lDTIra[lI].v3 := 0;
-        end else begin  //if bval=0 or null vector, else real vector
-            if lCol then begin
-               lSwap := lDTIra[lI].v1;
-               lDTIra[lI].v1 := lDTIra[lI].v2;
-               lDTIra[lI].v2 := lSwap;
-               lDTIra[lI].v3 := -lDTIra[lI].v3;
-            end else begin
-               lDTIra[lI].v1 := -lDTIra[lI].v1;
-               lDTIra[lI].v2 := lDTIra[lI].v2;
-               lDTIra[lI].v3 := lDTIra[lI].v3;
-            end;
-        end; //real vector  - not 0,0,0
-    end;//for each bvec
-end;
-
-(*procedure doBVecs;
-var
- lDICOMData:dicomdata;
- lDTI: TDTI;
-
-begin
-    lDICOMData.Orient[1] := 0.99872048491662;
-    lDICOMData.Orient[2] :=  -0.0015021527936;
-    lDICOMData.Orient[3] :=  -0.0505483584788;
-    lDICOMData.Orient[4] :=  -1.12378993e-008;
-    lDICOMData.Orient[5] :=  0.99955873135595;
-    lDICOMData.Orient[6] :=  -0.0297042517172;
-    lDTI.v1 := 0.99899346;
-    lDTI.v2 :=  0.00503525;
-    lDTI.v3 := -0.00604230;
-    correctBvecs(lDICOMdata, lDTI);
-
-end; *)
-
-
-
-function MkDICOMDir (var lDICOMdata: DICOMdata;  var lOutDir: string): boolean;
-var
-   lBlank,lName: string;
-   lPrefs: TPrefs;
-begin
-  result := false;
-  if not direxists(lOutDir) then
-     exit;
-  lBlank := '';
-  lPrefs.AppendDate := true;
-  lPrefs.AppendAcqSeries := false;
-  lPrefs.AppendProtocolName := false;
-  lPrefs.AppendPatientName := true;
-  lPrefs.AppendFilename := false;
-  lName := OutputFilename(lBlank,lDicomData, lPrefs);
-  if lName = '' then
-     exit;
-  lOutDir := lOutDir +lName;
-  Msg('Creating folder '+lOutDir);
-  {$I-}
-  MkDir(lOutDir);
-  if IOResult <> 0 then begin
-    //MessageDlg('Cannot create directory', mtWarning, [mbOk], 0)
-  end;
-
-  {$I+}
-
-  lOutDir := lOutDir + pathdelim;
-  result := true;
-end;
-
-procedure afx(lDICOMImgName: string; lDTI:TDTI; Pos: integer);
-begin
-   msg(extractfilename(lDicomImgName)+':'
-             +floattostr(lDTI.bval)+': '
-             +floattostr(lDTI.v1)+': '
-             +floattostr(lDTI.v2)+': '
-             +floattostr(lDTI.v3)+ ' @ '
-             +inttostr(Pos));
-end;
-
-function ImageScalingOrIntensityVaries(var lDICOMra: TDICOMrap; lFirstDICOM, lLastDICOM: integer): boolean;
-var
-  lIndex: integer;
-begin
-  result := false;
-  if (lFirstDICOM >= lLastDICOM) then exit; //only one image
-  result := true;
-  for lIndex := (lFirstDICOM +1) to lLastDICOM do begin
-    if lDICOMra^[lIndex].IntenIntercept <> lDICOMra^[lFirstDICOM].IntenIntercept then
-		  exit; //1492
-    if lDICOMra^[lIndex].IntenScale <> lDICOMra^[lFirstDICOM].IntenScale then
-		  exit; //1492
-    if lDICOMra^[lIndex].Allocbits_per_pixel <> lDICOMra^[lFirstDICOM].Allocbits_per_pixel then
-      exit;
-  end;
-  result := false;
-end;
-
-procedure MakeFloat (var lBuffer: bytep; var lDicomData: DICOMdata; var lSliceBytesOut: integer);
-//data is saved as RGBRGBRGB - convert to RRRR GGGG BBBB
-var
-   lRA: bytep;
-   lPix,lnPix,lnBytes: integer;
-   l8i : byteP;
-   l16ui : WordP;
-   l16i: SmallIntP;
-   l32i: LongIntP;
-   l32fo, l32f: SingleP;
-   lByteSwap: boolean;
-begin
-     if (lDicomData.XYZdim[1] < 1) or (lDicomData.XYZdim[2] < 1) or (lDicomData.XYZdim[3] < 1) then exit;
-     Msg(' Converting data to 32-bit float to correct for differences slope/intercept/precision: '+chr(9)+realtostr(lDicomData.IntenScale,8)+chr(9)+realtostr(lDicomData.IntenIntercept,8)+chr(9)+inttostr(lDicomData.Allocbits_per_pixel));
-       {$IFDEF ENDIAN_BIG}
-  lByteSwap := odd(lDICOMdata.little_endian);
-  {$ELSE}
-  lByteSwap := not odd(lDICOMdata.little_endian);
- {$ENDIF}
-     lnPix := lDicomData.XYZdim[1]*lDicomData.XYZdim[2]*lDicomData.XYZdim[3];
-     //msg('  '+inttostr(lDicomData.XYZdim[1])+' '+inttostr(lDicomData.XYZdim[2])+' '+inttostr(lDicomData.XYZdim[3]) );
-     lnBytes := lnPix *trunc(((lDicomData.Allocbits_per_pixel)+7)/8);
-     GetMem(lRA,lnBytes );
-     Move(lBuffer^,lRA^,lnBytes); //move(src,dest,sz)
-     Freemem(lBuffer);
-     GetMem(lBuffer,lnPix * 4); //save as 32 bit float: 4 bytes per pixel
-     l32fo := SingleP(@lBuffer^[1]);
-     if lDicomData.Allocbits_per_pixel = 8 then begin //8bit - byte swapping is not a problem...
-      for lPix := 1 to lnPix do
-         l32fo^[lPix] := lRA^[lPix]*lDicomData.IntenScale + lDicomData.IntenIntercept;
-     end; //8bit
-     //next 16 bit
-     if (lDicomData.Allocbits_per_pixel = 16) and (lByteSwap) then begin //UNSWAP 16bit
-      l16ui := WordP(@lRA^[1]);
-
-      for lPix := 1 to lnPix do
-         l16ui^[lPix] := swap(l16ui^[lPix]);
-     end; //UNSWAP 16bit
-     if (lDicomData.Allocbits_per_pixel = 16) and (not lDicomData.SignedData) then begin //16bit UNSIGNED
-
-      l16ui := WordP(@lRA^[1]);
-      for lPix := 1 to lnPix do
-         l32fo^[lPix] := l16ui^[lPix]*lDicomData.IntenScale + lDicomData.IntenIntercept;
-     end; //16bit UNSIGNED
-     if (lDicomData.Allocbits_per_pixel = 16) and (lDicomData.SignedData) then begin //16bit SIGNED
-      l16i := SmallIntP(@lRA^[1]);
-      for lPix := 1 to lnPix do
-         l32fo^[lPix] := l16i^[lPix]*lDicomData.IntenScale + lDicomData.IntenIntercept;
-     end; //16bit SIGNED
-     //NEXT 32bit
-     if (lDicomData.Allocbits_per_pixel = 32) and (not lDicomData.FloatData) then begin //UNSWAP 32bit
-      l32i := LongIntP(@lRA^[1]);
-      for lPix := 1 to lnPix do
-         pswap4i(l32i^[lPix]);
-     end; //UNSWAP 32bit
-     if (lDicomData.Allocbits_per_pixel = 32) and (not lDicomData.FloatData) then begin //32bit INTEGER
-      l32i := LongIntP(@lRA^[1]);
-      for lPix := 1 to lnPix do
-         l32fo^[lPix] := l32i^[lPix]*lDicomData.IntenScale + lDicomData.IntenIntercept;
-     end; //32bit INTEGER
-     if (lDicomData.Allocbits_per_pixel = 32) and ( lDicomData.FloatData) then begin //32bit FLOAT
-      l32f := SingleP(@lRA^[1]);
-      for lPix := 1 to lnPix do
-         l32fo^[lPix] := l32f^[lPix]*lDicomData.IntenScale + lDicomData.IntenIntercept;
-     end; //32bit FLOAT
-     Freemem(lRA);
-     lDicomData.Allocbits_per_pixel := 32;
-     lDicomData.FloatData := true;
-     lDicomData.IntenScale := 1;
-     lDicomData.IntenIntercept := 0;
-     lSliceBytesOut := lnPix * 4;
-end;
-
-function Dicom2NII(var lDICOMra: TDICOMrap; lFirstDICOM, lLastDICOM: integer; var lOutDirOrig: string; var lPrefs: TPrefs; lVols: integer): boolean;
-var
-  lVolBytesOut, lVolOffset, lVolOffsetInit : Int64; //2013: 64-bit support
- //lSliceBytesOut, lvolBytesOut, lvolOffset, lvolOffsetInit: integer;
- lPref: TPrefs;
- lDTIra: TDTIra;
- lVolGb : double;
- lSliceBytesOut,
- lAllocSLiceSz, lDTIdir,lRGB,
- lStart,lEnd,lmosX,lmosY,lIndex,lSecondDICOM,lSeries,lnSeries,lSliceBytes,lMosaicSlices:integer;
- //lBaseBitDepth,
-
- //lBaseIntenScale,lBaseIntenIntercept,
- lDX: single;
- //lDynStr,
- lDicomImgName,lOutHdrName,lOutImgName,lOutImgNameGZ,lOutDir,lOutDTIname:string;
- lDICOMData:dicomdata;
- lReadOK,lFlip,lIntenScaleVaries,lInterleaved,lFlipMosaic,lVolSave,lByteSwap : boolean;
- lAHdr: TNIFTIhdr;
- lTextF: TextFile;
- lOutF,lInF: File;
- lvBuffer,lsBuffer: bytep;
-begin
-  if lPrefs.DebugMode2 then begin
-
-        Msg( DICOMstr(1,lDICOMra,OutputFilename(lDicomImgName,lDICOMra^[lFirstDICOM],lPref)));
-        Msg(inttostr(lDICOMdata.XYZdim[1])+'x'+inttostr(lDICOMdata.XYZdim[2])+'x'+inttostr(lDICOMdata.XYZdim[3])+'x'+inttostr(lDICOMdata.XYZdim[4]));
-        result := true;
-        exit;
-  end;
-  result := false;
-
-  lPref := lPrefs;
-  CorrectPrefs(lPref);
-  lmosX := 1;
-  lmosY := 1;
-  lSecondDICOM := lFirstDICOM+1;
-
-  lInterleaved := false;
-
-  lnSeries :=  (lLastDICOM+1) -lFirstDICOM; //e.g. first=10, last=10 means 1 image
-  if lnSeries < 1 then
-	  exit;
-  //next if magnitude and phase maps are saved in the same 4D file, extract to separate files...
-  if (lDICOMra^[lFirstDICOM].file4D) and (MultiOrder(lDICOMra^[lFirstDICOM]) > 0) then
-     lPref.fourD := false;
-  lDicomImgName := lDICOMra^[lFirstDICOM].Filename;
-  lDicomData := lDICOMra^[lFirstDICOM];
-
-
-  if (lDicomData.SamplesPerPixel = 3) then begin
-      Msg('Warning: RGB to NIfTI conversion poorly tested: '+lDicomImgName);
-  end;
-  {$IFDEF ENDIAN_BIG}
-  lByteSwap := odd(lDICOMdata.little_endian);
-   (*if (lDicomData.CSAImageHeaderInfoPos > 0) or (lDicomData.CSAImageHeaderInfoSz >0) then begin
-     lDicomData.CSAImageHeaderInfoPos := 0;
-     lDicomData.CSAImageHeaderInfoSz := 0;
-     Msg('Warning: Modern Siemens CSA headers not supported on obsolete big-endian PowerPC computers. DTI vectors and mosaic slice positioning may be inaccurate.');
-   end; *)
-
-  {$ELSE}
-  lByteSwap := not odd(lDICOMdata.little_endian);
- {$ENDIF}
-  lMosaicSlices := lDicomData.SiemensSlices;
-  lOutDir := ExtractFileDirWithPathDelim2(lOutDirOrig);
-  if (lOutDir = '') then begin
-	lOutDir := ExtractFilePath(lDicomImgName);
-  end;
-  if not DirWritePermission(lOutDir) then begin // <- tested with Unix
-      Msg('Error: output directory is read-only: '+lOutDir);
-      exit;
-  end;
-  if lPref.createoutputfolder then
-     MkDICOMDir(lDICOMdata,lOutDir);
-  if not direxists(lOutDir) then begin
-	Msg('Unable to find output directory '+lOutDir);
-	lOutDir := ExtractFileDirWithPathDelim2(lDicomImgName)
-  end; //else directory exists
-
-
- //lOutHdrName :=lOutDir+OutputFilename(lDicomImgName,lDicomData,lPrefs.AppendDate,lPrefs.AppendAcqSeries,lPrefs.AppendProtocolName,lPrefs.AppendPatientName,lPrefs.FourD,lPrefs.AppendFilename)+'.hdr';
-	lOutHdrName :=lOutDir+OutputFilename(lDicomImgName,lDicomData,lPref)+'.hdr';
-	lOutImgName :=changefileext(lOutHdrName,'.img');
-	if lPref.SingleNIIFile then begin
-		lOutHdrName :=  changefileext(lOutHdrName,'.nii');
-		lOutImgName := lOutHdrName;
-	end;
-	if (lPref.SingleNIIFile) and (lPref.GZip) then begin
-		lOutHdrName := lOutHdrName+'.gz';
-		if (not UniqueFileName(lOutHdrName))  then begin
-			Msg('File already exists '+lOutImgName+' '+lOutHdrName);
-			exit;
-		end;
-		//we now need to remove the .gz - not that unique filename may have appended postfix, e.g. filename.nii.gz -> filenameA.nii.gz
-		StripGZExt(lOutHdrName);
-		lOutImgName := lOutHdrName;
-	end else begin
-		if (not UniqueFileName(lOutHdrName)) or (not UniqueFileName(lOutImgName)) then begin
-			Msg('File already exists '+lOutImgName+' '+lOutHdrName);
-			exit;
-		end;
-	end;
-	Msg(extractfilename(lDicomImgName)+'->'+extractfilename(lOutImgName));
-	DICOM2AnzHdr(lAHdr,lPref.Anonymize,lDicomImgName,lDICOMdata);
-  if lPrefs.DebugMode2 then begin
-      Msg(inttostr(lDICOMdata.SlicesPer3DVol )+'  '+inttostr(lVols)+'   '+inttostr(lnSeries));
-      Msg(inttostr(lDICOMdata.XYZdim[1])+'x'+inttostr(lDICOMdata.XYZdim[2])+'x'+inttostr(lDICOMdata.XYZdim[3])+'x'+inttostr(lDICOMdata.XYZdim[4]));
-        result := true;
-        exit;
-  end;
-
-
-        if (lVols > 1) and ((lnSeries mod lVols)=0) then
-           lDICOMdata.SlicesPer3DVol := round(lnSeries/lVols);
-        lDTIra[1].bval := -1; //not DTI
-        lDTIdir := 0;
-
-        IsSiemensDTI(lDicomData,lDTIra[1], lDicomImgName, lPrefs);//see if this is a Siemens DTI image - mosaics in B13, non-mosaic in B12
-	if (lDICOMdata.SiemensMosaicX > 1) or (lDICOMdata.SiemensMosaicY > 1) then begin
-           lFlipMosaic := IsNormalMosaic(lDicomData,lMosaicSlices, lDicomImgName);
-	   lAHdr.dim[1] := lDicomData.XYZdim[1] div lDICOMdata.SiemensMosaicX;
-	   lAHdr.dim[2] := lDicomData.XYZdim[2] div lDICOMdata.SiemensMosaicY;
-           lmosX := lDICOMdata.SiemensMosaicX;
-           lmosY := lDICOMdata.SiemensMosaicY;
-           //lSlices := lDICOMdata.SiemensSlices;//(lDicomImgName,'NumberOfImagesInMosaic');
-           if lMosaicSlices > 1 then
-              lAHdr.dim[3] := lMosaicSlices
-           else
-               lAHdr.dim[3] := lDICOMdata.SiemensMosaicX *lDICOMdata.SiemensMosaicY;
-	   lAHdr.dim[4] := lnSeries;
-           if ((lmosX*lmosY) < lAHdr.dim[3]) then begin
-              msg('Aborted '+lDicomData.Filename+ ' : This '+inttostr(lmosx)+'*'+inttostr(lmosy)+' mosaic can not hold '+inttostr(lAHdr.dim[3])+' slices.');
-              exit;
-           end;
-
-	end else if lDICOMdata.File4D then begin//(lDicomData.XYZdim[3] > 1) and (lnSeries = 1) and (lDICOMdata.SlicesPer3DVol > 1) and ((lAHdr.dim[3] mod lDICOMdata.SlicesPer3DVol)=0) then begin
-                lAHdr.dim[4] := lAHdr.dim[3] div lDICOMdata.SlicesPer3DVol;
-                lAHdr.dim[3] := lDICOMdata.SlicesPer3DVol;
-
-	end else if (lDicomData.XYZdim[3] > 1) then
-		lAHdr.dim[4] := lnSeries
-	else begin
-             if (lDICOMdata.SlicesPer3DVol > 1) and ((lnSeries mod lDICOMdata.SlicesPer3DVol)=0)  then begin
-	        lAHdr.dim[3] := lDICOMdata.SlicesPer3DVol;
-		lAHdr.dim[4] := round(lnSeries / lDICOMdata.SlicesPer3DVol);
-                if (lnSeries > 1) and (DICOMinterslicedistance( lDICOMra^[lFirstDICOM], lDICOMra^[lSecondDICOM]) < 0.01) then
-                   lInterleaved := true;
-             end else
-                 lAHdr.dim[3] := lnSeries;
-	end;
-	lFlip := false;
-	if lnSeries > 1 then  begin//check slice order
-		lFlip := CheckSliceDirection(lDICOMra^[lFirstDICOM],lDICOMra^[lLastDICOM]);
-		if lFlip then begin
-			lDicomImgName := lDICOMra^[lLastDICOM].Filename;
-                        lDICOMdata := lDICOMra^[lLastDICOM];
-		end;
-	end;
-  //next compute dx between slices
-  if (lAHdr.dim[3] > 1) and (lnSeries > 1) and (lDICOMdata.SiemensMosaicX <2)  then begin
-        lDX := abs(DICOMinterslicedistance( lDICOMra^[ Index (1,lFirstDICOM,lInterleaved,lFlip,lAHdr)], lDICOMra^[ Index (2,lFirstDICOM,lInterleaved,lFlip,lAHdr)]) );
-        if lDX <> 0 then begin
-           lDicomData.XYZmm[3] := lDX;
-           lAHdr.pixdim[3]  := lDX;
-        end;
-  end;
-	dicom_2_nifti(lDICOMdata,lAHdr,lMosaicSlices,lFlipmosaic);
-
-  //all slices in a NIFTI image must be of the same precision and have the same scaling intercept and slope - see if this applies
-  (*lBaseIntenScale := lDICOMdata.IntenScale;
-  lBaseIntenIntercept := lDICOMdata.IntenIntercept;
-  lBaseBitDepth := lDicomData.Allocbits_per_pixel;
-  lIntenScaleVaries := false;
-  for lSeries := 1 to lnSeries do begin
-    lIndex :=  Index (lSeries,lFirstDICOM,lInterleaved,lFlip,lAHdr);
-    if lDICOMra^[lIndex].IntenIntercept <> lBaseIntenIntercept then
-		  lIntenscaleVaries := true; //1492
-    if lDICOMra^[lIndex].IntenScale <> lBaseIntenScale then
-		  lIntenscaleVaries := true; //1492
-    if lDICOMra^[lIndex].Allocbits_per_pixel <> lBaseBitDepth then
-      lIntenscaleVaries := true;
-  end; //for lnSeries   *)
-  lIntenScaleVaries := ImageScalingOrIntensityVaries(lDICOMra, lFirstDICOM, lLastDICOM);
-
- (* for lSeries := 1 to lnSeries do begin
-                lIndex :=  Index (lSeries,lFirstDICOM,lInterleaved,lFlip,lAHdr);
-                lDicomData := lDICOMra^[lIndex];
-
-                msgfx(lSeries, lDICOMdata.DTI[1].v1,lDICOMdata.DTI[1].v2,lDICOMdata.DTI[1].v3);
-  end; *)
-  //exit;//get out of here - crucial critical -- last chance before data saved to disk
-     
-    if (lAHdr.bitpix = 8) and (lDicomData.SamplesPerPixel = 3) then begin
-       if (lIntenScaleVaries) then begin
-          msg('RGB files can not have varying intensity scales!');
-          lIntenScaleVaries := false;
-       end;
-       lRGB := 3;
-       lAHdr.datatype := kDT_RGB;
-       lAHdr.bitpix := 24;
-    end else
-        lRGB := 1;
-    if (lIntenScaleVaries) then begin
-       lAHdr.datatype := kDT_FLOAT;
-       lAHdr.bitpix := 32;
-       Msg('Warning: images have different precision or intensity scaling - saving as 32-bit float');
-    end;
-	lSliceBytes := lDicomData.XYZdim[1]*lDicomData.XYZdim[2]*lDicomData.XYZdim[3]*trunc(((lDicomData.Allocbits_per_pixel)+7)/8)*lRGB;
-	GetMem(lsBuffer,lSliceBytes);
-
-        lSliceBytesOut :=lAHdr.dim[1]*lAHdr.dim[2]*lAHdr.dim[3]*trunc((lAHdr.bitpix+7)/8)*lRGB;
-        lVolBytesOut := lSliceBytesOut * lAHdr.dim[4];
-        lVolOffset := 1;
-        lVolGB := (lSliceBytesOut/ 1073741824) * lAHdr.dim[4]; //bytes *1024 (kB) *1024 (Mb) * 1024 (Gb)
-        //note.nii files are 352bytes larger than calculated by lVolGb...
-        //Msg(floattostr(lVolGb)+' Gb');
-        if (lPrefs.maxGb64bit = 0) or (lVolGb <= lPrefs.maxGb64bit) then //maxGb64bit
-           lVolSave := true
-        else begin
-             Msg('Very large volume: '+floattostr(lVolGb)+' Gb: slice-by-slice conversion required.');
-             lVolSave := false;
-        end;
-	  if lVolSave then begin //save entire volume
-             if lPref.SingleNIIFile then begin
-                lVolOffset := kNIIImgOffset+1;// 353; //first 352 bytes empty
-                lVolBytesOut := lVolBytesOut + lVolOffset -1;
-             end else
-             lVolOffset := 1;
-
-             GetMem(lvBuffer,lVolBytesOut);
-
-        //showmessage(inttostr(lVolBytesOut));
-        //we could copy NIfTI header to Buffer, but this would need to be changed for
-        //4D->3D images or images where we swap 3rd and 4th dimension....
-      end else begin //save slice by slice - slower but low RAM usage...
-            if not SaveHdr (lOutHdrName,lAHdr, false,lPref.SPM2) then begin
-               Msg('Error saving data - do you have permission and space for '+lOutHdrName+'?');
-               exit;
-            end;
-            Filemode := 2;
-	    AssignFile(lOutF, lOutImgName);
-	    if lPref.SingleNIIFile then begin
-		Reset(lOutF,1);
-		Seek(lOutF,352);
-                lAHdr.vox_offset := 352;
-            end else
-		Rewrite(lOutF,1);
-        end; //end slice-bylslice
-	Filemode := 0; //set to read only
-        lVolOffsetInit := lVolOffset;
-	for lSeries := 1 to lnSeries do begin
-            lIndex :=  Index (lSeries,lFirstDICOM,lInterleaved,lFlip,lAHdr);
-                lDicomImgName := lDICOMra^[lIndex].Filename;
-                lDicomData := lDICOMra^[lIndex];
-                if (lDICOMdata.ManufacturerID = kPhilipsID) and (lDICOMdata.nDTIdir > 1) and (lAHdr.dim[4] < kMaxDTIDir) and (lDICOMdata.nDTIdir >= lAHdr.dim[4]) then begin //
-                   Msg('4D Philips DTI data '+inttostr(lDICOMdata.nDTIdir));
-                   for lDTIdir := 1 to lAHdr.dim[4] do begin
-                       lDTIra[lDTIdir].bval := lDICOMdata.DTI[lDTIdir].bval;
-                       lDTIra[lDTIdir].v1 := lDICOMdata.DTI[lDTIdir].v1;
-                       lDTIra[lDTIdir].v2 := lDICOMdata.DTI[lDTIdir].v2;
-                       lDTIra[lDTIdir].v3 := lDICOMdata.DTI[lDTIdir].v3;
-                   end;
-                   lDTIdir := lAHdr.dim[4];
-                end else if (lDICOMdata.ManufacturerID = kSiemensID) and (lDTIra[1].Bval >= 0) and (lDTIdir < kMaxDTIDir) and ( ((lSeries mod lAHdr.dim[3]) = 1)  or((lMosX > 1) or (lMosY > 1))) then begin //
-                   inc(lDTIdir);
-                   IsSiemensDTI(lDicomData,lDTIra[lDTIdir], lDicomImgName,lPrefs);
-
-                end else if (lDICOMdata.nDTIdir = 1) and (lDICOMdata.DTI[1].Bval >= 0) and (lDTIdir < kMaxDTIDir) and ( (lSeries mod lAHdr.dim[3]) = 1)   then begin //
-                   inc(lDTIdir);
-                   lDTIra[lDTIdir].bval := lDICOMdata.DTI[1].bval;
-                   lDTIra[lDTIdir].v1 := lDICOMdata.DTI[1].v1;
-                   lDTIra[lDTIdir].v2 := lDICOMdata.DTI[1].v2;
-                   lDTIra[lDTIdir].v3 := lDICOMdata.DTI[1].v3;
-                end;
-                lReadOK := true;
-                if (lDicomData.JPEGLosslessCpt) then begin
-                   AssignFile(lInF, lDicomImgName);
-                   Reset(lInF,1);
-                   //lDICOMdata.CompressSz := FileSize(lInF)-lDicomData.CompressOffset;
-                   Filemode := 0;  //ReadONly
-                   //lSliceBytesOut := lSliceBytes;
-                   Msg('Decoding lossless '+inttostr(lDICOMdata.XYZdim[1])+'x'+inttostr(lDICOMdata.XYZdim[2])+' JPEG starting from byte '+ inttostr(lDicomData.CompressOffset)+' with '+inttostr(lDICOMdata.CompressSz)+' bytes');
-                   if ( lDicomData.XYZdim[3] > 1) or ( lDicomData.XYZdim[4] > 1) then
-                    msg('*Warning: this software will only convert the first slice of this multislice lossless compressed JPEG');
-                   lAllocSLiceSz := (lDICOMdata.XYZdim[1]*lDICOMdata.XYZdim[2] * lDICOMdata.Allocbits_per_pixel+7) div 8 ;
-                   DecodeJPEG(lInF,SmallIntP0(lsBuffer),ByteP0(lsBuffer),lAllocSliceSz,lDicomData.CompressOffset,lDICOMdata.CompressSz,false);
-                   CloseFile(lInF);
-                   (*FlipTB(lDICOMdata,lsBuffer);
-                   if lVolSave then begin{save entire volume}
-                       Move(lsBuffer^,lvBuffer^[lvolOffset],lSliceBytesOut);
-                       //Msg(inttostr(lSeries));
-                       lVolOffset := lVolOffset + lSliceBytesOut;
-                   end else begin //save slice-by-slice
-                      Filemode := 2;  //read and write
-		                BlockWrite(lOutF, lsBuffer^, lSliceBytesOut);
-                   end;*)
-                end else if (FSize(lDicomImgName) >= (lSliceBytes+lDicomData.imagestart)) then begin
-                  Filemode := 0;  //ReadONly
-                  AssignFile(lInF, lDicomImgName);
-		              Reset(lInF,1);
-		              Seek(lInF,lDicomData.imagestart);
-                  Filemode := 0;  //ReadONly
-                  BlockRead(lInF, lsBuffer^, lSliceBytes);
-                  CloseFile(lInF);
-                  (*if (lDICOMdata.file4D) and (lPrefs.Swizzle4D) then
-                    SwapTime(lDICOMdata,lsBuffer);//data is stored X,Y,T,Z - swap to X,Y,Z,T
-                  lSliceBytesOut := lSliceBytes;
-                  if (lDICOMdata.PlanarConfig = 0) and (lDicomData.SamplesPerPixel = 3) then
-                       MakePlanar(lsBuffer,lDICOMdata);
-                  if (lMosX > 1) or (lMosY > 1) then begin
-			                  DeMosaic(lsBuffer,lmosX,lmosY,lMosaicSlices,lFlipMosaic,lDICOMdata);
-                        lSliceBytesOut :=lAHdr.dim[1]*lAHdr.dim[2]*lAHdr.dim[3]*trunc(((lDicomData.Allocbits_per_pixel)+7)/8);
-		              end else
-			              FlipTB(lDICOMdata,lsBuffer);
-
-                   if lVolSave then begin{save entire volume}
-                       Move(lsBuffer^,lvBuffer^[lvolOffset],lSliceBytesOut);
-                       lVolOffset := lVolOffset + lSliceBytesOut;
-                   end else begin //save slice-by-slice
-                      Filemode := 2;  //read and write
-		                  BlockWrite(lOutF, lsBuffer^, lSliceBytesOut);
-                   end;     *)
-                end else begin
-                    Msg('Serious error with file '+ extractfilename(lDicomImgName));
-                    lReadOK := false;
-                end; //if JPEG else if UNCOMPRESSED else ERROR
-                if lReadOK then begin
-                   lDicomData.XYZdim[4] := lAHdr.dim[4];  //do this now - depending on slice order DicomData can be first or last volume
-                  if (lDICOMdata.file4D) and (lPrefs.Swizzle4D) then
-                    SwapTime(lDICOMdata,lsBuffer);//data is stored X,Y,T,Z - swap to X,Y,Z,T
-                  lSliceBytesOut := lSliceBytes;
-                   if (lIntenScaleVaries) then begin
-
-                       MakeFloat(lsBuffer,lDICOMdata, lSliceBytesOut);
-                       lByteSwap := false; //Un-swapped during conversion
-                   end;
-                  if (lDICOMdata.PlanarConfig = 0) and (lDicomData.SamplesPerPixel = 3) then
-                       MakePlanar(lsBuffer,lDICOMdata);
-                  if (lMosX > 1) or (lMosY > 1) then begin
-			                  DeMosaic(lsBuffer,lmosX,lmosY,lMosaicSlices,lFlipMosaic,lDICOMdata);
-                        lSliceBytesOut :=lAHdr.dim[1]*lAHdr.dim[2]*lAHdr.dim[3]*trunc((lAHdr.bitpix+7)/8);
-		              end else
-			              FlipTB(lDICOMdata,lsBuffer);
-                   //msg(inttostr(lSliceBytesOut)+ '  '+inttostr(lAHdr.dim[1]*lAHdr.dim[2]*lAHdr.dim[3]*trunc((lAHdr.bitpix+7)/8)));
-                   //lSliceBytesOut :=lAHdr.dim[1]*lAHdr.dim[2]*lAHdr.dim[3]*trunc((lAHdr.bitpix+7)/8);
-                   if lVolSave then begin{save entire volume}
-                       Move(lsBuffer^,lvBuffer^[lvolOffset],lSliceBytesOut);
-                       lVolOffset := lVolOffset + lSliceBytesOut;
-                   end else begin //save slice-by-slice
-                      Filemode := 2;  //read and write
-		                  BlockWrite(lOutF, lsBuffer^, lSliceBytesOut);
-                   end;
-                end; //if lReadOK
-	    end;
-	    freemem(lsBuffer);
-      Filemode := 2;  //read and write
-      lOutImgNameGZ := lOutImgName;
-      if lVolSave then begin{save slice-by-slice}
-           lOutImgNameGZ :=  SaveNIfTICore (lOutImgName, lvBuffer, lVolOffsetInit, lAHdr, lPref,lByteSwap)
-      end else //data saved slice by slice
-	      CloseFile(lOutF);
-                 //if (lPref.StartClip > 0) or (lPref.EndClip > 0) then
-            //   Clip4D(lOutHdrName, lAHdr, false,lPref.SPM2,lPref.SingleNIIFile,lPref.GZip, true, lPref.StartClip,lPref.EndClip);
-
-        if lDTIdir > 1 then begin
-           //bvec file
-           lStart := -1;//ensure this is a DTI image - some scans must have a bvalue > 1
-           for lIndex := 1 to lDTIdir do
-               if lDTIra[lIndex].bval = 0 then
-                  lStart := lIndex;
-           if lStart < 1 then begin
-               Msg('* Warning: diffusion acquisition does not have b-0 image');
-                PartialAcquisitionError;
-           end;
-           lStart := -1;//ensure this is a DTI image - some scans must have a bvalue > 1
-           for lIndex := 1 to lDTIdir do
-               if lDTIra[lIndex].bval > 0 then
-                  lStart := lIndex;
-
-           if lStart > 0 then begin
-              lStart := 1;
-              lEnd := lDTIdir;
-              lOutDTIname := lOutImgName;
-              Msg('Number of diffusion directions = '+inttostr(lDTIdir));
-              if lDicomData.ManufacturerID = kSiemensID then begin
-                 Msg('Note: detected Siemens Software version [0018:1020] = '+inttostr(lDicomData.Vers0018_1020) );
-                 Msg('  -Will use 0019:000E or 0019:100E instead of 0029:1020 if version >= ' +inttostr(lPrefs.SiemensDTIUse0019If00181020atleast));
-                 Msg('  -Will stack across Acquisitions if version >=' +inttostr(lPrefs.SiemensDTIStackIf00181020atleast));
-                 Msg('  -No slice angulation correction of vectors if version >=' +inttostr(lPRefs.SiemensDTINoAngulationCorrectionIf00181020atleast));
-                 Msg('  To adjust, edit '+IniName );
-                 if lDicomData.Vers0018_1020 = 13 then
-                    Msg('  *Warning: some Siemens VB13 set DiffusionGradientDirection incorrectly. Please check manually validate');                    
-                 if lDicomData.Vers0018_1020 >= lPrefs.SiemensDTINoAngulationCorrectionIf00181020atleast  then 
-                    SiemensFlipYBvecs(lDTIra,lDTIdir)
-                 else
-                     SiemensCorrectBvecs(lDicomData,lDTIra,lDTIdir);
-              end else if lDicomData.ManufacturerID = kPhilipsID then begin
-                   PhilipsCorrectBvecs(lDicomData,lDTIra,lDTIdir);
-                   //next: philips scans can include DWI images with bval>0 and v1=0,v2=0,v3=0 - we want to exclude these
-                   for lIndex := lDTIdir downto 1 do
-                       if (lDTIra[lIndex].bval = 0) or (lDTIra[lIndex].v1 <> 0) or (lDTIra[lIndex].v2 <> 0) or (lDTIra[lIndex].v3 <> 0) then
-                         lStart := lIndex;
-                   for lIndex := 1 to lDTIdir do
-                       if (lDTIra[lIndex].bval = 0) or (lDTIra[lIndex].v1 <> 0) or (lDTIra[lIndex].v2 <> 0) or (lDTIra[lIndex].v3 <> 0) then
-                         lEnd := lIndex;
-                   if ((lStart >1) or (lEnd < lDTIdir)) and (lStart <= lEnd) then begin
-                      if lVolSave then {save slice-by-slice}
-                         lOutDTIname := SaveNIfTICoreCrop (lOutImgName, lvBuffer, lVolOffsetInit,lStart-1,lDTIdir-lEnd, lAHdr, lPref,lByteSwap)
-                       else
-                          lOutDTIname := Clip4D(lOutHdrName, lAHdr, false,lPref, lStart-1,lDTIdir-lEnd);
-                          //lOutDTIname := Clip4D(lOutHdrName, lAHdr, false,lPref.SPM2,lPref.SingleNIIFile,lPref.GZip, false, lStart-1,lDTIdir-lEnd);
-                      //Msg(lOutDTIName);
-                      Msg('Removed DWI from DTI scan - saving volumes '+inttostr(lStart)+'..'+inttostr(lEnd));
-                   end;//exclude scans
-              end else if lDicomData.ManufacturerID = kGEID then
-                GECorrectBvecs(lDicomData,lDTIra,lDTIdir)
-              else
-                  Msg('WARNING: Unkown manufacturer - DTI BVecs are probably incorrect.');//beta software
-              if lStart <= lEnd then begin
-              //create output vectors
-              if lOutDTIname <> '' then begin //image file created
-              lOutDTIname := changefileextX(lOutDTIname,'.bvec');
-              assignfile(lTextF,lOutDTIname);
-              Filemode := 0;
-              rewrite(lTextF);
-              for lSeries := lStart to lEnd do
-                  Write(lTextF,floattostr(lDTIra[lSeries].v1)+ ' ');
-              Writeln(lTextF);
-              for lSeries := lStart to lEnd do
-                  Write(lTextF,floattostr(lDTIra[lSeries].v2)+ ' ');
-              Writeln(lTextF);
-              for lSeries := lStart to lEnd do
-                  Write(lTextF,floattostr(lDTIra[lSeries].v3)+ ' ');
-              Writeln(lTextF);
-              closefile(lTextF);
-              //create bvals
-              lOutDTIname := changefileextX(lOutDTIname,'.bval');
-              assignfile(lTextF,lOutDTIname);
-              Filemode := 0;
-              rewrite(lTextF);
-              for lSeries := lStart to lEnd do
-                  Write(lTextF,inttostr(lDTIra[lSeries].bval)+' ');
-              Writeln(lTextF);
-              closefile(lTextF);
-              end;// if lOutDTIname <> '' then begin //image file created
-              end; //lStart <= lEnd
-           end; //some bvals > 0
-        end; //DTIdir
-
-        if lVolSave then //do this AFTER DTI extraction - allows rapid cropping of Philips DTI
-           Freemem ( lvBuffer)
-        else begin
-             CheckHugeUint16(lOutHdrName, false);
-             if (not lPref.FourD) and (lAHdr.dim[4] > 1) then   //Convert 4D to 3D
-                ChangeNIfTISubformat(lOutHdrName, lAHdr,lPref) ;
-
-             if (lPref.SingleNIIFile) and (lPref.Gzip) then begin
-                if (lPref.usePigz = 0) then begin  //usePigz forced for huge files ... internal unlikely 32-bit safe
-                   if not runPigz(lOutHdrName, 1) then
-                      msg('Warning: unable to compress '+lOutHdrName+' with pigz. Make sure pigz is installed.');
-                end else begin
-                        if not runPigz(lOutHdrName, lPref.usePigz) then
-                           msg('Warning: unable to compress '+lOutHdrName+' with pigz. Make sure pigz is installed.');
-                end;
-             end
-        end; //slice-by-slice
-	(*if 	lIntenscaleVaries then begin
-		beep;
-		Msg('Intensity scale/slope or bit-depth varies across slices: perhaps convert with MRIcro.');
-	end;*)
-        if (lPref.enablereorient) and (lDicomData.XYZdim[2] > lPref.MinReorientMatrix) and (lDicomData.XYZdim[1] > lPref.MinReorientMatrix) and (lAHdr.dim[3] > 64) and (lAHdr.dim[4] < 2) then begin
-           lOutImgName := Reorient(lOutImgNameGZ,lAHdr,lPref,false,false);
-           if (lOutImgName <> '') and (lDicomData.TE < 25)  and (lDicomData.TE > 0) then //T1 image
-              CropNIfTI(lOutImgName,lPref);
-        end;
-        result := true;
-        Filemode := 0;  //ReadONly
-        ExitCode := 0;
-end;
-
-end.
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/convertsimple.pas b/dcm2nii_prePARRECDTI/convertsimple.pas
deleted file mode 100755
index 5945cc0..0000000
--- a/dcm2nii_prePARRECDTI/convertsimple.pas
+++ /dev/null
@@ -1,258 +0,0 @@
-unit convertsimple;
-{$H+}
-interface
-uses
-{$IFDEF FPC}gzio2, {$ENDIF}
-define_types,SysUtils,dicomtypes,filename,nii_4dto3d,niftiutil,nii_orient, nii_crop,GraphicsMathLibrary,prefs;
-//function ConvertSimple2NII  ({var} lInFilename, lOutDir: string; var lPrefs: TPrefs): boolean;
-function FDF( lFName: string; var lDcm: DicomData {; var lByteSwap: boolean}): boolean;
-
-implementation
-uses dialogsx;
-
-procedure ReadlnX (var F: TextFile; var lResult: string);
-//Replicates Readln, but works for Unix files... Delphi 4's readln fails for non-MSDOS EOLs
-var
-   lCh: char;
-begin
-     lResult := '';
-     while not Eof(F) do begin
-           Read(F, lCh);
-           if (lCh in [#10,#13]) then begin
-              if lResult <> '' then begin
-                 //Showmessage(lResult);
-                 exit;
-              end;
-           end else
-               lResult := lResult + lCh;
-     end;
-end; //ReadlnX
-
-function ParseStr(lPattern: string; var lSample: string): integer;
-begin
-
-     result := Pos(lPattern,lSample);
-
-     if result < 1 then
-        exit;
-     //Msg('*'+lPattern+'*'+inttostr(result)+'*'+lSample+'*');
-     result := result+length(lPattern);//end of pattern
-     lSample := trim(copy(lSample,result,length(lSample)+1-result));
-end;
-
-procedure ExtractFloats(lSample: string; var V1,V2,V3: double);
-var
-   lCh: char;
-   lStr: string;
-   lP,lL,lN: integer;
-procedure RetireStr;
-begin
-     if lStr = '' then exit;
-     inc(lN);
-     case lN of
-                     1: V1 := strtofloat(lStr);
-                     2: V2 := strtofloat(lStr);
-                     3: V3 := strtofloat(lStr);
-                     else exit;
-     end;
-     lStr := '';
-end;
-begin
-     V1:= 1; V2 := 1; V3 := 1;
-     lL := length(lSample);
-     if lL < 1 then
-        exit;
-     decimalseparator := '.';
-     lP := 1;
-     lN:= 0;
-     lStr := '';
-     while lP <= lL do begin
-           lCh := lSample[lP];
-           if lCh in ['-','.','0'..'9'] then
-                lStr := lStr + lCh
-           else
-               retireStr;
-           inc(lP);
-     end;
-     RetireStr;
-end;
-
-procedure ExtractFloats10x(lSample: string; var V1,V2,V3: double);
-//cm to mm
-begin
-     ExtractFloats(lSample, V1,V2,V3);
-     V1 := V1 * 10;
-     V2 := V2 * 10;
-     V3 := V3 * 10;
-end;
-
-procedure ExtractInts(lSample: string; var V1,V2,V3: integer);
-var
-   F1,F2,F3: double;
-begin
-     //Msg('*'+lSample+'*');
-     ExtractFloats(lSample, F1,F2,F3);
-     V1 := round(F1);
-     V2 := round(F2);
-     V3 := round(F3);
-     //Msg(inttostr(V1)+','+inttostr(V2)+','+inttostr(V3));
-
-end;
-
-procedure ReportHeader (lFormatName: string; var lDicomData: dicomdata);
-const
-     kCR = '; ';
-begin
-      Msg (lFormatName
-              +kCR+ ' Slice Number:'+inttostr(lDicomData.ImageNum)
-              +kCR+ 'XYZ dim: ' +inttostr(lDicomData.XYZdim[1])+'/'+inttostr(lDicomData.XYZdim[2])+'/'+inttostr(lDicomData.XYZdim[3])
-              +kCR+ 'XYZ position: ' +floattostr(lDicomData.PatientPosX)+'/'+floattostr(lDicomData.PatientPosY)+'/'+floattostr(lDicomData.PatientPosZ)
-              +kCR+'Data offset: ' +inttostr(lDicomData.ImageStart)
-              +kCR+'XYZ mm: '+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)+'/'
-			  +floattostrf(lDicomData.XYZmm[2],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2)
-              +kCR+'TR: '+floattostrf(lDicomData.TR,ffFixed,8,2)  );
-end;
-
-function CMFOV2MM( lCMFOV,lMatrix: double): double;
-begin
-    if lMatrix > 0 then
-       result := lCMFOV*10 / lMatrix;
-end;
-(*Reads Varian FDF images (FDF = Flexible Data Format).
-Varian MRI FDF reader http://www.mathworks.com/matlabcentral/fileexchange/7449
-Multi_FDF_Opener.java - http://rsbweb.nih.gov/ij/plugins/multi-opener.html
- char  *spatial_rank = "2dfov";
-	if 3dfov then matrix will have three elements
-	if 3dfov then span will have three elements
- int    bigendian
- float  matrix[] = {512, 512};
- float  bits = 32;
- float  span[] = {4.000000, 4.000000};
- byte offset of image data is = file.length - xdim*ydim*zdim*bits/8;
- Appears only 32-bit float data... *)
-
-
-function Deblank (lInStr: string): string;
-var
-   lLen,lPos: integer;
-begin
-     result := '';
-     lLen := length(lInStr);
-     if lLen < 1 then
-        exit;
-     for lPos := 1 to lLen do
-         if lInStr[lPos] in ['=',',','[',']','+','-','.','\','~','/', '0'..'9','a'..'z','A'..'Z'] then
-            result := result +lINStr[lPos];
-end;
-
-function FDF( lFName: string; var lDcm: DicomData): boolean;
-//Note - some Varian scanners put in more white space between text than others...
-// "float bits=" versus "float  bits="
-//Therefore we deblank the data text to remove whitespace
-VAR
-   ltextfile: textfile;
-   lLine: string;
-   lFileSz,num: integer;
-   junk1f,junk2f,junk3f: double;
-   junk1,junk2: integer;
-   lDone,lSliceNum: boolean;
-begin
-    result := false;
-    lFileSz := FSize(lFName);
-    if lFileSz < 1{not fileexists (lFName)} then begin
-        MSG('Can not find file '+lFName);
-        exit;
-    end;
-    FileMode := 0;  { Set file access to read only }
-    AssignFile(ltextfile, lFName);
-    Reset(ltextfile);
-    lDone := false;
-    num := 1;
-    lSliceNum := false;
-    repeat
-          readlnx(ltextfile,lLine);
-          //lLine := trim(lLine);//remove leading/following characters
-          lLine := deblank(lLine);//remove leading/following characters
-          //msg(lLine);
-          if ParseStr('floatbits=', lLine) > 0 then
-             ExtractInts(lLine, lDcm.Allocbits_per_pixel ,junk1,junk2);
-          if ParseStr('intslice_no', lLine) > 0 then begin
-             lSliceNum := true;
-             ExtractInts(lLine, lDcm.ImageNum  ,junk1,junk2);
-          end;
-          if ParseStr('floatlocation[]=', lLine) > 0 then
-             ExtractFloats10x(lLine, lDcm.PatientPosX,lDcm.PatientPosY,lDcm.PatientPosZ);
-          if ParseStr('floatmatrix[]=', lLine) > 0 then
-             ExtractInts(lLine, lDcm.XYZdim[1],lDcm.XYZdim[2],lDcm.XYZdim[3]);
-          if ParseStr('floatspan[]=', lLine) > 0 then
-             ExtractFloats(lLine, lDCm.XYZmm[1],lDcm.XYZmm[2],lDcm.XYZmm[3]);
-          if ParseStr('floatTR=', lLine) > 0 then begin
-             ExtractFloats(lLine, junk1f,junk2f,junk3f);
-             lDcm.TR := junk1f/1000; //convert TR in msec to time in sec
-          end;
-          {if strmatch('intbigendian', line) then
-             machineformat = 'ieee-le'; % New Linux-based}
-          num := num + 1;
-          if num > 41 then
-             lDone := true;
-    until lDone;
-    if lDcm.Allocbits_per_pixel = 32 then begin
-       result := true;
-       lDcm.FloatData := true;
-    end else begin
-        Msg('Unsupported datatype: '+inttostr( lDcm.Allocbits_per_pixel)+ 'bits per pixel '+lFName);
-    end;
-    if not lSliceNum then begin
-       ExtractInts(lFName, lDcm.ImageNum ,junk1,junk2);
-    end;
-    //next - convert field of view in cm to voxel size in mm...
-    for num := 1 to 3 do
-        lDCm.XYZmm[num] := CMFOV2MM( lDCm.XYZmm[num],lDcm.XYZdim[num]);
-    lDcm.Little_Endian := 0;
-    lDcm.ImageStart :=  lFileSz - (lDcm.XYZdim[1]*lDcm.XYZdim[2]*lDcm.XYZdim[3]*(round(lDcm.Allocbits_per_pixel/8)));
-    if lDcm.ImageStart < 10 then
-       result := false;
-    if result then
-       ReportHeader('Varian FDF',lDcm);
-    CloseFile(ltextfile);
-    FileMode := 2;
-end;
-
-
-(*function Raw2NIfTI(lHdrName: string; var lHdr: TNIFTIhdr;  lPrefs: TPrefs; lByteSwap: boolean): boolean;
-//like ChangeNIfTISubformat except we use the passed lHdrdata...
-var
-   lImgBuffer: byteP;
-   lImgOffset: integer;
-   lOutImgName: string;
-   //lByteSwap: boolean;
-begin
-   result := false;
-   if not NIFTIhdr_LoadImgRaw  (false,lHdrName, lHdr, lImgBuffer, lImgOffset,lByteSwap) then  exit;
-   Msg('Converting to NIfTI '+lHdrName);
-   lOutImgName := ChangeFilePrefix (lHdrName,'c');
-   if lPrefs.CustomRename then
-      CustomFilename(lOutImgName);
-   if  SaveNIfTICore (lOutImgName, lImgBuffer, lImgOffset+1, lHdr, lPrefs,lByteSwap) ='' then exit;
-   Freemem(lImgBuffer);
-   result := true; //11/2007
-   ExitCode := 0;
-end;
-
-
-function ConvertSimple2NII  ({var} lInFilename , lOutDir: string; var lPrefs: TPrefs): boolean;
-//this is simple, but does not stack 2d slices into 3d volumes...
-var
-   lDcm: DicomData;
-   lHdr: TNIFTIhdr;
-    lBigEndian: boolean;
-begin
-    result := false;
-     NIFTIhdr_ClearHdr(lHdr);
-    Msg('WARNING: no image orientation matrix for '+lInFilename);
-    if not FDF (lInFilename,lDcm) then exit;
-    DICOM2AnzHdr (lHdr, false,lInFilename,lDcm);
-    //Raw2NIfTI(lInFilename,lHdr,lPrefs,true);
-end; *)
-
-end.
diff --git a/dcm2nii_prePARRECDTI/csaread.pas b/dcm2nii_prePARRECDTI/csaread.pas
deleted file mode 100755
index 3724eb8..0000000
--- a/dcm2nii_prePARRECDTI/csaread.pas
+++ /dev/null
@@ -1,247 +0,0 @@
-unit csaread;
-interface
-// Extract vital details from the Siemens CSA header that is contained within a DICOM file.
-//   This is DICOM group:element (0029:1010) [CSA Image Header Info]
-//   These values are crucial converting 2D mosaics to 3D images and computing DTI vectors
-//see http://nipy.sourceforge.net/nibabel/dicom/siemens_csa.html
-//    This is a port of John Ashburners' spm_dicom_headers.m Matlab code
-uses SysUtils, dialogsx, define_types;
-
-type
-  TBytearray =  array of byte;
-  TCSA = record
-     Slices,MosaicX,MosaicY: longword;
-     Bvalue,DTIv1,DTIv2,DTIv3, SliceNormV1, SliceNormV2,SliceNormV3: double;
-   end;
-
-function DecodeCSA2 (lFilename: string; lCSAImageHeaderInfoPos, lCSAImageHeaderInfoSz: integer; var lCSA: TCSA): boolean;
-
-function GetCSAImageHeaderInfoDTI (lFilename: string; lStart,lLength: integer; var lBval: integer; var ldti1,ldti2,ldti3: double): boolean;
-function GetCSAImageHeaderInfo (lFilename: string; lStart,lLength: integer; var lMosaicSlices,lMosaicX,lMosaicY: integer; var lv1,lv2,lv3: double): boolean;
-
-
-implementation
-
-function GetCSAImageHeaderInfoDTI (lFilename: string; lStart,lLength: integer; var lBval: integer; var ldti1,ldti2,ldti3: double): boolean;
-var
-   lCSA: TCSA;
-begin
-     //lBval := -1;//imposibble - read error
-     result := DecodeCSA2 (lFilename, lStart,lLength, lCSA);
-     if not result then exit;
-     lBval := round(lCSA.bvalue);
-     ldti1 := lCSA.DTIv1;
-     ldti2 := lCSA.DTIv2;
-     ldti3 := lCSA.DTIv3;
-end;
-
-function GetCSAImageHeaderInfo (lFilename: string; lStart,lLength: integer; var lMosaicSlices,lMosaicX,lMosaicY: integer; var lv1,lv2,lv3: double): boolean;
-var
-   lCSA: TCSA;
-begin
-     //lMosaicSlices := -1;//imposibble - read error
-     result := DecodeCSA2 (lFilename, lStart,lLength, lCSA);
-     if not result then exit;
-     lMosaicSlices := lCSA.Slices;
-     lMosaicX := lCSA.MosaicX;
-     lMosaicY := lCSA.MosaicY;
-     lv1 := lCSA.SliceNormV1;
-     lv2 := lCSA.SliceNormV2;
-     lv3 := lCSA.SliceNormV3;  //5/5/2013
-end;
-
-function DecodeCSA2 (lFilename: string; lCSAImageHeaderInfoPos, lCSAImageHeaderInfoSz: integer; var lCSA: TCSA): boolean;
-//provided with DICOM file as well as location and size of CSA header, this code returns the Siemens CSA header information
-
-const
-  kMaxItem = 4; // if you only need first 3 values, set to 4 so if an item has 6 values the final ones will overwrite 4th item
-type
-  TCSAtag = record
-     name : string[64];
-     vm: longint;
-     vr123: string[3];
-     vr4: string[1];
-     syngodt ,nitems,xx : longint;
-   end;
-  TCSAitem = record
-     xx1, xx2_Len, xx3_77, xx4: longint; // [ x L 77 x] L is length
-     value: string;
-   end;
-var
-    lFile    : File;
-    lVers: string;
-    lData : array of byte;
-    lnTag,lPos,lI,lT,lIbound: integer;
-    lTag :  TCSAtag;
-    lItem : array [1..kMaxItem] of TCSAitem;
-function SafeStr2Num (lStr: string): boolean; //for some reason, many fMRI images have bvalue = 'X1_01_001
-var
-  lP,lL: integer;
-begin
-  result := false;
-  lL := length(lStr);
-  if lL < 1 then exit;
-  for lP := 1 to lL do
-    if not(lStr[lP] in ['+','-','0'..'9','.','e','E']) then
-      exit;
-  result := true;
-end;//nested func SafeStr2Num
-function RightStr2Num (lStr: string): integer; //e.g. Siemens AcquisitionMatrixText "104p*96" -> "96"
-var
-  lL: integer;
-  lS: string;
-  lDone: boolean;
-begin
-  result := -1;
-  lS := '';
-  lL := length(lStr);
-  if lL < 1 then exit;
-  lDone := false;
-  while (lL >= 1) and (not lDone) do begin
-    if (lStr[lL] in ['+','-','0'..'9','.','e','E']) then
-      lS := lStr[lL]+lS
-    else if lS <> '' then
-      lDone := true;
-    dec(lL);
-  end;
-  if lS = '' then exit;
-  result := strtoint(lS);
-end; //nested func RightStr2Num
-function LeftStr2Num (lStr: string): integer; //e.g. Siemens AcquisitionMatrixText "104p*96" -> "104"
-var
-  lP,lL: integer;
-  lS: string;
-  lDone: boolean;
-begin
-  result := -1;
-  lS := '';
-  lL := length(lStr);
-  if lL < 1 then exit;
-  lP := 1;
-  lDone := false;
-  while (lP <= lL) and (not lDone) do begin
-    if (lStr[lP] in ['+','-','0'..'9','.','e','E']) then
-      lS := lS + lStr[lP]
-    else if lS <> '' then
-      lDone := true;
-    inc(lP);
-  end;
-  if lS = '' then exit;
-  result := strtoint(lS);
-end; //nested func LeftStr2Num
-function freadStr(len: integer): string;
-var
-  i: integer;
-begin
-  if (len+lPos) >= lCSAImageHeaderInfoSz then
-    Raise Exception.CreateFmt('csaread: corrupt file ', [lFilename]);
-  result := '';
-  i := 0;
-  while (i < len) and (lData[i+lPos] <> 0) and (lData[i+lPos] <> $20)  do begin
-      result := result + chr(lData[i+lPos]);
-      inc(i);
-  end;
-  lPos := lPos + len;
-end; //nested func freadStr
-function freaduint32: longword; overload; //uint32
-begin
-  if (4+lPos) >= lCSAImageHeaderInfoSz then
-    Raise Exception.CreateFmt('csaread: corrupt file ', [lFilename]);
-  result := (lData[lPos+3] shl 24)+(lData[lPos+2] shl 16)+(lData[lPos+1] shl 8)+lData[lPos];
-  lPos := lPos + 4;
-end;//nested func freaduint32
-function freadint32: longint; overload; //uint32
-begin
-  if (4+lPos) >= lCSAImageHeaderInfoSz then
-    Raise Exception.CreateFmt('csaread: corrupt file ', [lFilename]);
-  result := (lData[lPos+3] shl 24)+(lData[lPos+2] shl 16)+(lData[lPos+1] shl 8)+lData[lPos];
-  lPos := lPos + 4;
-end;//nested func freadint32
-function freadTag: TCSAtag;
-begin
-    result.name := freadStr(64);
-    result.vm:= freadint32;
-    result.vr123:= freadStr(3);
-    result.vr4:= freadStr(1);
-    result.syngodt := freadint32;
-    result.nitems := freadint32;
-    result.xx := freadint32;
-end;//nested func freadTag
-function freadItem: TCSAitem;
-begin
-  result.xx1:= freadint32;
-  result.xx2_Len:= freadint32;
-  result.xx3_77:= freadint32;
-  result.xx4:= freadint32;
-  result.value := freadStr(result.xx2_len);
-  lPos := lPos + ((4-(result.xx2_len) mod 4  )mod 4) ;
-end;//nested func freadItem
-begin  //main function DecodeCSA2
-   result := false;
-   lCSA.Bvalue := -1;
-   if (lCSAImageHeaderInfoSz < 1) then
-    exit;
-   if FSize(lFilename) <= (lCSAImageHeaderInfoPos+lCSAImageHeaderInfoSz) then
-        exit;
-   if lCSAImageHeaderInfoSz < 118 then
-    exit; //Too short to be a CSA header - Perhaps Philips or GE is using this tag
-   setlength(lData, lCSAImageHeaderInfoSz);
-   lPos := 0;
-   FileMode := fmOpenRead;
-   AssignFile(lFile, lFilename);
-   Reset(lFile, 1);   // Now we define one record as 1 byte
-   Seek(lFile, lCSAImageHeaderInfoPos);    // Records start from 0
-   BlockRead(lFile, lData[0], lCSAImageHeaderInfoSz);
-   CloseFile(lFile);
-   lVers := freadStr(4);
-   if lVers = 'SV10' then begin
-      //read header
-      lPos := lPos + 4; //skip 8 bytes of data, spm_dicom_headers refers to these as unused1 and unused2
-      lnTag := freaduint32;
-      if (lnTag < 1) or (lnTag > 1024) then begin
-        showmsg('Error reading CSA header');
-        exit;
-      end;
-      if (lData[lPos] <> 77) then showmsg('warning: strange CSA2 header');
-      lPos := lPos + 4; // skip the four bytes 77 00 00 00
-      //read tags
-      for lT := 1 to lnTag do begin
-        lTag := freadTag;
-        if lTag.nitems > 0 then begin
-          for lI := 1 to lTag.nitems do begin //read items
-            if lI > kMaxItem then
-              lIbound := kMaxItem //out of range
-            else
-              lIbound := lI;
-            lItem[lIbound] := freadItem;
-          end; //for each item
-          if (lTag.name = 'NumberOfImagesInMosaic') then
-            lCSA.Slices := round(strtofloat(lItem[1].value)) ;
-          if (lTag.name = 'AcquisitionMatrixText') then begin  //'96p*96 -> X= 96 and Y= 96
-            lCSA.MosaicX := LeftStr2Num(lItem[1].value);
-            lCSA.MosaicY := RightStr2Num(lItem[1].value);
-          end;
-          if (lTag.name = 'B_value') and (SafeStr2Num(lItem[1].value)) then
-            lCSA.Bvalue := strtofloat(lItem[1].value);
-          if (lTag.name = 'DiffusionGradientDirection') and (SafeStr2Num(lItem[1].value)) and (SafeStr2Num(lItem[2].value)) and (SafeStr2Num(lItem[3].value))  then begin
-            lCSA.DTIv1 := strtofloat(lItem[1].value);
-            lCSA.DTIv2 := strtofloat(lItem[2].value);
-            lCSA.DTIv3 := strtofloat(lItem[3].value);
-          end;
-          if (lTag.name = 'SliceNormalVector') and (SafeStr2Num(lItem[1].value)) and (SafeStr2Num(lItem[2].value)) and (SafeStr2Num(lItem[3].value))  then begin
-            lCSA.SliceNormV1 := strtofloat(lItem[1].value);
-            lCSA.SliceNormV2 := strtofloat(lItem[2].value);
-            lCSA.SliceNormV3 := strtofloat(lItem[3].value);
-          end;
-        end;//at least one item
-      end; //for each tag
-      result := true;
-      //showmsg('Success DecodeCSA2');
-   end else begin
-      msg('CSAread Warning: '+ lFilename +' at byte '+inttostr(lCSAImageHeaderInfoPos)+' reports version "'+lVers+'": only "SV10" format is supported: image is either corruprted, very old or new. See if a new version of this software is available.');
-   end;
-  lData := nil;
-end;// func DecodeCSA2
-
-end.
- 
diff --git a/dcm2nii_prePARRECDTI/dcm2nii.app/Contents/MacOS/dcm2nii b/dcm2nii_prePARRECDTI/dcm2nii.app/Contents/MacOS/dcm2nii
deleted file mode 100755
index bdcd35a..0000000
--- a/dcm2nii_prePARRECDTI/dcm2nii.app/Contents/MacOS/dcm2nii
+++ /dev/null
@@ -1 +0,0 @@
-../../../dcm2nii
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/dcm2nii.cfg b/dcm2nii_prePARRECDTI/dcm2nii.cfg
deleted file mode 100755
index 5d9b456..0000000
--- a/dcm2nii_prePARRECDTI/dcm2nii.cfg
+++ /dev/null
@@ -1,39 +0,0 @@
--$A8
--$B-
--$C+
--$D+
--$E-
--$F-
--$G+
--$H+
--$I+
--$J+
--$K-
--$L+
--$M-
--$N+
--$O+
--$P+
--$Q-
--$R-
--$S-
--$T-
--$U-
--$V+
--$W-
--$X+
--$YD
--$Z1
--cg
--AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
--H+
--W+
--M
--$M16384,1048576
--K$00400000
--LE"c:\program files (x86)\borland\delphi7\Projects\Bpl"
--LN"c:\program files (x86)\borland\delphi7\Projects\Bpl"
--U"..\common\;..\delphionly\"
--O"..\common\;..\delphionly\"
--I"..\common\;..\delphionly\"
--R"..\common\;..\delphionly\"
diff --git a/dcm2nii_prePARRECDTI/dcm2nii.dof b/dcm2nii_prePARRECDTI/dcm2nii.dof
deleted file mode 100755
index 1026d73..0000000
--- a/dcm2nii_prePARRECDTI/dcm2nii.dof
+++ /dev/null
@@ -1,143 +0,0 @@
-[FileVersion]
-Version=7.0
-[Compiler]
-A=8
-B=0
-C=1
-D=1
-E=0
-F=0
-G=1
-H=1
-I=1
-J=1
-K=0
-L=1
-M=0
-N=1
-O=1
-P=1
-Q=0
-R=0
-S=0
-T=0
-U=0
-V=1
-W=0
-X=1
-Y=1
-Z=1
-ShowHints=1
-ShowWarnings=1
-UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
-NamespacePrefix=
-SymbolDeprecated=1
-SymbolLibrary=1
-SymbolPlatform=1
-UnitLibrary=1
-UnitPlatform=1
-UnitDeprecated=1
-HResultCompat=1
-HidingMember=1
-HiddenVirtual=1
-Garbage=1
-BoundsError=1
-ZeroNilCompat=1
-StringConstTruncated=1
-ForLoopVarVarPar=1
-TypedConstVarPar=1
-AsgToTypedConst=1
-CaseLabelRange=1
-ForVariable=1
-ConstructingAbstract=1
-ComparisonFalse=1
-ComparisonTrue=1
-ComparingSignedUnsigned=1
-CombiningSignedUnsigned=1
-UnsupportedConstruct=1
-FileOpen=1
-FileOpenUnitSrc=1
-BadGlobalSymbol=1
-DuplicateConstructorDestructor=1
-InvalidDirective=1
-PackageNoLink=1
-PackageThreadVar=1
-ImplicitImport=1
-HPPEMITIgnored=1
-NoRetVal=1
-UseBeforeDef=1
-ForLoopVarUndef=1
-UnitNameMismatch=1
-NoCFGFileFound=1
-MessageDirective=1
-ImplicitVariants=1
-UnicodeToLocale=1
-LocaleToUnicode=1
-ImagebaseMultiple=1
-SuspiciousTypecast=1
-PrivatePropAccessor=1
-UnsafeType=1
-UnsafeCode=1
-UnsafeCast=1
-[Linker]
-MapFile=0
-OutputObjs=0
-ConsoleApp=1
-DebugInfo=0
-RemoteSymbols=0
-MinStackSize=16384
-MaxStackSize=1048576
-ImageBase=4194304
-ExeDescription=
-[Directories]
-OutputDir=
-UnitOutputDir=
-PackageDLLOutputDir=
-PackageDCPOutputDir=
-SearchPath=..\common\;..\delphionly\
-Packages=Vcl40;Vclx40;VclSmp40;Qrpt40;Vcldb40;RxCtl4
-Conditionals=
-DebugSourceDirs=
-UsePackages=0
-[Parameters]
-RunParams=
-HostApplication=
-Launcher=
-UseLauncher=0
-DebugCWD=
-[Language]
-ActiveLang=
-ProjectLang=
-RootDir=
-[Version Info]
-IncludeVerInfo=1
-AutoIncBuild=0
-MajorVer=0
-MinorVer=9
-Release=0
-Build=1
-Debug=0
-PreRelease=0
-Special=0
-Private=0
-DLL=0
-Locale=1033
-CodePage=1252
-[Version Info Keys]
-CompanyName=Chris Rorden
-FileDescription=DICOM and PAR/REC converter
-FileVersion=0.9.0.1
-InternalName=
-LegalCopyright=Copyright �
-LegalTrademarks=
-OriginalFilename=dcm2nii.exe
-ProductName=dcm2nii
-ProductVersion=0.0
-Comments=
-[HistoryLists\hlUnitAliases]
-Count=1
-Item0=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
-[HistoryLists\hlSearchPath]
-Count=2
-Item0=..\common\;..\delphionly\
-Item1=..\common\
diff --git a/dcm2nii_prePARRECDTI/dcm2nii.dpr b/dcm2nii_prePARRECDTI/dcm2nii.dpr
deleted file mode 100755
index 26dc125..0000000
--- a/dcm2nii_prePARRECDTI/dcm2nii.dpr
+++ /dev/null
@@ -1,33 +0,0 @@
-program dcm2nii;
-{$IFDEF FPC}
-{$mode objfpc}
-{$ELSE}
- {$APPTYPE CONSOLE}
-{$ENDIF}
-{$H+}
-uses
-  {$IFDEF UNIX}
-          {$IFDEF UseCThreads} cthreads, {$ENDIF}
-  {$ENDIF}
-  dialogsx,paramstrs,dicomtypes;
-{$IFNDEF UNIX}
-{$R *.res}
-{$ENDIF}
-
-begin
-     ShowMsg(kVers);
-     kUseDateTimeForID := true;
-     {$IFNDEF TEST}
-      ProcessParamStrs;
-     {$ELSE}
-         Testdcm2nii;
-         readln;
-     {$ENDIF}
-end.
-
-
-
-
-
-
-
diff --git a/dcm2nii_prePARRECDTI/dcm2nii.ico b/dcm2nii_prePARRECDTI/dcm2nii.ico
deleted file mode 100755
index f023db2..0000000
Binary files a/dcm2nii_prePARRECDTI/dcm2nii.ico and /dev/null differ
diff --git a/dcm2nii_prePARRECDTI/dcm2nii.ini b/dcm2nii_prePARRECDTI/dcm2nii.ini
deleted file mode 100755
index 65f634a..0000000
--- a/dcm2nii_prePARRECDTI/dcm2nii.ini
+++ /dev/null
@@ -1,50 +0,0 @@
-[BOOL]
-4D=1
-Anonymize=1
-SingleNIIFile=1
-Gzip=1
-SPM2=0
-AppendDate=0
-AppendAcqSeries=1
-AppendProtocolName=1
-AppendPatientName=0
-AppendFilename=0
-EveryFile=1
-ManualNIfTIConv=1
-AnonymizeSourceDICOM=0
-Swizzle4D=1
-Stack3DImagesWithSameAcqNum=0
-RecursiveUseNameAppend=0
-CustomRename=0
-disablereorient=0
-enablereorient=1
-createoutputfolder=0
-CollapseFolders=0
-Verbose=0
-AutoCrop=0
-fourD=1
-PhilipsPrecise=0
-UseGE_0021_104F=0
-DebugMode=0
-UntestedFeatures=0
-OrthoFlipXDim=0
-UINT16toFLOAT32=1
-
-[INT]
-BeginClip=0
-LastClip=0
-MinReorientMatrix=255
-RecursiveFolderDepth=5
-MaxReorientMatrix=1023
-OutDirMode=0
-IgnoreDTIRotationsIf_0002_0013_atleast=15
-IgnoreDTIRotationsIf_0018_1020_atleast=15
-SiemensDTIUse0019If00181020atleast=15
-SiemensDTINoAngulationCorrectionIf00181020atleast=1000
-SiemensDTIStackIf00181020atleast=15
-usePigz=0
-
-[STR]
-BackupDir=
-OutDir=C:\Users\neuropsych\Documents
-
diff --git a/dcm2nii_prePARRECDTI/dcm2nii.lpi b/dcm2nii_prePARRECDTI/dcm2nii.lpi
deleted file mode 100755
index 274537b..0000000
--- a/dcm2nii_prePARRECDTI/dcm2nii.lpi
+++ /dev/null
@@ -1,434 +0,0 @@
-<?xml version="1.0"?>
-<CONFIG>
-  <ProjectOptions>
-    <Version Value="9"/>
-    <PathDelim Value="\"/>
-    <General>
-      <Flags>
-        <LRSInOutputDirectory Value="False"/>
-      </Flags>
-      <MainUnit Value="0"/>
-      <ActiveWindowIndexAtStart Value="0"/>
-    </General>
-    <BuildModes Count="1">
-      <Item1 Name="default" Default="True"/>
-    </BuildModes>
-    <PublishOptions>
-      <Version Value="2"/>
-      <IgnoreBinaries Value="False"/>
-      <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
-      <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
-    </PublishOptions>
-    <RunParams>
-      <local>
-        <FormatVersion Value="1"/>
-        <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
-      </local>
-    </RunParams>
-    <Units Count="31">
-      <Unit0>
-        <Filename Value="dcm2nii.lpr"/>
-        <IsPartOfProject Value="True"/>
-        <UnitName Value="dcm2nii"/>
-        <EditorIndex Value="0"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="31"/>
-        <CursorPos X="48" Y="3"/>
-        <UsageCount Value="124"/>
-        <Loaded Value="True"/>
-        <LoadedDesigner Value="True"/>
-      </Unit0>
-      <Unit1>
-        <Filename Value="convert.pas"/>
-        <UnitName Value="convert"/>
-        <EditorIndex Value="7"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1455"/>
-        <CursorPos X="103" Y="1473"/>
-        <UsageCount Value="60"/>
-        <Loaded Value="True"/>
-      </Unit1>
-      <Unit2>
-        <Filename Value="define_types.pas"/>
-        <UnitName Value="define_types"/>
-        <TopLine Value="317"/>
-        <CursorPos X="1" Y="330"/>
-        <UsageCount Value="56"/>
-      </Unit2>
-      <Unit3>
-        <Filename Value="gzio2.pas"/>
-        <UnitName Value="gzio2"/>
-        <TopLine Value="1765"/>
-        <CursorPos X="7" Y="1784"/>
-        <UsageCount Value="56"/>
-      </Unit3>
-      <Unit4>
-        <Filename Value="dicom.pas"/>
-        <UnitName Value="dicom"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="1"/>
-        <UsageCount Value="56"/>
-      </Unit4>
-      <Unit5>
-        <Filename Value="nodialogs.pas"/>
-        <UnitName Value="nodialogs"/>
-        <TopLine Value="1"/>
-        <CursorPos X="10" Y="5"/>
-        <UsageCount Value="53"/>
-      </Unit5>
-      <Unit6>
-        <Filename Value="lsjpeg.pas"/>
-        <UnitName Value="lsjpeg"/>
-        <EditorIndex Value="9"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="393"/>
-        <CursorPos X="20" Y="518"/>
-        <UsageCount Value="59"/>
-        <Loaded Value="True"/>
-      </Unit6>
-      <Unit7>
-        <Filename Value="GraphicsMathLibrary.pas"/>
-        <UnitName Value="GraphicsMathLibrary"/>
-        <TopLine Value="61"/>
-        <CursorPos X="1" Y="66"/>
-        <UsageCount Value="53"/>
-      </Unit7>
-      <Unit8>
-        <Filename Value="sortdicom.pas"/>
-        <UnitName Value="sortdicom"/>
-        <TopLine Value="172"/>
-        <CursorPos X="24" Y="188"/>
-        <UsageCount Value="56"/>
-      </Unit8>
-      <Unit9>
-        <Filename Value="filename.pas"/>
-        <IsPartOfProject Value="True"/>
-        <UnitName Value="filename"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="51" Y="8"/>
-        <UsageCount Value="124"/>
-      </Unit9>
-      <Unit10>
-        <Filename Value="dicomtypes.pas"/>
-        <IsPartOfProject Value="True"/>
-        <UnitName Value="dicomtypes"/>
-        <TopLine Value="307"/>
-        <CursorPos X="42" Y="320"/>
-        <UsageCount Value="124"/>
-      </Unit10>
-      <Unit11>
-        <Filename Value="parconvert.pas"/>
-        <UnitName Value="parconvert"/>
-        <TopLine Value="1188"/>
-        <CursorPos X="44" Y="1199"/>
-        <UsageCount Value="56"/>
-      </Unit11>
-      <Unit12>
-        <Filename Value="..\..\junk\unit1.pas"/>
-        <ComponentName Value="Form1"/>
-        <HasResources Value="True"/>
-        <UnitName Value="Unit1"/>
-        <TopLine Value="1"/>
-        <CursorPos X="36" Y="7"/>
-        <UsageCount Value="2"/>
-      </Unit12>
-      <Unit13>
-        <Filename Value="nii4Dto3D.pas"/>
-        <UnitName Value="nii4dto3d"/>
-        <TopLine Value="114"/>
-        <CursorPos X="53" Y="125"/>
-        <UsageCount Value="10"/>
-      </Unit13>
-      <Unit14>
-        <Filename Value="dicomfast.pas"/>
-        <UnitName Value="dicomfast"/>
-        <TopLine Value="4"/>
-        <CursorPos X="6" Y="14"/>
-        <UsageCount Value="10"/>
-      </Unit14>
-      <Unit15>
-        <Filename Value="dicomcompat.pas"/>
-        <UnitName Value="dicomcompat"/>
-        <TopLine Value="5888"/>
-        <CursorPos X="31" Y="5918"/>
-        <UsageCount Value="10"/>
-      </Unit15>
-      <Unit16>
-        <Filename Value="dialogsx.pas"/>
-        <UnitName Value="dialogsx"/>
-        <TopLine Value="1"/>
-        <CursorPos X="10" Y="2"/>
-        <UsageCount Value="10"/>
-      </Unit16>
-      <Unit17>
-        <Filename Value="nii_4dto3d.pas"/>
-        <UnitName Value="nii_4dto3d"/>
-        <TopLine Value="113"/>
-        <CursorPos X="53" Y="124"/>
-        <UsageCount Value="10"/>
-      </Unit17>
-      <Unit18>
-        <Filename Value="nii_orient.pas"/>
-        <UnitName Value="nii_orient"/>
-        <EditorIndex Value="1"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="39" Y="2"/>
-        <UsageCount Value="14"/>
-        <Loaded Value="True"/>
-      </Unit18>
-      <Unit19>
-        <Filename Value="nii_crop.pas"/>
-        <UnitName Value="nii_crop"/>
-        <TopLine Value="1"/>
-        <CursorPos X="6" Y="2"/>
-        <UsageCount Value="10"/>
-      </Unit19>
-      <Unit20>
-        <Filename Value="paramstrs.pas"/>
-        <UnitName Value="paramstrs"/>
-        <EditorIndex Value="8"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="159"/>
-        <CursorPos X="20" Y="167"/>
-        <UsageCount Value="14"/>
-        <Loaded Value="True"/>
-      </Unit20>
-      <Unit21>
-        <Filename Value="readint.pas"/>
-        <UnitName Value="readint"/>
-        <TopLine Value="1"/>
-        <CursorPos X="13" Y="6"/>
-        <UsageCount Value="9"/>
-      </Unit21>
-      <Unit22>
-        <Filename Value="userdir.pas"/>
-        <UnitName Value="userdir"/>
-        <TopLine Value="1"/>
-        <CursorPos X="31" Y="13"/>
-        <UsageCount Value="9"/>
-      </Unit22>
-      <Unit23>
-        <Filename Value="..\common\isgui.inc"/>
-        <IsVisibleTab Value="True"/>
-        <EditorIndex Value="4"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="14" Y="1"/>
-        <UsageCount Value="13"/>
-        <Loaded Value="True"/>
-      </Unit23>
-      <Unit24>
-        <Filename Value="..\common\define_types.pas"/>
-        <UnitName Value="define_types"/>
-        <EditorIndex Value="6"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="23" Y="11"/>
-        <UsageCount Value="13"/>
-        <Loaded Value="True"/>
-      </Unit24>
-      <Unit25>
-        <Filename Value="..\common\gzio2.pas"/>
-        <UnitName Value="gzio2"/>
-        <TopLine Value="1809"/>
-        <CursorPos X="35" Y="1849"/>
-        <UsageCount Value="9"/>
-      </Unit25>
-      <Unit26>
-        <Filename Value="..\common\GraphicsMathLibrary.pas"/>
-        <UnitName Value="GraphicsMathLibrary"/>
-        <TopLine Value="547"/>
-        <CursorPos X="35" Y="552"/>
-        <UsageCount Value="9"/>
-      </Unit26>
-      <Unit27>
-        <Filename Value="..\common\dialogsx.pas"/>
-        <UnitName Value="dialogsx"/>
-        <EditorIndex Value="10"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="8"/>
-        <CursorPos X="55" Y="9"/>
-        <UsageCount Value="13"/>
-        <Loaded Value="True"/>
-      </Unit27>
-      <Unit28>
-        <Filename Value="prefs.pas"/>
-        <UnitName Value="prefs"/>
-        <EditorIndex Value="2"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="128"/>
-        <CursorPos X="84" Y="133"/>
-        <UsageCount Value="13"/>
-        <Loaded Value="True"/>
-      </Unit28>
-      <Unit29>
-        <Filename Value="..\common\userdir.pas"/>
-        <UnitName Value="userdir"/>
-        <EditorIndex Value="5"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="1"/>
-        <UsageCount Value="13"/>
-        <Loaded Value="True"/>
-      </Unit29>
-      <Unit30>
-        <Filename Value="niftiutil.pas"/>
-        <UnitName Value="niftiutil"/>
-        <EditorIndex Value="3"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="505"/>
-        <CursorPos X="32" Y="515"/>
-        <UsageCount Value="13"/>
-        <Loaded Value="True"/>
-      </Unit30>
-    </Units>
-    <JumpHistory Count="29" HistoryIndex="28">
-      <Position1>
-        <Filename Value="convert.pas"/>
-        <Caret Line="1622" Column="12" TopLine="1596"/>
-      </Position1>
-      <Position2>
-        <Filename Value="convert.pas"/>
-        <Caret Line="1258" Column="53" TopLine="1246"/>
-      </Position2>
-      <Position3>
-        <Filename Value="convert.pas"/>
-        <Caret Line="1442" Column="24" TopLine="1408"/>
-      </Position3>
-      <Position4>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="455" Column="41" TopLine="431"/>
-      </Position4>
-      <Position5>
-        <Filename Value="..\common\define_types.pas"/>
-        <Caret Line="174" Column="10" TopLine="153"/>
-      </Position5>
-      <Position6>
-        <Filename Value="..\common\define_types.pas"/>
-        <Caret Line="8" Column="64" TopLine="1"/>
-      </Position6>
-      <Position7>
-        <Filename Value="..\common\define_types.pas"/>
-        <Caret Line="172" Column="18" TopLine="137"/>
-      </Position7>
-      <Position8>
-        <Filename Value="..\common\define_types.pas"/>
-        <Caret Line="174" Column="18" TopLine="139"/>
-      </Position8>
-      <Position9>
-        <Filename Value="..\common\define_types.pas"/>
-        <Caret Line="922" Column="33" TopLine="900"/>
-      </Position9>
-      <Position10>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="490" Column="23" TopLine="471"/>
-      </Position10>
-      <Position11>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="6" Column="22" TopLine="1"/>
-      </Position11>
-      <Position12>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="425" Column="20" TopLine="412"/>
-      </Position12>
-      <Position13>
-        <Filename Value="..\common\define_types.pas"/>
-        <Caret Line="908" Column="11" TopLine="905"/>
-      </Position13>
-      <Position14>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="431" Column="49" TopLine="405"/>
-      </Position14>
-      <Position15>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="418" Column="11" TopLine="401"/>
-      </Position15>
-      <Position16>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="508" Column="32" TopLine="480"/>
-      </Position16>
-      <Position17>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="431" Column="19" TopLine="404"/>
-      </Position17>
-      <Position18>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="421" Column="16" TopLine="404"/>
-      </Position18>
-      <Position19>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="443" Column="4" TopLine="435"/>
-      </Position19>
-      <Position20>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="431" Column="39" TopLine="411"/>
-      </Position20>
-      <Position21>
-        <Filename Value="convert.pas"/>
-        <Caret Line="1272" Column="57" TopLine="1265"/>
-      </Position21>
-      <Position22>
-        <Filename Value="convert.pas"/>
-        <Caret Line="1279" Column="122" TopLine="1265"/>
-      </Position22>
-      <Position23>
-        <Filename Value="convert.pas"/>
-        <Caret Line="1359" Column="79" TopLine="1332"/>
-      </Position23>
-      <Position24>
-        <Filename Value="convert.pas"/>
-        <Caret Line="1360" Column="120" TopLine="1333"/>
-      </Position24>
-      <Position25>
-        <Filename Value="convert.pas"/>
-        <Caret Line="1385" Column="126" TopLine="1358"/>
-      </Position25>
-      <Position26>
-        <Filename Value="prefs.pas"/>
-        <Caret Line="26" Column="85" TopLine="1"/>
-      </Position26>
-      <Position27>
-        <Filename Value="prefs.pas"/>
-        <Caret Line="147" Column="3" TopLine="119"/>
-      </Position27>
-      <Position28>
-        <Filename Value="prefs.pas"/>
-        <Caret Line="26" Column="97" TopLine="11"/>
-      </Position28>
-      <Position29>
-        <Filename Value="prefs.pas"/>
-        <Caret Line="146" Column="22" TopLine="119"/>
-      </Position29>
-    </JumpHistory>
-  </ProjectOptions>
-  <CompilerOptions>
-    <Version Value="11"/>
-    <PathDelim Value="\"/>
-    <SearchPaths>
-      <OtherUnitFiles Value="..\common"/>
-    </SearchPaths>
-    <Parsing>
-      <SyntaxOptions>
-        <UseAnsiStrings Value="False"/>
-      </SyntaxOptions>
-    </Parsing>
-    <CodeGeneration>
-      <Optimizations>
-        <OptimizationLevel Value="2"/>
-      </Optimizations>
-    </CodeGeneration>
-    <Linking>
-      <Debugging>
-        <GenerateDebugInfo Value="False"/>
-        <UseLineInfoUnit Value="False"/>
-        <StripSymbols Value="True"/>
-      </Debugging>
-      <LinkSmart Value="True"/>
-    </Linking>
-    <Other>
-      <CompilerPath Value="$(CompPath)"/>
-    </Other>
-  </CompilerOptions>
-</CONFIG>
diff --git a/dcm2nii_prePARRECDTI/dcm2nii.lpr b/dcm2nii_prePARRECDTI/dcm2nii.lpr
deleted file mode 100755
index 374e69a..0000000
--- a/dcm2nii_prePARRECDTI/dcm2nii.lpr
+++ /dev/null
@@ -1,73 +0,0 @@
-program dcm2nii;
-{$IFDEF FPC}
-{$mode objfpc}
-{$ELSE}
- {$APPTYPE CONSOLE}
-{$ENDIF}
-{$H+}
-uses
-  {$IFDEF UNIX}
-          {$IFDEF UseCThreads} cthreads, {$ENDIF}
-{$ELSE}
-  shellAPI,
-  Windows,
-  {$ENDIF}
-
-  Classes,
-  inifiles,
-  SysUtils,
-  convert,
-  define_types,
-  sortdicom,
-  dicom,
-  parconvert,
-  filename,
-  dicomtypes,
-  nii_crop,
-  nii_4dto3d,
-  prefs,
-  dialogsx,
-  paramstrs;
-{$IFNDEF UNIX}
-//{$R laz.res}
-{$ENDIF}
-
-
-(*var lIn,lOut: string;
-Start: dword;
-lPrefs: TPrefs;
-begin
-Start := GetTickCount;
-	kUseDateTimeForID := true;
-        SetDefaultPrefs (lPrefs);
-        lPrefs.Gzip := true;
-        lPrefs.Anonymize := true;
-        lPrefs.SingleNIIFile := true;
-        lPrefs.everyfile := true;
-        lPrefs.AppendDate := false;
-        lPrefs.AppendAcqSeries := true;
-         lPrefs.AppendProtocolName := true;
-         lPrefs.AppendPatientName := false;
-         lPrefs.fourD := true;
-         lPrefs.AppendFilename := true;
-lOut := '';
-lIn := 'C:\dti64\rapid\IM_0001.dcm';
-
-LoadFileList(lIn,lOut,lPrefs);
-Msg('Finished. Elapsed time: '+inttostr(GetTickCount-Start));
- readln;
-
- end.  *)
-
-begin
-     Msg(kVers);
-     kUseDateTimeForID := true;
-      ProcessParamStrs;
-end.
-
-
-
-
-
-
-
diff --git a/dcm2nii_prePARRECDTI/dcm2nii.res b/dcm2nii_prePARRECDTI/dcm2nii.res
deleted file mode 100755
index c7fb1f5..0000000
Binary files a/dcm2nii_prePARRECDTI/dcm2nii.res and /dev/null differ
diff --git a/dcm2nii_prePARRECDTI/dcm2nii48.ico b/dcm2nii_prePARRECDTI/dcm2nii48.ico
deleted file mode 100755
index 375ec28..0000000
Binary files a/dcm2nii_prePARRECDTI/dcm2nii48.ico and /dev/null differ
diff --git a/dcm2nii_prePARRECDTI/dcm2niigui.cfg b/dcm2nii_prePARRECDTI/dcm2niigui.cfg
deleted file mode 100755
index 67f6fff..0000000
--- a/dcm2nii_prePARRECDTI/dcm2niigui.cfg
+++ /dev/null
@@ -1,39 +0,0 @@
--$A8
--$B-
--$C+
--$D+
--$E-
--$F-
--$G+
--$H+
--$I+
--$J+
--$K-
--$L+
--$M-
--$N+
--$O+
--$P+
--$Q-
--$R-
--$S-
--$T-
--$U-
--$V+
--$W-
--$X+
--$YD
--$Z1
--cg
--AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
--H+
--W+
--M
--$M16384,1048576
--K$00400000
--LE"c:\program files (x86)\borland\delphi7\Projects\Bpl"
--LN"c:\program files (x86)\borland\delphi7\Projects\Bpl"
--U"..\common\;C:\pas\d4\RX\Units\"
--O"..\common\;C:\pas\d4\RX\Units\"
--I"..\common\;C:\pas\d4\RX\Units\"
--R"..\common\;C:\pas\d4\RX\Units\"
diff --git a/dcm2nii_prePARRECDTI/dcm2niigui.dof b/dcm2nii_prePARRECDTI/dcm2niigui.dof
deleted file mode 100755
index 97da3dd..0000000
--- a/dcm2nii_prePARRECDTI/dcm2niigui.dof
+++ /dev/null
@@ -1,144 +0,0 @@
-[FileVersion]
-Version=7.0
-[Compiler]
-A=8
-B=0
-C=1
-D=1
-E=0
-F=0
-G=1
-H=1
-I=1
-J=1
-K=0
-L=1
-M=0
-N=1
-O=1
-P=1
-Q=0
-R=0
-S=0
-T=0
-U=0
-V=1
-W=0
-X=1
-Y=1
-Z=1
-ShowHints=1
-ShowWarnings=1
-UnitAliases=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
-NamespacePrefix=
-SymbolDeprecated=1
-SymbolLibrary=1
-SymbolPlatform=1
-UnitLibrary=1
-UnitPlatform=1
-UnitDeprecated=1
-HResultCompat=1
-HidingMember=1
-HiddenVirtual=1
-Garbage=1
-BoundsError=1
-ZeroNilCompat=1
-StringConstTruncated=1
-ForLoopVarVarPar=1
-TypedConstVarPar=1
-AsgToTypedConst=1
-CaseLabelRange=1
-ForVariable=1
-ConstructingAbstract=1
-ComparisonFalse=1
-ComparisonTrue=1
-ComparingSignedUnsigned=1
-CombiningSignedUnsigned=1
-UnsupportedConstruct=1
-FileOpen=1
-FileOpenUnitSrc=1
-BadGlobalSymbol=1
-DuplicateConstructorDestructor=1
-InvalidDirective=1
-PackageNoLink=1
-PackageThreadVar=1
-ImplicitImport=1
-HPPEMITIgnored=1
-NoRetVal=1
-UseBeforeDef=1
-ForLoopVarUndef=1
-UnitNameMismatch=1
-NoCFGFileFound=1
-MessageDirective=1
-ImplicitVariants=1
-UnicodeToLocale=1
-LocaleToUnicode=1
-ImagebaseMultiple=1
-SuspiciousTypecast=1
-PrivatePropAccessor=1
-UnsafeType=1
-UnsafeCode=1
-UnsafeCast=1
-[Linker]
-MapFile=0
-OutputObjs=0
-ConsoleApp=1
-DebugInfo=0
-RemoteSymbols=0
-MinStackSize=16384
-MaxStackSize=1048576
-ImageBase=4194304
-ExeDescription=
-[Directories]
-OutputDir=
-UnitOutputDir=
-PackageDLLOutputDir=
-PackageDCPOutputDir=
-SearchPath=..\common\;C:\pas\d4\RX\Units\
-Packages=Vcl40;Vclx40;VclSmp40;Qrpt40;Vcldb40;RxCtl4
-Conditionals=
-DebugSourceDirs=
-UsePackages=0
-[Parameters]
-RunParams=
-HostApplication=
-Launcher=
-UseLauncher=0
-DebugCWD=
-[Language]
-ActiveLang=
-ProjectLang=
-RootDir=
-[Version Info]
-IncludeVerInfo=1
-AutoIncBuild=0
-MajorVer=0
-MinorVer=9
-Release=0
-Build=0
-Debug=0
-PreRelease=0
-Special=0
-Private=0
-DLL=0
-Locale=1033
-CodePage=1252
-[Version Info Keys]
-CompanyName=
-FileDescription=
-FileVersion=0.9.0.0
-InternalName=
-LegalCopyright=
-LegalTrademarks=
-OriginalFilename=
-ProductName=
-ProductVersion=1.0.0.0
-Comments=
-[HistoryLists\hlUnitAliases]
-Count=1
-Item0=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
-[HistoryLists\hlSearchPath]
-Count=3
-Item0=..\common\;C:\pas\d4\RX\Units\
-Item1=..\common\;C:\pas\d4\RX\Units
-Item2=..\common\
diff --git a/dcm2nii_prePARRECDTI/dcm2niigui.dpr b/dcm2nii_prePARRECDTI/dcm2niigui.dpr
deleted file mode 100755
index b582288..0000000
--- a/dcm2nii_prePARRECDTI/dcm2niigui.dpr
+++ /dev/null
@@ -1,20 +0,0 @@
-program dcm2niigui;
-
-uses
-  Forms,
-  gui in 'gui.pas' {MainForm},
-  pref_form in 'pref_form.pas' {PrefsForm},
-  nifti_form in 'nifti_form.pas' {NIfTIform},
-  untar in 'untar.pas',
-  convertsimple in 'convertsimple.pas';
-
-{$R *.RES}
-
-begin
-  Application.Initialize;
-  Application.Title := 'dcm2niiGUI';
-  Application.CreateForm(TMainForm, MainForm);
-  Application.CreateForm(TPrefsForm, PrefsForm);
-  Application.CreateForm(TNIfTIform, NIfTIform);
-  Application.Run;
-end.
diff --git a/dcm2nii_prePARRECDTI/dcm2niigui.ico b/dcm2nii_prePARRECDTI/dcm2niigui.ico
deleted file mode 100755
index 375ec28..0000000
Binary files a/dcm2nii_prePARRECDTI/dcm2niigui.ico and /dev/null differ
diff --git a/dcm2nii_prePARRECDTI/dcm2niigui.ini b/dcm2nii_prePARRECDTI/dcm2niigui.ini
deleted file mode 100755
index 99e6b8a..0000000
--- a/dcm2nii_prePARRECDTI/dcm2niigui.ini
+++ /dev/null
@@ -1,45 +0,0 @@
-[BOOL]
-DebugMode=0
-UntestedFeatures=0
-UINT16toFLOAT32=1
-Verbose=0
-Anonymize=1
-AnonymizeSourceDICOM=0
-AppendAcqSeries=1
-AppendDate=1
-AppendFilename=0
-AppendPatientName=0
-AppendProtocolName=1
-AutoCrop=0
-CollapseFolders=1
-createoutputfolder=0
-CustomRename=0
-enablereorient=1
-OrthoFlipXDim=0
-EveryFile=1
-fourD=1
-Gzip=1
-ManualNIfTIConv=1
-PhilipsPrecise=0
-RecursiveUseNameAppend=0
-SingleNIIFile=1
-SPM2=0
-Stack3DImagesWithSameAcqNum=0
-Swizzle4D=1
-UseGE_0021_104F=0
-
-[INT]
-BeginClip=0
-LastClip=0
-usePigz=1
-MaxReorientMatrix=1023
-MinReorientMatrix=200
-RecursiveFolderDepth=5
-OutDirMode=0
-SiemensDTIUse0019If00181020atleast=15
-SiemensDTINoAngulationCorrectionIf00181020atleast=1000
-SiemensDTIStackIf00181020atleast=15
-
-[STR]
-OutDir=C:\Users\neuropsych\Documents
-
diff --git a/dcm2nii_prePARRECDTI/dcm2niigui.lpi b/dcm2nii_prePARRECDTI/dcm2niigui.lpi
deleted file mode 100755
index 061950e..0000000
--- a/dcm2nii_prePARRECDTI/dcm2niigui.lpi
+++ /dev/null
@@ -1,575 +0,0 @@
-<?xml version="1.0"?>
-<CONFIG>
-  <ProjectOptions>
-    <Version Value="9"/>
-    <PathDelim Value="\"/>
-    <General>
-      <Flags>
-        <LRSInOutputDirectory Value="False"/>
-      </Flags>
-      <MainUnit Value="0"/>
-      <Title Value="dcm2niigui.exe"/>
-      <UseXPManifest Value="True"/>
-      <Icon Value="0"/>
-      <ActiveWindowIndexAtStart Value="0"/>
-    </General>
-    <BuildModes Count="1">
-      <Item1 Name="default" Default="True"/>
-    </BuildModes>
-    <PublishOptions>
-      <Version Value="2"/>
-      <IgnoreBinaries Value="False"/>
-      <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
-      <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
-    </PublishOptions>
-    <RunParams>
-      <local>
-        <FormatVersion Value="1"/>
-        <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
-      </local>
-    </RunParams>
-    <RequiredPackages Count="1">
-      <Item1>
-        <PackageName Value="LCL"/>
-      </Item1>
-    </RequiredPackages>
-    <Units Count="46">
-      <Unit0>
-        <Filename Value="dcm2niigui.lpr"/>
-        <IsPartOfProject Value="True"/>
-        <UnitName Value="dcm2niigui"/>
-        <TopLine Value="1"/>
-        <CursorPos X="2" Y="1"/>
-        <UsageCount Value="67"/>
-      </Unit0>
-      <Unit1>
-        <Filename Value="gui.pas"/>
-        <IsPartOfProject Value="True"/>
-        <ComponentName Value="MainForm"/>
-        <HasResources Value="True"/>
-        <ResourceBaseClass Value="Form"/>
-        <UnitName Value="gui"/>
-        <EditorIndex Value="7"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1088"/>
-        <CursorPos X="91" Y="1092"/>
-        <UsageCount Value="67"/>
-        <Loaded Value="True"/>
-        <LoadedDesigner Value="True"/>
-      </Unit1>
-      <Unit2>
-        <Filename Value="dcm2niigui.lrs"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="1"/>
-        <UsageCount Value="7"/>
-      </Unit2>
-      <Unit3>
-        <Filename Value="nifti_form.pas"/>
-        <IsPartOfProject Value="True"/>
-        <ComponentName Value="NIfTIForm"/>
-        <HasResources Value="True"/>
-        <ResourceBaseClass Value="Form"/>
-        <UnitName Value="nifti_form"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="65"/>
-        <CursorPos X="37" Y="10"/>
-        <UsageCount Value="67"/>
-      </Unit3>
-      <Unit4>
-        <Filename Value="pref_form.pas"/>
-        <IsPartOfProject Value="True"/>
-        <ComponentName Value="PrefsForm"/>
-        <ResourceBaseClass Value="Form"/>
-        <UnitName Value="pref_form"/>
-        <TopLine Value="1"/>
-        <CursorPos X="101" Y="146"/>
-        <UsageCount Value="67"/>
-      </Unit4>
-      <Unit5>
-        <Filename Value="parconvert.pas"/>
-        <UnitName Value="parconvert"/>
-        <TopLine Value="91"/>
-        <CursorPos X="13" Y="93"/>
-        <UsageCount Value="15"/>
-      </Unit5>
-      <Unit6>
-        <Filename Value="pref_form.lrs"/>
-        <TopLine Value="1"/>
-        <CursorPos X="4" Y="36"/>
-        <UsageCount Value="8"/>
-      </Unit6>
-      <Unit7>
-        <Filename Value="..\..\lcl\lresources.pp"/>
-        <UnitName Value="LResources"/>
-        <TopLine Value="2628"/>
-        <CursorPos X="21" Y="2642"/>
-        <UsageCount Value="7"/>
-      </Unit7>
-      <Unit8>
-        <Filename Value="dialogsx.pas"/>
-        <UnitName Value="dialogsx"/>
-        <TopLine Value="1"/>
-        <CursorPos X="33" Y="9"/>
-        <UsageCount Value="8"/>
-      </Unit8>
-      <Unit9>
-        <Filename Value="readint.pas"/>
-        <UnitName Value="readint"/>
-        <TopLine Value="1"/>
-        <CursorPos X="15" Y="7"/>
-        <UsageCount Value="8"/>
-      </Unit9>
-      <Unit10>
-        <Filename Value="readint.lrs"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="1"/>
-        <UsageCount Value="8"/>
-      </Unit10>
-      <Unit11>
-        <Filename Value="usr\local\share\lazarus\lcl\nonwin32\messages.pp"/>
-        <UnitName Value="Messages"/>
-        <TopLine Value="1"/>
-        <CursorPos X="90" Y="12"/>
-        <UsageCount Value="7"/>
-      </Unit11>
-      <Unit12>
-        <Filename Value="define_types.pas"/>
-        <UnitName Value="define_types"/>
-        <TopLine Value="1"/>
-        <CursorPos X="40" Y="2"/>
-        <UsageCount Value="8"/>
-      </Unit12>
-      <Unit13>
-        <Filename Value="paramstrs.pas"/>
-        <UnitName Value="paramstrs"/>
-        <EditorIndex Value="2"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="4"/>
-        <CursorPos X="16" Y="20"/>
-        <UsageCount Value="23"/>
-        <Loaded Value="True"/>
-      </Unit13>
-      <Unit14>
-        <Filename Value="niftiutil.pas"/>
-        <UnitName Value="niftiutil"/>
-        <IsVisibleTab Value="True"/>
-        <EditorIndex Value="8"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="220"/>
-        <CursorPos X="6" Y="236"/>
-        <UsageCount Value="22"/>
-        <Loaded Value="True"/>
-      </Unit14>
-      <Unit15>
-        <Filename Value="prefs.pas"/>
-        <UnitName Value="prefs"/>
-        <EditorIndex Value="11"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="178"/>
-        <CursorPos X="66" Y="213"/>
-        <UsageCount Value="23"/>
-        <Loaded Value="True"/>
-      </Unit15>
-      <Unit16>
-        <Filename Value="dicom.pas"/>
-        <UnitName Value="dicom"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="13"/>
-        <UsageCount Value="10"/>
-      </Unit16>
-      <Unit17>
-        <Filename Value="dicomtypes.pas"/>
-        <UnitName Value="dicomtypes"/>
-        <EditorIndex Value="12"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="76"/>
-        <CursorPos X="17" Y="91"/>
-        <UsageCount Value="16"/>
-        <Loaded Value="True"/>
-      </Unit17>
-      <Unit18>
-        <Filename Value="filename.pas"/>
-        <UnitName Value="filename"/>
-        <TopLine Value="118"/>
-        <CursorPos X="55" Y="131"/>
-        <UsageCount Value="13"/>
-      </Unit18>
-      <Unit19>
-        <Filename Value="userdir.pas"/>
-        <UnitName Value="userdir"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="3"/>
-        <UsageCount Value="9"/>
-      </Unit19>
-      <Unit20>
-        <Filename Value="gzio2.pas"/>
-        <UnitName Value="gzio2"/>
-        <TopLine Value="762"/>
-        <CursorPos X="26" Y="788"/>
-        <UsageCount Value="7"/>
-      </Unit20>
-      <Unit21>
-        <Filename Value="nii_crop.pas"/>
-        <UnitName Value="nii_crop"/>
-        <TopLine Value="36"/>
-        <CursorPos X="1" Y="1"/>
-        <UsageCount Value="7"/>
-      </Unit21>
-      <Unit22>
-        <Filename Value="..\common\userdir.pas"/>
-        <UnitName Value="userdir"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="15"/>
-        <UsageCount Value="13"/>
-      </Unit22>
-      <Unit23>
-        <Filename Value="..\common\define_types.pas"/>
-        <UnitName Value="define_types"/>
-        <EditorIndex Value="0"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="3"/>
-        <CursorPos X="9" Y="29"/>
-        <UsageCount Value="21"/>
-        <Loaded Value="True"/>
-      </Unit23>
-      <Unit24>
-        <Filename Value="..\common\gziod.pas"/>
-        <UnitName Value="gziod"/>
-        <TopLine Value="311"/>
-        <CursorPos X="98" Y="322"/>
-        <UsageCount Value="7"/>
-      </Unit24>
-      <Unit25>
-        <Filename Value="convert.pas"/>
-        <UnitName Value="convert"/>
-        <EditorIndex Value="9"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="304"/>
-        <CursorPos X="26" Y="1498"/>
-        <UsageCount Value="20"/>
-        <Loaded Value="True"/>
-      </Unit25>
-      <Unit26>
-        <Filename Value="..\common\gzio2.pas"/>
-        <UnitName Value="gzio2"/>
-        <TopLine Value="647"/>
-        <CursorPos X="8" Y="667"/>
-        <UsageCount Value="10"/>
-      </Unit26>
-      <Unit27>
-        <Filename Value="nii_asl.pas"/>
-        <UnitName Value="nii_asl"/>
-        <TopLine Value="96"/>
-        <CursorPos X="7" Y="212"/>
-        <UsageCount Value="7"/>
-      </Unit27>
-      <Unit28>
-        <Filename Value="..\common\GraphicsMathLibrary.pas"/>
-        <UnitName Value="GraphicsMathLibrary"/>
-        <TopLine Value="1"/>
-        <CursorPos X="10" Y="27"/>
-        <UsageCount Value="7"/>
-      </Unit28>
-      <Unit29>
-        <Filename Value="..\common\dialogsx.pas"/>
-        <UnitName Value="dialogsx"/>
-        <TopLine Value="1"/>
-        <CursorPos X="33" Y="2"/>
-        <UsageCount Value="15"/>
-      </Unit29>
-      <Unit30>
-        <Filename Value="LibTar.pas"/>
-        <UnitName Value="LibTar"/>
-        <TopLine Value="246"/>
-        <CursorPos X="35" Y="272"/>
-        <UsageCount Value="7"/>
-      </Unit30>
-      <Unit31>
-        <Filename Value="untar.pas"/>
-        <UnitName Value="untar"/>
-        <TopLine Value="8"/>
-        <CursorPos X="38" Y="12"/>
-        <UsageCount Value="7"/>
-      </Unit31>
-      <Unit32>
-        <Filename Value="dicomfastread.pas"/>
-        <UnitName Value="dicomfastread"/>
-        <TopLine Value="427"/>
-        <CursorPos X="15" Y="435"/>
-        <UsageCount Value="7"/>
-      </Unit32>
-      <Unit33>
-        <Filename Value="dicomcompat.pas"/>
-        <UnitName Value="dicomcompat"/>
-        <EditorIndex Value="6"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="4719"/>
-        <CursorPos X="29" Y="4732"/>
-        <UsageCount Value="22"/>
-        <Loaded Value="True"/>
-      </Unit33>
-      <Unit34>
-        <Filename Value="lsjpeg.pas"/>
-        <UnitName Value="lsjpeg"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="45" Y="7"/>
-        <UsageCount Value="15"/>
-      </Unit34>
-      <Unit35>
-        <Filename Value="sortdicom.pas"/>
-        <UnitName Value="sortdicom"/>
-        <EditorIndex Value="3"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="381"/>
-        <CursorPos X="94" Y="388"/>
-        <UsageCount Value="19"/>
-        <Loaded Value="True"/>
-      </Unit35>
-      <Unit36>
-        <Filename Value=""/>
-        <UsageCount Value="9"/>
-      </Unit36>
-      <Unit37>
-        <Filename Value="nii_orient.pas"/>
-        <UnitName Value="nii_orient"/>
-        <TopLine Value="6"/>
-        <CursorPos X="36" Y="9"/>
-        <UsageCount Value="9"/>
-      </Unit37>
-      <Unit38>
-        <Filename Value="gui.lrs"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="3"/>
-        <UsageCount Value="9"/>
-      </Unit38>
-      <Unit39>
-        <Filename Value="nii_math.pas"/>
-        <UnitName Value="nii_math"/>
-        <TopLine Value="576"/>
-        <CursorPos X="78" Y="592"/>
-        <UsageCount Value="9"/>
-      </Unit39>
-      <Unit40>
-        <Filename Value="C:\Documents and Settings\chris\Desktop\scripter\unit1.pas"/>
-        <ComponentName Value="Form1"/>
-        <ResourceBaseClass Value="Form"/>
-        <UnitName Value="Unit1"/>
-        <TopLine Value="34"/>
-        <CursorPos X="1" Y="35"/>
-        <UsageCount Value="19"/>
-      </Unit40>
-      <Unit41>
-        <Filename Value="..\common\nifti_hdr.pas"/>
-        <UnitName Value="nifti_hdr"/>
-        <EditorIndex Value="4"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1286"/>
-        <CursorPos X="52" Y="1296"/>
-        <UsageCount Value="13"/>
-        <Loaded Value="True"/>
-      </Unit41>
-      <Unit42>
-        <Filename Value="..\common\isgui.inc"/>
-        <EditorIndex Value="5"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="10" Y="1"/>
-        <UsageCount Value="13"/>
-        <Loaded Value="True"/>
-      </Unit42>
-      <Unit43>
-        <Filename Value="csaread.pas"/>
-        <UnitName Value="csaread"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="217"/>
-        <CursorPos X="7" Y="221"/>
-        <UsageCount Value="9"/>
-      </Unit43>
-      <Unit44>
-        <Filename Value="..\..\..\..\..\..\Developer\lazarus\lcl\include\customform.inc"/>
-        <EditorIndex Value="10"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="2519"/>
-        <CursorPos X="28" Y="2532"/>
-        <UsageCount Value="13"/>
-        <Loaded Value="True"/>
-      </Unit44>
-      <Unit45>
-        <Filename Value="..\..\..\..\..\..\usr\local\share\fpcsrc\rtl\objpas\sysutils\sysinth.inc"/>
-        <EditorIndex Value="1"/>
-        <WindowIndex Value="0"/>
-        <TopLine Value="113"/>
-        <CursorPos X="81" Y="134"/>
-        <UsageCount Value="12"/>
-        <Loaded Value="True"/>
-      </Unit45>
-    </Units>
-    <JumpHistory Count="30" HistoryIndex="29">
-      <Position1>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="212" Column="24" TopLine="191"/>
-      </Position1>
-      <Position2>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="215" Column="23" TopLine="191"/>
-      </Position2>
-      <Position3>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="221" Column="236" TopLine="184"/>
-      </Position3>
-      <Position4>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="222" Column="5" TopLine="209"/>
-      </Position4>
-      <Position5>
-        <Filename Value="dicomcompat.pas"/>
-        <Caret Line="408" Column="161" TopLine="406"/>
-      </Position5>
-      <Position6>
-        <Filename Value="dicomcompat.pas"/>
-        <Caret Line="3201" Column="104" TopLine="3166"/>
-      </Position6>
-      <Position7>
-        <Filename Value="dicomcompat.pas"/>
-        <Caret Line="3910" Column="26" TopLine="3876"/>
-      </Position7>
-      <Position8>
-        <Filename Value="dicomcompat.pas"/>
-        <Caret Line="4736" Column="18" TopLine="4719"/>
-      </Position8>
-      <Position9>
-        <Filename Value="dicomcompat.pas"/>
-        <Caret Line="5229" Column="24" TopLine="5190"/>
-      </Position9>
-      <Position10>
-        <Filename Value="dicomcompat.pas"/>
-        <Caret Line="4514" Column="76" TopLine="4497"/>
-      </Position10>
-      <Position11>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="8" Column="57" TopLine="1"/>
-      </Position11>
-      <Position12>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="41" Column="49" TopLine="13"/>
-      </Position12>
-      <Position13>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="145" Column="21" TopLine="117"/>
-      </Position13>
-      <Position14>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="159" Column="49" TopLine="147"/>
-      </Position14>
-      <Position15>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="190" Column="53" TopLine="172"/>
-      </Position15>
-      <Position16>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="217" Column="54" TopLine="207"/>
-      </Position16>
-      <Position17>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="232" Column="25" TopLine="225"/>
-      </Position17>
-      <Position18>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="246" Column="1" TopLine="230"/>
-      </Position18>
-      <Position19>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="256" Column="1" TopLine="239"/>
-      </Position19>
-      <Position20>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="289" Column="23" TopLine="265"/>
-      </Position20>
-      <Position21>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="313" Column="15" TopLine="290"/>
-      </Position21>
-      <Position22>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="321" Column="19" TopLine="298"/>
-      </Position22>
-      <Position23>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="326" Column="1" TopLine="315"/>
-      </Position23>
-      <Position24>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="232" Column="25" TopLine="225"/>
-      </Position24>
-      <Position25>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="243" Column="21" TopLine="229"/>
-      </Position25>
-      <Position26>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="265" Column="38" TopLine="252"/>
-      </Position26>
-      <Position27>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="258" Column="7" TopLine="242"/>
-      </Position27>
-      <Position28>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="287" Column="41" TopLine="268"/>
-      </Position28>
-      <Position29>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="295" Column="40" TopLine="276"/>
-      </Position29>
-      <Position30>
-        <Filename Value="niftiutil.pas"/>
-        <Caret Line="317" Column="40" TopLine="298"/>
-      </Position30>
-    </JumpHistory>
-  </ProjectOptions>
-  <CompilerOptions>
-    <Version Value="11"/>
-    <PathDelim Value="\"/>
-    <SearchPaths>
-      <OtherUnitFiles Value="..\common"/>
-      <SrcPath Value="C:\lazarus\ideintf"/>
-    </SearchPaths>
-    <Parsing>
-      <SyntaxOptions>
-        <UseAnsiStrings Value="False"/>
-      </SyntaxOptions>
-    </Parsing>
-    <Linking>
-      <Debugging>
-        <GenerateDebugInfo Value="False"/>
-        <UseLineInfoUnit Value="False"/>
-        <StripSymbols Value="True"/>
-      </Debugging>
-      <LinkSmart Value="True"/>
-      <Options>
-        <Win32>
-          <GraphicApplication Value="True"/>
-        </Win32>
-      </Options>
-    </Linking>
-    <Other>
-      <WriteFPCLogo Value="False"/>
-      <CompilerMessages>
-        <UseMsgFile Value="True"/>
-      </CompilerMessages>
-      <CompilerPath Value="$(CompPath)"/>
-    </Other>
-  </CompilerOptions>
-  <Debugging>
-    <Exceptions Count="2">
-      <Item1>
-        <Name Value="ECodetoolError"/>
-      </Item1>
-      <Item2>
-        <Name Value="EFOpenError"/>
-      </Item2>
-    </Exceptions>
-  </Debugging>
-</CONFIG>
diff --git a/dcm2nii_prePARRECDTI/dcm2niigui.lpr b/dcm2nii_prePARRECDTI/dcm2niigui.lpr
deleted file mode 100755
index 5c96ba0..0000000
--- a/dcm2nii_prePARRECDTI/dcm2niigui.lpr
+++ /dev/null
@@ -1,25 +0,0 @@
-program dcm2niigui;
-
-{$mode objfpc}{$H+}
-
-uses
-  {$IFDEF UNIX}{$IFDEF UseCThreads}
-  cthreads,
-  {$ENDIF}{$ENDIF}
-  Interfaces, // this includes the LCL widgetset
-  Forms, gui, nifti_form, pref_form;
-  
-  
-
-
-//{$R dcm2niigui.res}
-
-begin
-  Application.Title:='dcm2niigui.exe';
-  Application.Initialize;
-  Application.CreateForm(TMainForm, MainForm);
-  Application.CreateForm(TNIfTIForm, NIfTIForm);
-  Application.CreateForm(TPrefsForm, PrefsForm);
-  Application.Run;
-end.
-
diff --git a/dcm2nii_prePARRECDTI/dcm2niigui.lrs b/dcm2nii_prePARRECDTI/dcm2niigui.lrs
deleted file mode 100755
index 8d76aa7..0000000
--- a/dcm2nii_prePARRECDTI/dcm2niigui.lrs
+++ /dev/null
@@ -1,732 +0,0 @@
-LazarusResources.Add('MAINICON','ICO',[
-  #0#0#1#0#4#0'00'#0#0#1#0' '#0#168'%'#0#0'F'#0#0#0'  '#0#0#1#0' '#0#168#16#0#0
-  +#238'%'#0#0#24#24#0#0#1#0' '#0#136#9#0#0#150'6'#0#0#16#16#0#0#1#0' '#0'h'#4#0
-  +#0#30'@'#0#0'('#0#0#0'0'#0#0#0'`'#0#0#0#1#0' '#0#0#0#0#0#128'%'#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#138#138#138#0#143#143#143#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#168#168#168#0#185#185#185#0#0#0#0#1#255#255#255#3#14#14#14#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#1#141#141#141#2#142
-  +#142#142#2#145#145#145#2#146#145#145#2#146#146#146#2'~~'#128#2'zz{'#1'{{{'#2
-  +'|||'#2'~~'#128#2#127#127#129#2#127#127#127#2#128#128#128#2#128#128#129#2#131
-  +#131#131#2#131#131#131#2#133#133#133#2#134#134#134#1'jjj'#2#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#131#131#131#0#173#173#173#0#178#178#178#2#0#0#0#0#0#0#0#0
-  +#0#0#0#5#0#0#0#7#0#0#0#6#0#0#0#6#0#0#0#6#0#0#0#6#0#0#0#6#0#0#0#6#0#0#0#8#0#0
-  +#0#0#143#143#143#0#145#145#146#0#130#130#130#0#139#138#147#0#153#152#174#0
-  +#143#141#177#0#156#154#202#0#161#159#206#0#163#160#209#0#162#159#208#0#153
-  +#151#195#0#135#134#166#0'vu'#131#0'mmn'#0'rrq'#0'rrr'#0'ttt'#0'}}}'#0'lll'#0
-  +'xxx'#0'888'#0#128#128#128#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#147#147#147#0#0#0#0#0#143#143#143#1#167#167#167#2
-  +#144#144#144#0'kkk'#9'zzz'#129#151#151#151#214#166#166#166#216#163#163#163
-  +#216#163#163#163#217#162#162#162#217#163#163#163#217#162#162#162#217#162#162
-  +#162#216#166#166#166#219#155#155#155#194'sss9rrp!pqm#'#132#130#141'#'#156#155
-  +#180'"'#149#147#188#27#156#154#204#25#162#159#211#25#164#162#214#25#164#161
-  +#213#25#155#153#199#25#132#131#166#25'ggt'#25'PPK'#25'STG'#25']]Y'#25'bbb'#25
-  +'iii'#25'bbb'#27'___'#6#23#23#23#0#130#130#130#0#137#137#137#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#157#157#157#0#156#156#156
-  +#0#137#137#137#0#183#183#183#0#175#175#175'H'#154#154#154#210#154#154#154#255
-  +#168#168#168#255#176#176#176#255#174#174#174#255#175#175#175#255#175#175#175
-  +#255#174#174#174#255#174#174#174#255#174#174#174#255#177#177#177#255#175#175
-  +#175#255#155#155#156#253#179#178#183#245#174#174#176#246#164#164#160#246#148
-  +#148#133#246#130#131'l'#241'wyY'#240'rtP'#240'stP'#240'xzZ'#240#131#132'l'
-  +#240#146#147#131#240#161#161#158#240#171#171#175#240#173#173#178#240#168#168
-  +#169#240#165#165#163#240#165#165#165#236#167#167#167#241#147#147#147#143#197
-  +#197#197#0#174#174#174#1#129#129#129#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#151#151#151#2#146#146#146#0#137#137#137#29#138#138
-  +#138#159#157#157#157#255#169#169#169#255#151#151#151#250#170#170#170#253#171
-  +#171#171#253#170#170#170#253#171#171#171#253#171#171#171#253#171#171#171#253
-  +#171#171#171#253#170#170#170#253#171#171#171#253#171#171#172#252#154#154#147
-  +#255#140#142'r'#255'lo;'#255'`d'#22#255'_e'#1#255'ek'#0#255'kq'#0#255'nu'#0
-  +#255'mt'#0#255'kq'#0#255'gm'#0#255'ek'#3#255'hm'#24#255'uy='#255#142#143'r'
-  +#255#167#167#164#255#180#180#187#255#176#176#178#255#175#176#175#255#165#165
-  ,#165#239#157#157#157#22'```'#0#128#128#128#1#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#164#164#164#2#171#171#171#5#149#149#149#205
-  +#168#168#168#255#167#167#167#251#164#164#164#252#152#152#152#255#173#173#173
-  +#254#171#171#171#254#171#171#171#255#172#172#172#255#172#172#172#255#172#172
-  +#172#255#172#172#172#255#171#171#171#254#171#171#169#254#176#176#182#255'hj7'
-  +#254'X^'#0#253'u|'#0#253#136#144#0#253#145#155#0#253#149#158#0#253#149#158#1
-  +#253#149#159#1#253#149#158#1#253#149#159#1#253#149#158#0#253#146#155#0#253
-  +#140#149#0#253#129#138#0#253't|'#0#253'qw'#17#253#132#135'S'#253#165#165#161
-  +#253#178#178#184#250#172#172#170#255#134#134#133'p'#173#173#173#0#169#169#169
-  +#3#170#170#171#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0'ppp'
-  +#0'lll"'#162#162#162#248#166#166#166#252#166#166#166#253#161#161#161#255#154
-  +#154#154#254#174#174#174#255#170#170#170#255#172#172#172#255#171#171#171#255
-  +#171#171#171#255#171#171#171#255#171#171#171#255#171#171#171#255#171#171#168
-  +#255#172#172#182#255#133#138'4'#255#146#156#1#255#149#157#3#255#145#154#0#255
-  +#143#152#0#255#143#152#0#255#143#152#0#255#142#151#0#255#143#151#0#255#143
-  +#151#0#255#143#152#0#255#143#152#0#255#144#153#0#255#146#156#1#255#148#158#1
-  +#255#144#154#0#255#130#139#0#255'x'#127#16#255#143#145'k'#251#177#176#184#254
-  +#163#163#163#211#201#202#198#5#169#170#165#1#190#185#230#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#143#143#143#0#131#131#131'J'#163#163
-  +#163#254#165#165#165#253#166#166#166#254#158#158#158#254#156#156#156#255#175
-  +#175#175#255#171#171#171#255#172#172#172#255#174#174#174#255#175#175#175#255
-  +#175#175#175#255#174#174#174#255#172#172#172#255#171#172#169#255#172#171#183
-  +#255#140#145';'#255#142#151#0#255#142#151#2#255#143#152#0#255#143#152#0#255
-  +#143#152#1#255#144#153#2#255#145#153#2#255#145#154#2#255#145#154#2#255#144
-  +#153#2#255#143#152#1#255#143#152#0#255#142#151#0#255#142#151#1#255#143#151#2
-  +#255#146#155#4#255#145#154#0#254#129#138#0#254#131#134'>'#252#165#165#169#255
-  +'}}'#132'I'#152#148#164#0#149#148#157#2#131#130#137#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#157#157#157#0#144#144#144's'#165#165#165#254#165#165
-  +#165#251#167#167#167#255#157#157#157#255#160#160#160#255#174#174#174#255#174
-  +#174#174#255#178#178#178#255#179#179#179#255#179#179#179#255#179#179#179#255
-  +#179#179#179#255#178#178#178#255#175#175#173#255#174#174#185#255#140#145'A'
-  +#255#143#153#0#255#144#153#3#255#144#153#1#255#145#154#0#255#143#153#0#255
-  +#140#149#0#255#137#147#0#255#137#147#0#255#138#148#0#255#141#151#0#255#145
-  +#155#0#255#147#156#0#255#146#155#0#255#145#155#0#255#145#155#0#255#145#154#0
-  +#255#144#153#0#255#148#158#0#255#139#149#0#251#131#137'!'#254#146#146#137#178
-  +#147#166#155#0#171#175#130#2#0#0#0#0#137#137#137#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#175#175#175#0#147#147#147#154#166#166#166#255#164#164#164#250
-  +#167#167#167#254#155#155#155#255#162#162#162#255#178#178#178#255#179#179#179
-  +#255#179#179#179#255#179#179#179#255#179#179#179#255#179#179#179#255#179#179
-  +#179#255#179#179#179#255#179#179#177#255#181#181#191#255#139#144'G'#255#135
-  +#145#0#255#140#149#0#255#140#150#0#255#137#145#0#255#140#147'&'#255#151#155
-  +'P'#255#158#161'i'#255#158#160'l'#255#154#157'e'#255#143#148'J'#255#131#138
-  +#28#255#129#137#6#255#129#136#18#255#132#139#25#255#131#137#27#255#131#137#30
-  +#255#130#137'!'#255#129#136'&'#254#133#138','#254#130#135')'#253'nqF'#249':F'
-  +'?(dfZ'#0'llf'#5#131#131#131#3#156#156#156#3#131#131#131#2#183#183#183#0#178
-  +#178#178#0#0#0#0#0#241#241#241#0#155#155#155#184#166#166#166#255#165#165#165
-  +#251#170#170#170#255#156#156#156#255#168#168#168#255#182#182#182#255#178#178
-  +#178#255#179#179#179#255#180#180#180#255#179#179#179#255#179#179#179#255#179
-  +#179#179#255#179#179#179#255#178#178#178#255#182#182#184#255#141#141#131#255
-  +#133#135'j'#255#136#138'd'#255#129#132'T'#255#130#132'r'#255#153#152#160#255
-  +#154#153#164#255#159#158#168#255#165#165#174#255#157#156#166#255#151#150#161
-  +#255#137#137#143#255'yyv'#255#142#142#146#255#148#148#153#255#148#148#154#255
-  +#150#150#158#255#151#151#159#255#152#152#161#254#152#152#162#255#151#150#162
-  +#252#153#153#157#254#135#133#135#210#146#145#149#27#165#166#165#0'zzz'#0#163
-  +#163#163#0#143#143#143#0#212#212#212#0#203#203#203#0'kkk'#0#250#250#250#4#157
-  +#157#157#208#168#168#168#255#171#171#171#252#176#176#176#255#160#160#160#255
-  +#170#170#170#255#181#181#181#255#178#178#178#255#180#180#180#255#179#179#179
-  +#255#180#180#180#255#180#180#180#255#179#179#179#255#180#180#179#255#178#178
-  +#179#255#181#181#181#255#150#150#152#255#152#152#157#255#154#154#161#255#157
-  +#156#165#255#151#151#155#255#132#132#131#255#127#127'|'#255#134#134#132#255
-  +#136#136#134#255#134#134#132#255#135#135#133#255#127#127'}'#255#151#151#152
-  +#255#153#153#153#255#149#149#148#255#146#146#144#255#142#143#141#255#139#139
-  +#137#255#135#135#133#255#131#131#130#254#142#142#140#255#142#142#142#252#144
-  +#144#144#255'zzz'#195#141#141#141'v'#139#139#139'{'#136#136#136'}wwwN'#174
-  ,#174#174#0#196#196#196#1'```'#0#11#11#11'('#157#157#157#226#171#171#171#255
-  +#173#173#173#253#175#175#175#255#160#160#160#255#169#169#169#255#181#181#181
-  +#255#179#179#179#255#179#179#179#255#180#180#180#255#180#180#180#255#180#180
-  +#180#255#180#180#180#255#179#179#180#255#179#179#178#255#182#182#183#255#150
-  +#150#150#255#148#148#146#255#155#156#154#255#138#138#135#255'tts'#255#130#130
-  +#130#255#140#140#140#255#141#141#141#255#143#143#143#255#146#146#146#255#149
-  +#149#149#255#135#135#135#255#127#127#127#255'yyy'#255'zzz'#255'zzz'#255'zzz'
-  +#255'~~~'#255'www'#255#132#132#132#255#174#174#174#254#170#170#170#255#170
-  +#170#170#252#173#173#173#255#172#172#172#255#171#171#171#255#172#172#172#255
-  +#153#153#153#224#176#176#176#1#179#179#179#1'eee'#2'qqqT'#162#162#162#236#173
-  +#173#173#255#172#172#172#254#176#176#176#255#161#161#161#255#168#168#168#255
-  +#182#182#182#255#179#179#179#255#180#180#180#255#180#180#180#255#180#180#180
-  +#255#180#180#180#255#180#180#180#255#180#180#180#255#178#178#178#255#183#183
-  +#183#255#152#152#152#255#145#145#145#255#152#152#152#255#131#131#131#255#149
-  +#149#149#255#154#154#154#255#153#153#153#254#155#155#155#255#154#154#154#254
-  +#154#154#154#254#155#155#155#254#136#136#136#254'zzz'#255#134#134#134#254#134
-  +#134#134#255#134#134#134#255#135#135#135#255#128#128#128#255#128#128#128#255
-  +#165#165#164#255#171#172#170#255#171#171#169#254#171#171#170#255#171#171#170
-  +#253#171#171#170#251#171#171#170#249#172#172#171#247#170#170#170#251'xxx'#167
-  +'TTT'#0#171#171#171#0'}}}'#127#169#169#169#242#173#173#173#255#173#173#173
-  +#253#176#176#176#255#162#162#162#255#167#167#167#255#182#182#182#255#179#179
-  +#179#255#180#180#180#255#180#180#180#255#180#180#180#255#180#180#180#255#180
-  +#180#180#255#180#180#180#255#178#178#178#255#183#183#183#255#154#154#154#254
-  +#145#145#145#255#155#155#155#253#141#141#141#251#154#154#154#251#154#154#154
-  +#251#152#152#152#250#152#152#152#250#150#150#150#250#149#149#149#250#149#149
-  +#149#251'}}}'#252'rrr'#254'|||'#255'xxx'#254'yyy'#255'sss'#255#130#130#129
-  +#255#171#171#172#255#177#177#181#255#174#173#177#255#175#175#179#255#175#175
-  +#179#255#175#174#180#255#176#175#179#255#176#176#178#255#174#174#174#255#176
-  +#176#175#255#175#175#175#255#145#145#145#190#149#149#149#23#130#130#130#157
-  +#171#171#171#246#174#174#174#255#173#173#173#254#176#176#176#255#162#162#162
-  +#255#167#167#167#255#182#182#182#255#179#179#179#255#180#180#180#255#180#180
-  +#180#255#180#180#180#255#180#180#180#255#180#180#180#255#180#180#180#255#179
-  +#179#179#255#181#181#181#254#165#165#165#255#186#186#186#254#199#199#199#255
-  +#134#134#134#255'xxx'#255#128#128#128#255'}}}'#255'|||'#255'zzz'#255'zzz'#255
-  +'{{{'#255'xxx'#255'ttt'#254'uuu'#254'www'#255'{{{'#255'uuu'#255#152#152#153
-  +#255#160#160#156#255#151#153#134#255#154#155#136#255#153#154#134#255#153#154
-  +#134#255#153#155#132#254#149#150#130#255#146#146#140#232#150#149#153#212#150
-  +#150#153#214#159#159#159#210#158#158#158#227'___Z'#138#138#138#179#171#171
-  +#171#249#173#173#173#255#172#172#172#254#175#175#175#255#162#162#162#255#167
-  +#167#167#255#181#181#181#255#178#178#179#255#179#179#180#255#179#179#179#255
-  +#179#179#179#255#179#179#179#255#179#179#179#255#179#179#179#255#178#178#178
-  +#255#182#182#182#255#164#164#164#253#189#189#189#254#164#164#164#237#145#145
-  +#145#180#141#141#141#169'nnn'#155'ooo'#142'nnn'#129'jjjtlllgwwwUiii'#134#164
-  +#164#164#255#172#172#172#252#174#174#174#254#177#177#177#254#180#180#179#255
-  +#185#185#186#255#167#167#162#255#128#136#9#255#137#146#0#255#135#144#0#255
-  +#136#144#0#255#138#147#0#250#129#137#0#255'ci'#5#157'fl'#0#5'nu'#0#8#0#0#0#6
-  +#0#0#0#5'rrr'#6#140#140#140#183#171#171#171#250#174#174#174#255#175#175#175
-  +#254#177#177#177#255#161#161#161#255#168#168#168#255#181#181#179#255#178#178
-  +#176#255#179#179#177#255#179#179#177#255#179#179#177#255#179#179#177#255#179
-  +#179#177#255#179#179#178#255#179#179#179#255#182#182#182#254#166#166#166#251
-  +#181#181#181#255#138#138#138'^'#172#172#172#0#166#166#166#0#136#136#136#0#134
-  +#134#134#0#127#127#127#0'www'#0'uuu'#0#206#206#206#0#219#219#219#0#173#173
-  +#173#200#197#197#197#254#194#194#194#252#194#194#194#255#193#193#193#255#193
-  +#193#192#255#191#191#201#255#142#148'1'#255#144#154#0#255#145#153#1#255#145
-  +#154#0#255#144#153#0#252#145#155#0#255#142#151#7#202#141#159#0#0#168#184#0#0
-  +'48'#0#0'DDD'#0'^^^'#0#140#140#140#183#172#172#172#250#172#172#172#255#160
-  +#160#160#254#170#170#170#255#158#158#158#255#171#171#172#255#184#183#193#255
-  +#181#180#191#255#182#181#193#255#181#181#192#255#182#181#192#255#181#181#192
-  +#255#181#180#192#255#180#180#185#255#176#177#176#255#176#176#177#253#165#165
-  +#165#255#175#175#175#231#30#30#30#16'jjj'#2'kkk'#2#147#147#147#2#128#128#128
-  +#3'zzz'#3'uuu'#3'yyy'#3#178#178#178#7#181#181#181#0#149#149#149'n'#188#188
-  +#188#255#191#191#191#251#191#191#191#254#191#191#191#255#190#190#188#255#194
-  +#193#204#255#148#151'R'#255#139#149#0#255#143#152#2#255#142#151#0#255#143#152
-  +#0#253#142#151#0#255#147#155#5#226'VkY'#10#168#173'E'#0#162#168'*'#0#0#0#0#0
-  ,#0#0#0#0#138#138#138#179#173#173#173#249#167#167#167#255#148#148#148#254#159
-  +#159#159#255#146#146#147#255#154#154#149#255#146#149'X'#255#143#147'P'#255
-  +#144#147'O'#255#143#147'M'#255#142#147'K'#255#143#147'K'#255#140#145'D'#255
-  +#144#147'p'#255#168#168#173#255#163#163#162#252#178#178#178#254#172#172#172
-  +#200#0#0#0#0#245#245#245#0'eee'#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0'vvv'#0#159
-  +#159#159#3#142#142#142#0#137#137#137'I'#187#187#187#255#192#192#192#253#191
-  +#191#191#253#191#191#191#255#191#191#189#255#195#194#204#255#150#154']'#255
-  +#139#148#0#255#143#152#1#255#143#152#0#255#144#153#0#252#142#151#0#255#146
-  +#155#1#232#161#168#29#18#154#164#20#0#162#167'*'#0#0#0#0#0#0#0#0#0#131#131
-  +#131#156#173#173#173#246#167#167#167#255#159#159#159#253#178#178#177#255#174
-  +#174#176#255#171#171#160#255#143#152#3#255#140#150#0#255#141#151#0#255#141
-  +#151#0#255#140#150#0#255#142#151#0#255#138#148#0#255#145#150'G'#255#195#195
-  +#206#255#192#193#190#252#196#196#196#255#171#171#171#206#255#255#255#2#0#0#0
-  +#0#140#140#140#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#129#129#129#0#158#158#158#3
-  +#144#144#144#1#140#140#140'N'#187#187#187#254#192#192#192#253#191#191#191#253
-  +#192#192#192#255#190#190#188#255#194#194#204#255#149#153'W'#255#140#149#0#255
-  +#144#153#2#255#142#151#0#255#144#153#0#253#143#152#0#255#146#155#2#231#177
-  +#184')'#18#157#166#25#0#162#171'*'#0#0#0#0#0#0#0#0#0'{{{y'#172#172#172#241
-  +#169#169#169#255#155#155#155#254#175#175#174#255#172#172#173#255#172#173#169
-  +#255#147#155#25#255#143#152#2#255#144#153#3#255#144#153#2#255#144#153#2#255
-  +#144#152#4#255#142#152#2#255#141#146'3'#255#189#189#198#255#190#190#189#253
-  +#193#193#193#254#179#179#179#240'EEE'#27'```'#1'zzz'#0#205#205#205#0#0#0#0#0
-  +#0#0#0#0#131#131#131#0'zzz'#0#196#196#196#4#201#201#201#0#154#154#154#129#191
-  +#191#191#255#191#191#191#251#191#191#191#254#191#191#191#255#191#191#189#255
-  +#191#190#201#255#143#148';'#255#142#152#0#255#143#152#1#255#143#152#0#255#143
-  +#152#0#252#142#151#0#255#145#154#4#224'''>'#0#8#162#170':'#0#162#170'*'#0#0#0
-  +#0#0#0#0#0#0'^^^J'#167#167#167#235#170#170#170#255#155#155#155#253#175#175
-  +#175#255#173#173#171#255#174#174#179#255#152#158'.'#255#141#151#0#255#144#153
-  +#1#255#144#153#0#255#144#153#0#255#142#151#0#255#144#154#0#255#135#143#13#255
-  +#179#179#177#255#194#194#194#254#192#192#191#250#190#190#190#255#150#150#150
-  +'~'#184#184#184#0#183#183#183#5#193#193#193#1'ZZZ'#0'```'#0#158#158#158#0'yy'
-  +'y'#3#189#189#189#1#191#191#191#13#173#173#173#222#193#193#193#254#191#191
-  +#191#252#192#192#192#255#190#190#190#255#193#193#193#255#181#181#183#255#136
-  +#143#18#255#144#153#0#255#142#151#0#255#144#153#0#254#142#151#0#251#145#154#4
-  +#254#155#163#23#196#142#153#13#0#158#167#11#0#162#171'*'#0#0#0#0#0#0#0#0#0#6
-  +#6#6#23#164#164#164#220#172#172#172#255#154#154#154#253#175#175#175#255#173
-  +#173#169#255#175#174#184#255#162#167'Z'#255#143#152#0#255#143#152#1#255#143
-  +#152#0#255#144#153#0#255#143#152#0#255#144#153#1#255#137#147#0#255#156#159'u'
-  +#255#195#194#202#254#184#184#181#253#185#185#185#252#177#177#177#245#144#144
-  +#144'B'#175#175#175#0#175#175#175#0#139#139#139#3#0#0#0#3#165#165#165#2#187
-  +#187#187#0#173#173#173#0#140#140#140#162#181#181#181#255#180#180#180#251#182
-  +#182#182#255#187#187#187#254#190#190#188#255#196#196#203#255#159#161#127#255
-  +#136#146#0#255#144#153#1#255#143#152#0#255#144#153#0#254#141#150#0#250#155
-  +#164#26#254#168#175'4'#150#175#181'7'#0#168#176'-'#2#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#162#162#162#195#174#174#174#255#154#154#154#252#174#174#174#255#172
-  +#172#171#255#174#173#181#255#171#173#138#255#150#159#10#255#142#151#0#255#144
-  +#153#0#255#144#153#0#255#144#153#0#255#143#152#0#255#144#153#0#255#135#142#29
-  +#255#173#172#177#254#180#180#179#255#177#177#177#253#181#181#181#254#170#170
-  +#170#242#164#164#164'l'#190#190#190#13#4#4#4#0'###'#0#158#158#158#0#169#169
-  +#169'.'#160#160#160#175#183#183#183#255#179#179#179#252#179#179#179#254#179
-  +#179#179#254#177#177#177#255#186#186#184#255#184#184#192#255#137#143'#'#255
-  +#143#153#0#255#143#152#1#255#144#153#0#254#143#152#0#255#143#151#0#251#162
-  +#170'('#255#162#170'-S'#166#173'2'#0#163#171')'#2#0#0#0#0#0#0#0#0#0#0#0#0#198
-  +#198#198#0#153#153#153#161#174#174#174#254#154#154#154#250#172#172#172#254
-  +#173#173#173#255#173#172#174#255#174#173#172#255#162#169'8'#255#144#153#0#255
-  +#143#152#0#255#143#152#0#255#143#152#0#255#142#151#0#255#144#153#1#255#139
-  +#148#0#255#137#141'N'#255#181#180#191#254#180#180#177#255#177#177#177#253#182
-  +#182#182#255#176#176#176#255#175#175#175#224#166#166#166#174#151#151#151#161
-  +#156#156#156#195#172#172#172#249#182#182#182#255#179#179#179#252#179#179#179
-  +#255#179#179#179#255#178#178#179#254#179#179#175#255#181#180#193#255#142#146
-  +'T'#255#140#149#0#255#144#153#1#255#143#152#0#255#143#152#0#255#142#151#0#252
-  +#148#157#10#253#165#172'.'#230#189#194'L'#16#165#173'%'#0#160#167'%'#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#161#161#161#0#147#147#147'v'#174#174#174#254#155#155#155
-  +#251#170#170#170#255#174#174#174#255#172#173#171#255#173#173#182#255#171#174
-  ,'x'#255#153#162#14#255#142#150#0#255#144#153#0#255#143#152#0#255#143#152#0
-  +#255#142#151#0#255#145#154#1#255#135#144#0#255#142#145'c'#255#181#180#192#254
-  +#181#181#180#255#178#178#176#254#179#179#179#253#180#180#180#255#181#181#181
-  +#255#183#183#183#255#183#183#183#255#181#181#181#255#178#178#178#252#179#179
-  +#180#255#179#179#179#254#178#178#176#254#181#181#179#255#182#181#193#255#145
-  +#148'h'#255#136#145#0#255#145#154#1#255#143#152#0#255#144#153#0#254#144#153#0
-  +#254#141#150#0#251#155#163#27#255#168#175'7'#134#180#187'D'#0#167#175'+'#2
-  +#159#167'#'#0#0#0#0#0#0#0#0#0#0#0#0#0#148#148#148#0#133#133#133'H'#172#172
-  +#172#255#157#157#157#253#167#167#167#254#175#175#175#255#173#173#172#255#173
-  +#172#174#255#173#173#170#255#167#173'B'#255#146#155#4#255#142#151#0#255#144
-  +#153#0#255#144#153#0#255#143#152#0#255#142#151#0#255#145#154#1#255#137#145#0
-  +#255#140#144'R'#255#172#172#178#254#184#183#190#254#181#181#180#254#179#179
-  +#176#252#178#178#176#251#178#178#177#251#178#178#177#251#178#178#177#253#179
-  +#179#177#254#179#179#176#254#181#181#179#254#183#183#189#255#173#173#181#255
-  +#141#145'X'#255#136#145#0#255#145#154#1#255#143#152#0#255#144#153#0#255#144
-  +#153#0#255#142#151#0#252#146#155#5#254#166#174'&'#230#168#176'0'#22#164#172
-  +'-'#1#160#167'.'#0#160#168'#'#0#0#0#0#0#0#0#0#0#0#0#0#0']]]'#0'RRR'#28#169
-  +#169#169#242#162#162#162#255#161#161#161#253#175#175#175#254#173#173#173#255
-  +#173#173#171#255#173#173#179#255#173#174#142#255#161#169'$'#255#143#152#0#255
-  +#143#152#0#255#144#153#0#255#144#153#0#255#144#153#0#255#143#152#0#255#145
-  +#154#1#255#140#149#0#255#134#140' '#255#152#154'z'#255#172#171#176#255#181
-  +#180#191#255#184#183#191#255#184#183#188#255#183#183#187#255#184#183#188#255
-  +#184#183#190#255#182#181#191#255#173#172#178#255#152#155#127#255#134#140'%'
-  +#255#139#149#0#255#145#154#0#255#143#152#0#255#144#153#0#255#144#153#0#255
-  +#143#152#0#254#142#151#0#251#152#160#18#255#140#146'6f'#149#157'$'#0#151#158
-  +'%'#3#161#168','#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#229#229#229#1#249#249#249
-  +#2#162#162#162#204#167#167#167#254#157#157#157#252#176#176#176#255#172#172
-  +#172#255#173#174#173#255#172#173#171#255#174#173#181#255#171#175's'#255#157
-  +#166#23#255#142#151#0#255#143#152#0#255#144#153#0#255#143#152#0#255#144#153#0
-  +#255#143#152#0#255#144#153#1#255#144#153#0#255#136#146#0#255#134#141#27#255
-  +#142#146'N'#255#151#153'u'#255#157#159#138#255#160#160#145#255#157#159#139
-  +#255#151#153'w'#255#142#146'R'#255#134#141#31#255#136#145#0#255#144#153#0#255
-  +#144#153#1#255#143#152#0#255#144#153#0#255#143#152#0#255#143#152#0#254#143
-  +#152#1#253#147#157#1#255#152#157'F'#236#175#174'M'#16'nk'#163#0#141#143'h'#1
-  +#165#172'-'#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#187#187#187#8#193#193#193#0#154
-  +#154#154#148#171#171#171#254#153#153#153#250#174#174#174#254#173#173#173#255
-  +#174#174#174#255#173#173#173#255#173#173#173#255#173#173#178#255#170#174'h'
-  +#255#156#164#19#255#142#151#0#255#143#152#0#255#144#153#0#255#144#153#0#255
-  +#144#153#0#255#143#152#0#255#143#152#1#255#145#154#1#255#145#154#0#255#141
-  +#150#0#255#137#146#0#255#135#143#0#255#134#143#0#255#134#143#0#255#136#145#0
-  +#255#140#150#0#255#144#154#0#255#145#154#1#255#143#152#1#255#143#152#0#255
-  +#144#153#0#255#143#152#0#254#144#153#0#254#143#152#1#255#141#151#0#249#161
-  +#167'J'#252#161#161#167#170#232#231#184#0#213#212#229#1'ty%'#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#151#151#151#9#143#143#143#0#135#135#135'S'#175#175
-  +#175#255#159#159#159#251#173#173#173#254#173#173#173#254#173#173#173#254#174
-  +#174#174#255#173#173#173#255#173#173#173#255#173#173#178#255#170#174'm'#255
-  +#157#165#24#255#143#153#0#255#142#151#0#255#144#153#0#255#144#153#0#255#143
-  +#152#0#255#144#153#0#255#143#152#0#255#143#152#1#255#144#153#2#255#145#154#2
-  +#255#145#154#0#255#145#155#0#255#145#154#0#255#145#154#1#255#144#153#2#255
-  +#143#152#1#255#143#152#0#255#144#153#0#255#144#153#0#254#144#153#0#254#144
-  +#153#1#255#142#151#0#254#141#151#0#251#166#171'M'#249#186#185#188#255#140#140
-  +#142'V'#154#153#175#0#159#159#158#2'sx'#22#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#135#135#135#3'yyy'#0'rrr'#24#174#174#174#247#171#171#171#255#172#172
-  +#172#248#179#179#179#250#173#173#173#251#173#173#173#252#173#173#173#253#172
-  +#173#172#253#172#173#172#254#173#173#180#254#171#173#130#254#161#168','#255
-  +#147#156#2#254#142#151#0#255#143#152#1#255#144#153#1#255#144#153#0#255#144
-  +#153#0#255#144#153#0#255#144#153#0#255#143#152#0#255#143#152#0#255#143#152#0
-  +#255#143#152#0#255#143#152#0#255#144#153#0#254#144#153#0#254#144#153#0#254
-  +#144#153#0#254#143#152#0#253#143#152#0#250#142#152#0#251#148#157#10#255#169
-  +#173'g'#255#181#180#187#255#172#172#173#204#146#147#143#16#132#132'~'#0#137
-  +#137#137#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#21#21#21#0#183#183
-  +#183#1#156#156#156#0#132#132#132'Q'#161#161#161#215#163#163#163#255#185#185
-  +#185#255#182#182#182#255#182#182#182#255#180#180#180#255#178#178#178#255#176
-  +#176#176#255#174#175#173#253#174#174#182#251#172#173#161#251#165#170'W'#251
-  ,#153#162#21#251#145#154#0#251#142#151#0#252#142#151#0#253#142#151#0#253#143
-  +#152#0#253#143#152#0#254#143#152#0#254#144#153#0#254#143#153#0#254#143#152#0
-  +#254#143#152#0#254#143#152#0#253#143#152#0#251#143#152#0#251#144#153#0#254
-  +#145#154#0#255#148#157#9#255#154#161'4'#255#165#167#142#230#179#178#194#161
-  +#209#209#209'J'#197#197#194#6#234#234#235#0#173#173#174#0#140#140#140#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0'TTT'#0#191#191#191#0'xxx'#1'aaa'#0
-  +#214#214#214#11#130#130#130'k'#157#157#157#152#163#163#163#176#166#166#166
-  +#201#170#170#170#225#173#173#173#240#176#176#176#252#176#176#176#255#176#176
-  +#174#255#178#178#180#255#180#180#186#255#179#180#158#255#170#175'c'#255#159
-  +#167'-'#255#152#161#15#255#148#157#4#255#146#155#0#255#145#154#0#255#144#153
-  +#0#255#143#152#0#255#143#152#0#255#144#153#0#255#145#154#0#255#143#152#3#255
-  +#147#156#7#255#149#157#11#255#147#155#17#255#145#151'"'#224#139#142'W'#160
-  +#132#130#156'T'#144#142#186#19#169#168#183#0#0#0#0#0#187#187#186#0#221#221
-  +#221#0#167#167#167#0#136#136#136#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#181#181#181#0'|||'#0'rrr'#2#183#183#183#0#142#142#142#0#192
-  +#192#192#0#0#0#0#0#0#0#0#0#0#0#0#8'XXX'#25'lll-'#142#142#142'B'#142#142#143
-  +'['#153#153#152't'#152#152#150#139#158#158#166#163#163#162#175#184#165#166
-  +#156#200#161#163't'#217#155#159'K'#230#150#157'/'#242#150#157'!'#249#151#159
-  +#27#252#153#161#26#255#154#161#27#255#152#160#27#253#151#159#29#242#164#171
-  +#28#215#152#159'"'#175#143#150'(w~'#131'.:'#13#0#255#10#255#255#0#0#255#255
-  +#186#0#0#0#0#0#193#191#209#2#255#255#255#2#220#220#218#0#230#230#230#0#160
-  +#160#160#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#142#142#142#0'xxx'#0#208#208#208#0#135#135#135#3#177#177#177#3#255#255
-  +#255#1'???'#0'   '#0'nnn'#0#127#127#127#0#147#147#147#0#163#163#163#0#181#181
-  +#181#0#0#0#0#0#216#216#236#0#0#0#0#0#0#0#0#0'&'#21#255#7'aU'#255#14'b`'#136
-  +#26'opS''x|40'#137#142'79'#139#144':<~'#132'-0y|8'#28#238#240#7#6#181#192#3#0
-  +#166#173#26#0#130#136')'#0']Z'#132#0#0#0#255#2'h['#208#2#0#0#0#0#197#195#213
-  +#0#242#242#247#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#1#170#170#170#1'www'#2#154#154#154#3#166#166#166#4#180
-  +#179#180#4#255#255#255#4#184#185#186#4#255#255#255#2#255#255#230#0'5#'#255#0
-  +'H2'#255#0'_Z'#171#0'qrV'#0#127#132'8'#0#140#145'<'#0#143#148'?'#0#133#139'0'
-  +#0'}'#128'9'#0#243#245#8#0#169#179#3#3#166#174#16#4#132#139'#'#3#0#0#0#1#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#1#143#149','#1
-  +'{'#129')'#2'w{3'#2'{'#127'7'#2#129#135'$'#2#0#0#0#1#253#255#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#255#255#255#255#255#255#0#0#255#255#255#255#255#255#0#0#255#255#255#255
-  +#255#255#0#0#255#255#255#255#255#255#0#0#255#255#255#255#255#255#0#0#255#255
-  +#255#255#255#255#0#0#255#255#255#255#255#255#0#0#252#0#127#255#255#255#0#0
-  +#248#0#0#0#7#255#0#0#224#0#0#0#7#255#0#0#192#0#0#0#3#255#0#0#192#0#0#0#3#255
-  ,#0#0#192#0#0#0#3#255#0#0#128#0#0#0#1#255#0#0#128#0#0#0#1#255#0#0#128#0#0#0#0
-  +#255#0#0#128#0#0#0#0#15#0#0#128#0#0#0#0#7#0#0#0#0#0#0#0#3#0#0#0#0#0#0#0#1#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#31#0#0#0#0#15#248#0#31#0#0#0#0#31#248#0#31#0#0#0#0
-  +#31#252#0#31#0#0#0#0#31#252#0#31#0#0#0#0#31#248#0#31#0#0#128#0#15#248#0#31#0
-  +#0#128#0#15#240#0#31#0#0#128#0#3#224#0#31#0#0#128#0#0#0#0'?'#0#0#128#0#0#0#0
-  +'?'#0#0#192#0#0#0#0#127#0#0#192#0#0#0#0#127#0#0#192#0#0#0#0#255#0#0#192#0#0#0
-  +#0#255#0#0#192#0#0#0#0#255#0#0#224#0#0#0#1#255#0#0#224#0#0#0#7#255#0#0#248#0
-  +#0#0#31#255#0#0#255#248#0#1#255#255#0#0#255#255#255#255#255#255#0#0#255#255
-  +#255#255#255#255#0#0#255#255#255#255#255#255#0#0#255#255#255#255#255#255#0#0
-  +#255#255#255#255#255#255#0#0#255#255#255#255#255#255#0#0#255#255#255#255#255
-  +#255#0#0'('#0#0#0' '#0#0#0'@'#0#0#0#1#0' '#0#0#0#0#0#128#16#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0'vvv'#0'{{{'#0'ZZZ'#0#143#143#143#2#148#148#148#2#146#146#146#2
-  +#146#146#146#2#146#146#146#2'nnn'#2#0#0#0#0#0#0#0#0'fff'#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#187#187#187#0'[[['
-  +#0'{{{'#2'aaa'#0#141#141#141#0#140#140#140#0#141#141#141#0#141#141#141#0#141
-  +#141#141#0#139#139#139#0'ccc'#0'aa`'#3'lko'#2#147#148'y'#3'y|O'#3'oq<'#3'uxE'
-  +#3#139#141'j'#3#165#166#153#3#173#173#173#3#171#171#171#3#172#172#172#3#174
-  +#174#174#3#149#149#149#1#164#164#164#0#166#166#166#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#138#138#138#0#161#161#161#1'SSS'#2'ooo'#0'WWW'#10#133#133
-  +#133'.'#137#137#137','#135#135#135'-'#135#135#135'-'#135#135#135','#134#134
-  +#134',\\Y'#2'YYO'#0'nnj'#0#137#137'y'#0'qrP'#0'fh;'#0'kmE'#0#130#130'k'#0#166
-  +#166#169#0#195#193#215#0#193#192#208#0#180#180#182#0#180#180#179#0#151#151
-  +#151#0#157#157#157#0#157#157#157#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#141#141#141#1#158#158#158#0#159#159#159#0#135#135#135'O'#146#146#146#214#167
-  +#167#167#254#170#170#170#254#169#169#169#255#170#170#170#255#170#170#170#253
-  +#172#172#172#255#155#155#157#197#164#164#171#153#159#158#163#156#142#141#137
-  +#153'yyj'#146'ss]'#147'wxd'#147#133#133'|'#147#152#152#157#147#166#166#179
-  +#147#168#167#176#146#161#161#160#144#158#158#156#147#139#139#139'&'#143#143
-  +#143#0#153#153#153#1#143#143#143#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#150#150
-  +#150#3#145#145#145#27#163#163#163#164#164#164#164#255#159#159#159#255#172#172
-  +#172#254#171#171#171#255#172#172#172#255#172#172#172#255#171#171#170#255#175
-  +#175#176#255#155#155#148#255'~'#129'Y'#255'rv*'#255'sx'#21#255'u|'#12#255'v}'
-  +#8#255'v|'#10#255'v{'#17#255'y~%'#255#131#134'K'#255#152#153#132#255#172#172
-  +#176#255#177#177#182#255#157#157#156#156#191#191#191#0#187#187#187#2#151#151
-  +#156#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#159#159#159#0#151#151#151#138#164#164
-  +#164#255#163#163#163#251#158#158#158#253#173#173#173#254#170#170#170#254#171
-  +#171#171#254#171#171#171#254#170#169#167#254#177#176#184#254#137#140'_'#252
-  +'u}'#0#251#141#150#0#251#146#156#0#251#148#157#0#251#148#158#0#251#148#158#0
-  +#251#147#156#0#251#143#153#0#251#136#145#0#251#127#135#0#251#129#135'%'#249
-  +#157#157#137#251#172#171#183#241#160#160#158#20#146#145#153#0#151#150#169#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#201#201#201#0#157#157#157#181#167#167#167#252
-  +#161#161#161#251#160#160#160#255#173#173#173#254#173#173#173#255#176#176#176
-  +#255#176#176#176#255#173#173#170#255#174#174#184#255#154#157'i'#255#145#155#3
-  +#255#145#154#5#255#144#153#0#255#142#151#0#255#140#150#0#255#141#150#0#255
-  +#143#152#0#255#145#155#0#255#147#156#0#255#148#157#0#255#144#154#0#254#133
-  +#142#0#251#146#150'X'#255#150#150#156'r'#163#164#158#0#166#167#151#3'ttr'#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#244#244#244#5#160#160#160#213#166#166#166#255#160#160
-  +#160#253#163#163#163#255#178#178#178#255#178#178#178#255#179#179#179#255#179
-  +#179#179#255#178#178#176#255#181#180#189#255#154#156'p'#255#135#145#0#255#140
-  +#150#0#255#139#148#5#255#146#153'('#255#151#156'<'#255#149#155';'#255#142#148
-  +'"'#255#135#143#6#255#136#144#11#255#136#144#15#255#136#144#19#255#140#147#22
-  +#252#133#141#22#254'}'#127'Q'#215'bg;'#2'lpA'#0'vvt'#0'EEE'#0'777'#0#0#0#0#0
-  +']]].'#162#162#162#232#169#169#169#255#163#163#163#254#168#168#168#255#181
-  +#181#181#255#178#178#178#255#179#179#179#255#179#179#179#255#178#178#178#255
-  +#183#183#184#255#158#158#151#255#137#139'l'#255#140#142'e'#255#141#142'}'#255
-  +#147#146#152#255#155#155#164#255#154#153#163#255#140#140#144#255#131#131'{'
-  ,#255#147#147#142#255#147#148#146#255#146#146#146#254#146#145#149#254#144#144
-  +#148#252#142#142#140#255'ut~'#149'{z'#136#11#138#138#137#12''''''''#2'LLL'#2
-  +#255#255#255#1#133#133#133'`'#164#164#164#244#175#175#175#255#167#167#167#253
-  +#170#170#170#255#180#180#180#255#178#178#178#255#180#180#180#255#179#179#179
-  +#255#179#179#179#255#182#182#182#255#162#162#163#255#152#152#158#255#150#150
-  +#158#255#130#129#133#254#132#132#130#254#137#137#134#254#141#141#138#254#138
-  +#138#137#254#136#136#138#254#136#136#137#255#132#132#132#254#133#133#132#255
-  +'zzy'#255#143#143#142#254#163#163#163#253#160#160#157#255#164#165#162#224#166
-  +#166#166#225#148#148#148#160#197#197#197#0#173#173#173#5#141#141#141#145#169
-  +#169#169#249#175#175#175#255#167#167#167#254#169#169#169#255#181#181#181#255
-  +#179#179#179#255#179#179#179#255#180#180#180#255#178#178#178#255#182#182#182
-  +#254#163#163#162#255#143#143#141#254#140#140#137#251#147#147#146#251#156#156
-  +#156#251#155#155#155#251#159#159#159#252#151#151#150#253'yyx'#253#127#127'~'
-  +#255#127#128#127#254'}}|'#255#139#139#139#254#174#173#176#255#177#176#180#254
-  +#176#175#179#252#175#175#179#255#176#175#177#255#171#171#172#255#151#151#153
-  +'|'#154#154#154#6#150#150#150#186#172#172#172#251#174#174#174#255#167#167#167
-  +#255#168#168#168#255#182#182#182#255#178#178#179#255#179#179#179#255#179#179
-  +#179#255#178#178#178#255#181#181#181#255#168#168#168#255#177#177#177#255#154
-  +#154#154#255#133#133#133#255#135#135#135#255#132#132#132#255'{{{'#255'vvv'
-  +#255'rrr'#255'www'#255'www'#255'~~'#127#254#163#163#160#255#161#162#148#254
-  +#159#160#147#254#160#161#146#254#157#157#144#253#155#155#155#229#157#157#157
-  +#225#154#154#151#236'~~~l'#154#154#154#207#173#173#173#252#176#176#176#255
-  +#169#169#169#254#169#169#168#255#182#182#180#255#179#179#177#255#180#180#178
-  +#255#180#180#178#255#179#179#178#255#181#181#181#254#172#172#172#254#184#184
-  +#184#251#137#137#137#142'mmms|||giiiZ'#182#182#182'K'#182#182#182'B'#161#161
-  +#161#212#178#178#178#255#179#179#178#251#186#186#188#255#172#173#163#255#133
-  +#141#9#255#138#147#2#254#139#148#2#252#131#139#1#254'ou'#13'Ylr'#6#10'rx'#7
-  +#14'lll'#14#155#155#155#210#172#172#172#253#168#168#168#255#162#162#162#255
-  +#168#168#170#255#181#180#190#255#178#178#187#255#179#179#188#255#179#178#187
-  +#255#178#177#184#255#177#177#176#250#170#170#170#254#168#168#168#188#219#219
-  +#219#0#223#223#223#0'555'#0'qqq'#0#183#183#183#0#186#186#186#0#164#164#164'c'
-  +#192#192#192#255#194#194#193#250#194#194#192#254#190#189#196#255#144#151'"'
-  +#255#143#153#0#255#144#152#0#250#145#154#0#255#148#157#6'y'#147#156#1#0#146
-  +#156#0#0'ppp'#0#155#155#155#203#170#170#170#252#157#157#155#255#161#161#165
-  +#254#156#157#135#255#144#150'7'#255#144#150'6'#255#144#150'4'#255#143#149'1'
-  +#255#145#149'P'#255#174#174#178#249#179#179#178#254#170#170#170#144#196#196
-  +#196#4#195#195#195#5#154#154#154#3'~~~'#3#155#155#155#4#155#155#155#2#151#151
-  +#151';'#186#186#186#254#191#191#191#252#191#191#189#253#190#190#198#255#145
-  +#151'/'#255#141#151#0#254#143#151#1#251#143#152#0#255#146#156#3#136#145#154#0
-  +#0#145#154#0#4#0#0#0#0#152#152#152#172#169#169#169#251#163#163#160#255#178
-  +#178#185#255#168#169#138#255#141#151#0#255#142#152#0#255#142#151#0#255#142
-  +#152#0#255#142#150#25#255#189#189#194#250#195#195#194#255#174#174#173#177#232
-  +#232#232#0#211#211#211#3#189#189#189#0#138#138#138#0#178#178#178#3#178#178
-  +#178#0#159#159#159'V'#190#190#190#255#191#191#191#250#192#192#191#254#188#187
-  +#193#255#142#149#30#255#143#152#0#255#143#152#0#250#143#152#0#254#146#155#6
-  +#129#143#153#0#0#144#153#0#4#0#0#0#0#143#143#143'y'#169#169#169#248#161#161
-  +#161#255#174#174#177#254#171#171#160#255#146#155#13#255#142#151#2#255#143#152
-  +#2#255#144#154#2#255#138#147#5#255#175#176#160#253#195#195#198#252#182#182
-  +#181#246#146#146#146'.'#166#166#166#0#185#185#185#0'xxx'#1#209#209#209#0#196
-  +#196#196#0#171#171#171#195#188#188#188#254#189#189#188#251#195#195#197#255
-  +#176#177#164#255#137#146#3#255#144#153#0#254#142#151#0#251#148#157#11#255#164
-  +#171'%_'#161#168'$'#0#159#166#30#3#0#0#0#0'mmm='#168#168#168#236#162#162#162
-  +#255#173#173#172#253#175#174#180#255#158#164':'#255#141#151#0#255#144#153#1
-  +#255#144#152#2#255#141#150#0#255#149#154'M'#255#183#182#194#252#179#179#174
-  +#255#170#170#170#224#180#180#180'G'#180#180#180#5#189#189#189#0#171#171#171
-  +'#'#155#155#155#168#179#179#179#255#178#178#178#252#179#179#174#255#190#189
-  +#201#254#151#156'O'#255#140#149#0#254#144#153#2#254#142#151#0#254#157#165#30
-  +#248#163#168'D%'#177#184'H'#0#165#173','#1#0#0#0#0#225#225#225#10#167#167#167
-  +#216#162#162#162#255#172#172#170#253#174#173#182#255#170#172'{'#255#146#156#2
-  +#255#142#151#1#255#143#152#0#255#144#153#1#255#136#145#1#254#155#157'~'#255
-  +#183#183#193#253#181#181#177#255#173#173#171#255#164#164#164#213#183#183#182
-  +#201#175#175#175#243#181#181#181#255#178#178#176#252#179#179#175#255#183#182
-  +#194#254#157#159'}'#255#138#147#2#255#144#153#1#255#142#151#0#251#145#154#4
-  +#254#163#171'*'#191'|'#130' '#0#162#170'('#1#154#165#0#0#0#0#0#0#221#221#221
-  ,#0#165#165#165#181#163#163#163#254#171#171#170#252#173#173#174#254#174#174
-  +#174#255#162#168'8'#255#142#151#0#255#143#152#1#255#143#152#0#255#144#153#1
-  +#254#137#146#7#254#154#156's'#255#179#178#189#253#184#184#191#253#184#184#185
-  +#255#179#179#178#255#182#182#181#255#181#181#181#251#182#182#188#255#179#179
-  +#189#254#154#157'u'#254#138#147#7#255#144#153#0#254#143#152#0#254#142#151#0
-  +#252#153#161#16#253#163#170'7E'#175#182'8'#0#163#170'('#2#162#171#25#0#0#0#0
-  +#0#172#172#172#0#162#162#162#132#163#163#163#254#168#168#168#251#174#174#173
-  +#255#173#173#179#255#173#174#146#255#155#163#21#255#141#150#0#255#144#153#1
-  +#255#143#152#0#255#144#153#0#255#139#148#0#254#142#148'7'#254#159#161#128#254
-  +#170#170#166#252#175#175#179#251#175#174#178#253#170#170#167#254#159#160#129
-  +#254#143#148'9'#254#139#148#0#255#144#153#0#255#143#152#0#255#143#152#2#251
-  +#144#154#0#254#150#157'('#182#148#157#25#0#166#174#30#1#160#168'%'#0#164#172
-  +'%'#0#0#0#0#0#156#156#156#0#150#150#150'I'#165#165#165#254#164#164#164#252
-  +#174#174#175#254#173#173#171#254#173#173#181#254#171#175#128#255#152#161#13
-  +#255#141#150#0#255#143#152#1#255#144#153#1#255#145#154#1#255#142#152#0#255
-  +#138#147#0#255#138#146#12#255#139#146#29#255#139#146#30#255#138#145#13#255
-  +#138#147#0#255#142#152#0#254#144#153#1#254#143#152#0#254#143#152#0#253#140
-  +#150#0#248#158#164'@'#255#155#155#162'\'#169#170#158#0#166#168#132#3#163#171
-  +'0'#0#0#0#0#0#0#0#0#0#154#154#154#0#146#146#146#18#169#169#169#244#170#170
-  +#170#255#176#176#176#251#172#172#172#251#172#172#171#251#173#172#183#251#171
-  +#174#132#251#154#162#24#252#141#151#0#253#142#151#0#254#143#152#1#254#144#153
-  +#1#254#145#154#1#254#144#154#0#255#144#153#0#254#144#153#0#254#144#154#0#254
-  +#145#154#0#254#144#152#1#252#143#152#0#251#143#152#0#254#143#153#0#255#164
-  +#169'K'#255#178#178#179#242#134#133#145#19#142#141#167#0#158#156#196#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#193#193#193#4#186#186#186#0#165#165#165'g'#158#158#158#236
-  +#178#178#178#255#179#179#179#255#177#177#177#255#177#177#175#255#176#175#183
-  +#255#175#175#159#255#164#169'N'#255#150#158#13#255#143#153#0#255#143#152#0
-  +#254#143#152#0#252#142#152#0#252#142#151#0#252#142#151#0#252#142#152#0#253
-  +#143#152#0#255#144#153#0#255#146#155#3#255#147#155#27#255#158#162'd'#217#172
-  +#170#188#142#167#167#178'0'#141#141#133#0#160#161#142#0#160#159#181#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0'{{{'#1#151#151#151#0'jjj'#25#150#150#150'L'#152#152
-  +#152'f'#168#168#168#129#162#162#162#157#170#170#168#183#170#170#175#205#174
-  +#173#182#224#170#172#143#240#161#166'T'#250#152#159'('#255#148#156#19#255#147
-  +#156#12#255#148#157#11#255#148#156#11#255#149#157#13#255#149#157#17#241#144
-  +#152#21#201#135#141'('#136'y{Y at ljv'#6#173#170#203#0#228#227#231#0#0#0#0#0#155
-  +#156#152#0#153#153#153#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#130#130#130#0#166
-  +#166#166#2'kkk'#0#166#166#166#0#180#180#180#0#178#178#178#0#251#252#252#0#202
-  +#202#199#0#0#0#0#0#18#20#0#8'wr'#188#22#148#144#210'%'#149#149#150'3'#137#141
-  +'OC'#140#146'.P'#149#156'-Y'#146#152'+T'#149#155'-<'#136#140':'#25'ruD'#0'y|'
-  +'('#0'JU'#0#0#138#169#0#0#181#177#215#3#215#215#220#2#247#247#253#0#169#169
-  +#169#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#150#150#150#0#165#165#165#0'g'
-  +'gg'#1#167#167#167#3#184#184#184#3#185#185#185#3#255#255#255#2#200#200#199#1
-  +#0#0#0#0#0#0#0#0#135#131#215#0#156#152#213#0#151#150#146#0#149#155'E'#0#148
-  +#154'+'#0#157#164'*'#0#153#160')'#0#155#162'.'#0#150#156'5'#0'sv@'#0'x{+'#3
-  +#128#136#6#2'tx-'#0#193#191#211#0#218#218#221#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#1#145#144#147#2#131#130#134#2#149#156'5'
-  +#3#154#161'"'#3#160#168'"'#3#156#164' '#3#153#160'#'#2#0#0#0#1#0#0#0#0#138
-  +#143'&'#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#240
-  +#0#0#255#192#0#0#127#128#0#0#127#128#0#0'?'#128#0#0'?'#128#0#0#31#0#0#0#3#0#0
-  +#0#1#0#0#0#0#0#0'`'#7#0#7#224#7#0#7#240#7#0#7#224#7#0#7#224#7#128#3#192#15
-  +#128#0#0#15#128#0#0#31#128#0#0#31#192#0#0#31#192#0#0'?'#192#0#0#127#248#0#3
-  +#255#255#254'?'#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255'('#0#0#0#24#0#0#0'0'#0#0#0#1#0' '#0#0#0#0#0'`'#9#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  ,#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#167#167#167
-  +#0#165#165#165#0#0#0#0#1#177#177#177#2#179#179#179#2#179#179#179#2#181#181
-  +#181#2#0#0#0#1#193#193#193#0#183#183#183#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0'ccc'#0
-  +#155#155#155#0#145#145#145#2#129#129#129#0#160#160#160#0#161#161#161#0#161
-  +#161#161#0#163#163#163#0#145#145#145#0#164#164#173#0#198#196#225#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0#0#0#0#133#133#133#0'{{{'#0'LLL'#0#184#184
-  +#184#0#0#0#0#0#0#0#0#0#0#0#0#0#142#142#142#0#163#163#163#0#130#130#130#0'{{{'
-  +'$'#153#153#153'H'#154#154#154'E'#153#153#153'E'#155#155#155'H'#138#139#138
-  +'&'#162#162#170#0#216#213#255#0#0#0#0#0#3','#0#0#0#0#0#0#0#0#0#0'V`'#0#0#0#0
-  +#0#0#0#0#0#0#218#218#216#0#238#238#233#0#172#172#172#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#154#154#154#2#162#162#162#11#150#150#150'~'#156#156#156#246#171#171#171
-  +#255#171#171#171#255#170#170#170#255#173#173#173#255#163#163#164#247#151#151
-  +#144#215#135#137'h'#216'tx;'#212'qu.'#211'uy<'#211#130#133']'#211#151#152#142
-  +#211#169#169#179#209#170#169#174#211#147#147#146'1'#152#152#151#0#168#168#168
-  +#1#156#157#145#0#0#0#0#0#0#0#0#0#198#198#198#0#157#157#157#171#164#164#164
-  +#255#162#162#162#254#172#172#172#252#170#170#170#253#170#170#168#253#175#175
-  +#180#252#151#152#131#255'sz'#8#255#130#138#0#255#137#146#0#255#139#148#0#255
-  +#137#146#0#255#133#141#0#255#131#138#15#255#139#143'A'#255#163#163#150#255
-  +#166#165#175#159#196#196#200#0#187#187#187#2#145#146'x'#0#147#147#147#0#0#0#0
-  +#0#204#204#204#13#163#163#163#226#163#163#163#252#162#162#162#252#174#174#174
-  +#255#176#176#176#254#175#175#174#254#177#176#185#255#158#160'z'#254#143#153#0
-  +#253#147#157#0#253#144#153#0#253#143#153#0#253#144#154#0#253#147#156#0#253
-  +#145#155#0#253#139#150#0#251#135#144#0#253#146#150'Z'#243#172#169#213#20#167
-  +#166#201#2#150#152#131#4#147#147#147#1#0#0#0#0'wwwC'#164#164#164#239#163#163
-  +#163#254#167#167#167#253#180#180#180#254#179#179#179#255#179#179#178#255#183
-  +#182#187#255#163#164#146#255#134#140'%'#255#138#144'('#255#146#150'Y'#255#156
-  +#158'v'#255#147#150'e'#255#132#136'<'#255#140#144'F'#255#142#146'O'#254#143
-  +#148'M'#252#135#138'P'#255'tti'#139'yzh'#0#129#131'g'#0#129#129#129#0#161#161
-  +#161#1#145#145#145#127#168#168#168#248#169#169#169#255#171#171#171#254#181
-  +#181#181#255#178#178#178#255#178#178#178#255#182#182#181#254#167#167#169#255
-  +#147#146#155#254#141#140#149#252#135#134#146#252#144#144#153#252#144#144#154
-  +#251#136#135#147#253#141#140#152#255#139#139#150#254#130#129#142#254#149#149
-  +#155#254#157#157#156#255#154#154#156#177#154#154#159#164#129#129#129#24#135
-  +#135#133#0#151#151#151#179#172#172#172#252#170#170#170#255#170#170#170#254
-  +#180#180#180#255#178#178#179#255#178#178#178#255#181#181#182#255#169#169#169
-  +#255#149#149#148#255#139#139#138#255#149#149#147#255#148#148#147#255#144#144
-  +#142#255'zzx'#255'vvt'#255'ttr'#255#138#138#137#255#175#174#186#255#175#175
-  +#187#254#175#174#184#255#175#175#181#255#162#161#169#213#161#161#169','#158
-  +#158#158#214#174#174#174#253#171#171#171#255#170#170#170#255#181#181#179#255
-  +#179#179#177#255#179#179#178#255#181#181#180#254#175#175#175#255#178#178#178
-  +#253#149#149#149#215'zzz'#204#131#131#131#193#151#151#151#177#135#135#135#232
-  +#145#145#144#255#150#150#153#253#164#165#154#255#146#151'L'#254#148#153'I'
-  +#254#142#146'J'#250#127#129'_'#135#127#129'Z'#131'wzMN'#161#161#161#223#171
-  +#171#171#254#164#164#164#255#169#168#171#254#180#179#187#255#177#177#185#255
-  +#178#177#184#255#177#177#179#251#173#173#172#255#168#168#168#163#190#190#190
-  +#0#170#170#170#0#192#192#192#0#187#187#187#0#170#170#170']'#194#194#194#255
-  +#198#198#200#252#185#185#181#254#139#148#4#254#141#151#0#253#140#150#0#254
-  +#136#144#0'.'#136#145#0#0#139#148#0#0#163#163#163#214#164#164#163#253#163#162
-  +#169#255#158#160'}'#255#144#150')'#255#145#151'*'#255#141#148'$'#255#160#162
-  +'|'#251#184#183#190#254#170#170#167'n'#183#183#183#0#190#190#190#3#192#192
-  +#192#3#164#164#164#4#157#157#157'.'#188#188#188#254#191#192#191#254#188#188
-  +#191#253#144#152#29#255#143#152#2#252#144#153#2#254#148#157#5'Q'#146#156#0#3
-  +#147#157#0#4#159#159#159#176#165#165#163#252#173#172#181#255#167#170#129#254
-  +#141#150#0#255#143#152#0#255#139#149#0#255#158#162'V'#251#198#197#210#255#177
-  +#177#172#177#207#207#207#0#204#204#204#0#194#194#194#0#188#188#188#0#167#167
-  +#167'n'#189#189#189#255#195#194#197#251#182#182#176#254#140#149#8#254#143#152
-  +#0#253#145#154#4#255#160#167#27'>'#154#162#20#0#152#161#14#2#154#154#154'r'
-  +#164#164#164#247#169#169#171#255#174#174#166#254#148#156#16#255#142#151#2#255
-  +#143#153#1#255#142#149#21#254#179#178#182#252#182#182#184#255#157#157#155'|'
-  +#159#159#159#13#168#168#168#5#170#170#170'O'#176#176#175#240#179#180#176#253
-  +#191#190#206#253#161#164'j'#255#139#149#0#253#142#151#0#254#154#163#24#241
-  +#153#160'E'#19#178#184'N'#0#171#179'0'#0#148#148#148'+'#164#164#164#234#168
-  +#168#166#255#176#175#185#253#163#168'Q'#255#141#151#0#255#144#153#2#255#141
-  ,#150#0#255#145#150'C'#254#179#178#191#254#183#183#189#255#175#175#174#232#174
-  +#175#173#222#176#176#175#255#181#181#182#255#183#182#197#254#163#164#141#255
-  +#139#148#8#255#143#152#0#251#145#154#2#255#161#168'&'#166#137#147#20#0#152
-  +#160#27#2#171#178'/'#0#211#211#211#0#163#163#163#205#166#166#165#254#174#174
-  +#178#252#174#175#162#254#154#162#25#255#140#150#0#255#145#153#3#254#140#150#0
-  +#255#143#149'1'#254#166#167#148#253#178#178#184#255#180#180#190#255#179#179
-  +#189#254#173#173#172#254#155#158'i'#255#139#147#6#254#144#153#0#254#141#151#0
-  +#252#147#156#8#246#164#173'.%'#162#169')'#0#163#171'%'#1#166#174'%'#0#174#174
-  +#174#0#161#161#161#158#165#165#165#254#173#173#171#248#173#172#180#252#172
-  +#174#137#253#150#159#11#253#140#150#0#254#144#153#2#254#143#152#0#254#139#148
-  +#0#254#143#150' '#253#146#152'7'#252#145#150'0'#254#140#148#16#254#140#149#0
-  +#254#144#153#0#252#140#150#0#249#147#156#7#255#159#162'c'#186#177#187'K'#0
-  +#171#177'\'#1#164#172')'#0#0#0#0#0#174#174#174#0#167#167#167'P'#168#168#168
-  +#255#176#176#176#255#174#175#173#255#175#175#183#255#172#174#143#255#154#162
-  +'$'#255#142#152#0#254#142#151#0#253#144#153#0#252#143#152#0#251#142#151#0#251
-  +#142#152#0#251#143#153#0#254#144#153#0#255#143#153#1#255#148#156#28#255#170
-  +#172#135#239#173#171#196'O'#178#176#196#1#188#189#188#1#163#170'('#0#0#0#0#0
-  +#187#187#187#1#163#163#163#1#135#135#135'T'#167#167#167#163#174#174#174#189
-  +#170#170#168#213#174#174#182#233#173#173#169#248#166#170'f'#255#153#160'('
-  +#255#147#155#13#255#145#154#7#255#146#155#6#255#146#154#7#255#146#155#8#255
-  +#143#151#13#233#142#149'('#175#147#150'rb'#151#152#145#24#165#165#171#0#148
-  +#149#138#0#188#188#186#0#0#0#0#0#0#0#0#0#190#190#190#0#188#188#188#0#169#169
-  +#169#0#186#186#186#0#212#212#213#0#1#1#7#0'y|H'#12#127#127#138#28#170#166#231
-  +'.'#161#161#164'A'#152#156'NS'#144#151'&b'#150#157'"k'#146#153'#_'#141#147'$'
-  +'9'#130#135'('#15'E>'#146#0#182#181#191#0#187#173#255#0#170#169#183#0#160#159
-  +#165#0#189#190#184#0#0#0#0#0#0#0#0#0#204#204#204#0#0#0#0#0'uuu'#2#180#180#180
-  +#2#207#207#207#1'BBC'#0#142#143#137#0#144#143#152#0#172#169#213#0#166#167#155
-  +#0#155#160'B'#0#153#161#30#0#154#162#28#0#151#159#30#0#149#156'#'#0#130#134
-  +')'#0'][^'#1'}'#132#22#2'dp'#0#0#195#195#199#0#183#183#185#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#1#180#180#179
-  +#1#188#187#196#2#174#176#138#2#161#169''''#2#152#160#27#3#155#163#23#3#155
-  +#164#24#3#159#167#27#2#0#0#0#1#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#192#0'?'#0#128#0#31#0#128#0#31#0#128#0
-  +#15#0#0#0#3#0#0#0#1#0#0#0#1#0#0'<'#7#0#0'>'#3#0#0'<'#7#0#0#28#7#0#128#0#7#0
-  +#128#0#15#0#128#0#15#0#128#0#31#0#192#0'?'#0#255#195#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0'('#0#0#0#16#0#0#0' '#0#0#0#1#0' '#0#0#0#0#0'@'#4#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#180#180#180#0#215#215#215#0#0#0#0#6#176#176
-  +#176#9#177#177#177#9#170#170#170#7#205#205#206#4#181#182#176#4#148#149#127#3
-  +#167#168#165#3#169#169#170#4#0#0#0#3#0#0#0#0#159#159#159#0#152#152#152#0#0#0
-  +#0#0#161#161#161#0#172#172#172#1#150#150#150#0#167#167#168#0#167#167#166#0
-  +#169#169#174#0#191#189#228#0#156#154#181#0'hf~'#0#141#138#191#0#182#178#255#0
-  +#158#158#158#0#138#138#138#0#138#138#136#0#147#147#147#0#0#0#0#0#164#164#164
-  +#0#168#168#168#0#147#147#147'F'#164#164#164'd'#164#164#163'd'#161#161#164'T'
-  +#180#179#203')'#159#157#176'''jh~%'#135#132#176'%'#171#167#233'&'#159#159#172
-  +'"~~w'#0#130#132'h'#0#144#147'^'#0#0#0#0#0#152#152#152#17#160#160#160#165#162
-  +#162#162#255#171#171#171#255#172#172#174#255#163#163#157#255#135#139'B'#254
-  +#131#138#29#253#128#134#13#252#132#138' '#252#143#147'N'#250#163#164#152#248
-  +#160#159#166'8'#167#165#186#3#173#173#182#4#0#0#0#0#152#152#152'\'#162#162
-  +#162#254#166#166#166#252#176#176#175#250#178#177#183#250#164#165#145#251#136
-  +#146#0#254#145#154#0#254#147#155#16#255#142#151#0#255#138#148#0#250#141#148
-  +#26#255#143#146'f'#160#153#159'I'#0#149#155'G'#0#251#251#251#2#157#157#157
-  +#161#166#166#166#250#172#172#172#254#180#180#180#255#181#181#182#254#172#172
-  +#170#255#141#143'q'#253#140#141'}'#252#149#149#149#254#137#138'}'#253#139#140
-  +'}'#254#137#138'z'#253#144#145#133#247#146#149'r{'#145#147'oA'#154#154#157#0
-  +#163#163#163#212#172#172#172#253#173#173#173#255#180#180#180#254#180#180#180
-  +#255#176#176#176#255#153#153#159#255#137#137#140#255#141#141#141#255#129#129
-  +#132#255'zz~'#255#141#141#142#254#167#168#161#254#165#165#165#255#158#158#173
-  +#228#163#162#157'Z'#167#167#167#235#169#169#168#253#170#170#172#255#178#178
-  +#180#255#177#177#179#252#176#176#175#254#167#167#166#159#155#155#153'A'#169
-  +#169#169'1'#161#161#158's'#181#181#184#254#178#179#162#251#141#149#13#254#139
-  +#148#7#232'{'#129#29'%'#148#155#19#29#163#163#158#225#166#165#174#254#158#161
-  ,'o'#255#143#151#29#254#144#151'%'#250#180#180#176#255#177#177#180'U'#193#193
-  +#199#0#180#180#179#0#170#170#167')'#194#194#195#255#186#187#179#253#143#151#7
-  +#254#144#153#0#244#158#167#12#24#154#163#18#0#160#160#153#173#168#168#175#252
-  +#168#170#128#255#142#152#0#255#139#149#0#253#170#172#133#254#183#183#196#207
-  +#187#187#186'('#184#184#181#27#172#172#166#176#188#187#200#254#169#171#127
-  +#250#139#149#0#254#151#159#17#221#137#144'7'#7#133#142#19#2#153#153#152'a'
-  +#165#165#165#244#174#174#176#254#154#161'*'#254#141#150#0#255#142#150#23#254
-  +#167#169#146#255#175#174#184#247#179#179#189#241#181#180#191#255#167#168#146
-  +#254#142#150#18#248#143#152#0#253#154#162#26#133#138#147#10#0#149#158#14#8
-  +#163#163#163#18#166#166#164#230#173#173#178#255#172#173#148#253#149#158#18
-  +#252#140#150#0#251#140#149#0#248#151#157'>'#253#155#159'U'#254#149#155'8'#248
-  +#140#149#0#253#142#152#0#255#152#159'-'#253#164#168#128#23#176#176#138#0#165
-  +#169'i'#2#176#176#176#0#153#153#153'~'#170#170#168#232#174#174#180#247#171
-  +#173#151#255#156#162';'#255#146#155#12#255#142#152#0#255#142#151#0#255#143
-  +#152#0#255#143#152#8#251#150#156'3'#204#166#168#137'k'#180#186#144#0#183#184
-  +#142#1#150#167#0#0#255#255#255#1#0#0#0#0'ssw'#14#145#146#134'"'#155#154#173
-  +'7'#175#174#189'M'#159#163'Pb'#145#152'"s'#149#156#29'y'#149#156#30'^'#140
-  +#146'&+'#143#148';'#0#153#161'('#0'jW='#0#186#187't'#0#143#160#0#0#208#208
-  +#208#0'III'#2#0#0#0#0#161#161#154#0#170#168#200#0#179#177#200#0#159#163'T'#0
-  +#149#157#17#0#150#158#14#0#148#156#18#0#140#146')'#0#143#147'G'#0#162#168'<'
-  +#3'}ci'#0#165#173'A'#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#2#187#187#185#4#183#183
-  +#188#6#181#181#169#8#162#168'E'#9#149#157#9#10#148#157#10#10#145#154#1#9#144
-  +#151#25#5#151#159#29#0#157#165#28#0#155#160'N'#0#0#0#0#0#0#0#0#0#255#255#0#0
-  +#255#255#0#0#227#255#0#0#128#15#0#0#0#7#0#0#0#3#0#0#0#0#0#0#1#131#0#0#1#195#0
-  +#0#1#131#0#0#0#3#0#0#128#7#0#0#128#7#0#0#252'?'#0#0#255#255#0#0#255#255#0#0
-]);
-
diff --git a/dcm2nii_prePARRECDTI/dcm2niigui.manifest b/dcm2nii_prePARRECDTI/dcm2niigui.manifest
deleted file mode 100755
index 07fb624..0000000
--- a/dcm2nii_prePARRECDTI/dcm2niigui.manifest
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
- <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="CompanyName.ProductName.YourApp" type="win32"/>
- <description>Your application description here.</description>
- <dependency>
-  <dependentAssembly>
-   <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
-  </dependentAssembly>
- </dependency>
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
-  <security>
-   <requestedPrivileges>
-    <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
-   </requestedPrivileges>
-  </security>
- </trustInfo>
-</assembly>
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/dcm2niigui.rc b/dcm2nii_prePARRECDTI/dcm2niigui.rc
deleted file mode 100755
index 71b1938..0000000
--- a/dcm2nii_prePARRECDTI/dcm2niigui.rc
+++ /dev/null
@@ -1,7 +0,0 @@
-#define RT_MANIFEST  24
-#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1
-#define ISOLATIONAWARE_MANIFEST_RESOURCE_ID 2
-#define ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID 3
-
-CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "dcm2niigui.manifest"
-MAINICON ICON "dcm2niigui.ico"
diff --git a/dcm2nii_prePARRECDTI/dcm2niigui.res b/dcm2nii_prePARRECDTI/dcm2niigui.res
deleted file mode 100755
index c682074..0000000
Binary files a/dcm2nii_prePARRECDTI/dcm2niigui.res and /dev/null differ
diff --git a/dcm2nii_prePARRECDTI/dicom.pas b/dcm2nii_prePARRECDTI/dicom.pas
deleted file mode 100755
index 7536b92..0000000
--- a/dcm2nii_prePARRECDTI/dicom.pas
+++ /dev/null
@@ -1,32 +0,0 @@
-unit dicom;
-{$H+}
-interface
-{$DEFINE COMPAT}
-uses
-   dialogsx,prefs,dicomtypes
-   {$IFDEF COMPAT}
-,dicomcompat{,dicomfast};
-{$ELSE}
-,dicomfast;
-{$ENDIF}
-procedure read_dicom_data(lReadJPEGtables,lVerboseRead,lAutoDECAT7,lReadECAToffsetTables,lAutodetectInterfile,lAutoDetectGenesis,lReadColorTables: boolean; var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;var lFileName: string; var lPrefs: TPrefs);
-
-implementation
-
-procedure read_dicom_data(lReadJPEGtables,lVerboseRead,lAutoDECAT7,lReadECAToffsetTables,lAutodetectInterfile,lAutoDetectGenesis,lReadColorTables: boolean; var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;var lFileName: string; var lPrefs: TPrefs);
-begin
-   lDICOMdata.Filename := lFilename;
-   lHdrOK := true;
-   lImageFormatOK:=true;
-   {$IFDEF COMPAT}
-   //if not fast_read_dicom_data(lDICOMdata,128, lFileName) then
-     read_dicom_data_compat(lReadJPEGtables,lVerboseRead,lAutoDECAT7,lReadECAToffsetTables,lAutodetectInterfile,lAutoDetectGenesis,lReadColorTables, lDICOMdata, lHdrOK, lImageFormatOK, lDynStr, lFileName,lPrefs);
-     {$ELSE}
-    lHdrOK := fast_read_dicom_data(lDICOMdata,128, lFileName);
-     {$ENDIF}
-end;
-
-end.
-
-
-
diff --git a/dcm2nii_prePARRECDTI/dicomcompat.pas b/dcm2nii_prePARRECDTI/dicomcompat.pas
deleted file mode 100755
index 3d2f941..0000000
--- a/dcm2nii_prePARRECDTI/dicomcompat.pas
+++ /dev/null
@@ -1,6432 +0,0 @@
-unit dicomcompat;
-interface
-uses
-{$Define NoTroubleshoot}
-{$IFDEF FPC}
-gzio2,
-{$ELSE}
-gziod,
-{$ENDIF}
-
-  SysUtils,Classes,define_types,filename,dicomtypes,dicomfastread,prefs,convertsimple, csaread;
-{$H+}
-var
-kUseDateTimeForID: boolean = false;
-procedure read_afni_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;var lFileName: string; var lRotation1,lRotation2,lRotation3: integer);
-procedure read_ecat_data(var lDICOMdata: DICOMdata;lVerboseRead,lReadECAToffsetTables:boolean; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;lFileName: string);
-procedure read_siemens_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;lFileName: string);
-procedure read_ge_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;lFileName: string);
-procedure read_interfile_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;var lFileName: string);
-procedure read_voxbo_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;var lFileName: string);
-procedure read_VFF_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;var lFileName: string);
-procedure read_picker_data(lVerboseRead: boolean; var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;lFileName: string);
-procedure read_tiff_data(var lDICOMdata: DICOMdata; var lReadOffsets,lHdrOK, lImageFormatOK: boolean; var lDynStr: string;lFileName: string);
-procedure read_dicom_data_compat(lReadJPEGtables,lVerboseRead,lAutoDECAT7,lReadECAToffsetTables,lAutodetectInterfile,lAutoDetectGenesis,lReadColorTables: boolean; var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;var lFileName: string; var lPrefs: TPrefs);
-
-var
-  gSizeMMWarningShown : boolean = false;
-  gECATJPEG_table_entries: integer = 0;
-  gECATJPEG_pos_table,gECATJPEG_size_table : LongIntP;
-  red_table_size : Integer = 0;
-  green_table_size : Integer = 0;
-  blue_table_size : Integer = 0;
-  red_table   : ByteP;
-  green_table : ByteP;
-  blue_table  : ByteP;
-implementation
-
-uses dialogsx;
-
-function SecSinceMidnightFloat (lStr: string): double;
-var
-  lNumStr: string;
-  sec: double;
-  i,len,dec: integer;
-begin
-  result := 0;//error
-
-  if lStr = '' then
-    exit;
-  len := length(lStr);
-  lNumStr := '';
-  for i := 1 to len do begin
-    if (lStr[i] = '.') or (lStr[i] = ',') then
-      lStr[i] := DecimalSeparator; //make native format, e.g. in Germany 10,123 whereas in USA 10.123
-    if lStr[i] in ['0'..'9',DecimalSeparator] then
-      lNumStr := lNumStr + lStr[i];
-  end;
-  if lNumStr = '' then
-    exit;
-
-  //make sure 6 characters before decimal, in case HHMMSS is written HMMSS
-  dec := length(lNumStr) + 1;
-  for i := length(lNumStr) downto 1 do
-    if lNumStr[i] = DecimalSeparator then
-      dec := i;
-  if dec > 7 then
-    exit; //HHMMSS.??? can only have 6 digits before decimal
-  while dec < 7 do begin
-    lNumStr := '0'+lNumStr;
-    inc(dec);
-  end;
-  //now in HHMMSS.????? format
-  len := length(lNumStr);
-  lStr := lNumStr[1]+lNumStr[2]; //HH
-  sec :=  60 * 60 * strtoint(lStr); //60m/h, 60s/m
-  lStr := lNumStr[3]+lNumStr[4]; //MM
-  sec := sec + ( 60 * strtoint(lStr)); //60s/m 1000ms/s
-  lStr := '';
-  for i := 5 to len do //SS.SSSS
-    lStr := lStr + lNumStr[i];
-  sec := sec + (  strtofloat(lStr)); //60s/m 1000ms/s
-  result := sec;
-end;
-
-function AddIndent(lIndent: integer): string;
-var
-  i: integer;
-begin
-  result := '';
-  if lIndent < 1 then
-    exit;
-  for i := 1 to lIndent do
-    result := result +'|';
-end;
-
-procedure read_ecat_data(var lDICOMdata: DICOMdata;lVerboseRead,lReadECAToffsetTables:boolean; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;lFileName: string);
-label
-  121,539;
-const
-     kMaxnSLices = 6000;
-     kStrSz = 40;
-var
-   lLongRA: LongIntp;
-   lECAT7sigUpcase,lECAT7sig  : array [0..6] of Char;
-  lParse,lSPos,lFPos{,lScomplement},lF,lS,lYear,lFrames,lVox,lHlfVox,lJ,lPass,lVolume,lNextDirectory,lSlice,lSliceSz,lVoxelType,lPos,lEntry,
-  lSlicePos,lLongRApos,lLongRAsz,{lSingleRApos,lSingleRAsz,}{lMatri,}lX,lY,lZ,lCacheSz,lImgSz,lSubHeadStart,lMatrixStart,lMatrixEnd,lInt,lInt2,lInt3,lINt4,n,filesz: LongInt;
-  lPlanes,lGates,lAqcType,lFileType: word;
-  lXmm,lYmm,lZmm,lCalibrationFactor, lQuantScale: real;
-  FP: file;
-  lCreateTable,lSwapBytes,lMR,lECAT6: boolean;
-function xWord(lPos: longint): word;
-var
-s: word;
-begin
-     seek(fp,lPos);
-     BlockRead(fp, s, 2, n);
-     if lSwapBytes then
-        result := swap(s)
-     else result := s; //assign address of s to inguy
-end;
-
-function swap32i(lPos: longint): Longint;
-type
-  swaptype = packed record
-    case byte of
-      0:(Word1,Word2 : word); //word is 16 bit
-      1:(Long:LongInt);
-  end;
-  swaptypep = ^swaptype;
-var
-   s : LongInt;
-  inguy:swaptypep;
-  outguy:swaptype;
-begin
-     seek(fp,lPos);
-  BlockRead(fp, s, 4, n);
-  inguy := @s; //assign address of s to inguy
-  if not lSwapBytes then begin
-      result := inguy^.long;
-      exit;
-  end;
-  outguy.Word1 := swap(inguy^.Word2);
-  outguy.Word2 := swap(inguy^.Word1);
-  swap32i:=outguy.Long;
-end;
-function StrRead (lPos, lSz: longint) : string;
-var
-   I: integer;
-   tx  : array [1..kStrSz] of Char;
-begin
-  result := '';
-  if lSz > kStrSz then exit;
-  seek(fp, lPos{-1});
-  BlockRead(fp, tx, lSz*SizeOf(Char), n);
-  for I := 1 to (lSz-1) do begin
-      if tx[I] in [' ','[',']','+','-','.','\','~','/', '0'..'9','a'..'z','A'..'Z'] then
-      {if (tx[I] <> kCR) and (tx[I] <> UNIXeoln) then}
-      result := result + tx[I];
-  end;
-end;
-function fswap4r (lPos: longint): single;
-type
-  swaptype = packed record
-    case byte of
-      0:(Word1,Word2 : word); //word is 16 bit
-      1:(float:single);
-  end;
-  swaptypep = ^swaptype;
-var
-   s:single;
-  inguy:swaptypep;
-  outguy:swaptype;
-begin
-     seek(fp,lPos);
-     if not lSwapBytes then begin
-        BlockRead(fp, result, 4, n);
-        exit;
-     end;
-  BlockRead(fp, s, 4, n);
-  inguy := @s; //assign address of s to inguy
-  outguy.Word1 := swap(inguy^.Word2);
-  outguy.Word2 := swap(inguy^.Word1);
-  fswap4r:=outguy.float;
-end;
-function fvax4r (lPos: longint): single;
-type
-  swaptype = packed record
-    case byte of
-      0:(Word1,Word2 : word); //word is 16 bit
-      1:(float:single);
-  end;
-  swaptypep = ^swaptype;
-var
-   s:single;
-   lT1,lT2 : word;
-  inguy:swaptypep;
-begin
-     seek(fp,lPos);
-     BlockRead(fp, s, 4, n);
-     inguy := @s;
-     if (inguy^.Word1 =0) and (inguy^.Word2 = 0) then begin
-        result := 0;
-        exit;
-     end;
-     lT1 := inguy^.Word1 and $80FF;
-     lT2 := ((inguy^.Word1 and $7F00) +$FF00) and $7F00;
-     inguy^.Word1 := inguy^.Word2;
-     inguy^.Word2 := (lt1+lT2);
-     fvax4r:=inguy^.float;
-end;
-begin
-  Clear_Dicom_Data(lDicomData);
-  if gECATJPEG_table_entries <> 0 then begin
-     freemem (gECATJPEG_pos_table);
-     freemem (gECATJPEG_size_table);
-     gECATJPEG_table_entries := 0;
-  end;
-  lHdrOK:= false;
-  lQuantScale:= 1;
-  lCalibrationFactor := 1;
-  lLongRASz := 0;
-  lLongRAPos := 0;
-  lImageFormatOK := false;
-  lVolume := 1;
-  if not fileexists(lFileName) then begin
-     Msg('Unable to find the image '+lFileName);
-     exit;
-  end;
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  FileSz := FileSize(fp);
-     if filesz < (2048) then begin
-        Msg('This file is to small to be a ECAT format image.');
-        goto 539;
-     end;
-  seek(fp, 0);
-  BlockRead(fp, lECAT7Sig, 6*SizeOf(Char){, n});
-  for lInt4 := 0 to (5) do begin
-      if lECAT7Sig[lInt4] in ['a'..'z','A'..'Z'] then
-         lECAT7SigUpCase[lInt4] := upcase(lECAT7Sig[lInt4])
-      else
-          lECAT7SigUpCase[lInt4] := ' ';
-  end;
-  if (lECAT7SigUpCase[0]='M') and (lECAT7SigUpCase[1]='A') and (lECAT7SigUpCase[2]='T') and (lECAT7SigUpCase[3]='R') and
-  (lECAT7SigUpCase[4]='I') and (lECAT7SigUpCase[5]='X') then
-    lECAT6 := false
-  else
-      lECAT6 := true;
-   if lEcat6 then begin
-      lSwapBytes := false;
-      lFileType := xWord(27*2);
-      if lFileType > 255 then lSwapBytes := not lSwapBytes;
-      lFileType := xWord(27*2);
-      lAqcType := xWord(175*2);
-      lPlanes := xWord(188*2);
-      lFrames := xword(189*2);
-      lGates := xWord(190*2);
-      lYear := xWord(70);
-      if (lPlanes < 1) or (lFrames < 1) or (lGates < 1) then begin
-         case MsgDlg('Warning: one of the planes/frames/gates values is less than 1 ['+inttostr(lPlanes)+'/'+inttostr(lFrames)+'/'+inttostr(lGates)+']. Is this file really ECAT 6 format? Press abort to cancel conversion. ',
-             mterror,[mbOK,mbAbort], 0) of
-             mrAbort: goto 539;
-         end; //case
-      end else if (lYear < 1940) or (lYear > 3000) then begin
-        case MsgDlg('Warning: the year value appears invalid ['+inttostr(lYear)+']. Is this file really ECAT 6 format? Press abort to cancel conversion. ',
-             mterror,[mbOK,mbAbort], 0) of
-             mrAbort: goto 539;
-        end; //case
-     end;
-     if lVerboseRead then begin
-        lDynStr :='ECAT6 data';
-        lDynStr :=lDynStr+kCR+('Patient Name:'+StrRead(190,32));
-        lDynStr :=lDynStr+kCR+('Patient ID:'+StrRead(174,16));
-        lDynStr :=lDynStr+kCR+('Study Desc:'+StrRead(318,32));
-        lDynStr := lDynStr+kCR+('Facility: '+StrRead(356,20));
-        lDynStr := lDynStr+kCR+('Planes: '+inttostr(lPlanes));
-        lDynStr := lDynStr+kCR+('Frames: '+inttostr(lFrames));
-        lDynStr := lDynStr+kCR+('Gates: '+inttostr(lGates));
-        lDynStr := lDynStr+kCR+('Date DD/MM/YY: '+ inttostr(xWord(66))+'/'+inttostr(xWord(68))+'/'+inttostr(lYear));
-     end; {show summary}
-   end else begin //NOT ECAT6
-       lSwapBytes := true;
-     lFileType := xWord(50);
-     if lFileType > 255 then lSwapBytes := not lSwapBytes;
-     lFileType := xWord(50);
-     lAqcType := xWord(328);
-     lPlanes := xWord(352);
-     lFrames := xWord(354);
-     lGates := xWord(356);
-     lCalibrationFactor := fswap4r(144);
-     if {(true) or} (lPlanes < 1) or (lFrames < 1) or (lGates < 1) then begin
-        case MsgDlg('Warning: on of the planes/frames/gates values is less than 1 ['+inttostr(lPlanes)+'/'+inttostr(lFrames)+'/'+inttostr(lGates)+']. Is this file really ECAT 7 format? Press abort to cancel conversion. ',
-             mterror,[mbOK,mbAbort], 0) of
-             mrAbort: goto 539;
-        end; //case
-     end; //error
-     if lVerboseRead then begin
-          lDynStr := 'ECAT 7 format';
-          lDynStr := lDynStr+kCR+('Serial Number:'+StrRead(52,10));
-          lDynStr := lDynStr+kCR+('Patient Name:'+StrRead(182,32));
-          lDynStr := lDynStr+kCR+('Patient ID:'+StrRead(166,16));
-          lDynStr := lDynStr+kCR+('Study Desc:'+StrRead(296,32));
-          lDynStr := lDynStr+kCR+('Facility: '+StrRead(332,20));
-          lDynStr := lDynStr+kCR+('Scanner: '+inttostr(xWord(48)));
-          lDynStr := lDynStr+kCR+('Planes: '+inttostr(lPlanes));
-          lDynStr := lDynStr+kCR+('Frames: '+inttostr(lFrames));
-          lDynStr := lDynStr+kCR+('Gates: '+inttostr(lGates));
-          lDynStr := lDynStr+kCR+'Calibration: '+floattostr(lCalibrationFactor);
-     end; {lShow Summary}
-   end; //lECAT7
-if lFiletype = 9 then lFiletype := 7;  //1364: treat projections as Volume16's 
-if not (lFileType in [1,2,3,4,7]) then begin
-   Msg('This software does not recognize the ECAT file type. Selected filetype: '+inttostr(lFileType));
-   goto 539;
-end;
-lVoxelType := 2;
-if lFileType = 3 then lVoxelType := 4;
-if lVerboseRead then begin
-  case lFileType of
-    1: lDynStr := lDynStr+kCR+('File type: Scan File');
-    2: lDynStr := lDynStr+kCR+('File type: Image File'); //x
-    3: lDynStr := lDynStr+kCR+('File type: Attn File');
-    4: lDynStr := lDynStr+kCR+('File type: Norm File');
-    7: lDynStr := lDynStr+kCR+('File type: Volume 16'); //x
-  end; //lfiletye case
-  case lAqcType of
-     1:lDynStr := lDynStr+kCR+('Acquisition type: Blank');
-     2:lDynStr := lDynStr+kCR+('Acquisition type: Transmission');
-     3:lDynStr := lDynStr+kCR+('Acquisition type: Static Emission');
-     4:lDynStr := lDynStr+kCR+('Acquisition type: Dynamic Emission');
-     5:lDynStr := lDynStr+kCR+('Acquisition type: Gated Emission');
-     6:lDynStr := lDynStr+kCR+('Acquisition type: Transmission Rect');
-     7:lDynStr := lDynStr+kCR+('Acquisition type: Emission Rect');
-     8:lDynStr := lDynStr+kCR+('Acquisition type: Whole Body Transm');
-     9:lDynStr := lDynStr+kCR+('Acquisition type: Whole Body Static');
-     else lDynStr := lDynStr+kCR+('Acquisition type: Undefined');
-  end; //case AqcType
-end; //verbose read
-if ((lECAT6) and (lFiletype =2)) or ({(not lECAT6) and} (lFileType=7)) then  //Kludge
-else begin
-     Msg('Unusual ECAT filetype. Please contact the author.');
-     goto 539;
-end;
-lHdrOK:= true;
-lImageFormatOK := true;
-lLongRASz := kMaxnSlices * sizeof(longint);
-getmem(lLongRA,lLongRAsz);
-lPos := 512;
-//lSingleRASz := kMaxnSlices * sizeof(single);
-//getmem(lSingleRA,lSingleRAsz);
-//lMatri := 0;
-lVolume := 1;
-lPass := 0;
-121:
-     lEntry := 1;
-     lInt := swap32i(lPos);
-     lInt2 := swap32i(lPos+4);
-   lNextDirectory := lInt2;
-   while true do begin
-      inc(lEntry);
-     lPos := lPos + 16;
-     lInt := swap32i(lPos);
-     lInt2 := swap32i(lPos+4);
-     lInt3 := swap32i(lPos+8);
-     lInt4 := swap32i(lPos+12);
-     lInt2 := lInt2 - 1;
-     lSubHeadStart := lINt2 *512;
-     lMatrixStart := ((lInt2) * 512)+512 {add subhead sz};
-     lMatrixEnd := lInt3 * 512;
-     if  (lInt4 = 1) and (lMatrixStart < FileSz) and (lMatrixEnd <= FileSz) then begin
-        if (lFileType= 7) {or (lFileType = 4) } or (lFileType = 2) then begin //Volume of 16-bit integers
-           if lEcat6 then begin
-               lX := xWord(lSubHeadStart+(66*2));
-               lY := xWord(lSubHeadStart+(67*2));
-               lZ := 1;//uxWord(lSubHeadStart+8);
-               lXmm := 10*fvax4r(lSubHeadStart+(92*2));// fswap4r(lSubHeadStart+(92*2));
-               lYmm := lXmm;//read32r(lSubHeadStart+(94*2));
-               lZmm := 10 * fvax4r(lSubHeadStart+(94*2));
-               lCalibrationFactor :=  fvax4r(lSubHeadStart+(194*2));
-               lQuantScale := fvax4r(lSubHeadStart+(86*2));
-               if lVerboseRead then
-                  lDynStr := lDynStr+kCR+'Plane '+inttostr(lPass+1)+' Calibration/Scale Factor: '+floattostr(lCalibrationFactor)+'/'+floattostr(lQuantScale);
-           end else begin
-           //02 or 07
-               lX := xWord(lSubHeadStart+4);
-               lY := xWord(lSubHeadStart+6);
-               lZ := xWord(lSubHeadStart+8);
-               //if lFileType <> 4 then begin
-               lXmm := 10*fswap4r(lSubHeadStart+34);
-               lYmm := 10*fswap4r(lSubHeadStart+38);
-               lZmm := 10*fswap4r(lSubHeadStart+42);
-               lQuantScale := fswap4r(lSubHeadStart+26);
-               if lVerboseRead then
-                  lDynStr := lDynStr+kCR+'Volume: '+inttostr(lPass+1)+' Scale Factor: '+floattostr(lQuantScale);
-               //end; //filetype <> 4
-           end;  //ecat7
-           if true then begin
-           //FileMode := 2; //set to read/write
-           inc(lPass);
-           lImgSz := lX * lY * lZ * lVoxelType; {2 bytes per voxel}
-           lSliceSz := lX * lY * lVoxelType;
-           if lZ < 1 then begin
-              lHdrOK := false;
-              goto 539;
-           end;
-           lSlicePos := lMatrixStart;
-           if ((lECAT6) and (lPass = 1)) or ( (not lECAT6)) then begin
-             lDICOMdata.XYZdim[1] := lX;
-             lDICOMdata.XYZdim[2] := lY;
-             lDICOMdata.XYZdim[3] := lZ;
-             lDICOMdata.XYZmm[1] := lXmm;
-             lDICOMdata.XYZmm[2] := lYmm;
-             lDICOMdata.XYZmm[3] := lZmm;
-             case lVoxelType of
-                  1: begin
-                     Msg('Error: 8-bit data not supported [yet]. Please contact the author.');
-                     lDicomData.Allocbits_per_pixel := 8;
-                     lHdrOK := false;
-                     goto 539;
-                  end;
-                  4: begin
-                     Msg('Error: 32-bit data not supported [yet]. Please contact the author.');
-                     lHdrOK := false;
-                     goto 539;
-                  end;
-                  else begin //16-bit integers
-                     lDicomData.Allocbits_per_pixel := 16;
-                  end;
-             end; {case lVoxelType}
-           end else begin //if lECAT6
-               if (lDICOMdata.XYZdim[1] <> lX) or (lDICOMdata.XYZdim[2] <> lY) or (lDICOMdata.XYZdim[3] <> lZ) then begin
-                  Msg('Error: different slices in this volume have different slice sizes. Please contact the author.');
-                  lHdrOK := false;
-                  goto 539;
-               end; //dimensions have changed
-               //lSlicePos :=((lMatri-1)*lImgSz);
-           end; //ECAT6
-           lVox := lSliceSz div 2;
-           lHlfVox := lSliceSz div 4;
-           for lSlice := 1 to lZ do begin
-              if (not lECAT6) then
-                 lSlicePos := ((lSlice-1)*lSliceSz)+lMatrixStart;
-               if lLongRAPos >= kMaxnSLices then begin
-                  lHdrOK := false;
-                  goto 539;
-               end;
-               inc(lLongRAPos);
-               lLongRA^[lLongRAPos] := lSlicePos;
-               {inc(lSingleRAPos);
-               if lCalibTableType = 1 then
-                  lSingleRA[lSingleRAPos] := lQuantScale
-               else
-                  lSingleRA[lSingleRAPos] := lCalibrationFactor *lQuantScale;}
-
-           end; //slice 1..lZ
-           if not lECAT6 then inc(lVolume);
-          end; //fileexistsex
-        end; //correct filetype
-     end; //matrix start/end within filesz
-     if (lMatrixStart > FileSz) or (lMatrixEnd >= FileSz) then goto 539;
-     if ((lEntry mod 32) = 0) then begin
-        if ((lNextDirectory-1)*512) <= lPos then goto 539; //no more directories
-        lPos := (lNextDirectory-1)*512;
-        goto 121;
-     end;  //entry 32
-     end ;  //while true
-539:
-  CloseFile(fp);
-  FileMode := 2; //set to read/write
-  lDicomData.XYZdim[3] := lLongRApos;
-  if not lECAT6 then dec(lVolume); //ECAT7 increments immediately before exiting loop - once too often
-  lDicomData.XYZdim[4] :=(lVolume);
-  if lSwapBytes then
-     lDicomData.little_endian := 0
-  else
-      lDicomData.little_endian := 1;
-  if (lLongRApos > 0) and (lHdrOK) then begin
-     lDicomData.ImageStart := lLongRA^[1];
-     lCreateTable := false;
-     if (lLongRApos > 1) then begin
-        lFPos := lDICOMdata.ImageStart;
-        for lS := 2 to lLongRApos do begin
-            lFPos := lFPos + lSliceSz;
-            if lFPos <> lLongRA^[lS] then lCreateTable := true;
-        end;
-        if (lCreateTable) and (lReadECAToffsetTables) then begin
-           gECATJPEG_table_entries := lLongRApos;
-           getmem (gECATJPEG_pos_table, gECATJPEG_table_entries*sizeof(longint));
-           getmem (gECATJPEG_size_table, gECATJPEG_table_entries*sizeof(longint));
-           for lS := 1 to gECATJPEG_table_entries do
-               gECATJPEG_pos_table^[lS] := lLongRA^[lS]
-        end else if (lCreateTable) then
-            lImageFormatOK := false;  //slices are offset within this file
-     end;
-     if (lVerboseRead) and (lHdrOK) then begin
-        lDynStr :=lDynStr+kCR+('XYZdim:'+inttostr(lX)+'/'+inttostr(lY)+'/'+inttostr(gECATJPEG_table_entries));
-        lDynStr :=lDynStr+kCR+('XYZmm: '+floattostrf(lDicomData.XYZmm[1],ffFixed,7,7)+'/'+floattostrf(lDicomData.XYZmm[2],ffFixed,7,7)
-        +'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,7,7));
-        //xlDynStr :=lDynStr+kCR+('Bits per voxel: '+inttostr(lDicomData.Storedbits_per_pixel));
-        lDynStr :=lDynStr+kCR+('Image Start: '+inttostr(lDicomData.ImageStart));
-        if lCreateTable then
-           lDynStr :=lDynStr+kCR+('Note: staggered slice offsets');
-     end
-  end;
-  //xlDicomData.Storedbits_per_pixel:= lDicomData.Allocbits_per_pixel;
-  if lLongRASz > 0 then
-     freemem(lLongRA);
-  (*if (lSingleRApos > 0) and (lHdrOK) and (lCalibTableType <> 0) then begin
-           gECAT_scalefactor_entries := lSingleRApos;
-           getmem (gECAT_scalefactor_table, gECAT_scalefactor_entries*sizeof(single));
-           for lS := 1 to gECAT_scalefactor_entries do
-               gECAT_scalefactor_table[lS] := lSingleRA[lS];
-  end;
-  if lSingleRASz > 0 then
-     freemem(lSingleRA);*)
-end;
-
-(*procedure write_slc (lFileName: string; var pDICOMdata: DICOMdata;var lSz: integer; lDICOM3: boolean);
-const kMaxRA = 41;
-     lXra: array [1..kMaxRA] of byte = (7,8,9,21,22,26,27,
-     35,36,44,45,
-     50,62,66,78,
-     81,95,
-     97,103,104,105,106,111,
-     113,123,127,
-     129,139,142,
-     146,147,148,149,155,156,157,
-     166,167,168,169,170);
-var
-   fp: file;
-   lX,lClr,lPos,lRApos: integer;
-   lP: bytep;
-procedure WriteString(lStr: string; lCR: boolean);
-var
-     n,lStrLen      : Integer;
-begin
-     lStrLen := length(lStr);
-     for n := 1 to lstrlen do begin
-            lPos := lPos + 1;
-            lP[lPos] := ord(lStr[n]);
-     end;
-     if lCR then begin
-        lPos := lPos + 1;
-        lP[lPos] := ord(kCR);
-     end;
-end;
-
-begin
-  lSz := 0;
-  getmem(lP,2048);
-  lPos := 0;
-  WriteString('11111',true);
-  WriteString(inttostr(pDicomData.XYZdim[1])+' '+inttostr(pDicomData.XYZdim[2])+' '+inttostr(pDicomData.XYZdim[3])+' 8',true);
-  WriteString(floattostrf(pDicomData.XYZmm[1],ffFixed,7,7)+' '+floattostrf(pDicomData.XYZmm[2],ffFixed,7,7)+' '+floattostrf(pDicomData.XYZmm[3],ffFixed,7,7),true);
-  WriteString('1 1 0 0',true); //mmunits,MR,original,nocompress
-  WriteString('16 12 X',false); //icon is 8x8 grid, so 64 bytes for red,green blue
-  for lClr := 1 to 3 do begin
-    lRApos := 1;
-    for lX := 1 to 192 do begin
-      inc(lPos);
-      if (lRApos <= kMaxRA) and (lX = lXra[lRApos]) then begin
-         inc(lRApos);
-         lP[lPos] := 200;
-      end else
-          lP[lPos] := 0;
-    end; {icongrid 1..192}
-  end; {RGB}
-  if lFileName <> '' then begin
-     AssignFile(fp, lFileName);
-     Rewrite(fp, 1);
-     blockwrite(fp,lP^,lPos);
-     close(fp);
-  end;
-  freemem(lP);
-  lSz := lPos;
-end;*)
-procedure read_interfile_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;var lFileName: string);
-label 333;
-const UNIXeoln = chr(10);
-var lTmpStr,
-lInStr,lUpCaseStr: string;
-lHdrEnd,lFloat,lUnsigned: boolean;
-lPos,lLen,FileSz,linPos: integer;
-fp: file;
-lCharRA: bytep;
-function readInterFloat:real;
-var lStr: string;
-begin
-  lStr := '';
-  While (lPos <= lLen) and (lInStr[lPos] <> ';') do begin
-        if lInStr[lPos] in ['+','-','e','E','.','0'..'9'] then
-           lStr := lStr+(linStr[lPos]);
-        inc(lPos);
-  end;
-    try
-       result := strtofloat(lStr);
-    except
-          on EConvertError do begin
-             Msg('Unable to convert the string '+lStr+' to a number');
-             result := 1;
-             exit;
-          end;
-    end; {except}
-  end;
-function readInterStr:string;
-var lStr: string;
-begin
-  lStr := '';
-  While (lPos <= lLen) and (lInStr[lPos] = ' ') do begin
-        inc(lPos);
-  end;
-  While (lPos <= lLen) and (lInStr[lPos] <> ';') do begin
-		if lInStr[lPos] <> ' ' then //1.39 build 6
-			lStr := lStr+upcase(linStr[lPos]); //zebra upcase
-        inc(lPos);
-  end;
-  result := lStr;
-end; //interstr func
-begin
-  lHdrOK := false;
-  lFloat := false;
-  lUnsigned := false;
-  lImageFormatOK := true;
-  Clear_Dicom_Data(lDicomData);
-  lDynStr := '';
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  FileSz := FileSize(fp);
-  lHdrEnd := false;
-  //lDicomData.ImageStart := FileSz;
-  GetMem( lCharRA, FileSz+1 );
-  BlockRead(fp, lCharRA^, FileSz, linpos);
-  if lInPos <> FileSz then Msg('Disk error: Unable to read full input file.');
-  linPos := 1;
-  CloseFile(fp);
-  FileMode := 2; //set to read/write
-repeat
-  linstr := '';
-  while (linPos < FileSz) and (lCharRA^[linPos] <> ord(kCR)) and (lCharRA^[linPos] <> ord(UNIXeoln)) do begin
-      lInStr := lInstr + chr(lCharRA^[linPos]);
-      inc(linPos);
-  end;
-  inc(lInPos);  //read EOLN
-  lLen := length(lInStr);
-  lPos := 1;
-  lUpcaseStr := '';
-  While (lPos <= lLen) and (lInStr[lPos] <> ';') and (lInStr[lPos] <> '=') and (lUpCaseStr <>'INTERFILE') do begin
-        if lInStr[lPos] in ['[',']','(',')','/','+','-',{' ',} '0'..'9','a'..'z','A'..'Z'] then
-           lUpCaseStr := lUpCaseStr+upcase(linStr[lPos]);
-        inc(lPos);
-  end;
-  inc(lPos); {read equal sign in := statement}
-  if lUpCaseStr ='INTERFILE' then begin
-     lHdrOK := true;
-     lDicomData.little_endian := 0;
-     end;
-  if lUpCaseStr ='DATASTARTINGBLOCK'then lDicomData.ImageStart := 2048 * round(readInterFloat);
-  if lUpCaseStr ='DATAOFFSETINBYTES'then lDicomData.ImageStart := round(readInterFloat);
-  if (lUpCaseStr ='MATRIXSIZE[1]') or (lUpCaseStr ='MATRIXSIZE[X]') then lDicomData.XYZdim[1] :=  round(readInterFloat);
-  if (lUpCaseStr ='MATRIXSIZE[2]')or (lUpCaseStr ='MATRIXSIZE[Y]')then lDicomData.XYZdim[2] :=  round(readInterFloat);
-  if (lUpCaseStr ='MATRIXSIZE[3]')or (lUpCaseStr ='MATRIXSIZE[Z]') or (lUpCaseStr ='NUMBEROFSLICES') or (lUpCaseStr ='TOTALNUMBEROFIMAGES') then begin
-     lDicomData.XYZdim[3] :=  round(readInterFloat);
-  end;
-  if lUpCaseStr ='IMAGEDATABYTEORDER' then begin
-     if readInterStr = 'LITTLEENDIAN' then lDicomData.little_endian := 1;
-  end;
-  if lUpCaseStr ='NUMBERFORMAT' then begin
-      lTmpStr := readInterStr;
-      if (lTmpStr = 'ASCII') or (lTmpStr='BIT') then begin
-         lHdrOK := false;
-         Msg('This software can not convert '+lTmpStr+' data type.');
-         goto 333;
-      end;
-      if lTmpStr = 'UNSIGNEDINTEGER' then lUnsigned := true;
-      if (lTmpStr='FLOAT') or (lTmpStr='SHORTFLOAT') or (lTmpStr='LONGFLOAT') then begin //1395
-         lFloat := true;
-	  end;
-  end;
-  if lUpCaseStr ='NAMEOFDATAFILE' then lFileName := ExtractFilePath(lFileName)+readInterStr;
-  if lUpCaseStr ='NUMBEROFBYTESPERPIXEL' then
-     lDicomData.Allocbits_per_pixel :=  round(readInterFloat)*8;
-  if (lUpCaseStr ='SCALINGFACTOR(MM/PIXEL)[1]') or (lUpCaseStr ='SCALINGFACTOR(MM/PIXEL)[X]') then
-     lDicomData.XYZmm[1] :=  (readInterFloat);
-  if (lUpCaseStr ='SCALINGFACTOR(MM/PIXEL)[2]') or (lUpCaseStr ='SCALINGFACTOR(MM/PIXEL)[Y]')then lDicomData.XYZmm[2] :=  (readInterFloat);
-  if (lUpCaseStr ='SCALINGFACTOR(MM/PIXEL)[3]')or (lUpCaseStr ='SCALINGFACTOR(MM/PIXEL)[Z]')or (lUpCaseStr ='SLICETHICKNESS')then lDicomData.XYZmm[3] :=  (readInterFloat);
-  if (lUpCaseStr ='ENDOFINTERFILE') then lHdrEnd := true;
-  if not lHdrOK then goto 333;
-  if lInStr <> '' then
-     lDynStr := lDynStr + lInStr+kCr;
-  lHdrOK := true;
-until (linPos >= FileSz) or (lHdrEnd){EOF(fp)};
-//xlDicomData.Storedbits_per_pixel := lDicomData.Allocbits_per_pixel;
-lImageFormatOK := true;
-if (not lFLoat) and (lUnsigned) and ((lDicomData.Allocbits_per_pixel = 16)) then begin
-   Msg('Warning: this Interfile image uses UNSIGNED 16-bit data [values 0..65535]. Analyze specifies SIGNED 16-bit data [-32768..32767]. Some images may not transfer well. [Future versions of MRIcro should fix this].');
-   lImageFormatOK := false;
-end else if (not lFLoat) and (lDicomData.Allocbits_per_pixel > 16) then begin
-   Msg('WARNING: The image '+lFileName+' is a '+inttostr(lDicomData.Allocbits_per_pixel)+'-bit integer data type. This software may display this as SIGNED data. Bits per voxel: '+inttostr(lDicomData.Allocbits_per_pixel));
-   lImageFormatOK := false;
-end else if (lFloat) then begin //zebra change float check
-   //Msg('WARNING: The image '+lFileName+' uses floating point [real] numbers. The current software can only read integer data type Interfile images.');
-   lDicomData.FloatData := true;
-   //lImageFormatOK := false;
-end;
-333:
-FreeMem( lCharRA);
-end; //interfile
-
-
-
-//afni start
-function ParseFileName (lFilewExt:String): string;
-var
-   lLen,lInc: integer;
-   lName: String;
-begin
-	lName := '';
-     lLen := length(lFilewExt);
-	lInc := lLen+1;
-     if  lLen > 0 then
-	   repeat
-              dec(lInc);
-        until (lFileWExt[lInc] = '.') or (lInc = 1);
-     if lInc > 1 then
-        for lLen := 1 to (lInc - 1) do
-            lName := lName + lFileWExt[lLen]
-     else
-         lName := lFilewExt; //no extension
-        ParseFileName := lName;
-end;
-
-procedure read_afni_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;var lFileName: string; var lRotation1,lRotation2,lRotation3: integer);
-//label 333;
-const UNIXeoln = chr(10);
-kTab = ord(chr(9));
-kSpace = ord(' ');
-var lTmpStr,lInStr,lUpCaseStr: string;
-lHdrEnd: boolean;
-lMSBch: char;
-lOri : array [1..4] of single;
-lTmpInt,lPos,lLen,FileSz,linPos: integer;
-fp: file;
-lCharRA: bytep;
-procedure readAFNIeoln;
-begin
-  while (linPos < FileSz) and (lCharRA^[linPos] <> ord(kCR)) and (lCharRA^[linPos] <> ord(UNIXeoln)) do
-      inc(linPos);
-  inc(lInPos);  //read EOLN
-end;
-function readAFNIFloat:real;
-var lStr: string;
-lCh:char;
-begin
-  lStr := '';
-  while (linPos < FileSz) and ((lStr='') or ((lCharRA^[lInPos] <> kTab) and (lCharRA^[lInPos] <> kSpace))) do begin
-        lCh:= chr(lCharRA^[linPos]);
-        if lCh in ['+','-','e','E','.','0'..'9'] then
-           lStr := lStr+lCh;
-      inc(linPos);
-  end;
-  if lStr = '' then exit;
-    try
-       result := strtofloat(lStr);
-    except
-          on EConvertError do begin
-             Msg('Unable to convert the string '+lStr+' to a number');
-             result := 1;
-             exit;
-          end;
-    end; {except}
-  end;
-begin
-  lHdrOK := false;
-  lImageFormatOK := true;
-  Clear_Dicom_Data(lDicomData);
-  lDynStr := '';
-  lTmpStr := string(StrUpper(PChar(ExtractFileExt(lFileName))));
-  if lTmpStr <> '.HEAD' then exit;
-  for lInPos := 1 to 3 do
-      lOri[lInPos] := -6666;
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  FileSz := FileSize(fp);
-  lHdrEnd := false;
-  //lDicomData.ImageStart := FileSz;
-  GetMem( lCharRA, FileSz+1 );
-  BlockRead(fp, lCharRA^, FileSz, linpos);
-  if lInPos <> FileSz then Msg('Disk error: Unable to read full input file.');
-  linPos := 1;
-  CloseFile(fp);
-  FileMode := 2; //set to read/write
-repeat
-  linstr := '';
-  while (linPos < FileSz) and (lCharRA^[linPos] <> ord(kCR)) and (lCharRA^[linPos] <> ord(UNIXeoln)) do begin
-      lInStr := lInstr + chr(lCharRA^[linPos]);
-      inc(linPos);
-  end;
-  inc(lInPos);  //read EOLN
-  lLen := length(lInStr);
-  lPos := 1;
-  lUpcaseStr := '';
-  While (lPos <= lLen) do begin
-        if lInStr[lPos] in ['_','[',']','(',')','/','+','-','=',{' ',} '0'..'9','a'..'z','A'..'Z'] then
-           lUpCaseStr := lUpCaseStr+upcase(linStr[lPos]);
-        inc(lPos);
-  end;
-  inc(lPos); {read equal sign in := statement}
-  if lUpCaseStr ='NAME=DATASET_DIMENSIONS'then begin
-     lImageFormatOK := true;
-     lHdrOK := true;
-     lFileName := parsefilename(lFilename)+'.BRIK'; //always UPPERcase
-     readAFNIeoln;
-     lDICOMdata.XYZdim[1] := round(readAFNIFloat);
-     lDICOMdata.XYZdim[2] := round(readAFNIFloat);
-     lDICOMdata.XYZdim[3] := round(readAFNIFloat);
-     //lDicomData.ImageStart := 2048 * round(readInterFloat);
-  end;
-  if lUpCaseStr ='NAME=BRICK_FLOAT_FACS'then begin
-     readAFNIeoln;
-     lDICOMdata.IntenScale :=  readAFNIFloat; //1380 read slope of intensity
-  end;
-  if lUpCaseStr ='NAME=DATASET_RANK'then begin
-     readAFNIeoln;
-     //2nd value is number of volumes
-     readAFNIFloat;
-     lDICOMdata.XYZdim[4] := round(readAFNIFloat);
-  end;
-  if lUpCaseStr ='NAME=BRICK_TYPES'then begin
-     readAFNIeoln;
-     lTmpInt := round(readAFNIFloat);
-     case lTmpInt of
-          0:lDicomData.Allocbits_per_pixel := 8;
-          1:begin
-                 lDicomData.Allocbits_per_pixel := 16;
-                 //lDicomData.MaxIntensity := 65535; //Old AFNI were UNSIGNED, new ones are SIGNED???
-          end;
-          3:begin
-                 lDicomData.Allocbits_per_pixel := 32;
-                 lDicomData.FloatData := true;
-          end;
-          else begin
-              lHdrEnd := true;
-              Msg('Unsupported AFNI BRICK_TYPES: '+inttostr(lTmpInt));
-          end;
-
-     end; //case
-     {datatype
-     0 = byte    (unsigned char; 1 byte)
-                1 = short   (2 bytes, signed)
-                3 = float   (4 bytes, assumed to be IEEE format)
-                5 = complex (8 bytes: real+imaginary parts)}
-  end;
-  if lUpCaseStr ='NAME=BYTEORDER_STRING'then begin
-     readAFNIeoln;
-     if ((linPos+2) < FileSz) then begin
-      lMSBch := chr(lCharRA^[linPos+1]);
-      if lMSBCh = 'L' then lDicomData.Little_Endian := 1;
-      if lMSBCh = 'M' then begin
-         lDicomData.Little_Endian := 0;
-      end;
-      linPos := lInPos + 2;
-     end;
-     //littleendian
-  end;
-  if lUpCaseStr ='NAME=ORIGIN'then begin
-     readAFNIeoln;
-     lOri[1] := (abs(readAFNIFloat));
-     lOri[2] := (abs(readAFNIFloat));
-     lOri[3] := (abs(readAFNIFloat));
-     //Xori,YOri,ZOri
-  end;
-  if lUpCaseStr ='NAME=DELTA'then begin
-     readAFNIeoln;
-     lDICOMdata.XYZmm[1] := abs(readAFNIFloat);
-     lDICOMdata.XYZmm[2] := abs(readAFNIFloat);
-     lDICOMdata.XYZmm[3] := abs(readAFNIFloat);
-
-     //Xmm,Ymm,Zmm
-  end;
-  if lUpCaseStr ='NAME=ORIENT_SPECIFIC'then begin
-     readAFNIeoln;
-     lRotation1 := round(readAFNIFloat);
-     lRotation2 := round(readAFNIFloat);
-     lRotation3 := round(readAFNIFloat);
-  end; //ORIENT_SPECIFIC rotation details
-  if lInStr <> '' then
-     lDynStr := lDynStr + lInStr+kCr;
-until (linPos >= FileSz) or (lHdrEnd){EOF(fp)};
-//xlDicomData.Storedbits_per_pixel := lDicomData.Allocbits_per_pixel;
-for lInPos := 1 to 3 do begin
-    if lOri[lInPos] < -6666 then //value not set
-       lDICOMdata.XYZori[lInPos] := round((1.0+lDICOMdata.XYZdim[lInPos])/2)
-    else if lDICOMdata.XYZmm[lInPos] <> 0 then
-       lDICOMdata.XYZori[lInPos] := round(1.5+lOri[lINPos] / lDICOMdata.XYZmm[lInPos]);
-end;
-//   lDicomData.Float := true;
-FreeMem( lCharRA);
-end; //interfile
-//afni end
-//voxbo start
-procedure read_voxbo_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;var lFileName: string);
-label 333;
-const UNIXeoln = chr(10);
-     kTab = chr(9);
-var lTmpStr,lInStr,lUpCaseStr: string;
-lFileTypeKnown,lHdrEnd,lFloat: boolean;
-lStartPos,lPos,lLen,FileSz,linPos: integer;
-fp: file;
-lCharRA: bytep;
-procedure readVBfloats (var lF1,lF2,lF3: double);
-//  While (lPos <= lLen) and ((lInStr[lPos] = kTab) or (lInStr[lPos] = ' ')) do begin
-//        inc(lPos);
-var  //lDigit : boolean;
-   n,lItemIndex: integer;
-   lStr,lfStr: string;
-begin
-    lf1 := 1;
-    lf2 := 1;
-    lf3 := 1;
- n := 0;
- for lItemIndex := 1 to 3 do begin
-    inc(n);
-    While (lPos <= lLen) and ((lInStr[lPos] = kTab) or (lInStr[lPos] = ' ')) do
-        inc(lPos);
-    if lPos > lLen then
-       exit;
-    lStr := '';
-    repeat
-        lStr := lStr+upcase(linStr[lPos]);
-        inc(lPos);
-    until (lPos > lLen) or (lInStr[lPos] = kTab) or (lInStr[lPos] = ' ');
-    if lStr <> '' then begin //string to convert
-       try
-          case n of
-               1: lF1 := strtofloat(lStr);
-               2: lF2 := strtofloat(lStr);
-               3: lF3 := strtofloat(lStr);
-          end;
-       except
-          on EConvertError do begin
-             Msg('Unable to convert the string '+lfStr+' to a real number');
-             exit;
-          end;
-       end; {except}
-    end; //if string to convert
- end;
-end;
-
-procedure readVBints (var lI1,lI2,lI3: integer);
-var lF1,lF2,lF3: double;
-begin
-     readVBfloats (lF1,lF2,lF3);
-     lI1 := round(lF1);
-     lI2 := round(lF2);
-     lI3 := round(lF3);
-end;
-function readVBStr:string;
-var lStr: string;
-begin
-  lStr := '';
-  While (lPos <= lLen) and ((lInStr[lPos] = kTab) or (lInStr[lPos] = ' ')) do begin
-        inc(lPos);
-  end;
-  While (lPos <= lLen) {and (lInStr[lPos] <> ';')} do begin
-        lStr := lStr+upcase(linStr[lPos]); //zebra upcase
-        inc(lPos);
-  end;
-  result := lStr;
-end; //interstr func
-begin
-  lHdrOK := false;
-  lFloat := false;
-  lImageFormatOK := true;
-  Clear_Dicom_Data(lDicomData);
-  lDynStr := '';
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  FileSz := FileSize(fp);
-  lHdrEnd := false;
-  //lDicomData.ImageStart := FileSz;
-  GetMem( lCharRA, FileSz+1 );
-  BlockRead(fp, lCharRA^, FileSz, linpos);
-  if lInPos <> FileSz then Msg('Disk error: Unable to read full input file.');
-  linPos := 1;
-  CloseFile(fp);
-  FileMode := 2; //set to read/write
-  lFileTypeKnown := false;
-repeat
-  linstr := '';
-
-  while (linPos < FileSz) and (lCharRA^[linPos] <> ord(kCR)) and (lCharRA^[linPos] <> ord(UNIXeoln)) do begin
-      lInStr := lInstr + chr(lCharRA^[linPos]);
-      inc(linPos);
-  end;
-  inc(lInPos);  //read EOLN
-  lLen := length(lInStr);
-  lPos := 1;
-  lUpcaseStr := '';
-  While (lPos <= lLen) and (lInStr[lPos] <> ':') do begin
-        if lInStr[lPos] in ['[',']','(',')','/','+','-', '0'..'9','a'..'z','A'..'Z'] then
-           lUpCaseStr := lUpCaseStr+upcase(linStr[lPos]);
-        inc(lPos);
-  end;
-  inc(lPos); {read equal sign in := statement}
-  if (lHdrOK) and (not lFileTypeKnown) and (lUpCaseStr = 'CUB1') then
-     lFileTypeKnown := true;
-  if (lHdrOK) and (not lFileTypeKnown) then begin
-     Msg('This software can not read this kind of VoxBo image. (Type:"'+lUpCaseStr+'")');
-     lHdrEnd := true;
-     lHdrOK := false;
-  end;
-  if (not lHdrOK) and (lUpCaseStr ='VB98') then begin
-     lDicomData.little_endian := 0;//all VoxBo files are Big Endian!
-     lStartPos := linPos;
-     lFileTypeKnown := true; //test for While Loop
-     while (linPos < FileSz) and lFileTypeKnown do begin
-           if (lCharRA^[linPos-1] = $0C) and (lCharRA^[linPos] = $0A) then begin
-              lFileTypeKnown := false;
-              lDicomData.ImageStart := linPos;
-              FileSz := linPos;  //size of VoxBo header
-           end;
-           inc(linPos);
-     end;
-     if lFileTypeKnown then begin //end of file character not found: abort!
-           Msg('Unable to find the end of the VoxBo header.');
-           lHdrEnd := true
-     end else
-           lHdrOK := true;
-     linPos := lStartPos; //now that we have found the header size, we can start from the beginning of the header
-  end;
-  if not lHdrOK then lHdrEnd := true;
-  if (lUpCaseStr ='BYTEORDER') and (readVBStr = 'LSBFIRST') then
-     lDicomData.little_endian := 1;
-  if lUpCaseStr ='DATATYPE'then begin
-     lTmpStr := readVBStr;
-     if lTmpStr = 'Byte' then
-        lDicomData.Allocbits_per_pixel := 8
-     else if (lTmpStr = 'INTEGER') or (lTmpStr = 'INT16')  then
-        lDicomData.Allocbits_per_pixel := 16
-     else if (lTmpStr = 'LONG') or (lTmpStr = 'INT32')  then
-        lDicomData.Allocbits_per_pixel := 32
-     else if (lTmpStr = 'FLOAT')  then begin
-        lFloat := true;
-        lDicomData.Allocbits_per_pixel := 32;
-     end else if (lTmpStr = 'DOUBLE')  then begin
-        lFloat := true;
-        lDicomData.Allocbits_per_pixel := 64;
-     end else begin
-         Msg('Unknown VoxBo data format: '+lTmpStr);
-     end;
-  end;
-  if lUpCaseStr ='VOXDIMS(XYZ)'then readVBints(lDicomData.XYZdim[1],lDicomData.XYZdim[2],lDicomData.XYZdim[3]);
-  if (lUpCaseStr ='VOXSIZES(XYZ)') then readVBfloats(lDicomData.XYZmm[1],lDicomData.XYZmm[2],lDicomData.XYZmm[3]);
-  if (lUpCaseStr ='ORIGIN(XYZ)')then begin
-     readVBints(lDicomData.XYZori[1],lDicomData.XYZori[2],lDicomData.XYZori[3]);
-     inc(lDicomData.XYZori[1]);//1393
-     inc(lDicomData.XYZori[2]);//1393
-     inc(lDicomData.XYZori[3]);//1393
-  end;
-  if not lHdrOK then goto 333;
-  if lInStr <> '' then
-     lDynStr := lDynStr + lInStr+kCr;
-until (linPos >= FileSz) or (lHdrEnd){EOF(fp)};
-//xlDicomData.Storedbits_per_pixel := lDicomData.Allocbits_per_pixel;
-//xlDicomData.Rotate180deg := true;
-lImageFormatOK := true;
-if (lFloat) then begin //zebra change float check
-   lDicomData.FloatData := true;
-   //lImageFormatOK := false;
-end;
-333:
-FreeMem( lCharRA);
-end;
-//voxbo end
-
-procedure read_vff_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;var lFileName: string);
-label 333;
-const UNIXeoln = chr(10);
-var lInStr,lUpCaseStr: string;
-//lHdrEnd: boolean;
-lPos,lLen,FileSz,linPos: integer;
-lDummy1,lDummy2,lDummy3 : double;
-fp: file;
-lCharRA: bytep;
-procedure readVFFvals (var lFloat1,lFloat2,lFloat3: double);
-var lStr: string;
-    lDouble: DOuble;
-    lInc: integer;
-begin
- for lInc := 1 to 3 do begin
-  lStr := '';
-  While (lPos <= lLen) and (lInStr[lPos] = ' ') do begin
-        inc(lPos);
-  end;
-  While (lPos <= lLen) and (lInStr[lPos] <> ';') and (lInStr[lPos] <> ' ') do begin
-        if lInStr[lPos] in ['+','-','e','E','.','0'..'9'] then
-           lStr := lStr+(linStr[lPos]);
-        inc(lPos);
-  end;
-  if lStr <> '' then begin
-    try
-       lDouble := strtofloat(lStr);
-    except
-          on EConvertError do begin
-             Msg('Unable to convert the string '+lStr+' to a number');
-             exit;
-          end;
-    end; {except}
-    case lInc of
-         2: lFloat2 := lDouble;
-         3: lFloat3 := lDouble;
-         else lFloat1 := lDouble;
-    end;
-  end; //lStr <> ''
- end; //lInc 1..3
-end; //interstr func
-begin
-  lHdrOK := false;
-  lImageFormatOK := true;
-  Clear_Dicom_Data(lDicomData);
-  lDicomData.little_endian := 0; //big-endian
-  lDynStr := '';
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  FileSz := FileSize(fp);
-  if FileSz > 2047 then FileSz := 2047;
-  GetMem( lCharRA, FileSz+1 );
-  BlockRead(fp, lCharRA^, FileSz, linpos);
-  if lInPos <> FileSz then Msg('Disk error: Unable to read full input file.');
-  lInPos := 1;
-  while (lCharRA^[lInPos] <> 12) and (lInPos < FileSz) do begin
-      inc(lInPos);
-  end;
-  inc(lInPos);
-  if (lInPos >= FileSz) or (lInPos < 12) then goto 333; //unable to find
-  lDynStr := lDynStr + 'Sun VFF Volume File Format'+kCr;
-  lDicomData.ImageStart := lInPos;
-  FileSz := lInPos-1;
-  linPos := 1;
-  CloseFile(fp);
-  FileMode := 2; //set to read/write
-repeat
-  linstr := '';
-  while (linPos < FileSz) and (lCharRA^[linPos] <> ord(kCR)) and (lCharRA^[linPos] <> ord(UNIXeoln)) do begin
-      lInStr := lInstr + chr(lCharRA^[linPos]);
-      inc(linPos);
-  end;
-  inc(lInPos);  //read EOLN
-  lLen := length(lInStr);
-  lPos := 1;
-  lUpcaseStr := '';
-  While (lPos <= lLen) and (lInStr[lPos] <> ';') and (lInStr[lPos] <> '=') and (lUpCaseStr <>'NCAA') do begin
-        if lInStr[lPos] in ['[',']','(',')','/','+','-',{' ',} '0'..'9','a'..'z','A'..'Z'] then
-           lUpCaseStr := lUpCaseStr+upcase(linStr[lPos]);
-        inc(lPos);
-  end;
-  inc(lPos); {read equal sign in := statement}
-  if lUpCaseStr ='NCAA' then begin
-     lHdrOK := true;
-     end;
-  if lUpCaseStr ='BITS' then begin
-      lDummy1 := 8;
-      readVFFvals(lDummy1,lDummy2,lDummy3);
-      lDicomData.Allocbits_per_pixel := round(lDummy1);
-  end;
-  if lUpCaseStr ='SIZE' then begin
-     lDummy1 := 1; lDummy2 := 1; lDummy3 := 1;
-     readVFFvals(lDummy1,lDummy2,lDummy3);
-     lDicomData.XYZdim[1] := round(lDummy1);
-     lDicomData.XYZdim[2] := round(lDummy2);
-     lDicomData.XYZdim[3] := round(lDummy3);
-  end;
-  if lUpCaseStr ='ASPECT' then begin
-     lDummy1 := 1; lDummy2 := 1; lDummy3 := 1;
-     readVFFvals(lDummy1,lDummy2,lDummy3);
-     lDicomData.XYZmm[1] := (lDummy1);
-     lDicomData.XYZmm[2] := (lDummy2);
-     lDicomData.XYZmm[3] := (lDummy3);
-  end;
-  if not lHdrOK then goto 333;
-  if lInStr <> '' then
-     lDynStr := lDynStr + lInStr+kCr;
-  //lHdrOK := true;
-until (linPos >= FileSz);
-//xlDicomData.Storedbits_per_pixel := lDicomData.Allocbits_per_pixel;
-lImageFormatOK := true;
-333:
-FreeMem( lCharRA);
-end;
-//********************************************************************
-(*procedure ShellSortItems (first, last: integer; var lPositionRA, lIndexRA: LongintP; var lRepeatedValues: boolean);
-{Shell sort chuck uses this- see 'Numerical Recipes in C' for similar sorts.}
-label
-     555;
-const
-     tiny = 1.0e-5;
-     aln2i = 1.442695022;
-var
-   n,t, nn, m, lognb2, l, k, j, i: longint;
-begin
-     lRepeatedValues := false;
-     n := abs(last - first + 1);
-     lognb2 := trunc(ln(n) * aln2i + tiny);
-     m := last;
-     for nn := 1 to lognb2 do
-         begin
-              m := m div 2;
-              k := last - m;
-              for j := 1 to k do begin
-                  i := j;
-                  555: {<- LABEL}
-                  l := i + m;
-                  if  (lIndexRA^[lPositionRA^[l]] = lIndexRA^[lPositionRA^[i]]) then begin
-                      lRepeatedValues := true;
-                      exit;
-                  end;
-                  if (lIndexRA^[lPositionRA^[l]] < lIndexRA^[lPositionRA^[i]]) then begin
-                     //swap values for i and l
-                     t := lPositionRA^[i];
-                     lPositionRA^[i] := lPositionRA^[l];
-                     lPositionRA^[l] := t;
-                     i := i - m;
-                     if (i >= 1) then
-                        goto 555;
-                  end
-              end
-         end
-end; //shellsort is fast and requires less memory than quicksort *)
-
-
-(*procedure PAR2DICOMstudyDate(var lDicomData: DICOMdata);
-{input: lDicomData.StudyDate =  2002.12.29 / 19:48:58.0000
-output: StudyDate = YYYYMMDD StudyTime= hhmmss }
-var
- I: integer;
-	lStr: string;
-begin
-	if length(lDicomData.StudyDate) < 14 then exit;
-	lStr := '';
-	for I := 1 to length(lDicomData.StudyDate) do
-		if lDicomData.StudyDate[I] in ['0'..'9'] then
-			lStr := lStr+ lDicomData.StudyDate[I];
-	if length(lStr) < 14 then exit;
-	lDicomData.StudyDate := '';
-	for I := 1 to 8 do
-		lDicomData.StudyDate := lDicomData.StudyDate+lStr[I];
-	lDicomData.StudyTime := '';
-	for I := 9 to 14 do
-		lDicomData.StudyTime := lDicomData.StudyTime+lStr[I];
-	lDicomData.PatientIDInt := StudySecSince2K(lDicomData.StudyDate,lDicomData.StudyTime);
-end;
-type tRange = record
-     Min,Val,Max: double; //some vals are ints, others floats
-end;
-
-procedure read_PAR_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK:boolean;  var lDynStr: string;var lFileName: string; lReadOffsetTables: boolean; var lOffset_pos_table: LongIntp; var lOffsetTableEntries: integer; lReadVaryingScaleFactors: boolean; var lVaryingScaleFactors_table,lVaryingIntercept_table: Singlep; var lVaryingScaleFactorsTableEntries,lnum4Ddatasets: integer);
-label 333; //1384 now reads up to 8 dimensional data....
-const UNIXeoln = chr(10);
-     kMaxnSLices = 32000;
-     kXdim = 1;
-     kYdim = 2;
-     kBitsPerVoxel = 3;
-     kSliceThick = 4;
-     kSliceGap = 5;
-     kXmm = 6;
-     kYmm = 7;
-     kSlope = 8;
-     kIntercept = 9;
-     kCalibratedSlope = 10; //1393 - attempt to use calibrated values
-     kDynTime = 11;
-     kSlice = 12;
-     kEcho = 13;
-     kDyn = 14;
-     kCardiac = 15;
-     kType = 16;
-     kSequence = 17;
-     kIndex = 18;
-     lIsParVers3x: boolean = true;
-     lRepeatedValues : boolean = false;
-     lSlicesNotInSequence: boolean = false;
-     lMaxSlice : integer = 0;
-var
-   lErrorStr,lInStr,lUpCaseStr,lReportedTRStr: string;
-   lSliceSequenceRA,lSortedSliceSequence: LongintP;
-   lSliceIndexRA: array [1..kMaxnSlices] of Longint;
-   lSliceSlopeRA,lSliceInterceptRA,lCalibratedSliceSlopeRA: array [1..kMaxnSlices] of single;
-   lSliceHeaderRA: array [1..32] of double;
-   lRangeRA: array [kXdim..kIndex] of tRange;
-   lMaxIndex,lSliceSz,lSliceInfoCount,lPos,lLen,lFileSz,lHdrPos,linPos,lInc: LongInt;
-   fp: file;
-   lCharRA: bytep;
-
-procedure MinMaxTRange (var lDimension: tRange;  lNewVal: double); //nested
-begin
-     lDimension.Val := lNewVal;
-     if lSliceInfoCount < 2 then begin
-        lDimension.Min := lDimension.Val;
-        lDimension.Max := lDimension.Val;
-     end;
-     if lNewVal < lDimension.Min then lDimension.Min := lNewVal;
-     if lNewVal > lDimension.Max then lDimension.Max := lNewVal;
-end; //nested InitTRange proc
-
-function readParStr:string;//nested
-var lStr: string;
-begin
-  lStr := '';
-  While (lPos <= lLen) do begin
-        if (lStr <> '') or (linStr[lPos]<>' ') then //strip leading spaces
-           lStr := lStr+(linStr[lPos]);
-        inc(lPos);
-  end; //while lPOs < lLen
-   result := lStr;
-end; //nested func ReadParStr
-function readParFloat:double;//nested
-var lStr: string;
-begin
-  lStr := '';
-  result := 1;
-  While (lPos <= lLen) and ((lStr='')  or(lInStr[lPos] <> ' ')) do begin
-        if lInStr[lPos] in ['+','-','e','E','.','0'..'9'] then
-           lStr := lStr+(linStr[lPos]);
-        inc(lPos);
-  end;
-  if lStr = '' then exit;
-    try
-       result := strtofloat(lStr);
-    except
-          on EConvertError do begin
-             Msg('read_PAR_data: Unable to convert the string '+lStr+' to a number');
-             result := 1;
-             exit;
-          end;
-    end; {except}
-end; //nested func ReadParFloat
-begin
-  //Initialize parameters
-  lnum4Ddatasets := 1;
-  lSliceInfoCount := 0;
-  for lInc := kXdim to kIndex do //initialize all values: important as PAR3 will not explicitly report all
-      MinMaxTRange(lRangeRA[lInc],0);
-  lHdrOK := false;
-  lImageFormatOK := false;
-  lIsParVers3x := true;
-  lOffsetTableEntries := 0;
-  lVaryingScaleFactorsTableEntries := 0;
-  Clear_Dicom_Data(lDicomData);
-  lDynStr := '';
-  //Read text header to buffer (lCharRA)
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  lFileSz := FileSize(fp);
-  GetMem( lCharRA, lFileSz+1 ); //note: must free dynamic memory: goto 333 if any error
-  GetMem (lSliceSequenceRA, kMaxnSLices*sizeof(longint));  //note: must free dynamic memory: goto 333 if any error
-  BlockRead(fp, lCharRA^, lFileSz, lInpos);
-  if lInPos <> lFileSz then begin
-     Msg('read_PAR_data: Disk error, unable to read full input file.');
-     goto 333;
-  end;
-  linPos := 1;
-  CloseFile(fp);
-  FileMode := 2; //set to read/write
-  //Next: read each line of header file...
-  repeat //for each line in file....
-    linstr := '';
-    while (linPos < lFileSz) and (lCharRA^[linPos] <> ord(kCR)) and (lCharRA^[linPos] <> ord(UNIXeoln)) do begin
-      lInStr := lInstr + chr(lCharRA^[linPos]);
-      inc(linPos);
-    end;
-    inc(lInPos);  //read EOLN
-    lLen := length(lInStr);
-    lPos := 1;
-    lUpcaseStr := '';
-    if lLen < 1 then
-       //ignore blank lines
-    else if (lInStr[1] = '*') and (not lHdrOK) then  //# -> comment
-         //ignore comment lines prior to start of header
-    else if (lInStr[1] = '#') and (lHdrOK) then  //# -> comment
-         //ignore comment lines
-    else if (lInStr[1] = '.') or (not lHdrOK) then  begin  //  GENERAL_INFORMATION section (line starts with '.')
-      //Note we also read in lines that do not have '.' if we have HdrOK=false, this allows us to detect the DATADESCRIPTIONFILE signature
-      While (lPos <= lLen) and (lInStr[lPos] <> ':') and ((not lHdrOK) or (lInStr[lPos] <> '#')) do begin
-        if lInStr[lPos] in ['[',']','(',')','/','+','-',{' ',} '0'..'9','a'..'z','A'..'Z'] then
-           lUpCaseStr := lUpCaseStr+upcase(linStr[lPos]);
-        inc(lPos);
-      end; //while reading line
-      inc(lPos); {read equal sign in := statement}
-               lDynStr := lDynStr + lInStr+kCR;
-      if (not lHdrOK) and (lUpcaseStr = ('DATADESCRIPTIONFILE')) then begin //1389 PAR file
-            lHdrOK := true;
-            lDicomData.little_endian := 1;
-      end;
-
-
-
-      if (lUpCaseStr ='REPETITIONTIME[MSEC]') then
-         lDicomData.TR :=  round(readParFloat);
-      if (lUpCaseStr ='MAXNUMBEROFSLICES/LOCATIONS') then
-         lDicomData.XYZdim[3] :=  round(readParFloat);
-      if (lUpCaseStr ='SLICETHICKNESS[MM]') then
-         MinMaxTRange(lRangeRA[kSliceThick],readParFloat);
-      if (lUpCaseStr ='SLICEGAP[MM]') then
-         MinMaxTRange(lRangeRA[kSliceGap],readParFloat);
-      if lUpCaseStr = 'RECONRESOLUTION(XY)' then begin
-         MinMaxTRange(lRangeRA[kXdim],readParFloat);
-         MinMaxTRange(lRangeRA[kYdim],readParFloat);
-	  end;
-      if lUpCaseStr = 'RECONSTRUCTIONNR' then
-         lDicomData.AcquNum :=  round(readParFloat);
-      if lUpCaseStr = 'ACQUISITIONNR' then
-         lDicomData.SeriesNum :=  round(readParFloat);
-      if lUpCaseStr = 'MAXNUMBEROFDYNAMICS' then begin
-         lDicomData.XYZdim[4] :=  round(readParFloat);
-      end;
-	  if lUpCaseStr = 'EXAMINATIONDATE/TIME' then begin
-		 lDicomData.StudyDate := readParStr;
-		 PAR2DICOMstudyDate(lDicomData);
-	  end;
-      //if lUpCaseStr = 'PROTOCOLNAME' then
-      //   lDicomData.modality := readParStr;
-      if lUpCaseStr = 'PATIENTNAME' then
-         lDicomData.PatientName := readParStr;
-      if lUpCaseStr ='IMAGEPIXELSIZE[8OR16BITS]' then begin
-         MinMaxTRange(lRangeRA[kBitsPerVoxel],readParFloat);
-      end;
-      if not lHdrOK then  begin
-         Msg('read_PAR_data: Error reading header');
-         goto 333;
-      end;
-    end else begin  //SliceInfo: IMAGE_INFORMATION (line does NOT start with '.' or '#')
-         inc(lSliceInfoCount);
-         if (lSliceInfoCount < 2) and (lRangeRA[kBitsPerVoxel].val < 1) then //PARvers3 has imagedepth in general header, only in image header for later versions
-            lIsParVers3x := false;
-         for lHdrPos := 1 to 26 do
-             lSliceHeaderRA[lHdrPos] := readparfloat;
-         //The next few values are in the same location for both PAR3 and PAR4
-         MinMaxTRange(lRangeRA[kSlice], round(lSliceHeaderRA[1]));
-         MinMaxTRange(lRangeRA[kEcho], round(lSliceHeaderRA[2]));
-         MinMaxTRange(lRangeRA[kDyn], round(lSliceHeaderRA[3]));
-         MinMaxTRange(lRangeRA[kCardiac], round(lSliceHeaderRA[4]));
-         MinMaxTRange(lRangeRA[kType], round(lSliceHeaderRA[5]));
-         MinMaxTRange(lRangeRA[kSequence], round(lSliceHeaderRA[6]));
-         MinMaxTRange(lRangeRA[kIndex], round(lSliceHeaderRA[7]));
-         if lIsParVers3x then begin //Read PAR3 data
-            MinMaxTRange(lRangeRA[kIntercept], lSliceHeaderRA[8]);; //8=intercept in PAR3
-            MinMaxTRange(lRangeRA[kSlope],lSliceHeaderRA[9]); //9=slope in PAR3
-            MinMaxTRange(lRangeRA[kCalibratedSlope],lSliceHeaderRA[10]);  //10=lcalibrated slope in PAR3 1393 - attempt to use calibrated values
-            MinMaxTRange(lRangeRA[kXmm],lSliceHeaderRA[23]); //23 PIXEL SPACING X  in PAR3
-            MinMaxTRange(lRangeRA[kYmm],lSliceHeaderRA[24]); //24 PIXEL SPACING Y IN PAR3
-            MinMaxTRange(lRangeRA[kDynTime],(lSliceHeaderRA[26]));  //26= dyn_scan_begin_time in PAR3
-         end else begin  //not PAR: assume PAR4
-            for lHdrPos := 27 to 32 do
-                lSliceHeaderRA[lHdrPos] := readparfloat;
-            MinMaxTRange(lRangeRA[kBitsPerVoxel],lSliceHeaderRA[8]);//8 BITS in PAR4
-            MinMaxTRange(lRangeRA[kXdim], lSliceHeaderRA[10]); //10 XDim in PAR4
-            MinMaxTRange(lRangeRA[kYdim], lSliceHeaderRA[11]); //11 YDim in PAR4
-            MinMaxTRange(lRangeRA[kIntercept],lSliceHeaderRA[12]); //12=intercept in PAR4
-            MinMaxTRange(lRangeRA[kSlope],lSliceHeaderRA[13]); //13=lslope in PAR4
-            MinMaxTRange(lRangeRA[kCalibratedSlope],lSliceHeaderRA[14]);  //14=lcalibrated slope in PAR4 1393 - attempt to use calibrated values
-            MinMaxTRange(lRangeRA[kSliceThick],lSliceHeaderRA[23]);//23 SLICE THICK in PAR4
-            MinMaxTRange(lRangeRA[kSliceGap], lSliceHeaderRA[24]); //24 SLICE GAP in PAR4
-            MinMaxTRange(lRangeRA[kXmm],lSliceHeaderRA[29]); //29 PIXEL SPACING X  in PAR4
-            MinMaxTRange(lRangeRA[kYmm],lSliceHeaderRA[30]); //30 PIXEL SPACING Y in PAR4
-            MinMaxTRange(lRangeRA[kDynTime],(lSliceHeaderRA[32]));//32= dyn_scan_begin_time in PAR4
-         end; //PAR4
-         if lSliceInfoCount < kMaxnSlices then begin
-            lSliceSequenceRA^[lSliceInfoCount] := ( (round(lRangeRA[kSequence].val)+round(lRangeRA[kType].val)+round(lRangeRA[kCardiac].val+lRangeRA[kEcho].val)) shl 24)+(round(lRangeRA[kDyn].val) shl 10)+round(lRangeRA[kSlice].val);
-            lSliceSlopeRA [lSliceInfoCount] := lRangeRA[kSlope].Val;
-            lCalibratedSliceSlopeRA [lSliceInfoCount] := lRangeRA[kCalibratedSlope].Val;
-            lSliceInterceptRA [lSliceInfoCount] := lRangeRA[kIntercept].val;
-            lSliceIndexRA[lSliceInfoCount]:= round(lRangeRA[kIndex].val);
-         end;
-    end; //SliceInfo Line
-  until (linPos >= lFileSz);//until done reading entire file...
-  //describe generic DICOM parameters
-  lDicomData.XYZdim[1] := round(lRangeRA[kXdim].Val);
-  lDicomData.XYZdim[2] := round(lRangeRA[kYdim].Val);
-  lDicomData.XYZdim[3] := 1+round(lRangeRA[kSlice].Max-lRangeRA[kSlice].Min);
-  if (lSliceInfoCount mod lDicomData.XYZdim[3]) <> 0 then
-     Msg('read_PAR_data: Total number of slices not divisible by number of slices per volume. Reconstruction error?');
-  if lDicomData.XYZdim[3] > 0 then
-     lDicomData.XYZdim[4] := lSliceInfoCount div lDicomData.XYZdim[3] //nVolumes = nSlices/nSlicePerVol
-  else
-      lDicomData.XYZdim[4] := 1;
-
-  lDicomData.XYZmm[1] := lRangeRA[kXmm].Val;
-  lDicomData.XYZmm[2] := lRangeRA[kYmm].Val;
-  lDicomData.XYZmm[3] := lRangeRA[kSliceThick].Val+lRangeRA[kSliceGap].Val;
-  lDicomData.Allocbits_per_pixel :=  round(lRangeRA[kBitsPerVoxel].Val);
-  lDicomData.IntenScale := lRangeRA[kSlope].Val;
-  lDicomData.IntenIntercept := lRangeRA[kIntercept].Val;
-if gPARprecise then begin
-  if (lDicomData.IntenIntercept <> 0) or (lRangeRA[kCalibratedSlope].val = 0) then
-     Msg('Warning: Unable to save calibrated Philips image intensity (non-zero scaling intercept). Turn off Etc/Options/CalibratedScaling to hide warning.');
-  if (lRangeRA[kSlope].min  = lRangeRA[kSlope].max)
-     and (lRangeRA[kIntercept].min = lRangeRA[kIntercept].max)
-     and (lRangeRA[kCalibratedSlope].min = lRangeRA[kCalibratedSlope].max)
-     and (lDicomData.IntenIntercept = 0) and (lRangeRA[kCalibratedSlope].val <> 0) then
-      lDicomData.IntenScale := 1 / lRangeRA[kCalibratedSlope].val;
-end; //if PARprecise
-  //Next: report number of Dynamic scans, this allows people to parse DynScans from Type/Cardiac/Echo/Sequence 4D files
-  lnum4Ddatasets := (round(lRangeRA[kDyn].Max - lRangeRA[kDyn].Min)+1)*lDicomData.XYZdim[3]; //slices in each dynamic session
-  if ((lSliceInfoCount mod lnum4Ddatasets) = 0) and ((lSliceInfoCount div lnum4Ddatasets) > 1) then
-    lnum4Ddatasets := (lSliceInfoCount div lnum4Ddatasets) //infer multiple Type/Cardiac/Echo/Sequence
-  else
-      lnum4Ddatasets := 1;
-  //next: Determine actual interscan interval
-  if (lDicomData.XYZdim[4] > 1) and ((lRangeRA[kDynTime].max-lRangeRA[kDynTime].min)> 0)  {1384} then begin
-        lReportedTRStr := 'Reported TR: '+floattostrf(lDicomData.TR,ffFixed,8,2)+kCR;
-        lDicomData.TR := (lRangeRA[kDynTime].max-lRangeRA[kDynTime].min)  /(lDicomData.XYZdim[4] - 1)*1000; //infer TR in ms
-  end else
-         lReportedTRStr :='';
-  //next: report header details
-  lDynStr := 'Philips PAR/REC Format' //'PAR/REC Format'
-              +kCR+ 'Patient name:'+lDicomData.PatientName
-              +kCR+ 'XYZ dim: ' +inttostr(lDicomData.XYZdim[1])+'/'+inttostr(lDicomData.XYZdim[2])+'/'+inttostr(lDicomData.XYZdim[3])
-              +kCR+'Volumes: ' +inttostr(lDicomData.XYZdim[4])
-              +kCR+'XYZ mm: '+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)+'/'
-              +floattostrf(lDicomData.XYZmm[2],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2)
-              +kCR+'TR: '+floattostrf(lDicomData.TR,ffFixed,8,2)
-              +kCR+lReportedTRStr+kCR+lDynStr;
-  //if we get here, the header is fine, next steps will see if image format is readable...
-  lHdrOK := true;
-  if lSliceInfoCount < 1 then
-     goto 333;
-  //next: see if slices are in sequence
-  lSlicesNotInSequence := false;
-  if lSliceInfoCount > 1 then begin
-     lMaxSlice :=  lSliceSequenceRA^[1];
-     lMaxIndex := lSliceIndexRA[1];
-     lInc := 1;
-     repeat
-        inc(lInc);
-        if lSliceSequenceRA^[lInc] < lMaxSlice then //not in sequence if image has lower slice order than previous image
-           lSlicesNotInSequence := true
-        else
-           lMaxSlice := lSliceSequenceRA^[lInc];
-        if lSliceIndexRA[lInc] < lMaxIndex then //not in sequence if image has lower slice index than previous image
-           lSlicesNotInSequence := true
-        else
-           lMaxIndex := lSliceIndexRA[lInc];
-     until (lInc = lSliceInfoCount) or (lSlicesNotInSequence);
-  end; //at least 2 slices
-  //Next: report any errors
-  lErrorStr := '';
-  if (lSlicesNotInSequence) and (not lReadOffsetTables) then
-     lErrorStr := lErrorStr + ' Slices not saved sequentially [using MRIcro''s ''Philips PAR to Analyze'' command may solve this]'+kCR;
-  if lSliceInfoCount > kMaxnSlices then
-     lErrorStr := lErrorStr + ' Too many slices: >'+inttostr(kMaxnSlices)+kCR;
-  if (not lReadVaryingScaleFactors) and (  (lRangeRA[kSlope].min <> lRangeRA[kSlope].max)
-    or (lRangeRA[kIntercept].min <> lRangeRA[kIntercept].max)) then
-     lErrorStr := lErrorStr + ' Differing intensity slope/intercept [using MRIcro''s ''Philips PAR to Analyze'' command may solve this]'+kCR;
-  if (lRangeRA[kBitsPerVoxel].min <> lRangeRA[kBitsPerVoxel].max) then  //5D file space+time+cardiac
-     lErrorStr := lErrorStr + ' Differing bits per voxel'+kCR;
-  //if (lRangeRA^[kCardiac].min <> lRangeRA^[kCardiac].max) then  //5D file space+time+cardiac
-  //   lErrorStr := lErrorStr + 'Multiple cardiac timepoints'+kCR;
-  //if (lRangeRA^[kEcho].min <> lRangeRA^[kEcho].max) then  //5D file space+time+echo
-  //   lErrorStr := lErrorStr + 'Multiple echo timepoints'+kCR;
-  if (lRangeRA[kSliceThick].min <> lRangeRA[kSliceThick].max) or (lRangeRA[kSliceGap].min <> lRangeRA[kSliceGap].max)
-    or (lRangeRA[kXdim].min <> lRangeRA[kXdim].max) or (lRangeRA[kYDim].min <> lRangeRA[kYDim].max)
-    or (lRangeRA[kXmm].min <> lRangeRA[kXmm].max) or (lRangeRA[kYmm].min <> lRangeRA[kYmm].max) then
-     lErrorStr := lErrorStr + ' Multiple/varying slice dimensions'+kCR;
-  //if any errors were encountered, report them....
-  if lErrorStr <> '' then begin
-      Msg('read_PAR_data: This software can not convert this Philips data:'+kCR+lErrorStr);
-      goto 333;
-  end;
-  //Next sort image indexes here...
-  if (lSliceInfoCount > 1) and(lSlicesNotInSequence) and ( lReadOffsetTables) then begin //sort image order...
-     //ShellSort (first, last: integer; var lPositionRA, lIndexLoRA,lIndexHiRA: LongintP; var lRepeatedValues: boolean)
-     GetMem (lOffset_pos_table, lSliceInfoCount*sizeof(longint));
-     for lInc := 1 to  lSliceInfoCount do
-         lOffset_pos_table^[lInc] := lInc;
-     ShellSortItems (1, lSliceInfoCount,lOffset_pos_table,lSliceSequenceRA, lRepeatedValues);
-     if lRepeatedValues then begin
-         Msg('read_PAR_data: fatal error, slices do not appear to have unique indexes [multiple copies of same slice]');
-         FreeMem (lOffset_pos_table);
-         goto 333;
-     end;
-     lOffsetTableEntries := lSliceInfoCount;
-  end; //sort image order...
-  //Next, generate list of scale slope
-  if  (lSliceInfoCount > 1) and (lReadVaryingScaleFactors) and ( (lRangeRA[kSlope].min <> lRangeRA[kSlope].max)
-    or (lRangeRA[kIntercept].min <> lRangeRA[kIntercept].max))  then begin {create offset LUT}
-      lVaryingScaleFactorsTableEntries := lSliceInfoCount;
-      getmem (lVaryingScaleFactors_table, lVaryingScaleFactorsTableEntries*sizeof(single));
-      getmem (lVaryingIntercept_table, lVaryingScaleFactorsTableEntries*sizeof(single));
-      if  lOffsetTableEntries = lSliceInfoCount then begin //need to sort slices
-
-          for lInc := 1 to lSliceInfoCount do begin
-              lVaryingScaleFactors_table^[lInc] := lSliceSlopeRA[lOffset_pos_table^[lInc]];
-              lVaryingIntercept_table^[lInc] := lSliceInterceptRA[lOffset_pos_table^[lInc]];
-if gPARprecise then begin
-  if (lVaryingIntercept_table^[lInc] <> 0) or (lCalibratedSliceSlopeRA[lOffset_pos_table^[lInc]]=0) then
-     Msg('Warning: Unable to save calibrated Philips image intensity (non-zero scaling intercept). Turn off Etc/Options/CalibratedScaling to hide warning.')
-  else begin
-      lVaryingScaleFactors_table^[lInc] := 1 / lCalibratedSliceSlopeRA[lOffset_pos_table^[lInc]];
-  end;
-end; //if PARprecise
-
-          end;
-      end else begin //if sorted, else unsorted
-
-          for lInc := 1 to lSliceInfoCount do begin
-              lVaryingScaleFactors_table^[lInc] := lSliceSlopeRA[lInc];
-              lVaryingIntercept_table^[lInc] := lSliceInterceptRA[lInc];
-if gPARprecise then begin
-  if (lVaryingIntercept_table^[lInc] <> 0) or (lCalibratedSliceSlopeRA[lInc]=0) then
-     Msg('Warning: Unable to save calibrated Philips image intensity (non-zero scaling intercept). Turn off Etc/Options/CalibratedScaling to hide warning.')
-  else
-      lVaryingScaleFactors_table^[lInc] := 1 / lCalibratedSliceSlopeRA[lInc];
-end; //if PARprecise
-
-          end;
-      end; //slices sorted
-  end;//read scale factors
-  //Next: now adjust Offsets to point to byte offset instead of slice number
-  lSliceSz := lDicomData.XYZdim[1]*lDicomData.XYZdim[2]*(lDicomData.Allocbits_per_pixel div 8);
-  if lOffsetTableEntries = lSliceInfoCount then
-          for lInc := 1 to lSliceInfoCount do
-              lOffset_pos_table^[lInc] := lSliceSz * (lSliceIndexRA[lOffset_pos_table^[lInc]]);
-  //report if 5D/6D/7D file is being saved as 4D
-  if (lRangeRA[kCardiac].min <> lRangeRA[kCardiac].max)
-    or (lRangeRA[kEcho].min <> lRangeRA[kEcho].max)   //5D file space+time+echo
-    or (lRangeRA[kType].min <> lRangeRA[kType].max)   //5D file space+time+echo
-    or (lRangeRA[kSequence].min <> lRangeRA[kSequence].max) then  //5D file space+time+echo
-      Msg('Warning: note that this image has more than 4 dimensions (multiple Cardiac/Echo/Type/Sequence)');
-  //if we get here, the Image Format is OK
-  lImageFormatOK := true;
-  lFileName := changefileextX(lFilename,'.rec'); //for Linux: case sensitive extension search '.rec' <> '.REC'
- 333: //abort clause: skips lHdrOK and lImageFormatOK
- //next: free dynamically allocated memory
- FreeMem( lCharRA);
- FreeMem (lSliceSequenceRA);
-end;   *)
-
-procedure read_ge_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;lFileName: string);
-label
-  539;
-var
-  lGap,lSliceThick,lTempFloat: single;
-  lTemp16,lI: word;
-  lSeriesOffset,lTemp32,lExamHdr,lImgHdr,lDATFormatOffset,lHdrOffset,lCompress,linitialoffset,n,filesz: LongInt;
-  tx     : array [0..36] of Char;
-  FP: file;
-  lGEodd,lGEFlag,{lSpecial,}lMR: boolean;
-function GEflag: boolean;
-begin
-     if (tx[0] = 'I') AND (tx[1]= 'M') AND (tx[2] = 'G')AND (tx[3]= 'F') then
-        result := true
-     else
-         result := false;
-end;
-function swap16i(lPos: longint): word;
-var
-   w : Word;
-begin
-  seek(fp,lPos-2);
-  BlockRead(fp, W, 2);
-  result := swap(W);
-end;
-
-function swap32i(lPos: longint): Longint;
-type
-  swaptype = packed record
-    case byte of
-      0:(Word1,Word2 : word); //word is 16 bit
-      1:(Long:LongInt);
-  end;
-  swaptypep = ^swaptype;
-var
-   s : LongInt;
-  inguy:swaptypep;
-  outguy:swaptype;
-begin
-     seek(fp,lPos);
-  BlockRead(fp, s, 4, n);
-  inguy := @s; //assign address of s to inguy
-  outguy.Word1 := swap(inguy^.Word2);
-  outguy.Word2 := swap(inguy^.Word1);
-  swap32i:=outguy.Long;
-end;
-function fswap4r (lPos: longint): single;
-type
-  swaptype = packed record
-    case byte of
-      0:(Word1,Word2 : word); //word is 16 bit
-      1:(float:single);
-  end;
-  swaptypep = ^swaptype;
-var
-   s:single;
-  inguy:swaptypep;
-  outguy:swaptype;
-begin
-     seek(fp,lPos);
-  BlockRead(fp, s, 4, n);
-  inguy := @s; //assign address of s to inguy
-  outguy.Word1 := swap(inguy^.Word2);
-  outguy.Word2 := swap(inguy^.Word1);
-  fswap4r:=outguy.float;
-end;
-begin
-  lImageFormatOK := true;
-  lSeriesOffset := 0;
-  lSLiceThick := 0;
-  lGap := 0;
-  lHdrOK := false;
-  lHdrOffset := 0;
-  if not fileexists(lFileName) then begin
-     lImageFormatOK := false;
-     exit;
-  end;
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  FIleSz := FileSize(fp);
-  lDATFormatOffset := 0;
-  Clear_Dicom_Data(lDicomData);
-     if filesz < (3240) then begin
-        Msg('This file is too small to be a Genesis DAT format image.');
-        goto 539;
-     end;
-     lDynStr:= '';
-     //lGEFlag := false;
-     lInitialOffset := 3228;//3240;
-     seek(fp, lInitialOffset);
-     BlockRead(fp, tx, 4*SizeOf(Char), n);
-     lGEflag := GEFlag;
-     if not lGEFlag then begin
-        lInitialOffset := 3240;
-        seek(fp, lInitialOffset);
-        BlockRead(fp, tx, 4*SizeOf(Char), n);
-        lGEflag := GEFlag;
-     end;
-     lGEodd := lGEFlag;
-     if not lGEFlag then begin
-        lInitialOffset := 0;
-        seek(fp, lInitialOffset);
-        BlockRead(fp, tx, 4*SizeOf(Char), n);
-        if not GEflag then begin {DAT format}
-           lDynStr := lDynStr+'GE Genesis Signa DAT tape format'+kCR;
-           seek(fp,114);
-           BlockRead(fp, tx, 4*SizeOf(Char), n);
-           lDynStr := lDynStr + 'Suite: ';
-           for lI := 0 to 3 do
-            lDynStr := lDynStr + tx[lI];
-           lDynStr := lDynStr + kCR;
-
-           seek(fp,114+97);
-           BlockRead(fp, tx, 25*SizeOf(Char), n);
-           lDynStr := lDynStr + 'Patient Name: ';
-           for lI := 0 to 24 do
-            lDynStr := lDynStr + tx[lI];
-           lDynStr := lDynStr + kCR;
-           seek(fp,114+84);
-           BlockRead(fp, tx, 13*SizeOf(Char), n);
-           lDynStr := lDynStr + 'Patient ID: ';
-           for lI := 0 to 12 do
-               lDynStr := lDynStr + tx[lI];
-           lDynStr := lDynStr + kCR;
-           seek(fp, 114+305);
-           BlockRead(fp, tx, 3*SizeOf(Char), n);
-           if (tx[0]='M') and (tx[1] = 'R') then
-              lMR := true
-           else if (tx[0] = 'C') and(tx[1] = 'T') then
-             lMR := false
-           else begin
-                Msg('Is this a Genesis DAT image? The modality is '+tx[0]+tx[1]+tx[3]
-              +'. Expected ''MR'' or ''CT''.');
-              goto 539;
-           end;
-           if lMR then
-              lInitialOffset := 3180
-           else
-               lInitialOffset := 3178;
-           seek(fp, lInitialOffset);
-           BlockRead(fp, tx, 4*SizeOf(Char), n);
-           if (tx[0] <> 'I') OR (tx[1] <> 'M') OR (tx[2] <> 'G') OR (tx[3] <> 'F') then begin
-              Msg('This image does not have the required label ''IMGF''. This is not a Genesis DAT image.');
-              goto 539;
-           end else
-        lDicomData.ImageNum := swap16i(2158+12);
-        lDicomData.XYZmm[3] := fswap4r (2158+26);// slice thickness mm
-        lDicomData.XYZmm[1] := fswap4r (2158+50);// pixel size- X
-        lDicomData.XYZmm[2] := fswap4r (2158+54);//pixel size - Y
-        lSliceThick := lDicomData.XYZmm[3];
-        lGap :=  fswap4r (lHdrOffset+118);//1410 gap thickness mm
-        if lGap > 0 then
-                  lDicomData.XYZmm[3] := lDicomData.XYZmm[3] + lGap;
-        lDATFormatOffset := 4;
-        if lMR then begin
-          lTemp32 := swap32i(2158+194);
-           lDynStr := lDynStr +'TR[usec]: '+inttostr(lTemp32) + kCR;
-           lTemp32 := swap32i(2158+198);
-           lDynStr := lDynStr +'TInvert[usec]: '+inttostr(lTemp32) + kCR;
-           lTemp32 := swap32i(2158+202);
-           lDynStr := lDynStr +'TE[usec]: '+inttostr(lTemp32) + kCR;
-           lTemp16 := swap16i(2158+210);
-           lDynStr := lDynStr +'Number of echoes: '+inttostr(lTemp16) + kCR;
-           lTemp16 := swap16i(2158+212);
-           lDynStr := lDynStr +'Echo: '+inttostr(lTemp16) + kCR;
-
-           lTempFloat  := fswap4r (2158+50); //not sure why I changed this to 50... 218 in Clunie's Description
-           lDynStr := lDynStr +'NEX: '+floattostr(lTempFloat) + kCR;
-
-           seek(fp,2158+308);
-           BlockRead(fp, tx, 33*SizeOf(Char), n);
-           lDynStr := lDynStr + 'Sequence: ';
-           for lI := 0 to 32 do
-               lDynStr := lDynStr + tx[lI];
-           lDynStr := lDynStr + kCR;
-
-
-           seek(fp,2158+362);
-           BlockRead(fp, tx, 17*SizeOf(Char), n);
-           lDynStr := lDynStr + 'Coil: ';
-           for lI := 0 to 16 do
-               lDynStr := lDynStr + tx[lI];
-           lDynStr := lDynStr + kCR;
-
-
-        end;
-
-     end; {DAT format}
-end;
-     lDicomData.ImageStart := lDATFormatOffset+linitialoffset + swap32i(linitialoffset+4);//byte displacement to image data
-     lDicomData.XYZdim[1] := swap32i(linitialoffset+8); //width
-     lDicomData.XYZdim[2] := swap32i(linitialoffset+12);//height
-     lDicomData.Allocbits_per_pixel := swap32i(linitialoffset+16);//bits
-     //xlDicomData.Storedbits_per_pixel:= lDicomData.Allocbits_per_pixel;
-     lCompress := swap32i(linitialoffset+20); //compression
-     lExamHdr :=  swap32i(linitialoffset+136);
-     lImgHdr :=  swap32i(linitialoffset+152);
-     if (lImgHdr = 0) and (lDicomData.ImageStart = 8432) then begin
-        lDicomData.ImageNum := swap16i(2310+12);
-		lDicomData.XYZmm[3] := fswap4r (2310+26);// slice thickness mm
-		lDicomData.XYZmm[1] := fswap4r (2310+50);// pixel size- X
-		lDicomData.XYZmm[2] := fswap4r (2310+54);//pixel size - Y
-		lSliceThick := lDicomData.XYZmm[3];
-		lGap :=  fswap4r (lHdrOffset+118);//1410 gap thickness mm
-		if lGap > 0 then
-		   lDicomData.XYZmm[3] := lDicomData.XYZmm[3] + lGap;
-
-	 end else if {(lSpecial = false) and} (lDATFormatOffset = 0) then begin
-		lDynStr := lDynStr+'GE Genesis Signa format'+kCR;
-		if (not lGEodd) and (lExamHdr <> 0) then begin
-		   lHdrOffset := swap32i(linitialoffset+132);//x132- int ptr to exam heade
-//Patient ID
-		   seek(fp,lHdrOffset+84);
-		   BlockRead(fp, tx, 13*SizeOf(Char), n);
-		   lDynStr := lDynStr + 'Patient ID: ';
-		   for lI := 0 to 12 do
-			lDynStr := lDynStr + tx[lI];
-		   lDynStr := lDynStr + kCR;
-//Patient Name
-		   seek(fp,lHdrOffset+97);
-		   BlockRead(fp, tx, 25*SizeOf(Char), n);
-		   lDynStr := lDynStr + 'Patient Name: ';
-		   for lI := 0 to 24 do
-			lDynStr := lDynStr + tx[lI];
-		   lDynStr := lDynStr + kCR;
-//Patient Age
-		lI := swap16i(lHdrOffset+122);
-		lDynStr := lDynStr+'Patient Age: '+inttostr(lI)+kCR;
-//Modality: MR or CT
-		   seek(fp,lHdrOffset+305);
-		   BlockRead(fp, tx, 3*SizeOf(Char), n);
-		   lDynStr := lDynStr + 'Type: ';
-		   for lI := 0 to 1 do
-			lDynStr := lDynStr + tx[lI];
-		   lDynStr := lDynStr + kCR;
-//Read series header
-		   lSeriesOffset := swap32i(linitialoffset+144);//read size of series header: only read if >0
-		   if lSeriesOffset > 12 then begin
-			  lSeriesOffset := swap32i(linitialoffset+140);//read size of series header: only read if >0
-			  lI := swap16i(lSeriesOffset+10);
-			  //lDynStr := lDynStr+'Series number: '+inttostr(lI)+kCR;
-			  lDicomData.SeriesNum := lI;
-		   end;
-
-
-//image data
-        lHdrOffset := swap32i(linitialoffset+148);//x148- int ptr to image heade
-        end;
-        if lGEodd then lHdrOffset := 2158+28;
-        if ((lHdrOffset +58) < FileSz) and (lImgHdr <> 0) then begin
-           lDicomData.AcquNum := swap16i(lHdrOffset+12); //note SERIES not IMAGE number, despite what Clunies FAQ says
-           lDicomData.ImageNum := swap16i(lHdrOffset+14); //this is IMAGEnum
-
-           //lDynStr := lDynStr +'Image number: '+inttostr(lDicomData.ImageNum)+ kCR;
-           lDicomData.XYZmm[3] := fswap4r (lHdrOffset{linitialoffset+lHdrOffset}+26);// slice thickness mm
-           lDicomData.XYZmm[1] := fswap4r (lHdrOffset{linitialoffset+lHdrOffset}+50);// pixel size- X
-           lDicomData.XYZmm[2] := fswap4r (lHdrOffset{linitialoffset+lHdrOffset}+54);//pixel size - Y
-           lSliceThick := lDicomData.XYZmm[3];
-           lGap :=  fswap4r (lHdrOffset+118);//1410 gap thickness mm
-           if lGap > 0 then
-                  lDicomData.XYZmm[3] := lDicomData.XYZmm[3] + lGap;
-        end;
-     end;
-     if (lCompress = 3) or (lCompress = 4) then begin
-        lImageFormatOK := false;//xlDicomData.GenesisCpt := true;
-        lDynStr := lDynStr+'Compressed data'+kCR;
-     end else
-         ;//xlDicomData.GenesisCpt := false;
-     if (lCompress = 2) or (lCompress = 4) then begin
-        lImageFormatOK := false;//xlDicomData.GenesisPackHdr := swap32i(linitialoffset+64);
-        lDynStr := lDynStr+'Packed data'+kCR;
-     end else
-         //xlDicomData.GenesisPackHdr := 0;
-	 lDynStr := lDynStr+'Series Number: '+inttostr(lDicomData.SeriesNum)
-	 +kCR+'Acquisition Number: '+inttostr(lDicomData.AcquNum)
-	 +kCR+'Image Number: '+inttostr(lDicomData.ImageNum)
-	 +kCR+'Slice Thickness/Gap: '+floattostrf(lSliceThick,ffFixed,8,2)+'/'+floattostrf(lGap,ffFixed,8,2)
-	 +kCR+'XYZ dim: ' +inttostr(lDicomData.XYZdim[1])+'/'+inttostr(lDicomData.XYZdim[2])+'/'+inttostr(lDicomData.XYZdim[3])
-	 +kCR+'XYZ mm: '+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)+'/'
-       +floattostrf(lDicomData.XYZmm[2],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2);
-  lHdrOK := true;
-  539:
-       CloseFile(fp);
-  FileMode := 2; //set to read/write
-end;//read_ge
-
-
-//start siemens
-procedure read_siemens_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;lFileName: string);
-label
-  567;
-var
-  lI: word;
- lYear,lMonth,lDay,n,filesz,lFullSz,lMatrixSz,lIHour,lIMin,lISec{,lAHour,lAMin,lASec}: LongInt;
- lFlipAngle,lGap,lSliceThick: double;
-  tx     : array [0..26] of Char;
-  lMagField,lTE,lTR: double;
-  lInstitution,lName, lID,lMinStr,lSecStr{,lAMinStr,lASecStr}: String;
-  FP: file;
-function swap32i(lPos: longint): Longint;
-type
-  swaptype = packed record
-    case byte of
-      0:(Word1,Word2 : word); //word is 16 bit
-      1:(Long:LongInt);
-  end;
-  swaptypep = ^swaptype;
-var
-   s : LongInt;
-  inguy:swaptypep;
-  outguy:swaptype;
-begin
-     seek(fp,lPos);
-  BlockRead(fp, s, 4, n);
-  inguy := @s; //assign address of s to inguy
-  outguy.Word1 := swap(inguy^.Word2);
-  outguy.Word2 := swap(inguy^.Word1);
-  swap32i:=outguy.Long;
-  //swap32i:=inguy.Long;
-end;
-function fswap8r (lPos: longint): double;
-type
-  swaptype = packed record
-    case byte of
-      0:(Word1,Word2,Word3,Word4 : word); //word is 16 bit
-      1:(float:double);
-  end;
-  swaptypep = ^swaptype;
-var
-   s:double;
-  inguy:swaptypep;
-  outguy:swaptype;
-begin
-     seek(fp,lPos);
-  BlockRead(fp, s, 8, n);
-  inguy := @s; //assign address of s to inguy
-  outguy.Word1 := swap(inguy^.Word4);
-  outguy.Word2 := swap(inguy^.Word3);
-  outguy.Word3 := swap(inguy^.Word2);
-  outguy.Word4 := swap(inguy^.Word1);
-  fswap8r:=outguy.float;
-end;
-begin
-  lImageFormatOK := true;
-  lHdrOK := false;
-  if not fileexists(lFileName) then begin
-     lImageFormatOK := false;
-     exit;
-  end;
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  FIleSz := FileSize(fp);
-  Clear_Dicom_Data(lDicomData);
-     if filesz < (6144) then begin
-        Msg('This file is to small to be a Siemens Magnetom Vision image.');
-        goto 567;
-     end;
-     seek(fp, 96);
-     BlockRead(fp, tx, 7*SizeOf(Char), n);
-  if (tx[0] <> 'S') OR (tx[1] <> 'I') OR (tx[2] <> 'E') OR (tx[3] <> 'M') then begin {manufacturer is not SIEMENS}
-        Msg('Is this a Siemens Magnetom Vision image [Manufacturer tag should be ''SIEMENS''].');
-        goto 567;
-  end; {manufacturer not siemens}
-  seek(fp, 105);
-  BlockRead(fp, Tx, 25*SizeOf(Char), n);
-  lINstitution := '';
-  for lI := 0 to 24 do begin
-      if tx[lI] in ['/','\','a'..'z','A'..'Z',' ','+','-','.',',','0'..'9'] then lINstitution := lINstitution + tx[lI];
-  end;  seek(fp, 768);
-  BlockRead(fp, Tx, 25*SizeOf(Char), n);
-  lName := '';
-  for lI := 0 to 24 do begin
-      if tx[lI] in ['/','\','a'..'z','A'..'Z',' ','+','-','.',',','0'..'9'] then lName := lName + tx[lI];
-  end;
-  seek(fp, 795);
-  BlockRead(fp, Tx, 12*SizeOf(Char), n);
-  lID := '';
-  for lI := 0 to 11 do begin
-      if tx[lI] in ['/','\','a'..'z','A'..'Z',' ','+','-','.',',','0'..'9'] then lID := lID + tx[lI];
-  end;
-     lDicomData.ImageStart := 6144;
-     lYear := swap32i(0);
-     lMonth := swap32i(4);
-     lDay := swap32i(8);
-     lIHour := swap32i(68);
-     lIMin := swap32i(72);
-     lISec := swap32i(76);
-     lDicomData.XYZmm[3] := fswap8r (1544);
-     lMagField := fswap8r (2560);
-     lTR := fswap8r (1560);
-     lTE := fswap8r (1568);
-     lDIcomData.AcquNum := swap32i(3212);
-     lMatrixSz := swap32i(2864);
-     lDicomData.SiemensSlices := swap32i(4004); //1366
-     //lFullSz := swap32i(4008);
-     //lInterleaveIf4 := swap32i(2888);
-     lFullSz := (2*lMatrixSz*lMatrixSz);//16bitdata
-     if ((FileSz - 6144) mod lFullSz) = 0 then begin
-        case ((FileSz-6144) div lFullSz) of
-             4: lFullSz := 2*lMatrixSz;
-             9: lFullSz := 3*lMatrixSz;
-             16: lFullSz := 4*lMatrixSz;
-             25: lFullSz := 5*lMatrixSz;
-             36: lFullSz := 6*lMatrixSz;
-             49: lFullSz := 7*lMatrixSz;
-             64: lFullSz := 8*lMatrixSz;
-             else lFullSz := lMatrixSz;
-        end;
-     end else lFullSz := lMatrixSz;
-     {3744/3752 are XY FOV in mm!}
-     lDicomData.XYZdim[1] := lFullSz;//lMatrixSz; //width
-     lDicomData.XYZdim[2] := lFullSz;//lMatrixSz;//height
-     {5000/5008 are size in mm, but wrong for mosaics}
-     if lMatrixSz <> 0 then begin
-        lDicomData.XYZmm[2] := fswap8r (3744)/lMatrixSz;
-        lDicomData.XYZmm[1] := fswap8r (3752)/lMatrixSz;
-        if ((lDicomData.XYZdim[1] mod lMatrixSz)=0) then
-           lDicomData.SiemensMosaicX := lDicomData.XYZdim[1] div lMatrixSz;
-        if ((lDicomData.XYZdim[2] mod lMatrixSz)=0) then
-           lDicomData.SiemensMosaicY := lDicomData.XYZdim[2] div lMatrixSz;
-        if lDicomData.SiemensMosaicX < 1 then lDicomData.SiemensMosaicX := 1; //1366
-        if lDicomData.SiemensMosaicY < 1 then lDicomData.SiemensMosaicY := 1; //1366
-     end;
-     lFlipAngle := fswap8r (2112); //1414
-{     lDicomData.XYZmm[2] := fswap8r (5000);
-     lDicomData.XYZmm[1] := fswap8r (5008);}
-     lSliceThick := lDicomData.XYZmm[3];
-     lGap := fswap8r (4136); //gap as ratio of slice thickness?!?!
-     if {lGap > 0} (lGap=-1) or (lGap=-19222) then //1410: exclusion values: do not ask me why 19222: from John Ashburner
-     else begin
-        //lDicomData.XYZmm[3] := abs(lDicomData.XYZmm[3] * (1+lGap));
-        lGap := lDicomData.XYZmm[3] * (lGap);
-        lDicomData.XYZmm[3] := abs(lDicomData.XYZmm[3] +lGap);
-     end;
-     lDicomData.Allocbits_per_pixel := 16;//bits
-     //xlDicomData.Storedbits_per_pixel:= lDicomData.Allocbits_per_pixel;
-     //xlDicomData.GenesisCpt := false;
-     //xlDicomData.GenesisPackHdr := 0;
-     lMinStr := inttostr(lIMin);
-     if length(lMinStr) = 1 then lMinStr := '0'+lMinStr;
-     lSecStr := inttostr(lISec);
-     if length(lSecStr) = 1 then lSecStr := '0'+lSecStr;
-
-
-
-     lDynStr := 'Siemens Magnetom Vision Format'+kCR+'Name: '+lName+kCR+'ID: '+lID+kCR+'Institution: '+lInstitution+kCR+
-     'Study DD/MM/YYYY: '+inttostr(lDay)+'/'+inttostr(lMonth)+'/'+inttostr(lYear)+kCR+
-     'Image Hour/Min/Sec: '+inttostr(lIHour)+':'+lMinStr+':'+lSecStr+kCR+
-     //'Acquisition Hour/Min/Sec: '+inttostr(lAHour)+':'+lAMinStr+':'+lASecStr+kCR+
-     'Magnetic Field Strength: '+ floattostrf(lMagField,ffFixed,8,2)+kCR+
-     'Image index: '+inttostr(lDIcomData.AcquNum)+kCR+
-     'Time Repitition/Echo [TR/TE]: '+ floattostrf(lTR,ffFixed,8,2)+'/'+ floattostrf(lTE,ffFixed,8,2)+kCR+
-     'Flip Angle: '+ floattostrf(lFlipAngle,ffFixed,8,2)+kCR+
-     'Slice Thickness/Gap: '+floattostrf(lSliceThick,ffFixed,8,2)+'/'+floattostrf(lGap,ffFixed,8,2)+kCR+
-     'XYZ dim:' +inttostr(lDicomData.XYZdim[1])+'/'
-     +inttostr(lDicomData.XYZdim[2])+'/'+inttostr(lDicomData.XYZdim[3])+kCR+
-     'XY matrix:' +inttostr(lDicomData.SiemensMosaicX)+'/'
-     +inttostr(lDicomData.SiemensMosaicY)+kCR+
-     'XYZ mm:'+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)+'/'
-     +floattostrf(lDicomData.XYZmm[2],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2);
-  lHdrOK := true;
-  //lDIcomData.AcquNum := 0;
-567:
-CloseFile(fp);
-  FileMode := 2; //set to read/write
-end;
-//end siemens
-//begin elscint
-procedure read_elscint_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;lFileName: string);
-label
-  539;
-var
-  //lExamHdr,lImgHdr,lDATFormatOffset,lHdrOffset,
-  {lDate,}lI,lCompress,n,filesz: LongInt;
-  tx     : array [0..41] of Char;
-  FP: file;
-function readStr(lPos,lLen: integer):  string;
-var lStr: string;
-    lStrInc: integer;
-begin
-     seek(fp,lPos);
-     BlockRead(fp, tx, lLen, n);
-     lStr := '';
-     for lStrInc := 0 to (lLen-1) do
-         lStr := lStr + tx[lStrInc];
-     result := lStr
-end;
-function read8ch(lPos: integer): char;
-begin
-     seek(fp,40);
-     BlockRead(fp, result, 1, n);
-     //lDicomData.ImageNum := ord(tx[0]);
-end;
-procedure read16i(lPos: longint; var lVal: integer);
-var lInWord: word;
-begin
-  seek(fp,lPos);
-  BlockRead(fp, lInWord, 2);
-  lVal := lInWord;
-end;
-procedure read32i(lPos: longint; var lVal: integer);
-var lInINt: integer;
-begin
-  seek(fp,lPos);
-  BlockRead(fp, lInINt, 4);
-  lVal :=lInINt;
-end;
-
-begin
-  lImageFormatOK := true;
-  lHdrOK := false;
-  if not fileexists(lFileName) then begin
-     lImageFormatOK := false;
-     exit;
-  end;
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  FIleSz := FileSize(fp);
-  Clear_Dicom_Data(lDicomData);
-     if filesz < (3240) then begin
-        Msg('This file is too small to be a Elscint format image.');
-        goto 539;
-     end;
-     lDynStr:= '';
-     read16i(0, lI);
-     if (lI <> 64206) then begin
-        Msg('Unable to read this file: it does start with the Elscint signature.');
-        goto 539;
-     end;
-     lDicomdata.little_endian := 1;
-     lDynStr:= 'Elscint Format'+kCR;
-     lDynStr := lDynStr+'Patient Name: '+readstr(4,20)+kCR;
-     lDynStr := lDynStr+'Patient ID: '+readstr(24,13)+kCR;
-     read16i(38,lDicomData.AcquNum);
-     lDicomData.ImageNum := ord(read8Ch(40));
-     lDynStr := lDynStr+'Doctor & Ward: '+readstr(100,20)+kCR;
-     lDynStr := lDynStr+'Comments: '+readstr(120,40)+kCR;
-     if ord(read8Ch(163)) = 1 then
-        lDynStr := lDynStr + 'Sex: M'+kCR
-     else
-        lDynStr := lDynStr + 'Sex: F'+kCR;
-     read16i(200,lI);
-     lDicomData.XYZmm[3] := lI * 0.1;
-     read16i(370,lDicomData.XYZdim[1]);
-     read16i(372,lDicomData.XYZdim[2]);
-     read16i(374,lI);
-     lDicomData.XYZmm[1] := lI / 256;
-     lDicomData.XYZmm[2] := lDicomData.XYZmm[1];
-     lCompress := ord(read8Ch(376));
-     //xlDicomData.ElscintCompress := true;
-     //xread16i(400,lDicomData.WindowWidth);
-     //x read16i(398,lDicomData.WindowCenter);
-     case lCompress of
-          0: begin
-               lDynStr := lDynStr + 'Compression: None'+kCR;
-               //xlDicomData.ElscintCompress := false;
-          end;
-          1: lImageFormatOK := false;//xlDynStr := lDynStr + 'Compression: Old'+kCR;
-          2: lImageFormatOK := false;//xlDynStr := lDynStr + 'Compression: 2400 Elite'+kCR;
-          22: lImageFormatOK := false;//xlDynStr := lDynStr + 'Compression: Twin'+kCR;
-          else begin
-               lImageFormatOK := false;//xlDynStr := lDynStr + 'Compression: Unknown '+inttostr(lCOmpress)+kCR;
-               //lDicomData.ElscintCompress := false;
-          end;
-     end;
-     //lDicomData.XYZdim[1] := swap32i(linitialoffset+8); //width
-     //lDicomData.XYZdim[2] := swap32i(linitialoffset+12);//height
-     lDicomData.ImageStart := 396;
-     lDicomData.Allocbits_per_pixel := 16;
-     //xlDicomData.Storedbits_per_pixel:= lDicomData.Allocbits_per_pixel;
-     if (lDicomData.XYZdim[1]=160) and (lDicomData.XYZdim[2]= 160) and (FIleSz=52224) then begin
-         lDicomData.ImageStart := 1024;
-         lImageFormatOK := true;//x//xlDicomData.ElscintCompress := False;
-     end;
-     //lDicomData.XYZmm[3] := fswap4r (2310+26);// slice thickness mm
-     lDynStr := lDynStr+'Image/Study Number: '+inttostr(lDicomData.ImageNum)+'/'+ inttostr(lDicomData.AcquNum)+kCR
-     +'XYZ dim: ' +inttostr(lDicomData.XYZdim[1])+'/'
-     +inttostr(lDicomData.XYZdim[2])+'/'+inttostr(lDicomData.XYZdim[3])
-     //x+kCR+'Window Center/Width: '+inttostr(lDicomData.WindowCenter)+'/'+inttostr(lDicomData.WindowWidth)
-     +kCR+'XYZ mm: '+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)+'/'
-     +floattostrf(lDicomData.XYZmm[2],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2);
-  lHdrOK := true;
-  lImageFormatOK := true;
-  539:
-       CloseFile(fp);
-  FileMode := 2; //set to read/write
-end;
-//end elscint
-
-
-
-//start picker
-procedure read_picker_data(lVerboseRead: boolean; var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;lFileName: string);
-label 423;
-const kPickerHeader =8192;
-kRecStart = 280; //is this a constant?
-var
-  lDataStart,lVal,lDBPos,lPos,lRecSz, lNumRecs,lRec,FileSz,n: Longint;
-  lThkM,lThkN,lSiz: double;
-  tx     : array [0..6] of Char;
-  FP: file;
-  lDiskCacheRA: pChar;
-function ReadRec(lRecNum: integer): boolean;
-var
-   lNameStr,lValStr: string;
-   lOffset,lLen,lFPOs,lFEnd: integer;
-function ValStrToFloat: double;
-var lConvStr: string;
-    lI: integer;
-begin
-     Result := 0.0;
-     lLen := Length(lValStr);
-     if lLen < 1 then exit;
-     lConvStr := '';
-     for lI := 1 to lLen do
-         if lValStr[lI] in ['0'..'9'] then
-            lConvStr := lConvStr+ lValStr[lI];
-     if Length(lConvStr) < 1 then exit;
-     Result := strtofloat(lConvStr);
-end;
-begin
-  Result := false;
-  lFPos := ((lRecNum-1) * lRecSz)+ kRecStart;
-  lFEnd := lFpos + 6;
-  lNameStr := '';
-  for lFPos := lFPos to lFEnd do
-         if ord(lDiskCacheRA[lFPos]) <> 0 then
-            lNameStr := lNameStr +lDiskCacheRA[lFPos];
-  if (lVerboseRead) or (lNameStr = 'RCNFSIZ') or (lNameStr='SCNTHKM') or (lNameStr='SCNTHKN') then begin
-     lFPos := ((lRecNum-1) * lRecSz)+ kRecStart+8;
-     lFEnd := lFPos+1;
-     lOffset := 0;
-     for lFPos := lFPos to lFend do
-         lOffset := ((lOffset)shl 8)+(ord(lDiskCacheRA[lFPos]));
-     lFPos := ((lRecNum-1) * lRecSz)+ kRecStart+10;
-     lFEnd := lFPos+1;
-     lLen := 0;
-     for lFPos := lFPos to lFend do
-         lLen := ((lLen)shl 8)+(ord(lDiskCacheRA[lFPos]));
-     lOffset := lDataStart+lOffset+1;
-     lFEnd := lOffset+lLen-1;
-     if (lLen < 1) or  (lFEnd > kPickerHeader) then exit;
-     lValStr := '';
-     for lFPos := (lOffset) to lFEnd  do begin
-         lValStr := lValStr+lDiskCacheRA[lFPos];
-     end;
-     if lVerboseRead then lDynStr := lDynStr+kCR+lNameStr+': '+ lValStr;
-     if (lNameStr = 'RCNFSIZ') then lSiz := ValStrToFloat;
-     if (lNameStr='SCNTHKM') then lThkM := ValStrToFloat;
-     if (lNameStr='SCNTHKN') then lThkN := ValStrToFloat;
-  end; //verboseread, or vital value
-  result := true;
-end;
-function FindStr(l1,l2,l3,l4,l5: Char; lReadNum: boolean; var lNum: integer): boolean;
-var //lMarker: integer;
-    lNumStr: String;
-begin
-     Result := false;
-     repeat
-           if (lDiskCacheRA[lPos-4]=l1) and (lDiskCacheRA[lPos-3]=l2)
-           and (lDiskCacheRA[lPos-2]=l3) and (lDiskCacheRA[lPos-1]=l4)
-           and (lDiskCacheRA[lPos]=l5) then Result := true;
-           inc (lPos);
-     until (Result) or (lPos >= kPickerHeader);
-     if not Result then exit;
-     if not lReadNum then exit;
-     Result := false;
-     lNumStr := '';
-     repeat
-           if (lDiskCacheRA[lPos] in ['0'..'9']) then
-           lNumStr := lNumStr + lDiskCacheRA[lPos]
-           else if lNumStr <> '' then Result := true;
-           inc(lPos);
-     until (Result) or (lPos = kPickerHeader);
-     lNum := strtoint(lNumStr);
-end;
-begin
-  lSiz := 0.0;
-  lThkM := 0.0;
-  lThkN := 0.0;
-  lImageFormatOK := true;
-  lHdrOK := false;
-  if not fileexists(lFileName) then begin
-     lImageFormatOK := false;
-     exit;
-  end;
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  FIleSz := FileSize(fp);
-  Clear_Dicom_Data(lDicomData);
-     if filesz < (kPickerHeader) then begin
-        Msg('This file is to small to be a Picker image: '+lFileName );
-       CloseFile(fp);
-       FileMode := 2; //set to read/write
-       exit;
-     end;
-     seek(fp, 0);
-     BlockRead(fp, tx, 4*SizeOf(Char), n);
-     if (tx[0] <> '*') OR (tx[1] <> '*') OR (tx[2] <> '*') OR (tx[3] <> ' ') then begin {manufacturer is not SIEMENS}
-        Msg('Is this a Picker image? Expected ''***'' at the start of the file.'+ lFileName);
-       CloseFile(fp);
-       FileMode := 2; //set to read/write
-       exit;
-     end; {not picker}
-     if filesz = (kPickerHeader + (1024*1024*2)) then begin
-        lDICOMdata.XYZdim[1] := 1024;
-        lDICOMdata.XYZdim[2] := 1024;
-        lDICOMdata.XYZdim[3] := 1;
-        lDICOMdata.ImageStart := 8192;
-     end else
-     if filesz = (kPickerHeader + (512*512*2)) then begin
-        lDICOMdata.XYZdim[1] := 512;
-        lDICOMdata.XYZdim[2] := 512;
-        lDICOMdata.XYZdim[3] := 1;
-        lDICOMdata.ImageStart := 8192;
-     end else
-     if filesz = (8192 + (256*256*2)) then begin
-        lDICOMdata.XYZdim[1] := 256;
-        lDICOMdata.XYZdim[2] := 256;
-        lDICOMdata.XYZdim[3] := 1;
-        lDICOMdata.ImageStart := 8192;
-     end else begin
-        Msg('This file is the incorrect size to be a Picker image.');
-       CloseFile(fp);
-       FileMode := 2; //set to read/write
-       exit;
-     end;
-     getmem(lDiskCacheRA,kPickerHeader*sizeof(char));
-     seek(fp, 0);
-     BlockRead(fp, lDiskCacheRA, kPickerHeader, n);
-     lRecSz := 0;
-     lNumRecs := 0;
-     lPos := 5;
-     if not FindStr('d','b','r','e','c',false, lVal) then goto 423;
-     lDBPos := lPos;
-     if not FindStr('r','e','c','s','z',true, lRecSz) then goto 423;
-     lPos := lDBPos;
-     if not FindStr('n','r','e','c','s',true, lnumRecs) then goto 423;
-     lPos := kRecStart; // IS THIS A CONSTANT???
-     lDataStart :=kRecStart + (lRecSz*lnumRecs)-1; //file starts at 0, so -1
-     if (lNumRecs = 0) or (lDataStart> kPickerHeader) then goto 423;
-     lRec := 0;
-     lDynStr := 'Picker Format';
-     repeat
-          inc(lRec);
-     until (not (ReadRec(lRec))) or (lRec >= lnumRecs);
-     if lSiz <> 0 then begin
-        lDICOMdata.XYZmm[1] := lSiz/lDICOMdata.XYZdim[1];
-        lDICOMdata.XYZmm[2] := lSiz/lDICOMdata.XYZdim[2];
-        if lVerboseRead then
-           lDynStr := lDynStr+kCR+'Voxel Size: '+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)
-           +'x'+ floattostrf(lDicomData.XYZmm[2],ffFixed,8,2);
-     end;
-     if (lThkM <> 0) and (lThkN <> 0) then begin
-        lDICOMdata.XYZmm[3] := lThkN/lThkM;
-        if lVerboseRead then
-           lDynStr := lDynStr+kCR+'Slice Thickness: '+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2);
-     end;
-  423:
-     freemem(lDiskCacheRA);
-     lHdrOK := true;
-     CloseFile(fp);
-     FileMode := 2; //set to read/write
-end;
-//end picker
-
-procedure read_minc_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;lFileName: string);
-var
-//  lReal: double;
-  lnOri,lnDim,lStartPosition,nelem0,jj,lDT0,vSizeRA,BeginRA,m,nnelem,nc_type,nc_size,lLen,nelem,j,lFilePosition,lDT,lFileSz,lSignature,lWord: integer;
-
-  lOri: array [1..3] of double;
-  //tx     : array [0..80] of Char;
-  lVarStr,lStr: string;
-  FP: file;
-function dTypeStr (lV: integer): integer;
-begin
-     case lV of
-          1,2: result := 1;
-          3: result := 2; //int16
-          4: result := 4; //int32
-          5: result := 4; //single
-          6: result := 8; //double
-     end;
-end; //nested fcn dTypeStr
-
-function read32i: Longint;
-type
-  swaptype = packed record
-    case byte of
-      0:(Word1,Word2 : word); //word is 16 bit
-      1:(Long:LongInt);
-  end;
-  swaptypep = ^swaptype;
-var
-   s : LongInt;
-  inguy:swaptypep;
-  outguy:swaptype;
-begin
-  seek(fp,lFilePosition);
-  lFilePosition := lFilePosition + 4;
-  BlockRead(fp, s, 4);
-  inguy := @s; //assign address of s to inguy
-  if lDICOMdata.Little_Endian = 0 then begin
-     outguy.Word1 := swap(inguy^.Word2);
-     outguy.Word2 := swap(inguy^.Word1);
-  end else
-      outguy.long := inguy^.long;
-  result:=outguy.Long;
-end;
-
-function read64r (lDataType: integer): Double;
-type
-  swaptype = packed record
-    case byte of
-      0:(Word1,Word2,Word3,Word4 : word); //word is 16 bit
-      1:(Long:Double);
-  end;
-  swaptypep = ^swaptype;
-var
-   s : Double;
-  inguy:swaptypep;
-  outguy:swaptype;
-begin
-  result := 1;
-  if lDataType <> 6 then begin
-      Msg('Unknown data type: MRIcro is unable to determine the voxel size.');
-      exit;
-  end;
-  seek(fp,lFilePosition);
-  lFilePosition := lFilePosition + 8;
-  BlockRead(fp, s, 8);
-  inguy := @s; //assign address of s to inguy
-  if lDICOMdata.Little_Endian = 0 then begin
-     outguy.Word1 := swap(inguy^.Word4);
-     outguy.Word2 := swap(inguy^.Word3);
-     outguy.Word3 := swap(inguy^.Word2);
-     outguy.Word4 := swap(inguy^.Word1);
-  end else
-      outguy.long := inguy^.long;
-  result:=outguy.Long;
-end;
-
-function readname: String;
-var lI,lLen: integer;
-    lCh: char;
-begin
-  result := '';
-  seek(fp,lFilePosition);
-  lLen := read32i;
-  if lLen < 1 then begin
-     Msg('Terminal error reading netCDF/MINC header (String length < 1)');
-     exit; //problem
-  end;
-  for lI := 1 to lLen do begin
-      BlockRead(fp, lCh, 1);
-      result := result + lCh;
-  end;
-  lFilePosition := lFilePosition + (((lLen+3) div 4) * 4);
-end;
-
-begin
-  lImageFormatOK := true;
-  lHdrOK := false;
-  if not fileexists(lFileName) then begin
-     lImageFormatOK := false;
-     exit;
-  end;
-  for lnOri := 1 to 3 do
-      lOri[lnOri] := 0;
-  lnOri := 4;
-  lnDim := 4;
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  lFileSz := FileSize(fp);
-  Clear_Dicom_Data(lDicomData);
-  if lFilesz < (77) then exit; //to small to be MINC
-
-  lFilePosition := 0;
-  lSignature := read32i;
-  if not (lSignature=1128547841) then begin
-     CloseFile(fp);
-     FileMode := 2; //set to read/write
-     Msg('Problem with MINC signature: '+ inttostr(lSignature));
-     exit;
-  end;
-  //xlDicomData.Rotate180deg := true;
-  lWord := read32i;//numrecs
-  lDT := read32i;
-  while (lDt=10) or (lDT=11) or (lDT=12) do begin
-     if lDT = 10 then begin //DT=10, Dimensions
-        nelem := read32i;
-        for j := 1 to nelem do begin
-            lStr := readname;
-            lLen := read32i;
-            if lStr = 'xspace' then lDicomData.XYZdim[3] := lLen;//DOES MINC always reverse X and Z? see also XYZmm
-            if lStr = 'yspace' then lDicomData.XYZdim[2] := lLen;
-            if lStr = 'zspace' then lDicomData.XYZdim[1] := lLen;
-        end; //for 1..nelem
-        lDT := read32i;
-    end;//DT=10, Dimensions
-    if lDT = 11 then begin //DT=11, Variables
-        nelem := read32i;
-        for j := 1 to nelem do begin
-            lVarStr := readname;
-            nnelem := read32i;
-            for m := 1 to nnelem do
-                lLen := read32i;
-            lDT0 := read32i;
-            if lDT0 = 12 then begin
-               nelem0 := read32i;
-               for jj := 1 to nelem0 do begin
-                   lStr := readname;
-                   nc_type := read32i;
-                   nc_size := dTypeStr(nc_Type);
-                   nnelem := read32i;
-                   lStartPosition := lFilePosition;
-
-                   if (lStr = 'step') then begin
-
-                      if (lVarStr = 'xspace') or (lVarStr = 'yspace') or (lVarStr = 'zspace') then begin
-                         dec(lnDim);
-                         if (lnDim < 4) and (lnDim>0) then
-                            lDicomData.XYZmm[lnDim] := read64r(nc_Type)
-                      end;
-
-                   end else if (lStr = 'start') then begin
-                      if (lVarStr = 'xspace') or (lVarStr = 'yspace') or (lVarStr = 'zspace') then begin
-                         dec(lnOri);
-                         if (lnOri < 4) and (lnOri > 0) then
-                            lOri[lnOri] := read64r(nc_Type)
-                      end;
-                   end;
-                   lFilePosition := lStartPosition + ((((nnelem*nc_size)+3) div 4)*4);
-
-               end;
-               lDT0 := read32i;
-               if lVarStr = 'image' then begin
-                  case lDT0 of
-                       1,2: lDicomData.Allocbits_per_pixel := 8;
-                       3: lDicomData.Allocbits_per_pixel := 16; //int16
-                       4: lDicomData.Allocbits_per_pixel := 32; //int32
-                       5: lDicomData.Allocbits_per_pixel := 32; //single
-                       6: lDicomData.Allocbits_per_pixel := 64; //double
-                  end;
-                  if (lDT0 = 5) or (lDT0 = 6) then
-                     lDicomData.FloatData := true;
-                  //xlDicomData.Storedbits_per_pixel := lDicomData.Allocbits_per_pixel;
-                  //lImgNC_Type := lDT0;
-               end;
-            end;
-            vSizeRA := read32i;
-            BeginRA := read32i;
-            if lVarStr = 'image' then begin
-               lDICOMdata.ImageStart := BeginRA;
-            end;
-        end; //for 1..nelem
-        lDT := read32i;
-    end;//DT=11
-    if lDT = 12 then begin //DT=12, Attributes
-        nelem := read32i;
-        for j := 1 to nelem do begin
-            lStr := readname;
-            nc_type := read32i;
-            nc_size := dTypeStr(nc_Type);
-            nnelem := read32i;
-            lFilePosition := lFilePosition + ((((nnelem*nc_size)+3) div 4)*4);
-        end; //for 1..nelem
-        lDT := read32i;
-    end;//DT=12, Dimensions
-  end; //while DT
-
-  if lOri[1] <> 0 then
-     lDicomData.XYZori[1] := round((-lOri[1])/lDicomData.XYZmm[1])+1;
-  if lOri[2] <> 0 then
-     lDicomData.XYZori[2] := round((-lOri[2])/lDicomData.XYZmm[2])+1;
-  if lOri[3] <> 0 then
-     lDicomData.XYZori[3] := round((-lOri[3])/lDicomData.XYZmm[3])+1;
-
-  lDynStr := 'MINC image'+kCR+
-     'XYZ dim:' +inttostr(lDicomData.XYZdim[1])+'/'
-     +inttostr(lDicomData.XYZdim[2])+'/'+inttostr(lDicomData.XYZdim[3])
-     +kCR+'XYZ origin:' +inttostr(lDicomData.XYZori[1])+'/'
-     +inttostr(lDicomData.XYZori[2])+'/'+inttostr(lDicomData.XYZori[3])
-     +kCR+'XYZ size [mm or micron]:'+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)+'/'
-     +floattostrf(lDicomData.XYZmm[2],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2)
-     +kCR+'Bits per sample/Samples per pixel: '+inttostr( lDICOMdata.Allocbits_per_pixel)
-     +kCR+'Data offset:' +inttostr(lDicomData.ImageStart);
-  lHdrOK := true;
-  lImageFormatOK := true;
-  CloseFile(fp);
-  FileMode := 2; //set to read/write
-end; //read_minc
-
-
-
-//start TIF
-procedure read_tiff_data(var lDICOMdata: DICOMdata; var lReadOffsets, lHdrOK, lImageFormatOK: boolean; var lDynStr: string;lFileName: string);
-label
-  566, 564;
-const
-     kMaxnSLices = 6000;
-var
-  lLongRA: LongIntP;
-  lStackSameDim,lContiguous: boolean;
-  l1stDicomData: DicomData;
-  //lDouble : double;
-  //lXmm,lYmm,lZmm: double;
-  lSingle: single;
-  lImageDataEndPosition,lStripPositionOffset,lStripPositionType,lStripPositionItems,
-  lStripCountOffset,lStripCountType,lStripCountItems,
-  lItem,lTagItems,lTagItemBytes,lTagPointer,lNumerator, lDenominator,
-  lImage_File_Directory,lTagType,lVal,lDirOffset,lOffset,lFileSz,
-  lnDirectories,lDir,lnSlices: Integer;
-  lTag,lWord,lWord2: word;
-  FP: file;
-(*FUNCTION longint2single ({var} s:longint): single;
-//returns true if s is Infinity, NAN or Indeterminate
-//4byte IEEE: msb[31] = signbit, bits[23-30] exponent, bits[0..22] mantissa
-//exponent of all 1s =   Infinity, NAN or Indeterminate
-VAR Overlay: Single ABSOLUTE s;
-BEGIN
-  result := Overlay;
-END;*)
-
-function read64r(lPos: integer):double;
-type
-  swaptype = packed record
-    case byte of
-      0:(Word1,Word2,Word3,Word4 : word); //word is 16 bit
-      1:(float:double);
-  end;
-  swaptypep = ^swaptype;
-var
-  inguy:swaptypep;
-  outguy:swaptype;
-  s: double;
-begin
-  seek(fp,lPos);
-  BlockRead(fp, s, 8);
-  inguy := @s; //assign address of s to inguy
-  if lDICOMdata.Little_Endian = 0{false} then begin
-     outguy.Word1 := swap(inguy^.Word4);
-     outguy.Word2 := swap(inguy^.Word3);
-     outguy.Word3 := swap(inguy^.Word2);
-     outguy.Word4 := swap(inguy^.Word1);
-  end else
-      outguy.float := inguy^.float;
-  result:=outguy.float;
-end;
-
-function read32i(lPos: longint): Longint;
-type
-  swaptype = packed record
-    case byte of
-      0:(Word1,Word2 : word); //word is 16 bit
-      1:(Long:LongInt);
-  end;
-  swaptypep = ^swaptype;
-var
-   s : LongInt;
-  inguy:swaptypep;
-  outguy:swaptype;
-begin
-  seek(fp,lPos);
-  BlockRead(fp, s, 4);
-  inguy := @s; //assign address of s to inguy
-  if lDICOMdata.Little_Endian = 0 then begin
-     outguy.Word1 := swap(inguy^.Word2);
-     outguy.Word2 := swap(inguy^.Word1);
-  end else
-      outguy.long := inguy^.long;
-  result:=outguy.Long;
-end;
-function read16(lPos: longint): Longint;
-var
-   s : word;
-begin
-  seek(fp,lPos);
-  BlockRead(fp, s, 2);
-  if lDICOMdata.Little_Endian = 0 then
-     result := swap(s)
-  else
-      result := s;
-end;
-
-function read8(lPos: longint): Longint;
-var
-   s : byte;
-begin
-  seek(fp,lPos);
-  BlockRead(fp, s, 1);
-  result := s;
-end;
-
-function readItem(lItemNum,lTagTypeI,lTagPointerI: integer): integer;
-begin
-     if lTagTypeI= 4 then
-        result := read32i(lTagPointerI+((lItemNum-1)*4))
-     else
-         result := read16(lTagPointerI+((lItemNum-1)*2));
-end;
-
-begin
-  Clear_Dicom_Data(lDicomData);
-  if gECATJPEG_table_entries <> 0 then begin
-     freemem (gECATJPEG_pos_table);
-     freemem (gECATJPEG_size_table);
-     gECATJPEG_table_entries := 0;
-  end;
-  //lXmm := -1; //not read
-  lImageFormatOK := true;
-  lHdrOK := false;
-  if not fileexists(lFileName) then begin
-     lImageFormatOK := false;
-     exit;
-  end;
-  //lLongRASz := kMaxnSlices * sizeof(longint);
-  getmem(lLongRA,kMaxnSlices*sizeof(longint));
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  lFileSz := FileSize(fp);
-  Clear_Dicom_Data(lDicomData);
-  //xlDicomData.PlanarConfig:=0;
-  if lFilesz < (28) then begin
-        goto 566;
-  end;
-  //TmpStr := string(StrUpper(PChar(ExtractFileExt(lFileName))));
-  //if not (TmpStr = '.TIF') or (TmpStr = '.TIFF') then exit;
-  lWord   := read16(0);
-  if lWord = $4d4d then
-     lDICOMdata.little_endian := 0
-  else if lWord = $4949 then lDICOMdata.little_endian := 1;
-  lWord2   := read16(2); //bits per pixel
-  if ((lWord=$4d4d) or (lWord=$4949)) and (lWord2 = $002a) then
-  else goto 566;
-  lOffset := read32i(4);
-  lImage_File_Directory := 0;
-  lContiguous := true;
-  lnSlices := 0;
-  //xlDicomData.SamplesPerPixel := 1;
-  //START while for each image_file_directory
-  while (lOffset > 0) and ((lOffset+2+12+4) < lFileSz) do begin
-        inc(lImage_File_Directory);
-        lnDirectories := read16(lOffset);
-        if (lnDirectories < 1) or ((lOffset+2+(12*lnDirectories)+4) > lFileSz) then
-           goto 566;
-        for lDir := 1 to lnDirectories do begin
-            lDirOffset := lOffset+2+((lDir-1)*12);
-            lTag   := read16(lDirOffset);
-            lTagType := read16(lDirOffset+2);
-            lTagItems := read32i(lDirOffset+4);
-            case lTagType of
-                 1: lVal := 1;//bytes
-                 3: lVal := 2;//word
-                 4: lVal := 4;//long
-                 5: lVal := 8;//rational
-                 else lVal := 1; //CHAR variable length
-            end;
-            lTagItemBytes := lVal * lTagItems;
-            if lTagItemBytes > 4 then
-                 lTagPointer := read32i(lDirOffset+8)
-            else
-                lTagPointer := (lDirOffset+8);
-            case lTagType of
-                 1: lVal := read8(lDirOffset+8);
-                 3: lVal := read16(lDirOffset+8);
-                 4: lVal := read32i(lDirOffset+8);
-                 5: begin //rational: two longs representing numerator and denominator
-                     lVal := read32i(lDirOffset+8);
-                     lNumerator := read32i(lVal);
-                     lDenominator := read32i(lVal+4);
-                     if lDenominator <> 0 then
-                        lSingle := lNumerator/lDenominator
-                     else
-                         lSingle := 1;
-                     if lSingle <> 0 then
-                        lSingle := 1/lSingle; //Xresolution/Yresolution refer to number of pixels per resolution_unit
-                     if lTag = 282 then  lDicomData.XYZmm[1] := lSingle;
-                     if lTag = 283 then  lDicomData.XYZmm[2] := lSingle;
-                 end;
-                 else lVal := 0;
-            end;
-            case lTag of
-                 //254: ;//NewSubFileType
-                 256: lDicomData.XYZdim[1] := lVal;//image_width
-                 257: lDicomData.XYZdim[2] := lVal;//image_height
-                 258: begin  //bits per sample
-                     if lTagItemBytes > 4 then lVal := 8;
-                     //if lVal <> 8 then goto 566;
-                     lDicomData.Allocbits_per_pixel := lVal;//bits
-                     //xlDicomData.Storedbits_per_pixel:= lDicomData.Allocbits_per_pixel;
-                 end;
-                 259: begin
-                           if lVal <> 1 then begin
-                              Msg('TIFF Read Error: Image data is compressed. Currently only uncompressed data is supported.');
-                              goto 566; //compressed data
-                           end;
-                      end;
-                 //x262: if lVal = 0 then lDicomdata.monochrome := 1;//invert colors //photometric_interpretation  //MinIsWhite,MinIsBlack,Palette
-                 //270: ; //ImageDescription
-                 273: begin //get offset to data
-                      lStripPositionOffset := lTagPointer;
-                      lStripPositionType := lTagType;
-                      lStripPositionItems := lTagItems;
-                      if (lImage_File_Directory=1) then
-                         lDicomData.ImageStart := readItem(1,lStripPositionType,lStripPositionOffset);
-                 end; //StripOffsets
-                 //274: ; //orientation
-                 277: begin
-                      //xlDicomData.SamplesPerPixel := lVal;
-                      //if lVal <> 1 then goto 566; //samples per pixel
-                 end;
-                 279: begin
-                      lStripCountOffset := lTagPointer;
-                      lStripCountType := lTagType;
-                      lStripCountItems := lTagItems;
-                 end;
-                 //278: message('rows:'+inttostr(lVal));//StripByteCount
-                 //279: message('count:'+inttostr(lVal));//StripByteCount
-                 //282 and 283 are rational values and read separately
-                 284: begin
-                      {xif lVal = 1 then
-                         lDicomData.PlanarConfig:= 0
-                      else
-                          lDicomData.PlanarConfig:= 1;//planarConfig
-                } end;
-                 34412: begin
-                     //Zeiss data header
- //0020h  float       x size of a pixel (�m or s)
- //0024h  float       y size of a pixel (�m or s)
- //0028h  float       z distance in a sequence (�m or s)
-        {stream.seek((int)position + 40);
-        VOXELSIZE_X = swap(stream.readDouble());
-        stream.seek((int)position + 48);
-        VOXELSIZE_Y = swap(stream.readDouble());
-        stream.seek((int)position + 56);
-        VOXELSIZE_Z = swap(stream.readDouble());}
-        lVal := read16(lTagPointer+2);
-        if lVal = 1024 then begin //LSM510 v2.8 images
-           lDicomData.XYZmm[1]{lXmm} := read64r(lTagPointer+40)*1000000;
-           lDicomData.XYZmm[2]{lYmm} := read64r(lTagPointer+48)*1000000;
-           lDicomData.XYZmm[3]{lZmm} := read64r(lTagPointer+56)*1000000;
-        end;
-        //following may work if lVal = 2, different type of LSM file I have not seen
-                      //lXmm := longint2single(read32i(lTagPointer+$0020));
-                      //lYmm := longint2single(read32i(lTagPointer+$0024));
-                      //lZmm := longint2single(read32i(lTagPointer+$0028));
-                 end;
-                 //296: ;//resolutionUnit 1=undefined, 2=inch, 3=centimeter
-                 //320??
-                 //LEICA: 34412
-  //SOFTWARE = 305
-  //DATE_TIME = 306
-  //ARTIST = 315
-  //PREDICTOR = 317
-  //COLORMAP = 320 => essntially custom LookUpTable
-  //EXTRASAMPLES = 338
-  //SAMPLEFORMAT = 339
-  //JPEGTABLES = 347
-                 //         lDicomData.ImageStart := lVal
-                 //else if lImage_File_Directory = 1 then Msg(inttostr(lTag)+'@'+inttostr(lTagPointer)+' value: '+inttostr(lVal));
-            end; //case lTag
-        end; //For Each Directory in Image_File_Directory
-        lOffset := read32i(lOffset+2+(12*lnDirectories));
-        //NEXT: check that each slice in 3D slice is the same dimension
-        lStackSameDim := true;
-        if (lImage_File_Directory=1) then begin
-          l1stDicomData := lDICOMdata;
-          lnSlices := 1; //inc(lnSlices);
-        end else begin
-             if lDicomData.XYZdim[1] <> l1stDicomData.XYZdim[1] then lStackSameDim  := false;
-             if lDicomData.XYZdim[2] <> l1stDicomData.XYZdim[2] then lStackSameDim  := false;
-             if lDicomData.Allocbits_per_pixel <> l1stDicomData.Allocbits_per_pixel then lStackSameDim  := false;
-             //xif lDicomData.SamplesPerPixel <> l1stDicomData.SamplesPerPixel then lStackSameDim  := false;
-             //xif lDicomData.PlanarConfig <> l1stDicomData.PlanarConfig then lStackSameDim  := false;
-             if not lStackSameDim then begin
-                //Msg(inttostr(lDicomData.XYZdim[1])+'x'+inttostr(l1stDicomData.XYZdim[1]));
-                if (lDicomData.XYZdim[1]*lDicomData.XYZdim[2]) > (l1stDicomData.XYZdim[1]*l1stDicomData.XYZdim[2]) then begin
-                   l1stDicomData := lDICOMdata;
-                   lnSlices := 1;
-                   lStackSameDim := true;
-                end;
-                //Msg('TIFF Read Error: Different 2D slices in this 3D stack have different dimensions.');
-                //goto 566;
-             end else
-                 inc(lnSlices); //if not samedim
-        end; //check that each slice is same dimension as 1st
-        //END check each 2D slice in 3D stack is same dimension
-        //NEXT: check if image data is contiguous
-        if (lStripCountItems > 0) and (lStripCountItems = lStripPositionItems) then begin
-           if (lnSlices=1) then lImageDataEndPosition := lDicomData.ImageStart;
-           for lItem := 1 to lStripCountItems do begin
-               lVal := readItem(lItem,lStripPositionType,lStripPositionOffset);
-               if (lVal <> lImageDataEndPosition) then
-                  lContiguous := false;
-                  //Msg(inttostr(lImage_File_Directory)+'@'+inttostr(lItem));
-               lImageDataEndPosition := lImageDataEndPosition+readItem(lItem,lStripCountType,lStripCountOffset);
-               if not lcontiguous then begin
-                  if (lReadOffsets) and (lStackSameDim)  then begin
-                     lLongRA^[lnSlices] := lVal;
-                  end else if (lReadOffsets) then
-                    //not correct size, but do not generate an error as we will read non-contiguous files
-                  else begin
-                      Msg('TIFF Read Error: Image data is not stored contiguously. '+
-                      'Solution: convert this image using MRIcro''s ''Convert TIFF/Zeiss to Analyze...'' command [Import menu].');
-                      goto 564;
-                  end;
-               end; //if not contiguous
-           end; //for each item
-        end;//at least one StripItem}
-        //END check image data is contiguous
-  end; //END while each Image_file_directory
-  lDicomData := l1stDicomData;
-  lDicomData.XYZdim[3] := lnSlices;
-  if (lReadOffsets) and (lnSlices > 1) and (not lcontiguous) then begin
-           gECATJPEG_table_entries := lnSlices; //Offset tables for TIFF
-           getmem (gECATJPEG_pos_table, gECATJPEG_table_entries*sizeof(longint));
-           getmem (gECATJPEG_size_table, gECATJPEG_table_entries*sizeof(longint));
-           gECATJPEG_pos_table^[1]  := l1stDicomData.ImageStart;
-           for lVal := 2 to gECATJPEG_table_entries do
-               gECATJPEG_pos_table^[lVal] := lLongRA^[lVal]
-  end;
-  lHdrOK := true;
-564:
-  lDynStr := 'TIFF image'+kCR+
-     'XYZ dim:' +inttostr(lDicomData.XYZdim[1])+'/'
-     +inttostr(lDicomData.XYZdim[2])+'/'+inttostr(lDicomData.XYZdim[3])
-     +kCR+'XYZ size [mm or micron]:'+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)+'/'
-     +floattostrf(lDicomData.XYZmm[2],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2)
-     +kCR+'Bits per sample/Samples per pixel: '+inttostr( lDICOMdata.Allocbits_per_pixel)
-     +kCR+'Data offset:' +inttostr(lDicomData.ImageStart);
-  {if lXmm > 0 then
-      lDynStr := lDynStr +kCR+'Zeiss XYZ mm:'+floattostr(lXmm)+'/'
-       +floattostr(lYmm)+'/'
-       +floattostr(lZmm);}
-566:
-  freemem(lLongRA);
-  CloseFile(fp);
-  FileMode := 2; //set to read/write
-end;
-
-procedure read_biorad_data(var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;lFileName: string);
-var
-   lCh: char;
-   lByte: Byte;
-  lSpaces,liPos,lFileSz,lWord,lNotes,lStart,lEnd: integer;
-  tx     : array [0..80] of Char;
-  lInfo,lStr,lTmpStr: string;
-  FP: file;
-procedure read16(lPos: longint; var lVal: integer);
-var lInWord: word;
-begin
-  seek(fp,lPos);
-  BlockRead(fp, lInWord, 2);
-  lVal := lInWord;
-end;
-procedure read32(lPos: longint; var lVal: integer);
-var lInINt: integer;
-begin
-  seek(fp,lPos);
-  BlockRead(fp, lInINt, 4);
-  lVal :=lInINt;
-end;
-
-begin
-  lImageFormatOK := true;
-  lHdrOK := false;
-  if not fileexists(lFileName) then begin
-     lImageFormatOK := false;
-     exit;
-  end;
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  lFileSz := FileSize(fp);
-  Clear_Dicom_Data(lDicomData);
-  if lFilesz < (77) then exit; //to small to be biorad
-  read16(54,lWord);
-  if (lWord=12345) then begin
-     lDicomData.little_endian := 1;
-           read16(0,lDicomData.XYZdim[1]);
-           read16(2,lDicomData.XYZdim[2]);
-           read16(4,lDicomData.XYZdim[3]);
-           read16(14,lWord);//byte format
-           if lWord = 1 then
-              lDicomData.Allocbits_per_pixel := 8
-           else
-               lDicomData.Allocbits_per_pixel := 16;//bits
-           //xlDicomData.Storedbits_per_pixel:= lDicomData.Allocbits_per_pixel;
-           lDicomData.ImageStart := 76;
-           read32(10,lNotes);
-           lStart := (lDicomData.XYZdim[1]*lDicomData.XYZdim[2]*lDicomData.XYZdim[3])+76;
-           lEnd := lStart + 96;
-           lDynStr := 'BIORAD PIC image'+kCR;
-           while (lNotes > 0) and (lFileSz >= lEnd)  do begin
-             read32(lStart+2,lNotes); //final note has bytes 2..5 set to zero
-             //read16(lStart+10,lNoteType);
-             //if lNoteType <> 1 then begin //ignore 'LIVE' notes - they do not include calibration info
-              seek(fp, lStart+16);
-              BlockRead(fp, tx, 80{, n});
-              lStr := '';
-              liPos := 0;
-              repeat
-                  lCh := tx[liPos];
-                  lByte := ord(lCh);
-                  if (lByte >= 32) and (lByte <= 126) then
-                     lStr := lStr+lCh
-                  else lByte := 0;
-                  inc(liPos);
-              until (liPos = 80) or (lByte = 0);
-              if length(lStr) > 6 then begin
-                  lInfo := '';
-                  for liPos := 1 to 6 do
-                      lInfo := lInfo+upcase(lStr[liPos]);
-                  ltmpstr := '';
-                  lSpaces := 0;
-                  for liPos := 1 to 80 do begin
-                      if lStr[liPos]=' ' then inc(lSpaces)
-                      else if lSpaces = 3 then
-                         ltmpstr := ltmpstr + lStr[liPos];
-                  end;
-                 if ltmpstr = '' then {no value to read}
-                 else if lInfo = 'AXIS_2' then
-                     lDicomData.XYZmm[1] := strtofloat(ltmpstr)
-                 else if lInfo = 'AXIS_3' then
-                     lDicomData.XYZmm[2] := strtofloat(ltmpstr)
-                 else if linfo = 'AXIS_4' then
-                     lDicomData.XYZmm[3] := strtofloat(ltmpstr);
-                  lDynStr := lDynStr+lStr+kCR;
-              end; //Str length > 6
-             //end;//notetype
-              lStart := lEnd;
-              lEnd := lEnd + 96;
-           end; //while notes
-           lHdrOK := true;
-           //lImageFormatOK := true;
-        end;//biorad signature
-  CloseFile(fp);
-  FileMode := 2; //set to read/write
-    lDynStr := 'BioRad image'+kCR+
-     'XYZ dim:' +inttostr(lDicomData.XYZdim[1])+'/'
-     +inttostr(lDicomData.XYZdim[2])+'/'+inttostr(lDicomData.XYZdim[3])
-     +kCR+'XYZ size [mm or micron]:'+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)+'/'
-     +floattostrf(lDicomData.XYZmm[2],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2)
-     +kCR+'Bits per sample/Samples per pixel: '+inttostr( lDICOMdata.Allocbits_per_pixel)
-     +kCR+'Data offset:' +inttostr(lDicomData.ImageStart);
-end; //biorad
-
-function SiemensVersion (lStr: string): integer;
-//Convert tag 0018,1020 from DICOM header to Siemens version number
-(*Returned value: system is in 1000s, last two digits are version
- Siemens syngo MR 2006T 4VB12T //-> 0012
-MR B13 4VB13A  //->0013
-MR.VB15A123    //->0015
-syngo MR B15  //-> 0015
-syngo MR B17 //->0017 B= Trio, Verio, Etc
-syngo MR C11 //->1011 C= Chinese C11 ~ B17
-syngo MR D11 //->2011 D= Skyra D11 ~ B17*)
-label 999;
-var
-  i,len: integer;
-begin
-  result := 0;
-  len := length(lStr);
-  if len < 3 then exit;
-  for i := 1 to len-1 do
-    if (upcase(lStr[i]) in ['A'..'Z']) and (lStr[i+1] in ['0'..'9']) then
-      goto 999;
-  exit; //not Siemens format
-999:
-  result :=  strtoint(lStr[i+1]);
-  if lStr[i+2] in ['0'..'9'] then
-    result := (result*10) + strtoint(lStr[i+2]);
-  result := (100*( ord(upcase(lStr[i]))- ord('B'))) + result;
-end;
-(* Obsolete - replaced by SiemensVersion
-function SiemensBversion (lStr: string): integer;
-//'syngo MR B17' returns 17
-//'MR.VB15A123' returns 15
-//'syngo MR B15' returns 15
-//'MR B13 4VB13A' returns 13
-//'syngo MR 2006T 4VB12T' returns 12
-var
-   Len,P,B: integer;
-   S: string;
-begin
-     result := 0;
-     Len := length(lStr);
-     if Len <2 then exit;
-     B := 0;
-     for P := 2 to (Len) do
-         if (upcase(lStr[P-1])='B') and ( lStr[P] in ['0'..'9'])  then
-            B := P;
-     if B < 1 then
-      exit;
-     S := '';
-     while (B<= Len) and (lStr[B] in ['0'..'9']) do begin
-      S := S + lStr[B];
-      inc(B);
-     end;
-     if length(S) < 1 then exit;
-     result := strtoint(S);
-end;*)
-
-(*function Str2IntDig (lStr: string; lDig: integer): integer;
-//robust stringtoint that strips out   any junk so that "Implementation Version Name=MR.VB15A123" returns 15
-// warning, strips out decimals, so 15.3 will return 153!
-//warning also ignores minus sign so -5.21 will return 521!
-var
-   Len,P: integer;
-   S: string;
-begin
-     result := 0;
-     Len := length(lStr);
-     if Len <1 then exit;
-     S := '';
-     for P := 1 to Len do
-         if (lStr[P] in ['0'..'9']) and (length(S) < lDig) then
-            S := S + lStr[P];
-     if length(S) < 1 then exit;
-     result := strtoint(S);
-end;  *)
-
-function  ExpectedDicomBytes (var lDICOMdata: DICOMdata): integer;
-begin
-  if lDicomData.JPEGLosslessCpt then begin
-    result :=  0; //actual compressed size unknown
-    exit;
-  end;
-  result := lDicomdata.XYZdim[1]*lDicomdata.XYZdim[2]*lDicomdata.XYZdim[3]*(lDicomData.Allocbits_per_pixel DIV 8);
-end;
-
-procedure read_dicom_data_compat(lReadJPEGtables,lVerboseRead,lAutoDECAT7,lReadECAToffsetTables,lAutoDetectInterfile,lAutoDetectGenesis,lReadColorTables: boolean; var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK: boolean; var lDynStr: string;var lFileName: string; var lPrefs: TPrefs);
-label 666,777;
-const
-  kMaxTextBuf = 50000; //maximum for screen output
-  kDiskCache = 16384; //size of disk buffer
-  kNaNsingle : single = 1/0;
-
-type
-  dicom_types = (unknown, i8, i16, i32, ui8, ui16, ui32, _string{,_float} );
-var
- // lTextF: TextFile; //abba
- lDICOMdataBackUp: DICOMdata;
- lWord,lWord2,lWord3: word;
- lWordRA: Wordp;
- lDiskCacheRA: pChar{ByteP};
- lRot1,lRot2,lRot3 : integer;//rotation dummies for AFNI
- FP: file;
-   lT0,lT1,lT2,lT3:byte;
-  lImagePositionPatientRead,
-  lResearchMode,lManufacturerIsPhilips,lManufacturerIsBruker,lMediface0002_0013,lSiemensMosaic0008_0008,lDICM_at_128, lTextOverFlow,lGenesis,lFirstPass,lrOK,lBig,lBigSet,lGrp,explicitVR,first_one    : Boolean;
-  lSwitchToImplicitAfterGroup0002, lTestError,lByteSwap,lGELX,time_to_quit,lProprietaryImageThumbnail,lFirstFragment,lOldSiemens_IncorrectMosaicMM : Boolean;
-  group, element, e_len, remaining, tmp : uint32;
-  tmpstr : kDICOMstr;
-  lgrpstr,lStr,info,lDummyStr   : string;
-  t      : dicom_types;
-  lfloat1,lfloat2,lfloat3,lThickness: double;
-  lTempInt,lEchoNum,lnVol,lnSlicePerVol,lJPEGentries,lErr,liPos,lCacheStart,lCachePos,lDiskCacheSz,n, i,value, Ht,Width,
-  max16,min16,filesz,where,lMatrixSz,lPhaseEncodingSteps,lJunk,lJunk2,lJunk3 : LongInt;
-  tx     : array [0..96] of Char;
-  l4DDistanceBetweenSliceCenters,lPhilipsScaleSlope: single;
-  buff: pCHar;
-  lColorRA: bytep;
-  lLongRA: Longintp;
-  lSingleRA,lInterceptRA: Singlep;
-  //lPapyrusnSlices,lPapyrusSlice : integer;
-  //lPapyrusZero,lPapyrus : boolean;
-procedure ByteSwap (var lInOut: integer);
-var lWord: word;
-begin
-     lWord := lInOut;
-     lWord := swap(lWord);
-     lInOut := lWord;
-end;
-procedure dReadCache (lFileStart: integer);
-begin
-  lCacheStart := lFileStart{lCacheStart + lDiskCacheSz};//eliminate old start
-  if lCacheStart < 0 then lCacheStart := 0;
-  if lDiskCacheSz > 0 then freemem(lDiskCacheRA);
-  if (FileSz-(lCacheStart)) < kDiskCache then
-     lDiskCacheSz := FileSz - (lCacheStart)
-  else
-      lDiskCacheSz := kDiskCache;
-  lCachePos := 0;
-  if (lDiskCacheSz < 1) then exit{goto 666};
-  if (lDiskCacheSz+lCacheStart) > FileSz then exit;
-  Seek(fp, lCacheStart);
-
-  GetMem(lDiskCacheRA, lDiskCacheSz {bytes});
-  BlockRead(fp, lDiskCacheRA^, lDiskCacheSz, n);
-end;
-
-function dFilePos (var lInFP: file): integer;
-begin
-     Result := lCacheStart + lCachePos;
-end;
-procedure dSeek (var lInFP: file; lPos: integer);
-begin
-  if (lPos >= lCacheStart) and (lPos < (lDiskCacheSz+lCacheStart)) then begin
-     lCachePos := lPos-lCacheStart;
-     exit;
-  end;
-  dReadCache(lPos);
-end;
-
-procedure dBlockRead (var lInfp: file; lInbuff: pChar; e_len: integer; var n: integer);
-var lN: integer;
-begin
-     N := 0;
-     if e_len < 0 then exit;
-     for lN := 0 to (e_len-1) do begin
-         if lCachePos >= lDiskCacheSz then begin
-            dReadCache(lCacheStart+lDiskCacheSz);
-            if lDiskCacheSz < 1 then exit;
-            lCachePos := 0;
-         end;
-         N := lN;
-         lInBuff[N] := lDiskCacheRA[lCachePos];
-         inc(lCachePos);
-     end;
-end;
-procedure readfloats (var fp: file; remaining: integer; var lOutStr: string; var lf1, lf2: double; var lReadOK: boolean);
-var  lDigit : boolean;
-   li,lLen,n: integer;
-    lfStr: string;
-begin
-    lf1 := 1;
-    lf2 := 2;
-    if e_len = 0 then begin
-       lReadOK := true;
-       exit;
-    end;
-    if (dFilePos(fp) > (filesz-remaining)) or (remaining < 1) then begin
-       lOutStr := '';
-       lReadOK := false;
-       exit;
-    end else
-        lReadOK := true;
-    lOutStr := '';
-    GetMem( buff, e_len);
-    dBlockRead(fp, buff{^}, e_len, n);
-	for li := 0 to e_len-1 do
-		if Char(buff[li]) in [{'/','\', delete: rev18}'e','E','+','-','.','0'..'9']
-           then lOutStr := lOutStr +(Char(buff[li]))
-        else begin
-             lOutStr := lOutStr + ' ';
-        end;
-    FreeMem( buff);
-    lfStr := '';
-    lLen := length(lOutStr);
-
-    li := 1;
-    lDigit := false;
-    repeat
-      if (lOutStr[li] in ['+','-','e','E','.','0'..'9']) then
-         lfStr := lfStr + lOutStr[li];
-      if lOutStr[li] in ['0'..'9'] then lDigit := true;
-      inc(li);
-    until (li > lLen) or (lDigit);
-    if not lDigit then exit;
-    if li <= li then begin
-       repeat
-             if not (lOutStr[li] in ['+','-','e','E','.','0'..'9']) then lDigit := false
-             else begin
-                  if lOutStr[li] = 'E' then lfStr := lfStr+'e'
-                  else
-                      lfStr := lfStr + lOutStr[li];
-             end;
-             inc(li);
-       until (li > lLen) or (not lDigit);
-    end;
-    //QStr(lfStr);
-    try
-       lf1 := strtofloat(lfStr);
-    except
-          on EConvertError do begin
-             Msg('Unable to convert the string '+lfStr+' to a real number');
-             lf1 := 1;
-             exit;
-          end;
-    end; {except}
-    lfStr := '';
-    if li > llen then exit;
-    repeat
-             if (lOutStr[li] in ['+','E','e','.','-','0'..'9']) then begin
-                  if lOutStr[li] = 'E' then lfStr := lfStr+'e'
-                  else
-                      lfStr := lfStr + lOutStr[li];
-             end;
-             if (lOutStr[li] in ['0'..'9']) then lDigit := true;
-             inc(li);
-    until (li > lLen) or ((lDigit) and (lOutStr[li]=' ')); //second half: rev18
-    if not lDigit then exit;
-    //QStr(lfStr);
-    try
-       lf2 := strtofloat(lfStr);
-    except
-          on EConvertError do begin
-             Msg('Unable to convert the string '+lfStr+' to a real number');
-             exit;
-          end;
-    end;
-
-end;
-
-procedure readfloats3 (var fp: file; remaining: integer; var lOutStr: string; var lf1, lf2,lf3: double; var lReadOK: boolean);
-var  lDigit : boolean;
-   lItem,li,lLen,n: integer;
-    lfTemp: double;
-    lfStr: string;
-begin
-    lf1 := 0;
-    lf2 := 0;
-    lf3 := 0;
-    lOutStr := '';
-    if e_len = 0 then begin
-       lReadOK := true;
-       exit;
-    end;
-    if (dFilePos(fp) > (filesz-remaining)) or (remaining < 1) then begin
-       lReadOK := false;
-       exit;
-    end else
-        lReadOK := true;
-    GetMem( buff, e_len);
-    dBlockRead(fp, buff{^}, e_len, n);
-    for li := 0 to e_len-1 do
-        if Char(buff[li]) in [{'/','\', delete: rev18}'e','E','+','-','.','0'..'9']
-           then lOutStr := lOutStr +(Char(buff[li]))
-        else lOutStr := lOutStr + ' ';
-    FreeMem( buff);
-	li := 1;
-	lLen := length(lOutStr);
- for lItem := 1 to 3 do begin
-    if li > llen then exit;
-	lfStr := '';
-	lLen := length(lOutStr);
-    lDigit := false;
-    repeat
-      if (lOutStr[li] in ['+','-','e','E','.','0'..'9']) then
-         lfStr := lfStr + lOutStr[li];
-      if lOutStr[li] in ['0'..'9'] then lDigit := true;
-      inc(li);
-    until (li > lLen) or (lDigit);
-    if not lDigit then exit;
-    if li <= li then begin
-       repeat
-             if not (lOutStr[li] in ['+','-','e','E','.','0'..'9']) then lDigit := false
-             else begin
-                  if lOutStr[li] = 'E' then lfStr := lfStr+'e'
-                  else
-                      lfStr := lfStr + lOutStr[li];
-             end;
-             inc(li);
-       until (li > lLen) or (not lDigit);
-    end;
-    //QStr(lfStr);
-    try
-       lftemp := strtofloat(lfStr);
-    except
-          on EConvertError do begin
-             Msg('Unable to convert the string '+lfStr+' to a real number');
-             //lftemp := 0;
-             exit;
-          end;
-    end; {except}
-    case lItem of
-         2: lf2 := lftemp;
-         3: lf3 := lftemp;
-		 else lf1 := lftemp;
-	end; //case of lItem
-end; //for each of 3 lItems
-end; //readfloats3
-
-procedure CheckIntersliceDistance (var lMinDistance: single);
-var
-   lX,lY,lZ,lDx: double;
-begin
-             readfloats3 (fp, remaining, lDummyStr, lX, lY,lZ, lROK);
-             //     fx(   lX, lY,lZ,6789);
-             e_len := 0;
-             remaining := 0;
-             //compute Distance between current slice and 1st slice...
-             lDx := sqrt( sqr(lX-lDicomData.PatientPosX)+sqr(lY-lDicomData.PatientPosY)+sqr(lZ-lDicomData.PatientPosZ));
-             if (lDx > 0) and (lMinDistance = kNaNsingle) then //first value
-                lMinDistance := lDx
-             else if (lDx > 0) and (lDx < lMinDistance) then //if 0 then this is a repeat, not a new slice
-                lMinDistance := lDx
-             else
-                exit;
-end;
-
-procedure readfloats6 (var fp: file; remaining: integer; var lOutStr: string; var lf1, lf2,lf3,lf4,lf5,lf6: double; var lReadOK: boolean);
-var  lDigit : boolean;
-   lItem,li,lLen,n: integer;
-	lfTemp: single;
-	lfStr: string;
-begin
-	lf1 := 0;
-	lf2 := 0;
-	lf3 := 0;
-	lf4 := 0;
-	lf5 := 0;
-	lf6 := 0;
-	lOutStr := '';
-	if e_len = 0 then begin
-	   lReadOK := true;
-	   exit;
-	end;
-	if (dFilePos(fp) > (filesz-remaining)) or (remaining < 1) then begin
-	   lReadOK := false;
-	   exit;
-	end else
-		lReadOK := true;
-	GetMem( buff, e_len);
-	dBlockRead(fp, buff{^}, e_len, n);
-	for li := 0 to e_len-1 do
-		if Char(buff[li]) in [{'/','\', delete: rev18}'e','E','+','-','.','0'..'9']
-		   then lOutStr := lOutStr +(Char(buff[li]))
-		else lOutStr := lOutStr + ' ';
-	FreeMem( buff);
-	li := 1;
-	lLen := length(lOutStr);
- for lItem := 1 to 6 do begin
-	if li > llen then exit;
-	lfStr := '';
-	lLen := length(lOutStr);
-	lDigit := false;
-	repeat
-	  if (lOutStr[li] in ['+','-','e','E','.','0'..'9']) then
-		 lfStr := lfStr + lOutStr[li];
-	  if lOutStr[li] in ['0'..'9'] then lDigit := true;
-	  inc(li);
-	until (li > lLen) or (lDigit);
-	if not lDigit then exit;
-	if li <= li then begin
-	   repeat
-			 if not (lOutStr[li] in ['+','-','e','E','.','0'..'9']) then lDigit := false
-			 else begin
-				  if lOutStr[li] = 'E' then lfStr := lfStr+'e'
-				  else
-					  lfStr := lfStr + lOutStr[li];
-			 end;
-			 inc(li);
-	   until (li > lLen) or (not lDigit);
-	end;
-
-	//QStr(lfStr);
-	try
-	   lftemp := strtofloat(lfStr);
-	except
-		  on EConvertError do begin
-			 Msg('Unable to convert the string '+lfStr+' to a real number');
-			 //lftemp := 0;
-			 exit;
-		  end;
-	end; {except}
-	case lItem of
-		 2: lf2 := lftemp;
-		 3: lf3 := lftemp;
-		 4: lf4 := lftemp;
-		 5: lf5 := lftemp;
-		 6: lf6 := lftemp;
-		 else lf1 := lftemp;
-	end; //case of lItem
-end; //for each of 3 lItems
-end;
-
-function read16( var fp : File; var lReadOK: boolean ): uint16;
-var
-	t1, t2 : uint8;
-  n      : Integer;
-begin
-if dFilePos(fp) > (filesz-2) then begin
-   read16 := 0;
-   lReadOK := false;
-   exit;
-end else
-    lReadOK := true;
-    GetMem( buff, 2);
-    dBlockRead(fp, buff{^}, 2, n);
-    T1 := ord(buff[0]);
-    T2 := ord(buff[1]);
-    freemem(buff);
-    if lDICOMdata.little_endian <> 0
-  	then Result := (t1 + t2*256) AND $FFFF
-  	else Result := (t1*256 + t2) AND $FFFF;
-end;
-
-function  ReadStr(var fp: file; remaining: integer; var lReadOK: boolean; VAR lmaxval:integer) : string;
-var lInc, lN,Val,n: integer;
-	t1, t2 : uint8;
-     lStr : String;
-begin
-lMaxVal := 0;
-if dFilePos(fp) > (filesz-remaining) then begin
-   lReadOK := false;
-   exit;
-end else
-    lReadOK := true;
-    Result := '';
-    lN := remaining div 2;
-    if lN < 1 then exit;
-    lStr := '';
-    for lInc := 1 to lN do begin
-        GetMem( buff, 2);
-        dBlockRead(fp, buff{^}, 2, n);
-        T1 := ord(buff[0]);
-        T2 := ord(buff[1]);
-        freemem(buff);
-        if lDICOMdata.little_endian <> 0 then
-           Val := (t1 + t2*256) AND $FFFF
-        else
-            Val := (t1*256 + t2) AND $FFFF;
-        if lInc < lN then
-           lStr := lStr + inttostr(Val)+ ', '
-        else
-            lStr := lStr + inttostr(Val);
-        if Val > lMaxVal then
-           lMaxVal := Val;
-    end;
-    Result := lStr;
-    if odd(remaining) then begin
-           getmem(buff,1);
-       dBlockRead(fp, buff{t1}, SizeOf(uint8), n);
-           freemem(buff);
-    end;
-end;
-
-(*function  ReadStrABC(var fp: file; remaining: integer; var lReadOK: boolean; VAR lA,lB,lC:integer) : string;
-var lInc, lN,Val,n: integer;
-	t1, t2 : uint8;
-     lStr : String;
-begin
-lA := 0;
-lB := 0;
-lC := 0;
-if dFilePos(fp) > (filesz-remaining) then begin
-   lReadOK := false;
-   exit;
-end else
-    lReadOK := true;
-    Result := '';
-    lN := remaining div 2;
-    if lN < 1 then exit;
-    lStr := '';
-    for lInc := 1 to lN do begin
-        GetMem( buff, 2);
-        dBlockRead(fp, buff{^}, 2, n);
-        T1 := ord(buff[0]);
-        T2 := ord(buff[1]);
-        freemem(buff);
-        if lDICOMdata.little_endian <> 0 then
-           Val := (t1 + t2*256) AND $FFFF
-        else
-            Val := (t1*256 + t2) AND $FFFF;
-        if lInc < lN then
-           lStr := lStr + inttostr(Val)+ ', '
-        else
-            lStr := lStr + inttostr(Val);
-        if lInc = 1 then
-           lA := Val;
-        if lInc = 2 then
-           lB := Val;
-        if lInc = 3 then
-           lC := Val;
-
-
-    end;
-    Result := lStr;
-    if odd(remaining) then begin
-           getmem(buff,1);
-       dBlockRead(fp, buff{t1}, SizeOf(uint8), n);
-           freemem(buff);
-    end;
-end; *)
-
-function  ReadStrHex(var fp: file; remaining: integer; var lReadOK: boolean) : string;
-var lInc, lN,Val,n: integer;
-	t1, t2 : uint8;
-     lStr : String;
-begin
-if dFilePos(fp) > (filesz-remaining) then begin
-   lReadOK := false;
-   exit;
-end else
-    lReadOK := true;
-    Result := '';
-    lN := remaining div 2;
-    if lN < 1 then exit;
-    lStr := '';
-    for lInc := 1 to lN do begin
-         GetMem( buff, 2);
-    dBlockRead(fp, buff, 2, n);
-    T1 := ord(buff[0]);
-    T2 := ord(buff[1]);
-    freemem(buff);
-     if lDICOMdata.little_endian <> 0 then
-        Val := (t1 + t2*256) AND $FFFF
-     else
-         Val := (t1*256 + t2) AND $FFFF;
-     if lInc < lN then lStr := lStr + 'x'+inttohex(Val,4)+ ', '
-     else lStr := lStr + 'x'+inttohex(Val,4);
-    end;
-    Result := lStr;
-    if odd(remaining) then begin
-       getmem(buff,1);
-       dBlockRead(fp, {t1}buff, SizeOf(uint8), n);
-       freemem(buff);
-    end;
-end;
-function SomaTomFloat: double;
-var lSomaStr: String;
-begin
-     //dSeek(fp,5992); //Slice Thickness from 5790 "SL   3.0"
-     //dSeek(fp,5841); //Field of View from 5838 "FoV   281"
-     //dSeek(fp,lPos);
-     lSomaStr := '';
-     tx[0] := 'x';
-     while (length(lSomaStr) < 64) and (tx[0] <> chr(0))  and (tx[0] <> '/') do begin
-                dBlockRead(fp, tx, 1, n);
-                if tx[0] in ['+','-','.','0'..'9','e','E'] then
-                   lSomaStr := lSomaStr + tx[0];
-     end;
-     if length(lSOmaStr) > 0 then
-        result := StrToFloat(lSomaStr)
-     else
-         result := 0;
-end;
-
-function PGMreadInt: integer;
-//reads integer from PGM header, disregards comment lines (which start with '#' symbol);
-var lStr: string;
-    lDigit: boolean;
-
-begin
-    Result := 1;
-    lStr := '';
-    repeat
-          dBlockRead(fp, tx, 1, n);
-          if tx[0] = '#' then begin //comment
-             repeat
-                   dBlockRead(fp, tx, 1, n);
-             until (ord(tx[0]) = $0A) or (dFilePos(fp) > (filesz-4)); //eoln indicates end of comment
-          end; //finished reading comment
-          if tx[0] in ['0'..'9'] then begin
-             lStr := lStr + tx[0];
-             lDigit := true;
-          end else
-              lDigit := false;
-    until ((lStr <> '') and (not lDigit)) or (dFilePos(fp) > (filesz-4)); //read digits until you hit whitespace
-    if lStr <> '' then
-       Result := strtoint(lStr);
-
-     {lStr := '';
-     tx[0] := 'x';
-     while (length(lStr) < 64) and (ord(tx[0]) <> $0A) do begin
-                dBlockRead(fp, tx, 1, n);
-                if tx[0] in ['#','+','-','.','0'..'9','e','E',' ','a'..'z','A'..'Z'] then
-                   lStr := lStr + tx[0];
-     end;
-     result := lStr;    }
-end;
-
-function read32 ( var fp : File; var lReadOK: boolean ): uint32;
-var
-	t1, t2, t3, t4 : byte;
-  n : Integer;
-begin
-if dFilePos(fp) > (filesz-4) then begin
-   Read32 := 0;
-   lReadOK := false;
-   exit;
-end else
-    lReadOK := true;
-    GetMem( buff, 4);
-    dBlockRead(fp, buff{^}, 4, n);
-    T1 := ord(buff[0]);
-    T2 := ord(buff[1]);
-    T3 := ord(buff[2]);
-    T4 := ord(buff[3]);
-    freemem(buff);
-    if lDICOMdata.little_endian <> 0 then
-        Result := t1 + (t2 shl 8) + (t3 shl 16) + (t4 shl 24)
-    else
-        Result := t4 + (t3 shl 8) + (t2 shl 16) + (t1 shl 24)
-    //if lDICOMdata.little_endian <> 0
-    //then Result := (t1 + t2*256 + t3*256*256 + t4*256*256*256) AND $FFFFFFFF
-    //else Result := (t1*256*256*256 + t2*256*256 + t3*256 + t4) AND $FFFFFFFF;
-end;
-
-function read32r ( var fp : File; var lReadOK: boolean ): single; //1382
-type
-  swaptype = packed record
-    case byte of
-      0:(Word1,Word2 : word); //word is 16 bit
-      1:(float:single);
-  end;
-  swaptypep = ^swaptype;
-var
-   s:single;
-  inguy:swaptypep;
-  outguy:swaptype;
-begin
-  if dFilePos(fp) > (filesz-4) then begin
-     read32r := 0;
-     lReadOK := false;
-     exit;
-  end else
-  lReadOK := true;
-    //GetMem( buff, 8);
-  dBlockRead(fp, @s, 4, n);
-  inguy := @s; //assign address of s to inguy
-  if lDICOMdata.little_endian <> 1 then begin
-     outguy.Word1 := swap(inguy^.Word2);
-     outguy.Word2 := swap(inguy^.Word1);
-  end else
-      outguy.float  := s; //1382 read64 needs to handle little endian in this way as well...
-  read32r:=outguy.float;
-end;
-
-function read64 ( var fp : File; var lReadOK: boolean ): double;
-type
-  swaptype = packed record
-    case byte of
-      0:(Word1,Word2,Word3,Word4 : word); //word is 16 bit
-      1:(float:double);
-  end;
-  swaptypep = ^swaptype;
-var
-   s:double;
-  inguy:swaptypep;
-  outguy:swaptype;
-begin
-  if dFilePos(fp) > (filesz-8) then begin
-     Read64 := 0;
-     lReadOK := false;
-     exit;
-  end else
-    lReadOK := true;
-    //GetMem( buff, 8);
-  dBlockRead(fp, @s, 8, n);
-  inguy := @s; //assign address of s to inguy
-  if lDICOMdata.little_endian <> 1 then begin
-     outguy.Word1 := swap(inguy^.Word4);
-     outguy.Word2 := swap(inguy^.Word3);
-     outguy.Word3 := swap(inguy^.Word2);
-     outguy.Word4 := swap(inguy^.Word1);
-  end else
-      outguy.float := inguy^.float; //1382
-  read64:=outguy.float;
-end;
-
-//magma
-function SafeStrToInt(var lInput: string): integer;
-var li,lLen: integer;
-begin
-     result := 0;
-              lLen := length(lInput);
-              lStr := '';
-              if lLen < 1 then exit;
-              for li := 1 to lLen do
-                 if lInput[li] in ['+','-','0'..'9']
-                     	then lStr := lStr +lInput[li];
-              Val(lStr,li,lErr);
-              if lErr = 0 then
-               result := lI;//strtoint(lStr);
-end;
-
-
-procedure DICOMHeaderStringToInt (var lInput: integer);
-var li: integer;
-begin
-              t := _string;
-              lStr := '';
-              if dFilePos(fp) > (filesz-e_len) then exit;//goto 666;
-              GetMem( buff, e_len);
-              dBlockRead(fp, buff{^}, e_len, n);
-              for li := 0 to e_len-1 do
-                   	if Char(buff[li]) in ['+','-','0'..'9']
-                     	then lStr := lStr +(Char(buff[li]));
-              FreeMem( buff);
-              Val(lStr,li,lErr);
-              if lErr = 0 then lInput := li;//strtoint(lStr);
-              remaining := 0;
-              tmp := lInput;
-end;
-
-procedure DICOMHeaderString (var lInput: kDICOMStr);
-var li,lStartPos: integer;
-begin
-     t := _string;
-             lStartPos := dFilePos(fp);
-             lInput := '';
-             if e_len < 1 then exit; //DICOM: should always be even
-             GetMem( buff, e_len);
-             dBlockRead(fp, buff{^}, e_len, n);
-             for li := 0 to e_len-1 do
-                   	if Char(buff[li]) in ['+','-','/','\',' ','0'..'9','a'..'z','A'..'Z'] then
-                            lInput :=  lInput +(Char(buff[li]))
-                   	else {if (buff[i] = 0) then}
-                             lInput :=  lInput +' ';
-
-              FreeMem( buff);
-              dseek(fp, lStartPos);
-end;
-procedure DICOMHeaderStringTime (var lInput: kDICOMstr);
-var li,lStartPos: integer;
-begin
-     t := _string;
-             lStartPos := dFilePos(fp);
-             lInput := '';
-             if e_len < 1 then exit; //DICOM: should always be even
-             GetMem( buff, e_len);
-             dBlockRead(fp, buff{^}, e_len, n);
-             for li := 0 to e_len-1 do
-                   	if Char(buff[li]) in ['+','-','/','\',' ','0'..'9','a'..'z','A'..'Z','.'] then
-                            lInput :=  lInput +(Char(buff[li]))
-                   	else if li <> (e_len-1) then
-                             lInput :=  lInput +':'
-                        else
-                            lInput :=  lInput +' ';
-
-              FreeMem( buff);
-              dseek(fp, lStartPos);
-end;
-label 1234;
-var lIndent: integer;
-  lprevGroup, lprevElement: uint32;
-var lInside00209113, lInside2005140F, lPhilipsWarning: boolean;//philips can list two DIFFERENT spatial positions per slice - ignore the one hidden inside 2005,140FlPrev0020: boolean;
-begin
-  //Init
-  //for lnVol := 1 to kMaxOrderVal do
-  //    lDICOMdata.OrderSlope[lDICOMdata.nOrder] := 0; //show this was not set
-  lInside00209113 := false;
-  lprevGroup := 0;
-  lprevElement := 0;
-  lPhilipsWarning := false;
-  lIndent := 0;
-  lInside2005140F := false;
-  lSwitchToImplicitAfterGroup0002 := false;
-  lGELX := false;
-  lByteSwap := false;
-  Clear_Dicom_Data(lDicomData);
-  Clear_Dicom_Data(lDICOMdataBackUp);
-  lDicomData.XYZdim[1] := 1;
-  lImagePositionPatientRead := false;// for 4D files, we need first volume
-  l4DDistanceBetweenSliceCenters := kNaNsingle;
-  lEchoNum := 0;
-  lThickness := 0;
-  lTestError := false;
-  lPhilipsScaleSlope := 0;
-  lManufacturerIsPhilips := false;
-  lManufacturerIsBruker := false;
-  lnVol := 0;
-  lnSlicePerVol := 0;
-  lResearchMode := false;
-  lMatrixSz := 0;
-  lPhaseEncodingSteps := 0;
-  lSiemensMosaic0008_0008 := false;
-  lMediface0002_0013 := false;//false wblate
-  lOldSiemens_IncorrectMosaicMM := false;
-  lCacheStart := 0;
-  lDiskCacheSz := 0;
-  lDynStr:= '';
-  lJPEGEntries := 0;
-  first_one    := true;
-  info := '';
-  lGrp:= false;
-  lBigSet := false;
-  lDICM_at_128 := false; //no DICOM signature
-  lFirstFragment := true;
-  lTextOverFlow := false;
-  lImageFormatOK := true;
-  lHdrOK := false;
-  //if lverboseRead then msg('xxx'+lFileName);
-  if not fileexists(lFileName) then begin
-     lImageFormatOK := false;
-     exit;
-  end;
-  //if lverboseRead then msg('zzzzz000000000');
-  TmpStr := string(StrUpper(PChar(ExtractFileExt(lFileName))));
-  lStr :='';
-  if TmpStr = '.FDF' then begin
-     if FDF( lFileName, lDicomData) then begin
-        lHdrOK := true;
-        lImageFormatOK := true;
-        exit;
-     end;
-  end;
-  if (TmpStr = '.REC') then begin //1417z: check in Unix: character upper/lower case may matter
-        lStr := changefileext(lFilename,'.par');
-        if fileexists(lStr) then
-                lFilename := lStr
-        else begin //Linux is case sensitive 1382...
-                lStr := changefileext(lFilename,'.PAR');
-                if fileexists(lStr) then
-                        lFilename := lStr
-        end;
-  end;
-  if (TmpStr = '.BRIK') then begin //1417z: check in Unix: character upper/lower case may matter
-        lStr := changefileext(lFilename,'.HEAD');
-        if fileexists(lStr) then lFilename := lStr;
-  end;
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  FIleSz := FileSize(fp);
-  if fileSz < 1 then begin
-     lImageFormatOK := false;
-     exit;
-  end;
-     lDICOMdata.Little_Endian := 1;
-  if FileSz > 200 then begin
-     dseek(fp, {0}128);
-    dBlockRead(fp, tx, 4*SizeOf(Char), n);
-     if (tx[0] = 'D') and (tx[1] = 'I') and (tx[2] = 'C') and (tx[3] = 'M') then
-        lDICM_at_128 := true;
-  end;//filesize > 200: check for 'DICM' at byte 128 - DICOM signature
-  if (lAutoDetectGenesis) and (FileSz > (5820{114+35+4})) then begin
-     dseek(fp, 0);
-     if (ord(tx[0])=206) and (ord(tx[1])=250) then begin
-        //Elscint format signature: check height and width to make sure
-
-           dseek(fp, 370);
-           group   := read16(fp,lrOK);//Width
-           dseek(fp, 372);
-           element := read16(fp,lrOK);//Ht
-           if ((Group=160) or(Group =256) or (Group= 340) or (Group=512) or (group =640)) and
-           ((element=160) or (element =256) or (element= 340) or (element=512) ) then begin
-                     CloseFile(fp);
-                     if lDiskCacheSz > 0 then
-                        freemem(lDiskCacheRA);
-                     FileMode := 2; //set to read/write
-                     read_elscint_data(lDICOMdata, lHdrOK, lImageFormatOK,lDynStr,lFileName);
-                     exit;
-           end; //confirmed: Elscint
-     end;
-     lGenesis := false;
-     if ((tx[0] <> 'I') OR (tx[1] <> 'M') OR (tx[2] <> 'G') OR (tx[3] <> 'F')) then begin {DAT format}
-        {if (FileSz > 114+305+4) then begin
-           dseek(fp, 114+305);
-           dBlockRead(fp, tx, 3*SizeOf(Char), n);
-           if ((tx[0]='M') and (tx[1] = 'R')) or ((tx[0] = 'C') and(tx[1] = 'T')) then
-              lGenesis := true;
-        end;}
-     end else
-         lGenesis := true;
-     if (not lGenesis) and (FileSz > 3252) then begin
-        dseek(fp, 3240);
-        dBlockRead(fp, tx, 4*SizeOf(Char), n);
-        if ((tx[0] = 'I') AND (tx[1] = 'M')AND (tx[2] = 'G') AND (tx[3] = 'F')) then
-           lGenesis := true;
-        if (not lGenesis) then begin
-           dseek(fp, 3178);
-           dBlockRead(fp, tx, 4*SizeOf(Char), n);
-           if ((tx[0] = 'I') AND (tx[1] = 'M')AND (tx[2] = 'G') AND (tx[3] = 'F')) then
-              lGenesis := true;
-        end;
-        if (not lGenesis) then begin
-           dseek(fp, 3180);
-           dBlockRead(fp, tx, 4*SizeOf(Char), n);
-           if ((tx[0] = 'I') AND (tx[1] = 'M')AND (tx[2] = 'G') AND (tx[3] = 'F')) then
-              lGenesis := true;
-        end;
-        if (not lGenesis) then begin //1499K
-           dseek(fp, 0);
-           dBlockRead(fp, tx, 4*SizeOf(Char), n);
-           if ((tx[0] = 'I') AND (tx[1] = 'M')AND (tx[2] = 'G') AND (tx[3] = 'F')) then
-              lGenesis := true;
-        end;
-
-     end;
-     if (not lGenesis) and (FileSz > 3252) then begin
-           dseek(fp, 3228);
-           dBlockRead(fp, tx, 4*SizeOf(Char), n);
-           if (tx[0] = 'I') AND (tx[1]= 'M') AND (tx[2] = 'G')AND (tx[3]= 'F') then
-              lGenesis := true;
-     end;
-     if lGenesis then begin
-        CloseFile(fp);
-        if lDiskCacheSz > 0 then
-           freemem(lDiskCacheRA);
-        FileMode := 2; //set to read/write
-        read_ge_data(lDICOMdata, lHdrOK, lImageFormatOK,lDynStr,lFileName);
-        exit;
-     end;
-  end; //AutodetectGenesis                        xxDCIM
-
-  if (lAutoDetectInterfile) and (FileSz > 256) and (not lDICM_at_128) then begin
-     if Copy(extractfilename(lFileName), 1, 4) = 'COR-' then begin
-        lStr := extractfiledir(lFilename) + '\COR-.info';
-        TmpStr := extractfiledir(lFilename) + '\COR-128';
-        if fileexists(lStr) and fileexists(TmpStr) then begin
-           lFilename := TmpStr;
-           lDynStr                        := 'FreeSurfer COR format' + kCR+'Only displaying image 128'+kCR+'Use MRIcro''s Import menu to convert this image'+kCR;
-           with lDicomData do begin
-                little_endian       := 0; // don't care
-                ImageStart          := 0;
-                Allocbits_per_pixel := 8;
-                XYZdim[1]           := 256;
-                XYZdim[2]           := 256;
-                XYZdim[3]           := 1;
-                XYZmm[1]            := 1;
-                XYZmm[2]            := 1;
-                XYZmm[3]            := 1;
-                //xStoredbits_per_pixel:= Allocbits_per_pixel;
-           END; //WITH
-           lHdrOK                         := True;
-           lImageFormatOK                 := True;
-           exit;
-        end; //COR-.info file exists
-     end; //if filename is COR-
-     //start TIF
-     //TIF IMAGES DO NOT ALWAYS HAVE EXTENSION if (TmpStr = '.TIF') or (TmpStr = '.TIFF') then begin
-        dseek(fp, 0);
-        lWord   := read16(fp,lrOK);
-        if lWord = $4d4d then
-           lDICOMdata.little_endian := 0
-        else if lWord = $4949 then lDICOMdata.little_endian := 1;
-        //dseek(fp, 2);
-        lWord2   := read16(fp,lrOK); //bits per pixel
-        if ((lWord=$4d4d) or (lWord=$4949)) and (lWord2 = $002a) then begin
-           CloseFile(fp);
-           if lDiskCacheSz > 0 then
-              freemem(lDiskCacheRA);
-           FileMode := 2; //set to read/write
-           read_tiff_data(lDICOMdata, lReadECAToffsetTables, lHdrOK, lImageFormatOK, lDynStr, lFileName);
-           //if lHdrOk then exit;
-           exit;
-        end;//TIF signature
-     //end; //.TIF extension
-     //end TIF
-     //start BMP 1667
-     TmpStr := string(StrUpper(PChar(ExtractFileExt(lFileName))));
-     if TmpStr = '.BMP' then begin
-        dseek(fp, 0);
-        lWord   := read16(fp,lrOK);
-        dseek(fp, 28);
-        lWord2   := read16(fp,lrOK); //bits per pixel
-        if (lWord=19778) and (lWord2 = 8) then begin //bitmap signature
-           dseek(fp, 10);
-           lDicomData.ImageStart := read32(fp,lrOK);//1078;
-           dseek(fp, 18);
-           lDicomData.XYZdim[1] := read32(fp,lrOK);
-           //dseek(fp, 22);
-           lDicomData.XYZdim[2] := read32(fp,lrOK);
-           lDicomData.XYZdim[3] := 1;//read16(fp,lrOK);
-           lDicomData.Allocbits_per_pixel := 8;//bits
-           //xlDicomData.Storedbits_per_pixel:= lDicomData.Allocbits_per_pixel;
-           lDynStr := 'BMP format';
-           CloseFile(fp);
-           if lDiskCacheSz > 0 then
-              freemem(lDiskCacheRA);
-           FileMode := 2; //set to read/write
-           lHdrOK := true;
-           lImageFormatOK:= true;
-           exit;
-        end;//bmp signature
-     end; //.BMP extension
-     //end BMP
-     if TmpStr = '.VOL' then begin //start SPACE vol format 1382
-        dseek(fp, 0);
-        dBlockRead(fp, tx, 6*SizeOf(Char), n);
-        if (tx[0] = 'm') and (tx[1] = 'd') and (tx[2] = 'v') and (tx[3] = 'o') and (tx[4] = 'l') and (tx[5] = '1') then begin
-           lDicomData.ImageStart := read32(fp,lrOK);//1078;
-           lDICOMdata.little_endian := 1;
-           lDicomData.XYZdim[1] := read32(fp,lrOK);
-           lDicomData.XYZdim[2] := read32(fp,lrOK);
-           lDicomData.XYZdim[3] := read32(fp,lrOK);
-           lDicomData.XYZmm[1] := read32r(fp,lrOK);
-           lDicomData.XYZmm[2] := read32r(fp,lrOK);
-           lDicomData.XYZmm[3] := read32r(fp,lrOK);
-           lDicomData.Allocbits_per_pixel := 8;//bits
-           //xlDicomData.Storedbits_per_pixel:= lDicomData.Allocbits_per_pixel;
-           lDynStr := 'Space VOL format';
-           CloseFile(fp);
-           if lDiskCacheSz > 0 then
-              freemem(lDiskCacheRA);
-           FileMode := 2; //set to read/write
-           lHdrOK := true;
-           lImageFormatOK:= true;
-           exit;
-        end;//vol signature
-     end; //.VOL extension
-     //end space .VOL format
-     //start DF3 PovRay DF3 density files
-     if (TmpStr = '.DF3') then begin
-        dseek(fp, 0);
-        lWord   := swap (read16(fp,lrOK));
-        lWord2   := swap (read16(fp,lrOK));
-        lWord3  := swap (read16(fp,lrOK));
-        //note: I assume all df3 headers are little endian. is this always true? if not, unswapped values could be tested for filesize
-        lMatrixSz := (lWord*lWord2*lWord3)+6;
-        if (lMatrixSz=FileSz)then begin //df3 signature
-           lDicomData.ImageStart := 6;//1078;
-           lDicomData.XYZdim[1] := lWord;
-           //dseek(fp, 22);
-           lDicomData.XYZdim[2] := lWord2;
-           lDicomData.XYZdim[3] := lWord3;
-           lDicomData.Allocbits_per_pixel := 8;//bits
-           //xlDicomData.Storedbits_per_pixel:= lDicomData.Allocbits_per_pixel;
-           CloseFile(fp);
-           if lDiskCacheSz > 0 then
-              freemem(lDiskCacheRA);
-           FileMode := 2; //set to read/write
-           lDynStr := 'PovRay DF3 density format';
-           lHdrOK := true;
-           lImageFormatOK:= true;
-           exit;
-        end;//df3 signature
-     end;
-     //end df3
-
-     //start .PGM
-     if (TmpStr = '.PGM') or (TmpStr = '.PPM') then begin
-        dseek(fp, 0);
-        lWord   := read16(fp,lrOK);
-        if (lWord=13648){'P5'=1x8BIT GRAYSCALE} or (lWord=13904) {'P6'=3x8bit RGB} then begin //bitmap signature
-          {repeat
-                PGMreadStr(lDicomData.XYZdim[1],lDicomData.XYZdim[2]);
-          until (lDicomData.XYZdim[2] > 0) ;}
-          lDicomData.XYZdim[1] := PGMreadInt;
-          lDicomData.XYZdim[2] := PGMreadInt;
-          PGMreadInt; //read maximum value
-
-           lDicomData.XYZdim[3] := 1;//read16(fp,lrOK);
-           lDicomData.Allocbits_per_pixel := 8;//bits
-           //xlDicomData.Storedbits_per_pixel:= lDicomData.Allocbits_per_pixel;
-           lDicomData.ImageStart := dFilepos(fp);
-          if lWord = 13904 then begin//RGB
-             //xlDicomData.SamplesPerPixel := 3;
-             //xlDicomData.PlanarConfig := 0;//RGBRGBRGB..., not RRR..RGGG..GBBB...B
-          end;
-           lDynStr:='PGM/PPM format 8-bit grayscale image [data saved in binary, not ASCII format]';
-           CloseFile(fp);
-           if lDiskCacheSz > 0 then
-              freemem(lDiskCacheRA);
-           FileMode := 2; //set to read/write
-           lHdrOK := true;
-           lImageFormatOK:= true;
-           exit;
-        end else if (lWord=12880){'P2'=1x8BIT ASCII} or (lWord=13136) {'P3'=3x8bit ASCI} then begin
-            Msg('Warning: this image appears to be an ASCII ppm/pgm image. This software can only read binary ppm/pgm images');
-        end;//pgm/ppm binary signature signature
-     end; //.PPM/PGM extension
-
-     //end .pgm
-
-     //start BioRadPIC 1667
-     if TmpStr = '.PIC' then begin
-        dseek(fp, 54);
-        lWord   := read16(fp,lrOK);
-        if (lWord=12345) then begin
-           CloseFile(fp);
-           if lDiskCacheSz > 0 then
-              freemem(lDiskCacheRA);
-           FileMode := 2; //set to read/write
-           read_biorad_data(lDICOMdata, lHdrOK, lImageFormatOK,lDynStr,lFileName);
-           exit;
-        end;//biorad signature
-     end; //.PIC extension biorad?
-     //end BIORAD PIC
-     if TmpStr = '.HEAD' then begin
-        read_afni_data(lDICOMdata, lHdrOK, lImageFormatOK, lDynStr, lFileName,lRot1,lRot2,lRot3);
-        if (lHdrOK) and (lImageFormatOK) then begin
-           CloseFile(fp);
-           if lDiskCacheSz > 0 then
-              freemem(lDiskCacheRA);
-           FileMode := 2; //set to read/write
-           exit;
-        end;
-     end;
-     dseek(fp, 0);
-     dBlockRead(fp, tx, 20*SizeOf(Char), n);
-     if (tx[0] = 'n') and (tx[1] = 'c') and (tx[2] = 'a') and (tx[3] = 'a') then begin
-         //SUN Vision File Format = .vff
-        CloseFile(fp);
-        if lDiskCacheSz > 0 then
-           freemem(lDiskCacheRA);
-        FileMode := 2; //set to read/write
-        read_vff_data(lDICOMdata, lHdrOK, lImageFormatOK, lDynStr, lFileName);
-        exit;
-     end;
-     liPos := 1;
-     lStr :='';
-     {999 While (liPos <= 20) and (lStr <> 'INTERFILE') do begin
-        if tx[liPos] in ['i','n','t','e','r', 'f','i','l','e','I','N','T','E','R', 'F','I','L','E'] then
-           lStr := lStr+upcase(tx[liPos]);
-        inc(liPos);
-     end; }
-     if lStr = 'INTERFILE' then begin
-        CloseFile(fp);
-        if lDiskCacheSz > 0 then
-           freemem(lDiskCacheRA);
-        FileMode := 2; //set to read/write
-        read_interfile_data(lDICOMdata, lHdrOK, lImageFormatOK, lDynStr, lFileName);
-        if lHdrOk then exit;
-        exit;
-     end; //'INTERFILE' in first 20 char
-  end;//detectint
-  // try DICOM part 10 i.e. a 128 byte file preamble followed by "DICM"
-  if filesz <= 300 then goto 666;
-  {begin siemens somatom: DO THIS BEFORE MAGNETOM: BOTH HAVE 'SIEMENS' SIGNATURE, SO CHECK FOR 'SOMATOM'}
-  if filesz = 530432 then begin
-     dseek(fp, 281);
-     dBlockRead(fp, tx, 8*SizeOf(Char), n);
-     if (tx[0] = 'S') and (tx[1] = 'O') and (tx[2] = 'M') and (tx[3] = 'A') and (tx[4] = 'T') and (tx[5] = 'O') and (tx[6] = 'M') then begin
-        lDicomData.ImageStart := 6144;
-        lDicomData.Allocbits_per_pixel := 16;
-        //xlDicomData.Storedbits_per_pixel := 16;
-        lDicomData.little_endian := 0;
-        lDicomData.XYZdim[1] := 512;
-        lDicomData.XYZdim[2] := 512;
-        lDicomData.XYZdim[3] := 1;
-        dSeek(fp,5999); //Study/Image from 5292 "STU/IMA   1070/16"
-        lDicomData.AcquNum := trunc(SomaTomFloat);//Slice Thickness from 5790 "SL   3.0"
-        lDicomData.ImageNum := trunc(SomaTomFloat);//Slice Thickness from 5790 "SL   3.0"
-        dSeek(fp,5792); //Slice Thickness from 5790 "SL   3.0"
-        lDicomData.XYZmm[3] := SomaTomFloat;//Slice Thickness from 5790 "SL   3.0"
-        dSeek(fp,5841); //Field of View from 5838 "FoV   281"
-        lDicomData.XYZmm[1] := SomaTomFloat; //Field of View from 5838 "FoV   281"
-        lDicomData.XYZmm[2] := lDicomData.XYZmm[1]/lDicomData.XYZdim[2];//do mm[2] first before FOV is overwritten
-        lDicomData.XYZmm[1] := lDicomData.XYZmm[1]/lDicomData.XYZdim[1];
-        if lVerboseRead then
-           lDynStr := 'Siemens Somatom Format'+kCR+
-           'Image Series/Number: '+inttostr(lDicomData.AcquNum)+'/'+inttostr(lDicomData.ImageNum)+kCR+
-           'XYZ dim:' +inttostr(lDicomData.XYZdim[1])+'/'
-           +inttostr(lDicomData.XYZdim[2])+'/'+inttostr(lDicomData.XYZdim[3])
-           +kCR+'XYZ mm:'+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)+'/'
-           +floattostrf(lDicomData.XYZmm[2],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2);
-        CloseFile(fp);
-        if lDiskCacheSz > 0 then
-           freemem(lDiskCacheRA);
-        FileMode := 2; //set to read/write
-        lImageFormatOK := true;
-        lHdrOK := true;
-        exit;
-     end; //signature found
-  end; //correctsize for somatom
-  {end siemens somatom}
-
-{siemens magnetom}
-  dseek(fp,96);
-  dBlockRead(fp, tx, 7*SizeOf(Char), n);
-  if (tx[0] = 'S') and (tx[1] = 'I') and (tx[2] = 'E') and (tx[3] = 'M') and (tx[4] = 'E') and (tx[5] = 'N') and (tx[6] = 'S') then begin
-        CloseFile(fp);
-        if lDiskCacheSz > 0 then
-           freemem(lDiskCacheRA);
-        FileMode := 2; //set to read/write
-        read_siemens_data(lDICOMdata, lHdrOK, lImageFormatOK, lDynStr, lFileName);
-        exit;
-  end;
-  {end siemens magnetom vision}
-  {siemens somatom plus}
-     dseek(fp, 0);
-     dBlockRead(fp, tx, 8*SizeOf(Char), n);
-  if (tx[0] = 'S') and (tx[1] = 'I') and (tx[2] = 'E') and (tx[3] = 'M') and (tx[4] = 'E') and (tx[5] = 'N') and (tx[6] = 'S') then begin
-        lDicomData.ImageStart := 8192;
-        lDicomData.Allocbits_per_pixel := 16;
-        //xlDicomData.Storedbits_per_pixel := 16;
-        lDicomData.little_endian := 0;
-        dseek(fp, 1800); //slice thickness
-        lDicomData.XYZmm[3] := read64(fp,lrOK);
-        dseek(fp, 4100);
-        lDicomData.AcquNum := read32(fp,lrOK);
-        dseek(fp, 4108);
-        lDicomData.ImageNum := read32(fp,lrOK);
-        dseek(fp, 4992); //X FOV
-        lDicomData.XYZmm[1] := read64(fp,lrOK);
-        dseek(fp, 5000); //Y FOV
-        lDicomData.XYZmm[2] := read64(fp,lrOK);
-        dseek(fp, 5340);
-        lDicomData.XYZdim[1] := read32(fp,lrOK);
-        dseek(fp, 5344);
-        lDicomData.XYZdim[2] := read32(fp,lrOK);
-        lDicomData.XYZdim[3] := 1;
-        if lDicomData.XYZdim[1] > 0 then
-           lDicomData.XYZmm[1] := lDicomData.XYZmm[1]/lDicomData.XYZdim[1];
-        if lDicomData.XYZdim[2] > 0 then
-           lDicomData.XYZmm[2] := lDicomData.XYZmm[2]/lDicomData.XYZdim[2];
-        if lVerboseRead then
-           lDynStr := 'Siemens Somatom Plus Format'+kCR+
-     'Image Series/Number: '+inttostr(lDicomData.AcquNum)+'/'+inttostr(lDicomData.ImageNum)+kCR+
-     'XYZ dim:' +inttostr(lDicomData.XYZdim[1])+'/'
-     +inttostr(lDicomData.XYZdim[2])+'/'+inttostr(lDicomData.XYZdim[3])
-     +kCR+'XYZ mm:'+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)+'/'
-     +floattostrf(lDicomData.XYZmm[2],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2);
-
-        CloseFile(fp);
-        if lDiskCacheSz > 0 then
-           freemem(lDiskCacheRA);
-        FileMode := 2; //set to read/write
-        lImageFormatOK := true;
-        lHdrOK := true;
-        exit;
-  end;
-  {end siemens somatom plus }
-  {picker}
-  dseek(fp,0);
-  dBlockRead(fp, tx, 8*SizeOf(Char), n);
-  if (tx[0]='C') and (tx[1]='D') and (tx[2]='F') and (ord(tx[3]) = 1) then begin
-        CloseFile(fp);
-        if lDiskCacheSz > 0 then
-           freemem(lDiskCacheRA);
-        FileMode := 2; //set to read/write
-        read_minc_data(lDICOMdata, lHdrOK, lImageFormatOK,lDynStr,lFileName);
-        exit;
-  end;
-  if (lAutoDECAT7) and (tx[0]='M') and (tx[1]='A') and (tx[2]='T') and (tx[3]='R') and (tx[4]='I') and (tx[5]='X') then begin
-        CloseFile(fp);
-        if lDiskCacheSz > 0 then
-           freemem(lDiskCacheRA);
-        FileMode := 2; //set to read/write
-        read_ecat_data(lDICOMdata, lVerboseRead,lReadECAToffsetTables,lHdrOK, lImageFormatOK, lDynStr, lFileName);
-        exit;
-  end;
-  if (tx[0] = '*') AND (tx[1] = '*') AND (tx[2] = '*') AND (tx[3] = ' ') then begin {picker Standard}
-        CloseFile(fp);
-        if lDiskCacheSz > 0 then
-           freemem(lDiskCacheRA);
-        FileMode := 2; //set to read/write
-        read_picker_data(lVerboseRead,lDICOMdata, lHdrOK, lImageFormatOK, lDynStr, lFileName);
-        exit;
-  end; {not picker standard}
-  //Start Picker Prism
-  ljunk := filesz-2048;
-  lDICOMdata.little_endian := 0;
-  //start: read x
-  dseek(fp, 322);
-  Width := read16(fp,lrOK);
-
-  //start: read y
-  dseek(fp, 326);
-  Ht := read16(fp,lrOK);
-  lMatrixSz := Width * Ht;
-
-  //check if correct filesize for picker prism
-  if (ord(tx[0]) = 1) and (ord(tx[1])=2) and ((ljunk mod lMatrixSz)=0){128*128*2bytes = 32768} then begin //Picker PRISM
-      lDicomData.little_endian := 0;
-      lDicomData.XYZdim[1] := Width;
-      lDicomData.XYZdim[2] := Ht;
-      lDicomData.XYZdim[3] := (ljunk div 32768);  {128*128*2bytes = 32768}
-      lDicomData.Allocbits_per_pixel := 16;
-      //xlDicomData.Storedbits_per_pixel := 16;
-      lDicomData.ImageStart := 2048;
-      //start: read slice thicness
-      dseek(fp,462);
-      dBlockRead(fp, tx, 12*SizeOf(Char), n);
-      lStr := '';
-      for ljunk := 0 to 11 do
-         if tx[ljunk] in ['0'..'9','.'] then
-            lStr := lStr+ tx[ljunk];
-      if lStr <> '' then
-         lDicomData.XYZmm[3] := strtofloat(lStr);
-      //start: voxel size
-      dseek(fp,594);
-      dBlockRead(fp, tx, 12*SizeOf(Char), n);
-      lStr := '';
-      for ljunk := 0 to 11 do
-         if tx[ljunk] in ['0'..'9','.'] then
-            lStr := lStr+ tx[ljunk];
-      if lStr <> '' then
-         lDicomData.XYZmm[1] := strtofloat(lStr);
-      lDicomData.XYZmm[2] := lDicomData.XYZmm[1];
-      //end: read voxel sizes
-      //start: patient name
-      dseek(fp,26);
-      dBlockRead(fp, tx, 22*SizeOf(Char), n);
-      lStr := '';
-      ljunk := 0;
-      while (ljunk < 22) and (ord(tx[ljunk]) <> 0) do begin
-            lStr := lStr+ tx[ljunk];
-            inc(ljunk);
-      end;
-      lDicomData.PatientName := lStr;
-      //start: patient ID
-      dseek(fp,48);
-      dBlockRead(fp, tx, 15*SizeOf(Char), n);
-      lstr := '';
-      ljunk := 0;
-      while (ljunk < 15) and (ord(tx[ljunk]) <> 0) do begin
-            lstr := lstr+ tx[ljunk];
-            inc(ljunk);
-      end;
-      //xlDicomData.PatientID := lStr;
-      //start: scan time
-      dseek(fp,186);
-      dBlockRead(fp, tx, 25*SizeOf(Char), n);
-      lstr := '';
-      ljunk := 0;
-      while (ljunk < 25) and (ord(tx[ljunk]) <> 0) do begin
-            lstr := lstr+ tx[ljunk];
-            inc(ljunk);
-      end;
-      //start: scanner type
-      dseek(fp,2);
-      dBlockRead(fp, tx, 25*SizeOf(Char), n);
-      lgrpstr := '';
-      ljunk := 0;
-      while (ljunk < 25) and (ord(tx[ljunk]) <> 0) do begin
-            lgrpstr := lgrpstr+ tx[ljunk];
-            inc(ljunk);
-      end;
-      //report results
-        if lVerboseRead then
-           lDynStr := 'Picker Format '+lgrpstr+kCR+
-             'Patient Name: '+lDicomData.PatientName+kCR+
-             //x'Patient ID: '+lDicomData.PatientID+kCR+
-             'Scan Time: '+lStr+kCR+
-     'XYZ dim:' +inttostr(lDicomData.XYZdim[1])+'/'
-     +inttostr(lDicomData.XYZdim[2])+'/'+inttostr(lDicomData.XYZdim[3])
-     +kCR+'XYZ mm:'+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)+'/'
-     +floattostrf(lDicomData.XYZmm[2],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2);
-        CloseFile(fp);
-        if lDiskCacheSz > 0 then
-           freemem(lDiskCacheRA);
-        FileMode := 2; //set to read/write
-        lImageFormatOK := true;
-        lHdrOK := true;
-        exit;
-
-  end; //end Picker PRISM
-    lMatrixSz := 0;
-
-  lDICOMdata.little_endian := 1;
-  lBig := false;
-  dseek(fp, {0}128);
-  //where := FilePos(fp);
-  dBlockRead(fp, tx, 4*SizeOf(Char), n);
-  if (tx[0] <> 'D') OR (tx[1] <> 'I') OR (tx[2] <> 'C') OR (tx[3] <> 'M') then begin
-
-     //if filesz > 132 then begin
-        dseek(fp, 0{128}); //skip the preamble - next 4 bytes should be 'DICM'
-  	   //where := FilePos(fp);
-        dBlockRead(fp, tx, 4*SizeOf(Char), n);
-     //end;
-     if (tx[0] <> 'D') OR (tx[1] <> 'I') OR (tx[2] <> 'C') OR (tx[3] <> 'M') then begin
-        dseek(fp, 0);
-        group   := read16(fp,lrOK);
-
-        if not lrOK then goto 666;
-
-        if group > $0008 then begin
-           group := swap(group);
-           lBig := true;
-        end;
-        if NOT (group in [$0000, $0001, $0002,$0003, $0004, $0008]) then // one more group added
-        begin
-
-           goto 666;
-        end;
-        dseek(fp, 0);
-        //Msg('DICM not at 0 or 128: ' +lFilename);
-     end;
-  end; //else Msg('DICM at 128{0}');;
-  time_to_quit := FALSE;
-  lProprietaryImageThumbnail := false;
-     explicitVR := false;
-    tmpstr := '';
-
-      tmp := 0;
-
-    while NOT time_to_quit do begin
-  t := unknown;
-  	where     := dFilePos(fp);
-     lFirstPass := true;
-777:
-   	group     := read16(fp,lrOK);
-     if (lSwitchToImplicitAfterGroup0002) and (group > 0002) then begin
-        lSwitchToImplicitAfterGroup0002 := false;
-        explicitVR := false;
-     end;
-
-     if not lrOK then goto 666;
-     if (lFirstPass) and (group = 2048) then begin
-         if lDicomData.little_endian = 1 then lDicomData.Little_endian := 0
-         else lDicomData.little_endian := 1;
-         dseek(fp,where);
-         lFirstPass := false;
-         goto 777;
-     end;
-
-     element   := read16(fp,lrOK);
-     if not lrOK then goto 666;
-     e_len:= read32(fp,lrOK);
-     if not lrOK then goto 666;
-lGrpStr := '';
-    lt0 := e_len and 255;
-    lt1 := (e_len shr 8) and 255;
-    lt2 := (e_len shr 16) and 255;
-    lt3 := (e_len shr 24) and 255;
- if (explicitVR) and (lT0=13) and (lT1=0) and (lT2=0) and (lT3=0) then
-   e_len := 10;  //hack for some GE Dicom images
-
-
- if explicitVR or first_one then begin
-   if group = $FFFE then else //1384  - ACUSON images switch off ExplicitVR for file image fragments
-   if  ((lT0=kO) and (lT1=kB)) or ((lT0=kU) and (lT1=kN)){<-UN added 11/11/2011} or ((lT0=kO) and (lT1=kW)) or ((lT0=kS) and (lT1=kQ)) {11/11 add UT}or ((lT0=kU) and (lT1=kT))  then begin
-       lGrpStr := chr(lT0)+chr(lT1);
-           e_len:= read32(fp,lrOK);
-           if not lrOK then goto 666;
-           if first_one then explicitVR := true;
-   end else if ((lT3=kO) and (lT2=kB)) or ((lT3=kU) and (lT2=kN)){<-UN added 11/11/2011} or((lT3=kO) and (lT2=kW)) or ((lT3=kS) and (lT2=kQ)) or ((lT3=kU) and (lT2=kT))then begin
-           e_len:= read32(fp,lrOK);
-           if not lrOK then goto 666;
-           if first_one then explicitVR := true;
-   end
-   else if  ( ((lT0=kA) and (lT1=kE)) or ((lT0=kA) and (lT1=kS))
-      or ((lT0=kA) and (lT1=kT)) or ((lT0=kC) and (lT1=kS)) or ((lT0=kD) and (lT1=kA))
-      or ((lT0=kD) and (lT1=kS))
-      or ((lT0=kD) and (lT1=kT)) or ((lT0=kF) and (lT1=kL)) or ((lT0=kF) and (lT1=kD))
-      or ((lT0=kI) and (lT1=kS)) or ((lT0=kL) and (lT1=kO))or ((lT0=kL) and (lT1=kT))
-      or ((lT0=kP) and (lT1=kN)) or ((lT0=kS) and (lT1=kH)) or ((lT0=kS) and (lT1=kL))
-      or ((lT0=kS) and (lT1=kS)) or ((lT0=kS) and (lT1=kT)) or ((lT0=kT) and (lT1=kM))
-      or ((lT0=kU) and (lT1=kI)) or ((lT0=kU) and (lT1=kL)) or ((lT0=kU) and (lT1=kS))
-      or ((lT0=kA) and (lT1=kE)) or ((lT0=kA) and (lT1=kS)) )
-      then begin
-           lGrpStr := chr(lT0) + chr(lT1);
-           if lDicomData.little_endian = 1 then
-              e_len := (e_len and $ffff0000) shr 16
-           else
-              e_len := swap((e_len and $ffff0000) shr 16);
-           if first_one then begin
-              explicitVR := true;
-           end;
-   end else if (
-           ((lT3=kA) and (lT2=kT)) or ((lT3=kC) and (lT2=kS)) or ((lT3=kD) and (lT2=kA))
-           or ((lT3=kD) and (lT2=kS))
-      or ((lT3=kD) and (lT2=kT)) or ((lT3=kF) and (lT2=kL)) or ((lT3=kF) and (lT2=kD))
-      or ((lT3=kI) and (lT2=kS)) or ((lT3=kL) and (lT2=kO))or ((lT3=kL) and (lT2=kT))
-      or ((lT3=kP) and (lT2=kN)) or ((lT3=kS) and (lT2=kH)) or ((lT3=kS) and (lT2=kL))
-      or ((lT3=kS) and (lT2=kS)) or ((lT3=kS) and (lT2=kT)) or ((lT3=kT) and (lT2=kM))
-      or ((lT3=kU) and (lT2=kI)) or ((lT3=kU) and (lT2=kL)) or ((lT3=kU) and (lT2=kS)))
-      then begin
-           if lDicomData.little_endian = 1 then
-              e_len := (256 * lT0) + lT1
-           else
-              e_len := (lT0) + (256*lT1);
-           if first_one then begin
-              explicitVR := true;
-           end;
-   end;
-end; //not first_one or explicit
-
-   if (first_one) and (lDicomdata.little_endian =0) and (e_len = $04000000) then begin
-      Msg('Switching to little endian');
-      lDicomData.little_endian := 1;
-      dseek(fp, where);
-      first_one := false;
-      goto 777;
-   end else if (first_one) and (lDicomData.little_endian =1) and (e_len = $04000000) then begin
-       Msg('Switching to little endian');
-       lDicomData.little_endian := 0;
-       dseek(fp, where);
-       first_one := false;
-       goto 777;
-   end;
-
-   if e_len = ($FFFFFFFF) then begin
-    e_len := 0;
-end;
-	if lGELX then begin
-   	   e_len := e_len and $FFFF;
-   end;
-   first_one    := false;
-    remaining := e_len;
-    info := '?';
-    tmpstr := '';
-    if (lIndent > 0) and (not ((group= $FFFE) and (element = $E0DD))) and (not lManufacturerIsPhilips)  then
-      //Philips stores slice positioning inside 0020,9113; lice orientation inside 0020,9116  but Siemens stores thumbnails in indented subheadings
-       goto 1234;
-	case group of
-        $0001 : // group for normal reading elscint DICOM
-        case element of
-          $0010 : info := 'Name';
-          $1001 : info := 'Elscint info';
-         end;
-    	$0002 :
-      	case element of
-        	$00 :  info := 'File Meta Elements Group Len';
-          $01 :  info := 'File Meta Info Version';
-          $02 :  info := 'Media Storage SOP Class UID';
-          $03 :  info := 'Media Storage SOP Inst UID';
-          $10 :  begin
-              //lTransferSyntaxReported := true;
-              info := 'Transfer Syntax UID';
-              TmpStr := '';
-              if dFilePos(fp) > (filesz-e_len) then goto 666;
-
-              GetMem( buff, e_len);
-              dBlockRead(fp, buff{^}, e_len, n);
-              for i := 0 to e_len-1 do
-                   	if Char(buff[i]) in ['+','-',' ', '0'..'9','a'..'z','A'..'Z']
-                     	then TmpStr := TmpStr +(Char(buff[i]))
-                      else TmpStr := TmpStr +('.');
-              FreeMem( buff);
-              lStr := '';
-              //Msg(TmpStr);
-              if TmpStr = '1.2.840.113619.5.2' then begin
-                 lGELX := true;
-				          LBigSet := true;
-                 lBig := true;
-              end;
-              //
-              if length(TmpStr) < 19 then begin
-                  //12/2010 assume 1.2.840.10008.1.2
-                  //Raw data, Implicit VR, Little Endian
-                  //   explicitVR := false; //china
-                  lSwitchToImplicitAfterGroup0002 := true;
-              end;
-
-              if length(TmpStr) >= 19 then begin
-
-                  if TmpStr[19] = '1' then begin
-                     lBigSet:= true;
-                     explicitVR := true; //duran
-                     lBig := false;
-                  end else if TmpStr[19] = '2' then begin
-                     lBigSet:= true;
-                     explicitVR := true; //duran
-                     lBig := true;
-                  end else if TmpStr[19] = '4' then begin
-                      if length(TmpStr) >= 21 then begin
-                         //Dec 2012.... dcm2nii can handle JPEG 123456
-                         if {not lReadJPEGtables} false then begin
-                            lImageFormatOK := false;
-                         end else begin
-
-                             i := strtoint(TmpStr[21]+TmpStr[22]);
-                             if (i <> 57) and (i <> 70) then begin
-                                lImageFormatOK := false;
-                                //lDicomData.JPEGLossyCpt := true
-                             end else begin
-
-                                  //lImageFormatOK := false;//123456
-                                  lDicomData.JPEGLosslessCpt := true;
-                             end;
-                         end;
-                      end else begin
-                          lImageFormatOK := false;
-                      end;
-                  end else if TmpStr[19] = '5' then begin
-                      lImageFormatOK := false;//xlDicomData.RunLengthEncoding := true;
-                  end else begin
-                      lImageFormatOK := false;
-                  end;
-                  if not lImageFormatOK then
-                    Msg('Unsupported Transfer Syntax '+(TmpStr)+' Solution: use MRIcro');
-
-              end; {length}
-                  remaining := 0;
-                  e_len := 0; {use tempstr}
-              end;
-          $12 :  begin
-              info := 'Implementation Class UID';
-              end;
-          $13 : begin
-              info := 'Implementation Version Name';
-              if e_len > 4 then begin
-				 TmpStr := '';
-				 DICOMHeaderString(TmpStr);
-               //lDicomData.ImplementationVersion := Str2Int(TmpStr);
-               if TmpStr = 'MEDIFACE 1 5' then
-                 lMediface0002_0013 := true; //detect MEDIFACE 1.5 error: error in length of two elements 0008:1111 and 0008:1140
-              end; //length > 4
-		  end; //element 13
-          $16 :  info := 'Source App Entity Title';
-          $100:  info := 'Private Info Creator UID';
-          $102:  info := 'Private Info';
-				end;
-      $0008 :
-        case element of
-          $00 :  begin
-              info := 'Identifying Group Length';
-          end;
-          $01 :  info := 'Length to End';
-          $05 :  info := 'Specific Character Set';
-            $08 :  begin
-              info := 'Image Type';
-              if dFilePos(fp) > (filesz-e_len) then goto 666;
-              lSiemensMosaic0008_0008:= false;
-              if (e_len >= 6) then begin //search for 'MOSAIC'
-                 GetMem( buff, e_len);
-                 dBlockRead(fp, buff{^}, e_len, n);
-                 i := e_len -6;//MOSAIC
-                 while (i>-1) and (not lSiemensMosaic0008_0008) do begin
-                   if (upcase(Char(buff[i])) = 'M') and (upcase(Char(buff[i+1])) = 'O')
-                      and (upcase(Char(buff[i+2])) = 'S') and (upcase(Char(buff[i+3])) = 'A')
-                      and (upcase(Char(buff[i+4])) = 'I') and (upcase(Char(buff[i+5])) = 'C')
-                   then //strip filler characters: DICOM elements must be padded for even length
-                      lSiemensMosaic0008_0008 := true;
-                   dec(i);
-                 end;
-                 FreeMem( buff);
-                 remaining := 0;
-                 e_len := 0; {use tempstr}
-               end;
-         end;
-          $10 :  info := 'Recognition Code';
-          $12 :  info := 'Instance Creation Date';
-          $13 :  info := 'Instance Creation Time';
-          $14 :  info := 'Instance Creator UID';
-          $16 :  info := 'SOP Class UID';
-          $18 :  info := 'SOP Instance UID';
-          $20 :  begin
-			  info := 'Study Date';
-              //lDicomData.StudyDatePos  := dFilePos(fp);
-			  DICOMHeaderString(lDicomData.StudyDate);
-              end;
-          $21 :  info := 'Series Date';
-          $22 :  info := 'Acquisition Date';
-          $23 :  info := 'Image Date';
-		  $30 :   begin  info := 'Study Time';
-			  DICOMHeaderStringTime(lDicomData.StudyTime);
-		  end;
-          $31 :  info := 'Series Time';
-		  $32 : begin  info := 'Acquisition Time';
-			  DICOMHeaderStringTime(TmpStr);
-              lDicomData.SecSinceMidnight := SecSinceMidnightFloat(TmpStr);
-
-		  end;
-          $33 : begin  info := 'Image Time';
-              //xxDICOMHeaderStringTime(lDicomData.ImgTime);
-          end;
-          $40 :  info := 'Data Set Type';
-          $41 :  info := 'Data Set Subtype';
-		  $50 :  begin
-          //xDICOMHeaderStringtoInt(lDicomData.accession);
-          info := 'Accession Number';
-          end;
-
-          $60 :  begin info := 'Modality';  t := _string; end;
-          $64 :  begin info := 'Conversion Type';  t := _string; end;
-          $70 : begin
-          info := 'Manufacturer';
-              //Only read last word, e.g. 'TYPE\MOSAIC' will be read as 'MOSAIC'
-              TmpStr := '';
-
-              if dFilePos(fp) > (filesz-e_len) then goto 666;
-              GetMem( buff, e_len);
-              dBlockRead(fp, buff{^}, e_len, n);
-              i := e_len -1;
-              while (i>-1) and (Char(buff[i]) in ['a'..'z','A'..'Z',' ']) do begin
-                   if (Char(buff[i])) <> ' ' then //strip filler characters: DICOM elements must be padded for even length
-                      TmpStr := upcase(Char(buff[i]))+TmpStr;
-                   dec(i);
-              end;
-              FreeMem( buff);
-                  remaining := 0;
-                  e_len := 0; {use tempstr}
-              if (length(TmpStr) > 3) and (TmpStr[1]='P') and (TmpStr[2]='H') and (TmpStr[3]='I') then
-                 lManufacturerIsPhilips := true;
-              if (length(TmpStr) > 3) and (TmpStr[1]='B') and (TmpStr[2]='R') and (TmpStr[3]='U') then
-                 lManufacturerIsBruker := true;
-
-              if lManufacturerIsPhilips then
-                 lDicomData.ManufacturerID := kPhilipsID;
-              if (length(TmpStr) > 3) and (TmpStr[1]='G') and (TmpStr[2]='E')  then
-                 lDicomData.ManufacturerID := kGEID;
-              if (length(TmpStr) > 3) and (TmpStr[1]='S') and (TmpStr[2]='I') and (TmpStr[3]='E') then
-                 lDicomData.ManufacturerID := kSiemensID;
-
-          end;
-          $80 :  info := 'Institution Name';
-		  $81 :  info := 'City Name';
-          $90 :  info := 'Referring Physician''s Name';
-          $100: info := 'Code Value';
-          $102 : begin
-            info := 'Coding Schema Designator';
-            t := _string;
-          end;
-          $104: info := 'Code Meaning';
-          $1010: info := 'Station Name';
-          $1030: begin info := 'Study Description'; t := _string; end;
-          $103e: begin info := 'Series Description'; t := _string; end;
-          $1040: info := 'Institutional Dept. Name';
-          $1050: info := 'Performing Physician''s Name';
-          $1060: info := 'Name Phys(s) Read Study';
-          $1070: begin info := 'Operator''s Name';  t := _string; end;
-          $1080: info := 'Admitting Diagnosis Description';
-          $1090: begin info := 'Manufacturer''s Model Name';t := _string; end;
-          $1111: begin
-                 if lMediface0002_0013 then E_LEN := 8;//+e_len;
-             end; //ABBA: patches error in DICOM images seen from Sheffield 0002,0013=MEDIFACE.1.5; 0002,0016=PICKER.MR.SCU
-          $1140: begin
-                   if (lMediface0002_0013) and (E_LEN > 255) then E_LEN := 8;
-                 end; //ABBA: patches error in DICOM images seen from Sheffield 0002,0013=MEDIFACE.1.5; 0002,0016=PICKER.MR.SCU
-          $2111: info := 'Derivation Description';
-          $2120: info := 'Stage Name';
-          $2122: begin info := 'Stage Number';t := _string; end;
-          $2124: begin info := 'Number of Stages';t := _string; end;
-		  $2128: begin info := 'View Number';t := _string; end;
-          $212A: begin info := 'Number of Views in stage';t := _string; end;
-          $2204: info := 'Transducer Orientation';
-          $9208: begin
-             info := 'ComplexImageComponent';
-				 TmpStr := '';
-				 DICOMHeaderString(TmpStr);
-              i := 0;
-
-              if length(TmpStr) >= 2 then begin
-                 if (TmpStr[1] = 'M') and (TmpStr[2] = 'A') then
-                    i := 1; //magnitude
-                 if (TmpStr[1] = 'P') and (TmpStr[2] = 'H') then
-                    i := 2; //phase
-                 if (TmpStr[1] = 'R') and (TmpStr[2] = 'E') then
-                    i := 3; //real
-                 if (TmpStr[1] = 'I') and (TmpStr[2] = 'M') then
-                    i := 4; //imaginary
-              end;
-              //mixed will be followed by subsequent settings, so do not use it here....
-              if (i > 0) and (lDICOMdata.nOrder < kMaxOrderVal) then begin
-                  inc(lDICOMdata.nOrder);
-                  //msg(TmpStr);
-                  lDICOMdata.order[lDICOMdata.nOrder] := i;
-              end;
-(*[ magnitude * MAGNITUDE
-[ phase * PHASE
-[ real * REAL
-[ imaginary * IMAGINARY
-[ mixed * MIXED*)
-              ///xxx xxx
-          end;
-
-        end;
-        $0009: if element = $0010 then begin
-
-             if e_len > 4 then begin
-               TmpStr := '';
-              if dFilePos(fp) > (filesz-e_len) then goto 666;
-              GetMem( buff, e_len);
-              dBlockRead(fp, buff{^}, e_len, n);
-              i := e_len -1;
-
-              while (i>-1) {and (Char(buff[i]) in ['a'..'z','A'..'Z',' '])} do begin
-                  if (Char(buff[i])) in ['a'..'z','A'..'Z'] then //strip filler characters: DICOM elements must be padded for even length
-                      TmpStr := upcase(Char(buff[i]))+TmpStr;
-                   dec(i);
-              end;
-              FreeMem( buff);
-              remaining := 0;
-              if (Length(TmpStr)>4) and (TmpStr[1]='M') and (TmpStr[2]='E') and (TmpStr[3]='R') and (TmpStr[4]='G') then
-                 lOldSiemens_IncorrectMosaicMM := true; //detect MERGE technologies mosaics
-              e_len := 0; {use tempstr}
-             end;
-
-
-          end;
-    	$0010 :
-		case element of
-        	$00 :  info := 'Patient Group Length';
-          $10 :  begin info := 'Patient''s Name'; t := _string;
-              //xlDicomData.NamePos := dFilePos(fp);
-              DICOMHeaderString(lDicomData.PatientName);
-          end;
-          $20 :  begin info := 'Patient ID';
-              //xDICOMHeaderString(lDicomData.PatientID);
-              //xlDicomData.PatientIDInt := safestrtoint(lDicomData.PatientID);
-          end;
-          //11/2010
-          //$30: info := 'Date of Birth'; //"Age String" type: e.g 067y for 67 years old, 067d for 67 days
-          $30 :  begin info := 'DoB'; t := _string;
-              //xlDicomData.NamePos := dFilePos(fp);
-              //lDicomData.PatientDoB := '1111';
-              DICOMHeaderString(lDicomData.PatientDoB);
-          end;
-          $32 : info := 'Patient Birth Time';
-          //$40 :  begin info := 'Patient Sex';  t := _string; end;
-          $40 :  begin info := 'Gender'; t := _string;
-              //xlDicomData.NamePos := dFilePos(fp);
-              DICOMHeaderString(lDicomData.PatientGender);
-          end;
-
-          $1000: info := 'Other Patient IDs';
-          $1001: info := 'Other Patient Names';
-          $1005: info := 'Patient''s Birth Name';
-          $1010: begin info := 'Patient Age'; t := _string; end;
-          $1030: info := 'Patient Weight';
-          $21b0: info := 'Additional Patient History';
-          $4000: info := 'Patient Comments';
-
-				end;
-    $0018 :
-        case element of
-			 $00 :  info := 'Acquisition Group Length';
-          $10 :  begin info := 'Contrast/Bolus Agent'; t := _string; end;
-          $15: info := 'Body Part Examined';
-		  $20 :  begin
-			info := 'Scanning Sequence';t := _string;
-			TmpStr := '';
-			DICOMHeaderString(TmpStr);
-			if TmpStr = 'RM' then lResearchMode := true;
-			end;
-		  $21 :  begin info := 'Sequence Variant';t := _string; end;
-		  $22 :  info := 'Scan Options';
-		  $23 :  begin info := 'MR Acquisition Type'; t := _string; end;
-		  $24 :  info := 'Sequence Name';
-		  $25 :  begin info := 'Angio Flag';t := _string; end;
-		  $30 :  info := 'Radionuclide';
-		  $50 :  begin info := 'Slice Thickness';
-			readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-			  if not lrOK then goto 666;
-              e_len := 0;      remaining := 0;
-             lDICOMdata.XYZmm[3] := lfloat1;
-             
-             lThickness := lfloat1;//lDICOMdata.Thickness := lfloat1; //1391b
-          end;
-          //$60: begin info := 'KVP [Peak Output, KV]';  t := _string; end; //aqw
-          $60: begin
-                info := 'KVP [Peak KV]';
-                readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-                if not lrOK then goto 666;
-                e_len := 0; remaining := 0;
-                lDicomData.kV := lFloat1;
-          end;
-
-          $70: begin t := _string; info := 'Counts Accumulated'; end;
-          $71: begin t := _string; info := 'Acquisition Condition'; end;
-		  //$80 :  begin info := 'Repetition Time';  t := _string; end; //aqw
-          //$81 :  begin info := 'Echo Time'; t := _string; end;  //aqw
-          $80 : begin info := 'Repetition Time [TR, ms]';
-                readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-                if not lrOK then goto 666;
-				e_len := 0; remaining := 0;
-                lDicomData.TR := lFloat1;
-                end;
-
-          $81 : begin
-          info := 'Echo Time [TE, ms]';
-                readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-                if not lrOK then goto 666;
-                e_len := 0; remaining := 0;
-                lDicomData.TE := lFloat1;
-          end;
-          $82 :  begin t := _string; info := 'Inversion Time';end;
-          $83 :  begin t := _string; info := 'Number of Averages'; end;
-          $84 :  info := 'Imaging Frequency';
-          $85 :  begin info := 'Imaged Nucleus';  t := _string; end;
-          $86 :  begin info := 'Echo Number';t := _string;
-
-             DICOMHeaderStringToInt(lEchoNum);
-             //lDICOMdata.Echo := lEchoNum;
-
-          end;
-//qq
-          $87 :  info := 'Magnetic Field Strength';
-          $88 : begin
-          info := 'Spacing Between Slices';
-            readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-              if not lrOK then goto 666;
-              e_len := 0;      remaining := 0; //1362 some use this for gap size, others for sum of gap and slicethickness!
-            //3333 if (lfloat1 > lDICOMdata.XYZmm[3]) or (lDICOMdata.XYZmm[3]=1) then
-             //lDICOMdata.XYZmm[3] := lfloat1;
-             //fx(lDICOMdata.XYZmm[3],lThickness,lfloat1);
-             if lfloat1 < 0 then
-                lDICOMdata.XYZmm[3] := lFloat1//does not make sense - found in some eFilm images from Marconi P3000
-             else if  ( (lThickness/2) > lfloat1 ) then
-                 lDICOMdata.XYZmm[3] := lfloat1+lThickness
-             else
-                 lDICOMdata.XYZmm[3] := lfloat1;//1392
-             //xldicomdata.spacing:=lfloat1;
-             end;
-          $89 : begin
-             // t := _string;
-              info := 'Number of Phase Encoding Steps';
-            //1499c This is a indirect method for detecting SIemens Mosaics: check if image height is evenly divisible by encoding steps
-            //      A real kludge due to Siemens not documenting mosaics explicitly: this workaround may incorrectly think rescaled images are mosaics!
-            readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-			lPhaseEncodingSteps := round(lfloat1);
-			//xxxMsg(floattostr(lFloat1));
-              if not lrOK then goto 666;
-              e_len := 0;      remaining := 0; //1362 some use this for gap size, others for sum of gap and slicethickness!
-            //if (lfloat1 > lDICOMdata.XYZmm[3]) or (lDICOMdata.XYZmm[3]=1) then
-            //lDICOMdata.XYZmm[3] := lfloat1;
-             //ldicomdata.spacing:=lfloat1;
-
-
-              end;
-          $90 :  info := 'Data collection diameter';
-          $91 :  begin info := 'Echo Train Length';t := _string; end;
-          $93: begin info := 'Percent Sampling'; t := _string; end;
-          $94: begin info := 'Percent Phase Field View'; t := _string; end;
-          $95 : begin info := 'Pixel Bandwidth';  t := _string; end;
-          $1000: begin t := _string; info := 'Device Serial Number'; end;
-          $1004: info := 'Plate ID';
-          $1020: begin
-                 info := 'Software Version';
-                 t := _string;
-                 if e_len > 2 then begin
-				 TmpStr := '';
-				 DICOMHeaderString(TmpStr);
-                                 lDicomData.Vers0018_1020 := Siemensversion(TmpStr);
-                 end;
-          
-                 //showmsg(inttostr(lDicomData.Vers0018_1020)+' '+TmpStr);
-          end;
-		  $1030: begin
-			info := 'Protocol Name';t := _string;
-			TmpStr := '';
-			DICOMHeaderString(TmpStr);
-			lDicomData.ProtocolName := TmpStr;
-			AplhaNumericStrDICOM (lDicomData.ProtocolName);
-		  end;
-		  $1040: info := 'Contrast/Bolus Route';
-		  $1050 :  begin
-              t := _string; info := 'Spatial Resolution'; end;
-          $1060: info := 'Trigger Time';
-          $1062: info := 'Nominal Interval';
-          $1063: info := 'Frame Time';
-          $1081: info := 'Low R-R Value';
-		  $1082: info := 'High R-R Value';
-          $1083: info := 'Intervals Acquired';
-          $1084: info := 'Intervals Rejected';
-          $1088: begin info := 'Heart Rate'; t := _string; end;
-          $1090: begin info :=  'Cardiac Number of Images'; t := _string; end;
-          $1094: begin info :=  'Trigger Window';t := _string; end;
-          $1100: info := 'Reconstruction Diameter';
-          $1110: info := 'Distance Source to Detector [mm]';
-          $1111: info := 'Distance Source to Patient [mm]';
-          $1120: info := 'Gantry/Detector Tilt';
-          $1130: info := 'Table Height';
-          $1140: info := 'Rotation Direction';
-          $1147: info := 'Field of View Shape';
-          $1149: begin
-              t := _string; info := 'Field of View Dimension[s]'; end;
-          $1150: begin
-            info := 'Exposure Time [ms]';
-            t := _string;
-          end;
-          $1151: begin
-                info := 'X-ray Tube Current [mA]';
-                readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-                if not lrOK then goto 666;
-                e_len := 0; remaining := 0;
-                //xlDicomData.mA := lFloat1;
-                end;
-
-          $1152 :  info := 'Acquisition Device Processing Description';
-		  $1155: info := 'Radiation Setting';
-          $1160: info := 'Filter Type';
-          $1164: info :='Imager Pixel Spacing';
-          $1166: info := 'Grid';
-          $1170 :  info := 'Generator Power';
-          $1180 : info := 'Collimator/grid Name';
-          $1190 : begin
-             info := 'Focal Spot[s]';
-             t := _string;
-          end;
-          $11A0 : begin
-            info := 'Body Part Thickness';
-            t := _string;
-          end;
-          $11A2 : info := 'Compression Force';
-          $1200 :  info := 'Date of Last Calibration';
-          $1201 :  info := 'Time of Last Calibration';
-          $1210: info := 'Convolution Kernel';
-          $1250: begin t := _string; info := 'Receiving Coil'; end;
-          $1251: begin t := _string; info := 'Transmitting Coil'; end;
-          $1260 :  begin
-              t := _string; info := 'Plate Type'; end;
-          $1261 :  begin
-              t := _string; info := 'Phosphor Type';  end;
-       $1310: begin info := 'Acquisition Matrix'; //Siemens Mosaics  converted by Merge can report the incorrect mm
-
-         //nji2
-       //NOTE: Matrix Information for MERGE converted images. Used Innocently for other uses by Siemens
-
-       if (lOldSiemens_IncorrectMosaicMM) or ((lSiemensMosaic0008_0008) and (lMatrixSz < 1){B13}) then begin
-
-          //TmpStr := ReadStrABC(fp, remaining,lrOK,lA,lB,lC);
-
-          TmpStr := ReadStr(fp, remaining,lrOK,lMatrixSz);
-          //ss//1362
-          //fx(remaining);
-          (*kEr := true;
-          readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-                if not lrOK then goto 666;
-				e_len := 0; remaining := 0;
-          kEr := false;
-
-          lMatrixSz := round(lFloat1);
-          msg(TmpStr);
-          fx(lMatrixSz,lFLoat1,lFloat2,4321);*)
-          {fx(lA,lB,lC);
-          lMatrixSz := lB;
-          lMatrixSzY := lC; }
-       end else
-          TmpStr := ReadStr(fp, remaining,lrOK,lJunk);//1362
-
-                     if not lrOK then goto 666;
-                     e_len := 0; remaining := 0;
-       end;
-          $1312: begin
-              t := _string; info := 'Phase Encoding Direction';
-              			TmpStr := '';
-			DICOMHeaderString(TmpStr);
-			lDicomData.PhaseEncoding := TmpStr;
-			AplhaNumericStrDICOM (lDicomData.PhaseEncoding);
-               end;
-          $1314: begin
-              t := _string; info := 'Flip Angle'; end;
-          $1315: begin
-              t := _string;info := 'Variable Flip Angle Flag'; end;
-          $1316: begin
-              t := _string;info := 'SAR'; end;
-          $1400: info := 'Acquisition Device Processing Description';
-          $1401: begin info := 'Acquisition Device Processing Code';t := _string; end;
-          $1402: info := 'Cassette Orientation';
-          $1403: info := 'Cassette Size';
-                    $1404: info := 'Exposures on Plate';
-          $1405: begin
-            info := 'Relative X-Ray Exposure';
-            t := _string;
-          end;
-          $1500: info := 'Positioner Motion';
-          $1508: info := 'Positioner Type';
-          $1510: begin
-			info := 'Positioner Primary Angle';
-            t := _string;
-          end;
-          $1511: info := 'Positioner Secondary Angle';
-          $5020: info := 'Processing Function';
-          $5100: begin
-              t := _string; info := 'Patient Position';
-              			TmpStr := '';
-			DICOMHeaderString(TmpStr);
-			lDicomData.PatientPos := TmpStr;
-			AplhaNumericStrDICOM (lDicomData.PatientPos);
-               end;
-          $5101: begin info := 'View Position';t := _string; end;
-          $6000: begin info := 'Sensitivity'; t := _string; end;
-                 $7004: info := 'Detector Type';
-          $7005: begin
-            info := 'Detector Configuration';
-            t := _string;
-          end;
-          $7006: info := 'Detector Description';
-          $700A: info := 'Detector ID';
-          $700C: info := 'Date of Last Detector Calibration';
-          $700E: info := 'Date of Last Detector Calibration';
-          $7048: info := 'Grid Period';
-          $7050: info := 'Filter Material LT';
-          $7060: info := 'Exposure Control Mode';
-       end;
-$0019: begin
-     (*case element of //1362
-//3/3/2008 this old method for detecting mosaics has a problem - if image is interpolated x2, you will assume a 2x2 mosaic
-        $1220: begin
-            info := 'Matrix';t := _string;
-            readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-              if not lrOK then goto 666;
-			  e_len := 0;
-              if lfloat2 > lfloat1 then lfloat1 := lfloat2;
-              lMatrixSz := round(lfloat1);
-                  //if >32767 then there will be wrap around if read as signed value!
-                  remaining := 0;
-       end;
-        $14D4: begin
-            info := 'Matrix';t := _string;
-            readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-              if not lrOK then goto 666;
-              e_len := 0;
-              if lfloat2 > lfloat1 then lfloat1 := lfloat2;
-              lMatrixSz := round(lfloat1);
-                  //if >32767 then there will be wrap around if read as signed value!
-                  remaining := 0;
-        end;
-        end; *) //case element
-
-        if lDicomData.ManufacturerID = kSiemensID then begin
-           case element of //1362
-              (*  $100A: begin //unsigned short $100A
-                        info := 'Number Of Images in Mosaic';
-                        tmp := read16(fp,lrOK);
-                        if not lrOK then goto 666;
-                        fx(e_len,tmp,remaining);
-
-                 end;*)
-                $000C,$100C: begin
-                             info := 'Siemens b-value';
-                             readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-                             if not lrOK then goto 666;
-                             e_len := 0; remaining := 0;
-                             tmpstr := floattostr(lFloat1);
-                             lDICOMdata.DTI[1].bval := round(lFloat1);
-                             lDICOMdata.SiemensDICOMDTI := true ;
-                             //msgfx( 777,lDICOMdata.DTI[1].bval,lDICOMdata.DTI[1].bval,lDICOMdata.DTI[1].bval);
-                end; // b-values
-                $000E,$100E: begin
-                             info := 'Siemens Gradient vector [x,y,z]';
-                             //readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-                             lDICOMdata.DTI[1].v1 := read64 (fp,lrOK);
-                             if not lrOK then goto 666;
-                             lDICOMdata.DTI[1].v2 := read64 (fp,lrOK);
-                             if not lrOK then goto 666;
-                             lDICOMdata.DTI[1].v3 := read64 (fp,lrOK);
-                             if not lrOK then goto 666;
-                             //msgfx( 666,lDICOMdata.DTI[1].v1,lDICOMdata.DTI[1].v2,lDICOMdata.DTI[1].v3);
-                             //readfloats3 (fp, remaining, lDummyStr, lDICOMdata.DTI[1].v1,lDICOMdata.DTI[1].v2,lDICOMdata.DTI[1].v3, lROK);
-                             //ShowMsg(lDummyStr);
-                             //fx(e_len,lDICOMdata.DTI[1].v1,lDICOMdata.DTI[1].v2,lDICOMdata.DTI[1].v3);
-
-                             e_len := 0; remaining := 0;
-                             //lDICOMdata.DTI[1].v1 := lFloat1;
-                end; // X diffusion direction
-
-
-           end;//Case element
-        end;//if Siemens
-
-        if lDicomData.ManufacturerID = kGEID then begin
-           case element of //1362
-                $10BB,$a0bb: begin
-                             info := 'GE Gradient vector [x]';
-                             readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-                             if not lrOK then goto 666;
-                             e_len := 0; remaining := 0;
-                             lDICOMdata.DTI[1].v1 := lFloat1;
-                end; // X diffusion direction
-                $10BC,$A0BC: begin
-                             info := 'GE Gradient vector [y]';
-                             readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-                             if not lrOK then goto 666;
-                             e_len := 0; remaining := 0;
-                             lDICOMdata.DTI[1].v2 := lFloat1;
-                end;//Y diffusion direction
-                $10BD,$A0BD: begin
-                             info := 'GE Gradient vector [z]';
-                             readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-                             if not lrOK then goto 666;
-                             e_len := 0; remaining := 0;
-                             lDICOMdata.DTI[1].v3 := lFloat1;
-                 end;// Z diffusion direction
-           end;//Case element
-           //
-           
-        end;//if GE
-        end;//$0019
-
-
-$0020 :
-        case element of
-					$00 :  info := 'Relationship Group Length';
-          $0d :  info := 'Study Instance UID';
-          $0e :  info := 'Series Instance UID';
-          $10 :  begin
-            info := 'Study ID';
-            t := _string;
-		  end;
-          $11 :  begin info := 'Series Number';
-						DICOMHeaderStringToInt(lDicomData.SeriesNum);
- end;
-          $12 : // begin info := 'Acquisition Number';  t := _string; end;
-          begin info := 'Acquisition Number';
-			  DICOMHeaderStringToInt(lDicomData.AcquNum);
-          end;
-
-          $13 :  begin info := 'Image Number';
-              DICOMHeaderStringToInt(lTempInt);
-              if (lDicomData.ImageNum < 2) and (lTempInt >= 0) then
-                 lDicomData.ImageNum := lTempInt;
-              //March2008 - some Philips data has multiple image numbers...
-              //  0018,1020,Software Version=1.5.4\1.5.4.3\Gyroscan PMS/DICOM 2.0 MR .Id. datadefs.v 5.27 2004/10/18 06.50
-              //msg(inttostr(lDicomData.ImageNum)+lDicomData.Filename);
-		  end;
-          $20 :  begin info := 'Patient Orientation';
-                 t := _string;
-           end;
-          $30 :  info := 'Image Position';
-          $32 :  begin
-              info := 'Image Position Patient';
-          //June 2009 - for Philips new 4D format we want value from the first slice...
-
-          if lInside2005140F then begin
-             if not (lPhilipsWarning) then
-              Msg('*User: check slice thickness. Possible Philips R3.2.2 bug - scanner can report different 0020,0032 values for the same slice.');
-             lPhilipsWarning := true;
-          end else begin
-            //5/2012: Philips R3.2.2 can save two instances of 0020:0032 for each slice: one from voxel center, one from voxel edge.
-
-            if not lImagePositionPatientRead then begin
-              readfloats3 (fp, remaining, lDummyStr, lDicomData.PatientPosX, lDicomData.PatientPosY,lDicomData.PatientPosZ, lROK);
-              //fx(   lDicomData.PatientPosX, lDicomData.PatientPosY,lDicomData.PatientPosZ,56789);
-              if not lrOK then goto 666;
-              e_len := 0;
-              remaining := 0;
-              lImagePositionPatientRead := true;
-              //we assume Philips reports the slice thickness correctly....
-              //an alternative would be to read both 1st and 2nd ImagePositionPatient and
-              //compute the function DICOMinterslicedistance
-            end else begin
-
-              CheckIntersliceDistance(l4DDistanceBetweenSliceCenters);
-
-            end; //not 1st read
-
-          end; //if lInside2005140F
-          //lInside2005140F := false;
-			  end;
-		  $35 :  info := 'Image Orientation';
-		  $37 : begin //nifti
-			info := 'Image Orientation (Patient)';
-			readfloats6 (fp, remaining, lDummyStr, lDicomData.Orient[1], lDicomData.Orient[2],lDicomData.Orient[3],lDicomData.Orient[4], lDicomData.Orient[5],lDicomData.Orient[6], lROK);
-		  if not lrOK then goto 666;
-		  e_len := 0;
-		  remaining := 0;
-
-			end;
-          $50 :  info := 'Location';
-          $52 :  info := 'Frame of Reference UID';
-          $91 :  info := 'Echo Train Length';
-          $70 :  info := 'Image Geometry Type';
-          $60 :  info := 'Laterality';
-          $0105 : begin
-                //Apr2007
-               
-                DICOMHeaderStringToInt(lnVol);
-
-           //Number of temporal positions=105
-          end;
-          $1001: info := 'Acquisitions in Series';
-          $1002: info := 'Images in Acquisition';
-          $1020: info := 'Reference';
-          $1040: begin info :=  'Position Reference';  t := _string; end;
-          $1041: begin info := 'Slice Location';
-            readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-              if not lrOK then goto 666;
-              e_len := 0;      remaining := 0;
-              ldicomdata.location:=lfloat1;
-             end;
-		 $1070: begin
-            info := 'Other Study Numbers';
-            t := _string;
-          end;
-          $3401: info := 'Modifying Device ID';
-          $3402: info := 'Modified Image ID';
-          $3403: info := 'Modified Image Date';
-          $3404: info := 'Modifying Device Mfg.';
-          $3405: info := 'Modified Image Time';
-          $3406: info := 'Modified Image Desc.';
-          $4000: info := 'Image Comments';
-          $5000: info := 'Original Image ID';
-		  $5002: info := 'Original Image... Nomenclature';
-      //$9113: xxxx
-				end;
- $0021:case element of
-      $104F: begin
-          info :='GE Locations in acquisition';
-
-                            if lPrefs.UseGE_0021_104F then begin
-                              //June 2009 - Thomas Stephan sent me a GE image where this was set to 2, but should have been 1
-                              //I hope removing this does not cause problems with other GE images...
-                                  if e_len = 2 then begin
-                                      lDicomData.SlicesPer3DVol := read16(fp,lrOK);
-                                      e_len := 0; remaining := 0;
-                                     /// fx(9999, lDicomData.SlicesPer3DVol);
-                                   end;
-                              end; //use 0021_104F
-      end;
-
-      $1341: begin
-          info :='Siemens Mosaic Slice Count';
-          DICOMHeaderStringToInt(lDicomData.SiemensSlices);
-
-      end;
-	  $134F: begin //1366
-          info :='Siemens Order of Slices';
-          t := _string;
-              lDICOMdata.SiemensInterleaved := 0; //0=no,1=yes,2=undefined
-              //look for "INTERLEAVED"
-              lStr := '';
-              if dFilePos(fp) > (filesz-e_len) then goto 666;
-              GetMem( buff, e_len);
-              dBlockRead(fp, buff{^}, e_len, n);
-              for i := 0 to e_len-1 do
-                   	if Char(buff[i]) in ['?','A'..'Z','a'..'z']
-                     	then lStr := lStr +upcase(Char(buff[i]));
-              FreeMem( buff);
-          if(lStr[1]= 'I') then lDICOMdata.SiemensInterleaved := 1; //0=no,1=yes,2=undefined
-          e_len := 0;
-      end;
- end;
-$0028 :   begin
-        case element of
-        	$00 :  info := 'Image Presentation Group Length';
-		  $02 :  begin
-              info := 'Samples Per Pixel';
-              tmp := read16(fp,lrOK);
-              if not lrOK then goto 666;
-              lDicomData.SamplesPerPixel :=tmp;
-                 if e_len > 255 then begin
-                    explicitVR := true;  //kludge: switch between implicit and explicitVR
-                 end;
-                 tmpstr := inttostr(tmp);
-                 e_len := 0;
-                  remaining := 0;
-              end;
-          $04 :  begin
-              info := 'Photometric Interpretation';
-              TmpStr := '';
-              if dFilePos(fp) > (filesz-e_len) then goto 666;
-              GetMem( buff, e_len);
-              dBlockRead(fp, buff{^}, e_len, n);
-              for i := 0 to e_len-1 do
-                   	if Char(buff[i]) in [{'+','-',' ', }'0'..'9','a'..'z','A'..'Z']
-                     	then TmpStr := TmpStr +(Char(buff[i]));
-              FreeMem( buff);
-              (*xif TmpStr = 'MONOCHROME1' then lDicomdata.monochrome := 1
-              else if TmpStr = 'MONOCHROME2' then lDicomdata.monochrome := 2
-              else if (length(TMpStr)> 0) and (TmpStr[1] = 'Y') then lDICOMdata.monochrome := 4
-              else lDICOMdata.monochrome := 3; *)
-                  remaining := 0;
-                  e_len := 0; {use tempstr}
-
-          end;
-          $05 :  info := 'Image Dimensions (ret)';
-          $06 : begin
-              info := 'Planar Configuration';
-              tmp := read16(fp,lrOK);
-              if not lrOK then goto 666;
-              lDicomData.PlanarConfig :=tmp;
-              remaining := 0;
-              end;
-
-          $08 :  begin
-              //if lPapyrusnSlices < 1 then
-              //   if remaining = 2 then begin
-              //     tmp := read16(fp,lrOK);
-              //
-              //   end else               xx
-                 DICOMHeaderStringToInt(lDicomData.XYZdim[3]);
-                  if lDicomData.XYZdim[3] < 1 then lDicomData.XYZdim[3] := 1;
-               info := 'Number of Frames';
-                 end;
-          $09: begin info := 'Frame Increment Pointer'; TmpStr := ReadStrHex(fp, remaining,lrOK);           if not lrOK then goto 666;
- e_len := 0; remaining := 0; end;
-          $10 :  begin info := 'Rows';
-          				lDicomData.XYZdim[2] := read16(fp,lrOK);
-                                        if not lrOK then goto 666;
-						tmp := lDicomData.XYZdim[2];
-                  remaining := 0;
-                 end;
-          $11 :  begin info := 'Columns';
-          				lDicomData.XYZdim[1] := read16(fp,lrOK);
-                             if not lrOK then goto 666;
-          				tmp := lDicomData.XYZdim[1];
-                  remaining := 0;
-                 end;
-          $30 :  begin info := 'Pixel Spacing';
-           readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-          if not lrOK then goto 666;
-          //qq
-               //row spacing [y], then column spacing [x]: see part 3 of DICOM
-          e_len := 0;      remaining := 0;
-             lDICOMdata.XYZmm[2] := lfloat1;
-             lDICOMdata.XYZmm[1] := lfloat2;
-          end;
-          $31: info := 'Zoom Factor';
-          $32: info := 'Zoom Center';
-          $34: begin info :='Pixel Aspect Ratio';t := _string; end;
-          $40: info := 'Image Format [ret]';
-          $50 :  info := 'Manipulated Image [ret]';
-          $51: info := 'Corrected Image';
-          $60: begin info := 'Compression Code [ret]';t := _string; end;
-          $100: begin info := 'Bits Allocated';
-                 if remaining = 4 then
-                    tmp := read32(fp,lrOK)
-				 else
-                     tmp := read16(fp,lrOK);
-                 //lWord := read16(fp,lrOK);
-                 //lWord := read16(fp,lrOK);
-
-                            if not lrOK then goto 666;
-                  if tmp = 8 then lDicomData.Allocbits_per_pixel := 8
-                  else if tmp = 12 then lDicomData.Allocbits_per_pixel := 12
-                  else if tmp = 16 then lDicomData.Allocbits_per_pixel := 16
-                  else if tmp = 32 then lDicomData.Allocbits_per_pixel := 32
-                  else if tmp = 24 then begin
-                       //xlDicomData.SamplesPerPixel := 3;
-                       lDicomData.Allocbits_per_pixel := 8
-                  end else begin
-                    lWord := tmp;
-                    lWord := swap(lWord);
-                    if lWord in [8,12,16,24,32] then begin
-                       lDicomData.Allocbits_per_pixel := tmp;
-                       lByteSwap := true;
-                    end else begin
-                        if lImageFormatOK then
-                       Msg('This software only reads 8, 12, 16, 24 [RGB] and 32 bit DICOM files. This file allocates '+inttostr(tmp)+' bits per voxel.');
-                      lImageFormatOK := false;
-                    end;
-                  end;
-                  //remaining := 2;//remaining; //1371->
-                  remaining := 0
-                 end;
-        	$0101: begin info := 'Bits Stored';
-				 if remaining = 4 then
-                    tmp := read32(fp,lrOK)
-                 else
-                     tmp := read16(fp,lrOK);
-
-                             if not lrOK then goto 666;
-
-                  (*if tmp <= 8 then lDicomData.Storedbits_per_pixel := 8
-                  else if tmp <= 16 then lDicomData.Storedbits_per_pixel := 16
-                  else if tmp <= 24 then begin
-                       lDicomData.Storedbits_per_pixel := 24;
-                       lDicomData.SamplesPerPixel := 3;
-                  end else begin
-                       lWord := tmp;
-                       lWord := swap(lWord);
-                       if lWord in [8,12,16] then begin
-                          lDicomData.Storedbits_per_pixel := tmp;
-                          lByteSwap := true;
-                       end else begin
-                           if lImageFormatOK then
-                              Msg('This software can only read 8, 12 and 16 bit DICOM files. This file stores '+inttostr(tmp)+' bits per voxel.');
-                           lDicomData.Storedbits_per_pixel := tmp;
-                           lImageFormatOK := false;{ }
-                       end;
-                  end;*)
-                  remaining := 0;
-          			 end;
-          $0102: begin info := 'High Bit';
-				 if remaining = 4 then
-                    tmp := read32(fp,lrOK)
-                 else
-                     tmp := read16(fp,lrOK);
-                                        if not lrOK then
-                                           goto 666;
-                  remaining := 0;
-                 end;
-          $0103: begin
-                 info := 'Pixel Representation';
-                 if remaining = 2 then begin
-                  tmp := read16(fp,lrOK);
-                  //1= signed, 0=unsigned...
-                  if tmp = 1 then
-                    lDicomData.SignedData := true;
-                  if tmp = 0 then
-                    lDicomData.SignedData := false;
-                  remaining := 0;
-                 end;
-            end;
-          $0104: info := 'Smallest Valid Pixel Value';
-          $0105: info := 'Largest Valid Pixel Value';
-          $0106: begin
-          //xlDicomData.MinIntensitySet:= true;
-                 info := 'Smallest Image Pixel Value';
-                 tmp := read16(fp,lrOK);
-                 if not lrOK then goto 666;
-                 //xlDicomData.Minintensity := tmp;
-                  //if >32767 then there will be wrap around if read as signed value!
-                  remaining := 0;
-                 end;
-		  $0107: begin
-                 info := 'Largest Image Pixel Value';
-               if remaining = 4 then
-                 tmp := read32(fp,lrOK)
-               else
-                 tmp := read16(fp,lrOK);
-                 if not lrOK then goto 666;
-                 //xlDicomData.Maxintensity := tmp;
-                  //if >32767 then there will be wrap around if read as signed value!
-                  remaining := 0;
-                 end;
-          $120: info := 'Pixel Padding Value';
-          $200: info := 'Image Location [ret]';
-          $1040: begin t := _string; info := 'Pixel Intensity Relationship'; end;
-          $1050: begin
-              info := 'Window Center';
-             if e_len > 0 then begin
-             readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-              if not lrOK then goto 666;
-              e_len := 0;      remaining := 0;
-             //xlDICOMdata.WindowCenter := round(lfloat1);
-             end;
-          end;{float}
-          $1051: begin info := 'Window Width';
-            if e_len > 0 then begin
-             readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-              if not lrOK then goto 666;
-              e_len := 0;
-			  remaining := 0;
-             //xlDICOMdata.WindowWidth := round(lfloat1);
-            end; //ignore empty elements, e.g. LeadTech's image6.dic
-  end;
-          $1052: begin t := _string;info :='Rescale Intercept';
-             readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-              if not lrOK then goto 666;
-              e_len := 0;      remaining := 0;
-             lDICOMdata.intenIntercept := lfloat1;
-             //if (lDICOMdata.nOrder > 0) and (lDICOMdata.nOrder < kMaxOrderVal) then
-             //     lDICOMdata.OrderIntercept[lDICOMdata.nOrder] := lfloat1;
-          end;  {float}
-
-          $1053:begin
-             t := _string; info :=  'Rescale Slope';
-             readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-              if not lrOK then goto 666;
-              e_len := 0;      remaining := 0;
-             if lFloat1 < 0.000000001 then begin
-                lFLoat1 := 1; //misused in some images, see IMG000025
-             end;
-             lDICOMdata.intenScale := lfloat1;
-             //if (lDICOMdata.nOrder > 0) and (lDICOMdata.nOrder < kMaxOrderVal) then
-             //     lDICOMdata.OrderSlope[lDICOMdata.nOrder] := lfloat1;
-                     end; {float}
-          $1054:begin t := _string; info := 'Rescale Type';end;
-          $1100: info := 'Gray Lookup Table [ret]';
-          $1101: begin  info := 'Red Palette Descriptor'; TmpStr := ReadStr(fp, remaining,lrOK,lJunk);
-                     if not lrOK then goto 666;
-e_len := 0; remaining := 0; end;
-          $1102: begin info := 'Green Palette Descriptor'; TmpStr := ReadStr(fp, remaining,lrOK,lJunk);
-                     if not lrOK then goto 666;
-e_len := 0; remaining := 0; end;
-          $1103: begin info := 'Blue Palette Descriptor'; TmpStr := ReadStr(fp, remaining,lrOK,lJunk);
-                     if not lrOK then goto 666;
-e_len := 0; remaining := 0; end;
-         $1199: begin
-                info := 'Palette Color Lookup Table UID';
-         end;
-          $1200: info := 'Gray Lookup Data [ret]';
-          $1201, $1202,$1203: begin
-                 case element of
-                      $1201: info := 'Red Table'; {future}
-                      $1202: info := 'Green Table'; {future}
-                      $1203: info := 'Blue Table'; {future}
-                 end;
-
-                 if dFilePos(fp) > (filesz-remaining) then
-                    goto 666;
-                 if not lReadColorTables then begin
-                    dSeek(fp, dFilePos(fp) + remaining);
-                 end else begin {load color}
-                   width := remaining div 2;
-
-                   if width > 0 then begin
-                     getmem(lWordRA,width*2);
-                     for i := (width) downto 1 do
-                         lWordRA^[i] := read16(fp,lrOK);
-                     //value := 159;
-                     value := lWordRA^[1];
-					max16 := value;
-  	                min16 := value;
-                     for i := (width) downto 1 do begin
-                         value := lWordRA^[i];
-                            if value < min16 then min16 := value;
-  	                    if value > max16 then max16 := value;
-                     end; //width..1
-                     if max16 - min16 = 0 then
-                        max16 := min16+1; {avoid divide by 0}
-                      if (lDicomData.Allocbits_per_pixel <= 8) and (width > 256) then width := 256; //currently only accepts palettes up to 8-bits
-                     GetMem( lColorRA, width );(**)
-                     for i := width downto 1 do
-                         lColorRA^[i] := (lWordRA^[i] shr 8) {and 255};
-                     FreeMem( lWordRA );
-                     case element of
-                          $1201: begin
-                             red_table_size := width;
-                             red_table   :=lColorRA;;
-                          end;
-                          $1202: begin
-                             green_table_size := width;
-                             green_table   :=lColorRA;;
-                             end;
-                          else {x$1203:} begin
-                             blue_table_size := width;
-                             blue_table   :=lColorRA;;
-                          end; {else}
-                     end; {case}
-				   end; //width > 0;
-                   if odd(remaining) then
-                      dSeek(fp, dFilePos(fp) + 1{remaining});
-                 end; {load color}
-                 tmpstr := 'Custom';
-                 remaining := 0;
-                 e_len := 0; {show tempstr}
-          end;
-          $1221, $1222,$1223: begin
-              info := 'Color Palette ['+inttostr(dFilePos(fp))+']';
-              (*xcase element of
-                   $1221: begin
-                           lDicomData.RLEredOffset:= dFilePos(fp);
-                           lDicomData.RLEredSz:= e_len;
-                   end;
-                   $1222: begin
-                           lDicomData.RLEgreenOffset:= dFilePos(fp);
-                           lDicomData.RLEgreenSz:= e_len;
-                   end;
-                   $1223: begin
-                           lDicomData.RLEblueOffset:= dFilePos(fp);
-                           lDicomData.RLEblueSz:= e_len;
-                   end;
-              end;*)//Case set offset and length
-
-              tmpstr := inttostr(e_len);
-              dSeek(fp, dFilePos(fp)+ e_LEN);
-              e_len := 0;
-		  end;
-
-                    $3002: info := 'LUT Descriptor';
-          $3003: info := 'LUT Explanation';
-          $3006: info := 'LUT Data';
-          $3010: begin
-                 info := 'VOI LUT Sequence';
-                 if (explicitVR) and (lT0=kS) and (lT1=kQ) then
-                    e_len := 8;
-             end;
-     end; //case
-end; //$0028
-       $41: case element of //Papyrus Private Group
-              $1010: begin
-                  info := 'Papyrus Icon [bytes skipped]';
-                  dSeek(fp, dFilePos(fp) + e_len);
-                 tmpstr := inttostr(e_len);
-                 remaining := 0;
-                 e_len := 0;
-              end; //element $0041:$1010
-              $1015: begin
-
-                  info := 'Papyrus Slices';
-                  (*Papyrus format is buggy - see lsjpeg.pas for details, therefore, I have removed extensive support
-                  if e_len = 2 then begin
-                     lDicomData.XYZdim[3]   := read16(fp,lrOK);
-                     if not lrOK then goto 666;
-                  end;
-				  if lDicomData.XYZdim[3] < 1 then lDicomData.XYZdim[3] := 1;
-                  if {(false) and }(lDicomData.XYZdim[3] > 1) and (lReadJPEGtables) and (gECATJPEG_table_entries = 0) then begin
-                     //Papyrus multislice files keep separate DICOM headers for each slice within a DICOM file
-                     lPapyrusnSlices := lDicomData.XYZdim[3];
-                     lPapyrusSlice := 0;
-                     //lPapyrusData := lDicomData;
-                    gECATJPEG_table_entries := lDICOMdata.XYZDim[3];
-                    getmem (gECATJPEG_pos_table, gECATJPEG_table_entries*sizeof(longint));
-                    getmem (gECATJPEG_size_table, gECATJPEG_table_entries*sizeof(longint));
-                 end else
-                  lDicomData.XYZdim[3] := 1;
-                  tmpstr := inttostr(lDicomData.XYZdim[3]);
-                  remaining := 0;
-                  e_len := 0;*)
-              end; //element $0041:$1015
-              $1050: begin
-                     info := 'Papyrus Bizarre Element'; //bizarre osiris problem
-                     if (dfilepos(fp)+e_len)=  (filesz) then
-                        e_len := 8;
-              end; //element $0041:$1050
-       end; //group $0041: Papyrus
-
-     $43: begin
-
-          if lDicomData.ManufacturerID = kGEID then begin
-             case element of
-                  $1039,$A039: begin
-                          // 0043,1039 (or 0043,a039). b value (as the first number in the string).
-
-                          info := 'GE Bvalue';
-                          if e_len > 0 then begin
-                             readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-                             if not lrOK then goto 666;
-                             e_len := 0;      remaining := 0;
-                             lDICOMdata.DTI[1].bval := round(lfloat1);
-                             lDICOMdata.nDTIdir := 1;
-                          end; //e_len>0
-                  end;//1039 or Ao39
-                    end;//Case
-          end; //Manufacturer = GE
-          end;//$0043 - GE bvalues
-
-     $54: case element of
-          $0: info := 'Nuclear Acquisition Group Length';
-          $11: info := 'Number of Energy Windows';
-          $21: info := 'Number of Detectors';
-          $51: info := 'Number of Rotations';
-          $80: begin info :=  'Slice Vector'; TmpStr := ReadStr(fp, remaining,lrOK,lJunk);           if not lrOK then goto 666;
- e_len := 0; remaining := 0; end;
-		  $81: info := 'Number of Slices';
-          $202: info := 'Type of Detector Motion';
-          $400: info := 'Image ID';
-
-          end;
-     $2010 :
-        case element of
-             $0: info := 'Film Box Group Length';
-             $100: info := 'Border Density';
-        end;
-      $4000 : info := 'Text';
-     $0029 : begin
-		case element of
-                $1010: begin
-			  //lSiemensMosaic0029_1010:= true;
-        if (lDicomData.kV = 0) then begin //Siemens uses 0029:1010 for both CT and MRI, but only MRI is in CSA format
-                lDicomData.CSAImageHeaderInfoPos := (dFilePos(fp));
-                lDicomData.CSAImageHeaderInfoSz := e_len;
-        end;
-			  info := 'Private Sequence Delimiter ['+inttostr(dFilePos(fp))+']';
-		  	  if not lImageFormatOK  then
-            time_to_quit := TRUE;
-
-                          //x(lDicomData.RunLengthEncoding) or ( ((lDicomData.JPEGLossycpt) or (lDicomData.JPEGLosslesscpt)) and (gECATJPEG_table_entries >= lDICOMdata.XYZdim[3]))}
-
-			  dSeek(fp, dFilePos(fp) + e_len);
-				 tmpstr := inttostr(e_len);
-				 remaining := 0;
-				 e_len := 0; {show tempstr}
-		 end;
-		 $1053: begin
-				info :='Philips Scale Slope';
-				readfloats (fp, remaining, lDummyStr, lfloat1, lfloat2, lROK);
-			  if not lrOK then goto 666;
-			  e_len := 0;      remaining := 0;
-			 lPhilipsScaleSlope := lfloat1;
-				{if e_len = 4 then begin
-				   lPhilipsScaleSlope := read32r(fp,lrOK);
-				   TmpStr := floattostr(lPhilipsScaleSlope);
-				   t := _string;
-
-				   if not lrOK then goto 666;
-				   e_len := 0;
-				   remaining := 0;
-				end;  }
-		 end;
-
-
-		 else begin
-		 end;
-		END;
-	 END; //gROUP 0029
-
-	 (* $0045 : begin
-		case element of
-			 $103B: begin
-				 msg('0045:103B');
-			 end; //element $1010
-
-		end; //CASE...element
-	  end; //group 0045
-           *)
-	  $0089 : begin
-		case element of
-			 $1010: begin
-				 e_len := 0;
-				 lProprietaryImageThumbnail := true;
-				 //lImageFormatOK := false;
-			 end; //element $1010
-			 $1020: begin
-				 //thoravision files
-
-				 if e_len > 12 then
-					e_len := 0;
-				 //lProprietaryImageThumbnail := true;
-				 //lImageFormatOK := false;
-			 end; //element $1010
-
-		end; //CASE...element
-	  end; //group 0089
-
-  	  $2001 : begin
-              if lDicomData.ManufacturerID = kPhilipsID then begin
-		case element of
-
-                     $1003: begin //bvalue
-                            if e_len = 4 then begin
-                               if lDICOMdata.nDTIdir < kMaxDTIdir then
-                                  inc(lDICOMdata.nDTIdir);
-                               lDICOMdata.DTI[lDICOMdata.nDTIdir].bval := round(read32r(fp,lrOK));
-                               TmpStr := inttostr(lDICOMdata.DTI[lDICOMdata.nDTIdir].bval);
-                               t := _string;
-                               info :='DTI b-val';
-                               if not lrOK then goto 666;
-                               e_len := 0;      remaining := 0;
-                            end; //e_len = 4
-                           
-                     end; //element 1003
-                     $100B: begin
-			info := 'philips: slice orientation';t := _string;
-			TmpStr := '';
-			DICOMHeaderString(TmpStr);
-			lDicomData.PhilipsSliceOrient := TmpStr;
-			AplhaNumericStrDICOM (lDicomData.PhilipsSliceOrient);
-		        end;//PhilipsSliceOrient
-			$1018: begin
-				   if e_len = 4 then begin
-					info :='number of slices';
-					lDicomData.SlicesPer3DVol := read32(fp,lrOK);
-					//uninterleave data
-					e_len := 0; remaining := 0;
-					if lResearchMode then
-						lDicomData.SeriesNum   := lDicomData.SeriesNum + 50; //do not jumble research recons and normal images
-					end; //e_len = 4
-                                        TmpStr := floattostr(lDicomData.SlicesPer3DVol);
-				end; //1018
-
-                       $102D: begin
-                              ///Apr2007
-
-                                   if e_len = 2 then begin
-                                      lnSlicePerVol := read16(fp,lrOK);
-                                      e_len := 0; remaining := 0;
-                                   end;
-				   //fx(213,lnSlicePerVol);
-				end; //102D
-
-                       $105F: begin //Philips Stack Sequence
-
-                              if e_len > 8 then e_len := 8;
-				end; //105F
-		end;
-              end; //if manufacturer = Philips
-	  end;
-
-		  //2001,1004)
-
-	  $2005 : begin
-
-
-              //if lDicomData.ManufacturerID = kPhilipsID then Msg(inttohex(element,4));
-              if lDicomData.ManufacturerID = kPhilipsID then begin
-		case element of
-      { $140F: begin
-        lInside2005140F := true;
-
-      end;}
-			 $100E: begin
-				if e_len = 4 then begin
-				   lPhilipsScaleSlope := read32r(fp,lrOK);
-				   TmpStr := floattostr(lPhilipsScaleSlope);
-				   t := _string;
-				   info :='Philips Scale Slope';
-				   if not lrOK then goto 666;
-				   e_len := 0;      remaining := 0;
-				end;
-			 end; //element $1010
-
-             $1071: begin
-
-				if e_len = 4 then begin
-				   lDicomData.AngulationAP := read32r(fp,lrOK);
-				   TmpStr := floattostr(lDicomData.AngulationAP);
-				   t := _string;
-				   info :='angulation midslice, AP (degrees)';
-				   if not lrOK then goto 666;
-				   e_len := 0;      remaining := 0;
-				end;
-			 end; // Philips AP angulation : -8.74086
-             $1072: begin
-				if e_len = 4 then begin
-				   lDicomData.AngulationFH := read32r(fp,lrOK);
-				   TmpStr := floattostr(lDicomData.AngulationFH);
-				   t := _string;
-				   info :='angulation midslice, FH (degrees)';
-				   if not lrOK then goto 666;
-				   e_len := 0;      remaining := 0;
-				end;
-			 end; // Philips Philips FH angulation : -3.53147
-             $1073: begin
-				if e_len = 4 then begin
-				   lDicomData.AngulationRL := read32r(fp,lrOK);
-				   TmpStr := floattostr(lDicomData.AngulationRL);
-				   t := _string;
-				   info :='angulation midslice, RL (degrees)';
-				   if not lrOK then goto 666;
-				   e_len := 0;      remaining := 0;
-				end;
-			 end; // Philips RL angulation
-             $10b0: begin
-                if e_len = 4 then begin
-                   lDICOMdata.DTI[lDICOMdata.nDTIdir].v1 := read32r(fp,lrOK);
-				   TmpStr := floattostr(lDICOMdata.DTI[lDICOMdata.nDTIdir].v1);
-				   t := _string;
-                   info :='Gradient vector [x]';
-                   if not lrOK then goto 666;
-                   e_len := 0;      remaining := 0;
-                end; //e_len = 4
-             end; //element 10b0
-             $10b1: begin
-                if e_len = 4 then begin
-                   lDICOMdata.DTI[lDICOMdata.nDTIdir].v2 := read32r(fp,lrOK);
-				   TmpStr := floattostr(lDICOMdata.DTI[lDICOMdata.nDTIdir].v2);
-				   t := _string;
-                   info :='Gradient vector [y]';
-                   if not lrOK then goto 666;
-                   e_len := 0;      remaining := 0;
-                end; //e_len = 4
-             end; //element 10b1
-             $10b2: begin
-                if e_len = 4 then begin
-                   lDICOMdata.DTI[lDICOMdata.nDTIdir].v3 := read32r(fp,lrOK);
-				   TmpStr := floattostr(lDICOMdata.DTI[lDICOMdata.nDTIdir].v3);
-				   t := _string;
-                   info :='Gradient vector [z]';
-                   //fx(lDICOMdata.DTI[lDICOMdata.nDTIdir].v1,lDICOMdata.DTI[lDICOMdata.nDTIdir].v2,lDICOMdata.DTI[lDICOMdata.nDTIdir].v3);
-                   if not lrOK then goto 666;
-                   e_len := 0;      remaining := 0;
-                end; //e_len = 4
-             end; //element 10b2
-		end; //CASE...element
-          end; //if Manufacturer = Philips
-	  end; //group 2005
-          $5200 : begin
-                case element of
-                    $9230: begin
-                           if (lDicomData.ManufacturerID = kPhilipsID) and (orientation_not_visible( lDICOMdata))then
-                              read_philips_hidden(lFilename, dFilePos(fp),e_len,lDICOMdata);
-                    end  //element 9230
-                end; //case element
-         end; //group 5200
-          $5400 : begin
-                case element of
-                    $0100: begin
-                      //can not convert sound files to images 12/2012
-                      lImageFormatOK := false;
-                      msg('Note: the DICOM file '+lFileName+' stores a waveform sequence (e.g. ECG) that will not be converted to an image');
-                      info :='WaveformSequence';
-                      //fx(lDICOMdata.DTI[lDICOMdata.nDTIdir].v1,lDICOMdata.DTI[lDICOMdata.nDTIdir].v2,lDICOMdata.DTI[lDICOMdata.nDTIdir].v3);
-                      if not lrOK then goto 666;
-                        e_len := 0;      remaining := 0;
-                    end  //element 0100
-                end; //case element
-         end; //group 5400
-     $DDFF : begin
-               case element of
-                    $00E0: begin
-		           //For papyrus multislice format: if (lPapyrusSlice >=  lPapyrusnSlices) then
-			   time_to_quit := TRUE;
-                      end;
-               end;
-            end;
-     $FFFE : begin
-        case element of
-        $E000 : begin
-          inc(lIndent);
-          lInside00209113 := (lprevGroup = $0020) and (lprevelement = $9113);
-          lInside2005140F  := (lprevGroup = $2005) and (lprevelement = $140F);
-         // if (lInside00209113) then fx(333);
-        (*iif lJPEGEntries > 17 then
-		   lTestError := true;
-
-
-        if not lProprietaryImageThumbnail then begin
-         f (lReadJPEGtables) and ((lDICOMdata.RunLengthEncoding) or (lDICOMdata.JPEGLossyCpt) or (lDICOMdata.JPEGLosslessCpt)) and (not lFirstFragment) and (e_len > 1024) {1384} and ( (e_len+dFilePos(fp)) <= FileSz) then begin
-           //first fragment is the index table, so the previous line skips the first fragment
-           if (gECATJPEG_table_entries = 0) then begin
-              gECATJPEG_table_entries := lDICOMdata.XYZDim[3];
-              getmem (gECATJPEG_pos_table, gECATJPEG_table_entries*sizeof(longint));
-              getmem (gECATJPEG_size_table, gECATJPEG_table_entries*sizeof(longint));
-           end;
-           if lJPEGentries < gECATJPEG_table_entries then begin
-               inc(lJPEGentries);
-               gECATJPEG_pos_table^[lJPEGEntries] := dFilePos(fp);
-               gECATJPEG_size_table^[lJPEGEntries] := e_len;
-           end;
-	   	end;
-
-        if (lDICOMdata.CompressOffset =0) and ( (e_len+dFilePos(fp)) <= FileSz) and  (e_len > 1024){ALOKA} then begin
-              lDICOMdata.CompressOffset := dFilePos(fp);
-              lDICOMdata.CompressSz := e_len;
-        end;
-        //if e_len > lDICOMdata.CompressSz then lDICOMdata.CompressSz := e_len;
-if (e_len > 1024) and (lDICOMdata.CompressSz=0) then begin //ABBA RLE ALOKA
-            //Time_To_Quit := true;//ABBA
-            lDICOMdata.CompressSz := e_len;
-           lDICOMdata.CompressOffset := dFilePos(fp);
-end;
-        if  (lFirstFragment) or ((e_len > lDICOMdata.CompressSz) and not (lDicomData.RunLengthEncoding)) then
-           lDICOMdata.CompressOffset := dFilePos(fp);
-        if  (e_len > lDICOMdata.CompressSz)  and  (e_len > 1024){ALOKA} then
-           lDICOMdata.CompressSz := e_len;
-         lFirstFragment := false;
-              lDICOMdataBackUp := lDICOMData;
-
-		   if (gECATJPEG_table_entries = 1) then begin //updatex
-               gECATJPEG_size_table^[1] := lDICOMdata.CompressSz;
-               gECATJPEG_pos_table^[1] := lDICOMdata.CompressOffset;
-           end; //updatex
-
-end; //not proprietaryThumbnail
-lProprietaryImageThumbnail := false; //1496
-         *)
-          lFirstFragment := false;//Dec09
-          lDICOMdataBackUp := lDICOMData;//Dec09
-
-         if ((e_len > 1024) and ((lDicomData.JPEGLosslessCpt)) or (e_len >= (lDicomData.XYZdim[1]*lDicomData.XYZdim[2]))){Apr 2011} and (lDicomData.XYZdim[1]> 1) then begin
-            lDICOMdata.CompressOffset := dFilePos(fp);
-            lDICOMdata.CompressSz  := e_len;
-            
-            Time_To_Quit := true;
-            //msg('abba'+inttostr(lDICOMdata.CompressOffset)+'  '+inttostr(lDICOMdata.CompressSz));
-         end;
-              info := 'Image Fragment ['+inttostr(dFilePos(fp))+']';
-
-         if  (dFilePos(fp) + e_len) >= filesz then
-            Time_To_Quit := true;
-              dSeek(fp, dFilePos(fp) + e_len);
-                 tmpstr := inttostr(e_len);
-                 remaining := 0;
-                 e_len := 0;
-              end;
-       $E0DD : begin
-              if (lIndent > 0) then dec(lIndent);
-               lInside00209113 := false;
-              lInside2005140F := false;
-              info := 'Sequence Delimiter';
-              if (lDICOMdata.XYZdim[1]<lDICOMdataBackUp.XYZdim[1]) then begin
-                 lDICOMData := lDICOMdataBackUp;
-                 dSeek(fp, dFilePos(fp) + e_len);
-                 //lDICOMData := lDICOMdataBackUp;
-              end else if not lImageFormatOK then  begin
-              //x(lDicomData.RunLengthEncoding) or ( ((lDicomData.JPEGLossycpt) or (lDicomData.JPEGLosslesscpt)) and (gECATJPEG_table_entries >= lDICOMdata.XYZdim[3])) then
-                  time_to_quit :=  TRUE;
-              end;
-             //RLE ABBA
-             if (e_len = 0)  then begin //ALOKA
-                explicitVR := true;
-                time_to_quit :=  FALSE;//RLE16=false
-             end;
-             //END
-
-              dSeek(fp, dFilePos(fp) + e_len);
-              tmpstr := inttostr(e_len);
-              remaining := 0;
-              e_len := 0;
-              end;
-        end;
-		end; 
-        $FFFC : begin
-              dSeek(fp, dFilePos(fp) + e_len);
-                 tmpstr := inttostr(e_len);
-                 remaining := 0;
-                 e_len := 0;
-              end;
-	$72FF : case element of
-		 $1041: time_to_quit := TRUE;
-	end; //case 72FF
-      $7FE0 :
-        case element of
-        	$00 :  begin
-           info := 'Pixel Data Group Length';
-           if not lImageFormatOK then time_to_quit := TRUE;
-           end;
-          $10 :  begin
-              info := 'Pixel Data';
-              TmpStr := inttostr(e_len);
-              //Showmsg(inttostr(ExpectedDicomBytes(lDicomData) ) +'  '+ inttostr(e_len));
-              if ((ExpectedDicomBytes(lDicomData) )  > e_len) or (lDICOMdata.XYZdim[1]<lDICOMdataBackUp.XYZdim[1]) then begin
-                 lDICOMData := lDICOMdataBackUp;
-				          dSeek(fp, dFilePos(fp) + e_len);
-				          //lDICOMData := lDICOMdataBackUp;
-			      end else if {(not lDicomData.RunLengthEncoding) and} (not lDicomData.JPEGLossycpt) and (not lDicomData.JPEGLosslesscpt) then begin
-				      time_to_quit := TRUE;
-				 //xlDicomData.ImageSz := e_len;
-
-			  end;
-			  e_len := 0;
-
-		  end;
-
-
-		  end;
-	  else
-		begin
-		  if (group >= $6000) AND (group <= $601e) AND ((group AND 1) = 0)
-			then  begin
-					  info := 'Overlay'+inttostr(dfilepos(fp))+'x'+inttostr(e_len);
-				end;
-		  if element = $0000 then info := 'Group Length';
-		  if element = $4000 then info := 'Comments';
-				end;
-	end;
-lStr := '';
-
-  1234:
-     lprevGroup :=  Group;
-     lprevElement := element;
-if (Time_TO_Quit) and (not lImageFormatOK) then begin
-   lHdrOK := true;
-   goto 666;
-end;
-
-//Msg(inttohex(group,4) +':'+inttohex(element,4) +'   '+inttostr(e_len)+'@'+ inttostr(dfilepos(fp)));
-
- if (e_len + dfilepos(fp)) > FileSz then begin//patch for GE files that only fill top 16-bytes w Random data
-	e_len := e_len and $FFFF;
- end;
-
-	if (e_len > 131072) then begin
-		//goto 666;
-	end;//zebra
-	if (NOT time_to_quit) AND (e_len > 0) and (remaining > 0) then begin
-	 if (e_len + dfilepos(fp)) > FileSz then begin
-		if not lImageFormatOK(*x(lDICOMdata.GenesisCpt) or (lDICOMdata.JPEGlosslessCpt) or (lDICOMdata.JPEGlossyCpt)*) then
-		  lHdrOK := true
-		else begin
-                     Msg('dcm Error: not a DICOM image: '+lFilename);
-                     {Msg('Diagnostics saved as: c:\dcmcrash.txt');
-                     //diagnostics
-                     assignfile(lTextF,'c:\dcmcrash.txt');
-                     Filemode := 0;
-                     rewrite(lTextF);
-                     Write(lTextF,lDynStr);
-                     closefile(lTextF); }
-
-                     //Msg(inttohex(group,4) +':'+inttohex(element,4) +'   '+inttostr(e_len)+'@'+ inttostr(dfilepos(fp)));
-                end;
-		goto 666;
-	 end;
-
-	 if e_len > 0 then begin
-		GetMem( buff, e_len);
-	 dBlockRead(fp, buff, e_len, n);
-	 if lVerboseRead then
-	  case t of
-		unknown :
-			case e_len of
-			1 : lStr := ( IntToStr(Integer(buff[0])));
-			2 : Begin
-					if lDicomData.little_endian <> 0
-					then i := Integer(buff[0]) + 256*Integer(buff[1])
-					else i := Integer(buff[0])*256 + Integer(buff[1]);
-				  lStr :=( IntToStr(i));
-							end;
-			4 : Begin
-					if lDicomData.little_endian <> 0
-					then i :=               Integer(buff[0])
-							  +         256*Integer(buff[1])
-							  +     256*256*Integer(buff[2])
-							  + 256*256*256*Integer(buff[3])
-					else i :=   Integer(buff[0])*256*256*256
-							  + Integer(buff[1])*256*256
-							  + Integer(buff[2])*256
-							  + Integer(buff[3]);
-				  lStr := (IntToStr(i));
-				end;
-				else begin
-						 if e_len > 0 then begin
-							for i := 0 to e_len-1 do begin
-							 if Char(buff[i]) in ['+','-','/','\',' ', '0'..'9','a'..'z','A'..'Z'] then
-								   lStr := lStr+(Char(buff[i]))
-								else
-									lStr := lStr+('.');
-							end;
-						 end else
-							 lStr := '*NO DATA*';
-			end;
-		   end;
-
-		i8, i16, i32, ui8, ui16, ui32,
-		_string  : for i := 0 to e_len-1 do
-					if Char(buff[i]) in ['+','-','/','\',' ', '0'..'9','a'..'z','A'..'Z']
-						then lStr := lStr +(Char(buff[i]))
-					  else lStr := lStr +('.');
-	  end;
-	  FreeMem(buff);
-
-	  end;
-	end
-	else if e_len > 0 then lStr := (IntToStr(tmp))
-	else  begin
-		 lStr := TmpStr;
-	end;
- (*if (lGrp)  then if MessageDlg(lStr+'= '+info+' '+IntToHex(where,4)+': ('+IntToHex(group,4)+','+IntToHex(element,4)+')'+IntToStr(e_len)+'. Continue?',
-	mtConfirmation, [mbYes, mbNo], 0) = mrNo then  GOTO 666;
-   *)
- //if (Group > $2005)  then
- //   msg(info+' '+IntToStr(where)+': ('+IntToHex(group,4)+','+IntToHex(element,4)+')'+IntToStr(e_len));
-{$IFDEF Troubleshoot}
-      Msg( IntToHex(group,4)+','+IntToHex(element,4)+','+Info+'='+lStr);//+' Offset'+inttostr(dfilepos(fp))+' Length'+inttostr(e_len));
-{$ENDIF Troubleshoot}
-
-
-   if lverboseRead then begin
-if length(lDynStr) > kMaxTextBuf then begin
-   if not lTextOverFlow  then begin
-	  lDynStr := lDynStr + 'Only showing the first '+inttostr(kMaxTextBuf) +' characters of this LARGE header';
-	  lTextOverFlow := true;
-
-   end;
-   //goto 666;
-end else
-   lDynStr := lDynStr+IntToHex(group,4)+','+IntToHex(element,4)+','+Info+'='+lStr+kCR ;
-
-    Msg(AddIndent(lIndent)+IntToHex(group,4)+','+IntToHex(element,4)+','+inttostr(e_len)+'@'+inttostr(dfilepos(fp))+','+Info+'='+lStr);
-end; //not verbose read
-
-  end;	// end for
-
-  lDicomData.ImageStart := dfilepos(fp);
-
-  if lBigSet then begin
-	  if lBig then lDicomData.little_endian := 0
-	  else lDicomData.little_endian := 1;
-  end;
-  lHdrOK := true;
-if lByteSwap then begin
-	ByteSwap(lDicomdata.XYZdim[1]);
-	ByteSwap(lDicomdata.XYZdim[2]);
-	if lDicomdata.XYZdim[3] <> 1 then
-	 ByteSwap(lDicomdata.XYZdim[3]);
-	 //xByteSwap(lDicomdata.SamplesPerPixel);
-	 ByteSwap(lDicomData.Allocbits_per_pixel);
-	 //xByteSwap(lDicomData.Storedbits_per_pixel);
-end;
-
-if (lDICOMdata.ManufacturerID = kPhilipsID) and (l4DDistanceBetweenSliceCenters <> kNaNsingle) then //some 3D and 4D Philips files do not correctly report interslice distance in 0018,0088 and 0018,0050...
-   lDICOMdata.XYZmm[3] := (l4DDistanceBetweenSliceCenters);
-if (lPrefs.PhilipsPrecise) and (lManufacturerIsPhilips) and (lPhilipsScaleSlope <> 0) then begin
-  PhilipsPrecise (lDicomData.IntenScale, lDICOMdata.intenIntercept,lPhilipsScaleSlope, lDicomData.IntenScale, lDICOMdata.intenIntercept,true);
-end; //if PARprecise
-if (lDICOMdata.ManufacturerID = kPhilipsID) and (lDICOMdata.nDTIdir > 1) then begin
-   lGELX := true;
-   for i := 1 to lDICOMdata.nDTIdir do
-       if lDICOMdata.DTI[lDICOMdata.nDTIdir].bval <> lDICOMdata.DTI[1].bval then
-          lGELX := false;//multiple B0 directions
-   if lGELX then
-      lDICOMdata.nDTIdir := 1;
-   lGELX := false;
-end;
-if (lMatrixSz > 1) and (lDicomData.CSAImageHeaderInfoPos > 0) and (lDicomData.CSAImageHeaderInfoSz > 0) and
-   not (((lDicomdata.XYZdim[1] mod lMatrixSz) = 0) and  ((lDicomdata.XYZdim[2] mod lMatrixSz) = 0)) then begin
-     //Slow method for non-square Siemens matrices - 0018:1310 based on phase/freq, so it is easier to read CSA to decode rows/columns
-
-       GetCSAImageHeaderInfo (lFilename, lDicomData.CSAImageHeaderInfoPos ,lDicomData.CSAImageHeaderInfoSz, lTempInt,lDICOMdata.SiemensMosaicX,lDICOMdata.SiemensMosaicY, lfloat1,lfloat2,lfloat3)
-end else
- if (lMatrixSz > 1) and ((lDicomdata.XYZdim[1] mod lMatrixSz) = 0) and ((lDicomdata.XYZdim[2] mod lMatrixSz) = 0) then begin
-
-		if ((lDicomData.XYZdim[1] mod lMatrixSz)=0) then
-		   lDicomData.SiemensMosaicX := lDicomData.XYZdim[1] div lMatrixSz;
-		if ((lDicomData.XYZdim[2] mod lMatrixSz)=0) then
-		   lDicomData.SiemensMosaicY := lDicomData.XYZdim[2] div lMatrixSz;
-		if lDicomData.SiemensMosaicX < 1 then lDicomData.SiemensMosaicX := 1; //1366
-		if lDicomData.SiemensMosaicY < 1 then lDicomData.SiemensMosaicY := 1; //1366
-
-	  if  lOldSiemens_IncorrectMosaicMM then begin //old formats convert size in mm incorrectly - modern versions are correct and include transfer syntax
-		 lDicomdata.XYZmm[1] := lDicomdata.XYZmm[1] * (lDicomdata.XYZdim[1] div lMatrixSz);
-		 lDicomdata.XYZmm[2] := lDicomdata.XYZmm[2] * (lDicomdata.XYZdim[2] div lMatrixSz);
-	  end;
-end else if (lSiemensMosaic0008_0008) and (lPhaseEncodingSteps > 0) and (lPhaseEncodingSteps < lDicomdata.XYZdim[2]) and ((lDicomdata.XYZdim[2] mod lPhaseEncodingSteps) = 0) and ((lDicomdata.XYZdim[2] mod (lDicomdata.XYZdim[2] div lPhaseEncodingSteps)) = 0) then begin
-	//1499c kludge for detecting new Siemens mosaics: WARNING may cause false positives - Siemens fault not mine!
-	lDicomData.SiemensMosaicY :=lDicomdata.XYZdim[2] div lPhaseEncodingSteps;
-	lDicomData.SiemensMosaicX := lDicomData.SiemensMosaicY;  //We also need to assume as many mosaic rows as columns, as Siemens does not save the phase encoding lines in the header...
-end;
- // fx(lnSlicePerVol,lnVol, lDicomData.SlicesPer3DVol,lDicomdata.XYZdim[3]  );
-//fx(lnVol,lnSlicePerVol,lDicomData.SlicesPer3DVol,lDicomdata.XYZdim[3]);
-//fx(lnSlicePerVol,lDicomData.ManufacturerID,kPhilipsID );
-if (lnSlicePerVol > 0) and (lDicomData.ManufacturerID = kPhilipsID) {and (lnVol > 1)} and (lDicomdata.XYZdim[3] > 1) and (lDicomData.SlicesPer3DVol > 0)and ((lDicomdata.XYZdim[3] mod lDicomData.SlicesPer3DVol) = 0)  then begin
-   lDICOMdata.File4D := true;
-   lnVol := lDicomdata.XYZdim[3] div lDicomData.SlicesPer3DVol;
-end;
-if lManufacturerIsBruker then
-   lDicomData.AcquNum := 1; //Bruker varies this for every image
-
-if (lEchoNum > 0) and (lEchoNum < 16) then begin
-    lDicomData.AcquNum := lDicomData.AcquNum + (1000*lEchoNum);
-end;
-
-if lVerboseRead then begin
-                      // lDicomData.PatientPosX, lDicomData.PatientPosY,lDicomData.PatientPosZ
-           Msg ('DICOM data');
-           Msg ('Series/Acquisition/Image/Xpos/YPos/ZPos:'+kTab+inttostr(lDicomData.SeriesNum)+kTab+inttostr(lDicomData.AcquNum)+kTab+inttostr(lDicomData.ImageNum)+kTab+floattostr(lDicomData.PatientPosX)+kTab+floattostr(lDicomData.PatientPosY)+kTab+floattostr(lDicomData.PatientPosZ));
-           Msg ('BPP: '+inttostr(lDicomData.Allocbits_per_pixel));
-           Msg ('XYZ dim:' +inttostr(lDicomData.XYZdim[1])+'/'+inttostr(lDicomData.XYZdim[2])+'/'+inttostr(lDicomData.XYZdim[3])  );
-           Msg ('XYZ mm:'+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[2],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2) );
-           Msg ('DTI bvalue:'+ inttostr(lDICOMdata.DTI[1].bval));
-           Msg ('DTI bvec:'+floattostrf(lDicomData.DTI[1].v1,ffFixed,8,2)+'/'+floattostrf(lDicomData.DTI[1].v2,ffFixed,8,2)+'/'+floattostrf(lDicomData.DTI[1].v3,ffFixed,8,2) );
- end;
- //msg('abba'+inttostr(lDICOMdata.CompressOffset)+'  '+inttostr(lDICOMdata.CompressSz));
-  666:
-  //if not lHdrOk then Msg('zx'+lFilename);
-  if lDiskCacheSz > 0 then
-	 freemem(lDiskCacheRA);
-  if not lHdrOK then lImageFormatOK := false;
-  CloseFile(fp);
-  FileMode := 2; //set to read/write
-  //if kUseDateTimeForID then
-	lDicomData.DateTime := StudyDateTime(lDicomData.StudyDate,lDicomData.StudyTime);
-  if (lDicomData.SiemensMosaicX > 1) then
-  	lDicomData.AcquNum := 1;
-end;
-
-
-end.
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/dicomfast.pas b/dcm2nii_prePARRECDTI/dicomfast.pas
deleted file mode 100755
index 7db0a4a..0000000
--- a/dcm2nii_prePARRECDTI/dicomfast.pas
+++ /dev/null
@@ -1,512 +0,0 @@
-unit dicomfast;
-{$H+}
-//this is x3 faster than the dicomcompat routines, but only works with well-behaved Explicit Little-Endian DICOM
-interface
-//0008,0070,ManufacturerID
-//Next values for Philips
-//Philips - must set 2001,105F length to 8 - allows reading of stack sequence
-//  2005,1071. Philips AP angulation
-//  2005,1072. Philips RL angulation
-//  2005,1073. Philips FH angulation
-//2001,100B Philips slice orientation (TRANSVERSAL, AXIAL, SAGITTAL)
-// Next values for GE
-//0019,10bb (or 0019,a0bb)= X diffusion direction
-//0019,10bc (or 0019,a0bc)= Y diffusion direction
-//0019,10bd (or 0019,a0bd)= Z diffusion direction
-//0018,1312 = phase encoding.
-
-
-uses
-{$IFNDEF FPC}Controls, {$ENDIF}
-   SysUtils,define_types,classes,dicomtypes;
-
-function fast_read_dicom_data(var lDICOMdata: DICOMdata; lOffset: integer;  var lFileName: string): boolean; //x3 faster!
-
-
-implementation
-uses dialogsx;
-{$DEFINE ANON}
-
-function fast_read_dicom_data(var lDICOMdata: DICOMdata; lOffset: integer; var lFileName: string): boolean;
-label
-999;
-const
-     kMaxBuf = (256*256)-1; //bytes
-     kMax16bit = (256*256)-1;
-     kImageType = $0008+($0008 shl 16 );
-     kStudyDate = $0008+($0020 shl 16 );
-     kSeriesDate = $0008+($0021 shl 16 );
-     kAcqDate = $0008+($0022 shl 16 );
-     kCreateDate =  $0008+($0012 shl 16 );
-     kStudyTime = $0008+($0030 shl 16 );
-     kPatientName = $0010+($0010 shl 16 );
-     {$IFDEF ANON} //position and lengths of tags to anonymize
-     kPatientID = $0010+($0020 shl 16 );
-     kPatientDOB = $0010+($0030 shl 16 );
-     kPatientSex = $0010+($0040 shl 16 );
-     kPatientAge = $0010+($1010 shl 16 );
-     kPatientWt = $0010+($1030 shl 16 );
-     {$ENDIF}
-     kSeq = $0018+($0020 shl 16 );
-     kZThick =  $0018+($0050 shl 16 );
-     kTR =  $0018+($0080 shl 16 );
-     kTE =  $0018+($0081 shl 16 );
-     kEchoNum =  $0018+($0086 shl 16 );
-     kZSpacing =  $0018+($0088 shl 16 );
-     kProtocolName =  $0018+($1030shl 16 );
-     kPatientPos = $0018+($5100 shl 16 );
-     kSeriesNum = $0020+($0011 shl 16 );
-     kAcquNum = $0020+($0012 shl 16 );
-     kImageNum = $0020+($0013 shl 16 );
-     kOrientation = $0020+($0037 shl 16 );
-     kLocation = $0020+($1041 shl 16 );
-     kDim3 = $0028+($0008 shl 16 );
-     kDim2 = $0028+($0010 shl 16 );
-     kDim1 = $0028+($0011 shl 16 );
-     kXYSpacing =  $0028+($0030 shl 16 );
-     kPosition = $0020+($0032 shl 16 );
-     knVol =  $0020+($0105 shl 16 );
-     kAlloc = $0028+($0100 shl 16 );
-     kIntercept = $0028+($1052 shl 16 );
-     kSlope = $0028+($1053 shl 16 );
-     kCSAImageHeaderInfo =  $0029+($1010 shl 16 );
-     kSlicesPer3DVol =  $2001+($1018 shl 16 );
-     kTransferSyntax = $0002+($0010 shl 16);
-     kImageStart = $7FE0+($0010 shl 16 );
-     kMaxFloats = 6;
-var
-  vr : array [1..2] of Char;
-  lFailure: boolean;
-   lByteRA: Bytep;
-   lFloatRA: array [1..kMaxFloats] of double;
-   lBufferSz,lPos,lFileSz,lBuffStart: integer;
-   lInFile: file;
-   lBufferError: boolean;
-procedure Str2FloatNum ( lStr: string; lnFloats: integer);
-var
-    lFStr: string;
-    lP,lnF: integer;
-begin
-     if (length(lStr) < 1) or (lnFloats < 1) or (lnFloats > kMaxFloats) then
-        exit;
-     for lnF := 1 to lnFloats do
-         lFloatRA[lnF] := 1;
-     lStr := lStr + ' '; //terminator
-     lFStr := '';
-     lP := 1;
-     lnF:= 0;
-     while lP <= length(lStr) do begin
-           if lStr[lP]  in ['+','-','0'..'9','.','e','E'] then
-              lFStr := lFStr + lStr[lP]
-           else if (lFStr <> '') then begin
-                inc(lnF);
-                //if lnFloats = 6 then showmessage(lFStr);
-                try
-                   lFloatRA[lnF] := strtofloat(lFStr);
-                except on EConvertError do
-                       lFloatRA[lnF] := 1;
-                end;//except
-                if lnF = lnFloats then exit;
-                lFStr := '';
-           end;
-           inc(lP);
-     end;
-end; //function Str2Float
-
-function GetByte (lFilePos: integer): byte;
-var
-   lBufPos: integer;
-begin
-    //the following error checking slows down reads a lot!
-    //a simpler alternative would be to make the buffer size the same size as the entire image...
-    //the current strategy saves memory and is faster for large images with small headers
-    if lFilepos > lFileSz then begin
-        lBufferError := true;
-        result := 0;
-        exit;
-    end;
-    lBufPos := lFilepos - lBuffStart+1;
-    if (lBufPos > lBufferSz) or (lBufPos < 1) then begin //reload buffer
-       if (lFilePos < 0) or (lFilePos > lFileSz) then begin
-          lBuffStart := lFilePos;
-          lBufPos := 1;
-          msg(lFileName);
-          lFailure := true;
-          Msg('Error: buffer overrun in DICOM read.');
-          exit;
-       end;
-       if lFilePos+kMaxBuf > lFileSz then
-          lBufferSz := lFileSz - (lFilePos)
-       else
-           lBufferSz := kMaxBuf; //read remaining
-       //fx(lFilepos,kMaxBuf);
-       AssignFile(lInFile, lFileName);
-       FileMode := 0;  //Set file access to read only
-       Reset(lInFile, 1);
-       seek(lInFile,lFilePos);
-       BlockRead(lInFile, lByteRA^[1], lBufferSz);
-       CloseFile(lInFile);
-       FileMode := 2;
-       lBuffStart := lFilePos;
-       lBufPos := 1;
-    end;
-    result := lByteRA^[lBufPos];
-end;
-
-function ReadInt4: integer;
-begin
-    if lDicomData.little_endian = 0 then
-        result := GetByte(lPos+3)+(GetByte(lPos+2) shl 8)+(GetByte(lPos+1) shl 16)+(GetByte(lPos) shl 24)
-    else
-        result := GetByte(lPos)+(GetByte(lPos+1) shl 8)+(GetByte(lPos+2) shl 16)+(GetByte(lPos+3) shl 24);
-    inc(lPos,4);
-end; //function Read4
-
-procedure ReadGroupElementLength(var lGroupElement,lLength: integer);
-begin
-     lGroupElement := ReadInt4;
-     vr[1] := chr(GetByte(lPos));
-     vr[2] := chr(GetByte(lPos+1));
-     //msg('   '+InttoHex(lGroupElement,8)+'   '+inttostr(lLength)+'   '+VR+ inttostr(GetByte(lPos+2)));
-
-     if (vr[2] < 'A')  then begin //implicit vr with 32-bit length
-        lLength := ReadInt4;
-        exit;
-     end;
-     //if vr = 'UN' then
-     if (vr = 'OB') or (vr = 'OW') or (vr = 'SQ') or (vr = 'UN') then begin  {explicit VR with 32-bit length}
-          lPos := lPos + 4;  {skip 2 byte string and 2 reserved bytes = 4 bytes = 2 words}
-          lLength := ReadInt4;//Ord4(buf[lPos]) + $100 * (buf[lPos+1] + $100 * (buf[lPos+2] + $100 * buf[lPos+3]))
-     end else begin {explicit VR with 16-bit length}
-         if lDicomData.little_endian = 0  then
-             lLength := (GetByte(lPos+3))+(GetByte(lPos+2) shl 8)
-         else
-             lLength := (GetByte(lPos+2))+(GetByte(lPos+3) shl 8);//GetLength := Ord4(buf[i+2]) + $100 * (buf[i+3]);
-         lPos := lPos + 4;  {skip 2 byte string and 2 length bytes = 4 bytes = 2 words}
-     end;
-     // msg(InttoHex(lGroupElement,8)+'   '+inttostr(lLength)+'   '+VR+ inttostr(GetByte(lPos+2)) + 'x'+inttostr(GetByte(lPos+3)) );
-
-end; //procedure ReadGroupElementLength
-
-function DCMStr(lBytes: integer): string;
-var
-   lC: integer;
-begin
-    result := '';
-    if lBytes < 1 then
-       exit;
-    for lC := lPos to (lPos+(lBytes-1)) do
-        result := result + char(GetByte(lC));
-    for lC := 1 to lBytes do
-        if result[lC]  in ['+','-','/','\',' ','0'..'9','a'..'z','A'..'Z','.'] then
-        else
-           result[lC] := ' ';
-end; //function DCMStr
-
-function DCMStr2Int (lBytes: integer): integer;
-var lErr: integer;
-    lStr: string;
-begin
-     lStr := DCMStr(lBytes);
-     Val(lStr,result,lErr);
-end; //function DCMStr2Int
-
-procedure DCMStr2FloatNum (lBytes,lnFloats: integer);
-begin
-     Str2FloatNum (DCMStr(lBytes), lnFloats);
-end; //function DCMStr2Float
-
-function DCMStr2Float (lBytes: integer): single;
-begin
-     DCMStr2FloatNum (lBytes,1);
-     result := lFloatRA[1];
-end; //function DCMStr2Float
-
-procedure DCMStr2Float2 (lBytes: integer; var lF1,lF2: double);
-begin
-     DCMStr2FloatNum (lBytes,3);
-     lF1 := lFloatRA[1];
-     lF2 := lFloatRA[2];
-end; //function DCMStr2Float2
-
-procedure DCMStr2Float3 (lBytes: integer; var lF1,lF2,lF3: double);
-begin
-     DCMStr2FloatNum (lBytes,3);
-     lF1 := lFloatRA[1];
-     lF2 := lFloatRA[2];
-     lF3 := lFloatRA[3];
-end; //function DCMStr2Float3
-
-procedure DCMStr2Float6 (lBytes: integer; var lF1,lF2,lF3,lF4,lF5,lF6: double);
-begin
-     DCMStr2FloatNum (lBytes,6);
-     lF1 := lFloatRA[1];
-     lF2 := lFloatRA[2];
-     lF3 := lFloatRA[3];
-     lF4 := lFloatRA[4];
-     lF5 := lFloatRA[5];
-     lF6 := lFloatRA[6];
-end; //function DCMStr2Float6
-
-function DCMint (lBytes: integer): integer; //read 16 bit short integer
-begin
-     if lBytes <= 2 then
-        result := GetByte(lPos)+(GetByte(lPos+1) shl 8) //shortint vs word?
-     else
-         result := GetByte(lPos)+(GetByte(lPos+1) shl 8)+(GetByte(lPos+2) shl 16)+(GetByte(lPos+3) shl 24);; //byte order??
-end; //function DCMint
-
-{$IFDEF ANON}
-Type
-  TPosLen =  RECORD //peristimulus plot
-    Pos,Len: integer;
-  end;
-procedure InitPosLen(var lPL: TPOsLen);
-begin
-    lPL.Pos := 0;
-    lPL.Len := 0;
-end;
-procedure SetPosLen(var lPL: TPosLen; lP,lL: integer);
-begin
-    lPL.Pos := lP;
-    lPL.Len := lL;
-end;
-
-procedure Anonymize(lStr: string; lPL: TPOsLen{lPos,lLen: integer});
-var
-   lDCMstr: string;
-   lP,lL: integer;
-begin
-     if ((lPL.Pos+lPL.Len) > lBufferSz) or (lPL.Len < 1) or (lPL.Pos < 1) then
-        exit;
-     lDCMStr := '';
-     lL := length(lStr);
-     if lL > lPL.Len then
-        lL := lPL.Len;
-     lP := 1;
-     while lP <= lL do begin
-           lDCMStr := lDCMStr + lStr[lP];
-           inc(lP);
-     end;
-     while lP <= lPL.Len do begin //pad string
-           lDCMStr := lDCMStr + ' ';
-           inc(lP);
-     end;
-     for lP := 1 to lPL.Len do
-          lByteRA^[lPL.Pos+lP] := Ord(lDCMstr[lP]);
-
-end;
-
-(*procedure AnonymizeDate(lStr: string; lPos,lLen: integer);
-var
-   lDCMstr: string;
-   lP,lL,lDateLen: integer;
-begin
-     Anonymize(lStr, lPos,lLen);
-     //put 19730316 into date field -Lauterbur paper published in Nature
-     lDCMstr := '19730316';
-     lDateLen := length(lDCMStr);
-     if ((lPos+lLen) > lBufferSz) or (lLen < lDateLen) or (lPos < 1) then
-        exit;
-     for lP := 1 to lDateLen do
-          lByteRA^[lPos+lP] := Ord(lDCMstr[lP]);
-
-end;*)
-
-{$ENDIF}
-
-var
-   lTempStr,lStr: string;
-   lTemp,lGroupElement,lLength,lEchoNum,lnVol: integer;
-   lResearchMode: boolean;
-   lThick: double;
-   {$IFDEF ANON} //position and lengths of tags to anonymize
-   lCreateDate,lName,lID,lDOB,lSex,lAge,lWt,lStudyDate,lSeriesDate,lAcqDate: TPosLen;
-   {$ENDIF}
-begin //function fast_read_dicom_data
-   {$IFDEF ANON} //position and lengths of tags to anonymize
-   InitPosLen(lName);
-   InitPosLen(lID);
-   InitPosLen(lDOB);
-   InitPosLen(lSex);
-   InitPosLen(lAge);
-   InitPosLen(lWt);
-   InitPosLen(lStudyDate);
-   InitPosLen(lSeriesDate);
-   InitPosLen(lAcqDate);
-   InitPosLen(lCreateDate);
-   {$ENDIF}
-   lFailure := false;
-     lnVol := 1;
-     lEchoNum := 1;
-     lThick := 0;
-     clear_dicom_data(lDicomData);
-     lDicomData.little_endian := 1;
-     result := false;
-     lResearchMode := false;
-     lBufferError := false;
-     lFileSz := FSize(lFilename);
-     lBufferSz := lFileSz-lOffset;
-     if lBufferSz < 512 then begin
-        //showmessage('Error: File too small '+lFilename);
-        exit;
-     end;
-     if lBufferSz > kMaxBuf then
-        lBufferSz := kMaxBuf;
-     GetMem(lByteRA,kMaxBuf);
-     lBufferSz := lBufferSz;
-     AssignFile(lInFile, lFileName);
-     FileMode := 0;  //Set file access to read only
-     Reset(lInFile, 1);
-     seek(lInFile,lOffset);
-     BlockRead(lInFile, lByteRA^[1], lBufferSz);
-     CloseFile(lInFile);
-     FileMode := 2;
-     lBuffStart := lOffset;
-     lPos := lOffset;
-     if lOffset = 128 then begin //DICOM files start with DICM at 128, Siemens shadow headers do not
-        if DCMStr(4) <> 'DICM' then begin
-           Msg(DCMStr(4)+ ' <> DICM');
-           FreeMem(lByteRA);
-           exit;
-        end;
-        lPos := lOffset + 4;//DICM read
-     end;//Offset = 128
-     //next check VR
-     if not( chr(GetByte(lPos+4)) in ['A'..'Z']) or not( chr(GetByte(lPos+5)) in ['A'..'Z']) then
-        Msg('implicit VR untested');
-     //next check Endian
-     lTemp := lPos;
-     ReadGroupElementLength(lGroupElement,lLength);
-     if lLength > kMax16bit then
-        Msg('ByteSwapped');
-     lPos := lTemp;
-     //end VR check
-     while (lDICOMData.imagestart = 0) and (not lBufferError) do begin
-         ReadGroupElementLength(lGroupElement,lLength);
-         if lFailure then goto 999;
-         case lGroupElement of
-                kTransferSyntax: begin
-                     lTempStr := (DCMStr(lLength));
-                     if (length(lTempStr) >= 19) and (lTempStr[19] = '2') then
-                        lDicomData.little_endian := 0;
-                 end;
-                 kImageType : begin
-                            lTempStr := DCMStr(lLength);
-                            //read last word - ver\mosaic -> MOSAIC
-                            lStr := '';
-                            lTemp := length(lTempStr);
-                            while (lTemp > 0) and (lTempStr[lTemp] in ['a'..'z','A'..'Z']) do begin
-                                  lStr := upcase(lTempStr[lTemp])+lStr;
-                                  dec(lTemp);
-                            end;
-                            if lStr = 'MOSAIC' then
-                               lDicomData.SiemensMosaicX := 2; //we need to read numaris for details...
-                 end;
-
-                 kStudyTime : lDicomData.StudyTime := DCMStr(lLength);
-                 {$IFDEF ANON} //position and lengths of tags to anonymize
-                kCreateDate: begin SetPosLen(lCreateDate,lPos,lLength) end;
-                 kSeriesDate: begin SetPosLen(lSeriesDate,lPos,lLength) end;
-                 kAcqDate: begin SetPosLen(lAcqDate,lPos,lLength) end;
-                 kStudyDate: begin SetPosLen(lStudyDate,lPos,lLength) end;
-                 kPatientName : begin SetPosLen(lName,lPos,lLength) end;
-                 kPatientID : begin SetPosLen(lID,lPos,lLength)  end;
-                 kPatientDOB : begin SetPosLen(lDOB,lPos,lLength)  end;
-                 kPatientSex : begin SetPosLen(lSex,lPos,lLength)  end;
-                 kPatientAge : begin SetPosLen(lAge,lPos,lLength)  end;
-                 kPatientWt : begin SetPosLen(lWt,lPos,lLength)  end;
-                 {$ELSE}
-                 kPatientName : lDicomData.PatientName := DCMStr(lLength);
-                 kStudyDate: lDicomData.StudyDate := DCMStr(lLength);
-
-                 {$ENDIF}
-                 kProtocolName : lDicomData.ProtocolName :=DCMStr(lLength);
-                 kPatientPos : lDicomData.PatientPos :=DCMStr(lLength); //should be HFS for Siemens = Head First Supine
-                 kSeriesNum : lDicomData.SeriesNum := DCMStr2Int(lLength);
-                 kAcquNum : lDicomData.AcquNum := DCMStr2Int(lLength);
-                 kSeq: begin
-                     if DCMStr(lLength) = 'RM' then
-                        lResearchMode := True;
-                 end;
-                 kImageNum : lDicomData.ImageNum := DCMStr2Int(lLength);
-                 kDim3 :lDicomData.XYZdim[3] := DCMStr2Int(lLength);
-                 kDim2 : lDicomData.XYZdim[2] := DCMint (lLength);
-                 kDim1 : lDicomData.XYZdim[1] := DCMint (lLength);
-                 kLocation : lDICOMData.Location := DCMStr2Float(lLength);
-                 kAlloc: lDicomData.Allocbits_per_pixel := DCMint (lLength);
-                 kTR : lDicomData.TR := DCMStr2Float(lLength);
-                 kTE: lDicomData.TE := DCMStr2Float(lLength);
-                 kEchoNum: lEchoNum := round (DCMStr2Float(lLength));
-                 kSlope : lDICOMData.IntenScale := DCMStr2Float(lLength);
-                 kIntercept : lDICOMData.IntenIntercept := DCMStr2Float(lLength);
-                 kOrientation : DCMStr2Float6(lLength, lDicomData.Orient[1], lDicomData.Orient[2],lDicomData.Orient[3],lDicomData.Orient[4], lDicomData.Orient[5],lDicomData.Orient[6]);
-                 kPosition : DCMStr2Float3 (lLength,lDicomData.PatientPosX, lDicomData.PatientPosY,lDicomData.PatientPosZ);
-                 knVol: lnVol := round (DCMStr2Float(lLength));
-                 kZThick: begin lThick := DCMStr2Float(lLength); lDICOMData.XYZmm[3] := lThick; end;//used differently by manufacturers
-                 kZSpacing: begin lDICOMData.XYZmm[3] := DCMStr2Float(lLength);
-                                 if  (lThick/2) > lDICOMdata.XYZmm[3]  then
-                                     lDICOMdata.XYZmm[3] := lDICOMdata.XYZmm[3] + lThick
-                           end; //used different by different manufacturers
-                 kXYSpacing: DCMStr2Float2 (lLength,  lDICOMdata.XYZmm[2],  lDICOMdata.XYZmm[1]);
-                 kCSAImageHeaderInfo: begin //order ICE,Acq,Num,Vector
-                   lDICOMdata.CSAImageHeaderInfoPos := lPos;
-                   lDICOMdata.CSAImageHeaderInfoSz :=  lLength;
-                                       end;
-                 kSlicesPer3DVol: lDICOMData.SlicesPer3DVol := DCMint (lLength);
-                 kImageStart: lDICOMData.ImageStart := lPos ; //-1 as indexed from 0.. not 1..
-         end; //Case lGroupElement
-         //Msg(VR+inttohex(lGroupElement and kMax16bit,4) +':'+inttohex( lGroupElement shr 16,4)+'  '+inttostr(lLength)+'@'+inttostr(lPos) );
-         lPos := lPos + (lLength);
-     end; //while imagestart=0 and not error
-     //clean up
-     lDicomData.DateTime := StudyDateTime(lDicomData.StudyDate,lDicomData.StudyTime);
-     if (lDicomData.SiemensMosaicX > 1) then
-  	lDicomData.AcquNum := 1;
-     if (lEchoNum > 1) and (lEchoNum < 16) then
-        lDicomData.AcquNum := lDicomData.AcquNum + (100*lEchoNum);
-     if lResearchMode then
-        lDicomData.SeriesNum   := lDicomData.SeriesNum + 100;
-     if (lDICOMData.SlicesPer3DVol > 0) and (lnVol > 1) and (lDicomdata.XYZdim[3] > 1) and (lDicomData.SlicesPer3DVol > 0)and ((lDicomdata.XYZdim[3] mod lDicomData.SlicesPer3DVol) = 0)  then
-        lDICOMdata.File4D := true;
-     if not lBufferError then
-        result := true;
-     FreeMem(lByteRA);
-     //Remaining portions only if anonymizing
-     {$IFDEF ANON}
-     Msg('Anonymizing DICOM '+extractfilename(lFilename));
-     lBufferSz := lFileSz;
-     GetMem(lByteRA,lBufferSz);
-     //read original
-     AssignFile(lInFile, lFileName);
-     FileMode := 0;  //Set file access to read only
-     Reset(lInFile, 1);
-     //seek(lInFile,1);
-     BlockRead(lInFile, lByteRA^[1], lBufferSz);
-     CloseFile(lInFile);
-     //anonymize...
-     Anonymize ('ANONYMIZED',lName);
-     Anonymize ('ANONYMIZED',lID);
-     Anonymize('19890323',lDOB); //Cold Fusion YYYYMMDD
-     Anonymize('19890323',lStudyDate); //Cold Fusion YYYYMMDD
-     Anonymize('19890323',lAcqDate); //Cold Fusion YYYYMMDD
-     Anonymize('19890323',lSeriesDate); //Cold Fusion YYYYMMDD
-     Anonymize('19890323',lCreateDate); //Cold Fusion YYYYMMDD
-
-     Anonymize('M',lSex);
-     Anonymize('18',lAge);
-     Anonymize('100',lWt);
-     //write anonymized data...
-     assignfile(lInFile, lFileName+'.dcm');
-     Filemode := 2; //read&write
-     Rewrite(lInFile,1);
-     BlockWrite(lInFile, lByteRA^[1],lBufferSz);
-     CloseFile(lInFile);
-     //clean up...
-   999:
-     FreeMem(lByteRA);
-     {$ENDIF}
-end; //function fast_read_dicom_data
-
-
-end.
diff --git a/dcm2nii_prePARRECDTI/dicomfastread.pas b/dcm2nii_prePARRECDTI/dicomfastread.pas
deleted file mode 100755
index 3e08f05..0000000
--- a/dcm2nii_prePARRECDTI/dicomfastread.pas
+++ /dev/null
@@ -1,540 +0,0 @@
-unit dicomfastread;
-{$H+}
-//this is x3 faster than the dicomcompat routines, but only works with well-behaved Explicit Little-Endian DICOM
-interface
-//0008,0070,ManufacturerID
-//Next values for Philips
-//Philips - must set 2001,105F length to 8 - allows reading of stack sequence
-//  2005,1071. Philips AP angulation
-//  2005,1072. Philips RL angulation
-//  2005,1073. Philips FH angulation
-//2001,100B Philips slice orientation (TRANSVERSAL, AXIAL, SAGITTAL)
-// Next values for GE
-//0019,10bb (or 0019,a0bb)= X diffusion direction
-//0019,10bc (or 0019,a0bc)= Y diffusion direction
-//0019,10bd (or 0019,a0bd)= Z diffusion direction
-//0018,1312 = phase encoding.
-
-
-uses
-{$IFNDEF FPC}Controls, {$ENDIF}
-   SysUtils,define_types,classes,dicomtypes;
-
-function fast_read_dicom_datax(var lDICOMdata: DICOMdata; lOffset,lFileSz: integer;  var lFileName: string): boolean; //x3 faster!
-procedure read_philips_hidden(var lFilename: string; lOffset,lLength: integer; var lDICOMdata: DICOMdata);
-function orientation_not_visible( lDICOMdata: DICOMdata) : boolean;
-
-implementation
-uses dialogsx;
-{$DEFINE notANON}
-
-function fast_read_dicom_datax(var lDICOMdata: DICOMdata; lOffset,lFileSz: integer; var lFileName: string): boolean;
-const
-     kMaxBuf = (256*256)-1; //bytes
-     kMax16bit = (256*256)-1;
-     kImageType = $00080008;
-     kStudyDate = $00210008;
-     kSeriesDate = $00210008;
-     kAcqDate = $00220008;
-     kCreateDate =  $00120008;
-     kStudyTime = $00300008;
-     kPatientName = $00100010;
-     {$IFDEF ANON} //position and lengths of tags to anonymize
-     kPatientID = $00200010;
-     kPatientDOB = $00300010;
-     kPatientSex = $00400010;
-     kPatientAge = $10100010;
-     kPatientWt = $10300010;
-     {$ENDIF}
-     kSeq = $00200018;
-     kZThick =  $00500018;
-     kTR =  $00800018;
-     kTE =  $00810018;
-     kEchoNum =  $00860018;
-     kZSpacing =  $00880018;
-     kProtocolName =  $10300018;
-     kPatientPos = $51000018;
-     kSeriesNum = $00110020;
-     kAcquNum = $00120020;
-     kImageNum = $00130020;
-     kOrientation = $00370020;
-     kLocation = $10410020;
-     kDim3 = $00080028;
-     kDim2 = $00100028;
-     kDim1 = $00110028;
-     kXYSpacing =  $00300028;
-     kPosition = $00320020;
-     knVol =  $01050020;
-     kAlloc = $01000028;
-     kIntercept = $10520028;
-     kSlope = $10530028;
-     kCSAImageHeaderInfo =  $10100029;
-     kSlicesPer3DVol =  $10182001;
-     kTransferSyntax = $00100002;
-     kImageStart = $00107FE0;
-     kPhilipsPhantom1 = $91130020;//$0020+($9113 shl 16 );
-     kPhilipsPhantom2 = $91160020;
-     kPhilipsPhantom3 = $91100028;
-     kMaxFloats = 6;
-var
-  vr : array [1..2] of Char;
-   lByteRA: Bytep;
-   lFloatRA: array [1..kMaxFloats] of double;
-   lBufferSz,lPos,lBuffStart: integer;
-   lInFile: file;
-   lBufferError: boolean;
-procedure Str2FloatNum ( lStr: string; lnFloats: integer);
-var
-    lFStr: string;
-    lP,lnF: integer;
-begin
-       if (length(lStr) < 1) or (lnFloats < 1) or (lnFloats > kMaxFloats) then
-        exit;
-     for lnF := 1 to lnFloats do
-         lFloatRA[lnF] := 1;
-     lStr := lStr + ' '; //terminator
-     lFStr := '';
-     lP := 1;
-     lnF:= 0;
-     while lP <= length(lStr) do begin
-           if lStr[lP]  in ['+','-','0'..'9','.','e','E'] then
-              lFStr := lFStr + lStr[lP]
-           else if (lFStr <> '') then begin
-                inc(lnF);
-                //if lnFloats = 6 then showmessage(lFStr);
-                try
-                   lFloatRA[lnF] := strtofloat(lFStr);
-                except on EConvertError do
-                       lFloatRA[lnF] := 1;
-                end;//except
-                if lnF = lnFloats then exit;
-                lFStr := '';
-           end;
-           inc(lP);
-     end;
-end; //function Str2Float
-
-function GetByte (lFilePos: integer): byte;
-var
-   lBufPos: integer;
-begin
-    //the following error checking slows down reads a lot!
-    //a simpler alternative would be to make the buffer size the same size as the entire image...
-    //the current strategy saves memory and is faster for large images with small headers
-    if lFilepos > lFileSz then begin
-        lBufferError := true;
-        result := 0;
-        exit;
-    end;
-    lBufPos := lFilepos - lBuffStart+1;
-    if (lBufPos > lBufferSz) or (lBufPos < 1) then begin //reload buffer
-       if lFilePos+kMaxBuf > lFileSz then
-          lBufferSz := lFileSz - (lFilePos)
-       else
-           lBufferSz := kMaxBuf; //read remaining
-       AssignFile(lInFile, lFileName);
-       FileMode := 0;  //Set file access to read only
-       Reset(lInFile, 1);
-       seek(lInFile,lFilePos);
-       BlockRead(lInFile, lByteRA^[1], lBufferSz);
-       CloseFile(lInFile);
-       FileMode := 2;
-       lBuffStart := lFilePos;
-       lBufPos := 1;
-    end;
-    result := lByteRA^[lBufPos];
-end;
-
-function ReadInt4: int64;
-begin
-    if lDicomData.little_endian = 0 then
-        result := GetByte(lPos+3)+(GetByte(lPos+2) shl 8)+(GetByte(lPos+1) shl 16)+(GetByte(lPos) shl 24)
-    else
-        result := GetByte(lPos)+(GetByte(lPos+1) shl 8)+(GetByte(lPos+2) shl 16)+(GetByte(lPos+3) shl 24);
-    inc(lPos,4);
-end; //function Read4
-
-function ReadCardinal: int64;
-begin
-    if lDicomData.little_endian = 0 then
-        result := GetByte(lPos+3)+(GetByte(lPos+2) shl 8)+(GetByte(lPos+1) shl 16)+(GetByte(lPos) shl 24)
-    else
-        result := GetByte(lPos)+(GetByte(lPos+1) shl 8)+(GetByte(lPos+2) shl 16)+(GetByte(lPos+3) shl 24);
-    inc(lPos,4);
-end; //function Read4
-
-procedure ReadGroupElementLength(var lGroupElement: int64; var lLength: integer);
-begin
-     lGroupElement := ReadCardinal;
-     VR := 'AA';
-     vr[1] := chr(GetByte(lPos));
-     vr[2] := chr(GetByte(lPos+1));
-     if vr[2] < 'A' then begin //implicit vr with 32-bit length
-        lLength := ReadInt4;
-        exit;
-     end;
-     if (vr = 'OB') or (vr = 'OW') or (vr = 'SQ') then begin  {explicit VR with 32-bit length}
-          lPos := lPos + 4;  {skip 2 byte string and 2 reserved bytes = 4 bytes = 2 words}
-          lLength := ReadInt4;//Ord4(buf[lPos]) + $100 * (buf[lPos+1] + $100 * (buf[lPos+2] + $100 * buf[lPos+3]))
-     end else begin {explicit VR with 16-bit length}
-         if lDicomData.little_endian = 0  then
-             lLength := (GetByte(lPos+3))+(GetByte(lPos+2) shl 8)
-         else
-             lLength := (GetByte(lPos+2))+(GetByte(lPos+3) shl 8);//GetLength := Ord4(buf[i+2]) + $100 * (buf[i+3]);
-         lPos := lPos + 4;  {skip 2 byte string and 2 length bytes = 4 bytes = 2 words}
-     end;
-     if (lGroupElement = kPhilipsPhantom1) or (lGroupElement = kPhilipsPhantom2) or (lGroupElement = kPhilipsPhantom3) then begin
-        //crucial Philips values are nested inside this string...
-        //fx(666);
-        //kX := true;
-        lLength := 8;
-     end;
-end; //procedure ReadGroupElementLength
-
-function DCMStr(lBytes: integer): string;
-var
-   lC: integer;
-begin
-    result := '';
-    if lBytes < 1 then
-       exit;
-    for lC := lPos to (lPos+(lBytes-1)) do
-        result := result + char(GetByte(lC));
-    for lC := 1 to lBytes do
-        if result[lC]  in ['+','-','/','\',' ','0'..'9','a'..'z','A'..'Z','.'] then
-        else
-           result[lC] := ' ';
-end; //function DCMStr
-
-function DCMStr2Int (lBytes: integer): integer;
-var lErr: integer;
-    lStr: string;
-begin
-     lStr := DCMStr(lBytes);
-     Val(lStr,result,lErr);
-end; //function DCMStr2Int
-
-procedure DCMStr2FloatNum (lBytes,lnFloats: integer);
-begin
-     Str2FloatNum (DCMStr(lBytes), lnFloats);
-end; //function DCMStr2Float
-
-function DCMStr2Float (lBytes: integer): single;
-begin
-     DCMStr2FloatNum (lBytes,1);
-     result := lFloatRA[1];
-end; //function DCMStr2Float
-
-procedure DCMStr2Float2 (lBytes: integer; var lF1,lF2: double);
-begin
-     DCMStr2FloatNum (lBytes,3);
-     lF1 := lFloatRA[1];
-     lF2 := lFloatRA[2];
-end; //function DCMStr2Float2
-
-procedure DCMStr2Float3 (lBytes: integer; var lF1,lF2,lF3: double);
-begin
-     DCMStr2FloatNum (lBytes,3);
-     lF1 := lFloatRA[1];
-     lF2 := lFloatRA[2];
-     lF3 := lFloatRA[3];
-end; //function DCMStr2Float3
-
-procedure DCMStr2Float6 (lBytes: integer; var lF1,lF2,lF3,lF4,lF5,lF6: double);
-begin
-     DCMStr2FloatNum (lBytes,6);
-     lF1 := lFloatRA[1];
-     lF2 := lFloatRA[2];
-     lF3 := lFloatRA[3];
-     lF4 := lFloatRA[4];
-     lF5 := lFloatRA[5];
-     lF6 := lFloatRA[6];
-end; //function DCMStr2Float6
-
-function DCMint (lBytes: integer): integer; //read 16 bit short integer
-begin
-     if lBytes <= 2 then
-        result := GetByte(lPos)+(GetByte(lPos+1) shl 8) //shortint vs word?
-     else
-         result := GetByte(lPos)+(GetByte(lPos+1) shl 8)+(GetByte(lPos+2) shl 16)+(GetByte(lPos+3) shl 24);; //byte order??
-end; //function DCMint
-
-{$IFDEF ANON}
-Type
-  TPosLen =  RECORD //peristimulus plot
-    Pos,Len: integer;
-  end;
-procedure InitPosLen(var lPL: TPOsLen);
-begin
-    lPL.Pos := 0;
-    lPL.Len := 0;
-end;
-procedure SetPosLen(var lPL: TPosLen; lP,lL: integer);
-begin
-    lPL.Pos := lP;
-    lPL.Len := lL;
-end;
-
-procedure Anonymize(lStr: string; lPL: TPOsLen{lPos,lLen: integer});
-var
-   lDCMstr: string;
-   lP,lL: integer;
-begin
-     if ((lPL.Pos+lPL.Len) > lBufferSz) or (lPL.Len < 1) or (lPL.Pos < 1) then
-        exit;
-     lDCMStr := '';
-     lL := length(lStr);
-     if lL > lPL.Len then
-        lL := lPL.Len;
-     lP := 1;
-     while lP <= lL do begin
-           lDCMStr := lDCMStr + lStr[lP];
-           inc(lP);
-     end;
-     while lP <= lPL.Len do begin //pad string
-           lDCMStr := lDCMStr + ' ';
-           inc(lP);
-     end;
-     for lP := 1 to lPL.Len do
-          lByteRA^[lPL.Pos+lP] := Ord(lDCMstr[lP]);
-
-end;
-
-{$ENDIF}
-
-var
-   lTempStr,lStr: string;
-   lGroupElement: int64;
-   lTemp,lLength,lEchoNum,lnVol: integer;
-   lResearchMode: boolean;
-   lThick: double;
-   {$IFDEF ANON} //position and lengths of tags to anonymize
-   lCreateDate,lName,lID,lDOB,lSex,lAge,lWt,lStudyDate,lSeriesDate,lAcqDate: TPosLen;
-   {$ENDIF}
-begin //function fast_read_dicom_data
-   {$IFDEF ANON} //position and lengths of tags to anonymize
-   InitPosLen(lName);
-   InitPosLen(lID);
-   InitPosLen(lDOB);
-   InitPosLen(lSex);
-   InitPosLen(lAge);
-   InitPosLen(lWt);
-   InitPosLen(lStudyDate);
-   InitPosLen(lSeriesDate);
-   InitPosLen(lAcqDate);
-   InitPosLen(lCreateDate);
-   {$ENDIF}
-     lnVol := 1;
-     lEchoNum := 1;
-     lThick := 0;
-     clear_dicom_data(lDicomData);
-     lDicomData.little_endian := 1;
-     result := false;
-     lResearchMode := false;
-     lBufferError := false;
-     if lFileSz < 1 then
-        lFileSz := FSize(lFilename);
-     lBufferSz := lFileSz-lOffset;
-     if lBufferSz < 512 then begin
-        //showmessage('Error: File too small '+lFilename);
-        exit;
-     end;
-      if lBufferSz > kMaxBuf then
-        lBufferSz := kMaxBuf;
-     GetMem(lByteRA,kMaxBuf);
-     lBufferSz := lBufferSz;
-     AssignFile(lInFile, lFileName);
-     FileMode := 0;  //Set file access to read only
-     Reset(lInFile, 1);
-     seek(lInFile,lOffset);
-     BlockRead(lInFile, lByteRA^[1], lBufferSz);
-     CloseFile(lInFile);
-     FileMode := 2;
-     lBuffStart := lOffset;
-     lPos := lOffset;
-     if lOffset = 128 then begin //DICOM files start with DICM at 128, Siemens shadow headers do not
-        if DCMStr(4) <> 'DICM' then begin
-           Msg(DCMStr(4)+ ' <> DICM');
-           FreeMem(lByteRA);
-           exit;
-        end;
-        lPos := lOffset + 4;//DICM read
-     end;//Offset = 128
-     //next check VR
-     if not( chr(GetByte(lPos+4)) in ['A'..'Z']) or not( chr(GetByte(lPos+5)) in ['A'..'Z']) then
-        Msg('implicit VR untested');
-     //next check Endian
-     lTemp := lPos;
-     ReadGroupElementLength(lGroupElement,lLength);
-     if lLength > kMax16bit then
-        Msg('ByteSwapped');
-     lPos := lTemp;
-     //end VR check
-     result := true;
-     while (lDICOMData.imagestart = 0) and (not lBufferError) do begin
-         ReadGroupElementLength(lGroupElement,lLength);
-         case lGroupElement of
-                kTransferSyntax: begin
-                     lTempStr := (DCMStr(lLength));
-                     if (length(lTempStr) >= 19) and (lTempStr[19] = '2') then
-                        lDicomData.little_endian := 0;
-                 end;
-                 kImageType : begin
-                            lTempStr := DCMStr(lLength);
-                            //read last word - ver\mosaic -> MOSAIC
-                            lStr := '';
-                            lTemp := length(lTempStr);
-                            while (lTemp > 0) and (lTempStr[lTemp] in ['a'..'z','A'..'Z']) do begin
-                                  lStr := upcase(lTempStr[lTemp])+lStr;
-                                  dec(lTemp);
-                            end;
-                            if lStr = 'MOSAIC' then
-                               lDicomData.SiemensMosaicX := 2; //we need to read numaris for details...
-                 end;
-
-                 kStudyTime : lDicomData.StudyTime := DCMStr(lLength);
-                 {$IFDEF ANON} //position and lengths of tags to anonymize
-                kCreateDate: begin SetPosLen(lCreateDate,lPos,lLength) end;
-                 kSeriesDate: begin SetPosLen(lSeriesDate,lPos,lLength) end;
-                 kAcqDate: begin SetPosLen(lAcqDate,lPos,lLength) end;
-                 kStudyDate: begin SetPosLen(lStudyDate,lPos,lLength) end;
-                 kPatientName : begin SetPosLen(lName,lPos,lLength) end;
-                 kPatientID : begin SetPosLen(lID,lPos,lLength)  end;
-                 kPatientDOB : begin SetPosLen(lDOB,lPos,lLength)  end;
-                 kPatientSex : begin SetPosLen(lSex,lPos,lLength)  end;
-                 kPatientAge : begin SetPosLen(lAge,lPos,lLength)  end;
-                 kPatientWt : begin SetPosLen(lWt,lPos,lLength)  end;
-                 {$ELSE}
-                 kPatientName : lDicomData.PatientName := DCMStr(lLength);
-                 kStudyDate: lDicomData.StudyDate := DCMStr(lLength);
-
-                 {$ENDIF}
-                 kProtocolName : lDicomData.ProtocolName :=DCMStr(lLength);
-                 kPatientPos : lDicomData.PatientPos :=DCMStr(lLength); //should be HFS for Siemens = Head First Supine
-                 kSeriesNum : lDicomData.SeriesNum := DCMStr2Int(lLength);
-                 kAcquNum : lDicomData.AcquNum := DCMStr2Int(lLength);
-                 kSeq: begin
-                     if DCMStr(lLength) = 'RM' then
-                        lResearchMode := True;
-                 end;
-                 kImageNum : lDicomData.ImageNum := DCMStr2Int(lLength);
-                 kDim3 :lDicomData.XYZdim[3] := DCMStr2Int(lLength);
-                 kDim2 : lDicomData.XYZdim[2] := DCMint (lLength);
-
-                 kDim1 : lDicomData.XYZdim[1] := DCMint (lLength);
-                 kLocation : lDICOMData.Location := DCMStr2Float(lLength);
-                 kAlloc: lDicomData.Allocbits_per_pixel := DCMint (lLength);
-                 kTR : lDicomData.TR := DCMStr2Float(lLength);
-                 kTE: lDicomData.TE := DCMStr2Float(lLength);
-                 kEchoNum: lEchoNum := round (DCMStr2Float(lLength));
-                 kSlope : lDICOMData.IntenScale := DCMStr2Float(lLength);
-                 kIntercept : lDICOMData.IntenIntercept := DCMStr2Float(lLength);
-                 kOrientation : DCMStr2Float6(lLength, lDicomData.Orient[1], lDicomData.Orient[2],lDicomData.Orient[3],lDicomData.Orient[4], lDicomData.Orient[5],lDicomData.Orient[6]);
-                 kPosition : DCMStr2Float3 (lLength,lDicomData.PatientPosX, lDicomData.PatientPosY,lDicomData.PatientPosZ);
-                 knVol: lnVol := round (DCMStr2Float(lLength));
-                 kZThick: begin lThick := DCMStr2Float(lLength); lDICOMData.XYZmm[3] := lThick; end;//used differently by manufacturers
-                 kZSpacing: begin lDICOMData.XYZmm[3] := DCMStr2Float(lLength);
-                                 if  (lThick/2) > lDICOMdata.XYZmm[3]  then
-                                     lDICOMdata.XYZmm[3] := lDICOMdata.XYZmm[3] + lThick
-                           end; //used different by different manufacturers
-                 kXYSpacing: begin
-                 DCMStr2Float2 (lLength,  lDICOMdata.XYZmm[2],  lDICOMdata.XYZmm[1]);
-                 end;
-                 kCSAImageHeaderInfo: begin //order ICE,Acq,Num,Vector
-                   lDICOMdata.CSAImageHeaderInfoPos := lPos;
-                   lDICOMdata.CSAImageHeaderInfoSz :=  lLength;
-                                       end;
-                 kSlicesPer3DVol: lDICOMData.SlicesPer3DVol := DCMint (lLength);
-                 kImageStart: lDICOMData.ImageStart := lPos ; //-1 as indexed from 0.. not 1..
-         end; //Case lGroupElement
-         //Msg(VR+inttohex(lGroupElement and kMax16bit,4) +':'+inttohex( lGroupElement shr 16,4)+'  '+inttostr(lLength)+'@'+inttostr(lPos) );
-         //msg(inttostr(lPos)+'  '+inttostr(lLength));
-         lPos := lPos + (lLength);
-     end; //while imagestart=0 and not error
-
-     //clean up
-     lDicomData.DateTime := StudyDateTime(lDicomData.StudyDate,lDicomData.StudyTime);
-     if (lDicomData.SiemensMosaicX > 1) then
-  	lDicomData.AcquNum := 1;
-     if (lEchoNum > 1) and (lEchoNum < 16) then
-        lDicomData.AcquNum := lDicomData.AcquNum + (100*lEchoNum);
-     if lResearchMode then
-        lDicomData.SeriesNum   := lDicomData.SeriesNum + 100;
-     if (lDICOMData.SlicesPer3DVol > 0) and (lnVol > 1) and (lDicomdata.XYZdim[3] > 1) and (lDicomData.SlicesPer3DVol > 0)and ((lDicomdata.XYZdim[3] mod lDicomData.SlicesPer3DVol) = 0)  then
-        lDICOMdata.File4D := true;
-     if not lBufferError then
-        result := true;
-     FreeMem(lByteRA);
-     //Remaining portions only if anonymizing
-     {$IFDEF ANON}
-     Msg('Anonymizing DICOM '+extractfilename(lFilename));
-     lBufferSz := lFileSz;
-     GetMem(lByteRA,lBufferSz);
-     //read original
-     AssignFile(lInFile, lFileName);
-     FileMode := 0;  //Set file access to read only
-     Reset(lInFile, 1);
-     //seek(lInFile,1);
-     BlockRead(lInFile, lByteRA^[1], lBufferSz);
-     CloseFile(lInFile);
-     //anonymize...
-     Anonymize ('ANONYMIZED',lName);
-     Anonymize ('ANONYMIZED',lID);
-     Anonymize('19890323',lDOB); //Cold Fusion YYYYMMDD
-     Anonymize('19890323',lStudyDate); //Cold Fusion YYYYMMDD
-     Anonymize('19890323',lAcqDate); //Cold Fusion YYYYMMDD
-     Anonymize('19890323',lSeriesDate); //Cold Fusion YYYYMMDD
-     Anonymize('19890323',lCreateDate); //Cold Fusion YYYYMMDD
-
-     Anonymize('M',lSex);
-     Anonymize('18',lAge);
-     Anonymize('100',lWt);
-     //write anonymized data...
-     assignfile(lInFile, lFileName+'.dcm');
-     Filemode := 2; //read&write
-     Rewrite(lInFile,1);
-     BlockWrite(lInFile, lByteRA^[1],lBufferSz);
-     CloseFile(lInFile);
-     //clean up...
-     FreeMem(lByteRA);
-     {$ENDIF}
-end; //function fast_read_dicom_data
-
-function orientation_not_visible( lDICOMdata: DICOMdata) : boolean;
-var
-   li : integer;
-   lDICOMdataX: DICOMdata;
-begin
-        result := false;
-        clear_dicom_data(lDicomDataX);
-        for li := 1 to 2 do  //only XY-direction - as philips reports correct Z in header
-            if lDICOMdata.XYZmm[li] <> lDICOMdataX.XYZmm[li] then
-               exit;
-        for li := 1 to 6 do
-            if lDicomData.Orient[li] <> lDicomDataX.Orient[li] then
-              exit;
-        if lDicomData.PatientPosX <> lDicomDataX.PatientPosX then exit;
-        if lDicomData.PatientPosY <> lDicomDataX.PatientPosY then exit;
-        if lDicomData.PatientPosZ <> lDicomDataX.PatientPosZ then exit;
-        result := true;
-end;
-
-
-procedure read_philips_hidden(var lFilename: string; lOffset,lLength: integer; var lDICOMdata: DICOMdata);
-var
-   li : integer;
-   lDICOMdataX: DICOMdata;
-begin
- if not fast_read_dicom_datax(lDICOMdataX, lOffset+8, lOffset+lLength, lFileName) then exit;
-        //fx(lDICOMdataX.XYZmm[1],lDICOMdataX.XYZmm[2]);
-        for li := 1 to 2 do //only XY-direction - as philips reports correct Z in header
-            lDICOMdata.XYZmm[li] := lDICOMdataX.XYZmm[li];
-        for li := 1 to 6 do
-         lDicomData.Orient[li] := lDicomDataX.Orient[li];
-        lDicomData.PatientPosX := lDicomDataX.PatientPosX;
-        lDicomData.PatientPosY := lDicomDataX.PatientPosY;
-        lDicomData.PatientPosZ := lDicomDataX.PatientPosZ;
-end;
-
-
-end.
diff --git a/dcm2nii_prePARRECDTI/dicomtypes.pas b/dcm2nii_prePARRECDTI/dicomtypes.pas
deleted file mode 100755
index 8f61a4e..0000000
--- a/dcm2nii_prePARRECDTI/dicomtypes.pas
+++ /dev/null
@@ -1,735 +0,0 @@
-unit dicomtypes;
-
-{$IFDEF FPC}
-{$mode objfpc}
-{$ENDIF}
-{$H+}
-{$Include ..\common\isgui.inc}
-
-interface
-var kUseDateTimeForID: boolean = false;
-const
-     kGEID = 1;
-     kPhilipsID = 2;
-     kSiemensID = 3;
-     kMaxDTIDir = 1024;//Maximum DTI directions
-     kMaxOrderVal = 1024;
-type
-TDTI = record
-   v1,v2,v3: double;   //4=volume, eg time: some EC*T7 images
-   bval: integer
-end;
-  TDTIRA = array [1..kMaxDTIDir] of TDTI;//TDICOM;//unsigned 8-bit int
-  TOrder= array [1..kMaxOrderVal] of byte;
-
-
-    kDICOMStr = String[32];
-   DICOMdata = record
-             XYZdim: array [1..4] of integer;
-             XYZori: array [1..3] of integer;
-             XYZmm: array [1..3] of double;
-             Orient: array [1..6] of double;
-             SignedData,SiemensDICOMDTICSA,SiemensDICOMDTI,FloatData,file4D,JPEGLossyCpt,JPEGLosslessCpt: boolean;
-             SecSinceMidnight,PatientPosX,PatientPosY,PatientPosZ,AngulationAP,AngulationFH,AngulationRL: double;
-             kV,TE, TR,IntenScale,IntenIntercept,location{,DTIv1,DTIv2,DTIv3}: single;
-             {Bval,}SlicesPer3DVol,SiemensInterleaved {0=no,1=yes,2=not defined},SiemensSlices,SiemensMosaicX,SiemensMosaicY,
-             nOrder,nDTIdir,AcquNum,ImageNum,SeriesNum,ImageStart,little_endian,Allocbits_per_pixel,SamplesPerPixel,
-             CSAImageHeaderInfoPos,CSAImageHeaderInfoSz,ManufacturerID,PlanarConfig, //ImplementationVersion,
-             Vers0018_1020,
-             CompressOffset,CompresssZ: integer;
-             DateTime: TDateTime;
-             PatientGender,PatientDoB,PatientPos,PatientName,ProtocolName,StudyDate,StudyTime,PhilipsSliceOrient,PhaseEncoding: kDICOMStr;
-             Filename: string[255];        
-             DTI: TDTIRA;
-   Order: TOrder; //4D datasets
-   //OrderSlope,OrderIntercept: TOrderScaling; //4D datasets
-   end;//DICOMdata record
-
-  TDICOMRA = array [1..1] of DicomData;//TDICOM;//unsigned 8-bit int
-  TDICOMRAp = ^TDICOMRA;
-  TNIFTIhdr  = packed record //Next: analyze Format Header structure
-   HdrSz : longint; //MUST BE 348
-   Data_Type: array [1..10] of char; //unused
-   db_name: array [1..18] of char; //unused
-   extents: longint; //unused
-   session_error: smallint; //unused
-   regular: char; ////unused: in Analyze 7.5 this must be 114
-   dim_info: byte; //MRI slice order
-   dim: array[0..7] of smallint; //Data array dimensions
-   intent_p1, intent_p2, intent_p3: single;
-   intent_code: smallint;
-   datatype: smallint;
-   bitpix: smallint;
-   slice_start: smallint;
-   pixdim: array[0..7]of single;
-   vox_offset: single;
-   scl_slope: single;//scaling slope
-   scl_inter: single;//scaling intercept
-   slice_end: smallint;
-   slice_code: byte; //e.g. ascending
-   xyzt_units: byte; //e.g. mm and sec
-   cal_max,cal_min: single; //unused
-   slice_duration: single; //time for one slice
-   toffset: single; //time axis to shift
-   glmax, glmin: longint; //UNUSED
-   descrip: array[1..80] of char;
-   aux_file: array[1..24] of char;
-   qform_code, sform_code: smallint;
-   quatern_b,quatern_c,quatern_d,
-   qoffset_x,qoffset_y,qoffset_z: single;
-   srow_x: array[0..3]of single;
-   srow_y: array[0..3]of single;
-   srow_z: array[0..3]of single;
-   intent_name: array[1..16] of char;
-   magic: longint;
- end; //TNIFTIhdr Header Structure
-
-
- const //nifti
-kDT_BINARY                 =1;     // binary (1 bit/voxel)
-kDT_UNSIGNED_CHAR          =2;     // unsigned char (8 bits/voxel)
-kDT_SIGNED_SHORT           =4;     // signed short (16 bits/voxel)
-kDT_SIGNED_INT             =8;     // signed int (32 bits/voxel)
-kDT_FLOAT                 =16;     // float (32 bits/voxel)
-kDT_COMPLEX               =32;     // complex (64 bits/voxel)
-kDT_DOUBLE                =64;     // double (64 bits/voxel)
-kDT_RGB                   =128;     // RGB triple (24 bits/voxel)
-kDT_INT8                  =256;     // signed char (8 bits)
-kDT_UINT16                =512;     // unsigned short (16 bits)
-kDT_UINT32                =768;     // unsigned int (32 bits)
-kDT_INT64                =1024;     // long long (64 bits)
-kDT_UINT64               =1280;     // unsigned long long (64 bits)
-kDT_FLOAT128             =1536;     // long double (128 bits)
-kDT_COMPLEX128           =1792;     // double pair (128 bits)
-kDT_COMPLEX256           =2048;     // long double pair (256 bits)
-//   slice_code values
- kNIFTI_SLICE_SEQ_UNKNOWN = 0;
- kNIFTI_SLICE_SEQ_INC = 1;
- kNIFTI_SLICE_SEQ_DEC = 2;
- kNIFTI_SLICE_ALT_INC = 3;
- kNIFTI_SLICE_ALT_DEC = 4;
-//xyzt_units values: note 3bit space and 3bit time packed into single byte
- kNIFTI_UNITS_UNKNOWN = 0;
- kNIFTI_UNITS_METER =  1;
- kNIFTI_UNITS_MM = 2;
- kNIFTI_UNITS_MICRON  = 3;
- kNIFTI_UNITS_SEC = 8;
- kNIFTI_UNITS_MSEC = 16;
- kNIFTI_UNITS_USEC = 24;
- kNIFTI_UNITS_HZ = 32;
- kNIFTI_UNITS_PPM = 40;
- //qform_code, sform_code values
- kNIFTI_XFORM_UNKNOWN = 0;
- kNIFTI_XFORM_SCANNER_ANAT = 1;//Scanner-based anatomical coordinates
- kNIFTI_XFORM_ALIGNED_ANAT = 2; //Coordinates aligned to another file e.g. EPI coregistered to T1
- kNIFTI_XFORM_TALAIRACH = 3; //Talairach-Tournoux Atlas; (0,0,0)=AC, etc.
- kNIFTI_XFORM_MNI_152 = 4; //MNI 152 normalized coordinates
- //Magic values
- kNIFTI_MAGIC_SEPARATE_HDR = $0031696E;//$6E693100;
- kNIFTI_MAGIC_EMBEDDED_HDR = $00312B6E;//$6E2B3100;
- //byte-swapped magic values
- kswapNIFTI_MAGIC_SEPARATE_HDR = $6E693100;
- kswapNIFTI_MAGIC_EMBEDDED_HDR = $6E2B3100;
- //Statistics Intention
- kNIFTI_INTENT_NONE        =0;
-kNIFTI_INTENT_CORREL      =2;
-kNIFTI_INTENT_TTEST       =3;
-kNIFTI_INTENT_FTEST       =4;
-kNIFTI_INTENT_ZSCORE      =5;
-kNIFTI_INTENT_CHISQ       =6;
-kNIFTI_INTENT_BETA        =7;
-kNIFTI_INTENT_BINOM       =8;
-kNIFTI_INTENT_GAMMA       =9;
-kNIFTI_INTENT_POISSON    =10;
-kNIFTI_INTENT_NORMAL     =11;
-kNIFTI_INTENT_FTEST_NONC =12;
-kNIFTI_INTENT_CHISQ_NONC =13;
-kNIFTI_INTENT_LOGISTIC   =14;
-kNIFTI_INTENT_LAPLACE    =15;
-kNIFTI_INTENT_UNIFORM    =16;
-kNIFTI_INTENT_TTEST_NONC =17;
-kNIFTI_INTENT_WEIBULL    =18;
-kNIFTI_INTENT_CHI        =19;
-kNIFTI_INTENT_INVGAUSS   =20;
-kNIFTI_INTENT_EXTVAL     =21;
-kNIFTI_INTENT_PVAL       =22;
-NIFTI_INTENT_LOGPVAL     =23;
-NIFTI_INTENT_LOG10PVAL	 =24;
-kNIFTI_LAST_STATCODE = 24;//kNIFTI_INTENT_PVAL;
-kNIFTI_INTENT_ESTIMATE  =1001;
-kNIFTI_FIRST_NONSTATCODE = kNIFTI_INTENT_ESTIMATE;
-kNIFTI_INTENT_LABEL     =1002;
-kNIFTI_INTENT_NEURONAME =1003;
-kNIFTI_INTENT_GENMATRIX =1004;
-kNIFTI_INTENT_SYMMATRIX =1005;
-kNIFTI_INTENT_DISPVECT  =1006;
-kNIFTI_INTENT_VECTOR    =1007;
-kNIFTI_INTENT_POINTSET  =1008;
-kNIFTI_INTENT_TRIANGLE  =1009;
-kNIFTI_INTENT_QUATERNION =1010;
-
-const //dicom
-kCR = chr (13);//PC EOLN
-kA = ord('A');
-kB = ord('B');
-kC = ord('C');
-kD = ord('D');
-kE = ord('E');
-kF = ord('F');
-kH = ord('H');
-kI = ord('I');
-kL = ord('L');
-kM = ord('M');
-kN = ord('N');
-kO = ord('O');
-kP = ord('P');
-kQ = ord('Q');
-kS = ord('S');
-kT = ord('T');
-kU = ord('U');
-kW = ord('W');
-
-procedure PhilipsPrecise (lRS, lRI,lSS: single; var lSlope,lIntercept: single; Precise: boolean);
-procedure clear_dicom_data (var lDicomdata:Dicomdata);
-function DICOMinterslicedistance(var lDicomdata1,lDicomdata2:Dicomdata): single;//1392
-function StudyDateTime (lInStudyDate, lInStudyTime: kDICOMStr): TDateTime;
-function StudyDateTime2Str (lDateTime: TDateTime):string;
-//function GetCSAImageHeaderInfoDTI (lFilename: string; lStart,lLength: integer; var lBval: integer; var ldti1,ldti2,ldti3: double): boolean;
-//function GetCSAImageHeaderInfo (lFilename: string; lStart,lLength: integer; var lMosaicSlices,lMosaicX,lMosaicY: integer; var lv1,lv2,lv3: double): boolean;
-procedure AplhaNumericStrDICOM (var lStr: kDICOMStr);
-procedure PartialAcquisitionError;
-function DICOMstr (i: integer; var lDICOMra: TDICOMrap;lOutname:string): string; overload;
-function DICOMstr (i: integer; var lDICOMra: TDICOMrap): string; overload;
-
-implementation
-
-uses dicom,sysutils,define_types,dialogsx;
-
-function YearsOld (lDICOM: DICOMdata): single;
-var
-   dob: TDateTime;
-   lnoon:string;
-begin
-     result := 0;
-     if length (lDICOM.PatientDoB) < 8 then
-        exit; //YYYYMMDD
-     try
-       lnoon := '120000';
-     dob := StudyDateTime (lDICOM.PatientDoB, lnoon);
-       result := (lDICOM.DateTime-dob)/365.2425;
-     except
-           result := 0;
-     end;
-end;
-function DICOMstr (i: integer; var lDICOMra: TDICOMrap;lOutname: string): string;  overload;
-var
-   lS: string;
-begin
-     if lOutname <> '' then
-        lS := kTab+'SuggestedOutput:'+lOutname
-     else
-         lS := '';
-
-     result := lDICOMra^[i].Filename
-       +kTab+'SeriesNum:'+kTab+inttostr(lDICOMra^[i].SeriesNum)
-       +kTab+'AcquNum:'+inttostr(lDICOMra^[i].AcquNum)
-       +kTab+'ImageNum:'+inttostr(lDICOMra^[i].ImageNum)
-       +kTab+'Name:'+lDICOMra^[i].PatientName
-       +kTab+'DoB:'+lDICOMra^[i].PatientDoB
-       +kTab+'Gender:'+lDICOMra^[i].PatientGender
-       +kTab+'DateTime:'+DateTimeToStr(lDICOMra^[i].DateTime)
-       +kTab+'Age(Years):'+floattostr(YearsOld(lDICOMra^[i]))
-       +lS ;
-
-end;  
-
-function DICOMstr (i: integer; var lDICOMra: TDICOMrap): string; overload;
-begin
-    result := DICOMstr (i, lDICOMra,'')
-end;
-
-procedure PartialAcquisitionError;
-begin
-     Msg('*  Potential partial acquisition or improper segmentation of files');
-     {$IFDEF GUI}
-        Msg('*  Possible solution: check ''Collapse folders'' in Help/Preferences and select directory that contains all images in subfolders');
-     {$ELSE}
-        Msg('*  Possible solution: use -c Y and use folder containing subdirectories as input');
-        Msg('*            or change .ini file to read: CollapseFolders=1');
-     {$ENDIF}
-end;
-
-function  PhilipsPreciseVal (lPV, lRS, lRI,lSS: single): single;
-begin
-     if (lRS*lSS) = 0 then //avoid divide by zero
-        result := 0
-     else
-         result := (lPV * lRS + lRI) / (lRS * lSS);
-end;
-
-procedure PhilipsPrecise (lRS, lRI,lSS: single; var lSlope,lIntercept: single; Precise: boolean);
-var
-   l0,l1: single;
-begin
-//# === PIXEL VALUES =============================================================
-//#  PV = pixel value in REC file, FP = floating point value, DV = displayed value on console
-//#  RS = rescale slope,           RI = rescale intercept,    SS = scale slope
-//#  DV = PV * RS + RI             FP = DV / (RS * SS)
-     if not Precise then begin //return DV not FP
-        lSlope := lRS;
-        if lSlope = 0 then
-           lSlope := 1;
-        lIntercept := lRI;
-        exit;
-     end; //if return DV
-     l0 := PhilipsPreciseVal (0, lRS, lRI,lSS);
-     l1 := PhilipsPreciseVal (1, lRS, lRI,lSS);
-     if l0 = l1 then begin
-        lSlope := 1;
-        lIntercept := 0;
-        exit;
-     end;
-     lIntercept := l0;
-     lSlope := l1-l0;
-end;
-
-
-function SecSinceMidnight(H,Min,S: integer): integer;
-//86,400 sec per day
-begin
-  //
-	result := 3600*(H) + 60* Min + S;//H not H-1 as our clock runs from  0..23  not 1..24
-end;
-
-function BogusDateTime: TDateTime;
-begin
-     result := EncodeDate(1989,3,23) + (SecSinceMidnight(12,0,0) / 86400);
-end;
-
-function EncodeDateTime (Y,M,D,H,Min,S: integer): TDateTime;
-begin
-
-  try
-	 result := EncodeDate(Y,M,D) + (SecSinceMidnight(H,Min,S) / 86400);
-  except  //impossible date - set to cold fusion date
-       result := BogusDateTime;
-  end;
-end;
-
-procedure DecodeDateTime (lDateTime: TDateTime; var Y,M,D,H,Min,S: word);
-var
-   secs: integer;
-begin
-     try
-        DecodeDate(lDateTime, Y, M, D);
-     except  //unable to decode date - use cold fusion values
-           Y := 1989;
-           M := 3;
-           D := 23;
-     end;
-     Secs := round(Frac(lDateTime)*86400);
-     S := secs mod 60;
-     Min := (secs div 60) mod 60;
-     H := (secs div 3600);
-end;
-
-function StudyDateTime2Str (lDateTime: TDateTime):string;
-var
-  Y,M,D,H,Min,S: word;
-begin
-	 DecodeDateTime (lDateTime,Y,M,D,H,Min,S);
-	 result := PadStr (Y, 4)+ PadStr (M, 2)+PadStr (D, 2)+'_'+PadStr (H, 2)+ PadStr (Min, 2)+PadStr (S, 2);
-end;
-
-function StudyDateTime (lInStudyDate, lInStudyTime: kDICOMStr): TDateTime;
-var lStr,lStudyDate, lStudyTime: string;
-	Y,M,D,H,Min,S: integer;
-begin
-	result := 0;
-	if (length(lInStudyDate) < 8){YYYYMMDD} or (length(lInStudyTime) < 6) {hhmmss} then
-		exit;
-	//next compress string, e.g. Elscint saves time as 16:54:21
-	lStudyDate :='';
-	for S := 1 to length (lInStudyDate) do
-		if lInStudyDate[S] in ['0'..'9'] then
-			lStudyDate := lStudyDate + lInStudyDate[S];
-	lStudyTime :='';
-	for S := 1 to length (lInStudyTime) do
-		if lInStudyTime[S] in ['0'..'9'] then
-			lStudyTime := lStudyTime + lInStudyTime[S];
-
-	if (length(lStudyDate) < 8){YYYYMMDD} or (length(lStudyTime) < 6) {hhmmss} then
-		exit;
-	lStr := lStudyDate[1]+lStudyDate[2]+lStudyDate[3]+lStudyDate[4];
-	Y := strtoint(lStr);
-	lStr := lStudyDate[5]+lStudyDate[6];
-	M := strtoint(lStr);
-	lStr := lStudyDate[7]+lStudyDate[8];
-	D := strtoint(lStr);
-	lStr := lStudyTime[1]+lStudyTime[2];
-	H := strtoint(lStr);
-	lStr := lStudyTime[3]+lStudyTime[4];
-	Min := strtoint(lStr);
-	lStr := lStudyTime[5]+lStudyTime[6];
-	S := strtoint(lStr);
-	result := EncodeDateTime (Y,M,D,H,Min,S);
-end;
-
-procedure AplhaNumericStrDICOM (var lStr: kDICOMStr);
-var
-	S: integer;
-	lOutStr: string;
-begin
-	if length(lStr) < 1 then exit;
-	lOutStr := '';
-
-	for S := 1 to length (lStr) do
-		if lStr[S] in ['0'..'9','A'..'Z','a'..'z'] then
-			lOutStr := lOutStr+ lStr[S];
-	lStr := lOutStr;
-end;
-(*
-function GetCSAImageHeaderInfoRaw (lIsDTI: boolean; lFilename: string; lStart,lLength: integer; var li1,li2,li3: integer; var lf1,lf2,lf3: double): boolean;
-//returns true if mosaic
-//will return false for non-mosaics - even if the have DTI information!
-//valid DTI signified by bval >= 0
-const
-        kMaxFloats = 6;
-var
-   //lZ: integer;
-   lByteRA: Bytep;
-   lNumarisTag: string;
-   lInFile: file;
-   lFloatRA: array [1..kMaxFloats] of double;
-
-function Str2FloatLastNum ( lStr: string): boolean;
-var
-    lFStr: string;
-    lP: integer;
-begin
-     lFloatRA[1] := 1;
-     result := false;
-     if (length(lStr) < 1) then
-        exit;
-     lFStr := '';
-     lP := length(lStr);
-     while (lP > 0) and ((lFStr = '') or (lStr[lP]  in ['+','-','0'..'9','.','e','E']))   do begin
-           if lStr[lP]  in ['+','-','0'..'9','.','e','E'] then
-              lFStr := lStr[lP]+lFStr;
-           dec(lP);
-     end;
-     if (lFStr = '') then
-        exit;
-     try
-        lFloatRA[1] := strtofloat(lFStr);
-     except on EConvertError do
-            lFloatRA[1] := 1;
-     end;//except
-     result := true;
-end; //function Str2Float
-
-function NumarisPos (lStr: string; lStart: integer): integer; //read 16 bit short integer
-var
-   lP,lLen,lMax,lMatch: integer;
-begin
-     result := 0;
-     lLen := length(lStr);
-     lMax := lLength-lLen;
-     if (lStart < 1) or (lMax < 1) or (lLen < 1) then
-        exit;
-     for lP := lStart to lMax do begin
-         lMatch := 0;
-         while (lMatch < lLen) and (lStr[lMatch+1] = char( lByteRA[lP+lMatch]) ) do
-               inc(lMatch);
-         if lMatch = lLen then begin
-             if (lP < lMax) and (char( lByteRA[lP+lMatch]) = '"') then begin
-                 lMatch := 0;//We want DiffusionGradientDirection, but not "DiffusionGradientDirection"
-             end else begin
-                 result := lP;
-                 exit;
-             end;
-         end;
-     end;
-end; //function NumarisPos
-
-function Str2FloatNum ( lStr: string; lnFloats: integer): boolean;
-var
-    lFStr: string;
-    lP,lnF: integer;
-begin
-     result := false;
-     if (length(lStr) < 1) or (lnFloats < 1) or (lnFloats > kMaxFloats) then
-        exit;
-     for lnF := 1 to lnFloats do
-         lFloatRA[lnF] := 1;
-     lStr := lStr + ' '; //terminator
-     lFStr := '';
-     lP := 1;
-     lnF:= 0;
-     while lP <= length(lStr) do begin
-           if lStr[lP]  in ['+','-','0'..'9','.','e','E'] then
-              lFStr := lFStr + lStr[lP]
-           else if (lFStr <> '') then begin
-                inc(lnF);
-                try
-                   lFloatRA[lnF] := strtofloat(lFStr);
-                except on EConvertError do
-                       Msg('Unable to interpret '+lNumarisTag+ ' in '+extractfilename(lFilename));
-                end;//except
-                if lnF = lnFloats then begin
-                   result := true;
-                   exit;
-                end;
-                lFStr := '';
-           end;
-           inc(lP);
-     end;
-end; //function Str2Float
-
-function NumarisStr (lStr,lIDStr: string): string;
-var
-   lP,lI: integer;
-   lPrevNum : boolean;
-begin
-     result := '';
-     lP := NumarisPos(lStr,1);
-     if lP <1 then exit;
-     if length(lIDstr) > 0 then begin
-        lP := NumarisPos(lIDstr,lP);
-        if lP <1 then exit;
-     end;
-     result := '';
-     lI := lP + length(lStr);
-     lPrevNum := false;
-     While (lI < (lLength)) and (lByteRA^[lI] <> $CD) do begin
-           if char(lByteRA[lI])  in ['-','0'..'9','.','p','*'] then begin
-              result := result + char(lByteRA[lI]);
-              lPrevNum := true;
-           end else begin
-               if lPrevNum then result := result + ' ';
-               lPrevNum := false;
-           end;
-           inc(lI);
-     end;
-end;
-
-function NumarisInt1 (lStr,lIDStr: string; var lI1: integer): boolean;
-begin
-    result := Str2FloatLastNum (NumarisStr(lStr,lIDStr));
-    if not result then exit;
-    lI1 := round(lFloatRA[1] );
-end;
-
-function NumarisFloat3 (lStr,lIDStr: string; var lF1,lF2,lF3: double): boolean;
-begin
-     //showmessage(lStr+' '+NumarisStr(lStr,lIDStr));
-    result := Str2FloatNum (NumarisStr(lStr,lIDStr),3);
-    if not result then exit;
-
-     lF1 := (lFloatRA[1]);
-     lF2 := (lFloatRA[2]);
-     lF3 := (lFloatRA[3]);
-end; //function NumarisFloat3
-
-function NumarisInt2PStar (lStr,lIDStr: string; var lI1,lI2: integer): boolean;
-var
-   lLen,lPos,lStarPos: integer;
-   lvStr,lpStarStr: string;
-begin //a 96x96 mosaic is usually saved as '64*64', but in B13 you can see '96p*96' or '.95  96p*96'
-     result := false;
-     lvStr := NumarisStr(lStr,lIDStr);
-     lLen := length(lvStr);
-     if lLen < 4 then exit;//not found
-     lStarPos := 0;
-     for lPos := 1 to (lLen-1) do
-         if (lvStr[lPos] = '*') then
-            lStarPos := lPos;
-     if lStarPos = 0 then exit;
-     lpStarStr := '';
-     lPos := lStarPos -1;
-     while (lPos >= 1) and ((lpStarStr = '')  or (lvStr[lPos]  in ['0'..'9'])) do begin
-           lpStarStr := lvStr[lPos] + lpStarStr;
-           dec(lPos);
-     end;
-     lpStarStr := lpStarStr + ' ';
-     lPos := lStarPos+1;
-     while (lPos < lLen) and ((lpStarStr = '')  or (lvStr[lPos]  in ['0'..'9'])) do begin
-           lpStarStr :=   lpStarStr+lvStr[lPos];
-           inc(lPos);
-     end;
-     result := Str2FloatNum (lpStarStr,2);
-
-     if not result then exit;
-     lI1 := round(lFloatRA[1]);
-     lI2 := round(lFloatRA[2]);
-     //Msg(lvStr+'  '+floattostr( lI1)+'x'+inttostr(lI2));
-end;
-
-begin // GetCSAImageHeaderInfoRaw
-     result := false;
-     if (lLength < 1) then
-        exit;
-     if FSize(lFilename) <= (lStart+lLength) then
-        exit;
-     li1 := -1; //impossible - should be >=0
-     li2 := 0;
-     li3 := 0;
-     lf1 := 0;//impossible, therefore not DTI - should be -1..1
-     lf2 := 0;//impossible, therefore not DTI
-     lf3 := 0;//impossible, therefore not DTI
-     GetMem(lByteRA,lLength);
-     AssignFile(lInFile, lFileName);
-     //Msg('fz '+lFilename);
-     FileMode := 0;  //Set file access to read only
-     Reset(lInFile, 1);
-     seek(lInFile,lStart);
-     BlockRead(lInFile, lByteRA^[1], lLength);
-     CloseFile(lInFile);
-     FileMode := 2;
-     if lIsDTI then begin
-
-        result := NumarisInt1 ('B_value','IS',li1);
-        //result := NumarisInt1 ('B_value','LO',li1);
-        if li1 > 0 then begin
-           NumarisFloat3('DiffusionGradientDirection','FD',lf1,lf2,lf3);
-           //vx(lf1,lf2,lf3,123);
-        end;
-     end else begin //get mosaic info
-         //fx(lStart,lLength);
-         result := NumarisInt1 ('NumberOfImagesInMosaic','US',li1);
-         if result then begin
-            NumarisInt2pStar ('AcquisitionMatrixText','SH', li2,li3);
-            NumarisFloat3('SliceNormalVector','FD',lf1,lf2,lf3);
-         end;
-     end;
-     FreeMem(lByteRA);
-end;//GetCSAImageHeaderInfoRaw
-
-function GetCSAImageHeaderInfoDTI (lFilename: string; lStart,lLength: integer; var lBval: integer; var ldti1,ldti2,ldti3: double): boolean;
-var
-   li2,li3: integer; //not used
-begin
-     result := GetCSAImageHeaderInfoRaw (TRUE,lFilename, lStart,lLength, lBval,li2,li3, ldti1,ldti2,ldti3);
-end;
-
-function GetCSAImageHeaderInfo (lFilename: string; lStart,lLength: integer; var lMosaicSlices,lMosaicX,lMosaicY: integer; var lv1,lv2,lv3: double): boolean;
-begin
-     result := GetCSAImageHeaderInfoRaw (FALSE,lFilename, lStart,lLength, lMosaicSlices,lMosaicX,lMosaicY, lv1,lv2,lv3);
-end;  *)
-
-
-procedure clear_dicom_data (var lDicomdata:Dicomdata);
-var
-	lI: integer;
-begin
-  with lDicomData do begin
-           lDicomData.CSAImageHeaderInfoPos  := 0;
-           lDicomData.CSAImageHeaderInfoSz := 0;
-	   for lI := 1 to 6 do
-		Orient[lI] := 0;
-	   DateTime := BogusDateTime;
-       ManufacturerID := 0;
-       kV := 0;
-       //ImplementationVersion := 0;
-       Vers0018_1020 := 0;
-       AngulationFH := 0;
-       AngulationRL := 0;
-       AngulationAP := 0;
-       nDTIdir := 0;
-       nOrder := 0;
-       PhilipsSliceOrient := 'NA';
-       PhaseEncoding := 'NA';
-       PatientPos := 'NA';
-       for lI := 1 to kMaxDTIdir do begin
-        DTI[lI].Bval := -1;
-       DTI[lI].v1 := 0;
-       DTI[lI].v2 := 0;
-       DTI[lI].v3 := 0;
-          (* DTI[lDICOMdata.nDTIdir].Bval := -1;
-       DTI[lDICOMdata.nDTIdir].v1 := 0;
-       DTI[lDICOMdata.nDTIdir].v2 := 0;
-       DTI[lDICOMdata.nDTIdir].v3 := 0; *)
-       end;
-       SiemensDICOMDTI := true;
-       SiemensDICOMDTICSA := false;
-       file4D := false;
-       PatientName := 'NO NAME';
-       PatientDoB := 'NO DOB';
-       PatientGender := 'NA';
-       //PatientID := 'NO ID';
-       StudyDate := '';
-       StudyTime := '';
-       SecSinceMidnight := 0;
-       //AcqTime := '';
-       //ImgTime := '';
-       TR := 0;
-       TE := 0;
-       //Echo := 0;
-       //kV := 0;
-       //mA := 0;
-       //Rotate180deg := false;
-        //MaxIntensity := 0;
-        //MinIntensity := 0;
-        //MinIntensitySet := false;
-        FloatData := false;
-		ImageNum := -1;
-		SlicesPer3DVol := 0;
-		SiemensInterleaved := 2; //0=no,1=yes,2=undefined
-        SiemensSlices := 0;
-        SiemensMosaicX := 1;
-        SiemensMosaicY := 1;
-        IntenScale := 1;
-        IntenIntercept := 0;
-        SeriesNum := 1;
-        AcquNum := 0;
-        ImageNum := 1;
-        //Accession := 1;
-        PlanarConfig:= 0; //only used in RGB values
-        //runlengthencoding := false;
-        //CompressSz := 0;
-        //CompressOffset := 0;
-        SamplesPerPixel := 1;
-        //WindowCenter := 0;
-        //WindowWidth := 0;
-        XYZmm[1] := 1;
-        XYZmm[2] := 1;
-        XYZmm[3] := 1;
-        XYZdim[1] := 1;
-        XYZdim[2] := 1;
-        XYZdim[3] := 1;
-        XYZdim[4] := 1;
-        lDicomData.XYZori[1] := 0;
-        lDicomData.XYZori[2] := 0;
-        lDicomData.XYZori[3] := 0;
-        ImageStart := 0;
-        Little_Endian := 0;
-        Allocbits_per_pixel := 16;//bits
-        //Storedbits_per_pixel:= Allocbits_per_pixel;
-        //StudyDatePos := 0;
-        //Spacing:=0;
-        //Thickness:= 0;//1391
-        Location:=0;
-        //Modality:='MR';
-        //ProtocolName := '';
-        //serietag:='';
-        PatientPosX := 0;//1392
-        PatientPosY := 0;//1392
-        PatientPosZ := 0;//1392
-        JPEGLossyCpt := false;
-        JPEGLosslessCpt := false;
-        SignedData := true;
-        CompressOffset := 0;
-        CompresssZ := 0;
-  end;
-end;
-
-function DICOMinterslicedistance(var lDicomdata1,lDicomdata2:Dicomdata): single;//1392
-begin
-     result := sqrt(sqr(lDICOMdata1.PatientPosX-lDICOMdata2.PatientPosX)
-            +sqr(lDICOMdata1.PatientPosY-lDICOMdata2.PatientPosY)
-            +sqr(lDICOMdata1.PatientPosZ-lDICOMdata2.PatientPosZ));
-
-end;
-
-end.
-
diff --git a/dcm2nii_prePARRECDTI/diskfree.pas b/dcm2nii_prePARRECDTI/diskfree.pas
deleted file mode 100755
index e6f612e..0000000
--- a/dcm2nii_prePARRECDTI/diskfree.pas
+++ /dev/null
@@ -1,352 +0,0 @@
-unit diskfree;
-
-{
-  Copyright 2001, by Michael Hopper
-
-  This unit provides generic functions for finding the number of bytes and
-  available bytes for a given drive volume or path.  These functions work for
-  both Linux and Windows systems.
-
-  Note:  In the near future, getmntent should be incorporated into the Linux
-  version of the code rather than reading the /etc/mtab file directly.  This
-  is for future compatibility.
-}
-
-interface
-
-uses
-  SysUtils;
-
-{$IFDEF LINUX}
-
-{ This function is included (necessary) only in the Linux version because the
-  Windows version is a little more intuitive, i.e., 1=A:, 2=B:, etc.
-}
-function GetVolumePath (Volume : integer) : TFileName;
-{$ENDIF}
-
-{ This overloaded function returns the number of available bytes for the
-  specified path or volume.  I've mimicked DiskFree in that Volume=0 indicates
-  the current directory (or pwd), while values greater than 0 return a value for
-  the drives A: through Z: on Windows systems.
-
-  For Linux systems, the /etc/mtab file is read, and only those devices mounted
-  under /dev are alphabetized and included.  This means that a value of 1 would
-  return the free space on /dev/fd0 if a floppy is mounted, or /dev/hda1 if a
-  floppy is not mounted.  Hence the need for the GetVolumePath function to
-  verify that you're getting the right path.
-}
-function GetAvailableFreeSpace(path : TFilename) : int64; overload;
-function GetAvailableFreeSpace(Volume : byte) : int64; overload;
-
-{  This overloaded function returns the total number of bytes for the volume or
-   path specified.  Specification of the path or volume follows the same pattern
-   as for the GetAvailableFreeSpace function.
-}
-function GetVolumeBytes(path : TFilename) : int64; overload;
-function GetVolumeBytes(Volume : byte) : int64; overload;
-
-implementation
-
-{$IFDEF MSWINDOWS}
-uses
-  Windows;
-{$ENDIF}
-
-{$IFDEF LINUX}
-uses
-  Classes,libc;
-
-const
-  MAX_PATH = 65536;
-{$ENDIF}
-
-{$IFDEF MSWINDOWS}
-function oldWindows : boolean;
-
-{
-  Use GetVersionEx windows call as defined in SysUtils and explained in the
-  Win32 help file to return true if this is a version of Win95 that is pre-OSR2.
-  Otherwise, return false.
-}
-
-var
-  MyVersionInfo : _OSVERSIONINFOA;
-
-begin
-
-// Get Windows version information
-getversionex(MyVersionInfo);
-
-// Report TRUE only if Platform is Win9x and BuildNumber is < 1000 (pre-OSR2).
-with MyVersionInfo do
-  begin
-  result := ((dwPlatformID = VER_PLATFORM_WIN32_WINDOWS) and
-            ((dwBuildNumber and $0000FFFF) < 1000))
-  end;
-end;
-{$ENDIF}
-
-
-
-{$IFDEF LINUX}
-function GetVolumePath (Volume : integer) : TFileName;
-
-{
-  Return the path of the Volume specified.  If Volume = 0, return the present
-  present working directory.
-}
-
-var
-  loop          : integer;
-  tempstr       : string;
-  mountedDrives : TStringlist;
-
-
-begin
-// return the present working directory if Volume = 0.
-if Volume = 0 then
-  result := getenvironmentvariable('PWD')
-else
-  begin
-  // Get information about currently mounted drives.
-  mountedDrives := tstringlist.create;
-  mountedDrives.LoadFromFile('/etc/mtab');
-
-  // Alphabetize
-  mountedDrives.Sort;
-
-  loop := 0;
-
-  // Loop to remove entries that are not drives
-  while loop < mountedDrives.Count do
-    begin
-    if pos('/dev/',mountedDrives.Strings[loop]) <> 1 then
-      mountedDrives.Delete(loop)
-    else
-      inc(loop);
-    end;
-
-  // If there are not enough mounted drives, then return a null string.
-  if Volume > mountedDrives.Count then
-    result := ''
-  else // parse the entry to return the mounted path.
-    begin
-    tempstr := mountedDrives.Strings[Volume-1];
-    tempstr := copy(tempstr,pos(' ',tempstr) + 1,length(tempstr));
-    tempstr := copy(tempstr,1,pos(' ',tempstr)-1);
-    result  := tempstr;
-    end;
-  end;
-end;
-{$ENDIF}
-
-
-
-function CalculateVolumeSpace(path : pchar; var AvailableBytes : int64; var TotalBytes : int64) : boolean;
-
-{
-  This function calculates and returns the number of available bytes and total
-  bytes for a given path.  It also returns a true value if successful, or false
-  if unsuccessful at determining the correct values.  If the function returns
-  false, then the AvailableBytes and TotalBytes values should be treated as
-  though they are undefined.
-}
-
-var
-{$IFDEF MSWINDOWS}
-  SectorsPerCluster,
-  BytesPerSector,
-  NumberOfFreeClusters,
-  TotalNumberOfClusters : cardinal;
-{$ENDIF}
-{$IFDEF LINUX}
-  myStatFs              : Tstatfs;
-{$ENDIF}
-
-begin
-{$IFDEF MSWINDOWS}
-
-// Check for pre-OSR2 Win95 because the GetDiskFreeSpace function was not
-// available.
-if not oldWindows then
-  result := GetDiskFreeSpaceEx(path,AvailableBytes,TotalBytes,nil)
-
-// If pre-OSR2 Win95, then calculate the free space.
-else if GetDiskFreeSpace(path,SectorsPerCluster,BytesPerSector,NumberOfFreeClusters,TotalNumberOfClusters) then
-  begin
-  result := true;
-  AvailableBytes := BytesPerSector * SectorsPerCluster * NumberOfFreeClusters;
-  TotalBytes := BytesPerSector * SectorsPerCluster * TotalNumberOfClusters;
-  end
-
-// If unsuccessful at either of the previous attempts, report failure.
-else
-  begin
-  result := false;
-  AvailableBytes := -1;
-  TotalBytes := -1;
-  end;
-{$ENDIF}
-
-{$IFDEF LINUX}
-
-// Read information about the volume.
-if statfs(path,myStatFS) = 0 then
-  begin
-
-  // Calculate AvailableBytes and TotalBytes.
-  AvailableBytes := int64(myStatFs.f_bAvail) * int64(myStatFs.f_bsize);
-  TotalBytes := int64(myStatFs.f_blocks) * int64(myStatFs.f_bsize);
-
-  // Report success.
-  result := true;
-  end
-
-else // report failure to get information
-  begin
-  AvailableBytes := -1;
-  TotalBytes := -1;
-  result := false;
-  end;
-{$ENDIF}
-end;
-
-
-
-function GetAvailableFreeSpace(path : TFilename) : int64; overload;
-
-{
-  Use the CalculateVolumeSpace function to find the free space for the path
-  specified.
-}
-
-var
-  TotalBytes      : int64;
-  pathPchar       : pchar;
-
-begin
-{$IFDEF MSWINDOWS}
-if ByteType(path,1) = mbSingleByte then
-  getmem(pathPchar,length(path) + 1)
-else
-  getmem(pathPchar,2 * (length(path) + 1));
-strpcopy(pathpchar,path);
-if not CalculateVolumeSpace(pathPchar,result,TotalBytes) then
-  result := -1;
-{$ENDIF}
-
-{$IFDEF LINUX}
-getmem(pathPchar,(length(path) + 1) * sizeof(char));
-strpcopy(pathPchar,path);
-if not CalculateVolumeSpace(pathPchar,result,TotalBytes) then
-  result := -1; // stub
-{$ENDIF}
-end;
-
-
-function GetAvailableFreeSpace(Volume : byte) : int64; overload;
-
-{
-  Use the CalculateVolumeSpace function to find the free space for the Volume
-  specified.
-}
-
-var
-  volumePath  : array [1..MAX_PATH + 1] of char;
-  volumePchar : pchar;
-  TotalSpace : int64;
-
-
-begin
-{$IFDEF MSWINDOWS}
-volumePchar := @volumePath;
-if Volume = 0 then
-  getcurrentdirectory(MAX_PATH + 1,volumePchar)
-else
-  strPCopy(volumePchar,chr(Volume - 1 + ord('A')) + ':\');
-if not CalculateVolumeSpace(volumePchar, result, TotalSpace) then
-  result := -1;
-{$ENDIF}
-
-{$IFDEF LINUX}
-volumePchar := @volumePath;
-if Volume = 0 then
-  strPCopy(volumePchar,getEnvironmentVariable('PWD'))
-else
-  strPCopy(volumePChar,GetVolumePath(Volume));
-if not CalculateVolumeSpace(volumePchar, result, TotalSpace) then
-  result := -1;
-{$ENDIF}
-end;
-
-
-
-function GetVolumeBytes(path : TFilename) : int64; overload;
-
-{
-  Use the CalculateVolumeSpace function to find the total space for the path
-  specified.
-}
-
-var
-  AvailableBytes  : int64;
-  pathPchar       : pchar;
-
-begin
-{$IFDEF MSWINDOWS}
-if ByteType(path,1) = mbSingleByte then
-  getmem(pathPchar,length(path) + 1)
-else
-  getmem(pathPchar,2 * (length(path) + 1));
-strpcopy(pathpchar,path);
-if not CalculateVolumeSpace(pathPchar,AvailableBytes,result) then
-  result := -1;
-{$ENDIF}
-
-{$IFDEF LINUX}
-getmem(pathPchar,(length(path) + 1) * sizeof(char));
-strpcopy(pathPchar,path);
-if not CalculateVolumeSpace(pathPchar,AvailableBytes, result) then
-  result := -1;
-{$ENDIF}
-end;
-
-
-
-function GetVolumeBytes(Volume : byte) : int64; overload;
-
-{
-  Use the CalculateVolumeSpace function to find the total space for the Volume
-  specified.
-}
-
-var
-  volumePath     : array [1..MAX_PATH + 1] of char;
-  volumePchar    : pchar;
-  AvailableBytes : int64;
-
-
-begin
-{$IFDEF MSWINDOWS}
-volumePchar := @volumePath;
-if Volume = 0 then
-  getcurrentdirectory(MAX_PATH + 1,volumePchar)
-else
-  strPCopy(volumePchar,chr(Volume - 1 + ord('A')) + ':\');
-if not CalculateVolumeSpace(volumePchar, AvailableBytes, result) then
-  result := -1;
-{$ENDIF}
-
-{$IFDEF LINUX}
-volumePchar := @volumePath;
-if Volume = 0 then
-  strPCopy(volumePchar,getEnvironmentVariable('PWD'))
-else
-  strPCopy(volumePChar,GetVolumePath(Volume));
-if not CalculateVolumeSpace(volumePchar, AvailableBytes, result) then
-  result := -1;
-{$ENDIF}
-end;
-
-end.
diff --git a/dcm2nii_prePARRECDTI/extrafpc.cfg b/dcm2nii_prePARRECDTI/extrafpc.cfg
deleted file mode 100755
index 4c13c40..0000000
--- a/dcm2nii_prePARRECDTI/extrafpc.cfg
+++ /dev/null
@@ -1,4 +0,0 @@
-#IFDEF Darwin
--k-macosx_version_min -k10.4
--XR/Developer/SDKs/MacOSX10.4u.sdk/
-#ENDIF
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/filename.pas b/dcm2nii_prePARRECDTI/filename.pas
deleted file mode 100755
index 48d8105..0000000
--- a/dcm2nii_prePARRECDTI/filename.pas
+++ /dev/null
@@ -1,200 +0,0 @@
-unit filename;
-{$IFDEF FPC}
-{$mode objfpc}
-{$ENDIF}
-{$H+}
-
-interface
-                                        
-
-uses
-//{$IFNDEF FPC}FileCtrl,{$ENDIF}
-  Classes, SysUtils,define_types,dicomtypes,prefs;
-procedure ExtractFileParts (var lFileName, lNameWOExt,lExt: string);
-function ExtractFileDirWithPathDelim2(lInFilename: string): string;
-procedure AplhaNumericStr (var lStr: string);
-procedure AplhaNumericStrExt (var lStr: string);
-function OutputFilename(var lDicomImgName: string; var lDicomData: dicomData; lPrefs: TPrefs): string;
-procedure StripNIIVOIExt (var lFilename: string);
-
-procedure StripGZExt (var lFilename: string);
-function FilenameWOExt( lFileName: string): string;
-function UpcaseStr(lIn: string): string;
-
-implementation
-uses dialogsx;
-
-
-function UpcaseStr(lIn: string): string;
-var lI: integer;
-begin
-	 result := lIn;
-	 if length(result) > 0 then
-		for lI := 1 to length(result) do
-			result[lI] := upcase(result[lI]);
-end;
-
-function FilenameWOExt( lFileName: string): string;
-var  lNameWOExt,lExt : string;
-begin
-	ExtractFileParts (lFileName, lNameWOExt,lExt);
-	result := extractfilename(lNameWOExt);
-end;
-
-procedure AplhaNumericStr (var lStr: string);
-var
-	S: integer;
-	lOutStr: string;
-begin
-	if length(lStr) < 1 then exit;
-	lOutStr := '';
-
-	for S := 1 to length (lStr) do
-		if lStr[S] in ['0'..'9','A'..'Z','a'..'z'] then
-			lOutStr := lOutStr+ lStr[S];
-	lStr := lOutStr;
-end;
-
-procedure AplhaNumericStrExt (var lStr: string);
-var
-	S: integer;
-	lOutStr: string;
-begin
-	if length(lStr) < 1 then exit;
-	lOutStr := '';
-
-	for S := 1 to length (lStr) do
-		if lStr[S] in ['0'..'9','A'..'Z','a'..'z','_','-','^'] then
-			lOutStr := lOutStr+ lStr[S];
-	lStr := lOutStr;
-end;
-
-procedure StripNIIVOIExt (var lFilename: string);
-var
-	lStr: string;
-	lLen,lPos: integer;
-begin
-	lLen := length(lFilename);
-	if lLen < 8 then exit;
-	lStr := '';
-	for lPos := (lLen-7) to (lLen) do
-		lStr := lStr +UpCase(lFilename[lPos]);
-	if lStr <> '.NII.VOI' then exit;
-	lStr := '';
-	for lPos := 1 to (lLen-8) do
-		lStr := lStr + lFilename[lPos];
-        lStr := lStr + '.VOI';
-	lFilename := lStr;
-end;
-
-procedure StripGZExt (var lFilename: string);
-var
-	lStr: string;
-	lLen,lPos: integer;
-begin
-	lLen := length(lFilename);
-	if lLen < 4 then exit;
-	lStr := '';
-	for lPos := (lLen-2) to (lLen) do
-		lStr := lStr +UpCase(lFilename[lPos]);
-	if lStr <> '.GZ' then exit;
-	//showmessage(lFilename +' ->'+lStr);
-	lStr := '';
-	for lPos := 1 to (lLen-3) do
-		lStr := lStr + lFilename[lPos];
-	lFilename := lStr;
-	//showmessage(lStr);
-end;
-
-function OutputFilename(var lDicomImgName: string; var lDicomData: dicomData; lPrefs: TPrefs): string;
-var lFile,lStr,lStr2,lExt: string;
- lAppendDate,lAppendAcqSeries,lAppendProtocolName,lAppendPatientName,lAppendFilename:boolean ;
-begin
-
-  lAppendDate := lPrefs.AppendDate;
-  lAppendAcqSeries := lPrefs.AppendAcqSeries;
-  lAppendProtocolName := lPrefs.AppendProtocolName;
-  lAppendPatientName := lPrefs.AppendPatientName;
-  lAppendFilename := lPrefs.AppendFilename;
-  if (not lAppendDate) and (not lAppendAcqSeries) and (not lAppendProtocolName) and (not lAppendPatientName) 
-     and (not lAppendFilename) then begin
-        lAppendDate := true;
-        lAppendAcqSeries := true;
-        lAppendProtocolName := true;
-  end;
-  lStr := '';
-
-  if lAppendPatientName then begin
-	lStr2 := lDicomData.PatientName;
-	AplhaNumericStrExt(lStr2);
-	lStr := lStr2+lStr;
-  end;
-  if lAppendProtocolName then begin
-	lStr2 := lDicomData.ProtocolName;
-	AplhaNumericStrExt(lStr2);
-	lStr := lStr2+lStr;
-  end;
-  if lAppendFilename then begin
-	  lFile := ExtractFilename (lDicomImgName);
-	  ExtractFileParts (lFile, lStr2,lExt);
-	  AplhaNumericStrExt(lStr2);
-	  lStr := lStr2+lStr;
-  end;
-  if lAppendAcqSeries then
-		  lStr := lStr+'s'+PadStr(lDicomData.SeriesNum,3)+'a'+PadStr(lDicomData.AcquNum,3);
-  if lAppendDate then
-	lStr := StudyDateTime2Str(lDicomData.DateTime)+lStr;
-  lStr :=  lPrefs.NameAppend + lStr;
-  result := lStr;
-
-
-
-end;
-
-
-
-procedure ExtractFileParts (var lFileName, lNameWOExt,lExt: string);
-var lI: integer;
-l2ndExt : string;
-begin
-   lNameWOExt := '';
-   lExt := ExtractFileExt(lFileName);
-   if length(lExt) > 0 then
-		for lI := 1 to length(lExt) do
-			lExt[lI] := upcase(lExt[lI]);
-   if (lExt = '.GZ') or (lExt = '.VOI') then begin
-	  lI := length(lFileName) - 6;
-	  if li < 1 then exit;
-	  l2ndExt := upcase(lFileName[lI])+upcase(lFileName[lI+1])+upcase(lFileName[li+2])+upcase(lFileName[li+3]);
-	  if (l2ndExt = '.TAR') or (l2ndExt = '.NII')  then
-		lExt := l2ndExt+lExt;
-   end;
-   if length(lExt) >= length (lFilename) then exit;
-   for lI := 1 to (length(lFilename)-length(lExt)) do
-    lNameWOExt := lNameWOExt + lFileName[lI];
-   //next for Unix do not use UpCase extension
-   if length(lExt) >= 0 then begin
-    l2ndExt := '';
-    for lI := 1 to (length(lExt)) do
-      l2ndExt :=  lFilename[length(lFilename)-lI+1]+l2ndExt;
-    lExt := l2ndExt;
-   end; //length > 0
-   //showmessage(lNameWOExt+'    '+lExt);
-end;
-
-function ExtractFileDirWithPathDelim2(lInFilename: string): string;
-//F:\filename.ext -> 'F:\' and F:\dir\filename.ext -> 'F:\dir\'
-//Despite documentation, Delphi3's ExtractFileDir does not always retain final pathdelim
-//ensures c:\temp is returned c:\temp\ not c:\
-begin
-  if DirExists(lInFilename) then begin
-  	result :=(lInFilename);
-	if result[length(result)]<> pathdelim then
-		result := result + pathdelim;
-	exit;
-  end;
-  result := ExtractFileDirWithPathDelim(lInFilename);
-end;
-
-end.
-
diff --git a/dcm2nii_prePARRECDTI/gui.dfm b/dcm2nii_prePARRECDTI/gui.dfm
deleted file mode 100755
index 9961827..0000000
Binary files a/dcm2nii_prePARRECDTI/gui.dfm and /dev/null differ
diff --git a/dcm2nii_prePARRECDTI/gui.lfm b/dcm2nii_prePARRECDTI/gui.lfm
deleted file mode 100755
index 3861a66..0000000
--- a/dcm2nii_prePARRECDTI/gui.lfm
+++ /dev/null
@@ -1,152 +0,0 @@
-object MainForm: TMainForm
-  Left = 355
-  Height = 363
-  Top = 132
-  Width = 598
-  ActiveControl = Panel1
-  AllowDropFiles = True
-  Caption = 'dcm2nii'
-  ClientHeight = 363
-  ClientWidth = 598
-  Menu = MainMenu1
-  OnClose = FormClose
-  OnCreate = FormCreate
-  OnDropFiles = FormDropFiles
-  OnShow = FormShow
-  Position = poScreenCenter
-  LCLVersion = '1.0.8.0'
-  object Memo1: TMemo
-    Left = 4
-    Height = 325
-    Top = 34
-    Width = 590
-    Align = alClient
-    BorderSpacing.Left = 4
-    BorderSpacing.Right = 4
-    BorderSpacing.Bottom = 4
-    ScrollBars = ssAutoVertical
-    TabOrder = 0
-  end
-  object Panel1: TPanel
-    Left = 0
-    Height = 34
-    Top = 0
-    Width = 598
-    Align = alTop
-    BevelOuter = bvNone
-    ClientHeight = 34
-    ClientWidth = 598
-    TabOrder = 1
-    object Label1: TLabel
-      Left = 1
-      Height = 26
-      Top = 5
-      Width = 140
-      Alignment = taRightJustify
-      Anchors = [akLeft]
-      AutoSize = False
-      Caption = 'Output Format:  '
-      Layout = tlCenter
-      ParentColor = False
-    end
-    object TypeCombo: TComboBox
-      Left = 160
-      Height = 20
-      Top = 3
-      Width = 264
-      ItemHeight = 0
-      Items.Strings = (
-        'SPM2 (3D Anlyze hdr/img)'
-        'SPM5 (3D NIfTI hdr/img)'
-        'SPM8 (3D NIfTI nii)'
-        '4D NIfTI hdr/img'
-        'FSL/SPM8 (4D NIfTI nii)'
-        'Compressed FSL (4D NIfTI nii)'
-      )
-      Style = csDropDownList
-      TabOrder = 0
-    end
-  end
-  object OpenHdrDlg: TOpenDialog
-    FilterIndex = 0
-    left = 24
-    top = 48
-  end
-  object MainMenu1: TMainMenu
-    left = 88
-    top = 48
-    object File1: TMenuItem
-      Caption = 'File'
-      object DICOMtoNIfTI1: TMenuItem
-        Caption = 'DICOM to NIfTI'
-        ShortCut = 16452
-        OnClick = dcm2niiBtnClick
-      end
-      object ModifyNIfTI1: TMenuItem
-        Caption = 'Modify NIfTI'
-        OnClick = ModifyNIfTI1Click
-      end
-      object NIfTI3D4D1: TMenuItem
-        Caption = 'NIfTI 3D -> 4D'
-        OnClick = NIfTI3D4D1Click
-      end
-      object AnonymizeDICOM1: TMenuItem
-        Caption = 'Anonymize DICOM'
-        OnClick = AnonymizeDICOM1Click
-      end
-      object Exit1: TMenuItem
-        Caption = 'Exit'
-        OnClick = Exit1Click
-      end
-    end
-    object Edit1: TMenuItem
-      Caption = 'Edit'
-      object Copy1: TMenuItem
-        Caption = 'Copy'
-        OnClick = Copy1Click
-      end
-    end
-    object UntestedMenu: TMenuItem
-      Caption = 'Untested'
-      object MirrorXdimension1: TMenuItem
-        Caption = 'Mirror X-dimension'
-        OnClick = MirrorXdimension1Click
-      end
-      object SumTPM1: TMenuItem
-        Caption = 'Sum TPM'
-        OnClick = SumTPM1Click
-      end
-      object ExtractDICOMdims1: TMenuItem
-        Caption = 'Extract DICOM dims'
-        OnClick = ExtractDICOMdims1Click
-      end
-      object ExtractDICOMhdr1: TMenuItem
-        Caption = 'Extract DICOM header'
-        OnClick = ExtractDICOMhdr1Click
-      end
-      object ExtractNIfTIhdrs1: TMenuItem
-        Caption = 'Extract NIfTI header'
-        OnClick = ExtractNIfTIhdrs1Click
-      end
-      object HalveMenu1: TMenuItem
-        Caption = 'Halve dimensions in-plane'
-        OnClick = HalveMenu1Click
-      end
-    end
-    object Help1: TMenuItem
-      Caption = 'Help'
-      object Preferences1: TMenuItem
-        Caption = 'Preferences'
-        OnClick = Preferences1Click
-      end
-      object About1: TMenuItem
-        Caption = 'Help'
-        OnClick = About1Click
-      end
-    end
-  end
-  object SelectDirectoryDialog1: TSelectDirectoryDialog
-    left = 159
-    top = 54
-  end
-end
diff --git a/dcm2nii_prePARRECDTI/gui.lrs b/dcm2nii_prePARRECDTI/gui.lrs
deleted file mode 100755
index 8bd9c3e..0000000
--- a/dcm2nii_prePARRECDTI/gui.lrs
+++ /dev/null
@@ -1,47 +0,0 @@
-{ This is an automatically generated lazarus resource file }
-
-LazarusResources.Add('TMainForm','FORMDATA',[
-  'TPF0'#9'TMainForm'#8'MainForm'#4'Left'#3'c'#1#6'Height'#3'k'#1#3'Top'#3#132#0
-  +#5'Width'#3'V'#2#13'ActiveControl'#7#6'Panel1'#14'AllowDropFiles'#9#7'Captio'
-  +'n'#6#7'dcm2nii'#12'ClientHeight'#3'k'#1#11'ClientWidth'#3'V'#2#4'Menu'#7#9
-  +'MainMenu1'#7'OnClose'#7#9'FormClose'#8'OnCreate'#7#10'FormCreate'#11'OnDrop'
-  +'Files'#7#13'FormDropFiles'#6'OnShow'#7#8'FormShow'#8'Position'#7#14'poScree'
-  +'nCenter'#10'LCLVersion'#6#7'1.0.8.0'#0#5'TMemo'#5'Memo1'#4'Left'#2#4#6'Heig'
-  +'ht'#3'E'#1#3'Top'#2'"'#5'Width'#3'N'#2#5'Align'#7#8'alClient'#18'BorderSpac'
-  +'ing.Left'#2#4#19'BorderSpacing.Right'#2#4#20'BorderSpacing.Bottom'#2#4#10'S'
-  +'crollBars'#7#14'ssAutoVertical'#8'TabOrder'#2#0#0#0#6'TPanel'#6'Panel1'#4'L'
-  +'eft'#2#0#6'Height'#2'"'#3'Top'#2#0#5'Width'#3'V'#2#5'Align'#7#5'alTop'#10'B'
-  +'evelOuter'#7#6'bvNone'#12'ClientHeight'#2'"'#11'ClientWidth'#3'V'#2#8'TabOr'
-  +'der'#2#1#0#6'TLabel'#6'Label1'#4'Left'#2#1#6'Height'#2#26#3'Top'#2#5#5'Widt'
-  +'h'#3#140#0#9'Alignment'#7#14'taRightJustify'#7'Anchors'#11#6'akLeft'#0#8'Au'
-  +'toSize'#8#7'Caption'#6#16'Output Format:  '#6'Layout'#7#8'tlCenter'#11'Pare'
-  +'ntColor'#8#0#0#9'TComboBox'#9'TypeCombo'#4'Left'#3#160#0#6'Height'#2#20#3'T'
-  +'op'#2#3#5'Width'#3#8#1#10'ItemHeight'#2#0#13'Items.Strings'#1#6#24'SPM2 (3D'
-  +' Anlyze hdr/img)'#6#23'SPM5 (3D NIfTI hdr/img)'#6#19'SPM8 (3D NIfTI nii)'#6
-  +#16'4D NIfTI hdr/img'#6#23'FSL/SPM8 (4D NIfTI nii)'#6#29'Compressed FSL (4D '
-  +'NIfTI nii)'#0#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#0#0#0#0#11'TOpenD'
-  +'ialog'#10'OpenHdrDlg'#11'FilterIndex'#2#0#4'left'#2#24#3'top'#2'0'#0#0#9'TM'
-  +'ainMenu'#9'MainMenu1'#4'left'#2'X'#3'top'#2'0'#0#9'TMenuItem'#5'File1'#7'Ca'
-  +'ption'#6#4'File'#0#9'TMenuItem'#13'DICOMtoNIfTI1'#7'Caption'#6#14'DICOM to '
-  +'NIfTI'#8'ShortCut'#3'D@'#7'OnClick'#7#15'dcm2niiBtnClick'#0#0#9'TMenuItem'
-  +#12'ModifyNIfTI1'#7'Caption'#6#12'Modify NIfTI'#7'OnClick'#7#17'ModifyNIfTI1'
-  +'Click'#0#0#9'TMenuItem'#10'NIfTI3D4D1'#7'Caption'#6#14'NIfTI 3D -> 4D'#7'On'
-  +'Click'#7#15'NIfTI3D4D1Click'#0#0#9'TMenuItem'#15'AnonymizeDICOM1'#7'Caption'
-  +#6#15'Anonymize DICOM'#7'OnClick'#7#20'AnonymizeDICOM1Click'#0#0#9'TMenuItem'
-  +#5'Exit1'#7'Caption'#6#4'Exit'#7'OnClick'#7#10'Exit1Click'#0#0#0#9'TMenuItem'
-  +#5'Edit1'#7'Caption'#6#4'Edit'#0#9'TMenuItem'#5'Copy1'#7'Caption'#6#4'Copy'#7
-  +'OnClick'#7#10'Copy1Click'#0#0#0#9'TMenuItem'#12'UntestedMenu'#7'Caption'#6#8
-  +'Untested'#0#9'TMenuItem'#17'MirrorXdimension1'#7'Caption'#6#18'Mirror X-dim'
-  +'ension'#7'OnClick'#7#22'MirrorXdimension1Click'#0#0#9'TMenuItem'#7'SumTPM1'
-  +#7'Caption'#6#7'Sum TPM'#7'OnClick'#7#12'SumTPM1Click'#0#0#9'TMenuItem'#17'E'
-  +'xtractDICOMdims1'#7'Caption'#6#18'Extract DICOM dims'#7'OnClick'#7#22'Extra'
-  +'ctDICOMdims1Click'#0#0#9'TMenuItem'#16'ExtractDICOMhdr1'#7'Caption'#6#20'Ex'
-  +'tract DICOM header'#7'OnClick'#7#21'ExtractDICOMhdr1Click'#0#0#9'TMenuItem'
-  +#17'ExtractNIfTIhdrs1'#7'Caption'#6#20'Extract NIfTI header'#7'OnClick'#7#22
-  +'ExtractNIfTIhdrs1Click'#0#0#9'TMenuItem'#10'HalveMenu1'#7'Caption'#6#25'Hal'
-  +'ve dimensions in-plane'#7'OnClick'#7#15'HalveMenu1Click'#0#0#0#9'TMenuItem'
-  +#5'Help1'#7'Caption'#6#4'Help'#0#9'TMenuItem'#12'Preferences1'#7'Caption'#6
-  +#11'Preferences'#7'OnClick'#7#17'Preferences1Click'#0#0#9'TMenuItem'#6'About'
-  +'1'#7'Caption'#6#4'Help'#7'OnClick'#7#11'About1Click'#0#0#0#0#22'TSelectDire'
-  +'ctoryDialog'#22'SelectDirectoryDialog1'#4'left'#3#159#0#3'top'#2'6'#0#0#0
-]);
diff --git a/dcm2nii_prePARRECDTI/gui.pas b/dcm2nii_prePARRECDTI/gui.pas
deleted file mode 100755
index 6627c27..0000000
--- a/dcm2nii_prePARRECDTI/gui.pas
+++ /dev/null
@@ -1,1166 +0,0 @@
-unit gui;
-{$IFDEF FPC}{$mode objfpc}{$H+}{$ENDIF}
-interface
-uses
-{$IFDEF FPC}LResources,LCLIntf, {$ENDIF}
-{$IFNDEF UNIX}  Windows,ShellAPI,ShlObj,
-{$ELSE}
-BaseUnix,LCLType,
-{$ENDIF}
-Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls,
-ToolWin, ComCtrls, ExtCtrls,IniFiles,define_types,sortdicom,dicom,parconvert,
-filename, convert,userdir,  paramstrs,nifti_hdr,nii_math,dicomtypes,nii_crop,
-nii_orient, nii_4dto3d,nii_asl,nii_reslice, Menus,nii_3dto4d,prefs,
-ConvertSimple,GraphicsMathLibrary;
-{$IFDEF FPC}
-type
-   { TMainForm }
-   TMainForm = class(TForm)
-    SelectDirectoryDialog1: TSelectDirectoryDialog;//<-Lazarus only - does not exist in Delphi 4
-    Label1: TLabel;
-    MainMenu1: TMainMenu;
-    File1: TMenuItem;
-    Edit1: TMenuItem;
-    Help1: TMenuItem;
-    About1: TMenuItem;
-    Copy1: TMenuItem;
-    DICOMtoNIfTI1: TMenuItem;
-    AnonymizeDICOM1: TMenuItem;
-    Exit1: TMenuItem;
-    ExtractDICOMdims1: TMenuItem;
-    ExtractDICOMhdr1: TMenuItem;
-    ExtractNIfTIhdrs1: TMenuItem;
-    SumTPM1: TMenuItem;
-    MirrorXdimension1: TMenuItem;
-    UntestedMenu: TMenuItem;
-    NIfTI3D4D1: TMenuItem;
-    ModifyNIfTI1: TMenuItem;
-    Preferences1: TMenuItem;
-    Memo1: TMemo;
-    OpenHdrDlg: TOpenDialog;
-    Panel1: TPanel;
-    TypeCombo: TComboBox;
-    ResliceNIfTI1: TMenuItem;
-    Deletenondcm1: TMenuItem;
-    HalveMenu1: TMenuItem;
-    procedure SavePrefs;
-    procedure ExtractDICOMdims1Click(Sender: TObject);
-    procedure ExtractDICOMhdr1Click(Sender: TObject);
-    procedure ExtractNIfTIhdrs1Click(Sender: TObject);
-    procedure FormClose(Sender: TObject; var vAction: TCloseAction);
-    procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
-    procedure HalveMenu1Click(Sender: TObject);
-    function OpenDialogExecute (lCaption: string;lAllowMultiSelect,lForceMultiSelect: boolean; lFilter: string): boolean;
-    procedure CheckPrefs (var lPrefs: TPrefs; lWrite: boolean);
-    function ConvertDCM2NII (lFilename: string; var lPrefs: TPrefs): boolean;
-    procedure FormCreate(Sender: TObject);
-    procedure Exit1Click(Sender: TObject);
-    procedure Copy1Click(Sender: TObject);
-    procedure About1Click(Sender: TObject);
-    procedure Preferences1Click(Sender: TObject);
-    procedure FormShow(Sender: TObject);
-    procedure SumTPM1Click(Sender: TObject);
-    procedure TypeComboChange(Sender: TObject);
-    procedure AnonymizeDICOM1Click(Sender: TObject);
-    procedure ModifyNIfTI1Click(Sender: TObject);
-    procedure NIfTI3D4D1Click(Sender: TObject);
-    procedure ResliceNIfTI1Click(Sender: TObject);
-    procedure Deletenondcm1Click(Sender: TObject);
-    procedure dcm2niiBtnClick(Sender: TObject);
-    procedure MirrorXdimension1Click(Sender: TObject);
-    function BrowseDialog(const Title: string): string;
-  end;
-{$ELSE}
-type
-   TMainForm = class(TForm)
-    Label1: TLabel;
-    MainMenu1: TMainMenu;
-    File1: TMenuItem;
-    Edit1: TMenuItem;
-    Help1: TMenuItem;
-    About1: TMenuItem;
-    Copy1: TMenuItem;
-    DICOMtoNIfTI1: TMenuItem;
-    AnonymizeDICOM1: TMenuItem;
-    Exit1: TMenuItem;
-    ExtractDICOMdims1: TMenuItem;
-    ExtractDICOMhdr1: TMenuItem;
-    ExtractNIfTIhdrs1: TMenuItem;
-    SumTPM1: TMenuItem;
-    MirrorXdimension1: TMenuItem;
-    UntestedMenu: TMenuItem;
-    NIfTI3D4D1: TMenuItem;
-    ModifyNIfTI1: TMenuItem;
-    Preferences1: TMenuItem;
-    Memo1: TMemo;
-    OpenHdrDlg: TOpenDialog;
-    Panel1: TPanel;
-    TypeCombo: TComboBox;
-    ResliceNIfTI1: TMenuItem;
-    Deletenondcm1: TMenuItem;
-    HalveMenu1: TMenuItem;
-        procedure SavePrefs;
-    procedure ExtractDICOMdims1Click(Sender: TObject);
-    procedure ExtractDICOMhdr1Click(Sender: TObject);
-    procedure ExtractNIfTIhdrs1Click(Sender: TObject);
-    procedure FormClose(Sender: TObject; var vAction: TCloseAction);
-    procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
-    procedure HalveMenu1Click(Sender: TObject);
-    function OpenDialogExecute (lCaption: string;lAllowMultiSelect,lForceMultiSelect: boolean; lFilter: string): boolean;
-    procedure CheckPrefs (var lPrefs: TPrefs; lWrite: boolean);
-    function ConvertDCM2NII (lFilename: string; var lPrefs: TPrefs): boolean;
-    procedure FormCreate(Sender: TObject);
-    procedure Exit1Click(Sender: TObject);
-    procedure Copy1Click(Sender: TObject);
-    procedure About1Click(Sender: TObject);
-    procedure Preferences1Click(Sender: TObject);
-    procedure FormShow(Sender: TObject);
-    procedure SumTPM1Click(Sender: TObject);
-    procedure TypeComboChange(Sender: TObject);
-    procedure AnonymizeDICOM1Click(Sender: TObject);
-    procedure ModifyNIfTI1Click(Sender: TObject);
-    procedure NIfTI3D4D1Click(Sender: TObject);
-    procedure ResliceNIfTI1Click(Sender: TObject);
-    procedure Deletenondcm1Click(Sender: TObject);
-    procedure dcm2niiBtnClick(Sender: TObject);
-    procedure MirrorXdimension1Click(Sender: TObject);
-    function BrowseDialog(const Title: string): string;
-  private
-         procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES; //<-Delphi only - does not exist in Lazarus
-  end;
-{$ENDIF}
-var
-  MainForm: TMainForm;
-
-implementation
-
-uses untar,pref_form, nifti_form,niftiutil{$IFNDEF UNIX},ActiveX {$ENDIF};
-{$IFNDEF FPC}
-{$R *.DFM}
-{$R windowsxp.res}
-{$ENDIF}
-
-procedure MsgX (lStr: string);
-begin
-         MainForm.Memo1.Lines.Add(lStr);
-end;
-
-function is4D (var lHdr: TNIFTIhdr): boolean;
-begin
-     if lHdr.dim[4] > 1 then
-        result := true
-     else
-         result := false;
-end;
-function SelectProcessNIFTI (var lHdr: TNIFTIhdr; var lFilename: string): integer;
-begin
-     result := -1; //returns -1 if error
-     if is4D(lHdr) then begin
-        NIfTIForm.Combo3D.visible := false;
-        NIfTIForm.Combo4D.visible := true;
-     end else begin
-         //NIfTIForm.Combo3D.itemIndex := 2;
-         NIfTIForm.Combo3D.visible := true;
-         NIfTIForm.Combo4D.visible := false;
-     end;
-     NiftiForm.Combo4DChange(nil);
-     NIftiForm.caption := extractfilename(lFilename);
-     //next - let user specify task
-     NiftiForm.showmodal;
-     if (NiftiForm.ModalResult = mrCancel) then
-        exit;
-     if is4D(lHdr) then
-        result := NiftiForm.Combo4D.ItemIndex
-     else
-         result := NiftiForm.Combo3D.ItemIndex;
-end;
-
-
-
-procedure ProcessNIfTI(lFilenames : TStrings; lPrefs: TPrefs);
-var
-   l4D, lPrev4D, lByteSwap: boolean;
-   lINc,lProcess: integer;
-   lExt,lFilename,lOutname: string;
-   lHdr: TNIFTIhdr;
-begin
-     if lFilenames.Count < 1 then exit;
-     //CheckHugeUint16(lFilenames.Strings[0], false);
-
-     lPrev4D := false; //ignored in if statement - set only to avoid compiler warning
-     lProcess := 0; //always set in if statement - set only to avoid compiler warning
-     for lInc := 1 to lFilenames.Count do begin
-         lFilename := lFilenames.Strings[lInc-1];
-         lExt := UpCaseExt(lFilename);
-         if lExt ='.IMG' then
-            lFilename :=  changefileext(lFilename,'.hdr');
-         if not NIFTIhdr_LoadHdr (lFilename, lHdr, lByteSwap) then begin
-            MsgX('Unable to read as NifTI/Analyze' + lFilename);
-            exit;
-         end;
-         l4D := is4D(lHdr);
-         //choose process
-         //fx( lFilenames.Count,777);
-         if (lInc = 1) or (l4D <> lPrev4D) then begin
-            lProcess := SelectProcessNIFTI(lHdr,lFilename);
-            if lProcess < 0 then exit;
-            lPrev4D := l4D;
-         end;
-         //next - convert image as specified
-         SetOutputFormat(NIfTIForm.TypeCombo.ItemIndex,lPrefs);
-         if l4D then begin
-         case lProcess of
-              0: ChangeNIfTISubformat(lFilename,lHdr,lPrefs);
-              1: Reorder4D(lFilename, lHdr, lByteSwap,lPrefs);
-              2: Clip4D(lFilename, lHdr, false,lPrefs,NiftiForm.StartEdit.value, NiftiForm.EndEdit.value);
-              3: Float32NIfTI(lFilename, lPrefs);
-               4: FormulaNIfTI(lFilename,lPrefs, NiftiForm.ScaleEdit.value, NiftiForm.PowerEdit.value);
-              5: ASL_subtract(lFilename,false,{subtract} (NiftiForm.AsLCombo.itemIndex ),lPrefs);
-              6: CropNIfTIX(lFilename, lPrefs, NiftiForm.EndEdit.value, NiftiForm.StartEdit.value, 0,0,0,0 );
-
-              else showmessage('Unknown function');
-         end; //case combo
-     end else begin //if 4d else 3d
-         //Int16LogPtoZNIfTI32Z(lFilename, lPrefs);
-         case lProcess of
-              0: ChangeNIfTISubformat(lFilename,lHdr,lPrefs);
-              1: Reorient(lFilename,lHdr, lPrefs,false,false);
-              2: begin
-                   lOutname := Reorient(lFilename,lHdr, lPrefs,false,false);
-                   if lOutname <> '' then
-                    CropNIfTI(lOutname,lPrefs);
-                 end;//2
-              3: CropNIfTIX(lFilename, lPrefs, NiftiForm.EndEdit.value, NiftiForm.StartEdit.value, 0,0,0,0 );
-              4: SiemensPhase2RadiansNIfTI(lFilename, lPrefs);
-              else showmessage('Unknown function');
-
-         end; //case 3d
-     end; //if 4d else 3d end
- end; //for each image
-end;
-
-procedure PromptOutput (var lPrefs: TPrefs);
-begin
-     if (lPrefs.OutDirMode = kOutDirModePrompt) then
-        lPrefs.OutDir := GetDirPrompt(lPrefs.OutDir);
-     //GetDirPrompt(lPrefs.OutDir);
-end;
-
-function TMainForm.ConvertDCM2NII (lFilename: string; var lPrefs: TPrefs): boolean;
-//returns true if files treated as DICOM or PAR/REC - these will search entire folder
-var
-   lOutDir,lExt: String;
-   lStartTime: DWord;
-   lStrings : TStrings;
-begin
-     DecimalSeparator := '.';
-     result := false;
-     if (not Fileexists(lFilename)) and (not DirExists(lFilename)) then
-        exit;
-     PromptOutput ( lPrefs);
-     result := true;
-     //3/2011... do not clear here, so we can look across images... Memo1.lines.clear;
-     //MsgX(kVers);
-     Memo1.lines.add('Converting '+lFilename);
-     Memo1.Repaint;
-     MainForm.Repaint;
-     MainForm.Update;
-     refresh;
-
-
-     lOutDir := extractfiledir(lFilename);
-     lStartTime := GetTickCount;
-     if DirExists(lFilename) then begin
-        RecursiveFolderSearch(lFilename,lFilename,lPrefs,0);
-        lPrefs.NameAppend := '';
-     end else begin
-          lExt := UpCaseExt(lFilename);
-          {if (lExt = '.FDF') then
-             ConvertSimple2NII(lFilename,lOutDir,lPrefs)
-          else}
-          if (lExt = '.REC') or (lExt = '.PAR') then begin
-             LoadFileListPARREC(lFilename,lOutDir,lPrefs)
-          end else if (lExt = '.TGZ')  then
-                DeTGZ(lFilename,lPrefs)
-          else if (IsNiftiExt (lFilename)) or (IsVOIExt (lFilename)) then begin
-              result := false;
-              lStrings := TStringList.Create;
-              lStrings.add(lFilename);
-              ProcessNIfTI(lStrings,lPrefs);
-              lStrings.Free;
-          end else begin
-              if (DirExists(lOutDir)) and (not lPrefs.Verbose)  then
-                 RecursiveFolderSearch(lOutDir,lOutDir,lPrefs,0)
-              else
-                  LoadFileList(lFilename,lOutDir,lPrefs);
-              lPrefs.NameAppend := '';
-          end;
-     end;
-     Memo1.lines.add('Conversion completed in '+inttostr(GetTickCount-lStartTime)+' ms');
-end;
-
-function ShowHeader (lFilename: string): boolean;
-var
-   lPrefs: TPrefs;
-begin
-     PrefsForm.ReadPrefs(lPrefs);
-     lPrefs.verbose := true;
-     MainForm.Memo1.lines.add('Location '+lFilename);
-     result := MainForm.ConvertDCM2NII( lFilename,lPrefs);
-
-end;
-
-procedure ProcessFilenames(lFilenames : TStrings; lPrefs: TPrefs);
-var
-   i: integer;
-   lAllNII: boolean;
-begin
-     if lFilenames.Count < 1 then exit;
-     lAllNii := true;
-     for i := 0 to (lFilenames.Count-1) do
-           if (not (IsNiftiExt (lFilenames.Strings[i]))) and (not (IsVOIExt (lFilenames.Strings[i]))) then
-              lAllNii := false;
-     if lAllNii then begin
-        ProcessNiFTI (lFilenames,lPrefs);
-        exit;
-     end;
-     if ssCtrl in KeyDataToShiftState(vk_Shift) then begin
-        for i := 0 to (lFilenames.Count-1) do
-             ShowHeader (lFilenames.Strings[i])
-     end else
-             MainForm.ConvertDCM2NII( lFilenames.Strings[0],lPrefs);
-end;
-
-{$IFNDEF FPC}//if delphi
-
-procedure TMainForm.WMDropFiles(var Msg: TWMDropFiles);
-var
-  CFileName: array[0..MAX_PATH] of Char;
-
-  lInc: integer;
-  lPrefs: TPrefs;
-  lStrings: TStrings;
-begin
-     CheckPrefs(lPrefs,False);
-  //lDone := false;
-  lInc := 0;
-  try
-   lStrings := TStringList.Create;
-   while (DragQueryFile(Msg.Drop, lInc, CFileName, MAX_PATH) > 0) {and (not lDone)} do begin
-          lStrings.add(CFilename);
-
-         Msg.Result := 0;
-         inc(lInc);
-    end; //while
-    ProcessFilenames(lStrings,lPrefs);
-    lStrings.Free;
-  finally
-    DragFinish(Msg.Drop);
-  end;
-end;
-
-function TMainForm.BrowseDialog(const Title: string): string;
-var
-  iFlag: integer;
-  lpItemID : PItemIDList;
-  BrowseInfo : TBrowseInfo;
-  DisplayName : array[0..MAX_PATH] of char;
-  TempPath : array[0..MAX_PATH] of char;
-begin
-  iFlag :=  BIF_RETURNONLYFSDIRS;
-    //iFlag :=  BIF_BROWSEINCLUDEFILES;
-    //iFlag :=  BIF_BROWSEFORCOMPUTER;
-    //iFlag :=  BIF_BROWSEFORPRINTER;
-  Result:='';
-  FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
-  with BrowseInfo do begin
-	hwndOwner := Application.Handle;
-	pszDisplayName := @DisplayName;
-	lpszTitle := PChar(Title);
-	ulFlags := iFlag;
-  end;
-  lpItemID := SHBrowseForFolder(BrowseInfo);
-  if lpItemId <> nil then begin
-	SHGetPathFromIDList(lpItemID, TempPath);
-	Result := TempPath;
-	GlobalFreePtr(lpItemID);
-  end;     
-end;
-{$ELSE}
-function TMainForm.BrowseDialog(const Title: string): string;
-begin
-    result := '';
-    SelectDirectoryDialog1.title := Title;
-    if not SelectDirectoryDialog1.execute then exit;
-    result := SelectDirectoryDialog1.Filename;
-end;
-{$ENDIF}
-procedure TMainForm.dcm2niiBtnClick(Sender: TObject);
-var
-   sTitle,lDirName: string;
-   lPrefs: TPrefs;
-begin
-     CheckPrefs(lPrefs,False);
-//    {$IFNDEF UNIX}
-      sTitle:='Choose a folder with DICOM images';
-      lDirName := BrowseDialog(sTitle);
-//      {$ELSE}
-//      if not OpenDialogExecute('Select DICOM images you wish to convert)',true,false,kAnyFilter) then
-//         exit;
-//         lDirName := extractfiledir( OpenHdrDlg.Filename);
-//      {$ENDIF}
-      ConvertDCM2NII(lDirName,lPrefs);
-end;
-
-
-
-procedure TMainForm.CheckPrefs (var lPrefs: TPrefs; lWrite: boolean);
-begin
-    if lWrite then begin
-       //showmessage('w');
-       //options if writing
-      TypeCombo.ItemIndex :=  DefaultOutputFormat (lPrefs);
-
-      (*  if lPrefs.SPM2 then
-          TypeCombo.ItemIndex := 0 //SPM2 3D hdr/img analyze
-       else if not lPrefs.FourD  then begin
-            if not (lPrefs.SingleNIIFile) then
-               TypeCombo.ItemIndex := 1 //SPM5 3D hdr/img
-            else
-                TypeCombo.ItemIndex := 2; //SPM8 3D nii
-       end else if not lPrefs.SingleNIIFile then
-            TypeCombo.ItemIndex := 3 //?? 4D hdr/img
-       else if not lPrefs.GZip then
-            TypeCombo.ItemIndex := 4 //FSL 4D nii
-       else
-           TypeCombo.ItemIndex := 5; //FSL 4D nii.gz *)
-       exit;
-    end;
-  SetDefaultPrefs (lPrefs);
-  PrefsForm.ReadPrefs(lPrefs);
-  SetOutputFormat(TypeCombo.ItemIndex,lPrefs);
-  lPrefs.AnonymizeSourceDICOM := false;
-end;
-
-(*procedure Fz;
-var
-   lPrefs: TPrefs;
-   lByteSwap: boolean;
-   lExt,lFilename,lOutname,lNameWOExt: string;
-   lHdr: TNIFTIhdr;
-begin
-  lFilename := 'C:\dti64\rapid\fz3.nii';
-  lFilename := 'C:\t1\mx.nii';
-     if not NIFTIhdr_LoadHdr (lFilename, lHdr, lByteSwap) then begin
-        MsgX('Unable to read as NifTI/Analyze' + lFilename);
-        exit;
-     end;
-     MainForm.CheckPrefs(lPrefs,False);
-  Reorient(lFilename, lHdr,lPrefs,false);
-end;     *)
-
-(*procedure Fz;
-var
-   lPrefs: TPrefs;
-   lF: string;
-begin
-     lF := 'C:\iceland\temp';
-      SetDefaultPrefs (lPrefs);
-       lPrefs.AnonymizeSourceDICOM := true;
-     MainForm.ConvertDCM2NII(lF,lPrefs);
-end;*)
-
-procedure TMainForm.FormCreate(Sender: TObject);
-begin
-    {$IFDEF Darwin}
-      Exit1.visible := false;
-    {$ENDIF}
-      {$IFNDEF UNIX}DragAcceptFiles(Handle, True);{$ENDIF}
-    //Memo1.Lines.Add(kVers);
-    DecimalSeparator := '.';
-    Application.HintHidePause := 30000;
-    {$IFDEF Darwin}
-    {$IFNDEF LCLgtk} //only for Carbon compile
-            DICOMtoNIfTI1.ShortCut := ShortCut(Word('D'), [ssMeta]);
-            Copy1.ShortCut := ShortCut(Word('C'), [ssMeta]);
-            Preferences1.ShortCut := ShortCut(Word('P'), [ssMeta]);
-            About1.ShortCut := ShortCut(Word('A'), [ssMeta]);
-    {$ENDIF}//Carbon
-    {$ENDIF}//Darwin
-end;          
-
-
-
-procedure TMainForm.Exit1Click(Sender: TObject);
-begin
-     Close;
-end;
-
-procedure TMainForm.Copy1Click(Sender: TObject);
-begin
-	Memo1.SelectAll;
-	Memo1.CopyToClipboard;
-end;
-
-(*procedure testpermissions;
-var
-   p,n,x,s: string;
-
-begin
-    s:= '/usr/lib64/lazarus/cr/';
-    inputquery('cap','name',s);
-     FilenameParts (s,p,n,x);
-     if DirWritePermission(p) then
-        showmessage('+'+p+'*'+n+'*'+x)
-     else
-         showmessage('-'+p+'*'+n+'*'+x);
-end; *)
-
-(*procedure testpermissions;
-var
-   p,n,x,s: string;
-
-begin
-    s:= '/usr/lib64/lazarus/test/dcm2niigui.ini';
-    if fpAccess (s,R_OK)=0 then //ensure user has read-access to prefs file...
-       showmessage('dcm = 0');
-    s:= '/usr/lib64/lazarus/test/dcx.ini';
-    if fpAccess (s,R_OK)=0 then //ensure user has read-access to prefs file...
-       showmessage('dcx = 0');
-
-end; *)
-(*procedure Force32;
-var
-   lPrefs: TPrefs;
-   lI: integer;
-begin
-     PrefsForm.ReadPrefs(lPrefs);
-     for lI := 1 to 6 do
-         NII_force32 ('C:\walker\vois\i'+inttostr(lI)+'.nii','C:\walker\vois\ri'+inttostr(lI)+'.nii',lPrefs);
-end;*)
-
-(*procedure Force32;
-var
-   lPrefs: TPrefs;
-begin
-     PrefsForm.ReadPrefs(lPrefs);
-         Rescale_4Dtissuemaps ('C:\walker\vois\4Dsri1.nii','C:\walker\vois\TPMQ.nii',lPrefs);
-end;*)
-
-(*procedure Force32;
-var
-   lPrefs: TPrefs;
-const
-     kDir = 'C:\walker\i3\';
-     kTemp = kDir + 'TPM3.nii';
-     kTempSym = kDir + 'TPM3sym.nii';
-begin
-//exit;
-     PrefsForm.ReadPrefs(lPrefs);
-         //scale_4Dtissuemaps ('C:\walker\vois\4Dsri1.nii','C:\walker\TPMLo.nii',lPrefs);
-         //rge4DFiles ('C:\walker\TPMLo.nii','C:\walker\TPMHi.nii','C:\walker\TPMEX.nii',78,lPrefs);
-     Insert3Din4D (kDir+'m1.nii.gz',kTemp,kTemp,1, lPrefs);
-     Insert3Din4D (kDir+'m2.nii.gz',kTemp,kTemp,2, lPrefs);
-     Insert3Din4D (kDir+'m3.nii.gz',kTemp,kTemp,3, lPrefs);
-     Insert3Din4D (kDir+'m4.nii.gz',kTemp,kTemp,4, lPrefs);
-     Insert3Din4D (kDir+'m5.nii.gz',kTemp,kTemp,5, lPrefs);
-     Insert3Din4D (kDir+'m6.nii.gz',kTemp,kTemp,6, lPrefs);
-     Rescale_4Dtissuemaps(kTemp,kTempSym,lPrefs,true);
-end;  *)
-
-(*procedure Force32;
-var
-   lPrefs: TPrefs;
-const
-     kDir = 'C:\walker\i4\';
-     kTemp = kDir + 'TPM4.nii';
-     kTempSym = kDir + 'TPM4sym.nii';
-begin
-//exit;
-     PrefsForm.ReadPrefs(lPrefs);
-         //scale_4Dtissuemaps ('C:\walker\vois\4Dsri1.nii','C:\walker\TPMLo.nii',lPrefs);
-         //rge4DFiles ('C:\walker\TPMLo.nii','C:\walker\TPMHi.nii','C:\walker\TPMEX.nii',78,lPrefs);
-     Insert3Din4D (kDir+'sm1.nii',kTemp,kTemp,1, lPrefs);
-     Insert3Din4D (kDir+'sm2.nii',kTemp,kTemp,2, lPrefs);
-     Insert3Din4D (kDir+'sm3.nii',kTemp,kTemp,3, lPrefs);
-     Insert3Din4D (kDir+'sm4.nii',kTemp,kTemp,4, lPrefs);
-     Insert3Din4D (kDir+'sm5.nii',kTemp,kTemp,5, lPrefs);
-     Insert3Din4D (kDir+'sm6.nii',kTemp,kTemp,6, lPrefs);
-     Rescale_4Dtissuemaps(kTemp,kTempSym,lPrefs,true);
-end;  *)
-(*procedure Force32;
-var
-   lPrefs: TPrefs;
-   lMaskName: string;
-   lHdr: TNIfTIHdr;
-   lByteSwap, lSaveThresh3D: boolean;
-   lV: integer;
-begin
-//exit;
-     PrefsForm.ReadPrefs(lPrefs);
-     if not MainForm.OpenDialogExecute('Select the mask image',false,false,kImgFilter) then
-        exit;
-     lMaskName := MainForm.OpenHdrDlg.Filename;
-     if not NIFTIhdr_LoadHdr (lMaskName, lHdr, lByteSwap) then
-        exit;
-     if (lHdr.Dim[4] < 1) then
-        exit;
-     lSaveThresh3D := (MessageDlg('Save thresholded images for each individual?',mtCustom,[mbYes,mbNo], 0)=mrYes);
-
-     for lV := 1 to lHdr.Dim[4] do
-         if MainForm.OpenDialogExecute('Select NIfTI images you wish to mask with volume '+inttostr(lV),true,false,kImgFilter) then
-            MaskImages(lMaskName, MainForm.OpenHdrDlg.Files,lPrefs,lV, lSaveThresh3D);
-end;   *)
-
-(*procedure Force32;
-var
-   lPrefs: TPrefs;
-   lI: integer;
-   //lMaskName: string;
-begin
-//exit;
-     PrefsForm.ReadPrefs(lPrefs);
-     if not MainForm.OpenDialogExecute('Select all the c1 (gray matter) images to binarize. The c2 (gray matter),c3,c4,c5,c6 images should be in th same folder.',true,false,kImgFilter) then
-        exit;
-     //lMaskName := ('C:\Documents and Settings\chris\Desktop\walkerseg\zero\wc120100128_102305t1saghiress002a1001.nii');
-     //Binarize(lMaskName,lPrefs);
-     if MainForm.OpenHdrDlg.Files.count < 1 then exit;
-     for lI := 0 to (MainForm.OpenHdrDlg.Files.count-1) do
-         Binarize(MainForm.OpenHdrDlg.Files[lI],lPrefs);
-end;    *)
-
-{$IFNDEF FPC}
-procedure MaskVBM;
-var
-   lPrefs: TPrefs;
-   lI: integer;
-   lMaskName: string;
-begin
-     PrefsForm.ReadPrefs(lPrefs);
-     if not MainForm.OpenDialogExecute('Select all TEMPLATE c1 (gray matter) image.',false,false,kImgFilter) then
-        exit;
-     lMaskName := MainForm.OpenHdrDlg.Filename;
-     if not MainForm.OpenDialogExecute('Select all the c1 (gray matter) images to binarize. The c2 (gray matter),c3,c4,c5,c6 images should be in th same folder.',true,false,kImgFilter) then
-        exit;
-     if MainForm.OpenHdrDlg.Files.count < 1 then exit;
-     for lI := 0 to (MainForm.OpenHdrDlg.Files.count-1) do
-         MaskImgs(lMaskName, MainForm.OpenHdrDlg.Files[lI],lPrefs, 0.02);
-end;
-{$ENDIF}
-{$IFNDEF FPC}
-procedure Mask;
-var
-   lPrefs: TPrefs;
-   lMaskName: string;
-   lHdr: TNIfTIHdr;
-   lByteSwap {, lSaveThresh3D}: boolean;
-   lI,lV: integer;
-begin
-     PrefsForm.ReadPrefs(lPrefs);
-     if not MainForm.OpenDialogExecute('Select the mask image',false,false,kImgFilter) then
-        exit;
-     lMaskName := MainForm.OpenHdrDlg.Filename;
-     if not NIFTIhdr_LoadHdr (lMaskName, lHdr, lByteSwap) then
-        exit;
-     lV := 1;
-     //lSaveThresh3D := (MessageDlg('Save thresholded images for each individual?',mtCustom,[mbYes,mbNo], 0)=mrYes);
-     //for lV := 1 to lHdr.Dim[4] do
-     if not MainForm.OpenDialogExecute('Select NIfTI images you wish to mask with volume '+inttostr(lV),true,false,kImgFilter) then
-        exit;
-     if MainForm.OpenHdrDlg.Files.count < 1 then exit;
-     for lI := 0 to (MainForm.OpenHdrDlg.Files.count-1) do
-         MaskImg(lMaskName, MainForm.OpenHdrDlg.Files[lI], lPrefs, 1);
-end;
-{$ENDIF}
-
-
-function ExtNIIorIMG(lStr: string): boolean;
-var
-   lExt: string;
-begin
-     result := false;
-     lExt := UpCaseExt(lStr);
-     if (lExt = '.NII') or (lExt = '.NII.GZ') then
-        result := true;
-     if (lExt = '.IMG') {and (FSize(ChangeFileExt(lStr,'.hdr'))> 0)} then
-        result := true;
-end;
-
-procedure NIIbatch (lDir,lS: string);
-begin
-     with mainform.Memo1.lines do begin
-          add('subjx = strvcat'+lS+';');
-          add('subj = cellstr(subjx);');
-          add('dir = '''+lDir+''';');
-          add('tic');
-          add('for i=1:length(subj)');
-          add('  filename = [dir,filesep,subj{i}];');
-          add('  nii_16bit(filename);');
-          add('end;');
-          add('toc');
-     end;//with
-end;//proc NIIbatch
-procedure NII2Mat;
-var
-   str,pre,sTitle,lDirName: string;
-   lSearchRec: TSearchRec;
-begin
-        {$IFNDEF FPC}
-        sTitle:='Choose a folder with DICOM images';
-      lDirName := MainForm.BrowseDialog(sTitle);
-      {$ELSE}
-      if not MainForm.OpenDialogExecute('Select DICOM images you wish to inspect)',true,false,kAnyFilter) then
-         exit;
-      lDirName := extractfiledir( MainForm.OpenHdrDlg.Filename);
-      {$ENDIF}
-      str := '(';
-      pre := '';
-
-{$IFDEF UNIX}
- if FindFirst(lDirName+pathdelim+'*',faAnyFile-faSysFile,lSearchRec) = 0 then begin
-{$ELSE}
- if FindFirst(lDirName+pathdelim+'*.*',faAnyFile-faSysFile,lSearchRec) = 0 then begin
-{$ENDIF}
-    //lFilename := '';
-    repeat
-      //lNewName := lNewDir+lSearchRec.Name;
-      if  (lSearchRec.Name = '.') or (lSearchRec.Name = '..') then begin
-            //
-      end else if (lSearchRec.Name <> '') and (ExtNIIorIMG(lSearchRec.Name)) and (not DirExists(lSearchRec.Name)) then begin
-	      	str := str +pre+ ''''+extractfilename(lSearchRec.Name)+'''';
-                pre:=','
-      end;
-      //mainform.Memo1.lines.add(lSearchRec.Name);
-    until (FindNext(lSearchRec) <> 0);
-
- end;
- FindClose(lSearchRec);
- str := str + ')';
- if length(str) > 2 then
-    NIIbatch (lDirName,str)//mainform.Memo1.lines.add(str)
- else
-    mainform.Memo1.lines.add('No NIfTI images found in '+lDirName)
-
-end;
-
-(*procedure NII2Mat(lExt: string);
-var
-   str,pre,sTitle,lDirName: string;
-   lSearchRec: TSearchRec;
-begin
-        {$IFNDEF FPC}
-        sTitle:='Choose a folder with DICOM images';
-      lDirName := BrowseDialog(sTitle);
-      {$ELSE}
-      if not OpenDialogExecute('Select DICOM images you wish to inspect)',true,false,kAnyFilter) then
-         exit;
-      lDirName := extractfiledir( OpenHdrDlg.Filename);
-      {$ENDIF}
-      str := '(';
-      pre := '';
-
-{$IFDEF UNIX}
- if FindFirst(lDirName+pathdelim+'*.img',faAnyFile-faSysFile,lSearchRec) = 0 then begin
-{$ELSE}
- if FindFirst(lDirName+pathdelim+'*.img',faAnyFile-faSysFile,lSearchRec) = 0 then begin
-{$ENDIF}
-    //lFilename := '';
-    repeat
-      //lNewName := lNewDir+lSearchRec.Name;
-      if  (lSearchRec.Name = '.') or (lSearchRec.Name = '..') then begin
-            //
-      end else if (lSearchRec.Name <> '') and (not DirExists(lSearchRec.Name)) then begin
-	      	str := str +pre+ ''''+extractfilename(lSearchRec.Name)+'''';
-                pre:=','
-      end;
-      //mainform.Memo1.lines.add(lSearchRec.Name);
-    until (FindNext(lSearchRec) <> 0);
-
- end;
- FindClose(lSearchRec);
- str := str + ')';
- mainform.Memo1.lines.add(str);
-end;      *)
-
-
-(*procedure BenchMarkDicom;
-var
-    lC: Integer;
-    lS: TDateTime;
-    var lDICOMdata: DICOMdata;
-         lHdrOK, lImageFormatOK: boolean;
-         lDynStr: string;var lFileName: string;
-    var lPrefs: TPrefs ;
-begin
- SetDefaultPrefs (lPrefs);
-lS := Now;
-lFilename := '/Users/rorden/philips/T1_IM_0007';
-for lC := 1 to 100 do
-    read_dicom_data(true,false,false,false,false,false,false, lDICOMdata, lHdrOK, lImageFormatOK, lDynStr, lFileName, lPrefs);
-Showmessage('Milliseconds elapsed '+  FormatDateTime('z', Now-lS) );
-end; *)
-
-procedure TMainForm.About1Click(Sender: TObject);
-//var value: int64;
-begin
-//fx(VBversion('MR B13 4VB13A')); exit;
-//NII2Mat;exit;
- //BenchMarkDicom;
-{$IFNDEF FPC}
-  if (ssCtrl in KeyDataToShiftState(vk_Shift))  then begin
-    Mask;
-    exit;
-  end;
-  if (ssShift in KeyDataToShiftState(vk_Shift))  then begin
-    MaskVBM;
-    exit;
-  end;
-{$ENDIF}
-     //force32;
-    //showmessage(ExtractFileDirWithPathDelim('c:\pas'));
-
-    //testpermissions;
-    Showmessage(kVers+ kCR+'Fallback ini file: '+ changefileext(paramstr(0),'.ini'));
-end;
-
-procedure TMainForm.Preferences1Click(Sender: TObject);
-var
-   lPrefs: TPrefs;
-begin
-     PrefsForm.ReadPrefs(lPrefs);
-     PrefsForm.Showmodal;
-     if (PrefsForm.ModalResult = mrCancel) then
-        PrefsForm.WritePrefs(lPrefs);
-end;
-
-(*procedure ShowDICOM (var lPrefs: TPrefs);
-var
-lDICOMdata: DICOMdata;
-lHdrOK,lImgOK: boolean;
-lDynStr,lFilename: string;
-
-begin
-     lFilename := 'c:\i185386.MRDC.94';
-     read_dicom_data(true,true{not verbose},true,true,true,true,false, lDICOMdata, lHdrOK, lImgOK, lDynStr,lFileName,lPrefs );
-     msgX(lDynStr);
-end;*)
-procedure TMainForm.FormShow(Sender: TObject);
-var
-   lPrefs: TPrefs;
-   lIniName: string;
-begin
-    MsgX(kVers);
-
-    SetDefaultPrefs(lPrefs);
-    lIniName := IniName;//changefileext(paramstr(0),'.ini');
-    //showmessage(changefileext(paramstr(0),'.ini'));
-    (*lReadPrefs := true;
-    if (ssShift in KeyDataToShiftState(vk_Shift))  then
-    	case MessageDlg('Shift key down during launch: do you want to reset the default preferences?', mtConfirmation,
-				[mbYes, mbNo], 0) of	{ produce the message dialog box }
-				mrYes: lReadPrefs := false;
-        end; //case *)
-    if not ResetDefaults {lReadPrefs} then begin
-    {$IFNDEF UNIX}
-     if (ParamCount > 0) then
-        ProcessParamStrs
-     else if fileexists (lIniName) then
-          IniFile(True,lIniName, lPrefs)
-     else
-         IniFile(True,changefileext(paramstr(0),'.ini'), lPrefs); //this allows an administrator to create default startup
-         //IniFile(True,lIniName, lPrefs);
-     {$ELSE}
-     if fileexists (lIniName) then
-          IniFile(True,lIniName, lPrefs)
-     else
-         IniFile(True,changefileext(paramstr(0),'.ini'), lPrefs); //this allows an administrator to create default startup
-     {$ENDIF}
-   end; //lReadPrefs
-    CheckPrefs(lPrefs,True);
-     PrefsForm.WritePrefs(lPrefs);
-     NIfTIForm.TypeCombo.ItemIndex := TypeCombo.ItemIndex;
-    UntestedMenu.visible := lPrefs.UntestedFeatures;
-     //ConvertDCM2NII('c:\b17\b17\b17.IMA',lPrefs);
-end;
-
-
-
-procedure TMainForm.TypeComboChange(Sender: TObject);
-begin
-     NIfTIForm.TypeCombo.ItemIndex := TypeCombo.ItemIndex;
-end;
-
-procedure TMainForm.AnonymizeDICOM1Click(Sender: TObject);
-var
-   sTitle,lDirName: string;
-   lPrefs: TPrefs;
-begin
-  CheckPrefs(lPrefs,False);
-  lPrefs.AnonymizeSourceDICOM := true;
-  sTitle:='Choose a folder with DICOM images';
-    lDirName := BrowseDialog(sTitle);
-    ConvertDCM2NII(lDirName,lPrefs);
-end;
-
-function TMainForm.OpenDialogExecute (lCaption: string;lAllowMultiSelect,lForceMultiSelect: boolean; lFilter: string): boolean;//; lAllowMultiSelect: boolean): boolean;
-var
-   lNumberofFiles: integer;
-begin
-	OpenHdrDlg.Filter := lFilter;//kAnaHdrFilter;//lFilter;
-	OpenHdrDlg.FilterIndex := 1;
-	OpenHdrDlg.Title := lCaption;
-	if lAllowMultiSelect then
-		OpenHdrDlg.Options := [ofAllowMultiSelect,ofFileMustExist]
-	else
-		OpenHdrDlg.Options := [ofFileMustExist];
-	result := OpenHdrDlg.Execute;
-	if not result then exit;
-	if lForceMultiSelect then begin
-		lNumberofFiles:= OpenHdrDlg.Files.Count;
-		if  lNumberofFiles < 2 then begin
-			Showmessage('Error: This function is designed to overlay MULTIPLE images. You selected less than two images.');
-			result := false;
-		end;
-	end;
-end;
-
-procedure TMainForm.SavePrefs;
-var
-   lPrefs: TPrefs;
-   lIniName: string;
-begin
-    lIniName := IniName;//changefileext(paramstr(0),'.ini');
-    CheckPrefs(lPrefs,False);
-    if lPrefs.WritePrefsOnQuit then
-       IniFile(False,lIniName, lPrefs);
-end;
-
-procedure TMainForm.FormClose(Sender: TObject; var vAction: TCloseAction);
-begin
-  SavePrefs;
-end;
-
-
-procedure TMainForm.FormDropFiles(Sender: TObject;
-  const FileNames: array of String);
-var
-   lI,lN: integer;
-  lPrefs: TPrefs;
-  //lDone: boolean;
-  lStrings: TStrings;//lFilename: string;
-begin
-     //lDone := false;
-     CheckPrefs(lPrefs,False);
-     lN := length(FileNames);
-     if lN < 1 then
-        exit;
-      lStrings := TStringList.Create;
-      for lI := 0 to (lN-1) do
-         lStrings.add(Filenames[lI]);
-     ProcessFilenames(lStrings,lPrefs);
-    lStrings.Free;
-
-end;
-
-procedure TMainForm.HalveMenu1Click(Sender: TObject);
-var
-   lPrefs: TPrefs;
-   lI: integer;
-begin
-     PrefsForm.ReadPrefs(lPrefs);
-     if not MainForm.OpenDialogExecute('Select image(s) you wish to LR flip',true,false,kImgFilter) then
-        exit;
-     if MainForm.OpenHdrDlg.Files.count < 1 then exit;
-     for lI := 0 to (MainForm.OpenHdrDlg.Files.count-1) do
-         ShrinkNII(MainForm.OpenHdrDlg.Files[lI], lPrefs);
-end;
-
-procedure TMainForm.ModifyNIfTI1Click(Sender: TObject);
-var
-   lPrefs: TPrefs;
-begin
- if not OpenDialogExecute('Select NIfTI images you wish to modify)',true,false,kImgFilter) then
-    exit;
- CheckPrefs(lPrefs,False);
- ProcessNIfTI(OpenHdrDlg.Files,lPrefs);
-end; //ModifyNIfTI1Click
-
-procedure TMainForm.NIfTI3D4D1Click(Sender: TObject);
-var lStrings: TStringList;
-   lPrefs: TPrefs;
-begin
- if not OpenDialogExecute('Select the 3D NIfTI images you wish to stack)',true,false,kImgFilter) then
-    exit;
- lStrings := TStringList.Create;
- lStrings.addstrings(OpenHdrDlg.Files);
- CheckPrefs(lPrefs,False);
- Stack3Dto4D(lStrings, False, lPrefs);
- lStrings.Free;
-end;
-
-procedure TMainForm.ResliceNIfTI1Click(Sender: TObject);
-var
-   lDestName,lSourceName,lTargetName: string;
-   lPos: integer;
-   lPrefs: TPrefs;
-begin
-         CheckPrefs(lPrefs,False);
-     Memo1.lines.clear;
-     refresh;
-     MsgX(kVers);
-     MsgX('This function reslices source images to match the dimensions of a target image.');
-     MsgX(' Images are assumed to be coregistered.');
-     MsgX(' The resulting images will have the orientation, voxel size and bounding box of the target image.');
-     MsgX(' Resliced images will be given the prefix ''r''.');
-     MsgX(' This function uses trilinear interpolation - there may be some loss of precision.');
-     if not OpenDialogExecute('Select target image',true,false,kImgFilter) then
-        exit;
-     lTargetName := OpenHdrDlg.Filename;
-     if not OpenDialogExecute('Select images you wish to reslice to match target)',true,false,kImgFilter) then
-        exit;
-     for lPos := 1 to OpenHdrDlg.Files.Count do begin
-         lSourceName := OpenHdrDlg.Files[lPos-1];
-         lDestName := ChangeFilePrefix (lSourceName,'r');
-         MsgX('Reslicing '+lSourceName +' to match dimensions of '+lTargetname+' resliced image = '+lDestName);
-         Reslice2Targ (lSourceName,lTargetName,lDestName, lPrefs );
-
-     end;
-
-end;
-
-
-procedure DelRecursiveFolderSearch (lFolderName: string; lMaxDepth, lDepth: integer);
-var
- lNewDir,lNewName,lFilename,lExt: String;
- lSearchRec: TSearchRec;
-begin
- lNewDir := lFolderName+PathDelim;
-{$IFDEF UNIX}
- if FindFirst(lNewDir+'*',faAnyFile-faSysFile,lSearchRec) = 0 then begin
-{$ELSE}
- if FindFirst(lNewDir+'*.*',faAnyFile-faSysFile,lSearchRec) = 0 then begin
-{$ENDIF}
-    lFilename := '';
-    repeat
-      lNewName := lNewDir+lSearchRec.Name;
-      if  (lSearchRec.Name <> '.') and (lSearchRec.Name <> '..') then begin
-            if DirExists(lNewName) then begin
-               if lDepth < lMaxDepth then begin
-                  DelRecursiveFolderSearch(lNewName,lMaxDepth,lDepth+1);
-               end;
-               //exit;//4/4/2008
-            end else
-                lFilename := lNewname;
-      end;
-      if (lFilename <> '') and (not DirExists(lNewName)) then begin
-	      	lExt := UpCaseExt(lFilename);
-                if (lExt <> '.DCM') then begin
-                   msgx('del '+lFilename);
-                   DeleteFile(lFilename);
-                end;
-      end;
-    until (FindNext(lSearchRec) <> 0);
-
- end;
- FindClose(lSearchRec);
-end;
-
-
-procedure TMainForm.Deletenondcm1Click(Sender: TObject);
-var
-   sTitle,lDirName: string;
-begin
-  Showmessage('Warning: this command will delete all files that do not have the extension .dcm') ;
-  sTitle:='Choose a folder with DICOM images';
-    lDirName := BrowseDialog(sTitle);
-    DelRecursiveFolderSearch(lDirName,32,1);
-end;
-
-procedure TMainForm.MirrorXdimension1Click(Sender: TObject);
-//UntestedFeatures
-var
-   lPrefs: TPrefs;
-   lI: integer;
-begin
-     PrefsForm.ReadPrefs(lPrefs);
-     if not MainForm.OpenDialogExecute('Select image(s) you wish to LR flip',true,false,kImgFilter) then
-        exit;
-     if MainForm.OpenHdrDlg.Files.count < 1 then exit;
-     for lI := 0 to (MainForm.OpenHdrDlg.Files.count-1) do
-         LRFlip(MainForm.OpenHdrDlg.Files[lI], lPrefs);
-end;
-
-procedure TMainForm.SumTPM1Click(Sender: TObject);
-var
-   lPrefs: TPrefs;
-   lI: integer;
-begin
-     PrefsForm.ReadPrefs(lPrefs);
-     if not OpenDialogExecute('Select TPM to sum)',true,false,kAnyFilter) then
-          exit;
-     for lI := 1 to 5 do
-         SumTPM(OpenHdrDlg.Filename,ChangeFilePrefix (OpenHdrDlg.Filename,'sum'+inttostr(lI)) ,lPrefs,lI);
-end;
-
-
-procedure TMainForm.ExtractDICOMdims1Click(Sender: TObject);
-var
-   sTitle,lDirName: string;
-   lPrefs: TPrefs;
-begin
-        CheckPrefs(lPrefs,False);
-        lPrefs.DebugMode2 := true;
-        {$IFNDEF FPC}
-        sTitle:='Choose a folder with DICOM images';
-      lDirName := BrowseDialog(sTitle);
-      {$ELSE}
-      if not OpenDialogExecute('Select DICOM images you wish to inspect)',true,false,kAnyFilter) then
-         exit;
-      lDirName := extractfiledir( OpenHdrDlg.Filename);
-      {$ENDIF}
-      Memo1.lines.Clear;
-      ConvertDCM2NII(lDirName,lPrefs);
-end;
-
-procedure TMainForm.ExtractDICOMhdr1Click(Sender: TObject);
-var
-   lnVol,lVol: integer;
-   lHdrName: string;
-begin
- if not OpenDialogExecute('Select the 3D NIfTI images to inspect)',true,false,kAnyFilter) then
-    exit;                                
- lnVol := OpenHdrDlg.Files.count;
-   Memo1.lines.clear;
-   for lVol := 1 to lnVol do
-      ShowHeader (OpenHdrDlg.Files[lVol-1]);
-end;
-
-procedure TMainForm.ExtractNIfTIhdrs1Click(Sender: TObject);
-var
-          lStrings: TStringList;
-begin
- if not OpenDialogExecute('Select the 3D NIfTI images to inspect)',true,false,kImgFilter) then
-    exit;
- Memo1.lines.clear;
- lStrings := TStringList.Create;
- lStrings.addstrings(OpenHdrDlg.Files);
- ExtractNIFTIHdrs(lStrings);
- lStrings.Free;
-end;
-
-{$IFDEF UNIX}
-initialization
-  {$I gui.lrs}
-{$ELSE} //not unix: windows
-initialization
-{$IFDEF FPC}
-  {$I gui.lrs}
- {$ENDIF}
-  OleInitialize(nil);
-
-finalization
-  OleUninitialize
-{$ENDIF}
-end.
-
-
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/guii.lrs b/dcm2nii_prePARRECDTI/guii.lrs
deleted file mode 100755
index 9d2eb5f..0000000
--- a/dcm2nii_prePARRECDTI/guii.lrs
+++ /dev/null
@@ -1,36 +0,0 @@
-{ This is an automatically generated lazarus resource file }
-
-LazarusResources.Add('TMainForm','FORMDATA',[
-  'TPF0'#9'TMainForm'#8'MainForm'#4'Left'#3'#'#1#6'Height'#3','#1#3'Top'#3#149#0
-  +#5'Width'#3#144#1#18'HorzScrollBar.Page'#3#143#1#18'VertScrollBar.Page'#3#24
-  +#1#13'ActiveControl'#7#5'Memo1'#7'Caption'#6#7'dcm2nii'#4'Menu'#7#9'MainMenu'
-  +'1'#6'OnShow'#7#8'FormShow'#0#8'TToolBar'#8'ToolBar1'#6'Height'#2#26#5'Width'
-  +#3#144#1#7'Caption'#6#8'ToolBar1'#11'EdgeBorders'#11#0#8'TabOrder'#2#0#0#6'T'
-  +'Label'#6'Label1'#4'Left'#2#1#6'Height'#2#14#5'Width'#2'O'#9'Alignment'#7#8
-  +'taCenter'#7'Caption'#6#15'Output Format: '#5'Color'#7#6'clNone'#11'ParentCo'
-  +'lor'#8#0#0#9'TComboBox'#9'TypeCombo'#4'Left'#2'P'#6'Height'#2#22#5'Width'#2
-  +'d'#16'AutoCompleteText'#11#22'cbactEndOfLineComplete'#20'cbactSearchAscendi'
-  +'ng'#0#13'Items.Strings'#1#6#24'SPM2 (3D Anlyze hdr/img)'#6#23'SPM5 (3D NIfT'
-  +'I hdr/img)'#6#16'4D NIfTI hdr/img'#6#18'FSL (4D NIfTI nii)'#6#29'Compressed'
-  +' FSL (4D NIfTI nii)'#0#9'MaxLength'#2#0#5'Style'#7#14'csDropDownList'#8'Tab'
-  +'Order'#2#0#0#0#0#5'TMemo'#5'Memo1'#6'Height'#3#255#0#3'Top'#2#26#5'Width'#3
-  +#144#1#5'Align'#7#8'alClient'#13'Lines.Strings'#1#6#0#0#8'TabOrder'#2#1#0#0#9
-  +'TMainMenu'#9'MainMenu1'#4'left'#2'G'#3'top'#2'<'#0#9'TMenuItem'#8'FileMenu'
-  +#7'Caption'#6#4'File'#7'OnClick'#7#13'FileMenuClick'#0#9'TMenuItem'#12'Modif'
-  +'yNifti1'#7'Caption'#6#12'Modify NIfTI'#7'OnClick'#7#17'ModifyNifti1Click'#0
-  +#0#9'TMenuItem'#9'MenuItem7'#7'Caption'#6#14'DICOM to NIfTI'#7'OnClick'#7#15
-  +'dcm2niiBtnClick'#0#0#9'TMenuItem'#15'AnonymizeDICOM1'#7'Caption'#6#15'Anony'
-  +'mize DICOM'#7'OnClick'#7#20'AnonymizeDICOM1Click'#0#0#9'TMenuItem'#5'Exit1'
-  +#7'Caption'#6#4'Exit'#7'OnClick'#7#10'Exit1Click'#0#0#0#9'TMenuItem'#9'MenuI'
-  +'tem5'#7'Caption'#6#8'EditMenu'#0#9'TMenuItem'#9'MenuItem6'#7'Caption'#6#4'C'
-  +'opy'#0#0#0#9'TMenuItem'#9'MenuItem2'#7'Caption'#6#4'Edit'#7'OnClick'#7#14'M'
-  +'enuItem2Click'#0#9'TMenuItem'#5'Copy1'#7'Caption'#6#4'Copy'#8'ShortCut'#3'C'
-  +'@'#7'OnClick'#7#10'Copy1Click'#0#0#0#9'TMenuItem'#9'MenuItem1'#7'Caption'#6
-  +#4'Help'#7'OnClick'#7#14'MenuItem1Click'#0#9'TMenuItem'#9'MenuItem3'#7'Capti'
-  +'on'#6#11'Preferences'#7'OnClick'#7#17'Preferences1Click'#0#0#9'TMenuItem'#9
-  +'MenuItem4'#7'Caption'#6#5'About'#7'OnClick'#7#11'About1Click'#0#0#0#0#22'TS'
-  +'electDirectoryDialog'#9'DirSelect'#5'Title'#6#16'Select Directory'#11'Filte'
-  +'rIndex'#2#0#4'left'#2'G'#3'top'#2'`'#0#0#11'TOpenDialog'#10'OpenHdrDlg'#5'T'
-  +'itle'#6#18'Open existing file'#11'FilterIndex'#2#0#4'left'#2'H'#3'top'#3#128
-  +#0#0#0#0
-]);
diff --git a/dcm2nii_prePARRECDTI/lsjpeg.pas b/dcm2nii_prePARRECDTI/lsjpeg.pas
deleted file mode 100755
index 30dc1bb..0000000
--- a/dcm2nii_prePARRECDTI/lsjpeg.pas
+++ /dev/null
@@ -1,777 +0,0 @@
-unit lsjpeg;
-{*$DEFINE Stream}
-//rev13: changes by CR and JGS
-//rev19: uses Lookup table for decoding Huffman table: this doubles the speed
-//rev26: fixed memory leak: FreeMem(lRawRA)
-interface
-{$IFDEF FPC} {$mode delphi}{$H+} {$ENDIF}
-
-uses
-dialogsx,
-  sysutils,define_types,classes;
-type
-    HufRA = record
-           HufSz,HufCode,HufVal: Integer;
-    end;
-{$IFDEF Stream}
-  procedure DecodeJPEG(var lStream: TMemoryStream; var lOutSmallRA: SmallIntP0; var lImgRAz: ByteP0;lOutputSz,lCptPosition,lCptSize: integer; lVerbose: boolean);
-{$ELSE}
-  procedure DecodeJPEG(var infp: file; var lOutSmallRA: SmallIntP0; var lImgRAz: ByteP0;lOutputSz,lCptPosition,lCptSize: integer; lVerbose: boolean);
-{$ENDIF}
-implementation
-
-{$IFDEF Stream}
-  procedure DecodeJPEG(var lStream: TMemoryStream; var lOutSmallRA: SmallIntP0; var lImgRAz: ByteP0;lOutputSz,lCptPosition,lCptSize: integer; lVerbose: boolean);
-{$ELSE}
-procedure DecodeJPEG(var infp: file; var lOutSmallRA: SmallIntP0; var lImgRAz: ByteP0;lOutputSz,lCptPosition,lCptSize: integer; lVerbose: boolean);
-{$ENDIF}
-const
-     kmaxFrames = 4;
-label
-     666 {EOF}, 123 {Freemem};
-  var
-    lRawRA: bytep;
-    lImgRA: WordP;
-    lHufVal,lAbba,lOffset,lLineStart,lPredicted,lPredictedG,lPredictedB,lRestartSegmentSz,
-    lSz,k,Code,Si,lIncX,lIncY,lInc,lPredA,lPredB,lPredC,lCurrentBitPos,btS1,btS2, btMarkerType,
-    DHTnLi,DHTtcth,SOFprecision,SOSpttrans, SOFnf,SOFarrayPos,SOSns,SOSarrayPos,SOSss,SOSse,SOSahal:integer;//byte;
-    lHufTable,lnHufTables,{lDecode,}lImgStart,lRawSz,lRawPos,lItems,SOFydim, SOFxdim: integer;
-    lMaxHufSi,lMaxHufVal: array [1..kmaxFrames] of integer;
-    DHTLiRA,DHTstartRA: array [1..kmaxFrames,0..31] of integer;//byte;
-    lBitMask: array [1..17] of integer;
-    lSSSSszRA: array [1..kMaxFrames,0..17] of byte;
-    lLookUpRA: array [1..kMaxFrames,0..255] of byte; //lists all possible SSSS with <= 8bits
-    lHufRA: array [1..kMaxFrames,0..31] of HufRA;
-    lFrameCount,lSegmentLength,lSegmentEnd,lI: integer;
-    lImgTypeC3,lHdrOK: boolean;
-function ReadBit: integer; //Read the next single bit
-begin
-     result := (lRawRA[lRawPos] shr (7-lCurrentBitPos)) and 1;
-     lCurrentBitPos := lCurrentBitPos + 1;
-     if (lCurrentBitPos = 8) then begin
-        lRawPos := 1+lRawPos;
-        lCurrentBitPos := 0;
-     end;
-end; //nested proc ReadBit
-
-(*
-START Disabled Procedures
-// These functions are not used: these routines have been inlined (following VTune profiling)
-// but they are useful utilities if you want to explore Huffman Tables
-function ReadBits2_9 ( lNum: integer): integer; //lNum: bits to read, not to exceed 9
-//wo Advance: does not increment the Byte/Bit position. Use AdvanceBitPos to do this
-begin
-     result := lRawRA[lRawPos];
-     result := result shl 8 + lRawRA[lRawPos+1];
-     //result := result shl 8 + lRawRA[lRawPos+2];
-     result := (result shr (16-lCurrentBitPos-lNum)) and lBitMask[lNum]; //lCurrentBitPos is incremented from 1, so -1
-     lCurrentBitPos := lCurrentBitPos + lNum;
-     if (lCurrentBitPos > 7) then begin
-        lRawPos := lRawPos+(lCurrentBitPos shr 3{div 8});
-        lCurrentBitPos := (lCurrentBitPos and 7{mod 8});
-     end;
-end;
-procedure RetractBitPos(lNum: integer);
-begin
-  lCurrentBitPos := lCurrentBitPos - lNum;
-  while (lCurrentBitPos < 0) do begin
-    lRawPos := lRawPos - 1;
-    lCurrentBitPos := lCurrentBitPos + 8;
-  end;
-end;
-procedure AdvanceBitPos(lNum: integer);
-//Advances Bit/Byte counters
-begin
-     lCurrentBitPos := lCurrentBitPos + lNum;
-     if (lCurrentBitPos > 7) then begin
-        lRawPos := lRawPos+(lCurrentBitPos shr 3{div 8});
-        lCurrentBitPos := (lCurrentBitPos and 7{mod 8});
-     end;
-end;
-END Disabled Procedures*)
-
-function ReadBits ( lNum: integer): integer; //lNum: bits to read, not to exceed 16
-begin
-     result := lRawRA[lRawPos];
-     result := result shl 8 + lRawRA[lRawPos+1];
-     result := result shl 8 + lRawRA[lRawPos+2];
-     result := (result shr (24-lCurrentBitPos-lNum)) and lBitMask[lNum]; //lCurrentBitPos is incremented from 1, so -1
-     lCurrentBitPos := lCurrentBitPos + lNum;
-     if (lCurrentBitPos > 7) then begin
-        lRawPos := lRawPos+(lCurrentBitPos shr 3{div 8});
-        lCurrentBitPos := (lCurrentBitPos and 7{mod 8});
-     end;
-end; //nested proc ReadBits
-
-function DecodePixelDifference( lFrame: integer): integer;//Red/Green/Blue each a separate 'Frame': can have unique huffman tables
-var
-   lByte,lHufValSSSS,lInput,lInputbits,lDiff,lI: integer;
-begin
-  // read one byte from the stream, without modifying the pointer
-  lByte := (lRawRA[lRawPos] shl lCurrentBitPos) + (lRawRA[lRawPos+1] shr (8-lCurrentBitPos));
-  lByte := lByte and 255;
-  lHufValSSSS := lLookUpRA[lFrame,lByte];
-  //lLookUpRA: array [1..kMaxFrames,0..255] of byte; //lists all possible SSSS with <= 8bits
-  if lHufValSSSS < 255 then begin
-     lCurrentBitPos := lSSSSszRA[lFrame,lHufValSSSS] + lCurrentBitPos;
-     lRawPos := lRawPos + (lCurrentBitpos shr 3);
-     lCurrentBitpos := lCurrentBitpos and 7;
-     //AdvanceBitPos(lSSSSszRA[lFrame,lSSSS]), but inlined;
-  end else begin //full SSSS is not in the first 8-bits
-   //if (lByte < 0) or (lByte > 255) then showmessage('yikes: this is impossible');
-   lInput := lByte;
-   lInputBits := 8;
-   inc(lRawPos); // forward 8 bits = precisely 1 byte
-   repeat
-      Inc(lInputBits);
-      lInput := lInput shl 1 + ReadBit;
-      if DHTLiRA[lFrame,lInputBits] <> 0 then begin //if any entires with this length
-         for lI := DHTstartRA[lFrame,lInputBits] to (DHTstartRA[lFrame,lInputBits]+DHTLiRA[lFrame,lInputBits]-1) do begin
-            if (lInput = lHufRA[lFrame,lI].HufCode) then
-             lHufValSSSS := lHufRA[lFrame,lI].HufVal;
-         end; //check each code
-      end; //if any entires with this length
-      if (lInputBits >= lMaxHufSi[lFrame]) and (lHufValSSSS > 254) then begin//exhausted options CR: added rev13
-         lHufValSSSS := lMaxHufVal[lFrame]; 
-      end;
-   until (lHufValSSSS < 255){found};
-  end; //answer in first 8 bits
-  //The HufVal is referred to as the SSSS in the Codec, so it is called 'lHufValSSSS'
-  case lHufValSSSS of
-          0: result:= 0;
-          1: if ReadBit = 0 then result := -1 else result := 1;
-          (*BELOW only a tiny bit faster to separate 2..15 into 2..9 and 10..15, requires extra procedure and more
-          2..9: begin //see 10..15 for explanation
-                     lDiff := ReadBits2_9(lHufValSSSS);
-                     if (lDiff > (lBitMask[lHufValSSSS-1])) then  //add
-                        result := lDiff
-                     else //negation
-                          result := lDiff - lBitMask[lHufValSSSS];
-                end; //2..9 *)
-          2..15: begin
-          //Osiris includes extra bits after SSSS=16...a violation of the standard See "TABLE H.2 - Difference categories for lossless Huffman coding" of the codec ITU-T81
-          //According to the Codec H.1.2.2 "No extra bits are appended after SSSS = 16 is encoded."
-          //To patch for Osiris Change case from 2..15 to 2..16
-          //  This will work for Osiris images, but will break non-Osiris images
-              lDiff := ReadBits(lHufValSSSS);
-              if (lDiff > (lBitMask[lHufValSSSS-1])) then  //add
-                  result := lDiff
-                  // this is slightly unintuitive: the positive bit is identical to the offset shown in TABLE H.2, a slower but more intuitive way to do this is:
-                  //result := (lDiff and lBitMask[lHufVal-1]) + (1 shl (lHufval-1));
-                  //where you clip off the sign bit and then SHL appropriately
-              else //negation
-                 result := lDiff - lBitMask[lHufValSSSS];
-                 //NEXT to lines are a bit more intuitive:
-                 {lDiff := lBitMask[lHufVal-1]- lDiff;
-                 result := -(lDiff + (1 shl (lHufval-1)));}//negation
-          end; //10..15
-          else {16, not osiris}
-               result := 32768;
-  end; //case HuffVal
-end; //nested proc DecodePixelDifference
-
-procedure ReadByte(var lByte: integer);
-begin
-     inc(lRawPos);
-     lByte := lRawRA[lRawPos];
-end;   //nested proc ReadByte
-
-function ReadWord: word;
-var
-   lbtL1, lbtL2: byte;
-begin
-     inc(lRawPos);
-     lbtL1 := lRawRA[lRawPos];
-     inc(lRawPos);
-     lbtL2 := lRawRA[lRawPos];
-     result := (256 * lbtL1 + lbtL2)
-end; //nested proc ReadWord
-//NEXT: main procedure
-  begin
-    lAbba := 4;
-    lnHufTables := 0;
-    lRawSz := lCptSize;
-    lRawPos := 0;
-    lRestartSegmentSz := 0;
-    lImgTypeC3 := false;
-    SOFxdim:= 1;
-    if lRawSz < 32 then goto 666;
-    for lFrameCount := 1 to kMaxFrames do
-      for lInc := 1 to 16 do
-        DHTstartRA[lFrameCount,lInc] := 0;
-    SOFydim := 1;
-    SOSpttrans := 0;
-    lHdrOK := false;
-    SOFnf := 0;
-    SOSns := 0;
-    GetMem( lRawRA, lRawSz);
-{$IFDEF Stream}
-    lStream.Seek(lCptPosition, soFromBeginning);
-    lStream.readBuffer(lRawRA^, lRawSz);
-{$ELSE}
-    Seek(infp,lCptPosition);
-    BlockRead(infp, lRawRA^, lRawSz);
-{$ENDIF}
-    ReadByte(btS1);
-    ReadByte(btS1);
-    repeat
-      repeat
-            if lRawPos <= lRawSz then ReadByte(btS1);
-            if btS1 <> $FF then begin
-               goto 666;
-            end;
-            if lRawPos <= lRawSz then  ReadByte( btMarkerType);
-            case btMarkerType of //only process segments with length fields
-                 $0,$1,$D0..$D7,$FF: btMarkerType := 0; //0&FF = fillers, $1=TEM,$D0..D7=resync
-            end;
-      until (lRawPos >= lRawSz) or (btMarkerType <> 0);
-      lSegmentLength := ReadWord;
-      lSegmentEnd := lRawPos+(lSegmentLength - 2);
-      if lSegmentEnd > lRawSz then goto 666;
-      if (btMarkerType = $C3)  then
-         lImgTypeC3 := true;
-      if lverbose then msg( {result+}inttohex(btMarkerType,2){':'+inttostr( lSegmentLength )+'@'+inttostr(positon)+' '});
-      case btMarkerType of
-           $0: ; //filler - ignore
-           $C0..$C3,$C5..$CB,$CD..$CF: begin //read SOF FrameHeader
-             ReadByte(SOFprecision);
-             SOFydim := ReadWord;
-             SOFxdim:= ReadWord;
-             ReadByte(SOFnf);
-             if lverbose then msg('[precision:'+inttostr(SOFprecision)+' X*Y:'+inttostr(SOFxdim)+'*'+inttostr(SOFydim)+'nFrames:'+inttostr(SOFnf)+'] ');
-             if (not lImgTypeC3) or ((SOFnf <> 1) and (SOFnf <> 3)) then begin
-                 msg('Unable to extract this file format.');
-             end;
-             SOFarrayPos := lRawPos;
-             lRawPos := (lSegmentEnd);
-           end; //SOF FrameHeader
-           $C4: begin //DHT Huffman
-              if lverbose then msg( 'HuffmanLength'+inttostr(lSegmentLength)+':');
-            //if SOFnf <1 then SOFnf := 1; //we may not know SOFnf yet!
-            lFrameCount := 1;
-            repeat
-             ReadByte( DHTtcth);
-             //showmessage(inttostr(lFrameCount)+'@'+inttostr(DHTtcth and 15)+'x'+inttostr(DHTtcth ));
-             DHTnLi := 0;
-             for lInc := 1 to 16 do begin
-                 ReadByte(DHTliRA[lFrameCount,lInc]);
-                 DHTnLi := DHTnLi +  DHTliRA[lFrameCount,lInc];
-                 if DHTliRA[lFrameCount,lInc] <> 0 then lMaxHufSi[lFrameCount] := lInc;
-                 //showmessage(inttostr(DHTliRA[lFrameCount,lInc])+'@'+inttostr(lMaxHufSi));
-             end;
-             if DHTnLi > 17 then begin
-                msg('Huffman table corrupted.');
-                goto 666;
-             end;
-             lIncY := 0; //frequency
-
-             for lInc := 0 to 31 do begin
-               lHufRA[lFrameCount, lInc].HufVal := -1;
-               lHufRA[lFrameCount, lInc].HufSz := -1;
-               lHufRA[lFrameCount, lInc].HufCode := -1;
-             end;
-
-             for lInc := 1 to 16 do begin //set the huffman size values
-                 if DHTliRA[lFrameCount,lInc]> 0 then begin
-                     DHTstartRA[lFrameCount,lInc] := lIncY+1;
-                     for lIncX := 1 to DHTliRA[lFrameCount,lInc] do begin
-                         inc(lIncY);
-                         ReadByte(btS1);
-                         lHufRA[lFrameCount,lIncY].HufVal := btS1;
-                         lMaxHufVal[lFrameCount] := btS1;
-                         if (btS1 >= 0) and (btS1 <= 16) then
-                           lHufRA[lFrameCount,lIncY].HufSz := lInc
-                         else begin
-                            msg('Huffman size array corrupted.');
-                            goto 666;
-                         end; {}
-                     end;
-                 end; //Length of size lInc > 0
-             end;
-             //showmessage('Max bits:'+inttostr(lMaxHufSi)+' SSSS:'+inttostr(lMaxHufVal));
-             K := 1;
-             Code := 0;
-             Si := lHufRA[lFrameCount,K].HufSz;//HuffSizeRA[1];
-             repeat
-                   while (Si = lHufRA[lFrameCount,K].HufSz) do begin
-                         lHufRA[lFrameCount,K].HufCode := Code;
-                         //showmessage('bits: '+inttostr(Si)+' NthEntry:'+inttostr(K)+' Code:'+inttostr(Code));
-                         Code := Code + 1;
-                         Inc(K);
-                   end;
-                   if K <= DHTnLi then begin
-                      while lHufRA[lFrameCount,K].HufSz > Si do begin
-                            Code := Code Shl 1;
-                            Si := Si + 1;
-                      end; //while Si
-                   end; //K <= 17
-             until K > DHTnLi;// JGS added rev13
-             inc(lFrameCount);
-            until (lSegmentEnd-lRawPos) < 18;
-            lnHufTables := lFrameCount - 1;
-            //showmessage(inttostr(lnHufTables));
-            lRawPos := (lSegmentEnd);
-           end; //$C4: DHT Huffman
-            $DD: begin  //Define Restart
-               lRestartSegmentSz := Readword;
-               lRawPos := (lSegmentEnd);
-           end;
-           $DA: begin //read SOS Scan Header
-             if SOSns > 0 then goto 666; //multiple SOS!
-             ReadByte(SOSns);
-             //if Ns = 1 then NOT interleaved, else interleaved: see B.2.3
-             SOSarrayPos := lRawPos;
-             if SOSns > 0 then begin
-                 for lInc := 1 to SOSns do begin
-                     ReadByte( btS1); //component identifier 1=Y,2=Cb,3=Cr,4=I,5=Q
-                     ReadByte(btS2); //horizontal and vertical sampling factors
-                 end;
-             end;
-             ReadByte(SOSss); //predictor selection B.3
-             ReadByte( SOSse);
-             ReadByte( SOSahal); //lower 4bits= pointtransform
-             SOSpttrans := SOSahal and 16;
-             if lverbose then
-                msg('[Predictor: '+inttostr(SOSss)+' PointTransform:'+inttostr(SOSahal)+'] ');
-             lRawPos := (lSegmentEnd);
-           end; //$DA SOS - Scan Header
-           else begin //skip marker segment;
-                lRawPos := (lSegmentEnd);
-           end;
-      end; //case markertype
-    until (lRawPos >= lRawSz) or (btMarkerType = $DA); {hexDA=Start of scan}
-    lHdrOK := true; //errors goto label 666, so are NOT OK
-    lImgStart := lRawPos;
-666:
-    if not lHdrOK then begin
-       msg('Unable to read this file - is this really a JPEG image?');
-       goto 123;
-    end;
-    if (not lImgTypeC3) then
-      goto 123; //lossless compressed huffman tables
-    //NEXT: unpad data - delete byte that follows $FF
-    lINc := lRawPos;
-    lIncX := lRawPos;
-    repeat
-          lRawRA[lIncX] := lRawRA[lInc];
-          if lRawRA[lInc] = 255 then begin
-             if (lRawRA[lInc+1] = $00) then
-                 lInc := lInc+1
-             else begin
-                 //showmessage(inttostr(lRawRA[lInc+1]));
-                 if (lRawRA[lInc+1] = $D9) then //end of image
-                    lIncX := -666; //end of padding
-             end;
-          end;
-          inc(lInc);
-          inc(lIncX);
-    until lIncX < 0;
-    //End: Data unpadding
-    //NEXT: Create Huffman LookupTable.
-    //We will compute all possible outcomes for an 8-bit value, while less intuitive than
-    //reading Huffman 1 bit at a time, it doubles the decompression speed
-    lBitMask[1]:= 1;
-    lBitMask[2]:= 3;
-    lBitMask[3]:= 7;
-    lBitMask[4]:= 15;
-    lBitMask[5]:= 31;
-    lBitMask[6]:= 63;
-    lBitMask[7]:= 127;
-    lBitMask[8]:= 255;
-    lBitMask[9]:= 511;
-    lBitMask[10]:= 1023;
-    lBitMask[11]:= 2047;
-    lBitMask[12]:= 4095;
-    lBitMask[13]:= 8191;
-    lBitMask[14]:= 16383;
-    lBitMask[15]:= 32767;
-    lBitMask[16]:= 65535;
-    lBitMask[17]:= 131071; //ONLY required for Osiris corrupted images, see DecodePixelDifference for details
-    //NEXT: some RGB images use only a single Huffman table for all 3 colour planes. In this case, replicate the correct values
-    if (lnHufTables < SOFnf) then begin //use single Hufman table for each frame
-       //showmessage('generating tables'+inttostr(SOFnf));
-       if lnHufTables < 1 then begin
-           msg('Lossless JPEG decoding error: no Huffman tables.');
-           goto 123;
-       end;
-       for lFrameCount := 2 to SOFnf do begin
-           for lInc := 1 to 16 do
-               DHTstartRA[lFrameCount,lInc] := DHTstartRA[1,lInc];
-           for lInc := 0 to 31 do begin
-               lHufRA[lFrameCount,lInc].HufCode := lHufRA[1,lInc].HufCode;
-               lHufRA[lFrameCount,lInc].HufVal := lHufRA[1,lInc].HufVal;
-               lHufRA[lFrameCount,lInc].HufSz := lHufRA[1,lInc].HufSz;
-               DHTliRA[lFrameCount,lInc] := DHTliRA[1,lInc];
-           end; //for each table entry
-       end; //for each frame                                           xx
-    end;// if lnHufTables < SOFnf
-    for lFrameCount := 1 to  kMaxFrames do
-      for lInc := 0 to 17 do
-          lSSSSszRA[lFrameCount,lInc] := 123; //Impossible value for SSSS, suggests 8-bits can not describe answer
-    for lFrameCount := 1 to  kMaxFrames do
-      for lInc := 0 to 255 do
-          lLookUpRA[lFrameCount,lInc] := 255; //Impossible value for SSSS, suggests 8-bits can not describe answer
-    //NEXT fill lookuptable
-    for lFrameCount := 1 to  SOFnf do begin
-      lIncY := 0;
-      for lSz := 1 to 8 do begin //set the huffman lookup table for keys with lengths <=8
-        if DHTliRA[lFrameCount,lSz]> 0 then begin
-           for lIncX := 1 to DHTliRA[lFrameCount,lSz] do begin
-                         inc(lIncY);
-                         lHufVal := lHufRA[lFrameCount,lIncY].HufVal; //SSSS
-                         {if (lHufVal < 0) or (lHufVal > 17) then begin
-                             showmessage('Unknown SSSS =' +inttostr(lHufVal));
-                             lHufVal := 16;
-                         end; }
-                         lSSSSszRA[lFrameCount,lHufVal] := lSz;
-                         k := (lHufRA[lFrameCount,lIncY].HufCode shl (8-lSz )) and 255; //K= most sig bits for hufman table
-                         if lSz < 8 then begin //fill in all possible bits that exceed the huffman table
-                              lInc := lBitMask[8-lSz];
-                              for lCurrentBitPos := 0 to lInc do begin
-                                 lLookUpRA[lFrameCount,k+lCurrentBitPos] := lHufVal;
-                              end;
-                         end else
-                             lLookUpRA[lFrameCount,k] := lHufVal; //SSSS
-
-                         {Showmessage('Frame ' + inttostr(lFrameCount) + ' SSSS= '+inttostr(lHufRA[lFrameCount,lIncY].HufVal)+
-                            '  Size= '+inttostr(lHufRA[1,lIncY].HufSz)+
-                            '  Code= '+inttostr(lHufRA[1,lIncY].HufCode)+
-                            '  SHL Code= '+inttostr(k)+
-                            '  EmptyBits= '+inttostr(lInc)); {}
-           end; //Set SSSS
-        end; //Length of size lInc > 0
-      end; //for lInc := 1 to 8
-    end; //For each frame, e.g. once each for Red/Green/Blue
-    //Next: uncompress data: different loops for different predictors
-    SOFxdim:= SOFnf*SOFxdim;
-    lItems :=  SOFxdim*SOFydim;
-    //if lVerbose then showmessage('precision'+inttostr(SOFprecision));
-    //for timing, multiple decoding loops lRawAbba := lRawPos;for lLoopsAbba := 1 to 100 do begin lRawPos := lRawAbba;
-       //if (lRestartSegmentSz > 0) and ((SOFPrecision<> 8) or (SOSss = 7)) then //add restart support if we ever find any samples to test
-       //   showmessage('This image uses restart markers. Please contact the author. Predictor:Precision '+inttostr(SOSss)+':'+inttostr(SOFPrecision));
-       inc(lRawPos);//abbax
-       lCurrentBitPos := 0; //read in a new byte
-       //lCurrentBitPos := 1; //read in a new byte
-       lItems :=  SOFxdim*SOFydim;
-       lPredicted :=  1 shl (SOFPrecision-1-SOSpttrans);
-       lInc := 0;
-       if (SOFPrecision<> 8) then begin //start - 16 bit data
-          lImgRA := @lOutSmallRA[0];{set to 1 for MRIcro, else 0}
-          FillChar(lImgRA^,lItems*sizeof(word), 0); //zero array
-          lPredB:= 0;
-          lPredC := 0;
-          case SOSss of //predictors 1,2,3 examine single previous pixel, here we set the relative location
-                   2: lPredA:= SOFxDim-1; //Rb directly above
-                   3: lPredA:= SOFxDim; //Rc UpperLeft:above and to the left
-                   4,5: begin
-                      lPredA := 0;
-                      lPredB := SOFxDim-1; //Rb directly above
-                      lPredC:= SOFxDim; //Rc UpperLeft:above and to the left
-                   end;
-                   6: begin
-                      lPredB := 0;
-                      lPredA := SOFxDim-1; //Rb directly above
-                      lPredC:= SOFxDim; //Rc UpperLeft:above and to the left
-                   end;
-                   else lPredA := 0; //Ra: directly to left
-          end; //case SOSss: predictor offset
-          for lIncX := 1 to SOFxdim do begin
-              inc(lInc); //writenext voxel
-              if lInc > 1 then lPredicted := lImgRA[lInc-1];
-              lImgRA[lInc] := lPredicted+DecodePixelDifference(1);
-          end; //first line: use prev voxel prediction;
-         if lRestartSegmentSz = 0 then begin
-             for lIncY := 2 to SOFyDim do begin
-                 inc(lInc); //write next voxel
-                 lPredicted := lImgRA[lInc-SOFxdim];
-                 lImgRA[lInc] := lPredicted+DecodePixelDifference(1);
-                 if SOSss = 4 then begin
-                    for lIncX := 2 to SOFxdim do begin
-                         lPredicted := lImgRA[lInc-lPredA]+lImgRA[lInc-lPredB]-lImgRA[lInc-lPredC];
-                         inc(lInc); //writenext voxel
-                         lImgRA[lInc] := lPredicted+DecodePixelDifference(1);
-                    end; //for lIncX
-                 end else if (SOSss = 5) or (SOSss = 6) then begin
-                    for lIncX := 2 to SOFxdim do begin
-                         lPredicted := lImgRA[lInc-lPredA]+ ((lImgRA[lInc-lPredB]-lImgRA[lInc-lPredC]) shr 1);
-                         inc(lInc); //writenext voxel
-                         lImgRA[lInc] := lPredicted+DecodePixelDifference(1);
-                    end; //for lIncX
-                 end else if SOSss = 7 then begin
-                    for lIncX := 2 to SOFxdim do begin
-                        inc(lInc); //writenext voxel
-                        lPredicted := (lImgRA[lInc-1]+lImgRA[lInc-SOFxdim]) shr 1;
-                        lImgRA[lInc] := lPredicted+DecodePixelDifference(1);
-                    end; //for lIncX
-                 end else begin //SOSss 1,2,3 read single values
-                     for lIncX := 2 to SOFxdim do begin
-                         lPredicted := lImgRA[lInc-lPredA];
-                         inc(lInc); //writenext voxel
-                         lImgRA[lInc] := lPredicted+DecodePixelDifference(1);
-                     end; //for lIncX
-                 end;  //SOSss predictor
-
-
-             end; //for lIncY
-         end {RestartSegmentSz = 0} else begin {restartsegment}
-             if SOSss > 3 then
-                msg('Unusual 16-bit lossless JPEG with restart segments. Please contact the author:'+inttostr(SOSss));
-             lSegmentEnd := lRestartSegmentSz;
-             repeat
-                    if lSegmentEnd > lItems then lSegmentEnd := lItems;
-                    lLineStart := (((lInc div SOFxDim)+1)* SOFxDim){-1};
-                    if lInc > (SOFxDim+1) then
-                       lPredicted :=  1 shl (SOFPrecision-1-SOSpttrans)
-                    else
-                        lPredicted := lImgRA[lInc-SOFxdim];
-
-                    for lInc := lInc to (lSegmentEnd-1) do begin
-                      lImgRA[lInc] := lPredicted+DecodePixelDifference(1);
-                      if lInc+1 = lLineStart then begin//newline
-                        lPredicted := lImgRA[lInc+1-SOFxdim];
-                        lLineStart := lLineStart + SOFxDim;
-                      end else
-                        lPredicted := lImgRA[lInc-lPredA];
-                    end;
-                    if (lSegmentEnd+1) < lItems then begin
-                        dec(lRawPos);
-                        repeat
-                              while (lRawRA[lRawPos] <> 255) do
-                                    inc(lRawPos);
-                              inc(lRawPos);
-                        until (lRawRA[lRawPos] >= $D0) and (lRawRA[lRawPos] <= $D7);
-                        lCurrentBitPos := 0; //read in a new byte
-                        inc(lRawPos);//abbax
-                    end;
-                    lSegmentEnd := lSegmentEnd + lRestartSegmentSz;
-              until (lRestartSegmentSz < 1) or ((lSegmentEnd-2) > lItems);
-             end; //restartsegments
-       end else if SOFnf = 3 then begin //>8bit data; 8 bit follows
-              //LOSSLESS JPEG: 7 possible predictors - we will handle all of them
-              lPredB:= 0;
-              lPredC := 0;
-              case SOSss of //predictors 1,2,3 examine single previous pixel, here we set the relative location
-                   2: lPredA:= SOFxDim-3; //Rb directly above
-                   3: lPredA:= SOFxDim; //Rc UpperLeft:above and to the left
-                   5: begin
-                      lPredA := 0;
-                      lPredB := SOFxDim-3; //Rb directly above
-                      lPredC:= SOFxDim; //Rc UpperLeft:above and to the left
-                   end;
-                   6: begin
-                      lPredB := 0;
-                      lPredA := SOFxDim-3; //Rb directly above
-                      lPredC:= SOFxDim; //Rc UpperLeft:above and to the left
-                   end;
-                   else lPredA := 0; //Ra: directly to left
-              end; //case SOSss: predictor offset
-              lPredictedG := lPredicted;
-              lPredictedB := lPredicted;
-              lOffset := 0;
-              lInc := lOffset;
-              for lIncX := 1 to (SOFxdim div 3) do begin //write first line
-                  //DecodePixelDifference=RED
-                  lImgRAz[lInc] := lPredicted+DecodePixelDifference(1);
-                  lPredicted := lImgRAz[lInc];
-                  inc(lInc); //writenext voxel
-                  //DecodePixelDifference=GREEN
-                  lImgRAz[lInc] := lPredictedG+DecodePixelDifference(2);
-                  lPredictedG := lImgRAz[lInc];
-                  inc(lInc); //writenext voxel
-                  //DecodePixelDifference=BLUE
-                  lImgRAz[lInc] := lPredictedB+DecodePixelDifference(3);
-                  lPredictedB := lImgRAz[lInc];
-                  inc(lInc); //writenext voxel
-              end; //first line: use prev voxel prediction;
-              if lRestartSegmentSz = 0 then lSegmentEnd := lItems
-              else lSegmentEnd := lRestartSegmentSz;
-              repeat
-                    if lSegmentEnd > lItems then lSegmentEnd := lItems;
-                    lLineStart := (((lInc div SOFxDim)+1)* SOFxDim)+lOffset{-1};
-                     if lInc > (SOFxDim+1) then begin
-                       lPredicted :=  1 shl (SOFPrecision-1-SOSpttrans);
-                       lPredictedG :=  lPredicted;
-                       lPredictedB :=  lPredicted;
-                    end else begin
-                        lPredicted := lImgRAz[lInc-SOFxdim+lOffset];
-                        lPredictedG := lImgRAz[1+lInc-SOFxdim+lOffset];
-                        lPredictedB := lImgRAz[2+lInc-SOFxdim+lOffset];
-                    end;
-               if SOSss = 4 then  begin //predictor = 4
-                    //this is a 24-bit image, so for 512-pixel wid image, SOFxdim will be (3*512=) 1536
-                    while lInc < (lSegmentEnd-1) do begin
-                      lImgRAz[lInc] := lPredicted+DecodePixelDifference(1); //RED
-                      inc(lInc);
-                      lImgRAz[lInc] := lPredictedG+DecodePixelDifference(2); //GREEN
-                      inc(lInc);
-                      lImgRAz[lInc] := lPredictedB+DecodePixelDifference(3); //BLUE
-                      inc(lInc);
-                      if lInc = lLineStart then begin//newline
-                         lPredicted := lImgRAz[lInc-SOFxdim];
-                         lPredictedG := lImgRAz[lInc-SOFxdim+1];
-                         lPredictedB := lImgRAz[lInc-SOFxdim+2];
-                         lLineStart := lLineStart + (SOFxDim);
-                      end else begin
-                        lPredicted :=  lImgRAz[lInc-3]+lImgRAz[lInc-3-(SOFxDim-3)]-lImgRAz[lInc-3-SOFxDim];
-                        lPredictedG := lImgRAz[lInc-2]+lImgRAz[lInc-2-(SOFxDim-3)]-lImgRAz[lInc-2-SOFxDim];
-                        lPredictedB := lImgRAz[lInc-1]+lImgRAz[lInc-1-(SOFxDim-3)]-lImgRAz[lInc-1-SOFxDim];
-                      end;
-                    end;
-               //xxx
-               end else if (SOSss = 5) or (SOSss = 6) then  begin //predictor = 5 or 6
-                    //this is a 24-bit image, so for 512-pixel wid image, SOFxdim will be (3*512=) 1536
-                    while lInc < (lSegmentEnd-1) do begin
-                      lImgRAz[lInc] := lPredicted+DecodePixelDifference(1); //RED
-                      inc(lInc);
-                      lImgRAz[lInc] := lPredictedG+DecodePixelDifference(2); //GREEN
-                      inc(lInc);
-                      lImgRAz[lInc] := lPredictedB+DecodePixelDifference(3); //BLUE
-                      inc(lInc);
-                      if lInc = lLineStart then begin//newline
-                         lPredicted := lImgRAz[lInc-SOFxdim];
-                         lPredictedG := lImgRAz[lInc-SOFxdim+1];
-                         lPredictedB := lImgRAz[lInc-SOFxdim+2];
-                         lLineStart := lLineStart + (SOFxDim);
-                      end else begin
-                        lPredicted :=  lImgRAz[lInc-3-lPredA]+((lImgRAz[lInc-3-lPredB]-lImgRAz[lInc-3-lPredC])shr 1);
-                        lPredictedG := lImgRAz[lInc-2-lPredA]+((lImgRAz[lInc-2-lPredB]-lImgRAz[lInc-2-lPredC])shr 1);
-                        lPredictedB := lImgRAz[lInc-1-lPredA]+((lImgRAz[lInc-1-lPredB]-lImgRAz[lInc-1-lPredC])shr 1);
-                      end;
-                    end;
-               end else if SOSss = 7 then  begin //predictor = 7
-                    while lInc < (lSegmentEnd-1) do begin
-                      lImgRAz[lInc] := lPredicted+DecodePixelDifference(1); //RED
-                      inc(lInc);
-                      lImgRAz[lInc] := lPredictedG+DecodePixelDifference(2); //GREEN
-                      inc(lInc);
-                      lImgRAz[lInc] := lPredictedB+DecodePixelDifference(3); //BLUE
-                      inc(lInc);
-                      if lInc = lLineStart then begin//newline
-                         lPredicted := lImgRAz[lInc-SOFxdim];
-                         lPredictedG := lImgRAz[lInc-SOFxdim+1];
-                         lPredictedB := lImgRAz[lInc-SOFxdim+2];
-                         lLineStart := lLineStart + (SOFxDim);
-                      end else begin
-                        lPredicted :=  (lImgRAz[lInc-3]+lImgRAz[lInc-3-(SOFxDim-3)])shr 1;
-                        lPredictedG := (lImgRAz[lInc-2]+lImgRAz[lInc-2-(SOFxDim-3)]) shr 1;
-                        lPredictedB := (lImgRAz[lInc-1]+lImgRAz[lInc-1-(SOFxDim-3)]) shr 1;
-                      end;
-                    end;
-
-               end else begin //predictor in range 1,2,3
-                    //this is a 24-bit image, so for 512-pixel wid image, SOFxdim will be (3*512=) 1536
-                    while lInc < (lSegmentEnd-1) do begin
-                      lImgRAz[lInc] := lPredicted+DecodePixelDifference(1); //RED
-                      inc(lInc);
-                      lImgRAz[lInc] := lPredictedG+DecodePixelDifference(2); //GREEN
-                      inc(lInc);
-                      lImgRAz[lInc] := lPredictedB+DecodePixelDifference(3); //BLUE
-                      inc(lInc);
-                      if lInc = lLineStart then begin//newline
-                         lPredicted := lImgRAz[lInc-SOFxdim];
-                         lPredictedG := lImgRAz[lInc-SOFxdim+1];
-                         lPredictedB := lImgRAz[lInc-SOFxdim+2];
-                         lLineStart := lLineStart + (SOFxDim);
-                      end else begin
-                        lPredicted := lImgRAz[lInc-3-lPredA];
-                        lPredictedG := lImgRAz[lInc-2-lPredA];
-                        lPredictedB := lImgRAz[lInc-1-lPredA];
-                      end;
-                    end;
-               end; //predictor <> 7
-              until (lRestartSegmentSz < 1) or ((lSegmentEnd-2) > lItems);
-          // end; //8<>15data type
-       end else begin //previously 12/16/24bit data, 8 bit follows
-              lInc := 0;
-              //LOSSLESS JPEG: 7 possible predictors - we will handle all of them
-              lPredB:= 0;
-              lPredC := 0;
-              case SOSss of //predictors 1,2,3 examine single previous pixel, here we set the relative location
-                   2: lPredA:= SOFxDim-1; //Rb directly above
-                   3: lPredA:= SOFxDim; //Rc UpperLeft:above and to the left
-                   5: begin
-                      lPredA := 0;
-                      lPredB := SOFxDim-1; //Rb directly above
-                      lPredC:= SOFxDim; //Rc UpperLeft:above and to the left
-                   end;
-                   6: begin
-                      lPredB := 0;
-                      lPredA := SOFxDim-1; //Rb directly above
-                      lPredC:= SOFxDim; //Rc UpperLeft:above and to the left
-                   end;
-                   else lPredA := 0; //Ra: directly to left
-              end; //case SOSss: predictor offset
-              //lOffset := -1;
-              for lIncX := 1 to SOFxdim do begin //write first line
-                  lImgRAz[lInc] := lPredicted+DecodePixelDifference(1);
-                  inc(lInc); //writenext voxel
-                  lPredicted := lImgRAz[lInc-1];
-              end; //first line: use prev voxel prediction;
-              if lRestartSegmentSz = 0 then lSegmentEnd := lItems
-              else lSegmentEnd := lRestartSegmentSz;
-              repeat
-                    if lSegmentEnd > lItems then lSegmentEnd := lItems;
-                    lLineStart := (((lInc div SOFxDim)+1)* SOFxDim){-1};
-                    if lInc > (SOFxDim+1) then
-                       lPredicted :=  1 shl (SOFPrecision-1-SOSpttrans)
-                    else
-                        lPredicted := lImgRAz[lInc-SOFxdim];
-                if SOSss = 4 then begin //predictor 4 : ABOVE+LEFT-(UPPERLEFT)
-                    for lInc := lInc to (lSegmentEnd-1) do begin
-                      lImgRAz[lInc] := lPredicted+DecodePixelDifference(1);
-                      if lInc+1 = lLineStart then begin//newline
-                        lPredicted := lImgRAz[lInc+1-SOFxdim];
-                        lLineStart := lLineStart + SOFxDim;
-                      end else
-                        lPredicted := lImgRAz[lInc]+lImgRAz[lInc-(SOFxDim-1)] -lImgRAz[lInc-SOFxDim] ;
-                    end;
-
-                end else if (SOSss = 5) or (SOSss=6) then begin //predictor 5,6 : comparisons
-                    for lInc := lInc to (lSegmentEnd-1) do begin
-                      lImgRAz[lInc] := lPredicted+DecodePixelDifference(1);
-                      if lInc+1 = lLineStart then begin//newline
-                        lPredicted := lImgRAz[lInc+1-SOFxdim];
-                        lLineStart := lLineStart + SOFxDim;
-                      end else
-                        lPredicted := lImgRAz[lInc-lPredA]+((lImgRAz[lInc-lPredB]-lImgRAz[lInc-lPredC]) shr 1) ;
-                    end;
-               end else if SOSss = 7 then begin //predictor 7: average above and left
-                    for lInc := lInc to (lSegmentEnd-1) do begin
-                      lImgRAz[lInc] := lPredicted+DecodePixelDifference(1);
-                      if lInc+1 = lLineStart then begin//newline
-                        lPredicted := lImgRAz[lInc+1-SOFxdim];
-                        lLineStart := lLineStart + SOFxDim;
-                      end else
-                        lPredA := lImgRAz[lInc];
-                        lPredB:= lImgRAz[lInc-SOFxDim+1];//correct
-                        lPredicted := (lPredA+lPredB) shr 1;
-                    end;
-               end else begin //predictor <> 7 : assume SOSss=1: previous
-                    for lInc := lInc to (lSegmentEnd-1) do begin
-                      lImgRAz[lInc] := lPredicted+DecodePixelDifference(1);
-                      if lInc+1 = lLineStart then begin//newline
-                        lPredicted := lImgRAz[lInc+1-SOFxdim];
-                        lLineStart := lLineStart + SOFxDim;
-                      end else
-                        lPredicted := lImgRAz[lInc-lPredA];
-                    end;
-               end; //predictor <> 7
-                    if (lSegmentEnd+1) < lItems then begin
-                        dec(lRawPos);
-                        repeat
-                              while (lRawRA[lRawPos] <> 255) do
-                                    inc(lRawPos);
-                              inc(lRawPos);
-                        until (lRawRA[lRawPos] >= $D0) and (lRawRA[lRawPos] <= $D7);
-                        lCurrentBitPos := 0; //read in a new byte
-                        inc(lRawPos);
-                        //lCurrentBitPos := 9; //read in a new byte
-                    end;
-                    lSegmentEnd := lSegmentEnd + lRestartSegmentSz;
-              until (lRestartSegmentSz < 1) or ((lSegmentEnd-2) > lItems);
-           end; //8<>15data type
-123:
-    FreeMem( lRawRA); //release memory buffer
-end;
-
-end.
diff --git a/dcm2nii_prePARRECDTI/nifti_form.dfm b/dcm2nii_prePARRECDTI/nifti_form.dfm
deleted file mode 100755
index 1ae875c..0000000
Binary files a/dcm2nii_prePARRECDTI/nifti_form.dfm and /dev/null differ
diff --git a/dcm2nii_prePARRECDTI/nifti_form.lfm b/dcm2nii_prePARRECDTI/nifti_form.lfm
deleted file mode 100755
index b6de3d9..0000000
--- a/dcm2nii_prePARRECDTI/nifti_form.lfm
+++ /dev/null
@@ -1,226 +0,0 @@
-object NIfTIForm: TNIfTIForm
-  Left = 797
-  Height = 266
-  Top = 32
-  Width = 338
-  ActiveControl = OKBtn
-  BorderIcons = [biSystemMenu]
-  BorderStyle = bsDialog
-  Caption = 'Convert NIfTI File'
-  ClientHeight = 266
-  ClientWidth = 338
-  Constraints.MaxHeight = 266
-  Constraints.MaxWidth = 338
-  Constraints.MinHeight = 266
-  Constraints.MinWidth = 338
-  OnCreate = FormCreate
-  LCLVersion = '0.9.30.2'
-  object Label1: TLabel
-    Left = 8
-    Height = 17
-    Top = 168
-    Width = 102
-    Alignment = taCenter
-    Caption = 'Output Format: '
-    ParentColor = False
-  end
-  object Label4: TLabel
-    Left = 8
-    Height = 17
-    Top = 16
-    Width = 35
-    Alignment = taCenter
-    Caption = 'Task:'
-    ParentColor = False
-  end
-  object OKBtn: TButton
-    Left = 200
-    Height = 25
-    Top = 208
-    Width = 75
-    BorderSpacing.InnerBorder = 4
-    Caption = 'OK'
-    ModalResult = 1
-    OnClick = OKBtnClick
-    TabOrder = 0
-  end
-  object CancelBtn: TButton
-    Left = 104
-    Height = 25
-    Top = 208
-    Width = 75
-    BorderSpacing.InnerBorder = 4
-    Caption = 'Cancel'
-    ModalResult = 2
-    TabOrder = 1
-  end
-  object TypeCombo: TComboBox
-    Left = 118
-    Height = 20
-    Top = 163
-    Width = 209
-    ItemHeight = 0
-    Items.Strings = (
-      'SPM2 (3D Anlyze hdr/img)'
-      'SPM5 (3D NIfTI hdr/img)'
-      'SPM8 (3D NIfTI nii)'
-      '4D NIfTI hdr/img'
-      'FSL (4D NIfTI nii)'
-      'Compressed FSL (4D NIfTI nii)'
-      'MRIcron drawing (voi)'
-    )
-    Style = csDropDownList
-    TabOrder = 2
-  end
-  object Panel1: TPanel
-    Left = 8
-    Height = 103
-    Top = 59
-    Width = 312
-    BevelOuter = bvNone
-    ClientHeight = 103
-    ClientWidth = 312
-    TabOrder = 3
-    object Label2: TLabel
-      Left = 8
-      Height = 17
-      Top = 15
-      Width = 190
-      Caption = 'Volumes to remove from start'
-      ParentColor = False
-    end
-    object Label3: TLabel
-      Left = 7
-      Height = 17
-      Top = 55
-      Width = 185
-      Caption = 'Volumes to remove from end'
-      ParentColor = False
-    end
-    object StartEdit: TSpinEdit
-      Left = 224
-      Height = 16
-      Top = 13
-      Width = 74
-      MaxValue = 9999999
-      TabOrder = 0
-    end
-    object EndEdit: TSpinEdit
-      Left = 224
-      Height = 16
-      Top = 53
-      Width = 74
-      MaxValue = 9999999
-      TabOrder = 1
-    end
-  end
-  object Combo4D: TComboBox
-    Left = 47
-    Height = 20
-    Top = 11
-    Width = 280
-    ItemHeight = 0
-    Items.Strings = (
-      'Change format'
-      'Flip dimensions 3 and 4'
-      'Clip 1st/Last Volumes'
-      'Export as 32-bit real'
-      'Apply formula'
-      'ASL conversion'
-    )
-    OnChange = Combo4DChange
-    Style = csDropDownList
-    TabOrder = 4
-  end
-  object Combo3D: TComboBox
-    Left = 48
-    Height = 20
-    Top = 11
-    Width = 279
-    ItemHeight = 0
-    Items.Strings = (
-      'Change format'
-      'Reorient to orthogonal'
-      'Reorient and crop'
-    )
-    Style = csDropDownList
-    TabOrder = 5
-  end
-  object ASLPanel: TPanel
-    Left = 40
-    Height = 50
-    Top = 24
-    Width = 275
-    BevelOuter = bvNone
-    ClientHeight = 50
-    ClientWidth = 275
-    TabOrder = 6
-    object ASLCombo: TComboBox
-      Left = 16
-      Height = 20
-      Top = 11
-      Width = 246
-      ItemHeight = 0
-      Items.Strings = (
-        'Subtract pairs - first image tagged'
-        'Subtract pairs - first image control'
-        'Subtract Custom'
-        'Add (odd+even) BOLD'
-      )
-      Style = csDropDownList
-      TabOrder = 0
-    end
-  end
-  object FormulaPanel: TPanel
-    Left = 47
-    Height = 114
-    Top = 56
-    Width = 273
-    BevelOuter = bvNone
-    ClientHeight = 114
-    ClientWidth = 273
-    TabOrder = 7
-    object Label5: TLabel
-      Left = 31
-      Height = 17
-      Top = 17
-      Width = 33
-      Alignment = taCenter
-      Caption = 'Scale'
-      ParentColor = False
-    end
-    object Label6: TLabel
-      Left = 31
-      Height = 17
-      Top = 59
-      Width = 39
-      Alignment = taCenter
-      Caption = 'Power'
-      ParentColor = False
-    end
-    object ScaleEdit: TFloatSpinEdit
-      Left = 127
-      Height = 16
-      Top = 11
-      Width = 130
-      DecimalPlaces = 8
-      Increment = 1
-      MaxValue = 100
-      MinValue = 0
-      TabOrder = 0
-      Value = 1.2E-6
-    end
-    object PowerEdit: TFloatSpinEdit
-      Left = 127
-      Height = 16
-      Top = 56
-      Width = 130
-      DecimalPlaces = 8
-      Increment = 1
-      MaxValue = 100
-      MinValue = 0
-      TabOrder = 1
-      Value = 1.2E-6
-    end
-  end
-end
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/nifti_form.lrs b/dcm2nii_prePARRECDTI/nifti_form.lrs
deleted file mode 100755
index eb9a942..0000000
--- a/dcm2nii_prePARRECDTI/nifti_form.lrs
+++ /dev/null
@@ -1,62 +0,0 @@
-{ This is an automatically generated lazarus resource file }
-
-LazarusResources.Add('TNIfTIForm','FORMDATA',[
-  'TPF0'#10'TNIfTIForm'#9'NIfTIForm'#4'Left'#3#29#3#6'Height'#3#10#1#3'Top'#2' '
-  +#5'Width'#3'R'#1#13'ActiveControl'#7#5'OKBtn'#11'BorderIcons'#11#12'biSystem'
-  +'Menu'#0#11'BorderStyle'#7#8'bsDialog'#7'Caption'#6#18'Convert NIfTI File'#12
-  +'ClientHeight'#3#10#1#11'ClientWidth'#3'R'#1#21'Constraints.MaxHeight'#3#10#1
-  +#20'Constraints.MaxWidth'#3'R'#1#21'Constraints.MinHeight'#3#10#1#20'Constra'
-  +'ints.MinWidth'#3'R'#1#8'OnCreate'#7#10'FormCreate'#10'LCLVersion'#6#8'0.9.3'
-  +'0.2'#0#6'TLabel'#6'Label1'#4'Left'#2#8#6'Height'#2#17#3'Top'#3#168#0#5'Widt'
-  +'h'#2'f'#9'Alignment'#7#8'taCenter'#7'Caption'#6#15'Output Format: '#11'Pare'
-  +'ntColor'#8#0#0#6'TLabel'#6'Label4'#4'Left'#2#8#6'Height'#2#17#3'Top'#2#16#5
-  +'Width'#2'#'#9'Alignment'#7#8'taCenter'#7'Caption'#6#5'Task:'#11'ParentColor'
-  +#8#0#0#7'TButton'#5'OKBtn'#4'Left'#3#200#0#6'Height'#2#25#3'Top'#3#208#0#5'W'
-  +'idth'#2'K'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#2'OK'#11'ModalRes'
-  +'ult'#2#1#7'OnClick'#7#10'OKBtnClick'#8'TabOrder'#2#0#0#0#7'TButton'#9'Cance'
-  +'lBtn'#4'Left'#2'h'#6'Height'#2#25#3'Top'#3#208#0#5'Width'#2'K'#25'BorderSpa'
-  +'cing.InnerBorder'#2#4#7'Caption'#6#6'Cancel'#11'ModalResult'#2#2#8'TabOrder'
-  +#2#1#0#0#9'TComboBox'#9'TypeCombo'#4'Left'#2'v'#6'Height'#2#20#3'Top'#3#163#0
-  +#5'Width'#3#209#0#10'ItemHeight'#2#0#13'Items.Strings'#1#6#24'SPM2 (3D Anlyz'
-  +'e hdr/img)'#6#23'SPM5 (3D NIfTI hdr/img)'#6#19'SPM8 (3D NIfTI nii)'#6#16'4D'
-  +' NIfTI hdr/img'#6#18'FSL (4D NIfTI nii)'#6#29'Compressed FSL (4D NIfTI nii)'
-  +#6#21'MRIcron drawing (voi)'#0#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#2
-  +#0#0#6'TPanel'#6'Panel1'#4'Left'#2#8#6'Height'#2'g'#3'Top'#2';'#5'Width'#3'8'
-  +#1#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#2'g'#11'ClientWidth'#3'8'#1#8
-  +'TabOrder'#2#3#0#6'TLabel'#6'Label2'#4'Left'#2#8#6'Height'#2#17#3'Top'#2#15#5
-  +'Width'#3#190#0#7'Caption'#6#28'Volumes to remove from start'#11'ParentColor'
-  +#8#0#0#6'TLabel'#6'Label3'#4'Left'#2#7#6'Height'#2#17#3'Top'#2'7'#5'Width'#3
-  +#185#0#7'Caption'#6#26'Volumes to remove from end'#11'ParentColor'#8#0#0#9'T'
-  +'SpinEdit'#9'StartEdit'#4'Left'#3#224#0#6'Height'#2#16#3'Top'#2#13#5'Width'#2
-  +'J'#8'MaxValue'#4#127#150#152#0#8'TabOrder'#2#0#0#0#9'TSpinEdit'#7'EndEdit'#4
-  +'Left'#3#224#0#6'Height'#2#16#3'Top'#2'5'#5'Width'#2'J'#8'MaxValue'#4#127#150
-  +#152#0#8'TabOrder'#2#1#0#0#0#9'TComboBox'#7'Combo4D'#4'Left'#2'/'#6'Height'#2
-  +#20#3'Top'#2#11#5'Width'#3#24#1#10'ItemHeight'#2#0#13'Items.Strings'#1#6#13
-  +'Change format'#6#23'Flip dimensions 3 and 4'#6#21'Clip 1st/Last Volumes'#6
-  +#21'Export as 32-bit real'#6#13'Apply formula'#6#14'ASL conversion'#0#8'OnCh'
-  +'ange'#7#13'Combo4DChange'#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#4#0#0
-  +#9'TComboBox'#7'Combo3D'#4'Left'#2'0'#6'Height'#2#20#3'Top'#2#11#5'Width'#3
-  +#23#1#10'ItemHeight'#2#0#13'Items.Strings'#1#6#13'Change format'#6#22'Reorie'
-  +'nt to orthogonal'#6#17'Reorient and crop'#0#5'Style'#7#14'csDropDownList'#8
-  +'TabOrder'#2#5#0#0#6'TPanel'#8'ASLPanel'#4'Left'#2'('#6'Height'#2'2'#3'Top'#2
-  +#24#5'Width'#3#19#1#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#2'2'#11'Clie'
-  +'ntWidth'#3#19#1#8'TabOrder'#2#6#0#9'TComboBox'#8'ASLCombo'#4'Left'#2#16#6'H'
-  +'eight'#2#20#3'Top'#2#11#5'Width'#3#246#0#10'ItemHeight'#2#0#13'Items.String'
-  +'s'#1#6'#Subtract pairs - first image tagged'#6'$Subtract pairs - first imag'
-  +'e control'#6#15'Subtract Custom'#6#19'Add (odd+even) BOLD'#0#5'Style'#7#14
-  +'csDropDownList'#8'TabOrder'#2#0#0#0#0#6'TPanel'#12'FormulaPanel'#4'Left'#2
-  +'/'#6'Height'#2'r'#3'Top'#2'8'#5'Width'#3#17#1#10'BevelOuter'#7#6'bvNone'#12
-  +'ClientHeight'#2'r'#11'ClientWidth'#3#17#1#8'TabOrder'#2#7#0#6'TLabel'#6'Lab'
-  +'el5'#4'Left'#2#31#6'Height'#2#17#3'Top'#2#17#5'Width'#2'!'#9'Alignment'#7#8
-  +'taCenter'#7'Caption'#6#5'Scale'#11'ParentColor'#8#0#0#6'TLabel'#6'Label6'#4
-  +'Left'#2#31#6'Height'#2#17#3'Top'#2';'#5'Width'#2''''#9'Alignment'#7#8'taCen'
-  +'ter'#7'Caption'#6#5'Power'#11'ParentColor'#8#0#0#14'TFloatSpinEdit'#9'Scale'
-  +'Edit'#4'Left'#2#127#6'Height'#2#16#3'Top'#2#11#5'Width'#3#130#0#13'DecimalP'
-  +'laces'#2#8#9'Increment'#5#0#0#0#0#0#0#0#128#255'?'#8'MaxValue'#5#0#0#0#0#0#0
-  +#0#200#5'@'#8'MinValue'#5#0#0#0#0#0#0#0#0#0#0#8'TabOrder'#2#0#5'Value'#5#0
-  +#176#27'l'#160#175#15#161#235'?'#0#0#14'TFloatSpinEdit'#9'PowerEdit'#4'Left'
-  +#2#127#6'Height'#2#16#3'Top'#2'8'#5'Width'#3#130#0#13'DecimalPlaces'#2#8#9'I'
-  +'ncrement'#5#0#0#0#0#0#0#0#128#255'?'#8'MaxValue'#5#0#0#0#0#0#0#0#200#5'@'#8
-  +'MinValue'#5#0#0#0#0#0#0#0#0#0#0#8'TabOrder'#2#1#5'Value'#5#0#176#27'l'#160
-  +#175#15#161#235'?'#0#0#0#0
-]);
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/nifti_form.pas b/dcm2nii_prePARRECDTI/nifti_form.pas
deleted file mode 100755
index 8c76f10..0000000
--- a/dcm2nii_prePARRECDTI/nifti_form.pas
+++ /dev/null
@@ -1,134 +0,0 @@
-unit nifti_form;
-
-interface
-
-uses
-{$IFDEF FPC}LResources,
-{$ELSE}
-RXSpin,
-{$ENDIF}
-{$IFNDEF UNIX} Windows,{$ENDIF}
-  Buttons, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
-  StdCtrls, Spin, ExtCtrls {, Mask};
-{$IFNDEF FPC}
-type
-  TNIfTIform = class(TForm)
-    ASLCombo: TComboBox;
-    Combo4D: TComboBox;
-    Label1: TLabel;
-    OKBtn: TButton;
-    CancelBtn: TButton;
-    Combo3D: TComboBox;
-    Panel1: TPanel;
-    FormulaPanel: TPanel;
-    StartEdit: TSpinEdit;
-    EndEdit: TSpinEdit;
-    Label2: TLabel;
-    Label3: TLabel;
-    TypeCombo: TComboBox;
-    Label4: TLabel;
-    ASLPanel: TPanel;
-    Label5: TLabel;
-    ScaleEdit: TRxSpinEdit;
-    PowerEdit: TRxSpinEdit;
-    procedure Combo4DChange(Sender: TObject);
-    procedure FormCreate(Sender: TObject);
-    procedure OKBtnClick(Sender: TObject);
-  private
-{$ELSE}
-type
-  TNIfTIform = class(TForm)
-    ASLCombo: TComboBox;
-    Combo4D: TComboBox;
-    Label1: TLabel;
-    OKBtn: TButton;
-    CancelBtn: TButton;
-    Combo3D: TComboBox;
-    Panel1: TPanel;
-    FormulaPanel: TPanel;
-    StartEdit: TSpinEdit;
-    EndEdit: TSpinEdit;
-    Label2: TLabel;
-    Label3: TLabel;
-    TypeCombo: TComboBox;
-    Label4: TLabel;
-    ASLPanel: TPanel;
-    Label5: TLabel;
-    ScaleEdit: TFloatSpinEdit;
-    PowerEdit: TFloatSpinEdit;
-    procedure Combo4DChange(Sender: TObject);
-    procedure FormCreate(Sender: TObject);
-    procedure OKBtnClick(Sender: TObject);
-  private
-
-{$ENDIF}
-{Delphi...
-    ScaleEdit: TRxSpinEdit;
-    PowerEdit: TRxSpinEdit;
-Lazarus
-    ScaleEdit: TFloatSpinEdit;
-    PowerEdit: TFloatSpinEdit;
-}
-    { Private declarations }
-  public
-    { Public declarations }
-  end;
-
-var
-  NIfTIform: TNIfTIform;
-
-implementation
-
-{$IFNDEF FPC}
-{$R *.DFM}
-{$ENDIF}
-
-procedure TNIfTIform.Combo4DChange(Sender: TObject);
-var
-   lS: string;
-begin
-     lS := '';
-     If ((Combo4D.visible) and (Combo4D.ItemIndex = 6))
-       or ( (not (Combo4D.visible)) and (Combo3D.ItemIndex = 3)) then begin
-        Panel1.visible := true;
-        lS := 'Slices';
-     end else If (Combo4D.visible) and (Combo4D.ItemIndex = 2) then begin
-        Panel1.visible := true;
-        lS := 'Volumes'
-     end else
-         Panel1.visible := false;
-     if lS <> '' then begin
-         Label2.Caption := lS+' to remove from start';
-         Label3.Caption := lS+' to remove from end';
-
-     end;
-     If (Combo4D.visible) and (Combo4D.ItemIndex = 4) then
-        FormulaPanel.visible := true
-     else
-         FormulaPanel.visible := false;
-     If (Combo4D.visible) and (Combo4D.ItemIndex = 5) then
-        ASLPanel.visible := true
-     else
-         ASLPanel.visible := false;
-end;
-
-procedure TNIfTIform.FormCreate(Sender: TObject);
-begin
-   Combo3D.ItemIndex := 0;
-   Combo4D.ItemIndex := 0;
-   ASLCombo.ItemIndex := 0;
-end;
-
-procedure TNIfTIform.OKBtnClick(Sender: TObject);
-begin
-
-end;
-
-{$IFDEF FPC}
-
-
-initialization
-  {$I nifti_form.lrs}
- {$ENDIF}
-
-end.
diff --git a/dcm2nii_prePARRECDTI/niftiutil.pas b/dcm2nii_prePARRECDTI/niftiutil.pas
deleted file mode 100755
index c785669..0000000
--- a/dcm2nii_prePARRECDTI/niftiutil.pas
+++ /dev/null
@@ -1,1905 +0,0 @@
-unit niftiutil;
- {$Include ..\common\isgui.inc}
-interface
-uses
-{$IFDEF FPC}
- {$IFDEF GUI}FileUtil, {$ENDIF} //FileUtil requires LResources that requires extra environment variables with tools like matlab
-gzio2, process,  //FileUtil,
-{$ELSE}
-gziod, ShellAPI,Windows,Forms,
-{$ENDIF}
-  SysUtils,Classes,define_types,filename,dicomtypes,prefs;
-{$H+}
-const
-	kNIIImgOffset = 352; //header is 348 bytes, but 352 is divisible by 8...
-function MaskImgs(lC1template, lC1source: string; lPrefs: TPrefs ; lThresh: single): string;
-function MaskImg(ltemplate, lsource: string; lPrefs: TPrefs; lThresh: single ): string;
-function Binarize(lC1Name: string; lPrefs: TPrefs ): string;
-function SameHdrDim (lAHdr,lBHdr: TNIFTIhdr; lCheck4D, lCheckDataType: boolean): boolean;
-procedure NIFTIhdr_ClearHdr (var lHdr: TNIFTIhdr ); //put sensible default values into header
-procedure DICOM2AnzHdr (var lBHdr: TNIFTIhdr; lAnonymize: boolean; var lFilename: string; var lDICOMdata: DicomData);
-procedure CustomFilename (var lFilename: string);
-function SumTPM (lSrcName,lDestName: string; lPrefs: TPrefs; lTissueTypes2Average: integer):string;
-//function SameHdrDim (lAHdr,lBHdr: TNIFTIhdr): boolean;
-function SaveHdr (var lFilename: ANSIstring; var lInHdr: TNIFTIhdr ; lSwap,lSPM2:boolean): boolean;
-function NIFTIhdr_LoadHdr (var lFilename: string; var lHdr: TNIFTIHdr; var lByteSwap: boolean): boolean;
-procedure NIFTIhdr_SlicesToCoord (var lHdr: TNIFTIhdr; lXslice,lYslice,lZslice: integer; var lXmm,lYmm,lZmm: single);
-function ChangeNIfTISubformat(lHdrName: string; var lHdr: TNIFTIhdr; lPrefs: TPrefs): boolean;
-procedure SaveHdrRAM (var lFilename: ANSIstring; var lInHdr,lOutHdr: TNIFTIhdr ; lSwap,lSPM2:boolean);
-function SaveNIfTICore (var lOutImgName: string; var lvBuffer: bytep;  lVolOffset: integer; var lInHdr: TNIFTIhdr; var lPrefs: TPrefs; var lByteSwap: boolean): string;
-function SaveNIfTICoreCrop (var lOutImgName: string; var lvBuffer: bytep;  lVolOffset,lStartClip,lEndClip: integer; var lInHdr: TNIFTIhdr; var lPrefs: TPrefs; var lByteSwap: boolean): string;
-function NIFTIhdr_LoadImg (var lFilename: string; var lHdr: TNIFTIHdr; var lImgBuffer: byteP; var lImgOffset: integer; var lByteSwap: boolean): boolean;
-procedure NIFTIhdr_UnswapImg (var lHdr: TNIFTIHdr; var lImgBuffer: byteP; var lImgOffset: integer; var lByteSwap: boolean); //ensures image data is in native space
-function NIFTIhdr_LoadImgRaw (LoadHdr: boolean; var lFilename: string; var lHdr: TNIFTIHdr; var lImgBuffer: byteP; var lImgOffset: integer; var lByteSwap: boolean): boolean;
-function NII_force32 (lSrcName,lDestName: string; lPrefs: TPrefs):string;
-function Rescale_4Dtissuemaps (lSrcName,lDestName: string; lPrefs: TPrefs; lMakeSym: boolean):string;
-function Merge4DFiles (lLowSliceName,lHighSliceName,lDestName: string; lNumberofLowSlicesToCopy: integer; lPrefs: TPrefs):string;
-function Insert3Din4D (l3DSliceName,l4DSliceName,lDestName: string; lVol2Copy: integer; lPrefs: TPrefs):string;
-function MaskImages(lMaskName: string; lFiles: TStrings; lPrefs: TPrefs; lVol: integer; lSaveThresh: boolean): string;
-function NonspatialDimensionsNII (lA: TNIFTIhdr): integer;
-function runPigz(var lImgName : string; processes: integer): boolean;
-function CheckHugeUint16(lFilename: string; UINT16toFLOAT32: boolean): boolean;
-implementation
-uses dialogsx;
-
-
-
-function AddFileNum(lVol,lnVol: integer; var lInName: string): string;
-var
-lNameWOExt,lExt: string;
-begin
-    ExtractFileParts (lInName, lNameWOExt,lExt);
-    result := lNameWOExt+'_'+PadStr(lVol,length(inttostr(lnVol))) +lExt;
-end;
-
-procedure NIFTIhdr_UnswapImg (var lHdr: TNIFTIHdr; var lImgBuffer: byteP; var lImgOffset: integer; var lByteSwap: boolean); //ensures image data is in native space
-//returns data in native endian
-//sets 'ByteSwap' flag to false. E.G. a big-endian image will be saved as little-endian on little endian machines
-var
-   lInc,lImgSamples : integer;
-   //2f : SingleP;
-   l32i : LongIntP;
-   l16i : SmallIntP;
-begin
-     if not lByteSwap then exit;
-     case lHdr.datatype of
-          kDT_UNSIGNED_CHAR : begin
-              lByteSwap := false; //single byte data - no need to byte swap...
-              exit;
-            end;
-	  kDT_SIGNED_SHORT,kDT_SIGNED_INT,kDT_FLOAT: ;//supported format
-         else begin
-             Msg('niftiutil UnSwapImg error: datatype not supported.');
-             exit;
-         end;
-     end; //case
-     lImgSamples := lHdr.Dim[1] *lHdr.Dim[2]*lHdr.Dim[3]*NonspatialDimensionsNII(lHdr);
-     if lImgSamples < 1 then
-        exit;
-     case lHdr.datatype of
-	  kDT_SIGNED_SHORT: begin
-             l16i := SmallIntP(@lImgBuffer^[lImgOffset+1]);
-             for lInc := 1 to lImgSamples do
-                 l16i^[lInc] := Swap(l16i^[lInc]);
-          end; //l16i
-          kDT_SIGNED_INT,kDT_FLOAT: begin
-             //note: for the purposes of byte swapping, floats and long ints are the same
-             l32i := LongIntP(@lImgBuffer^[lImgOffset+1]);
-             for lInc := 1 to lImgSamples do
-                 Swap4(l32i^[lInc]);
-          end;//32i
-          (*kDT_FLOAT: begin
-             l32f := SingleP(@lImgBuffer^[lImgOffset+1]);
-             for lInc := 1 to lImgSamples do
-                 pswap4r(l32f^[lInc]);  //faster as procedure than function see www.optimalcode.com
-          end; //32f*)
-     end; //case
-     lByteSwap := false;
-end;
-
-procedure NIFTIhdr_SwapBytes (var lAHdr: TNIFTIhdr ); //Swap Byte order for the Analyze type
-var
-   lInc: integer;
-begin
-    with lAHdr do begin
-         swap4(hdrsz);
-         swap4(extents);
-         session_error := swap(session_error);
-         for lInc := 0 to 7 do
-             dim[lInc] := swap(dim[lInc]);
-         Xswap4r(intent_p1);
-         Xswap4r(intent_p2);
-         Xswap4r(intent_p3);
-         intent_code:= swap(intent_code);
-         datatype:= swap(datatype);
-         bitpix := swap(bitpix);
-         slice_start:= swap(slice_start);
-         for lInc := 0 to 7 do
-             Xswap4r(pixdim[linc]);
-         Xswap4r(vox_offset);
-         Xswap4r(scl_slope);
-         Xswap4r(scl_inter);
-         slice_end := swap(slice_end);
-         Xswap4r(cal_max);
-         Xswap4r(cal_min);
-         Xswap4r(slice_duration);
-         Xswap4r(toffset);
-         swap4(glmax);
-         swap4(glmin);
-         qform_code := swap(qform_code);
-         sform_code:= swap(sform_code);
-         Xswap4r(quatern_b);
-         Xswap4r(quatern_c);
-         Xswap4r(quatern_d);
-         Xswap4r(qoffset_x);
-         Xswap4r(qoffset_y);
-         Xswap4r(qoffset_z);
-         for lInc := 0 to 3 do begin
-             Xswap4r(srow_x[lInc]);
-             Xswap4r(srow_y[lInc]);
-             Xswap4r(srow_z[lInc]);
-         end;
-    end; //with NIFTIhdr
-end; //proc NIFTIhdr_Swa
-
-(*procedure TestUINT16 (lval: integer);
-//this procedure demonstrates that words and smallints are identical for values 0..32767, so no need to swap if values are in this range
-var
-l16ui : WordP;
-l16i: SmallIntP;
-begin
-  getmem(l16ui,1*sizeof(word));
-  l16ui^[1] := lval;
-  l16i := SmallIntP(@l16ui^[1]);
-  fx(l16i^[1],l16ui^[1]);
-  freemem(l16ui);
-end;*)
-
-
-function CheckHugeUint16(lFilename: string; UINT16toFLOAT32: boolean): boolean;
-var
-   lHdr: TNIFTIHdr;
-   lByteSwap: boolean;
-   lMax,lVol,lVox: integer;
-   lnVol,lnVox: Int64;
-   lImgBuffer: WordP;
-   lExt,lImgName: string;
-   lInF: File;
-begin
-     result := false;
-     if (GzExt(lFilename)) then begin
-        Msg('CheckHugeUint16: Unable to read GZ files ' + lFilename);
-        exit;
-     end;
-     if not NIFTIhdr_LoadHdr (lFilename, lHdr, lByteSwap) then begin
-             Msg('CheckHugeUint16: Unable to read as NifTI/Analyze ' + lFilename);
-             exit;
-     end;//load the header from disk...
-     lnVol := NonspatialDimensionsNII(lHdr);
-     lnVox := lHdr.dim[1]*lHdr.dim[2]*lHdr.dim[3];
-     result := true;
-     if (lHdr.datatype <> kDT_UINT16) or (lnVol < 1) or (lnVox < 1) or (lByteswap) then
-        exit;
-     if lByteswap then begin
-             Msg('CheckHugeUint16: Unable to read byte-swapped data (yet) ' + lFilename);
-             result := false;
-             exit;
-     end;//load the header from disk...
-
-     GetMem(lImgBuffer,lnVox * sizeof(Word));
-     lExt := UpCaseExt(lFilename);
-    if lExt ='.HDR' then
-        lImgName :=  changefileext(lFilename,'.img')
-    else
-        lImgName := lFilename;
-    AssignFile(lInF, lImgName);
-    Reset(lInF,1);
-    Seek(lInF,round(lHdr.vox_offset));
-    Filemode := 0;  //ReadOnly
-    for lVol := 1 to lnVol do begin
-        BlockRead(lInF, lImgBuffer^[1],lnVox * sizeof(Word));
-        if lVol = 1 then begin
-           lMax := lImgBuffer^[1];
-        end;
-        for lVox := 1 to lnVox do
-            if (lImgBuffer^[lVox] > lMax) then
-               lMax := lImgBuffer^[lVox];
-    end;
-    CloseFile(lInF);
-    FreeMem(lImgBuffer);
-    Filemode := 2;  //Read-Write
-    if (lMax < 32768) then begin
-       lHdr.datatype := kDT_SIGNED_SHORT;
-       AssignFile(lInF, lFileName); {WIN}
-        Reset(lInF,1) ;
-        BlockWrite(lInF,lHdr,sizeof(TNIFTIhdr) );
-        CloseFile(lInF);
-       Msg(lFilename+' losslessly converted from UINT16->INT16, maximum value is '+inttostr(lMax));
-       result := true;
-       exit;
-    end;
-    Msg('WARNING: This huge image is stored in the unusual UINT16 format. Maximum intensity of '+inttostr(lMax)
-    +'makes it impossible to save the image as the more popular INT16 format. Some tools may not be able to process this image. ' +lFilename);
-
-     result := true;
-end;
-
-procedure Uint16 (var lvBuffer: bytep;  lVolOffset: integer; var lInHdr: TNIFTIhdr;var lPrefs: TPrefs; var lByteSwap: boolean);
-//kDT_UINT16 saves data range 0..65535, but this is an atypical NIfTI format (not included in earlier Analyze format)
-// this procedure saves the data as kDT_SIGNED_SHORT 0..36767
-//   if data range is <32767 then saved unchanged, if range is >32767, saved as 15-bit (Least Significant bit clipped).
-var
-    i,lmax,lv,lnv: Int64;
-    lTempB: ByteP;
-    l16ui : WordP;
-    l32f: SingleP;
-begin
-  lnv := lInHdr.dim[1]*lInHdr.dim[2]*lInHdr.dim[3]*NonspatialDimensionsNII(lInHdr);
-  if (lInHdr.datatype <> kDT_UINT16) or (lnv < 1) then
-    exit;
-  l16ui := WordP(@lvBuffer^[lVolOffset]);
-  if lByteSwap then begin
-    lmax := swap(l16ui^[1]);
-
-    //for lv := 1 to lnv do  // fpc can not use int64 in for loop
-    lv := 1;
-    while lv <= lnv do begin
-        if swap(l16ui^[lv]) > lmax then
-           lmax := swap(l16ui^[lv]);
-	inc(lv)
-    end;
-  end else begin
-    lmax := l16ui^[1];
-    //for lv := 1 to lnv do //fpc can not use int64 in for loop
-    lv := 1;
-    while lv <= lnv do begin
-        if l16ui^[lv] > lmax then
-          lmax := l16ui^[lv];
-	inc(lv)
-    end;
-  end;  //if swapped else not swapped
-  if lmax < 32768 then begin //lossless: unsigned range <32768 (15 bits), so can be stored in signed 16bit
-    lInHdr.datatype := kDT_SIGNED_SHORT;
-    (*next lines not required, as range 0..32767 is stored identically for WORDS and SMALLINTS, see TestUINT16
-    l16i := SmallIntP(@lvBuffer^[lVolOffset]);
-    for lv := 1 to lnv do
-      l16i^[lv] := l16ui^[lv];  *)
-  end else if not lPrefs.UINT16toFLOAT32 then begin
-     Msg('Warning: unusual NIFTI format UINT16, range: '+inttostr(lMax) );
-     Msg(' If you prefer compatibility, edit your preference named UINT16toFLOAT32');
-  end else begin
-    Msg('Warning: for compatibility, converting UINT16->FLOAT32, range: '+inttostr(lMax) );
-    Msg(' If you prefer filesize over compatibility, edit your preference named UINT16toFLOAT32');
-    lInHdr.datatype := kDT_Float;
-    lInHdr.bitpix := 32;
-    lmax := lVolOffset+ (lnv*sizeof(Word));
-    GetMem(lTempB,lmax);
-    if lByteSwap then begin
-      Msg(' Swapping data to native byte order (Big vs Little Endian)');
-      //for lv := 1 to lnv do  //fpc can not use int64 in for loop
-      lv := 1;
-      while lv <= lnv do begin
-        l16ui^[lv] := swap(l16ui^[lv]);
-	inc(lv)
-      end;
-
-    end;
-    //for lv := 1 to lmax do //fpc can not use int64 in for loop
-    lv := 1;
-    while lv <= lmax do begin
-         lTempB^[lv] := lvBuffer^[lv];
-	inc(lv)
-    end;
-
-    (*if lByteSwap then begin
-      lByteSwap := false;
-      if (lVolOffset > 0) do
-        for lv := 1 to lVolOffset do
-          lTempB^[lv] := swap(lvBuffer^[lv]);
-      xx
-      for lv := 1 to lmax do
-        lTempB^[lv] := swap(lvBuffer^[lv]);
-      Msg(' Swapping data to native byte order (Big vs Little Endian)');
-    end else begin
-      for lv := 1 to lmax do
-        lTempB^[lv] := lvBuffer^[lv];
-    end;*)
-    freemem(lvBuffer);
-    GetMem(lvBuffer,lVolOffset+ (lnv*sizeof(single)));
-    //for lv := 1 to lVolOffset do //fpc can not use int64 in for loop
-    lv := 1;
-    while lv <= lVolOffset do begin
-        lvBuffer^[lv] := lTempB^[lv];
-	inc(lv)
-    end;
-
-    l16ui := WordP(@lTempB^[lVolOffset]);
-    l32f := SingleP(@lvBuffer^[lVolOffset]);
-    //for lv := 1 to lnv do //fpc can not use int64 in for loop
-    lv := 1;
-    while lv <= lnv do begin
-        l32f^[lv] :=l16ui^[lv];
-	inc(lv)
-    end;
-    Freemem(lTempB);
-  end;// if range requires conversion to 32-bit float
-end; //Uint16
-
-
-function getPigzNameWithPath: string;
-//returns path to pigz executable, e.g. '/Users/rorden/downloads/pigz-master/pigz';
-var
-    temp, exename: string;
-begin
-  {$IFDEF ENDIAN_BIG}
-  Msg('pigz not available with PowerPC computers');
-  result := '';
-  exit;
-  {$ENDIF}
-  {$IFDEF UNIX}
-          exename := 'pigz';
-          {$IFDEF GUI}
-          result := FindDefaultExecutablePath(exename);  // "which pigz"
-          if length(result) > 0 then
-             exit;
-          {$ENDIF}
-  {$ELSE}
-         exename := 'pigz.exe';
-  {$ENDIF}
-  //result := ExtractFilePath(Application.ExeName)+'pigz';
-  result := ExtractFilePath(  paramstr(0))+exename;
-  if fileexists(result) then exit;
-  {$IFDEF DARWIN}
-  temp := result;
-  result := ExtractFilePath(paramstr(0));
-  result := LeftStr(result, Pos((ExtractFileName(paramstr(0))+'.app'), result)-1)+exename;
-  if fileexists(result) then exit;
-  Msg('File compression error: pigz does not exist in you path or '+result+' or '+temp);
-  {$ELSE}
-  Msg('File compression error: pigz does not exist in you path or '+result);
-  {$ENDIF}
-  result := '';
-end;
-
-{$IFDEF FPC} //Freepascal has handy 'Process' for calling console applications
-function runPigz(var lImgName : string; processes: integer): boolean;
-// abs(processes): 1= default (as many as available, 2..n: use this many processors
-//  if processes is a NEGATIVE value, application does not wait for Pigz to complete...
-var
-   AProcess: TProcess;
-   Acmd: string;
-   AResponse: TStringList;
-   i: integer;
-begin
-  result := false;
-  Acmd := getPigzNameWithPath;  //+' -k' //<- to KEEP original
-  if length(Acmd) < 1 then exit;
-  //Acmd := Acmd +' -v -k';//verbose, keep files
-  if abs(processes) > 1 then
-     Acmd := Acmd + ' -p '+inttostr( abs(processes) );
-  Acmd := Acmd +' "'+lImgName+'"';
-  Msg('External compression: '+Acmd);
-  AProcess := TProcess.Create(nil);
-  //AProcess.Environment.Add('FSLDIR='/usr/local/fsl/);   //optional
-  AProcess.CommandLine := Acmd;
-  if (processes > 0) then //wait for pgzip to complete...
-    AProcess.Options := AProcess.Options + [poWaitOnExit, poStderrToOutPut, poUsePipes]
-  else  //do not wait for pigz
-    AProcess.Options := AProcess.Options + [poStderrToOutPut, poUsePipes];
-  AProcess.Execute;
-  if (processes > 0) then begin//wait for pgzip to complete...
-    AResponse := TStringList.Create;
-    AResponse.LoadFromStream(AProcess.Output);
-    if AResponse.Count > 0 then
-     for i := 1 to AResponse.Count do
-         Msg(' '+AResponse.Strings[i-1]);
-    AResponse.Free;
-  end;
-  AProcess.Free;
-  result := true;
-end;
-{$ELSE} //Delphi does not have 'Process' for calling console applications
-
-procedure ExecNewProcess(AppName, ACmd : String; WaitUntilDone: boolean);
-var
-  StartInfo  : TStartupInfo;
-  ProcInfo   : TProcessInformation;
-  CreateOK   : Boolean;
-begin
-  { fill with known state }
-  FillChar(StartInfo,SizeOf(TStartupInfo),#0);
-  FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
-  StartInfo.cb := SizeOf(TStartupInfo);
-  CreateOK := CreateProcess(PChar(AppName),Pchar(Acmd), nil, nil,False,
-              CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS, 
-              nil, nil, StartInfo, ProcInfo);
-  { check to see if successful }
-  if (CreateOK) and (WaitUntilDone) then
-    WaitForSingleObject(ProcInfo.hProcess, INFINITE);
-end;
-
-function runPigz(var lImgName : string; processes: integer): boolean;
-// abs(processes): 1= default (as many as available, 2..n: use this many processors
-//  if processes is a NEGATIVE value, application does not wait for Pigz to complete...
-var
-   AppName, Acmd: string;
-begin
-  result := false;
-  AppName := getPigzNameWithPath;  //+' -k' //<- to KEEP original
-  if length(AppName) < 1 then exit;
-  Acmd := '';
-  //Acmd := Acmd +' -v -k';//verbose, keep files
-  if abs(processes) > 1 then
-     Acmd := Acmd + ' -p '+inttostr( abs(processes) );
-  Acmd := Acmd +' "'+lImgName+'"';
-  Msg('External compression: '+AppName+' '+Acmd);
-  Acmd := AppName+' '+Acmd;
-  ExecNewProcess(AppName, ACmd, (processes > 0));
-  result := true;
-end;
-{$ENDIF}
-procedure BlockWriteX(var f: file; var lvBuffer: bytep; Count: Int64;var Result: Int64; lStart: Int64);
-var
-   lSaved, lBlockSize, lMaxBlockSize: Int64;
-   lResult: integer;
-begin
-  if (Count <= 2147483647) then begin
-     //BlockWrite(f, lvBuffer^[lStart], Count);
-     BlockWrite(f, lvBuffer^[lStart], Count, lResult);
-     Result := lResult;
-     exit;
-  end;
-  lMaxBlockSize := 1073741824; //  1Gb = 1073741824 bytes
-  lBlockSize := lMaxBlockSize;
-  lSaved := 0;
-  while (lSaved < Count) do begin
-        if (Count-lSaved) < lMaxBlockSize then
-           lBlockSize := Count-lSaved;
-        BlockWrite(f, lvBuffer^[lStart+lSaved], lBlockSize, lResult);
-        lSaved := lSaved + lResult;
-        if (lResult < lBlockSize) then begin
-           msg('BlockWriteX: Serious problem saving huge file - is disk space exhausted?');
-           Result := lSaved;
-           exit;
-        end;
-
-  end;
-  Result := lSaved;
-end;
-
-function SaveNIfTICore (var lOutImgName: string; var lvBuffer: bytep;  lVolOffset: integer; var lInHdr: TNIFTIhdr; var lPrefs: TPrefs; var lByteSwap: boolean): string;
-//image data should start at lVolOffset - this should be AT LEAST kNIIImgOffset (=352) bytes for creating .nii.gz files
-//important note - when converting 4D to 3D to .nii format the lvBuffer is changed :: must correct this
-var
-   lPref : TPrefs;
-   lVol, lusePigz: integer;
-   lGZip: boolean;
-   lVolStart,lVolBytes,lBytesSaved: Int64;
-   lOutF: File;
-   lNoGZName,lHdrName,lImgName: string;
-   l3dHdr,lOutHdr : TNIFTIHdr;
-   lHdrBupRA: bytep;
-
-begin
-     lNoGZName := (lOutImgName);
-     StripGZExt(lNoGZName); //we want to convert filename.nii.gz -> filename.hdr not -> filename.nii.hdr
-     StripNIIVOIExt(lNoGZName);//we want to convert filename.nii.voi to filename.hdr
-     lPref := lPrefs;
-     CorrectPrefs(lPref);
-     result := '';
-     Uint16 (lvBuffer,lVolOffset, lInHdr,lPrefs,lByteSwap);
-     if (not lPref.FourD) and (lInHdr.dim[4] > 1) then begin //4D -> 3D
-        lVolBytes := lInHdr.dim[1]*lInHdr.dim[2]*lInHdr.dim[3]*trunc(((lInHdr.bitpix)+7)/8);
-        lVolStart := lVolOffset;
-        l3dHdr := lInHdr;
-        l3dHdr.dim[4] := 1;
-        for lVol := 1 to lInHdr.dim[4] do begin
-            //1st - save header
-            lHdrName := AddFileNum(lVol,lInHdr.dim[4],lNoGZName);
-            result := SaveNIfTICore (lHdrName, lvBuffer, lVolStart, l3dHdr, lPref,lByteswap);
-            lVolStart := lVolStart + lVolBytes;
-            //SaveNiftiCore new filename, new offset
-        end; //for each vol
-        exit;
-     end; //l4Dto3D
-
-     Filemode := 2;
-     lVolBytes := lInHdr.dim[1]*lInHdr.dim[2]*lInHdr.dim[3]*lInHdr.dim[4]*trunc(((lInHdr.bitpix)+7)/8);
-
-
-     if ((kNIIImgOffset+lVolBytes)> DiskFreeEx(lNoGZName)) then begin
-		    Msg('Insufficient disk space '+
-		    lNoGZName+ kCR+' Bytes Required: '+inttostr(lVolBytes) );
-		    exit;
-     end;
-     if (lPref.SingleNIIFile) then begin
-        lVolStart := lVolOffset-kNIIImgOffset;
-        lVolBytes := lVolBytes + kNIIImgOffset;
-        if lVolStart < 1 then begin
-           Msg('SaveNIfTICore Error: '+inttostr(lVolStart));
-           exit;
-        end;
-
-        getmem(lHdrBupRA,kNIIImgOffset);
-        Move(lvBuffer^[lVolStart],lHdrBupRA^[1],kNIIImgOffset);
-        //bytes 349,350,351,352 should be set to zero
-        lVol := 0;
-        lvBuffer^[kNIIImgOffset-3+lVol] := 0;
-        lvBuffer^[kNIIImgOffset-2+lVol] := 0;
-        lvBuffer^[kNIIImgOffset-1+lVol] := 0;
-        lvBuffer^[kNIIImgOffset+lVol] := 0;
-        //next - create [potentially byte swapped] header and load into buffer
-        lImgName :=  changefileext(lNoGZName,'.nii');
-
-        SaveHdrRAM (lImgName,lInHdr,lOutHdr, lByteSwap,lPrefs.SPM2);
-
-        Move(lOutHdr,lvBuffer^[lVolStart],sizeof(lOutHdr)); //move 348 byte header in place
-
-        //finally - write buffer to disk
-        //Msg(inttostr(lPrefs.usePigz)+'   *'+inttostr(length(getPigzNameWithPath))+'*');
-        lusePigz:= lPrefs.usePigz;
-        lGZip := lPrefs.Gzip;
-        if (lVolBytes >1073741824) and (lGZip)  then begin  //  1Gb = 1073741824 bytes
-           if (length(getPigzNameWithPath) > 0) then begin
-              if (lusePigz = 0) then begin
-                 lusePigz := 1;
-                 Msg('Using pigz to create GZ: file too large for internal compressor');
-              end;
-           end else begin
-               lGZip := false;
-               Msg('Warning: File not GZipped (too large). Solution: install pigz');
-           end;
-        end;
-
-        if (lGZip) and (lusePigz <> 0) and (length(getPigzNameWithPath) > 0) then begin
-            AssignFile(lOutF, lImgName);
-            Rewrite(lOutF,1);
-            //BlockWrite(lOutF, lvBuffer^[lVolStart], lVolBytes,lBytesSaved);
-            BlockWriteX(lOutF, lvBuffer, lVolBytes,lBytesSaved,lVolStart);
-            CloseFile(lOutF);
-            runPigz(lImgName, lusePigz);
-           //DeleteFile(lImgName);
-        end else if lGZip then begin
-            if lPrefs.VOI then
-                lImgName :=  changefileext(lNoGZName,'.voi')
-            else
-                lImgName :=  changefileext(lNoGZName,'.nii.gz');
-            Msg('GZip...' + extractfilename(lImgName));
-            GZipBuffer(lImgName, @lvBuffer^[lVolStart],lVolBytes,true);
-
-
-        end else begin //not .nii.gz -> .nii
-            Msg('Saving '+lImgName);
-            AssignFile(lOutF, lImgName);
-            Rewrite(lOutF,1);
-            //BlockWrite(lOutF, lvBuffer^[lVolStart], lVolBytes);
-            BlockWriteX(lOutF, lvBuffer, lVolBytes,lBytesSaved,lVolStart);
-            CloseFile(lOutF);
-        end; //else no GZip
-        Move(lHdrBupRA^[1],lvBuffer^[lVolStart],kNIIImgOffset); //replace data overwritten by header - otherwise 4D->3D corrupts lvBuffer
-        freemem(lHdrBupRA);
-     end else begin  //not .nii -> hdr and img
-         lHdrName :=  changefileext(lNoGZName,'.hdr');
-         lImgName :=  changefileext(lNoGZName,'.img');
-        //next - create [potentially byte swapped] header and save to disk
-        if not SaveHdr (lHdrName,lInHdr, lByteSwap,lPrefs.SPM2) then
-           exit;
-        //finally - write buffer to disk
-        AssignFile(lOutF, lImgName);
-        Rewrite(lOutF,1);
-        BlockWrite(lOutF, lvBuffer^[lVolOffset], lVolBytes);
-        CloseFile(lOutF);
-     end; //else hdr+img
-
-     result := lImgName;
-end;
-
-function SaveNIfTICoreCrop (var lOutImgName: string; var lvBuffer: bytep;  lVolOffset,lStartClip,lEndClip: integer; var lInHdr: TNIFTIhdr; var lPrefs: TPrefs; var lByteSwap: boolean): string;
-var
-   lVolStart,lVolBytes: integer;
-   lClipName: string;
-   lClipHdr : TNIFTIHdr;
-begin
-     result := '';
-     if (lStartClip < 0) or (lEndClip < 0) then
-        exit; //no negative values
-     if (lStartClip <= 0) and (lEndClip <= 0) then
-        exit; //no change
-     if (lStartClip+lEndClip) >= lInHdr.dim[4] then
-        exit; //can not remove this many volumes
-     lVolBytes := lInHdr.dim[1]*lInHdr.dim[2]*lInHdr.dim[3]*trunc(((lInHdr.bitpix)+7)/8);
-     lClipHdr := lInHdr;
-     lClipHdr.dim[4] := lInHdr.dim[4]-lStartClip-lEndClip;
-     lVolStart := lVolOffset + (lStartClip*lVolBytes);
-     lClipName := ChangeFilePrefix (lOutImgName,'x');
-     result := SaveNIfTICore (lClipName, lvBuffer, lVolStart, lClipHdr, lPrefs,lByteSwap);
-end;
-
-function SubBound (lVal,lMin: integer): integer;
-begin
-    result := lVal;
-    if result < lMin then
-       result := lMin;
-end;
-
-function NonspatialDimensionsNII (lA: TNIFTIhdr): integer;
-//returns sum of 4th, 5th, 6th and 7th dimension...
-begin
-     result := SubBound(lA.dim[4],1)*SubBound(lA.dim[5],1)*SubBound(lA.dim[6],1)*SubBound(lA.dim[7],1);
-end;
-
-function NIFTIhdr_LoadImgRaw (LoadHdr: boolean; var lFilename: string; var lHdr: TNIFTIHdr; var lImgBuffer: byteP; var lImgOffset: integer; var lByteSwap: boolean): boolean;
-//ImgBuffer always offset by kNIIImgOffset- this allows rapid nii.gz creation
-//loads img to byteP - if this returns successfully you must freemem(lImgBuffer)
-var
-   lExt,lImgName: string;
-   lVol,lFileBytes,lImgBytes: integer;
-   lBuf: ByteP;
-   lGZin: boolean;
-   lInF: File;
-begin
-    result := false;
-    if loadHdr then begin
-       if not NIFTIhdr_LoadHdr (lFilename, lHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lFilename);
-        exit;
-       end;
-    end;//if we load the header from disk...
-    lExt := UpCaseExt(lFilename);
-    lGZin := ExtGZ(lFilename);
-    if lExt = '.VOI' then
-       lGZin := true;
-   lImgOffset := kNIIImgOffset;// (=352) bytes for creating .nii.gz files
-   lVol := NonspatialDimensionsNII(lHdr);//lHdr.dim[4];
-   if lVol < 1 then
-      lVol := 1;
-   lImgBytes := lHdr.dim[1]*lHdr.dim[2]*lHdr.dim[3]*lVol*(lHdr.bitpix div 8);
-   if lExt ='.HDR' then
-       lImgName :=  changefileext(lFilename,'.img')
-   else
-       lImgName := lFilename;
-   if not fileexists(lImgName) then begin
-       Msg('LoadImg Error: Unable to find '+lImgName);
-       exit;
-   end;
-   if (not lGZin) and (FSize (lImgName) < ( lImgBytes+round(lHdr.vox_offset))) then begin
-       Msg('LoadImg Error: File smaller than expected  '+lImgName);
-       exit;
-   end;
-   lFileBytes := lImgBytes+ lImgOffset;
-   GetMem(lImgBuffer,lFileBytes);
-   if lGZin then begin
-      lBuf := @lImgBuffer^[lImgOffset+1];
-      UnGZip (lImgName,lBuf, round(lHdr.vox_offset),lImgBytes);
-   end else begin
-       AssignFile(lInF, lImgName);
-       Reset(lInF,1);
-       Seek(lInF,round(lHdr.vox_offset));
-       Filemode := 0;  //ReadONly
-       BlockRead(lInF, lImgBuffer^[lImgOffset+1],lImgBytes);
-       CloseFile(lInF);
-   end;
-   Filemode := 2;  //Read/Write
-   result := true;
-end; //NIFTIhdr_LoadImgRaw
-
-function NIFTIhdr_LoadImg (var lFilename: string; var lHdr: TNIFTIHdr; var lImgBuffer: byteP; var lImgOffset: integer; var lByteSwap: boolean): boolean;
-begin
-    result := NIFTIhdr_LoadImgRaw (true, lFilename, lHdr, lImgBuffer, lImgOffset, lByteSwap);
-end;
-(*function NIFTIhdr_LoadImg (var lFilename: string; var lHdr: TNIFTIHdr; var lImgBuffer: byteP; var lImgOffset: integer; var lByteSwap: boolean): boolean;
-//ImgBuffer always offset by kNIIImgOffset- this allows rapid nii.gz creation
-//loads img to byteP - if this returns successfully you must freemem(lImgBuffer)
-var
-   lExt,lImgName: string;
-   lVol,lFileBytes,lImgBytes: integer;
-   lBuf: ByteP;
-   lGZin: boolean;
-   lInF: File;
-begin
-    result := false;
-    if not NIFTIhdr_LoadHdr (lFilename, lHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lFilename);
-        exit;
-    end;
-    lExt := UpCaseExt(lFilename);
-    lGZin := ExtGZ(lFilename);
-    if lExt = '.VOI' then
-       lGZin := true;
-   lImgOffset := kNIIImgOffset;// (=352) bytes for creating .nii.gz files
-   lVol := lHdr.dim[4];
-   if lVol < 1 then
-      lVol := 1;
-   lImgBytes := lHdr.dim[1]*lHdr.dim[2]*lHdr.dim[3]*lVol*(lHdr.bitpix div 8);
-   if lExt ='.HDR' then
-       lImgName :=  changefileext(lFilename,'.img')
-   else
-       lImgName := lFilename;
-   if not fileexists(lImgName) then begin
-       Msg('LoadImg Error: Unable to find '+lImgName);
-       exit;
-   end;
-   if (not lGZin) and (FSize (lImgName) < ( lImgBytes)) then begin
-       Msg('LoadImg Error: File smaller than expected  '+lImgName);
-       exit;
-   end;
-   lFileBytes := lImgBytes+ lImgOffset;
-   GetMem(lImgBuffer,lFileBytes);
-   if lGZin then begin
-      lBuf := @lImgBuffer^[lImgOffset+1];
-      UnGZip (lImgName,lBuf, round(lHdr.vox_offset),lImgBytes);
-   end else begin
-       AssignFile(lInF, lImgName);
-       Reset(lInF,1);
-       Seek(lInF,round(lHdr.vox_offset));
-       Filemode := 0;  //ReadONly
-       BlockRead(lInF, lImgBuffer^[lImgOffset+1],lImgBytes);
-       CloseFile(lInF);
-   end;
-   Filemode := 2;  //Read/Write
-   result := true;
-end; *)
-
-procedure CustomFilename (var lFilename: string);
-var
-   lNew,lPath,lName,lExt: string;
-begin
-     if not FilenameParts (lFilename, lPath,lName,lExt) then exit;
-     lNew := GetStr('Rename '+lName);
-     if lNew = '' then exit;
-     lFilename := lPath + lNew + lExt;
-end;
-
-function ChangeNIfTISubformat(lHdrName: string; var lHdr: TNIFTIhdr;  lPrefs: TPrefs): boolean;
-var
-   lImgBuffer: byteP;
-   lImgOffset: integer;
-   lOutImgName: string;
-   lByteSwap: boolean;
-begin
-   result := false;
-   if not NIFTIhdr_LoadImg (lHdrName, lHdr, lImgBuffer, lImgOffset,lByteSwap) then  exit;
-   Msg('Changing subformat of '+lHdrName);
-   lOutImgName := ChangeFilePrefix (lHdrName,'f');
-   if lPrefs.CustomRename then
-      CustomFilename(lOutImgName);
-   if  SaveNIfTICore (lOutImgName, lImgBuffer, lImgOffset+1, lHdr, lPrefs,lByteSwap) ='' then exit;
-   Freemem(lImgBuffer);
-   result := true; //11/2007
-   ExitCode := 0;
-end;
-
-
-procedure NIFTIhdr_SlicesToCoord (var lHdr: TNIFTIhdr; lXslice,lYslice,lZslice: integer; var lXmm,lYmm,lZmm: single);
-//ignores origin offset
-begin
-    lXmm := (lHdr.srow_x[0]*lXslice)+ (lHdr.srow_x[1]*lYslice)+(lHdr.srow_x[2]*lzslice);
-    lYmm := (lHdr.srow_y[0]*lXslice)+ (lHdr.srow_y[1]*lYslice)+(lHdr.srow_y[2]*lzslice);
-    lZmm := (lHdr.srow_z[0]*lXslice)+ (lHdr.srow_z[1]*lYslice)+(lHdr.srow_z[2]*lzslice);
-end;
-
-
-
-function NIFTIhdr_LoadHdr (var lFilename: string; var lHdr: TNIFTIHdr; var lByteSwap: boolean): boolean;
-var
-  lHdrFile: file;  {lOri: array [1..3] of single;}  lBuff: Bytep;
-  lReportedSz, lSwappedReportedSz,lHdrSz: Longint;
-  lFileSz: Int64;
-  lExt: string; //1494
-begin
-  Result := false; //assume error
-  if lFilename = '' then exit;
-  lExt := UpCaseExt(lFilename);
-  if lExt = '.IMG' then
-	lFilename := changeFileExt(lFilename,'.hdr');
-  lHdrSz := sizeof(TniftiHdr);
-  lFileSz := FSize (lFilename);
-  if lFileSz = 0 then begin
-	  Msg('Unable to find NIFTI header named '+lFilename);
-	  exit;
-  end;
-  if lFileSz < lHdrSz then begin
-	  Msg('Error in reading NIFTI header: NIfTI headers need to be at least '+inttostr(lHdrSz)+ ' bytes: '+lFilename);
-	  exit;
-  end;
-  FileMode := 0;  { Set file access to read only }
-   if (lExt = '.NII.GZ') or (lExt = '.VOI') then begin//1388
-	  lBuff := @lHdr;
-	UnGZip(lFileName,lBuff,0,lHdrSz); //1388
-   end else begin //if gzip
-	   {$I-}
-	   AssignFile(lHdrFile, lFileName);
-	   FileMode := 0;  { Set file access to read only }
-	   Reset(lHdrFile, 1);
-	   {$I+}
-	   if ioresult <> 0 then begin
-		  Msg('Error in reading NIFTI header.'+inttostr(IOResult));
-		  FileMode := 2;
-		  exit;
-	   end;
-	   BlockRead(lHdrFile, lHdr, lHdrSz);
-	   CloseFile(lHdrFile);
-   end;
-  FileMode := 2;
-  if (IOResult <> 0) then exit;
-  lReportedSz := lHdr.HdrSz;
-  lSwappedReportedSz := lReportedSz;
-  swap4(lSwappedReportedSz);
-  if lReportedSz = lHdrSz then begin
-	 lByteSwap := false;
-  end else if lSwappedReportedSz = lHdrSz then begin
-	  lByteSwap := true;
-	  NIFTIhdr_SwapBytes (lHdr);
-  end else begin
-	  Msg('Warning: the header file is not in NIfTi format [the first 4 bytes do not have the value 348]. Assuming big-endian data.');
-	  exit;
-  end;
-  if (lHdr.dim[0] > 7) or (lHdr.dim[0] < 1) then begin //only 1..7 dims, so this
-	  Msg('Illegal NIfTI Format Header: this header does not specify 1..7 dimensions.');
-	  exit;
-  end;
-  if lHdr.Dim[4] < 1 then
-        lHdr.Dim[4] := 1;
-  result := true;
-end; //func Analyzehdr_LoadHdr
-
-function SaveHdr (var lFilename: ANSIstring; var lInHdr: TNIFTIhdr ; lSwap,lSPM2:boolean): boolean;
-var
-	lOutHdr: TNIFTIhdr;
-	lExt: string;
-	lF: File;
-	lLong: LongINt;
-begin
-	 result := false;
-	 if ((sizeof(TNIFTIhdr ))> DiskFreeEx(lFilename)) then begin
-		Msg('There is not enough free space on the destination disk to save the header. '+kCR+
-		lFileName+ kCR+' Bytes Required: '+inttostr(sizeof(TNIFTIhdr )) );
-		exit;
-	 end;
-  if lInHdr.dim[4] > 1 then begin
-      lInHdr.dim[0] := 4;
-  end else begin
-      lInHdr.dim[0] := 3;//3D july2006
-      lInHdr.dim[4] := 1;//3D july2006
-  end;
-	 {if Fileexists(lFileName) then begin
-		 Msg('Error: the file '+lFileName+' already exists.');
-		 exit;
-	 end; }
-	 result := true;
-	 move(lInHdr, lOutHdr, sizeof(lOutHdr)) ;
-	lExt := UpCaseExt(lFileName);
-	if (lExt='.IMG') or (lExt ='.HDR') then begin
- {$IFDEF obsoleteENDIAN_BIG} //OSX PPC
-		lOutHdr.magic := kswapNIFTI_MAGIC_SEPARATE_HDR;
-  {$ELSE}
-		lOutHdr.magic := kNIFTI_MAGIC_SEPARATE_HDR;
-  {$ENDIF}
-		lOutHdr.vox_offset := 0;
-                  if lSPM2 then begin //SPM2 does not recognize NIfTI - origin values will be wrong
-                   lOutHdr.magic := 0;
-                   lOutHdr.qform_code := 0;
-                   lOutHdr.sform_code:= 0;
-                   lOutHdr.quatern_b := 0;
-                   lOutHdr.quatern_c := 0;
-                   lOutHdr.quatern_d := 0;
-                   lOutHdr.qoffset_x  := 0;
-                   lOutHdr.qoffset_y := 0;
-                   lOutHdr.qoffset_z := 0;
-                end;
-	end else begin
- {$IFDEF obsoleteENDIAN_BIG} //OSX PPC
-		lOutHdr.magic := kswapNIFTI_MAGIC_EMBEDDED_HDR;
-  {$ELSE}
-		lOutHdr.magic := kNIFTI_MAGIC_EMBEDDED_HDR;
-  {$ENDIF}
-	lOutHdr.vox_offset := kNIIImgOffset;//352 bytes
-	end;
- {$IFDEF obsoleteENDIAN_BIG} //OSX PPC
-	 if not lSwap  then
-  {$ELSE}
-	 if lSwap  then
-  {$ENDIF}
-        NIFTIhdr_SwapBytes (lOutHdr);{swap to sun format}
-     Filemode := 1; //1366
-	 AssignFile(lF, lFileName); {WIN}
-	 if fileexists(lFilename) then
-		Reset(lF,1)
-	 else
-	 Rewrite(lF,1);
-	 BlockWrite(lF,lOutHdr, sizeof(TNIFTIhdr ));
-	 if (lExt='.IMG') or (lExt ='.HDR') then begin
-	 end else begin
-		lLong := 0;
-		BlockWrite(lF,lLong, 4);
-	 end;
-	 CloseFile(lF);
-     Filemode := 2; //1366
-end;
-
-procedure SaveHdrRAM (var lFilename: ANSIstring; var lInHdr,lOutHdr: TNIFTIhdr ; lSwap,lSPM2:boolean);
-var
-	lExt: string;
-begin
-  if lInHdr.dim[4] > 1 then begin
-      lInHdr.dim[0] := 4;
-  end else begin
-      lInHdr.dim[0] := 3;//3D july2006
-      lInHdr.dim[4] := 1;//3D july2006
-  end;
-	 move(lInHdr, lOutHdr, sizeof(lOutHdr)) ;
-	lExt := UpCaseExt(lFileName);
-	if (lExt='.IMG') or (lExt ='.HDR') then begin
- {$IFDEF obsoleteENDIAN_BIG} //OSX PPC
-		lOutHdr.magic := kswapNIFTI_MAGIC_SEPARATE_HDR;
-  {$ELSE}
-		lOutHdr.magic := kNIFTI_MAGIC_SEPARATE_HDR;
-  {$ENDIF}
-		lOutHdr.vox_offset := 0;
-                  if lSPM2 then begin //SPM2 does not recognize NIfTI - origin values will be wrong
-                   lOutHdr.magic := 0;
-                   lOutHdr.qform_code := 0;
-                   lOutHdr.sform_code:= 0;
-                   lOutHdr.quatern_b := 0;
-                   lOutHdr.quatern_c := 0;
-                   lOutHdr.quatern_d := 0;
-                   lOutHdr.qoffset_x  := 0;
-                   lOutHdr.qoffset_y := 0;
-                   lOutHdr.qoffset_z := 0;
-                end;
-	end else begin
- {$IFDEF obsoleteENDIAN_BIG} //OSX PPC
-		lOutHdr.magic := kswapNIFTI_MAGIC_EMBEDDED_HDR;
-  {$ELSE}
-		lOutHdr.magic := kNIFTI_MAGIC_EMBEDDED_HDR;
-  {$ENDIF}
-	lOutHdr.vox_offset := kNIIImgOffset;//352 bytes
-
-	end;
- {$IFDEF obsoleteENDIAN_BIG} //OSX PPC
-	 if not lSwap  then
-  {$ELSE}
-	 if lSwap  then
-  {$ENDIF}
-        NIFTIhdr_SwapBytes (lOutHdr);{swap to sun format}
-end;
-
-procedure NIFTIhdr_SetIdentityMatrixx (var lHdr: TNIFTIHdr); //create neutral rotation matrix
-var lInc: integer;
-begin
-	with lHdr do begin
-		 for lInc := 0 to 3 do
-			 srow_x[lInc] := 0;
-		 for lInc := 0 to 3 do
-             srow_y[lInc] := 0;
-         for lInc := 0 to 3 do
-             srow_z[lInc] := 0;
-         for lInc := 1 to 16 do
-             intent_name[lInc] := chr(0);
-         //next: create identity matrix: if code is switched on there will not be a problem
-		 srow_x[0] := 1;
-         srow_y[1] := 1;
-         srow_z[2] := 1;
-    end;
-end; //proc NIFTIhdr_IdentityMatrix
-
-procedure NIFTIhdr_ClearHdr (var lHdr: TNIFTIhdr ); //put sensible default values into header
-var lInc: byte;
-begin
-  with lHdr do begin
-         {set to 0}
-         HdrSz := sizeof(TNIFTIhdr);
-         for lInc := 1 to 10 do
-             Data_Type[lInc] := chr(0);
-         for lInc := 1 to 18 do
-             db_name[lInc] := chr(0);
-         extents:=0;
-         session_error:= 0;
-         regular:='r';
-		 dim_info:=(0);
-         dim[0] := 4;
-         for lInc := 1 to 7 do
-             dim[lInc] := 0;
-         intent_p1 := 0;
-         intent_p2 := 0;
-         intent_p3 := 0;
-         intent_code:=0;
-         datatype:=0 ;
-         bitpix:=0;
-         slice_start:=0;
-         for lInc := 1 to 7 do
-             pixdim[linc]:= 1.0;
-         vox_offset:= 0.0;
-         scl_slope := 1.0;
-         scl_inter:= 0.0;
-         slice_end:= 0;
-         slice_code := 0;
-		 xyzt_units := 10;
-         cal_max:= 0.0;
-         cal_min:= 0.0;
-         slice_duration:=0;
-         toffset:= 0;
-         glmax:= 0;
-         glmin:= 0;
-         for lInc := 1 to 80 do
-             descrip[lInc] := chr(0);{80 spaces}
-         for lInc := 1 to 24 do
-             aux_file[lInc] := chr(0);{80 spaces}
-         {below are standard settings which are not 0}
-         bitpix := 16;//vc16; {8bits per pixel, e.g. unsigned char 136}
-         DataType := 4;//vc4;{2=unsigned char, 4=16bit int 136}
-         Dim[0] := 3;
-         Dim[1] := 256;
-         Dim[2] := 256;
-         Dim[3] := 128;
-         Dim[4] := 1; {n vols}
-         Dim[5] := 1;
-         Dim[6] := 1;
-         Dim[7] := 1;
-         glMin := 0;
-         glMax := 255;
-         qform_code := kNIFTI_XFORM_UNKNOWN;
-         sform_code:= kNIFTI_XFORM_UNKNOWN;
-         quatern_b := 0;
-         quatern_c := 0;
-         quatern_d := 0;
-         qoffset_x := 0;
-         qoffset_y := 0;
-         qoffset_z := 0;
-         NIFTIhdr_SetIdentityMatrixx(lHdr);
-         magic := kNIFTI_MAGIC_SEPARATE_HDR;
-    end; //with the NIfTI header...
-end; //proc NIFTIhdr_ClearHdr
-
-procedure DICOM2AnzHdr (var lBHdr: TNIFTIhdr; lAnonymize: boolean; var lFilename: string; var lDICOMdata: DicomData);
-var lInc,lLen: integer;
-   lStr,lFilenameWOPath: string;
-begin
-  NIFTIhdr_ClearHdr(lBHdr);
-if not lAnonymize then begin
-  //next: put PatientID into patient_ID array
-   lLen := length(lDICOMdata.ProtocolName);
-   if lLen > 23 then lLen := 23; //24=size of aux_file
-   if lLen > 0 then begin
-     lBHdr.aux_file[1] :='!';
-      for lInc := 1 to lLen do
-        lBHdr.aux_file[lInc+1] := lDICOMdata.ProtocolName[lInc];
-   end;
- (*  lLen := length(lDicomData.PatientID);
-  if lLen > 10 then lLen := 10; //10=size of patient_ID array
-  if lLen > 0 then
-     for lInc := 1 to lLen do
-      lBHdr.patient_id[lInc] := lDicomData.PatientID[lInc];   *)
-
-  //next: put PatientName into Descrip array
-  lLen := length(lDicomData.PatientName);
-  if lLen > 80 then lLen := 80; //80=size of descrip array
-  if lLen > 0 then
-     for lInc := 1 to lLen do
-      lBHdr.descrip[lInc] := lDicomData.PatientName[lInc];
-  //next: put StudyDate into exp_date array
- (* lLen := length(lDicomData.StudyDate);
-  if lLen > 10 then lLen := 10; //10=size of exp_date array
-  if lLen > 0 then
-     for lInc := 1 to lLen do
-      lBHdr.exp_date[lInc] := lDicomData.StudyDate[lInc]; *)
-  //next: put AcqTime into exp_time array
-  (*lLen := length(lDicomData.AcqTime);
-  if lLen > 10 then lLen := 10; //10=size of exp_time array
-  if lLen > 0 then
-     for lInc := 1 to lLen do
-      lBHdr.exp_time[lInc] := lDicomData.AcqTime[lInc];  *)
-  //next: put Modality into generated array
-  (*lLen := length(lDicomData.modality);
-  if lLen > 10 then lLen := 10; //10=size of generated array
-  if lLen > 0 then
-     for lInc := 1 to lLen do
-      lBHdr.generated[lInc] := lDicomData.modality[lInc];*)
-end; //Not anonymized
-  //next: put TR into db_Name array
-  lStr := '?TR:'+floattostrf(lDicomData.TR,ffFixed,8,3)+' TE:'+floattostrf(lDicomData.TE,ffFixed,8,2);
-  lLen := length(lStr);
-  if lLen > 18 then lLen := 18; //10=size of generated array
-  if lLen > 0 then
-     for lInc := 1 to lLen do
-      lBHdr.db_name[lInc] := lStr[lInc];
-
-
-
-  if lDICOMdata.XYZdim[4] > 1 then
-  	lBHdr.Dim[0] := 4 //4D Data June 2006
-  else
-  	lBHdr.Dim[0] := 3;
-  lBHdr.Dim[1] := lDICOMdata.XYZdim[1];
-  lBHdr.Dim[2] := lDICOMdata.XYZdim[2];
-  lBHdr.Dim[3] := lDICOMdata.XYZdim[3];
-  lBHdr.Dim[4] := lDICOMdata.XYZdim[4];
-  lBHdr.pixdim[1]:= lDICOMdata.XYZmm[1];
-  lBHdr.pixdim[2]:= lDICOMdata.XYZmm[2];
-  lBHdr.pixdim[3]:= lDICOMdata.XYZmm[3];
-  lBHdr.pixdim[4] := lDicomData.TR/1000; //convert MS to second = assumes xyzt = 10
-
-  lBHdr.pixdim[7] := lDICOMdata.SecSinceMidnight;
-  if lDICOMdata.IntenScale <> 0 then
-	 lBHdr.scl_slope := lDICOMdata.IntenScale
-  else
-      lBHdr.scl_slope := 1;
-  if not specialsingle(lDICOMdata.IntenIntercept) then
-	 lBHdr.scl_inter := lDICOMdata.IntenIntercept //1406
-  else lBHdr.scl_inter := 0;
-  lBHdr.bitpix := 8; //1360
-  lBHdr.datatype := 2; //1360
-  if lDicomData.Allocbits_per_pixel <> 8 then begin
-     if lDicomData.Allocbits_per_pixel = 32 then begin
-        lBHdr.bitpix := 32;
-        if lDicomData.FloatData then
-           lBHdr.datatype := 16
-        else
-            lBHdr.datatype := 8;
-     end else if lDicomData.Allocbits_per_pixel = 64 then begin
-        lBHdr.bitpix := 64;
-        lBHdr.datatype := 64;
-     end else begin //16bits per pixel
-         lBHdr.bitpix := 16;
-         lBHdr.datatype := kDT_SIGNED_SHORT;
-         if (not lDicomData.SignedData) and (lDicomData.Allocbits_per_pixel = 16) then begin
-           lBHdr.datatype :=kDT_UINT16;
-           //Msg('NII convert warning: unusual 16-bit UNsigned data format - may not be correctly recognized by all software.');
-         end;
-     end;
-  end;
-end;  //proc DICOM2AnzHdr
-
-function NII_force32 (lSrcName,lDestName: string; lPrefs: TPrefs):string;
-var
-   lPOs,lSrcOffset,lVol,lVox: integer;
-  l32f : SingleP;
-   l32is : LongIntP;
-   l16is : SmallIntP;
-   l8is,lSrcBuffer,lBuffUnaligned,lBuffAligned: bytep;
-   lSrcHdr,lDestHdr: TNIFTIhdr;
-   lByteSwap: boolean;
-begin
-     result := '';
-     if not NIFTIhdr_LoadHdr (lSrcname, lSrcHdr, lByteSwap) then exit;
-     case lSrcHdr.datatype of
-           kDT_UNSIGNED_CHAR : ;
-	  kDT_SIGNED_SHORT: ;
-          kDT_SIGNED_INT: ;
-	  kDT_FLOAT: begin
-          Msg('NII convert to 32-bit float error: datatype already 32-bit float.');
-             exit;
-            end;
-         else begin
-             Msg('NII convert to 32-bit float error: datatype not supported.');
-             exit;
-         end;
-     end; //case
-     lDestHdr := lSrcHdr; //destination has the comments and voxel BPP of source
-     //lDestHdr.dim[4] := 1;
-     lDestHdr.datatype := kDT_FLOAT;
-     lDestHdr.bitpix := 32;
-     lVol := lDestHdr.Dim[4];
-     lVox := lDestHdr.Dim[1]*lDestHdr.Dim[2]*lDestHdr.Dim[3]*lVol;
-     //load dataset
-     if not NIFTIhdr_LoadImg (lSrcName, lSrcHdr, lSrcBuffer, lSrcOffset,lByteSwap) then  exit;
-     NIFTIhdr_UnswapImg(lSrcHdr, lSrcBuffer, lSrcOffset,lByteSwap);//interpolation requires data is in native endian
-     l8is := (@lSrcBuffer^[lSrcOffset+1]);
-     GetMem(lBuffUnaligned ,(4*lVox) + 16+kNIIImgOffset);
-     {$IFDEF FPC}
-     lBuffAligned := Align(lBuffUnaligned,16); // not commented - check this
-     {$ELSE}
-     lBuffAligned := ByteP($fffffff0 and (integer(lBuffUnaligned)+15));
-     {$ENDIF}
-     lPos := 1;
-     l32f := SingleP(@lBuffAligned^[kNIIImgOffset+lPos] );
-     case lSrcHdr.datatype of
-	  kDT_SIGNED_SHORT: l16is := SmallIntP(l8is );
-          kDT_SIGNED_INT:l32is := LongIntP(l8is );
-	  //kDT_FLOAT: l32fs := SingleP(l8is );
-     end; //case
-     if lSrcHdr.datatype = kDT_UNSIGNED_CHAR then begin
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l8is^[lPos];
-     end else if lSrcHdr.datatype = kDT_SIGNED_SHORT then begin
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l16is^[lPos];
-     end else if lSrcHdr.datatype = kDT_SIGNED_INT then begin
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l32is^[lPos];
-     end;
-     result :=  SaveNIfTICore (lDestName, lBuffAligned, kNIIImgOffset+1, lDestHdr, lPrefs,lByteSwap);
-     Freemem(lBuffUnaligned);
-     Freemem(lSrcBuffer);
-end;
-procedure MakeSym (var l32f: SingleP; var lHdr: TNIFTIhdr);
-var
-   lHalf,lL,lLines,lH,lX,lOffset: integer;
-   lV : single;
-begin
-     lX := lHdr.Dim[1];
-     lHalf := lX div 2; //we will not touch middle voxel of odd data...
-     lLines := lHdr.Dim[2]*lHdr.Dim[3]*lHdr.Dim[4];
-     if (lHalf < 1) or (lLines < 1) then
-        exit;
-
-     lOffset := 0;
-     for lL := 1 to lLines do begin
-         lOffset := lOffset + lX;
-         for lH := 1 to lHalf do begin
-             lV := (l32f^[lOffset+lH] + l32f^[lOffset+lX-lH+1]) / 2;
-             l32f^[lOffset+lH] := lV;
-             l32f^[lOffset+lX-lH+1] := lV;
-         end;
-     end;
-end;
-
-function Rescale_4Dtissuemaps (lSrcName,lDestName: string; lPrefs: TPrefs; lMakeSym: boolean):string;
-//takes 4D image where each volume is 8-bit tissue map, saves as 32-bit float, ensures that no voxel has more than kmax or less than kmin intensity
-const
-     kMaxAllTissues = 0.99;
-     kMinAllTissues = 0.50; //set to 0 to ignore
-     //kMax= 0.85;
-     //kMin = 0.000;
-var
-   lScale,lSum: double;
-   lV,lPOs,lSrcOffset,lVol,lVox: integer;
-   l32fs,l32f : SingleP;
-   l32is : LongIntP;
-   l16is : SmallIntP;
-   l8is,lSrcBuffer,lBuffUnaligned,lBuffAligned: bytep;
-   lSrcHdr,lDestHdr: TNIFTIhdr;
-   lByteSwap: boolean;
-   lSumName: string;
-begin
-     result := '';
-     if not NIFTIhdr_LoadHdr (lSrcname, lSrcHdr, lByteSwap) then exit;
-     case lSrcHdr.datatype of
-           kDT_UNSIGNED_CHAR : ;
-	  kDT_SIGNED_SHORT: ;
-          kDT_SIGNED_INT: ;
-	  kDT_FLOAT: ;
-         else begin
-             Msg('NII convert to 32-bit float error: datatype not supported.');
-             exit;
-         end;
-     end; //case
-     lDestHdr := lSrcHdr; //destination has the comments and voxel BPP of source
-     //lDestHdr.dim[4] := 1;
-     lDestHdr.datatype := kDT_FLOAT;
-     lDestHdr.bitpix := 32;
-     lVol := lDestHdr.Dim[4];
-     lVox := lDestHdr.Dim[1]*lDestHdr.Dim[2]*lDestHdr.Dim[3]*lVol;
-     //load dataset
-     if not NIFTIhdr_LoadImg (lSrcName, lSrcHdr, lSrcBuffer, lSrcOffset,lByteSwap) then  exit;
-     NIFTIhdr_UnswapImg(lSrcHdr, lSrcBuffer, lSrcOffset,lByteSwap);//interpolation requires data is in native endian
-     l8is := (@lSrcBuffer^[lSrcOffset+1]);
-     GetMem(lBuffUnaligned ,(4*lVox) + 16+kNIIImgOffset);
-     {$IFDEF FPC}
-     lBuffAligned := Align(lBuffUnaligned,16); // not commented - check this
-     {$ELSE}
-     lBuffAligned := ByteP($fffffff0 and (integer(lBuffUnaligned)+15));
-     {$ENDIF}
-     lPos := 1;
-     l32f := SingleP(@lBuffAligned^[kNIIImgOffset+lPos] );
-     case lSrcHdr.datatype of
-	  kDT_SIGNED_SHORT: l16is := SmallIntP(l8is );
-          kDT_SIGNED_INT:l32is := LongIntP(l8is );
-	  kDT_FLOAT: l32fs := SingleP(l8is );
-     end; //case
-     if lSrcHdr.datatype = kDT_UNSIGNED_CHAR then begin
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l8is^[lPos];
-     end else if lSrcHdr.datatype = kDT_SIGNED_SHORT then begin
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l16is^[lPos];
-     end else if lSrcHdr.datatype = kDT_SIGNED_INT then begin
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l32is^[lPos];
-     end else if lSrcHdr.datatype = kDT_FLOAT then begin
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l32fs^[lPos];
-     end;
-     if lMakeSym then
-        MakeSym (l32f,lDestHdr);
-
-     //next - ensure that no voxel has sum probability more than kMaxAllTissues
-     if lVol > 1 then begin  //for 4D data...
-        lVox := lDestHdr.Dim[1]*lDestHdr.Dim[2]*lDestHdr.Dim[3]; //this will be done in 3D, not 4D
-        for lPos := 1 to lVox do begin
-            lSum := 0;
-            for lV := 1 to lVol do
-             lSum := lSum+ l32f^[lPos + ((lV-1)*lVox )]; //lookup table could speed this up
-             if (lSum < kMinAllTissues) and (kMinAllTissues > 0) then begin
-               lScale := kMinAllTissues-lSum;
-               //add to 5th volume (soft tissue - non-brain
-               l32f^[lPos + ((5-1)*lVox )] := lScale + l32f^[lPos + ((5-1)*lVox )]; //lookup table could speed this up
-            end else if lSum > kMaxAllTissues then begin
-               lScale := (kMaxAllTissues/lSum);
-               for lV := 1 to lVol do
-                   l32f^[lPos + ((lV-1)*lVox )] := lScale * l32f^[lPos + ((lV-1)*lVox )]; //lookup table could speed this up
-            end;
-        end; //each voxel
-     end; //4D
-
-     (*lVox := lDestHdr.Dim[1]*lDestHdr.Dim[2]*lDestHdr.Dim[3]*lVol;
-     //next - ensure no voxel is more than kmax
-     for lPos := 1 to lVox do
-         if l32f^[lPos] > kMax then
-             l32f^[lPos] := kMax;
-     //next - ensure that no voxel is less than kmin
-     for lPos := 1 to lVox do
-         if l32f^[lPos] < kMin then
-             l32f^[lPos] := kMin;    *)
-     result :=  SaveNIfTICore (lDestName, lBuffAligned, kNIIImgOffset+1, lDestHdr, lPrefs,lByteSwap);
-
-     //optional ... SumMap
-     if lVol > 1 then begin  //for 4D data...
-        lVox := lDestHdr.Dim[1]*lDestHdr.Dim[2]*lDestHdr.Dim[3]; //this will be done in 3D, not 4D
-        for lPos := 1 to lVox do begin
-            lSum := 0;
-            for lV := 1 to lVol do
-                lSum := lSum+ l32f^[lPos + ((lV-1)*lVox )]; //lookup table could speed this up
-            l32f^[lPos ] := lSum; //lookup table could speed this up
-        end; //each voxel
-     end; //4D
-     lDestHdr.Dim[4] := 1;
-     lSumName :=  ChangeFilePrefix (lDestName,'sum');
-     result :=  SaveNIfTICore (lSumName, lBuffAligned, kNIIImgOffset+1, lDestHdr, lPrefs,lByteSwap);
-     //... end SumMap
-     Freemem(lBuffUnaligned);
-     Freemem(lSrcBuffer);
-end;
-
-
-function SumTPM (lSrcName,lDestName: string; lPrefs: TPrefs; lTissueTypes2Average: integer):string;
-//Sum of first three tissue types (GM, WM, CSF
-var
-   //lScale,lSum: double;
-   lPOs,lSrcOffset,lVol,lVox,lnVol: integer;
-   l32fs,l32f : SingleP;
-   l32is : LongIntP;
-   l16is : SmallIntP;
-   l8is,lSrcBuffer,lBuffUnaligned,lBuffAligned: bytep;
-   lSrcHdr,lDestHdr: TNIFTIhdr;
-   lByteSwap: boolean;
-   //lSumName: string;
-begin
-     result := '';
-     if not NIFTIhdr_LoadHdr (lSrcname, lSrcHdr, lByteSwap) then exit;
-     case lSrcHdr.datatype of
-           kDT_UNSIGNED_CHAR,kDT_SIGNED_SHORT,kDT_SIGNED_INT,kDT_FLOAT: ;
-         else begin
-             Msg('SumTPM error: datatype not supported.');
-             exit;
-         end;
-     end; //case
-     lDestHdr := lSrcHdr; //destination has the comments and voxel BPP of source
-     lDestHdr.datatype := kDT_FLOAT;
-     lDestHdr.bitpix := 32;
-     lDestHdr.Dim[4] := 1;
-     lVox := lDestHdr.Dim[1]*lDestHdr.Dim[2]*lDestHdr.Dim[3];
-     //load dataset
-     if not NIFTIhdr_LoadImg (lSrcName, lSrcHdr, lSrcBuffer, lSrcOffset,lByteSwap) then  exit;
-     NIFTIhdr_UnswapImg(lSrcHdr, lSrcBuffer, lSrcOffset,lByteSwap);//interpolation requires data is in native endian
-     l8is := (@lSrcBuffer^[lSrcOffset+1]);
-     lnVol := NonspatialDimensionsNII(lSrcHdr);
-     if lnVol > lTissueTypes2Average then
-        lnVol := lTissueTypes2Average;
-     if lnVol < 1 then
-        exit;
-     GetMem(lBuffUnaligned ,(4*lVox) + 16+kNIIImgOffset);
-     {$IFDEF FPC}
-     lBuffAligned := Align(lBuffUnaligned,16); // not commented - check this
-     {$ELSE}
-     lBuffAligned := ByteP($fffffff0 and (integer(lBuffUnaligned)+15));
-     {$ENDIF}
-     lPos := 1;
-     l32f := SingleP(@lBuffAligned^[kNIIImgOffset+lPos] );
-     for lPos := 1 to lVox do
-                l32f^[lPos] := 0;
-     if lSrcHdr.datatype = kDT_UNSIGNED_CHAR then begin
-        for lVol := 0 to lnVol -1 do
-            for lPos := 1 to lVox do
-                l32f^[lPos] := l32f^[lPos]+l8is^[lPos+(lVol*lVox)];
-     end else if lSrcHdr.datatype = kDT_SIGNED_SHORT then begin
-         l16is := SmallIntP(l8is );
-        for lVol := 0 to lnVol -1 do
-            for lPos := 1 to lVox do
-                l32f^[lPos] := l32f^[lPos]+l16is^[lPos+(lVol*lVox)];
-     end else if lSrcHdr.datatype = kDT_SIGNED_INT then begin
-        l32is := LongIntP(l8is );
-        for lVol := 0 to lnVol -1 do
-            for lPos := 1 to lVox do
-                l32f^[lPos] := l32f^[lPos]+l32is^[lPos+(lVol*lVox)];
-     end else if lSrcHdr.datatype = kDT_FLOAT then begin
-         l32fs := SingleP(l8is );
-         for lVol := 0 to lnVol -1 do
-            for lPos := 1 to lVox do
-                l32f^[lPos] := l32f^[lPos]+l32fs^[lPos+(lVol*lVox)];
-     end;
-     result :=  SaveNIfTICore (lDestName, lBuffAligned, kNIIImgOffset+1, lDestHdr, lPrefs,lByteSwap);
-     lDestHdr.Dim[4] := 1;
-
-     //result :=  SaveNIfTICore (lSumName, lBuffAligned, kNIIImgOffset+1, lDestHdr, lPrefs,lByteSwap);
-     //... end SumMap
-     Freemem(lBuffUnaligned);
-     Freemem(lSrcBuffer);
-end;
-
-
-function SameHdrDim (lAHdr,lBHdr: TNIFTIhdr; lCheck4D, lCheckDataType: boolean): boolean;
-var
-   i: integer;
-begin
-     result := true;
-     if (lCheckDataType) and (lAHdr.datatype <> lBHdr.datatype) then
-        result := false;
-     for i := 1 to 3 do
-         if (lAHdr.Dim[i] <> lBHdr.Dim[i]) then
-            result := false;
-     for i := 1 to 3 do
-         if (lAHdr.pixdim[i] <> lBHdr.pixdim[i]) then
-            result := false;
-     if lCheck4D then
-         if (lAHdr.Dim[4] <> lBHdr.Dim[4]) then
-            result := false;
-     if not result then begin
-        fx(1211);
-        msg('Image dimensions or datatype differ');
-     end;
-end;
-
-function Merge4DFiles (lLowSliceName,lHighSliceName,lDestName: string; lNumberofLowSlicesToCopy: integer; lPrefs: TPrefs):string;
-//takes 4D image where each volume is 8-bit tissue map, saves as 32-bit float, ensures that no voxel has more than kmax or less than kmin intensity
-var
-   lVolOffset,lSliceBytes,lV,lLoOffset,lHiOffset,lVol,lVox: integer;
-   l8iHi,l8iLo,lLoBuffer,lHiBuffer {,lBuffUnaligned,lBuffAligned}: bytep;
-   lLoHdr,lHiHdr: TNIFTIhdr;
-   lByteSwapLo,lByteSwapHi: boolean;
-   lBPP: integer;
-begin
-     result := '';
-     if not NIFTIhdr_LoadHdr (lLowSliceName, lLoHdr, lByteSwapLo) then exit;
-     if not NIFTIhdr_LoadHdr (lHighSliceName, lHiHdr, lByteSwapHi) then exit;
-     if lNumberofLowSlicesToCopy < 1 then
-        exit;
-     if not SameHdrDim(lLoHdr, lHiHdr,true,true) then
-        exit;
-     case lLoHdr.datatype of
-          kDT_UNSIGNED_CHAR : lBPP := 1;
-	        kDT_SIGNED_SHORT: lBPP := 2;
-          kDT_SIGNED_INT:lBPP := 4;
-	        kDT_FLOAT: lBPP := 4;
-         else begin
-             Msg('Merge4DFiles error: datatype not supported.');
-             exit;
-         end;
-     end; //case
-    //lDestHdr.dim[4] := 1;
-     lVol := lHiHdr.Dim[4];
-     lSliceBytes:= lHiHdr.Dim[1]*lHiHdr.Dim[2] * lBPP;
-     //load dataset
-     if not NIFTIhdr_LoadImg (lLowSliceName, lLoHdr, lLoBuffer, lLoOffset,lByteSwapLo) then  exit;
-     NIFTIhdr_UnswapImg(lLoHdr, lLoBuffer, lLoOffset,lByteSwapLo);//interpolation requires data is in native endian
-     if not NIFTIhdr_loadImg (lHighSliceName, lhiHdr, lhiBuffer, lhiOffset,lByteSwaphi) then  exit;
-     NIFTIhdr_UnswapImg(lhiHdr, lhiBuffer, lhiOffset,lByteSwaphi);//interpolation requires data is in native endian
-
-     l8iLo := (@lLoBuffer^[lLoOffset+1]);
-     l8iHi := (@lHiBuffer^[lHiOffset+1]);
-
-     for lV := 1 to lVol do begin
-         lVolOffset := (lV - 1) * (lSliceBytes*lHiHdr.Dim[3]);
-         for lVox := 1 to (lSliceBytes*lNumberofLowSlicesToCopy) do
-             l8iHi^[lVox+lVolOffset] := l8iLo^[lVox+lVolOffset];
-     end;
-     result :=  SaveNIfTICore (lDestName, lhiBuffer, kNIIImgOffset+1, lHiHdr, lPrefs,lByteSwapHi);
-     Freemem(lhiBuffer);
-     Freemem(lloBuffer);
-end;
-
-function Insert3Din4D (l3DSliceName,l4DSliceName,lDestName: string; lVol2Copy: integer; lPrefs: TPrefs):string;
-//takes 4D image where each volume is 8-bit tissue map, saves as 32-bit float, ensures that no voxel has more than kmax or less than kmin intensity
-var
-   lVolOffset,lVolBytes,l3DOffset,l4DOffset,lVox: integer;
-   l8i4D,l8i3D,l3DBuffer,l4DBuffer {,lBuffUnaligned,lBuffAligned}: bytep;
-   l3DHdr,l4DHdr: TNIFTIhdr;
-   lByteSwap3D,lByteSwap4D: boolean;
-   lBPP: integer;
-begin
-     result := '';
-     if not NIFTIhdr_LoadHdr (l3DSliceName, l3DHdr, lByteSwap3D) then exit;
-     if not NIFTIhdr_LoadHdr (l4DSliceName, l4DHdr, lByteSwap4D) then exit;
-     if lVol2Copy < 1 then
-        exit;
-     if not SameHdrDim(l3DHdr, l4DHdr,false,true) then
-        exit;
-     case l3DHdr.datatype of
-           kDT_UNSIGNED_CHAR : lBPP := 1;
-	  kDT_SIGNED_SHORT: lBPP := 2;
-          kDT_SIGNED_INT:lBPP := 4;
-	  kDT_FLOAT: lBPP := 4;
-         else begin
-             Msg('Merge4DFiles error: datatype not supported.');
-             exit;
-         end;
-     end; //case
-    //lDestHdr.dim[4] := 1;
-    // lVol := l4DHdr.Dim[4];
-     lVolBytes:= l4DHdr.Dim[1]*l4DHdr.Dim[2]*l4DHdr.Dim[3]* lBPP;
-     //load dataset
-     if not NIFTIhdr_LoadImg (l3DSliceName, l3DHdr, l3DBuffer, l3DOffset,lByteSwap3D) then  exit;
-     NIFTIhdr_UnswapImg(l3DHdr, l3DBuffer, l3DOffset,lByteSwap3D);//interpolation requires data is in native endian
-     if not NIFTIhdr_loadImg (l4DSliceName, l4DHdr, l4DBuffer, l4DOffset,lByteSwap4D) then  exit;
-     NIFTIhdr_UnswapImg(l4DHdr, l4DBuffer, l4DOffset,lByteSwap4D);//interpolation requires data is in native endian
-
-     l8i3D := (@l3DBuffer^[l3DOffset+1]);
-     l8i4D := (@l4DBuffer^[l4DOffset+1]);
-     lVolOffset := (lVol2Copy - 1) * (lVolBytes);
-     for lVox := 1 to (lVolBytes) do
-             l8i4D^[lVox+lVolOffset] := l8i3D^[lVox];
-     result :=  SaveNIfTICore (lDestName, l4DBuffer, kNIIImgOffset+1, l4DHdr, lPrefs,lByteSwap4D);
-     Freemem(l4DBuffer);
-     Freemem(l3DBuffer);
-end;
-
-
-function NIFTIhdr_LoadImg8bit (var lSrcName: string; var lSrcHdr: TNIFTIHdr; var lSrcBuffer: bytep; var lSrcOffset: integer; var lByteSwap: boolean): boolean;
-
-begin
-     result := false;
-     if not NIFTIhdr_LoadImg (lSrcName, lSrcHdr, lSrcBuffer, lSrcOffset,lByteSwap) then  exit;
-     if lSrcHdr.datatype <> kDT_UNSIGNED_CHAR then begin
-        msg('Only able to read 8-bit data.');
-        exit;
-     end;
-     //NIFTIhdr_UnswapImg(lSrcHdr, lSrcBuffer, lSrcOffset,lByteSwap);//interpolation requires data is in native endian
-     result := true;
-end;
-
-function MaskImages(lMaskName: string; lFiles: TStrings; lPrefs: TPrefs; lVol: integer; lSaveThresh: boolean): string;
-var
-   lFileOffset,lMaskOffset,lInc,lVox,lPos,lOK: integer;
-   lMaskHdr,lFileHdr: TNIFTIHdr;
-   lMaskSwap,lFileSwap: boolean;
-   lFilename: string;
-   lMaskBuffer,lFileBuffer,l8if: bytep;
-   l32fm,l32fmean, l32fmeanpre: singlep;
-begin
-     result := '';
-     if not NIFTIhdr_LoadHdr (lMaskName, lMaskHdr, lMaskSwap) then exit;
-     if lMaskHdr.datatype <> kDT_FLOAT then begin
-         msg('This function only works with 32-bit float data.');
-         exit;
-     end;
-     lVox := lMaskHdr.Dim[1]*lMaskHdr.Dim[2]*lMaskHdr.Dim[3];
-     if lFiles.Count < 1 then exit;
-     if not NIFTIhdr_LoadImg (lMaskName, lMaskHdr, lMaskBuffer, lMaskOffset,lMaskSwap) then  exit;
-     NIFTIhdr_UnswapImg(lMaskHdr, lMaskBuffer, lMaskOffset,lMaskSwap);//interpolation requires data is in native endian
-     //fx(  ((lVol-1)* (lVox*4) ) );
-     l32fm := SingleP(@lMaskBuffer^[lMaskOffset+1+ ((lVol-1)* (lVox*4) )]);
-     //l32fo := SingleP(@lBuffAligned^[kNIIImgOffset+lPos] );
-     GetMem(l32fmean ,(4*lVox));
-     for lPos := 1 to lVox do
-         l32fmean^[lPos] := 0;
-     GetMem(l32fmeanpre ,(4*lVox));
-     for lPos := 1 to lVox do
-         l32fmeanpre^[lPos] := 0;
-     lOK := 0;
-     for lInc := 1 to lFiles.Count do begin
-         lFilename := lFiles.Strings[lInc-1];
-         if not NIFTIhdr_LoadImg8bit (lFileName, lFileHdr, lFilebuffer, lFileOffset,lFileSwap) then begin
-            msg('Serious error reading '+lFilename);
-            exit;
-         end;
-         if not (SameHdrDim(lMaskHdr,lFileHdr,false,false)) then
-            //fx(666)
-            //msg('This function only works with data with identical dimensions.')
-         else begin
-              l8if := (@lFilebuffer^[lFileOffset+1]);
-              for lPos := 1 to lVox do begin
-                  l32fmeanpre^[lPos] := l32fmeanpre^[lPos] + l8if^[lPos];
-                  if l32fm^[lPos] = 0 then
-                     l8if^[lPos] := 0
-                  else
-                      l32fmean^[lPos] := l32fmean^[lPos] + l8if^[lPos];
-              end;
-              lFilename :=  ChangeFilePrefix (lFilename,'z');
-              if lSaveThresh then
-                 result :=  SaveNIfTICore (lFilename, lFileBuffer, lFileOffset+1, lFileHdr, lPrefs,lFileSwap);
-              inc(lOK);
-         end;
-         Freemem(lFilebuffer);
-     end;
-     if lOK > 1 then begin
-        lMaskHdr.dim[4] := 1; //save only one volume
-        lMaskHdr.scl_slope := lFileHdr.scl_slope;
-        lMaskHdr.scl_inter := lFileHdr.scl_inter;
-
-        l32fm := SingleP(@lMaskBuffer^[lMaskOffset+1]);
-        for lPos := 1 to lVox do
-            l32fm^[lPos] := l32fmean^[lPos]/lOK;
-        lFilename :=  ChangeFilePrefix (lMaskName,'mean'+inttostr(lVol));
-        result :=  SaveNIfTICore (lFilename, lMaskBuffer, lMaskOffset+1, lMaskHdr, lPrefs,lMaskSwap);
-        for lPos := 1 to lVox do
-            l32fm^[lPos] := l32fmeanpre^[lPos]/lOK;
-        lFilename :=  ChangeFilePrefix (lMaskName,'meanpre'+inttostr(lVol));
-        result :=  SaveNIfTICore (lFilename, lMaskBuffer, lMaskOffset+1, lMaskHdr, lPrefs,lMaskSwap);
-     end;
-     Freemem(l32fmean);
-     Freemem(lMaskBuffer);
-end;
-
-function lDigitChar (lString: string): integer;
-//returns position of first number in filename, e.g. c:\x1xx.nii would return 5, since '1' is 5th char
-var
-   lP, lLen: integer;
-begin
-     result := 0;
-     lLen := length(lString);
-     if lLen < 1 then
-        exit;
-     for lP := lLen downto 1 do begin
-         if lString[lP] in ['0'..'9'] then
-            result := lP;
-         if lString[lP] in ['/','\'] then
-            exit;
-     end;
-
-end;
-
-function Binarize(lC1Name: string; lPrefs: TPrefs ): string;
-const
-     kMaps = 5;
-     kInten: array [1.. kMaps] of integer = ({graymatter}4,{whitematter}5,{csf}3,{bone}2,{soft tissue}1);
-var
-   //lFileOffset,lMaskOffset,lInc,lVox,lPos,lOK: integer;
-   lHname : array [1..kMaps] of string;
-   lH: array [1..kMaps] of TNIFTIHdr;
-   lMax,lMaxV,lV,lVox,lMap,lCharPos: integer;
-   lHSwap: boolean;
-   //lFilename: string;
-   lHBuffer,lH8i: array [1..kMaps] of bytep;
-   lHOffset: array [1..kMaps] of integer;
-   //l32fm,l32fmean, l32fmeanpre: singlep;
-begin
-     result := '';
-     lCharPos :=  lDigitChar (lC1Name);
-     if lCharPos < 1 then begin
-        msg('Error: number should be in filename.');
-        exit;
-     end;
-     for lMap := 1 to kMaps do begin
-         lHname[lMap] := lC1Name;
-         lHname[lMap][lCharPos] := inttostr(lMap)[1];
-         if not fileexists(lHname[lMap]) then begin
-            msg('Can not find '+lHname[lMap]);
-            exit;
-         end;
-     end;
-
-     for lMap := 1 to kMaps do begin
-         if not NIFTIhdr_LoadImg8bit (lHname[lMap], lH[lMap], lHBuffer[lMap], lHOffset[lMap],lHSwap) then begin
-            msg('Serious error reading '+lHname[lMap]);
-            exit;
-         end;
-         lH8i[lMap] := (@lHBuffer[lMap]^[lHOffset[lMap]+1]);
-     end;
-     lVox := lH[1].Dim[1]*lH[1].Dim[2]*lH[1].Dim[3];
-     (*for lV := 1 to lVox do begin
-         lMax := lH8i[4]^[lV] * 2;
-         if lMax > 1 {255} then lMax := 255;
-         lH8i[4]^[lV] := 255;
-     end;     *)
-     for lV := 1 to lVox do begin
-         lMax := kMaps;
-         lMaxV := lH8i[kMaps]^[lV];
-         for lMap := (kMaps-1) downto 1 do begin
-             if lH8i[lMap]^[lV] > lMaxV then begin
-                lMax := lMap;
-                lMaxV := lH8i[lMap]^[lV];
-             end;
-         end;
-         lMax := kInten[lMax];
-         //if lMax = kMaps then lMax := 0;
-         if lMaxV < 25 then lMax := 0;
-         lH8i[1]^[lV] := lMax;
-     end;
-     lH[1].dim[4] := 1; //save only one volume
-     lH[1].scl_slope := 1;
-     lH[1].scl_inter := 0;
-     lHname[1][lCharPos] := 'b';
-     result :=  SaveNIfTICore (lHname[1], lHBuffer[1], lHOffset[1]+1, lH[1], lPrefs,lHSwap);
-     for lMap := 1 to kMaps do
-         Freemem(lHBuffer[lMap]);
-end;
-
-(*function NIFTIhdr_LoadImgAs32float (var lSrcName: string; var lSrcHdr: TNIFTIHdr; var lSrcBuffer: bytep; var l32f: singlep; var lSrcOffset: integer; var lByteSwap: boolean): boolean;
-//function NIFTIhdr_LoadImgAs32float (var lSrcName: string; var lSrcHdr: TNIFTIHdr; {var lSrcBuffer: bytep;} var l32f: singlep; var lSrcOffset: integer; var lByteSwap: boolean): boolean;
-var
-   l32is : LongIntP;
-   l16is : SmallIntP;
-   lImgBuffer,l8is: bytep;
-   lPos,lVox: integer;
-   //lSrcBuffer: bytep;
-begin
-     result := false;
-     if not NIFTIhdr_LoadImg (lSrcName, lSrcHdr, lImgBuffer, lSrcOffset,lByteSwap) then  exit;
-     NIFTIhdr_UnswapImg(lSrcHdr, lImgBuffer, lSrcOffset,lByteSwap);//interpolation requires data is in native endian
-     result := true;
-     l8is := (@lImgBuffer^[lSrcOffset+1]);
-
-     //GetMem(l32f ,4*lVox );
-     case lSrcHdr.datatype of
-	  kDT_SIGNED_SHORT: l16is := SmallIntP(l8is );
-          kDT_SIGNED_INT:l32is := LongIntP(l8is );
-	  kDT_FLOAT: begin l32f := SingleP(l8is ); lSrcBuffer := lImgBuffer; {<- not sure if this works!} exit; end;
-     end; //case
-     lVox := lSrcHdr.Dim[1]*lSrcHdr.Dim[2]*lSrcHdr.Dim[3];
-     GetMem(lSrcBuffer ,(4*lVox) +lSrcOffset);
-     l32f := SingleP(@lSrcBuffer^[lSrcOffset+1]);
-
-     if lSrcHdr.datatype = kDT_UNSIGNED_CHAR then
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l8is^[lPos]
-     else if lSrcHdr.datatype = kDT_SIGNED_SHORT then
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l16is^[lPos]
-     else if lSrcHdr.datatype = kDT_SIGNED_INT then
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l32is^[lPos];
-     result := true;
-     freemem(lImgBuffer);
-     lSrcHdr.datatype := kDT_FLOAT;
-end;   *)
-
-
-function As32 (lSrcName: string; var lSrcHdr:TNIFTIhdr; var l32f: singlep):boolean;
-//takes 4D image where each volume is 8-bit tissue map, saves as 32-bit float, ensures that no voxel has more than kmax or less than kmin intensity
-var
-(*   lScale,lSum: double;
-   lV,lPOs,lSrcOffset,lVol,lVox: integer;
-   l32fs,l32f : SingleP;
-   l32is : LongIntP;
-   l16is : SmallIntP;
-   l8is,lSrcBuffer,lBuffUnaligned,lBuffAligned: bytep;
-   lSrcHdr,lDestHdr: TNIFTIhdr;  *)
-   l32is : LongIntP;
-   l32fs : SingleP;
-   l16is : SmallIntP;
-   l8is,lSrcBuffer: bytep;
-   lSrcOffset,lVox,lPos: integer;
-   lByteSwap: boolean;
-begin
-     result := false;
-     if not NIFTIhdr_LoadHdr (lSrcname, lSrcHdr, lByteSwap) then exit;
-     case lSrcHdr.datatype of
-           kDT_UNSIGNED_CHAR : ;
-	  kDT_SIGNED_SHORT: ;
-          kDT_SIGNED_INT: ;
-	  kDT_FLOAT: ;
-         else begin
-             Msg('NII convert to 32-bit float error: datatype not supported.');
-             exit;
-         end;
-     end; //case
-     lVox := lSrcHdr.Dim[1]*lSrcHdr.Dim[2]*lSrcHdr.Dim[3];
-     //load dataset
-     if not NIFTIhdr_LoadImg (lSrcName, lSrcHdr, lSrcBuffer, lSrcOffset,lByteSwap) then  exit;
-     NIFTIhdr_UnswapImg(lSrcHdr, lSrcBuffer, lSrcOffset,lByteSwap);//interpolation requires data is in native endian
-     l8is := (@lSrcBuffer^[lSrcOffset+1]);
-     GetMem(l32f ,lVox * sizeof(single));
-     //lPos := 1;
-     case lSrcHdr.datatype of
-	  kDT_SIGNED_SHORT: l16is := SmallIntP(l8is );
-          kDT_SIGNED_INT:l32is := LongIntP(l8is );
-	  kDT_FLOAT: l32fs := SingleP(l8is );
-     end; //case
-     if lSrcHdr.datatype = kDT_UNSIGNED_CHAR then begin
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l8is^[lPos];
-     end else if lSrcHdr.datatype = kDT_SIGNED_SHORT then begin
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l16is^[lPos];
-     end else if lSrcHdr.datatype = kDT_SIGNED_INT then begin
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l32is^[lPos];
-     end else if lSrcHdr.datatype = kDT_FLOAT then begin
-        for lPos := 1 to lVox do
-            l32f^[lPos] := l32fs^[lPos];
-        for lPos := 1 to lVox do
-           if specialsingle(l32f^[lPos]) then
-              l32f^[lPos] := 0;
-     end;
-
-
-     freemem(lSrcBuffer);
-     result := true;
-
-end;
-//function MaskImgs(lC1template, lC1source: string; lPrefs: TPrefs ; lThresh: integer): string;
-function MaskImg(ltemplate, lsource: string; lPrefs: TPrefs; lThresh: single ): string;
-label
-     666;
-var
-   lH,lT:  TNIFTIHdr;
-   lV,lVox,lHOffset: integer;
-   lHSwap: boolean;
-  l32fs : SingleP;
-  l8is,lHBuffer:  bytep;
-   lOutname: string;
-begin
-     result := '';
-     if (not fileexists(lsource)) then begin
-        msg('Can not find '+ lsource);
-        exit;
-     end;
-
-     if  (not fileexists(ltemplate)) then begin
-        msg('Can not find '+ ltemplate);
-        exit;
-     end;
-     //if not NIFTIhdr_LoadImgAs32float (lsource, lH, lHBuffer, lHOffset,lHSwap) then begin
-     if not NIFTIhdr_LoadImg8bit (lsource, lH, lHBuffer, lHOffset,lHSwap) then begin
-        msg('Serious error reading '+lsource);
-        exit;
-     end;
-     //function NIFTIhdr_LoadImgAs32float (var lSrcName: string; var lSrcHdr: TNIFTIHdr; var lSrcBuffer: bytep; var l32f: singlep; var lSrcOffset: integer; var lByteSwap: boolean): boolean;
-     if not As32 (ltemplate, lT, l32fs) then  begin
-        msg('Serious error reading '+ltemplate);
-        exit;
-     end;
-     lVox := lH.Dim[1]*lH.Dim[2]*lH.Dim[3];
-     if not SameHdrDim (lH,lT, false, false) then begin
-        msg('Image dimensions do not match: '+ltemplate+' <> '+lsource);
-        goto 666;
-     end;
-     l8is := (@lHBuffer^[lHOffset+1]);
-     for lV := 1 to lVox do
-          if (l32fs^[lV] < lThresh) then
-             l8is^[lV] := 0;
-     lH.dim[4] := 1; //save only one volume
-     lH.scl_slope := 1;
-     lH.scl_inter := 0;
-     lOutname := ChangeFilePrefix(lsource,'m');
-     msg(lsource +' masked with '+ltemplate +' = '+lOutname);
-     result :=  SaveNIfTICore (loutname, lHBuffer, lHOffset+1, lH, lPrefs,lHSwap);
-666:
-    Freemem(l32fs);
-    Freemem(lHBuffer);
-end;
-
-
-
-function MaskImgs(lC1template, lC1source: string; lPrefs: TPrefs ; lThresh: single): string;
-const
-     kMaps = 5;
-var
-   lTName,lSName: string;
-   lMap,lSPos,lTPos: integer;
-begin
-     result := '';
-     lSPos :=  lDigitChar (lC1source);
-     lTPos :=  lDigitChar (lC1template);
-     if (lSPos < 1) or (lTPos < 1)  then begin
-        msg('Error: number should be in filenames: '+lC1template+'  '+ lC1source);
-        exit;
-     end;
-     lSname:= lC1source;
-     lTname:= lC1template;
-
-     for lMap := 1 to kMaps do begin
-         lSname[lSPos] := inttostr(lMap)[1];
-         lTname[lTPos] := inttostr(lMap)[1];
-         //msg(lTName+'  '+ lSName);
-         if ( fileexists(lTName)) and ( fileexists(lSName)) then
-            result := MaskImg(lTName, lSName, lPrefs, lThresh) ;
-     end;
-     msg('Masking completed');
-end;
-
-
-
-
-end.
-
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/nii_3dto4d.pas b/dcm2nii_prePARRECDTI/nii_3dto4d.pas
deleted file mode 100755
index 04d76d8..0000000
--- a/dcm2nii_prePARRECDTI/nii_3dto4d.pas
+++ /dev/null
@@ -1,456 +0,0 @@
-unit nii_3dto4d;
-{$H+}
-
-
-interface
-
-uses
-{$IFDEF FPC}gzio2,{$ENDIF}
-  SysUtils,define_types,dicomtypes,niftiutil,prefs,classes;
-
-function Stack3Dto4D(var lStr: TStringList; lOverwrite: boolean; lPrefs: TPrefs): boolean;
-function ExtractNIFTIHdrs(var lStr: TStringList): boolean;
-
-implementation
-uses dialogsx;
-
-function LeadingZeroFilename (lInX: string): string;
-var
-   lIn: string;
-   lC,lnPad,lPos,lnDec,lExtPos,lLen: integer;
-begin
-     {$IFDEF Unix}
-     lIn := lInX;
-     {$ELSE}
-     lIn := Lowercase(lInX);
-     {$ENDIF}
-     lnPad := 8;
-     lLen := length(lIn);
-     result := lIn;
-     if lLen < 1 then exit;
-     lExtPos := 1;
-     while (lExtPos <= lLen) and (lIn[lExtPos] <> '.') do
-           inc(lExtPos);
-     if lExtPos <= 1 then
-        exit;
-     //lnDec := 0;
-     lPos := lExtPos -1;
-     while (lPos > 0) and ( lIn[lPos] in ['0'..'9']) do
-           dec(lPos);
-     lnDec := (lExtPos-lPos)-1;
-     if (lnDec = 0) or (lnDec >= lnPad) then
-        exit;
-     result := '';
-     if lPos > 0 then
-        for lC := 1 to lPos do
-            result := result + lIn[lC];
-     for lC := 1 to (lnPad-lnDec) do
-         result := result + '0';
-     for lC := (lPos+1) to lLen do
-         result := result+lIn[lC];
-end;
-
-procedure SortStrPadded (var lStr: TStringList);
-//file1,file2...file10  not file1,file10..file2
-//may be slow: not a great sorting algorithm
-//may be inefficient: not sure if strings are exchanged or only pointers...
-var counter, look:integer; temp:Tstrings;
-begin
-   if lStr.Count < 2 then exit;
-   temp := TStringList.Create;
-   for counter:=0 to lStr.Count-1 do
-          temp.Append(LeadingZeroFilename{LowerCase}(lStr[counter]));
-          for counter:=0 to temp.Count-1 do
-               for look:=counter+1 to temp.Count-1 do
-               if temp[look]<temp[counter] then begin
-               lStr.Exchange(look, counter);
-               temp.Exchange(look,counter);
-     end;
-     temp.Free;
-end;
-
-function PasStr (lStr: string): string; //removes nulls
-var
-   i: integer;
-   t: string;
-begin
-     result := '';
-     for i := 1 to length(lStr) do begin
-         if (lStr[i] <> kDel) and(lStr[i] <> kTab) and (lStr[i] <> kEsc) and (lStr[i] <> chr(10)) and (lStr[i] <> chr (13)) and (ord(lStr[i]) <> 0) then
-            result := result + lStr[i];
-     end;
-     result := '"'+result +'"'
-end;
-
-function NIIstr (lFileName: string; lHdr : TNIFTIhdr): string;
-begin
-     result := lFileName
-     +kTab+'XYZT'+kTab+inttostr(lHdr.Dim[1])+kTab+inttostr(lHdr.Dim[2])+kTab+inttostr(lHdr.Dim[3])+kTab+inttostr(lHdr.Dim[4])
-     +kTab+'XYZTmm'+kTab+floattostr(lHdr.PixDim[1])+kTab+floattostr(lHdr.PixDim[2])+kTab+floattostr(lHdr.PixDim[3])+kTab+floattostr(lHdr.PixDim[4])
-     +kTab+'Description'+kTab+PasStr(lHdr.descrip)
-     +kTab+'Data_Type'+kTab+PasStr(lHdr.Data_Type)
-     +kTab+'db_name'+kTab+PasStr(lHdr.db_name)
-     +kTab+'aux_file'+kTab+PasStr(lHdr.aux_file)
-     +kTab+'intent_name'+kTab+PasStr(lHdr.intent_name)
-
-     ;
-end;
-
-function ExtractNIFTIHdrs(var lStr: TStringList): boolean;
-var
-   lHdrName: string;
-   lHdr : TNIFTIhdr;
-   lByteSwap: boolean;
-   lVol,lnVol : integer;
-begin
-   result := false;
-   lnVol := lStr.Count;
-   if lnVol < 1 then
-      exit;
-   SortStrPadded(lStr);
-   NIFTIhdr_LoadHdr (lHdrName, lHdr,lByteSwap);
-   for lVol := 1 to lnVol do begin
-       lHdrName := lStr[lVol-1];
-       if not NIFTIhdr_LoadHdr (lHdrName, lHdr,lByteSwap) then
-          Msg('Unable to find '+lHdrName)
-       else
-           Msg(NIIstr(lHdrName,lHdr));
-
-       //Msg( inttostr(lVol)+': '+lHdrName);
-   end;
-end;
-
-
-function Stack3Dto4D(var lStr: TStringList; lOverwrite: boolean; lPrefs: TPrefs): boolean;
-//function Reorder4D(var lHdrName: string; var lHdr: TNIFTIhdr; lOverwrite: boolean; lPrefs: TPrefs): boolean;
-label 123;
-var
-   lOutBuffer,lIBuffer: byteP;
-   lInOffset,lnVol,l4DVolBytes,l3DVolBytes,lIn3DBytes,l4DBytes,lVol,lInPos,lOutPos,lSlice: integer;
-   lHdrName,lOutImgName: string;
-   lHdr1,lHdr2,lOutHdr : TNIFTIhdr;
-   lByteSwap: boolean;
-   lPrefs4D: TPrefs;
-begin
-   result := false;
-   lnVol := lStr.Count;
-   if lnVol < 2 then begin
-      Msg('Stack 3D to 4D requires >1 volume');
-      exit;
-   end;
-   SortStrPadded(lStr);
-   lHdrName := lStr[0];
-   NIFTIhdr_LoadHdr (lHdrName, lHdr1,lByteSwap);
-   for lVol := 1 to lnVol do begin
-       lHdrName := lStr[lVol-1];
-       if not NIFTIhdr_LoadHdr (lHdrName, lHdr2,lByteSwap) then begin
-          Msg('Stack 3D to 4D unable to find '+lHdrName);
-          exit;
-       end;
-       if (lHdr1.dim[4] > 1) then begin
-          Msg('Stack 3D to 4D aborted, image is already 4D: '+lHdrName );
-          exit;
-       end;
-       if (lHdr1.dim[1] <> lHdr2.dim[1]) or (lHdr1.dim[2] <> lHdr2.dim[2]) or
-          (lHdr1.dim[3] <> lHdr2.dim[3]) or (lHdr1.datatype <> lHdr2.datatype) then begin
-          Msg('Stack 3D to 4D aborted, image dimensions/datatype vary '+lHdrName + ' <> '+lStr[0]);
-          exit;
-       end;
-       //Msg( inttostr(lVol)+': '+lHdrName);
-   end;
-   lOutHdr := lHdr1;
-   lOutHdr.dim[4] := lnVol;
-   l3DVolBytes := lHdr1.dim[1]*lHdr1.dim[2]*lHdr1.dim[3]*(lHdr1.bitpix div 8);
-   l4DVolBytes := l3DVolBytes * lnVol;
-   GetMem(lOutBuffer,l4DVolBytes+kNIIImgOffset);
-
-   Msg('Order in output file:');
-   lOutImgName := ChangeFilePrefix (lStr[0],'4D');
-   lOutPos := kNIIImgOffset + 1;
-   for lVol := 1 to lnVol do begin
-       lHdrName := lStr[lVol-1];
-       Msg( inttostr(lVol)+': '+lHdrName);
-       if not NIFTIhdr_LoadImg (lHdrName, lHdr2, lIBuffer, lInOffset,lByteSwap) then begin
-          Msg('3D -> 4D error loading image '+lHdrName);
-          goto 123;
-       end;
-       Move(lIBuffer^[lInOffset+1],lOutBuffer^[lOutPos],l3DVolBytes);
-       freemem(lIBuffer);
-       lOutPos := lOutPos + l3DVolBytes;
-   end;
-   lPrefs4D := lPrefs;
-   lPrefs4D.fourD := true;
-   Msg('4D image '+lOutImgName);
-   if  SaveNIfTICore (lOutImgName, lOutBuffer, kNIIImgOffset+1, lOutHdr, lPrefs4D,lByteSwap) = '' then begin
-      Msg('3D -> 4D Error');
-      goto 123;
-   end;
-
-    freemem(lOutBuffer);
-  result := true;
-  exit;
-123:
-    freemem(lOutBuffer);
-end;
-
-
-
-(*function Reorder4D(var lHdrName: string; var lHdr: TNIFTIhdr; lByteSwap,lSPM2in,lSingleNIIFile,lGZ,lOverwrite: boolean): boolean;
-var
-   lOutHdr: TNIFTIhdr;
-   lInName,lImgName: string;
-   lPos,lSlice,lVol,lInVolBytes,lSliceBytes: integer;
-   lBuffer: bytep;
-   lGZi,lSPM2: boolean;
-   lOutF,lInF: File;
-begin
-   result := false;
-   lGZi := lGZ;
-   lSPM2 := lSPM2in;
-   if lSingleNIIFIle then
-      lSPM2 := false;
-   if (lHdr.dim[4] < 2) or (lHdr.dim[3] < 2) then
-      exit;
-   lOutHdr := lHdr;
-   lOutHdr.dim[4] := lHdr.dim[3];
-   lOutHdr.dim[3] := lHdr.dim[4];
-   lSliceBytes := lHdr.dim[1]*lHdr.dim[2]*(lHdr.bitpix div 8);
-   lInVolBytes := lSliceBytes*lHdr.dim[3];
-   GetMem(lBuffer,lSliceBytes);
-   if UpCaseExt(lHdrName) ='.HDR' then begin
-       if lOverwrite then
-          deletefile(lHdrName);
-       lInName :=  changefileext(lHdrName,'.img')
-   end else begin
-       lOutHdr.vox_offset := 352;
-       lInName := lHdrName;
-   end;
-   if not fileexists(lInName) then begin
-       Msg('4Dclip Error: Unable to find '+lInName);
-       exit;
-   end;
-   if FSize (lInName) < ( (lInVolBytes*lHdr.dim[4])+round(lHdr.vox_offset)) then begin
-       Msg('4Dclip Error: File smaller than expected (can not convert compressed) '+lInName);
-       exit;
-   end;
-   Msg('Reordering image');
-   if not lSingleNiiFile then begin
-       lHdrName :=  changefileext(lHdrName,'.hdr');
-       lImgName :=  changefileext(lHdrName,'.img');
-       lGZi := false;
-   end else begin
-       lHdrName :=  changefileext(lHdrName,'.nii');
-       lImgName :=  changefileext(lHdrName,'.nii');
-   end;
-   if lOverwrite then begin
-      renamefile(lInName,changefileext(lInName,'.tmp'));
-      lInName := changefileext(lInName,'.tmp');
-   end else begin
-       lHdrName := ChangeFilePrefixExt (lHdrName,'x');
-       lImgName := ChangeFilePrefixExt (lImgName,'x');
-       Msg('saving as '+lHdrName);
-   end;
-   AssignFile(lInF, lInName);
-   Reset(lInF,1);
-   Seek(lInF,round(lHdr.vox_offset));
-   SaveHdr (lHdrName,lOutHdr,lByteSwap{ false},lSPM2);
-   AssignFile(lOutF, lImgName);
-   if lSingleNIIFile then begin
-      Reset(lOutF,1);
-      Seek(lOutF,352);
-   end else
-       Rewrite(lOutF,1);
-   for lVol := 1 to  lOutHdr.dim[4] do begin
-       lPos := ((lVol-1)*lSliceBytes) + round(lHdr.vox_offset);
-       for lSlice := 1 to lOutHdr.dim[3] do begin
-           Filemode := 0;  //ReadONly
-           seek(lInF,lPos);
-           BlockRead(lInF, lBuffer^, lSliceBytes);
-           Filemode := 2;
-           BlockWrite(lOutF, lBuffer^, lSliceBytes);
-           lPos := lPos + lInVolBytes;
-       end;//for lslice
-   end; //for lvol
-   CloseFile(lInF);
-   CloseFile(lOutF);
-   Freemem(lBuffer);
-   if lOverwrite then
-      DeleteFile(lInName);
-   if lGZi then
-      GZipFile(lImgName,lImgName+'.gz',true);
-   result := true;
-end;      *)
-
-(*function Clip4D(var lHdrName: string; var lHdr: TNIFTIhdr;  lByteSwap,lSPM2in, lSingleNIIFile,lGZ,lOverwrite: boolean; lStartIn,lEndIn: integer ): string;
-var
-   lOutHdr: TNIFTIhdr;
-   lInName,lImgName: string;
-   lVol,lVolBytes,lStart,lEnd: integer;
-    lBuffer: bytep;
-    lGZi,lSPM2 : boolean;
-    lOutF,lInF: File;
-begin
-   result := '';
-   lGZi := lGZ;
-   lSPM2 := lSPM2in;
-   if lSingleNIIFIle then
-      lSPM2 := false;
-   lStart := lStartIn;
-   if lStart < 0 then
-      lStart := 0;
-   lEnd := lEndIn;
-   if lEnd < 0 then
-      lEnd := 0;
-   lOutHdr := lHdr;
-   lOutHdr.dim[4] := lOutHdr.dim[4]-lStart-lEnd;
-   if lOutHdr.dim[4] < 1 then
-      exit;
-   lVolBytes := lOutHdr.dim[1]*lOutHdr.dim[2]*lOutHdr.dim[3]*(lOutHdr.bitpix div 8);
-   GetMem(lBuffer,lVolBytes);
-   if UpCaseExt(lHdrName) ='.HDR' then begin
-       if lOverwrite then
-          deletefile(lHdrName);
-       lInName :=  changefileext(lHdrName,'.img')
-   end else begin
-       lOutHdr.vox_offset := 352;
-       lInName := lHdrName;
-   end;
-   if not fileexists(lInName) then begin
-       Msg('4Dclip Error: Unable to find '+lInName);
-       exit;
-   end;
-   if FSize (lInName) < ( (lVolBytes*lHdr.dim[4])+round(lHdr.vox_offset)) then begin
-       Msg('4Dclip Error: File smaller than expected (can not convert compressed) '+lInName);
-       exit;
-   end;
-   if (lStart > 0) or (lEnd > 0) then
-      Msg('4D clip - removing first '+inttostr(lStart)+' and last '+inttostr(lEnd) +' volumes')
-   else
-       Msg('Formatting image');
-   if not lSingleNiiFile then begin
-       lGZi := false;
-       lHdrName :=  changefileext(lHdrName,'.hdr');
-       lImgName :=  changefileext(lHdrName,'.img');
-   end else begin
-       lHdrName :=  changefileext(lHdrName,'.nii');
-       lImgName :=  changefileext(lHdrName,'.nii');
-   end;
-   if lOverwrite then begin
-      renamefile(lInName,changefileext(lInName,'.tmp'));
-      lInName := changefileext(lInName,'.tmp');
-   end else begin
-       lHdrName := ChangeFilePrefixExt (lHdrName,'x');
-       lImgName := ChangeFilePrefixExt (lImgName,'x');
-       Msg('Saving clipped as '+lHdrName);
-   end;
-   AssignFile(lInF, lInName);
-   Reset(lInF,1);
-   Seek(lInF,round(lHdr.vox_offset));
-   SaveHdr (lHdrName,lOutHdr, lByteSwap{false},lSPM2);
-   AssignFile(lOutF, lImgName);
-   if lSingleNIIFile then begin
-      Reset(lOutF,1);
-      Seek(lOutF,352);
-   end else
-       Rewrite(lOutF,1);
-   for lVol := 1 to (lHdr.dim[4]-lEnd) do begin
-       //1st - save header
-       Filemode := 0;  //ReadONly
-       BlockRead(lInF, lBuffer^, lVolBytes);
-       if (lVol > lStart) then begin
-          Filemode := 2;
-          BlockWrite(lOutF, lBuffer^, lVolBytes);
-       end;
-   end;
-   CloseFile(lInF);
-   CloseFile(lOutF);
-   Freemem(lBuffer);
-   if lOverwrite then
-      DeleteFile(lInName);
-   if lGZi then begin
-      lHdrName := lImgName+'.gz';
-      GZipFile(lImgName,lHdrName,true);
-   end;
-   result := lHdrName;
-end;
-
-function Convert4Dto3D(var lHdrName: string; var lHdr: TNIFTIhdr; lByteSwap, lSPM2in,lSingleNIIFile,lGZ: boolean ): boolean;
-var
-   lOutHdr: TNIFTIhdr;
-   lOutName,lImgName: string;
-   lVol,lVolBytes: integer;
-    lBuffer: bytep;
-    lSPM2,lGZi: boolean;
-     lOutF,lInF: File;
-begin
-   result := false;
-   lSPM2 := lSPM2in;
-   if lSingleNIIFIle then
-      lSPM2 := false;
-   lGZi := lGZ;
-   if lHdr.dim[4] < 2 then
-      exit;
-   lOutHdr := lHdr;
-   lOutHdr.dim[0] := 3;//3D
-   lOutHdr.dim[4] := 1;
-   lVolBytes := lOutHdr.dim[1]*lOutHdr.dim[2]*lOutHdr.dim[3]*(lOutHdr.bitpix div 8);
-   GetMem(lBuffer,lVolBytes);
-   //lSingleNIIFile := true;
-   if UpCaseExt(lHdrName) ='.HDR' then begin
-       //lSingleNIIFile := false;
-       lImgName :=  changefileext(lHdrName,'.img')
-   end else
-       lImgName := lHdrName;
-   if not fileexists(lImgName) then begin
-       Msg('4D->3D Error: Unable to find '+lImgName);
-       exit;
-   end;
-   if FSize (lImgName) < ( (lVolBytes*lHdr.dim[4])+round(lHdr.vox_offset)) then begin
-       Msg('4D->3D Error: File smaller than expected (can not convert compressed) '+lImgName);
-       exit;
-   end;
-   //Msg(inttostr(round(lHdr.vox_offset)));
-   AssignFile(lInF, lImgName);
-   Reset(lInF,1);
-   Seek(lInF,round(lHdr.vox_offset));
-   if not lSingleNiiFile then begin
-       lGZi := false;
-       lHdrName :=  changefileext(lHdrName,'.hdr');
-       lImgName :=  changefileext(lHdrName,'.img');
-   end else begin
-       lHdrName :=  changefileext(lHdrName,'.nii');
-       lImgName :=  changefileext(lHdrName,'.nii');
-   end;
-   for lVol := 1 to lHdr.dim[4] do begin
-       //1st - save header
-       lOutName := AddFileNum(lVol,lHdr.dim[4],lHdrName);
-       SaveHdr (lOutName,lOutHdr,lByteSwap {false},lSPM2);
-       Filemode := 0;  //ReadONly
-       BlockRead(lInF, lBuffer^, lVolBytes);
-
-       lOutName := AddFileNum(lVol,lHdr.dim[4],lImgName);
-       Filemode := 2;
-       AssignFile(lOutF, lOutName);
-       if (lSingleNIIFile) and (not lSPM2) then begin
-		Reset(lOutF,1);
-		Seek(lOutF,352);
-       end else
-		Rewrite(lOutF,1);
-       BlockWrite(lOutF, lBuffer^, lVolBytes);
-       CloseFile(lOutF);
-       if lGZi then begin
-          GZipFile(lOutName,lOutName+'.gz',true);
-          //DeleteFile(lOutName);
-       end;
-   end;
-   CloseFile(lInF);
-   Freemem(lBuffer);
-   //if lDeleteOrig then begin
-      DeleteFile(lHdrName);
-      if not lSingleNIIFile then
-         DeleteFile(lImgName);
-   //end;
-end;       *)
-
-
-end.
diff --git a/dcm2nii_prePARRECDTI/nii_4dto3d.pas b/dcm2nii_prePARRECDTI/nii_4dto3d.pas
deleted file mode 100755
index f2757f1..0000000
--- a/dcm2nii_prePARRECDTI/nii_4dto3d.pas
+++ /dev/null
@@ -1,458 +0,0 @@
-unit nii_4dto3d;
-{$H+}
-
-
-interface
-
-uses
-{$IFDEF FPC}gzio2,{$ENDIF}
-  SysUtils,define_types,dicomtypes,niftiutil,prefs,nii_orient,nii_crop;
-
-//function Convert4Dto3D(var lHdrName: string; var lHdr: TNIFTIhdr; lByteSwap,lSPM2in,lSingleNIIFile,lGZ :boolean ): boolean;
-//function Clip4D(var lHdrName: string; var lHdr: TNIFTIhdr; lByteSwap,lSPM2in,lSingleNIIFile,lGZ,lOverwrite: boolean; lStartIn,lEndIn: integer ): string;
-function ModifyAnalyze(lFilename: string; lPrefs: TPrefs): boolean;
-function Clip4D(var lHdrName: string; var lHdr: TNIFTIhdr;lOverwrite: boolean; lPrefs: TPrefs; lStartIn,lEndIn: integer): string;
-//function Reorder4D(var lHdrName: string; var lHdr: TNIFTIhdr; lByteSwap,lSPM2in,lSingleNIIFile,lGZ,lOverwrite: boolean): boolean;
-function Reorder4D(var lHdrName: string; var lHdr: TNIFTIhdr; lOverwrite: boolean; lPrefs: TPrefs): boolean;
-
-implementation
-uses dialogsx;
-
-
-
-
-function ModifyAnalyze(lFilename: string; lPrefs: TPrefs): boolean;
-var
-   lExt,lOutname: string;
-   lHdr: TNIFTIhdr;
-   lFormat,lStartIn,lEndIn, lMinStartIn: integer;
-   lByteSwap,lReorder: boolean;
-   lPref: TPrefs;
-begin
-    lPref := lPrefs;
-     result := false;
-            lStartIn := 0;
-            lEndIn := 0;
-            lReorder := false;
-     lExt := UpCaseExt(lFilename);
-     if not NIFTIhdr_LoadHdr (lFilename, lHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lFilename);
-        exit;
-     end;
-     if lPrefs.AutoCrop then begin
-        Msg('Autocrop NIfTI/Analyze image '+lFileName);
-        lOutname := Reorient(lFilename,lHdr, lPrefs,false,false);
-        if lOutname <> '' then
-           CropNIfTI(lOutname,lPrefs);
-         exit;
-     end;
-     Msg('Adjusting NIfTI/Analyze image '+lFileName);
-     if (lHdr.dim[4] > 1) then begin //if 4D input
-      if (lPrefs.BeginClip > 0) and (lPrefs.BeginClip < lHdr.dim[4]) then begin
-        lStartIn := lPrefs.BeginClip;
-        Msg('Warning: removing first '+inttostr(lStartIn) + ' volumes (preference: BeginClip)');
-      end;
-      if (lStartIn <> lPrefs.BeginClip) then
-        Msg('Warning preference BeginClip is being ignored (not enough volumes)');
-      if (lPrefs.LastClip > 0)  and ( (lPrefs.LastClip+ lPrefs.BeginClip) < lHdr.dim[4]) then begin
-        lEndIn := lPrefs.LastClip;
-        Msg('Warning: removing final '+inttostr(lEndIn) + ' volumes (preference: LastClip)');
-      end;
-      if (lEndIn <> lPrefs.LastClip) then
-        Msg('Warning preference LastClip is being ignored (not enough volumes)');
-     end;//if 4D input
-     //next - determine output format
-     if not lPref.ManualNiFtiConv then begin
-        lReorder := false;
-     end else begin //manually specify conversion parameters
-        lFormat := GetInt('Output: 0=spm2,1=spm5,2=spm8,3=hdr4D,4=fsl,5=fsl.gz ', 0,DefaultOutputFormat (lPrefs),5);
-        SetOutputFormat(lFormat,lPref); //: 0=SPM2,1=SPM5,2=spm8,3=4D hdr/img,4=fsl(default),5=fsl.gz
-
-
-(*        if (lFormat <= 0) then
-           lPref.SPM2 := true
-        else
-            lPref.SPM2 := false;
-        if (lFormat <= 1) then //0,1 = hdr/img pairs
-           lPref.singleNIIfile := false
-        else //>1 = .nii
-             lPref.singleNIIfile := true;
-        if (lFormat <= 2) then //0,1,2 = 3D output
-           lPref.fourD := false
-        else //>2 = 4D
-             lPref.fourD  := true;
-        if (lFormat >= 4) then
-           lPref.GZip := true
-        else
-            lPref.GZip := false; *)
-        //next - 4D images: clip ends or flip order
-        if lHdr.dim[4] > 1 then begin //4D file
-           if (lHdr.dim[4] > 1) and (lHdr.dim[3] > 1) then begin
-              Msg('  Enter a value of -1 to flip 3rd and 4th dimensions.');
-              lMinStartIn := -1;
-           end else
-               lMinStartIn := 0;
-           lStartIn := GetInt('Enter volumes to remove from start ', lMinStartIn,lStartIn,lHdr.dim[4]);
-           if lStartIn >= 0 then
-              lEndIn := GetInt('Enter volumes to remove from end ' ,0,lEndIn,lHdr.dim[4]);
-           if ((lStartIn < 0) or (lEndIn < 0)) and (lHdr.dim[4] > 1) and (lHdr.dim[3] > 1) then
-              lReorder := true
-           else
-               lReorder := false;
-           if lHdr.dim[4] <= (lStartIn+lEndIn) then begin
-              Msg('Clip Analyze aborted: unable to remove this many volumes.');
-              exit;
-           end;
-        end;(* else begin //not 4D file
-            l4Dto3D := false;
-            lStartIn := 0;
-            lEndIn := 0;
-            lReorder := false;
-        end;//if 4D else    *)
-     end; //manual specification of conversion
-     //
-
-(*     if lExt = '.NII.GZ' then begin
-        //lTempName := lFilename;//ChangeFilePrefixExt (lFileName,'x');
-        ExtractFileParts (lFileName, lNameWOExt,lExt);
-        lTempName := lNameWOExt+'.nii';
-        Gunzip(lFileName,lTempName);
-        //Msg('Unzip '+lFilename+'->'+lTempName);
-        lFilename := lTempName;
-     end else //not gzip
-         lTempName := '';   *)
-     //Next create reordered or trimmed image in the correct format
-
-     if lReorder then begin
-       if not Reorder4D(lFileName, lHdr, false,lPref) then exit;
-       //if not Reorder4D(lFileName, lHdr, lByteSwap,lSPM2,lSingleFile,lGZ, false) then exit;
-     end else if (lStartIn=0) and (lEndIn= 0) then begin
-         if  not ChangeNIfTISubformat(lFileName, lHdr,lPref) then begin
-            Msg('Error changing format!');
-            exit;
-         end;
-     end else begin
-       if  Clip4D(lFileName, lHdr, false,lPref,lStartIn,lEndIn)='' then exit;
-     end;
-     result := true;
-
-end;
-
-function Clip4D(var lHdrName: string; var lHdr: TNIFTIhdr;lOverwrite: boolean; lPrefs: TPrefs; lStartIn,lEndIn: integer): string;
-var
-   lImgBuffer: byteP;
-   lImgOffset: integer;
-   lOutImgName: string;
-   lByteSwap: boolean;
-begin
-   result := '';
-   if not NIFTIhdr_LoadImg (lHdrName, lHdr, lImgBuffer, lImgOffset,lByteSwap) then  exit;
-   Msg('4D Clipping '+lHdrName);
-   lOutImgName := ChangeFilePrefix (lHdrName,'f');
-   result := SaveNIfTICoreCrop (lOutImgName, lImgBuffer, lImgOffset+1,lStartIn,lEndIn, lHdr, lPrefs,lByteSwap);
-   Freemem(lImgBuffer);
-
-end;
-
-function Reorder4D(var lHdrName: string; var lHdr: TNIFTIhdr; lOverwrite: boolean; lPrefs: TPrefs): boolean;
-var
-   lInBuffer,lOutBuffer: byteP;
-   lImgOffset,lSliceBytes,lIn3DBytes,l4DBytes,lVol,lInPos,lOutPos,lSlice: integer;
-   lOutImgName: string;
-   lOutHdr : TNIFTIhdr;
-   lByteSwap: boolean;
-begin
-   result := false;
-   if not NIFTIhdr_LoadImg (lHdrName, lHdr, lInBuffer, lImgOffset,lByteSwap) then  exit;
-   if (lHdr.dim[4] < 2) or (lHdr.dim[3] < 2) then
-      exit;
-   if lOverwrite then
-       lOutImgName := lHdrName
-   else
-       lOutImgName := ChangeFilePrefix (lHdrName,'x');
-   lOutHdr := lHdr;
-   lOutHdr.dim[3] := lHdr.dim[4];
-   lOutHdr.dim[4] := lHdr.dim[3];
-   lSliceBytes := lHdr.dim[1]*lHdr.dim[2]*(lHdr.bitpix div 8);
-   lIn3DBytes := lSliceBytes*lHdr.dim[3];
-   l4DBytes := lIn3DBytes*lHdr.dim[4];
-   Msg('Changing order of dimensions 3 and 4 of '+lHdrName);
-   GetMem(lOutBuffer,l4DBytes+kNIIImgOffset);
-   lOutPos := kNIIImgOffset + 1;
-   for lVol := 1 to  lOutHdr.dim[4] do begin
-       lInPos := ((lVol-1)*lSliceBytes) + lImgOffset+1;
-       for lSlice := 1 to lOutHdr.dim[3] do begin
-           Move(lInBuffer^[lInPos],lOutBuffer^[lOutPos],lSliceBytes);
-           lInPos := lInPos + lIn3DBytes;
-           lOutPos := lOutPos + lSliceBytes;
-       end;//for lslice
-   end; //for lvol
-   Msg(lOutImgName);
-   if  SaveNIfTICore (lOutImgName, lOutBuffer, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap) = '' then begin
-      Msg('Reorder Error');
-      Freemem(lInBuffer);
-      Freemem(lOutBuffer);
-      exit;
-   end;
-   result := true;
-end;
-
-(*function Reorder4D(var lHdrName: string; var lHdr: TNIFTIhdr; lByteSwap,lSPM2in,lSingleNIIFile,lGZ,lOverwrite: boolean): boolean;
-var
-   lOutHdr: TNIFTIhdr;
-   lInName,lImgName: string;
-   lPos,lSlice,lVol,lInVolBytes,lSliceBytes: integer;
-   lBuffer: bytep;
-   lGZi,lSPM2: boolean;
-   lOutF,lInF: File;
-begin
-   result := false;
-   lGZi := lGZ;
-   lSPM2 := lSPM2in;
-   if lSingleNIIFIle then
-      lSPM2 := false;
-   if (lHdr.dim[4] < 2) or (lHdr.dim[3] < 2) then
-      exit;
-   lOutHdr := lHdr;
-   lOutHdr.dim[4] := lHdr.dim[3];
-   lOutHdr.dim[3] := lHdr.dim[4];
-   lSliceBytes := lHdr.dim[1]*lHdr.dim[2]*(lHdr.bitpix div 8);
-   lInVolBytes := lSliceBytes*lHdr.dim[3];
-   GetMem(lBuffer,lSliceBytes);
-   if UpCaseExt(lHdrName) ='.HDR' then begin
-       if lOverwrite then
-          deletefile(lHdrName);
-       lInName :=  changefileext(lHdrName,'.img')
-   end else begin
-       lOutHdr.vox_offset := 352;
-       lInName := lHdrName;
-   end;
-   if not fileexists(lInName) then begin
-       Msg('4Dclip Error: Unable to find '+lInName);
-       exit;
-   end;
-   if FSize (lInName) < ( (lInVolBytes*lHdr.dim[4])+round(lHdr.vox_offset)) then begin
-       Msg('4Dclip Error: File smaller than expected (can not convert compressed) '+lInName);
-       exit;
-   end;
-   Msg('Reordering image');
-   if not lSingleNiiFile then begin
-       lHdrName :=  changefileext(lHdrName,'.hdr');
-       lImgName :=  changefileext(lHdrName,'.img');
-       lGZi := false;
-   end else begin
-       lHdrName :=  changefileext(lHdrName,'.nii');
-       lImgName :=  changefileext(lHdrName,'.nii');
-   end;
-   if lOverwrite then begin
-      renamefile(lInName,changefileext(lInName,'.tmp'));
-      lInName := changefileext(lInName,'.tmp');
-   end else begin
-       lHdrName := ChangeFilePrefixExt (lHdrName,'x');
-       lImgName := ChangeFilePrefixExt (lImgName,'x');
-       Msg('saving as '+lHdrName);
-   end;
-   AssignFile(lInF, lInName);
-   Reset(lInF,1);
-   Seek(lInF,round(lHdr.vox_offset));
-   SaveHdr (lHdrName,lOutHdr,lByteSwap{ false},lSPM2);
-   AssignFile(lOutF, lImgName);
-   if lSingleNIIFile then begin
-      Reset(lOutF,1);
-      Seek(lOutF,352);
-   end else
-       Rewrite(lOutF,1);
-   for lVol := 1 to  lOutHdr.dim[4] do begin
-       lPos := ((lVol-1)*lSliceBytes) + round(lHdr.vox_offset);
-       for lSlice := 1 to lOutHdr.dim[3] do begin
-           Filemode := 0;  //ReadONly
-           seek(lInF,lPos);
-           BlockRead(lInF, lBuffer^, lSliceBytes);
-           Filemode := 2;
-           BlockWrite(lOutF, lBuffer^, lSliceBytes);
-           lPos := lPos + lInVolBytes;
-       end;//for lslice
-   end; //for lvol
-   CloseFile(lInF);
-   CloseFile(lOutF);
-   Freemem(lBuffer);
-   if lOverwrite then
-      DeleteFile(lInName);
-   if lGZi then
-      GZipFile(lImgName,lImgName+'.gz',true);
-   result := true;
-end;      *)
-
-(*function Clip4D(var lHdrName: string; var lHdr: TNIFTIhdr;  lByteSwap,lSPM2in, lSingleNIIFile,lGZ,lOverwrite: boolean; lStartIn,lEndIn: integer ): string;
-var
-   lOutHdr: TNIFTIhdr;
-   lInName,lImgName: string;
-   lVol,lVolBytes,lStart,lEnd: integer;
-    lBuffer: bytep;
-    lGZi,lSPM2 : boolean;
-    lOutF,lInF: File;
-begin
-   result := '';
-   lGZi := lGZ;
-   lSPM2 := lSPM2in;
-   if lSingleNIIFIle then
-      lSPM2 := false;
-   lStart := lStartIn;
-   if lStart < 0 then
-      lStart := 0;
-   lEnd := lEndIn;
-   if lEnd < 0 then
-      lEnd := 0;
-   lOutHdr := lHdr;
-   lOutHdr.dim[4] := lOutHdr.dim[4]-lStart-lEnd;
-   if lOutHdr.dim[4] < 1 then
-      exit;
-   lVolBytes := lOutHdr.dim[1]*lOutHdr.dim[2]*lOutHdr.dim[3]*(lOutHdr.bitpix div 8);
-   GetMem(lBuffer,lVolBytes);
-   if UpCaseExt(lHdrName) ='.HDR' then begin
-       if lOverwrite then
-          deletefile(lHdrName);
-       lInName :=  changefileext(lHdrName,'.img')
-   end else begin
-       lOutHdr.vox_offset := 352;
-       lInName := lHdrName;
-   end;
-   if not fileexists(lInName) then begin
-       Msg('4Dclip Error: Unable to find '+lInName);
-       exit;
-   end;
-   if FSize (lInName) < ( (lVolBytes*lHdr.dim[4])+round(lHdr.vox_offset)) then begin
-       Msg('4Dclip Error: File smaller than expected (can not convert compressed) '+lInName);
-       exit;
-   end;
-   if (lStart > 0) or (lEnd > 0) then
-      Msg('4D clip - removing first '+inttostr(lStart)+' and last '+inttostr(lEnd) +' volumes')
-   else
-       Msg('Formatting image');
-   if not lSingleNiiFile then begin
-       lGZi := false;
-       lHdrName :=  changefileext(lHdrName,'.hdr');
-       lImgName :=  changefileext(lHdrName,'.img');
-   end else begin
-       lHdrName :=  changefileext(lHdrName,'.nii');
-       lImgName :=  changefileext(lHdrName,'.nii');
-   end;
-   if lOverwrite then begin
-      renamefile(lInName,changefileext(lInName,'.tmp'));
-      lInName := changefileext(lInName,'.tmp');
-   end else begin
-       lHdrName := ChangeFilePrefixExt (lHdrName,'x');
-       lImgName := ChangeFilePrefixExt (lImgName,'x');
-       Msg('Saving clipped as '+lHdrName);
-   end;
-   AssignFile(lInF, lInName);
-   Reset(lInF,1);
-   Seek(lInF,round(lHdr.vox_offset));
-   SaveHdr (lHdrName,lOutHdr, lByteSwap{false},lSPM2);
-   AssignFile(lOutF, lImgName);
-   if lSingleNIIFile then begin
-      Reset(lOutF,1);
-      Seek(lOutF,352);
-   end else
-       Rewrite(lOutF,1);
-   for lVol := 1 to (lHdr.dim[4]-lEnd) do begin
-       //1st - save header
-       Filemode := 0;  //ReadONly
-       BlockRead(lInF, lBuffer^, lVolBytes);
-       if (lVol > lStart) then begin
-          Filemode := 2;
-          BlockWrite(lOutF, lBuffer^, lVolBytes);
-       end;
-   end;
-   CloseFile(lInF);
-   CloseFile(lOutF);
-   Freemem(lBuffer);
-   if lOverwrite then
-      DeleteFile(lInName);
-   if lGZi then begin
-      lHdrName := lImgName+'.gz';
-      GZipFile(lImgName,lHdrName,true);
-   end;
-   result := lHdrName;
-end;
-
-function Convert4Dto3D(var lHdrName: string; var lHdr: TNIFTIhdr; lByteSwap, lSPM2in,lSingleNIIFile,lGZ: boolean ): boolean;
-var
-   lOutHdr: TNIFTIhdr;
-   lOutName,lImgName: string;
-   lVol,lVolBytes: integer;
-    lBuffer: bytep;
-    lSPM2,lGZi: boolean;
-     lOutF,lInF: File;
-begin
-   result := false;
-   lSPM2 := lSPM2in;
-   if lSingleNIIFIle then
-      lSPM2 := false;
-   lGZi := lGZ;
-   if lHdr.dim[4] < 2 then
-      exit;
-   lOutHdr := lHdr;
-   lOutHdr.dim[0] := 3;//3D
-   lOutHdr.dim[4] := 1;
-   lVolBytes := lOutHdr.dim[1]*lOutHdr.dim[2]*lOutHdr.dim[3]*(lOutHdr.bitpix div 8);
-   GetMem(lBuffer,lVolBytes);
-   //lSingleNIIFile := true;
-   if UpCaseExt(lHdrName) ='.HDR' then begin
-       //lSingleNIIFile := false;
-       lImgName :=  changefileext(lHdrName,'.img')
-   end else
-       lImgName := lHdrName;
-   if not fileexists(lImgName) then begin
-       Msg('4D->3D Error: Unable to find '+lImgName);
-       exit;
-   end;
-   if FSize (lImgName) < ( (lVolBytes*lHdr.dim[4])+round(lHdr.vox_offset)) then begin
-       Msg('4D->3D Error: File smaller than expected (can not convert compressed) '+lImgName);
-       exit;
-   end;
-   //Msg(inttostr(round(lHdr.vox_offset)));
-   AssignFile(lInF, lImgName);
-   Reset(lInF,1);
-   Seek(lInF,round(lHdr.vox_offset));
-   if not lSingleNiiFile then begin
-       lGZi := false;
-       lHdrName :=  changefileext(lHdrName,'.hdr');
-       lImgName :=  changefileext(lHdrName,'.img');
-   end else begin
-       lHdrName :=  changefileext(lHdrName,'.nii');
-       lImgName :=  changefileext(lHdrName,'.nii');
-   end;
-   for lVol := 1 to lHdr.dim[4] do begin
-       //1st - save header
-       lOutName := AddFileNum(lVol,lHdr.dim[4],lHdrName);
-       SaveHdr (lOutName,lOutHdr,lByteSwap {false},lSPM2);
-       Filemode := 0;  //ReadONly
-       BlockRead(lInF, lBuffer^, lVolBytes);
-
-       lOutName := AddFileNum(lVol,lHdr.dim[4],lImgName);
-       Filemode := 2;
-       AssignFile(lOutF, lOutName);
-       if (lSingleNIIFile) and (not lSPM2) then begin
-		Reset(lOutF,1);
-		Seek(lOutF,352);
-       end else
-		Rewrite(lOutF,1);
-       BlockWrite(lOutF, lBuffer^, lVolBytes);
-       CloseFile(lOutF);
-       if lGZi then begin
-          GZipFile(lOutName,lOutName+'.gz',true);
-          //DeleteFile(lOutName);
-       end;
-   end;
-   CloseFile(lInF);
-   Freemem(lBuffer);
-   //if lDeleteOrig then begin
-      DeleteFile(lHdrName);
-      if not lSingleNIIFile then
-         DeleteFile(lImgName);
-   //end;
-end;       *)
-
-
-end.
diff --git a/dcm2nii_prePARRECDTI/nii_asl.pas b/dcm2nii_prePARRECDTI/nii_asl.pas
deleted file mode 100755
index a2595d8..0000000
--- a/dcm2nii_prePARRECDTI/nii_asl.pas
+++ /dev/null
@@ -1,605 +0,0 @@
-unit nii_asl;
-//tools for Arterial spin labeling...
-{$H+}
-
-
-interface
-
-uses
-{$IFDEF FPC}gzio2,{$ENDIF}
-  SysUtils,define_types,dicomtypes,niftiutil,prefs;
-
-function ASL_subtract(var lHdrName: string;  lOverwrite: boolean; lFunction : integer; lPrefs: TPrefs): boolean;
-//ASL_subtract(var lHdrName: string;  lOverwrite: boolean; lFunction : integer; lPrefs: TPrefs)
-
-implementation
-uses dialogsx,gui,dialogs;
-
-function Parse (var lNumStr: string; var Val1,Val2: integer): boolean;
-var
-   lS: string;
-   lLen,lP: integer;
-begin
-    Val1 := 0;
-    Val2 := 0;
-    result := false;
-    lLen := length(lNumStr);
-    if lLen < 3 then exit;
-    lS := '';
-    lP := 1;
-    while (lP <= lLen) and (lNumStr[lP] <> ',') do begin
-          lS := lS + lNumStr[lP];
-          inc(lP);
-    end;
-    if lS = '' then
-       exit;
-    try
-       Val1 := strtoint(lS);
-    except
-          Msg('Error converting text to number '+lS);
-    end;
-    //next number
-    inc(lP);
-    lS := '';
-    while (lP <= lLen) and (lNumStr[lP] <> ',') do begin
-          lS := lS + lNumStr[lP];
-          inc(lP);
-    end;
-    if lS = '' then
-       exit;
-    try
-       Val2 := strtoint(lS);
-    except
-          Msg('Error converting text to number '+lS);
-    end;
-    result := true;
-end;
-
-function readCSV (lFilename: string;  var lnObservations: integer; var lPosRA,lNegRA: LongIntp): boolean;
-var
-   lNumStr: string;
-   F: TextFile;
-   R,A,B,C: integer;
-begin
-     lnObservations := 0;
-     result := false;
-     if not fileexists(lFilename) then exit;
-     AssignFile(F, lFilename);
-     FileMode := 0;  //Set file access to read only
-     //First pass: determine column height/width
-     Reset(F);
-     R := 0;
-     while (not Eof(F))  do begin
-           Readln(F,lNumStr);
-           if Parse(lNumStr,A,B) then
-              inc(R);
-     end;
-     if (R < 1)  then begin
-         msg('problems reading CSV: must have at least 2 columns and 1 row.');
-         exit;
-     end;
-     lnObservations := R;
-     Getmem(lPosRA,lnObservations*sizeof(integer));
-     Getmem(lNegRA,lnObservations*sizeof(integer));
-     for R := 1 to lnObservations do begin
-         lPosRA^[R] := -1;
-         lNegRA^[R] := -1;
-     end;
-     //second pass
-     Reset(F);
-     C := 0;
-     while (not Eof(F)) and (C<lnObservations) do begin
-           Readln(F,lNumStr);
-           if Parse(lNumStr,A,B ) then begin
-               inc(C);
-               lPosRA^[C] := A;
-               lNegRA^[C] := B;
-           end;
-     end;
-     CloseFile(F);
-	 FileMode := 2;  //Set file access to read/write
-         result := true;
-end;
-//start 32-bit float versions
-function SaveMean32 (var lHdrName: string;var lInHdr: TNIFTIhdr; lBuffAligned: bytep;lImgBuffer : SingleP ;lPrefs: TPrefs; lByteSwap:boolean ): string;
-var
-   lOutHdr : TNIFTIhdr;
-   lOutImgName: string;
-   lVol,lOutVolOffset,lInc,lImgSamples: integer;
-   lSum: double;
-begin
-     result := '';
-     lOutHdr := lInHdr;
-     lImgSamples := lOutHdr.dim[1]*lOutHdr.dim[2]*lOutHdr.dim[3];
-     if (lImgSamples < 1) or (lInHdr.dim[4] < 1) then
-        exit;
-   //next make mean
-   lOutImgName := ChangeFilePrefix (lHdrName,'mean');
-   for lInc := 1 to lImgSamples do  begin
-       lSum := 0;
-       lOutVolOffset := 0;
-       for lVol := 1 to  lInHdr.dim[4] do begin
-           lSum := lSum+lImgBuffer^[lOutVolOffset+lInc];
-           lOutVolOffset := lOutVolOffset+lImgSamples;
-       end;
-       lImgBuffer^[lInc] :=  (lSum /lOutHdr.dim[4]);
-   end;
-
-   lOutHdr.dim[4] := 1;
-   result :=  SaveNIfTICore (lOutImgName, lBuffAligned, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-end; //SaveMean32
-
-
-function ASL_subtract32(var lHdrName: string; lOverwrite: boolean; lFunction : integer; lPrefs: TPrefs): boolean;
-//lFunction :
-//0 = Subtract (even-odd)
-//1= Subtract (odd-even)
-//2= Subtract custom
-//3= Add (odd+even) BOLD
-//4= Parse OddEven  aka SplitOddEven
-//for odd/even, first scan is odd (1), second scan is even (2) [indexed from 1]
-label
- 666;
-var
-   lPosRA,lNegRA: LongIntp;
-   lImgOffset,lVol,lInVolOddOffset,lInVolEvenOffset,lOutVolOffset,
-   lImgSamples,l4DVox,lInc: integer;
-   lCSVname,lResultStr,lOutImgName: string;
-   lInHdr, lOutHdr : TNIFTIhdr;
-   lSplitOddEven,lCustom,lSubtract,lOddMinusEven,lByteSwap: boolean;
-   lBuffer,lSrcBuffer, lBuffUnaligned,lBuffAligned: bytep;
-   lOdd,lEven: single;
-   lOddVol,lEvenVol: integer;
-   lImgBuffer,l32Buf : SingleP;
-   //lSum: double;
-begin
-     lSplitOddEven := lFunction = 4;
-     lCustom := lFunction = 2;
-     lOddMinusEven := lFunction = 1;
-     lSubtract := (lFunction <> 3);
-   result := false;
-     if not NIFTIhdr_LoadHdr (lHdrName, lInHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lHdrName);
-        exit;
-     end;
-   case lInHdr.datatype of
-     {kDT_UNSIGNED_CHAR,kDT_SIGNED_SHORT,kDT_UINT16, kDT_SIGNED_INT,}kDT_FLOAT:;//Supported
-     else begin
-         Msg('Error with ASL_subtract: image format must be 32-bit floating point values.');
-         exit;
-     end;
-   end;//case headertype
-   if (odd(lInHdr.dim[4])) or (lInHdr.dim[4] < 2) then begin
-      Msg('ASL routines require an even number of volumes');
-      exit;
-   end;
-
-   if not NIFTIhdr_LoadImg (lHdrName, lInHdr, lSrcBuffer, lImgOffset,lByteSwap) then  exit;
-   lBuffer := (@lSrcBuffer^[lImgOffset+1]);
-   l32Buf := SingleP(lBuffer );
-   if lOverwrite then
-       lOutImgName := lHdrName
-   else begin
-        if lSplitOddEven then
-          lOutImgName := ChangeFilePrefix (lHdrName,'odd')
-       else if lSubtract then begin
-          if lCustom then
-              lOutImgName := ChangeFilePrefix (lHdrName,'subc')
-          else if lOddMinusEven then
-              lOutImgName := ChangeFilePrefix (lHdrName,'subome')
-          else
-              lOutImgName := ChangeFilePrefix (lHdrName,'subemo')
-       end else
-          lOutImgName := ChangeFilePrefix (lHdrName,'add');
-   end;
-   lOutHdr := lInHdr;
-   lOutHdr.dim[4] := lInHdr.dim[4] div 2;
-   lOutHdr.pixdim[4] := 2 * lInHdr.pixdim[4];
-   lImgSamples := lOutHdr.dim[1]*lOutHdr.dim[2]*lOutHdr.dim[3];
-   l4DVox := lImgSamples * lOutHdr.dim[4];
-   //l3DBytes := l3DVox*(lOutHdr.bitpix div 8);
-   //l4DBytes := l3DBytes*lOutHdr.dim[4];
-   if lCustom then
-         lResultStr := 'Custom subtraction'
-   else if lSubtract then begin
-      if lOddMinusEven then
-         lResultStr := 'Subtract Odd-Even'
-      else
-         lResultStr := 'Subtract Even-Odd';
-   end else
-       lResultStr := 'Add Odd+Even';
-   Msg('Computing '+lResultStr+'  '+lHdrName);
-   lResultStr := ''; //assume error
-   GetMem(lBuffUnaligned ,(sizeof(single)*l4DVox) + 16+kNIIImgOffset);
-   {$IFDEF FPC}
-    lBuffAligned := Align(lBuffUnaligned,16); // not commented - check this
-   {$ELSE}
-   lBuffAligned := ByteP($fffffff0 and (integer(lBuffUnaligned)+15));
-   {$ENDIF}
-   lInc := 1;
-   lImgBuffer := SingleP(@lBuffAligned^[kNIIImgOffset+lInc]);
-   if lByteSwap then
-      for lInc := 1 to l4DVox do
-          pswap4r(l32Buf^[lInc]);  //faster as procedure than function see www.optimalcode.com
-
-   if lSplitOddEven then begin
-   //compute odd
-   for lVol := 1 to  lOutHdr.dim[4] do begin
-       lOutVolOffset := (lVol -1) * lImgSamples;
-       //lInVolEvenOffset := ((lVol*2) -1) * lImgSamples; //second, fourth
-       lInVolOddOffset := ((lVol*2) -2) * lImgSamples; //first, thired
-       for lInc := 1 to lImgSamples do  begin
-               lOdd := l32Buf^[lInVolOddOffset+lInc];
-               //lEven := l16Buf^[lInVolEvenOffset+lInc];
-               lImgBuffer^[lOutVolOffset+lInc] := lOdd;
-       end; //for lImgSamples
-   end; //for lvol
-   lresultStr :=  SaveNIfTICore (lOutImgName, lBuffAligned, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-   lresultStr :=  SaveMean32 (lOutImgName, lOutHdr, lBuffAligned,lImgBuffer,lPrefs,lByteSwap);
-   //compute even
-   lOutImgName := ChangeFilePrefix (lHdrName,'even');
-   for lVol := 1 to  lOutHdr.dim[4] do begin
-       lOutVolOffset := (lVol -1) * lImgSamples;
-       lInVolEvenOffset := ((lVol*2) -1) * lImgSamples; //second, fourth
-       //lInVolOddOffset := ((lVol*2) -2) * lImgSamples; //first, thired
-       for lInc := 1 to lImgSamples do  begin
-               //lOdd := l16Buf^[lInVolOddOffset+lInc];
-               lEven := l32Buf^[lInVolEvenOffset+lInc];
-               lImgBuffer^[lOutVolOffset+lInc] := lEven;
-       end; //for lImgSamples
-   end; //for lvol
-end else if lCustom then begin //not lSplitOddEven .. if Custom
-   Msg('Select a comma separated text file that describes how to subtract images.');
-   Msg('For example, to subtract a six volume dataset your file could be:');
-   Msg('1,6');
-   Msg('2,5');
-   Msg('3,4');
-   Msg('The first output volume would be the first input volume minus the sixth');
-   Msg('The second output volume would be the second input volume minus the fifth');
-   Msg('The final output volume would be the third input volume minus the fourth');
-   Msg('Your file should have '+inttostr(lOutHdr.dim[4])+' lines, one for each output volume');
-
-   if not MainForm.OpenDialogExecute('Select NIfTI images you wish to modify)',true,false,kTxtFilter) then
-    goto 666;
-   lCSVName := MainForm.OpenHdrDlg.Filename;
-   //MainForm.BrowseDialog('Choose collapase file
-   if not readCSV (lCSVname, lVol, lPosRA,lNegRA) then
-      goto 666;
-   if lVol < lOutHdr.dim[4] then begin
-      Msg ('Only found '+inttostr(lVol)+' contrasts in '+ lCSVName+' a total of '+inttostr(lOutHdr.dim[4])+' required');
-      freemem(lPosRA);
-      freemem(lNegRA);
-      goto 666;
-   end;
-   for lVol := 1 to  lOutHdr.dim[4] do begin
-       lOutVolOffset := (lVol -1) * lImgSamples;
-       lEvenVol := lNegRA^[lVol];
-       lOddVol := lPosRA^[lVol];
-       if (lEvenVol > 0) and (lOddVol > 0) and (lEvenVol <= lInHdr.dim[4]) and (lOddVol <= lInHdr.dim[4]) then begin
-          Msg (inttostr(lVol) +' = '+inttostr(lOddVol)+' - '+inttostr(lEvenVol) );
-          lInVolEvenOffset := (lEvenVol -1) * lImgSamples;
-          lInVolOddOffset := (lOddVol -1) * lImgSamples;
-          for lInc := 1 to lImgSamples do  begin
-               lOdd := l32Buf^[lInVolOddOffset+lInc];
-               lEven := l32Buf^[lInVolEvenOffset+lInc];
-               lImgBuffer^[lOutVolOffset+lInc] := lOdd - lEven;
-          end; //each voxel in volume
-       end else begin
-          Msg ('Error: volumes out of range '+inttostr(lVol) +' = '+inttostr(lOddVol)+' - '+inttostr(lEvenVol) );
-       end;
-   end; //for lvol
-      freemem(lPosRA);
-      freemem(lNegRA);
-end else begin  //not custom  or lSplitOddEven
-   for lVol := 1 to  lOutHdr.dim[4] do begin
-       lOutVolOffset := (lVol -1) * lImgSamples;
-       lInVolEvenOffset := ((lVol*2) -1) * lImgSamples; //second, fourth
-       lInVolOddOffset := ((lVol*2) -2) * lImgSamples; //first, thired
-       if lSubtract then begin
-          if lOddMinusEven then begin
-             for lInc := 1 to lImgSamples do  begin
-               lOdd := l32Buf^[lInVolOddOffset+lInc];
-               lEven := l32Buf^[lInVolEvenOffset+lInc];
-               lImgBuffer^[lOutVolOffset+lInc] := lOdd - lEven;
-             end; //for lImgSamples
-          end else begin //not lOddMinusEven
-             for lInc := 1 to lImgSamples do  begin
-               lOdd := l32Buf^[lInVolOddOffset+lInc];
-               lEven := l32Buf^[lInVolEvenOffset+lInc];
-               lImgBuffer^[lOutVolOffset+lInc] := lEven-lOdd;
-             end; //for lImgSamples
-          end; //if else lOddMinusEven
-       end else begin //not subtract... add
-           for lInc := 1 to lImgSamples do  begin
-               lOdd := l32Buf^[lInVolOddOffset+lInc];
-               lEven := l32Buf^[lInVolEvenOffset+lInc];
-               lImgBuffer^[lOutVolOffset+lInc] := lOdd + lEven;
-           end; //for lImgSamples
-       end; //add
-   end; //for lvol
-end;
-   lresultStr :=  SaveNIfTICore (lOutImgName, lBuffAligned, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-   //next make mean
-   lresultStr :=  SaveMean32 (lOutImgName, lOutHdr, lBuffAligned,lImgBuffer,lPrefs,lByteSwap);
-666:
-   Freemem(lSrcBuffer);
-   Freemem(lBuffUnaligned);
-   if lResultStr = '' then //error - do not report success
-      exit;
-   result := true;
-end; //ASL_subtract32
-//end 32bit versions
-
-
-function SaveMean (var lHdrName: string;var lInHdr: TNIFTIhdr; lInBuffer : SmallIntP; lPrefs: TPrefs; lByteSwap:boolean ): string;
-var
-   lOutHdr : TNIFTIhdr;
-   lOutImgName: string;
-   lVol,lOutVolOffset,lInc,lImgSamples: integer;
-   lSum: double;
-   lBuffUnaligned,lBuffAligned: bytep;
-   lImgBuffer: Singlep;
-begin
-     result := '';
-     lOutHdr := lInHdr;
-     lImgSamples := lOutHdr.dim[1]*lOutHdr.dim[2]*lOutHdr.dim[3];
-     if (lImgSamples < 1) or (lInHdr.dim[4] < 1) then
-        exit;
-   GetMem(lBuffUnaligned ,(sizeof(single)*lImgSamples) + 16+kNIIImgOffset);
-   {$IFDEF FPC}
-    lBuffAligned := Align(lBuffUnaligned,16); // not commented - check this
-   {$ELSE}
-   lBuffAligned := ByteP($fffffff0 and (integer(lBuffUnaligned)+15));
-   {$ENDIF}
-   lInc := 1;
-   lImgBuffer := SingleP(@lBuffAligned^[kNIIImgOffset+lInc]);
-   //next make mean
-   lOutImgName := ChangeFilePrefix (lHdrName,'mean');
-   for lInc := 1 to lImgSamples do  begin
-       lSum := 0;
-       lOutVolOffset := 0;
-       for lVol := 1 to  lInHdr.dim[4] do begin
-           lSum := lSum+lInBuffer^[lOutVolOffset+lInc];
-           lOutVolOffset := lOutVolOffset+lImgSamples;
-       end;
-       lImgBuffer^[lInc] :=  (lSum /lOutHdr.dim[4]);
-   end;
-
-   lOutHdr.dim[4] := 1;
-   lOutHdr.datatype := kDT_FLOAT;
-   lOutHdr.bitpix := 32;
-   result :=  SaveNIfTICore (lOutImgName, lBuffAligned, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-   freemem( lBuffUnaligned);
-end; //SaveMean
-
-(*function SaveMean (var lHdrName: string;var lInHdr: TNIFTIhdr; lBuffAligned: bytep;lImgBuffer : SmallIntP;lPrefs: TPrefs; lByteSwap:boolean ): string;
-var
-   lOutHdr : TNIFTIhdr;
-   lOutImgName: string;
-   lVol,lOutVolOffset,lInc,lImgSamples: integer;
-   lSum: double;
-begin
-     result := '';
-     lOutHdr := lInHdr;
-     lImgSamples := lOutHdr.dim[1]*lOutHdr.dim[2]*lOutHdr.dim[3];
-     if (lImgSamples < 1) or (lInHdr.dim[4] < 1) then
-        exit;
-   //next make mean
-   lOutImgName := ChangeFilePrefix (lHdrName,'mean');
-   for lInc := 1 to lImgSamples do  begin
-       lSum := 0;
-       lOutVolOffset := 0;
-       for lVol := 1 to  lInHdr.dim[4] do begin
-           lSum := lSum+lImgBuffer^[lOutVolOffset+lInc];
-           lOutVolOffset := lOutVolOffset+lImgSamples;
-       end;
-       lImgBuffer^[lInc] :=  round(lSum /lOutHdr.dim[4]);
-   end;
-
-   lOutHdr.dim[4] := 1;
-   result :=  SaveNIfTICore (lOutImgName, lBuffAligned, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-end; //SaveMean*)
-
-function ASL_subtract(var lHdrName: string; lOverwrite: boolean; lFunction : integer; lPrefs: TPrefs): boolean;
-//lFunction :
-//0 = Subtract (even-odd)
-//1= Subtract (odd-even)
-//2= Subtract custom
-//3= Add (odd+even) BOLD
-//4= Parse OddEven  aka SplitOddEven
-//for odd/even, first scan is odd (1), second scan is even (2) [indexed from 1]
-label
- 666;
-var
-   lPosRA,lNegRA: LongIntp;
-   lImgOffset,lVol,lInVolOddOffset,lInVolEvenOffset,lOutVolOffset,
-   lOddVol,lEvenVol: integer;
-   lImgSamples,l4DVox,lInc: integer;
-   lCSVname,lResultStr,lOutImgName: string;
-   lInHdr, lOutHdr : TNIFTIhdr;
-   lSplitOddEven,lCustom,lSubtract,lOddMinusEven,lByteSwap: boolean;
-   lBuffer,lSrcBuffer, lBuffUnaligned,lBuffAligned: bytep;
-   lOdd,lEven: integer;
-   lImgBuffer,l16Buf : SmallIntP;
-   //lSum: double;
-begin
-     lSplitOddEven := lFunction = 4;
-     lCustom := lFunction = 2;
-     lOddMinusEven := lFunction = 1;
-     lSubtract := (lFunction <> 3);
-   result := false;
-     if not NIFTIhdr_LoadHdr (lHdrName, lInHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lHdrName);
-        exit;
-     end;
-   case lInHdr.datatype of
-     {kDT_UNSIGNED_CHAR,}kDT_SIGNED_SHORT{,kDT_UINT16, kDT_SIGNED_INT,kDT_FLOAT}:;//Supported
-     kDT_FLOAT: begin
-                result := ASL_subtract32(lHdrName,lOverwrite,lFunction,lPrefs);
-                exit;                   
-     end;//kDT_FLOAT
-     else begin
-         Msg('Error with ASL_subtract: image format must be 16-bit signed integers.');
-         exit;
-     end;
-   end;//case headertype
-   if (odd(lInHdr.dim[4])) or (lInHdr.dim[4] < 2) then begin
-      Msg('ASL routines require an even number of volumes');
-      exit;
-   end;
-
-   if not NIFTIhdr_LoadImg (lHdrName, lInHdr, lSrcBuffer, lImgOffset,lByteSwap) then  exit;
-   lBuffer := (@lSrcBuffer^[lImgOffset+1]);
-   l16Buf := SmallIntP(lBuffer );
-   if lOverwrite then
-       lOutImgName := lHdrName
-   else begin
-        if lSplitOddEven then
-          lOutImgName := ChangeFilePrefix (lHdrName,'odd')
-       else if lSubtract then begin
-          if lCustom then
-              lOutImgName := ChangeFilePrefix (lHdrName,'subc')
-          else if lOddMinusEven then
-              lOutImgName := ChangeFilePrefix (lHdrName,'subome')
-          else
-              lOutImgName := ChangeFilePrefix (lHdrName,'subemo')
-       end else
-          lOutImgName := ChangeFilePrefix (lHdrName,'add');
-   end;
-   lOutHdr := lInHdr;
-   lOutHdr.dim[4] := lInHdr.dim[4] div 2;
-   lOutHdr.pixdim[4] := 2 * lInHdr.pixdim[4];
-   lImgSamples := lOutHdr.dim[1]*lOutHdr.dim[2]*lOutHdr.dim[3];
-   l4DVox := lImgSamples * lOutHdr.dim[4];
-   //l3DBytes := l3DVox*(lOutHdr.bitpix div 8);
-   //l4DBytes := l3DBytes*lOutHdr.dim[4];
-   if lCustom then
-         lResultStr := 'Custom subtraction'
-   else if lSubtract then begin
-      if lOddMinusEven then
-         lResultStr := 'Subtract Odd-Even'
-      else
-         lResultStr := 'Subtract Even-Odd';
-   end else
-       lResultStr := 'Add Odd+Even';
-   Msg('Computing '+lResultStr+'  '+lHdrName);
-   lResultStr := ''; //assume error
-   GetMem(lBuffUnaligned ,(sizeof(smallint)*l4DVox) + 16+kNIIImgOffset);
-   {$IFDEF FPC}
-    lBuffAligned := Align(lBuffUnaligned,16); // not commented - check this
-   {$ELSE}
-   lBuffAligned := ByteP($fffffff0 and (integer(lBuffUnaligned)+15));
-   {$ENDIF}
-   lInc := 1;
-   lImgBuffer := SmallIntP(@lBuffAligned^[kNIIImgOffset+lInc]);
-   if lByteSwap then
-      for lInc := 1 to l4DVox do
-          l16Buf^[lInc]  := Swap(l16Buf^[lInc]) ;
-if lSplitOddEven then begin
-   //compute odd
-   for lVol := 1 to  lOutHdr.dim[4] do begin
-       lOutVolOffset := (lVol -1) * lImgSamples;
-       //lInVolEvenOffset := ((lVol*2) -1) * lImgSamples; //second, fourth
-       lInVolOddOffset := ((lVol*2) -2) * lImgSamples; //first, thired
-       for lInc := 1 to lImgSamples do  begin
-               lOdd := l16Buf^[lInVolOddOffset+lInc];
-               //lEven := l16Buf^[lInVolEvenOffset+lInc];
-               lImgBuffer^[lOutVolOffset+lInc] := lOdd;
-       end; //for lImgSamples
-   end; //for lvol
-   lresultStr :=  SaveNIfTICore (lOutImgName, lBuffAligned, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-   lresultStr :=  SaveMean (lOutImgName, lOutHdr, lImgBuffer,lPrefs,lByteSwap);
-   //compute even
-   lOutImgName := ChangeFilePrefix (lHdrName,'even');
-   for lVol := 1 to  lOutHdr.dim[4] do begin
-       lOutVolOffset := (lVol -1) * lImgSamples;
-       lInVolEvenOffset := ((lVol*2) -1) * lImgSamples; //second, fourth
-       //lInVolOddOffset := ((lVol*2) -2) * lImgSamples; //first, thired
-       for lInc := 1 to lImgSamples do  begin
-               //lOdd := l16Buf^[lInVolOddOffset+lInc];
-               lEven := l16Buf^[lInVolEvenOffset+lInc];
-               lImgBuffer^[lOutVolOffset+lInc] := lEven;
-       end; //for lImgSamples
-   end; //for lvol
-end else if lCustom then begin //not lSplitOddEven .. if Custom
-   Msg('Select a comma separated text file that describes how to subtract images.');
-   Msg('For example, to subtract a six volume dataset your file could be:');
-   Msg('1,6');
-   Msg('2,5');
-   Msg('3,4');
-   Msg('The first output volume would be the first input volume minus the sixth');
-   Msg('The second output volume would be the second input volume minus the fifth');
-   Msg('The final output volume would be the third input volume minus the fourth');
-   Msg('Your file should have '+inttostr(lOutHdr.dim[4])+' lines, one for each output volume');
-
-   if not MainForm.OpenDialogExecute('Select NIfTI images you wish to modify)',true,false,kTxtFilter) then
-    goto 666;
-   lCSVName := MainForm.OpenHdrDlg.Filename;
-   //MainForm.BrowseDialog('Choose collapase file
-   if not readCSV (lCSVname, lVol, lPosRA,lNegRA) then
-      goto 666;
-   if lVol < lOutHdr.dim[4] then begin
-      Msg ('Only found '+inttostr(lVol)+' contrasts in '+ lCSVName+' a total of '+inttostr(lOutHdr.dim[4])+' required');
-      freemem(lPosRA);
-      freemem(lNegRA);
-      goto 666;
-   end;
-   for lVol := 1 to  lOutHdr.dim[4] do begin
-       lOutVolOffset := (lVol -1) * lImgSamples;
-       lEvenVol := lNegRA^[lVol];
-       lOddVol := lPosRA^[lVol];
-       if (lEvenVol > 0) and (lOddVol > 0) and (lEvenVol <= lInHdr.dim[4]) and (lOddVol <= lInHdr.dim[4]) then begin
-          Msg (inttostr(lVol) +' = '+inttostr(lOddVol)+' - '+inttostr(lEvenVol) );
-          lInVolEvenOffset := (lEvenVol -1) * lImgSamples; //second, fourth
-          lInVolOddOffset := (lOddVol -1) * lImgSamples; //first, thired
-          for lInc := 1 to lImgSamples do  begin
-               lOdd := l16Buf^[lInVolOddOffset+lInc];
-               lEven := l16Buf^[lInVolEvenOffset+lInc];
-               lImgBuffer^[lOutVolOffset+lInc] := lOdd - lEven;
-          end; //each voxel in volume
-       end else begin
-          Msg ('Error: volumes out of range '+inttostr(lVol) +' = '+inttostr(lOddVol)+' - '+inttostr(lEvenVol) );
-       end;
-   end; //for lvol
-      freemem(lPosRA);
-      freemem(lNegRA);
-end else begin  //not custom  or lSplitOddEven
-   for lVol := 1 to  lOutHdr.dim[4] do begin
-       lOutVolOffset := (lVol -1) * lImgSamples;
-       lInVolEvenOffset := ((lVol*2) -1) * lImgSamples; //second, fourth
-       lInVolOddOffset := ((lVol*2) -2) * lImgSamples; //first, thired
-       if lSubtract then begin
-          if lOddMinusEven then begin
-             for lInc := 1 to lImgSamples do  begin
-               lOdd := l16Buf^[lInVolOddOffset+lInc];
-               lEven := l16Buf^[lInVolEvenOffset+lInc];
-               lImgBuffer^[lOutVolOffset+lInc] := lOdd - lEven;
-             end; //for lImgSamples
-          end else begin //not lOddMinusEven
-             for lInc := 1 to lImgSamples do  begin
-               lOdd := l16Buf^[lInVolOddOffset+lInc];
-               lEven := l16Buf^[lInVolEvenOffset+lInc];
-               lImgBuffer^[lOutVolOffset+lInc] := lEven-lOdd;
-             end; //for lImgSamples
-          end; //if else lOddMinusEven
-       end else begin //not subtract... add
-           for lInc := 1 to lImgSamples do  begin
-               lOdd := l16Buf^[lInVolOddOffset+lInc];
-               lEven := l16Buf^[lInVolEvenOffset+lInc];
-               lImgBuffer^[lOutVolOffset+lInc] := lOdd + lEven;
-           end; //for lImgSamples
-       end; //add
-   end; //for lvol
-end;
-   lresultStr :=  SaveNIfTICore (lOutImgName, lBuffAligned, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-   //next make mean
-   lresultStr :=  SaveMean (lOutImgName, lOutHdr, lImgBuffer,lPrefs,lByteSwap);
-666:
-   Freemem(lSrcBuffer);
-   Freemem(lBuffUnaligned);
-   if lResultStr = '' then //error - do not report success
-      exit;
-   result := true;
-end; //ASL_subtract
-
-end.
diff --git a/dcm2nii_prePARRECDTI/nii_crop.pas b/dcm2nii_prePARRECDTI/nii_crop.pas
deleted file mode 100755
index 78b5d2f..0000000
--- a/dcm2nii_prePARRECDTI/nii_crop.pas
+++ /dev/null
@@ -1,1003 +0,0 @@
-unit nii_crop;
-{$H+}
-//TO DO: ByteSwap, DataTypes, Orthogonality
-
-//VENTRAL direction: attempts to remove excess neck ...
-//OTHER directions: zeros slices where signal intensity is <5%
-//assumes image is oriented in canonical space, e.g.
-//closest to rotation matrix [1 0 0; 0 1 0; 0 0 1]
-//if your image is not rotated in this manner, use nii_orient first
-interface
-
-uses
-{$IFDEF FPC}gzio2,{$ENDIF}
-//distr,
-  SysUtils,define_types,dicomtypes,niftiutil,GraphicsMathLibrary,prefs;
-//function Int16LogPtoZNIfTI32Z(lFilename: string; lPrefs: TPrefs): string;
-function CropNIfTI(lFilename: string; lPrefs: TPrefs): string;//returns output filename if successful
-function Float32NIfTI(lFilename: string; lPrefs: TPrefs): string;
-function FormulaNIfTI(lFilename: string; lPrefs: TPrefs; lScale,lPower: double): string;
-//function RescaleNIfTI(lFilename: string; lPrefs: TPrefs; lScale: double): string;
-function RemoveNIfTIscalefactor(lFilename: string; lPrefs: TPrefs): string;
-function CropNIfTIX(lFilename: string; lPrefs: TPrefs; lDorsalCrop, lVentralCrop, lLCrop,lRCrop, lACrop, lPCrop : integer ): string;
-function SiemensPhase2RadiansNIfTI(lFilename: string; lPrefs: TPrefs): string;
-
-implementation
-uses dialogsx,math;
-
-function RemoveNIfTIscalefactor(lFilename: string; lPrefs: TPrefs): string;
-//rescale data by  lScale
-var
-   lInHdr,lOutHdr: TNIFTIhdr;
-   lOutname: string;
-   l4DBytes,lInOffset,l1: integer;
-   lInBuffer,lOutBuffer: bytep;
-   lByteSwap: boolean;
-begin
-     result := '';
-     //lExt := UpCaseExt(lFilename);
-     if not NIFTIhdr_LoadHdr (lFilename, lInHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lFilename);
-        exit;
-     end;
-   case lInHdr.datatype of
-     kDT_UNSIGNED_CHAR,kDT_SIGNED_SHORT,kDT_UINT16, kDT_SIGNED_INT,kDT_FLOAT:;//Supported
-     else begin
-         Msg('rescaleNIfTI unsupported datatype.');
-         exit;
-     end;
-   end;
-   Msg('removing scale factor NIfTI/Analyze image '+lFileName);
-   lOutHdr := lInHdr;
-   lOutHdr.scl_slope := 1;
-   lOutHdr.scl_inter := 0;
-   l4DBytes := lInHdr.dim[1]*lInHdr.dim[2]*lInHdr.dim[3]*lInHdr.dim[4]*(lInHdr.bitpix div 8);
-   if not NIFTIhdr_LoadImg (lFileName, lInHdr, lInBuffer, lInOffset,lByteSwap) then  exit;
-   GetMem(lOutBuffer,l4DBytes+kNIIImgOffset);
-   //lOutPos := kNIIImgOffset + 1;
-   l1 := 1;
-   Move(lInBuffer^[lInOffset+l1],lOutBuffer^[kNIIImgOffset + l1],l4DBytes);
-   lOutname := ChangeFilePrefix (lFileName,'r');
-   Msg(lOutName);
-   if  SaveNIfTICore (lOutName, lOutBuffer, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap) = '' then begin
-      Msg('Remove scale error');
-      Freemem(lInBuffer);
-      Freemem(lOutBuffer);
-      exit;
-   end;
-      Freemem(lInBuffer);
-      Freemem(lOutBuffer);
-   result := lOutname;
-end;
-
-function FormulaNIfTI(lFilename: string; lPrefs: TPrefs; lScale,lPower: double): string;
-//apply formula to dataset, then save results as 32-bit float....
-var
-   lInHdr,lOutHdr: TNIFTIhdr;
-   lOutname,lExt: string;
-   lAdj: single;
-   lImgSamples,lInc,lImgOffset,lVol,lnVol,lPos: integer;
-   lSrcBuffer,lBuffer, lBuffUnaligned,lBuffAligned: bytep;
-   l32Buf,lImgBuffer: singlep;
-   l16Buf : SmallIntP;
-   lByteSwap: boolean;
-begin
-     result := '';
-     lExt := UpCaseExt(lFilename);
-     if not NIFTIhdr_LoadHdr (lFilename, lInHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lFilename);
-        exit;
-     end;
-   case lInHdr.datatype of
-     kDT_UNSIGNED_CHAR,kDT_SIGNED_SHORT,kDT_UINT16, kDT_SIGNED_INT,kDT_FLOAT:;//Supported
-     else begin
-         Msg('Error with nii_crop: unsupported datatype.');
-         exit;
-     end;
-   end;
-   Msg('Applying formula to NIfTI/Analyze image'+lFileName);
-   lOutHdr := lInHdr;
-   lOutHdr.datatype := kDT_FLOAT;
-   lOutHdr.bitpix := 32;
-   lImgSamples := lInHdr.dim[1]*lInHdr.dim[2]*lInHdr.dim[3]*lInHdr.dim[4];
-   if not NIFTIhdr_LoadImg (lFileName, lInHdr, lSrcBuffer, lImgOffset,lByteSwap) then  exit;
-   //Msg('Automatically Cropping image');
-   lBuffer := (@lSrcBuffer^[lImgOffset+1]);
-   GetMem(lBuffUnaligned ,(sizeof(single)*lImgSamples) + 16+kNIIImgOffset);
-   {$IFDEF FPC}
-    lBuffAligned := Align(lBuffUnaligned,16); // not commented - check this
-   {$ELSE}
-   lBuffAligned := ByteP($fffffff0 and (integer(lBuffUnaligned)+15));
-   {$ENDIF}
-   lInc := 1;
-   lImgBuffer := SingleP(@lBuffAligned^[kNIIImgOffset+lInc]);
-   case lInHdr.datatype of
-           kDT_UNSIGNED_CHAR : begin //8 bit
-             for lInc := 1 to lImgSamples do
-                 lImgBuffer^[lInc] := lBuffer^[lInc];
-             end;
-	  kDT_SIGNED_SHORT{,kDT_UINT16}: begin //16-bit int
-		l16Buf := SmallIntP(lBuffer );
-		if lByteSwap then begin
-                   for lInc := 1 to lImgSamples do
-			  lImgBuffer^[lInc] := Swap(l16Buf^[lInc]);
-                end else begin
-                    for lInc := 1 to lImgSamples do
-                        lImgBuffer^[lInc] := l16Buf^[lInc];
-                end;
-          end;//16bit
-          kDT_SIGNED_INT: begin
-		l32Buf := SingleP(lBuffer );
-		if lByteSwap then //unswap and convert integer to float
-			 for lInc := 1 to lImgSamples do
-			  lImgBuffer^[lInc] := (Swap4r4i(l32Buf^[lInc]))
-		else  //convert integer to float
-                      for lInc := 1 to lImgSamples do
-			  lImgBuffer^[lInc] := Conv4r4i(l32Buf^[lInc]);
-		end; //32-bit int
-	  kDT_FLOAT: begin
-		l32Buf := SingleP(lBuffer);
-                for lInc := 1 to lImgSamples do
-                    lImgBuffer[lInc] := l32Buf[lInc];
-		if lByteSwap then
-                   for lInc := 1 to lImgSamples do
-                       pswap4r(lImgBuffer^[lInc]);  //faster as procedure than function see www.optimalcode.com
-		for lInc := 1 to lImgSamples do
-			if specialsingle(lImgBuffer^[lInc]) then lImgBuffer^[lInc] := 0.0;
-		 //invert= for lInc := 1 to lImgSamples do l32Buf[lInc] := -l32Buf[lInc];
-          end; //32-bit float
-         else begin
-             Msg('Serious error: format not supported by Float32.');
-             exit;
-         end;
-   end; //case
-   //apply formula
-   lImgSamples := lInHdr.dim[1]*lInHdr.dim[2]*lInHdr.dim[3]; //3D data
-   lnVol := lInHdr.dim[4]; //4th dimension
-   lPos := 0;
-   //fx(lScale,lPower);
-   for lVol := 1 to lnVol do begin
-       lAdj := 1/(lScale* Power(lVol,lPower));
-       for lInc := 1 to lImgSamples do begin
-           inc(lPos);
-           lImgBuffer^[lPos] := lAdj*lImgBuffer^[lPos];
-           //lImgBuffer[lPos] := lImgBuffer[lPos] * lScale;
-       end;
-   end;
-   lOutname := ChangeFilePrefix (lFileName,'f');
-   result := SaveNIfTICore (lOutName, lBuffAligned, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-   Freemem(lBuffUnaligned);
-   Freemem(lSrcBuffer);
-end;
-
-
-function Float32NIfTI(lFilename: string; lPrefs: TPrefs): string;
-//convert any data format as 32-bit float....
-var
-   lInHdr,lOutHdr: TNIFTIhdr;
-   lOutname,lExt: string;
-   lImgSamples,lInc,lImgOffset: integer;
-   lSrcBuffer,lBuffer, lBuffUnaligned,lBuffAligned: bytep;
-   l32Buf,lImgBuffer: singlep;
-   l16Buf : SmallIntP;
-   lByteSwap: boolean;
-begin
-     result := '';
-     lExt := UpCaseExt(lFilename);
-     if not NIFTIhdr_LoadHdr (lFilename, lInHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lFilename);
-        exit;
-     end;
-   if lInHdr.datatype = kDT_FLOAT then begin
-         Msg('No need to apply Float32 : data is already 32-bit real: '+lFilename);
-         exit;
-   end;
-   case lInHdr.datatype of
-     kDT_UNSIGNED_CHAR,kDT_SIGNED_SHORT,kDT_UINT16, kDT_SIGNED_INT,kDT_FLOAT:;//Supported
-     else begin
-         Msg('Float32 unsupported datatype.');
-         exit;
-     end;
-   end;
-   Msg('Converting NIfTI/Analyze image to 32-bit float'+lFileName);
-   lOutHdr := lInHdr;
-   lOutHdr.datatype := kDT_FLOAT;
-   lOutHdr.bitpix := 32;
-   lImgSamples := lInHdr.dim[1]*lInHdr.dim[2]*lInHdr.dim[3]*lInHdr.dim[4];
-   if not NIFTIhdr_LoadImg (lFileName, lInHdr, lSrcBuffer, lImgOffset,lByteSwap) then  exit;
-   //Msg('Automatically Cropping image');
-   lBuffer := (@lSrcBuffer^[lImgOffset+1]);
-   GetMem(lBuffUnaligned ,(sizeof(single)*lImgSamples) + 16+kNIIImgOffset);
-   {$IFDEF FPC}
-   lBuffAligned := align(lBuffUnaligned,16);
-   {$ELSE}
-   lBuffAligned := ByteP($fffffff0 and (integer(lBuffUnaligned)+15));
-   {$ENDIF}
-   lInc := 1;
-   lImgBuffer := SingleP(@lBuffAligned^[kNIIImgOffset+lInc]);
-   case lInHdr.datatype of
-           kDT_UNSIGNED_CHAR : begin //8 bit
-             for lInc := 1 to lImgSamples do
-                 lImgBuffer^[lInc] := lBuffer^[lInc];
-             end;
-	  kDT_SIGNED_SHORT{,kDT_UINT16}: begin //16-bit int
-		l16Buf := SmallIntP(lBuffer );
-		if lByteSwap then begin
-                   for lInc := 1 to lImgSamples do
-			  lImgBuffer^[lInc] := Swap(l16Buf^[lInc]);
-                end else begin
-                    for lInc := 1 to lImgSamples do
-                        lImgBuffer^[lInc] := l16Buf^[lInc];
-                end;
-          end;//16bit
-          kDT_SIGNED_INT: begin
-		l32Buf := SingleP(lBuffer );
-		if lByteSwap then //unswap and convert integer to float
-			 for lInc := 1 to lImgSamples do
-			  lImgBuffer^[lInc] := (Swap4r4i(l32Buf^[lInc]))
-		else  //convert integer to float
-                      for lInc := 1 to lImgSamples do
-			  lImgBuffer^[lInc] := Conv4r4i(l32Buf^[lInc]);
-		end; //32-bit int
-	  kDT_FLOAT: begin
-		l32Buf := SingleP(lBuffer);
-                for lInc := 1 to lImgSamples do
-                    lImgBuffer[lInc] := l32Buf[lInc];
-		if lByteSwap then
-                   for lInc := 1 to lImgSamples do
-                       pswap4r(lImgBuffer^[lInc]);  //faster as procedure than function see www.optimalcode.com
-		for lInc := 1 to lImgSamples do
-			if specialsingle(lImgBuffer^[lInc]) then lImgBuffer^[lInc] := 0.0;
-		 //invert= for lInc := 1 to lImgSamples do l32Buf[lInc] := -l32Buf[lInc];
-          end; //32-bit float
-         else begin
-             Msg('Serious error: format not supported by Float32.');
-             exit;
-         end;
-   end; //case
-   lOutname := ChangeFilePrefix (lFileName,'f');
-   result := SaveNIfTICore (lOutName, lBuffAligned, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-   Freemem(lBuffUnaligned);
-   Freemem(lSrcBuffer);
-end;
-
-
-(*function LogPtoZ (lLogP: single): single;
-var
-   lD: double;
-begin
-     ///lD := Log10(lLogp);
-     lD := Power(10,-lLogP);
-     result := pNormalInv(lD);
-     //fx(lD,lZ);
-end;
-
-function Int16LogPtoZNIfTI32Z(lFilename: string; lPrefs: TPrefs): string;
-//convert any data format as 32-bit float....
-var
-   lInHdr,lOutHdr: TNIFTIhdr;
-   lOutname,lExt: string;
-   lImgSamples,lInc,lImgOffset: integer;
-   lSrcBuffer,lBuffer, lBuffUnaligned,lBuffAligned: bytep;
-   l32Buf,lImgBuffer: singlep;
-   l16Buf : SmallIntP;
-   lByteSwap: boolean;
-begin
-     result := '';
-     lExt := UpCaseExt(lFilename);
-     if not NIFTIhdr_LoadHdr (lFilename, lInHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lFilename);
-        exit;
-     end;
-   if lInHdr.datatype = kDT_FLOAT then begin
-         Msg('No need to apply Float32 : data is already 32-bit real: '+lFilename);
-         exit;
-   end;
-   case lInHdr.datatype of
-     kDT_UNSIGNED_CHAR,kDT_SIGNED_SHORT,kDT_UINT16, kDT_SIGNED_INT,kDT_FLOAT:;//Supported
-     else begin
-         Msg('Float32 unsupported datatype.');
-         exit;
-     end;
-   end;
-   Msg('Converting NIfTI/Analyze image to 32-bit float'+lFileName);
-   lOutHdr := lInHdr;
-   lOutHdr.datatype := kDT_FLOAT;
-   lOutHdr.bitpix := 32;
-   lImgSamples := lInHdr.dim[1]*lInHdr.dim[2]*lInHdr.dim[3]*lInHdr.dim[4];
-   if not NIFTIhdr_LoadImg (lFileName, lInHdr, lSrcBuffer, lImgOffset,lByteSwap) then  exit;
-   //Msg('Automatically Cropping image');
-   lBuffer := (@lSrcBuffer^[lImgOffset+1]);
-   GetMem(lBuffUnaligned ,(sizeof(single)*lImgSamples) + 16+kNIIImgOffset);
-   {$IFDEF FPC}
-   lBuffAligned := align(lBuffUnaligned,16);
-   {$ELSE}
-   lBuffAligned := ByteP($fffffff0 and (integer(lBuffUnaligned)+15));
-   {$ENDIF}
-   lInc := 1;
-   lImgBuffer := SingleP(@lBuffAligned^[kNIIImgOffset+lInc]);
-   lOutHdr.scl_slope := 1;
-   case lInHdr.datatype of
-	  kDT_SIGNED_SHORT{,kDT_UINT16}: begin //16-bit int
-		l16Buf := SmallIntP(lBuffer );
-		if lByteSwap then begin
-                   for lInc := 1 to lImgSamples do
-			  lImgBuffer^[lInc] := Swap(l16Buf^[lInc]);
-                end else begin
-                    for lInc := 1 to lImgSamples do begin
-                        if l16Buf^[lInc] =0 then
-                           lImgBuffer^[lInc] := 0
-                        else if l16Buf^[lInc] =32767 then
-                           lImgBuffer^[lInc] := 0
-                        else
-                            lImgBuffer^[lInc] := LogPtoZ(0.01*l16Buf^[lInc]);
-                    end;
-                end;
-          end;//16bit
-         else begin
-             Msg('Serious error: format not supported by Float32.');
-             exit;
-         end;
-   end; //case
-   lOutname := ChangeFilePrefix (lFileName,'f');
-   result := SaveNIfTICore (lOutName, lBuffAligned, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-   Freemem(lBuffUnaligned);
-   Freemem(lSrcBuffer);
-end;*)
-
-
-procedure SmoothRA (var lRA: Doublep; lItems: integer);
-var
- lRecip: double;
- lTempRA,lTempRAUnaligned: Doublep;
- lI: integer;
-begin
-     if lItems < 3 then exit;
-     GetMem(lTempRAUnaligned,(lItems*sizeof(double))+16);
-     {$IFDEF FPC}
-     lTempRA := align(lTempRAUnaligned,16);
-     {$ELSE}
-     lTempRA := DoubleP($fffffff0 and (integer(lTempRAUnaligned)+15));
-     {$ENDIF}
-
-     for lI := 1 to lItems do
-         lTempRA^[lI] := lRA^[lI];
-     lRecip := 1/3; //multiplies faster than divides
-     for lI := 2 to (lItems-1) do
-         lRA^[lI] := (lTempRA^[lI-1]+lTempRA^[lI]+lTempRA^[lI+1])*lRecip;
-     FreeMem(lTempRAUnaligned);
-end;
-
-function MaxRA (var lRA: Doublep; lStart,lItems: integer): integer;
-var
- lMax: double;
- lI: integer;
-begin
-     result := lStart;
-     if (lItems < 2) or (lStart >= lItems) or ((lItems-lStart)< 1) then exit;
-     lMax := lRA^[lStart];
-     for lI := lStart to lItems do
-         if lRA^[lI] > lMax then begin
-             result := lI;
-             lMax := lRA^[lI]
-         end;
-end;
-
-function MinRA (var lRA: Doublep; lStart,lItems: integer): integer;
-var
- lMin: double;
- lI: integer;
-begin
-     result := lStart;
-     if (lItems < 2) or (lStart >= lItems) or ((lItems-lStart)< 1) then exit;
-     lMin := lRA^[lStart];
-     for lI := lStart to lItems do
-         if lRA^[lI] < lMin then begin
-             result := lI;
-             lMin := lRA^[lI]
-         end;
-end;
-
-
-function FindDVCrop2 (var lHdr: TNIFTIhdr;  var lDorsalCrop,lVentralCrop: integer): boolean;
-const
-     kMaxDVmm = 200;
-var
-   lSliceMM: double;
-begin
-     result := false;
-     if lHdr.pixdim[3] < 0.0001 then
-        exit;
-     lSliceMM := lHdr.pixdim[3]* (lHdr.Dim[3]-lDorsalCrop-lVentralCrop);
-     if lSliceMM > kMaxDVmm then begin //decide how many more ventral slices to remove
-        lSliceMM := lSliceMM - kMaxDVmm;
-        lSliceMM := lSliceMM / lHdr.pixdim[3];
-        //msg(inttostr(lVentralCrop));
-        lVentralCrop := lVentralCrop + round(lSliceMM);
-        //msg(inttostr(lVentralCrop));
-     end;
-     result := true;
-end;
-
-function FindDVCrop (var lHdr: TNIFTIhdr; var ScrnBuffer: Singlep; var lDorsalCrop,lVentralCrop: integer; lPct: integer): boolean;
-var
-   lSliceMax: double;
-   lSliceSum,lSliceSumUnaligned: Doublep;
-   lXY,lZ,lSlices,lSliceSz,lSliceStart,lVentralMaxSlice,lMaxSlice,lMinSlice,lGap: integer;
-begin
-     result := false;
-     lDorsalCrop := 0;
-     lVentralCrop := 0;
-     if (lPct < 1) or (lPct > 100) then
-        exit;
-     lSlices := lHdr.dim[3];
-     lSliceSz := lHdr.dim[1]*lHdr.dim[2];
-     GetMem(lSliceSumUnaligned,(lSlices*sizeof(double))+16);
-     {$IFDEF FPC}
-     lSliceSum := align(lSliceSumUnaligned,16);
-     {$ELSE}
-     lSliceSum := DoubleP($fffffff0 and (integer(lSliceSumUnaligned)+15));
-     {$ENDIF}
-     lSliceMax := 0;
-     for lZ := 1 to lSlices do begin
-         lSliceSum^[lZ] := 0;
-         lSliceStart := (lZ-1)*lSliceSz;
-         for lXY := 1 to lSliceSz do
-             lSliceSum^[lZ] := lSliceSum^[lZ]+ ScrnBuffer^[lXY+lSliceStart];
-         if  lSliceMax < lSliceSum^[lZ] then
-             lSliceMax := lSliceSum^[lZ];
-     end; //for each slice
-     if lSliceMax = 0 then begin //no data variance
-        Freemem(lSliceSumUnaligned);
-        exit;
-     end; //VolSum = 0
-     //next: normalize so each slice is normalized to brightest axial slice
-     for lZ := 1 to lSlices do
-         lSliceSum^[lZ] := lSliceSum^[lZ]/lSliceMax;
-     result := true;
-     //next: smooth
-     SmoothRA(lSliceSum,lSlices);
-     //next - top cropping - removing slices that are <5%  of maximum slice
-     lZ := lSlices;
-     while (lZ > 1) and (lSliceSum^[lZ] < (lPct/100)) do
-           dec(lZ);
-     lDorsalCrop := lSlices-lZ;
-     //next findMax
-     lMaxSlice := MaxRA(lSliceSum,1,lSlices);
-     //next - ensure there is at least 60mm from max to bottom of an image - enough spine to worry about
-     lVentralMaxSlice := lMaxSlice-round(60/abs(lHdr.pixdim[3]));
-     if lVentralMaxSlice < 1 then
-        exit;
-     lVentralMaxSlice := MaxRA(lSliceSum,1,lVentralMaxSlice);
-     //finally: find minima between these two points...
-     lMinSlice := MinRA(lSliceSum,lVentralMaxSlice,lMaxSlice);
-     lGap := round((lMaxSlice-lMinSlice)*0.9);//add 40% for cerebellum
-     if (lMinSlice-lGap) > 1 then begin
-        result := true;
-        lVentralCrop := lMinSlice-lGap;
-     end;
-     //fx(lVentralCrop,lDorsalCrop);
-     //next show output...
-     {TextForm.Memo1.Lines.Clear;
-     for lZ := 1 to lSlices do
-          TextForm.Memo1.Lines.add(inttostr(lZ)+','+floattostr(lSliceSum^[lZ]));
-     TextForm.Show; }
-     //cleanup
-     Freemem(lSliceSumUnaligned);
-     //next - max 200mm from top of head to spinal column....
-
-     //if (lSliceMM > kMaxDVmm
-
-end;
-
-function FindLRCrop (var lHdr: TNIFTIhdr;  var ScrnBuffer: Singlep;  var lLCrop,lRCrop:integer; lPct,lDCrop,lVCrop: integer): boolean;
-//amount of image to crop from left/right for N% signal intensity
-var
-   lSliceMax: double;
-   lSliceSum,lSliceSumUnaligned: Doublep;
-   lZmin,lZmax,lX,lY,lZ,lSlices,lSliceSz,lSliceStart: integer;
-begin
-     result := false;
-     lLCrop := 0;
-     lRCrop := 0;
-     if (lPct < 1) or (lPct > 100) then
-        exit;
-     lZMin := lVCrop;
-     lZMax := lHdr.Dim[3]-lDCrop;
-     SortInt(lZMin,lZMax);
-     lZMin := Bound(lZMin,1,lHdr.Dim[3]);
-     lZMax := Bound(lZMax,1,lHdr.Dim[3]);
-     if lZMin >= lZMax then
-        exit;
-
-     lSlices := lHdr.Dim[1];
-     lSliceSz := lHdr.Dim[1]*lHdr.Dim[2];
-     GetMem(lSliceSumUnaligned,(lSlices*sizeof(double))+16);
-     {$IFDEF FPC}
-     lSliceSum := align(lSliceSumUnaligned,16);
-     {$ELSE}
-     lSliceSum := DoubleP($fffffff0 and (integer(lSliceSumUnaligned)+15));
-     {$ENDIF}
-     lSliceMax := 0;
-     for lX := 1 to lSlices do begin
-         lSliceSum^[lX] := 0;
-         for lZ := {1 to lHdr.Dim[3]} lZMin to lZMax do begin
-             lSliceStart := lX+ ((lZ-1)*lSliceSz);
-             for lY := 1 to lHdr.Dim[2] do begin
-                 lSliceSum^[lX] := lSliceSum^[lX]+ ScrnBuffer^[lSliceStart];
-                 lSliceStart := lSliceStart + lHdr.Dim[1];
-             end;
-         end;
-         //for lYZ := 1 to lSliceSz do
-         //    lSliceSum^[lZ] := lSliceSum^[lZ]+ gMRIcroOverlay[kBGOverlayNum].ScrnBuffer[lXY+lSliceStart];
-         if  lSliceMax < lSliceSum^[lX] then
-             lSliceMax := lSliceSum^[lX];
-     end; //for each slice
-     if lSliceMax = 0 then begin //no data variance
-        Freemem(lSliceSumUnaligned);
-        exit;
-     end; //VolSum = 0
-     //next: smooth
-     SmoothRA(lSliceSum,lSlices);
-     //next: normalize so each slice is normalized to brightest axial slice
-     for lX := 1 to lSlices do
-         lSliceSum^[lX] := lSliceSum^[lX]/lSliceMax;
-     //next - Left cropping- removing slices that are <5%  of maximum slice
-     lX := lSlices;
-     while (lX > 1) and (lSliceSum^[lX] < (lPct/100)) do
-           dec(lX);
-     lRCrop := lSlices-lX;
-     //next - Left cropping- removing slices that are <5%  of maximum slice
-     lX := 1;
-     while (lX <= lSlices) and (lSliceSum^[lX] < (lPct/100)) do
-           inc(lX);
-     lLCrop := lX-1;
-     //fx(lLCrop,lRCrop);
-     result := true;
-     Freemem(lSliceSumUnaligned);
-end;
-
-function FindAPCrop (var lHdr: TNIFTIhdr; var ScrnBuffer: Singlep;  var lACrop,lPCrop: integer; lPct,lDCrop,lVCrop: integer): boolean;
-//amount of image to crop from anterior/posterior for 5% signal intensity
-var
-   lSliceMax: double;
-   lSliceSum,lSliceSumUnaligned: Doublep;
-   lZMin,lZMax,lX,lY,lZ,lSlices,lSliceSz,lSliceStart: integer;
-begin
-     result := false;
-     lACrop := 0;
-     lPCrop := 0;
-     lZMin := lVCrop;
-     lZMax := lHdr.Dim[3]-lDCrop;
-     SortInt(lZMin,lZMax);
-     lZMin := Bound(lZMin,1,lHdr.Dim[3]);
-     lZMax := Bound(lZMax,1,lHdr.Dim[3]);
-     if lZMin >= lZMax then
-        exit;
-     if (lPct < 1) or (lPct > 100) then
-        exit;
-     lSlices := lHdr.Dim[2];
-     lSliceSz := lHdr.Dim[1]*lHdr.Dim[2];
-     //lCoroSliceSz := lHdr.Dim[1]*lHdr.Dim[3];
-     GetMem(lSliceSumUnaligned,(lSlices*sizeof(double))+16);
-     {$IFDEF FPC}
-     lSliceSum := align(lSliceSumUnaligned,16);
-     {$ELSE}
-     lSliceSum := DoubleP($fffffff0 and (integer(lSliceSumUnaligned)+15));
-     {$ENDIF}
-     lSliceMax := 0;
-     for lY := 1 to lSlices do begin
-         lSliceSum^[lY] := 0;
-         //lSliceStart := lY;
-         for lZ := {1 to lHdr.Dim[3]} lZMin to lZMax do begin
-             lSliceStart := ((lY-1)* lHdr.Dim[1])+ ((lZ-1)*lSliceSz);
-             //if lSliceStart > (lSliceSz*lHdr.Dim[3]) then
-             //   Msg('xx');
-             for lX := 1 to lHdr.Dim[1] do
-                 lSliceSum^[lY] := lSliceSum^[lY]+ ScrnBuffer^[lSliceStart+lX];
-         end; //for lZ
-         //for lYZ := 1 to lSliceSz do
-         //    lSliceSum^[lY] := lSliceSum^[lY]+ gMRIcroOverlay[kBGOverlayNum].ScrnBuffer[lXY+lSliceStart];
-         if  lSliceMax < lSliceSum^[lY] then
-             lSliceMax := lSliceSum^[lY];
-     end; //for each slice
-     if lSliceMax = 0 then begin //no data variance
-        Freemem(lSliceSumUnaligned);
-        exit;
-     end; //VolSum = 0
-     //next: smooth
-     SmoothRA(lSliceSum,lSlices);
-     //next: normalize so each slice is normalized to brightest axial slice
-     for lY := 1 to lSlices do
-         lSliceSum^[lY] := lSliceSum^[lY]/lSliceMax;
-     //next - Left cropping- removing slices that are <5%  of maximum slice
-     lY := lSlices;
-     while (lY > 1) and (lSliceSum^[lY] < (lPct/100)) do
-           dec(lY);
-     lACrop := lSlices-lY;
-     //next - Left cropping- removing slices that are <5%  of maximum slice
-     lY := 1;
-     while (lY <= lSlices) and (lSliceSum^[lY] < (lPct/100)) do
-           inc(lY);
-     lPCrop := lY-1;
-     result := true;
-     Freemem(lSliceSumUnaligned);
-end;
-
-function CropNIfTIX(lFilename: string; lPrefs: TPrefs; lDorsalCrop, lVentralCrop, lLCrop,lRCrop, lACrop, lPCrop : integer ): string;
-//to do : data swapping (errors on detection and writing zero in reverse order)
-var
-   lInHdr,lOutHdr: TNIFTIhdr;
-   lOutname,lExt: string;
-   lXmm,lYmm,lZmm: single;
-   lMat: TMatrix;
-   lOutPos,//lInc,     //lImgSamples,
-   lX,lY,lZ,lBPP, lB,
-   lVol, lInVol,lInZOffset,lInYOffset,lInSliceSz,lInXSz,lInPos,lImgOffset: integer;
-   lSrcBuffer,lBuffer//, lBuffUnaligned
-   : bytep;
-   //l32Buf,lImgBuffer: singlep;
-   //l16Buf : SmallIntP;
-   //lWordX: Word;
-   //lSPM2: boolean;
-   lOutF,lInF: File;
-   lByteSwap: boolean;
-begin
-   result := '';
-   if (lDorsalCrop = 0) and (lVentralCrop = 0)
-      and (lLCrop = 0) and (lRCrop = 0)
-      and (lACrop = 0) and (lPCrop = 0) then begin
-             Msg('Crop slices quitting: no need to delete slices.');
-             exit;   //25 Sept 2008
-   end;
-   if (lDorsalCrop < 0) or (lVentralCrop < 0)
-      or (lLCrop < 0) or (lRCrop < 0)
-      or (lACrop < 0) or (lPCrop < 0) then begin
-             Msg('Crop slices quitting: negative values should be impossible.');
-             exit;
-   end;
-     result := '';
-     lExt := UpCaseExt(lFilename);
-     if not NIFTIhdr_LoadHdr (lFilename, lInHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lFilename);
-        exit;
-     end;
-     //Next create reordered or trimmed image in the correct format
-   case lInHdr.datatype of
-     kDT_UNSIGNED_CHAR,kDT_SIGNED_SHORT,kDT_UINT16, kDT_SIGNED_INT,kDT_FLOAT:;//Supported
-     else begin
-         Msg('Crop 3D unsupported datatype.');
-         exit;
-     end;
-   end;
-   Msg('Cropping NIfTI/Analyze image '+lFileName);
-   lOutHdr := lInHdr;
-   //lImgSamples := lInHdr.dim[1]*lInHdr.dim[2]*lInHdr.dim[3];
-   lBPP := (lInHdr.bitpix div 8); //bytes per pixel
-  if not NIFTIhdr_LoadImg (lFileName, lInHdr, lSrcBuffer, lImgOffset,lByteSwap) then  exit;
-   //Msg('Automatically Cropping image');
-    lBuffer := (@lSrcBuffer^[lImgOffset+1]);
-   //next compute size of cropped volume
-   lOutHdr.Dim[1] := lInHdr.Dim[1]-lLCrop-lRCrop;
-   lOutHdr.Dim[2] := lInHdr.Dim[2]-lACrop-lPCrop;
-   lOutHdr.Dim[3] := lInHdr.Dim[3]-lDorsalCrop-lVentralCrop;
-   if (lOutHdr.Dim[1] < 1) or (lOutHdr.Dim[2] <12) or (lOutHdr.Dim[3] < 1) then begin
-        Msg('Requested to crop more slices than available.');
-        Freemem(lSrcBuffer);
-        exit;
-   end;
-   //lVolBytes := lOutHdr.dim[1]*lOutHdr.dim[2]*lOutHdr.dim[3]*lBPP;
-   //next: readjust origin to take into account removed slices
-   //REQUIRES images to be aligned to nearest orthogonal to canonical space [1 0 0; 0 1 0; 0 0 1]
-   NIFTIhdr_SlicesToCoord (lInHdr,lLCrop,lPCrop,lVentralCrop, lXmm,lYmm,lZmm);
-   lOutHdr.srow_x[3] := lInHdr.srow_x[3] + lXmm;
-   lOutHdr.srow_y[3] := lInHdr.srow_y[3] + lYmm;
-   lOutHdr.srow_z[3] := lInHdr.srow_z[3] + lZmm;
-   lMat := Matrix3D (
-	lOutHdr.srow_x[0], lOutHdr.srow_x[1], lOutHdr.srow_x[2], lOutHdr.srow_x[3],
-	lOutHdr.srow_y[0], lOutHdr.srow_y[1], lOutHdr.srow_y[2], lOutHdr.srow_y[3],
-	lOutHdr.srow_z[0], lOutHdr.srow_z[1], lOutHdr.srow_z[2], lOutHdr.srow_z[3],
-	0, 0, 0, 1);
-   nifti_mat44_to_quatern( lMat,
-   lOutHdr.quatern_b,lOutHdr.quatern_c,lOutHdr.quatern_d,
-   lOutHdr.qoffset_x,lOutHdr.qoffset_y,lOutHdr.qoffset_z,
-                             lXmm, lYmm, lZmm, lOutHdr.pixdim[0]{QFac});
-   //note we write and read to the same buffer - we will always SHRINK output
-   //no need to byteswap data - we will save in the save format as stored
-
-   lOutPos := 0;
-   lInSliceSz := lInHdr.dim[1]*lInHdr.dim[2]*lBPP;
-   lInXSz := lInHdr.dim[1]*lBPP;
-   for lVol := 1 to lOutHdr.dim[4] do begin
-     lInVol := (lVol-1) * (lInSliceSz * lInHdr.dim[3]);
-     //fx(lInVol,lVol);
-     for lZ := 1 to lOutHdr.dim[3] do begin
-       lInZOffset := (lVentralCrop+lZ-1) * lInSliceSz;
-       for lY := 1 to lOutHdr.dim[2] do begin
-           lInYOffset := ((lPCrop+lY-1) * lInXSz) + lInZOffset + (lLCrop*lBPP);
-           for lX := 1 to lOutHdr.dim[1] do begin
-               for lB := 1 to lBPP do begin
-                   inc(lOutPos);
-                   lInPos := ((lX-1) * lBPP) + lInYOffset + lB;
-                   lBuffer^[lOutPos] := lBuffer^[lInPos+lInVol];
-               end;
-           end;
-       end; //for Y
-     end; //for Z
-   end; //for Vol
-   lOutname := ChangeFilePrefix (lFileName,'c');
-   result := SaveNIfTICore (lOutName, lSrcBuffer, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-   Freemem(lSrcBuffer);
-end;
-
-function CropNIfTI(lFilename: string; lPrefs: TPrefs): string;
-//to do : data swapping (errors on detection and writing zero in reverse order)
-var
-   lInHdr,lOutHdr: TNIFTIhdr;
-   lOutname,lExt: string;
-   lXmm,lYmm,lZmm: single;
-   lMat: TMatrix;
-   lOutPos,lImgSamples,lInc,
-   lX,lY,lZ,lBPP, lB,
-   lInZOffset,lInYOffset,lInSliceSz,lInXSz,lInPos,lImgOffset: integer;
-   lSrcBuffer,lBuffer, lBuffUnaligned: bytep;
-   l32Buf,lImgBuffer: singlep;
-   l16Buf : SmallIntP;
-   //lOutF,lInF: File;
-   lACrop,lPCrop,lDorsalCrop,lVentralCrop,lLCrop,lRCrop: integer;
-   lByteSwap: boolean;
-begin
-     result := '';
-     lExt := UpCaseExt(lFilename);
-     if not NIFTIhdr_LoadHdr (lFilename, lInHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lFilename);
-        exit;
-     end;
-     if (lInHdr.dim[1] > lPrefs.MaxReorientMatrix) or (lInHdr.dim[2] > lPrefs.MaxReorientMatrix) or(lInHdr.dim[3] > lPrefs.MaxReorientMatrix) then begin
-      Msg('This image will not be cropped (larger than MaxReorientMatrix= '+inttostr(lPrefs.MaxReorientMatrix));
-      exit;
-     end;
-     //check orthogonal alignment....
-     if lInHdr.dim[4] > 1 then begin
-        Msg('Only able to Crop 3D images (reorienting 4D could disrupt slice timing and diffusion directions.');
-        exit;
-     end;
-     //Next create reordered or trimmed image in the correct format
-   case lInHdr.datatype of
-     kDT_UNSIGNED_CHAR,kDT_SIGNED_SHORT,kDT_UINT16, kDT_SIGNED_INT,kDT_FLOAT:;//Supported
-     else begin
-         Msg('Crop 3D unsupported datatype.');
-         exit;
-     end;
-   end;
-
-   Msg('Cropping NIfTI/Analyze image '+lFileName);
-   lOutHdr := lInHdr;
-   lImgSamples := lInHdr.dim[1]*lInHdr.dim[2]*lInHdr.dim[3];
-   lBPP := (lInHdr.bitpix div 8); //bytes per pixel
-   //lVolBytes := lImgSamples*lBPP;
-  if not NIFTIhdr_LoadImg (lFileName, lInHdr, lSrcBuffer, lImgOffset,lByteSwap) then  exit;
-   //Msg('Automatically Cropping image');
-    lBuffer := (@lSrcBuffer^[lImgOffset+1]);
-   GetMem(lBuffUnaligned ,(sizeof(single)*lImgSamples) + 16);
-   {$IFDEF FPC}
-   lImgBuffer :=align(lBuffUnaligned,16);
-   {$ELSE}
-   lImgBuffer := SingleP($fffffff0 and (integer(lBuffUnaligned)+15));
-   {$ENDIF}
-  case lInHdr.datatype of
-           kDT_UNSIGNED_CHAR : begin //8 bit
-             for lInc := 1 to lImgSamples do
-                 lImgBuffer^[lInc] := lBuffer^[lInc];
-             end;
-
-	  kDT_SIGNED_SHORT{,kDT_UINT16}: begin //16-bit int
-		l16Buf := SmallIntP(lBuffer );
-		if lByteSwap then begin
-                   for lInc := 1 to lImgSamples do
-			  lImgBuffer^[lInc] := Swap(l16Buf^[lInc]);
-                end else begin
-                    for lInc := 1 to lImgSamples do
-                        lImgBuffer^[lInc] := l16Buf^[lInc];
-                end;
-          end;//16bit
-          kDT_SIGNED_INT: begin
-		l32Buf := SingleP(lBuffer );
-		if lByteSwap then //unswap and convert integer to float
-			 for lInc := 1 to lImgSamples do
-			  lImgBuffer^[lInc] := (Swap4r4i(l32Buf^[lInc]))
-		else  //convert integer to float
-                      for lInc := 1 to lImgSamples do
-			  lImgBuffer^[lInc] := Conv4r4i(l32Buf^[lInc]);
-		end; //32-bit int
-	  kDT_FLOAT: begin
-		l32Buf := SingleP(lBuffer);
-                for lInc := 1 to lImgSamples do
-                    lImgBuffer[lInc] := l32Buf[lInc];
-		if lByteSwap then
-                   for lInc := 1 to lImgSamples do
-                       pswap4r(lImgBuffer^[lInc]);  //faster as procedure than function see www.optimalcode.com
-		for lInc := 1 to lImgSamples do
-			if specialsingle(lImgBuffer^[lInc]) then lImgBuffer^[lInc] := 0.0;
-		 //invert= for lInc := 1 to lImgSamples do l32Buf[lInc] := -l32Buf[lInc];
-          end; //32-bit float
-         else begin
-             Msg('Serious error: format not supported by Crop3D.');
-             exit;
-         end;
-   end; //case
-   FindDVCrop (lInHdr, lImgBuffer, lDorsalCrop,lVentralCrop, 5);
-   FindDVCrop2 (lInHdr, lDorsalCrop,lVentralCrop);
-   FindLRCrop (lInHdr, lImgBuffer, lLCrop,lRCrop,3,lDorsalCrop,lVentralCrop);//3% often sagittal scans near brain
-   FindAPCrop (lInHdr, lImgBuffer, lACrop,lPCrop, 5,lDorsalCrop,lVentralCrop);
-   FreeMem(lBuffUnaligned);
-   if (lDorsalCrop = 0) and (lVentralCrop = 0)
-      and (lLCrop = 0) and (lRCrop = 0)
-      and (lACrop = 0) and (lPCrop = 0) then begin
-             Msg('Crop 3D quitting: no need to delete slices.');
-             Freemem(lSrcBuffer);
-             exit;   //25 Sept 2008
-   end;
-   if (lDorsalCrop < 0) or (lVentralCrop < 0)
-      or (lLCrop < 0) or (lRCrop < 0)
-      or (lACrop < 0) or (lPCrop < 0) then begin
-             Msg('Crop 3D quitting: negative values should be impossible.');
-             beep;
-             Freemem(lSrcBuffer);
-   end;
-   //next compute size of cropped volume
-   lOutHdr.Dim[1] := lInHdr.Dim[1]-lLCrop-lRCrop;
-   lOutHdr.Dim[2] := lInHdr.Dim[2]-lACrop-lPCrop;
-   lOutHdr.Dim[3] := lInHdr.Dim[3]-lDorsalCrop-lVentralCrop;
-   //lVolBytes := lOutHdr.dim[1]*lOutHdr.dim[2]*lOutHdr.dim[3]*lBPP;
-   //next: readjust origin to take into account removed slices
-   //REQUIRES images to be aligned to nearest orthogonal to canonical space [1 0 0; 0 1 0; 0 0 1]
-   NIFTIhdr_SlicesToCoord (lInHdr,lLCrop,lPCrop,lVentralCrop, lXmm,lYmm,lZmm);
-   lOutHdr.srow_x[3] := lInHdr.srow_x[3] + lXmm;
-   lOutHdr.srow_y[3] := lInHdr.srow_y[3] + lYmm;
-   lOutHdr.srow_z[3] := lInHdr.srow_z[3] + lZmm;
-   lMat := Matrix3D (
-	lOutHdr.srow_x[0], lOutHdr.srow_x[1], lOutHdr.srow_x[2], lOutHdr.srow_x[3],
-	lOutHdr.srow_y[0], lOutHdr.srow_y[1], lOutHdr.srow_y[2], lOutHdr.srow_y[3],
-	lOutHdr.srow_z[0], lOutHdr.srow_z[1], lOutHdr.srow_z[2], lOutHdr.srow_z[3],
-	0, 0, 0, 1);
-   nifti_mat44_to_quatern( lMat,
-   lOutHdr.quatern_b,lOutHdr.quatern_c,lOutHdr.quatern_d,
-   lOutHdr.qoffset_x,lOutHdr.qoffset_y,lOutHdr.qoffset_z,
-                             lXmm, lYmm, lZmm, lOutHdr.pixdim[0]{QFac});
-   //note we write and read to the same buffer - we will always SHRINK output
-   //no need to byteswap data - we will save in the save format as stored
-
-
-   lOutPos := 0;
-   lInSliceSz := lInHdr.dim[1]*lInHdr.dim[2]*lBPP;
-   lInXSz := lInHdr.dim[1]*lBPP;
-   for lZ := 1 to lOutHdr.dim[3] do begin
-       lInZOffset := (lVentralCrop+lZ-1) * lInSliceSz;
-       for lY := 1 to lOutHdr.dim[2] do begin
-           lInYOffset := ((lPCrop+lY-1) * lInXSz) + lInZOffset + (lLCrop*lBPP);
-           for lX := 1 to lOutHdr.dim[1] do begin
-               for lB := 1 to lBPP do begin
-                   inc(lOutPos);
-                   lInPos := ((lX-1) * lBPP) + lInYOffset + lB;
-                   lBuffer^[lOutPos] := lBuffer^[lInPos];
-               end;
-           end;
-       end; //for Y
-   end; //for Z
-   lOutname := ChangeFilePrefix (lFileName,'c');
-   result := SaveNIfTICore (lOutName, lSrcBuffer, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-   Freemem(lSrcBuffer);
-end;
-
-
-(*function CropNIfTI(lFilename: string; lPrefs: TPrefs): string;
-var
-
-   lTempName,lExt,lNameWOExt: string;
-   lHdr: TNIFTIhdr;
-   lByteSwap: boolean;
-begin
-     result := '';
-     lExt := UpCaseExt(lFilename);
-     if not NIFTIhdr_LoadHdr (lFilename, lHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lFilename);
-        exit;
-     end;
-     //check orthogonal alignment....
-     if lHdr.dim[4] > 1 then begin
-        Msg('Only able to Crop 3D images (reorienting 4D could disrupt slice timing and diffusion directions.');
-        exit;
-     end;
-     //next - determine output format
-
-     if lExt = '.NII.GZ' then begin
-        //lTempName := lFilename;//ChangeFilePrefixExt (lFileName,'x');
-        ExtractFileParts (lFileName, lNameWOExt,lExt);
-        lTempName := lNameWOExt+'.nii';
-        Gunzip(lFileName,lTempName);
-        lFilename := lTempName;
-     end else //not gzip
-         lTempName := '';
-     //Next create reordered or trimmed image in the correct format
-     result := Crop(lFileName, lHdr,lByteSwap, lPrefs.SPM2,lPrefs.SingleNIIFile, false);
-
-     if (result <> '') and (lPrefs.GZip) then begin
-             GZipFile(lFileName,lFileName+'.gz',true);
-             result := result +'.gz';
-     end;
-
-     if lTempName <> '' then //delete GZip temp
-        deletefile(lTempName);
-end;  *)
-
-function SiemensPhase2RadiansNIfTI(lFilename: string; lPrefs: TPrefs): string;
-//convert any data format as 32-bit float....
-var
-   lInHdr,lOutHdr: TNIFTIhdr;
-   lOutname,lExt: string;
-   lMax,lMin,lImgSamples,lInc,lImgOffset: integer;
-   lSrcBuffer,lBuffer, lBuffUnaligned,lBuffAligned: bytep;
-   //l32Buf,
-   lImgBuffer: singlep;
-   l16Buf : SmallIntP;
-   lByteSwap: boolean;
-begin
-     result := '';
-     lExt := UpCaseExt(lFilename);
-     if not NIFTIhdr_LoadHdr (lFilename, lInHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lFilename);
-        exit;
-     end;
-   if lInHdr.datatype <> kDT_SIGNED_SHORT then begin
-         Msg('Unable to run SiemensPhase2Radians : input image must be 16-bit NIfTI image with intensities 0..4096 corresponding to -pi..+pi : '+lFilename);
-         exit;
-   end;
-   //Msg('SiemensPhase2Radians converting 16-bit image (0..4095) to 32-bit float (-pi..+pi).'+lFileName);
-   lOutHdr := lInHdr;
-   lOutHdr.datatype := kDT_FLOAT;
-   lOutHdr.bitpix := 32;
-   lOutHdr.scl_slope := 1;
-   lOutHdr.scl_inter := 0;
-   lImgSamples := lInHdr.dim[1]*lInHdr.dim[2]*lInHdr.dim[3]*lInHdr.dim[4];
-   if not NIFTIhdr_LoadImg (lFileName, lInHdr, lSrcBuffer, lImgOffset,lByteSwap) then  exit;
-   lBuffer := (@lSrcBuffer^[lImgOffset+1]);
-   GetMem(lBuffUnaligned ,(sizeof(single)*lImgSamples) + 16+kNIIImgOffset);
-   {$IFDEF FPC}
-   lBuffAligned := align(lBuffUnaligned,16);
-   {$ELSE}
-   lBuffAligned := ByteP($fffffff0 and (integer(lBuffUnaligned)+15));
-   {$ENDIF}
-   lInc := 1;
-   lImgBuffer := SingleP(@lBuffAligned^[kNIIImgOffset+lInc]);
-   l16Buf := SmallIntP(lBuffer );
-   if lByteSwap then 
-      for lInc := 1 to lImgSamples do
-         l16Buf^[lInc]  := Swap(l16Buf^[lInc]);
-   lMax := l16Buf^[1];
-   for lInc := 1 to lImgSamples do
-       if l16Buf^[lInc] > lMax then
-          lMax := l16Buf^[lInc];
-   lMin := l16Buf^[1];
-   for lInc := 1 to lImgSamples do
-       if l16Buf^[lInc] < lMin then
-          lMin := l16Buf^[lInc];
-   if (lMin < 0) or (lMax > 4096) then
-      Msg('Error: SiemensPhase2Radians expects input data with raw intensity ranging from 0..4096 (corresponding to -pi..+pi) - this image''s intensity is not in these bounds'+lFileName)
-   else begin
-       Msg('SiemensPhase2Radians converting 0..4096 to -pi..+pi '+ lFilename);
-       //Excel formula  =((A1-2048)/2048)*PI()
-       //fx(lMin,lMax);
-       for lInc := 1 to lImgSamples do
-           lImgBuffer^[lInc] := ((l16Buf^[lInc]-2048)/2048)*pi;
-       lOutname := ChangeFilePrefix (lFileName,'rad');
-       result := SaveNIfTICore (lOutName, lBuffAligned, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-   end;
-   Freemem(lBuffUnaligned);
-   Freemem(lSrcBuffer);
-end;
-
-
-
-end.
-
diff --git a/dcm2nii_prePARRECDTI/nii_math.pas b/dcm2nii_prePARRECDTI/nii_math.pas
deleted file mode 100755
index 0c02869..0000000
--- a/dcm2nii_prePARRECDTI/nii_math.pas
+++ /dev/null
@@ -1,600 +0,0 @@
-unit nii_math;
-
-interface
-{$H+}
-uses
-  //nii_types,nii_write,
-  niftiutil,dicomtypes,prefs,
-  define_types, sysutils, dialogsx,GraphicsMathLibrary;
-
-type
-  TNIFTIimg =  record
-   HdrName: string;
-   Hdr: TNIFTIhdr;
-   ByteSwap: boolean;
-   Offset: integer;
-   Buffer,i8: bytep;
-   f32: singlep;
-   i32 : longintP;
-   i16 : SmallIntP;
-  end;
-function RMS3d (lAName,lBName,lMaskName: string; lMaskThresh: single; lSaveOutput: boolean; lPrefs: TPrefs):double;
-function AddSlices (lAName: string; lSlices: integer; lPrefs: TPrefs):boolean;
-function ReportMinMax (lAName: string): boolean;
-function Hounsfield2NormScale (lAName: string; lPrefs: TPrefs):boolean;
-function ShrinkNII (lAName: string; lPrefs: TPrefs): boolean;
-
-implementation
-
-procedure CreateNII(var lNII: TNIfTIimg);
-begin
-     lNII.Buffer := nil;
-end;
-
-procedure FreeNII(var lNII: TNIfTIimg);
-begin
-     if lNII.Buffer <> nil then
-        Freemem(lNII.Buffer);
-end;
-
-function LoadHdrNII(lFilename: string; var lNII: TNIfTIimg): boolean;
-begin
-     result := false;
-     lNII.HdrName := lFilename;
-     if not NIFTIhdr_LoadHdr (lNII.HdrName, lNII.Hdr, lNII.ByteSwap) then begin;
-        ShowMsg('Header load error '+lFilename);
-        exit;
-     end;
-     result := true;
-end;
-
-function SubBound (lVal,lMin: integer): integer;
-begin
-    result := lVal;
-    if result < lMin then
-       result := lMin;
-end;
-
-function NonspatialDimensionsNII (lA: TNIFTIimg): integer;
-//returns sum of 4th, 5th, 6th and 7th dimension...
-begin
-     result := SubBound(lA.Hdr.dim[4],1)*SubBound(lA.Hdr.dim[5],1)*SubBound(lA.Hdr.dim[6],1)*SubBound(lA.Hdr.dim[7],1);
-end;
-
-function LoadImgNII(lFilename: string; var lNII: TNIfTIimg): boolean;
-begin
-     result := false;
-     if not LoadHdrNII(lFilename,lNII) then
-        exit;
-     if not NIFTIhdr_LoadImgRaw (False,lNII.HdrName, lNII.Hdr, lNII.Buffer, lNII.Offset,lNII.ByteSwap) then begin
-        ShowMsg('Image load error '+lFilename);
-        exit;
-     end;
-     NIFTIhdr_UnswapImg(lNII.Hdr,lNII.Buffer,lNII.Offset,lNII.ByteSwap);
-     lNII.f32 := SingleP(@lNII.Buffer^[lNII.Offset+1]);
-     lNII.i32 := LongintP(@lNII.Buffer^[lNII.Offset+1]);
-     lNII.i16 := SmallIntP(@lNII.Buffer^[lNII.Offset+1]);
-     lNII.i8 := ByteP(@lNII.Buffer^[lNII.Offset+1]);
-     result := true;
-end;
-
-procedure Force3DNII (var lNII: TNIFTIimg);
-begin
-     lNII.Hdr.dim[0] := 3;
-     lNII.Hdr.dim[4] := 1;
-     lNII.Hdr.Dim[5] := 1;
-     lNII.Hdr.Dim[6] := 1;
-     lNII.Hdr.Dim[7] := 1;
-end;
-
-function CreateEmptyImgNII(lHdr: TNIFTIHdr; var lNII: TNIfTIimg): boolean;
-var
-   lVol,lImgBytes,lFileBytes: integer;
-begin
-     result := false;
-     //FreeNII ???
-     lNII.Hdr := lHdr;
-     lNII.Offset := kNIIImgOffset;// (=352) bytes for creating .nii.gz files
-     lVol := NonspatialDimensionsNII(lNiI);
-     //lVol := lHdr.dim[4]+lHdr.dim[5]+lHdr.dim[6]+lHdr.dim[7]; //crepes
-     if lVol < 1 then
-      lVol := 1;
-     lImgBytes := lHdr.dim[1]*lHdr.dim[2]*lHdr.dim[3]*lVol*(lHdr.bitpix div 8);
-     if lImgBytes < 1 then
-        exit;
-     lFileBytes := lImgBytes+ kNIIImgOffset;
-     GetMem(lNII.Buffer,lFileBytes);
-     lNII.f32 := SingleP(@lNII.Buffer^[lNII.Offset+1]);
-     lNII.i32 := LongintP(@lNII.Buffer^[lNII.Offset+1]);
-     lNII.i16 := SmallIntP(@lNII.Buffer^[lNII.Offset+1]);
-     lNII.i8 := ByteP(@lNII.Buffer^[lNII.Offset+1]);
-     result := true;
-end;
-
-
-function MinMaxNII(var lNII: TNIfTIimg; lVol: integer; ApplyHdrScaling: boolean; var lMin,lMax: double): boolean;
-//returns min and max intensity in as Volume.
-//For 4D data, use lVol to specify the volume
-//  if lVol < 1 then all volumes
-var
-   i,lnVol,lVox,lVoxOffset: integer;
-begin
-     result := false;
-     if lNII.Buffer = nil then begin
-        showmsg('MinMax Error: image not loaded.');
-        exit;//image not loaded...
-     end;
-     lnVol := NonspatialDimensionsNII(lNiI);
-     lVox := lNII.Hdr.dim[1]*lNII.Hdr.dim[2]*lNII.Hdr.dim[3];
-     if (lnVol < 1) or (lVox < 1) then
-        exit;
-     lVoxOffset := 0;
-     if (lVol < 1) or (lVol > lnVol) then
-        lVox := lVox * lnVol
-     else
-         lVoxOffset := (lVol-1)*lVox;
-     case lNII.Hdr.datatype of
-          kDT_UNSIGNED_CHAR: begin
-                     lMin := lNII.i8^[lVoxOffset+1];
-                     lMax := lMin;
-                     for i := 1 to lVox do
-                         if lNII.i8^[lVoxOffset+i] > lMax then
-                            lMax := lNII.i8^[lVoxOffset+i];
-                     for i := 1 to lVox do
-                         if lNII.i8^[lVoxOffset+i] < lMin then
-                            lMin := lNII.i8^[lVoxOffset+i];
-             end;//CHAR
-          kDT_SIGNED_SHORT: begin
-                     lMin := lNII.i16^[lVoxOffset+1];
-                     lMax := lMin;
-                     for i := 1 to lVox do
-                         if lNII.i16^[lVoxOffset+i] > lMax then
-                            lMax := lNII.i16^[lVoxOffset+i];
-                     for i := 1 to lVox do
-                         if lNII.i16^[lVoxOffset+i] < lMin then
-                            lMin := lNII.i16^[lVoxOffset+i];
-             end;//kDT_SIGNED_SHORT
-          kDT_SIGNED_INT: begin
-                     lMin := lNII.i32^[lVoxOffset+1];
-                     lMax := lMin;
-                     for i := 1 to lVox do
-                         if lNII.i32^[lVoxOffset+i] > lMax then
-                            lMax := lNII.i32^[lVoxOffset+i];
-                     for i := 1 to lVox do
-                         if lNII.i32^[lVoxOffset+i] < lMin then
-                            lMin := lNII.i32^[lVoxOffset+i];
-             end;//kDT_SIGNED_INT
-          kDT_FLOAT: begin
-                     lMin := lNII.f32^[lVoxOffset+1];
-                     lMax := lMin;
-                     for i := 1 to lVox do
-                         if lNII.f32^[lVoxOffset+i] > lMax then
-                            lMax := lNII.f32^[lVoxOffset+i];
-                     for i := 1 to lVox do
-                         if lNII.f32^[lVoxOffset+i] < lMin then
-                            lMin := lNII.f32^[lVoxOffset+i];
-             end;//float
-     end;// datatype
-     if ApplyHdrScaling then begin
-        lMin := (lMin * lNII.hdr.scl_slope)+lNII.hdr.scl_inter;
-        lMax := (lMax * lNII.hdr.scl_slope)+lNII.hdr.scl_inter;
-     end;
-     result := true;
-end;
-
-function SameHdrDimNII (lA,lB: TNIFTIimg; lCheck4D, lCheckDataType: boolean): boolean;
-begin
-     result := SameHdrDim (lA.Hdr,lB.Hdr, lCheck4D, lCheckDataType);
-     if not result then
-        ShowMsg('Dimensions differ '+lA.Hdrname+' <> '+lB.HdrName);
-end;
-
-function ReportMinMax (lAName: string): boolean;
-label
-     666;
-var
-   lA: TNIfTIimg;
-   lMin,lMax: double;
-begin
-     result := false;
-     CreateNII(lA);
-     if not LoadImgNII(lAName,lA) then
-        goto 666;
-     if not MinMaxNII(lA,0,true,lMin,lMax) then
-        goto 666;
-     showmsg(lAName+kTab+'Min'+floattostr(lMin)+kTab+'Max:'+floattostr(lMax));
-     result := true;
-666:
-     FreeNII(lA);
-end;
-
-function Hounsfield2NormScale (lAName: string;  lPrefs: TPrefs):boolean;
-//Hounsfield scaled data in the range
-//Air	-1000
-//Fat	120
-//Water	0
-//Muscle	~40
-//Contrast	+130
-//Bone	>400 (typically ~1000)
-//problem 1: SPM assume 0 is dark [zero fills edges] - so we need to make minimum 0
-//note the contrast of interest is in the compressed range -100..+200
-//http://en.wikipedia.org/wiki/Hounsfield_units
-const
-     kUninterestingDarkUnits = 900; // e.g. -1000..-100
-     kInterestingMidUnits = 300; //e.g. -100..+300
-     kScaleRatio = 2;// increase dynamic range of interesting voxels by 3
-label
-     666;
-var
-   lA,lOut: TNIfTIimg;
-   lMin,lMax,lRange: double;
-   i,lVox: integer;
-   v16,lExtra,lMin16: SmallInt;
-   //lPrefs: TPrefs;
-   lOName: string;
-begin
-     result :=  false;
-     CreateNII(lA);
-     CreateNII(lOut);
-     if not LoadImgNII(lAName,lA) then
-        goto 666;
-     if lA.Hdr.datatype <> kDT_SIGNED_SHORT then begin
-        showmsg('Hounsfield2NormScale Error: Image datatype must be 16-bit integer : '+lAName);
-        goto 666;
-     end;
-     lVox := lA.Hdr.dim[1]*lA.Hdr.dim[2]*lA.Hdr.dim[3]*NonspatialDimensionsNII(lA);
-     if lVox < 1 then
-        goto 666;
-     if not MinMaxNII(lA,0,false,lMin,lMax) then
-        goto 666;
-     lRange := lMax-lMin;
-     if lRange < 1800 then begin
-        //note assume integer data type with scaling...
-        showmsg('Hounsfield2NormScale Error: dark to bright regions of a Hounsfield calibrated CT scan of the brain should exceed 1800 (air=-1000,bone=1000) : '+lAName);
-        goto 666;
-     end;
-     //create output
-     lOut.Hdr := lA.Hdr;
-     force3DNII(lOut);
-     lOut.Hdr.datatype := kDT_SIGNED_SHORT;
-     lOut.Hdr.scl_slope := 1;
-     lOut.Hdr.scl_inter := 0;
-     lOut.ByteSwap := false;
-     CreateEmptyImgNII(lOut.Hdr, lOut);
-     //translate values
-     lMin16 := round(lMin);
-     case lA.Hdr.datatype of
-          kDT_SIGNED_SHORT: begin
-             for i := 1 to lVox do begin
-                 v16 := lA.i16^[i]-lMin16;
-                 lExtra := v16-kUninterestingDarkUnits;
-                 if lExtra > kInterestingMidUnits then
-                    lExtra := kInterestingMidUnits;
-                 if lExtra > 0 then
-                    lExtra := lExtra*kScaleRatio
-                 else
-                     lExtra := 0;
-                 lOut.i16^[i] := v16+lExtra;
-             end;
-             lOut.i16^[1] := 0;//ANTS uses this voxel for background color
-          end;//kDT_SIGNED_SHORT
-          else begin
-                  Showmsg('Unsupported datatype');
-          end;//float
-     end;// datatype
-     //Save data
-     lOName := ChangeFilePrefix(lAName,'x');
-     //SetDefaultPrefs (lPrefs);
-     //lOName := lAName;
-     //lPrefs.gzip := true;
-     SaveNIfTICore (lOName, lOut.Buffer, kNIIImgOffset+1, lOut.Hdr, lPrefs,lOut.ByteSwap);
-     result := true;
-666:
-     FreeNII(lA);
-     FreeNII(lOut);
-end;
-
-function RMS3d (lAName,lBName,lMaskName: string; lMaskThresh: single; lSaveOutput: boolean; lPrefs: TPrefs):double;
-//Determines Root Mean Square Error between A and B
-// both A and B are 3D images
-//   Mean for each voxel sqrt(X^2+Y^2+Z^2)
-//OPTIONAL: Mask image (set name to '' to ignore)
-const
-NaN : double = 1/0;
-kErrorStr = 'RMS';
-label
-     666;
-var
-   lA,lB,lMask,lOut: TNIfTIimg;
-   lSum,lRMS: double;
-   lV,lVox,lCount,lMaskCount: integer;
-   lUseMask: boolean;
-   //lPrefs: TPrefs;
-   lOName: string;
-begin
-     result :=  0;
-     lUseMask := false;
-     CreateNII(lA);
-     CreateNII(lB);
-     CreateNII(lMask);
-     CreateNII(lOut);
-     if not LoadImgNII(lAName,lA) then
-        goto 666;
-     if not LoadImgNII(lBName,lB) then
-        goto 666;
-     if not SameHdrDimNII(lA,lB,true,true) then
-        goto 666;
-     if NonspatialDimensionsNII(lA) <> 3 then begin
-      ShowMsg('Image must have 3 volumes [not '+inttostr(NonspatialDimensionsNII(lA))+'] ' +lAName);
-      goto 666;
-     end;
-     lVox := lA.Hdr.Dim[1]*lA.Hdr.Dim[2] * lA.Hdr.Dim[3];
-     if lVox < 1 then
-      goto 666;
-     case lA.Hdr.datatype of
-          kDT_FLOAT:;//lBPP := 4;
-         else begin
-             ShowMsg(kErrorStr+' datatype not supported.');
-             exit;
-         end;
-     end; //case
-     //next lines: mask....
-     if (lMaskName <> '') and (not fileexists(lMaskName)) then
-        ShowMsg(kErrorStr+'unable to find mask '+lMaskName)
-     else if (lMaskName <> '') and (fileexists(lMaskName)) then begin
-        lUseMask := true;
-        if not LoadImgNII(lMaskName,lMask) then
-           goto 666;
-        if lMask.Hdr.datatype <> kDT_FLOAT then begin
-           ShowMsg(kErrorStr+'datatype not supported. '+lMaskName);
-           goto 666;
-        end;
-        if not SameHdrDimNII(lA,lMask,true,true) then
-           goto 666;
-     end; //mask
-     //output
-     if lSaveOutput then begin
-        lOut.Hdr := lA.Hdr;
-        force3DNII(lOut);
-        lOut.Hdr.datatype := kDT_FLOAT;
-        lOut.ByteSwap := false;
-        CreateEmptyImgNII(lOut.Hdr, lOut);
-        for lV := 1 to lVox do
-            lOut.f32^[lV] := 0;
-     end;
-     lSum:= 0;
-     lCount := 0;
-     lMaskCount := 0;
-     case lA.Hdr.datatype of
-          kDT_FLOAT: begin
-             for lV := 1 to lVox do begin
-               if (not (lUseMask)) or ((not SpecialSingle(lMask.f32^[lV])) and (lMask.f32^[lV]> lMaskThresh)) then begin
-                 inc(lMaskCount);
-                 if (not SpecialSingle(lA.f32^[lV])) and (not SpecialSingle(lA.f32^[lV+lVox])) and (not SpecialSingle(lA.f32^[lV+lVox+lVox]))
-                  and (not SpecialSingle(lB.f32^[lV])) and (not SpecialSingle(lB.f32^[lV+lVox])) and (not SpecialSingle(lB.f32^[lV+lVox+lVox])) then begin
-                 //if true then begin
-                      inc(lCount);
-                     lRMS :=  sqrt(sqr(lA.f32^[lV]-lB.f32^[lV])+ sqr(lA.f32^[lV+lVox]-lB.f32^[lV+lVox])+sqr(lA.f32^[lV+lVox+lVox]-lB.f32^[lV+lVox+lVox]));
-                      if (lSaveOutput)  then begin
-                         try   //switch from double to single precision...
-                            lOut.f32^[lV] := lRMS;
-                         except
-                             lOut.f32^[lV] := NAN;
-                         end; //except
-                      end;
-                      lSum := lSum + lRMS;
-                 end; //not special - i.e. NaN
-
-              end;//in mask
-             end;//each 3D voxel
-          end; //kDT_FLOAT
-     end;//case of datatype
-
-     if lMaskCount = 0 then
-        ShowMsg(kErrorStr+' No voxels greater than '+floattostr(lMaskThresh)+' in mask '+lMaskName)
-     else if lCount = 0 then
-        ShowMsg(kErrorStr+' No valid voxels. All NaN?')
-     else if lSaveOutput then begin
-          lOName := ChangeFilePrefix(lAName,'Xrms');
-          //SetDefaultPrefs (lPrefs);
-          SaveNIfTICore (lOName, lOut.Buffer, kNIIImgOffset+1, lOut.Hdr, lPrefs,lOut.ByteSwap);
-     end;
-     if lCount > 0 then
-      result := lSum/lCount;
-666:
-     FreeNII(lA);
-     FreeNII(lB);
-     FreeNII(lMask);
-     FreeNII(lOut);
-end;
-
-function AddSlices (lAName: string; lSlices: integer; lPrefs: TPrefs):boolean;
-const
-NaN : double = 1/0;
-kErrorStr = 'RMS';
-label
-     666;
-var
-   lA,lOut: TNIfTIimg;
-   lOffset,lV,lS,lI,lVolBytes,lSliceBytes: integer;
-   //lPrefs: TPrefs;
-   lOName: string;
-begin
-     result :=  false;
-     if lSlices < 1 then
-        exit;
-     CreateNII(lA);
-     CreateNII(lOut);
-     if not LoadImgNII(lAName,lA) then
-        goto 666;
-     lSliceBytes := lA.hdr.dim[1]*lA.hdr.dim[2]*trunc(((lA.Hdr.bitpix)+7)/8);
-     lVolBytes := lSliceBytes * lA.hdr.dim[3];
-     if (lSliceBytes < 1) or (lVolBytes < 1) then
-        goto 666;
-     lOut.Hdr := lA.Hdr;
-     force3DNII(lOut);
-     lOut.hdr.dim[3] := lOut.hdr.dim[3] + lSlices;
-     lOut.Hdr.datatype := kDT_FLOAT;
-     lOut.ByteSwap := false;
-     CreateEmptyImgNII(lOut.Hdr, lOut);
-     lI := 0;
-     //lOffset := 0;
-     lOffset := lSliceBytes * 10;
-     for lS :=1 to lSlices do
-         for lV := 1 to (lSliceBytes) do begin
-             inc(lI);
-             //lOut.i8^[lI] := 0;
-             lOut.i8^[lI] := lA.i8^[lV+lOffset]
-         end;
-     lSliceBytes := lSliceBytes * lSlices;
-     for lV := 1 to lVolBytes do
-         lOut.i8^[lV+lSliceBytes] := lA.i8^[lV];
-
-     //lOffset := 0;
-     lSliceBytes := lA.hdr.dim[1]*lA.hdr.dim[2]*trunc(((lA.Hdr.bitpix)+7)/8);
-     lI := 0;
-     lOffset := lSliceBytes * 10;
-     for lS :=1 to 18 do
-         for lV := 1 to (lSliceBytes) do begin
-             inc(lI);
-             //lOut.i8^[lI] := 0;
-             lOut.i8^[lI] := lA.i8^[lV+lOffset]
-         end;
-
-     lOName := ChangeFilePrefix(lAName,'x');
-     //SetDefaultPrefs (lPrefs);
-     if SaveNIfTICore (lOName, lOut.Buffer, kNIIImgOffset+1, lOut.Hdr, lPrefs,lOut.ByteSwap) <> '' then
-        result := true;
-666:
-     FreeNII(lA);
-     FreeNII(lOut);
-end;
-
-procedure RescaleHdr (var lHdr: TNIFTIHdr; lX,lY,lZ: double);
-var
-   lIn,lScale,lResidualMat: TMatrix;
-      dx, dy, dz: single;
-begin
-    lIn := Matrix3D (
-    lHdr.srow_x[0],lHdr.srow_x[1],lHdr.srow_x[2],lHdr.srow_x[3],
-    lHdr.srow_y[0],lHdr.srow_y[1],lHdr.srow_y[2],lHdr.srow_y[3],
-    lHdr.srow_z[0],lHdr.srow_z[1],lHdr.srow_z[2],lHdr.srow_z[3],
-    0,0,0,1);
-    lScale := Matrix3D   (lX,0,0,0,
-                         0,lY,0,0,
-                         0,0,lZ,0,
-                         0,0,0,1);
-    lResidualMat := MultiplyMatrices(lIn,lScale);
-  lHdr.srow_x[0] := lResidualMat.Matrix[1,1];
-  lHdr.srow_x[1] := lResidualMat.Matrix[1,2];
-  lHdr.srow_x[2] := lResidualMat.Matrix[1,3];
-  lHdr.srow_y[0] := lResidualMat.Matrix[2,1];
-  lHdr.srow_y[1] := lResidualMat.Matrix[2,2];
-  lHdr.srow_y[2] := lResidualMat.Matrix[2,3];
-  lHdr.srow_z[0] := lResidualMat.Matrix[3,1];
-  lHdr.srow_z[1] := lResidualMat.Matrix[3,2];
-  lHdr.srow_z[2] := lResidualMat.Matrix[3,3];
-  lHdr.srow_x[3] := lResidualMat.Matrix[1,4];
-  lHdr.srow_y[3] := lResidualMat.Matrix[2,4];
-  lHdr.srow_z[3] := lResidualMat.Matrix[3,4];
-  nifti_mat44_to_quatern( lResidualMat,
-   lHdr.quatern_b,lHdr.quatern_c,lHdr.quatern_d,
-   lHdr.qoffset_x,lHdr.qoffset_y,lHdr.qoffset_z,
-                             dx, dy, dz,lHdr.pixdim[0]  {QFac});
-end;
-
-function ShrinkNII(lAName: String; lPrefs: TPrefs): boolean;
-//Halves X and Y dimensions
-label
-     666;
-var
-   lOName: string;
-   lo,li,lx,lyz: integer;
-   lA,lOut: TNIfTIimg;
-begin
-     result := false;
-     CreateNII(lA);
-     CreateNII(lOut);
-     if not LoadImgNII(lAName,lA) then
-        goto 666;
-     if odd(lA.hdr.dim[1]) or odd(lA.hdr.dim[2]) then begin
-        ShowMsg('ShrinkNII error X and Y must be divisible by 2 '+inttostr(lA.hdr.dim[1])+' '+inttostr(lA.hdr.dim[2]));
-        goto 666;
-     end;
-     case lA.Hdr.datatype of
-          kDT_UNSIGNED_CHAR,kDT_SIGNED_SHORT , kDT_SIGNED_INT, kDT_FLOAT:;//lBPP := 4;
-         else begin
-             ShowMsg('ShrinkNII datatype not supported.');
-             exit;
-         end;
-     end; //case
-
-     lOut.Hdr := lA.Hdr;
-     force3DNII(lOut);
-     lOut.hdr.dim[1] := lOut.hdr.dim[1] div 2;
-     lOut.hdr.dim[2] := lOut.hdr.dim[2] div 2;
-     lOut.hdr.pixdim[1] := lOut.hdr.pixdim[1] * 2;
-     lOut.hdr.pixdim[2] := lOut.hdr.pixdim[2] * 2;
-     RescaleHdr(lOut.hdr,2,2,1);
-     lOut.ByteSwap := false;
-     CreateEmptyImgNII(lOut.Hdr, lOut);
-     case lA.Hdr.datatype of
-          kDT_UNSIGNED_CHAR: begin
-              li := 1;
-              lo := 1;
-              for lyz := 1 to (lOut.hdr.dim[2]*lOut.hdr.dim[3]) do begin
-                      for lx := 1 to lOut.hdr.dim[1] do begin
-                          lOut.i8^[lo] := (lA.i8^[li]+lA.i8^[li+1]+lA.i8^[li]+lA.i8^[li+1]) div 4;
-                          inc(li,2); //skip voxel
-                          inc(lo);
-                      end;//x
-                      inc(li,lA.hdr.dim[1]); //skip line
-              end;//yz
-             end;//CHAR
-          kDT_SIGNED_SHORT: begin
-              li := 1;
-              lo := 1;
-              for lyz := 1 to (lOut.hdr.dim[2]*lOut.hdr.dim[3]) do begin
-                      for lx := 1 to lOut.hdr.dim[1] do begin
-                          lOut.i16^[lo] := (lA.i16^[li]+lA.i16^[li+1]+lA.i16^[li]+lA.i16^[li+1]) div 4;
-                          inc(li,2); //skip voxel
-                          inc(lo);
-                      end;//x
-                      inc(li,lA.hdr.dim[1]); //skip line
-              end;//yz
-             end;//kDT_SIGNED_SHORT
-          kDT_SIGNED_INT: begin
-              li := 1;
-              lo := 1;
-              for lyz := 1 to (lOut.hdr.dim[2]*lOut.hdr.dim[3]) do begin
-                      for lx := 1 to lOut.hdr.dim[1] do begin
-                          lOut.i32^[lo] := (lA.i32^[li]+lA.i32^[li+1]+lA.i32^[li]+lA.i32^[li+1]) div 4;
-                          inc(li,2); //skip voxel
-                          inc(lo);
-                      end;//x
-                      inc(li,lA.hdr.dim[1]); //skip line
-              end;//yz
-             end;//kDT_SIGNED_INT
-          kDT_FLOAT: begin
-              li := 1;
-              lo := 1;
-              for lyz := 1 to (lOut.hdr.dim[2]*lOut.hdr.dim[3]) do begin
-                      for lx := 1 to lOut.hdr.dim[1] do begin
-                          lOut.f32^[lo] := (lA.f32^[li]+lA.f32^[li+1]+lA.f32^[li]+lA.f32^[li+1]) / 4;
-                          inc(li,2); //skip voxel
-                          inc(lo);
-                      end;//x
-                      inc(li,lA.hdr.dim[1]); //skip line
-              end;//yz
-             end;//float
-     end;// datatype
-     lOName := ChangeFilePrefix(lAName,'d');
-     if SaveNIfTICore (lOName, lOut.Buffer, kNIIImgOffset+1, lOut.Hdr, lPrefs,lOut.ByteSwap) <> '' then
-        result := true;
-666:
-     FreeNII(lA);
-     FreeNII(lOut);
-end;
-
-
-end.
diff --git a/dcm2nii_prePARRECDTI/nii_orient.pas b/dcm2nii_prePARRECDTI/nii_orient.pas
deleted file mode 100755
index eaac9e7..0000000
--- a/dcm2nii_prePARRECDTI/nii_orient.pas
+++ /dev/null
@@ -1,726 +0,0 @@
-unit nii_orient;
-{$H+}
-//reorients a NIfTI image to canonical space ...
-//closest to canonical rotation matrix [1 0 0; 0 1 0; 0 0 1]
-interface
-
-uses
-{$IFDEF FPC}gzio2,{$ENDIF}
-  SysUtils,define_types,dicomtypes,niftiutil,GraphicsMathLibrary,prefs;
-
-function Reorient(var lHdrName: string; var lHdr: TNIFTIhdr; lPrefs: TPrefs; lOverwrite,lForce: boolean): string;
-//function SuperReorient(var lHdrName: string;  lPrefs: TPrefs):string;
-function LRFlip(lFilename: string; lPrefs: TPrefs): boolean;
-
-implementation
-uses dialogsx;
-(*procedure Mx(var lM: TMatrix);
-begin
-    Msg('=['+
-             floattostr(lM.matrix[1,1])+', '+floattostr(lM.matrix[1,2])+', '+floattostr(lM.matrix[1,3])+', '+floattostr(lM.matrix[1,4])+'; '+
-             floattostr(lM.matrix[2,1])+', '+floattostr(lM.matrix[2,2])+', '+floattostr(lM.matrix[2,3])+', '+floattostr(lM.matrix[2,4])+'; '+
-             floattostr(lM.matrix[3,1])+', '+floattostr(lM.matrix[3,2])+', '+floattostr(lM.matrix[3,3])+', '+floattostr(lM.matrix[3,4])+'; '+
-             ' 0, 0, 0, 1]');
-end;*)
-
-
-function NIfTIAlignedM (var lM: TMatrix): boolean;
-//check that diagonals are positive and all other cells are zero
-//negative diagonals suggests flipping...
-//non-negative other cells suggests the image is not pure axial
-var
-   lr,lc: integer;
-begin
-    result := false;
-    for lr := 1 to 3 do
-        for lc := 1 to 3 do begin
-            if (lr = lc) and (lM.matrix[lr,lc] <= 0) then
-               exit;
-            if (lr <> lc) and (lM.matrix[lr,lc] <> 0) then
-               exit;
-        end;
-    result := true;
-end;
-
-
-function NIfTIAligned (var lHdr: TNIFTIhdr): boolean;
-//check that diagonals are positive and all other cells are zero
-//negative diagonals suggests flipping...
-//non-negative other cells suggests the image is not pure axial
-var
-   lM: TMatrix;
-begin
-    lM := Matrix3D (
-    lHdr.srow_x[0],lHdr.srow_x[1],lHdr.srow_x[2],lHdr.srow_x[3],
-    lHdr.srow_y[0],lHdr.srow_y[1],lHdr.srow_y[2],lHdr.srow_y[3],
-    lHdr.srow_z[0],lHdr.srow_z[1],lHdr.srow_z[2],lHdr.srow_z[3],
-    0,0,0,1);
-    result := NIfTIAlignedM(lM);
-end;
-
-procedure FromMatrix (M: TMatrix; var  m11,m12,m13, m21,m22,m23,
-						   m31,m32,m33:  DOUBLE)  ;
-  BEGIN
-
-   m11 := M.Matrix[1,1];
-   m12 := M.Matrix[1,2];
-   m13 := M.Matrix[1,3];
-   m21 := M.Matrix[2,1];
-   m22 := M.Matrix[2,2];
-   m23 := M.Matrix[2,3];
-   m31 := M.Matrix[3,1];
-   m32 := M.Matrix[3,2];
-   m33 := M.Matrix[3,3];
-END {FromMatrix3D};
-
-function nifti_mat44_orthogx( lR :TMatrix; lPrefs: TPrefs): TMatrix;
-//returns rotation matrix required to orient image so it is aligned nearest to the identity matrix =
-// 1 0 0 0
-// 0 1 0 0
-// 0 0 1 0
-// 0 0 0 1
-//Therefore, image is approximately oriented in space
-var
-   lrow,lcol,lMaxRow,lMaxCol,l2ndMaxRow,l2ndMaxCol,l3rdMaxRow,l3rdMaxCol: integer;
-   r11,r12,r13 , r21,r22,r23 , r31,r32,r33, val,lAbsmax,lAbs: double;
-   Q,Flip: TMatrix;  //3x3
-begin
-   // load 3x3 matrix into local variables
-   FromMatrix(lR,r11,r12,r13,r21,r22,r23,r31,r32,r33);
-   Q := Matrix2D( r11,r12,r13,r21,r22,r23,r31,r32,r33);
-   // normalize row 1
-   val := Q.matrix[1,1]*Q.matrix[1,1] + Q.matrix[1,2]*Q.matrix[1,2] + Q.matrix[1,3]*Q.matrix[1,3] ;
-   if( val > 0.0 )then begin
-     val := 1.0 / sqrt(val) ;
-     Q.matrix[1,1] := Q.matrix[1,1]*val ;
-     Q.matrix[1,2] := Q.matrix[1,2]*val ;
-     Q.matrix[1,3] := Q.matrix[1,3]*val ;
-   end else begin
-     Q.matrix[1,1] := 1.0 ; Q.matrix[1,2] := 0.0; Q.matrix[1,3] := 0.0 ;
-   end;
-   // normalize row 2
-   val := Q.matrix[2,1]*Q.matrix[2,1] + Q.matrix[2,2]*Q.matrix[2,2] + Q.matrix[2,3]*Q.matrix[2,3] ;
-   if( val > 0.0 ) then begin
-     val := 1.0 / sqrt(val) ;
-     Q.matrix[2,1] := Q.matrix[2,1]* val ;
-     Q.matrix[2,2] := Q.matrix[2,2] * val ;
-     Q.matrix[2,3] := Q.matrix[2,3] * val ;
-   end else begin
-     Q.matrix[2,1] := 0.0 ; Q.matrix[2,2] := 1.0 ; Q.matrix[2,3] := 0.0 ;
-   end;
-   // normalize row 3
-   val := Q.matrix[3,1]*Q.matrix[3,1] + Q.matrix[3,2]*Q.matrix[3,2] + Q.matrix[3,3]*Q.matrix[3,3] ;
-   if( val > 0.0 ) then begin
-     val := 1.0 / sqrt(val) ;
-     Q.matrix[3,1] := Q.matrix[3,1] *val ;
-      Q.matrix[3,2] := Q.matrix[3,2] *val ;
-      Q.matrix[3,3] := Q.matrix[3,3] *val ;
-   end else begin
-     Q.matrix[3,1] := Q.matrix[1,2]*Q.matrix[2,3] - Q.matrix[1,3]*Q.matrix[2,2] ;  //* cross */
-     Q.matrix[3,2] := Q.matrix[1,3]*Q.matrix[2,1] - Q.matrix[1,1]*Q.matrix[2,3] ;  //* product */
-     Q.matrix[3,3] := Q.matrix[1,1]*Q.matrix[2,2] - Q.matrix[1,2]*Q.matrix[2,1] ;
-   end;
-   //next - find closest orthogonal coordinates - each matrix cell must be 0,-1 or 1
-   //First: find axis most aligned to a principal axis
-   lAbsmax := 0;
-   lMaxRow := 1;
-   lMaxCol := 1;
-   for lrow := 1 to 3 do begin
-       for lcol := 1 to 3 do begin
-           lAbs := abs(Q.matrix[lrow,lcol]);
-           if lAbs > lAbsMax then begin
-              lAbsmax := lAbs;
-              lMaxRow := lRow;
-              lMaxCol := lCol;
-           end;
-       end; //for rows
-   end; //for columns
-   //Second - find find axis that is 2nd closest to principal axis
-   lAbsmax := 0;
-   l2ndMaxRow := 2;
-   l2ndMaxCol := 2;
-   for lrow := 1 to 3 do begin
-       for lcol := 1 to 3 do begin
-           if (lrow <> lMaxRow) and (lCol <> lMaxCol) then begin
-              lAbs := abs(Q.matrix[lrow,lcol]);
-              if lAbs > lAbsMax then begin
-                 lAbsmax := lAbs;
-                 l2ndMaxRow := lRow;
-                 l2ndMaxCol := lCol;
-              end; //new max
-           end; //do not check MaxRow/MaxCol
-       end; //for rows
-   end; //for columns
-   //next - no degrees of freedom left: third prinicple axis is the remaining axis
-   if ((lMaxRow = 1) or (l2ndMaxRow = 1)) and ((lMaxRow = 2) or (l2ndMaxRow = 2)) then
-      l3rdMaxRow := 3
-   else if ((lMaxRow = 1) or (l2ndMaxRow = 1)) and ((lMaxRow = 3) or (l2ndMaxRow = 3)) then
-        l3rdMaxRow := 2
-   else
-       l3rdMaxRow := 1;
-   if ((lMaxCol = 1) or (l2ndMaxCol = 1)) and ((lMaxCol = 2) or (l2ndMaxCol = 2)) then
-      l3rdMaxCol := 3
-   else if ((lMaxCol = 1) or (l2ndMaxCol = 1)) and ((lMaxCol = 3) or (l2ndMaxCol = 3)) then
-        l3rdMaxCol := 2
-   else
-       l3rdMaxCol := 1;
-   //finally, fill in our rotation matrix
-   //cells in the canonical rotation transform can only have values 0,1,-1
-   result := Matrix3D( 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1);
-
-   if Q.matrix[lMaxRow,lMaxCol] < 0 then
-      result.matrix[lMaxRow,lMaxCol] := -1
-   else
-       result.matrix[lMaxRow,lMaxCol] := 1;
-
-   if Q.matrix[l2ndMaxRow,l2ndMaxCol] < 0 then
-      result.matrix[l2ndMaxRow,l2ndMaxCol] := -1
-   else
-       result.matrix[l2ndMaxRow,l2ndMaxCol] := 1;
-
-   if Q.matrix[l3rdMaxRow,l3rdMaxCol] < 0 then
-      result.matrix[l3rdMaxRow,l3rdMaxCol] := -1
-   else
-       result.matrix[l3rdMaxRow,l3rdMaxCol] := 1;
-   if  lPrefs.OrthoFlipXDim then begin
-      Flip := Matrix3D(-1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1);
-      Q := result;
-      result := multiplymatrices(Flip,Q); 
-   end;
-end;
-
-
-FUNCTION QuickInvertMatrix3D  (CONST Input:TMatrix):  TMatrix;
-//http://www.cellperformance.com/articles/2006/06/a_4x4_matrix_inverse_1.html
-//Most of the time in the video games, programmers are not doing a standard inverse matrix.
-//It is too expensive. Instead, to inverse a matrix, they consider it as orthonormal
-//and they just do a 3x3 transpose of the rotation part with a dot product for the translation.
-//Sometimes the full inverse algorithm is necessary....
-var
-   i,j: integer;
-begin
- result.size := Input.size;
- for i := 1 to 3 do
-     for j := 1 to 3 do
-         result.matrix[i,j] := input.matrix[j,i];
- //next - fill in edge if 3D
- if result.size <> size3D then
-    exit; //do not fill in final column for 2D matrices
- for i := 1 to 3 do
-     result.matrix[4,i] := 0;
- for i := 1 to 3 do
-     result.matrix[i,4] := 0;
- result.matrix[4,4] := 1;
-end;
-
-procedure FindMatrixPt (lX,lY,lZ: single; var lXout,lYOut,lZOut: single; var lMatrix: TMatrix);
-begin
-	lXOut := (lX*lMatrix.matrix[1,1])+(lY*lMatrix.matrix[1,2])+(lZ*lMatrix.matrix[1,3])+lMatrix.matrix[1,4];
-	lYOut := (lX*lMatrix.matrix[2,1])+(lY*lMatrix.matrix[2,2])+(lZ*lMatrix.matrix[2,3])+lMatrix.matrix[2,4];
-	lZOut := (lX*lMatrix.matrix[3,1])+(lY*lMatrix.matrix[3,2])+(lZ*lMatrix.matrix[3,3])+lMatrix.matrix[3,4];
-end;
-
-procedure CheckMin(var lX,lY,lZ,lXMin,lYMin,lZMin: single);
-begin
-	if lX < lXMin then lXMin := lX;
-	if lY < lYMin then lYMin := lY;
-	if lZ < lZMin then lZMin := lZ;
-end;
-
-procedure Mins (var lMatrix: TMatrix; var lHdr: TNIFTIhdr; var lXMin,lYMin,lZMin: single);
-var
-   lPos,lXc,lYc,lZc: integer;
-   lx,ly,lz: single;
-begin
-  FindMatrixPt(0,0,0,lX,lY,lZ,lMatrix);
-  lXMin := lX;
-  lYMin := lY;
-  lZMin := lZ;
-  for lPos := 1 to 7 do begin
-	if odd(lPos) then
-		lXc := lHdr.Dim[1]-1
-	else
-		lXc := 0;
-	if odd(lPos shr 1) then
-		lYc := lHdr.Dim[2]-1
-	else
-		lYc := 0;
-	if odd(lPos shr 2) then
-		lZc := lHdr.Dim[3]-1
-	else
-		lZc := 0;
-	FindMatrixPt(lXc,lYc,lZc,lX,lY,lZ,lMatrix);
-	CheckMin(lX,lY,lZ,lXMin,lYMin,lZMin);
-  end;
-end;
-
-function ReorientCore(var lHdrName: string; lPrefix: string; var lHdr: TNIFTIhdr; lPrefs: TPrefs; lOverwrite,lKeepOrigHdr: boolean; var lInMat,lRotMat: TMatrix): string;
-var
-   lOutHdr: TNIFTIhdr;
-   lOutName: string;
-   lResidualMat: TMatrix;
-   lInMinX,lInMinY,lInMinZ,lOutMinX,lOutMinY,lOutMinZ,
-   dx, dy, dz, QFac: single;
-   lStartX,lStartY,lStartZ,
-   lZ,lY,lX,lB,
-   lOutZ,lOutY,
-   lVol,lNumVol,lXInc, lYInc, lZInc,lBPP: integer;
-   lInPos,lVolBytes,lOutPos,lInOffset: integer;
-   lBufferIn,lBufferOut,lIBuffer,lOBuffer: bytep;
-   lByteSwap,lFlipX,lFlipY,lFlipZ: boolean;
-   lOutF,lInF: File;
-begin
-   result := '';
-   lOutHdr := lHdr;
-   //Some software uses negative pixdims to represent a spatial flip - now that the image is canonical, all dimensions are positive
-   lOutHdr.pixdim[1] := abs(lHdr.pixdim[1]);
-   lOutHdr.pixdim[2] := abs(lHdr.pixdim[2]);
-   lOutHdr.pixdim[3] := abs(lHdr.pixdim[3]);
-   //sort out dim1
-   lFlipX := false;
-   if lRotMat.Matrix[1,2] <> 0 then begin
-       lXinc := lHdr.dim[1];
-       lOutHdr.dim[1] := lHdr.dim[2];
-       lOutHdr.pixdim[1] := abs(lHdr.pixdim[2]);
-       if lRotMat.Matrix[1,2] < 0 then lFlipX := true
-   end else if lRotMat.Matrix[1,3] <> 0 then begin
-       lXinc := lHdr.dim[1]*lHdr.dim[2];
-       lOutHdr.dim[1] := lHdr.dim[3];
-       lOutHdr.pixdim[1] := abs(lHdr.pixdim[3]);
-       if lRotMat.Matrix[1,3] < 0 then lFlipX := true
-   end else begin
-       lXinc := 1;
-       if lRotMat.Matrix[1,1] < 0 then lFlipX := true
-   end;
-   //sort out dim2
-   lFlipY := false;
-   if lRotMat.Matrix[2,2] <> 0 then begin
-       lYinc := lHdr.dim[1];
-       //lOutHdr.dim[2] := lHdr.dim[2];
-       //lOutHdr.pixdim[2] := lHdr.pixdim[2];
-       if lRotMat.Matrix[2,2] < 0 then lFlipY := true
-   end else if lRotMat.Matrix[2,3] <> 0 then begin
-       lYinc := lHdr.dim[1]*lHdr.dim[2];
-       lOutHdr.dim[2] := lHdr.dim[3];
-       lOutHdr.pixdim[2] := abs(lHdr.pixdim[3]);
-       if lRotMat.Matrix[2,3] < 0 then lFlipY := true
-   end else begin
-       lYinc := 1;
-       lOutHdr.dim[2] := lHdr.dim[1];
-       lOutHdr.pixdim[2] := abs(lHdr.pixdim[1]);
-       if lRotMat.Matrix[2,1] < 0 then lFlipY := true
-   end;
-   //sort out dim3
-   lFlipZ := false;
-   if lRotMat.Matrix[3,2] <> 0 then begin
-       lZinc := lHdr.dim[1];
-       lOutHdr.dim[3] := lHdr.dim[2];
-       lOutHdr.pixdim[3] := lHdr.pixdim[2];
-       if lRotMat.Matrix[3,2] < 0 then lFlipZ := true;
-   end else if lRotMat.Matrix[3,3] <> 0 then begin
-       lZinc := lHdr.dim[1]*lHdr.dim[2];
-       //lOutHdr.dim[3] := lHdr.dim[3];
-       //lOutHdr.pixdim[3] := lHdr.pixdim[3];
-       if lRotMat.Matrix[3,3] < 0 then lFlipZ := true;
-   end else begin
-       lZinc := 1;
-       lOutHdr.dim[3] := lHdr.dim[1];
-       lOutHdr.pixdim[3] := lHdr.pixdim[1];
-       if lRotMat.Matrix[3,1] < 0 then lFlipZ := true;
-   end;
-   //details for writing...
-   lBPP := (lHdr.bitpix div 8); //bytes per pixel
-   lXinc := lXinc * lBPP;
-   lYinc := lYinc * lBPP;
-   lZinc := lZinc * lBPP;
-   lVolBytes := lHdr.dim[1]*lHdr.dim[2]*lHdr.dim[3]*lBPP;
-   //now write header...
-   //create Matrix of residual orientation...
-  lResidualMat := QuickInvertMatrix3D(lRotMat);
-  //the next steps are inelegant - the translation values are computed by brute force
-  //at the moment, our lResidualMat looks like this
-  //lResidualMat  =  [ 0  -1  0  0; 0  0 1 0; 1  0 0  0; 0 0 0 1];
-  //however, it should specify the dimensions in mm of the dimensions that are flipped
-  //However, note that whenever you reverse the direction of
-  //voxel coordinates, you need to include the appropriate offset
-  //in the 'a' matrix.  That is:
-  //lResidualMat = [0 0 1 0; -1 0 0 Nx-1; 0 1 0 0; 0 0 0 1]
-  //where Nx is the number of voxels in the x direction.
-  //So, if you took Nx=256, then for your values before, you'd get:
-  //TransRot  =  [ 0  -1  0  255; 0  0 1 0; 1  0 0  0; 0 0 0 1];
-  //Because we do not do this, we use the function mins to compute the translations...
-  //I have not implemented refined version yet - require sample volumes to check
-  //Ensure Nx is voxels not mm, etc....
-  //start of kludge
-  lResidualMat := multiplymatrices(lInMat,lResidualMat); //source
-  lResidualMat.Matrix[1,4] := 0;
-  lResidualMat.Matrix[2,4] := 0;
-  lResidualMat.Matrix[3,4] := 0;
-  Mins (lInMat, lHdr,lInMinX,lInMinY,lInMinZ);
-  Mins (lResidualMat, lOutHdr,lOutMinX,lOutMinY,lOutMinZ);
-  lResidualMat.Matrix[1,4] :=  lInMinX-lOutMinX;
-  lResidualMat.Matrix[2,4]  := lInMinY-lOutMinY;
-  lResidualMat.Matrix[3,4] := lInMinZ-lOutMinZ;
-  //End of kuldge
-  lOutHdr.srow_x[0] := lResidualMat.Matrix[1,1];
-  lOutHdr.srow_x[1] := lResidualMat.Matrix[1,2];
-  lOutHdr.srow_x[2] := lResidualMat.Matrix[1,3];
-  lOutHdr.srow_y[0] := lResidualMat.Matrix[2,1];
-  lOutHdr.srow_y[1] := lResidualMat.Matrix[2,2];
-  lOutHdr.srow_y[2] := lResidualMat.Matrix[2,3];
-  lOutHdr.srow_z[0] := lResidualMat.Matrix[3,1];
-  lOutHdr.srow_z[1] := lResidualMat.Matrix[3,2];
-  lOutHdr.srow_z[2] := lResidualMat.Matrix[3,3];
-  lOutHdr.srow_x[3] := lResidualMat.Matrix[1,4];
-  lOutHdr.srow_y[3] := lResidualMat.Matrix[2,4];
-  lOutHdr.srow_z[3] := lResidualMat.Matrix[3,4];
-  nifti_mat44_to_quatern( lResidualMat,
-   lOutHdr.quatern_b,lOutHdr.quatern_c,lOutHdr.quatern_d,
-   lOutHdr.qoffset_x,lOutHdr.qoffset_y,lOutHdr.qoffset_z,
-                             dx, dy, dz,lOutHdr.pixdim[0]  {QFac});
-   //read input
-   if not NIFTIhdr_LoadImg (lHdrName, lHdr, lIBuffer, lInOffset,lByteSwap) then  exit;
-
-   lNumVol := lOutHdr.dim[4];
-   if lNumVol < 1 then //hopefully this nevee happens
-      lNumVol := 1;
-   GetMem(lOBuffer,lNumVol*lVolBytes+kNIIImgOffset);
-   lBufferIn := (@liBuffer^[lInOffset+1]);
-   lOutPos := 0;
-   lBufferOut := (@loBuffer^[kNIIImgOffset+1+lOutPos]);
-   if lFlipX then
-      lXInc := -lXInc;
-   if lFlipY then
-      lYInc := -lYInc;
-   if lFlipZ then
-      lZInc := -lZInc;
-   for lVol := 1 to lNumVol do begin
-   //convert
-   if lFlipX then
-      lStartX := (lOutHdr.dim[1]-1)*-lXInc
-   else
-       lStartX := 0;
-   if lFlipY then
-      lStartX := lStartX + (lOutHdr.dim[2]-1)*-lYInc;
-   if lFlipZ then
-      lStartX := lStartX + (lOutHdr.dim[3]-1)*-lZInc;
-   lStartX := lStartX + ((lVol-1)*lVolBytes);
-   for lZ := 1 to lOutHdr.dim[3] do begin
-       lOutZ := lStartX + (lZ-1) * lZInc;
-       for lY := 1 to lOutHdr.dim[2] do begin
-           lOutY := ((lY-1) * lYInc) + lOutZ;
-           for lX := 1 to lOutHdr.dim[1] do begin
-               for lB := 1 to lBPP do begin
-                   inc(lOutPos);
-                   lInPos := ((lX-1) * lXInc) + lOutY + lB;
-                   lBufferOut^[lOutPos] := lBufferIn^[lInPos];
-               end;
-           end;
-       end; //for Y
-   end; //for Z
-  end;//For each volume
-   Freemem(lIBuffer);
-   if lOverwrite then
-      lOutName := lHdrName
-   else
-       lOutName := ChangeFilePrefix (lHdrName,lPrefix);
-     Msg('Reorienting as '+lOutName);
-   if lKeepOrigHdr then
-       result :=  SaveNIfTICore (lOutName, lOBuffer, kNIIImgOffset+1, lHdr, lPrefs,lByteSwap)
-   else
-       result :=  SaveNIfTICore (lOutName, lOBuffer, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-   Freemem(lOBuffer);
-end;//ReorientCore
-
-(*function ReorientCore(var lHdrName: string; lPrefix: string; var lHdr: TNIFTIhdr; lPrefs: TPrefs; lOverwrite: boolean; var lInMat,lRotMat: TMatrix): string;
-var
-   lOutHdr: TNIFTIhdr;
-   lOutName: string;
-   lResidualMat: TMatrix;
-   lInMinX,lInMinY,lInMinZ,lOutMinX,lOutMinY,lOutMinZ,
-   dx, dy, dz, QFac: single;
-   lStartX,lStartY,lStartZ,
-   lZ,lY,lX,lB,
-   lOutZ,lOutY,
-   lXInc, lYInc, lZInc,lBPP: integer;
-   lInPos,lVolBytes,lOutPos,lInOffset: integer;
-   lBufferIn,lBufferOut,lIBuffer,lOBuffer: bytep;
-   lByteSwap,lFlipX,lFlipY,lFlipZ: boolean;
-   lOutF,lInF: File;
-begin
-   result := '';
-   lOutHdr := lHdr;
-   if lOutHdr.dim[4] > 1 then begin
-       showmessage('Reorient only designed for 3D images.');
-       exit;
-   end;
-   //Some software uses negative pixdims to represent a spatial flip - now that the image is canonical, all dimensions are positive
-   lOutHdr.pixdim[1] := abs(lHdr.pixdim[1]);
-   lOutHdr.pixdim[2] := abs(lHdr.pixdim[2]);
-   lOutHdr.pixdim[3] := abs(lHdr.pixdim[3]);
-   //sort out dim1
-   lFlipX := false;
-   if lRotMat.Matrix[1,2] <> 0 then begin
-       lXinc := lHdr.dim[1];
-       lOutHdr.dim[1] := lHdr.dim[2];
-       lOutHdr.pixdim[1] := abs(lHdr.pixdim[2]);
-       if lRotMat.Matrix[1,2] < 0 then lFlipX := true
-   end else if lRotMat.Matrix[1,3] <> 0 then begin
-       lXinc := lHdr.dim[1]*lHdr.dim[2];
-       lOutHdr.dim[1] := lHdr.dim[3];
-       lOutHdr.pixdim[1] := abs(lHdr.pixdim[3]);
-       if lRotMat.Matrix[1,3] < 0 then lFlipX := true
-   end else begin
-       lXinc := 1;
-       if lRotMat.Matrix[1,1] < 0 then lFlipX := true
-   end;
-   //sort out dim2
-   lFlipY := false;
-   if lRotMat.Matrix[2,2] <> 0 then begin
-       lYinc := lHdr.dim[1];
-       //lOutHdr.dim[2] := lHdr.dim[2];
-       //lOutHdr.pixdim[2] := lHdr.pixdim[2];
-       if lRotMat.Matrix[2,2] < 0 then lFlipY := true
-   end else if lRotMat.Matrix[2,3] <> 0 then begin
-       lYinc := lHdr.dim[1]*lHdr.dim[2];
-       lOutHdr.dim[2] := lHdr.dim[3];
-       lOutHdr.pixdim[2] := abs(lHdr.pixdim[3]);
-       if lRotMat.Matrix[2,3] < 0 then lFlipY := true
-   end else begin
-       lYinc := 1;
-       lOutHdr.dim[2] := lHdr.dim[1];
-       lOutHdr.pixdim[2] := abs(lHdr.pixdim[1]);
-       if lRotMat.Matrix[2,1] < 0 then lFlipY := true
-   end;
-   //sort out dim3
-   lFlipZ := false;
-   if lRotMat.Matrix[3,2] <> 0 then begin
-       lZinc := lHdr.dim[1];
-       lOutHdr.dim[3] := lHdr.dim[2];
-       lOutHdr.pixdim[3] := lHdr.pixdim[2];
-       if lRotMat.Matrix[3,2] < 0 then lFlipZ := true;
-   end else if lRotMat.Matrix[3,3] <> 0 then begin
-       lZinc := lHdr.dim[1]*lHdr.dim[2];
-       //lOutHdr.dim[3] := lHdr.dim[3];
-       //lOutHdr.pixdim[3] := lHdr.pixdim[3];
-       if lRotMat.Matrix[3,3] < 0 then lFlipZ := true;
-   end else begin
-       lZinc := 1;
-       lOutHdr.dim[3] := lHdr.dim[1];
-       lOutHdr.pixdim[3] := lHdr.pixdim[1];
-       if lRotMat.Matrix[3,1] < 0 then lFlipZ := true;
-   end;
-   //details for writing...
-   lBPP := (lHdr.bitpix div 8); //bytes per pixel
-   lXinc := lXinc * lBPP;
-   lYinc := lYinc * lBPP;
-   lZinc := lZinc * lBPP;
-   lVolBytes := lHdr.dim[1]*lHdr.dim[2]*lHdr.dim[3]*lBPP;
-   //now write header...
-   //create Matrix of residual orientation...
-  lResidualMat := QuickInvertMatrix3D(lRotMat);
-  //the next steps are inelegant - the translation values are computed by brute force
-  //at the moment, our lResidualMat looks like this
-  //lResidualMat  =  [ 0  -1  0  0; 0  0 1 0; 1  0 0  0; 0 0 0 1];
-  //however, it should specify the dimensions in mm of the dimensions that are flipped
-  //However, note that whenever you reverse the direction of
-  //voxel coordinates, you need to include the appropriate offset
-  //in the 'a' matrix.  That is:
-  //lResidualMat = [0 0 1 0; -1 0 0 Nx-1; 0 1 0 0; 0 0 0 1]
-  //where Nx is the number of voxels in the x direction.
-  //So, if you took Nx=256, then for your values before, you'd get:
-  //TransRot  =  [ 0  -1  0  255; 0  0 1 0; 1  0 0  0; 0 0 0 1];
-  //Because we do not do this, we use the function mins to compute the translations...
-  //I have not implemented refined version yet - require sample volumes to check
-  //Ensure Nx is voxels not mm, etc....
-  //start of kludge
-  lResidualMat := multiplymatrices(lInMat,lResidualMat); //source
-  lResidualMat.Matrix[1,4] := 0;
-  lResidualMat.Matrix[2,4] := 0;
-  lResidualMat.Matrix[3,4] := 0;
-  Mins (lInMat, lHdr,lInMinX,lInMinY,lInMinZ);
-  Mins (lResidualMat, lOutHdr,lOutMinX,lOutMinY,lOutMinZ);
-  lResidualMat.Matrix[1,4] :=  lInMinX-lOutMinX;
-  lResidualMat.Matrix[2,4]  := lInMinY-lOutMinY;
-  lResidualMat.Matrix[3,4] := lInMinZ-lOutMinZ;
-  //End of kuldge
-  lOutHdr.srow_x[0] := lResidualMat.Matrix[1,1];
-  lOutHdr.srow_x[1] := lResidualMat.Matrix[1,2];
-  lOutHdr.srow_x[2] := lResidualMat.Matrix[1,3];
-  lOutHdr.srow_y[0] := lResidualMat.Matrix[2,1];
-  lOutHdr.srow_y[1] := lResidualMat.Matrix[2,2];
-  lOutHdr.srow_y[2] := lResidualMat.Matrix[2,3];
-  lOutHdr.srow_z[0] := lResidualMat.Matrix[3,1];
-  lOutHdr.srow_z[1] := lResidualMat.Matrix[3,2];
-  lOutHdr.srow_z[2] := lResidualMat.Matrix[3,3];
-  lOutHdr.srow_x[3] := lResidualMat.Matrix[1,4];
-  lOutHdr.srow_y[3] := lResidualMat.Matrix[2,4];
-  lOutHdr.srow_z[3] := lResidualMat.Matrix[3,4];
-
-  nifti_mat44_to_quatern( lResidualMat,
-   lOutHdr.quatern_b,lOutHdr.quatern_c,lOutHdr.quatern_d,
-   lOutHdr.qoffset_x,lOutHdr.qoffset_y,lOutHdr.qoffset_z,
-                             dx, dy, dz, QFac);
-   //read input
-   if not NIFTIhdr_LoadImg (lHdrName, lHdr, lIBuffer, lInOffset,lByteSwap) then  exit;
-
-   GetMem(lOBuffer,lVolBytes+kNIIImgOffset);
-   lBufferIn := (@liBuffer^[lInOffset+1]);
-   lOutPos := 0;
-   lBufferOut := (@loBuffer^[kNIIImgOffset+1+lOutPos]);
-   //convert
-   if lFlipX then begin
-      lStartX := (lOutHdr.dim[1]-1)*lXInc;
-      lXInc := -lXInc;
-   end else
-       lStartX := 0;
-   if lFlipY then begin
-      lStartX := lStartX + (lOutHdr.dim[2]-1)*lYInc;
-      lYInc := -lYInc;
-   end;
-   if lFlipZ then begin
-      lStartX := lStartX + (lOutHdr.dim[3]-1)*lZInc;
-      lZInc := -lZInc;
-   end;
-
-   for lZ := 1 to lOutHdr.dim[3] do begin
-       lOutZ := lStartX + (lZ-1) * lZInc;
-       for lY := 1 to lOutHdr.dim[2] do begin
-           lOutY := ((lY-1) * lYInc) + lOutZ;
-           for lX := 1 to lOutHdr.dim[1] do begin
-               for lB := 1 to lBPP do begin
-                   inc(lOutPos);
-                   lInPos := ((lX-1) * lXInc) + lOutY + lB;
-                   lBufferOut^[lOutPos] := lBufferIn^[lInPos];
-               end;
-           end;
-       end; //for Y
-   end; //for Z
-   Freemem(lIBuffer);
-   if lOverwrite then
-      lOutName := lHdrName
-   else
-       lOutName := ChangeFilePrefix (lHdrName,lPrefix);
-     Msg('Reorienting as '+lOutName);
-   result :=  SaveNIfTICore (lOutName, lOBuffer, kNIIImgOffset+1, lOutHdr, lPrefs,lByteSwap);
-   Freemem(lOBuffer);
-end;//ReorientCore   *)
-
-(*function SuperReorient(var lHdrName: string; {var lHdr: TNIFTIhdr;} lPrefs: TPrefs): string;
-//super-reorient generates  copies of the source image with different orthogonal rotations
-//useful for testing viewing software
-var
-  lRot,lRotMod: integer;
-  lByteSwap: boolean;
-  lInMat,lRotMat,lTempMat,lTransformMat,lNormalMat,lFlipMat: TMatrix;
-  lPrefix: string;
-  lHdr: TNIFTIhdr;
-begin
-         if not NIFTIhdr_LoadHdr (lHdrName, lHdr, lByteSwap) then begin
-            Msg('Unable to read as NifTI/Analyze' + lHdrName);
-            exit;
-         end;
-   result := '';
-   lInMat := Matrix3D (
-    lHdr.srow_x[0],lHdr.srow_x[1],lHdr.srow_x[2],lHdr.srow_x[3],
-    lHdr.srow_y[0],lHdr.srow_y[1],lHdr.srow_y[2],lHdr.srow_y[3],
-    lHdr.srow_z[0],lHdr.srow_z[1],lHdr.srow_z[2],lHdr.srow_z[3],
-    0,0,0,1);
-    lNormalMat := nifti_mat44_orthogx(lInMat);
-    //lRot := 3; begin
-    for lRot := 1 to 24 do begin
-       lRotMod := lRot mod 6;
-       case lRotMod of
-            1: lTempMat := Matrix3D(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1);
-            2: lTempMat := Matrix3D(1,0,0,0, 0,0,1,0, 0,1,0,0, 0,0,0,1);
-            3: lTempMat := Matrix3D(0,1,0,0, 1,0,0,0, 0,0,1,0, 0,0,0,1);
-            4: lTempMat := Matrix3D(0,1,0,0, 0,0,1,0, 1,0,0,0, 0,0,0,1);
-            5: lTempMat := Matrix3D(0,0,1,0, 1,0,0,0, 0,1,0,0, 0,0,0,1);
-            else lTempMat := Matrix3D(0,0,1,0, 0,1,0,0, 1,0,0,0, 0,0,0,1);
-       end;
-       case lRot of
-           1..6: lFlipMat := Eye3D;
-           7..12: lFlipMat := Matrix3D(-1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1);
-           13..18: lFlipMat := Matrix3D(1,0,0,0, 0,-1,0,0, 0,0,1,0, 0,0,0,1);
-           19..24: lFlipMat  := Matrix3D(1,0,0,0, 0,1,0,0, 0,0,-1,0, 0,0,0,1);
-       end;
-       lTransformMat := MultiplyMatrices(lTempMat,lFlipMat);
-       lRotMat := MultiplyMatrices(lNormalMat,lTransformMat);
-       lPrefix := floattostr(lTransformMat.Matrix[1,1])+floattostr(lTransformMat.Matrix[1,2])+floattostr(lTransformMat.Matrix[1,3])
-               +'_'+floattostr(lTransformMat.Matrix[2,1])+floattostr(lTransformMat.Matrix[2,2])+floattostr(lTransformMat.Matrix[2,3])
-               +'_'+floattostr(lTransformMat.Matrix[3,1])+floattostr(lTransformMat.Matrix[3,2])+floattostr(lTransformMat.Matrix[3,3]);
-       Msg(lPrefix);
-       result := ReorientCore(lHdrName, lPrefix,lHdr, lPrefs, false, lInMat,lRotMat);
-   end;
-end;//proc SuperReorient
-*)
-
-function Reorient(var lHdrName: string; var lHdr: TNIFTIhdr; lPrefs: TPrefs; lOverwrite,lForce: boolean): string;
-//returns output filename if successful
-//reslice an image so it is in canonical space
-var
-   lInMat,lRotMat: TMatrix;
-begin
-   result := '';
-   if (lHdr.dim[4] > 1) or (lHdr.dim[3] < 2) then begin
-      Msg('Can only orient 3D images '+inttostr(lHdr.dim[3])+' '+inttostr(lHdr.dim[4]));
-      exit;
-   end;
-   if (lHdr.dim[1] > lPrefs.MaxReorientMatrix) or (lHdr.dim[2] > lPrefs.MaxReorientMatrix) or(lHdr.dim[3] > lPrefs.MaxReorientMatrix) then begin
-      Msg('This image will not be reoriented (larger than MaxReorientMatrix= '+inttostr(lPrefs.MaxReorientMatrix));
-      exit;
-   end;
-   lInMat := Matrix3D (
-    lHdr.srow_x[0],lHdr.srow_x[1],lHdr.srow_x[2],lHdr.srow_x[3],
-    lHdr.srow_y[0],lHdr.srow_y[1],lHdr.srow_y[2],lHdr.srow_y[3],
-    lHdr.srow_z[0],lHdr.srow_z[1],lHdr.srow_z[2],lHdr.srow_z[3],
-    0,0,0,1);
-   if (not lForce) and (NIfTIAlignedM (lInMat)) then begin
-     result := lHdrName;
-     Msg('Image is already canonically oriented: '+lHdrName);
-     exit;
-   end;
-   lRotMat := nifti_mat44_orthogx( lInMat,lPrefs);
-   if NIfTIAlignedM (lRotMat) then begin
-     result := lHdrName;
-     Msg('According to header, image is already approximately canonically oriented');
-     exit; //already as close as possible
-   end;
-   result := ReorientCore(lHdrName, 'o',lHdr, lPrefs, lOverwrite,false, lInMat,lRotMat);
-end;
-
-function LRFlip(lFilename: string; lPrefs: TPrefs): boolean;
-//function Reorient(var lHdrName: string; var lHdr: TNIFTIhdr; lPrefs: TPrefs; lOverwrite,lForce: boolean): string;
-//returns output filename if successful
-//reslice an image so it is in canonical space
-var
-   lHdr: TNIFTIhdr;
-   lByteSwap: boolean;
-   lInMat,lRotMat: TMatrix;
-begin
-   result := false;
-   if not NIFTIhdr_LoadHdr (lFilename, lHdr, lByteSwap) then begin
-        Msg('Unable to read as NifTI/Analyze' + lFilename);
-        exit;
-   end;
-   if (lHdr.dim[1] > lPrefs.MaxReorientMatrix) or (lHdr.dim[2] > lPrefs.MaxReorientMatrix) or(lHdr.dim[3] > lPrefs.MaxReorientMatrix) then begin
-      Msg('This image will not be reoriented (larger than MaxReorientMatrix= '+inttostr(lPrefs.MaxReorientMatrix));
-      exit;
-   end;
-   lInMat := Matrix3D (
-    lHdr.srow_x[0],lHdr.srow_x[1],lHdr.srow_x[2],lHdr.srow_x[3],
-    lHdr.srow_y[0],lHdr.srow_y[1],lHdr.srow_y[2],lHdr.srow_y[3],
-    lHdr.srow_z[0],lHdr.srow_z[1],lHdr.srow_z[2],lHdr.srow_z[3],
-    0,0,0,1);
-
-   lRotMat := Matrix3D(
-    -1,0,0,0,
-    0,1,0,0,
-    0,0,1,0,
-    0,0,0,1);
-   result := (ReorientCore(lFilename, 'lr',lHdr, lPrefs, false,true, lInMat,lRotMat)<> '');
-end;
-
-
-end.
-
diff --git a/dcm2nii_prePARRECDTI/nii_reslice.pas b/dcm2nii_prePARRECDTI/nii_reslice.pas
deleted file mode 100755
index e64269f..0000000
--- a/dcm2nii_prePARRECDTI/nii_reslice.pas
+++ /dev/null
@@ -1,449 +0,0 @@
-unit nii_reslice;
-interface
-{$H+}
-uses
-    niftiutil,define_types,sysutils,dicomtypes,prefs;
-
-//function ResliceImgNIfTI (lTargetImgName,lSrcImgName,lOutputName: string): boolean;
-function Reslice2Targ (lSrcName,lTargetName,lDestName: string; lPrefs: TPrefs):string;
-
-implementation
-
-uses GraphicsMathLibrary, dialogsx;
-
-
-function Hdr2Mat (lHdr:  TNIFTIhdr): TMatrix;
-begin
-  Result := Matrix3D (
-  lHdr.srow_x[0],lHdr.srow_x[1],lHdr.srow_x[2],lHdr.srow_x[3],      // 3D "graphics" matrix
-  lHdr.srow_y[0],lHdr.srow_y[1],lHdr.srow_y[2],lHdr.srow_y[3],      // 3D "graphics" matrix
-  lHdr.srow_z[0],lHdr.srow_z[1],lHdr.srow_z[2],lHdr.srow_z[3],      // 3D "graphics" matrix
-						   0,0,0,1);
-end;
-
-
-(*procedure ReportMatrix (lM:TMatrix);
-const
-	kCR = chr (13);
-begin
-	showmessage(RealToStr(lM.matrix[1,1],6)+','+RealToStr(lM.matrix[1,2],6)+','+RealToStr(lM.matrix[1,3],6)+','+RealToStr(lM.matrix[1,4],6)+kCR+
-		RealToStr(lM.matrix[2,1],6)+','+RealToStr(lM.matrix[2,2],6)+','+RealToStr(lM.matrix[2,3],6)+','+RealToStr(lM.matrix[2,4],6)+kCR+
-		RealToStr(lM.matrix[3,1],6)+','+RealToStr(lM.matrix[3,2],6)+','+RealToStr(lM.matrix[3,3],6)+','+RealToStr(lM.matrix[3,4],6)+kCR
-    +RealToStr(lM.matrix[4,1],6)+','+RealToStr(lM.matrix[4,2],6)+','+RealToStr(lM.matrix[4,3],6)+','+RealToStr(lM.matrix[4,4],6)
-	  );
-end;     *)
-
-(*
-procedure  SPMmat(var lDestMat: TMatrix);
-//SPM matrices are indexed from 1
-//This function is only useful for direct comparisons with SPM
-var
-  lTemp,lVS: TMatrix;
-begin
-  lVS := Matrix3D (1,0,0,-1,
-    0,1,0,-1,
-    0,0,1,-1, 0,0,0,1);//VoxelShift
-  lTemp := lDestMat;
-  lDestMat := MultiplyMatrices(lTemp,lVS);
-end;*)
-
-procedure  Coord(var lV: TVector; var lMat: TMatrix);
-//transform X Y Z by matrix
-var
-  lXi,lYi,lZi: single;
-begin
-  lXi := lV.x; lYi := lV.y; lZi := lV.z;
-  lV.x := (lXi*lMat.matrix[1][1]+lYi*lMat.matrix[1][2]+lZi*lMat.matrix[1][3]+lMat.matrix[1][4]);
-  lV.y := (lXi*lMat.matrix[2][1]+lYi*lMat.matrix[2][2]+lZi*lMat.matrix[2][3]+lMat.matrix[2][4]);
-  lV.z := (lXi*lMat.matrix[3][1]+lYi*lMat.matrix[3][2]+lZi*lMat.matrix[3][3]+lMat.matrix[3][4]);
-
-end;
-
-procedure  Transposemat(var lMat: TMatrix);
-var
-  lTemp: TMatrix;
-  i,j: integer;
-begin
-  lTemp := lMat;
-  for i := 1 to lMat.size do
-    for j := 1 to lMat.size do
-      lMat.matrix[i,j] := lTemp.matrix[j,i];
-end;
-
-PROCEDURE gaussj(VAR a: TMatrix);//Invert a Matrix - see Numerical Recipes
-VAR
-   big,dum,pivinv: real;
-   n,i,icol,irow,j,k,l,ll: integer;
-   indxc,indxr,ipiv: array [1..4] of integer;
-BEGIN
-   icol := 1;//not used - avoids compiler warning
-   irow := 1;//not used - avoids compiler warning
-   n := a.size;
-   FOR j := 1 TO n DO BEGIN
-      ipiv[j] := 0
-   END;
-   FOR i := 1 TO n DO BEGIN
-      big := 0.0;
-      FOR j := 1 TO n DO BEGIN
-         IF (ipiv[j] <> 1) THEN BEGIN
-            FOR k := 1 TO n DO BEGIN
-               IF (ipiv[k] = 0) THEN BEGIN
-                  IF (abs(a.matrix[j,k]) >= big) THEN BEGIN
-                     big := abs(a.matrix[j,k]);
-                     irow := j;
-                     icol := k
-                  END
-               END ELSE IF (ipiv[k] > 1) THEN BEGIN
-                  writeln('pause 1 in GAUSSJ - singular matrix'); readln
-               END
-            END
-         END
-      END;
-      ipiv[icol] := ipiv[icol]+1;
-      IF (irow <> icol) THEN BEGIN
-         FOR l := 1 TO n DO BEGIN
-            dum := a.matrix[irow,l];
-            a.matrix[irow,l] := a.matrix[icol,l];
-            a.matrix[icol,l] := dum
-         END;
-      END;
-      indxr[i] := irow;
-      indxc[i] := icol;
-      IF (a.matrix[icol,icol] = 0.0) THEN BEGIN
-         Msg('pause 2 in GAUSSJ - singular matrix');
-         exit;
-      END;
-      pivinv := 1.0/a.matrix[icol,icol];
-      a.matrix[icol,icol] := 1.0;
-      FOR l := 1 TO n DO BEGIN
-         a.matrix[icol,l] := a.matrix[icol,l]*pivinv
-      END;
-      FOR ll := 1 TO n DO BEGIN
-         IF (ll <> icol) THEN BEGIN
-            dum := a.matrix[ll,icol];
-            a.matrix[ll,icol] := 0.0;
-            FOR l := 1 TO n DO BEGIN
-               a.matrix[ll,l] := a.matrix[ll,l]-a.matrix[icol,l]*dum
-            END;
-         END
-      END
-   END;
-   FOR l := n DOWNTO 1 DO BEGIN
-      IF (indxr[l] <> indxc[l]) THEN BEGIN
-         FOR k := 1 TO n DO BEGIN
-            dum := a.matrix[k,indxr[l]];
-            a.matrix[k,indxr[l]] := a.matrix[k,indxc[l]];
-            a.matrix[k,indxc[l]] := dum
-         END
-      END
-   END
-END;
-
-procedure SubVec (var lVx: TVector; lV0: TVector);
-begin
-  lVx.x := lVx.x - lV0.x;
-  lVx.y := lVx.y - lV0.y;
-  lVx.z := lVx.z - lV0.z;
-end;
-
-function Voxel2Voxel (var lDestHdr,lSrcHdr: TNIFTIhdr): TMatrix;
-//returns matrix for transforming voxels from one image to the other image
-//results are in VOXELS not mm
-var
-   lV0,lVx,lVy,lVz: TVector;
-   lDestMat,lSrcMatInv,lSrcMat: TMatrix;
-
-begin
-     //Step 1 - compute source coordinates in mm for 4 voxels
-     //the first vector is at 0,0,0, with the
-     //subsequent voxels being left, up or anterior
-     lDestMat := Hdr2Mat(lDestHdr);
-     //SPMmat(lDestMat);
-     lV0 := Vector3D  (0,0,0);
-     lVx := Vector3D  (1,0,0);
-     lVy := Vector3D  (0,1,0);
-     lVz := Vector3D  (0,0,1);
-     Coord(lV0,lDestMat);
-     Coord(lVx,lDestMat);
-     Coord(lVy,lDestMat);
-     Coord(lVz,lDestMat);
-     lSrcMat := Hdr2Mat(lSrcHdr);
-     //SPMmat(lSrcMat);
-     lSrcMatInv := lSrcMat;
-     gaussj(lSrcMatInv);
-     //the vectors should be rows not columns....
-     //therefore we transpose the matrix
-     Transposemat(lSrcMatInv);
-     //the 'transform' multiplies the vector by the matrix
-     lV0 := Transform (lV0,lSrcMatInv);
-     lVx := Transform (lVx,lSrcMatInv);
-     lVy := Transform (lVy,lSrcMatInv);
-     lVz := Transform (lVz,lSrcMatInv);
-     //subtract each vector from the origin
-     // this reveals the voxel-space influence for each dimension
-     SubVec(lVx,lV0);
-     SubVec(lVy,lV0);
-     SubVec(lVz,lV0);
-     result := Matrix3D(lVx.x,lVy.x,lVz.x,lV0.x,
-      lVx.y,lVy.y,lVz.y,lV0.y,
-      lVx.z,lVy.z,lVz.z,lV0.z, 0,0,0,1);
-end;
-
-procedure CopyHdrMat(var lTarg,lDest: TNIfTIHdr);
-//destination has dimensions and rotations of destination
-var
-   lI: integer;
-begin
-     //destination will have dimensions of target
-   lDest.dim[0] := 3; //3D
-   for lI := 1 to 3 do
-       lDest.dim[lI] := lTarg.dim[lI];
-   lDest.dim[4] := 1; //3D
-   //destination will have pixdim of target
-   for lI := 0 to 7 do
-       lDest.pixdim[lI] := lTarg.pixdim[lI];
-   lDest.xyzt_units := lTarg.xyzt_units; //e.g. mm and sec
-   lDest.qform_code := lTarg.qform_code;
-   lDest.sform_code := lTarg.sform_code;
-   lDest.quatern_b := lTarg.quatern_b;
-   lDest.quatern_c := lTarg.quatern_c;
-   lDest.quatern_d := lTarg.quatern_d;
-   lDest.qoffset_x := lTarg.qoffset_x;
-   lDest.qoffset_y := lTarg.qoffset_y;
-   lDest.qoffset_z := lTarg.qoffset_z;
-   for lI := 0 to 3 do begin
-       lDest.srow_x[lI] := lTarg.srow_x[lI];
-       lDest.srow_y[lI] := lTarg.srow_y[lI];
-       lDest.srow_z[lI] := lTarg.srow_z[lI];
-   end;
-end;
-
-function Reslice2Targ (lSrcName,lTargetName,lDestName: string; lPrefs: TPrefs):string;
-var
-   lPos,lXYs,lXYZs,lXs,lYs,lZs,lXi,lYi,lZi,lX,lY,lZ,
-   lXo,lYo,lZo,lMinY,lMinZ,lMaxY,lMaxZ,lSrcOffset,lBPP,lXYZ: integer;
-   lXrM1,lYrM1,lZrM1,lXreal,lYreal,lZreal,
-   lZx,lZy,lZz,lYx,lYy,lYz,
-   lInMinX,lInMinY,lInMinZ, lOutMinX,lOutMinY,lOutMinZ: single;
-   lXx,lXy,lXz: Singlep0;
-   l32fs,l32f : SingleP;
-   l32is,l32i : LongIntP;
-   l16is,l16i : SmallIntP;
-   l8i,l8is,lSrcBuffer,lBuffUnaligned,lBuffAligned: bytep;
-   lMat: TMatrix;
-      lTargHdr,lSrcHdr,lDestHdr: TNIFTIhdr;
-      lByteSwap: boolean;
-begin
-     result := '';
-     if not NIFTIhdr_LoadHdr (lSrcname, lSrcHdr, lByteSwap) then exit;
-     if not NIFTIhdr_LoadHdr (lTargetName, lTargHdr, lByteSwap) then exit;
-     case lSrcHdr.datatype of
-           kDT_UNSIGNED_CHAR : lBPP := 1;
-	  kDT_SIGNED_SHORT: lBPP := 2;
-          kDT_SIGNED_INT:lBPP := 4;
-	  kDT_FLOAT: lBPP := 4;
-         else begin
-             Msg('NII reslice error: datatype not supported.');
-             exit;
-         end;
-     end; //case
-     lMat := Voxel2Voxel (lTargHdr,lSrcHdr);
-     lDestHdr := lSrcHdr; //destination has the comments and voxel BPP of source
-     CopyHdrMat(lTargHdr,lDestHdr);//destination has dimensions and rotations of destination
-     lXs := lSrcHdr.Dim[1];
-     lYs := lSrcHdr.Dim[2];
-     lZs := lSrcHdr.Dim[3];
-
-     lXYs:=lXs*lYs; //slicesz
-     lXYZs := lXYs*lZs;
-     lX := lDestHdr.Dim[1];
-     lY := lDestHdr.Dim[2];
-     lZ := lDestHdr.Dim[3];
-     lDestHdr.Dim[4] := 1;
-     //load dataset
-     if not NIFTIhdr_LoadImg (lSrcName, lSrcHdr, lSrcBuffer, lSrcOffset,lByteSwap) then  exit;
-     NIFTIhdr_UnswapImg(lSrcHdr, lSrcBuffer, lSrcOffset,lByteSwap);//interpolation requires data is in native endian
-     l8is := (@lSrcBuffer^[lSrcOffset+1]);
-     GetMem(lBuffUnaligned ,(lBPP*lX*lY*lZ) + 16+kNIIImgOffset);
-     {$IFDEF FPC}
-     lBuffAligned := Align(lBuffUnaligned,16); // not commented - check this
-     {$ELSE}
-     lBuffAligned := ByteP($fffffff0 and (integer(lBuffUnaligned)+15));
-     {$ENDIF}
-     lPos := 1;
-     case lSrcHdr.datatype of
-          kDT_UNSIGNED_CHAR : l8i  := @lBuffAligned^[kNIIImgOffset+lPos];
-	  kDT_SIGNED_SHORT: l16i := SmallIntP(@lBuffAligned^[kNIIImgOffset+lPos] );
-          kDT_SIGNED_INT:l32i := LongIntP(@lBuffAligned^[kNIIImgOffset+lPos] );
-	  kDT_FLOAT: l32f := SingleP(@lBuffAligned^[kNIIImgOffset+lPos] );
-     end; //case
-     case lSrcHdr.datatype of
-           //kDT_UNSIGNED_CHAR : l8is := l8is;
-	  kDT_SIGNED_SHORT: l16is := SmallIntP(l8is );
-          kDT_SIGNED_INT:l32is := LongIntP(l8is );
-	  kDT_FLOAT: l32fs := SingleP(l8is );
-     end; //case
-     //next clear image
-     case lSrcHdr.datatype of
-           kDT_UNSIGNED_CHAR : for lPos := 1 to (lX*lY*lZ) do l8i^[lPos] := 0;
-	  kDT_SIGNED_SHORT: for lPos := 1 to (lX*lY*lZ) do l16i^[lPos] := 0;
-          kDT_SIGNED_INT:for lPos := 1 to (lX*lY*lZ) do l32i^[lPos] := 0;
-	  kDT_FLOAT: for lPos := 1 to (lX*lY*lZ) do l32f^[lPos] := 0;
-     end; //case
-     //now we can apply the transforms...
-     //build lookup table - speed up inner loop
-     getmem(lXx, lX*sizeof(single));
-     getmem(lXy, lX*sizeof(single));
-     getmem(lXz, lX*sizeof(single));
-     for lXi := 0 to (lX-1) do begin
-      lXx^[lXi] := lXi*lMat.matrix[1][1];
-      lXy^[lXi] := lXi*lMat.matrix[2][1];
-      lXz^[lXi] := lXi*lMat.matrix[3][1];
-     end;
-     //compute trilinear interpolation
-     lPos := 0;
-     for lZi := 0 to (lZ-1) do begin
-         //these values are the same for all voxels in the slice
-         // compute once per slice
-         lZx := lZi*lMat.matrix[1][3];
-         lZy := lZi*lMat.matrix[2][3];
-         lZz := lZi*lMat.matrix[3][3];
-         for lYi := 0 to (lY-1) do begin
-             //these values change once per row
-             // compute once per row
-             lYx :=  lYi*lMat.matrix[1][2];
-             lYy :=  lYi*lMat.matrix[2][2];
-             lYz :=  lYi*lMat.matrix[3][2];
-             for lXi := 0 to (lX-1) do begin
-                 //compute each column
-                 inc(lPos);
-
-                 lXreal := (lXx^[lXi]+lYx+lZx+lMat.matrix[1][4]);
-                 lYreal := (lXy^[lXi]+lYy+lZy+lMat.matrix[2][4]);
-                 lZreal := (lXz^[lXi]+lYz+lZz+lMat.matrix[3][4]);
-                 //need to test Xreal as -0.01 truncates to zero
-                 if (lXreal >= 0) and (lYreal >= 0{1}) and (lZreal >= 0{1}) and
-                     (lXreal < (lXs -1)) and (lYreal < (lYs -1) ) and (lZreal < (lZs -1))
-                  then begin
-                    //compute the contribution for each of the 8 source voxels
-                    //nearest to the target
-			              lXo := trunc(lXreal);
-			              lYo := trunc(lYreal);
-			              lZo := trunc(lZreal);
-			              lXreal := lXreal-lXo;
-			              lYreal := lYreal-lYo;
-			              lZreal := lZreal-lZo;
-                    lXrM1 := 1-lXreal;
-			              lYrM1 := 1-lYreal;
-			              lZrM1 := 1-lZreal;
-			              lMinY := lYo*lXs;
-			              lMinZ := lZo*lXYs;
-			              lMaxY := lMinY+lXs;
-			              lMaxZ := lMinZ+lXYs;
-                    inc(lXo);//images incremented from 1 not 0
-     case lSrcHdr.datatype of
-          kDT_UNSIGNED_CHAR : begin// l8is := l8is;
-                          l8i^[lPos] :=
-                           round (
-		 	   {all min} ( (lXrM1*lYrM1*lZrM1)*l8is^[lXo+lMinY+lMinZ])
-			   {x+1}+((lXreal*lYrM1*lZrM1)*l8is^[lXo+1+lMinY+lMinZ])
-			   {y+1}+((lXrM1*lYreal*lZrM1)*l8is^[lXo+lMaxY+lMinZ])
-			   {z+1}+((lXrM1*lYrM1*lZreal)*l8is^[lXo+lMinY+lMaxZ])
-			   {x+1,y+1}+((lXreal*lYreal*lZrM1)*l8is^[lXo+1+lMaxY+lMinZ])
-			   {x+1,z+1}+((lXreal*lYrM1*lZreal)*l8is^[lXo+1+lMinY+lMaxZ])
-			   {y+1,z+1}+((lXrM1*lYreal*lZreal)*l8is^[lXo+lMaxY+lMaxZ])
-			   {x+1,y+1,z+1}+((lXreal*lYreal*lZreal)*l8is^[lXo+1+lMaxY+lMaxZ]) );
-          end;
-	  kDT_SIGNED_SHORT: begin
-                          l16i^[lPos] :=
-                           round (
-		 	   {all min} ( (lXrM1*lYrM1*lZrM1)*l16is^[lXo+lMinY+lMinZ])
-			   {x+1}+((lXreal*lYrM1*lZrM1)*l16is^[lXo+1+lMinY+lMinZ])
-			   {y+1}+((lXrM1*lYreal*lZrM1)*l16is^[lXo+lMaxY+lMinZ])
-			   {z+1}+((lXrM1*lYrM1*lZreal)*l16is^[lXo+lMinY+lMaxZ])
-			   {x+1,y+1}+((lXreal*lYreal*lZrM1)*l16is^[lXo+1+lMaxY+lMinZ])
-			   {x+1,z+1}+((lXreal*lYrM1*lZreal)*l16is^[lXo+1+lMinY+lMaxZ])
-			   {y+1,z+1}+((lXrM1*lYreal*lZreal)*l16is^[lXo+lMaxY+lMaxZ])
-			   {x+1,y+1,z+1}+((lXreal*lYreal*lZreal)*l16is^[lXo+1+lMaxY+lMaxZ]) );
-          end;
-          kDT_SIGNED_INT:begin
-                          l32i^[lPos] :=
-                           round (
-		 	   {all min} ( (lXrM1*lYrM1*lZrM1)*l32is^[lXo+lMinY+lMinZ])
-			   {x+1}+((lXreal*lYrM1*lZrM1)*l32is^[lXo+1+lMinY+lMinZ])
-			   {y+1}+((lXrM1*lYreal*lZrM1)*l32is^[lXo+lMaxY+lMinZ])
-			   {z+1}+((lXrM1*lYrM1*lZreal)*l32is^[lXo+lMinY+lMaxZ])
-			   {x+1,y+1}+((lXreal*lYreal*lZrM1)*l32is^[lXo+1+lMaxY+lMinZ])
-			   {x+1,z+1}+((lXreal*lYrM1*lZreal)*l32is^[lXo+1+lMinY+lMaxZ])
-			   {y+1,z+1}+((lXrM1*lYreal*lZreal)*l32is^[lXo+lMaxY+lMaxZ])
-			   {x+1,y+1,z+1}+((lXreal*lYreal*lZreal)*l32is^[lXo+1+lMaxY+lMaxZ]) );
-          end;
-	  kDT_FLOAT: begin  //note - we do not round results - all intensities might be frational...
-                          l32f^[lPos] :=
-                            (
-		 	   {all min} ( (lXrM1*lYrM1*lZrM1)*l32fs^[lXo+lMinY+lMinZ])
-			   {x+1}+((lXreal*lYrM1*lZrM1)*l32fs^[lXo+1+lMinY+lMinZ])
-			   {y+1}+((lXrM1*lYreal*lZrM1)*l32fs^[lXo+lMaxY+lMinZ])
-			   {z+1}+((lXrM1*lYrM1*lZreal)*l32fs^[lXo+lMinY+lMaxZ])
-			   {x+1,y+1}+((lXreal*lYreal*lZrM1)*l32fs^[lXo+1+lMaxY+lMinZ])
-			   {x+1,z+1}+((lXreal*lYrM1*lZreal)*l32fs^[lXo+1+lMinY+lMaxZ])
-			   {y+1,z+1}+((lXrM1*lYreal*lZreal)*l32fs^[lXo+lMaxY+lMaxZ])
-			   {x+1,y+1,z+1}+((lXreal*lYreal*lZreal)*l32fs^[lXo+1+lMaxY+lMaxZ]) );
-          end;
-     end; //case
-
-                 end; //if voxel is in source image's bounding box
-             end;//z
-         end;//y
-     end;//z
-     //release lookup tables
-     freemem(lXx);
-     freemem(lXy);
-     freemem(lXz);
-     //check to see if image is empty...
-     lPos := 1;
-     case lSrcHdr.datatype of
-           kDT_UNSIGNED_CHAR : while (lPos <= (lX*lY*lZ)) and (l8i^[lPos] = 0) do inc(lPos);
-	  kDT_SIGNED_SHORT: while (lPos <= (lX*lY*lZ)) and (l16i^[lPos] = 0) do inc(lPos);
-          kDT_SIGNED_INT:while (lPos <= (lX*lY*lZ)) and (l32i^[lPos] = 0) do inc(lPos);
-	  kDT_FLOAT: while (lPos <= (lX*lY*lZ)) and (l32f^[lPos] = 0) do inc(lPos);
-     end; //case
-     if lPos <= (lX*lY*lZ) then begin //image not empty
-        result :=  SaveNIfTICore (lDestName, lBuffAligned, kNIIImgOffset+1, lDestHdr, lPrefs,lByteSwap);
-     end else begin
-         Msg('no voxels in output');
-     end;
-     Freemem(lBuffUnaligned);
-     Freemem(lSrcBuffer);
-end;
-
-(*function ResliceImgNIfTI (lTargetImgName,lSrcImgName,lOutputName: string): boolean;
-label
- 666;
-var
-   lReslice : boolean;
-   lDestHdr,lSrcHdr: TMRIcroHdr;
-   lSrcMat,lDestMat,lSrcMatINv,lDestMatInv,lMat: TMatrix;
-   lOffX,lOffY,lOffZ: single;
-   D: double;
-begin
-     result := false;
-     if not fileexists(lTargetImgName) then exit;
-     if not fileexists(lSrcImgName) then exit;
-     ImgForm.CloseImagesClick(nil);
-     lReslice := gBGImg.ResliceOnLoad;
-     gBGImg.ResliceOnLoad := false;
-     //if not HdrForm.OpenAndDisplayHdr(lTargetImgName,lDestHdr) then goto 666;
-     if not NIFTIhdr_LoadHdr(lTargetImgName, lDestHdr) then goto 666;
-     if not NIFTIhdr_LoadHdr(lSrcImgName, lSrcHdr) then goto 666;
-     if not ImgForm.OpenAndDisplayImg(lSrcImgName,false) then exit;
-     if not Qx(lDestHdr,lSrcHdr,lOutputName) then goto 666;
-
-     result := true;
-666:
-     if not result then
-        showmessage('Error applying transform '+lSrcImgName+'->'+lTargetImgName);
-     gBGImg.ResliceOnLoad := lReslice;
-end;  *)
-
-end.
diff --git a/dcm2nii_prePARRECDTI/notes.txt b/dcm2nii_prePARRECDTI/notes.txt
deleted file mode 100755
index 18e8743..0000000
--- a/dcm2nii_prePARRECDTI/notes.txt
+++ /dev/null
@@ -1,180 +0,0 @@
-Siemens DICOM always uses scanner coordinates to specify diffusion directions according to Michael Harms [mharms at conte.wustl.edu]
-
-
-We to specify a custom set of directions using entries in a DiffusionVectors.txt file even for the VB13 and VB17 product ep2d_diff sequence, although I think this capability requires a separately purchased license.  (What at one point was probably a WIP-only feature got built into the product sequence already by the time of VB13).
-
-Within that DiffusionVectors.txt file, one can specify whether the values are interpreted in a "xyz" or "prs" coordinate system.
-
->From old WIP_ep2d_diff documentation I have the following:
-------
-For the directive CoordinateSystem two different values are allowed:
-� "xyz" specifies that this vector set is to be played out in the magnet coordinate system.
-� "prs" makes the sequence to use the rotation matrix of the current slice, i.e. the phase-read-slice gradient axis system is used.
-------
-
-Everyone here at WU that uses custom directions always plays them out in the XYZ coordinate system.  HOWEVER, the coordinate system used in playing out the gradients should be irrelevant if one is reading the directions out of the **DICOM**.  That is, even if someone specified a custom gradient set to play out in the PRS coordinate system, the directions in the DICOM should still be STORED in the +LPS DICOM coordinate system, meaning that they would still need to be rotated for an obliqu [...]
-
-If your Siemen's contact, or your VD11 Skyra user indicates otherwise, then I think I'll pull my hair out!!
-
-
-Hi Chris, Jolinda,
-
-Ok, you guys are really not going to like me, but now that we seem to be reaching a consensus on the issue of rotation for VB13-VB17, I wanted to make sure you were aware of the issue of possibly incorrect bvecs under VB13, which is a completely orthogonal issue.
-
-First, I should note that the B_matrix entry in the CSA field of the DICOM is correct for VB13-VB17 (according to Siemens -- see below).
-These B_matrix entries include the impact of the imaging gradients on the B matrix.
-
-Unfortunately, the algorithm that Siemen's used to convert the B_matrix entry into an "equivalent" principle eigendirection yields incorrect results in some instances for VB13.  You may have noticed that the 2- norm of DiffusionGradientDirections (thenceforth DGD, as stored in the
-DICOM) are not necessarily 1.000 for VB13 data.  Both dcm2nii and MRIConvert return directions with a norm of exactly 1.0000, so both programs must be re-norming to exactly 1 behind the scenes as a final step prior to output.  
-
-HOWEVER, norming the magnitude of the direction to 1 is NOT sufficient to recover from the error in Siemen's algorithm.  For example, I have a case from a VB13 dataset (using a custom 30 direction set) where the norm for one of the DGD was only 0.16.  For that case, I computed the first eigenvector of the B_matrix (using Matlab's 'princomp' function).
-The resulting direction (which should be the "correct" one) differed from the DGD entry in the DICOM by 12.5 degrees, which indicates that simply re-norming the reported DGD values to 1.0 is indeed NOT SUFFICIENT to guarantee "correct" bvecs for VB13 data.
-
-This is a semi-known issue, and is presumably the reason that the DicomToNrrd and Nipy converters include options to re-derive the direction from the B_matrix.
-
-i.e.,
-http://mail.scipy.org/pipermail/nipy-devel/2010-September/004768.html
-
-and this snippet of email passed on to me by Darren Gitelman:
-
--------
-3) When I corresponded with Mark Scully and Hans Johnson who wrote the dicom2nrrd convertor they suggested that there are standard Siemens tags for the gradients and there are gradients that one obtains from the B matrix. They say the former is wrong. I had written to them that when DTIstudio extracted the gradients from the mosaic image it agreed with dicom2nrrd but only if I did not use the dicom2nrrd option "useBMatrixGradientDirections" which they told me to use.  There response was  [...]
-
-        As to DTIstudio agreeing with the output of DicomToNrrd when run
-        without useBMatrixGradientDirections, I assume DTIstudio is
-        reading the standard tags for direction?  If that's the case,
-        it's getting the same wrong data as DicomToNrrd gets when it
-        doesn't use the BMatrix.  The whole reason we made it possible
-        to use the BMatrix to calculate the gradients and B values is
-        because the standard tags were wrong in a subset of our Siemens
-        scans.
-
---------
-
-Unfortunately, I have no idea how frequently the DGD entries may be wrong under VB13, and whether or not custom gradient sets are more likely to be affected by the bug than "built-in" gradient sets.  I'm actually going to email Mark and Hans next to see if they have a sense for that.
-
-Also, I should mention that I was told by Siemen's that the DGD for VB17 are correct, and for VB15 are "correct" up to polarity.  Specifically, here is what Stefan Huwer of Siemen's emailed to me regarding this
-issue:
-
----------
-regarding software versions and issues with the diffusion gradient
-direction:
-
-VB13: B_matrix field correct, diffusion_direction sometimes wrong. 
-VB15: B_matrix field correct, diffusion_direction correct (up to polarity). 
-VB17: B_matrix correct, diffusion_direction correct
-
---------
-
-So, why do I bring this all up?  First, you (and others) should be aware of the issue, and perhaps I should make some additions to your Word document to explain the issue.  That said, I'm not expecting that either MRIConvert or dcm2nii would be modified to include an option to derive the directions from the B_matrix, as that is a rather major software addition.  However, it might be appropriate to include a warning message along the lines of the following for VB13 data:
-
-"Warning: bvecs are sometimes wrong for VB13 data, due to a bug in the algorithm by which Siemen's converted the B_matrix to a principle eigendirection.  The frequency and extent of this problem is unknown at this time".
-
-And for VB15 data:
-"Warning: Polarity of the bvecs may possibly be wrong for VB15 data."
-
-cheers,
--MH
-
---
-Michael Harms, Ph.D.
---------------------------------------------------------------------
-Conte Center for the Neuroscience of Mental Disorders Washington University School of Medicine Department of Psychiatry, Box 8134
-Renard Hospital, Room 6604           Tel: 314-747-6173
-660 South Euclid Ave.                Fax: 314-747-2182
-St. Louis, MO 63110                  Email: mharms at wustl.edu
---------------------------------------------------------------------
-
-
-FYI: It sounds like Hans Johnson and Mark Scully (emails in header
-below) have probably seen just about every "modern" vendor/software combination possible.  So, they might be a resource if you wanted to understand GE and Philips better, although it sounds like they might not have much experience with the oblique acquisition issue.
-
-cheers,
--MH
-
--------- Forwarded Message --------
-From: Johnson, Hans J <hans-johnson at uiowa.edu>
-To: Michael Harms <mharms at conte.wustl.edu>, Scully, Mark S <mark- scully at uiowa.edu>
-Cc: Joy Matsui <joy-matsui at uiowa.edu>
-Subject: Re: DicomToNrrd specifics
-Date: Thu, 31 Mar 2011 21:30:26 +0000
-Michael,
-
-We feel your pain.  We are working on a 32 site study, and we see just about every kind of data possible.
-
-I'm getting this from memory, so take that into consideration.
-
-I believe that VB13 had 2 gradients incorrect (gradient 14,15 in our 30 direction scan).
-
-The "useBMatrixGradientDirections" does not take scan obliquenss into account, it simply recomputes the values that should have been in the public dicom tags in the first place.  I am saying this without every having dealt with oblique DWI scans.
-
-====
-Just wait until you get to deal with phillips data :)  It is really fun!
-
-
---
-Hans J. Johnson, Ph.D.
-hans-johnson at uiowa.edu
-Assistant Professor of Psychiatry
-University of Iowa Carver College of Medicine
-W278 GH, 200 Hawkins Drive
-
-Iowa City, Iowa 52242
-Phone:  319-353-8587
-
-
-
-
-
-
-
------Original Message-----
-From: Michael Harms <mharms at conte.wustl.edu>
-Date: Thu, 31 Mar 2011 15:29:47 -0500
-To: Mark Scully <mark-scully at uiowa.edu>, Hans Johnson <hans-johnson at uiowa.edu>
-Cc: <mharms at conte.wustl.edu>
-Subject: DicomToNrrd specifics
-
-
-Hello Mark and Hans,
-
-I've been conversing with Jolinda Smith (MRIConvert), Chris Rorden
-(dcm2nii) and others (Darren Gittelman, Fred Tam) regarding some issues with getting bvecs from Siemens VB13, VB15, and VB17 DICOMs.
-
-Darren indicated to me that he had the following correspondence with you
-previously:
-
-----------
-3) When I corresponded with Mark Scully and Hans Johnson who wrote the dicom2nrrd convertor they suggested that there are standard Siemens tags for the gradients and there are gradients that one obtains from the B matrix. They say the former is wrong. I had written to them that when DTIstudio extracted the gradients from the mosaic image it agreed with dicom2nrrd but only if I did not use the dicom2nrrd option "useBMatrixGradientDirections" which they told me to use.  There response was  [...]
-
-        As to DTIstudio agreeing with the output of DicomToNrrd when run
-        without useBMatrixGradientDirections, I assume DTIstudio is
-        reading the standard tags for direction?  If that's the case,
-        it's getting the same wrong data as DicomToNrrd gets when it
-        doesn't use the BMatrix.  The whole reason we made it possible
-        to use the BMatrix to calculate the gradients and B values is
-        because the standard tags were wrong in a subset of our Siemens
-        scans.
-
---------
-
-It is my understanding, in emails with Stefan Huwer at Siemens, that the issue of possibly incorrect entries in the DiffusionGradientDirection
-("DGD") entry in the CSA portion of the Siemen's DICOM, is only for VB13 (although the polarity of the DGD's can be off by 180 degrees for VB15 data).  Is that your understanding and experience as well?
-
-Do you have any empirical sense of the frequency and extent of this problem under VB13?  e.g., What percentage of directions are affected on average?  And are certain directions consistently affected across different sessions?
-
-Also, on a different different issue, does DicomToNrrd rotate the DGD entries (or alternatively the B_matrix if using the "useBMatrixGradientDirections" option) for oblique acquisitions for VB13-VB17?
-
-[I know this latter issue would be easy enough to test, but I've already spent a ton of time on this annoying issue, so I hope you don't mind me just asking you directly, so that I don't have to learn another dicom converter.  I'm trying to see if I can't get agreement among various converter developers regarding the necessity of rotating the DGD entries (or B_matrix) for oblique VB13-VB17 acquisitions -- just today I brought Jolinda and Chris around to this position, so I wanted to see  [...]
-
-Thanks!
--MH
-
---
-Michael Harms, Ph.D.
---------------------------------------------------------------------
-Conte Center for the Neuroscience of Mental Disorders Washington University School of Medicine Department of Psychiatry, Box 8134
-Renard Hospital, Room 6604           Tel: 314-747-6173
-660 South Euclid Ave.                Fax: 314-747-2182
-St. Louis, MO 63110                  Email: mharms at wustl.edu
---------------------------------------------------------------------
diff --git a/dcm2nii_prePARRECDTI/paramstrs.pas b/dcm2nii_prePARRECDTI/paramstrs.pas
deleted file mode 100755
index ac8b6b4..0000000
--- a/dcm2nii_prePARRECDTI/paramstrs.pas
+++ /dev/null
@@ -1,381 +0,0 @@
-unit paramstrs;
-   {$H+}
-interface
-uses prefs,define_types;
-const
-kVers = 'Chris Rorden''s dcm2nii :: '+kMRIcronvers;
-{$Include ..\common\isgui.inc}
-procedure ProcessParamStrs;
-// procedure Testdcm2nii;
-procedure RecursiveFolderSearch (lFolderName,lOutDir: string; var lPrefs: TPrefs; lDepth: integer);
-implementation
-
-uses
-{$IFDEF GUI}gui, {$ENDIF}
-
-{$IFNDEF UNIX}
-    Windows,{$ENDIF}dialogsx, Classes,
-  inifiles,SysUtils,convert,sortdicom,dicom,parconvert,filename,dicomtypes,
-  nii_crop,nii_orient,nii_4dto3d,userdir;
-
-(*procedure RecursiveFolderSearch (lFolderName,lOutDir: string; var lPrefs: TPrefs; lDepth: integer);
-var
- lNewDir,lNewName,lFilename,lExt: String;
- lSearchRec: TSearchRec;
-begin
- if (lPrefs.CollapseFolders) then begin //Convert all folders in single step...
-    LoadFileList(lFolderName,lOutDir,lPrefs);
-    exit;
- end;
- lNewDir := lFolderName+PathDelim;
-{$IFDEF UNIX}
- if FindFirst(lNewDir+'*',faAnyFile-faSysFile,lSearchRec) = 0 then begin
-{$ELSE}
- if FindFirst(lNewDir+'*.*',faAnyFile-faSysFile,lSearchRec) = 0 then begin
-{$ENDIF}
-    lFilename := '';
-    repeat
-      lNewName := lNewDir+lSearchRec.Name;
-      if  (lSearchRec.Name <> '.') and (lSearchRec.Name <> '..') then begin
-            if DirExists(lNewName) then begin
-               if lDepth < lPrefs.RecursiveFolderDepth then begin
-                  if (lDepth = 0) and (lPrefs.RecursiveUseNameAppend) then begin
-                     lPrefs.NameAppend := extractfilename(lNewName)+'_';
-                     Msg('recursive base folder '+lPrefs.NameAppend);
-                  end;
-                  RecursiveFolderSearch(lNewName,lOutDir,lPrefs,lDepth+1);
-               end;
-               //exit;//4/4/2008
-            end else
-                lFilename := lNewname;
-      end;
-    until (FindNext(lSearchRec) <> 0);
-    if lFilename <> '' then begin
-	      	lExt := UpCaseExt(lFilename);
-                if (lExt = '.REC') or (lExt = '.PAR') then
-			LoadFileListPARREC(lFilename,lOutDir,lPrefs)
-		else begin
-			Msg('recursive conversion '+lFilename);
-                        LoadFileList(lFilename,lOutDir,lPrefs);
-                end;
-     end;
- end;
- FindClose(lSearchRec);
-end;  *)
-
-function IsDicom (lFilename: string): boolean;
-var
-   lDICOMdata: DICOMData;
-   lDynStr: string;
-   lHdrOK,lImgOK: boolean;
-   lPrefs: TPrefs;
-begin
-     result := false;
-     read_dicom_data(true,false{not verbose},true,true,true,true,false, lDICOMdata, lHdrOK, lImgOK, lDynStr,lFileName,lPrefs );
-     if (lHdrOK) and (lImgOK) then
-        result := true;
-end;
-
-procedure RecursiveFolderSearch (lFolderName,lOutDir: string; var lPrefs: TPrefs; lDepth: integer);
-var
- lNewDir,lFilename,lExt: String;
- lDirStrings: TStringList;
- lSearchRec: TSearchRec;
- lI: integer;
-begin
- if (lPrefs.CollapseFolders) then begin //Convert all folders in single step...
-    LoadFileList(lFolderName,lOutDir,lPrefs);
-    exit;
- end;
- lNewDir := lFolderName+PathDelim;
- //first check for deeper folders...
- {$IFDEF DEBUG}Msg('---Recursively searching '+lfoldername+' depth = '+inttostr(lDepth)); {$ENDIF}
- if lDepth < lPrefs.RecursiveFolderDepth then begin
-    lDirStrings := TStringList.Create;
-    {$IFDEF UNIX}
-    if FindFirst(lNewDir+'*',faDirectory,lSearchRec) = 0 then begin
-    {$ELSE}
-    if FindFirst(lNewDir+'*.*',faDirectory,lSearchRec) = 0 then begin
-    {$ENDIF}
-      lFilename := '';
-      repeat
-        if  (lSearchRec.Name <> '.') and (lSearchRec.Name <> '..') then begin
-          lFileName := lNewDir+lSearchRec.Name;
-          if DirExists(lFileName) then begin
-             (*if (lDepth = 0) and (lPrefs.RecursiveUseNameAppend) then begin
-                     lPrefs.NameAppend := extractfilename(lSearchRec.Name)+'_';
-                     Msg('recursive base folder '+lPrefs.NameAppend);
-             end;  *)
-             lDirStrings.Add(lNewDir+lSearchRec.Name);
-          end;
-        end;
-      until (FindNext(lSearchRec) <> 0);
-    end; //findfirst
-    FindClose(lSearchRec);
-    lDirStrings.Sort;
-    if lDirStrings.Count > 0 then
-     for lI := 0 to (lDirStrings.Count-1) do begin
-               if (lDepth = 0) and (lPrefs.RecursiveUseNameAppend) then begin
-                       lPrefs.NameAppend := extractfilename(lDirStrings[lI])+'_';
-                       Msg('recursive base folder '+lPrefs.NameAppend);
-               end;
-               RecursiveFolderSearch(lDirStrings[lI],lOutDir,lPrefs,lDepth+1);
-     end;
-    lDirStrings.free;
- end; //lDepth < lPrefs.RecursiveFolderDepth
- //next check for files in current folder...
- {$IFDEF UNIX}
- if FindFirst(lNewDir+'*',faAnyFile-faSysFile-faHidden,lSearchRec) = 0 then begin
-{$ELSE}
- if FindFirst(lNewDir+'*.*',faAnyFile-faSysFile-faHidden,lSearchRec) = 0 then begin
-{$ENDIF}
-        repeat
-          lFileName := lNewDir+lSearchRec.Name;
-          lExt := UpCaseExt(lFilename);
-          if (lFilename <> '') and (FileExists(lFileName)) and (not DirExists(lFileName)) and (not IsNiftiExt(lExt)) then begin
-                if (lExt = '.REC') or (lExt = '.PAR') then
-			LoadFileListPARREC(lFilename,lOutDir,lPrefs)
-		else if IsDicom (lFilename) then begin
-			Msg('Looking for DICOM files in folder with '+lFilename);
-                        LoadFileList(lFilename,lOutDir,lPrefs);
-                end else
-                    lFilename := '';
-          end else
-              lFilename :='';
-        until (FindNext(lSearchRec) <> 0) or (lFilename <> '');
-  end; //findfirst
-  FindClose(lSearchRec);
-end; //RecursiveFolderSearch
-
-function Bool2YN (lBool: boolean): char;
-begin
-	if lBool then
-		result := 'Y'
-	else
-		result := 'N';
-end;
-
-procedure CharBool (lCh: char; var lBool: boolean);
-begin
-	if lCh = 'Y' then
-		lBool := true;
-	if lCh = 'N' then
-		lBool := false;
-end;
-
-procedure ShowHelp (var lIniName: string; lPrefs: TPrefs);
-begin
-	 Msg('Either drag and drop or specify command line options:');
-	 Msg('  '+FilenameWOExt(paramstr(0))+' <options> <sourcenames>');
-	 Msg('OPTIONS:');
-         Msg(' -4 Create 4D volumes, else DTI/fMRI saved as many 3D volumes: Y,N = '+Bool2YN(lPrefs.FourD));
-	 Msg(' -a Anonymize [remove identifying information]: Y,N = '+Bool2YN(lPrefs.Anonymize));
-	 Msg(' -b load settings from specified inifile, e.g. ''-b C:\set\t1.ini''  ');
-	 Msg(' -c Collapse input folders: Y,N = '+Bool2YN(lPrefs.CollapseFolders));
-	 Msg(' -d Date in filename [filename.dcm -> 20061230122032.nii]: Y,N = '+Bool2YN(lPrefs.AppendDate));
-	 Msg(' -e events (series/acq) in filename [filename.dcm -> s002a003.nii]: Y,N = '+Bool2YN(lPrefs.AppendAcqSeries));
-	 Msg(' -f Source filename [e.g. filename.par -> filename.nii]: Y,N = '+Bool2YN(lPrefs.AppendFilename));
-	 Msg(' -g gzip output, filename.nii.gz [ignored if ''-n n'']: Y,N = '+Bool2YN(lPrefs.Gzip));
-	 Msg(' -i ID  in filename [filename.dcm -> johndoe.nii]: Y,N = '+Bool2YN(lPrefs.AppendPatientName));
-	 Msg(' -m manually prompt user to specify output format [NIfTI input only]: Y,N = '+Bool2YN(lPrefs.ManualNIfTIConv));
-	 Msg(' -n output .nii file [if no, create .hdr/.img pair]: Y,N = '+Bool2YN(lPrefs.SingleNIIFile));
-	 Msg(' -o Output Directory, e.g. ''C:\TEMP'' (if unspecified, source directory is used)');
-	 Msg(' -p Protocol in filename [filename.dcm -> TFE_T1.nii]: Y,N = '+Bool2YN(lPrefs.AppendProtocolName));
-	 Msg(' -r Reorient image to nearest orthogonal: Y,N ');
-	 //Msg(' -s SPM2/Analyze not SPM5/NIfTI [ignored if ''-n y'']: Y,N = '+Bool2YN(lPrefs.SPM2));
-         Msg(' -v Convert every image in the directory: Y,N = '+Bool2YN(lPrefs.EveryFile));
-         Msg(' -x Reorient and crop 3D NIfTI images: Y,N = '+Bool2YN(lPrefs.Autocrop));
-	 Msg('  You can also set defaults by editing '+lIniName);
-{$IFDEF UNIX}
-	 Msg('EXAMPLE: '+FilenameWOExt(paramstr(0))+' -a y /Users/Joe/Documents/dcm/IM_0116');
-{$ELSE}
-	 Msg('EXAMPLE: '+FilenameWOExt(paramstr(0))+' -a y -o C:\TEMP C:\DICOM\input1.par C:\input2.par');
-	 Msg('Hit <Enter> to exit.');
-	 MyReadLn;
-{$ENDIF}
-end; //proc ShowHelp
-
- (*procedure Testdcm2nii;
- var
-   lIniName : string;
-   lPrefs: TPrefs;
- begin
-  lIniName := IniName;//DefaultsDir('')+ParseFileName(ExtractFilename(paramstr(0) ) )+'.ini';
-     IniFile(True,lIniName, lPrefs);
-
-     ModifyAnalyze('C:\4d\4d.nii', lPrefs)
- end; *)
-
-function CustomIni: boolean; //returns true if user specifies a custom ini file
-var
-  i: integer;
-  lStr: string;
-begin
-  result := false;
-  
-  if (ParamCount < 1) then exit;
-  for i := 1 to ParamCount do begin
-    lStr := UpcaseStr(ParamStr(I));
-		if (length(lStr)>1) and (lStr[1] = '-') and (lStr[2] = 'B') then
-      result := true;
-  end;
-end;
-
-procedure ProcessParamStrs;
-var
-   lDir,lStr,lOutDir,lExt: String;
-   {$IFNDEF UNIX}lStartTime: DWord;{$ENDIF}
-   lHelpShown,lAbort,lSilent: boolean;
-   lCommandChar: Char;
-   lPrefs: TPrefs;
-   P,I: integer;
-  lIniName : string;
-begin
-  if (ParamCount > 0) then
-       ExitCode := 1;//assume error ... will be set to 0 on successful processing of any files...
-  SetDefaultPrefs (lPrefs);
-  DecimalSeparator := '.';
-  lHelpShown := false;
-  lAbort := false;
-  lSilent := false;
-  if not CustomIni then begin //if the user specifies a custom ini file, do not load the default file....
-    lIniName := IniName;//DefaultsDir('')+ParseFileName(ExtractFilename(paramstr(0) ) )+'.ini';
-    if fileexists (lIniName) then
-     IniFile(True,lIniName, lPrefs)
-    else
-      IniFile(True,changefileext(paramstr(0),'.init'), lPrefs); //this allows an administrator to create default startup
-  end;
-  lOutDir := '';
-  //dcm2nii will save nii as default, dcm2niiz will default to gzip, dcm2nii3d will make 3d files..
-  lStr := UpcaseStr(FilenameWOExt(paramstr(0)));
-  I := length(lStr);
-  if I > 1 then begin
-	lCommandChar := lStr[I];
-	if (lCommandChar = 'G') or (lCommandChar = 'R') then
-		lPrefs.SingleNIIFile := false
-	else if (lCommandChar = 'Z') then
-		lPrefs.Gzip := true;
-	for P := 1 to I do
-		if lStr[P] in ['0'..'9'] then
-			lCommandChar := lStr[P];
-	if (lCommandChar = '3')  then
-		lPrefs.FourD := false
-  end;
-  //now read filename
-  lStr := paramstr(0);
-  lStr := extractfilename(lStr);
-  lStr := string(StrUpper(PChar(lStr))) ;
-  if (ParamCount > 0) then begin
-	I := 0;
-	repeat
-	 lStr := '';
-	 repeat
-		inc(I);
-		if I = 1 then
-			lStr := ParamStr(I)
-		else begin
-			if lStr <> '' then
-			   lStr := lStr +' '+ ParamStr(I)
-			else
-				lStr := ParamStr(I);
-		end;
-		if (length(lStr)>1) and (lStr[1] = '-') and (ParamCount > I) then begin //special command
-		   lCommandChar := UpCase(lStr[2]);
-           inc(I);
-           lStr := ParamStr(I);
-		   {$IFDEF UNIX}
-		   if (lCommandChar <> 'O') and (lCommandChar <> 'B') then begin
-                      lStr := string(StrUpper(PChar(lStr))) ;  //do not upcase paths...
-		   end;
-		   {$ELSE}
-		   lStr := string(StrUpper(PChar(lStr))) ;
-		   {$ENDIF}
-		   case lCommandChar of
-				'4': CharBool(lStr[1],lPrefs.FourD);
-				'A': CharBool(lStr[1],lPrefs.Anonymize);
-        'C': CharBool(lStr[1],lPrefs.CollapseFolders);
-				'D': CharBool(lStr[1],lPrefs.AppendDate);
-				'E': CharBool(lStr[1],lPrefs.AppendAcqSeries);
-				'F': CharBool(lStr[1],lPrefs.AppendFilename);
-				'G': CharBool(lStr[1],lPrefs.Gzip);
-				'I': CharBool(lStr[1],lPrefs.AppendPatientName);
-				'M': CharBool(lStr[1],lPrefs.ManualNIfTIConv);
-				'N': CharBool(lStr[1],lPrefs.SingleNIIFile);
-				'P': CharBool(lStr[1],lPrefs.AppendProtocolName);
-                                'R': CharBool(lStr[1],lPrefs.enablereorient);
-				'S': CharBool(lStr[1],lPrefs.SPM2);
-				'V': CharBool(lStr[1],lPrefs.EveryFile);
-                                'X': CharBool(lStr[1],lPrefs.Autocrop);
-				'B': begin //load INI file
-					  lIniName := lStr;
-					  if fileexists(lIniName) then begin
-                                                 IniFile(True,lIniName, lPrefs);
-					 end else
-		                             Msg('0 ERROR: unable to find '+lIniName);
-                                     end;
-				'O': begin //output directory
-					  lOutDir := '';
-					  if direxists(lStr) then begin
-						 lOutDir := lStr;
-						 if lOutDir[length(lOutDir)] <> pathdelim then
-							lOutDir := lOutDir + pathdelim;
-					  end;
-					 end;
-		   end; //case lStr[2]
-		   lStr := '';
-		end; //special command
-	 until (I=ParamCount) or (fileexists(lStr)) or (lAbort);
-	 if (not lPrefs.AppendPatientName) and (not lPrefs.AppendProtocolName) and (not lPrefs.AppendAcqSeries) and (not lPrefs.AppendDate) and (not lPrefs.AppendFilename) then begin
-		 lPrefs.AppendPatientName := true;
-		 lPrefs.AppendProtocolName :=  true;
-	       	 lPrefs.AppendDate := true;
-		 lPrefs.AppendAcqSeries := true;
-	 end;
-         if direxists(lStr) then begin
-            RecursiveFolderSearch(lStr,lOutDir,lPrefs,0);
-            lPrefs.NameAppend := '';
-	 end else if fileexists(lStr) then begin
-                lDir := ExtractFileDir(lStr);
-                if lDir = '' then begin //since fileexists, file is in working directory
-                  lDir := GetCurrentDir;
-                  Msg('0 files in working directory '+lDir);
-                  EnsureDirEndsWithPathDelim(lDir);
-                  if fileexists(lDir + lStr) then
-                     lStr := lDir+ lStr;
-                end;
-		lExt := UpCaseExt(lStr);
-                if IsNiftiExt(lStr) then begin
-{$IFDEF GUI}
-        MainForm.ConvertDCM2NII(lStr,lPrefs);
-        //Msg('Please drag and drop NIfTI images onto dcm2niigui to convert them')
-{$ELSE}
-  ModifyAnalyze(lStr,lPrefs);
-{$ENDIF}
-		end else if (lExt = '.REC') or (lExt = '.PAR') then begin
-                    LoadFileListPARREC(lStr,lOutDir,lPrefs);
-                    if lPrefs.everyfile then
-                       exit;
-		end else begin
-                    {$IFNDEF UNIX}lStartTime := GetTickCount; {$ENDIF}
-                    if  lPrefs.everyfile then
-                        LoadFileList(lStr,lOutDir,lPrefs)
-                    else
-                        LoadParamFileList(lStr,lOutDir,lPrefs,I);
-                    {$IFNDEF UNIX}Msg('Time elapsed '+inttostr( GetTickCount-lStartTime)+'ms'); {$ENDIF}
-                    exit; //only process a single file
-                end;
-	 end else if  not (lSilent) then begin
-		Msg('0 '+paramstr(0)+' ERROR: unable to find '+lStr);
-		if not lHelpShown then
-			Showhelp(lIniName, lPrefs);
-		lHelpShown := true;
-	 end;
-	until I >= ParamCount;
-  end else begin //no parameters passed - show help
-	  ShowHelp(lIniName, lPrefs);
-          IniFile(False,lIniName, lPrefs);//ensure latest version of preferences file is created...
-  end;//param count > 0
-end;
-
-end.
- 
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/parconvert.pas b/dcm2nii_prePARRECDTI/parconvert.pas
deleted file mode 100755
index 97d83c2..0000000
--- a/dcm2nii_prePARRECDTI/parconvert.pas
+++ /dev/null
@@ -1,1201 +0,0 @@
-unit parconvert;
-{$H+}
-interface
-uses
-{$IFDEF FPC}gzio2, {$ENDIF}
-define_types,SysUtils,dicom,dicomtypes,filename,nii_4dto3d,niftiutil,nii_orient, nii_crop,GraphicsMathLibrary,prefs;
-
-function LoadFileListPARREC  (var lInFilename, lOutDir: string; var lPrefs: TPrefs): boolean;
-implementation
-uses dialogsx;
-
-procedure PAR2DICOMstudyDate(var lDicomData: DICOMdata);
-{input: lDicomData.StudyDate =  2002.12.29 / 19:48:58.0000
-output: StudyDate = YYYYMMDD StudyTime= hhmmss }
-var
-	I: integer;
-	lStr: string;
-begin
-	if length(lDicomData.StudyDate) < 14 then exit;
-	lStr := '';
-	for I := 1 to length(lDicomData.StudyDate) do
-		if lDicomData.StudyDate[I] in ['0'..'9'] then
-			lStr := lStr+ lDicomData.StudyDate[I];
-	if length(lStr) < 14 then exit;
-	lDicomData.StudyDate := '';
-	for I := 1 to 8 do
-		lDicomData.StudyDate := lDicomData.StudyDate+lStr[I];
-	lDicomData.StudyTime := '';
-	for I := 9 to 14 do
-		lDicomData.StudyTime := lDicomData.StudyTime+lStr[I];
-	lDicomData.DateTime := StudyDateTime(lDicomData.StudyDate,lDicomData.StudyTime);
-end;
-
-procedure ShellSortItems (first, last: integer; var lPositionRA: longintp; lIndexRA: int64P; var lRepeatedValues: boolean);
-{Shell sort chuck uses this- see 'Numerical Recipes in C' for similar sorts.}
-label
-     555;
-const
-     tiny = 1.0e-5;
-     aln2i = 1.442695022;
-var
-   n,t, nn, m, lognb2, l, k, j, i: longint;
-begin
-     lRepeatedValues := false;
-     n := abs(last - first + 1);
-     lognb2 := trunc(ln(n) * aln2i + tiny);
-     m := last;
-     for nn := 1 to lognb2 do
-         begin
-              m := m div 2;
-              k := last - m;
-              for j := 1 to k do begin
-                  i := j;
-                  555: {<- LABEL}
-                  l := i + m;
-                  if  (lIndexRA^[lPositionRA^[l]] = lIndexRA^[lPositionRA^[i]]) then begin
-                      lRepeatedValues := true;
-                      exit;
-                  end;
-                  if (lIndexRA^[lPositionRA^[l]] < lIndexRA^[lPositionRA^[i]]) then begin
-                     //swap values for i and l
-                     t := lPositionRA^[i];
-                     lPositionRA^[i] := lPositionRA^[l];
-                     lPositionRA^[l] := t;
-					 i := i - m;
-                     if (i >= 1) then
-                        goto 555;
-                  end
-              end
-         end
-end; //shellsort is fast and requires less memory than quicksort
-
-function SinDeg(lDeg: double): double;
-begin
-	 result := sin(lDeg*PI/180);
-end;
-
-function CosDeg(lDeg: double): double;
-begin
-	 result := Cos(lDeg*PI/180);
-end;
-
-  FUNCTION Matrix3DL (CONST m11,m12,m13, m21,m22,m23,
-						   m31,m32,m33:  DOUBLE):  TMatrix;
-  BEGIN
-    WITH RESULT DO
-	BEGIN
-      matrix[1,1] := m11; matrix[1,2] := m12;
-	  matrix[1,3] := m13; matrix[1,4] := 0;
-      matrix[2,1] := m21; matrix[2,2] := m22;
-	  matrix[2,3] := m23; matrix[2,4] := 0;
-      matrix[3,1] := m31; matrix[3,2] := m32;
-	  matrix[3,3] := m33; matrix[3,4] := 0;
-	  matrix[4,1] := 0; matrix[4,2] := 0;
-      matrix[4,3] := 0; matrix[4,4] := 1;
-      size := size3D
-    END
-  END {Matrix3D};
-    // 'Defuzz' is used for comparisons and to avoid propagation of 'fuzzy',
-  //  nearly-zero values.  DOUBLE calculations often result in 'fuzzy' values.
-  //  The term 'fuzz' was adapted from the APL language.
-(* FUNCTION  Defuzz(CONST x:  DOUBLE):  DOUBLE;
-  BEGIN
-    IF  ABS(x) < fuzz
-    THEN RESULT := 0.0
-    ELSE RESULT := x
-  END {Defuzz};
-  *)
-   FUNCTION MultiplyMatrices (CONST a,b:  TMatrix):  TMatrix;
-    VAR
-      i,j,k:  TIndex;
-      temp :  DOUBLE;
-  BEGIN
-    RESULT.size := a.size;
-    IF  a.size = b.size
-    THEN
-
-      FOR i := 1 TO a.size DO
-      BEGIN
-        FOR j := 1 TO a.size DO
-        BEGIN
-
-          temp := 0.0;
-          FOR k := 1 TO a.size DO
-          BEGIN
-            temp := temp + a.matrix[i,k]*b.matrix[k,j];
-          END;
-          RESULT.matrix[i,j] := Defuzz(temp)
-
-		END
-      END
-
-    ELSE Msg('MultiplyMatrices error: '+inttostr(a.size)+' <> '+inttostr(b.size))
-  END {MultiplyMatrices};
-
-  function RealToStr(lR: double {was extended}; lDec: integer): string;
-begin
-	 RealTOStr := FloatToStrF(lR, ffFixed,7,lDec);
-end;
-
-procedure ReportMatrix (lStr: string;lM:TMatrix);
-begin
-	Msg(lStr);
-	Msg(	RealToStr(lM.matrix[1,1],6)+','+RealToStr(lM.matrix[1,2],6)+','+RealToStr(lM.matrix[1,3],6)+','+RealToStr(lM.matrix[1,4],6));
-	Msg(	RealToStr(lM.matrix[2,1],6)+','+RealToStr(lM.matrix[2,2],6)+','+RealToStr(lM.matrix[2,3],6)+','+RealToStr(lM.matrix[2,4],6));
-	Msg(	RealToStr(lM.matrix[3,1],6)+','+RealToStr(lM.matrix[3,2],6)+','+RealToStr(lM.matrix[3,3],6)+','+RealToStr(lM.matrix[3,4],6));
-	Msg(	RealToStr(lM.matrix[4,1],6)+','+RealToStr(lM.matrix[4,2],6)+','+RealToStr(lM.matrix[4,3],6)+','+RealToStr(lM.matrix[4,4],6));
-end;
-
-FUNCTION Diag3D (CONST m1,m2,m3,m4:  DOUBLE):  TMatrix;
-  BEGIN
-	WITH RESULT DO
-	BEGIN
-	  matrix[1,1] := m1; matrix[1,2] := 0;
-	  matrix[1,3] := 0; matrix[1,4] := 0;
-
-	  matrix[2,1] := 0; matrix[2,2] := m2;
-	  matrix[2,3] := 0; matrix[2,4] := 0;
-
-	  matrix[3,1] := 0; matrix[3,2] := 0;
-	  matrix[3,3] := m3; matrix[3,4] := 0;
-
-	  matrix[4,1] := 0; matrix[4,2] := 0;
-	  matrix[4,3] := 0; matrix[4,4] := m4;
-	  size := size3D
-	END
-END {Diag3D};
-
-FUNCTION Matrix3D (CONST m11,m12,m13,m14, m21,m22,m23,m24,
-                           m31,m32,m33,m34, m41,m42,m43,m44:  DOUBLE):  TMatrix;
-  BEGIN
-    WITH RESULT DO
-    BEGIN
-      matrix[1,1] := m11; matrix[1,2] := m12;
-      matrix[1,3] := m13; matrix[1,4] := m14;
-
-	  matrix[2,1] := m21; matrix[2,2] := m22;
-      matrix[2,3] := m23; matrix[2,4] := m24;
-
-      matrix[3,1] := m31; matrix[3,2] := m32;
-      matrix[3,3] := m33; matrix[3,4] := m34;
-
-      matrix[4,1] := m41; matrix[4,2] := m42;
-      matrix[4,3] := m43; matrix[4,4] := m44;
-      size := size3D
-	END
-  END {Matrix3D};
-
-function mat44_inverse(var R: Tmatrix ) : TMatrix;
-var
-	r11,r12,r13,r21,r22,r23,r31,r32,r33,v1,v2,v3 , deti : double;
-	Q: TMatrix;
-begin
-   r11 := R.matrix[1,1]; r12 := R.matrix[1,2]; r13 := R.matrix[1,3];  //* [ r11 r12 r13 v1 ] */
-   r21 := R.matrix[2,1]; r22 := R.matrix[2,2]; r23 := R.matrix[2,3];  //* [ r21 r22 r23 v2 ] */
-   r31 := R.matrix[3,1]; r32 := R.matrix[3,2]; r33 := R.matrix[3,3];  //* [ r31 r32 r33 v3 ] */
-   v1  := R.matrix[1,4]; v2  := R.matrix[2,4]; v3  := R.matrix[3,4];  //* [  0   0   0   1 ] */
-
-   deti := r11*r22*r33-r11*r32*r23-r21*r12*r33
-		 +r21*r32*r13+r31*r12*r23-r31*r22*r13 ;
-
-   if( deti <> 0.0 ) then
-	deti := 1.0 / deti ;
-
-   Q.matrix[1,1] := deti*( r22*r33-r32*r23) ;
-   Q.matrix[1,2] := deti*(-r12*r33+r32*r13) ;
-   Q.matrix[1,3] := deti*( r12*r23-r22*r13) ;
-   Q.matrix[1,4] := deti*(-r12*r23*v3+r12*v2*r33+r22*r13*v3
-					 -r22*v1*r33-r32*r13*v2+r32*v1*r23) ;
-
-   Q.matrix[2,1] := deti*(-r21*r33+r31*r23) ;
-   Q.matrix[2,2] := deti*( r11*r33-r31*r13) ;
-   Q.matrix[2,3] := deti*(-r11*r23+r21*r13) ;
-   Q.matrix[2,4] := deti*( r11*r23*v3-r11*v2*r33-r21*r13*v3
-					 +r21*v1*r33+r31*r13*v2-r31*v1*r23) ;
-
-   Q.matrix[3,1] := deti*( r21*r32-r31*r22) ;
-   Q.matrix[3,2] := deti*(-r11*r32+r31*r12) ;
-   Q.matrix[3,3] := deti*( r11*r22-r21*r12) ;
-   Q.matrix[3,4] := deti*(-r11*r22*v3+r11*r32*v2+r21*r12*v3
-					 -r21*r32*v1-r31*r12*v2+r31*r22*v1) ;
-
-   Q.matrix[4,1] := 0; Q.matrix[4,2] := 0; Q.matrix[4,3] := 0.0 ;
-   Q.matrix[4,4] := 1;// (deti == 0.0l) ? 0.0l : 1.0l ; /* failure flag if deti == 0 */
-
-   result :=  Q ;
-end;
-
-procedure SetLarger (var lA,lB: double);
-begin
-	if lA > lB then
-		lB := lA
-	else
-		lA := lB;
-end;
-
-
-procedure matx(var lNHdr: TNiftiHdr; var lDICOMdata: DICOMdata; b,c,a,{b,c,a,}offa,offb,offc,lx,ly,lz,lAPFOV,lFHFOV,lRLFOV: single; lOrient: integer);
-var
-lxmm,lymm,lzmm,x,y,z,la,lb,lc: double;
-dx,dy,dz: single;
-	analyze_to_dicom,base,ra,rb,rc,lmm,patient_to_tal,lZm:TMatrix;
-begin
-	lNHdr.sform_code := kNIFTI_XFORM_UNKNOWN;
-	if (lZ < 1) or (lY < 1) or (lX < 1) then exit;
-	  {a=angle(3,1);
-	  b=angle(1,1);
-	  c=angle(2,1);}
-	  ra := Matrix3DL(1, 0, 0, 0, cos(a*pi/180), -sin(a*pi/180), 0, sin(a*pi/180), cos(a*pi/180));
-	  rb := Matrix3DL(cos(b*pi/180), 0, sin(b*pi/180), 0, 1, 0, -sin(b*pi/180), 0, cos(b*pi/180));
-	  rc := Matrix3DL(cos(c*pi/180), -sin(c*pi/180), 0, sin(c*pi/180), cos(c*pi/180), 0, 0, 0, 1);
-	  base.size := size3D;
-	  base := MultiplyMatrices(rb,rc);
-	  base := MultiplyMatrices(ra,base);
-	  if lOrient = 2 then begin //sagittal
-             //Msg('sag');
-                     lmm := Matrix3D (
-			0, 0, -1,0,
-			1, 0, 0, 0,
-			0, -1, 0,0,
-			0, 0, 0, 1);
-		lYmm := lAPFOV /lX;
-		lZmm := lFHFOV / lY;
-		//use smallest in plane resolution...
-		SetLarger (lYmm,lZmm);
-		lXmm := lRLFOV /lZ;
-	end else if lOrient = 3 then begin //coronal
-                 //Msg('Coronal');
-                 lmm := Matrix3D (
-			1, 0, 0,0,
-			0,0, 1, 0,
-			0, -1, 0,0,
-			0, 0, 0, 1);
-		lXmm := lRLFOV /lX;
-		lZmm := lFHFOV / lY;
-		//use smallest in plane resolution...
-		SetLarger (lXmm,lZmm);
-		lYmm := lAPFOV /lZ;
-
-	end else begin
-                 //Msg('Axial '+inttostr(lOrient));
-                  lmm :=  diag3D(1, 1, 1,1);
-                 lXmm := lRLFOV /lX;
-		lYmm := lAPFOV /lY;
-		//use smallest in plane resolution...
-		SetLarger (lXmm,lYmm);
-		lZmm := lFHFOV / lZ;
-	end;
-		lZm := Matrix3D (lxmm,0,0,0,
-					  0,lymm,0,0,
-						   0,0,lZmm,0,
-						   0,0,0,1);
-    patient_to_tal   := diag3D(-1, -1, 1,1);
-   analyze_to_dicom := Matrix3D (
-	1, 0, 0,0,
-	0,-1, 0,0,
-	0, 0, 1,0,
-	0, 0, 0, 1);
-
-//correct- A_tot=patient_to_tal*R_tot*Zm*lmm*analyze_to_dicom;
-//wrong - A_tot=patient_to_tal*Zm*R_tot*lmm*analyze_to_dicom;
-{ReportMatrix('Rtot',base);
-ReportMatrix('zoom',lZm);
-ReportMatrix('p2tal',patient_to_tal);
-ReportMatrix('lmm',lmm);
-ReportMatrix('analyze_to_dicom',analyze_to_dicom);}
-
-   base := MultiplyMatrices(patient_to_tal,base);
-   base := MultiplyMatrices(base,lZm);
-   base := MultiplyMatrices(base,lmm);//2/2007 suggested by Bas Neggers
-   base:= MultiplyMatrices(base,analyze_to_dicom);
-
-	x := (lx-1)/2;
-	y := (ly-2)/2;
-	z := (lz-1)/2;
-	la :=(base.matrix[1,1]*x)+(base.matrix[1,2]*y)+(base.matrix[1,3]*z)+base.matrix[1,4];
-	lb :=(base.matrix[2,1]*x)+(base.matrix[2,2]*y)+(base.matrix[2,3]*z)+base.matrix[2,4];
-	lc :=(base.matrix[3,1]*x)+(base.matrix[3,2]*y)+(base.matrix[3,3]*z)+base.matrix[3,4];
-	base.matrix[1,4] := -la-offa;
-	base.matrix[2,4] := -lb-offb;
-	base.matrix[3,4] := -lC+offc;
-   //ReportMatrix('nifti final',base);
-   lNHdr.sform_code := kNIFTI_XFORM_SCANNER_ANAT;
-   lNHdr.srow_x[0] := base.matrix[1,1];
-   lNHdr.srow_x[1] := base.matrix[1,2];
-   lNHdr.srow_x[2] := base.matrix[1,3];
-   lNHdr.srow_x[3] := base.matrix[1,4];
-   lNHdr.srow_y[0] := base.matrix[2,1];
-   lNHdr.srow_y[1] := base.matrix[2,2];
-   lNHdr.srow_y[2] := base.matrix[2,3];
-   lNHdr.srow_y[3] := base.matrix[2,4];
-   lNHdr.srow_z[0] := base.matrix[3,1];
-   lNHdr.srow_z[1] := base.matrix[3,2];
-   lNHdr.srow_z[2] := base.matrix[3,3];
-   lNHdr.srow_z[3] := base.matrix[3,4];
-   lNHdr.qform_code := kNIFTI_XFORM_SCANNER_ANAT;
-   nifti_mat44_to_quatern( base,
-   lNHdr.quatern_b,lNHdr.quatern_c,lNHdr.quatern_d,
-   lNHdr.qoffset_x,lNHdr.qoffset_y,lNHdr.qoffset_z,
-                             dx, dy, dz, lNHdr.pixdim[0]{QFac});
- end;
-
-procedure read_PAR2NII(var lNHdr: TNIftIHdr; var lDICOMdata: DICOMdata; var lHdrOK, lImageFormatOK,lPrecise:boolean;  var lDynStr: string;var lFileName: string; lReadOffsetTables: boolean; var lOffset_pos_table: LongIntp; var lOffsetTableEntries,lRescaleEntries: integer;  var lSlopeRA,lInterceptRA: Singlep; var lnum4Ddatasets: integer);
-label 333; //1384 now reads up to 8 dimensional data....
-type tRange = record
-     Min,Val,Max: double; //some vals are ints, others floats
-end;
-const UNIXeoln = chr(10);
-     kMaxnSLices = 18000;//delphi 32000 - lazarus fails >15000
-     kXdim = 1;
-     kYdim = 2;
-     kBitsPerVoxel = 3;
-     kSliceThick = 4;
-     kSliceGap = 5;
-     kXmm = 6;
-	 kYmm = 7;
-	 kRS = 8;
-	 kRI = 9;
-	 kSS = 10; //1393 - attempt to use calibrated values
-	 kDynTime = 11;
-	 kSlice = 12;
-	 kEcho = 13;
-	 kDyn = 14;
-	 kCardiac = 15;
-	 kType = 16;
-	 kSequence = 17;
-         kASL = 18;
-	 kIndex = 19;
-       lIsParVers3: boolean = true;
-       lIsParVers42: boolean = false;
-       lIsParVers41: boolean = false;
-     lRepeatedValues : boolean = false;
-     lSlicesNotInSequence: boolean = false;
-     lMaxSlice : integer = 0;
-     lMaxIndex : integer = 0;
-     lSliceSz: integer = 0;
-     lMatOrient: boolean = false;
-     //lOffsetTablesRequired: boolean = false;
-var lErrorStr,lInStr,lUpCaseStr,lReportedTRStr{,lUpcase20Str}: string;
-   lAPFOV,lFHFOV,lRLFOV,
-   lScanResX,lScanResY,lAngleA,lAngleB,lAngleC,lOffset1,lOffset2,lOffset3{,lXFOV,lYFOV}: double;
-   lSliceIndexRAx,lSliceSequenceRA,lSortedSliceSequence: int64P;
-   //lSliceIndexRA: array [1..kMaxnSlices] of longint;
-   //lSSx,lRSx,lRIx: array [1..kMaxnSlices] of single;
-   lSlopeRAx,lInterceptRAx: array [1..kMaxnSlices] of single;
-   lSliceHeaderRA: array [1..50] of double;
-   //lRepeatedValues,lSlicesNotInSequence,lIsParVers3: boolean;//,lMissingVolumes,{,lLongRAtooSmall,lMissingVolumes,lConstantScale,lContiguousSlices,}
-   lRangeRA: array [kXdim..kIndex] of tRange;
-   lSliceInfoCount,lPos,lLen,lFileSz,lHdrPos,linPos,lInc,lOrient: integer;
-   fp: file;
-   lCharRA: bytep;
-procedure MinMaxTRange (var lDimension: tRange;  lNewVal: double); //nested
-begin
-     lDimension.Val := lNewVal;
-     if lSliceInfoCount < 2 then begin
-        lDimension.Min := lDimension.Val;
-        lDimension.Max := lDimension.Val;
-	 end;
-     if lNewVal < lDimension.Min then lDimension.Min := lNewVal;
-	 if lNewVal > lDimension.Max then lDimension.Max := lNewVal;
-end; //nested InitTRange proc
-function readParStr:string;//nested
-var lStr: string;
-begin
-  lStr := '';
-  While (lPos <= lLen) do begin
-        if (lStr <> '') or (linStr[lPos]<>' ') then //strip leading spaces
-		   lStr := lStr+(linStr[lPos]);
-        inc(lPos);
-  end; //while lPOs < lLen
-   result := lStr;
-end; //nested func ReadParStr
-function readParFloat:double;//nested
-var lStr: string;
-begin
-  lStr := '';
-  result := 1;
-  While (lPos <= lLen) and ((lStr='')  or(lInStr[lPos] <> ' ')) do begin
-        if lInStr[lPos] in ['+','-','e','E','.','0'..'9'] then
-           lStr := lStr+(linStr[lPos]);
-        inc(lPos);
-  end;
-  if lStr = '' then exit;
-	try
-       result := strtofloat(lStr);
-    except
-		  on EConvertError do begin
-			 Msg('read_PAR2NII: Unable to convert the string '+lStr+' to a number');
-			 result := 1;
-			 exit;
-		  end;
-	end; {except}
-end; //nested func ReadParFloat
-begin
-  //Initialize parameters
-  lOrient := 0;
-  lAPFOV := 1;
-  lnum4Ddatasets := 1;
-  lMatOrient := false;
-  lIsParVers3 := true;
-  lIsParVers41 := false;
-  lIsParVers42 := false;
-  lSliceInfoCount := 0;
-  getmem(lSliceIndexRAx, kMaxnSLices* sizeof(int64));
-
-  for lInc := kXdim to kIndex do //initialize all values: important as PAR3 will not explicitly report all
-	  MinMaxTRange(lRangeRA[lInc],0);
-  lHdrOK := false;
-  lImageFormatOK := false;
-  lRescaleEntries := 0;
-  lOffsetTableEntries := 0;
-  Clear_Dicom_Data(lDicomData);
-  lDynStr := '';
-
-  //Read text header to buffer (lCharRA)
-  FileMode := 0; //set to readonly
-  AssignFile(fp, lFileName);
-  Reset(fp, 1);
-  lFileSz := FileSize(fp);
-  GetMem( lCharRA, lFileSz+1 ); //note: must free dynamic memory: goto 333 if any error
-  GetMem (lSliceSequenceRA, kMaxnSLices*sizeof(int64));  //note: must free dynamic memory: goto 333 if any error
-  BlockRead(fp, lCharRA^, lFileSz, lInpos);
-  if lInPos <> lFileSz then begin
-     Msg('read_PAR2NII: Disk error, unable to read full input file.');
-     goto 333;
-  end;
-  linPos := 1;
-  CloseFile(fp);
-  FileMode := 2; //set to read/write
-  //Next: read each line of header file...
-
-  repeat //for each line in file....
-    linstr := '';
-    while (linPos < lFileSz) and (lCharRA^[linPos] <> ord(kCR)) and (lCharRA^[linPos] <> ord(UNIXeoln)) do begin
-      lInStr := lInstr + chr(lCharRA^[linPos]);
-      inc(linPos);
-    end;
-	inc(lInPos);  //read EOLN
-    lLen := length(lInStr);
-	lPos := 1;
-    lUpcaseStr := '';
-    if lLen < 1 then
-       //ignore blank lines
-    else if (lInStr[1] = '*') and (not lHdrOK) then  //# -> comment
-		 //ignore comment lines prior to start of header
-	else if (lInStr[1] = '#') and (lHdrOK) then  begin//# -> comment   ignore UNLESS it reveals version
-        if (Length(lInStr)> 16) and (lInStr[3] = 'C') and (Copy(lInStr,3,15) = 'CLINICAL TRYOUT') then begin
-           lUpCaseStr := '';
-           lHdrPos := Length(lInStr);
-           while (lHdrPos > 0) and (UpCase(lInStr[lHdrPos]) <> 'V') do begin
-                 if lInStr[lHdrPos] in ['.', '0'..'9'] then
-                 lUpCaseStr := UpCase(lInStr[lHdrPos])+lUpCaseStr;
-                 dec(lHdrPos);
-           end;
-           if lUpCaseStr = '3' then
-              lIsParVers3 := true
-           else if lUpCaseStr = '4' then
-              lIsParVers3 := false
-           else if lUpCaseStr = '4.1' then begin
-              lIsParVers3 := false;
-              lIsParVers41 := true;
-              Msg('PAR v4.1 not yet fully supported')
-           end else if lUpCaseStr = '4.2' then begin //11/2007
-              lIsParVers3 := false;
-              lIsParVers41 := true;
-              lIsParVers42 := true;
-              Msg('PAR v4.2 not yet fully supported')
-           end else
-               Msg('Warning: unknown PAR version '+lUpCaseStr);
-
-        end;
-    end else if (lInStr[1] = '.') or (not lHdrOK) then  begin  //  GENERAL_INFORMATION section (line starts with '.')
-      //Note we also read in lines that do not have '.' if we have HdrOK=false, this allows us to detect the DATADESCRIPTIONFILE signature
-      While (lPos <= lLen) and (lInStr[lPos] <> ':') and ((not lHdrOK) or (lInStr[lPos] <> '#')) do begin
-        if lInStr[lPos] in ['[',']','(',')','/','+','-',{' ',} '0'..'9','a'..'z','A'..'Z'] then
-           lUpCaseStr := lUpCaseStr+upcase(linStr[lPos]);
-        inc(lPos);
-      end; //while reading line
-      inc(lPos); {read equal sign in := statement}
-               lDynStr := lDynStr + lInStr+kCR;
-	  //Msg(inttostr(length(lUpCaseStr)));
-      if (not lHdrOK) and (lUpcaseStr = ('DATADESCRIPTIONFILE')) then begin //1389 PAR file
-            lHdrOK := true;
-            lDicomData.little_endian := 1;
-      end;
-
-
-(*      if (not lHdrOK) and (length(lUpCaseStr) >= 19) then begin
-         //lUpcase20Str := xx
-         lUpcase20Str := '';
-         for lInc := 1 to 19 do
-			 lUpcase20Str := lUpCase20Str + lUpcaseStr[lInc];
-         //Msg(lUpcase20Str);
-         if (lUpcase20Str = ('DATADESCRIPTIONFILE')) or (lUpcase20Str = ('EXPERIMENTALPRIDEDA')) then begin //PAR file
-			lHdrOK := true;
-            lDicomData.little_endian := 1;
-         end;
-      end;
-  *)
-	  if (lUpCaseStr ='REPETITIONTIME[MSEC]') or (lUpCaseStr ='REPETITIONTIME[MS]') then
-		 lDicomData.TR :=  round(readParFloat);
-	  if (lUpCaseStr ='MAXNUMBEROFSLICES/LOCATIONS') then
-		 lDicomData.XYZdim[3] :=  round(readParFloat);
-	  if (lUpCaseStr ='SLICETHICKNESS[MM]') then
-		 MinMaxTRange(lRangeRA[kSliceThick],readParFloat);
-      if (lUpCaseStr ='SLICEGAP[MM]') then
-         MinMaxTRange(lRangeRA[kSliceGap],readParFloat);
-	  if lUpCaseStr = 'FOV(APFHRL)[MM]' then begin
-		 lDicomData.XYZmm[2] :=  (readParFloat); //AP anterior->posterior
-		 lDicomData.XYZmm[3] :=  (readParFloat); //FH foot head
-		 lDicomData.XYZmm[1] :=  (readParFloat); //RL Right-Left
-		 lAPFOV := lDicomData.XYZmm[2];
-		 lFHFOV := lDicomData.XYZmm[3];
-		 lRLFOV := lDicomData.XYZmm[1];
-	  end;
-	  if lUpCaseStr = 'SCANRESOLUTION(XY)' then begin
-		 lScanResX :=  round(readParFloat);
-		 lScanResY :=  round(readParFloat);
-	  end;
-	  {if lUpCaseStr = 'SCANPERCENTAGE' then begin
-		 lScanPct :=  round(readParFloat);
-      end; }
-      if lUpCaseStr = 'RECONRESOLUTION(XY)' then begin
-         MinMaxTRange(lRangeRA[kXdim],readParFloat);
-         MinMaxTRange(lRangeRA[kYdim],readParFloat);
-	  end;
-      if lUpCaseStr = 'RECONSTRUCTIONNR' then
-		 lDicomData.AcquNum :=  round(readParFloat);
-      if lUpCaseStr = 'ACQUISITIONNR' then
-         lDicomData.SeriesNum :=  round(readParFloat);
-      if lUpCaseStr = 'MAXNUMBEROFDYNAMICS' then begin
-         lDicomData.XYZdim[4] :=  round(readParFloat);
-      end;
-	  if lUpCaseStr = 'EXAMINATIONDATE/TIME' then begin
-		 lDicomData.StudyDate := readParStr;
-		 PAR2DICOMstudyDate(lDicomData);
-	  end;
-	  if (lUpCaseStr ='ANGULATIONMIDSLICE(APFHRL)[DEGR]') then begin
-		  lAngleA :=  (readParFloat);
-		  lAngleB :=  (readParFloat);
-		  lAngleC :=  (readParFloat);
-	  end;
-	  if (lUpCaseStr ='OFFCENTREMIDSLICE(APFHRL)[MM]') then begin
-		  lOffset2 :=  (readParFloat);
-		  lOffset3 :=  (readParFloat);
-		  lOffset1 :=  (readParFloat);
-	  end;
-	  if lUpCaseStr = 'PROTOCOLNAME' then
-		 lDicomData.ProtocolName := readParStr;
-      if lUpCaseStr = 'PATIENTNAME' then
-         lDicomData.PatientName := readParStr;
-      if lUpCaseStr ='IMAGEPIXELSIZE[8OR16BITS]' then begin
-         MinMaxTRange(lRangeRA[kBitsPerVoxel],readParFloat);
-      end;
-      if not lHdrOK then  begin
-         Msg('read_PAR2NII: Error reading header');
-         goto 333;
-	  end;
-	end else begin  //SliceInfo: IMAGE_INFORMATION (line does NOT start with '.' or '#')
-         inc(lSliceInfoCount);
-         if (lSliceInfoCount < 2) and (lRangeRA[kBitsPerVoxel].val < 1) then //PARvers3 has imagedepth in general header, only in image header for later versions
-			lIsParVers3 := false;
-         for lHdrPos := 1 to 26 do
-			 lSliceHeaderRA[lHdrPos] := readparfloat;
-		 //The next few values are in the same location for both PAR3 and PAR4
-		 MinMaxTRange(lRangeRA[kSlice], round(lSliceHeaderRA[1]));
-		 MinMaxTRange(lRangeRA[kEcho], round(lSliceHeaderRA[2]));
-		 MinMaxTRange(lRangeRA[kDyn], round(lSliceHeaderRA[3]));
-     if not lIsParVers42 then //if 4.2 then we will use combination of Cardiac and ASL for cardiac number
-		  MinMaxTRange(lRangeRA[kCardiac], round(lSliceHeaderRA[4]));
-		 MinMaxTRange(lRangeRA[kType], round(lSliceHeaderRA[5]));
-		 MinMaxTRange(lRangeRA[kSequence], round(lSliceHeaderRA[6]));
-		 MinMaxTRange(lRangeRA[kIndex], round(lSliceHeaderRA[7]));
-		 if lIsParVers3 then begin //Read PAR3 data
-			MinMaxTRange(lRangeRA[kRI], lSliceHeaderRA[8]);; //8=intercept in PAR3
-			MinMaxTRange(lRangeRA[kRS],lSliceHeaderRA[9]); //9=slope in PAR3
-			MinMaxTRange(lRangeRA[kSS],lSliceHeaderRA[10]);  //10=lcalibrated slope in PAR3 1393 - attempt to use calibrated values
-			//MinMaxTRange(lRangeRA[kXmm],lSliceHeaderRA[23]); //23 PIXEL SPACING X  in PAR3
-			//MinMaxTRange(lRangeRA[kYmm],lSliceHeaderRA[24]); //24 PIXEL SPACING Y IN PAR3
-			MinMaxTRange(lRangeRA[kDynTime],(lSliceHeaderRA[26]));  //26= dyn_scan_begin_time in PAR3
-		 end else begin  //not PAR: assume PAR4
-			for lHdrPos := 27 to 32 do
-				lSliceHeaderRA[lHdrPos] := readparfloat;
-			MinMaxTRange(lRangeRA[kBitsPerVoxel],lSliceHeaderRA[8]);//8 BITS in PAR4
-			MinMaxTRange(lRangeRA[kXdim], lSliceHeaderRA[10]); //10 XDim in PAR4
-			MinMaxTRange(lRangeRA[kYdim], lSliceHeaderRA[11]); //11 YDim in PAR4
-			MinMaxTRange(lRangeRA[kRI],lSliceHeaderRA[12]); //12=intercept in PAR4
-			MinMaxTRange(lRangeRA[kRS],lSliceHeaderRA[13]); //13=lslope in PAR4
-			MinMaxTRange(lRangeRA[kSS],lSliceHeaderRA[14]);  //14=lcalibrated slope in PAR4 1393 - attempt to use calibrated values
-			MinMaxTRange(lRangeRA[kDynTime],(lSliceHeaderRA[32]));//32= dyn_scan_begin_time in PAR4
-                        if lIsParVers41 then begin
-                           for lHdrPos := 33 to 47 do
-				lSliceHeaderRA[lHdrPos] := readparfloat;
-                           if ({diff}lSliceHeaderRA[34]<> 0) and ({grad}lSliceHeaderRA[43]<> 0) then //DTI scan - treat as dynamics
-                               MinMaxTRange(lRangeRA[kDyn], ({diff}lSliceHeaderRA[34]*100)+ ({gradient}lSliceHeaderRA[43]) );
-                           if lIsParVers42 then begin
-                              for lHdrPos := 48 to 49 do
-				lSliceHeaderRA[lHdrPos] := readparfloat;
-                              //fx( lSliceHeaderRA[49]);
-                              MinMaxTRange(lRangeRA[kCardiac], ({cardiac}lSliceHeaderRA[49]*100)+ ({asl}lSliceHeaderRA[4]) );
-                           end; //PAR42
-
-                        end; //PAR41
-		 end; //PAR4
-		 if lSliceInfoCount < kMaxnSlices then begin
-			lSliceSequenceRA^[lSliceInfoCount] :=  (round(lRangeRA[kSequence].val) shl 48)+(round(lRangeRA[kType].val) shl 40)+(round(lRangeRA[kCardiac].val) shl 32)+(round(lRangeRA[kEcho].val) shl 24)+(round(lRangeRA[kDyn].val) shl 10)+round(lRangeRA[kSlice].val);
-			(*lRSx [lSliceInfoCount] := lRangeRA[kRS].Val;
-			lRIx [lSliceInfoCount] := lRangeRA[kRI].val;
-			lSSx [lSliceInfoCount] := lRangeRA[kSS].Val;
-                        *)
-                        // fx( lRangeRA[kType].val ,lRangeRA[kEcho].val);
-                        PhilipsPrecise (lRangeRA[kRS].Val, lRangeRA[kRI].val,lRangeRA[kSS].Val,lSlopeRAx[lSliceInfoCount],lInterceptRAx[lSliceInfoCount],lPrecise);
-			lSliceIndexRAx^[lSliceInfoCount]:= round(lRangeRA[kIndex].val);
-		 end;
-		 if (not lMatOrient) and (lSliceHeaderRA[1]=1) and (lSliceHeaderRA[2]=1) {and (lSliceHeaderRA[3]=1)} and (lSliceHeaderRA[4]=1) then begin
-                        lMatOrient := true;
-                        //first slice/echo/-dynamic/cardiac --- take slice position information from this slice...
-			//par4 - 20,21,22 ; par3 16,17,18
-			if lIsParVers3 then
-				lOrient := round(lSliceHeaderRA[19])
-			else
-				lOrient := round(lSliceHeaderRA[26]);
-
-                          matx(lNHdr,lDicomData,lAngleA,lAngleB,lAngleC,lOffset1,lOffset2,lOffset3,
-				lRangeRA[kXdim].Val,lRangeRA[kYdim].Val,lDicomData.XYZdim[3],
-				lAPFOV,lFHFOV,lRLFOV,lOrient);
-			//procedure mat(b,c,a,offa,offb,offc,lx,ly,lz,lxmm,lymm,lzmm: single);
-		 end;
-	end; //SliceInfo Line
-  until (linPos >= lFileSz);//until done reading entire file...
-  //describe generic DICOM parameters
-  lDicomData.XYZdim[1] := round(lRangeRA[kXdim].Val);
-  lDicomData.XYZdim[2] := round(lRangeRA[kYdim].Val);
-  lDicomData.XYZdim[3] := 1+round(lRangeRA[kSlice].Max-lRangeRA[kSlice].Min);
-  if (lSliceInfoCount mod lDicomData.XYZdim[3]) <> 0 then
-	 Msg('read_PAR2NII: Total number of slices not divisible by number of slices per volume. Reconstruction error?');
-  if lDicomData.XYZdim[3] > 0 then
-	 lDicomData.XYZdim[4] := lSliceInfoCount div lDicomData.XYZdim[3] //nVolumes = nSlices/nSlicePerVol
-  else
-	  lDicomData.XYZdim[4] := 1;
-  if lOrient = 2 then begin //sagittal
-	lDicomData.XYZmm[1] := lAPFOV /lDicomData.XYZdim[1];
-	lDicomData.XYZmm[2] := lFHFOV / lDicomData.XYZdim[2];
-	lDicomData.XYZmm[3] := lRLFOV /lDicomData.XYZdim[3];
-  end else if lOrient = 3 then begin //coronal
-	lDicomData.XYZmm[1] := lRLFOV /lDicomData.XYZdim[1];
-	lDicomData.XYZmm[2] := lFHFOV / lDicomData.XYZdim[2];
-	lDicomData.XYZmm[3] := lAPFOV /lDicomData.XYZdim[3];
-  end else begin //axial
-	lDicomData.XYZmm[1] := lRLFOV /lDicomData.XYZdim[1];
-	lDicomData.XYZmm[2] := lAPFOV /lDicomData.XYZdim[2];
-	lDicomData.XYZmm[3] := lFHFOV / lDicomData.XYZdim[3];
-  end;
-  //use smallest in plane resolution...
-  SetLarger (lDicomData.XYZmm[1],lDicomData.XYZmm[2]);
-  lDicomData.Allocbits_per_pixel :=  round(lRangeRA[kBitsPerVoxel].Val);
-  lDicomData.IntenScale := lRangeRA[kRS].Val;
-  lDicomData.IntenIntercept := lRangeRA[kRI].Val;
-  //Next: report number of Dynamic scans, this allows people to parse DynScans from Type/Cardiac/Echo/Sequence 4D files
-  lnum4Ddatasets := (round(lRangeRA[kDyn].Max - lRangeRA[kDyn].Min)+1)*lDicomData.XYZdim[3]; //slices in each dynamic session
-  if ((lSliceInfoCount mod lnum4Ddatasets) = 0) and ((lSliceInfoCount div lnum4Ddatasets) > 1) then
-    lnum4Ddatasets := (lSliceInfoCount div lnum4Ddatasets) //infer multiple Type/Cardiac/Echo/Sequence
-  else
-      lnum4Ddatasets := 1;
-  //next: Determine actual interscan interval
-  if (lDicomData.XYZdim[4] > 1) and ((lRangeRA[kDynTime].max-lRangeRA[kDynTime].min)> 0)  {1384} then begin
-        lReportedTRStr := 'Reported TR: '+floattostrf(lDicomData.TR,ffFixed,8,2)+kCR;
-        lDicomData.TR := (lRangeRA[kDynTime].max-lRangeRA[kDynTime].min)  /(lDicomData.XYZdim[4] - 1)*1000; //infer TR in ms
-  end else
-         lReportedTRStr :='';
-  //next: report header details
-  lDynStr := 'Philips PAR/REC Format' //'PAR/REC Format'
-              +kCR+ 'Patient name:'+lDicomData.PatientName
-              +kCR+ 'XYZ dim: ' +inttostr(lDicomData.XYZdim[1])+'/'+inttostr(lDicomData.XYZdim[2])+'/'+inttostr(lDicomData.XYZdim[3])
-              +kCR+'Volumes: ' +inttostr(lDicomData.XYZdim[4])
-              +kCR+'XYZ mm: '+floattostrf(lDicomData.XYZmm[1],ffFixed,8,2)+'/'
-			  +floattostrf(lDicomData.XYZmm[2],ffFixed,8,2)+'/'+floattostrf(lDicomData.XYZmm[3],ffFixed,8,2)
-			  +kCR+'TR: '+floattostrf(lDicomData.TR,ffFixed,8,2)
-              +kCR+lReportedTRStr+kCR+lDynStr;
-
-  //if we get here, the header is fine, next steps will see if image format is readable...
-  lHdrOK := true;
-  if lSliceInfoCount < 1 then begin
-     Msg('No valid images found.') ;
-     goto 333;
-  end;
-  //next: see if slices are in sequence
-  lSlicesNotInSequence := false;
-  if lSliceInfoCount > 1 then begin
-     lMaxSlice := lSliceSequenceRA^[1];
-	 lMaxIndex := lSliceIndexRAx^[1];
-     lInc := 1;
-     repeat
-        inc(lInc);
-        if lSliceSequenceRA^[lInc] < lMaxSlice then //not in sequence if image has lower slice order than previous image
-           lSlicesNotInSequence := true
-        else
-           lMaxSlice := lSliceSequenceRA^[lInc];
-        if lSliceIndexRAx^[lInc] < lMaxIndex then //not in sequence if image has lower slice index than previous image
-           lSlicesNotInSequence := true
-        else
-           lMaxIndex := lSliceIndexRAx^[lInc];
-     until (lInc = lSliceInfoCount) or (lSlicesNotInSequence);
-  end; //at least 2 slices
-  //Next: report any errors
-       lErrorStr := '';
-  if (lSlicesNotInSequence) and (not lReadOffsetTables) then
-     lErrorStr := lErrorStr + ' Slices not saved sequentially [using MRIcro''s ''Philips PAR to Analyze'' command may solve this]'+kCR;
-  if lSliceInfoCount > kMaxnSlices then
-     lErrorStr := lErrorStr + ' Too many slices: >'+inttostr(kMaxnSlices)+kCR;
-  if (lRangeRA[kBitsPerVoxel].min <> lRangeRA[kBitsPerVoxel].max) then  //5D file space+time+cardiac
-     lErrorStr := lErrorStr + ' Differing bits per voxel'+kCR;
-  //if (lRangeRA[kCardiac].min <> lRangeRA[kCardiac].max) then  //5D file space+time+cardiac
-  //   lErrorStr := lErrorStr + 'Multiple cardiac timepoints'+kCR;
-  //if (lRangeRA[kEcho].min <> lRangeRA[kEcho].max) then  //5D file space+time+echo
-  //   lErrorStr := lErrorStr + 'Multiple echo timepoints'+kCR;
-  if (lRangeRA[kSliceThick].min <> lRangeRA[kSliceThick].max) or (lRangeRA[kSliceGap].min <> lRangeRA[kSliceGap].max)
-    or (lRangeRA[kXdim].min <> lRangeRA[kXdim].max) or (lRangeRA[kYDim].min <> lRangeRA[kYDim].max)
-    or (lRangeRA[kXmm].min <> lRangeRA[kXmm].max) or (lRangeRA[kYmm].min <> lRangeRA[kYmm].max) then
-     lErrorStr := lErrorStr + ' Multiple/varying slice dimensions'+kCR;
-  //if any errors were encountered, report them....
-
-  if lErrorStr <> '' then begin
-      Msg('read_PAR2NII: This software can not convert this Philips data:'+kCR+lErrorStr);
-      goto 333;
-  end;
-       //Next sort image indexes here...
-  if (lSliceInfoCount > 1) and(lSlicesNotInSequence) and ( lReadOffsetTables) then begin //sort image order...
-     //ShellSort (first, last: integer; var lPositionRA, lIndexLoRA,lIndexHiRA: LongintP; var lRepeatedValues: boolean)
-     GetMem (lOffset_pos_table, lSliceInfoCount*sizeof(int64));
-     for lInc := 1 to  lSliceInfoCount do
-         lOffset_pos_table^[lInc] := lInc;
-	 ShellSortItems (1, lSliceInfoCount,lOffset_pos_table,lSliceSequenceRA, lRepeatedValues);
-    (* if lRepeatedValues then begin
-         Msg('read_PAR2NII: fatal error, slices do not appear to have unique indexes [multiple copies of same slice]');
-         FreeMem (lOffset_pos_table);
-         goto 333;
-     end; *)
-     lOffsetTableEntries := lSliceInfoCount;
-  end; //sort image order...
-
-
-       //Next, generate list of scale slope
-  (*lOffsetTablesRequired := false;
-  if (lSliceInfoCount > 1) and ( (lRangeRA[kSS].min <> lRangeRA[kSS].max)
-    or  (lRangeRA[kRS].min <> lRangeRA[kRS].max)
-    or (lRangeRA[kRI].min <> lRangeRA[kRI].max)) then
-       lOffsetTablesRequired := true;
-    *)
-   lDicomData.IntenScale :=  lSlopeRAx[1];
-   lDicomData.IntenIntercept := lInterceptRAx[1];
-  //PhilipsPrecise (lRSx[lInc], lRIx[lInc],lSSx[lInc], lDicomData.IntenScale,lDicomData.IntenIntercept);
-
-  //if lOffsetTablesRequired then begin
-  //    Msg('Image saved as 32-bit data: varying intensity scaling factors or complicated Pixel to Precise transform');
-  if  (lRangeRA[kSS].min = lRangeRA[kSS].max)
-    and (lRangeRA[kRS].min  = lRangeRA[kRS].max)
-    and (lRangeRA[kRI].min  = lRangeRA[kRI].max) then
-          lRescaleEntries := 0
-   else begin
-       lRescaleEntries := lSliceInfoCount;
-      getmem (lSlopeRA, lRescaleEntries*sizeof(single));
-      getmem (lInterceptRA, lRescaleEntries*sizeof(single));
-      if  lOffsetTableEntries = lSliceInfoCount then begin //need to sort slices
-          for lInc := 1 to lSliceInfoCount do begin
-              lSlopeRA^[lInc] := lSlopeRAx[lOffset_pos_table^[lInc]];
-              lInterceptRA^[lInc] := lInterceptRAx[lOffset_pos_table^[lInc]];
-          end;
-      end else begin //if sorted, else unsorted
-          for lInc := 1 to lSliceInfoCount do begin
-              lSlopeRA^[lInc] := lSlopeRAx[lInc];
-              lInterceptRA^[lInc] := lInterceptRAx[lInc];
-          end;
-      end; //slices sorted
-  end;//read scale factors
-  //Next: now adjust Offsets to point to byte offset instead of slice number
-  lSliceSz := lDicomData.XYZdim[1]*lDicomData.XYZdim[2]*(lDicomData.Allocbits_per_pixel div 8);
-  if lOffsetTableEntries = lSliceInfoCount then
-          for lInc := 1 to lSliceInfoCount do
-              lOffset_pos_table^[lInc] := lSliceSz * (lSliceIndexRAx^[lOffset_pos_table^[lInc]]);
-  //report if 5D/6D/7D file is being saved as 4D
-  if (lRangeRA[kCardiac].min <> lRangeRA[kCardiac].max)
-    or (lRangeRA[kEcho].min <> lRangeRA[kEcho].max)   //5D file space+time+echo
-    or (lRangeRA[kType].min <> lRangeRA[kType].max)   //5D file space+time+echo
-    or (lRangeRA[kSequence].min <> lRangeRA[kSequence].max) then begin//5D file space+time+echo
-      Msg('Warning: note that this image has more than 4 dimensions (multiple Cardiac/Echo/Type/Sequence)');
-      Msg('Cardiac min..max '+floattostr(lRangeRA[kCardiac].min)+'..'+floattostr(lRangeRA[kCardiac].max) );
-      Msg('Echo min..max '+floattostr(lRangeRA[kEcho].min)+'..'+floattostr(lRangeRA[kEcho].max) );
-      Msg('Type min..max '+floattostr(lRangeRA[kType].min)+'..'+floattostr(lRangeRA[kType].max) );
-      Msg('Sequence min..max '+floattostr(lRangeRA[kSequence].min)+'..'+floattostr(lRangeRA[kSequence].max) );
-      
-    end;
-  //if we get here, the Image Format is OK
-  lImageFormatOK := true;
-  lFileName := changefileextX(lFilename,'.rec'); //for Linux: case sensitive extension search '.rec' <> '.REC'
- 333: //abort clause: skips lHdrOK and lImageFormatOK
- //next: free dynamically allocated memory
- FreeMem( lCharRA);
- FreeMem (lSliceSequenceRA);
- Freemem(lSliceIndexRAx);
-end;
-
-
-(*function StudySecSince2KStr (lInSec: integer): string;
-var
-  days,secs,Y,M,D,H,Min,S, l,n,i,j: integer;
-begin
-	 result := 'DateNA';//bogus
-	 days := (lInSec div 86400)+2451547;//+2451547 as we convert to julian
-	 //Msg(inttostr(days));
-	 //next convert Y,M,D
-	 l := days + 68569;
-	 n := trunc(( 4 * l ) / 146097);
-	 l := trunc(l - ( 146097 * n + 3 ) / 4);
-	 i := trunc(( 4000 * ( l + 1 ) ) / 1461001);
-	 l := trunc(l - ( 1461 * i ) / 4 + 31);
-	 j := trunc(( 80 * l ) / 2447 );
-	 d := trunc(l - ( 2447 * j ) / 80);
-	 l := trunc(j / 11);
-	 m := j + 2 - ( 12 * l );
-	 y := 100 * ( n - 49 ) + i + l;
-	 //next convert H,Min,Sec
-	 if lInSec < 0 then begin//date prior to 2000 -saved as negative
-		 secs := (lInSec - ( (lInSec div 86400)*86400)+86400) mod 86400
-	 end else
-		secs := lInSec mod 86400; //value 0..86399
-	 S := secs mod 60;
-	 Min := (secs div 60) mod 60;
-	 H := (secs div 3600)+1;
-	 result := PadStr (Y, 4)+ PadStr (M, 2)+PadStr (D, 2)+'_'+PadStr (H, 2)+ PadStr (Min, 2)+PadStr (S, 2);
-end;*)
-
-function UniqueFileName (var lInStr: string): boolean;
-var
-  lInc: integer;
-  lPathWName,lExt: string;
-begin
-    result := true;
-    if not Fileexists(lInStr) then exit;
-	ExtractFileParts(lInStr,lPathWName,lExt);
-    lInc := ord('A');
-    while (lInc <= ord('Z')) and ( Fileexists(lPathWName+chr(lInc)+lExt))  do
-      inc(lInc);
-    if lInc > ord('Z') then
-      result := false
-    else
-      lInStr := lPathWName+chr(lInc)+lExt;
-end;
-
-function ConvertPhilipsPARtoAnalyze (var lInFilename, lOutDir: string; var lPrefs: TPrefs): boolean;
-label
-	 678;
-var
-   //lVaryingScaleFactorsTableEntries,
-   lLines,lColBytes,lRows,lRowsdiv2,lSwap,lInc,
-	l4Doffset,lcurrent4Dvol,lnum4Ddatasets,
- lSlicePixelsx,
- lnSlicesx,
- lSliceSzOutx,
- lSLiceSzx,
-       lRescaleEntries, lPos,lOffsetTableEntries: longint;
-	lOutF,lInF: File;
-	lNHdr,lAHdr: TNIFTIhdr;
-	lP,lBuffer : Bytep;
-	lFileName,lRECFilename,lOutImgName,lOutHdrName,lDynStr,lOutDirPath: String;
-	lDICOMdata: dicomdata;
-	lScaleFactorVariesInThis4DVolume,lAbort,lHdrOK, lImageFormatOK: boolean;
-         lSlopeRA,lInterceptRA,
-	lSingleBuffer: Singlep;
-	lOffset_pos_table: LongIntp;
-begin
-     result := false;
-     lFileName := lInFilename;
-  if (lOutDir = '') then
-	lOutDirPath := ExtractFilePath(lFileName)//ExtractFileDirWithPathDelim(lFilename)//ExtractFilePath(lFileName)
-  else if not direxists(lOutDir) then begin
-	Msg('Unable to find output directory '+lOutDir);
-	lOutDirPath := ExtractFilePath(lFileName)
-  end else
-	lOutDirPath := lOutDir;
-  if (length(lOutDirPath) > 0) and (lOutDirPath[length(lOutDirPath)] <> pathdelim) then
-    lOutDirPath := lOutDirPath + pathdelim;
-	lAbort := false;
-	lRecFilename :=ChangeFileExt(lFileName,'.rec');
-        Msg('input name '+ lInFilename);
-        Msg('input REC name '+lRecFilename);
-	//Apr08 problems with filenames with . in them lRecFilename :=ExtractFilePath(lFileName)+ParseFileName(ExtractFileName(lFileName))+'.rec';
-	if not fileexists(lRecFilename) then //might be Linux: case sensitive extensions
-	       lRecFilename :=ChangeFileExt(lFileName,'.REC');
-	       //	lRecFilename :=ExtractFilePath(lFileName)+ParseFileName(ExtractFileName(lFileName))+'.REC';
-	if not fileexists(lRecFilename) then
-		Msg('Unable to find REC image data file named '+lRecFileName)
-	else if fileexists(lRecFilename) and fileexists(lFilename) then begin //convert
-		read_par2NII(lNHdr,lDICOMdata,lHdrOK,lImageFormatOK,lPRefs.PhilipsPrecise, lDynStr,lFileName,true,lOffset_pos_table,lOffsetTableEntries,lRescaleEntries, lSlopeRA,lInterceptRA,lnum4Ddatasets);
-	 if (lnum4Ddatasets > 1) and ((lDicomData.XYZdim[4] mod lnum4Ddatasets) = 0) then  //break 5D files into separate 4D files
-		lDicomData.XYZdim[4] := lDicomData.XYZdim[4] div lnum4Ddatasets
-	 else
-		 lnum4Ddatasets := 1;
-			lRows := lDicomData.XYZdim[2];
-			lRowsdiv2 := lRows div 2;
-			lColBytes := lDicomData.XYZdim[1]*(lDicomData.Allocbits_per_pixel div 8);
-			lSlicePixelsx := (lDicomData.XYZdim[1]*lDicomData.XYZdim[2]);
-			lSliceSzx := lSlicePixelsx*(lDicomData.Allocbits_per_pixel div 8);
-  lnSlicesx := lDicomData.XYZdim[3] * lDicomData.XYZdim[4];
-  lcurrent4Dvol := 0;
-	 l4DOffset := 0;
-  //  exit;    //crucial critical test exit
-  if lHdrOK then begin
-     repeat //for each 4D volume
-            inc(lcurrent4Dvol);
-	    lOutHdrName :=lOutDirPath+{Pathdelim+}OutputFilename(lRecFilename,lDicomData,lPrefs);//Pathdelim 11/2007
-	    if lnum4Ddatasets > 1 then begin
-	       l4DOffset :=  (lcurrent4Dvol-1)* lnSlicesx;
-	       lOutHdrName :=(lOutHdrName)+'x'+inttostr(lcurrent4Dvol)+'.hdr'
-	    end else
-	        lOutHdrName :=(lOutHdrName)+'.hdr';
-			lOutImgName :=changefileext(lOutHdrName,'.img');
-			if lPrefs.SingleNIIFile then begin
-				lOutHdrName :=  changefileext(lOutHdrName,'.nii');
-				lOutImgName := lOutHdrName;
-			end;
-	if (lPrefs.SingleNIIFile) and (lPrefs.GZip) then begin
-		lOutHdrName := lOutHdrName+'.gz';
-		if (not UniqueFileName(lOutHdrName))  then begin
-			Msg('File already exists '+lOutImgName+' '+lOutHdrName);
-			exit;
-		end;
-
-		//we now need to remove the .gz - not that unique filename may have appended postfix, e.g. filename.nii.gz -> filenameA.nii.gz
-		//StripGZExt(lOutHdrName);
-		lOutImgName := lOutHdrName;
-	end else begin
-		if (not UniqueFileName(lOutHdrName)) or (not UniqueFileName(lOutImgName)) then begin
-			Msg('File already exists '+lOutImgName+' '+lOutHdrName);
-			exit;
-		end;
-	end;
-			Msg(lFileName+' --> '+ lOutImgName);
-//exit; //trap
-						{$IFDEF LINUX}
-						//perhaps the file is .REC, not .rec
-                       if (lSliceSzx * lnSLicesx) > FSize(lFileName)   then
-								lRecFilename := changefileext(lFileName,'.REC');
-						{$ENDIF}
-			if (lSliceSzx * lnSLicesx) > FSize(lRecFilename)   then begin
-
-			   Msg('Conversion error: the REC file '+lRecFilename+ ' is not as large as described by the PAR file X*Y*Z*T*BytesPerPixel='
-                                           + inttostr(lDicomData.XYZdim[1])+'*'+inttostr(lDicomData.XYZdim[2])+'*'+inttostr(lDicomData.XYZdim[3])+'*'+inttostr(lDicomData.XYZdim[4])+'*'+inttostr(lDicomData.Allocbits_per_pixel div 8)
-                                           +' = '+ inttostr(lSliceSzx* lnSLicesx)+' <>  '+inttostr(FSize(lFileName)) );
-						{$IFDEF LINUX}
-			   Msg(' Suggestion: in UNIX .REC and .rec are different files - check file extension'  );
-						{$ENDIF}
-			   lAbort := true;
-			end else if ((sizeof(TNIFTIhdr)+(lSliceSzx*lnSlicesx))> DiskFreeEx(lOutImgName)) then begin
-			   Msg('There is not enough free space on the destination disk to save the converted image. '+kCR+
-			   lOutImgName+ kCR+' Bytes Required: '+inttostr(sizeof(TNIFTIhdr)+(lSliceSzx*lnSlicesx)) );
-			   lAbort := true;
-			end else if fileexists(lOutHdrName) or fileexists(lOutImgName) then
-			   Msg('Unable to convert images:  file already exists named: '+lOutHdrName)
-			else if  (not lHdrOK)   then
-                             msg('Problem with header...')
-                        else if (not lImageFormatOK) then
-                             msg('Problem with image...')
-
-                        else if (lHdrOK) and (lImageFormatOK) and (lDicomData.XYZdim[3] > 0) and (lSliceSzx > 0) then begin
-			   DICOM2AnzHdr(lAHdr,lPrefs.Anonymize,lFilename,lDICOMdata);
-                           lSliceSzOutx := lSliceSzx;
-                           lScaleFactorVariesInThis4DVolume := false;
-                           //check if 4D scale slope changes for this 4D dataset...
-                           if lRescaleEntries > 0 then begin
-                              lAHdr.scl_slope := lSlopeRA^[l4DOffset+1];
-                              lAHdr.scl_inter := lInterceptRA^[l4DOffset+1];
-
-                              if lRescaleEntries > 0 then begin
-                                for lInc := 1 to lnSlicesx do begin
-                                  if lAHdr.scl_slope <> lSlopeRA^[l4DOffset+lInc] then
-                                     lScaleFactorVariesInThis4DVolume := true;
-                                  if lAHdr.scl_inter <> lInterceptRA^[l4DOffset+lInc] then
-                                     lScaleFactorVariesInThis4DVolume := true;
-                                end;
-                              end;
-                              if lScaleFactorVariesInThis4DVolume then begin
-				  lAHdr.bitpix := 32;
-				  lAHdr.DataType := 16;
-				  lAHdr.scl_slope := 1;
-				  lAHdr.scl_inter := 0;
-                                  lSliceSzOutx := lSlicePixelsx*sizeof(single);
-                              end;
-                           end;
-                           //end of 4D scale factor variation...
-                           lAHdr.sform_code := lNHdr.sform_code;
-                           lAHdr.srow_x[0] := lNHdr.srow_x[0];
-                           lAHdr.srow_x[1] := lNHdr.srow_x[1];
-                           lAHdr.srow_x[2] := lNHdr.srow_x[2];
-                           lAHdr.srow_x[3] := lNHdr.srow_x[3];
-                           lAHdr.srow_y[0] := lNHdr.srow_y[0];
-                           lAHdr.srow_y[1] := lNHdr.srow_y[1];
-                           lAHdr.srow_y[2] := lNHdr.srow_y[2];
-                           lAHdr.srow_y[3] := lNHdr.srow_y[3];
-                           lAHdr.srow_z[0] := lNHdr.srow_z[0];
-                           lAHdr.srow_z[1] := lNHdr.srow_z[1];
-                           lAHdr.srow_z[2] := lNHdr.srow_z[2];
-                           lAHdr.srow_z[3] := lNHdr.srow_z[3];
-                           lAHdr.qform_code := lNHdr.qform_code;
-   lAHdr.quatern_b := lNHdr.quatern_b;
-   lAHdr.quatern_c := lNHdr.quatern_c;
-   lAHdr.quatern_d := lNHdr.quatern_d;
-   lAHdr.qoffset_x := lNHdr.qoffset_x;
-   lAHdr.qoffset_y := lNHdr.qoffset_y;
-   lAHdr.qoffset_z := lNHdr.qoffset_z;
-   lAHdr.pixdim[0] := lNHdr.pixdim[0];
-   {$IFDEF ENDIAN_BIG}
-   if SaveHdr (lOutHdrName,lAHdr, true,lPrefs.SPM2) then begin
-   {$ELSE}
-   if SaveHdr (lOutHdrName,lAHdr, false,lPrefs.SPM2) then begin
-   {$ENDIF}
-				  Filemode := 2;//1385: read-write
-				  AssignFile(lOutF, lOutImgName);
-				  if lPrefs.SingleNIIFile then begin
-					Reset(lOutF,1);
-					Seek(lOutF,352);
-                                        lAHdr.vox_offset := 352;
-				  end else
-					Rewrite(lOutF,1); //setting block size only about 12% speed increase: HD cache must help
-				  Filemode := 0;//1385: read-only
-				  AssignFile(lInF, lRecFilename);
-				  Reset(lInF,lSliceSzx);
-				  GetMem(lBuffer,lSliceSzx);
-				  if lScaleFactorVariesInThis4DVolume then
-					 GetMem(lSingleBuffer,lSliceSzOutx);
-				  for lInc := 1 to lnSlicesx do begin
-					  //application.ProcessMessages;
-					  if lOffsetTableEntries > 1 then //data not contiguous
-						 Seek(lInF,  (lOffset_pos_table^[lInc+l4DOffset] div lSliceSzx))
-					  else
-						  Seek(lInF, (l4DOffset+lInc-1));
-					  Filemode := 0;  //ReadONly
-					  BlockRead(lInF, lBuffer^, 1);
-					  Filemode := 2;  //read and write
-					  GetMem ( lP ,  lColBytes);
-					  for lLines := 1 to lRowsdiv2 do begin
-						  Move(lBuffer[((lLines-1)*lColBytes)+1],lP^,lColBytes);
-						  Move(lBuffer[(( lRows-lLines)*lColBytes)+1],lBuffer[((lLines-1)*lColBytes)+1],lColBytes);
-						  Move(lP^,lBuffer[(( lRows-lLines)*lColBytes)+1],lColBytes);
-					  end;
-					  FreeMem(lP);
-					  if lScaleFactorVariesInThis4DVolume  then begin
-						  if lDicomData.Allocbits_per_pixel = 8 then begin
-							 for lLines := 1 to lSlicePixelsx do
-							  lSingleBuffer^[lLines] := lBuffer^[lLines]*lSlopeRA^[l4DOffset+lInc]+lInterceptRA^[l4DOffset+lInc];
-						  end else if lDicomData.Allocbits_per_pixel = 16 then begin
-							 lPos := 1;
-							 for lLines := 1 to lSlicePixelsx do begin
-							  lSingleBuffer^[lLines] := lBuffer^[lLines]*lSlopeRA^[l4DOffset+lInc]+lInterceptRA^[l4DOffset+lInc];
-							  //lSingleBuffer^[lLines] := lBuffer^[lPos]*lRS+lRI;
-							  inc(lPos,2);
-							 end;
-						  end else
-							  Msg('Error: can only convert 8/16bit PAR/REC files with varying scaling values.');
-						  BlockWrite(lOutF, lSingleBuffer^, lSliceSzOutx);
-					  end else
-						  BlockWrite(lOutF, lBuffer^, lSliceSzOutx);
-				  end;
-				  CloseFile(lOutF);
-				  CloseFile(lInF);
-				  freemem(lBuffer);
-				  if lScaleFactorVariesInThis4DVolume then
-					 FreeMem(lSingleBuffer);
-			   end else
-				   lAbort := true; //save header failed: probably read only disk, or less than 348 bytes: do not force inidividual to see message for each file
-                //if (lPrefs.StartClip > 0) or (lPrefs.EndClip > 0) then
-                //   Clip4D(lOutHdrName, lAHdr, false,lPrefs.SPM2,lPrefs.SingleNIIFile,lPrefs.GZip,true, lPrefs.StartClip,lPrefs.EndClip);
-                (*if (not lPrefs.FourD) and (lAHdr.dim[4] > 1) then begin
-                   Convert4Dto3D(lOutImgName, lAHdr, false,lPrefs.SPM2,lPrefs.SingleNIIFile, lPrefs.Gzip);
-                end else if lPrefs.SingleNIIFile and lPrefs.Gzip then
-                   GZipFile(lOutImgName,lOutImgName+'.gz',true);*)
-
-                if ((not lPrefs.FourD) and (lAHdr.dim[4] > 1)) {or ((lPrefs.SingleNIIFile) and (lPrefs.Gzip))} then
-                   if ChangeNIfTISubformat(lOutImgName, lAHdr,lPrefs) then begin
-                      deleteFile(lOutImgName);//11/2007 : delete original
-                   end;
-               end; //file OK
-
-
-	 until (lcurrent4Dvol>=lnum4Ddatasets) or (lAbort); //for each 4D dataset
-  end; //lHdrOK
-	 if lOffsetTableEntries > 0 then begin
-			   freemem (lOffset_pos_table);
-			   lOffsetTableEntries := 0;
-	 end; //slice offset table filled
-	 if lRescaleEntries > 0 then begin
-			   freemem ( lSlopeRA);
-			   freemem (lInterceptRA);
-	 end; //slice offset table filled
-end; //REC exists
-		 if lAbort then goto 678;
-   result := true;
-   ExitCode := 0;
-   if (lDicomData.XYZdim[2] > lPrefs.MinReorientMatrix) and (lDicomData.XYZdim[1] > lPrefs.MinReorientMatrix) and (lAHdr.dim[4] < 2) then begin
-           lOutImgName := Reorient(lOutImgName,lAHdr,lPrefs,false,false);
-           if (lOutImgName <> '') {success}and (lDicomData.TE < 25) then //T1 image
-              CropNIfTI(lOutImgName,lPrefs);
-   end;
-
-	 678:
-	 Filemode := 2; //1385
-end;
-
-function LoadFileListPARREC  (var lInFilename, lOutDir: string; var lPrefs: TPrefs): boolean;
-var
- lFilePath,lMaskExt,lPARname,lOutDirName: String;
- lError: boolean;
- lSearchRec: TSearchRec;
-begin
-     lOutDirName := lOutDir;
-     if (lPrefs.OutDirMode <> kOutDirModeInput) and (DirExists(lPrefs.OutDir)) then begin
-        //For kOutDirModePrompt one should set OutDir before getting here
-        //This is required so recursive searches do not repetitively prompt the user...
-        lOutDirName := lPrefs.OutDir;
-     end; //1/2010
-     lOutDirName := ExtractFileDirWithPathDelim(lOutDirName);
-     if not DirWritePermission(lOutDirName) then begin // <- tested with Unix
-        Msg('Error: output directory is read-only: '+lOutDirName);
-        exit;
-     end;
-   lError := false;
-   if lPrefs.EveryFile = true then begin
-      lFilePath := ExtractFileDirWithPathDelim(lInFilename);
-      {$IFDEF Linux}
-      lMaskExt := '*';
-      {$ELSE}
-      lMaskExt := '*.*';
-      {$ENDIF}
-      Filemode := 0; //readonly
-      if FindFirst(lFilePath{+PathDelim}+lMaskExt, faAnyFile-faSysFile-faDirectory, lSearchRec) = 0 then begin
-         repeat
-	       if UpCaseExt(lSearchRec.Name) = '.PAR' then begin
-				lPARname := (lFilePath+lSearchRec.Name);
-				result := ConvertPhilipsPARtoAnalyze(lPARname, lOutDirName, lPrefs);
-                                if not result then
-                                   lError := true;
-			end;
-              until (FindNext(lSearchRec) <> 0);
-         end else
-               Msg( 'Error: Unable to find PAR files in '+lFilePath{+PathDelim}+lMaskExt); //some files found
-	 SysUtils.FindClose(lSearchRec);
-	 Filemode := 2;
-   end else begin
-      if FileExists(lInFilename) then begin
-	 lError := ConvertPhilipsPARtoAnalyze(lInFilename, lOutDirName, lPrefs);
-      end else
-	 Msg( 'Unable to find PAR file named '+lInFilename); //some files found
-   end;
-   if lError then
-      result := false //at least one error
-   else
-       result := true;
-end;
-
-end.
-
diff --git a/dcm2nii_prePARRECDTI/pref_form.dfm b/dcm2nii_prePARRECDTI/pref_form.dfm
deleted file mode 100755
index d300a3e..0000000
Binary files a/dcm2nii_prePARRECDTI/pref_form.dfm and /dev/null differ
diff --git a/dcm2nii_prePARRECDTI/pref_form.lfm b/dcm2nii_prePARRECDTI/pref_form.lfm
deleted file mode 100755
index 830f7fc..0000000
--- a/dcm2nii_prePARRECDTI/pref_form.lfm
+++ /dev/null
@@ -1,189 +0,0 @@
-object PrefsForm: TPrefsForm
-  Left = 401
-  Height = 424
-  Top = 198
-  Width = 464
-  HorzScrollBar.Page = 463
-  VertScrollBar.Page = 323
-  ActiveControl = DateCheck
-  BorderIcons = [biSystemMenu]
-  Caption = 'Preferences'
-  ClientHeight = 424
-  ClientWidth = 464
-  Constraints.MaxHeight = 424
-  Constraints.MaxWidth = 464
-  Constraints.MinHeight = 389
-  Constraints.MinWidth = 464
-  Position = poDesktopCenter
-  LCLVersion = '0.9.30'
-  object Label1: TLabel
-    Left = 129
-    Height = 17
-    Top = 291
-    Width = 188
-    Caption = 'Recursive folder search depth'
-    ParentColor = False
-  end
-  object OutDirLabel: TLabel
-    Left = 43
-    Height = 17
-    Top = 352
-    Width = 19
-    Caption = 'c:\'
-    ParentColor = False
-  end
-  object FilenameBox: TGroupBox
-    Left = 8
-    Height = 160
-    Top = 8
-    Width = 448
-    Caption = 'Output Filename'
-    ClientHeight = 138
-    ClientWidth = 440
-    TabOrder = 0
-    object DateCheck: TCheckBox
-      Left = 22
-      Height = 18
-      Top = 8
-      Width = 124
-      Caption = 'Acquisition Date'
-      OnChange = FilenameChecks
-      TabOrder = 0
-    end
-    object InputNameCheck: TCheckBox
-      Left = 22
-      Height = 18
-      Top = 33
-      Width = 114
-      Caption = 'Input Filename'
-      OnChange = FilenameChecks
-      TabOrder = 1
-    end
-    object ProtocolCheck: TCheckBox
-      Left = 22
-      Height = 18
-      Top = 57
-      Width = 113
-      Caption = 'Protocol Name'
-      OnChange = FilenameChecks
-      TabOrder = 2
-    end
-    object PatientNameCheck: TCheckBox
-      Left = 22
-      Height = 18
-      Top = 81
-      Width = 104
-      Caption = 'Patient Name'
-      OnChange = FilenameChecks
-      TabOrder = 3
-    end
-    object SeriesCheck: TCheckBox
-      Left = 22
-      Height = 18
-      Top = 105
-      Width = 132
-      Caption = 'Acquisition Series'
-      OnChange = FilenameChecks
-      TabOrder = 4
-    end
-  end
-  object OKbtn: TButton
-    Left = 360
-    Height = 25
-    Top = 392
-    Width = 75
-    BorderSpacing.InnerBorder = 4
-    Caption = 'OK'
-    ModalResult = 1
-    TabOrder = 1
-  end
-  object CancelBtn: TButton
-    Left = 272
-    Height = 25
-    Top = 392
-    Width = 75
-    BorderSpacing.InnerBorder = 4
-    Caption = 'Cancel'
-    ModalResult = 2
-    TabOrder = 2
-  end
-  object NotAnonymizeCheck: TCheckBox
-    Left = 35
-    Height = 18
-    Top = 172
-    Width = 233
-    Caption = 'Save patient name in NIfTI header'
-    TabOrder = 3
-  end
-  object ReorientCheck: TCheckBox
-    Left = 35
-    Height = 18
-    Top = 202
-    Width = 338
-    Caption = 'Reorient large images to nearest orthogonal plane'
-    TabOrder = 4
-  end
-  object RecursiveSpin: TSpinEdit
-    Left = 38
-    Height = 16
-    Top = 288
-    Width = 77
-    MaxValue = 10
-    TabOrder = 5
-  end
-  object OutputCombo: TComboBox
-    Left = 35
-    Height = 20
-    Top = 320
-    Width = 253
-    ItemHeight = 0
-    Items.Strings = (
-      'Save to source folder'
-      'Prompt user for output folder'
-      'Always save to...'
-    )
-    OnChange = OutputComboChange
-    OnMouseUp = OutputComboMouseUp
-    Style = csDropDownList
-    TabOrder = 6
-  end
-  object CollapseCheck: TCheckBox
-    Left = 35
-    Height = 18
-    Hint = 'Sort images regardless of source directory. Slower, required if series segmented across folders'
-    Top = 232
-    Width = 122
-    Caption = 'Collapse folders'
-    TabOrder = 7
-  end
-  object Stack3DImagesWithSameAcqNum: TCheckBox
-    Left = 35
-    Height = 18
-    Hint = 'Sort images regardless of source directory. Slower, required if series segmented across folders'
-    Top = 262
-    Width = 316
-    Caption = 'Stack 3D images with same acquistion number'
-    TabOrder = 8
-  end
-  object TextEditorBtn: TButton
-    Left = 38
-    Height = 25
-    Top = 392
-    Width = 123
-    BorderSpacing.InnerBorder = 4
-    Caption = 'Text Edit'
-    OnClick = TextEditorBtnClick
-    TabOrder = 9
-  end
-  object WritePrefsOnQuit: TCheckBox
-    Left = 284
-    Height = 18
-    Top = 230
-    Width = 138
-    Caption = 'Write prefs on quit'
-    Checked = True
-    State = cbChecked
-    TabOrder = 10
-    Visible = False
-  end
-end
diff --git a/dcm2nii_prePARRECDTI/pref_form.lrs b/dcm2nii_prePARRECDTI/pref_form.lrs
deleted file mode 100755
index a18876b..0000000
--- a/dcm2nii_prePARRECDTI/pref_form.lrs
+++ /dev/null
@@ -1,56 +0,0 @@
-{ This is an automatically generated lazarus resource file }
-
-LazarusResources.Add('TPrefsForm','FORMDATA',[
-  'TPF0'#10'TPrefsForm'#9'PrefsForm'#4'Left'#3#145#1#6'Height'#3#168#1#3'Top'#3
-  +#198#0#5'Width'#3#208#1#18'HorzScrollBar.Page'#3#207#1#18'VertScrollBar.Page'
-  +#3'C'#1#13'ActiveControl'#7#9'DateCheck'#11'BorderIcons'#11#12'biSystemMenu'
-  +#0#7'Caption'#6#11'Preferences'#12'ClientHeight'#3#168#1#11'ClientWidth'#3
-  +#208#1#21'Constraints.MaxHeight'#3#168#1#20'Constraints.MaxWidth'#3#208#1#21
-  +'Constraints.MinHeight'#3#133#1#20'Constraints.MinWidth'#3#208#1#8'Position'
-  +#7#15'poDesktopCenter'#10'LCLVersion'#6#6'0.9.30'#0#6'TLabel'#6'Label1'#4'Le'
-  +'ft'#3#129#0#6'Height'#2#17#3'Top'#3'#'#1#5'Width'#3#188#0#7'Caption'#6#29'R'
-  +'ecursive folder search depth'#11'ParentColor'#8#0#0#6'TLabel'#11'OutDirLabe'
-  +'l'#4'Left'#2'+'#6'Height'#2#17#3'Top'#3'`'#1#5'Width'#2#19#7'Caption'#6#3'c'
-  +':\'#11'ParentColor'#8#0#0#9'TGroupBox'#11'FilenameBox'#4'Left'#2#8#6'Height'
-  +#3#160#0#3'Top'#2#8#5'Width'#3#192#1#7'Caption'#6#15'Output Filename'#12'Cli'
-  +'entHeight'#3#138#0#11'ClientWidth'#3#184#1#8'TabOrder'#2#0#0#9'TCheckBox'#9
-  +'DateCheck'#4'Left'#2#22#6'Height'#2#18#3'Top'#2#8#5'Width'#2'|'#7'Caption'#6
-  +#16'Acquisition Date'#8'OnChange'#7#14'FilenameChecks'#8'TabOrder'#2#0#0#0#9
-  +'TCheckBox'#14'InputNameCheck'#4'Left'#2#22#6'Height'#2#18#3'Top'#2'!'#5'Wid'
-  +'th'#2'r'#7'Caption'#6#14'Input Filename'#8'OnChange'#7#14'FilenameChecks'#8
-  +'TabOrder'#2#1#0#0#9'TCheckBox'#13'ProtocolCheck'#4'Left'#2#22#6'Height'#2#18
-  +#3'Top'#2'9'#5'Width'#2'q'#7'Caption'#6#13'Protocol Name'#8'OnChange'#7#14'F'
-  +'ilenameChecks'#8'TabOrder'#2#2#0#0#9'TCheckBox'#16'PatientNameCheck'#4'Left'
-  +#2#22#6'Height'#2#18#3'Top'#2'Q'#5'Width'#2'h'#7'Caption'#6#12'Patient Name'
-  +#8'OnChange'#7#14'FilenameChecks'#8'TabOrder'#2#3#0#0#9'TCheckBox'#11'Series'
-  +'Check'#4'Left'#2#22#6'Height'#2#18#3'Top'#2'i'#5'Width'#3#132#0#7'Caption'#6
-  +#18'Acquisition Series'#8'OnChange'#7#14'FilenameChecks'#8'TabOrder'#2#4#0#0
-  +#0#7'TButton'#5'OKbtn'#4'Left'#3'h'#1#6'Height'#2#25#3'Top'#3#136#1#5'Width'
-  +#2'K'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#2'OK'#11'ModalResult'#2
-  +#1#8'TabOrder'#2#1#0#0#7'TButton'#9'CancelBtn'#4'Left'#3#16#1#6'Height'#2#25
-  +#3'Top'#3#136#1#5'Width'#2'K'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6
-  +#6'Cancel'#11'ModalResult'#2#2#8'TabOrder'#2#2#0#0#9'TCheckBox'#17'NotAnonym'
-  +'izeCheck'#4'Left'#2'#'#6'Height'#2#18#3'Top'#3#172#0#5'Width'#3#233#0#7'Cap'
-  +'tion'#6'!Save patient name in NIfTI header'#8'TabOrder'#2#3#0#0#9'TCheckBox'
-  +#13'ReorientCheck'#4'Left'#2'#'#6'Height'#2#18#3'Top'#3#202#0#5'Width'#3'R'#1
-  +#7'Caption'#6'1Reorient large images to nearest orthogonal plane'#8'TabOrder'
-  +#2#4#0#0#9'TSpinEdit'#13'RecursiveSpin'#4'Left'#2'&'#6'Height'#2#16#3'Top'#3
-  +' '#1#5'Width'#2'M'#8'MaxValue'#2#10#8'TabOrder'#2#5#0#0#9'TComboBox'#11'Out'
-  +'putCombo'#4'Left'#2'#'#6'Height'#2#20#3'Top'#3'@'#1#5'Width'#3#253#0#10'Ite'
-  +'mHeight'#2#0#13'Items.Strings'#1#6#21'Save to source folder'#6#29'Prompt us'
-  +'er for output folder'#6#17'Always save to...'#0#8'OnChange'#7#17'OutputComb'
-  +'oChange'#9'OnMouseUp'#7#18'OutputComboMouseUp'#5'Style'#7#14'csDropDownList'
-  +#8'TabOrder'#2#6#0#0#9'TCheckBox'#13'CollapseCheck'#4'Left'#2'#'#6'Height'#2
-  +#18#4'Hint'#6'_Sort images regardless of source directory. Slower, required '
-  +'if series segmented across folders'#3'Top'#3#232#0#5'Width'#2'z'#7'Caption'
-  +#6#16'Collapse folders'#8'TabOrder'#2#7#0#0#9'TCheckBox'#27'Stack3DImagesWit'
-  +'hSameAcqNum'#4'Left'#2'#'#6'Height'#2#18#4'Hint'#6'_Sort images regardless '
-  +'of source directory. Slower, required if series segmented across folders'#3
-  +'Top'#3#6#1#5'Width'#3'<'#1#7'Caption'#6'+Stack 3D images with same acquisti'
-  +'on number'#8'TabOrder'#2#8#0#0#7'TButton'#13'TextEditorBtn'#4'Left'#2'&'#6
-  +'Height'#2#25#3'Top'#3#136#1#5'Width'#2'{'#25'BorderSpacing.InnerBorder'#2#4
-  +#7'Caption'#6#9'Text Edit'#7'OnClick'#7#18'TextEditorBtnClick'#8'TabOrder'#2
-  +#9#0#0#9'TCheckBox'#16'WritePrefsOnQuit'#4'Left'#3#28#1#6'Height'#2#18#3'Top'
-  +#3#230#0#5'Width'#3#138#0#7'Caption'#6#19'Write prefs on quit'#7'Checked'#9#5
-  +'State'#7#9'cbChecked'#8'TabOrder'#2#10#7'Visible'#8#0#0#0
-]);
diff --git a/dcm2nii_prePARRECDTI/pref_form.pas b/dcm2nii_prePARRECDTI/pref_form.pas
deleted file mode 100755
index e760b4d..0000000
--- a/dcm2nii_prePARRECDTI/pref_form.pas
+++ /dev/null
@@ -1,192 +0,0 @@
-unit pref_form;
-
-interface
-
-uses
-
-{$IFDEF FPC}LResources,{$ENDIF}
-  {$IFDEF UNIX}Process, {$ELSE}ShellApi, Windows,{$ENDIF} Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
-  StdCtrls,filename,define_types,dicomtypes,prefs, Spin, Buttons;
-
-type
-{$H+}
-  { TPrefsForm }
-  TPrefsForm = class(TForm)
-   // WritePrefsOnQuit: TCheckBox;
-   // TextEditorBtn: TButton;
-    Stack3DImagesWithSameAcqNum: TCheckBox;
-    OutputCombo: TComboBox;
-    FilenameBox: TGroupBox;
-    DateCheck: TCheckBox;
-    OutDirLabel: TLabel;
-    CollapseCheck: TCheckBox;
-    SeriesCheck: TCheckBox;
-    ProtocolCheck: TCheckBox;
-    PatientNameCheck: TCheckBox;
-    InputNameCheck: TCheckBox;
-    NotAnonymizeCheck: TCheckBox;
-    ReorientCheck: TCheckBox;
-    OKBtn: TButton;
-    CancelBtn: TButton;
-    RecursiveSpin: TSpinEdit;
-    Label1: TLabel;
-    TextEditorBtn: TButton;
-    WritePrefsOnQuit: TCheckBox;
-    //Stack3DImagesWithSameAcqNum: TCheckBox;
-    //CollapseCheck: TCheckBox;
-    procedure FilenameChecks(Sender: TObject);
-    procedure OutputComboMouseUp(Sender: TObject; Button: TMouseButton;
-      Shift: TShiftState; X, Y: Integer);
-    procedure ReadPrefs(var lPrefs: TPrefs);
-    procedure TextEditorBtnClick(Sender: TObject);
-    procedure WritePrefs(var lPrefs: TPrefs);
-    procedure SetOutDirLabel;
-    procedure OutputComboChange(Sender: TObject);
-    procedure SetOutput;
-  private
-    { Private declarations }
-  public
-    { Public declarations }
-  end;
-
-var
-  PrefsForm: TPrefsForm;
-
-implementation
-{$IFNDEF FPC}
-{$R *.DFM}
-{$ENDIF}
-uses gui,userdir;
-var
-   gPrefs: TPrefs;
-procedure TPrefsForm.SetOutDirLabel;
-begin
-     OutDirLabel.visible :=  (OutputCombo.ItemIndex = kOutDirModeOutDir);
-end;
-
-procedure TPrefsForm.WritePrefs(var lPrefs: TPrefs);
-begin
-     gPrefs := lPrefs;
-     Stack3DImagesWithSameAcqNum.Checked := lPrefs.Stack3DImagesWithSameAcqNum;
-     DateCheck.Checked := lPrefs.AppendDate;
-     SeriesCheck.Checked := lPrefs.AppendAcqSeries;
-     ProtocolCheck.Checked := lPrefs.AppendProtocolName;
-     PatientNameCheck.Checked := lPrefs.AppendPatientName;
-     InputNameCheck.checked := lPrefs.AppendFilename;
-     CollapseCheck.checked := lPrefs.CollapseFolders;
-     ReorientCheck.Checked := (lPrefs.MinReorientMatrix < 32000);
-     NotAnonymizeCheck.Checked := not lPrefs.Anonymize;
-     RecursiveSpin.Value := lPrefs.RecursiveFolderDepth;
-     OutDirLabel.Caption := lPrefs.OutDir;
-     if (lPrefs.OutDirMode < 0) or (lPrefs.OutDirMode >= OutputCombo.Items.count) then
-        lPrefs.OutDirMode := 0;
-     OutputCombo.ItemIndex := lPrefs.OutDirMode;
-     SetOutDirLabel;
-end;
-
-procedure TPrefsForm.ReadPrefs(var lPrefs: TPrefs);
-begin
-    lPrefs := gPrefs;
-    lPrefs.Stack3DImagesWithSameAcqNum := Stack3DImagesWithSameAcqNum.checked;
-    lPrefs.AppendDate := DateCheck.Checked;
-    lPrefs.AppendAcqSeries := SeriesCheck.Checked;
-    lPrefs.AppendProtocolName := ProtocolCheck.Checked;
-    lPrefs.AppendPatientName := PatientNameCheck.Checked;
-    lPrefs.AppendFilename := InputNameCheck.checked;
-    //lPrefs.SaveToBaseFolder := SaveToBaseFolderCheck.Checked;
-    lPrefs.CollapseFolders := CollapseCheck.checked;
-    if ReorientCheck.Checked then begin
-       if lPrefs.MinReorientMatrix = MaxInt then
-          lPrefs.MinReorientMatrix := kMinReorientMatrix
-    end else
-        lPrefs.MinReorientMatrix := MaxInt;
-    lPrefs.Anonymize := not NotAnonymizeCheck.Checked;
-    lPrefs.RecursiveFolderDepth := RecursiveSpin.Value;
-    lPrefs.OutDir := OutDirLabel.Caption;
-    lPrefs.OutDirMode := OutputCombo.ItemIndex;
-    lPrefs.WritePrefsOnQuit := WritePrefsOnQuit.Checked;
-end;
-
-
-procedure TPrefsForm.TextEditorBtnClick(Sender: TObject);
-{$IFDEF UNIX}
-var
-  AProcess: TProcess;
-begin
-    Showmessage('Preferences will be opened in a text editor. The program '+ExtractFilename(paramstr(0))+' will now quit, so that the file will not be overwritten.');
-    MainForm.SavePrefs;
-    AProcess := TProcess.Create(nil);
-    {$IFDEF UNIX}
-            {$IFDEF Darwin}
-            AProcess.CommandLine := 'open -a TextEdit '+IniName;
-            {$ELSE}
-            AProcess.CommandLine := 'open -a gedit '+IniName;
-            {$ENDIF}
-    {$ELSE}
-          AProcess.CommandLine := 'notepad '+IniName;
-    {$ENDIF}
-  //AProcess.Options := AProcess.Options + [poWaitOnExit];
-  AProcess.Execute;
-  AProcess.Free;
-  WritePrefsOnQuit.checked := false;
-  MainForm.close;
-end;
-{$ELSE} //ShellExecute(Handle,'open', 'c:\windows\notepad.exe','c:\SomeText.txt', nil, SW_SHOWNORMAL) ;
-begin
-    Showmessage('Preferences will be opened in a text editor. The program '+ExtractFilename(paramstr(0))+' will now quit, so that the file will not be overwritten.');
-   MainForm.SavePrefs;
-    ShellExecute(Handle,'open', 'notepad.exe',PAnsiChar(AnsiString(IniName)), nil, SW_SHOWNORMAL) ;
-  WritePrefsOnQuit.checked := false;
-  MainForm.close;
-end;
-{$ENDIF}
-
-procedure TPrefsForm.FilenameChecks(Sender: TObject);
-var
-   lDICOMImgName: string;
-   lDicomData: DICOMdata;
-   lPrefs: TPrefs;
-begin
-   Clear_Dicom_Data(lDicomData);
-   SetDefaultPrefs (lPrefs);
-   ReadPrefs(lPrefs);
-  clear_dicom_data(lDicomData);
-   lDICOMImgName:= 'IM_0160';
-   //lDicomData.StudyDate := '1/1/1970';
-   lDicomData.PatientName := 'JOHNDOE';
-   lDicomData.ProtocolName := 'AnatT1';
-   //FilenameBox.Caption := 'Output Filename ('+  OutputFilename(lDicomImgName,lDicomData,lPrefs.AppendDate,lPrefs.AppendAcqSeries,lPrefs.AppendProtocolName,lPrefs.AppendPatientName,lPrefs.FourD,lPrefs.AppendFilename)+')';
-   FilenameBox.Caption := 'Output Filename ('+  OutputFilename(lDicomImgName,lDicomData,lPrefs)+')';
-end;
-
-procedure TPrefsForm.SetOutput;
-begin
-      SetOutDirLabel;
-  if not (OutputCombo.ItemIndex = kOutDirModeOutDir) then
-     exit;
-  OutDirLabel.Caption := GetDirPrompt(OutDirLabel.Caption);
-end;
-
-procedure TPrefsForm.OutputComboMouseUp(Sender: TObject; Button: TMouseButton;
-  Shift: TShiftState; X, Y: Integer);
-//for OSX
-begin
- {$IFDEF Darwin}
-   SetOutput;
- {$ENDIF}
-end;
-
-procedure TPrefsForm.OutputComboChange(Sender: TObject);
-//for all OSes except OSX...
-begin
-{$IFNDEF Darwin}
-     SetOutput;
-{$ENDIF}
-end;
-
-initialization
-{$IFDEF FPC}
-  {$I pref_form.lrs}
- {$ENDIF}
-
-end.
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/prefs.pas b/dcm2nii_prePARRECDTI/prefs.pas
deleted file mode 100755
index 4693b76..0000000
--- a/dcm2nii_prePARRECDTI/prefs.pas
+++ /dev/null
@@ -1,276 +0,0 @@
-unit prefs;
-{$H+}
-{$Include ..\common\isgui.inc}
-interface
-uses
-  {$IFDEF FPC}
-  {$IFDEF UNIX} BaseUnix,{$ENDIF}
-  {$IFDEF GUI}LResources, {$ENDIF}
-  
-  {$ELSE}
-   SelectFolder,
-{$ENDIF}
-  inifiles, define_types,SysUtils, userdir, dialogsx;
-
-type
-  TPrefs = record
-         WritePrefsOnQuit,OrthoFlipXDim,RecursiveUseNameAppend,AnonymizeSourceDICOM, ManualNIfTIConv,Anonymize,
-          SingleNIIFile,Gzip,SPM2,VOI,enablereorient,createoutputfolder,
-         AppendDate,AppendAcqSeries,AppendProtocolName,AppendPatientName,AppendFilename,
-         everyfile,fourD,Swizzle4D,Stack3DImagesWithSameAcqNum,customRename,
-         CollapseFolders,AutoCrop, UseGE_0021_104F, PhilipsPrecise,Verbose,DebugMode,DebugMode2,UntestedFeatures,UINT16toFLOAT32: boolean;
-
-         BeginClip, LastClip,SiemensDTIUse0019If00181020atleast,
-         SiemensDTINoAngulationCorrectionIf00181020atleast,
-         SiemensDTIStackIf00181020atleast,
-         OutDirMode, MinReorientMatrix,MaxReorientMatrix,RecursiveFolderDepth,usePigz,maxGb64bit
-         : integer;
-         OutDir, BackupDir,NameAppend: string;
-  end;
-const
-     kOutDirModeInput = 0;//save output files to source folder
-     kOutDirModePrompt = 1;//prompt user to specify location of output dir
-     kOutDirModeOutDir = 2;//save output to lPrefs.OutDir
-     kMinReorientMatrix = 200; //reorient images with matrices > this value
-procedure SetOutputFormat (lItemIndex: integer; var lPrefs: TPrefs);
-procedure SetDefaultPrefs (var lPrefs: TPrefs);
-procedure CorrectPrefs (var lPrefs: TPrefs); //ensures only usable file types are created
-function IniFile(lRead: boolean; lFilename: string; var lPrefs: TPrefs): boolean;
-function DefaultOutputFormat (lPrefs: TPrefs): integer;
-
-implementation
-
-function DefaultOutputFormat (lPrefs: TPrefs): integer;
-begin
-     if lPrefs.SPM2 then
-          result := 0 //SPM2 3D hdr/img analyze
-     else if not lPrefs.FourD  then begin
-            if not (lPrefs.SingleNIIFile) then
-               result := 1 //SPM5 3D hdr/img
-            else
-                result:= 2; //SPM8 3D nii
-     end else if not lPrefs.SingleNIIFile then
-            result := 3 //?? 4D hdr/img
-     else if not lPrefs.GZip then
-            result := 4 //FSL 4D nii
-     else
-           result := 5; //FSL 4D nii.gz
-end;
-
-procedure SetOutputFormat (lItemIndex: integer; var lPrefs: TPrefs);
-//SetOutputFormat(n,lPrefs) : 0=SPM2,1=SPM5,2=spm8,3=4D hdr/img,4=fsl(default),5=fsl.gz, 6=.voi
-begin
-    //next: options for reading;
-    lPrefs.VOI := false;
-    lPrefs.SPM2 := false;
-    lPrefs.fourD := true;
-    lPrefs.SingleNIIFile := true;
-    lPrefs.GZip := false;
-    case lItemIndex of
-         0: begin//spm2
-                lPrefs.SPM2 := true;
-                lPrefs.fourD := false;
-                lPrefs.SingleNIIFile := false;
-                end;
-         1: begin//spm5
-                lPrefs.fourD := false;
-                lPrefs.SingleNIIFile := false;
-                end;
-         2: begin//spm8
-                lPrefs.fourD := false;
-                end;
-         3: lPrefs.SingleNIIFile := false;//4D Hdr/Img
-         5: lPrefs.GZip := true;//FSL compressed
-         6: begin //VOI
-            lPrefs.GZip := true;//FSL compressed
-            lPrefs.VOI := true;
-         end;
-    end;//case
-end;
-
-procedure CorrectPrefs (var lPrefs: TPrefs); //ensures only usable file types are created
-begin
-  if lPrefs.SingleNIIFile then
-     lPrefs.SPM2 := false; //SPM2 only reads .hdr/.img - loses NIfTI information
-  if not lPrefs.SingleNIIFile then
-     lPrefs.Gzip := false; //nii.gz is OK, but img.gz is not
-end;
-
-procedure SetDefaultPrefs (var lPrefs: TPrefs);
-begin
- with lPrefs do begin
-  OutDirMode := kOutDirModeInput;
-  SiemensDTIUse0019If00181020atleast := 15;
-  SiemensDTINoAngulationCorrectionIf00181020atleast := 1000;
-  SiemensDTIStackIf00181020atleast := 15;
-  //IgnoreDTIRotationsIf_0002_0013_atleast := 15;
-  VOI := false;
-  OutDir := UserDataFolder;
-  PhilipsPrecise := false;
-  UseGE_0021_104F := false;
-  CollapseFolders := true;
-  AutoCrop := false; //for dcm2nii - reorient and crop 3D nifti input images...
-  CustomRename := false;
-  createoutputfolder := false;
-  Stack3DImagesWithSameAcqNum := false;
-  RecursiveUseNameAppend := false;//changes paramstrs.pas recursive search to add top level folder name
-  DebugMode := false;
-  DebugMode2 := false;
-  UntestedFeatures := false;
-  Verbose := false;
-  SingleNIIFile := true;
-  Gzip := true;
-  OrthoFlipXDim := false;
-  SPM2 := false;
-  Anonymize := true;
-  AppendDate := true;
-  AppendAcqSeries := true;
-  AppendProtocolName := true;
-  AppendPatientName := false;
-  AppendFilename := false;
-  EveryFile:=true;
-  FourD := true;
-  enablereorient := true;
-  ManualNIfTIConv := true;
-  AnonymizeSourceDICOM := false;
-  Swizzle4D := true;
-  RecursiveFolderDepth := 5;
-  MinReorientMatrix := kMinReorientMatrix;
-  MaxReorientMatrix := 1023;
-  NameAppend := '';
-  BackupDir := '';
-  WritePrefsOnQuit := true;
-  UINT16toFLOAT32 := true;
-  BeginClip := 0;
-  LastClip := 0;
-  usePigz := 0;
-  {$ifdef CPU64}
-    maxGb64bit := 6;
-  {$ELSE}
-    maxGb64bit := 1;
-  {$ENDIF}
-
- end;
-end;
-
-procedure IniInt(lRead: boolean; lIniFile: TCustomIniFile; lIdent: string;  var lValue: integer);
-//read or write an integer value to the initialization file
-var
-	lStr: string;
-begin
-        if not lRead then begin
-           lIniFile.WriteString('INT',lIdent,IntToStr(lValue));
-           exit;
-        end;
-	lStr := lIniFile.ReadString('INT',lIdent, '');
-	if length(lStr) > 0 then
-		lValue := StrToInt(lStr);
-end; //IniInt
-
-procedure IniBool(lRead: boolean; lIniFile: TCustomIniFile; lIdent: string;  var lValue: boolean);
-//read or write a boolean value to the initialization file
-var
-	lStr: string;
-begin
-        if not lRead then begin
-           lIniFile.WriteString('BOOL',lIdent,Bool2Char(lValue));
-           exit;
-        end;
-	lStr := lIniFile.ReadString('BOOL',lIdent, '');
-	if length(lStr) > 0 then
-		lValue := Char2Bool(lStr[1]);
-end; //IniBool
-
-procedure IniStr(lRead: boolean; lIniFile: TCustomIniFile; lIdent: string; var lValue: string);
-//read or write a string value to the initialization file
-begin
-  if not lRead then begin
-    lIniFile.WriteString('STR',lIdent,lValue);
-    exit;
-  end;
-	lValue := lIniFile.ReadString('STR',lIdent, '');
-end; //IniStr
-
-function IniFile(lRead: boolean; lFilename: string; var lPrefs: TPrefs): boolean;
-//Read or write initialization variables to disk
-var
-  lIniFile: TMemIniFile;
-begin
-  result := false;
-  if (lRead) and (not Fileexists(lFilename)) then
-        exit;
-  {$IFDEF UNIX}  //Uses BaseUnix;
-  if (lRead) and (fpAccess (lFilename,R_OK)<>0) then begin//ensure user has read-access to prefs file...
-    msg('Unable to load preferences: no write access for '+lFilename);
-    exit;
-  end;
-  {$ENDIF}
-  if (lRead) then begin
-     Filemode := 0; //Readonly
-     msg('reading preferences file '+lFilename);
-  end else
-      Filemode := 2; //Read-Write
-
-  //lIniFile := TIniFile.Create(lFilename);
-  lIniFile := TMemIniFile.Create(lFilename);
-
-  IniBool(lRead,lIniFile,'DebugMode',lPrefs.DebugMode);
-  IniBool(lRead,lIniFile,'UntestedFeatures',lPrefs.UntestedFeatures);
-  IniBool(lRead,lIniFile,'UINT16toFLOAT32',lPrefs.UINT16toFLOAT32);
-  IniBool(lRead,lIniFile,'Verbose',lPrefs.Verbose);
-  IniBool(lRead,lIniFile,'Anonymize',lPrefs.Anonymize);
-  IniBool(lRead,lIniFile, 'AnonymizeSourceDICOM',lPrefs.AnonymizeSourceDICOM);
-  IniBool(lRead,lIniFile,'AppendAcqSeries',lPrefs.AppendAcqSeries);
-  IniBool(lRead,lIniFile,'AppendDate',lPrefs.AppendDate);
-  IniBool(lRead,lIniFile,'AppendFilename',lPrefs.AppendFilename);
-  IniBool(lRead,lIniFile,'AppendPatientName',lPrefs.AppendPatientName);
-  IniBool(lRead,lIniFile,'AppendProtocolName',lPrefs.AppendProtocolName);
-  IniBool(lRead,lIniFile,'AutoCrop',lPrefs.AutoCrop);
-  IniBool(lRead,lIniFile,'CollapseFolders',lPrefs.CollapseFolders);
-  IniBool(lRead,lIniFile,'createoutputfolder',lPrefs.createoutputfolder);
-  IniBool(lRead,lIniFile,'CustomRename',lPrefs.CustomRename);
-  IniBool(lRead,lIniFile,'enablereorient',lPrefs.enablereorient);
-  IniBool(lRead,lIniFile,'OrthoFlipXDim',lPrefs.OrthoFlipXDim);
-  IniBool(lRead,lIniFile,'EveryFile',lPrefs.EveryFile);
-  IniBool(lRead,lIniFile,'fourD',lPrefs.fourD);
-  IniBool(lRead,lIniFile,'Gzip',lPrefs.Gzip);
-  IniBool(lRead,lIniFile,'ManualNIfTIConv',lPrefs.ManualNIfTIConv);
-  IniBool(lRead,lIniFile,'PhilipsPrecise',lPrefs.PhilipsPrecise);
-  IniBool(lRead,lIniFile,'RecursiveUseNameAppend',lPrefs.RecursiveUseNameAppend);
-  IniBool(lRead,lIniFile,'SingleNIIFile',lPrefs.SingleNIIFile);
-  IniBool(lRead,lIniFile,'SPM2',lPrefs.SPM2);
-  IniBool(lRead,lIniFile,'Stack3DImagesWithSameAcqNum',lPrefs.Stack3DImagesWithSameAcqNum);
-  IniBool(lRead,lIniFile,'Swizzle4D',lPrefs.Swizzle4D);
-  IniBool(lRead,lIniFile,'UseGE_0021_104F',lPrefs.UseGE_0021_104F);
-
-  IniInt(lRead,lIniFile,'BeginClip',lPrefs.BeginClip);
-  IniInt(lRead,lIniFile,'LastClip',lPrefs.LastClip);
-  IniInt(lRead,lIniFile,'usePigz',lPrefs.usePigz);
-  {$ifdef CPU64}
-  IniInt(lRead,lIniFile,'maxGb64bit',lPrefs.maxGb64bit);
-  {$ENDIF}
-	IniInt(lRead,lIniFile,'MaxReorientMatrix',lPrefs.MaxReorientMatrix);
-	IniInt(lRead,lIniFile,'MinReorientMatrix',lPrefs.MinReorientMatrix);
-	IniInt(lRead,lIniFile,'RecursiveFolderDepth',lPrefs.RecursiveFolderDepth);
-	IniInt(lRead,lIniFile,'OutDirMode',lPrefs.OutDirMode);
-
-  IniInt(lRead,lIniFile,'SiemensDTIUse0019If00181020atleast',lPrefs.SiemensDTIUse0019If00181020atleast);
-  IniInt(lRead,lIniFile,'SiemensDTINoAngulationCorrectionIf00181020atleast',lPrefs.SiemensDTINoAngulationCorrectionIf00181020atleast);
-  IniInt(lRead,lIniFile,'SiemensDTIStackIf00181020atleast',lPrefs.SiemensDTIStackIf00181020atleast);
-  lPrefs.BackupDir := lIniFile.ReadString('STR','BackupDir',lPrefs.BackupDir);
-  IniStr(lRead,lIniFile,'OutDir',lPrefs.OutDir);
-  if (lPrefs.OutDirMode < kOutDirModeInput) or (lPrefs.OutDirMode > kOutDirModeOutDir) then
-           lPrefs.OutDirMode := kOutDirModeOutDir;
-  if (lRead) and (not(DirExists(lPrefs.OutDir))) then
-     lPrefs.OutDir := UserDataFolder;
-  if not lRead then
-    lIniFile.UpdateFile;
-  lIniFile.Free;
-  if (lRead) then
-     Filemode := 2; //Read-write
-end;
-
-end.
-
-
-
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/readint.dfm b/dcm2nii_prePARRECDTI/readint.dfm
deleted file mode 100755
index 6dc59bd..0000000
Binary files a/dcm2nii_prePARRECDTI/readint.dfm and /dev/null differ
diff --git a/dcm2nii_prePARRECDTI/readint.lrs b/dcm2nii_prePARRECDTI/readint.lrs
deleted file mode 100755
index feb8ee0..0000000
--- a/dcm2nii_prePARRECDTI/readint.lrs
+++ /dev/null
@@ -1,14 +0,0 @@
-LazarusResources.Add('TReadIntForm','FORMDATA',[
-  'TPF0'#12'TReadIntForm'#11'ReadIntForm'#4'Left'#3'2'#1#6'Height'#2'P'#3'Top'#3
-  +'*'#2#5'Width'#3#213#1#18'HorzScrollBar.Page'#3#212#1#18'VertScrollBar.Page'
-  +#2'O'#13'ActiveControl'#7#11'ReadIntEdit'#11'BorderStyle'#7#8'bsDialog'#7'Ca'
-  +'ption'#6#16'Integer required'#11'Font.Height'#2#245#9'Font.Name'#6#13'MS Sa'
-  +'ns Serif'#8'OnCreate'#7#10'FormCreate'#8'Position'#7#14'poScreenCenter'#0#6
-  +'TLabel'#12'ReadIntLabel'#4'Left'#2#16#6'Height'#2#14#3'Top'#2#12#5'Width'#3
-  +'P'#1#9'Alignment'#7#14'taRightJustify'#8'AutoSize'#8#7'Caption'#6#14'Enter '
-  +'a number'#5'Color'#7#6'clNone'#11'ParentColor'#8#0#0#9'TSpinEdit'#11'ReadIn'
-  +'tEdit'#4'Left'#3'h'#1#6'Height'#2#22#3'Top'#2#12#5'Width'#2']'#8'MaxValue'#2
-  +#0#8'TabOrder'#2#0#0#0#7'TButton'#5'OKBtn'#4'Left'#3'p'#1#6'Height'#2#25#3'T'
-  +'op'#2','#5'Width'#2'K'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#2'OK'
-  +#7'OnClick'#7#10'OKBtnClick'#8'TabOrder'#2#1#0#0#0
-]);
diff --git a/dcm2nii_prePARRECDTI/readint.pas b/dcm2nii_prePARRECDTI/readint.pas
deleted file mode 100755
index c6e1391..0000000
--- a/dcm2nii_prePARRECDTI/readint.pas
+++ /dev/null
@@ -1,54 +0,0 @@
-unit readint;
-
-interface
-
-uses
-{$IFDEF FPC}LResources,Buttons,{$ENDIF}
-{$IFNDEF UNIX}  Windows,{$ENDIF}
-   Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
-  StdCtrls, Spin,define_types;
-
-type
-  TReadIntForm = class(TForm)
-    ReadIntEdit: TSpinEdit;
-    ReadIntLabel: TLabel;
-    OKBtn: TButton;
-    function GetInt(lStr: string; lMin,lDefault,lMax: integer): integer;
-    procedure OKBtnClick(Sender: TObject);
-	  private
-	{ Private declarations }
-  public
-
-	{ Public declarations }
-  end;
-const
-	gPassname: kStr20='NIH';
-var
-  ReadIntForm: TReadIntForm;
-
-implementation
-
-{$IFNDEF FPC}{$R *.DFM}   {$ENDIF}
-
- function TReadIntForm.GetInt(lStr: string; lMin,lDefault,lMax: integer): integer;
- begin
-	  //result := lDefault;
-      ReadIntLabel.caption := lStr+' ['+inttostr(lMin)+'..'+inttostr(lMax)+']';
-	  ReadIntEdit.MinValue := lMin;
-	  ReadIntEdit.MaxValue := lMax;
-	  ReadIntEdit.Value := lDefault;
-	  ReadIntForm.ShowModal;
-	  result :=  ReadIntEdit.Value;
- end;
-
-procedure TReadIntForm.OKBtnClick(Sender: TObject);
-begin
-	  ReadIntForm.ModalResult := mrOK;
-end;
-
-{$IFDEF FPC}
-initialization
-  {$I readint.lrs}
- {$ENDIF}
-
-end.
diff --git a/dcm2nii_prePARRECDTI/sortdicom.pas b/dcm2nii_prePARRECDTI/sortdicom.pas
deleted file mode 100755
index 61c0b14..0000000
--- a/dcm2nii_prePARRECDTI/sortdicom.pas
+++ /dev/null
@@ -1,499 +0,0 @@
-unit sortdicom;
-{$H+}
-{$Include ..\common\isgui.inc}
-
-interface
-uses
-  SysUtils,define_types,classes,dicom,dicomtypes,convert,dicomfast,prefs,userdir;
-
-
-function LoadFileList (var lInFilename, lOutDirname: string; var lPrefs: TPrefs):boolean;
-function LoadParamFileList (var lInFilename, lOutDirname: string; var lPrefs: TPrefs; lParamNum: integer): boolean;
-
-implementation
-
-uses dialogsx;
-
-function IsRepeat (var lD1,lD2: DicomData) : boolean;
-begin
-     if (lD1.ImageNum = lD2.ImageNum) and
-        (lD1.AcquNum = lD2.AcquNum) and
-        (lD1.SeriesNum = lD2.SeriesNum) and
-        (lD1.DateTime = lD2.DateTime)  then
-          result := true
-     else
-         result := false;
-end;
-
-function IsEqualDT (lI1,lI2: TDateTime; var l1LessThan2: boolean): boolean;
-begin
-     if lI1 = lI2 then
-        result := true
-     else
-         result := false;
-     if lI1 < lI2 then
-        l1LessThan2 := true
-     else
-         l1LessThan2 := false;
-end;
-
-function IsEqual (lI1,lI2: integer; var l1LessThan2: boolean): boolean;
-begin
-     if lI1 = lI2 then
-        result := true
-     else
-         result := false;
-     if lI1 < lI2 then
-        l1LessThan2 := true
-     else
-         l1LessThan2 := false;
-end;
-
-function D1LessThanD2 (var lD1,lD2: DicomData) : boolean;
-begin
-     if not IsEqualDT (lD1.DateTime, lD2.DateTime, result) then
-        exit;
-     //only get here if lD1.DataTime = lD2.DateTime
-     if not IsEqual (lD1.SeriesNum, lD2.SeriesNum, result) then
-        exit;
-     //only get here if lD1.SeriesNum = lD2.SeriesNum
-     if not IsEqual (lD1.AcquNum, lD2.AcquNum, result) then
-        exit;
-     //only get here if lD1.AcquNum = lD2.AcquNum
-     if not IsEqual (lD1.ImageNum, lD2.ImageNum, result) then
-        exit;
-     //only get here if lD1.ImageNum = lD2.ImageNum
-end;
-
-
-
-procedure ReportError (l,i: integer; var lDICOMra: TDICOMrap);
-begin
-//Msg('Error: these files have the same index '+ lDICOMra^[lPositionRA^[l]].Filename+' = '+lDICOMra^[lPositionRA^[i]].Filename);
-              Msg('Error: these files have the same index '+ DICOMstr(l,lDICOMra)+' = '+DICOMstr(i,lDICOMra));
-end;
-
-procedure ShellSortDCM (var Items: integer; var lDICOMra: TDICOMrap; var lRepeatedValues: boolean);
-//Shell sort /- see 'Numerical Recipes in C' for similar sorts: less memory intensive than recursive quicksort
-label
-     555;
-const
-     tiny = 1.0e-5;
-     aln2i = 1.442695022;
-var
-   inputItems,n,t, nn, m, lognb2, l, k, j, i: longint;
- lPositionRA,lPositionRA2: LongintP;
- lTempDICOMra: TDICOMrap;
-
-begin
-     inputItems := Items;
-     lRepeatedValues := false;
-     if Items < 2 then
-        exit;
-     Getmem(lPositionRA,Items*sizeof(LongInt));
-     for i := 1 to items do
-         lPositionRA^[i] := i;
-     n := (Items );
-     lognb2 := trunc(ln(n) * aln2i + tiny);
-     m := Items;
-     for nn := 1 to lognb2 do
-         begin
-              m := m div 2;
-              k := Items - m;
-              for j := 1 to k do begin
-                  i := j;
-                  555:
-                  l := i + m;
-
-                  if //identical refs
-                    {(lDICOMra^[lPositionRA^[l]].ImageNum = lDICOMra^[lPositionRA^[i]].ImageNum) and
-                    (lDICOMra^[lPositionRA^[l]].AcquNum = lDICOMra^[lPositionRA^[i]].AcquNum) and
-                    (lDICOMra^[lPositionRA^[l]].SeriesNum = lDICOMra^[lPositionRA^[i]].SeriesNum) and
-                    (lDICOMra^[lPositionRA^[l]].DateTime = lDICOMra^[lPositionRA^[i]].DateTime)}
-IsRepeat(lDICOMra^[lPositionRA^[l]], lDICOMra^[lPositionRA^[i]])
-                    then begin
-                      lRepeatedValues := true;
-                      ReportError(lPositionRA^[l],lPositionRA^[i],lDICOMra);
-                      //Msg('Error: these files have the same index '+ lDICOMra^[lPositionRA^[l]].Filename+' = '+lDICOMra^[lPositionRA^[i]].Filename);
-
-                  end else
-                  if D1LessThanD2 (lDICOMra^[lPositionRA^[l]],lDICOMra^[lPositionRA^[i]])
-{                    (lDICOMra^[lPositionRA^[l]].DateTime < lDICOMra^[lPositionRA^[i]].DateTime) or
-                   ((lDICOMra^[lPositionRA^[l]].DateTime = lDICOMra^[lPositionRA^[i]].DateTime) and (lDICOMra^[lPositionRA^[l]].SeriesNum < lDICOMra^[lPositionRA^[i]].SeriesNum)) or
-                   ((lDICOMra^[lPositionRA^[l]].DateTime = lDICOMra^[lPositionRA^[i]].DateTime) and (lDICOMra^[lPositionRA^[l]].SeriesNum = lDICOMra^[lPositionRA^[i]].SeriesNum) and (lDICOMra^[lPositionRA^[l]].AcquNum < lDICOMra^[lPositionRA^[i]].AcquNum)) or
-                   ((lDICOMra^[lPositionRA^[l]].DateTime = lDICOMra^[lPositionRA^[i]].DateTime) and (lDICOMra^[lPositionRA^[l]].SeriesNum = lDICOMra^[lPositionRA^[i]].SeriesNum) and (lDICOMra^[lPositionRA^[l]].AcquNum = lDICOMra^[lPositionRA^[i]].AcquNum) and  (lDICOMra^[lPositionRA^[l]].ImageNum < lDICOMra^[lPositionRA^[i]].ImageNum))
- }
-                   then begin
-                     //swap values for i and l
-                     t := lPositionRA^[i];
-                     lPositionRA^[i] := lPositionRA^[l];
-                     lPositionRA^[l] := t;
-                     i := i - m;
-                     if (i >= 1) then
-                        goto 555;
-                  end
-              end
-         end;
-         //next - remove any repeated values
-         if lRepeatedValues then begin
-            Getmem(lPositionRA2,Items*sizeof(LongInt));
-            k := 1;
-            lPositionRA2^[1] := lPositionRA^[1];
-            for i := 2 to Items do begin
-                  if not IsRepeat(lDICOMra^[lPositionRA^[i-1]],lDICOMra^[lPositionRA^[i]]) then begin
-                     inc(k);
-                     lPositionRA2^[k] := lPositionRA^[i];
-                  end;
-            end;
-            Items := k;
-            for i := 1 to Items do
-                lPositionRA^[i] := lPositionRA2^[i];
-            Freemem(lPositionRA2);
-         end;
-
-
-          //Next - created sorted lists based on pointers...
-          //... a  quicker way would be to return the pointers, but this is still pretty fast...
-          //... a lower memory solution would be to swap items inside lDICOMra
-          Getmem(lTempDICOMra,InputItems*sizeof({TDICOM}DicomData));
-          for I := 1 to InputItems do
-              lTempDICOMra^[I] := lDICOMra^[I];
-          if InputItems <> Items then begin
-             Freemem(lDICOMra);
-             Getmem(lDICOMra,Items*sizeof({TDICOM}DicomData));
-          end;
-          for I := 1 to Items do
-              lDICOMra^[I] := lTempDICOMra^[lPositionRA^[I]];
-          Freemem(lTempDICOMra);
-         //finally, cleanup
-         Freemem(lPositionRA);
-end; //ShellSortDCM
-
-const
-kTolerance = 0.0000095; //assume files are from different series if their orientation differs by more than this value
-//unfortunately, GE images have a rounding error, so nearby slices often have different values...
-
-function SameIDSeriesAcqXYZ( var ld1,ld2: DicomData{TDICOM};var lPrefs: TPrefs): boolean;
-var
-   lStack: boolean;
-   lI: integer;
-begin
-     result := false;
-     if (ld1.file4D)  then //if previous file is a 4D image, we should convert it separately
-        exit;
-     if (ld1.DateTime = ld2.DateTime) and(ld1.SeriesNum = ld2.SeriesNum) {and (ld1.acquNum = ld2.acquNum)}
-       and(ld1.XYZdim[1] = ld2.XYZdim[1]) and(ld1.XYZdim[2] = ld2.XYZdim[2]) and(ld1.XYZdim[3] = ld2.XYZdim[3]) then
-        //result := true
-     else
-         exit;
-     lStack := lPrefs.Stack3DImagesWithSameAcqNum;
-     if (ld1.Vers0018_1020 >= lPrefs.SiemensDTIStackIf00181020atleast) then
-        lStack := true; //recent Siemens scanners will have different NEx saved as different images and different directions saved as different images
-     if   (not lStack) and (ld1.acquNum <> ld2.acquNum) then begin
-         msg('Images not stacked because acquisition number changes. If you want to stack these images set Stack3DImagesWithSameAcqNum=1 in your ini file.');
-         exit;
-     end;
-     (*if (ld1.PatientIDInt = ld2.PatientIDInt) and(ld1.SeriesNum = ld2.SeriesNum) and (ld1.acquNum = ld2.acquNum)
-       and(ld1.XYZdim[1] = ld2.XYZdim[1]) and(ld1.XYZdim[2] = ld2.XYZdim[2]) and(ld1.XYZdim[3] = ld2.XYZdim[3]) then
-        //result := true
-     else
-         exit;*)
-     for lI := 1 to 6 do begin
-         //if (ld1.orient[lI] <> ld2.orient[lI]) then
-         if abs (ld1.orient[lI] - ld2.orient[lI]) > kTolerance then
-            exit;
-     end;
-     (*if (ld1.IntenScale <> ld2.IntenScale) or (ld1.IntenIntercept <> ld2.IntenIntercept)  then begin//if previous file is a 4D image, we should convert it separately
-        msg('Warning: unable to stack images because intensity scaling varies. Names: '+ld1.Filename+' '+ld2.filename+' Slopes: '+floattostr(ld1.IntenScale)+' '+floattostr(ld2.IntenScale)+' Intercepts: '+floattostr(ld1.IntenIntercept)+' '+floattostr(ld2.IntenIntercept));
-        exit;
-     end;  *)
-     result := true;
-end;
-
-function ProcessSingleFolderDCM (var lInFilename: string; var lStringList : TStringList): boolean;
-//assumes lStringList is already created and will be freed later...
-var
-  lSearchRec: TSearchRec;
-  lPrev,lFilename,lFilepath,lMaskExt,lExt: string;
-begin
-     result := false;
-     lFilePath := ExtractFileDirWithPathDelim(lInFilename);
-     lExt := string(StrUpper(PChar(ExtractFileExt(lInFilename)))); //.head
-     if (lExt = '.PAR') or (lExt = '.REC') {or (lExt = '.HDR') or (lExt = '.IMG')or (lExt = '.HEAD') or (lExt = '.BRIK')} then
-     {$IFDEF Unix}
-        lMaskExt := '*'+ExtractFileExt(lInFilename) //Linux is case sensitive, these extensions are used by paired files: only read one of pair
-     else
-         lMaskExt := '*';
-     {$ELSE}
-        lMaskExt := '*'+lExt //these extensions are used by paired files: only read one of pair
-     else
-         lMaskExt := '*.*';
-     {$ENDIF}
-    //Msg('yyy'+lFilePath+'::'+lMaskExt);
-    lPrev := '.';
-    Filemode := 0; //readonly
-     if FindFirst(lFilePath{+PathDelim}+lMaskExt, faAnyFile-faSysFile-faDirectory, lSearchRec) = 0 then begin
-        repeat
-              if (length(lSearchRec.Name) < 1) then
-                 //do nothing
-                 lFilename := ''
-              {$IFDEF Unix}
-//next two lines would not recognize filename that starts with dor, e.g. \home\cr\.filename.ima
-//              else if  (lSearchRec.Name[1] = '.')  then
-//                 lFilename := ''
-              else if  (lSearchRec.Name = '..')  then
-                 lFilename := ''
-              else if  (lSearchRec.Name = '.')  then
-                 lFilename := ''
-              {$ENDIF}
-              else begin
-                   lFilename := lFilePath+lSearchRec.Name;
-
-                   if (lFilename = '') or (length (lFilename) > 255) then begin
-                      Msg('Unable to convert images where the file path and name exceed 255 characters.');
-                      Msg('Solution: put images in a folder with a shorter path.');
-                      Msg(lFilename);
-                   end else if (lFilename <> lPrev) then begin
-                       lStringList.Add(lFileName);
-                        //if lFilename = lPrev then
-                        //   msg(lPrev);
-                        lPrev := lFilename;
-                        //  msg(lFilePath+lMaskExt+' ->'+lSearchRec.Name+'z'+inttostr(lStringList.count));
-
-                   end;
-              end;
-        until (FindNext(lSearchRec) <> 0);
-     end; //some files found
-     // msg('xxxx'+inttostr( lStringList.Count));
-
-     SysUtils.FindClose(lSearchRec);
-     Filemode := 2; //readonly
-     result := true;
-end; //ProcessSingleFolder
-
-procedure ProcessRecursiveFolder (var lFolderNameIn: string; var lStringList : TStringList; lDepth: integer; var lPrefs: TPrefs);
-var
- len: integer;
- lFolderName,lNewDir,lNewName,lFilename,lExt: String;
- lSearchRec: TSearchRec;
-begin
- lFolderName := lFolderNameIn;
- if not DirExists (lFolderName) then begin
-     lFolderName := ExtractFileDir(lFolderName);
- end;
- if (length(lFolderName) > 1) and (lFolderName[length(lFolderName)] <> PathDelim) then
-    lNewDir := lFolderName+PathDelim;
- if DirExists (lNewDir) then begin
-{$IFDEF UNIX}
- if FindFirst(lNewDir+'*',faAnyFile-faSysFile,lSearchRec) = 0 then begin
-{$ELSE}
- if FindFirst(lNewDir+'*.*',faAnyFile-faSysFile,lSearchRec) = 0 then begin
-{$ENDIF}
-    lFilename := '';
-    repeat
-      lNewName := lNewDir+lSearchRec.Name;
-      if  (lSearchRec.Name <> '.') and (lSearchRec.Name <> '..') then begin
-            if DirExists(lNewName) then begin
-               if lDepth < lPrefs.RecursiveFolderDepth then begin
-                  ProcessRecursiveFolder (lNewName, lStringList, lDepth+1, lPrefs);
-               end;
-               //exit;//4/4/2008
-            end else
-                lFilename := lNewname;
-      end;
-    until (FindNext(lSearchRec) <> 0);
-   end else begin //if directory exists... else we were passed a filename
-       lFilename := lFolderName;
-   end;
-   if lFilename = '' then
-      exit;
-   //Msg('xxxx '+ lFilename);
-    if lFilename <> '' then begin
-       ProcessSingleFolderDCM (lFilename, lStringList);
-     end;
- end;
- FindClose(lSearchRec);
-
-end;
-
-
-function LoadFileListInner (var lOutDirname: string; var lPrefs: TPrefs; var lStringList : TStringList): boolean;
-var
-  lPrevDICOM,lDicomData: DicomData;
-  lDICOMra: TDICOMrap;
-  lnumEchos,lRepeatLocations,lStartImg,lValidItems, lItems,lInc: integer;
-  lError,lRepeatedValues,lHdrOK,lImgOK: boolean;
-  lFilename,lDynStr: string;
-begin
-    result := false;
-     lItems := lStringList.Count;
-     if lItems < 1 then begin
-        lStringList.Free;
-        exit;
-     end;
-     Filemode := 2;
-    Msg('Validating '+inttostr(lItems)+' potential DICOM images.');
-
-     //START ANON
-     if lPrefs.AnonymizeSourceDICOM then begin
-        for lInc := 1 to lItems do begin
-         lFilename := lStringList.Strings[lInc-1];
-         fast_read_dicom_data(lDICOMdata, 128, lFileName); //x3 faster!
-        end;
-        lStringList.Free;
-        result := true;
-        Exit;
-     end; //if anonymizeSourceDICOM
-     //END ANON
-     getmem(lDICOMra,lItems*sizeof(DicomData));
-     lValidItems := 0;
-     for lInc := 1 to lItems do begin
-         lFilename := lStringList.Strings[lInc-1];
-
-         read_dicom_data(true,false{not verbose},true,true,true,true,false, lDICOMdata, lHdrOK, lImgOK, lDynStr,lFileName,lPrefs );
-         if (lHdrOK) and (lImgOK) then begin //valid file
-            inc(lValidItems);
-            lDICOMra^[lValidItems] := lDicomData;
-         end; //if image is OK
-     end; //for each item
-     lStringList.Free;
-     if lValidItems = 0 then begin
-        Msg('Unable to find any DICOM files in the path '+lFileName);
-        freemem(lDICOMra);
-        exit;
-     end;
-     Msg('Found '+inttostr(lValidItems)+' DICOM images.');
-     ShellSortDCM (lValidItems,lDICOMra,lRepeatedValues);
-     if lRepeatedValues then begin //separate into series
-        Msg('Warning: repeated image indexes in the path '+lFileName);
-        //freemem(lDICOMra);
-        //exit;
-     end;
-     if lPrefs.DebugMode then begin
-        for lInc := 1 to lValidItems do
-            Msg( DICOMstr(lInc,lDICOMra));
-         exit;
-     end;
-     lStartImg := 1;
-     lRepeatLocations := 0;
-     lnumEchos := 1;
-     lPrevDICOM := lDICOMra^[1];
-     for lInc := 1 to lValidItems do begin
-         //msg(lDICOMra^[lInc].Filename+','+floattostr(lDICOMra^[lInc].PatientPosX)+','+floattostr(lDICOMra^[lInc].PatientPosY)+','+floattostr(lDICOMra^[lInc].PatientPosZ)  );
-
-         if  (lInc > 1) and (not SameIDSeriesAcqXYZ (lPrevDICOM ,lDICOMra^[lInc],lPrefs))   then begin
-                    //SameIDSeriesAcqXYZ2 (lPrevDICOM ,lDICOMra^[lInc]);
-                    if (lRepeatLocations < 2) and (lnumEchos > 1) then
-                       lRepeatLocations := lnumEchos;
-                    Msg('Converting '+inttostr(lInc-1)+'/'+inttostr(lValidItems)+'  volumes: '+inttostr(lRepeatLocations));
-                    result := Dicom2NII(lDICOMra,lStartImg,lInc-1,lOutDirname,lPrefs,lRepeatLocations);
-                    if not result then
-                       lError := true;
-                    lPrevDICOM := lDICOMra^[lInc];
-                    lStartImg := lInc;
-                    lRepeatLocations := 1;
-         end else if //(lDICOMra^[lInc].location = lPrevDICOM.Location) and
-              (lDICOMra^[lInc].PatientPosX = lPrevDICOM.PatientPosX) and
-             (lDICOMra^[lInc].PatientPosY = lPrevDICOM.PatientPosY) and
-             (lDICOMra^[lInc].PatientPosZ = lPrevDICOM.PatientPosZ) then begin
-             //fx(lDICOMra^[lInc].PatientPosZ , lPrevDICOM.PatientPosZ );
-             //fx(666,lRepeatLocations,lDICOMra^[lInc].location, lPrevDICOM.Location);
-             inc(lRepeatLocations);
-         end else if (lInc > 1) and ( (lDICOMra^[lInc].AcquNum) > (lDICOMra^[lInc-1].AcquNum+999)) then //we increment acquisition number by 1000 to denote new echo
-             inc(lnumEchos);
-     end; //for each valid
-     if (lRepeatLocations < 2) and (lnumEchos > 1) then
-        lRepeatLocations := lnumEchos;
-     //fx(lPrevDICOM.PatientPosX, lPrevDICOM.PatientPosY, lPrevDICOM.PatientPosZ );
-     //Msg( inttostr(lValidItems-lStartImg+1)+'  '+ inttostr(lRepeatLocations));
-     //fx(lRepeatLocations);
-     if (((lValidItems-lStartImg+1) mod lRepeatLocations) <> 0) then begin
-        Msg('*Warning: Number of images in series ('+inttostr(lValidItems-lStartImg+1)+') not divisible by number of volumes ('+inttostr(lRepeatLocations)+')');
-        Msg('*  Perhaps the selected folder only has some of the images');
-         PartialAcquisitionError;
-
-     end;
-     if (lPrevDICOM.SlicesPer3DVol > 0) and (not lPrevDICOM.file4D) and ((lValidItems div lRepeatLocations) <> lPrevDICOM.SlicesPer3DVol) then begin
-        Msg('Warning: Number of slices per volume ('+inttostr((lValidItems div lRepeatLocations))+')appears different than reported in DICOM header ('+inttostr(lPrevDICOM.SlicesPer3DVol)+')');
-        Msg('  Perhaps the selected folder only has some of the images');
-     end;
-
-     Msg('Converting '+inttostr(lValidItems)+'/'+inttostr(lValidItems)+'  volumes: '+inttostr(lRepeatLocations));
-     Dicom2NII(lDICOMra,lStartImg,lValidItems,lOutDirname,lPrefs,lRepeatLocations);
-     if lError then
-        result := false //at least one error
-     else
-       result := true;
-     freemem(lDICOMra);
-end;
-
-function ReportDICOMHeader (var lInFilename: string; var lPrefs: TPRefs): boolean;
-var
-  lDicomData: DicomData;
-  lDynStr: string;
-  lHdrOK,lImgOK: boolean;
-begin
-        read_dicom_data(false,true,false,false,false,false,false, lDICOMdata, lHdrOK, lImgOK, lDynStr,lInFileName,lPrefs );
-        result := lHdrOK;
-end;
-
-
-
-function LoadFileList (var lInFilename, lOutDirname: string; var lPrefs: TPrefs): boolean;
-var
-  lStringList : TStringList;
-begin
-     result := false;
-     if lPrefs.Verbose then begin
-        //msg(lInFilename);
-        result :=  ReportDICOMHeader (lInFilename, lPrefs);
-        exit;
-     end;
-     lStringList := TStringList.Create;
-     if (lPrefs.OutDirMode <> kOutDirModeInput) and (DirExists(lPrefs.OutDir)) then begin
-        //For kOutDirModePrompt one should set OutDir before getting here
-        //This is required so recursive searches do not repetitively prompt the user...
-        lOutDirName := lPrefs.OutDir;
-     end; //1/2010
-     if lOutDirName = '' then begin
-        if DirExists (lInFilename) then
-           lOutDirName := lInFilename
-        else
-            lOutDirName := extractfiledir(lInFilename);
-     end;
-     if not(DirExists(lOutDirName)) then
-        lOutDirName := UserDataFolder;
-     if lPrefs.CollapseFolders then begin
-         msg('Data will be exported to '+lOutDirname);
-         ProcessRecursiveFolder (lInFilename, lStringList, 0, lPrefs);
-         result := true;
-     end else
-         result :=  ProcessSingleFolderDCM (lInFilename, lStringList);
-     if (not result) or (lStringList.Count  < 1) then begin
-        Msg('+Unable to find any images in the path '+lInFilename);
-        lStringList.Free;
-     end else
-        result :=  LoadFileListInner (lOutDirName, lPrefs,lStringList)
-end;
-
-
-function LoadParamFileList (var lInFilename, lOutDirname: string; var lPrefs: TPrefs; lParamNum: integer): boolean;
-var
-  lStringList : TStringList;
-  lI : integer;
-begin
-     result := false;
-     if lPrefs.Verbose then begin
-        result :=  ReportDICOMHeader (lInFilename, lPrefs);
-        exit;
-     end;
-     lStringList := TStringList.Create;
-     lStringList.Add(lInFilename);
-     if ((lParamNum) < ParamCount) then
-        for lI := (lParamNum+1) to ParamCount do
-            lStringList.Add(Paramstr(lI));
-     msg('Only converting files explicitly specified');
-     result :=  LoadFileListInner (lOutDirName, lPrefs,lStringList)
-end;
-
-end.
\ No newline at end of file
diff --git a/dcm2nii_prePARRECDTI/untar.pas b/dcm2nii_prePARRECDTI/untar.pas
deleted file mode 100755
index f0c994b..0000000
--- a/dcm2nii_prePARRECDTI/untar.pas
+++ /dev/null
@@ -1,357 +0,0 @@
-unit untar;
-
-interface
-{$IFDEF FPC}{$mode delphi}{$H+}{$ENDIF}
-uses
-{$IFDEF FPC}
-gzio2,
-{$ELSE}
-gziod,
-{$ENDIF}
-define_types,SysUtils,LibTar,
-gzio,dialogsx,prefs,sortdicom,classes;
-
-function DeTGZ (lFilename: string; lPrefs: TPrefs): boolean;
-function isTGZ (var lStr: string): boolean;
-
-implementation
-
-function isTGZ (var lStr: string): boolean;
-var lExt: string;
-begin
-   lExt := extractfileext(lStr);
-   lExt := UpperCase(lExt);
-   if (lExt='.TGZ') then
-      Result := true
-   else
-       Result := false;
-end;
-
-(*procedure Extract (var lTarFile: string; lOverwrite: boolean); //extract target
-VAR
-  TA        : TTarArchive;
-  DirRec    : TTarDirRec;
-  lPos,lLen,lnumFilesTotal,lnumFilesCompleted,lPct: longint;
-  lStr,lOutDir,lLocalDir,lFileName,lNewDir,lTarName : String;
-begin
-            lOutDir := extractfiledir(lTarFile);
-            //next Count files for progress bar....
-            lnumFilesTotal := 0;
-            TA := TTarArchive.Create (lTarFile);
-            TRY
-               TA.Reset;
-               TA.SetFilePos (0);
-               TA.FindNext (DirRec);
-               repeat
-                     inc(lnumFilesTotal);
-               until not TA.FindNext (DirRec);
-
-            FINALLY
-                   TA.Free;
-            END;
-            //finished counting files
-            //next: extract files...
-            lnumFilesCompleted := 0;
-            //FProgress := 0;
-            TA := TTarArchive.Create (lTarFile);
-            TRY
-               TA.Reset;
-               TA.SetFilePos (0);
-               TA.FindNext (DirRec);
-            repeat
-              inc(lNumFilesCompleted);
-              {lPct := round(lNumFilesCOmpleted/lNumfilesTotal*100);
-              if lPct > FProgress then begin //only update progress bar 100 times: do not waste time updating screen
-                 FProgress := lPct;
-                 DoOnProgress;
-              end;}
-              if DirRec.Name <> '' then begin
-               //Screen.Cursor := crHourGlass;
-               TRY
-                  //filename change '/' to '\'
-                  lTarName := '';
-                  lLen := length(DirRec.name);
-                  for lPos := 1 to lLen do begin
-                     if (DirRec.Name[lPos]='/') or (DirRec.Name[lPos]='\') then
-                        lTarName := lTarName + pathdelim//'\'
-                     else if (DirRec.Name[lPos]=':') then
-
-                     else
-                         lTarName := lTarName + DirRec.Name[lPos];
-                  end;
-                  lFilename := lOutDir+pathdelim+lTarName;
-                  lLocalDir := extractfiledir(lFileName);
-                  if (DirExists(lLocalDir)) then begin
-                    {lProceed := mrYes;
-                    if Fileexists(lFileName) then begin
-                       if (gmrOverwrite = mrYes) or (gmrOverwrite = mrNo) then begin
-                          OverwriteForm.Label1.caption := 'Warning: the file '+lFilename+' already exists.';
-                          gmrOverwrite := OverwriteForm.Showmodal;
-                       end;
-                       lProceed := gmrOverwrite;
-                    end;  }
-                    if lOverwrite{(lProceed = mrYes) or (lProceed = mrYesToAll)} then begin
-                     if (length(lFilename)>2) and ((lFilename[length(lFilename)] = '\') or (lFilename[length(lFilename)] = '/'))  then begin
-                        lLen := length(lFilename)-1;
-                        lStr := lFilename;
-                        lFilename := '';
-                        for lPos := 1 to lLen do
-                            lFilename := lFilename+lStr[lPos];
-                        if not direxists(lFilename) then begin
-                           mkdir (lFilename);
-                        end;
-                     end else
-                         TA.ReadFile (lFileName);
-                    end; //proceed
-                  end else begin
-                     lLen := length(lTarName);
-                     lPos := 1;
-                     if (lLen >= 1) and ((lTarName[1] = '\') or (lTarName[1] = '/')) then inc(lPos);
-                     lNewDir := lOutDir+pathdelim;
-                     while lPos <= lLen do begin
-                          if (lTarName[lPos] = '\') or (lTarName[lPos] = '/') then begin
-                             //showmessage('creating directory:'+lNewDir);
-                             if not direxists(lNewDir) then
-                                mkdir(lNewDir);
-                             lNewDir := lNewDir + pathdelim;
-                          end else
-                           lNewDir := lNewDir + lTarName[lPos];
-                          inc(lPos);
-                     end;
-                     if (lFileName[length(lFileName)] <> '/') and(lFileName[length(lFileName)] <> '\') and  (DirExists(lLocalDir)) and (not Fileexists(lFileName)) then begin
-                        TA.ReadFile (lFileName)
-                     end;
-                  end;
-               FINALLY
-                      //Screen.Cursor := crDefault;
-               END;
-              end;
-            until not TA.FindNext (DirRec);
-            FINALLY
-                   TA.Free;
-            END;
-end;*)
-
-procedure Extract (var lTarFile: string; lOverwrite: boolean); //extract target
-VAR
-  TA        : TTarArchive;
-  DirRec    : TTarDirRec;
-  lPos,lLen,lnumFilesTotal,lnumFilesCompleted,lPct: longint;
-  lStr,lOutDir,lLocalDir,lFileName,lNewDir,lTarName : String;
-begin
-            lOutDir := extractfiledir(lTarFile);
-            //next Count files for progress bar....
-            lnumFilesTotal := 0;
-            TA := TTarArchive.Create (lTarFile);
-            TRY
-               TA.Reset;
-               TA.SetFilePos (0);
-               TA.FindNext (DirRec);
-               repeat
-                     inc(lnumFilesTotal);
-               until not TA.FindNext (DirRec);
-
-            FINALLY
-                   TA.Free;
-            END;
-            //finished counting files
-            //next: extract files...
-            lnumFilesCompleted := 0;
-            //FProgress := 0;
-            TA := TTarArchive.Create (lTarFile);
-            TRY
-               TA.Reset;
-               TA.SetFilePos (0);
-               TA.FindNext (DirRec);
-            repeat
-              inc(lNumFilesCompleted);
-              {lPct := round(lNumFilesCOmpleted/lNumfilesTotal*100);
-              if lPct > FProgress then begin //only update progress bar 100 times: do not waste time updating screen
-                 FProgress := lPct;
-                 DoOnProgress;
-              end;}
-              if DirRec.Name <> '' then begin
-               //Screen.Cursor := crHourGlass;
-               TRY
-                  //filename change '/' to '\'
-                  lTarName := '';
-                  lLen := length(DirRec.name);
-                  for lPos := 1 to lLen do begin
-                     if (DirRec.Name[lPos]='/') or (DirRec.Name[lPos]='\') then
-                        lTarName := lTarName + pathdelim//'\'
-                     else if (DirRec.Name[lPos]=':') then
-
-                     else
-                         lTarName := lTarName + DirRec.Name[lPos];
-                  end;
-                  lFilename := lOutDir+pathdelim+lTarName;
-                  lLocalDir := extractfiledir(lFileName);
-                  if (DirExists(lLocalDir)) then begin
-                    (*lProceed := mrYes;
-                    if Fileexists(lFileName) then begin
-                       if (gmrOverwrite = mrYes) or (gmrOverwrite = mrNo) then begin
-                          OverwriteForm.Label1.caption := 'Warning: the file '+lFilename+' already exists.';
-                          gmrOverwrite := OverwriteForm.Showmodal;
-                       end;
-                       lProceed := gmrOverwrite;
-                    end;  *)
-                    if lOverwrite{(lProceed = mrYes) or (lProceed = mrYesToAll)} then begin
-                     if (length(lFilename)>2) and (lFilename[length(lFilename)] = pathdelim)   then begin
-                        lLen := length(lFilename)-1;
-                        lStr := lFilename;
-                        lFilename := '';
-                        for lPos := 1 to lLen do
-                            lFilename := lFilename+lStr[lPos];
-                        if not direxists(lFilename) then begin
-                           mkdir (lFilename);
-                        end;
-                     end else
-                         TA.ReadFile (lFileName);
-                    end; //proceed
-                  end else begin
-                     lLen := length(lTarName);
-                     lPos := 1;
-                     if (lLen >= 1) and (lTarName[1] = pathdelim) then inc(lPos);
-                     lNewDir := lOutDir+pathdelim;
-                     while lPos <= lLen do begin
-                          if (lTarName[lPos] = pathdelim) then begin
-                             //showmessage('creating directory:'+lNewDir);
-                             if not direxists(lNewDir) then
-                                mkdir(lNewDir);
-                             lNewDir := lNewDir + pathdelim;
-                          end else
-                           lNewDir := lNewDir + lTarName[lPos];
-                          inc(lPos);
-                     end;
-                     if (lFileName[length(lFileName)] <> pathdelim) and  (DirExists(lLocalDir)) and (not Fileexists(lFileName)) then begin
-                        TA.ReadFile (lFileName)
-                     end;
-                  end;
-               FINALLY
-                      //Screen.Cursor := crDefault;
-               END;
-              end;
-            until not TA.FindNext (DirRec);
-            FINALLY
-                   TA.Free;
-            END;
-end;
-
-
-function FindFile (lDir: String): string;
-//lDir should include pathdelim, e.g. c:\folder\
-var lSearchRec: TSearchRec;
-begin
-  result := '';
-  if FindFirst(lDir+'*', faAnyFile-faSysFile-faDirectory, lSearchRec) = 0 then
-  	result := lDir +lSearchRec.Name;
-  FindClose(lSearchRec);
-end;
-
-procedure DeleteTreeX (const Path : string; recursive : boolean);
-var
-  Result    : integer;
-  SearchRec : TSearchRec;
-begin
-  Result := FindFirst(Path + '*', faAnyFile-faDirectory , SearchRec);
-  while Result = 0 do
-  begin
-    if not DeleteFile (Path + SearchRec.name) then
-    begin
-      FileSetAttr (Path + SearchRec.name, 0); { reset all flags }
-      DeleteFile (Path + SearchRec.name);
-    end;
-    Result := FindNext(SearchRec);
-  end;
-  FindClose(SearchRec);
-  if not recursive then
-    exit;
-  Result := FindFirst(Path + '*.*', faDirectory, SearchRec);
-  while Result = 0 do
-  begin
-    if (SearchRec.name <> '.') and (SearchRec.name <> '..') then
-    begin
-      FileSetAttr (Path + SearchRec.name, faDirectory);
-      DeleteTreeX (Path + SearchRec.name + '\', TRUE);
-      RmDir (Path + SearchRec.name);
-    end;
-    Result := FindNext(SearchRec);
-  end;
-  FindClose(SearchRec);
-end;
-
-Procedure copyfile( Const sourcefilename, targetfilename: String );
-Var 
-  S, T: TFileStream; 
-Begin 
-  S := TFileStream.Create( sourcefilename, fmOpenRead ); 
-  try 
-    T := TFileStream.Create( targetfilename, fmOpenWrite or fmCreate ); 
-    try 
-      T.CopyFrom(S, S.Size ) ; 
-    finally 
-      T.Free; 
-    end; 
-  finally 
-    S.Free; 
-  end; 
-End;
-
-procedure CopyDir ( lSourceDir,lDestDir: string);
-var
-  Result    : integer;
-  SearchRec : TSearchRec;
-  lSrc,lDest: string;
-begin
-  Result := FindFirst(lSourceDir + '*', faAnyFile-faDirectory , SearchRec);
-  while Result = 0 do  begin
-      lSrc := lSourceDir + SearchRec.name;
-      lDest := lDestDir + SearchRec.Name;
-      copyfile(lSrc,lDest);
-    Result := FindNext(SearchRec);
-  end;
-  FindClose(SearchRec);
-end;
-
-function DeTGZ (lFilename: string; lPrefs: TPrefs): boolean;
-var
- lPath,lName,lExt,lOutPath,lTempDir,lTarName,lDicomName: string;
-begin
-     result := false;
-     if (not fileexists(lFilename)) or (not isTGZ(lFilename)) then
-        exit;
-     FilenameParts (lFilename , lPath,lName,lExt);
-
-     lOutPath := lPath+lName;
-     if direxists(lOutPath) then begin
-         Msg('Unable to extract TGZ file - folder exists '+lOutpath);
-         exit;
-     end;
-     MkDir(lOutPath);
-     lTempDir := lOutPath+pathdelim+'temp';
-     MkDir(lTempDir);
-     lTarName := lTempDir+Pathdelim+lName+'.tar';
-     UnGZipFile (lFilename,lTarName); //unzip
-     Extract (lTarName,true);
-     deletefile(lTarName);
-     //now convert files to NIFTI
-     lDICOMName := FindFile(lTempDir+Pathdelim);
-     if (lDICOMName = '') or (not fileexists(lDICOMname)) then
-        exit;
-     LoadFileList(lDICOMName,lOutPath,lPrefs);
-
-     DeleteTreeX(lTempDir+Pathdelim, true);
-     RmDir(lTempDir);
-     if (lPrefs.BackupDir <> '') and (DirExists(lPrefs.BackupDir)) then begin
-        lTempDir := lPrefs.BackupDir;
-        if lTempDir[length(lTempDir)] <> pathdelim then
-           lTempDir := lTempDir + pathdelim;
-        Msg('Copying to backup folder named '+lTempDir);
-        CopyDir(lOutPath+pathdelim, lTempDir);
-        Msg('Backup completed');
-     end;
-     //Extract (lFilename,true);
-     result := true;
-end;
-
-end.
diff --git a/dcm2nii_prePARRECDTI/userdir.pas b/dcm2nii_prePARRECDTI/userdir.pas
deleted file mode 100755
index a76fc83..0000000
--- a/dcm2nii_prePARRECDTI/userdir.pas
+++ /dev/null
@@ -1,220 +0,0 @@
-unit userdir;
-//returns directory where user has read/write permissions...
-{$IFDEF FPC} {$mode delphi}{$H+} {$ENDIF}
-interface
-//returns number of cores: a computer with two dual cores will report 4
-function IniName: string;
-function DefaultsDir (lSubFolder: string): string;
-function UserDataFolder: string;  //uses shlobj
-
-implementation
-{$Include ..\common\isgui.inc}
-
-{$IFDEF UNIX}
-uses Process, SysUtils,classes,IniFiles,
-{$IFDEF GUI}dialogs;{$ELSE} dialogsx;{$ENDIF}
-
-function UserDataFolder: string;
-begin
-    result :=expandfilename('~/');
-end;
-
-
-function FileNameNoExt (lFilewExt:String): string;
-//remove final extension
-var
-   lLen,lInc: integer;
-   lName: String;
-begin
-	lName := '';
-     lLen := length(lFilewExt);
-	lInc := lLen+1;
-	 if  lLen > 0 then begin
-	   repeat
-                 dec(lInc);
-           until (lFileWExt[lInc] = '.') or (lInc = 1);
-	 end;
-     if lInc > 1 then
-        for lLen := 1 to (lInc - 1) do
-            lName := lName + lFileWExt[lLen]
-     else
-         lName := lFilewExt; //no extension
-     Result := lName;
-end;
-
-function DefaultsDir (lSubFolder: string): string;
-//for Linux: DefaultsDir is ~/appname/SubFolder/, e.g. /home/username/mricron/subfolder/
-//Note: Final character is pathdelim
-const
-     pathdelim = '/';
-var
-   lBaseDir: string;
-begin
-     lBaseDir := GetEnvironmentVariable ('HOME')+pathdelim+'.'+ FileNameNoExt(ExtractFilename(paramstr(0) ) );
-     if not DirectoryExists(lBaseDir) then begin
-        {$I-}
-        MkDir(lBaseDir);
-        if IOResult <> 0 then begin
-               //Msg('Unable to create new folder '+lBaseDir);
-        end;
-        {$I+}
-     end;
-     lBaseDir := lBaseDir+pathdelim;
-     if lSubFolder <> '' then begin
-         lBaseDir := lBaseDir + lSubFolder;
-         if not DirectoryExists(lBaseDir) then begin
-            {$I-}
-            MkDir(lBaseDir);
-            if IOResult <> 0 then begin
-               //you may want to show an error, e.g. showmessage('Unable to create new folder '+lBaseDir);
-               exit;
-            end;
-            {$I+}
-         end;
-         result := lBaseDir + pathdelim;
-     end else
-         result := lBaseDir;
-end;
-
-function IniName: string;
-begin
-  result := DefaultsDir('')+FileNameNoExt(extractfilename(paramstr(0)))+'.ini';
-end;
-{$ELSE} //If UNIX ELSE NOT Unix
-uses
-    SysUtils, Windows,shlobj;
-
-//for administrators, we can write to folder with executable, otherwise we will save data to the user's AppDataFolder
-function AppDataFolder: string;  //uses shlobj
-{$IFDEF FPC} const CSIDL_APPDATA = 26; {$ENDIF}
-var
-   Path : pchar;
-   idList : PItemIDList;
-begin
-     GetMem(Path, MAX_PATH);
-     SHGetSpecialFolderLocation(0, CSIDL_APPDATA , idList);
-     SHGetPathFromIDList(idList, Path);
-     Result := string(Path);
-     FreeMem(Path);
-end;
-
-function UserDataFolder: string;  //uses shlobj
-var
-    PIDL : PItemIDList;
-    Folder : array[0..MAX_PATH] of Char;
-    const CSIDL_PERSONAL = $0005;
-begin
-SHGetSpecialFolderLocation(0, CSIDL_PERSONAL, PIDL);
-SHGetPathFromIDList(PIDL, Folder);
-result :=Folder;
-end;
-
-(*function UserDataFolder: string;  //uses shlobj
-var
-   Path : pchar;
-   idList : PItemIDList;
-begin
-     GetMem(Path, MAX_PATH);
-     SHGetSpecialFolderLocation(0, csidl_Personal , idList);
-     SHGetPathFromIDList(idList, Path);
-     Result := string(Path);
-     FreeMem(Path);
-end;   *)
-
-function IsAdmin: Boolean;
-const
-  SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority =
-    (Value: (0, 0, 0, 0, 0, 5));
-  SECURITY_BUILTIN_DOMAIN_RID = $00000020;
-  DOMAIN_ALIAS_RID_ADMINS     = $00000220;
-var
-  hAccessToken: THandle;
-  ptgGroups: PTokenGroups;
-  dwInfoBufferSize: DWORD;
-  psidAdministrators: PSID;
-  x: Integer;
-  bSuccess: BOOL;
-  LastError: integer;
-begin
-
-  if Win32Platform <> VER_PLATFORM_WIN32_NT then
-  begin
-    Result := True;
-    exit;
-  end;
-
-  Result := False;
-  bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True,
-    hAccessToken);
-  if not bSuccess then
-  begin
-    if GetLastError = ERROR_NO_TOKEN then
-    bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY,
-      hAccessToken);
-  end;
-  if bSuccess then
-  begin
-    GetMem(ptgGroups, 1024);
-    {$IFDEF FPC}
-    bSuccess := GetTokenInformation(hAccessToken, TokenGroups,
-      ptgGroups, 1024, @dwInfoBufferSize);
-    {$ELSE}
-    bSuccess := GetTokenInformation(hAccessToken, TokenGroups,
-      ptgGroups, 1024, dwInfoBufferSize);
-    {$ENDIF}
-    LastError := GetLastError;
-    if not bSuccess then begin
-      //you may want to show an error message..
-      //showmessage(format('GetLastError %d',[LastError]));
-    end;
-    CloseHandle(hAccessToken);
-    if bSuccess then
-    begin
-      AllocateAndInitializeSid(SECURITY_NT_AUTHORITY, 2,
-        SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
-        0, 0, 0, 0, 0, 0, psidAdministrators);
-      {$R-}
-      for x := 0 to ptgGroups.GroupCount - 1 do
-        if EqualSid(psidAdministrators, ptgGroups.Groups[x].Sid) then
-        begin
-          Result := True;
-          break;
-        end;
-      {$R+}
-      FreeSid(psidAdministrators);
-    end;
-    FreeMem(ptgGroups);
-  end;
-end;
-
-
-function IniName: string;
-//only administrators can write to c:\program files -use AppDataFolder for non-Administrators
-begin
-     if isAdmin then
-        result := changefileext(paramstr(0),'.ini')
-     else
-         result := AppDataFolder+'\'+changefileext(extractfilename(paramstr(0)),'.ini');
-end;
-
-function DefaultsDir (lSubFolder: string): string;
-const
-     pathdelim = '\';
-//for Administrators: DefaultsDir is in the location of the executable, e.g. c:\program files\mricron\subfolder\
-//for non-Administrators, the AppDataFolder is returned
-//Note: Final character is pathdelim
-begin
-    result := extractfilepath(IniName);
-    if length(result) < 1 then exit;
-    if result[length(result)] <> pathdelim then
-       result := result + pathdelim;
-    if lSubFolder = '' then
-       exit;
-    result := result + lSubFolder;
-    if result[length(result)] <> pathdelim then
-       result := result + pathdelim;
-
-end;
-{$ENDIF}
-
-end.
diff --git a/dcm2nii_prePARRECDTI/windowsxp.res b/dcm2nii_prePARRECDTI/windowsxp.res
deleted file mode 100755
index 5f33505..0000000
Binary files a/dcm2nii_prePARRECDTI/windowsxp.res and /dev/null differ
diff --git a/dcm2nii_prePARRECDTI/zconf.inc b/dcm2nii_prePARRECDTI/zconf.inc
deleted file mode 100755
index 0f9e451..0000000
--- a/dcm2nii_prePARRECDTI/zconf.inc
+++ /dev/null
@@ -1,24 +0,0 @@
-{ -------------------------------------------------------------------- }
-
-{$DEFINE MAX_MATCH_IS_258}
-
-{ Compile with -DMAXSEG_64K if the alloc function cannot allocate more
-  than 64k bytes at a time (needed on systems with 16-bit int). }
-
-{- $DEFINE MAXSEG_64K}
-{$IFNDEF WIN32}
-  {$DEFINE UNALIGNED_OK}  { requires SizeOf(ush) = 2 ! }
-{$ENDIF}
-
-{$UNDEF DYNAMIC_CRC_TABLE}
-{$UNDEF FASTEST}
-{$define patch112}        { apply patch from the zlib home page }
-{ -------------------------------------------------------------------- }
-{$IFDEF FPC}
- {$DEFINE Use32}
- {$UNDEF DPMI}
- {$UNDEF MSDOS}
- {$UNDEF UNALIGNED_OK}  { requires SizeOf(ush) = 2 ! }
- {$UNDEF MAXSEG_64K}
-{$ENDIF}
-
diff --git a/drop.patch b/drop.patch
old mode 100644
new mode 100755
diff --git a/drop_patch.txt b/drop_patch.txt
old mode 100644
new mode 100755
diff --git a/mricron.lpi b/mricron.lpi
index 1c29426..be5d39e 100755
--- a/mricron.lpi
+++ b/mricron.lpi
@@ -1,4 +1,4 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <CONFIG>
   <ProjectOptions>
     <Version Value="9"/>
@@ -36,7 +36,7 @@
         <PackageName Value="LCL"/>
       </Item2>
     </RequiredPackages>
-    <Units Count="144">
+    <Units Count="141">
       <Unit0>
         <Filename Value="mricron.lpr"/>
         <IsPartOfProject Value="True"/>
@@ -53,7 +53,7 @@
         <UnitName Value="Unit1"/>
         <TopLine Value="16"/>
         <CursorPos X="7" Y="19"/>
-        <UsageCount Value="16"/>
+        <UsageCount Value="12"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
       </Unit1>
       <Unit2>
@@ -63,10 +63,10 @@
         <HasResources Value="True"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="nifti_hdr_view"/>
-        <EditorIndex Value="2"/>
+        <EditorIndex Value="6"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="677"/>
-        <CursorPos X="13" Y="678"/>
+        <TopLine Value="273"/>
+        <CursorPos X="36" Y="602"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
@@ -77,7 +77,7 @@
         <UnitName Value="define_types"/>
         <TopLine Value="410"/>
         <CursorPos X="23" Y="420"/>
-        <UsageCount Value="97"/>
+        <UsageCount Value="93"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
       </Unit3>
       <Unit4>
@@ -85,7 +85,7 @@
         <UnitName Value="GraphicsMathLibrary"/>
         <TopLine Value="326"/>
         <CursorPos X="38" Y="349"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="6"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
       </Unit4>
       <Unit5>
@@ -102,15 +102,6 @@
         <DefaultSyntaxHighlighter Value="Delphi"/>
       </Unit5>
       <Unit6>
-        <Filename Value="unit2.pas"/>
-        <ComponentName Value="Form2"/>
-        <UnitName Value="Unit2"/>
-        <TopLine Value="105"/>
-        <CursorPos X="1" Y="116"/>
-        <UsageCount Value="3"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit6>
-      <Unit7>
         <Filename Value="text.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="TextForm"/>
@@ -122,28 +113,30 @@
         <CursorPos X="1" Y="61"/>
         <UsageCount Value="200"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit7>
-      <Unit8>
+      </Unit6>
+      <Unit7>
         <Filename Value="..\lcl\include\customform.inc"/>
         <TopLine Value="315"/>
         <CursorPos X="31" Y="325"/>
-        <UsageCount Value="5"/>
+        <UsageCount Value="1"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit8>
-      <Unit9>
+      </Unit7>
+      <Unit8>
         <Filename Value="render.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="RenderForm"/>
         <HasResources Value="True"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="render"/>
+        <EditorIndex Value="2"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="18" Y="4"/>
+        <TopLine Value="362"/>
+        <CursorPos X="56" Y="370"/>
         <UsageCount Value="200"/>
+        <Loaded Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit9>
-      <Unit10>
+      </Unit8>
+      <Unit9>
         <Filename Value="ROIfilt.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="FilterROIform"/>
@@ -155,52 +148,46 @@
         <CursorPos X="58" Y="13"/>
         <UsageCount Value="200"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit10>
-      <Unit11>
+      </Unit9>
+      <Unit10>
         <Filename Value="smoothVOI.pas"/>
         <ComponentName Value="SmoothVOIForm"/>
         <HasResources Value="True"/>
         <UnitName Value="smoothVOI"/>
         <TopLine Value="382"/>
         <CursorPos X="31" Y="303"/>
-        <UsageCount Value="5"/>
+        <UsageCount Value="1"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit11>
-      <Unit12>
+      </Unit10>
+      <Unit11>
         <Filename Value="nifti_img_view.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="ImgForm"/>
         <HasResources Value="True"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="nifti_img_view"/>
+        <IsVisibleTab Value="True"/>
         <EditorIndex Value="0"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="150"/>
-        <CursorPos X="106" Y="151"/>
+        <TopLine Value="4101"/>
+        <CursorPos X="26" Y="4119"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
+        <LoadedDesigner Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit12>
-      <Unit13>
+      </Unit11>
+      <Unit12>
         <Filename Value="nifti_img.pas"/>
         <UnitName Value="nifti_img"/>
-        <EditorIndex Value="3"/>
+        <EditorIndex Value="9"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="5458"/>
-        <CursorPos X="54" Y="5472"/>
+        <TopLine Value="5298"/>
+        <CursorPos X="52" Y="5323"/>
         <UsageCount Value="100"/>
         <Loaded Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit13>
-      <Unit14>
-        <Filename Value="DISTR.PAS"/>
-        <UnitName Value="Distr"/>
-        <TopLine Value="137"/>
-        <CursorPos X="22" Y="150"/>
-        <UsageCount Value="1"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit14>
-      <Unit15>
+      </Unit12>
+      <Unit13>
         <Filename Value="cutout.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="CutoutForm"/>
@@ -211,8 +198,8 @@
         <CursorPos X="29" Y="166"/>
         <UsageCount Value="200"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit15>
-      <Unit16>
+      </Unit13>
+      <Unit14>
         <Filename Value="MultiSlice.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="MultiSliceForm"/>
@@ -224,15 +211,8 @@
         <CursorPos X="46" Y="851"/>
         <UsageCount Value="200"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit16>
-      <Unit17>
-        <Filename Value="render.lrs"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="175"/>
-        <UsageCount Value="3"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit17>
-      <Unit18>
+      </Unit14>
+      <Unit15>
         <Filename Value="autoroi.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="AutoROIForm"/>
@@ -244,28 +224,28 @@
         <CursorPos X="68" Y="537"/>
         <UsageCount Value="200"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit18>
-      <Unit19>
+      </Unit15>
+      <Unit16>
         <Filename Value="spread.pas"/>
         <ComponentName Value="SpreadForm"/>
         <HasResources Value="True"/>
         <UnitName Value="spread"/>
         <TopLine Value="83"/>
         <CursorPos X="47" Y="93"/>
-        <UsageCount Value="196"/>
+        <UsageCount Value="192"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit19>
-      <Unit20>
+      </Unit16>
+      <Unit17>
         <Filename Value="design.pas"/>
         <ComponentName Value="DesignForm"/>
         <HasResources Value="True"/>
         <UnitName Value="design"/>
         <TopLine Value="1"/>
         <CursorPos X="45" Y="167"/>
-        <UsageCount Value="196"/>
+        <UsageCount Value="192"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit20>
-      <Unit21>
+      </Unit17>
+      <Unit18>
         <Filename Value="histoform.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="HistogramForm"/>
@@ -277,112 +257,101 @@
         <CursorPos X="1" Y="76"/>
         <UsageCount Value="200"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit21>
-      <Unit22>
+      </Unit18>
+      <Unit19>
         <Filename Value="nifti_img_view.lrs"/>
         <TopLine Value="2"/>
         <CursorPos X="1" Y="1000"/>
-        <UsageCount Value="9"/>
+        <UsageCount Value="5"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit22>
-      <Unit23>
+      </Unit19>
+      <Unit20>
         <Filename Value="logistic.pas"/>
         <UnitName Value="logistic"/>
         <TopLine Value="1075"/>
         <CursorPos X="1" Y="1100"/>
-        <UsageCount Value="26"/>
+        <UsageCount Value="22"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit23>
-      <Unit24>
+      </Unit20>
+      <Unit21>
         <Filename Value="ReadInt.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="ReadIntForm"/>
         <HasResources Value="True"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="ReadInt"/>
-        <TopLine Value="53"/>
-        <CursorPos X="80" Y="68"/>
+        <EditorIndex Value="8"/>
+        <WindowIndex Value="0"/>
+        <TopLine Value="1"/>
+        <CursorPos X="77" Y="2"/>
         <UsageCount Value="200"/>
+        <Loaded Value="True"/>
+        <LoadedDesigner Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit24>
-      <Unit25>
-        <Filename Value="unit1.lfm"/>
-        <TopLine Value="1"/>
-        <CursorPos X="1" Y="1"/>
-        <UsageCount Value="3"/>
-        <DefaultSyntaxHighlighter Value="LFM"/>
-      </Unit25>
-      <Unit26>
+      </Unit21>
+      <Unit22>
         <Filename Value="..\lcl\grids.pas"/>
         <UnitName Value="Grids"/>
         <TopLine Value="5919"/>
         <CursorPos X="1" Y="5925"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="6"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit26>
-      <Unit27>
+      </Unit22>
+      <Unit23>
         <Filename Value="..\lcl\include\graphic.inc"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="104"/>
-        <UsageCount Value="5"/>
-        <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit27>
-      <Unit28>
-        <Filename Value="..\lcl\lclproc.pas"/>
-        <UnitName Value="LCLProc"/>
-        <TopLine Value="731"/>
-        <CursorPos X="1" Y="741"/>
-        <UsageCount Value="3"/>
+        <UsageCount Value="1"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit28>
-      <Unit29>
+      </Unit23>
+      <Unit24>
         <Filename Value="nifti_img_view.lfm"/>
         <TopLine Value="499"/>
         <CursorPos X="7" Y="513"/>
-        <UsageCount Value="4"/>
+        <UsageCount Value="10"/>
         <DefaultSyntaxHighlighter Value="LFM"/>
-      </Unit29>
-      <Unit30>
+      </Unit24>
+      <Unit25>
         <Filename Value="nifti_hdr.pas"/>
         <UnitName Value="nifti_hdr"/>
         <TopLine Value="172"/>
         <CursorPos X="5" Y="188"/>
-        <UsageCount Value="89"/>
+        <UsageCount Value="85"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit30>
-      <Unit31>
+      </Unit25>
+      <Unit26>
         <Filename Value="gzio2.pas"/>
         <UnitName Value="gzio2"/>
         <TopLine Value="278"/>
         <CursorPos X="11" Y="282"/>
-        <UsageCount Value="41"/>
+        <UsageCount Value="37"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit31>
-      <Unit32>
+      </Unit26>
+      <Unit27>
         <Filename Value="stat.pas"/>
         <UnitName Value="stat"/>
         <TopLine Value="318"/>
         <CursorPos X="10" Y="329"/>
-        <UsageCount Value="18"/>
+        <UsageCount Value="14"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit32>
-      <Unit33>
+      </Unit27>
+      <Unit28>
         <Filename Value="..\lcl\forms.pp"/>
         <UnitName Value="Forms"/>
         <TopLine Value="799"/>
         <CursorPos X="1" Y="806"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="6"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit33>
-      <Unit34>
+      </Unit28>
+      <Unit29>
         <Filename Value="..\lcl\lmessages.pp"/>
         <UnitName Value="LMessages"/>
         <TopLine Value="588"/>
         <CursorPos X="1" Y="600"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="6"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit34>
-      <Unit35>
+      </Unit29>
+      <Unit30>
         <Filename Value="cropedges.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="CropEdgeForm"/>
@@ -394,20 +363,21 @@
         <CursorPos X="3" Y="83"/>
         <UsageCount Value="200"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit35>
-      <Unit36>
+      </Unit30>
+      <Unit31>
         <Filename Value="bet.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="BETForm"/>
+        <HasResources Value="True"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="bet"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="86"/>
-        <CursorPos X="43" Y="99"/>
+        <TopLine Value="54"/>
+        <CursorPos X="59" Y="55"/>
         <UsageCount Value="200"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit36>
-      <Unit37>
+      </Unit31>
+      <Unit32>
         <Filename Value="mni.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="MNIForm"/>
@@ -418,86 +388,89 @@
         <CursorPos X="3" Y="53"/>
         <UsageCount Value="200"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit37>
-      <Unit38>
+      </Unit32>
+      <Unit33>
         <Filename Value="RenderThds.pas"/>
         <UnitName Value="RenderThds"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="20" Y="4"/>
-        <UsageCount Value="17"/>
+        <UsageCount Value="13"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit38>
-      <Unit39>
+      </Unit33>
+      <Unit34>
         <Filename Value="..\examples\bounty\qgraphics.pas"/>
         <UnitName Value="qgraphics"/>
         <TopLine Value="30"/>
         <CursorPos X="15" Y="38"/>
-        <UsageCount Value="5"/>
+        <UsageCount Value="1"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit39>
-      <Unit40>
+      </Unit34>
+      <Unit35>
         <Filename Value="wgraphics.pas"/>
         <UnitName Value="wgraphics"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="9"/>
-        <UsageCount Value="18"/>
+        <UsageCount Value="14"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit40>
-      <Unit41>
+      </Unit35>
+      <Unit36>
         <Filename Value="ugraphics.pas"/>
         <UnitName Value="ugraphics"/>
         <TopLine Value="1"/>
         <CursorPos X="15" Y="1"/>
-        <UsageCount Value="89"/>
+        <UsageCount Value="85"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit41>
-      <Unit42>
+      </Unit36>
+      <Unit37>
         <Filename Value="mricron_w\nifti_img.pas"/>
         <UnitName Value="nifti_img"/>
         <TopLine Value="70"/>
         <CursorPos X="26" Y="82"/>
-        <UsageCount Value="5"/>
+        <UsageCount Value="1"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit42>
-      <Unit43>
+      </Unit37>
+      <Unit38>
         <Filename Value="..\examples\bounty\fx8.pas"/>
         <UnitName Value="fx8"/>
         <TopLine Value="114"/>
         <CursorPos X="68" Y="121"/>
-        <UsageCount Value="5"/>
+        <UsageCount Value="1"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit43>
-      <Unit44>
+      </Unit38>
+      <Unit39>
         <Filename Value="fx8.pas"/>
         <UnitName Value="fx8"/>
-        <TopLine Value="119"/>
-        <CursorPos X="20" Y="146"/>
-        <UsageCount Value="17"/>
+        <EditorIndex Value="1"/>
+        <WindowIndex Value="0"/>
+        <TopLine Value="200"/>
+        <CursorPos X="20" Y="246"/>
+        <UsageCount Value="13"/>
+        <Loaded Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit44>
-      <Unit45>
+      </Unit39>
+      <Unit40>
         <Filename Value="MultiSlice.lfm"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="1"/>
-        <UsageCount Value="5"/>
+        <UsageCount Value="1"/>
         <DefaultSyntaxHighlighter Value="LFM"/>
-      </Unit45>
-      <Unit46>
+      </Unit40>
+      <Unit41>
         <Filename Value="MultiSlice.lrs"/>
         <TopLine Value="1"/>
         <CursorPos X="17" Y="3"/>
-        <UsageCount Value="12"/>
+        <UsageCount Value="8"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit46>
-      <Unit47>
+      </Unit41>
+      <Unit42>
         <Filename Value="smoothVOI.lfm"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="1"/>
-        <UsageCount Value="5"/>
+        <UsageCount Value="1"/>
         <DefaultSyntaxHighlighter Value="LFM"/>
-      </Unit47>
-      <Unit48>
+      </Unit42>
+      <Unit43>
         <Filename Value="voismooth.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="voismoothform"/>
@@ -508,100 +481,103 @@
         <CursorPos X="36" Y="391"/>
         <UsageCount Value="200"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit48>
-      <Unit49>
+      </Unit43>
+      <Unit44>
         <Filename Value="..\components\rtticontrols\rttictrls.pas"/>
         <UnitName Value="RTTICtrls"/>
         <TopLine Value="20"/>
         <CursorPos X="56" Y="37"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit49>
-      <Unit50>
+      </Unit44>
+      <Unit45>
         <Filename Value="..\lcl\fileutil.pas"/>
         <UnitName Value="FileUtil"/>
         <TopLine Value="105"/>
         <CursorPos X="35" Y="124"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit50>
-      <Unit51>
+      </Unit45>
+      <Unit46>
         <Filename Value="prefs.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="PrefForm"/>
         <HasResources Value="True"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="prefs"/>
+        <EditorIndex Value="7"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="18"/>
-        <CursorPos X="48" Y="26"/>
+        <TopLine Value="43"/>
+        <CursorPos X="46" Y="58"/>
         <UsageCount Value="200"/>
+        <Loaded Value="True"/>
+        <LoadedDesigner Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit51>
-      <Unit52>
+      </Unit46>
+      <Unit47>
         <Filename Value="dcm2nii\dcm2niigui.lrs"/>
         <TopLine Value="1"/>
         <CursorPos X="23" Y="1"/>
-        <UsageCount Value="5"/>
+        <UsageCount Value="1"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit52>
-      <Unit53>
+      </Unit47>
+      <Unit48>
         <Filename Value="C:\Documents and Settings\Chris Rorden\Application Data\Opera\Opera\profile\cache4\temporary_download\JclSysInfo.pas"/>
         <UnitName Value="JclSysInfo"/>
         <TopLine Value="29"/>
         <CursorPos X="36" Y="36"/>
-        <UsageCount Value="11"/>
+        <UsageCount Value="7"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit53>
-      <Unit54>
+      </Unit48>
+      <Unit49>
         <Filename Value="rgbroutines.pas"/>
         <UnitName Value="RGBRoutines"/>
         <TopLine Value="49"/>
         <CursorPos X="49" Y="4"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="6"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit54>
-      <Unit55>
+      </Unit49>
+      <Unit50>
         <Filename Value="junk.pas"/>
         <UnitName Value="junk"/>
         <TopLine Value="33"/>
         <CursorPos X="1" Y="46"/>
-        <UsageCount Value="7"/>
+        <UsageCount Value="3"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit55>
-      <Unit56>
+      </Unit50>
+      <Unit51>
         <Filename Value="rgbtypes.pas"/>
         <UnitName Value="RGBTypes"/>
         <TopLine Value="1"/>
         <CursorPos X="44" Y="5"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="6"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit56>
-      <Unit57>
+      </Unit51>
+      <Unit52>
         <Filename Value="usr\local\share\lazarus\components\rtticontrols\runtimetypeinfocontrols.pas"/>
         <UnitName Value="RunTimeTypeInfoControls"/>
         <TopLine Value="1"/>
         <CursorPos X="23" Y="4"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit57>
-      <Unit58>
+      </Unit52>
+      <Unit53>
         <Filename Value="usr\local\share\lazarus\tools\svn2revisioninc.pas"/>
         <UnitName Value="Svn2RevisionInc"/>
         <TopLine Value="34"/>
         <CursorPos X="40" Y="49"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit58>
-      <Unit59>
+      </Unit53>
+      <Unit54>
         <Filename Value="userdir.pas"/>
         <UnitName Value="userdir"/>
         <TopLine Value="62"/>
         <CursorPos X="10" Y="6"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="6"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit59>
-      <Unit60>
+      </Unit54>
+      <Unit55>
         <Filename Value="perisettings.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="PSForm"/>
@@ -609,10 +585,10 @@
         <UnitName Value="perisettings"/>
         <TopLine Value="81"/>
         <CursorPos X="38" Y="96"/>
-        <UsageCount Value="191"/>
+        <UsageCount Value="224"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit60>
-      <Unit61>
+      </Unit55>
+      <Unit56>
         <Filename Value="graphx.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="Graph4DForm"/>
@@ -620,249 +596,251 @@
         <UnitName Value="graphx"/>
         <TopLine Value="1043"/>
         <CursorPos X="29" Y="1055"/>
-        <UsageCount Value="191"/>
+        <UsageCount Value="224"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit61>
-      <Unit62>
+      </Unit56>
+      <Unit57>
         <Filename Value="metagraph.pas"/>
         <UnitName Value="metagraph"/>
         <TopLine Value="40"/>
         <CursorPos X="19" Y="45"/>
-        <UsageCount Value="12"/>
+        <UsageCount Value="8"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit62>
-      <Unit63>
+      </Unit57>
+      <Unit58>
         <Filename Value="render2.pas"/>
         <UnitName Value="render"/>
         <TopLine Value="1045"/>
         <CursorPos X="1" Y="1066"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit63>
-      <Unit64>
+      </Unit58>
+      <Unit59>
         <Filename Value="RenderThds2.pas"/>
         <UnitName Value="RenderThds2"/>
         <TopLine Value="308"/>
         <CursorPos X="1" Y="333"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit64>
-      <Unit65>
+      </Unit59>
+      <Unit60>
         <Filename Value="rgb\rgbgraphics.pas"/>
         <UnitName Value="RGBGraphics"/>
         <TopLine Value="241"/>
         <CursorPos X="5" Y="255"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit65>
-      <Unit66>
+      </Unit60>
+      <Unit61>
         <Filename Value="C:\Desktop\rgbgraphics.pas"/>
         <UnitName Value="RGBGraphics"/>
         <TopLine Value="151"/>
         <CursorPos X="1" Y="165"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit66>
-      <Unit67>
+      </Unit61>
+      <Unit62>
         <Filename Value="rgb\rgbtypes.pas"/>
         <UnitName Value="RGBTypes"/>
         <TopLine Value="1"/>
         <CursorPos X="131" Y="4"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit67>
-      <Unit68>
+      </Unit62>
+      <Unit63>
         <Filename Value="C:\Desktop\rgbtypes.pas"/>
         <UnitName Value="RGBTypes"/>
         <TopLine Value="45"/>
         <CursorPos X="5" Y="59"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit68>
-      <Unit69>
+      </Unit63>
+      <Unit64>
         <Filename Value="..\share\mango.txt"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="5"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="None"/>
-      </Unit69>
-      <Unit70>
+      </Unit64>
+      <Unit65>
         <Filename Value="..\share\tempura.txt"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="3"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="None"/>
-      </Unit70>
-      <Unit71>
+      </Unit65>
+      <Unit66>
         <Filename Value="rgb\rgbroutines.pas"/>
         <UnitName Value="RGBRoutines"/>
         <TopLine Value="26"/>
         <CursorPos X="1" Y="46"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit71>
-      <Unit72>
+      </Unit66>
+      <Unit67>
         <Filename Value="..\share\mexico.txt"/>
         <TopLine Value="20"/>
         <CursorPos X="4" Y="23"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="None"/>
-      </Unit72>
-      <Unit73>
+      </Unit67>
+      <Unit68>
         <Filename Value="usr\local\share\lazarus\components\rtticontrols\rttictrls.pas"/>
         <UnitName Value="RTTICtrls"/>
         <TopLine Value="18"/>
         <CursorPos X="31" Y="33"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit73>
-      <Unit74>
+      </Unit68>
+      <Unit69>
         <Filename Value="usr\local\share\lazarus\lcl\fileutil.pas"/>
         <UnitName Value="FileUtil"/>
         <TopLine Value="4"/>
         <CursorPos X="43" Y="10"/>
-        <UsageCount Value="7"/>
+        <UsageCount Value="3"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit74>
-      <Unit75>
+      </Unit69>
+      <Unit70>
         <Filename Value="cpucount.pas"/>
         <UnitName Value="cpucount"/>
         <TopLine Value="55"/>
         <CursorPos X="24" Y="5"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit75>
-      <Unit76>
+      </Unit70>
+      <Unit71>
         <Filename Value="..\share\xview.pas"/>
         <UnitName Value="nifti_img_view"/>
         <TopLine Value="3594"/>
         <CursorPos X="20" Y="3617"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit76>
-      <Unit77>
+      </Unit71>
+      <Unit72>
         <Filename Value="..\share\xhdr.pas"/>
         <UnitName Value="nifti_hdr"/>
         <TopLine Value="160"/>
         <CursorPos X="1" Y="174"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit77>
-      <Unit78>
+      </Unit72>
+      <Unit73>
         <Filename Value="rgb\rgbcarbonroutines.pas"/>
         <UnitName Value="RGBCarbonRoutines"/>
         <TopLine Value="9"/>
         <CursorPos X="36" Y="23"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit78>
-      <Unit79>
+      </Unit73>
+      <Unit74>
         <Filename Value="rgb\rgbgtkroutines.pas"/>
         <UnitName Value="RGBGTKRoutines"/>
         <TopLine Value="28"/>
         <CursorPos X="4" Y="36"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="4"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit79>
-      <Unit80>
+      </Unit74>
+      <Unit75>
         <Filename Value="rgb\lazrgbgraphics.pas"/>
         <UnitName Value="LazRGBGraphics"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="1"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit80>
-      <Unit81>
+      </Unit75>
+      <Unit76>
         <Filename Value="rgb\rgbutils.pas"/>
         <UnitName Value="RGBUtils"/>
         <TopLine Value="20"/>
         <CursorPos X="66" Y="47"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit81>
-      <Unit82>
+      </Unit76>
+      <Unit77>
         <Filename Value="rgbw\RGBGraphics.pas"/>
         <UnitName Value="RGBGraphics"/>
         <TopLine Value="172"/>
         <CursorPos X="29" Y="186"/>
-        <UsageCount Value="6"/>
+        <UsageCount Value="2"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit82>
-      <Unit83>
+      </Unit77>
+      <Unit78>
         <Filename Value="irender.pas"/>
         <UnitName Value="render"/>
         <TopLine Value="1310"/>
         <CursorPos X="1" Y="1328"/>
-        <UsageCount Value="11"/>
+        <UsageCount Value="7"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit83>
-      <Unit84>
+      </Unit78>
+      <Unit79>
         <Filename Value="render_composite.pas"/>
         <UnitName Value="render_composite"/>
+        <EditorIndex Value="3"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="7"/>
-        <CursorPos X="23" Y="21"/>
-        <UsageCount Value="12"/>
+        <TopLine Value="824"/>
+        <CursorPos X="66" Y="838"/>
+        <UsageCount Value="11"/>
+        <Loaded Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit84>
-      <Unit85>
+      </Unit79>
+      <Unit80>
         <Filename Value="periplot.pas"/>
         <UnitName Value="periplot"/>
         <TopLine Value="532"/>
         <CursorPos X="20" Y="544"/>
-        <UsageCount Value="13"/>
+        <UsageCount Value="9"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit85>
-      <Unit86>
+      </Unit80>
+      <Unit81>
         <Filename Value="periutils.pas"/>
         <UnitName Value="periutils"/>
         <TopLine Value="159"/>
         <CursorPos X="1" Y="183"/>
-        <UsageCount Value="15"/>
+        <UsageCount Value="11"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit86>
-      <Unit87>
+      </Unit81>
+      <Unit82>
         <Filename Value="reslice.pas"/>
         <UnitName Value="reslice"/>
         <TopLine Value="202"/>
         <CursorPos X="46" Y="211"/>
-        <UsageCount Value="11"/>
+        <UsageCount Value="7"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit87>
-      <Unit88>
+      </Unit82>
+      <Unit83>
         <Filename Value="fpmath\fmath.pas"/>
         <UnitName Value="fmath"/>
         <TopLine Value="761"/>
         <CursorPos X="30" Y="852"/>
-        <UsageCount Value="7"/>
+        <UsageCount Value="3"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit88>
-      <Unit89>
+      </Unit83>
+      <Unit84>
         <Filename Value="hrf.pas"/>
         <UnitName Value="hrf"/>
         <TopLine Value="135"/>
         <CursorPos X="29" Y="151"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="4"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit89>
-      <Unit90>
+      </Unit84>
+      <Unit85>
         <Filename Value="fpmath\regmult.pas"/>
         <UnitName Value="regmult"/>
         <TopLine Value="119"/>
         <CursorPos X="1" Y="115"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="4"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit90>
-      <Unit91>
+      </Unit85>
+      <Unit86>
         <Filename Value="clustering.pas"/>
         <UnitName Value="clustering"/>
         <WindowIndex Value="0"/>
         <TopLine Value="161"/>
         <CursorPos X="6" Y="183"/>
-        <UsageCount Value="15"/>
+        <UsageCount Value="11"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit91>
-      <Unit92>
+      </Unit86>
+      <Unit87>
         <Filename Value="ReadFloat.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="ReadFloatForm"/>
@@ -870,224 +848,223 @@
         <UnitName Value="ReadFloat"/>
         <TopLine Value="38"/>
         <CursorPos X="38" Y="53"/>
-        <UsageCount Value="152"/>
+        <UsageCount Value="195"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit92>
-      <Unit93>
+      </Unit87>
+      <Unit88>
         <Filename Value="npm\gzio2.pas"/>
         <UnitName Value="gzio2"/>
         <TopLine Value="756"/>
         <CursorPos X="13" Y="797"/>
-        <UsageCount Value="7"/>
+        <UsageCount Value="3"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit93>
-      <Unit94>
+      </Unit88>
+      <Unit89>
         <Filename Value="common\nifti_hdr.pas"/>
         <UnitName Value="nifti_hdr"/>
         <WindowIndex Value="0"/>
         <TopLine Value="22"/>
         <CursorPos X="1" Y="36"/>
-        <UsageCount Value="30"/>
+        <UsageCount Value="26"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit94>
-      <Unit95>
+      </Unit89>
+      <Unit90>
         <Filename Value="common\define_types.pas"/>
         <UnitName Value="define_types"/>
+        <EditorIndex Value="5"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="1310"/>
-        <CursorPos X="1" Y="1317"/>
-        <UsageCount Value="47"/>
+        <TopLine Value="205"/>
+        <CursorPos X="36" Y="147"/>
+        <UsageCount Value="68"/>
+        <Loaded Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit95>
-      <Unit96>
+      </Unit90>
+      <Unit91>
         <Filename Value="common\cpucount.pas"/>
         <UnitName Value="cpucount"/>
         <TopLine Value="1"/>
         <CursorPos X="46" Y="12"/>
-        <UsageCount Value="9"/>
+        <UsageCount Value="5"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit96>
-      <Unit97>
+      </Unit91>
+      <Unit92>
         <Filename Value="common\userdir.pas"/>
         <UnitName Value="userdir"/>
         <TopLine Value="35"/>
         <CursorPos X="14" Y="43"/>
-        <UsageCount Value="16"/>
+        <UsageCount Value="12"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit97>
-      <Unit98>
+      </Unit92>
+      <Unit93>
         <Filename Value="C:\lazarus\lcl\dialogs.pp"/>
         <UnitName Value="Dialogs"/>
         <TopLine Value="466"/>
         <CursorPos X="43" Y="481"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="4"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit98>
-      <Unit99>
+      </Unit93>
+      <Unit94>
         <Filename Value="dicomhdr.pas"/>
         <UnitName Value="dicomhdr"/>
         <TopLine Value="464"/>
         <CursorPos X="50" Y="493"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="4"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit99>
-      <Unit100>
+      </Unit94>
+      <Unit95>
         <Filename Value="rgbnew\rgbgtkroutines.pas"/>
         <UnitName Value="RGBGTKRoutines"/>
         <TopLine Value="67"/>
         <CursorPos X="1" Y="79"/>
-        <UsageCount Value="7"/>
+        <UsageCount Value="3"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit100>
-      <Unit101>
+      </Unit95>
+      <Unit96>
         <Filename Value="render.lfm"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="1"/>
-        <UsageCount Value="7"/>
+        <UsageCount Value="3"/>
         <DefaultSyntaxHighlighter Value="LFM"/>
-      </Unit101>
-      <Unit102>
+      </Unit96>
+      <Unit97>
         <Filename Value="common\GraphicsMathLibrary.pas"/>
         <UnitName Value="GraphicsMathLibrary"/>
         <TopLine Value="45"/>
         <CursorPos X="15" Y="60"/>
-        <UsageCount Value="13"/>
+        <UsageCount Value="9"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit102>
-      <Unit103>
+      </Unit97>
+      <Unit98>
         <Filename Value="reslice_img.pas"/>
         <UnitName Value="reslice_img"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="46" Y="6"/>
-        <UsageCount Value="16"/>
+        <UsageCount Value="12"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit103>
-      <Unit104>
+      </Unit98>
+      <Unit99>
         <Filename Value="ortho_reorient.pas"/>
         <UnitName Value="ortho_reorient"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="81" Y="6"/>
-        <UsageCount Value="16"/>
+        <UsageCount Value="12"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit104>
-      <Unit105>
+      </Unit99>
+      <Unit100>
         <Filename Value="common\dicomhdr.pas"/>
         <UnitName Value="dicomhdr"/>
-        <IsVisibleTab Value="True"/>
-        <EditorIndex Value="5"/>
         <WindowIndex Value="0"/>
         <TopLine Value="6"/>
-        <CursorPos X="1" Y="10"/>
-        <UsageCount Value="15"/>
-        <Loaded Value="True"/>
+        <CursorPos X="26" Y="11"/>
+        <UsageCount Value="31"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit105>
-      <Unit106>
+      </Unit100>
+      <Unit101>
         <Filename Value="C:\lazarus\components\cgi\cgimodules.pas"/>
         <UnitName Value="cgiModules"/>
         <TopLine Value="1"/>
         <CursorPos X="53" Y="19"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="4"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit106>
-      <Unit107>
+      </Unit101>
+      <Unit102>
         <Filename Value="reslice_fsl.pas"/>
         <UnitName Value="reslice_fsl"/>
         <TopLine Value="25"/>
         <CursorPos X="27" Y="38"/>
-        <UsageCount Value="18"/>
+        <UsageCount Value="14"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit107>
-      <Unit108>
+      </Unit102>
+      <Unit103>
         <Filename Value="..\mricrogl\sourcex\mricrogl.lpr"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="1"/>
-        <UsageCount Value="7"/>
+        <UsageCount Value="3"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit108>
-      <Unit109>
+      </Unit103>
+      <Unit104>
         <Filename Value="..\gl\Source\Base\OpenGL1x.pas"/>
         <UnitName Value="OpenGL1x"/>
         <TopLine Value="5131"/>
         <CursorPos X="10" Y="5142"/>
-        <UsageCount Value="7"/>
+        <UsageCount Value="3"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit109>
-      <Unit110>
+      </Unit104>
+      <Unit105>
         <Filename Value="imgutil.pas"/>
         <UnitName Value="imgutil"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="87" Y="11"/>
-        <UsageCount Value="12"/>
+        <UsageCount Value="8"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit110>
-      <Unit111>
+      </Unit105>
+      <Unit106>
         <Filename Value="batch.pas"/>
         <UnitName Value="batch"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="98" Y="2"/>
-        <UsageCount Value="17"/>
+        <UsageCount Value="13"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit111>
-      <Unit112>
+      </Unit106>
+      <Unit107>
         <Filename Value="fdr.pas"/>
         <UnitName Value="fdr"/>
         <TopLine Value="1"/>
         <CursorPos X="51" Y="73"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="4"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit112>
-      <Unit113>
+      </Unit107>
+      <Unit108>
         <Filename Value="statclustertable.pas"/>
         <UnitName Value="statclustertable"/>
         <WindowIndex Value="0"/>
         <TopLine Value="103"/>
         <CursorPos X="83" Y="113"/>
-        <UsageCount Value="15"/>
+        <UsageCount Value="11"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit113>
-      <Unit114>
+      </Unit108>
+      <Unit109>
         <Filename Value="reorient.pas"/>
         <UnitName Value="reorient"/>
         <TopLine Value="54"/>
         <CursorPos X="35" Y="56"/>
-        <UsageCount Value="13"/>
+        <UsageCount Value="9"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit114>
-      <Unit115>
+      </Unit109>
+      <Unit110>
         <Filename Value="C:\lazarus\fpc\2.2.2\source\rtl\objpas\sysutils\osutilsh.inc"/>
         <TopLine Value="31"/>
         <CursorPos X="10" Y="38"/>
-        <UsageCount Value="11"/>
+        <UsageCount Value="7"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit115>
-      <Unit116>
+      </Unit110>
+      <Unit111>
         <Filename Value="npm\part.pas"/>
         <UnitName Value="part"/>
         <TopLine Value="1"/>
         <CursorPos X="11" Y="31"/>
-        <UsageCount Value="11"/>
+        <UsageCount Value="7"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit116>
-      <Unit117>
+      </Unit111>
+      <Unit112>
         <Filename Value="graphx.lrs"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="153"/>
-        <UsageCount Value="9"/>
+        <UsageCount Value="5"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit117>
-      <Unit118>
+      </Unit112>
+      <Unit113>
         <Filename Value="landmarks.lfm"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="1"/>
-        <UsageCount Value="9"/>
+        <UsageCount Value="5"/>
         <DefaultSyntaxHighlighter Value="LFM"/>
-      </Unit118>
-      <Unit119>
+      </Unit113>
+      <Unit114>
         <Filename Value="landmarks.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="AnatForm"/>
@@ -1096,341 +1073,357 @@
         <UnitName Value="landmarks"/>
         <TopLine Value="166"/>
         <CursorPos X="50" Y="175"/>
-        <UsageCount Value="98"/>
+        <UsageCount Value="141"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit119>
-      <Unit120>
+      </Unit114>
+      <Unit115>
         <Filename Value="prefs.lfm"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="1"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="4"/>
         <DefaultSyntaxHighlighter Value="LFM"/>
-      </Unit120>
-      <Unit121>
+      </Unit115>
+      <Unit116>
         <Filename Value="C:\usr\share\fpcsrc\rtl\unix\baseunix.pp"/>
         <UnitName Value="BaseUnix"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="1"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="4"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit121>
-      <Unit122>
+      </Unit116>
+      <Unit117>
         <Filename Value="common\isgui.inc"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="10" Y="1"/>
-        <UsageCount Value="22"/>
+        <UsageCount Value="18"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit122>
-      <Unit123>
+      </Unit117>
+      <Unit118>
         <Filename Value="batchstatselect.pas"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="batchstatselect"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="43" Y="6"/>
-        <UsageCount Value="87"/>
+        <UsageCount Value="130"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit123>
-      <Unit124>
+      </Unit118>
+      <Unit119>
         <Filename Value="yokeipc.pas"/>
         <UnitName Value="yokeipc"/>
         <TopLine Value="3"/>
         <CursorPos X="29" Y="105"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="4"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit124>
-      <Unit125>
+      </Unit119>
+      <Unit120>
         <Filename Value="yokesharemem.pas"/>
         <UnitName Value="yokesharemem"/>
         <WindowIndex Value="0"/>
         <TopLine Value="53"/>
         <CursorPos X="14" Y="58"/>
-        <UsageCount Value="13"/>
+        <UsageCount Value="9"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit125>
-      <Unit126>
+      </Unit120>
+      <Unit121>
         <Filename Value="winmemmap.pas"/>
         <UnitName Value="winmemmap"/>
         <TopLine Value="2"/>
         <CursorPos X="56" Y="9"/>
-        <UsageCount Value="9"/>
+        <UsageCount Value="5"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit126>
-      <Unit127>
+      </Unit121>
+      <Unit122>
         <Filename Value="C:\usr\lib\lazarus\lcl\interfaces\gtk\interfaces.pp"/>
         <UnitName Value="Interfaces"/>
         <TopLine Value="1"/>
         <CursorPos X="17" Y="13"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="4"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit127>
-      <Unit128>
+      </Unit122>
+      <Unit123>
         <Filename Value="C:\lazarus\fpc\2.4.1\source\rtl\win\wininc\defines.inc"/>
         <TopLine Value="1"/>
         <CursorPos X="64" Y="301"/>
-        <UsageCount Value="9"/>
+        <UsageCount Value="5"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit128>
-      <Unit129>
+      </Unit123>
+      <Unit124>
         <Filename Value="common\dialogsx.pas"/>
         <UnitName Value="dialogsx"/>
         <WindowIndex Value="0"/>
         <TopLine Value="118"/>
         <CursorPos X="38" Y="119"/>
-        <UsageCount Value="18"/>
+        <UsageCount Value="14"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit129>
-      <Unit130>
+      </Unit124>
+      <Unit125>
         <Filename Value="..\mricrogl\source\common\nifti_hdr.pas"/>
         <UnitName Value="nifti_hdr"/>
         <TopLine Value="47"/>
         <CursorPos X="26" Y="49"/>
-        <UsageCount Value="8"/>
+        <UsageCount Value="4"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit130>
-      <Unit131>
+      </Unit125>
+      <Unit126>
         <Filename Value="C:\usr\share\fpcsrc\packages\fcl-process\src\process.pp"/>
         <UnitName Value="process"/>
         <TopLine Value="25"/>
         <CursorPos X="70" Y="25"/>
-        <UsageCount Value="9"/>
+        <UsageCount Value="5"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit131>
-      <Unit132>
+      </Unit126>
+      <Unit127>
         <Filename Value="otsu.pas"/>
         <UnitName Value="otsu"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="9" Y="6"/>
-        <UsageCount Value="18"/>
+        <UsageCount Value="14"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit132>
-      <Unit133>
+      </Unit127>
+      <Unit128>
         <Filename Value="C:\Developer\lazarus\lcl\interfaces\carbon\carbonobject.inc"/>
         <WindowIndex Value="0"/>
         <TopLine Value="206"/>
         <CursorPos X="1" Y="228"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="6"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit133>
-      <Unit134>
+      </Unit128>
+      <Unit129>
         <Filename Value="otsu2.pas"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="otsu2"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="13" Y="98"/>
-        <UsageCount Value="64"/>
+        <UsageCount Value="107"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit134>
-      <Unit135>
+      </Unit129>
+      <Unit130>
         <Filename Value="CarbonOpenDoc.pas"/>
         <UnitName Value="CarbonOpenDoc"/>
         <WindowIndex Value="0"/>
         <TopLine Value="33"/>
         <CursorPos X="42" Y="38"/>
-        <UsageCount Value="11"/>
+        <UsageCount Value="7"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit135>
-      <Unit136>
+      </Unit130>
+      <Unit131>
         <Filename Value="fastsmooth.pas"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="fastsmooth"/>
         <WindowIndex Value="0"/>
         <TopLine Value="16"/>
         <CursorPos X="17" Y="28"/>
-        <UsageCount Value="64"/>
+        <UsageCount Value="107"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit136>
-      <Unit137>
+      </Unit131>
+      <Unit132>
         <Filename Value="common\gzio2.pas"/>
         <UnitName Value="gzio2"/>
-        <EditorIndex Value="6"/>
         <WindowIndex Value="0"/>
         <TopLine Value="111"/>
         <CursorPos X="81" Y="119"/>
-        <UsageCount Value="24"/>
-        <Loaded Value="True"/>
+        <UsageCount Value="40"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit137>
-      <Unit138>
+      </Unit132>
+      <Unit133>
         <Filename Value="otsuml.pas"/>
         <UnitName Value="otsuml"/>
         <WindowIndex Value="0"/>
         <TopLine Value="275"/>
         <CursorPos X="11" Y="15"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="6"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit138>
-      <Unit139>
+      </Unit133>
+      <Unit134>
         <Filename Value="nii_label.pas"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="nii_label"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="1" Y="34"/>
-        <UsageCount Value="45"/>
+        <UsageCount Value="88"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit139>
-      <Unit140>
+      </Unit134>
+      <Unit135>
         <Filename Value="crop.pas"/>
         <UnitName Value="crop"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="113" Y="9"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="6"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit140>
-      <Unit141>
+      </Unit135>
+      <Unit136>
         <Filename Value="..\raycast\gzio2.pas"/>
         <UnitName Value="gzio2"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1175"/>
         <CursorPos X="1" Y="1180"/>
-        <UsageCount Value="10"/>
+        <UsageCount Value="6"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit141>
-      <Unit142>
+      </Unit136>
+      <Unit137>
         <Filename Value="common\nifti_types.pas"/>
         <UnitName Value="nifti_types"/>
-        <EditorIndex Value="4"/>
+        <EditorIndex Value="10"/>
         <WindowIndex Value="0"/>
         <TopLine Value="109"/>
         <CursorPos X="3" Y="118"/>
-        <UsageCount Value="18"/>
+        <UsageCount Value="40"/>
         <Loaded Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit142>
-      <Unit143>
+      </Unit137>
+      <Unit138>
         <Filename Value="common\nifti_foreign.pas"/>
         <UnitName Value="nifti_foreign"/>
-        <EditorIndex Value="1"/>
+        <EditorIndex Value="4"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="815"/>
-        <CursorPos X="29" Y="826"/>
-        <UsageCount Value="18"/>
+        <TopLine Value="885"/>
+        <CursorPos X="7" Y="886"/>
+        <UsageCount Value="40"/>
         <Loaded Value="True"/>
         <DefaultSyntaxHighlighter Value="Delphi"/>
-      </Unit143>
+      </Unit138>
+      <Unit139>
+        <Filename Value="..\..\..\..\..\usr\local\share\fpcsrc\rtl\objpas\sysutils\sysstrh.inc"/>
+        <WindowIndex Value="0"/>
+        <TopLine Value="157"/>
+        <CursorPos X="38" Y="170"/>
+        <UsageCount Value="25"/>
+      </Unit139>
+      <Unit140>
+        <Filename Value="..\..\..\..\..\Developer\lazarus\lcl\interfaces\carbon\carbonobject.inc"/>
+        <WindowIndex Value="0"/>
+        <TopLine Value="668"/>
+        <CursorPos X="42" Y="678"/>
+        <UsageCount Value="25"/>
+      </Unit140>
     </Units>
-    <JumpHistory Count="29" HistoryIndex="28">
+    <JumpHistory Count="30" HistoryIndex="29">
       <Position1>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="799" Column="27" TopLine="672"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="1128" Column="43" TopLine="1102"/>
       </Position1>
       <Position2>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="620" Column="63" TopLine="613"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="4110" Column="27" TopLine="4096"/>
       </Position2>
       <Position3>
-        <Filename Value="common\nifti_types.pas"/>
-        <Caret Line="5" Column="85" TopLine="1"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="240" Column="28" TopLine="225"/>
       </Position3>
       <Position4>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="806" Column="59" TopLine="793"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="830" Column="28" TopLine="809"/>
       </Position4>
       <Position5>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="805" Column="32" TopLine="796"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="841" Column="37" TopLine="816"/>
       </Position5>
       <Position6>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="805" Column="32" TopLine="796"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="872" Column="20" TopLine="846"/>
       </Position6>
       <Position7>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="617" Column="5" TopLine="602"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="1029" Column="28" TopLine="1003"/>
       </Position7>
       <Position8>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="609" Column="3" TopLine="602"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="1374" Column="26" TopLine="1348"/>
       </Position8>
       <Position9>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="4" Column="117" TopLine="1"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="1377" Column="22" TopLine="1351"/>
       </Position9>
       <Position10>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="623" Column="95" TopLine="610"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="1380" Column="21" TopLine="1354"/>
       </Position10>
       <Position11>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="709" Column="32" TopLine="701"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="1385" Column="36" TopLine="1359"/>
       </Position11>
       <Position12>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="721" Column="18" TopLine="701"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="1441" Column="25" TopLine="1416"/>
       </Position12>
       <Position13>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="719" Column="76" TopLine="708"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="1453" Column="27" TopLine="1427"/>
       </Position13>
       <Position14>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="33" Column="126" TopLine="30"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="1492" Column="23" TopLine="1466"/>
       </Position14>
       <Position15>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="624" Column="7" TopLine="604"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="1620" Column="22" TopLine="1594"/>
       </Position15>
       <Position16>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="132" Column="109" TopLine="127"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="4110" Column="31" TopLine="4084"/>
       </Position16>
       <Position17>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="3" Column="109" TopLine="1"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="4500" Column="20" TopLine="4475"/>
       </Position17>
       <Position18>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="634" Column="31" TopLine="622"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="4670" Column="27" TopLine="4644"/>
       </Position18>
       <Position19>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="638" Column="20" TopLine="622"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="4690" Column="20" TopLine="4665"/>
       </Position19>
       <Position20>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="824" Column="35" TopLine="816"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="4884" Column="20" TopLine="4858"/>
       </Position20>
       <Position21>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="826" Column="40" TopLine="810"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="5051" Column="28" TopLine="5025"/>
       </Position21>
       <Position22>
-        <Filename Value="common\nifti_foreign.pas"/>
-        <Caret Line="656" Column="10" TopLine="641"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="240" Column="28" TopLine="225"/>
       </Position22>
       <Position23>
-        <Filename Value="nifti_hdr_view.pas"/>
-        <Caret Line="8" Column="87" TopLine="1"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="830" Column="28" TopLine="804"/>
       </Position23>
       <Position24>
-        <Filename Value="nifti_img.pas"/>
-        <Caret Line="88" Column="118" TopLine="87"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="841" Column="37" TopLine="816"/>
       </Position24>
       <Position25>
-        <Filename Value="nifti_img.pas"/>
-        <Caret Line="5060" Column="37" TopLine="5043"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="1029" Column="28" TopLine="1003"/>
       </Position25>
       <Position26>
-        <Filename Value="nifti_img.pas"/>
-        <Caret Line="5102" Column="18" TopLine="5087"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="1392" Column="35" TopLine="1384"/>
       </Position26>
       <Position27>
-        <Filename Value="nifti_img.pas"/>
-        <Caret Line="5472" Column="54" TopLine="5458"/>
+        <Filename Value="nifti_hdr_view.pas"/>
+        <Caret Line="171" Column="31" TopLine="156"/>
       </Position27>
       <Position28>
-        <Filename Value="common\dicomhdr.pas"/>
-        <Caret Line="7" Column="76" TopLine="1"/>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="1392" Column="35" TopLine="1384"/>
       </Position28>
       <Position29>
-        <Filename Value="common\dicomhdr.pas"/>
-        <Caret Line="36" Column="47" TopLine="26"/>
+        <Filename Value="nifti_img.pas"/>
+        <Caret Line="2" Column="121" TopLine="1"/>
       </Position29>
+      <Position30>
+        <Filename Value="nifti_img_view.pas"/>
+        <Caret Line="111" Column="31" TopLine="107"/>
+      </Position30>
     </JumpHistory>
   </ProjectOptions>
   <CompilerOptions>
@@ -1486,4 +1479,5 @@
       </Item2>
     </Exceptions>
   </Debugging>
+  <EditorMacros Count="0"/>
 </CONFIG>
\ No newline at end of file
diff --git a/nifti_img.pas b/nifti_img.pas
index b52819b..641d697 100755
--- a/nifti_img.pas
+++ b/nifti_img.pas
@@ -1747,6 +1747,10 @@ procedure ScaleBMP2Draw (var InvZoomShl10,lX, lY, lPanel: integer; lImage: TImag
 begin
 	 //lScaleShl10 := ComputeInvZoomShl10(SelectedImageNum,lImage);
 	 //ImgForm.StatusLabel.Caption := inttostr(InvZoomShl10);
+  {$IFNDEF Darwin}
+     please check if next line required for this OS! 8/8/2014
+  {$ENDIF}
+  lX := lX -1;
          if (gBGImg.FlipSag) and (lPanel = 2) then
 		lX := ((lImage.Width-lX) * InvZoomShl10) shr 10
   	 else if (lX < 1) then
@@ -2279,7 +2283,7 @@ begin
   end else begin
       ImgForm.SaveDialog1.Filter := 'NIfTI compressed (.nii.gz)|*.nii.gz|NIfTI (.nii)|*.nii|NIfTI (.hdr/.img)|*.hdr|Volume of Interest(.voi)|*.voi|MRIcro (.roi)|*.roi';
       ImgForm.SaveDialog1.Filename := changefileext(ImgForm.SaveDialog1.Filename,'.nii.gz');//10/10/06
-      ImgForm.SaveDialog1.FilterIndex:= gBGImg.SaveImgFilter+1; //+1since default added
+      ImgForm.SaveDialog1.FilterIndex:= gBGImg.SaveImgFilter; //8/8/2014 removed +1 new behavior with new lazarus 1.2+1since default added
       ImgForm.SaveDialog1.DefaultExt := '.nii.gz';
   end;
   if lDefFilename <> '' then
@@ -2290,9 +2294,12 @@ begin
   else
       gBGImg.SaveImgFilter :=  ImgForm.SaveDialog1.FilterIndex;
   lFileName := ImgForm.SaveDialog1.Filename;
-  {$IFDEF FPC}
+  {$IFDEF FPC} //recent versions of Lazarus (1.2) do handle this, but will put .gz not .nii.gz
   if ImgForm.SaveDialog1.filterIndex > 0 then begin
-     lExt := GetExtensionFromFilterAtIndex(ImgForm.SaveDialog1.Filter,ImgForm.SaveDialog1.FilterIndex+1);
+     {$IFNDEF Darwin}
+         check next line in each OS
+     {$ENDIF}
+     lExt := GetExtensionFromFilterAtIndex(ImgForm.SaveDialog1.Filter,ImgForm.SaveDialog1.FilterIndex); //8/8/2014 check on OSX 10.4
      lFilename := ChangeFileExtX(lFilename,lExt);
    end;
   {$ENDIF}
@@ -3104,6 +3111,7 @@ var
   lINSz,  lDstWidM,x,y: integer;
     lXRatio,lYRatio: single;
   begin
+
   lInBuff:= ByteP(lRGBBuff);
   yP:=0;
   lXRatio := lInXYRatio;
@@ -3111,11 +3119,15 @@ var
   lInSz := lSrcWid *lSrcHt;
   lOutwid := round(lSrcWid*lXRatio);
   lOutHt := round(lSrcHt*lYRatio);
+  //
+  //showmessage(inttostr(lOutwid)+' '+inttostr(lOutHt)+'  '+floattostr(lXRatio)+'  '+floattostr(lYRatio));
+  if (lOutwid < 2) or (lOutHt < 2) then exit;
   xP2:=((lSrcWid-1)shl 15)div (lOutWid -1 );
   yP2:=((lSrcHt-1)shl 15)div (lOutHt -1);
   lPos := 1;
   lDstWidM := lOutWid - 1;
   getmem(lBuff, lOutHt*lOutWid*4);
+
   lInSz := lInSz * 4; //32bytesperpixel
   for y:=0 to lOutHt-1 do begin
       xP:= 0;
@@ -4978,6 +4990,15 @@ begin
         lBGImg.MaxChar[3] := 'S';
         exit;
      end;
+     if (not gBGImg.OrthoReslice) then begin
+         lBGImg.MinChar[1] := ' ';
+        lBGImg.MaxChar[1] := ' ';
+        lBGImg.MinChar[2] := ' ';
+        lBGImg.MaxChar[2] := ' ';
+        lBGImg.MinChar[3] := ' ';
+        lBGImg.MaxChar[3] := ' ';
+        exit;
+     end;
      //there are two approaches to solve this - a more elegant solution is to find the nearest orthogonal aligment
      //the method below is simpler, but might give unusual results if the field of view in one dimension is much larger than another
      lMatrix := lHdr.Mat;
@@ -5027,6 +5048,7 @@ begin
                  lBGImg.MaxChar[lDim] := '?';
          end;
      end;//for each dim
+
 end;  //proc FindAlignment
 
 function DICOMMirrorImgBuffer(var lHdr: TMRIcroHdr ): boolean;
diff --git a/nifti_img_view.lfm b/nifti_img_view.lfm
index bc22885..e468a17 100755
--- a/nifti_img_view.lfm
+++ b/nifti_img_view.lfm
@@ -1,7 +1,7 @@
 object ImgForm: TImgForm
-  Left = 347
+  Left = 465
   Height = 469
-  Top = 156
+  Top = 114
   Width = 1025
   ActiveControl = ControlPanel
   AllowDropFiles = True
@@ -20,7 +20,7 @@ object ImgForm: TImgForm
   OnResize = FormResize
   OnShow = FormShow
   Position = poScreenCenter
-  LCLVersion = '1.0.12.0'
+  LCLVersion = '1.2.4.0'
   object ControlPanel: TPanel
     Left = 0
     Height = 40
@@ -37,25 +37,25 @@ object ImgForm: TImgForm
     OnDblClick = ControlPanelDblClick
     object LabelX: TLabel
       Left = 6
-      Height = 18
+      Height = 17
       Top = 12
-      Width = 9
+      Width = 8
       Caption = 'X'
       ParentColor = False
     end
     object LabelY: TLabel
       Left = 81
-      Height = 18
+      Height = 17
       Top = 12
-      Width = 9
+      Width = 8
       Caption = 'Y'
       ParentColor = False
     end
     object LabelZ: TLabel
       Left = 153
-      Height = 18
+      Height = 17
       Top = 12
-      Width = 8
+      Width = 7
       Caption = 'Z'
       ParentColor = False
     end
@@ -117,7 +117,6 @@ object ImgForm: TImgForm
         FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00D96B6D06D24F5057FFFF
         FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00
       }
-      NumGlyphs = 0
       OnMouseDown = HideROIBtnMouseDown
       OnMouseUp = HideROIBtnMouseUp
     end
@@ -202,7 +201,6 @@ object ImgForm: TImgForm
         FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00
       }
       GroupIndex = 321
-      NumGlyphs = 0
       OnClick = XBarBtnClick
       OnMouseDown = XBarBtnMouseDown
       ShowHint = True
@@ -295,7 +293,6 @@ object ImgForm: TImgForm
           56BE8C6363D79D7171E7986E6EE5865F5FD4775353B75B3C3C720B07071BFFFF
           FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00
         }
-        NumGlyphs = 0
         OnClick = AutoContrastBtnClick
       end
       object LutFromZeroBtn: TSpeedButton
@@ -362,7 +359,6 @@ object ImgForm: TImgForm
           808080808080808080808080808080808080
         }
         GroupIndex = 194
-        NumGlyphs = 0
         OnClick = LutFromZeroBtnClick
       end
       object ColorBarBtn: TSpeedButton
@@ -402,7 +398,6 @@ object ImgForm: TImgForm
           8080808080808080808080808080808080808080808080808080808080808080
           8080808080808080808080808080808080808080808080808080
         }
-        NumGlyphs = 0
         OnMouseDown = ColorBarBtnMouseDown
       end
       object LayerDrop: TComboBox
@@ -597,7 +592,6 @@ object ImgForm: TImgForm
           FF0000FF0000FF0000FF0000FF0000FF0000FF0000FF0000FF00
         }
         GroupIndex = 44
-        NumGlyphs = 0
         OnClick = PenBtnClick
       end
       object ClosedPenBtn: TSpeedButton
@@ -666,7 +660,6 @@ object ImgForm: TImgForm
           FF0000FF0000FF0000FF0000FF0000FF0000FF0000FF0000FF00
         }
         GroupIndex = 44
-        NumGlyphs = 0
         OnClick = PenBtnClick
       end
       object FillBtn: TSpeedButton
@@ -750,7 +743,6 @@ object ImgForm: TImgForm
           FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00
         }
         GroupIndex = 44
-        NumGlyphs = 0
         OnClick = PenBtnClick
       end
       object EllipseBtn: TSpeedButton
@@ -831,7 +823,6 @@ object ImgForm: TImgForm
           FF4835005E844C0017D00300F54A0000FF480000FF480000FF48
         }
         GroupIndex = 44
-        NumGlyphs = 0
         OnClick = PenBtnClick
       end
       object Fill3DBtn: TSpeedButton
@@ -915,7 +906,6 @@ object ImgForm: TImgForm
           FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00
         }
         GroupIndex = 44
-        NumGlyphs = 0
         OnClick = Fill3DBtnClick
       end
     end
@@ -932,9 +922,9 @@ object ImgForm: TImgForm
     TabOrder = 1
     object StatusLabel: TLabel
       Left = 2
-      Height = 18
+      Height = 17
       Top = 2
-      Width = 134
+      Width = 133
       Caption = '  No Images Loaded  '
       ParentColor = False
     end
@@ -965,11 +955,11 @@ object ImgForm: TImgForm
       Height = 411
       Top = 0
       Width = 1025
-      HorzScrollBar.Page = 1025
-      VertScrollBar.Page = 411
+      HorzScrollBar.Page = 775
+      VertScrollBar.Page = 250
       Align = alClient
-      ClientHeight = 411
-      ClientWidth = 1025
+      ClientHeight = 396
+      ClientWidth = 1010
       Constraints.MinWidth = 5
       Color = clBlack
       ParentColor = False
diff --git a/nifti_img_view.lrs b/nifti_img_view.lrs
index f308432..2bc4b73 100755
--- a/nifti_img_view.lrs
+++ b/nifti_img_view.lrs
@@ -1,75 +1,75 @@
 { This is an automatically generated lazarus resource file }
 
 LazarusResources.Add('TImgForm','FORMDATA',[
-  'TPF0'#8'TImgForm'#7'ImgForm'#4'Left'#3'['#1#6'Height'#3#213#1#3'Top'#3#156#0
-  +#5'Width'#3#1#4#13'ActiveControl'#7#12'ControlPanel'#14'AllowDropFiles'#9#7
-  +'Caption'#6#7'MRIcroN'#12'ClientHeight'#3#213#1#11'ClientWidth'#3#1#4#8'Dock'
-  +'Site'#9#9'Font.Name'#6#13'MS Sans Serif'#4'Menu'#7#9'MainMenu1'#7'OnClose'#7
-  +#9'FormClose'#8'OnCreate'#7#10'FormCreate'#9'OnDestroy'#7#11'FormDestroy'#11
-  +'OnDropFiles'#7#13'FormDropFiles'#9'OnKeyDown'#7#11'FormKeyDown'#10'OnKeyPre'
-  +'ss'#7#12'FormKeyPress'#8'OnResize'#7#10'FormResize'#6'OnShow'#7#8'FormShow'
-  +#8'Position'#7#14'poScreenCenter'#10'LCLVersion'#6#8'1.0.12.0'#0#6'TPanel'#12
-  +'ControlPanel'#4'Left'#2#0#6'Height'#2'('#3'Top'#2#0#5'Width'#3#1#4#5'Align'
-  +#7#5'alTop'#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#2'('#11'ClientWidth'
-  +#3#1#4#11'ParentColor'#8#14'ParentShowHint'#8#8'ShowHint'#9#8'TabOrder'#2#0
-  +#10'OnDblClick'#7#20'ControlPanelDblClick'#0#6'TLabel'#6'LabelX'#4'Left'#2#6
-  +#6'Height'#2#18#3'Top'#2#12#5'Width'#2#9#7'Caption'#6#1'X'#11'ParentColor'#8
-  +#0#0#6'TLabel'#6'LabelY'#4'Left'#2'Q'#6'Height'#2#18#3'Top'#2#12#5'Width'#2#9
-  +#7'Caption'#6#1'Y'#11'ParentColor'#8#0#0#6'TLabel'#6'LabelZ'#4'Left'#3#153#0
-  +#6'Height'#2#18#3'Top'#2#12#5'Width'#2#8#7'Caption'#6#1'Z'#11'ParentColor'#8
-  +#0#0#12'TSpeedButton'#10'HideROIBtn'#4'Left'#3'('#3#6'Height'#2#30#4'Hint'#6
-  +#30'Briefly hide VOIs and Overlays'#3'Top'#2#4#5'Width'#2#30#10'Glyph.Data'
-  +#10':'#6#0#0'6'#6#0#0'BM6'#6#0#0#0#0#0#0'6'#0#0#0'('#0#0#0#16#0#0#0#24#0#0#0
-  +#1#0' '#0#0#0#0#0#0#6#0#0'd'#0#0#0'd'#0#0#0#0#0#0#0#0#0#0#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#198#28#29'%'#192#0#0#127#140'EE'#188#183#11#11#203
-  +#191#1#1#232#192#0#0#246#192#0#0#219#192#0#0#189#192#0#0#160#192#0#0#130#192
-  +#0#0'c'#192#0#0'$'#255#255#255#0#255#255#255#0#214']_<'#207'AB'#196#200'%%'
-  +#255#141'LL'#255'G'#160#160#255'B'#168#168#255#152'55'#255#192#0#0#255#192#0
-  +#0#255#192#0#0#255#192#0#0#255#154'33'#255#192#0#0#255#192#0#0#255#192#0#0
-  +#197#222#130#132#134#216'fg'#253#209'JK'#255#202'-.'#255#171'00'#255'0'#191
-  +#191#255'0'#191#191#255#133'OO'#255#192#0#0#255#192#0#0#255#191#1#1#255'~XX'
-  +#255'>'#173#173#255'Q'#148#148#255#175#22#22#255#192#0#0#149#224#138#141#187
-  +#218'np'#255#211'RS'#255#204'56'#255#171'9:'#255#140'FF'#255'z^^'#255#191#1#1
-  +#255#192#0#0#255#192#0#0#255#192#0#0#255#133'OO'#255'0'#191#191#255'7'#182
-  +#182#255#166'""'#255#192#0#0'>'#226#147#149'W'#219'wx'#255#213'Z\'#255#206'>'
-  +'?'#255#182'66'#255#193#5#5#255#187#7#7#255#192#0#0#255#192#0#0#255#192#0#0
-  +#255#178#18#18#255#151'77'#255'oll'#255#147'<<'#255#186#8#8#229#192#0#0#1#228
-  +#155#158#7#221#127#129#236#210'gh'#255#162'op'#255'K'#176#176#255'too'#255
-  +#184#10#10#255#192#0#0#255#187#6#6#255#163''''''#255'N'#151#151#255'~WW'#255
-  +#184#11#11#255#189#4#4#255#192#0#0#143#255#255#255#0#255#255#255#0#223#135
-  +#137#144#217'kl'#255'r'#159#160#255'3'#204#204#255'I'#169#169#255#189#4#4#255
-  +#192#0#0#255#192#0#0#255'_'#129#129#255'0'#191#191#255'L'#154#154#255#191#1#1
-  +#255#192#0#0#255#192#0#0'8'#255#255#255#0#255#255#255#0#225#144#146','#219's'
-  +'u'#255#136#147#148#255'T'#175#175#255#133'ij'#255#175#24#24#255#192#0#0#255
-  +#192#0#0#255'rhh'#255'E'#163#163#255'waa'#255#175#22#22#255#192#0#0#224#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#221'{}'#201#214'_a'#255
-  +#185'WX'#255#200'(('#255#194#10#10#255#192#0#0#255#192#0#0#255#192#0#0#255
-  +#166'""'#255#191#1#1#255#192#0#0#255#192#0#0#137#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#223#132#134'e'#172#135#136#255#209'KM'#255#203
-  +'/0'#255#196#19#19#255#192#0#0#255#192#0#0#255#168'  '#255#192#0#0#255#192#0
-  +#0#255#192#0#0#255#192#0#0'2'#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#225#140#142#13'L'#205#206#251'b'#175#176#255#199'<='#255#198#27#27
-  +#255#192#0#0#255#148'::'#255'N'#151#151#255'c||'#255#166'""'#255#192#0#0#218
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0'Z'#200#200#204'M'#196#197#255#196'JK'#255#200'#$'#255#193#7#7#255
-  +#142'CC'#255'0'#191#191#255'3'#187#187#255#172#26#26#255#192#0#0#131#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +'Z'#204#205'k'#187'xz'#255#203'MN'#255#202',,'#255#195#15#15#255#144'@@'#255
-  +'c{{'#255'rgg'#255#169#30#30#255#192#0#0','#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#255#255#3#217'ln'#214
-  +#210'PR'#255#201'78'#255#197#24#24#255#192#0#0#255#189#4#4#255#180#16#16#255
-  +#192#0#0#212#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#219'uwr'#212'YZ'#255#149'rs'
-  +#255#148'YY'#255#166'%%'#255#192#0#0#255#192#0#0#255#192#0#0'}'#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#221'}'#127#21#159#137#138#251'7'#205#206#255'2'#201
-  +#201#255#154'>>'#255#192#0#0#255#192#0#0#255#192#0#0'&'#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  ,#255#255#255#0#255#255#255#0#176#133#135#182'B'#199#199#255'B'#188#188#255
-  +#131'bc'#255#192#0#0#255#192#0#0#206#255#255#255#0#255#255#255#0#255#255#255
+  'TPF0'#8'TImgForm'#7'ImgForm'#4'Left'#3#209#1#6'Height'#3#213#1#3'Top'#2'r'#5
+  +'Width'#3#1#4#13'ActiveControl'#7#12'ControlPanel'#14'AllowDropFiles'#9#7'Ca'
+  +'ption'#6#7'MRIcroN'#12'ClientHeight'#3#213#1#11'ClientWidth'#3#1#4#8'DockSi'
+  +'te'#9#9'Font.Name'#6#13'MS Sans Serif'#4'Menu'#7#9'MainMenu1'#7'OnClose'#7#9
+  +'FormClose'#8'OnCreate'#7#10'FormCreate'#9'OnDestroy'#7#11'FormDestroy'#11'O'
+  +'nDropFiles'#7#13'FormDropFiles'#9'OnKeyDown'#7#11'FormKeyDown'#10'OnKeyPres'
+  +'s'#7#12'FormKeyPress'#8'OnResize'#7#10'FormResize'#6'OnShow'#7#8'FormShow'#8
+  +'Position'#7#14'poScreenCenter'#10'LCLVersion'#6#7'1.2.4.0'#0#6'TPanel'#12'C'
+  +'ontrolPanel'#4'Left'#2#0#6'Height'#2'('#3'Top'#2#0#5'Width'#3#1#4#5'Align'#7
+  +#5'alTop'#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#2'('#11'ClientWidth'#3
+  +#1#4#11'ParentColor'#8#14'ParentShowHint'#8#8'ShowHint'#9#8'TabOrder'#2#0#10
+  +'OnDblClick'#7#20'ControlPanelDblClick'#0#6'TLabel'#6'LabelX'#4'Left'#2#6#6
+  +'Height'#2#17#3'Top'#2#12#5'Width'#2#8#7'Caption'#6#1'X'#11'ParentColor'#8#0
+  +#0#6'TLabel'#6'LabelY'#4'Left'#2'Q'#6'Height'#2#17#3'Top'#2#12#5'Width'#2#8#7
+  +'Caption'#6#1'Y'#11'ParentColor'#8#0#0#6'TLabel'#6'LabelZ'#4'Left'#3#153#0#6
+  +'Height'#2#17#3'Top'#2#12#5'Width'#2#7#7'Caption'#6#1'Z'#11'ParentColor'#8#0
+  +#0#12'TSpeedButton'#10'HideROIBtn'#4'Left'#3'('#3#6'Height'#2#30#4'Hint'#6#30
+  +'Briefly hide VOIs and Overlays'#3'Top'#2#4#5'Width'#2#30#10'Glyph.Data'#10
+  +':'#6#0#0'6'#6#0#0'BM6'#6#0#0#0#0#0#0'6'#0#0#0'('#0#0#0#16#0#0#0#24#0#0#0#1#0
+  +' '#0#0#0#0#0#0#6#0#0'd'#0#0#0'd'#0#0#0#0#0#0#0#0#0#0#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#198#28#29'%'#192#0#0#127#140'EE'#188#183#11#11#203#191#1
+  +#1#232#192#0#0#246#192#0#0#219#192#0#0#189#192#0#0#160#192#0#0#130#192#0#0'c'
+  +#192#0#0'$'#255#255#255#0#255#255#255#0#214']_<'#207'AB'#196#200'%%'#255#141
+  +'LL'#255'G'#160#160#255'B'#168#168#255#152'55'#255#192#0#0#255#192#0#0#255
+  +#192#0#0#255#192#0#0#255#154'33'#255#192#0#0#255#192#0#0#255#192#0#0#197#222
+  +#130#132#134#216'fg'#253#209'JK'#255#202'-.'#255#171'00'#255'0'#191#191#255
+  +'0'#191#191#255#133'OO'#255#192#0#0#255#192#0#0#255#191#1#1#255'~XX'#255'>'
+  +#173#173#255'Q'#148#148#255#175#22#22#255#192#0#0#149#224#138#141#187#218'np'
+  +#255#211'RS'#255#204'56'#255#171'9:'#255#140'FF'#255'z^^'#255#191#1#1#255#192
+  +#0#0#255#192#0#0#255#192#0#0#255#133'OO'#255'0'#191#191#255'7'#182#182#255
+  +#166'""'#255#192#0#0'>'#226#147#149'W'#219'wx'#255#213'Z\'#255#206'>?'#255
+  +#182'66'#255#193#5#5#255#187#7#7#255#192#0#0#255#192#0#0#255#192#0#0#255#178
+  +#18#18#255#151'77'#255'oll'#255#147'<<'#255#186#8#8#229#192#0#0#1#228#155#158
+  +#7#221#127#129#236#210'gh'#255#162'op'#255'K'#176#176#255'too'#255#184#10#10
+  +#255#192#0#0#255#187#6#6#255#163''''''#255'N'#151#151#255'~WW'#255#184#11#11
+  +#255#189#4#4#255#192#0#0#143#255#255#255#0#255#255#255#0#223#135#137#144#217
+  +'kl'#255'r'#159#160#255'3'#204#204#255'I'#169#169#255#189#4#4#255#192#0#0#255
+  +#192#0#0#255'_'#129#129#255'0'#191#191#255'L'#154#154#255#191#1#1#255#192#0#0
+  +#255#192#0#0'8'#255#255#255#0#255#255#255#0#225#144#146','#219'su'#255#136
+  +#147#148#255'T'#175#175#255#133'ij'#255#175#24#24#255#192#0#0#255#192#0#0#255
+  +'rhh'#255'E'#163#163#255'waa'#255#175#22#22#255#192#0#0#224#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#221'{}'#201#214'_a'#255#185'WX'#255
+  +#200'(('#255#194#10#10#255#192#0#0#255#192#0#0#255#192#0#0#255#166'""'#255
+  +#191#1#1#255#192#0#0#255#192#0#0#137#255#255#255#0#255#255#255#0#255#255#255
+  +#0#255#255#255#0#223#132#134'e'#172#135#136#255#209'KM'#255#203'/0'#255#196
+  +#19#19#255#192#0#0#255#192#0#0#255#168'  '#255#192#0#0#255#192#0#0#255#192#0
+  +#0#255#192#0#0'2'#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#225
+  +#140#142#13'L'#205#206#251'b'#175#176#255#199'<='#255#198#27#27#255#192#0#0
+  +#255#148'::'#255'N'#151#151#255'c||'#255#166'""'#255#192#0#0#218#255#255#255
+  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'Z'
+  +#200#200#204'M'#196#197#255#196'JK'#255#200'#$'#255#193#7#7#255#142'CC'#255
+  +'0'#191#191#255'3'#187#187#255#172#26#26#255#192#0#0#131#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'Z'#204#205
+  +'k'#187'xz'#255#203'MN'#255#202',,'#255#195#15#15#255#144'@@'#255'c{{'#255'r'
+  +'gg'#255#169#30#30#255#192#0#0','#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#0#255#255#3#217'ln'#214#210'PR'
+  +#255#201'78'#255#197#24#24#255#192#0#0#255#189#4#4#255#180#16#16#255#192#0#0
+  +#212#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#219'uwr'#212'YZ'#255#149'rs'#255
+  +#148'YY'#255#166'%%'#255#192#0#0#255#192#0#0#255#192#0#0'}'#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#221'}'#127#21#159#137#138#251'7'#205#206#255'2'#201#201
+  +#255#154'>>'#255#192#0#0#255#192#0#0#255#192#0#0'&'#255#255#255#0#255#255#255
   +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#206'z{J'#209'XZ'#255#154'kk'#255#198#29#29#255#192#0
-  +#0#255#192#0#0'w'#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  ,#255#255#0#255#255#255#0#176#133#135#182'B'#199#199#255'B'#188#188#255#131'b'
+  +'c'#255#192#0#0#255#192#0#0#206#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#206'z{J'#209'XZ'#255#154'kk'#255#198#29#29#255#192#0#0
+  +#255#192#0#0'w'#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
   +#255#0#220'z|'#2#214']_'#225#207'AB'#255#182'9:'#255#194#9#9#255#192#0#0'!'
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
@@ -87,62 +87,66 @@ LazarusResources.Add('TImgForm','FORMDATA',[
   +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#217'k'
   +'m'#6#210'OPW'#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#9'NumGlyphs'#2#0#11'OnMouseDown'#7#19
-  +'HideROIBtnMouseDown'#9'OnMouseUp'#7#17'HideROIBtnMouseUp'#0#0#12'TSpeedButt'
-  +'on'#7'XBarBtn'#4'Left'#3'F'#3#6'Height'#2#30#4'Hint'#6#190'Toggle Crosshair'
-  +'s'#13#10'right-click to change gap size'#13#10'right+ctrl click to change c'
-  +'olor'#13#10'right+alt click to change thickness'#13#10'right+shift to repos'
-  +'ition origin'#13#10'right+ctrl+alt to adjust font size'#3'Top'#2#4#5'Width'
-  +#2#30#10'AllowAllUp'#9#10'Glyph.Data'#10#218#8#0#0#214#8#0#0'BM'#214#8#0#0#0
-  +#0#0#0'6'#0#0#0'('#0#0#0#23#0#0#0#24#0#0#0#1#0' '#0#0#0#0#0#160#8#0#0'd'#0#0
-  +#0'd'#0#0#0#0#0#0#0#0#0#0#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#192#0#0'9'#192#0#0'4'#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#0#0#255#20#0#0#255'P'#0#0#255#10#255
+  +#255#255#0#255#255#255#0#255#255#255#0#11'OnMouseDown'#7#19'HideROIBtnMouseD'
+  +'own'#9'OnMouseUp'#7#17'HideROIBtnMouseUp'#0#0#12'TSpeedButton'#7'XBarBtn'#4
+  +'Left'#3'F'#3#6'Height'#2#30#4'Hint'#6#190'Toggle Crosshairs'#13#10'right-cl'
+  +'ick to change gap size'#13#10'right+ctrl click to change color'#13#10'right'
+  +'+alt click to change thickness'#13#10'right+shift to reposition origin'#13
+  +#10'right+ctrl+alt to adjust font size'#3'Top'#2#4#5'Width'#2#30#10'AllowAll'
+  +'Up'#9#10'Glyph.Data'#10#218#8#0#0#214#8#0#0'BM'#214#8#0#0#0#0#0#0'6'#0#0#0
+  +'('#0#0#0#23#0#0#0#24#0#0#0#1#0' '#0#0#0#0#0#160#8#0#0'd'#0#0#0'd'#0#0#0#0#0
+  +#0#0#0#0#0#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#192#0#0'9'#192#0#0'4'#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#0#0#255#20#0#0#255'P'#0#0#255#10#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
   +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0
-  +#255' '#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0
+  +#0#255' '#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255
+  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255
   +#255#0#0#255' '#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'
-  +#0#0#255#255#0#0#255' '#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255
-  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0
-  +#255'@'#0#0#255#255#0#0#255' '#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#25
-  +#0#0#255'P'#0#0#255'P'#0#0#255'P'#0#0#255'Pv'#0'c'#206'q'#0'h'#195#0#0#255'P'
-  +#0#0#255'P'#0#0#255'P'#0#0#255'P'#0#0#255'P'#0#0#255'|'#0#0#255#255#0#0#255
-  +'f'#0#0#255'P'#0#0#255'P'#0#0#255'P'#0#0#255'P'#0#0#255'P'#0#0#255'P'#0#0#255
-  +'P'#0#0#255#25#0#0#255'P'#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#25#0#0#255'P'#0
+  +#0#255'P'#0#0#255'P'#0#0#255'Pv'#0'c'#206'q'#0'h'#195#0#0#255'P'#0#0#255'P'#0
+  +#0#255'P'#0#0#255'P'#0#0#255'P'#0#0#255'|'#0#0#255#255#0#0#255'f'#0#0#255'P'
+  +#0#0#255'P'#0#0#255'P'#0#0#255'P'#0#0#255'P'#0#0#255'P'#0#0#255'P'#0#0#255#25
+  +#0#0#255'P'#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
   +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
   +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
-  +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255'P'#0#0#255#5#0#0#255
-  +#16#0#0#255#16#0#0#255#16#0#0#255#16#176#0#22#188#174#0#24#173#0#0#255#16#0#0
-  +#255#16#0#0#255#16#0#0#255#16#0#0#255#16#0#0#255'L'#0#0#255#255#0#0#255'.'#0
-  +#0#255#16#0#0#255#16#0#0#255#16#0#0#255#16#0#0#255#16#0#0#255#16#0#0#255#16#0
-  +#0#255#5#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255
-  +#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255#255#255#0#255#255
-  ,#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255'P'#0#0#255#5#0#0#255#16#0#0#255
+  +#16#0#0#255#16#0#0#255#16#176#0#22#188#174#0#24#173#0#0#255#16#0#0#255#16#0#0
+  +#255#16#0#0#255#16#0#0#255#16#0#0#255'L'#0#0#255#255#0#0#255'.'#0#0#255#16#0
+  +#0#255#16#0#0#255#16#0#0#255#16#0#0#255#16#0#0#255#16#0#0#255#16#0#0#255#5
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#192#0
+  +#0#184#192#0#0#168#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255#255#255#0#255#255#255#0
+  ,#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255
+  +#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
   +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0
-  +#255' '#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0
+  +#0#255' '#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255
+  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255
   +#255#0#0#255' '#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
@@ -150,279 +154,274 @@ LazarusResources.Add('TImgForm','FORMDATA',[
   +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'
   +#0#0#255#255#0#0#255' '#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255
-  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#192#0#0'M'#192#0#0
+  +#248#192#0#0#248#192#0#0#248#192#0#0#248#192#0#0#253#192#0#0#253#192#0#0#248
+  +#192#0#0#248#192#0#0#248#192#0#0#248#192#0#0#248#143#0'A'#250#0#0#255#255#167
+  +#0'!'#249#192#0#0#248#192#0#0#248#192#0#0#248#192#0#0#248#192#0#0#248#192#0#0
+  +#248#192#0#0#248#192#0#0'M'#192#0#0' '#192#0#0'h'#192#0#0'h'#192#0#0'h'#192#0
+  +#0'h'#192#0#0#213#192#0#0#203#192#0#0'h'#192#0#0'h'#192#0#0'h'#192#0#0'h'#192
+  +#0#0'hi'#0's'#142#0#0#255#255#142#0'B{'#192#0#0'h'#192#0#0'h'#192#0#0'h'#192
+  +#0#0'h'#192#0#0'h'#192#0#0'h'#192#0#0'h'#192#0#0' '#255#255#255#0#255#255#255
+  +#0#255#255#255#0#255#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0
+  +#255#255#0#0#255' '#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0
   +#255'@'#0#0#255#255#0#0#255' '#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#192#0#0'M'
-  +#192#0#0#248#192#0#0#248#192#0#0#248#192#0#0#248#192#0#0#253#192#0#0#253#192
-  +#0#0#248#192#0#0#248#192#0#0#248#192#0#0#248#192#0#0#248#143#0'A'#250#0#0#255
-  +#255#167#0'!'#249#192#0#0#248#192#0#0#248#192#0#0#248#192#0#0#248#192#0#0#248
-  +#192#0#0#248#192#0#0#248#192#0#0'M'#192#0#0' '#192#0#0'h'#192#0#0'h'#192#0#0
-  +'h'#192#0#0'h'#192#0#0#213#192#0#0#203#192#0#0'h'#192#0#0'h'#192#0#0'h'#192#0
-  +#0'h'#192#0#0'hi'#0's'#142#0#0#255#255#142#0'B{'#192#0#0'h'#192#0#0'h'#192#0
-  +#0'h'#192#0#0'h'#192#0#0'h'#192#0#0'h'#192#0#0'h'#192#0#0' '#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#192#0#0#184#192#0#0
-  +#168#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0
-  +#0#255'@'#0#0#255#255#0#0#255' '#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#192#0#0
-  +#184#192#0#0#168#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255#255#255#0#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#192#0#0#184
+  +#192#0#0#168#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255#255#255#0#255#255#255#0#255#255
   +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#192#0#0#184#192#0#0#168#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#192#0
+  +#0#184#192#0#0#168#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255#255#255#0#255#255#255#0
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255
+  +#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
   +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0
-  +#255' '#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#192#0#0#184#192#0#0#168#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#0#0#255'@'#0#0#255#255#0#0#255' '#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#192#0#0'9'#192#0#0'4'#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#20#0#0#255
-  +'P'#0#0#255#10#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#10'GroupIndex'#3'A'#1#9
-  +'NumGlyphs'#2#0#7'OnClick'#7#12'XBarBtnClick'#11'OnMouseDown'#7#16'XBarBtnMo'
-  +'useDown'#8'ShowHint'#9#14'ParentShowHint'#8#0#0#6'TPanel'#10'LayerPanel'#4
-  ,'Left'#3'0'#1#6'Height'#2'$'#3'Top'#2#2#5'Width'#3#244#1#12'ClientHeight'#2
-  +'$'#11'ClientWidth'#3#244#1#8'TabOrder'#2#5#0#12'TSpeedButton'#15'AutoContra'
-  +'stBtn'#4'Left'#2'y'#6'Height'#2#28#4'Hint'#6#12'Autocontrast'#3'Top'#2#3#5
-  +'Width'#2#28#10'Glyph.Data'#10#218#8#0#0#214#8#0#0'BM'#214#8#0#0#0#0#0#0'6'#0
-  +#0#0'('#0#0#0#24#0#0#0#23#0#0#0#1#0' '#0#0#0#0#0#160#8#0#0'd'#0#0#0'd'#0#0#0
-  +#0#0#0#0#0#0#0#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#0#0#0'"'#25#25#25'c...'#165'???'#194
-  +'RRR'#215'OOO'#213'<<<'#192'---'#159#17#17#17'_'#0#0#0#26#255#255#255#0#255
+  +#255#255#0#255#255#255#0#192#0#0'9'#192#0#0'4'#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#20#0#0#255'P'#0#0#255#10
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#10'GroupIndex'#3'A'#1#7'OnClick'#7#12
+  +'XBarBtnClick'#11'OnMouseDown'#7#16'XBarBtnMouseDown'#8'ShowHint'#9#14'Paren'
+  +'tShowHint'#8#0#0#6'TPanel'#10'LayerPanel'#4'Left'#3'0'#1#6'Height'#2'$'#3'T'
+  ,'op'#2#2#5'Width'#3#244#1#12'ClientHeight'#2'$'#11'ClientWidth'#3#244#1#8'Ta'
+  +'bOrder'#2#5#0#12'TSpeedButton'#15'AutoContrastBtn'#4'Left'#2'y'#6'Height'#2
+  +#28#4'Hint'#6#12'Autocontrast'#3'Top'#2#3#5'Width'#2#28#10'Glyph.Data'#10#218
+  +#8#0#0#214#8#0#0'BM'#214#8#0#0#0#0#0#0'6'#0#0#0'('#0#0#0#24#0#0#0#23#0#0#0#1
+  +#0' '#0#0#0#0#0#160#8#0#0'd'#0#0#0'd'#0#0#0#0#0#0#0#0#0#0#0#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#0#0#0'"'#25#25#25'c...'#165'???'#194'RRR'#215'OOO'#213'<<<'#192'---'
+  +#159#17#17#17'_'#0#0#0#26#255#255#255#0#255#255#255#0#255#255#255#0#255#255
   +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#0#0#0#12'...'#168'www'#232#198#198#198#254#244#244#244#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#240#240#240#255#24#24#24#255
-  +'100'#242'*(('#157#0#0#0#5#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#255#255#0#255#255#255#0#255#255#255#0#0#0#0#12'...'#168'www'#232#198#198
+  +#198#254#244#244#244#255#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#240#240#240#255#24#24#24#255'100'#242'*(('#157#0#0#0#5#255#255
   +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +'###SEEE'#218#220#220#220#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#0#255#255#255#0#255#255#255#0'###SEEE'#218#220#220#220#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#27#22#22#255#26#16#16#255''''#26#26#255'2(('#234'#'#30#30';'#255#255#255
-  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0'000'#158#150#150#150#240#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#27#22#22#255#26#16#16#255
+  +''''#26#26#255'2(('#234'#'#30#30';'#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'000'#158#150#150#150
+  +#240#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#250#250#255',  '#255'/'#28#28#255':##'#255
-  +'>%%'#255'ZEE'#248'@66'#133#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0'$$$Y'#144#144#144#240#255#255#255#255#255#255#255#255
+  +#250#250#255',  '#255'/'#28#28#255':##'#255'>%%'#255'ZEE'#248'@66'#133#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'$$$Y'#144
+  +#144#144#240#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#254#254#255#255#245#245#255':(('#255
-  +'B(('#255'Q11'#255'W44'#255'O//'#255'Y@@'#248'+'#31#31'='#255#255#255#0#255
-  +#255#255#0#255#255#255#0#0#0#0#22'JJJ'#223#255#255#255#255#255#255#255#255
+  +#255#255#254#254#255#255#245#245#255':(('#255'B(('#255'Q11'#255'W44'#255'O//'
+  +#255'Y@@'#248'+'#31#31'='#255#255#255#0#255#255#255#0#255#255#255#0#0#0#0#22
+  +'JJJ'#223#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#252#252#255#255#243
-  +#243#255'B--'#255'N//'#255'd<<'#255'pCC'#255'a::'#255'K--'#255'H66'#232#17#10
-  +#10#10#255#255#255#0#255#255#255#0'000'#194#232#232#232#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#251#250#250
-  +#255#253#253#253#255#255#255#255#255#255#255#255#255#255#255#255#255#255#252
-  +#252#255#255#242#242#255'C--'#255'O//'#255'f=='#255'uFF'#255'c;;'#255'L..'
-  +#255'B..'#255':11'#174#255#255#255#0#0#0#0'-'#139#139#139#238#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#243#240#239
-  +#255#130'hh'#255#244#242#242#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#254#254#255#255#245#245#255'<))'#255'E))'#255'U33'#255'\77'#255'S22'
-  +#255'B(('#255'-'#27#27#255'<33'#242#0#0#0#9'!!!r'#207#207#207#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#232#223#223#255#131'^]'
-  +#255'c>>'#255#244#242#242#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#249#249#255'/!!'#255'3'#31#31#255'?&&'#255'C(('#255'=%%'
-  +#255'0'#29#29#255#31#19#19#255' '#28#28#254#3#3#3'<111'#177#251#251#251#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#222#204#203#255#141']\'#255
-  +'zML'#255'kCB'#255'tWV'#255'hQP'#255'\HH'#255'O@@'#255'C88'#255'600'#255#21
-  +#13#13#255#30#18#18#255''''#23#23#255')'#25#25#255'&'#23#23#255#28#17#17#255
-  +#14#8#8#255#2#2#2#255'%%%'#138'EEE'#202#255#255#255#255#255#255#255#255#255
-  +#254#254#255#215#183#182#255#159'ed'#255#144'[Z'#255#129'RP'#255'sHG'#255'd?'
-  +'>'#255'U55'#255'F,+'#255'7#"'#255'('#25#25#255#26#16#16#255#11#7#7#255#7#4#4
-  +#255#14#8#8#255#16#10#10#255#13#8#8#255#5#3#3#255#0#0#0#255#0#0#0#255''''''''
-  +#199'TTT'#219#255#255#255#255#255#255#255#255#227#192#191#255#182'sq'#255#167
-  +'ih'#255#152'`^'#255#137'VU'#255'zML'#255'kDC'#255']:9'#255'N10'#255'?('''
-  +#255'0'#30#30#255'!'#21#21#255#19#12#11#255#4#2#2#255#0#0#0#255#0#0#0#255#0#0
-  +#0#255#0#0#0#255#0#0#0#255#0#0#0#255'+++'#219'EEE'#202#255#255#255#255#255
-  +#255#255#255#254#252#251#255#212#166#166#255#175'nm'#255#160'ec'#255#145'[Z'
-  +#255#130'RQ'#255'sIH'#255'd?>'#255'V65'#255'G-,'#255'8##'#255')'#26#25#255#26
-  +#16#16#255#12#7#7#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0
-  +#255''''''''#199'111'#177#251#251#251#255#255#255#255#255#255#255#255#255#255
-  +#254#254#255#218#184#183#255#167'jh'#255#153'`_'#255#138'WV'#255'{ML'#255'lD'
-  +'C'#255'];:'#255'O21'#255'@(('#255'1'#31#30#255'"'#21#21#255#19#12#12#255#4#3
-  +#3#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#2#2#2#255'%%%'#137'!!!r'#207
-  +#207#207#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#226#202#202#255#162'ih'#255#146'\Z'#255#225#214#213#255#246#244#244#255#245
-  +#243#243#255#244#242#242#255#244#242#242#255#243#241#241#255'6'''''#255#27#17
-  ,#17#255#12#8#7#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#22#22#22#254#3#3#3
-  +'<'#0#0#0'-'#139#139#139#238#255#255#255#255#255#254#254#255#255#254#254#255
-  +#255#254#254#255#255#255#255#255#234#219#219#255#161'mk'#255#233#223#223#255
+  +#255#255#255#255#255#252#252#255#255#243#243#255'B--'#255'N//'#255'd<<'#255
+  +'pCC'#255'a::'#255'K--'#255'H66'#232#17#10#10#10#255#255#255#0#255#255#255#0
+  +'000'#194#232#232#232#255#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#251#250#250#255#253#253#253#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#252#252#255#255#242#242#255'C--'#255'O/'
+  +'/'#255'f=='#255'uFF'#255'c;;'#255'L..'#255'B..'#255':11'#174#255#255#255#0#0
+  +#0#0'-'#139#139#139#238#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#243#240#239#255#130'hh'#255#244#242#242#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#254#254#255#255#245#245#255
+  +'<))'#255'E))'#255'U33'#255'\77'#255'S22'#255'B(('#255'-'#27#27#255'<33'#242
+  +#0#0#0#9'!!!r'#207#207#207#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#232#223#223#255#131'^]'#255'c>>'#255#244#242#242#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#249#249#255
+  +'/!!'#255'3'#31#31#255'?&&'#255'C(('#255'=%%'#255'0'#29#29#255#31#19#19#255
+  +' '#28#28#254#3#3#3'<111'#177#251#251#251#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#222#204#203#255#141']\'#255'zML'#255'kCB'#255'tWV'#255'hQP'
+  +#255'\HH'#255'O@@'#255'C88'#255'600'#255#21#13#13#255#30#18#18#255''''#23#23
+  +#255')'#25#25#255'&'#23#23#255#28#17#17#255#14#8#8#255#2#2#2#255'%%%'#138'EE'
+  +'E'#202#255#255#255#255#255#255#255#255#255#254#254#255#215#183#182#255#159
+  +'ed'#255#144'[Z'#255#129'RP'#255'sHG'#255'd?>'#255'U55'#255'F,+'#255'7#"'#255
+  +'('#25#25#255#26#16#16#255#11#7#7#255#7#4#4#255#14#8#8#255#16#10#10#255#13#8
+  +#8#255#5#3#3#255#0#0#0#255#0#0#0#255''''''''#199'TTT'#219#255#255#255#255#255
+  +#255#255#255#227#192#191#255#182'sq'#255#167'ih'#255#152'`^'#255#137'VU'#255
+  +'zML'#255'kDC'#255']:9'#255'N10'#255'?('''#255'0'#30#30#255'!'#21#21#255#19
+  +#12#11#255#4#2#2#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0
+  +#255'+++'#219'EEE'#202#255#255#255#255#255#255#255#255#254#252#251#255#212
+  +#166#166#255#175'nm'#255#160'ec'#255#145'[Z'#255#130'RQ'#255'sIH'#255'd?>'
+  +#255'V65'#255'G-,'#255'8##'#255')'#26#25#255#26#16#16#255#12#7#7#255#0#0#0
+  +#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255''''''''#199'111'#177
+  +#251#251#251#255#255#255#255#255#255#255#255#255#255#254#254#255#218#184#183
+  +#255#167'jh'#255#153'`_'#255#138'WV'#255'{ML'#255'lDC'#255'];:'#255'O21'#255
+  +'@(('#255'1'#31#30#255'"'#21#21#255#19#12#12#255#4#3#3#255#0#0#0#255#0#0#0
+  +#255#0#0#0#255#0#0#0#255#2#2#2#255'%%%'#137'!!!r'#207#207#207#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#226#202#202#255#162'ih'
+  +#255#146'\Z'#255#225#214#213#255#246#244#244#255#245#243#243#255#244#242#242
+  +#255#244#242#242#255#243#241#241#255'6'''''#255#27#17#17#255#12#8#7#255#0#0#0
+  ,#255#0#0#0#255#0#0#0#255#0#0#0#255#22#22#22#254#3#3#3'<'#0#0#0'-'#139#139#139
+  +#238#255#255#255#255#255#254#254#255#255#254#254#255#255#254#254#255#255#255
+  +#255#255#234#219#219#255#161'mk'#255#233#223#223#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255'>,,'#255'#'#22#21
+  +#255#20#12#12#255#5#3#3#255#0#0#0#255#0#0#0#255#0#0#0#255'***'#241#0#0#0#9
+  +#255#255#255#0':55'#196#234#226#226#255#255#247#247#255#255#247#247#255#255
+  +#248#248#255#255#248#248#255#255#248#248#255#243#229#229#255#243#237#237#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255'>,,'#255'#'#22#21#255#20#12#12#255#5#3#3#255#0#0#0#255#0#0#0#255#0#0#0
-  +#255'***'#241#0#0#0#9#255#255#255#0':55'#196#234#226#226#255#255#247#247#255
-  +#255#247#247#255#255#248#248#255#255#248#248#255#255#248#248#255#243#229#229
-  +#255#243#237#237#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255'E11'#255'+'#27#26#255#28#17#17#255#13#8#8#255#0#0#0
-  +#255#0#0#0#255#19#19#19#255''''''''#169#255#255#255#0#255#255#255#0'('#24#24
-  +#26'dVV'#227#255#241#241#255#255#241#241#255#255#241#241#255#255#242#242#255
-  +#255#242#242#255#255#242#242#255#255#243#243#255#255#248#248#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255'L65'#255'2 '#31#255'%'
-  +#22#22#255#28#17#17#255#19#12#12#255#17#10#10#255'+&&'#229#0#0#0#9#255#255
-  +#255#0#255#255#255#0#255#255#255#0'O;;f'#166#146#146#243#255#235#235#255#255
-  +#235#235#255#255#236#236#255#255#236#236#255#255#236#236#255#255#237#237#255
-  +#255#237#237#255#255#240#240#255#255#251#251#255#255#252#252#255#255#251#251
-  +#255'`A@'#255'P21'#255'L//'#255'A(('#255'3'#31#31#255'B44'#247#24#20#20'9'
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'YEE'
-  +#171#177#151#151#244#255#229#229#255#255#230#230#255#255#230#230#255#255#230
-  +#230#255#255#231#231#255#255#231#231#255#255#231#231#255#255#231#231#255#255
-  +#231#231#255#255#231#231#255#128'SS'#255'lBB'#255'`;;'#255'T43'#255'eMM'#248
-  +':22'#131#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255
-  +#0#255#255#255#0#255#255#255#0'cFFh'#132'aa'#229#230#200#200#255#255#224#224
-  +#255#255#224#224#255#255#224#224#255#255#225#225#255#255#225#225#255#255#225
-  +#225#255#255#225#225#255#255#225#225#255#143'\\'#255'~MM'#255'vKJ'#255'cEE'
-  +#236'3((?'#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#154']]'#29'qP'
-  +'P'#189#170#132#132#240#218#182#182#254#248#211#211#255#255#219#219#255#255
-  +#219#219#255#255#219#219#255#255#219#219#255#245#210#210#255#160'ii'#255#144
-  +'ee'#245'aFF'#170'@'''''#7#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0'D)),uMM'#131'|VV'#190#140'cc'#215
-  +#157'qq'#231#152'nn'#229#134'__'#212'wSS'#183'[<<r'#11#7#7#27#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#9'NumGlyphs'#2#0#7'OnClick'#7#20'AutoContrastBtnClick'#0#0#12'TSp'
-  +'eedButton'#14'LutFromZeroBtn'#4'Left'#3#183#1#6'Height'#2#28#4'Hint'#6#21'C'
-  +'olor range from zero'#3'Top'#2#4#5'Width'#2#28#10'AllowAllUp'#9#10'Glyph.Da'
-  +'ta'#10#178#6#0#0#174#6#0#0'BM'#174#6#0#0#0#0#0#0'6'#0#0#0'('#0#0#0#24#0#0#0
-  +#23#0#0#0#1#0#24#0#0#0#0#0'x'#6#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0
+  +#255'E11'#255'+'#27#26#255#28#17#17#255#13#8#8#255#0#0#0#255#0#0#0#255#19#19
+  +#19#255''''''''#169#255#255#255#0#255#255#255#0'('#24#24#26'dVV'#227#255#241
+  +#241#255#255#241#241#255#255#241#241#255#255#242#242#255#255#242#242#255#255
+  +#242#242#255#255#243#243#255#255#248#248#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255'L65'#255'2 '#31#255'%'#22#22#255#28#17#17
+  +#255#19#12#12#255#17#10#10#255'+&&'#229#0#0#0#9#255#255#255#0#255#255#255#0
+  +#255#255#255#0'O;;f'#166#146#146#243#255#235#235#255#255#235#235#255#255#236
+  +#236#255#255#236#236#255#255#236#236#255#255#237#237#255#255#237#237#255#255
+  +#240#240#255#255#251#251#255#255#252#252#255#255#251#251#255'`A@'#255'P21'
+  +#255'L//'#255'A(('#255'3'#31#31#255'B44'#247#24#20#20'9'#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'YEE'#171#177#151#151#244
+  +#255#229#229#255#255#230#230#255#255#230#230#255#255#230#230#255#255#231#231
+  +#255#255#231#231#255#255#231#231#255#255#231#231#255#255#231#231#255#255#231
+  +#231#255#128'SS'#255'lBB'#255'`;;'#255'T43'#255'eMM'#248':22'#131#255#255#255
+  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0'cFFh'#132'aa'#229#230#200#200#255#255#224#224#255#255#224#224#255
+  +#255#224#224#255#255#225#225#255#255#225#225#255#255#225#225#255#255#225#225
+  +#255#255#225#225#255#143'\\'#255'~MM'#255'vKJ'#255'cEE'#236'3((?'#255#255#255
+  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#154']]'#29'qPP'#189#170#132#132#240
+  +#218#182#182#254#248#211#211#255#255#219#219#255#255#219#219#255#255#219#219
+  +#255#255#219#219#255#245#210#210#255#160'ii'#255#144'ee'#245'aFF'#170'@'''''
+  +#7#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0'D)),uMM'#131'|VV'#190#140'cc'#215#157'qq'#231#152'nn'
+  +#229#134'__'#212'wSS'#183'[<<r'#11#7#7#27#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#7'OnClick'#7
+  +#20'AutoContrastBtnClick'#0#0#12'TSpeedButton'#14'LutFromZeroBtn'#4'Left'#3
+  +#183#1#6'Height'#2#28#4'Hint'#6#21'Color range from zero'#3'Top'#2#4#5'Width'
+  +#2#28#10'AllowAllUp'#9#10'Glyph.Data'#10#178#6#0#0#174#6#0#0'BM'#174#6#0#0#0
+  +#0#0#0'6'#0#0#0'('#0#0#0#24#0#0#0#23#0#0#0#1#0#24#0#0#0#0#0'x'#6#0#0#0#0#0#0
+  +#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
   +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
   +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
-  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0
+  +#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
   +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
-  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0
-  +#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
-  +#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0#255#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255
+  +#0#0#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0
+  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
+  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0#255
+  +#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
+  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
+  +#255#0#0#255#0#0#0#0#0#0#0#0#255#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255
   +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
-  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0#255#0#0
+  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0#255#0#0#0#0#0#0
+  +#0#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0
+  +#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
+  +#255#0#0#0#0#0#0#0#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0
+  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
+  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
+  +#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0#0
+  +#0#0#0#0#0#0#255#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0
   +#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
-  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
-  +#0#0#255#0#0#0#0#0#0#0#0#255#0#0#0#0#0#0#0#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0
-  +#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0#0#0#0#0#0#0#255#0#0#255#0#0#0#0
-  +#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
-  +#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0
-  +#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0
-  +#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0#0#0#0#0#0#0#0#0#0
-  +#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0
-  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0#0#255#0#0
-  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0
-  +#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0
-  +#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#0#255#0#255#0#0#255#0#0#255#0#0
-  ,#255#0#0#255#0#0#255#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0
-  +#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255
-  +#0#0#0#255#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#255#0#0
-  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
-  +#0#0#0#0#0#255#0#0#255#0#128#128#128#128#128#128#0#0#255#128#128#128#128#128
-  +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
+  +#255#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
+  +#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0
+  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0
+  +#255#0#0#0#255#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#255#0
+  ,#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
+  +#255#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#255#0#255#0#0#255#0#0#255#0
+  +#0#255#0#0#255#0#0#255#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
+  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#0#0#0#255#0#0#255#0#128#128#128
+  +#128#128#128#0#0#255#128#128#128#128#128#128#128#128#128#128#128#128#128#128
   +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
   +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
-  +#128#128#128#128#0#0#0#0#0#0#10#8#8#14#8#8#20#12#12#25#15#15#30#18#18'#'#20
-  +#20'('#23#23','#26#26'1'#29#29'6  9##:%%:'''':)):++:--:00'#0#0#0#0#0#0#0#0#0
-  +#128#128#128#128#128#128#0#0#0#0#0#0','#26#26'D((Y55oBB'#132'OO'#154'\\'#176
-  +'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255
-  +#181#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0
-  +#128#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'#132'OO'#154'\\'#176
-  +'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255
-  +#181#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0
-  +#128#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'#132'OO'#154'\\'#176
-  +'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255
-  +#181#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0
-  +#128#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'#132'OO'#154'\\'#176
-  +'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255
-  +#181#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0
-  +#128#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'#132'OO'#154'\\'#176
-  +'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255
-  +#181#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0
-  +#128#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'#132'OO'#154'\\'#176
-  +'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255
-  +#181#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0
-  +#128#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'#132'OO'#154'\\'#176
-  +'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255
-  +#181#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0
-  +#128#128#128#128#128#128#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
+  +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#0#0#0#0#0#0#10#8#8
+  +#14#8#8#20#12#12#25#15#15#30#18#18'#'#20#20'('#23#23','#26#26'1'#29#29'6  9#'
+  +'#:%%:'''':)):++:--:00'#0#0#0#0#0#0#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0
+  +','#26#26'D((Y55oBB'#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144
+  +#254#155#155#255#164#164#255#172#172#255#181#181#255#190#190#255#198#198#255
+  +#215#215#255#224#224#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0'.'
+  +#27#27'D((Y55oBB'#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144#254
+  +#155#155#255#164#164#255#172#172#255#181#181#255#190#190#255#198#198#255#215
+  +#215#255#224#224#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0'.'#27
+  +#27'D((Y55oBB'#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144#254
+  +#155#155#255#164#164#255#172#172#255#181#181#255#190#190#255#198#198#255#215
+  +#215#255#224#224#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0'.'#27
+  +#27'D((Y55oBB'#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144#254
+  +#155#155#255#164#164#255#172#172#255#181#181#255#190#190#255#198#198#255#215
+  +#215#255#224#224#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0'.'#27
+  +#27'D((Y55oBB'#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144#254
+  +#155#155#255#164#164#255#172#172#255#181#181#255#190#190#255#198#198#255#215
+  +#215#255#224#224#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0'.'#27
+  +#27'D((Y55oBB'#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144#254
+  +#155#155#255#164#164#255#172#172#255#181#181#255#190#190#255#198#198#255#215
+  +#215#255#224#224#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0'.'#27
+  +#27'D((Y55oBB'#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144#254
+  +#155#155#255#164#164#255#172#172#255#181#181#255#190#190#255#198#198#255#215
+  +#215#255#224#224#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0#0#0#0
   +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
-  +#0#0#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
+  +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#128#128#128#128#128#128#128#128#128
   +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
   +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
   +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
-  +#10'GroupIndex'#3#194#0#9'NumGlyphs'#2#0#7'OnClick'#7#19'LutFromZeroBtnClick'
-  +#0#0#12'TSpeedButton'#11'ColorBarBtn'#4'Left'#3#211#1#6'Height'#2#28#4'Hint'
-  +#6#17'Draw color range '#3'Top'#2#4#5'Width'#2#28#10'Glyph.Data'#10#154#3#0#0
-  +#150#3#0#0'BM'#150#3#0#0#0#0#0#0'6'#0#0#0'('#0#0#0#24#0#0#0#12#0#0#0#1#0#24#0
-  +#0#0#0#0'`'#3#0#0'd'#0#0#0'd'#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0
+  +#128#128#128#128#128#128#128#128#128#10'GroupIndex'#3#194#0#7'OnClick'#7#19
+  +'LutFromZeroBtnClick'#0#0#12'TSpeedButton'#11'ColorBarBtn'#4'Left'#3#211#1#6
+  +'Height'#2#28#4'Hint'#6#17'Draw color range '#3'Top'#2#4#5'Width'#2#28#10'Gl'
+  +'yph.Data'#10#154#3#0#0#150#3#0#0'BM'#150#3#0#0#0#0#0#0'6'#0#0#0'('#0#0#0#24
+  +#0#0#0#12#0#0#0#1#0#24#0#0#0#0#0'`'#3#0#0'd'#0#0#0'd'#0#0#0#0#0#0#0#0#0#0#0#0
   +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
   +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
-  +#255#0#0#255#0#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
+  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#128#128#128#128#128#128#128#128#128
   +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
   +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
   +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
-  +#128#128#128#0#0#0#0#0#0#10#8#8#14#8#8#20#12#12#25#15#15#30#18#18'#'#20#20'('
-  +#23#23','#26#26'1'#29#29'6  9##:%%:'''':)):++:--:00'#0#0#0#0#0#0#0#0#0#128
-  +#128#128#128#128#128#0#0#0#0#0#0','#26#26'D((Y55oBB'#132'OO'#154'\\'#176'ii'
-  +#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255#181
-  +#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0#128
-  +#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'#132'OO'#154'\\'#176'ii'
-  +#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255#181
-  +#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0#128
-  +#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'#132'OO'#154'\\'#176'ii'
-  +#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255#181
-  +#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0#128
-  +#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'#132'OO'#154'\\'#176'ii'
-  +#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255#181
-  +#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0#128
-  +#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'#132'OO'#154'\\'#176'ii'
-  +#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255#181
-  ,#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0#128
-  +#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'#132'OO'#154'\\'#176'ii'
-  +#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255#181
-  +#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0#128
-  +#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'#132'OO'#154'\\'#176'ii'
-  +#197'vv'#218#131#131#241#144#144#254#155#155#255#164#164#255#172#172#255#181
-  +#181#255#190#190#255#198#198#255#215#215#255#224#224#255#255#255#0#0#0#128
-  +#128#128#128#128#128#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
+  +#128#128#128#128#128#128#128#128#128#0#0#0#0#0#0#10#8#8#14#8#8#20#12#12#25#15
+  +#15#30#18#18'#'#20#20'('#23#23','#26#26'1'#29#29'6  9##:%%:'''':)):++:--:00'
+  +#0#0#0#0#0#0#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0','#26#26'D((Y55oBB'
+  +#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164
+  +#164#255#172#172#255#181#181#255#190#190#255#198#198#255#215#215#255#224#224
+  +#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'
+  +#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164
+  +#164#255#172#172#255#181#181#255#190#190#255#198#198#255#215#215#255#224#224
+  +#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'
+  +#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164
+  +#164#255#172#172#255#181#181#255#190#190#255#198#198#255#215#215#255#224#224
+  +#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'
+  +#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164
+  +#164#255#172#172#255#181#181#255#190#190#255#198#198#255#215#215#255#224#224
+  +#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'
+  +#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164
+  +#164#255#172#172#255#181#181#255#190#190#255#198#198#255#215#215#255#224#224
+  ,#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'
+  +#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164
+  +#164#255#172#172#255#181#181#255#190#190#255#198#198#255#215#215#255#224#224
+  +#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0'.'#27#27'D((Y55oBB'
+  +#132'OO'#154'\\'#176'ii'#197'vv'#218#131#131#241#144#144#254#155#155#255#164
+  +#164#255#172#172#255#181#181#255#190#190#255#198#198#255#215#215#255#224#224
+  +#255#255#255#0#0#0#128#128#128#128#128#128#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
   +#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0
+  +#0#0#0#0#0#0#0#0#0#0#0#128#128#128#128#128#128#128#128#128#128#128#128#128
   +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
   +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
   +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128
-  +#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#128#9'N'
-  +'umGlyphs'#2#0#11'OnMouseDown'#7#20'ColorBarBtnMouseDown'#0#0#9'TComboBox'#9
-  +'LayerDrop'#4'Left'#2#4#6'Height'#2#20#3'Top'#2#4#5'Width'#2't'#10'ItemHeigh'
-  +'t'#2#0#9'ItemIndex'#2#0#13'Items.Strings'#1#6#16'Background Layer'#0#8'OnCh'
-  +'ange'#7#15'LayerDropChange'#8'OnSelect'#7#15'LayerDropSelect'#14'ParentShow'
-  +'Hint'#8#8'ShowHint'#9#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#0#4'Text'
-  +#6#16'Background Layer'#0#0#14'TFloatSpinEdit'#13'MinWindowEdit'#4'Left'#3
-  +#153#0#6'Height'#2#16#3'Top'#2#4#5'Width'#2'X'#13'DecimalPlaces'#2#4#9'Incre'
-  +'ment'#5#0#0#0#0#0#0#0#128#255'?'#8'MaxValue'#5#0#0#0#0#0#127#150#152#22'@'#8
-  +'MinValue'#5#0#0#0#0#0#127#150#152#22#192#8'OnChange'#7#27'MinContrastWindow'
-  +'EditChange'#8'TabOrder'#2#1#5'Value'#5#0#0#0#0#0#0#0#128#255'?'#0#0#14'TFlo'
-  +'atSpinEdit'#13'MaxWindowEdit'#4'Left'#3#245#0#6'Height'#2#16#3'Top'#2#4#5'W'
-  +'idth'#2'X'#13'DecimalPlaces'#2#4#9'Increment'#5#0#0#0#0#0#0#0#128#255'?'#8
-  +'MaxValue'#5#0#0#0#0#0#127#150#152#22'@'#8'MinValue'#5#0#0#0#0#0#127#150#152
-  +#22#192#8'OnChange'#7#27'MaxContrastWindowEditChange'#8'TabOrder'#2#2#5'Valu'
-  +'e'#5#0#0#0#0#0#0#0#128#255'?'#0#0#9'TComboBox'#7'LUTdrop'#4'Left'#3'T'#1#6
-  +'Height'#2#20#3'Top'#2#5#5'Width'#2'd'#13'DropDownCount'#2'B'#10'ItemHeight'
-  +#2#0#8'OnChange'#7#13'LUTdropChange'#8'OnSelect'#7#13'LUTdropSelect'#14'Pare'
-  +'ntShowHint'#8#8'ShowHint'#9#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#3#0
-  +#0#0#9'TComboBox'#8'ZoomDrop'#4'Left'#3#225#0#6'Height'#2#20#3'Top'#2#8#5'Wi'
-  +'dth'#2'O'#13'DropDownCount'#2#12#10'ItemHeight'#2#0#13'Items.Strings'#1#6#6
-  +'To Fit'#6#6'To Int'#6#2'x1'#6#2'x2'#6#2'x3'#6#2'x4'#6#2'x5'#6#2'x6'#6#2'x7'
-  +#6#2'x8'#6#2'x9'#0#8'OnChange'#7#14'ZoomDropChange'#8'OnSelect'#7#14'ZoomDro'
-  +'pSelect'#14'ParentShowHint'#8#8'ShowHint'#9#5'Style'#7#14'csDropDownList'#8
-  +'TabOrder'#2#4#0#0#9'TSpinEdit'#9'XViewEdit'#4'Left'#2#24#6'Height'#2#16#3'T'
-  +'op'#2#12#5'Width'#2'4'#8'MinValue'#2#1#8'OnChange'#7#15'XViewEditChange'#8
+  +#128#128#128#128#128#11'OnMouseDown'#7#20'ColorBarBtnMouseDown'#0#0#9'TCombo'
+  +'Box'#9'LayerDrop'#4'Left'#2#4#6'Height'#2#20#3'Top'#2#4#5'Width'#2't'#10'It'
+  +'emHeight'#2#0#9'ItemIndex'#2#0#13'Items.Strings'#1#6#16'Background Layer'#0
+  +#8'OnChange'#7#15'LayerDropChange'#8'OnSelect'#7#15'LayerDropSelect'#14'Pare'
+  +'ntShowHint'#8#8'ShowHint'#9#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#0#4
+  +'Text'#6#16'Background Layer'#0#0#14'TFloatSpinEdit'#13'MinWindowEdit'#4'Lef'
+  +'t'#3#153#0#6'Height'#2#16#3'Top'#2#4#5'Width'#2'X'#13'DecimalPlaces'#2#4#9
+  +'Increment'#5#0#0#0#0#0#0#0#128#255'?'#8'MaxValue'#5#0#0#0#0#0#127#150#152#22
+  +'@'#8'MinValue'#5#0#0#0#0#0#127#150#152#22#192#8'OnChange'#7#27'MinContrastW'
+  +'indowEditChange'#8'TabOrder'#2#1#5'Value'#5#0#0#0#0#0#0#0#128#255'?'#0#0#14
+  +'TFloatSpinEdit'#13'MaxWindowEdit'#4'Left'#3#245#0#6'Height'#2#16#3'Top'#2#4
+  +#5'Width'#2'X'#13'DecimalPlaces'#2#4#9'Increment'#5#0#0#0#0#0#0#0#128#255'?'
+  +#8'MaxValue'#5#0#0#0#0#0#127#150#152#22'@'#8'MinValue'#5#0#0#0#0#0#127#150
+  +#152#22#192#8'OnChange'#7#27'MaxContrastWindowEditChange'#8'TabOrder'#2#2#5
+  +'Value'#5#0#0#0#0#0#0#0#128#255'?'#0#0#9'TComboBox'#7'LUTdrop'#4'Left'#3'T'#1
+  +#6'Height'#2#20#3'Top'#2#5#5'Width'#2'd'#13'DropDownCount'#2'B'#10'ItemHeigh'
+  +'t'#2#0#8'OnChange'#7#13'LUTdropChange'#8'OnSelect'#7#13'LUTdropSelect'#14'P'
+  +'arentShowHint'#8#8'ShowHint'#9#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#3
+  +#0#0#0#9'TComboBox'#8'ZoomDrop'#4'Left'#3#225#0#6'Height'#2#20#3'Top'#2#8#5
+  +'Width'#2'O'#13'DropDownCount'#2#12#10'ItemHeight'#2#0#13'Items.Strings'#1#6
+  +#6'To Fit'#6#6'To Int'#6#2'x1'#6#2'x2'#6#2'x3'#6#2'x4'#6#2'x5'#6#2'x6'#6#2'x'
+  +'7'#6#2'x8'#6#2'x9'#0#8'OnChange'#7#14'ZoomDropChange'#8'OnSelect'#7#14'Zoom'
+  +'DropSelect'#14'ParentShowHint'#8#8'ShowHint'#9#5'Style'#7#14'csDropDownList'
+  +#8'TabOrder'#2#4#0#0#9'TSpinEdit'#9'XViewEdit'#4'Left'#2#24#6'Height'#2#16#3
+  +'Top'#2#12#5'Width'#2'4'#8'MinValue'#2#1#8'OnChange'#7#15'XViewEditChange'#8
   +'TabOrder'#2#0#5'Value'#2'd'#0#0#9'TSpinEdit'#9'YViewEdit'#4'Left'#2'a'#6'He'
   +'ight'#2#16#3'Top'#2#12#5'Width'#2'4'#8'MinValue'#2#1#8'OnChange'#7#15'XView'
   +'EditChange'#8'TabOrder'#2#1#5'Value'#2' '#0#0#9'TSpinEdit'#9'ZViewEdit'#4'L'
@@ -449,8 +448,8 @@ LazarusResources.Add('TImgForm','FORMDATA',[
   +#148#217#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
   +#255#0#0#255#0#201#201#204#142#142#218'33'#242'33'#242#165#165#213#0#255#0#0
   +#255#0#0#255#0#0#255#0#159#159#219#152#152#255'55'#255#0#0#255'??'#238#0#255
-  ,#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0
-  +#203#203#204'``'#229'33'#242'SS'#233#201#201#204#0#255#0#0#255#0#0#255#0#0
+  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0
+  ,#203#203#204'``'#229'33'#242'SS'#233#201#201#204#0#255#0#0#255#0#0#255#0#0
   +#255#0#202#202#204'vv'#228#26#26#251'..'#242#168#168#212#0#255#0#0#255#0#0
   +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#154#154#215'3'
   +'3'#241'<<'#239#181#181#209#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#204#204
@@ -498,379 +497,378 @@ LazarusResources.Add('TImgForm','FORMDATA',[
   +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
   +#0#170#170#170#5#5#5'%%%'#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
   +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
-  +#0#0#255#0#10'GroupIndex'#2','#9'NumGlyphs'#2#0#7'OnClick'#7#11'PenBtnClick'
-  +#0#0#12'TSpeedButton'#12'ClosedPenBtn'#4'Left'#2#30#6'Height'#2#30#4'Hint'#6
-  +#13'Autoclose Pen'#3'Top'#2#0#5'Width'#2#30#10'AllowAllUp'#9#10'Glyph.Data'
-  +#10#250#6#0#0#246#6#0#0'BM'#246#6#0#0#0#0#0#0'6'#0#0#0'('#0#0#0#24#0#0#0#24#0
-  +#0#0#1#0#24#0#0#0#0#0#192#6#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255
-  +#0#0#255#0#0#255#0#201#201#204#186#186#208#177#177#210#176#176#210#180#180
-  +#209#188#188#207#198#198#205#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0
-  +#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#202
-  +#202#204#164#164#213'{{'#223'44'#241'33'#242'33'#242'33'#241'55'#241'77'#240
-  +'CC'#237'VV'#233'oo'#226#139#139#219#173#173#211#200#200#204#0#255#0#0#255#0
-  +#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#160#160#214'//'#243#23#23
-  +#248#151#151#216'::'#240'33'#242'33'#242'33'#242'33'#242'33'#242'33'#242'33'
-  +#242'33'#242'33'#242'33'#241'AA'#238'uu'#224#184#184#208#0#255#0#0#255#0#0
-  +#255#0#0#255#0#0#255#0#171#171#211'bb'#251'LL'#255#20#20#249#199#199#204#194
-  +#194#206#175#175#211#161#161#214#154#154#216#148#148#217#140#140#219#130#130
-  ,#222'xx'#224'mm'#227'\\'#231'BB'#238'33'#241'33'#242'=='#238#186#186#207#0
-  +#255#0#0#255#0#0#255#0#0#255#0#127#127#227#179#179#255'<<'#255#0#0#254#148
-  +#148#217#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
-  +#255#0#0#255#0#201#201#204#142#142#218'33'#242'33'#242#165#165#213#0#255#0#0
-  +#255#0#0#255#0#0#255#0#159#159#219#152#152#255'55'#255#0#0#255'??'#238#0#255
-  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0
-  +#203#203#204'``'#229'33'#242'SS'#233#201#201#204#0#255#0#0#255#0#0#255#0#0
-  +#255#0#202#202#204'vv'#228#26#26#251'..'#242#168#168#212#0#255#0#0#255#0#255
-  +#0#0#255#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#154#154#215'33'
-  +#241'<<'#239#181#181#209#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#204#204#204
-  +#169#169#169';;C[[]'#185#185#185#0#255#0#255#0#0#255#0#0#255#0#0#255#0#0#0
-  +#255#0#0#255#0#0#255#0#0#255#0#202#202#204'MM'#234'44'#241#153#153#216#0#255
-  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#204#204#204'@@@'#14#14#14#0#0#0#28
-  +#28#28#180#180#180#255#0#0#255#0#0#255#0#0#255#0#0#0#255#0#0#255#0#0#255#0#0
-  +#255#0#184#184#208'44'#241'\\'#231#203#203#204#0#255#0#0#255#0#0#255#0#0#255
-  +#0#0#255#0#0#255#0#203#203#203'DDDPPP'#0#0#0#0#0#0'bbb'#0#255#0#255#0#0#255#0
-  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#197#197#205'GG'#236'JJ'#235#188
-  +#188#207#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#203#203#203'FFF___'
-  +#0#0#0#0#0#0'???'#0#255#0#0#255#0#0#255#0#0#255#0#255#0#0#255#0#0#0#255#0#0
-  +#255#0#0#255#0#177#177#210'II'#235'AA'#237#151#151#216#203#203#204#0#255#0#0
-  +#255#0#0#255#0#0#255#0#0#255#0'IIIeee'#0#0#0#0#0#0'000'#0#255#0#0#255#0#0#255
-  +#0#255#0#0#255#0#0#255#0#0#255#0#0#0#255#0#0#255#0#0#255#0#196#196#205'zz'
-  +#223'77'#240']]'#231#181#181#209#0#255#0#0#255#0#0#255#0#0#255#0'PPPiii'#0#0
-  +#0#0#0#0'$$$'#0#255#0#0#255#0#0#255#0#255#0#0#255#0#0#255#0#0#255#0#0#0#255#0
-  +#0#255#0#0#255#0#0#255#0#203#203#204#178#178#210'[['#231'::'#239#139#139#219
-  +#202#202#204#0#255#0#0#255#0'iii[[['#0#0#0#0#0#0#29#29#29#0#255#0#0#255#0#0
-  +#255#0#0#255#0#255#0#0#255#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
-  +#0#0#255#0#202#202#204#151#151#216'>>'#238'{{'#223#203#203#204#0#255#0#145
-  +#145#145'PPP'#1#1#1#0#0#0#27#27#27#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
-  +#255#0#0#255#0#255#0#0#255#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#203
-  +#203#204'{{'#223';;'#239#194#194#205#0#255#0#187#187#187':::'#10#10#10#0#0#0
-  +#24#24#24#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#255#0#0#255#0#0#255
-  +#0#0#255#0#0#0#255#0#0#255#0#203#203#204#182#182#209'll'#227'SS'#233#169#169
-  +#212#0#255#0#0#255#0#202#202#202'222'#23#23#23#0#0#0#16#16#16#203#203#203#0
-  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#255#0#0#255#0#0#255#0#0#255#0#0#203
-  +#203#204#174#174#211'ii'#228'bb'#229#159#159#214#202#202#204#0#255#0#0#255#0
-  +#0#255#0#0#255#0'KKK'#21#21#21#0#0#0#11#11#11#198#198#198#0#255#0#0#255#0#0
-  +#255#0#0#255#0#0#255#0#0#255#0#255#0#0#255#0#0#160#160#214'nn'#226'zz'#223
-  +#181#181#209#203#203#204#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#133
-  +#133#133#2#2#2#0#0#0#5#5#5#187#187#187#0#255#0#0#255#0#0#255#0#0#255#0#0#255
-  +#0#0#255#0#196#196#205#149#149#216#165#165#213#200#200#204#0#255#0#0#255#0#0
-  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#191#191#191#8#8#8#0#0
-  +#0#0#0#0#163#163#163#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#203#203
-  +#204#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0
-  +#0#255#0#0#255#0#0#255#0#0#255#0'JJJ'#0#0#0#0#0#0#132#132#132#0#255#0#0#255#0
-  +#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
-  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#166
-  +#166#166#3#3#3#0#0#0'eee'#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
+  +#0#0#255#0#10'GroupIndex'#2','#7'OnClick'#7#11'PenBtnClick'#0#0#12'TSpeedBut'
+  +'ton'#12'ClosedPenBtn'#4'Left'#2#30#6'Height'#2#30#4'Hint'#6#13'Autoclose Pe'
+  +'n'#3'Top'#2#0#5'Width'#2#30#10'AllowAllUp'#9#10'Glyph.Data'#10#250#6#0#0#246
+  +#6#0#0'BM'#246#6#0#0#0#0#0#0'6'#0#0#0'('#0#0#0#24#0#0#0#24#0#0#0#1#0#24#0#0#0
+  +#0#0#192#6#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#255#0#0#255#0#0#255#0#0#255
+  +#0#201#201#204#186#186#208#177#177#210#176#176#210#180#180#209#188#188#207
+  +#198#198#205#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0
+  +#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#202#202#204#164#164
+  +#213'{{'#223'44'#241'33'#242'33'#242'33'#241'55'#241'77'#240'CC'#237'VV'#233
+  +'oo'#226#139#139#219#173#173#211#200#200#204#0#255#0#0#255#0#0#255#0#0#255#0
+  +#0#255#0#0#255#0#0#255#0#0#255#0#160#160#214'//'#243#23#23#248#151#151#216':'
+  +':'#240'33'#242'33'#242'33'#242'33'#242'33'#242'33'#242'33'#242'33'#242'33'
+  +#242'33'#241'AA'#238'uu'#224#184#184#208#0#255#0#0#255#0#0#255#0#0#255#0#0
+  +#255#0#171#171#211'bb'#251'LL'#255#20#20#249#199#199#204#194#194#206#175#175
+  +#211#161#161#214#154#154#216#148#148#217#140#140#219#130#130#222'xx'#224'mm'
+  +#227'\\'#231'BB'#238'33'#241'33'#242'=='#238#186#186#207#0#255#0#0#255#0#0
+  ,#255#0#0#255#0#127#127#227#179#179#255'<<'#255#0#0#254#148#148#217#0#255#0#0
+  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#201
+  +#201#204#142#142#218'33'#242'33'#242#165#165#213#0#255#0#0#255#0#0#255#0#0
+  +#255#0#159#159#219#152#152#255'55'#255#0#0#255'??'#238#0#255#0#0#255#0#0#255
+  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#203#203#204'``'
+  +#229'33'#242'SS'#233#201#201#204#0#255#0#0#255#0#0#255#0#0#255#0#202#202#204
+  +'vv'#228#26#26#251'..'#242#168#168#212#0#255#0#0#255#0#255#0#0#255#0#0#0#255
+  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#154#154#215'33'#241'<<'#239#181
+  +#181#209#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#204#204#204#169#169#169';;C'
+  +'[[]'#185#185#185#0#255#0#255#0#0#255#0#0#255#0#0#255#0#0#0#255#0#0#255#0#0
+  +#255#0#0#255#0#202#202#204'MM'#234'44'#241#153#153#216#0#255#0#0#255#0#0#255
+  +#0#0#255#0#0#255#0#0#255#0#204#204#204'@@@'#14#14#14#0#0#0#28#28#28#180#180
+  +#180#255#0#0#255#0#0#255#0#0#255#0#0#0#255#0#0#255#0#0#255#0#0#255#0#184#184
+  +#208'44'#241'\\'#231#203#203#204#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
+  +#255#0#203#203#203'DDDPPP'#0#0#0#0#0#0'bbb'#0#255#0#255#0#0#255#0#0#0#255#0#0
+  +#255#0#0#255#0#0#255#0#0#255#0#197#197#205'GG'#236'JJ'#235#188#188#207#0#255
+  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#203#203#203'FFF___'#0#0#0#0#0#0'?'
+  +'??'#0#255#0#0#255#0#0#255#0#0#255#0#255#0#0#255#0#0#0#255#0#0#255#0#0#255#0
+  +#177#177#210'II'#235'AA'#237#151#151#216#203#203#204#0#255#0#0#255#0#0#255#0
+  +#0#255#0#0#255#0'IIIeee'#0#0#0#0#0#0'000'#0#255#0#0#255#0#0#255#0#255#0#0#255
+  +#0#0#255#0#0#255#0#0#0#255#0#0#255#0#0#255#0#196#196#205'zz'#223'77'#240']]'
+  +#231#181#181#209#0#255#0#0#255#0#0#255#0#0#255#0'PPPiii'#0#0#0#0#0#0'$$$'#0
+  +#255#0#0#255#0#0#255#0#255#0#0#255#0#0#255#0#0#255#0#0#0#255#0#0#255#0#0#255
+  +#0#0#255#0#203#203#204#178#178#210'[['#231'::'#239#139#139#219#202#202#204#0
+  +#255#0#0#255#0'iii[[['#0#0#0#0#0#0#29#29#29#0#255#0#0#255#0#0#255#0#0#255#0
+  +#255#0#0#255#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#202
+  +#202#204#151#151#216'>>'#238'{{'#223#203#203#204#0#255#0#145#145#145'PPP'#1#1
+  +#1#0#0#0#27#27#27#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#255
+  +#0#0#255#0#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#203#203#204'{{'#223';;'
+  +#239#194#194#205#0#255#0#187#187#187':::'#10#10#10#0#0#0#24#24#24#0#255#0#0
+  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#255#0#0#255#0#0#255#0#0#255#0#0#0#255
+  +#0#0#255#0#203#203#204#182#182#209'll'#227'SS'#233#169#169#212#0#255#0#0#255
+  +#0#202#202#202'222'#23#23#23#0#0#0#16#16#16#203#203#203#0#255#0#0#255#0#0#255
+  +#0#0#255#0#0#255#0#255#0#0#255#0#0#255#0#0#255#0#0#203#203#204#174#174#211'i'
+  +'i'#228'bb'#229#159#159#214#202#202#204#0#255#0#0#255#0#0#255#0#0#255#0'KKK'
+  +#21#21#21#0#0#0#11#11#11#198#198#198#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0
+  +#0#255#0#255#0#0#255#0#0#160#160#214'nn'#226'zz'#223#181#181#209#203#203#204
+  +#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#133#133#133#2#2#2#0#0#0#5#5
+  +#5#187#187#187#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#196#196#205
+  +#149#149#216#165#165#213#200#200#204#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0
+  +#0#255#0#0#255#0#0#255#0#0#255#0#191#191#191#8#8#8#0#0#0#0#0#0#163#163#163#0
+  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#203#203#204#0#255#0#0#255#0#0
   +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
-  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0'AAA'#0#0#0'FFF'#0#255#0#0#255#0#0
+  +#0#0#255#0'JJJ'#0#0#0#0#0#0#132#132#132#0#255#0#0#255#0#0#255#0#0#255#0#0#255
+  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
+  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#166#166#166#3#3#3#0#0#0'eee'#0
   +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
-  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0
-  +#170#170#170#5#5#5'%%%'#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
   +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
-  +#255#0#10'GroupIndex'#2','#9'NumGlyphs'#2#0#7'OnClick'#7#11'PenBtnClick'#0#0
-  +#12'TSpeedButton'#7'FillBtn'#4'Left'#2'<'#6'Height'#2#30#4'Hint'#6#9'Fill to'
-  +'ol'#3'Top'#2#0#5'Width'#2#30#10'AllowAllUp'#9#10'Glyph.Data'#10#218#8#0#0
-  +#214#8#0#0'BM'#214#8#0#0#0#0#0#0'6'#0#0#0'('#0#0#0#23#0#0#0#24#0#0#0#1#0' '#0
-  +#0#0#0#0#160#8#0#0'd'#0#0#0'd'#0#0#0#0#0#0#0#0#0#0#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#0#0#255#8#0#0#255'O'#0#0#255'z'#0#0#255#147#0#0#255#171
-  +#0#0#255#196#0#0#255#221#0#0#255#245#0#0#255#239#0#0#255#211#0#0#255#184#0#0
-  +#255#156#0#0#255#129#0#0#255'T'#0#0#255#3#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#0#0#255#4#0#0#255'H'#0#0#255#160#0#0#255
-  +#241#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
-  ,#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
-  +#255#255#0#0#255#221#0#0#255'$'#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#0#0#255#156#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
+  +#255#0#0#255#0'AAA'#0#0#0'FFF'#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255
+  +#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
+  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#170#170#170#5#5#5'%%%'#0#255#0
+  +#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0
+  +#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#0#255#0#10'GroupIndex'#2','#7
+  +'OnClick'#7#11'PenBtnClick'#0#0#12'TSpeedButton'#7'FillBtn'#4'Left'#2'<'#6'H'
+  +'eight'#2#30#4'Hint'#6#9'Fill tool'#3'Top'#2#0#5'Width'#2#30#10'AllowAllUp'#9
+  +#10'Glyph.Data'#10#218#8#0#0#214#8#0#0'BM'#214#8#0#0#0#0#0#0'6'#0#0#0'('#0#0
+  +#0#23#0#0#0#24#0#0#0#1#0' '#0#0#0#0#0#160#8#0#0'd'#0#0#0'd'#0#0#0#0#0#0#0#0#0
+  +#0#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#8#0#0#255'O'#0#0#255
+  +'z'#0#0#255#147#0#0#255#171#0#0#255#196#0#0#255#221#0#0#255#245#0#0#255#239#0
+  +#0#255#211#0#0#255#184#0#0#255#156#0#0#255#129#0#0#255'T'#0#0#255#3#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#4#0#0
+  +#255'H'#0#0#255#160#0#0#255#241#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
+  +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#221#0#0#255'$'#255#255#255#0#255
+  ,#255#255#0#255#255#255#0#255#255#255#0#0#0#255#156#0#0#255#255#0#0#255#255#0
+  +#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
   +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#142#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#0#0#255#212#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
   +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
-  +#0#0#255#142#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255
-  +#212#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
   +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
-  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#254#0#0#255'@'#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'A'#0#0#255#248#0#0
-  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
+  +#255#254#0#0#255'@'#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0
+  +#0#255'A'#0#0#255#248#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
   +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
-  +#0#0#255#237#0#0#255#182#0#0#255'6'#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'0'#0#0#255#214#0#0#255#255
-  +#0#0#255#255#0#0#255#255#0#0#255#252#0#0#255#227#0#0#255#209#0#0#255#191#0#0
-  +#255#173#0#0#255#155#0#0#255'}'#0#0#255'N'#0#0#255#30'T'#0#0#25'\'#9#9']T'#0
-  +#0#7#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#0#0#255#16#0#0#255#215#0#0#255'O'#0#0#255')'#0#0
-  +#255#6#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0'e'#18#18'jv%%'#228#180'mn'#248'r##'#225'h'#24#24
-  +#140'T'#0#0#3#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#0#0#255'f'#0#0#255#171#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'T'#0#0#28
-  +'i'#23#23#198#172'_`'#241#251#187#189#255#253#195#197#255#253#201#203#255#190
-  +#130#131#245'h'#25#25#195'T'#0#0#13#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#0#0#255#207#0#0#255#130#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'f'#18#18'ox%%'
-  +#229#228#154#155#255#253#187#189#255#253#193#195#255#253#199#201#255#252#205
-  +#207#255#252#211#213#255#217#171#173#252'h'#27#27#203'T'#0#0#3#255#255#255#0
-  +#255#255#255#0#0#0#255'%'#0#0#255#255#0#0#255'Y'#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0'T'#0#0#30'j'#21#22#201#176'^^'#242
-  +#252#178#179#255#253#185#186#255#253#191#192#255#253#197#199#255#252#203#205
-  +#255#252#209#211#255#252#215#217#255#252#221#223#255#189#142#144#245'f'#25#26
-  +#143#255#255#255#0#255#255#255#0#0#0#255'z'#0#0#255#255#0#0#255'9'#255#255
-  +#255#0#255#255#255#0#255#255#255#0'T'#0#0#1'f'#17#17'tz%%'#229#231#148#148
-  +#255#254#177#178#255#253#183#184#255#253#189#190#255#253#195#196#255#253#201
-  +#203#255#252#207#209#255#252#212#215#255#252#218#221#255#252#224#227#255#251
-  +#230#233#255#128'>?'#232'T'#0#0'#'#255#255#255#0#0#0#255#167#0#0#255#255#0#0
-  +#255'P'#255#255#255#0#255#255#255#0'T'#0#0'!j'#20#20#203#180'\\'#243#253#168
-  +#169#255#254#175#176#255#253#181#182#255#253#187#188#255#253#193#194#255#253
-  +#198#200#255#252#204#206#255#252#210#213#255#252#216#219#255#252#222#225#255
-  +#251#228#231#255#251#234#237#255#215#188#191#255'h'#30#30#156#255#255#255#0#0
-  +#0#255#153#0#0#255#255#0#0#255#130'T'#0#0#1'g'#17#17'x|$$'#230#233#141#141
-  +#255#254#167#167#255#254#173#173#255#253#179#180#255#253#184#186#255#253#190
-  +#192#255#253#196#198#255#252#202#204#255#252#208#210#255#252#214#217#255#252
-  +#220#223#255#252#226#229#255#251#232#235#255#251#238#241#255#251#244#247#255
-  +'i  '#228#255#255#255#0#0#0#255')'#0#0#255#244#0#0#254#241'G'#20'd'#230'r''2'
-  +#252#223#130#130#255#254#165#165#255#254#170#171#255#254#176#177#255#253#182
-  +#184#255#253#188#190#255#253#194#196#255#253#200#202#255#252#206#208#255#252
-  +#212#214#255#252#218#221#255#252#224#227#255#251#230#233#255#251#236#239#255
-  +#251#241#245#255#175#134#136#243'f'#27#27#134#255#255#255#0#255#255#255#0#0#0
-  +#255#22#13#0#217#155'5%'#205#249'C?'#243#255'E+'#185#255#129':H'#255#215#135
-  +#135#255#253#180#181#255#253#186#187#255#253#192#194#255#253#198#200#255#252
-  +#204#206#255#252#210#212#255#252#216#218#255#252#222#224#255#251#228#231#255
-  +#251#233#237#255#251#239#243#255#211#187#190#253'g'#28#29#191#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0'T'#0#0#12'm%$'#224#173#167#243#255
-  +#0#0#255#255#22#21#253#255'[3'#142#255#195'|}'#255#253#190#191#255#253#196
-  +#197#255#252#202#204#255#252#208#210#255#252#214#216#255#252#219#222#255#252
-  +#225#228#255#251#231#234#255#251#237#241#255#235#219#223#255'j!!'#220'T'#0#0
-  +#13#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'_'
-  +#16#16'\'#165'wu'#239'A?'#252#255#0#0#255#255#0#0#255#255'P2'#169#255#183'uv'
-  +#255#253#200#201#255#252#205#208#255#252#211#214#255#252#217#220#255#252#223
-  +#226#255#251#229#232#255#251#235#238#255#248#236#240#255'w45'#231'T'#0#0')'
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  ,#255#255#0#255#255#255#0'h'#29#29#201#197#183#219#255#6#6#255#255#0#0#255#255
-  +#0#0#255#255'P7'#184#255#169'jj'#255#252#209#212#255#252#215#218#255#252#221
-  +#224#255#251#227#230#255#251#233#236#255#251#239#242#255#150'`b'#237'c'#22#22
-  +'\'#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0'T'#0#0'&v10'#231#163#156#241#255#4#4
-  +#255#255#0#0#255#255#0#0#255#255'P;'#197#255#171'pq'#255#252#219#222#255#252
-  +#225#228#255#251#231#234#255#251#237#240#255#191#155#157#247'g'#28#29#156#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0']'#13#12'=u10'
-  +#229#168#159#236#255#6#6#255#255#0#0#255#255#0#0#255#255']3'#136#255#227#190
-  +#191#255#251#229#232#255#251#235#238#255#222#199#202#255'h'#30#31#203'T'#0#0
-  +#3#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0'W'#5#5'-q+*'#225#172#162#230#255#9#9#255#255#0#0#255#255#19#18#252#255
-  +'|AW'#255#251#232#236#255#241#224#228#255'n&'''#224'T'#0#0#21#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#0#0#255#255#0#0#255#255#0#0#255#237#0#0#255#182#0#0#255'6'#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'0'
+  +#0#0#255#214#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#252#0#0#255#227#0#0
+  +#255#209#0#0#255#191#0#0#255#173#0#0#255#155#0#0#255'}'#0#0#255'N'#0#0#255#30
+  +'T'#0#0#25'\'#9#9']T'#0#0#7#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#16#0#0#255#215#0#0
+  +#255'O'#0#0#255')'#0#0#255#6#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'e'#18#18'jv%%'#228#180
+  +'mn'#248'r##'#225'h'#24#24#140'T'#0#0#3#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#0#0#255'f'#0#0#255#171#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0'T'#0#0' o''&'#219#192#178#217#255']['#251#255#4#4#255
-  +#255'E2'#202#255#194#156#158#255#129'AB'#233'['#10#11'8'#255#255#255#0#255
+  +#255#0#255#255#255#0'T'#0#0#28'i'#23#23#198#172'_`'#241#251#187#189#255#253
+  +#195#197#255#253#201#203#255#190#130#131#245'h'#25#25#195'T'#0#0#13#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#207#0#0#255#130#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0'f'#18#18'ox%%'#229#228#154#155#255#253#187#189#255#253
+  +#193#195#255#253#199#201#255#252#205#207#255#252#211#213#255#217#171#173#252
+  +'h'#27#27#203'T'#0#0#3#255#255#255#0#255#255#255#0#0#0#255'%'#0#0#255#255#0#0
+  +#255'Y'#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +'T'#0#0#30'j'#21#22#201#176'^^'#242#252#178#179#255#253#185#186#255#253#191
+  +#192#255#253#197#199#255#252#203#205#255#252#209#211#255#252#215#217#255#252
+  +#221#223#255#189#142#144#245'f'#25#26#143#255#255#255#0#255#255#255#0#0#0#255
+  +'z'#0#0#255#255#0#0#255'9'#255#255#255#0#255#255#255#0#255#255#255#0'T'#0#0#1
+  +'f'#17#17'tz%%'#229#231#148#148#255#254#177#178#255#253#183#184#255#253#189
+  +#190#255#253#195#196#255#253#201#203#255#252#207#209#255#252#212#215#255#252
+  +#218#221#255#252#224#227#255#251#230#233#255#128'>?'#232'T'#0#0'#'#255#255
+  +#255#0#0#0#255#167#0#0#255#255#0#0#255'P'#255#255#255#0#255#255#255#0'T'#0#0
+  +'!j'#20#20#203#180'\\'#243#253#168#169#255#254#175#176#255#253#181#182#255
+  +#253#187#188#255#253#193#194#255#253#198#200#255#252#204#206#255#252#210#213
+  +#255#252#216#219#255#252#222#225#255#251#228#231#255#251#234#237#255#215#188
+  +#191#255'h'#30#30#156#255#255#255#0#0#0#255#153#0#0#255#255#0#0#255#130'T'#0
+  +#0#1'g'#17#17'x|$$'#230#233#141#141#255#254#167#167#255#254#173#173#255#253
+  +#179#180#255#253#184#186#255#253#190#192#255#253#196#198#255#252#202#204#255
+  +#252#208#210#255#252#214#217#255#252#220#223#255#252#226#229#255#251#232#235
+  +#255#251#238#241#255#251#244#247#255'i  '#228#255#255#255#0#0#0#255')'#0#0
+  +#255#244#0#0#254#241'G'#20'd'#230'r''2'#252#223#130#130#255#254#165#165#255
+  +#254#170#171#255#254#176#177#255#253#182#184#255#253#188#190#255#253#194#196
+  +#255#253#200#202#255#252#206#208#255#252#212#214#255#252#218#221#255#252#224
+  +#227#255#251#230#233#255#251#236#239#255#251#241#245#255#175#134#136#243'f'
+  +#27#27#134#255#255#255#0#255#255#255#0#0#0#255#22#13#0#217#155'5%'#205#249'C'
+  +'?'#243#255'E+'#185#255#129':H'#255#215#135#135#255#253#180#181#255#253#186
+  +#187#255#253#192#194#255#253#198#200#255#252#204#206#255#252#210#212#255#252
+  +#216#218#255#252#222#224#255#251#228#231#255#251#233#237#255#251#239#243#255
+  +#211#187#190#253'g'#28#29#191#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0'T'#0#0#12'm%$'#224#173#167#243#255#0#0#255#255#22#21#253#255'[3'
+  +#142#255#195'|}'#255#253#190#191#255#253#196#197#255#252#202#204#255#252#208
+  +#210#255#252#214#216#255#252#219#222#255#252#225#228#255#251#231#234#255#251
+  +#237#241#255#235#219#223#255'j!!'#220'T'#0#0#13#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0'_'#16#16'\'#165'wu'#239'A?'#252
+  +#255#0#0#255#255#0#0#255#255'P2'#169#255#183'uv'#255#253#200#201#255#252#205
+  +#208#255#252#211#214#255#252#217#220#255#252#223#226#255#251#229#232#255#251
+  +#235#238#255#248#236#240#255'w45'#231'T'#0#0')'#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'h'#29
+  +#29#201#197#183#219#255#6#6#255#255#0#0#255#255#0#0#255#255'P7'#184#255#169
+  ,'jj'#255#252#209#212#255#252#215#218#255#252#221#224#255#251#227#230#255#251
+  +#233#236#255#251#239#242#255#150'`b'#237'c'#22#22'\'#255#255#255#0#255#255
   +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0'T'#0#0#22'k"!'#186#139'ON'#229#199
-  +#182#209#255#220#211#235#255'w22'#252'g'#27#28'r'#255#255#255#0#255#255#255#0
+  +#255#255#255#0'T'#0#0'&v10'#231#163#156#241#255#4#4#255#255#0#0#255#255#0#0
+  +#255#255'P;'#197#255#171'pq'#255#252#219#222#255#252#225#228#255#251#231#234
+  +#255#251#237#240#255#191#155#157#247'g'#28#29#156#255#255#255#0#255#255#255#0
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#255#0#255#255#255#0#255#255#255#0']'#13#12'=u10'#229#168#159#236#255#6#6
+  +#255#255#0#0#255#255#0#0#255#255']3'#136#255#227#190#191#255#251#229#232#255
+  +#251#235#238#255#222#199#202#255'h'#30#31#203'T'#0#0#3#255#255#255#0#255#255
   +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +'T'#0#0' j '#31#165'l##'#231'i'#31#31#190#255#255#255#0#255#255#255#0#255#255
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'W'#5#5'-q+*'#225#172
+  +#162#230#255#9#9#255#255#0#0#255#255#19#18#252#255'|AW'#255#251#232#236#255
+  +#241#224#228#255'n&'''#224'T'#0#0#21#255#255#255#0#255#255#255#0#255#255#255
+  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'T'#0#0' o'
+  +'''&'#219#192#178#217#255']['#251#255#4#4#255#255'E2'#202#255#194#156#158#255
+  +#129'AB'#233'['#10#11'8'#255#255#255#0#255#255#255#0#255#255#255#0#255#255
   +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#10'GroupIndex'#2','#9'NumGlyphs'#2#0#7'OnClick'#7#11'PenBtnClick'#0#0#12'TS'
-  +'peedButton'#10'EllipseBtn'#4'Left'#2'Z'#6'Height'#2#30#4'Hint'#6#12'Ellipse'
-  +' Tool'#3'Top'#2#0#5'Width'#2#30#10'AllowAllUp'#9#10'Glyph.Data'#10'z'#8#0#0
-  +'v'#8#0#0'BMv'#8#0#0#0#0#0#0'6'#0#0#0'('#0#0#0#24#0#0#0#22#0#0#0#1#0' '#0#0#0
-  +#0#0'@'#8#0#0'd'#0#0#0'd'#0#0#0#0#0#0#0#0#0#0#0#255#255#255#0#255#255#255#0
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#0#0#255#7#0#0#255'g'#0#0#255#179#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#0'T'#0#0#22'k"!'#186#139'ON'#229#199#182#209#255#220#211#235#255'w2'
+  +'2'#252'g'#27#28'r'#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#0#0#255#26#0#0#255','#0#0#255#3#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#0#0#255#5'11'#255#191'>>'#255#255#0#0#255#203#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#31#0#0
-  +#255#167#0#0#255#229#0#0#255#255#0#0#255#255#0#0#255#245#0#0#255#195#0#0#255
-  +'R'#255#255#255#0#255#255#255#0#0#0#255'8'#166#166#255#255'55'#255#255#0#0
-  +#255#249#0#0#255#20#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'd'#0#0#255
-  +#242#0#0#255#203#0#0#255'h'#0#0#255'4'#0#0#255'"'#0#0#255'U'#0#0#255#154#0#0
-  +#255#253#0#0#255#166#0#0#255#16#7#7#255'$'#163#163#255#255',,'#255#255#0#0
-  +#255#255#0#0#255'l'#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'N'#0#0#255#254#0#0#255'|'
-  +#0#0#255#4#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#0#0#255'='#0#0#255#225#0#0#255#173#255#255#255#0',,'#255']'#15#15#255
-  +#216#0#0#255#156#0#0#255#18#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#0#0#255#18#0#0#255#231#0#0#255#147#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#0#0#255'6'#0#0#255#252#0#0#255'YT'#0#0'''T'#0#0
-  +#185'T'#0#0#140'T'#0#0#8#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#0#0#255#127#0#0#255#224#0#0#255#10#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#138#0#0#255#224'Z'#9#9#139
-  +'_'#16#16#255'T'#0#0#255'T'#0#0#207'T'#0#0#3#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#0#0#255#183#0#0#255#153#255#255#255#0
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0'T'#0#0' j '#31#165'l##'#231
+  +'i'#31#31#190#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#10'GroupIndex'#2','#7'OnCli'
+  +'ck'#7#11'PenBtnClick'#0#0#12'TSpeedButton'#10'EllipseBtn'#4'Left'#2'Z'#6'He'
+  +'ight'#2#30#4'Hint'#6#12'Ellipse Tool'#3'Top'#2#0#5'Width'#2#30#10'AllowAllU'
+  +'p'#9#10'Glyph.Data'#10'z'#8#0#0'v'#8#0#0'BMv'#8#0#0#0#0#0#0'6'#0#0#0'('#0#0
+  +#0#24#0#0#0#22#0#0#0#1#0' '#0#0#0#0#0'@'#8#0#0'd'#0#0#0'd'#0#0#0#0#0#0#0#0#0
+  +#0#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#0#0#255#5#0#0#255#8#0#0#255'<'#0#0#255#255'Z'#15#26
-  ,#192#128'AA'#255'T'#0#0#255'T'#0#0#255'M'#0#21'H'#0#0#255#8#0#0#255#8#0#0#255
-  +#8#0#0#255#8#0#0#255#8#0#0#255#235#0#0#255'h'#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#0#0#255#176#0#0#255#255#0#0#255#255#0#0#255#255'8'#0'U'#255#131'FF'
-  +#255'T'#0#0#255'T'#0#0#255'%'#0#144#255#0#0#255#255#0#0#255#255#0#0#255#255#0
-  +#0#255#255#0#0#255#255#0#0#255#235#0#0#255'h'#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#7#0#0#255'g'#0#0
+  +#255#179#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255
+  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#0#0#255#26#0#0#255','#0#0#255#3#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#5'11'#255#191'>'
+  +'>'#255#255#0#0#255#203#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255
+  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#0#0#255#31#0#0#255#167#0#0#255#229#0#0#255#255#0#0#255#255#0#0#255
+  +#245#0#0#255#195#0#0#255'R'#255#255#255#0#255#255#255#0#0#0#255'8'#166#166
+  +#255#255'55'#255#255#0#0#255#249#0#0#255#20#255#255#255#0#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#0#0#255#176#0#0#255#141#0#0#255'.'#0#0#255#251'@'#0'<'#190#130'EE'#255
-  +'T'#0#0#255'T'#0#0#255'H'#0'$'#145#0#0#255'('#0#0#255'('#0#0#255'('#0#0#255
-  +'I'#0#0#255#255#0#0#255#183#0#0#255#152#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#0#0#255#176#0#0#255'x'#0#0#255'5'#0#0#255#255'L'#0#23#132#130'DD'#255'T'#0#0
-  +#255'T'#0#0#255'T'#0#0#136#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255
-  +'('#0#0#255#255#0#0#255#129#0#0#255#221#0#0#255#8#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0
-  +#255#176#0#0#255'x'#0#0#255#134#0#0#255#226'T'#0#0'D'#130'DD'#255'T'#0#0#255
-  +'T'#0#0#255'T'#0#0#145#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'('#0
-  +#0#255#255#0#0#255#21#0#0#255#234#0#0#255#141#255#255#255#0#255#255#255#0#255
+  +#255#0#0#0#255'd'#0#0#255#242#0#0#255#203#0#0#255'h'#0#0#255'4'#0#0#255'"'#0
+  +#0#255'U'#0#0#255#154#0#0#255#253#0#0#255#166#0#0#255#16#7#7#255'$'#163#163
+  +#255#255',,'#255#255#0#0#255#255#0#0#255'l'#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'N'
+  +#0#0#255#254#0#0#255'|'#0#0#255#4#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#0#0#255'='#0#0#255#225#0#0#255#173#255#255#255#0
+  +',,'#255']'#15#15#255#216#0#0#255#156#0#0#255#18#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#18#0#0#255
+  +#231#0#0#255#147#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'6'#0#0#255#252#0
+  +#0#255'YT'#0#0'''T'#0#0#185'T'#0#0#140'T'#0#0#8#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#127#0#0#255
+  +#224#0#0#255#10#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255
-  +#176#0#0#255#146#0#0#255#251#0#0#255'_T'#0#0#9#129'CC'#250'U'#1#1#255'T'#0#0
-  +#255'T'#0#0#153#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'('#0#0#255
-  +#255#255#255#255#0#0#0#255'S'#0#0#255#253#0#0#255't'#0#0#255#2#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#193#0#0#255
-  +#238#0#0#255#179#255#255#255#0#255#255#255#0'm%%'#198'X'#6#6#255'T'#0#0#255
-  +'T'#0#0#161#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'('#0#0#255#255
-  +#255#255#255#0#255#255#255#0#0#0#255'l'#0#0#255#245#0#0#255#196#0#0#255'`'#0
-  +#0#255','#0#0#255#26#0#0#255'M'#0#0#255#146#0#0#255#254#0#0#255#212#0#0#255
-  +#19#255#255#255#0#255#255#255#0'U'#2#2'}Y'#8#8#255'T'#0#0#255'T'#0#0#169#255
-  +#255#255#0#255#255#255#0#255#255#255#0#0#0#255'('#0#0#255#255#255#255#255#0
-  +#255#255#255#0#255#255#255#0#0#0#255'$'#0#0#255#175#0#0#255#236#0#0#255#255#0
-  +#0#255#255#0#0#255#249#0#0#255#203#0#0#255#204#0#0#255'x'#255#255#255#0#255
-  +#255#255#0#255#255#255#0'T'#0#0':U'#1#1#255'T'#0#0#255'T'#0#0#199#255#255#255
-  +#0#255#255#255#0#255#255#255#0#0#0#255'('#0#0#255#255#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'"'#0#0
-  +#255'4'#0#0#255#7#255#255#255#0#0#0#255#176#0#0#255'x'#255#255#255#0#255#255
-  +#255#0#255#255#255#0'T'#0#0#4'T'#0#0#243'T'#0#0#255'T'#0#0#254'T'#0#0#26#255
-  +#255#255#0#255#255#255#0#0#0#255'('#0#0#255#255#255#255#255#0#255#255#255#0
+  +#138#0#0#255#224'Z'#9#9#139'_'#16#16#255'T'#0#0#255'T'#0#0#207'T'#0#0#3#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255
+  +#183#0#0#255#153#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#5#0#0#255#8#0#0
+  +#255'<'#0#0#255#255'Z'#15#26#192#128'AA'#255'T'#0#0#255'T'#0#0#255'M'#0#21'H'
+  +#0#0#255#8#0#0#255#8#0#0#255#8#0#0#255#8#0#0#255#8#0#0#255#235#0#0#255'h'#255
+  ,#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#0#0#255#176#0#0#255#255#0#0#255#255#0#0
+  +#255#255'8'#0'U'#255#131'FF'#255'T'#0#0#255'T'#0#0#255'%'#0#144#255#0#0#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#235#0#0#255'h'
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#0#0#255#176#0#0#255'x'#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0'T'#0#0#160'T'#0#0#255'T'#0#0#255
-  +'T'#0#0'l'#255#255#255#0#255#255#255#0#0#0#255'('#0#0#255#255#255#255#255#0
+  +#255#255#0#255#255#255#0#255#255#255#0#0#0#255#176#0#0#255#141#0#0#255'.'#0#0
+  +#255#251'@'#0'<'#190#130'EE'#255'T'#0#0#255'T'#0#0#255'H'#0'$'#145#0#0#255'('
+  +#0#0#255'('#0#0#255'('#0#0#255'I'#0#0#255#255#0#0#255#183#0#0#255#152#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#0#0#255#176#0#0#255'x'#0#0#255'5'#0#0#255#255'L'
+  +#0#23#132#130'DD'#255'T'#0#0#255'T'#0#0#255'T'#0#0#136#255#255#255#0#255#255
+  +#255#0#255#255#255#0#0#0#255'('#0#0#255#255#0#0#255#129#0#0#255#221#0#0#255#8
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#176#0#0#255'x'
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0'T'#0#0'!T'#0#0#250
-  +'T'#0#0#255'T'#0#0#190#255#255#255#0#255#255#255#0#0#0#255'('#0#0#255#255#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#176#0
-  +#0#255'x'#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255
-  +#0'T'#0#0#149'T'#0#0#255'T'#0#0#251'T'#0#0#15#255#255#255#0#0#0#255'('#0#0
+  +#255#255#0#255#255#255#0#0#0#255#176#0#0#255'x'#0#0#255#134#0#0#255#226'T'#0
+  +#0'D'#130'DD'#255'T'#0#0#255'T'#0#0#255'T'#0#0#145#255#255#255#0#255#255#255
+  +#0#255#255#255#0#0#0#255'('#0#0#255#255#0#0#255#21#0#0#255#234#0#0#255#141
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#0#0#255#176#0#0#255#146#0#0#255#251#0#0#255'_T'#0#0
+  +#9#129'CC'#250'U'#1#1#255'T'#0#0#255'T'#0#0#153#255#255#255#0#255#255#255#0
+  +#255#255#255#0#0#0#255'('#0#0#255#255#255#255#255#0#0#0#255'S'#0#0#255#253#0
+  +#0#255't'#0#0#255#2#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#0#0#255#193#0#0#255#238#0#0#255#179#255#255#255#0#255#255#255
+  +#0'm%%'#198'X'#6#6#255'T'#0#0#255'T'#0#0#161#255#255#255#0#255#255#255#0#255
+  +#255#255#0#0#0#255'('#0#0#255#255#255#255#255#0#255#255#255#0#0#0#255'l'#0#0
+  +#255#245#0#0#255#196#0#0#255'`'#0#0#255','#0#0#255#26#0#0#255'M'#0#0#255#146
+  +#0#0#255#254#0#0#255#212#0#0#255#19#255#255#255#0#255#255#255#0'U'#2#2'}Y'#8
+  +#8#255'T'#0#0#255'T'#0#0#169#255#255#255#0#255#255#255#0#255#255#255#0#0#0
+  +#255'('#0#0#255#255#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'$'#0#0
+  +#255#175#0#0#255#236#0#0#255#255#0#0#255#255#0#0#255#249#0#0#255#203#0#0#255
+  +#204#0#0#255'x'#255#255#255#0#255#255#255#0#255#255#255#0'T'#0#0':U'#1#1#255
+  +'T'#0#0#255'T'#0#0#199#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'('#0
+  +#0#255#255#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#0#0#255'"'#0#0#255'4'#0#0#255#7#255#255#255#0#0#0#255
+  +#176#0#0#255'x'#255#255#255#0#255#255#255#0#255#255#255#0'T'#0#0#4'T'#0#0#243
+  +'T'#0#0#255'T'#0#0#254'T'#0#0#26#255#255#255#0#255#255#255#0#0#0#255'('#0#0
   +#255#255#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255
   +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0
-  +#255#176#0#0#255#243#0#0#255#232#0#0#255#232#0#0#255#232#0#0#255#232#0#0#255
-  +#232#9#0#228#234'Q'#0#8#254'T'#0#0#255#11#0#221#235#0#0#255#232#0#0#255#235#0
-  +#0#255#255#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
-  +#0#0#255'1'#0#0#255'H'#0#0#255'H'#0#0#255'H'#0#0#255'H'#0#0#255'H'#0#0#255'H'
-  +#0#0#255'H5'#0'^'#132'L'#0#23#208#3#0#245'J'#0#0#255'H'#0#0#255'H'#0#0#255'H'
-  +#10'GroupIndex'#2','#9'NumGlyphs'#2#0#7'OnClick'#7#11'PenBtnClick'#0#0#12'TS'
-  +'peedButton'#9'Fill3DBtn'#4'Left'#2'x'#6'Height'#2#30#4'Hint'#6'(Create VOI '
-  +'based on background intensity'#3'Top'#2#0#5'Width'#2#30#10'AllowAllUp'#9#10
-  +'Glyph.Data'#10#218#8#0#0#214#8#0#0'BM'#214#8#0#0#0#0#0#0'6'#0#0#0'('#0#0#0
-  +#24#0#0#0#23#0#0#0#1#0' '#0#0#0#0#0#160#8#0#0'd'#0#0#0'd'#0#0#0#0#0#0#0#0#0#0
-  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#0#0#255#28#0#0#255'Q'#0#0#255#131#0#0#255#181#0#0
-  ,#255#231#0#0#255#231#0#0#255#181#0#0#255#131#0#0#255'Q'#2#4#255#28#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#176#0#0#255'x'#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +'T'#0#0#160'T'#0#0#255'T'#0#0#255'T'#0#0'l'#255#255#255#0#255#255#255#0#0#0
+  +#255'('#0#0#255#255#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
   +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#0#0#255#11#0#0#255#141#0#0#255#252#0#0#255#255#0#0#255#255#0#0#255
-  +#255#0#0#255#255#0#0#255#255#0#0#255#255#1#2#255#255#10#17#255#255#18#28#255
-  +#252#23'%'#255#141#26'*'#255#11#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#0#0#255#176#0#0#255'x'#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0'T'#0#0'!T'#0#0#250'T'#0#0#255'T'#0#0#190#255#255#255#0#255#255
+  +#255#0#0#0#255'('#0#0#255#255#255#255#255#0#255#255#255#0#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#0#0#255'F'#0#0#255#223#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
-  +#0#0#255#255#0#0#255#255#0#0#255#255#3#5#255#255#14#23#255#255#24''''#255#255
-  +'!4'#255#255'''>'#255#255'+D'#255#223'+E'#255'F'#255#255#255#0#255#255#255#0
-  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0
-  +#255#135#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
-  +#255#0#0#255#255#0#0#255#255#0#0#255#255#13#21#255#255#26')'#255#255'%<'#255
-  +#255'/K'#255#255'7W'#255#255';_'#255#255'<`'#255#255'9['#255#135#255#255#255
-  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'J'#0#0#255
-  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
-  +#0#0#255#255#0#0#255#255#8#12#255#255#22'#'#255#255'$9'#255#255'1N'#255#255
-  +'=`'#255#255'Fp'#255#255'Ly'#255#255'Mz'#255#255'It'#255#255'Ag'#255'J'#255
-  +#255#255#0#255#255#255#0#255#255#255#0#0#0#255#22#0#0#255#233#0#0#255#255#0#0
-  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
-  +#255#0#0#255#255#13#22#255#255#29'.'#255#255',F'#255#255':]'#255#255'Hr'#255
-  +#255'T'#133#255#255'\'#147#255#255'^'#149#255#255'X'#140#255#255'M{'#255#233
-  +'@f'#255#22#255#255#255#0#255#255#255#0#0#0#255#180#0#0#255#255#0#0#255#255#0
-  +#0#218#255#0#0#185#255#0#0#160#255#0#0#184#255#0#0#222#255#0#0#253#255#0#0
-  +#255#255#1#2#255#255#17#27#253#255#25''''#191#255'%:'#191#255'0L'#191#255'<_'
-  +#191#255'Fp'#191#255'V'#136#204#255'd'#159#231#255'd'#158#254#255'V'#137#255
-  +#255'Gq'#255#180#255#255#255#0#0#0#255'*'#0#0#255#255#0#0#224#255#0#0'E'#255
-  +#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0'9'#255#0#0#222#255#2#3
-  +#255#255#17#28#245#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0
-  +#0#255#0#0#0#255#14#23'#'#255'4S'#150#255'It'#255#255'9Z'#255'*'#0#0#255'`'#0
-  +#0#254#255#0#0'='#255#0#0#0#255#0#0#0#255#0#0'{'#255#0#0#236#255#0#0#141#255
-  +#0#0#0#255#0#0#0#255#0#0'3'#255#0#1#255#255#15#25#245#255#0#0#0#255#0#0#0#255
-  +#0#0#0#255#17#28'9'#255#31'2V'#255#21'!3'#255#0#0#0#255#0#0#0#255#0#0#0#255
-  +'%<'#138#255'6V'#255'`'#0#0#255#150#0#0#255#255#0#0#253#255#0#0#231#255#0#0
-  +#205#255#0#0#250#255#0#0#255#255#0#0#222#255#0#0#0#255#0#0#0#255#0#0#1#255#0
-  +#0#242#255#12#19#245#255#0#0#0#255#0#0#0#255#0#0#0#255'*B'#154#255'Q'#128#255
-  +#255'X'#140#255#255'%:h'#255#0#0#0#255#0#0#0#255#5#7#19#255'0L'#255#150#0#0
-  +#255#203#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#187#255#0#0'k'
-  +#255#0#0''''#255#0#0#0#255#0#0#0#255#0#0'j'#255#0#0#255#255#6#10#245#255#0#0
-  +#0#255#0#0#0#255#0#0#0#255'"7'#154#255'Bj'#255#255'Hr'#255#255'1N'#171#255#0
-  +#0#0#255#0#0#0#255#0#0#0#255'!5'#217#209#0#0#255#242#0#0#255#255#0#0#255#255
-  +#0#0#255#255#0#0#255#255#0#0#170#255#0#0#3#255#0#0#0#255#0#0#0#255#0#0'~'#255
-  +#0#0#255#255#0#0#255#255#0#0#245#255#0#0#0#255#0#0#0#255#0#0#0#255#27'*'#154
-  +#255'3Q'#255#255'7X'#255#255#31'1'#139#255#0#0#0#255#0#0#0#255#0#0#0#255#25
-  +''''#226#243#0#0#255#200#0#0#255#255#0#0#248#255#0#0#217#255#0#0#184#255#0#0
-  +#246#255#0#0#236#255#0#0'>'#255#0#0#0#255#0#0#0#255#0#0#174#255#0#0#255#255#0
-  +#0#245#255#0#0#0#255#0#0#0#255#0#0#0#255#18#28#154#255'#8'#255#255'!5'#217
-  +#255#8#12'2'#255#0#0#0#255#0#0#0#255#3#5#30#255#15#25#255#200#0#0#255#146#0#0
-  +#255#255#0#0#133#255#0#0#0#255#0#0#0#255#0#0']'#255#0#0#173#255#0#0'/'#255#0
-  +#0#0#255#0#0#0#255#0#0#188#255#0#0#255#255#0#0#245#255#0#0#0#255#0#0#0#255#0
-  +#0#0#255#1#2#24#255#2#3#22#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#2#255#7#11
-  +#180#255#2#3#255#146#0#0#255'\'#0#0#255#255#0#0#255#255#0#0'{'#255#0#0#15#255
-  +#0#0#0#255#0#0#0#255#0#0#0#255#0#0#15#255#0#0'}'#255#0#0#255#255#0#0#255#255
-  +#0#0#245#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#3#255#1#1
-  +#31#255#1#2'N'#255#0#1#206#255#0#0#255#255#0#0#255'\'#0#0#255'%'#0#0#255#255
-  +#0#7#255#255#0#15#255#255#0#16#250#255#0#14#225#255#0#11#213#255#0#5#230#255
-  +#0#0#251#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#239#255#0#0
-  +#239#255#0#0#239#255#0#0#239#255#0#0#239#255#0#0#251#255#0#0#255#255#0#0#255
-  +#255#0#0#255#255#0#0#255#255#0#0#255'%'#255#255#255#0#0#28#255#181#0#29#255
-  +#255#0#29#255#255#0#28#255#255#0#28#255#255#0#27#255#255#0#27#255#255#0#23
-  +#255#255#0#10#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
-  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
-  +#0#0#255#255#0#0#255#164#255#255#255#0#255#255#255#0#0'2'#255#23#0'&'#255#232
-  +#0'#'#255#255#0'#'#255#255#0'"'#255#255#0'!'#255#255#0' '#255#255#0' '#255
-  ,#255#0#31#255#255#0#23#255#255#0#4#255#255#0#0#255#255#0#0#255#255#0#0#255
-  +#255#0#0#255#255#0#0#255#255#0#1#255#255#0#7#255#255#0#14#255#255#0#18#255
-  +#255#0#20#255#230#0'!'#255#22#255#255#255#0#255#255#255#0#255#255#255#0#0'4'
-  +#255'U'#0'+'#255#253#0'*'#255#255#0')'#255#255#0'('#255#255#0''''#255#255#0
-  +'&'#255#255#0'%'#255#255#0'%'#255#255#0'#'#255#255#0#16#255#255#0#8#255#255#0
-  +#11#255#255#0#14#255#255#0#22#255#255#0#30#255#255#0#31#255#255#0#30#255#255
-  +#0#30#255#253#0' '#255'O'#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#0','#255#136#0'1'#255#253#0'0'#255#255#0'/'#255#255#0'.'
-  +#255#255#0'.'#255#255#0','#255#255#0','#255#255#0'+'#255#255#0'*'#255#255#0
-  +'*'#255#255#0'('#255#255#0'('#255#255#0''''#255#255#0'&'#255#255#0'%'#255#255
-  +#0'%'#255#253#0'"'#255#135#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0'A'#255'J'#0'='#255#222#0
-  +'7'#255#255#0'6'#255#255#0'5'#255#255#0'5'#255#255#0'3'#255#255#0'2'#255#255
-  +#0'2'#255#255#0'1'#255#255#0'0'#255#255#0'/'#255#255#0'.'#255#255#0'.'#255
-  +#255#0'0'#255#221#0'1'#255'G'#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#0#255#255#255#0#0#0#255#176#0#0#255'x'#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0'T'#0#0#149'T'#0#0#255'T'#0#0#251'T'#0
+  +#0#15#255#255#255#0#0#0#255'('#0#0#255#255#255#255#255#0#255#255#255#0#255
   +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
-  +#255#0#0#147#255#17#0'B'#255#147#0'>'#255#249#0'='#255#255#0'<'#255#255#0';'
-  +#255#255#0';'#255#255#0':'#255#255#0'8'#255#255#0'8'#255#255#0'7'#255#255#0
-  +'5'#255#249#0':'#255#146#0'{'#255#14#255#255#255#0#255#255#255#0#255#255#255
-  +#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0'U'#255#18#0'['#255'['
-  +#0'O'#255#142#0'J'#255#185#0'F'#255#223#0'F'#255#223#0'H'#255#186#0'L'#255
-  +#142#0'Q'#255'Y'#0'E'#255#16#255#255#255#0#255#255#255#0#255#255#255#0#255
-  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#10'GroupIndex'#2','#9'N'
-  +'umGlyphs'#2#0#7'OnClick'#7#14'Fill3DBtnClick'#0#0#0#0#6'TPanel'#8'MagPanel'
-  +#4'Left'#2#0#6'Height'#2#18#3'Top'#3#195#1#5'Width'#3#1#4#5'Align'#7#8'alBot'
-  +'tom'#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#2#18#11'ClientWidth'#3#1#4
-  +#8'TabOrder'#2#1#0#6'TLabel'#11'StatusLabel'#4'Left'#2#2#6'Height'#2#18#3'To'
-  +'p'#2#2#5'Width'#3#134#0#7'Caption'#6#20'  No Images Loaded  '#11'ParentColo'
-  +'r'#8#0#0#12'TProgressBar'#12'ProgressBar1'#4'Left'#3'k'#3#6'Height'#2#18#3
-  +'Top'#2#0#5'Width'#3#150#0#5'Align'#7#7'alRight'#7'Anchors'#11#7'akRight'#8
-  +'akBottom'#0#11'BorderWidth'#2#1#8'TabOrder'#2#0#0#0#0#6'TPanel'#6'Panel1'#4
-  +'Left'#2#0#6'Height'#3#155#1#3'Top'#2'('#5'Width'#3#1#4#5'Align'#7#8'alClien'
-  +'t'#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#3#155#1#11'ClientWidth'#3#1#4
-  +#8'TabOrder'#2#2#0#10'TScrollBox'#11'TriplePanel'#3'Tag'#3#154#2#4'Left'#2#0
-  +#6'Height'#3#155#1#3'Top'#2#0#5'Width'#3#1#4#18'HorzScrollBar.Page'#3#1#4#18
-  +'VertScrollBar.Page'#3#155#1#5'Align'#7#8'alClient'#12'ClientHeight'#3#155#1
-  +#11'ClientWidth'#3#1#4#20'Constraints.MinWidth'#2#5#5'Color'#7#7'clBlack'#11
+  +#255#0#255#255#255#0#255#255#255#0#0#0#255#176#0#0#255#243#0#0#255#232#0#0
+  +#255#232#0#0#255#232#0#0#255#232#0#0#255#232#9#0#228#234'Q'#0#8#254'T'#0#0
+  +#255#11#0#221#235#0#0#255#232#0#0#255#235#0#0#255#255#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255'1'#0#0#255'H'#0#0#255'H'#0
+  +#0#255'H'#0#0#255'H'#0#0#255'H'#0#0#255'H'#0#0#255'H5'#0'^'#132'L'#0#23#208#3
+  +#0#245'J'#0#0#255'H'#0#0#255'H'#0#0#255'H'#10'GroupIndex'#2','#7'OnClick'#7
+  +#11'PenBtnClick'#0#0#12'TSpeedButton'#9'Fill3DBtn'#4'Left'#2'x'#6'Height'#2
+  +#30#4'Hint'#6'(Create VOI based on background intensity'#3'Top'#2#0#5'Width'
+  +#2#30#10'AllowAllUp'#9#10'Glyph.Data'#10#218#8#0#0#214#8#0#0'BM'#214#8#0#0#0
+  +#0#0#0'6'#0#0#0'('#0#0#0#24#0#0#0#23#0#0#0#1#0' '#0#0#0#0#0#160#8#0#0'd'#0#0
+  +#0'd'#0#0#0#0#0#0#0#0#0#0#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#28#0#0#255'Q'#0#0
+  +#255#131#0#0#255#181#0#0#255#231#0#0#255#231#0#0#255#181#0#0#255#131#0#0#255
+  +'Q'#2#4#255#28#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  ,#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#0#0#255#11#0#0#255#141#0#0#255#252#0#0#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#1#2#255#255
+  +#10#17#255#255#18#28#255#252#23'%'#255#141#26'*'#255#11#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#0#0#255'F'#0#0#255#223#0#0#255#255#0#0#255#255#0
+  +#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#3#5#255#255#14#23
+  +#255#255#24''''#255#255'!4'#255#255'''>'#255#255'+D'#255#223'+E'#255'F'#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#0#0#255#135#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#13#21#255
+  +#255#26')'#255#255'%<'#255#255'/K'#255#255'7W'#255#255';_'#255#255'<`'#255
+  +#255'9['#255#135#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#0#0#255'J'#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#8#12#255#255#22'#'#255
+  +#255'$9'#255#255'1N'#255#255'=`'#255#255'Fp'#255#255'Ly'#255#255'Mz'#255#255
+  +'It'#255#255'Ag'#255'J'#255#255#255#0#255#255#255#0#255#255#255#0#0#0#255#22
+  +#0#0#255#233#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
+  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#13#22#255#255#29'.'#255#255',F'
+  +#255#255':]'#255#255'Hr'#255#255'T'#133#255#255'\'#147#255#255'^'#149#255#255
+  +'X'#140#255#255'M{'#255#233'@f'#255#22#255#255#255#0#255#255#255#0#0#0#255
+  +#180#0#0#255#255#0#0#255#255#0#0#218#255#0#0#185#255#0#0#160#255#0#0#184#255
+  +#0#0#222#255#0#0#253#255#0#0#255#255#1#2#255#255#17#27#253#255#25''''#191#255
+  +'%:'#191#255'0L'#191#255'<_'#191#255'Fp'#191#255'V'#136#204#255'd'#159#231
+  +#255'd'#158#254#255'V'#137#255#255'Gq'#255#180#255#255#255#0#0#0#255'*'#0#0
+  +#255#255#0#0#224#255#0#0'E'#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0
+  +#255#0#0'9'#255#0#0#222#255#2#3#255#255#17#28#245#255#0#0#0#255#0#0#0#255#0#0
+  +#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#14#23'#'#255'4S'#150#255'It'
+  +#255#255'9Z'#255'*'#0#0#255'`'#0#0#254#255#0#0'='#255#0#0#0#255#0#0#0#255#0#0
+  +'{'#255#0#0#236#255#0#0#141#255#0#0#0#255#0#0#0#255#0#0'3'#255#0#1#255#255#15
+  +#25#245#255#0#0#0#255#0#0#0#255#0#0#0#255#17#28'9'#255#31'2V'#255#21'!3'#255
+  +#0#0#0#255#0#0#0#255#0#0#0#255'%<'#138#255'6V'#255'`'#0#0#255#150#0#0#255#255
+  +#0#0#253#255#0#0#231#255#0#0#205#255#0#0#250#255#0#0#255#255#0#0#222#255#0#0
+  +#0#255#0#0#0#255#0#0#1#255#0#0#242#255#12#19#245#255#0#0#0#255#0#0#0#255#0#0
+  +#0#255'*B'#154#255'Q'#128#255#255'X'#140#255#255'%:h'#255#0#0#0#255#0#0#0#255
+  +#5#7#19#255'0L'#255#150#0#0#255#203#0#0#255#255#0#0#255#255#0#0#255#255#0#0
+  +#255#255#0#0#187#255#0#0'k'#255#0#0''''#255#0#0#0#255#0#0#0#255#0#0'j'#255#0
+  +#0#255#255#6#10#245#255#0#0#0#255#0#0#0#255#0#0#0#255'"7'#154#255'Bj'#255#255
+  +'Hr'#255#255'1N'#171#255#0#0#0#255#0#0#0#255#0#0#0#255'!5'#217#209#0#0#255
+  +#242#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#170#255#0#0#3#255#0
+  +#0#0#255#0#0#0#255#0#0'~'#255#0#0#255#255#0#0#255#255#0#0#245#255#0#0#0#255#0
+  +#0#0#255#0#0#0#255#27'*'#154#255'3Q'#255#255'7X'#255#255#31'1'#139#255#0#0#0
+  +#255#0#0#0#255#0#0#0#255#25''''#226#243#0#0#255#200#0#0#255#255#0#0#248#255#0
+  +#0#217#255#0#0#184#255#0#0#246#255#0#0#236#255#0#0'>'#255#0#0#0#255#0#0#0#255
+  +#0#0#174#255#0#0#255#255#0#0#245#255#0#0#0#255#0#0#0#255#0#0#0#255#18#28#154
+  +#255'#8'#255#255'!5'#217#255#8#12'2'#255#0#0#0#255#0#0#0#255#3#5#30#255#15#25
+  +#255#200#0#0#255#146#0#0#255#255#0#0#133#255#0#0#0#255#0#0#0#255#0#0']'#255#0
+  +#0#173#255#0#0'/'#255#0#0#0#255#0#0#0#255#0#0#188#255#0#0#255#255#0#0#245#255
+  +#0#0#0#255#0#0#0#255#0#0#0#255#1#2#24#255#2#3#22#255#0#0#0#255#0#0#0#255#0#0
+  +#0#255#0#0#2#255#7#11#180#255#2#3#255#146#0#0#255'\'#0#0#255#255#0#0#255#255
+  +#0#0'{'#255#0#0#15#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#15#255#0#0'}'#255#0
+  +#0#255#255#0#0#255#255#0#0#245#255#0#0#0#255#0#0#0#255#0#0#0#255#0#0#0#255#0
+  +#0#0#255#0#0#3#255#1#1#31#255#1#2'N'#255#0#1#206#255#0#0#255#255#0#0#255'\'#0
+  +#0#255'%'#0#0#255#255#0#7#255#255#0#15#255#255#0#16#250#255#0#14#225#255#0#11
+  +#213#255#0#5#230#255#0#0#251#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
+  +#255#0#0#239#255#0#0#239#255#0#0#239#255#0#0#239#255#0#0#239#255#0#0#251#255
+  +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255'%'#255#255#255#0#0
+  +#28#255#181#0#29#255#255#0#29#255#255#0#28#255#255#0#28#255#255#0#27#255#255
+  +#0#27#255#255#0#23#255#255#0#10#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0
+  +#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
+  +#255#255#0#0#255#255#0#0#255#255#0#0#255#164#255#255#255#0#255#255#255#0#0'2'
+  +#255#23#0'&'#255#232#0'#'#255#255#0'#'#255#255#0'"'#255#255#0'!'#255#255#0' '
+  +#255#255#0' '#255#255#0#31#255#255#0#23#255#255#0#4#255#255#0#0#255#255#0#0
+  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#1#255#255#0#7#255#255#0#14#255
+  ,#255#0#18#255#255#0#20#255#230#0'!'#255#22#255#255#255#0#255#255#255#0#255
+  +#255#255#0#0'4'#255'U'#0'+'#255#253#0'*'#255#255#0')'#255#255#0'('#255#255#0
+  +''''#255#255#0'&'#255#255#0'%'#255#255#0'%'#255#255#0'#'#255#255#0#16#255#255
+  +#0#8#255#255#0#11#255#255#0#14#255#255#0#22#255#255#0#30#255#255#0#31#255#255
+  +#0#30#255#255#0#30#255#253#0' '#255'O'#255#255#255#0#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#0','#255#136#0'1'#255#253#0'0'#255#255#0
+  +'/'#255#255#0'.'#255#255#0'.'#255#255#0','#255#255#0','#255#255#0'+'#255#255
+  +#0'*'#255#255#0'*'#255#255#0'('#255#255#0'('#255#255#0''''#255#255#0'&'#255
+  +#255#0'%'#255#255#0'%'#255#253#0'"'#255#135#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0'A'#255
+  +'J'#0'='#255#222#0'7'#255#255#0'6'#255#255#0'5'#255#255#0'5'#255#255#0'3'#255
+  +#255#0'2'#255#255#0'2'#255#255#0'1'#255#255#0'0'#255#255#0'/'#255#255#0'.'
+  +#255#255#0'.'#255#255#0'0'#255#221#0'1'#255'G'#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#0#147#255#17#0'B'#255#147#0'>'#255#249#0'='#255#255
+  +#0'<'#255#255#0';'#255#255#0';'#255#255#0':'#255#255#0'8'#255#255#0'8'#255
+  +#255#0'7'#255#255#0'5'#255#249#0':'#255#146#0'{'#255#14#255#255#255#0#255#255
+  +#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0
+  +#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#0'U'
+  +#255#18#0'['#255'['#0'O'#255#142#0'J'#255#185#0'F'#255#223#0'F'#255#223#0'H'
+  +#255#186#0'L'#255#142#0'Q'#255'Y'#0'E'#255#16#255#255#255#0#255#255#255#0#255
+  +#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#255#255#255#0#10'GroupI'
+  +'ndex'#2','#7'OnClick'#7#14'Fill3DBtnClick'#0#0#0#0#6'TPanel'#8'MagPanel'#4
+  +'Left'#2#0#6'Height'#2#18#3'Top'#3#195#1#5'Width'#3#1#4#5'Align'#7#8'alBotto'
+  +'m'#10'BevelOuter'#7#6'bvNone'#12'ClientHeight'#2#18#11'ClientWidth'#3#1#4#8
+  +'TabOrder'#2#1#0#6'TLabel'#11'StatusLabel'#4'Left'#2#2#6'Height'#2#17#3'Top'
+  +#2#2#5'Width'#3#133#0#7'Caption'#6#20'  No Images Loaded  '#11'ParentColor'#8
+  +#0#0#12'TProgressBar'#12'ProgressBar1'#4'Left'#3'k'#3#6'Height'#2#18#3'Top'#2
+  +#0#5'Width'#3#150#0#5'Align'#7#7'alRight'#7'Anchors'#11#7'akRight'#8'akBotto'
+  +'m'#0#11'BorderWidth'#2#1#8'TabOrder'#2#0#0#0#0#6'TPanel'#6'Panel1'#4'Left'#2
+  +#0#6'Height'#3#155#1#3'Top'#2'('#5'Width'#3#1#4#5'Align'#7#8'alClient'#10'Be'
+  +'velOuter'#7#6'bvNone'#12'ClientHeight'#3#155#1#11'ClientWidth'#3#1#4#8'TabO'
+  +'rder'#2#2#0#10'TScrollBox'#11'TriplePanel'#3'Tag'#3#154#2#4'Left'#2#0#6'Hei'
+  +'ght'#3#155#1#3'Top'#2#0#5'Width'#3#1#4#18'HorzScrollBar.Page'#3#7#3#18'Vert'
+  +'ScrollBar.Page'#3#250#0#5'Align'#7#8'alClient'#12'ClientHeight'#3#140#1#11
+  +'ClientWidth'#3#242#3#20'Constraints.MinWidth'#2#5#5'Color'#7#7'clBlack'#11
   +'ParentColor'#8#8'TabOrder'#2#0#7'OnClick'#7#13'ImgPanelClick'#0#6'TImage'#10
   +'PGImageCor'#3'Tag'#2#2#6'Cursor'#7#7'crCross'#4'Left'#2#1#6'Height'#2#12#3
   +'Top'#2#1#5'Width'#2#12#8'AutoSize'#9#10'OnDblClick'#7#18'PGImageCorDblClick'
@@ -897,9 +895,9 @@ LazarusResources.Add('TImgForm','FORMDATA',[
   +'&Edit'#0#9'TMenuItem'#5'Copy1'#7'Caption'#6#4'Copy'#8'ShortCut'#3'C@'#7'OnC'
   +'lick'#7#10'Copy1Click'#0#0#9'TMenuItem'#6'Paste1'#7'Caption'#6#5'Paste'#8'S'
   +'hortCut'#3'V@'#7'OnClick'#7#11'Paste1Click'#0#0#9'TMenuItem'#5'Undo1'#7'Cap'
-  ,'tion'#6#4'Undo'#8'ShortCut'#3'Z@'#7'OnClick'#7#10'Undo1Click'#0#0#0#9'TMenu'
+  +'tion'#6#4'Undo'#8'ShortCut'#3'Z@'#7'OnClick'#7#10'Undo1Click'#0#0#0#9'TMenu'
   +'Item'#11'OverlayMenu'#7'Caption'#6#8'&Overlay'#0#9'TMenuItem'#11'OverlayOpe'
-  +'n'#7'Caption'#6#3'Add'#8'ShortCut'#3'A@'#7'OnClick'#7#16'OverlayOpenClick'#0
+  ,'n'#7'Caption'#6#3'Add'#8'ShortCut'#3'A@'#7'OnClick'#7#16'OverlayOpenClick'#0
   +#0#9'TMenuItem'#15'CloseOverlayImg'#7'Caption'#6#14'Close overlays'#7'OnClic'
   +'k'#7#20'CloseOverlayImgClick'#0#0#9'TMenuItem'#14'BGTransPctMenu'#7'Caption'
   +#6#26'Transparency on background'#0#9'TMenuItem'#8'BGtrans0'#7'Caption'#6#9
@@ -961,9 +959,9 @@ LazarusResources.Add('TImgForm','FORMDATA',[
   +'ate overlap images'#7'OnClick'#7#13'CreateOverlap'#0#0#9'TMenuItem'#10'Chis'
   +'quare1'#7'Caption'#6#17'Subtraction Plots'#7'OnClick'#7#15'Chisquare1Click'
   +#0#0#9'TMenuItem'#13'BatchROImean1'#7'Caption'#6#18'Batch descriptives'#7'On'
-  ,'Click'#7#18'BatchROImean1Click'#0#0#9'TMenuItem'#14'Batchprobmaps1'#7'Capti'
+  +'Click'#7#18'BatchROImean1Click'#0#0#9'TMenuItem'#14'Batchprobmaps1'#7'Capti'
   +'on'#6#15'Batch prob maps'#7'OnClick'#7#19'Batchprobmaps1Click'#0#0#9'TMenuI'
-  +'tem/Batchclusterprobmaps1Batchclusterprobmaps1Click'#7'Caption'#6#23'Batch '
+  ,'tem/Batchclusterprobmaps1Batchclusterprobmaps1Click'#7'Caption'#6#23'Batch '
   +'cluster prob maps'#7'OnClick'#7'4Batchclusterprobmaps1Batchclusterprobmaps1'
   +'ClickClick'#0#0#0#9'TMenuItem'#8'Convert1'#7'Caption'#6#7'Convert'#0#9'TMen'
   +'uItem'#7'ROIVOI1'#7'Caption'#6#10'ROI -> VOI'#7'OnClick'#7#12'ROIVOI1Click'
@@ -1025,9 +1023,9 @@ LazarusResources.Add('TImgForm','FORMDATA',[
   +#12'Quicksmooth1'#7'Caption'#6#20'3D Smooth background'#7'OnClick'#7#17'Quic'
   +'ksmooth1Click'#0#0#9'TMenuItem'#17'OverlaySmoothMenu'#7'Caption'#6#18'3D Sm'
   +'ooth overlays'#7'OnClick'#7#22'OverlaySmoothMenuClick'#0#0#9'TMenuItem'#12
-  ,'Menu2DSmooth'#7'Caption'#6#13'2D Smooth all'#7'Checked'#9#7'OnClick'#7#17'M'
+  +'Menu2DSmooth'#7'Caption'#6#13'2D Smooth all'#7'Checked'#9#7'OnClick'#7#17'M'
   +'enu2DSmoothClick'#0#0#9'TMenuItem'#2'N4'#7'Caption'#6#1'-'#0#0#9'TMenuItem'
-  +#10'FlipLRmenu'#7'Caption'#6#8'Flip L/R'#7'OnClick'#7#15'FlipLRmenuClick'#0#0
+  ,#10'FlipLRmenu'#7'Caption'#6#8'Flip L/R'#7'OnClick'#7#15'FlipLRmenuClick'#0#0
   +#9'TMenuItem'#8'YokeMenu'#7'Caption'#6#4'Yoke'#8'ShortCut'#3'Y@'#7'OnClick'#7
   +#13'YokeMenuClick'#0#0#9'TMenuItem'#2'N2'#7'Caption'#6#1'-'#0#0#9'TMenuItem'
   +#15'MagnifyMenuItem'#7'Caption'#6#7'Magnify'#7'OnClick'#7#20'MagnifyMenuItem'
diff --git a/nifti_img_view.pas b/nifti_img_view.pas
index 7634ab9..414a12a 100755
--- a/nifti_img_view.pas
+++ b/nifti_img_view.pas
@@ -19,8 +19,8 @@ yokesharemem,
 LResources, fx8, cpucount, SysUtils, Classes, Graphics, Controls, Forms,
 Dialogs, Menus, ComCtrls, ExtCtrls, StdCtrls, GraphicsMathLibrary, ClipBrd,
 define_types, Spin, Buttons, nifti_hdr, nifti_hdr_view, nifti_img, voismooth,
-IniFiles, ReadInt, registry,  stat, Distr, bet, mni, prefs, CropEdges,nifti_types,
-userdir, graphx, GraphType, IntfGraphics, landmarks,fastsmooth, nii_label;
+IniFiles, ReadInt,  stat, Distr, bet, mni, prefs, CropEdges,nifti_types,
+userdir, graphx, GraphType, IntfGraphics, landmarks,fastsmooth, nii_label;//registry
 
 
 type
@@ -626,7 +626,7 @@ begin
 
   lIniFile.Free;
 end;
-
+(*
 function registerfiletype(inft,inkey,desc,icon:string): boolean;
 var myreg : treginifile;
 	ct : integer;
@@ -655,7 +655,7 @@ begin
 		   showmessage('Only administrators can change file associations. You are currently logged in as a restricted user.');
 	 end;
 	 myreg.free;
-end;
+end;   *)
 
 procedure WriteIni2Form (lBGImg: TBGImg);
 begin
@@ -866,7 +866,6 @@ procedure TImgForm.FormDropFiles(Sender: TObject; const FileNames: array of Stri
 var
    lFilename: string;
 begin
-
   if length(FileNames) < 1 then
      exit;
   lFilename := Filenames[0];
@@ -1388,6 +1387,8 @@ var
    lVal: integer;
 begin
 	 Result := false;
+         if (FSize(lFilename)) < 348 then exit; //to small to be a header or DICOM image
+
 	 if not HdrForm.OpenAndDisplayHdr(lFilename,gMRIcroOverlay[kBGOverlayNum]) then exit;
 
 
@@ -1769,7 +1770,7 @@ var
 	lPos: integer;
 begin
   lPos := lX + ((lY-1)*gBGImg.ScrnDim[1])+((lZ-1)*gBGImg.ScrnDim[1]*gBGImg.ScrnDim[2]);
-  ImgIntensity(lHdr,lPos);
+  result := ImgIntensity(lHdr,lPos);
 end;
 
 function TImgForm.ImgIntensityString(var lHdr: TMRIcroHdr; lVox: integer): string;  overload;
@@ -1982,12 +1983,18 @@ begin
    for lYpos := gSelectRect.Top to gSelectRect.Bottom do begin
 	   for lXpos := gSelectRect.Left to gSelectRect.Right do begin
 		   XYscrn2Img (lImage,lPanel,lXpos,lYPos, lXout,lYOut,lZOut);
-			lVal:= ImgIntensity(gMRIcroOverlay[lLayer],lXout,lYOut,lZOut);
+                  // lVox := lXout + ((lYout-1)*gBGImg.ScrnDim[1])+((lZout-1)*gBGImg.ScrnDim[1]*gBGImg.ScrnDim[2]);
+                  // lVal := ImgIntensity(gMRIcroOverlay[lLayer],lVox);
+		lVal:= ImgIntensity(gMRIcroOverlay[lLayer],lXout,lYOut,lZOut);
 			if lVal < lMinInten then lMinInten := lVal;
+
 			if lVal > lMaxInten then lMaxInten := lVal;
 	   end; //for PGX each column
    end; //for PGY2 - each row
-   ImgForm.StatusLabel.caption := 'Intensity range'+(RealToStr(lMinInten,4))+'..'+({x} RealToStr(lMaxInten,4));
+   //ImgForm.StatusLabel.caption := (RealToStr(lMinInten,4))+'..'+({x} RealToStr(lMaxInten,4))+'bexx'+ inttostr(lXout)+'x'+inttostr(lYOut)+'x'+inttostr(lZOut)+' '+inttostr(ActiveLayer);
+
+   //   ImgForm.StatusLabel.caption := 'bexx'+ inttostr(gSelectRect.Top)+'..'+inttostr(gSelectRect.Bottom)+' -> '+inttostr(gSelectRect.Left)+'..'+inttostr(gSelectRect.Right);
+  ImgForm.StatusLabel.caption := 'Intensity range '+(RealToStr(lMinInten,4))+'..'+({x} RealToStr(lMaxInten,4));
    if lMinInten = lMaxInten then exit; //no range
    ImgForm.MinWindowEdit.value  := lMinInten;
    ImgForm.MaxWindowEdit.value := lMaxInten;
@@ -3477,9 +3484,9 @@ begin
     if lCopy then begin
        {$IFDEF FPC}
        lOutImg.Picture.Bitmap.SaveToClipboardFormat(2);
-       {$ELSE}
-       Clipboard.Assign(lOutImg.Picture.Graphic);
+       //Clipboard.Assign(lOutImg.Picture.Bitmap);
        {$ENDIF}
+       Clipboard.Assign(lOutImg.Picture.Graphic);
     end else
         SaveImgAsPNGBMP (lOutImg);
   finally
@@ -4096,11 +4103,31 @@ begin
 	FreeMem(lBuffer);
 end; //procedure Chisquare1Click
 
+procedure Paris(lFilename: string);
+begin
+     ImgForm.CloseImagesClick(nil);
+
+     ImgForm.OpenAndDisplayImg(lFilename,True);
+  ImgForm.caption := 'x';
+  //if not HdrForm.OpenAndDisplayHdr(lFilename,gMRIcroOverlay[kBGOverlayNum]) then exit;
+  ImgForm.Caption := 'y';
+end;
+
+procedure Normandy;
+begin
+  gBGImg.Prompt4DVolume  := false;
+  gBGImg.Resliced :=true;
+       paris('/Users/rorden/downloads/fx/DBM8768/DBM8768_DIFFUSION AX PRE PERFUSION.nii.gz');
+     gBGImg.Prompt4DVolume  := true;
+end;
+
 procedure TImgForm.ROIVOI1Click(Sender: TObject);
 var
 	lNumberofFiles,lC: integer;
 	lFilename: string;
 begin
+  Normandy;
+  exit;
 	if gMRIcroOverlay[kBGOverlayNum].ScrnBufferItems < 1 then begin
 		showmessage('Please load a background image (''File''/''Open'') before adding an overlay.');
 		exit;
diff --git a/npm/npm.app/Contents/Info.plist b/npm/npm.app/Contents/Info.plist
old mode 100644
new mode 100755
diff --git a/npm/npm.app/Contents/MacOS/npm b/npm/npm.app/Contents/MacOS/npm
deleted file mode 120000
index 20acbf9..0000000
--- a/npm/npm.app/Contents/MacOS/npm
+++ /dev/null
@@ -1 +0,0 @@
-../../../npm
\ No newline at end of file
diff --git a/npm/npm.app/Contents/MacOS/npm b/npm/npm.app/Contents/MacOS/npm
new file mode 100755
index 0000000..20acbf9
--- /dev/null
+++ b/npm/npm.app/Contents/MacOS/npm
@@ -0,0 +1 @@
+../../../npm
\ No newline at end of file
diff --git a/npm/npm.app/Contents/PkgInfo b/npm/npm.app/Contents/PkgInfo
old mode 100644
new mode 100755
diff --git a/npm/npm.lpi b/npm/npm.lpi
index e244a9b..db3ae8b 100755
--- a/npm/npm.lpi
+++ b/npm/npm.lpi
@@ -53,7 +53,6 @@
         <HasResources Value="True"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="npmform"/>
-        <IsVisibleTab Value="True"/>
         <EditorIndex Value="1"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1046"/>
@@ -166,10 +165,13 @@
         <HasResources Value="True"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="spread"/>
+        <IsVisibleTab Value="True"/>
+        <EditorIndex Value="2"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="556"/>
-        <CursorPos X="1" Y="584"/>
+        <TopLine Value="547"/>
+        <CursorPos X="11" Y="557"/>
         <UsageCount Value="106"/>
+        <Loaded Value="True"/>
       </Unit13>
       <Unit14>
         <Filename Value="gzio2.pas"/>
@@ -355,7 +357,7 @@
       <Unit38>
         <Filename Value="regression.pas"/>
         <UnitName Value="regression"/>
-        <EditorIndex Value="5"/>
+        <EditorIndex Value="6"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="69" Y="13"/>
@@ -386,7 +388,7 @@
       <Unit42>
         <Filename Value="..\common\define_types.pas"/>
         <UnitName Value="define_types"/>
-        <EditorIndex Value="4"/>
+        <EditorIndex Value="5"/>
         <WindowIndex Value="0"/>
         <TopLine Value="8"/>
         <CursorPos X="57" Y="25"/>
@@ -522,7 +524,7 @@
       <Unit60>
         <Filename Value="unpm.pas"/>
         <UnitName Value="unpm"/>
-        <EditorIndex Value="3"/>
+        <EditorIndex Value="4"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="49" Y="8"/>
@@ -532,7 +534,7 @@
       <Unit61>
         <Filename Value="turbolesion.pas"/>
         <UnitName Value="turbolesion"/>
-        <EditorIndex Value="2"/>
+        <EditorIndex Value="3"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="63" Y="8"/>
@@ -640,79 +642,79 @@
       </Position11>
       <Position12>
         <Filename Value="npmform.pas"/>
-        <Caret Line="811" Column="50" TopLine="816"/>
+        <Caret Line="906" Column="26" TopLine="886"/>
       </Position12>
       <Position13>
         <Filename Value="npmform.pas"/>
-        <Caret Line="906" Column="26" TopLine="886"/>
+        <Caret Line="2" Column="127" TopLine="1"/>
       </Position13>
       <Position14>
         <Filename Value="npmform.pas"/>
-        <Caret Line="2" Column="127" TopLine="1"/>
+        <Caret Line="130" Column="21" TopLine="110"/>
       </Position14>
       <Position15>
         <Filename Value="npmform.pas"/>
-        <Caret Line="130" Column="21" TopLine="110"/>
+        <Caret Line="2" Column="129" TopLine="1"/>
       </Position15>
       <Position16>
         <Filename Value="npmform.pas"/>
-        <Caret Line="2" Column="129" TopLine="1"/>
+        <Caret Line="25" Column="18" TopLine="5"/>
       </Position16>
       <Position17>
         <Filename Value="npmform.pas"/>
-        <Caret Line="25" Column="18" TopLine="5"/>
+        <Caret Line="3" Column="130" TopLine="1"/>
       </Position17>
       <Position18>
         <Filename Value="npmform.pas"/>
-        <Caret Line="3" Column="130" TopLine="1"/>
+        <Caret Line="82" Column="17" TopLine="62"/>
       </Position18>
       <Position19>
         <Filename Value="npmform.pas"/>
-        <Caret Line="82" Column="17" TopLine="62"/>
+        <Caret Line="94" Column="15" TopLine="74"/>
       </Position19>
       <Position20>
         <Filename Value="npmform.pas"/>
-        <Caret Line="94" Column="15" TopLine="74"/>
+        <Caret Line="119" Column="25" TopLine="99"/>
       </Position20>
       <Position21>
         <Filename Value="npmform.pas"/>
-        <Caret Line="119" Column="25" TopLine="99"/>
+        <Caret Line="3" Column="129" TopLine="1"/>
       </Position21>
       <Position22>
         <Filename Value="npmform.pas"/>
-        <Caret Line="3" Column="129" TopLine="1"/>
+        <Caret Line="104" Column="30" TopLine="84"/>
       </Position22>
       <Position23>
         <Filename Value="npmform.pas"/>
-        <Caret Line="104" Column="30" TopLine="84"/>
+        <Caret Line="414" Column="49" TopLine="394"/>
       </Position23>
       <Position24>
         <Filename Value="npmform.pas"/>
-        <Caret Line="414" Column="49" TopLine="394"/>
+        <Caret Line="992" Column="7" TopLine="991"/>
       </Position24>
       <Position25>
         <Filename Value="npmform.pas"/>
-        <Caret Line="992" Column="7" TopLine="991"/>
+        <Caret Line="991" Column="7" TopLine="990"/>
       </Position25>
       <Position26>
         <Filename Value="npmform.pas"/>
-        <Caret Line="991" Column="7" TopLine="990"/>
+        <Caret Line="5" Column="105" TopLine="1"/>
       </Position26>
       <Position27>
         <Filename Value="npmform.pas"/>
-        <Caret Line="5" Column="105" TopLine="1"/>
+        <Caret Line="103" Column="7" TopLine="83"/>
       </Position27>
       <Position28>
         <Filename Value="npmform.pas"/>
-        <Caret Line="103" Column="7" TopLine="83"/>
+        <Caret Line="118" Column="32" TopLine="98"/>
       </Position28>
       <Position29>
         <Filename Value="npmform.pas"/>
-        <Caret Line="118" Column="32" TopLine="98"/>
+        <Caret Line="434" Column="8" TopLine="410"/>
       </Position29>
       <Position30>
-        <Filename Value="npmform.pas"/>
-        <Caret Line="434" Column="8" TopLine="410"/>
+        <Filename Value="spread.pas"/>
+        <Caret Line="584" Column="1" TopLine="555"/>
       </Position30>
     </JumpHistory>
   </ProjectOptions>
diff --git a/npm/spread.pas b/npm/spread.pas
index 0873ed9..05bc43b 100755
--- a/npm/spread.pas
+++ b/npm/spread.pas
@@ -9,8 +9,8 @@ Toolwin,shlobj,Spin,ShellApi,windows,messages,
 LResources,
 {$ENDIF}
    SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
-  Grids, Menus,  ComCtrls, Buttons,Clipbrd,design, StdCtrls,Registry,
-  define_types,valformat;
+  Grids, Menus,  ComCtrls, Buttons,Clipbrd,design, StdCtrls,
+  define_types,valformat;//Registry,
 
 type
 
@@ -528,7 +528,7 @@ begin
     DecimalSeparator :=lDecimalSep;
 end;
 
-
+(*
 procedure registerfiletype(inft,inkey,desc,icon:string);
 var myreg : treginifile;
     ct : integer;
@@ -554,7 +554,7 @@ begin
      finally
             myreg.free;
      end;
-end;
+end;    *)
 
 procedure TSpreadForm.FormCreate(Sender: TObject);
 begin
diff --git a/prefs.lfm b/prefs.lfm
index 8f9851a..de912f7 100755
--- a/prefs.lfm
+++ b/prefs.lfm
@@ -16,52 +16,52 @@ object PrefForm: TPrefForm
   OnCreate = FormCreate
   OnShow = FormShow
   Position = poScreenCenter
-  LCLVersion = '1.0.2.0'
+  LCLVersion = '1.0.12.0'
   object GroupBox1: TGroupBox
     Left = 8
     Height = 280
     Top = 8
     Width = 368
     Caption = 'Image Display'
-    ClientHeight = 262
-    ClientWidth = 364
+    ClientHeight = 258
+    ClientWidth = 360
     TabOrder = 0
     object Label1: TLabel
       Left = 120
-      Height = 14
+      Height = 17
       Top = 71
-      Width = 138
+      Width = 190
       Caption = 'Maximum Dimension [Voxels]'
       ParentColor = False
     end
     object Label2: TLabel
       Left = 120
-      Height = 14
+      Height = 17
       Top = 113
-      Width = 92
+      Width = 120
       Caption = 'Rendering Threads'
       ParentColor = False
     end
     object Label3: TLabel
       Left = 120
-      Height = 14
+      Height = 17
       Top = 145
-      Width = 119
+      Width = 161
       Caption = 'Decimal places Displayed'
       ParentColor = False
     end
     object ResliceCheck: TCheckBox
       Left = 15
-      Height = 17
+      Height = 18
       Top = 9
-      Width = 163
+      Width = 210
       Caption = 'Reorient images when loading'
       OnClick = ResliceCheckClick
       TabOrder = 0
     end
     object MaxDimEdit: TSpinEdit
       Left = 14
-      Height = 21
+      Height = 16
       Top = 64
       Width = 100
       MaxValue = 4096
@@ -71,7 +71,7 @@ object PrefForm: TPrefForm
     end
     object ThreadEdit: TSpinEdit
       Left = 14
-      Height = 21
+      Height = 16
       Top = 101
       Width = 100
       MaxValue = 4096
@@ -81,7 +81,7 @@ object PrefForm: TPrefForm
     end
     object SigDigEdit: TSpinEdit
       Left = 14
-      Height = 21
+      Height = 16
       Top = 138
       Width = 100
       MaxValue = 32
@@ -89,18 +89,17 @@ object PrefForm: TPrefForm
     end
     object OrthoCheck: TCheckBox
       Left = 43
-      Height = 17
+      Height = 18
       Top = 37
-      Width = 190
+      Width = 240
       Caption = 'Rotate to nearest orthogonal angle'
       TabOrder = 4
-      Visible = False
     end
     object SingleRowCheck: TCheckBox
       Left = 15
-      Height = 17
+      Height = 18
       Top = 208
-      Width = 134
+      Width = 174
       Caption = 'All slices on a single row'
       TabOrder = 5
     end
@@ -111,14 +110,14 @@ object PrefForm: TPrefForm
     Top = 296
     Width = 368
     Caption = 'Drawing'
-    ClientHeight = 46
-    ClientWidth = 364
+    ClientHeight = 42
+    ClientWidth = 360
     TabOrder = 1
     object ThinPenCheck: TCheckBox
       Left = 15
-      Height = 17
+      Height = 18
       Top = 16
-      Width = 61
+      Width = 75
       Caption = 'Thin Pen'
       TabOrder = 0
     end
diff --git a/prefs.lrs b/prefs.lrs
index 4d6541b..b1e17f7 100755
--- a/prefs.lrs
+++ b/prefs.lrs
@@ -7,37 +7,37 @@ LazarusResources.Add('TPrefForm','FORMDATA',[
   +'s'#12'ClientHeight'#3#200#1#11'ClientWidth'#3#137#1#21'Constraints.MaxHeigh'
   +'t'#3#200#1#20'Constraints.MaxWidth'#3#137#1#21'Constraints.MinHeight'#3#200
   +#1#20'Constraints.MinWidth'#3#137#1#8'OnCreate'#7#10'FormCreate'#6'OnShow'#7
-  +#8'FormShow'#8'Position'#7#14'poScreenCenter'#10'LCLVersion'#6#7'1.0.2.0'#0#9
-  +'TGroupBox'#9'GroupBox1'#4'Left'#2#8#6'Height'#3#24#1#3'Top'#2#8#5'Width'#3
-  +'p'#1#7'Caption'#6#13'Image Display'#12'ClientHeight'#3#6#1#11'ClientWidth'#3
-  +'l'#1#8'TabOrder'#2#0#0#6'TLabel'#6'Label1'#4'Left'#2'x'#6'Height'#2#14#3'To'
-  +'p'#2'G'#5'Width'#3#138#0#7'Caption'#6#26'Maximum Dimension [Voxels]'#11'Par'
-  +'entColor'#8#0#0#6'TLabel'#6'Label2'#4'Left'#2'x'#6'Height'#2#14#3'Top'#2'q'
-  +#5'Width'#2'\'#7'Caption'#6#17'Rendering Threads'#11'ParentColor'#8#0#0#6'TL'
-  +'abel'#6'Label3'#4'Left'#2'x'#6'Height'#2#14#3'Top'#3#145#0#5'Width'#2'w'#7
-  +'Caption'#6#24'Decimal places Displayed'#11'ParentColor'#8#0#0#9'TCheckBox'
-  +#12'ResliceCheck'#4'Left'#2#15#6'Height'#2#17#3'Top'#2#9#5'Width'#3#163#0#7
+  +#8'FormShow'#8'Position'#7#14'poScreenCenter'#10'LCLVersion'#6#8'1.0.12.0'#0
+  +#9'TGroupBox'#9'GroupBox1'#4'Left'#2#8#6'Height'#3#24#1#3'Top'#2#8#5'Width'#3
+  +'p'#1#7'Caption'#6#13'Image Display'#12'ClientHeight'#3#2#1#11'ClientWidth'#3
+  +'h'#1#8'TabOrder'#2#0#0#6'TLabel'#6'Label1'#4'Left'#2'x'#6'Height'#2#17#3'To'
+  +'p'#2'G'#5'Width'#3#190#0#7'Caption'#6#26'Maximum Dimension [Voxels]'#11'Par'
+  +'entColor'#8#0#0#6'TLabel'#6'Label2'#4'Left'#2'x'#6'Height'#2#17#3'Top'#2'q'
+  +#5'Width'#2'x'#7'Caption'#6#17'Rendering Threads'#11'ParentColor'#8#0#0#6'TL'
+  +'abel'#6'Label3'#4'Left'#2'x'#6'Height'#2#17#3'Top'#3#145#0#5'Width'#3#161#0
+  +#7'Caption'#6#24'Decimal places Displayed'#11'ParentColor'#8#0#0#9'TCheckBox'
+  +#12'ResliceCheck'#4'Left'#2#15#6'Height'#2#18#3'Top'#2#9#5'Width'#3#210#0#7
   +'Caption'#6#28'Reorient images when loading'#7'OnClick'#7#17'ResliceCheckCli'
   +'ck'#8'TabOrder'#2#0#0#0#9'TSpinEdit'#10'MaxDimEdit'#4'Left'#2#14#6'Height'#2
-  +#21#3'Top'#2'@'#5'Width'#2'd'#8'MaxValue'#3#0#16#8'MinValue'#3#0#1#8'TabOrde'
+  +#16#3'Top'#2'@'#5'Width'#2'd'#8'MaxValue'#3#0#16#8'MinValue'#3#0#1#8'TabOrde'
   +'r'#2#1#5'Value'#3#0#1#0#0#9'TSpinEdit'#10'ThreadEdit'#4'Left'#2#14#6'Height'
-  +#2#21#3'Top'#2'e'#5'Width'#2'd'#8'MaxValue'#3#0#16#8'MinValue'#2#1#8'TabOrde'
+  +#2#16#3'Top'#2'e'#5'Width'#2'd'#8'MaxValue'#3#0#16#8'MinValue'#2#1#8'TabOrde'
   +'r'#2#2#5'Value'#2#1#0#0#9'TSpinEdit'#10'SigDigEdit'#4'Left'#2#14#6'Height'#2
-  +#21#3'Top'#3#138#0#5'Width'#2'd'#8'MaxValue'#2' '#8'TabOrder'#2#3#0#0#9'TChe'
-  +'ckBox'#10'OrthoCheck'#4'Left'#2'+'#6'Height'#2#17#3'Top'#2'%'#5'Width'#3#190
-  +#0#7'Caption'#6'"Rotate to nearest orthogonal angle'#8'TabOrder'#2#4#7'Visib'
-  +'le'#8#0#0#9'TCheckBox'#14'SingleRowCheck'#4'Left'#2#15#6'Height'#2#17#3'Top'
-  +#3#208#0#5'Width'#3#134#0#7'Caption'#6#26'All slices on a single row'#8'TabO'
-  +'rder'#2#5#0#0#0#9'TGroupBox'#9'GroupBox2'#4'Left'#2#8#6'Height'#2'@'#3'Top'
-  +#3'('#1#5'Width'#3'p'#1#7'Caption'#6#7'Drawing'#12'ClientHeight'#2'.'#11'Cli'
-  +'entWidth'#3'l'#1#8'TabOrder'#2#1#0#9'TCheckBox'#12'ThinPenCheck'#4'Left'#2
-  +#15#6'Height'#2#17#3'Top'#2#16#5'Width'#2'='#7'Caption'#6#8'Thin Pen'#8'TabO'
-  +'rder'#2#0#0#0#0#7'TButton'#5'OKBtn'#4'Left'#3'('#1#6'Height'#2#25#3'Top'#3
-  +#160#1#5'Width'#2'K'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#2'OK'#7
-  +'OnClick'#7#10'OKBtnClick'#8'TabOrder'#2#2#0#0#7'TButton'#9'CancelBtn'#4'Lef'
-  +'t'#3#192#0#6'Height'#2#25#3'Top'#3#160#1#5'Width'#2'K'#25'BorderSpacing.Inn'
-  +'erBorder'#2#4#7'Caption'#6#6'Cancel'#7'OnClick'#7#14'CancelBtnClick'#8'TabO'
-  +'rder'#2#3#0#0#7'TButton'#7'XBarClr'#4'Left'#2#26#6'Height'#2#25#3'Top'#3#197
-  +#0#5'Width'#3#178#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#22'Choose'
-  +' Cross-Bar Color'#7'OnClick'#7#12'XBarClrClick'#8'TabOrder'#2#4#0#0#0
-]);
+  +#16#3'Top'#3#138#0#5'Width'#2'd'#8'MaxValue'#2' '#8'TabOrder'#2#3#0#0#9'TChe'
+  +'ckBox'#10'OrthoCheck'#4'Left'#2'+'#6'Height'#2#18#3'Top'#2'%'#5'Width'#3#240
+  +#0#7'Caption'#6'"Rotate to nearest orthogonal angle'#8'TabOrder'#2#4#0#0#9'T'
+  +'CheckBox'#14'SingleRowCheck'#4'Left'#2#15#6'Height'#2#18#3'Top'#3#208#0#5'W'
+  +'idth'#3#174#0#7'Caption'#6#26'All slices on a single row'#8'TabOrder'#2#5#0
+  +#0#0#9'TGroupBox'#9'GroupBox2'#4'Left'#2#8#6'Height'#2'@'#3'Top'#3'('#1#5'Wi'
+  +'dth'#3'p'#1#7'Caption'#6#7'Drawing'#12'ClientHeight'#2'*'#11'ClientWidth'#3
+  +'h'#1#8'TabOrder'#2#1#0#9'TCheckBox'#12'ThinPenCheck'#4'Left'#2#15#6'Height'
+  +#2#18#3'Top'#2#16#5'Width'#2'K'#7'Caption'#6#8'Thin Pen'#8'TabOrder'#2#0#0#0
+  +#0#7'TButton'#5'OKBtn'#4'Left'#3'('#1#6'Height'#2#25#3'Top'#3#160#1#5'Width'
+  +#2'K'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#2'OK'#7'OnClick'#7#10'O'
+  +'KBtnClick'#8'TabOrder'#2#2#0#0#7'TButton'#9'CancelBtn'#4'Left'#3#192#0#6'He'
+  +'ight'#2#25#3'Top'#3#160#1#5'Width'#2'K'#25'BorderSpacing.InnerBorder'#2#4#7
+  +'Caption'#6#6'Cancel'#7'OnClick'#7#14'CancelBtnClick'#8'TabOrder'#2#3#0#0#7
+  +'TButton'#7'XBarClr'#4'Left'#2#26#6'Height'#2#25#3'Top'#3#197#0#5'Width'#3
+  +#178#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#22'Choose Cross-Bar Co'
+  +'lor'#7'OnClick'#7#12'XBarClrClick'#8'TabOrder'#2#4#0#0#0
+]);
\ No newline at end of file
diff --git a/prefs.pas b/prefs.pas
index 3a8f441..7f2d7f2 100755
--- a/prefs.pas
+++ b/prefs.pas
@@ -91,7 +91,7 @@ end;
 
 procedure TPrefForm.ResliceCheckClick(Sender: TObject);
 begin
-    // OrthoCheck.Visible := not ResliceCheck.checked;
+    OrthoCheck.Visible := not ResliceCheck.checked;
 end;
 
 procedure TPrefForm.XBarClrClick(Sender: TObject);
@@ -104,4 +104,4 @@ initialization
   {$I prefs.lrs}
 
 end.
-
+
\ No newline at end of file
diff --git a/render.lfm b/render.lfm
index 3fc1a3a..8ed3444 100755
--- a/render.lfm
+++ b/render.lfm
@@ -1,11 +1,11 @@
 object RenderForm: TRenderForm
-  Left = 258
+  Left = 313
   Height = 512
-  Top = 167
+  Top = 165
   Width = 955
   ActiveControl = AzimuthEdit
   Caption = 'Volume Render'
-  ClientHeight = 493
+  ClientHeight = 512
   ClientWidth = 955
   Font.Name = 'MS Sans Serif'
   Menu = MainMenu1
@@ -13,7 +13,7 @@ object RenderForm: TRenderForm
   OnHide = FormHide
   OnShow = FormShow
   Position = poScreenCenter
-  LCLVersion = '0.9.29'
+  LCLVersion = '1.0.12.0'
   object RenderBar: TPanel
     Left = 0
     Height = 32
@@ -26,17 +26,17 @@ object RenderForm: TRenderForm
     TabOrder = 0
     object Label4: TLabel
       Left = 152
-      Height = 17
+      Height = 18
       Top = 5
-      Width = 57
+      Width = 58
       Caption = 'Elevation'
       ParentColor = False
     end
     object Label1: TLabel
       Left = 4
-      Height = 17
+      Height = 18
       Top = 5
-      Width = 47
+      Width = 53
       Caption = 'Azimuth'
       ParentColor = False
     end
@@ -46,7 +46,6 @@ object RenderForm: TRenderForm
       Hint = 'Generate high-resolution rendering'
       Top = 0
       Width = 40
-      Color = clBtnFace
       Glyph.Data = {
         76080000424D7608000000000000360000002800000018000000160000000100
         2000000000004008000064000000640000000000000000000000FFFFFFFFFFFF
@@ -138,7 +137,7 @@ object RenderForm: TRenderForm
     end
     object Label5: TLabel
       Left = 616
-      Height = 17
+      Height = 18
       Top = 5
       Width = 66
       Caption = 'Shading %'
@@ -146,7 +145,7 @@ object RenderForm: TRenderForm
     end
     object AzimuthEdit: TSpinEdit
       Left = 72
-      Height = 21
+      Height = 16
       Top = 2
       Width = 70
       Increment = 30
@@ -157,7 +156,7 @@ object RenderForm: TRenderForm
     end
     object ElevationEdit: TSpinEdit
       Left = 216
-      Height = 21
+      Height = 16
       Top = 2
       Width = 70
       Increment = 30
@@ -191,7 +190,7 @@ object RenderForm: TRenderForm
     end
     object ShadeEdit: TSpinEdit
       Left = 690
-      Height = 21
+      Height = 16
       Top = 2
       Width = 70
       Increment = 10
@@ -212,12 +211,14 @@ object RenderForm: TRenderForm
   end
   object RenderPanel: TScrollBox
     Left = 0
-    Height = 461
+    Height = 480
     Top = 32
     Width = 955
+    HorzScrollBar.Page = 955
+    VertScrollBar.Page = 480
     Align = alClient
-    ClientHeight = 457
-    ClientWidth = 951
+    ClientHeight = 480
+    ClientWidth = 955
     TabOrder = 1
     object RenderImage: TImage
       Tag = 2
@@ -572,4 +573,4 @@ object RenderForm: TRenderForm
     left = 48
     top = 32
   end
-end
+end
\ No newline at end of file
diff --git a/render.lrs b/render.lrs
index 0351088..2be9dd1 100755
--- a/render.lrs
+++ b/render.lrs
@@ -1,231 +1,231 @@
 { This is an automatically generated lazarus resource file }
 
 LazarusResources.Add('TRenderForm','FORMDATA',[
-  'TPF0'#11'TRenderForm'#10'RenderForm'#4'Left'#3#2#1#6'Height'#3#0#2#3'Top'#3
-  +#167#0#5'Width'#3#187#3#13'ActiveControl'#7#11'AzimuthEdit'#7'Caption'#6#13
-  +'Volume Render'#12'ClientHeight'#3#237#1#11'ClientWidth'#3#187#3#9'Font.Name'
-  +#6#13'MS Sans Serif'#4'Menu'#7#9'MainMenu1'#8'OnCreate'#7#10'FormCreate'#6'O'
-  +'nHide'#7#8'FormHide'#6'OnShow'#7#8'FormShow'#8'Position'#7#14'poScreenCente'
-  +'r'#10'LCLVersion'#6#6'0.9.29'#0#6'TPanel'#9'RenderBar'#4'Left'#2#0#6'Height'
+  'TPF0'#11'TRenderForm'#10'RenderForm'#4'Left'#3'9'#1#6'Height'#3#0#2#3'Top'#3
+  +#165#0#5'Width'#3#187#3#13'ActiveControl'#7#11'AzimuthEdit'#7'Caption'#6#13
+  +'Volume Render'#12'ClientHeight'#3#0#2#11'ClientWidth'#3#187#3#9'Font.Name'#6
+  +#13'MS Sans Serif'#4'Menu'#7#9'MainMenu1'#8'OnCreate'#7#10'FormCreate'#6'OnH'
+  +'ide'#7#8'FormHide'#6'OnShow'#7#8'FormShow'#8'Position'#7#14'poScreenCenter'
+  +#10'LCLVersion'#6#8'1.0.12.0'#0#6'TPanel'#9'RenderBar'#4'Left'#2#0#6'Height'
   +#2' '#3'Top'#2#0#5'Width'#3#187#3#5'Align'#7#5'alTop'#10'BevelOuter'#7#6'bvN'
   +'one'#12'ClientHeight'#2' '#11'ClientWidth'#3#187#3#8'TabOrder'#2#0#0#6'TLab'
-  +'el'#6'Label4'#4'Left'#3#152#0#6'Height'#2#17#3'Top'#2#5#5'Width'#2'9'#7'Cap'
+  +'el'#6'Label4'#4'Left'#3#152#0#6'Height'#2#18#3'Top'#2#5#5'Width'#2':'#7'Cap'
   +'tion'#6#9'Elevation'#11'ParentColor'#8#0#0#6'TLabel'#6'Label1'#4'Left'#2#4#6
-  +'Height'#2#17#3'Top'#2#5#5'Width'#2'/'#7'Caption'#6#7'Azimuth'#11'ParentColo'
+  +'Height'#2#18#3'Top'#2#5#5'Width'#2'5'#7'Caption'#6#7'Azimuth'#11'ParentColo'
   +'r'#8#0#0#12'TSpeedButton'#10'RefreshBtn'#4'Left'#3'('#1#6'Height'#2#31#4'Hi'
-  +'nt'#6'"Generate high-resolution rendering'#3'Top'#2#0#5'Width'#2'('#5'Color'
-  +#7#9'clBtnFace'#10'Glyph.Data'#10'z'#8#0#0'v'#8#0#0'BMv'#8#0#0#0#0#0#0'6'#0#0
-  +#0'('#0#0#0#24#0#0#0#22#0#0#0#1#0' '#0#0#0#0#0'@'#8#0#0'd'#0#0#0'd'#0#0#0#0#0
-  +#0#0#0#0#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +'nt'#6'"Generate high-resolution rendering'#3'Top'#2#0#5'Width'#2'('#10'Glyp'
+  +'h.Data'#10'z'#8#0#0'v'#8#0#0'BMv'#8#0#0#0#0#0#0'6'#0#0#0'('#0#0#0#24#0#0#0
+  +#22#0#0#0#1#0' '#0#0#0#0#0'@'#8#0#0'd'#0#0#0'd'#0#0#0#0#0#0#0#0#0#0#0#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0
+  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255
+  +#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
   +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255
-  +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
   +#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255
+  +#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255
   +#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0
-  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255
   +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0
   +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255
-  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
-  +#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255
+  +#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
+  +#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
   +#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0
-  +#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255
+  +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255
   +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255
+  +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
+  +#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0
-  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255
-  +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
+  ,#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
+  +#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0
   +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255
   +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
-  +#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0
-  ,#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255
   +#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
+  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
-  +#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
   +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255
-  +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
-  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
   +#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255
-  +#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0
-  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255
+  +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0
-  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0
-  +#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
+  +#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
+  +#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255
+  +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
   +#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
-  +#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0
+  +#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255
+  +#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0
   +#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
   +#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
+  +#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255
+  +#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255
+  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255
   +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
-  +#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255
-  +#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255
-  +#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255
-  +#255#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0
-  +#255#255#0#0#255#255#0#0#255#255#9'NumGlyphs'#2#0#7'OnClick'#7#12'RefreshCli'
-  +'ck'#8'ShowHint'#9#14'ParentShowHint'#8#0#0#6'TImage'#14'RenderImageBUP'#3'T'
-  +'ag'#2#2#6'Cursor'#7#7'crCross'#4'Left'#3'h'#1#6'Height'#2#12#3'Top'#2#8#5'W'
-  +'idth'#2#12#8'AutoSize'#9#6'Center'#9#11'OnMouseDown'#7#20'RenderImageMouseD'
-  +'own'#11'OnMouseMove'#7#20'RenderImageMouseMove'#7'Stretch'#9#7'Visible'#8#0
-  +#0#6'TLabel'#6'Label5'#4'Left'#3'h'#2#6'Height'#2#17#3'Top'#2#5#5'Width'#2'B'
-  +#7'Caption'#6#9'Shading %'#11'ParentColor'#8#0#0#9'TSpinEdit'#11'AzimuthEdit'
-  +#4'Left'#2'H'#6'Height'#2#21#3'Top'#2#2#5'Width'#2'F'#9'Increment'#2#30#8'Ma'
-  +'xValue'#3'h'#1#8'OnChange'#7#10'EditChange'#8'TabOrder'#2#0#5'Value'#2'x'#0
-  +#0#9'TSpinEdit'#13'ElevationEdit'#4'Left'#3#216#0#6'Height'#2#21#3'Top'#2#2#5
-  +'Width'#2'F'#9'Increment'#2#30#8'MaxValue'#3#180#0#8'MinValue'#3'L'#255#8'On'
-  +'Change'#7#10'EditChange'#8'TabOrder'#2#1#5'Value'#2#30#0#0#9'TTrackBar'#9'B'
-  +'iasTrack'#4'Left'#3'`'#1#6'Height'#2#29#3'Top'#2#2#5'Width'#2'x'#3'Max'#2'd'
-  +#8'OnChange'#7#15'BiasTrackChange'#8'Position'#2'2'#9'TickStyle'#7#6'tsNone'
-  +#8'TabOrder'#2#2#0#0#9'TTrackBar'#9'GainTrack'#4'Left'#3#224#1#6'Height'#2#29
-  +#3'Top'#2#2#5'Width'#2'x'#3'Max'#2'd'#8'OnChange'#7#15'BiasTrackChange'#8'Po'
-  ,'sition'#2'2'#9'TickStyle'#7#6'tsNone'#8'TabOrder'#2#3#0#0#9'TSpinEdit'#9'Sh'
-  +'adeEdit'#4'Left'#3#178#2#6'Height'#2#21#3'Top'#2#2#5'Width'#2'F'#9'Incremen'
-  +'t'#2#10#8'OnChange'#7#10'EditChange'#8'TabOrder'#2#4#0#0#9'TTrackBar'#9'Cli'
-  +'pTrack'#4'Left'#3#8#3#6'Height'#2#29#3'Top'#2#2#5'Width'#2'x'#3'Max'#3#231#3
-  +#8'OnChange'#7#15'ClipTrackChange'#8'Position'#2#0#9'TickStyle'#7#6'tsNone'#8
-  +'TabOrder'#2#5#0#0#0#10'TScrollBox'#11'RenderPanel'#4'Left'#2#0#6'Height'#3
-  +#205#1#3'Top'#2' '#5'Width'#3#187#3#5'Align'#7#8'alClient'#12'ClientHeight'#3
-  +#201#1#11'ClientWidth'#3#183#3#8'TabOrder'#2#1#0#6'TImage'#11'RenderImage'#3
-  +'Tag'#2#2#6'Cursor'#7#7'crCross'#4'Left'#2#2#6'Height'#2#12#3'Top'#2#2#5'Wid'
-  +'th'#2#12#8'AutoSize'#9#11'OnMouseDown'#7#20'RenderImageMouseDown'#11'OnMous'
-  +'eMove'#7#20'RenderImageMouseMove'#7'Stretch'#9#0#0#0#9'TMainMenu'#9'MainMen'
-  +'u1'#4'left'#2#16#3'top'#2' '#0#9'TMenuItem'#8'FileMenu'#7'Caption'#6#4'File'
-  +#0#9'TMenuItem'#9'Settings1'#7'Caption'#6#13'Open settings'#7'OnClick'#7#14
-  +'Settings1Click'#0#0#9'TMenuItem'#13'Savesettings1'#7'Caption'#6#16'Save set'
-  +'tings...'#7'OnClick'#7#18'Savesettings1Click'#0#0#9'TMenuItem'#5'Save1'#7'C'
-  +'aption'#6#17'Save as bitmap...'#8'ShortCut'#3'S@'#7'OnClick'#7#10'Save1Clic'
-  +'k'#0#0#9'TMenuItem'#15'RotationBMPMenu'#7'Caption'#6#21'Save Rotation Bitma'
-  +'ps'#7'OnClick'#7#20'RotationBMPMenuClick'#0#0#9'TMenuItem'#12'SaveClipMenu'
-  +#7'Caption'#6#17'Save clip bitmaps'#7'OnClick'#7#17'SaveClipMenuClick'#0#0#9
-  +'TMenuItem'#6'Close1'#7'Caption'#6#12'Close window'#8'ShortCut'#3'W@'#7'OnCl'
-  +'ick'#7#11'Close1Click'#0#0#0#9'TMenuItem'#5'Edit1'#7'Caption'#6#4'Edit'#0#9
-  +'TMenuItem'#5'Copy1'#7'Caption'#6#4'Copy'#7'OnClick'#7#10'Copy1Click'#0#0#0#9
-  +'TMenuItem'#7'Volume1'#7'Caption'#6#10'Background'#0#9'TMenuItem'#19'RenderB'
-  +'GSurfaceMenu'#7'Caption'#6#18'Air/Skin Threshold'#0#9'TMenuItem'#2'N1'#7'Ca'
-  +'ption'#6#2'0%'#10'GroupIndex'#2'w'#9'RadioItem'#9#7'OnClick'#7#7'N1Click'#0
-  +#0#9'TMenuItem'#4'N101'#3'Tag'#2#25#7'Caption'#6#3'10%'#7'Checked'#9#10'Grou'
-  +'pIndex'#2'w'#9'RadioItem'#9#7'OnClick'#7#7'N1Click'#0#0#9'TMenuItem'#4'N401'
-  +#3'Tag'#2'3'#7'Caption'#6#3'20%'#10'GroupIndex'#2'w'#9'RadioItem'#9#7'OnClic'
-  +'k'#7#7'N1Click'#0#0#9'TMenuItem'#4'N601'#3'Tag'#2'L'#7'Caption'#6#3'30%'#10
-  +'GroupIndex'#2'w'#9'RadioItem'#9#7'OnClick'#7#7'N1Click'#0#0#9'TMenuItem'#4
-  +'N801'#3'Tag'#2'e'#7'Caption'#6#3'40%'#10'GroupIndex'#2'w'#9'RadioItem'#9#7
-  +'OnClick'#7#7'N1Click'#0#0#9'TMenuItem'#4'N403'#3'Tag'#3#128#0#7'Caption'#6#3
-  +'50%'#10'GroupIndex'#2'w'#9'RadioItem'#9#7'OnClick'#7#7'N1Click'#0#0#9'TMenu'
-  +'Item'#4'N404'#3'Tag'#3#152#0#7'Caption'#6#3'60%'#10'GroupIndex'#2'w'#9'Radi'
-  +'oItem'#9#7'OnClick'#7#7'N1Click'#0#0#9'TMenuItem'#4'N405'#3'Tag'#3#178#0#7
-  +'Caption'#6#3'70%'#10'GroupIndex'#2'w'#9'RadioItem'#9#7'OnClick'#7#7'N1Click'
-  +#0#0#0#9'TMenuItem'#17'RenderBGDepthMenu'#7'Caption'#6#12'Search Depth'#0#9
-  +'TMenuItem'#8'N1voxel1'#3'Tag'#2#1#7'Caption'#6#7'1 voxel'#7'Checked'#9#10'G'
+  +#255#255#255#255#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255
+  +#255#0#0#255#255#0#0#255#255#0#0#255#255#255#255#255#255#255#255#255#255#255
+  +#255#255#255#255#255#255#255#0#0#255#255#0#0#255#255#0#0#255#255#0#0#255#255
+  +#0#0#255#255#9'NumGlyphs'#2#0#7'OnClick'#7#12'RefreshClick'#8'ShowHint'#9#14
+  +'ParentShowHint'#8#0#0#6'TImage'#14'RenderImageBUP'#3'Tag'#2#2#6'Cursor'#7#7
+  +'crCross'#4'Left'#3'h'#1#6'Height'#2#12#3'Top'#2#8#5'Width'#2#12#8'AutoSize'
+  +#9#6'Center'#9#11'OnMouseDown'#7#20'RenderImageMouseDown'#11'OnMouseMove'#7
+  +#20'RenderImageMouseMove'#7'Stretch'#9#7'Visible'#8#0#0#6'TLabel'#6'Label5'#4
+  +'Left'#3'h'#2#6'Height'#2#18#3'Top'#2#5#5'Width'#2'B'#7'Caption'#6#9'Shading'
+  +' %'#11'ParentColor'#8#0#0#9'TSpinEdit'#11'AzimuthEdit'#4'Left'#2'H'#6'Heigh'
+  +'t'#2#16#3'Top'#2#2#5'Width'#2'F'#9'Increment'#2#30#8'MaxValue'#3'h'#1#8'OnC'
+  +'hange'#7#10'EditChange'#8'TabOrder'#2#0#5'Value'#2'x'#0#0#9'TSpinEdit'#13'E'
+  +'levationEdit'#4'Left'#3#216#0#6'Height'#2#16#3'Top'#2#2#5'Width'#2'F'#9'Inc'
+  +'rement'#2#30#8'MaxValue'#3#180#0#8'MinValue'#3'L'#255#8'OnChange'#7#10'Edit'
+  +'Change'#8'TabOrder'#2#1#5'Value'#2#30#0#0#9'TTrackBar'#9'BiasTrack'#4'Left'
+  +#3'`'#1#6'Height'#2#29#3'Top'#2#2#5'Width'#2'x'#3'Max'#2'd'#8'OnChange'#7#15
+  +'BiasTrackChange'#8'Position'#2'2'#9'TickStyle'#7#6'tsNone'#8'TabOrder'#2#2#0
+  +#0#9'TTrackBar'#9'GainTrack'#4'Left'#3#224#1#6'Height'#2#29#3'Top'#2#2#5'Wid'
+  +'th'#2'x'#3'Max'#2'd'#8'OnChange'#7#15'BiasTrackChange'#8'Position'#2'2'#9'T'
+  ,'ickStyle'#7#6'tsNone'#8'TabOrder'#2#3#0#0#9'TSpinEdit'#9'ShadeEdit'#4'Left'
+  +#3#178#2#6'Height'#2#16#3'Top'#2#2#5'Width'#2'F'#9'Increment'#2#10#8'OnChang'
+  +'e'#7#10'EditChange'#8'TabOrder'#2#4#0#0#9'TTrackBar'#9'ClipTrack'#4'Left'#3
+  +#8#3#6'Height'#2#29#3'Top'#2#2#5'Width'#2'x'#3'Max'#3#231#3#8'OnChange'#7#15
+  +'ClipTrackChange'#8'Position'#2#0#9'TickStyle'#7#6'tsNone'#8'TabOrder'#2#5#0
+  +#0#0#10'TScrollBox'#11'RenderPanel'#4'Left'#2#0#6'Height'#3#224#1#3'Top'#2' '
+  +#5'Width'#3#187#3#18'HorzScrollBar.Page'#3#187#3#18'VertScrollBar.Page'#3#224
+  +#1#5'Align'#7#8'alClient'#12'ClientHeight'#3#224#1#11'ClientWidth'#3#187#3#8
+  +'TabOrder'#2#1#0#6'TImage'#11'RenderImage'#3'Tag'#2#2#6'Cursor'#7#7'crCross'
+  +#4'Left'#2#2#6'Height'#2#12#3'Top'#2#2#5'Width'#2#12#8'AutoSize'#9#11'OnMous'
+  +'eDown'#7#20'RenderImageMouseDown'#11'OnMouseMove'#7#20'RenderImageMouseMove'
+  +#7'Stretch'#9#0#0#0#9'TMainMenu'#9'MainMenu1'#4'left'#2#16#3'top'#2' '#0#9'T'
+  +'MenuItem'#8'FileMenu'#7'Caption'#6#4'File'#0#9'TMenuItem'#9'Settings1'#7'Ca'
+  +'ption'#6#13'Open settings'#7'OnClick'#7#14'Settings1Click'#0#0#9'TMenuItem'
+  +#13'Savesettings1'#7'Caption'#6#16'Save settings...'#7'OnClick'#7#18'Saveset'
+  +'tings1Click'#0#0#9'TMenuItem'#5'Save1'#7'Caption'#6#17'Save as bitmap...'#8
+  +'ShortCut'#3'S@'#7'OnClick'#7#10'Save1Click'#0#0#9'TMenuItem'#15'RotationBMP'
+  +'Menu'#7'Caption'#6#21'Save Rotation Bitmaps'#7'OnClick'#7#20'RotationBMPMen'
+  +'uClick'#0#0#9'TMenuItem'#12'SaveClipMenu'#7'Caption'#6#17'Save clip bitmaps'
+  +#7'OnClick'#7#17'SaveClipMenuClick'#0#0#9'TMenuItem'#6'Close1'#7'Caption'#6
+  +#12'Close window'#8'ShortCut'#3'W@'#7'OnClick'#7#11'Close1Click'#0#0#0#9'TMe'
+  +'nuItem'#5'Edit1'#7'Caption'#6#4'Edit'#0#9'TMenuItem'#5'Copy1'#7'Caption'#6#4
+  +'Copy'#7'OnClick'#7#10'Copy1Click'#0#0#0#9'TMenuItem'#7'Volume1'#7'Caption'#6
+  +#10'Background'#0#9'TMenuItem'#19'RenderBGSurfaceMenu'#7'Caption'#6#18'Air/S'
+  +'kin Threshold'#0#9'TMenuItem'#2'N1'#7'Caption'#6#2'0%'#10'GroupIndex'#2'w'#9
+  +'RadioItem'#9#7'OnClick'#7#7'N1Click'#0#0#9'TMenuItem'#4'N101'#3'Tag'#2#25#7
+  +'Caption'#6#3'10%'#7'Checked'#9#10'GroupIndex'#2'w'#9'RadioItem'#9#7'OnClick'
+  +#7#7'N1Click'#0#0#9'TMenuItem'#4'N401'#3'Tag'#2'3'#7'Caption'#6#3'20%'#10'Gr'
+  +'oupIndex'#2'w'#9'RadioItem'#9#7'OnClick'#7#7'N1Click'#0#0#9'TMenuItem'#4'N6'
+  +'01'#3'Tag'#2'L'#7'Caption'#6#3'30%'#10'GroupIndex'#2'w'#9'RadioItem'#9#7'On'
+  +'Click'#7#7'N1Click'#0#0#9'TMenuItem'#4'N801'#3'Tag'#2'e'#7'Caption'#6#3'40%'
+  +#10'GroupIndex'#2'w'#9'RadioItem'#9#7'OnClick'#7#7'N1Click'#0#0#9'TMenuItem'
+  +#4'N403'#3'Tag'#3#128#0#7'Caption'#6#3'50%'#10'GroupIndex'#2'w'#9'RadioItem'
+  +#9#7'OnClick'#7#7'N1Click'#0#0#9'TMenuItem'#4'N404'#3'Tag'#3#152#0#7'Caption'
+  +#6#3'60%'#10'GroupIndex'#2'w'#9'RadioItem'#9#7'OnClick'#7#7'N1Click'#0#0#9'T'
+  +'MenuItem'#4'N405'#3'Tag'#3#178#0#7'Caption'#6#3'70%'#10'GroupIndex'#2'w'#9
+  +'RadioItem'#9#7'OnClick'#7#7'N1Click'#0#0#0#9'TMenuItem'#17'RenderBGDepthMen'
+  +'u'#7'Caption'#6#12'Search Depth'#0#9'TMenuItem'#8'N1voxel1'#3'Tag'#2#1#7'Ca'
+  +'ption'#6#7'1 voxel'#7'Checked'#9#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnCli'
+  +'ck'#7#13'N1voxel1Click'#0#0#9'TMenuItem'#9'N2voxels1'#3'Tag'#2#2#7'Caption'
+  +#6#8'2 voxels'#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#13'N1voxel1Cl'
+  +'ick'#0#0#9'TMenuItem'#9'N4voxels1'#3'Tag'#2#4#7'Caption'#6#8'4 voxels'#10'G'
   +'roupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#13'N1voxel1Click'#0#0#9'TMenuIt'
-  +'em'#9'N2voxels1'#3'Tag'#2#2#7'Caption'#6#8'2 voxels'#10'GroupIndex'#2'z'#9
-  +'RadioItem'#9#7'OnClick'#7#13'N1voxel1Click'#0#0#9'TMenuItem'#9'N4voxels1'#3
-  +'Tag'#2#4#7'Caption'#6#8'4 voxels'#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnCl'
-  +'ick'#7#13'N1voxel1Click'#0#0#9'TMenuItem'#9'N8voxels1'#3'Tag'#2#8#7'Caption'
-  +#6#8'8 voxels'#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#13'N1voxel1Cl'
-  +'ick'#0#0#9'TMenuItem'#10'N16voxels1'#3'Tag'#2#12#7'Caption'#6#9'12 voxels'
-  +#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#13'N1voxel1Click'#0#0#9'TMe'
-  +'nuItem'#9'N16voxels'#3'Tag'#2#16#7'Caption'#6#9'16 voxels'#10'GroupIndex'#2
-  +'z'#9'RadioItem'#9#7'OnClick'#7#13'N1voxel1Click'#0#0#9'TMenuItem'#9'Infinit'
-  +'e1'#3'Tag'#4#255#255#255#127#7'Caption'#6#8'Infinite'#10'GroupIndex'#2'z'#9
-  +'RadioItem'#9#7'OnClick'#7#13'N1voxel1Click'#0#0#9'TMenuItem'#7'MIPItem'#7'C'
-  +'aption'#6#3'MIP'#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#13'N1voxel'
-  +'1Click'#0#0#0#0#9'TMenuItem'#8'Overlay1'#7'Caption'#6#7'Overlay'#0#9'TMenuI'
-  +'tem'#24'RenderOverlaySurfaceMenu'#7'Caption'#6#18'Air/Skin Threshold'#0#9'T'
-  +'MenuItem'#3'N01'#7'Caption'#6#2'0%'#7'Checked'#9#10'GroupIndex'#2'x'#9'Radi'
-  +'oItem'#9#7'OnClick'#7#8'N01Click'#0#0#9'TMenuItem'#4'N102'#3'Tag'#2#25#7'Ca'
-  +'ption'#6#3'10%'#10'GroupIndex'#2'x'#9'RadioItem'#9#7'OnClick'#7#8'N01Click'
-  +#0#0#9'TMenuItem'#4'N201'#3'Tag'#2'3'#7'Caption'#6#3'20%'#10'GroupIndex'#2'x'
-  +#9'RadioItem'#9#7'OnClick'#7#8'N01Click'#0#0#9'TMenuItem'#4'N301'#3'Tag'#2'L'
-  +#7'Caption'#6#3'30%'#10'GroupIndex'#2'x'#9'RadioItem'#9#7'OnClick'#7#8'N01Cl'
-  +'ick'#0#0#9'TMenuItem'#4'N402'#3'Tag'#2'e'#7'Caption'#6#3'40%'#10'GroupIndex'
-  +#2'x'#9'RadioItem'#9#7'OnClick'#7#8'N01Click'#0#0#9'TMenuItem'#4'N501'#3'Tag'
-  +#3#128#0#7'Caption'#6#3'50%'#10'GroupIndex'#2'x'#9'RadioItem'#9#7'OnClick'#7
-  +#8'N01Click'#0#0#9'TMenuItem'#4'N602'#3'Tag'#3#152#0#7'Caption'#6#3'60%'#10
-  +'GroupIndex'#2'x'#9'RadioItem'#9#7'OnClick'#7#8'N01Click'#0#0#9'TMenuItem'#4
-  ,'N701'#3'Tag'#3#178#0#7'Caption'#6#3'70%'#10'GroupIndex'#2'x'#9'RadioItem'#9
-  +#7'OnClick'#7#8'N01Click'#0#0#0#9'TMenuItem'#22'RenderOverlayDepthMenu'#7'Ca'
-  +'ption'#6#12'Search Depth'#0#9'TMenuItem'#8'N1voxel2'#3'Tag'#2#1#7'Caption'#6
-  +#7'1 voxel'#7'Checked'#9#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#22
-  +'OverlayRenderDepthItem'#0#0#9'TMenuItem'#9'N2voxels2'#3'Tag'#2#2#7'Caption'
-  +#6#8'2 voxels'#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#22'OverlayRen'
-  +'derDepthItem'#0#0#9'TMenuItem'#9'N4voxels2'#3'Tag'#2#4#7'Caption'#6#8'4 vox'
-  +'els'#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#22'OverlayRenderDepthI'
-  +'tem'#0#0#9'TMenuItem'#9'N8voxels2'#3'Tag'#2#8#7'Caption'#6#8'8 voxels'#10'G'
-  +'roupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#22'OverlayRenderDepthItem'#0#0#9
-  +'TMenuItem'#10'N12voxels1'#3'Tag'#2#12#7'Caption'#6#9'12 voxels'#10'GroupInd'
-  +'ex'#2'z'#9'RadioItem'#9#7'OnClick'#7#22'OverlayRenderDepthItem'#0#0#9'TMenu'
-  +'Item'#10'N16voxels2'#3'Tag'#2#16#7'Caption'#6#9'16 voxels'#10'GroupIndex'#2
+  +'em'#9'N8voxels1'#3'Tag'#2#8#7'Caption'#6#8'8 voxels'#10'GroupIndex'#2'z'#9
+  +'RadioItem'#9#7'OnClick'#7#13'N1voxel1Click'#0#0#9'TMenuItem'#10'N16voxels1'
+  +#3'Tag'#2#12#7'Caption'#6#9'12 voxels'#10'GroupIndex'#2'z'#9'RadioItem'#9#7
+  +'OnClick'#7#13'N1voxel1Click'#0#0#9'TMenuItem'#9'N16voxels'#3'Tag'#2#16#7'Ca'
+  +'ption'#6#9'16 voxels'#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#13'N1'
+  +'voxel1Click'#0#0#9'TMenuItem'#9'Infinite1'#3'Tag'#4#255#255#255#127#7'Capti'
+  +'on'#6#8'Infinite'#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#13'N1voxe'
+  +'l1Click'#0#0#9'TMenuItem'#7'MIPItem'#7'Caption'#6#3'MIP'#10'GroupIndex'#2'z'
+  +#9'RadioItem'#9#7'OnClick'#7#13'N1voxel1Click'#0#0#0#0#9'TMenuItem'#8'Overla'
+  +'y1'#7'Caption'#6#7'Overlay'#0#9'TMenuItem'#24'RenderOverlaySurfaceMenu'#7'C'
+  +'aption'#6#18'Air/Skin Threshold'#0#9'TMenuItem'#3'N01'#7'Caption'#6#2'0%'#7
+  +'Checked'#9#10'GroupIndex'#2'x'#9'RadioItem'#9#7'OnClick'#7#8'N01Click'#0#0#9
+  +'TMenuItem'#4'N102'#3'Tag'#2#25#7'Caption'#6#3'10%'#10'GroupIndex'#2'x'#9'Ra'
+  +'dioItem'#9#7'OnClick'#7#8'N01Click'#0#0#9'TMenuItem'#4'N201'#3'Tag'#2'3'#7
+  +'Caption'#6#3'20%'#10'GroupIndex'#2'x'#9'RadioItem'#9#7'OnClick'#7#8'N01Clic'
+  +'k'#0#0#9'TMenuItem'#4'N301'#3'Tag'#2'L'#7'Caption'#6#3'30%'#10'GroupIndex'#2
+  +'x'#9'RadioItem'#9#7'OnClick'#7#8'N01Click'#0#0#9'TMenuItem'#4'N402'#3'Tag'#2
+  +'e'#7'Caption'#6#3'40%'#10'GroupIndex'#2'x'#9'RadioItem'#9#7'OnClick'#7#8'N0'
+  +'1Click'#0#0#9'TMenuItem'#4'N501'#3'Tag'#3#128#0#7'Caption'#6#3'50%'#10'Grou'
+  +'pIndex'#2'x'#9'RadioItem'#9#7'OnClick'#7#8'N01Click'#0#0#9'TMenuItem'#4'N60'
+  +'2'#3'Tag'#3#152#0#7'Caption'#6#3'60%'#10'GroupIndex'#2'x'#9'RadioItem'#9#7
+  ,'OnClick'#7#8'N01Click'#0#0#9'TMenuItem'#4'N701'#3'Tag'#3#178#0#7'Caption'#6
+  +#3'70%'#10'GroupIndex'#2'x'#9'RadioItem'#9#7'OnClick'#7#8'N01Click'#0#0#0#9
+  +'TMenuItem'#22'RenderOverlayDepthMenu'#7'Caption'#6#12'Search Depth'#0#9'TMe'
+  +'nuItem'#8'N1voxel2'#3'Tag'#2#1#7'Caption'#6#7'1 voxel'#7'Checked'#9#10'Grou'
+  +'pIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#22'OverlayRenderDepthItem'#0#0#9'T'
+  +'MenuItem'#9'N2voxels2'#3'Tag'#2#2#7'Caption'#6#8'2 voxels'#10'GroupIndex'#2
   +'z'#9'RadioItem'#9#7'OnClick'#7#22'OverlayRenderDepthItem'#0#0#9'TMenuItem'#9
-  +'Infinite2'#3'Tag'#4#255#255#255#127#7'Caption'#6#8'Infinite'#10'GroupIndex'
-  +#2'z'#9'RadioItem'#9#7'OnClick'#7#22'OverlayRenderDepthItem'#0#0#0#9'TMenuIt'
-  +'em'#7'Search1'#7'Caption'#6#6'Search'#0#9'TMenuItem'#9'BehindBG1'#7'Caption'
-  +#6#9'Any Depth'#10'GroupIndex'#2#17#9'RadioItem'#9#7'OnClick'#7#9'SetSearch'
-  +#0#0#9'TMenuItem'#8'Infront1'#3'Tag'#2#1#7'Caption'#6' Below BG surface [max'
-  +' intensity]'#10'GroupIndex'#2#17#9'RadioItem'#9#7'OnClick'#7#9'SetSearch'#0
-  +#0#9'TMenuItem'#9'Anydepth1'#3'Tag'#2#2#7'Caption'#6#24'Infront/below BG sur'
-  +'face'#10'GroupIndex'#2#17#9'RadioItem'#9#7'OnClick'#7#9'SetSearch'#0#0#0#0#9
-  +'TMenuItem'#8'Quality1'#7'Caption'#6#4'View'#0#9'TMenuItem'#10'CutoutMenu'#7
-  +'Caption'#6#6'Cutout'#7'OnClick'#7#12'Cutout1Click'#0#0#9'TMenuItem'#9'MenuI'
-  +'tem1'#7'Caption'#6#1'-'#0#0#9'TMenuItem'#14'RenderSmoothBG'#7'Caption'#6#17
-  +'Smooth Background'#7'Checked'#9#4'Hint'#6#14'Blur rendering'#7'OnClick'#7#19
-  +'RenderSmoothBGClick'#0#0#9'TMenuItem'#19'RenderSmoothOverlay'#7'Caption'#6
-  +#14'Smooth Overlay'#7'Checked'#9#4'Hint'#6#14'Blur rendering'#7'OnClick'#7#19
-  +'RenderSmoothBGClick'#0#0#9'TMenuItem'#26'RenderPreciseInterpolation'#7'Capt'
-  +'ion'#6#21'Precise interpolation'#4'Hint'#6'"Use trilinear interpolation [sl'
-  +'ow]'#7'OnClick'#7#31'RenderPreciseInterpolationClick'#0#0#9'TMenuItem'#2'N2'
-  +#7'Caption'#6#1'-'#0#0#9'TMenuItem'#11'FlipLRcheck'#7'Caption'#6#8'Flip L/R'
-  +#7'OnClick'#7#17'RenderSmoothClick'#0#0#0#0#6'TTimer'#18'RenderRefreshTimer'
-  +#7'Enabled'#8#8'Interval'#3#150#0#7'OnTimer'#7#23'RenderRefreshTimerTimer'#4
-  +'left'#2'0'#3'top'#2' '#0#0#0
+  +'N4voxels2'#3'Tag'#2#4#7'Caption'#6#8'4 voxels'#10'GroupIndex'#2'z'#9'RadioI'
+  +'tem'#9#7'OnClick'#7#22'OverlayRenderDepthItem'#0#0#9'TMenuItem'#9'N8voxels2'
+  +#3'Tag'#2#8#7'Caption'#6#8'8 voxels'#10'GroupIndex'#2'z'#9'RadioItem'#9#7'On'
+  +'Click'#7#22'OverlayRenderDepthItem'#0#0#9'TMenuItem'#10'N12voxels1'#3'Tag'#2
+  +#12#7'Caption'#6#9'12 voxels'#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7
+  +#22'OverlayRenderDepthItem'#0#0#9'TMenuItem'#10'N16voxels2'#3'Tag'#2#16#7'Ca'
+  +'ption'#6#9'16 voxels'#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#22'Ov'
+  +'erlayRenderDepthItem'#0#0#9'TMenuItem'#9'Infinite2'#3'Tag'#4#255#255#255#127
+  +#7'Caption'#6#8'Infinite'#10'GroupIndex'#2'z'#9'RadioItem'#9#7'OnClick'#7#22
+  +'OverlayRenderDepthItem'#0#0#0#9'TMenuItem'#7'Search1'#7'Caption'#6#6'Search'
+  +#0#9'TMenuItem'#9'BehindBG1'#7'Caption'#6#9'Any Depth'#10'GroupIndex'#2#17#9
+  +'RadioItem'#9#7'OnClick'#7#9'SetSearch'#0#0#9'TMenuItem'#8'Infront1'#3'Tag'#2
+  +#1#7'Caption'#6' Below BG surface [max intensity]'#10'GroupIndex'#2#17#9'Rad'
+  +'ioItem'#9#7'OnClick'#7#9'SetSearch'#0#0#9'TMenuItem'#9'Anydepth1'#3'Tag'#2#2
+  +#7'Caption'#6#24'Infront/below BG surface'#10'GroupIndex'#2#17#9'RadioItem'#9
+  +#7'OnClick'#7#9'SetSearch'#0#0#0#0#9'TMenuItem'#8'Quality1'#7'Caption'#6#4'V'
+  +'iew'#0#9'TMenuItem'#10'CutoutMenu'#7'Caption'#6#6'Cutout'#7'OnClick'#7#12'C'
+  +'utout1Click'#0#0#9'TMenuItem'#9'MenuItem1'#7'Caption'#6#1'-'#0#0#9'TMenuIte'
+  +'m'#14'RenderSmoothBG'#7'Caption'#6#17'Smooth Background'#7'Checked'#9#4'Hin'
+  +'t'#6#14'Blur rendering'#7'OnClick'#7#19'RenderSmoothBGClick'#0#0#9'TMenuIte'
+  +'m'#19'RenderSmoothOverlay'#7'Caption'#6#14'Smooth Overlay'#7'Checked'#9#4'H'
+  +'int'#6#14'Blur rendering'#7'OnClick'#7#19'RenderSmoothBGClick'#0#0#9'TMenuI'
+  +'tem'#26'RenderPreciseInterpolation'#7'Caption'#6#21'Precise interpolation'#4
+  +'Hint'#6'"Use trilinear interpolation [slow]'#7'OnClick'#7#31'RenderPreciseI'
+  +'nterpolationClick'#0#0#9'TMenuItem'#2'N2'#7'Caption'#6#1'-'#0#0#9'TMenuItem'
+  +#11'FlipLRcheck'#7'Caption'#6#8'Flip L/R'#7'OnClick'#7#17'RenderSmoothClick'
+  +#0#0#0#0#6'TTimer'#18'RenderRefreshTimer'#7'Enabled'#8#8'Interval'#3#150#0#7
+  +'OnTimer'#7#23'RenderRefreshTimerTimer'#4'left'#2'0'#3'top'#2' '#0#0#0
 ]);
diff --git a/render.pas b/render.pas
index 2c4d374..933ecf7 100755
--- a/render.pas
+++ b/render.pas
@@ -335,10 +335,24 @@ begin
 end;
 
 procedure TRenderForm.Save1Click(Sender: TObject);
+//this code is required for OSX Lazarus, not sure about Windows/Delphi
+var
+lOutImg: TImage;
+begin
+  lOutImg :=  TImage.Create(ImgForm);
+       lOutImg.Width := RenderImage.Width;
+    lOutImg.Height := RenderImage.Height;
+    lOutImg.Canvas.Draw(0,0,RenderImage.Picture.Graphic);
+    SaveImgAsPNGBMP (lOutImg);
+    FreeAndNil (lOutImg);
+end;
+
+(*procedure TRenderForm.Save1Click(Sender: TObject);
 begin
 	 //if (RenderImage.Picture.Graphic = nil) then begin
 	 SaveImgAsPNGBMP (RenderImage);
-end;
+         ///xxxx
+end;*)
 
 procedure TRenderForm.RenderImageMouseMove(Sender: TObject;
   Shift: TShiftState; X, Y: Integer);
@@ -347,7 +361,19 @@ end;
 
 procedure TRenderForm.Copy1Click(Sender: TObject);
 {$IFDEF FPC}
+var
+lOutImg: TImage;
 begin
+  lOutImg :=  TImage.Create(ImgForm);
+  lOutImg.Width := RenderImage.Width;
+  lOutImg.Height := RenderImage.Height;
+  lOutImg.Canvas.Draw(0,0,RenderImage.Picture.Graphic);
+  lOutImg.Picture.Bitmap.SaveToClipboardFormat(2);
+  Clipboard.Assign(lOutImg.Picture.Graphic);
+  FreeAndNil (lOutImg);
+end;
+
+(*begin
         {$IFDEF zxDarwin}
         Showmessage('Copy not yet supported with OSX: use File/Save');
         exit;
@@ -357,7 +383,7 @@ begin
         exit;
      end;
         RenderImage.Picture.Bitmap.SaveToClipboardFormat(2);
-end;
+end;*)
 {$ELSE}
 var
   MyFormat : Word;
@@ -676,7 +702,14 @@ end;
 procedure RenderDrawXBar ( lHorPos, lVerPos: integer;var lImage: TImage);
 var lL,lT,lW,lH,lZoomPct: integer;
 begin
-	 lImage.Picture.Graphic := RenderForm.RenderImageBUP.Picture.Graphic;
+
+
+     lImage.Picture.Graphic := RenderForm.RenderImageBUP.Picture.Graphic;
+     {$IFNDEF Darwin}
+        xxxx make sure next line required on this OS!
+     {$ENDIF}
+     lImage.Canvas.Draw(0,0,RenderForm.RenderImageBUP.Picture.Graphic);
+     //lImage.Picture.Bitmap := RenderForm.RenderImageBUP.Picture.Bitmap;    //xxxx
          //redraw image even if not drawing X-bar: hide visible X-bar if use toggles X-bars off.
          if not ImgForm.XBarBtn.Down then
             exit; //only draw xbars if requested

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/mricron.git



More information about the debian-med-commit mailing list