visad/src/main/java/ucar/nc2/iosp/grid/GridHorizCoordSys.java
private boolean makeProjection(NetcdfFile ncfile, int projType) {
    switch (projType) {

      case GridTableLookup.RotatedLatLon:
        makeRotatedLatLon(ncfile);
        break;

      case GridTableLookup.PolarStereographic:
        makePS();
        break;

      case GridTableLookup.LambertConformal:
        makeLC();
        break;

      case GridTableLookup.Mercator:
        makeMercator();
        break;

      case GridTableLookup.Orthographic:
        //makeSpaceViewOrOthographic();
        makeMSGgeostationary();
        break;

      case GridTableLookup.Curvilinear:
        makeCurvilinearAxis( ncfile);
        break;

      default:
        throw new UnsupportedOperationException("unknown projection = "
            + gds.getInt(GridDefRecord.GRID_TYPE));
    }

    // dummy coordsys variable
    Variable v = new Variable(ncfile, g, null, grid_name);
    v.setDataType(DataType.CHAR);
    v.setDimensions(""); // scalar
    char[] data = new char[]{'d'};
    Array dataArray = Array.factory(DataType.CHAR, new int[0], data);
    v.setCachedData(dataArray, false);

    for (Attribute att : attributes)
      v.addAttribute(att);

    // add CF Conventions attributes
    v.addAttribute(new Attribute(GridCF.EARTH_SHAPE, shape_name));

    // LOOK - spherical earth ??
    double radius_spherical_earth = gds.getDouble(GridDefRecord.RADIUS_SPHERICAL_EARTH);
    // have to check both because Grib1 and Grib2 used different names
    if (Double.isNaN(radius_spherical_earth))
      radius_spherical_earth = gds.getDouble("radius_spherical_earth");

    if( ! Double.isNaN(radius_spherical_earth) ) {
      //inconsistent - sometimes in km, sometimes in m.
      if (radius_spherical_earth < 10000.00) // then its in km
        radius_spherical_earth *= 1000.0;    // convert to meters
      v.addAttribute(new Attribute(GridCF.EARTH_RADIUS, radius_spherical_earth)); //this attribute needs to be meters

    } else { // oblate earth
      double major_axis = gds.getDouble( GridDefRecord.MAJOR_AXIS_EARTH );
      if (Double.isNaN( major_axis ))
        major_axis = gds.getDouble("major_axis_earth");
      double minor_axis = gds.getDouble( GridDefRecord.MINOR_AXIS_EARTH );
      if (Double.isNaN(minor_axis))
        minor_axis = gds.getDouble("minor_axis_earth");
      if ( ! Double.isNaN ( major_axis ) && ! Double.isNaN ( minor_axis )) {
        v.addAttribute(new Attribute(GridCF.SEMI_MAJOR_AXIS, major_axis));
        v.addAttribute(new Attribute(GridCF.SEMI_MINOR_AXIS, minor_axis));
      }
    }
    addGDSparams(v);
    ncfile.addVariable(g, v);
    return true;
  }
private boolean makeProjection(NetcdfFile ncfile, int projType) {
    switch (projType) {

      case GridTableLookup.RotatedLatLon:
        makeRotatedLatLon(ncfile);
        break;

      case GridTableLookup.PolarStereographic:
        makePS();
        break;

      case GridTableLookup.LambertConformal:
        makeLC();
        break;

      case GridTableLookup.Mercator:
        makeMercator();
        break;

      case GridTableLookup.Orthographic:
        //makeSpaceViewOrOthographic();
        makeMSGgeostationary();
        break;

      case GridTableLookup.Curvilinear:
        makeCurvilinearAxis( ncfile);
        break;

      default:
        throw new UnsupportedOperationException("unknown projection = "
            + gds.getInt(GridDefRecord.GRID_TYPE));
    }

    // dummy coordsys variable
    Variable v = new Variable(ncfile, g, null, grid_name);
    v.setDataType(DataType.CHAR);
    v.setDimensions(""); // scalar
    char[] data = new char[]{'d'};
    Array dataArray = Array.factory(DataType.CHAR, new int[0], data);
    v.setCachedData(dataArray, false);

    for (Attribute att : attributes)
      v.addAttribute(att);

    // add CF Conventions attributes
    v.addAttribute(new Attribute(GridCF.EARTH_SHAPE, shape_name));

    // LOOK - spherical earth ??
    double radius_spherical_earth = gds.getDouble(GridDefRecord.RADIUS_SPHERICAL_EARTH);
    // have to check both because Grib1 and Grib2 used different names
    if (Double.isNaN(radius_spherical_earth))
      radius_spherical_earth = gds.getDouble("radius_spherical_earth");

    if( ! Double.isNaN(radius_spherical_earth) ) {
      //inconsistent - sometimes in km, sometimes in m.
      if (radius_spherical_earth < 10000.00) // then its in km
        radius_spherical_earth *= 1000.0;    // convert to meters
      v.addAttribute(new Attribute(GridCF.EARTH_RADIUS, radius_spherical_earth)); //this attribute needs to be meters

    } else { // oblate earth
      double major_axis = gds.getDouble( GridDefRecord.MAJOR_AXIS_EARTH );
      if (Double.isNaN( major_axis ))
        major_axis = gds.getDouble("major_axis_earth");
      double minor_axis = gds.getDouble( GridDefRecord.MINOR_AXIS_EARTH );
      if (Double.isNaN(minor_axis))
        minor_axis = gds.getDouble("minor_axis_earth");
      if ( ! Double.isNaN ( major_axis ) && ! Double.isNaN ( minor_axis )) {
        v.addAttribute(new Attribute(GridCF.SEMI_MAJOR_AXIS, major_axis));
        v.addAttribute(new Attribute(GridCF.SEMI_MINOR_AXIS, minor_axis));
      }
    }
    addGDSparams(v);
    ncfile.addVariable(g, v);
    return true;
  }
