Go Back   Science Forums
View Single Post
Old 02-21-2008   #3 (permalink)
sanctus's Avatar
sanctus
Resident Diabolist


Location:
Geneva-Bern-Zürich, Switzerland;Oslo,Norway
 
sanctus has a brilliant futuresanctus has a brilliant futuresanctus has a brilliant futuresanctus has a brilliant futuresanctus has a brilliant futuresanctus has a brilliant futuresanctus has a brilliant futuresanctus has a brilliant future
 



Not Ranked  0 score     
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
 
» Advertisement
» Current Poll
Who's the sexiest man alive? Johnny Depp or Robert Pattinson?
Johnny Depp - 27.27%
3 Votes
Robert Pattinson - 0%
0 Votes
Someone else (please specify) - 45.45%
5 Votes
I'm too macho to think a guy is sexy - 27.27%
3 Votes
Total Votes: 11
You may not vote on this poll.


All times are GMT -8. The time now is 02:23 AM.

Hypography?

Hypography [n.]: A combination of "hyperlink" and "bibliography" - ie, a list of links to electronic documents. Comparable to discography and bibliography, but not cartography.

We have been online since May 2000, and aim to be the best place to find and share science-related content of all kinds.

Share the love!

Please add more science to your life. Use our RSS feeds on your blog, your portal, or your favorite feedreader!


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000-2009 Hypography
Part of the Hypography - Science for Everyone Network