tdm/src/main/java/thredds/tdm/GCpass1.java
private Accum scanLeafDirectoryCollection(boolean isGrib1, FeatureCollectionConfig config,
                                            Counters parentCounters,
                                            Logger logger, Path dirPath, boolean isTop,
                                            Indent indent, Formatter fm) throws IOException {

    if (config.ptype == FeatureCollectionConfig.PartitionType.file) {
      reportOneFileHeader(indent, fm);
      fm.format("%sDirectory %s%n", indent, dirPath);
    }
    Accum accum = new Accum();
    int nfiles = 0;

    Counters countersThisDir = parentCounters.makeSubCounters();

    Formatter errlog = new Formatter();
    CollectionSpecParser specp = config.getCollectionSpecParser(errlog);

    DirectoryCollection dcm = new DirectoryCollection(config.collectionName, dirPath, isTop, config.olderThan, logger);
    // dcm.setUseGribFilter(false);
    dcm.putAuxInfo(FeatureCollectionConfig.AUX_CONFIG, config);
    if (specp.getFilter() != null)
      dcm.setStreamFilter(new StreamFilter(specp.getFilter(), specp.getFilterOnName()));

    try (CloseableIterator<MFile> iter = dcm.getFileIterator()) {
      while (iter.hasNext()) {
        MFile mfile = iter.next();
        Counters countersOneFile = countersThisDir.makeSubCounters();
        int nrecords = 0;

        if (isGrib1) {
          Grib1Index grib1Index = readGrib1Index(mfile, false);
          if (grib1Index == null) {
            System.out.printf("%s%s: read or create failed%n", indent, mfile.getPath());
            continue;
          }
          for (ucar.nc2.grib.grib1.Grib1Record gr : grib1Index.getRecords()) {
            accumGrib1Record(gr, countersOneFile);
            nrecords++;
          }
        } else {
          Grib2Index grib2Index = readGrib2Index(mfile, false);
          if (grib2Index == null) {
            System.out.printf("%s%s: read or create failed%n", indent, mfile.getPath());
            continue;
          }
          for (ucar.nc2.grib.grib2.Grib2Record gr : grib2Index.getRecords()) {
            accumGrib2Record(gr, countersOneFile);
            nrecords++;
          }
        }

        accum.nrecords += nrecords;
        countersThisDir.addTo(countersOneFile);
        if (config.ptype == FeatureCollectionConfig.PartitionType.file)
          reportOneFile(mfile, nrecords, countersOneFile, indent, fm);
        nfiles++;

        // get file sizes
        String path = mfile.getPath();
        if (path.endsWith(GribIndex.GBX9_IDX)) {
          accum.indexSize += ((float) mfile.getLength() / (1000 * 1000)); // mb
        } else {
          accum.fileSize += ((float) mfile.getLength() / (1000 * 1000)); // mb
          File idxFile = GribIndexCache.getExistingFileOrCache(path + GribIndex.GBX9_IDX);
          if (idxFile.exists())
            accum.indexSize += ((float) idxFile.length() / (1000 * 1000)); // mb
        }
      }
    }

    parentCounters.addTo(countersThisDir);
    accum.nfiles += nfiles;
    accum.last = reportOneDir(dirPath.toString(), accum, countersThisDir, indent, accum.last);
    return accum;
  }
private Accum scanLeafDirectoryCollection(boolean isGrib1, FeatureCollectionConfig config,
                                            Counters parentCounters,
                                            Logger logger, Path dirPath, boolean isTop,
                                            Indent indent, Formatter fm) throws IOException {

    if (config.ptype == FeatureCollectionConfig.PartitionType.file) {
      reportOneFileHeader(indent, fm);
      fm.format("%sDirectory %s%n", indent, dirPath);
    }
    Accum accum = new Accum();
    int nfiles = 0;

    Counters countersThisDir = parentCounters.makeSubCounters();

    Formatter errlog = new Formatter();
    CollectionSpecParser specp = config.getCollectionSpecParser(errlog);

    DirectoryCollection dcm = new DirectoryCollection(config.collectionName, dirPath, isTop, config.olderThan, logger);
    // dcm.setUseGribFilter(false);
    dcm.putAuxInfo(FeatureCollectionConfig.AUX_CONFIG, config);
    if (specp.getFilter() != null)
      dcm.setStreamFilter(new StreamFilter(specp.getFilter(), specp.getFilterOnName()));

    try (CloseableIterator<MFile> iter = dcm.getFileIterator()) {
      while (iter.hasNext()) {
        MFile mfile = iter.next();
        Counters countersOneFile = countersThisDir.makeSubCounters();
        int nrecords = 0;

        if (isGrib1) {
          Grib1Index grib1Index = readGrib1Index(mfile, false);
          if (grib1Index == null) {
            System.out.printf("%s%s: read or create failed%n", indent, mfile.getPath());
            continue;
          }
          for (ucar.nc2.grib.grib1.Grib1Record gr : grib1Index.getRecords()) {
            accumGrib1Record(gr, countersOneFile);
            nrecords++;
          }
        } else {
          Grib2Index grib2Index = readGrib2Index(mfile, false);
          if (grib2Index == null) {
            System.out.printf("%s%s: read or create failed%n", indent, mfile.getPath());
            continue;
          }
          for (ucar.nc2.grib.grib2.Grib2Record gr : grib2Index.getRecords()) {
            accumGrib2Record(gr, countersOneFile);
            nrecords++;
          }
        }

        accum.nrecords += nrecords;
        countersThisDir.addTo(countersOneFile);
        if (config.ptype == FeatureCollectionConfig.PartitionType.file)
          reportOneFile(mfile, nrecords, countersOneFile, indent, fm);
        nfiles++;

        // get file sizes
        String path = mfile.getPath();
        if (path.endsWith(GribIndex.GBX9_IDX)) {
          accum.indexSize += ((float) mfile.getLength() / (1000 * 1000)); // mb
        } else {
          accum.fileSize += ((float) mfile.getLength() / (1000 * 1000)); // mb
          File idxFile = GribIndexCache.getExistingFileOrCache(path + GribIndex.GBX9_IDX);
          if (idxFile.exists())
            accum.indexSize += ((float) idxFile.length() / (1000 * 1000)); // mb
        }
      }
    }

    parentCounters.addTo(countersThisDir);
    accum.nfiles += nfiles;
    accum.last = reportOneDir(dirPath.toString(), accum, countersThisDir, indent, accum.last);
    return accum;
  }
