cdm/src/main/java/ucar/nc2/dataset/conv/ADASConvention.java
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) throws IOException {
    if (null != ds.findVariable("x")) return; // check if its already been done - aggregating enhanced datasets.

    // old way
    Attribute att = ds.findGlobalAttribute("MAPPROJ");
    int projType = att.getNumericValue().intValue();

    double lat1 = findAttributeDouble(ds, "TRUELAT1", Double.NaN);
    double lat2 = findAttributeDouble(ds, "TRUELAT2", Double.NaN);
    double lat_origin = lat1;
    double lon_origin = findAttributeDouble(ds, "TRUELON", Double.NaN);
    double false_easting = 0.0;
    double false_northing = 0.0;

    // new way
    String projName = ds.findAttValueIgnoreCase(null, CF.GRID_MAPPING_NAME, null);
    if (projName != null) {
      projName = projName.trim();
      lat_origin = findAttributeDouble(ds, "latitude_of_projection_origin", Double.NaN);
      lon_origin = findAttributeDouble(ds, "longitude_of_central_meridian", Double.NaN);
      false_easting = findAttributeDouble(ds, "false_easting", 0.0);
      false_northing = findAttributeDouble(ds, "false_northing", 0.0);

      Attribute att2 = ds.findGlobalAttributeIgnoreCase("standard_parallel");
      if (att2 != null) {
        lat1 = att2.getNumericValue().doubleValue();
        lat2 = (att2.getLength() > 1) ? att2.getNumericValue(1).doubleValue() : lat1;
      }
    } else {
      if (projType == 2) projName = "lambert_conformal_conic";
    }

    Variable coord_var = ds.findVariable("x_stag");
    if (!Double.isNaN(false_easting) || !Double.isNaN(false_northing)) {
      String units = ds.findAttValueIgnoreCase(coord_var, CDM.UNITS, null);
      double scalef = 1.0;
      try {
        scalef = SimpleUnit.getConversionFactor(units, "km");
      } catch (IllegalArgumentException e) {
        log.error(units + " not convertible to km");
      }
      false_easting *= scalef;
      false_northing *= scalef;
    }

    ProjectionImpl proj;
    if ((projName != null) && projName.equalsIgnoreCase("lambert_conformal_conic")) {
      proj = new LambertConformal(lat_origin, lon_origin, lat1, lat2, false_easting, false_northing);
      projCT = new ProjectionCT("Projection", "FGDC", proj);
      if (false_easting == 0.0) calcCenterPoints(ds, proj); // old way
    } else {
      parseInfo.format("ERROR: unknown projection type = %s%n", projName);
    }

    if (debugProj && (proj != null)) {
      System.out.println(" using LC " + proj.paramsToString());
      double lat_check = findAttributeDouble(ds, "CTRLAT", Double.NaN);
      double lon_check = findAttributeDouble(ds, "CTRLON", Double.NaN);

      LatLonPointImpl lpt0 = new LatLonPointImpl(lat_check, lon_check);
      ProjectionPoint ppt0 = proj.latLonToProj(lpt0, new ProjectionPointImpl());
      System.out.println("CTR lpt0= " + lpt0 + " ppt0=" + ppt0);

      Variable xstag = ds.findVariable("x_stag");
      ArrayFloat.D1 xstagData = (ArrayFloat.D1) xstag.read();
      float center_x = xstagData.get((int) xstag.getSize() - 1);
      Variable ystag = ds.findVariable("y_stag");
      ArrayFloat.D1 ystagData = (ArrayFloat.D1) ystag.read();
      float center_y = ystagData.get((int) ystag.getSize() - 1);
      System.out.println("CTR should be x,y= " + center_x / 2000 + ", " + center_y / 2000);

      lpt0 = new LatLonPointImpl(lat_origin, lon_origin);
      ppt0 = proj.latLonToProj(lpt0, new ProjectionPointImpl());
      System.out.println("ORIGIN lpt0= " + lpt0 + " ppt0=" + ppt0);

      lpt0 = new LatLonPointImpl(lat_origin, lon_origin);
      ppt0 = proj.latLonToProj(lpt0, new ProjectionPointImpl());
      System.out.println("TRUE ORIGIN lpt0= " + lpt0 + " ppt0=" + ppt0);
    }

    if (projCT != null) {
      VariableDS v = makeCoordinateTransformVariable(ds, projCT);
      v.addAttribute(new Attribute(_Coordinate.AxisTypes, "GeoX GeoY"));
      ds.addVariable(null, v);
    }

    if (ds.findVariable("x_stag") != null)
      ds.addCoordinateAxis(makeCoordAxis(ds, "x"));
    if (ds.findVariable("y_stag") != null)
      ds.addCoordinateAxis(makeCoordAxis(ds, "y"));
    if (ds.findVariable("z_stag") != null)
      ds.addCoordinateAxis(makeCoordAxis(ds, "z"));

    Variable zsoil = ds.findVariable("ZPSOIL");
    if (zsoil != null)
      zsoil.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.GeoZ.toString()));

    ds.finish();
  }
