aodn / imos-toolbox

Graphical tool for QC'ing and NetCDF'ing oceanographic datasets
GNU General Public License v3.0
46 stars 31 forks source link

Incorrect regex in read_header_key() for Signature parser #758

Open sspagnol opened 3 years ago

sspagnol commented 3 years ago

In signatureParse.m, the function read_header_key() does not correctly extract key if it's the last in the list. For example this would fail

hstr = 'GETAVG1,ABC="CBA",MIAVG=600,ERR=0.00e-10';
[value] = read_header_key(hstr,'GETAVG1','ERR','float');

Pretty sure the regex should change from

re_match = ['(?<mode>(' mode  '))' '(.*?)' key '={1}' '(?<value>(' mtype ')),']; 

To

re_match = ['(?<mode>(' mode  '))' '(.*?)' key '={1}' '(?<value>(' mtype '))']; 

i.e remove last comma.

Also are the tests actually run? Ask as they refer to a function read_nortek_key()

hugo-sardi commented 3 years ago

Good catch!

Also are the tests actually run? Ask as they refer to a function read_nortek_key()

Not for this one! The problem here is that the docstring test of read_header_key cannot be reached because test_docstring can only inspect the top function docstring, which is signatureParse. Hence, the docstring is never evaluated and became outdated/wrong. This is the reason why this function docstring is currently outdated/wrong.

To solve this, one needs to factor the function out into another file, but this involves renaming it to a meaningful name, since it is only for Norteks.

Tasks involved: