Computer Science Software, hardware, computational theory, cool peripherals, and emerging cybernetic technologies


Advertisement (please log in or register to remove this ad)
Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old 02-21-2008, 11:45 AM
sanctus's Avatar
Resident Diabolist
Points: 29,060, Level: 74 Points: 29,060, Level: 74 Points: 29,060, Level: 74
Activity: 5% Activity: 5% Activity: 5%
Hypography Staff Member
Administrator
 
Join Date: Mar 2004
Location: Geneva-Bern-Zürich, Switzerland
Posts: 2,447
Blog Entries: 1
sanctus is a name known to allsanctus is a name known to allsanctus is a name known to allsanctus is a name known to allsanctus is a name known to allsanctus is a name known to allsanctus is a name known to all
Using c code in Matlab...on xubuntu

I don't really like Matlab, but where I do civil service at the moment I have to use it. Luckily there is some extern c-code in it (at least it gets to almost acceptable speeds this way).

Now since there are strong security issues where I work I don't have admin rights on my machine, this implied that I installed Xubuntu today, which took me all day...
Now, to use the c-file you have to compile them out of Matlab via a comand
Code:
mex myfile.c
But before doing this you have to choose which compiler to use...I choose gcc (version 4.1.3 or 4.3.1 don't remember) also because the only available already installed.

The error I get is very strange because it says something like: "error: missing '(' or (...) before '/' token"


(...) stands for a part I don't remember now (I'm at home now and not at work)
and the C-code starts with some comments //

I think that there is something not installed in the gcc, but what is it?

Hope it was comprehensible
__________________
Administrator

A COUNTRY WITHOUT AN ARMY IS LIKE A FISH WITHOUT A BIKE!!!


I don't believe in god, but I do believe in what others call utopies.

Last edited by sanctus; 02-21-2008 at 11:48 AM.
Reply With Quote
Advertisement
  #2 (permalink)  
Old 02-21-2008, 06:23 PM
alexander's Avatar
Resident USSRian
Points: 69,669, Level: 100 Points: 69,669, Level: 100 Points: 69,669, Level: 100
Activity: 63% Activity: 63% Activity: 63%
Hypography Staff Member
Administrator
Gallery Curator
Dev Team Member
 
Join Date: May 2004
Location: Just before 0xAA55
Posts: 3,964
alexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant future
Send a message via AIM to alexander
Re: Using c code in Matlab...on xubuntu

need to see your code lol
__________________

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.
Reply With Quote
  #3 (permalink)  
Old 02-21-2008, 10:48 PM
sanctus's Avatar
Resident Diabolist
Points: 29,060, Level: 74 Points: 29,060, Level: 74 Points: 29,060, Level: 74
Activity: 5% Activity: 5% Activity: 5%
Hypography Staff Member
Administrator
 
Join Date: Mar 2004
Location: Geneva-Bern-Zürich, Switzerland
Posts: 2,447
Blog Entries: 1
sanctus is a name known to allsanctus is a name known to allsanctus is a name known to allsanctus is a name known to allsanctus is a name known to allsanctus is a name known to allsanctus is a name known to all
Re: Using c code in Matlab...on xubuntu

So you don't think it is a compiler issue?

Because on windows it compiled fine so I don't think it is a code problem, but anyway here is the code

Code:
/* : 1.1 $ */
// Automatically generated by Matlab AppWizard version 1.0
//
// This is the gateway routine for a MATLAB Math/Graphics Library-based
// C MATLAB MEX File.


#include "mex.h"
#include <math.h>
#define K 10.0
#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))
#define SGN(A) ((A)>0?1.:-1.)
#define ABS(A) ((A)>0?(A):-(A))

// Computes |grad u| div[grad(u)/|grad(u)|]
//--------------------------------------------
void 	giveGradient(double *GpX,double *GpY,double *GpZ,
                    double *GpXpY,double *GpXmY,
                    double *GpYpZ,double *GmYpZ,double *GpXpZ,double *GmXpZ,
                    double *GpXpYpZ,double *GmXpYpZ,double *GpXmYpZ,double *GmXmYpZ,
                    double *Gradient,double *Laplacian, double *In, double *MASK, int* dim)
{	
	int ix,iy,iz;
	int rows, pagesize;
    int index,pX,pY,pZ;
    int pXpY,pXmY,pYpZ,mYpZ,pXpZ,mXpZ;
    int pXpYpZ, mXpYpZ,pXmYpZ, mXmYpZ;
    double cnst1 = 1.0/sqrt(2);
    double cnst2 = 1.0/sqrt(3);
    
    rows = dim[0];
	pagesize = dim[0]*dim[1];
    
	for(ix=1;ix<dim[0]-1;ix++) 
		for(iy=1;iy<dim[1]-1;iy++) 
			for(iz=1;iz<dim[2]-1;iz++) 
			{
				index   = ix + iy*rows + iz*pagesize;
                if(MASK[index]==0)
                    Gradient[index]=0;
                else
                {
                    // One connected pixels
                    pX = index+1;
                    pY = index+rows;
                    pZ = index+pagesize;
                    GpX[index] = MASK[pX]*(In[pX]-In[index]);
                    GpY[index] = MASK[pY]*(In[pY]-In[index]);
                    GpZ[index] = MASK[pZ]*(In[pZ]-In[index]);
                    
                    Gradient[index] = GpX[index]*GpX[index] + GpY[index]*GpY[index]  + GpZ[index]*GpZ[index];

                    // Two connected pixels

                    pXpY = index+rows+1;
                    pXmY = index-rows+1;
                    pYpZ = index+pagesize+rows;
                    mYpZ = index+pagesize-rows;
                    pXpZ = index+pagesize+1;
                    mXpZ = index+pagesize-1;

                    GpXpY[index] = cnst1*MASK[pXpY]*(In[pXpY]-In[index]);
                    GpXmY[index] = cnst1*MASK[pXmY]*(In[pXmY]-In[index]);
                    GpYpZ[index] = cnst1*MASK[pYpZ]*(In[pYpZ]-In[index]);
                    GmYpZ[index] = cnst1*MASK[mYpZ]*(In[mYpZ]-In[index]);
                    GpXpZ[index] = cnst1*MASK[pXpZ]*(In[pXpZ]-In[index]);
                    GmXpZ[index] = cnst1*MASK[mXpZ]*(In[mXpZ]-In[index]);

                    Gradient[index] += GpXpY[index]*GpXpY[index] + GpXmY[index]*GpXmY[index]  + GpYpZ[index]*GpYpZ[index];
                    Gradient[index] += GmYpZ[index]*GmYpZ[index] + GpXpZ[index]*GpXpZ[index]  + GmXpZ[index]*GmXpZ[index];

                    // Three connected pixels

                    pXpYpZ = index+rows+1+pagesize;
                    mXpYpZ = index+rows-1+pagesize;
                    pXmYpZ = index-rows+1+pagesize;
                    mXmYpZ = index-rows-1+pagesize;
                    

                    GpXpYpZ[index] = cnst2*MASK[pXpYpZ]*(In[pXpYpZ]-In[index]);
                    GmXpYpZ[index] = cnst2*MASK[mXpYpZ]*(In[mXpYpZ]-In[index]);
                    GpXmYpZ[index] = cnst2*MASK[pXmYpZ]*(In[pXmYpZ]-In[index]);
                    GmXmYpZ[index] = cnst2*MASK[mXmYpZ]*(In[mXmYpZ]-In[index]);
                    Gradient[index] += GpXpYpZ[index]*GpXpYpZ[index] + GmXpYpZ[index]*GmXpYpZ[index];
                    Gradient[index] += GpXmYpZ[index]*GpXmYpZ[index] + GmXmYpZ[index]*GmXmYpZ[index];
                }
               
            }

    for(ix=1;ix<dim[0]-1;ix++) 
		for(iy=1;iy<dim[1]-1;iy++) 
			for(iz=1;iz<dim[2]-1;iz++) 
			{
                // One connected pixels
				index   = ix + iy*rows + iz*pagesize;
                pX = index-1;
                pY = index-rows;
                pZ = index-pagesize;
                Laplacian[index]  = GpX[pX]-GpX[index];
                Laplacian[index] += GpY[pY]-GpY[index];
                Laplacian[index] += GpZ[pZ]-GpZ[index];
                
                // Two connected pixels
                pXpY = index-rows-1;
                pXmY = index+rows-1;
                pYpZ = index-pagesize-rows;
                mYpZ = index-pagesize+rows;
                pXpZ = index-pagesize-1;
                mXpZ = index-pagesize+1;
                
                Laplacian[index] += cnst1*(GpXpY[pXpY]-GpXpY[index]);
                Laplacian[index] += cnst1*(GpXmY[pXmY]-GpXmY[index]);
                Laplacian[index] += cnst1*(GpYpZ[pYpZ]-GpYpZ[index]);
                Laplacian[index] += cnst1*(GmYpZ[mYpZ]-GmYpZ[index]);
                Laplacian[index] += cnst1*(GpXpZ[pXpZ]-GpXpZ[index]);
                Laplacian[index] += cnst1*(GmXpZ[mXpZ]-GmXpZ[index]);
                
                // Three connected pixels

                    
                pXpYpZ = index-rows-1-pagesize;
                mXpYpZ = index-rows+1-pagesize;
                pXmYpZ = index+rows-1-pagesize;
                mXmYpZ = index+rows+1-pagesize;
                    
                Laplacian[index] += cnst2*(GpXpYpZ[pXpYpZ]-GpXpYpZ[index]);
                Laplacian[index] += cnst2*(GmXpYpZ[mXpYpZ]-GmXpYpZ[index]);
                Laplacian[index] += cnst2*(GpXmYpZ[pXmYpZ]-GpXmYpZ[index]);
                Laplacian[index] += cnst2*(GmXmYpZ[mXmYpZ]-GmXmYpZ[index]);
                 
             }
    
    
}





