コード例 #1
0
ファイル: DumpNetCDF.java プロジェクト: jkachika/galileo
  public static void main(String[] args) throws Exception {
    DiskCache.setCachePolicy(true);

    File f = new File(args[0]);
    Pair<String, String> nameParts = FileNames.splitExtension(f);
    String ext = nameParts.b;
    if (ext.equals("grb") || ext.equals("bz2") || ext.equals("gz")) {
      Map<String, Metadata> metaMap = ConvertNetCDF.readFile(f.getAbsolutePath());

      /* Don't cache more than 1 GB: */
      DiskCache.cleanCache(1073741824, null);

      /*String[] attribs = { "temperature_surface",
      "total_cloud_cover_entire_atmosphere",
      "visibility_surface",
      "pressure_surface",
      "categorical_snow_yes1_no0_surface",
      "categorical_rain_yes1_no0_surface",
      "relative_humidity_zerodegc_isotherm" };*/
      String[] attribs = {"U-component_of_wind"};
      Metadata m = metaMap.get("9x");
      System.out.print("9x@" + m.getTemporalProperties().getStart() + "\t");
      for (String attrib : attribs) {
        System.out.print(m.getAttribute(attrib).getString() + "\t");
      }
      System.out.println();
    }
  }
コード例 #2
0
ファイル: ConvertNetCDF.java プロジェクト: jkachika/galileo
  public static void main(String[] args) throws Exception {
    DiskCache.setCachePolicy(true);

    File dir = new File(args[0]);
    for (File f : dir.listFiles()) {
      Pair<String, String> nameParts = FileNames.splitExtension(f);
      String ext = nameParts.b;
      if (ext.equals("grb") || ext.equals("bz2") || ext.equals("gz")) {
        Map<String, Metadata> metaMap = ConvertNetCDF.readFile(f.getAbsolutePath());

        /* Don't cache more than 1 GB: */
        DiskCache.cleanCache(1073741824, null);

        /* Now that we have geographically-partitioned files, let's pick
         * some attributes to store as indexable metadata. */

        /* Write converted files to disk */
        System.out.print("Writing converted files");
        int processed = 0;
        int increment = metaMap.keySet().size() / 50;
        for (String g : metaMap.keySet()) {
          Metadata meta = metaMap.get(g);

          /* Create the directory for this file */
          String storageDir = getStorageDir(args[1], meta);
          File destDir = new File(storageDir);
          if (!destDir.exists()) {
            if (!destDir.mkdirs()) {
              throw new IOException("Failed to create directory " + destDir);
            }
          }

          /* Create a file Block to store all the metadata in, and
           * generate a subset for indexing purposes. */
          Block block = createBlock(nameParts.a, meta);

          /* Write out the file */
          String outputName = nameParts.a + ".gblock";
          FileOutputStream fOut = new FileOutputStream(storageDir + "/" + outputName);
          fOut.write(Serializer.serialize(block));
          fOut.close();

          if (++processed % increment == 0) {
            System.out.print('.');
          }
        }
        System.out.println();
      }
    }
  }