%% $RCSfile: sdspmtrnsp2.tlc,v $ %% $Revision: 1.2 $ %% $Date: 2000/06/15 20:37:47 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Matrix transpose %implements sdspmtrnsp2 "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 Transpose (%) - % */ %% %assign INPORT = 0 %assign OUTPORT = 0 %assign need_copy = (LibBlockInputSignalBufferDstPort(INPORT) != OUTPORT) %assign cplx = (LibBlockInputSignalIsComplex(INPORT) != 0) %assign dtype = cplx ? "creal_T" : "real_T" %assign hermit = cplx ? LibBlockParameterValue(Hermit,0) : 0 %assign numDims = LibBlockInputSignalNumDimensions(INPORT) %assign dims = LibBlockInputSignalDimensions(INPORT) %assign cols = (numDims == 2) ? dims[1] : 1 %assign rows = dims[0] %% %if need_copy %if cols == 1 || rows == 1 %% %% Vector input %% %assign rollVars = ["U","Y"] %roll sigIdx = RollRegions, lcv = RollThreshold, \ block, "Roller", rollVars %if !hermit %assign u = LibBlockInputSignal(INPORT, "", lcv, sigIdx) %assign y = LibBlockOutputSignal(OUTPORT, "", lcv, sigIdx) % = %; %else %assign u_re = LibBlockInputSignal(INPORT, "", lcv, "%%") %assign u_im = LibBlockInputSignal(INPORT, "", lcv, "%%") %assign y_re = LibBlockOutputSignal(OUTPORT, "", lcv, "%%") %assign y_im = LibBlockOutputSignal(OUTPORT, "", lcv, "%%") % = %; % = -%; %endif %endroll %else %% %% Matrix input %% %\ %% { /* * Transpose matrix: Walk the inputs in order down * the columns and write the outputs across the rows */ % *u = %; % *y = %; int_T j = %; while(j-- > 0) { % *yy = y++; int_T i = %; while(i-- > 0) { %if !hermit *yy = *u++; %else yy->re = u->re; yy->im = -(u++)->im; %endif yy += %; } } } %endif %else /* In-place algorithm for square matrices: */ %% %\ { % *y = %; const int_T cols = %; int_T i; for (i=0; i; j tmp = y[i*cols+j]; %if !hermit y[i*cols+j] = y[j*cols+i]; y[j*cols+i] = tmp; %else %% Complex hermitian: y[i*cols+j].re = y[j*cols+i].re; y[i*cols+j].im = -y[j*cols+i].im; y[j*cols+i].re = tmp.re; y[j*cols+i].im = -tmp.im; %endif } } } %endif %% need_copy %endfunction %% [EOF] sdspmtrnsp.tlc