visad/src/main/java/ucar/nc2/iosp/mcidas/McGridDefRecord.java
private void setParams() {

        /* PS and CONF projection parameters */
    double xrowi;   // row # of North Pole*10000
    double xcoli;   // column # of North Pole* 10000
    double xqlon;   // longitude parallel to columns
    double xspace;  // column spacing at standard latitude
    double yspace;  // row spacing at standard latitude
    double xt1;     // standard latitude
    double xt2;     // 2nd standard latitude
    double xh;      //
    double xfac;    //
    double xblat;   //
        /* Merc and pseudo_merc parameters */
    double glamx;  // max latitude
    double glomx;  // max longitude
    double glamn;  // min latitude
    double glomn;  // min longitude
    double ginct;  // grid increment in latitude
    double gincn;  // grid increment in longitude

    try {
      GRIDnav nav = new GRIDnav(vals);

      int gridType = vals[33];
      int navType = gridType % 10;
      addParam("Proj", String.valueOf(navType));
      boolean wierd = gridType / 10 == 1;
      int ny = vals[1];
      int nx = vals[2];
      addParam(PROJ, getProjName(navType));
      addParam(NX, String.valueOf(nx));
      addParam(NY, String.valueOf(ny));
      double[][] input;
      if (nav.isFlippedRowCoordinates()) {
        input = new double[][]{{1, nx}, {1, ny}};
      } else {
        input = new double[][]{{1, nx}, {ny, 1}};
      }
      double[][] llur = nav.toLatLon(input);
            /*
            if (cnt == 0 && navType == 6) {
                System.out.println("Proj = " + getProjName(navType) + ":" + navType);
                System.out.println("isFlipped = " + nav.isFlippedRowCoordinates());
                ucar.unidata.util.Misc.printArray("input x", input[0]);
                ucar.unidata.util.Misc.printArray("input y", input[1]);
                ucar.unidata.util.Misc.printArray("lats", llur[0]);
                ucar.unidata.util.Misc.printArray("lons", llur[1]);
                cnt++;
            }
            */
      addParam(LA1, String.valueOf(llur[0][0]));
      addParam(LO1, String.valueOf(llur[1][0]));
      addParam(LA2, String.valueOf(llur[0][1]));
      addParam(LO2, String.valueOf(llur[1][1]));

      switch (navType) {

        case PSEUDO_MERCATOR:
        case PSEUDO_MERCATOR_GENERAL:
          glamx = vals[34] / 10000.;
          glomx = -vals[35] / 10000.;
          glamn = vals[34] / 10000.;
          glomn = -vals[35] / 10000.;
          ginct = vals[38] / 10000.;
          gincn = (navType == PSEUDO_MERCATOR_GENERAL)
                  ? vals[39] / 10000.
                  : ginct;
          addParam("Latin", String.valueOf(20));
          //addParam(DX, String.valueOf(gincn));
          //addParam(DY, String.valueOf(ginct));
                  /*
                  if (wierd) {
                    double x = xnr;
                    xnr = xnc;
                    xnc = x;
                  }
                  */
          break;

        case PS_OR_LAMBERT_CONIC:
          xrowi = vals[34] / 10000.;  // row # of the North pole*10000
          xcoli = vals[35] / 10000.;  // col # of the North pole*10000
          xspace = vals[36];  // column spacing at standard lat (m)
          xqlon = -vals[37] / 10000.;  // lon parallel to cols (deg*10000)
          xt1 = vals[38] / 10000.;  // first standard lat
          xt2 = vals[39] / 10000.;  // second standard lat
          addParam(LATIN1, String.valueOf(xt1));
          addParam(LOV, String.valueOf(xqlon));
          addParam(LATIN2, String.valueOf(xt2));
          addParam(DX, String.valueOf(xspace));
          addParam(DY, String.valueOf(xspace));
                  /*
                  xh = (xt1 >= 0) ? 1. : -1.;
                  xt1 =(90.-xh*xt1)*xrad;
                  xt2 =(90.-xh*xt2)*xrad;
                  xfac =1.0;
                  if (xt1 != xt2)
                     xfac = (Math.log(Math.sin(xt1))-Math.log(Math.sin(xt2)))/
                            (Math.log(Math.tan(.5*xt1))-Math.log(Math.tan(.5*xt2)));
                  xfac = 1.0/xfac;
                  xblat = 6370. * Math.sin(xt1)/
                           (xspace*xfac*(Math.pow(Math.tan(xt1*.5),xfac)));
                  if (wierd) {
                     double x=xnr;
                     xnr=xnc;
                     xnc=x;
                     x=xcoli;
                     xcoli=xrowi;
                     xrowi=xnr-x+1.0;
                     xqlon=xqlon+90.;
                  }
                  */

          break;

        case EQUIDISTANT:
          xrowi = 1.;
          xcoli = 1.;
          glamx = vals[34] / 10000.;   // lat of (1,1) degrees*10000
          glomx = -vals[35] / 10000.;  // lon of (1,1) degrees*10000
          //xrot  = -xrad*vals[36]/10000.; // clockwise rotation of col 1
          xspace = vals[37] / 1000.;   // column spacing
          yspace = vals[38] / 1000.;   // row spacing
          addParam(LA1, String.valueOf(glamx));
          addParam(LO1, String.valueOf(glomx));
          addParam(DX, String.valueOf(xspace));
          addParam(DY, String.valueOf(yspace));
                  /*
                  xblat = EARTH_RADIUS*xrad/yspace;
                  xblon = EARTH_RADIUS*xrad/xspace;

                  if (wierd) {
                    double x = xnr;
                    xnr = xnc;
                    xnc = x;
                  }
                  */

          break;

        case LAMBERT_CONFORMAL_TANGENT:
          xrowi = vals[34] / 10000.;  // lat at (1,1)
          xcoli = vals[35] / 10000.;  // lon at (1,1)
          xspace = vals[36];  // column spacing at standard lat (m)
          xqlon = -vals[37] / 10000.;  // lon parallel to cols (deg*10000)
          xt1 = vals[38] / 10000.;  // standard lat 1
          xt2 = vals[39] / 10000.;  // standard lat 2
          if (Double.compare(xt2, (double) McIDASUtil.MCMISSING) == 0 || (xt2 == 0)) { // LOOK suspicious floating point point compare
            xt2 = xt1;
          }
          addParam(LATIN1, String.valueOf(xt1));
          addParam(LOV, String.valueOf(xqlon));
          addParam(LATIN2, String.valueOf(xt2));
          addParam(DX, String.valueOf(xspace));
          addParam(DY, String.valueOf(xspace));
                  /*
                  xh = (xt1 >= 0) ? 1. : -1.;
                  xt1 = (90. - xh * xt1) * xrad;
                  xfac = Math.cos(xt1);
                  xblat = EARTH_RADIUS * Math.tan(xt1) /
                             (xspace * Math.pow(Math.tan(xt1*.5), xfac));
                             */

          break;

        default:
          break;
      }
    } catch (McIDASException me) {
      System.out.println("couldn't set nav");
    }

  }
