0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 function [c] = ens_initConfig( fname )
0013
0014
0015
0016 config = parseConfig( fname );
0017
0018 DEFAULT_WIDTH = 750;
0019 DEFAULT_HEIGHT = 500;
0020 DEFAULT_BOTTOM_HEIGHT = 48;
0021 DEFAULT_TOP_HEIGHT = 24;
0022 DEFAULT_CENTER_BOTTOM_HEIGHT = 26;
0023
0024 DEFAULT_DB_NAME = 'ensemble_main';
0025 DEFAULT_DB_SERVER = 'atonal';
0026 DEFAULT_CONN_ID = 9;
0027
0028 MIN_HEIGHT = 100;
0029
0030
0031
0032 c.db_name = getValue( config, 'db_name' );
0033 if( ~length( c.db_name ) )
0034 c.db_name = DEFAULT_DB_NAME;
0035 end
0036 c.db_server = getValue( config, 'db_server' );
0037 if( ~length( c.db_server ) )
0038 c.db_server = DEFAULT_DB_SERVER;
0039 end
0040 c.conn_id = str2double( getValue( config, 'conn_id' ) );
0041 if( isnan( c.conn_id ) | c.conn_id < 0 )
0042 c.conn_id = DEFAULT_CONN_ID;
0043 end
0044
0045
0046
0047 c.dim.h = str2double( getValue( config, 'height' ) );
0048 if( isnan(c.dim.h) | c.dim.h <= 0 )
0049 c.dim.h = DEFAULT_HEIGHT;
0050 end
0051 if( c.dim.h < MIN_HEIGHT )
0052 c.dim.h = MIN_HEIGHT;
0053 end
0054
0055 c.dim.w = str2double( getValue( config, 'width' ) );
0056 if( isnan(c.dim.w) | c.dim.w <= 0 )
0057 c.dim.w = DEFAULT_WIDTH;
0058 end
0059
0060 c.dim.bh = str2double( getValue( config, 'bottom_height' ) );
0061 if( isnan(c.dim.bh) | c.dim.bh <= 0 )
0062 c.dim.bh = DEFAULT_BOTTOM_HEIGHT;
0063 end
0064
0065 c.dim.cbh = str2double( getValue( config, 'center_bottom_height' ) );
0066 if( isnan(c.dim.cbh) | c.dim.cbh <= 0 )
0067 c.dim.cbh = DEFAULT_CENTER_BOTTOM_HEIGHT;
0068 end
0069
0070 c.dim.th = str2double( getValue( config, 'top_height' ) );
0071 if( isnan(c.dim.th) | c.dim.th <= 0 )
0072 c.dim.th = DEFAULT_TOP_HEIGHT;
0073 end
0074
0075
0076
0077 c.dim.b1h = 20;
0078 c.dim.b1w = 20;
0079
0080
0081 screenSize = get(0,'ScreenSize');
0082 c.dim.sh = screenSize(4);
0083 c.dim.sw = screenSize(3);
0084 c.dim.minAnTreeHeight = 80;
0085
0086
0087 checkNum = 1;
0088 slotNum = 1;
0089 while(1)
0090 checkName = sprintf( 'analysisFunction%d', checkNum );
0091 if( length( getValue( config, checkName ) ) > 0 )
0092 if( exist( getValue( config, checkName ) ) ~= 2 )
0093 fprintf( 'Error: analysis function ''%s'' not found in path. Skipping.\n', getValue( config, checkName ) );
0094 checkNum = checkNum + 1;
0095 continue;
0096 end
0097 c.analysisFunction{slotNum} = getValue( config, checkName );
0098 checkName = sprintf( 'analysisComment%d', checkNum );
0099 if( length( getValue( config, checkName ) ) > 0 )
0100 c.analysisComment{slotNum} = [getValue( config, checkName ) sprintf('\n\nHelp:\n') help( c.analysisFunction{slotNum} )];
0101 else
0102 c.analysisComment{slotNum} = [sprintf( 'Help:\n' ) help( c.analysisFunction{slotNum} )];
0103 end
0104 else
0105 break;
0106 end
0107
0108 slotNum = slotNum + 1;
0109 checkNum = checkNum + 1;
0110
0111 end
0112
0113
0114
0115 function [res] = getValue( config, name )
0116 res = [];
0117
0118 if( ~length( config ) )
0119 return;
0120 end
0121
0122 for x = 1 : length( config.name )
0123
0124 if( strcmp( name, config.name{x} ) )
0125 res = config.value{x};
0126 return;
0127 end
0128
0129 end
0130
0131
0132 function [res] = parseConfig( fname )
0133
0134 res = [];
0135
0136 f = fopen( fname, 'r' );
0137
0138 if( f == -1 )
0139 return;
0140 end
0141
0142 x = 1;
0143
0144 while 1
0145
0146 l = fgetl(f);
0147
0148 if( ~ischar(l) )
0149 break;
0150 end
0151
0152
0153 if( length(l) < 3 | l(1) == '#' )
0154 continue;
0155 end
0156
0157
0158
0159 p = strfind(l,'|');
0160
0161
0162
0163
0164 if( length(p) ~= 1 | p < 2 )
0165 continue;
0166 end
0167
0168 name = l(1:p-1);
0169 value = l(p+1:end);
0170
0171 res.name{x} = name;
0172 res.value{x} = value;
0173
0174 x = x + 1;
0175
0176 end
0177
0178 fclose(f);
0179
0180