%% $RCSfile: sdspsrt2.tlc,v $ %% $Revision: 1.2 $ %% $Date: 2000/06/15 20:37:50 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Sort the input vector %implements sdspsrt2 "C" %%============================================================================ %openfile buffer %% /* DSP Blockset Median Block dependencies: */ extern void qid_RecSort(const real_T *qid_array, int_T *qid_index, int_T i, int_T j); %closefile buffer % %%============================================================================ %% Function: InitializeConditions ============================================= %% %function InitializeConditions(block, system) Output /* DSP Blockset Sort (%) - % */ %% %assign INPORT_DATA = 0 %assign width = LibBlockInputSignalWidth(INPORT_DATA) %assign numDims = LibBlockInputSignalNumDimensions(INPORT_DATA) %assign dims = LibBlockInputSignalDimensions(INPORT_DATA) %% %assign isFullMatrix = LibBlockInputSignalIsFullMatrix(INPORT_DATA) %assign frame = LibBlockInputSignalIsFrameData(INPORT_DATA) %assign nChans = (frame || isFullMatrix) ? dims[1] : 1 %assign nSamps = (frame || isFullMatrix) ? dims[0] : width %% { int32_T *index = %; int_T i; for (i=0; i < %; i++) { int j; for (j=0; j < %; j++) { *index++ = j; } } } %endfunction %% InitializeConditions %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Sort (%) - % */ %% %assign direction = CAST("Number",SFcnParamSettings.Direction) %assign out_type = CAST("Number",SFcnParamSettings.Output_Type) %% %assign Ascend = 1 %assign Descend = 2 %% %assign outVal_and_Idx = 1 %assign outVal = 2 %assign outIdx = 3 %% %assign INPORT_DATA = 0 %assign OUTPORT_DATA = 0 %assign OUTPORT_IDX = (out_type == outIdx) ? 0 : 1 %% %assign cplx = (LibBlockInputSignalIsComplex(INPORT_DATA) != 0) %assign dtype = cplx ? "creal_T" : "real_T" %% %assign width = LibBlockInputSignalWidth(INPORT_DATA) %assign numDims = LibBlockInputSignalNumDimensions(INPORT_DATA) %assign dims = LibBlockInputSignalDimensions(INPORT_DATA) %% %assign isFullMatrix = LibBlockInputSignalIsFullMatrix(INPORT_DATA) %assign frame = LibBlockInputSignalIsFrameData(INPORT_DATA) %assign nChans = (frame || isFullMatrix) ? dims[1] : 1 %assign nSamps = (frame || isFullMatrix) ? dims[0] : width %% %if width != 1 { const %*u = %; real_T *sort_in = (real_T *)%; int32_T *index = %; int_T i; for(i=0; i<%; i++) { int j; for(j=0;j<%;j++) { %if cplx sort_in[j] = CMAGSQ(*u); u++; %else sort_in[j] = *u++; %endif } /* Sort input values */ qid_RecSort(sort_in, index, 0, %-1); sort_in += %; index += %; } } %endif %% %% The only difference between outputting in ascending order and %% outputting in descending order is the for loop construct. %% %assign ChanLoopStart = "i = 0" %assign ChanLoopTest = "i < %" %assign ChanLoopEnd = "i++" %% %if direction==Ascend %% %assign nSampLoopStart = "j = 0" %assign nSampLoopTest = "j < %" %assign nSampLoopEnd = "j++" %else %% Descend %% %assign nSampLoopStart = "j = %" %assign nSampLoopTest = "j >= 0" %assign nSampLoopEnd = "j--" %endif %% { int32_T *index = %; %if out_type != outIdx { /* Output the sorted values: */ % *y = %; % *u = %; int i; for(%; %; %) { int j; for(%; %; %) { *y++ = u[index[j]]; } u += %; index += %; } %if (out_type == outVal_and_Idx) index -= %; %endif } %endif %% %if out_type != outVal { /* Output the sorted indices */ real_T *y1 = %; int i; for(%; %; %) { int j; for(%; %; %) { *y1++ = (real_T)(index[j]+1); /* Convert to MATLAB 1-based indexing */ } index += %; } } %endif } %endfunction %% [EOF] sdspsrt2.tlc