cdm/src/main/java/ucar/nc2/dataset/conv/Cosmic1Convention.java
public void augmentDataset(NetcdfDataset ds,
                             CancelTask cancelTask) throws IOException {

    Attribute leoAtt = ds.findGlobalAttribute("leoId");

    if (leoAtt == null) {
      if (ds.findVariable("time") == null) {
        // create a time variable - assume its linear along the vertical dimension
        double start = ds.readAttributeDouble(null, "start_time",
                Double.NaN);
        double stop = ds.readAttributeDouble(null, "stop_time",
                Double.NaN);

        if (Double.isNaN(start) && Double.isNaN(stop)) {
          double top = ds.readAttributeDouble(null, "toptime",
                  Double.NaN);
          double bot = ds.readAttributeDouble(null, "bottime",
                  Double.NaN);

          this.conventionName = "Cosmic2";
          if (top > bot) {
            stop = top;
            start = bot;
          } else {
            stop = bot;
            start = top;
          }

        }

        Dimension dim = ds.findDimension("MSL_alt");
        Variable dimV = ds.findVariable("MSL_alt");
        Array dimU = dimV.read();
        int inscr = (dimU.getFloat(1) - dimU.getFloat(0)) > 0
                ? 1
                : 0;
        int n = dim.getLength();
        double incr = (stop - start) / n;

        String timeUnits = "seconds since 1980-01-06 00:00:00";
        Variable timeVar = new VariableDS(ds, null, null, "time",
                DataType.DOUBLE, dim.getShortName(),
                timeUnits, null);
        ds.addVariable(null, timeVar);
        timeVar.addAttribute(new Attribute(CDM.UNITS, timeUnits));
        timeVar.addAttribute(new Attribute(_Coordinate.AxisType,
                AxisType.Time.toString()));
        int dir = ds.readAttributeInteger(null, "irs", 1);
        ArrayDouble.D1 data =
                (ArrayDouble.D1) Array.factory(DataType.DOUBLE,
                        new int[]{n});
        if (inscr == 0) {
          if (dir == 1) {
            for (int i = 0; i < n; i++) {
              data.set(i, start + i * incr);
            }
          } else {
            for (int i = 0; i < n; i++) {
              data.set(i, stop - i * incr);
            }
          }
        } else {
          for (int i = 0; i < n; i++) {
            data.set(i, stop - i * incr);
          }
        }
        timeVar.setCachedData(data, false);
      }

      Variable v = ds.findVariable("Lat");
      if (v == null) {
        v = ds.findVariable("GEO_lat");
      }
      v.addAttribute(new Attribute(_Coordinate.AxisType,
              AxisType.Lat.toString()));
      Variable v1 = ds.findVariable("Lon");
      if (v1 == null) {
        v1 = ds.findVariable("GEO_lon");
      }
      v1.addAttribute(new Attribute(_Coordinate.AxisType,
              AxisType.Lon.toString()));
    } else {
      Dimension dim = ds.findDimension("time");
      int n = dim.getLength();
      Variable latVar = new VariableDS(ds, null, null, "Lat",
              DataType.FLOAT, dim.getShortName(),
              "degree", null);
      latVar.addAttribute(new Attribute(_Coordinate.AxisType,
              AxisType.Lat.toString()));
      ds.addVariable(null, latVar);
      Variable lonVar = new VariableDS(ds, null, null, "Lon",
              DataType.FLOAT, dim.getShortName(),
              "degree", null);
      lonVar.addAttribute(new Attribute(_Coordinate.AxisType,
              AxisType.Lon.toString()));
      ds.addVariable(null, lonVar);
      Variable altVar = new VariableDS(ds, null, null, "MSL_alt",
              DataType.FLOAT, dim.getShortName(),
              "meter", null);
      altVar.addAttribute(new Attribute(_Coordinate.AxisType,
              AxisType.Height.toString()));
      ds.addVariable(null, altVar);

      // cal data array
      ArrayFloat.D1 latData =
              (ArrayFloat.D1) Array.factory(DataType.FLOAT,
                      new int[]{n});
      ArrayFloat.D1 lonData =
              (ArrayFloat.D1) Array.factory(DataType.FLOAT,
                      new int[]{n});
      ArrayFloat.D1 altData =
              (ArrayFloat.D1) Array.factory(DataType.FLOAT,
                      new int[]{n});
      ArrayDouble.D1 timeData =
              (ArrayDouble.D1) Array.factory(DataType.DOUBLE,
                      new int[]{n});
      this.conventionName = "Cosmic3";

      int iyr = ds.readAttributeInteger(null, "year", 2009);
      int mon = ds.readAttributeInteger(null, "month", 0);
      int iday = ds.readAttributeInteger(null, "day", 0);
      int ihr = ds.readAttributeInteger(null, "hour", 0);
      int min = ds.readAttributeInteger(null, "minute", 0);
      int sec = ds.readAttributeInteger(null, "second", 0);

      double start = ds.readAttributeDouble(null, "startTime",
              Double.NaN);
      double stop = ds.readAttributeDouble(null, "stopTime",
              Double.NaN);
      double incr = (stop - start) / n;
      int t = 0;
      // double julian = juday(mon, iday, iyr);
      // cal the dtheta based pm attributes
      double dtheta = gast(iyr, mon, iday, ihr, min, sec, t);

      Variable tVar = ds.findVariable("time");
      String timeUnits = "seconds since 1980-01-06 00:00:00";  //dtime.getUnit().toString();
      tVar.removeAttributeIgnoreCase(CDM.VALID_RANGE);
      tVar.removeAttributeIgnoreCase(CDM.UNITS);
      tVar.addAttribute(new Attribute(CDM.UNITS, timeUnits));
      tVar.addAttribute(new Attribute(_Coordinate.AxisType,
              AxisType.Time.toString()));

      Variable v = ds.findVariable("xLeo");
      Array xLeo = v.read();
      v = ds.findVariable("yLeo");
      Array yLeo = v.read();
      v = ds.findVariable("zLeo");
      Array zLeo = v.read();
      double a = 6378.1370;
      double b = 6356.7523142;
      IndexIterator iiter0 = xLeo.getIndexIterator();
      IndexIterator iiter1 = yLeo.getIndexIterator();
      IndexIterator iiter2 = zLeo.getIndexIterator();
      int i = 0;

      while (iiter0.hasNext()) {

        double[] v_inertial = new double[3];
        v_inertial[0] = iiter0.getDoubleNext();  //.getDouble(i); //.nextDouble();
        v_inertial[1] = iiter1.getDoubleNext();  //.getDouble(i); //.nextDouble();
        v_inertial[2] = iiter2.getDoubleNext();  //.getDouble(i); //.nextDouble();
        double[] uvz = new double[3];
        uvz[0] = 0.0;
        uvz[1] = 0.0;
        uvz[2] = 1.0;
        // v_ecef should be in the (approximate) ECEF frame

        // double[] v_ecf = execute(v_inertial, julian);
        double[] v_ecf = spin(v_inertial, uvz, -1 * dtheta);

        // cal lat/lon here
        // double [] llh = ECFtoLLA(v_ecf[0]*1000, v_ecf[1]*1000, v_ecf[2]*1000, a,  b);
        double[] llh = xyzell(a, b, v_ecf);
        latData.set(i, (float) llh[0]);
        lonData.set(i, (float) llh[1]);
        altData.set(i, (float) llh[2]);
        timeData.set(i, start + i * incr);
        i++;
      }

      latVar.setCachedData(latData, false);
      lonVar.setCachedData(lonData, false);
      altVar.setCachedData(altData, false);
      tVar.setCachedData(timeData, false);
    }
    ds.finish();

  }
