NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/MEXSRC/read_icq4_mex5.c

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1 #include <math.h>
2 #include <stdio.h>
3 #include "mex.h"
4 #include "opnml_mex5_allocs.c"
5 #define BUFFER_SIZE 72
6
7 /************************************************************
8
9   ####     ##     #####  ######  #    #    ##     #   #
10  #    #   #  #      #    #       #    #   #  #     # #
11  #       #    #     #    #####   #    #  #    #     #
12  #  ###  ######     #    #       # ## #  ######     #
13  #    #  #    #     #    #       ##  ##  #    #     #
14   ####   #    #     #    ######  #    #  #    #     #
15
16 ************************************************************/
17
18
19 void mexFunction(int            nlhs,
20                  mxArray       *plhs[],
21                  int            nrhs,
22                  const mxArray *prhs[])
23 {
24
25 /* ---- read_icq4_mex will be called as :
26         [HMID, UMID, VMID, HOLD, UOLD, VOLD,...
27          ZMID,  ZOLD, UZMID ,VZMID, WZMID, ...
28          Q2MID, Q2LMID, TMPMID, SALMID]=read_icq4(icq4name,nn,nnv);
29        
30         I/O argument count has already been checked in the calling
31         routine, read_ucd.  The input filename will have to be
32         checked here, though.
33                                              ------------------------ */
34
35    double *temp;
36    double *temp1, *temp2, *temp3, *temp4, *temp5, *temp6;
37    double *temp7, *temp8, *temp9;
38    double *temp10, *temp11, *temp12,*temp13, *temp14, *temp15;
39
40    int nn,nnv,i,j;
41    int errflag,strlen,itrash,tcomp,ncomp,*ncompcomp;
42    char *icq4name, *line;
43    FILE *fp=NULL, *fopen();
44    
45 /* ---- extract input filename from first pointer to RHS 
46                               --------------------------------------- */ 
47    strlen=mxGetN(prhs[0])+1;
48    icq4name=mxCalloc(strlen,sizeof(char));
49    if (mxGetString(prhs[0],icq4name,strlen)==1)
50       fprintf(stderr,"Input filename string extraction failed in READ_ICQ4_MEX.");
51
52 /* get nn,nnv from RHS */
53    temp=mxGetPr(prhs[1]);
54    nn=(int)temp[0];
55    temp=mxGetPr(prhs[2]);
56    nnv=(int)temp[0];
57      
58 /* ---- Open UCD filename ------------------------------------------- */
59    if (!(fp = fopen(icq4name,"r"))){
60       fprintf(stderr,"Open of %s failed.\n",icq4name);
61       /* Allocate the return matricies as empty [] */
62       plhs[0]=mxCreateDoubleMatrix(0,0,mxREAL);
63       plhs[1]=mxCreateDoubleMatrix(0,0,mxREAL);
64       plhs[2]=mxCreateDoubleMatrix(0,0,mxREAL);
65       plhs[3]=mxCreateDoubleMatrix(0,0,mxREAL);
66       plhs[4]=mxCreateDoubleMatrix(0,0,mxREAL);
67       plhs[5]=mxCreateDoubleMatrix(0,0,mxREAL);
68       plhs[6]=mxCreateDoubleMatrix(0,0,mxREAL);
69       plhs[7]=mxCreateDoubleMatrix(0,0,mxREAL);
70       plhs[8]=mxCreateDoubleMatrix(0,0,mxREAL);
71       plhs[9]=mxCreateDoubleMatrix(0,0,mxREAL);
72       plhs[10]=mxCreateDoubleMatrix(0,0,mxREAL);
73       plhs[11]=mxCreateDoubleMatrix(0,0,mxREAL);
74       plhs[12]=mxCreateDoubleMatrix(0,0,mxREAL);
75       plhs[13]=mxCreateDoubleMatrix(0,0,mxREAL);
76       plhs[14]=mxCreateDoubleMatrix(0,0,mxREAL);
77       return;
78    }
79
80    line=mxCalloc(BUFFER_SIZE,sizeof(char));
81    for(i=0;i<6;i++)
82       fgets(line,BUFFER_SIZE,fp); 
83
84
85 /* ---- Allocate space for x,y,z ------------------------------------ */
86    plhs[0]=mxCreateDoubleMatrix(1,nn,mxREAL);
87    plhs[1]=mxCreateDoubleMatrix(1,nn,mxREAL);
88    plhs[2]=mxCreateDoubleMatrix(1,nn,mxREAL);
89    plhs[3]=mxCreateDoubleMatrix(1,nn,mxREAL);
90    plhs[4]=mxCreateDoubleMatrix(1,nn,mxREAL);
91    plhs[5]=mxCreateDoubleMatrix(1,nn,mxREAL);
92    plhs[6]=mxCreateDoubleMatrix(1,nn*nnv,mxREAL);
93    plhs[7]=mxCreateDoubleMatrix(1,nn*nnv,mxREAL);
94    plhs[8]=mxCreateDoubleMatrix(1,nn*nnv,mxREAL);
95    plhs[9]=mxCreateDoubleMatrix(1,nn*nnv,mxREAL);
96    plhs[10]=mxCreateDoubleMatrix(1,nn*nnv,mxREAL);
97    plhs[11]=mxCreateDoubleMatrix(1,nn*nnv,mxREAL);
98    plhs[12]=mxCreateDoubleMatrix(1,nn*nnv,mxREAL);
99    plhs[13]=mxCreateDoubleMatrix(1,nn*nnv,mxREAL);
100    plhs[14]=mxCreateDoubleMatrix(1,nn*nnv,mxREAL);
101
102    temp1= (double *) mxDvector(0,nn-1);
103    temp2= (double *) mxDvector(0,nn-1);
104    temp3= (double *) mxDvector(0,nn-1);
105    temp4= (double *) mxDvector(0,nn-1);
106    temp5= (double *) mxDvector(0,nn-1);
107    temp6= (double *) mxDvector(0,nn-1);
108    
109    for(i=0;i<nn;i++)
110       fscanf(fp,"%lf %lf %lf %lf %lf %lf",&temp1[i],&temp2[i],
111                                           &temp3[i],&temp4[i],
112                                           &temp5[i],&temp6[i]);
113
114    mxSetPr(plhs[0],temp1);
115    mxSetPr(plhs[1],temp2);
116    mxSetPr(plhs[2],temp3);
117    mxSetPr(plhs[3],temp4);
118    mxSetPr(plhs[4],temp5);
119    mxSetPr(plhs[5],temp6);
120
121    temp7= (double *) mxDvector(0,nn*nnv-1);
122    temp8= (double *) mxDvector(0,nn*nnv-1);
123    temp9= (double *) mxDvector(0,nn*nnv-1);
124    temp10= (double *) mxDvector(0,nn*nnv-1);
125    temp11= (double *) mxDvector(0,nn*nnv-1);
126    temp12= (double *) mxDvector(0,nn*nnv-1);
127    temp13= (double *) mxDvector(0,nn*nnv-1);
128    temp14= (double *) mxDvector(0,nn*nnv-1);
129    temp15= (double *) mxDvector(0,nn*nnv-1);
130
131    for(i=0;i<nn*nnv;i++)
132       fscanf(fp,"%lf %lf %lf %lf %lf %lf %lf %lf %lf",&temp7[i],&temp8[i],
133                                           &temp9[i],&temp10[i],
134                                           &temp11[i],&temp12[i],
135                                           &temp13[i],&temp14[i],&temp15[i]);
136    mxSetPr(plhs[6],temp7);
137    mxSetPr(plhs[7],temp8);
138    mxSetPr(plhs[8],temp9);
139    mxSetPr(plhs[9],temp10);
140    mxSetPr(plhs[10],temp11);
141    mxSetPr(plhs[11],temp12);
142    mxSetPr(plhs[12],temp13);
143    mxSetPr(plhs[13],temp14);
144    mxSetPr(plhs[14],temp15);
145
146    
147    fclose(fp);
148 /* No "frees" needed if arrays allocated with "mx" allocation routines */
149    return;
150 }
151 /*-----------------------------------------------------*
152  *                                                     *
153  *               ****  get_token  ****                 *
154  *                                                     *
155  * returns the next value in tline[] separated by a    *
156  * blank.                                              *
157  *-----------------------------------------------------*/
158
159 int get_token(char **tline, char *data,char  *control)
160 {
161
162   char *line, token[80], c;
163
164   int ntc;
165
166   c = 0;
167   line = *tline;
168
169   for (ntc = 0; c != '\n'; line++) {
170     if (((c  = *line) != ' ') && (c != '\n'))
171       token[ntc++] = c;
172     else if (ntc != 0) {
173       token[ntc] = '\0';
174       sscanf (token, control, data);
175       *tline = line;
176       break;
177       }
178     }
179
180   return (ntc);
181 }
Note: See TracBrowser for help on using the browser.