function [missioninfo]=make_directory_files_structure(missioninfo,datasource,gldatatype)
% [missioninfo]=make_directory_files_structure(missioninfo,datasource,gldatatype)
% create the directory structure and the file names for the 3 processing
% levels (0, 1 and 2) according to the kind of data used and the data source 
% 
% created by L. Houpert (houpertloic@gmail.com), 26/05/2016, as part of the
% oceano_data_toolbox project: https://bitbucket.org/Lhoupert/oceano_data_toolbox


%==========================================================================
% Definition of the directory structure and file names

procdatadir = ['~/Data/Dropbox/Work/Postdoc_OSNAP/seaglider/work/read_data/from_toolbox_loic/matlab_data/' missioninfo.observatory '/'];
plotdir     = ['~/Data/Dropbox/Work/Postdoc_OSNAP/seaglider/work/read_data/from_toolbox_loic/plots/' missioninfo.observatory '/']; 

%--------------------------------------------------------------------------
% Def parameter step0 processing: conversion raw data

if datasource ==1208 | datasource ==1209 %for netcdf files but different basestationversion

    missioninfo.rawdata.TSlevel   = gldatatype.TSlevel;% 'processed' or 'raw'
    missioninfo.rawdata.flightmod = gldatatype.flightmod;% 'HDM' or 'GSM'   
    missioninfo.step0.proclevel = 'step0_raw_data';       
    if datasource == 1208
    	missioninfo.rawdata.dataDir = [ missioninfo.rawdata.dataDir 'reprocessed_dive_files' filesep 'nc']; 
    	missioninfo.rawdata.orig = 'netcdf_processed_by_basestation_208';
    elseif datasource == 1209 % base station 2.09
    	missioninfo.rawdata.dataDir = [ missioninfo.rawdata.dataDir 'reprocessed_dive_files_base-2.09' filesep 'nc'];
    	missioninfo.rawdata.orig = 'netcdf_processed_by_basestation_209';
    end
    missioninfo.step0.procdataDir = [ procdatadir  missioninfo.step0.proclevel '/'  ...
            	missioninfo.rawdata.orig '/TS' missioninfo.rawdata.TSlevel '_' missioninfo.rawdata.flightmod ];      
    missioninfo.step0.matfilename = [ missioninfo.glname '_' missioninfo.glmission '_' missioninfo.step0.proclevel  ];    
    missioninfo.step0.plotdir = [ plotdir  missioninfo.rawdata.orig ...
        '/TS' missioninfo.rawdata.TSlevel '_' missioninfo.rawdata.flightmod ]; 
    missioninfo.step0.plotname = [ missioninfo.glname '_' missioninfo.glmission '_' missioninfo.step0.proclevel  ];             
elseif datasource == 2
    missioninfo.rawdata.orig = 'eng_processed_by_UEA_toolbox';
    missioninfo.rawdata.TSlevel   = 'processed';% 'processed' or 'raw'
    missioninfo.rawdata.flightmod = 'HDM';% 'HDM' or 'GSM'       
    missioninfo.rawdata.flight_regression_passes = gldatatype.flight_regression_passes; 
    missioninfo.step0.proclevel = 'step0_raw_data';    
    if missioninfo.rawdata.flight_regression_passes == 0
         subdirname = 'noopti';
    else
         subdirname = ['opti_' num2str(missioninfo.rawdata.flight_regression_passes) ...
                                    'regress_passes'];
    end 
    missioninfo.step0.procdataDir = [procdatadir missioninfo.step0.proclevel '/' ...
                  missioninfo.rawdata.orig '/' subdirname ];    
    missioninfo.step0.matfilename = [ missioninfo.glname '_' missioninfo.glmission '_' ...
                  missioninfo.step0.proclevel '_' subdirname ];  
    missioninfo.step0.plotdir = [plotdir  missioninfo.rawdata.orig '/' subdirname ];         
    missioninfo.step0.plotname = [ missioninfo.glname '_' missioninfo.glmission '_' ...
                  missioninfo.step0.proclevel '_' subdirname ];   
              
