Home > ensemble_gui > ens_initConfig.m

ens_initConfig

PURPOSE ^

Reads the contents of the specified GUI config file

SYNOPSIS ^

function [c] = ens_initConfig( fname )

DESCRIPTION ^

 Reads the contents of the specified GUI config file
 and puts the results into the return stuct "c" which will become 
 the "config" field of the main GUI data struct. 
 Checks for data validation and setting default values for missing
 variables are all done here.
 
 To add a new variable, you only need to add it to the config file,
 check for its value here, and assign it to a position within the
 return struct "c". Then the main GUI can do whatever it wants with it.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 %
0002 % Reads the contents of the specified GUI config file
0003 % and puts the results into the return stuct "c" which will become
0004 % the "config" field of the main GUI data struct.
0005 % Checks for data validation and setting default values for missing
0006 % variables are all done here.
0007 %
0008 % To add a new variable, you only need to add it to the config file,
0009 % check for its value here, and assign it to a position within the
0010 % return struct "c". Then the main GUI can do whatever it wants with it.
0011 %
0012 function [c] = ens_initConfig( fname )
0013 
0014     % if file name doesn't exist then config will come back from parseConfig
0015     % as an empty list, and all the config values below will be filled with defaults
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; % height of edit field area under center uitree
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     % mysql database settings with default values
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     % GUI positions and dimensions
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     % these may change during development but after that
0076     % these should stay constant
0077     c.dim.b1h = 20;        % button style 1 height
0078     c.dim.b1w = 20;        % button style 1 width
0079     
0080     % size of monitor/resolution
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         % lines that begin with # are comments
0153         if( length(l) < 3 | l(1) == '#' )
0154             continue;
0155         end
0156 
0157         % locate the | pipe character that separates the
0158         % config variable name and its value
0159         p = strfind(l,'|');
0160 
0161         % if there's no |, or if it's the first
0162         % char (which wouldn't allow a valid name),
0163         % skip this line.
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

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003