source: issm/trunk-jpl/src/modules/KMLMeshWrite/KMLMeshWrite.cpp@ 13236

Last change on this file since 13236 was 13236, checked in by Mathieu Morlighem, 13 years ago

CHG: preparing files for python inclusion

File size: 4.9 KB
Line 
1/*\file KMLMeshWrite.c
2 *\brief: KML mesh writer module.
3 */
4#include "./KMLMeshWrite.h"
5
6void KMLMeshWriteUsage(void){/*{{{*/
7 _pprintLine_("KMLMeshWrite - KML mesh writer module:");
8 _pprintLine_("");
9 _pprintLine_(" This module writes the mesh of a model as KML polygons into the specified KML file.");
10 _pprintLine_("");
11 _pprintLine_(" Usage:");
12 _pprintLine_(" ierror=KMLMeshWrite(name,notes,elem,nodecon,lat,long,part,data,cmap,kmlfile);");
13 _pprintLine_("");
14 _pprintLine_(" name model name (string, may be empty)");
15 _pprintLine_(" notes model notes (string or cell array of strings, may be empty)");
16 _pprintLine_(" elem elements (double array)");
17 _pprintLine_(" nodecon nodal connectivity array (double array, may be empty)");
18 _pprintLine_(" lat nodal latititudes (double vector)");
19 _pprintLine_(" long nodal longitudes (double vector)");
20 _pprintLine_(" part nodal partitions (double vector, may be empty)");
21 _pprintLine_(" data nodal or element data (double vector, may be empty)");
22 _pprintLine_(" cmap color map (double nx3 array, may be empty)");
23 _pprintLine_(" kmlfile KML file name (string)");
24 _pprintLine_("");
25 _pprintLine_(" ierror error flag (double, non-zero for error)");
26 _pprintLine_("");
27 _pprintLine_(" Example:");
28 _pprintLine_(" KMLMeshWrite(md.name,md.notes,md.elements,md.nodeconnectivity,md.lat,md.long,md.part,md.fm_criterion,options.cmap,filekml);");
29 _pprintLine_("");
30}/*}}}*/
31WRAPPER(KMLMeshWrite){
32
33 int i,j,nnodes=0,verbose=1;
34
35 /*input: */
36 char* name=NULL;
37 char* notes=NULL;
38 char* notes2=NULL;
39 const mxArray* notesi;
40 mwIndex nindex;
41 int* elem=NULL;
42 int melem=0,nelem=0;
43 int* nodecon=NULL;
44 int mncon=0,nncon=0;
45 double* lat=NULL;
46 int mlat=0,nlat=0,llat=0;
47 double* lng=NULL;
48 int mlng=0,nlng=0,llng=0;
49 int nparts=0;
50 int* part=NULL;
51 int mprt=0,nprt=0,lprt=0;
52 double* data=NULL;
53 int mdata=0,ndata=0;
54 double* cmap=NULL;
55 int mcmap=0,ncmap=0;
56 char* filnam=NULL;
57 FILE* fid=NULL;
58 Options* options=NULL;
59
60 /* output: */
61 int ierror=0;
62
63 /*Boot module: */
64 MODULEBOOT();
65
66 /*checks on arguments on the matlab side: */
67 if (nlhs > NLHS) {
68 KMLMeshWriteUsage(); _error_("KMLMeshWrite usage error");
69 }
70 if (nrhs < NRHS) {
71 KMLMeshWriteUsage(); _error_("KMLMeshWrite usage error");
72 }
73
74 /*Input datasets: */
75 FetchData(&name,NAME);
76
77/* notes is typically a cell array of character strings */
78 if (mxIsCell(NOTES)) {
79 for (nindex=0; nindex<mxGetNumberOfElements(NOTES); nindex++) {
80 notesi=mxGetCell(NOTES,nindex);
81 if (notesi && mxIsChar(notesi) && mxGetNumberOfElements(notesi)) {
82 if (!notes) {
83 notes=xNew<char>(mxGetNumberOfElements(notesi)+1);
84 mxGetString(notesi,notes,mxGetNumberOfElements(notesi)+1);
85 }
86 else {
87/* note that strlen does not include trailing null */
88 notes2=xNew<char>(strlen(notes)+1+mxGetNumberOfElements(notesi)+1);
89 memcpy(notes2,notes,(strlen(notes)+1)*sizeof(char));
90 xDelete<char>(notes);
91 notes=notes2;
92 notes2=NULL;
93// notes=(char*)xrealloc(notes,(strlen(notes)+1+mxGetNumberOfElements(notesi)+1)*sizeof(char));
94 strcat(notes,"\n");
95 mxGetString(notesi,&notes[strlen(notes)],mxGetNumberOfElements(notesi)+1);
96 }
97 }
98 }
99 }
100 else
101 FetchData(&notes,NOTES);
102 FetchData(&elem,&melem,&nelem,ELEMHANDLE);
103 FetchData(&nodecon,&mncon,&nncon,NODECONHANDLE);
104 FetchData(&lat,&mlat,&nlat,LATHANDLE);
105 llat=mlat*nlat;
106 FetchData(&lng,&mlng,&nlng,LNGHANDLE);
107 llng=mlng*nlng;
108 FetchData(&part,&mprt,&nprt,PARTHANDLE);
109 lprt=mprt*nprt;
110 FetchData(&data,&mdata,&ndata,DATAHANDLE);
111 FetchData(&cmap,&mcmap,&ncmap,CMAPHANDLE);
112 FetchData(&filnam,FILENAME);
113 FetchData(&options,NRHS,nrhs,prhs);
114
115 /*some checks*/
116 for (i=0; i<melem*nelem; i++) if(elem[i]>nnodes) nnodes=elem[i];
117 if(part) for (i=0; i<lprt; i++) if (part[i]+1 > nparts) nparts=part[i]+1;
118
119 if (nodecon && (mncon != nnodes))
120 {_error_("Nodal connectivity table, if supplied, must be supplied for all nodes.");}
121 else if (!nodecon)
122 mncon=nnodes;
123 if ((llat != nnodes) || (llng != nnodes) || (llat != llng))
124 _error_("Latitude and longitude vectors must be supplied for all nodes.");
125 if (part && (lprt != nnodes))
126 _error_("Partitioning vector, if supplied, must be supplied for all nodes.");
127 if (data && !((mdata == nnodes) || (mdata == melem)))
128 _error_("Data matrix, if supplied, must be supplied for all nodes or all elements.");
129 if (cmap && (ncmap != 3))
130 _error_("Colormap matrix, if supplied, must have three columns for rgb.");
131 if (!strlen(filnam))
132 strcpy(filnam,"stdout");
133
134 /* Run core computations: */
135 fid=fopen(filnam,"w");
136 KMLMeshWritex(&ierror,name,notes,elem,melem,nelem,nodecon,mncon,nncon,lat,lng,part,data,mdata,ndata,cmap,mcmap,ncmap,fid);
137 fclose(fid);
138
139 /*Write data: */
140 WriteData(ERRORFLAG,ierror);
141
142 /*Clean-up*/
143 delete options;
144 if (mxIsCell(NOTES) && notes) xfree((void**)&notes);
145
146 /*end module: */
147 MODULEEND();
148}
Note: See TracBrowser for help on using the repository browser.