1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
---|
2 | "http://www.w3.org/TR/REC-html40/loose.dtd"> |
---|
3 | <html> |
---|
4 | <head> |
---|
5 | <title>Description of name_generator</title> |
---|
6 | <meta name="keywords" content="name_generator"> |
---|
7 | <meta name="description" content="'name_generator': creates a file name from a root name and indices."> |
---|
8 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
9 | <meta name="generator" content="m2html © 2003 Guillaume Flandin"> |
---|
10 | <meta name="robots" content="index, follow"> |
---|
11 | <link type="text/css" rel="stylesheet" href="../m2html.css"> |
---|
12 | </head> |
---|
13 | <body> |
---|
14 | <a name="_top"></a> |
---|
15 | <div><a href="../index.html">Home</a> > <a href="index.html">.</a> > name_generator.m</div> |
---|
16 | |
---|
17 | <!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td> |
---|
18 | <td align="right"><a href="index.html">Index for . <img alt=">" border="0" src="../right.png"></a></td></tr></table>--> |
---|
19 | |
---|
20 | <h1>name_generator |
---|
21 | </h1> |
---|
22 | |
---|
23 | <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
24 | <div class="box"><strong>'name_generator': creates a file name from a root name and indices.</strong></div> |
---|
25 | |
---|
26 | <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
27 | <div class="box"><strong>function [filename,idetect,num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out]=name_generator(filebase,num_i1,num_j1,ext,nom_type,comp_input,num_i2,num_j2,subdir); </strong></div> |
---|
28 | |
---|
29 | <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
30 | <div class="fragment"><pre class="comment">'name_generator': creates a file name from a root name and indices. |
---|
31 | --------------------------------------------------------------------- |
---|
32 | [filename,idetect,num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out]=... |
---|
33 | name_generator(filebase,num_i1,num_j1,ext,nom_type,comp_input,num_i2,num_j2,subdir); |
---|
34 | --------------------------------------------------------------------- |
---|
35 | This function detects the existence the constructed file name and it can |
---|
36 | find indices according to file existence if they are not specified |
---|
37 | %rmq: this function is related to the reverse functions display2name and name2diplay |
---|
38 | --------------------------------------------------------------------- |
---|
39 | OUTPUT: |
---|
40 | filename: string representing the file name (including path) |
---|
41 | idetect: =1 if the file is detected, 0 otherwise |
---|
42 | num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out: index numbers and subdirectory detected |
---|
43 | for free input (= to the corresponding input indices when comp_input=1) |
---|
44 | --------------------------------------------------------------------- |
---|
45 | INPUT: |
---|
46 | 'filebase': the root name, |
---|
47 | 'num_i1: first labelling index i |
---|
48 | 'num_j1', first labelling index j |
---|
49 | 'ext': file name extension (e.g. '.png' or '.nc') |
---|
50 | 'nom_type': string defining the kind of nomenclature used: |
---|
51 | nom_type='': constant name [filebase ext] (default output if 'nom_type' is undefined) |
---|
52 | nom_type='*': the same file [filebase ext] contains successive fields (ex avi movies) |
---|
53 | nom_type='_i': series of files with a single index i preceded by '_'(e.g. 'aa_45.png'). |
---|
54 | nom_type='#' series of indexed images wich is not series_i [filebase index ext], e.g. 'aa045.jpg' or 'aa45.tif' |
---|
55 | nom_type='_i_j' matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png') |
---|
56 | nom_type='_i1-i2' from pairs from a single index (e.g. 'aa_45-47.nc') |
---|
57 | nom_type='_i_j1-j2'pairs of j indices (e.g. 'aa_45_2-3.nc') |
---|
58 | nom_type='_i1-i2_j' pairs of i indices (e.g. 'aa_45-46_2.nc') |
---|
59 | nom_type='#a','#A' with a numerical index and an index letter(e.g.'aa045b.png'), OBSOLETE (replaced by 'series_i_j') |
---|
60 | nom_type='%03d' or '%04d', series of indexed images with numbers completed with zeros to 3 or 4 digits, e.g.'aa045.tif' |
---|
61 | nom_type='_%03d', '_%04d', or '_%05d', series of indexed images with _ and numbers completed with zeros to 3, 4 or 5 digits, e.g.'aa_045.tif' |
---|
62 | nom_type='raw_SMD', same as '#a' but with no extension ext='', OBSOLETE |
---|
63 | nom_type='#_ab' from pairs of '#a' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by 'netc_2D') |
---|
64 | nom_type='%3dab' from pairs of '%3da' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by 'netc_2D') |
---|
65 | A REVOIR: 'comp_input'=1 for writting =0 for reading , 'comp_input'(for nom_type involving index pairs (e.g. netc)) |
---|
66 | comp_input=1: the index pair is imposed, |
---|
67 | comp_input=0: the index pair is automatically searched, choosing the most recent file in case of multiple choice |
---|
68 | 'num_i2': second index i (for nom_type involving index pairs (e.g. netc)) |
---|
69 | 'num_j2': second index j (for nom_type involving index pairs (e.g. netc)) |
---|
70 | 'subdir': (used for nom_type=netc...) string representing the name of the subdirectory 'subdir' containing file. |
---|
71 | subdir='': no subdirectory, |
---|
72 | subdir='?', the file is first searched with no subdirectory, then in the most recently modified subdirectory if not detected.</pre></div> |
---|
73 | |
---|
74 | <!-- crossreference --> |
---|
75 | <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
76 | This function calls: |
---|
77 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
78 | <li><a href="name2display.html" class="code" title="function [RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput)">name2display</a> 'name2display': extracts the root name and field numbers from an input filename</li><li><a href="num2stra.html" class="code" title="function str=num2stra(num,nom_type,index);">num2stra</a> 'num2stra': transform number to the corresponding character string depending on the nomenclature</li><li><a href="stra2num.html" class="code" title="function numres=stra2num(str)">stra2num</a> 'stra2num': transform letters (a, b, c) or numerical strings ('1','2'..) to the corresponding numbers</li></ul> |
---|
79 | This function is called by: |
---|
80 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
81 | <li><a href="civ.html" class="code" title="function varargout = civ(varargin)">civ</a> 'civ': function associated with the interface 'civ.fig' for PIV, spline interpolation and stereo PIV (patch)</li><li><a href="civ_3D.html" class="code" title="function varargout = civ_3D(varargin)">civ_3D</a> 'civ_3D': function associated with the interface 'civ_3D.fig' for PIV in volume</li><li><a href="series.html" class="code" title="function varargout = series(varargin)">series</a> 'series': master function associated to the GUI series.m for analysis field series</li><li><a href="uvmat.html" class="code" title="function varargout = uvmat(varargin)">uvmat</a> 'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization</li></ul> |
---|
82 | <!-- crossreference --> |
---|
83 | |
---|
84 | <h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
85 | <ul style="list-style-image:url(../matlabicon.gif)"> |
---|
86 | <li><a href="#_sub1" class="code">function [filename,num_i1,num_j1,num_i2,num_j2,idetect]=search_pair(filebasesub,num_i1,num_j1,num_i2,nom_type)</a></li></ul> |
---|
87 | <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2> |
---|
88 | <div class="fragment"><pre>0001 <span class="comment">%'name_generator': creates a file name from a root name and indices.</span> |
---|
89 | 0002 <span class="comment">%---------------------------------------------------------------------</span> |
---|
90 | 0003 <span class="comment">% [filename,idetect,num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out]=...</span> |
---|
91 | 0004 <span class="comment">% name_generator(filebase,num_i1,num_j1,ext,nom_type,comp_input,num_i2,num_j2,subdir);</span> |
---|
92 | 0005 <span class="comment">%---------------------------------------------------------------------</span> |
---|
93 | 0006 <span class="comment">% This function detects the existence the constructed file name and it can</span> |
---|
94 | 0007 <span class="comment">% find indices according to file existence if they are not specified</span> |
---|
95 | 0008 <span class="comment">%%rmq: this function is related to the reverse functions display2name and name2diplay</span> |
---|
96 | 0009 <span class="comment">%---------------------------------------------------------------------</span> |
---|
97 | 0010 <span class="comment">% OUTPUT:</span> |
---|
98 | 0011 <span class="comment">%filename: string representing the file name (including path)</span> |
---|
99 | 0012 <span class="comment">%idetect: =1 if the file is detected, 0 otherwise</span> |
---|
100 | 0013 <span class="comment">%num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out: index numbers and subdirectory detected</span> |
---|
101 | 0014 <span class="comment">%for free input (= to the corresponding input indices when comp_input=1)</span> |
---|
102 | 0015 <span class="comment">%---------------------------------------------------------------------</span> |
---|
103 | 0016 <span class="comment">% INPUT:</span> |
---|
104 | 0017 <span class="comment">% 'filebase': the root name,</span> |
---|
105 | 0018 <span class="comment">% 'num_i1: first labelling index i</span> |
---|
106 | 0019 <span class="comment">% 'num_j1', first labelling index j</span> |
---|
107 | 0020 <span class="comment">% 'ext': file name extension (e.g. '.png' or '.nc')</span> |
---|
108 | 0021 <span class="comment">% 'nom_type': string defining the kind of nomenclature used:</span> |
---|
109 | 0022 <span class="comment">%nom_type='': constant name [filebase ext] (default output if 'nom_type' is undefined)</span> |
---|
110 | 0023 <span class="comment">%nom_type='*': the same file [filebase ext] contains successive fields (ex avi movies)</span> |
---|
111 | 0024 <span class="comment">%nom_type='_i': series of files with a single index i preceded by '_'(e.g. 'aa_45.png').</span> |
---|
112 | 0025 <span class="comment">%nom_type='#' series of indexed images wich is not series_i [filebase index ext], e.g. 'aa045.jpg' or 'aa45.tif'</span> |
---|
113 | 0026 <span class="comment">%nom_type='_i_j' matrix of files with two indices i and j separated by '_'(e.g. 'aa_45_2.png')</span> |
---|
114 | 0027 <span class="comment">%nom_type='_i1-i2' from pairs from a single index (e.g. 'aa_45-47.nc')</span> |
---|
115 | 0028 <span class="comment">%nom_type='_i_j1-j2'pairs of j indices (e.g. 'aa_45_2-3.nc')</span> |
---|
116 | 0029 <span class="comment">%nom_type='_i1-i2_j' pairs of i indices (e.g. 'aa_45-46_2.nc')</span> |
---|
117 | 0030 <span class="comment">%nom_type='#a','#A' with a numerical index and an index letter(e.g.'aa045b.png'), OBSOLETE (replaced by 'series_i_j')</span> |
---|
118 | 0031 <span class="comment">%nom_type='%03d' or '%04d', series of indexed images with numbers completed with zeros to 3 or 4 digits, e.g.'aa045.tif'</span> |
---|
119 | 0032 <span class="comment">%nom_type='_%03d', '_%04d', or '_%05d', series of indexed images with _ and numbers completed with zeros to 3, 4 or 5 digits, e.g.'aa_045.tif'</span> |
---|
120 | 0033 <span class="comment">%nom_type='raw_SMD', same as '#a' but with no extension ext='', OBSOLETE</span> |
---|
121 | 0034 <span class="comment">%nom_type='#_ab' from pairs of '#a' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by 'netc_2D')</span> |
---|
122 | 0035 <span class="comment">%nom_type='%3dab' from pairs of '%3da' images (e.g. 'aa045bc.nc'), ext='.nc', OBSOLETE (replaced by 'netc_2D')</span> |
---|
123 | 0036 <span class="comment">% A REVOIR: 'comp_input'=1 for writting =0 for reading , 'comp_input'(for nom_type involving index pairs (e.g. netc))</span> |
---|
124 | 0037 <span class="comment">%comp_input=1: the index pair is imposed,</span> |
---|
125 | 0038 <span class="comment">%comp_input=0: the index pair is automatically searched, choosing the most recent file in case of multiple choice</span> |
---|
126 | 0039 <span class="comment">% 'num_i2': second index i (for nom_type involving index pairs (e.g. netc))</span> |
---|
127 | 0040 <span class="comment">% 'num_j2': second index j (for nom_type involving index pairs (e.g. netc))</span> |
---|
128 | 0041 <span class="comment">% 'subdir': (used for nom_type=netc...) string representing the name of the subdirectory 'subdir' containing file.</span> |
---|
129 | 0042 <span class="comment">%subdir='': no subdirectory,</span> |
---|
130 | 0043 <span class="comment">%subdir='?', the file is first searched with no subdirectory, then in the most recently modified subdirectory if not detected.</span> |
---|
131 | 0044 |
---|
132 | 0045 <span class="comment">% A FAIRE: si comp_inpu=0, si _i_j n'existe pas, chercher _i,</span> |
---|
133 | 0046 <a name="_sub0" href="#_subfunctions" class="code">function [filename,idetect,num_i1_out,num_j1_out,num_i2_out,num_j2_out,subdir_out]=</a><span class="keyword">...</span> |
---|
134 | 0047 name_generator(filebase,num_i1,num_j1,ext,nom_type,comp_input,num_i2,num_j2,subdir); |
---|
135 | 0048 sizf=size(filebase); |
---|
136 | 0049 <span class="keyword">if</span> (~ischar(filebase)||~isequal(sizf(1),1)),filebase=<span class="string">''</span>;<span class="keyword">end</span> |
---|
137 | 0050 <span class="keyword">if</span> ~ischar(ext),ext=<span class="string">''</span>;<span class="keyword">end</span> |
---|
138 | 0051 <span class="comment">% filename=[filebase ext];%default</span> |
---|
139 | 0052 idetect=0; |
---|
140 | 0053 <span class="keyword">if</span> ~exist(<span class="string">'num_i1'</span>,<span class="string">'var'</span>) || isequal(num_i1,[]) |
---|
141 | 0054 num_i1=1; <span class="comment">%default</span> |
---|
142 | 0055 <span class="keyword">end</span> |
---|
143 | 0056 <span class="keyword">if</span> ~exist(<span class="string">'num_j1'</span>,<span class="string">'var'</span>) || isequal(num_j1,[]) |
---|
144 | 0057 num_j1=1; <span class="comment">%default</span> |
---|
145 | 0058 <span class="keyword">end</span> |
---|
146 | 0059 <span class="keyword">if</span> ~exist(<span class="string">'num_i2'</span>,<span class="string">'var'</span>) || isequal(num_i2,[]) |
---|
147 | 0060 num_i2=num_i1; <span class="comment">%default</span> |
---|
148 | 0061 <span class="keyword">end</span> |
---|
149 | 0062 <span class="keyword">if</span> ~exist(<span class="string">'subdir'</span>,<span class="string">'var'</span>)|| isempty(subdir) |
---|
150 | 0063 subdir=<span class="string">''</span> ; <span class="comment">%default</span> |
---|
151 | 0064 <span class="keyword">end</span> |
---|
152 | 0065 <span class="comment">%detection of mask or mean: filebase of the form [root '_' xxx 'm$$$'] with xxx a number and $$$ three characters</span> |
---|
153 | 0066 <span class="keyword">if</span> length(filebase)>4 & filebase(end-3)==<span class="string">'m'</span>; |
---|
154 | 0067 basedouble=double(filebase); |
---|
155 | 0068 val=(48>basedouble)|(basedouble>57);<span class="comment">% select the non-numerical characters</span> |
---|
156 | 0069 i=length(filebase)-4; |
---|
157 | 0070 <span class="keyword">while</span> val(i)==0 & i>0 |
---|
158 | 0071 i=i-1; |
---|
159 | 0072 <span class="keyword">end</span> |
---|
160 | 0073 nbslice=str2num(filebase(i+1:end-4)); |
---|
161 | 0074 <span class="keyword">if</span> ~isequal(nbslice,[]) |
---|
162 | 0075 num_i1=mod(num_i1-1,nbslice)+1; <span class="comment">%take the rest in the division</span> |
---|
163 | 0076 <span class="keyword">if</span> isequal(nom_type,<span class="string">'png_old'</span>)|isequal(nom_type,<span class="string">'#a'</span>) |
---|
164 | 0077 num_j1=1;<span class="comment">% mask name must end by 'a'</span> |
---|
165 | 0078 <span class="keyword">end</span> |
---|
166 | 0079 <span class="keyword">end</span> |
---|
167 | 0080 <span class="keyword">end</span> |
---|
168 | 0081 test_pairs=isequal(nom_type,<span class="string">'netc_old'</span>)| isequal(nom_type,<span class="string">'netc_2D'</span>) | isequal(nom_type,<span class="string">'netc_3D'</span>)| isequal(nom_type,<span class="string">'_i1-i2_j1-j2'</span>)| <span class="keyword">...</span> |
---|
169 | 0082 isequal(nom_type,<span class="string">'netc_series'</span>)| isequal(nom_type,<span class="string">'#_ab'</span>)| isequal(nom_type,<span class="string">'_i_j1-j2'</span>)| isequal(nom_type,<span class="string">'_i1-i2_j'</span>)| isequal(nom_type,<span class="string">'_i1-i2'</span>); |
---|
170 | 0083 test_2D= isequal(nom_type,<span class="string">'netc_old'</span>) |isequal(nom_type,<span class="string">'netc_2D'</span>)|isequal(nom_type,<span class="string">'#_ab'</span>) |isequal(nom_type,<span class="string">'_i_j1-j2'</span>); |
---|
171 | 0084 test_3D=isequal(nom_type,<span class="string">'netc_3D'</span>) |isequal(nom_type,<span class="string">'netc_series'</span>)| isequal(nom_type,<span class="string">'_i1-i2_j'</span>)| isequal(nom_type,<span class="string">'_i1-i2'</span>); |
---|
172 | 0085 <span class="keyword">if</span> isequal(nom_type,<span class="string">'series_i'</span>)| isequal(nom_type,<span class="string">'_i'</span>); |
---|
173 | 0086 filename=[filebase <span class="string">'_'</span> num2str(num_i1) ext]; |
---|
174 | 0087 idetect=(exist(filename,<span class="string">'file'</span>)==2); |
---|
175 | 0088 <span class="keyword">elseif</span> length(nom_type)==5 && isequal(nom_type(1:3),<span class="string">'_%0'</span>)&& isequal(nom_type(5),<span class="string">'d'</span>); |
---|
176 | 0089 filename=[filebase <span class="string">'_'</span> num2str(num_i1,nom_type(2:5)) ext]; |
---|
177 | 0090 idetect=(exist(filename,<span class="string">'file'</span>)==2); |
---|
178 | 0091 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'series_i_j'</span>)| isequal(nom_type,<span class="string">'_i_j'</span>) |
---|
179 | 0092 filename=[filebase <span class="string">'_'</span> num2str(num_i1) <span class="string">'_'</span> num2str(num_j1) ext]; |
---|
180 | 0093 idetect=(exist(filename,<span class="string">'file'</span>)==2); |
---|
181 | 0094 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'png_old'</span>)| isequal(nom_type,<span class="string">'#a'</span>)| isequal(nom_type,<span class="string">'#A'</span>) |
---|
182 | 0095 filename=[filebase num2str(num_i1,<span class="string">'%03d'</span>) <a href="num2stra.html" class="code" title="function str=num2stra(num,nom_type,index);">num2stra</a>(num_j1,nom_type) ext]; |
---|
183 | 0096 idetect=(exist(filename,<span class="string">'file'</span>)==2); |
---|
184 | 0097 <span class="keyword">elseif</span> length(nom_type)>=5 & isequal(nom_type(2:3),<span class="string">'%0'</span>) & isequal(nom_type(5),<span class="string">'d'</span>) <span class="comment">%isequal(nom_type,'_%04dA') %camera PCO Toulouse</span> |
---|
185 | 0098 filename=[filebase nom_type(1) num2str(num_i1,nom_type(2:4)) <a href="num2stra.html" class="code" title="function str=num2stra(num,nom_type,index);">num2stra</a>(num_j1,nom_type) ext]; |
---|
186 | 0099 idetect=(exist(filename,<span class="string">'file'</span>)==2); |
---|
187 | 0100 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'raw_SMD'</span>) <span class="comment">%suffix a, b, c without extension</span> |
---|
188 | 0101 filename=[filebase num2str(num_i1,<span class="string">'%03d'</span>) <a href="num2stra.html" class="code" title="function str=num2stra(num,nom_type,index);">num2stra</a>(num_j1,nom_type)]; |
---|
189 | 0102 idetect=(exist(filename,<span class="string">'file'</span>)==2); |
---|
190 | 0103 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'ima_num'</span>)| isequal(nom_type,<span class="string">'#'</span>) |
---|
191 | 0104 filename=[filebase num2str(num_i1) ext]; |
---|
192 | 0105 idetect=(exist(filename,<span class="string">'file'</span>)==2); |
---|
193 | 0106 <span class="keyword">elseif</span> length(nom_type)>=4 & isequal(nom_type(1:2),<span class="string">'%0'</span>) & isequal(nom_type(end),<span class="string">'d'</span>) |
---|
194 | 0107 filename=[filebase num2str(num_i1,nom_type) ext]; <span class="comment">%test number with a 0 before</span> |
---|
195 | 0108 idetect=(exist(filename,<span class="string">'file'</span>)==2); |
---|
196 | 0109 |
---|
197 | 0110 <span class="comment">%case of derived file indexing (e.g. netcdf files)</span> |
---|
198 | 0111 <span class="keyword">elseif</span> test_pairs |
---|
199 | 0112 <span class="keyword">if</span> (~exist(<span class="string">'num_j2'</span>,<span class="string">'var'</span>)| isequal(num_j2,[])) & test_2D |
---|
200 | 0113 num_j2=num_j1+1; <span class="comment">%default if num_j2 undefined</span> |
---|
201 | 0114 <span class="keyword">end</span> |
---|
202 | 0115 <span class="keyword">if</span> (~exist(<span class="string">'num_i2'</span>,<span class="string">'var'</span>)| isequal(num_i2,[])) & test_3D |
---|
203 | 0116 num_i2=num_i1+1; <span class="comment">%default if num_i2 undefined</span> |
---|
204 | 0117 <span class="keyword">end</span> |
---|
205 | 0118 filebasesub=filebase; |
---|
206 | 0119 <span class="comment">% get the root name filebasesub for the netcdf files</span> |
---|
207 | 0120 <span class="keyword">if</span> ~isequal(subdir,<span class="string">''</span>) && ~isequal(subdir,<span class="string">'?'</span>) |
---|
208 | 0121 [Path,Name]=fileparts(filebase); |
---|
209 | 0122 filebasesub=fullfile(Path,subdir,Name); |
---|
210 | 0123 <span class="keyword">end</span> |
---|
211 | 0124 <span class="comment">%inexistant pair if num_i2=0 or num_j2=0</span> |
---|
212 | 0125 <span class="keyword">if</span> isequal(num_i2,0) |
---|
213 | 0126 filename=[filebasesub <span class="string">'*-*_'</span> num2str(num_i1) ext]; |
---|
214 | 0127 <span class="keyword">return</span> |
---|
215 | 0128 <span class="keyword">end</span> |
---|
216 | 0129 <span class="keyword">if</span> isequal(num_j2,0) |
---|
217 | 0130 filename=[filebasesub <span class="string">'_'</span> num2str(num_i1) <span class="string">'_*-*'</span> ext]; |
---|
218 | 0131 <span class="keyword">return</span> |
---|
219 | 0132 <span class="keyword">end</span> |
---|
220 | 0133 <span class="comment">% case of an imposed image pair (comp_input=1)</span> |
---|
221 | 0134 <span class="keyword">if</span> (exist(<span class="string">'comp_input'</span>,<span class="string">'var'</span>) & isequal(comp_input,1)) |
---|
222 | 0135 <span class="keyword">if</span> isequal(nom_type,<span class="string">'netc_old'</span>)|isequal(nom_type,<span class="string">'#_ab'</span>) |
---|
223 | 0136 <span class="keyword">if</span> isequal(num2str(num_j1),num2str(num_j2))<span class="comment">% case of displacements at the same time</span> |
---|
224 | 0137 filename=[filebasesub num2str(num_i1,<span class="string">'%03d'</span>) <span class="string">'_'</span> <a href="num2stra.html" class="code" title="function str=num2stra(num,nom_type,index);">num2stra</a>(num_j1,nom_type) ext]; |
---|
225 | 0138 <span class="keyword">else</span> |
---|
226 | 0139 filename=[filebasesub num2str(num_i1,<span class="string">'%03d'</span>) <span class="string">'_'</span> <a href="num2stra.html" class="code" title="function str=num2stra(num,nom_type,index);">num2stra</a>(num_j1,nom_type) <a href="num2stra.html" class="code" title="function str=num2stra(num,nom_type,index);">num2stra</a>(num_j2,nom_type) ext]; |
---|
227 | 0140 <span class="keyword">end</span> |
---|
228 | 0141 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'netc_2D'</span>)|isequal(nom_type,<span class="string">'_i_j1-j2'</span>) |
---|
229 | 0142 <span class="keyword">if</span> isequal(num2str(num_j1),num2str(num_j2))<span class="comment">% case of displacements at the same time</span> |
---|
230 | 0143 filename=[filebasesub <span class="string">'_'</span> num2str(num_i1) <span class="string">'_'</span> num2str(num_j1) ext]; |
---|
231 | 0144 <span class="keyword">else</span> |
---|
232 | 0145 filename=[filebasesub <span class="string">'_'</span> num2str(num_i1) <span class="string">'_'</span> num2str(num_j1) <span class="string">'-'</span> num2str(num_j2) ext]; |
---|
233 | 0146 <span class="keyword">end</span> |
---|
234 | 0147 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'netc_3D'</span>) || isequal(nom_type,<span class="string">'_i1-i2_j'</span>) |
---|
235 | 0148 <span class="keyword">if</span> isequal(num2str(num_i1),num2str(num_i2))<span class="comment">% case of displacements at the same time</span> |
---|
236 | 0149 filename=[filebasesub <span class="string">'_'</span> num2str(num_i1) <span class="string">'_'</span> num2str(num_j1) ext]; |
---|
237 | 0150 <span class="keyword">else</span> |
---|
238 | 0151 filename=[filebasesub <span class="string">'_'</span> num2str(num_i1) <span class="string">'-'</span> num2str(num_i2) <span class="string">'_'</span> num2str(num_j1) ext]; |
---|
239 | 0152 <span class="keyword">end</span> |
---|
240 | 0153 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'netc_series'</span>) || isequal(nom_type,<span class="string">'_i1-i2'</span>) |
---|
241 | 0154 <span class="keyword">if</span> isequal(num2str(num_i1),num2str(num_i2))<span class="comment">% case of displacements at the same time</span> |
---|
242 | 0155 filename=[filebasesub <span class="string">'_'</span> num2str(num_i1) ext]; |
---|
243 | 0156 <span class="keyword">else</span> |
---|
244 | 0157 filename=[filebasesub <span class="string">'_'</span> num2str(num_i1) <span class="string">'-'</span> num2str(num_i2) ext]; |
---|
245 | 0158 <span class="keyword">end</span> |
---|
246 | 0159 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'_i1-i2_j1-j2'</span>) |
---|
247 | 0160 <span class="keyword">if</span> isequal(num2str(num_i1),num2str(num_i2))<span class="comment">% case of displacements at the same time</span> |
---|
248 | 0161 app1= [num2str(num_i1)]; |
---|
249 | 0162 <span class="keyword">else</span> |
---|
250 | 0163 app1= [num2str(num_i1) <span class="string">'-'</span> num2str(num_i2)]; |
---|
251 | 0164 <span class="keyword">end</span> |
---|
252 | 0165 <span class="keyword">if</span> isequal(num2str(num_j1),num2str(num_j2))<span class="comment">% case of displacements at the same time</span> |
---|
253 | 0166 app2= [num2str(num_j1)]; |
---|
254 | 0167 <span class="keyword">else</span> |
---|
255 | 0168 app2= [num2str(num_j1) <span class="string">'-'</span> num2str(num_j2)]; |
---|
256 | 0169 <span class="keyword">end</span> |
---|
257 | 0170 filename=[filebasesub <span class="string">'_'</span> app1 <span class="string">'_'</span> app2 ext]; |
---|
258 | 0171 <span class="keyword">end</span> |
---|
259 | 0172 idetect=(exist(filename,<span class="string">'file'</span>)==2); |
---|
260 | 0173 <span class="comment">% case of an image pair to determine (comp_input=0)</span> |
---|
261 | 0174 <span class="keyword">else</span> |
---|
262 | 0175 [filename,num_i1,num_j1,num_i2,num_j2,idetect]=<a href="#_sub1" class="code" title="subfunction [filename,num_i1,num_j1,num_i2,num_j2,idetect]=search_pair(filebasesub,num_i1,num_j1,num_i2,nom_type)">search_pair</a>(filebasesub,num_i1,num_j1,num_i2,nom_type); |
---|
263 | 0176 <span class="keyword">end</span> |
---|
264 | 0177 |
---|
265 | 0178 <span class="comment">%look for sub-directories containing netcdf files</span> |
---|
266 | 0179 <span class="keyword">if</span> idetect==0 && isequal(subdir,<span class="string">'?'</span>) |
---|
267 | 0180 [pathfile,name]=fileparts(filebase); |
---|
268 | 0181 direct=dir(pathfile);<span class="comment">%directory containing filebase</span> |
---|
269 | 0182 datedir=[];<span class="comment">%default</span> |
---|
270 | 0183 idir=0; |
---|
271 | 0184 indir=find(cell2mat({direct.isdir}));<span class="comment">% find indices of subdirectories</span> |
---|
272 | 0185 direct=direct(indir([3:end]));<span class="comment">% keep only the subdirectories,eliminating the two first terms '.' and '..'</span> |
---|
273 | 0186 lengthdir=length(direct); |
---|
274 | 0187 <span class="keyword">if</span> lengthdir==0 |
---|
275 | 0188 subdir=<span class="string">''</span>;<span class="comment">% no subdirectory found</span> |
---|
276 | 0189 <span class="keyword">else</span> |
---|
277 | 0190 <span class="keyword">for</span> idir=1:lengthdir |
---|
278 | 0191 date_str=direct(idir).date;<span class="comment">%string of the date of last modification</span> |
---|
279 | 0192 datedir(idir)=0;<span class="comment">%default</span> |
---|
280 | 0193 char_code=double(date_str);<span class="comment">% code of the date characters</span> |
---|
281 | 0194 special_char=(char_code>127); <span class="comment">%non standard Ascii character (e.g. date in french)</span> |
---|
282 | 0195 <span class="keyword">if</span> isempty(find(special_char))<span class="comment">% standard Ascii character</span> |
---|
283 | 0196 datedir(idir)=datenum(date_str); |
---|
284 | 0197 <span class="keyword">end</span> |
---|
285 | 0198 <span class="comment">% datedir(idir)=datenum(direct(idir).date); %absolute date of last directory modification</span> |
---|
286 | 0199 <span class="keyword">end</span> |
---|
287 | 0200 [mostrec,indrec]=max(datedir);<span class="comment">% most recently modified subdir chosen by default</span> |
---|
288 | 0201 subdir=direct(indrec).name; <span class="comment">%chosen directory</span> |
---|
289 | 0202 <span class="keyword">end</span> |
---|
290 | 0203 filebasesub=fullfile(pathfile,subdir,name); |
---|
291 | 0204 <span class="comment">%if the image pair is imposed</span> |
---|
292 | 0205 <span class="keyword">if</span> (exist(<span class="string">'comp_input'</span>,<span class="string">'var'</span>) & isequal(comp_input,1)) |
---|
293 | 0206 <span class="keyword">if</span> isequal(nom_type,<span class="string">'netc_old'</span>)|isequal(nom_type,<span class="string">'#_ab'</span>) |
---|
294 | 0207 filename=[filebasesub num2str(num_i1,<span class="string">'%03d'</span>) <span class="string">'_'</span> <a href="num2stra.html" class="code" title="function str=num2stra(num,nom_type,index);">num2stra</a>(num_j1,nom_type) <a href="num2stra.html" class="code" title="function str=num2stra(num,nom_type,index);">num2stra</a>(num_j2,nom_type) ext]; |
---|
295 | 0208 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'netc_2D'</span>)|isequal(nom_type,<span class="string">'_i1_j1-j2'</span>) |
---|
296 | 0209 filename=[filebasesub <span class="string">'_'</span> num2str(num_i1) <span class="string">'_'</span> num2str(num_j1) <span class="string">'-'</span> num2str(num_i2) ext]; |
---|
297 | 0210 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'netc_3D'</span>)|isequal(nom_type,<span class="string">'_i1-i2_j'</span>) |
---|
298 | 0211 filename=[filebasesub <span class="string">'_'</span> num2str(num_i1) <span class="string">'-'</span> num2str(num_i2) <span class="string">'_'</span> num2str(num_j1) ext]; |
---|
299 | 0212 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'netc_series'</span>)|isequal(nom_type,<span class="string">'_i1-i2'</span>) |
---|
300 | 0213 filename=[filebasesub <span class="string">'_'</span> num2str(num_i1) <span class="string">'-'</span> num2str(num_i2) ext]; |
---|
301 | 0214 <span class="keyword">end</span> |
---|
302 | 0215 idetect=(exist(filename,<span class="string">'file'</span>)==2); |
---|
303 | 0216 <span class="keyword">else</span> |
---|
304 | 0217 [filename,num_i1,num_j1,num_i2,num_j2,idetect]=<a href="#_sub1" class="code" title="subfunction [filename,num_i1,num_j1,num_i2,num_j2,idetect]=search_pair(filebasesub,num_i1,num_j1,num_i2,nom_type)">search_pair</a>(filebasesub,num_i1,num_j1,num_i2,nom_type); |
---|
305 | 0218 <span class="keyword">end</span> |
---|
306 | 0219 <span class="keyword">end</span> |
---|
307 | 0220 <span class="comment">% elseif isequal(nom_type,'none')|isequal(nom_type,'')|isequal(nom_type,'*')</span> |
---|
308 | 0221 <span class="keyword">else</span> |
---|
309 | 0222 filebasesub=filebase; |
---|
310 | 0223 <span class="keyword">if</span> ~isequal(subdir,<span class="string">''</span>) && ~isequal(subdir,<span class="string">'?'</span>) |
---|
311 | 0224 [Path,Name]=fileparts(filebase); |
---|
312 | 0225 filebasesub=fullfile(Path,subdir,Name); |
---|
313 | 0226 <span class="keyword">end</span> |
---|
314 | 0227 filename=[filebasesub ext]; |
---|
315 | 0228 idetect=(exist(filename,<span class="string">'file'</span>)==2); |
---|
316 | 0229 <span class="keyword">end</span> |
---|
317 | 0230 num_i1_out=num_i1; |
---|
318 | 0231 num_j1_out=num_j1; |
---|
319 | 0232 <span class="keyword">if</span> exist(<span class="string">'num_i2'</span>,<span class="string">'var'</span>), num_i2_out=num_i2; <span class="keyword">else</span>, num_i2_out=[]; <span class="keyword">end</span>; |
---|
320 | 0233 <span class="keyword">if</span> exist(<span class="string">'num_j2'</span>,<span class="string">'var'</span>), num_j2_out=num_j2; <span class="keyword">else</span>, num_j2_out=[]; <span class="keyword">end</span>; |
---|
321 | 0234 <span class="keyword">if</span> ~isequal(subdir,<span class="string">'?'</span>), subdir_out=subdir; <span class="keyword">else</span>, subdir_out=<span class="string">''</span>;<span class="keyword">end</span>; |
---|
322 | 0235 |
---|
323 | 0236 <span class="comment">%---------------------------------------------------------------</span> |
---|
324 | 0237 <span class="comment">% search the appropriate image pair (netcdf file) corresponding to a given</span> |
---|
325 | 0238 <span class="comment">% image number</span> |
---|
326 | 0239 <span class="comment">%-------------------------------------------------------------------</span> |
---|
327 | 0240 <a name="_sub1" href="#_subfunctions" class="code">function [filename,num_i1,num_j1,num_i2,num_j2,idetect]=search_pair(filebasesub,num_i1,num_j1,num_i2,nom_type)</a> |
---|
328 | 0241 <span class="comment">% for nom_type=netc_2D or netc_old, it searches all the pairs corresponding</span> |
---|
329 | 0242 <span class="comment">% to num_i1, and chooses the most recent file.</span> |
---|
330 | 0243 <span class="comment">%for nom_type=netc_3D or netc_series, it searches all the pairs (num_i1</span> |
---|
331 | 0244 <span class="comment">%num_i2), with num_i1 as the first index, and chooses the most recent file.</span> |
---|
332 | 0245 |
---|
333 | 0246 filename=[];num_j2=[];idetect=0;<span class="comment">%default values</span> |
---|
334 | 0247 <span class="keyword">if</span> isequal(nom_type,<span class="string">'netc_old'</span>)|isequal(nom_type,<span class="string">'#_ab'</span>) |
---|
335 | 0248 dirpair=dir([filebasesub num2str(num_i1,<span class="string">'%03d'</span>) <span class="string">'_*.nc'</span>]); |
---|
336 | 0249 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'netc_2D'</span>)|isequal(nom_type,<span class="string">'_i_j1-j2'</span>) |
---|
337 | 0250 dirpair=dir([filebasesub <span class="string">'_'</span> num2str(num_i1) <span class="string">'_*-*.nc'</span>]); |
---|
338 | 0251 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'netc_3D'</span>)|isequal(nom_type,<span class="string">'_i1-i2_j'</span>) |
---|
339 | 0252 dirpair=dir([filebasesub <span class="string">'_'</span> num2str(num_i1) <span class="string">'-*_'</span> num2str(num_j1) <span class="string">'.nc'</span>]); |
---|
340 | 0253 <span class="keyword">elseif</span> isequal(nom_type,<span class="string">'netc_series'</span>)|isequal(nom_type,<span class="string">'_i1-i2'</span>) |
---|
341 | 0254 dirpair=dir([filebasesub <span class="string">'_'</span> num2str(num_i1) <span class="string">'-*.nc'</span>]); |
---|
342 | 0255 <span class="keyword">if</span> isempty(dirpair) |
---|
343 | 0256 dirpair=dir([filebasesub <span class="string">'_*-'</span> num2str(num_i2) <span class="string">'.nc'</span>]); |
---|
344 | 0257 <span class="keyword">end</span> |
---|
345 | 0258 <span class="keyword">end</span> |
---|
346 | 0259 nbpair=length(dirpair); |
---|
347 | 0260 <span class="keyword">if</span> nbpair >= 1 <span class="comment">%choose the most recent file if several are found</span> |
---|
348 | 0261 idetect=1; <span class="comment">%detected pair</span> |
---|
349 | 0262 <span class="keyword">for</span> ipair=1:nbpair |
---|
350 | 0263 date_str=dirpair(ipair).date;<span class="comment">%string of the date of last modification</span> |
---|
351 | 0264 datepair(ipair)=0;<span class="comment">%default</span> |
---|
352 | 0265 char_code=double(date_str);<span class="comment">% code of the date characters</span> |
---|
353 | 0266 special_char=(char_code>127); <span class="comment">%non standard Ascii character (e.g. date in french)</span> |
---|
354 | 0267 <span class="keyword">if</span> isempty(find(special_char))<span class="comment">% standard Ascii character</span> |
---|
355 | 0268 datepair(ipair)=datenum(date_str); |
---|
356 | 0269 <span class="keyword">end</span> |
---|
357 | 0270 <span class="comment">% datepair(ipair)=datenum(dirpair(ipair).date);</span> |
---|
358 | 0271 <span class="keyword">end</span> |
---|
359 | 0272 [choice,indpair]=max(datepair); |
---|
360 | 0273 <span class="comment">% [filebase,field_count,str2,str_a,str_b,ext,nom_type]=name2display(dirpair(indpair).name);</span> |
---|
361 | 0274 [pathname,file,field_count,str2,str_a,str_b,ext,nom_type]=<a href="name2display.html" class="code" title="function [RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput)">name2display</a>(dirpair(indpair).name); |
---|
362 | 0275 num_i1=str2num(field_count); |
---|
363 | 0276 num_i2=str2num(str2); |
---|
364 | 0277 num_j1=<a href="stra2num.html" class="code" title="function numres=stra2num(str)">stra2num</a>(str_a); |
---|
365 | 0278 num_j2=<a href="stra2num.html" class="code" title="function numres=stra2num(str)">stra2num</a>(str_b); |
---|
366 | 0279 pathname=fileparts(filebasesub);<span class="comment">% CORRIGE LE 6 JUIN (ETAIT DESACTIVE)</span> |
---|
367 | 0280 filename=fullfile(pathname,dirpair(indpair).name); |
---|
368 | 0281 <span class="keyword">end</span> |
---|
369 | 0282 |
---|
370 | 0283</pre></div> |
---|
371 | <hr><address>Generated on Fri 13-Nov-2009 11:17:03 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address> |
---|
372 | </body> |
---|
373 | </html> |
---|