Changeset 8120 for trunk/ippTools/src/regtool.c
- Timestamp:
- Aug 3, 2006, 6:18:57 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/regtool.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/regtool.c
r8042 r8120 12 12 static psArray *newFrameSearchPending(pxConfig *config); 13 13 static p1PendingExpRow *newToP1PendingExp(newExpRow *newExp); 14 static p2PendingExpRow *newToP2PendingExp( newExpRow *newExp);14 static p2PendingExpRow *newToP2PendingExp(pxConfig *config, newExpRow *newExp); 15 15 static p2PendingImfileRow *newImfileToP2PendingImfile(newImfileRow *newImfile); 16 static rawScienceFrame *newToRawScienceFrame(pxConfig *config, newFrame *newFrame); 17 static rawScienceExpRow *newToRawScienceExp(pxConfig *config, newExpRow *exp); 18 16 19 17 20 # define MODECASE(caseName, func) \ … … 89 92 // insert 'new' rawScience & detrendframes 90 93 if (psArrayLength(new) > 0) { 94 // start a transaction so we don't end up file raw* frames but no 95 // p2Pending*, etc. 96 if (!psDBTransaction(config->dbh)) { 97 psError(PS_ERR_UNKNOWN, false, "database error"); 98 psFree(exp); 99 psFree(new); 100 return false; 101 } 102 91 103 for (long i = 0; i < psArrayLength(new); i++) { 92 104 newFrame *newFrame = new->data[i]; 93 105 if (detrend) { 94 106 // it's a detrend frame 95 rawDetrendFrame *frame = newToRawDetrendFrame( newFrame);107 rawDetrendFrame *frame = newToRawDetrendFrame(config, newFrame); 96 108 if (!frame) { 97 109 psError(PS_ERR_UNKNOWN, false, "failed to convert new frame into a detrend frame"); … … 100 112 } 101 113 if (!rawDetrendFrameInsert(config, frame)) { 114 // rollback 115 if (!psDBRollback(config->dbh)) { 116 psError(PS_ERR_UNKNOWN, false, "database error"); 117 } 102 118 psError(PS_ERR_UNKNOWN, false, "failed to insert frame into the database"); 103 119 psFree(frame); … … 112 128 // it's a science frame 113 129 // insert into into rawScienceExp 114 rawScienceFrame *frame = newToRawScienceFrame( newFrame);130 rawScienceFrame *frame = newToRawScienceFrame(config, newFrame); 115 131 if (!frame) { 132 // rollback 133 if (!psDBRollback(config->dbh)) { 134 psError(PS_ERR_UNKNOWN, false, "database error"); 135 } 116 136 psError(PS_ERR_UNKNOWN, false, "failed to convert new frame into a science frame"); 117 137 psFree(new); … … 119 139 } 120 140 if (!rawScienceFrameInsert(config, frame)) { 141 // rollback 142 if (!psDBRollback(config->dbh)) { 143 psError(PS_ERR_UNKNOWN, false, "database error"); 144 } 121 145 psError(PS_ERR_UNKNOWN, false, "failed to insert frame into the database"); 122 146 psFree(frame); … … 127 151 128 152 // insert into into p2PendingExp 129 p2PendingExpRow *exp = newToP2PendingExp(newFrame->exposure); 153 // XXX add a newToP2PendingFrame() 154 // XXX add a p2PendingFrameInsert() 155 p2PendingExpRow *exp = newToP2PendingExp(config, newFrame->exposure); 130 156 if (!exp) { 157 // rollback 158 if (!psDBRollback(config->dbh)) { 159 psError(PS_ERR_UNKNOWN, false, "database error"); 160 } 131 161 psError(PS_ERR_UNKNOWN, false, "failed to convert newExp into a p2PendingExp"); 132 162 psFree(new); 133 163 return false; 134 164 } 165 135 166 if (!p2PendingExpInsertObject(config->dbh, exp)) { 167 // rollback 168 if (!psDBRollback(config->dbh)) { 169 psError(PS_ERR_UNKNOWN, false, "database error"); 170 } 136 171 psError(PS_ERR_UNKNOWN, false, "failed to insert p2PendingExp into the database"); 137 172 psFree(exp); … … 145 180 p2PendingImfileRow *imfile = newImfileToP2PendingImfile(newFrame->images->data[i]); 146 181 if (!p2PendingImfileInsertObject(config->dbh, imfile)) { 147 psError(PS_ERR_UNKNOWN, false, "failed to insert p2PendingImfile into the database"); 182 // rollback 183 if (!psDBRollback(config->dbh)) { 184 psError(PS_ERR_UNKNOWN, false, "database error"); 185 } 186 psError(PS_ERR_UNKNOWN, false, "failed to insert p2PendingImfile into the database"); 148 187 psFree(imfile); 149 188 psFree(new); … … 152 191 psFree(imfile); 153 192 } 193 } 194 // point of no return for p2Pending[Exp|Imfile] 195 if (!psDBCommit(config->dbh)) { 196 psError(PS_ERR_UNKNOWN, false, "database error"); 197 return false; 154 198 } 155 199 } … … 231 275 newExp->telescope, 232 276 newExp->exp_type, 233 // newExp->class,234 277 newExp->imfiles, 235 278 "my filter", 236 "my stats", 279 0.1, // airmass 280 0.2, // ra 281 0.3, // dec 282 0.4, // exp time 283 0.5, // background 237 284 "my recipe", 238 285 0xff // XXX calc version number … … 240 287 } 241 288 242 static p2PendingExpRow *newToP2PendingExp(newExpRow *newExp) 243 { 289 static p2PendingExpRow *newToP2PendingExp(pxConfig *config, newExpRow *exp) 290 { 291 PS_ASSERT_PTR_NON_NULL(config, NULL); 292 PS_ASSERT_PTR_NON_NULL(exp, NULL); 293 294 bool status = false; 295 psString filter = psMetadataLookupStr(&status, config->args, "-filter"); 296 if (!status) { 297 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -filter"); 298 return false; 299 } 300 if (!filter) { 301 psError(PS_ERR_UNKNOWN, true, "-filter is required"); 302 return false; 303 } 304 psF32 airmass = psMetadataLookupF32(&status, config->args, "-airmass"); 305 if (!status) { 306 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -airmass"); 307 return false; 308 } 309 if (isnan(airmass)) { 310 psError(PS_ERR_UNKNOWN, true, "-airmass is required"); 311 return false; 312 } 313 psF64 ra = psMetadataLookupF64(&status, config->args, "-ra"); 314 if (!status) { 315 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ra"); 316 return false; 317 } 318 if (isnan(ra)) { 319 psError(PS_ERR_UNKNOWN, true, "-ra is required"); 320 return false; 321 } 322 psF64 decl = psMetadataLookupF64(&status, config->args, "-decl"); 323 if (!status) { 324 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -decl"); 325 return false; 326 } 327 if (isnan(decl)) { 328 psError(PS_ERR_UNKNOWN, true, "-decl is required"); 329 return false; 330 } 331 psF32 exp_time = psMetadataLookupF32(&status, config->args, "-exp_time"); 332 if (!status) { 333 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_time"); 334 return false; 335 } 336 if (isnan(exp_time)) { 337 psError(PS_ERR_UNKNOWN, true, "-exp_time is required"); 338 return false; 339 } 340 psF64 background = psMetadataLookupF64(&status, config->args, "-background"); 341 if (!status) { 342 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -background"); 343 return false; 344 } 345 if (isnan(background)) { 346 psError(PS_ERR_UNKNOWN, true, "-background is required"); 347 return false; 348 } 349 244 350 return p2PendingExpRowAlloc( 245 newExp->exp_id, 246 newExp->camera, 247 newExp->telescope, 248 newExp->exp_type, 249 // newExp->class, 250 newExp->imfiles, 251 "my filter", 252 "my stats", 351 exp->exp_id, 352 exp->camera, 353 exp->telescope, 354 exp->exp_type, 355 exp->imfiles, 356 filter, 357 airmass, 358 ra, 359 decl, 360 exp_time, 361 background, 253 362 "my recipe", 254 363 0xff, // XXX calc version number … … 263 372 newImfile->class_id, 264 373 newImfile->uri, 265 "my stats",266 374 "my recipe", 267 375 0xff, // XXX calc version number … … 269 377 ); 270 378 } 379 380 static rawScienceFrame *newToRawScienceFrame(pxConfig *config, newFrame *newFrame) 381 { 382 PS_ASSERT_PTR_NON_NULL(config, NULL); 383 PS_ASSERT_PTR_NON_NULL(newFrame, NULL); 384 385 newExpRow *newExp = newFrame->exposure; 386 rawScienceExpRow *rawScienceExp = newToRawScienceExp(config, newExp); 387 if (!rawScienceExp) { 388 psError(PS_ERR_UNKNOWN, false, "failed to convert newExp to rawScienceExp"); 389 return NULL; 390 } 391 392 psArray *newImages = newFrame->images; 393 psArray *rawImages = psArrayAlloc(psArrayLength(newImages)); 394 for (long i = 0; i < psArrayLength(newImages); i++) { 395 newImfileRow *newImfile = newImages->data[i]; 396 rawImfileRow *rawImfile = rawImfileRowAlloc( 397 newImfile->exp_id, 398 newImfile->class, 399 newImfile->class_id, 400 newImfile->uri 401 ); 402 psArrayAdd(rawImages, 0, rawImfile); 403 psFree(rawImfile); 404 } 405 406 rawScienceFrame *rawScienceFrame = rawScienceFrameAlloc(rawScienceExp, rawImages); 407 psFree(rawScienceExp); 408 psFree(rawImages); 409 410 return rawScienceFrame; 411 } 412 413 static rawScienceExpRow *newToRawScienceExp(pxConfig *config, newExpRow *exp) 414 { 415 PS_ASSERT_PTR_NON_NULL(config, NULL); 416 PS_ASSERT_PTR_NON_NULL(exp, NULL); 417 418 bool status = false; 419 psString filter = psMetadataLookupStr(&status, config->args, "-filter"); 420 if (!status) { 421 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -filter"); 422 return NULL; 423 } 424 if (!filter) { 425 psError(PS_ERR_UNKNOWN, true, "-filter is required"); 426 return NULL; 427 } 428 psF32 airmass = psMetadataLookupF32(&status, config->args, "-airmass"); 429 if (!status) { 430 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -airmass"); 431 return NULL; 432 } 433 if (isnan(airmass)) { 434 psError(PS_ERR_UNKNOWN, true, "-airmass is required"); 435 return NULL; 436 } 437 psF64 ra = psMetadataLookupF64(&status, config->args, "-ra"); 438 if (!status) { 439 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -ra"); 440 return NULL; 441 } 442 if (isnan(ra)) { 443 psError(PS_ERR_UNKNOWN, true, "-airmass is required"); 444 return NULL; 445 } 446 psF64 decl = psMetadataLookupF64(&status, config->args, "-decl"); 447 if (!status) { 448 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -decl"); 449 return NULL; 450 } 451 if (isnan(decl)) { 452 psError(PS_ERR_UNKNOWN, true, "-decl is required"); 453 return NULL; 454 } 455 psF32 exp_time = psMetadataLookupF32(&status, config->args, "-exp_time"); 456 if (!status) { 457 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_time"); 458 return NULL; 459 } 460 if (isnan(exp_time)) { 461 psError(PS_ERR_UNKNOWN, true, "-exp_time is required"); 462 return NULL; 463 } 464 psF64 background = psMetadataLookupF64(&status, config->args, "-background"); 465 if (!status) { 466 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -background"); 467 return NULL; 468 } 469 if (isnan(background)) { 470 psError(PS_ERR_UNKNOWN, true, "-background is required"); 471 return NULL; 472 } 473 474 return rawScienceExpRowAlloc( 475 exp->exp_id, 476 exp->camera, 477 exp->telescope, 478 exp->exp_type, 479 exp->imfiles, 480 filter, 481 airmass, 482 ra, 483 decl, 484 exp_time, 485 background 486 ); 487 } 488 489
Note:
See TracChangeset
for help on using the changeset viewer.
