Changeset 32922
- Timestamp:
- Dec 11, 2011, 1:39:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/Ohana/src/opihi/cmd.astro/spex2dgas.c
r32918 r32922 78 78 dF = MIN (maxPressure, MAX (-maxPressure, dF)); 79 79 80 float dPdXi = dF * dX / Dcur; 81 float dPdYi = dF * dY / Dcur; 82 83 // if we are too close, then dX/Dcur is too ill-defined, just jump away 80 float dPdXi, dPdYi; 81 if (fabs(Dcur) < 1e-6) { 82 dPdXi = 0.0; 83 dPdYi = 0.0; 84 } else { 85 dPdXi = dF * dX / Dcur; 86 dPdYi = dF * dY / Dcur; 87 } 88 89 if (isnan(Dtgt) || isnan(dX) || isnan(dY) || isnan(Dcur) || isnan(dF) || isnan(dPdXi) || isnan(dPdYi)) abort(); 90 91 // if we are too close, then dX/Dcur is too ill-defined, just jump away by 5% of Dtgt 84 92 if (Dcur < 0.01*Dtgt) { 85 dPdXi = drand48() - 0.5;86 dPdYi = drand48() - 0.5;93 dPdXi = (drand48() - 0.5)*0.1*Dtgt; 94 dPdYi = (drand48() - 0.5)*0.1*Dtgt; 87 95 } 88 96 … … 108 116 int spex2dgas (int argc, char **argv) { 109 117 110 int i, iter;118 int i, j, iter, IoMax; 111 119 Vector *index1, *index2, *distance; 112 113 // init random numbers 114 long A, B; 115 A = time(NULL); 116 for (B = 0; A == time(NULL); B++); 117 srand48(B); 120 float XoMax, YoMax; 121 122 { 123 // init random numbers 124 long A, B; 125 A = time(NULL); 126 for (B = 0; A == time(NULL); B++); 127 srand48(B); 128 } 118 129 119 130 if (argc != 9) goto usage; … … 202 213 // int Ngrid = sqrt(Nobject); 203 214 // float dgrid = 1.5 * Dmax / Ngrid; // XXX remove the fudge factor 204 for (i = 0; i < Nobject; i++) { 205 // object[i].Xo = dgrid * (int) (i % Ngrid); 206 // object[i].Yo = dgrid * (int) (i / Ngrid); 207 object[i].Xo = Dmax*drand48(); 208 object[i].Yo = Dmax*drand48(); 215 // XXX for (i = 0; i < Nobject; i++) { 216 // XXX // object[i].Xo = dgrid * (int) (i % Ngrid); 217 // XXX // object[i].Yo = dgrid * (int) (i / Ngrid); 218 // XXX object[i].Xo = Dmax*drand48(); 219 // XXX object[i].Yo = Dmax*drand48(); 220 // XXX object[i].dPdX = 0.0; 221 // XXX object[i].dPdY = 0.0; 222 // XXX } 223 224 // place the objects at the initial guess locations 225 // use object 0 and its most distant friend to constrain: 226 227 int idx1 = 0; 228 int idx2 = object[idx1].index[object[idx1].Nindex-1]; 229 float A = object[idx1].Dtgt[object[idx1].Nindex-1]; 230 object[idx1].Xo = 0.0; 231 object[idx1].Yo = 0.0; 232 object[idx1].dPdX = 0.0; 233 object[idx1].dPdY = 0.0; 234 235 object[idx2].Xo = A; 236 object[idx2].Yo = 0.0; 237 object[idx2].dPdX = 0.0; 238 object[idx2].dPdY = 0.0; 239 240 // choose the correct Y side by comparing to the distance from the most deviant 241 YoMax = 0; 242 XoMax = 0; 243 IoMax = 0; 244 245 for (i = 0; i < Nobject; i++) { 246 if (i == idx1) continue; 247 if (i == idx2) continue; 248 float B = NAN; 249 float C = NAN; 250 for (j = 0; (isnan(B) || isnan(C)) && (j < object[i].Nindex); j++) { 251 if (object[i].index[j] == idx1) { B = object[i].Dtgt[j]; } 252 if (object[i].index[j] == idx2) { C = object[i].Dtgt[j]; } 253 } 254 if (isnan(B) || isnan(C)) abort(); 255 256 float Xo = (SQ(A) + SQ(B) - SQ(C)) / (2*A); 257 float Y2 = SQ(B) - SQ(Xo); 258 259 float Yo = (Y2 < 0) ? 0.0 : sqrt(Y2); 260 if (isnan(Yo)) abort(); 261 262 object[i].Xo = Xo; 263 object[i].Yo = Yo; 209 264 object[i].dPdX = 0.0; 210 265 object[i].dPdY = 0.0; 266 if (Yo > YoMax) { 267 YoMax = Yo; 268 XoMax = Xo; 269 IoMax = i; 270 } 271 } 272 273 for (i = 0; i < Nobject; i++) { 274 if (i == idx1) continue; 275 if (i == idx2) continue; 276 if (i == IoMax) continue; 277 for (j = 0; j < object[i].Nindex; j++) { 278 if (object[i].index[j] == IoMax) { 279 float d02 = SQ(object[i].Dtgt[j]); 280 float dX = XoMax - object[i].Xo; 281 float dY1 = YoMax - object[i].Yo; 282 float dY2 = YoMax + object[i].Yo; 283 float d12 = SQ(dX) + SQ(dY1); 284 float d22 = SQ(dX) + SQ(dY2); 285 if (fabs(d12 - d02) > fabs(d22 - d02)) { 286 object[i].Yo = -object[i].Yo; 287 break; 288 } 289 } 290 } 211 291 } 212 292 … … 215 295 216 296 int nearNeighbors = (iter < nCloseIter); 297 298 // save the result 299 char name[64]; 300 snprintf (name, 64, "output.%02d.dat", iter); 301 FILE *output = fopen (name, "w"); 302 for (i = 0; i < Nobject; i++) { 303 fprintf (output, "%f %f : %f %f\n", object[i].Xo, object[i].Yo, object[i].dPdX, object[i].dPdY); 304 } 305 fclose (output); 217 306 218 307 // measure (dP/dX),(dP/dY) for all objects
Note:
See TracChangeset
for help on using the changeset viewer.
