%% $RCSfile: sdspsrt.tlc,v $ %% $Revision: 1.7 $ %% $Date: 2000/06/15 20:37:50 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Sort the input vector %implements sdspsrt "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: BlockInstanceSetup =============================================== %% %function BlockInstanceSetup(block, system) void %% %assign INPORT = 0 %assign width = LibDataInputPortWidth(INPORT) % % % %endfunction %% BlockInstanceSetup %% Function: InitializeConditions ============================================= %% %function InitializeConditions(block, system) Output /* DSP Blockset Sort (%) - % */ %% %assign INPORT = 0 %assign width = LibDataInputPortWidth(INPORT) %% { int_T i; for (i=0; i < %; i++) { % = i; } } %endfunction %% InitializeConditions %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Sort (%) - % */ %% %assign direction = LibBlockParameterValue(Direction,0) %assign out_type = LibBlockParameterValue(Output_Type,0) %% %assign Ascend = 1 %assign Descend = 2 %% %assign outVal_and_Idx = 1 %assign outVal = 2 %assign outIdx = 3 %% %assign INPORT = 0 %assign OUTPORT_VAL = 0 %assign OUTPORT_IDX = (out_type == outIdx) ? 0 : 1 %% %assign cplx = (LibBlockInputSignalIsComplex(INPORT) != 0) %assign contig = IsInputPortContiguous(block, INPORT) %assign N = LibDataInputPortWidth(INPORT) %assign dtype = cplx ? "creal_T" : "real_T" %% %assign index = LibBlockIWork(Index, "", "", 0) %% %if !contig % %else %if N != 1 %if !cplx %% %% REAL %% /* Sort input vector: */ qid_RecSort(%, &%, 0, %); %else %% %% COMPLEX %% { /* Copy magnitude of complex input values into temp scratch area: */ real_T *sort_in = (real_T *)%; %assign rollVars = ["U"] %roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars *sort_in++ = CMAGSQ(%); %endroll /* Sort input vector: */ qid_RecSort(sort_in - %, &%, 0, %); } %endif %endif %endif %% %% The only difference between outputting in ascending order and %% outputting in descending order is the for loop construct. %% %if direction==Ascend %% %assign LoopStart = "i = 0" %assign LoopTest = "i < %" %assign LoopEnd = "i++" %else %% Descend %% %assign LoopStart = "i = %" %assign LoopTest = "i >= 0" %assign LoopEnd = "i--" %endif %% { int_T *index = &%; %if out_type != outIdx { /* Output the sorted values: */ % *y = %; % *u = %; int i; for(%; %; %) { *y++ = u[index[i]]; } } %endif %% %if out_type != outVal { /* Output the sorted indices:*/ real_T *y = %; int i; for (%; %; %) { *y++ = (real_T)(index[i]+1); /* Convert to MATLAB 1-based indexing */ } } %endif } %endfunction %% [EOF] sdspsrt.tlc