coder: problem with externally defined structures

4 次查看(过去 30 天)
Hi, I'd like to generate a C code from an m-function (gc1D.m), which accpets an externally defined structure as an input argument. The same structure is passed on within the m-function to a custom C-function (rfgc1D.c), which reads a data file, performs some operations on that and returns another externally defined structure (through a pointer) and an integer value as an indicator of succesfull reading. Here are header files with a C-function prototype and parts of structures definitions (just the relevant ones):
rfgc1D.h
#ifndef _RFGC1D_H_
#define _RFGC1D_H_
#include "udf_gc1D.h"
extern int rfgc1D(const fluentDataStruct, gcDataStruct *);
#endif
udf_gc1D.h
#ifndef _UDF_GC1D_H_
#define _UDF_GC1D_H_
typedef struct {
char *path2file;
double grateL;
double grateW;
double grateV;
int nGrateCells;
double Acell;
double *Tenv;
} fluentDataStruct;
. . . .
. . . .
. . . .
typedef struct {
double gasInletT;
. . . .
. . . .
. . . .
critStruct crit;
relaxStruct relax;
double *heaterTval;
} gcDataStruct;
#endif
Important fields of these structures are nGrateCells and Tenv from fluentDataStruct and heaterTval from gcDataStruct. There is a piece of code at the end of
rfgc1D.c:
int rfgc1D(const fluentDataStruct fData, gcDataStruct *gcData){
FILE *datafile;
. . . .
. . . .
. . . .
for(i=0;i<fData.nGrateCells;i++)
gcData->heaterTval[i] = fData.Tenv[i];
return 1;
}
The function is called using coder.ceval within the primary function
gc1D.c:
function [] = gc1D(fluentData) %#codegen
. . . .
. . . .
. . . .
coder.cstructname(fluentData,'fluentDataStruct','extern','HeaderFile','udf_gc1D.h');
gcData=gcDataInit(fluentData.nGrateCells); % initialize gcData
coder.cstructname(gcData,'gcDataStruct','extern','HeaderFile','udf_gc1D.h');
read_succ=coder.ceval('rfgc1D',fluentData,coder.wref(gcData)); %read file
. . . .
. . . .
% other local matlab variables are defined here using gcData, including the
% following one
solid.irrad = gcData.heaterEmiss*steffBoltz*gcData.heaterTval(1)^4;
. . . .
. . . .
gcDataInit is an m-function for initializing the structure gcData.
gcDataInit.m
function [gcData] = gcDataInit(nCells)
gcData.gasInletT=298.15;
. . . .
. . . .
. . . .
gcData.heaterTval=zeros(1,nCells);
coder.cstructname(gcData.crit.Ts,'solidTempCritStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData.crit.Tg,'gasTempCritStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData.crit.Vg,'gasVelCritStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData.crit.Rhos,'solidRhoCritStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData.crit.Yg,'gasYiCritStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData.crit.Ys,'solidYiCritStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData.relax.Ts,'solidTempRelaxStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData.relax.Tg,'gasTempRelaxStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData.relax.Vg,'gasVelRelaxStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData.relax.Rhos,'solidRhoRelaxStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData.relax.Yg,'gasYiRelaxStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData.relax.Ys,'solidYiRelaxStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData.crit,'critStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData.relax,'relaxStruct','extern','HeaderFile','udf_gc1D.h');
coder.cstructname(gcData,'gcDataStruct','extern','HeaderFile','udf_gc1D.h');
end
When building the project, this error occurs:
gc1D.c:1376: error: request for member ‘data’ in something not a structure or union
This code can be found in the compiled code gc1D.c at the line 1376:
1375: solid.irrad = gcData.heaterEmiss * 5.66E-8 * rt_powd_snf
1376: (gcData.heaterTval->data[0], 4.0);
Apparently, data is not defined as a field of heaterTval in the definition of the structure. What am I doing wrong? What should I do to tell the coder not to define this additional field? I'd appreciate your help!
  2 个评论
Kaustubha Govind
Kaustubha Govind 2012-8-8
Tomas: You may want to contact MathWorks Tech Support if you do not receive a response here.
Tomas Jurena
Tomas Jurena 2012-8-9
Thank you for your comment. I can wait for anyone's response for a few more days while working on another part of the project. However, afterwards if I do not get any or I do not resolve the problem myself, I'll ask the Tech Support for help.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by