Changeset 1022 for trunk


Ignore:
Timestamp:
Dec 11, 2017, 1:15:03 AM (6 years ago)
Author:
sommeria
Message:

opendap reading intreoduced

Location:
trunk/src
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/fileparts_uvmat.m

    r977 r1022  
    138138        RootFile=regexprep(RootFile,[r.num1 r.end_string '$'],'');
    139139    else % case with separator '_'
    140         r=regexp(RootFile,'\D(?<num1>\d+)_(?<end_string>[a-z]|[A-Z]|[a-z][a-z]|[A-Z][A-Z])$','names');
     140        r=regexp(RootFile,'\D*(?<num1>\d+)_(?<end_string>[a-z]|[A-Z]|[a-z][a-z]|[A-Z][A-Z])$','names');
    141141        if ~isempty(r)
    142142            NomType=['_' get_type(r.end_string)];
  • trunk/src/find_file_series.m

    r1011 r1022  
    4949
    5050%% get input root name and nomenclature type
     51if isempty(regexp(FilePath,'^http://'))
    5152fullfileinput=fullfile(FilePath,fileinput);% input file name with path
     53else
     54  fullfileinput=[FilePath '/' fileinput];
     55end
    5256[FileInfo,MovieObject]=get_file_info(fullfileinput);
    5357
    5458%% check for particular file types: images, movies, civ data
    55 %if isfield(FileInfo,'FileIndexing') && strcmp(FileInfo.FileIndexing,'on')
    56     [RootPath,SubDir,RootFile,i1_input,i2_input,j1_input,j2_input,FileExt,NomType]=fileparts_uvmat(fullfileinput);
    57     %     if ~isempty(regexp(SubDir,'^level\d+$')) && exist([RootPath '.xml'],'file')
    58     %         NomType='level';
    59     %     end
    60     i1_series=zeros(1,1,1);
    61     i2_series=zeros(1,1,1);
    62     j1_series=zeros(1,1,1);
    63     j2_series=zeros(1,1,1);
    64     checkfileindexing=1;
    65 %else % no file indexing
    66 %     [PathDir,RootFile]=fileparts(fullfileinput);
    67 %     [RootPath,SubDir,DirExt]=fileparts(PathDir);
    68 %     SubDir=[SubDir DirExt];% include part after . in the name (considered as a file extension)
    69 %     NomType='*';
    70 %     i1_series=[];i2_series=[];j1_series=[];j2_series=[];
    71 %     i1_input=1;i2_input=[];j1_input=[];j2_input=[];
    72 %     if exist(fullfileinput,'file')~=2
    73 %         RootFile='';
    74 %         return
    75 %     end
    76 %     checkfileindexing=0;
    77 %end
    78 if ~exist(FilePath,'dir')
     59[RootPath,SubDir,RootFile,i1_input,i2_input,j1_input,j2_input,FileExt,NomType]=fileparts_uvmat(fullfileinput);
     60i1_series=zeros(1,1,1);
     61i2_series=zeros(1,1,1);
     62j1_series=zeros(1,1,1);
     63j2_series=zeros(1,1,1);
     64checkfileindexing=1;
     65if isempty(regexp(FilePath,'^http://')) && ~exist(FilePath,'dir')
    7966    return % don't go further if the dir path does not exist
    8067end
     
    10996                        j1_input=[];
    11097                        j2_input=[];
    111                     elseif exist([RootPath '.xml'],'file')% new convention with j indices in sub-folders level0, 1...
    112                         rj=regexp(SubDir,'^level(?<j1>\d+)$','names');
    113                         if ~isempty(rj)
    114                             j1_input=rj.j1;
    115                             NomType='level';
    116                             [RootPath,SubDir]=fileparts(RootPath);
    117                         end
    11898                    end
    11999                end
     
    134114        %Look for cases with letter indexing for the second index
    135115        r=regexp(NomType,'^(?<sep1>_?)(?<i1>\d+)(?<sep2>_?)(?<j1>[a|A])(?<j2>[b|B]?)$','names');
    136         if ~isempty(r)
     116        if ~isempty(r) %indexing image pair with letters
    137117            sep1=r.sep1;
    138118            sep2=r.sep2;
     
    175155 
    176156        detect_string=['^' RootFile sep1 i1_str i2_str sep2 j1_str j2_str FileExt '$'];%string used in regexp to detect file indices
     157%         if isempty(regexp(FilePath,'^http://'))
    177158        %find the string used to extract the relevant files with the command dir
    178         star_string=[RootFile sep1 i1_star i2_star sep2 j1_star j2_star FileExt];
    179         wd=pwd;%current working directory
    180         cd (FilePath)% move to the local dir to save time in the operation dir.
    181         dirpair=dir(star_string);% look for relevant files in the file directory
    182         cd(wd)
    183         nbpair=numel(dirpair);
     159%         star_string=[RootFile sep1 i1_star i2_star sep2 j1_star j2_star FileExt];
     160%         wd=pwd;%current working directory
     161%         cd (FilePath)% move to the local dir to save time in the operation dir.
     162%         dirpair=dir(star_string);% look for relevant files in the file directory
     163%         cd(wd)
     164%         else
     165            ListStruct=dir_uvmat(FilePath);
     166            ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
     167            ListFiles=ListCells(1,:);%list of file names
     168            rr=regexp(ListFiles,detect_string,'names');
     169%         end
     170%         nbpair=numel(dirpair);
     171        nbpair=numel(rr);
    184172        ref_i_list=zeros(1,nbpair);
    185173        ref_j_list=zeros(1,nbpair);
     
    189177        % scan the list of relevant files, extract the indices
    190178        for ifile=1:nbpair
    191             rr=regexp(dirpair(ifile).name,detect_string,'names');
    192             if ~isempty(rr)
    193                 i1=str2num(rr.i1);
    194                 i2=str2num(regexprep(rr.i2,'^-',''));
    195                 j1=stra2num(regexprep(rr.j1,'^_',''));
    196                 j2=stra2num(regexprep(rr.j2,'^-',''));
     179%             rr=regexp(dirpair(ifile).name,detect_string,'names');
     180            if ~isempty(rr{ifile})
     181                i1=str2num(rr{ifile}.i1);
     182                i2=str2num(regexprep(rr{ifile}.i2,'^-',''));
     183                j1=stra2num(regexprep(rr{ifile}.j1,'^_',''));
     184                j2=stra2num(regexprep(rr{ifile}.j2,'^-',''));
    197185                ref_i=i1;
    198186                if isempty(i2_input)
     
    263251        if ~isempty(ind_select)
    264252            [tild,ifile_min]=min(ref_ij(ind_select));
    265             [tild,tild,tild,tild,tild,tild,tild,tild,NomType]=fileparts_uvmat(dirpair(ind_select(ifile_min)).name);% update the representation of indices (number of 0 before the number)
     253            [tild,tild,tild,tild,tild,tild,tild,tild,NomType]=fileparts_uvmat(ListFiles{ind_select(ifile_min)});% update the representation of indices (number of 0 before the number)
    266254            NomType=regexprep(NomType,['^' NomTypePref],'');
    267255            %% update the file type if the input file does not exist (pb of 0001)
    268256            if isempty(FileInfo.FileType)
    269                 [FileInfo,MovieObject]=get_file_info(fullfile(FilePath,dirpair(ifile_min).name));
     257                [FileInfo,MovieObject]=get_file_info(fullfile(FilePath,ListFiles(ifile_min)));
    270258            end
    271259        end
  • trunk/src/fullfile_uvmat.m

    r977 r1022  
    9393
    9494%% look for NomType with pairs (separator '-' or terminasion ab or AB
    95 if strcmp(NomType,'level')% organisation with a sub-folder for the files of each index i
    96     filename=fullfile(RootPath,SubDir,['level' num2str(j1)],[RootFile num2str(i1) FileExt]);
    97 else
     95% if strcmp(NomType,'level')% organisation with a sub-folder for the files of each index i
     96%     filename=fullfile(RootPath,SubDir,['level' num2str(j1)],[RootFile num2str(i1) FileExt]);
     97% else
    9898    if ~isempty(regexp(NomType,'^_\d'))
    9999        sep1='_';
     
    136136        end
    137137    end
     138    if isempty(regexp(RootPath,'^http://'))
    138139    filename=fullfile(RootPath,SubDir,RootFile);
     140    else
     141        filename=[RootPath '/' SubDir '/' RootFile];
     142    end
    139143    filename=[filename sep1 i1_str sep2 i2_str sep3 j1_str sep4 j2_str];
    140144    filename=[regexprep(filename,'_$','') FileExt];%suppress possible '_' at the end of the string and add the extension
    141 end
     145% end
    142146
    143147function test
  • trunk/src/get_file_info.m

    r1009 r1022  
    3838function [FileInfo,VideoObject]=get_file_info(fileinput)
    3939VideoObject=[];
    40 if exist(fileinput,'file')==2
     40if ~isempty(regexp(fileinput,'^http://'))|| exist(fileinput,'file')
    4141    FileInfo.FileName=fileinput;
    4242    FileInfo.FileType='txt'; %default
  • trunk/src/nc2struct.m

    r1001 r1022  
    7979            end
    8080        else
     81            if regexp(nc,'^http://')
     82                nc=netcdf.open(nc,'NC_NOWRITE');
     83                testfile=1;
     84            else
    8185            errormsg=['ERROR:file ' nc ' does not exist'];
    8286            return
     87            end
    8388        end
    8489    else
  • trunk/src/read_field.m

    r1007 r1022  
    5454ParamOut=ParamIn;%default
    5555errormsg='';
    56 if ~exist(FileName,'file')
     56if isempty(regexp(FileName,'^http://'))&& ~exist(FileName,'file')
    5757    errormsg=['input file ' FileName ' does not exist'];
    5858    return
  • trunk/src/uigetfile_uvmat.m

    r977 r1022  
    4848InputFileName='';%default
    4949if ischar(InputName)
    50     if exist(InputName,'dir')
    51         InputDir=InputName;
    52         InputFileName='';
    53     elseif exist(InputName,'file')
    54         [InputDir,InputFileName,Ext]=fileparts(InputName);
    55         if isempty(InputFileName)% if InputName is already the root
    56             InputFileName=InputDir;
    57             if  ~isempty(strcmp (computer, {'PCWIN','PCWIN64'}))%case of Windows systems
    58 %                 InputDir=[InputDir '\'];% append '\' for a correct action of dir
    59                 InputFileName=[InputFileName '\'];
     50    if isempty(regexp(InputName,'^http://'))%usual files
     51        if exist(InputName,'dir')
     52            InputDir=InputName;
     53            InputFileName='';
     54        elseif exist(InputName,'file')
     55            [InputDir,InputFileName,Ext]=fileparts(InputName);
     56            if isempty(InputFileName)% if InputName is already the root
     57                InputFileName=InputDir;
     58                if  ~isempty(strcmp (computer, {'PCWIN','PCWIN64'}))%case of Windows systems
     59                    %                 InputDir=[InputDir '\'];% append '\' for a correct action of dir
     60                    InputFileName=[InputFileName '\'];
     61                end
     62            end
     63            if isdir(InputName)
     64                InputFileName=['+/' InputFileName Ext];
    6065            end
    6166        end
    62         if isdir(InputName)
    63             InputFileName=['+/' InputFileName Ext];
     67        if  ismember(computer,{'PCWIN','PCWIN64'})%case of Windows systems
     68            InputDir=[InputDir '\'];% append '\' for a correct action of dir
    6469        end
    65     end
    66 end
    67 if  ismember(computer,{'PCWIN','PCWIN64'})%case of Windows systems
    68       InputDir=[InputDir '\'];% append '\' for a correct action of dir
    69 end
     70    else
     71        [InputDir,InputFileName,Ext]=fileparts(InputName);
     72    end
     73end
     74
    7075hfig=findobj(allchild(0),'tag',option);
    7176if isempty(hfig)
     
    147152htitlebox=findobj(hfig,'tag','titlebox');  % display the current dir name 
    148153DirName=get(htitlebox,'String');
    149 if isempty(regexp(DirName,'^http://'))% if the input dir is not a web site (begins by http://)
    150 %     FullSelectName=DirName;
    151 % else
    152154if ~strcmp(filter_ext,'uigetdir')% a file is expected as output, not a dir
    153155    hlist=findobj(hfig,'Tag','list');
     
    163165        SelectName=SelectName(1:ind_dot-1);
    164166    end
    165     FullSelectName=fullfile(DirName,SelectName);
    166     % if regexp(DirName,'^http://')% if the input dir is a web site (begins by http://)
    167 
    168     if exist(FullSelectName,'file')
     167    if isempty(regexp(DirName,'^http://'))% if the input dir is not a web site (begins by http://)
     168        FullSelectName=fullfile(DirName,SelectName);
     169        check_exist=exist(FullSelectName,'file');
     170    else
     171        FullSelectName=[DirName '/' SelectName];
     172        check_exist=1;
     173    end
     174    if check_exist
    169175        switch option
    170176            case 'browser'
     
    185191    end
    186192end
    187 end
    188193set(hObject,'backgroundColor',[0 1 0])% indicate end button activation
    189194uiresume(get(hObject,'parent'))
    190195
    191 %------------------------------------------------------------------------   
     196%------------------------------------------------------------------------
    192197% --- launched by refreshing the display figure
    193198function refresh_GUI(hObject,InputFileName,FilterExt)
     
    209214DirName=get(htitlebox,'String');
    210215hsort_option=findobj(hfig,'tag','sort_option');
    211 if strcmp(get(hfig,'Tag'),'status_display')
     216% use with GUI series
     217if strcmp(get(hfig,'Tag'),'status_display') % use with GUI series
    212218    hseries=findobj(allchild(0),'tag','series');
    213219    hstatus=findobj(hseries,'tag','status');
     
    218224    end
    219225    hlist=findobj(hfig,'tag','list');
    220     testrecent=0;   
     226    testrecent=0;
    221227    NbOutputFile=[];
    222228    if isfield(StatusData,'NbOutputFile')
     
    226232    [ListFiles,NumFiles]=list_files(DirName,1,TimeStart);% list the directory content
    227233   
    228     %% update the waitbar
     234    % update the waitbar
    229235    hwaitbar=findobj(hfig,'tag','waitbar');
    230236    if ~isempty(NbOutputFile)
     
    233239        set(hwaitbar,'Position',BarPosition)
    234240    end
    235 else
     241else  %use as usual browser
    236242    sort_option='name';
    237243    if strcmp(get(hsort_option,'Visible'),'on')&& isequal(get(hsort_option,'Value'),2)
     
    281287htitlebox=findobj(hfig,'tag','titlebox');  % display the new dir name 
    282288DirName=get(htitlebox,'String');
     289CheckSubDir=~isempty(regexp(list{index},'^\+'));
    283290SelectName=regexprep(list{index},'^\+/','');% remove the +/ used to mark dir
    284291ind_dot=regexp(SelectName,'\s*\.\.\.');%remove what is beyond  '...'
     
    289296    FullSelectName=fileparts(DirName);
    290297else
    291     FullSelectName=fullfile(DirName,SelectName);
    292 end
    293 if exist(FullSelectName,'dir')% a directory has been selected
     298    if isempty(regexp(DirName,'^http://'))% usual files
     299        FullSelectName=fullfile(DirName,SelectName);
     300    else
     301        FullSelectName=[DirName '/' SelectName];
     302    end
     303end
     304if CheckSubDir%exist(FullSelectName,'dir')% a directory has been selected
    294305    set(hObject,'BackgroundColor',[1 1 0])% paint list in yellow to indicate action
    295306    drawnow
     
    315326function [ListFiles,NumFiles]=list_files(DirName,check_date,sort_option,filter_ext)
    316327%-------------------------------------------------------------------------
    317 ListStruct=dir(DirName);% get structure of the current directory
     328ListStruct=dir_uvmat(DirName);% get structure of the current directory
    318329NumFiles=0; %default
    319330if numel(ListStruct)<1  % case of empty dir
    320 %     if regexp(DirName,'^http://')% if the input dir is a web site (begins by http://)
    321 %         web(DirName)
    322 %     else
    323331    ListFiles={};
    324332    return
    325 %     end
    326333end
    327334ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
    328335ListFiles=ListCells(1,:);%list of file names
    329336check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
     337% for ilist=1:numel(check_dir)
     338%     if check_dir(ilist)
    330339ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
     340%     end
     341% end
    331342if exist('filter_ext','var') && ~strcmp(filter_ext,'*') &&~strcmp(filter_ext,'uigetdir')
    332343    if strcmp(filter_ext,'image')
  • trunk/src/uvmat.m

    r1010 r1022  
    446446function MenuBrowse_Callback(hObject, eventdata, handles)
    447447[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
     448if isempty(regexp(RootPath,'^http://'))%usual files
    448449oldfile=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
     450else %Opendap
     451    oldfile=[RootPath '/' SubDir '/' RootFile FileIndices FileExt];
     452end
    449453if isempty(oldfile) %loads the previously stored file name and set it as default in the file_input box
    450454    oldfile=get(handles.RootPath,'UserData');
     
    452456fileinput=uigetfile_uvmat('pick an input file',oldfile);
    453457hh=dir(fileinput);
    454 if numel(hh)>1fill_GUI
     458if numel(hh)>1
    455459    msgbox_uvmat('ERROR','invalid input, probably a broken link');
    456460else
     
    18001804%% look for the input file existence
    18011805errormsg='';%default
    1802 if ~exist(fileinput,'file')
     1806if isempty(regexp(fileinput,'^http://')) && ~exist(fileinput,'file')
    18031807    errormsg=['input file ' fileinput  ' does not exist'];
    18041808    msgbox_uvmat('ERROR',errormsg)
     
    18411845% detect the file type, get the movie object if relevant, and look for the corresponding file series:
    18421846% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
     1847% if isempty(regexp(fileinput,'^http://'))
    18431848[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileInfo,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
     1849% else
     1850%     FileInfo.FileType='netcdf';
     1851%     [RootPath,SubDir,RootFile,i1,i2,j1,j2,Ext,NomType]=fileparts_uvmat(fileinput);
     1852%     i1_series=[0 i1 i2];
     1853%     i2_series=[];
     1854%     j1_series=[0 j1 j1];
     1855%     j2_series=[0 j1 j1];
     1856%     MovieObject=[];
     1857% %     [RootPath,RootFile]=fileparts(fileinput);
     1858% %     [RootPath,SubDir]=fileparts(RootPath);
     1859% %     NomType='*';
     1860% end
    18441861FileType=FileInfo.FileType;
    18451862if strcmp(FileType,'txt')
     
    18831900        set(handles_SubDir,'String',['/' SubDir]);
    18841901        set(handles_RootFile,'String',['/' RootFile]); %display the separator
    1885         if strcmp(NomType,'level')
    1886             rootname=fullfile(RootPath,SubDir,'level');
    1887             rr=regexp(fileinput,['^' rootname '(?<j>\d+)/' RootFile '(?<i>\d+)' FileExt '$'],'names');
    1888             if ~isempty(rr)
    1889                 set(handles_FileIndex,'String',rr.i);
    1890             end
    1891         else
     1902%         if strcmp(NomType,'level')
     1903%             rootname=fullfile(RootPath,SubDir,'level');
     1904%             rr=regexp(fileinput,['^' rootname '(?<j>\d+)/' RootFile '(?<i>\d+)' FileExt '$'],'names');
     1905%             if ~isempty(rr)
     1906%                 set(handles_FileIndex,'String',rr.i);
     1907%             end
     1908%         else
     1909            if isempty(regexp(RootPath,'^http://'))
    18921910            rootname=fullfile(RootPath,SubDir,RootFile);
     1911            else
     1912                rootname=[RootPath '/' SubDir '/' RootFile];
     1913            end
    18931914            indices=fileinput(length(rootname)+1:end);
    18941915            indices(end-length(FileExt)+1:end)=[]; %remove extension
    18951916            set(handles_FileIndex,'String',indices);
    1896         end
     1917%         end
    18971918        set(handles_NomType,'String',NomType);
    18981919        set(handles_FileExt,'String',FileExt);
     
    31873208if isempty(i2), set(handles.i2,'String',''); end % suppress the second i index display if not used
    31883209if isempty(j2), set(handles.j2,'String',''); end % suppress the second j index display if not used
    3189 if strcmp(get(handles.NomType,'String'),'level')
    3190     jindex=str2num(get(handles.j1,'String'));
    3191     filename=[fullfile(RootPath,SubDir,['level' num2str(jindex)],RootFile) FileIndex FileExt];% build the input file name (first line)
    3192 else
     3210% if strcmp(get(handles.NomType,'String'),'level')
     3211%     jindex=str2num(get(handles.j1,'String'));
     3212%     filename=[fullfile(RootPath,SubDir,['level' num2str(jindex)],RootFile) FileIndex FileExt];% build the input file name (first line)
     3213% else
     3214if isempty(regexp(RootPath,'^http://'))
    31933215filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)
     3216else
     3217    filename=[RootPath '/' SubDir '/' RootFile FileIndex FileExt];%
    31943218end
    31953219filename_1='';%default second file name
     
    32473271
    32483272%% determine the main input file information for action
    3249 if ~exist(FileName,'file')
     3273if isempty(regexp(FileName,'^http://')) &&~exist(FileName,'file')
    32503274    errormsg=['input file ' FileName ' does not exist'];
    32513275    return
     
    43404364field= list_fields{index_fields(1)}; % selected string
    43414365[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
     4366if isempty(regexp(RootPath,'^http://'))
    43424367FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
     4368else
     4369    FileName=[RootPath '/' SubDir '/' RootFile FileIndices FileExt];
     4370end
    43434371[tild,tild,tild,i1,i2,j1,j2,tild,NomType]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt]);
    43444372
     
    43854413        %read selection from get_field
    43864414        [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
     4415        if isempty(regexp(RootPath,'^http://'))
    43874416        FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
     4417        else
     4418            FileName=[RootPath '/' SubDir '/' RootFile FileIndices FileExt];
     4419        end
    43884420        GetFieldData=get_field(FileName,ParamIn);% inport field names from the GUI get_field
    43894421        FieldList={};
Note: See TracChangeset for help on using the changeset viewer.