COMPREAL v float and REAL

Use this forum to post Vensim related questions.
Post Reply
Dr John P Weldon
Member
Posts: 39
Joined: Sun Oct 07, 2018 7:56 pm
Vensim version: DSS

COMPREAL v float and REAL

Post by Dr John P Weldon »

Venext.c

val[2].vec->vals, (1128)
val[3].val, (1129)

1>c:\vensim\venext6\external sub functions\hospital\venext.c(1128): warning C4133:
'function': incompatible types - from 'COMPREAL *' to 'float *'
1>c:\vensim\venext6\external sub functions\hospital\venext.c(1129): warning C4244:
'function': conversion from 'COMPREAL' to 'REAL', possible loss of data

I am preparing to run DSS v8.1.0 and VS 2017 under Windows 10.

These are two examples of many warnings relating to venext.c. There was advice that this file had been discontinued, but venext.c is evidently still needed.

Please advise how these warnings can be made to go away.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: COMPREAL v float and REAL

Post by Administrator »

Have you removed venext.c from the external function library sample that ships with Vensim and copied it to your own project? If yes, you will be missing the correct definitions for COMPREAL etc. The best option is to start with the sample project and adjust that to meet your needs.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Dr John P Weldon
Member
Posts: 39
Joined: Sun Oct 07, 2018 7:56 pm
Vensim version: DSS

Re: COMPREAL v float and REAL

Post by Dr John P Weldon »

double rval=0.0;

case ADJTM_FUNC :
rval = ADJTM(val[0].vec->vals, (L1150)
val[1].vec->vals,
val[2].vec->vals,
val[3].val,
val[4].val,
val[5].val,
val[6].val,
val[7].val,
val[8].val,
val[9].val,
val[10].val); (L1160)
break;

Warnings

1>..\Venext6\External Sub Functions\hospital\Venext.c(1150): warning C4133: 'function': incompatible types - from 'COMPREAL *' to 'float *'
1>..\Venext6\External Sub Functions\hospital\Venext.c(1151): warning C4133: 'function': incompatible types - from 'COMPREAL *' to 'float *'
1>..\Venext6\External Sub Functions\hospital\Venext.c(1152): warning C4133: 'function': incompatible types - from 'COMPREAL *' to 'float *'
1>..\Venext6\External Sub Functions\hospital\Venext.c(1153): warning C4244: 'function': conversion from 'COMPREAL' to 'REAL', possible loss of data
1>..\Venext6\External Sub Functions\hospital\Venext.c(1154): warning C4244: 'function': conversion from 'COMPREAL' to 'REAL', possible loss of data
1>..\Venext6\External Sub Functions\hospital\Venext.c(1155): warning C4244: 'function': conversion from 'COMPREAL' to 'REAL', possible loss of data
1>..\Venext6\External Sub Functions\hospital\Venext.c(1156): warning C4244: 'function': conversion from 'COMPREAL' to 'REAL', possible loss of data
1>..\Venext6\External Sub Functions\hospital\Venext.c(1157): warning C4244: 'function': conversion from 'COMPREAL' to 'REAL', possible loss of data
1>..\Venext6\External Sub Functions\hospital\Venext.c(1158): warning C4244: 'function': conversion from 'COMPREAL' to 'REAL', possible loss of data
1>..\Venext6\External Sub Functions\hospital\Venext.c(1159): warning C4244: 'function': conversion from 'COMPREAL' to 'REAL', possible loss of data
1>..\Venext6\External Sub Functions\hospital\Venext.c(1160): warning C4244: 'function': conversion from 'COMPREAL' to 'REAL', possible loss of data

When I sought help initially to make these warnings go away I was told that it was not a Vensim matter but a C/C++ problem. I therefore contacted the C++ forum, where two experienced responders informed me that they do not know how to help me.

A Google search confirmed that COMPREAL apparently has no existence outside Vensim.

I was also told initially that a sample venext.c file that ships with Vensim would assist in resolving my problem. No sample venext.c file has been found on my hard disk that can do that.

I should therefore be obliged if somebody in the Vensim forum would kindly tell me how to make these warnings go away. I am using DSS 8.1.0 with Visual Studio 2017 under Windows 10.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: COMPREAL v float and REAL

Post by Administrator »

Same answer as before (which you did not reply to).

Have you removed venext.c from the external function library sample that ships with Vensim and copied it to your own project? If yes, you will be missing the correct definitions for COMPREAL etc. The best option is to start with the sample project and adjust that to meet your needs.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Dr John P Weldon
Member
Posts: 39
Joined: Sun Oct 07, 2018 7:56 pm
Vensim version: DSS

Re: COMPREAL v float and REAL

Post by Dr John P Weldon »

I have already informed the forum that

I was also told initially that a sample venext.c file that ships with Vensim would assist in resolving my problem. No sample venext.c file has been
found on my hard disk that can do that.

Please copy this sample venext.c file to me. Perhaps I can then resolve the matter.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: COMPREAL v float and REAL

Post by tomfid »

Assuming you're on Windows, you should have C:\Users\Public\Vensim\COMP\VensimExternalFunctionLibrary\Windows\VensimExternalFunctionLibrary which contains venext.c in a sample project.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: COMPREAL v float and REAL

Post by tomfid »

A COMPREAL is a float or double (usually the latter these days), depending on the definitions of DBLPREC and DPMATH.

It's actually #defined in vensim.h, which needs to be included in the project. A copy should be a couple levels up in the directory hierarchy.

Presumably ADJTM_FUNC etc. in ..\Venext6\External Sub Functions\hospital\Venext.c is your customized function, not ours. So the issue is likely one of compatibility between your venext.c, presumably based on an earlier version, and the latest vensim.h.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: COMPREAL v float and REAL

Post by Administrator »

Dr John P Weldon wrote: Mon Jan 25, 2021 9:39 pmI was also told initially that a sample venext.c file that ships with Vensim would assist in resolving my problem. No sample venext.c file has been
found on my hard disk that can do that.
I've checked our emails, the reply to you was "We no longer provide venext.c. We now provide a full Visual Studio project that compiles for both Windows 32 and 64 versions of Vensim. You can find this project at C:\Users\Public\Vensim\COMP\VensimExternalFunctionLibrary\Windows"
Dr John P Weldon wrote: Mon Jan 25, 2021 9:39 pmNo sample venext.c file has been found on my hard disk that can do that.
Have a look in

C:\Users\Public\Vensim\COMP\VensimExternalFunctionLibrary\Windows

This contains the Visual Studio project that I keep referring to. If you open this project, you will find that one of the files is called venext.c.

I strongly suggest you use the code I updated for you as this did compile and work. If you don't wish to do this, then I strongly suggest you open the Visual Studio project we provide and update that for your needs.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: COMPREAL v float and REAL

Post by tomfid »

It might be useful to use a tool like kdiff or winmerge to compare your venext.c to the copy that installs with Vensim. The differences should all be your additional code blocks, i.e. stuff related to ADJTM_FUNC.
Dr John P Weldon
Member
Posts: 39
Joined: Sun Oct 07, 2018 7:56 pm
Vensim version: DSS

Re: COMPREAL v float and REAL

Post by Dr John P Weldon »

It is not sufficiently evident from the sample venext.c what the new version of my ADJTM.C etc. should look like. I should therefore be obliged if somebody could translate ADJTM.C into that new version. I could then use the 'template' to convert the remaining 130 plus instances.

In my models an example of ADJTM.C appears as follows.

DROLST[MDSV]=ADJTM(DROLST1[MDS1],DROLST2[MDS1],DROLST3[MDS1],0,0,0,Time,TIME_STEP,MEDSA,22,RUNNO)~ p ~|

In my current venext.c ADJTM.C appears as follows.

extern REAL ADJTM(DATAP ARGVAL, DATAP ARGVL1, DATAP ARGVL2, REAL nondim, REAL nondm1, REAL nondm2, REAL time, REAL dt, REAL andn1,
REAL calls, REAL runno);

{"ADJTM"," {ARGVAL}, {ARGVL1}, {ARGVL2}, {nondim}, {nondm1}, {nondm2}, {time}, {dt}, {andn1}, {calls}, {runno} ",11,3,ADJTM_FUNC,0,0,0,0},

case ADJTM_FUNC:
rval = ADJTM(val[0].vec->vals,
val[1].vec->vals,
val[2].vec->vals,
val[3].val,
val[4].val,
val[5].val,
val[6].val,
val[7].val,
val[8].val,
val[9].val,
val[10].val);
break;
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: COMPREAL v float and REAL

Post by tomfid »

I think this might be really simple ... replace the REAL (=float) instances with COMPREAL (which will be a double in double-precision Vensim). This should get rid of the
incompatible types - from 'COMPREAL *' to 'float *'
errors - these happen because floats and doubles have a different size.
Dr John P Weldon
Member
Posts: 39
Joined: Sun Oct 07, 2018 7:56 pm
Vensim version: DSS

Re: COMPREAL v float and REAL

Post by Dr John P Weldon »

I always welcome simple solutions. However, there are apparently no REAL instances to replace in venext.c, particularly in the 'case' section of venext.c where all the COMPREAL warnings occur. Am I misunderstanding you in some way?
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: COMPREAL v float and REAL

Post by tomfid »

I was looking at the REALs in the declaration:
extern REAL ADJTM(DATAP ARGVAL, DATAP ARGVL1, DATAP ARGVL2, REAL nondim, REAL nondm1, REAL nondm2, REAL time, REAL dt, REAL andn1,
REAL calls, REAL runno);
If this function is defined in ADJTM.c, then presumably there are some internal REAL or float instances in that file that should probably be declared as COMPREAL or double instead.
Dr John P Weldon
Member
Posts: 39
Joined: Sun Oct 07, 2018 7:56 pm
Vensim version: DSS

Re: COMPREAL v float and REAL

Post by Dr John P Weldon »

I changed all extern REALs to double, to conform with the sample venext.c. That did not work. Same warnings as before.

I then changed all extern REALs to extern COMPREALs. That did not work either.

Following your latest advice I changed all internal REALs in ADJTM.c to COMPREAL. In venext.c (extern REAL section) I also changed all internal REALs in ADJTM.c to COMPREAL.

That worked for val[3].val to val[10].val). No more warnings for them. However, the val[?].vec->vals instances are still generating warnings. What do I do with them? They are the DATAP items in ADJTM.c.

case ADJTM_FUNC:
rval = ADJTM(val[0].vec->vals,
val[1].vec->vals,
val[2].vec->vals,
val[3].val,
val[4].val,
val[5].val,
val[6].val,
val[7].val,
val[8].val,
val[9].val,
val[10].val);
break;

It is very evident that the sample venext.c that ships with Vensim is not an adequate guide or template. I hope that a lot more detail will be provided later.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: COMPREAL v float and REAL

Post by Administrator »

Dr John P Weldon wrote: Mon Feb 01, 2021 7:03 amIt is very evident that the sample venext.c that ships with Vensim is not an adequate guide or template. I hope that a lot more detail will be provided later.
I've repeatedly said you need to start with the Visual Studio Project that ships with Vensim and modify that. venext.c by itself is not a guide or template, you need the whole project. Is there a reason you are reluctant to start wit the project we provide?

I've also already done this for you. Is there a reason you are reluctant the use what I've already done?

DATAP is not a Vensim variable type. You will need to work out what that is.

I strongly suggest you use what I have already done for you, if not, then start with the Visual Studio project we provide.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: COMPREAL v float and REAL

Post by tomfid »

DATAP is presumably a float, since the first three errors are 'incompatible types - from 'COMPREAL *' to 'float *'.' Pointer arithmetic can't work on these because of the float/double size difference. The other warnings would probably work with an implicit cast, but it would be better for everything to have matching types. Again, this seems likely to be a simple matter of adjusting the types in ADJTM.
Dr John P Weldon
Member
Posts: 39
Joined: Sun Oct 07, 2018 7:56 pm
Vensim version: DSS

Re: COMPREAL v float and REAL

Post by Dr John P Weldon »

One type of warning that appears often is

1>c:\vensim\venext6\external sub functions\hospital\paramid4.c(663): warning C4244:
'return': conversion from 'COMPREAL' to 'REAL', possible loss of data

COMPREAL paramid4_v;

if( EQUAL(type, ONE)){ // integer array
paramid4_v = (COMPREAL)entout4[ndm1 - 1][ndm2 - 1][ndm3 - 1][ndm4 - 1];
}
else if( EQUAL(type, TWO)){ // COMPREAL array
paramid4_v = entoutf4[ndm1 - 1][ndm2 - 1][ndm3 - 1][ndm4 - 1];
}
return paramid4_v; (L663)
} // end of function