public void augmentDataset(NetcdfDataset ds, CancelTask cancelTask) throws IOException {
    if (null != ds.findVariable("x")) return; // check if its already been done - aggregating enhanced datasets.

    // old way
    Attribute att = ds.findGlobalAttribute("MAPPROJ");
    int projType = att.getNumericValue().intValue();

    double lat1 = findAttributeDouble(ds, "TRUELAT1", Double.NaN);
    double lat2 = findAttributeDouble(ds, "TRUELAT2", Double.NaN);
    double lat_origin = lat1;
    double lon_origin = findAttributeDouble(ds, "TRUELON", Double.NaN);
    double false_easting = 0.0;
    double false_northing = 0.0;

    // new way
    String projName = ds.findAttValueIgnoreCase(null, CF.GRID_MAPPING_NAME, null);
    if (projName != null) {
      projName = projName.trim();
      lat_origin = findAttributeDouble(ds, "latitude_of_projection_origin", Double.NaN);
      lon_origin = findAttributeDouble(ds, "longitude_of_central_meridian", Double.NaN);
      false_easting = findAttributeDouble(ds, "false_easting", 0.0);
      false_northing = findAttributeDouble(ds, "false_northing", 0.0);

      Attribute att2 = ds.findGlobalAttributeIgnoreCase("standard_parallel");
      if (att2 != null) {
        lat1 = att2.getNumericValue().doubleValue();
        lat2 = (att2.getLength() > 1) ? att2.getNumericValue(1).doubleValue() : lat1;
      }
    } else {
      if (projType == 2) projName = "lambert_conformal_conic";
    }

    Variable coord_var = ds.findVariable("x_stag");
    if (!Double.isNaN(false_easting) || !Double.isNaN(false_northing)) {
      String units = ds.findAttValueIgnoreCase(coord_var, CDM.UNITS, null);
      double scalef = 1.0;
      try {
        scalef = SimpleUnit.getConversionFactor(units, "km");
      } catch (IllegalArgumentException e) {
        log.error(units + " not convertible to km");
      }
      false_easting *= scalef;
      false_northing *= scalef;
    }

    ProjectionImpl proj;
    if ((projName != null) && projName.equalsIgnoreCase("lambert_conformal_conic")) {
      proj = new LambertConformal(lat_origin, lon_origin, lat1, lat2, false_easting, false_northing);
      projCT = new ProjectionCT("Projection", "FGDC", proj);
      if (false_easting == 0.0) calcCenterPoints(ds, proj); // old way
    } else {
      parseInfo.format("ERROR: unknown projection type = %s%n", projName);
    }

    if (debugProj && (proj != null)) {
      System.out.println(" using LC " + proj.paramsToString());
      double lat_check = findAttributeDouble(ds, "CTRLAT", Double.NaN);
      double lon_check = findAttributeDouble(ds, "CTRLON", Double.NaN);

      LatLonPointImpl lpt0 = new LatLonPointImpl(lat_check, lon_check);
      ProjectionPoint ppt0 = proj.latLonToProj(lpt0, new ProjectionPointImpl());
      System.out.println("CTR lpt0= " + lpt0 + " ppt0=" + ppt0);

      Variable xstag = ds.findVariable("x_stag");
      ArrayFloat.D1 xstagData = (ArrayFloat.D1) xstag.read();
      float center_x = xstagData.get((int) xstag.getSize() - 1);
      Variable ystag = ds.findVariable("y_stag");
      ArrayFloat.D1 ystagData = (ArrayFloat.D1) ystag.read();
      float center_y = ystagData.get((int) ystag.getSize() - 1);
      System.out.println("CTR should be x,y= " + center_x / 2000 + ", " + center_y / 2000);

      lpt0 = new LatLonPointImpl(lat_origin, lon_origin);
      ppt0 = proj.latLonToProj(lpt0, new ProjectionPointImpl());
      System.out.println("ORIGIN lpt0= " + lpt0 + " ppt0=" + ppt0);

      lpt0 = new LatLonPointImpl(lat_origin, lon_origin);
      ppt0 = proj.latLonToProj(lpt0, new ProjectionPointImpl());
      System.out.println("TRUE ORIGIN lpt0= " + lpt0 + " ppt0=" + ppt0);
    }

    if (projCT != null) {
      VariableDS v = makeCoordinateTransformVariable(ds, projCT);
      v.addAttribute(new Attribute(_Coordinate.AxisTypes, "GeoX GeoY"));
      ds.addVariable(null, v);
    }

    if (ds.findVariable("x_stag") != null)
      ds.addCoordinateAxis(makeCoordAxis(ds, "x"));
    if (ds.findVariable("y_stag") != null)
      ds.addCoordinateAxis(makeCoordAxis(ds, "y"));
    if (ds.findVariable("z_stag") != null)
      ds.addCoordinateAxis(makeCoordAxis(ds, "z"));

    Variable zsoil = ds.findVariable("ZPSOIL");
    if (zsoil != null)
      zsoil.addAttribute(new Attribute(_Coordinate.AxisType, AxisType.GeoZ.toString()));

    ds.finish();
  }
