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 2dseq 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 03/08/04 */ public class seqOpener extends ImagePlus implements PlugIn { private static int xsize=1; private static int ysize=1; private static int zsize=1; private static int ymin=0; private static int dattype=0; private static int imagetype=0; private String byteOrder = ""; public void run(String path) { String FileLine; int index; File theFile=new File(path); String directory = theFile.getParent(); String fileName = theFile.getName(); File reco = new File(directory, "reco"); File proc2s = new File(directory, "proc2s"); File d3proc = new File(directory, "d3proc"); if (reco.exists()) read_reco(reco); // this seems to be a ParaVision file else if (proc2s.exists()) read_proc2s(proc2s); // this seems to be a XWinNMR file try { RandomAccessFile f = new RandomAccessFile(d3proc, "r"); // IJ.log("reading " +d3proc.getPath()); while ((FileLine = f.readLine()) != null) { index = FileLine.indexOf("="); if (FileLine.startsWith("##$IM_SIX=")) { xsize = getiValue(FileLine.substring(index+1).trim()); } if (FileLine.startsWith("##$IM_SIY=")) { ysize = getiValue(FileLine.substring(index+1).trim()); } if (FileLine.startsWith("##$IM_SIZ=")) { zsize = getiValue(FileLine.substring(index+1).trim()); } if (FileLine.startsWith("##$DATTYPE= ")) { dattype = getiValue(FileLine.substring(index+1).trim()); } } f.close(); } catch (IOException e) { IJ.showMessage("seqOpener", "File d3proc not found."); dattype = 0; } File titlefile = new File(directory, "title"); try { RandomAccessFile f = new RandomAccessFile(titlefile, "r"); FileLine = f.readLine(); f.close(); } catch (IOException e) { FileLine = fileName; } switch (dattype) { case 0: ImportDialog id = new ImportDialog(fileName, directory); id.openImage(); break; case 1: IJ.run("Raw...", "open='" +path +"' image='8-bit' width=" +xsize +" height=" + ysize +" offset=0 number=" +zsize +" gap=0" +byteOrder); break; case 2: IJ.run("Raw...", "open='" +path +"' image='16-bit Signed' width=" +xsize +" height=" + ysize +" offset=0 number=" +zsize +" gap=0" +byteOrder); break; case 12: IJ.run("Raw...", "open='" +path +"' image='16-bit Signed' width=" +xsize +" height=" + ysize +" offset=0 number=" +zsize +" gap=0" +byteOrder); break; case 3: IJ.run("Raw...", "open='" +path +"' image='16-bit Unsigned' width=" +xsize +" height=" + ysize +" offset=0 number=" +zsize +" gap=0" +byteOrder); break; case 4: IJ.run("Raw...", "open='" +path +"' image='32-bit Signed' width=" +xsize +" height=" + ysize +" offset=0 number=" +zsize +" gap=0" +byteOrder); break; case 5: IJ.run("Raw...", "open='" +path +"' image='32-bit Unsigned' width=" +xsize +" height=" + ysize +" offset=0 number=" +zsize +" gap=0" +byteOrder); break; default: IJ.run("Raw...", "open='" +path +"' image='32-bit Unsigned' width=" +xsize +" height=" + ysize +" offset=0 number=" +zsize +" gap=0" +byteOrder); break; } IJ.run("Rename...", "title='" +FileLine +"'"); } void read_reco(File reco) { String FileLine; int index; // IJ.log("reading " +reco.getPath()); if (!reco.canRead()) { IJ.showMessage("seqOpener", "Cannot read " +reco.getPath() +"."); return; } try { RandomAccessFile f = new RandomAccessFile(reco, "r"); while ((FileLine = f.readLine()) != null) { index = FileLine.indexOf("="); if (FileLine.startsWith("##$RECO_wordtype=")) { if (FileLine.substring(index+1).equalsIgnoreCase("_8bit_unsgn_int")) dattype = 1; if (FileLine.substring(index+1).equalsIgnoreCase("_16bit_sgn_int")) dattype = 2; if (FileLine.substring(index+1).equalsIgnoreCase("_32bit_sgn_int")) dattype = 4; } if (FileLine.startsWith("##$RECO_image_type=")) { if (FileLine.substring(index+1).equalsIgnoreCase("magnitude_image")) imagetype = 0; else imagetype = 1; } if (FileLine.startsWith("##$RECO_byte_order=")) { if (FileLine.substring(index+1).equalsIgnoreCase("bigendian")) byteOrder = ""; if (FileLine.substring(index+1).equalsIgnoreCase("littleendian")) byteOrder = " little-endian"; } } f.close(); } catch (IOException e) { IJ.showMessage("seqOpener", "File reco not found."); dattype = 0; } } void read_proc2s(File proc2s) { String FileLine; int index, ivalue; if (!proc2s.canRead()) { IJ.showMessage("seqOpener", "Cannot read " +proc2s.getPath() +"."); return; } // IJ.log("reading " +proc2s.getPath()); try { RandomAccessFile f = new RandomAccessFile(proc2s, "r"); while ((FileLine = f.readLine()) != null) { index = FileLine.indexOf("="); if (FileLine.startsWith("##$BYTORDP=")) { ivalue = getiValue(FileLine.substring(index+1).trim()); if (ivalue < 1) byteOrder = ""; else byteOrder = " little-endian"; } } } catch (IOException e) { IJ.showMessage("seqOpener", "File proc2s not found."); dattype = 0; } } double getdValue(String theText) { Double d; try {d = new Double(theText);} catch (NumberFormatException e){ IJ.showMessage("seqOpener", "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("seqOpener", "Cannot convert " +theText +" to int."); d = null; } return d.intValue(); } }