// ===============================================================================
//
// Multi_FDF_Opener.java
//
// This ImageJ plugin can be used to open MULTIPLE Varian imaging files in FDF format
// (FDF = Flexible Data Format).
// This program is free distributed in the hope that it will be useful to those who are interested
// in processing MRI images (Varian) by ImageJ, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU General Public License for more details.
//
// This program is free software; Therefore, you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// Michael A. Miller is highly appreciated for his pioneering effort, "FDF_Reader.java" downloadable
// from .
//
// Copyright (C) Shanrong Zhang
// Date: December 23, 2003
//
// ================================================================================
import java.io.*;
import java.util.*;
import java.lang.Math.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import ij.*;
import ij.plugin.*;
import ij.process.*;
import ij.io.*;
import ij.measure.*;
public class Multi_FDF_Opener implements PlugIn {
static File directory;
public void run(String arg) {
JFileChooser fc = null;
try {fc = new JFileChooser();}
catch (Throwable e) {IJ.error("This plugin requires Java 2 or Swing."); return;}
fc.setMultiSelectionEnabled(true);
if (directory == null) {
String sdir = OpenDialog.getDefaultDirectory();
if (sdir != null)
directory = new File(sdir);
}
if (directory != null)
fc.setCurrentDirectory(directory);
int returnVal = fc.showOpenDialog(IJ.getInstance());
if (returnVal != JFileChooser.APPROVE_OPTION)
return;
File[] files = fc.getSelectedFiles();
if (files.length == 0) {
files = new File[1];
files[0] = fc.getSelectedFile();
}
for (int i=0; i>> " + line);
if( line.length() == 0 ) {
IJ.log("line is empty");
} else {
StringTokenizer st = new StringTokenizer( line, " *=;,{}[]\"");
type = st.nextToken();
if( type.equals("int") ) {
// process ints
name = st.nextToken();
if( name.equals("bigendian") ) {
bigEndian = Long.valueOf(st.nextToken()).longValue();
} else if( name.equals("checksum") ) {
done = true;
}
} else if( type.equals("float") ) {
// process float
name = st.nextToken();
if( name.equals("matrix") ) {
if( spatial_rank.equals("2dfov") ) {
xdim = Long.valueOf(st.nextToken()).longValue();
ydim = Long.valueOf(st.nextToken()).longValue();
} else if( spatial_rank.equals("3dfov") ) {
xdim = Long.valueOf(st.nextToken()).longValue();
ydim = Long.valueOf(st.nextToken()).longValue();
zdim = Long.valueOf(st.nextToken()).longValue();
}
} else if( name.equals("span") ) {
if( spatial_rank.equals("2dfov") ) {
xspan = Float.valueOf(st.nextToken()).floatValue();
yspan = Float.valueOf(st.nextToken()).floatValue();
} else if( spatial_rank.equals("3dfov") ) {
xspan = Float.valueOf(st.nextToken()).floatValue();
yspan = Float.valueOf(st.nextToken()).floatValue();
zspan = Float.valueOf(st.nextToken()).floatValue();
}
} else if( name.equals("bigendian") ) {
bigEndian = Long.valueOf(st.nextToken()).longValue();
}
} else if( type.equals("char") ) {
name = st.nextToken();
if( name.equals("spatial_rank") ) {
spatial_rank = st.nextToken();
}
}
count = count + 1;
}
}
}
catch ( FileNotFoundException e ) {
IJ.showStatus( "File Disappeared" );
}
xsize = 10 * xspan / xdim;
ysize = 10 * yspan / ydim;
zsize = 10 * zspan / zdim;
fi.fileName = fdffile;
fi.directory = directory;
fi.fileFormat = fi.RAW;
fi.width = (int)xdim;
fi.height = (int)ydim;
fi.nImages = (int)zdim;
fi.pixelWidth = xsize;
fi.pixelHeight = ysize;
fi.pixelDepth = zsize;
fi.intelByteOrder = bigEndian == 0 ? true: false;
fi.fileType = FileInfo.GRAY32_FLOAT;
fi.unit = "mm";
fi.offset = (int)(file.length() - xdim*ydim*zdim*4);
IJ.log(" intelByteOrder: " + fi.intelByteOrder);
IJ.log(" xdim: " + xdim);
IJ.log(" ydim: " + ydim);
IJ.log(" zdim: " + zdim);
IJ.log(" xspan: " + xspan);
IJ.log(" yspan: " + yspan);
IJ.log(" zspan: " + zspan);
IJ.log(" xsize: " + xsize);
IJ.log(" ysize: " + ysize);
IJ.log(" zsize: " + zsize);
IJ.log(" file length: " + file.length() );
IJ.log(" data offset: " + fi.offset );
// IJ.log(" fi.offset = " + fi.offset);
// IJ.log("");
return (fi);
}
}