00001 #ident "$Header: /home/cvsuser/cvsroot/JSOC/proj/lev0/apps/save_packet_to_dayfile.c,v 1.17 2014/08/27 19:20:38 prodtest Exp $"
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include "decode_hk.h"
00013 #include "packets.h"
00014 #include "save_packet_to_dayfile.h"
00015 #include "decode_hk_vcdu.h"
00016 #include <sys/time.h>
00017 #include <time.h>
00018 #include "timeio.h"
00019 #include <dirent.h>
00020 #include "printk.h"
00021 #include <errno.h>
00022
00023
00024 int check_filename_apid(char *fn, int apid);
00025 int check_filename_pkt_time(char *fn, unsigned short *word_ptr);
00026 int check_for_pkt_time( HK_Dayfile_Data_t **fdfd, unsigned short *word_ptr);
00027 int check_dfd_file( unsigned short *word_ptr, int apid);
00028 int check_for_dfd(int apid, HK_Dayfile_Data_t *dfd, HK_Dayfile_Data_t **fdfd);
00029 int free_dayfile_data( HK_Dayfile_Data_t **df_head);
00030 int free_dayfile_pkt_data( HK_Dayfile_Data_t **df_head);
00031 double get_packet_time(unsigned short *word_ptr);
00032 char *get_dayfilename(int apid, double tc_sec);
00033 int get_day_from_pkttime(double tc_sec);
00034 int get_hour_from_pkttime(double tc_sec);
00035 int get_month_from_pkttime(double tc_sec);
00036 int get_yr_from_pkttime(double tc_sec);
00037 int load_dfd_node(unsigned short *word_ptr,HK_Dayfile_Data_t **df_head);
00038 int load_packet_data( unsigned short *word_ptr, HK_Dayfile_Packet_t **pkt);
00039 void set_time_values(HK_Dayfile_Data_t **dn, double tcsec);
00040 int write_packet_to_dayfile(HK_Dayfile_Data_t **df_head);
00041
00042
00043 static TIME SDO_to_DRMS_time(int sdo_s, int sdo_ss);
00044 extern void sprint_time (char *at, TIME t, char *zone, int precision);
00045
00046
00047 char *do_date() {
00048 time_t tval;
00049 struct tm *t_ptr;
00050 char datestring[32];
00051
00052 tval = time(NULL);
00053 t_ptr = localtime(&tval);
00054 sprintf(datestring, "%d.%02d.%02d_%02d:%02d:%02d",
00055 (t_ptr->tm_year+1900), (t_ptr->tm_mon+1),
00056 t_ptr->tm_mday, t_ptr->tm_hour, t_ptr->tm_min, t_ptr->tm_sec);
00057 return(datestring);
00058 }
00059
00060
00061
00062
00063 int save_packet_to_dayfile(unsigned short *word_ptr, int apid, HK_Dayfile_Data_t **df_head)
00064 {
00065
00066 HK_Dayfile_Packet_t *pkt, *temp_pkt,*prev_pkt;
00067 HK_Dayfile_Data_t *dd, *dd_tmp, *found_dfd;
00068 int wdf_status;
00069 int ldfd_status;
00070
00071
00072 if(!load_packet_data( word_ptr, &pkt))
00073 {
00074 printkerr("ERROR at %s, line %d: Could not load packet data to "
00075 "day file data structure.\n"
00076 __FILE__, __LINE__);
00077 }
00078
00079
00080
00081 if (*df_head == NULL)
00082 {
00083 ldfd_status = load_dfd_node(word_ptr, &dd_tmp);
00084 if (ldfd_status == ERROR_HK_ENVIRONMENT_VARS_NOT_SET)
00085 {
00086 return (ERROR_HK_ENVIRONMENT_VARS_NOT_SET);
00087 }
00088
00089 if(ldfd_status == HK_DF_DAYFILE_LOAD_SUCCESS)
00090 {
00091 *df_head= dd_tmp;
00092 }
00093 }
00094
00095
00096
00097 if (*df_head == NULL)
00098 {
00099
00100 dd = malloc(sizeof(HK_Dayfile_Data_t));
00101 if(!dd)
00102 {
00103 printkerr("ERROR at %s, line %d: Could not malloc space!\n", __FILE__, __LINE__);
00104 }
00105
00106
00107 dd->apid=(short)apid;
00108 (void)set_time_values(&dd, get_packet_time(word_ptr));
00109
00110
00111 strcpy(dd->dayfile, get_dayfilename(dd->apid, get_packet_time(word_ptr)));
00112
00113
00114 dd->next=NULL;
00115
00116
00117 dd->pkt=pkt;
00118
00119
00120 *df_head = dd_tmp = dd;
00121 }
00122 else
00123 {
00124
00125
00126 dd_tmp= *df_head;
00127 if (check_for_dfd(apid, dd_tmp, &found_dfd))
00128 {
00129
00130
00131 if (check_for_pkt_time( &found_dfd, word_ptr))
00132 {
00133 ;
00134 }
00135 else
00136 {
00137
00138 if (check_dfd_file(word_ptr, apid))
00139 {
00140
00141 wdf_status= write_packet_to_dayfile( &dd_tmp);
00142 if (wdf_status == 0)
00143 {
00144 return (ERROR_HK_ENVIRONMENT_VARS_NOT_SET);
00145 }
00146 wdf_status= free_dayfile_data( &dd_tmp);
00147
00148
00149 ldfd_status = load_dfd_node(word_ptr, &dd_tmp);
00150 if (ldfd_status == ERROR_HK_ENVIRONMENT_VARS_NOT_SET)
00151 {
00152 return (ERROR_HK_ENVIRONMENT_VARS_NOT_SET);
00153 }
00154
00155
00156 *df_head=dd_tmp;
00157
00158
00159 if (check_for_dfd(apid, dd_tmp, &found_dfd))
00160 {
00161 ;
00162 }
00163 }
00164 else
00165 {
00166
00167
00168 wdf_status = write_packet_to_dayfile( &dd_tmp);
00169 if (wdf_status == 0)
00170 {
00171 return (ERROR_HK_ENVIRONMENT_VARS_NOT_SET);
00172 }
00173 wdf_status = free_dayfile_pkt_data( &dd_tmp);
00174
00175
00176 strcpy(found_dfd->dayfile, get_dayfilename(found_dfd->apid, get_packet_time(word_ptr)));
00177 (void)set_time_values(&found_dfd, get_packet_time(word_ptr));
00178 }
00179 }
00180
00181
00182 temp_pkt = found_dfd->pkt;
00183
00184
00185 if (temp_pkt)
00186 {
00187
00188
00189 for(prev_pkt=temp_pkt; temp_pkt; prev_pkt=temp_pkt,temp_pkt = temp_pkt->next);
00190
00191
00192 prev_pkt->next=pkt;
00193 }
00194 else
00195 {
00196
00197 found_dfd->pkt=pkt;
00198 }
00199 }
00200 else
00201 {
00202
00203 dd = malloc(sizeof(HK_Dayfile_Data_t));
00204 if(!dd)
00205 {
00206 printkerr("ERROR at %s, line %d: Could not malloc space!\n", __FILE__, __LINE__);
00207 }
00208 dd->apid=(short)apid;
00209 (void)set_time_values(&dd, get_packet_time(word_ptr));
00210 strcpy(dd->dayfile, get_dayfilename(dd->apid, get_packet_time(word_ptr)));
00211 dd->next=NULL;
00212
00213
00214 dd_tmp= *df_head;
00215 while ( dd_tmp->next)
00216 {
00217 dd_tmp= dd_tmp->next;
00218 }
00219 dd_tmp->next = dd;
00220
00221
00222 dd->pkt=pkt;
00223 }
00224 }
00225 return (HK_SUCCESS_WRITE_DAYFILE);
00226 }
00227
00228
00229
00230
00231 double get_packet_time(unsigned short *word_ptr)
00232 {
00233
00234 TIME pkt_time;
00235 double tc;
00236 unsigned int *wptr;
00237 unsigned int pkt_secs;
00238 unsigned int pkt_subsecs;
00239
00240
00241 wptr = (unsigned int*)(word_ptr+3);
00242
00243 pkt_secs = (unsigned int) ( (*wptr) >> 24 & 0x000000FF);
00244
00245 pkt_secs |= (unsigned int) ( (*wptr) >> 8 & 0x0000FF00);
00246
00247 pkt_secs |= (unsigned int) ( (*wptr) << 24 & 0xFF000000);
00248
00249 pkt_secs |= (unsigned int) ( (*wptr) << 8 & 0x00FF0000);
00250
00251
00252 wptr = (unsigned int*)(word_ptr+5);
00253
00254 pkt_subsecs = (unsigned int) ( (*wptr) >> 24 & 0x000000FF);
00255
00256 pkt_subsecs |= (unsigned int) ( (*wptr) >> 8 & 0x0000FF00);
00257
00258 pkt_subsecs |= (unsigned int) ( (*wptr) << 24 & 0xFF000000);
00259
00260 pkt_subsecs |= (unsigned int) ( (*wptr) << 8 & 0x00FF0000);
00261
00262
00263 int shifted_ss=(pkt_subsecs >> 16) & 0xFFFF;
00264 pkt_time = SDO_to_DRMS_time(pkt_secs, shifted_ss);
00265
00266 tc=pkt_time;
00267 return tc;
00268 }
00269
00270
00271
00272
00273 int load_packet_data( unsigned short *word_ptr, HK_Dayfile_Packet_t **pkt)
00274 {
00275 HK_Dayfile_Packet_t *pp;
00276 char vn[10];
00277 char *ptr_vn;
00278 int i;
00279 unsigned short w;
00280
00281
00282 ptr_vn =vn;
00283
00284
00285 pp = malloc(sizeof(HK_Dayfile_Packet_t));
00286 if(!pp)
00287 {
00288 printkerr("ERROR at %s, line %d: Could not malloc space!\n", __FILE__, __LINE__);
00289 }
00290
00291
00292 w = word_ptr[7];
00293 sprintf(ptr_vn, "%d.%d", w & 0x00FF, w >> 8 & 0x00FF );
00294
00295
00296 w = word_ptr[2];
00297 pp->length = (unsigned short)((w >> 8 & 0x00FF) + (w & 0x00FF));
00298
00299
00300 for (i = 0 ; i < pp->length/2 + 4; i++)
00301 {
00302 pp->value[i]=word_ptr[i] ;
00303 }
00304 pp->next=NULL;
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 *pkt =pp;
00322 return (HK_DF_LOAD_PACKET_SUCCESS);
00323 }
00324
00325
00326
00327
00328 int check_for_dfd(int apid, HK_Dayfile_Data_t *dfd, HK_Dayfile_Data_t **fdfd)
00329 {
00330
00331 HK_Dayfile_Data_t *dfd_t, *found_dfd;
00332
00333
00334 dfd_t=dfd;
00335
00336
00337 while (dfd_t)
00338 {
00339
00340 if (dfd_t->apid == apid)
00341 {
00342 found_dfd=dfd_t;
00343 *fdfd=found_dfd;
00344 return (HK_DF_CHECK_FOUND);
00345 }
00346 dfd_t=dfd_t->next;
00347 }
00348 found_dfd=NULL;
00349 return (HK_DF_CHECK_NOT_FOUND);
00350 }
00351
00352
00353
00354
00355 int write_packet_to_dayfile(HK_Dayfile_Data_t **df_head)
00356 {
00357
00358 FILE *file_ptr;
00359 HK_Dayfile_Packet_t *pp;
00360 HK_Dayfile_Data_t *dd;
00361 char filename[MAX_FILE_NAME];
00362 char dn[MAX_DIRECTORY_NAME];
00363 char *p_dn;
00364
00365
00366 p_dn = getenv("HK_DF_HSB_DIRECTORY");
00367 if(!p_dn)
00368 {
00369 printkerr("ERROR at %s, line %d: Could not get directory environment "
00370 "variable:<HK_DF_HSB_DIRECTORY>. Set the env variable "
00371 "HK_DF_HSB_DIRECTORY to existing directory name. \n",
00372 __FILE__,__LINE__);
00373 return ( ERROR_HK_ENVIRONMENT_VARS_NOT_SET );
00374 }
00375 strcpy(dn,p_dn);
00376
00377
00378 dd= *df_head;
00379 while (dd)
00380 {
00381
00382
00383
00384
00385 sprintf(filename,"%s/%s",dn, dd->dayfile);
00386
00387
00388 file_ptr = fopen( filename ,"a");
00389 if(!file_ptr)
00390 {
00391 printkerr("ERROR errno=%d at %s, line %d %s: Could not open file at:"
00392 "<%s>. Check have permission "
00393 "to write to directory or check if directory exists. \n",
00394 errno, __FILE__,__LINE__, do_date(), filename);
00395 return ( ERROR_HK_FAILED_OPEN_DAYFILE);
00396 }
00397
00398
00399
00400 for( pp = dd->pkt; pp ; pp=pp->next)
00401 {
00402 fwrite(pp->value,1, pp->length + 7,file_ptr);
00403 }
00404
00405
00406 if (file_ptr)
00407 {
00408 fclose(file_ptr);
00409 }
00410
00411
00412 dd=dd->next;
00413 }
00414 return (HK_SUCCESS_WRITE_DAYFILE);
00415 }
00416
00417
00418
00419
00420 int free_dayfile_pkt_data( HK_Dayfile_Data_t **df_head)
00421 {
00422
00423 HK_Dayfile_Data_t *dfd, *t_dfd;
00424 HK_Dayfile_Packet_t *pp, *t_pp;
00425
00426 dfd= *df_head;
00427 if (dfd)
00428 {
00429
00430 t_dfd= dfd;
00431 while (t_dfd)
00432 {
00433
00434
00435 for ( pp=t_dfd->pkt; pp ; )
00436 {
00437 t_pp= pp->next;
00438 free((HK_Dayfile_Packet_t*) pp);
00439 pp=t_pp;
00440 }
00441
00442
00443 dfd= t_dfd->next;
00444
00445
00446 t_dfd->pkt=NULL;
00447 t_dfd=dfd;
00448 }
00449 }
00450 return (HK_SUCCESS_WRITE_DAYFILE);
00451 }
00452
00453
00454
00455
00456 int free_dayfile_data( HK_Dayfile_Data_t **df_head)
00457 {
00458
00459 HK_Dayfile_Data_t *dfd, *t_dfd;
00460 HK_Dayfile_Packet_t *pp, *t_pp;
00461
00462 dfd= *df_head;
00463 if (dfd)
00464 {
00465
00466 t_dfd= dfd;
00467 while (t_dfd)
00468 {
00469
00470 for ( pp=t_dfd->pkt; pp ; pp=t_pp)
00471 {
00472 t_pp = pp->next;
00473 free((HK_Dayfile_Packet_t*) pp);
00474 }
00475
00476
00477 dfd= t_dfd->next;
00478
00479
00480 free(t_dfd);
00481 t_dfd=dfd;
00482 }
00483 }
00484 return (HK_SUCCESS_WRITE_DAYFILE);
00485 }
00486
00487
00488
00489
00490 int get_yr_from_pkttime(double tc_sec)
00491 {
00492
00493 short year;
00494 char at[200];
00495
00496
00497 (void)sprint_time (at, tc_sec, "UTC", 0);
00498 strcat(at,"\0");
00499
00500
00501 sscanf(at,"%hd",&year);
00502 return (year);
00503 }
00504
00505 int get_month_from_pkttime(double tc_sec)
00506 {
00507
00508 short month;
00509 char at[200];
00510
00511
00512 (void)sprint_time (at, tc_sec, "UTC", 0);
00513 strcat(at,"\0");
00514
00515
00516 sscanf(at,"%*d.%hd",&month);
00517 return (month);
00518 }
00519
00520 int get_day_from_pkttime(double tc_sec)
00521 {
00522
00523 short day;
00524 char at[200];
00525
00526
00527 (void)sprint_time (at, tc_sec, "UTC", 0);
00528 strcat(at,"\0");
00529
00530
00531 sscanf(at,"%*d.%*d.%hd",&day);
00532 return (day);
00533 }
00534
00535 int get_hour_from_pkttime(double tc_sec)
00536 {
00537
00538 short hour;
00539 char at[200];
00540
00541
00542 (void)sprint_time (at, tc_sec, "UTC", 0);
00543 strcat(at,"\0");
00544
00545
00546 sscanf(at,"%*d.%*d.%*d_%hd",&hour);
00547 return (hour);
00548 }
00549
00550
00551
00552
00553 char * get_dayfilename(int apid, double tc_sec)
00554 {
00555
00556 int year,month,day, hour, minute, second, version;
00557 char filename[200];
00558 char at[200];
00559 char *fp;
00560
00561
00562 version=0;
00563 fp = filename;
00564
00565
00566 (void)sprint_time (at, tc_sec, "UTC", 0);
00567 strcat(at,"\0");
00568
00569
00570 sscanf(at,"%d.%d.%d_%d:%d:%d.%*s",&year,&month,&day,&hour,&minute,&second);
00571 sprintf(filename,"hsb_%4.4d_%4.4d_%2.2d_%2.2d_%2.2d_%2.2d_%2.2d_%2.2d.hkt",apid,year,month,day,hour,minute,second,version);
00572 strcat(filename,"\0");
00573 return fp;
00574 }
00575
00576
00577 int check_for_pkt_time( HK_Dayfile_Data_t **fdfd, unsigned short *word_ptr)
00578 {
00579
00580 HK_Dayfile_Data_t *t_dfd;
00581 int pkt_yr,pkt_month,pkt_day;
00582
00583
00584 t_dfd = *fdfd;
00585
00586
00587 pkt_yr=get_yr_from_pkttime(get_packet_time(word_ptr));
00588 pkt_month=get_month_from_pkttime(get_packet_time(word_ptr));
00589 pkt_day=get_day_from_pkttime(get_packet_time(word_ptr));
00590
00591
00592 if (( t_dfd->year == pkt_yr) && (t_dfd->month == pkt_month) && (t_dfd->day == pkt_day))
00593 {
00594
00595 return (HK_DF_CHECK_FOUND) ;
00596 }
00597 else
00598 {
00599
00600
00601 return (HK_DF_CHECK_NOT_FOUND) ;
00602 }
00603 }
00604
00605
00606
00607
00608 void set_time_values(HK_Dayfile_Data_t **dn, double tcsec)
00609 {
00610
00611 HK_Dayfile_Data_t *td;
00612 char at[200];
00613
00614
00615 td= *dn;
00616
00617
00618 (void)sprint_time (at, tcsec, "UTC", 0);
00619 strcat(at,"\0");
00620
00621
00622 sscanf(at,"%hd.%hd.%hd_%hd:%hd:%hd", &td->year, &td->month,
00623 &td->day, &td->hour, &td->minute, &td->second);
00624 return;
00625 }
00626
00627
00628
00629 int check_dfd_file( unsigned short *word_ptr, int apid)
00630 {
00631
00632 DIR *dir_p;
00633 char dn[MAX_DIRECTORY_NAME];
00634 char *p_dn;
00635 struct dirent *dir_entry_p;
00636
00637
00638 p_dn = getenv("HK_DF_HSB_DIRECTORY");
00639 strcpy(dn,p_dn);
00640
00641
00642 if ((dir_p = opendir(dn)) == NULL)
00643 {
00644 printkerr("Error at %s, line %d: Could not open directory <%s>. "
00645 "Check if environment variable <HK_DF_HSB_DIRECTORY> is set .\n",
00646 __FILE__,__LINE__,dn);
00647 return ERROR_HK_FAILED_OPEN_DAYFILE;
00648 }
00649
00650
00651 while( (dir_entry_p = readdir(dir_p)) != NULL )
00652 {
00653 if( strncmp(dir_entry_p->d_name,"hsb_",4) )
00654 {
00655 continue;
00656 }
00657 else
00658 {
00659
00660
00661
00662 if ( (!check_filename_pkt_time(dir_entry_p->d_name, word_ptr)) || (!check_filename_apid(dir_entry_p->d_name,apid)) )
00663 {
00664 continue;
00665 }
00666 else
00667 {
00668 return (HK_DF_CHECK_FOUND );
00669 }
00670 }
00671 }
00672 closedir(dir_p);
00673 return (HK_DF_CHECK_NOT_FOUND);
00674 }
00675
00676
00677
00678
00679 int load_dfd_node( unsigned short *word_ptr, HK_Dayfile_Data_t **dfd)
00680 {
00681
00682 DIR *dir_p;
00683 HK_Dayfile_Data_t *dd,*t_dd;
00684 char dn[MAX_DIRECTORY_NAME];
00685 char *p_dn;
00686 struct dirent *dir_entry_p;
00687
00688
00689 dd=NULL;
00690 *dfd= dd;
00691 p_dn=dn;
00692
00693
00694 p_dn = getenv("HK_DF_HSB_DIRECTORY");
00695 if(!p_dn){
00696 printkerr("Error at %s, line %d: Could not set environment variable. "
00697 "Check if environment variable <HK_DF_HSB_DIRECTORY> is set .\n",
00698 __FILE__,__LINE__);
00699 return ERROR_HK_ENVIRONMENT_VARS_NOT_SET;
00700 }
00701
00702
00703 if ((dir_p = opendir(p_dn)) == NULL)
00704 {
00705 printkerr("Error at %s, line %d: Could not open directory <%s>. "
00706 "Check if environment variable <HK_DF_HSB_DIRECTORY> is set .\n",
00707 __FILE__,__LINE__,dn);
00708 return ERROR_HK_FAILED_OPEN_DAYFILE;
00709 }
00710
00711
00712 while( (dir_entry_p = readdir(dir_p)) != NULL )
00713 {
00714 if( strncmp(dir_entry_p->d_name,"hsb_",4) )
00715 {
00716 continue;
00717 }
00718 else
00719 {
00720
00721
00722
00723 if ( !check_filename_pkt_time(dir_entry_p->d_name, word_ptr) )
00724 {
00725 continue;
00726 }
00727
00728 if (!dd)
00729 {
00730
00731 dd = malloc(sizeof(HK_Dayfile_Data_t));
00732 if(!dd)
00733 {
00734 printkerr("ERROR at %s, line %d: Could not malloc space!\n", __FILE__, __LINE__);
00735 exit(1);
00736 }
00737
00738
00739 *dfd= dd;
00740 t_dd=dd;
00741
00742
00743 sscanf(dir_entry_p->d_name, "hsb_%hd_%hd_%hd_%hd_%hd_%hd_%hd",
00744 &dd->apid,&dd->year,&dd->month,&dd->day,&dd->hour,&dd->minute, &dd->second );
00745
00746
00747 strcpy(dd->dayfile, dir_entry_p->d_name);
00748 strcat(dd->dayfile, "\0");
00749 dd->next=NULL;
00750 dd->pkt=NULL;
00751 }
00752 else
00753 {
00754
00755 t_dd = malloc(sizeof(HK_Dayfile_Data_t));
00756 if(!t_dd)
00757 {
00758 printkerr("ERROR at %s, line %d: Could not malloc space!\n", __FILE__, __LINE__);
00759 }
00760
00761
00762 sscanf(dir_entry_p->d_name, "hsb_%hd_%hd_%hd_%hd_%hd_%hd_%hd",
00763 &t_dd->apid,&t_dd->year,&t_dd->month,&t_dd->day,&t_dd->hour,&t_dd->minute, &t_dd->second);
00764
00765
00766
00767 strcpy(t_dd->dayfile, dir_entry_p->d_name);
00768 strcat(t_dd->dayfile,"\0");
00769 t_dd->next=NULL;
00770 t_dd->pkt=NULL;
00771
00772
00773 dd->next=t_dd;
00774 dd=t_dd;
00775 }
00776 }
00777 }
00778 closedir(dir_p);
00779
00780 return HK_DF_DAYFILE_LOAD_SUCCESS;
00781 }
00782
00783
00784
00785
00786 int check_filename_pkt_time(char *fn, unsigned short *word_ptr)
00787 {
00788
00789 int pkt_yr,pkt_month,pkt_day;
00790 int fn_yr,fn_month,fn_day;
00791
00792
00793 strcat(fn,"\0");
00794 pkt_yr=get_yr_from_pkttime(get_packet_time(word_ptr));
00795 pkt_month=get_month_from_pkttime(get_packet_time(word_ptr));
00796 pkt_day=get_day_from_pkttime(get_packet_time(word_ptr));
00797 sscanf(fn, "hsb_%*d_%d_%d_%d_%*d_%*d_%*d.%*s",&fn_yr, &fn_month,&fn_day);
00798
00799
00800 if ( (pkt_yr == fn_yr) && (pkt_month == fn_month) && (pkt_day == fn_day) )
00801 {
00802 return (HK_DF_CHECK_FOUND);
00803 }
00804 else
00805 {
00806 return (HK_DF_CHECK_NOT_FOUND) ;
00807 }
00808
00809 }
00810
00811
00812
00813 int check_filename_apid(char *fn, int apid)
00814 {
00815
00816 int fn_yr,fn_month,fn_day;
00817 int fn_apid;
00818
00819
00820 strcat(fn,"\0");
00821 sscanf(fn, "hsb_%d_%d_%d_%d_%*d_%*d_%*d.%*s",&fn_apid,&fn_yr, &fn_month,&fn_day);
00822
00823
00824 if (apid == fn_apid)
00825 {
00826 return (HK_DF_CHECK_FOUND);
00827 }
00828 else
00829 {
00830 return (HK_DF_CHECK_NOT_FOUND) ;
00831 }
00832 }
00833
00834
00835
00836
00837 static TIME SDO_to_DRMS_time(int sdo_s, int sdo_ss)
00838 {
00839 static int firstcall = 1;
00840 static TIME sdo_epoch;
00841 if (firstcall)
00842 {
00843 firstcall = 0;
00844 sdo_epoch = sscan_time("1958.01.01_00:00:00_TAI");
00845 }
00846 return(sdo_epoch + (TIME)sdo_s + (TIME)(sdo_ss)/65536.0);
00847 }