Index: trunk/src/series/sliding_average.m
===================================================================
--- trunk/src/series/sliding_average.m	(revision 1093)
+++ trunk/src/series/sliding_average.m	(revision 1094)
@@ -25,7 +25,7 @@
 %             .RUN =0 for GUI input, =1 for function activation
 %             .RunMode='local','background', 'cluster': type of function  use
-%             
-%    .IndexRange: set the file or frame indices on which the action must be performed
-%    .FieldTransform: .TransformName: name of the selected transform function
+%             900
+%    .IndexRange: set the file or frame indices on which the action must be performseriesed
+%    .FieldTransform: .TransformName: name of the select39ed transform function
 %                     .TransformPath:   path  of the selected transform function
 %    .InputFields: sub structure describing the input fields withfields
@@ -34,9 +34,8 @@
 %              .FieldName_1: name of the second field in case of two input series
 %              .VelType_1: velocity type of the second field in case of two input series
-%              .Coord_y: name of y coordinate variable
+%             uvmat .Coord_y: name of y coordinate variable
 %              .Coord_x: name of x coordinate variable
 %    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
 %=======================================================================
 % Copyright 2008-2021, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
@@ -62,10 +61,10 @@
 if isstruct(Param) && isequal(Param.Action.RUN,0)
     ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
-    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
+    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to mseriesax (options 'off'/'on', 'off' by default)
     ParamOut.NbSlice=1; %nbre of slices ('off' by default)
     ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
     ParamOut.FieldTransform = 'on';%can use a transform function
-    ParamOut.ProjObject='off';%can use projection object(option 'off'/'on',
+    ParamOut.ProjObject='off';%can use projection object39(option 'off'/'on',
     ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
     ParamOut.OutputDirExt='.tfilter';%set the output dir extension
@@ -122,5 +121,5 @@
         return
     end
-    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
+    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});900
     FileType{iview}=FileInfo{iview}.FileType;
     CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
@@ -138,5 +137,5 @@
 if size(time,1)>1
     diff_time=max(max(diff(time)));
-    if diff_time>0
+    if diff_time>0series
         msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
     end   
@@ -177,5 +176,5 @@
 
 %% Set field names and velocity types
-InputFields{1}=[];%default (case of images)
+InputFields{1}=[];%default (case of images)series
 if isfield(Param,'InputFields')
     InputFields{1}=Param.InputFields;
@@ -187,12 +186,18 @@
 %% initialisation
 T=24.2; %main wave period
+t0=3; % time for motion start (torus at its maximum x)
 NbPeriod=2; %number of periods for the sliding average
 omega=2*pi/T;
+amplitude=2.5; %oscillation amplitude
+Lscale=15;%diameter of the torus, length scale for normalisation
+Uscale=amplitude*omega;
 
 DataOut.ListGlobalAttribute= {'Conventions','Time'};
 DataOut.Conventions='uvmat';
-DataOut.ListVarName={'coord_y','coord_x','Umean','Vmean','Ucos','Vcos','DUDXsin','DUDYsin','DVDXsin','DVDYsin','Ustokes','Vstokes'};
+DataOut.ListVarName={'coord_y','coord_x','Umean','Vmean','Ucos','Vcos','DUDXsin','DUDXcos','DUDYsin','DVDXsin','DVDXcos'...
+    ,'DVDYsin','Ustokes','Vstokes'};
 DataOut.VarDimName={'coord_y','coord_x',{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},...
-    {'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'}};
+    {'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},...
+    {'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'}};
 
 %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
@@ -207,6 +212,9 @@
 Time_end=Data.Time;
 dt=(Time_end-Time_1)/(NbField-1); %time interval 
-NpTime=round(NbPeriod*T/dt+1)
-
+NpTime=round(NbPeriod*T/dt+1);
+
+OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
+RootFileOut=RootFile{1};
+NomTypeOut='_1';
 %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
 disp('loop for filtering started')
@@ -219,8 +227,8 @@
     [Field,tild,errormsg] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
     
-    %%%%%%%%%%%% MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
+    %%%%%%%%%%% MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
     if index==1 %first field
-        DataOut.coord_x=Field.coord_x;
-        DataOut.coord_y=Field.coord_y;
+        DataOut.coord_x=Field.coord_x/Lscale;
+        DataOut.coord_y=Field.coord_y/Lscale;
         npy=numel(DataOut.coord_y);
         npx=numel(DataOut.coord_x);
@@ -229,49 +237,56 @@
         Ucos=zeros(NpTime,npy,npx);
         Vcos=zeros(NpTime,npy,npx);
+        DUDXcos=zeros(NpTime,npy,npx);
         DUDXsin=zeros(NpTime,npy,npx);
         DUDYsin=zeros(NpTime,npy,npx);
+        DVDXcos=zeros(NpTime,npy,npx);
         DVDXsin=zeros(NpTime,npy,npx);
         DVDYsin=zeros(NpTime,npy,npx);
     end
-      Time(index)=Field.Time;
+    Time(index)=Field.Time-t0;%time from the start of the motion
     Umean=circshift(Umean,[-1 0 0]); %shift U by ishift along the first index
