package ucar.nc2.iosp.grib;

/**
* Copyright 1998-2009 University Corporation for Atmospheric Research/Unidata
*
* Portions of this software were developed by the Unidata Program at the
* University Corporation for Atmospheric Research.
*
* Access and use of this software shall impose the following obligations
* and understandings on the user. The user is granted the right, without
* any fee or cost, to use, copy, modify, alter, enhance and distribute
* this software, and any derivative works thereof, and its supporting
* documentation for any purpose whatsoever, provided that this entire
* notice appears in all copies of the software, derivative works and
* supporting documentation.  Further, UCAR requests that the user credit
* UCAR/Unidata in any publications that result from the use of this
* software or in any product that includes this software. The names UCAR
* and/or Unidata, however, may not be used in any advertising or publicity
* to endorse or promote any products or commercial entity unless specific
* written permission is obtained from UCAR/Unidata. The user also
* understands that UCAR/Unidata is not obligated to provide the user with
* any support, consulting, training or assistance of any kind with regard
* to the use, operation and performance of this software nor to provide
* the user with any updates, revisions, new versions or "bug fixes."
*
* THIS SOFTWARE IS PROVIDED BY UCAR/UNIDATA "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL UCAR/UNIDATA BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE ACCESS, USE OR PERFORMANCE OF THIS SOFTWARE.
*/

import ucar.nc2.TestAll;
import ucar.nc2.NetcdfFile;
import ucar.nc2.Variable;
import ucar.nc2.Dimension;

import java.io.IOException;
import java.io.File;

import junit.framework.TestCase;

/**
 * Created by IntelliJ IDEA.
 * User: Robb
 * Date: Nov 6, 2009
 * Time: 3:38:51 PM
 */
public class TestHybridData extends TestCase {
  public TestHybridData(String name) {
    super(name);
  }

  public void testCompare() throws IOException {
    File where = new File("C:/data/grib/hybrid");
    if (where.exists()) {
      String[] args = new String[1];
      args[0] = "C:/data/grib";
      doAll(args);
    } else {
      doAll(null);
    }
  }

  void doAll(String args[]) throws IOException {

    String dirB1;
    if (args == null || args.length < 1) {
      dirB1 = TestAll.testdataDir + "grid/grib/grib1/ecmwf";
    } else {
      dirB1 = args[0] + "/hybrid";
    }
    File dir = new File(dirB1);
    if (dir.isDirectory()) {
      System.out.println("In directory " + dir.getParent() + "/" + dir.getName());
      String[] children = dir.list();
      for (String child : children) {
        //System.out.println( "children i ="+ children[ i ]);
        File aChild = new File(dir, child);
        //System.out.println( "child ="+ child.getName() );
        if (aChild.isDirectory()) {
          // skip index *gbx and inventory *xml files
        } else if (
            child.length() == 0 ||
                child.endsWith("ncml") ||
                child.endsWith("gbx") ||
                child.endsWith("gbx8") ||
                child.endsWith("xml") ||
                child.endsWith("nc") ||
                child.startsWith("ls")) {

        } else {
          System.out.println("\n\nReading File " + child);
          //compareNC( dirB1 +"/"+ child, dirB2 +"/"+ child);
          long start = System.currentTimeMillis();

          NetcdfFile ncfile  = NetcdfFile.open(dirB1 + "/" + child);
          System.out.println("Time to create Netcdf object  " +
              (System.currentTimeMillis() - start) + "  ms");

          if (child.equals( "ECMWF.hybrid.grib1")) {
            Variable Hybrid = ncfile.findVariable( "hybrid");
            int idx = Hybrid.findDimensionIndex( "hybrid");
            Dimension dim = Hybrid.getDimension( idx );

          } else if (child.equals( "07010418_arw_d01.GrbF01500")) {
          }
          ncfile .close();
        }
      }
    } else {
    }
  }

  static public void main(String args[]) throws IOException {
    TestHybridData ggi = new TestHybridData("");
    ggi.testCompare();
  }


}

@@ -1965,16 +1965,114 @@
 RE.%0D%0A*/%0D
+%0A/**%0D%0A * Created by IntelliJ IDEA.%0D%0A * User: Robb%0D%0A * Date: Nov 6, 2009%0D%0A * Time: 3:38:51 PM%0D%0A */%0D
 %0A%0D%0Aimpor
@@ -2271,104 +2271,8 @@
 %0D%0A%0D%0A
-/**%0D%0A * Created by IntelliJ IDEA.%0D%0A * User: Robb%0D%0A * Date: Nov 6, 2009%0D%0A * Time: 3:38:51 PM%0D%0A */
 %0D%0Apu
@@ -4126,18 +4126,18 @@
 .grib1%22)
-)
  
+)
 %7B%0D%0A     
@@ -4186,32 +4186,414 @@
 le( %22hybrid%22);%0D%0A
+            assert( Hybrid.getNameAndDimensions().equals( %22hybrid(hybrid=91)%22));%0D%0A            Variable Hybrida = ncfile.findVariable( %22hybrida%22);%0D%0A            assert( Hybrida.getNameAndDimensions().equals( %22hybrida(hybrid=91)%22));%0D%0A            Variable Hybridb = ncfile.findVariable( %22hybridb%22);%0D%0A            assert( Hybridb.getNameAndDimensions().equals( %22hybridb(hybrid=91)%22));%0D%0A%0D%0A
             int 
@@ -4761,24 +4761,167 @@
 01500%22)) %7B%0D%0A
+            Variable Hybrid = ncfile.findVariable( %22hybrid%22);%0D%0A            assert(Hybrid.getNameAndDimensions().equals( %22hybrid(hybrid=2)%22));%0D%0A
           %7D%0D

Test hybrid variables