function  J  = J_calc_bifilar( m , g, D, L, t, n , varargin)
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here

average_strings = {'average','mean','ave'}; 
least_squares_strings = {'least squares','ls'}; 

mode = 0; 
if ~isempty(varargin)
    for k = 1:length(varargin)
        if any(strcmpi(varargin{k},average_strings))
            mode = 0; 
        end
        if any(strcmpi(varargin{k},least_squares_strings))
            mode = 1; 
        end
    end
end

if mode == 0 %averge
        N = length(t); 
        Js = zeros(1,N); 
        for k = 1:N
            Js(k) = m(k)*g*D(k)^2/(16*pi^2*L(k))*(t(k)/n(k))^2; 
        end        
        J = mean(Js); 
end

if mode == 1 %least squares
    J = (16*pi^2*L./(m*g.*D.^2))\(t./n).^2 ; 
end



end

