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

global_amp_rw.c

Go to the documentation of this file.
00001 
00002 #include <global_amp_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_AMP_VERSION (short)1
00015 
00016 
00017 /* ------------------------------------------------------------------------- */
00018 
00019 GLOBAL_MSG_STATUS InitGlobalAmp( GLOBAL_AMP_STRUCT * p_struct )
00020 {
00021    if ( p_struct == NULL )
00022    {
00023      return GLOBAL_MSG_NULL;
00024    }
00025    p_struct->version = GLOBAL_AMP_VERSION;
00026    p_struct->logo.instid = 0;
00027    p_struct->logo.mod = 0;
00028    p_struct->logo.type = 0;
00029    p_struct->sequence = 0;
00030    strcpy( p_struct->station, "?" );
00031    strcpy( p_struct->channel, "?" );
00032    strcpy( p_struct->network, "?" );
00033    strcpy( p_struct->location, "?" );
00034    strcpy( p_struct->amp_time, "?" );
00035    p_struct->amptype = AMPTYPE_NONE;
00036    p_struct->adcounts = 0.0;
00037    p_struct->period = 0.0;
00038 
00039    return GLOBAL_MSG_SUCCESS;
00040 }
00041 
00042 /* ------------------------------------------------------------------------- */
00043 
00044 GLOBAL_MSG_STATUS WriteAmpToBuffer( GLOBAL_AMP_STRUCT * p_struct
00045                                   , char              * p_buffer
00046                                   , unsigned int        p_length
00047                                   )
00048 {
00049    char _author[10];
00050 
00051    if ( p_struct == NULL )
00052    {
00053       return GLOBAL_MSG_NULL;
00054    }
00055 
00056    if ( p_buffer == NULL )
00057    {
00058       return GLOBAL_MSG_BADPARAM;
00059    }
00060 
00061    if ( p_length < GLOBAL_AMP_MAXBUFSIZE )
00062    {
00063       return GLOBAL_MSG_TOOSMALL;
00064    }
00065 
00066    if ( p_struct->version != GLOBAL_AMP_VERSION )
00067    {
00068       return GLOBAL_MSG_VERSINVALID;
00069    }
00070 
00071    EncodeAuthor( p_struct->logo, _author );
00072 
00073    sprintf( p_buffer
00074           , "%s %d %d %s %s %s %s %s %d %1.4f %1.4f\n"
00075           ,  _author
00076           , p_struct->sequence
00077           , p_struct->version
00078           , p_struct->station
00079           , p_struct->channel
00080           , p_struct->network
00081           , p_struct->location
00082           , p_struct->amp_time
00083           , p_struct->amptype
00084           , p_struct->adcounts
00085           , p_struct->period
00086           );
00087 
00088    return GLOBAL_MSG_SUCCESS;
00089 }
00090 
00091 /* ------------------------------------------------------------------------- */
00092 
00093 GLOBAL_MSG_STATUS StringToAmp( GLOBAL_AMP_STRUCT * p_struct, char * p_string )
00094 {
00095    char _str[80];
00096 
00097    if ( p_struct == NULL )
00098    {
00099       return GLOBAL_MSG_NULL;
00100    }
00101 
00102    if ( p_struct->version != GLOBAL_AMP_VERSION )
00103    {
00104       return GLOBAL_MSG_VERSINVALID;
00105    }
00106 
00107    if ( p_string == NULL )
00108    {
00109       return GLOBAL_MSG_BADPARAM;
00110    }
00111 
00112    InitGlobalAmp(p_struct);
00113 
00114    k_put(p_string);
00115 
00116    /*  Author  */
00117    strcpy( _str , k_str() );
00118    if ( strlen(_str) == 0 )
00119    {
00120       return GLOBAL_MSG_FORMATERROR;
00121    }
00122 
00123    if ( DecodeAuthor( &(p_struct->logo), _str ) != GLOBAL_MSG_SUCCESS )
00124    {
00125       return GLOBAL_MSG_FORMATERROR;
00126    }
00127 
00128    /*  sequence number  */
00129    p_struct->sequence = k_long();
00130    if ( k_err() != 0 )
00131    {
00132       return GLOBAL_MSG_FORMATERROR;
00133    }
00134 
00135    /*  version number  */
00136    p_struct->version = (short)k_long();
00137    if ( k_err() != 0 )
00138    {
00139       return GLOBAL_MSG_FORMATERROR;
00140    }
00141 
00142    if ( p_struct->version != GLOBAL_AMP_VERSION )
00143    {
00144       return GLOBAL_MSG_VERSINVALID;
00145    }
00146 
00147    /*  Station  */
00148    strcpy( p_struct->station , k_str() );
00149    if ( strlen(p_struct->station) == 0 )
00150    {
00151       return GLOBAL_MSG_FORMATERROR;
00152    }
00153 
00154    /*  Channel  */
00155    strcpy( p_struct->channel , k_str() );
00156    if ( strlen(p_struct->channel) == 0 )
00157    {
00158       return GLOBAL_MSG_FORMATERROR;
00159    }
00160 
00161    /*  Network  */
00162    strcpy( p_struct->network , k_str() );
00163    if ( strlen(p_struct->network) == 0 )
00164    {
00165       return GLOBAL_MSG_FORMATERROR;
00166    }
00167 
00168    /*  Location  */
00169    strcpy( p_struct->location , k_str() );
00170    if ( strlen(p_struct->location) == 0 )
00171    {
00172       return GLOBAL_MSG_FORMATERROR;
00173    }
00174 
00175    /*  Amplitude Time  */
00176    strcpy( p_struct->amp_time , k_str() );
00177    if ( strlen(p_struct->amp_time) == 0 )
00178    {
00179       return GLOBAL_MSG_FORMATERROR;
00180    }
00181 
00182    /*  Amplitude Type  */
00183    p_struct->amptype = (int)k_long();
00184    if ( k_err() != 0 )
00185    {
00186       return GLOBAL_MSG_FORMATERROR;
00187    }
00188 
00189    if ( p_struct->amptype < 0 || AMPTYPE_COUNT <= p_struct->amptype )
00190    {
00191       return GLOBAL_MSG_FORMATERROR;
00192    }
00193 
00194    /*  A / D Counts  */
00195    p_struct->adcounts = k_val();
00196    if ( k_err() != 0 )
00197    {
00198       return GLOBAL_MSG_FORMATERROR;
00199    }
00200 
00201    /*  Period  */
00202    p_struct->period = k_val();
00203    if ( k_err() != 0 )
00204    {
00205       return GLOBAL_MSG_FORMATERROR;
00206    }
00207 
00208    return GLOBAL_MSG_SUCCESS;
00209 }
00210 

Generated on Tue May 6 09:16:02 2003 for Earthworm Libs by doxygen1.3-rc3