-        Vmean=circshift(Vmean,[-1 0 0]); %shift U by ishift along the first index
-        Ucos=circshift(Ucos,[-1 0 0]); %shift U by ishift along the first index
-        Vcos=circshift(Vcos,[-1 0 0]); %shift U by ishift along the first index
-        DUDXsin=circshift(DUDXsin,[-1 0 0]);
-        DUDYsin=circshift(DUDYsin,[-1 0 0]);
-        DVDXsin=circshift(DVDXsin,[-1 0 0]);
-        DVDYsin=circshift(DVDYsin,[-1 0 0]);
-        Umean(end,:,:)=Field.U;
-        Vmean(end,:,:)=Field.V;
-        Ucos(end,:,:)=Field.U*cos(omega*Time(index));
-        Vcos(end,:,:)=Field.V*cos(omega*Time(index));
-        DUDXsin(end,:,:)=Field.DUDX*sin(omega*Time(index));
-        DUDYsin(end,:,:)=Field.DUDY*sin(omega*Time(index));
-        DVDXsin(end,:,:)=Field.DVDX*sin(omega*Time(index));
-        DVDYsin(end,:,:)=Field.DVDY*sin(omega*Time(index));
-        DataOut.Time=Time(index)-(NpTime-1)*dt/2;
-        DataOut.Umean=squeeze(nanmean(Umean,1));
-        DataOut.Vmean=squeeze(nanmean(Vmean,1));
-        DataOut.Ucos=2*squeeze(nanmean(Ucos,1));
-        DataOut.Vcos=2*squeeze(nanmean(Vcos,1));
-        DataOut.DUDXsin=2*squeeze(nanmean(DUDXsin,1));
-        DataOut.DUDYsin=2*squeeze(nanmean(DUDYsin,1));
-        DataOut.DVDXsin=2*squeeze(nanmean(DVDXsin,1));
-        DataOut.DVDYsin=2*squeeze(nanmean(DVDYsin,1));
-        DataOut.Ustokes=(1/omega)*(DataOut.Ucos.*DataOut.DUDXsin+DataOut.Vcos.*DataOut.DUDYsin);
-        DataOut.Vstokes=(1/omega)*(DataOut.Ucos.*DataOut.DVDXsin+DataOut.Vcos.*DataOut.DVDYsin);
+    Vmean=circshift(Vmean,[-1 0 0]); %shift U by ishift along the first index
+    Ucos=circshift(Ucos,[-1 0 0]); %shift U by ishift along the first index
+    Vcos=circshift(Vcos,[-1 0 0]); %shift U by ishift along the first index
+    DUDXcos=circshift(DUDXcos,[-1 0 0]);
+    DUDXsin=circshift(DUDXsin,[-1 0 0]);
+    DUDYsin=circshift(DUDYsin,[-1 0 0]);        
+    DVDXcos=circshift(DVDXcos,[-1 0 0]);
+    DVDXsin=circshift(DVDXsin,[-1 0 0]);
+    DVDYsin=circshift(DVDYsin,[-1 0 0]);       
+    Umean(end,:,:)=Field.U;
+    Vmean(end,:,:)=Field.V;
+    Ucos(end,:,:)=Field.U*cos(omega*Time(index));
+    Vcos(end,:,:)=Field.V*cos(omega*Time(index));
+    DUDXcos(end,:,:)=Field.DUDX*cos(omega*Time(index));
+    DUDXsin(end,:,:)=Field.DUDX*sin(omega*Time(index));
+    DUDYsin(end,:,:)=Field.DUDY*sin(omega*Time(index));% ParamOut=[];%default output
+
+    DVDXcos(end,:,:)=Field.DVDX*cos(omega*Time(index));
+    DVDXsin(end,:,:)=Field.DVDX*sin(omega*Time(index));
+    DVDYsin(end,:,:)=Field.DVDY*sin(omega*Time(index));
+    DataOut.Time=(Time(index)-(NpTime-1)*dt/2)/T;%time inperiods from the beginning of the oscillation (torus at max abscissa)
+    DataOut.Umean=(1/Uscale)*squeeze(nanmean(Umean,1));
+    DataOut.Vmean=(1/Uscale)*squeeze(nanmean(Vmean,1));
+    DataOut.Ucos=2*squeeze(nanmean(Ucos,1));
+    DataOut.Vcos=2*squeeze(nanmean(Vcos,1));
+    DataOut.DUDXcos=2*squeeze(nanmean(DUDXcos,1));
+    DataOut.DUDXsin=2*squeeze(nanmean(DUDXsin,1));
+    DataOut.DUDYsin=2*squeeze(nanmean(DUDYsin,1));
+    DataOut.DVDXcos=2*squeeze(nanmean(DVDXcos,1));
+    DataOut.DVDXsin=2*squeeze(nanmean(DVDXsin,1));
+    DataOut.DVDYsin=2*squeeze(nanmean(DVDYsin,1));
+    DataOut.Ustokes=(1/omega)*(1/Uscale)*(DataOut.Ucos.*DataOut.DUDXsin+DataOut.Vcos.*DataOut.DUDYsin);
+    DataOut.Vstokes=(1/omega)*(1/Uscale)*(DataOut.Ucos.*DataOut.DVDXsin+DataOut.Vcos.*DataOut.DVDYsin);
+
     % writing the result file as netcdf file
-    if index-round(NpTime/2)>=1
-        OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomType{1},index-round(NpTime/2));
-        %case of netcdf input file , determine global attributes
-        errormsg=struct2nc(OutputFile,DataOut); %save result file
-        if isempty(errormsg)
-            disp([OutputFile ' written']);
-        else
-            disp(['error in writting result file: ' errormsg])
-        end
-    end
-end
-%%%%%%%%%%%%%%%% end loop on field indices %%%%%%%%%%%%%%%%
-
+    i1=i1_series{1}(index);
+    OutputFile=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,'.nc',NomTypeOut,i1);
+    errormsg=struct2nc(OutputFile, DataOut);
+    if isempty(errormsg)
+        disp([OutputFile ' written'])
+    else
+        disp(errormsg)
+    end
+end
+    
