How to use Psychtoolbox with Matlab Compiler?

I am looking for tips from anyone who has successfully
used Psychtoolbox with the Matlab Compiler to build a standalone application.

Following the Matlab documentation and deploytool,
I got their "magicsquare" example working.

I followed the same steps with my Psychtoolbox program
and the compilation steps worked fine.

When I run the compiled program, it crashes at the first Psychtoolbox function:

I am hoping this will be an easy fix.

- - - - -
System Configuration:
Mac OS 10.6.7
Matlab 7.10.0.499 (R2010a)
??? Error using ==> fgetl at 44
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in ==> PsychtoolboxVersion at 108
Error in ==> expt at 30
MATLAB:FileIO:InvalidFid
- - - - -

This is the code near line 108 of PsychtoolboxVersion.m

file=fullfile(PsychtoolboxRoot,'Contents.m');
f=fopen(file,'r');
fgetl(f); <~~~ LINE 108
s=fgetl(f);
fclose(f);

- - - - -

I am guessing the PsychtoolboxRoot is not being set correctly in the compiled version,
since fopen can't find the Contents.m file,
... therefore getfl(f) fails because "f" is not valid.

I am running the compiled code on the same iMac as the regular Matlab program,
so all the Psychtoolbox stuff is there in /Applications/Psychtoolbox

any suggestions would be appreciated,
David Jones
dxjones@...
--- In psychtoolbox@yahoogroups.com, "dxjonespix" <dxjones@...> wrote:
>
> I am looking for tips from anyone who has successfully
> used Psychtoolbox with the Matlab Compiler to build a standalone application.
>
> Following the Matlab documentation and deploytool,
> I got their "magicsquare" example working.
>
> I followed the same steps with my Psychtoolbox program
> and the compilation steps worked fine.
>
> When I run the compiled program, it crashes at the first Psychtoolbox function:
>
> I am hoping this will be an easy fix.
>

The easy fix would be to not use PsychtoolboxVersion() or any function/code that depends on auto-detected relative filesystem pathes, e.g., PsychtoolboxRoot(), as this won't work in a compiled Matlab executable. PsychtoolboxRoot() searches for itself to find the Psychtoolbox main folder, and some functions encode pathes relative to PsychtoolboxRoot(). Such pathes are not reproduced 1:1 inside a compiled project afaik, so this can't work.

Psychtoolbox is not designed or tested for use in compiled Matlab executables, so i guess compiling complex stimulus scripts will involve quite a bit of manual work, e.g., manually encoding or changing relative pathes and defining dependencies. E.g., the mcc only knows about M-Files and mex files, but not about our GLSL shaders or other files like sound or image files, .mat files and other stuff we use. There are many ways to get it wrong.

-mario


> - - - - -
> System Configuration:
> Mac OS 10.6.7
> Matlab 7.10.0.499 (R2010a)
> ??? Error using ==> fgetl at 44
> Invalid file identifier. Use fopen to generate a valid file identifier.
>
> Error in ==> PsychtoolboxVersion at 108
> Error in ==> expt at 30
> MATLAB:FileIO:InvalidFid
> - - - - -
>
> This is the code near line 108 of PsychtoolboxVersion.m
>
> file=fullfile(PsychtoolboxRoot,'Contents.m');
> f=fopen(file,'r');
> fgetl(f); <~~~ LINE 108
> s=fgetl(f);
> fclose(f);
>
> - - - - -
>
> I am guessing the PsychtoolboxRoot is not being set correctly in the compiled version,
> since fopen can't find the Contents.m file,
> ... therefore getfl(f) fails because "f" is not valid.
>
> I am running the compiled code on the same iMac as the regular Matlab program,
> so all the Psychtoolbox stuff is there in /Applications/Psychtoolbox
>
> any suggestions would be appreciated,
> David Jones
> dxjones@...
>