/*\file KMLMeshWrite.c *\brief: KML mesh writer module. */ #include "./KMLMeshWrite.h" void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){ int i,j,nnodes=0,verbose=1; /*input: */ char* name=NULL; char* notes=NULL; const mxArray* notesi; mwIndex nindex; int* elem=NULL; int melem=0,nelem=0; int* nodecon=NULL; int mncon=0,nncon=0; double* lat=NULL; int mlat=0,nlat=0,llat=0; double* lng=NULL; int mlng=0,nlng=0,llng=0; int nparts=0; int* part=NULL; int mprt=0,nprt=0,lprt=0; double* data=NULL; int mdata=0,ndata=0; double* cmap=NULL; int mcmap=0,ncmap=0; char* filnam=NULL; FILE* fid=NULL; Options* options=NULL; /* output: */ int ierror=0; /*Boot module: */ MODULEBOOT(); /*checks on arguments on the matlab side: */ if (nlhs > NLHS) { KMLMeshWriteUsage(); _error_("KMLMeshWrite usage error"); } if (nrhs < NRHS) { KMLMeshWriteUsage(); _error_("KMLMeshWrite usage error"); } /*Input datasets: */ if (verbose) printf("Fetching inputs:\n"); FetchData(&name,NAME); if (verbose) printf(" name =\"%s\"\n",name); /* notes is typically a cell array of character strings */ if (mxIsCell(NOTES)) { for (nindex=0; nindexSize()) for(i=0;iSize();i++) ((Option*)options->GetObjectByOffset(i))->DeepEcho(); /*some checks*/ if (verbose) printf("Checking inputs:\n"); for (i=0; i nnodes) nnodes=elem[i]; if (verbose) printf(" nnodes =%d\n",nnodes); if (part) for (i=0; i nparts) nparts=part[i]+1; if (verbose) printf(" nparts =%d\n",nparts); if (nodecon && (mncon != nnodes)) _error_("Nodal connectivity table, if supplied, must be supplied for all nodes."); else if (!nodecon) mncon=nnodes; if ((llat != nnodes) || (llng != nnodes) || (llat != llng)) _error_("Latitude and longitude vectors must be supplied for all nodes."); if (part && (lprt != nnodes)) _error_("Partitioning vector, if supplied, must be supplied for all nodes."); if (data && !((mdata == nnodes) || (mdata == melem))) _error_("Data matrix, if supplied, must be supplied for all nodes or all elements."); if (cmap && (ncmap != 3)) _error_("Colormap matrix, if supplied, must have three columns for rgb."); if (!strlen(filnam)) strcpy(filnam,"stdout"); if (verbose) printf("Opening file \"%s\".\n",filnam); fid=fopen(filnam,"w"); /* Run core computations: */ if (verbose) printf("Calling core:\n"); KMLMeshWritex(&ierror, name, notes, elem,melem,nelem, nodecon,mncon,nncon, lat,lng, part, data,mdata,ndata, cmap,mcmap,ncmap, fid); if (verbose) printf("Closing file \"%s\".\n",filnam); fclose(fid); /*Write data: */ WriteData(ERRORFLAG,ierror); /*Clean-up*/ delete options; if (mxIsCell(NOTES) && notes) xfree((void**)¬es); /*end module: */ MODULEEND(); } void KMLMeshWriteUsage(void) { _printf_(true,"KMLMeshWrite - KML mesh writer module:\n"); _printf_(true,"\n"); _printf_(true," This module writes the mesh of a model as KML polygons into the specified KML file.\n"); _printf_(true,"\n"); _printf_(true," Usage:\n"); _printf_(true," ierror=KMLMeshWrite(name,notes,elem,nodecon,lat,long,part,data,cmap,kmlfile);\n"); _printf_(true,"\n"); _printf_(true," name model name (string, may be empty)\n"); _printf_(true," notes model notes (string or cell array of strings, may be empty)\n"); _printf_(true," elem elements (double array)\n"); _printf_(true," nodecon nodal connectivity array (double array, may be empty)\n"); _printf_(true," lat nodal latititudes (double vector)\n"); _printf_(true," long nodal longitudes (double vector)\n"); _printf_(true," part nodal partitions (double vector, may be empty)\n"); _printf_(true," data nodal or element data (double vector, may be empty)\n"); _printf_(true," cmap color map (double nx3 array, may be empty)\n"); _printf_(true," kmlfile KML file name (string)\n"); _printf_(true,"\n"); _printf_(true," ierror error flag (double, non-zero for error)\n"); _printf_(true,"\n"); _printf_(true," Example:\n"); _printf_(true," KMLMeshWrite(md.name,md.notes,md.elements,md.nodeconnectivity,md.lat,md.long,md.part,md.fm_criterion,options.cmap,filekml);\n"); _printf_(true,"\n"); }