# mglib

## Personal IDL library for M. Galloy

single page | use frames     summary     class     fields     routine details     file attributes

## fileio/

includes main-level program

## Routines

result = mg_read_config(filename [, defaults=hash] [, error=long] [, /fold_case])

Reads a configuration file and returns an MGffOptions object with the results.

Options and their values are listed one option per line, though the value can extend over multiple lines by indenting at least one space on the continued lined. There must be either a ":" or an "=" after the option name. Leading space before the first character in the value is ignored. For example:

 option1: value1 option2 = value2 option3 : a very long value3 
The values of options 1, 2, and 3 are "value1", "value2", and "a very long value3", respectively.

Comments have "#" or ";" as the first character on a line and are ignored.

Sections break a configuration file into namespaces. They are specified by placing a name in square brackets, such as:

 [ section_name ] 
Options after this declaration and before the next such section declaration are in the "section_name" section. Options before the first section declaration are in the default section (the entire configuration file can be in the default section).

Interpolation can be used to substitute values from one option into another. Only options from the default section or the current section can be used. Interpolation uses MG_SUBS and hence its syntax, in this case:

 %(option_name)s 
where the "s" stands for string (MG_SUBS can substitute numeric quantities and uses the C format codes, but options are always strings so "s" is always used in this case).

### Parameters

filename in required type=string

filename of configuration file to read

### Keywords

defaults in optional type=hash

hash containing default values for items to be specified in configuration file

error out optional type=long

set to a named variable to retrieve any error code from attempting to read the configuration file; 0 for OK, -1 for file not found, -2 for invalid syntax in configuration file

fold_case in optional type=boolean

set for case-insensitive results (for section and option names, but not for values)

### Examples

For example, suppose the following configuration file is in config.ini:

 [My Section] foodir: %(dir)s/whatever dir=frob long: this value continues in the next line 
It can be read into an MGffOptions object with:
 IDL> config = mg_read_config('config.ini') 
The result can be queried for values:
 IDL> print, config->has_option('foodir', section='My Section') 1 IDL> print, config->get('foodir', section='My Section') frob/whatever 
This example is found as a main-level program at the end of this file. Run it with:
 IDL> .run mg_read_config 

## File attributes

 Modification date: Mon Jun 16 12:49:40 2014 Lines: 92 Docformat: rst rst
Personal library of Michael Galloy
Contact me if you have enhancement requests or bug fixes.