function [time, tskin] = read_tskin(path,period)
%% Import data from text file.
% Script for importing data from the following text file:
%
%    C:\data\Main\MODFS\NCDC2015\CRNH0203-2015-AK_Utqiagvik_formerly_Barrow_4_ENE.txt
%
% To extend the code to different selected data or a different text file,
% generate a function instead of a script.

% Auto-generated by MATLAB on 2018/10/29 10:49:14

%% Initialize variables.
filename = [path 'CRNS0101-05-2018-AK_Utqiagvik_formerly_Barrow_4_ENE.txt'];

%% Read columns of data as text:
% For more information, see the TEXTSCAN documentation.
formatSpec = '%5s%9s%5s%9s%5s%7s%8s%8s%8s%8s%7s%2s%8s%2s%2s%s%s%s%s%s%s%s%s';

%% Open the text file.
fileID = fopen(filename,'r');

%% Read columns of data according to the format.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
fgetl(fileID)
dataArray = textscan(fileID, formatSpec, 'Delimiter', '', 'WhiteSpace', '', 'TextType', 'string',  'ReturnOnError', false);

%% Close the text file.
fclose(fileID);

time = datenum(dataArray{2},'yyyymmdd') + fix(str2num(char(dataArray{3}))/100)/24 + (str2num(char(dataArray{3}))-fix(str2num(char(dataArray{3}))/100)*100)/60/24;
tskin = str2num(char(dataArray{13}));
tskin_qc = str2num(char(dataArray{15}));
tskin(tskin_qc > 0) = NaN;

tskin(time < datenum(period(1,:)) | time > datenum(period(2,:))+ 1 - 5/24/60,:) = [];
time(time < datenum(period(1,:)) | time > datenum(period(2,:))+ 1 - 5/24/60,:) = [];

% convert
tskin = tskin + 273.15;