diff --git a/multi_adcp_mooring/merge_data_finalfile.m b/multi_adcp_mooring/merge_data_finalfile.m
index 4de84d5e661b77a15b7086e7a6d0f25f67a46518..4646dabd28165611f43d4db585b6dfb74e48c1a3 100644
--- a/multi_adcp_mooring/merge_data_finalfile.m
+++ b/multi_adcp_mooring/merge_data_finalfile.m
@@ -5,8 +5,8 @@
 clear all; close all;
 
 %% Variables
-FileToMerge1     = '/media/irdcampagnes/PIRATA/PIRATA-DATA/MOORING-PIRATA-ALL/0W/merged_data/ADCP_0W0N_2016_2020_1d.nc'; %.nc file to merge with
-FileToMerge2     = '/home/proussel/Documents/OUTILS/ADCP/ADCP_mooring_data_processing/FR31/0-0/ADCP_0W0N_2020_2021_1d.nc'; %.nc file to merge
+FileToMerge1     = '/home/proussel/Documents/OUTILS/ADCP/ADCP_mooring_data_processing/ADCP_0W0N_2016_2020_1d.nc'; %.nc file to merge with
+FileToMerge2     = '/media/irdcampagnes/PIRATA/PIRATA-DATA/MOORING-PIRATA/0-0/ADCP_0W0N_2020_2021_1d.nc'; %.nc file to merge
 step_subsampling = 1; % 1=daily
 plot_data        = 1;
 mooring.name     = '0W0N';
@@ -37,7 +37,7 @@ ncfile2.v     = ncread(FileToMerge2,'VCUR');
 %depth = fliplr(depth);
 max(vertcat(ncfile1.depth,ncfile2.depth))
 min(vertcat(ncfile1.depth,ncfile2.depth))
-depth = 0:5:300;
+depth = 0:5:320;
 
 %% Create time matrix
 time  = vertcat(ncfile1.time,ncfile2.time);
@@ -59,6 +59,24 @@ v     = vertcat(v1,v2);
 
 time  = time*ones(1,length(depth));
 
+% create a continuous series of daily data, ranging from min(d) to max(d)
+final_time = ceil(min(min(time))):0.25:floor(max(max(time)));
+ADCP_final.u = NaN(length(final_time),length(depth));
+ADCP_final.v = NaN(length(final_time),length(depth));
+
+for i_time = 1:length(final_time)
+    for j_time = 1:length(time)
+        if final_time(i_time) == time(j_time,1)
+            ADCP_final.u(i_time,:)=u(j_time,:);
+            ADCP_final.v(i_time,:)=v(j_time,:);
+        end
+    end
+end
+
+time = final_time;
+time  = time'*ones(1,length(depth));
+u    = ADCP_final.u;
+v    = ADCP_final.v;
 
 %% Plot data
 if plot_data
@@ -81,7 +99,7 @@ if plot_data
     ylabel('Depth (m)');
     ylim([0,max(max(depth))]);
     gregtick;
-    title({[mooring.name, ' - ' num2str(date1) ' to ' num2str(date2) ' - ZONAL VELOCITY - RDI ',num2str(freq),' kHz (filtered from tide)']});
+    title({[mooring.name, ' - ' num2str(date1) ' to ' num2str(date2) ' - ZONAL VELOCITY - RDI ',num2str(freq),' (filtered from tide)']});
     
     %v
     subplot(2,1,2);
diff --git a/multi_adcp_mooring/template_combine_adcp_up_and_down.m b/multi_adcp_mooring/template_combine_adcp_up_and_down.m
index 67588a105d61d17f4afd10761c40a4bad0f25d9a..ffebcdcaa89ec71178f878c3128bee39e46c0c0d 100644
--- a/multi_adcp_mooring/template_combine_adcp_up_and_down.m
+++ b/multi_adcp_mooring/template_combine_adcp_up_and_down.m
@@ -16,17 +16,17 @@ clear all;close all;
 addpath('.\moored_adcp_proc');
 
 % Location of ADCP up and down data
-fpath = '/media/irdcampagnes/PIRATA/PIRATA_ADCP-MOORINGS/23W/2004-2005';
+fpath = '/media/irdcampagnes/PIRATA/PIRATA-FR22/data-adjusted/MOUILLAGE_ADCP';
 
 % Directory for outputs
-fpath_output = '/media/irdcampagnes/PIRATA/PIRATA_ADCP-MOORINGS/23W/2004-2005';
-
+fpath_output = '/media/irdcampagnes/PIRATA/PIRATA-FR22/data-adjusted/MOUILLAGE_ADCP/';
+d_fillvalue = -9999;
 % Contour levels for u anv v fields
 niv_u = (-1.5:0.1:1.5);
 niv_v = (-0.5:0.1:0.5);
 
 %% combine up and down
