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