LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling Multiple mains

Darnell:

 

You ask for suggestions?  I gave you the changes you need to make in my last post.  Did you save the .h file after you made the changes?

 

Look carefully at the function prototype and calling statement that I gave you in my last post.  Rermove the asterisks from your original code.  You need to change the parameter types in your function definition as well as the prototype.

 

Did you make those 3 changes: function prototype, function definition, and calling statement?

 

Post the same snippets of code you did the first time, updated with the changes I described.

 

What C reference book are you using?

Message Edited by Al S on 09-10-2009 07:28 PM
0 Kudos
Message 11 of 38
(1,832 Views)

Another option, if you can't change the called function and you need to use arrays of pointers, is to use arrays of pointers in your calling routine.

 

long q,u;

double* temp_data[4][3000];

double* meas[3000];

 

//>>>>>>>>>Call to libray function from x program...

q=4;

u=1000;

 

f_ConvDblToSingleArray( temp_data, meas, q);

 

Where does your data come from?  That can help you determine if you want to use arrays of doubles or arrays of pointers to doubles. 

0 Kudos
Message 12 of 38
(1,820 Views)

sorry about that i was watching the football game. now im back.

 

ok we are grabbing data from a telemtry system or encoder. the first is parameter of an index, and the second is index of values.

 

 

im getting ready to make the changes now.

 

 

0 Kudos
Message 13 of 38
(1,815 Views)

1>c:\documents and settings\z1083774\desktop\jjjj\jjjj\edd.cpp(18) : error C2664: 'f_ConvDblToSingleArray' : cannot convert parameter 1 from 'double [4][3000]' to 'double [][1000]'
 

#include <stdio.h>


long f_ConvDblToSingleArray ( double double_array[4][1000], double single_array[3000] , int max_index );
int main()
{
   
long q=0,u=0;
double temp_data[4][3000] =
{
0.0
};
double meas[3000] =
{
0.0
};

f_ConvDblToSingleArray( temp_data, meas, q );

return 0;
}

long f_ConvDblToSingleArray
(
double double_array[4][1000],
double single_array[3000] ,
int max_index );

//Library Function...(This compiles...)
long f_ConvDblToSingleArray
(
double double_array[4][1000],
double single_array[3000] ,
int max_index )
{
long error = 0;

int idx1 = 0;
int idx2 = 0;
int index = 0;

for (idx1=0; idx1 < max_index; idx1++)
{
for ( idx2=0; idx2 < max_index; idx2++ )
{
single_array[index++] = double_array[idx1][idx2];
}
}//

//****************calling program:************************
long q,u;
double temp_data[4][3000] =
{
0.0
};
double meas[3000] =
{
0.0
};

/////>>>>>>>>>Call to libray function from x program...
q=4;
u=1000;


//>>>>>>>>This call produces the following error:
 return 0;
//error C2664: 'f_ConvDblToSingleArray' : cannot convert parameter 1 from 'double *' to 'double *[][1000]'
}

0 Kudos
Message 14 of 38
(1,815 Views)

1>c:\documents and settings\z1083774\desktop\jjjj\jjjj\edd.cpp(18) : error C2664: 'f_ConvDblToSingleArray' : cannot convert parameter 1 from 'double [4][3000]' to 'double [][1000]'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

 

 

im getting the same error

0 Kudos
Message 15 of 38
(1,815 Views)

Hi darnell,

 

1>c:\documents and settings\z1083774\desktop\jjjj\jjjj\edd.cpp(18) : error C2664: 'f_ConvDblToSingleArray' : cannot convert parameter 1 from 'double [4][3000]' to 'double [][1000]'

That "cpp" extension puzzles me: are you developing this code in C or C++? And which compiler / ide are you using for it? Even that "C2664" error code doesn't seem to be generated by CVI.

 

 

I will let to Al  to add some explanations on the theorical part of the problems you are facing now: he's a very clever programmer and better than me in this. I simply add here some notes on problems I can see in your code.

 

 

This is your main in a more compacted form:

int main()
{
    long q=0,u=0;
    double temp_data[4][3000] = { 0.0 };
    double meas[3000] = { 0.0 };

    f_ConvDblToSingleArray (temp_data, meas, q);

    return 0;
}

Passing q = 0 to your function it will do nothing as none of your loop will execute any cycle. Anyway, this is the minor problem, the same as passing a long variable in an int paramter (but you should fix it, indeed!)

 

 

