1 function UDXoutput2Ddata(filename,p,t,u,attr_name,attr_rank,attr_shape,endfile)
4 ## UDXoutput2Ddata(filename,p,t,u,attr_name,attr_rank,attr_shape,endfile)
6 ## Outputs data in DX form.
7 ## Only one variable can be written to the file
8 ## variable must be a scalar, vector or tensor of doubles
11 ## attr_name = name of the variable (type string)
12 ## attr_rank = rank of variable data (0 for scalar, 1 for vector, etc.)
13 ## attr_shape = number of components of variable data (assumed 1 for scalar)
17 % This file is part of
19 % SECS2D - A 2-D Drift--Diffusion Semiconductor Device Simulator
20 % -------------------------------------------------------------------
21 % Copyright (C) 2004-2006 Carlo de Falco
25 % SECS2D is free software; you can redistribute it and/or modify
26 % it under the terms of the GNU General Public License as published by
27 % the Free Software Foundation; either version 2 of the License, or
28 % (at your option) any later version.
30 % SECS2D is distributed in the hope that it will be useful,
31 % but WITHOUT ANY WARRANTY; without even the implied warranty of
32 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 % GNU General Public License for more details.
35 % You should have received a copy of the GNU General Public License
36 % along with SECS2D; If not, see <http://www.gnu.org/licenses/>.
45 %eval(['!rm -f ',filename]);
47 fid=fopen (filename,'w');
49 Ntriangoli = size(t,1);
52 fprintf(fid,'object "pos"\nclass array type float rank 1 shape 2 items %d data follows',Nnodi);
56 fprintf(fid,' %1.7e',p(i,:));
61 elseif(min(min(t))~=0)
62 disp('WARNING: check triangle structure')
64 # In DX format nodes are
65 # numbered starting from zero,
66 # instead we want to number
67 # them starting from 1!
68 # Here we restore the DX
71 fprintf(fid,'\n\nobject "con"\nclass array type int rank 1 shape 3 items %d data follows',Ntriangoli);
74 fprintf(fid,' %d',t(i,:));
77 fprintf(fid,'\nattribute "element type" string "triangles"\nattribute "ref" string "positions"\n\n');
79 if ((attr_rank==0) & (min(size(u))==1))
80 fprintf(fid,'object "%s.data"\nclass array type double rank 0 items %d data follows',attr_name,Ndati);
81 fprintf(fid,'\n %1.7e',u);
84 fprintf(fid,'object "%s.data"\nclass array type double rank %d shape %d items %d data follows', ...
85 attr_name,attr_rank,attr_shape,Ndati);
88 fprintf(fid,' %1.7e',u(i,:));
94 fprintf(fid,['\nattribute "dep" string "positions"\n\n' ...
95 'object "%s" class field\n'...
96 'component "positions" value "pos"\n'...
97 'component "connections" value "con"\n'...
98 'component "data" value "%s.data"\n'],...
100 elseif Ndati==Ntriangoli
101 fprintf(fid,['\nattribute "dep" string "connections"\n\n' ...
102 'object "%s" class field\n'...
103 'component "positions" value "pos"\n'...
104 'component "connections" value "con"\n'...
105 'component "data" value "%s.data"\n'],...
106 attr_name,attr_name);
110 fprintf(fid,'\nend\n');