Changeset 355 for trunk/src


Ignore:
Timestamp:
Dec 30, 2011, 7:40:59 PM (13 years ago)
Author:
sommeria
Message:

civ updated with new functions for opening files, consistently with uvmat
Bugs to be expected (use previous version then)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/civ.m

    r354 r355  
    102102%% prepare the GUI with parameters from the input file if opened from uvmat
    103103if exist('fileinput','var')% && isfield(param,'RootName') && ~isempty(param.RootName)
     104    set(handles.RootName,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
    104105    errormsg=display_file_name(handles,fileinput);
    105106    if ~isempty(errormsg)
    106107        msgbox_uvmat('ERROR',errormsg)
    107108    end
     109    set(handles.RootName,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
    108110end
    109111
     
    205207
    206208%% prepare the GUI with parameters from the input file
     209set(handles.RootName,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
    207210errormsg=display_file_name(handles,fileinput);
    208211if ~isempty(errormsg)
    209212    msgbox_uvmat('ERROR',erromsg)
    210213end
    211 
     214set(handles.RootName,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
    212215
    213216%------------------------------------------------------------------------
     
    215218function MenuFile_1_Callback(hObject, eventdata, handles)
    216219%------------------------------------------------------------------------
     220set(handles.RootName,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
    217221fileinput=get(handles.MenuFile_1,'Label');
    218222errormsg=display_file_name(handles,fileinput);
    219223if ~isempty(errormsg)
    220     msgbox_uvmat('ERROR',erromsg)
    221 end
     224    msgbox_uvmat('ERROR',errormsg)
     225end
     226set(handles.RootName,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
    222227
    223228% -----------------------------------------------------------------------
     
    225230function MenuFile_2_Callback(hObject, eventdata, handles)
    226231%------------------------------------------------------------------------
     232set(handles.RootName,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
    227233fileinput=get(handles.MenuFile_2,'Label');
    228234errormsg=display_file_name(handles,fileinput);
    229235if ~isempty(errormsg)
    230     msgbox_uvmat('ERROR',erromsg)
    231 end
     236    msgbox_uvmat('ERROR',errormsg)
     237end
     238set(handles.RootName,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
    232239
    233240% -----------------------------------------------------------------------
     
    235242function MenuFile_3_Callback(hObject, eventdata, handles)
    236243%------------------------------------------------------------------------
     244set(handles.RootName,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
    237245fileinput=get(handles.MenuFile_3,'Label');
    238246errormsg=display_file_name(handles,fileinput);
    239247if ~isempty(errormsg)
    240     msgbox_uvmat('ERROR',erromsg)
    241 end
     248    msgbox_uvmat('ERROR',errormsg)
     249end
     250set(handles.RootName,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
    242251
    243252% -----------------------------------------------------------------------
     
    245254function MenuFile_4_Callback(hObject, eventdata, handles)
    246255%------------------------------------------------------------------------
     256set(handles.RootName,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
    247257fileinput=get(handles.MenuFile_4,'Label');
    248258errormsg=display_file_name(handles,fileinput);
    249259if ~isempty(errormsg)
    250     msgbox_uvmat('ERROR',erromsg)
    251 end
     260    msgbox_uvmat('ERROR',errormsg)
     261end
     262set(handles.RootName,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
    252263
    253264% -----------------------------------------------------------------------
     
    255266function MenuFile_5_Callback(hObject, eventdata, handles)
    256267%------------------------------------------------------------------------
     268set(handles.RootName,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
    257269fileinput=get(handles.MenuFile_5,'Label');
    258270errormsg=display_file_name(handles,fileinput);
    259271if ~isempty(errormsg)
    260     msgbox_uvmat('ERROR',erromsg)
    261 end
    262 
     272    msgbox_uvmat('ERROR',errormsg)
     273end
     274set(handles.RootName,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
    263275% -----------------------------------------------------------------------
    264276% --- Prepare the GUI for the compiled CivX program
     
    308320function RootName_Callback(hObject, eventdata, handles)
    309321%------------------------------------------------------------------------
     322set(handles.RootName,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
    310323filebase=get(handles.RootName,'String');
    311324errormsg=display_file_name(handles,filebase);
     
    313326    msgbox_uvmat('ERROR',erromsg)
    314327end
    315 
     328set(handles.RootName,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
    316329%------------------------------------------------------------------------
    317330% --- general function activated for an input file series
     
    320333set(handles.ListCompareMode,'Visible','on')
    321334errormsg='';%default empty error message
     335drawnow
    322336
    323337%% enable RUN, BATCH button and 'status' display
     
    333347%% determine nomenclature types and extension of the input files
    334348ext_ima='';%default
    335 nom_type_ima='';%default
    336 nom_type_nc='';
     349NomTypeIma='';%default
     350NomTypeNc='';
    337351%[RootPath,RootFile,i1_str,i2_str,j1_str,j2_str,ext_input,nom_type_input,SubDir]=name2display(fileinput);
    338 [RootPath,SubDir,RootFile,i1,i2,j1,j2,ext_input,nom_type_input]=fileparts_uvmat(fileinput);
     352[RootPath,SubDir,RootFile,i1,i2,j1,j2,ExtInput,NomTypeInput]=fileparts_uvmat(fileinput);
     353[RootPath,RootFile,i1_series,i2_series,j1_series,j2_series,NomTypeInput,FileType,Object]=find_file_series(fileinput);
     354if strcmp(NomTypeInput,'*')% movies will be opened at the first frame
     355    i1=1;
     356    i2=[];
     357    j1=[];
     358    j2=[];
     359end 
     360ind_opening=0;%default
     361switch FileType
     362    case 'civdata'
     363        Data=nc2struct(fileinput,'ListGlobalAttribute','CivStage','Civ1_ImageA');
     364        if isfield(Data,'Txt')
     365            errormsg=Data.Txt;
     366            return
     367        end
     368        if ~isempty(Data.CivStage)%test for civ files
     369            ind_opening=Data.CivStage;
     370        end
     371        if ~isempty(Data.Civ1_ImageA)%test for civ files
     372            imageinput=Data.Civ1_ImageA;
     373            if ~exist(imageinput,'file')
     374                errormsg=['the image ' imageinput ' does not exist, please enter an image'];
     375                return
     376            end
     377        end
     378        set(handles.MenuMatlab,'checked','on')
     379        set(handles.MenuCivX,'checked','off')
     380        NomTypeNc=NomTypeInput;
     381    case 'civx'
     382        Data=nc2struct(fileinput,'ListGlobalAttribute','fix','patch','civ2','fix2');
     383        if ~isempty(Data.fix2)
     384            ind_opening=5;
     385        elseif ~isempty(Data.civ2)
     386            ind_opening=4;
     387        elseif ~isempty(Data.patch)
     388            ind_opening=3;
     389        elseif ~isempty(Data.fix)
     390            ind_opening=2;
     391        end
     392        % look for the input images
     393        check_letter=~isempty(regexp(NomTypeInput,'[ab|AB]$'));%detect pair label by letter
     394        NomTypeIma=NomTypeInput;
     395        if check_letter
     396            NomTypeIma=NomTypeInput(1:end-1);
     397        else
     398            r=regexp(NomTypeIma,'.-(?<num2>\d+$','names');
     399            if ~isempty(r)
     400                NomTypeIma=regexprep(NomTypeIma,['-' r.num2],'');
     401            end
     402        end
     403        imageinput=fullfile_uvmat(RootPath,'',RootFile,'.png',NomTypeIma,i1,[],j1);
     404        if ~exist(imageinput,'file')
     405            errormsg='no image corresponds to the input .nc file, please open an image';
     406            return
     407        end
     408    case {'image','multimage','video'}
     409         imageinput=fileinput;
     410         NomTypeIma=NomTypeInput;
     411         ext_ima=ExtInput;
     412    otherwise
     413        errormsg='invalid input file: enter an image, a movie or .nc file';
     414end
     415[RootPath,RootFile,i1_series,i2_series,j1_series,j2_series,NomTypeIma,ImageType,Object]=find_file_series(imageinput);
    339416RootName=fullfile(RootPath,RootFile);
    340417set(handles.RootName,'String',RootName)
    341 set(handles.RootName,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
    342 drawnow
    343 % i1=str2double(i1_str);
    344 % i2=str2double(i2_str);
    345 % j1=str2double(j1_str);
    346 % j2=str2double(j2_str);
     418MaxIndex_i=max(i1_series(i1_series>0));
     419MaxIndex_j=max(j1_series(j1_series>0));
     420
    347421num_ref_i=i1;%efaulmt ref index
    348422num_ref_j=j1;
    349423browse=get(handles.RootName,'UserData');
     424browse.nom_type_nc=NomTypeNc;
     425browse.nom_type_ima=NomTypeInput;
    350426browse.incr_pair=[0 0];%default
    351427
    352 % form=imformats(ext_input(2:end));
    353 check_letter=0;
    354 check_separator=0;
    355 if ~isempty(ext_input)&&(~isempty(imformats(ext_input(2:end)))||strcmpi(ext_input,'.avi'))% if the extension corresponds to an image or movie format recognized by Matlab
    356     ext_ima=ext_input;
    357     nom_type_ima=nom_type_input;
    358     imagename=fileinput;
    359     check_letter=~isempty(regexp(nom_type_ima,'[a|A]$'));%detect pair label by letter
    360 else %case of netcdf input file, look for corresponding images
    361     nom_type_nc=nom_type_input;
    362     imagename=fullfile_uvmat(RootPath,[],RootFile,ext_ima,nom_type_ima,1,[],1);
    363     %imagename=name_generator(fullfile(RootPath,RootFile),1,1,ext_ima,nom_type_ima);
    364     i1_str='';
    365     j1_str='';
    366     if ~isnan(i2)
    367         num_ref_i=floor((num_ref_i+i2)/2);% reference image number corresponding to the file
    368         browse.incr_pair(1)=i2-i1;
    369         browse.incr_pair(2)=0;
    370     end
    371     %TODO: read the image name in the netcdf file (if documented)
    372     %look for double image series '_i_j'
    373     check_letter=~isempty(regexp(nom_type_nc,'[ab|AB]$'));%detect pair label by letter
    374     if check_letter
    375         j1_str=nom_type_nc(end-1);
    376         r=regexp(nom_type_nc,'_(?<num1>\d+)','names');
    377         if ~isempty(r)
    378             i1_str=r.num1;
    379         end
    380     else
    381         NomTypeIma=regexprep(nom_type_nc,'-\d','');%
    382         r_end=regexp(NomTypeIma,'.\D(?<num2>\d+$','names');
    383         if ~isempty(r_end)
    384             j1_str=r.num2;
    385         end
    386     end
    387     r=regexp(NomTypeIma,'_(?<num1>\d+)','names');
    388     if ~isempty(r)
    389         i1_str=r.num1;
    390     end 
    391     dirima=dir([RootName '_' i1_str '_' j1_str '.*']);
    392     if isempty(dirima)
    393         % look for images series  with sub marker '_'
    394         dirima=dir([RootName '_*' i1_str  '.*']);
    395         if isempty(dirima)
    396             % look for other images series
    397             dirima=dir([RootName '*' i1_str '.*']);
    398             if isempty(dirima)
    399                 % look for other images series witth letter appendix
    400                 appendix=char(96+j1_str);
    401                 dirima=dir([RootName '*' i1_str appendix '.*']);
    402             end
    403         end
    404     end
    405     for ilist=1:numel(dirima)
    406         %[pp,ff,i1_str,i2_str,j1_str,j2_str,ext_list,nom_type_list]=name2display(dirima(ilist).name);
    407         [tild,tild,tild,i1,i2,j1,j2,ext_list,nom_type_list]=fileparts_uvmat(dirima(ilist).name);
    408         form=imformats(ext_list(2:end));
    409         if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
    410             ext_ima=ext_list;
    411             nom_type_ima=nom_type_list;
    412 %             i1=str2double(i1_str);
    413 %             j1=str2double(j1_str);
    414 %             i2=str2double(i2_str);
    415 %             j2=str2double(j2_str);         
    416             % set the range of fields (1:1 by default) and selected pair
    417             if isempty(i2)
    418                 num_ref_i=i1;
    419             else
    420                 num_ref_i=floor((i1+i2)/2);
    421                 browse.incr_pair(1)=i2-i1;
    422                 browse.incr_pair(2)=0;
    423             end
    424             if isempty(j2)
    425                 if isempty(j1)
    426                     num_ref_j=1;
    427                 else
    428                     num_ref_j=j1;
    429                 end
    430             else
    431                 num_ref_j=floor((j1+j2)/2);
    432                 browse.incr_pair(2)=j2-j1;
    433             end
    434             break
    435         end
    436     end
    437 end
    438 [RootPath,RootFile,i1_series,tild,j1_series,tild,NomType,FileType,Object]=find_file_series(imagename);
    439 MaxIndex_i=max(i1_series(i1_series>0));
    440 MaxIndex_j=max(j1_series(j1_series>0));
     428% % form=imformats(ext_input(2:end));
     429% check_letter=0;
     430% check_separator=0;
     431% if ~isempty(ext_input)&&(~isempty(imformats(ext_input(2:end)))||strcmpi(ext_input,'.avi'))% if the extension corresponds to an image or movie format recognized by Matlab
     432%     ext_ima=ext_input;
     433%     nom_type_ima=nom_type_input;
     434%     imagename=fileinput;
     435%     check_letter=~isempty(regexp(nom_type_ima,'[a|A]$'));%detect pair label by letter
     436% else %case of netcdf input file, look for corresponding images
     437%     nom_type_nc=nom_type_input;
     438%     imagename=fullfile_uvmat(RootPath,[],RootFile,ext_ima,nom_type_ima,1,[],1);
     439%     %imagename=name_generator(fullfile(RootPath,RootFile),1,1,ext_ima,nom_type_ima);
     440%     i1_str='';
     441%     j1_str='';
     442%     if ~isnan(i2)
     443%         num_ref_i=floor((num_ref_i+i2)/2);% reference image number corresponding to the file
     444%         browse.incr_pair(1)=i2-i1;
     445%         browse.incr_pair(2)=0;
     446%     end
     447%     %TODO: read the image name in the netcdf file (if documented)
     448%     %look for double image series '_i_j'
     449%     check_letter=~isempty(regexp(nom_type_nc,'[ab|AB]$'));%detect pair label by letter
     450%     if check_letter
     451%         j1_str=nom_type_nc(end-1);
     452%         r=regexp(nom_type_nc,'_(?<num1>\d+)','names');
     453%         if ~isempty(r)
     454%             i1_str=r.num1;
     455%         end
     456%     else
     457%         NomTypeIma=regexprep(nom_type_nc,'-\d','');%
     458%         r_end=regexp(NomTypeIma,'.\D(?<num2>\d+$','names');
     459%         if ~isempty(r_end)
     460%             j1_str=r.num2;
     461%         end
     462%     end
     463%     r=regexp(NomTypeIma,'_(?<num1>\d+)','names');
     464%     if ~isempty(r)
     465%         i1_str=r.num1;
     466%     end 
     467%     dirima=dir([RootName '_' i1_str '_' j1_str '.*']);
     468%     if isempty(dirima)
     469%         % look for images series  with sub marker '_'
     470%         dirima=dir([RootName '_*' i1_str  '.*']);
     471%         if isempty(dirima)
     472%             % look for other images series
     473%             dirima=dir([RootName '*' i1_str '.*']);
     474%             if isempty(dirima)
     475%                 % look for other images series witth letter appendix
     476%                 appendix=char(96+j1_str);
     477%                 dirima=dir([RootName '*' i1_str appendix '.*']);
     478%             end
     479%         end
     480%     end
     481%     for ilist=1:numel(dirima)
     482%         %[pp,ff,i1_str,i2_str,j1_str,j2_str,ext_list,nom_type_list]=name2display(dirima(ilist).name);
     483%         [tild,tild,tild,i1,i2,j1,j2,ext_list,nom_type_list]=fileparts_uvmat(dirima(ilist).name);
     484%         form=imformats(ext_list(2:end));
     485%         if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
     486%             ext_ima=ext_list;
     487%             nom_type_ima=nom_type_list;
     488% %             i1=str2double(i1_str);
     489% %             j1=str2double(j1_str);
     490% %             i2=str2double(i2_str);
     491% %             j2=str2double(j2_str);         
     492%             % set the range of fields (1:1 by default) and selected pair
     493%             if isempty(i2)
     494%                 num_ref_i=i1;
     495%             else
     496%                 num_ref_i=floor((i1+i2)/2);
     497%                 browse.incr_pair(1)=i2-i1;
     498%                 browse.incr_pair(2)=0;
     499%             end
     500%             if isempty(j2)
     501%                 if isempty(j1)
     502%                     num_ref_j=1;
     503%                 else
     504%                     num_ref_j=j1;
     505%                 end
     506%             else
     507%                 num_ref_j=floor((j1+j2)/2);
     508%                 browse.incr_pair(2)=j2-j1;
     509%             end
     510%             break
     511%         end
     512%     end
     513% end
     514
    441515
    442516%% look for an image documentation file
     
    567641
    568642%% set the civ options depending on the input file content
    569 ind_opening=0;%default
    570 if isequal(ext_input,'.nc')
    571     browse.nom_type_nc=nom_type_input;
    572     ind_opening=2;% propose 'fix' as the default option
    573     Data=nc2struct(fileinput,'ListGlobalAttribute','CivStage','absolut_time_T0','fix','patch','civ2','fix2');
    574     if isfield(Data,'Txt')
    575         msgbox_uvmat('ERROR',Data.Txt)
    576         return
    577     end
    578     if ~isempty(Data.CivStage)%test for civ files
    579         ind_opening=Data.CivStage;
    580         set(handles.ListPairMode,'Value',3)
    581     end
    582 end
     643% ind_opening=0;%default
     644% if isequal(ext_input,'.nc')
     645%     browse.nom_type_nc=nom_type_input;
     646%     ind_opening=2;% propose 'fix' as the default option
     647%     Data=nc2struct(fileinput,'ListGlobalAttribute','CivStage','absolut_time_T0','fix','patch','civ2','fix2');
     648%     if isfield(Data,'Txt')
     649%         msgbox_uvmat('ERROR',Data.Txt)
     650%         return
     651%     end
     652%     if ~isempty(Data.CivStage)%test for civ files
     653%         ind_opening=Data.CivStage;
     654%         set(handles.ListPairMode,'Value',3)
     655%     end
     656% end
    583657ListOptions={'CheckCiv1', 'CheckFix1' 'CheckPatch1', 'CheckCiv2', 'CheckFix2', 'CheckPatch2'};
    584658for index = 1:ind_opening
     
    595669% TODO: determine MaxIndex_i and MaxIndex_j using find_file_series (in the absence of xml file)
    596670% try
    597 if ~check_letter|| isequal(nom_type_nc,'_1-2')|| (MaxIndex_j==1)
     671check_letter=~isempty(regexp(NomTypeIma,'[ab|AB]$'));%detect pair label by letter
     672if ~check_letter|| isequal(NomTypeNc,'_1-2')|| (MaxIndex_j==1)
    598673    set(handles.ListPairMode,'Value',1)
    599674    set(handles.ListPairMode,'String',{'series(Di)'})   
     
    653728
    654729%% store info
    655 browse.nom_type_ima=nom_type_ima;
     730% browse.nom_type_ima=nom_type_ima;
    656731set(handles.RootName,'UserData',browse)% store the nomenclature type
    657732
Note: See TracChangeset for help on using the changeset viewer.