Changeset 30201
- Timestamp:
- Jan 5, 2011, 7:30:11 AM (15 years ago)
- Location:
- branches/eam_branches/ipp-20101205/Ohana/src
- Files:
-
- 5 edited
-
libkapa/src/DrawRotString.c (modified) (3 diffs)
-
libkapa/src/PSRotFont.c (modified) (3 diffs)
-
libkapa/src/bDrawRotFont.c (modified) (3 diffs)
-
opihi/cmd.data/match2d.c (modified) (6 diffs)
-
opihi/cmd.data/vstats.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20101205/Ohana/src/libkapa/src/DrawRotString.c
r10073 r30201 27 27 unsigned char *bitmap; 28 28 char *currentname, basename[64]; 29 int i, dy, dx, N, X, Y, code ;29 int i, dy, dx, N, X, Y, code, protect; 30 30 int dX, Xoff, dY, Yoff, YoffBase; 31 31 int currentsize, basesize; … … 63 63 64 64 code = FALSE; 65 protect = FALSE; 65 66 66 67 YoffBase = Yoff; … … 70 71 if ((N < 0) || (N >= NROTCHARS)) continue; 71 72 73 if (N == 39) { // single-quote 74 protect = protect ? FALSE : TRUE; 75 } 76 72 77 /* check for special characters */ 73 if (!code ) {78 if (!code && !protect) { 74 79 if (N == 94) { 75 80 SetRotFont (currentname, (int)(0.8*currentsize)); -
branches/eam_branches/ipp-20101205/Ohana/src/libkapa/src/PSRotFont.c
r10073 r30201 7 7 8 8 char *segment, basename[64], *currentname; 9 int i, N, code ;9 int i, N, code, protect; 10 10 int dX, dY, Xoff, Yoff, X, Y, Nseg, NSEG, YoffBase; 11 11 double cs, sn, fscale, currentscale; … … 60 60 61 61 code = FALSE; 62 protect = FALSE; 63 62 64 YoffBase = 0; 63 65 /* accumulate string segments with common state */ … … 66 68 if ((N < 0) || (N >= NROTCHARS)) continue; 67 69 70 if (N == 39) { // single-quote 71 protect = protect ? FALSE : TRUE; 72 } 73 68 74 /* check for special characters */ 69 if (!code ) {75 if (!code && !protect) { 70 76 /* superscript character (^) */ 71 77 if (N == 94) { -
branches/eam_branches/ipp-20101205/Ohana/src/libkapa/src/bDrawRotFont.c
r29938 r30201 14 14 unsigned char *bitmap; 15 15 char *currentname, basename[64]; 16 int i, dy, dx, N, X, Y, code ;16 int i, dy, dx, N, X, Y, code, protect; 17 17 int dX, Xoff, dY, Yoff, YoffBase; 18 18 int currentsize, basesize; … … 53 53 54 54 code = FALSE; 55 protect = FALSE; 55 56 56 57 YoffBase = Yoff; … … 60 61 if ((N < 0) || (N >= NROTCHARS)) continue; 61 62 63 if (N == 39) { // single-quote 64 protect = protect ? FALSE : TRUE; 65 } 66 62 67 /* check for special characters */ 63 if (!code ) {68 if (!code && !protect) { 64 69 if (N == 94) { 65 70 SetRotFont (currentname, (int)(0.8*currentsize)); -
branches/eam_branches/ipp-20101205/Ohana/src/opihi/cmd.data/match2d.c
r27817 r30201 1 1 # include "data.h" 2 2 3 int find_matches2d (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index1, Vector *index2); 4 int find_matches2d_closest (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index); 3 5 4 6 // match2d (X1) (Y1) (X2) (Y2) (Radius) [-index1 (index1)] [-index2 (index2)] [-nomatch1 nomatch1] [-nomatch2 nomatch2] … … 6 8 int match2d (int argc, char **argv) { 7 9 8 int N ;10 int N, CLOSEST; 9 11 double Radius; 10 12 char *endptr; … … 12 14 Vector *index1, *index2; 13 15 16 CLOSEST = FALSE; 17 if ((N = get_argument (argc, argv, "-closest"))) { 18 remove_argument (N, &argc, argv); 19 CLOSEST = TRUE; 20 } 21 14 22 if ((N = get_argument (argc, argv, "-index1"))) { 15 23 remove_argument (N, &argc, argv); … … 30 38 if (argc != 6) { 31 39 gprint (GP_ERR, "USAGE: match2d X1 Y1 X2 Y2 Radius [-index1 (index1)] [-index2 (index2)] [-closest]\n"); 32 // gprint (GP_ERR, "USAGE: match2d X1 Y1 X2 Y2 Radius [-index1 (index1)] [-index2 (index2)] [-closest]\n"); 33 // gprint (GP_ERR, " if -closest is provided, index1 & index2 will have the same length as X1 and X2 (respectively)\n"); 34 // gprint (GP_ERR, " with either the index of the match or a value of -1 for non-matches\n"); 35 return (FALSE); 36 } 40 gprint (GP_ERR, " if -closest is provided, index1 & index2 will have the same length as X1 and X2 (respectively)\n"); 41 gprint (GP_ERR, " with either the index of the match or a value of -1 for non-matches\n"); 42 return (FALSE); 43 } 44 45 /* 46 we have two modes of operation: 47 48 without -closest, we are finding all matched pairs within the match radius. in this 49 case, the two index vectors have the same length, one entry per matched pair. 50 x1[index1],y1[index1] matches to x2[index2],y2[index2]. 51 52 with -closest selected, we are finding the closest element of set 1 to each of set 2 53 and vice versa. in this case, index1 is always the same length as x1,y1, while index2 54 is the same lengths as x2,y2. x2[index1],y2[index1] matches x1,y1 while 55 x1[index2],y1[index2] matches x2,y2 56 57 */ 37 58 38 59 if ((X1vec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE); … … 61 82 } 62 83 63 find_matches2d (X1vec, Y1vec, X2vec, Y2vec, Radius, index1, index2); 84 if (CLOSEST) { 85 find_matches2d_closest (X1vec, Y1vec, X2vec, Y2vec, Radius, index1); 86 find_matches2d_closest (X2vec, Y2vec, X1vec, Y1vec, Radius, index2); 87 } else { 88 find_matches2d (X1vec, Y1vec, X2vec, Y2vec, Radius, index1, index2); 89 } 64 90 65 91 return (TRUE); … … 132 158 return (TRUE); 133 159 } 160 161 // find the elements of X2,Y2 which are closest to each element of X1,Y1 (-1 if no match) 162 int find_matches2d_closest (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index) { 163 164 off_t i, j, Jmin, Ji, I, J, *N1, *N2, NMATCH; 165 double dX, dY, dR, Radius2, Rmin; 166 167 NMATCH = X1->Nelements; 168 ResetVector (index, OPIHI_INT, NMATCH); 169 170 ALLOCATE (N1, off_t, X1->Nelements); 171 ALLOCATE (N2, off_t, X2->Nelements); 172 173 for (i = 0; i < X1->Nelements; i++) { N1[i] = i; } 174 for (i = 0; i < X2->Nelements; i++) { N2[i] = i; } 175 176 sort_coords_indexonly (X1->elements.Flt, Y1->elements.Flt, N1, X1->Nelements); 177 sort_coords_indexonly (X2->elements.Flt, Y2->elements.Flt, N2, X2->Nelements); 178 179 Radius2 = Radius*Radius; 180 181 // find the closest entry in list 2 to the current entry in list 1: 182 for (i = j = 0; (i < X1->Nelements) && (j < X2->Nelements);) { 183 I = N1[i]; 184 J = N2[j]; 185 186 dX = X1->elements.Flt[I] - X2->elements.Flt[J]; 187 188 if (dX <= -1.02*Radius) { 189 // no match in list 2 to this entry 190 index->elements.Int[I] = -1; 191 i++; 192 continue; 193 } 194 if (dX >= +1.02*Radius) { j++; continue; } 195 196 // look for closest matches of list2() to list1(i) 197 Jmin = -1; 198 Rmin = Radius2; 199 for (Ji = j; (dX > -1.02*Radius) && (Ji < X2->Nelements); Ji++) { 200 J = N2[Ji]; 201 dX = X1->elements.Flt[I] - X2->elements.Flt[J]; 202 dY = Y1->elements.Flt[I] - Y2->elements.Flt[J]; 203 dR = dX*dX + dY*dY; 204 if (dR > Radius2) continue; 205 if (dR < Rmin) { 206 Rmin = dR; 207 Jmin = J; 208 } 209 } 210 211 // no match in list 2 to this entry 212 if (Jmin == -1) { 213 index->elements.Int[I] = -1; 214 i++; 215 continue; 216 } 217 index->elements.Int[I] = Jmin; 218 i++; 219 } 220 index->Nelements = NMATCH; 221 222 free (N1); 223 free (N2); 224 225 return (TRUE); 226 } -
branches/eam_branches/ipp-20101205/Ohana/src/opihi/cmd.data/vstats.c
r21508 r30201 3 3 int vstats (int argc, char **argv) { 4 4 5 int i, N;6 double max, min, sum, var, dvar, mean, stdev;7 float IgnoreValue ;5 int i, iter, N, Nbin, Niter; 6 double max, min, pmin, pmax, sum, var, dvar, mean, stdev; 7 float IgnoreValue, Nsigma; 8 8 int Ignore, Quiet; 9 9 10 int *Nval, bin, Nmode, Nmed ;11 double dx, mode, median ;10 int *Nval, bin, Nmode, Nmed, Nused; 11 double dx, mode, median, threshold; 12 12 Vector *vec; 13 char *mask = NULL; 13 14 14 15 IgnoreValue = 0; … … 21 22 } 22 23 24 Niter = 1; 25 Nsigma = 3.0; 26 27 if ((N = get_argument (argc, argv, "-sigma-clip"))) { 28 remove_argument (N, &argc, argv); 29 Nsigma = atof(argv[N]); 30 Niter = 3; 31 remove_argument (N, &argc, argv); 32 } 33 34 if ((N = get_argument (argc, argv, "-iter"))) { 35 remove_argument (N, &argc, argv); 36 Niter = atoi(argv[N]); 37 remove_argument (N, &argc, argv); 38 } 39 23 40 Quiet = FALSE; 24 41 if ((N = get_argument (argc, argv, "-q"))) { … … 32 49 33 50 if (argc != 2) { 34 gprint (GP_ERR, "USAGE: vstat (vector)\n"); 51 gprint (GP_ERR, "USAGE: vstat (vector) [-ignore value] [-q] [-quiet] [-iter Niter] [-sigma-clip Nsigma]\n"); 52 gprint (GP_ERR, " default is 1 iteration without sigma clipping or 3 with sigma clipping\n"); 35 53 return (FALSE); 36 54 } … … 39 57 40 58 /* we need two passes, one for max, min, mean, sum, one for median, stdev, etc */ 59 60 // set a good / bad mask 61 ALLOCATE (mask, char, vec[0].Nelements); 62 if (vec[0].type == OPIHI_FLT) { 63 opihi_flt *X = vec[0].elements.Flt; 64 for (i = 0; i < vec[0].Nelements; i++, X++) { 65 mask[i] = 1; 66 if (!finite (*X)) continue; 67 if (Ignore && (*X == IgnoreValue)) continue; 68 mask[i] = 0; 69 } 70 } else { 71 opihi_int *X = vec[0].elements.Int; 72 for (i = 0; i < vec[0].Nelements; i++, X++) { 73 mask[i] = 1; 74 if (!finite (*X)) continue; 75 if (Ignore && (*X == IgnoreValue)) continue; 76 mask[i] = 0; 77 } 78 } 41 79 42 80 /* calculate max, min, mean, sum, npix */ … … 47 85 opihi_flt *X = vec[0].elements.Flt; 48 86 for (i = 0; i < vec[0].Nelements; i++, X++) { 49 if (!finite (*X)) continue; 50 if (Ignore && (*X == IgnoreValue)) continue; 87 if (mask[i]) continue; 51 88 max = MAX (*X, max); 52 89 min = MIN (*X, min); … … 57 94 opihi_int *X = vec[0].elements.Int; 58 95 for (i = 0; i < vec[0].Nelements; i++, X++) { 59 if (!finite (*X)) continue; 60 if (Ignore && (*X == IgnoreValue)) continue; 96 if (mask[i]) continue; 61 97 max = MAX (*X, max); 62 98 min = MIN (*X, min); … … 67 103 mean = sum / N; 68 104 69 /* calculate median and mode with resolution of (max - min) / 1000 */ 70 dx = (max - min) / 1000; 71 if (dx == 0) { 72 median = mode = min; 73 stdev = 0.0; 74 goto skip; 75 } 76 77 ALLOCATE (Nval, int, 1002); 78 bzero (Nval, 1000*sizeof(int)); 79 var = 0; 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 } 101 stdev = sqrt (var / N); 102 103 Nmode = 0; 104 mode = Nval[Nmode]; 105 median = 0; 106 Nmed = -1; 107 for (i = 0; i < 1001; i++) { 108 if (Nmed == -1) { 109 median += Nval[i]; 110 if (median >= N / 2.0) { 111 Nmed = i; 112 median = i * dx + min; 105 // we do Niter passes; on each pass, we exclude entries > Nsigma from the median 106 pmin = min; 107 pmax = max; 108 109 for (iter = 0; iter < Niter; iter ++) { 110 111 // reduce Nbin after the first iteration? 112 Nbin = 1000; 113 114 /* calculate median and mode with resolution of (max - min) / 1000 */ 115 dx = (pmax - pmin) / Nbin; 116 if (dx == 0) { 117 median = mode = min; 118 stdev = 0.0; 119 goto skip; 120 } 121 122 ALLOCATE (Nval, int, Nbin + 2); 123 bzero (Nval, Nbin*sizeof(int)); 124 var = 0; 125 if (vec[0].type == OPIHI_FLT) { 126 opihi_flt *X = vec[0].elements.Flt; 127 for (i = 0; i < vec[0].Nelements; i++, X++) { 128 if (mask[i]) continue; 129 bin = MAX (0, MIN (Nbin, (*X - pmin) / dx)); 130 Nval[bin] ++; 131 dvar = (*X - mean); 132 var += dvar*dvar; 133 } 134 } else { 135 opihi_int *X = vec[0].elements.Int; 136 for (i = 0; i < vec[0].Nelements; i++, X++) { 137 if (mask[i]) continue; 138 bin = MAX (0, MIN (Nbin, (*X - pmin) / dx)); 139 Nval[bin] ++; 140 dvar = (*X - mean); 141 var += dvar*dvar; 142 } 143 } 144 stdev = sqrt (var / N); 145 146 Nmode = 0; 147 mode = Nval[Nmode]; 148 median = 0; 149 Nmed = -1; 150 for (i = 0; i < Nbin + 1; i++) { 151 if (Nmed == -1) { 152 median += Nval[i]; 153 if (median >= N / 2.0) { 154 Nmed = i; 155 median = i * dx + pmin; 156 } 113 157 } 114 } 115 if (mode < Nval[i]) { 116 Nmode = i; 117 mode = Nval[Nmode]; 118 } 119 } 120 mode = Nmode * dx + min; 121 free (Nval); 158 if (mode < Nval[i]) { 159 Nmode = i; 160 mode = Nval[Nmode]; 161 } 162 } 163 mode = Nmode * dx + pmin; 164 free (Nval); 165 166 threshold = Nsigma * stdev; 167 168 // we are going to do another pass: mark the entries to skip 169 pmin = max; 170 pmax = min; 171 if (iter < Niter - 1) { 172 if (vec[0].type == OPIHI_FLT) { 173 opihi_flt *X = vec[0].elements.Flt; 174 for (i = 0; i < vec[0].Nelements; i++, X++) { 175 if (mask[i]) continue; 176 if (fabs(*X - median) > threshold) { 177 mask[i] = 1; 178 } else { 179 pmin = MIN (*X, pmin); 180 pmax = MAX (*X, pmax); 181 } 182 } 183 } else { 184 opihi_int *X = vec[0].elements.Int; 185 for (i = 0; i < vec[0].Nelements; i++, X++) { 186 if (mask[i]) continue; 187 if (fabs(*X - median) > threshold) { 188 mask[i] = 1; 189 } else { 190 pmin = MIN (*X, pmin); 191 pmax = MAX (*X, pmax); 192 } 193 } 194 } 195 } 196 // gprint (GP_ERR, "iter %d, mean: %g, stdev: %g, min: %g, max: %g, median: %g, mode: %g, Npts: %d\n", 197 // iter, mean, stdev, min, max, median, mode, N); 198 } 199 200 Nused = 0; 201 for (i = 0; i < vec[0].Nelements; i++) { 202 if (mask[i]) continue; 203 Nused ++; 204 } 122 205 123 206 skip: 207 FREE(mask); 208 124 209 if (!Quiet) { 125 210 gprint (GP_ERR, "mean: %g, stdev: %g, min: %g, max: %g, median: %g, mode: %g, Npts: %d\n", 126 mean, stdev, min, max, median, mode, N); 127 } 128 211 mean, stdev, min, max, median, mode, N); 212 } 213 214 set_variable ("PMIN", pmin); 215 set_variable ("PMAX", pmax); 129 216 set_variable ("MIN", min); 130 217 set_variable ("MAX", max); … … 134 221 set_variable ("TOTAL", sum); 135 222 set_int_variable ("NPIX", N); 223 set_int_variable ("NPTS", N); 224 set_int_variable ("NUSED", Nused); 136 225 set_variable ("SIGMA", stdev); 137 226 return (TRUE);
Note:
See TracChangeset
for help on using the changeset viewer.
