%% $RCSfile: sdspdiag.tlc,v $ %% $Revision: 1.8 $ %% $Date: 2000/06/15 20:37:39 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Create a matrix from a diagonal or extract the diag from a matrix. %implements sdspdiag "C" %% Function: BlockInstanceSetup =============================================== %% %% Abstract: %% Rename the S-Function parameter for easy reference. %% %function BlockInstanceSetup(block, system) void %% % % %% %endfunction %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Matrix Diagonal (%) - % */ %% %assign Diag2Full = 1 %assign Full2Diag = 2 %% %assign INPORT = 0 %assign OUTPORT = 0 %assign mode = LibBlockParameterValue(Mode,0) %assign a_width = CAST("Number",LibDataInputPortWidth(0)) %assign o_width = CAST("Number",LibDataOutputPortWidth(0)) %assign cplx = LibBlockInputSignalIsComplex(INPORT) != 0 %assign dtype = cplx ? "creal_T" : "real_T" %assign need_copy = (LibBlockInputSignalBufferDstPort(INPORT) != OUTPORT) %% %if need_copy %% %if !IsInputPortContiguous(block,INPORT) % %endif { % *A = %; % *y = %; %if mode == Diag2Full /* Diag2Full */ int_T nc = 0; while (nc++ < %) { int_T nr = 0; while (nr++ < %) { %if !cplx *y++ = (nr == nc) ? *A++ : 0.0; %else if(nr == nc) { *y++ = *A++; } else { y->re = 0.0; (y++)->im = 0.0; } %endif } } %elseif mode == Full2Diag %assign cols = CAST("Number",LibBlockParameterValue(Cols,0)) %if cols == -1 %assign rows = o_width %assign Nmin = rows %else %assign rows = a_width/cols %if rows < cols %assign Nmin = rows %else %assign Nmin = cols %endif %endif /* Full2Diag */ int_T i = %; while (i-- > 0) { *y++ = *A; A += %; } %endif } %else %% /* Scalar output equals input. No code needed. */ %% %endif %endfunction %% [EOF] sdspdiag.tlc