Commit 640cb8f4 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

GAN di_xls_converter beta finished

parent 5e8a978f
...@@ -5,16 +5,26 @@ function hhmmss=dday2hhmmss(dday) ...@@ -5,16 +5,26 @@ function hhmmss=dday2hhmmss(dday)
if isnumeric(dday) if isnumeric(dday)
% Hours % Hours
tmp=dday*24; hh=floor(dday*24);
hhmmss=sprintf('%02u',floor(tmp));
% Minutes % Minutes
tmp=(tmp-floor(tmp))*60; mm=floor(mod(dday*24,1)*60);
hhmmss=[hhmmss sprintf('%02u',floor(tmp))];
% seconds % seconds
tmp=(tmp-floor(tmp))*60; ss=round(mod(dday*24*60,1)*60);
hhmmss=[hhmmss sprintf('%02u',floor(tmp))]; if (ss==60)
ss=0;
if (mm==59)
mm=0;
hh=hh+1;
else
mm=mm+1;
end
end
hhmmss=sprintf('%02u%02u%02u',hh,mm,ss);
else else
......
function my_xlswrite(opsys,varargin) function state=my_xlswrite(opsys,varargin)
% Call correct xls(x) writing routne - depending on O/S % Call correct xls(x) writing routne - depending on O/S
if (opsys(1:2) == 'PC') if (opsys(1:2) == 'PC')
xlswrite(varargin{:}) state=xlswrite(varargin{:});
elseif (opsys(1:2) == 'GL') elseif (opsys(1:2) == 'GL')
xlwrite(varargin{:}) state=xlwrite(varargin{:});
end end
end end
\ No newline at end of file
function write_DI_xls(path,DI,file_template,del) function write_DI_xls(path,DI,file_template,del)
% ///////////////////////////////////////////////////////////////////// % /////////////////////////////////////////////////////////////////////////
% Create new xlsx-Files % Load libraries
% ///////////////////////////////////////////////////////////////////// % /////////////////////////////////////////////////////////////////////////
% Create folders opsys = computer;
if (~exist(path,'dir')); mkdir(path_n); end if strcmp(opsys(1:2), 'PC') == 1
bs = '\'; % backslash
% Starttime on full minute elseif strcmp(opsys(1:2), 'GL') == 1
time = DI.D.WU.time(1); bs = '/'; % slash
javaaddpath('lib/xlwrite/poi_library/poi-3.8-20120326.jar');
% Create filename javaaddpath('lib/xlwrite/poi_library/poi-ooxml-3.8-20120326.jar');
file_new=[path bs 'DI_' station(1:3) '_' ... javaaddpath('lib/xlwrite/poi_library/poi-ooxml-schemas-3.8-20120326.jar');
num2str(DI.DATE.yyyymmdd) num2str(DI.D.WU.time(1:4)) '.xls']; javaaddpath('lib/xlwrite/poi_library/xmlbeans-2.3.0.jar');
javaaddpath('lib/xlwrite/poi_library/dom4j-1.6.1.jar');
if (exist(file_new,'file')==2) javaaddpath('lib/xlwrite/poi_library/stax-api-1.0.1.jar');
if del else
warning(['File ' file_new ' will be overwritten.']); display('operating system not recognised');
else end
error(['File ' file_new' already exists.']);
end
end % /////////////////////////////////////////////////////////////////////
% Create new xlsx-Files
% Copy file from template % /////////////////////////////////////////////////////////////////////
copyfile(file_template,file_new);
% Create folders
% ///////////////////////////////////////////////////////////////////// if (~exist(path,'dir')); mkdir(path); end
% Write Info
% ///////////////////////////////////////////////////////////////////// % Create filename
file_new=[path bs 'DI_' DI.INFO.station(1:3) '_' ...
% Observatory station name num2str(DI.DATE.yyyymmdd) num2str(DI.D.EU.time(1:4)) '.xls'];
tmp{1}=DI.INFO.station;
% Year of abs. measurement if (exist(file_new,'file')==2)
tmp{2}=DI.DATE.yyyymmdd(5:8); if del
% MMDD warning(['File ' file_new ' will be overwritten.']);
tmp{3}=DI.DATE.yyyymmdd([3:4 1:2]); else
warning(['File ' file_new ' already exists.']);
my_xlswrite(opsys,file_new,tmp,1,'A8'); return;
clearvars tmp
% Observer name
tmp{1}=DI.INFO.observer;
% Azimuth mark
tmp{2}=DI.AZ.number;
% Theodolite type
tmp{3}='020';
% Units
tmp{4}='DMS';
my_xlswrite(opsys,file_new,tmp,1,'E8');
clearvars tmp
% Pillar number
tmp{1}=1;
my_xlswrite(opsys,file_new,tmp,1,'F13');
clearvars tmp
% /////////////////////////////////////////////////////////////////////
% Write azimuth mark readings
% /////////////////////////////////////////////////////////////////////
% Sensor dn / Sensor up
fields={'SD' 'SU'};
for i=1:length(fields)
f=DI.AZ.(fields{i}).D;
tmp{2*i-1}=f(1);
if length(f)>1 && ~isnan(f(2))
tmp{2*i}=f(2);
else
tmp{2*i}=f(1);
end
end
my_xlswrite(opsys,file_new,tmp,1,'A31');
clearvars tmp
for i=1:length(fields)
f=DI.AZ.(fields{i}).I;
tmp{2*i-1}=f(1);
if length(f)>1 && ~isnan(f(2))
tmp{2*i}=f(2);
else
tmp{2*i}=f(1);
end
end
my_xlswrite(opsys,file_new,tmp,1,'A13');
clearvars tmp
% /////////////////////////////////////////////////////////////////////
% Write declination readings
% /////////////////////////////////////////////////////////////////////
% Time
fields={'EU' 'WU' 'ED' 'WD'};
for i=1:length(fields)
tmpval=DI.D.(fields{i}).time;
tmp{2*i-1} = tmpval;
tmp{2*i} = tmpval;
end end
end
my_xlswrite(opsys,file_new,tmp',1,'B19');
clearvars tmp % Copy file from template
copyfile(file_template,file_new);
% Readings
% /////////////////////////////////////////////////////////////////////
fields={'WU' 'ED' 'WD' 'EU'}; % Write Info
% /////////////////////////////////////////////////////////////////////
for i=1:length(fields)
tmpval=DI.D.(fields{i}).val; % Observatory station name
tmpval=floor(tmpval)+mod(tmpval,1)*0.6; tmp{1}=DI.INFO.station;
tmp{2*i-1} = tmpval; % Year of abs. measurement
tmp{2*i} = tmpval; tmp{2}=DI.DATE.yyyymmdd(1:4);
% MMDD
tmp{3}=DI.DATE.yyyymmdd([5:8]);
my_xlswrite(opsys,file_new,tmp,1,'A8');
clearvars tmp
% Observer name
tmp{1}=DI.INFO.observer;
% Azimuth mark
tmp{2}=DI.AZ.number;
% Theodolite type
tmp{3}='020';
% Units
tmp{4}='DMS';
my_xlswrite(opsys,file_new,tmp,1,'E8');
clearvars tmp
% Pillar number
tmp{1}=1;
my_xlswrite(opsys,file_new,tmp,1,'F13');
clearvars tmp
% /////////////////////////////////////////////////////////////////////
% Write azimuth mark readings
% /////////////////////////////////////////////////////////////////////
% Sensor dn / Sensor up
fields={'SD' 'SU'};
for i=1:length(fields)
tmpval=DI.AZ.(fields{i}).D;
tmpval=floor(tmpval)+mod(tmpval,1)*0.6;
tmp{2*i-1}=tmpval(1);
if length(tmpval)>1 && ~isnan(tmpval(2))
tmp{2*i}=tmpval(2);
else
tmp{2*i}=tmpval(1);
DI.INFO.comment{end+1} = ['Only one azimuth reading (' fields{i} ...
') before D.'];
end end
end
my_xlswrite(opsys,file_new,tmp',1,'C19'); tmpD=tmp;
clearvars tmp
my_xlswrite(opsys,file_new,tmp,1,'A13');
% Residuals clearvars tmp
tmp=num2cell(zeros(8,1));
dataflag=1;
my_xlswrite(opsys,file_new,tmp,1,'D19'); for i=1:length(fields)
clearvars tmp tmpval=DI.AZ.(fields{i}).I;
tmpval=floor(tmpval)+mod(tmpval,1)*0.6;
% ///////////////////////////////////////////////////////////////////// if isnan(tmpval)
% Write inclination readings tmpval=tmpD{2*i-1};
% ///////////////////////////////////////////////////////////////////// DI.INFO.comment{end+1} = ['No azimuth reading (' fields{i} ...
') before I.'];
fields={'NU' 'SD' 'ND' 'SU'}; dataflag=0;
% Time
for i=1:length(fields)
tmpval=DI.I.(fields{i}).time;
tmp{2*i-1} = tmpval;
tmp{2*i} = tmpval;
end end
tmp{2*i-1}=tmpval(1);
my_xlswrite(opsys,file_new,tmp',1,'B37'); if length(tmpval)>1 && ~isnan(tmpval(2))
clearvars tmp tmp{2*i}=tmpval(2);
else
% Readings tmp{2*i}=tmpval(1);
if dataflag
for i=1:length(fields) DI.INFO.comment{end+1} = ['Only one azimuth reading (' fields{i} ...
tmpval=DI.I.(fields{i}).val; ') before I.'];
tmpval=floor(tmpval)+mod(tmpval,1)*0.6; end
tmp{2*i-1} = tmpval;
tmp{2*i} = tmpval;
end end
end
my_xlswrite(opsys,file_new,tmp',1,'D37'); clearvars tmpval tmpvalD dataflag
clearvars tmp
my_xlswrite(opsys,file_new,tmp,1,'A31');
% Residuals clearvars tmp
tmp=num2cell(zeros(8,1));
% /////////////////////////////////////////////////////////////////////
my_xlswrite(opsys,file_new,tmp,1,'E37'); % Write declination readings
clearvars tmp % /////////////////////////////////////////////////////////////////////
% Meridian % Time
tmp{1}=mod(floor(DI.M)+mod(DI.M,1)*0.6,180);
my_xlswrite(opsys,file_new,tmp,1,'C37'); fields={'EU' 'WU' 'ED' 'WD'};
clearvars tmp
for i=1:length(fields)
tmpval=DI.D.(fields{i}).time;
tmp{2*i-1} = tmpval;
tmp{2*i} = tmpval;
end
my_xlswrite(opsys,file_new,tmp',1,'B19');
clearvars tmp
% Readings
for i=1:length(fields)
tmpval=DI.D.(fields{i}).val;
tmpval=floor(tmpval)+mod(tmpval,1)*0.6;
tmp{2*i-1} = tmpval;
tmp{2*i} = tmpval;
end
my_xlswrite(opsys,file_new,tmp',1,'C19');
clearvars tmp
% Residuals
tmp=num2cell(zeros(8,1));
my_xlswrite(opsys,file_new,tmp,1,'D19');
clearvars tmp
% /////////////////////////////////////////////////////////////////////
% Write inclination readings
% /////////////////////////////////////////////////////////////////////
fields={'NU' 'SD' 'ND' 'SU'};
% Time
for i=1:length(fields)
tmpval=DI.I.(fields{i}).time;
tmp{2*i-1} = tmpval;
tmp{2*i} = tmpval;
end
my_xlswrite(opsys,file_new,tmp',1,'B37');
clearvars tmp
% Readings
for i=1:length(fields)
tmpval=DI.I.(fields{i}).val;
tmpval=floor(tmpval)+mod(tmpval,1)*0.6;
tmp{2*i-1} = tmpval;
tmp{2*i} = tmpval;
end
my_xlswrite(opsys,file_new,tmp',1,'D37');
clearvars tmp
% Residuals
tmp=num2cell(zeros(8,1));
my_xlswrite(opsys,file_new,tmp,1,'E37');
clearvars tmp
% Meridian
tmp{1}=mod(floor(DI.M)+mod(DI.M,1)*0.6,180);
my_xlswrite(opsys,file_new,tmp,1,'C37');
clearvars tmp
% /////////////////////////////////////////////////////////////////////
% Write comment
% /////////////////////////////////////////////////////////////////////
for i=0:length(DI.INFO.comment)-1
my_xlswrite(opsys,file_new,DI.INFO.comment(i+1),1,...
[char(65+4*(mod(i,2))) num2str(floor((i)/2)+59)]);
end
end end
function num=pos_cell2num(cell) function num=pos_cell2num(cell)
......
% WRITTEN BY Achim Morschhauser, GFZ Potsdam, 30.05.2018 % WRITTEN BY Achim Morschhauser, GFZ Potsdam, 30.05.2018
function di_xls_converter_GAN(file_in,path_abs,del) function di_xls_converter_GAN(varargin)
% di_xls_converter Converts absolute measurement xls(x) files from GAN excel % di_xls_converter Converts absolute measurement xls(x) files from GAN excel
% file format to Juergen Matzka's (JM) format. % file format to Juergen Matzka's (JM) format.
% %
% Template of xls-file must be in same folder as the script %
% % INPUT:
% INPUT: % ------
% - file_in: TTB Excel file %
% - path_abs: Path to new abs. xlsx files % All input is defined as paramater-argument pair, e.g.
% This path should contain the following structure: % di_xls_converter('starttime','2018-01-01') for starttime='2018-01-01'.
% | %
% |-- 3 haracter station name + 1 digit number (e.g. wn0) % REQUIRED:
% |-- yr %
% - del: Overwrite existing files (1) or only give warning (0) % - path_abs char Path to absolute measurements.
% Folder DI_GAN_YYYY' will be created in this
% % directory.
% Operating-system dependent stuff %
% % OPTIONAL (default is given following double point):
opsys = computer; %
if strcmp(opsys(1:2), 'PC') == 1 % - file_in char GAN Excel file: 'tools/20180525.xlsx'
bs = '\'; % backslash %
elseif strcmp(opsys(1:2), 'GL') == 1 % - file_template char Excel template: 'tools/DI_GAN_template'
bs = '/'; % slash %
% Add library paths for use of xlwrite (write to xls(x) from linux) % - del numeric Overwrite existing files (1) or give
% javaaddpath(pwd); % warning (0): 0
% javaaddpath('lib/xlwrite/poi_library/poi-3.8-20120326.jar'); %
% javaaddpath('lib/xlwrite/poi_library/poi-ooxml-3.8-20120326.jar'); % - startdate YYYY-mm-dd First DI-measurement to process: 1800-01-01
% javaaddpath('lib/xlwrite/poi_library/poi-ooxml-schemas-3.8-20120326.jar'); %
% javaaddpath('lib/xlwrite/poi_library/xmlbeans-2.3.0.jar'); % - stopdate YYYY-mm-dd Last DI-measurement to process: today
% javaaddpath('lib/xlwrite/poi_library/dom4j-1.6.1.jar');
% javaaddpath('lib/xlwrite/poi_library/stax-api-1.0.1.jar'); %
else % Parse input arguments
display('operating system not recognised'); %
arg_specs.path_abs.required=1;
arg_specs.path_abs.type='char';
arg_specs.file_in.default='tools/20180525.xlsx';
arg_specs.file_in.type='char';
arg_specs.file_template.default='tools/DI_GAN_template.xls';
arg_specs.file_template.type='char';
arg_specs.del.default=0;
arg_specs.del.valid={0,1};
arg_specs.startdate.default='1800-01-01';
arg_specs.startdate.type='char';
arg_specs.startdate.dim2=10;
arg_specs.stopdate.default=datestr(date,'YYYY-mm-DD');
arg_specs.stopdate.type='char';
arg_specs.stopdate.dim2=10;
[arg_parsed, state]=parse_arg(arg_specs,varargin);
if (state.err == 1) % warning occurred, but no error
warning(state.wngmsg);
elseif (state.err == 2) % error occured, stop execution
error(state.errmsg);
end end
...@@ -43,20 +72,14 @@ end ...@@ -43,20 +72,14 @@ end
% Station name % Station name
station='GAN'; station='GAN';
% Path to script startdate=datenum(arg_parsed.startdate,'YYYY-mm-DD');
bin_path=fileparts(mfilename('fullpath')); stopdate=datenum(arg_parsed.stopdate,'YYYY-mm-DD');
% Path to abs. measurements
obspath=path_abs;
% Excel sheet dummy
file_template=[bin_path 'DI_GAN_template.xls'];
% %
% Read GAN xls-file % Read GAN xls-file
% %
[~,~,xls_in] = xlsread(file_in, 1); [~,~,xls_in] = xlsread(arg_parsed.file_in, 1);
% Search for first entry % Search for first entry
row=1; row=1;
...@@ -81,9 +104,6 @@ for row=row_start:size(xls_in,1) ...@@ -81,9 +104,6 @@ for row=row_start:size(xls_in,1)
% Read date % Read date
tmp = num2str(xls_in{row,1}); tmp = num2str(xls_in{row,1});
if (row==61)
disp('HELLO')
end
if any(isnan(tmp)) || length(tmp) ~= 8 if any(isnan(tmp)) || length(tmp) ~= 8
warning(['Problem with date on row ' num2str(row) ... warning(['Problem with date on row ' num2str(row) ...
', DI measurement was ignored.']); ', DI measurement was ignored.']);
...@@ -94,6 +114,12 @@ for row=row_start:size(xls_in,1) ...@@ -94,6 +114,12 @@ for row=row_start:size(xls_in,1)
DI.DATE.month = str2double(tmp(5:6)); DI.DATE.month = str2double(tmp(5:6));
DI.DATE.day = str2double(tmp(7:8)); DI.DATE.day = str2double(tmp(7:8));
% Check if should be read
if datenum(DI.DATE.yyyymmdd,'YYYYmmdd') < startdate || ...
datenum(DI.DATE.yyyymmdd,'YYYYmmdd') > stopdate
continue
end
% Read azimuth mark % Read azimuth mark
if strcmp(xls_in{row,2},'Light post') if strcmp(xls_in{row,2},'Light post')
...@@ -147,7 +173,11 @@ for row=row_start:size(xls_in,1) ...@@ -147,7 +173,11 @@ for row=row_start:size(xls_in,1)
DI.AZ.SD.I(1)=xls_in{row,37}+xls_in{row,38}/60; % Sensor down DI.AZ.SD.I(1)=xls_in{row,37}+xls_in{row,38}/60; % Sensor down
% Remarks % Remarks
DI.INFO.comment = xls_in{row,39}; if ~isnan(xls_in{row,39})
DI.INFO.comment{1} = xls_in{row,39};
else
DI.INFO.comment={};
end
% Observer % Observer
tmp=lower(xls_in{row,42}); tmp=lower(xls_in{row,42});
...@@ -180,6 +210,10 @@ for row=row_start:size(xls_in,1) ...@@ -180,6 +210,10 @@ for row=row_start:size(xls_in,1)
% Write DI measurements to xls-file % Write DI measurements to xls-file
% %
bs=backslash;
path_abs=[arg_parsed.path_abs bs 'DI_' upper(station) num2str(DI.DATE.year) bs];