// read in the index, create if it doesnt exist or is out of date
 public static Grib1TimePartition factory(
     TimePartitionCollection tpc, CollectionManager.Force force, Formatter f) throws IOException {
   Grib1TimePartitionBuilder builder =
       new Grib1TimePartitionBuilder(tpc.getCollectionName(), new File(tpc.getRoot()), tpc);
   builder.readOrCreateIndex(force, f);
   return builder.tp;
 }
 // read in the index, index raf already open
 public static Grib1TimePartition createFromIndex(
     String name, File directory, RandomAccessFile raf) throws IOException {
   Grib1TimePartitionBuilder builder = new Grib1TimePartitionBuilder(name, directory, null);
   if (builder.readIndex(raf)) {
     return builder.tp;
   }
   throw new IOException("Reading index failed");
 }
 // called by tdm
 public static boolean update(TimePartitionCollection tpc, Formatter f) throws IOException {
   Grib1TimePartitionBuilder builder =
       new Grib1TimePartitionBuilder(tpc.getCollectionName(), new File(tpc.getRoot()), tpc);
   if (!builder.needsUpdate()) return false;
   builder.readOrCreateIndex(CollectionManager.Force.always, f);
   builder.gc.close();
   return true;
 }
  /**
   * write new index if needed
   *
   * @param tpc use this collection
   * @param force force index
   * @param f put status messagess here
   * @return true if index was written
   * @throws IOException on error
   */
  public static boolean writeIndexFile(
      TimePartitionCollection tpc, CollectionManager.Force force, Formatter f) throws IOException {
    Grib1TimePartitionBuilder builder = null;
    try {
      builder =
          new Grib1TimePartitionBuilder(tpc.getCollectionName(), new File(tpc.getRoot()), tpc);
      return builder.readOrCreateIndex(force, f);

    } finally {
      if ((builder != null) && (builder.tp != null)) builder.tp.close();
    }
  }
 public static void main(String[] args) throws IOException {
   Formatter f = new Formatter();
   String indexName = (args.length > 0) ? args[0] : "F:/nomads/NOMADS-cfsrr-timeseries.ncx";
   RandomAccessFile raf = new RandomAccessFile(indexName, "r");
   Grib1TimePartition gtc = Grib1TimePartitionBuilder.createFromIndex("test", null, raf);
   gtc.showIndex(f);
   System.out.printf("%s%n", f);
 }