13a14
> #include "/home/noio/programs/codas3/include/matfile.h"
22c23
< #define MASK            100000
---
> #define MASK            65535
42c43
<   char *filename;
---
>   char filename[1000];
44c45
<   float *buffer;     /******* store all the data read from the input file ***/
---
>   unsigned short int *buffer;     /******* store all the data read from the input file ***/
48c49
<   int i,j, x1, x2, y1, y2, x_range, y_range, n, m; 
---
>   int i,j, x1, x2, y1, y2, x_range, y_range, n, m, k; 
53,56d53
< /*  if(nrhs < 4){
<     mexErrMsgTxt("Need greater than 4 input arguments. Please input [latmin, latmax, lonmin, lonmax, m, n]");
<   } 
< */
58c55,56
<   filename = m2s(prhs[0]);
---
>   if(mxGetString(prhs[0], filename, 1000))
>     mexErrMsgTxt("Error in the filename");
112c110
<   if(!(buffer=(float *)malloc((y2-y1+1) * NX * sizeof(float)))){
---
>   if(!(buffer=(unsigned short int *)malloc((y2-y1+1) * NX * sizeof(unsigned short int)))){
116c114
<   if(fseek(infile, y1*NX*sizeof(float), 0) == -1){
---
>   if(fseek(infile, (y1+1)*NX*sizeof(unsigned short int), 0) == -1){
119,120c117,118
<   fread((char *)buffer, (y2-y1+1) * NX * sizeof(float), 1, infile);
<   
---
>   fread((char *)buffer, (y2-y1+1) * NX * sizeof(unsigned short int), 1, infile);
> /*  mexPrintf("%d %d\n", buffer[0], buffer[1]);*/
125,126c123,124
< 
<   for(j=0;j<x_range;j++)
---
>   k=0;
> /*  for(j=0;j<x_range;j++)
129c127
< 	*pr2 = -1.0;
---
> 	pr2[k] = -1.0;
131,132c129,130
< 	*pr2 = *(buffer + i * m * NX + x1+j*n);
<       pr2++;
---
> 	pr2[k] = buffer[i * m * NX + x1+j*n];
>       k++;
134c132,139
<   
---
>   */
> 
>   for(j=0;j<x_range;j++)
>     for(i=0;i<y_range;i++){
>       tonan_d(&pr2[k], &buffer[i*m*NX+x1+j*n]);
>       k++;
>     }
> 
142a148
> 
164a171,187
> 
> void tonan_d(dest, source)
> double *dest;
> unsigned short *source;
> {
>    int i;
>    union { double d; long l[2]; } NaN;
> 
>    NaN.l[0] = NaN_d_0;
>    NaN.l[1] = NaN_d_1;
> 
> /*mexPrintf("here %d \n", *source); */
>    *dest =  (*source < MASK) ? *source : NaN.d; 
> 
> }
> 
> 
