using mex for C

3 visualizaciones (últimos 30 días)
nomad nomad
nomad nomad el 3 de Mayo de 2011
Hello,
I have a program in C that works and I would like to run MatLab in order to process data quickly and immediately.
I tried the following syntax, and Matlab by typing mex COSENO.C, it gives me:
C:\PROGRA~1\MATLAB\R2008A\BIN\MEX.PL: Error: 'COSENO.C' not found.
??? Error using ==> mex at 207 Unable to complete successfully.
Où je dois mettre le fichier CENTRE.C.et est ce qu'il y a d'autres changements à faire dans le programme.
#include "mex.h"
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]) {
# include <math.h>
# include <conio.h>
# include <stdlib.h>
# include <stdio.h>
# include <alloc.h>
# include <io.h>
float disco (char fichero[], int nfil, int ncol, int control,
char huge *a, int tipo);
void ordena ( float huge *mod, long huge *orden, long int nd );
void main(void)
{
char arch[30],arch0[30],arch1[30],archi[30];
float huge *i;
float huge *i1;
float huge *masque;
long huge *qq;
float pi, th, sumpos, sumneg, delta;
int dim, j;
long n2, n1, cont=0;
long int p1, p2, p3, p4;
/*pi=3.141592654;*/
clrscr();
gotoxy(2,2);
printf(" dimension du fichier: ");
scanf("%d",&dim);
gotoxy(2,4);
n2=(long)dim * (long)dim ;
p1 = 0L; p2 = (long)(dim/2);
p3 = (long)dim* p2;
p4 = p3 + p2;
i=farcalloc((unsigned)n2,4);
i1=farcalloc((unsigned)n2,4);
masque=farcalloc((unsigned)n2,4);
qq=farcalloc(n2,sizeof(long int));
if ( i== NULL || i1== NULL || qq==NULL || masque==NULL){
printf ( "\n\a\a no hay memoria ");
goto fin;
}
bik:
clrscr();
gotoxy(2,4);
printf(" la valeur seuille th: ");
scanf("%f",&th);
clrscr();
gotoxy(2,8);
printf(" donner le nom de la phase a analyser: ");
scanf("%s",&arch0);
j=disco(arch0,dim,dim,1,(char*)i,4);
if(j!=1) goto fin;
gotoxy(2,10);
printf(" donner l'amplitude de l'objet a discriminer: ");
scanf("%s",&arch1);
j=disco(arch1,dim,dim,1,(char*)i1,4);
if(j!=1) goto fin;
gotoxy(2,12);
printf(" donner le nom du masque optimal: ");
scanf("%s",&archi);
for( n1=0; n1<n2; n1++ ){
i1[n1] *= (float)cos( (double)i[n1] );
masque[n1] = 1;
}
masque[p1] = masque[p2] = masque[p3] = masque[p4] = 0;
i1[p1] = i1[p2] = i1[p3] = i1[p4] = 0;
ordena ( i1, qq, n2 );
n1=0; sumpos = sumneg = 0;
while (i1[ qq[n1] ] >0) {
sumpos += i1[ qq[n1] ];
n1++;
}
for(; n1<n2; n1++) sumneg += i1[ qq[n1] ];
delta = sumpos + sumneg;
if( delta < 0 && fabs((double)delta) > th ) {
n1=n2-1;
while ( delta < 0 && fabs((double)delta) > th ){
masque[ qq[n1] ] = 0;
delta -= i1[ qq[n1] ];
n1--; cont++;
delta -= i1[ qq[n1] ];
n1--; cont++;
}
} else if ( delta > th ){
n1=0;
while ( delta > th ){
masque[ qq[n1] ] = 0;
delta -= i1[ qq[n1] ];
n1++; cont++;
delta -= i1[ qq[n1] ];
n1++; cont++;
}
}
clrscr();
gotoxy(10, 10);
printf("Number of blocked pixels = %ld, %f",
cont+4L, (float)(cont+4L)/(float)n2);
gotoxy(10, 14);
printf("threshold = %f, delta = %f", th, delta);
j=disco(archi,dim,dim,2,(char*)masque,4);
if(j!=1) goto fin;
fin:
farfree((void far*)i);
farfree((void far *)i1);
farfree((void far *)masque);
farfree((void far *)qq);
}
/***************************************************/
/* ORDENA */
/* classés du plus grand au plus petit des éléments*/
/* vecteur mod[]. L'ordre des éléments*/
/* donnée dans la matrice orden[]. orden[0] nous donne*/
/* élément m maximum, orden[1] ce qui suit, ... */
/* orden[nd-1] l'élément m de petites*/
/***************************************************/
void ordena ( float huge *mod, long huge *orden, long int nd )
{
long kac, kfin, k, k1, o, p, p1;
kfin = nd-1;
do {
k = -1; kac = 0; k1 = 0;
do {
k++; k1++;
if ( mod[ orden[k] ] < mod[ orden[k1] ] ){
o = orden[k]; orden[k] = orden[k1]; orden[k1] = o;
kac = k1; p = k; p1 = k-1;
while ( p1>0 ) {
if( mod[orden[p]] > mod[orden[p1]] ){
o = orden[p]; orden[p] = orden[p1]; orden[p1] = o;
p--; p1--;
} else p1 =0;
};
}
} while ( k1 < kfin );
kfin = kac; printf("\n %ld", kfin);
} while ( kfin > 1 );
}
/*********************************************************************\
* *
* *
* DISCO.C *
* ======= *
* *
* Numéros, le transfert de routine de tout type de*
* mémoire variable sur un disque ou un disque*
* à une variable de la mémoire. *
* *
* --------- *
* *
* Paramètre: *
* *
* fichero - Nom du fichier disque. *
* nfil, ncol - Nombre de lignes et de colonnes. *
* control - 1 pour lire le fichier. *
* 2 d'enregistrer dans le fichier. *
* a - pointeur vers une variable. *
* tipo - nombre d'octets par élément variable. *
* *
* *
\*********************************************************************/
float disco (char fichero[], int nfil, int ncol, int control,
char huge *a, int tipo)
{
long int n, cont, ng;
int unidad, j, cociente, resto;
if (control == 1) {
if ((unidad = open (fichero,1)) == -1) {
return (-1);
}
cont = (long) nfil * (long) ncol * tipo;
resto = cont % 32768;
cociente = cont / 32768;
for (j = 0, n = 0; j < cociente; j++,n += 32768)
_read (unidad, (char*)&a[n], 32768);
_read (unidad, (char*)&a[n], resto);
close (unidad);
return (1);
}
if (control == 2) {
if ((unidad = creat (fichero, 200)) == -1) {
return (-1);
}
cont = (long) nfil * (long) ncol * tipo;
resto = cont % 32768;
cociente = cont / 32768;
ng = 0;
for (j = 0, n = 0; j < cociente; j++, n += 32768)
ng = ng + (unsigned) _write (unidad, (char*)&a[n], 32768);
ng = ng + (unsigned) _write (unidad, (char*)&a[n], resto);
if (ng != cont) {
return (0);
}
close (unidad);
return (1);
}
return (0);
}
}

