IRIS Toolbox Reference Manual

## dbsave

Save database as CSV file

#### Syntax

    List = dbsave(D,FName)
    List = dbsave(D,FName,Dates,...)

#### Output arguments

- `List` [ cellstr ] - - List of actually saved database entries.

#### Input arguments

- `D` [ struct ] - Database whose tseries and numeric entries will be saved.

- `FName` [ char ] - Filename under which the CSV will be saved, including its extension.

- `Dates` [ numeric | `Inf` ] Dates or date range on which the tseries objects will be saved.

#### Options

- `'class='` [ `true` | false ] - Include a row with class and size specifications.

- `'comment='` [ `true` | `false` ] - Include a row with comments for tseries objects.

- `'decimal='` [ numeric | empty ] - Number of decimals up to which the data will be saved; if empty the `'format'` option is used.

- `'format='` [ char | `'%.8e'` ] Numeric format that will be used to represent the data, see `sprintf` for details on formatting, The format must start with a `'%'`, and must not include identifiers specifying order of processing, i.e. the `'$'` signs, or left-justify flags, the `'-'` signs.

- `'freqLetters='` [ char | `'YHQBM'` ] - Five letters to represent the five possible date frequencies (annual, semi-annual, quarterly, bimonthly, monthly).

- `'nan='` [ char | `'NaN'` ] - String that will be used to represent NaNs.

- `'saveSubdb='` [ `true` | `false` ] - Save sub-databases (structs found within the struct `D`); the sub-databases will be saved to separate CSF files.

- `'userData='` [ char | 'userdata' ] - Field name from which any kind of userdata will be read and saved in the CSV file.

#### Description

The data saved include also imaginary parts of complex numbers.

##### Saving user data with the database

If your database contains field named `'userdata='`, this will be saved in the CSV file on a separate row. The `'userdata='` field can be any combination of numeric, char, and cell arrays and 1-by-1 structs.

You can use the `'userdata='` field to describe the database or preserve any sort of metadata. To change the name of the field that is treated as user data, use the `'userData='` option.

#### Example

Create a simple database with two time series.

    d = struct();
    d.x = tseries(qq(2010,1):qq(2010,4),@rand);
    d.y = tseries(qq(2010,1):qq(2010,4),@rand);

Add your own description of the database, e.g.

    d.userdata = {'My database',datestr(now())};

Save the database as CSV using `dbsave`,

    dbsave(d,'mydatabase.csv');

When you later load the database,

    d = dbload('mydatabase.csv')

    d =

       userdata: {'My database'  '23-Sep-2011 14:10:17'}
              x: [4x1 tseries]
              y: [4x1 tseries]

the database will preserve the `'userdata='` field.

#### Example

To change the field name under which you store your own user data, use the `'userdata='` option when running `dbsave`,

    d = struct();
    d.x = tseries(qq(2010,1):qq(2010,4),@rand);
    d.y = tseries(qq(2010,1):qq(2010,4),@rand);
    d.MYUSERDATA = {'My database',datestr(now())};
    dbsave(d,'mydatabase.csv',Inf,'userData=','MYUSERDATA');

The name of the user data field is also kept in the CSV file so that `dbload` works fine in this case, too, and returns a database identical to the saved one,

    d = dbload('mydatabase.csv')

    d =

       MYUSERDATA: {'My database'  '23-Sep-2011 14:10:17'}
                x: [4x1 tseries]
                y: [4x1 tseries]

IRIS Toolbox. Copyright © 2007—2013 Jaromir Benes.