import ij.*; import ij.gui.*; import ij.process.*; import ij.plugin.*; import ij.io.*; import java.io.*; import java.io.RandomAccessFile; import java.lang.String; /** Imports a ser file from Bruker written by Bertram Manz, Arbeitsgruppe Magnetische Resonanz, Fraunhofer-Institut für Biomedizinische Technik Enheimer Str. 48 66386 St. Ingbert Germany bertram dot manz at ibmt dot fraunhofer dot de Version 29/07/04 */ public class serOpener extends ImagePlus implements PlugIn { private static int xsize=1; private static int ysize=1; private static int zsize=1; public void run(String path) { String FileLine; File theFile=new File(path); String directory = theFile.getParent(); String fileName = theFile.getName(); String fileSeparator = (String)System.getProperty("file.separator"); File acqu = new File(directory, "acqu"); try { RandomAccessFile f = new RandomAccessFile(acqu, "r"); while ((FileLine = f.readLine()) != null) { if (FileLine.startsWith("##$TD= ")) { xsize = getiValue(FileLine.substring(7, FileLine.length())); } } f.close(); } catch (IOException e) { IJ.showMessage("serOpener", "File acqu not found."); zsize = 0; } if (xsize < 256) xsize = 256; File acqu2 = new File(directory, "acqu2"); try { RandomAccessFile f = new RandomAccessFile(acqu2, "r"); while ((FileLine = f.readLine()) != null) { if (FileLine.startsWith("##$TD= ")) { ysize = getiValue(FileLine.substring(7, FileLine.length())); } } f.close(); } catch (IOException e) { IJ.showMessage("serOpener", "File acqu2 not found."); ysize = 0; } File acqu3 = new File(directory, "acqu3"); try { RandomAccessFile f = new RandomAccessFile(acqu3, "r"); while ((FileLine = f.readLine()) != null) { if (FileLine.startsWith("##$TD= ")) { zsize = getiValue(FileLine.substring(7, FileLine.length())); } } f.close(); } catch (IOException e) { zsize = 1; // This is a 2D file } String titledirectory = directory + fileSeparator +"pdata" +fileSeparator +"1"; File titlefile = new File(titledirectory, "title"); try { RandomAccessFile f = new RandomAccessFile(titlefile, "r"); FileLine = f.readLine(); f.close(); } catch (IOException e) { FileLine = fileName; } if ((xsize == 0) || (ysize ==0) || (zsize == 0)) { ImportDialog id = new ImportDialog(fileName, directory); id.openImage(); } else { IJ.run("Raw...", "open='" +path +"' image='32-bit Signed' width=" +xsize +" height=" + ysize +" offset=0 number=" +zsize +" gap=0"); } IJ.run("Rename...", "title='" +FileLine +"'"); // IJ.run("ExtractReal Imag"); // IJ.run("Close"); } double getdValue(String theText) { Double d; try {d = new Double(theText);} catch (NumberFormatException e){ IJ.showMessage("serOpener", "Cannot convert " +theText +" to double."); d = null; } return d.doubleValue(); } int getiValue(String theText) { Integer d; try {d = new Integer(theText);} catch (NumberFormatException e){ IJ.showMessage("serOpener", "Cannot convert " +theText +" to int."); d = null; } return d.intValue(); } }