function result = ParseVatManagerDataLog(hFile)

%{
    Using C++ pseudo-code to document complex structure returned by ParseVatManagerDataLog()

    typedef struct
    {
        datenum timestamp;
        float data;
    } DataPoint;

    typedef struct
    {
        string channelName;
        vector<DataPoint> dataPoints;
    } ChannelData;

    vector<ChannelData> result
%}
    result = [];
    
    return
    
    char = fgetl(hFile,1);
    
    # Check for and discard SCP response leading "["
    if (char != '[')
        result = NA;
        return       
    endif
     

    
    currentChannelData.channelName = "";
    currentChannelData.dataPoints = [];
    
    eof = false;
    
    while (!eof)
    
        line = "";
        
        while (true)
        
            char = fgets(hFile,1);
            
            if (feof(hFile))
                eof = true;
                break
            elseif strcmp(char, ";")
                #record terminator
                break       
            else
                # Append <char> to <line>
                line = [line, char];  
            endif
        endwhile
        
        if strcmp(line, "]")
            #SCP response trailing "]"
            continue
        endif
        
        # Discard leading & trailing whitespace
        line = strtrim(line);
        
        %line       
        
        if strcmp(line, "")
          continue 
        elseif strncmp(line, "Channel:", length("Channel:"))
            # Start of new channel section
            
            if !strcmp(currentChannelData.channelName, "")
                # Append <currentChannelData> to <result>
                result = [result, currentChannelData];
            endif
            
            # (Re)initialise <currentChannelData>
            currentChannelData.channelName      = strtok(line([length("Channel:") + 1:end]), ","); 
            currentChannelData.isNumericData    = !strncmp(line, "EVENT", length("EVENT"));
            currentChannelData.datapoints       = [];            
        else
            # Parsing data points from channel indicated by <currentChannelData.channelName>    
            
            tokens = strsplit(line,",");
            datestampStr    = [tokens{1}, tokens{2}];
            dataStr         = tokens{3}; 
       
            datestampStr    =   strtrim(datestampStr);
            dataStr         =   strtrim(dataStr);

            timestamp       =   datenum(datestampStr, "yyyymmddHHMM.SS");
            
            if currentChannelData.isNumericData 
                data            =  str2double(dataStr);
            endevents
            
            datapoint.timestamp = timestamp;
            datapoint.data      = data;
            currentChannelData.datapoints = [currentChannelData.dataPoints, datapoint];
                 
        endif
        
    endwhile
endfunction

