1 | %'read_xls': function for reading and displaying Excel files
|
---|
2 | %------------------------------------------------------------------------
|
---|
3 | % function [hfig_xls]=read_xls(fileinput,hfig)
|
---|
4 | %
|
---|
5 | % OUTPUT:
|
---|
6 | % hfig_xls: figure handle for display
|
---|
7 | %
|
---|
8 | % INPUT:
|
---|
9 | % fileinput: name of the input file (char string)
|
---|
10 | % hfig: handle of the display figure (a new display figure hfig_xls is created if hfig undefined)
|
---|
11 | %
|
---|
12 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
13 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
|
---|
14 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
15 | % This file is part of the toolbox UVMAT.
|
---|
16 | %
|
---|
17 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
18 | % it under the terms of the GNU General Public License as published by
|
---|
19 | % the Free Software Foundation; either version 2 of the License, or
|
---|
20 | % (at your option) any later version.
|
---|
21 | %
|
---|
22 | % UVMAT is distributed in the hope that it will be useful,
|
---|
23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
25 | % GNU General Public License (file UVMAT/COPYING.txt) for more details.
|
---|
26 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
27 |
|
---|
28 | function [hfig_xls]=read_xls(fileinput,hfig)
|
---|
29 | [Tabnum,Tabtext]=xlsread(fileinput);
|
---|
30 | [textnx,textny]=size(Tabtext);
|
---|
31 | [numnx,numny]=size(Tabnum);
|
---|
32 | ilastxt=textnx-numnx;%index of last text row
|
---|
33 | jlastxt=textny-numny;%index of last text column
|
---|
34 | for jtab=1:textny%read line
|
---|
35 | for itab=1:textnx% read column
|
---|
36 | textlu=cell2mat(Tabtext(itab,jtab));
|
---|
37 | if isequal(textlu,[])& itab > ilastxt & jtab > jlastxt %replace txt by number
|
---|
38 | textlu=num2str(Tabnum(itab-ilastxt,jtab-jlastxt));
|
---|
39 | end
|
---|
40 | Tabdisplay(itab,jtab)={textlu};
|
---|
41 | lengthtext(itab)=length(textlu);
|
---|
42 | end
|
---|
43 | widthcolumn(jtab)=max(lengthtext);
|
---|
44 | end
|
---|
45 | Tabchar={};%default
|
---|
46 | for itab=1:textnx %justify table
|
---|
47 | charchain=[];
|
---|
48 | for jtab=1:textny% read line
|
---|
49 | textlu=Tabdisplay{itab,jtab};
|
---|
50 | if widthcolumn(jtab)>length(textlu)
|
---|
51 | blankstr=char(46*ones(1,widthcolumn(jtab)-length(textlu)));
|
---|
52 | textlu=[textlu blankstr ];
|
---|
53 | end
|
---|
54 | charchain=[charchain textlu char(9) ' | '];
|
---|
55 | end
|
---|
56 | Tabchar(itab)={charchain};
|
---|
57 | end
|
---|
58 | if exist('hfig','var') & ishandle(hfig)
|
---|
59 | figure(hfig);
|
---|
60 | hfig_xls=hfig;
|
---|
61 | else
|
---|
62 | hfig_xls=figure;
|
---|
63 | end
|
---|
64 | set(hfig_xls,'Name',fileinput)
|
---|
65 | set(hfig_xls,'MenuBar','none')
|
---|
66 | hpos=get(hfig_xls,'Pos');
|
---|
67 | ExpName.cell=Tabtext([2:textnx],1);%first column (dir name)
|
---|
68 | ExpName.Num=Tabnum;
|
---|
69 | % ExpName.Units=Tabtext(2,[2:textny]);%look for the units line (needs to be the second line)
|
---|
70 | iparam=0;
|
---|
71 | for icol=2:textny
|
---|
72 | % Tabtext(2,icol)
|
---|
73 | if ~isempty(Tabtext{2,icol})&~isequal(Tabtext{2,icol},'')
|
---|
74 | iparam=iparam+1;
|
---|
75 | ExpName.Param{iparam}=Tabtext{1,icol};
|
---|
76 | ExpName.Units{iparam}=Tabtext{2,icol};
|
---|
77 | ExpName.Column(iparam)=icol;
|
---|
78 | end
|
---|
79 | end
|
---|
80 |
|
---|
81 | ExpName.path=fileparts(fileinput);
|
---|
82 | h=uicontrol('Style','listbox', 'Position', [5 5 0.9*hpos(3) 0.9*hpos(4)], 'String', Tabchar, ...
|
---|
83 | 'FontName','Monospaced','Callback',@link2file,'UserData',ExpName,'Tag','listbox');
|
---|
84 | % hh=uicontrol('Style','Pushbutton', 'Position', [0.93*hpos(1) 0.93*hpos(2) 0.05*hpos(3) 0.05*hpos(4)], 'String', 'Update','Callback',@project_update);
|
---|
85 | % set(h,'HorizontalAlignment','left')
|
---|
86 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
87 | %called by xlsdisplay to navigate from a .xls file or create the
|
---|
88 | % the experiment directories
|
---|
89 | function link2file(obj,event,fileinput)
|
---|
90 | global t
|
---|
91 | bla=get(gcbo,'String');
|
---|
92 | ind=get(gcbo,'Value')
|
---|
93 | if (ind==1|ind==2),return,end; %no action on the first line
|
---|
94 | ExpNameStruct=get(gcbo,'UserData')
|
---|
95 | ExpName=ExpNameStruct.cell{ind-1}
|
---|
96 | ProjectFullName=ExpNameStruct.path;%full name of the project (including path)
|
---|
97 | [Pth,ProjectName]=fileparts(ProjectFullName);
|
---|
98 | ExpPath=fullfile(ProjectFullName,ExpName);% full name of the experiment directory
|
---|
99 | ExpDocName=fullfile(ExpPath,[ExpName '.xml']);% full name of the .xml file ExpDoc
|
---|
100 | if exist(ExpDocName,'file')
|
---|
101 | hh=editxml({ExpDocName})
|
---|
102 | % [FileName, PathName, filterindex] = uigetfile( ...
|
---|
103 | % {'*.xml','(*.xml)';
|
---|
104 | % '*.xml', '.xml files ';
|
---|
105 | % '*.*', 'All Files (*.*)'}, ...
|
---|
106 | % 'Pick a file',ExpDocName);
|
---|
107 | % fileinput=[PathName FileName];%complete file name
|
---|
108 | % sizf=size(fileinput);
|
---|
109 | % if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
|
---|
110 | % [path,name,ext]=fileparts(fileinput);
|
---|
111 | % if isequal(ext,'.civ') | isequal(ext,'.log') | isequal(ext,'.cmx') isequal(ext,'.txt')
|
---|
112 | % edit(fileinput)
|
---|
113 | % elseif isequal(ext,'.xml')
|
---|
114 | % varargin{1}=fileinput;
|
---|
115 | % editxml(varargin)
|
---|
116 | % elseif isequal(ext,'.fig')
|
---|
117 | % open(fileinput)
|
---|
118 | % elseif isequal(ext,'.xls')
|
---|
119 | % xlsdisplay(fileinput)
|
---|
120 | % else
|
---|
121 | % uvmat({fileinput})
|
---|
122 | % end
|
---|
123 | else
|
---|
124 | answer=questdlg({['ExpDoc file ' ExpDocName ' does not exist, create the experiment?'];''})
|
---|
125 | if isequal(answer,'Yes')
|
---|
126 | if exist(ExpPath,'dir')~=7 %create a directory if it does not exist
|
---|
127 | dircur=pwd; %current working directory
|
---|
128 | cd(ProjectFullName);
|
---|
129 | [m1,m2,m3]=mkdir(ExpName);
|
---|
130 | cd(pwd);%come back to the initial working dir
|
---|
131 | end
|
---|
132 | % %copy exp parameters
|
---|
133 | ParamNames=ExpNameStruct.Param;
|
---|
134 | ParamValues=ExpNameStruct.Num(ind-1,ExpNameStruct.Column-1);
|
---|
135 | ParamUnits=ExpNameStruct.Units;
|
---|
136 | t=xmltree;%new xmltree
|
---|
137 | t=set(t,1,'name','ExpDoc');
|
---|
138 | t=attributes(t,'add',1,'xmlns:xsi','none');
|
---|
139 | [t,ExpElement]=add(t,1,'element','Exp');
|
---|
140 | [t]=add(t,ExpElement,'chardata',ExpName);
|
---|
141 | for iparam=1:length(ParamNames)
|
---|
142 | [t,ParamElement]=add(t,1,'element',ParamNames{iparam});
|
---|
143 | t=add(t,ParamElement,'chardata',num2str(ParamValues(iparam)));
|
---|
144 | t=attributes(t,'add',ParamElement,'unit',ParamUnits{iparam}); %ADD UNIT ATTRIBUTE
|
---|
145 | end
|
---|
146 | list_dir=dir(ExpPath);%list of the Exp directory, detect sub-directories,.xml and image files
|
---|
147 | nbdir_exp=0;
|
---|
148 | %scan the Exp directory
|
---|
149 | for idir_exp=3:length(list_dir)
|
---|
150 | %detect subdirectories
|
---|
151 | if list_dir(idir_exp).isdir% 'device' subdirectories
|
---|
152 | nbdir_exp=nbdir_exp+1;
|
---|
153 | ExpData.Device{nbdir_exp}=list_dir(idir_exp).name;
|
---|
154 | [t,DeviceElement]=add(t,1,'element',list_dir(idir_exp).name);
|
---|
155 | t=attributes(t,'add',DeviceElement,'type','DEVICE_DIR');
|
---|
156 | t=attributes(t,'add',DeviceElement,'source','dir');
|
---|
157 | list_subdir=dir(fullfile(ExpPath,list_dir(idir_exp).name));
|
---|
158 | nbsubdir=0;
|
---|
159 | testrecord=1;
|
---|
160 | RootIma='';
|
---|
161 | RootNc='';
|
---|
162 | nbfile=0;
|
---|
163 | % nbfile={};
|
---|
164 | %scan the Device subdirectory
|
---|
165 | for isubdir=3:length(list_subdir)
|
---|
166 | if list_subdir(isubdir).isdir
|
---|
167 | nbsubdir=nbsubdir+1;
|
---|
168 | Device.Record{nbsubdir}=list_subdir(isubdir).name;
|
---|
169 | else
|
---|
170 | nbfile=nbfile+1;
|
---|
171 | fname{nbfile}=list_subdir(isubdir).name;
|
---|
172 | end
|
---|
173 | end
|
---|
174 | if isunix%sort by root names and indices , change the separator '_' so that 1_1 come as the first name
|
---|
175 | fname_mod=regexprep(fname,'_','/');
|
---|
176 | fname_mod=sort(fname_mod); %sort by name
|
---|
177 | fname=regexprep(fname_mod,'/','_');
|
---|
178 | end
|
---|
179 | for ifile=1:nbfile;
|
---|
180 | [Path,Name,Ext]=fileparts(fname{ifile});
|
---|
181 | if isequal(Ext,'.xml')
|
---|
182 | [t,ImaDocElement]=add(t,DeviceElement,'element','ImaDoc');
|
---|
183 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
184 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
185 | testrecord=0;%we have an image series without 'record' subdir
|
---|
186 | elseif isequal(Ext,'.png')
|
---|
187 | [Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
|
---|
188 | if ~isequal(Root,RootIma)%only one image recorded for each root name
|
---|
189 | [t,ImaDocElement]=add(t,DeviceElement,'element','Image');
|
---|
190 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
191 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
192 | RootIma=Root;
|
---|
193 | end
|
---|
194 | testrecord=0;%we have an image series without 'record' subdir
|
---|
195 | elseif isequal(Ext,'.nc')
|
---|
196 | [Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
|
---|
197 | if ~isequal(Root,RootNc)%only one image recorded for each root name
|
---|
198 | [t,ImaDocElement]=add(t,DeviceElement,'element','Ncdata');
|
---|
199 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
200 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
201 | RootNc=Root;
|
---|
202 | end
|
---|
203 | testrecord=0;%we have an image series without 'record' subdir
|
---|
204 | end
|
---|
205 | end
|
---|
206 | if testrecord
|
---|
207 | %the subdevice directory is 'record' (no images detected at this level)
|
---|
208 | for idir_s=1:nbsubdir
|
---|
209 | [t,RecordElement]=add(t,DeviceElement,'element',Device.Record{idir_s});
|
---|
210 | t=attributes(t,'add',RecordElement,'type','RECORD_DIR');
|
---|
211 | t=attributes(t,'add',RecordElement,'source','dir');
|
---|
212 | list_subdir=dir(fullfile(ExpPath,list_dir(idir_exp).name,Device.Record{idir_s}));
|
---|
213 | nbsubdir=0;
|
---|
214 | RootIma='';
|
---|
215 | RootNc='';
|
---|
216 | nbfile=0;
|
---|
217 | fname={};
|
---|
218 | for isubdir=3:length(list_subdir)
|
---|
219 | if list_subdir(isubdir).isdir
|
---|
220 | nbsubdir=nbsubdir+1;
|
---|
221 | [t,RecordElement]=add(t,DeviceElement,'element',Device.Record{idir_exp});
|
---|
222 | t=attributes(t,'add',RecordElement,'type','RECORD_DIR');
|
---|
223 | t=attributes(t,'add',RecordElement,'source','dir');
|
---|
224 | %VOIR les .netcdf a l'interieur
|
---|
225 | else
|
---|
226 | nbfile=nbfile+1;
|
---|
227 | fname{nbfile}=list_subdir(isubdir).name;
|
---|
228 | end
|
---|
229 | end
|
---|
230 | if isunix
|
---|
231 | fname_mod=regexprep(fname,'_','/');
|
---|
232 | fname_mod=sort(fname_mod); %sort by name
|
---|
233 | fname=regexprep(fname_mod,'/','_');
|
---|
234 | end
|
---|
235 | for ifile=1:nbfile;
|
---|
236 | [Path,Name,Ext]=fileparts(fname{ifile});
|
---|
237 | if isequal(Ext,'.xml')
|
---|
238 | [t,ImaDocElement]=add(t,DeviceElement,'element','ImaDoc');
|
---|
239 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
240 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
241 | elseif isequal(Ext,'.png')
|
---|
242 | [Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
|
---|
243 | if ~isequal(Root,RootIma)
|
---|
244 | [t,ImaDocElement]=add(t,DeviceElement,'element','Image');
|
---|
245 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
246 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
247 | RootIma=Root;
|
---|
248 | end
|
---|
249 | elseif isequal(Ext,'.nc')
|
---|
250 | [Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
|
---|
251 | if ~isequal(Root,RootNc)%only one image recorded for each root name
|
---|
252 | [t,ImaDocElement]=add(t,DeviceElement,'element','Ncdata');
|
---|
253 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
254 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
255 | RootNc=Root;
|
---|
256 | end
|
---|
257 | end
|
---|
258 | end
|
---|
259 | end
|
---|
260 | else%the subdevice directory is a civ directory (coexist with images)
|
---|
261 | for idir_s=1:nbsubdir
|
---|
262 | [t,RecordElement]=add(t,DeviceElement,'element',Device.Record{idir_s});
|
---|
263 | t=attributes(t,'add',RecordElement,'type','CIV_DIR');
|
---|
264 | t=attributes(t,'add',RecordElement,'source','dir');
|
---|
265 | %list files under the civ directory
|
---|
266 | list_subdir=dir(fullfile(ExpPath,list_dir(idir_exp).name,Device.Record{idir_s}));
|
---|
267 |
|
---|
268 | nbsubdir=0;
|
---|
269 | nbfile=0;
|
---|
270 | RootXml='';
|
---|
271 | RootNc='';
|
---|
272 | fname={};
|
---|
273 | for isubdir=3:length(list_subdir)
|
---|
274 | if list_subdir(isubdir).isdir
|
---|
275 | nbsubdir=nbsubdir+1;
|
---|
276 | [t,SubElement]=add(t,RecordElement,'element',list_subdir(isubdir).name);
|
---|
277 | t=attributes(t,'add',SubElement,'type','UNKNOWN_DIR');
|
---|
278 | t=attributes(t,'add',SubElement,'source','dir');
|
---|
279 | else
|
---|
280 | nbfile=nbfile+1;
|
---|
281 | fname{nbfile}=list_subdir(isubdir).name;
|
---|
282 | end
|
---|
283 | end
|
---|
284 | if isunix
|
---|
285 | fname_mod=regexprep(fname,'_','/');
|
---|
286 | fname_mod=sort(fname_mod); %sort by name
|
---|
287 | fname=regexprep(fname_mod,'/','_');
|
---|
288 | end
|
---|
289 | for ifile=1:nbfile;
|
---|
290 | [Path,Name,Ext]=fileparts(fname{ifile});
|
---|
291 | if isequal(Ext,'.xml')
|
---|
292 | [Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
|
---|
293 | if ~isequal(Root,RootXml)%only one image recorded for each root name
|
---|
294 | [t,ImaDocElement]=add(t,RecordElement,'element','CivDoc');
|
---|
295 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
296 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
297 | RootXml=Root;
|
---|
298 | end
|
---|
299 | elseif isequal(Ext,'.nc')
|
---|
300 | [Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
|
---|
301 | if ~isequal(Root,RootNc)%only one image recorded for each root name
|
---|
302 | [t,ImaDocElement]=add(t,RecordElement,'element','Ncdata');
|
---|
303 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
304 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
305 | RootNc=Root;
|
---|
306 | end
|
---|
307 | end
|
---|
308 | end
|
---|
309 | end
|
---|
310 | end
|
---|
311 | end
|
---|
312 | end
|
---|
313 | save(t);%display xml file on the screen
|
---|
314 | save(t,ExpDocName);
|
---|
315 | end
|
---|
316 | end
|
---|
317 | % [erread,message]=fileattrib('./DATA');
|
---|
318 | % if ~isempty(message) & ~isequal(message.UserWrite,1)
|
---|
319 | % errordlg(['Need writting access to ' message.Name])
|
---|
320 | % return
|
---|
321 | % end
|
---|
322 |
|
---|
323 |
|
---|
324 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
325 | function project_update(obj,event,fileinput)
|
---|
326 | hchild=get(gcbf,'children');
|
---|
327 | h=findobj(gcbf,'Tag','listbox')
|
---|
328 | |
---|