The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Weather::GHCN::App::CacheUtil - Show or clean up cache content

VERSION

version v0.0.011

SYNOPSIS

    use Weather::GHCN::App::CacheUtil;

    Weather::GHCN::App::CacheUtil->run( \@ARGV );

See ghcn_cacheutil -help for details.

SUBROUTINES

run ( \@ARGV )

Invoke this subroutine, passing in a reference to @ARGV, in order to get list of cache contents or remove cache content.

See ghnc_cache.pl -help for details.

filter_files ( \%files )

Given a hash containing Path::Tiny objects representing the files in the designed ghcn cache folder, apply the various filtering criteria options and mark those objects which match the criteria by inserting the key INCLUDE with value 1 in the %files entry for that object.

Modifies the content of %files. Void return.

get_ghcn ($profile, $cachedir)

Returns a Weather::GHCN::StationTable object initialized with a cache location obtained from $cachedir or, if $cachdir is undefined, from the cachedir option defined in the user profile specified by $profile. If errors are encounterd, it dies and produces a list.

get_options ( \@ARGV )

get_options encapsulates everything we need to process command line options, or to set options when invoking this script from a test script.

Normally it's called by passing a reference to @ARGV; from a test script you'd set up a local array variable to specify the options.

By convention, you should set up a file-scoped lexical variable named $Opt and set it in the mainline using the return value from this function. Then all options can be accessed used $Opt->option notation.

get_alias_stnids ( \%profile )

Read the hash obtained from the user profile file and find the alias definitions. Return a hash of station id's that have been aliased.

load_cached_files ($ghcn, $cache_pto, \%alias )

Given a Weather::GHCN::StationTable object and a cache Path::Tiny object, and a hash of which files correspond to aliased stations, return a hash which combines the file information and the station information (where applicable) and categorizes each entry by type: D for daily data file, A for aliases station, and C for catalog files.

match_type ($file_type, $match_types)

Cache files are categorized by type: D for .dly files, A for .dly files that correspond to user aliases, and C for .txt files. The user can provide a -type option with a string to select based on type. The string can contain any or all of the three letters. This function is used to match the file type with the -type option. Returns true if the $file_type letter (D, A or C) is found in the $match_types string.

outclip ()

When called initially, it redirects STDOUT to local variable so that printing is saved in memory. On the subsequent call, it writes the content of the variable to the Windows Clipboard and resets STDOUT to its original state (usually the terminal).

Since Windows::Clipboard is platform specific, calls to this subroutine should conditional. The following pattern is recommended:

    # modules for Windows only
    use if $OSNAME eq 'MSWin32', 'Win32::Clipboard';

    # is it ok to use Win32::Clipboard?
    our $USE_WINCLIP = $OSNAME eq 'MSWin32';

    # send print output to the Windows clipboard if requested and doable
    outclip() if $Opt->outclip and $USE_WINCLIP;

    ... print stuff
    
    # restore print output to stdout
    outclip() if $Opt->outclip and $USE_WINCLIP;

This subroutine relies on state variables. It cannot be used in a nested fashion. It is best confined to main:: (or the top-level subroutine).

report_daily_files ($files_href)

Given a hash of the cache file hash objects, each consisting of a merger of file properties and station properties, this subroutine will print a report listing those that were flagged for inclusion by filter_files().

Output is ordered by StationId. Catalog (.txt) files don't have a station id, so short version of the filename is used. Since those names are lowercase, they sort last in the the list.

The Type of the file appears in the first column: D for daily weather data files, A for daily weather data files that correspond to aliases defined in the user profile, and C for catalog files.

round ($v)

Round $v using the half-adjust method. Returns an integer.