Skip to content
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

Add code from #INLINE F90_RCONST_USE at the top of the UPDATE_RCONST subroutine #120

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ docs/build/*

# Other files/dirs to exclude
*.pdf
/examples/mcm/__pycache__
/examples/mcm*/__pycache__
/examples/mcm*/*.exe

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] - TBD
### Added
- Added new inline key `F90_RCONST_USE` in `src/gdata.h` and `src/scanner.c`

### Changed
- Updated `Update_RCONST` to use `Y` instead of `C` to account for updated variable species concentrations
- Updated C-I tests to print the compiler versions that are used
- Updated routine `GenerateUpdateRconst` to manually write the `SUBROUTINE` and `END SUBROUTINE` lines (F90 only)
- Updated routine `GenerateUpdateRconst` to inline code from `#INLINE F90_RCONST_USE` before any other F90 variable declarations or statements
- Updated `.gitignore` to ignore executables in the MCM example folders

### Fixed
- Added `char* rootFileName` to functions and function prototypes for `Use_C`, `Use_F`, `Use_F90`, `Use_MATLAB`, and `Generate`
Expand Down
10 changes: 5 additions & 5 deletions src/gdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ enum krtypes { NUMBER, EXPRESION, PHOTO };
enum table_modes { F_TEXT, FC_TEXT, C_TEXT, S_TEXT };
enum lang { NO_LANG, C_LANG, F77_LANG, F90_LANG, MATLAB_LANG };
enum inl_code {
F77_GLOBAL, F77_INIT, F77_DATA, F77_UTIL, F77_RATES,
F77_RCONST, F90_GLOBAL, F90_INIT, F90_DATA, F90_UTIL,
F90_RATES, F90_RCONST, C_GLOBAL, C_INIT, C_DATA,
C_UTIL, C_RATES, C_RCONST, MATLAB_GLOBAL, MATLAB_INIT,
MATLAB_DATA, MATLAB_UTIL, MATLAB_RATES, MATLAB_RCONST,
F77_GLOBAL, F77_INIT, F77_DATA, F77_UTIL, F77_RATES,
F77_RCONST, F90_GLOBAL, F90_INIT, F90_DATA, F90_UTIL,
F90_RATES, F90_RCONST, F90_RCONST_USE, C_GLOBAL, C_INIT,
C_DATA, C_UTIL, C_RATES, C_RCONST, MATLAB_GLOBAL,
MATLAB_INIT, MATLAB_DATA, MATLAB_UTIL, MATLAB_RATES, MATLAB_RCONST,
INLINE_OPT
};

Expand Down
74 changes: 57 additions & 17 deletions src/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2167,43 +2167,70 @@ void GenerateUpdateRconst()
{
int i;
int UPDATE_RCONST;
int YIN,Y;
int YIN, Y;

UseFile( rateFile );

if (useLang==F90_LANG) {
// F90: Declare function with optional YIN argument and local Y variable.
//
// SPECIAL HANDLING FOR F90:
// -------------------------
// Manually write the "SUBROUTINE RCONST ( YIN )" line instead of
// using the FunctionBegin( UPDATE_RCONST ). This will allow us
// to add any inlined F90 use statements immediately afterwards.
// Recall that F90 "USE" statements must precede variable
// declarations or any other executable statements, or else a
// compilation error will be generated.
//
// -- Bob Yantosca (19 Dec 2024)
//
bprintf("SUBROUTINE Update_RCONST ( YIN )");
NewLines(2);

// Inline USE statements right after the subroutine declaration
WriteComment("Begin INLINED RCONST - F90 USE STATEMENTS");
NewLines(1);
bprintf( InlineCode[ F90_RCONST_USE ].code );
FlushBuf();
NewLines(1);
WriteComment("End INLINED RCONST - F90 USE STATEMENTS");
NewLines(1);

// Declare optional YIN argument
YIN = DefvElmO( "YIN", real, -NVAR, "Optional input concentrations of variable species" );
UPDATE_RCONST = DefFnc( "Update_RCONST", 1, "function to update rate constants");
Declare(YIN);
NewLines(1);

FunctionBegin( UPDATE_RCONST, YIN );
// Declare local Y variable
Y = DefvElm( "Y", real, -NSPEC, "Concentrations of species (local)" );
Declare(Y);
NewLines(1);

// Copy values of YIN to Y if YIN is present
WriteComment("Ensure local Y array is filled with variable and constant concentrations");
bprintf(" Y(1:NSPEC) = C(1:NSPEC)\n");
NewLines(1);
WriteComment("Update local Y array if variable concentrations are provided");
bprintf(" if (present(YIN)) Y(1:NVAR) = YIN(1:NVAR)\n");
NewLines(2);

} else {
//
// For other languages, declare function w/o any arguments
//
UPDATE_RCONST = DefFnc( "Update_RCONST", 0, "function to update rate constants");
FunctionBegin( UPDATE_RCONST );
}

F77_Inline(" INCLUDE '%s_Global.h'", rootFileName);
MATLAB_Inline("global SUN TEMP RCONST");

switch( useLang ){
case F90_LANG:
WriteComment("Ensure local Y array is filled with variable and constant concentrations");
bprintf(" Y(1:NSPEC) = C(1:NSPEC)\n");
NewLines(1);
WriteComment("Update local Y array if variable concentrations are provided");
bprintf(" if (present(YIN)) Y(1:NVAR) = YIN(1:NVAR)\n");
break;
}

if ( useLang==F77_LANG )
IncludeCode( "%s/util/UserRateLaws_FcnHeader", Home );

NewLines(1);

// Inline code from {C,F77,F90_MATLAB}_RCONST inline keys
NewLines(1);
WriteComment("Begin INLINED RCONST");
NewLines(1);
Expand Down Expand Up @@ -2242,9 +2269,22 @@ int YIN,Y;
}

MATLAB_Inline(" RCONST = RCONST(:);");

FunctionEnd( UPDATE_RCONST );
FreeVariable( UPDATE_RCONST );
//
// SPECIAL HANDLING FOR F90:
// -------------------------
// Manually write the "END SUBROUTINE UPDATE_RCONST" line when
// generating F90 output. But if generating C, F77, MatLab output,
// then close the UPDATE_RCONST routine as we normally would.
// -- Bob Yantosca (19 Dec 2024)
//
if (useLang == F90_LANG) {
NewLines(1);
bprintf("END SUBROUTINE UPDATE_RCONST");
NewLines(1);
} else {
FunctionEnd( UPDATE_RCONST );
FreeVariable( UPDATE_RCONST );
}
}


Expand Down
1 change: 1 addition & 0 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ INLINE_KEY InlineKeys[] = { { F77_GLOBAL, APPEND, "F77_GLOBAL" },
{ F90_UTIL, APPEND, "F90_UTIL" },
{ F90_RATES, APPEND, "F90_RATES" },
{ F90_RCONST, APPEND, "F90_RCONST" },
{ F90_RCONST_USE, APPEND, "F90_RCONST_USE"},
{ C_GLOBAL, APPEND, "C_GLOBAL" },
{ C_INIT, APPEND, "C_INIT" },
{ C_DATA, APPEND, "C_DATA" },
Expand Down