Home > vbmeg > external > iso2mesh > savejmesh.m

savejmesh

PURPOSE ^

SYNOPSIS ^

function savejmesh(node,face,elem,fname,varargin)

DESCRIPTION ^

 savejmesh(node,face,elem,fname,opt)

 export a mesh to the JMesh format

 author: Qianqian Fang, <q.fang at neu.edu>
 date: 2011/10/06

 input:
      node: input, node list, dimension (nn,3)
      face: input, optional, surface face element list, dimension (be,3)
      elem: input, tetrahedral element list, dimension (ne,4)
      fname: output file name
      opt: additional parameters in the form of 'parameter',value pairs
           valid parameters include:
           'Dimension': 0 - a user defined mesh, 2- a 2D mesh, 3- a 3D mesh
           'Author': a string to set the author of the mesh
           'MeshTitle': a string to set the title of the mesh
           'MeshTag': a value as the tag of the mesh data
           'MeshGroup': a value to group this mesh with other mesh data
           'Comment': a string as the additional note for the mesh data

 -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function savejmesh(node,face,elem,fname,varargin)
0002 %
0003 % savejmesh(node,face,elem,fname,opt)
0004 %
0005 % export a mesh to the JMesh format
0006 %
0007 % author: Qianqian Fang, <q.fang at neu.edu>
0008 % date: 2011/10/06
0009 %
0010 % input:
0011 %      node: input, node list, dimension (nn,3)
0012 %      face: input, optional, surface face element list, dimension (be,3)
0013 %      elem: input, tetrahedral element list, dimension (ne,4)
0014 %      fname: output file name
0015 %      opt: additional parameters in the form of 'parameter',value pairs
0016 %           valid parameters include:
0017 %           'Dimension': 0 - a user defined mesh, 2- a 2D mesh, 3- a 3D mesh
0018 %           'Author': a string to set the author of the mesh
0019 %           'MeshTitle': a string to set the title of the mesh
0020 %           'MeshTag': a value as the tag of the mesh data
0021 %           'MeshGroup': a value to group this mesh with other mesh data
0022 %           'Comment': a string as the additional note for the mesh data
0023 %
0024 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0025 %
0026 
0027 if(nargin==2)
0028    fname=face;
0029    face=[];
0030    elem=[];
0031 end
0032 
0033 if(nargin==3)
0034    fname=elem;
0035    elem=[];
0036 end
0037 
0038 if(length(varargin)==1 && ischar(varargin{1}))
0039    opt=struct('FileName',varargin{1});
0040 else
0041    opt=varargin2struct(varargin{:});
0042 end
0043 
0044 meshdim=jsonopt('Dimension',0,opt);
0045 
0046 fid=fopen(fname,'wt');
0047 if(fid==-1)
0048     error('You do not have permission to save mesh files.');
0049 end
0050 
0051 mesh.MeshVersion=0.5;
0052 mesh.CreationTime=datestr(now);
0053 mesh.Comment=['Created by iso2mesh ' iso2meshver '(http://iso2mesh.sf.net)'];
0054 
0055 if(meshdim==0) % a user-defined mesh
0056     mesh.MeshNode=node;
0057     if(~isempty(face))
0058         mesh.MeshSurf=face;
0059     end
0060     if(~isempty(elem))
0061         mesh.MeshElem=elem;
0062     end
0063 elseif(meshdim==3) % a 3D mesh
0064     nd=size(node);
0065     if(nd(2)<3) error('expecting 3 or more columns in node'); end
0066     mesh.MeshPoint3D=node(:,1:3);
0067     if(nd(2)>3)
0068         mesh.MeshNodeVal=node(:,4:end);
0069     end
0070     if(~isempty(face))
0071         nd=size(face);
0072         if(nd(2)<3) error('expecting 3 or more columns in face'); end
0073         mesh.MeshTri=face(:,1:3);
0074         if(nd(2)>3)
0075             mesh.MeshTriVal=face(:,4:end);
0076         end
0077     end
0078     if(~isempty(elem))
0079         nd=size(elem);
0080         if(nd(2)<4) error('expecting 4 or more columns in elem'); end
0081         mesh.MeshTetra=elem(:,1:4);
0082         if(nd(2)>4)
0083             mesh.MeshTetraVal=elem(:,5:end);
0084         end
0085     end
0086 elseif(meshdim==2) % a 2D mesh
0087     nd=size(node);
0088     if(nd(2)<2) error('expecting 2 or more columns in node'); end
0089     mesh.MeshPoint2D=node(:,1:2);
0090     if(nd(2)>2)
0091         mesh.MeshNodeVal=node(:,3:end);
0092     end
0093     if(~isempty(face))
0094         nd=size(face);
0095         if(nd(2)<3) error('expecting 3 or more columns in face'); end
0096         mesh.MeshTri=face(:,1:3);
0097         if(nd(2)>3)
0098             mesh.MeshTriVal=face(:,4:end);
0099         end
0100     end
0101     if(~isempty(elem))
0102         warning('elem is redundant in a 2D mesh, skip');
0103     end
0104 else
0105     error('the specified Dimension is not supported, please remove to save data to a general format');
0106 end
0107 
0108 author=jsonopt('Author','',opt);
0109 if(~isempty(author))
0110     mesh.Author=author;
0111 end
0112 
0113 title=jsonopt('MeshTitle','',opt);
0114 if(~isempty(title))
0115     mesh.MeshTitle=title;
0116 end
0117 
0118 tag=jsonopt('MeshTag',[],opt);
0119 if(~isempty(tag))
0120     mesh.MeshTag=tag;
0121 end
0122 
0123 group=jsonopt('MeshGroup',[],opt);
0124 if(~isempty(group))
0125     mesh.MeshTag=group;
0126 end
0127 
0128 comm=jsonopt('Comment','',opt);
0129 if(~isempty(comm))
0130     mesh.Comment=comm;
0131 end
0132 
0133 fprintf(fid,'%s\n',savejson('',mesh,varargin{:}));
0134 
0135 fclose(fid);

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005