]> Creatis software - CreaPhase.git/blob - octave_packages/fpl-1.2.0/FPL2dxappenddata.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / fpl-1.2.0 / FPL2dxappenddata.m
1 ## Copyright (C) 2004-2008  Carlo de Falco, Massimiliano Culpo
2 ##
3 ##  This file is part of 
4 ##
5 ##                   FPL - Fem PLotting package for octave
6 ## 
7 ##  FPL is free software; you can redistribute it and/or modify
8 ##  it under the terms of the GNU General Public License as published by
9 ##  the Free Software Foundation; either version 2 of the License, or
10 ##  (at your option) any later version.
11 ## 
12 ##  FPL is distributed in the hope that it will be useful,
13 ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ##  GNU General Public License for more details.
16 ## 
17 ##  You should have received a copy of the GNU General Public License
18 ##  along with FPL; If not, see <http://www.gnu.org/licenses/>.
19 ##
20 ##
21 ##  AUTHORS:
22 ##  Carlo de Falco <cdf _AT_ users.sourceforge.net>
23 ##
24 ##  Culpo Massimiliano
25 ##  Bergische Universitaet Wuppertal
26 ##  Fachbereich C - Mathematik und Naturwissenschaften
27 ##  Arbeitsgruppe fuer Angewandte MathematD-42119 Wuppertal  Gaussstr. 20 
28 ##  D-42119 Wuppertal, Germany
29
30 ## -*- texinfo -*-
31 ##  @deftypefn {Function File} {} FPL2dxappenddata ( @var{filename},
32 ##  @var{p}, @var{t}, @var{u}, @var{attr_name}, @var{attr_rank},
33 ##  @var{attr_shape}, @var{endflie} )
34 ##
35 ##   Apends data to a file in DX form.
36 ##   Only one variable can be written to the file
37 ##   variable must be a scalar, vector or tensor of doubles   
38 ##   mesh data in the file must be consistent with this variable
39 ##
40 ##   Variable must be a scalar, vector or tensor of doubles   
41 ##
42 ## @itemize @minus
43 ##  @item @var{filename}= name of file to save (type string)
44 ##  @item @var{p}, @var{t} = mesh
45 ##  @item @var{u} = variable to save
46 ##  @item @var{attr_name}  = name of the variable (type string)
47 ##  @item @var{attr_rank}  = rank of variable data (0 for scalar, 1 for vector, etc.)
48 ##  @item @var{attr_shape} = number of components of variable data  (assumed 1 for scalar)
49 ##  @item @var{endfile} = 0 if you want to add other variables to the
50 ##  same file, 1 otherwise
51 ## @end itemize
52 ## @end deftypefn
53
54 function FPL2dxappenddata(filename,p,t,u,attr_name,attr_rank,attr_shape,endfile)
55
56   p = p';
57   t = t';
58   t = t(:,1:3);
59
60   fid=fopen (filename,'a');
61   Nnodi = size(p,1);
62   Ntriangoli = size(t,1);
63
64   fprintf(fid,'\nattribute "element type" string "triangles"\nattribute "ref" string "positions"\n\n');
65
66   if ((attr_rank==0) & (min(size(u))==1))
67     fprintf(fid,'object "%s.data"\nclass array type double rank 0 items %d data follows',attr_name,Nnodi);
68             fprintf(fid,'\n %1.7e',u);
69                   else
70                     fprintf(fid,'object "%s.data"\nclass array type double rank %d shape %d items %d data follows', ...
71                             attr_name,attr_rank,attr_shape,Nnodi);
72                     for i=1:Nnodi
73                     fprintf(fid,'\n');
74                     fprintf(fid,'    %1.7e',u(i,:));
75                     endfor
76   endif
77   fprintf(fid,['\nattribute "dep" string "positions"\n\n' ...
78                'object "%s" class field\n'...
79                'component "positions" value "pos"\n'...
80                'component "connections" value "con"\n'...
81                'component "data" value "%s.data"\n'],...
82           attr_name,attr_name);
83   
84   if(endfile)
85     fprintf(fid,'\nend\n');
86   endif
87   
88   fclose (fid);
89   
90 endfunction