00001 #ident "$Header: /home/cvsuser/cvsroot/JSOC/proj/lev1/apps/load_mp.c,v 1.5 2014/02/11 00:40:00 production Exp $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00112
00113
00114 #define HKLMP_FAILED_STATUS 1
00115 #define HKLMP_PASSED_STATUS 0
00116 #define HKLMP_MAX_DSNAME_STR 100
00117 #define HKLMP_MAX_DIR_FILE_NAME 200
00118 #define HKLMP_MAX_KEYWORD_NAME_STR 100
00119 #define HKLMP_MAX_QUERY_STR 200
00120 #define HKLMP_MAX_CHARS_IN_LINE 200
00121 #define HKLMP_PACKET_TIME_STR 100
00122 #define HKLMP_VAR_VERSION 8
00123 #define HKLMP_VAR_T_HKVALS 4
00124 #define HKLMP_VAR_T_STOP 2
00125 #define HKLMP_VAR_T_START 1
00126 #define HKLMP_NO_IMAGE_LOC_FILE 100
00127
00128
00129 #define ENVFILE "/home/production/cvs/JSOC/proj/lev1/apps/SOURCE_ENV_FOR_LOAD_MP"
00130
00131
00132 #include <stdio.h>
00133 #include <stdlib.h>
00134 #include <string.h>
00135 #include <time.h>
00136 #include <math.h>
00137 #include <sys/stat.h>
00138 #include <unistd.h>
00139 #include <stdarg.h>
00140 #include "drms.h"
00141 #include "drms_names.h"
00142 #include "jsoc_main.h"
00143 #include "load_hk_config_files.h"
00144 #include "write_hk_to_drms.h"
00145 #include "packets.h"
00146 #include "decode_hk.h"
00147 #include "printk.h"
00148
00149
00150
00151 ModuleArgs_t module_args[] =
00152 {
00153 {ARG_STRING, "ilf", "Not Specified", "full path to image location file"},
00154 {ARG_END}
00155 };
00156 ModuleArgs_t *ggModArgs=module_args;
00157 char* module_name = "load_mp";
00158
00159
00160
00161 TIME set_tstop_value(char *seriesname, char tstart_str[HKLMP_PACKET_TIME_STR],TIME *ptstart);
00162 int set_mp_version(char *seriesname, char tstart_str[HKLMP_PACKET_TIME_STR]);
00163 int get_hmilegstatus_keywords(DRMS_Record_t *record, TIME *p_hkvals,char hk_time_val[HKLMP_PACKET_TIME_STR]);
00164 int get_hmiissstatus_keywords(DRMS_Record_t *record, TIME *p_hkvals,char hk_time_val[HKLMP_PACKET_TIME_STR]);
00165 int get_aiaiss12status_keywords(DRMS_Record_t *record, TIME *p_hkvals,char hk_time_val[HKLMP_PACKET_TIME_STR]);
00166 int get_aiaiss34status_keywords(DRMS_Record_t *record, TIME *p_hkvals,char hk_time_val[HKLMP_PACKET_TIME_STR]);
00167 static void set_env_variables();
00168 void update_tstop_version(char query[HKLMP_MAX_QUERY_STR], char mp_tstart_value[HKLMP_PACKET_TIME_STR]);
00169 void check_oldrec_tstop_time(char query[HKLMP_MAX_QUERY_STR], char mp_tstart_value[HKLMP_PACKET_TIME_STR]);
00170 void my_usage (void);
00171 int set_image_loc_values(DRMS_Record_t *record, char *seriesname, TIME *ptr_tstart, char mp_tstart_str[HKLMP_PACKET_TIME_STR] , TIME *ptr_hkvals, char hk_time_val_str[HKLMP_PACKET_TIME_STR], char im_loc_fn[HKLMP_MAX_DIR_FILE_NAME]);
00172
00173
00174 extern int DoIt(void);
00175 extern int nice_intro (void);
00176 extern void sprint_time (char *at, TIME t, char *zone, int precision);
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 void my_usage (void)
00189 {
00190
00191 printf ("Usage:\nload_mp [-h] "
00192 "ilf=<image location file> \n"
00193 " details are:\n"
00194 " -h: help - show this message then exit(optional field)\n"
00195 " ilf=<full directory path to image location file name> -use full path to image location file file(required field)\n"
00196 " note:need master pointing series already created for this program to load keywords in data series.\n"
00197 " note:need to create image_location using set_mp.pl script or by hand editing file using correct file format.\n"
00198 " Example of running:\n"
00199 " load_mp ilf=/home/carl/cvs/TBL_JSOC/lev1/image_location_file/image_location_2009_10_29.txt\n");
00200 }
00201
00202
00203
00204
00205
00206
00207
00208
00209 int nice_intro (void)
00210 {
00211 int usage = cmdparams_get_int (&cmdparams, "h", NULL);
00212 if (usage == 1)
00213 {
00214 my_usage();
00215 return(1);
00216 }
00217 return (0);
00218 }
00219
00220
00221
00222
00223
00224
00225
00226
00227 int DoIt(void)
00228 {
00229
00230
00231 DRMS_RecordSet_t *rs;
00232 DRMS_Record_t *rec;
00233 FILE *file_ptr;
00234 TIME *p_hkvals;
00235 TIME *p_tstart;
00236 TIME hk_vals;
00237 TIME tstart_vals;
00238 char query[HKLMP_MAX_QUERY_STR];
00239 char hk_directory_filename[HKLMP_MAX_DIR_FILE_NAME];
00240 char hk_time_value[HKLMP_PACKET_TIME_STR];
00241 char mp_tstart_value[HKLMP_PACKET_TIME_STR];
00242 char mp_seriesname[HKLMP_MAX_DSNAME_STR];
00243 char *hk_df_fn;
00244 char *sn;
00245 int set_image_status;
00246 unsigned int t_status=0;
00247 int status;
00248
00249
00250 p_hkvals=&hk_vals;
00251 p_tstart=&tstart_vals;
00252 sn=mp_seriesname;
00253
00254
00255 set_env_variables();
00256
00257
00258 hk_df_fn= hk_directory_filename;
00259
00260
00261 char *ilf = cmdparams_get_str (&cmdparams, "ilf", NULL);
00262
00263
00264 if (nice_intro ()) return (0);
00265
00266
00267 if (ilf == NULL)
00268 {
00269 printkerr("ERROR at %s, line %d: Need to enter image location file name! "
00270 "Exiting program.\n ", __FILE__,__LINE__);
00271 my_usage();
00272 return (0);
00273 }
00274
00275
00276 strcpy(hk_df_fn, ilf);
00277 strcat(hk_df_fn, "\0");
00278 file_ptr=fopen(hk_df_fn,"r");
00279
00280
00281 if (!file_ptr)
00282 {
00283 printkerr("ERROR at %s, line %d: Please check filename and directory is correct. "
00284 " Could not find or open -ilf- directory and filename: "
00285 "<%s>. Example format for -ilf- file: ilf=/home/rock/image_location.txt. Exiting execution.\n",
00286 __FILE__,__LINE__, hk_df_fn);
00287 return(0);
00288 }
00289
00290 fclose(file_ptr);
00291
00292
00293 sn = (char *)getenv("HK_LMP_MP_SERIESNAME");
00294 if(sn == NULL)
00295 {
00296 printkerr("ERROR at %s, line %d: no master pointing seriesname environment variable set. "
00297 " Set envirionment HK_LMP_MP_SERIESNAME variable in sourced file "
00298 " SOURCE_ENV_FOR_LOAD_MP.\n", __FILE__,__LINE__);
00299 return (HKLMP_FAILED_STATUS);
00300 }
00301 strcpy(query,sn);
00302 strcat(query,"\0");
00303 #ifdef DEBUG_LOAD_MP
00304 printf("load_mp:(1): Master pointing series name is <%s>\n",query);
00305 #endif
00306
00307
00308 rs = drms_create_records( drms_env, 1, query, DRMS_PERMANENT, &status);
00309 if (status)
00310 {
00311 printkerr("ERROR at %s, line %d: Cannot create record using this data"
00312 " series name:<%s>.Existing program.\n",__FILE__,__LINE__, query);
00313 return 1;
00314 }
00315 #ifdef DEBUG_LOAD_MP
00316 else
00317 {
00318 printf("load_mp:(2):Sucessfully created record for series <%s>\n", query);
00319 }
00320 #endif
00321
00322
00323 rec = rs->records[0];
00324
00325 #ifdef DEBUG_LOAD_MP
00326 printf("load_mp:(3):Calling set_image_loc_values to set image location values in <%s>\n", query);
00327 #endif
00328
00329
00330 set_image_status=set_image_loc_values(rec, sn, p_tstart, mp_tstart_value, p_hkvals, hk_time_value, ilf);
00331 if (set_image_status > 0 && set_image_status < 15)
00332 {
00333 printkerr("ERROR at %s, line %d: Returned error status <%d> from set_image_loc_values function. "
00334 "Exiting from load_mp executable. Please add in the required keywords listed.\n",
00335 __FILE__,__LINE__, set_image_status);
00336
00337 if (!((unsigned int)set_image_status>>3 & 0x00000001))
00338 printkerr("-->>Add VERSION keyword to image location file.\n");
00339
00340 if (!((unsigned int)set_image_status & 0x00000001))
00341 printkerr("-->>Add T_START keyword to image location file.\n");
00342
00343 if (!((unsigned int)set_image_status>>2 & 0x00000001))
00344 printkerr("-->>Add T_HKVALS keyword to image location file.\n");
00345
00346 if (!((unsigned int)set_image_status>>1 & 0x00000001))
00347 printkerr("-->>Add T_STOP keyword to image location file.\n");
00348
00349
00350 return(0);
00351 }
00352 else if ( set_image_status == HKLMP_NO_IMAGE_LOC_FILE )
00353 {
00354 printkerr("ERROR at %s, line %d: Returned error status <%d> from set_image_loc_values function. "
00355 "Exiting from load_mp executable. Please check image location file name's directory and "
00356 "filename are correct.\n", __FILE__,__LINE__, set_image_status);
00357
00358 return(0);
00359 }
00360
00361
00362
00363 if( get_hmilegstatus_keywords(rec, p_hkvals, hk_time_value))
00364 {
00365 printkerr("ERROR at %s, line %d: Returned error status from get_hmilegstatus_keywords function. "
00366 "Exiting from load_mp executable. Please use correct HKVALS setting in image loc file and rerun.\n",
00367 __FILE__,__LINE__);
00368 status = drms_close_records(rs, DRMS_FREE_RECORD);
00369 return(0);
00370 }
00371
00372
00373
00374 if(get_hmiissstatus_keywords(rec, p_hkvals, hk_time_value))
00375 {
00376 printkerr("ERROR at %s, line %d: Returned error status from get_hmiissstatus_keywords function. "
00377 "Exiting from load_mp executable. Please use correct HKVALS setting in image loc file and rerun.\n",
00378 __FILE__,__LINE__);
00379 status = drms_close_records(rs, DRMS_FREE_RECORD);
00380 return(0);
00381 }
00382
00383
00384 if(get_aiaiss12status_keywords(rec, p_hkvals, hk_time_value))
00385 {
00386 printkerr("ERROR at %s, line %d: Returned error status from get_iss12status_keywords function. "
00387 "Exiting from load_mp executable. Please use correct HKVALS setting in image loc file and rerun.\n",
00388 __FILE__,__LINE__);
00389 status = drms_close_records(rs, DRMS_FREE_RECORD);
00390 return(0);
00391 }
00392
00393
00394 if(get_aiaiss34status_keywords(rec, p_hkvals, hk_time_value))
00395 {
00396 printkerr("ERROR at %s, line %d: Returned error status from get_iss34status_keywords function. "
00397 "Exiting from load_mp executable. Please use correct HKVALS setting in image loc file and rerun.\n",
00398 __FILE__,__LINE__);
00399 status = drms_close_records(rs, DRMS_FREE_RECORD);
00400 return(0);
00401 }
00402
00403
00404 status = drms_close_records(rs, DRMS_INSERT_RECORD);
00405 if (status)
00406 {
00407 printkerr("ERROR at %s, line %d: Cannot close drms record.\n",
00408 __FILE__,__LINE__);
00409 return 0;
00410 }
00411 else
00412 {
00413 ;
00414 #ifdef DEBUG_LOAD_MP
00415 printf("load_mp:(42): Completed close of write of record of master pointing series\n" );
00416 #endif
00417 }
00418
00419
00420 (void)update_tstop_version(query, mp_tstart_value);
00421 (void)check_oldrec_tstop_time(query, mp_tstart_value);
00422
00423 printf(". . . successfully added or updated record in master pointing series<%s> for T_START record <%s>\n",query, mp_tstart_value);
00424
00425 return 0;
00426 }
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437 void set_env_variables()
00438 {
00439 FILE * fp;
00440 char envfile[500], s1[256],s2[256],s3[256], line[256];
00441
00442
00443 strcpy(envfile, ENVFILE );
00444
00445 if(!(fp=fopen(envfile, "r")))
00446 {
00447 printf("ERROR:Can't open environment variable file <%s>. Check setting is correct.\n", envfile);
00448 exit(0);
00449 }
00450
00451 while( fgets(line, MAXLINE_IN_FILE, fp) != NULL )
00452 {
00453 if (!strncmp(line, "#", 1))
00454 {
00455 continue;
00456 }
00457 else
00458 {
00459 sscanf(line, "%s %s %s ", s1,s2,s3);
00460
00461 setenv(s2, s3, 1);
00462 }
00463 }
00464
00465 fclose(fp);
00466 }
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476 int set_image_loc_values(DRMS_Record_t *record, char *seriesname, TIME *ptr_tstart, char mp_tstart_str[HKLMP_PACKET_TIME_STR] , TIME *ptr_hkvals, char hk_time_val_str[HKLMP_PACKET_TIME_STR], char im_loc_fn[HKLMP_MAX_DIR_FILE_NAME])
00477 {
00478
00479
00480 DRMS_Type_t keytype;
00481 DRMS_Type_Value_t key_anyval;
00482 FILE *file_ptr;
00483 TIME now_time;
00484 TIME t_start_value;
00485 TIME t_stop_value;
00486 char *hk_df_fn;
00487 char hk_directory_filename[HKLMP_MAX_DIR_FILE_NAME];
00488 char keyname[HKLMP_MAX_KEYWORD_NAME_STR];
00489 char line[HKLMP_MAX_CHARS_IN_LINE];
00490 char time_str[HKLMP_PACKET_TIME_STR];
00491 char t_start_str[HKLMP_PACKET_TIME_STR];
00492 char t_stop_str[HKLMP_PACKET_TIME_STR];
00493 int filevar_status;
00494 int ret_ver_value;
00495 int status;
00496 struct tm timestorage;
00497 struct tm *time_ptr;
00498 time_t tvalue;
00499
00500
00501 time_ptr= ×torage;
00502 hk_df_fn= hk_directory_filename;
00503 filevar_status=0;
00504
00505
00506 strcpy(hk_df_fn, im_loc_fn);
00507 strcat(hk_df_fn, "\0");
00508 file_ptr=fopen(hk_df_fn,"r");
00509 if (!file_ptr)
00510 {
00511 printkerr("ERROR at %s, line %d: Please check filename and directory is correct. "
00512 " Could not get image_location.txt directory and filename: %s "
00513 " Exiting execution.\n",
00514 __FILE__,__LINE__, hk_df_fn);
00515 return(HKLMP_NO_IMAGE_LOC_FILE);
00516 }
00517
00518
00519
00520 while( fgets(line, MAXLINE_IN_FILE, file_ptr) != NULL )
00521 {
00522 if(line[0] == '#')
00523 {
00524 continue;
00525 }
00526 else if (!strncmp(line, "KWD", 3))
00527 {
00528
00529 sscanf(line,"%*s%s%*s%*s",keyname);
00530 strcat(keyname,"\0");
00531
00532
00533 if (!strcmp(keyname, "T_START") || !strcmp(keyname, "T_STOP") || !strcmp(keyname, "T_HKVALS"))
00534 {
00535 if(!strcmp(keyname, "T_STOP"))
00536 {
00537
00538 filevar_status+=HKLMP_VAR_T_STOP;
00539
00540
00541
00542 t_stop_value=set_tstop_value(seriesname, mp_tstart_str,ptr_tstart);
00543 if(t_stop_value > 0)
00544 {
00545 #ifdef DEBUG_LOAD_MP
00546 printf("load_mp:(5):set_image_loc_values():setting T_STOP <%f>\n",t_stop_value);
00547 #endif
00548
00549 keytype= DRMS_TYPE_TIME;
00550
00551 key_anyval.time_val= t_stop_value;
00552
00553 status = drms_setkey(record, keyname, keytype, &key_anyval);
00554 continue;
00555 }
00556
00557
00558 }
00559
00560
00561 sscanf(line,"%*s%*s%s%*s",t_start_str);
00562
00563 t_start_value = sscan_time( t_start_str);
00564 keytype= DRMS_TYPE_TIME;
00565 key_anyval.time_val= t_start_value;
00566 status = drms_setkey(record, keyname, keytype, &key_anyval);
00567
00568
00569 if(!strcmp(keyname, "T_HKVALS"))
00570 {
00571
00572 filevar_status+=HKLMP_VAR_T_HKVALS;
00573
00574
00575 *ptr_hkvals=t_start_value;
00576 strcpy( hk_time_val_str,t_start_str);
00577
00578 #ifdef DEBUG_LOAD_MP
00579 printf("load_mp:(15):set_image_loc_values():Setting T_HKVALS keyword to float value to:<%f>\n", *ptr_hkvals);
00580 #endif
00581 }
00582 if(!strcmp(keyname, "T_START"))
00583 {
00584
00585 filevar_status+=HKLMP_VAR_T_START;
00586
00587
00588 *ptr_tstart=t_start_value;
00589 strcpy( mp_tstart_str,t_start_str);
00590
00591 #ifdef DEBUG_LOAD_MP
00592 printf("load_mp:(4):set_image_loc_values():Setting T_START float value using data in image loc file:<%f>\n", *ptr_tstart);
00593 printf("load_mp:(5):set_image_loc_values():String display of T_START setting<%s>\n", mp_tstart_str);
00594 #endif
00595 }
00596 }
00597 else if(!strcmp(keyname, "VERSION"))
00598 {
00599
00600 filevar_status+=HKLMP_VAR_VERSION;
00601
00602
00603
00604 ret_ver_value=set_mp_version(seriesname, mp_tstart_str);
00605
00606 #ifdef DEBUG_LOAD_MP
00607 printf("load_mp:(21):set_image_loc_values(): from set_mp_version: <%d>\n",ret_ver_value);
00608 #endif
00609
00610
00611 keytype= DRMS_TYPE_INT;
00612 key_anyval.int_val= ret_ver_value;
00613 status = drms_setkey(record, keyname, keytype, &key_anyval);
00614 }
00615 else
00616 {
00617
00618 keytype= DRMS_TYPE_FLOAT;
00619 sscanf(line,"%*s%*s%f%*s",&key_anyval.float_val);
00620 status = drms_setkey(record, keyname, keytype, &key_anyval);
00621 }
00622 }
00623 }
00624
00625
00626 fclose(file_ptr);
00627
00628
00629 tvalue = time(NULL);
00630
00631 time_ptr = gmtime(&tvalue);
00632
00633 for(int i=0; i < HKLMP_PACKET_TIME_STR;time_str[i]='\0',i++);
00634
00635 sprintf(time_str, "%04d.%02d.%02d_%02d:%02d:%02d_UTC",(time_ptr->tm_year+1900),
00636 (time_ptr->tm_mon+1), time_ptr->tm_mday, time_ptr->tm_hour, time_ptr->tm_min, time_ptr->tm_sec);
00637
00638 now_time=sscan_time(time_str);
00639
00640
00641
00642 keytype= DRMS_TYPE_TIME;
00643 strcpy(keyname, "DATE");
00644
00645 key_anyval.time_val= now_time;
00646
00647 status = drms_setkey(record, keyname, keytype, &key_anyval);
00648
00649
00650 if(filevar_status == HKLMP_VAR_VERSION+HKLMP_VAR_T_START+HKLMP_VAR_T_STOP+HKLMP_VAR_T_HKVALS)
00651 {
00652 return(0);
00653 }
00654 else
00655 {
00656 return (filevar_status);
00657 }
00658 }
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670 int get_hmilegstatus_keywords(DRMS_Record_t *record, TIME *p_hkvals,char hk_time_val[HKLMP_PACKET_TIME_STR] )
00671 {
00672
00673
00674
00675 DRMS_RecordSet_t *rs;
00676 DRMS_Record_t *rec;
00677 DRMS_Type_Value_t key_anyval;
00678 TIME adj_hkval;
00679 char adj_hkval_str[HKLMP_PACKET_TIME_STR];
00680 char nquery[HKLMP_MAX_QUERY_STR];
00681 char dsname[HKLMP_MAX_DSNAME_STR];
00682 char series[HKLMP_MAX_DSNAME_STR];
00683 char *sn;
00684 float leg_step;
00685 int status;
00686
00687
00688 sn=series;
00689 rs=NULL;
00690 rec=NULL;
00691
00692
00693 sn = (char *)getenv("HK_LMP_HMI_LEG_SERIESNAME");
00694 if(sn == NULL)
00695 {
00696 printkerr("ERROR at %s, line %d: no hmi leg status environment variable set. "
00697 " Set envirionment HK_LMP_HMI_LEG_SERIESNAME variable in sourced file "
00698 " SOURCE_ENV_FOR_LOAD_MP.\n", __FILE__,__LINE__);
00699 return (HKLMP_FAILED_STATUS);
00700 }
00701
00702
00703 strcpy(dsname,sn);
00704 strcat(dsname,"\0");
00705
00706
00707 rs = drms_open_records(drms_env, dsname, &status);
00708 if(rs->n)
00709 {
00710 rec=rs->records[0];
00711 #ifdef DEBUG_LOAD_MP
00712 printf("load_mp:(22):get_hmilegstatus():number of records retrieved was %d\n",rs->n);
00713 #endif
00714 leg_step=drms_getkey_float(rec, "T_START_step", &status);
00715 drms_close_records(rs, DRMS_FREE_RECORD);
00716 }
00717 else
00718 {
00719 printkerr("ERROR at %s, line %d: Could not find records for <%s> series. "
00720 "Could not get step value needed to load this series values in master pointing series.\n",
00721 __FILE__,__LINE__,dsname);
00722 return(HKLMP_FAILED_STATUS);
00723 }
00724
00725
00726 #ifdef DEBUG_LOAD_MP
00727 printf("load_mp:(23):get_hmilegstatus_keywords():hkval_str is <%s>\n",hk_time_val);
00728 #endif
00729
00730
00731 adj_hkval= *p_hkvals - leg_step;
00732
00733
00734 (void)sprint_time (adj_hkval_str, adj_hkval, "UTC", 0);
00735 strcat(adj_hkval_str,"\0");
00736 #ifdef DEBUG_LOAD_MP
00737 printf("load_mp:(24):get_hmilegstatus_keywords():adj_hkval_str is <%s>\n",adj_hkval_str);
00738 #endif
00739
00740
00741
00742
00743
00744 sprintf(nquery,"%s[? $(%s) >= T_START AND $(%s) < T_START ?]",dsname, hk_time_val, adj_hkval_str);
00745 #ifdef DEBUG_LOAD_MP
00746 printf("load_mp:(25):get_hmilegstatus():nquery is<%s>\n",nquery);
00747 #endif
00748
00749
00750 rs = drms_open_records(drms_env, nquery, &status);
00751 if(!rs->n)
00752 {
00753 printkerr("ERROR at %s, line %d: No Records found using query <%s>. "
00754 "Could not set values from <%s> series in master pointing series.\n",
00755 __FILE__,__LINE__,nquery,dsname);
00756 return(HKLMP_FAILED_STATUS);
00757 }
00758 if(rs->n)
00759 {
00760 rec=rs->records[0];
00761 #ifdef DEBUG_LOAD_MP
00762 printf("load_mp:(26):get_hmilegstatus():number of records retrieved was %d\n",rs->n);
00763 #endif
00764
00765 drms_setkey_float(record, "HMI_FSW_AL1_POSITION", drms_getkey_float(rec, "HAL1POS_MEAN", &status));
00766 drms_setkey_float(record, "HMI_FSW_AL2_POSITION", drms_getkey_float(rec, "HAL2POS_MEAN", &status));
00767 drms_setkey_float(record, "HMI_AL1_STATUS",drms_getkey_float(rec, "HAL1STAT_MEAN", &status));
00768 drms_setkey_float(record, "HMI_AL2_STATUS",drms_getkey_float(rec, "HAL2STAT_MEAN", &status));
00769
00770
00771 drms_close_records(rs, DRMS_FREE_RECORD);
00772 }
00773 return(HKLMP_PASSED_STATUS);
00774 }
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786 int get_hmiissstatus_keywords(DRMS_Record_t *record, TIME *p_hkvals,char hk_time_val[HKLMP_PACKET_TIME_STR])
00787 {
00788
00789
00790
00791 DRMS_RecordSet_t *rs;
00792 DRMS_Record_t *rec;
00793 DRMS_Type_Value_t key_anyval;
00794 TIME adj_hkval;
00795 char adj_hkval_str[HKLMP_PACKET_TIME_STR];
00796 char nquery[HKLMP_MAX_QUERY_STR];
00797 char dsname[HKLMP_MAX_DSNAME_STR];
00798 char series[HKLMP_MAX_DSNAME_STR];
00799 float leg_step;
00800 int status;
00801 char *sn;
00802 sn=series;
00803
00804
00805 sn=series;
00806 rs=NULL;
00807 rec=NULL;
00808
00809
00810 sn = (char *)getenv("HK_LMP_HMI_ISS_SERIESNAME");
00811 if(sn == NULL)
00812 {
00813 printkerr("ERROR at %s, line %d: no hmi iss status environment variable set. "
00814 " Set envirionment HK_LMP_HMI_ISS_SERIESNAME variable in sourced file "
00815 " SOURCE_ENV_FOR_LOAD_MP.\n", __FILE__,__LINE__);
00816 return (HKLMP_FAILED_STATUS);
00817 }
00818
00819
00820 strcpy(dsname,sn);
00821
00822
00823 rs = drms_open_records(drms_env, dsname, &status);
00824 if(rs->n)
00825 {
00826 rec=rs->records[0];
00827 #ifdef DEBUG_LOAD_MP
00828 printf("load_mp:(27):get_hmissstatus():number of records retrieved was %d\n",rs->n);
00829 #endif
00830 leg_step=drms_getkey_float(rec, "T_START_step", &status);
00831 drms_close_records(rs, DRMS_FREE_RECORD);
00832 }
00833 else
00834 {
00835 printkerr("ERROR at %s, line %d: Could not find records for <%s> series. "
00836 "Could not get step value needed to load this series values in master pointing series.\n",
00837 __FILE__,__LINE__,dsname);
00838 return(HKLMP_FAILED_STATUS);
00839 }
00840
00841
00842 #ifdef DEBUG_LOAD_MP
00843 printf("load_mp:(28):get_hmiissstatus_keywords:hkval_str is <%s>\n",hk_time_val);
00844 #endif
00845
00846
00847 adj_hkval= *p_hkvals - leg_step;
00848
00849
00850 (void)sprint_time (adj_hkval_str, adj_hkval, "UTC", 0);
00851 strcat(adj_hkval_str,"\0");
00852 #ifdef DEBUG_LOAD_MP
00853 printf("load_mp:(29):get_hmiissstatus_keywords():adj_hkval_str is <%s>\n",adj_hkval_str);
00854 #endif
00855
00856
00857
00858
00859
00860 sprintf(nquery,"%s[? $(%s) >= T_START AND $(%s) < T_START ?]",dsname,hk_time_val, adj_hkval_str);
00861 #ifdef DEBUG_LOAD_MP
00862 printf("load_mp:(30):get_hmiissstatus():nquery is<%s>\n",nquery);
00863 #endif
00864
00865
00866 rs = drms_open_records(drms_env, nquery, &status);
00867 if(!rs->n)
00868 {
00869 printkerr("ERROR at %s, line %d: No Records found using query <%s>. "
00870 "Could not set values from <%s> series in master pointing series.\n",
00871 __FILE__,__LINE__,nquery,dsname);
00872 return(HKLMP_FAILED_STATUS);
00873 }
00874 if(rs->n)
00875 {
00876 rec=rs->records[0];
00877 #ifdef DEBUG_LOAD_MP
00878 printf("load_mp:(31):get_hmissstatus():number of records retrieved was %d\n",rs->n);
00879 #endif
00880
00881 drms_setkey_float(record, "HMI_ISS_ERRGAINY", drms_getkey_float(rec, "HIERRGNY_MEAN", &status));
00882 drms_setkey_float(record, "HMI_ISS_ERRGAINZ", drms_getkey_float(rec, "HIERRGNZ_MEAN", &status));
00883 drms_setkey_float(record, "HMI_ISS_ERROFFY", drms_getkey_float(rec, "HIERROFY_MEAN", &status));
00884 drms_setkey_float(record, "HMI_ISS_ERROFFZ", drms_getkey_float(rec, "HIERROFZ_MEAN", &status));
00885 drms_setkey_float(record, "HMI_ISS_PZTOFFA", drms_getkey_float(rec, "HIPZTOFA_MEAN", &status));
00886 drms_setkey_float(record, "HMI_ISS_PZTOFFB",drms_getkey_float(rec, "HIPZTOFB_MEAN", &status));
00887 drms_setkey_float(record, "HMI_ISS_PZTOFFC",drms_getkey_float(rec, "HIPZTOFC_MEAN", &status));
00888 drms_setkey_float(record, "HMI_ISS_PKT_YCOEF_A",drms_getkey_float(rec, "HIYCOEFA_MEAN", &status));
00889 drms_setkey_float(record, "HMI_ISS_PKT_YCOEF_B", drms_getkey_float(rec, "HISYCOEF_MEAN", &status));
00890 drms_setkey_float(record, "HMI_ISS_PKT_YCOEF_C", drms_getkey_float(rec, "HIYCOEFC_MEAN", &status));
00891 drms_setkey_float(record, "HMI_ISS_PKT_ZCOEF_A", drms_getkey_float(rec, "HIZCOEFA_MEAN", &status));
00892 drms_setkey_float(record, "HMI_ISS_PKT_ZCOEF_B", drms_getkey_float(rec, "HIZCOEFB_MEAN", &status));
00893 drms_setkey_float(record, "HMI_ISS_PKT_ZCOEF_C", drms_getkey_float(rec, "HIZCOEFC_MEAN", &status));
00894
00895 drms_close_records(rs, DRMS_FREE_RECORD);
00896 }
00897 return(HKLMP_PASSED_STATUS);
00898
00899 }
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911 int get_aiaiss12status_keywords(DRMS_Record_t *record, TIME *p_hkvals,char hk_time_val[HKLMP_PACKET_TIME_STR])
00912 {
00913
00914
00915
00916 DRMS_RecordSet_t *rs;
00917 DRMS_Record_t *rec;
00918 DRMS_Type_Value_t key_anyval;
00919 TIME adj_hkval;
00920 char adj_hkval_str[HKLMP_PACKET_TIME_STR];
00921 char nquery[HKLMP_MAX_QUERY_STR];
00922 char dsname[HKLMP_MAX_DSNAME_STR];
00923 char series[HKLMP_MAX_DSNAME_STR];
00924 char *sn;
00925 float leg_step;
00926 int status;
00927
00928
00929 sn=series;
00930 rs=NULL;
00931 rec=NULL;
00932
00933
00934 sn = (char *)getenv("HK_LMP_AIA_ISS12_SERIESNAME");
00935 if(sn == NULL)
00936 {
00937 printkerr("ERROR at %s, line %d: no aia iss12 status environment variable set. "
00938 " Set envirionment HK_LMP_AIA_ISS12_SERIESNAME variable in sourced file "
00939 " SOURCE_ENV_FOR_LOAD_MP.\n", __FILE__,__LINE__);
00940 return (HKLMP_FAILED_STATUS);
00941 }
00942
00943
00944 strcpy(dsname,sn);
00945
00946
00947 rs = drms_open_records(drms_env, dsname, &status);
00948 if(rs->n)
00949 {
00950 rec=rs->records[0];
00951 #ifdef DEBUG_LOAD_MP
00952 printf("load_mp:(32):get_aiaiss12status():number of records retrieved was %d\n",rs->n);
00953 #endif
00954 leg_step=drms_getkey_float(rec, "T_START_step", &status);
00955 drms_close_records(rs, DRMS_FREE_RECORD);
00956 }
00957 else
00958 {
00959 printkerr("ERROR at %s, line %d: Could not find records for <%s> series. "
00960 "Could not get step value needed to load this series values in master pointing series.\n",
00961 __FILE__,__LINE__,dsname);
00962 return(HKLMP_FAILED_STATUS);
00963 }
00964
00965
00966 #ifdef DEBUG_LOAD_MP
00967 printf("load_mp:(33):get_aiaiss12sstatus_keywords():hkval_str is <%s>\n",hk_time_val);
00968 #endif
00969
00970
00971 adj_hkval= *p_hkvals - leg_step;
00972
00973
00974 (void)sprint_time (adj_hkval_str, adj_hkval, "UTC", 0);
00975 strcat(adj_hkval_str,"\0");
00976 #ifdef DEBUG_LOAD_MP
00977 printf("load_mp:(34):get_aiaiss12status_keywords():adj_hkval_str is <%s>\n",adj_hkval_str);
00978 #endif
00979
00980
00981
00982
00983
00984 sprintf(nquery,"%s[? $(%s) >= T_START AND $(%s) < T_START ?]",dsname,hk_time_val, adj_hkval_str);
00985 #ifdef DEBUG_LOAD_MP
00986 printf("load_mp:(35):get_aiaiss12status():nquery is<%s>\n",nquery);
00987 #endif
00988
00989
00990 rs = drms_open_records(drms_env, nquery, &status);
00991 if(!rs->n)
00992 {
00993 printkerr("ERROR at %s, line %d: No Records found using query <%s>. "
00994 "Check the HKVALS value selected has value in aia.iss_1_2_status series. "
00995 "Could not set values from <%s> series in master pointing series.\n",
00996 __FILE__,__LINE__,nquery,dsname);
00997 return(HKLMP_FAILED_STATUS);
00998 }
00999 if(rs->n)
01000 {
01001 rec=rs->records[0];
01002 #ifdef DEBUG_LOAD_MP
01003 printf("load_mp:(36):get_aiaiss12status():number of records retrieved was %d\n",rs->n);
01004 #endif
01005
01006
01007 drms_setkey_float(record, "AIA_IS1_ERRGAINY", drms_getkey_float(rec, "A1ERRGNY_MEAN", &status));
01008 drms_setkey_float(record, "AIA_IS1_ERRGAINZ",drms_getkey_float(rec, "A1ERRGNZ_MEAN", &status));
01009 drms_setkey_float(record, "AIA_IS1_ERROFFY", drms_getkey_float(rec, "A1ERROFY_MEAN", &status));
01010 drms_setkey_float(record, "AIA_IS1_ERROFFZ", drms_getkey_float(rec, "A1ERROFZ_MEAN", &status));
01011 drms_setkey_float(record, "AIA_IS1_PZTGAINA", drms_getkey_float(rec, "A1PZTGNA_MEAN", &status));
01012 drms_setkey_float(record, "AIA_IS1_PZTGAINB", drms_getkey_float(rec, "A1PZTGNB_MEAN", &status));
01013 drms_setkey_float(record, "AIA_IS1_PZTGAINC", drms_getkey_float(rec, "A1PZTGNC_MEAN", &status));
01014 drms_setkey_float(record, "AIA_IS1_PZTOFFA", drms_getkey_float(rec, "A1PZTOFA_MEAN", &status));
01015 drms_setkey_float(record, "AIA_IS1_PZTOFFB", drms_getkey_float(rec, "A1PZTOFB_MEAN", &status));
01016 drms_setkey_float(record, "AIA_IS1_PZTOFFC", drms_getkey_float(rec, "A1PZTOFC_MEAN", &status));
01017 drms_setkey_float(record, "AIA_GT1_PKT_YCOEF_A",drms_getkey_float(rec, "AGT1_YCA_MEAN", &status));
01018 drms_setkey_float(record, "AIA_GT1_PKT_YCOEF_B",drms_getkey_float(rec, "AGT1_YCB_MEAN", &status));
01019 drms_setkey_float(record, "AIA_GT1_PKT_YCOEF_C",drms_getkey_float(rec, "AGT1_YCC_MEAN", &status));
01020 drms_setkey_float(record, "AIA_GT1_PKT_ZCOEF_A",drms_getkey_float(rec, "AGT1_ZCA_MEAN", &status));
01021 drms_setkey_float(record, "AIA_GT1_PKT_ZCOEF_B",drms_getkey_float(rec, "AGT1_ZCB_MEAN", &status));
01022 drms_setkey_float(record, "AIA_GT1_PKT_ZCOEF_C",drms_getkey_float(rec, "AGT1_ZCC_MEAN", &status));
01023 drms_setkey_float(record, "AIA_IS2_ERRGAINY",drms_getkey_float(rec, "A2ERRGNY_MEAN", &status));
01024 drms_setkey_float(record, "AIA_IS2_ERRGAINZ",drms_getkey_float(rec, "A2ERRGNZ_MEAN", &status));
01025 drms_setkey_float(record, "AIA_IS2_ERROFFY", drms_getkey_float(rec, "A2ERROFY_MEAN", &status));
01026 drms_setkey_float(record, "AIA_IS2_ERROFFZ",drms_getkey_float(rec, "A2ERROFZ_MEAN", &status));
01027 drms_setkey_float(record, "AIA_IS2_PZTGAINA", drms_getkey_float(rec, "A2PZTGNA_MEAN", &status));
01028 drms_setkey_float(record, "AIA_IS2_PZTGAINB",drms_getkey_float(rec, "A2PZTGNB_MEAN", &status));
01029 drms_setkey_float(record, "AIA_IS2_PZTGAINC",drms_getkey_float(rec, "A2PZTGNC_MEAN", &status));
01030 drms_setkey_float(record, "AIA_IS2_PZTOFFA",drms_getkey_float(rec, "A2PZTOFA_MEAN", &status));
01031 drms_setkey_float(record, "AIA_IS2_PZTOFFB",drms_getkey_float(rec, "A2PZTOFB_MEAN", &status));
01032 drms_setkey_float(record, "AIA_IS2_PZTOFFC",drms_getkey_float(rec, "A2PZTOFC_MEAN", &status));
01033 drms_setkey_float(record, "AIA_GT2_PKT_YCOEF_A", drms_getkey_float(rec, "AGT2_YCA_MEAN", &status));
01034 drms_setkey_float(record, "AIA_GT2_PKT_YCOEF_B",drms_getkey_float(rec, "AGT2_YCB_MEAN", &status));
01035 drms_setkey_float(record, "AIA_GT2_PKT_YCOEF_C",drms_getkey_float(rec, "AGT2_YCC_MEAN", &status));
01036 drms_setkey_float(record, "AIA_GT2_PKT_ZCOEF_A",drms_getkey_float(rec, "AGT2_ZCA_MEAN", &status));
01037 drms_setkey_float(record, "AIA_GT2_PKT_ZCOEF_B",drms_getkey_float(rec, "AGT2_ZCB_MEAN", &status));
01038 drms_setkey_float(record, "AIA_GT2_PKT_ZCOEF_C",drms_getkey_float(rec, "AGT2_ZCC_MEAN", &status));
01039
01040
01041 drms_close_records(rs, DRMS_FREE_RECORD);
01042 }
01043 return(HKLMP_PASSED_STATUS);
01044 }
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056 int get_aiaiss34status_keywords(DRMS_Record_t *record, TIME *p_hkvals,char hk_time_val[HKLMP_PACKET_TIME_STR])
01057 {
01058
01059
01060
01061 DRMS_RecordSet_t *rs;
01062 DRMS_Record_t *rec;
01063 DRMS_Type_Value_t key_anyval;
01064 TIME adj_hkval;
01065 char adj_hkval_str[HKLMP_PACKET_TIME_STR];
01066 char nquery[HKLMP_MAX_QUERY_STR];
01067 char dsname[HKLMP_MAX_DSNAME_STR];
01068 char series[HKLMP_MAX_DSNAME_STR];
01069 char *sn;
01070 float leg_step;
01071 int status;
01072
01073
01074 sn=series;
01075 rs=NULL;
01076 rec=NULL;
01077
01078
01079 sn = (char *)getenv("HK_LMP_AIA_ISS34_SERIESNAME");
01080 if(sn == NULL)
01081 {
01082 printkerr("ERROR at %s, line %d: no aia iss34 status environment variable set. "
01083 " Set envirionment HK_LMP_AIA_ISS34_SERIESNAME variable in sourced file "
01084 " SOURCE_ENV_FOR_LOAD_MP.\n", __FILE__,__LINE__);
01085 return (HKLMP_FAILED_STATUS);
01086 }
01087
01088
01089 strcpy(dsname,sn);
01090
01091
01092 rs = drms_open_records(drms_env, dsname, &status);
01093 if(rs->n)
01094 {
01095 rec=rs->records[0];
01096 #ifdef DEBUG_LOAD_MP
01097 printf("load_mp:(37):get_aiaiss34status():number of records retrieved was %d\n",rs->n);
01098 #endif
01099 leg_step=drms_getkey_float(rec, "T_START_step", &status);
01100 drms_close_records(rs, DRMS_FREE_RECORD);
01101 }
01102 else
01103 {
01104 printkerr("ERROR at %s, line %d: Could not find records for <%s> series. "
01105 "Could not get step value needed to load this series values in master pointing series.\n",
01106 __FILE__,__LINE__,dsname);
01107 return(HKLMP_FAILED_STATUS);
01108 }
01109
01110
01111 #ifdef DEBUG_LOAD_MP
01112 printf("load_mp:(38):get_aiaiss34sstatus_keywords():hkval_str is <%s>\n",hk_time_val);
01113 #endif
01114
01115
01116 adj_hkval= *p_hkvals - leg_step;
01117
01118
01119 (void)sprint_time (adj_hkval_str, adj_hkval, "UTC", 0);
01120 strcat(adj_hkval_str,"\0");
01121 #ifdef DEBUG_LOAD_MP
01122 printf("load_mp:(39):get_aiaiss34status_keywords():adj_hkval_str is <%s>\n",adj_hkval_str);
01123 #endif
01124
01125
01126
01127
01128
01129 sprintf(nquery,"%s[? $(%s) >= T_START AND $(%s) < T_START ?]",dsname,hk_time_val, adj_hkval_str);
01130 #ifdef DEBUG_LOAD_MP
01131 printf("load_mp:(40):get_aiaiss34status():nquery is<%s>\n",nquery);
01132 #endif
01133
01134
01135 rs = drms_open_records(drms_env, nquery, &status);
01136 if(!rs->n)
01137 {
01138 printkerr("ERROR at %s, line %d: No Records found using query <%s>. "
01139 "Could not set values from <%s> series in master pointing series.\n",
01140 __FILE__,__LINE__,nquery,dsname);
01141 return(HKLMP_FAILED_STATUS);
01142 }
01143 if(rs->n)
01144 {
01145 rec=rs->records[0];
01146 #ifdef DEBUG_LOAD_MP
01147 printf("load_mp:(41):get_aiaiss34status():number of records retrieved was %d\n",rs->n);
01148 #endif
01149
01150
01151 drms_setkey_float(record, "AIA_IS3_ERRGAINY", drms_getkey_float(rec, "A3ERRGNY_MEAN", &status));
01152 drms_setkey_float(record, "AIA_IS3_ERRGAINZ", drms_getkey_float(rec, "A3ERRGNZ_MEAN", &status));
01153 drms_setkey_float(record, "AIA_IS3_ERROFFY", drms_getkey_float(rec, "A3ERROFY_MEAN", &status));
01154 drms_setkey_float(record, "AIA_IS3_ERROFFZ", drms_getkey_float(rec, "A3ERROFZ_MEAN", &status));
01155 drms_setkey_float(record, "AIA_IS3_PZTGAINA", drms_getkey_float(rec, "A3PZTGNA_MEAN", &status));
01156 drms_setkey_float(record, "AIA_IS3_PZTGAINB", drms_getkey_float(rec, "A3PZTGNB_MEAN", &status));
01157 drms_setkey_float(record, "AIA_IS3_PZTGAINC", drms_getkey_float(rec, "A3PZTGNC_MEAN",&status));
01158 drms_setkey_float(record, "AIA_IS3_PZTOFFA", drms_getkey_float(rec, "A3PZTOFA_MEAN", &status));
01159 drms_setkey_float(record, "AIA_IS3_PZTOFFB", drms_getkey_float(rec, "A3PZTOFB_MEAN", &status));
01160 drms_setkey_float(record, "AIA_IS3_PZTOFFC", drms_getkey_float(rec, "A3PZTOFC_MEAN", &status));
01161 drms_setkey_float(record, "AIA_GT3_PKT_YCOEF_A", drms_getkey_float(rec, "AGT3_YCA_MEAN", &status));
01162 drms_setkey_float(record, "AIA_GT3_PKT_YCOEF_B", drms_getkey_float(rec, "AGT3_YCB_MEAN", &status));
01163 drms_setkey_float(record, "AIA_GT3_PKT_YCOEF_C", drms_getkey_float(rec, "AGT3_YCC_MEAN", &status));
01164 drms_setkey_float(record, "AIA_GT3_PKT_ZCOEF_A", drms_getkey_float(rec, "AGT3_ZCA_MEAN", &status));
01165 drms_setkey_float(record, "AIA_GT3_PKT_ZCOEF_B", drms_getkey_float(rec, "AGT3_ZCB_MEAN", &status));
01166 drms_setkey_float(record, "AIA_GT3_PKT_ZCOEF_C", drms_getkey_float(rec, "AGT3_ZCC_MEAN", &status));
01167 drms_setkey_float(record, "AIA_IS4_ERRGAINY", drms_getkey_float(rec, "A4ERRGNY_MEAN", &status));
01168 drms_setkey_float(record, "AIA_IS4_ERRGAINZ", drms_getkey_float(rec, "A4ERRGNZ_MEAN", &status));
01169 drms_setkey_float(record, "AIA_IS4_ERROFFY", drms_getkey_float(rec, "A4ERROFY_MEAN", &status));
01170 drms_setkey_float(record, "AIA_IS4_ERROFFZ", drms_getkey_float(rec, "A4ERROFZ_MEAN", &status));
01171 drms_setkey_float(record, "AIA_IS4_PZTGAINA", drms_getkey_float(rec, "A4PZTGNA_MEAN", &status));
01172 drms_setkey_float(record, "AIA_IS4_PZTGAINB", drms_getkey_float(rec, "A4PZTGNB_MEAN", &status));
01173 drms_setkey_float(record, "AIA_IS4_PZTGAINC", drms_getkey_float(rec, "A4PZTGNC_MEAN", &status));
01174 drms_setkey_float(record, "AIA_IS4_PZTOFFA", drms_getkey_float(rec, "A4PZTOFA_MEAN", &status));
01175 drms_setkey_float(record, "AIA_IS4_PZTOFFB", drms_getkey_float(rec, "A4PZTOFB_MEAN", &status));
01176 drms_setkey_float(record, "AIA_IS4_PZTOFFC", drms_getkey_float(rec, "A4PZTOFC_MEAN", &status));
01177 drms_setkey_float(record, "AIA_GT4_PKT_YCOEF_A", drms_getkey_float(rec, "AGT4_YCA_MEAN", &status));
01178 drms_setkey_float(record, "AIA_GT4_PKT_YCOEF_B", drms_getkey_float(rec, "AGT4_YCB_MEAN", &status));
01179 drms_setkey_float(record, "AIA_GT4_PKT_YCOEF_C", drms_getkey_float(rec, "AGT4_YCC_MEAN", &status));
01180 drms_setkey_float(record, "AIA_GT4_PKT_ZCOEF_A", drms_getkey_float(rec, "AGT4_ZCA_MEAN", &status));
01181 drms_setkey_float(record, "AIA_GT4_PKT_ZCOEF_B", drms_getkey_float(rec, "AGT4_ZCB_MEAN", &status));
01182 drms_setkey_float(record, "AIA_GT4_PKT_ZCOEF_C", drms_getkey_float(rec, "AGT4_ZCC_MEAN", &status));
01183
01184
01185 drms_close_records(rs, DRMS_FREE_RECORD);
01186 }
01187
01188 return(HKLMP_PASSED_STATUS);
01189
01190 }
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201 void update_tstop_version(char query[HKLMP_MAX_QUERY_STR], char mp_tstart_value[HKLMP_PACKET_TIME_STR])
01202 {
01203 DRMS_RecordSet_t *old_rs;
01204 DRMS_Record_t *old_rec;
01205 DRMS_RecordSet_t *rs;
01206 DRMS_Record_t *rec;
01207 DRMS_Type_t keytype;
01208 DRMS_Type_Value_t key_anyval;
01209 TIME new_tstop;
01210 TIME prev_tstart;
01211 char keyname[HKLMP_MAX_KEYWORD_NAME_STR];
01212 char nquery[HKLMP_MAX_QUERY_STR];
01213 int status;
01214
01215
01216 sprintf(nquery,"%s[? T_START < $(%s) AND VERSION = 0 ?]",query,mp_tstart_value);
01217 #ifdef DEBUG_LOAD_MP
01218 printf("load_mp:(43):update_tstop_version(): query is:<%s> mp_tstart_value:<%s>\n",query, mp_tstart_value);
01219 printf("load_mp:(44):update_tstop_version():nquery is<%s>\n",nquery);
01220 #endif
01221
01222
01223 old_rs = drms_open_records(drms_env, nquery, &status);
01224
01225 if (status)
01226 {
01227 printkerr("ERROR at %s, line %d:update_tstop_version(): Cannot open record using this data"
01228 " series name:<%s>.Existing program.\n",__FILE__,__LINE__, query);
01229 status = drms_close_records(old_rs, DRMS_FREE_RECORD);
01230 return;
01231 }
01232 else
01233 {
01234 ;
01235 #ifdef DEBUG_LOAD_MP
01236 printf("load_mp:(45):update_tstop_version():Sucessfully created record for series <%s>\n", query);
01237 #endif
01238 }
01239
01240
01241 if (old_rs->n == 1)
01242 {
01243 old_rec = old_rs->records[0];
01244 #ifdef DEBUG_LOAD_MP
01245 printf("load_mp:(46):update_tstop_version():in if:got %d record\n",old_rs->n);
01246 #endif
01247 }
01248 else if (old_rs->n == 0)
01249 {
01250
01251 #ifdef DEBUG_LOAD_MP
01252 printf("load_mp:(47):update_tstop_version():if 0 records then no need to update old T_START Record. note got <%d> records\n",old_rs->n);
01253 #endif
01254 status = drms_close_records(old_rs, DRMS_FREE_RECORD);
01255 return;
01256 }
01257 else
01258 {
01259 #ifdef DEBUG_LOAD_MP
01260 printf("load_mp:(48):update_tstop_version():in else:got not 1 or 0 records. This should not occur. Got <%d> records\n",old_rs->n);
01261 #endif
01262 printkerr("ERROR at %s, line %d:update_tstop_version(): Got more than one record with"
01263 " verion equal to 0 for query:<%s>.Returning.\n",__FILE__,__LINE__, nquery);
01264 status = drms_close_records(old_rs, DRMS_FREE_RECORD);
01265 return;
01266 }
01267
01268
01269
01270 prev_tstart= drms_getkey_time(old_rec, "T_START", &status);
01271
01272
01273 rs = drms_create_records( drms_env, 1, query, DRMS_PERMANENT, &status);
01274
01275
01276 rec = rs->records[0];
01277
01278
01279 (void)drms_copykeys(rec, old_rec, 1, kDRMS_KeyClass_All);
01280
01281
01282
01283 strcpy(keyname, "T_START");
01284 keytype= DRMS_TYPE_TIME;
01285 key_anyval.time_val= prev_tstart;
01286 status = drms_setkey(rec, keyname, keytype, &key_anyval);
01287
01288
01289
01290 new_tstop = sscan_time( mp_tstart_value);
01291
01292 #ifdef DEBUG_LOAD_MP
01293 printf ("load_mp:(49):update_tstop_version:mp_tstart_value<%s>\n", mp_tstart_value);
01294 printf ("load_mp:(50):update_tstop_version:new_tstop_float<%f>\n", new_tstop);
01295 #endif
01296 strcpy(keyname, "T_STOP");
01297 keytype= DRMS_TYPE_TIME;
01298 key_anyval.time_val= new_tstop;
01299 status = drms_setkey(rec, keyname, keytype, &key_anyval);
01300
01301
01302 strcpy(keyname, "VERSION");
01303 keytype= DRMS_TYPE_INT;
01304 key_anyval.int_val= 1;
01305 status = drms_setkey(rec, keyname, keytype, &key_anyval);
01306
01307
01308 status = drms_close_records(rs, DRMS_INSERT_RECORD);
01309 if (status != 0)
01310 {
01311 printkerr("ERROR at %s, line %d: Cannot close drms record. Status ret:<%d> "
01312 "Failed to update rec that was the latest rec, with new T_STOP and VERSION values.\n",
01313 __FILE__,__LINE__,status);
01314 }
01315 else
01316 {
01317 ;
01318 #ifdef DEBUG_LOAD_MP
01319 printf("load_mp:(51):update_tstop_version(): Completed close of write of record for master pointing series\n");
01320 #endif
01321 }
01322
01323
01324 status = drms_close_records(old_rs, DRMS_FREE_RECORD);
01325 if (status != 0)
01326 {
01327 printkerr("ERROR at %s, line %d: Cannot close drms record. Status ret:<%d>\n",
01328 __FILE__,__LINE__,status);
01329 }
01330
01331 }
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341 int set_mp_version(char *sname, char tstart_str[HKLMP_PACKET_TIME_STR])
01342 {
01343
01344 DRMS_RecordSet_t *exists_rs;
01345 DRMS_Record_t *exists_rec;
01346 int status;
01347 int curr_ver;
01348 char rec_exists_query[HKLMP_MAX_QUERY_STR];
01349
01350 #ifdef DEBUG_LOAD_MP
01351 printf("load_mp:(16):set_mp_version(): Check if not last record and if there increment VERSION.\n");
01352 #endif
01353
01354
01355 sprintf(rec_exists_query,"%s[? T_START=$(%s) AND VERSION>=1 ?]",sname,tstart_str);
01356 #ifdef DEBUG_LOAD_MP
01357 printf("load_mp:(17):set_mp_version():Check rec exists with this query:<%s>\n", rec_exists_query);
01358 #endif
01359
01360 exists_rs = drms_open_records(drms_env, rec_exists_query, &status);
01361 if(exists_rs->n > 0)
01362 {
01363
01364 exists_rec=exists_rs->records[0];
01365 curr_ver=drms_getkey_int(exists_rec, "VERSION", &status);
01366 status = drms_close_records(exists_rs, DRMS_FREE_RECORD);
01367 return(++curr_ver);
01368 }
01369 else
01370 {
01371 status = drms_close_records(exists_rs, DRMS_FREE_RECORD);
01372
01373
01374 sprintf(rec_exists_query,"%s[? T_START>$(%s) AND VERSION=0 ?]",sname,tstart_str);
01375 exists_rs = drms_open_records(drms_env, rec_exists_query, &status);
01376 #ifdef DEBUG_LOAD_MP
01377 printf("load_mp:(18):set_mp_version():check rec exists using this query:<%s>\n",rec_exists_query);
01378 #endif
01379 if(exists_rs->n > 0)
01380 {
01381
01382 #ifdef DEBUG_LOAD_MP
01383 printf("load_mp:(19):set_mp_version():Rec exists:<%s>\n", rec_exists_query);
01384 #endif
01385
01386 status = drms_close_records(exists_rs, DRMS_FREE_RECORD);
01387 return(1);
01388 }
01389 else
01390 {
01391
01392 #ifdef DEBUG_LOAD_MP
01393 printf("load_mp:(20):set_mp_version():Rec does not exists:<%s>\n", rec_exists_query);
01394 #endif
01395 status = drms_close_records(exists_rs, DRMS_FREE_RECORD);
01396 return(0);
01397 }
01398 }
01399 }
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409 TIME set_tstop_value(char *sname, char tstart_str[HKLMP_PACKET_TIME_STR],TIME *ptstart)
01410 {
01411
01412 DRMS_RecordSet_t *exists_rs;
01413 DRMS_RecordSet_t *find_rs;
01414 DRMS_Record_t *exists_rec;
01415 DRMS_Record_t *find_rec;
01416 TIME curr_tstop;
01417 TIME find_closest;
01418 TIME find_current;
01419 char find_rec_query[HKLMP_MAX_QUERY_STR];
01420 char rec_exists_query[HKLMP_MAX_QUERY_STR];
01421 int find_rs_num;
01422 int i;
01423 int status;
01424
01425 #ifdef DEBUG_LOAD_MP
01426 printf("load_mp:(6)set_tstop_value():Setting T_STOP value\n");
01427 printf("load_mp:(7)set_tstop_value():tstart value passed is <%s>\n", tstart_str);
01428 #endif
01429
01430
01431 sprintf(rec_exists_query,"%s[? T_START=$(%s) AND VERSION>=1 ?]",sname,tstart_str);
01432 #ifdef DEBUG_LOAD_MP
01433 printf("load_mp:(8)set_tstop_value() CASE 1-if rec not last but record there:check if rec exists using query:<%s>\n", rec_exists_query);
01434 #endif
01435
01436 exists_rs = drms_open_records(drms_env, rec_exists_query, &status);
01437 if(exists_rs->n > 0)
01438 {
01439
01440 exists_rec=exists_rs->records[0];
01441
01442
01443 curr_tstop=drms_getkey_time(exists_rec, "T_STOP", &status);
01444 #ifdef DEBUG_LOAD_MP
01445 printf("load_mp:(9)set_tstop_value() Found rec for above Case 1-Retrieve T_STOP value from record and return back value:%f\n",curr_tstop);
01446 #endif
01447
01448
01449 status = drms_close_records(exists_rs, DRMS_FREE_RECORD);
01450
01451
01452 return(curr_tstop);
01453 }
01454 else
01455 {
01456
01457
01458
01459
01460 status = drms_close_records(exists_rs, DRMS_FREE_RECORD);
01461
01462
01463 sprintf(find_rec_query,"%s[? T_START>$(%s) AND VERSION>=0 ?]",sname,tstart_str);
01464 find_rs = drms_open_records(drms_env, find_rec_query, &status);
01465
01466
01467 find_rs_num=find_rs->n;
01468
01469 #ifdef DEBUG_LOAD_MP
01470 printf("load_mp:(10)set_tstop_value():CASE 2- if rec not last but less than all T_START times. Retrieve T_STOP value using this query:<%s>\n", find_rec_query);
01471 printf("load_mp:(11)set_tstop_value():Rec(s) found for above query. if zero use file value. find_rs_num:<%d>\n", find_rs_num);
01472 printf("load_mp:(12)set_tstop_value():new tstart value:ptstart:<%f>\n", *ptstart);
01473 #endif
01474
01475
01476 for(i=0, find_closest=0.0;i<find_rs_num;i++)
01477 {
01478 find_rec=find_rs->records[i];
01479 #ifdef DEBUG_LOAD_MP
01480 printf("load_mp:(13)set_tstop_value:Found rec for above CASE 2: T_START TIME got <%f>\n",drms_getkey_time(find_rec, "T_START", &status));
01481 #endif
01482 find_current=drms_getkey_time(find_rec, "T_START", &status);
01483 if(i == 0)
01484 {
01485
01486 find_closest= find_current;
01487 }
01488 else
01489 {
01490 if( (fabs(find_closest) - fabs(*ptstart)) > (fabs(find_current) - fabs(*ptstart)) )
01491 {
01492 find_closest= find_current;
01493 }
01494 }
01495 }
01496 status = drms_close_records(find_rs, DRMS_FREE_RECORD);
01497 #ifdef DEBUG_LOAD_MP
01498 printf("load_mp:(14):set_tstop_value:closest value:find_closest:<%f>\n", find_closest);
01499 #endif
01500
01501
01502 return(find_closest);
01503 }
01504 }
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516 void check_oldrec_tstop_time(char query[HKLMP_MAX_QUERY_STR], char mp_tstart_value[HKLMP_PACKET_TIME_STR])
01517 {
01518
01519 DRMS_RecordSet_t *old_rs;
01520 DRMS_Record_t *old_rec;
01521 DRMS_RecordSet_t *rs;
01522 DRMS_Record_t *rec;
01523 DRMS_Type_t keytype;
01524 DRMS_Type_Value_t key_anyval;
01525 TIME mp_tstop_value;
01526 TIME new_new_tstop;
01527 TIME new_tstop;
01528 TIME prev_tstart;
01529 char keyname[HKLMP_MAX_KEYWORD_NAME_STR];
01530 char nquery[HKLMP_MAX_QUERY_STR];
01531 int status;
01532 int old_rec_version;
01533 char new_new_tstop_str[HKLMP_PACKET_TIME_STR];
01534
01535
01536 sprintf(nquery,"%s[? T_START = $(%s) ?]",query,mp_tstart_value);
01537 #ifdef DEBUG_LOAD_MP
01538 printf("load_mp:(52):check_oldrec_tstop_time:query is:<%s> mp_tstart_value:<%s>\n",query, mp_tstart_value);
01539 printf("load_mp:(53):check_oldrec_tstop_time:nquery is<%s>\n",nquery);
01540 #endif
01541
01542
01543 rs = drms_open_records(drms_env, nquery, &status);
01544 rec=rs->records[0];
01545
01546
01547 new_new_tstop= drms_getkey_time(rec, "T_STOP", &status);
01548
01549
01550 #ifdef DEBUG_LOAD_MP
01551 (void)sprint_time (new_new_tstop_str, new_new_tstop, "UTC", 0);
01552 printf("load_mp:(54):new_new_tstop_str is %s\n", new_new_tstop_str);
01553 #endif
01554
01555
01556
01557 status = drms_close_records(rs, DRMS_FREE_RECORD);
01558
01559
01560 sprintf(nquery,"%s[? T_START < $(%s) AND T_STOP = %.0f ?]",query,mp_tstart_value, new_new_tstop);
01561 #ifdef DEBUG_LOAD_MP
01562 printf("load_mp:(55):check_oldrec_tstop_time:query is:<%s> mp_tstart_value:<%s>\n",query, mp_tstart_value);
01563 printf("load_mp:(56):check_oldrec_tstop_time:nquery is<%s>\n",nquery);
01564 #endif
01565
01566
01567 old_rs = drms_open_records(drms_env, nquery, &status);
01568
01569 if (status)
01570 {
01571 printkerr("ERROR at %s, line %d:check_oldrec_tstop_time(): Cannot create record using this data"
01572 " series name:<%s>.Existing program.\n",__FILE__,__LINE__, query);
01573 return;
01574 }
01575
01576
01577 if (old_rs->n == 1)
01578 {
01579 old_rec = old_rs->records[0];
01580 #ifdef DEBUG_LOAD_MP
01581 printf("load_mp:(57):check_oldrec_tstop_time():in if:got %d record\n",old_rs->n);
01582 #endif
01583 }
01584 else if (old_rs->n == 0)
01585 {
01586 #ifdef DEBUG_LOAD_MP
01587 printf("load_mp:(58):check_oldrec_tstop_time():if 0 records then no need to update old T_START Record. note got <%d> records\n",old_rs->n);
01588 #endif
01589 return;
01590 }
01591 else
01592 {
01593 #ifdef DEBUG_LOAD_MP
01594 printf("load_mp:(59):check_oldrec_tstop_time():in else-check_oldrec_tstop_time:got not 1 or 0 records. Got <%d> records\n",old_rs->n);
01595 #endif
01596 printkerr("ERROR at %s, line %d:check_oldrec_tstop_time(): Got more than one record with"
01597 " verion equal to 0 for query:<%s>.Returning.\n",__FILE__,__LINE__, nquery);
01598 return;
01599 }
01600
01601
01602
01603 prev_tstart= drms_getkey_time(old_rec, "T_START", &status);
01604
01605
01606 rs = drms_create_records( drms_env, 1, query, DRMS_PERMANENT, &status);
01607
01608
01609 rec = rs->records[0];
01610
01611
01612 (void)drms_copykeys(rec, old_rec, 1, kDRMS_KeyClass_All);
01613
01614
01615
01616 strcpy(keyname, "T_START");
01617 keytype= DRMS_TYPE_TIME;
01618 key_anyval.time_val= prev_tstart;
01619 status = drms_setkey(rec, keyname, keytype, &key_anyval);
01620
01621
01622
01623 new_tstop = sscan_time( mp_tstart_value);
01624
01625 #ifdef DEBUG_LOAD_MP
01626 printf ("load_mp:(60):check_oldrec_tstop_time():mp_tstart_value<%s>\n", mp_tstart_value);
01627 printf ("load_mp:(61):check_oldrec_tstop_time():new_tstop_float<%f>\n", new_tstop);
01628 #endif
01629 strcpy(keyname, "T_STOP");
01630 keytype= DRMS_TYPE_TIME;
01631 key_anyval.time_val= new_tstop;
01632 status = drms_setkey(rec, keyname, keytype, &key_anyval);
01633
01634
01635 old_rec_version= drms_getkey_time(old_rec, "VERSION", &status);
01636 strcpy(keyname, "VERSION");
01637 keytype= DRMS_TYPE_INT;
01638 key_anyval.int_val= old_rec_version + 1;
01639 status = drms_setkey(rec, keyname, keytype, &key_anyval);
01640
01641
01642 status = drms_close_records(rs, DRMS_INSERT_RECORD);
01643 if (status != 0)
01644 {
01645 printkerr("ERROR at %s, line %d: Cannot close rs drms record. Status ret:<%d>\n",
01646 __FILE__,__LINE__,status);
01647 }
01648 else
01649 {
01650 ;
01651 #ifdef DEBUG_LOAD_MP
01652 printf("load_mp:(62):check_oldrec_tstop_time():Successfully inserted update previous record and closed rs record. status <%d>\n",status);
01653 #endif
01654 }
01655
01656
01657 status = drms_close_records(old_rs, DRMS_FREE_RECORD);
01658 if (status != 0)
01659 {
01660 printkerr("ERROR at %s, line %d: Cannot close old_rs drms record. Status ret:<%d>\n",
01661 __FILE__,__LINE__,status);
01662 }
01663 else
01664 {
01665 ;
01666 #ifdef DEBUG_LOAD_MP
01667 printf("load_mp:(63):check_oldrec_tstop_time():Successfully closed old_rs record. status <%d>\n",status);
01668 #endif
01669 }
01670 }