public void augmentDataset(NetcdfDataset ds,
                             CancelTask cancelTask) throws IOException {

    Attribute leoAtt = ds.findGlobalAttribute("leoId");

    if (leoAtt == null) {
      if (ds.findVariable("time") == null) {
        // create a time variable - assume its linear along the vertical dimension
        double start = ds.readAttributeDouble(null, "start_time",
                Double.NaN);
        double stop = ds.readAttributeDouble(null, "stop_time",
                Double.NaN);

        if (Double.isNaN(start) && Double.isNaN(stop)) {
          double top = ds.readAttributeDouble(null, "toptime",
                  Double.NaN);
          double bot = ds.readAttributeDouble(null, "bottime",
                  Double.NaN);

          this.conventionName = "Cosmic2";
          if (top > bot) {
            stop = top;
            start = bot;
          } else {
            stop = bot;
            start = top;
          }

        }

        Dimension dim = ds.findDimension("MSL_alt");
        Variable dimV = ds.findVariable("MSL_alt");
        Array dimU = dimV.read();
        int inscr = (dimU.getFloat(1) - dimU.getFloat(0)) > 0
                ? 1
                : 0;
        int n = dim.getLength();
        double incr = (stop - start) / n;

        String timeUnits = "seconds since 1980-01-06 00:00:00";
        Variable timeVar = new VariableDS(ds, null, null, "time",
                DataType.DOUBLE, dim.getShortName(),
                timeUnits, null);
        ds.addVariable(null, timeVar);
        timeVar.addAttribute(new Attribute(CDM.UNITS, timeUnits));
        timeVar.addAttribute(new Attribute(_Coordinate.AxisType,
                AxisType.Time.toString()));
        int dir = ds.readAttributeInteger(null, "irs", 1);
        ArrayDouble.D1 data =
                (ArrayDouble.D1) Array.factory(DataType.DOUBLE,
                        new int[]{n});
        if (inscr == 0) {
          if (dir == 1) {
            for (int i = 0; i < n; i++) {
              data.set(i, start + i * incr);
            }
          } else {
            for (int i = 0; i < n; i++) {
              data.set(i, stop - i * incr);
            }
          }
        } else {
          for (int i = 0; i < n; i++) {
            data.set(i, stop - i * incr);
          }
        }
        timeVar.setCachedData(data, false);
      }

      Variable v = ds.findVariable("Lat");
      if (v == null) {
        v = ds.findVariable("GEO_lat");
      }
      v.addAttribute(new Attribute(_Coordinate.AxisType,
              AxisType.Lat.toString()));
      Variable v1 = ds.findVariable("Lon");
      if (v1 == null) {
        v1 = ds.findVariable("GEO_lon");
      }
      v1.addAttribute(new Attribute(_Coordinate.AxisType,
              AxisType.Lon.toString()));
    } else {
      Dimension dim = ds.findDimension("time");
      int n = dim.getLength();
      Variable latVar = new VariableDS(ds, null, null, "Lat",
              DataType.FLOAT, dim.getShortName(),
              "degree", null);
      latVar.addAttribute(new Attribute(_Coordinate.AxisType,
              AxisType.Lat.toString()));
      ds.addVariable(null, latVar);
      Variable lonVar = new VariableDS(ds, null, null, "Lon",
              DataType.FLOAT, dim.getShortName(),
              "degree", null);
      lonVar.addAttribute(new Attribute(_Coordinate.AxisType,
              AxisType.Lon.toString()));
      ds.addVariable(null, lonVar);
      Variable altVar = new VariableDS(ds, null, null, "MSL_alt",
              DataType.FLOAT, dim.getShortName(),
              "meter", null);
      altVar.addAttribute(new Attribute(_Coordinate.AxisType,
              AxisType.Height.toString()));
      ds.addVariable(null, altVar);

      // cal data array
      ArrayFloat.D1 latData =
              (ArrayFloat.D1) Array.factory(DataType.FLOAT,
                      new int[]{n});
      ArrayFloat.D1 lonData =
              (ArrayFloat.D1) Array.factory(DataType.FLOAT,
                      new int[]{n});
      ArrayFloat.D1 altData =
              (ArrayFloat.D1) Array.factory(DataType.FLOAT,
                      new int[]{n});
      ArrayDouble.D1 timeData =
              (ArrayDouble.D1) Array.factory(DataType.DOUBLE,
                      new int[]{n});
      this.conventionName = "Cosmic3";

      int iyr = ds.readAttributeInteger(null, "year", 2009);
      int mon = ds.readAttributeInteger(null, "month", 0);
      int iday = ds.readAttributeInteger(null, "day", 0);
      int ihr = ds.readAttributeInteger(null, "hour", 0);
      int min = ds.readAttributeInteger(null, "minute", 0);
      int sec = ds.readAttributeInteger(null, "second", 0);

      double start = ds.readAttributeDouble(null, "startTime",
              Double.NaN);
      double stop = ds.readAttributeDouble(null, "stopTime",
              Double.NaN);
      double incr = (stop - start) / n;
      int t = 0;
      // double julian = juday(mon, iday, iyr);
      // cal the dtheta based pm attributes
      double dtheta = gast(iyr, mon, iday, ihr, min, sec, t);

      Variable tVar = ds.findVariable("time");
      String timeUnits = "seconds since 1980-01-06 00:00:00";  //dtime.getUnit().toString();
      tVar.removeAttributeIgnoreCase(CDM.VALID_RANGE);
      tVar.removeAttributeIgnoreCase(CDM.UNITS);
      tVar.addAttribute(new Attribute(CDM.UNITS, timeUnits));
      tVar.addAttribute(new Attribute(_Coordinate.AxisType,
              AxisType.Time.toString()));

      Variable v = ds.findVariable("xLeo");
      Array xLeo = v.read();
      v = ds.findVariable("yLeo");
      Array yLeo = v.read();
      v = ds.findVariable("zLeo");
      Array zLeo = v.read();
      double a = 6378.1370;
      double b = 6356.7523142;
      IndexIterator iiter0 = xLeo.getIndexIterator();
      IndexIterator iiter1 = yLeo.getIndexIterator();
      IndexIterator iiter2 = zLeo.getIndexIterator();
      int i = 0;

      while (iiter0.hasNext()) {

        double[] v_inertial = new double[3];
        v_inertial[0] = iiter0.getDoubleNext();  //.getDouble(i); //.nextDouble();
        v_inertial[1] = iiter1.getDoubleNext();  //.getDouble(i); //.nextDouble();
        v_inertial[2] = iiter2.getDoubleNext();  //.getDouble(i); //.nextDouble();
        double[] uvz = new double[3];
        uvz[0] = 0.0;
        uvz[1] = 0.0;
        uvz[2] = 1.0;
        // v_ecef should be in the (approximate) ECEF frame

        // double[] v_ecf = execute(v_inertial, julian);
        double[] v_ecf = spin(v_inertial, uvz, -1 * dtheta);

        // cal lat/lon here
        // double [] llh = ECFtoLLA(v_ecf[0]*1000, v_ecf[1]*1000, v_ecf[2]*1000, a,  b);
        double[] llh = xyzell(a, b, v_ecf);
        latData.set(i, (float) llh[0]);
        lonData.set(i, (float) llh[1]);
        altData.set(i, (float) llh[2]);
        timeData.set(i, start + i * incr);
        i++;
      }

      latVar.setCachedData(latData, false);
      lonVar.setCachedData(lonData, false);
      altVar.setCachedData(altData, false);
      tVar.setCachedData(timeData, false);
    }
    ds.finish();

  }
