Skip to content

Commit

Permalink
Resolves building issues (WRF/WRF-chem) with Intel compilers (ifx/icx) (
Browse files Browse the repository at this point in the history
#1942)

TYPE: bug fix

KEYWORDS: Missing/Wrong Prototypes in C code, WRF-Chem

SOURCE: Changgui Lin

DESCRIPTION OF CHANGES:
Problem:
Problem: Most C code written long ago. No prototypes were used. See PR#1823. And, this pr is kind of an extension to PR#1823 addressing the same issue for building WRF-chem.

Solution:
Add missing prototypes; rearrange function order to support new Intel oneAPI compiler

RELEASE NOTE: This PR fixed missing and/or wrong prototypes in C code to support successful compilation of WRF-Chem when using the Intel oneAPI compiler ifx/icx.
  • Loading branch information
ahheo committed Feb 20, 2024
1 parent d66b399 commit 2e15abb
Show file tree
Hide file tree
Showing 36 changed files with 277 additions and 225 deletions.
6 changes: 3 additions & 3 deletions chem/KPP/kpp/kpp-2.1/src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "gdata.h"
#include "code.h"
#include "scan.h"
#include <time.h>
#include <unistd.h>
#include <string.h>
Expand Down Expand Up @@ -98,7 +99,6 @@ FILE * mex_jacFile = 0;
FILE * mex_hessFile = 0;
FILE * wrf_UpdateRconstFile = 0;


FILE * currentFile;

int ident = 0;
Expand Down Expand Up @@ -193,7 +193,7 @@ char *p;
p = outBuf;
while( *p )
*p++ &= ~0x80;
fprintf( currentFile, outBuf );
fprintf( currentFile, "%s", outBuf );
outBuffer = outBuf;
*outBuffer = 0;
}
Expand All @@ -205,7 +205,7 @@ char *p;
p = buf;
while( *p )
*p++ &= ~0x80;
fprintf( currentFile, buf );
fprintf( currentFile, "%s", buf );
}

void WriteDelim()
Expand Down
19 changes: 15 additions & 4 deletions chem/KPP/kpp/kpp-2.1/src/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define _CODE_H_

#include <stdlib.h>
#include <unistd.h>
#include "gdef.h"

#define MAX_DEPTH 10
Expand Down Expand Up @@ -167,10 +168,10 @@ void CommentFncBegin( int f, int *vars );
void CommentFunctionBegin( int f, ... );
void CommentFunctionEnd( int f );

void Use_C();
void Use_F();
void Use_F90();
void Use_MATLAB();
void Use_C( char *rootFileName );
void Use_F( char *rootFileName );
void Use_F90( char *rootFileName );
void Use_MATLAB( char *rootFileName );

extern void (*WriteElm)( NODE *n );
extern void (*WriteSymbol)( int op );
Expand All @@ -188,4 +189,14 @@ extern void (*FunctionEnd)( int f );

void WriteDelim();

/* >>> CL: code_matlab.c */
extern void MATLAB_Inline( char *fmt, ... );
/* >>> CL: code_F90.c */
extern void F90_Inline( char *fmt, ... );
/* >>> CL: code_F77.c */
extern void F77_Inline( char *fmt, ... );
/* >>> CL: gen.c */
extern int EqnString( int eq, char * buf );
/* <<< CL */

#endif
5 changes: 3 additions & 2 deletions chem/KPP/kpp/kpp-2.1/src/code_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "gdata.h"
#include "code.h"
#include "scan.h"
#include <string.h>

#define MAX_LINE 120
Expand Down Expand Up @@ -366,7 +367,7 @@ char dummy_val[100]; /* used just to avoid strange behaviour of
case CONST: bprintf("#define %-20s %-10s ", var->name, val );
break;
default:
printf( "Invalid constant", var->type );
printf( "Invalid constant %d", var->type );
break;
}
if( varTable[ v ]->comment )
Expand Down Expand Up @@ -484,7 +485,7 @@ char buf[ 1000 ];
FlushBuf();
}

void Use_C()
void Use_C( char *rootFileName )
{
WriteElm = C_WriteElm;
WriteSymbol = C_WriteSymbol;
Expand Down
2 changes: 1 addition & 1 deletion chem/KPP/kpp/kpp-2.1/src/code_f77.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ char buf[ 1000 ];
}

/*************************************************************************************************/
void Use_F()
void Use_F( char *rootFileName )
{
WriteElm = F77_WriteElm;
WriteSymbol = F77_WriteSymbol;
Expand Down
2 changes: 1 addition & 1 deletion chem/KPP/kpp/kpp-2.1/src/code_f90.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ char buf[ 1000 ];
}

/*************************************************************************************************/
void Use_F90()
void Use_F90( char *rootFileName )
{
WriteElm = F90_WriteElm;
WriteSymbol = F90_WriteSymbol;
Expand Down
3 changes: 2 additions & 1 deletion chem/KPP/kpp/kpp-2.1/src/code_matlab.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "gdata.h"
#include "code.h"
#include "scan.h"
#include <string.h>
#include <time.h>

Expand Down Expand Up @@ -673,7 +674,7 @@ char buf[ 1000 ];
}

/*************************************************************************************************/
void Use_MATLAB()
void Use_MATLAB( char *rootFileName )
{
WriteElm = MATLAB_WriteElm;
WriteSymbol = MATLAB_WriteSymbol;
Expand Down
8 changes: 4 additions & 4 deletions chem/KPP/kpp/kpp-2.1/src/gdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@

#include <stdio.h>

#define MAX_EQN 1200 /* mz_rs_20050130 */
#define MAX_SPECIES 500 /* mz_rs_20050130 */
#define MAX_SPNAME 30
#define MAX_EQN 50000 /* 1200 *//* CL *//* mz_rs_20050130 */
#define MAX_SPECIES 10000 /* 500 *//* CL *//* mz_rs_20050130 */
#define MAX_SPNAME 50 /* 30 *//* CL */
#define MAX_IVAL 40
/* MAX_EQNTAG = max length of equation ID in eqn file */
#define MAX_EQNTAG 32
Expand Down Expand Up @@ -196,7 +196,7 @@ void CmdDriver( char *cmd );
void CmdRun( char *cmd );
void CmdStochastic( char *cmd );

void Generate();
void Generate( char *rootFileName );

char * FileName( char *name, char* env, char *dir, char *ext );

Expand Down
46 changes: 26 additions & 20 deletions chem/KPP/kpp/kpp-2.1/src/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
******************************************************************************/


#include <string.h>
#include <math.h>
#include "gdata.h"
#include "code.h"
#include "scan.h"
Expand Down Expand Up @@ -610,11 +612,12 @@ char buf1[100], buf2[100];
if( VarNr == 0 ) return;

if (useLang != MATLAB_LANG) /* Matlab generates an additional file per function */

if ( useWRFConform )
UseFile( integratorFile );
else
UseFile( functionFile );
{
if ( useWRFConform ){
UseFile( integratorFile );}
else{
UseFile( functionFile ); }
}

if ( useWRFConform )
{
Expand Down Expand Up @@ -756,11 +759,12 @@ char buf1[100], buf2[100];
if( VarNr == 0 ) return;

if (useLang != MATLAB_LANG) /* Matlab generates an additional file per function */

if ( useWRFConform )
UseFile( integratorFile );
else
UseFile( functionFile );
{
if ( useWRFConform ) {
UseFile( integratorFile ); }
else {
UseFile( functionFile ); }
}

if ( useWRFConform )
{
Expand Down Expand Up @@ -1099,12 +1103,14 @@ char buf1[100], buf2[100];
if (useJacobian == JAC_OFF) return;

if (useLang != MATLAB_LANG) /* Matlab generates an additional file per function */
{

if ( useWRFConform ){
UseFile( integratorFile );}
else {
UseFile( jacobianFile );}
}

if ( useWRFConform )
UseFile( integratorFile );
else
UseFile( jacobianFile );

if ( useWRFConform ){
sprintf( buf1, "%s_Jac_SP", rootFileName );
Jac_SP = DefFnc( buf1, 4,
Expand Down Expand Up @@ -1932,7 +1938,7 @@ char buf1[100];
sprintf( buf1, "%s_KppSolve", rootFileName );
}else{
UseFile( linalgFile );
sprintf( buf1, "KppSolve", rootFileName );
sprintf( buf1, "%s_KppSolve", rootFileName );
}

SOLVE = DefFnc( buf1, 2, "sparse back substitution");
Expand Down Expand Up @@ -2165,7 +2171,7 @@ int UPDATE_RCONST;
F77_Inline(" INCLUDE '%s_Global.h'", rootFileName);
MATLAB_Inline("global SUN TEMP RCONST");

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

NewLines(1);
Expand Down Expand Up @@ -3380,14 +3386,14 @@ case 't':
break;

default:
printf("\n Unrecognized option '%s' in GenerateF90Modules\n", where);
printf("\n Unrecognized option '%c' in GenerateF90Modules\n", where);
break;
}
}


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void Generate()
void Generate( char *rootFileName )
{
int i, j;
int n;
Expand All @@ -3414,7 +3420,7 @@ int n;
break;
case MATLAB_LANG: Use_MATLAB( rootFileName );
break;
default: printf("\n Language no '%s' unknown\n",useLang );
default: printf("\n Language no '%d' unknown\n",useLang );
}
printf("\nKPP is initializing the code generation.");
InitGen();
Expand Down
2 changes: 1 addition & 1 deletion chem/KPP/kpp/kpp-2.1/src/gen_org.c
Original file line number Diff line number Diff line change
Expand Up @@ -3075,7 +3075,7 @@ case 't':


/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void Generate()
void Generate( char *rootFileName )
{
int i, j;
int n;
Expand Down
2 changes: 1 addition & 1 deletion chem/KPP/kpp/kpp-2.1/src/kpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ for (i=0; i<SpcNr; i++)
}

/*******************************************************************/
int Postprocess( char * root )
void Postprocess( char * root )
{
char buf[ 1024 ];
char cmd[500];
Expand Down
29 changes: 27 additions & 2 deletions chem/KPP/kpp/kpp-2.1/src/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
#define _SCAN_H_

#include <stdio.h>
#include <ctype.h>
#include "gdef.h"

/* mz_rs_20050518+ value increased */
#define MAX_INLINE 30000
#define MAX_INLINE 50000 /* 30000 *//* CL further increased */
/* #define MAX_INLINE 4000 */
/* mz_rs_20050518- */

Expand Down Expand Up @@ -97,7 +98,7 @@ void WriteSpecies();
void WriteMatrices();
void WriteOptions();

void yyerror() ;
void yyerror( char * str ) ;
void ParserErrorMessage() ;

char * AppendString( char * s1, char * s2, int * len, int addlen );
Expand All @@ -107,4 +108,28 @@ void AddInlineCode( char * context, char * code );
int yyerrflag ;
#endif

/* >>> CL: scanner.c */
extern void CmdStoicmat( char *cmd );
extern void CheckAll();
extern void LookAtAll();
extern void TransportAll();
extern void DefineInitializeNbr( char *cmd );
extern void DefineXGrid( char *cmd );
extern void DefineYGrid( char *cmd );
extern void DefineZGrid( char *cmd );
extern void SparseData( char *cmd );
extern void AddUseFile( char *fname );
extern void WRFConform();
extern int ParseEquationFile( char * filename );

/* >>> CL: scan.l */
extern int EqNoCase( char *s1, char *s2 );

/* >>> CL: scan.y */
extern int yylex(void);
/* <<< CL */

/* <<< CL */


#endif
2 changes: 0 additions & 2 deletions chem/KPP/kpp/kpp-2.1/src/scan.l
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
******************************************************************************/



%s CMD_STATE INC_STATE MOD_STATE INT_STATE
%s PRM_STATE DSP_STATE SSP_STATE INI_STATE EQN_STATE EQNTAG_STATE
%s RATE_STATE LMP_STATE CR_IGNORE SC_IGNORE ATM_STATE LKT_STATE INL_STATE
Expand All @@ -43,7 +42,6 @@
#include "scan.h"
#include "y.tab.h"

void*malloc() ;
void Include ( char * filename );
int EndInclude();

Expand Down
5 changes: 3 additions & 2 deletions chem/KPP/kpp/kpp-2.1/src/scan.y
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@
#include <string.h>
#include <unistd.h>
#include "scan.h"
#include "gdata.h"

#define __YYSCLASS

#define YYDEBUG 1
extern char yytext[];
extern FILE * yyin;
/* extern int yyerrstatus; */

int nError = 0;
int nWarning = 0;

Expand All @@ -65,7 +66,7 @@
%}

%union{
char str[80];
char str[500];
};

%token JACOBIAN DOUBLE FUNCTION DEFVAR DEFRAD DEFFIX SETVAR SETRAD SETFIX
Expand Down
2 changes: 1 addition & 1 deletion chem/KPP/util/wkc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include ../../configure.kpp

CFLAGS = #-ansi
LDFLAGS =
DEBUG = -g
DEBUG = -O0 -g
OBJ = registry_kpp.o my_strtok.o data.o type.o misc.o reg_parse.o \
gen_kpp.o get_wrf_chem_specs.o gen_kpp_mech_dr.o gen_kpp_interface.o \
get_kpp_chem_specs.o compare_kpp_to_species.o get_wrf_radicals.o \
Expand Down

0 comments on commit 2e15abb

Please sign in to comment.