void mexFunction(
	int nlhs,              // Number of left hand side (output) arguments
	mxArray *plhs[],       // Array of left hand side arguments
	int nrhs,              // Number f right hand side (input) arguments
	const mxArray *prhs[]  // Array of right hand side arguments
	                    )
{
	int *temp;
	int dim[3];
	double *Gradient, *Laplacian, *In, *MASK;
    double *GpX, *GpY, *GpZ;
	double *GpXpY, *GpXmY, *GpYpZ,*GmYpZ, *GpXpZ, *GmXpZ;
	double *GpXpYpZ, *GmXpYpZ, *GpXmYpZ,*GmXmYpZ;	

	   
if (nrhs!= 2 || nlhs!=15)
	   mexErrMsgTxt("Usage: [Gradient,Laplacian,GpX,GpY,GpZ,GpXpY,GpXmY,GpXmY,GmYpZ,GpXpZ,GmXpZ]=giveGradient1(In,Mask)");

    temp = mxGetDimensions(prhs[0]);
   /* printf("number of temp dimensions = %d n",temp); ssssssssss commented because I want speed
     printf("number of temp1 dimensions = %d n",temp[0]);
      printf("number of temp2 dimensions = %d n",temp[1]);
       printf("number of temp3 dimensions = %d n",temp[2]);*/
    dim[0] = temp[0];dim[1] = temp[1];dim[2] = temp[2];

	plhs[0] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	Gradient  = mxGetPr(plhs[0]);
	plhs[1] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	Laplacian  = mxGetPr(plhs[1]);
	
    plhs[2] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	GpX  = mxGetPr(plhs[2]);
	plhs[3] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	GpY  = mxGetPr(plhs[3]);
	plhs[4] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	GpZ  = mxGetPr(plhs[4]);

    plhs[5] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	GpXpY  = mxGetPr(plhs[5]);
	plhs[6] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	GpXmY  = mxGetPr(plhs[6]);
	plhs[7] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	GpYpZ  = mxGetPr(plhs[7]);
    plhs[8] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	GmYpZ  = mxGetPr(plhs[8]);
	plhs[9] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	GpXpZ  = mxGetPr(plhs[9]);
	plhs[10] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	GmXpZ  = mxGetPr(plhs[10]);
    
    plhs[11] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	GpXpYpZ  = mxGetPr(plhs[11]);
    plhs[12] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	GmXpYpZ  = mxGetPr(plhs[12]);
	plhs[13] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	GpXmYpZ  = mxGetPr(plhs[13]);
	plhs[14] = mxCreateNumericArray(3, dim, mxDOUBLE_CLASS, mxREAL);
	GmXmYpZ  = mxGetPr(plhs[14]);
 
    In  = mxGetPr(prhs[0]);
	MASK = mxGetPr(prhs[1]);
	
    giveGradient(GpX,GpY,GpZ,GpXpY,GpXmY,GpYpZ,GmYpZ,GpXpZ,GmXpZ,GpXpYpZ,GmXpYpZ,GpXmYpZ,GmXmYpZ,Gradient,Laplacian,In,MASK,dim);
   }
