grib/src/main/java/ucar/nc2/grib/collection/GribCdmIndex.java
@Nullable
  public static GribCollectionMutable openMutableGCFromIndex(String indexFilename, FeatureCollectionConfig config, boolean dataOnly, boolean useCache, Logger logger) {
    File indexFileInCache = useCache ? GribIndexCache.getExistingFileOrCache(indexFilename) : new File(indexFilename);
    if (indexFileInCache == null) {
      return null;
    }
    String indexFilenameInCache = indexFileInCache.getPath();
    String name = makeNameFromIndexFilename(indexFilename);
    GribCollectionMutable result = null;

    try (RandomAccessFile raf = RandomAccessFile.acquire(indexFilenameInCache)) {
      GribCollectionType type = getType(raf);

      switch (type) {
        case GRIB2:
          result = Grib2CollectionBuilderFromIndex.openMutableGCFromIndex(name, raf, config, logger);
          break;
        case Partition2:
          result = Grib2PartitionBuilderFromIndex.openMutablePCFromIndex(name, raf, config, logger);
          break;
        case GRIB1:
          result = Grib1CollectionBuilderFromIndex.openMutableGCFromIndex(name, raf, config, logger);
          break;
        case Partition1:
          result = Grib1PartitionBuilderFromIndex.openMutablePCFromIndex(name, raf, config, logger);
          break;
        default:
          logger.warn("GribCdmIndex.openMutableGCFromIndex failed on {} type={}", indexFilenameInCache, type);
      }

      if (result != null) {
        result.lastModified = raf.getLastModified();
        result.fileSize = raf.length();
      }

    } catch (Throwable t) {
      logger.warn("GribCdmIndex.openMutableGCFromIndex failed on " + indexFilenameInCache, t);
    }

    if (result == null) {
      RandomAccessFile.eject(indexFilenameInCache);
      if (!indexFileInCache.delete())
        logger.warn("failed to delete {}", indexFileInCache.getPath());
    }

    return result;
  }
@Nullable
  public static GribCollectionMutable openMutableGCFromIndex(String indexFilename, FeatureCollectionConfig config, boolean dataOnly, boolean useCache, Logger logger) {
    File indexFileInCache = useCache ? GribIndexCache.getExistingFileOrCache(indexFilename) : new File(indexFilename);
    if (indexFileInCache == null) {
      return null;
    }
    String indexFilenameInCache = indexFileInCache.getPath();
    String name = makeNameFromIndexFilename(indexFilename);
    GribCollectionMutable result = null;

    try (RandomAccessFile raf = RandomAccessFile.acquire(indexFilenameInCache)) {
      GribCollectionType type = getType(raf);

      switch (type) {
        case GRIB2:
          result = Grib2CollectionBuilderFromIndex.openMutableGCFromIndex(name, raf, config, logger);
          break;
        case Partition2:
          result = Grib2PartitionBuilderFromIndex.openMutablePCFromIndex(name, raf, config, logger);
          break;
        case GRIB1:
          result = Grib1CollectionBuilderFromIndex.openMutableGCFromIndex(name, raf, config, logger);
          break;
        case Partition1:
          result = Grib1PartitionBuilderFromIndex.openMutablePCFromIndex(name, raf, config, logger);
          break;
        default:
          logger.warn("GribCdmIndex.openMutableGCFromIndex failed on {} type={}", indexFilenameInCache, type);
      }

      if (result != null) {
        result.lastModified = raf.getLastModified();
        result.fileSize = raf.length();
      }

    } catch (Throwable t) {
      logger.warn("GribCdmIndex.openMutableGCFromIndex failed on " + indexFilenameInCache, t);
    }

    if (result == null) {
      RandomAccessFile.eject(indexFilenameInCache);
      if (!indexFileInCache.delete())
        logger.warn("failed to delete {}", indexFileInCache.getPath());
    }

    return result;
  }
open GribCollectionImmutable from an existing index file. return null on failure