12671
|
1 ## Copyright (C) 2006,2007,2008,2009,2010 Carlo de Falco, Massimiliano Culpo |
|
2 ## |
|
3 ## This file is part of: |
|
4 ## FPL - Fem PLotting package for octave |
|
5 ## |
|
6 ## FPL is free software; you can redistribute it and/or modify |
|
7 ## it under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or |
|
9 ## (at your option) any later version. |
|
10 ## |
|
11 ## FPL is distributed in the hope that it will be useful, |
|
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 ## GNU General Public License for more details. |
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
|
17 ## along with FPL; If not, see <http://www.gnu.org/licenses/>. |
|
18 ## |
|
19 ## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> |
|
20 ## author: Massimiliano Culpo <culpo _AT_ users.sourceforge.net> |
|
21 |
|
22 ## -*- texinfo -*- |
|
23 ## @deftypefn {Function File} {} fpl_dx_write_series (@var{basename}, @ |
|
24 ## @var{mesh}, @var{u}, @var{sp}, @var{attr_name}, @var{attr_rank}, @ |
|
25 ## @var{attr_shape}) |
|
26 ## |
|
27 ## Output data series in ASCII Open-DX format. |
|
28 ## |
|
29 ## @var{basename} is a string containing the base-name of the dx file where the |
|
30 ## data will be saved. |
|
31 ## |
|
32 ## @var{mesh} is a PDE-tool like mesh, like the ones generated by the |
|
33 ## "msh" package. |
|
34 ## |
|
35 ## @var{u} is the series to be saved. It should represent scalar, vector |
|
36 ## or tensor of doubles. @var{sp} is the vector of the sampled points |
|
37 ## (e.g. time points in the case of a time series). |
|
38 ## |
|
39 ## @var{attr_name} is a descriptive name for the series @var{u}, while |
|
40 ## @var{attr_rank} is the rank of the field items (0 for scalar, 1 for |
|
41 ## vector, etc.) and @var{attr_shape} is the number of components of the |
|
42 ## field items (assumed 1 for scalar). |
|
43 ## |
|
44 ## @seealso{fpl_dx_write_field} |
|
45 ## |
|
46 ## @end deftypefn |
|
47 |
|
48 function fpl_dx_write_series(basename,mesh,u,tp,attr_name,attr_rank,attr_shape) |
|
49 |
|
50 ## FIXME: add append capabilities as in fpl_dx_write_field?? |
|
51 |
|
52 if nargin!=7 |
|
53 error("fpl_dx_write_series: wrong number of input"); |
|
54 endif |
|
55 |
|
56 if !ischar(basename) |
|
57 error("fpl_dx_write_series: basename should be a valid string"); |
|
58 elseif !( isstruct(mesh) ) |
|
59 error("fpl_dx_write_series: mesh should be a valid structure"); |
|
60 elseif !ismatrix(u) |
|
61 error("fpl_dx_write_series: u should be a valid matrix"); |
|
62 elseif !ischar(attr_name) |
|
63 error("fpl_dx_write_series: attr_name should be a valid string"); |
|
64 elseif !isscalar(attr_rank) |
|
65 error("fpl_dx_write_series: attr_rank should be a valid scalar"); |
|
66 elseif !isscalar(attr_shape) |
|
67 error("fpl_dx_write_series: attr_shape should be a valid scalar"); |
|
68 ##elseif !isscalar(endfile) |
|
69 ##error("fpl_dx_write_series: endfile should be a valid scalar"); |
|
70 endif |
|
71 |
|
72 filename = [basename ".dx"]; |
|
73 |
|
74 npoints = length(tp); |
|
75 |
|
76 p = mesh.p'; |
|
77 dim = columns(p); # 2D or 3D |
|
78 |
|
79 if dim == 2 |
|
80 t = mesh.t(1:3,:)'; |
|
81 elseif dim == 3 |
|
82 t = mesh.t(1:4,:)'; |
|
83 else |
|
84 error("fpl_dx_write_series: neither 2D triangle nor 3D tetrahedral mesh"); |
|
85 endif |
|
86 |
|
87 nnodes = rows(p); |
|
88 nelems = rows(t); |
|
89 ndatas = rows(u); |
|
90 |
|
91 if ndatas == nnodes |
|
92 dep = "positions"; |
|
93 elseif ndatas == nelems |
|
94 dep = "connections"; |
|
95 else |
|
96 error("fpl_dx_write_series: neither position nor connection data type") |
|
97 endif |
|
98 |
|
99 ## Write field items to file |
|
100 idx = (1:attr_shape); |
|
101 for ii = 1:npoints |
|
102 field = u(:,idx); |
|
103 fname = sprintf("%s.%d",attr_name,ii); |
|
104 fpl_dx_write_field(basename,mesh,field,fname,attr_rank,attr_shape,0); |
|
105 idx += attr_shape; |
|
106 endfor |
|
107 |
|
108 ##if endfile |
|
109 fid = fopen(filename,"a"); |
|
110 fprintf (fid, "object \"%s_series\" class series\n",attr_name); |
|
111 for ii = 1:npoints |
|
112 fname = sprintf("%s.%d",attr_name,ii); |
|
113 fprintf (fid,"member %d position %g value \"%s\"\n",ii-1,tp(ii),fname); |
|
114 endfor |
|
115 fprintf (fid, "\nend\n"); |
|
116 fclose(fid); |
|
117 ##endif |
|
118 |
|
119 endfunction |