And the errors are
Code:
>> mex givegradient.c
Warning: You are using gcc version "4.1.2".  The earliest gcc version supported
with mex is "3.4.0".  The latest version tested for use with mex is "3.4.5".
To download a different version of gcc, visit http://gcc.gnu.org 
givegradient.c:2: error: expected identifier or ‘(’ before ‘/’ token
givegradient.c:16: error: expected identifier or ‘(’ before ‘/’ token
givegradient.c:142: error: expected declaration specifiers or ‘...’ before ‘/’ token
givegradient.c:143: error: expected declaration specifiers or ‘...’ before ‘/’ token
givegradient.c:144: error: expected declaration specifiers or ‘...’ before ‘/’ token
givegradient.c:147: error: conflicting types for ‘mexFunction’
/usr/local/matlab/extern/include/mex.h:148: error: previous declaration of ‘mexFunction’ was here
givegradient.c: In function ‘mexFunction’:
givegradient.c:156: error: ‘nrhs’ undeclared (first use in this function)
givegradient.c:156: error: (Each undeclared identifier is reported only once
givegradient.c:156: error: for each function it appears in.)
givegradient.c:159: error: ‘prhs’ undeclared (first use in this function)
givegradient.c:159: warning: assignment discards qualifiers from pointer target type
givegradient.c:166: error: ‘plhs’ undeclared (first use in this function)

    mex: compile of 'givegradient.c' failed.

??? Error using ==> mex
Unable to complete successfully.
__________________
Administrator

A COUNTRY WITHOUT AN ARMY IS LIKE A FISH WITHOUT A BIKE!!!


I don't believe in god, but I do believe in what others call utopies.
Reply With Quote
  #4 (permalink)  
Old 02-21-2008, 10:55 PM
Buffy's Avatar
Resident Slayer
Points: 120,420, Level: 100 Points: 120,420, Level: 100 Points: 120,420, Level: 100
Activity: 26% Activity: 26% Activity: 26%
Hypography Staff Member
Administrator
 
Join Date: Jan 2005
Location: Sunnydale, CA
Posts: 6,415
Buffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond reputeBuffy has a reputation beyond repute
Re: Using c code in Matlab...on xubuntu

Um, it might be that because the file is a ".c" file, that gcc thinks its ANSI C, which does not recognize "//" as a comment line (although Microsoft C++ might!).

I'd try changing the extension on the source file to ".cpp" or else edit your "//" lines to "/* blah */"....

I haven't touched gcc in years, so I may have no idea of what I'm talking about!

Syntactically correct,
Buffy
__________________
"If you do not agree with anything I say, I'll not only retract it, but deny under oath that I ever said it!"
__________________________________________________ ______________-- Tom Lehrer

"What, you guys couldn’t even wear one of your tuxedo t-shirts? I mean, I know each one of you have one."


Forum Administrator
Hypography Science Forums - Science for Boys and Girls! Its not for nothing that we hang out here.
Reply With Quote
  #5 (permalink)  
Old 02-22-2008, 01:00 AM
sanctus's Avatar
Resident Diabolist
Points: 29,060, Level: 74 Points: 29,060, Level: 74 Points: 29,060, Level: 74
Activity: 5% Activity: 5% Activity: 5%
Hypography Staff Member
Administrator
 
Join Date: Mar 2004
Location: Geneva-Bern-Zürich, Switzerland
Posts: 2,447
Blog Entries: 1
sanctus is a name known to allsanctus is a name known to allsanctus is a name known to allsanctus is a name known to allsanctus is a name known to allsanctus is a name known to allsanctus is a name known to all
Re: Using c code in Matlab...on xubuntu

Thanks Buffy, it works fine with *.cc or *.cpp. This helped me a lot!
__________________
Administrator

A COUNTRY WITHOUT AN ARMY IS LIKE A FISH WITHOUT A BIKE!!!


I don't believe in god, but I do believe in what others call utopies.
Reply With Quote
  #6 (permalink)  
Old 02-22-2008, 04:51 AM
alexander's Avatar
Resident USSRian
Points: 69,669, Level: 100 Points: 69,669, Level: 100 Points: 69,669, Level: 100
Activity: 63% Activity: 63% Activity: 63%
Hypography Staff Member
Administrator
Gallery Curator
Dev Team Member
 
Join Date: May 2004
Location: Just before 0xAA55
Posts: 3,964
alexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant futurealexander has a brilliant future
Send a message via AIM to alexander
Re: Using c code in Matlab...on xubuntu

yeah, its because you used gcc, gcc by default thinks that any file passed to it as a C file, unless otherwise specified, that is why g++ was created, because unlike gcc, g++ thinks that any file passed to it is cpp by default.

you may want to link your mex to g++ vs gcc... you could make a make file too

here is something that may be of help: Tutorial on MATLAB executables (MEX files)
__________________

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.
Reply With Quote
Reply

Bookmarks
Advertisement


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
New code discovered in DNA C1ay News in Brief 1 07-25-2006
Break the code! ronthepon Watercooler 25 07-21-2006
URL code tag test Turtle Test forum 7 07-15-2006
Standard map in matlab sanctus Computer Science 5 05-03-2005
unbreakable code rileyj Physics and Mathematics 0 04-10-2004

» Advertisement
» Latest Science News
Powering the planet
imageNSF-funded Chemical Bonding Center project provides a new approach for harnessing the sun's energy
Read » | 0 comments

DNA Barcodes: Are They Always Accurate?
imageBrigham Young University (BYU) study questions the reliability iof some results.
Read » | 0 comments

Make Contact: Ask an Astronaut on the Space Station a Question
imageAstronaut Greg Chamitoff, aboard the International Space Station 220 miles above Earth, is ready to take your questions.
Read » | 0 comments
» Current Poll
Do U text?
No - 25.00%
6 Votes
Yes; < 6 messages/day - 50.00%
12 Votes
Yes; 6-15 messages/day - 12.50%
3 Votes
Yes; 16 to 43 messages/day - 8.33%
2 Votes
Yes; > 43 messages/day - 4.17%
1 Vote
What? - 0%
0 Votes
Total Votes: 24
You may not vote on this poll.
» Random Social Groups
Photographers
10 members | 66 pictures
Environmental Harvest
10 members | 11 pictures
Guitarists
4 members | 0 pictures
The Prophesy: Crew Members
6 members | 0 pictures
Hypography jugglers
5 members | 7 pictures
» View All Groups
Advertisement

All times are GMT -8. The time now is 05:21 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Copyright © 2000-2008 Hypography
Part of the Hypography - Science for Everyone Network

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67