00001 #include <global_loc_rw.h>
00002
00003 #include <string.h>
00004 #include <stdlib.h>
00005 #include <stdio.h>
00006
00007 #include <kom.h>
00008
00009
00010
00011
00012
00013 #define GLOBAL_AMPLINE_VERSION (short)4
00014
00015 #define GLOBAL_PHSLINE_VERSION (short)2
00016
00017 #define GLOBAL_LOC_VERSION (short)3
00018
00019 #include <earthworm.h>
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 GLOBAL_MSG_STATUS InitGlobalAmpLine( GLOBAL_AMPLINE_STRUCT * p_struct )
00032 {
00033 if ( p_struct == NULL )
00034 {
00035 return GLOBAL_MSG_NULL;
00036 }
00037
00038 p_struct->version = GLOBAL_AMPLINE_VERSION;
00039 p_struct->logo.instid = 0;
00040 p_struct->logo.mod = 0;
00041 p_struct->logo.type = 0;
00042 p_struct->pick_sequence = 0;
00043 strcpy( p_struct->station , "?" );
00044 strcpy( p_struct->channel , "?" );
00045 strcpy( p_struct->network , "?" );
00046 strcpy( p_struct->location , "?" );
00047 strcpy( p_struct->amp_time , "?" );
00048 p_struct->amptype = AMPTYPE_NONE;
00049 p_struct->adcounts = 0.0;
00050 p_struct->period = 0.0;
00051
00052 return GLOBAL_MSG_SUCCESS;
00053 }
00054
00055
00056
00057 GLOBAL_MSG_STATUS InitGlobalPhaseLine( GLOBAL_PHSLINE_STRUCT * p_struct )
00058 {
00059 short _a;
00060
00061 if ( p_struct == NULL )
00062 {
00063 return GLOBAL_MSG_NULL;
00064 }
00065 p_struct->version = GLOBAL_PHSLINE_VERSION;
00066 p_struct->logo.instid = 0;
00067 p_struct->logo.mod = 0;
00068 p_struct->logo.type = 0;
00069 p_struct->sequence = 0;
00070 strcpy( p_struct->station , "?" );
00071 strcpy( p_struct->channel , "?" );
00072 strcpy( p_struct->network , "?" );
00073 strcpy( p_struct->location , "?" );
00074 strcpy( p_struct->pick_time , "?" );
00075 strcpy( p_struct->phase_name , "?" );
00076 p_struct->quality = 0.0;
00077 p_struct->polarity = '?';
00078
00079 for ( _a = 0 ; _a < MAX_AMPS_PER_GLOBALPHASE ; _a++ )
00080 {
00081 InitGlobalAmpLine( &p_struct->amps[_a] );
00082 }
00083
00084 return GLOBAL_MSG_SUCCESS;
00085 }
00086
00087
00088
00089 GLOBAL_MSG_STATUS InitGlobalLoc( GLOBAL_LOC_STRUCT * p_struct )
00090 {
00091 int _i;
00092
00093
00094 if ( p_struct == NULL )
00095 {
00096 return GLOBAL_MSG_NULL;
00097 }
00098
00099 p_struct->version = GLOBAL_LOC_VERSION;
00100 p_struct->logo.instid = 0;
00101 p_struct->logo.mod = 0;
00102 p_struct->logo.type = 0;
00103 p_struct->event_id = 0;
00104 p_struct->origin_id = 0;
00105 strcpy( p_struct->origin_time , "?" );
00106 p_struct->lat = 0.0;
00107 p_struct->lon = 0.0;
00108 p_struct->depth = 0.0;
00109 p_struct->gap = 0.0;
00110 p_struct->dmin = 0.0;
00111 p_struct->rms = 0.0;
00112 p_struct->pick_count = 0;
00113 p_struct->nphs = 0;
00114
00115
00116 for ( _i = 0 ; _i < GLOBAL_LOC_MAXPHS ; _i++ )
00117 {
00118 InitGlobalPhaseLine( &p_struct->phases[_i] );
00119 }
00120
00121 return GLOBAL_MSG_SUCCESS;
00122 }
00123
00124
00125
00126
00127
00128 GLOBAL_MSG_STATUS WriteAmpLineToBuffer( GLOBAL_AMPLINE_STRUCT * p_struct
00129 , char * p_buffer
00130 , unsigned int p_length
00131 )
00132 {
00133 char _author[10];
00134
00135 if ( p_struct == NULL )
00136 {
00137 return GLOBAL_MSG_NULL;
00138 }
00139
00140 if ( p_buffer == NULL )
00141 {
00142 return GLOBAL_MSG_BADPARAM;
00143 }
00144
00145 if ( p_length < GLOBAL_AMPLINE_MAXBUFSIZE )
00146 {
00147 return GLOBAL_MSG_TOOSMALL;
00148 }
00149
00150 if ( p_struct->version != GLOBAL_AMPLINE_VERSION )
00151 {
00152 return GLOBAL_MSG_VERSINVALID;
00153 }
00154
00155 EncodeAuthor( p_struct->logo, _author );
00156
00157 sprintf( p_buffer
00158 , "%s %d %d %s %s %s %s %s %d %1.4f %1.4f\n"
00159 , _author
00160 , p_struct->pick_sequence
00161 , p_struct->version
00162 , p_struct->station
00163 , p_struct->channel
00164 , p_struct->network
00165 , p_struct->location
00166 , p_struct->amp_time
00167 , p_struct->amptype
00168 , p_struct->adcounts
00169 , p_struct->period
00170 );
00171
00172 return GLOBAL_MSG_SUCCESS;
00173 }
00174
00175
00176
00177 GLOBAL_MSG_STATUS WritePhaseLineToBuffer( GLOBAL_PHSLINE_STRUCT * p_struct
00178 , char * p_buffer
00179 , unsigned int p_length
00180 )
00181 {
00182 char _author[10];
00183
00184 if ( p_struct == NULL )
00185 {
00186 return GLOBAL_MSG_NULL;
00187 }
00188
00189 if ( p_buffer == NULL )
00190 {
00191 return GLOBAL_MSG_BADPARAM;
00192 }
00193
00194 if ( p_length < GLOBAL_PHSLINE_MAXBUFSIZE )
00195 {
00196 return GLOBAL_MSG_TOOSMALL;
00197 }
00198
00199 if ( p_struct->version != GLOBAL_PHSLINE_VERSION )
00200 {
00201 return GLOBAL_MSG_VERSINVALID;
00202 }
00203
00204 EncodeAuthor( p_struct->logo, _author );
00205
00206 sprintf( p_buffer
00207 , "%s %d %d %s %s %s %s %s %s %1.4f %c %d\n"
00208 , _author
00209 , p_struct->sequence
00210 , p_struct->version
00211 , p_struct->station
00212 , p_struct->channel
00213 , p_struct->network
00214 , p_struct->location
00215 , p_struct->pick_time
00216 , p_struct->phase_name
00217 , p_struct->quality
00218 , p_struct->polarity
00219 );
00220
00221 return GLOBAL_MSG_SUCCESS;
00222 }
00223
00224
00225
00226 GLOBAL_MSG_STATUS WriteLocToBuffer( GLOBAL_LOC_STRUCT * p_loc
00227 , char * p_buffer
00228 , unsigned int p_length
00229 )
00230 {
00231 GLOBAL_MSG_STATUS r_code = GLOBAL_MSG_SUCCESS;
00232
00233 char * _writelocation = p_buffer;
00234
00235 char _author[10];
00236
00237 int _phaseindex
00238 , _ampindex
00239 ;
00240
00241 GLOBAL_PHSLINE_BUFFER _phs_buffer;
00242
00243 GLOBAL_AMPLINE_BUFFER _amp_buffer;
00244
00245
00246 if ( p_loc == NULL )
00247 {
00248 return GLOBAL_MSG_NULL;
00249 }
00250
00251 if ( p_buffer == NULL )
00252 {
00253 return GLOBAL_MSG_BADPARAM;
00254 }
00255
00256 if ( p_length < (unsigned int)( GLOBAL_LOC_SUM_MAXSIZE
00257 + p_loc->nphs * GLOBAL_PHSLINE_MAXBUFSIZE
00258 )
00259 )
00260 {
00261 return GLOBAL_MSG_TOOSMALL;
00262 }
00263
00264 if ( p_loc->version != GLOBAL_LOC_VERSION )
00265 {
00266 return GLOBAL_MSG_VERSINVALID;
00267 }
00268
00269 EncodeAuthor( p_loc->logo, _author );
00270
00271 sprintf( _writelocation
00272 , "SUM %s %d %d %d %s %.4f %.4f %.3f %.3f %.3f %.3f %d %d\n"
00273 , _author
00274 , p_loc->version
00275 , p_loc->event_id
00276 , p_loc->origin_id
00277 , p_loc->origin_time
00278 , p_loc->lat
00279 , p_loc->lon
00280 , p_loc->depth
00281 , p_loc->gap
00282 , p_loc->dmin
00283 , p_loc->rms
00284 , p_loc->pick_count
00285 , p_loc->nphs
00286 );
00287
00288 _writelocation = p_buffer + strlen(p_buffer);
00289
00290 for ( _phaseindex = 0 ; _phaseindex < p_loc->nphs ; _phaseindex++ )
00291 {
00292 if ( (r_code = WritePhaseLineToBuffer( &p_loc->phases[_phaseindex]
00293 , _phs_buffer
00294 , GLOBAL_PHSLINE_MAXBUFSIZE
00295 ) ) == GLOBAL_MSG_SUCCESS )
00296 {
00297 if ( GLOBAL_LOC_MAXBUFSIZE <= (strlen(p_buffer) + strlen("PHS ") + strlen(_phs_buffer) + 1) )
00298 {
00299 return GLOBAL_MSG_DEFINESMALL;
00300 }
00301 strcat( _writelocation, "PHS " );
00302 strcat( _writelocation, _phs_buffer );
00303
00304 for ( _ampindex = 0 ; _ampindex < MAX_AMPS_PER_GLOBALPHASE ; _ampindex++ )
00305 {
00306 if ( p_loc->phases[_phaseindex].amps[_ampindex].logo.type == 0 )
00307 {
00308
00309 continue;
00310 }
00311
00312 if ( (r_code = WriteAmpLineToBuffer( &p_loc->phases[_phaseindex].amps[_ampindex]
00313 , _amp_buffer
00314 , GLOBAL_AMPLINE_MAXBUFSIZE )
00315 ) == GLOBAL_MSG_SUCCESS )
00316 {
00317 if ( GLOBAL_LOC_MAXBUFSIZE <= (strlen(p_buffer) + strlen("AMP ") + strlen(_amp_buffer) + 1) )
00318 {
00319 return GLOBAL_MSG_DEFINESMALL;
00320 }
00321 strcat( _writelocation, "AMP " );
00322 strcat( _writelocation, _amp_buffer );
00323 }
00324 else
00325 {
00326 return r_code;
00327 }
00328 }
00329 }
00330 else
00331 {
00332 return r_code;
00333 }
00334 }
00335
00336
00337 strcat( p_buffer, "\n" );
00338
00339 return r_code;
00340 }
00341
00342
00343
00344
00345 GLOBAL_MSG_STATUS StringToAmpLine( GLOBAL_AMPLINE_STRUCT * p_amp, char * p_string )
00346 {
00347 char _str[80];
00348
00349 GLOBAL_AMPLINE_BUFFER workbuff;
00350
00351 if ( p_amp == NULL )
00352 {
00353 logit( "", "DEBUG StringToAmpLine() FAILURE A\n");
00354 return GLOBAL_MSG_NULL;
00355 }
00356
00357 if ( p_string == NULL )
00358 {
00359 logit( "", "DEBUG StringToAmpLine() FAILURE C\n");
00360 return GLOBAL_MSG_BADPARAM;
00361 }
00362
00363 InitGlobalAmpLine(p_amp);
00364
00365 if ( GLOBAL_AMPLINE_MAXBUFSIZE < strlen( p_string ) )
00366 {
00367 strncpy( workbuff , p_string , GLOBAL_AMPLINE_MAXBUFSIZE );
00368 workbuff[GLOBAL_AMPLINE_MAXBUFSIZE] = '\0';
00369 }
00370 else
00371 {
00372 strcpy( workbuff, p_string );
00373 }
00374
00375 k_put(workbuff);
00376
00377
00378 strcpy( _str , k_str() );
00379 if ( strlen(_str) == 0 )
00380 {
00381 logit( "", "DEBUG StringToAmpLine() FAILURE D\n");
00382 return GLOBAL_MSG_FORMATERROR;
00383 }
00384
00385 if ( DecodeAuthor( &(p_amp->logo), _str ) != GLOBAL_MSG_SUCCESS )
00386 {
00387 logit( "", "DEBUG StringToAmpLine() FAILURE E\n");
00388 return GLOBAL_MSG_FORMATERROR;
00389 }
00390
00391
00392 p_amp->pick_sequence = k_long();
00393 if ( k_err() != 0 )
00394 {
00395 logit( "", "DEBUG StringToAmpLine() FAILURE F\n");
00396 return GLOBAL_MSG_FORMATERROR;
00397 }
00398
00399
00400 p_amp->version = (short)k_long();
00401 if ( k_err() != 0 )
00402 {
00403 logit( "", "DEBUG StringToAmpLine() FAILURE F\n");
00404 return GLOBAL_MSG_FORMATERROR;
00405 }
00406
00407 if ( p_amp->version != GLOBAL_AMPLINE_VERSION )
00408 {
00409 logit( "", "DEBUG StringToAmpLine() FAILURE G\n");
00410 return GLOBAL_MSG_VERSINVALID;
00411 }
00412
00413
00414 strcpy( p_amp->station , k_str() );
00415 if ( strlen(p_amp->station) == 0 )
00416 {
00417 logit( "", "DEBUG StringToAmpLine() FAILURE H\n");
00418 return GLOBAL_MSG_FORMATERROR;
00419 }
00420
00421
00422 strcpy( p_amp->channel , k_str() );
00423 if ( strlen(p_amp->channel) == 0 )
00424 {
00425 logit( "", "DEBUG StringToAmpLine() FAILURE I\n");
00426 return GLOBAL_MSG_FORMATERROR;
00427 }
00428
00429
00430 strcpy( p_amp->network , k_str() );
00431 if ( strlen(p_amp->network) == 0 )
00432 {
00433 logit( "", "DEBUG StringToAmpLine() FAILURE J\n");
00434 return GLOBAL_MSG_FORMATERROR;
00435 }
00436
00437
00438 strcpy( p_amp->location , k_str() );
00439 if ( strlen(p_amp->location) == 0 )
00440 {
00441 logit( "", "DEBUG StringToAmpLine() FAILURE K\n");
00442 return GLOBAL_MSG_FORMATERROR;
00443 }
00444
00445
00446 strcpy( p_amp->amp_time , k_str() );
00447 if ( strlen(p_amp->amp_time) == 0 )
00448 {
00449 logit( "", "DEBUG StringToAmpLine() FAILURE L\n");
00450 return GLOBAL_MSG_FORMATERROR;
00451 }
00452
00453
00454 p_amp->amptype = (int)k_long();
00455 if ( k_err() != 0 )
00456 {
00457 logit( "", "DEBUG StringToAmpLine() FAILURE M\n");
00458 return GLOBAL_MSG_FORMATERROR;
00459 }
00460
00461
00462 p_amp->adcounts = k_val();
00463 if ( k_err() != 0 )
00464 {
00465 logit( "", "DEBUG StringToAmpLine() FAILURE N\n");
00466 return GLOBAL_MSG_FORMATERROR;
00467 }
00468
00469
00470 p_amp->period = k_val();
00471 if ( k_err() != 0 )
00472 {
00473 logit( "", "DEBUG StringToAmpLine() FAILURE O\n");
00474 return GLOBAL_MSG_FORMATERROR;
00475 }
00476
00477 return GLOBAL_MSG_SUCCESS;
00478 }
00479
00480
00481
00482 GLOBAL_MSG_STATUS StringToPhaseLine( GLOBAL_PHSLINE_STRUCT * p_struct, char * p_string )
00483 {
00484 char _str[80];
00485
00486 GLOBAL_PHSLINE_SUM_BUFFER workbuff;
00487
00488 if ( p_struct == NULL )
00489 {
00490 logit( "", "DEBUG StringToPhaseLine() FAILURE A\n");
00491 return GLOBAL_MSG_NULL;
00492 }
00493
00494 if ( p_string == NULL )
00495 {
00496 logit( "", "DEBUG StringToPhaseLine() FAILURE C\n");
00497 return GLOBAL_MSG_BADPARAM;
00498 }
00499
00500 InitGlobalPhaseLine(p_struct);
00501
00502 if ( GLOBAL_PHSLINE_SUM_MAXSIZE < strlen( p_string ) )
00503 {
00504 strncpy( workbuff , p_string , GLOBAL_PHSLINE_SUM_MAXSIZE );
00505 workbuff[GLOBAL_PHSLINE_SUM_MAXSIZE] = '\0';
00506 }
00507 else
00508 {
00509 strcpy( workbuff, p_string );
00510 }
00511
00512 k_put(workbuff);
00513
00514
00515 strcpy( _str , k_str() );
00516
00517 if ( strlen(_str) == 0 )
00518 {
00519 logit( "", "DEBUG StringToPhaseLine() FAILURE D\n");
00520 return GLOBAL_MSG_FORMATERROR;
00521 }
00522
00523 if ( DecodeAuthor( &(p_struct->logo), _str ) != GLOBAL_MSG_SUCCESS )
00524 {
00525 logit( "", "DEBUG StringToPhaseLine() FAILURE E\n");
00526 return GLOBAL_MSG_FORMATERROR;
00527 }
00528
00529
00530 p_struct->sequence = k_long();
00531 if ( k_err() != 0 )
00532 {
00533 logit( "", "DEBUG StringToPhaseLine() FAILURE F\n");
00534 return GLOBAL_MSG_FORMATERROR;
00535 }
00536
00537
00538 p_struct->version = (short)k_long();
00539 if ( k_err() != 0 )
00540 {
00541 logit( "", "DEBUG StringToPhaseLine() FAILURE G\n");
00542 return GLOBAL_MSG_FORMATERROR;
00543 }
00544
00545 if ( p_struct->version != GLOBAL_PHSLINE_VERSION )
00546 {
00547 logit( "", "DEBUG StringToPhaseLine() FAILURE H\n");
00548 return GLOBAL_MSG_VERSINVALID;
00549 }
00550
00551
00552 strcpy( p_struct->station , k_str() );
00553 if ( strlen(p_struct->station) == 0 )
00554 {
00555 logit( "", "DEBUG StringToPhaseLine() FAILURE I\n");
00556 return GLOBAL_MSG_FORMATERROR;
00557 }
00558
00559
00560 strcpy( p_struct->channel , k_str() );
00561 if ( strlen(p_struct->channel) == 0 )
00562 {
00563 logit( "", "DEBUG StringToPhaseLine() FAILURE J\n");
00564 return GLOBAL_MSG_FORMATERROR;
00565 }
00566
00567
00568 strcpy( p_struct->network , k_str() );
00569 if ( strlen(p_struct->network) == 0 )
00570 {
00571 logit( "", "DEBUG StringToPhaseLine() FAILURE K\n");
00572 return GLOBAL_MSG_FORMATERROR;
00573 }
00574
00575
00576 strcpy( p_struct->location , k_str() );
00577 if ( strlen(p_struct->location) == 0 )
00578 {
00579 logit( "", "DEBUG StringToPhaseLine() FAILURE L\n");
00580 return GLOBAL_MSG_FORMATERROR;
00581 }
00582
00583
00584 strcpy( p_struct->pick_time , k_str() );
00585 if ( strlen(p_struct->pick_time) == 0 )
00586 {
00587 logit( "", "DEBUG StringToPhaseLine() FAILURE M\n");
00588 return GLOBAL_MSG_FORMATERROR;
00589 }
00590
00591
00592 strcpy( p_struct->phase_name , k_str() );
00593 if ( strlen(p_struct->phase_name) == 0 )
00594 {
00595 logit( "", "DEBUG StringToPhaseLine() FAILURE N\n");
00596 return GLOBAL_MSG_FORMATERROR;
00597 }
00598
00599
00600 p_struct->quality = k_val();
00601 if ( k_err() != 0 )
00602 {
00603 logit( "", "DEBUG StringToPhaseLine() FAILURE O\n");
00604 return GLOBAL_MSG_FORMATERROR;
00605 }
00606
00607
00608 strcpy( _str, k_str() );
00609 if ( strlen(_str) == 0 )
00610 {
00611 logit( "", "DEBUG StringToPhaseLine() FAILURE P\n");
00612 return GLOBAL_MSG_FORMATERROR;
00613 }
00614 p_struct->polarity = _str[0];
00615
00616
00617 return GLOBAL_MSG_SUCCESS;
00618 }
00619
00620
00621
00622 GLOBAL_MSG_STATUS StringToLoc( GLOBAL_LOC_STRUCT * p_loc, char * p_string )
00623 {
00624
00625
00626
00627
00628
00629
00630 GLOBAL_PHSLINE_STRUCT * _phs_pointer = NULL;
00631
00632 GLOBAL_AMPLINE_STRUCT _amp_data;
00633
00634 GLOBAL_MSG_STATUS _processresult;
00635
00636 char * _readpoint = p_string
00637 , * _linemark
00638 ;
00639
00640 int _phscount;
00641
00642 char _readingchildren = 1;
00643
00644 char _str[80];
00645
00646 GLOBAL_LOC_SUM_BUFFER sumbuff;
00647 int _index;
00648
00649 if ( p_string == NULL )
00650 {
00651 return GLOBAL_MSG_NULL;
00652 }
00653
00654 InitGlobalLoc(p_loc);
00655
00656
00657 if ( (_linemark = strchr( _readpoint, '\n' )) == NULL )
00658 {
00659
00660 logit( "", "DEBUG StringToLoc() FAILURE A\n");
00661 return GLOBAL_MSG_FORMATERROR;
00662 }
00663
00664 _index = _linemark - _readpoint;
00665
00666 strncpy( sumbuff , _readpoint , _index );
00667 sumbuff[_index] = '\0';
00668
00669 k_put(sumbuff);
00670
00671
00672 strcpy( _str , k_str() );
00673 if ( strcmp(_str, "SUM") != 0 )
00674 {
00675 logit( "", "DEBUG StringToLoc() FAILURE B\n");
00676 return GLOBAL_MSG_FORMATERROR;
00677 }
00678
00679
00680 strcpy( _str , k_str() );
00681 if ( strlen(_str) == 0 )
00682 {
00683 logit( "", "DEBUG StringToLoc() FAILURE C\n");
00684 return GLOBAL_MSG_FORMATERROR;
00685 }
00686
00687 if ( DecodeAuthor( &(p_loc->logo), _str ) != GLOBAL_MSG_SUCCESS )
00688 {
00689 logit( "", "DEBUG StringToLoc() FAILURE D\n");
00690 return GLOBAL_MSG_FORMATERROR;
00691 }
00692
00693
00694 p_loc->version = (short)k_long();
00695 if ( k_err() != 0 )
00696 {
00697 logit( "", "DEBUG StringToLoc() FAILURE E\n");
00698 return GLOBAL_MSG_FORMATERROR;
00699 }
00700
00701
00702 if ( p_loc->version != GLOBAL_LOC_VERSION )
00703 {
00704 logit( "", "DEBUG StringToLoc() FAILURE E 2\n");
00705 return GLOBAL_MSG_VERSINVALID;
00706 }
00707
00708
00709
00710 p_loc->event_id = k_long();
00711 if ( k_err() != 0 )
00712 {
00713 logit( "", "DEBUG StringToLoc() FAILURE F\n");
00714 return GLOBAL_MSG_FORMATERROR;
00715 }
00716
00717
00718
00719 p_loc->origin_id = k_long();
00720 if ( k_err() != 0 )
00721 {
00722 logit( "", "DEBUG StringToLoc() FAILURE G\n");
00723 return GLOBAL_MSG_FORMATERROR;
00724 }
00725
00726
00727
00728 strcpy( p_loc->origin_time , k_str() );
00729 if ( strlen(p_loc->origin_time) == 0 )
00730 {
00731 logit( "", "DEBUG StringToLoc() FAILURE H\n");
00732 return GLOBAL_MSG_FORMATERROR;
00733 }
00734
00735
00736
00737 p_loc->lat = k_val();
00738 if ( k_err() != 0 )
00739 {
00740 logit( "", "DEBUG StringToLoc() FAILURE I\n");
00741 return GLOBAL_MSG_FORMATERROR;
00742 }
00743
00744
00745 p_loc->lon = k_val();
00746 if ( k_err() != 0 )
00747 {
00748 logit( "", "DEBUG StringToLoc() FAILURE J\n");
00749 return GLOBAL_MSG_FORMATERROR;
00750 }
00751
00752
00753 p_loc->depth = (float)k_val();
00754 if ( k_err() != 0 )
00755 {
00756 logit( "", "DEBUG StringToLoc() FAILURE K\n");
00757 return GLOBAL_MSG_FORMATERROR;
00758 }
00759
00760
00761
00762 p_loc->gap = (float)k_val();
00763 if ( k_err() != 0 )
00764 {
00765 logit( "", "DEBUG StringToLoc() FAILURE L\n");
00766 return GLOBAL_MSG_FORMATERROR;
00767 }
00768
00769
00770 p_loc->dmin = (float)k_val();
00771 if ( k_err() != 0 )
00772 {
00773 logit( "", "DEBUG StringToLoc() FAILURE M\n");
00774 return GLOBAL_MSG_FORMATERROR;
00775 }
00776
00777
00778 p_loc->rms = (float)k_val();
00779 if ( k_err() != 0 )
00780 {
00781 logit( "", "DEBUG StringToLoc() FAILURE N\n");
00782 return GLOBAL_MSG_FORMATERROR;
00783 }
00784
00785
00786
00787 p_loc->pick_count = (int)k_long();
00788 if ( k_err() != 0 )
00789 {
00790 logit( "", "DEBUG StringToLoc() FAILURE O\n");
00791 return GLOBAL_MSG_FORMATERROR;
00792 }
00793
00794
00795
00796
00797 _phscount = (int)k_long();
00798 if ( k_err() != 0 )
00799 {
00800 logit( "", "DEBUG StringToLoc() FAILURE P\n");
00801 return GLOBAL_MSG_FORMATERROR;
00802 }
00803
00804
00805
00806 do
00807 {
00808
00809 _readpoint = _linemark + 1;
00810
00811
00812
00813
00814 if ( *_readpoint == '\n' || *_readpoint == '\r' )
00815 {
00816
00817 _readingchildren = 0;
00818 break;
00819 }
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829 if ( strncmp( _readpoint, "PHS ", 4 ) == 0 )
00830 {
00831
00832
00833 if ( p_loc->nphs == GLOBAL_LOC_MAXPHS )
00834 {
00835
00836 logit( "", "DEBUG StringToLoc() FAILURE Q\n");
00837 return GLOBAL_MSG_MAXCHILDREN;
00838 }
00839
00840
00841 _readpoint += 4;
00842
00843
00844 if ( (_linemark = strchr( _readpoint, '\n' )) == NULL )
00845 {
00846
00847 logit( "", "DEBUG StringToLoc() FAILURE R\n");
00848 return GLOBAL_MSG_FORMATERROR;
00849 }
00850
00851
00852 *_linemark = '\0';
00853
00854 _phs_pointer = &p_loc->phases[p_loc->nphs];
00855
00856
00857 if ( (_processresult = StringToPhaseLine( _phs_pointer, _readpoint )) != GLOBAL_MSG_SUCCESS )
00858 {
00859 logit( "", "DEBUG StringToLoc() FAILURE S\n");
00860 return _processresult;
00861 }
00862
00863
00864
00865 p_loc->nphs++;
00866
00867
00868
00869 }
00870 else if ( strncmp( _readpoint, "AMP ", 4 ) == 0 )
00871 {
00872
00873
00874 if ( p_loc->nphs == 0 || _phs_pointer == NULL )
00875 {
00876
00877
00878
00879
00880 logit( "", "DEBUG StringToLoc() FAILURE T\n");
00881 return GLOBAL_MSG_FORMATERROR;
00882 }
00883
00884
00885
00886 _readpoint += 4;
00887
00888
00889 if ( (_linemark = strchr( _readpoint, '\n' )) == NULL )
00890 {
00891
00892 logit( "", "DEBUG StringToLoc() FAILURE V\n");
00893 return GLOBAL_MSG_FORMATERROR;
00894 }
00895
00896
00897 *_linemark = '\0';
00898
00899
00900
00901 if ( (_processresult = StringToAmpLine( &_amp_data, _readpoint )) != GLOBAL_MSG_SUCCESS )
00902 {
00903 logit( "", "DEBUG StringToLoc() FAILURE W\n");
00904 return _processresult;
00905 }
00906
00907
00908 if ( (_processresult = AddAmpLineToPhase( _phs_pointer, &_amp_data )) < 0 )
00909 {
00910 logit( "", "DEBUG StringToLoc() FAILURE X\n");
00911 return _processresult;
00912 }
00913
00914
00915
00916 }
00917 else
00918 {
00919
00920 logit( "", "DEBUG StringToLoc() FAILURE Y\n>%s<\n", _readpoint);
00921 return GLOBAL_MSG_BADCHILD;
00922 }
00923
00924 } while( _readingchildren == 1 );
00925
00926 if ( p_loc->nphs != _phscount )
00927 {
00928 logit( "", "DEBUG StringToLoc() FAILURE Z\n");
00929 return GLOBAL_MSG_FORMATERROR;
00930 }
00931
00932 return GLOBAL_MSG_SUCCESS;
00933 }
00934
00935
00936
00937
00938
00939 int AddAmpLineToPhase( GLOBAL_PHSLINE_STRUCT * p_phase
00940 , GLOBAL_AMPLINE_STRUCT * p_amp
00941 )
00942 {
00943 GLOBAL_AMPLINE_STRUCT * _destin;
00944
00945 int ampindex = GLOBAL_MSG_BADAMPTYPE;
00946
00947 if ( p_phase == NULL || p_amp == NULL )
00948 {
00949 return GLOBAL_MSG_NULL;
00950 }
00951
00952 if ( p_phase->version != GLOBAL_PHSLINE_VERSION )
00953 {
00954 return GLOBAL_MSG_VERSINVALID;
00955 }
00956
00957 if ( p_amp->version != GLOBAL_AMPLINE_VERSION )
00958 {
00959 return GLOBAL_MSG_BADPARAM;
00960 }
00961
00962
00963 ampindex = p_amp->amptype - 1;
00964
00965 if ( 0 <= ampindex && ampindex < MAX_AMPS_PER_GLOBALPHASE )
00966 {
00967 _destin = &p_phase->amps[ampindex];
00968
00969 _destin->logo.type = p_amp->logo.type;
00970 _destin->logo.mod = p_amp->logo.mod;
00971 _destin->logo.instid = p_amp->logo.instid;
00972 _destin->pick_sequence = p_amp->pick_sequence;
00973 _destin->version = p_amp->version;
00974 strcpy( _destin->station , p_amp->station );
00975 strcpy( _destin->channel , p_amp->channel );
00976 strcpy( _destin->network , p_amp->network );
00977 strcpy( _destin->location , p_amp->location );
00978 strcpy( _destin->amp_time , p_amp->amp_time );
00979 _destin->amptype = p_amp->amptype;
00980 _destin->adcounts = p_amp->adcounts;
00981 _destin->period = p_amp->period;
00982
00983 }
00984
00985 return ampindex;
00986 }
00987
00988
00989
00990 int AddPhaseLineToLoc( GLOBAL_LOC_STRUCT * p_loc
00991 , GLOBAL_PHSLINE_STRUCT * p_phase
00992 )
00993 {
00994 int r_code;
00995
00996 GLOBAL_PHSLINE_STRUCT * _destin;
00997
00998 short _a;
00999
01000 if ( p_loc == NULL || p_phase == NULL )
01001 {
01002 return GLOBAL_MSG_NULL;
01003 }
01004
01005 if ( p_loc->version != GLOBAL_LOC_VERSION )
01006 {
01007 return GLOBAL_MSG_VERSINVALID;
01008 }
01009
01010 if ( p_phase->version != GLOBAL_PHSLINE_VERSION )
01011 {
01012 return GLOBAL_MSG_BADPARAM;
01013 }
01014
01015 if ( p_loc->nphs == GLOBAL_LOC_MAXPHS )
01016 {
01017 return GLOBAL_MSG_MAXCHILDREN;
01018 }
01019
01020 _destin = &p_loc->phases[p_loc->nphs];
01021
01022 _destin->version = p_phase->version;
01023 _destin->logo.type = p_phase->logo.type;
01024 _destin->logo.mod = p_phase->logo.mod;
01025 _destin->logo.instid = p_phase->logo.instid;
01026 _destin->sequence = p_phase->sequence;
01027 strcpy( _destin->station , p_phase->station );
01028 strcpy( _destin->channel , p_phase->channel );
01029 strcpy( _destin->network , p_phase->network );
01030 strcpy( _destin->location , p_phase->location );
01031 strcpy( _destin->pick_time , p_phase->pick_time );
01032 strcpy( _destin->phase_name , p_phase->phase_name );
01033 _destin->quality = p_phase->quality;
01034 _destin->polarity = p_phase->polarity;
01035
01036 for ( _a = 0 ; _a < MAX_AMPS_PER_GLOBALPHASE ; _a++ )
01037 {
01038 if ( p_phase->amps[_a].logo.type == 0 )
01039 {
01040 continue;
01041 }
01042 if ( (r_code = AddAmpLineToPhase( _destin, &p_phase->amps[_a] )) < 0 )
01043 {
01044 return r_code;
01045 }
01046 }
01047
01048 p_loc->nphs++;
01049
01050 return p_loc->nphs - 1;
01051 }
01052
01053
01054
01055
01056
01057 int GetLocPhaseIndex( GLOBAL_LOC_STRUCT * p_loc
01058 , GLOBAL_PHSLINE_STRUCT * p_phase
01059 )
01060 {
01061 int r_index = 0
01062 , _idx = 0
01063 ;
01064
01065 for ( ; _idx < p_loc->nphs ; _idx++ )
01066 {
01067 if ( p_phase->sequence == p_loc->phases[_idx].sequence
01068 && p_phase->logo.mod == p_loc->phases[_idx].logo.mod
01069 && p_phase->logo.instid == p_loc->phases[_idx].logo.instid
01070 )
01071 {
01072
01073 r_index = _idx;
01074 break;
01075 }
01076 }
01077
01078 return r_index;
01079 }
01080
01081
01082
01083
01084
01085 GLOBAL_MSG_STATUS ClearAmpLines( GLOBAL_PHSLINE_STRUCT * p_phase )
01086 {
01087 int _a;
01088
01089 if ( p_phase == NULL )
01090 {
01091 return GLOBAL_MSG_NULL;
01092 }
01093 if ( p_phase->version != GLOBAL_LOC_VERSION )
01094 {
01095 return GLOBAL_MSG_VERSINVALID;
01096 }
01097 for ( _a = 0 ; _a < MAX_AMPS_PER_GLOBALPHASE ; _a++ )
01098 {
01099 InitGlobalAmpLine( &p_phase->amps[_a] );
01100 }
01101 return GLOBAL_MSG_SUCCESS;
01102 }
01103
01104
01105
01106 GLOBAL_MSG_STATUS ClearPhaseLines( GLOBAL_LOC_STRUCT * p_loc )
01107 {
01108 if ( p_loc == NULL )
01109 {
01110 return GLOBAL_MSG_NULL;
01111 }
01112 if ( p_loc->version != GLOBAL_LOC_VERSION )
01113 {
01114 return GLOBAL_MSG_VERSINVALID;
01115 }
01116 p_loc->nphs = 0;
01117 return GLOBAL_MSG_SUCCESS;
01118 }
01119
01120
01121
01122
01123
01124
01125
01126