VERB_code_2.3
save_plt.m
1 % Save arrays into .plt format
2 % save_plt(filename, arrays... )
3 %
4 % See also: save_picture
5 
6 function [varargout]=save_plt(filename, varargin)
7 
8 %total size calculating
9 total_size = size(varargin{1}.arr, 1)*size(varargin{1}.arr, 2)*size(varargin{1}.arr, 3);
10 
11 %adding all arrays to the 1 array
12 if (nargin > 1)
13  %reshape first array to the 1d array and add to the total array
14  total_array = reshape(permute(varargin{1}.arr, [3,2,1]), [total_size, 1]);
15  n_of_vars = 1;
16  % creating output format
17  format_string = '%e\t';
18  for it = 2:nargin-1
19  %reshape others arrays to the 1d array and add to the total array
20  total_array = [total_array, reshape(permute(varargin{it}.arr, [3,2,1]), [total_size, 1])];
21  n_of_vars = n_of_vars + 1;
22  format_string = [format_string, '%e\t'];
23  end
24 end
25 format_string = [format_string, '\n'];
26 
27 %remove NaN
28 total_array (find(~isfinite(total_array)))=1e-22;
29 
30 fid = fopen(filename, 'w');
31 
32 %writing comments
33 for it = 1:nargin-1
34  try
35  for comment = varargin{it}.comments
36  fprintf(fid, '%s\n', comment{1});
37  end
38  catch
39  end
40 end
41 % try
42 % %trying to write comments, if exists
43 % fprintf(fid, '%s\n', varargin{it}.comments);
44 % catch
45 % %else - nothing
46 % end
47 %end
48 
49 
50 %writing header
51 fprintf(fid, 'VARIABLES = ');
52 for it = 1:nargin-1
53  try
54  %trying to write var-name, if exists
55  fprintf(fid, '"%s", ', varargin{it}.name); % ...name{1}
56  catch
57  fprintf(fid, '"func.", ');
58  end
59 end
60 fprintf(fid, '\nZONE T="..." I=%d, J=%d, K=%d\n', size(varargin{1}.arr, 3), size(varargin{1}.arr, 2), size(varargin{1}.arr, 1));
61 
62 fprintf(fid, format_string, total_array');
63 
64 fclose(fid);