Another problem is

1>c:\vensim\venext6\external sub functions\hospital\nldate.c(301): error C2086:
'COMPREAL nldate_v': redefinition

COMPREAL nldate_v;

nldate_v = (COMPREAL)pxleh14[mdsv - 1];
return nldate_v; (L301)
} // end of function

Please suggest solutions for these problems.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: COMPREAL v float and REAL

Post by tomfid »

'return': conversion from 'COMPREAL' to 'REAL', possible loss of data

COMPREAL paramid4_v;

...
return paramid4_v; (L663)
} // end of function
I think the issue here must be that the function is returning COMPREAL paramid4_v, but the function's return type is declared as REAL rather than COMPREAL. Changing the function definition and declaration should fix that.
'COMPREAL nldate_v': redefinition
This implies that nldate_v is already declared as something else (perhaps a REAL, but could be anything) - either further up in the function header, or perhaps as one of the arguments.
Dr John P Weldon
Member
Posts: 39
Joined: Sun Oct 07, 2018 7:56 pm
Vensim version: DSS

Re: COMPREAL v float and REAL

Post by Dr John P Weldon »

By 'the function' I assume that you refer to the subprogram: in this case paramid4.c. I changed its declaration to COMPREAL /*FUNCTION*/ PARAMID4( ...
The declarations of function PARAMID4 in venext.c are

extern COMPREAL PARAMID4(DATAP INVAR, DATAP ONDTM, DATAP OSTTM, DATAP XNDTM, DATAP XSTTM, COMPREAL runop1, COMPREAL xlonof,
COMPREAL runno, COMPREAL time, COMPREAL akrow, COMPREAL alrow, COMPREAL amrow, COMPREAL anrow, COMPREAL asrow,
COMPREAL ndn1, COMPREAL ndn2, COMPREAL ndn3, COMPREAL ndn4, COMPREAL ndr1, COMPREAL ndr2, COMPREAL olist, COMPREAL ntabn,
COMPREAL type, COMPREAL pndst);

{"PARAMID4"," {INVAR}, {ONDTM}, {OSTTM}, {XNDTM}, {XSTTM}, {runop1}, {xlonof}, {runno}, {time}, {akrow}, {alrow}, {amrow}, {anrow}, {asrow},
{ndn1}, {ndn2}, {ndn3}, {ndn4}, {ndr1}, {ndr2}, {olist}, {ntabn}, {type}, {pndst} ",24,5,PARAMID4_FUNC,0,0,0,0},

case PARAMID4_FUNC :
rval = PARAMID4(val[0].vec->vals,
val[1].vec->vals,
val[2].vec->vals,
val[3].vec->vals,
val[4].vec->vals,
val[5].val,
...
val[23].val);
break;

I do not yet know how to revise '.vec->vals', although I have declared DATAP as COMPREAL.

Is there anything else that I must change?

The result of the change was

1>c:\vensim\venext6\external sub functions\hospital\paramid4.c(663): error C2086: 'COMPREAL paramid4_v': redefinition
1>c:\vensim\venext6\external sub functions\hospital\paramid4.c(42): note: see declaration of 'paramid4_v'
1>c:\vensim\venext6\external sub functions\hospital\paramid4.c(806): warning C4091: ' ': ignored on left of 'double' when no variable is declared

Re function NLDATE.c

COMPREAL nldate_v;

nldate_v is not a function argument.

Declaration of NLDATE.c is

COMPREAL /*FUNCTION*/ NLDATE( DATAP PXLEH16, DATAP PXLEH20, DATAP ANLNP, COMPREAL time, COMPREAL today2, COMPREAL ameds,
COMPREAL runno, COMPREAL call )

Venext.c conforms to this.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: COMPREAL v float and REAL

Post by tomfid »

A redefinition error generally occurs when you declare something, then declare it again later in the same scope:

int x;
<blabla>
float x;

https://docs.microsoft.com/en-us/cpp/er ... w=msvc-160

If DATAP is a COMPREAL, I think vec->vals should be fine.
Post Reply