function [HJC_location] = findhipcentre(fname,optim_type)
% read in trc file
mkr_data = dlmread(fname,'\t',6,2);

% get the thigh and sacrum markers from the coord data
RASI = mkr_data(:,1:3);
LASI = mkr_data(:,4:6);
SACR = mkr_data(:,7:9);
if optim_type == 'L_HJC'
    TH1 = mkr_data(:,37:39);
    TH2 = mkr_data(:,40:42);
    TH3 = mkr_data(:,43:45);
else
    TH1 = mkr_data(:,10:12);
    TH2 = mkr_data(:,13:15);
    TH3 = mkr_data(:,16:18);
end

% define the pelvis origin
originPelvis=(LASI+RASI)/2;

%calculate unit vectors of Pelvis segment relative to global
[e1Pelvis,e2Pelvis,e3Pelvis]=segmentorientationV1V3(originPelvis-SACR,RASI-LASI);

%now transform the marker points into the pelvis coordinate system
for i=1:length(e1Pelvis)
    rotationmatrix=[e1Pelvis(i,:);e2Pelvis(i,:);e3Pelvis(i,:)];
    originPelvisvector=originPelvis(i,:)';
    TH1Pelvis(i,:)=(rotationmatrix*(TH1(i,:)')-rotationmatrix*originPelvisvector)';
    TH2Pelvis(i,:)=(rotationmatrix*(TH2(i,:)')-rotationmatrix*originPelvisvector)';
    TH3Pelvis(i,:)=(rotationmatrix*(TH3(i,:)')-rotationmatrix*originPelvisvector)';
end

ThighMarkersInPelvisCS=[TH1Pelvis TH2Pelvis TH3Pelvis];
[HJC_location]=calc_HJC(ThighMarkersInPelvisCS);

