1 # A few hints about interfacing with Matlab
5 While deal.II offers a lot of possibilities to output data in different formats to produce awesome graphics, sometimes you experience the need to evaluate the data directly. Most of the deal.II classes have methods to temporarily write out raw data (e.g. Vector::block_write, etc.), and maybe you find it useful to load and modify the data in an environment like Matlab. The following scripts enable reading and writing of deal.II vector data, codes to process matrices may follow.
7 These codes should be easy to port to Octave.
14 function v = read_deal_vec(file, accuracy);
15 % function vect = read_deal_vec(file);
16 % function vect = read_deal_vec(file, accuracy);
18 % reads in a DEAL.II vector, written by Vector<>::block_write().
19 % The vector is stored in "file", which can be either a filename or
20 % a file handle. If you supply a filename, the file will be closed
22 % You usually only supply a file handle if more than one vector is
23 % stored within the file.
24 % "Accuracy" can be given if you stored a vector storing floats or
25 % long doubles. It is by default set to 'double'.
27 % Ralf B. Schulz, 2003--2005
29 if(nargin < 2), accuracy = 'double'; end;
34 file = fopen(file, 'r');
38 n = fscanf(file,'%d',1)
40 while(fscanf(file,'%c',1) ~= '[end;
42 v = fread(file, n, accuracy);
44 if(fscanf(file,'%c',1) ~= ']('),)'), error('wrong file format!'); end;
54 function write_deal_vec(file, vec, accuracy);
55 % function write_deal_vec(file, vector);
56 % function write_deal_vec(file, vector, accuracy);
58 % writes out a DEAL.II vector that can be read in using
59 % Vector<>::block_read(). The vector is stored in "file",
60 % which can be either a filename or a file handle. If you
61 % supply a filename, the file will be closed automatically.
62 % You usually supply a file handle if more than one vector is
63 % to be written to the file.
64 % "Accuracy" can be given if you stored a vector storing floats or
65 % long doubles. It is by default set to 'double'.
67 % Ralf B. Schulz, 2003--2005
75 if(isnumeric(filename))
79 file = fopen(filename, 'w');
83 fprintf(file,'%d\n[length(vec));
84 fwrite(file, vec, accuracy);
85 fprintf(file,'](',)\n');
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams