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)
if isnumeric(dday)
% Hours
tmp=dday*24;
hhmmss=sprintf('%02u',floor(tmp));
hh=floor(dday*24);
% Minutes
tmp=(tmp-floor(tmp))*60;
hhmmss=[hhmmss sprintf('%02u',floor(tmp))];
mm=floor(mod(dday*24,1)*60);
% seconds
tmp=(tmp-floor(tmp))*60;
hhmmss=[hhmmss sprintf('%02u',floor(tmp))];
ss=round(mod(dday*24*60,1)*60);
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
......
function my_xlswrite(opsys,varargin)
function state=my_xlswrite(opsys,varargin)
% Call correct xls(x) writing routne - depending on O/S
if (opsys(1:2) == 'PC')
xlswrite(varargin{:})
state=xlswrite(varargin{:});
elseif (opsys(1:2) == 'GL')
xlwrite(varargin{:})
state=xlwrite(varargin{:});
end
end
\ No newline at end of file
function write_DI_xls(path,DI,file_template,del)
% /////////////////////////////////////////////////////////////////////
% Create new xlsx-Files
% /////////////////////////////////////////////////////////////////////
% Create folders
if (~exist(path,'dir')); mkdir(path_n); end
% Starttime on full minute
time = DI.D.WU.time(1);
% Create filename
file_new=[path bs 'DI_' station(1:3) '_' ...
num2str(DI.DATE.yyyymmdd) num2str(DI.D.WU.time(1:4)) '.xls'];
if (exist(file_new,'file')==2)
if del
warning(['File ' file_new ' will be overwritten.']);
else
error(['File ' file_new' already exists.']);
end
end
% Copy file from template
copyfile(file_template,file_new);
% /////////////////////////////////////////////////////////////////////
% Write Info
% /////////////////////////////////////////////////////////////////////
% Observatory station name
tmp{1}=DI.INFO.station;
% Year of abs. measurement
tmp{2}=DI.DATE.yyyymmdd(5:8);
% MMDD
tmp{3}=DI.DATE.yyyymmdd([3:4 1:2]);
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)
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;
% /////////////////////////////////////////////////////////////////////////
% Load libraries
% /////////////////////////////////////////////////////////////////////////
opsys = computer;
if strcmp(opsys(1:2), 'PC') == 1
bs = '\'; % backslash
elseif strcmp(opsys(1:2), 'GL') == 1
bs = '/'; % slash
javaaddpath('lib/xlwrite/poi_library/poi-3.8-20120326.jar');
javaaddpath('lib/xlwrite/poi_library/poi-ooxml-3.8-20120326.jar');
javaaddpath('lib/xlwrite/poi_library/poi-ooxml-schemas-3.8-20120326.jar');
javaaddpath('lib/xlwrite/poi_library/xmlbeans-2.3.0.jar');
javaaddpath('lib/xlwrite/poi_library/dom4j-1.6.1.jar');
javaaddpath('lib/xlwrite/poi_library/stax-api-1.0.1.jar');
else
display('operating system not recognised');
end
% /////////////////////////////////////////////////////////////////////
% Create new xlsx-Files
% /////////////////////////////////////////////////////////////////////
% Create folders
if (~exist(path,'dir')); mkdir(path); end
% Create filename
file_new=[path bs 'DI_' DI.INFO.station(1:3) '_' ...
num2str(DI.DATE.yyyymmdd) num2str(DI.D.EU.time(1:4)) '.xls'];
if (exist(file_new,'file')==2)
if del
warning(['File ' file_new ' will be overwritten.']);
else
warning(['File ' file_new ' already exists.']);
return;
end
my_xlswrite(opsys,file_new,tmp',1,'B19');
clearvars tmp
% Readings
fields={'WU' 'ED' 'WD' 'EU'};
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
% Copy file from template
copyfile(file_template,file_new);
% /////////////////////////////////////////////////////////////////////
% Write Info
% /////////////////////////////////////////////////////////////////////
% Observatory station name
tmp{1}=DI.INFO.station;
% Year of abs. measurement
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
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
tmpD=tmp;
my_xlswrite(opsys,file_new,tmp,1,'A13');
clearvars tmp
dataflag=1;
for i=1:length(fields)
tmpval=DI.AZ.(fields{i}).I;
tmpval=floor(tmpval)+mod(tmpval,1)*0.6;
if isnan(tmpval)
tmpval=tmpD{2*i-1};
DI.INFO.comment{end+1} = ['No azimuth reading (' fields{i} ...
') before I.'];
dataflag=0;
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;
tmp{2*i-1}=tmpval(1);
if length(tmpval)>1 && ~isnan(tmpval(2))
tmp{2*i}=tmpval(2);
else
tmp{2*i}=tmpval(1);
if dataflag
DI.INFO.comment{end+1} = ['Only one azimuth reading (' fields{i} ...
') before I.'];
end
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
end
clearvars tmpval tmpvalD dataflag
my_xlswrite(opsys,file_new,tmp,1,'A31');
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
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
function num=pos_cell2num(cell)
......
% 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
% file format to Juergen Matzka's (JM) format.
%
% Template of xls-file must be in same folder as the script
%
% INPUT:
% - file_in: TTB Excel file
% - path_abs: Path to new abs. xlsx files
% This path should contain the following structure:
% |
% |-- 3 haracter station name + 1 digit number (e.g. wn0)
% |-- yr
% - del: Overwrite existing files (1) or only give warning (0)
%
% Operating-system dependent stuff
%
opsys = computer;
if strcmp(opsys(1:2), 'PC') == 1
bs = '\'; % backslash
elseif strcmp(opsys(1:2), 'GL') == 1
bs = '/'; % slash
% Add library paths for use of xlwrite (write to xls(x) from linux)
% javaaddpath(pwd);
% javaaddpath('lib/xlwrite/poi_library/poi-3.8-20120326.jar');
% javaaddpath('lib/xlwrite/poi_library/poi-ooxml-3.8-20120326.jar');
% javaaddpath('lib/xlwrite/poi_library/poi-ooxml-schemas-3.8-20120326.jar');
% javaaddpath('lib/xlwrite/poi_library/xmlbeans-2.3.0.jar');
% javaaddpath('lib/xlwrite/poi_library/dom4j-1.6.1.jar');
% javaaddpath('lib/xlwrite/poi_library/stax-api-1.0.1.jar');
else
display('operating system not recognised');
%
% INPUT:
% ------
%
% All input is defined as paramater-argument pair, e.g.
% di_xls_converter('starttime','2018-01-01') for starttime='2018-01-01'.
%
% REQUIRED:
%
% - path_abs char Path to absolute measurements.
% Folder DI_GAN_YYYY' will be created in this
% directory.
%
% OPTIONAL (default is given following double point):
%
% - file_in char GAN Excel file: 'tools/20180525.xlsx'
%
% - file_template char Excel template: 'tools/DI_GAN_template'
%
% - del numeric Overwrite existing files (1) or give
% warning (0): 0
%
% - startdate YYYY-mm-dd First DI-measurement to process: 1800-01-01
%
% - stopdate YYYY-mm-dd Last DI-measurement to process: today
%
% Parse input arguments
%
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
......@@ -43,20 +72,14 @@ end
% Station name
station='GAN';
% Path to script
bin_path=fileparts(mfilename('fullpath'));
% Path to abs. measurements
obspath=path_abs;
% Excel sheet dummy
file_template=[bin_path 'DI_GAN_template.xls'];
startdate=datenum(arg_parsed.startdate,'YYYY-mm-DD');
stopdate=datenum(arg_parsed.stopdate,'YYYY-mm-DD');
%
% Read GAN xls-file
%
[~,~,xls_in] = xlsread(file_in, 1);
[~,~,xls_in] = xlsread(arg_parsed.file_in, 1);
% Search for first entry
row=1;
......@@ -81,9 +104,6 @@ for row=row_start:size(xls_in,1)
% Read date
tmp = num2str(xls_in{row,1});
if (row==61)
disp('HELLO')
end
if any(isnan(tmp)) || length(tmp) ~= 8
warning(['Problem with date on row ' num2str(row) ...
', DI measurement was ignored.']);
......@@ -94,6 +114,12 @@ for row=row_start:size(xls_in,1)
DI.DATE.month = str2double(tmp(5:6));
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
if strcmp(xls_in{row,2},'Light post')
......@@ -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
% 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
tmp=lower(xls_in{row,42});
......@@ -180,6 +210,10 @@ for row=row_start:size(xls_in,1)
% Write DI measurements to xls-file
%
bs=backslash;
path_abs=[arg_parsed.path_abs bs 'DI_' upper(station) num2str(DI.DATE.year) bs];
write_DI_xls(path_abs,DI,arg_parsed.file_template,arg_parsed.del);
%
% Clean up
......
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