|
|
**Table of Contents**
|
|
|
|
|
|
[[_TOC_]]
|
|
|
|
|
|
# Source Code Formatting
|
|
|
The source code of Matlab & Octave is very permissive, in order to make it more unified code base and potentially easier to navigate we have chosen a style that matches EEGLABS own style.
|
|
|
|
|
|
# Compatibility
|
|
|
Any code provided to this project should be compatible with both GNU Octave and MATLAB. This can usually be facilitated by clever thinking or using runtime switches based on the execution environment.
|
|
|
```
|
|
|
if exist('OCTAVE_VERSION')
|
|
|
% Do this if Octave
|
|
|
else
|
|
|
% Do this if Matlab
|
|
|
end;
|
|
|
```
|
|
|
|
|
|
# Help Text
|
|
|
The first contiguous block of comments (% symbol) is the help text, the help text should give the following information: A description of the function, a "usage" text, a Inputs section, a Outputs section, and potentially a See also: section. The help text should provide enough documentation in order to understand fully how the function operates.
|
|
|
Consider using this example as a guide:
|
|
|
```
|
|
|
% pop_sample() - description of the function. If less than
|
|
|
% three arguments are given, a window pops up
|
|
|
% to ask for the value of the additional
|
|
|
% parameters.
|
|
|
%
|
|
|
% Usage:
|
|
|
% >> OUTEEG = pop_sample( INEEG, type, param3 );
|
|
|
%
|
|
|
% Inputs:
|
|
|
% INEEG - input EEG dataset
|
|
|
% type - type of processing. 1 process the raw
|
|
|
% data and 0 the ICA components.
|
|
|
% param3 - additional parameter.
|
|
|
%
|
|
|
% Outputs:
|
|
|
% OUTEEG - output dataset
|
|
|
%
|
|
|
% See also:
|
|
|
% SAMPLE, EEGLAB
|
|
|
```
|
|
|
|
|
|
# License Preamble
|
|
|
The beginning of each file (after the help text, but not contiguous) should contain the license preamble of the GNU GPL 2 License.
|
|
|
|
|
|
```
|
|
|
% Copyright (C) 2017 Brock University Cognitive and Affective Neuroscience Lab
|
|
|
%
|
|
|
% Code written by <List authors with `,' between>
|
|
|
%
|
|
|
% This program is free software; you can redistribute it and/or modify
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
% the Free Software Foundation; either version 2 of the License, or
|
|
|
% (at your option) any later version.
|
|
|
%
|
|
|
% This program is distributed in the hope that it will be useful,
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
% GNU General Public License for more details.
|
|
|
%
|
|
|
% You should have received a copy of the GNU General Public License
|
|
|
% along with this program (LICENSE.txt file in the root directory); if not,
|
|
|
% write to the Free Software Foundation, Inc., 59 Temple Place,
|
|
|
% Suite 330, Boston, MA 02111-1307 USA
|
|
|
```
|
|
|
# Changelog
|
|
|
Change logs for the project exist in CHANGELOG and should be formatted as below.
|
|
|
Please note double spaces and ensure you leave a space between change entries. See
|
|
|
[GNU Style](https://www.gnu.org/prep/standards/html_node/Change-Logs.html#Change-Logs) for more details.
|
|
|
```
|
|
|
YYYY-MM-DD John Doe <johndoe@example.com>
|
|
|
|
|
|
* myfile.ext (myfunction): my changes made
|
|
|
additional changes
|
|
|
|
|
|
* myfile.ext (unrelated_change): my changes made
|
|
|
to myfile.ext but completely unrelated to the above
|
|
|
|
|
|
* anotherfile.ext (somefunction): more changes
|
|
|
```
|
|
|
|
|
|
# Logging
|
|
|
Instead of using `disp()` or `printf()` use [matlog](https://github.com/co60ca/matlog) instead. This will allow us to pick what level of logging we want in each script and wont pollute the standard output. Additionally, logging_log includes much more useful information such as the time since last log message, time since program start, clock time and call site (file and line number). It may also print call stacks in the case of 'ERROR' and 'WARN'
|
|
|
|
|
|
The function is called as such:
|
|
|
```
|
|
|
logging_log(log_level, message, current_level)
|
|
|
```
|
|
|
Where log_level and current_level is one of 'ERROR', 'WARN', 'NOTICE', 'INFO', 'DEBUG'
|
|
|
In general you should use it as such:
|
|
|
```
|
|
|
logging_log('INFO', 'Subtracted average from data');
|
|
|
logging_log('ERROR', 'Fatal error occured, print stack trace and exit');
|
|
|
```
|
|
|
|
|
|
If the global `'LOGGING_LEVEL'` is set we will use that instead `current_level`. If `current_level` is unset we use the package default ('INFO').
|
|
|
|
|
|
`log_level` determines per logging level setting if a logging message should be displayed. The message will be displayed if the `log_level` > `current_level`or default level if `current_level` is not set.
|
|
|
|
|
|
# Syntax
|
|
|
1. Use 4 spaces instead of tabs to indent a block
|
|
|
2. Limit lines to 79 columns, break using `...`on the subsequent line indent two blocks
|
|
|
```
|
|
|
com = sprintf('pop_sample( %s, %d, [%s] );', inputname(1), typeproc, ...
|
|
|
int2str(param3));
|
|
|
```
|
|
|
3. Avoid inline if statements and other such structures
|
|
|
4. Leave spaces between the assignment operator left hand side and right hand side
|
|
|
```
|
|
|
a = [3, 5, 7];
|
|
|
```
|
|
|
5. Leave a space after a comma in a list of items, such as in parameter lists and literal matrices or cell arrays
|
|
|
```
|
|
|
rval = addme(a, b);
|
|
|
```
|
|
|
6. Function names should be lowercase and with_underscores_to_separate_words
|
|
|
7. Code section titles use double percent sign (%%) and should be use to delimit large sections of code
|
|
|
8. Avoid use of multi line comments `%{ %}` instead favouring multiple single line quotes, such as in the preamble
|
|
|
9. Leave a space between the comment and the `%` in comments
|
|
|
10. Leave TODO messages for future work by using the format: `% TODO(<your login)` this will make it easy to see who owns which TODO and makes searching for you own actionables easier
|
|
|
11. Never use single `&` or `|` unless absolutely need to
|
|
|
|
|
|
***
|
|
|
|
|
|
[ :house: **Return to Main Page**](https://git.sharcnet.ca/bucanl_pipelines/eeg_pipe_asr_amica/wikis/home) |
|
|
\ No newline at end of file |