16 public void run(String path) {
17 File pf =
new File(path);
18 String directory = pf.getName();
19 String fileName = pf.getParent();
21 FitsDecoder fd =
new FitsDecoder(directory, fileName);
23 try {fi = fd.getInfo();}
24 catch (IOException e) {}
25 if (fi!=null && fi.width>0 && fi.height>0 && fi.offset>0) {
26 FileOpener fo =
new FileOpener(fi);
32 if (fi.fileType==FileInfo.GRAY16_SIGNED && fd.bscale==1.0 && fd.bzero==32768.0)
37 if (path.equals(
""))
show();
39 IJ.
error(
"This does not appear to be a FITS file.");
46 private String directory, fileName;
47 private DataInputStream f;
48 private StringBuffer info =
new StringBuffer(512);
51 public FitsDecoder(String directory, String fileName) {
52 this.directory = directory;
53 this.fileName = fileName;
56 FileInfo getInfo() throws IOException {
57 FileInfo fi =
new FileInfo();
58 fi.fileFormat = FileInfo.FITS;
59 fi.fileName = fileName;
60 fi.directory = directory;
65 f =
new DataInputStream(
new FileInputStream(directory + fileName));
66 String line = getString(80);
67 info.append(line+
"\n");
68 if (!line.startsWith(
"SIMPLE"))
69 {f.close();
return null;}
75 info.append(line+
"\n");
78 int index = line.indexOf (
"=" );
81 int commentIndex = line.indexOf (
"/", index );
82 if ( commentIndex < 0 )
84 commentIndex = line.length ();
92 key = line.substring ( 0, index ).trim ();
93 value = line.substring ( index + 1, commentIndex ).trim ();
102 if (key.equals (
"END") )
break;
105 if (key.equals(
"BITPIX")) {
106 int bitsPerPixel = Integer.parseInt ( value );
108 fi.fileType = FileInfo.GRAY8;
109 else if (bitsPerPixel==16)
110 fi.fileType = FileInfo.GRAY16_SIGNED;
111 else if (bitsPerPixel==32)
112 fi.fileType = FileInfo.GRAY32_INT;
113 else if (bitsPerPixel==-32)
114 fi.fileType = FileInfo.GRAY32_FLOAT;
116 IJ.error(
"BITPIX must be 8, 16, 32 or -32 (float).");
120 }
else if (key.equals(
"NAXIS1"))
121 fi.width = Integer.parseInt ( value );
122 else if (key.equals(
"NAXIS2"))
123 fi.height = Integer.parseInt( value );
124 else if (key.equals(
"NAXIS3"))
125 fi.nImages = Integer.parseInt ( value );
126 else if (key.equals(
"BSCALE"))
127 bscale = parseDouble ( value );
128 else if (key.equals(
"BZERO"))
129 bzero = parseDouble ( value );
131 if (count>360 && fi.width==0)
132 {f.close();
return null;}
136 fi.offset = 2880+2880*(((count*80)-1)/2880);
140 String getString(
int length)
throws IOException {
141 byte[] b =
new byte[length];
143 return new String(b);
146 int getInteger(String s) {
147 s = s.substring(10, 30);
149 return Integer.parseInt(s);
152 double parseDouble(String s)
throws NumberFormatException {
153 Double d =
new Double(s);
154 return d.doubleValue();
157 String getHeaderInfo() {
158 return new String(info);