-load([fpath, '/23W0N_3173_instr_01_int_filt_sub.mat']);
+load([fpath, '/up/10W0N_508_instr_01_int_filt_sub.mat']);
 adcp_up=adcp;
 up_u=data.uintfilt;
 up_v=data.vintfilt;
@@ -35,7 +35,7 @@ up_time=data.inttim;
 %npts_up= data.npts_up;
 freq_up=adcp_up.config.sysconfig.frequency;
 
-load([fpath, '/23W0N_3173_instr_02_int_filt_sub.mat']);
+load([fpath, '/down/10W0N_509_instr_01_int_filt_sub.mat']);
 adcp_down=adcp;
 down_u=data.uintfilt;
 down_v=data.vintfilt;
@@ -92,7 +92,7 @@ data.uintfilt = uintfilt;
 data.vintfilt = vintfilt;
 data.inttim   = inttim;
 data.Z        = Z;
-mooring.name  = '23W0N';
+mooring.name  = '10W0N';
 save([fpath_output, mooring.name '_instr_int_filt_sub_up_down.mat'],'mooring','data');
 
 %% Figure
@@ -113,7 +113,7 @@ ylabel('Depth (m)');
 ylim([0,round(max(Z))]);
 %change figure label in HH:MM
 gregtick;
-title({[mooring.name, ' - ZONAL VELOCITY - RDI 150 kHz and 75 kHz (filtered from tide)']});
+title({[mooring.name, ' - ZONAL VELOCITY - RDI 2 x 300 kHz (filtered from tide)']});
 
 
 %v
@@ -128,7 +128,7 @@ ylabel('Depth (m)');
 ylim([0,round(max(Z))]);
 %change figure label in HH:MM
 gregtick;
-title({[mooring.name, ' - ZONAL VELOCITY - RDI 150 kHz and 75 kHz (filtered from tide)']});
+title({[mooring.name, ' - ZONAL VELOCITY - RDI 2 x 300 kHz (filtered from tide)']});
 
 
 graph_name = [fpath_output, mooring.name '_up_down_U_V_int_filt_sub'];
@@ -140,32 +140,37 @@ print(hf,graph_name,'-dpdf','-r300');
 %%  Write netcdf file
 disp('****')
 disp('Creating .nc file')
