Changeset 530 for trunk/src/uvmat.m


Ignore:
Timestamp:
Aug 27, 2012, 4:38:41 PM (12 years ago)
Author:
sommeria
Message:

new conventions for find_field_cells .

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uvmat.m

    r528 r530  
    347347end
    348348[FileName, PathName] = uigetfile({'*.*','All Files(*.*)'},'Pick a file',oldfile);
     349if ~ischar(FileName),return,end %abandon if the browser is cancelled
    349350fileinput=[PathName FileName];%complete file name
    350 if ~exist(fileinput,'file')
    351     return %abandon if the browser is cancelled
    352 end
    353351
    354352%% display the selected field and related information
     
    397395RootPath=get(handles.RootPath,'String');
    398396[FileName, PathName] = uigetfile({'*.*','All Files(*.*)'},'Pick a file',RootPath);
     397if ~ischar(FileName),return,end %abandon if the browser is cancelled
    399398fileinput_1=[PathName FileName];%complete file name
    400 if ~exist(fileinput_1,'file')
    401     return %abandon of the browser is cancelled
    402 end
    403399
    404400% refresh the current displayed field
     
    12861282            '*.*', 'All Files (*.*)'}, ...
    12871283            'Pick a mask file *.png',FileBase);
     1284        if ~ischar(FileName),return,end %abandon if the browser is cancelled
    12881285        maskname=fullfile(PathName,FileName);
    1289         if ~exist(maskname,'file')
    1290             errormsg='no file browsed';
    1291         end
    12921286        [RootDir,SubDir,RootFile,tild,tild,tild,tild,tild,Mask.NomType]=fileparts_uvmat(maskname);
    12931287        Mask.Base=fullfile(RootDir,SubDir,RootFile);
     
    23882382
    23892383%% analyse input field
    2390 test_x=0;
    2391 test_z=0;% test for unstructured z coordinate
    2392 [errormsg,ListDimName,DimValue,VarDimIndex]=check_field_structure(UvData.Field);% check the input field structure
    2393 if ~isempty(errormsg)
    2394     errormsg=['error in uvmat/refresh_field/check_field_structure: ' errormsg];% display error
    2395     return
    2396 end
    2397 [CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(UvData.Field);% analyse  the input field structure
     2384%test_x=0;
     2385%test_z=0;% test for unstructured z coordinate
     2386%[errormsg,ListDimName,DimValue,VarDimIndex]=check_field_structure(UvData.Field);% check the input field structure
     2387% if ~isempty(errormsg)
     2388%     errormsg=['error in uvmat/refresh_field/check_field_structure: ' errormsg];% display error
     2389%     return
     2390% end
     2391[CellInfo,NbDimArray,errormsg]=find_field_cells(UvData.Field);% analyse  the input field structure
    23982392if ~isempty(errormsg)
    23992393    errormsg=['uvmat /refresh_field / find_field_cells / ' errormsg];% display error
    24002394    return
    24012395end
    2402 [NbDim,imax]=max(NbDim);% spatial dimension of the input field
     2396
     2397NbDim=max(NbDimArray);% spatial dimension of the input field
     2398imax=find(NbDimArray==NbDim);% indices of field cells to consider
    24032399if isfield(UvData.Field,'NbDim')
    2404     NbDim=UvData.Field.NbDim;% deal with plane fields containing z coordinates
    2405 end
     2400    NbDim=double(UvData.Field.NbDim);% deal with plane fields containing z coordinates
     2401end
     2402
    24062403
    24072404%% get bounds and mesh (needed  to propose default options for projection objects)
    24082405if NbDim>1
    2409     XName=''; %default
    2410     YName='';
    2411     %unstructured coordinates
    2412     if ~isempty(VarType{imax}.coord_x)&&~isempty(VarType{imax}.coord_y)
    2413         XName=UvData.Field.ListVarName{VarType{imax}.coord_x};
    2414         YName=UvData.Field.ListVarName{VarType{imax}.coord_y};
    2415         test_x=1;%test for unstructured coordinates
    2416         if ~isempty(VarType{imax}.coord_z)
    2417             ZName=UvData.Field.ListVarName{VarType{imax}.coord_z};
    2418         else
    2419             NbDim=2;
    2420         end
    2421         %structured coordinate
    2422     elseif numel(VarType)>=imax && numel(VarType{imax}.coord)>=NbDim && VarType{imax}.coord(NbDim)>0
    2423         XName=UvData.Field.ListVarName{VarType{imax}.coord(NbDim)};
    2424         if NbDim> 1 && VarType{imax}.coord(NbDim-1)>0
    2425             YName=UvData.Field.ListVarName{VarType{imax}.coord(NbDim-1)}; %structured coordinates
    2426         end
    2427         DimIndex=VarDimIndex{CellVarIndex{imax}(1)}; %list of dim indices for the variable
    2428         nbpoints_x=DimValue(DimIndex(NbDim));
    2429         XMax=nbpoints_x;%default
    2430         XMin=1;%default
    2431     end
    2432    
     2406    CoordMax=zeros(1,numel(imax));
     2407    CoordMin=zeros(1,numel(imax));
     2408    for ind=1:numel(imax)
     2409        XName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end)};
     2410        YName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end-1)};
     2411        CoordMax(ind,1)=max(max(UvData.Field.(XName)));
     2412        CoordMin(ind,1)=min(min(UvData.Field.(XName)));
     2413        CoordMax(ind,2)=max(max(UvData.Field.(YName)));
     2414        CoordMin(ind,2)=min(min(UvData.Field.(YName)));
     2415        %         test_x=1;%test for unstructured coordinates
     2416        if NbDim==3
     2417            ZName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(1)};
     2418            CoordMax(imax(ind),3)=max(max(UvData.Field.(ZName)));
     2419            CoordMin(ind,3)=min(min(UvData.Field.(ZName)));
     2420        end
     2421       
     2422        switch CellInfo{imax(ind)}.CoordType
     2423           
     2424            case 'scattered' %unstructured coordinates
     2425                NbPoints(ind)=CellInfo{imax(ind)}.CoordSize;% nbre of points
     2426                Mesh(ind)=(prod(CoordMax(ind,:)-CoordMin(ind,:))/NbPoints)^(1/NbDim); %(volume or area per point)^(1/NbDim)
     2427            case 'grid'%structured coordinate
     2428                NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points
     2429                Mesh(ind)=min((CoordMax(ind,:)-CoordMin(ind,:))./NbPoints);
     2430               
     2431        end
     2432    end
     2433    UvData.Field.Mesh=min(Mesh);
     2434    UvData.Field.XMax=max(CoordMax(ind,1));
     2435    UvData.Field.XMin=min(CoordMin(ind,1));
     2436    UvData.Field.YMax=max(CoordMax(ind,2));
     2437    UvData.Field.YMin=max(CoordMin(ind,2));
    24332438    if NbDim==3
    2434         if ~test_x
    2435             ZName=UvData.Field.ListVarName{VarType{imax}.coord(1)};%structured coordinates in 3D
    2436         end
    2437         ZMax=max(UvData.Field.(ZName));
    2438         ZMin=min(UvData.Field.(ZName));
    2439         UvData.Field.ZMax=ZMax;
    2440         UvData.Field.ZMin=ZMin;
    2441         test_z=1;
    2442         if isequal(ZMin,ZMax)%no z dependency
    2443             NbDim=2;
    2444             test_z=0;
    2445         end
    2446     end
    2447     if ~isempty (XName)
    2448         XMax=max(max(UvData.Field.(XName)));
    2449         XMin=min(min(UvData.Field.(XName)));
    2450         UvData.Field.NbDim=NbDim;
    2451         UvData.Field.XMax=XMax;
    2452         UvData.Field.XMin=XMin;
    2453         if NbDim >1&& ~isempty(YName)
    2454             YMax=max(max(UvData.Field.(YName)));
    2455             YMin=min(min(UvData.Field.(YName)));
    2456             UvData.Field.YMax=YMax;
    2457             UvData.Field.YMin=YMin;
    2458         end
    2459         nbvec=length(UvData.Field.(XName));
    2460         if test_x %unstructured coordinates
    2461             if test_z
    2462                 UvData.Field.Mesh=((XMax-XMin)*(YMax-YMin)*(ZMax-ZMin))/nbvec;% volume per vector
    2463                 UvData.Field.Mesh=(UvData.Field.Mesh)^(1/3);
    2464             else
    2465                 UvData.Field.Mesh=sqrt((XMax-XMin)*(YMax-YMin)/nbvec);%2D
    2466             end
    2467         end
    2468     end
    2469     % case of structured coordinates
    2470     if ~test_x
    2471         DX=(XMax-XMin)/(nbpoints_x-1);
    2472         if NbDim >1
    2473             nbpoints_y=DimValue(DimIndex(NbDim-1));
    2474             if isempty(YName)% if the y coordinate is not expressed, it is taken as the matrix index
    2475                 DY=1;
    2476                 UvData.Field.YMax=nbpoints_y;
    2477                 UvData.Field.YMin=1;
    2478             else
    2479                 DY=(YMax-YMin)/(nbpoints_y-1);
    2480             end
    2481         end
    2482         if NbDim==3
    2483             nbpoints_z=DimValue(DimIndex(1));
    2484             DZ=(ZMax-ZMin)/(nbpoints_z-1);
    2485             UvData.Field.Mesh=(DX*DY*DZ)^(1/3);
    2486             UvData.Field.ZMax=ZMax;
    2487             UvData.Field.ZMin=ZMin;
    2488         else
    2489             UvData.Field.Mesh=DX;%sqrt(DX*DY);
    2490         end
     2439        UvData.Field.ZMax=max(CoordMax(ind,3));
     2440        UvData.Field.ZMin=max(CoordMin(ind,3));
    24912441    end
    24922442    % adjust the mesh to a value 1, 2 , 5 *10^n
     
    26642614            ObjectData.A=flag_mask.*double(ObjectData.A);
    26652615            ObjectData.A=feval(AClass,ObjectData.A);
    2666             ind_off=[];
    2667             if isfield(ObjectData,'ListVarName')
    2668                 for ilist=1:length(ObjectData.ListVarName)
    2669                     if isequal(ObjectData.ListVarName{ilist},'Mask')||isequal(ObjectData.ListVarName{ilist},'MaskX')||isequal(ObjectData.ListVarName{ilist},'MaskY')
    2670                         ind_off=[ind_off ilist];
    2671                     end
    2672                 end
    2673                 ObjectData.ListVarName(ind_off)=[];
    2674                 VarDimIndex(ind_off)=[];
    2675                 ind_off=[];
    2676                 for ilist=1:length(ListDimName)
    2677                     if isequal(ListDimName{ilist},'MaskX') || isequal(ListDimName{ilist},'MaskY')
    2678                         ind_off=[ind_off ilist];
    2679                     end
    2680                 end
    2681                 ListDimName(ind_off)=[];
    2682                 DimValue(ind_off)=[];
    2683             end
     2616%             ind_off=[];
     2617%             if isfield(ObjectData,'ListVarName')
     2618%                 for ilist=1:length(ObjectData.ListVarName)
     2619%                     if isequal(ObjectData.ListVarName{ilist},'Mask')||isequal(ObjectData.ListVarName{ilist},'MaskX')||isequal(ObjectData.ListVarName{ilist},'MaskY')
     2620%                         ind_off=[ind_off ilist];
     2621%                     end
     2622%                 end
     2623%                 ObjectData.ListVarName(ind_off)=[];
     2624%                 VarDimIndex(ind_off)=[];
     2625%                 ind_off=[];
     2626%             
     2627%             end
    26842628        end
    26852629        if ~isempty(ObjectData)
     
    27522696function histo1_menu_Callback(hObject, eventdata, handles)
    27532697%--------------------------------------------
    2754 %plot first histo
    2755 %huvmat=get(handles.histo1_menu,'parent');
    27562698histo_menu=get(handles.histo1_menu,'String');
    27572699histo_value=get(handles.histo1_menu,'Value');
    27582700FieldName=histo_menu{histo_value};
    2759 % update_histo(handles.HistoAxes,handles.uvmat,FieldName)
    2760 %
    2761 % %------------------------------------------------------------------------
    2762 % function histo2_menu_Callback(hObject, eventdata, handles)
    2763 % %------------------------------------------------------------------------
    2764 % %plot second histo
    2765 % %huvmat=get(handles.histo2_menu,'parent');
    2766 % histo_menu=get(handles.histo2_menu,'String');
    2767 % histo_value=get(handles.histo2_menu,'Value');
    2768 % FieldName=histo_menu{histo_value};
    2769 % update_histo(handles.histo_v,handles.uvmat,FieldName)
    2770 %
    2771 % %------------------------------------------------------------------------
    2772 % %read the field .Fieldname stored in UvData and plot its histogram
    2773 % function update_histo(haxes,huvmat,FieldName)
    2774 %------------------------------------------------------------------------
     2701
    27752702UvData=get(handles.uvmat,'UserData');
    27762703Field=UvData.Field;
     
    28452772            set(hlegend,'String',{FieldName;FieldName_2})
    28462773        end
    2847 %         hh=get(handles.HistoAxes,'children');
    2848 %         get(hh(1))
    2849 %         get(hh(2))
    28502774    end
    28512775end
     
    30973021            '*.vol','.volume images (png)'; ...
    30983022            '*.*',  'All Files (*.*)'}, ...
    3099             'Pick an image',imagename);   
     3023            'Pick an image',imagename);
     3024        if ~ischar(FileName),return,end %abandon if the browser is cancelled
    31003025        imagename=[PathName FileName];
    31013026    end
     
    31113036            '*.*',  'All Files (*.*)'}, ...
    31123037            'Pick a netcdf file',FileBase);
     3038        if ~ischar(FileName),return,end %abandon if the browser is cancelled
    31133039        FullFileName=[PathName FileName];
    31143040        % display the selected field and related information
     
    32093135                '*.*',  'All Files (*.*)'}, ...
    32103136                'Pick an image',imagename);
     3137            if ~ischar(FileName),return,end %abandon if the browser is cancelled
    32113138            imagename=[PathName FileName];
    32123139        end
     
    35453472        '*.*', 'All Files (*.*)'}, ...
    35463473        'Pick the transform function', prev_path);
     3474    if ~ischar(FileName),return,end %abandon if the browser is cancelled
    35473475    path_transform_fct =fullfile(PathName,FileName);
    3548     if ~exist(path_transform_fct,'file')% cancel has been activated
    3549         return
    3550     end
    35513476    if isempty(regexp(FileName,'.m$'))% detect file extension .m
    35523477        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
Note: See TracChangeset for help on using the changeset viewer.