Path: news.mathworks.com!not-for-mail
From: "basudha pradhan" <lucky_faith_911@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: reading binary file from mexFunction
Date: Wed, 12 Sep 2007 20:42:36 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 53
Message-ID: <fc9ivs$odj$1@fred.mathworks.com>
References: <fc1fri$au3$1@fred.mathworks.com> <fc1r8j$iql$1@fred.mathworks.com> <fc6kvd$1ul$1@fred.mathworks.com> <muymyvtnkj8.fsf@G99-Boettcher.llan.ll.mit.edu> <fc7ai3$hu8$1@fred.mathworks.com> <muyr6l4m1rn.fsf@G99-Boettcher.llan.ll.mit.edu>
Reply-To: "basudha pradhan" <lucky_faith_911@hotmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1189629756 25011 172.30.248.38 (12 Sep 2007 20:42:36 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 12 Sep 2007 20:42:36 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1088565
Xref: news.mathworks.com comp.soft-sys.matlab:428181


Thanks Peter. It works now. That mex function was for 
decoder. I have mex function for encoder . The encoder runs 
ok in C but when i call it from matlab, the encoded file is 
not right. So i am guessing my mex function is bad. 

input to the mex function is char array(input_buf). then it 
call C subroutine where it pass this input_buf and buflen
(length of input). C subroutine process the input and write 
the output to a file. So there is no output variable for 
mex function. this is what i tried. 

void mexFunction(int nlhs, mxArray *plhs[],
                 int nrhs, const mxArray *prhs[])
{
   char *input_buf; 
   int buflen;
   int status;  
     
   /* Check for proper number of arguments. */
  if (nrhs != 1) 
    mexErrMsgTxt("One input required.");
  
    
  /* Input must be a string. */
  if (mxIsChar(prhs[0]) != 1)
    mexErrMsgTxt("Input must be a string.");

  /* Input must be a row vector. */
  if (mxGetM(prhs[0]) != 1)
    mexErrMsgTxt("Input must be a row vector.");
    
  /* Get the length of the input string. */
  buflen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;

  /* Allocate memory for input strings. */
  input_buf = mxCalloc(buflen, sizeof(char));
  
  /* Copy the string data from prhs[0] into a C string 
   * input_buf. */
  status = mxGetString(prhs[0], input_buf, buflen);
  if (status != 0) 
    mexWarnMsgTxt("Not enough space. String is 
truncated.");    
      
    /* Call the C subroutine. */
  MQ_enc(input_buf, buflen);
  mxFree(input_buf);
}

Your suggestions would be greatly appreciated.

Thanks
~Basudha