cdm/src/main/java/ucar/nc2/iosp/IospHelper.java
static public Object makePrimitiveArray(int size, DataType dataType, Object fillValue) {

    if (dataType.getPrimitiveClassType() == byte.class || (dataType == DataType.CHAR)) {
      byte[] pa = new byte[size];
      byte val = ((Number) fillValue).byteValue();
      if (val != 0)
        for (int i = 0; i < size; i++) pa[i] = val;
      // if (dataType == DataType.CHAR) return convertByteToChar(pa);
      return pa;

    } else if (dataType == DataType.OPAQUE) {
      return new byte[size];

    } else if (dataType.getPrimitiveClassType() == short.class) {
      short[] pa = new short[size];
      short val = ((Number) fillValue).shortValue();
      if (val != 0)
        for (int i = 0; i < size; i++) pa[i] = val;
      return pa;

    } else if (dataType.getPrimitiveClassType() == int.class) {
      int[] pa = new int[size];
      int val = ((Number) fillValue).intValue();
      if (val != 0)
        for (int i = 0; i < size; i++) pa[i] = val;
      return pa;

    } else if (dataType.getPrimitiveClassType() == long.class) {
      long[] pa = new long[size];
      long val = ((Number) fillValue).longValue();
      if (val != 0)
        for (int i = 0; i < size; i++) pa[i] = val;
      return pa;

    } else if (dataType == DataType.FLOAT) {
      float[] pa = new float[size];
      float val = ((Number) fillValue).floatValue();
      if (val != 0.0)
        for (int i = 0; i < size; i++) pa[i] = val;
      return pa;

    } else if (dataType == DataType.DOUBLE) {
      double[] pa = new double[size];
      double val = ((Number) fillValue).doubleValue();
      if (val != 0.0)
        for (int i = 0; i < size; i++) pa[i] = val;
      return pa;

    } else if (dataType == DataType.STRING) {
      String[] pa = new String[size];
      for (int i = 0; i < size; i++) pa[i] = (String) fillValue;
      return pa;

    } else if (dataType == DataType.STRUCTURE) {
      byte[] pa = new byte[size];
      if (fillValue != null) {
        byte[] val = (byte[]) fillValue;
        int count = 0;
        while (count < size)
          for (byte aVal : val) pa[count++] = aVal;
      }
      return pa;
    }

    throw new IllegalStateException();
  }
static public Object makePrimitiveArray(int size, DataType dataType, Object fillValue) {

    if (dataType.getPrimitiveClassType() == byte.class || (dataType == DataType.CHAR)) {
      byte[] pa = new byte[size];
      byte val = ((Number) fillValue).byteValue();
      if (val != 0)
        for (int i = 0; i < size; i++) pa[i] = val;
      // if (dataType == DataType.CHAR) return convertByteToChar(pa);
      return pa;

    } else if (dataType == DataType.OPAQUE) {
      return new byte[size];

    } else if (dataType.getPrimitiveClassType() == short.class) {
      short[] pa = new short[size];
      short val = ((Number) fillValue).shortValue();
      if (val != 0)
        for (int i = 0; i < size; i++) pa[i] = val;
      return pa;

    } else if (dataType.getPrimitiveClassType() == int.class) {
      int[] pa = new int[size];
      int val = ((Number) fillValue).intValue();
      if (val != 0)
        for (int i = 0; i < size; i++) pa[i] = val;
      return pa;

    } else if (dataType.getPrimitiveClassType() == long.class) {
      long[] pa = new long[size];
      long val = ((Number) fillValue).longValue();
      if (val != 0)
        for (int i = 0; i < size; i++) pa[i] = val;
      return pa;

    } else if (dataType == DataType.FLOAT) {
      float[] pa = new float[size];
      float val = ((Number) fillValue).floatValue();
      if (val != 0.0)
        for (int i = 0; i < size; i++) pa[i] = val;
      return pa;

    } else if (dataType == DataType.DOUBLE) {
      double[] pa = new double[size];
      double val = ((Number) fillValue).doubleValue();
      if (val != 0.0)
        for (int i = 0; i < size; i++) pa[i] = val;
      return pa;

    } else if (dataType == DataType.STRING) {
      String[] pa = new String[size];
      for (int i = 0; i < size; i++) pa[i] = (String) fillValue;
      return pa;

    } else if (dataType == DataType.STRUCTURE) {
      byte[] pa = new byte[size];
      if (fillValue != null) {
        byte[] val = (byte[]) fillValue;
        int count = 0;
        while (count < size)
          for (byte aVal : val) pa[count++] = aVal;
      }
      return pa;
    }

    throw new IllegalStateException();
  }
static public Object makePrimitiveArray ( int size , DataType dataType , Object fillValue ) { if ( dataType . getPrimitiveClassType ( ) == byte . class || ( dataType == DataType . CHAR ) ) { byte [ ] pa = new byte [ size ] ; byte val = ( ( Number ) fillValue ) . byteValue ( ) ; if ( val != 0 ) for ( int i = 0 ; i < size ; i ++ ) pa [ i ] = val ; // if (dataType == DataType.CHAR) return convertByteToChar(pa);
 return pa ; } else if ( dataType == DataType . OPAQUE ) { return new byte [ size ] ; } else if ( dataType . getPrimitiveClassType ( ) == short . class ) { short [ ] pa = new short [ size ] ; short val = ( ( Number ) fillValue ) . shortValue ( ) ; if ( val != 0 ) for ( int i = 0 ; i < size ; i ++ ) pa [ i ] = val ; return pa ; } else if ( dataType . getPrimitiveClassType ( ) == int . class ) { int [ ] pa = new int [ size ] ; int val = ( ( Number ) fillValue ) . intValue ( ) ; if ( val != 0 ) for ( int i = 0 ; i < size ; i ++ ) pa [ i ] = val ; return pa ; } else if ( dataType . getPrimitiveClassType ( ) == long . class ) { long [ ] pa = new long [ size ] ; long val = ( ( Number ) fillValue ) . longValue ( ) ; if ( val != 0 ) for ( int i = 0 ; i < size ; i ++ ) pa [ i ] = val ; return pa ; } else if ( dataType == DataType . FLOAT ) { float [ ] pa = new float [ size ] ; float val = ( ( Number ) fillValue ) . floatValue ( ) ; if ( val != 0.0 ) for ( int i = 0 ; i < size ; i ++ ) pa [ i ] = val ; return pa ; } else if ( dataType == DataType . DOUBLE ) { double [ ] pa = new double [ size ] ; double val = ( ( Number ) fillValue ) . doubleValue ( ) ; if ( val != 0.0 ) for ( int i = 0 ; i < size ; i ++ ) pa [ i ] = val ; return pa ; } else if ( dataType == DataType . STRING ) { String [ ] pa = new String [ size ] ; for ( int i = 0 ; i < size ; i ++ ) pa [ i ] = ( String ) fillValue ; return pa ; } else if ( dataType == DataType . STRUCTURE ) { byte [ ] pa = new byte [ size ] ; if ( fillValue != null ) { byte [ ] val = ( byte [ ] ) fillValue ; int count = 0 ; while ( count < size ) for ( byte aVal : val ) pa [ count ++ ] = aVal ; } return pa ; } throw new IllegalStateException ( ) ; }
Create 1D primitive array of the given size and type, fill it with the given value

@param size      the size of the array to create
@param dataType  dataType of the variable
@param fillValue must be Number if dataType.isNumeric(), or String for STRING, byte[] for Structure, or null for none
@return primitive array with data read in
Create 1D primitive array of the given size and type fill it with the given value