Changeset 42466 for trunk/Ohana/src/opihi/cmd.data/concat.c
- Timestamp:
- May 24, 2023, 3:31:48 PM (3 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.data/concat.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/concat.c
r20936 r42466 32 32 if ((ivec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 33 33 34 // we have 4 cases: (ivec == flt or int) and (ovec == flt or int) 34 // if the output vector is empty, inherit the type of the input vector 35 if (!ovec->Nelements) { ResetVector (ovec, ivec->type, ovec->Nelements); } 36 37 // we have 3 input and 3 output types : INT, FLT, STR 38 39 // both are strings 40 if ((ovec[0].type == OPIHI_STR) && (ivec[0].type == OPIHI_STR)) { 41 REALLOCATE (ovec->elements.Str, char *, MAX(1, ovec->Nelements + ivec->Nelements)); 42 for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) { 43 ovec[0].elements.Str[j] = strcreate(ivec[0].elements.Str[i]); 44 } 45 goto done; 46 } 47 48 // if only one is a string, raise an error 49 if ((ovec[0].type == OPIHI_STR) || (ivec[0].type == OPIHI_STR)) { 50 gprint (GP_ERR, "ERROR: cannot mix string and numerical vectors\n"); 51 return FALSE; 52 } 53 54 // both vectors are floats 35 55 if ((ovec[0].type == OPIHI_FLT) && (ivec[0].type == OPIHI_FLT)) { 36 56 REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements + ivec[0].Nelements); … … 38 58 ovec[0].elements.Flt[j] = ivec[0].elements.Flt[i]; 39 59 } 60 goto done; 40 61 } 62 // both vectors are ints 63 if ((ovec[0].type == OPIHI_INT) && (ivec[0].type == OPIHI_INT)) { 64 REALLOCATE (ovec[0].elements.Int, opihi_int, ovec[0].Nelements + ivec[0].Nelements); 65 for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) { 66 ovec[0].elements.Int[j] = ivec[0].elements.Int[i]; 67 } 68 goto done; 69 } 70 71 // if output vector is a float and input is an int, cast the int values to the float 41 72 if ((ovec[0].type == OPIHI_FLT) && (ivec[0].type == OPIHI_INT)) { 42 73 REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements + ivec[0].Nelements); … … 44 75 ovec[0].elements.Flt[j] = ivec[0].elements.Int[i]; 45 76 } 46 } 47 if ((ovec[0].type == OPIHI_INT) && (ivec[0].type == OPIHI_INT)) { 48 REALLOCATE (ovec[0].elements.Int, opihi_int, ovec[0].Nelements + ivec[0].Nelements); 49 for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) { 50 ovec[0].elements.Int[j] = ivec[0].elements.Int[i]; 51 } 77 goto done; 52 78 } 53 79 80 // the output vector is an int and input is a float: 54 81 // this case forces ovec to be raised to FLT 55 82 if ((ovec[0].type == OPIHI_INT) && (ivec[0].type == OPIHI_FLT)) { … … 64 91 ovec[0].elements.Flt[j] = ivec[0].elements.Flt[i]; 65 92 } 93 goto done; 66 94 } 67 95 96 done: 68 97 ovec[0].Nelements += ivec[0].Nelements; 69 98 return (TRUE);
Note:
See TracChangeset
for help on using the changeset viewer.
