Changeset 462 for trunk


Ignore:
Timestamp:
Jun 20, 2012, 2:14:10 PM (13 years ago)
Author:
sommeria
Message:

a few bug repairs and update in the series fcts

Location:
trunk/src/series
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series/aver_stat.m

    r457 r462  
    6767%% select different modes,  RUN, parameter input, BATCH
    6868% BATCH  case: read the xml file for batch case
    69 ParamOut=Param; %default output
    7069if ischar(Param)
    71     if strcmp(Param,'input?')
    72         checkrun=1;% will inly search input parameters (preparation of BATCH mode)
    73     else
    7470        Param=xml2struct(Param);
    7571        checkrun=0;
    76     end
    7772% RUN case: parameters introduced as the input structure Param
    7873else
    7974    hseries=guidata(Param.hseries);%handles of the GUI series
    8075    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
    81     checkrun=2; % indicate the RUN option is used
    82 end
     76    if isfield(Param,'Specific')&& strcmp(Param.Specific,'?')
     77        checkrun=1;% will only search interactive input parameters (preparation of BATCH mode)
     78    else
     79        checkrun=2; % indicate the RUN option is used
     80    end
     81end
     82ParamOut=Param; %default output
    8383
    8484%% root input file(s) and type
     
    240240
    241241%% Initiate output fields
    242 %initiate the output structure as a copy of the first input one (reproduce fields)
    243 [DataOut,ParamOut,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
    244 if ~isempty(errormsg)
    245     msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg])
    246     return
    247 end
    248 time_1=[];
    249 if isfield(DataOut,'Time')
    250     time_1=DataOut.Time(1);
    251 end
    252 if CheckNc{iview}
    253     if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute))
    254         DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute];
    255     end
    256     DataOut.Conventions='uvmat';
    257     DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}];
    258     ActionKey='Action';
    259     while isfield(DataOut,ActionKey)
    260         ActionKey=[ActionKey '_1'];
    261     end
    262     DataOut.(ActionKey)=Param.Action;
    263     DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}];
    264     if isfield(DataOut,'Time')
    265         DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}];
    266     end
    267 end
     242% %initiate the output structure as a copy of the first input one (reproduce fields)
     243% [DataOut,ParamOut,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
     244% if ~isempty(errormsg)
     245%     msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg])
     246%     return
     247% end
     248% time_1=[];
     249% if isfield(DataOut,'Time')
     250%     time_1=DataOut.Time(1);
     251% end
     252% if CheckNc{iview}
     253%     if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute))
     254%         DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute];
     255%     end
     256%     DataOut.Conventions='uvmat';
     257%     DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}];
     258%     ActionKey='Action';
     259%     while isfield(DataOut,ActionKey)
     260%         ActionKey=[ActionKey '_1'];
     261%     end
     262%     DataOut.(ActionKey)=Param.Action;
     263%     DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}];
     264%     if isfield(DataOut,'Time')
     265%         DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}];
     266%     end
     267% end
    268268
    269269%% MAIN LOOP ON SLICES
     
    274274    nbmissing=0;
    275275   
    276    %initiate result fields
    277    for ivar=1:length(DataOut.ListVarName)
    278        DataOut.(DataOut.ListVarName{ivar})=0; % initialise all fields to zero
    279    end
    280 
     276    %initiate result fields
     277   for ivar=1:length(DataOut.ListVarName)
     278       DataOut.(DataOut.ListVarName{ivar})=0; % initialise all fields to zero
     279   end
     280   
    281281    %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
    282282    for index=index_slice
     
    304304        %%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
    305305        % EDIT FROM HERE
    306 
    307         if isempty(errormsg)     
     306       
     307        if isempty(errormsg)
    308308            % coordinate transform (or other user defined transform)
    309309            if ~isempty(transform_fct)
     
    339339            %field projection on an object
    340340            if Param.CheckObject
    341                 [Field,errormsg]=proj_field(Field,ProjObject);
     341                [Field,errormsg]=proj_field(Field,Param.ProjObject);
    342342                if ~isempty(errormsg)
    343343                    msgbox_uvmat('ERROR',['error in aver_stat/proj_field:' errormsg])
     
    349349            %%%%%%%%%%%% MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
    350350            %update sum
    351             for ivar=1:length(Field.ListVarName)
    352                 VarName=Field.ListVarName{ivar};
    353                 sizmean=size(DataOut.(VarName));
    354                 siz=size(Field.(VarName));
    355                 if ~isequal(DataOut.(VarName),0)&& ~isequal(siz,sizmean)
    356                     msgbox_uvmat('ERROR',['unequal size of input field ' VarName ', need to project  on a grid'])
    357                     return
    358                 else
    359                     DataOut.(VarName)=DataOut.(VarName)+ double(Field.(VarName)); % update the sum
     351            if nbfiles==1 %first field
     352                time_1=[];
     353                if isfield(Field,'Time')
     354                    time_1=Field.Time(1);
     355                end
     356                DataOut=Field;%default
     357                for ivar=1:length(Field.ListVarName)
     358                    VarName=Field.ListVarName{ivar};
     359                    DataOut.(VarName)=double(DataOut.(VarName));
     360                end
     361            else   %current field
     362                for ivar=1:length(Field.ListVarName)
     363                    VarName=Field.ListVarName{ivar};
     364                    sizmean=size(DataOut.(VarName));
     365                    siz=size(Field.(VarName));
     366                    if ~isequal(DataOut.(VarName),0)&& ~isequal(siz,sizmean)
     367                        msgbox_uvmat('ERROR',['unequal size of input field ' VarName ', need to project  on a grid'])
     368                        return
     369                    else
     370                        DataOut.(VarName)=DataOut.(VarName)+ double(Field.(VarName)); % update the sum
     371                    end
    360372                end
    361373            end
    362374            %%%%%%%%%%%%   END MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
    363375        else
    364             display(errormsg) 
     376            display(errormsg)
    365377        end
    366378    end
     
    374386        msgbox_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipted'])
    375387    end
    376     if isempty(time) % time is read from files 
     388    if isempty(time) % time is read from files
    377389        if isfield(Field,'Time')
    378390            time_end=Field.Time(1);%last time read
  • trunk/src/series/merge_proj.m

    r457 r462  
    4747%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    4848
    49 function GUI_input=merge_proj(Param)
     49function ParamOut=merge_proj(Param)
    5050
    5151%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
    5252if ~exist('Param','var') % case with no input parameter
    53     GUI_input={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation)
     53    ParamOut={'NbViewMax';'';...% max nbre of input file series (default='' , no limitation)
    5454        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
     55        'WholeIndexRange';'off';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
    5556        'NbSlice';'on'; ...%nbre of slices ('off' by default)
    56         'VelType';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
    57         'FieldName';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
     57        'VelType';'one';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     58        'FieldName';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
    5859        'FieldTransform'; 'on';...%can use a transform function
    5960        'ProjObject';'on';...%can use projection object(option 'off'/'on',
    60         'Mask';'on';...%can use mask option   (option 'off'/'on', 'off' by default)
    61         'OutputDirExt';'.proj';...%set the output dir extension
     61        'Mask';'off';...%can use mask option   (option 'off'/'on', 'off' by default)
     62        'OutputDirExt';'.mproj';...%set the output dir extension
    6263               ''};
    6364        return
     
    6869% BATCH  case: read the xml file for batch case
    6970if ischar(Param)
    70     if strcmp(Param,'input?')
    71         checkrun=1;% will inly search input parameters (preparation of BATCH mode)
    72     else
    7371        Param=xml2struct(Param);
    7472        checkrun=0;
    75     end
    7673% RUN case: parameters introduced as the input structure Param
    7774else
    7875    hseries=guidata(Param.hseries);%handles of the GUI series
    7976    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
    80     checkrun=2; % indicate the RUN option is used
    81 end
     77    if isfield(Param,'Specific')&& strcmp(Param.Specific,'?')
     78        checkrun=1;% will only search interactive input parameters (preparation of BATCH mode)
     79    else
     80        checkrun=2; % indicate the RUN option is used
     81    end
     82end
     83ParamOut=Param; %default output
    8284
    8385%% root input file(s) and type
     
    100102
    101103NbSlice=1;%default
    102 if isfield(Param.IndexRange,'NbSlice')
     104if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
    103105    NbSlice=Param.IndexRange.NbSlice;
    104106end
     
    111113
    112114%determine the file type on each line from the first input file
    113 ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images)
    114 
    115 [FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
    116 CheckImage{1}=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images
    117 if ~isempty(j1_series{1})
    118     frame_index{1}=j1_series{1};
    119 else
    120     frame_index{1}=i1_series{1};
     115ImageTypeOptions={'image','multimage','mmreader','video'};
     116NcTypeOptions={'netcdf','civx','civdata'};
     117for iview=1:nbview
     118    if ~exist(filecell{iview,1}','file')
     119        msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
     120        return
     121    end
     122    [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
     123    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
     124    CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
     125    if ~isempty(j1_series{iview})
     126        frame_index{iview}=j1_series{iview};
     127    else
     128        frame_index{iview}=i1_series{iview};
     129    end
    121130end
    122131
     
    126135itime=0;
    127136NbSlice_calib={};
     137XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing)
    128138for iview=1:nbview%Loop on views
    129     XmlData{iview}=[];%default
    130     filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
    131     if exist([filebase{iview} '.xml'],'file')
    132         [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
    133         if isfield(XmlData{iview},'Time')
    134             itime=itime+1;
    135             timecell{itime}=XmlData{iview}.Time;
    136         end
    137         if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
    138             NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
    139             if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
    140                 msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
    141             end
    142         end
    143     elseif exist([filebase{iview} '.civ'],'file')
    144         [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
     139    SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.'
     140    filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
     141    if ~exist(filexml,'file')
     142        filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder
     143        if ~exist(filexml,'file')
     144            filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file
     145            if ~exist(filexml,'file')
     146                filexml='';
     147            end
     148        end
     149    end
     150    if ~isempty(filexml)
     151        [XmlData{iview},error]=imadoc2struct(filexml);
     152    end
     153    if isfield(XmlData{iview},'Time')
    145154        itime=itime+1;
    146         timecell{itime}=time;
    147         XmlData{iview}.Time=time;
    148         GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
    149         GeometryCalib.Tx=0;
    150         GeometryCalib.Ty=0;
    151         GeometryCalib.Tz=1;
    152         GeometryCalib.dpx=1;
    153         GeometryCalib.dpy=1;
    154         GeometryCalib.sx=1;
    155         GeometryCalib.Cx=0;
    156         GeometryCalib.Cy=0;
    157         GeometryCalib.f=1;
    158         GeometryCalib.kappa1=0;
    159         GeometryCalib.CoordUnit='cm';
    160         XmlData{iview}.GeometryCalib=GeometryCalib;
    161         if error==1
    162             msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
     155        timecell{itime}=XmlData{iview}.Time;
     156    end
     157    if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
     158        NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
     159        if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
     160            msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
    163161        end
    164162    end
     
    191189    end   
    192190end
    193 if size(time,2) < i2_series{1}(end) || size(time,3) < j2_series{1}(end)% time array absent or too short in ImaDoc xml file'
     191if size(time,2) < i2_series{1}(end) ||( ~isempty(j2_series{1}) && size(time,3) < j2_series{1}(end))% time array absent or too short in ImaDoc xml file'
    194192    time=[];
    195193end
     
    212210    return
    213211end
    214 if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
    215         msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
     212for iview=1:nbview
     213        if ~isequal(CheckImage{iview},CheckImage{1})||~isequal(CheckNc{iview},CheckNc{1})
     214        msgbox_uvmat('ERROR','input set of input series: need  either netcdf either image series')
    216215    return
    217216end
    218 NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
    219 if NbSlice~=nbfield_j
    220     answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
    221     if ~strcmp(answer,'Yes')
    222         return
    223     end
    224 end
     217NomTypeOut=NomType;% output file index will indicate the first and last ref index in the series
    225218
    226219%% Set field names and velocity types
    227 InputFields{1}=[];%default (case of images)
    228 if isfield(Param,'InputFields')
    229     InputFields{1}=Param.InputFields;
    230 end
    231 if nbview==2
    232     InputFields{2}=[];%default (case of images)
    233     if isfield(Param,'InputFields')
    234         InputFields{2}=Param.InputFields{1};%default
    235         if isfield(Param.InputFields,'FieldName_1')
    236             InputFields{2}.FieldName=Param.InputFields.FieldName_1;
    237             if isfield(Param.InputFields,'VelType_1')
    238                 InputFields{2}.VelType=Param.InputFields.VelType_1;
    239             end
    240         end
    241     end
    242 end
     220%use Param.InputFields for all views
    243221
    244222%% Initiate output fields
    245223%initiate the output structure as a copy of the first input one (reproduce fields)
    246 [DataOut,ParamOut,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
     224[DataOut,ParamOut,errormsg] = read_field(filecell{1,1},FileType{1},Param.InputFields,1);
    247225if ~isempty(errormsg)
    248226    msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg])
     
    278256   
    279257   %initiate result fields
     258   
    280259   for ivar=1:length(DataOut.ListVarName)
    281260       DataOut.(DataOut.ListVarName{ivar})=0; % initialise all fields to zero
     
    290269            stopstate='queue';
    291270        end
    292 %OUTPUT
    293 % GUI_input=list of options in the GUI series.fig needed for the function
    294 %
    295 %INPUT:
    296 % Param: structure containing all the parameters read on the GUI series
    297 %  or name of the xml file containing these parameters (BATCH case)
    298 %
    299 
    300 
    301 %% projection object
    302 test_object=get(hseries.GetObject,'Value');
    303 if test_object
    304     hset_object=findobj(allchild(0),'tag','set_object');
    305     %ProjObject=read_set_object(guidata(hset_object));
    306     ProjObject=read_GUI(hset_object);
    307     if ~isfield(ProjObject,'Type')
    308             msgbox_uvmat('ERROR','Undefined projection object type')
    309             return
    310     end
    311     if ~isequal(ProjObject.Type,'plane')|| isequal(ProjObject.ProjMode,'projection')
    312             msgbox_uvmat('ERROR','The projection object must be a plane with projection mode interp or filter')
    313             return
    314     end
    315     answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' ProjObject.Type]);
    316     if ~isequal(answeryes,'Yes')
    317         return
    318     end
    319 end
    320 
    321 %% features of the input fields
    322 RootPath=Param.InputTable(:,1);
    323 RootFile=Param.InputTable(:,3);
    324 SubDir=Param.InputTable(:,2);
    325 NomType=Param.InputTable(:,4);
    326 FileExt=Param.InputTable(:,5);
    327 
    328 nbview=length(RootFile);%number of views (file series to merge)
    329 nbfield=size(i1_series{1},1)*size(i1_series{1},2);%number of fields in the time series
    330 hhh=which('mmreader');
    331 for iview=1:nbview
    332     test_movie(iview)=0;
    333     if ~isempty(hhh)
    334         if isequal(lower(FileExt{iview}),'.avi')
    335             MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
    336             test_movie(iview)=1;
    337         end
    338     end
    339 end
    340 
    341 %% Calibration data and timing: read the ImaDoc files
    342 timecell={};
    343 itime=0;
    344 NbSlice_calib={}; %test for z index
    345 for iview=1:nbview%Loop on views
    346     XmlData{iview}=[];%default
    347     filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
    348     if exist([filebase{iview} '.xml'],'file')
    349         [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
    350         if isfield(XmlData{iview},'Time')
    351             itime=itime+1;
    352             timecell{itime}=XmlData{iview}.Time;
    353         end
    354         if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
    355             NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);
    356             if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
    357                 msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
    358             end
    359         end   
    360     elseif exist([filebase{iview} '.civ'],'file')
    361         [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
    362         itime=itime+1;
    363         timecell{itime}=time;
    364         XmlData{iview}.Time=time;
    365         GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
    366         GeometryCalib.Tx=0;
    367         GeometryCalib.Ty=0;
    368         GeometryCalib.Tz=1;
    369         GeometryCalib.dpx=1;
    370         GeometryCalib.dpy=1;
    371         GeometryCalib.sx=1;
    372         GeometryCalib.Cx=0;
    373         GeometryCalib.Cy=0;
    374         GeometryCalib.f=1;
    375         GeometryCalib.kappa1=0;
    376         GeometryCalib.CoordUnit='cm';
    377         XmlData{iview}.GeometryCalib=GeometryCalib;
    378         if error==1
    379             msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
    380         end
    381     end
    382 end
    383 
    384 %% check coincidence in time
    385 multitime=0;
    386 if isempty(timecell)
    387     time=[];
    388 elseif length(timecell)==1
    389     time=timecell{1};
    390 elseif length(timecell)>1
    391     multitime=1;
    392     for icell=1:length(timecell)
    393         if ~isequal(size(timecell{icell}),size(timecell{1}))
    394             msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
    395             time=timecell{1};
    396             multitime=0;
    397             break
    398         end
    399     end
    400 end
    401 if multitime
    402     for icell=1:length(timecell)
    403         time(icell,:,:)=timecell{icell};
    404     end
    405     diff_time=max(max(diff(time)));
    406     if diff_time>0
    407         msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)])
    408     end   
    409     time=sqeeze(mean(time,1));
    410 end
    411 % if size(time,2) < i2_series{1}(end) || size(time,3) < j2_series{1}(end)% ime array absent or too short in ImaDoc xml file'
    412 %     time=[];
    413 % end
    414 
    415 %% Field and velocity type (the same for all views)
    416 FieldName='';
    417 if isfield(Param,'InputFields')&&isfield(Param.InputFields,'FieldMenu') 
    418     FieldName=Param.InputFields.FieldMenu;%the same set of fields for all views
    419     VelType=Param.InputFields.VelTypeMenu;
    420 end
    421 % if strcmp(get(hseries.FieldMenu,'Visible'),'on')
    422 %     Field_str=get(hseries.FieldMenu,'String');
    423 %     val=get(hseries.FieldMenu,'Value');
    424 %     FieldName=Field_str(val);%the same set of fields for all views
    425 %     VelType_str=get(hseries.VelTypeMenu,'String');
    426 %     VelType_val=get(hseries.VelTypeMenu,'Value');
    427 %     VelType=VelType_str{VelType_val}; %the same for all views
    428     if strcmp(FieldName,'')
    429         msgbox_uvmat('ERROR','no input field defined in FieldMenu')
    430     elseif strcmp(FieldName,'get_field...')
    431         hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
    432         SubField=get_field('read_get_field',hObject,eventdata,hget_field); %read the names of the variables to plot in the get_field GUI
    433     end
    434 % end
    435 %detect whether all the files are 'images' or 'netcdf'
    436 testima=0;
    437 testvol=0;
    438 testcivx=0;
    439 testnc=0;
    440 for iview=1:nbview
    441      ext=FileExt{iview};
    442      form=imformats(ext(2:end));
    443      if isequal(lower(ext),'.vol')
    444          testvol=testvol+1;
    445      elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
    446          testima=testima+1;
    447      elseif isequal(ext,'.nc')
    448          testnc=testnc+1;
    449      end
    450 end
    451 if testvol
    452     msgbox_uvmat('ERROR','volume images not implemented yet')
    453     return
    454 end
    455 if testnc~=nbview && testima~=nbview && testvol~=nbview
    456     msgbox_uvmat('ERROR','need a set of images or a set of netcdf files with the same fields as input')
    457     return
    458 end
    459 if ~isequal(FieldName,'get_field...')
    460     testcivx=testnc;
    461 end
    462 
    463 %% name of output files and directory:
    464 ProjectDir=fileparts(fileparts(RootPath{1}));% preoject directory (GERK)
    465 prompt={['result directory (in' ProjectDir ')']};
    466 % RootPath=get(hseries.RootPath,'String');
    467 % SubDir=get(hseries.SubDir,'String');
    468 if isequal(length(RootPath),1)
    469     fulldir=RootPath{1};
    470     subdir='merge_proj';
    471     res_subdir=fullfile(fulldir,subdir);
    472 else
    473     def={fullfile(ProjectDir,'0_RESULTS')};
    474     dlgTitle='result directory';
    475     lineNo=1;
    476     answer=msgbox_uvmat('INPUT_TXT',dlgTitle,def);
    477     fulldir=answer{1};
    478     subdir=[];
    479     dirlist=sort(RootFile);
    480     for iview=1:nbview
    481         if ~isempty(subdir)
    482             subdir=[subdir '-'];
    483         end
    484         subdir=[subdir dirlist{iview}];
    485     end 
    486     res_subdir=fullfile(fulldir,subdir);
    487 end
    488 ext=FileExt{1};
    489 if ~exist(fulldir,'dir')
    490     msgbox_uvmat('ERROR',['directory ' fulldir ' needs to be created'])
    491     return
    492 end
    493 if ~exist(res_subdir,'dir')
    494     dircur=pwd;
    495     cd(fulldir);
    496     succeed=mkdir(subdir);
    497     if succeed
    498         [xx,msg2] = fileattrib(res_subdir,'+w','g'); %yield writing access (+w) to user group (g)
    499         if ~strcmp(msg2,'')
    500             msgbox_uvmat('ERROR',['pb of permission for ' res_subdir ': ' msg2])%error message for directory creation
    501             cd(dircur)
    502             return
    503         end
    504         cd(dircur);
    505     else
    506         msgbox_uvmat('ERROR',['Cannot create directory ' fulldir])
    507         return
    508     end
    509 end
    510 filebasesub=fullfile(res_subdir,RootFile{1});
    511 %filebase_merge=fullfile(res_subdir,'merged');%root name for the merged files
    512 
    513 %% MAIN LOOP
    514 for ifile=1:nbfield               
    515     stopstate=get(hseries.RUN,'BusyAction');
    516     if isequal(stopstate,'queue')% enable STOP command from the 'series' interface
    517          update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
    518          
    519         %% ----------LOOP ON VIEWS----------------------
    520         nbtime=0;
     271       
     272        %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
     273        Data=cell(1,nbview);%initiate the set Data
    521274        for iview=1:nbview
    522          %name of the current file
    523          filename=filecell{iview,ifile};
    524           %  filename=name_generator(filebase{iview},i1_series{iview}(ifile),j1_series{iview}(ifile),FileExt{iview},NomType{iview},1,i2_series{iview}(ifile),j2_series{iview}(ifile),SubDir{iview});
    525             if ~exist(filename,'file')
    526                 msgbox_uvmat('ERROR',['missing input file' filename])
     275            % reading input file(s)
     276            [Data{iview},ParamOut,errormsg] = read_field(filecell{iview,index},FileType{iview},Param.InputFields,frame_index{iview}(index));
     277            if ~isempty(errormsg)
     278                errormsg=['error of input reading: ' errormsg];
    527279                break
    528280            end
    529             timeread(iview)=0;
    530          %reading the current file
    531             if testima
    532                 if test_movie(iview)
    533                     Field{iview}.A=read(MovieObject{iview},i1_series{iview}(ifile));
    534                 else
    535                     Field{iview}.A=imread(filename);
    536                 end % TODO: introduce ListVarName
    537                 npxy=size(Field{iview}.A);
    538                 Field{iview}.ListVarName={'AX','AY','A'};
    539                 Field{iview}.VarDimName={'AX','AY',{'AY','AX'}};
    540                 Field{iview}.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
    541                 Field{iview}.AY=[npxy(1)-0.5 0.5];
    542                 Field{iview}.CoordUnit='pixel';
    543                 Field{iview}.AName='image';
    544             else
    545                 if testcivx
    546                     [Field{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
    547                 else
    548                     [Field{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data               
    549                     Field{iview}.VarAttribute=SubField.VarAttribute;
    550                 end
    551                 if isfield(Field{iview},'Txt')
    552                     msgbox_uvmat('ERROR',Field{iview}.Txt)
    553                     return
    554                 end
    555                 if isfield(Field{iview},'Time')
    556                     timeread(iview)=Field{iview}.Time;
    557                     nbtime=nbtime+1;
    558                 end
    559             end
    560281            if ~isempty(NbSlice_calib)
    561                 Field{iview}.ZIndex=mod(i1_series{iview}(ifile)-1,NbSlice_calib{1})+1;
     282                Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
    562283            end
    563284         %transform the input field (e.g; phys) if requested
    564285            if ~isempty(transform_fct)
    565                 Field{iview}=transform_fct(Field{iview},XmlData{iview});  %transform to phys if requested
    566             end
    567             if testcivx
    568                 Field{iview}=calc_field(FieldName,Field{iview});
    569             end
     286                Data{iview}=transform_fct(Data{iview},XmlData{iview});  %transform to phys if requested
     287            end
     288                        % field calculation (vort, div...)
     289            if strcmp(FileType{1},'civx')||strcmp(FileType{1},'civ')
     290                Data{iview}=calc_field(Param.InputFields.FieldName,Data{iview});%calculate field (vort..)
     291            end
     292           
    570293         %projection on object (gridded plane)
    571294            if test_object
    572                 [Field{iview},errormsg]=proj_field(Field{iview},ProjObject);
     295                [Data{iview},errormsg]=proj_field(Data{iview},ProjObject);
    573296                if ~isempty(errormsg)
    574297                    msgbox_uvmat('ERROR',['error in merge_proge/proj_field: ' errormsg])
     
    580303         
    581304        %% merge the nbview fields
    582         MergeData=merge_field(Field);
     305        MergeData=merge_field(Data);
    583306        if isfield(MergeData,'Txt')
    584307            msgbox_uvmat('ERROR',MergeData.Txt)
     
    586309        end       
    587310     % generating the name of the merged field
    588      if testima
    589          ResultExt='.png';
    590      else
    591          ResultExt=FileExt{iview};
    592      end
    593      i1=i1_series{iview}(ifile);
     311     i1=i1_series{iview}(index);
    594312     if ~isempty(i2_series{iview})
    595          i2=i2_series{iview}(ifile);
     313         i2=i2_series{iview}(index);
    596314     else
    597315         i2=i1;
     
    600318     j2=1;
    601319     if ~isempty(j1_series{iview})
    602          j1=j1_series{iview}(ifile);
     320         j1=j1_series{iview}(index);
    603321          if ~isempty(j2_series{iview})
    604               j2=j2_series{iview}(ifile);
     322              j2=j2_series{iview}(index);
    605323          else
    606324              j2=j1;
    607325          end
    608326     end
    609      mergename=fullfile_uvmat(res_subdir,'','merged',ResultExt,NomType{iview},i1,i2,j1,j2);
    610     % mergename=name_generator(filebase_merge,i1,j1_series{iview}(ifile),ResultExt,NomType{iview},1,i2_series{iview}(ifile),j2_series{iview}(ifile));
    611        
     327     OutputFile=fullfile_uvmat(RootPath{1},Param.OutputSubDir,RootFile{1},FileExtOut,NomType{1},i1,i2,j1,j2);
     328           
    612329     % time of the merged field:
    613330        time_i=0;%default
     
    626343                bitdepth=16;
    627344            end
    628             imwrite(MergeData.A,mergename,'BitDepth',bitdepth);
     345            imwrite(MergeData.A,OutputFile,'BitDepth',bitdepth);
    629346            %write xml calibration file
    630347            siz=size(MergeData.A);
     
    659376            MergeData.nb_dim=2;
    660377            dt=[];
    661             if isfield(Field{1},'dt')&& isnumeric(Field{1}.dt)
    662                 dt=Field{1}.dt;
    663             end
    664             for iview =2:numel(Field)
    665                 if ~(isfield(Field{iview},'dt')&& isequal(Field{iview}.dt,dt))
     378            if isfield(Data{1},'dt')&& isnumeric(Data{1}.dt)
     379                dt=Data{1}.dt;
     380            end
     381            for iview =2:numel(Data)
     382                if ~(isfield(Data{iview},'dt')&& isequal(Data{iview}.dt,dt))
    666383                    dt=[];%dt not the same for all fields
    667384                end
     
    673390            end
    674391            MergeData.Time=time_i;
    675             error=struct2nc(mergename,MergeData);%save result file
     392            error=struct2nc(OutputFile,MergeData);%save result file
    676393            if isempty(error)
    677                 display(['output file ' mergename ' written'])
     394                display(['output file ' OutputFile ' written'])
    678395            else
    679396                display(error)
  • trunk/src/series/relabel_i_j.m

    r457 r462  
    6767%% select different modes,  RUN, parameter input, BATCH
    6868% BATCH  case: read the xml file for batch case
    69 GUI_config=Param;%reproduce the input parameters, no interactive input
    7069if ischar(Param)
    71     if strcmp(Param,'input?')
    72         checkrun=1;% will inly search input parameters (preparation of BATCH mode)
    73     else
    7470        Param=xml2struct(Param);
    7571        checkrun=0;
    76     end
    7772% RUN case: parameters introduced as the input structure Param
    7873else
    7974    hseries=guidata(Param.hseries);%handles of the GUI series
    8075    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
    81     checkrun=2; % indicate the RUN option is used
    82 end
     76    if isfield(Param,'Specific')&& strcmp(Param.Specific,'?')
     77        checkrun=1;% will only search interactive input parameters (preparation of BATCH mode)
     78    else
     79        checkrun=2; % indicate the RUN option is used
     80    end
     81end
     82ParamOut=Param; %default output
    8383
    8484%% root input file(s) and type
  • trunk/src/series/sub_background.m

    r459 r462  
    7575%% select different modes,  RUN, parameter input, BATCH
    7676% BATCH  case: read the xml file for batch case
    77 ParamOut=Param; %default output
    7877if ischar(Param)
    79     if strcmp(Param,'input?')
    80         checkrun=1;% will search input parameters (preparation of BATCH mode)
    81     else
    8278        Param=xml2struct(Param);
    8379        checkrun=0;
    84     end
    8580% RUN case: parameters introduced as the input structure Param
    8681else
    8782    hseries=guidata(Param.hseries);%handles of the GUI series
    8883    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
    89     checkrun=2; % indicate the RUN option is used
    90 end
     84    if isfield(Param,'Specific')&& strcmp(Param.Specific,'?')
     85        checkrun=1;% will search input parameters (preparation of BATCH mode)
     86    else
     87        checkrun=2; % indicate the RUN option is used
     88    end
     89end
     90ParamOut=Param; %default output
    9191
    9292%% root input file(s) and type
     
    147147    if strcmp(lower(NomType{1}(end)),'a')
    148148        NomTypeOut=NomType{1};%case of letter appendix
     149    elseif isempty(j1_series)
     150        NomTypeOut='_1';
    149151    else
    150152        NomTypeOut='_1_1';% caseof purely numerical indexing
  • trunk/src/series/time_series.m

    r459 r462  
    6767%% select different modes,  RUN, parameter input, BATCH
    6868% BATCH  case: read the xml file for batch case
    69 ParamOut=Param; %default output
    7069if ischar(Param)
    71     if strcmp(Param,'input?')
    72         checkrun=1;% will inly search input parameters (preparation of BATCH mode)
    73     else
    7470        Param=xml2struct(Param);
    7571        checkrun=0;
    76     end
    7772% RUN case: parameters introduced as the input structure Param
    7873else
    7974    hseries=guidata(Param.hseries);%handles of the GUI series
    8075    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
    81     checkrun=2; % indicate the RUN option is used
    82 end
     76    if isfield(Param,'Specific')&& strcmp(Param.Specific,'?')
     77        checkrun=1;% will only search interactive input parameters (preparation of BATCH mode)
     78    else
     79        checkrun=2; % indicate the RUN option is used
     80    end
     81end
     82ParamOut=Param; %default output
    8383
    8484%% root input file(s) and type
Note: See TracChangeset for help on using the changeset viewer.