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 3rrr and 3iii files 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 rrr3iiiOpener extends ImagePlus implements PlugIn { private static final int UINT32=0, INT32=1; private static final String[] types = {"uint32","int32"}; private static int xsize=1; private static int ysize=1; private static int zsize=1; private static int xdim=1; private static int ydim=1; private static int zdim=1; private static int ymin=0; public void run(String path) { String FileLine; File theFile=new File(path); String directory = theFile.getParent(); String fileName = theFile.getName(); File procs = new File(directory, "procs"); try { RandomAccessFile f = new RandomAccessFile(procs, "r"); while ((FileLine = f.readLine()) != null) { if (FileLine.startsWith("##$SI= ")) { xsize = getiValue(FileLine.substring(7, FileLine.length())); } if (FileLine.startsWith("##$XDIM= ")) { xdim = getiValue(FileLine.substring(9, FileLine.length())); } if (FileLine.startsWith("##$YMIN_p= ")) { ymin = getiValue(FileLine.substring(11, FileLine.length())); } } f.close(); } catch (IOException e) { IJ.showMessage("rrr3iiiOpener", "File procs not found."); xsize = 0; xdim = 0; } File proc2s = new File(directory, "proc2s"); try { RandomAccessFile f = new RandomAccessFile(proc2s, "r"); while ((FileLine = f.readLine()) != null) { if (FileLine.startsWith("##$SI= ")) { ysize = getiValue(FileLine.substring(7, FileLine.length())); } if (FileLine.startsWith("##$XDIM= ")) { ydim = getiValue(FileLine.substring(9, FileLine.length())); } } f.close(); } catch (IOException e) { IJ.showMessage("rrr3iiiOpener", "File proc2s not found."); ysize = 0; ydim = 0; } File proc3s = new File(directory, "proc3s"); try { RandomAccessFile f = new RandomAccessFile(proc3s, "r"); while ((FileLine = f.readLine()) != null) { if (FileLine.startsWith("##$SI= ")) { zsize = getiValue(FileLine.substring(7, FileLine.length())); } if (FileLine.startsWith("##$XDIM= ")) { zdim = getiValue(FileLine.substring(9, FileLine.length())); } } f.close(); } catch (IOException e) { IJ.showMessage("rrr3iiiOpener", "File proc3s not found."); zsize = 0; zdim = 0; } File titlefile = new File(directory, "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 { if (ymin < 0) { IJ.run("Raw...", "open='" +path +"' image='32-bit Signed' width=" +xsize +" height=" + ysize +" offset=0 number=" +zsize +" gap=0"); } else { IJ.run("Raw...", "open='" +path +"' image='32-bit Unsigned' width=" +xsize +" height=" + ysize +" offset=0 number=" +zsize +" gap=0"); } } IJ.run("Rename...", "title='" +FileLine +"'"); ImagePlus imp = WindowManager.getCurrentImage(); if ((xdim > 0) && (ydim > 0) && (zdim > 0)) Order(imp, xdim, ydim, zdim); } double getdValue(String theText) { Double d; try {d = new Double(theText);} catch (NumberFormatException e){ IJ.showMessage("rrr3iiiOpener", "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("rrr3iiiOpener", "Cannot convert " +theText +" to int."); d = null; } return d.intValue(); } void Order(ImagePlus imp, int xd1, int xd2, int xd3) { float[] DataArray1, DataArray2; int width, height, slices; int h1, i1, j1, h2, i2, j2,l; float helpf; ImageProcessor ip; ImageStack is; String s1; width = imp.getWidth(); height = imp.getHeight(); slices = imp.getStackSize(); is = imp.getStack(); DataArray1 = new float[width*height*slices]; DataArray2 = new float[width*height*slices]; for (h1=0; h1