public void augmentDataset ( NetcdfDataset ds , CancelTask cancelTask ) throws IOException { if ( null != ds . findVariable ( "x" ) ) return ; // check if its already been done - aggregating enhanced datasets.
 // old way
 Attribute att = ds . findGlobalAttribute ( "MAPPROJ" ) ; int projType = att . getNumericValue ( ) . intValue ( ) ; double lat1 = findAttributeDouble ( ds , "TRUELAT1" , Double . NaN ) ; double lat2 = findAttributeDouble ( ds , "TRUELAT2" , Double . NaN ) ; double lat_origin = lat1 ; double lon_origin = findAttributeDouble ( ds , "TRUELON" , Double . NaN ) ; double false_easting = 0.0 ; double false_northing = 0.0 ; // new way
 String projName = ds . findAttValueIgnoreCase ( null , CF . GRID_MAPPING_NAME , null ) ; if ( projName != null ) { projName = projName . trim ( ) ; lat_origin = findAttributeDouble ( ds , "latitude_of_projection_origin" , Double . NaN ) ; lon_origin = findAttributeDouble ( ds , "longitude_of_central_meridian" , Double . NaN ) ; false_easting = findAttributeDouble ( ds , "false_easting" , 0.0 ) ; false_northing = findAttributeDouble ( ds , "false_northing" , 0.0 ) ; Attribute att2 = ds . findGlobalAttributeIgnoreCase ( "standard_parallel" ) ; if ( att2 != null ) { lat1 = att2 . getNumericValue ( ) . doubleValue ( ) ; lat2 = ( att2 . getLength ( ) > 1 ) ? att2 . getNumericValue ( 1 ) . doubleValue ( ) : lat1 ; } } else { if ( projType == 2 ) projName = "lambert_conformal_conic" ; } Variable coord_var = ds . findVariable ( "x_stag" ) ; if ( ! Double . isNaN ( false_easting ) || ! Double . isNaN ( false_northing ) ) { String units = ds . findAttValueIgnoreCase ( coord_var , CDM . UNITS , null ) ; double scalef = 1.0 ; try { scalef = SimpleUnit . getConversionFactor ( units , "km" ) ; } catch ( IllegalArgumentException e ) { log . error ( units + " not convertible to km" ) ; } false_easting *= scalef ; false_northing *= scalef ; } ProjectionImpl proj ; if ( ( projName != null ) && projName . equalsIgnoreCase ( "lambert_conformal_conic" ) ) { proj = new LambertConformal ( lat_origin , lon_origin , lat1 , lat2 , false_easting , false_northing ) ; projCT = new ProjectionCT ( "Projection" , "FGDC" , proj ) ; if ( false_easting == 0.0 ) calcCenterPoints ( ds , proj ) ; // old way
 } else { parseInfo . format ( "ERROR: unknown projection type = %s%n" , projName ) ; } if ( debugProj && ( proj != null ) ) { System . out . println ( " using LC " + proj . paramsToString ( ) ) ; double lat_check = findAttributeDouble ( ds , "CTRLAT" , Double . NaN ) ; double lon_check = findAttributeDouble ( ds , "CTRLON" , Double . NaN ) ; LatLonPointImpl lpt0 = new LatLonPointImpl ( lat_check , lon_check ) ; ProjectionPoint ppt0 = proj . latLonToProj ( lpt0 , new ProjectionPointImpl ( ) ) ; System . out . println ( "CTR lpt0= " + lpt0 + " ppt0=" + ppt0 ) ; Variable xstag = ds . findVariable ( "x_stag" ) ; ArrayFloat . D1 xstagData = ( ArrayFloat . D1 ) xstag . read ( ) ; float center_x = xstagData . get ( ( int ) xstag . getSize ( ) - 1 ) ; Variable ystag = ds . findVariable ( "y_stag" ) ; ArrayFloat . D1 ystagData = ( ArrayFloat . D1 ) ystag . read ( ) ; float center_y = ystagData . get ( ( int ) ystag . getSize ( ) - 1 ) ; System . out . println ( "CTR should be x,y= " + center_x / 2000 + ", " + center_y / 2000 ) ; lpt0 = new LatLonPointImpl ( lat_origin , lon_origin ) ; ppt0 = proj . latLonToProj ( lpt0 , new ProjectionPointImpl ( ) ) ; System . out . println ( "ORIGIN lpt0= " + lpt0 + " ppt0=" + ppt0 ) ; lpt0 = new LatLonPointImpl ( lat_origin , lon_origin ) ; ppt0 = proj . latLonToProj ( lpt0 , new ProjectionPointImpl ( ) ) ; System . out . println ( "TRUE ORIGIN lpt0= " + lpt0 + " ppt0=" + ppt0 ) ; } if ( projCT != null ) { VariableDS v = makeCoordinateTransformVariable ( ds , projCT ) ; v . addAttribute ( new Attribute ( _Coordinate . AxisTypes , "GeoX GeoY" ) ) ; ds . addVariable ( null , v ) ; } if ( ds . findVariable ( "x_stag" ) != null ) ds . addCoordinateAxis ( makeCoordAxis ( ds , "x" ) ) ; if ( ds . findVariable ( "y_stag" ) != null ) ds . addCoordinateAxis ( makeCoordAxis ( ds , "y" ) ) ; if ( ds . findVariable ( "z_stag" ) != null ) ds . addCoordinateAxis ( makeCoordAxis ( ds , "z" ) ) ; Variable zsoil = ds . findVariable ( "ZPSOIL" ) ; if ( zsoil != null ) zsoil . addAttribute ( new Attribute ( _Coordinate . AxisType , AxisType . GeoZ . toString ( ) ) ) ; ds . finish ( ) ; }
create a NetcdfDataset out of this NetcdfFile, adding coordinates etc.
create a NetcdfDataset out of this NetcdfFile adding coordinates etc .