public void augmentDataset ( NetcdfDataset ds , CancelTask cancelTask ) throws IOException { Attribute leoAtt = ds . findGlobalAttribute ( "leoId" ) ; if ( leoAtt == null ) { if ( ds . findVariable ( "time" ) == null ) { // create a time variable - assume its linear along the vertical dimension
 double start = ds . readAttributeDouble ( null , "start_time" , Double . NaN ) ; double stop = ds . readAttributeDouble ( null , "stop_time" , Double . NaN ) ; if ( Double . isNaN ( start ) && Double . isNaN ( stop ) ) { double top = ds . readAttributeDouble ( null , "toptime" , Double . NaN ) ; double bot = ds . readAttributeDouble ( null , "bottime" , Double . NaN ) ; this . conventionName = "Cosmic2" ; if ( top > bot ) { stop = top ; start = bot ; } else { stop = bot ; start = top ; } } Dimension dim = ds . findDimension ( "MSL_alt" ) ; Variable dimV = ds . findVariable ( "MSL_alt" ) ; Array dimU = dimV . read ( ) ; int inscr = ( dimU . getFloat ( 1 ) - dimU . getFloat ( 0 ) ) > 0 ? 1 : 0 ; int n = dim . getLength ( ) ; double incr = ( stop - start ) / n ; String timeUnits = "seconds since 1980-01-06 00:00:00" ; Variable timeVar = new VariableDS ( ds , null , null , "time" , DataType . DOUBLE , dim . getShortName ( ) , timeUnits , null ) ; ds . addVariable ( null , timeVar ) ; timeVar . addAttribute ( new Attribute ( CDM . UNITS , timeUnits ) ) ; timeVar . addAttribute ( new Attribute ( _Coordinate . AxisType , AxisType . Time . toString ( ) ) ) ; int dir = ds . readAttributeInteger ( null , "irs" , 1 ) ; ArrayDouble . D1 data = ( ArrayDouble . D1 ) Array . factory ( DataType . DOUBLE , new int [ ] { n } ) ; if ( inscr == 0 ) { if ( dir == 1 ) { for ( int i = 0 ; i < n ; i ++ ) { data . set ( i , start + i * incr ) ; } } else { for ( int i = 0 ; i < n ; i ++ ) { data . set ( i , stop - i * incr ) ; } } } else { for ( int i = 0 ; i < n ; i ++ ) { data . set ( i , stop - i * incr ) ; } } timeVar . setCachedData ( data , false ) ; } Variable v = ds . findVariable ( "Lat" ) ; if ( v == null ) { v = ds . findVariable ( "GEO_lat" ) ; } v . addAttribute ( new Attribute ( _Coordinate . AxisType , AxisType . Lat . toString ( ) ) ) ; Variable v1 = ds . findVariable ( "Lon" ) ; if ( v1 == null ) { v1 = ds . findVariable ( "GEO_lon" ) ; } v1 . addAttribute ( new Attribute ( _Coordinate . AxisType , AxisType . Lon . toString ( ) ) ) ; } else { Dimension dim = ds . findDimension ( "time" ) ; int n = dim . getLength ( ) ; Variable latVar = new VariableDS ( ds , null , null , "Lat" , DataType . FLOAT , dim . getShortName ( ) , "degree" , null ) ; latVar . addAttribute ( new Attribute ( _Coordinate . AxisType , AxisType . Lat . toString ( ) ) ) ; ds . addVariable ( null , latVar ) ; Variable lonVar = new VariableDS ( ds , null , null , "Lon" , DataType . FLOAT , dim . getShortName ( ) , "degree" , null ) ; lonVar . addAttribute ( new Attribute ( _Coordinate . AxisType , AxisType . Lon . toString ( ) ) ) ; ds . addVariable ( null , lonVar ) ; Variable altVar = new VariableDS ( ds , null , null , "MSL_alt" , DataType . FLOAT , dim . getShortName ( ) , "meter" , null ) ; altVar . addAttribute ( new Attribute ( _Coordinate . AxisType , AxisType . Height . toString ( ) ) ) ; ds . addVariable ( null , altVar ) ; // cal data array
 ArrayFloat . D1 latData = ( ArrayFloat . D1 ) Array . factory ( DataType . FLOAT , new int [ ] { n } ) ; ArrayFloat . D1 lonData = ( ArrayFloat . D1 ) Array . factory ( DataType . FLOAT , new int [ ] { n } ) ; ArrayFloat . D1 altData = ( ArrayFloat . D1 ) Array . factory ( DataType . FLOAT , new int [ ] { n } ) ; ArrayDouble . D1 timeData = ( ArrayDouble . D1 ) Array . factory ( DataType . DOUBLE , new int [ ] { n } ) ; this . conventionName = "Cosmic3" ; int iyr = ds . readAttributeInteger ( null , "year" , 2009 ) ; int mon = ds . readAttributeInteger ( null , "month" , 0 ) ; int iday = ds . readAttributeInteger ( null , "day" , 0 ) ; int ihr = ds . readAttributeInteger ( null , "hour" , 0 ) ; int min = ds . readAttributeInteger ( null , "minute" , 0 ) ; int sec = ds . readAttributeInteger ( null , "second" , 0 ) ; double start = ds . readAttributeDouble ( null , "startTime" , Double . NaN ) ; double stop = ds . readAttributeDouble ( null , "stopTime" , Double . NaN ) ; double incr = ( stop - start ) / n ; int t = 0 ; // double julian = juday(mon, iday, iyr);
 // cal the dtheta based pm attributes
 double dtheta = gast ( iyr , mon , iday , ihr , min , sec , t ) ; Variable tVar = ds . findVariable ( "time" ) ; String timeUnits = "seconds since 1980-01-06 00:00:00" ; //dtime.getUnit().toString();
 tVar . removeAttributeIgnoreCase ( CDM . VALID_RANGE ) ; tVar . removeAttributeIgnoreCase ( CDM . UNITS ) ; tVar . addAttribute ( new Attribute ( CDM . UNITS , timeUnits ) ) ; tVar . addAttribute ( new Attribute ( _Coordinate . AxisType , AxisType . Time . toString ( ) ) ) ; Variable v = ds . findVariable ( "xLeo" ) ; Array xLeo = v . read ( ) ; v = ds . findVariable ( "yLeo" ) ; Array yLeo = v . read ( ) ; v = ds . findVariable ( "zLeo" ) ; Array zLeo = v . read ( ) ; double a = 6378.1370 ; double b = 6356.7523142 ; IndexIterator iiter0 = xLeo . getIndexIterator ( ) ; IndexIterator iiter1 = yLeo . getIndexIterator ( ) ; IndexIterator iiter2 = zLeo . getIndexIterator ( ) ; int i = 0 ; while ( iiter0 . hasNext ( ) ) { double [ ] v_inertial = new double [ 3 ] ; v_inertial [ 0 ] = iiter0 . getDoubleNext ( ) ; //.getDouble(i); //.nextDouble();
 v_inertial [ 1 ] = iiter1 . getDoubleNext ( ) ; //.getDouble(i); //.nextDouble();
 v_inertial [ 2 ] = iiter2 . getDoubleNext ( ) ; //.getDouble(i); //.nextDouble();
 double [ ] uvz = new double [ 3 ] ; uvz [ 0 ] = 0.0 ; uvz [ 1 ] = 0.0 ; uvz [ 2 ] = 1.0 ; // v_ecef should be in the (approximate) ECEF frame
 // double[] v_ecf = execute(v_inertial, julian);
 double [ ] v_ecf = spin ( v_inertial , uvz , - 1 * dtheta ) ; // cal lat/lon here
 // double [] llh = ECFtoLLA(v_ecf[0]*1000, v_ecf[1]*1000, v_ecf[2]*1000, a,  b);
 double [ ] llh = xyzell ( a , b , v_ecf ) ; latData . set ( i , ( float ) llh [ 0 ] ) ; lonData . set ( i , ( float ) llh [ 1 ] ) ; altData . set ( i , ( float ) llh [ 2 ] ) ; timeData . set ( i , start + i * incr ) ; i ++ ; } latVar . setCachedData ( latData , false ) ; lonVar . setCachedData ( lonData , false ) ; altVar . setCachedData ( altData , false ) ; tVar . setCachedData ( timeData , false ) ; } ds . finish ( ) ; }
_more_

@param ds         _more_
@param cancelTask _more_
@throws IOException _more_
_more_