| 61 | import nom.tam.util.Cursor; |
| 62 | |
| 63 | public class FitsReader implements AutoCloseable { |
| 64 | public static boolean skipTessQualCheck = Prefs.getBoolean(".aij.skipTessQualCheck", false); |
| 65 | private static final LeapSeconds LEAP_SECONDS = new LeapSeconds(); |
| 66 | private final Fits fits; |
| 67 | private final List<HDUDescriptor> hduDescriptors; |
| 68 | private final BasicHDU<?>[] hdus; |
| 69 | private int firstImageIndex = -1; |
| 70 | private int width = 0; |
| 71 | private int height = 0; |
| 72 | private int depth = 0; |
| 73 | private double bZero = 0.0; |
| 74 | private double bScale = 0.0; |
| 75 | private final String directory; |
| 76 | public final String fileName; |
| 77 | public String fileBase; |
| 78 | public String fileType; |
| 79 | private ImageProcessor[] cachedProcessors; |
| 80 | private String[] cachedHeaders; |
| 81 | private boolean isMeasurementsTable; |
| 82 | |
| 83 | private FitsReader(Path path, String directory, String fileName) throws IOException { |
| 84 | FitsFactory.setAllowHeaderRepairs(true); |
| 85 | this(new Fits(path.toFile()), directory, fileName); |
| 86 | } |
| 87 | |
| 88 | private FitsReader(Fits fits, String directory, String fileName) throws IOException { |
| 89 | this.directory = directory; |
| 90 | this.fileName = fileName; |
| 91 | this.fits = fits; |
| 92 | this.hdus = fits.read(); // Reads to end of File, and for RandomAccess files skips reading data |
| 93 | hduDescriptors = new ArrayList<>(fits.getNumberOfHDUs()); |
| 94 | |
| 95 | for (int i = 0; i < fits.getNumberOfHDUs(); i++) { |
| 96 | hduDescriptors.add(new HDUDescriptor(fits.getHDU(i))); |
| 97 | } |
| 98 | |
| 99 | setupImageData(); |
| 100 | } |
| 101 | |
| 102 | public static FitsReader create(String path) throws IOException { |
| 103 | OpenDialog od = new OpenDialog("Open FITS...", path); |
| 104 | var directory = od.getDirectory(); |
| 105 | var fileName = od.getFileName(); |
| 106 | if (fileName == null) { |
| 107 | throw new FitsException("Null filename."); |
| 108 | } |
| 109 | |
| 110 | IJ.showStatus("Opening: " + directory + fileName); |
| 111 | |
| 112 | if (isFileWithinZip(path)) { |
| 113 | var s = path.split("\\.zip"); |
| 114 | |
| 115 | try (var zip = new ZipFile(s[0] + ".zip")) { |
| 116 | var m = new ProgressMonitorInputStream(IJ.getInstance(), |
| 117 | "Reading FITS image", zip.getInputStream(zip.getEntry(s[1].substring(1)))); |
| 118 | FitsFactory.setAllowHeaderRepairs(true); |
| 119 | return new FitsReader(new Fits(m), directory, fileName); |
| 120 | } |
nothing calls this directly
no test coverage detected