-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG/ISSUE] Matlab Fun() issues #56
Comments
It looks like a fix to the function declarations is in order. I think // Add code to return equation rates via optional argument Aout
// -- Bob Yantosca (29 Apr 2022)
NewLines(1);
if ( useLang == F90_LANG ) {
fprintf(functionFile, " !### Use Aout to return equation rates\n");
fprintf(functionFile, " IF ( PRESENT( Aout ) ) Aout = A\n");
} I've patched the function declaration for if(useLang == F90_LANG) {
F_VAR = DefFnc( "Fun", 5,
"time derivatives of variables - Aggregate form");
FSPLIT_VAR = DefFnc( "Fun_SPLIT", 7,
"time derivatives of variables - Split form");
}
else {
F_VAR = DefFnc( "Fun", 4,
"time derivatives of variables - Aggregate form");
FSPLIT_VAR = DefFnc( "Fun_SPLIT", 6,
"time derivatives of variables - Split form");
}
// We have added the capability to return equation rates and the
// time derivative of variable species from Fun via optional arguments
// Aout and VdotOut (when z_useAggregate=1)
// -- Bob Yantosca (03 May 2022)
if( z_useAggregate ) {
if(useLang == F90_LANG) { // F90_LANG adds Aout, but not needed for other languages
FunctionBegin( F_VAR, V, F, RCT, Vdot, Aout );
}
else {
FunctionBegin( F_VAR, V, F, RCT, Vdot );
}
}
else {
if(useLang == F90_LANG) { // F90_LANG adds Aout, but not needed for other languages
FunctionBegin( FSPLIT_VAR, V, F, RCT, Vdot, P_VAR, D_VAR, Aout );
}
else {
FunctionBegin( FSPLIT_VAR, V, F, RCT, Vdot, P_VAR, D_VAR );
}
}
if ( (useLang==MATLAB_LANG)&&(!z_useAggregate) )
printf("\nWarning: in the function definition for Fun_SPLIT.m move P_VAR to output vars\n"); This builds the code correctly for Matlab. |
For some reason,
This seemed to be fine before, maybe it's a recent Matlab update? |
Sorry, @jimmielin, I hardly know anything about Matlab. Maybe we should ask our Matlab colleagues directly here? |
Hi Rolf, thanks for the suggestion, I'm still looking through the changes we made for the Matlab fixes for PACT-1D as they seem to be related. I'll follow up in that thread shortly once I figure out what changes are needed and confirm they don't break PACT-1D. |
src/gen.c - Implement the fix proposed by @jimmielin in PR #56. We now declare FUN and FUN_SPLIT with an extra argument (Aout) only for F90. CHANGELOG.md - Updated accordingly Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
We can now close this issue since PR #99 has been merged into version 3.1.1. |
I'm trying to get a small mechanism running with Matlab/Octave but I'm running into a weird bug in the latest
dev
commit.I have a new Matlab mechanism using
small_strato
, specified bym_small_strato.kpp
:Running
kpp
this generates the code fine but it crashes onFun()
- looking atm_small_strato_Fun.m
, the code is obviously wrong:For some reason,
Aout
is set as the output argument. This is wrong. Looking at PACT-1D-HALOGENS' current code at https://github.com/PACT1D/PACT-1D-HALOGENS/blob/main/mechanism/mech_Fun.mthe declaration of
Fun()
should only have(V, F, RCT)
andVdot
is the output argument:I suspect that the function declaration at this line is not correct for MATLAB, but I'm not sure how to fix this. For some reason
Results in matlab generated code to have
Aout
as the output arg, notVdot
. I thinkVdot
is expected sinceFun_Chem()
uses it:The text was updated successfully, but these errors were encountered: