]> Creatis software - CreaPhase.git/blob - octave_packages/secs2d-0.0.8/Utilities/UDXappend2Ddata.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / secs2d-0.0.8 / Utilities / UDXappend2Ddata.m
1 function UDXappend2Ddata(filename,p,t,u,attr_name,attr_rank,attr_shape,endfile)
2
3 %
4 %   UDXappend2Ddata(filename,p,t,u,attr_name,attr_rank,attr_shape)
5 %
6 %   Apends data to a file 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 %   mesh data in the file must be consistent with this variable
10 %
11 %   x
12 %   attr_name  = name of the variable                   (type string)
13 %   attr_rank  = rank of variable data                  (0 for scalar, 1 for vector, etc.)
14 %   attr_shape = number of components of variable data  (assumed 1 for scalar)
15 %
16
17 p = p';
18 t = t';
19 t = t(:,1:3);
20
21 %eval(['!rm -f ',filename]);
22
23 fid=fopen (filename,'a');
24 Nnodi = size(p,1);
25 Ntriangoli = size(t,1);
26
27 fprintf(fid,'\nattribute "element type" string "triangles"\nattribute "ref" string "positions"\n\n');
28
29 if ((attr_rank==0) & (min(size(u))==1))
30     fprintf(fid,'object "%s.data"\nclass array type double rank 0 items %d data follows',attr_name,Nnodi);
31     fprintf(fid,'\n %1.7e',u);
32 else
33     fprintf(fid,'object "%s.data"\nclass array type double rank %d shape %d items %d data follows', ...
34         attr_name,attr_rank,attr_shape,Nnodi);
35     for i=1:Nnodi
36         fprintf(fid,'\n');
37         fprintf(fid,'    %1.7e',u(i,:));
38     end
39 end
40 fprintf(fid,['\nattribute "dep" string "positions"\n\n' ...
41              'object "%s" class field\n'...
42              'component "positions" value "pos"\n'...
43              'component "connections" value "con"\n'...
44              'component "data" value "%s.data"\n'],...
45               attr_name,attr_name);
46
47 if(endfile)
48     fprintf(fid,'\nend\n');
49 end
50
51 fclose (fid);
52
53
54 % Last Revision:
55 % $Author: cdf $
56 % $Date: 2007-05-22 21:16:23 +0200 (tir, 22 maj 2007) $