private boolean makeProjection ( NetcdfFile ncfile , int projType ) { switch ( projType ) { case GridTableLookup . RotatedLatLon : makeRotatedLatLon ( ncfile ) ; break ; case GridTableLookup . PolarStereographic : makePS ( ) ; break ; case GridTableLookup . LambertConformal : makeLC ( ) ; break ; case GridTableLookup . Mercator : makeMercator ( ) ; break ; case GridTableLookup . Orthographic : //makeSpaceViewOrOthographic(); makeMSGgeostationary ( ) ; break ; case GridTableLookup . Curvilinear : makeCurvilinearAxis ( ncfile ) ; break ; default : throw new UnsupportedOperationException ( "unknown projection = " + gds . getInt ( GridDefRecord . GRID_TYPE ) ) ; } // dummy coordsys variable Variable v = new Variable ( ncfile , g , null , grid_name ) ; v . setDataType ( DataType . CHAR ) ; v . setDimensions ( "" ) ; // scalar char [ ] data = new char [ ] { ' ' } ; Array dataArray = Array . factory ( DataType . CHAR , new int [ 0 ] , data ) ; v . setCachedData ( dataArray , false ) ; for ( Attribute att : attributes ) v . addAttribute ( att ) ; // add CF Conventions attributes v . addAttribute ( new Attribute ( GridCF . EARTH_SHAPE , shape_name ) ) ; // LOOK - spherical earth ?? double radius_spherical_earth = gds . getDouble ( GridDefRecord . RADIUS_SPHERICAL_EARTH ) ; // have to check both because Grib1 and Grib2 used different names if ( Double . isNaN ( radius_spherical_earth ) ) radius_spherical_earth = gds . getDouble ( "radius_spherical_earth" ) ; if ( ! Double . isNaN ( radius_spherical_earth ) ) { //inconsistent - sometimes in km, sometimes in m. if ( radius_spherical_earth < 10000.00 ) // then its in km radius_spherical_earth *= 1000.0 ; // convert to meters v . addAttribute ( new Attribute ( GridCF . EARTH_RADIUS , radius_spherical_earth ) ) ; //this attribute needs to be meters } else { // oblate earth double major_axis = gds . getDouble ( GridDefRecord . MAJOR_AXIS_EARTH ) ; if ( Double . isNaN ( major_axis ) ) major_axis = gds . getDouble ( "major_axis_earth" ) ; double minor_axis = gds . getDouble ( GridDefRecord . MINOR_AXIS_EARTH ) ; if ( Double . isNaN ( minor_axis ) ) minor_axis = gds . getDouble ( "minor_axis_earth" ) ; if ( ! Double . isNaN ( major_axis ) && ! Double . isNaN ( minor_axis ) ) { v . addAttribute ( new Attribute ( GridCF . SEMI_MAJOR_AXIS , major_axis ) ) ; v . addAttribute ( new Attribute ( GridCF . SEMI_MINOR_AXIS , minor_axis ) ) ; } } addGDSparams ( v ) ; ncfile . addVariable ( g , v ) ; return true ; }
Make a projection and add it to the netCDF file

@param ncfile netCDF file
@return true if projection was added and coordinates need to be added, false means do nothing
Make a projection and add it to the netCDF file