Path: news.mathworks.com!not-for-mail
From: "Ben " <ben.cowley@helsinki.fi>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Compiled Matlab fgets error
Date: Wed, 12 Sep 2012 04:56:07 +0000 (UTC)
Organization: Helsingin Yliopiston Observatorio
Lines: 134
Message-ID: <k2p4l7$qf6$1@newscl01ah.mathworks.com>
References: <k2o940$q1o$1@newscl01ah.mathworks.com> <k2oa8k$g25$1@speranza.aioe.org>
Reply-To: "Ben " <ben.cowley@helsinki.fi>
NNTP-Posting-Host: www-00-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1347425767 27110 172.30.248.45 (12 Sep 2012 04:56:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 12 Sep 2012 04:56:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3269771
Xref: news.mathworks.com comp.soft-sys.matlab:778294

Hi,

I'll quote the code but there's quite a lot :)

It starts with uigetfile, and runs through some file IO for various types of text files. Some of these functions are Matlab native, some (at least xml2struct) are picked up off F-Ex. They run fine, and for testing they spit out an xls file to show they have worked.
They're acting on a directory location which looks like:
<root folder - obtained by uigetfile>
 - text files
 - <games folder>
 - <game 1>
 -  - EEG file
 - <game 2>
 -  - EEG file
...

So what I'm wondering now is whether it matters that the root folder is added to the path by addpath(), and the subdirectories are not added explicitly in the same way (they are meant to be added by the same call to addpath).

<code>
    % First file to grab
    fname = 'patient_condition.txt';

    % Find the desired session folder
    if isempty( pathn )
        [fname, pathn] = uigetfile( fname, 'Select Session Data' );
    end
    % Add session folder to path
    addpath( genpath(pathn) );
    % Get list of files in folder
    seshfs = dir( pathn );
    % If there is no 'games' folder, then nothing of interest took place.
    if sum(strcmp({seshfs.name}, 'games'))==0
        disp( ['*#*#*#* There were no games found at ' pathn '; aborting *#*#*#*'] );
        return;
    end

    %% PATIENT CONDITION VALUES
    % Get the patient condition data
    fname = fullfile(pathn, fname);
    fid = fopen(fname);
    pcond = textscan(fid, '%s %f', 'Delimiter', ':');
    % Cut date variable and reduce the score by an order of mag, shorten names
    date = datestr(datenum(num2str(pcond{2}(6)), 'yyyymmddHHMMSS'));
    pcond{1}(6) = []; pcond{2}(6) = [];
    % Get end of session data, append to condition data
    fname = fullfile(pathn, 'session_score.txt');
    fid = fopen(fname);
    if fid ~= -1,   ptmp1 = textscan(fid, '%s %f', 'Delimiter', ':');
    else
        disp( '*#*#*#* Session score not found - subbing zeros *#*#*#*' );
        ptmp1 = { {'-'; '-'; 'session_average_score'}, [0.0; 0.0; 0.0] };
    end;
    fname = fullfile(pathn, 'session_summary.txt');
    fid = fopen(fname);
    if fid ~= -1,   ptmp2 = textscan(fid, '%s %f', 'Delimiter', ':');
    else
        disp( '*#*#*#* Session summary not found - subbing zeros *#*#*#*' );
        ptmp2 = { {'Effort'; 'Frustration'}, [0.0; 0.0] };
    end
    % Combine the three patient condition files - careful about session score
    % as it reads in 1 line more than there is (due to extra ':' in file)
    if ~isempty( ptmp1 ) && ~isempty( ptmp2 )
        pcond = {[pcond{1}; ptmp2{1}; ptmp1{1}(3)] [pcond{2}; ptmp2{2}; ptmp1{2}(3)]};
    end
    pcond{1}{2} = 'Hrs since sleep';
    pcond{1}{8} = 'Session Score/10';
    pcond{2}(8) = pcond{2}(8)./10;

    % Get IEP stuff: Individual alpha freq
    iep = 0.5;
    fname = fullfile(pathn, '..', 'IEP', 'theta.f');
    tmp = xml2struct( fname );
    iep = [iep str2double( tmp.OpenViBE_dash_SettingsOverride.SettingValue{4}.Text )];
    iep = [iep str2double( tmp.OpenViBE_dash_SettingsOverride.SettingValue{5}.Text )];
    % USE THIS VECTOR TO FIND THE VALUES IN BANDS PER GAME
    iep = [iep iep(3)*2 25 45];

    % For COMPILED CODE, test how far it runs.
    xlswrite( 'testout', pcond{1} );

    %% BASELINE VALUES, SPECTRA & COEFFICIENTS CAN CHANGE EVERY GAME. 
    %  MAY NEED TO REWRITE THIS SECTION FOR GAME BY GAME PARSING

    blEEG = [];
    blPwr = [];
    blFrq = [];
    blPows = [];
    basedur = '-';
    % Get the beta and theta baseline values, if a baseline was recorded.
    fname = fullfile(pathn, 'baseline.gdf');
    if exist( fname, 'file' ) == 2
        % Use the baseline.gdf to display the baseline spectrum?
       if seshfs( strcmp({seshfs.name}, 'baseline.gdf')==1 ).bytes > 4096
            blEEG = pop_biosig( fname );
            blEEG.data = double(blEEG.data);
            basedur = blEEG.pnts/blEEG.srate;
       end
    end
</code>

dpb <none@non.net> wrote in message <k2oa8k$g25$1@speranza.aioe.org>...
> On 9/11/2012 4:06 PM, Ben wrote:
> ...
> 
> > The problem for me is that my code uses Eeglab to open .gdf files and
> > the fgets error is thrown from inside there. I cannot change that part
> > of the code, so my question is, does the way that I set up the path in
> > the code or compile the program affect its functioning?
> >
> > FYI, the path is obtained using uigetfile(), and then before the line
> > where the EEG data is read there are several types of text file being
> > read without throwing this error. So that part of the program seems to
> > work ok - it is only when the Eeglab code is called that it fails. Can
> > anyone shed light on how the compiler affects calls to file read functions?
> 
> Well, certainly anything you do re: a path inside code will affect it's 
> functioning, yes.
> 
> One problem often run into when run a compiled app instead of in the 
> workplace is that the process that is spawned to run the executable may 
> not have the identical environment (variables, path, home directory, 
> etc., etc., etc., ....) so files that are visible in the one location 
> may not be in the other.
> 
> Also, w/ another toolbox in play I worry about whether the fid passing 
> is in a separate context so the 3rd party package isn't seeing the fid 
> you think it is.
> 
> I would think such questions can only be answered w/ specific code 
> structure to look at--it's too abstract to simply talk about it; one has 
> to see what actually is being done, specifically to say anything 
> specific.  (Or, I can fall back to the "crystal ball is in the garage 
> for service again" mantra... :) )
> 
> --