[8] | 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')
|
---|
[343] | 187 | %[Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
|
---|
| 188 | [~,~,Root]=fileparts_uvmat(fname{ifile});
|
---|
[8] | 189 | if ~isequal(Root,RootIma)%only one image recorded for each root name
|
---|
| 190 | [t,ImaDocElement]=add(t,DeviceElement,'element','Image');
|
---|
| 191 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
| 192 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
| 193 | RootIma=Root;
|
---|
| 194 | end
|
---|
| 195 | testrecord=0;%we have an image series without 'record' subdir
|
---|
| 196 | elseif isequal(Ext,'.nc')
|
---|
[343] | 197 | %[Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
|
---|
| 198 | [~,~,Root]=fileparts_uvmat(fname{ifile});
|
---|
[8] | 199 | if ~isequal(Root,RootNc)%only one image recorded for each root name
|
---|
| 200 | [t,ImaDocElement]=add(t,DeviceElement,'element','Ncdata');
|
---|
| 201 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
| 202 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
| 203 | RootNc=Root;
|
---|
| 204 | end
|
---|
| 205 | testrecord=0;%we have an image series without 'record' subdir
|
---|
| 206 | end
|
---|
| 207 | end
|
---|
| 208 | if testrecord
|
---|
| 209 | %the subdevice directory is 'record' (no images detected at this level)
|
---|
| 210 | for idir_s=1:nbsubdir
|
---|
| 211 | [t,RecordElement]=add(t,DeviceElement,'element',Device.Record{idir_s});
|
---|
| 212 | t=attributes(t,'add',RecordElement,'type','RECORD_DIR');
|
---|
| 213 | t=attributes(t,'add',RecordElement,'source','dir');
|
---|
| 214 | list_subdir=dir(fullfile(ExpPath,list_dir(idir_exp).name,Device.Record{idir_s}));
|
---|
| 215 | nbsubdir=0;
|
---|
| 216 | RootIma='';
|
---|
| 217 | RootNc='';
|
---|
| 218 | nbfile=0;
|
---|
| 219 | fname={};
|
---|
| 220 | for isubdir=3:length(list_subdir)
|
---|
| 221 | if list_subdir(isubdir).isdir
|
---|
| 222 | nbsubdir=nbsubdir+1;
|
---|
| 223 | [t,RecordElement]=add(t,DeviceElement,'element',Device.Record{idir_exp});
|
---|
| 224 | t=attributes(t,'add',RecordElement,'type','RECORD_DIR');
|
---|
| 225 | t=attributes(t,'add',RecordElement,'source','dir');
|
---|
| 226 | %VOIR les .netcdf a l'interieur
|
---|
| 227 | else
|
---|
| 228 | nbfile=nbfile+1;
|
---|
| 229 | fname{nbfile}=list_subdir(isubdir).name;
|
---|
| 230 | end
|
---|
| 231 | end
|
---|
| 232 | if isunix
|
---|
| 233 | fname_mod=regexprep(fname,'_','/');
|
---|
| 234 | fname_mod=sort(fname_mod); %sort by name
|
---|
| 235 | fname=regexprep(fname_mod,'/','_');
|
---|
| 236 | end
|
---|
| 237 | for ifile=1:nbfile;
|
---|
| 238 | [Path,Name,Ext]=fileparts(fname{ifile});
|
---|
| 239 | if isequal(Ext,'.xml')
|
---|
| 240 | [t,ImaDocElement]=add(t,DeviceElement,'element','ImaDoc');
|
---|
| 241 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
| 242 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
| 243 | elseif isequal(Ext,'.png')
|
---|
[343] | 244 | % [Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
|
---|
| 245 | [~,~,Root]=fileparts_uvmat(fname{ifile});
|
---|
[8] | 246 | if ~isequal(Root,RootIma)
|
---|
| 247 | [t,ImaDocElement]=add(t,DeviceElement,'element','Image');
|
---|
| 248 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
| 249 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
| 250 | RootIma=Root;
|
---|
| 251 | end
|
---|
| 252 | elseif isequal(Ext,'.nc')
|
---|
[343] | 253 | %[Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
|
---|
| 254 | [~,~,Root]=fileparts_uvmat(fname{ifile});
|
---|
[8] | 255 | if ~isequal(Root,RootNc)%only one image recorded for each root name
|
---|
| 256 | [t,ImaDocElement]=add(t,DeviceElement,'element','Ncdata');
|
---|
| 257 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
| 258 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
| 259 | RootNc=Root;
|
---|
| 260 | end
|
---|
| 261 | end
|
---|
| 262 | end
|
---|
| 263 | end
|
---|
| 264 | else%the subdevice directory is a civ directory (coexist with images)
|
---|
| 265 | for idir_s=1:nbsubdir
|
---|
| 266 | [t,RecordElement]=add(t,DeviceElement,'element',Device.Record{idir_s});
|
---|
| 267 | t=attributes(t,'add',RecordElement,'type','CIV_DIR');
|
---|
| 268 | t=attributes(t,'add',RecordElement,'source','dir');
|
---|
| 269 | %list files under the civ directory
|
---|
| 270 | list_subdir=dir(fullfile(ExpPath,list_dir(idir_exp).name,Device.Record{idir_s}));
|
---|
| 271 |
|
---|
| 272 | nbsubdir=0;
|
---|
| 273 | nbfile=0;
|
---|
| 274 | RootXml='';
|
---|
| 275 | RootNc='';
|
---|
| 276 | fname={};
|
---|
| 277 | for isubdir=3:length(list_subdir)
|
---|
| 278 | if list_subdir(isubdir).isdir
|
---|
| 279 | nbsubdir=nbsubdir+1;
|
---|
| 280 | [t,SubElement]=add(t,RecordElement,'element',list_subdir(isubdir).name);
|
---|
| 281 | t=attributes(t,'add',SubElement,'type','UNKNOWN_DIR');
|
---|
| 282 | t=attributes(t,'add',SubElement,'source','dir');
|
---|
| 283 | else
|
---|
| 284 | nbfile=nbfile+1;
|
---|
| 285 | fname{nbfile}=list_subdir(isubdir).name;
|
---|
| 286 | end
|
---|
| 287 | end
|
---|
| 288 | if isunix
|
---|
| 289 | fname_mod=regexprep(fname,'_','/');
|
---|
| 290 | fname_mod=sort(fname_mod); %sort by name
|
---|
| 291 | fname=regexprep(fname_mod,'/','_');
|
---|
| 292 | end
|
---|
| 293 | for ifile=1:nbfile;
|
---|
| 294 | [Path,Name,Ext]=fileparts(fname{ifile});
|
---|
| 295 | if isequal(Ext,'.xml')
|
---|
[343] | 296 | %[Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
|
---|
| 297 | [~,~,Root]=fileparts_uvmat(fname{ifile});
|
---|
[8] | 298 | if ~isequal(Root,RootXml)%only one image recorded for each root name
|
---|
| 299 | [t,ImaDocElement]=add(t,RecordElement,'element','CivDoc');
|
---|
| 300 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
| 301 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
| 302 | RootXml=Root;
|
---|
| 303 | end
|
---|
| 304 | elseif isequal(Ext,'.nc')
|
---|
[343] | 305 | %[Path,Root,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fname{ifile});
|
---|
| 306 | [~,~,Root]=fileparts_uvmat(fname{ifile});
|
---|
[8] | 307 | if ~isequal(Root,RootNc)%only one image recorded for each root name
|
---|
| 308 | [t,ImaDocElement]=add(t,RecordElement,'element','Ncdata');
|
---|
| 309 | t=add(t,ImaDocElement,'chardata',fname{ifile});
|
---|
| 310 | t=attributes(t,'add',ImaDocElement,'source','file');
|
---|
| 311 | RootNc=Root;
|
---|
| 312 | end
|
---|
| 313 | end
|
---|
| 314 | end
|
---|
| 315 | end
|
---|
| 316 | end
|
---|
| 317 | end
|
---|
| 318 | end
|
---|
| 319 | save(t);%display xml file on the screen
|
---|
| 320 | save(t,ExpDocName);
|
---|
| 321 | end
|
---|
| 322 | end
|
---|
| 323 | % [erread,message]=fileattrib('./DATA');
|
---|
| 324 | % if ~isempty(message) & ~isequal(message.UserWrite,1)
|
---|
| 325 | % errordlg(['Need writting access to ' message.Name])
|
---|
| 326 | % return
|
---|
| 327 | % end
|
---|
| 328 |
|
---|
| 329 |
|
---|
| 330 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 331 | function project_update(obj,event,fileinput)
|
---|
| 332 | hchild=get(gcbf,'children');
|
---|
| 333 | h=findobj(gcbf,'Tag','listbox')
|
---|
| 334 | |
---|