private void setParams() {

        /* PS and CONF projection parameters */
    double xrowi;   // row # of North Pole*10000
    double xcoli;   // column # of North Pole* 10000
    double xqlon;   // longitude parallel to columns
    double xspace;  // column spacing at standard latitude
    double yspace;  // row spacing at standard latitude
    double xt1;     // standard latitude
    double xt2;     // 2nd standard latitude
    double xh;      //
    double xfac;    //
    double xblat;   //
        /* Merc and pseudo_merc parameters */
    double glamx;  // max latitude
    double glomx;  // max longitude
    double glamn;  // min latitude
    double glomn;  // min longitude
    double ginct;  // grid increment in latitude
    double gincn;  // grid increment in longitude

    try {
      GRIDnav nav = new GRIDnav(vals);

      int gridType = vals[33];
      int navType = gridType % 10;
      addParam("Proj", String.valueOf(navType));
      boolean wierd = gridType / 10 == 1;
      int ny = vals[1];
      int nx = vals[2];
      addParam(PROJ, getProjName(navType));
      addParam(NX, String.valueOf(nx));
      addParam(NY, String.valueOf(ny));
      double[][] input;
      if (nav.isFlippedRowCoordinates()) {
        input = new double[][]{{1, nx}, {1, ny}};
      } else {
        input = new double[][]{{1, nx}, {ny, 1}};
      }
      double[][] llur = nav.toLatLon(input);
            /*
            if (cnt == 0 && navType == 6) {
                System.out.println("Proj = " + getProjName(navType) + ":" + navType);
                System.out.println("isFlipped = " + nav.isFlippedRowCoordinates());
                ucar.unidata.util.Misc.printArray("input x", input[0]);
                ucar.unidata.util.Misc.printArray("input y", input[1]);
                ucar.unidata.util.Misc.printArray("lats", llur[0]);
                ucar.unidata.util.Misc.printArray("lons", llur[1]);
                cnt++;
            }
            */
      addParam(LA1, String.valueOf(llur[0][0]));
      addParam(LO1, String.valueOf(llur[1][0]));
      addParam(LA2, String.valueOf(llur[0][1]));
      addParam(LO2, String.valueOf(llur[1][1]));

      switch (navType) {

        case PSEUDO_MERCATOR:
        case PSEUDO_MERCATOR_GENERAL:
          glamx = vals[34] / 10000.;
          glomx = -vals[35] / 10000.;
          glamn = vals[34] / 10000.;
          glomn = -vals[35] / 10000.;
          ginct = vals[38] / 10000.;
          gincn = (navType == PSEUDO_MERCATOR_GENERAL)
                  ? vals[39] / 10000.
                  : ginct;
          addParam("Latin", String.valueOf(20));
          //addParam(DX, String.valueOf(gincn));
          //addParam(DY, String.valueOf(ginct));
                  /*
                  if (wierd) {
                    double x = xnr;
                    xnr = xnc;
                    xnc = x;
                  }
                  */
          break;

        case PS_OR_LAMBERT_CONIC:
          xrowi = vals[34] / 10000.;  // row # of the North pole*10000
          xcoli = vals[35] / 10000.;  // col # of the North pole*10000
          xspace = vals[36];  // column spacing at standard lat (m)
          xqlon = -vals[37] / 10000.;  // lon parallel to cols (deg*10000)
          xt1 = vals[38] / 10000.;  // first standard lat
          xt2 = vals[39] / 10000.;  // second standard lat
          addParam(LATIN1, String.valueOf(xt1));
          addParam(LOV, String.valueOf(xqlon));
          addParam(LATIN2, String.valueOf(xt2));
          addParam(DX, String.valueOf(xspace));
          addParam(DY, String.valueOf(xspace));
                  /*
                  xh = (xt1 >= 0) ? 1. : -1.;
                  xt1 =(90.-xh*xt1)*xrad;
                  xt2 =(90.-xh*xt2)*xrad;
                  xfac =1.0;
                  if (xt1 != xt2)
                     xfac = (Math.log(Math.sin(xt1))-Math.log(Math.sin(xt2)))/
                            (Math.log(Math.tan(.5*xt1))-Math.log(Math.tan(.5*xt2)));
                  xfac = 1.0/xfac;
                  xblat = 6370. * Math.sin(xt1)/
                           (xspace*xfac*(Math.pow(Math.tan(xt1*.5),xfac)));
                  if (wierd) {
                     double x=xnr;
                     xnr=xnc;
                     xnc=x;
                     x=xcoli;
                     xcoli=xrowi;
                     xrowi=xnr-x+1.0;
                     xqlon=xqlon+90.;
                  }
                  */

          break;

        case EQUIDISTANT:
          xrowi = 1.;
          xcoli = 1.;
          glamx = vals[34] / 10000.;   // lat of (1,1) degrees*10000
          glomx = -vals[35] / 10000.;  // lon of (1,1) degrees*10000
          //xrot  = -xrad*vals[36]/10000.; // clockwise rotation of col 1
          xspace = vals[37] / 1000.;   // column spacing
          yspace = vals[38] / 1000.;   // row spacing
          addParam(LA1, String.valueOf(glamx));
          addParam(LO1, String.valueOf(glomx));
          addParam(DX, String.valueOf(xspace));
          addParam(DY, String.valueOf(yspace));
                  /*
                  xblat = EARTH_RADIUS*xrad/yspace;
                  xblon = EARTH_RADIUS*xrad/xspace;

                  if (wierd) {
                    double x = xnr;
                    xnr = xnc;
                    xnc = x;
                  }
                  */

          break;

        case LAMBERT_CONFORMAL_TANGENT:
          xrowi = vals[34] / 10000.;  // lat at (1,1)
          xcoli = vals[35] / 10000.;  // lon at (1,1)
          xspace = vals[36];  // column spacing at standard lat (m)
          xqlon = -vals[37] / 10000.;  // lon parallel to cols (deg*10000)
          xt1 = vals[38] / 10000.;  // standard lat 1
          xt2 = vals[39] / 10000.;  // standard lat 2
          if (Double.compare(xt2, (double) McIDASUtil.MCMISSING) == 0 || (xt2 == 0)) { // LOOK suspicious floating point point compare
            xt2 = xt1;
          }
          addParam(LATIN1, String.valueOf(xt1));
          addParam(LOV, String.valueOf(xqlon));
          addParam(LATIN2, String.valueOf(xt2));
          addParam(DX, String.valueOf(xspace));
          addParam(DY, String.valueOf(xspace));
                  /*
                  xh = (xt1 >= 0) ? 1. : -1.;
                  xt1 = (90. - xh * xt1) * xrad;
                  xfac = Math.cos(xt1);
                  xblat = EARTH_RADIUS * Math.tan(xt1) /
                             (xspace * Math.pow(Math.tan(xt1*.5), xfac));
                             */

          break;

        default:
          break;
      }
    } catch (McIDASException me) {
      System.out.println("couldn't set nav");
    }

  }
