Package net.ivoa.fits

Examples of net.ivoa.fits.FitsException


  }

  public int[] getAxes() throws FitsException {
    int nAxis = myHeader.getIntValue("NAXIS", 0);
    if (nAxis < 0) {
      throw new FitsException("Negative NAXIS value " + nAxis);
    }
    if (nAxis > 999) {
      throw new FitsException("NAXIS value " + nAxis + " too large");
    }

    if (nAxis == 0) {
      return null;
    }
View Full Code Here


  /** Indicate that an HDU is the first element of a FITS file. */
  public void setPrimaryHDU(boolean newPrimary) throws FitsException {

    if (newPrimary && !canBePrimary()) {
      throw new FitsException("Invalid attempt to make HDU of type:"
          + this.getClass().getName() + " primary.");
    } else {
      this.isPrimary = newPrimary;
    }

View Full Code Here

    if (i instanceof RandomAccess) {
      try {
        i.skipBytes((int) byteSize);
      } catch (IOException e) {
        throw new FitsException("Unable to skip over data:" + e);
      }

    } else {
      try {
        i.readFully(data);
      } catch (IOException e) {
        throw new FitsException("Unable to read unknown data:" + e);
      }

    }

    int pad = FitsUtil.padding(getTrueSize());
    try {
      if (i.skipBytes(pad) != pad) {
        throw new FitsException("Error skipping padding");
      }
    } catch (IOException e) {
      throw new FitsException("Error reading unknown padding:" + e);
    }
  }
View Full Code Here

    if (data == null) {
      getData();
    }

    if (data == null) {
      throw new FitsException("Null unknown data");
    }

    try {
      o.write(data);
    } catch (IOException e) {
      throw new FitsException("IO Error on unknown data write" + e);
    }

    byte[] padding = new byte[FitsUtil.padding(getTrueSize())];
    try {
      o.write(padding);
    } catch (IOException e) {
      throw new FitsException("Error writing padding: " + e);
    }

  }
View Full Code Here

        setFileOffset(str);

        try {
            str.readArray(dataArray);
        } catch (IOException e) {
            throw new FitsException("IO error reading Random Groups data " + e);
        }
        int pad = FitsUtil.padding(getTrueSize());
        try {
            str.skipBytes(pad);
        } catch (IOException e) {
            throw new FitsException("IO error reading padding.");
        }
    }
View Full Code Here

            str.writeArray(dataArray);
            byte[] padding = new byte[FitsUtil.padding(getTrueSize())];
            str.write(padding);
            str.flush();
        } catch (IOException e) {
            throw new FitsException("IO error writing random groups data " + e);
        }
    }
View Full Code Here

    }

    public void fillHeader(Header h) throws FitsException {

        if (dataArray.length <= 0 || dataArray[0].length != 2) {
            throw new FitsException("Data not conformable to Random Groups");
        }

        int gcount = dataArray.length;
        Object paraSamp = dataArray[0][0];
        Object dataSamp = dataArray[0][1];

        Class pbase = net.ivoa.util.ArrayFuncs.getBaseClass(paraSamp);
        Class dbase = net.ivoa.util.ArrayFuncs.getBaseClass(dataSamp);

        if (pbase != dbase) {
            throw new FitsException(
                    "Data and parameters do not agree in type for random group");
        }

        int[] pdims = net.ivoa.util.ArrayFuncs.getDimensions(paraSamp);
        int[] ddims = net.ivoa.util.ArrayFuncs.getDimensions(dataSamp);

        if (pdims.length != 1) {
            throw new FitsException(
                    "Parameters are not 1 d array for random groups");
        }

        // Got the information we need to build the header.

        h.setSimple(true);
        if (dbase == byte.class) {
            h.setBitpix(8);
        } else if (dbase == short.class) {
            h.setBitpix(16);
        } else if (dbase == char.class) {
            h.setBitpix(-16);
        } else if (dbase == int.class) {
            h.setBitpix(32);
        } else if (dbase == long.class) { // Non-standard
            h.setBitpix(64);
        } else if (dbase == float.class) {
            h.setBitpix(-32);
        } else if (dbase == double.class) {
            h.setBitpix(-64);
        } else {
            throw new FitsException("Data type:" + dbase
                    + " not supported for random groups");
        }

        h.setNaxes(ddims.length + 1);
        h.addValue("NAXIS1", 0, "");
View Full Code Here

    Class baseClass;

    int gCount = h.getIntValue("GCOUNT", 1);
    int pCount = h.getIntValue("PCOUNT", 0);
    if (gCount > 1 || pCount != 0) {
      throw new FitsException("Group data treated as images");
    }

    bitpix = (int) h.getIntValue("BITPIX", 0);

    baseClass = getType(h);

    ndim = h.getIntValue("NAXIS", 0);
    dims = new int[ndim];

    // Note that we have to invert the order of the axes
    // for the FITS file to get the order in the array we
    // are generating.

    byteSize = 1;
    for (i = 0; i < ndim; i += 1) {
      int cdim = h.getIntValue("NAXIS" + (i + 1), 0);
      if (cdim < 0) {
        throw new FitsException("Invalid array dimension:" + cdim);
      }
      byteSize *= cdim;
      dims[ndim - i - 1] = (int) cdim;
    }
    byteSize *= Math.abs(bitpix) / 8;
View Full Code Here

    String classname = dataArray.getClass().getName();

    int[] dimens = ArrayFuncs.getDimensions(dataArray);

    if (dimens == null || dimens.length == 0) {
      throw new FitsException("Image data object not array");
    }

    int bitpix = getBitPix();

    // if this is neither a primary header nor an image extension,
    // make it a primary header
    head.setSimple(true);
    head.setBitpix(bitpix);
    head.setNaxes(dimens.length);

    for (int i = 1; i <= dimens.length; i += 1) {
      if (dimens[i - 1] == -1) {
        throw new FitsException("Unfilled array for dimension: " + i);
      }
      head.setNaxis(i, dimens[dimens.length - i]);
    }
    head.addValue("EXTEND", true, "Extension permitted"); // Just in case!
    head.addValue("PCOUNT", 0, "No extra parameters");
View Full Code Here

      tiler = new ImageDataTiler((RandomAccess) i, ((RandomAccess) i)
          .getFilePointer(), dataDescription);
      try {
        i.skipBytes((int) byteSize);
      } catch (IOException e) {
        throw new FitsException("Unable to skip over data:" + e);
      }

    } else {
      dataArray = ArrayFuncs.newInstance(dataDescription.type,
          dataDescription.dims);
      try {
        i.readArray(dataArray);
      } catch (IOException e) {
        throw new FitsException("Unable to read image data:" + e);
      }

      tiler = new ImageDataTiler(null, 0, dataDescription);
    }

    int pad = FitsUtil.padding(getTrueSize());
    try {
      if (i.skipBytes(pad) != pad) {
        throw new FitsException("Error skipping padding");
      }
    } catch (IOException e) {
      throw new FitsException("Error reading image padding (" + pad
          + " bytes) :" + e);
    }
  }
View Full Code Here

TOP

Related Classes of net.ivoa.fits.FitsException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.