[.cfg] file format

[.cfg] files are human-readable text files containing fieldname/fieldvalue pairs using the syntax:

#fieldname

fieldvalue1

fieldvalue2

etc....


Field names are entered following the character #

They can only include letters/numbers and cannot start with a number (e.g. #variable01)

Field names can also contain multiple levels separated by the dot character (e.g. #denoising.filter). Multiple levels will be interpreted as structure fields/subfields


Field values can be numeric (entered as arrays or two-dimensional matrices) or alphanumeric (interpreted as lists / cell-arrays separated by newline characters)


Comments can be included following the character %

Example .cfg file contents:


% a single value

#pi 3.14159265


% a 2D matrix

#hadamard

1 1 1 1

1 -1 1 -1

1 1 -1 -1

1 -1 -1 1


% a single string

#phrase

hello world


% two strings

#files

/disk/file1

/disk/file2


% a structure

#disk.name large

#disk.number 3

#disk.avail 1/2


[.cfg] files can be read in Matlab using the function conn_loadcfgfile. For example:

>> data = conn_loadcfgfile('example.cfg')

data =

struct with fields:

pi: 3.1416

hadamard: [4×4 double]

phrase: {'hello world'}

files: {2×1 cell}

disk: [1×1 struct]


They can also be created from a Matlab structure using the function conn_savecfgfile. For example:

>> conn_savecfgfile('example2.cfg', data);

#pi

3.1416

#hadamard

1 1 1 1

1 -1 1 -1

1 1 -1 -1

1 -1 -1 1

#phrase

hello world

#files

/disk/file1

/disk/file2

#disk.name

large

#disk.number

3

#disk.avail

0.5


Last, they can also be exported to [.json] file format using the syntax:

>> spm_jsonwrite('example2.json', data);

{

"pi": 3.14159265,

"hadamard": [[1,1,1,1],[1,-1,1,-1],[1,1,-1,-1],[1,-1,-1,1]],

"phrase": ["hello world"],

"files": [

"/disk/file1",

"/disk/file2"

],

"disk": {

"name": ["large"],

"number": 3,

"avail": 0.5

}

}