]> Creatis software - CreaPhase.git/blob - octave_packages/secs2d-0.0.8/Utilities/UDXoutput2Ddata.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / secs2d-0.0.8 / Utilities / UDXoutput2Ddata.m
1 function UDXoutput2Ddata(filename,p,t,u,attr_name,attr_rank,attr_shape,endfile)
2
3 ##
4 ##   UDXoutput2Ddata(filename,p,t,u,attr_name,attr_rank,attr_shape,endfile)
5 ##
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   
9 ##
10 ##   x
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)
14 ##
15
16
17 % This file is part of 
18 %
19 %            SECS2D - A 2-D Drift--Diffusion Semiconductor Device Simulator
20 %         -------------------------------------------------------------------
21 %            Copyright (C) 2004-2006  Carlo de Falco
22 %
23 %
24 %
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.
29 %
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.
34 %
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/>.
37
38
39
40
41   p = p';
42   t = t';
43   t = t(:,1:3);
44
45   %eval(['!rm -f ',filename]);
46   
47   fid=fopen (filename,'w');
48   Nnodi = size(p,1);
49   Ntriangoli = size(t,1);
50   Ndati = size(u,1);
51
52   fprintf(fid,'object "pos"\nclass array type float rank 1 shape 2 items %d data follows',Nnodi);
53
54   for i=1:Nnodi
55     fprintf(fid,'\n');
56     fprintf(fid,'    %1.7e',p(i,:));
57   end
58   
59   if (min(min(t))==1)
60     t=t-1;
61   elseif(min(min(t))~=0)
62     disp('WARNING: check triangle structure')
63   end                    
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
69                                 # format
70
71   fprintf(fid,'\n\nobject "con"\nclass array type int rank 1 shape 3 items %d data follows',Ntriangoli);
72   for i=1:Ntriangoli
73     fprintf(fid,'\n');
74     fprintf(fid,'      %d',t(i,:));
75   end
76   
77   fprintf(fid,'\nattribute "element type" string "triangles"\nattribute "ref" string "positions"\n\n');
78   
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);
82
83   else
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);
86     for i=1:Ndati
87       fprintf(fid,'\n');
88       fprintf(fid,'    %1.7e',u(i,:));
89     end
90
91 end
92
93 if Ndati==Nnodi
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'],...
99           attr_name,attr_name);
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);
107 end
108
109   if(endfile)
110     fprintf(fid,'\nend\n');
111   end
112   
113   fclose (fid);
114
115