Changeset 20936 for trunk/Ohana/src/opihi/cmd.data
- Timestamp:
- Dec 7, 2008, 3:31:01 PM (18 years ago)
- Location:
- trunk/Ohana/src/opihi/cmd.data
- Files:
-
- 57 edited
-
accum.c (modified) (3 diffs)
-
applyfit.c (modified) (3 diffs)
-
applyfit2d.c (modified) (3 diffs)
-
concat.c (modified) (3 diffs)
-
contour.c (modified) (4 diffs)
-
create.c (modified) (2 diffs)
-
cumulative.c (modified) (2 diffs)
-
cut.c (modified) (4 diffs)
-
dbselect.c (modified) (3 diffs)
-
dimendown.c (modified) (2 diffs)
-
dimenup.c (modified) (2 diffs)
-
fft1d.c (modified) (2 diffs)
-
fit.c (modified) (8 diffs)
-
fit2d.c (modified) (8 diffs)
-
gaussdeviate.c (modified) (2 diffs)
-
gaussj.c (modified) (3 diffs)
-
grid.c (modified) (6 diffs)
-
gridify.c (modified) (3 diffs)
-
histogram.c (modified) (2 diffs)
-
imcut.c (modified) (2 diffs)
-
imhist.c (modified) (2 diffs)
-
integrate.c (modified) (2 diffs)
-
interpolate.c (modified) (1 diff)
-
lookup.c (modified) (3 diffs)
-
medacc.c (modified) (5 diffs)
-
mget.c (modified) (4 diffs)
-
mset.c (modified) (3 diffs)
-
peak.c (modified) (2 diffs)
-
periodogram.c (modified) (8 diffs)
-
plot.c (modified) (1 diff)
-
read_vectors.c (modified) (13 diffs)
-
select.c (modified) (1 diff)
-
sort.c (modified) (3 diffs)
-
subset.c (modified) (2 diffs)
-
svd.c (modified) (2 diffs)
-
test/applyfit2d.sh (modified) (2 diffs)
-
test/fit.sh (modified) (6 diffs)
-
test/gaussj.sh (modified) (2 diffs)
-
test/histogram.sh (modified) (2 diffs)
-
test/peak.sh (modified) (3 diffs)
-
test/vgauss.sh (modified) (4 diffs)
-
test/vmaxwell.sh (modified) (1 diff)
-
ungridify.c (modified) (3 diffs)
-
uniq.c (modified) (2 diffs)
-
vbin.c (modified) (2 diffs)
-
vclip.c (modified) (3 diffs)
-
vgauss.c (modified) (7 diffs)
-
vgrid.c (modified) (4 diffs)
-
vload.c (modified) (2 diffs)
-
vmaxwell.c (modified) (6 diffs)
-
vpop.c (modified) (1 diff)
-
vroll.c (modified) (2 diffs)
-
vsmooth.c (modified) (5 diffs)
-
vstat.c (modified) (3 diffs)
-
vzload.c (modified) (1 diff)
-
write_vectors.c (modified) (2 diffs)
-
zplot.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/accum.c
r7917 r20936 5 5 int i, Nbins, bin, N, Normalize; 6 6 float start, end, delta; 7 float *V, *K, *O, *NV; 7 int *NV; 8 opihi_flt *V, *K, *O; 8 9 Vector *val, *key, *out; 9 10 … … 29 30 if ((out = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) return (FALSE); 30 31 32 REQUIRE_VECTOR_FLT (val, FALSE); 33 REQUIRE_VECTOR_FLT (key, FALSE); 34 31 35 start = atof (argv[4]); 32 36 end = atof (argv[5]); … … 45 49 Nbins = (end - start) / delta; 46 50 47 out[0].Nelements = Nbins; 48 REALLOCATE (out[0].elements, float, out[0].Nelements); 49 bzero (out[0].elements, sizeof(float)*out[0].Nelements); 51 ResetVector (out, OPIHI_FLT, Nbins); 52 bzero (out[0].elements.Flt, sizeof(opihi_flt)*out[0].Nelements); 50 53 if (Normalize) { 51 ALLOCATE (NV, float, Nbins);52 bzero (NV, sizeof( float)*Nbins);54 ALLOCATE (NV, int, Nbins); 55 bzero (NV, sizeof(int)*Nbins); 53 56 } 54 57 55 V = val[0].elements ;56 K = key[0].elements ;57 O = out[0].elements ;58 V = val[0].elements.Flt; 59 K = key[0].elements.Flt; 60 O = out[0].elements.Flt; 58 61 59 62 for (i = 0; i < val[0].Nelements; i++, V++, K++) { -
trunk/Ohana/src/opihi/cmd.data/applyfit.c
r16428 r20936 1 1 # include "data.h" 2 3 char *get_variable (char *);4 2 5 3 int applyfit (int argc, char **argv) { … … 8 6 char *c, name[64]; 9 7 double *C, X; 10 float *x,*y;8 opihi_flt *y; 11 9 Vector *xvec, *yvec; 12 10 … … 38 36 free (c); 39 37 } 40 yvec[0].Nelements = xvec[0].Nelements;41 REALLOCATE (yvec[0].elements, float, yvec[0].Nelements);42 bzero (yvec[0].elements, sizeof(float)*yvec[0].Nelements);43 x = xvec[0].elements;44 y = yvec[0].elements;45 38 46 for (j = 0; j < xvec[0].Nelements; j++, x++, y++) { 47 X = 1; 48 for (i = 0; i < order + 1; i++) { 49 *y += C[i]*X; 50 X = X * (*x); 39 ResetVector (yvec, OPIHI_FLT, xvec[0].Nelements); 40 bzero (yvec[0].elements.Flt, sizeof(opihi_flt)*yvec[0].Nelements); 41 y = yvec[0].elements.Flt; 42 43 if (xvec[0].type == OPIHI_FLT) { 44 opihi_flt *x = xvec[0].elements.Flt; 45 for (j = 0; j < xvec[0].Nelements; j++, x++, y++) { 46 X = 1; 47 for (i = 0; i < order + 1; i++) { 48 *y += C[i]*X; 49 X = X * (*x); 50 } 51 } 52 } else { 53 opihi_int *x = xvec[0].elements.Int; 54 for (j = 0; j < xvec[0].Nelements; j++, x++, y++) { 55 X = 1; 56 for (i = 0; i < order + 1; i++) { 57 *y += C[i]*X; 58 X = X * (*x); 59 } 51 60 } 52 61 } -
trunk/Ohana/src/opihi/cmd.data/applyfit2d.c
r16428 r20936 1 1 # include "data.h" 2 3 char *get_variable (char *);4 2 5 3 int applyfit2d (int argc, char **argv) { … … 8 6 char *c, name[64]; 9 7 double **C, X, Y; 10 float *x, *y,*z;8 opihi_flt *z; 11 9 Vector *xvec, *yvec, *zvec; 12 10 … … 45 43 } 46 44 47 zvec[0].Nelements = xvec[0].Nelements; 48 REALLOCATE (zvec[0].elements, float, zvec[0].Nelements); 49 bzero (zvec[0].elements, sizeof(float)*zvec[0].Nelements); 50 x = xvec[0].elements; 51 y = yvec[0].elements; 52 z = zvec[0].elements; 45 ResetVector (zvec, OPIHI_FLT, xvec[0].Nelements); 46 bzero (zvec[0].elements.Flt, sizeof(opihi_flt)*zvec[0].Nelements); 47 z = zvec[0].elements.Flt; 53 48 54 for (n = 0; n < xvec[0].Nelements; n++, x++, y++, z++) { 55 Y = X = 1; 56 for (j = 0; j < order + 1; j++) { 57 X = Y; 58 for (i = 0; i < order + 1 - j; i++) { 59 *z += C[i][j]*X; 60 X = X * (*x); 49 // we have four cases (x == flt or int) and (y == flt or int) 50 if ((xvec[0].type == OPIHI_FLT) && (yvec[0].type == OPIHI_FLT)) { 51 opihi_flt *x = xvec[0].elements.Flt; 52 opihi_flt *y = yvec[0].elements.Flt; 53 for (n = 0; n < xvec[0].Nelements; n++, x++, y++, z++) { 54 Y = X = 1; 55 for (j = 0; j < order + 1; j++) { 56 X = Y; 57 for (i = 0; i < order + 1 - j; i++) { 58 *z += C[i][j]*X; 59 X = X * (*x); 60 } 61 Y = Y * (*y); 61 62 } 62 Y = Y * (*y);63 63 } 64 64 } 65 if ((xvec[0].type == OPIHI_FLT) && (yvec[0].type == OPIHI_INT)) { 66 opihi_flt *x = xvec[0].elements.Flt; 67 opihi_int *y = yvec[0].elements.Int; 68 for (n = 0; n < xvec[0].Nelements; n++, x++, y++, z++) { 69 Y = X = 1; 70 for (j = 0; j < order + 1; j++) { 71 X = Y; 72 for (i = 0; i < order + 1 - j; i++) { 73 *z += C[i][j]*X; 74 X = X * (*x); 75 } 76 Y = Y * (*y); 77 } 78 } 79 } 80 if ((xvec[0].type == OPIHI_INT) && (yvec[0].type == OPIHI_FLT)) { 81 opihi_int *x = xvec[0].elements.Int; 82 opihi_flt *y = yvec[0].elements.Flt; 83 for (n = 0; n < xvec[0].Nelements; n++, x++, y++, z++) { 84 Y = X = 1; 85 for (j = 0; j < order + 1; j++) { 86 X = Y; 87 for (i = 0; i < order + 1 - j; i++) { 88 *z += C[i][j]*X; 89 X = X * (*x); 90 } 91 Y = Y * (*y); 92 } 93 } 94 } 95 if ((xvec[0].type == OPIHI_INT) && (yvec[0].type == OPIHI_INT)) { 96 opihi_int *x = xvec[0].elements.Int; 97 opihi_int *y = yvec[0].elements.Int; 98 for (n = 0; n < xvec[0].Nelements; n++, x++, y++, z++) { 99 Y = X = 1; 100 for (j = 0; j < order + 1; j++) { 101 X = Y; 102 for (i = 0; i < order + 1 - j; i++) { 103 *z += C[i][j]*X; 104 X = X * (*x); 105 } 106 Y = Y * (*y); 107 } 108 } 109 } 110 65 111 for (i = 0; i < order + 1; i++) free (C[i]); 66 112 free (C); -
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 } -
trunk/Ohana/src/opihi/cmd.data/contour.c
r7917 r20936 44 44 int N, NVEC; 45 45 46 void DUMP (float x, float y, float dx, float dy) { 47 48 xv[0].elements[N] = x; 49 xv[0].elements[N+1] = x+dx; 50 51 yv[0].elements[N] = y; 52 yv[0].elements[N+1] = y+dy; 46 void DUMP (opihi_flt x, opihi_flt y, opihi_flt dx, opihi_flt dy) { 47 48 xv[0].elements.Flt[N] = x; 49 xv[0].elements.Flt[N+1] = x+dx; 50 yv[0].elements.Flt[N] = y; 51 yv[0].elements.Flt[N+1] = y+dy; 53 52 54 53 N+=2; … … 56 55 if (N >= NVEC - 2) { 57 56 NVEC += 100; 58 REALLOCATE (xv[0].elements , float, NVEC);59 REALLOCATE (yv[0].elements , float, NVEC);57 REALLOCATE (xv[0].elements.Flt, opihi_flt, NVEC); 58 REALLOCATE (yv[0].elements.Flt, opihi_flt, NVEC); 60 59 } 61 60 } … … 64 63 65 64 int i, j, Nx, Ny; 65 opihi_flt x, y, dx, dy; 66 66 float level, d00, d01, d10, d11, tmp; 67 float x, y, dx, dy;68 67 float *v00, *v01, *v10, *v11; 69 68 float *matrix; … … 93 92 N = 0; 94 93 NVEC = 100; 95 R EALLOCATE (xv[0].elements, float, NVEC);96 R EALLOCATE (yv[0].elements, float, NVEC);94 ResetVector (xv, OPIHI_FLT, NVEC); 95 ResetVector (yv, OPIHI_FLT, NVEC); 97 96 98 97 for (j = 1; j < Ny; j++) { -
trunk/Ohana/src/opihi/cmd.data/create.c
r12332 r20936 3 3 int create (int argc, char **argv) { 4 4 5 int i ;5 int i, N, INT; 6 6 float start, end, delta; 7 7 Vector *vec; 8 8 9 INT = FALSE; 10 if ((N = get_argument (argc, argv, "-int"))) { 11 INT = TRUE; 12 remove_argument (N, &argc, argv); 13 } 14 9 15 if ((argc != 5) && (argc != 4)) { 10 16 gprint (GP_ERR, "USAGE: create vector start end [delta]\n"); … … 27 33 } 28 34 35 if (INT && (delta != (int)delta)) { 36 gprint (GP_ERR, "integer vector requested but fractional step-size specified\n"); 37 return (FALSE); 38 } 39 29 40 vec[0].Nelements = (end - start) / delta; 30 REALLOCATE (vec[0].elements, float, vec[0].Nelements);31 41 32 for (i = 0; i < vec[0].Nelements; i++) { 33 vec[0].elements[i] = start + i*delta; 42 if (INT) { 43 vec[0].type = OPIHI_INT; 44 REALLOCATE (vec[0].elements.Int, opihi_int, vec[0].Nelements); 45 for (i = 0; i < vec[0].Nelements; i++) { 46 vec[0].elements.Int[i] = start + i*delta; 47 } 48 } else { 49 vec[0].type = OPIHI_FLT; 50 REALLOCATE (vec[0].elements.Flt, opihi_flt, vec[0].Nelements); 51 for (i = 0; i < vec[0].Nelements; i++) { 52 vec[0].elements.Flt[i] = start + i*delta; 53 } 34 54 } 35 55 -
trunk/Ohana/src/opihi/cmd.data/cumulative.c
r10307 r20936 4 4 5 5 int i; 6 float *Vi,*Vo;6 opihi_flt *Vo; 7 7 Vector *ivec, *ovec; 8 8 … … 14 14 if ((ivec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 15 15 if ((ovec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) return (FALSE); 16 ovec[0].Nelements = ivec[0].Nelements;17 18 REALLOCATE (ovec[0].elements, float, ovec[0].Nelements);19 bzero (ovec[0].elements, sizeof(float)*ovec[0].Nelements);20 16 21 Vi = ivec[0].elements; 22 Vo = ovec[0].elements; 23 *Vo = *Vi; 24 for (i = 1; i < ivec[0].Nelements; i++, Vi++, Vo++) { 25 *Vo = Vo[-1] + *Vi; 26 } 17 ResetVector (ovec, OPIHI_FLT, ivec[0].Nelements); 18 bzero (ovec[0].elements.Flt, sizeof(opihi_flt)*ovec[0].Nelements); 19 20 Vo = ovec[0].elements.Flt; 21 22 if (ivec[0].type == OPIHI_FLT) { 23 opihi_flt *Vi = ivec[0].elements.Flt; 24 *Vo = *Vi; 25 for (i = 1; i < ivec[0].Nelements; i++, Vi++, Vo++) { 26 *Vo = Vo[-1] + *Vi; 27 } 28 } else { 29 opihi_int *Vi = ivec[0].elements.Int; 30 *Vo = *Vi; 31 for (i = 1; i < ivec[0].Nelements; i++, Vi++, Vo++) { 32 *Vo = Vo[-1] + *Vi; 33 } 34 } 27 35 return (TRUE); 28 36 } -
trunk/Ohana/src/opihi/cmd.data/cut.c
r16446 r20936 48 48 case 'X': 49 49 /* create output vectors */ 50 xvec[0].Nelements = yvec[0].Nelements = nx; 51 REALLOCATE (xvec[0].elements, float, MAX (nx, 1)); 52 REALLOCATE (yvec[0].elements, float, MAX (nx, 1)); 53 bzero (yvec[0].elements, nx*sizeof(float)); 50 ResetVector (xvec, OPIHI_FLT, MAX (nx, 1)); 51 ResetVector (yvec, OPIHI_FLT, MAX (nx, 1)); 52 bzero (yvec[0].elements.Flt, nx*sizeof(opihi_flt)); 54 53 for (i = 0; i < nx; i++) { 55 xvec[0].elements [i] = i + sx;54 xvec[0].elements.Flt[i] = i + sx; 56 55 } 57 56 ALLOCATE (Vbuf, float, MAX (ny, 1)); … … 74 73 if (Mode == MEAN) { value /= ny; } 75 74 } 76 yvec[0].elements [i] = value;75 yvec[0].elements.Flt[i] = value; 77 76 } 78 77 free (Vbuf); … … 81 80 case 'y': 82 81 case 'Y': 83 xvec[0].Nelements = yvec[0].Nelements = ny; 84 REALLOCATE (xvec[0].elements, float, ny); 85 REALLOCATE (yvec[0].elements, float, ny); 86 bzero (yvec[0].elements, ny*sizeof(float)); 82 ResetVector (xvec, OPIHI_FLT, MAX (ny, 1)); 83 ResetVector (yvec, OPIHI_FLT, MAX (ny, 1)); 84 bzero (yvec[0].elements.Flt, ny*sizeof(opihi_flt)); 87 85 for (i = 0; i < ny; i++) { 88 xvec[0].elements [i] = i + sy;86 xvec[0].elements.Flt[i] = i + sy; 89 87 } 90 88 ALLOCATE (Vbuf, float, MAX (nx, 1)); … … 107 105 if (Mode == MEAN) { value /= nx; } 108 106 } 109 yvec[0].elements [i] = value;107 yvec[0].elements.Flt[i] = value; 110 108 } 111 109 free (Vbuf); -
trunk/Ohana/src/opihi/cmd.data/dbselect.c
r17852 r20936 67 67 return (FALSE); 68 68 } 69 REALLOCATE (vec[i][0].elements, float, Nrows); 70 vec[i][0].Nelements = Nrows; 69 switch (fields[i].type) { 70 case FIELD_TYPE_TINY: 71 case FIELD_TYPE_SHORT: 72 case FIELD_TYPE_LONG: 73 case FIELD_TYPE_INT24: 74 case FIELD_TYPE_LONGLONG: 75 ResetVector (vec[i], OPIHI_INT, Nrows); 76 break; 77 case FIELD_TYPE_DECIMAL: 78 case FIELD_TYPE_FLOAT: 79 case FIELD_TYPE_DOUBLE: 80 case FIELD_TYPE_TIME: 81 case FIELD_TYPE_DATE: 82 case FIELD_TYPE_DATETIME: 83 ResetVector (vec[i], OPIHI_FLT, Nrows); 84 break; 85 default: 86 ResetVector (vec[i], OPIHI_FLT, Nrows); 87 break; 88 } 71 89 } 72 90 … … 88 106 case FIELD_TYPE_INT24: 89 107 case FIELD_TYPE_LONGLONG: 108 vec[i][0].elements.Int[j] = atol (row[i]); 109 break; 90 110 case FIELD_TYPE_DECIMAL: 91 111 case FIELD_TYPE_FLOAT: 92 112 case FIELD_TYPE_DOUBLE: 93 vec[i][0].elements [j] = atof (row[i]);113 vec[i][0].elements.Flt[j] = atof (row[i]); 94 114 break; 95 115 case FIELD_TYPE_TIME: … … 97 117 case FIELD_TYPE_DATETIME: 98 118 seconds = ohana_date_to_sec (row[i]); 99 vec[i][0].elements [j] = ohana_sec_to_mjd (seconds);119 vec[i][0].elements.Flt[j] = ohana_sec_to_mjd (seconds); 100 120 break; 101 121 default: 102 vec[i][0].elements [j] = NAN;122 vec[i][0].elements.Flt[j] = NAN; 103 123 } 104 124 } else { 105 vec[i][0].elements [j] = NAN;125 vec[i][0].elements.Flt[j] = NAN; 106 126 } 107 127 } -
trunk/Ohana/src/opihi/cmd.data/dimendown.c
r7917 r20936 6 6 7 7 int i, Nx, Ny, Npix, N, mode; 8 float *in, *out; 8 float *in; 9 opihi_flt *out; 9 10 Vector *vec; 10 11 Buffer *buf; … … 29 30 Npix = Nx * Ny; 30 31 31 vec[0].Nelements = Npix; 32 REALLOCATE (vec[0].elements, float, Npix); 32 ResetVector (vec, OPIHI_FLT, Npix); 33 33 34 34 in = (float *) buf[0].matrix.buffer; 35 out = vec[0].elements ;35 out = vec[0].elements.Flt; 36 36 37 37 switch (mode) { -
trunk/Ohana/src/opihi/cmd.data/dimenup.c
r9275 r20936 4 4 5 5 int i, Nx, Ny, Npix; 6 float * in, *out;6 float *out; 7 7 Vector *vec; 8 8 Buffer *buf; … … 29 29 30 30 out = (float *) buf[0].matrix.buffer; 31 in = vec[0].elements;32 31 33 for (i = 0; i < Npix; i++, in++, out++) { 34 *out = *in; 32 if (vec[0].type == OPIHI_FLT) { 33 opihi_flt *in = vec[0].elements.Flt; 34 for (i = 0; i < Npix; i++, in++, out++) { 35 *out = *in; 36 } 37 } else { 38 opihi_int *in = vec[0].elements.Int; 39 for (i = 0; i < Npix; i++, in++, out++) { 40 *out = *in; 41 } 35 42 } 36 43 -
trunk/Ohana/src/opihi/cmd.data/fft1d.c
r16107 r20936 25 25 if ((Ire = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 26 26 27 REQUIRE_VECTOR_FLT (Ire, FALSE); 28 if (Iim) { REQUIRE_VECTOR_FLT (Iim, FALSE); } 29 27 30 // check the input data (match lengths? binary length?) 28 31 Npix = Ire[0].Nelements; … … 40 43 if ((Oim = SelectVector (argv[5], ANYVECTOR, TRUE)) == NULL) return (FALSE); 41 44 42 // allocate sufficient output space 43 Ore[0].Nelements = Npix; 44 Oim[0].Nelements = Npix; 45 REALLOCATE (Ore[0].elements, float, Npix); 46 REALLOCATE (Oim[0].elements, float, Npix); 45 // allocate sufficient output space, force output to be FLT 46 ResetVector (Ore, OPIHI_FLT, Npix); 47 ResetVector (Oim, OPIHI_FLT, Npix); 47 48 48 49 // copy data to output vectors (fft is done in place) 49 memcpy (Ore[0].elements , Ire[0].elements, Npix*sizeof(float));50 memcpy (Ore[0].elements.Flt, Ire[0].elements.Flt, Npix*sizeof(opihi_flt)); 50 51 51 52 // copy imaginary vector or create a zero vector 52 53 if (ZeroImaginary) { 53 memset (Oim[0].elements , 0, Npix*sizeof(float));54 memset (Oim[0].elements.Flt, 0, Npix*sizeof(opihi_flt)); 54 55 } else { 55 memcpy (Oim[0].elements , Iim[0].elements, Npix*sizeof(float));56 memcpy (Oim[0].elements.Flt, Iim[0].elements.Flt, Npix*sizeof(opihi_flt)); 56 57 } 57 58 58 fft1D (Ore[0].elements, Oim[0].elements, Npix, Nbit, forward);59 dfft1D (Ore[0].elements.Flt, Oim[0].elements.Flt, Npix, Nbit, forward); 59 60 60 61 return (TRUE); -
trunk/Ohana/src/opihi/cmd.data/fit.c
r16059 r20936 8 8 int N, Weight, Quiet, ClipNiter; 9 9 Vector *xvec, *yvec, *dyvec; 10 float *x, *y, *dy, *yf, *yfit;10 opihi_flt *x, *y, *dy, *yf, *yfit; 11 11 char name[64], *mask; 12 12 … … 53 53 return (FALSE); 54 54 } 55 if (Weight && xvec[0].Nelements != dyvec[0].Nelements) { 56 gprint (GP_ERR, "vectors must have same length\n"); 57 return (FALSE); 58 } 59 55 REQUIRE_VECTOR_FLT (xvec, FALSE); 56 REQUIRE_VECTOR_FLT (yvec, FALSE); 57 58 if (Weight) { 59 REQUIRE_VECTOR_FLT (dyvec, FALSE); 60 if (xvec[0].Nelements != dyvec[0].Nelements) { 61 gprint (GP_ERR, "vectors must have same length\n"); 62 return (FALSE); 63 } 64 } 65 66 60 67 /* nterm is number of polynomial terms, starting at x^0 */ 61 68 order = atof (argv[3]); … … 63 70 mterm = 2*nterm; 64 71 65 ALLOCATE (yfit, float, xvec[0].Nelements);72 ALLOCATE (yfit, opihi_flt, xvec[0].Nelements); 66 73 ALLOCATE (mask, char, xvec[0].Nelements); 67 74 memset (mask, 0, xvec[0].Nelements); … … 88 95 89 96 /* perform linear fit */ 90 x = xvec[0].elements ;91 y = yvec[0].elements ;92 if (Weight) dy = dyvec[0].elements ;97 x = xvec[0].elements.Flt; 98 y = yvec[0].elements.Flt; 99 if (Weight) dy = dyvec[0].elements.Flt; 93 100 94 101 for (i = 0; i < xvec[0].Nelements; i++, x++, y++) { … … 121 128 122 129 /* generate fitted values */ 123 x = xvec[0].elements ;130 x = xvec[0].elements.Flt; 124 131 yf = yfit; 125 132 for (i = 0; i < xvec[0].Nelements; i++, x++, yf++) { … … 134 141 135 142 /* measure fit residual scatter */ 136 x = xvec[0].elements ;137 y = yvec[0].elements ;143 x = xvec[0].elements.Flt; 144 y = yvec[0].elements.Flt; 138 145 yf = yfit; 139 146 dY = dY2 = 0; … … 150 157 151 158 /* mask outlier points */ 152 x = xvec[0].elements ;153 y = yvec[0].elements ;159 x = xvec[0].elements.Flt; 160 y = yvec[0].elements.Flt; 154 161 yf = yfit; 155 162 Nmask = 0; … … 193 200 if ((fvec = SelectVector ("yfit", ANYVECTOR, TRUE)) == NULL) return (FALSE); 194 201 if ((mvec = SelectVector ("mask", ANYVECTOR, TRUE)) == NULL) return (FALSE); 195 free (fvec[0].elements );196 fvec[0].elements = yfit;202 free (fvec[0].elements.Flt); 203 fvec[0].elements.Flt = yfit; 197 204 fvec[0].Nelements = xvec[0].Nelements; 198 205 mvec[0].Nelements = xvec[0].Nelements; 199 206 200 REALLOCATE (mvec[0].elements , float, xvec[0].Nelements);207 REALLOCATE (mvec[0].elements.Flt, opihi_flt, xvec[0].Nelements); 201 208 for (i = 0; i < xvec[0].Nelements; i++) { 202 mvec[0].elements [i] = mask[i];209 mvec[0].elements.Flt[i] = mask[i]; 203 210 } 204 211 } else { -
trunk/Ohana/src/opihi/cmd.data/fit2d.c
r16059 r20936 7 7 int k, K, i, j, n, Npt, Nmask, nx, ny, nterm, mterm, wterm, order; 8 8 int N, Weight, Quiet, ClipNiter, VERBOSE; 9 float *x, *y, *z, *dz, *zfit, *zf;9 opihi_flt *x, *y, *z, *dz, *zfit, *zf; 10 10 char name[64], *mask; 11 11 Vector *xvec, *yvec, *zvec, *dzvec; … … 64 64 return (FALSE); 65 65 } 66 if (Weight && xvec[0].Nelements != dzvec[0].Nelements) { 67 gprint (GP_ERR, "vectors must have same length\n"); 68 return (FALSE); 66 REQUIRE_VECTOR_FLT (xvec, FALSE); 67 REQUIRE_VECTOR_FLT (yvec, FALSE); 68 REQUIRE_VECTOR_FLT (zvec, FALSE); 69 70 if (Weight) { 71 REQUIRE_VECTOR_FLT (dzvec, FALSE); 72 if (xvec[0].Nelements != dzvec[0].Nelements) { 73 gprint (GP_ERR, "vectors must have same length\n"); 74 return (FALSE); 75 } 69 76 } 70 77 … … 74 81 mterm = 2*order + 1; 75 82 76 ALLOCATE (zfit, float, xvec[0].Nelements);83 ALLOCATE (zfit, opihi_flt, xvec[0].Nelements); 77 84 ALLOCATE (mask, char, xvec[0].Nelements); 78 85 memset (mask, 0, xvec[0].Nelements); … … 102 109 } 103 110 104 x = xvec[0].elements ;105 y = yvec[0].elements ;106 z = zvec[0].elements ;107 if (Weight) dz = dzvec[0].elements ;111 x = xvec[0].elements.Flt; 112 y = yvec[0].elements.Flt; 113 z = zvec[0].elements.Flt; 114 if (Weight) dz = dzvec[0].elements.Flt; 108 115 109 116 /* add up the x,y values */ … … 128 135 129 136 /* add up the z values */ 130 x = xvec[0].elements ;131 y = yvec[0].elements ;132 z = zvec[0].elements ;137 x = xvec[0].elements.Flt; 138 y = yvec[0].elements.Flt; 139 z = zvec[0].elements.Flt; 133 140 for (i = 0; i < xvec[0].Nelements; i++, x++, y++, z++) { 134 141 if (mask[i]) continue; … … 179 186 */ 180 187 /* generate fitted values */ 181 x = xvec[0].elements ;182 y = yvec[0].elements ;188 x = xvec[0].elements.Flt; 189 y = yvec[0].elements.Flt; 183 190 zf = zfit; 184 191 for (n = 0; n < xvec[0].Nelements; n++, x++, y++, zf++) { … … 197 204 198 205 /* measure fit residual scatter */ 199 x = xvec[0].elements ;200 y = yvec[0].elements ;201 z = zvec[0].elements ;206 x = xvec[0].elements.Flt; 207 y = yvec[0].elements.Flt; 208 z = zvec[0].elements.Flt; 202 209 zf = zfit; 203 210 dZ = dZ2 = 0; … … 216 223 217 224 /* mask outlier points */ 218 x = xvec[0].elements ;219 y = yvec[0].elements ;220 z = zvec[0].elements ;225 x = xvec[0].elements.Flt; 226 y = yvec[0].elements.Flt; 227 z = zvec[0].elements.Flt; 221 228 zf = zfit; 222 229 Nmask = 0; -
trunk/Ohana/src/opihi/cmd.data/gaussdeviate.c
r7917 r20936 15 15 sigma = atof (argv[4]); 16 16 17 vec[0].Nelements = Npts; 18 REALLOCATE (vec[0].elements, float, Npts); 17 ResetVector (vec, OPIHI_FLT, Npts); 19 18 20 19 gauss_init (2048); 21 20 for (i = 0; i < Npts; i++) { 22 vec[0].elements [i] = rnd_gauss (mean, sigma);21 vec[0].elements.Flt[i] = rnd_gauss (mean, sigma); 23 22 } 24 23 return (TRUE); … … 46 45 sigma = atof (argv[4]); 47 46 48 vec[0].Nelements = Npts; 49 REALLOCATE (vec[0].elements, float, Npts); 47 ResetVector (vec, OPIHI_FLT, Npts); 50 48 51 49 gauss_init (Npts); 52 50 for (i = 0; i < Npts; i++) { 53 vec[0].elements [i] = int_gauss (i);51 vec[0].elements.Flt[i] = int_gauss (i); 54 52 } 55 53 return (TRUE); -
trunk/Ohana/src/opihi/cmd.data/gaussj.c
r16117 r20936 2 2 3 3 int gaussjordan (int argc, char **argv) { 4 5 float *m, *v; 4 5 float *m; 6 opihi_flt *vf; 7 opihi_int *vi; 6 8 double **a, **b; 7 int i, j, N, status, QUIET ;9 int i, j, N, status, QUIET, isFloat; 8 10 Vector *B; 9 11 Buffer *A; … … 31 33 } 32 34 35 isFloat = (B[0].type == OPIHI_FLT); 36 vf = B[0].elements.Flt; 37 vi = B[0].elements.Int; 38 33 39 m = (float *) A[0].matrix.buffer; 34 v = B[0].elements;35 40 for (i = 0; i < N; i++) { 36 41 for (j = 0; j < N; j++) { 37 42 a[i][j] = m[i+j*N]; 38 43 } 39 b[i][0] = v[i];44 b[i][0] = isFloat ? vf[i] : vi[i]; 40 45 } 41 46 42 47 status = dgaussjordan (a, b, N, 1); 48 49 // output vector needs to be float, so re-cast it 50 ResetVector (B, OPIHI_FLT, N); 51 vf = B[0].elements.Flt; 43 52 44 53 for (i = 0; i < N; i++) { … … 46 55 m[i+j*N] = a[i][j]; 47 56 } 48 v [i] = b[i][0];57 vf[i] = b[i][0]; 49 58 } 50 59 -
trunk/Ohana/src/opihi/cmd.data/grid.c
r13479 r20936 23 23 24 24 N = 0; 25 Xvec.Nelements = 200; 26 Yvec.Nelements = 200; 27 ALLOCATE (Xvec.elements, float, Xvec.Nelements); 28 ALLOCATE (Yvec.elements, float, Yvec.Nelements); 25 SetVector (&Xvec, OPIHI_FLT, 200); 26 SetVector (&Yvec, OPIHI_FLT, 200); 29 27 30 28 major = minor = 1; … … 64 62 if (MajorTick) { 65 63 /* major tick */ 66 Xvec.elements [N] = next;67 Yvec.elements [N] = graphmode.ymin;68 N++; 69 if (N == Xvec.Nelements) { 70 Xvec.Nelements += 200; 71 Yvec.Nelements += 200; 72 REALLOCATE (Xvec.elements , float, Xvec.Nelements);73 REALLOCATE (Yvec.elements , float, Yvec.Nelements);74 } 75 Xvec.elements [N] = next;76 Yvec.elements [N] = graphmode.ymax;77 N++; 78 if (N == Xvec.Nelements) { 79 Xvec.Nelements += 200; 80 Yvec.Nelements += 200; 81 REALLOCATE (Xvec.elements , float, Xvec.Nelements);82 REALLOCATE (Yvec.elements , float, Yvec.Nelements);64 Xvec.elements.Flt[N] = next; 65 Yvec.elements.Flt[N] = graphmode.ymin; 66 N++; 67 if (N == Xvec.Nelements) { 68 Xvec.Nelements += 200; 69 Yvec.Nelements += 200; 70 REALLOCATE (Xvec.elements.Flt, opihi_flt, Xvec.Nelements); 71 REALLOCATE (Yvec.elements.Flt, opihi_flt, Yvec.Nelements); 72 } 73 Xvec.elements.Flt[N] = next; 74 Yvec.elements.Flt[N] = graphmode.ymax; 75 N++; 76 if (N == Xvec.Nelements) { 77 Xvec.Nelements += 200; 78 Yvec.Nelements += 200; 79 REALLOCATE (Xvec.elements.Flt, opihi_flt, Xvec.Nelements); 80 REALLOCATE (Yvec.elements.Flt, opihi_flt, Yvec.Nelements); 83 81 } 84 82 } … … 86 84 if (MinorTick) { 87 85 /* minor tick */ 88 Xvec.elements [N] = next;89 Yvec.elements [N] = graphmode.ymin;90 N++; 91 if (N == Xvec.Nelements) { 92 Xvec.Nelements += 200; 93 Yvec.Nelements += 200; 94 REALLOCATE (Xvec.elements , float, Xvec.Nelements);95 REALLOCATE (Yvec.elements , float, Yvec.Nelements);96 } 97 Xvec.elements [N] = next;98 Yvec.elements [N] = graphmode.ymax;99 N++; 100 if (N == Xvec.Nelements) { 101 Xvec.Nelements += 200; 102 Yvec.Nelements += 200; 103 REALLOCATE (Xvec.elements , float, Xvec.Nelements);104 REALLOCATE (Yvec.elements , float, Yvec.Nelements);86 Xvec.elements.Flt[N] = next; 87 Yvec.elements.Flt[N] = graphmode.ymin; 88 N++; 89 if (N == Xvec.Nelements) { 90 Xvec.Nelements += 200; 91 Yvec.Nelements += 200; 92 REALLOCATE (Xvec.elements.Flt, opihi_flt, Xvec.Nelements); 93 REALLOCATE (Yvec.elements.Flt, opihi_flt, Yvec.Nelements); 94 } 95 Xvec.elements.Flt[N] = next; 96 Yvec.elements.Flt[N] = graphmode.ymax; 97 N++; 98 if (N == Xvec.Nelements) { 99 Xvec.Nelements += 200; 100 Yvec.Nelements += 200; 101 REALLOCATE (Xvec.elements.Flt, opihi_flt, Xvec.Nelements); 102 REALLOCATE (Yvec.elements.Flt, opihi_flt, Yvec.Nelements); 105 103 } 106 104 } … … 144 142 if (MajorTick) { 145 143 /* major tick */ 146 Xvec.elements [N] = graphmode.xmin;147 Yvec.elements [N] = next;148 N++; 149 if (N == Xvec.Nelements) { 150 Xvec.Nelements += 200; 151 Yvec.Nelements += 200; 152 REALLOCATE (Xvec.elements , float, Xvec.Nelements);153 REALLOCATE (Yvec.elements , float, Yvec.Nelements);154 } 155 Xvec.elements [N] = graphmode.xmax;156 Yvec.elements [N] = next;157 N++; 158 if (N == Xvec.Nelements) { 159 Xvec.Nelements += 200; 160 Yvec.Nelements += 200; 161 REALLOCATE (Xvec.elements , float, Xvec.Nelements);162 REALLOCATE (Yvec.elements , float, Yvec.Nelements);144 Xvec.elements.Flt[N] = graphmode.xmin; 145 Yvec.elements.Flt[N] = next; 146 N++; 147 if (N == Xvec.Nelements) { 148 Xvec.Nelements += 200; 149 Yvec.Nelements += 200; 150 REALLOCATE (Xvec.elements.Flt, opihi_flt, Xvec.Nelements); 151 REALLOCATE (Yvec.elements.Flt, opihi_flt, Yvec.Nelements); 152 } 153 Xvec.elements.Flt[N] = graphmode.xmax; 154 Yvec.elements.Flt[N] = next; 155 N++; 156 if (N == Xvec.Nelements) { 157 Xvec.Nelements += 200; 158 Yvec.Nelements += 200; 159 REALLOCATE (Xvec.elements.Flt, opihi_flt, Xvec.Nelements); 160 REALLOCATE (Yvec.elements.Flt, opihi_flt, Yvec.Nelements); 163 161 } 164 162 } … … 166 164 if (MinorTick) { 167 165 /* minor tick */ 168 Xvec.elements [N] = graphmode.xmin;169 Yvec.elements [N] = next;170 N++; 171 if (N == Xvec.Nelements) { 172 Xvec.Nelements += 200; 173 Yvec.Nelements += 200; 174 REALLOCATE (Xvec.elements , float, Xvec.Nelements);175 REALLOCATE (Yvec.elements , float, Yvec.Nelements);176 } 177 Xvec.elements [N] = graphmode.xmax;178 Yvec.elements [N] = next;179 N++; 180 if (N == Xvec.Nelements) { 181 Xvec.Nelements += 200; 182 Yvec.Nelements += 200; 183 REALLOCATE (Xvec.elements , float, Xvec.Nelements);184 REALLOCATE (Yvec.elements , float, Yvec.Nelements);166 Xvec.elements.Flt[N] = graphmode.xmin; 167 Yvec.elements.Flt[N] = next; 168 N++; 169 if (N == Xvec.Nelements) { 170 Xvec.Nelements += 200; 171 Yvec.Nelements += 200; 172 REALLOCATE (Xvec.elements.Flt, opihi_flt, Xvec.Nelements); 173 REALLOCATE (Yvec.elements.Flt, opihi_flt, Yvec.Nelements); 174 } 175 Xvec.elements.Flt[N] = graphmode.xmax; 176 Yvec.elements.Flt[N] = next; 177 N++; 178 if (N == Xvec.Nelements) { 179 Xvec.Nelements += 200; 180 Yvec.Nelements += 200; 181 REALLOCATE (Xvec.elements.Flt, opihi_flt, Xvec.Nelements); 182 REALLOCATE (Yvec.elements.Flt, opihi_flt, Yvec.Nelements); 185 183 } 186 184 } … … 193 191 graphmode.ptype = 100; /* connect a pair */ 194 192 graphmode.etype = 0; 195 PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);196 197 free (Xvec.elements );198 free (Yvec.elements );193 PlotVectorPair (kapa, &Xvec, &Yvec, &graphmode); 194 195 free (Xvec.elements.Flt); 196 free (Yvec.elements.Flt); 199 197 200 198 return (TRUE); -
trunk/Ohana/src/opihi/cmd.data/gridify.c
r9275 r20936 5 5 int i, Nx, Ny, Xb, Yb, Normalize, N; 6 6 float Xmin, Xmax, dX, Ymin, Ymax, dY; 7 float *buf, *val , *x, *y, *z;7 float *buf, *val; 8 8 int *Nval; 9 9 Buffer *bf; 10 10 Vector *vx, *vy, *vz; 11 opihi_flt *x, *y, *z; 11 12 12 13 Normalize = TRUE; … … 28 29 if (vx[0].Nelements != vy[0].Nelements) return (FALSE); 29 30 if (vx[0].Nelements != vz[0].Nelements) return (FALSE); 31 32 REQUIRE_VECTOR_FLT (vx, FALSE); 33 REQUIRE_VECTOR_FLT (vy, FALSE); 34 REQUIRE_VECTOR_FLT (vz, FALSE); 30 35 31 36 Xmin = atof (argv[5]); … … 50 55 bzero (Nval, Nx*Ny*sizeof(int)); 51 56 52 x = vx[0].elements ;53 y = vy[0].elements ;54 z = vz[0].elements ;57 x = vx[0].elements.Flt; 58 y = vy[0].elements.Flt; 59 z = vz[0].elements.Flt; 55 60 for (i = 0; i < vx[0].Nelements; i++, x++, y++, z++) { 56 61 Xb = (*x - Xmin) / dX; -
trunk/Ohana/src/opihi/cmd.data/histogram.c
r18251 r20936 4 4 5 5 int i, bin, Nbins; 6 float *V, start, end, delta; 6 opihi_int *OUT; 7 opihi_flt start, end, delta; 7 8 Vector *xvec, *yvec; 8 9 … … 30 31 if ((xvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 31 32 if ((yvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) return (FALSE); 32 yvec[0].Nelements = Nbins; 33 34 REALLOCATE (yvec[0].elements, float, yvec[0].Nelements); 35 bzero (yvec[0].elements, sizeof(float)*yvec[0].Nelements); 36 if (Nbins < 1) { 37 return (TRUE); 33 34 ResetVector (yvec, OPIHI_INT, Nbins); 35 bzero (yvec[0].elements.Int, sizeof(opihi_int)*yvec[0].Nelements); 36 if (Nbins < 1) return (TRUE); 37 OUT = yvec[0].elements.Int; 38 39 if (xvec[0].type == OPIHI_FLT) { 40 opihi_flt *V = xvec[0].elements.Flt; 41 for (i = 0; i < xvec[0].Nelements; i++, V++) { 42 if (isnan(*V)) continue; 43 bin = MIN (MAX (0, (*V - start) / delta), Nbins - 1); 44 OUT[bin]++; 45 } 46 } else { 47 opihi_int *V = xvec[0].elements.Int; 48 for (i = 0; i < xvec[0].Nelements; i++, V++) { 49 if (isnan(*V)) continue; 50 bin = MIN (MAX (0, (*V - start) / delta), Nbins - 1); 51 OUT[bin]++; 52 } 38 53 } 39 40 V = xvec[0].elements;41 for (i = 0; i < xvec[0].Nelements; i++, V++) {42 if (isnan(*V)) continue;43 bin = MIN (MAX (0, (*V - start) / delta), Nbins - 1);44 yvec[0].elements[bin] += 1.0;45 }46 54 47 55 return (TRUE); -
trunk/Ohana/src/opihi/cmd.data/imcut.c
r7917 r20936 37 37 dY = dY / L; 38 38 39 REALLOCATE (xvec[0].elements, float, MAX (L, 1)); 40 REALLOCATE (yvec[0].elements, float, MAX (L, 1)); 41 xvec[0].Nelements = L; 42 yvec[0].Nelements = L; 39 ResetVector (xvec, OPIHI_FLT, MAX (L, 1)); 40 ResetVector (yvec, OPIHI_FLT, MAX (L, 1)); 43 41 44 42 V = (float *)buf[0].matrix.buffer; … … 46 44 xi = xs + i*dX - 0.5; 47 45 yi = ys + i*dY - 0.5; 48 xvec[0].elements [i] = i;49 yvec[0].elements [i] = V[xi + Nx*yi];46 xvec[0].elements.Flt[i] = i; 47 yvec[0].elements.Flt[i] = V[xi + Nx*yi]; 50 48 } 51 49 -
trunk/Ohana/src/opihi/cmd.data/imhist.c
r16429 r20936 105 105 } 106 106 107 vec1[0].Nelements = Nbins + 1; 108 vec2[0].Nelements = Nbins + 1; 109 REALLOCATE (vec1[0].elements, float, vec1[0].Nelements); 110 bzero (vec1[0].elements, vec1[0].Nelements*sizeof(float)); 111 REALLOCATE (vec2[0].elements, float, vec2[0].Nelements); 112 bzero (vec2[0].elements, vec2[0].Nelements*sizeof(float)); 107 ResetVector (vec1, OPIHI_FLT, Nbins + 1); 108 ResetVector (vec2, OPIHI_FLT, Nbins + 1); 109 bzero (vec1[0].elements.Flt, vec1[0].Nelements*sizeof(opihi_flt)); 110 bzero (vec2[0].elements.Flt, vec2[0].Nelements*sizeof(opihi_flt)); 113 111 114 112 for (j = sy; j < sy + ny; j++) { … … 116 114 for (i = 0; i < nx; i++, V++) { 117 115 bin = MAX (MIN (Nbins, (*V - min) / dx), 0); 118 vec2[0].elements [bin] += 1.0;116 vec2[0].elements.Flt[bin] += 1.0; 119 117 } 120 118 } 121 119 for (i = 0; i < Nbins + 1; i++, V++) { 122 vec1[0].elements [i] = i*dx + min;120 vec1[0].elements.Flt[i] = i*dx + min; 123 121 } 124 122 -
trunk/Ohana/src/opihi/cmd.data/integrate.c
r7917 r20936 3 3 int integrate (int argc, char **argv) { 4 4 5 int i, N, VERBOSE; 6 float *X, *Y; 7 double start, end, value, range; 5 int i, N, VERBOSE, isFloat; 6 opihi_flt *Yf; 7 opihi_int *Yi; 8 double start, end, value, range, dvalue; 8 9 Vector *vecx, *vecy; 9 10 … … 25 26 end = atof (argv[4]); 26 27 27 X = vecx[0].elements; 28 Y = vecy[0].elements; 28 isFloat = vecy[0].type == OPIHI_FLT; 29 Yf = vecy[0].elements.Flt; 30 Yi = vecy[0].elements.Int; 29 31 30 32 value = 0; 31 33 range = 0; 32 for (i = 0; i < vecx[0].Nelements-1; i++, X++, Y++) { 33 if ((*X >= start) && (*X <= end)) { 34 value += *Y * (X[1] - X[0]); 35 range += (X[1] - X[0]); 36 } 37 } 34 35 if (vecx[0].type == OPIHI_FLT) { 36 opihi_flt *X = vecx[0].elements.Flt; 37 for (i = 0; i < vecx[0].Nelements-1; i++, X++, Yi++, Yf++) { 38 if ((*X >= start) && (*X <= end)) { 39 dvalue = (isFloat) ? *Yf : *Yi; 40 value += dvalue * (X[1] - X[0]); 41 range += (X[1] - X[0]); 42 } 43 } 44 } else { 45 opihi_int *X = vecx[0].elements.Int; 46 for (i = 0; i < vecx[0].Nelements-1; i++, X++, Yi++, Yf++) { 47 if ((*X >= start) && (*X <= end)) { 48 dvalue = (isFloat) ? *Yf : *Yi; 49 value += dvalue * (X[1] - X[0]); 50 range += (X[1] - X[0]); 51 } 52 } 53 } 38 54 39 55 set_variable ("sum", value); -
trunk/Ohana/src/opihi/cmd.data/interpolate.c
r7917 r20936 21 21 if ((yout = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE); 22 22 23 yout[0].Nelements = xout[0].Nelements; 24 REALLOCATE (yout[0].elements, float, yout[0].Nelements); 23 REQUIRE_VECTOR_FLT (xin, FALSE); 24 REQUIRE_VECTOR_FLT (yin, FALSE); 25 REQUIRE_VECTOR_FLT (xout, FALSE); 26 ResetVector (yout, OPIHI_FLT, xout[0].Nelements); 25 27 26 dx = xin[0].elements [1] - xin[0].elements[0];27 dy = yin[0].elements [1] - yin[0].elements[0];28 x0 = xin[0].elements [0];29 y0 = yin[0].elements [0];28 dx = xin[0].elements.Flt[1] - xin[0].elements.Flt[0]; 29 dy = yin[0].elements.Flt[1] - yin[0].elements.Flt[0]; 30 x0 = xin[0].elements.Flt[0]; 31 y0 = yin[0].elements.Flt[0]; 30 32 31 33 /* in vectors are sorted, out vectors are not */ 32 34 for (j = 0; j < xin[0].Nelements - 1; j++) { 33 dx = xin[0].elements [j+1] - xin[0].elements[j];34 dy = yin[0].elements [j+1] - yin[0].elements[j];35 x0 = xin[0].elements [j];36 y0 = yin[0].elements [j];37 x1 = xin[0].elements [j+1];35 dx = xin[0].elements.Flt[j+1] - xin[0].elements.Flt[j]; 36 dy = yin[0].elements.Flt[j+1] - yin[0].elements.Flt[j]; 37 x0 = xin[0].elements.Flt[j]; 38 y0 = yin[0].elements.Flt[j]; 39 x1 = xin[0].elements.Flt[j+1]; 38 40 for (i = 0; i < xout[0].Nelements; i++) { 39 if ((xout[0].elements [i] >= x0) && (xout[0].elements[i] < x1)) {40 yout[0].elements [i] = (dy/dx)*(xout[0].elements[i] - x0) + y0;41 if ((xout[0].elements.Flt[i] >= x0) && (xout[0].elements.Flt[i] < x1)) { 42 yout[0].elements.Flt[i] = (dy/dx)*(xout[0].elements.Flt[i] - x0) + y0; 41 43 } 42 if ((j == 0) && (xout[0].elements [i] < x0)) {43 yout[0].elements [i] = (dy/dx)*(xout[0].elements[i] - x0) + y0;44 if ((j == 0) && (xout[0].elements.Flt[i] < x0)) { 45 yout[0].elements.Flt[i] = (dy/dx)*(xout[0].elements.Flt[i] - x0) + y0; 44 46 } 45 if ((j == xin[0].Nelements - 2) && (xout[0].elements [i] >= x1)) {46 yout[0].elements [i] = (dy/dx)*(xout[0].elements[i] - x0) + y0;47 if ((j == xin[0].Nelements - 2) && (xout[0].elements.Flt[i] >= x1)) { 48 yout[0].elements.Flt[i] = (dy/dx)*(xout[0].elements.Flt[i] - x0) + y0; 47 49 } 48 50 } -
trunk/Ohana/src/opihi/cmd.data/lookup.c
r7952 r20936 4 4 5 5 int i, j; 6 float *ip, *op, *xp, *yp;6 opihi_flt *ip, *op, *xp, *yp; 7 7 Vector *in, *out, *xv, *yv; 8 8 … … 17 17 if ((yv = SelectVector (argv[4], OLDVECTOR, TRUE)) == NULL) return (FALSE); 18 18 19 REQUIRE_VECTOR_FLT (in, FALSE); 20 REQUIRE_VECTOR_FLT (xv, FALSE); 21 REQUIRE_VECTOR_FLT (yv, FALSE); 22 19 23 if (xv[0].Nelements != yv[0].Nelements) { 20 24 gprint (GP_ERR, "unmatched lookup table lengths\n"); … … 22 26 } 23 27 24 out[0].Nelements = in[0].Nelements; 25 REALLOCATE (out[0].elements, float, out[0].Nelements); 28 ResetVector (out, OPIHI_FLT, in[0].Nelements); 26 29 27 ip = in[0].elements ;28 op = out[0].elements ;30 ip = in[0].elements.Flt; 31 op = out[0].elements.Flt; 29 32 30 33 for (i = 0; i < in[0].Nelements; i++, ip++, op++) { 31 34 // re-write this using bisection 32 xp = xv[0].elements ;33 yp = yv[0].elements ;35 xp = xv[0].elements.Flt; 36 yp = yv[0].elements.Flt; 34 37 35 38 for (j = 0; (*ip < *xp) && (j < yv[0].Nelements); j++); -
trunk/Ohana/src/opihi/cmd.data/medacc.c
r7917 r20936 5 5 int i, j, Nbins, Nvalues, N, N0, N1; 6 6 double start, end, delta, k0, k1, fn; 7 float *V, *K, *V1, *K1, *O, *tmpvec, *tmpkey;7 opihi_flt *V, *K, *V1, *K1, *O, *tmpvec, *tmpkey; 8 8 Vector *val, *key, *out; 9 9 … … 21 21 if ((out = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) return (FALSE); 22 22 23 REQUIRE_VECTOR_FLT (val, FALSE); 24 REQUIRE_VECTOR_FLT (key, FALSE); 25 23 26 start = atof (argv[4]); 24 27 end = atof (argv[5]); … … 34 37 Nbins = 1 + (int)((end - start) / delta); 35 38 36 out[0].Nelements = Nbins; 37 REALLOCATE (out[0].elements, float, out[0].Nelements); 38 bzero (out[0].elements, sizeof(float)*out[0].Nelements); 39 ResetVector (out, OPIHI_FLT, Nbins); 40 bzero (out[0].elements.Flt, sizeof(opihi_flt)*out[0].Nelements); 39 41 40 42 /* copy vec and key to temp vectors */ 41 ALLOCATE (tmpvec, float, val[0].Nelements);42 ALLOCATE (tmpkey, float, val[0].Nelements);43 ALLOCATE (tmpvec, opihi_flt, val[0].Nelements); 44 ALLOCATE (tmpkey, opihi_flt, val[0].Nelements); 43 45 44 V = val[0].elements ;45 K = key[0].elements ;46 V = val[0].elements.Flt; 47 K = key[0].elements.Flt; 46 48 V1 = tmpvec; 47 49 K1 = tmpkey; … … 53 55 54 56 /* sort vec and key by key */ 55 fsortpair (tmpkey, tmpvec, Nvalues);57 dsortpair (tmpkey, tmpvec, Nvalues); 56 58 57 O = out[0].elements ;59 O = out[0].elements.Flt; 58 60 /* find the start and end key for each range */ 59 61 N0 = 0; … … 67 69 N1 = j; 68 70 N = N1 - N0; 69 fsort (&tmpvec[N0], N);71 dsort (&tmpvec[N0], N); 70 72 fn = O[i] = 0; 71 73 for (j = N0 + 0.25*N; j < N0 + 0.75*N; j++) { -
trunk/Ohana/src/opihi/cmd.data/mget.c
r7917 r20936 4 4 5 5 int i, Nx, Ny, Npix, xdir, Nset; 6 float *in, *out; 6 float *in; 7 opihi_flt *out; 7 8 Buffer *buf; 8 9 Vector *vec; … … 32 33 33 34 if (xdir) { 34 vec[0].Nelements =Npix = Nx;35 R EALLOCATE (vec[0].elements, float, Npix);35 Npix = Nx; 36 ResetVector (vec, OPIHI_FLT, Nx); 36 37 if (Nset >= Ny) { 37 38 gprint (GP_ERR, "row out of range\n"); … … 39 40 } 40 41 in = (float *) buf[0].matrix.buffer + Nx*Nset; 41 out = vec[0].elements ;42 out = vec[0].elements.Flt; 42 43 for (i = 0; i < Npix; i++, in++, out++) { 43 44 *out = *in; 44 45 } 45 return (TRUE);46 46 } else { 47 vec[0].Nelements =Npix = Ny;48 R EALLOCATE (vec[0].elements, float, Npix);47 Npix = Ny; 48 ResetVector (vec, OPIHI_FLT, Ny); 49 49 if (Nset >= Nx) { 50 50 gprint (GP_ERR, "column out of range\n"); … … 52 52 } 53 53 in = (float *) buf[0].matrix.buffer + Nset; 54 out = vec[0].elements ;54 out = vec[0].elements.Flt; 55 55 for (i = 0; i < Npix; i++, in+=Nx, out++) { 56 56 *out = *in; 57 57 } 58 return (TRUE);59 }58 } 59 return (TRUE); 60 60 } 61 -
trunk/Ohana/src/opihi/cmd.data/mset.c
r7917 r20936 4 4 5 5 int i, Nx, Ny, Npix, xdir, Nset; 6 float * in, *out;6 float *out; 7 7 Buffer *buf; 8 8 Vector *vec; … … 42 42 } 43 43 out = (float *) buf[0].matrix.buffer + Nx*Nset; 44 in = vec[0].elements; 45 for (i = 0; i < Npix; i++, in++, out++) { 46 *out = *in; 44 45 if (vec[0].type == OPIHI_FLT) { 46 opihi_flt *in = vec[0].elements.Flt; 47 for (i = 0; i < Npix; i++, in++, out++) { 48 *out = *in; 49 } 50 } else { 51 opihi_int *in = vec[0].elements.Int; 52 for (i = 0; i < Npix; i++, in++, out++) { 53 *out = *in; 54 } 47 55 } 48 56 return (TRUE); 57 49 58 } else { 50 59 if (Ny != Npix) { … … 57 66 } 58 67 out = (float *) buf[0].matrix.buffer + Nset; 59 in = vec[0].elements; 60 for (i = 0; i < Npix; i++, in++, out+=Nx) { 61 *out = *in; 68 69 if (vec[0].type == OPIHI_FLT) { 70 opihi_flt *in = vec[0].elements.Flt; 71 for (i = 0; i < Npix; i++, in++, out+=Nx) { 72 *out = *in; 73 } 74 } else { 75 opihi_int *in = vec[0].elements.Int; 76 for (i = 0; i < Npix; i++, in++, out+=Nx) { 77 *out = *in; 78 } 62 79 } 63 80 return (TRUE); -
trunk/Ohana/src/opihi/cmd.data/peak.c
r7917 r20936 5 5 int i, N, imax, QUIET; 6 6 double start, end, xmax, ymax; 7 float *X, *Y;8 7 Vector *vecx, *vecy; 9 8 … … 26 25 end = atof (argv[4]); 27 26 } else { 28 start = vecx[0].elements[0];29 end = vecx[0].elements[vecx[0].Nelements - 1];27 start = (vecx[0].type == OPIHI_FLT) ? vecx[0].elements.Flt[0] : vecx[0].elements.Int[0]; 28 end = (vecx[0].type == OPIHI_FLT) ? vecx[0].elements.Flt[vecx[0].Nelements - 1] : vecx[0].elements.Int[vecx[0].Nelements - 1]; 30 29 } 31 30 32 X = vecx[0].elements; 33 Y = vecy[0].elements; 31 imax = -1; 32 xmax = -HUGE_VAL; 33 ymax = -HUGE_VAL; 34 34 35 imax = -1; 36 xmax = *X; 37 ymax = *Y; 38 for (i = 1; i < vecx[0].Nelements-1; i++, X++, Y++) { 39 if ((*X >= start) && (*X <= end)) { 40 if ((imax == -1) || (*Y > ymax)) { 41 xmax = *X; 42 ymax = *Y; 43 imax = i; 44 } 45 } 46 } 35 if ((vecx[0].type == OPIHI_FLT) && (vecy[0].type == OPIHI_FLT)) { 36 opihi_flt *X = vecx[0].elements.Flt; 37 opihi_flt *Y = vecy[0].elements.Flt; 38 for (i = 0; i < vecx[0].Nelements; i++, X++, Y++) { 39 if (*X < start) continue; 40 if (*X > end) continue; 41 if (*Y < ymax) continue; 42 xmax = *X; 43 ymax = *Y; 44 imax = i; 45 } 46 } 47 if ((vecx[0].type == OPIHI_FLT) && (vecy[0].type == OPIHI_INT)) { 48 opihi_flt *X = vecx[0].elements.Flt; 49 opihi_int *Y = vecy[0].elements.Int; 50 for (i = 0; i < vecx[0].Nelements; i++, X++, Y++) { 51 if (*X < start) continue; 52 if (*X > end) continue; 53 if (*Y < ymax) continue; 54 xmax = *X; 55 ymax = *Y; 56 imax = i; 57 } 58 } 59 if ((vecx[0].type == OPIHI_INT) && (vecy[0].type == OPIHI_FLT)) { 60 opihi_int *X = vecx[0].elements.Int; 61 opihi_flt *Y = vecy[0].elements.Flt; 62 for (i = 0; i < vecx[0].Nelements; i++, X++, Y++) { 63 if (*X < start) continue; 64 if (*X > end) continue; 65 if (*Y < ymax) continue; 66 xmax = *X; 67 ymax = *Y; 68 imax = i; 69 } 70 } 71 if ((vecx[0].type == OPIHI_INT) && (vecy[0].type == OPIHI_INT)) { 72 opihi_int *X = vecx[0].elements.Int; 73 opihi_int *Y = vecy[0].elements.Int; 74 for (i = 0; i < vecx[0].Nelements; i++, X++, Y++) { 75 if (*X < start) continue; 76 if (*X > end) continue; 77 if (*Y < ymax) continue; 78 xmax = *X; 79 ymax = *Y; 80 imax = i; 81 } 82 } 47 83 48 84 set_variable ("peakval", ymax); -
trunk/Ohana/src/opihi/cmd.data/periodogram.c
r7917 r20936 4 4 5 5 int i, N, Npt, Np, NP, VERBOSE; 6 float *tv, *fv;6 opihi_flt *tv, *fv; 7 7 float minP, maxP, minT, maxT, dTime; 8 8 float mean, var, w, tau, P, Pc, Ps, Po; … … 28 28 if ((power = SelectVector (argv[6], ANYVECTOR, TRUE)) == NULL) return (FALSE); 29 29 30 REQUIRE_VECTOR_FLT (time, FALSE); 31 REQUIRE_VECTOR_FLT (flux, FALSE); 32 30 33 /* find the max baseline, mean, and variance */ 31 minT = maxT = time[0].elements [0];34 minT = maxT = time[0].elements.Flt[0]; 32 35 Npt = time[0].Nelements; 33 tv = time[0].elements ;34 fv = flux[0].elements ;36 tv = time[0].elements.Flt; 37 fv = flux[0].elements.Flt; 35 38 mean = var = 0; 36 39 for (i = 0; i < Npt; i++, tv++, fv++) { … … 40 43 } 41 44 mean = mean / Npt; 42 fv = flux[0].elements ;45 fv = flux[0].elements.Flt; 43 46 for (i = 0; i < Npt; i++, fv++) { 44 47 var += SQ(*fv - mean); … … 56 59 Np = 0; 57 60 NP = 100; 58 R EALLOCATE (power[0].elements, float, NP);59 R EALLOCATE (period[0].elements, float, NP);61 ResetVector (power, OPIHI_FLT, NP); 62 ResetVector (period, OPIHI_FLT, NP); 60 63 61 64 P = minP; … … 64 67 65 68 /* find the period offset tau */ 66 tv = time[0].elements ;69 tv = time[0].elements.Flt; 67 70 cs = sn = 0; 68 71 for (i = 0; i < Npt; i++, tv++) { … … 73 76 74 77 /* find the power at this period */ 75 tv = time[0].elements ;76 fv = flux[0].elements ;78 tv = time[0].elements.Flt; 79 fv = flux[0].elements.Flt; 77 80 cs = sn = cs2 = sn2 = 0; 78 81 for (i = 0; i < Npt; i++, tv++, fv++) { … … 90 93 Po = (Pc + Ps) / (2*var); 91 94 92 power[0].elements [Np] = Po;93 period[0].elements [Np] = P;95 power[0].elements.Flt[Np] = Po; 96 period[0].elements.Flt[Np] = P; 94 97 Np ++; 95 98 if (Np >= NP) { 96 99 NP += 100; 97 REALLOCATE (power[0].elements , float, NP);98 REALLOCATE (period[0].elements , float, NP);100 REALLOCATE (power[0].elements.Flt, opihi_flt, NP); 101 REALLOCATE (period[0].elements.Flt, opihi_flt, NP); 99 102 } 100 103 … … 106 109 } 107 110 108 power[0].Nelements = Np; 109 period[0].Nelements = Np; 110 REALLOCATE (power[0].elements, float, Np); 111 REALLOCATE (period[0].elements, float, Np); 111 ResetVector (power, OPIHI_FLT, Np); 112 ResetVector (period, OPIHI_FLT, Np); 112 113 113 114 return (TRUE); -
trunk/Ohana/src/opihi/cmd.data/plot.c
r13479 r20936 58 58 if (!KapaPrepPlot (kapa, Npts, &graphmode)) return (FALSE); 59 59 60 KapaPlotVector (kapa, Npts, xvec[0].elements, "x");61 KapaPlotVector (kapa, Npts, yvec[0].elements, "y");60 PlotVectorSingle (kapa, xvec, "x"); 61 PlotVectorSingle (kapa, yvec, "y"); 62 62 if (graphmode.etype & 0x01) { 63 KapaPlotVector (kapa, Npts, dymvec[0].elements, "dym");64 KapaPlotVector (kapa, Npts, dypvec[0].elements, "dyp");63 PlotVectorSingle (kapa, dymvec, "dym"); 64 PlotVectorSingle (kapa, dypvec, "dyp"); 65 65 } 66 66 if (graphmode.etype & 0x02) { 67 KapaPlotVector (kapa, Npts, dxmvec[0].elements, "dxm");68 KapaPlotVector (kapa, Npts, dxpvec[0].elements, "dxp");67 PlotVectorSingle (kapa, dxmvec, "dxm"); 68 PlotVectorSingle (kapa, dxpvec, "dxp"); 69 69 } 70 70 return (TRUE); -
trunk/Ohana/src/opihi/cmd.data/read_vectors.c
r17070 r20936 70 70 return (FALSE); 71 71 } 72 // XXX we could allow flags (eg, N.i) to specify INT vs FLT types vectors... 72 73 colstr = argv[2*i+2]; 73 74 for (j = 0; j < strlen (colstr); j++) { … … 81 82 col[i] = atof (colstr); 82 83 } 83 84 85 // currently, all read vectors are forced to be type FLT 84 86 NELEM = 1000; 85 87 for (i = 0; i < Nvec; i++) { 86 R EALLOCATE (vec[i][0].elements, float, NELEM);88 ResetVector (vec[i], OPIHI_FLT, NELEM); 87 89 } 88 90 … … 121 123 for (i = 0; (i < Nvec) && status; i++) { 122 124 status = dparse (&value, col[i], c0); 123 vec[i][0].elements [N] = value;124 if (!status) vec[i][0].elements [N] = 0.0/0.0;125 vec[i][0].elements.Flt[N] = value; 126 if (!status) vec[i][0].elements.Flt[N] = NAN; 125 127 } 126 128 if (status) N++; … … 130 132 NELEM += 1000; 131 133 for (i = 0; i < Nvec; i++) { 132 REALLOCATE (vec[i][0].elements , float, NELEM);134 REALLOCATE (vec[i][0].elements.Flt, opihi_flt, NELEM); 133 135 } 134 136 } … … 137 139 } 138 140 for (i = 0; i < Nvec; i++) { 139 REALLOCATE (vec[i][0].elements , float, MAX (N,1));141 REALLOCATE (vec[i][0].elements.Flt, opihi_flt, MAX (N,1)); 140 142 vec[i][0].Nelements = N; 141 143 } … … 157 159 int read_table_vectors (int argc, char **argv, char *extname) { 158 160 159 int i, j, k, N, Nbytes, Nextend, Ny, Binary ;161 int i, j, k, N, Nbytes, Nextend, Ny, Binary, vecType; 160 162 char type[16], ID[80], *CCDKeyword; 161 163 FTable table; … … 260 262 } 261 263 if (Nval == 0) ESCAPE ("no data for field in table"); 262 264 265 vecType = OPIHI_INT; 266 if (!strcmp (type, "double") || !strcmp (type, "float")) { 267 vecType = OPIHI_FLT; 268 } 269 270 // define the multifield vector names 263 271 ALLOCATE (vec, Vector *, Nval); 264 272 for (j = 0; j < Nval; j++) { … … 268 276 sprintf (name, "%s:%d", argv[i], j); 269 277 if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name"); 270 REALLOCATE (vec[j][0].elements, float, MAX (Ny,1)); 271 vec[j][0].Nelements = Ny; 278 ResetVector (vec[j], vecType, MAX (Ny,1)); 272 279 } 273 280 … … 276 283 for (j = 0; j < Ny; j++) { 277 284 for (k = 0; k < Nval; k++, Pd++) { 278 vec[k][0].elements [j] = *Pd;285 vec[k][0].elements.Flt[j] = *Pd; 279 286 } 280 287 } … … 284 291 for (j = 0; j < Ny; j++) { 285 292 for (k = 0; k < Nval; k++, Pf++) { 286 vec[k][0].elements [j] = *Pf;293 vec[k][0].elements.Flt[j] = *Pf; 287 294 } 288 295 } … … 292 299 for (j = 0; j < Ny; j++) { 293 300 for (k = 0; k < Nval; k++, Pi++) { 294 vec[k][0].elements [j] = *Pi;301 vec[k][0].elements.Int[j] = *Pi; 295 302 } 296 303 } … … 300 307 for (j = 0; j < Ny; j++) { 301 308 for (k = 0; k < Nval; k++, Ps++) { 302 vec[k][0].elements [j] = *Ps;309 vec[k][0].elements.Int[j] = *Ps; 303 310 } 304 311 } … … 308 315 for (j = 0; j < Ny; j++) { 309 316 for (k = 0; k < Nval; k++, Pc++) { 310 vec[k][0].elements [j] = *Pc;317 vec[k][0].elements.Int[j] = *Pc; 311 318 } 312 319 } -
trunk/Ohana/src/opihi/cmd.data/select.c
r7917 r20936 27 27 /* check size of in1, in2, tvec: must match */ 28 28 29 REALLOCATE (ovec[0].elements, float, MAX (tvec[0].Nelements, 1)); 30 for (i = 0; i < tvec[0].Nelements; i++) { 31 ovec[0].elements[i] = tvec[0].elements[i] ? in1[0].elements[i] : in2[0].elements[i]; 29 if ((in1->type == OPIHI_INT) && (in2->type == OPIHI_INT)) { 30 ResetVector (ovec, OPIHI_INT, MAX (tvec[0].Nelements, 1)); 31 } else { 32 ResetVector (ovec, OPIHI_FLT, MAX (tvec[0].Nelements, 1)); 32 33 } 33 ovec[0].Nelements = tvec[0].Nelements; 34 REALLOCATE (ovec[0].elements, float, MAX (ovec[0].Nelements, 1)); 34 35 // (in1 and in2) == (flt or int) and tvec == (flt or int) 36 if ((in1->type == OPIHI_FLT) && (in2->type == OPIHI_FLT) && (tvec->type == OPIHI_FLT)) { 37 for (i = 0; i < tvec[0].Nelements; i++) { 38 ovec[0].elements.Flt[i] = tvec[0].elements.Flt[i] ? in1[0].elements.Flt[i] : in2[0].elements.Flt[i]; 39 } 40 } 41 if ((in1->type == OPIHI_FLT) && (in2->type == OPIHI_FLT) && (tvec->type == OPIHI_INT)) { 42 for (i = 0; i < tvec[0].Nelements; i++) { 43 ovec[0].elements.Flt[i] = tvec[0].elements.Int[i] ? in1[0].elements.Flt[i] : in2[0].elements.Flt[i]; 44 } 45 } 46 if ((in1->type == OPIHI_INT) && (in2->type == OPIHI_FLT) && (tvec->type == OPIHI_FLT)) { 47 for (i = 0; i < tvec[0].Nelements; i++) { 48 ovec[0].elements.Flt[i] = tvec[0].elements.Flt[i] ? in1[0].elements.Int[i] : in2[0].elements.Flt[i]; 49 } 50 } 51 if ((in1->type == OPIHI_INT) && (in2->type == OPIHI_FLT) && (tvec->type == OPIHI_INT)) { 52 for (i = 0; i < tvec[0].Nelements; i++) { 53 ovec[0].elements.Flt[i] = tvec[0].elements.Int[i] ? in1[0].elements.Int[i] : in2[0].elements.Flt[i]; 54 } 55 } 56 if ((in1->type == OPIHI_FLT) && (in2->type == OPIHI_INT) && (tvec->type == OPIHI_FLT)) { 57 for (i = 0; i < tvec[0].Nelements; i++) { 58 ovec[0].elements.Flt[i] = tvec[0].elements.Flt[i] ? in1[0].elements.Flt[i] : in2[0].elements.Int[i]; 59 } 60 } 61 if ((in1->type == OPIHI_FLT) && (in2->type == OPIHI_INT) && (tvec->type == OPIHI_INT)) { 62 for (i = 0; i < tvec[0].Nelements; i++) { 63 ovec[0].elements.Flt[i] = tvec[0].elements.Int[i] ? in1[0].elements.Flt[i] : in2[0].elements.Int[i]; 64 } 65 } 66 if ((in1->type == OPIHI_INT) && (in2->type == OPIHI_INT) && (tvec->type == OPIHI_FLT)) { 67 for (i = 0; i < tvec[0].Nelements; i++) { 68 ovec[0].elements.Int[i] = tvec[0].elements.Flt[i] ? in1[0].elements.Int[i] : in2[0].elements.Int[i]; 69 } 70 } 71 if ((in1->type == OPIHI_INT) && (in2->type == OPIHI_INT) && (tvec->type == OPIHI_INT)) { 72 for (i = 0; i < tvec[0].Nelements; i++) { 73 ovec[0].elements.Int[i] = tvec[0].elements.Int[i] ? in1[0].elements.Int[i] : in2[0].elements.Int[i]; 74 } 75 } 35 76 36 77 DeleteVector (tvec); -
trunk/Ohana/src/opihi/cmd.data/sort.c
r7917 r20936 1 1 # include "data.h" 2 2 3 void fsortindex (opihi_flt *X, int *IDX, int N) { 4 5 # define SWAPFUNC(A,B){ opihi_flt tmp; int itmp; \ 6 tmp = X[A]; X[A] = X[B]; X[B] = tmp; \ 7 itmp = IDX[A]; IDX[A] = IDX[B]; IDX[B] = itmp; \ 8 } 9 # define COMPARE(A,B)(X[A] < X[B]) 10 11 OHANA_SORT (N, COMPARE, SWAPFUNC); 12 13 # undef SWAPFUNC 14 # undef COMPARE 15 16 } 17 18 void isortindex (opihi_int *X, int *IDX, int N) { 19 20 # define SWAPFUNC(A,B){ opihi_int tmp; int itmp; \ 21 tmp = X[A]; X[A] = X[B]; X[B] = tmp; \ 22 itmp = IDX[A]; IDX[A] = IDX[B]; IDX[B] = itmp; \ 23 } 24 # define COMPARE(A,B)(X[A] < X[B]) 25 26 OHANA_SORT (N, COMPARE, SWAPFUNC); 27 28 # undef SWAPFUNC 29 # undef COMPARE 30 31 } 32 33 // XXX add an option to NOT sort, but return an index instead? 3 34 int sort_vectors (int argc, char **argv) { 4 35 5 36 int i, j, Nvec, Nval; 6 float *temp, *index, *T, *V, *I; 37 opihi_flt *ftemp; 38 opihi_int *itemp; 39 int *index, *I; 7 40 Vector **vec; 8 41 … … 35 68 } 36 69 37 /* create index (use float to use sortpair)*/38 ALLOCATE (index, float, Nval);70 /* create index */ 71 ALLOCATE (index, int, Nval); 39 72 for (i = 0; i < Nval; i++) index[i] = i; 40 73 41 74 /* sort key & index */ 42 fsortpair (vec[0][0].elements, index, Nval); 75 if (vec[0][0].type == OPIHI_FLT) { 76 fsortindex (vec[0][0].elements.Flt, index, Nval); 77 } else { 78 isortindex (vec[0][0].elements.Int, index, Nval); 79 } 43 80 44 ALLOCATE (temp, float, Nval); 81 ALLOCATE (ftemp, opihi_flt, Nval); 82 ALLOCATE (itemp, opihi_int, Nval); 83 45 84 for (i = 1; i < Nvec; i++) { 46 T = temp; 47 V = vec[i][0].elements; 48 I = index; 49 for (j = 0; j < Nval; j++, T++, I++) { 50 *T = V[(int)(*I)]; 85 if (vec[i][0].type == OPIHI_FLT) { 86 opihi_flt *T = ftemp; 87 opihi_flt *V = vec[i][0].elements.Flt; 88 I = index; 89 for (j = 0; j < Nval; j++, T++, I++) { 90 *T = V[*I]; 91 } 92 /* swap .elements.Flt (== V) and ftemp */ 93 vec[i][0].elements.Flt = ftemp; 94 ftemp = V; 95 } else { 96 opihi_int *T = itemp; 97 opihi_int *V = vec[i][0].elements.Int; 98 I = index; 99 for (j = 0; j < Nval; j++, T++, I++) { 100 *T = V[*I]; 101 } 102 /* swap .elements.Flt (== V) and itemp */ 103 vec[i][0].elements.Int = itemp; 104 itemp = V; 51 105 } 52 /* swap .elements (== V) and temp */53 vec[i][0].elements = temp;54 temp = V;55 106 } 56 free (temp); 107 free (itemp); 108 free (ftemp); 57 109 free (vec); 58 110 free (index); … … 61 113 62 114 } 63 64 -
trunk/Ohana/src/opihi/cmd.data/subset.c
r7917 r20936 6 6 7 7 char *out; 8 int i, j, size;8 int i, Npts, size; 9 9 Vector *ivec, *ovec, *tvec; 10 10 … … 28 28 /* check size of ivec, tvec: must match */ 29 29 30 REALLOCATE (ovec[0].elements, float, MAX (tvec[0].Nelements, 1)); 31 for (j = i = 0; i < tvec[0].Nelements; i++) { 32 if (tvec[0].elements[i]) { 33 ovec[0].elements[j] = ivec[0].elements[i]; 34 j++; 30 // ovec matches ivec in type 31 ResetVector (ovec, ivec->type, MAX (tvec[0].Nelements, 1)); 32 33 // we have four cases: (ivec == flt or int) and (tvec == flt or int) 34 if ((ivec->type == OPIHI_FLT) && (tvec->type == OPIHI_FLT)) { 35 opihi_flt *vi = ivec[0].elements.Flt; 36 opihi_flt *vt = tvec[0].elements.Flt; 37 for (Npts = i = 0; i < tvec[0].Nelements; i++, vi++, vt++) { 38 if (!*vt) continue; 39 ovec[0].elements.Flt[Npts] = *vi; 40 Npts++; 35 41 } 36 42 } 37 ovec[0].Nelements = j; 38 REALLOCATE (ovec[0].elements, float, MAX (ovec[0].Nelements, 1)); 43 if ((ivec->type == OPIHI_FLT) && (tvec->type == OPIHI_INT)) { 44 opihi_flt *vi = ivec[0].elements.Flt; 45 opihi_int *vt = tvec[0].elements.Int; 46 for (Npts = i = 0; i < tvec[0].Nelements; i++, vi++, vt++) { 47 if (!*vt) continue; 48 ovec[0].elements.Flt[Npts] = *vi; 49 Npts++; 50 } 51 } 52 if ((ivec->type == OPIHI_INT) && (tvec->type == OPIHI_FLT)) { 53 opihi_int *vi = ivec[0].elements.Int; 54 opihi_flt *vt = tvec[0].elements.Flt; 55 for (Npts = i = 0; i < tvec[0].Nelements; i++, vi++, vt++) { 56 if (!*vt) continue; 57 ovec[0].elements.Int[Npts] = *vi; 58 Npts++; 59 } 60 } 61 if ((ivec->type == OPIHI_INT) && (tvec->type == OPIHI_INT)) { 62 opihi_int *vi = ivec[0].elements.Int; 63 opihi_int *vt = tvec[0].elements.Int; 64 for (Npts = i = 0; i < tvec[0].Nelements; i++, vi++, vt++) { 65 if (!*vt) continue; 66 ovec[0].elements.Int[Npts] = *vi; 67 Npts++; 68 } 69 } 70 71 // free up unused memory 72 ResetVector (ovec, ivec->type, MAX (Npts, 1)); 39 73 40 74 DeleteVector (tvec); -
trunk/Ohana/src/opihi/cmd.data/svd.c
r7917 r20936 4 4 5 5 int i, Nx, Ny, status; 6 float *in, *out, *A, *U, *W, *V; 6 float *in, *out, *A, *U, *V; 7 Buffer *Ma, *Mu, *Mv; 7 8 Vector *Vw; 8 Buffer *Ma, *Mu, *Mv;9 opihi_flt *W; 9 10 10 11 if (argc != 6) goto usage; … … 42 43 43 44 /* w is Nx */ 44 Vw[0].Nelements = Nx; 45 REALLOCATE (Vw[0].elements, float, Nx); 45 ResetVector (Vw, OPIHI_FLT, Nx); 46 46 47 47 /* pointers to the various arrays */ 48 48 A = (float *) Ma[0].matrix.buffer; 49 49 U = (float *) Mu[0].matrix.buffer; 50 W = (float *) Vw[0].elements;51 50 V = (float *) Mv[0].matrix.buffer; 51 W = Vw[0].elements.Flt; 52 52 53 53 /* copy A to U (svdcmp replaces A with U) */ -
trunk/Ohana/src/opihi/cmd.data/test/applyfit2d.sh
r16056 r20936 32 32 33 33 # Memory test 34 # NOTE: requires test1 to be run first 34 35 macro memtest1 35 36 … … 48 49 $PASS = 1 49 50 50 if ( $endmem - $startmem > 10)51 if (($endmem - $startmem)/1000 > 1.0) 51 52 $PASS = 0 52 53 echo "growth: {$endmem-$startmem}" -
trunk/Ohana/src/opihi/cmd.data/test/fit.sh
r16431 r20936 47 47 if ($Cn != 1) 48 48 $PASS = 0 49 end 50 if (abs($C0 - 3) > 0.01) 51 $PASS = 0 52 end 53 if (abs($C1 - 5) > 0.01) 54 $PASS = 0 49 echo "wrong number of elements : $Cn" 50 end 51 if (abs($C0 - 3) > 0.06) 52 $PASS = 0 53 echo "wrong value for C0 : $C0" 54 end 55 if (abs($C1 - 5) > 0.06) 56 $PASS = 0 57 echo "wrong value for C1 : $C1" 55 58 end 56 59 end … … 72 75 $PASS = 0 73 76 end 74 if (abs($C0 - 3) > 0.0 2)75 $PASS = 0 76 end 77 if (abs($C1 - 5) > 0.0 2)77 if (abs($C0 - 3) > 0.06) 78 $PASS = 0 79 end 80 if (abs($C1 - 5) > 0.06) 78 81 $PASS = 0 79 82 end … … 102 105 $PASS = 0 103 106 end 104 if (abs($C0 - 3) > 0.0 2)105 $PASS = 0 106 end 107 if (abs($C1 - 5) > 0.0 2)107 if (abs($C0 - 3) > 0.06) 108 $PASS = 0 109 end 110 if (abs($C1 - 5) > 0.06) 108 111 $PASS = 0 109 112 end … … 150 153 $PASS = 0 151 154 end 152 if (abs($C0 - 3) > 0.0 5)153 $PASS = 0 154 end 155 if (abs($C1 - 5) > 0.0 5)156 $PASS = 0 157 end 158 if (abs($C2 + 4) > 0.0 5)155 if (abs($C0 - 3) > 0.06) 156 $PASS = 0 157 end 158 if (abs($C1 - 5) > 0.06) 159 $PASS = 0 160 end 161 if (abs($C2 + 4) > 0.06) 159 162 $PASS = 0 160 163 end … … 177 180 $PASS = 0 178 181 end 179 if (abs($C0 - 3) > 0.0 5)180 $PASS = 0 181 end 182 if (abs($C1 - 5) > 0.0 5)183 $PASS = 0 184 end 185 if (abs($C2 + 4) > 0.0 5)182 if (abs($C0 - 3) > 0.06) 183 $PASS = 0 184 end 185 if (abs($C1 - 5) > 0.06) 186 $PASS = 0 187 end 188 if (abs($C2 + 4) > 0.06) 186 189 $PASS = 0 187 190 end … … 212 215 $PASS = 0 213 216 end 214 if (abs($C0 - 3) > 0.0 5)215 $PASS = 0 216 end 217 if (abs($C1 - 5) > 0.0 5)218 $PASS = 0 219 end 220 if (abs($C2 + 4) > 0.0 5)221 $PASS = 0 222 end 223 end 217 if (abs($C0 - 3) > 0.06) 218 $PASS = 0 219 end 220 if (abs($C1 - 5) > 0.06) 221 $PASS = 0 222 end 223 if (abs($C2 + 4) > 0.06) 224 $PASS = 0 225 end 226 end -
trunk/Ohana/src/opihi/cmd.data/test/gaussj.sh
r16269 r20936 232 232 for i 0 B[] 233 233 for j 0 B[] 234 # echo $i $j meas[$i] inA[$i][$j] B[$j] {inA[$i][$j] * B[$j]} {meas[$i] + inA[$i][$j] * B[$j]} 234 235 meas[$i] = meas[$i] + inA[$i][$j] * B[$j] 236 # echo "-> meas[$i]" 235 237 end 236 238 end … … 238 240 for i 0 inB[] 239 241 if (abs(inB[$i]-meas[$i]) > 1e-5) 242 echo inB[$i] meas[$i] {abs(inB[$i]-meas[$i])} 240 243 $PASS = 0 241 244 end -
trunk/Ohana/src/opihi/cmd.data/test/histogram.sh
r16056 r20936 12 12 local i 13 13 14 create x 0 10 0.1 14 # set data values at the i*0.1 + 0.05 values so round-off does not causs miscounts 15 create x 0.05 10.05 0.1 15 16 16 17 for i 45 55 … … 18 19 end 19 20 21 # histogram bins are 0-0.1, 0.1-0.2, etc 20 22 histogram x xhis 0 10 0.1 21 23 -
trunk/Ohana/src/opihi/cmd.data/test/peak.sh
r14176 r20936 21 21 $PASS = 0 22 22 end 23 if ($peaknum != 5 1)23 if ($peaknum != 50) 24 24 $PASS = 0 25 25 end … … 43 43 $PASS = 0 44 44 end 45 if ($peaknum != 5 1)45 if ($peaknum != 50) 46 46 $PASS = 0 47 47 end … … 67 67 $PASS = 0 68 68 end 69 if ($peaknum != 5 1)69 if ($peaknum != 50) 70 70 $PASS = 0 71 71 end -
trunk/Ohana/src/opihi/cmd.data/test/vgauss.sh
r10069 r20936 20 20 21 21 vgauss -q x y dy yfit 22 # lim x y; clear; box; plot -x 1 -c black x y; plot -c red x yfit 23 # cursor 22 24 23 25 if (abs($C0 - 0.0) > 0.01) … … 51 53 52 54 vgauss -q x y dy yfit 55 # lim x y; clear; box; plot -x 1 -c black x y; plot -c red x yfit 56 # cursor 53 57 54 58 if (abs($C0 - 0.0) > 0.01) … … 71 75 break -auto off 72 76 77 $C0o = 0.5 78 $C1o = 2 79 $C2o = 900 80 $C3o = 1 81 73 82 create x -10 10 0.1 74 set y = 1000 * exp(-0.5*x^2/3^2)83 set y = $C3o + $C2o * exp(-0.5*(x - $C0o)^2/$C1o^2) 75 84 76 85 gaussdev dY y[] 0.0 1.0 … … 78 87 set y = y + dy 79 88 80 $C0 = 0.581 $C1 = 282 $C2 = 90083 $C3 = 189 $C0 = $C0o + 2 90 $C1 = $C1o + 2 91 $C2 = $C2o + 50 92 $C3 = $C3o + 10 84 93 85 94 vgauss -q x y dy yfit 95 # lim x y; clear; box; plot -x 1 -c black x y; plot -c red x yfit 96 # cursor 86 97 87 if (abs($C0 - 0.0) > 0.01) 98 $dS = 3.0 / sqrt(y[]) 99 100 if (abs($C0 - $C0o) > $dS) 88 101 $PASS = 0 89 102 end 90 if (abs($C1 - 3.0) > 0.01)103 if (abs($C1 - $C1o)/$C1o > $dS) 91 104 $PASS = 0 92 105 end 93 if (abs($C2 - 1000.0) > 1)106 if (abs($C2 - $C2o)/$C2o > $dS) 94 107 $PASS = 0 95 108 end 96 if (abs($C3 - 0.0) > 0.2)109 if (abs($C3 - $C3o) > $dS) 97 110 $PASS = 0 98 111 end -
trunk/Ohana/src/opihi/cmd.data/test/vmaxwell.sh
r10069 r20936 40 40 break -auto off 41 41 42 $C0o = 250 43 $C1o = 25 44 $C2o = 100 45 $C3o = 1 46 $C4o = 10 47 42 48 create x 0 1000 1 43 set y = 1000 * (x-200)^2 * exp(-0.5*(x-300)^2/30^2) 44 set dy = (rnd(y) - 0.5)/0.5 49 set y = $C2o * (x-$C4o)^2 * exp(-0.5*(x-$C0o)^2/$C1o^2) + $C3o 50 gaussdev dY y[] 0.0 1.0 51 set dy = dY * sqrt(y) 45 52 set y = y + dy 46 53 47 lim x y; clear; box; plot -x 1 -c black x y 54 $C0 = $C0o + 20 55 $C1 = $C1o + 2 56 $C2 = $C2o + 100 57 $C3 = $C3o + 10 58 $C4 = $C4o + 20 48 59 49 $C0 = 250 50 $C1 = 25 51 $C2 = 900 52 $C3 = 1 53 $C4 = 190 60 vmaxwell -q x y dy yfit 61 lim x y; clear; box; plot -x 1 -c black x y; plot x yfit -c red 54 62 55 vmaxwell x y dy yfit 56 plot x yfit -c red 63 $dS = 6.0 / sqrt(y[]) 57 64 58 if (abs($C0 - 0.0) > 0.01)65 if (abs($C0 - $C0o) > $dS) 59 66 $PASS = 0 60 67 end 61 if (abs($C1 - 3.0) > 0.01)68 if (abs($C1 - $C1o)/$C1o > $dS) 62 69 $PASS = 0 63 70 end 64 if (abs($C2 - 1000.0) > 0.1)71 if (abs($C2 - $C2o)/$C2o > $dS) 65 72 $PASS = 0 66 73 end 67 if (abs($C3 - 0.0) > 0.1) 74 if (abs($C3 - $C3o) > $dS) 75 $PASS = 0 76 end 77 if (abs($C4 - $C4o)/$C4o > $dS) 68 78 $PASS = 0 69 79 end -
trunk/Ohana/src/opihi/cmd.data/ungridify.c
r7917 r20936 1 1 # include "data.h" 2 2 3 // XXX adapt this to accept an optional region to limit the areas, otherwise use the whole image 3 4 int ungridify (int argc, char **argv) { 4 5 … … 6 7 int Nx, Ny, NX, NY; 7 8 int Xmin, Xmax, Ymin, Ymax; 8 float *v, *x, *y, *z;9 9 Buffer *bf; 10 float *v; 10 11 Vector *vx, *vy, *vz; 12 opihi_flt *x, *y, *z; 11 13 12 14 if (argc != 9) { 13 15 gprint (GP_ERR, "USAGE: ungridify buffer Xmin Xmax Ymin Ymax x y z\n"); 16 gprint (GP_ERR, " convert a portion of an image to a collection a triplet of vectors\n"); 14 17 return (FALSE); 15 18 } … … 29 32 if ((vy = SelectVector (argv[7], ANYVECTOR, TRUE)) == NULL) return (FALSE); 30 33 if ((vz = SelectVector (argv[8], ANYVECTOR, TRUE)) == NULL) return (FALSE); 31 REALLOCATE (vx[0].elements, float, Nx*Ny);32 REALLOCATE (vy[0].elements, float, Nx*Ny);33 REALLOCATE (vz[0].elements, float, Nx*Ny);34 34 35 x = vx[0].elements; 36 y = vy[0].elements; 37 z = vz[0].elements; 35 ResetVector (vx, OPIHI_FLT, Nx*Ny); 36 ResetVector (vy, OPIHI_FLT, Nx*Ny); 37 ResetVector (vz, OPIHI_FLT, Nx*Ny); 38 39 x = vx[0].elements.Flt; 40 y = vy[0].elements.Flt; 41 z = vz[0].elements.Flt; 38 42 n = 0; 39 43 v = (float *)bf[0].matrix.buffer; 40 44 for (j = Ymin; j < Ymax; j++) { 41 45 for (i = Xmin; i < Xmax; i++, x++, y++, z++, n++) { 42 vx[0].elements [n] = i;43 vy[0].elements [n] = j;46 vx[0].elements.Flt[n] = i; 47 vy[0].elements.Flt[n] = j; 44 48 if (i < 0) continue; 45 49 if (i >= NX) continue; 46 50 if (j < 0) continue; 47 51 if (j >= NY) continue; 48 vz[0].elements [n] = v[i+j*NX];52 vz[0].elements.Flt[n] = v[i+j*NX]; 49 53 } 50 54 } 51 55 if (n != Nx*Ny) { 52 56 gprint (GP_ERR, "error in ungrid: %d vs %d (%d x %d)\n", n, Nx*Ny, Nx, Ny); 57 gprint (GP_ERR, "(this is probably a programming error in ungridify)\n"); 53 58 } 54 59 vx[0].Nelements = vy[0].Nelements = vz[0].Nelements = n; -
trunk/Ohana/src/opihi/cmd.data/uniq.c
r7917 r20936 4 4 5 5 int Nnew, i, j, found; 6 float *v1, *v2;7 6 Vector *ivec, *ovec; 8 7 … … 16 15 17 16 /* allocate the maximum possible needed */ 18 ALLOCATE (ovec[0].elements, float, ivec[0].Nelements);17 ResetVector (ovec, ivec->type, ivec->Nelements); 19 18 20 19 Nnew = 0; 21 v1 = ivec[0].elements; 22 for (i = 0; i < ivec[0].Nelements; i++, v1++) { 23 v2 = ovec[0].elements; 24 found = FALSE; 25 for (j = 0; !found && (j < Nnew); j++, v2++) { 26 if (*v1 == *v2) found = TRUE; 20 21 if (ivec->type == OPIHI_FLT) { 22 opihi_flt *v1 = ivec[0].elements.Flt; 23 for (i = 0; i < ivec[0].Nelements; i++, v1++) { 24 opihi_flt *v2 = ovec[0].elements.Flt; 25 found = FALSE; 26 for (j = 0; !found && (j < Nnew); j++, v2++) { 27 if (*v1 == *v2) found = TRUE; 28 } 29 if (!found) { 30 ovec[0].elements.Flt[Nnew] = *v1; 31 Nnew ++; 32 } 27 33 } 28 if (!found) { 29 ovec[0].elements[Nnew] = *v1; 30 Nnew ++; 34 } else { 35 opihi_int *v1 = ivec[0].elements.Int; 36 for (i = 0; i < ivec[0].Nelements; i++, v1++) { 37 opihi_int *v2 = ovec[0].elements.Int; 38 found = FALSE; 39 for (j = 0; !found && (j < Nnew); j++, v2++) { 40 if (*v1 == *v2) found = TRUE; 41 } 42 if (!found) { 43 ovec[0].elements.Int[Nnew] = *v1; 44 Nnew ++; 45 } 31 46 } 32 47 } 33 48 34 ovec[0].Nelements = Nnew;35 R EALLOCATE (ovec[0].elements, float, ovec[0].Nelements);49 // free up extra memory 50 ResetVector (ovec, ivec->type, Nnew); 36 51 37 52 return (TRUE); -
trunk/Ohana/src/opihi/cmd.data/vbin.c
r7917 r20936 5 5 int i, j, n, N, Nin, Nout; 6 6 int Normalize, Ignore; 7 float *Vout, *Vin, IgnoreValue;7 opihi_flt *Vout, IgnoreValue; 8 8 double scale; 9 9 Vector *in, *out; … … 42 42 Nout = Nin / scale; 43 43 44 REALLOCATE (out[0].elements, float, Nout);45 out[0].Nelements = Nout;44 // re-binning creates a float vector 45 ResetVector (out, OPIHI_FLT, in[0].Nelements); 46 46 47 Vin = in[0].elements; 48 Vout = out[0].elements; 49 for (n = j = 0; j < Nout; j++, Vout++) { 50 *Vout = 0; 51 for (N = i = 0; (i < scale) && (n < Nin); n++, i++, Vin++) { 52 if (!finite (*Vin)) continue; 53 if (Ignore && (*Vin == IgnoreValue)) continue; 54 *Vout += *Vin; 55 N ++; 56 } 57 if (Normalize) { 58 if (N > 0) { 59 *Vout /= (float) N; 60 } else { 61 *Vout = 0; 47 Vout = out[0].elements.Flt; 48 49 if (in[0].type == OPIHI_FLT) { 50 opihi_flt *Vin = in[0].elements.Flt; 51 for (n = j = 0; j < Nout; j++, Vout++) { 52 *Vout = 0; 53 for (N = i = 0; (i < scale) && (n < Nin); n++, i++, Vin++) { 54 if (!finite (*Vin)) continue; 55 if (Ignore && (*Vin == IgnoreValue)) continue; 56 *Vout += *Vin; 57 N ++; 58 } 59 if (Normalize) { 60 if (N > 0) { 61 *Vout /= (opihi_flt) N; 62 } else { 63 *Vout = 0; 64 } 65 } 66 } 67 } else { 68 opihi_int *Vin = in[0].elements.Int; 69 for (n = j = 0; j < Nout; j++, Vout++) { 70 *Vout = 0; 71 for (N = i = 0; (i < scale) && (n < Nin); n++, i++, Vin++) { 72 if (!finite (*Vin)) continue; 73 if (Ignore && (*Vin == IgnoreValue)) continue; 74 *Vout += *Vin; 75 N ++; 76 } 77 if (Normalize) { 78 if (N > 0) { 79 *Vout /= (opihi_flt) N; 80 } else { 81 *Vout = 0; 82 } 62 83 } 63 84 } -
trunk/Ohana/src/opihi/cmd.data/vclip.c
r7917 r20936 3 3 int vclip (int argc, char **argv) { 4 4 5 int i, Npix, DO_NAN, DO_INF, N;5 int i, Npix, DO_NAN, DO_INF, DO_CLIP, N; 6 6 double min, Vmin, max, Vmax, nan_val, inf_val; 7 float *in;8 7 Vector *vec; 9 8 … … 33 32 if ((vec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); 34 33 34 DO_CLIP = FALSE; 35 35 if (argc == 6) { 36 36 min = atof (argv[2]); … … 38 38 max = atof (argv[4]); 39 39 Vmax = atof (argv[5]); 40 DO_CLIP = TRUE; 40 41 } 41 42 43 if (DO_NAN && vec[0].type == OPIHI_INT) { 44 gprint (GP_ERR, " warning : clipping on NAN is invalid for INT vectors\n"); 45 return (FALSE); 46 } 47 48 if (DO_INF && vec[0].type == OPIHI_INT) { 49 gprint (GP_ERR, " warning : clipping on INF is invalid for INT vectors\n"); 50 return (FALSE); 51 } 52 42 53 Npix = vec[0].Nelements; 43 in = vec[0].elements;44 54 45 if (argc == 6) { 55 if (vec[0].type == OPIHI_FLT) { 56 opihi_flt *in = vec[0].elements.Flt; 46 57 for (i = 0; i < Npix; i++, in++) { 47 if ( *in < min)58 if (DO_CLIP && (*in < min)) { 48 59 *in = Vmin; 49 if (*in > max) 60 } 61 if (DO_CLIP && (*in > max)) { 50 62 *in = Vmax; 51 } 52 } 53 in = vec[0].elements; 54 if (DO_NAN) { 55 for (i = 0; i < Npix; i++, in++) { 56 if (isnan (*in)) { 63 } 64 if (!finite (*in) && DO_INF) { 65 *in = inf_val; 66 } 67 if (isnan (*in) && DO_NAN) { 57 68 *in = nan_val; 58 69 } 59 70 } 60 } 61 in = vec[0].elements; 62 if (DO_INF) { 71 } else { 72 opihi_int *in = vec[0].elements.Int; 63 73 for (i = 0; i < Npix; i++, in++) { 64 if (!finite (*in)) { 65 *in = inf_val; 74 if (DO_CLIP && (*in < min)) { 75 *in = Vmin; 76 } 77 if (DO_CLIP && (*in > max)) { 78 *in = Vmax; 66 79 } 67 80 } 68 81 } 69 82 return (TRUE); 70 71 83 } 72 73 -
trunk/Ohana/src/opihi/cmd.data/vgauss.c
r16446 r20936 2 2 3 3 /* local private functions */ 4 float fgaussOD (float, float *, int, float *);4 opihi_flt fgaussOD (opihi_flt, opihi_flt *, int, opihi_flt *); 5 5 6 6 # define GET_VAR(V,A) \ … … 16 16 17 17 int i, N, Npts, Npar, Quiet; 18 float par[4], *v1, *v2, *dy, **covar;19 float chisq, ochisq, dchisq;18 opihi_flt par[4], *v1, *v2, *dy, **covar; 19 opihi_flt chisq, ochisq, dchisq; 20 20 Vector *xvec, *yvec, *svec, *ovec; 21 21 char *c, name[16]; … … 42 42 if ((ovec = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE); 43 43 44 REQUIRE_VECTOR_FLT (xvec, FALSE); 45 REQUIRE_VECTOR_FLT (yvec, FALSE); 46 REQUIRE_VECTOR_FLT (svec, FALSE); 47 44 48 Npts = xvec[0].Nelements; 45 ALLOCATE (dy, float, Npts); 46 REALLOCATE (ovec[0].elements, float, Npts); 49 ResetVector (ovec, OPIHI_FLT, Npts); 50 51 ALLOCATE (dy, opihi_flt, Npts); 47 52 48 53 GET_VAR (par[0], "C0"); … … 52 57 Npar = 4; 53 58 54 v1 = svec[0].elements; 59 // mrqmin takes the inverse variance (do not generate NANs) 60 v1 = svec[0].elements.Flt; 55 61 v2 = dy; 56 62 for (i = 0; i < Npts; i++, v1++, v2++) { … … 58 64 } 59 65 60 ochisq = mrqinit (xvec[0].elements , yvec[0].elements, dy, Npts, par, Npar, fgaussOD, !Quiet);66 ochisq = mrqinit (xvec[0].elements.Flt, yvec[0].elements.Flt, dy, Npts, par, Npar, fgaussOD, !Quiet); 61 67 dchisq = ochisq + 2*Npts; 62 68 63 69 for (i = 0; (i < 20) && ((dchisq > 0.1*(Npts - Npar)) || (dchisq <= 0.0)); i++) { 64 chisq = mrqmin (xvec[0].elements , yvec[0].elements, dy, Npts, par, Npar, fgaussOD, !Quiet);70 chisq = mrqmin (xvec[0].elements.Flt, yvec[0].elements.Flt, dy, Npts, par, Npar, fgaussOD, !Quiet); 65 71 dchisq = ochisq - chisq; 66 72 ochisq = chisq; … … 70 76 71 77 for (i = 0; i < Npts; i++) { 72 ovec[0].elements [i] = fgaussOD (xvec[0].elements[i], par, Npar, dy);78 ovec[0].elements.Flt[i] = fgaussOD (xvec[0].elements.Flt[i], par, Npar, dy); 73 79 } 74 80 ovec[0].Nelements = Npts; … … 90 96 91 97 /* pars: x_o, sigma, I, back */ 92 float fgaussOD (float x, float *par, int Npar, float *dpar) {98 opihi_flt fgaussOD (opihi_flt x, opihi_flt *par, int Npar, opihi_flt *dpar) { 93 99 94 float z, r, f;100 opihi_flt z, r, f; 95 101 96 102 z = (x - par[0])/par[1]; -
trunk/Ohana/src/opihi/cmd.data/vgrid.c
r9275 r20936 5 5 int i, Nx, Ny, Xb, Yb; 6 6 float Xmin, Xmax, dX, Ymin, Ymax, dY; 7 float *buf, *val, *x, *y, *z; 7 float *buf; 8 opihi_flt *val, *x, *y, *z; 8 9 int *Nval; 9 10 Buffer *bf; … … 12 13 if (argc != 11) { 13 14 gprint (GP_ERR, "USAGE: vgrid x y z buffer Xmin Xmax dX Ymin Ymax dY\n"); 15 gprint (GP_ERR, " re-grid values from a triplet of vectors (x,y,z) into an image\n"); 16 gprint (GP_ERR, " the vectors must be floating-point type\n"); 14 17 return (FALSE); 15 18 } … … 22 25 if (vx[0].Nelements != vy[0].Nelements) return (FALSE); 23 26 if (vx[0].Nelements != vz[0].Nelements) return (FALSE); 27 28 REQUIRE_VECTOR_FLT (vx, FALSE); 29 REQUIRE_VECTOR_FLT (vy, FALSE); 30 REQUIRE_VECTOR_FLT (vz, FALSE); 24 31 25 32 Xmin = atof (argv[5]); … … 39 46 strcpy (bf[0].file, "(empty)"); 40 47 41 ALLOCATE (val, float, Nx*Ny);42 bzero (val, Nx*Ny*sizeof( float));48 ALLOCATE (val, opihi_flt, Nx*Ny); 49 bzero (val, Nx*Ny*sizeof(opihi_flt)); 43 50 ALLOCATE (Nval, int, Nx*Ny); 44 51 bzero (Nval, Nx*Ny*sizeof(int)); 45 52 46 x = vx[0].elements ;47 y = vy[0].elements ;48 z = vz[0].elements ;53 x = vx[0].elements.Flt; 54 y = vy[0].elements.Flt; 55 z = vz[0].elements.Flt; 49 56 for (i = 0; i < vx[0].Nelements; i++, x++, y++, z++) { 50 57 Xb = (*x - Xmin) / dX; -
trunk/Ohana/src/opihi/cmd.data/vload.c
r19840 r20936 6 6 int kapa, type; 7 7 char *name; 8 double dx, dy, size,angle;8 double dx, dy, angle; 9 9 KiiOverlay *overlay; 10 10 Vector *vecx, *vecy; … … 82 82 overlay[i].type = type; 83 83 overlay[i].text = NULL; 84 overlay[i].x = vecx[0].elements[i]+0.5; 85 overlay[i].y = vecy[0].elements[i]+0.5; 84 overlay[i].x = (vecx[0].type == OPIHI_FLT) ? vecx[0].elements.Flt[i] : vecx[0].elements.Int[i]; 85 overlay[i].y = (vecy[0].type == OPIHI_FLT) ? vecy[0].elements.Flt[i] : vecy[0].elements.Int[i]; 86 overlay[i].x += 0.5; 87 overlay[i].y += 0.5; 86 88 overlay[i].dx = dx; 87 89 overlay[i].dy = dy; -
trunk/Ohana/src/opihi/cmd.data/vmaxwell.c
r16446 r20936 2 2 3 3 /* local private functions */ 4 float fmaxwellOD (float, float *, int, float *);4 opihi_flt fmaxwellOD (opihi_flt, opihi_flt *, int, opihi_flt *); 5 5 6 6 # define GET_VAR(V,A) \ … … 16 16 17 17 int i, N, Npts, Npar, Quiet; 18 float par[5], *v1, *v2, *dy, **covar;19 float chisq, ochisq, dchisq;18 opihi_flt par[5], *v1, *v2, *dy, **covar; 19 opihi_flt chisq, ochisq, dchisq; 20 20 Vector *xvec, *yvec, *svec, *ovec; 21 21 char *c, name[16]; … … 42 42 if ((ovec = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE); 43 43 44 REQUIRE_VECTOR_FLT (xvec, FALSE); 45 REQUIRE_VECTOR_FLT (yvec, FALSE); 46 REQUIRE_VECTOR_FLT (svec, FALSE); 47 44 48 Npts = xvec[0].Nelements; 45 ALLOCATE (dy, float, Npts);46 R EALLOCATE (ovec[0].elements, float, Npts);49 ALLOCATE (dy, opihi_flt, Npts); 50 ResetVector (ovec, OPIHI_FLT, Npts); 47 51 48 52 GET_VAR (par[0], "C0"); … … 54 58 /* careful of variable renomalization */ 55 59 56 v1 = svec[0].elements ;60 v1 = svec[0].elements.Flt; 57 61 v2 = dy; 58 62 for (i = 0; i < Npts; i++, v1++, v2++) *v2 = 1.0 / (*v1 * *v1); 59 63 60 ochisq = mrqinit (xvec[0].elements , yvec[0].elements, dy, Npts, par, Npar, fmaxwellOD, !Quiet);64 ochisq = mrqinit (xvec[0].elements.Flt, yvec[0].elements.Flt, dy, Npts, par, Npar, fmaxwellOD, !Quiet); 61 65 dchisq = ochisq + 2*Npts; 62 66 63 for (i = 0; (i < 20) && ((dchisq > 0.1*(Npts - Npar)) || (dchisq <= 0.0)); i++) {64 chisq = mrqmin (xvec[0].elements , yvec[0].elements, dy, Npts, par, Npar, fmaxwellOD, !Quiet);67 for (i = 0; (i < 30) && ((dchisq > 0.1*(Npts - Npar)) || (dchisq <= 0.0)); i++) { 68 chisq = mrqmin (xvec[0].elements.Flt, yvec[0].elements.Flt, dy, Npts, par, Npar, fmaxwellOD, !Quiet); 65 69 dchisq = ochisq - chisq; 66 70 ochisq = chisq; … … 70 74 71 75 for (i = 0; i < Npts; i++) { 72 ovec[0].elements [i] = fmaxwellOD (xvec[0].elements[i], par, Npar, dy);76 ovec[0].elements.Flt[i] = fmaxwellOD (xvec[0].elements.Flt[i], par, Npar, dy); 73 77 } 74 78 ovec[0].Nelements = Npts; … … 90 94 91 95 /* pars: x_o, -0.5/sigma^2, I, back, ref */ 92 float fmaxwellOD (float x, float *par, int Npar, float *dpar) { 96 // f = C3 + C2*(x - C4)^2 * exp(-0.5*(x - C0)^2 / C1^2) 97 opihi_flt fmaxwellOD (opihi_flt x, opihi_flt *par, int Npar, opihi_flt *dpar) { 93 98 94 float z, r, f;99 opihi_flt z, r, f; 95 100 96 101 z = (x - par[0])/par[1]; -
trunk/Ohana/src/opihi/cmd.data/vpop.c
r7917 r20936 17 17 18 18 if (Npix > 1) { 19 memmove (&vec[0].elements[0], &vec[0].elements[1], Npix*sizeof(float)); 19 if (vec[0].type == OPIHI_FLT) { 20 memmove (&vec[0].elements.Flt[0], &vec[0].elements.Flt[1], Npix*sizeof(opihi_flt)); 21 } else { 22 memmove (&vec[0].elements.Int[0], &vec[0].elements.Int[1], Npix*sizeof(opihi_int)); 23 } 20 24 } 21 25 vec[0].Nelements = Npix - 1; -
trunk/Ohana/src/opihi/cmd.data/vroll.c
r7917 r20936 4 4 5 5 int Npix; 6 float first;6 opihi_flt first; 7 7 Vector *vec; 8 8 … … 17 17 if (Npix < 2) return (TRUE); 18 18 19 first = vec[0].elements[0]; 20 memmove (&vec[0].elements[0], &vec[0].elements[1], Npix*sizeof(float)); 21 vec[0].elements[Npix-1] = first; 19 if (vec[0].type == OPIHI_FLT) { 20 first = vec[0].elements.Flt[0]; 21 memmove (&vec[0].elements.Flt[0], &vec[0].elements.Flt[1], Npix*sizeof(opihi_flt)); 22 vec[0].elements.Flt[Npix-1] = first; 23 } else { 24 first = vec[0].elements.Int[0]; 25 memmove (&vec[0].elements.Int[0], &vec[0].elements.Int[1], Npix*sizeof(opihi_int)); 26 vec[0].elements.Int[Npix-1] = first; 27 } 22 28 return (TRUE); 23 29 } -
trunk/Ohana/src/opihi/cmd.data/vsmooth.c
r7917 r20936 3 3 int vsmooth (int argc, char **argv) { 4 4 5 int i, n, N, Nx, Ns, Ngauss; 6 float *vi, *vo, *gauss, *gaussnorm; 7 float g, s, sigma, Nsigma; 5 int i, n, N, Nx, Ns, Ngauss, isFloat; 6 opihi_flt *vf, *vo, *gauss, *gaussnorm; 7 opihi_int *vi; 8 float g, s, sigma, Nsigma, value; 8 9 Vector *in; 9 10 … … 23 24 sigma = atof (argv[2]); 24 25 Nx = in[0].Nelements; 25 vi = in[0].elements;26 26 27 27 /* build a 1D gaussian */ 28 28 Ns = (int) (Nsigma*sigma + 0.5); 29 29 Ngauss = 2*Ns + 1; 30 ALLOCATE (gaussnorm, float, Ngauss);30 ALLOCATE (gaussnorm, opihi_flt, Ngauss); 31 31 gauss = &gaussnorm[Ns]; 32 32 for (i = -Ns; i < Ns + 1; i++) { … … 34 34 } 35 35 36 ALLOCATE (vo, float, Nx); 36 ALLOCATE (vo, opihi_flt, Nx); 37 38 isFloat = (in[0].type == OPIHI_FLT); 39 vf = in[0].elements.Flt; 40 vi = in[0].elements.Int; 37 41 38 42 for (i = 0; i < Nx; i++) { … … 41 45 if (i+n < 0) continue; 42 46 if (i+n >= Nx) continue; 43 s += gauss[n]*vi[i+n]; 47 value = isFloat ? vf[i+n] : vi[i+n]; 48 s += gauss[n]*value; 44 49 g += gauss[n]; 45 50 } … … 47 52 } 48 53 49 free (in[0].elements);50 54 free (gaussnorm); 51 55 52 in[0].elements = vo; 56 if (isFloat) { 57 free (in[0].elements.Flt); 58 } else { 59 free (in[0].elements.Int); 60 } 61 62 // smoothing an int vector results in a float vector 63 in[0].type = OPIHI_FLT; 64 in[0].elements.Flt = vo; 53 65 return (TRUE); 54 66 } -
trunk/Ohana/src/opihi/cmd.data/vstat.c
r7917 r20936 5 5 int i, N; 6 6 double max, min, sum, var, dvar, mean, stdev; 7 float *X,IgnoreValue;7 float IgnoreValue; 8 8 int Ignore, Quiet; 9 9 … … 41 41 42 42 /* calculate max, min, mean, sum, npix */ 43 X = vec[0].elements;44 43 max = -HUGE_VAL; 45 44 min = HUGE_VAL; 46 45 sum = N = 0; 47 for (i = 0; i < vec[0].Nelements; i++, X++) { 48 if (!finite (*X)) continue; 49 if (Ignore && (*X == IgnoreValue)) continue; 50 max = MAX (*X, max); 51 min = MIN (*X, min); 52 sum += *X; 53 N++; 54 } 46 if (vec[0].type == OPIHI_FLT) { 47 opihi_flt *X = vec[0].elements.Flt; 48 for (i = 0; i < vec[0].Nelements; i++, X++) { 49 if (!finite (*X)) continue; 50 if (Ignore && (*X == IgnoreValue)) continue; 51 max = MAX (*X, max); 52 min = MIN (*X, min); 53 sum += *X; 54 N++; 55 } 56 } else { 57 opihi_int *X = vec[0].elements.Int; 58 for (i = 0; i < vec[0].Nelements; i++, X++) { 59 if (!finite (*X)) continue; 60 if (Ignore && (*X == IgnoreValue)) continue; 61 max = MAX (*X, max); 62 min = MIN (*X, min); 63 sum += *X; 64 N++; 65 } 66 } 55 67 mean = sum / N; 56 68 … … 65 77 ALLOCATE (Nval, int, 1002); 66 78 bzero (Nval, 1000*sizeof(int)); 67 X = vec[0].elements;68 79 var = 0; 69 for (i = 0; i < vec[0].Nelements; i++, X++) { 70 if (!finite (*X)) continue; 71 if (Ignore && (*X == IgnoreValue)) continue; 72 bin = MAX (0, MIN (1000, (*X - min) / dx)); 73 Nval[bin] ++; 74 dvar = (*X - mean); 75 var += dvar*dvar; 76 } 80 if (vec[0].type == OPIHI_FLT) { 81 opihi_flt *X = vec[0].elements.Flt; 82 for (i = 0; i < vec[0].Nelements; i++, X++) { 83 if (!finite (*X)) continue; 84 if (Ignore && (*X == IgnoreValue)) continue; 85 bin = MAX (0, MIN (1000, (*X - min) / dx)); 86 Nval[bin] ++; 87 dvar = (*X - mean); 88 var += dvar*dvar; 89 } 90 } else { 91 opihi_int *X = vec[0].elements.Int; 92 for (i = 0; i < vec[0].Nelements; i++, X++) { 93 if (!finite (*X)) continue; 94 if (Ignore && (*X == IgnoreValue)) continue; 95 bin = MAX (0, MIN (1000, (*X - min) / dx)); 96 Nval[bin] ++; 97 dvar = (*X - mean); 98 var += dvar*dvar; 99 } 100 } 77 101 stdev = sqrt (var / N); 78 102 -
trunk/Ohana/src/opihi/cmd.data/vzload.c
r17419 r20936 58 58 59 59 for (i = N = 0; i < Noverlay; i++) { 60 size = MIN (MAX_OUTPUT_SIZE, (vecz[0].elements[i] - min) / range); 60 float z = (vecz[0].type == OPIHI_FLT) ? vecz[0].elements.Flt[i] : vecz[0].elements.Int[i]; 61 size = MIN (MAX_OUTPUT_SIZE, (z - min) / range); 61 62 if (size < 0.1) continue; 62 63 63 64 overlay[N].type = type; 64 65 overlay[N].text = NULL; 65 overlay[N].x = vecx[0].elements[i]+0.5; 66 overlay[N].y = vecy[0].elements[i]+0.5; 66 overlay[N].x = (vecx[0].type == OPIHI_FLT) ? vecx[0].elements.Flt[i] : vecx[0].elements.Int[i]; 67 overlay[N].y = (vecy[0].type == OPIHI_FLT) ? vecy[0].elements.Flt[i] : vecy[0].elements.Int[i]; 68 69 overlay[N].x += 0.5; 70 overlay[N].y += 0.5; 71 67 72 overlay[N].angle = 0.0; 68 73 -
trunk/Ohana/src/opihi/cmd.data/write_vectors.c
r20534 r20936 78 78 for (i = 0; i < vec[0][0].Nelements; i++) { 79 79 for (j = 0; j < Nvec; j++) { 80 fprintf (f, "%.10g ", vec[j][0].elements[i]); 80 if (vec[j][0].type == OPIHI_FLT) { 81 fprintf (f, "%.12g ", vec[j][0].elements.Flt[i]); 82 } else { 83 fprintf (f, "%d ", vec[j][0].elements.Int[i]); 84 } 81 85 } 82 86 fprintf (f, "\n"); … … 135 139 for (j = 0; j < Nvec; j++) { 136 140 if (fmttype[j] == 'd') { 137 fprintf (f, fmtlist[j], (int)(vec[j][0].elements[i])); 141 if (vec[j][0].type == OPIHI_FLT) { 142 fprintf (f, fmtlist[j], (int)(vec[j][0].elements.Flt[i])); 143 } else { 144 fprintf (f, fmtlist[j], (int)(vec[j][0].elements.Int[i])); 145 } 138 146 } 139 147 if (fmttype[j] == 'f') { 140 fprintf (f, fmtlist[j], (float)(vec[j][0].elements[i])); 148 if (vec[j][0].type == OPIHI_FLT) { 149 fprintf (f, fmtlist[j], (float)(vec[j][0].elements.Flt[i])); 150 } else { 151 fprintf (f, fmtlist[j], (float)(vec[j][0].elements.Int[i])); 152 } 141 153 } 142 154 } -
trunk/Ohana/src/opihi/cmd.data/zplot.c
r14590 r20936 3 3 int zplot (int argc, char **argv) { 4 4 5 int i, kapa , Npts;6 float *in,*out;5 int i, kapa; 6 opihi_flt *out; 7 7 double min, range; 8 8 Graphdata graphmode; … … 31 31 return (FALSE); 32 32 } 33 Zvec.Nelements = zvec[0].Nelements;34 ALLOCATE (Zvec.elements, float, Zvec.Nelements);33 SetVector (&Zvec, OPIHI_FLT, zvec[0].Nelements); 34 out = Zvec.elements.Flt; 35 35 36 in = zvec[0].elements; 37 out = Zvec.elements; 38 for (i = 0; i < Zvec.Nelements; i++, in++, out++) { 39 *out = MIN (1.0, MAX (0.01, (*in - min) / range)); 36 if (zvec[0].type == OPIHI_FLT) { 37 opihi_flt *in = zvec[0].elements.Flt; 38 for (i = 0; i < Zvec.Nelements; i++, in++, out++) { 39 *out = MIN (1.0, MAX (0.01, (*in - min) / range)); 40 } 41 } else { 42 opihi_int *in = zvec[0].elements.Int; 43 for (i = 0; i < Zvec.Nelements; i++, in++, out++) { 44 *out = MIN (1.0, MAX (0.01, (*in - min) / range)); 45 } 40 46 } 41 47 … … 44 50 graphmode.size = -1; /* point size determined by Zvec */ 45 51 graphmode.etype = 0; /* no errorbars */ 46 Npts = xvec[0].Nelements; 47 PlotVectorTriplet (kapa, Npts, xvec[0].elements, yvec[0].elements, Zvec.elements, &graphmode); 52 PlotVectorTriplet (kapa, xvec, yvec, &Zvec, &graphmode); 48 53 49 free (Zvec.elements );54 free (Zvec.elements.Ptr); 50 55 51 56 return (TRUE);
Note:
See TracChangeset
for help on using the changeset viewer.
