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

Merge branch 'Functions'

Conflicts:
	IAGA2002_Kyoto_transfer_Katrin.m
	calculate_baselines_environment.m
	lib/calculate_baselines.m
	plot_baseline_universal.m
parents 4bc09e3c 895e5f79
......@@ -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
......
%% program to transfer IAGA2002-files by email to Kyoto
%
% works only from thinlink
%
% works with Q-files and P-files
% here was an error in our declination baseline for NAQ affecting data sent
% to Kyoto and Intermagnet from April 17 to 23,
% If you can send them with the similar method as the realtime data (i.e.,
% just changing the header from "R" to "Q"), Kyoto GIN will be able
% to handle them. But I need time to modify my program.
% dtudata@swdc234.kugi.kyoto-u.ac.jp
%
% header:
% tdc20120520pmin.min
%
% attachment: same file
clear all
startdate = jd2000(2018, 07, 18); % HERE START DATE FOR non-online
enddate = jd2000(2018, 07, 18); % HERE END DATE FOR non-online
station = 'VNA1';
%station = 'WNG1';
%station = 'BFO1';
%station = 'TDC1';
%station = 'NGK0';
%station = 'GAN0';
IAGAtype = 'P'; % preliminary data
%IAGAtype = 'Q'; % quasi definitive data
%IAGAtype = 'P'; % quasi definitive data
recipient = {'gfzdata@swdc234.kugi.kyoto-u.ac.jp'};
if strcmp(station(1:3), 'VNA')
recipient = {'neumayer-geo@awi.de'
'gfzdata@swdc234.kugi.kyoto-u.ac.jp'
'Alfons.Eckstaller@awi.de'};
end %if
% recipient = {'gfzdata@swdc234.kugi.kyoto-u.ac.jp'
% 'jrgm@space.dtu.dk'};
% recipient = 'dtudata@swdc234.kugi.kyoto-u.ac.jp'; %
% recipient = 'jrgm@space.dtu.dk'; %
%recipient = 'David.Calp@NRCan-RNCan.gc.ca'
opsys = computer;
if strcmp(opsys(1:5), 'MACI6') == 1
% setup for Juergens Mac in GFZ VPN or network
path1 = '/Users/jmat/work/IAGA2002_Kyoto_transfer/';
bs = '/'; % slash
%setpref('Internet','SMTP_Server','smtp.gfz-potsdam.de');
%setpref('Internet','E_mail','jmat@gfz-potsdam.de');
setpref('Internet','SMTP_Server','smtp.gfz-potsdam.de');
setpref('Internet','E_mail','tornow@gfz-potsdam.de');
elseif strcmp(opsys(1:2), 'PC') == 1
path1 = 'O:\jmat\IAGA2002_Kyoto_transfer\';
bs = '\'; % slash
setpref('Internet','SMTP_Server','smtp.gfz-potsdam.de');
setpref('Internet','E_mail','jmat@gfz-potsdam.de');
else
diplay('operating system not recognised');
end
for i = 1:size(recipient, 1)
for idate = startdate:enddate
[year month day] = jd2date(idate);
IAGA_pathname = [path1 upper(IAGAtype) '_files' bs station(1:3) bs...
num2str(year, '%4.4d') bs];
IAGA_filename = [lower(station(1:3)) num2str(year, '%4.4d')...
num2str(month, '%2.2d') num2str(day, '%2.2d')...
lower(IAGAtype) 'min.min'];
IAGA_pathfile = [IAGA_pathname IAGA_filename]
if exist(IAGA_pathfile, 'file') == 2
% sendmail(recipients,subject,message,attachments)
sendmail(recipient{i}, IAGA_filename, '', IAGA_pathfile)
display(['sent ' IAGA_filename ' to ' recipient{i}]);
else
display(['not found: ' IAGA_filename]);
end
end %for idate
end %for i
\ No newline at end of file
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
......@@ -25,66 +25,46 @@
% Required:
% =========
%
% - starttime used as input for jd2000 starttime
% - station character vector station name
%
% - 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)
% - path character Path to data files
% Default: Current directory
%
% - 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
% - parfile character Parameter file
% vector Default: parameters_win.txt
%
% - output_format 'c' (default) means calibrated, all types of files
% 'r' means raw, only raw-file 1 second
% and IAGA V
% - startdate input for jd2000 startdate
% Default: today
%
% - 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'
% - stopdate input for jd2000 stopdate
% Default: today
%
% - output_resolution '0' (default) don't write mat-file
% 's' means that also 1-second values are
% saved in matlab format.
% - number_DI integer number of DI measurements to
% be read:
% 0 (default): all in time
% specified by
% start/stopdate
% <0 number of meas.
% before stopdate
% >0 number of meas.
% after startdate
%
% - time_interval 'n' (default) specified by startdate and enddate
% 'r' means real time from magobs/magdata
% - tempsource 'c' (default) Temperature from cdf-file
% 's' Temperature from spreadsheet
%
% 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';
% - temp_correct 'y' (default) Apply temperature correction
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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
%
......@@ -97,69 +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;
% 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;
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';
......@@ -173,43 +103,17 @@ arg_specs.temp_correct.valid={'y','n'};
arg_specs.apply_time_lag.default='y';
arg_specs.apply_time_lag.valid={'y'};
%
% Find time error
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;
% Timeshift array
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
......@@ -220,14 +124,12 @@ end
% -------------------------------------------------------------------------
% 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;
station = arg_parsed.station(1,1:4);
tempsource = arg_parsed.tempsource;
temp_correct = arg_parsed.temp_correct;
......@@ -236,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))
......@@ -249,28 +151,14 @@ end
% Generate paths
% -------------------------------------------------------------------------
return_array = []; %returnes baseliens etc from function
return_array = []; %returns baseliens etc from function
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 = [path1 bs '0DI_measurements' bs 'DI_' station(1:3) ...
num2str(year, '%4.4d') bs];
path_cdf = [path1 bs station(1:4) bs 'cdf' bs];
%end
%month = 1; removed 27/2-2012
%day = 7;
% =========================================================================
% START PROCESSING
......@@ -278,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
% %
......@@ -365,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') ...