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 fid 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 fidOpener extends ImagePlus implements PlugIn { private static int xsize=1; private static int ysize=1; private static int zsize=1; private static int dimensions=1; private static int ni=1; private static int nr=1; public void run(String path) { String FileLine; int iii; int xs=1, ys=1, zs=1; File theFile=new File(path); String directory = theFile.getParent(); String fileName = theFile.getName(); String fileSeparator = (String)System.getProperty("file.separator"); File acqp = new File(directory, "acqp"); try { RandomAccessFile f = new RandomAccessFile(acqp, "r"); while ((FileLine = f.readLine()) != null) { if (FileLine.startsWith("##$ACQ_size=")) { int index1 = FileLine.indexOf("("); int index2 = FileLine.indexOf(")"); dimensions = getiValue(FileLine.substring(index1+2, index2-1)); FileLine = f.readLine(); switch (dimensions) { case 1: IJ.showMessage("fidOpener", "1D files are not supported."); break; case 2: index1 = FileLine.indexOf(" "); xsize = getiValue(FileLine.substring(0, index1)); ys = getiValue(FileLine.substring(index1+1)); break; case 3: index1 = FileLine.indexOf(" "); index2 = FileLine.indexOf(" ", index1+1); xsize = getiValue(FileLine.substring(0, index1)); ys = getiValue(FileLine.substring(index1+1, index2)); zs = getiValue(FileLine.substring(index2+1)); break; default: IJ.showMessage("fidOpener", "File type not supported."); break; } } if (FileLine.startsWith("##$NI=")) { ni = getiValue(FileLine.substring(6, FileLine.length())); } if (FileLine.startsWith("##$NR=")) { nr = getiValue(FileLine.substring(6, FileLine.length())); } } f.close(); if (dimensions == 2) { if (ni == 1) {ysize = ys; zsize = nr;} else {ysize = ni; zsize = ys*nr;} } if (dimensions == 3) { ysize = ni*ys; zsize = nr*zs; } if (xsize < 256) xsize = 256; IJ.log("ni, nr = " +ni +", " + nr); IJ.log("dimensions = " +dimensions); IJ.log("xsize, ysize, zsize = " +xsize +", " +ysize +", " +zsize); } catch (IOException e) { IJ.showMessage("fidOpener", "File acqp not found."); xsize = 0; } 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) { 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 +"'"); } double getdValue(String theText) { Double d; try {d = new Double(theText);} catch (NumberFormatException e){ IJ.showMessage("fidOpener", "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("fidOpener", "Cannot convert " +theText +" to int."); d = null; } return d.intValue(); } }