visad/src/main/java/ucar/nc2/iosp/grid/GridHorizCoordSys.java
void addToNetcdfFile(NetcdfFile ncfile) {

    if (isLatLon) {
      double dy;
      if (gds.getDouble(GridDefRecord.DY) == GridDefRecord.UNDEFINED) {
        dy = setLatLonDxDy();
      } else {
        dy = (gds.getDouble(GridDefRecord.LA2) < gds.getDouble(GridDefRecord.LA1))
            ? -gds.getDouble(GridDefRecord.DY) : gds.getDouble(GridDefRecord.DY);
      }

      // lat
      if (isGaussian) {
        addGaussianLatAxis(ncfile, "lat", "degrees_north", "latitude coordinate", "latitude", AxisType.Lat);

      } else {
        addCoordAxis(ncfile, "lat", gds.getInt(GridDefRecord.NY), gds.getDouble(GridDefRecord.LA1), dy,
                "degrees_north", "latitude coordinate", "latitude", AxisType.Lat);
      }

      // lon
      addCoordAxis(ncfile, "lon", gds.getInt(GridDefRecord.NX), gds.getDouble(GridDefRecord.LO1), gds.getDouble(GridDefRecord.DX),
              "degrees_east", "longitude coordinate", "longitude", AxisType.Lon);

      // add dummy variable for lat/lon coord system
      addCoordSystemVariable(ncfile, "latLonCoordSys", "time lat lon");

    } else {
      int projType = lookup.getProjectionType(gds);
      if (makeProjection(ncfile, projType)) {

        double[] yData, xData;
        if (projType == GridTableLookup.RotatedLatLon) {
          double dy = (gds.getDouble("La2") < gds.getDouble(GridDefRecord.LA1)
              ? -gds.getDouble(GridDefRecord.DY) : gds.getDouble(GridDefRecord.DY));

          yData = addCoordAxis(ncfile, "y", gds.getInt(GridDefRecord.NY),
              gds.getDouble(GridDefRecord.LA1), dy, "degrees",
              "y coordinate of projection", "projection_y_coordinate", AxisType.GeoY);
          xData = addCoordAxis(ncfile, "x", gds.getInt(GridDefRecord.NX),
              gds.getDouble(GridDefRecord.LO1), gds.getDouble(GridDefRecord.DX), "degrees",
              "x coordinate of projection", "projection_x_coordinate", AxisType.GeoX);

        } else if (projType == GridTableLookup.Orthographic) {
          yData = addCoordAxis(ncfile, "y", gds.getInt(GridDefRecord.NY), starty, incry, "km",  // fake km - really pixel
              "y coordinate of projection", "projection_y_coordinate", AxisType.GeoY);     // dunno what the 3 is
          xData = addCoordAxis(ncfile, "x", gds.getInt(GridDefRecord.NX), startx, incrx, "km",
              "x coordinate of projection", "projection_x_coordinate", AxisType.GeoX);

        } else if (projType ==  GridTableLookup.Curvilinear ) {
          yData = null;
          xData = null;

        } else {
          yData = addCoordAxis(ncfile, "y", gds.getInt(GridDefRecord.NY), starty, getDyInKm(), "km", "y coordinate of projection",
              "projection_y_coordinate", AxisType.GeoY);
          xData = addCoordAxis(ncfile, "x", gds.getInt(GridDefRecord.NX), startx, getDxInKm(), "km", "x coordinate of projection",
              "projection_x_coordinate", AxisType.GeoX);
        }

        // optional 2D lat/lon
        if (GridServiceProvider.addLatLon && (projType != GridTableLookup.Curvilinear))
          addLatLon2D(ncfile, xData, yData);
      }
    }
  }
void addToNetcdfFile(NetcdfFile ncfile) {

    if (isLatLon) {
      double dy;
      if (gds.getDouble(GridDefRecord.DY) == GridDefRecord.UNDEFINED) {
        dy = setLatLonDxDy();
      } else {
        dy = (gds.getDouble(GridDefRecord.LA2) < gds.getDouble(GridDefRecord.LA1))
            ? -gds.getDouble(GridDefRecord.DY) : gds.getDouble(GridDefRecord.DY);
      }

      // lat
      if (isGaussian) {
        addGaussianLatAxis(ncfile, "lat", "degrees_north", "latitude coordinate", "latitude", AxisType.Lat);

      } else {
        addCoordAxis(ncfile, "lat", gds.getInt(GridDefRecord.NY), gds.getDouble(GridDefRecord.LA1), dy,
                "degrees_north", "latitude coordinate", "latitude", AxisType.Lat);
      }

      // lon
      addCoordAxis(ncfile, "lon", gds.getInt(GridDefRecord.NX), gds.getDouble(GridDefRecord.LO1), gds.getDouble(GridDefRecord.DX),
              "degrees_east", "longitude coordinate", "longitude", AxisType.Lon);

      // add dummy variable for lat/lon coord system
      addCoordSystemVariable(ncfile, "latLonCoordSys", "time lat lon");

    } else {
      int projType = lookup.getProjectionType(gds);
      if (makeProjection(ncfile, projType)) {

        double[] yData, xData;
        if (projType == GridTableLookup.RotatedLatLon) {
          double dy = (gds.getDouble("La2") < gds.getDouble(GridDefRecord.LA1)
              ? -gds.getDouble(GridDefRecord.DY) : gds.getDouble(GridDefRecord.DY));

          yData = addCoordAxis(ncfile, "y", gds.getInt(GridDefRecord.NY),
              gds.getDouble(GridDefRecord.LA1), dy, "degrees",
              "y coordinate of projection", "projection_y_coordinate", AxisType.GeoY);
          xData = addCoordAxis(ncfile, "x", gds.getInt(GridDefRecord.NX),
              gds.getDouble(GridDefRecord.LO1), gds.getDouble(GridDefRecord.DX), "degrees",
              "x coordinate of projection", "projection_x_coordinate", AxisType.GeoX);

        } else if (projType == GridTableLookup.Orthographic) {
          yData = addCoordAxis(ncfile, "y", gds.getInt(GridDefRecord.NY), starty, incry, "km",  // fake km - really pixel
              "y coordinate of projection", "projection_y_coordinate", AxisType.GeoY);     // dunno what the 3 is
          xData = addCoordAxis(ncfile, "x", gds.getInt(GridDefRecord.NX), startx, incrx, "km",
              "x coordinate of projection", "projection_x_coordinate", AxisType.GeoX);

        } else if (projType ==  GridTableLookup.Curvilinear ) {
          yData = null;
          xData = null;

        } else {
          yData = addCoordAxis(ncfile, "y", gds.getInt(GridDefRecord.NY), starty, getDyInKm(), "km", "y coordinate of projection",
              "projection_y_coordinate", AxisType.GeoY);
          xData = addCoordAxis(ncfile, "x", gds.getInt(GridDefRecord.NX), startx, getDxInKm(), "km", "x coordinate of projection",
              "projection_x_coordinate", AxisType.GeoX);
        }

        // optional 2D lat/lon
        if (GridServiceProvider.addLatLon && (projType != GridTableLookup.Curvilinear))
          addLatLon2D(ncfile, xData, yData);
      }
    }
  }
