]> Creatis software - CreaPhase.git/blob - octave_packages/nurbs-1.3.6/nrbexport.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nurbs-1.3.6 / nrbexport.m
1 function nrbexport (nurbs, filename)
2
3 %
4 % NRBEXPORT: export NURBS geometries to a format compatible with the one used in GeoPDEs (version 0.6).
5
6 % Calling Sequence:
7
8 %   nrbexport (nurbs, filename);
9
10 % INPUT:
11
12 %   nurbs    : NURBS curve, surface or volume, see nrbmak.
13 %   filename : name of the output file.
14
15
16 % Description:
17
18 %   The data of the nurbs structure is written in the file, in a format 
19 %     that can be read by GeoPDEs.
20 %
21 %    Copyright (C) 2011 Rafael Vazquez
22 %
23 %    This program is free software: you can redistribute it and/or modify
24 %    it under the terms of the GNU General Public License as published by
25 %    the Free Software Foundation, either version 2 of the License, or
26 %    (at your option) any later version.
27
28 %    This program is distributed in the hope that it will be useful,
29 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
30 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31 %    GNU General Public License for more details.
32 %
33 %    You should have received a copy of the GNU General Public License
34 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
35
36 fid = fopen (filename, 'w');
37 if (fid < 0)
38   error ('nrbexport: cannot open file %s', filename);
39 end
40
41 ndim = numel (nurbs(1).order);
42 npatch = numel (nurbs);
43 fprintf (fid, '%s\n', '# nurbs mesh v.0.7');
44 fprintf (fid, '%s\n', '#');
45 fprintf (fid, '%s\n', ['# ' date]);
46 fprintf (fid, '%s\n', '#');
47
48 fprintf (fid, '%2i', ndim, 1);
49 fprintf (fid, '\n');
50 for iptc = 1:npatch
51   fprintf (fid, '%s %i', 'PATCH', iptc);
52   fprintf (fid, '\n');
53   fprintf (fid, '%2i', nurbs(iptc).order-1);
54   fprintf (fid, '\n');
55   fprintf (fid, '%2i', nurbs(iptc).number);
56   fprintf (fid, '\n');
57   for ii = 1:ndim
58     fprintf (fid, '%1.7f   ', nurbs(iptc).knots{ii});
59     fprintf (fid, '\n');
60   end
61
62   if (ndim == 2)
63     for ii = 1:ndim
64       fprintf (fid, '%1.15f   ', nurbs(iptc).coefs(ii,:,:));
65       fprintf (fid, '\n');
66     end
67     fprintf (fid, '%1.15f   ', nurbs(iptc).coefs(4,:,:));
68     fprintf (fid, '\n');
69   elseif (ndim == 3)
70     for ii = 1:ndim
71       fprintf (fid, '%1.15f   ', nurbs(iptc).coefs(ii,:,:,:));
72       fprintf (fid, '\n');
73     end
74     fprintf (fid, '%1.15f   ', nurbs(iptc).coefs(4,:,:,:));
75     fprintf (fid, '\n');
76   end
77 end
78
79 fclose (fid);
80 end