class NumRu::GDir

A class to represent diretories and data files for GPhys.

Overview

A GDir object represents a directory, or a file (such as a NetCDF file or GrADS control file), for which GPhys objects can be defined for the variables in it. This means that a NetCDF file, for example, is treated a directory, rather than a plain file.

GDir serves a directory tree under a root (top) directory, which can be set as a class variable with GDir.top=. All the absolute path of GDir is actually relative to the root directory, and to access outside the root directory is prohibited. Furthermore, it has a working directory as a class variable, whose initial value is the top directory and can be changed by GDir.cd.

NEW(2005/06): Now GDir can accept DODS URL as a path. Also, the top directory can be set to a DODS URL.

Class Methods

GDir.top=(top)

Sets the root directory. This should be done before making any GDir objects by GDir.new. The default root directory is the root directory of the local file system ('/').

ARGUMENTS

RETURN VALUE

GDir.top

RETURN VALUE

GDir.new(path)

Constructor.

ARGUMENTS

RETURN VALUE

ERRORS

EXAMPLES

GDir.set_text_pattern(*regexps)

Sets regular expressions to match the file name of text files. The default is /\.txt$/ and /^\w*$/.

ARGUMENTS

RETURN VALUE

ERRORS

GDir.add_text_pattern(regexp [, regexp [, ...]])

Similar to GDir.set_text_pattern, but adds regular expressions instead of replacing existing ones.

RETURN VALUE

ERRORS

GDir.cd(path)

Changes the working directory of the class.

RETURN VALUE

GDir.cwd=(path)

Aliased to GDir.cd.

GDir.cwd

Returns the current working directory as a GDir. The initial value of the working directory is the top directory.

RETURN VALUE

GDir.cd(path)

Changes the working directory to path

RETURN VALUE

GDir[]

GDir.data

GDir.text

GDir.list_dirs

GDir.list_dirs_v

GDir.list_data

GDir.list_data_v

GDir.list_texts

GDir.list_texts_v

GDir.ls

GDir.ls_v

All of these are dispatched to the current working directory. Thus, GDir.show is equivalent to GDir.cwd.show, for example.

Instance Methods

close

Closes the file/directory objects in the GDir.

path

Returns the path (relative to the top directory)

RETURN VALUE

name

Name of the GDir

RETURN VALUE

inspect

Returns the path

RETURN VALUE

[path]

Returns a GDir, GPhys, or File (text), by calling dir, data, or text depending on path.

ARGUMENTS

RETURN VALUE

ERROR

dir(path)

Returns a GDir specified the path.

ARGUMENTS

RETURN VALUE

ERROR

data(path)

Returns a GPhys specified the path.

ARGUMENTS

RETURN VALUE

ERROR

text(path)

Returns a text file object specified the path.

ARGUMENTS

RETURN VALUE

ERROR

find_dir( filt )

Recursively search a GDir whose name match filt..

ARGUMENTS

RETURN VALUE

find_data( name=nil,long_name=nil,units=nil )

Recursively search data variables under the directory. Mathces are by taking "AND" for non-nil arguments. (At least one of the three arguments must be non-nil.)

ARGUMENTS

RETURN VALUE

list_dirs(path=nil)

Returns the names of the directories.

See also ls.

ARGUMENTS

RETURN VALUE

list_dirs_v(path=nil)

Verbose version of list_dirs, showing size and mtime like 'ls -l'.

See also ls_l.

ARGUMENTS

RETURN VALUE

list_data(path=nil)

Returns the names of the data (variables on which GPhys objects can be defined.) Returns a non-empty array if the GDir (current or at the path) is actually a file recognized by GPhys (i.e., NetCDF or GrADS control file).

ARGUMENTS

RETURN VALUE

list_data_v(path=nil)

Verbose version of list_data, showing shape, long_name, and units.

See also ls_l.

ARGUMENTS

RETURN VALUE

list_texts(path=nil)

Returns the names of the text files. Whether a file is a text file or not is judged based on the name of the file: That matched the predefined patters is judged as a text file regardless whether it is really so. The default pattern is /\.txt$/ and /^\w*$/. The patterns can be customized by set_text_patterns or add_text_patterns.

ARGUMENTS

RETURN VALUE

list_texts_v(path=nil)

Verbose version of list_texts, showing size and mtime like 'ls -l'.

See also ls_l.

ARGUMENTS

RETURN VALUE

ls(path=nil)

Prints the results of list_dirs, list_data, and list_texts on the standard output.

RETURN VALUE

each_dir

Iterator for each directory (GDir) under self.

each_data

Iterator for each GPhys under self.

ls_l(path=nil)

Verbose version of ls. Prints the results of list_dirs_v, list_data_v, and list_texts_v on the standard output.

RETURN VALUE

mtime

Returns the last modified time.

RETURN VALUE

atime

Returns the last accessed time.

RETURN VALUE

ctime

Returns ctime.

RETURN VALUE

mtime_like_ls_l

Returns the last modified time formated as in ls -l. That is, if the time of last modification is greater than six months ago, it is shown in the format 'month date year'; otherwise, 'month date time'.

RETURN VALUE