Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Achim Morschhauser
OBS_MAT
Commits
640cb8f4
Commit
640cb8f4
authored
Jun 01, 2018
by
Achim Morschhauser
Browse files
GAN di_xls_converter beta finished
parent
5e8a978f
Changes
6
Show whitespace changes
Inline
Side-by-side
lib/dday2hhmmss.m
View file @
640cb8f4
...
...
@@ -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
...
...
lib/my_xlswrite.m
View file @
640cb8f4
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
lib/write_DI_xls.m
View file @
640cb8f4
function
write_DI_xls
(
path
,
DI
,
file_template
,
del
)
% /////////////////////////////////////////////////////////////////////
% Create new xlsx-Files
% /////////////////////////////////////////////////////////////////////
% /////////////////////////////////////////////////////////////////////////
% 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 folders
if
(
~
exist
(
path
,
'dir'
));
mkdir
(
path_n
);
end
% /////////////////////////////////////////////////////////////////////
% Create new xlsx-Files
% /////////////////////////////////////////////////////////////////////
% Starttime on full minute
time
=
DI
.
D
.
WU
.
time
(
1
);
% Create folders
if
(
~
exist
(
path
,
'dir'
));
mkdir
(
path
);
end
% Create filename
file_new
=
[
path
bs
'DI_'
station
(
1
:
3
)
'_'
...
num2str
(
DI
.
DATE
.
yyyymmdd
)
num2str
(
DI
.
D
.
W
U
.
time
(
1
:
4
))
'.xls'
];
% Create filename
file_new
=
[
path
bs
'DI_'
DI
.
INFO
.
station
(
1
:
3
)
'_'
...
num2str
(
DI
.
DATE
.
yyyymmdd
)
num2str
(
DI
.
D
.
E
U
.
time
(
1
:
4
))
'.xls'
];
if
(
exist
(
file_new
,
'file'
)
==
2
)
if
(
exist
(
file_new
,
'file'
)
==
2
)
if
del
warning
([
'File '
file_new
' will be overwritten.'
]);
else
error
([
'File '
file_new
' already exists.'
]);
end
warning
([
'File '
file_new
' already exists.'
]);
return
;
end
end
% Copy file from template
copyfile
(
file_template
,
file_new
);
% Copy file from template
copyfile
(
file_template
,
file_new
);
% /////////////////////////////////////////////////////////////////////
% Write Info
% /////////////////////////////////////////////////////////////////////
% /////////////////////////////////////////////////////////////////////
% 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
]);
% 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
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'
;
% 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
my_xlswrite
(
opsys
,
file_new
,
tmp
,
1
,
'E8'
);
clearvars
tmp
% Pillar number
tmp
{
1
}
=
1
;
% Pillar number
tmp
{
1
}
=
1
;
my_xlswrite
(
opsys
,
file_new
,
tmp
,
1
,
'F13'
);
clearvars
tmp
my_xlswrite
(
opsys
,
file_new
,
tmp
,
1
,
'F13'
);
clearvars
tmp
% /////////////////////////////////////////////////////////////////////
% Write azimuth mark readings
% /////////////////////////////////////////////////////////////////////
% /////////////////////////////////////////////////////////////////////
% Write azimuth mark readings
% /////////////////////////////////////////////////////////////////////
% Sensor dn / Sensor up
% Sensor dn / Sensor up
fields
=
{
'SD'
'SU'
};
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
);
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
}
=
f
(
1
);
tmp
{
2
*
i
}
=
tmpval
(
1
);
DI
.
INFO
.
comment
{
end
+
1
}
=
[
'Only one azimuth reading ('
fields
{
i
}
...
') before D.'
];
end
end
my_xlswrite
(
opsys
,
file_new
,
tmp
,
1
,
'A31'
);
clearvars
tmp
end
tmpD
=
tmp
;
my_xlswrite
(
opsys
,
file_new
,
tmp
,
1
,
'A13'
);
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
);
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
tmp
{
2
*
i
-
1
}
=
tmpval
(
1
);
if
length
(
tmpval
)
>
1
&&
~
isnan
(
tmpval
(
2
))
tmp
{
2
*
i
}
=
tmpval
(
2
);
else
tmp
{
2
*
i
}
=
f
(
1
);
tmp
{
2
*
i
}
=
tmpval
(
1
);
if
dataflag
DI
.
INFO
.
comment
{
end
+
1
}
=
[
'Only one azimuth reading ('
fields
{
i
}
...
') before I.'
];
end
end
end
clearvars
tmpval
tmpvalD
dataflag
my_xlswrite
(
opsys
,
file_new
,
tmp
,
1
,
'A
1
3'
);
clearvars
tmp
my_xlswrite
(
opsys
,
file_new
,
tmp
,
1
,
'A3
1
'
);
clearvars
tmp
% /////////////////////////////////////////////////////////////////////
% Write declination readings
% /////////////////////////////////////////////////////////////////////
% /////////////////////////////////////////////////////////////////////
% Write declination readings
% /////////////////////////////////////////////////////////////////////
% Time
% Time
fields
=
{
'EU'
'WU'
'ED'
'WD'
};
fields
=
{
'EU'
'WU'
'ED'
'WD'
};
for
i
=
1
:
length
(
fields
)
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
end
% Readings
my_xlswrite
(
opsys
,
file_new
,
tmp
',1,'
B19
'
);
clearvars
tmp
fields
=
{
'WU'
'ED'
'WD'
'EU'
};
% Readings
for
i
=
1
:
length
(
fields
)
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
end
my_xlswrite
(
opsys
,
file_new
,
tmp
',1,'
C19
'
);
clearvars
tmp
my_xlswrite
(
opsys
,
file_new
,
tmp
',1,'
C19
'
);
clearvars
tmp
% Residuals
tmp
=
num2cell
(
zeros
(
8
,
1
));
% Residuals
tmp
=
num2cell
(
zeros
(
8
,
1
));
my_xlswrite
(
opsys
,
file_new
,
tmp
,
1
,
'D19'
);
clearvars
tmp
my_xlswrite
(
opsys
,
file_new
,
tmp
,
1
,
'D19'
);
clearvars
tmp
% /////////////////////////////////////////////////////////////////////
% Write inclination readings
% /////////////////////////////////////////////////////////////////////
% /////////////////////////////////////////////////////////////////////
% Write inclination readings
% /////////////////////////////////////////////////////////////////////
fields
=
{
'NU'
'SD'
'ND'
'SU'
};
fields
=
{
'NU'
'SD'
'ND'
'SU'
};
% Time
% Time
for
i
=
1
:
length
(
fields
)
for
i
=
1
:
length
(
fields
)
tmpval
=
DI
.
I
.
(
fields
{
i
})
.
time
;
tmp
{
2
*
i
-
1
}
=
tmpval
;
tmp
{
2
*
i
}
=
tmpval
;
end
end
my_xlswrite
(
opsys
,
file_new
,
tmp
',1,'
B37
'
);
clearvars
tmp
my_xlswrite
(
opsys
,
file_new
,
tmp
',1,'
B37
'
);
clearvars
tmp
% Readings
% Readings
for
i
=
1
:
length
(
fields
)
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
end
my_xlswrite
(
opsys
,
file_new
,
tmp
',1,'
D37
'
);
clearvars
tmp
my_xlswrite
(
opsys
,
file_new
,
tmp
',1,'
D37
'
);
clearvars
tmp
% Residuals
tmp
=
num2cell
(
zeros
(
8
,
1
));
% Residuals
tmp
=
num2cell
(
zeros
(
8
,
1
));
my_xlswrite
(
opsys
,
file_new
,
tmp
,
1
,
'E37'
);
clearvars
tmp
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
% 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
...
...
tools/DI_GAN_template.xls
View file @
640cb8f4
No preview for this file type
tools/TEST.xls
deleted
100644 → 0
View file @
5e8a978f
File deleted
tools/di_xls_converter_GAN.m
View file @
640cb8f4
% 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'
);
% ------
%
% 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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment