Create Xref-Html Frames                    Remove All Frames
file:d:/code/LRC/Splicer/splicer_code_ver2.2/splicer_drawing_functions.c        (Tue Mar 14 16:49:26 2000 )


   1: /*
   2:     contains the following functions:
   3: */
   4:          void SplicerInitialSettings();
   5:          void SetMinMax();
   6:          void SetDisplayDefaults();
   7:          int  GetDisplayValues();
   8:          void AxisDep();
   9:          void AxisVar();
  10:          void AxisCorr();
  11:          void AxisDepthOffset();
  12:          void AxisAge();
  13:          void MakeTheGCs();
  14:          void SetInitialColors();
  15:          int  FindAveDepth();
  16:          int  Correlate();
  17:          int  RepickDepth();
  18:          int  FindMinMax();
  19:          int  CleanUpCore();
  20:          int  CleanUpSpliceCore();
  21:          void DisplaySliderControl();
  22:          int  StdDev();
  23:          int  SiteAveDepth();
  24:          void MakeClipMask();
  25:          void FindClipRegion();
  26:          int  FindMinMaxOneCore();
  27:          void ReadColorList();
  28:          int  GetColorPixelValue();
  29:          void SetCustomeColorButtonColors();
  30:          void SetCustomeColorWidgetBGColors();
  31:          void SetCustomeColorWidgetFGColors();
  32:          void PlaceDialog();
  33:          void MapStratToAffine();
  34:          void FindStratDepthOffset();
  35:          void AgeDepthMinMax();
  36:          void AgeDepthPlotValues();
  37:          int  CalcAge();
  38:          int  GetColorSet();
  39:          void SetColorSetBGandFG();
  40:          int FindSpliceAveAge();
  41: 
  42: #include <Xm/Xm.h>
  43: #include <Xm/Text.h>
  44: #include <stdio.h>
  45: #include <stdlib.h>
  46: #include <string.h>
  47: #include <math.h>
  48: #include "splicer-creation-c.h"
  49: #include "splicer_vars.h"
  50: 
  51: void SplicerInitialSettings(dpy)
  52: Display *dpy;
  53: {
  54:   int i;
  55:   char *string;
  56:   time_t tp;
  57: 
  58: /*
  59:   if((string=(char*)calloc(1000, CHAR_SIZE))==NULL)
  60:                  SpBadMemAlloc("");
  61:   (void)strcpy(string,(char*)getenv("WHERE_AM_I"));
  62:   for(i=0; i<strlen(string); ++i) {
  63:     string[i] = toupper(string[i]);
  64:   }
  65:   if(strcmp(string, "SHIP") == 0) {
  66:     whereami = SHIP;
  67:   }
  68:   else if(strcmp(string, "SHORE") == 0) {
  69:     whereami = SHORE;
  70:   }
  71:   else {
  72:     whereami = SHORE;
  73:   }
  74:   free(string);
  75: */
  76:   dataset_cnt = 0;
  77:   dset = 0;
  78:   XtUnmanageChild(optionMenuDataSet);
  79:   XtUnmanageChild(pushButtonDataSet1);
  80:   XtUnmanageChild(pushButtonDataSet2);
  81:   XtUnmanageChild(pushButtonDataSet3);
  82:   XtUnmanageChild(pushButtonDataSet4);
  83:   XtUnmanageChild(pushButtonDataSet5);
  84:   XtUnmanageChild(pushButtonDataSet6);
  85:   XtUnmanageChild(pushButtonDataSet7);
  86:   XtUnmanageChild(pushButtonDataSet8);
  87:   XtUnmanageChild(pushButtonDataSet9);
  88:   have_data = DONT;
  89:   have_affine = DONT;
  90:   have_tie = DONT;
  91:   last_tie = NONE;
  92:   have_tie1 = NO;
  93:   have_tie2 = NO;
  94:   have_shift = DONT;
  95:   have_corr = DONT;
  96:   have_splice = DONT;
  97:   have_core_to_splice = DONT;
  98:   have_splice_tie = DONT;
  99:   last_sp_tie = NONE;
 100:   have_sp_tie1 = NO;
 101:   have_sp_tie2 = NO;
 102:   have_strat = DONT;
 103:   have_splicetoage = DONT;
 104:   have_time_series = DONT;
 105:   have_splicetoage_tie = DONT;
 106:   have_timeseries_tie = DONT;
 107:   last_splicetoage_tie = NONE;
 108:   have_splicetoage_corr = DONT;
 109:   lastaffinehole = -1;
 110:   lastaffinecore = -1;
 111:   draw_offsets = NO;
 112:   are_compositing = NO;
 113:   did_affine = NO;
 114:   saved_affine = NO;
 115:   are_splicing = NO;
 116:   did_splicing = NO;
 117:   saved_splice = NO;
 118:   are_dragging = NO;
 119:   are_agemodelling = NO;
 120:   did_agemodel = NO;
 121:   saved_agemodel = NO;
 122:   agemodel_cnt = 0;
 123:   reason_for_redraw = DRAW_EVERYTHING;
 124:   last_scale_val_edit = 0;
 125:   last_scale_val_view = 0;
 126:   splicertable.data_cnt = 0;
 127:   agemodel_cnt = 0;
 128:   are_agemodelling = NO;
 129:   agemodelling_depth_type = MBSF;
 130:   write_report = NO;
 131:   open_dataform_is_up = NO;
 132:   MakeTheGCs(dpy);
 133:   SetInitialColors(dpy);
 134:   SetDisplayDefaults();
 135:   ReadColorList(dpy);
 136:   XtSetSensitive(pushButtonDataBase, FALSE);
 137:   XtSetSensitive(cascadeButtonSave,FALSE);
 138:   XtSetSensitive(pushButtonSaveCull,FALSE);
 139:   XtSetSensitive(pushButtonSaveAffine,FALSE);
 140:   XtSetSensitive(pushButtonSaveSplicerTable,FALSE);
 141:   XtSetSensitive(pushButtonSaveStrat,FALSE);
 142:   XtSetSensitive(pushButtonSaveData,FALSE);
 143:   XtSetSensitive(pushButtonSaveSplicerData,FALSE);
 144:   XtSetSensitive(cascadeButtonClear,FALSE);
 145:   XtSetSensitive(pushButtonClearAll,FALSE);
 146:   XtSetSensitive(pushButtonClearComposite,FALSE);
 147:   XtSetSensitive(pushButtonClearSplice,FALSE);
 148:   XtSetSensitive(pushButtonClearStrat,FALSE);
 149:   XtSetSensitive(pushButtonComposite,FALSE);
 150:   XtSetSensitive(cascadeButtonSplice,FALSE);
 151:   XtSetSensitive(pushButtonDisplay,TRUE);
 152:   XtSetSensitive(pushButtonViewOffsets,FALSE);
 153:   XtSetSensitive(pushButtonViewAgeDepth,FALSE);
 154:   XtSetSensitive(cascadeButtonDataManip, False);
 155:   XmToggleButtonSetState(toggleButtonLockSlider, True, NULL);
 156:   XmToggleButtonSetState(toggleButtonAgeDepthmbsf, True, NULL);
 157:   XmToggleButtonSetState(toggleButtonPlotUnsmooth, True, NULL); 
 158:   XmToggleButtonSetState(toggleButtonPlotSmooth, False, NULL);
 159:   XmToggleButtonSetState(toggleButtonPlotBoth, False, NULL);
 160:   XmToggleButtonSetState(toggleButtonOpenFormatsOther1, True, NULL);
 161:   XtSetSensitive(toggleButtonPlotSmooth,FALSE);
 162:   XtSetSensitive(toggleButtonPlotUnsmooth,FALSE);
 163:   XtSetSensitive(toggleButtonPlotBoth,FALSE);
 164:   XmToggleButtonSetState(toggleButtonHeaderNo, True, NULL);
 165:   XmToggleButtonSetState(toggleButtonHeaderYes, False, NULL);
 166: 
 167:   XtUnmanageChild(formFileSelectionTimeSeries);
 168:   XtUnmanageChild(optionMenuStratType1);
 169:   XtUnmanageChild(labelStratType1);
 170:   XtVaSetValues(XtParent(formFileSelection), XmNheight, 640, NULL);
 171: 
 172:   /* write to report
 173:   */
 174:   XtManageChild(formTextReport);
 175:   if((string=(char*)calloc(1000, CHAR_SIZE))==NULL)
 176:                  SpBadMemAlloc("");
 177:   if(time(&tp)) {
 178:     (void)sprintf(string,"Start of Session.  %s",ctime(&tp));
 179:   }
 180:   else {
 181:     (void)sprintf(string, "Start of Session. No date available.\n");
 182:   }
 183:   SpUpdateReport(string);
 184:   free(string);
 185:   XtPopdown(XtParent(formTextReport));
 186: }
 187: 
 188: void SetMinMax(ds)
 189: int ds;
 190: {
 191:   int scalemax;
 192:   char string[50];
 193: 
 194:   (void)sprintf(string, "%.2f", data[ds]->min); 
 195:   XtVaSetValues(textVarMin, XmNvalue, string, NULL); 
 196:   (void)sprintf(string, "%.2f", data[ds]->max); 
 197:   XtVaSetValues(textVarMax, XmNvalue, string, NULL); 
 198: 
 199:   scalemax = maxdep + (0.2 * maxdep); 
 200:   XtVaSetValues(drawingAreaEditScale, XmNmaximum, scalemax, NULL); 
 201:   XtVaSetValues(drawingAreaViewScale, XmNmaximum, scalemax, NULL);
 202: 
 203:   (void)sprintf(string, "");
 204: }
 205: 
 206: void SetDisplayDefaults()
 207: {
 208:   int scalemax;
 209:   char string[50];
 210: 
 211:   depmeterdisplayed = DEPMETERDISPLAYED;
 212:   (void)sprintf(string, "%.3f", depmeterdisplayed);
 213:   XtVaSetValues(textDepthScale, XmNvalue, string, NULL);
 214: 
 215:   deptic = DEPTIC;
 216:   (void)sprintf(string, "%.1f", deptic); 
 217:   XtVaSetValues(textDepthTic, XmNvalue, string, NULL); 
 218: 
 219:   varaxislen = VAR_AXIS_LEN;
 220:   (void)sprintf(string, "%d", varaxislen); 
 221:   XtVaSetValues(textVarAxisLen, XmNvalue, string, NULL); 
 222: 
 223:   minvar = 0.0;
 224:   (void)sprintf(string, "%.2f", minvar); 
 225:   XtVaSetValues(textVarMin, XmNvalue, string, NULL); 
 226: 
 227:   maxvar = 0.0;
 228:   (void)sprintf(string, "%.2f", maxvar);
 229:   XtVaSetValues(textVarMax, XmNvalue, string, NULL); 
 230: 
 231:   scale_mult = SCALE_MULT;
 232:   (void)sprintf(string, "%d", scale_mult); 
 233:   XtVaSetValues(textScaleMult, XmNvalue, string, NULL); 
 234: 
 235:   XtVaSetValues(drawingAreaEditScale, XmNscaleMultiple, scale_mult, NULL);
 236:   XtVaSetValues(drawingAreaViewScale, XmNscaleMultiple, scale_mult, NULL);
 237:   XmToggleButtonSetState(toggleButtonScaleDragYes, True, NULL);
 238:   XmToggleButtonSetState(toggleButtonScaleDragNo, False, NULL);
 239: 
 240:   maxdep = MAXDEP;
 241:   scalemax = maxdep;
 242:   XtVaSetValues(drawingAreaEditScale, XmNmaximum, scalemax, NULL);
 243:   XtVaSetValues(drawingAreaViewScale, XmNmaximum, scalemax, NULL);
 244: 
 245:   XmToggleButtonSetState(toggleButtonPlotUnsmooth, False, NULL);
 246:   XmToggleButtonSetState(toggleButtonPlotSmooth, False, NULL);
 247:   XmToggleButtonSetState(toggleButtonPlotBoth, False, NULL);
 248: /*
 249:   if(smooth.method == NONE) {
 250:   }
 251:   else if(smooth.plot == UNSMOOTHED) {
 252:   }
 253:   else if(smooth.plot == SMOOTHED) {
 254:     XmToggleButtonSetState(toggleButtonPlotSmooth, True, NULL);
 255:     XmToggleButtonSetState(toggleButtonPlotUnsmooth, False, NULL);
 256:   }
 257:   else if(smooth.plot == SMOOTHEDBOTH) {
 258:     XmToggleButtonSetState(toggleButtonPlotBoth, True, NULL);
 259:     XmToggleButtonSetState(toggleButtonPlotUnsmooth, False, NULL);
 260:   }
 261: */  
 262:   (void)sprintf(string, "%.2f", DEPTHCHANGE);
 263:   XtVaSetValues(textDepthChange, XmNvalue, string, NULL);
 264: 
 265:   (void)sprintf(string, "");
 266: }
 267: 
 268: 
 269: int GetDisplayValues(ds)
 270: int ds;
 271: {
 272:   double check, fract, ip;
 273:   String  str;
 274: 
 275:   str = XmTextGetString(textDepthScale);
 276:   depmeterdisplayed = atof(str);
 277:   XtFree(str);
 278: 
 279:   /* check that meters display is a whole number >= 1
 280:   */
 281:   check = depmeterdisplayed;
 282:   fract = modf(check, &ip);
 283:   if(fract != 0.0){
 284:     depmeterdisplayed = DEPMETERDISPLAYED;
 285:     (void)sprintf(buffer,"meters displayed must be a whole number.");
 286:     SpManageWarningBox(buffer);
 287:     return 1;
 288:   }
 289:   if(depmeterdisplayed < 1.0){
 290:     depmeterdisplayed = DEPMETERDISPLAYED;
 291:     (void)sprintf(buffer,"meters displayed must be greater than or equal to 1.0."); 
 292:     SpManageWarningBox(buffer); 
 293:     return 1;
 294:   }
 295: 
 296:   str = XmTextGetString(textDepthTic); 
 297:   deptic = atof(str);
 298:   XtFree(str);
 299: 
 300: 
 301:   /* check that the depth tic is a whole number and divides evenly into number
 302:      of meters displayed
 303:   */
 304:   check = deptic;
 305:   fract = modf(check, &ip);
 306:   if(fract != 0.0){
 307:     deptic = DEPTIC;
 308:     (void)sprintf(buffer,"the depth tic must be a whole number.");
 309:     SpManageWarningBox(buffer);
 310:     return 1;
 311:   }
 312:   check = depmeterdisplayed/deptic;
 313:   fract = modf(check, &ip);
 314:   if(fract != 0.0){
 315:     deptic = DEPTIC;
 316:     (void)sprintf(buffer,"the depth tic interval must divide evenly into number of meters displyed");
 317:     SpManageWarningBox(buffer);
 318:     return 1;
 319:   }
 320: 
 321:   str = XmTextGetString(textVarAxisLen); 
 322:   varaxislen = atoi(str);
 323:   XtFree(str);
 324: 
 325:   /* check that the var axis length has some length
 326:   */
 327:   if(varaxislen < 10){
 328:     varaxislen = VAR_AXIS_LEN;
 329:     (void)sprintf(buffer,"the variable axis pixel length is unreasonably small.");
 330:     SpManageWarningBox(buffer);
 331:     return 1;
 332:   }
 333: 
 334:   str = XmTextGetString(textVarMin); 
 335:   minvar = atof(str);
 336:   XtFree(str);
 337: 
 338:   str = XmTextGetString(textVarMax); 
 339:   maxvar = atof(str);
 340:   XtFree(str);
 341: 
 342:   /* check that the max is greater than the min and the range is not 
 343:      approaching zero
 344:   */
 345:   if(maxvar < minvar){
 346:     (void)sprintf(buffer,"the variable axis maximum is less than its minimum."); 
 347:     SpManageWarningBox(buffer);
 348:     return 1; 
 349:   }
 350:   if(have_data == DO){
 351:     if(maxvar == minvar){
 352:       (void)sprintf(buffer,"the variable axis minimum equals its maximum."); 
 353:       SpManageWarningBox(buffer);
 354:       return 1;  
 355:     }
 356:     if(fabs(maxvar - minvar) < 0.001){
 357:       (void)sprintf(buffer,"the variable axis range is unreasonably small."); 
 358:       SpManageWarningBox(buffer);
 359:       return 1; 
 360:     }
 361:   }
 362: 
 363:   if(have_data == DO) {
 364:     data[ds]->min = minvar;
 365:     data[ds]->max = maxvar;
 366:   }
 367: 
 368:      /* check that the var axis length and var display range relative to
 369:         real var range is reasonable. just warn;  
 370:   
 371:      if((varaxislen/(maxvar - minvar) * (realmaxvar - realminvar) - varaxislen) > 200) {
 372:        (void)sprintf(buffer,"the variable axis display range is much smaller than real range.");
 373:        SpManageWarningBox(buffer);
 374:      }
 375:     */
 376: 
 377:   str = XmTextGetString(textScaleMult); 
 378:   check = atof(str);
 379:   XtFree(str);
 380: 
 381:   /* check that slider scale is a whole number greater than or equal to one
 382:   */
 383:   fract = modf(check, &ip);
 384:   if(fract != 0.0){
 385:     (void)sprintf(buffer,"the scroll increment must be a whole number.");
 386:     SpManageWarningBox(buffer);
 387:     return 1;
 388:   }
 389:   scale_mult = check;
 390:   if(scale_mult < 1){
 391:     (void)sprintf(buffer,"the scroll increment must be greater than or equal to 1.0."); 
 392:     SpManageWarningBox(buffer); 
 393:     return 1; 
 394:   }
 395: 
 396:   XtVaSetValues(drawingAreaEditScale, XmNscaleMultiple, scale_mult, NULL);
 397:   XtVaSetValues(drawingAreaViewScale, XmNscaleMultiple, scale_mult, NULL);
 398: 
 399:   if(XmToggleButtonGetState(toggleButtonPlotUnsmooth) == True){
 400:     smooth.plot = UNSMOOTHED;
 401:   }
 402:   else if(XmToggleButtonGetState(toggleButtonPlotSmooth) == True){
 403:     smooth.plot = SMOOTHED; 
 404:   }
 405:   else if(XmToggleButtonGetState(toggleButtonPlotBoth) == True){
 406:     smooth.plot = SMOOTHEDBOTH; 
 407:   }
 408: 
 409:   return 0;
 410: }
 411: 
 412: 
 413: void AxisDep(w, dpy, wid, gc, maxmeter, top_off, left, ticpixlen, depinc, unitinc, depscalepix, annot, label)
 414: Widget w;
 415: Display *dpy;
 416: Window wid;
 417: GC gc;
 418: int top_off, left, ticpixlen, annot, label;
 419: float unitinc, depscalepix, depinc, maxmeter;
 420: {
 421:   int yoff, laboff, chk;
 422:   char s[50];
 423:   Dimension win_height;
 424: 
 425:   /* get the height and width of the drawing area
 426:   */
 427:   XtVaGetValues(w, XmNheight, &win_height, NULL);
 428: 
 429:   /* label the axis
 430:   */
 431:   if(label > 0){
 432:     if(label == MBSF) {
 433:       (void)sprintf(s,"mbsf");
 434:     }
 435:     else if(label == MCD) {
 436:       (void)sprintf(s,"mcd");
 437:     }
 438:     else {
 439:       (void)sprintf(s,"m");
 440:     }
 441:     XDrawString(dpy, wid, gc, 8, OFF + 30, s, (int)strlen(s));
 442:   }
 443: 
 444:   yoff = top_off;
 445:   /* draw the depth axis and tic it
 446:   */
 447:   if(left > 0) {
 448:     XDrawLine(dpy, wid, gc, OFF, yoff, OFF, yoff + left);
 449:     yoff = yoff + left;
 450:   }
 451:   laboff=YAXIS_ANNOT_OFF;
 452:   if(unitinc >= 10.0 && unitinc < 100.0) {
 453:     laboff = YAXIS_ANNOT_OFF + 5;
 454:   }
 455:   else if(unitinc >= 100.0) {
 456:     laboff=YAXIS_ANNOT_OFF + 9;
 457:   }
 458:   XDrawLine(dpy, wid, gc, OFF, yoff, OFF-4, yoff);
 459:   (void)sprintf(s,"%.1f",unitinc);
 460:   XDrawString(dpy, wid, gc, OFF-laboff, yoff+2, s, (int)strlen(s));
 461:   chk = 1;
 462:   
 463:   while(yoff+ticpixlen <= (int)win_height && unitinc < maxmeter){
 464:     XDrawLine(dpy, wid, gc, OFF, yoff, OFF, yoff+ticpixlen);
 465:     yoff = yoff + ticpixlen;
 466:     XDrawLine(dpy, wid, gc, OFF, yoff, OFF-4, yoff);
 467:     unitinc = unitinc + depinc;
 468:     if(unitinc >= 10.0 && unitinc < 100.0) {
 469:       laboff = YAXIS_ANNOT_OFF + 5;
 470:     }
 471:     else if(unitinc >= 100.0) {
 472:       laboff=YAXIS_ANNOT_OFF + 9;
 473:     }
 474:     if(chk == annot){
 475:       (void)sprintf(s,"%.1f",unitinc);
 476:       XDrawString(dpy, wid, gc, OFF-laboff, yoff, s, (int)strlen(s));
 477:       chk = 1;
 478:     }
 479:     else {
 480:       ++chk;
 481:     }
 482:   }
 483:   if(yoff < (int)win_height && unitinc < maxmeter) {
 484:     XDrawLine(dpy, wid, gc, OFF, yoff, OFF, win_height);
 485:   }
 486: 
 487:   (void)sprintf(s, "");
 488: } 
 489:  
 490: void AxisVar()
 491: {
 492: }
 493: 
 494: int XAxisDepthCorrSetup(lead, dt, len, tic, ntic, perpix, max)
 495: int    lead;
 496: float  dt;
 497: int    *len;
 498: float  *tic;
 499: int    *ntic;
 500: float  *perpix;
 501: float  *max;
 502: {
 503:   double fract, check, ip;
 504: 
 505:   check = *len;
 506:   if(lead * dt  <= 1){
 507:     fract = modf((check/5.0), &ip);
 508:     if(fract == 0.0){
 509:     }
 510:     else if(fract < 0.5){
 511:       *len = ip * 5.0;
 512:     }
 513:     else {
 514:       *len = (ip * 5.0) + 5.0;
 515:     }
 516:     *tic=0.2;
 517:     *ntic=10;
 518:     *perpix=1.0/(*len);
 519:     *max=1.0;
 520:   }
 521:   else if(lead * dt <= 2){
 522:     fract = modf((check/4.0), &ip);
 523:     if(fract == 0.0){
 524:     }
 525:     else if(fract < 0.5){
 526:       *len = ip * 4.0;
 527:     }
 528:     else {
 529:       *len = (ip * 4.0) + 4.0;
 530:     }
 531:     *tic=0.5;
 532:     *ntic=8;
 533:     *perpix=2.0/(*len);
 534:     *max=2.0;
 535:   }
 536:   else if(lead * dt <= 3){
 537:     fract = modf((check/6.0), &ip);
 538:     if(fract == 0.0){
 539:     }
 540:     else if(fract < 0.5){
 541:       *len = ip * 6.0;
 542:     }
 543:     else {
 544:       *len = (ip * 6.0) + 6.0;
 545:     }
 546:     *tic=0.5;
 547:     *ntic=12;
 548:     *perpix=3.0/(*len);
 549:     *max=3.0;
 550:   }
 551:   else if(lead * dt <= 4){
 552:     fract = modf((check/4.0), &ip);
 553:     if(fract == 0.0){
 554:     }
 555:     else if(fract < 0.5){
 556:       *len = ip * 4.0;
 557:     }
 558:     else {
 559:       *len = (ip * 4.0) + 4.0;
 560:     }
 561:     *tic=1.0;
 562:     *ntic=8;
 563:     *perpix=4.0/(*len);
 564:     *max=4.0;
 565:   }
 566:   else if(lead *dt <= 5){
 567:     fract = modf((check/5.0), &ip);
 568:     if(fract == 0.0){
 569:     }
 570:     else if(fract < 0.5){
 571:       *len = ip * 5.0;
 572:     }
 573:     else {
 574:       *len = (ip * 5.0) + 5.0;
 575:     }
 576:     *tic=1.0;
 577:     *ntic=10;
 578:     *perpix=5.0/(*len);
 579:     *max=5.0;
 580:   }
 581:   else if(lead * dt <= 6){
 582:     fract = modf((check/6.0), &ip);
 583:     if(fract == 0.0){
 584:     }
 585:     else if(fract < 0.5){
 586:       *len = ip * 6.0;
 587:     }
 588:     else {
 589:       *len = (ip * 6.0) + 6.0;
 590:     }
 591:     *tic=1.0;
 592:     *ntic=12;
 593:     *perpix=6.0/(*len);
 594:     *max=6.0;
 595:   }
 596:   else if(lead * dt <= 7){
 597:     fract = modf((check/7.0), &ip);
 598:     if(fract == 0.0){
 599:     }
 600:     else if(fract < 0.5){
 601:       *len = ip * 7.0;
 602:     }
 603:     else {
 604:       *len = (ip * 7.0) + 7.0;
 605:     }
 606:     *tic=1.0;
 607:     *ntic=14;
 608:     *perpix=7.0/(*len);
 609:     *max=7.0;
 610:   }
 611:   else if(lead * dt <= 8){
 612:     fract = modf((check/4.0), &ip);
 613:     if(fract == 0.0){
 614:     }
 615:     else if(fract < 0.5){
 616:       *len = ip * 4.0;
 617:     }
 618:     else {
 619:       *len = (ip * 4.0) + 4.0;
 620:     }
 621:     *tic=2.0;
 622:     *ntic=8;
 623:     *perpix=8.0/(*len);
 624:     *max=8.0;
 625:   }
 626:   else if(lead * dt <= 10){
 627:     fract = modf((check/5.0), &ip);
 628:     if(fract == 0.0){
 629:     }
 630:     else if(fract < 0.5){
 631:       *len = ip * 5.0;
 632:     }
 633:     else {
 634:       *len = (ip * 5.0) + 5.0;
 635:     }
 636:     *tic=2.0;
 637:     *ntic=10;
 638:     *perpix=10.0/(*len);
 639:     *max=10.0;
 640:   }
 641:   else if(lead * dt <= 15){
 642:     fract = modf((check/3.0), &ip);
 643:     if(fract == 0.0){
 644:     }
 645:     else if(fract < 0.5){
 646:       *len = ip * 3.0;
 647:     }
 648:     else {
 649:       *len = (ip * 3.0) + 3.0;
 650:     }
 651:     *tic=5.0;
 652:     *ntic=6;
 653:     *perpix=10.0/(*len);
 654:     *max=10.0;
 655:   }
 656:   else if(lead * dt <= 20){
 657:     fract = modf((check/4.0), &ip);
 658:     if(fract == 0.0){
 659:     }
 660:     else if(fract < 0.5){
 661:       *len = ip * 4.0;
 662:     }
 663:     else {
 664:       *len = (ip * 4.0) + 4.0;
 665:     }
 666:     *tic=5.0;
 667:     *ntic=8;
 668:     *perpix=10.0/(*len);
 669:     *max=10.0;
 670:   }
 671:   else if(lead * dt <= 25){
 672:     fract = modf((check/5.0), &ip);
 673:     if(fract == 0.0){
 674:     }
 675:     else if(fract < 0.5){
 676:       *len = ip * 5.0;
 677:     }
 678:     else {
 679:       *len = (ip * 5.0) + 5.0;
 680:     }
 681:     *tic=5.0;
 682:     *ntic=10;
 683:     *perpix=10.0/(*len);
 684:     *max=10.0;
 685:   }
 686:   else {
 687:     return 1;
 688:   }
 689: 
 690:   return 0;
 691: }
 692: 
 693: void AxisCorr(dpy, xid, gc, lagtic, nlagtic, maxlag, ylen, xlen, place)
 694: Display *dpy;
 695: Window xid;
 696: GC gc;
 697: int nlagtic, ylen, xlen, place;
 698: float lagtic, maxlag;
 699: {
 700:   int i, m, xoff, yoff, inc;
 701:   char s[50];
 702:   float corr;
 703: 
 704:   /* draw and label the lead,lag axis and tic it
 705:   */
 706:   XDrawString(dpy, xid, gc, SPACE, SPACE/2, "lag from tie", 12);
 707:   XDrawString(dpy, xid, gc, xlen + SPACE - 5, SPACE/2, "tie", 3);
 708:   XDrawString(dpy, xid, gc, (xlen * 2) + SPACE - 70, SPACE/2, "lead from tie", 13);
 709: 
 710:   m = SPACE;
 711:   yoff = (ylen/2) + SPACE;
 712:   XDrawLine(dpy, xid, gc, m, yoff, m + (xlen * 2), yoff);
 713:   if(place == 2) {
 714:     (void)sprintf(s,"%.2f",-1*maxlag);
 715:   }
 716:   else {
 717:     (void)sprintf(s,"%.1f",-1*maxlag);
 718:   }
 719:   XDrawString(dpy, xid, gc, m-5, yoff+15, s, (int)strlen(s));
 720:   inc = (xlen * 2)/nlagtic;
 721:   for(i=0; i <= nlagtic; ++i){
 722:     XDrawLine(dpy, xid, gc, m, yoff-3, m, yoff+3);
 723:     m = m + inc;
 724:   }  
 725:   if(place == 2) {
 726:     (void)sprintf(s,"%.2f", maxlag);
 727:   }
 728:   else {
 729:     (void)sprintf(s,"%.1f", maxlag);
 730:   }
 731:   XDrawString(dpy, xid, gc, m-5-inc, yoff+15, s, (int)strlen(s));
 732: 
 733:   /* draw and label the corr coef axis
 734:   */
 735:   m = SPACE;
 736:   corr = 1.0;
 737:   xoff = SPACE + xlen;
 738:   XDrawLine(dpy, xid, gc, xoff, m, xoff, ylen + SPACE);
 739:   (void)sprintf(s,"%.1f",corr);
 740:   XDrawString(dpy, xid, gc, xoff+10, m+3, s, (int)strlen(s));
 741:   inc = ylen/10;
 742:   for(i=0; i <= 10; ++i){
 743:     XDrawLine(dpy, xid, gc, xoff-3, m, xoff+3, m);
 744:     m = m + inc;
 745:   }  
 746:   (void)sprintf(s,"%.1f",-1*corr);
 747:   XDrawString(dpy, xid, gc, xoff+10, m+3-inc, s, (int)strlen(s));
 748: 
 749:   (void)sprintf(s, "");
 750: }
 751: 
 752: void AxisDepthOffset(w, dpy, wid, gc, maxmeter, top_off, left, ticpixlen, depinc, unitinc, depscalepix, annot)
 753: Widget w;
 754: Display *dpy;
 755: Window wid;
 756: GC gc;
 757: int top_off, left, ticpixlen, annot;
 758: float unitinc, depscalepix, depinc, maxmeter;
 759: {
 760:   int xoff, laboff, inc, dinc;
 761:   char s[50];
 762:   Dimension win_width;
 763: 
 764:   /* get the  width of the drawing area
 765:   */ 
 766:   XtVaGetValues(w, XmNwidth, &win_width, NULL);
 767: 
 768:   /*label the axis
 769:   */
 770:   (void)sprintf(s,"Depth offset (m)");
 771:   XDrawString(dpy, wid, gc, OFF + 20, 20, s, (int)strlen(s));
 772: 
 773:   inc = unitinc + .1;
 774:   dinc = depinc + .1;
 775: 
 776:   /* draw the depth offset axis(x axis) and tic it
 777:   */
 778:   xoff = OFF;
 779:   laboff= 0;
 780:   XDrawLine(dpy, wid, gc, xoff, OFF, xoff, OFF - 4);
 781:   (void)sprintf(s,"%d",inc);
 782:   XDrawString(dpy, wid, gc, xoff - laboff, OFF - 10, "0", 1);
 783:      
 784:   while(xoff + ticpixlen <= (int)win_width && unitinc < maxmeter){
 785:     XDrawLine(dpy, wid, gc, xoff, OFF, xoff + ticpixlen, OFF);
 786:     xoff = xoff + ticpixlen;
 787:     XDrawLine(dpy, wid, gc, xoff, OFF, xoff, OFF - 4);
 788:     inc = inc + dinc;
 789:     if(inc >= 10 && inc < 100){
 790:       laboff = 3;
 791:     }
 792:     else if(unitinc >= 100.0) {
 793:       laboff= 5;
 794:     }
 795:     (void)sprintf(s,"%d",inc);
 796:     XDrawString(dpy, wid, gc, xoff - laboff, OFF - 10, s, (int)strlen(s));
 797:   }
 798: 
 799:   (void)sprintf(s, "");
 800: }
 801: 
 802: void AxisAge(w, dpy, wid, gc, maxage, top_off, left, ticpixlen, ageinc, unitinc, ageperpix, annot)
 803: Widget w;
 804: Display *dpy;
 805: Window wid;
 806: GC gc;
 807: int top_off, ticpixlen, annot, left;
 808: float unitinc, ageperpix, ageinc, maxage;
 809: {
 810:   int xoff, laboff, inc, dinc, max;
 811:   char s[50]; 
 812:   Dimension win_width;
 813:  
 814:   /* get the  width of the drawing area
 815:   */ 
 816:   XtVaGetValues(w, XmNwidth, &win_width, NULL);
 817:  
 818:   /*label the axis
 819:   */
 820:   (void)sprintf(s,"Age(Ma)");
 821:   XDrawString(dpy, wid, gc, OFF + 20, 20, s, (int)strlen(s));
 822:  
 823:   inc = unitinc + .1;
 824:   dinc = ageinc + .1;
 825:   max = maxage + .1;
 826:  
 827:   xoff = top_off;
 828: 
 829:   /* if axis does not start at first tic draw up to first tic
 830:   */
 831:   if(left > 0) {
 832:     XDrawLine(dpy, wid, gc, xoff, top_off_agedepth_depth, xoff + left, top_off_agedepth_depth);
 833:     xoff = xoff + left;
 834:   }
 835: 
 836:   /* draw and label the first tic
 837:   */
 838:   laboff= 0;
 839:   XDrawLine(dpy, wid, gc, xoff, OFF, xoff, OFF - 4);
 840:   (void)sprintf(s,"%d",inc);
 841:   XDrawString(dpy, wid, gc, xoff - laboff, top_off_agedepth_depth - 10, s, (int)strlen(s));
 842:      
 843:   while(inc < max){
 844:     XDrawLine(dpy, wid, gc, xoff, top_off_agedepth_depth, xoff + ticpixlen, top_off_agedepth_depth);
 845:     xoff = xoff + ticpixlen;
 846:     XDrawLine(dpy, wid, gc, xoff, top_off_agedepth_depth, xoff, top_off_agedepth_depth - 4);
 847:     inc = inc + dinc;
 848:     if(inc >= 10 && inc < 100){
 849:       laboff = 3;
 850:     }
 851:     else if(inc >= 100.0) {
 852:       laboff= 5;
 853:     }
 854:     (void)sprintf(s,"%d",inc);
 855:     XDrawString(dpy, wid, gc, xoff - laboff, top_off_agedepth_depth - 10, s, (int)strlen(s));
 856:   }
 857:   if(xoff < (int)win_width - top_off - SPACE - OFF && inc < max) {
 858:     ticpixlen = (int)win_width - top_off - SPACE - xoff;
 859:     XDrawLine(dpy, wid, gc, xoff, top_off_agedepth_depth, xoff + ticpixlen, top_off_agedepth_depth);
 860:     xoff = xoff + ticpixlen;
 861:     XDrawLine(dpy, wid, gc, xoff, top_off_agedepth_depth, xoff, top_off_agedepth_depth - 4);
 862:     laboff = 25;
 863:     unitinc = inc + (ticpixlen * ageperpix);
 864:     (void)sprintf(s,"%8.4f",unitinc);
 865:     XDrawString(dpy, wid, gc, xoff - laboff, top_off_agedepth_depth - 10, s, (int)strlen(s));
 866:   }
 867: 
 868:   (void)sprintf(s, "");
 869: }
 870: 
 871: AxisSpliceAge(w, dpy, wid, gc, maxmeter, top_off, left, ticpixlen, depinc, unitinc, depscalepix, annot, label)
 872: Widget w;
 873: Display *dpy;
 874: Window wid;
 875: GC gc;
 876: int top_off, left, ticpixlen, annot, label;
 877: float unitinc, depscalepix, depinc, maxmeter;
 878: {
 879:   int yoff, laboff, chk;
 880:   char s[50];
 881:   Dimension win_height;
 882: 
 883:   /* get the height and width of the drawing area
 884:   */
 885:   XtVaGetValues(w, XmNheight, &win_height, NULL);
 886: 
 887:   if(label > 0){
 888:     (void)sprintf(s,"Ma");
 889:     XDrawString(dpy, wid, gc, 8, OFF + 30, s, (int)strlen(s));
 890:   }
 891: 
 892:   yoff = top_off;
 893:   /* draw the depth axis and tic it
 894:   */
 895:   if(left > 0) {
 896:     XDrawLine(dpy, wid, gc, OFF, yoff, OFF, yoff + left);
 897:     yoff = yoff + left;
 898:   }
 899:   laboff=YAXIS_ANNOT_OFF + 10;
 900:   if(unitinc >= 10.0) {
 901:     laboff = YAXIS_ANNOT_OFF + 15;
 902:   }
 903:   XDrawLine(dpy, wid, gc, OFF, yoff, OFF-4, yoff);
 904:   (void)sprintf(s,"%.3f",unitinc);
 905:   XDrawString(dpy, wid, gc, OFF-laboff, yoff+2, s, (int)strlen(s));
 906:   chk = 1;
 907:  
 908:   while(yoff+ticpixlen <= (int)win_height && unitinc < maxmeter){
 909:     XDrawLine(dpy, wid, gc, OFF, yoff, OFF, yoff+ticpixlen);
 910:     yoff = yoff + ticpixlen;
 911:     XDrawLine(dpy, wid, gc, OFF, yoff, OFF-4, yoff);
 912:     unitinc = unitinc + depinc;
 913:     if(unitinc >= 10.0 && unitinc < 100.0) {
 914:       laboff = YAXIS_ANNOT_OFF + 5;
 915:     }
 916:     else if(unitinc >= 100.0) {
 917:       laboff=YAXIS_ANNOT_OFF + 9;
 918:     }
 919:     if(chk == annot){
 920:       (void)sprintf(s,"%.3f",unitinc);
 921:       XDrawString(dpy, wid, gc, OFF-laboff, yoff, s, (int)strlen(s));
 922:       chk = 1;
 923:     }
 924:     else {
 925:       ++chk;
 926:     }
 927:   }
 928:   if(yoff < (int)win_height && unitinc < maxmeter) {
 929:     XDrawLine(dpy, wid, gc, OFF, yoff, OFF, win_height);
 930:   }
 931: 
 932:   (void)sprintf(s, "");
 933: }
 934: 
 935: void MakeTheGCs(display)
 936: Display *display;
 937: {
 938:   int screen_num;
 939:   XFontStruct *font;
 940: 
 941:   /* create the GC's for the drawing windows 
 942:   */
 943:   screen_num = DefaultScreen(display);
 944:   gc_drawingAreaEdit = XCreateGC(display,
 945:                        RootWindow(display, screen_num),
 946:                        NULL, NULL);
 947:   gc_drawingAreaView = XCreateGC(display, 
 948:                        RootWindow(display, screen_num), 
 949:                        NULL, NULL);
 950:   gc_drawingAreaTieCorrelation = XCreateGC(display, 
 951:                                  RootWindow(display, screen_num), 
 952:                                  NULL, NULL);
 953:   gc_drawingAreaSpliceCorrelation = XCreateGC(display, 
 954:                                     RootWindow(display, screen_num), 
 955:                                     NULL, NULL);
 956:   gc_drawingAreaAgeDepth = XCreateGC(display,
 957:                                     RootWindow(display, screen_num),
 958:                                     NULL, NULL);
 959:   gc_drawingAreaDepthOffset = XCreateGC(display,
 960:                                     RootWindow(display, screen_num),
 961:                                     NULL, NULL);
 962:   gc_drawingAreaSpliceToAge = XCreateGC(display,
 963:                                     RootWindow(display, screen_num),
 964:                                     NULL, NULL);
 965:   gc_drawingAreaTieToTimeSeriesCorr = XCreateGC(display,
 966:                                     RootWindow(display, screen_num),
 967:                                     NULL, NULL);
 968:   
 969:   /* and set their fonts
 970:   */
 971:   if(!(font = XLoadQueryFont(display, "-*-helvetica-*-r-*--12-*"))) {
 972:     (void)sprintf(buffer, "Query for composite and splice drawing area fonts failed.");
 973:     SpManageWarningBox(buffer);
 974:   }  
 975:   else {
 976:     XSetFont(display, gc_drawingAreaEdit, font->fid);
 977:     XSetFont(display, gc_drawingAreaView, font->fid);
 978:   }
 979:   if(!(font = XLoadQueryFont(display, "-*-helvetica-*-r-*--10-*"))) {
 980:     (void)sprintf(buffer, "Query for correlation and depth offset drawing area fonts failed."); 
 981:     SpManageWarningBox(buffer);
 982:   }  
 983:   else {
 984:     XSetFont(display, gc_drawingAreaTieCorrelation, font->fid);
 985:     XSetFont(display, gc_drawingAreaSpliceCorrelation, font->fid);
 986:     XSetFont(display, gc_drawingAreaDepthOffset, font->fid);
 987:     XSetFont(display, gc_drawingAreaAgeDepth, font->fid);
 988:     XSetFont(display, gc_drawingAreaSpliceToAge, font->fid);
 989:     XSetFont(display, gc_drawingAreaTieToTimeSeriesCorr, font->fid);
 990:   }
 991:   if(!(font = XLoadQueryFont(display, "-*-helvetica-*-r-*--8-*"))) {
 992:   }  
 993:   else {
 994:   }
 995: }
 996: 
 997: void SetInitialColors(dpy)
 998: Display *dpy;
 999: {
1000:   XmString xmstring;
1001:   XColor return_color, unused;
1002:   Pixel pixwhite, pixblack;
1003:   int GetColorSet();
1004: 
1005:   cmap = DefaultColormapOfScreen(XtScreen(drawingAreaEdit));
1006: 
1007:   /* get black and white pixel values for backup incase have a
1008:      failed named color allocation
1009:   */
1010:   pixblack = BlackPixelOfScreen(XtScreen(drawingAreaEdit));
1011:   pixwhite = WhitePixelOfScreen(XtScreen(drawingAreaEdit));
1012: 
1013:   /* get the colorset to use
1014:   */
1015:   GetColorSet();
1016: 
1017:   /* set the background color for the four drawing areas 
1018:   */
1019:   if(!XAllocNamedColor(dpy, cmap, color[BG_COLOR], &return_color, &unused)) {
1020:     (void)sprintf(buffer, "can not allocate named color.  %s", color[BG_COLOR]); 
1021:     SpManageWarningBox(buffer);
1022:     bgPixel = pixblack; 
1023:     xmstring = XmStringCreateSimple("black");
1024:     XtVaSetValues(pushButtonDrawingAreaColorBG, XmNlabelString, xmstring, NULL);
1025:     XmStringFree(xmstring);
1026:   }
1027:   else {
1028:     bgPixel = return_color.pixel;
1029:     xmstring = XmStringCreateSimple(color[BG_COLOR]);
1030:     XtVaSetValues(pushButtonDrawingAreaColorBG, XmNlabelString, xmstring, NULL);
1031:     XmStringFree(xmstring);
1032:   }
1033:   XtVaSetValues(pushButtonDrawingAreaColorBG, XmNbackground, bgPixel, NULL);
1034:   XtVaSetValues(drawingAreaEdit, XmNbackground, bgPixel, NULL); 
1035:   XtVaSetValues(drawingAreaView, XmNbackground, bgPixel, NULL);
1036:   XtVaSetValues(drawingAreaTieCorrelation, XmNbackground, bgPixel, NULL);
1037:   XtVaSetValues(drawingAreaCompCorrelation, XmNbackground, bgPixel, NULL);
1038:   XtVaSetValues(drawingAreaDepthOffset, XmNbackground, bgPixel, NULL);
1039:   XtVaSetValues(drawingAreaAgeDepth, XmNbackground, bgPixel, NULL);
1040:   XtVaSetValues(drawingAreaSpliceToAge, XmNbackground, bgPixel, NULL);
1041:   XtVaSetValues(drawingAreaTieToTimeSeriesCorr, XmNbackground, bgPixel, NULL);
1042: 
1043:   /* set the border color of labels for cursor location and ties to 
1044:      the drawing areas background color
1045:   */
1046:   XtVaSetValues(labelCursorLocation, XmNborderColor, bgPixel, NULL);
1047:   XtVaSetValues(labelDepthOffsetCursorLocation, XmNborderColor, bgPixel, NULL);
1048:   XtVaSetValues(labelSpliceCursorLocation, XmNborderColor, bgPixel, NULL);
1049:   XtVaSetValues(labelAgeDepthCursorLocation, XmNborderColor, bgPixel, NULL);
1050:   XtVaSetValues(labelSpliceToAgeCursorLocation, XmNborderColor, bgPixel, NULL);
1051:   XtVaSetValues(labelTie1ID, XmNborderColor, bgPixel, NULL);
1052:   XtVaSetValues(labelTie2ID, XmNborderColor, bgPixel, NULL);
1053:   XtVaSetValues(labelTie1var, XmNborderColor, bgPixel, NULL);
1054:   XtVaSetValues(labelTie2var, XmNborderColor, bgPixel, NULL);
1055:   XtVaSetValues(labelTie1sbd, XmNborderColor, bgPixel, NULL);
1056:   XtVaSetValues(labelTie2sbd, XmNborderColor, bgPixel, NULL);
1057:   XtVaSetValues(labelSpliceTie1ID, XmNborderColor, bgPixel, NULL); 
1058:   XtVaSetValues(labelSpliceTie2ID, XmNborderColor, bgPixel, NULL);
1059:   XtVaSetValues(labelSpliceTie1var, XmNborderColor, bgPixel, NULL); 
1060:   XtVaSetValues(labelSpliceTie2var, XmNborderColor, bgPixel, NULL); 
1061:   XtVaSetValues(labelSpliceTie1sbd, XmNborderColor, bgPixel, NULL); 
1062:   XtVaSetValues(labelSpliceTie2sbd, XmNborderColor, bgPixel, NULL);
1063:   XtVaSetValues(labelSpliceDifferenceInValue, XmNborderColor, bgPixel, NULL);
1064: 
1065: 
1066:   /* set the row-column and label background color to drawing area color
1067:   */
1068:   XtVaSetValues(rowColumnColorCompositeAndSplice, XmNbackground, bgPixel, NULL);
1069:   XtVaSetValues(rowColumnColorCorrelation, XmNbackground, bgPixel, NULL);
1070:   XtVaSetValues(rowColumnColorDepthOffset, XmNbackground, bgPixel, NULL);
1071:   XtVaSetValues(rowColumnColorDrawingAreas, XmNbackground, bgPixel, NULL);
1072:   XtVaSetValues(rowColumnColorAgeDepth, XmNbackground, bgPixel, NULL);
1073:   XtVaSetValues(rowColumnColorSpliceToAge, XmNbackground, bgPixel, NULL);
1074:  
1075:   XtVaSetValues(labelDrawingAreaColorBG, XmNbackground, bgPixel, NULL);
1076:   XtVaSetValues(labelDrawingAreaColorLabels, XmNbackground, bgPixel, NULL);
1077:   XtVaSetValues(labelColorCoreRelated, XmNbackground, bgPixel, NULL);
1078:   XtVaSetValues(labelColorCorembsf, XmNbackground, bgPixel, NULL);
1079:   XtVaSetValues(labelColorCoremcd, XmNbackground, bgPixel, NULL);
1080:   XtVaSetValues(labelColorSmooth, XmNbackground, bgPixel, NULL);
1081:   XtVaSetValues(labelColorSplice, XmNbackground, bgPixel, NULL);
1082:   XtVaSetValues(labelColorSpliceLocation, XmNbackground, bgPixel, NULL);
1083:   XtVaSetValues(labelColorTieRelated, XmNbackground, bgPixel, NULL);
1084:   XtVaSetValues(labelColorTiePtFixed, XmNbackground, bgPixel, NULL);
1085:   XtVaSetValues(labelColorTiePtShift, XmNbackground, bgPixel, NULL);
1086:   XtVaSetValues(labelColorTieLine, XmNbackground, bgPixel, NULL);
1087:   XtVaSetValues(labelColorOverlayInCorr, XmNbackground, bgPixel, NULL);
1088:   XtVaSetValues(labelColorOverlayOutCorr, XmNbackground, bgPixel, NULL);
1089:   XtVaSetValues(labelColorStrat, XmNbackground, bgPixel, NULL);
1090:   XtVaSetValues(labelColorPaleomag, XmNbackground, bgPixel, NULL);
1091:   XtVaSetValues(labelColorDiatom, XmNbackground, bgPixel, NULL);
1092:   XtVaSetValues(labelColorRad, XmNbackground, bgPixel, NULL);
1093:   XtVaSetValues(labelColorForam, XmNbackground, bgPixel, NULL);
1094:   XtVaSetValues(labelColorNanno, XmNbackground, bgPixel, NULL);
1095:   XtVaSetValues(labelColorCorrCoef, XmNbackground, bgPixel, NULL);
1096:   XtVaSetValues(labelColorBestCorr, XmNbackground, bgPixel, NULL);
1097:   XtVaSetValues(labelColorDepthOffsetLine, XmNbackground, bgPixel, NULL);
1098:   XtVaSetValues(labelColorDepthOffsetHole1, XmNbackground, bgPixel, NULL);
1099:   XtVaSetValues(labelColorDepthOffsetHole2, XmNbackground, bgPixel, NULL);
1100:   XtVaSetValues(labelColorDepthOffsetHole3, XmNbackground, bgPixel, NULL);
1101:   XtVaSetValues(labelColorDepthOffsetHole4, XmNbackground, bgPixel, NULL);
1102:   XtVaSetValues(labelColorDepthOffsetHole5, XmNbackground, bgPixel, NULL);
1103:   XtVaSetValues(labelColorDepthOffsetHole6, XmNbackground, bgPixel, NULL);
1104:   XtVaSetValues(labelColorDepthOffsetHole7, XmNbackground, bgPixel, NULL);
1105:   XtVaSetValues(labelColorDepthOffsetHole8, XmNbackground, bgPixel, NULL);
1106:   XtVaSetValues(labelColorDepthOffsetHole9, XmNbackground, bgPixel, NULL);
1107:   XtVaSetValues(labelColorDepthOffsetHole10, XmNbackground, bgPixel, NULL);
1108:   XtVaSetValues(labelColorDepthOffsetHole11, XmNbackground, bgPixel, NULL);
1109:   XtVaSetValues(labelColorAgeDepthHandPick, XmNbackground, bgPixel, NULL);
1110:   XtVaSetValues(labelColorAgeDepthLine, XmNbackground, bgPixel, NULL);
1111:   XtVaSetValues(labelColorSedRate, XmNbackground, bgPixel, NULL);
1112:   XtVaSetValues(labelColorTimeSeries, XmNbackground, bgPixel, NULL);
1113:   XtVaSetValues(labelColorDatumLocation, XmNbackground, bgPixel, NULL);
1114: 
1115:   /* if no foreground and or background color were read on command line args
1116:      set the colors for hsplicer foreground and background to the drawing
1117:      args background and labels 
1118:   */
1119:   if(prgfg == NO || prgbg == NO) {
1120:     (void)sprintf(prgfgcolor, "");
1121:     (void)sprintf(prgfgcolor, color[LABEL_COLOR]);
1122:     (void)sprintf(prgbgcolor, "");
1123:     (void)sprintf(prgbgcolor, color[BG_COLOR]);
1124:   }
1125: 
1126:   /* set all the foreground colors
1127:   */
1128: 
1129:   /* the labels for all four drawing areas
1130:   */
1131:   if(!XAllocNamedColor(dpy, cmap, color[LABEL_COLOR], &return_color, &unused)) {
1132:     (void)sprintf(buffer, "can not allocate named color.  %s", color[LABEL_COLOR]);
1133:     SpManageWarningBox(buffer);
1134:     fgPixel[LABEL_COLOR] = pixwhite;
1135:     xmstring = XmStringCreateSimple("white");
1136:     XtVaSetValues(pushButtonDrawingAreaColorLabels, XmNlabelString, xmstring, NULL);
1137:     XmStringFree(xmstring);
1138:   }
1139:   else { 
1140:     fgPixel[LABEL_COLOR] = return_color.pixel;
1141:     xmstring = XmStringCreateSimple(color[LABEL_COLOR]);
1142:     XtVaSetValues(pushButtonDrawingAreaColorLabels, XmNlabelString, xmstring, NULL);
1143:     XmStringFree(xmstring);
1144:   }
1145:   XtVaSetValues(pushButtonDrawingAreaColorLabels, XmNbackground, fgPixel[LABEL_COLOR], NULL);
1146:  
1147:   /* set the row-column label foreground colors to the label color
1148:   */
1149:   XtVaSetValues(labelDrawingAreaColorBG, XmNforeground, fgPixel[LABEL_COLOR], NULL); 
1150:   XtVaSetValues(labelDrawingAreaColorLabels, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1151:   XtVaSetValues(labelColorCoreRelated, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1152:   XtVaSetValues(labelColorCorembsf, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1153:   XtVaSetValues(labelColorCoremcd, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1154:   XtVaSetValues(labelColorSmooth, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1155:   XtVaSetValues(labelColorSplice, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1156:   XtVaSetValues(labelColorSpliceLocation, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1157:   XtVaSetValues(labelColorTieRelated, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1158:   XtVaSetValues(labelColorTiePtFixed, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1159:   XtVaSetValues(labelColorTiePtShift, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1160:   XtVaSetValues(labelColorTieLine, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1161:   XtVaSetValues(labelColorOverlayInCorr, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1162:   XtVaSetValues(labelColorOverlayOutCorr, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1163:   XtVaSetValues(labelColorStrat, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1164:   XtVaSetValues(labelColorPaleomag, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1165:   XtVaSetValues(labelColorDiatom, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1166:   XtVaSetValues(labelColorRad, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1167:   XtVaSetValues(labelColorForam, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1168:   XtVaSetValues(labelColorNanno, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1169:   XtVaSetValues(labelColorCorrCoef, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1170:   XtVaSetValues(labelColorBestCorr, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1171:   XtVaSetValues(labelColorDepthOffsetLine, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1172:   XtVaSetValues(labelColorDepthOffsetHole1, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1173:   XtVaSetValues(labelColorDepthOffsetHole2, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1174:   XtVaSetValues(labelColorDepthOffsetHole3, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1175:   XtVaSetValues(labelColorDepthOffsetHole4, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1176:   XtVaSetValues(labelColorDepthOffsetHole5, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1177:   XtVaSetValues(labelColorDepthOffsetHole6, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1178:   XtVaSetValues(labelColorDepthOffsetHole7, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1179:   XtVaSetValues(labelColorDepthOffsetHole8, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1180:   XtVaSetValues(labelColorDepthOffsetHole9, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1181:   XtVaSetValues(labelColorDepthOffsetHole10, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1182:   XtVaSetValues(labelColorDepthOffsetHole11, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1183:   XtVaSetValues(labelColorAgeDepthHandPick, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1184:   XtVaSetValues(labelColorAgeDepthLine, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1185:   XtVaSetValues(labelColorSedRate, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1186:   XtVaSetValues(labelColorTimeSeries, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1187:   XtVaSetValues(labelColorDatumLocation, XmNforeground, fgPixel[LABEL_COLOR], NULL);
1188:  
1189:   /* the original unadjusted ODP sb depth 
1190:   */
1191:   if(!XAllocNamedColor(dpy, cmap, color[MBSF_COLOR], &return_color, &unused)) {
1192:     (void)sprintf(buffer, "can not allocate named color.  %s", color[MBSF_COLOR]);
1193:     SpManageWarningBox(buffer);
1194:     fgPixel[MBSF_COLOR] = pixwhite;
1195:     xmstring = XmStringCreateSimple("white");
1196:     XtVaSetValues(pushButtonColorCorembsf, XmNlabelString, xmstring, NULL);
1197:     XmStringFree(xmstring);
1198:   }
1199:   else {
1200:     fgPixel[MBSF_COLOR] = return_color.pixel;
1201:     xmstring = XmStringCreateSimple(color[MBSF_COLOR]);
1202:     XtVaSetValues(pushButtonColorCorembsf, XmNlabelString, xmstring, NULL);
1203:     XmStringFree(xmstring);
1204:   }
1205:   XtVaSetValues(pushButtonColorCorembsf, XmNbackground, fgPixel[MBSF_COLOR], NULL);
1206: 
1207:   /* the smoothed data
1208:   */
1209:   if(!XAllocNamedColor(dpy, cmap, color[SMOOTH_COLOR], &return_color, &unused)) {
1210:     (void)sprintf(buffer, "can not allocate named color.  %s", color[SMOOTH_COLOR]);
1211:     SpManageWarningBox(buffer);
1212:     fgPixel[SMOOTH_COLOR] = pixwhite;
1213:     xmstring = XmStringCreateSimple("white");
1214:     XtVaSetValues(pushButtonColorSmooth, XmNlabelString, xmstring, NULL);
1215:     XmStringFree(xmstring);
1216:   }
1217:   else {
1218:     fgPixel[SMOOTH_COLOR] = return_color.pixel;
1219:     xmstring = XmStringCreateSimple(color[SMOOTH_COLOR]); 
1220:     XtVaSetValues(pushButtonColorSmooth, XmNlabelString, xmstring, NULL); 
1221:     XmStringFree(xmstring);
1222:   }
1223:   XtVaSetValues(pushButtonColorSmooth, XmNbackground, fgPixel[SMOOTH_COLOR], NULL);
1224: 
1225:   /* composite and splice tie lines
1226:   */
1227:   if(!XAllocNamedColor(dpy, cmap, color[TIELINE_COLOR], &return_color, &unused)) { 
1228:     (void)sprintf(buffer, "can not allocate named color.  %s", color[TIELINE_COLOR]); 
1229:     SpManageWarningBox(buffer);
1230:     fgPixel[TIELINE_COLOR] = pixwhite; 
1231:     xmstring = XmStringCreateSimple("white"); 
1232:     XtVaSetValues(pushButtonColorTieLine, XmNlabelString, xmstring, NULL);
1233:     XmStringFree(xmstring);
1234:   } 
1235:   else {
1236:     fgPixel[TIELINE_COLOR] = return_color.pixel; 
1237:     xmstring = XmStringCreateSimple(color[TIELINE_COLOR]); 
1238:     XtVaSetValues(pushButtonColorTieLine, XmNlabelString, xmstring, NULL); 
1239:     XmStringFree(xmstring);
1240:   }
1241:   XtVaSetValues(pushButtonColorTieLine, XmNbackground, fgPixel[TIELINE_COLOR], NULL);
1242:   
1243:   /* the middle button tie point 1 (fixed; it stays put)
1244:      let this convention hold for splice as well
1245:   */
1246:   if(!XAllocNamedColor(dpy, cmap, color[TIEPTFIXED_COLOR], &return_color, &unused)) {
1247:     (void)sprintf(buffer, "can not allocate named color.  %s", color[TIEPTFIXED_COLOR]);
1248:     SpManageWarningBox(buffer);
1249:     fgPixel[TIEPTFIXED_COLOR] = pixwhite;
1250:     xmstring = XmStringCreateSimple("white"); 
1251:     XtVaSetValues(pushButtonColorTiePtFixed, XmNlabelString, xmstring, NULL);
1252:     XmStringFree(xmstring);
1253:   }
1254:   else {
1255:     fgPixel[TIEPTFIXED_COLOR] = return_color.pixel;
1256:     xmstring = XmStringCreateSimple(color[TIEPTFIXED_COLOR]); 
1257:     XtVaSetValues(pushButtonColorTiePtFixed, XmNlabelString, xmstring, NULL); 
1258:     XmStringFree(xmstring);
1259:   }
1260:   XtVaSetValues(pushButtonColorTiePtFixed, XmNbackground, fgPixel[TIEPTFIXED_COLOR], NULL);
1261: 
1262:   /* the right button tie point 2 (shift; it moves)
1263:      let this convention hold for splice as well
1264:   */
1265:   if(!XAllocNamedColor(dpy, cmap, color[TIEPTSHIFT_COLOR], &return_color, &unused)) {
1266:     (void)sprintf(buffer, "can not allocate named color.  %s", color[TIEPTSHIFT_COLOR]);
1267:     SpManageWarningBox(buffer);
1268:     fgPixel[TIEPTSHIFT_COLOR] = pixwhite;
1269:     xmstring = XmStringCreateSimple("white"); 
1270:     XtVaSetValues(pushButtonColorTiePtShift, XmNlabelString, xmstring, NULL);
1271:     XmStringFree(xmstring);
1272:   }
1273:   else {
1274:     fgPixel[TIEPTSHIFT_COLOR] = return_color.pixel;
1275:     xmstring = XmStringCreateSimple(color[TIEPTSHIFT_COLOR]); 
1276:     XtVaSetValues(pushButtonColorTiePtShift, XmNlabelString, xmstring, NULL); 
1277:     XmStringFree(xmstring);
1278:   }
1279:   XtVaSetValues(pushButtonColorTiePtShift, XmNbackground, fgPixel[TIEPTSHIFT_COLOR], NULL);
1280:   
1281:   /* the composite and splice core overlays 
1282:   */
1283:   /* part of core used in correlation
1284:   */
1285:   if(!XAllocNamedColor(dpy, cmap, color[OVERLAYINCORR_COLOR], &return_color, &unused)) { 
1286:     (void)sprintf(buffer, "can not allocate named color.  %s", color[OVERLAYINCORR_COLOR]); 
1287:     SpManageWarningBox(buffer);
1288:     fgPixel[OVERLAYINCORR_COLOR] = pixwhite;
1289:     xmstring = XmStringCreateSimple("white"); 
1290:     XtVaSetValues(pushButtonColorOverlayInCorr, XmNlabelString, xmstring, NULL);
1291:     XmStringFree(xmstring);
1292:   } 
1293:   else {
1294:     fgPixel[OVERLAYINCORR_COLOR] = return_color.pixel; 
1295:     xmstring = XmStringCreateSimple(color[OVERLAYINCORR_COLOR]); 
1296:     XtVaSetValues(pushButtonColorOverlayInCorr, XmNlabelString, xmstring, NULL); 
1297:     XmStringFree(xmstring);
1298:   }
1299:   XtVaSetValues(pushButtonColorOverlayInCorr, XmNbackground, fgPixel[OVERLAYINCORR_COLOR], NULL);
1300:   /* part of core not used in correlation
1301:   */
1302:   if(!XAllocNamedColor(dpy, cmap, color[OVERLAYOUTCORR_COLOR], &return_color, &unused)) {
1303:     (void)sprintf(buffer, "can not allocate named color.  %s", color[OVERLAYOUTCORR_COLOR]);
1304:     SpManageWarningBox(buffer);
1305:     fgPixel[OVERLAYOUTCORR_COLOR]  = pixwhite;
1306:     xmstring = XmStringCreateSimple("white"); 
1307:     XtVaSetValues(pushButtonColorOverlayOutCorr, XmNlabelString, xmstring, NULL);
1308:     XmStringFree(xmstring);
1309:   } 
1310:   else {
1311:     fgPixel[OVERLAYOUTCORR_COLOR]  = return_color.pixel;
1312:     xmstring = XmStringCreateSimple(color[OVERLAYOUTCORR_COLOR]); 
1313:     XtVaSetValues(pushButtonColorOverlayOutCorr, XmNlabelString, xmstring, NULL); 
1314:     XmStringFree(xmstring);
1315:   }
1316:   XtVaSetValues(pushButtonColorOverlayOutCorr, XmNbackground, fgPixel[OVERLAYOUTCORR_COLOR], NULL);
1317: 
1318:   /* the depth adjusted(shifted) core 
1319:   */
1320:   if(!XAllocNamedColor(dpy, cmap, color[MCD_COLOR], &return_color, &unused)) {
1321:     (void)sprintf(buffer, "can not allocate named color.  %s", color[MCD_COLOR]);
1322:     SpManageWarningBox(buffer);
1323:     fgPixel[MCD_COLOR]  = pixwhite;
1324:     xmstring = XmStringCreateSimple("white"); 
1325:     XtVaSetValues(pushButtonColorCoremcd, XmNlabelString, xmstring, NULL);
1326:     XmStringFree(xmstring);
1327:   }
1328:   else {
1329:     fgPixel[MCD_COLOR] = return_color.pixel;
1330:     xmstring = XmStringCreateSimple(color[MCD_COLOR]); 
1331:     XtVaSetValues(pushButtonColorCoremcd, XmNlabelString, xmstring, NULL); 
1332:     XmStringFree(xmstring);
1333:   }
1334:   XtVaSetValues(pushButtonColorCoremcd, XmNbackground, fgPixel[MCD_COLOR], NULL);
1335: 
1336: 
1337:   /* the splice composite 
1338:   */
1339:   if(!XAllocNamedColor(dpy, cmap, color[SPLICE_COLOR], &return_color, &unused)) {
1340:     (void)sprintf(buffer, "can not allocate named color.  %s", color[SPLICE_COLOR]);
1341:     SpManageWarningBox(buffer);
1342:     fgPixel[SPLICE_COLOR]  = pixwhite;
1343:     xmstring = XmStringCreateSimple("white"); 
1344:     XtVaSetValues(pushButtonColorSplice, XmNlabelString, xmstring, NULL);
1345:     XmStringFree(xmstring);
1346:   } 
1347:   else {
1348:     fgPixel[SPLICE_COLOR]  = return_color.pixel;
1349:     xmstring = XmStringCreateSimple(color[SPLICE_COLOR]); 
1350:     XtVaSetValues(pushButtonColorSplice, XmNlabelString, xmstring, NULL); 
1351:     XmStringFree(xmstring);
1352:   }
1353:   XtVaSetValues(pushButtonColorSplice, XmNbackground, fgPixel[SPLICE_COLOR], NULL);
1354: 
1355:   /* the lines between spliced cores
1356:   */
1357:   if(!XAllocNamedColor(dpy, cmap, color[SPLICELOCATION_COLOR], &return_color, &unused)) {
1358:     (void)sprintf(buffer, "can not allocate named color.  %s", color[SPLICELOCATION_COLOR]);
1359:     SpManageWarningBox(buffer);
1360:     fgPixel[SPLICELOCATION_COLOR] = pixwhite;
1361:     xmstring = XmStringCreateSimple("white"); 
1362:     XtVaSetValues(pushButtonColorSpliceLocation, XmNlabelString, xmstring, NULL);
1363:     XmStringFree(xmstring);
1364:   }
1365:   else {
1366:     fgPixel[SPLICELOCATION_COLOR] = return_color.pixel;
1367:     xmstring = XmStringCreateSimple(color[SPLICELOCATION_COLOR]); 
1368:     XtVaSetValues(pushButtonColorSpliceLocation, XmNlabelString, xmstring, NULL); 
1369:     XmStringFree(xmstring);
1370:   }
1371:   XtVaSetValues(pushButtonColorSpliceLocation, XmNbackground, fgPixel[SPLICELOCATION_COLOR], NULL);
1372: 
1373:   /* the composite and splice correlation coef
1374:   */
1375:   if(!XAllocNamedColor(dpy, cmap, color[CORRCOEF_COLOR], &return_color, &unused)) {  
1376:     (void)sprintf(buffer, "can not allocate named color.  %s", color[CORRCOEF_COLOR]); 
1377:     SpManageWarningBox(buffer);
1378:     fgPixel[CORRCOEF_COLOR] = pixwhite;
1379:     xmstring = XmStringCreateSimple("white"); 
1380:     XtVaSetValues(pushButtonColorCorrCoef, XmNlabelString, xmstring, NULL);
1381:     XmStringFree(xmstring);
1382:   }  
1383:   else {
1384:     fgPixel[CORRCOEF_COLOR] = return_color.pixel;
1385:     xmstring = XmStringCreateSimple(color[CORRCOEF_COLOR]); 
1386:     XtVaSetValues(pushButtonColorCorrCoef, XmNlabelString, xmstring, NULL); 
1387:     XmStringFree(xmstring);
1388:   }
1389:   XtVaSetValues(pushButtonColorCorrCoef, XmNbackground, fgPixel[CORRCOEF_COLOR], NULL);
1390: 
1391:   /* the line on axis indicating location of best corr. coef.
1392:   */
1393:   if(!XAllocNamedColor(dpy, cmap, color[BESTCORR_COLOR], &return_color, &unused)) {
1394:     (void)sprintf(buffer, "can not allocate named color.  %s", color[BESTCORR_COLOR]);   
1395:     SpManageWarningBox(buffer);
1396:     fgPixel[BESTCORR_COLOR] = pixwhite;
1397:     xmstring = XmStringCreateSimple("white"); 
1398:     XtVaSetValues(pushButtonColorBestCorr, XmNlabelString, xmstring, NULL);
1399:     XmStringFree(xmstring);
1400:   }  
1401:   else { 
1402:     fgPixel[BESTCORR_COLOR] = return_color.pixel;
1403:     xmstring = XmStringCreateSimple(color[BESTCORR_COLOR]); 
1404:     XtVaSetValues(pushButtonColorBestCorr, XmNlabelString, xmstring, NULL); 
1405:     XmStringFree(xmstring);
1406:   } 
1407:   XtVaSetValues(pushButtonColorBestCorr, XmNbackground, fgPixel[BESTCORR_COLOR], NULL);
1408: 
1409:   /* stratigraphy colors;
1410:   */
1411:   if(!XAllocNamedColor(dpy, cmap, color[PALEOMAG_COLOR], &return_color, &unused)) {
1412:     (void)sprintf(buffer, "can not allocate named color.  %s", color[PALEOMAG_COLOR]);
1413:     SpManageWarningBox(buffer);
1414:     fgPixel[PALEOMAG_COLOR] = pixwhite;
1415:     xmstring = XmStringCreateSimple("white"); 
1416:     XtVaSetValues(pushButtonColorPaleomag, XmNlabelString, xmstring, NULL);
1417:     XmStringFree(xmstring);
1418:   }
1419:   else {
1420:     fgPixel[PALEOMAG_COLOR] = return_color.pixel;
1421:     xmstring = XmStringCreateSimple(color[PALEOMAG_COLOR]); 
1422:     XtVaSetValues(pushButtonColorPaleomag, XmNlabelString, xmstring, NULL); 
1423:     XmStringFree(xmstring);
1424:   }
1425:   XtVaSetValues(pushButtonColorPaleomag, XmNbackground, fgPixel[PALEOMAG_COLOR], NULL);
1426: 
1427:   if(!XAllocNamedColor(dpy, cmap, color[DIATOM_COLOR], &return_color, &unused)) {
1428:     (void)sprintf(buffer, "can not allocate named color %s.",  color[DIATOM_COLOR]);
1429:     SpManageWarningBox(buffer);
1430:     fgPixel[DIATOM_COLOR] = pixwhite;
1431:     xmstring = XmStringCreateSimple("white"); 
1432:     XtVaSetValues(pushButtonColorDiatom, XmNlabelString, xmstring, NULL);
1433:     XmStringFree(xmstring);
1434:   }
1435:   else {
1436:     fgPixel[DIATOM_COLOR] = return_color.pixel;
1437:     xmstring = XmStringCreateSimple(color[DIATOM_COLOR]); 
1438:     XtVaSetValues(pushButtonColorDiatom, XmNlabelString, xmstring, NULL); 
1439:     XmStringFree(xmstring);
1440:   }
1441:   XtVaSetValues(pushButtonColorDiatom, XmNbackground, fgPixel[DIATOM_COLOR], NULL);
1442: 
1443:   if(!XAllocNamedColor(dpy, cmap, color[RAD_COLOR], &return_color, &unused)) { 
1444:     (void)sprintf(buffer, "can not allocate named color.  %s", color[RAD_COLOR]); 
1445:     SpManageWarningBox(buffer);
1446:     fgPixel[RAD_COLOR] = pixwhite;
1447:     xmstring = XmStringCreateSimple("white"); 
1448:     XtVaSetValues(pushButtonColorRad, XmNlabelString, xmstring, NULL);
1449:     XmStringFree(xmstring);
1450:   } 
1451:   else {
1452:     fgPixel[RAD_COLOR] = return_color.pixel;
1453:     xmstring = XmStringCreateSimple(color[RAD_COLOR]); 
1454:     XtVaSetValues(pushButtonColorRad, XmNlabelString, xmstring, NULL); 
1455:     XmStringFree(xmstring);
1456:   }
1457:   XtVaSetValues(pushButtonColorRad, XmNbackground, fgPixel[RAD_COLOR], NULL);
1458: 
1459:   if(!XAllocNamedColor(dpy, cmap, color[FORAM_COLOR], &return_color, &unused)) { 
1460:     (void)sprintf(buffer, "can not allocate named color.  %s", color[FORAM_COLOR]); 
1461:     SpManageWarningBox(buffer);
1462:     fgPixel[FORAM_COLOR] = pixwhite;
1463:     xmstring = XmStringCreateSimple("white"); 
1464:     XtVaSetValues(pushButtonColorForam, XmNlabelString, xmstring, NULL);
1465:     XmStringFree(xmstring);
1466:   } 
1467:   else {
1468:     fgPixel[FORAM_COLOR] = return_color.pixel;
1469:     xmstring = XmStringCreateSimple(color[FORAM_COLOR]); 
1470:     XtVaSetValues(pushButtonColorForam, XmNlabelString, xmstring, NULL); 
1471:     XmStringFree(xmstring);
1472:   }
1473:   XtVaSetValues(pushButtonColorForam, XmNbackground, fgPixel[FORAM_COLOR], NULL);
1474:   
1475:   if(!XAllocNamedColor(dpy, cmap, color[NANNO_COLOR], &return_color, &unused)) { 
1476:     (void)sprintf(buffer, "can not allocate named color.  %s", color[NANNO_COLOR]); 
1477:     SpManageWarningBox(buffer);
1478:     fgPixel[NANNO_COLOR] = pixwhite;
1479:     xmstring = XmStringCreateSimple("white"); 
1480:     XtVaSetValues(pushButtonColorNanno, XmNlabelString, xmstring, NULL);
1481:     XmStringFree(xmstring);
1482:   } 
1483:   else {
1484:     fgPixel[NANNO_COLOR] = return_color.pixel;
1485:     xmstring = XmStringCreateSimple(color[NANNO_COLOR]); 
1486:     XtVaSetValues(pushButtonColorNanno, XmNlabelString, xmstring, NULL); 
1487:     XmStringFree(xmstring);
1488:   }
1489:   XtVaSetValues(pushButtonColorNanno, XmNbackground, fgPixel[NANNO_COLOR], NULL);
1490: 
1491:   /* view depth offset colors
1492:   */
1493:   if(!XAllocNamedColor(dpy, cmap, color[DEPOFFLINE_COLOR], &return_color, &unused)) {
1494:     (void)sprintf(buffer, "can not allocate named color.  %s", color[DEPOFFLINE_COLOR]);
1495:     SpManageWarningBox(buffer);
1496:     fgPixel[DEPOFFLINE_COLOR] = pixwhite;
1497:     xmstring = XmStringCreateSimple("white"); 
1498:     XtVaSetValues(pushButtonColorDepthOffsetLine, XmNlabelString, xmstring, NULL);
1499:     XmStringFree(xmstring);
1500:   }
1501:   else {
1502:     fgPixel[DEPOFFLINE_COLOR] = return_color.pixel;
1503:     xmstring = XmStringCreateSimple(color[DEPOFFLINE_COLOR]); 
1504:     XtVaSetValues(pushButtonColorDepthOffsetLine, XmNlabelString, xmstring, NULL); 
1505:     XmStringFree(xmstring);
1506:   }
1507:   XtVaSetValues(pushButtonColorDepthOffsetLine, XmNbackground, fgPixel[DEPOFFLINE_COLOR], NULL);
1508:   
1509:   if(!XAllocNamedColor(dpy, cmap, color[DEPOFFHOLE1_COLOR], &return_color, &unused)) {
1510:     (void)sprintf(buffer, "can not allocate named color.  %s", color[DEPOFFHOLE1_COLOR]);
1511:     SpManageWarningBox(buffer);
1512:     fgPixel[DEPOFFHOLE1_COLOR] = pixwhite;
1513:     xmstring = XmStringCreateSimple("white"); 
1514:     XtVaSetValues(pushButtonColorDepthOffsetHole1, XmNlabelString, xmstring, NULL);
1515:     XmStringFree(xmstring);
1516:   }
1517:   else { 
1518:     fgPixel[DEPOFFHOLE1_COLOR] = return_color.pixel;
1519:     xmstring = XmStringCreateSimple(color[DEPOFFHOLE1_COLOR]); 
1520:     XtVaSetValues(pushButtonColorDepthOffsetHole1, XmNlabelString, xmstring, NULL); 
1521:     XmStringFree(xmstring);
1522:   }
1523:   XtVaSetValues(pushButtonColorDepthOffsetHole1, XmNbackground, fgPixel[DEPOFFHOLE1_COLOR], NULL);
1524: 
1525:   if(!XAllocNamedColor(dpy, cmap, color[DEPOFFHOLE2_COLOR], &return_color, &unused)) { 
1526:     (void)sprintf(buffer, "can not allocate named color.  %s", color[DEPOFFHOLE2_COLOR]); 
1527:     SpManageWarningBox(buffer); 
1528:     fgPixel[DEPOFFHOLE2_COLOR] = pixwhite; 
1529:     xmstring = XmStringCreateSimple("white");  
1530:     XtVaSetValues(pushButtonColorDepthOffsetHole2, XmNlabelString, xmstring, NULL);
1531:     XmStringFree(xmstring);
1532:   } 
1533:   else {  
1534:     fgPixel[DEPOFFHOLE2_COLOR] = return_color.pixel; 
1535:     xmstring = XmStringCreateSimple(color[DEPOFFHOLE2_COLOR]);  
1536:     XtVaSetValues(pushButtonColorDepthOffsetHole2, XmNlabelString, xmstring, NULL);  
1537:     XmStringFree(xmstring);
1538:   }
1539:   XtVaSetValues(pushButtonColorDepthOffsetHole2, XmNbackground, fgPixel[DEPOFFHOLE2_COLOR], NULL);
1540: 
1541:   if(!XAllocNamedColor(dpy, cmap, color[DEPOFFHOLE3_COLOR], &return_color, &unused)) { 
1542:     (void)sprintf(buffer, "can not allocate named color.  %s", color[DEPOFFHOLE3_COLOR]); 
1543:     SpManageWarningBox(buffer); 
1544:     fgPixel[DEPOFFHOLE3_COLOR] = pixwhite; 
1545:     xmstring = XmStringCreateSimple("white");  
1546:     XtVaSetValues(pushButtonColorDepthOffsetHole3, XmNlabelString, xmstring, NULL);
1547:     XmStringFree(xmstring);
1548:   } 
1549:   else {  
1550:     fgPixel[DEPOFFHOLE3_COLOR] = return_color.pixel; 
1551:     xmstring = XmStringCreateSimple(color[DEPOFFHOLE3_COLOR]);  
1552:     XtVaSetValues(pushButtonColorDepthOffsetHole3, XmNlabelString, xmstring, NULL);  
1553:     XmStringFree(xmstring);
1554:   }
1555:   XtVaSetValues(pushButtonColorDepthOffsetHole3, XmNbackground, fgPixel[DEPOFFHOLE3_COLOR], NULL);
1556: 
1557:   if(!XAllocNamedColor(dpy, cmap, color[DEPOFFHOLE4_COLOR], &return_color, &unused)) { 
1558:     (void)sprintf(buffer, "can not allocate named color.  %s", color[DEPOFFHOLE4_COLOR]); 
1559:     SpManageWarningBox(buffer); 
1560:     fgPixel[DEPOFFHOLE4_COLOR] = pixwhite; 
1561:     xmstring = XmStringCreateSimple("white");  
1562:     XtVaSetValues(pushButtonColorDepthOffsetHole4, XmNlabelString, xmstring, NULL);
1563:     XmStringFree(xmstring);
1564:   } 
1565:   else {  
1566:     fgPixel[DEPOFFHOLE4_COLOR] = return_color.pixel; 
1567:     xmstring = XmStringCreateSimple(color[DEPOFFHOLE4_COLOR]);  
1568:     XtVaSetValues(pushButtonColorDepthOffsetHole4, XmNlabelString, xmstring, NULL);  
1569:     XmStringFree(xmstring);
1570:   }
1571:   XtVaSetValues(pushButtonColorDepthOffsetHole4, XmNbackground, fgPixel[DEPOFFHOLE4_COLOR], NULL);
1572: 
1573:   if(!XAllocNamedColor(dpy, cmap, color[DEPOFFHOLE5_COLOR], &return_color, &unused)) { 
1574:     (void)sprintf(buffer, "can not allocate named color.  %s", color[DEPOFFHOLE5_COLOR]); 
1575:     SpManageWarningBox(buffer); 
1576:     fgPixel[DEPOFFHOLE5_COLOR] = pixwhite; 
1577:     xmstring = XmStringCreateSimple("white");  
1578:     XtVaSetValues(pushButtonColorDepthOffsetHole5, XmNlabelString, xmstring, NULL);
1579:     XmStringFree(xmstring);
1580:   } 
1581:   else {  
1582:     fgPixel[DEPOFFHOLE5_COLOR] = return_color.pixel; 
1583:     xmstring = XmStringCreateSimple(color[DEPOFFHOLE5_COLOR]);  
1584:     XtVaSetValues(pushButtonColorDepthOffsetHole5, XmNlabelString, xmstring, NULL);  
1585:     XmStringFree(xmstring);
1586:   }
1587:   XtVaSetValues(pushButtonColorDepthOffsetHole5, XmNbackground, fgPixel[DEPOFFHOLE5_COLOR], NULL);
1588: 
1589:   if(!XAllocNamedColor(dpy, cmap, color[DEPOFFHOLE6_COLOR], &return_color, &unused)) {
1590:     (void)sprintf(buffer, "can not allocate named color.  %s", color[DEPOFFHOLE6_COLOR]);
1591:     SpManageWarningBox(buffer);
1592:     fgPixel[DEPOFFHOLE6_COLOR] = pixwhite;
1593:     xmstring = XmStringCreateSimple("white");  
1594:     XtVaSetValues(pushButtonColorDepthOffsetHole6, XmNlabelString, xmstring, NULL);
1595:     XmStringFree(xmstring);
1596:   }
1597:   else { 
1598:     fgPixel[DEPOFFHOLE6_COLOR] = return_color.pixel;
1599:     xmstring = XmStringCreateSimple(color[DEPOFFHOLE6_COLOR]);  
1600:     XtVaSetValues(pushButtonColorDepthOffsetHole6, XmNlabelString, xmstring, NULL);  
1601:     XmStringFree(xmstring);
1602:   }
1603:   XtVaSetValues(pushButtonColorDepthOffsetHole6, XmNbackground, fgPixel[DEPOFFHOLE6_COLOR], NULL);
1604:  
1605:   if(!XAllocNamedColor(dpy, cmap, color[DEPOFFHOLE7_COLOR], &return_color, &unused)) {
1606:     (void)sprintf(buffer, "can not allocate named color.  %s", color[DEPOFFHOLE7_COLOR]);
1607:     SpManageWarningBox(buffer);
1608:     fgPixel[DEPOFFHOLE7_COLOR] = pixwhite;
1609:     xmstring = XmStringCreateSimple("white");  
1610:     XtVaSetValues(pushButtonColorDepthOffsetHole7, XmNlabelString, xmstring, NULL);
1611:     XmStringFree(xmstring);
1612:   }
1613:   else { 
1614:     fgPixel[DEPOFFHOLE7_COLOR] = return_color.pixel;
1615:     xmstring = XmStringCreateSimple(color[DEPOFFHOLE7_COLOR]);  
1616:     XtVaSetValues(pushButtonColorDepthOffsetHole7, XmNlabelString, xmstring, NULL);  
1617:     XmStringFree(xmstring);
1618:   }
1619:   XtVaSetValues(pushButtonColorDepthOffsetHole7, XmNbackground, fgPixel[DEPOFFHOLE7_COLOR], NULL);
1620: 
1621:   if(!XAllocNamedColor(dpy, cmap, color[DEPOFFHOLE8_COLOR], &return_color, &unused)) {
1622:     (void)sprintf(buffer, "can not allocate named color.  %s", color[DEPOFFHOLE8_COLOR]);
1623:     SpManageWarningBox(buffer);
1624:     fgPixel[DEPOFFHOLE8_COLOR] = pixwhite;
1625:     xmstring = XmStringCreateSimple("white");  
1626:     XtVaSetValues(pushButtonColorDepthOffsetHole8, XmNlabelString, xmstring, NULL);
1627:     XmStringFree(xmstring);
1628:   }
1629:   else { 
1630:     fgPixel[DEPOFFHOLE8_COLOR] = return_color.pixel;
1631:     xmstring = XmStringCreateSimple(color[DEPOFFHOLE8_COLOR]);  
1632:     XtVaSetValues(pushButtonColorDepthOffsetHole8, XmNlabelString, xmstring, NULL);  
1633:     XmStringFree(xmstring);
1634:   }
1635:   XtVaSetValues(pushButtonColorDepthOffsetHole8, XmNbackground, fgPixel[DEPOFFHOLE8_COLOR], NULL);
1636: 
1637:   if(!XAllocNamedColor(dpy, cmap, color[DEPOFFHOLE9_COLOR], &return_color, &unused)) {
1638:     (void)sprintf(buffer, "can not allocate named color.  %s", color[DEPOFFHOLE9_COLOR]);
1639:     SpManageWarningBox(buffer);
1640:     fgPixel[DEPOFFHOLE9_COLOR] = pixwhite;
1641:     xmstring = XmStringCreateSimple("white");  
1642:     XtVaSetValues(pushButtonColorDepthOffsetHole9, XmNlabelString, xmstring, NULL);
1643:     XmStringFree(xmstring);
1644:   }
1645:   else { 
1646:     fgPixel[DEPOFFHOLE9_COLOR] = return_color.pixel;
1647:     xmstring = XmStringCreateSimple(color[DEPOFFHOLE9_COLOR]);   
1648:     XtVaSetValues(pushButtonColorDepthOffsetHole9, XmNlabelString, xmstring, NULL);   
1649:     XmStringFree(xmstring);
1650:   }
1651:   XtVaSetValues(pushButtonColorDepthOffsetHole9, XmNbackground, fgPixel[DEPOFFHOLE9_COLOR], NULL);
1652: 
1653:   if(!XAllocNamedColor(dpy, cmap, color[DEPOFFHOLE10_COLOR], &return_color, &unused)) {
1654:     (void)sprintf(buffer, "can not allocate named color.  %s", color[DEPOFFHOLE10_COLOR]);
1655:     SpManageWarningBox(buffer);
1656:     fgPixel[DEPOFFHOLE10_COLOR] = pixwhite;
1657:     xmstring = XmStringCreateSimple("white");  
1658:     XtVaSetValues(pushButtonColorDepthOffsetHole10, XmNlabelString, xmstring, NULL);
1659:     XmStringFree(xmstring);
1660:   }
1661:   else { 
1662:     fgPixel[DEPOFFHOLE10_COLOR] = return_color.pixel;
1663:     xmstring = XmStringCreateSimple(color[DEPOFFHOLE10_COLOR]);   
1664:     XtVaSetValues(pushButtonColorDepthOffsetHole10, XmNlabelString, xmstring, NULL);   
1665:     XmStringFree(xmstring);
1666:   }
1667:   XtVaSetValues(pushButtonColorDepthOffsetHole10, XmNbackground, fgPixel[DEPOFFHOLE10_COLOR], NULL);
1668: 
1669:   if(!XAllocNamedColor(dpy, cmap, color[DEPOFFHOLE11_COLOR], &return_color, &unused)) {
1670:     (void)sprintf(buffer, "can not allocate named color.  %s", color[DEPOFFHOLE11_COLOR]);
1671:     SpManageWarningBox(buffer);
1672:     fgPixel[DEPOFFHOLE11_COLOR] = pixwhite;
1673:     xmstring = XmStringCreateSimple("white");  
1674:     XtVaSetValues(pushButtonColorDepthOffsetHole11, XmNlabelString, xmstring, NULL);
1675:     XmStringFree(xmstring);
1676:   }
1677:   else { 
1678:     fgPixel[DEPOFFHOLE11_COLOR] = return_color.pixel;
1679:     xmstring = XmStringCreateSimple(color[DEPOFFHOLE11_COLOR]);   
1680:     XtVaSetValues(pushButtonColorDepthOffsetHole11, XmNlabelString, xmstring, NULL);   
1681:     XmStringFree(xmstring);
1682:   }
1683:   XtVaSetValues(pushButtonColorDepthOffsetHole11, XmNbackground, fgPixel[DEPOFFHOLE11_COLOR], NULL);
1684: 
1685:   /* colors for the age depth
1686:   */
1687:   if(!XAllocNamedColor(dpy, cmap, color[AGEDEPHANDPICK_COLOR], &return_color, &unused)) {
1688:     (void)sprintf(buffer, "can not allocate named color.  %s", color[AGEDEPHANDPICK_COLOR]);
1689:     SpManageWarningBox(buffer);
1690:     fgPixel[AGEDEPHANDPICK_COLOR] = pixwhite;
1691:     xmstring = XmStringCreateSimple("white"); 
1692:     XtVaSetValues(pushButtonColorAgeDepthHandPick, XmNlabelString, xmstring, NULL);
1693:     XmStringFree(xmstring);
1694:   }
1695:   else {
1696:     fgPixel[AGEDEPHANDPICK_COLOR] = return_color.pixel;
1697:     xmstring = XmStringCreateSimple(color[AGEDEPHANDPICK_COLOR]);
1698:     XtVaSetValues(pushButtonColorAgeDepthHandPick, XmNlabelString, xmstring, NULL);
1699:     XmStringFree(xmstring);
1700:   }
1701:   XtVaSetValues(pushButtonColorAgeDepthHandPick, XmNbackground, fgPixel[AGEDEPHANDPICK_COLOR], NULL);
1702: 
1703:   if(!XAllocNamedColor(dpy, cmap, color[AGEDEPLINE_COLOR], &return_color, &unused)) {
1704:     (void)sprintf(buffer, "can not allocate named color.  %s", color[AGEDEPLINE_COLOR]);
1705:     SpManageWarningBox(buffer);
1706:     fgPixel[AGEDEPLINE_COLOR] = pixwhite;
1707:     xmstring = XmStringCreateSimple("white"); 
1708:     XtVaSetValues(pushButtonColorAgeDepthLine, XmNlabelString, xmstring, NULL);
1709:     XmStringFree(xmstring);
1710:   }
1711:   else {
1712:     fgPixel[AGEDEPLINE_COLOR] = return_color.pixel;
1713:     xmstring = XmStringCreateSimple(color[AGEDEPLINE_COLOR]);
1714:     XtVaSetValues(pushButtonColorAgeDepthLine, XmNlabelString, xmstring, NULL);
1715:     XmStringFree(xmstring);
1716:   }
1717:   XtVaSetValues(pushButtonColorAgeDepthLine, XmNbackground, fgPixel[AGEDEPLINE_COLOR], NULL);
1718: 
1719:   /* set the colors for splice vs age
1720:   */
1721:   if(!XAllocNamedColor(dpy, cmap, color[SEDRATE_COLOR], &return_color, &unused)) {
1722:     (void)sprintf(buffer, "can not allocate named color.  %s", color[SEDRATE_COLOR]);
1723:     SpManageWarningBox(buffer);
1724:     fgPixel[SEDRATE_COLOR] = pixwhite;
1725:     xmstring = XmStringCreateSimple("white");
1726:     XtVaSetValues(pushButtonColorSedRate, XmNlabelString, xmstring, NULL);
1727:     XmStringFree(xmstring);
1728:   }
1729:   else {
1730:     fgPixel[SEDRATE_COLOR] = return_color.pixel;
1731:     xmstring = XmStringCreateSimple(color[SEDRATE_COLOR]);
1732:     XtVaSetValues(pushButtonColorSedRate, XmNlabelString, xmstring, NULL);
1733:     XmStringFree(xmstring);
1734:   }
1735:   XtVaSetValues(pushButtonColorSedRate, XmNbackground, fgPixel[SEDRATE_COLOR], NULL);
1736: 
1737:   if(!XAllocNamedColor(dpy, cmap, color[TIMESERIES_COLOR], &return_color, &unused)) {
1738:     (void)sprintf(buffer, "can not allocate named color.  %s", color[TIMESERIES_COLOR]);
1739:     SpManageWarningBox(buffer);
1740:     fgPixel[TIMESERIES_COLOR] = pixwhite;
1741:     xmstring = XmStringCreateSimple("white");
1742:     XtVaSetValues(pushButtonColorTimeSeries, XmNlabelString, xmstring, NULL);
1743:     XmStringFree(xmstring);
1744:   }
1745:   else {
1746:     fgPixel[TIMESERIES_COLOR] = return_color.pixel;
1747:     xmstring = XmStringCreateSimple(color[TIMESERIES_COLOR]);
1748:     XtVaSetValues(pushButtonColorTimeSeries, XmNlabelString, xmstring, NULL);
1749:     XmStringFree(xmstring);
1750:   }
1751:   XtVaSetValues(pushButtonColorTimeSeries, XmNbackground, fgPixel[TIMESERIES_COLOR], NULL);
1752: 
1753:   if(!XAllocNamedColor(dpy, cmap, color[DATUMLOC_COLOR], &return_color, &unused)) {
1754:     (void)sprintf(buffer, "can not allocate named color.  %s", color[DATUMLOC_COLOR]);
1755:     SpManageWarningBox(buffer);
1756:     fgPixel[DATUMLOC_COLOR] = pixwhite;
1757:     xmstring = XmStringCreateSimple("white");
1758:     XtVaSetValues(pushButtonColorDatumLocation, XmNlabelString, xmstring, NULL);
1759:     XmStringFree(xmstring);
1760:   }
1761:   else {
1762:     fgPixel[DATUMLOC_COLOR] = return_color.pixel;
1763:     xmstring = XmStringCreateSimple(color[DATUMLOC_COLOR]);
1764:     XtVaSetValues(pushButtonColorDatumLocation, XmNlabelString, xmstring, NULL);
1765:     XmStringFree(xmstring);
1766:   }
1767:   XtVaSetValues(pushButtonColorDatumLocation, XmNbackground, fgPixel[DATUMLOC_COLOR], NULL);
1768: }
1769: 
1770: 
1771: int FindAveDepth(holenum, corenum, pavedt)
1772: int holenum, corenum;
1773: float *pavedt;
1774: {
1775:   int i, n, err, dum;
1776:   float sbd[MAXPERCORE], dat[MAXPERCORE];
1777: 
1778:   /* calculate the average depth step for current
1779:      'tied' cores.
1780:      note that cum depth offset is irrelevant
1781:      and whether using smooth or not unimportant
1782:   */
1783:   *pavedt = 0.0;
1784:   n = 0;
1785:   if(data[dset]->holes[holenum]->core[corenum]->numvalues > 1){
1786: 
1787:     /* clean core of bad values
1788:     */
1789:     dum = 0;
1790:     err = CleanUpCore(dset, holenum, corenum, &n, sbd, dat, NO, &dum);
1791: 
1792:     if(n > 1) { 
1793:       for(i=0; i<n-1; ++i){
1794:         *pavedt = *pavedt + sbd[i+1] - sbd[i];
1795:       }
1796:       *pavedt = *pavedt/n;
1797:     }   
1798:     else {
1799:       (void)sprintf(buffer, "Warning; can not calculate average depth in hole %c core %d. using 0.05m.",
1800:                               data[dset]->holes[holenum]->name, data[dset]->holes[holenum]->core[corenum]->num);
1801:       SpManageWarningBox(buffer);
1802:       *pavedt = 0.05;
1803:       return 1;
1804:     }
1805:   }
1806:   else { 
1807:     (void)sprintf(buffer, "Warning; hole %c core %d has less than 2 points!", 
1808:                             data[dset]->holes[holenum]->name, data[dset]->holes[holenum]->core[corenum]->num);
1809:     SpManageWarningBox(buffer);
1810:     return 2;
1811:   }
1812: 
1813:   return 0;
1814: }
1815: 
1816: 
1817: /* correlation function. note that in this function
1818:    x is core 1 and y is core 2 
1819: */
1820: int Correlate(nx,ny,offx,offy,x,y,pcoef,pn)
1821: int nx, ny, offx, offy, *pn;
1822: float x[MAXPERCORE], y[MAXPERCORE], *pcoef;
1823: {
1824:   int j;
1825:   float sumx, sumy, sumxy, sumxsq, sumysq, stdevx, stdevy;
1826:  
1827:  
1828:   *pn=0;
1829:   sumx=0.0;
1830:   sumy=0.0;
1831:   sumxy=0.0;
1832:   sumxsq=0.0;
1833:   sumysq=0.0;
1834:  
1835:   /* sum up  
1836:   */
1837:   for(j=0; j<ny; ++j){
1838:     if(j+offx+offy < 0 || j+offx+offy >= nx){
1839:     }
1840:     else if(x[j+offx+offy] == -9999.0 || y[j+offy] == -9999.0){
1841:     }
1842:     else {
1843:       ++*pn;
1844:       sumx=sumx+x[j+offx+offy];
1845:       sumy=sumy+y[j+offy];
1846:       sumxy=sumxy+x[j+offx+offy]*y[j+offy];
1847:       sumxsq=sumxsq+x[j+offx+offy]*x[j+offx+offy];
1848:       sumysq=sumysq+y[j+offy]*y[j+offy];
1849:     }
1850:   }
1851: 
1852:   /* calculate the standard deviation and
1853:      the correlation coeficiant
1854:   */
1855:   if(*pn > 1){
1856:     stdevx=((*pn)*sumxsq)-(sumx*sumx);
1857:     stdevy=((*pn)*sumysq)-(sumy*sumy);
1858:     if(stdevx <= 0 || stdevy <= 0){
1859:       *pcoef=0.0;
1860:       *pn=0;
1861:     }
1862:     else {
1863:       stdevx=sqrt(stdevx);
1864:       stdevy=sqrt(stdevy);
1865:       *pcoef=(((*pn)*sumxy)-(sumx*sumy))/(stdevx*stdevy);
1866:     }
1867:   }
1868:   else {
1869:     *pcoef=0.0;
1870:     *pn=0;
1871:   }
1872:   return 0;
1873: }
1874: 
1875: 
1876: /* repick depth at constant depth step
1877: */
1878: int RepickDepth(pdep,pvar,pn,ptie,dt)
1879: int *pn, *ptie;
1880: float *pdep, *pvar, dt;
1881: {
1882:   int i, n, k, kt, lastk, lastn;
1883:   float dep[MAXPERCORE], var[MAXPERCORE];
1884: 
1885:   /* repick from tie point backwards to first sample
1886:   */
1887:   n=(pdep[*ptie]-pdep[0])/dt+1;
1888:   if(n > MAXPERCORE){
1889:     return 1;
1890:   }
1891:   dep[n-1]=pdep[*ptie];
1892:   for(i=n-2; i>=0;--i){
1893:     dep[i]=dep[i+1]-dt;
1894:   }
1895:   k=*ptie;
1896:   kt=n-1;
1897:   while(kt >= 0){
1898:     if((k-1) < 0 && dep[kt] <= pdep[0]){
1899:       var[kt]=(pvar[1]-pvar[0])/
1900:                 (pdep[1]-pdep[0])*
1901:                 (dep[kt]-pdep[0])+pvar[0];
1902:       --kt;
1903:     }
1904:     else if(dep[kt] <= pdep[k] && 
1905:             dep[kt] >= pdep[k-1]){
1906:       var[kt]=(pvar[k]-pvar[k-1])/
1907:                 (pdep[k]-pdep[k-1])*
1908:                 (dep[kt]-pdep[k-1])+pvar[k-1];
1909:       --kt;
1910:     }
1911:     else if(dep[kt] < pdep[k] && (k-1) > 0){
1912:       --k;
1913:     }
1914:     else if(dep[kt] < pdep[0]){
1915:       var[kt]=(pvar[1]-pvar[0])/
1916:                 (pdep[1]-pdep[0])*
1917:                 (dep[kt]-pdep[0])+pvar[0];
1918:       --kt;
1919:     }
1920:   }
1921: 
1922:   /* repick from tie point to last sample
1923:   */
1924:   lastk=*pn-1;
1925:   lastn=(pdep[lastk]-pdep[*ptie])/dt+n;
1926:   if(lastn > MAXPERCORE){   
1927:     return 1;
1928:   } 
1929:   for(i=n;i<lastn;++i){
1930:     dep[i]=dep[i-1]+dt;
1931:   } 
1932:   k=*ptie;
1933:   kt=n;
1934:   while(kt < lastn){ 
1935:     if(k > lastk && dep[kt] >= pdep[lastk]){
1936:       var[kt]=(pvar[lastk]-pvar[lastk-1])/
1937:          (pdep[lastk]-pdep[lastk-1])*
1938:          (dep[kt]-pdep[lastk])+pvar[lastk];
1939:       ++kt;
1940:     }
1941:     else if(dep[kt] >= pdep[k-1] &&
1942:             dep[kt] <= pdep[k]){
1943:       var[kt]=(pvar[k]-pvar[k-1])/
1944:                 (pdep[k]-pdep[k-1])*
1945:                 (dep[kt]-pdep[k-1])+pvar[k-1];
1946:       ++kt;
1947:     } 
1948:     else if(dep[kt] > pdep[k] && (k+1) <= lastk){
1949:       ++k;
1950:     }    
1951:     else if(dep[kt] > pdep[lastk]){
1952:       var[kt]=(pvar[lastk]-pvar[lastk-1])/
1953:          (pdep[lastk]-pdep[lastk-1])*
1954:          (dep[kt]-pdep[lastk])+pvar[lastk];
1955:       ++kt;
1956:     }
1957:   }
1958:   *ptie=n-1;
1959:   *pn=lastn;
1960:   for(i=0; i<lastn; ++i){
1961:     pdep[i]=dep[i];
1962:     pvar[i]=var[i];
1963:   }
1964: 
1965:   /* check that have no duplicate depths
1966:   */
1967:   for(i=1; i<lastn; ++i){
1968:     if(dep[i-1] == dep[i]){
1969:       (void)sprintf(buffer, "Repick; depths not in descending order at %.2f", dep[i]); 
1970:       SpManageWarningBox(buffer);
1971:     }
1972:     else if(dep[i-1] > dep[i]){
1973:       (void)sprintf(buffer, "Repicking depth; depths not in descending order at %.2f", dep[i]);  
1974:       SpManageWarningBox(buffer);
1975:     }
1976:   }
1977: 
1978:   return 0;
1979: }
1980: 
1981: 
1982: /* find min and max of current var for entire site.
1983:    convert these to nearest reasonable whole numbers.
1984:    and change them to +/- (PLUSMINUSSTD std from mean.
1985:    use this range to calculate the initial drawing
1986:    scale to use.
1987:    this would be (max-min)/VAR_AXIS_LEN
1988:    also find the maximum depth; minimum always 0.
1989: */
1990: int FindMinMax(ds)
1991: int ds;
1992: {
1993:   int i, j, k, sm, err, dum, coren, nstd;
1994:   float *phold, coredep[MAXPERCORE], corevar[MAXPERCORE];
1995:   double std, mean, sumstd, summean;
1996: 
1997:   if(data[ds]->numholes < 1) {
1998:     return(0);
1999:   }
2000: 
2001:   if(smooth.method == NONE) {
2002:     sm = NO;
2003:   }
2004:   else if((smooth.method == GAUSSIAN || smooth.method == OTHER) &&
2005:           (smooth.plot == UNSMOOTHED || smooth.plot == SMOOTHEDBOTH)){ 
2006:     sm = NO;
2007:   }  
2008:   else if((smooth.method == GAUSSIAN || smooth.method == OTHER) &&
2009:            smooth.plot == SMOOTHED){
2010:     sm = YES;
2011:   }
2012: 
2013:   minvar = 9999.0;
2014:   maxvar = -9999.0;
2015:   maxdep = -9999.0;
2016:   summean = 0.0;
2017:   mean = 0.0;
2018:   sumstd = 0.0;
2019:   std = 0.0;
2020:   nstd = 0;
2021: 
2022:   for(i=0; i<data[ds]->numholes; ++i) {
2023:     if(data[ds]->holes[i]->numcores < 1) {
2024:     }
2025:     else {
2026:       for(j=0; j<data[ds]->holes[i]->numcores; ++j) {
2027:         if(data[ds]->holes[i]->core[j]->numvalues < 1) {
2028:         }
2029:         else {
2030:           for(k=0; k<data[ds]->holes[i]->core[j]->numvalues; ++k) {
2031: 
2032:             if(sm == NO &&
2033:                (data[ds]->holes[i]->core[j]->value[k]->quality) == GOOD){
2034:               phold = data[ds]->holes[i]->core[j]->value[k]->data;
2035:               if(*phold > maxvar) {
2036:                 maxvar = *phold;
2037:               }  
2038:               else if(*phold < minvar) {
2039:                 minvar = *phold;
2040:               }
2041:             }
2042:             else if(sm == YES &&
2043:                     data[ds]->holes[i]->core[j]->value[k]->smooth_ok >= SMOK){
2044:               if(data[ds]->holes[i]->core[j]->value[k]->sm_data > maxvar) {
2045:                 maxvar = data[ds]->holes[i]->core[j]->value[k]->sm_data;  
2046:               }  
2047:               else if(data[ds]->holes[i]->core[j]->value[k]->sm_data < minvar) { 
2048:                 minvar = data[ds]->holes[i]->core[j]->value[k]->sm_data;
2049:               }
2050:             }
2051:             else {
2052:             }
2053:           }
2054: 
2055:           dum = 0;
2056:           err = CleanUpCore(ds, i, j, &coren, coredep, corevar, NO, &dum);
2057:           err = StdDev(corevar, coren, 0, coren, &std, &mean);
2058:           sumstd = sumstd + std;
2059:           summean = summean + mean;
2060:           ++nstd;
2061:         }
2062:       }  
2063:     }  
2064:     j = data[ds]->holes[i]->numcores - 1;
2065:     k = data[ds]->holes[i]->core[j]->numvalues - 1;
2066:     if(data[ds]->holes[i]->core[j]->value[k]->sb_depth > maxdep){
2067:       maxdep = data[ds]->holes[i]->core[j]->value[k]->sb_depth;
2068:     }
2069:   }
2070: 
2071:   if(minvar == 9999.0 || maxvar == -9999.0) {
2072:     return 1;
2073:   }
2074:   else {
2075:     realminvar = minvar;
2076:     realmaxvar = maxvar;
2077: 
2078:     if(nstd > 0 && err == 0) {
2079:       std = sumstd/nstd;
2080:       mean = summean/nstd;
2081:       minvar = mean - (PLUSMINUSSTD * std);
2082:       maxvar = mean + (PLUSMINUSSTD * std);
2083:     }
2084:     else {
2085:       return 1;
2086:     }
2087:   }
2088: 
2089:   return 0;
2090: }
2091: 
2092: /* clean up one cores depth and var
2093:    for either plotting or correlation.
2094:    find and average mult samples per level,
2095:    remove bad values,
2096:    chack that samples in desending order,
2097:    Add the cummulative depth offset to sbd.
2098:    (future) deal with gaps in data.
2099: */
2100: int CleanUpCore(s, hnum, cnum, pn, psbd, pdata, sm, pt)
2101: int s, hnum, cnum, *pn, sm, *pt;
2102: float *pdata, *psbd;
2103: {
2104:   int j, k, n, ndiv, tie;
2105:   float sum, savetiedep;
2106: 
2107:   /*look for and trash any bad data by not storing
2108:     them in the pointers pdata and psbd
2109:     if have sent a core for  correlation and remove
2110:     a sample, change the tie(if needed).
2111:   */
2112:     
2113:   n = 0;
2114:   tie = *pt;
2115:   for(j=0; j<data[s]->holes[hnum]->core[cnum]->numvalues; ++j) {
2116:     if(sm == NO && data[s]->holes[hnum]->core[cnum]->value[j]->quality == GOOD){
2117:       pdata[n] = *data[s]->holes[hnum]->core[cnum]->value[j]->data;
2118:       psbd[n] = data[s]->holes[hnum]->core[cnum]->value[j]->sb_depth;
2119:       ++n;
2120:     }
2121:     else if(sm == YES && data[s]->holes[hnum]->core[cnum]->value[j]->smooth_ok >= SMOK){
2122:       pdata[n] = data[s]->holes[hnum]->core[cnum]->value[j]->sm_data;
2123:       psbd[n] = data[s]->holes[hnum]->core[cnum]->value[j]->sb_depth;
2124:       ++n;
2125:     }
2126:     else if(tie > 0 && n < tie){
2127:       --tie;
2128:     }
2129:   }
2130:   *pn = n;
2131: 
2132:   /* check that there are at least two data points in
2133:      this core
2134:   */
2135:   if(n < 2) {
2136:     return 1;
2137:   }
2138: 
2139:   /* check that data is in order
2140:   */
2141:   for(j=1; j<n; ++j) {
2142:     if(psbd[j] < psbd[j-1]) {
2143:       return 2;
2144:     }
2145:   }
2146: 
2147:   /* look for mult samples per level and average any found
2148:      can now use the pointers pdata and psbd rather than
2149:      the global structs
2150:      the var will either be unsmoothed or smoothed
2151:      depending on value of sm = NO/YES.
2152:      if are correlating and find mult samples, adjust
2153:      tie(if needed)
2154:   */
2155:   sum = pdata[0];
2156:   ndiv = 1;
2157:   savetiedep = psbd[tie];
2158:   k = 0;
2159:   for(j=1; j<n; ++j){
2160:     if(psbd[j] == psbd[j-1] &&
2161:                    j < n-1){
2162:       sum = sum + pdata[j];
2163:       ++ndiv;
2164:     }
2165:     else if(psbd[j] == psbd[j-1] && j == n-1){
2166:       sum = sum + pdata[j];
2167:       ++ndiv;
2168:       psbd[k] = psbd[j-1];
2169:       pdata[k] =  sum/ndiv;
2170:       ++k;
2171:       --tie;
2172:     }  
2173:     else if(psbd[j] != psbd[j-1] && j < n-1){
2174:       psbd[k] = psbd[j-1];
2175:       pdata[k] = sum/ndiv;
2176:       sum = pdata[j];
2177:       ndiv=1;
2178:       ++k;
2179:     }  
2180:     else if(psbd[j] != psbd[j-1] && j == n-1){
2181:       psbd[k] = psbd[j-1];
2182:       pdata[k] = sum/ndiv;
2183:       ++k;
2184:       psbd[k] = psbd[j];
2185:       pdata[k] = pdata[j];
2186:       ++k;
2187:     }  
2188:     else {
2189:     }  
2190:   }
2191:   *pn = k;
2192:   *pt = tie;
2193: 
2194:   for(j=0; j<k; ++j) {
2195:     if(fabs(savetiedep - psbd[j]) < 0.0001) {
2196:       tie = j;
2197:     }
2198:   }
2199:   *pt = tie;
2200: 
2201:   /* check again that there are at least two data points in
2202:      this core
2203:   */
2204:   if(k < 2) {
2205:     return 1;
2206:   }
2207:   
2208: