function out = seismic_ch15_nonbuilding(W, SDS, SD1, R, Ie, Omega0, hcg, B, n_bolts, unitType)
% seismic_ch15_nonbuilding
%
% ASCE 7-22 Chapter 15 seismic design for a rigid non-building structure
% (equipment on grade: z = 0, T taken as 0 so Cs = SDS*Ie/R controls).
%
% This function handles equipment such as the Deployment Module example:
% a single rigid body on a concrete pad, governed by Chapter 15, not
% Chapter 13.  The shear-building ELF tab in the GUI requires story
% mass/stiffness inputs, which are not meaningful for a rigid block.
% Use this function directly for that case.
%
% INPUTS
%   W        - Operating weight (lbf for English, N for metric)
%   SDS      - Design spectral acceleration, short period (g)
%   SD1      - Design spectral acceleration, 1-second (g)
%   R        - Response modification factor (Table 15.4-2)
%   Ie       - Seismic importance factor
%   Omega0   - Overstrength factor (Table 15.4-2)
%   hcg      - Height of center of gravity above base plate
%                English: inches | Metric: mm
%   B        - Base plate half-width (bolt half-spacing for overturning)
%                English: inches | Metric: mm
%   n_bolts  - Total number of anchor bolts in base plate
%   unitType - 'english' or 'metric'
%
% OUTPUTS (struct)
%   out.Cs          - Governing seismic coefficient
%   out.Cs_basic    - SDS*Ie/R
%   out.Cs_min      - max(0.044*SDS*Ie, 0.01)
%   out.Eh          - Horizontal seismic force (lbf or N)
%   out.Ev          - Vertical seismic load effect (lbf or N)
%   out.MOT         - Overturning moment (lbf-in or N-mm)
%   out.MR          - Restoring moment, LC4 (lbf-in or N-mm)
%   out.Va          - Shear per anchor bolt (lbf or N)
%   out.Em_plus     - Amplified seismic force, additive (lbf or N)
%   out.Em_minus    - Amplified seismic force, subtractive (lbf or N)

arguments
    W        (1,1) double {mustBePositive}
    SDS      (1,1) double {mustBePositive}
    SD1      (1,1) double {mustBePositive}
    R        (1,1) double {mustBePositive}
    Ie       (1,1) double {mustBePositive}
    Omega0   (1,1) double {mustBePositive}
    hcg      (1,1) double {mustBePositive}
    B        (1,1) double {mustBePositive}
    n_bolts  (1,1) double {mustBePositive}
    unitType (1,:) char   {mustBeMember(unitType,{'english','metric'})} = 'english'
end

% ----------------------------------------------------------------
% Cs — rigid structure at grade: T = 0, so plateau governs
% ----------------------------------------------------------------
Cs_basic = SDS * Ie / R;

Cs_min1  = 0.044 * SDS * Ie;
Cs_min2  = 0.01;
Cs_min   = max(Cs_min1, Cs_min2);

Cs = max(Cs_basic, Cs_min);

% ----------------------------------------------------------------
% Horizontal seismic force  Eh = Cs * W  (ASCE 7-22 §15.4.1)
% ----------------------------------------------------------------
Eh = Cs * W;

% ----------------------------------------------------------------
% Vertical seismic load effect  Ev = 0.2 * SDS * W
% (ASCE 7-22 §12.4.2.2 — applies at all SDC B–F)
% ----------------------------------------------------------------
Ev = 0.2 * SDS * W;

% ----------------------------------------------------------------
% Overturning moment  MOT = Eh * hcg  (LC3 / LC4)
% ----------------------------------------------------------------
MOT = Eh * hcg;

% ----------------------------------------------------------------
% Restoring moment  MR = (0.9 − 0.2*SDS) * W * B   (LC4, worst case)
% LC4: (0.9 − 0.2*SDS)*D + Eh  — minimises restoring moment
% ----------------------------------------------------------------
MR = (0.9 - 0.2*SDS) * W * B;

% ----------------------------------------------------------------
% Anchor shear  Va = Eh / n_bolts  (uniform distribution)
% ----------------------------------------------------------------
Va = Eh / n_bolts;

% ----------------------------------------------------------------
% Amplified seismic force Em (ASCE 7-22 §12.4.3)
%   Em_plus  = Omega0 * Eh + Ev   (LC5: compressive case)
%   Em_minus = Omega0 * Eh - Ev   (LC6: tension case)
% ----------------------------------------------------------------
Em_plus  = Omega0 * Eh + Ev;
Em_minus = Omega0 * Eh - Ev;

% ----------------------------------------------------------------
% Package outputs
% ----------------------------------------------------------------
out = struct();
out.W        = W;
out.SDS      = SDS;
out.SD1      = SD1;
out.R        = R;
out.Ie       = Ie;
out.Omega0   = Omega0;
out.Cs_basic = Cs_basic;
out.Cs_min   = Cs_min;
out.Cs       = Cs;
out.Eh       = Eh;
out.Ev       = Ev;
out.MOT      = MOT;
out.MR       = MR;
out.Va       = Va;
out.Em_plus  = Em_plus;
out.Em_minus = Em_minus;
out.unitType = unitType;

% ----------------------------------------------------------------
% Print summary
% ----------------------------------------------------------------
if strcmpi(unitType,'english')
    fu  = 'lbf';
    mu  = 'lbf-in';
else
    fu  = 'N';
    mu  = 'N-mm';
end

fprintf('\n========================================================\n');
fprintf('  ASCE 7-22 Chapter 15 — Rigid Non-Building Structure\n');
fprintf('========================================================\n');
fprintf('  W        = %.1f %s\n', W,  fu);
fprintf('  SDS      = %.3f g\n',  SDS);
fprintf('  SD1      = %.3f g\n',  SD1);
fprintf('  R        = %.1f\n',    R);
fprintf('  Ie       = %.1f\n',    Ie);
fprintf('  Omega0   = %.1f\n',    Omega0);
fprintf('--------------------------------------------------------\n');
fprintf('  Cs (basic = SDS*Ie/R) = %.3f g\n', Cs_basic);
fprintf('  Cs_min  = max(0.044*SDS*Ie, 0.01) = %.4f g\n', Cs_min);
fprintf('  Cs (governing)         = %.3f g\n', Cs);
fprintf('--------------------------------------------------------\n');
fprintf('  Eh  = Cs * W             = %.1f %s\n',  Eh,  fu);
fprintf('  Ev  = 0.2*SDS*W          = %.1f %s\n',  Ev,  fu);
fprintf('  MOT = Eh * hcg           = %.0f %s\n',  MOT, mu);
fprintf('  MR  = (0.9-0.2*SDS)*W*B  = %.0f %s\n',  MR,  mu);
fprintf('  Va  = Eh / n_bolts       = %.1f %s/bolt\n', Va, fu);
fprintf('  Em+ = Omega0*Eh + Ev     = %.1f %s\n',  Em_plus,  fu);
fprintf('  Em- = Omega0*Eh - Ev     = %.1f %s\n',  Em_minus, fu);
if MOT < MR
    fprintf('  Overturning check: MOT < MR  OK (no net uplift)\n');
else
    fprintf('  Overturning check: MOT > MR  UPLIFT — anchor tension required\n');
end
fprintf('========================================================\n\n');

end
