From: <prn...@us...> - 2010-11-14 18:08:14
|
Revision: 7917 http://octave.svn.sourceforge.net/octave/?rev=7917&view=rev Author: prnienhuis Date: 2010-11-14 16:58:07 +0000 (Sun, 14 Nov 2010) Log Message: ----------- Initial versions. I think some improvements to the code are useful but the author hasn't replied yet :-) Added Paths: ----------- trunk/octave-forge/main/io/inst/savevtk.m trunk/octave-forge/main/io/inst/savevtkvector.m Added: trunk/octave-forge/main/io/inst/savevtk.m =================================================================== --- trunk/octave-forge/main/io/inst/savevtk.m (rev 0) +++ trunk/octave-forge/main/io/inst/savevtk.m 2010-11-14 16:58:07 UTC (rev 7917) @@ -0,0 +1,57 @@ +## Copyright (C) 2010 Kurnia Wano, Levente Torok +##. +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +##. +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +##. +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## +## -*- texinfo -*- +## +## @deftypefn {Function File} savevtk ( @var{X}, @var{Y}, @var{Z}, @var{filename} ) +## savevtk Save a 3-D scalar array in VTK format. +## savevtk(array, filename) saves a 3-D array of any size to +## filename in VTK format. +##. +## -*- texinfo -*- +## +## +## Author: Kurnia Wano, Levente Torok <Tor...@gm...> +## Created: 2010-08-02 +## Updates: 2010-11-03 +## + +function savevtk(array, filename) + [nx, ny, nz] = size(array); + fid = fopen(filename, 'wt'); + fprintf(fid, '# vtk DataFile Version 2.0\n'); + fprintf(fid, 'Comment goes here\n'); + fprintf(fid, 'ASCII\n'); + fprintf(fid, '\n'); + fprintf(fid, 'DATASET STRUCTURED_POINTS\n'); + fprintf(fid, 'DIMENSIONS %d %d %d\n', nx, ny, nz); + fprintf(fid, '\n'); + fprintf(fid, 'ORIGIN 0.000 0.000 0.000\n'); + fprintf(fid, 'SPACING 1.000 1.000 1.000\n'); + fprintf(fid, '\n'); + fprintf(fid, 'POINT_DATA %d\n', nx*ny*nz); + fprintf(fid, 'SCALARS scalars double\n'); + fprintf(fid, 'LOOKUP_TABLE default\n'); + fprintf(fid, '\n'); + for a=1:nz + for b=1:ny + for c=1:nx + fprintf(fid, '%d ', array(c,b,a)); + end + fprintf(fid, '\n'); + end + end + fclose(fid); +return Added: trunk/octave-forge/main/io/inst/savevtkvector.m =================================================================== --- trunk/octave-forge/main/io/inst/savevtkvector.m (rev 0) +++ trunk/octave-forge/main/io/inst/savevtkvector.m 2010-11-14 16:58:07 UTC (rev 7917) @@ -0,0 +1,64 @@ +## Copyright (C) 2010 Kurnia Wano, Levente Torok +##. +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +##. +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +##. +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## + +## -*- texinfo -*- +## +## @deftypefn {Function File} savevtkvector ( @var{X}, @var{Y}, @var{Z}, @var{filename} ) +## savevtkvector Save a 3-D vector array in VTK format +## savevtkvector(X,Y,Z,filename) saves a 3-D vector of any size to +## filename in VTK format. X, Y and Z should be arrays of the same +## size, each storing speeds in the a single Cartesian directions. +## +## @end deftypefn +## +## +## Author: Kurnia Wano, Levente Torok <Tor...@gm...> +## Created: 2010-08-02 +## Updates: 2010-11-03 +## + +function savevtkvector(X, Y, Z, filename) + + if ((size(X) ~= size(Y)) | (size(X) ~= size(Z))) + error('Error: velocity arrays of unequal size\n'); + return; + end + [ny,nx,nz]=size(datax); + xx=1:size(datax,2); + yy=1:size(datax,1); + zz=1:size(datax,3); + datax=datax(:)’; + datay=datay(:)’; + dataz=dataz(:)’; + %% Header + fid=fopen(fullfile(outputd,filename),’w'); + fprintf(fid,’%s\n’,'# vtk DataFile Version 3.0′); + fprintf(fid,’%s\n’,’3D LFF extrapolation’); + fprintf(fid,’%s\n’,'ASCII’); + fprintf(fid,’%s\n’,'DATASET RECTILINEAR_GRID’); + fprintf(fid,’%s %1.0i %1.0i %1.0i\n’,'DIMENSIONS’,nx,ny,nz); + fprintf(fid,’%s %1.0i %s\n’,'X_COORDINATES’,nx,’float’); + fprintf(fid,’%1.0i ‘,xx); + fprintf(fid,’\n%s %1.0i %s\n’,'Y_COORDINATES’,ny,’float’); + fprintf(fid,’%1.0i ‘,yy); + fprintf(fid,’\n%s %1.0i %s\n’,'Z_COORDINATES’,nz,’float’); + fprintf(fid,’%1.0i ‘,zz); + %% Data + fprintf(fid,’\n%s %1.0i’,'POINT_DATA’,nx*ny*nz); + fprintf(fid,’\n%s\n’,'VECTORS BFIELD float’); + fprintf(fid,’%6.2f %6.2f %6.2f\n’,[datax;datay;dataz]); + fclose(fid); +return This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |