// // time: Wed Apr 24 07:51:31 1996 // // version: 3.0.0 (format), 3.1.0 (DX) // // // Begin MDF // MODULE FindPositionWithLargestData // CATEGORY Macros // DESCRIPTION returns the position which is associated with the largest data value // INPUT data; scalar list or field; (none); data field // INPUT largest; flag; (1); Extract positions of largest (1) or smallest (0) data values // OUTPUT position; value list or string list; position with largest data value // OUTPUT data; value list or string list; largest data value // End MDF // // comment: This macro, given a data field, extracts the position(s) associated with the largest (or smallest) data value(s). // comment: // comment: If you know that only *one* position has the extreme data value, this macro could be simplified a great deal, removing all the get and set pairs and simply outputing the outputs of the two Selects near the left side of the macro, with the which parameter of the Selects set to 0. // comment: // comment: Sort is used to first sort the data field by data field, in either descending or ascending order. Thus the extreme data values are all near the beginning of the data component. The associated positions are of course also now at the beginning of the positions component. // comment: // comment: There are several Get/Set pairs in this macro. One holds a counter for selecting from the data and positions components. Another holds the last data value, for comparison with the current value. This will control the termination of the macro. Another two Get and Set pairs are used to create the list of data values and list of positions, for the situation when there is more than one extreme data value. // comment: // comment: (C) COPYRIGHT International Business Machines Corp. 1996. // comment: All Rights Reserved. // comment: Licensed Materials - Property of IBM // comment: // comment: Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of IBM not be used in advertising or publicity pertaining to distribution of the software without specific prior written permission. // comment: // comment: INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THE SOFTWARE, BOTH INDIVIDUALLY AND AS ONE OR MORE GROUPS, "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IBM DOES NOT WARRANT AGAINST THE INFRINGMENT OF PATENTS, COPYRIGHT OR ANY OTHER INTELLECTUAL PROPERTY RIGHTS OF OTHERS. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE, BOTH INDIVIDUALLY AND AS ONE OR MORE GROUPS, IS WITH YOU. // workspace: width = 910, height = 801 // layout: snap = 0, width = 50, height = 50, align = NN // macro FindPositionWithLargestData( data ,largest ) -> ( position ,data ) { // // node First[1]: x = 331, y = 21, inputs = 0, label = First // FindPositionWithLargestData_First_1_out_1 = First( ) [instance: 1, cache: 1]; // // node Transmitter[2]: x = 338, y = 95, inputs = 1, label = first // first = FindPositionWithLargestData_First_1_out_1; // // node Receiver[4]: x = 442, y = 414, inputs = 1, label = first // FindPositionWithLargestData_Receiver_4_out_1 = first; // // node Get[3]: x = 214, y = 494, inputs = 3, label = Get // FindPositionWithLargestData_Get_3_out_1, FindPositionWithLargestData_Get_3_out_2 = Get( NULL, FindPositionWithLargestData_Receiver_4_out_1, NULL ) [instance: 3, cache: 1]; // // node Input[1]: x = 137, y = 22, inputs = 0, label = Input // parameter: position = 1, name = 'data', value = ' ', descriptive = 0, description = 'data field', required = 1, visible = 1 // FindPositionWithLargestData_Input_1_out_1 = data; // // node Input[2]: x = 227, y = 30, inputs = 0, label = Input // parameter: position = 2, name = 'largest', value = '(1)', descriptive = 1, description = 'Extract positions of largest (1) or smallest (0) data values', required = 0, visible = 1 // FindPositionWithLargestData_Input_2_out_1 = largest; // // node Sort[1]: x = 182, y = 112, inputs = 2, label = Sort // input[2]: defaulting = 1, visible = 1, type = 3, value = 1 // FindPositionWithLargestData_Sort_1_out_1 = Sort( FindPositionWithLargestData_Input_1_out_1, FindPositionWithLargestData_Input_2_out_1 ) [instance: 1, cache: 1]; // // node Extract[2]: x = 204, y = 211, inputs = 2, label = Extract // FindPositionWithLargestData_Extract_2_out_1 = Extract( FindPositionWithLargestData_Sort_1_out_1, NULL ) [instance: 2, cache: 1]; // // node Receiver[2]: x = 489, y = 6, inputs = 1, label = first // FindPositionWithLargestData_Receiver_2_out_1 = first; // // node Get[2]: x = 491, y = 79, inputs = 3, label = Get // input[1]: defaulting = 0, visible = 1, type = 67108863, value = 0 // FindPositionWithLargestData_Get_2_out_1, FindPositionWithLargestData_Get_2_out_2 = Get( 0, FindPositionWithLargestData_Receiver_2_out_1, NULL ) [instance: 2, cache: 1]; // // node Transmitter[1]: x = 422, y = 251, inputs = 1, label = select_which // select_which = FindPositionWithLargestData_Get_2_out_1; // // node Receiver[1]: x = 14, y = 261, inputs = 1, label = select_which // FindPositionWithLargestData_Receiver_1_out_1 = select_which; // // node Select[2]: x = 221, y = 335, inputs = 3, label = Select // FindPositionWithLargestData_Select_2_out_1 = Select( FindPositionWithLargestData_Extract_2_out_1, FindPositionWithLargestData_Receiver_1_out_1, NULL ) [instance: 2, cache: 1]; // // node Transmitter[3]: x = 170, y = 413, inputs = 1, label = data_val // data_val = FindPositionWithLargestData_Select_2_out_1; // // node Receiver[5]: x = 683, y = 55, inputs = 1, label = data_val // FindPositionWithLargestData_Receiver_5_out_1 = data_val; // // node Select[3]: x = 290, y = 286, inputs = 3, label = Select // FindPositionWithLargestData_Select_3_out_1 = Select( FindPositionWithLargestData_Extract_2_out_1, NULL, NULL ) [instance: 3, cache: 1]; // // node Transmitter[4]: x = 306, y = 364, inputs = 1, label = first_data // first_data = FindPositionWithLargestData_Select_3_out_1; // // node Receiver[6]: x = 764, y = 13, inputs = 1, label = first_data // FindPositionWithLargestData_Receiver_6_out_1 = first_data; // // node Receiver[3]: x = 863, y = 10, inputs = 1, label = first // FindPositionWithLargestData_Receiver_3_out_1 = first; // // node Get[1]: x = 821, y = 102, inputs = 3, label = Get // FindPositionWithLargestData_Get_1_out_1, FindPositionWithLargestData_Get_1_out_2 = Get( FindPositionWithLargestData_Receiver_6_out_1, FindPositionWithLargestData_Receiver_3_out_1, NULL ) [instance: 1, cache: 1]; // // node Compute[1]: x = 663, y = 142, inputs = 3, label = Compute // input[1]: defaulting = 0, visible = 0, type = 32, value = "$0 == $1 ? 0 : 1" // expression: value = data_val == last_val ? 0 : 1 // name[2]: value = data_val // name[3]: value = last_val // FindPositionWithLargestData_Compute_1_out_1 = Compute( "$0 == $1 ? 0 : 1", FindPositionWithLargestData_Receiver_5_out_1, FindPositionWithLargestData_Get_1_out_1 ) [instance: 1, cache: 1]; // // node Transmitter[5]: x = 682, y = 252, inputs = 1, label = not_the_same // not_the_same = FindPositionWithLargestData_Compute_1_out_1; // // node Receiver[7]: x = 0, y = 432, inputs = 1, label = not_the_same // FindPositionWithLargestData_Receiver_7_out_1 = not_the_same; // // node Compute[3]: x = 5, y = 510, inputs = 2, label = Compute // input[1]: defaulting = 0, visible = 0, type = 32, value = "$0+1" // expression: value = a+1 // name[2]: value = a // FindPositionWithLargestData_Compute_3_out_1 = Compute( "$0+1", FindPositionWithLargestData_Receiver_7_out_1 ) [instance: 3, cache: 1]; // // node Extract[1]: x = 119, y = 208, inputs = 2, label = Extract // input[2]: defaulting = 0, visible = 1, type = 32, value = "positions" // FindPositionWithLargestData_Extract_1_out_1 = Extract( FindPositionWithLargestData_Sort_1_out_1, "positions" ) [instance: 1, cache: 1]; // // node Select[1]: x = 129, y = 333, inputs = 3, label = Select // FindPositionWithLargestData_Select_1_out_1 = Select( FindPositionWithLargestData_Extract_1_out_1, FindPositionWithLargestData_Receiver_1_out_1, NULL ) [instance: 1, cache: 1]; // // node Switch[1]: x = 24, y = 601, inputs = 3, label = Switch // FindPositionWithLargestData_Switch_1_out_1 = Switch( FindPositionWithLargestData_Compute_3_out_1, FindPositionWithLargestData_Select_1_out_1, NULL ) [instance: 1, cache: 1]; // // node List[1]: x = 132, y = 652, inputs = 2, label = List // FindPositionWithLargestData_List_1_out_1 = List( FindPositionWithLargestData_Get_3_out_1, FindPositionWithLargestData_Switch_1_out_1 ) [instance: 1, cache: 1]; // // node Output[1]: x = 172, y = 727, inputs = 1, label = Output // parameter: position = 1, name = 'position', value = ' ', descriptive = 0, description = 'position with largest data value', required = 0, visible = 1 // position = FindPositionWithLargestData_List_1_out_1; // // node Get[4]: x = 402, y = 499, inputs = 3, label = Get // FindPositionWithLargestData_Get_4_out_1, FindPositionWithLargestData_Get_4_out_2 = Get( NULL, FindPositionWithLargestData_Receiver_4_out_1, NULL ) [instance: 4, cache: 1]; // // node Switch[2]: x = 297, y = 635, inputs = 3, label = Switch // FindPositionWithLargestData_Switch_2_out_1 = Switch( FindPositionWithLargestData_Compute_3_out_1, FindPositionWithLargestData_Select_2_out_1, NULL ) [instance: 2, cache: 1]; // // node List[2]: x = 392, y = 643, inputs = 2, label = List // FindPositionWithLargestData_List_2_out_1 = List( FindPositionWithLargestData_Get_4_out_1, FindPositionWithLargestData_Switch_2_out_1 ) [instance: 2, cache: 1]; // // node Output[2]: x = 391, y = 738, inputs = 1, label = Output // parameter: position = 2, name = 'data', value = ' ', descriptive = 0, description = 'largest data value', required = 0, visible = 1 // data = FindPositionWithLargestData_List_2_out_1; // // node Set[1]: x = 861, y = 247, inputs = 3, label = Set // Set( FindPositionWithLargestData_Receiver_5_out_1, FindPositionWithLargestData_Get_1_out_2, NULL ) [instance: 1, cache: 1]; // // node Done[1]: x = 798, y = 249, inputs = 1, label = Done // Done( FindPositionWithLargestData_Compute_1_out_1 ) [instance: 1, cache: 1]; // // node Compute[2]: x = 532, y = 162, inputs = 2, label = Compute // input[1]: defaulting = 0, visible = 0, type = 32, value = "$0+1" // expression: value = a+1 // name[2]: value = a // FindPositionWithLargestData_Compute_2_out_1 = Compute( "$0+1", FindPositionWithLargestData_Get_2_out_1 ) [instance: 2, cache: 1]; // // node Set[2]: x = 580, y = 255, inputs = 3, label = Set // Set( FindPositionWithLargestData_Compute_2_out_1, FindPositionWithLargestData_Get_2_out_2, NULL ) [instance: 2, cache: 1]; // // node Set[3]: x = 253, y = 699, inputs = 3, label = Set // Set( FindPositionWithLargestData_List_1_out_1, FindPositionWithLargestData_Get_3_out_2, NULL ) [instance: 3, cache: 1]; // // node Set[4]: x = 493, y = 694, inputs = 3, label = Set // Set( FindPositionWithLargestData_List_2_out_1, FindPositionWithLargestData_Get_4_out_2, NULL ) [instance: 4, cache: 1]; // network: end of macro body } FindPositionWithLargestData_First_1_out_1 = NULL; FindPositionWithLargestData_Transmitter_2_out_1 = NULL; FindPositionWithLargestData_Receiver_4_out_1 = NULL; FindPositionWithLargestData_Get_3_out_1 = NULL; FindPositionWithLargestData_Get_3_out_2 = NULL; FindPositionWithLargestData_Input_1_out_1 = NULL; FindPositionWithLargestData_Input_2_out_1 = NULL; FindPositionWithLargestData_Sort_1_out_1 = NULL; FindPositionWithLargestData_Extract_2_out_1 = NULL; FindPositionWithLargestData_Receiver_2_out_1 = NULL; FindPositionWithLargestData_Get_2_out_1 = NULL; FindPositionWithLargestData_Get_2_out_2 = NULL; FindPositionWithLargestData_Transmitter_1_out_1 = NULL; FindPositionWithLargestData_Receiver_1_out_1 = NULL; FindPositionWithLargestData_Select_2_out_1 = NULL; FindPositionWithLargestData_Transmitter_3_out_1 = NULL; FindPositionWithLargestData_Receiver_5_out_1 = NULL; FindPositionWithLargestData_Select_3_out_1 = NULL; FindPositionWithLargestData_Transmitter_4_out_1 = NULL; FindPositionWithLargestData_Receiver_6_out_1 = NULL; FindPositionWithLargestData_Receiver_3_out_1 = NULL; FindPositionWithLargestData_Get_1_out_1 = NULL; FindPositionWithLargestData_Get_1_out_2 = NULL; FindPositionWithLargestData_Compute_1_out_1 = NULL; FindPositionWithLargestData_Transmitter_5_out_1 = NULL; FindPositionWithLargestData_Receiver_7_out_1 = NULL; FindPositionWithLargestData_Compute_3_out_1 = NULL; FindPositionWithLargestData_Extract_1_out_1 = NULL; FindPositionWithLargestData_Select_1_out_1 = NULL; FindPositionWithLargestData_Switch_1_out_1 = NULL; FindPositionWithLargestData_List_1_out_1 = NULL; FindPositionWithLargestData_Get_4_out_1 = NULL; FindPositionWithLargestData_Get_4_out_2 = NULL; FindPositionWithLargestData_Switch_2_out_1 = NULL; FindPositionWithLargestData_List_2_out_1 = NULL; FindPositionWithLargestData_Compute_2_out_1 = NULL;