waterml/src/main/java/ucar/nc2/ogc/erddap/util/ErddapEDUnits.java
private static String oneUdunitsToUcum(String udunits) {
        //repeatedly pull off start of udunits and build ucum, till done
        String oldUdunits = udunits;
        StringBuilder ucum = new StringBuilder();
        MAIN:
        while (true) {
            //try to find udunits in hashMap
            String tUcum = udHashMap.get(udunits);
            if (tUcum != null) {
                //success! done!
                ucum.append(tUcum);
                return ucum.toString();
            }

            //try to separate out a metricName prefix (e.g., "kilo")
            for (int p = 0; p < nMetric; p++) {
                if (udunits.startsWith(metricName[p])) {
                    udunits = udunits.substring(metricName[p].length());
                    ucum.append(metricAcronym[p]);
                    if (udunits.length() == 0) {
                        ucum.append("{count}");
                        return ucum.toString();
                    }
                    continue MAIN;
                }
            }

            //try to separate out a metricAcronym prefix (e.g., "k")
            for (int p = 0; p < nMetric; p++) {
                if (udunits.startsWith(metricAcronym[p])) {
                    udunits = udunits.substring(metricAcronym[p].length());
                    ucum.append(metricAcronym[p]);
                    if (udunits.length() == 0) {
                        ucum.append("{count}");
                        return ucum.toString();
                    }
                    continue MAIN;
                }
            }

            return oldUdunits;
        }
    }
private static String oneUdunitsToUcum(String udunits) {
        //repeatedly pull off start of udunits and build ucum, till done
        String oldUdunits = udunits;
        StringBuilder ucum = new StringBuilder();
        MAIN:
        while (true) {
            //try to find udunits in hashMap
            String tUcum = udHashMap.get(udunits);
            if (tUcum != null) {
                //success! done!
                ucum.append(tUcum);
                return ucum.toString();
            }

            //try to separate out a metricName prefix (e.g., "kilo")
            for (int p = 0; p < nMetric; p++) {
                if (udunits.startsWith(metricName[p])) {
                    udunits = udunits.substring(metricName[p].length());
                    ucum.append(metricAcronym[p]);
                    if (udunits.length() == 0) {
                        ucum.append("{count}");
                        return ucum.toString();
                    }
                    continue MAIN;
                }
            }

            //try to separate out a metricAcronym prefix (e.g., "k")
            for (int p = 0; p < nMetric; p++) {
                if (udunits.startsWith(metricAcronym[p])) {
                    udunits = udunits.substring(metricAcronym[p].length());
                    ucum.append(metricAcronym[p]);
                    if (udunits.length() == 0) {
                        ucum.append("{count}");
                        return ucum.toString();
                    }
                    continue MAIN;
                }
            }

            return oldUdunits;
        }
    }
private static String oneUdunitsToUcum ( String udunits ) { //repeatedly pull off start of udunits and build ucum, till done String oldUdunits = udunits ; StringBuilder ucum = new StringBuilder ( ) ; MAIN : while ( true ) { //try to find udunits in hashMap String tUcum = udHashMap . get ( udunits ) ; if ( tUcum != null ) { //success! done! ucum . append ( tUcum ) ; return ucum . toString ( ) ; } //try to separate out a metricName prefix (e.g., "kilo") for ( int p = 0 ; p < nMetric ; p ++ ) { if ( udunits . startsWith ( metricName [ p ] ) ) { udunits = udunits . substring ( metricName [ p ] . length ( ) ) ; ucum . append ( metricAcronym [ p ] ) ; if ( udunits . length ( ) == 0 ) { ucum . append ( "{count}" ) ; return ucum . toString ( ) ; } continue MAIN ; } } //try to separate out a metricAcronym prefix (e.g., "k") for ( int p = 0 ; p < nMetric ; p ++ ) { if ( udunits . startsWith ( metricAcronym [ p ] ) ) { udunits = udunits . substring ( metricAcronym [ p ] . length ( ) ) ; ucum . append ( metricAcronym [ p ] ) ; if ( udunits . length ( ) == 0 ) { ucum . append ( "{count}" ) ; return ucum . toString ( ) ; } continue MAIN ; } } return oldUdunits ; } }
This converts one udunits term (perhaps with metric prefix(es)) to the corresponding ucum string.
If udunits is just metric prefix(es), this returns the prefix acronym(s) with "{count}" as suffix
(e.g., dkilo returns dk{count}).
If this can't completely convert udunits, it returns the original udunits
(e.g., kiloBobs remains kiloBobs  (to avoid 'exact' becoming 'ect' ).
This converts one udunits term ( perhaps with metric prefix ( es )) to the corresponding ucum string . If udunits is just metric prefix ( es ) this returns the prefix acronym ( s ) with { count } as suffix ( e . g . dkilo returns dk { count } ) . If this can t completely convert udunits it returns the original udunits ( e . g . kiloBobs remains kiloBobs ( to avoid exact becoming ect ) .