Changeset 7978
- Timestamp:
- 03/28/19 16:41:43 (8 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libsrc/util/cosmos0putaway.c
r7976 r7978 58 58 59 59 #define TAG_FILE '.tag' /* file containing the last known file tag */ 60 #define GAP_FILL 'NaN' 60 61 #define MAXTXT 150 61 62 … … 68 69 static long LineMean; /* average of the 60 samples in the line */ 69 70 71 72 70 73 /* Internal Function Prototypes */ 71 74 static int StructMakeLocal(void *, int, char, int); 72 75 char global_outputdir[80]; 76 sprintf(global_outputdir, "e:\earthworm\memphis\data\database_v0"); 73 77 /************************************************************************ 74 78 * Initialization function, * … … 78 82 * if not ,BEFORE an event has to be processed. * 79 83 * * 80 * For PCCOSMOS0, all we want to do is to make sure that the *84 * For COSMOS0, all we want to do is to make sure that the * 81 85 * directory where files should be written exists. * 82 86 *************************************************************************/ … … 353 357 * It gets to see the corresponding SNIPPET structure, and the event id * 354 358 * * 355 * For PCCOSMOS0, this routine writes to the COSMOS0 file, pointed to by*359 * For COSMOS0, this routine writes to the COSMOS0 file, pointed to by * 356 360 * the COSMOS0fp pointer, all of the received trace data in COSMOS0 * 357 361 * format: * … … 380 384 char day_line[122]; 381 385 char fourdigits[5]; 382 char hour_line[8 2] = ";";386 char hour_line[81] = "; "; 383 387 char sample[12]; 384 388 char elevendigits[12]; … … 402 406 char tempstr[COSMOSLINELEN]; 403 407 char tempstr2[COSMOSLINELEN]; 404 405 408 406 409 /* Put this in the .d file once we know we want it. */ … … 585 588 currenttime = begintime; 586 589 j = 0; 587 if (Cadence == MINUTE) { 588 589 while ((j < nsamp_this_scn) && (currenttime < getThis->reqEndtime)) 590 591 592 while ((j < nsamp_this_scn) && (currenttime < getThis->reqEndtime)) 593 { 594 /* Only give them what they asked for, not each sample we got back. 595 Tracebufs contain multiple samples, and we may need to request 596 an earlier one to get the start sample we need, or a later one 597 for the last sample*/ 598 while (currenttime < getThis->reqStarttime) { 599 currenttime = currenttime + 1 / samprate; 600 j++; 601 } 602 603 s_place = 0; 604 605 /* 35-394 60I6 60 6-digit 1-minute values for the given element for that data hour. 606 * The values are in tenth-minutes for D and I, and in 607 * nanoTeslas for the intensity elements. 608 */ 609 total = 0; 610 LineMean = 0; 611 612 i = 0; 613 614 /* WRITE DATA */ 615 616 while (i < 7 && j < nsamp_this_scn) 590 617 { 591 /* Only give them what they asked for, not each sample we got back. 592 Tracebufs contain multiple samples, and we may need to request 593 an earlier one to get the start sample we need, or a later one 594 for the last sample*/ 595 while (currenttime < getThis->reqStarttime) { 596 currenttime = currenttime + 1 / samprate; 597 j++; 598 } 599 600 s_place = 0; 601 602 /* 35-394 60I6 60 6-digit 1-minute values for the given element for that data hour. 603 * The values are in tenth-minutes for D and I, and in 604 * nanoTeslas for the intensity elements. 605 */ 606 total = 0; 607 LineMean = 0; 608 609 i = 0; 610 611 /* WRITE DATA */ 612 613 /* Drop 60 sample values into the line while counting up the total for */ 614 /* later calculating the mean of these 60 samples. If there is any gap */ 615 /* we won't bother with the mean, LineMean becomes 9999 */ 616 while (i < 7 && j < nsamp_this_scn) 617 { 618 if (COSMOS0Buffer[j] != getThis->fill) { 619 sprintf(elevendigits, " "); /* we want leading spaces */ 620 if (((int)(COSMOS0Buffer[j] * Multiplier) > 999999) || ((int)(COSMOS0Buffer[j] * Multiplier) < -99999)) { 621 sprintf(sample, "9999"); 622 /* prevent out of range string */ 623 } 624 else { 625 sprintf(sample, "%d", (int)(COSMOS0Buffer[j] * Multiplier)); 626 } 627 strcpy(elevendigits + 11 - strlen(sample), sample); 628 strcpy(hour_line + s_place, elevendigits); 618 if (COSMOS0Buffer[j] != getThis->fill) { 619 sprintf(elevendigits, " "); /* we want leading spaces */ 620 if (((int)(COSMOS0Buffer[j] * Multiplier) > 999999) || ((int)(COSMOS0Buffer[j] * Multiplier) < -99999)) { 621 sprintf(sample, "9999"); 622 /* prevent out of range string */ 629 623 } 630 624 else { 631 /* We have a gap */ 632 strcpy(hour_line + s_place, " 9999"); 633 LineMean = 9999; 625 sprintf(sample, "%d", (int)(COSMOS0Buffer[j] * Multiplier)); 634 626 } 635 s_place = s_place + 11; 636 637 total += (int)(COSMOS0Buffer[j] * Multiplier); 638 639 j++; i++; 627 strcpy(elevendigits + 11 - strlen(sample), sample); 628 strcpy(hour_line + s_place, elevendigits); 640 629 } 641 642 643 /* 401-402 Record end marker. 644 * Two chars 'cr'= 13 and 'nl'= 10. 645 */ 646 hour_line[80] = '\r'; 647 hour_line[80] = ' '; 648 hour_line[81] = '\n'; 649 650 /* Write out line */ 651 if (fwrite(&hour_line, sizeof(hour_line), 1, COSMOS0fp) != 1) 652 { 653 logit("et", "COSMOS0PA_next: error writing COSMOS0 line. \n"); 654 return EW_FAILURE; 630 else { 631 /* We have a gap, this is where gap data is written */ 632 //strcpy(hour_line + s_place, " 9999"); 633 sprintf(sample, " 0"); 634 strcpy(elevendigits + 11 - strlen(sample), sample); 635 strcpy(hour_line + s_place, elevendigits); 655 636 } 656 } 657 }/* End if (Cadence == MINUTE) */ 658 /************************* HOUR **************************************************/ 659 else if (Cadence == HOUR) { 660 661 /* Skip ahead to the time range requested */ 662 while ((currenttime < getThis->reqStarttime) && (j < nsamp_this_scn)) { 663 currenttime = currenttime + 1 / wf->samprate; 664 j++; 665 } 666 667 /* We first try and find a tabular base that will apply to all data 668 * that has been returned from our waveserver request. If there is 669 * no base that will fit all the data and be within -999 to 9998, we will 670 * keep removing low and high values 'till we get one. This base will work 671 * for most days, but not spike days. Spike days will recalculate their 672 * own tabular base; We'll skip extra data at the beginning FIX: but not at end */ 673 tabular_base = FindTabularBase(nsamp_this_scn, COSMOS0Buffer, getThis, Multiplier, j); 674 675 while ((j < nsamp_this_scn) && (currenttime < getThis->reqEndtime)) { 676 677 /* On to data */ 678 679 /* 21-116 24I4 24 4-digit hourly mean values for the day. */ 680 /* The values are in tenth-minutes for D and I, and in */ 681 /* nanoTeslas for the intensity elements. */ 682 /* The first hourly mean value represents the mean value */ 683 /* between 00:00 UT and 01:00 UT, ..., the 24th value */ 684 /* represents the mean between 23:00 UT and 24:00 UT. */ 685 /* A missing value is identified by 9999. */ 686 s_place = 0; 687 total = 0; 688 LineMean = 0; 689 i = 0; 690 691 /* WRITE DATA */ 692 /* Drop 24 sample values into the line while counting up the total for 693 * later calculating the mean of these 24 samples. If there is any gap 694 * we won't bother with the mean, LineMean becomes 9999 */ 695 while (i < 24 && j < nsamp_this_scn) 696 { 697 unrounded = ((COSMOS0Buffer[j] * Multiplier)) - (tabular_base * 100); 698 if (unrounded < 0) { 699 current_int = (int)(unrounded - .5); 700 } 701 else { 702 current_int = (int)(unrounded + .5); 703 } 704 if ((current_int > 9999) || (current_int < -999)) { 705 /* How did this happen? */ 706 if (debug == 1) { 707 logit("et", "current_int out of range for COSMOS0 hourly format %d\n", current_int); 708 } 709 current_int = 9999; 710 } 711 /*current_int = (int)((COSMOS0Buffer[j]*Multiplier)) - (tabular_base*100);*/ 712 if (COSMOS0Buffer[j] != getThis->fill) { 713 sprintf(fourdigits, " "); /* we want leading spaces */; 714 sprintf(sample, "%4d", current_int); 715 strcpy(fourdigits + 4 - strlen(sample), sample); 716 strcpy(day_line + s_place, fourdigits); 717 total += current_int; 718 719 } 720 else { 721 /* We have a gap */ 722 strcpy(day_line + s_place, "9999"); 723 LineMean = 9999; 724 } 725 s_place = s_place + 4; 726 727 currenttime = currenttime + 1 / wf->samprate; 728 if (currenttime >= getThis->reqEndtime) { 729 //break; 730 j = nsamp_this_scn; 731 } 732 j++; i++; 733 } 734 while (i < 24) { 735 /* If we got here, and i is less than 24, then we've got no more samples, 736 * but we're not finished with an hour line yet. 737 * Fill this line with COSMOS0 gap fill values. */ 738 strcpy(day_line + s_place, "9999"); 739 LineMean = 9999; 740 s_place = s_place + 4; 741 i++; 742 } 743 744 /* 117-120 I4 Daily Mean. */ 745 /* If any of the hourly mean values for the day are missing */ 746 /* 9999 will appear as the daily mean. */ 747 if ((LineMean > 9999) || (LineMean < -999)) { 748 LineMean = 9999; 749 /* prevent out of range string */ 750 } 751 if (LineMean != 9999) { 752 LineMean = total / 24; /* Mean of the first 24 samples if there are no gaps */ 753 /* We've already subtracted the tabular base from each */ 754 /* value before dropping in the total. */ 755 } 756 sprintf(fourdigits, " "); /* we want leading spaces */ 757 sprintf( sample, "%ld", LineMean ); 758 strcpy(fourdigits + 4 - strlen(sample), sample); 759 strcpy(day_line + 116, fourdigits); 760 761 /* 121-122 Record end marker. */ 762 /* Two chars 'cr'= 13 and 'nl'= 10. */ 763 day_line[120] = '\r'; 764 day_line[121] = '\n'; 765 /* Write out line */ 766 if (fwrite(&day_line, sizeof(day_line), 1, COSMOS0fp) != 1) 767 { 768 logit("et", "COSMOS0PA_next: error writing COSMOS0 line. \n"); 769 return EW_FAILURE; 770 } 771 772 } /* End whiling through the data samples */ 773 } /* End if (Cadence == HOUR) */ 637 s_place = s_place + 11; 638 639 total += (int)(COSMOS0Buffer[j] * Multiplier); 640 641 j++; i++; 642 } 643 644 645 /* 401-402 Record end marker. 646 * Two chars 'cr'= 13 and 'nl'= 10. 647 */ 648 hour_line[77] = ' '; /*Replace that null that sprintf got us*/ 649 hour_line[80] = '\n'; 650 651 /* Write out line */ 652 if (fwrite(&hour_line, sizeof(hour_line), 1, COSMOS0fp) != 1) 653 { 654 logit("et", "COSMOS0PA_next: error writing COSMOS0 line. \n"); 655 return EW_FAILURE; 656 } 657 } 774 658 return EW_SUCCESS; 775 659 } 660 661 776 662 777 663 /************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.