Changeset 20936 for trunk/Ohana/src/opihi/cmd.data/concat.c
- Timestamp:
- Dec 7, 2008, 3:31:01 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.data/concat.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/concat.c
r8131 r20936 5 5 int i, j, Nin; 6 6 double value; 7 opihi_flt *temp; 7 8 Vector *ivec, *ovec; 8 9 … … 19 20 Nin = ovec[0].Nelements; 20 21 ovec[0].Nelements++; 21 REALLOCATE (ovec[0].elements, float, ovec[0].Nelements); 22 ovec[0].elements[Nin] = value; 22 if (ovec[0].type == OPIHI_FLT) { 23 REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements); 24 ovec[0].elements.Flt[Nin] = value; 25 } else { 26 REALLOCATE (ovec[0].elements.Int, opihi_int, ovec[0].Nelements); 27 ovec[0].elements.Int[Nin] = value; 28 } 23 29 return (TRUE); 24 30 } … … 26 32 if ((ivec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 27 33 28 REALLOCATE (ovec[0].elements, float, ovec[0].Nelements + ivec[0].Nelements); 29 for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) { 30 ovec[0].elements[j] = ivec[0].elements[i]; 34 // we have 4 cases: (ivec == flt or int) and (ovec == flt or int) 35 if ((ovec[0].type == OPIHI_FLT) && (ivec[0].type == OPIHI_FLT)) { 36 REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements + ivec[0].Nelements); 37 for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) { 38 ovec[0].elements.Flt[j] = ivec[0].elements.Flt[i]; 39 } 31 40 } 41 if ((ovec[0].type == OPIHI_FLT) && (ivec[0].type == OPIHI_INT)) { 42 REALLOCATE (ovec[0].elements.Flt, opihi_flt, ovec[0].Nelements + ivec[0].Nelements); 43 for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) { 44 ovec[0].elements.Flt[j] = ivec[0].elements.Int[i]; 45 } 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 } 52 } 53 54 // this case forces ovec to be raised to FLT 55 if ((ovec[0].type == OPIHI_INT) && (ivec[0].type == OPIHI_FLT)) { 56 ALLOCATE (temp, opihi_flt, ovec[0].Nelements + ivec[0].Nelements); 57 for (i = 0; i < ovec[0].Nelements; i++) { 58 temp[i] = ovec[0].elements.Int[i]; 59 } 60 ovec[0].type = OPIHI_FLT; 61 free (ovec[0].elements.Int); 62 ovec[0].elements.Flt = temp; 63 for (j = ovec[0].Nelements, i = 0; i < ivec[0].Nelements; i++, j++) { 64 ovec[0].elements.Flt[j] = ivec[0].elements.Flt[i]; 65 } 66 } 67 32 68 ovec[0].Nelements += ivec[0].Nelements; 33 34 69 return (TRUE); 35 36 70 }
Note:
See TracChangeset
for help on using the changeset viewer.
