Main Page Class Hierarchy Compound List File List Compound Members File Members

# global_pick_rw.c

Go to the documentation of this file.

    00001
    00002 #include <global_pick_rw.h>
    00003
    00004 #include <string.h>
    00005 #include <stdlib.h>
    00006 #include <stdio.h>
    00007
    00008 #include <kom.h>  /* string parsing */
    00009
    00010
    00011 /*
    00012 ** Version currently handled by this code
    00013 */
    00014 #define GLOBAL_PICK_VERSION (short)1
    00015
    00016
    00017
    00018 /* ------------------------------------------------------------------------- */
    00019
    00020 GLOBAL_MSG_STATUS InitGlobalPick( GLOBAL_PICK_STRUCT * p_struct )
    00021 {
    00022    if ( p_struct == NULL )
    00023    {
    00024      return GLOBAL_MSG_NULL;
    00025    }
    00026    p_struct->version = GLOBAL_PICK_VERSION;
    00027    p_struct->logo.instid = 0;
    00028    p_struct->logo.mod = 0;
    00029    p_struct->logo.type = 0;
    00030    p_struct->sequence = 0;
    00031    strcpy( p_struct->station, "?" );
    00032    strcpy( p_struct->channel, "?" );
    00033    strcpy( p_struct->network, "?" );
    00034    strcpy( p_struct->location, "?" );
    00035    strcpy( p_struct->pick_time, "?" );
    00036    strcpy( p_struct->phase_name, "?" );
    00037    p_struct->quality = 0.0;
    00038    p_struct->polarity = '?';
    00039
    00040    return GLOBAL_MSG_SUCCESS;
    00041 }
    00042
    00043 /* ------------------------------------------------------------------------- */
    00044
    00045 GLOBAL_MSG_STATUS WritePickToBuffer( GLOBAL_PICK_STRUCT * p_struct
    00046                                    , char               * p_buffer
    00047                                    , unsigned int         p_length
    00048                                    )
    00049 {
    00050    char _author[10];
    00051
    00052    if ( p_struct == NULL )
    00053    {
    00054       return GLOBAL_MSG_NULL;
    00055    }
    00056
    00057    if ( p_buffer == NULL )
    00058    {
    00059       return GLOBAL_MSG_BADPARAM;
    00060    }
    00061
    00062    if ( p_length < GLOBAL_PICK_MAXBUFSIZE )
    00063    {
    00064       return GLOBAL_MSG_TOOSMALL;
    00065    }
    00066
    00067    if ( p_struct->version != GLOBAL_PICK_VERSION )
    00068    {
    00069       return GLOBAL_MSG_VERSINVALID;
    00070    }
    00071
    00072    EncodeAuthor( p_struct->logo, _author );
    00073
    00074    sprintf( p_buffer
    00075           , "%s %d %d %s %s %s %s %s %s %1.4f %c\n"
    00076           ,  _author
    00077           , p_struct->sequence
    00078           , p_struct->version
    00079           , p_struct->station
    00080           , p_struct->channel
    00081           , p_struct->network
    00082           , p_struct->location
    00083           , p_struct->pick_time
    00084           , p_struct->phase_name
    00085                   , p_struct->quality
    00086                   , p_struct->polarity
    00087           );
    00088
    00089    return GLOBAL_MSG_SUCCESS;
    00090 }
    00091
    00092 /* ------------------------------------------------------------------------- */
    00093
    00094 GLOBAL_MSG_STATUS StringToPick( GLOBAL_PICK_STRUCT * p_struct, char * p_string )
    00095 {
    00096    char _str[80];
    00097    long _lng;
    00098
    00099    if ( p_struct == NULL )
    00100    {
    00101       return GLOBAL_MSG_NULL;
    00102    }
    00103
    00104    if ( p_struct->version != GLOBAL_PICK_VERSION )
    00105    {
    00106       return GLOBAL_MSG_VERSINVALID;
    00107    }
    00108
    00109    if ( p_string == NULL )
    00110    {
    00111       return GLOBAL_MSG_BADPARAM;
    00112    }
    00113
    00114    InitGlobalPick(p_struct);
    00115
    00116    k_put(p_string);
    00117
    00118    /*  Author  */
    00119    strcpy( _str , k_str() );
    00120
    00121    if ( strlen(_str) == 0 )
    00122    {
    00123       return GLOBAL_MSG_FORMATERROR;
    00124    }
    00125
    00126    if ( DecodeAuthor( &(p_struct->logo), _str ) != GLOBAL_MSG_SUCCESS )
    00127    {
    00128       return GLOBAL_MSG_FORMATERROR;
    00129    }
    00130
    00131    /*  sequence number  */
    00132    p_struct->sequence = k_long();
    00133    if ( k_err() != 0 )
    00134    {
    00135       return GLOBAL_MSG_FORMATERROR;
    00136    }
    00137
    00138    /*  version number  */
    00139    p_struct->version = (short)k_long();
    00140    if ( k_err() != 0 )
    00141    {
    00142       return GLOBAL_MSG_FORMATERROR;
    00143    }
    00144
    00145    if ( p_struct->version != GLOBAL_PICK_VERSION )
    00146    {
    00147       return GLOBAL_MSG_VERSINVALID;
    00148    }
    00149
    00150    /*  Station  */
    00151    strcpy( p_struct->station , k_str() );
    00152    if ( strlen(p_struct->station) == 0 )
    00153    {
    00154       return GLOBAL_MSG_FORMATERROR;
    00155    }
    00156
    00157    /*  Channel  */
    00158    strcpy( p_struct->channel , k_str() );
    00159    if ( strlen(p_struct->channel) == 0 )
    00160    {
    00161       return GLOBAL_MSG_FORMATERROR;
    00162    }
    00163
    00164    /*  Network  */
    00165    strcpy( p_struct->network , k_str() );
    00166    if ( strlen(p_struct->network) == 0 )
    00167    {
    00168       return GLOBAL_MSG_FORMATERROR;
    00169    }
    00170
    00171    /*  Location  */
    00172    strcpy( p_struct->location , k_str() );
    00173    if ( strlen(p_struct->location) == 0 )
    00174    {
    00175       return GLOBAL_MSG_FORMATERROR;
    00176    }
    00177
    00178    /*  Pick Time  */
    00179    strcpy( p_struct->pick_time , k_str() );
    00180    if ( strlen(p_struct->pick_time) == 0 )
    00181    {
    00182       return GLOBAL_MSG_FORMATERROR;
    00183    }
    00184
    00185    /*  Phase Name  */
    00186    strcpy( p_struct->phase_name , k_str() );
    00187    if ( strlen(p_struct->phase_name) == 0 )
    00188    {
    00189       return GLOBAL_MSG_FORMATERROR;
    00190    }
    00191
    00192    /*  Quality  */
    00193    p_struct->quality = k_val();
    00194    if ( k_err() != 0 )
    00195    {
    00196       return GLOBAL_MSG_FORMATERROR;
    00197    }
    00198
    00199    /*  Polarity  */
    00200    strcpy( _str, k_str() );
    00201    if ( strlen(_str) == 0 )
    00202    {
    00203       return GLOBAL_MSG_FORMATERROR;
    00204    }
    00205    p_struct->polarity = _str[0];
    00206
    00207    return GLOBAL_MSG_SUCCESS;
    00208 }
    00209