Macro with an array type parameter

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Has thanked: 57 times
Been thanked: 27 times

Macro with an array type parameter

Post by Mantas »

Good afternoon bright minds,

I had some issues while trying to replicate some C code on Flowcode. The problem is the input parameters on the macro. It allows you to create an array type parameter, but when you are trying to call it, you get an "incompatible argument" pop-up note error, or if you are tying to put a non array argument you get a message "Can not convert to type 'float[6]' "(in the case if it was a float type array parameter) , so no matter what you type in, it is not possible to call the macro. For example, I was trying to recreate such a C code on the flowcode:

Code: Select all

double earth_values(double term_sum[], int count, double jme)
{
    int i;
    double sum=0;

    for (i = 0; i < count; i++)
        sum += term_sum[i]*pow(jme, i);

    sum /= 1.0e8;

    return sum;
}
the result was:
earth_values.fcm
Sample macro
(3.11 KiB) Downloaded 229 times
Which has to be used in the recreated macro on the flowcode but as the following C code:

Code: Select all

double earth_radius_vector(double jme)
{
    double sum[R_COUNT];
    int i;

    for (i = 0; i < R_COUNT; i++)
        sum[i] = earth_periodic_term_summation(R_TERMS[i], r_subcount[i], jme);

    return earth_values(sum, R_COUNT, jme);

}
The other issue I had is when I tried to recreate a C code like this, with a 2 dimentional array:

Code: Select all

double earth_periodic_term_summation(const double terms[][TERM_COUNT], int count, double jme)
{
    int i;
    double sum=0;

    for (i = 0; i < count; i++)
        sum += terms[i][TERM_A]*cos(terms[i][TERM_B]+terms[i][TERM_C]*jme);

    return sum;
}
How is it possible to recreate such a parameter like const couble terms[][TERM_COUNT] ? This is suppose to acquire the value from the LUT, such as following example:

Code: Select all

const double R_TERMS[R_COUNT][R_MAX_SUBCOUNT][TERM_COUNT]=
{
    {
        {100013989.0,0,0},
        {1670700.0,3.0984635,6283.07585},
        {13956.0,3.05525,12566.1517},
        {3084.0,5.1985,77713.7715},
        {1628.0,1.1739,5753.3849},
        {1576.0,2.8469,7860.4194},
        {925.0,5.453,11506.77},
        {542.0,4.564,3930.21},
        {472.0,3.661,5884.927},
        {346.0,0.964,5507.553},
        {329.0,5.9,5223.694},
        {307.0,0.299,5573.143},
        {243.0,4.273,11790.629},
        {212.0,5.847,1577.344},
        {186.0,5.022,10977.079},
        {175.0,3.012,18849.228},
        {110.0,5.055,5486.778},
        {98,0.89,6069.78},
        {86,5.69,15720.84},
        {86,1.27,161000.69},
        {65,0.27,17260.15},
        {63,0.92,529.69},
        {57,2.01,83996.85},
        {56,5.24,71430.7},
        {49,3.25,2544.31},
        {47,2.58,775.52},
        {45,5.54,9437.76},
        {43,6.01,6275.96},
        {39,5.36,4694},
        {38,2.39,8827.39},
        {37,0.83,19651.05},
        {37,4.9,12139.55},
        {36,1.67,12036.46},
        {35,1.84,2942.46},
        {33,0.24,7084.9},
        {32,0.18,5088.63},
        {32,1.78,398.15},
        {28,1.21,6286.6},
        {28,1.9,6279.55},
        {26,4.59,10447.39}
    },
    {
        {103019.0,1.10749,6283.07585},
        {1721.0,1.0644,12566.1517},
        {702.0,3.142,0},
        {32,1.02,18849.23},
        {31,2.84,5507.55},
        {25,1.32,5223.69},
        {18,1.42,1577.34},
        {10,5.91,10977.08},
        {9,1.42,6275.96},
        {9,0.27,5486.78}
    },
    {
        {4359.0,5.7846,6283.0758},
        {124.0,5.579,12566.152},
        {12,3.14,0},
        {9,3.63,77713.77},
        {6,1.87,5573.14},
        {3,5.47,18849.23}
    },
    {
        {145.0,4.273,6283.076},
        {7,3.92,12566.15}
    },
    {
        {4,2.56,6283.08}
    }
};
Best regards,
Mantas
Science is my true religion.

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Has thanked: 57 times
Been thanked: 27 times

Re: Macro with an array type parameter

Post by Mantas »

Hello support team,

I found out that it is some kind of bug in the flowcode, because if I create a global variable instead of a local variable "sum" the flowcode lets me use this variable to call the earth values macro to insert the parameter "terms_sum". I think there is something you should look into. It is not critical but it is something that should be fixed.

Best regards,
Mantas
Science is my true religion.

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times

Re: Macro with an array type parameter

Post by Spanish_dude »

You don't really need to add arguments to flowcode macros as each defined variable is a global variable and can be used anywhere in the code (except for local variables in macros).
Nicolas

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Has thanked: 57 times
Been thanked: 27 times

Re: Macro with an array type parameter

Post by Mantas »

Apologies, it was really my mistake, I created a local variable array that is smaller than the argument in the macro I was calling.

Nicolas, yes I am aware of that, but I need to do this otherwise I will have same named variables in my global variable collection, and because this macro is called to return the value of several different global variables, I need to do this to avoid mess.

Best regards,
Mantas
Science is my true religion.

Post Reply