Changeset 39 for trunk/src/series.m


Ignore:
Timestamp:
Mar 9, 2010, 5:46:24 PM (11 years ago)
Author:
sommeria
Message:

civ: bug corrected for civ in batch
series and uvmat: further improvement and debugging for the menu of field transforms

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series.m

    r38 r39  
    66%INPUT
    77% param: structure with input parameters (link with the GUI uvmat)
    8 %      .menu_coord_str: string for the CoordType (menu for coordinate transforms)
    9 %      .menu_coord_val: value for CoordType (menu for coordinate transforms)
     8%      .menu_coord_str: string for the transform_fct (menu for coordinate transforms)
     9%      .menu_coord_val: value for transform_fct (menu for coordinate transforms)
    1010%      .FileName: input file name
    1111%      .FileName_1: second input file name
     
    9696%file name and browser initialisation
    9797if isfield(param,'menu_coord_str')
    98     set(handles.CoordType,'String',param.menu_coord_str)
     98    set(handles.transform_fct,'String',param.menu_coord_str)
    9999end
    100100if isfield(param,'menu_coord_val')
    101     set(handles.CoordType,'Value',param.menu_coord_val);
    102 else
    103      set(handles.CoordType,'Value',1);%default
     101    set(handles.transform_fct,'Value',param.menu_coord_val);
     102else
     103     set(handles.transform_fct,'Value',1);%default
    104104end
    105105
     
    132132NomType_Callback(hObject, eventdata, handles)
    133133
    134 %loads the information stored in prefdir to initiate the browser and the list of functions
     134%loads the information stored in prefdir to initiate  the list of ACTION functions
    135135fct_menu={'check_files';'aver_stat';'time_series';'merge_proj';'clean_civ_cmx'};
    136136transform_menu={'';'phys';'px';'phys_polar'};
     
    139139[path_series,name,ext]=fileparts(which('series'));
    140140path_series=fullfile(path_series,'series');%path of the function 'series'
    141 path_transform=fullfile(path_series,'transform_field');%path of the function 'series'
     141path_transform=fullfile(path_series,'transform_field');%path of the field transform functions
    142142for ilist=1:length(fct_menu)
    143143    fct_path{ilist,1}=path_series;%paths of the fuctions buil-in in 'series.m'
    144144end
    145 for ilist=1:length(transform_menu)
    146     transform_path{ilist,1}=path_transform;
    147 end
     145
     146%TRANSFORM menu: loads the information stored in prefdir to initiate  the list of field transform functions
     147menu_str={'';'phys';'px';'phys_polar'};
     148nb_builtin=numel(menu_str); %number of functions
     149[path_uvmat,name,ext]=fileparts(which('uvmat'));
     150addpath(fullfile(path_uvmat,'transform_field'))
     151fct_handle{1,1}=[];
     152testexist(1)=1;
     153for ilist=2:length(menu_str)
     154    if exist(menu_str{ilist},'file')
     155        fct_handle{ilist,1}=str2func(menu_str{ilist});
     156        testexist(ilist)=1;
     157    else
     158        testexist(ilist)=0;
     159    end
     160end
     161rmpath(fullfile(path_uvmat,'transform_field'))
     162
    148163% read the list of functions stored in the personal file 'uvmat_perso.mat' in prefdir
    149164dir_perso=prefdir;
     
    159174    end
    160175    if isfield(h,'transform_fct') && iscell(h.transform_fct)
    161          for ilist=1:length(h.transform_fct)
     176        for ilist=1:length(h.transform_fct);
    162177             [path,file]=fileparts(h.transform_fct{ilist});
    163              transform_path=[transform_path; {path}];%concatene the list of paths
    164              transform_menu=[transform_menu;{file}];
    165          end
     178             addpath(path)
     179             if exist(file,'file')
     180                h_func=str2func(file);
     181                testexist=[testexist 1];
     182             else
     183                h_func=[];
     184                testexist=[testexist 0];
     185             end
     186             fct_handle=[fct_handle; {h_func}];%concatene the list of paths
     187             rmpath(path)
     188             menu_str=[menu_str; {file}];
     189        end
    166190    end
    167191end
     
    169193set(handles.ACTION,'String',fct_menu)
    170194set(handles.ACTION,'UserData',fct_path)% store the list of path in UserData of ACTION
    171 transform_menu=[transform_menu;{'more...'}];
    172 set(handles.CoordType,'String',transform_menu)
    173 set(handles.CoordType,'UserData',transform_path)% store the list of path in UserData of ACTION
     195
     196menu_str=menu_str(find(testexist));
     197fct_handle=fct_handle(find(testexist));
     198menu_str=[menu_str;{'more...'}];
     199set(handles.transform_fct,'String',menu_str)
     200set(handles.transform_fct,'UserData',fct_handle)% store the list of path in UserData of ACTION
    174201
    175202% display the GUI for the default action 'check_files'
     
    544571testveltype=isequal(get(handles.VelTypeMenu,'enable'),'on');
    545572testveltype_1=isequal(get(handles.VelTypeMenu_1,'enable'),'on');
    546 testtransform=isequal(get(handles.CoordType,'Enable'),'on');
     573testtransform=isequal(get(handles.transform_fct,'Enable'),'on');
    547574testnc=0;
    548575testnc_1=0;
     
    962989function view_TRANSFORM(handles,state)
    963990set(handles.TRANSFORM_frame,'Visible',state)
    964 set(handles.CoordType,'Visible',state);
     991set(handles.transform_fct,'Visible',state);
    965992set(handles.TRANSFORM_title,'Visible',state)
    966993
     
    13281355    Series.Field=FieldMenu(FieldValue);
    13291356end
    1330 menu_coord_state=get(handles.CoordType,'Visible');
     1357menu_coord_state=get(handles.transform_fct,'Visible');
    13311358Series.CoordType='';%default
    13321359if isequal(menu_coord_state,'on')
    1333     menu_coord=get(handles.CoordType,'String');
    1334     menu_index=get(handles.CoordType,'Value');
     1360    menu_coord=get(handles.transform_fct,'String');
     1361    menu_index=get(handles.transform_fct,'Value');
    13351362    Series.CoordType=menu_coord{menu_index};
    13361363end
     
    15931620path_series=which('series');%path to series.m
    15941621list_path=get(handles.ACTION,'UserData');%list of recorded paths to functions of the list ACTION
    1595 
     1622default_file=fullfile(list_path{end},ACTION);
    15961623% add a new function to the menu if the selected item is 'more...'
    15971624if isequal(ACTION,'more...')
    15981625    pathfct=fileparts(path_series);
    1599 %     browse_name=fullfile(path_series,'series');%go to UVMAT/series by default
    1600 %     if length(list_path)>nb_builtin
    1601 %         browse_name=list_path{end};% initialize browser with  the path of the last introduced function
    1602 %      end
    16031626    [FileName, PathName, filterindex] = uigetfile( ...
    16041627       {'*.m', ' (*.m)';
    16051628        '*.m',  '.m files '; ...
    16061629        '*.*', 'All Files (*.*)'}, ...
    1607         'Pick a file',list_path{end});
     1630        'Pick a file',default_file);
    16081631    if length(FileName)<2
    16091632        return
     
    16851708set(handles.FieldMenu_1,'Enable','off')
    16861709set(handles.VelTypeMenu_1,'Enable','off')
    1687 set(handles.CoordType,'Enable','off')
     1710set(handles.transform_fct,'Enable','off')
    16881711%set the displayed GUI item needed for input parameters
    16891712%list_input=feval(ACTION);% input list asked by the selected function
     
    17891812        case 'CoordType'   %hidden by default
    17901813            if isequal(lower(varargout{ilist+1}),'on')
    1791                 set(handles.CoordType,'Enable','on')
     1814                set(handles.transform_fct,'Enable','on')
    17921815                view_TRANSFORM(handles,'on')
    17931816            end
     
    21102133    else
    21112134        siz=size(times);
    2112         if siz(1)>=last_i & siz(2)>=last_j
     2135        if siz(1)>=last_i && siz(2)>=last_j && first_i>=1 && first_j>=1
    21132136            time_first=times(first_i,first_j);
    21142137            time_last=times(last_i,last_j);
     
    21882211
    21892212
    2190 
    2191 
    2192 
    2193 
     2213% --- Executes on selection change in transform_fct.
     2214function transform_fct_Callback(hObject, eventdata, handles)
     2215
     2216global nb_transform
     2217
     2218% huvmat=get(handles.transform_fct,'parent');
     2219menu=get(handles.transform_fct,'String');
     2220ind_coord=get(handles.transform_fct,'Value');
     2221coord_option=menu{ind_coord};
     2222list_transform=get(handles.transform_fct,'UserData')
     2223ff=functions(list_transform{end});
     2224if isequal(coord_option,'more...');
     2225    coord_fct='';
     2226    prompt = {'Enter the name of the transform function'};
     2227    dlg_title = 'user defined transform';
     2228    num_lines= 1;
     2229    [FileName, PathName, filterindex] = uigetfile( ...
     2230       {'*.m', ' (*.m)';
     2231        '*.m',  '.m files '; ...
     2232        '*.*', 'All Files (*.*)'}, ...
     2233        'Pick a file', ff.file);
     2234    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
     2235        PathName(end)=[];
     2236    end
     2237    transform_selected =fullfile(PathName,FileName);
     2238    if ~exist(transform_selected,'file')
     2239          return
     2240    end
     2241    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
     2242    if ~isequal(ext_fct,'.m')
     2243        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
     2244        return
     2245    end
     2246   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
     2247   ind_coord=get(handles.transform_fct,'Value');
     2248   addpath(PathName)
     2249   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
     2250   set(handles.transform_fct,'UserData',list_transform)
     2251   rmpath(PathName)
     2252   % save the new menu in the personal file 'uvmat_perso.mat'
     2253   dir_perso=prefdir;%personal Matalb directory
     2254   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
     2255   if exist(profil_perso,'file')
     2256       for ilist=nb_transform+1:numel(list_transform)
     2257           ff=functions(list_transform{ilist})
     2258           transform_fct{ilist-nb_transform}=ff.file;
     2259       end
     2260        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
     2261   end
     2262end
     2263
     2264%check the current path to the selected function
     2265func=functions(list_transform{ind_coord});
     2266set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
     2267
     2268
     2269
     2270function path_transform_Callback(hObject, eventdata, handles)
     2271% hObject    handle to path_transform (see GCBO)
     2272% eventdata  reserved - to be defined in a future version of MATLAB
     2273% handles    structure with handles and user data (see GUIDATA)
     2274
     2275% Hints: get(hObject,'String') returns contents of path_transform as text
     2276%        str2double(get(hObject,'String')) returns contents of path_transform as a double
     2277
     2278
     2279% --- Executes during object creation, after setting all properties.
     2280function path_transform_CreateFcn(hObject, eventdata, handles)
     2281% hObject    handle to path_transform (see GCBO)
     2282% eventdata  reserved - to be defined in a future version of MATLAB
     2283% handles    empty - handles not created until after all CreateFcns called
     2284
     2285% Hint: edit controls usually have a white background on Windows.
     2286%       See ISPC and COMPUTER.
     2287if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
     2288    set(hObject,'BackgroundColor','white');
     2289end
     2290
     2291
Note: See TracChangeset for help on using the changeset viewer.