Commit e482c114 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

calculate_baselines_environment

parent ed5f3532
......@@ -69,75 +69,201 @@
% - time_interval 'n' (default) specified by startdate and enddate
% 'r' means real time from magobs/magdata
%
% read in all DI-measurements for this year
%number_DI = 5; % read in the last x measurements in this year
%number_DI = 0; % use date range from below
%year = 2018;
%start_mmdd = '0419';
%end___mmdd = '0419';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function calculate_baselines_environment(varargin)
opsys = computer;
figure
station = 'SMA0g'; % c or d or g or s or l for datalogger
%station = 'WNG1g'; % c or d or g or s or l for datalogger
%station = 'NGK0g'; % c or d or g or s or l for datalogger
%station = 'TDC1d'; % c or d or g or s or l for datalogger
%station = 'VNA1s'; % c or d or g or s or l for datalogger
% station = 'BFO1s'; % c or d or g or s or l for datalogger
%station = 'SHE0g'; % c or d or g or s or l for datalogger
%station = 'TTB0g'; % c or d or g or s or l for datalogger
%station = 'TTB1l'; % c or d or g or s or l for datalogger
%station = 'VSS0g'; % c or d or g or s or l for datalogger
tempsource = 'c'; % c for cdf
temp_correct = 'y'; % apply temp-correction function to variations 'y'
apply_time_lag = 'y'; %reads from raw1(K61)
find_time_error = 'n';
timeshift_array = [-300:1:300]';
number_DI = 1000; % read in all DI-measurements for this year
number_DI = 5; % read in the last x measurements in this year
number_DI = 0; % use date range from below
year = 2018;
start_mmdd = '0419';
end___mmdd = '0419';
ppmsource = 'c'; % 's' for spreadsheet, 'c' for cdf, here always 'c'
if ~strcmp(opsys(1:2), 'PC')
error('operating system not supported');
end
% =========================================================================
% Parse input arguments
%
% Get parameters from input file and command-line arguments:
%
% First, read from parameter file. The default parameter file is
% 'parameters_win.txt', and is overwritten by command-line passed
% parameter file.
% Then overwrite with command-line arguments. If a parameter is not
% specified in parameter file, it is required at command-line.
% =========================================================================
% -------------------------------------------------------------------------
% Specify required arguments
% -------------------------------------------------------------------------
% Station name
arg_specs.station.required=1;
arg_specs.station.type='char';
arg_specs.station.dim1=1;
arg_specs.station.dim2=5;
% Number of DI measurements to be read for given year
arg_specs.number_DI.required=1;
arg_specs.number_DI.type = 'numeric';
arg_specs.number_DI.dim1 = 1;
arg_specs.number_DI.dim2 = 1;
arg_specs.startdate.required=1;
arg_specs.startdate.type='char';
arg_specs.startdate.dim1=1;
arg_specs.startdate.dim2=10;
% -------------------------------------------------------------------------
% Try to read default values from parameter file
% -------------------------------------------------------------------------
% First try to get parameter file
arg_specs.parfile.default='parameters_win.txt';
arg_specs.parfile.type='char';
arg_specs.parfile.dim1=1;
% Parse arguments for parameter file
[arg_parsed state]=parse_arg(arg_specs,varargin);
% Check if parameter file exists
if ~exist(arg_parsed.parfile,'file')
warning(['Specified parameter file ' arg_parsed.parfile ...
'does not exist. I will try to get all parameters from command-line.']);
% Set default values from parameter file
else
[arg_specs.path.default, ...
arg_specs.station.default, ...
arg_specs.startdate.default]=...
read_parameters(arg_parsed.parfile,'PATH','STATION','DATE',...
{0,0,0});
end
% -------------------------------------------------------------------------
% Specify optional arguments
% -------------------------------------------------------------------------
% Source for temperature readings
% 'c' for cdf
arg_specs.tempsource.default='c';
arg_specs.tempsource.valid={'c'};
% Apply temp-correction function to variations 'y'
arg_specs.temp_correct.default='y';
arg_specs.temp_correct.valid={'y','n'};
% Reads from raw1(K61)
arg_specs.apply_time_lag.default='y';
arg_specs.apply_time_lag.valid={'y'};
%
arg_specs.find_time_error.default='n';
%
arg_specs.timeshift_array.default=[-300:1:300]';
arg_specs.stopdate.default=arg_specs.startdate.default;
arg_specs.stopdate.type='char';
arg_specs.stopdate.dim1=1;
arg_specs.stopdate.dim2=10;
% -------------------------------------------------------------------------
% Parse arguments
% -------------------------------------------------------------------------
[arg_parsed, state]=parse_arg(arg_specs,varargin);
% -------------------------------------------------------------------------
% Error treatment
% -------------------------------------------------------------------------
% if ~isempty(arg_parsed.number_DI) && isempty(arg_parsed.year)
% error('Year must be specified if number_DI is given');
% end
%
% if xor(isempty(arg_parsed.stopdate),isempty(arg_parsed.startdate))
% error('Always specify startdate and stopdate');
% end
%
% if ~isempty(arg_parsed.year) && ~isempty(arg_parsed.startdate)
% error('Start/Stopdate cannot be specified together with year');
% end
if (state.err == 1) % warning occurred, but no error
warning(state.wngmsg);
elseif (state.err == 2) % error occured, stop execution
error(state.errmsg);
end
% -------------------------------------------------------------------------
% Assign input arguments
% -------------------------------------------------------------------------
% This was removed as option here !
%
% 's' for spreadsheet, 'c' for cdf, here always 'c'
% If 's' is to be used, then change this in calculate_baselines.m
ppmsource = 'c';
path1 = arg_parsed.path;
station = arg_parsed.station;
tempsource = arg_parsed.tempsource;
temp_correct = arg_parsed.temp_correct;
apply_time_lag = arg_parsed.apply_time_lag;
find_time_error = arg_parsed.find_time_error;
timeshift_array = arg_parsed.timeshift_array;
return_array = []; %returnes baseliens etc from function
opsys = computer;
% if strcmp(opsys(1:2), 'GL') == 1 %removed because XLS-files can only be
% processed on Windows systems
% path1 = '/nfs/magobs/';
% bs = '/'; % slash
% else
if strcmp(opsys(1:2), 'PC') == 1
path1 = 'Y:';
bs = '\'; % backslash
else
display('operating system not recognised');
number_DI = arg_parsed.number_DI;
start_mmdd = arg_parsed.startdate([6:7 9:10]);
end___mmdd = arg_parsed.stopdate([6:7 9:10]);
year = str2double(arg_parsed.stopdate(1:4));
if ~strcmp(arg_parsed.stopdate(1:4),arg_parsed.startdate(1:4))
warning(['Startyear and stopyear differ, but only one year is ' ...
'allowed! \n Startyear is used: ' num2str(year)]);
end
% =========================================================================
% GENERATE PATHS
% =========================================================================
path_DI = [path1 bs 'BPDATA' bs 'DI_' station(1:3) ...
num2str(year, '%4.4d') bs];
if strcmp(station(1:3), 'MSN')
path_DI = [path1 bs 'BPDATA' bs 'DI_' 'NGK' ...
num2str(year, '%4.4d') bs];
end %MSN
return_array = []; %returnes baseliens etc from function
path_cdf = [path1 bs 'laptop_data' bs station(1:4) bs 'cdf' bs];
bs=backslash;
% Is this still needed?
% path_DI = [path1 bs 'BPDATA' bs 'DI_' station(1:3) ...
% num2str(year, '%4.4d') bs];
% if strcmp(station(1:3), 'MSN')
% path_DI = [path1 bs 'BPDATA' bs 'DI_' 'NGK' ...
% num2str(year, '%4.4d') bs];
% end %MSN
%
% path_cdf = [path1 bs 'laptop_data' bs station(1:4) bs 'cdf' bs];
if strcmp(pwd, 'O:\jmat\0programme_win')
path_DI = ['O:' bs 'jmat' bs '0DI_measurements' bs 'DI_' ...
station(1:3) ...
%if strcmp(pwd, 'O:\jmat\0programme_win')
path_DI = [path1 bs '0DI_measurements' bs 'DI_' station(1:3) ...
num2str(year, '%4.4d') bs];
path_cdf = ['O:' bs 'jmat' bs station(1:4) bs 'cdf' bs];
end
path_cdf = [path1 bs station(1:4) bs 'cdf' bs];
%end
%month = 1; removed 27/2-2012
%day = 7;
% =========================================================================
% START PROCESSING
% =========================================================================
figure
% % START Identify and convert Achims GFZ-DI-schemes
% % with name e.g. ng0_140102.xls
......@@ -261,7 +387,7 @@ end
B = dir(filename_criterion);
C = struct2cell(B);
for i = 1:size(C, 2) %remove filernames with wrong length
for i = 1:size(C, 2) %remove filenames with wrong length
length_here = size(char(C{1,i}), 2);
if length_here == filename_length
D(i) = 1;
......@@ -288,27 +414,26 @@ clear D
% reduce number of DI-measurements
if number_DI ~= 1000
if number_DI == 0
for i = 1:size(C, 2) %remove filenames that have '0' or '1' at 'end-11'
characters_here = char(C{1,i});
if str2num(characters_here(end-11:end-8)) >= ...
str2num(start_mmdd) &&...
str2num(characters_here(end-11:end-8)) <= ...
str2num(end___mmdd)
D(i) = 1;
else
D(i) = 0;
end
if number_DI == 0
for i = 1:size(C, 2) %remove filenames that have '0' or '1' at 'end-11'
characters_here = char(C{1,i});
if str2num(characters_here(end-11:end-8)) >= ...
str2num(start_mmdd) &&...
str2num(characters_here(end-11:end-8)) <= ...
str2num(end___mmdd)
D(i) = 1;
else
D(i) = 0;
end
C = C(:,D == 1);
filenames = char(C{1,:});
clear D
end
else
filenames1 = filenames;
filenames = filenames1(end - number_DI+1:end,:);
C = C(:,D == 1);
filenames = char(C{1,:});
clear D
elseif number_DI ~= 1000
filenames1 = filenames;
filenames = filenames1(end - number_DI+1:end,:);
end
......@@ -352,3 +477,4 @@ return_array = [return_array; return_string]
end %i
save('recent-DI', 'return_array')
end
......@@ -185,7 +185,7 @@ arg_specs.parfile.dim1=1;
% Check if parameter file exists
if ~exist(arg_parsed.parfile,'file')
warning(['Specified parameter file ' arg_parsed.parfile ...
'does not exist. Try tp get all parameters from command-line.']);
'does not exist. I will try to get all parameters from command-line.']);
end
% Set default values from parameter file
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment