Java Array One Dimension to Two Dimension array1DTo2D(final Object data, final int bitpix, final int width, final int height)

Here you can find the source of array1DTo2D(final Object data, final int bitpix, final int width, final int height)

Description

Converts a Fits data 1D to 2D.

License

Open Source License

Parameter

Parameter Description
data data to convert
bitpix bitpix value
width number of pixels along X axis
height number of pixels along Y axis

Return

the fits 2D

Declaration

public static Object array1DTo2D(final Object data, final int bitpix, final int width, final int height) 

Method Source Code

//package com.java2s;
/*******************************************************************************
* Copyright 2010-2014 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
*
* This file is part of SITools2.//from   www  .  j  av  a 2  s  .  c  o  m
*
* SITools2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SITools2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

public class Main {
    /**
     * Converts a Fits data 1D to 2D.
     *
     * @param data data to convert
     * @param bitpix bitpix value
     * @param width number of pixels along X axis
     * @param height number of pixels along Y axis
     * @return the fits 2D
     */
    public static Object array1DTo2D(final Object data, final int bitpix, final int width, final int height) {
        Object obj;
        switch (bitpix) {
        case 8:
            byte[] dataB = (byte[]) data;
            byte[][] resultB = new byte[height][width];
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    resultB[i][j] = dataB[i * width + j];
                }
            }
            obj = resultB;
            break;
        case 16:
            short[] dataS = (short[]) data;
            short[][] resultS = new short[height][width];
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    resultS[i][j] = dataS[i * width + j];
                }
            }
            obj = resultS;
            break;
        case 32:
            int[] dataI = (int[]) data;
            int[][] resultI = new int[height][width];
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    resultI[i][j] = dataI[i * width + j];
                }
            }
            obj = resultI;
            break;
        case -32:
            float[] dataF = (float[]) data;
            float[][] resultF = new float[height][width];
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    resultF[i][j] = dataF[i * width + j];
                }
            }
            obj = resultF;
            break;
        case -64:
            double[] dataD = (double[]) data;
            double[][] resultD = new double[height][width];
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    resultD[i][j] = dataD[i * width + j];
                }
            }
            obj = resultD;
            break;
        default:
            throw new IllegalArgumentException("BitPix is not supported");
        }
        return obj;
    }
}

Related

  1. array1DTo2D(double[] In, int H)
  2. array1dTo2d(float[] in, int firstDim)
  3. array1Dto2D(int m, int n, double[] b)
  4. array1DTo2D(int[] array1D)
  5. array1Dto2D(int[] d1, int imageWidth, int imageHeight)