elseif datasource == 3  % EGO NETCDF format    
    missioninfo.rawdata.TSlevel   = gldatatype.TSlevel; 
    missioninfo.rawdata.flightmod = gldatatype.flightmod; 
    missioninfo.step0.proclevel = 'step0_raw_data';       
    missioninfo.rawdata.dataDir = [ missioninfo.rawdata.dataDir]; 
    missioninfo.rawdata.orig = 'EGO_nc_RT';
    missioninfo.step0.procdataDir = [ procdatadir  missioninfo.step0.proclevel '/'  ...
            	missioninfo.rawdata.orig '/TS' missioninfo.rawdata.TSlevel '_' missioninfo.rawdata.flightmod ];      
    missioninfo.step0.matfilename = [ missioninfo.glname '_' missioninfo.glmission '_' missioninfo.step0.proclevel  ];    
    missioninfo.step0.plotdir = [ plotdir  missioninfo.rawdata.orig ...
        '/TS' missioninfo.rawdata.TSlevel '_' missioninfo.rawdata.flightmod ]; 
    missioninfo.step0.plotname = [ missioninfo.glname '_' missioninfo.glmission '_' missioninfo.step0.proclevel  ];               
    
end

%--------------------------------------------------------------------------
% Def parameter step1 processing
missioninfo.step1.proclevel = 'step1';   
if datasource == 1208  | datasource ==1209 | datasource == 3
    missioninfo.step1.procdataDir = [ procdatadir  missioninfo.step1.proclevel '/'  ...
                 missioninfo.rawdata.orig '/TS' missioninfo.rawdata.TSlevel '_' missioninfo.rawdata.flightmod ];    
    missioninfo.step1.matfilename = [ missioninfo.glname '_' missioninfo.glmission '_' missioninfo.step1.proclevel '_pfsdata' ];    
missioninfo.step1.plotdir = [ plotdir  missioninfo.rawdata.orig '/TS' missioninfo.rawdata.TSlevel '_' missioninfo.rawdata.flightmod ]; 
    missioninfo.step1.plotname = [ missioninfo.glname '_' missioninfo.glmission '_' missioninfo.step1.proclevel  ];             
elseif datasource == 2
    missioninfo.step1.procdataDir = [procdatadir  missioninfo.step1.proclevel '/' ...
                  missioninfo.rawdata.orig '/' subdirname ];    
    missioninfo.step1.matfilename = [ missioninfo.glname '_' missioninfo.glmission '_' ...
                  missioninfo.step1.proclevel '_' subdirname '_pfdata'];      
    missioninfo.step1.plotdir = [plotdir missioninfo.rawdata.orig '/' subdirname ];         
    missioninfo.step1.plotname = [ missioninfo.glname '_' missioninfo.glmission '_' ...
                  missioninfo.step1.proclevel '_' subdirname ];                    
end

%--------------------------------------------------------------------------
% Def parameter step2 processing
missioninfo.step2.proclevel = 'step2';   
if datasource == 1208  | datasource ==1209 | datasource == 3
    missioninfo.step2.procdataDir = [ procdatadir  missioninfo.step2.proclevel '/'  ...
                 missioninfo.rawdata.orig '/TS' missioninfo.rawdata.TSlevel '_' missioninfo.rawdata.flightmod ];    
    missioninfo.step2.matfilename = [ missioninfo.glname '_' missioninfo.glmission '_' missioninfo.step2.proclevel '_pfsdata' ];    
missioninfo.step2.plotdir = [ plotdir  missioninfo.rawdata.orig '/TS' missioninfo.rawdata.TSlevel '_' missioninfo.rawdata.flightmod ]; 
    missioninfo.step2.plotname = [ missioninfo.glname '_' missioninfo.glmission '_' missioninfo.step2.proclevel  ];             
elseif datasource == 2
    missioninfo.step2.procdataDir = [procdatadir  missioninfo.step2.proclevel '/' ...
                  missioninfo.rawdata.orig '/' subdirname ];    
    missioninfo.step2.matfilename = [ missioninfo.glname '_' missioninfo.glmission '_' ...
                  missioninfo.step1.proclevel '_' subdirname '_pfdata'];      
    missioninfo.step2.plotdir = [plotdir missioninfo.rawdata.orig '/' subdirname ];         
    missioninfo.step2.plotname = [ missioninfo.glname '_' missioninfo.glmission '_' ...
                  missioninfo.step2.proclevel '_' subdirname ];                    
end


end
