Skip to content

Commit

Permalink
Merge pull request #95 from at88mph/nom-tam-fits-1-18
Browse files Browse the repository at this point in the history
Nom tam fits 1 18
  • Loading branch information
pdowler authored Aug 3, 2023
2 parents a22ec79 + 98e56d2 commit d2954d2
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 196 deletions.
16 changes: 8 additions & 8 deletions cadc-data-ops-fits/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ repositories {

sourceCompatibility = 1.8
group = 'org.opencadc'
version = '0.2.9'
version = '0.3.0'

description = 'OpenCADC FITS cutout library'
def git_url = 'https://github.com/opencadc/dal'

dependencies {
compile 'org.opencadc:cadc-dali:[1.2.10,2.0.0)'
compile 'org.opencadc:cadc-util:[1.6,2.0)'
compile 'org.opencadc:cadc-soda-server:[1.2.1,2.0)'
compile 'org.opencadc:cadc-wcs:[2.0,3.0)'
compile 'org.opencadc:jsky:[1.0.0,2.0.0)'
compile 'org.opencadc:nom-tam-fits:[1.16.8,1.17.0)'
implementation 'org.opencadc:cadc-dali:[1.2.10,2.0.0)'
implementation 'org.opencadc:cadc-util:[1.6,2.0)'
implementation 'org.opencadc:cadc-soda-server:[1.2.1,2.0)'
implementation 'org.opencadc:cadc-wcs:[2.1.4,3.0)'
implementation 'org.opencadc:jsky:[1.0.0,2.0.0)'
implementation 'gov.nasa.gsfc.heasarc:nom-tam-fits:1.18.0'

// Use JUnit test framework
testCompile 'junit:junit:[4.13,5.0)'
testImplementation 'junit:junit:[4.13,5.0)'
}

apply from: '../opencadc.gradle'
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
import nom.tam.fits.Header;
import nom.tam.fits.HeaderCard;
import nom.tam.util.Cursor;
import nom.tam.util.RandomAccessDataObject;
import nom.tam.util.RandomAccessFileIO;
import org.apache.log4j.Logger;
import org.opencadc.fits.slice.NDimensionalSlicer;
import org.opencadc.soda.server.Cutout;
Expand All @@ -96,9 +96,9 @@
public class FitsOperations {
private static final Logger log = Logger.getLogger(FitsOperations.class);

private final RandomAccessDataObject src;
private final RandomAccessFileIO src;

public FitsOperations(RandomAccessDataObject src) {
public FitsOperations(RandomAccessFileIO src) {
this.src = src;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
************************************************************************
******************* CANADIAN ASTRONOMY DATA CENTRE *******************
************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES **************
*
* (c) 2023. (c) 2023.
* Government of Canada Gouvernement du Canada
* National Research Council Conseil national de recherches
* Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R6
* All rights reserved Tous droits réservés
*
* NRC disclaims any warranties, Le CNRC dénie toute garantie
* expressed, implied, or énoncée, implicite ou légale,
* statutory, of any kind with de quelque nature que ce
* respect to the software, soit, concernant le logiciel,
* including without limitation y compris sans restriction
* any warranty of merchantability toute garantie de valeur
* or fitness for a particular marchande ou de pertinence
* purpose. NRC shall not be pour un usage particulier.
* liable in any event for any Le CNRC ne pourra en aucun cas
* damages, whether direct or être tenu responsable de tout
* indirect, special or general, dommage, direct ou indirect,
* consequential or incidental, particulier ou général,
* arising from the use of the accessoire ou fortuit, résultant
* software. Neither the name de l'utilisation du logiciel. Ni
* of the National Research le nom du Conseil National de
* Council of Canada nor the Recherches du Canada ni les noms
* names of its contributors may de ses participants ne peuvent
* be used to endorse or promote être utilisés pour approuver ou
* products derived from this promouvoir les produits dérivés
* software without specific prior de ce logiciel sans autorisation
* written permission. préalable et particulière
* par écrit.
*
* This file is part of the Ce fichier fait partie du projet
* OpenCADC project. OpenCADC.
*
* OpenCADC is free software: OpenCADC est un logiciel libre ;
* you can redistribute it and/or vous pouvez le redistribuer ou le
* modify it under the terms of modifier suivant les termes de
* the GNU Affero General Public la “GNU Affero General Public
* License as published by the License” telle que publiée
* Free Software Foundation, par la Free Software Foundation
* either version 3 of the : soit la version 3 de cette
* License, or (at your option) licence, soit (à votre gré)
* any later version. toute version ultérieure.
*
* OpenCADC is distributed in the OpenCADC est distribué
* hope that it will be useful, dans l’espoir qu’il vous
* but WITHOUT ANY WARRANTY; sera utile, mais SANS AUCUNE
* without even the implied GARANTIE : sans même la garantie
* warranty of MERCHANTABILITY implicite de COMMERCIALISABILITÉ
* or FITNESS FOR A PARTICULAR ni d’ADÉQUATION À UN OBJECTIF
* PURPOSE. See the GNU Affero PARTICULIER. Consultez la Licence
* General Public License for Générale Publique GNU Affero
* more details. pour plus de détails.
*
* You should have received Vous devriez avoir reçu une
* a copy of the GNU Affero copie de la Licence Générale
* General Public License along Publique GNU Affero avec
* with OpenCADC. If not, see OpenCADC ; si ce n’est
* <http://www.gnu.org/licenses/>. pas le cas, consultez :
* <http://www.gnu.org/licenses/>.
*
*
************************************************************************
*/

package org.opencadc.fits;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

import nom.tam.util.RandomAccessFileIO;


public class RandomAccessStorageObject extends RandomAccessFile implements RandomAccessFileIO {
public RandomAccessStorageObject(File file, String mode) throws FileNotFoundException {
super(file, mode);
}

@Override
public long position() throws IOException {
return super.getFilePointer();
}

@Override
public void position(long n) throws IOException {
super.seek(n);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import java.util.Iterator;
import java.util.Map;

import nom.tam.fits.FitsFactory;
import nom.tam.fits.Header;
import nom.tam.fits.HeaderCard;
import nom.tam.fits.HeaderCardException;
Expand Down Expand Up @@ -407,39 +408,54 @@ private Header cloneHeader(final Header source) throws HeaderCardException {
return destination;
}

/**
* Copy a header card with some potential modifications. COMMENT and HISTORY cards are truncated to the
* maximum length.
* @param destination The Header to write to.
* @param headerCardKey The current key.
* @param valueType The class type of the value.
* @param comment The comment value for COMMENT or HISTORY values.
* @param value The string value.
* @throws HeaderCardException
*/
private void cloneHeaderCard(final Header destination, final String headerCardKey, final Class<?> valueType,
final String comment, final String value) throws HeaderCardException {
// Check for blank lines or just plain comments that are not standard FITS comments.
if (!StringUtil.hasText(headerCardKey)) {
destination.addValue(headerCardKey, (String) null, comment);
} else if (Standard.COMMENT.key().equals(headerCardKey)) {
destination.insertComment(comment);
if (StringUtil.hasText(comment) && comment.length() > HeaderCard.MAX_COMMENT_CARD_COMMENT_LENGTH) {
destination.insertComment(comment.substring(0, HeaderCard.MAX_COMMENT_CARD_COMMENT_LENGTH));
} else {
destination.insertComment(comment);
}
} else if (Standard.HISTORY.key().equals(headerCardKey)) {
destination.insertHistory(comment);
if (StringUtil.hasText(comment) && comment.length() > HeaderCard.MAX_COMMENT_CARD_COMMENT_LENGTH) {
destination.insertHistory(comment.substring(0, HeaderCard.MAX_COMMENT_CARD_COMMENT_LENGTH));
} else {
destination.insertHistory(comment);
}
} else if (headerCardKey.startsWith(CADCExt.CDELT.key())) {
// CDELT values cannot be zero.
final double cdeltValue = Double.parseDouble(value);
destination.addValue(headerCardKey, cdeltValue == 0.0D ? 1.0D : cdeltValue,
comment);
destination.addValue(headerCardKey, cdeltValue == 0.0D ? 1.0D : cdeltValue, comment);
} else {
if (valueType == String.class || valueType == null) {
destination.addValue(headerCardKey, value, comment);
} else if (valueType == Boolean.class) {
destination.addValue(headerCardKey, Boolean.parseBoolean(value) || value.equals("T"), comment);
} else if (valueType == Integer.class) {
destination.addValue(headerCardKey, Integer.parseInt(value),
comment);
destination.addValue(headerCardKey, Integer.parseInt(value), comment);
} else if (valueType == BigInteger.class) {
destination.addValue(headerCardKey, new BigInteger(value), comment);
} else if (valueType == Long.class) {
destination.addValue(headerCardKey, Long.parseLong(value),
comment);
destination.addValue(headerCardKey, Long.parseLong(value), comment);
} else if (valueType == Double.class) {
destination.addValue(headerCardKey, Double.parseDouble(value),
comment);
destination.addValue(headerCardKey, Double.parseDouble(value), comment);
} else if (valueType == BigDecimal.class) {
destination.addValue(headerCardKey, new BigDecimal(value),
comment);
destination.addValue(headerCardKey, new BigDecimal(value), comment);
} else if (valueType == Float.class) {
destination.addValue(headerCardKey, Float.parseFloat(value), comment);
}
}
}
Expand Down
Loading

0 comments on commit d2954d2

Please sign in to comment.