private Accum scanLeafDirectoryCollection ( boolean isGrib1 , FeatureCollectionConfig config , Counters parentCounters , Logger logger , Path dirPath , boolean isTop , Indent indent , Formatter fm ) throws IOException { if ( config . ptype == FeatureCollectionConfig . PartitionType . file ) { reportOneFileHeader ( indent , fm ) ; fm . format ( "%sDirectory %s%n" , indent , dirPath ) ; } Accum accum = new Accum ( ) ; int nfiles = 0 ; Counters countersThisDir = parentCounters . makeSubCounters ( ) ; Formatter errlog = new Formatter ( ) ; CollectionSpecParser specp = config . getCollectionSpecParser ( errlog ) ; DirectoryCollection dcm = new DirectoryCollection ( config . collectionName , dirPath , isTop , config . olderThan , logger ) ; // dcm.setUseGribFilter(false); dcm . putAuxInfo ( FeatureCollectionConfig . AUX_CONFIG , config ) ; if ( specp . getFilter ( ) != null ) dcm . setStreamFilter ( new StreamFilter ( specp . getFilter ( ) , specp . getFilterOnName ( ) ) ) ; try ( CloseableIterator < MFile > iter = dcm . getFileIterator ( ) ) { while ( iter . hasNext ( ) ) { MFile mfile = iter . next ( ) ; Counters countersOneFile = countersThisDir . makeSubCounters ( ) ; int nrecords = 0 ; if ( isGrib1 ) { Grib1Index grib1Index = readGrib1Index ( mfile , false ) ; if ( grib1Index == null ) { System . out . printf ( "%s%s: read or create failed%n" , indent , mfile . getPath ( ) ) ; continue ; } for ( ucar . nc2 . grib . grib1 . Grib1Record gr : grib1Index . getRecords ( ) ) { accumGrib1Record ( gr , countersOneFile ) ; nrecords ++ ; } } else { Grib2Index grib2Index = readGrib2Index ( mfile , false ) ; if ( grib2Index == null ) { System . out . printf ( "%s%s: read or create failed%n" , indent , mfile . getPath ( ) ) ; continue ; } for ( ucar . nc2 . grib . grib2 . Grib2Record gr : grib2Index . getRecords ( ) ) { accumGrib2Record ( gr , countersOneFile ) ; nrecords ++ ; } } accum . nrecords += nrecords ; countersThisDir . addTo ( countersOneFile ) ; if ( config . ptype == FeatureCollectionConfig . PartitionType . file ) reportOneFile ( mfile , nrecords , countersOneFile , indent , fm ) ; nfiles ++ ; // get file sizes String path = mfile . getPath ( ) ; if ( path . endsWith ( GribIndex . GBX9_IDX ) ) { accum . indexSize += ( ( float ) mfile . getLength ( ) / ( 1000 * 1000 ) ) ; // mb } else { accum . fileSize += ( ( float ) mfile . getLength ( ) / ( 1000 * 1000 ) ) ; // mb File idxFile = GribIndexCache . getExistingFileOrCache ( path + GribIndex . GBX9_IDX ) ; if ( idxFile . exists ( ) ) accum . indexSize += ( ( float ) idxFile . length ( ) / ( 1000 * 1000 ) ) ; // mb } } } parentCounters . addTo ( countersThisDir ) ; accum . nfiles += nfiles ; accum . last = reportOneDir ( dirPath . toString ( ) , accum , countersThisDir , indent , accum . last ) ; return accum ; }
Update all the grib indices in one directory, and the collection index for that directory

@param config  FeatureCollectionConfig
@param dirPath directory path
@throws IOException
Update all the grib indices in one directory and the collection index for that directory