Make functions unreadable to end-user

조회 수: 4 (최근 30일)
Caleb
Caleb 2016년 9월 26일
댓글: Walter Roberson 2016년 9월 26일
I have a complete program to perform phase equilibrium calculations at fixed temperature and pressure using an equation of state (EOS). The structure of the code is as follows.
TPflash_Main.m is the main file that calls the following:
1. "INPUTS.m" is a script that gathers all possible parameters from an EXCEL file and creates DATA.mat
2. "EOSparameters.m" is a function that gathers only relevant variables from DATA.mat (based on inputs to the function)
  • [normalizedComposition, EOSprops] = EOSparameters(Components, Composition, EOS)
3. "TPflash.m" is a function that computes equilibrium properties and calls the equation of state that corresponds to the input "EoS".
  • [eqProps] = TPflash(T,P,normalizedComposition,EOSprops,EOS)
I want the code to be packaged in such a way that the end-user cannot see the internals of the code. I have made INPUTS.m into an executable, but this isn't really what I want because I want the user to be able to pass inputs to the function to be able to change the source EXCEL file.
Additionally, there is a function file that is called by TPflash.m that I want the end-user to be able to replace with their own. If you have familiarity with flash calculations, then this is the file that outputs compressibility (Z) and fugacity (PHI) depending on the equation of state. I have coded the cubic equations of state and it is called by TPflash.m by:
  • [Z, PHI] = cubicEOS(T,P,Compositions,EOSprops)
I want the user to be able to replace my "cubicEOS.m" function with one of their own where I require that they output the same properties [Z,PHI] as "cubicEOS.m"
I'm a long-time user of MATLAB, so I have checked all the usual places to get help on this issue. I know the answer will be obvious, but I'm tired of looking. Thank you for any help!

채택된 답변

Walter Roberson
Walter Roberson 2016년 9월 26일
You could pcode your routines, but a user who bothers to user a debugger can find out names of functions and variables.
You could create a shared library (executable) that could be called. This would have to be done for each platform to be supported. Because a MATLAB instance would still be there, it would be possible to call a user-provided function. Uaer-provided routines may be able to probe the call stack to some degree.
Any data that you hang off a graphics object (or other queryable MATLAB object) is fair game for the user to try to probe. Any shared variable or persistent variable is fair game for a user to probe with functions() if they can get hold of the function handle.
On MS Windows, you could create an executable that was communicated with using COM objects. You could hide the important parts and provide an interface routine.
On all platforms, you could create an executable that was communicated with using TCP.
Note: code that has been obscured in this ways is not permitted in the MATLAB File Exchange.
  댓글 수: 2
Caleb
Caleb 2016년 9월 26일
What I'm trying to do I've seen done with MEX files. Can I make a MEX file from MATLAB source code?
Walter Roberson
Walter Roberson 2016년 9월 26일
MATLAB Coder can generate C/C++ source, provided that your code fits within the language subset.
MATLAB Compiler compiling to a shared library has more leeway because the full MATLAB MCR engine is still around for that case.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conway's Game of Life에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by