Changeset 1180 for trunk/src/uvmat.m


Ignore:
Timestamp:
Mar 27, 2025, 5:59:21 PM (3 weeks ago)
Author:
sommeria
Message:

various bugs repaired,Relabeling frames installed for multitif

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uvmat.m

    r1179 r1180  
    517517    end
    518518end
    519 
    520 
    521 
    522 % -----------------------------------------------------------------------
    523 % --- Executes on the menu Open/Browse campaign...
    524 % --- search the file inside a campaign, using the GUI browse_data
    525 % -----------------------------------------------------------------------
    526 function MenuBrowseCampaign_Callback(hObject, eventdata, handles)
    527 % set(handles.MenuOpenCampaign,'ForegroundColor',[1 1 0])
    528 % drawnow
    529 [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
    530 DataSeries=fullfile(RootPath,SubDir);
    531 if isempty(DataSeries) %loads the previously stored file name and set it as default in the file_input box
    532     DataSeries=get(handles.RootPath,'UserData');
    533 end
    534 OutPut=browse_data(DataSeries,'on');% open the GUI browse_data to get select a campaign dir, experiment and device
    535 if ~isfield(OutPut,'Campaign')
    536     return
    537 end
    538 DataSeries=fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1});
    539 fileinput=uigetfile_uvmat('pick an input file',DataSeries);
    540 hh=dir(fileinput);
    541 if numel(hh)>1
    542     msgbox_uvmat('ERROR','invalid input, probably a broken link');
    543     return
    544 end
    545 
    546 %% update the list of campaigns in the menubar
    547 MenuCampaign=[{get(handles.MenuCampaign_1,'Label')};{get(handles.MenuCampaign_2,'Label')};...
    548     {get(handles.MenuCampaign_3,'Label')};{get(handles.MenuCampaign_4,'Label')};{get(handles.MenuCampaign_5,'Label')}];
    549 check_dir=isempty(find(strcmp(DataSeries,MenuCampaign)));
    550 if check_dir %insert the new campaign in the list if it is not found
    551     MenuCampaign(end)=[]; %suppress the last item
    552     MenuCampaign=[{DataSeries};MenuCampaign];%insert the new campaign
    553     for ilist=1:numel(MenuCampaign)
    554         set(handles.(['MenuCampaign_' num2str(ilist)]),'Label',MenuCampaign{ilist})
    555     end
    556     % save the list for future opening:
    557     dir_perso=prefdir;
    558     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    559     if exist(profil_perso,'file')
    560         save (profil_perso,'MenuCampaign','RootPath','-append'); %store the file names for future opening of uvmat
    561     else
    562         save (profil_perso,'MenuCampaign','RootPath','-V6'); %store the file names for future opening of uvmat
    563     end
    564 end
    565 
    566 %% display the selected field and related information
    567 %display_file_name( handles,fullfile(DirName,FileName))
    568 display_file_name( handles,fileinput)
    569 set(handles.MenuOpenCampaign,'ForegroundColor',[0 0 0])
    570 
    571 % -----------------------------------------------------------------------
    572 % --- Open again as second field the file whose name has been recorded in MenuFile_1
    573 % -----------------------------------------------------------------------
    574 function MenuCampaign_Callback(hObject, eventdata, handles)
    575 
    576 set(handles.MenuOpenCampaign,'ForegroundColor',[1 1 0])
    577 OutPut=browse_data(get(hObject,'Label'),'on');% open the GUI browse_data to get select a campaign dir, experiment and device
    578 if isfield(OutPut,'Campaign')
    579     fileinput=uigetfile_uvmat('pick an input file',fullfile(OutPut.Campaign,OutPut.Experiment{1},OutPut.DataSeries{1}));
    580     hh=dir(fileinput);
    581     if numel(hh)>1
    582         msgbox_uvmat('ERROR','invalid input, probably a broken link');
    583     else
    584         display_file_name(handles,fileinput)
    585     end
    586 end
    587 set(handles.MenuOpenCampaign,'ForegroundColor',[0 0 0])
    588 
    589519
    590520%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    11691099%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    11701100%------------------------------------------------------------------------
     1101function MenuRuler_Callback(hObject, eventdata, handles)
     1102%------------------------------------------------------------------------
     1103if strcmp(get(handles.MenuRuler,'checked'),'on')
     1104    set(handles.MenuRuler,'checked','off')%desactivate if activated
     1105else
     1106    set(handles.MenuRuler,'checked','on')%activate if selected
     1107    set(handles.CheckZoom,'Value',0)
     1108    CheckZoom_Callback(handles.uvmat, [], handles)
     1109    UvData=get(handles.uvmat,'UserData');
     1110    UvData.MouseAction='ruler';
     1111    set(handles.uvmat,'UserData',UvData);
     1112end
     1113
     1114%------------------------------------------------------------------------
    11711115function MenuCalib_Callback(hObject, eventdata, handles)
    11721116%------------------------------------------------------------------------
     
    19951939set_grid(FileName,UvData.Field);% call the set_object interface
    19961940
    1997 
    1998 %------------------------------------------------------------------------
    1999 function MenuRuler_Callback(hObject, eventdata, handles)
    2000 %------------------------------------------------------------------------
    2001 if strcmp(get(handles.MenuRuler,'checked'),'on')
    2002     set(handles.MenuRuler,'checked','off')%desactivate if activated
    2003 else
    2004     set(handles.MenuRuler,'checked','on')%activate if selected
    2005     set(handles.CheckZoom,'Value',0)
    2006     CheckZoom_Callback(handles.uvmat, [], handles)
    2007     UvData=get(handles.uvmat,'UserData');
    2008     UvData.MouseAction='ruler';
    2009     set(handles.uvmat,'UserData',UvData);
     1941%------------------------------------------------------------------------
     1942%-- introduce a section FileSeries in the xml file ImaDoc to virtually relabel frames
     1943% --------------------------------------------------------------------
     1944function MenuRelabelFrames_Callback(hObject, eventdata, handles)
     1945
     1946[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
     1947FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];
     1948CheckAbort=false;
     1949if strcmp(get(handles.MenuRelabelFrames,'checked'),'off')% if the option is selected
     1950    if strcmp(FileExt,'.tif') && ~isempty(regexp(RootFile,'^im', 'once'))% case of PCO images, document <FileSeries> in the xml file
     1951        FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];
     1952        FileInfo=get_file_info(FileName);
     1953        XmlFile=fullfile(RootPath,[SubDir '.xml']);
     1954        [XmlData,errormsg]=imadoc2struct(XmlFile);
     1955        if ~isempty(errormsg)
     1956            disp(['a file ' XmlFile ' is needed to document the timing'])
     1957            CheckAbort=true;
     1958        elseif ~isfield(XmlData,'FileSeries')% fill the FleSeries if does not exist
     1959            FileSeries.Convention='PCO';
     1960            FileSeries.FileName{1,1}='im.tif';
     1961            FileSeries.FileName{2,1}='im@0001.tif';
     1962            FileSeries.NbFramePerFile=FileInfo.NumberOfFrames;
     1963            [checkupdate,xmlfile,errormsg]=update_imadoc(RootPath,SubDir,'FileSeries',FileSeries);
     1964            if isempty(errormsg)
     1965                disp([xmlfile 'updated with FileSeries'])
     1966            else
     1967                disp(errormsg)
     1968                CheckAbort=true;
     1969            end
     1970        end
     1971    end
     1972    if ~CheckAbort
     1973    set(handles.MenuRelabelFrames,'checked','on')
     1974    end
     1975else
     1976    set(handles.MenuRelabelFrames,'checked','off')%if the option was chcked, uncheck it
     1977end
     1978if ~CheckAbort
     1979    errormsg=display_file_name(handles,FileName,1);
     1980    if ~isempty(errormsg)
     1981        disp(errormsg)
     1982    end
    20101983end
    20111984
     
    20151988
    20161989%------------------------------------------------------------------------
    2017 % open the GUI 'series'
     1990% open the GUI 'series' with the current file series as input
    20181991function MenuRun1_Callback(hObject, eventdata, handles)
    20191992%------------------------------------------------------------------------
    20201993MenuRun(hObject,handles);
    20211994
    2022 
     1995%------------------------------------------------------------------------
     1996% open the GUI 'series' with the current file series as input
    20231997% --------------------------------------------------------------------
    20241998function MenuRun2_Callback(hObject, eventdata, handles)
    20251999MenuRun(hObject,handles);
    2026 % Param=read_GUI(handles.uvmat);
    2027 % Param.HiddenData=get(handles.uvmat,'UserData');
    2028 % hseries=series(Param);
    2029 % hhseries=guidata(hseries);
    2030 % ActionMenu=get(hhseries.ActionName,'String');
    2031 % index_action=find(strcmp('civ_series',ActionMenu));
    2032 % set(hhseries.ActionName,'Value',index_action);
    2033 % series('ActionName_Callback',hObject,eventdata,hhseries); %file input with xml reading  in uvmat, show the image in phys coordinates
    2034 
     2000
     2001%------------------------------------------------------------------------
     2002% open the GUI 'series' with the current file series as input
    20352003% --------------------------------------------------------------------
    20362004function MenuRun3_Callback(hObject, eventdata, handles)
    20372005MenuRun(hObject,handles);
    2038 % Param=read_GUI(handles.uvmat);
    2039 % Param.HiddenData=get(handles.uvmat,'UserData');
    2040 % hseries=series(Param);
    2041 % hhseries=guidata(hseries);
    2042 % ActionMenu=get(hhseries.ActionName,'String');
    2043 % index_action=find(strcmp('test_filter_tps',ActionMenu));
    2044 % set(hhseries.ActionName,'Value',index_action);
    2045 % series('ActionName_Callback',hObject,eventdata,hhseries); %file input with xml reading  in uvmat, show the image in phys coordinates
    2046 
     2006
     2007%------------------------------------------------------------------------
     2008% open the GUI 'series' with the current file series as input
     2009% --------------------------------------------------------------------
    20472010function MenuRun(hObject,handles)
    20482011Param=read_GUI(handles.uvmat);
     
    23112274        elseif isfield(FileInfo,'VolumeScan')
    23122275            Mask.VolumeScan=FileInfo.VolumeScan;
    2313 end
    2314 set(handles.CheckMask,'UserData', Mask)
     2276        end
     2277        set(handles.CheckMask,'UserData', Mask)
    23152278    else
    23162279        set(handles.CheckMask,'Value',0)
    23172280        CheckMask_Callback(handles.CheckMask, [], handles)
    2318 end
     2281    end
    23192282else %read the current field index to synchronise with the first series
    23202283    i1_s=str2double(get(handles.i1,'String'));
     
    24192382set(handles.FixVelType,'Value',0); %desactivate fixed veltype by default
    24202383
    2421 %% look for the xml file and read it
    2422 XmlFileName=find_imadoc(RootPath,SubDir);
     2384%% look for the ImaDoc xml file and read it
     2385XmlFileName=find_imadoc(RootPath,SubDir);% search the appropriate ImaDoc xml file
    24232386[~,XmlName]=fileparts(XmlFileName);
    24242387warntext='';%default warning message
    24252388NbSlice=1;%default
    2426 %CheckImaDoc=false;
    24272389TimeUnit='';%default
    24282390TimeName='';%default
    2429 CheckIndexing=false;%default
    24302391XmlData=[];
    2431 if isempty(XmlFileName)
     2392if isempty(XmlFileName) %no ImaDoc xml file detected
    24322393    set(handles.view_xml,'Visible','off')
    24332394else
     
    24412402    end
    24422403    if ~isempty(XmlData)
    2443         %CheckImaDoc=true;
    24442404        if isfield(XmlData,'TimeUnit')&& ~isempty(XmlData.TimeUnit)
    24452405            TimeUnit=XmlData.TimeUnit;
    24462406        end
    24472407        if isfield(XmlData,'Time')&& ~isempty(XmlData.Time)
    2448             TimeName='xml';%
    2449             if XmlData.Time(1,:)==XmlData.Time(2,:)% case starting with index 1
    2450                 sizDti=size(XmlData.Time,1)-1;%size of the time vector explicitly defined in the xml file
    2451                 ind_start=1;
    2452             else
    2453                 sizDti=size(XmlData.Time,1);% case starting with index 0
    2454                 ind_start=0;
    2455             end
    2456             if isfield(XmlData,'FileSeries')
    2457                 if strcmp(XmlName,SubDir)% frame indexing documented from the xml file (case PCO)
    2458                     CheckIndexing=true;
    2459                 else
    2460                     XmlData=rmfield(XmlData,'FileSeries');%desactivate file indexing option for derived file series
    2461                 end
     2408            TimeName='xml';%Time possibly documented by the xml file (but priority to the opened file if available)
     2409%             if XmlData.Time(1,:)==XmlData.Time(2,:)% case starting with index 1
     2410%                 sizDti=size(XmlData.Time,1)-1;%size of the time vector explicitly defined in the xml file
     2411%                 ind_start=1;
     2412%             else
     2413%                 sizDti=size(XmlData.Time,1);% case starting with index 0
     2414%                 ind_start=0;
     2415%             end
     2416            if isfield(XmlData,'FileSeries')&& ~strcmp(XmlName,SubDir)
     2417                  XmlData=rmfield(XmlData,'FileSeries');%desactivate file indexing option for derived file series (e.g. images.png)
    24622418            end
    24632419        end
     
    24702426    end
    24712427end
     2428XmlData.FileInfo=FileInfo;
    24722429
    24732430%% get the file series
    24742431MovieObject=[];
    2475 if strcmp(TimeName,'xml') && strcmp(XmlName,SubDir)% get the image series info from the xml file
    2476     [nbfield,nbfield_j]=size(XmlData.Time);
    2477     nbfield=nbfield-1; %remove the possible index 0
    2478     nbfield_j=nbfield_j-1; %remove the possible index 0
     2432if strcmp(get(handles.MenuRelabelFrames,'checked'),'on') && isfield(XmlData,'FileSeries') && isfield(XmlData.FileSeries,'FileName')
     2433    CheckIndexing=true;
     2434    NomType='*';
     2435    i1_series=[];
     2436    i2_series=[];
     2437    j1_series=[];
     2438    j2_series=[];
     2439    nbfield=[];
     2440    nbfield_j=[];
     2441
     2442    %     if iscell(XmlData.FileSeries.FileName)
     2443    %         [RootPath,SubDir,RootFile,i1,i2,j1,j2,Ext,NomType]=fileparts_uvmat(XmlData.FileSeries.FileName{1});
     2444    %     else
     2445    %     [RootPath,SubDir,RootFile,i1,i2,j1,j2,Ext,NomType]=fileparts_uvmat(XmlData.FileSeries.FileName);
     2446    %     end
     2447    if strcmp(TimeName,'xml') %&& CheckIndexing% get the image series info from the xml file
     2448        [nbfield,nbfield_j]=size(XmlData.Time);
     2449        nbfield=nbfield-1; %remove the possible index 0
     2450        nbfield_j=nbfield_j-1; %remove the possible index 0
    24792451        i1_series=zeros(nbfield,nbfield_j,1);
    2480     i1_series(:,:,1)=(1:nbfield)'*ones(1,nbfield_j);
    2481     i2_series=i1_series;
    2482     if nbfield_j==1
    2483         j1_series=[];
    2484     else
    2485     j1_series(:,:,1)=ones(nbfield,1)*(1:nbfield_j);
    2486     end
    2487     j2_series=j1_series;
    2488 else % scan the input folder to get the list of existing files
    2489     [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileInfo,MovieObject,i1,i2,j1,j2]=...
     2452        i1_series(:,:,1)=(1:nbfield)'*ones(1,nbfield_j);
     2453        i2_series=i1_series;
     2454        if nbfield_j==1
     2455            j1_series=[];
     2456        else
     2457            j1_series(:,:,1)=ones(nbfield,1)*(1:nbfield_j);
     2458        end
     2459        j2_series=j1_series;
     2460    end
     2461    set(handles.i1,'String','1')
     2462    set(handles.j1,'String','1')
     2463else % scan the input folder to get the list of existing files and NomType
     2464    CheckIndexing=false;
     2465    [~,~,~,i1_series,i2_series,j1_series,j2_series,NomType,FileInfo,MovieObject]=...
    24902466        find_file_series(fullfile(RootPath,SubDir),FileName);
    24912467    nbfield=max(max(max(i2_series)));% total number of fields (i index)
     
    24972473        nbfield_j=max(max(max(j1_series)));
    24982474    end
    2499     if input_line==1
     2475    if ~isempty(j1_series)&& ~strcmp(NomType,'*')% the j index is used to label the frame in multimage series
     2476        set(handles.j1,'String','1')
     2477    end
     2478end
     2479if input_line==1
    25002480    set(handles.NomType,'String',NomType)
    2501     else
    2502          set(handles.NomType_1,'String',NomType)
    2503     end
    2504 end
    2505 if CheckIndexing
    2506     i1=str2double(get(handles.FileIndex,'String'));
    2507     if isnan(i1)
    2508         i1=1;
    2509     else
    2510     i1=(i1-XmlData.FileSeries.FirstFileIndex)*XmlData.FileSeries.NbFramePerFile+1;%frame index deduced from input file index
    2511     end
    2512     if strcmp(TimeName,'xml')% indices i and j
    2513                 j1=mod(i1-1,nbfield_j)+1;
    2514                 i1=floor((i1-1)/nbfield_j)+1;
    2515                 set(handles.j1,'String',num2str(j1))
    2516     end
    2517     set(handles.i1,'String',num2str(i1))
    2518 end
     2481else
     2482    set(handles.NomType_1,'String',NomType)
     2483end
     2484% if CheckIndexing
     2485% %     i1=str2double(get(handles.FileIndex,'String'));
     2486% %     if isnan(i1)
     2487% %         i1=1;
     2488% %     else
     2489% %         i1=(i1-XmlData.FileSeries.FirstFileIndex)*XmlData.FileSeries.NbFramePerFile+1;%frame index deduced from input file index
     2490% %     end
     2491% %     if strcmp(TimeName,'xml')% indices i and j
     2492% %         j1=mod(i1-1,nbfield_j)+1;
     2493% %         i1=floor((i1-1)/nbfield_j)+1;
     2494% %         set(handles.j1,'String',num2str(j1))
     2495% %     end
     2496% %     set(handles.i1,'String',num2str(i1))
     2497%
     2498% end
    25192499
    25202500
     
    25342514%% read timing and total frame number from the current file (e.g. movie files)
    25352515ColorType='falsecolor'; %default
    2536 if isfield(FileInfo,'FrameRate')% frame rate given in the file (case of video data)
     2516if ~CheckIndexing && isfield(FileInfo,'FrameRate')% frame rate given in the file (case of video data)
    25372517    TimeUnit='s';
    25382518    if isempty(j1_series) %frame index along i
     
    25622542%% read parameters (time, geometric calibration..) from a documentation file (.xml advised)
    25632543%XmlData.GeometryCalib=[];%default
    2564 if input_line==1
    2565     [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
    2566 else
    2567     [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
    2568 end
     2544% if input_line==1
     2545%     [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
     2546% else
     2547%     [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
     2548% end
    25692549
    25702550%% Define timing
     
    26292609            set(handles.TransformName,'Value',3); % phys transform by default if fixedLimits is off
    26302610        end
    2631         if isfield(XmlData.Slice,'SliceCoord')
     2611        if isfield(XmlData,'Slice') && isfield(XmlData.Slice,'SliceCoord')
    26322612           siz=size(XmlData.Slice.SliceCoord);
    26332613           if siz(1)>1
     
    32623242    set(handles.CheckFixPair,'Value',0)
    32633243end
    3264 CheckFixPair=get(handles.CheckFixPair,'Value')||(isempty(i2)&& isempty(j2));
     3244%CheckFixPair=get(handles.CheckFixPair,'Value')||(isempty(i2)&& isempty(j2));
    32653245
    32663246% the pair i1-i2 or j1-j2 is imposed (check box CheckFixPair selected)
     
    34413421    if strcmp(NomType,'level')
    34423422        indices=num2str(i1);
    3443     elseif isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'FileSeries')
     3423    elseif strcmp(get(handles.MenuRelabelFrames,'Checked'),'on') && isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'FileSeries')
    34443424        NbField_j_cell=get(handles.MaxIndex_j,'String');
    34453425        NbField_j=str2double(NbField_j_cell{1});
    3446         [RootFile,indices,FrameIndex]=index2filename(UvData.XmlData{1}.FileSeries,i1,j1,NbField_j);
     3426        [RootFile,FrameIndex]=index2filename(UvData.XmlData{1}.FileSeries,i1,j1,NbField_j);
     3427        [~,RootFile]=fileparts(RootFile);%suppress the file extension
    34473428        set(handles.RootFile,'String',RootFile)
     3429        indices='';
    34483430    else
    34493431        indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,j2);
     
    36513633        return
    36523634    end
    3653     [FNameMulti,FileIndexString,frame_index]=index2filename(UvData.XmlData{1}.FileSeries,num_i1,num_j1,NbField_j);
    3654     FileName=fullfile(RootName,[FNameMulti FileIndexString Ext]);
     3635    [FileName,frame_index]=index2filename(UvData.XmlData{1}.FileSeries,num_i1,num_j1,NbField_j);
     3636    FileName=fullfile(RootName,FileName);
    36553637end
    36563638switch UvData.FileInfo{1}.FieldType
     
    38713853        set(handles.VelType_1,'String',[{''};menu])
    38723854    else
    3873          set(handles.VelType_1,'Visible','off')
     3855        set(handles.VelType_1,'Visible','off')
    38743856    end
    38753857    % update the second field menu: the same quantity
     
    38943876end
    38953877
    3896 %% display time value of the current file
     3878%% display time value of the current field
    38973879abstime=[];%default inputs
    38983880dt=[];
     
    39033885TimeName=get(handles.TimeName,'String');
    39043886
    3905 % time from xml file or video movie
    3906 if strcmp(TimeName,'xml')||strcmp(TimeName,'video')
    3907     if isempty(num_i2)||isnan(num_i2)
    3908         num_i2=num_i1;
    3909     end
    3910     if isempty(num_j1)||isnan(num_j1)
    3911         num_j1=1;
    3912     end
    3913     if isempty(num_j2)||isnan(num_j2)
    3914         num_j2=num_j1;
    3915     end
    3916     siz=size(UvData.XmlData{1}.Time);
    3917     if ~isempty(num_i1)&& ~isempty(num_i2) && num_i1>=0 &&siz(1)>=max(num_i1+1,num_i2+1) && siz(2)>=max(num_j1+1,num_j2+1)
    3918         abstime=(UvData.XmlData{1}.Time(num_i1+1,num_j1+1)+UvData.XmlData{1}.Time(num_i2+1,num_j2+1))/2;%overset the time read from files
    3919         dt=(UvData.XmlData{1}.Time(num_i2+1,num_j2+1)-UvData.XmlData{1}.Time(num_i1+1,num_j1+1));
    3920         Field{1}.Dt=dt;
    3921         if isfield(UvData.XmlData{1},'TimeUnit')
    3922             TimeUnit=UvData.XmlData{1}.TimeUnit;
    3923         end
    3924     end
    3925 end
    3926 
    3927 % time in the input file, not defined in a xml file or movie
    3928 if isempty(abstime)
    3929     if (strcmp(TimeName,'civdata')||strcmp(TimeName,'civx')||strcmp(TimeName,'timestamp'))&&isfield(Field{1},'Time')
    3930         abstime=Field{1}.Time;
    3931     elseif ~isempty(regexp(TimeName,'^att:', 'once'))
    3932         abstime=Field{1}.(TimeName(5:end));%the time is an attribute  selected by get_file
    3933         if isfield(Field{1},[TimeName(5:end) 'Unit'])
    3934             TimeUnit=Field{1}.([TimeName(5:end) 'Unit']);
     3887switch TimeName
     3888    case 'xml'   % time from ImaDoc xml file
     3889        if isempty(num_i2)||isnan(num_i2)
     3890            num_i2=num_i1;
     3891        end
     3892        if isempty(num_j1)||isnan(num_j1)
     3893            num_j1=1;
     3894        end
     3895        if isempty(num_j2)||isnan(num_j2)
     3896            num_j2=num_j1;
     3897        end
     3898        siz=size(UvData.XmlData{1}.Time);
     3899        if ~isempty(num_i1)&& ~isempty(num_i2) && num_i1>=0 &&siz(1)>=max(num_i1+1,num_i2+1) && siz(2)>=max(num_j1+1,num_j2+1)
     3900            abstime=(UvData.XmlData{1}.Time(num_i1+1,num_j1+1)+UvData.XmlData{1}.Time(num_i2+1,num_j2+1))/2;%overset the time read from files
     3901            dt=(UvData.XmlData{1}.Time(num_i2+1,num_j2+1)-UvData.XmlData{1}.Time(num_i1+1,num_j1+1));
     3902            Field{1}.Dt=dt;
     3903            if isfield(UvData.XmlData{1},'TimeUnit')
     3904                TimeUnit=UvData.XmlData{1}.TimeUnit;
     3905            end
     3906        end
     3907
     3908    case 'video'% time  obtained from the frame rate in video file
     3909        if isempty(num_i2)% single video record with frame index num_i1
     3910            abstime=num_i1/UvData.XmlData{1}.FileInfo.FrameRate;
    39353911        else
    3936             TimeUnit='';
    3937         end
    3938     elseif  ~isempty(regexp(TimeName,'^var:', 'once'))
    3939         abstime=Field{1}.(TimeName(5:end));%the time is a variale selected by get_file
    3940         % TODO: look for time unit attribute
    3941     elseif ~isempty(regexp(TimeName,'^dim:'))
    3942         abstime=str2double(get(handles.i1,'String'));
    3943         TimeUnit='index';
    3944     end
    3945     if isfield(Field{1},'Dt')
    3946         dt=Field{1}.Dt;%dt read from the netcdf input file
    3947     elseif numel(Field)==2 && isfield(Field{2},'Dt')%dt obtained from the second field if not defined in the first
    3948         dt=Field{2}.Dt;%dt read from the netcdf input file
    3949     end
     3912            abstime=num_i2/UvData.XmlData{1}.FileInfo.FrameRate;% set of video records with frame index num_i2
     3913        end
     3914        TimeUnit='s';
     3915
     3916    otherwise  % time sought  in the input file
     3917        if (strcmp(TimeName,'civdata')||strcmp(TimeName,'civx')||strcmp(TimeName,'timestamp'))&&isfield(Field{1},'Time')
     3918            abstime=Field{1}.Time;
     3919        elseif ~isempty(regexp(TimeName,'^att:', 'once'))
     3920            abstime=Field{1}.(TimeName(5:end));%the time is an attribute  selected by get_file
     3921            if isfield(Field{1},[TimeName(5:end) 'Unit'])
     3922                TimeUnit=Field{1}.([TimeName(5:end) 'Unit']);
     3923            else
     3924                TimeUnit='';
     3925            end
     3926        elseif  ~isempty(regexp(TimeName,'^var:', 'once'))
     3927            abstime=Field{1}.(TimeName(5:end));%the time is a variale selected by get_file
     3928            % TODO: look for time unit attribute
     3929        elseif ~isempty(regexp(TimeName,'^dim:', 'once'))
     3930            abstime=str2double(get(handles.i1,'String'));
     3931            TimeUnit='index';
     3932        end
     3933        if isfield(Field{1},'Dt')
     3934            dt=Field{1}.Dt;%dt read from the netcdf input file
     3935        elseif numel(Field)==2 && isfield(Field{2},'Dt')%dt obtained from the second field if not defined in the first
     3936            dt=Field{2}.Dt;%dt read from the netcdf input file
     3937        end
    39503938end
    39513939set(handles.TimeValue,'String',num2str(abstime))
     
    62496237
    62506238
     6239
     6240
Note: See TracChangeset for help on using the changeset viewer.