Respuestas (4)

Jan
Jan el 3 de Mayo de 2011
Your C-file does not contain the function "mexFunction", but ou need one as gateway. But this does not explain why "mex CENTRE.C" searches for the file "COSENO.C". What is "COSENO.C"?
  2 comentarios
Jan
Jan el 3 de Mayo de 2011
Is the file "COSENO.C" in the current folder?!
Eric Moore
Eric Moore el 15 de Mayo de 2011
I think it does, it looks like he's taken his working C program and placed it inside of the { } defining the body of the mexFunction function.

Iniciar sesión para comentar.


Matt Fig
Matt Fig el 3 de Mayo de 2011
Is the name of your file saved on disk as COSENO.C (capitalized and all)?

nomad nomad
nomad nomad el 3 de Mayo de 2011
I'm wrong, I meant by typing COSENO.C.
  1 comentario
Kaustubha Govind
Kaustubha Govind el 3 de Mayo de 2011
When you type the following at the MATLAB prompt:
>> !cd
Does it return the same path as the current directory in MATLAB?

Iniciar sesión para comentar.


nomad nomad
nomad nomad el 3 de Mayo de 2011
it gives me this way:
C:\Users\Adil\Documents\MATLAB
  2 comentarios
Matt Fig
Matt Fig el 3 de Mayo de 2011
Please respond to answers by using the comments, not by posting multiple new 'answers' which do not actually answer the original question...
Kaustubha Govind
Kaustubha Govind el 4 de Mayo de 2011
Is "C:\Users\Adil\Documents\MATLAB" where your source file is present? If yes, please paste the response of:
>> mex -v COSENO.C
Also, like Matt Fig previously asked - is your MEX-file really saved as COSENO.C?

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by