Commit 4bc09e3c authored by Jürgen Matzka's avatar Jürgen Matzka
Browse files

Merge branch 'Functions'

Conflicts:
	calculate_baselines_environment.m
	plot_baseline_universal.m
parents 6879234a c69aeafd
......@@ -14,77 +14,270 @@
% make function calcualte_ime_error_absolutes.m fit for Matlab2013 cdfread:
% %informcdf.Variables{i,3},1 contains the length of the array
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% amors 20180504
%
% Script converted to Function
%
% Use command-line arguments instead of hardcoded values for parameters
%
% Required:
% =========
%
% - starttime used as input for jd2000 starttime
%
% - stoptime used as imput for jd2000 stoptime
%
% - station character vector station name
%
% Optional:
% =========
%
% - produce_IAGA_2002_min '0' (default) no output
% 'P' provisional data
% 'D' definitive data
% 'Q' quasi-definitive data
% 'V' variation (V)
%
% - produce_IAGA_2002_sec '0' (default) no output
% 'P' provisional data
% 'D' definitive data
% 'Q' quasi-definitive data
% 'V' variation (V)
%
% - calculate_IAGA_F 'n' (default) 888888 is set in the F-column for
% types Q, D, P, V
% 'y' for type other than V), then F is
% calculated from XYZ
%
% - output_format 'c' (default) means calibrated, all types of files
% 'r' means raw, only raw-file 1 second
% and IAGA V
%
% - output_ftp 'n' (default) raw one second data saved as cdf
% 'y' raw one second data saved as ftp
% REQUIRES
% - output_format = 'r'
% - output_resolution = 's'
% - produce_IAGA_2002_min = '0'
%
% - output_resolution '0' (default) don't write mat-file
% 's' means that also 1-second values are
% saved in matlab format.
%
% - 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)
clear all
close all
opsys = computer;
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.
% =========================================================================
% -------------------------------------------------------------------------
% 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
% -------------------------------------------------------------------------
% Build struct of command-line specifications
% -------------------------------------------------------------------------
%
% 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;
%
% Specify optional arguments
% Source for temperature readings
% 'c' for cdf
arg_specs.tempsource.default='c';
arg_specs.tempsource.valid={'c','s'};
% 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 from command-line
% -------------------------------------------------------------------------
[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 all the parameters
% =========================================================================
% -------------------------------------------------------------------------
% General parameters
% -------------------------------------------------------------------------
% This was removed as option here !
%
% 's' for spreadsheet, 'c' for cdf, here always 'c'
figure
station='GAN0j';
%station = 'SMA0g'; % c or d or g or s or l for datalogger
%station = 'WNG5g'; % 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 = 2017;
start_mmdd = '1201';
end___mmdd = '1231';
ppmsource = 'c'; % '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
diplay('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
% %
......@@ -208,7 +401,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;
......@@ -235,27 +428,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
......@@ -299,3 +491,4 @@ return_array = [return_array; return_string]
end %i
save('recent-DI', 'return_array')
end
......@@ -131,7 +131,7 @@
% Required:
% =========
%
% - starttime used as input for jd2000 starttime for conversion
% - starttime c starttime for conversion
%
% - stoptime used as imput for jd2000 stoptime for conversion
%
......
This diff is collapsed.
......@@ -671,6 +671,8 @@ if strcmp(station, 'BFO1s')
6211 20867.30 'q' '2017-01-02'
6453 20868.20 'q' '2017-09-01'
6606 20868.70 'q' '2018-02-01'
6674.5 20868.98 'q' '2018-04-10'
6674.5 20916.20 'q' '2018-04-10' % Variometer re-oriented
}; % REMEMBER for QD: default is the first day of the next month!!!
D0alines = {
5113 0.054100 'd' '2013-12-31'
......@@ -686,6 +688,8 @@ if strcmp(station, 'BFO1s')
6211 0.05800 'q' '2017-01-02'
6453 0.06450 'q' '2017-09-01'
6606 0.05933 'q' '2018-02-01'
6674.5 0.06092 'q' '2018-04-10'
6674.5 0.65325 'q' '2018-04-10' % Variometer re-oriented
}; % REMEMBER for QD: default is the first day of the next month!!!
% remember 0.01 degree = 3.7 nT
Z0alines = {
......@@ -700,6 +704,8 @@ if strcmp(station, 'BFO1s')
6211 43344.00 'q' '2017-01-02'
6453 43343.50 'q' '2017-09-01'
6606 43343.30 'q' '2018-02-01'
6674.5 43343.53 'q' '2018-04-10'
6674.5 43393.66 'q' '2018-04-10' % Variometer re-oriented
}; % REMEMBER for QD: default is the first day of the next month!!!
end
......
......@@ -235,8 +235,51 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ppmsec2cdf(varargin)
% =========================================================================
% 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.
% =========================================================================
% -------------------------------------------------------------------------
% Parse input arguments
% 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
[arg_specs.path.default, ...
arg_specs.station.default, ...
arg_specs.starttime.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
% -------------------------------------------------------------------------
% Build struct of command-line specifications
% -------------------------------------------------------------------------
%
......@@ -256,20 +299,6 @@ 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'};
% station_array = ['SMA0g'];
%station_array = ['MSN0g'];
%station_array = ['WNG1g'];
%station_array = ['LRV1a'];
%station_array = ['SMA0g'];
%station_array = ['PUL0g'; 'TEL0g'];
%station_array = ['TDC1d'];
%station_array = ['NGK0g'];
% station_array = ['BFO1s'];
%station_array = ['VSS0g'];
%station_array = ['TDC1d'];
%station_array = ['VSS1g'];
%station_array = ['VNA1s'];
% station_array = ['MAR1l'];
%
% Specify optional arguments
......@@ -283,8 +312,9 @@ arg_specs.DontWriteFTPDownload.valid={0,1};
arg_specs.MakeTromsoFile.default=0;
arg_specs.MakeTromsoFile.valid={0,1};
%
% Parse arguments
% -------------------------------------------------------------------------
% Parse arguments from command-line
% -------------------------------------------------------------------------
[arg_parsed state]=parse_arg(arg_specs,varargin);
......@@ -297,9 +327,9 @@ elseif (state.err == 2) % error occured, stop execution
end
% -------------------------------------------------------------------------
% Assign input arguments
% -------------------------------------------------------------------------
% =========================================================================
% Assign all the parameters
% =========================================================================
DontWriteFTPDownload = arg_parsed.DontWriteFTPDownload;
......@@ -323,27 +353,14 @@ station_array=arg_parsed.station;
% PATHS, depending on OS
%
opsys = computer;
if strcmp(opsys(1:2), 'GL') == 1
% root path
path1 = '/nfs/magobs/magdata/data';
path1 = '/home/variomet/jmat'
bs = '/'; % slash
elseif strcmp(opsys(1:2), 'PC') == 1
path1 = 'Y:\laptop_data';
if strcmp(pwd, 'O:\jmat\0programme_win') % ERKENNT KATRINS RECHNER
path1 = 'O:\jmat';
end
bs = '\'; % backslash
else
diplay('operating system not recognised');
end
path1 = arg_parsed.path;
% -------------------------------------------------------------------------
% START WITH PROCESSING
% -------------------------------------------------------------------------
% =========================================================================
% Start with processing
% =========================================================================
bs=backslash;
opsys=computer;
array_size = 86400;
timestamp_check_vs_GPS_list = []; %introduced 2014-01-26
......
......@@ -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
......@@ -218,6 +218,8 @@ end
1, 1, 1,...
1, 1, 1,...
1});
% Remove NaNs (no value specified in parfile) and set to required if no
% default was specified
......@@ -312,7 +314,7 @@ end
% Assign general parameters
showdate = strrep(arg_parsed.date,'-','');
hhmm = arg_parsed.time;
STATION = arg_parsed.station; % Station name
STATION = arg_parsed.station(1:4); % Station name
NEIGHBOUR1 = arg_parsed.neighbour1; % Neighbour 1 station name
NEIGHBOUR2 = arg_parsed.neighbour2; % Neighbour 2 station name
LENGTH = arg_parsed.length; % Length of observation interval in minutes
......
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