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


   1: /*
   2:   splicer_io.c
   3: */
   4: #include <Xm/Xm.h>
   5: #include <Xm/Text.h>
   6: #include <X11/cursorfont.h>
   7: #include <stdio.h>
   8: #include <math.h>
   9: #include <ctype.h>
  10: #include <fcntl.h>
  11: #include <string.h>
  12: #include <malloc.h>
  13: #include <unistd.h>
  14: #include "splicer-creation-c.h"
  15: #include "splicer_vars.h"
  16: 
  17: #define MAXLINE   (1001)
  18: #define MAXPREVIEW      (20)
  19: long  atol();
  20: int close();
  21: char  line[MAXLINE];
  22: 
  23: 
  24: int SpReadSplicerTable(fptr,splicerptr,cnt)
  25: FILE  *fptr;
  26: SplicerTableInfo  *splicerptr;
  27: int *cnt;
  28: {
  29:   int status,i;
  30: 
  31:   status=fscanf(fptr,"%d %c %d %c %s %f %f %f %f %s %d %c %d %c %s %f %f %f %f",
  32:       &splicerptr[*cnt].site,&splicerptr[*cnt].hole,&splicerptr[*cnt].core,&splicerptr[*cnt].core_type,
  33:       splicerptr[*cnt].section,&splicerptr[*cnt].top_int,&splicerptr[*cnt].bot_int,
  34:       &splicerptr[*cnt].mbsf,&splicerptr[*cnt].mcd, splicerptr[*cnt+1].type_of_splice,
  35:       &splicerptr[*cnt+1].site,&splicerptr[*cnt+1].hole,&splicerptr[*cnt+1].core,&splicerptr[*cnt+1].core_type,
  36:       splicerptr[*cnt+1].section,&splicerptr[*cnt+1].top_int,&splicerptr[*cnt+1].bot_int,
  37:       &splicerptr[*cnt+1].mbsf,&splicerptr[*cnt+1].mcd);
  38:   if(status==9 || status==19) /* more data to read */
  39:   {
  40:     *cnt=*cnt+status/9;
  41:     splicerptr[*cnt].hole=toupper(splicerptr[*cnt].hole);
  42:     splicerptr[*cnt].core_type=toupper(splicerptr[*cnt].core_type);
  43:     for(i=0;i<(int)strlen(splicerptr[*cnt].section);i++)
  44:     {
  45:       if(isalpha(splicerptr[*cnt].section[i]))
  46:         splicerptr[*cnt].section[i]=toupper(splicerptr[*cnt].section[i]);
  47:     }
  48:     splicerptr[*cnt+1].hole=toupper(splicerptr[*cnt+1].hole);
  49:     splicerptr[*cnt+1].core_type=toupper(splicerptr[*cnt+1].core_type);
  50:     for(i=0;i<(int)strlen(splicerptr[*cnt+1].section);i++)
  51:     {
  52:       if(isalpha(splicerptr[*cnt+1].section[i]))
  53:         splicerptr[*cnt+1].section[i]=toupper(splicerptr[*cnt+1].section[i]);
  54:     }
  55:   }
  56:   return(status);
  57: }
  58: 
  59: int SpWriteSplicerTable(splfile)
  60: char *splfile;
  61: {
  62:   int i;
  63:   Hole  *holeptr1,*holeptr2;
  64:   Core  *coreptr1,*coreptr2;
  65:   Value *valueptr1,*valueptr2;
  66:         FILE    *fptr;
  67:         SplicerTableInfo  *spl1, *spl2;
  68: 
  69:   if((fptr=fopen(splfile, "w")) == NULL){
  70:     return;
  71:   }
  72: 
  73:   i = 1;
  74:   while(i<splicertable.data_cnt-1) {
  75:     spl1 = &splicertable.data[i];
  76:     spl2 = &splicertable.data[i+1];
  77:     if((int)strcmp(spl2->type_of_splice, "interp") == 0) {
  78:       (void)sprintf(spl2->type_of_splice, "tie");
  79:     }
  80:     (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.1f\t%.2f\t%.2f\t%s\t%d\t%c\t%d\t%c\t%s\t%.1f\t%.1f\t%.2f\t%.2f\n",
  81:       spl1->site, spl1->hole, spl1->core, spl1->core_type, spl1->section, spl1->top_int, spl1->bot_int, spl1->mbsf, spl1->mcd,
  82:       spl2->type_of_splice,
  83:       spl2->site, spl2->hole, spl2->core, spl2->core_type, spl2->section, spl2->top_int, spl2->bot_int, spl2->mbsf, spl2->mcd);
  84:     i = i + 2;
  85:   } 
  86:   
  87:   i = splicertable.data_cnt-1;
  88:   spl1 = &splicertable.data[i];
  89:   (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.1f\t%.2f\t%.2f\n", 
  90:     spl1->site, spl1->hole, spl1->core, spl1->core_type, spl1->section, spl1->top_int, spl1->bot_int, spl1->mbsf, spl1->mcd);
  91: 
  92:   fclose(fptr);
  93: 
  94:   return(True);
  95: }
  96: 
  97: int SpReadStrat(fptr,stratptr)
  98: FILE  *fptr;
  99: StratData *stratptr;
 100: {
 101:   int status,i;
 102: 
 103:   status=fscanf(fptr,"%s %s %f %f %d %d %c %d %c %s %f %f %d %d %c %d %c %s %f %f",
 104:     stratptr->name,stratptr->code,&stratptr->top_age,&stratptr->bot_age,&stratptr->top.leg,
 105:     &stratptr->top.site,&stratptr->top.hole,&stratptr->top.core,
 106:     &stratptr->top.coretype,stratptr->top.section,&stratptr->top.interval,
 107:     &stratptr->top.sb_depth,&stratptr->bot.leg,&stratptr->bot.site,&stratptr->bot.hole,&stratptr->bot.core,
 108:     &stratptr->bot.coretype,stratptr->bot.section,&stratptr->bot.interval,&stratptr->bot.sb_depth);
 109:   stratptr->top.hole=toupper(stratptr->top.hole);
 110:   stratptr->top.coretype=toupper(stratptr->top.coretype);
 111:   for(i=0;i<(int)strlen(stratptr->top.section);i++)
 112:   {
 113:     if(isalpha(stratptr->top.section[i]))
 114:       stratptr->top.section[i]=toupper(stratptr->top.section[i]);
 115:   }
 116:   stratptr->bot.hole=toupper(stratptr->bot.hole);
 117:   stratptr->bot.coretype=toupper(stratptr->bot.coretype);
 118:   for(i=0;i<(int)strlen(stratptr->bot.section);i++)
 119:   {
 120:     if(isalpha(stratptr->bot.section[i]))
 121:       stratptr->bot.section[i]=toupper(stratptr->bot.section[i]);
 122:   }
 123:   if(status==20)
 124:     return(True);
 125:   else if(status!=EOF)
 126:   {
 127:     message.error=True;
 128:                 if((charptr=(char*)calloc(200,CHAR_SIZE))==NULL) {
 129:                   SpBadMemAlloc("SpReadSTrat");
 130:                 }
 131:                 else {
 132:                   (void)sprintf(charptr,"Error reading stat file. This happened at datum name %s", stratptr->name);
 133:                 }
 134:     SpManageWarningBox(charptr);
 135:                 free(charptr);
 136:     return(False);
 137:   }
 138:   else
 139:     return(False);
 140: 
 141: } 
 142: 
 143: int SpWriteStrat(fptr,stratptr)
 144: FILE  *fptr;
 145: StratData *stratptr;
 146: {
 147:   char  topoffset[6],botoffset[6],
 148:     topmsd[9],botmsd[9];
 149:   
 150:   if(stratptr->top.in_affine == NO)
 151:   {
 152:     (void)sprintf(topmsd,"N/A");
 153:     (void)sprintf(topoffset,"N/A");
 154:   }
 155:   else
 156:   {
 157:     (void)sprintf(topmsd,"%.2f",stratptr->top.sb_depth+stratptr->top.offset);
 158:     (void)sprintf(topoffset,"%.2f",stratptr->top.offset);
 159:   }
 160:   if(stratptr->bot.in_affine == NO)
 161:   {
 162:     (void)sprintf(topmsd,"N/A");
 163:     (void)sprintf(botoffset,"N/A");
 164:   }
 165:   else
 166:   {
 167:     (void)sprintf(botmsd,"%.2f",stratptr->bot.sb_depth+stratptr->bot.offset);
 168:     (void)sprintf(botoffset,"%.2f",stratptr->bot.offset);
 169:   }
 170:   fprintf(fptr,"%s\t%s\t%.2f\t%.2f\t%d\t%d\t%c\t%d\t%c\t%s\t%.2f\t%.2f\t%s\t%s\t%d\t%d\t%c\t%d\t%c\t%s\t%.2f\t%.2f\t%s\t%s\n",
 171:     stratptr->name,stratptr->code,stratptr->top_age,stratptr->bot_age,stratptr->top.leg,
 172:     stratptr->top.site,stratptr->top.hole,stratptr->top.core,
 173:     stratptr->top.coretype,stratptr->top.section,stratptr->top.interval,
 174:     stratptr->top.sb_depth, topoffset, topmsd,
 175:     stratptr->bot.leg,stratptr->bot.site,stratptr->bot.hole,stratptr->bot.core,
 176:     stratptr->bot.coretype,stratptr->bot.section,stratptr->bot.interval,stratptr->bot.sb_depth,
 177:     botoffset,botmsd);
 178:   return(True);
 179: }
 180: int SpWriteData(fptr,holeptr)
 181: FILE  *fptr;
 182: Hole  *holeptr;
 183: {
 184:   int i,j;
 185:   Core  *coreptr;
 186:   Value *valueptr;
 187: 
 188:   for(i=0;i<holeptr->numcores;i++)
 189:   {
 190:     coreptr=holeptr->core[i];
 191:     for(j=0;j<coreptr->numvalues;j++)
 192:     {
 193:       valueptr=coreptr->value[j];
 194:         valueptr=coreptr->value[j];
 195:       if(valueptr->quality==GOOD)
 196:       {
 197:                                 switch (data[dset]->in_format) {
 198:                 
 199:                                   case MST95REPORT:
 200:                                   case TKREPORT:
 201:             (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.1f\t%.2f\t%.3f",
 202:                   data[dset]->site,holeptr->name,coreptr->num,valueptr->type,
 203:             valueptr->section,valueptr->top_int,
 204:             valueptr->bot_int, valueptr->sb_depth, *valueptr->data);
 205:             if(smooth.method!=NONE)
 206:           (void)fprintf(fptr,"\t%.3f",valueptr->sm_data);
 207:                                     break;
 208:                                   case ODPOTHER1:
 209:                                     (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.1f\t%.2f\t%.2f",
 210:                                                 data[dset]->site,holeptr->name,coreptr->num,valueptr->type,
 211:                                                 valueptr->section,valueptr->top_int,
 212:                                                 valueptr->bot_int, valueptr->sb_depth, *valueptr->data);
 213:                                     if(smooth.method!=NONE)
 214:                                         (void)fprintf(fptr,"\t%.2f",valueptr->sm_data);
 215:                                     break;
 216:                                   case ODPOTHER2:
 217:                                     (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.1f\t%.2f\t%.2f",
 218:                                                 data[dset]->site, holeptr->name,coreptr->num,valueptr->type,
 219:                                                 valueptr->section,valueptr->top_int,
 220:                                                 valueptr->bot_int, valueptr->sb_depth, *valueptr->data);
 221:                                     if(smooth.method!=NONE)
 222:                                         (void)fprintf(fptr,"\t%.2f",valueptr->sm_data);
 223:                                     break;
 224:                                   case ODPOTHER3:
 225:                                     (void)fprintf(fptr,"%d\t%c\t%d\t%s\t%.1f\t%.1f\t%.2f\t%.2f",
 226:                                                 data[dset]->site, holeptr->name,coreptr->num,
 227:                                                 valueptr->section,valueptr->top_int,
 228:                                                 valueptr->bot_int, valueptr->sb_depth, *valueptr->data);
 229:                                     if(smooth.method!=NONE)
 230:                                         (void)fprintf(fptr,"\t%.2f",valueptr->sm_data);
 231:                                     break;
 232:                                   case ODPOTHER4:
 233:                                     (void)fprintf(fptr,"%d\t%c\t%d\t%s\t%.1f\t%.2f\t%.2f",
 234:                                                 data[dset]->site, holeptr->name,coreptr->num,
 235:                                                 valueptr->section,valueptr->top_int,
 236:                                                 valueptr->sb_depth, *valueptr->data);
 237:                                     if(smooth.method!=NONE)
 238:                                         (void)fprintf(fptr,"\t%.2f",valueptr->sm_data);
 239:                                     break;
 240:                                   case JANUSCLEAN:
 241:                                   case JANUSORIG:
 242:                                   case ODPOTHER5:
 243:                                     (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.2f\t%.3f",
 244:                                                 data[dset]->site,holeptr->name,coreptr->num,valueptr->type,
 245:                                                 valueptr->section,valueptr->top_int,
 246:                                                 valueptr->sb_depth, *valueptr->data);
 247:                                     if(smooth.method!=NONE)
 248:                                         (void)fprintf(fptr,"\t%.3f",valueptr->sm_data);
 249:                                     break;
 250:                                 }
 251:         (void)fprintf(fptr,"\t%.2f\t%.2f\n", coreptr->cum_dep_offset,
 252:             (valueptr->sb_depth+coreptr->cum_dep_offset));
 253:       }
 254:     }
 255:   }
 256:   return(True);
 257: }
 258: 
 259: int SpWriteSplicerData(filename, writeage)
 260: char    *filename;
 261: int     writeage;
 262: {
 263:   int i,j;
 264:         float   smvar;
 265:   Hole  *holeptr;
 266:   Core  *coreptr;
 267:   Value *valueptr;
 268:         FILE    *fptr;
 269: 
 270:         if((fptr=fopen(filename,"w"))==NULL)
 271:         {
 272:           (void)sprintf(buffer, "Could not write file %s.", filename);
 273:           SpManageWarningBox(buffer);
 274:           return;
 275:         }
 276: 
 277:         io_wait_cursor = XCreateFontCursor(XtDisplay(formFileSelection), XC_watch);
 278:         if(io_wait_cursor != BadAlloc && io_wait_cursor != BadFont && io_wait_cursor != BadValue) {
 279:           XDefineCursor(XtDisplay(formFileSelection), XtWindow(formFileSelection), io_wait_cursor);
 280:         }
 281: 
 282:   for(i=0;i<spcomp.numcores;i++)
 283:   {
 284:     holeptr=data[dset]->holes[spcomp.hole[i]];
 285:     coreptr=holeptr->core[spcomp.core[i]];
 286:                 if(smooth.method == NONE){
 287:       for(j=0;j<spcomp.numpercore[i];j++)
 288:       {
 289:                     /* if the first point in core is at the same depth as last point of last
 290:                        core don't write it
 291:                     */ 
 292:                     if(!(i > 0 && j == 0 && fabs(spcomp.sb_depth[i][j] - spcomp.sb_depth[i-1][spcomp.numpercore[i-1]-1]) < 0.005))
 293:                     {
 294:       valueptr=coreptr->value[spcomp.MapToOrig[i][j]];
 295:                         switch (data[dset]->in_format) {
 296: 
 297:                           case MST95REPORT:
 298:                           case TKREPORT:
 299:           (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.1f\t%.2f\t%.3f\t%.2f\t%.2f",
 300:           data[dset]->site, holeptr->name, coreptr->num, valueptr->type, valueptr->section, valueptr->top_int,
 301:           valueptr->bot_int, valueptr->sb_depth, spcomp.var[i][j], spcomp.Depthoffset[i],
 302:           spcomp.sb_depth[i][j]);
 303:                              break;
 304:                           case ODPOTHER1:
 305:                             (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.1f\t%.2f\t%.2f\t%.2f\t%.2f",
 306:                                         data[dset]->site, holeptr->name, coreptr->num, valueptr->type, valueptr->section, valueptr->top_int,
 307:                                         valueptr->bot_int, valueptr->sb_depth, spcomp.var[i][j], spcomp.Depthoffset[i],
 308:                                         spcomp.sb_depth[i][j]);
 309:                             break;
 310:                           case ODPOTHER2:
 311:                             (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.1f\t%.2f\t%.2f\t%.2f\t%.2f",
 312:                                         data[dset]->site, holeptr->name, coreptr->num, valueptr->type, valueptr->section, valueptr->top_int,
 313:                                         valueptr->bot_int, valueptr->sb_depth, spcomp.var[i][j], spcomp.Depthoffset[i],
 314:                                         spcomp.sb_depth[i][j]);
 315:                             break;
 316:                           case ODPOTHER3:
 317:                             (void)fprintf(fptr,"%d\t%c\t%d\t%s\t%.1f\t%.1f\t%.2f\t%.2f\t%.2f\t%.2f",
 318:                                         data[dset]->site, holeptr->name, coreptr->num, valueptr->section, valueptr->top_int,
 319:                                         valueptr->bot_int, valueptr->sb_depth, spcomp.var[i][j], spcomp.Depthoffset[i],
 320:                                         spcomp.sb_depth[i][j]);
 321:                             break;
 322:                           case ODPOTHER4:
 323:                             (void)fprintf(fptr,"%d\t%c\t%d\t%s\t%.1f\t%.2f\t%.2f\t%.2f\t%.2f",
 324:                                         data[dset]->site, holeptr->name, coreptr->num, valueptr->section, valueptr->top_int,
 325:                                         valueptr->sb_depth, spcomp.var[i][j], spcomp.Depthoffset[i],
 326:                                         spcomp.sb_depth[i][j]);
 327:                             break;
 328:                           case JANUSCLEAN:
 329:                           case JANUSORIG:
 330:                           case ODPOTHER5:
 331:                             (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.2f\t%.3f\t%.2f\t%.2f",
 332:                                         data[dset]->site, holeptr->name, coreptr->num, valueptr->type, valueptr->section, valueptr->top_int,
 333:                                         valueptr->sb_depth, spcomp.var[i][j], spcomp.Depthoffset[i],
 334:                                         spcomp.sb_depth[i][j]);
 335:                              break;
 336:                         }
 337:                         if(writeage == YES) 
 338:                         {
 339:                              (void)fprintf(fptr,"\t%.3f\n", spcomp.age[i][j]);
 340:                         }
 341:                         else
 342:                         {
 343:                              (void)fprintf(fptr,"\n");
 344:                         }
 345:                     }
 346:                     else
 347:                     {
 348:                     }
 349:                   }
 350:                 }
 351:                 else if(smooth.method == GAUSSIAN || smooth.method == OTHER){
 352:                   for(j=0;j<spcomp.numpercore[i];j++)
 353:                   {  
 354:                     if(!(i > 0 && j == 0 && fabs(spcomp.sb_depth[i][j] - spcomp.sb_depth[i-1][spcomp.numpercore[i-1]-1]) < 0.005)){ 
 355:                         valueptr=coreptr->value[spcomp.MapToOrig[i][j]];
 356:                         if(valueptr->smooth_ok >= SMOK){
 357:                           smvar = valueptr->sm_data;
 358:                         }
 359:                         else {
 360:                           smvar = spcomp.var[i][j];
 361:                         }
 362: 
 363:                         switch (data[dset]->in_format) {
 364:  
 365:                           case MST95REPORT:
 366:                           case TKREPORT:
 367:                             (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.1f\t%.2f\t%.3f\t%.3f\t%.2f\t%.2f",
 368:                                         data[dset]->site,holeptr->name,coreptr->num,valueptr->type,valueptr->section,valueptr->top_int,
 369:                                         valueptr->bot_int, valueptr->sb_depth, spcomp.var[i][j], smvar,
 370:                                         spcomp.Depthoffset[i], spcomp.sb_depth[i][j]);
 371:                             break;
 372:                           case ODPOTHER1:
 373:                             (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.1f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f",
 374:                                         data[dset]->site, holeptr->name, coreptr->num, valueptr->type, valueptr->section, valueptr->top_int,
 375:                                         valueptr->bot_int, valueptr->sb_depth, spcomp.var[i][j], smvar, spcomp.Depthoffset[i],
 376:                                         spcomp.sb_depth[i][j]);
 377:                             break;
 378:                           case ODPOTHER2:
 379:                             (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.1f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f",
 380:                                         data[dset]->site, holeptr->name, coreptr->num, valueptr->type, valueptr->section, valueptr->top_int,
 381:                                         valueptr->bot_int, valueptr->sb_depth, spcomp.var[i][j], smvar, spcomp.Depthoffset[i],
 382:                                         spcomp.sb_depth[i][j]);
 383:                             break;
 384:                           case ODPOTHER3:
 385:                             (void)fprintf(fptr,"%d\t%c\t%d\t%s\t%.1f\t%.1f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f",
 386:                                         data[dset]->site, holeptr->name, coreptr->num, valueptr->section, valueptr->top_int,
 387:                                         valueptr->bot_int, valueptr->sb_depth, spcomp.var[i][j], smvar, spcomp.Depthoffset[i],
 388:                                         spcomp.sb_depth[i][j]);
 389:                             break;
 390:                           case ODPOTHER4:
 391:                             (void)fprintf(fptr,"%d\t%c\t%d\t%s\t%.1f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f",
 392:                                         data[dset]->site, holeptr->name, coreptr->num, valueptr->section, valueptr->top_int,
 393:                                         valueptr->sb_depth, spcomp.var[i][j], smvar, spcomp.Depthoffset[i],
 394:                                         spcomp.sb_depth[i][j]);
 395:                             break;
 396:                           case JANUSCLEAN:
 397:                           case JANUSORIG:
 398:                           case ODPOTHER5:
 399:                             (void)fprintf(fptr,"%d\t%c\t%d\t%c\t%s\t%.1f\t%.2f\t%.3f\t%.3f\t%.2f\t%.2f",
 400:                                         data[dset]->site,holeptr->name,coreptr->num,valueptr->type,valueptr->section,valueptr->top_int,
 401:                                         valueptr->sb_depth, spcomp.var[i][j], smvar,
 402:                                         spcomp.Depthoffset[i], spcomp.sb_depth[i][j]);
 403:                             break;
 404:                         }
 405:                         if(writeage == YES) 
 406:                         {
 407:                            (void)fprintf(fptr,"\t%.3f\t%.2f\n", spcomp.age[i][j], spcomp.sedrate[i][j]);
 408:                         }
 409:                         else
 410:                         {
 411:                            (void)fprintf(fptr,"\n");
 412:                         }
 413:                     }
 414:                     else
 415:                     {
 416:                     }
 417:                   }
 418:                 }
 419:   }
 420: 
 421:         if(io_wait_cursor) {
 422:           XUndefineCursor(XtDisplay(formFileSelection), XtWindow(formFileSelection));
 423:           XFreeCursor(XtDisplay(formFileSelection), io_wait_cursor);
 424:         }
 425:         fclose(fptr);
 426:   return(True);
 427: }
 428:     
 429: 
 430: int SpReadTKreport(fptr,dataptr)
 431: FILE  *fptr;
 432: DataFile  *dataptr;
 433: {
 434:   int core_num,this_hole,this_core,max_alloc,i,status;
 435:         float   dum;
 436:   Hole  *holeptr;
 437:   Core  *coreptr;
 438:   Value *valueptr;
 439:   char  hole_name;
 440: 
 441:   /*return False=more data, true=done */
 442:   dataptr->subleg=' ';
 443:   if((status=fscanf(fptr,"%d %d %c %d",&dataptr->leg,&dataptr->site,&hole_name,&core_num))!=4)
 444:   {
 445:     if(status==EOF)
 446:       return(True);
 447:     else
 448:     {
 449:       dataptr->readerrors++;
 450:       return(False);
 451:     }
 452:   }
 453:   else
 454:   {
 455:          
 456:   /* check if new hole */
 457:     hole_name=toupper(hole_name);
 458:     if(dataptr->holes_used==NULL || strchr(dataptr->holes_used,hole_name)==NULL)
 459:     {
 460:       dataptr->numholes++;
 461:       if(dataptr->numholes >1)  /* not first hole */
 462:       {
 463:         if((charptr=(char*)realloc(dataptr->holes_used,(dataptr->numholes+1)*CHAR_SIZE))==NULL)
 464:           SpBadMemAlloc("SpReadTKreport 2");
 465:         else
 466:           dataptr->holes_used = charptr;
 467:         if((charptr=(char*)realloc((char*)dataptr->holes,dataptr->numholes*sizeof(Hole*)))==NULL)
 468:           SpBadMemAlloc("SpReadTKreport 3");
 469:         else
 470:           dataptr->holes=(Hole**)charptr;
 471:       }
 472:       else    /* first hole */
 473:       {
 474:         if((dataptr->holes_used=(char*)calloc(2,sizeof(char)))==NULL)
 475:           SpBadMemAlloc("SpReadTKreport 4");
 476:         dataptr->holes_used[0]='\0';
 477:         if((dataptr->holes=(Hole**)calloc(dataptr->numholes,sizeof(Hole*)))==NULL)
 478:           SpBadMemAlloc("SpReadTKreport 5");
 479:       }
 480:       /* set hole values */
 481:       if((dataptr->holes[dataptr->numholes-1]=(Hole*)calloc(1,sizeof(Hole)))==NULL)
 482:         SpBadMemAlloc("SpReadTKreport 6");
 483:       this_hole=dataptr->numholes-1;
 484:       holeptr=dataptr->holes[this_hole];
 485:       holeptr->name=hole_name;
 486:       (void)sprintf(dataptr->holes_used,"%s%c",dataptr->holes_used,hole_name);
 487:       holeptr->numcores=0;
 488:     }
 489:     else  /* hole already exists */
 490:       for(this_hole=0;this_hole<dataptr->numholes && 
 491:           dataptr->holes[this_hole]->name!=hole_name;this_hole++);
 492:     holeptr=dataptr->holes[this_hole];
 493:     /* check if new core*/
 494:     for(this_core=0;this_core<holeptr->numcores && core_num != holeptr->core[this_core]->num;this_core++);
 495:     if(this_core >= holeptr->numcores)
 496:     {
 497:       if(holeptr->numcores++>0) /* not first core*/
 498:       {
 499:         if((charptr=(char*)realloc((char*)holeptr->core,holeptr->numcores*sizeof(Core*)))==NULL)
 500:           SpBadMemAlloc("SpReadTKreport 7");
 501:         else
 502:           holeptr->core=(Core**)charptr;
 503:       }
 504:       else    /* firstcore */
 505:       {
 506:         if((holeptr->core=(Core**)calloc(holeptr->numcores,sizeof(Core*)))==NULL)
 507:           SpBadMemAlloc("SpReadTKreport 8");
 508:       }
 509:       /* set core values */
 510:       if((holeptr->core[this_core]=(Core*)calloc(1,sizeof(Core)))==NULL)
 511:         SpBadMemAlloc("SpReadTKreport 9");
 512:       coreptr=holeptr->core[this_core];
 513:       coreptr->num=core_num;
 514:       coreptr->numvalues=0;
 515:       if((coreptr->value=(Value**)calloc(ALLOC_INT,sizeof(Value*)))==NULL)
 516:         SpBadMemAlloc("SpReadTKreport 10");
 517:       for(coreptr->allocvalues=0;coreptr->allocvalues<ALLOC_INT;coreptr->allocvalues++)
 518:       {
 519:         if((coreptr->value[coreptr->allocvalues]=(Value*)calloc(1,sizeof(Value)))==NULL)
 520:           SpBadMemAlloc("SpReadTKreport 11");
 521:       }
 522:     }
 523:     coreptr=holeptr->core[this_core];
 524:     coreptr->cum_dep_offset=0.0;
 525:     coreptr->did_offset=False;
 526:     if(coreptr->numvalues++ >= coreptr->allocvalues)
 527:     {
 528:       max_alloc=coreptr->allocvalues+ALLOC_INT;
 529:       if((charptr=(char*)realloc((char*)coreptr->value,max_alloc*sizeof(Value*)))==NULL)
 530:         SpBadMemAlloc("SpReadTKreport 12");
 531:       else
 532:         coreptr->value=(Value**) charptr;
 533:       for(;coreptr->allocvalues<max_alloc;coreptr->allocvalues++)
 534:       {
 535:         if((coreptr->value[coreptr->allocvalues]=(Value*)calloc(1,sizeof(Value)))==NULL)
 536:           SpBadMemAlloc("SpReadTKreport 13");
 537:       }
 538:     }
 539:     valueptr=coreptr->value[coreptr->numvalues-1];
 540:   /* get standard core values */
 541:     while((valueptr->type=fgetc(fptr))!=EOF && isspace(valueptr->type));
 542:     if(valueptr->type==EOF)
 543:       return(True);
 544:     else
 545:       valueptr->type=toupper(valueptr->type);
 546:     while((valueptr->section[0]=fgetc(fptr))!=EOF && isspace(valueptr->section[0]));
 547:     if(valueptr->section[0]==EOF)
 548:       return(True);
 549:     else
 550:       valueptr->section[0]=toupper(valueptr->section[0]);
 551:     valueptr->section[1]=fgetc(fptr);
 552:     if(isspace(valueptr->section[1]))
 553:       valueptr->section[1]='\0';
 554:     else
 555:       valueptr->section[1]=toupper(valueptr->section[1]);
 556:     valueptr->section[1]='\0';
 557:     if((status=fscanf(fptr,"%f %f %f",&valueptr->top_int,&valueptr->bot_int,&valueptr->sb_depth))!=3)
 558:     {
 559:       if(status==EOF)
 560:         return(True);
 561:       else
 562:       {
 563:         dataptr->readerrors++;
 564:         return(False);
 565:       }
 566:     }
 567:                 if(fabs(valueptr->sb_depth - BAD_CODE) <= ROUNDCHECK) {
 568:                   valueptr->quality=BAD_SB_DEPTH;
 569:                 }
 570:                 else {
 571:         valueptr->quality=GOOD;
 572:                 }
 573:     valueptr->run_num=0;
 574:   /* get type specific values */
 575:     switch (dataptr->type)
 576:     {
 577:       case GRAPE:
 578:         if((valueptr->grape=(Grapedata*)calloc(1,sizeof(Grapedata)))==NULL)
 579:           SpBadMemAlloc("SpReadTKreport 15");
 580:         if((status=fscanf(fptr,"%f",&valueptr->grape->density)) != 1)
 581:         {
 582:           if(status==EOF)
 583:             return(True);
 584:           else
 585:           {
 586:             dataptr->readerrors++;
 587:             message.error=True;
 588:           }
 589:         }
 590:         else
 591:         {
 592:                                         valueptr->data=&valueptr->grape->density;
 593:           valueptr->grape->gamma_counts=0;
 594:                                         valueptr->grape->b_corr_density = 0.0;
 595:         }
 596:         break;
 597:       case SUSCEPTIBILITY:
 598:         if((valueptr->susceptibility=(Susceptibility*)calloc(1,sizeof(Susceptibility)))==NULL)
 599:           SpBadMemAlloc("SpReadTKreport 16");
 600:         if((status=fscanf(fptr,"%f",&valueptr->susceptibility->corrected)) !=1)
 601:         {
 602:           if(status==EOF)
 603:             return(True);
 604:           else
 605:           {
 606:             dataptr->readerrors++;
 607:             message.error=True;
 608:           }
 609:         }
 610:         else
 611:         {
 612:           valueptr->susceptibility->observed=0.0;
 613:           valueptr->data=&valueptr->susceptibility->corrected;
 614:         }
 615:         break;
 616:       case PWAVE:
 617:         if((valueptr->pwave=(Pwavedata*)calloc(1,sizeof(Pwavedata)))==NULL)
 618:           SpBadMemAlloc("SpReadTKreport 17");
 619:         if((status=fscanf(fptr,"%f",&valueptr->pwave->velocity)) !=1)
 620:         {
 621:           if(status==EOF)
 622:             return(True);
 623:           else
 624:           {
 625:             dataptr->readerrors++;
 626:             message.error=True;
 627:           }
 628:         }
 629:         else
 630:         {
 631:           valueptr->pwave->sig_strength=0;
 632:           valueptr->pwave->travel_time=0;
 633:           valueptr->pwave->displacement=0;
 634:           valueptr->data=&valueptr->pwave->velocity;
 635:         }
 636:         break;
 637:       case NATURALGAMMA:
 638:                                 if((valueptr->naturalgamma=(Natgammadata*)calloc(1,sizeof(Natgammadata)))==NULL)
 639:                                         SpBadMemAlloc("SpReadTKreport 18");
 640:                                 if((status=fscanf(fptr,"%f %d %f %f %f %f %f %d",&valueptr->naturalgamma->total_cnt,
 641:             &valueptr->naturalgamma->sample_time,
 642:             &valueptr->naturalgamma->seg1_cnt,&valueptr->naturalgamma->seg2_cnt,
 643:             &valueptr->naturalgamma->seg3_cnt,&valueptr->naturalgamma->seg4_cnt,
 644:             &valueptr->naturalgamma->seg5_cnt,&valueptr->run_num))!=8)
 645:                                 {
 646:           if(status==EOF)
 647:             return(True);
 648:           else
 649:           {
 650:                                           dataptr->readerrors++;
 651:                                           message.error=True;
 652:           }
 653:                                 }
 654:                                 else
 655:                                 {
 656:                                         valueptr->data=&valueptr->naturalgamma->total_cnt;
 657:                                 }
 658:                                 break;
 659:       case REFLECTANCEMST:
 660:         if((valueptr->reflectanceMST=(ReflectanceMST*)calloc(1,sizeof(ReflectanceMST)))==NULL)
 661:           SpBadMemAlloc("SpReadTKreport 19");
 662:         for(i=0;i<31;i++)
 663:           valueptr->reflectanceMST->nm_value[i]=0.0;
 664:         if((status=fscanf(fptr,"%f",&valueptr->reflectanceMST->nm_value[15]))!=1)
 665:         {
 666:           if(status==EOF)
 667:             return(True);
 668:           else
 669:           {
 670:             dataptr->readerrors++;
 671:             message.error=True;
 672:           }
 673:         }
 674:         else
 675:         {
 676:           valueptr->reflectanceMST->L=0.0;
 677:           valueptr->reflectanceMST->a=0.0;
 678:           valueptr->reflectanceMST->b=0.0;
 679:           valueptr->reflectanceMST->munsell_hue[0]='\0';
 680:           valueptr->reflectanceMST->munsell_value[0]='\0';
 681:           valueptr->data=&valueptr->reflectanceMST->nm_value[15];
 682:         }
 683:         break;
 684:                         case OTHERTYPE:
 685:                                 break;
 686:       default:
 687:         dataptr->readerrors++;
 688:         message.error=True;
 689:     }
 690:     if(message.error==True)
 691:     {
 692:       message.fatal=False;
 693:       message.default_button=XmDIALOG_OK_BUTTON;
 694:       message.type=XmDIALOG_ERROR;
 695:       message.caller=SPREADTKREPORT;
 696:       if((message.label=(char*)calloc(500+(int)strlen(format[dataptr->in_format])+
 697:                                           (int)strlen(type[dataptr->type]),CHAR_SIZE))==NULL)
 698:         SpBadMemAlloc("SpReadTKreport 15");
 699:       (void)sprintf(message.label,"Invalid TK format and/or %s type at %c  %d  %s  %6.1f %6.1f %8.2f",
 700:                                               type[dataptr->type], holeptr->name, coreptr->num, valueptr->section,
 701:                                               valueptr->top_int, valueptr->bot_int, valueptr->sb_depth);
 702:       SpManageMessage(message);
 703:     }
 704:     else
 705:       valueptr->sm_data=*valueptr->data;
 706:   }
 707:   return(False);
 708: }
 709: int SpReadOtherOdp(fptr,dataptr)
 710: FILE  *fptr;
 711: DataFile  *dataptr;
 712: {
 713:   char  hole_name;
 714:   int core_num,status,this_hole,this_core,max_alloc;
 715:   Value tmp_value,*valueptr;
 716:   Core  *coreptr;
 717:   Hole  *holeptr;
 718: 
 719:   /*return False=more data, true=done */
 720: /* read data line */
 721:   if(fgets(line,1000,fptr)==NULL)
 722:     return(True);
 723: /* get variables */
 724:   dataptr->subleg=' ';
 725:   switch (dataptr->in_format)
 726:   {
 727:     case  ODPOTHER1:
 728:       if((status=sscanf(line,openfileinfo.other_format,&dataptr->leg,
 729:           &dataptr->site,&hole_name,&core_num,&tmp_value.type,
 730:           tmp_value.section,&tmp_value.top_int,&tmp_value.bot_int,
 731:           &tmp_value.sb_depth,&tmp_value.otherodp))!=10)
 732:       {
 733:         if(status==EOF)
 734:           return(True);
 735:         else
 736:           message.error=True;
 737:       }
 738:       break;
 739:     case  ODPOTHER2:
 740:       dataptr->leg=0;
 741:       if((status=sscanf(line,openfileinfo.other_format,
 742:           &dataptr->site,&hole_name,&core_num,&tmp_value.type,
 743:           tmp_value.section,&tmp_value.top_int,&tmp_value.bot_int,
 744:           &tmp_value.sb_depth,&tmp_value.otherodp))!=9)
 745:       {
 746:         if(status==EOF)
 747:           return(True);
 748:         else
 749:           message.error=True;
 750:       }
 751:       break;
 752:     case  ODPOTHER3:
 753:       dataptr->leg=0;
 754:                         tmp_value.type = '?';
 755:       if((status=sscanf(line,openfileinfo.other_format, &dataptr->site,&hole_name,&core_num,
 756:           tmp_value.section,&tmp_value.top_int,&tmp_value.bot_int,
 757:           &tmp_value.sb_depth,&tmp_value.otherodp))!=8)
 758:       {
 759:         if(status==EOF)
 760:           return(True);
 761:         else
 762:           message.error=True;
 763:       }
 764:       break;
 765:     case  ODPOTHER4:
 766:       dataptr->leg=0;
 767:                         tmp_value.type = '?';
 768:       if((status=sscanf(line,openfileinfo.other_format, &dataptr->site,&hole_name,&core_num,
 769:           tmp_value.section,&tmp_value.top_int,
 770:           &tmp_value.sb_depth,&tmp_value.otherodp))!=7)
 771:       {
 772:         if(status==EOF)
 773:           return(True);
 774:         else
 775:           message.error=True;
 776:       }
 777:       tmp_value.bot_int=tmp_value.top_int;
 778:       break;
 779:                 case    ODPOTHER5:
 780:                         if((status=sscanf(line,openfileinfo.other_format,&dataptr->leg,
 781:                                         &dataptr->site,&hole_name,&core_num,&tmp_value.type,
 782:                                         tmp_value.section,&tmp_value.top_int,
 783:                                         &tmp_value.sb_depth,&tmp_value.otherodp))!=9)
 784:                         {
 785:                                 if(status==EOF)
 786:                                         return(True);
 787:                                 else
 788:                                         message.error=True;
 789:                         }
 790:                         tmp_value.bot_int=tmp_value.top_int;
 791:                         break;
 792:     default:
 793:       message.fatal=False;
 794:       message.default_button=XmDIALOG_OK_BUTTON;
 795:       message.type=XmDIALOG_ERROR;
 796:       message.caller=SPREADOTHERODP;
 797:       if((message.label=(char*)calloc(100,CHAR_SIZE))==NULL)
 798:         SpBadMemAlloc("SpReadOtherOdp 1");
 799:       (void)sprintf(message.label,"Invalid other odp data type %d",dataptr->type);
 800:       SpManageMessage(message);
 801:       return(False);
 802:   }
 803:   if(message.error)
 804:   {
 805:     message.fatal=False;
 806:     message.default_button=XmDIALOG_OK_BUTTON;
 807:     message.type=XmDIALOG_ERROR;
 808:     message.caller=SPREADOTHERODP;
 809:     if((message.label=(char*)calloc(50+(int)strlen(type[dataptr->type])+
 810:           (int)strlen(format[dataptr->in_format]) + (int)strlen(line),CHAR_SIZE))==NULL)
 811:       SpBadMemAlloc("SpReadOtherOdp 2");
 812:     (void)sprintf(message.label,"Bad %s %s at line\n %s",format[dataptr->in_format],type[dataptr->type], line);
 813:     SpManageMessage(message);
 814:     return(False);
 815:   }
 816: 
 817:   /* check if new hole */
 818:   hole_name=toupper(hole_name);
 819:   if(dataptr->holes_used==NULL || strchr(dataptr->holes_used,hole_name)==NULL)
 820:   {
 821:     dataptr->numholes++;
 822:     if(dataptr->numholes >1)  /* not first hole */
 823:     {
 824:       if((charptr=(char*)realloc(dataptr->holes_used,(dataptr->numholes+1)*CHAR_SIZE))==NULL)
 825:         SpBadMemAlloc("SpReadOtherOdp 3");
 826:       else
 827:         dataptr->holes_used = charptr;
 828:       if((charptr=(char*)realloc((char*)dataptr->holes,dataptr->numholes*sizeof(Hole*)))==NULL)
 829:         SpBadMemAlloc("SpReadOtherOdp 4");
 830:       else
 831:         dataptr->holes=(Hole**)charptr;
 832:     }
 833:     else    /* first hole */
 834:     {
 835:       if((dataptr->holes_used=(char*)calloc(2,sizeof(char)))==NULL)
 836:         SpBadMemAlloc("SpReadOtherOdp 5");
 837:       dataptr->holes_used[0]='\0';
 838:       if((dataptr->holes=(Hole**)calloc(dataptr->numholes,sizeof(Hole*)))==NULL)
 839:         SpBadMemAlloc("SpReadOtherOdp 6");
 840:     }
 841:     /* set hole values */
 842:     if((dataptr->holes[dataptr->numholes-1]=(Hole*)calloc(1,sizeof(Hole)))==NULL)
 843:       SpBadMemAlloc("SpReadOtherOdp 7");
 844:     this_hole=dataptr->numholes-1;
 845:     holeptr=dataptr->holes[this_hole];
 846:     holeptr->name=hole_name;
 847:     (void)sprintf(dataptr->holes_used,"%s%c",dataptr->holes_used,hole_name);
 848:     holeptr->numcores=0;
 849:   }
 850:   else  /* hole already exists */
 851:   {
 852:     for(this_hole=0;this_hole<dataptr->numholes && 
 853:         dataptr->holes[this_hole]->name!=hole_name;this_hole++);
 854:   }
 855:   holeptr=dataptr->holes[this_hole];
 856:   /* check if new core*/
 857:   for(this_core=0;this_core<holeptr->numcores && core_num != holeptr->core[this_core]->num;this_core++);
 858:   if(this_core >= holeptr->numcores)
 859:   {
 860:     if(holeptr->numcores++>0) /* not first core*/
 861:     {
 862:       if((charptr=(char*)realloc((char*)holeptr->core,holeptr->numcores*sizeof(Core*)))==NULL)
 863:         SpBadMemAlloc("SpReadOtherOdp 8");
 864:       else
 865:         holeptr->core=(Core**)charptr;
 866:     }
 867:     else    /* firstcore */
 868:     {
 869:       if((holeptr->core=(Core**)calloc(holeptr->numcores,sizeof(Core*)))==NULL)
 870:         SpBadMemAlloc("SpReadOtherOdp 9");
 871:     }
 872:     /* set core values */
 873:     if((holeptr->core[this_core]=(Core*)calloc(1,sizeof(Core)))==NULL)
 874:       SpBadMemAlloc("SpReadOtherOdp 10");
 875:     coreptr=holeptr->core[this_core];
 876:     coreptr->num=core_num;
 877:     coreptr->numvalues=0;
 878:     if((coreptr->value=(Value**)calloc(ALLOC_INT,sizeof(Value*)))==NULL)
 879:       SpBadMemAlloc("SpReadOtherOdp 11");
 880:     for(coreptr->allocvalues=0;coreptr->allocvalues<ALLOC_INT;coreptr->allocvalues++)
 881:     {
 882:       if((coreptr->value[coreptr->allocvalues]=(Value*)calloc(1,sizeof(Value)))==NULL)
 883:         SpBadMemAlloc("SpReadOtherOdp 12");
 884:     }
 885:   }
 886:   coreptr=holeptr->core[this_core];
 887:   coreptr->cum_dep_offset=0.0;
 888:   coreptr->did_offset=False;
 889:   if(coreptr->numvalues++ >= coreptr->allocvalues)
 890:   {
 891:     max_alloc=coreptr->allocvalues+ALLOC_INT;
 892:     if((charptr=(char*)realloc((char*)coreptr->value,max_alloc*sizeof(Value*)))==NULL)
 893:       SpBadMemAlloc("SpReadOtherOdp 13");
 894:     else
 895:       coreptr->value=(Value**) charptr;
 896:     for(;coreptr->allocvalues<max_alloc;coreptr->allocvalues++)
 897:     {
 898:       if((coreptr->value[coreptr->allocvalues]=(Value*)calloc(1,sizeof(Value)))==NULL)
 899:         SpBadMemAlloc("SpReadOtherOdp 14");
 900:     }
 901:   }
 902:   valueptr=coreptr->value[coreptr->numvalues-1];
 903: /* get standard core values */
 904:   valueptr->type=tmp_value.type;
 905:   (void)strcpy(valueptr->section,tmp_value.section);
 906:   valueptr->top_int=tmp_value.top_int;
 907:   valueptr->bot_int=tmp_value.bot_int;
 908:   valueptr->sb_depth=tmp_value.sb_depth;
 909:   valueptr->otherodp=tmp_value.otherodp;
 910:         if(fabs(valueptr->sb_depth - BAD_CODE) <= ROUNDCHECK) {
 911:           valueptr->quality=BAD_SB_DEPTH;
 912:         }
 913:         else {
 914:     valueptr->quality=GOOD;
 915:         }
 916:   valueptr->run_num=0;
 917:   valueptr->data=&valueptr->otherodp;
 918:   valueptr->sm_data=*valueptr->data;
 919:   return(False);
 920: 
 921: }
 922: 
 923: int SpReadMST95report(fptr,dataptr)
 924: FILE  *fptr;
 925: DataFile  *dataptr;
 926: {
 927: /* return False=more data, true=done */
 928:   char  c_value[20];
 929:   int core,this_hole,this_core,max_alloc,nm_num,pos;
 930:   Hole  *holeptr;
 931:   Core  *coreptr;
 932:   Value *valueptr;
 933:   int i,len;
 934: 
 935: /* read one data line */
 936:   if(fgets(line,MAXLINE,fptr)!=NULL)
 937:   {
 938:   /* get rid of ending blanks */
 939:     len=(int)strlen(line);
 940:     for(i=len-1;i>0 && isspace(line[i]);i--)
 941:       line[i]='\0';
 942:     len=(int)strlen(line);
 943:   /* get  standard header information */
 944:     (void)strncpy(c_value,&line[1],3); c_value[3]='\0';
 945:     dataptr->leg=atol(c_value);
 946:     dataptr->subleg = line[5];
 947:     (void)strncpy(c_value,&line[7],4); c_value[4]='\0';
 948:     dataptr->site= atol(c_value);
 949: 
 950:     /* check if new hole */
 951:     if(dataptr->holes_used==NULL || strchr(dataptr->holes_used,line[12])==NULL)
 952:     {
 953:       dataptr->numholes++;
 954:       if(line[12]==' ') /* no hole given, ignore line */
 955:       {
 956:         dataptr->readerrors++;
 957:         return(False);
 958:       }
 959:       if(dataptr->numholes >1)  /* not first hole */
 960:       {
 961:         if((charptr=(char*)realloc(dataptr->holes_used,(dataptr->numholes+1)*CHAR_SIZE))==NULL)
 962:           SpBadMemAlloc("SpReadMST95report 1");
 963:         else
 964:           dataptr->holes_used = charptr;
 965:         if((charptr=(char*)realloc((char*)dataptr->holes,dataptr->numholes*sizeof(Hole*)))==NULL)
 966:           SpBadMemAlloc("SpReadMST95report 2");
 967:         else
 968:           dataptr->holes=(Hole**)charptr;
 969:       }
 970:       else    /* first hole */
 971:       {
 972:         if((dataptr->holes_used=(char*)calloc(2,sizeof(char)))==NULL)
 973:           SpBadMemAlloc("SpReadMST95report 3");
 974:         dataptr->holes_used[0]='\0';
 975:         if((dataptr->holes=(Hole**)calloc(dataptr->numholes,sizeof(Hole*)))==NULL)
 976:           SpBadMemAlloc("SpReadMST95report 4");
 977:       }
 978:       /* set hole values */
 979:       if((dataptr->holes[dataptr->numholes-1]=(Hole*)calloc(1,sizeof(Hole)))==NULL)
 980:         SpBadMemAlloc("SpReadMST95report 5");
 981:       this_hole=dataptr->numholes-1;
 982:       holeptr=dataptr->holes[this_hole];
 983:       holeptr->name=toupper(line[12]);
 984:       (void)sprintf(dataptr->holes_used,"%s%c",dataptr->holes_used,line[12]);
 985:       holeptr->numcores=0;
 986:     }
 987:     else  /* hole already exists */
 988:       for(this_hole=0;this_hole<dataptr->numholes && 
 989:           dataptr->holes[this_hole]->name!=line[12];this_hole++);
 990:     holeptr=dataptr->holes[this_hole];
 991:     /* get core value */
 992:     (void)strncpy(c_value,&line[14],3); c_value[3]='\0';
 993:     core=atol(c_value);
 994:     /* check if new core*/
 995:     for(this_core=0;this_core<holeptr->numcores && core != holeptr->core[this_core]->num;this_core++);
 996:     if(this_core >= holeptr->numcores)
 997:     {
 998:       if(holeptr->numcores++>0) /* not first core*/
 999:       {
1000:         if((charptr=(char*)realloc((char*)holeptr->core,holeptr->numcores*sizeof(Core*)))==NULL)
1001:           SpBadMemAlloc("SpReadMST95report 6");
1002:         else
1003:           holeptr->core=(Core**)charptr;
1004:       }
1005:       else    /* firstcore */
1006:       {
1007:         if((holeptr->core=(Core**)malloc(holeptr->numcores*sizeof(Core*)))==NULL)
1008:           SpBadMemAlloc("SpReadMST95report 7");
1009:       }
1010:       /* set core values */
1011:       if((holeptr->core[this_core]=(Core*)calloc(1,sizeof(Core)))==NULL)
1012:         SpBadMemAlloc("SpReadMST95report 8");
1013:       coreptr=holeptr->core[this_core];
1014:       coreptr->num=core;
1015:       coreptr->numvalues=0;
1016:       if((coreptr->value=(Value**)calloc(ALLOC_INT,sizeof(Value*)))==NULL)
1017:         SpBadMemAlloc("SpReadMST95report 9");
1018:       for(coreptr->allocvalues=0;coreptr->allocvalues<ALLOC_INT;coreptr->allocvalues++)
1019:       {
1020:         if((coreptr->value[coreptr->allocvalues]=(Value*)calloc(1,sizeof(Value)))==NULL)
1021:           SpBadMemAlloc("SpReadMST95report 10");
1022:       }
1023:     }
1024:     coreptr=holeptr->core[this_core];
1025:     coreptr->cum_dep_offset=0.0;
1026:     coreptr->did_offset=False;
1027:     if(coreptr->numvalues++ >= coreptr->allocvalues)
1028:     {
1029:       max_alloc=coreptr->allocvalues+ALLOC_INT;
1030:       if((charptr=(char*)realloc((char*)coreptr->value,max_alloc*sizeof(Value*)))==NULL)
1031:         SpBadMemAlloc("SpReadMST95report 11");
1032:       else
1033:         coreptr->value=(Value**) charptr;
1034:       for(;coreptr->allocvalues<max_alloc;coreptr->allocvalues++)
1035:       {
1036:         if((coreptr->value[coreptr->allocvalues]=(Value*)calloc(1,sizeof(Value)))==NULL)
1037:           SpBadMemAlloc("SpReadMST95report 12");
1038:       }
1039:     }
1040:     valueptr=coreptr->value[coreptr->numvalues-1];
1041:   /* get standard core values */
1042:     valueptr->type=line[18];
1043:     valueptr->type=toupper(valueptr->type);
1044:     if(isspace(line[20]))
1045:     {
1046:       (void)strncpy(valueptr->section,&line[21],1);
1047:       valueptr->section[1]='\0';
1048:     }
1049:     else
1050:       (void)strncpy(valueptr->section,&line[20],2);
1051:     valueptr->section[2]='\0';
1052:     for(i=0;i<(int)strlen(valueptr->section);i++)
1053:     {
1054:       if(isalpha(valueptr->section[i]))
1055:         valueptr->section[i]=toupper(valueptr->section[i]);
1056:     }
1057:     (void)strncpy(c_value,&line[23],5); c_value[5]='\0';
1058:     valueptr->top_int=(float)atof(c_value);
1059:     (void)strncpy(c_value,&line[29],5); c_value[5]='\0';
1060:     valueptr->bot_int=(float)atof(c_value);
1061:     (void)strncpy(c_value,&line[35],7); c_value[7]='\0';
1062:     valueptr->sb_depth=(float)atof(c_value);
1063:                 if(fabs(valueptr->sb_depth - BAD_CODE) <= ROUNDCHECK) {
1064:                   valueptr->quality=BAD_SB_DEPTH;
1065:                 }
1066:                 else {
1067:       valueptr->quality=GOOD;
1068:                 }
1069:   /* get data type specific values */
1070:     if(dataptr->type==GRAPE)
1071:     {
1072:       if(len!=72)
1073:       {
1074:         coreptr->numvalues--;
1075:         message.error=True;
1076:         message.fatal=False;
1077:         message.caller=SPREADMST95REPORT;
1078:         message.type=XmDIALOG_WARNING;
1079:         message.default_button=XmDIALOG_OK_BUTTON;
1080:         if((message.label=(char*)calloc(500,CHAR_SIZE))==NULL)
1081:           SpBadMemAlloc("SpReadMST95report 13");
1082:         (void)sprintf(message.label,"Invalid Grape and/or MST95 format at. %c  %d  %s  %6.1f %6.1f %8.2f",
1083:                                               holeptr->name, coreptr->num, valueptr->section, 
1084:                                               valueptr->top_int, valueptr->bot_int, valueptr->sb_depth);
1085:         return(False);
1086:       }
1087:       if((valueptr->grape=(Grapedata*)calloc(1,sizeof(Grapedata)))==NULL)
1088:         SpBadMemAlloc("SpReadMST95report 14");
1089:       (void)strncpy(c_value,&line[46],5);c_value[5]='\0';
1090:       valueptr->grape->density=(float)atof(c_value);
1091:       valueptr->data=&valueptr->grape->density;
1092:       valueptr->sm_data=valueptr->grape->density;
1093:       (void)strncpy(c_value,&line[54],5);c_value[5]='\0';
1094:       valueptr->grape->b_corr_density=(float)atof(c_value);
1095:       (void)strncpy(c_value,&line[62],5);c_value[5]='\0';
1096:       valueptr->grape->gamma_counts=atol(c_value);
1097:       (void)strncpy(c_value,&line[68],4);c_value[4]='\0';
1098:       valueptr->run_num=atol(c_value);
1099:     } 
1100:     else if (dataptr->type==PWAVE)
1101:     {
1102:       if(len!=82)
1103:       {
1104:                                 coreptr->numvalues--;
1105:                                 message.error=True;
1106:                                 message.fatal=False; 
1107:                                 message.caller=SPREADMST95REPORT;
1108:                                 message.type=XmDIALOG_WARNING; 
1109:                                 message.default_button=XmDIALOG_OK_BUTTON; 
1110:                                 if((message.label=(char*)calloc(500,CHAR_SIZE))==NULL)
1111:                                         SpBadMemAlloc("SpReadMST95report 15");
1112:         (void)sprintf(message.label,"Invalid Pwave and/or MST95 format at. %c  %d  %s  %6.1f %6.1f %8.2f",
1113:                                                holeptr->name, coreptr->num, valueptr->section, valueptr->top_int, valueptr->bot_int,
1114:                                                valueptr->sb_depth);
1115:         return(False);
1116:       }
1117:       if((valueptr->pwave=(Pwavedata*)calloc(1,sizeof(Pwavedata)))==NULL)
1118:         SpBadMemAlloc("SpReadMST95report 16");
1119:       (void)strncpy(c_value,&line[44],7); c_value[7]='\0';
1120:       valueptr->pwave->velocity=(float)atof(c_value);
1121:       valueptr->data=&valueptr->pwave->velocity;
1122:       valueptr->sm_data=valueptr->pwave->velocity;
1123:       (void)strncpy(c_value,&line[51],4); c_value[4]='\0';
1124:       valueptr->pwave->sig_strength=atol(c_value);
1125:       (void)strncpy(c_value,&line[56],4); c_value[4]='\0';
1126:       valueptr->pwave->travel_time=atol(c_value);
1127:       (void)strncpy(c_value,&line[71],5); c_value[5]='\0';
1128:       valueptr->pwave->displacement=atol(c_value);
1129:       (void)strncpy(c_value,&line[78],4); c_value[4]='\0';
1130:       valueptr->run_num=atol(c_value);
1131:     }
1132:     else if (dataptr->type==NATURALGAMMA)
1133:     {
1134:       if(len!=92)
1135:       {
1136:                                 coreptr->numvalues--;
1137:                                 message.error=True; 
1138:                                 message.fatal=False;  
1139:                                 message.caller=SPREADMST95REPORT; 
1140:                                 message.type=XmDIALOG_WARNING;  
1141:                                 message.default_button=XmDIALOG_OK_BUTTON;  
1142:                                 if((message.label=(char*)calloc(500,CHAR_SIZE))==NULL)
1143:                                         SpBadMemAlloc("SpReadMST95report 17");
1144:         (void)sprintf(message.label,"Invalid Natural Gamma and/or MST95 format at. %c  %d  %s  %6.1f %6.1f %8.2f",
1145:                                                holeptr->name, coreptr->num, valueptr->section, valueptr->top_int, valueptr->bot_int,
1146:                                                valueptr->sb_depth);
1147:         return(False);
1148:       }
1149:       if((valueptr->naturalgamma=(Natgammadata*)calloc(1,sizeof(Natgammadata)))==NULL)
1150:                                 SpBadMemAlloc("SpReadMST95report 18");
1151:       (void)strncpy(c_value,&line[44],8); c_value[8]='\0';
1152:       valueptr->naturalgamma->total_cnt=(float)atol(c_value);
1153:       valueptr->data=&valueptr->naturalgamma->total_cnt;
1154:       valueptr->sm_data=valueptr->naturalgamma->total_cnt;
1155:       (void)strncpy(c_value,&line[52],5); c_value[5]='\0';
1156:       valueptr->naturalgamma->sample_time=atol(c_value);
1157:       (void)strncpy(c_value,&line[58],5); c_value[5]='\0';
1158:       valueptr->naturalgamma->seg1_cnt=atof(c_value);
1159:       (void)strncpy(c_value,&line[64],5); c_value[5]='\0';
1160:       valueptr->naturalgamma->seg2_cnt=atof(c_value);
1161:       (void)strncpy(c_value,&line[70],5); c_value[5]='\0';
1162:       valueptr->naturalgamma->seg3_cnt=atof(c_value);
1163:       (void)strncpy(c_value,&line[76],5); c_value[5]='\0';
1164:       valueptr->naturalgamma->seg4_cnt=atof(c_value);
1165:       (void)strncpy(c_value,&line[82],5); c_value[5]='\0';
1166:       valueptr->naturalgamma->seg5_cnt=atof(c_value);
1167:       (void)strncpy(c_value,&line[88],4); c_value[4]='\0';
1168:       valueptr->run_num=atol(c_value);
1169:     }
1170:     else if (dataptr->type==SUSCEPTIBILITY)
1171:     {
1172:       if(len!=63)
1173:       {
1174:                                 coreptr->numvalues--;
1175:                                 message.error=True;  
1176:                                 message.fatal=False;   
1177:                                 message.caller=SPREADMST95REPORT;  
1178:                                 message.type=XmDIALOG_WARNING;   
1179:                                 message.default_button=XmDIALOG_OK_BUTTON;   
1180:                                 if((message.label=(char*)calloc(500,CHAR_SIZE))==NULL) 
1181:                                         SpBadMemAlloc("SpReadMST95report 19");
1182:         (void)sprintf(message.label,"Invalid Magnetic Susceptibility and/or MST95 format at. %c  %d  %s  %6.1f %6.1f %8.2f",
1183:                                                holeptr->name, coreptr->num, valueptr->section, valueptr->top_int, valueptr->bot_int,
1184:                                                valueptr->sb_depth);
1185:         return(False);
1186:       }
1187:       if((valueptr->susceptibility=(Susceptibility*)calloc(1,sizeof(Susceptibility)))==NULL)
1188:                                 SpBadMemAlloc("SpReadMST95report 20");
1189:       (void)strncpy(c_value,&line[44],6); c_value[7]='\0';
1190:       valueptr->susceptibility->observed=(float)atof(c_value);
1191:       (void)strncpy(c_value,&line[50],8); c_value[7]='\0';
1192:       valueptr->susceptibility->corrected=(float)atof(c_value);
1193:       valueptr->data=&valueptr->susceptibility->corrected;
1194:       valueptr->sm_data=valueptr->susceptibility->corrected;
1195:       (void)strncpy(c_value,&line[59],4); c_value[4]='\0';
1196:       valueptr->run_num=atol(c_value);
1197:     }
1198:     else if(dataptr->type==REFLECTANCEMST)
1199:     {
1200:       if(len!=267)
1201:       {
1202:                                 coreptr->numvalues--;
1203:                                 message.error=True;   
1204:                                 message.fatal=False;    
1205:                                 message.caller=SPREADMST95REPORT;   
1206:                                 message.type=XmDIALOG_WARNING;    
1207:                                 message.default_button=XmDIALOG_OK_BUTTON;    
1208:                                 if((message.label=(char*)calloc(500,CHAR_SIZE))==NULL)  
1209:                                         SpBadMemAlloc("SpReadMST95report 21");
1210:         (void)sprintf(message.label,"Invalid Reflectance and/or MST95 format at. %c  %d  %s  %6.1f %6.1f %8.2f",
1211:                                                holeptr->name, coreptr->num, valueptr->section, valueptr->top_int, valueptr->bot_int,
1212:                                                valueptr->sb_depth);
1213:         return(False);
1214:       }
1215:       if((valueptr->reflectanceMST=(ReflectanceMST*)calloc(1,sizeof(ReflectanceMST)))==NULL)
1216:         SpBadMemAlloc("SpReadMST95report 22");
1217:       (void)strncpy(c_value,&line[45],6); c_value[7]='\0';
1218:       valueptr->reflectanceMST->L=(float)atof(c_value);
1219:       (void)strncpy(c_value,&line[52],6); c_value[7]='\0';
1220:       valueptr->reflectanceMST->a=(float)atof(c_value);
1221:       (void)strncpy(c_value,&line[59],6); c_value[7]='\0';
1222:       valueptr->reflectanceMST->b=(float)atof(c_value);
1223:       (void)strncpy(valueptr->reflectanceMST->munsell_hue,&line[66],6);
1224:       (void)strncpy(valueptr->reflectanceMST->munsell_value,&line[73],9);
1225:       pos=81;
1226:       for(nm_num=0;nm_num<31;nm_num++)
1227:       {
1228:         (void)strncpy(c_value,&line[pos],6); c_value[7]='\0';
1229:         valueptr->reflectanceMST->nm_value[nm_num]=(float)atof(c_value);
1230:         pos+=6;
1231:       }
1232:       valueptr->data=&valueptr->reflectanceMST->nm_value[15];
1233:       valueptr->sm_data=valueptr->reflectanceMST->nm_value[15];
1234:       valueptr->run_num=0;
1235:     }
1236:                 else if(dataptr->type==OTHERTYPE) 
1237:                 {
1238: 
1239:                 }
1240:     else
1241:     {       message.error=True;    
1242:                         message.fatal=False;     
1243:                         message.caller=SPREADMST95REPORT;    
1244:                         message.type=XmDIALOG_WARNING;     
1245:                         message.default_button=XmDIALOG_OK_BUTTON;     
1246:                         if((message.label=(char*)calloc(500,CHAR_SIZE))==NULL)   
1247:                           SpBadMemAlloc("SpReadMST95report 21");
1248:       (void)sprintf(message.label,"Invalid data type %d.\n",dataptr->type);
1249:       return(False);
1250:     }
1251:     /* return not end of file */
1252:     return(False);
1253:   }
1254:   else  /* end of file found */
1255:     return(True);
1256: }
1257: 
1258: HashInfo **SpReadAffineTable(filename,num)
1259: char  *filename;
1260: int *num;
1261: {
1262:   FILE  *fptr;
1263:   int i,alloc_num,j, nh, nc,
1264:     hashsize,status;
1265:   HashInfo  **affineinfo;
1266:   float   xvalue,dummy1,dummy2;
1267:   char  did_it;
1268:         void CheckAffineTableOrder(),
1269:              CheckAffineTableMissingHole(),
1270:              MapHoleToAffineTable(),
1271:              CheckAffineTableMissingCore(),
1272:              MapCoreToAffineTable();
1273: 
1274: /* open input affine table */
1275:   if((fptr=fopen(filename,"r"))==NULL)
1276:   {
1277:     message.error=True;
1278:     message.fatal=False;
1279:     message.default_button=XmDIALOG_OK_BUTTON;
1280:     message.type=XmDIALOG_ERROR;
1281:     message.caller=SPREADAFFINETABLE;
1282:     if((message.label=(char*)calloc((int)strlen(filename)+50,CHAR_SIZE))==NULL)
1283:       SpBadMemAlloc("SpReadAffineTable 1");
1284:     (void)sprintf(message.label,"error opening affine table %s.",filename);
1285:     SpManageMessage(message);
1286:   }
1287:   else
1288:   {
1289:     message.error=False;
1290:   /* allocate initial array */
1291:     alloc_num=ALLOC_INT;
1292:     if((affineinfo=(HashInfo**)calloc(alloc_num,sizeof(HashInfo*)))==NULL)
1293:       SpBadMemAlloc("SpReadAffineTable 2");
1294:     hashsize=sizeof(HashInfo);
1295:     for(i=0;i<alloc_num;i++)
1296:     {
1297:       if((affineinfo[i]=(HashInfo*)calloc(1,hashsize))==NULL)
1298:         SpBadMemAlloc("SpReadAffineTable 3");
1299:     }
1300:   /* read affine table */
1301:     for(j=0;(status=fscanf(fptr,"%d %d %c %d %c %f %c",&affineinfo[j]->leg,
1302:         &affineinfo[j]->site,&affineinfo[j]->hole,&affineinfo[j]->core,
1303:         &affineinfo[j]->coretype,&xvalue,&did_it))==7;
1304:         j++)
1305:     {
1306:     /* convert data values as needed */
1307:       affineinfo[j]->hole=toupper(affineinfo[j]->hole);
1308:       affineinfo[j]->coretype=toupper(affineinfo[j]->coretype);
1309:       did_it=toupper(did_it);
1310:       affineinfo[j]->value= rint(xvalue*100.0);
1311:       affineinfo[j]->subleg=' ';
1312:       if(did_it=='N')
1313:         affineinfo[j]->value2=False;
1314:       else
1315:         affineinfo[j]->value2=True;
1316:                 /* put values in affine table */ 
1317:                         if(j == 0) {
1318:                           strcpy(affinetable.hole[0].name, &affineinfo[0]->hole);
1319:                           nh = 0;
1320:                           nc = 0;
1321:                           affinetable.numhole = 1;
1322:                           affinetable.hole[0].numcore = 0;
1323:                         }
1324:                         else if(j > 0 && affineinfo[j]->hole != affineinfo[j-1]->hole) {
1325:                           ++nh;
1326:                           ++affinetable.numhole;
1327:                           strcpy(affinetable.hole[nh].name, &affineinfo[j]->hole);
1328:                           nc = 0;
1329:                           affinetable.hole[nh].numcore = 0;
1330:                         }
1331:                         affinetable.hole[nh].core[nc].leg = affineinfo[j]->leg;
1332:                         affinetable.hole[nh].core[nc].site = affineinfo[j]->site;
1333:                         affinetable.hole[nh].core[nc].name = affineinfo[j]->core;
1334:                         strncpy(affinetable.hole[nh].core[nc].type, &affineinfo[j]->coretype, 1);
1335:                         affinetable.hole[nh].core[nc].cum_depth_offset = xvalue;
1336:                         affinetable.hole[nh].core[nc].did_offset = affineinfo[j]->value2;
1337:                         ++nc;
1338:                         ++affinetable.hole[nh].numcore;
1339: 
1340:     /* allocate more memory if necessary */
1341:       if(j+1>=alloc_num)
1342:       {
1343:         alloc_num+=ALLOC_INT;
1344:         if((charptr=(char*)realloc((char*)affineinfo,alloc_num*sizeof(HashInfo*)))==NULL)
1345:           SpBadMemAlloc("SpReadAffineTable 4");
1346:         else
1347:           affineinfo=(HashInfo**)charptr;
1348:         for(i=j+1;i<alloc_num;i++)
1349:         {
1350:           if((affineinfo[i]=(HashInfo*)calloc(1,hashsize))==NULL)
1351:             SpBadMemAlloc("SpReadAffineTable 5");
1352:         }
1353:       }
1354:     }
1355: 
1356:     if(status!=EOF)
1357:     {
1358:       message.error=True;
1359:       message.fatal=False;
1360:       message.default_button=XmDIALOG_OK_BUTTON;
1361:       message.caller=SPREADAFFINETABLE;
1362:       message.type=XmDIALOG_ERROR;
1363:       if((message.label=(char*)calloc((int)strlen(filename)+100,CHAR_SIZE))==NULL)
1364:         SpBadMemAlloc("SpReadAffineTable 6");
1365:       (void)sprintf(message.label,"Error reading affine table %s line %d.",filename,j);
1366:       for(i=0;i<alloc_num;i++)
1367:       {
1368:         if(affineinfo[i])
1369:         {
1370:           free(affineinfo[i]);
1371:           affineinfo[i]=NULL;
1372:         }
1373:       }
1374:       if(affineinfo)
1375:       {
1376:         free(affineinfo);
1377:         affineinfo=NULL;
1378:       }
1379:     }
1380:                 else 
1381:                 {
1382:                   for(i=0; i<dataset_cnt; ++i) {
1383:                     (void)CheckAffineTableOrder(&affinetable);
1384:                     (void)CheckAffineTableMissingHole(&affinetable, i);
1385:                     (void)MapHoleToAffineTable(&affinetable, i);
1386:                     (void)CheckAffineTableMissingCore(&affinetable, i);
1387:                     (void)MapCoreToAffineTable(&affinetable, i);
1388:                   }
1389:                 }
1390: 
1391:     *num=j;
1392:     fclose(fptr);
1393:   }
1394:   return(affineinfo);
1395: }
1396: 
1397: HashInfo **SpReadCullTable(filename,num)
1398: char  *filename;
1399: int *num;
1400: {
1401:   int fdcull,i,alloc_num,j,
1402:     hashsize,status;
1403:   HashInfo  **cullinfo;
1404: 
1405: /* open input cull table */
1406:   if((fdcull=open(filename,O_RDONLY|O_CREAT,0))== -1)
1407:     return((HashInfo**)NULL);
1408:   else
1409:   {
1410:   /* allocate initial array */
1411:     alloc_num=ALLOC_INT;
1412:     if((cullinfo=(HashInfo**)calloc(alloc_num,sizeof(HashInfo*)))==NULL)
1413:       SpBadMemAlloc("SpCullTable 2");
1414:     hashsize=sizeof(HashInfo);
1415:     for(i=0;i<alloc_num;i++)
1416:     {
1417:       if((cullinfo[i]=(HashInfo*)calloc(1,hashsize))==NULL)
1418:         SpBadMemAlloc("SpCullTable 3");
1419:     }
1420:   /* read cull table */
1421:     status=hashsize;
1422:     for(j=0;status==hashsize;j++)
1423:     {
1424:     /* allocate more memory if necessary */
1425:       if(j>=alloc_num)
1426:       {
1427:         alloc_num+=ALLOC_INT;
1428:         if((charptr=(char*)realloc((char*)cullinfo,alloc_num*sizeof(HashInfo*)))==NULL)
1429:           SpBadMemAlloc("SpCullTable 4");
1430:         else
1431:           cullinfo=(HashInfo**)charptr;
1432:         for(i=j;i<alloc_num;i++)
1433:         {
1434:           if((cullinfo[i]=(HashInfo*)calloc(1,hashsize))==NULL)
1435:             SpBadMemAlloc("SpCullTable 5");
1436:         }
1437:       }
1438:       status=read(fdcull,(char *) cullinfo[j],hashsize);
1439:     }
1440:     *num=j-1;
1441:     close(fdcull);
1442:   }
1443:   if(status!=0 || *num == 0)
1444:     return((HashInfo**)NULL);
1445:   else
1446:     return(cullinfo);
1447: }
1448: 
1449: int SpWriteAffineTable(affineptr,filename)
1450: AffineTable     *affineptr;
1451: char    *filename;
1452: {
1453:   FILE  *fptr;
1454:   int i,j;
1455:   char  did_it;
1456: 
1457: 
1458: /* open output affinetable */
1459:   if((fptr=fopen(filename,"w"))==NULL)
1460:   {
1461:     message.error=True;
1462:     message.fatal=False;
1463:     message.caller=SPWRITEAFFINETABLE;
1464:     message.default_button=XmDIALOG_OK_BUTTON;
1465:     message.type=XmDIALOG_ERROR;
1466:     if((message.label=(char*)calloc((int)strlen(filename)+50,CHAR_SIZE))==NULL)
1467:       SpBadMemAlloc("SpWriteAffineTable 1");
1468:     (void)sprintf(message.label,"Error opening affine table %s.",filename);
1469:     SpManageMessage(message);
1470:   }
1471:   else
1472:   {
1473:     message.error=False;
1474:   /* write out file */
1475:     for(i=0;i<affineptr->numhole;i++)
1476:     {
1477:       for(j=0;j<affineptr->hole[i].numcore;j++)
1478:       {
1479:         if(affineptr->hole[i].core[j].did_offset)
1480:           did_it='Y';
1481:         else
1482:           did_it='N';
1483: 
1484:         (void)fprintf(fptr,"%d\t%d\t%s\t%d\t%s\t%.2f\t%c\n", affineptr->hole[i].core[j].leg,
1485:           affineptr->hole[i].core[j].site, affineptr->hole[i].name, affineptr->hole[i].core[j].name,
1486:           affineptr->hole[i].core[j].type, 
1487:                                         affineptr->hole[i].core[j].cum_depth_offset, did_it);
1488:       }
1489:     }
1490:     fclose(fptr);
1491:   }
1492:   return(!message.error);
1493: }
1494: 
1495: int SpWriteCullTable(dataptr,filename)
1496: DataFile  *dataptr;
1497: char    *filename;
1498: {
1499:   int fdcull,flag;
1500:   int i,j,k;
1501:   HashInfo  info;
1502:   Core  *coreptr;
1503: #if OS == SUNOS
1504:   int write();
1505: #elif OS == SOLARIS
1506:   ssize_t write();
1507: #endif
1508: 
1509: 
1510: /* open output cull table */
1511:   if((fdcull=open(filename,O_WRONLY|O_CREAT,0744))== -1)
1512:   {
1513:     message.error=True;
1514:     if((charptr=(char*)calloc((int)strlen(filename)+50,CHAR_SIZE))==NULL)
1515:       SpBadMemAlloc("SpWriteCullTable 1");
1516:     else
1517:       (void)sprintf(charptr,"Error opening cull table %s.",filename);
1518:     SpManageWarningBox(charptr);
1519:     free(charptr);
1520:   }
1521:   else
1522:   {
1523:     message.error=False;
1524:   /* write out file */
1525:     info.leg=dataptr->leg;
1526:     info.subleg=dataptr->subleg;
1527:     info.site=dataptr->site;
1528:     flag=BAD_CULL1 | BAD_CULL2 | BAD_TOP;
1529:     for(i=0;i<dataptr->numholes;i++)
1530:     {
1531:       info.hole=dataptr->holes[i]->name;
1532:       {
1533:         for(j=0;j<dataptr->holes[i]->numcores;j++)
1534:         {
1535:           coreptr=dataptr->holes[i]->core[j];
1536:           info.core=coreptr->num;
1537:           for(k=0;k<coreptr->numvalues;k++)
1538:           {
1539:             info.coretype=coreptr->value[k]->type;
1540:             (void)strcpy(info.section,coreptr->value[k]->section);
1541:             info.top_int=coreptr->value[k]->top_int;
1542:           /* write flagged values to file */
1543:             if((info.value=coreptr->value[k]->quality) & flag)
1544:               (void)write(fdcull,(char*)&info,sizeof(HashInfo));
1545:           }
1546:         }
1547:       }
1548:     }
1549:     close(fdcull);
1550:   }
1551:   return(!message.error);
1552: }
1553: 
1554: int     SpWriteAgeModel(fptr)
1555: FILE    *fptr;
1556: {
1557:         int i;
1558:         char    topoffset[6],botoffset[6],
1559:                 topmsd[9],botmsd[9];
1560: 
1561:         if(agemodel_cnt < 1) 
1562:         {
1563:           return;
1564:         }
1565:         else 
1566:         {
1567:           for(i=0; i<agemodel_cnt; ++i) 
1568:           {
1569:             if(agemodel[i].top.in_affine == NO)
1570:             {
1571:                 (void)sprintf(topmsd,"N/A");
1572:                 (void)sprintf(topoffset,"N/A");
1573:             }
1574:             else
1575:             {
1576:                 (void)sprintf(topmsd,"%.2f",agemodel[i].top.sb_depth+agemodel[i].top.offset);
1577:                 (void)sprintf(topoffset,"%.2f",agemodel[i].top.offset);
1578:             }
1579:             if(agemodel[i].bot.in_affine == NO)
1580:             {
1581:                 (void)sprintf(topmsd,"N/A");
1582:                 (void)sprintf(botoffset,"N/A");
1583:             }
1584:             else
1585:             {
1586:                 (void)sprintf(botmsd,"%.2f",agemodel[i].bot.sb_depth+agemodel[i].bot.offset);
1587:                 (void)sprintf(botoffset,"%.2f",agemodel[i].bot.offset);
1588:             }
1589: 
1590:             fprintf(fptr,"%8.3f\t%8.3f\t%8.4f\t%8.3f\t%s\t%s", 
1591:                       agemodel[i].avembsf, agemodel[i].avemcd, agemodel[i].aveage, agemodel[i].sedrate, 
1592:                       agemodel[i].name, agemodel[i].code);
1593:             if(agemodel[i].type == PALEOMAG) {
1594:               fprintf(fptr, "\tPaleomag\n");
1595:             }
1596:             else if(agemodel[i].type == DIATOMS) {
1597:               fprintf(fptr, "\tDiatom\n");
1598:             }
1599:             else if(agemodel[i].type == RADIOLARIA) {
1600:               fprintf(fptr, "\tRadiolaria\n");
1601:             }
1602:             else if(agemodel[i].type == FORAMINIFERA) {
1603:               fprintf(fptr, "\tForaminifera\n");
1604:             }
1605:             else if(agemodel[i].type == NANNOFOSSILS) {
1606:               fprintf(fptr, "\tNannofossil\n");
1607:             }
1608:             else if(agemodel[i].type == HANDPICK) {
1609:               fprintf(fptr, "\tHandpick\n");
1610:             }
1611:             else if(agemodel[i].type == TIME) {
1612:               fprintf(fptr, "\tTimeSeries\n");
1613:             }
1614:             else {
1615:               fprintf(fptr, "\n");
1616:             }
1617:           }
1618:         }
1619:         return(True);
1620: }
1621: 
1622: int     SpReadAgeModel(fptr)
1623: FILE    *fptr;
1624: {
1625:         int i, status;
1626:         char s[201], strattype[50];
1627: 
1628:         agemodel_cnt = 0;
1629:         status = 1;
1630: 
1631:         for(i=0; i<MAXAGE; ++i) 
1632:         {
1633:           if(fgets(s, 200, fptr) == NULL) {
1634:             return;
1635:           }
1636:           sscanf(s, "%f %f %f %f %s %s %s",
1637:                    &agemodel[i].avembsf, &agemodel[i].avemcd, &agemodel[i].aveage, &agemodel[i].sedrate,
1638:                    &agemodel[i].name, &agemodel[i].code, strattype);
1639:           if(strcmp(strattype, "Paleomag") == 0) {
1640:             agemodel[i].type = PALEOMAG;
1641:           }
1642:           else if(strcmp(strattype, "Diatom") == 0) {
1643:             agemodel[i].type = DIATOMS;
1644:           }
1645:           else if(strcmp(strattype, "Radiolaria") == 0) {
1646:             agemodel[i].type = RADIOLARIA;
1647:           }
1648:           else if(strcmp(strattype, "Foraminifera") == 0) {
1649:             agemodel[i].type = FORAMINIFERA;
1650:           }
1651:           else if(strcmp(strattype, "Nannofossil") == 0) {
1652:             agemodel[i].type = NANNOFOSSILS;
1653:           }
1654:           else if(strcmp(strattype, "Handpick") == 0) {
1655:             agemodel[i].type = HANDPICK;
1656:           }
1657:           else if(strcmp(strattype, "TimeSeries") == 0) {
1658:             agemodel[i].type = TIME;
1659:           }
1660:           else {
1661:             agemodel[i].type = -1;
1662:           }
1663:           sprintf(strattype,"");
1664: 
1665:           ++agemodel_cnt;
1666:         }
1667:         sprintf(s,"");
1668:         return(True);
1669: }
1670: 
1671: void ReadPreviewInput(file)
1672: char *file;
1673: {
1674:   int l, len;
1675:   char *text;
1676:   FILE *fd;
1677:   XmTextPosition  pos;
1678: 
1679:   if((fd = fopen(file, "r"))==NULL) {
1680:     message.error=True;
1681:     message.fatal=False;
1682:     message.default_button=XmDIALOG_OK_BUTTON;
1683:     message.type=XmDIALOG_ERROR;
1684:     message.caller=NONE;
1685:     if((message.label=(char*)calloc((int)strlen(file)+100,CHAR_SIZE))==NULL)
1686:                         SpBadMemAlloc("SpReadPreviewInput 1");
1687:     (void)sprintf(message.label,"Error: could not open preview input file  %s.",file);
1688:     SpManageMessage(message);
1689:   }
1690:   else {
1691:     l = 0;
1692:     len = 500;
1693:     if((text=(char*)calloc(len * MAXPREVIEW + 1000, CHAR_SIZE))==NULL)
1694:                 SpBadMemAlloc("ReadPreviewInput 2");
1695:     (void)sprintf(text, "");
1696:     (void)sprintf(text, "%s\n\n", file);
1697:     while((fgets(line,500,fd) != NULL) && l<MAXPREVIEW) {
1698:       ++l;
1699:       (void)strcat(text, line);
1700:     }
1701:   } 
1702:   fclose(fd);
1703: 
1704:   pos=XmTextGetLastPosition(textPreviewInput);
1705: 
1706:   XmTextInsert(textPreviewInput,pos,text);
1707: 
1708:   free(text);
1709: }
1710: 
1711: int ReadTimeSeries(file)
1712: char *file;
1713: {
1714:   void ViewSpliceVsAge();
1715:   int i, n, ndiv, all, moreall, sumall, valcol, agecol, nline;
1716:   char *fmt, *str;
1717:   float minval, maxval, startage, endage, age, val, sumval;
1718:   FILE *fd;
1719: 
1720:   /* get the time series read info
1721:   */
1722:   str = XmTextGetString(textFieldTimeSeriesAgeCol);
1723:   agecol = atoi(str);
1724:   free(str);
1725:   str = XmTextGetString(textFieldTimeSeriesValCol);
1726:   valcol = atoi(str);
1727:   free(str);
1728:   str = XmTextGetString(textFieldTimeSeriesFromAge);
1729:   startage = atof(str);
1730:   free(str);
1731:   str = XmTextGetString(textFieldTimeSeriesToAge);
1732:   endage = atof(str);
1733:   free(str);
1734:   if(fabs(endage - 0.0) < 0.0001) {
1735:     endage = 999.9;
1736:   }
1737: 
1738:   if(XmToggleButtonGetState(toggleButtonTimeSeriesAgeMa) == True) {
1739:     timeseries.MaConvert = 1.0;
1740:   }
1741:   else if(XmToggleButtonGetState(toggleButtonTimeSeriesAgeKyr) == True) {
1742:     timeseries.MaConvert = 0.001;
1743:   }
1744:   else if(XmToggleButtonGetState(toggleButtonTimeSeriesAgeYrs) == True) {
1745:     timeseries.MaConvert = 0.000001;
1746:   }
1747:   else {
1748:   }
1749: 
1750:   /* make the read format
1751:   */
1752:   if((fmt=(char*)calloc(100,CHAR_SIZE)) == NULL)
1753:                  SpBadMemAlloc("ReadTimeSeries");
1754:   (void)sprintf(fmt,"");
1755:   i = 1;
1756:   if(agecol > valcol) {
1757:     if(valcol == 1) {
1758: 
1759:     }
1760:     else {
1761:       while(i<valcol) {
1762:         ++i;
1763:         strcat(fmt,"%*s ");
1764:       }
1765:     }
1766:     strcat(fmt,"%f ");
1767:     ++i;
1768:     if(i == agecol) {
1769:     }
1770:     else {
1771:       while(i<agecol) {
1772:         ++i;
1773:         strcat(fmt,"%*s ");
1774:       }
1775:     }
1776:     strcat(fmt,"%f");
1777:   }
1778:   else if(valcol > agecol) {
1779:     if(agecol == 1) {
1780: 
1781:     }
1782:     else {
1783:       while(i<agecol) {
1784:         ++i;
1785:         strcat(fmt,"%*s ");
1786:       }
1787:     }
1788:     strcat(fmt,"%f ");
1789:     ++i;
1790:     if(i == valcol) {
1791:     }
1792:     else {
1793:       while(i<valcol) {
1794:         ++i;
1795:         strcat(fmt,"%*s ");
1796:       }
1797:     }
1798:     strcat(fmt,"%f");
1799:   }
1800:   else {
1801:   }
1802: 
1803:   all = 500;
1804:   moreall = 100;
1805:   if((fd = fopen(file, "r"))==NULL) {
1806:     message.error=True;
1807:     message.fatal=False;
1808:     message.default_button=XmDIALOG_OK_BUTTON;
1809:     message.type=XmDIALOG_ERROR;
1810:     message.caller=NONE;
1811:     if((message.label=(char*)calloc((int)strlen(file)+100,CHAR_SIZE))==NULL)
1812:                         SpBadMemAlloc("SpReadTimeSeries");
1813:     (void)sprintf(message.label,"Error: could not open time series file  %s.",file);
1814:     SpManageMessage(message);
1815:   }
1816:   else {
1817:     timeseries.age=(float*)calloc(all, sizeof(float));
1818:     timeseries.val=(float*)calloc(all, sizeof(float));
1819:     i=0;
1820:     nline = 0;
1821:     sumall = all;
1822:     while(fgets(line,1000,fd) != NULL) {
1823:       ++nline;
1824:       if(valcol > agecol) {
1825:         if((sscanf(line,fmt, &age, &val)) != 2) {
1826:            if((charptr=(char*)calloc(200,CHAR_SIZE))==NULL) {
1827:               SpBadMemAlloc("ReadTimeSeries");
1828:             }
1829:             else {
1830:               (void)sprintf(charptr,"There is a format problem in time series file. This happened on line %d", nline);
1831:             }
1832:             SpManageWarningBox(charptr);
1833:             free(charptr);
1834:             SpCleanUp(TIMESERIES);
1835:             return 1;
1836:         }
1837:       }
1838:       else if(agecol > valcol) {
1839:         if((sscanf(line,fmt, &val, &age)) != 2) {
1840:           if((charptr=(char*)calloc(200,CHAR_SIZE))==NULL) {
1841:               SpBadMemAlloc("ReadTimeSeries");
1842:             }
1843:             else {
1844:               (void)sprintf(charptr,"There is a format problem in time series file. This happened on line %d", nline);
1845:             }
1846:             SpManageWarningBox(charptr);
1847:             free(charptr);
1848:             SpCleanUp(TIMESERIES);
1849:             return 1;
1850:         }
1851:       }
1852:       age = age * timeseries.MaConvert;
1853: 
1854:       if(age <= endage && age >= startage) {
1855: 
1856:         /* check that the age is in descending order
1857:         */
1858:         if(i>0) {
1859:           if(age < timeseries.age[i-1]) {
1860:             if((charptr=(char*)calloc(200,CHAR_SIZE))==NULL) {
1861:               SpBadMemAlloc("ReadTimeSeries");
1862:             }
1863:             else {
1864:               (void)sprintf(charptr,"The time series is not in descending order.\nThis happened on line %d at %.3f Ma", nline, timeseries.age[i-1]);
1865:               
1866:             }
1867:             SpManageWarningBox(charptr);
1868:             free(charptr);           
1869:             SpCleanUp(TIMESERIES);
1870:             return 1;
1871:           }
1872:         } 
1873:         timeseries.age[i] = age;
1874:         timeseries.val[i] = val;
1875: 
1876:         if(i == 0) {
1877:           minval = timeseries.val[i];
1878:           maxval = timeseries.val[i];
1879:         }
1880:         else if(timeseries.val[i] > maxval) {
1881:           maxval = timeseries.val[i];
1882:         }
1883:         else if(timeseries.val[i] < minval) {
1884:           minval = timeseries.val[i];
1885:         } 
1886: 
1887:         ++i;
1888: 
1889:         if(i >= sumall) {
1890:           sumall = sumall + moreall;
1891:           if((timeseries.age=(float*)realloc((float*)timeseries.age, sumall*sizeof(float)))==NULL)
1892:           {
1893:                         SpBadMemAlloc("ReadTimeSeries");
1894:           }
1895:           else 
1896:           {
1897:           }
1898:           if((timeseries.val=(float*)realloc((float*)timeseries.val, sumall*sizeof(float)))==NULL)
1899:           {
1900:                         SpBadMemAlloc("ReadTimeSeries");
1901:           }
1902:           else
1903:           {
1904:           }
1905:         }
1906:       }
1907:     }
1908:     timeseries.n=i;
1909:     timeseries.minval = minval;
1910:     timeseries.maxval = maxval;
1911:   }
1912:   fclose(fd);
1913:   free(fmt);
1914: 
1915:   if(timeseries.n < 2) {
1916:     if((charptr=(char*)calloc(200,CHAR_SIZE))==NULL) {
1917:               SpBadMemAlloc("ReadTimeSeries");
1918:     }
1919:     else {
1920:       (void)sprintf(charptr,"The time series has less than two points.");
1921:     }
1922:     SpManageWarningBox(charptr);
1923:     free(charptr);
1924:     SpCleanUp(TIMESERIES);
1925:     return 1;
1926:   }
1927: 
1928:   /* check for mult samples per level
1929:   */
1930:   sumval = timeseries.val[0];
1931:   n = 0;
1932:   ndiv = 1;
1933:   for(i=1; i<timeseries.n; ++i) {
1934:     if(timeseries.age[i] == timeseries.age[i-1] && i < timeseries.n - 1) {
1935:       sumval = sumval + timeseries.val[i];
1936:       ++ndiv;
1937:     }
1938:     else if(timeseries.age[i] == timeseries.age[i-1] && i == timeseries.n - 1) {
1939:       sumval = sumval + timeseries.val[i];
1940:       ++ndiv;
1941:       timeseries.age[n] = timeseries.age[i-1];
1942:       timeseries.val[n] = sumval/ndiv;
1943:       ++n;
1944:     }
1945:     else if(timeseries.age[i] > timeseries.age[i-1] && i < timeseries.n - 1) {
1946:       timeseries.age[n] = timeseries.age[i-1];
1947:       timeseries.val[n] = sumval/ndiv;
1948:       sumval = timeseries.val[i];
1949:       ndiv = 1;
1950:       ++n;
1951:     }
1952:     else if(timeseries.age[i] > timeseries.age[i-1] && i == timeseries.n - 1) {
1953:       timeseries.age[n] = timeseries.age[i-1];
1954:       timeseries.val[n] = sumval/ndiv;
1955:       ++n;
1956:       timeseries.age[n] = timeseries.age[i];
1957:       timeseries.val[n] = timeseries.val[i];
1958:       ++n;
1959:     }
1960:     else {
1961:     }
1962:   }
1963:   timeseries.n = n;
1964: 
1965:   if(timeseries.n < 2) {
1966:     if((charptr=(char*)calloc(200,CHAR_SIZE))==NULL) {
1967:               SpBadMemAlloc("ReadTimeSeries");
1968:     }
1969:     else {
1970:       (void)sprintf(charptr,"The time series has less than two points.");
1971:     }
1972:     SpManageWarningBox(charptr);
1973:     free(charptr);
1974:     SpCleanUp(TIMESERIES);
1975:     return 1;
1976:   }
1977: 
1978:   have_time_series = DO;
1979:   XtSetSensitive(pushButtonOpenAgeSignal, False);
1980:   XtSetSensitive(pushButtonOpenTimeSeries, False);
1981:   XtSetSensitive(radioBoxInvertTimeSeries, True);
1982:   ViewSpliceVsAge((Widget)NULL, (XtPointer)NULL, (XtPointer)NULL);
1983: 
1984:   return 0;
1985: }
1986: 
1987: int SpReadJanus(fptr,dataptr)
1988: FILE    *fptr;
1989: DataFile        *dataptr;
1990: {
1991:         char    hole_name, munsell[2][20];
1992:         int     core_num,status,this_hole,this_core,max_alloc;
1993:         float   val[6];
1994:         Value   tmp_value,*valueptr;
1995:         Core    *coreptr;
1996:         Hole    *holeptr;
1997: 
1998:         /*return False=more data, true=done */
1999: 
2000: /* read data line */
2001:         dataptr->subleg=' ';
2002:         if(fgets(buffer,1000,fptr)==NULL)
2003:                 return(True);
2004: 
2005:         if(dataptr->in_format == JANUSORIG) {
2006:           if(strcmp(buffer, "Sql statement executed OK!\n") == 0) {
2007:             return(True);
2008:           }
2009:         }
2010: 
2011: /* get variables */
2012:         switch (dataptr->type)
2013:         {
2014:                 case    GRAPE:
2015:                 case    PWAVE:
2016:                 case    NATURALGAMMA:
2017:                         if((status=sscanf(buffer, "%d %d %c %d %c %s %f %f %f",
2018:                                    &dataptr->leg, &dataptr->site, &hole_name, &core_num, &tmp_value.type,
2019:                                    tmp_value.section, &tmp_value.top_int, &tmp_value.sb_depth,
2020:                                    &val[0]))!=9)
2021:                         {
2022:                                 if(status==EOF)
2023:                                         return(True);
2024:                                 else
2025:                                         message.error=True;
2026:                         }
2027:                         break;
2028:                 case    SUSCEPTIBILITY:
2029:                         if((status=sscanf(buffer, "%d %d %c %d %c %s %f %f %f %f",
2030:                                    &dataptr->leg, &dataptr->site, &hole_name, &core_num, &tmp_value.type,
2031:                                    tmp_value.section, &tmp_value.top_int, &tmp_value.sb_depth,
2032:                                    &val[0], &val[1]))!=10)
2033:                         {
2034:                                 if(status==EOF)
2035:                                         return(True);
2036:                                 else
2037:                                         message.error=True;
2038:                         }
2039:                         break;
2040:                 case    REFLECTANCEMST:
2041:                         if((status=sscanf(buffer, "%d %d %c %d %c %s %f %f %f %f %f %s, %s, %f %f %f",
2042:                                    &dataptr->leg, &dataptr->site, &hole_name, &core_num, &tmp_value.type,
2043:                                    tmp_value.section, &tmp_value.top_int, &tmp_value.sb_depth,
2044:                                    &val[0], val[1], &val[2], munsell[0], munsell[1], &val[3], &val[4], &val[5]))!=16)
2045:                         {
2046:                                 if(status == 13) {
2047:                                 }
2048:                                 else if(status==EOF) {
2049:                                         return(True);
2050:                                 }
2051:                                 else {
2052:                                         message.error=True;
2053:                                 }
2054:                         }
2055:                         break;
2056:                 default:
2057:                         message.fatal=False;
2058:                         message.default_button=XmDIALOG_OK_BUTTON;
2059:                         message.type=XmDIALOG_ERROR;
2060:                         message.caller=SPREADJANUS;
2061:                         if((message.label=(char*)calloc(100,CHAR_SIZE))==NULL)
2062:                                 SpBadMemAlloc("SpReadJanus 1");
2063:                         (void)sprintf(message.label,"Invalid other odp data type %d",dataptr->type);
2064:                         SpManageMessage(message);
2065:                         return(True);
2066:         }
2067:         tmp_value.bot_int=tmp_value.top_int;
2068:         if(message.error)
2069:         {
2070:                 message.fatal=False;
2071:                 message.default_button=XmDIALOG_OK_BUTTON;
2072:                 message.type=XmDIALOG_ERROR;
2073:                 message.caller=SPREADJANUS;
2074:                 if((message.label=(char*)calloc(50+(int)strlen(type[dataptr->type])+
2075:                                         (int)strlen(format[dataptr->in_format]),CHAR_SIZE))==NULL)
2076:                         SpBadMemAlloc("SpReadJanus 2");
2077:                 (void)sprintf(message.label,"Bad %s %s line",format[dataptr->in_format],type[dataptr->type]);
2078:                 SpManageMessage(message);
2079:                 return(False);
2080:         }
2081:         /* check if new hole */
2082:         hole_name=toupper(hole_name);
2083:         if(dataptr->holes_used==NULL || strchr(dataptr->holes_used,hole_name)==NULL)
2084:         {
2085:                 dataptr->numholes++;
2086:                 if(dataptr->numholes >1)        /* not first hole */
2087:                 {
2088:                         if((charptr=(char*)realloc(dataptr->holes_used,(dataptr->numholes+1)*CHAR_SIZE))==NULL)
2089:                                 SpBadMemAlloc("SpReadJanus 3");
2090:                         else
2091:                                 dataptr->holes_used = charptr;
2092:                         if((charptr=(char*)realloc((char*)dataptr->holes,dataptr->numholes*sizeof(Hole*)))==NULL)
2093:                                 SpBadMemAlloc("SpReadJanus 4");
2094:                         else
2095:                                 dataptr->holes=(Hole**)charptr;
2096:                 }
2097:                 else            /* first hole */
2098:                 {
2099:                         if((dataptr->holes_used=(char*)calloc(2,sizeof(char)))==NULL)
2100:                                 SpBadMemAlloc("SpReadJanus 5");
2101:                         dataptr->holes_used[0]='\0';
2102:                         if((dataptr->holes=(Hole**)calloc(dataptr->numholes,sizeof(Hole*)))==NULL)
2103:                                 SpBadMemAlloc("SpReadJanus 6");
2104:                 }
2105:                 /* set hole values */
2106:                 if((dataptr->holes[dataptr->numholes-1]=(Hole*)calloc(1,sizeof(Hole)))==NULL)
2107:                         SpBadMemAlloc("SpReadJanus 7");
2108:                 this_hole=dataptr->numholes-1;
2109:                 holeptr=dataptr->holes[this_hole];
2110:                 holeptr->name=hole_name;
2111:                 (void)sprintf(dataptr->holes_used,"%s%c",dataptr->holes_used,hole_name);
2112:                 holeptr->numcores=0;
2113:         }
2114:         else    /* hole already exists */
2115:         {
2116:                 for(this_hole=0;this_hole<dataptr->numholes && dataptr->holes[this_hole]->name!=hole_name;this_hole++);
2117:         }
2118:         holeptr=dataptr->holes[this_hole];
2119:         /* check if new core*/
2120:         for(this_core=0;this_core<holeptr->numcores && core_num != holeptr->core[this_core]->num;this_core++);
2121:         if(this_core >= holeptr->numcores)
2122:         {
2123:                 if(holeptr->numcores++>0)       /* not first core*/
2124:                 {
2125:                         if((charptr=(char*)realloc((char*)holeptr->core,holeptr->numcores*sizeof(Core*)))==NULL)
2126:                                 SpBadMemAlloc("SpReadJanus 8");
2127:                         else
2128:                                 data[dset]->holes[this_hole]->core=(Core**)charptr;
2129:                 }
2130:                 else            /* firstcore */
2131:                 {
2132:                         if((holeptr->core=(Core**)calloc(holeptr->numcores,sizeof(Core*)))==NULL)
2133:                                 SpBadMemAlloc("SpReadJanus 9");
2134:                 }
2135:                 /* set core values */
2136:                 if((holeptr->core[this_core]=(Core*)calloc(1,sizeof(Core)))==NULL)
2137:                         SpBadMemAlloc("SpReadJanus 10");
2138:                 coreptr=holeptr->core[this_core];
2139:                 coreptr->num=core_num;
2140:                 coreptr->numvalues=0;
2141:                 if((coreptr->value=(Value**)calloc(ALLOC_INT,sizeof(Value*)))==NULL)
2142:                         SpBadMemAlloc("SpReadJanus 11");
2143:                 for(coreptr->allocvalues=0;coreptr->allocvalues<ALLOC_INT;coreptr->allocvalues++)
2144:                 {
2145:                         if((coreptr->value[coreptr->allocvalues]=(Value*)calloc(1,sizeof(Value)))==NULL)
2146:                                 SpBadMemAlloc("SpReadJanus 12");
2147:                 }
2148:         }
2149:         coreptr=holeptr->core[this_core];
2150:         if(coreptr->numvalues++ >= coreptr->allocvalues)
2151:         {
2152:                 max_alloc=coreptr->allocvalues+ALLOC_INT;
2153:                 if((charptr=(char*)realloc((char*)coreptr->value,max_alloc*sizeof(Value*)))==NULL)
2154:                         SpBadMemAlloc("SpReadJanus 13");
2155:                 else
2156:                         coreptr->value=(Value**) charptr;
2157:                 for(;coreptr->allocvalues<max_alloc;coreptr->allocvalues++)
2158:                 {
2159:                         if((coreptr->value[coreptr->allocvalues]=(Value*)calloc(1,sizeof(Value)))==NULL)
2160:                                 SpBadMemAlloc("SpReadJanus 14");
2161:                 }
2162:         }
2163:         valueptr=coreptr->value[coreptr->numvalues-1];
2164: /* get standard core values */
2165:         valueptr->type=tmp_value.type;
2166:         (void)strcpy(valueptr->section,tmp_value.section);
2167:         valueptr->top_int=tmp_value.top_int;
2168:         valueptr->bot_int=tmp_value.bot_int;
2169:         valueptr->sb_depth=tmp_value.sb_depth;
2170:         if(fabs(valueptr->sb_depth - BAD_CODE) <= ROUNDCHECK)
2171:                 valueptr->quality=BAD_SB_DEPTH;
2172:         else
2173:                 valueptr->quality=GOOD;
2174:         valueptr->run_num=0;
2175:         switch (dataptr->type)
2176:         {
2177:           case GRAPE:
2178:           case PWAVE:
2179:           case NATURALGAMMA:
2180:             valueptr->otherodp = val[0];
2181:             valueptr->data = &valueptr->otherodp;
2182:             break;
2183:           case SUSCEPTIBILITY:
2184:             if((valueptr->susceptibility=(Susceptibility*)calloc(1,sizeof(Susceptibility)))==NULL)
2185:                                         SpBadMemAlloc("SpReadJanus 15");
2186:             valueptr->susceptibility->observed = val[0];
2187:             valueptr->susceptibility->corrected = val[1];
2188:             valueptr->data = &valueptr->susceptibility->corrected;
2189:             break;
2190:           case REFLECTANCEMST:
2191:             if((valueptr->reflectanceMST=(ReflectanceMST*)calloc(1,sizeof(ReflectanceMST)))==NULL)
2192:                                         SpBadMemAlloc("SpReadJanus 16");
2193:             valueptr->reflectanceMST->L = val[0];
2194:             valueptr->reflectanceMST->a = val[1];
2195:             valueptr->reflectanceMST->b = val[2];
2196:             strcpy(valueptr->reflectanceMST->munsell_hue, munsell[0]);
2197:             strcpy(valueptr->reflectanceMST->munsell_value, munsell[1]);
2198:             valueptr->data = &valueptr->reflectanceMST->L;
2199:             break;
2200:           default:
2201:             dataptr->readerrors++;
2202:             message.error=True;
2203:         }
2204: 
2205:         if(message.error==True)
2206:         {
2207:           message.fatal=False;
2208:           message.default_button=XmDIALOG_OK_BUTTON;
2209:           message.type=XmDIALOG_ERROR;
2210:           message.caller=SPREADJANUS;
2211:           if((message.label=(char*)calloc(50+(int)strlen(format[dataptr->in_format])+(int)strlen(type[dataptr->type]),sizeof(char)))==NULL)
2212:                                 SpBadMemAlloc("SpReadJanus 17");
2213:           (void)sprintf(message.label,"Bad %s %s line",format[dataptr->in_format],type[dataptr->type]);
2214:           SpManageMessage(message);
2215:         }
2216:         else
2217:           valueptr->sm_data=*valueptr->data;
2218: 
2219:         return(False);
2220: }
2221: 








































Html form generated by Xrefactory version 1.6.7 on Fri Sep 03 17:18:59 2004