public static float[] convertQuasiGrid(float[] quasi, int[] linePts, int nx, int ny, GribData.InterpolationMethod interpolationMethod) {

    if (interpolationMethod == GribData.InterpolationMethod.none) return quasi;


    //int nrows;   /* number of rows in input */
    // int ix[]; /* row i starts at idat[ix[i]], and ix[nrows] is 1 after
    // last elem of idat */
    //float *idat; /* input quasi-regular data */
    //int ni;      /* constant length of each output row */
    //int nj;      /* number of output rows */
    //float *odat; /* where to put ni*nj outputs, already allocated */

    int max = getMax(linePts);
    if (nx < 0) {
      assert ny == linePts.length;
      nx = max;
    } else {
      assert ny < 0;
      assert nx == linePts.length;
      ny = max;
    }

    double x1_der = 1.0e30;  /* derivative of the first end point */
    double xn_der = 1.0e30;  /* derivative of the nth end point */
    double[] second_d;         /* second derivatives of input row */
    int inputIdx = 0;    /* current index position in input */
    int outputIdx = 0;    /* current index position in output */

    float[] data = new float[nx * ny];

    if (interpolationMethod == GribData.InterpolationMethod.cubic) {

      for (int j = 0; j < ny; j++) { // LOOK - assumes varies by x
        //int inrow;            /* input row to use */
        int npoints;  /* number input points in current parrallel */

        //inrow = j * (nrows - 1) / (nj - 1);  /* set the row number */
        //npoints = ix[inrow+1] - ix[inrow];   /* set number of input points */
        npoints = linePts[j];  /* number of input points in this parellel */

        // skip the processing if npoints = number of points in output parrallel
        if (npoints == nx) {
          for (int i = 0; i < nx; i++) {
            data[outputIdx++] = quasi[inputIdx++];
          }
          continue;
        }
        //second_d = (float *)emalloc(npoints * sizeof(double));
        second_d = new double[npoints];

      /* calculate the second derivatives of the input row */
        secondDerivative(
                //&idat[ix[inrow]], /* input row */
                quasi,                /* input data */
                inputIdx,             /* current index position in input */
                npoints,              /*  number of points in input row */
                x1_der,               /* first derivative of first element */
                xn_der,               /* first derivative of nth element */
                second_d);            /* output second derivative */

      /* interpolate the output row */
        for (int i = 0; i < nx; i++) {
          double mapped_i;  /* i mapped to input space */
          mapped_i = (float) i / ((float) nx) * ((float) npoints);

        /* map output point to input space */
          cubicSpline(  /* interpolate the value */
                  quasi,         /* input data */
                  inputIdx,      /* current index position in input */
                  second_d,      /* calculated second derivatives */
                  mapped_i,      /* element to be interpolated */
                  data,          /* output data */
                  outputIdx++);  /* where to put the interpolated value */
        }
        inputIdx += npoints;
      }

    } else if (interpolationMethod == GribData.InterpolationMethod.linear) { // =>
      // USE_LINEAR

      for (int j = 0; j < ny; j++) { // LOOK - assumes varies by x
        // int inrow; /* input row to use */
        // inrow = j * (nrows - 1) / (nj - 1); /* set the row number */
        // npoints = ix[inrow+1] - ix[inrow]; /* set number of input points */
        int npoints = linePts[j]; /* number of input points in this parallel */

        // skip the processing if npoints = number of points in output
        // parallel
        if (npoints == nx) {
          for (int i = 0; i < nx; i++)
            data[outputIdx++] = quasi[inputIdx++];
          continue;
        }

        for (int i = 0; i < nx; i++) {
          double mapped_i = (float) i / ((float) nx) * ((float) npoints); // i mapped to input space

          // interpolate this point
          linear( quasi, /* input data */
                  inputIdx, /* current index position in input */
                  mapped_i, /* element to be interpolated */
                  data,     /* output data */
                  outputIdx++, /* where to put the interpolated value */
                  npoints);
        }

        inputIdx += npoints;
      }

    } else {
      throw new RuntimeException("unsupported interpolation method");
    }

    return data;
  }
public static float [ ] convertQuasiGrid ( float [ ] quasi , int [ ] linePts , int nx , int ny , GribData . InterpolationMethod interpolationMethod ) { if ( interpolationMethod == GribData . InterpolationMethod . none ) return quasi ; int max = getMax ( linePts ) ; if ( nx < 0 ) { assert ny == linePts . length ; nx = max ; } else { assert ny < 0 ; assert nx == linePts . length ; ny = max ; } double x1_der = 1.0e30 ; double xn_der = 1.0e30 ; double [ ] second_d ; int inputIdx = 0 ; int outputIdx = 0 ; float [ ] data = new float [ nx * ny ] ; if ( interpolationMethod == GribData . InterpolationMethod . cubic ) { for ( int j = 0 ; j < ny ; j ++ ) { int npoints ; npoints = linePts [ j ] ; if ( npoints == nx ) { for ( int i = 0 ; i < nx ; i ++ ) { data [ outputIdx ++ ] = quasi [ inputIdx ++ ] ; } continue ; } second_d = new double [ npoints ] ; secondDerivative ( quasi , inputIdx , npoints , x1_der , xn_der , second_d ) ; for ( int i = 0 ; i < nx ; i ++ ) { double mapped_i ; mapped_i = ( float ) i / ( ( float ) nx ) * ( ( float ) npoints ) ; cubicSpline ( quasi , inputIdx , second_d , mapped_i , data , outputIdx ++ ) ; } inputIdx += npoints ; } } else if ( interpolationMethod == GribData . InterpolationMethod . linear ) { for ( int j = 0 ; j < ny ; j ++ ) { int npoints = linePts [ j ] ; if ( npoints == nx ) { for ( int i = 0 ; i < nx ; i ++ ) data [ outputIdx ++ ] = quasi [ inputIdx ++ ] ; continue ; } for ( int i = 0 ; i < nx ; i ++ ) { double mapped_i = ( float ) i / ( ( float ) nx ) * ( ( float ) npoints ) ; linear ( quasi , inputIdx , mapped_i , data , outputIdx ++ , npoints ) ; } inputIdx += npoints ; } } else { throw new RuntimeException ( "unsupported interpolation method" ) ; } return data ; }
@param quasi   input data
@param linePts npts in each line
@param nx      num parellels or undefined
@param ny      num parellels or undefined
@return regular grid