예제 #1
0
 /**
  * Find the class for the projection
  *
  * @param proj projection
  * @return corresponding ProjectionClass (or null if not found)
  */
 private ProjectionClass findProjectionClass(Projection proj) {
   Class want = proj.getClass();
   ComboBoxModel projClassList = projClassCB.getModel();
   for (int i = 0; i < projClassList.getSize(); i++) {
     ProjectionClass pc = (ProjectionClass) projClassList.getElementAt(i);
     if (want.equals(pc.projClass)) {
       return pc;
     }
   }
   return null;
 }
  private Projection test(String filename, String ctvName, String varName, Class projClass)
      throws IOException, InvalidRangeException {
    System.out.printf("Open= %s%n", filename);
    NetcdfDataset ncd = ucar.nc2.dataset.NetcdfDataset.openDataset(filename);

    Variable ctv = null;
    if (ctvName != null) {
      ctv = ncd.findVariable(ctvName);
      assert ctv != null;
      System.out.println(" dump of ctv = \n" + ctv);
    }

    VariableDS v = (VariableDS) ncd.findVariable(varName);
    assert v != null;

    List<CoordinateSystem> cList = v.getCoordinateSystems();
    assert cList != null;
    assert cList.size() == 1;
    CoordinateSystem csys = cList.get(0);

    List<CoordinateTransform> pList = new ArrayList<CoordinateTransform>();
    List<CoordinateTransform> tList = csys.getCoordinateTransforms();
    assert tList != null;
    for (int i = 0; i < tList.size(); i++) {
      CoordinateTransform ct = tList.get(i);
      if (ct.getTransformType() == TransformType.Projection) pList.add(ct);
    }
    assert pList.size() == 1;
    CoordinateTransform ct = pList.get(0);
    assert ct.getTransformType() == TransformType.Projection;
    assert ct instanceof ProjectionCT;

    ProjectionCT vct = (ProjectionCT) ct;
    Projection proj = vct.getProjection();
    assert proj != null;
    assert projClass.isInstance(proj) : proj.getClass().getName();

    VariableDS ctvSyn = CoordTransBuilder.makeDummyTransformVariable(ncd, ct);
    System.out.println(" dump of equivilent ctv = \n" + ctvSyn);

    if (ctv != null) {
      Formatter f = new Formatter(System.out);
      CompareNetcdf.checkContains(ctv.getAttributes(), ctvSyn.getAttributes(), f);
    }

    ncd.close();
    return proj;
  }