Commit 3d9caee7 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Functions added, calculate_baselines_environment new date selection

parent aa23a242
......@@ -32,7 +32,7 @@
%
% - starttime used as input for jd2000 starttime for conversion
%
% - stoptime used as imput for jd2000 stoptime for conversion
% - stoptime used as input for jd2000 stoptime for conversion
%
% - station cell array of characters station names
%
......@@ -51,25 +51,13 @@ function IAGA2002_Kyoto_transfer(varargin)
% Parse input arguments
% =========================================================================
% Parameter file
parfile='parameters_win.txt';
% -------------------------------------------------------------------------
% Specify required arguments
% -------------------------------------------------------------------------
arg_specs.starttime.required=1;
arg_specs.starttime.type='char';
arg_specs.starttime.dim1=1;
arg_specs.starttime.dim2=10;
arg_specs.stoptime.required=1;
arg_specs.stoptime.type='char';
arg_specs.stoptime.dim1=1;
arg_specs.stoptime.dim2=10;
arg_specs.station.required=1;
arg_specs.station.dim2=4;
arg_specs.station.type='char';
%station = 'VNA1';
arg_specs.IAGAtype.required = 1;
arg_specs.IAGAtype.valid={'Q','P'};
......@@ -77,37 +65,28 @@ arg_specs.IAGAtype.valid={'Q','P'};
% Specify optional arguments
% -------------------------------------------------------------------------
% -------------------------------------------------------------------------
% Parse arguments
% -------------------------------------------------------------------------
[arg_parsed state]=parse_arg(arg_specs,varargin);
% NONE
% -------------------------------------------------------------------------
% Error treatment
% Parse arguments
% -------------------------------------------------------------------------
if (state.err == 1) % warning occurred, but no error
warning(state.wngmsg);
elseif (state.err == 2) % error occured, stop execution
error(state.errmsg);
end
arg_parsed = get_cmd_par(arg_specs,parfile,varargin);
% -------------------------------------------------------------------------
% Assign input arguments
% -------------------------------------------------------------------------
% =========================================================================
% Assign all the parameters
% =========================================================================
% Required arguments
tmp=datevec(datenum(arg_parsed.starttime,'yyyy-mm-dd'));
tmp=datevec(datenum(arg_parsed.startdate,'yyyy-mm-dd'));
startdate = jd2000(tmp(1),tmp(2),tmp(3));
tmp=datevec(datenum(arg_parsed.stoptime,'yyyy-mm-dd'));
tmp=datevec(datenum(arg_parsed.stopdate,'yyyy-mm-dd'));
enddate = jd2000(tmp(1),tmp(2),tmp(3));
IAGAtype = arg_parsed.IAGAtype;
station = arg_parsed.station(1,1:4);
station = arg_parsed.station;
IAGAtype = arg_parsed.IAGAtype;
% =========================================================================
% START PROCESSING
......
modified: IAGA2002_Kyoto_transfer.m
modified: calculate_baselines_environment.m
modified: cdf2def.m
NOT READY modified: cdf_supplementing.m
modified: plot_baseline_universal.m
modified: ppmsec2cdf.m
modified: varlab_01.m
......@@ -27,46 +27,44 @@
%
% - station character vector station name
%
% - startdate input for jd2000 startdate
%
% Optional:
% =========
%
% - path character Path to data files
% Default: Current directory
%
% - parfile character Parameter file
% vector (Default: parameters_win.txt)
% vector Default: parameters_win.txt
%
% - startdate input for jd2000 startdate
% Default: today
%
% - stopdate input for jd2000 stopdate
% default: today
% Default: today
%
% - number_DI integer number of DI measurements to
% be read:
% 0 (default): all in time
% specified by
% start/stopdate
% else: number of meas.
% <0 number of meas.
% before stopdate
% >0 number of meas.
% after startdate
%
% - tempsource 'c' (default) Temperature from cdf-file
% 's' Temperature from spreadsheet
%
% - temp_correct 'y' (default) Apply temperature correction
%
% 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;
if ~strcmp(opsys(1:2), 'PC')
error('operating system not supported');
if ~ispc
error('Operating system currently not supported.')
end
% =========================================================================
% Parse input arguments
%
......@@ -79,74 +77,19 @@ end
% specified in parameter file, it is required at command-line.
% =========================================================================
% -------------------------------------------------------------------------
% 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.']);
end
% Set default values from parameter file
[arg_specs.path.default, ...
arg_specs.station.default, ...
arg_specs.startdate.default]=...
read_parameters(arg_parsed.parfile,'PATH','STATION','DATE',...
{0,0,0});
% Remove NaNs (no value specified in parfile) and set to required if no
% default was specified
for field=fields(arg_specs)'
if isnan(arg_specs.(field{1}).default)
arg_specs.(field{1})=rmfield(arg_specs.(field{1}),'default');
arg_specs.(field{1}).required=1;
end
end
% Parameter file
parfile='parameters_win.txt';
% -------------------------------------------------------------------------
% Build struct of command-line specifications
% Specify optional arguments
% -------------------------------------------------------------------------
%
% 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;
arg_specs.startdate.required=1;
arg_specs.startdate.type='char';
arg_specs.startdate.dim1=1;
arg_specs.startdate.dim2=10;
% Number of DI measurements to be read for given year
arg_specs.number_DI.required=1;
arg_specs.number_DI.default=0;
arg_specs.number_DI.type = 'numeric';
arg_specs.number_DI.dim1 = 1;
arg_specs.number_DI.dim2 = 1;
%
% Specify optional arguments
% Stopdate
arg_specs.stopdate.default=arg_specs.startdate.default;
arg_specs.stopdate.type='char';
arg_specs.stopdate.dim1=1;
arg_specs.stopdate.dim2=10;
% Source for temperature readings
% 'c' for cdf
arg_specs.tempsource.default='c';
......@@ -164,34 +107,13 @@ arg_specs.apply_time_lag.valid={'y'};
arg_specs.find_time_error.default='n';
% Timeshift array
arg_specs.timeshift_array.default=[-300:1:300]';
arg_specs.timeshift_array.default=(-300:1:300)';
% -------------------------------------------------------------------------
% Parse arguments from command-line
% 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
arg_parsed = get_cmd_par(arg_specs,parfile,varargin);
% =========================================================================
% Assign all the parameters
......@@ -207,7 +129,7 @@ end
ppmsource = 'c';
path1 = arg_parsed.path;
station = arg_parsed.station;
station = arg_parsed.station(1,1:4);
tempsource = arg_parsed.tempsource;
temp_correct = arg_parsed.temp_correct;
......@@ -216,8 +138,8 @@ find_time_error = arg_parsed.find_time_error;
timeshift_array = arg_parsed.timeshift_array;
number_DI = arg_parsed.number_DI;
start_mmdd = arg_parsed.startdate([6:7 9:10]);
end___mmdd = arg_parsed.stopdate([6:7 9:10]);
startdate = datenum(arg_parsed.startdate,'YYYY-mm-dd');
stopdate = datenum(arg_parsed.stopdate,'YYYY-mm-dd');
year = str2double(arg_parsed.stopdate(1:4));
if ~strcmp(arg_parsed.stopdate(1:4),arg_parsed.startdate(1:4))
......@@ -229,7 +151,7 @@ end
% Generate paths
% -------------------------------------------------------------------------
return_array = []; %returnes baseliens etc from function
return_array = []; %returns baseliens etc from function
bs=backslash;
......@@ -244,6 +166,147 @@ path_cdf = [path1 bs station(1:4) bs 'cdf' bs];
figure
% -------------------------------------------------------------------------
% Create path to DI-measurements and set correct filename length
% -------------------------------------------------------------------------
if strcmp(station(1:3), 'TDC') || strcmp(station(1:3), 'VNA') ...
|| strcmp(station(1:3), 'BFO') || strcmp(station(1:3), 'MSN')...
|| strcmp(station(1:3), 'NGK') || strcmp(station(1:3), 'WNG') ...
|| strcmp(station(1:3), 'TTB') || strcmp(station(1:3), 'VRE')...
|| strcmp(station(1:3), 'SMA') ...
|| strcmp(station(1:3), 'SHE') || strcmp(station(1:3), 'VSS') ...
|| strcmp(station(1:3), 'GAN')
filename_criterion = [path_DI 'DI_' station(1:3) '_'...
num2str(year, '%4.4d') '*.xls'];
filename_length = 23;
else
filename_criterion = [path_DI '*.xls'];
filename_length = 12;
end
% -------------------------------------------------------------------------
% Create list of correctly named files
% -------------------------------------------------------------------------
% Get filenames
B = dir(filename_criterion);
% Select correctly named files
sel=true(length(B),1);
for i=1:length(B)
% Check length of file
if length(B(i).name) ~= filename_length
sel(i)=false;
end
% Check first digit of month (must be '0' or '1')
if ~regexp(B(i).name(end-11),'[01]')
sel(i)=false;
end
end
B=B(sel);
% -------------------------------------------------------------------------
% Select files according to date
% -------------------------------------------------------------------------
% Assume filenames are sorted alphabetically
sel=false(length(B),1);
if number_DI == 0
for i=1:length(B)
day=datenum(B(i).name(8:15),'YYYYmmdd');
if (day >= startdate) && (day <= stopdate)
sel(i)=true;
end
end
fprintf('Process %d DI-measurements in time range %s to %s.\n',...
sum(sel),datestr(startdate),datestr(stopdate));
elseif number_DI > 0
for i=1:length(B)
day=datenum(B(i).name(8:15),'YYYYmmdd');
if (day >= startdate)
sel(i:min(number_DI+i-1,length(B)))=true;
break;
end
end
fprintf('Process max. %d DI-measurements after (including) %s: %d available.\n',...
number_DI,datestr(startdate),sum(sel));
elseif number_DI < 0
for i=length(B):-1:1
day=datenum(B(i).name(8:15),'YYYYmmdd');
if (day <= stopdate)
sel(max(i+number_DI+1,1):i)=true;
break;
end
end
fprintf('Process max. %d DI-measurements before (including) %s: %d available.\n',...
-number_DI,datestr(stopdate),sum(sel));
end
B=B(sel);
% -------------------------------------------------------------------------
% Call calculate_baselines for list of filenames
% -------------------------------------------------------------------------
for i = 1:length(B)
DI_file = [path_DI B(i).name];
cdf_file = [path_cdf station(1:4) '_' B(i).name(end-15:end-8) '.cdf'];
if exist(DI_file, 'file')
if strcmp(find_time_error, 'y')
[return_string] = ...
calculate_time_error_absolutes(DI_file, cdf_file, station,...
ppmsource, tempsource, temp_correct, timeshift_array);
else
if strcmp(station(1:3), 'VRE')
[return_string] = ...
calculate_baselines_VRE(DI_file, cdf_file, station,...
ppmsource, tempsource, temp_correct, apply_time_lag);
return_string = char(return_string{1});
else
[return_string] = ...
calculate_baselines(DI_file, cdf_file, station,...
ppmsource, tempsource, temp_correct, apply_time_lag);
return_string = char(return_string{1});
end
end
end
return_array = [return_array; return_string]
end %i
save('recent-DI', 'return_array')
end
% =========================================================================
% HERITAGE
% =========================================================================
% % START Identify and convert Achims GFZ-DI-schemes
% % with name e.g. ng0_140102.xls
% %
......@@ -331,130 +394,3 @@ figure
% % END Identify and convert Achims GFZ-DI-schemes
%
%
%read in filenames for DI-files from directory, remove unrelevant filenames
%from list
if strcmp(station(1:3), 'TDC') || strcmp(station(1:3), 'VNA') ...
|| strcmp(station(1:3), 'BFO') || strcmp(station(1:3), 'MSN')...
|| strcmp(station(1:3), 'NGK') || strcmp(station(1:3), 'WNG') ...
|| strcmp(station(1:3), 'TTB') || strcmp(station(1:3), 'VRE')...
|| strcmp(station(1:3), 'SMA') ...
|| strcmp(station(1:3), 'SHE') || strcmp(station(1:3), 'VSS') ...
|| strcmp(station(1:3), 'GAN');
filename_criterion = [path_DI 'DI_' station(1:3) '_'...
num2str(year, '%4.4d') '*.xls'];
filename_length = 23;
% elseif strcmp(station(1:3), 'WNG')
%
% filename_criterion = [path_DI 'DI_' station(1:3) '0_'...
% num2str(year-2000, '%2.2d') '*.xls'];
% filename_length = 22;
else
filename_criterion = [path_DI '*.xls'];
filename_length = 12;
end
B = dir(filename_criterion);
C = struct2cell(B);
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;
else
D(i) = 0;
end
end
C = C(:,D == 1);
filenames = char(C{1,:});
clear D
for i = 1:size(C, 2) %remove filenames that have '0' or '1' at 'end-11'
characters_here = char(C{1,i});
if strcmp(characters_here(end-11), '0') || ...
strcmp(characters_here(end-11), '1')
D(i) = 1;
else
D(i) = 0;
end
end
C = C(:,D == 1);
filenames = char(C{1,:});
clear D
% reduce number of DI-measurements
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
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
%
%
% call function for list of filenames
%
%
for i = 1:size(filenames, 1)
DI_file = [path_DI filenames(i,:)];
cdf_file = [path_cdf station(1:4) '_' num2str(year, '%4.4d')...
filenames(i,end-11:end-8) '.cdf'];
if exist(DI_file, 'file')
if strcmp(find_time_error, 'y')
[return_string] = ...
calculate_time_error_absolutes(DI_file, cdf_file, station,...
ppmsource, tempsource, temp_correct, timeshift_array);
else
if strcmp(station(1:3), 'VRE')
[return_string] = ...
calculate_baselines_VRE(DI_file, cdf_file, station,...
ppmsource, tempsource, temp_correct, apply_time_lag);
return_string = char(return_string{1});
else
[return_string] = ...
calculate_baselines(DI_file, cdf_file, station,...
ppmsource, tempsource, temp_correct, apply_time_lag);
return_string = char(return_string{1});
end
end
end
return_array = [return_array; return_string]
end %i
save('recent-DI', 'return_array')
end
......@@ -183,24 +183,14 @@ function cdf2def(varargin)
% Parse input arguments
% =========================================================================
% Parameter file
parfile='parameters_win.txt';
% -------------------------------------------------------------------------
% Specify required arguments
% -------------------------------------------------------------------------
arg_specs.starttime.required=1;
arg_specs.starttime.type='char';
arg_specs.starttime.dim1=1;
arg_specs.starttime.dim2=10;
arg_specs.stoptime.required=1;
arg_specs.stoptime.type='char';
arg_specs.stoptime.dim1=1;
arg_specs.stoptime.dim2=10;
arg_specs.station.required=1;
arg_specs.station.dim2=5;
arg_specs.station.type='char';
%arg_specs.valid = {'BFO1s';'MSN0g';'NGK0g';'NGK1g';'NGK2g'; 'NGK3g';'NGK6g';'NGK7g';'NGK8g';'WNG0g';'WNG1g';'WNG2g';'WNG3g';'VNA1s';'SHE0g';'VSS0g';'TTB0g';'TTB1l';'PUL0g';'TEL0g';'VNA1s';'VSS0g'};
% NONE, except the ones in parfile
% -------------------------------------------------------------------------
% Specify optional arguments
......@@ -231,28 +221,17 @@ arg_specs.time_interval.valid={'n','r'};
% Parse arguments
% -------------------------------------------------------------------------
[arg_parsed state]=parse_arg(arg_specs,varargin);
arg_parsed = get_cmd_par(arg_specs,parfile,varargin);