Changeset 930 for trunk


Ignore:
Timestamp:
Mar 10, 2016, 9:40:57 PM (9 years ago)
Author:
sommeria
Message:

extract functions updated

Location:
trunk/src
Files:
1 added
3 edited

Legend:

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

    r929 r930  
    153153end
    154154t=xmltree;
    155 %%% A REMETTREE %%%%%%%%%%%%%%%%%%%%%
     155
    156156save(t,fullfile(RootPath,'Running.xml'))%create an xml file to indicate that processing takes place
    157157
     
    194194        return
    195195    end
    196     [XmlData,errormsg]=imadoc2struct(filexml);
     196 
    197197    newxml=fullfile(RootPath,Param.InputTable{iview,3});
    198198    newxml=regexprep(newxml,'_Master_Dalsa_4M180$','');%suppress '_Master_Dalsa_4M180'
    199199    newxml=[newxml '.xml'];
    200200   
    201     [success,errormsg] = copyfile(filexml,newxml); %copy the xml file in the upper folder
    202        
    203     nbfield2=size(XmlData.Time,2)-1;
    204     if nbfield2>1
    205         NomTypeNew='_1_1';
    206     else
    207         NomTypeNew='_1';
    208     end
     201    %copyfile_modif(filexml,newxml); %copy the xml file in the upper folder
     202   
     203    %[XmlData,errormsg]=imadoc2struct(newxml);
     204%     nbfield2=size(XmlData.Time,2)-1;
     205%     if nbfield2>1
     206%         NomTypeNew='_1_1';
     207%     else
     208%         NomTypeNew='_1';
     209%     end
    209210    %% get the names of .seq and .sqb files
    210211    switch Param.InputTable{iview,5}
     
    212213            filename_seq=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.seq']);
    213214            filename_sqb=fullfile(RootPath,Param.InputTable{iview,2},[Param.InputTable{iview,3} '.sqb']);
    214             logdir=[Param.InputTable{1,2} .extract];
     215            logdir=[Param.OutputSubDir Param.OutputDirExt];
    215216            [success,errormsg] = copyfile(filename_seq,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.seq']); %copy the seq file in the upper folder
    216217            [success,errormsg] = copyfile(filename_sqb,[fullfile(RootPath,logdir,Param.InputTable{iview,3}) '.sqb']); %copy the sqb file in the upper folder
     
    240241        SeqData.binrepertoire=[SeqData.binrepertoire DirExt];
    241242    end
    242    
    243     %% checking consistency with the xml file
    244     [npi,npj]=size(XmlData.Time);
    245     if ~isequal(SeqData.nb_frames,(npi-1)*(npj-1))
    246         disp_uvmat('ERRROR',['inconsistent number of images ' num2str(SeqData.nb_frames) ' with respect to the xml file: ' num2str((npi-1)*(npj-1))] ,checkrun);
    247         return
    248     end
     243   
    249244   
    250245    %% reading the .sqb file
     
    273268    for ii=1: numel(m.Data)
    274269        timestamp(ii)=m.Data(ii).timestamp;
    275         j1=1;
    276         if ~isequal(nbfield2,1)
    277             j1=mod(ii-1,nbfield2)+1;
    278         end
    279         i1=floor((ii-1)/nbfield2)+1;
    280         diff_time(i1,j1)= timestamp(ii)-XmlData.Time(i1+1,j1+1);
    281     end
    282     time_diff_max=max(diff_time');
    283     time_diff_min=min(diff_time');
    284     if max(time_diff_max)>0.005
    285         disp(['WARNING:timestamps exceeds xml time by' num2str(max(time_diff_max))])
    286         checkpreserve=1;
    287     elseif min(time_diff_min)<-0.005
    288         disp(['timestamps is lower than xml time by' num2str(min(time_diff_min))])
    289         checkpreserve=1;
     270%         j1=1;
     271%         if ~isequal(nbfield2,1)
     272%             j1=mod(ii-1,nbfield2)+1;
     273%         end
     274%         i1=floor((ii-1)/nbfield2)+1;
     275        %diff_time(i1,j1)= timestamp(ii)-XmlData.Time(i1+1,j1+1);
     276    end
     277    [nbfield2,msg]=copyfile_modif(filexml,timestamp,newxml); %copy the xml file in the upper folder
     278    [XmlData,errormsg]=imadoc2struct(newxml);% check reading of the new xml file
     279    if ~isempty(errormsg)
     280        disp(errormsg)
     281        return
     282    end
     283    difftime=XmlData.Time(2:end,2:end)-(reshape(timestamp,nbfield2,[]))';
     284    disp(['time from xml and timestamp differ by ' num2str(max(max(abs(difftime))))])
     285    if max(abs(difftime))>0.01
     286        checkpreserve=1;% will not erase the initial files, possibility of error
     287    end
     288    if nbfield2>1
     289        NomTypeNew='_1_1';
    290290    else
    291         disp('CONFIRMATION:time from xml file correct within better than 5 ms')
    292     end
    293     if checkpreserve
    294           disp(  'max and min of timestamp-xml time for each index i:')
    295           disp(time_diff_max)
    296           disp(time_diff_min)           
    297     end
     291        NomTypeNew='_1';
     292    end
     293
    298294    [BinList,errormsg]=binread_rdv_series(RootPath,SeqData,m.Data,nbfield2,NomTypeNew);
    299295    if ~isempty(errormsg)
     
    301297        return
    302298    end
     299   
    303300    % check the existence of the expected output image files (from the xml)
    304301    FileDir=SeqData.sequencename;
     
    314311%% remove binary files if transfer OK
    315312    if ~checkpreserve
    316         for ibin=1:numel(BinList)
    317             delete(BinList{ibin})
     313        for iview=1:size(Param.InputTable,1)
     314         fullfile(RootPath,Param.InputTable{iview,2})
     315
     316        [SUCCESS,MESSAGE]=rmdir(fullfile(RootPath,Param.InputTable{iview,2}),'s')
    318317        end
    319         rmdir(fullfile(RootPath,Param.InputTable{iview,2}))
    320318    end
    321319delete(fullfile(RootPath,'Running.xml'))%delete the  xml file to indicate that processing is finished
     
    323321%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    324322%--------- reads a series of bin files
     323
    325324%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    326325function [BinList,errormsg]=binread_rdv_series(PathDir,SeqData,SqbData,nbfield2,NomTypeNew)
     
    349348fid=0;
    350349errormsg='';
     350BinList={};
     351
    351352classname=sprintf('uint%d',SeqData.bytesperpixel*8);
    352353
     
    424425
    425426
    426 % for ifile=1:nbfield
    427 %             update_waitbar(WaitbarHandle,ifile/nbfield)
    428 %     if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue')
    429 %         disp('program stopped by user')
    430 %         break
    431 %     end
    432 %     [A,FileInfo,timestamps]=read_rdvision(filename,ifile);
    433 %     if ifile==1
    434 %         classA=class(A);
    435 %         if strcmp(classA,'uint8')
    436 %             BitDepth=8;
    437 %         else
    438 %         BitDepth=16;
    439 %         end
    440 %     end
    441 %     j1=[];
    442 %     if ~isequal(nbfield2,1)
    443 %     j1=mod(ifile-1+first_label,nbfield2)+1;
    444 %     end
    445 %     i1=floor((ifile-1+first_label)/nbfield2)+1;
    446 %     OutputFile=fullfile_uvmat(RootPath{1},OutputDir,'img','.png',NomTypeNew,i1,[],j1);
    447 %     try
    448 %         imwrite(A,OutputFile,'BitDepth',BitDepth) % case of 16 bit images
    449 %     disp([OutputFile ' written']);
    450 %         [s,errormsg] = fileattrib(OutputFile,'-w','a'); %set images to read only '-w' for all users ('a')
    451 %         if ~s
    452 %             disp_uvmat('ERROR',errormsg,checkrun);
    453 %             return
    454 %         end
    455 %     catch ME
    456 %         disp_uvmat('ERROR',ME.message,checkrun);
    457 %         return
    458 %     end
    459 %
    460 % end
    461 
    462 %'imadoc2struct_special': reads the xml file for image documentation
    463 %------------------------------------------------------------------------
    464 % function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
    465 %
    466 % OUTPUT:
    467 % s: structure representing ImaDoc
    468 %   s.Heading: information about the data hierarchical structure
    469 %   s.Time: matrix of times
    470 %   s.TimeUnit
    471 %  s.GeometryCalib: substructure containing the parameters for geometric calibration
    472 % errormsg: error message
    473 %
    474 % INPUT:
    475 % ImaDoc: full name of the xml input file with head key ImaDoc
    476 % option: ='GeometryCalib': read  the data of GeometryCalib, including source point coordinates
    477 
    478 function [s,errormsg]=imadoc2struct_special(ImaDoc,option)
    479 
    480 %% default input and output
    481 if ~exist('option','var')
    482     option='*';
    483 end
    484 errormsg=[];%default
    485 s.Heading=[];%default
    486 s.Time=[]; %default
    487 s.TimeUnit=[]; %default
    488 s.GeometryCalib=[];
    489 tsai=[];%default
    490 
    491 %% opening the xml file
    492 if exist(ImaDoc,'file')~=2, errormsg=[ ImaDoc ' does not exist']; return;end;%input file does not exist
    493 try
    494     t=xmltree(ImaDoc);
    495 catch
    496     errormsg={[ImaDoc ' is not a valid xml file']; lasterr};
    497     display(errormsg);
    498     return
    499 end
    500 uid_root=find(t,'/ImaDoc');
    501 if isempty(uid_root), errormsg=[ImaDoc ' is not an image documentation file ImaDoc']; return; end;%not an ImaDoc .xml file
    502 
    503 
    504 %% Heading
    505 uid_Heading=find(t,'/ImaDoc/Heading');
    506 if ~isempty(uid_Heading),
    507     uid_Campaign=find(t,'/ImaDoc/Heading/Campaign');
    508     uid_Exp=find(t,'/ImaDoc/Heading/Experiment');
    509     uid_Device=find(t,'/ImaDoc/Heading/Device');
    510     uid_Record=find(t,'/ImaDoc/Heading/Record');
    511     uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName');
    512     s.Heading.Campaign=get(t,children(t,uid_Campaign),'value');
    513     s.Heading.Experiment=get(t,children(t,uid_Exp),'value');
    514     s.Heading.Device=get(t,children(t,uid_Device),'value');
    515     if ~isempty(uid_Record)
    516         s.Heading.Record=get(t,children(t,uid_Record),'value');
    517     end
    518     s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value');
    519 end
    520 
    521 %% Camera  and timing
    522 if strcmp(option,'*') || strcmp(option,'Camera')
    523     uid_Camera=find(t,'/ImaDoc/Camera');
    524     if ~isempty(uid_Camera)
    525         uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize');
    526         if ~isempty(uid_ImageSize);
    527             ImageSize=get(t,children(t,uid_ImageSize),'value');
    528             xindex=findstr(ImageSize,'x');
    529             if length(xindex)>=2
    530                 s.Npx=str2double(ImageSize(1:xindex(1)-1));
    531                 s.Npy=str2double(ImageSize(xindex(1)+1:xindex(2)-1));
    532             end
    533         end
    534         uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit');
    535         if ~isempty(uid_TimeUnit)
    536             s.TimeUnit=get(t,children(t,uid_TimeUnit),'value');
    537         end
    538         uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming');
    539         if ~isempty(uid_BurstTiming)
    540             for k=1:length(uid_BurstTiming)
    541                 subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming
    542                 % reading Dtk
    543                 Frequency=get_value(subt,'/BurstTiming/FrameFrequency',1);
    544                 Dtj=get_value(subt,'/BurstTiming/Dtj',[]);
    545                 Dtj=Dtj/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
    546                 NbDtj=get_value(subt,'/BurstTiming/NbDtj',[]);
    547                 %%%% correction RDvision %%%%
    548 %                 NbDtj=NbDtj/numel(Dtj);
    549 %                 s.NbDtj=NbDtj;
    550 %                 %%%%
    551                 Dti=get_value(subt,'/BurstTiming/Dti',[]);
    552                 NbDti=get_value(subt,'/BurstTiming/NbDti',1);
    553                  %%%% correction RDvision %%%%
    554                 if isempty(Dti)% series
    555                      Dti=Dtj;
    556                       NbDti=NbDtj;
    557                      Dtj=[];
    558                      s.Dti=Dti;
    559                      s.NbDti=NbDti;
    560                 else
    561                     % NbDtj=NbDtj/numel(Dtj);%bursts
    562                     if ~isempty(NbDtj)
    563                     s.NbDtj=NbDtj/numel(Dtj);%bursts;
    564                     else
    565                         s.NbDtj=1;
    566                     end
    567                 end
    568                 %%%% %%%%
    569                 Dti=Dti/Frequency;%Dtj converted from frame unit to TimeUnit (e.g. 's')
    570 
    571                 Time_val=get_value(subt,'/BurstTiming/Time',0);%time in TimeUnit
    572                 if ~isempty(Dti)
    573                     Dti=reshape(Dti'*ones(1,NbDti),NbDti*numel(Dti),1); %concatene Dti vector NbDti times
    574                     Time_val=[Time_val;Time_val(end)+cumsum(Dti)];%append the times defined by the intervals  Dti
    575                 end
    576                 if ~isempty(Dtj)
    577                     Dtj=reshape(Dtj'*ones(1,s.NbDtj),1,s.NbDtj*numel(Dtj)); %concatene Dtj vector NbDtj times
    578                     Dtj=[0 Dtj];
    579                     Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj
    580                 end
    581                 % reading Dtk
    582                 Dtk=get_value(subt,'/BurstTiming/Dtk',[]);
    583                 NbDtk=get_value(subt,'/BurstTiming/NbDtk',1);
    584                 %%%% correction RDvision %%%%
    585                 if ~isequal(NbDtk,1)
    586                     NbDtk=-1+(NbDtk+1)/(NbDti+1);
    587                 end
    588                 s.NbDtk=NbDtk;
    589                 %%%%%
    590                 if isempty(Dtk)
    591                     s.Time=[s.Time;Time_val];
    592                 else
    593                     for kblock=1:NbDtk+1
    594                         Time_val_k=Time_val+(kblock-1)*Dtk;
    595                         s.Time=[s.Time;Time_val_k];
    596                     end
    597                 end
    598             end
    599         end
    600     end
    601 end
    602 
    603 %% motor
    604 if strcmp(option,'*') || strcmp(option,'GeometryCalib')
    605     uid_subtree=find(t,'/ImaDoc/TranslationMotor');
    606     if length(uid_subtree)==1
    607         subt=branch(t,uid_subtree);%subtree under GeometryCalib
    608        [s.TranslationMotor,errormsg]=read_subtree(subt,{'Nbslice','ZStart','ZEnd'},[1 1 1],[1 1 1]);
    609     end
    610 end
    611 %%  geometric calibration
    612 if strcmp(option,'*') || strcmp(option,'GeometryCalib')
    613     uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib');
    614     if ~isempty(uid_GeometryCalib)
    615         if length(uid_GeometryCalib)>1
    616             errormsg=['More than one GeometryCalib in ' filecivxml];
    617             return
    618         end
    619         subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib
    620         cont=get(subt,1,'contents');
    621         if ~isempty(cont)
    622             uid_CalibrationType=find(subt,'/GeometryCalib/CalibrationType');
    623             if isequal(length(uid_CalibrationType),1)
    624                 tsai.CalibrationType=get(subt,children(subt,uid_CalibrationType),'value');
    625             end
    626             uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit');
    627             if isequal(length(uid_CoordUnit),1)
    628                 tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value');
    629             end
    630             uid_fx_fy=find(subt,'/GeometryCalib/fx_fy');
    631             focal=[];%default fro old convention (Reg Wilson)
    632             if isequal(length(uid_fx_fy),1)
    633                 tsai.fx_fy=str2num(get(subt,children(subt,uid_fx_fy),'value'));
    634             else %old convention (Reg Wilson)
    635                 uid_focal=find(subt,'/GeometryCalib/focal');
    636                 uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy');
    637                 uid_sx=find(subt,'/GeometryCalib/sx');
    638                 if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_sx)
    639                     dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));
    640                     sx=str2num(get(subt,children(subt,uid_sx),'value'));
    641                     focal=str2num(get(subt,children(subt,uid_focal),'value'));
    642                     tsai.fx_fy(1)=sx*focal/dpx_dpy(1);
    643                     tsai.fx_fy(2)=focal/dpx_dpy(2);
    644                 end
    645             end
    646             uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy');
    647             if ~isempty(uid_Cx_Cy)
    648                 tsai.Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value'));
    649             end
    650             uid_kc=find(subt,'/GeometryCalib/kc');
    651             if ~isempty(uid_kc)
    652                 tsai.kc=str2double(get(subt,children(subt,uid_kc),'value'));
    653             else %old convention (Reg Wilson)
    654                 uid_kappa1=find(subt,'/GeometryCalib/kappa1');
    655                 if ~isempty(uid_kappa1)&& ~isempty(focal)
    656                     kappa1=str2double(get(subt,children(subt,uid_kappa1),'value'));
    657                     tsai.kc=-kappa1*focal*focal;
    658                 end
    659             end
    660             uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
    661             if ~isempty(uid_Tx_Ty_Tz)
    662                 tsai.Tx_Ty_Tz=str2num(get(subt,children(subt,uid_Tx_Ty_Tz),'value'));
    663             end
    664             uid_R=find(subt,'/GeometryCalib/R');
    665             if ~isempty(uid_R)
    666                 RR=get(subt,children(subt,uid_R),'value');
    667                 if length(RR)==3
    668                     tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})];
    669                 end
    670             end
    671            
    672             %look for laser plane definitions
    673             uid_Angle=find(subt,'/GeometryCalib/PlaneAngle');
    674             uid_Pos=find(subt,'/GeometryCalib/SliceCoord');
    675             if isempty(uid_Pos)
    676                 uid_Pos=find(subt,'/GeometryCalib/PlanePos');%old convention
    677             end
    678             if ~isempty(uid_Angle)
    679                 tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value'));
    680             end
    681             if ~isempty(uid_Pos)
    682                 for j=1:length(uid_Pos)
    683                     tsai.SliceCoord(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value'));
    684                 end
    685                 uid_DZ=find(subt,'/GeometryCalib/SliceDZ');
    686                 uid_NbSlice=find(subt,'/GeometryCalib/NbSlice');
    687                 if ~isempty(uid_DZ) && ~isempty(uid_NbSlice)
    688                     DZ=str2double(get(subt,children(subt,uid_DZ),'value'));
    689                     NbSlice=get(subt,children(subt,uid_NbSlice),'value');
    690                     if isequal(NbSlice,'volume')
    691                         tsai.NbSlice='volume';
    692                         NbSlice=NbDtj+1;
    693                     else
    694                         tsai.NbSlice=str2double(NbSlice);
    695                     end
    696                     tsai.SliceCoord=ones(NbSlice,1)*tsai.SliceCoord+DZ*(0:NbSlice-1)'*[0 0 1];
    697                 end
    698             end   
    699             tsai.SliceAngle=get_value(subt,'/GeometryCalib/SliceAngle',[0 0 0]);
    700             tsai.VolumeScan=get_value(subt,'/GeometryCalib/VolumeScan','n');
    701             tsai.InterfaceCoord=get_value(subt,'/GeometryCalib/InterfaceCoord',[0 0 0]);
    702             tsai.RefractionIndex=get_value(subt,'/GeometryCalib/RefractionIndex',1);
    703            
    704             if strcmp(option,'GeometryCalib')
    705                 tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]);
    706             end
    707             s.GeometryCalib=tsai;
    708         end
    709     end
    710 end
    711 
    712 %--------------------------------------------------
    713 %  read a subtree
    714 % INPUT:
    715 % t: xltree
    716 % head_element: head elelemnt of the subtree
    717 % Data, structure containing
    718 %    .Key: element name
    719 %    .Type: type of element ('charg', 'float'....)
    720 %    .NbOccur: nbre of occurrence, NaN for un specified number
    721 function [s,errormsg]=read_subtree(subt,Data,NbOccur,NumTest)
    722 %--------------------------------------------------
    723 s=[];%default
    724 errormsg='';
    725 head_element=get(subt,1,'name');
    726     cont=get(subt,1,'contents');
    727     if ~isempty(cont)
    728         for ilist=1:length(Data)
    729             uid_key=find(subt,[head_element '/' Data{ilist}]);
    730             if ~isequal(length(uid_key),NbOccur(ilist))
    731                 errormsg=['wrong number of occurence for ' Data{ilist}];
    732                 return
    733             end
    734             for ival=1:length(uid_key)
    735                 val=get(subt,children(subt,uid_key(ival)),'value');
    736                 if ~NumTest(ilist)
    737                     eval(['s.' Data{ilist} '=val;']);
    738                 else
    739                     eval(['s.' Data{ilist} '=str2double(val);'])
    740                 end
    741             end
    742         end
    743     end
    744 
    745 
    746 %--------------------------------------------------
    747 %  read an xml element
    748 function val=get_value(t,label,default)
    749 %--------------------------------------------------
    750 val=default;
    751 uid=find(t,label);%find the element iud(s)
    752 if ~isempty(uid) %if the element named label exists
    753    uid_child=children(t,uid);%find the children
    754    if ~isempty(uid_child)
    755        data=get(t,uid_child,'type');%get the type of child
    756        if iscell(data)% case of multiple element
    757            for icell=1:numel(data)
    758                val_read=str2num(get(t,uid_child(icell),'value'));
    759                if ~isempty(val_read)
    760                    val(icell,:)=val_read;
    761                end
    762            end
    763 %           val=val';
    764        else % case of unique element value
    765            val_read=str2num(get(t,uid_child,'value'));
    766            if ~isempty(val_read)
    767                val=val_read;
    768            else
    769               val=get(t,uid_child,'value');%char string data
    770            end
    771        end
    772    end
    773 end
    774 
    775 
    776 
    777 
     427function [nbfield2,msg]=copyfile_modif(filexml,timestamp,newxml)
     428msg='';
     429t=xmltree(filexml);
     430
     431%% correct NbDtj
     432uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
     433uid_content=get(t,uid_NbDtj,'contents');
     434t=set(t,uid_content,'value','1');% set NbDtj to 1 (correct error in the xml file)
     435
     436%% check Dtj
     437uid_Dtj=find(t,'ImaDoc/Camera/BurstTiming/Dtj');
     438uid_content=get(t,uid_Dtj,'contents');
     439Dtj=str2num(get(t,uid_content,'value'));
     440nbfield2=numel(Dtj)+1;
     441timestamp=(reshape(timestamp,nbfield2,[]))';
     442diff_Dtj=diff(timestamp(1,:))-Dtj;
     443if max(abs(diff_Dtj))>min(Dtj)/1000
     444    disp(['Dtj from xml file differs from time stamp by ' num2str(max(abs(diff_Dtj))) ', '])%'
     445else
     446    disp('Dtj OK');
     447end
     448
     449%% correct NbDti
     450NbDti=size(timestamp,1); %default for series or burst
     451uid_motor_nbslice=find(t,'ImaDoc/TranslationMotor/Nbslice');
     452if ~isempty(uid_motor_nbslice)
     453    uid_content=get(t,uid_motor_nbslice,'contents');
     454    NbSlice=str2num(get(t,uid_content,'value'));
     455    NbDti=NbSlice-1;
     456uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
     457uid_content=get(t,uid_NbDti,'contents');
     458t=set(t,uid_content,'value',num2str(NbDti));
     459end
     460
     461%% adjust Dti
     462uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
     463uid_content=get(t,uid_Dti,'contents');
     464Dti=str2num(get(t,uid_content,'value'));
     465Dti_stamp=(timestamp(1+NbDti,1)-timestamp(1,1))/NbDti;
     466if abs(Dti_stamp-Dti)>Dti/1000
     467    disp([msg 'Dti from xml file corrected by ' num2str(Dti_stamp-Dti) ', ']);%'
     468else
     469    disp('Dti OK')
     470end
     471t=set(t,uid_content,'value',num2str(Dti_stamp));
     472
     473%% adjust Dtk
     474uid_Dtk=find(t,'ImaDoc/Camera/BurstTiming/Dtk');
     475if ~isempty(uid_Dtk)
     476uid_content_Dtk=get(t,uid_Dtk,'contents');
     477Dtk=str2num(get(t,uid_content_Dtk,'value'));
     478uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
     479uid_content_NbDtk=get(t,uid_NbDtk,'contents');
     480NbDtk=str2num(get(t,uid_content_NbDtk,'value'));
     481Dtk_stamp=(timestamp(end-NbDti,1)-timestamp(1,1))/NbDtk;
     482if abs(Dtk_stamp-Dtk)>Dtk/1000
     483    disp([msg 'Dtk from xml file corrected by ' num2str(Dtk_stamp-Dtk)]);
     484else
     485    disp('Dtk OK')
     486end
     487t=set(t,uid_content_Dtk,'value',num2str(Dtk_stamp));
     488end
     489
     490save(t,newxml)
     491
     492
     493
     494
  • trunk/src/struct2nc.m

    r924 r930  
    3535%=======================================================================
    3636
    37 function errormsg=struct2nc(flname,Data)
    38 if ~ischar(flname)
    39     errormsg='invalid input for the netcf file name';
    40     return
    41 end
     37function [errormsg,nc]=struct2nc(flname,Data,action)
     38nc=[];
     39% if ~ischar(flname)
     40%     errormsg='invalid input for the netcf file name';
     41%     return
     42% end
    4243if ~exist('Data','var')
    4344     errormsg='no data  input for the netcdf file';
    4445    return
    4546end
    46 FilePath=fileparts(flname);
    47 if ~strcmp(FilePath,'') && ~exist(FilePath,'dir')
    48     errormsg=['directory ' FilePath ' needs to be created'];
    49     return
    50 end
     47if ~exist('action','var')
     48    action='one_input'; %fill the file with data and close it
     49end
     50
    5151
    5252%% check the validity of the input field structure
     
    5959
    6060%% create the netcdf file with name flname in format NETCDF4
    61 cmode = netcdf.getConstant('NETCDF4');
    62 cmode = bitor(cmode, netcdf.getConstant('CLASSIC_MODEL'));
    63 cmode = bitor(cmode, netcdf.getConstant('CLOBBER'));
    64 nc = netcdf.create(flname, cmode);
     61if ischar(flname)
     62    FilePath=fileparts(flname);
     63    if ~strcmp(FilePath,'') && ~exist(FilePath,'dir')
     64        errormsg=['directory ' FilePath ' needs to be created'];
     65        return
     66    end
     67    cmode = netcdf.getConstant('NETCDF4');
     68    cmode = bitor(cmode, netcdf.getConstant('CLASSIC_MODEL'));
     69    cmode = bitor(cmode, netcdf.getConstant('CLOBBER'));
     70    nc = netcdf.create(flname, cmode);
     71else
     72    nc=flname;
     73end
    6574
    6675%% write global constants
     
    159168    end
    160169end
     170if strcmp(action,'one_input')
    161171netcdf.close(nc)
    162 
     172end
    163173
    164174%'check_field_structure': check the validity of the field struture representation consistant with the netcdf format
  • trunk/src/xml2struct.m

    r924 r930  
    1313
    1414%=======================================================================
    15 % Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
     15% Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France/.fsnet/project/coriolis/2016/16CIRCUMPOLAR/EXP07/2016-03-08T
     16
    1617%   http://www.legi.grenoble-inp.fr
    1718%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
Note: See TracChangeset for help on using the changeset viewer.