-[yr_start , ~, ~] = gregorian(inttim(1));
-[yr_end,  ~, ~]   = gregorian(inttim(length(inttim)));
-
-ncid     = netcdf.create([fpath_output,'ADCP_',mooring.name,'_',num2str(yr_start),'_',num2str(yr_end),'_1d.nc'],'NC_WRITE');
-
-%create dimension
-dimidt   = netcdf.defDim(ncid,'time',length(inttim));
-dimidz   = netcdf.defDim(ncid,'depth',length(Z));
-%Define IDs for the dimension variables (pressure,time,latitude,...)
-time_ID  = netcdf.defVar(ncid,'time','double',dimidt);
-depth_ID = netcdf.defVar(ncid,'depth','double',dimidz);
-%Define the main variable ()
-u_ID     = netcdf.defVar(ncid,'u','double',[dimidt dimidz]);
-v_ID     = netcdf.defVar(ncid,'v','double',[dimidt dimidz]);
-
-%We are done defining the NetCdf
-netcdf.endDef(ncid);
-%Then store the dimension variables in
-netcdf.putVar(ncid,time_ID,inttim);
-netcdf.putVar(ncid,depth_ID,Z);
-%Then store my main variable
-netcdf.putVar(ncid,u_ID,uintfilt');
-netcdf.putVar(ncid,v_ID,vintfilt');
-
-%We're done, close the netcdf
-netcdf.close(ncid);
+
+% Input parameters for NETCDF Global Attributes
+tc_globAttFilename      = fullfile('tools/input_GlobalAttrParameters.xls'); % JLL 2020/12 Il serait judicieux de remonter cette valeur en début du script template_get_adcp_data.m
+
+%% Prepare informations and variables required to create NETCDF file %% 
+[yr_start , ~, ~]       = gregorian(data.inttim(1));
+[yr_end,  ~, ~]         = gregorian(data.inttim(length(data.inttim)));
+
+% Read inputs metadata required for NETCDF Global Attributes
+[~,~,cell_ncAttributes] = xlsread(tc_globAttFilename);
+
+% Complete output path and filename 
+tc_ncFilenam_out        = fullfile(fpath_output,['ADCP_',mooring.name,'_',num2str(yr_start),'_',num2str(yr_end),'_1d.nc']);
+
+% Assign a "4D-size" (TIME,DEPTH,LATITUDE,LONGITUDE) to the ADCP current variables : UINTFILT, VINTFILT
+td_uADCP                = ones(numel(data.inttim),numel(data.Z),numel(data.lat),numel(data.lon)) * d_fillvalue;
+td_uADCP(:,:,1,1)       = data.uintfilt';
+td_vADCP                = ones(numel(data.inttim),numel(data.Z),numel(data.lat),numel(data.lon)) * d_fillvalue;
+td_vADCP(:,:,1,1)       = data.vintfilt';
+
+% Flip for convention
+data.Z                  = fliplr(data.Z);
+td_uADCP                = fliplr(td_uADCP);
+td_vADCP                = fliplr(td_vADCP);
+
+% Group general ADCP mooring informations and ADCP data to be written in NETCDF file format
+struct_dataADCP         = struct('mooringName', mooring.name, 'mooringLat', mooring.lat,...
+    'mooringLon', mooring.lon, 'time', data.inttim, 'depth', data.Z,...
+    'u', td_uADCP, 'v', td_vADCP);
+
+%%  Write netcdf file  %%        
+f_w_ADCP_ncOS(tc_ncFilenam_out,cell_ncAttributes,struct_dataADCP,d_fillvalue);
 disp('****')
-% -------------------------------------------------------------------------------------------
 
diff --git a/qualify/qualify_data.m b/qualify/qualify_data.m
index 6ca5fb846c427c188fe304e2f08cb2270871e806..2e6b23736661fda5d8be5b20e02945c2c44e4ab3 100644
--- a/qualify/qualify_data.m
+++ b/qualify/qualify_data.m
@@ -20,11 +20,11 @@ DVLfile   = '/media/irdcampagnes/PIRATA/PIRATA-FR31/data-final/SADCP/DVL600/ncc/
 LADCPfil1 = '/media/irdcampagnes/PIRATA/PIRATA-FR31/data-adjusted/LADCP/profiles/FR31_006.mat';
 LADCPfil2 = '/media/irdcampagnes/PIRATA/PIRATA-FR31/data-adjusted/LADCP/profiles/FR31_031.mat';
 % %
-% OS38file  = '/media/irdcampagnes/PIRATA/PIRATA-FR30/data-final/SADCP/OS38/ncc/FR30-OS38_osite_mat20_fhv1_corr_final.nc';
-% OS150file = '/media/irdcampagnes/PIRATA/PIRATA-FR30/data-final/SADCP/OS150/ncc/FR30-OS150_osite_mat20_fhv1_corr_final.nc';
-% DVLfile   = '/media/irdcampagnes/PIRATA/PIRATA-FR30/data-final/SADCP/LOCH/ncc/FR30-DVL600_osite_mat20_fhv1_corr_final.nc';
-% LADCPfil1 = '/media/irdcampagnes/PIRATA/PIRATA-FR30/data-adjusted/LADCP/profiles/FR30_009.mat';
-% LADCPfil2 = '/media/irdcampagnes/PIRATA/PIRATA-FR30/data-adjusted/LADCP/profiles/FR30_010.mat';
+OS38file  = '/media/irdcampagnes/PIRATA/PIRATA-FR30/data-final/SADCP/OS38/ncc/FR30-OS38_osite_mat20_fhv1_corr_final.nc';
+OS150file = '/media/irdcampagnes/PIRATA/PIRATA-FR30/data-final/SADCP/OS150/ncc/FR30-OS150_osite_mat20_fhv1_corr_final.nc';
+DVLfile   = '/media/irdcampagnes/PIRATA/PIRATA-FR30/data-final/SADCP/LOCH/ncc/FR30-DVL600_osite_mat20_fhv1_corr_final.nc';
+LADCPfil1 = '/media/irdcampagnes/PIRATA/PIRATA-FR30/data-adjusted/LADCP/profiles/FR30_009.mat';
+LADCPfil2 = '/media/irdcampagnes/PIRATA/PIRATA-FR30/data-adjusted/LADCP/profiles/FR30_010.mat';
 % % 
 % OS38file  = '/media/irdcampagnes/PIRATA/PIRATA-FR29/data-final/SADCP/OS38/data/LTA/PIRATA-FR29-OS38_LTA_osite_fhv1_final.nc';
 % OS150file = '/media/irdcampagnes/PIRATA/PIRATA-FR29/data-final/SADCP/OS150/data/LTA/PIRATA-FR29-OS150_LTA_osite_fhv1_final.nc';
@@ -272,6 +272,7 @@ ylim([-300 0])
 date_dvl  = (h_dvl(plt_dvl)-h_mooring(plt_m))*(24*60);
 date_os   = (h_os(plt_os)-h_mooring(plt_m))*(24*60);
 date_os38 = (h_os38(plt_os38)-h_mooring(plt_m))*(24*60);
+
 if date_os<0
         legend(['OS150 / ' num2str(round(date_os)) 'min'], ['OS38 / ' num2str(round(date_os38)) 'min'], ['DVL / ' num2str(round(date_dvl)) 'min'], ['ADCP Mooring / ' datestr(h_mooring(plt_m))], 'ADCP filtered','location', 'southeast')  
 else
diff --git a/specific/template_get_adcp_data_10w.m b/specific/template_get_adcp_data_10w.m
index ae5109c73550d9cc3e25a7a8ef8d77adccd94db9..9ec6cd7494326c74a210030d109901914b129766 100644
--- a/specific/template_get_adcp_data_10w.m
+++ b/specific/template_get_adcp_data_10w.m
@@ -39,8 +39,16 @@ instr            = 1;
 %% Convert variables
 latDegInd               = strfind(mooring.lat,'°');
 lonDegInd               = strfind(mooring.lon,'°');
-mooring.lat             = str2double(mooring.lat(1:latDegInd-1))+str2double(mooring.lat(latDegInd+1:end-1))/60;
-mooring.lon             = str2double(mooring.lon(1:lonDegInd-1))+str2double(mooring.lon(lonDegInd+1:end-1))/60;
+if strfind(mooring.lon,'-')
+    mooring.lat             = str2double(mooring.lat(1:latDegInd-1))-str2double(mooring.lat(latDegInd+1:end-1))/60;
+else
+    mooring.lat             = str2double(mooring.lat(1:latDegInd-1))+str2double(mooring.lat(latDegInd+1:end-1))/60;
+end
+if strfind(mooring.lon,'-')
+    mooring.lon             = str2double(mooring.lon(1:lonDegInd-1))-str2double(mooring.lon(lonDegInd+1:end-1))/60;
+else
+    mooring.lon             = str2double(mooring.lon(1:lonDegInd-1))+str2double(mooring.lon(lonDegInd+1:end-1))/60;
+end
 clock_drift             = clock_drift/3600;  % convert into hrs
 
 %% Read rawfile
@@ -54,6 +62,7 @@ raw_file                = [fpath_output, mooring.name '_' num2str(adcp.sn) '_ins
 %     raw                 = read_os3(rawfile,'all');
 %     save(raw_file,'raw','-v7.3');
 % end
+load('10W0N_508_instr_01.mat')
 load('FR22-UP-508.mat')
 
 %% Correct clock drift
@@ -113,7 +122,7 @@ ea                  = squeeze(mean(test(:,4,first:last),2));
 %pg                  = squeeze(raw.pg(:,4,first:last));
 %time                = raw.juliandate(first:last);
 time = julian(SerYear(first:last)+2000,SerMon(first:last),SerDay(first:last),SerHour(first:last));
-time=time(1)+datenum(0,0,0,1,0,0).*[0:length(depth)-1]';
+%time=time(1)+datenum(0,0,0,1,0,0).*[0:length(depth)-1]';
 ang                 = [raw.pitch(first:last) raw.roll(first:last) raw.heading(first:last)];
 soundspeed          = raw.soundspeed(first:last);
 temp                = raw.temperature(first:last);
@@ -133,9 +142,9 @@ EA0                 = round(mean(ea(nbin,:)));
 
 %% Calculate Magnetic deviation values
 [a,~]                   = gregorian(raw.juliandate(1));
-magnetic_deviation_ini  = -magdev(mooring.lat,mooring.lon,0,a+(time(1)-julian(a,1,1,0,0,0))/365.25);
+magnetic_deviation_ini  = magdev(mooring.lat,mooring.lon,0,a+(raw.juliandate(1)-julian(a,1,1,0,0,0))/365.25);
 [a,~]                   = gregorian(raw.juliandate(end));
-magnetic_deviation_end  = -magdev(mooring.lat,mooring.lon,0,a+(time(end)-julian(a,1,1,0,0,0))/365.25);
+magnetic_deviation_end  = magdev(mooring.lat,mooring.lon,0,a+(raw.juliandate(end)-julian(a,1,1,0,0,0))/365.25);
 rot                     = (magnetic_deviation_ini+magnetic_deviation_end)/2;
 mag_dev                 = linspace(magnetic_deviation_ini, magnetic_deviation_end, length(time));
 %mag_dev                 = mag_dev(first:last);
diff --git a/specific/template_get_adcp_data_10w_down.m b/specific/template_get_adcp_data_10w_down.m
index ef18be4fb2a3d2f15fed5ea872f0c202789ab4c8..6439f6403adb5156d043798ef21f07ccc118dfa6 100644
--- a/specific/template_get_adcp_data_10w_down.m
+++ b/specific/template_get_adcp_data_10w_down.m
@@ -39,8 +39,16 @@ instr            = 1;
 %% Convert variables
 latDegInd               = strfind(mooring.lat,'°');
 lonDegInd               = strfind(mooring.lon,'°');
-mooring.lat             = str2double(mooring.lat(1:latDegInd-1))+str2double(mooring.lat(latDegInd+1:end-1))/60;
-mooring.lon             = str2double(mooring.lon(1:lonDegInd-1))+str2double(mooring.lon(lonDegInd+1:end-1))/60;
+if strfind(mooring.lon,'-')
+    mooring.lat             = str2double(mooring.lat(1:latDegInd-1))-str2double(mooring.lat(latDegInd+1:end-1))/60;
+else
+    mooring.lat             = str2double(mooring.lat(1:latDegInd-1))+str2double(mooring.lat(latDegInd+1:end-1))/60;
+end
+if strfind(mooring.lon,'-')
+    mooring.lon             = str2double(mooring.lon(1:lonDegInd-1))-str2double(mooring.lon(lonDegInd+1:end-1))/60;
+else
+    mooring.lon             = str2double(mooring.lon(1:lonDegInd-1))+str2double(mooring.lon(lonDegInd+1:end-1))/60;
+end
 clock_drift             = clock_drift/3600;  % convert into hrs
 
 %% Read rawfile
@@ -143,9 +151,9 @@ EA0                 = round(mean(ea(nbin,:)));
 
 %% Calculate Magnetic deviation values
 [a,~]                   = gregorian(raw.juliandate(1));
-magnetic_deviation_ini  = -magdev(mooring.lat,mooring.lon,0,a+(time(1)-julian(a,1,1,0,0,0))/365.25);
+magnetic_deviation_ini  = magdev(mooring.lat,mooring.lon,0,a+(raw.juliandate(1)-julian(a,1,1,0,0,0))/365.25);
 [a,~]                   = gregorian(raw.juliandate(end));
-magnetic_deviation_end  = -magdev(mooring.lat,mooring.lon,0,a+(time(end)-julian(a,1,1,0,0,0))/365.25);
+magnetic_deviation_end  = magdev(mooring.lat,mooring.lon,0,a+(raw.juliandate(end)-julian(a,1,1,0,0,0))/365.25);
 rot                     = (magnetic_deviation_ini+magnetic_deviation_end)/2;
 mag_dev                 = linspace(magnetic_deviation_ini, magnetic_deviation_end, length(time));
 %mag_dev                 = mag_dev(first:last);
diff --git a/template_get_adcp_data.m b/template_get_adcp_data.m
index afe9da08c9e35e739e3d0156acb8ada520d260c5..0af674adcf67e98a84b4e64327dc8da99023e190 100644
--- a/template_get_adcp_data.m
+++ b/template_get_adcp_data.m
@@ -23,16 +23,16 @@ fpath_output     = './FR31/0-0/';
 cruise.name      = 'PIRATA';                                                              % cruise name
 mooring.name     = '0W0N';                                                                % '0N10W'
 mooring.lat      = '00°00.176';                                                           % latitude [°']
-mooring.lon      = '-00°03.920';                                                           % longitude [°']
+mooring.lon      = '-00°03.920';                                                          % longitude [°']
 clock_drift      = 146;                                                                   % [seconds]
 
 % ADCP info
-adcp.sn          = 22545;                                                                 % ADCP serial number
+adcp.sn          = 22546;                                                                 % ADCP serial number
 adcp.type        = '150 khz Quartermaster';                                               % Type : Quartermaster, longranger
 adcp.direction   = 'up';                                                                  % upward-looking 'up', downward-looking 'dn'
 adcp.instr_depth = 300;                                                                   % nominal instrument depth
 instr            = 1;                                                                     % this is just for name convention and sorting of all mooring instruments
-offset_pres_sens = 1;                                                                    % offset in m between pressure sensore and ADCP
+offset_pres_sens = 1;                                                                     % offset in m between pressure sensore and ADCP
 
 % NCFILE info
 d_fillvalue     = -9999;