%
% DESCRIPTION: Program to create the Drillhole lithology GDF file in the Matlab format.
% 
% [TimeZone] and [Description] have text format so the values give in ''


clear;clc;
[FormatName] = 'GDF';
[FormatVersion] = 2.1;
[CRS] = 'EPSG:4326';%['EPSG:' num2str(input('[CRS] EPSG code (just number) = '))];
[TimeZone] = 'UTC' %input('TimeZone (char) = ');
[Description] = 'Description of dataset'; %input('Description of data (char) = ');
         
[FieldDescription] = {
    'Name','Name of collar drillhole'
    'Length_from','Start length position'
    'Length_to','End length position'
    'Lithology','Lithology at specified pipe length'
    'Lat','Latitude of collar drillhole'
    'Long','Longitude of collar drillhole'
    'Elevation','Elevation of collar drillhole'
    };
[FieldType] = {
    'Name',3
    'Length_from',4
    'Length_to',4
    'Lithology',3
    'Lat',4
    'Long',4
    'Elevation',4
    };
[FieldUnit] = {
    'Name','char'
    'Length_from','m'
    'Length_to','m'
    'Lithology','char'
    'Lat','deg'
    'Long','deg'
    'Elevation','m'
    };

[d] = struct();

[Na, La, Lo, El] = textread('input_data_lithology_info.txt','%s %f %f %f','delimiter',';','headerlines',1);

[Na2, Lf, Lt, Lh] = textread('input_data_lithology.txt','%s %f %f %s ','delimiter',';','headerlines',1);

for k=1:length(Na)
    d(k).Name = Na{k,1};
    d(k).Length_from = Lf(strcmp(Na2,Na{k,1}));
    d(k).Length_to = Lt(strcmp(Na2,Na{k,1}));
    d(k).Lithology = Lh(strcmp(Na2,Na{k,1}));
    d(k).Lat = La(k,1);
    d(k).Long = Lo(k,1);
    d(k).Elevation = El(k,1);
    
     display([Na{k,1} ' - done'])
end

clear k Na La Lo El Na2 Lf Lt Lh

save('GDF_EpisodeName_Drillhole_lithology_example.mat')
