cdm/src/main/java/ucar/nc2/geotiff/GeoTiffWriter2.java
private double[] getSwathLatLonInformation(Array lat, Array lon) {
    // Calculate the increment of latitude and longitude of original swath data
    // Calculate the size of the boundingBox
    // element0: Longitude increment
    // element1: Latitude increment
    // element2: minLat
    // element3: maxLat
    // element4: minLon
    // element5: maxLon
    // element6: width of the boundingBox
    // element7: height of the boundingBox
    double increment[] = {0, 0, 0, 0, 0, 0, 0, 0};
    IndexIterator latIter = lat.getIndexIterator();
    IndexIterator lonIter = lon.getIndexIterator();

    int numScan = (lat.getShape())[0];
    int numSample = (lat.getShape())[1];

    double maxLat = -91,
            minLat = 91,
            maxLon = -181,
            minLon = 181;

    float firstLineStartLat = 0;
    float firstLineStartLon = 0;
    float firstLineEndLat = 0;
    float firstLineEndLon = 0;
    float lastLineStartLat = 0;
    float lastLineStartLon = 0;
    float lastLineEndLat = 0;
    float lastLineEndLon = 0;

    for (int i = 0; i < numScan; i++) {
      for (int j = 0; j < numSample; j++) {
        if (latIter.hasNext() && lonIter.hasNext()) {
          float curLat = latIter.getFloatNext();
          float curLon = lonIter.getFloatNext();
          if ((i == 0) && (j == 0)) {
            firstLineStartLat = curLat;
            firstLineStartLon = curLon;
          } else if ((i == 0) && (j == numSample - 1)) {
            firstLineEndLat = curLat;
            firstLineEndLon = curLon;
          } else if ((i == numScan - 1) && (j == 0)) {
            lastLineStartLat = curLat;
            lastLineStartLon = curLon;
          } else if ((i == numScan - 1) && (j == numSample - 1)) {
            lastLineEndLat = curLat;
            lastLineEndLon = curLon;
          }
        }
      }
    }
    double[] edgeLat = {firstLineStartLat, firstLineEndLat, lastLineStartLat, lastLineEndLat};
    double[] edgeLon = {firstLineStartLon, firstLineEndLon, lastLineStartLon, lastLineEndLon};
    for (int i = 0; i < edgeLat.length; i++) {
      maxLat = ((maxLat > edgeLat[i])
              ? maxLat
              : edgeLat[i]);
      minLat = ((minLat < edgeLat[i])
              ? minLat
              : edgeLat[i]);
      maxLon = ((maxLon > edgeLon[i])
              ? maxLon
              : edgeLon[i]);
      minLon = ((minLon < edgeLon[i])
              ? minLon
              : edgeLon[i]);
    }

    double xInc1 = Math.abs((firstLineEndLon - firstLineStartLon) / numSample);
    //double xInc2 = Math.abs((lastLineEndLon - lastLineStartLon)/numSample);
    double yInc1 = Math.abs((lastLineStartLat - firstLineStartLat) / numScan);
    //double yInc2 = Math.abs((lastLineEndLat - firstLineEndLat)/numScan);
    increment[0] = xInc1;  // > xInc2 ? xInc1 : xInc2;
    increment[1] = yInc1;  // > yInc2 ? yInc1 : yInc2;
    increment[2] = minLat;
    increment[3] = maxLat;
    increment[4] = minLon;
    increment[5] = maxLon;
    increment[6] = (maxLon - minLon) / xInc1;
    increment[7] = (maxLat - minLat) / yInc1;
    return increment;
  }
private double[] getSwathLatLonInformation(Array lat, Array lon) {
    // Calculate the increment of latitude and longitude of original swath data
    // Calculate the size of the boundingBox
    // element0: Longitude increment
    // element1: Latitude increment
    // element2: minLat
    // element3: maxLat
    // element4: minLon
    // element5: maxLon
    // element6: width of the boundingBox
    // element7: height of the boundingBox
    double increment[] = {0, 0, 0, 0, 0, 0, 0, 0};
    IndexIterator latIter = lat.getIndexIterator();
    IndexIterator lonIter = lon.getIndexIterator();

    int numScan = (lat.getShape())[0];
    int numSample = (lat.getShape())[1];

    double maxLat = -91,
            minLat = 91,
            maxLon = -181,
            minLon = 181;

    float firstLineStartLat = 0;
    float firstLineStartLon = 0;
    float firstLineEndLat = 0;
    float firstLineEndLon = 0;
    float lastLineStartLat = 0;
    float lastLineStartLon = 0;
    float lastLineEndLat = 0;
    float lastLineEndLon = 0;

    for (int i = 0; i < numScan; i++) {
      for (int j = 0; j < numSample; j++) {
        if (latIter.hasNext() && lonIter.hasNext()) {
          float curLat = latIter.getFloatNext();
          float curLon = lonIter.getFloatNext();
          if ((i == 0) && (j == 0)) {
            firstLineStartLat = curLat;
            firstLineStartLon = curLon;
          } else if ((i == 0) && (j == numSample - 1)) {
            firstLineEndLat = curLat;
            firstLineEndLon = curLon;
          } else if ((i == numScan - 1) && (j == 0)) {
            lastLineStartLat = curLat;
            lastLineStartLon = curLon;
          } else if ((i == numScan - 1) && (j == numSample - 1)) {
            lastLineEndLat = curLat;
            lastLineEndLon = curLon;
          }
        }
      }
    }
    double[] edgeLat = {firstLineStartLat, firstLineEndLat, lastLineStartLat, lastLineEndLat};
    double[] edgeLon = {firstLineStartLon, firstLineEndLon, lastLineStartLon, lastLineEndLon};
    for (int i = 0; i < edgeLat.length; i++) {
      maxLat = ((maxLat > edgeLat[i])
              ? maxLat
              : edgeLat[i]);
      minLat = ((minLat < edgeLat[i])
              ? minLat
              : edgeLat[i]);
      maxLon = ((maxLon > edgeLon[i])
              ? maxLon
              : edgeLon[i]);
      minLon = ((minLon < edgeLon[i])
              ? minLon
              : edgeLon[i]);
    }

    double xInc1 = Math.abs((firstLineEndLon - firstLineStartLon) / numSample);
    //double xInc2 = Math.abs((lastLineEndLon - lastLineStartLon)/numSample);
    double yInc1 = Math.abs((lastLineStartLat - firstLineStartLat) / numScan);
    //double yInc2 = Math.abs((lastLineEndLat - firstLineEndLat)/numScan);
    increment[0] = xInc1;  // > xInc2 ? xInc1 : xInc2;
    increment[1] = yInc1;  // > yInc2 ? yInc1 : yInc2;
    increment[2] = minLat;
    increment[3] = maxLat;
    increment[4] = minLon;
    increment[5] = maxLon;
    increment[6] = (maxLon - minLon) / xInc1;
    increment[7] = (maxLat - minLat) / yInc1;
    return increment;
  }
get lat lon information from the swath

@param lat 2D lat array
@param lon 2D lon array
@return double array for geotiff