More serious is a note on your f_ConvDblToSingleArray function: I noted that you are using the single max_index parameter for each of the loop: you may be running into problems for max_index > 54, as 55^2=3025 so you will be trying to access elements outside the boundary of the destination array (this doesn't considering that you are constantly accessing elements outside one boundary of double_array for q>3: probably the compiler will be tolerant on it as the memory block is contiguous but you may be mixing your data irreparably)

 

long f_ConvDblToSingleArray (double double_array[4][1000], double single_array[3000], int max_index)

{
    long error = 0;

    int idx1 = 0;
    int idx2 = 0;
    int index = 0;

    for (idx1 = 0; idx1 < max_index; idx1++) {
        for (idx2 = 0; idx2 < max_index; idx2++) {
            single_array[index++] = double_array[idx1][idx2];
        }
    }

    return 0;
}

 

Message Edited by Roberto Bozzolo on 09-11-2009 09:18 AM


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 16 of 38
(1,801 Views)

C2664 is a Microsoft Visual Studio error.

 

by default, visual studio makes a difference between a file ending in .cpp and a file ending in .c: a .cpp file is compiled in C++ mode, which is a bit more strict on type and type conversions.

0 Kudos
Message 17 of 38
(1,797 Views)

im helping someone with this, it compiles in cvi, but in visual studio c++ it doesnt.

 

the person is trying to do it in c++

0 Kudos
Message 18 of 38
(1,788 Views)

i think i found the problem

 

 this what i was doing at first

 

long f_ConvDblToSingleArray ( double  *double_array[4][1000], double *single_array[3000] , int max_index );

 

        

        long q,u;

double* temp_data[4][3000];

double* meas[3000];

,

 

what what fix the error was i had to change it to

 

 

long f_ConvDblToSingleArray ( double *double_array[4][1000], double *single_array[3000] , int max_index );

        

        long q,u;

double temp_data[][1000];change this to a 1000

double meas[3000];

,

 

 

i dont know if that mean anything, i dont know how he's trying to apply the  q, and the u  , so i will send this to im today, and see what i help him

0 Kudos
Message 19 of 38
(1,782 Views)

Darnell:

 

Good job reading the error message (3000 vs. 1000).  Just like the last time, part of the information you needed to fix the problem was contained in the error message.

 

However, the solution you posted puzzles me.  You said

 

what what fix the error was i had to change it to

 

 

long f_ConvDblToSingleArray ( double *double_array[4][1000], double *single_array[3000] , int max_index );

        

        long q,u;

double temp_data[][1000];change this to a 1000

double meas[3000];

 

Your declaration of temp_data won't work.  To declare the array, you need to declare both the number of rows and the number of columns.

You're also back to one of your original problems with arrays of doubles vs. arrays of pointers to doubles.

 

Here's a little more background on how C and C++ use arrays with functions.

 

In C and C++, functions cannot change the values of the passed parameters.  If you want a function to change the value of a variable you need to pass, you pass the pointer to the variable, not the variable itself.  CVI does that with many of its library functions like GetCtrlVal().

 

int GetCtrlVal (int Panel_Handle, int Control_ID, void *Value);

 

You're not passing Value, you're passing a pointer to Value, so the function can update Value without affecting the passed parameter (a pointer to Value).

 

When you pass an array to a function, you are actually passing a pointer to the array, so you're not passing a potentially large block of memory to the function, you're just passing a pointer.  That means that any change your function makes to the array will be available after the function returns to the calling routine.

 

Now since you're passing a pointer, the array parameter declaration in your prototype doesn't need to fully specify the size of the array.  For single dimensional arrays, declaring the size of the array in the function parameter declaration is optional and most compilers ignore it.  For multidimensional array, in the function parameter declaration, declaring the number of rows is optional, but you need to declare the number of columns.

 

For example, your prototype

 

long f_ConvDblToSingleArray ( double *double_array[4][1000], double *single_array[3000] , int max_index );

 

could be written

 

long f_ConvDblToSingleArray ( double *double_array[][1000], double *single_array[] , int max_index );

 

If you take another look at the error message, you'll see that the number of rows in the function parameter is just shown as [], because that's how the compiler sees it within the function.

cannot convert parameter 1 from 'double [4][3000]' to 'double [][1000]'

So for passing multidimensional arrays, in the function parameter declarations you need to specify the number of columns,  but don't you need to specify the number of rows.  But as I said earlier, in the array variable declaration, you do need to specify both the number of rows and the number of columns.

 

Getting back to one of your original problems, the function and the calling statement need to agree on the data type being passed.  If your calling routine declares an array of doubles, you can't pass that to a function that's expecting an array of pointers to doubles.  In your "solution" code you posted and I included in this post, it looks like you're going back to that problem.  Review my earlier posts.  In both your calling routine as well as your function, you need to declare arrays of pointers to doubles or arrays of doubles.  You can't mix and match.

 

If your source data is actually an array of pointers, then change your calling routine to use an array of pointers and leave the called function parameter declarations as arrays of pointers.

 

If your source data is actually an array of doubles, but your called function (in the .cpp code) is already used by other apps and you don't want to change it, you need to create an array of pointers to doubles in your calling routine and stuff that array with the pointers of each element in the double array.  And then pass the new array of pointers to the .cpp code.

 

But if you can change the .cpp code, as I suggested earlier, I would do away with arrays of pointers, unless you understand a good reason to use them (and there may be a good reason I'm not thinking of).

Message Edited by Al S on 09-11-2009 09:57 AM
0 Kudos
Message 20 of 38
(1,770 Views)