diff --git a/processing/format.R b/processing/format.R
index 1068f9857d513ab6622dba3f5fd08c4028455845..ec84328e6788769167500aa3b3273098fc3984fc 100644
--- a/processing/format.R
+++ b/processing/format.R
@@ -145,7 +145,7 @@ prepare_date = function(df_XEx, df_Xlist) {
     # }
     
     # df_XEx$values = dateExJul
-        
+
     dateStart_group = summarise(group_by(df_Xlist$data, group),
                                 Date = min(Date))
     # filter(group_by(df_Xlist$data, group), Date == min(Date))
@@ -166,8 +166,27 @@ prepare_date = function(df_XEx, df_Xlist) {
         OkdateStart_group = dateStart_group$group == group
         Shift = dateStart_group$Date_julian[OkdateStart_group]
         year = dateStart_group$Year[OkdateStart_group]
-        OkXEx = df_XEx$group1 == group & df_XEx$datetime == year
-        df_XEx$values[OkXEx] = df_XEx$values[OkXEx] + Shift        
+        OkXEx_code_year = df_XEx$group1 == group & df_XEx$datetime == year
+        df_XEx$values[OkXEx_code_year] =
+            df_XEx$values[OkXEx_code_year] + Shift
+
+        OkXEx_code = df_XEx$group1 == group        
+        XEx_code = df_XEx$values[OkXEx_code]
+        
+        # dXExUp = abs(XEx_code - c(XEx_code[2:length(XEx_code)],
+                                  # XEx_code[length(XEx_code)]))
+        # dXExDown = abs(XEx_code - c(XEx_code[1],
+                                    # XEx_code[1:(length(XEx_code) - 1)]))
+        # dExMean =  apply(rbind(dXExUp, dXExDown), 2, mean, na.rm=TRUE)
+
+        meanXEx_code = mean(XEx_code, na.rm=TRUE)
+        dXEx_code = abs(XEx_code - meanXEx_code)
+        stdXEx_code = sd(XEx_code, na.rm=TRUE)
+        print(stdXEx_code*2)
+        print(dXEx_code)
+        XEx_code[dXEx_code >= 365/3] = XEx_code[dXEx_code >= 365/3] + 365
+        # df_XEx$values[OkXEx_code] = XEx_code
+
     }
 
     return (df_XEx)