private void setParams ( ) { /* PS and CONF projection parameters */ double xrowi ; // row # of North Pole*10000 double xcoli ; // column # of North Pole* 10000 double xqlon ; // longitude parallel to columns double xspace ; // column spacing at standard latitude double yspace ; // row spacing at standard latitude double xt1 ; // standard latitude double xt2 ; // 2nd standard latitude double xh ; // double xfac ; // double xblat ; // /* Merc and pseudo_merc parameters */ double glamx ; // max latitude double glomx ; // max longitude double glamn ; // min latitude double glomn ; // min longitude double ginct ; // grid increment in latitude double gincn ; // grid increment in longitude try { GRIDnav nav = new GRIDnav ( vals ) ; int gridType = vals [ 33 ] ; int navType = gridType % 10 ; addParam ( "Proj" , String . valueOf ( navType ) ) ; boolean wierd = gridType / 10 == 1 ; int ny = vals [ 1 ] ; int nx = vals [ 2 ] ; addParam ( PROJ , getProjName ( navType ) ) ; addParam ( NX , String . valueOf ( nx ) ) ; addParam ( NY , String . valueOf ( ny ) ) ; double [ ] [ ] input ; if ( nav . isFlippedRowCoordinates ( ) ) { input = new double [ ] [ ] { { 1 , nx } , { 1 , ny } } ; } else { input = new double [ ] [ ] { { 1 , nx } , { ny , 1 } } ; } double [ ] [ ] llur = nav . toLatLon ( input ) ; /*
            if (cnt == 0 && navType == 6) {
                System.out.println("Proj = " + getProjName(navType) + ":" + navType);
                System.out.println("isFlipped = " + nav.isFlippedRowCoordinates());
                ucar.unidata.util.Misc.printArray("input x", input[0]);
                ucar.unidata.util.Misc.printArray("input y", input[1]);
                ucar.unidata.util.Misc.printArray("lats", llur[0]);
                ucar.unidata.util.Misc.printArray("lons", llur[1]);
                cnt++;
            }
            */ addParam ( LA1 , String . valueOf ( llur [ 0 ] [ 0 ] ) ) ; addParam ( LO1 , String . valueOf ( llur [ 1 ] [ 0 ] ) ) ; addParam ( LA2 , String . valueOf ( llur [ 0 ] [ 1 ] ) ) ; addParam ( LO2 , String . valueOf ( llur [ 1 ] [ 1 ] ) ) ; switch ( navType ) { case PSEUDO_MERCATOR : case PSEUDO_MERCATOR_GENERAL : glamx = vals [ 34 ] / 10000. ; glomx = - vals [ 35 ] / 10000. ; glamn = vals [ 34 ] / 10000. ; glomn = - vals [ 35 ] / 10000. ; ginct = vals [ 38 ] / 10000. ; gincn = ( navType == PSEUDO_MERCATOR_GENERAL ) ? vals [ 39 ] / 10000. : ginct ; addParam ( "Latin" , String . valueOf ( 20 ) ) ; //addParam(DX, String.valueOf(gincn)); //addParam(DY, String.valueOf(ginct)); /*
                  if (wierd) {
                    double x = xnr;
                    xnr = xnc;
                    xnc = x;
                  }
                  */ break ; case PS_OR_LAMBERT_CONIC : xrowi = vals [ 34 ] / 10000. ; // row # of the North pole*10000 xcoli = vals [ 35 ] / 10000. ; // col # of the North pole*10000 xspace = vals [ 36 ] ; // column spacing at standard lat (m) xqlon = - vals [ 37 ] / 10000. ; // lon parallel to cols (deg*10000) xt1 = vals [ 38 ] / 10000. ; // first standard lat xt2 = vals [ 39 ] / 10000. ; // second standard lat addParam ( LATIN1 , String . valueOf ( xt1 ) ) ; addParam ( LOV , String . valueOf ( xqlon ) ) ; addParam ( LATIN2 , String . valueOf ( xt2 ) ) ; addParam ( DX , String . valueOf ( xspace ) ) ; addParam ( DY , String . valueOf ( xspace ) ) ; /*
                  xh = (xt1 >= 0) ? 1. : -1.;
                  xt1 =(90.-xh*xt1)*xrad;
                  xt2 =(90.-xh*xt2)*xrad;
                  xfac =1.0;
                  if (xt1 != xt2)
                     xfac = (Math.log(Math.sin(xt1))-Math.log(Math.sin(xt2)))/
                            (Math.log(Math.tan(.5*xt1))-Math.log(Math.tan(.5*xt2)));
                  xfac = 1.0/xfac;
                  xblat = 6370. * Math.sin(xt1)/
                           (xspace*xfac*(Math.pow(Math.tan(xt1*.5),xfac)));
                  if (wierd) {
                     double x=xnr;
                     xnr=xnc;
                     xnc=x;
                     x=xcoli;
                     xcoli=xrowi;
                     xrowi=xnr-x+1.0;
                     xqlon=xqlon+90.;
                  }
                  */ break ; case EQUIDISTANT : xrowi = 1. ; xcoli = 1. ; glamx = vals [ 34 ] / 10000. ; // lat of (1,1) degrees*10000 glomx = - vals [ 35 ] / 10000. ; // lon of (1,1) degrees*10000 //xrot  = -xrad*vals[36]/10000.; // clockwise rotation of col 1 xspace = vals [ 37 ] / 1000. ; // column spacing yspace = vals [ 38 ] / 1000. ; // row spacing addParam ( LA1 , String . valueOf ( glamx ) ) ; addParam ( LO1 , String . valueOf ( glomx ) ) ; addParam ( DX , String . valueOf ( xspace ) ) ; addParam ( DY , String . valueOf ( yspace ) ) ; /*
                  xblat = EARTH_RADIUS*xrad/yspace;
                  xblon = EARTH_RADIUS*xrad/xspace;

                  if (wierd) {
                    double x = xnr;
                    xnr = xnc;
                    xnc = x;
                  }
                  */ break ; case LAMBERT_CONFORMAL_TANGENT : xrowi = vals [ 34 ] / 10000. ; // lat at (1,1) xcoli = vals [ 35 ] / 10000. ; // lon at (1,1) xspace = vals [ 36 ] ; // column spacing at standard lat (m) xqlon = - vals [ 37 ] / 10000. ; // lon parallel to cols (deg*10000) xt1 = vals [ 38 ] / 10000. ; // standard lat 1 xt2 = vals [ 39 ] / 10000. ; // standard lat 2 if ( Double . compare ( xt2 , ( double ) McIDASUtil . MCMISSING ) == 0 || ( xt2 == 0 ) ) { // LOOK suspicious floating point point compare xt2 = xt1 ; } addParam ( LATIN1 , String . valueOf ( xt1 ) ) ; addParam ( LOV , String . valueOf ( xqlon ) ) ; addParam ( LATIN2 , String . valueOf ( xt2 ) ) ; addParam ( DX , String . valueOf ( xspace ) ) ; addParam ( DY , String . valueOf ( xspace ) ) ; /*
                  xh = (xt1 >= 0) ? 1. : -1.;
                  xt1 = (90. - xh * xt1) * xrad;
                  xfac = Math.cos(xt1);
                  xblat = EARTH_RADIUS * Math.tan(xt1) /
                             (xspace * Math.pow(Math.tan(xt1*.5), xfac));
                             */ break ; default : break ; } } catch ( McIDASException me ) { System . out . println ( "couldn't set nav" ) ; } }
Set the parameters for the GDS
Set the parameters for the GDS