void addToNetcdfFile ( NetcdfFile ncfile ) { if ( isLatLon ) { double dy ; if ( gds . getDouble ( GridDefRecord . DY ) == GridDefRecord . UNDEFINED ) { dy = setLatLonDxDy ( ) ; } else { dy = ( gds . getDouble ( GridDefRecord . LA2 ) < gds . getDouble ( GridDefRecord . LA1 ) ) ? - gds . getDouble ( GridDefRecord . DY ) : gds . getDouble ( GridDefRecord . DY ) ; } // lat if ( isGaussian ) { addGaussianLatAxis ( ncfile , "lat" , "degrees_north" , "latitude coordinate" , "latitude" , AxisType . Lat ) ; } else { addCoordAxis ( ncfile , "lat" , gds . getInt ( GridDefRecord . NY ) , gds . getDouble ( GridDefRecord . LA1 ) , dy , "degrees_north" , "latitude coordinate" , "latitude" , AxisType . Lat ) ; } // lon addCoordAxis ( ncfile , "lon" , gds . getInt ( GridDefRecord . NX ) , gds . getDouble ( GridDefRecord . LO1 ) , gds . getDouble ( GridDefRecord . DX ) , "degrees_east" , "longitude coordinate" , "longitude" , AxisType . Lon ) ; // add dummy variable for lat/lon coord system addCoordSystemVariable ( ncfile , "latLonCoordSys" , "time lat lon" ) ; } else { int projType = lookup . getProjectionType ( gds ) ; if ( makeProjection ( ncfile , projType ) ) { double [ ] yData , xData ; if ( projType == GridTableLookup . RotatedLatLon ) { double dy = ( gds . getDouble ( "La2" ) < gds . getDouble ( GridDefRecord . LA1 ) ? - gds . getDouble ( GridDefRecord . DY ) : gds . getDouble ( GridDefRecord . DY ) ) ; yData = addCoordAxis ( ncfile , "y" , gds . getInt ( GridDefRecord . NY ) , gds . getDouble ( GridDefRecord . LA1 ) , dy , "degrees" , "y coordinate of projection" , "projection_y_coordinate" , AxisType . GeoY ) ; xData = addCoordAxis ( ncfile , "x" , gds . getInt ( GridDefRecord . NX ) , gds . getDouble ( GridDefRecord . LO1 ) , gds . getDouble ( GridDefRecord . DX ) , "degrees" , "x coordinate of projection" , "projection_x_coordinate" , AxisType . GeoX ) ; } else if ( projType == GridTableLookup . Orthographic ) { yData = addCoordAxis ( ncfile , "y" , gds . getInt ( GridDefRecord . NY ) , starty , incry , "km" , // fake km - really pixel "y coordinate of projection" , "projection_y_coordinate" , AxisType . GeoY ) ; // dunno what the 3 is xData = addCoordAxis ( ncfile , "x" , gds . getInt ( GridDefRecord . NX ) , startx , incrx , "km" , "x coordinate of projection" , "projection_x_coordinate" , AxisType . GeoX ) ; } else if ( projType == GridTableLookup . Curvilinear ) { yData = null ; xData = null ; } else { yData = addCoordAxis ( ncfile , "y" , gds . getInt ( GridDefRecord . NY ) , starty , getDyInKm ( ) , "km" , "y coordinate of projection" , "projection_y_coordinate" , AxisType . GeoY ) ; xData = addCoordAxis ( ncfile , "x" , gds . getInt ( GridDefRecord . NX ) , startx , getDxInKm ( ) , "km" , "x coordinate of projection" , "projection_x_coordinate" , AxisType . GeoX ) ; } // optional 2D lat/lon if ( GridServiceProvider . addLatLon && ( projType != GridTableLookup . Curvilinear ) ) addLatLon2D ( ncfile , xData , yData ) ; } } }
Add the variables to the netCDF file

@param ncfile the netCDF file
Add the variables to the netCDF file