Error in MLife with OUTB files

Dear all,

I think it is better to start a new topic to explain the problem I’m having.
This first post is just a link to another thread where I expose my initial problem.

I will be describing the issues and adding the steps of the debugging process I’m following.

Best regards,

So far, this is what I have done:

The first error was called in the readFASTbinary.m file. As you know, when downloading MLife, it has a “Source” folder with many MATLAB functions. I noticed this function is different from the one that comes in the MATLAB toolbox. I started a comparison between them.

I gathered some binary output files that I had from other simulations and made a simple script to read and graph them. With the readFASTbinary.m from the “Source” folder of MLife I wasn’t able to open a single file, but with the other one, there were no problems. It outputted this error (with LenDesc being a large negative number, if that can help):

Error using fread
Invalid size.

Error in ReadFASTbinary (line 42)
    DescStrASCII = fread( fid, LenDesc,     'uint8' );  % DescStr converted to ASCII
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in load_file_header (line 36)
      [~, cellNames, cellUnits, ~] = ReadFASTbinary(fileName);
                                     ^^^^^^^^^^^^^^^^^^^^^^^^
Error in process_mlife_inputs (line 169)
      [names, units] = load_file_header(FileInfo.FileName{1}, FileInfo.FileFormat, FileInfo.NamesLine, FileInfo.UnitsLine, ...
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in mlife (line 275)
   [FileInfo, Statistics, Fatigue] = process_mlife_inputs(FileInfo, Statistics, Fatigue, dataDirectory);
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in MLife_template (line 9)
[Fatigue, Statistics] = mlife(settingsFile, dataDirectory, outputDirectory);
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

So, with that, I changed the function in the “Source” folder to the MATLAB toolbox one and solved the first problem.

After this change, another error appeared in another function.

Error using process_mlife_inputs (line 190)
For fatigue channel #1, the channel number must be between 1 and 4 (inclusive).

Somehow the code was only reading 4 channels from my output binary file, which previously I had checked and been able to graph many channels successfully. The line of code in the process_mlife_inputs.m that generated the error is:

if ( doFatigue && ( ( Fatigue.ChanInfo(iCh).Chan <= 0 ) || ( Fatigue.ChanInfo(iCh).Chan > FileInfo.nChannels ) ) )
         beep;
         error( '  For fatigue channel #%d, the channel number must be between 1 and %d (inclusive).', iCh, FileInfo.nChannels );
      end % if

I noticed a couple of things about the variable FileInfo:

  • FileInfo.nChannles = 4; this is what is causing the error.

But at the same time it has:

  • FileInfo.Names = 1x141 cell
  • FileInfo.Units = 1x141 cell

being 141 the number of channels that my binary output file has. I checked it, and I think it comes from the function load_file_header.m. This function calls the readFASTbinary.m function if the file format is 2. Hence this part makes sense and is done correctly.

However, I found the origin of the FileInfo.nChannles in the function read_settings.m .

The variable FileInfo.nChannles is defined in the function read_settings.m like this:

FileInfo.nChannels = double(TotChans);

Where TotChans is defined like:

TotChans = NumChans + NumCChan + NumLRChans

I’m not using Calcultated Channels either Load Roses Channels so their value is zero.

After running the code step by step, I found a piece of code I don’t understand. In this part of the code, the value of NumChans if calculated.

HeadLines  = textscan( fidData, '%s', NamesLine, 'delimiter', '\n' );
fclose( fidData );
temp       = textscan( HeadLines{1}{NamesLine}, '%s' );
NumChans   = size( temp{1}, 1 );
 %      NumChansSN = NumChans;
 ChanNames  = cell( 1, NumChans );
   
 for Ch=1:NumChans
  %         ChanNames{Ch} = [ '$', temp{1}{Ch} ];
    	ChanNames{Ch} = temp{1}{Ch};
 end % for Ch

According to the MATLAB webpage definition, the textscan function can be used to “read formatted data from text file or string”. Why is it used here if the data file can also be binary?

To try to understand this piece of code I used an ASCII output file, since MLife works well with this type of formats. Basicly it reads the header of the output file and saves it in a cell array. Then, move all the names of the channels to temp and uses its size to calculate the number of channels.

When I repeated this process with a binary output file I saw that, maybe because of textscan, the cell array was full of strange symbols (like this: ¦Yù…ì7þÙ ÄV ±·»¤/ ·$"­DÑO2=,¡ Ä+1 úz) and I think they are been treated like normal text. That’s why it just reads 4.

I think I found the root of the problem.

After a more detailed study of the code exposed in the last post, I discovered what is changing when the output file format is ASCII or binary.

For an ASCII output file, in the MLife input file I had written this:

-----  Input-Data Layout  ------------------------------------------------------
0                 TitleLine         The row with the file title on it (zero if no title is available).
7                 NamesLine         The row with the channel names on it (zero if no names are available or are specified below).
8                 UnitsLine         The row with the channel units on it (zero if no units are available or are specified below).
9                 FirstDataLine     The first row of data.
0                NumChans          The number of channels in each input file.
ChanTitle    ChanUnits    Scale  Offset   PSF_Type  NumCols rows of data follow.  Title and units strings must be 10 characters or less.

and the values of internal variables of the read_settings.m functions are:


As you can see, nothing strange, but for a binary output file (with the same configuration in the MLife input file) I saw something that caught my attention. Everything was full of the same strange symbols I described in the last post, but when I was checking the lenght of each cell I discovered that in the cell 4, after many symbols, this was written:

All the header of the file was written in a single line (the image is the text pasted in a Word document). I changed the MLife input file and wrote NamesLine = 4 and with this I managed to execute MLife with my binary output file.

EDIT:
I created two identical result files but each with a different format (.out and .outb), I ran them in MLife as follows:
OUT → NamesLine = 7
OUTB → NamesLine = 4

after comparing the results, I was able to confirm that there is no difference at all, so we can say that the problem is resolved.

Sorry if I made a big deal out of nothing.

Best regards,

1 Like

Dear @Ignacio.Lopez,

I’m glad you solved the issue! When I saw your post, I forwarded it to others to respond; I’m glad you figured it out before they got to it!

Best regards,