From: <cd...@us...> - 2011-08-17 06:24:30
|
Revision: 8466 http://octave.svn.sourceforge.net/octave/?rev=8466&view=rev Author: cdf Date: 2011-08-17 06:24:23 +0000 (Wed, 17 Aug 2011) Log Message: ----------- added new function Modified Paths: -------------- trunk/octave-forge/extra/fpl/INDEX trunk/octave-forge/extra/fpl/inst/FPL2dxappenddata.m trunk/octave-forge/extra/fpl/inst/FPL2dxoutputdata.m trunk/octave-forge/extra/fpl/inst/FPL3dxoutputfield.m trunk/octave-forge/extra/fpl/inst/fpl_vtk_write_field.m trunk/octave-forge/extra/fpl/inst/savevtk.m trunk/octave-forge/extra/fpl/inst/savevtkvector.m Added Paths: ----------- trunk/octave-forge/extra/fpl/inst/fpl_vtk_assemble_series.m Modified: trunk/octave-forge/extra/fpl/INDEX =================================================================== --- trunk/octave-forge/extra/fpl/INDEX 2011-08-16 21:03:07 UTC (rev 8465) +++ trunk/octave-forge/extra/fpl/INDEX 2011-08-17 06:24:23 UTC (rev 8466) @@ -4,6 +4,9 @@ fpl_dx_write_series.m Functions to save data in VTK format fpl_vtk_write_field.m + fpl_vtk_assemble_series.m + savevtk + savevtkvector Pdetool compatible plotting functions pdesurf pdemesh Modified: trunk/octave-forge/extra/fpl/inst/FPL2dxappenddata.m =================================================================== --- trunk/octave-forge/extra/fpl/inst/FPL2dxappenddata.m 2011-08-16 21:03:07 UTC (rev 8465) +++ trunk/octave-forge/extra/fpl/inst/FPL2dxappenddata.m 2011-08-17 06:24:23 UTC (rev 8466) @@ -63,7 +63,7 @@ fprintf(fid,'\nattribute "element type" string "triangles"\nattribute "ref" string "positions"\n\n'); - if ((attr_rank==0) & (min(size(u))==1)) + if ((attr_rank==0) && (min(size(u))==1)) fprintf(fid,'object "%s.data"\nclass array type double rank 0 items %d data follows',attr_name,Nnodi); fprintf(fid,'\n %1.7e',u); else Modified: trunk/octave-forge/extra/fpl/inst/FPL2dxoutputdata.m =================================================================== --- trunk/octave-forge/extra/fpl/inst/FPL2dxoutputdata.m 2011-08-16 21:03:07 UTC (rev 8465) +++ trunk/octave-forge/extra/fpl/inst/FPL2dxoutputdata.m 2011-08-17 06:24:23 UTC (rev 8466) @@ -86,7 +86,7 @@ fprintf(fid,"\nattribute ""element type"" string ""triangles""\nattribute ""ref"" string ""positions""\n\n"); - if ((attr_rank==0) & (min(size(u))==1)) + if ((attr_rank==0) && (min(size(u))==1)) fprintf(fid,"object ""%s.data""\nclass array type double rank 0 items %d data follows",attr_name,Ndati); fprintf(fid,"\n %1.7e",u); Modified: trunk/octave-forge/extra/fpl/inst/FPL3dxoutputfield.m =================================================================== --- trunk/octave-forge/extra/fpl/inst/FPL3dxoutputfield.m 2011-08-16 21:03:07 UTC (rev 8465) +++ trunk/octave-forge/extra/fpl/inst/FPL3dxoutputfield.m 2011-08-17 06:24:23 UTC (rev 8466) @@ -52,7 +52,7 @@ fid = fopen (filename,"w"); nnodes = size(field,1); - if ((attr_rank==0) & (min(size(field))==1)) + if ((attr_rank==0) && (min(size(field))==1)) fprintf(fid,"object ""%s.data""\nclass array type double rank 0 items %d data follows",attr_name,nnodes); fprintf(fid,"\n %e",field); else Added: trunk/octave-forge/extra/fpl/inst/fpl_vtk_assemble_series.m =================================================================== --- trunk/octave-forge/extra/fpl/inst/fpl_vtk_assemble_series.m (rev 0) +++ trunk/octave-forge/extra/fpl/inst/fpl_vtk_assemble_series.m 2011-08-17 06:24:23 UTC (rev 8466) @@ -0,0 +1,60 @@ +## Copyright (C) 2011 Carlo de Falco +## +## This file is part of: +## FPL - Fem PLotting package for octave +## +## FPL 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. +## +## FPL 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 FPL; If not, see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## @deftypefn {Function File} {} fpl_vtk_assemble_series (@var{collection}, @var{basenanme}, @var{format}, @var{idx}, @var{time}) +## +## Assemble a ParaView collection file (pvd) from a set of files representing data at different time-steps. +## +## @var{collection} is a string containing the base-name of the pvd file +## where the data will be saved. +## +## @var{basename}, @var{format}, @var{idx} are two strings and a set of integers, the name of the i-th file in the collection +## will be computed as @code{sprintf ([basename, format, ".vtu"], idx(i))}. +## +## @var{time} is the set of time-steps to which data correspond +## +## @seealso{fpl_vtk_write_field, fpl_dx_write_series} +## +## @end deftypefn + + +function fpl_vtk_assemble_series (collection, basenanme, format, idx, time) + + fid = fopen (strcat (collection, ".pvd"), "w"); + + ## Header + fprintf (fid, "<?xml version=""1.0""?>\n"); + fprintf (fid, "<VTKFile type=""Collection"" "); + fprintf (fid, " version=""0.1"">\n"); + fprintf (fid, "<Collection>\n"); + + ## Series + for ii = 1:ntpoints + fprintf (fid, "<DataSet timestep=""%#17.17g"" group=""%s"" ", time(ii), basename); + fprintf (fid, strcat ("file=""%s.", format, ".vtu""/>\n"), basename, idx(ii)); + endfor + + ## Footer + fprintf (fid, "</Collection>\n"); + fprintf (fid, "</VTKFile>\n"); + fclose (fid); + +endfunction \ No newline at end of file Modified: trunk/octave-forge/extra/fpl/inst/fpl_vtk_write_field.m =================================================================== --- trunk/octave-forge/extra/fpl/inst/fpl_vtk_write_field.m 2011-08-16 21:03:07 UTC (rev 8465) +++ trunk/octave-forge/extra/fpl/inst/fpl_vtk_write_field.m 2011-08-17 06:24:23 UTC (rev 8466) @@ -45,79 +45,82 @@ ## Example: ## @example ## <generate msh1, node centered field nc1, cell centered field cc1> -## fpl_vtk_write_field("example",msh1,@{nc1, "temperature"@},@ -## @{cc1, "density"@},0); +## fpl_vtk_write_field ("example", msh1, @{nc1, "temperature"@}, @{cc1, "density"@}, 0); ## <generate msh2, node centered field nc2> -## fpl_vtk_write_field("example",msh2,@{nc2, "temperature"@},@ -## @{@},1); +## fpl_vtk_write_field ("example", msh2, @{nc2, "temperature"@}, @{@}, 1); ## @end example ## will generate a valid XML-VTK UnstructuredGrid file. ## -## @seealso{fpl_dx_write_field, fpl_dx_write_series} +## @seealso{fpl_dx_write_field, fpl_dx_write_series, fpl_vtk_assemble_series} ## ## @end deftypefn -function fpl_vtk_write_field(basename,mesh,nodedata,celldata,endfile) +function fpl_vtk_write_field (basename, mesh, nodedata, celldata, endfile) ## Check input if nargin!=5 - error("fpl_vtk_write_field: wrong number of input"); + error ("fpl_vtk_write_field: wrong number of input parameters"); endif - if !ischar(basename) - error("fpl_vtk_write_field: basename should be a valid string"); - elseif !( isstruct(mesh) ) - error("fpl_vtk_write_field: mesh should be a valid structure"); - elseif !(iscell(nodedata) && iscell(celldata)) - error("fpl_vtk_write_field: nodedata and celldata should be a valid cells"); + if (! ischar (basename)) + error ("fpl_vtk_write_field: basename should be a string"); + elseif (! isstruct (mesh)) + error ("fpl_vtk_write_field: mesh should be a struct"); + elseif (! (iscell (nodedata) && iscell (celldata))) + error ("fpl_vtk_write_field: nodedata and celldata should be cell arrays"); endif filename = [basename ".vtu"]; - if ! exist(filename,"file") - fid = fopen (filename,"w"); + if (! exist (filename, "file")) + fid = fopen (filename, "w"); + ## Header - fprintf (fid,"<?xml version=""1.0""?>\n"); - fprintf (fid,"<VTKFile type=""UnstructuredGrid"" version=""0.1"" byte_order=""LittleEndian"">\n"); - fprintf (fid,"<UnstructuredGrid>\n"); + fprintf (fid, "<?xml version=""1.0""?>\n"); + fprintf (fid, "<VTKFile type=""UnstructuredGrid"" version=""0.1"" byte_order=""LittleEndian"">\n"); + fprintf (fid, "<UnstructuredGrid>\n"); else + ## FIXME: the following should be performed in a cleaner way! Does a ## backward fgetl function exist? ## If file exist, check if it was already closed - fid = fopen (filename,"r"); - fseek(fid,-10,SEEK_END); - tst = fgetl(fid); - if strcmp(tst,"</VTKFile>") - error("fpl_vtk_write_field: file %s exist and was already closed",filename); + fid = fopen (filename, "r"); + fseek (fid, -10, SEEK_END); + tst = fgetl (fid); + if (strcmp (tst, "</VTKFile>")) + error ("fpl_vtk_write_field: file %s exist and was already closed", filename); endif - fclose(fid); - fid = fopen (filename,"a"); + fclose (fid); + fid = fopen (filename, "a"); endif p = mesh.p; - dim = rows(p); # 2D or 3D + dim = rows (p); # 2D or 3D if dim == 2 - t = mesh.t(1:3,:); + t = mesh.t (1:3,:); elseif dim == 3 - t = mesh.t(1:4,:); + t = mesh.t (1:4,:); else - error("fpl_vtk_write_field: neither 2D triangle nor 3D tetrahedral mesh"); + error ("fpl_vtk_write_field: neither 2D triangle nor 3D tetrahedral mesh"); endif t -= 1; - nnodes = columns(p); - nelems = columns(t); + nnodes = columns (p); + nelems = columns (t); ## Header for <Piece> - fprintf (fid,"<Piece NumberOfPoints=""%d"" NumberOfCells=""%d"">\n",nnodes,nelems); + fprintf (fid, "<Piece NumberOfPoints=""%d"" NumberOfCells=""%d"">\n", nnodes, nelems); + ## Print grid - print_grid(fid,dim,p,nnodes,t,nelems); - ## Print PointData - print_data_points(fid,nodedata,nnodes) - print_cell_data (fid,celldata,nelems) + print_grid (fid, dim, p, nnodes, t, nelems); + + ## Print Data + print_data_points (fid, nodedata, nnodes) + print_cell_data (fid, celldata, nelems) + ## Footer for <Piece> fprintf (fid, "</Piece>\n"); @@ -132,7 +135,7 @@ endfunction ## Print Points and Cells Data -function print_grid(fid,dim,p,nnodes,t,nelems) +function print_grid (fid, dim, p, nnodes, t, nelems) if dim == 2 p = [p; zeros(1,nnodes)]; @@ -142,11 +145,11 @@ endif ## VTK-Points (mesh nodes) - fprintf (fid,"<Points>\n"); - fprintf (fid,"<DataArray type=""Float64"" Name=""Array"" NumberOfComponents=""3"" format=""ascii"">\n"); - fprintf (fid,"%g %g %g\n", p); - fprintf (fid,"</DataArray>\n"); - fprintf (fid,"</Points>\n"); + fprintf (fid, "<Points>\n"); + fprintf (fid, "<DataArray type=""Float64"" Name=""Array"" NumberOfComponents=""3"" format=""ascii"">\n"); + fprintf (fid, "%g %g %g\n", p); + fprintf (fid, "</DataArray>\n"); + fprintf (fid, "</Points>\n"); ## VTK-Cells (mesh elements) fprintf (fid, "<Cells>\n"); @@ -168,40 +171,40 @@ endfunction ## Print DataPoints -function print_data_points(fid,nodedata,nnodes) +function print_data_points (fid, nodedata, nnodes) ## # of data to print in ## <PointData> field - nvdata = size(nodedata,1); + nvdata = size (nodedata, 1); if (nvdata) fprintf (fid, "<PointData>\n"); for ii = 1:nvdata data = nodedata{ii,1}; dataname = nodedata{ii,2}; - nsamples = rows(data); - ncomp = columns(data); - if nsamples != nnodes - error("fpl_vtk_write_field: wrong number of samples in <PointData> ""%s""",dataname); + nsamples = rows (data); + ncomp = columns (data); + if (nsamples != nnodes) + error ("fpl_vtk_write_field: wrong number of samples in <PointData> ""%s""", dataname); endif - fprintf (fid,"<DataArray type=""Float32"" Name=""%s"" ",dataname); - fprintf (fid,"NumberOfComponents=""%d"" format=""ascii"">\n",ncomp); + fprintf (fid, "<DataArray type=""Float32"" Name=""%s"" ", dataname); + fprintf (fid, "NumberOfComponents=""%d"" format=""ascii"">\n", ncomp); for jj = 1:nsamples - fprintf (fid,"%g ",data(jj,:)); - fprintf (fid,"\n"); + fprintf (fid, "%g ", data(jj,:)); + fprintf (fid, "\n"); endfor - fprintf (fid,"</DataArray>\n"); + fprintf (fid, "</DataArray>\n"); endfor fprintf (fid, "</PointData>\n"); endif endfunction -function print_cell_data(fid,celldata,nelems) +function print_cell_data (fid, celldata, nelems) ## # of data to print in ## <CellData> field - nvdata = size(celldata,1); + nvdata = size (celldata, 1); if (nvdata) fprintf (fid, "<CellData>\n"); @@ -211,15 +214,15 @@ nsamples = rows(data); ncomp = columns(data); if nsamples != nelems - error("fpl_vtk_write_field: wrong number of samples in <CellData> ""%s""",dataname); + error ("fpl_vtk_write_field: wrong number of samples in <CellData> ""%s""", dataname); endif - fprintf (fid,"<DataArray type=""Float32"" Name=""%s"" ",dataname); - fprintf (fid,"NumberOfComponents=""%d"" format=""ascii"">\n",ncomp); + fprintf (fid, "<DataArray type=""Float32"" Name=""%s"" ", dataname); + fprintf (fid, "NumberOfComponents=""%d"" format=""ascii"">\n", ncomp); for jj = 1:nsamples - fprintf (fid,"%g ",data(jj,:)); - fprintf (fid,"\n"); + fprintf (fid, "%g ", data(jj,:)); + fprintf (fid, "\n"); endfor - fprintf (fid,"</DataArray>\n"); + fprintf (fid, "</DataArray>\n"); endfor fprintf (fid, "</CellData>\n"); endif Modified: trunk/octave-forge/extra/fpl/inst/savevtk.m =================================================================== --- trunk/octave-forge/extra/fpl/inst/savevtk.m 2011-08-16 21:03:07 UTC (rev 8465) +++ trunk/octave-forge/extra/fpl/inst/savevtk.m 2011-08-17 06:24:23 UTC (rev 8466) @@ -14,31 +14,30 @@ ## along with this program; If not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} [ @var{status} ] = savevtk ( @var{X}, @var{Y}, @var{Z}, @var{filename} ) -## savevtk Save a 3-D scalar array in VTK format. +## @deftypefn {Function File} [@var{status}] = savevtk ( @var{X}, @var{Y}, @var{Z}, @var{filename} ) ## -## savevtk( array, filename ) saves a 3-D array of any size to -## filename in VTK format. This file format is used by Mayavi2 for example. +## Save a 3-D scalar array @var{array} to the file @var{filename} in VTK structured-grid format. ## -## If no write errors occurred, output argument status is set to 1, otherwise 0. +## This file format is used by Mayavi2 or ParaView for example. +## If no write errors occurred, output argument @var{status} is set to 1, otherwise 0. ## ## Example: ## ## @example ## n = 30; -## X = zeros(n,n,n); +## X = zeros (n, n, n); ## for x = 1:n ## for y = 1:n ## for z = 1:n -## X(x, y, z) = 1/sqrt ( x*x + y*y + z*z ); +## X(x, y, z) = 1 / sqrt (x*x + y*y + z*z); ## endfor ## endfor ## endfor -## X = X * 200 / max(max(max(X))); -## savevtk( X, "spherical.vtk"); +## X = X * 200 / max (max (max (X))); +## savevtk (X, "spherical.vtk"); ## @end example ## -## @seealso savevtkvector +## @seealso{savevtkvector} ## ## @end deftypefn @@ -46,55 +45,55 @@ ## Author: Kurnia Wano, Levente Torok <Tor...@gm...> ## Created: 2010-08-02 matlab version ## Updates: 2010-11-03 octave adoptation +## 2011-08-17 remove matlab style short-cicuit operator, indentation, help text ## -function [status ] = savevtk (array, filename="vtkout.vtk") +function status = savevtk (array, filename="vtkout.vtk") - status = 0; - if (nargin < 1), usage ("[status] = savevtk (array, filename)"); endif - dims = size (array) - if ( size (dims) != 3) -# if (ndims (A) != 3) - error ("Save Vtk requires a 3 dimensional array"); + status = 0; + if (nargin < 1), usage ("[status] = savevtk (array, filename)"); endif + dims = size (array); + if (numel (dims) != 3) + error ("Save Vtk requires a 3 dimensional array"); + endif + [nx, ny, nz] = size (array); + + if (ischar (filename)) + [fid, msg] = fopen (filename, 'wt'); + if (fid < 0) + error ("Cannot open file for saving file. %s", msg); endif - [nx, ny, nz] = size (array); + else + usage ("Filename expected for arg # 2"); + endif - if (ischar (filename)) - [fid, msg] = fopen (filename, 'wt'); - if (fid < 0) - error ("Cannot open file for saving file. %s", msg); - endif - else - usage ("Filename expected for arg # 2"); - endif + try + 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)); + endfor + fprintf (fid, '\n'); + endfor + endfor + fclose (fid); + status = 1; + catch + error ("Error writing file %s - disk full?", filename); + end_try_catch - try - 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)); - endfor - fprintf (fid, '\n'); - endfor - endfor - fclose (fid); - status = 1; - catch - error ("Error writing file %s - disk full?", filename); - end_try_catch - endfunction Modified: trunk/octave-forge/extra/fpl/inst/savevtkvector.m =================================================================== --- trunk/octave-forge/extra/fpl/inst/savevtkvector.m 2011-08-16 21:03:07 UTC (rev 8465) +++ trunk/octave-forge/extra/fpl/inst/savevtkvector.m 2011-08-17 06:24:23 UTC (rev 8466) @@ -15,71 +15,71 @@ ## ## -*- texinfo -*- -## @deftypefn {Function File} [ @var{status} ] = savevtkvector ( @var{X}, @var{Y}, @var{Z}, @var{filename} ) -## savevtkvector Save a 3-D vector array in VTK format +## @deftypefn {Function File} [@var{status}] = savevtkvector (@var{X}, @var{Y}, @var{Z}, @var{filename}) ## -## savevtkvector (X, Y, Z, filename) saves a 3-D vector of any size to -## filename in VTK format. This file format is used by Mayavi2 for example. -## X, Y and Z should be arrays of the same -## size, each storing speeds in the a single Cartesian directions. +## Save a 3-D vector field of components @var{X}, @var{Y}, @var{Z} to the file @var{filename} in VTK format. ## -## If no write errors occurred, output argument status is set to 1, otherwise 0. +## This file format is used by Mayavi2 or ParaView for example. +## X, Y and Z should be 3-D arrays of the same +## size, each storing vector components in a given Cartesian direction. ## +## If no write errors occurred, output argument @var{status} is set to 1, otherwise 0. +## +## @seealso{savevtk} ## @end deftypefn ## ## Author: Kurnia Wano, Levente Torok <Tor...@gm...> ## Created: 2010-08-02 matlab version ## Updates: 2010-11-03 octave adoptatoin +## 2011-08-17 remove matlab style short-cicuit operator, indentation, help text ## -function [ status ] = savevtkvector (X, Y, Z, filename) +function [status] = savevtkvector (X, Y, Z, filename='vtkvector.vtk') + + status = 0; + if (nargin < 4), usage ("[status] = savevtkvector (X, Y, Z, filename='vtkvector.vtk')"); endif + if ((size(X) ~= size(Y)) || (size(X) ~= size(Z))) + error ("Error: velocity arrays of unequal size\n"); + 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 + if (ischar (filename)) + [ fid, msg ] = fopen (fullfile (outputd, filename), 'w'); + if ( fid < 1 ) + error ("Cannot open the file for saving: %s", msg); + endif + else + usage ("Filename expected for arg # 2"); + endif - status = 0; - if (nargin < 4), usage ("[status] = savevtkvector (X, Y, Z, filename='vtkvector.out')"); endif - if ((size(X) ~= size(Y)) | (size(X) ~= size(Z))) - error ("Error: velocity arrays of unequal size\n"); -# return; return not needed here, error() breaks out already - 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 + try + 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); + status = 1; + catch + error ("Error writing file %s - disk full?", filename) + end_try_catch - if (ischar (filename)) - [ fid, msg ] = fopen (fullfile (outputd, filename), 'w'); - if ( fid < 1 ) - error ("Cannot open the file for saving: %s", msg); - endif - else - usage ("Filename expected for arg # 2"); - endif - - try - 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); - status = 1; - catch - error ("Error writing file %s - disk full?", filename) - end_try_catch - endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |