Changeset 7983


Ignore:
Timestamp:
03/28/19 21:12:53 (3 months ago)
Author:
stefan
Message:

hm, zu instead of d in printf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/cosmos/src/libsrc/util/cosmos0putaway.c

    r7978 r7983  
    5454#include "earthworm_simple_funcs.h" 
    5555#include "chron3.h" 
    56 #include "read_arc.h" 
    5756  
    5857 
    59 #define TAG_FILE        '.tag'        /* file containing the last known file tag */ 
    60 #define GAP_FILL        'NaN' 
    61 #define MAXTXT           150 
    62  
    63 FILE    *COSMOS0fp;                      /* file pointer for the COSMOS0 file */ 
    64 FILE    *COSMOS0Libfp;                   /* file pointer for the COSMOS0 library file */ 
    65 FILE    *EVENTARCfp;                     /* file pointer to the seismic event file */ 
     58 
     59 
     60// just testing 
     61// sprintf(global_outputdir, "e:\earthworm\memphis\data\database_v0"); 
     62 
     63 
    6664 
    6765static  long   *COSMOS0Buffer;           /* write out COSMOS0 data as long integers */ 
     
    7371/* Internal Function Prototypes */ 
    7472static int StructMakeLocal(void *, int, char, int); 
    75 char global_outputdir[80]; 
    76 sprintf(global_outputdir, "e:\earthworm\memphis\data\database_v0"); 
    7773/************************************************************************ 
    7874* Initialization function,                                              * 
     
    154150        char    str[COSMOSLINELEN]; 
    155151        char    tempstr[COSMOSLINELEN]; 
     152        char    tempstr2[COSMOSLINELEN]; 
    156153        int     LineNumber = 0; 
    157154        time_t  rawtime; 
     
    301298                                        59-80 Record identification, assigned by preparing agency. 
    302299                                    "06/17/2018, 18:34:38.004 GMT (Q=5) "<- 35 chars   " (Q=5) " "38199368.SB.WLA.00.HN " <- 22char*/  
    303                         strncpy(record_id, str + 45, 34); 
    304                         fprintf(COSMOS0fp, "Rcrd start time:%s %s\n", cos_date, record_id); 
     300                        /* strncpy(record_id, str + 45, 34); no, we're not going to use any of the prev string */ 
     301                        /* We pad with white space, because we're going to overwrite some of it, and we'll only copy 
     302                           the relevant characters to go up to 80, andything too long will get truncated. */ 
     303                        sprintf(tempstr, "Rcrd start time:%s                             ", cos_date); 
     304                        sprintf(tempstr2, "RcrdId:%zu.%s.%s.%s.%s                  ",  
     305                                arcmsg.sum.qid,ptrReq->net,  ptrReq->sta, ptrReq->loc, ptrReq->chan); 
     306                        strncpy(tempstr + 51, tempstr2, 29); 
     307                        tempstr[80] = '\0'; /* Chop off any extra junk */ 
     308                        fprintf(COSMOS0fp, "%s\n", tempstr); 
    305309                        break; 
    306310                case 10: /* 10 20-27 Length of raw record, as recorded (seconds); 45-54 Maximum of raw (uncorrected) 
     
    331335                case 47: /*AQMS normally writes this comment, but we're not using AQMS*/ 
    332336                        /* Example: | RcrdId: NC.72282711.NC.C031.HNE.01 */ 
    333                         sprintf(tempstr, "| RcrdId: %s.72282711.%s.%s.%s.%s ", /* FIX: If anyone knows what I can put here instead of 72282711, I'll do it!*/ 
    334                                 ptrReq->net, ptrReq->net, ptrReq->sta, ptrReq->chan, ptrReq->loc); 
     337                        sprintf(tempstr, "| RcrdId: %s.%zu.%s.%s.%s.%s ", /* FIX: If anyone knows what I can put here instead of 72282711, I'll do it!*/ 
     338                                ptrReq->net, arcmsg.sum.qid, ptrReq->net, ptrReq->sta, ptrReq->chan, ptrReq->loc); 
    335339                        fprintf(COSMOS0fp, "%s\n", tempstr); 
    336340                        break; 
     
    619623                                sprintf(elevendigits, "           "); /* we want leading spaces */ 
    620624                                if (((int)(COSMOS0Buffer[j] * Multiplier) > 999999) || ((int)(COSMOS0Buffer[j] * Multiplier) < -99999)) { 
    621                                         sprintf(sample, "9999"); 
     625                                        sprintf(sample, GAP_FILL); 
    622626                                        /* prevent out of range string */ 
    623627                                } 
     
    631635                                /* We have a gap, this is where gap data is written */ 
    632636                                //strcpy(hour_line + s_place, "  9999"); 
    633                                 sprintf(sample, " 0"); 
     637                                sprintf(sample, GAP_FILL); 
    634638                                strcpy(elevendigits + 11 - strlen(sample), sample); 
    635639                                strcpy(hour_line + s_place, elevendigits);                               
     
    687691        free((char *)COSMOS0Buffer); 
    688692        return(EW_SUCCESS); 
    689 } 
    690  
    691 /************************************************************************ 
    692 * We first try and find a tabular base that will apply to all data      * 
    693 * that has been returned from our waveserver request. If there is       * 
    694 * no base that will fit all the data and be within -999 to 9998, we     * 
    695 * will keep removing low and high values 'till we get one. This base    * 
    696 * will work for most days, but not spike days. Spike days will          * 
    697 * recalculate their own tabular base                                    * 
    698 *************************************************************************/ 
    699 int FindTabularBase(int number_samples, long *SampleBuffer, TRACE_REQ *getThis, double Multiplier, int skip) 
    700 { 
    701         int daymax; 
    702         int daymin; 
    703         int tabular_base = 999; 
    704         int range; 
    705         int j; 
    706         int sample_COSMOS0_int; 
    707  
    708         daymax = (int)getThis->fill; 
    709         daymin = (int)getThis->fill; 
    710  
    711         for (j = skip; j<number_samples; j++) { 
    712                 /* From the definition above: For the intensity elements we have that 
    713                 * hourly value (nanoTeslas) = tab.base*100 + tab.value 
    714                 * The Multiplier is specific to the USGS waveservers so they can get 
    715                 * decimal values out of the integer type...                             */ 
    716                 /* Won't divide by 100 'till we're done */ 
    717  
    718                 /* Skip ahead past all gaps */ 
    719                 if (SampleBuffer[j] == getThis->fill) { 
    720                         continue; 
    721                 } 
    722                 sample_COSMOS0_int = (int)((SampleBuffer[j] * Multiplier)); 
    723                 /* Keep track of the line's max and min for the tabular base generation */ 
    724                 if ((sample_COSMOS0_int > daymax) || (daymax == getThis->fill)) { 
    725                         daymax = sample_COSMOS0_int; 
    726                 } 
    727                 if ((sample_COSMOS0_int < daymin) || (daymin == getThis->fill)) { 
    728                         daymin = sample_COSMOS0_int; 
    729                 } 
    730                 range = daymax - daymin; 
    731         } 
    732         /* Really we want our values ideally to be less than 1000 and > than 1. 
    733         * second most ideally less than 1000 and > than -999. 
    734         * after that, not ideal, anything that fits between 9998 and -999 
    735         * after that, grab the median and make that 5500; 
    736         * everything out of range becomes a spike = 9999 */ 
    737         if (range < 899) { 
    738                 /* let's have the lowest number in our range = 0 * 
    739                 * so we will subtract that number from all numbers. */ 
    740                 tabular_base = daymin / 100; 
    741         } 
    742         else if (range < 1899) { 
    743                 /* let's have the highest number in our range = 999 
    744                 * so we have as few negative numbers as possible */ 
    745                 tabular_base = (daymax - 900) / 100; 
    746         } 
    747         else if (range < (9898 + 999 + 1)) { /* the 1 is to account for 0; 999 is for to -999*/ 
    748                                                                                  /* let's have the lowest number in our range = -999 
    749                                                                                  * so our numbers are as low as possible, and are more 
    750                                                                                  * likely to be less than 3 digits . */ 
    751                 tabular_base = (daymin + 999) / 100; 
    752         } 
    753         else if (number_samples < 25) { 
    754                 /* out of range: if we're out of range then let's make the 
    755                 * median value equal to 5500. We'll have to drop (ie: make 9999) 
    756                 * spike numbers on this line that are > 9998 and < -999  */ 
    757                 tabular_base = (Median(number_samples, SampleBuffer) + 5500) / 100; 
    758         } 
    759         else { 
    760                 /* If we're finding the tabular base for a larger range than a day 
    761                 * and we can't find one, don't use the median, just return failure 
    762                 * We might be doing this we we want to find a common base for an 
    763                 * entire COSMOS0 file for a particular element. So if this fails, 
    764                 * First line will determine it's own tabular base. Each subsequent 
    765                 * line will try to use the previous line's base. If that fails the 
    766                 * subsequent line will calculate a new base. */ 
    767                 tabular_base = 9999; 
    768         } 
    769         return(tabular_base); 
    770693} 
    771694 
Note: See TracChangeset for help on using the changeset viewer.