You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: optmagstr.m
    path of file: ./repos/spinw/swfiles/@spinw
    
    the code of the file until where you have to start completion: function optm = optmagstr(obj, varargin)
% general magnetic structure optimizer
% 
% ### Syntax
% 
% `optm = optmagstr(obj,Name,Value)`
% 
% ### Description
% 
% `optm = optmagstr(obj,Name,Value)` is a general magnetic structure
% optimizer that as the name suggests is general however usually less
% efficient than [spinw.optmagk] or [spinw.optmagsteep]. However this
% function enables the usage of constraint functions to improve the
% optimization. This function is most usefull i
    
function by
% giving the name of the parameter. For parameter names see the help of the
% used constraint function. Limits per optimization parameter can be given
% in the following format: `optmagstr('ParName',[min max],...)`. For example
% to fix the `nTheta` value of [gm_planar] during the optimisation to zero
% use: `optmagstr(obj,'func',@gm_planar,'nTheta',[0 0])`.
%
% 
% #### Optimisation parameters
% 
% The optimization parameters are identical to the input options of the
% Matlab built-in optimizer [matlab.fminsearch].
%
% `'tolx'`
% : Minimum change of `x` when convergence reached, default
%     value is $10^{-4}$.
% 
% `'tolfun'`
% : Minimum change of the $R$ value when convergence reached,
%     default value is $10^{-5}$.
% 
% `'maxfunevals'`
% : Maximum number of function evaluations, default value
%     is $10^7$.
% 
% `'maxiter'`
% : Maximum number of iterations, default value is $10^4$.
% 
% ### Output Arguments
% 
% `optm`
% : Struct type variable with the following fields:
%   * `obj`       spinw object that contains the optimised magnetic structure.
%   * `x`         Optimised paramters in a row vector with $n_{par}$ number
%                 of elements.
%   * `fname`     Name of the contraint function.
%   * `xname`     Cell containing the name of the $x$ parameters with
%                   $n_{par}$ elements.
%   * `e`         Energy per spin in the optimised structure.
%   * `exitflag`  Exit flag of the optimisation code, see [matlab.fminsearch].
%   * `output`    Detailed output of the optimisation code, see [matlab.fminsearch].
%   * `param`     Input parameters, stored in a struct.
% 
% ### See Also
% 
% [spinw] \| [spinw.anneal] \| [gm_spherical3d] \| [gm_planar] \| [fminsearch]
%

if ~any(obj.atom.mag)
    error('spinw:optmagstr:NoMagAtom','There is no magnetic atom in the unit cell with S>0!');
end

% save the time of the beginning of the calculation
if nargout > 0
    optm.datestart  = datestr(now);
end