swapac |
Table of contents
ProcedureSWAPAC ( Swap array, character ) SUBROUTINE SWAPAC ( N, LOCN, M, LOCM, ARRAY ) AbstractSwap (exchange) two non-intersecting groups of contiguous elements of a character array. Required_ReadingNone. KeywordsARRAY DeclarationsIMPLICIT NONE INTEGER N INTEGER LOCN INTEGER M INTEGER LOCM CHARACTER*(*) ARRAY ( * ) Brief_I/OVARIABLE I/O DESCRIPTION -------- --- -------------------------------------------------- N I Number of elements in the first group. LOCN I Location of the first group. M I Number of elements in the second group. LOCM I Location of the second group. ARRAY I-O The array. Detailed_InputN, LOCN define the first group of elements to be exchanged: ARRAY(LOCN) through ARRAY(LOCN+N-1). M, LOCM define the second group of elements to be exchanged: ARRAY(LOCM) through ARRAY(LOCM+M-1). These must be distinct from the first group. ARRAY on input contains both groups of elements in their original locations. Detailed_OutputARRAY on output contains the input array with the indicated groups of elements exchanged. ParametersNone. Exceptions1) If the elements to be swapped are not distinct, the error SPICE(NOTDISTINCT) is signaled. 2) If LOCN or LOCM is less than one, the error SPICE(INVALIDINDEX) is signaled. 3) If the number of elements to be swapped is less than zero, the error SPICE(INVALIDARGUMENT) is signaled. FilesNone. ParticularsIf N [M] is zero, the second [first] group is removed from its current location and inserted in front of ARRAY(LOCN) [ARRAY(LOCM)]. Thus, to move the second [first] group to the front of the list, set N [M] and LOCN [LOCM] to zero and one respectively. To move the group to the end of the list, set N [M] and LOCN [LOCM] to zero and one more than the number of elements in the array. All of the elements to be swapped must be distinct. ExamplesLet ARRAY contain the following elements. Roosevelt Truman Eisenhower Kennedy Johnson Nixon Ford Carter Reagan Cuomo Then the following calls CALL SWAPAC ( 1, 2, 2, 7, ARRAY ) CALL SWAPAC ( 3, 1, 3, 8, ARRAY ) CALL SWAPAC ( 3, 4, 0, 1, ARRAY ) CALL SWAPAC ( 2, 4, 0, 11, ARRAY ) yield the following arrays respectively. [1] [2] [3] [4] Roosevelt Carter Kennedy Roosevelt Ford Reagan Johnson Truman Carter Cuomo Nixon Eisenhower Eisenhower Kennedy Roosevelt Nixon Kennedy Johnson Truman Ford Johnson Nixon Eisenhower Carter Nixon Ford Ford Reagan Truman Roosevelt Carter Cuomo Reagan Truman Reagan Kennedy Cuomo Eisenhower Cuomo Johnson The following calls CALL SWAPAC ( 3, 2, 4, 5, ARRAY ) CALL SWAPAC ( 4, 5, 3, 2, ARRAY ) yield the following arrays. Note that the resulting arrays are equivalent. [1] [2] Roosevelt Roosevelt Johnson Johnson Nixon Nixon Ford Ford Carter Carter Truman Truman Eisenhower Eisenhower Kennedy Kennedy Reagan Reagan Cuomo Cuomo The calls CALL SWAPAC ( 3, 5, 4, 6, ARRAY ) CALL SWAPAC ( 3, -3, 3, 10, ARRAY ) signal the errors SPICE(NOTDISTINCT) SPICE(INVALIDINDEX) respectively. RestrictionsNone. Literature_ReferencesNone. Author_and_InstitutionN.J. Bachman (JPL) J. Diaz del Rio (ODC Space) B.V. Semenov (JPL) W.L. Taber (JPL) I.M. Underwood (JPL) VersionSPICELIB Version 1.2.0, 05-JUN-2021 (JDR) Added IMPLICIT NONE statement. Edited the header to comply with NAIF standard. SPICELIB Version 1.1.1, 18-MAY-2010 (BVS) Removed "C$" marker from text in the header. SPICELIB Version 1.1.0, 09-SEP-2005 (NJB) Updated to remove non-standard use of duplicate arguments in CYCLAC call. SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) Comment section for permuted index source lines was added following the header. SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) |
Fri Dec 31 18:36:58 2021