00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <jsoc_main.h>
00026 #include <cmdparams.h>
00027 #include <drms.h>
00028 #include <drms_names.h>
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <ctype.h>
00032 #include <strings.h>
00033 #include <errno.h>
00034 #include <sys/types.h>
00035 #include <sys/time.h>
00036 #include <sys/stat.h>
00037 #include <dirent.h>
00038 #include <unistd.h>
00039 #include <printk.h>
00040 #include <math.h>
00041 #include <signal.h>
00042 #include "packets.h"
00043 #include "imgdecode_iris.h"
00044 #include "decode_hk_vcdu.h"
00045 #include "decode_hk.h"
00046 #include "load_hk_config_files.h"
00047 #include "add_small_image.c"
00048 #include "mypng.h"
00049 #include "tdsignals.h"
00050 #include "quallev0_iris.h"
00051
00052 #define RESTART_CNT 2 //#of tlm files to process before restart
00053
00054
00055
00056
00058
00059
00060
00061
00063
00064
00065
00066
00067 #define LEV0SERIESNAMEHMIGND "hmi_ground.lev0_dds"
00068 #define TLMSERIESNAMEHMIGND "hmi_ground.tlm_dds"
00069
00070
00071
00072
00074
00075
00076
00078
00079
00080
00081
00082 #define LEV0SERIESNAMEAIAGND "aia_ground.lev0_dds"
00083 #define TLMSERIESNAMEAIAGND "aia_ground.tlm_dds"
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 #define TLMSERIESNAMEHMI "iris_ground.tlm_lmsal"
00101 #define TLMSERIESNAMEHMIAMES "iris_ground.tlm_ames"
00102
00103
00104
00105
00106
00107
00108 #define LEV0SERIESNAMEHMI "iris_ground.lev0_ROT"
00109 #define LEV0SERIESNAMEHMIAMES "iris_ground.lev0_ames"
00110 #define LEV0SERIESNAMEAIA "su_prodtest.aia_lev0"
00111 #define TLMSERIESNAMEAIA "su_prodtest.aiatlm"
00112
00113 #define WDLOGDIR "/dds/logs"
00114 #define WDLOGFILE "wdlog"
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 #define H0LOGFILE "/usr/local/logs/lev0/ingest_lev0_iris.%s.%s.%s.log"
00132 #define PKTSZ 1788 //size of VCDU pkt
00133 #define MAXFILES 65535 //max # of file can handle in tlmdir
00134 #define NUMTIMERS 8 //number of seperate timers avail
00135
00136 #define IMAGE_NUM_COMMIT 1
00137 #define TESTAPPID 0x199 //appid of test pattern packet
00138 #define TESTVALUE 0xc0b //first value in test pattern packet
00139 #define MAXERRMSGCNT 10 //max # of err msg before skip the tlm file
00140 #define NOTSPECIFIED "***NOTSPECIFIED***"
00141
00142 #define ENVFILE "/home/prodtest/cvs/IRIS/proj/lev0/apps/SOURCE_ENV_FOR_HK_DECODE"
00143 #define ENVFILEA "/home/prodtest/cvs/IRIS/proj/lev0/apps/SOURCE_ENV_FOR_HK_DECODE_AMES"
00144 #define ENVFILE_GND "/home/production/cvs/JSOC/proj/lev0/apps/SOURCE_ENV_FOR_HK_DECODE_GROUND"
00145
00146 extern int decode_next_hk_vcdu(unsigned short *tbuf, CCSDS_Packet_t **hk, unsigned int *Fsn);
00147 extern int write_hk_to_drms();
00148 extern void HMI_compute_exposure_times(DRMS_Record_t *rec, HK_Keyword_t *isp, int flg);
00149
00150 extern void sprint_time_ISOX (char *tstring, TIME t);
00151 static TIME SDO_to_DRMS_time(int sdo_s, int sdo_ss);
00152
00153 int nxlook[5][9] = {
00154 {1096, 0, 0, 0, 0, 0, 0, 0, 0},
00155 {0, 1096, 1096, 0, 1096, 0, 0, 0, 1096},
00156 {0, 548, 548, 0, 548, 0, 0, 0, 548},
00157 {0, 0, 0, 0, 0, 0, 0, 0, 0},
00158 {0, 274, 274, 0, 274, 0, 0, 0, 274}
00159 };
00160
00161 int nylook[5][9] = {
00162 {4144, 0, 0, 0, 0, 0, 0, 0, 0},
00163 {0, 4144, 2072, 0, 1036, 0, 0, 0, 518},
00164 {0, 4144, 2072, 0, 1036, 0, 0, 0, 518},
00165 {0, 0, 0, 0, 0, 0, 0, 0, 0},
00166 {0, 4144, 2072, 0, 1036, 0, 0, 0, 518}
00167 };
00168
00169 int nxlookTap[5][9] = {
00170 {1096, 0, 0, 0, 0, 0, 0, 0, 0},
00171 {0, 1096, 1096, 0, 1096, 0, 0, 0, 1096},
00172 {0, 548, 548, 0, 548, 0, 0, 0, 548},
00173 {0, 0, 0, 0, 0, 0, 0, 0, 0},
00174 {0, 274, 274, 0, 274, 0, 0, 0, 274}
00175 };
00176
00177 int nylookTap[5][9] = {
00178 {2072, 0, 0, 0, 0, 0, 0, 0, 0},
00179 {0, 2072, 1036, 0, 518, 0, 0, 0, 259},
00180 {0, 2072, 1036, 0, 518, 0, 0, 0, 259},
00181 {0, 0, 0, 0, 0, 0, 0, 0, 0},
00182 {0, 2072, 1036, 0, 518, 0, 0, 0, 259}
00183 };
00184
00185
00186 int nxlookdefault = 1096;
00187 int nylookdefault = 4144;
00188 int nxlookTapdefault = 1096;
00189 int nylookTapdefault = 2072;
00190
00191 struct nextimage {
00192 DRMS_Record_t *rsN;
00193 DRMS_Segment_t *segN;
00194 IMG *imgN;
00195 int fsnN;
00196 };
00197
00198 struct nextimage NextImage;
00199 static int OpenNextImg = 0;
00200
00201
00202 ModuleArgs_t module_args[] = {
00203 {ARG_STRING, "vc", NOTSPECIFIED, "Primary virt channel to listen to"},
00204 {ARG_STRING, "indir", NOTSPECIFIED, "directory containing the files to ingest"},
00205 {ARG_STRING, "outdir", NOTSPECIFIED, "directory to move the files to after the ingest"},
00206 {ARG_STRING, "logfile", NOTSPECIFIED, "optional log file name. Will create one if not given"},
00207 {ARG_FLAG, "A", "0", "use Ames datasets"},
00208 {ARG_FLAG, "v", "0", "verbose flag"},
00209 {ARG_FLAG, "h", "0", "help flag"},
00210 {ARG_FLAG, "r", "0", "restart flag"},
00211 {ARG_END}
00212
00213 };
00214
00215 CmdParams_t cmdparams;
00216
00217 char *module_name = "ingest_lev0_iris";
00218
00219 typedef enum
00220 {
00221 kThreadSigErr_Success
00222 } ThreadSigErr_t;
00223 static short sumsptrl, sumspat;
00224 static int printflg = 0;
00225 static int errskip=0;
00226 static int nx, ny, npix;
00227 static int gLoop = 1;
00228 static pthread_mutex_t mutex;
00229 static struct timeval tv0;
00230 static td_alarm_t talarm = 0;
00231 FILE *wdlogfp;
00232 FILE *h0logfp;
00233 static IMG Image, ImageOld;
00234 static IMG *Img, *ImgO, *ImgC;
00235 static CCSDS_Packet_t *Hk;
00236 static DRMS_Record_t *rs;
00237 static DRMS_Segment_t *segment;
00238 static DRMS_Array_t *segArray;
00239 static DRMS_RecordSet_t *rset;
00240 static DRMS_Record_t *rs_old, *rsc;
00241 static DRMS_Segment_t *segmentc;
00242 static DRMS_Array_t *cArray, *oldArray;
00243 static DRMS_SegmentDimInfo_t DimInfo;
00244 static TIME sdo_epoch;
00245 static char datestr[32];
00246 static char bld_vers[16];
00247
00248 static struct timeval first[NUMTIMERS], second[NUMTIMERS];
00249 static char Indir[300];
00250 char wdlogname[128],oldwdlogname[128],Incmd[128];
00251
00252 int INVALtime;
00253 unsigned int fsn = 0;
00254 unsigned int fsnx = 0;
00255 unsigned int fsnISP = 0;
00256 unsigned int fsnISPTOCLOSE = 0;
00257 unsigned int fsnISPX = 0;
00258 unsigned int fsnISP_noop = 0;
00259 unsigned int fsn_prev = 0;
00260 unsigned int fsn_pre_rexmit = 0;
00261 unsigned int fid = 0;
00262 unsigned int tapcode = 0;
00263 unsigned int cropid = 0;
00264 unsigned int isysn = 0;
00265
00266 short *rdat;
00267 short tmpdat[MAXPIXELS];
00268 long long vcdu_seq_num;
00269 long long vcdu_seq_num_next;
00270 long long total_missing_im_pdu;
00271 unsigned int vcdu_24_cnt, vcdu_24_cnt_next;
00272 int verbose;
00273 int grounddata = 0;
00274 int appid;
00275 int testid1, testid2;
00276 int hmiaiaflg;
00277 int whk_status;
00278 int total_tlm_vcdu;
00279 int total_missing_vcdu;
00280 int errmsgcnt, fileimgcnt;
00281 int cntsleeps = 0;
00282 int nofiletimeout = 0;
00283 int timeoutclose = 0;
00284 int paused = 0;
00285 int imagecnt = 0;
00286 int restartflg = 0;
00287 int amesflg = 0;
00288 int abortflg = 0;
00289 int conterr = 0;
00290 int sigalrmflg = 0;
00291 int ignoresigalrmflg = 0;
00292 int firstfound = 0;
00293 int ALRMSEC = 60;
00294 int sleep_interval = 2;
00295 char ispquery[256];
00296 char logname[128];
00297 char argvc[32], argindir[96], arglogfile[96], argoutdir[96];
00298 char timetag[32];
00299 char pchan[8];
00300 char rchan[8];
00301 char stopfile[80];
00302 char tlmseriesname[128];
00303 char lev0seriesname[128];
00304 char tlmnamekey[128];
00305 char tlmnamekeyfirst[128];
00306 char oldtlmdsnam[128];
00307 char *username;
00308 char *tlmdir;
00309 char *outdir;
00310 char *logfile;
00311 char *vc;
00312 DRMS_RecordSet_t *RSISP, *RSISPTO;
00313 struct stat stbuf;
00314 struct p_r_chans {
00315 char *pchan;
00316 char *rchan;
00317 int instru;
00318 };
00319 typedef struct p_r_chans P_R_CHANS;
00320
00321 P_R_CHANS p_r_chan_pairs[] = {
00322 {"VC01", "VC09", 1},
00323 {"VC04", "VC12", 1},
00324 {"VC02", "VC10", 0},
00325 {"VC05", "VC13", 0},
00326 {"VC03", "VC11", 0},
00327 {"n/a", "n/a"}
00328 };
00329
00330 struct namesort {
00331 char *name;
00332 };
00333 typedef struct namesort NAMESORT;
00334
00335
00336 int nice_intro ()
00337 {
00338 int usage = cmdparams_get_int (&cmdparams, "h", NULL);
00339 if (usage)
00340 {
00341 printf ("Usage:\ningest_lev0_iris [-vh] "
00342 "vc=<virt chan> indir=</dir> [outdir=</dir>] [logfile=<file>]\n"
00343 " -h: help - show this message then exit\n"
00344 " -v: verbose\n"
00345
00346 " -c: continue processing the current fsn after a imgdecode() error\n"
00347 " -r: restart. only used when we restart ourselves periodically\n"
00348 " -A: Ames. Use Ames ds e.g. iris_ground.tlm_ames\n"
00349 "vc= primary virt channel to listen to e.g. VC02\n"
00350 "indir= directory containing the files to ingest\n"
00351 "outdir= optional dir to copy the files to after the ingest\n"
00352 "logfile= optional log file name. Will create one if not given\n");
00353 return(1);
00354 }
00355 verbose = cmdparams_get_int (&cmdparams, "v", NULL);
00356
00357 conterr = cmdparams_get_int (&cmdparams, "c", NULL);
00358 restartflg = cmdparams_get_int (&cmdparams, "r", NULL);
00359 amesflg = cmdparams_get_int (&cmdparams, "A", NULL);
00360 return (0);
00361 }
00362
00363 TIME SDO_to_DRMS_time(int sdo_s, int sdo_ss)
00364 {
00365 static int firstcall = 1;
00366 if (firstcall)
00367 {
00368 firstcall = 0;
00369 }
00370
00371 return(sdo_epoch + (TIME)sdo_s + (TIME)(sdo_ss)/65536.0);
00372 }
00373
00374
00375 char *do_datestr() {
00376 time_t tval;
00377 struct tm *t_ptr;
00378
00379 tval = time(NULL);
00380 t_ptr = localtime(&tval);
00381 sprintf(datestr, "%d.%02d.%02d_%02d:%02d:%02d",
00382 (t_ptr->tm_year+1900), (t_ptr->tm_mon+1),
00383 t_ptr->tm_mday, t_ptr->tm_hour, t_ptr->tm_min, t_ptr->tm_sec);
00384 return(datestr);
00385 }
00386
00387
00388 char *gettimetag()
00389 {
00390 struct timeval tvalr;
00391 struct tm *t_ptr;
00392
00393 gettimeofday(&tvalr, NULL);
00394 t_ptr = localtime((const time_t *)&tvalr);
00395 sprintf(timetag, "%04d.%02d.%02d.%02d%02d%02d",
00396 (t_ptr->tm_year+1900), (t_ptr->tm_mon+1), t_ptr->tm_mday, t_ptr->tm_hour, t_ptr->tm_min, t_ptr->tm_sec);
00397 return(timetag);
00398 }
00399
00400
00401 void BeginTimer(int n)
00402 {
00403 gettimeofday (&first[n], NULL);
00404 }
00405
00406 float EndTimer(int n)
00407 {
00408 gettimeofday (&second[n], NULL);
00409 if (first[n].tv_usec > second[n].tv_usec) {
00410 second[n].tv_usec += 1000000;
00411 second[n].tv_sec--;
00412 }
00413 return (float) (second[n].tv_sec-first[n].tv_sec) +
00414 (float) (second[n].tv_usec-first[n].tv_usec)/1000000.0;
00415 }
00416
00417
00418 int h0log(const char *fmt, ...)
00419 {
00420 va_list args;
00421 char string[32768];
00422
00423 va_start(args, fmt);
00424 vsprintf(string, fmt, args);
00425 if(h0logfp) {
00426 fprintf(h0logfp, string);
00427 fflush(h0logfp);
00428 } else {
00429 printf(string);
00430 fflush(stdout);
00431 }
00432 va_end(args);
00433 return(0);
00434 }
00435
00436 int send_mail(char *fmt, ...)
00437 {
00438 va_list args;
00439 char string[1024], cmd[1024];
00440
00441 va_start(args, fmt);
00442 vsprintf(string, fmt, args);
00443 sprintf(cmd, "echo \"%s\" | Mail -s \"ingest_lev0_iris mail\" prodtest", string);
00444 system(cmd);
00445 va_end(args);
00446 return(0);
00447 }
00448
00449
00450 void do_quallev0(DRMS_Record_t *rs, IMG *img, int fsn)
00451 {
00452 char *iissloop, *cdark, *cled;
00453 char *hseqerr, *aistate;
00454 char wave_str[16];
00455 int status, isqfsn, asqfsn;
00456 float percentd;
00457 uint32_t missvals, datav;
00458 uint32_t hcf1encd, hcf2encd, hps1encd, hps2encd, hps3encd;
00459 uint32_t hwt1encd, hwt2encd, hwt3encd, hwt4encd;
00460 uint32_t hcf1pos, hcf2pos, hpl1pos, hpl2pos, hpl3pos, hwl1pos, hwl2pos;
00461 uint32_t hwl3pos, hwl4pos;
00462 uint32_t aiawvlen, aifwen, aiasen;
00463 short aifiltyp;
00464 uint32_t quallev0 = 0;
00465 uint32_t qmiss = 0;
00466
00467 if(img->overflow) quallev0 = quallev0 | Q_OVFL;
00468 if(img->headerr) quallev0 = quallev0 | Q_HDRERR;
00469 if(img->nerrors) quallev0 = quallev0 | Q_CMPERR;
00470 if(img->last_pix_err) quallev0 = quallev0 | Q_LPXERR;
00471 if(img->reopened) quallev0 = quallev0 | Q_REOPENED;
00472 missvals = img->totalvals - img->datavals;
00473 if(missvals > 0) quallev0 = quallev0 | Q_MISS0;
00474 datav = img->totalvals;
00475 if(missvals > (uint32_t)(datav * 0.01)) quallev0 = quallev0 | Q_MISS1;
00476 if(missvals > (uint32_t)(datav * 0.05)) quallev0 = quallev0 | Q_MISS2;
00477 if(missvals > (uint32_t)(datav * 0.25)) quallev0 = quallev0 | Q_MISS3;
00478 if(missvals == datav) quallev0 = quallev0 | Q_MISSI;
00479 if(img->datavals == 0) quallev0 = quallev0 | Q_MISSALL;
00480
00481
00482
00483
00484
00485
00486
00487
00488 if(fsn == 469769216) quallev0 = quallev0 | Q_CORRUPT;
00489 if(INVALtime) quallev0 = quallev0 | Q_INVALTIME;
00490 if(cdark = drms_getkey_string(rs, "IMG_TYPE", &status)) {
00491 if(!strcmp(cdark, "DARK")) quallev0 = quallev0 | Q_DARK;
00492 free(cdark);
00493 }
00494 if(cled = drms_getkey_string(rs, "IMG_TYPE", &status)) {
00495 if(!strcmp(cled, "LED")) quallev0 = quallev0 | Q_LED;
00496 free(cled);
00497 }
00498 isqfsn = drms_getkey_int(rs, "ISQFSN", &status);
00499 if(status || (fsn != isqfsn)) quallev0 = quallev0 | Q_NOISP;
00500 if(iissloop = drms_getkey_string(rs, "IISSLOOP", &status)) {
00501 if(!strcmp(iissloop, "OPEN")) quallev0 = quallev0 | Q_ISSOPEN;
00502 free(iissloop);
00503 }
00504 drms_setkey_int(rs, "QUALITY", quallev0);
00505 drms_setkey_string(rs, "BLD_VERS", bld_vers);
00506 percentd = (float)((100.0 * (float)img->datavals)/(float)img->totalvals);
00507 drms_setkey_float(rs, "PERCENTD", percentd);
00508 }
00509
00510
00511 void close_image(DRMS_Record_t *rs, DRMS_Segment_t *seg, DRMS_Array_t *array,
00512 IMG *img, int fsn)
00513 {
00514 DRMS_RecordSet_t *rsisp;
00515 DRMS_Record_t *rsispr;
00516 STAT stat;
00517 int status, n, k, ival, i, j, nnx, nny;
00518 int drms_status = 0;
00519 short sval;
00520 uint32_t missvals;
00521 long long cmdx;
00522 TIME cmdxd;
00523 char *cptr, *iname;
00524 char tlmdsname[128];
00525 char queryext[256];
00526 char recdir[DRMS_MAXPATHLEN];
00527
00528 if(!img->initialized) {
00529 printk("**No image to close in close_image() for fsn = %u\n", fsn);
00530 return;
00531 }
00532 printk("*Closing image for fsn = %u\n", fsn);
00533 if(imgstat_iris(img, &stat)) {
00534 printk("**Error on imgstat_iris() for fsn = %u\n", fsn);
00535 }
00536 else {
00537 drms_setkey_short(rs, "DATAMIN", stat.min);
00538 drms_setkey_short(rs, "DATAMAX", stat.max);
00539 drms_setkey_short(rs, "DATAMEDN", stat.median);
00540 drms_setkey_float(rs, "DATAMEAN", stat.mean);
00541 drms_setkey_float(rs, "DATARMS", stat.rms);
00542 drms_setkey_float(rs, "DATASKEW", stat.skew);
00543 drms_setkey_float(rs, "DATAKURT", stat.kurt);
00544 }
00545
00546 if(hmiaiaflg) {
00547 drms_setkey_int(rs, "CAMERA", (img->telnum)+1);
00548 cmdx = drms_getkey_longlong(rs, "AIMGSHCE", &status);
00549 if (0 == cmdx) drms_setkey_int(rs, "AIMGTYP", 1);
00550 }
00551 else {
00552
00553
00554
00555
00556 }
00557 drms_setkey_int(rs, "IMGAPID", img->apid);
00558 drms_setkey_int(rs, "CROPID", img->cropid);
00559 drms_setkey_int(rs, "ISYSN", img->isysn);
00560 if(drms_setkey_int(rs, "LUTID", img->luid)) {
00561 printk("ERROR on setkey_int for LUTID\n");
00562 }
00563 status = drms_setkey_short(rs, "SUMSPTRL", sumsptrl);
00564 status = drms_setkey_short(rs, "SUMSPAT", sumspat);
00565 drms_setkey_int(rs, "TAPCODE", img->tap);
00566
00567 n = (img->N) & 0x1F;
00568 n = n << 3;
00569 k = (img->K) & 0x07;
00570 if(img->N == 16) {
00571 drms_setkey_int(rs, "COMPID", 0);
00572 drms_setkey_int(rs, "BITSELID", 0);
00573 }
00574 else {
00575 drms_setkey_int(rs, "COMPID", n+k);
00576 drms_setkey_int(rs, "BITSELID", img->R);
00577 }
00578 drms_setkey_int(rs, "FID", img->fid);
00579 drms_setkey_int(rs, "TOTVALS", img->totalvals);
00580 drms_setkey_int(rs, "DATAVALS", img->datavals);
00581 drms_setkey_int(rs, "NPACKETS", img->npackets);
00582 drms_setkey_int(rs, "NERRORS", img->nerrors);
00583 drms_setkey_short(rs, "EOIERROR", img->last_pix_err);
00584 drms_setkey_short(rs, "HEADRERR", img->headerr);
00585 drms_setkey_short(rs, "OVERFLOW", img->overflow);
00586 missvals = img->totalvals - img->datavals;
00587 drms_setkey_int(rs, "MISSVALS", missvals);
00588 snprintf(tlmdsname, 128, "%s[%s]", tlmseriesname, tlmnamekeyfirst);
00589 drms_setkey_string(rs, "TLMDSNAM", tlmdsname);
00590 unsigned int pts = img->first_packet_time >> 16;
00591 int ptss = img->first_packet_time & 0xffff;
00592 TIME fpt = SDO_to_DRMS_time(pts, ptss);
00593 drms_setkey_double(rs, "IMGFPT", fpt);
00594 drms_setkey_double(rs, "DATE", CURRENT_SYSTEM_TIME);
00595 do_quallev0(rs, img, fsn);
00596 if(!timeoutclose) {
00597 rsisp = RSISP;
00598 }
00599 else {
00600 timeoutclose = 0;
00601
00602 sprintf(queryext, "%s[? I_SQ_FRAME_SN=%d ?]", ispquery, fsn);
00603 printk("queryext = %s\n", queryext);
00604 rsisp = drms_open_records(drms_env, queryext, &drms_status);
00605 }
00606
00609 if(!rsisp || !rsisp->records || (fsn != fsnISP && !fsnISP_noop)) {
00610 printk("ERROR: Can't open isp record to put keywords in lev0.\n");
00611 printk(" The ISP was not received prior to the image for fsn %lu\n", fsn);
00612 printk(" Proceed anyway.\n");
00613 printk("drms_status=%d, rsisp=%lu, fsn=%lu, fsnISP=%lu, fsnISP_noop=%lu\n",
00614 drms_status, rsisp, fsn, fsnISP, fsnISP_noop);
00615 }
00616 else {
00617 fsnISP_noop = 0;
00618 rsispr = rsisp->records[0];
00619
00620
00621
00622
00623
00624
00625 iname = getenv("HK_ISP_IRIS_DSNAME");
00626 status = drms_setkey_string(rs, "ISPSNAME", iname);
00627 iname = drms_getkey_string(rsispr, "PACKET_VERSION_NUMBER",&status);
00628 status = drms_setkey_string(rs, "ISPPKTVN", iname);
00629 iname = drms_getkey_string(rsispr, "HK_SOURCE",&status);
00630 status = drms_setkey_string(rs, "HKSOURCE", iname);
00631 cmdxd = drms_getkey_double(rsispr, "PACKET_TIME", &status);
00632 status = drms_setkey_double(rs, "ISPPKTIM", cmdxd);
00633 cmdx = drms_getkey_longlong(rsispr, "APID56_TIMECODE_SEC", &status);
00634 status = drms_setkey_longlong(rs, "ITCS56", cmdx);
00635 cmdx = drms_getkey_longlong(rsispr, "APID56_TIMECODE_SSEC", &status);
00636 status = drms_setkey_longlong(rs, "ITCSS56", cmdx);
00637 ival = drms_getkey_int(rsispr, "APID56_APID_VERSION", &status);
00638 status = drms_setkey_int(rs, "IVER56", ival);
00639 sval = drms_getkey_short(rsispr, "I_SQ_ISYS_NUM", &status);
00640 status = drms_setkey_short(rs, "ISQISYSN", sval);
00641 ival = drms_getkey_int(rsispr, "I_SQ_FRAME_SN", &status);
00642 status = drms_setkey_int(rs, "ISQFSN", ival);
00643
00644
00645 sval = drms_getkey_short(rsispr, "I_IMG_CRS_ID", &status);
00646 status = drms_setkey_short(rs, "IICRSID", sval);
00647 sval = drms_getkey_short(rsispr, "I_IMG_OBSLIST_ID", &status);
00648 status = drms_setkey_short(rs, "IIOBSLID", sval);
00649 sval = drms_getkey_short(rsispr, "I_IMG_FRMLIST_ID", &status);
00650 status = drms_setkey_short(rs, "IIFRMLID", sval);
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660 iname = drms_getkey_string(rsispr, "I_ISS_LOOP",&status);
00661 status = drms_setkey_string(rs, "IISSLOOP", iname);
00662 sval = drms_getkey_short(rsispr, "I_IMG_CFG_DELAY_1", &status);
00663 status = drms_setkey_short(rs, "IIMGCFD1", sval);
00664 sval = drms_getkey_short(rsispr, "I_IMG_CFG_DELAY_2", &status);
00665 status = drms_setkey_short(rs, "IIMGCFD2", sval);
00666 sval = drms_getkey_short(rsispr, "I_IMG_CFG_DELAY_3", &status);
00667 status = drms_setkey_short(rs, "IIMGCFD3", sval);
00668 sval = drms_getkey_short(rsispr, "I_IMG_CFG_DELAY_4", &status);
00669 status = drms_setkey_short(rs, "IIMGCFD4", sval);
00670 sval = drms_getkey_short(rsispr, "I_GTP_SUNVECTOR_X", &status);
00671 status = drms_setkey_short(rs, "IGTPSVX", sval);
00672 sval = drms_getkey_short(rsispr, "I_GTP_SUNVECTOR_Y", &status);
00673 status = drms_setkey_short(rs, "IGTPSVY", sval);
00674 sval = drms_getkey_short(rsispr, "I_ISS_PZTOFFA", &status);
00675 status = drms_setkey_short(rs, "IISSPZTA", sval);
00676 sval = drms_getkey_short(rsispr, "I_ISS_PZTOFFB", &status);
00677 status = drms_setkey_short(rs, "IISSPZTB", sval);
00678 sval = drms_getkey_short(rsispr, "I_ISS_PZTOFFC", &status);
00679 status = drms_setkey_short(rs, "IISSPZTC", sval);
00680
00681
00682
00683
00684
00685 ival = drms_getkey_int(rsispr, "I_IMG_SH_CMDED_EXPOSURE", &status);
00686 status = drms_setkey_int(rs, "IIMGSHCE", ival);
00687 ival = drms_getkey_int(rsispr, "I_OBC_TIME_SH1_FUV_SEC", &status);
00688 status = drms_setkey_int(rs, "IIMGOTS1", ival);
00689 ival = drms_getkey_int(rsispr, "I_OBC_TIME_SH1_FUV_SS", &status);
00690 status = drms_setkey_int(rs, "IMGOTSS1", ival);
00691 ival = drms_getkey_int(rsispr, "I_MC_FUV_A_CLOSE_TIME", &status);
00692 status = drms_setkey_int(rs, "IFUVACT", ival);
00693 ival = drms_getkey_int(rsispr, "I_MC_FUV_A_OPEN_TIME", &status);
00694 status = drms_setkey_int(rs, "IFUVAOT", ival);
00695 ival = drms_getkey_int(rsispr, "I_MC_FUV_B_CLOSE_TIME", &status);
00696 status = drms_setkey_int(rs, "IFUVBCT", ival);
00697 ival = drms_getkey_int(rsispr, "I_MC_FUV_B_OPEN_TIME", &status);
00698 status = drms_setkey_int(rs, "IFUVBOT", ival);
00699 ival = drms_getkey_int(rsispr, "I_MC_FUV_C_CLOSE_TIME", &status);
00700 status = drms_setkey_int(rs, "IFUVCCT", ival);
00701 ival = drms_getkey_int(rsispr, "I_MC_FUV_C_OPEN_TIME", &status);
00702 status = drms_setkey_int(rs, "IFUVCOT", ival);
00703 ival = drms_getkey_int(rsispr, "I_MC_FUV_D_CLOSE_TIME", &status);
00704 status = drms_setkey_int(rs, "IFUVDCT", ival);
00705 ival = drms_getkey_int(rsispr, "I_MC_FUV_D_OPEN_TIME", &status);
00706 status = drms_setkey_int(rs, "IFUVDOT", ival);
00707 ival = drms_getkey_int(rsispr, "I_MC_FUV_E_CLOSE_TIME", &status);
00708 status = drms_setkey_int(rs, "IFUVECT", ival);
00709 ival = drms_getkey_int(rsispr, "I_MC_FUV_E_OPEN_TIME", &status);
00710 status = drms_setkey_int(rs, "IFUVEOT", ival);
00711 ival = drms_getkey_int(rsispr, "I_MC_FUV_F_CLOSE_TIME", &status);
00712 status = drms_setkey_int(rs, "IFUVFCT", ival);
00713 ival = drms_getkey_int(rsispr, "I_MC_FUV_F_OPEN_TIME", &status);
00714 status = drms_setkey_int(rs, "IFUVFOT", ival);
00715 ival = drms_getkey_int(rsispr, "I_OBC_TIME_SH2_NUV_SEC", &status);
00716 status = drms_setkey_int(rs, "IIMGOTS2", ival);
00717 ival = drms_getkey_int(rsispr, "I_OBC_TIME_SH2_NUV_SS", &status);
00718 status = drms_setkey_int(rs, "IMGOTSS2", ival);
00719 ival = drms_getkey_int(rsispr, "I_MC_NUV_A_CLOSE_TIME", &status);
00720 status = drms_setkey_int(rs, "INUVACT", ival);
00721 ival = drms_getkey_int(rsispr, "I_MC_NUV_A_OPEN_TIME", &status);
00722 status = drms_setkey_int(rs, "INUVAOT", ival);
00723 ival = drms_getkey_int(rsispr, "I_MC_NUV_B_CLOSE_TIME", &status);
00724 status = drms_setkey_int(rs, "INUVBCT", ival);
00725 ival = drms_getkey_int(rsispr, "I_MC_NUV_B_OPEN_TIME", &status);
00726 status = drms_setkey_int(rs, "INUVBOT", ival);
00727 ival = drms_getkey_int(rsispr, "I_MC_NUV_C_CLOSE_TIME", &status);
00728 status = drms_setkey_int(rs, "INUVCCT", ival);
00729 ival = drms_getkey_int(rsispr, "I_MC_NUV_C_OPEN_TIME", &status);
00730 status = drms_setkey_int(rs, "INUVCOT", ival);
00731 ival = drms_getkey_int(rsispr, "I_MC_NUV_D_CLOSE_TIME", &status);
00732 status = drms_setkey_int(rs, "INUVDCT", ival);
00733 ival = drms_getkey_int(rsispr, "I_MC_NUV_D_OPEN_TIME", &status);
00734 status = drms_setkey_int(rs, "INUVDOT", ival);
00735 ival = drms_getkey_int(rsispr, "I_MC_NUV_E_CLOSE_TIME", &status);
00736 status = drms_setkey_int(rs, "INUVECT", ival);
00737 ival = drms_getkey_int(rsispr, "I_MC_NUV_E_OPEN_TIME", &status);
00738 status = drms_setkey_int(rs, "INUVEOT", ival);
00739 ival = drms_getkey_int(rsispr, "I_OBC_TIME_SH3_SJI_SEC", &status);
00740 status = drms_setkey_int(rs, "IIMGOTS3", ival);
00741 ival = drms_getkey_int(rsispr, "I_OBC_TIME_SH3_SJI_SS", &status);
00742 status = drms_setkey_int(rs, "IMGOTSS3", ival);
00743 ival = drms_getkey_int(rsispr, "I_MC_SJI_A_CLOSE_TIME", &status);
00744 status = drms_setkey_int(rs, "ISJIACT", ival);
00745 ival = drms_getkey_int(rsispr, "I_MC_SJI_A_OPEN_TIME", &status);
00746 status = drms_setkey_int(rs, "ISJIAOT", ival);
00747 ival = drms_getkey_int(rsispr, "I_MC_SJI_B_CLOSE_TIME", &status);
00748 status = drms_setkey_int(rs, "ISJIBCT", ival);
00749 ival = drms_getkey_int(rsispr, "I_MC_SJI_B_OPEN_TIME", &status);
00750 status = drms_setkey_int(rs, "ISJIBOT", ival);
00751 ival = drms_getkey_int(rsispr, "I_MC_SJI_C_CLOSE_TIME", &status);
00752 status = drms_setkey_int(rs, "ISJICCT", ival);
00753 ival = drms_getkey_int(rsispr, "I_MC_SJI_C_OPEN_TIME", &status);
00754 status = drms_setkey_int(rs, "ISJICOT", ival);
00755 ival = drms_getkey_int(rsispr, "I_MC_SJI_D_CLOSE_TIME", &status);
00756 status = drms_setkey_int(rs, "ISJIDCT", ival);
00757 ival = drms_getkey_int(rsispr, "I_MC_SJI_D_OPEN_TIME", &status);
00758 status = drms_setkey_int(rs, "ISJIDOT", ival);
00759 ival = drms_getkey_int(rsispr, "I_MC_SJI_E_CLOSE_TIME", &status);
00760 status = drms_setkey_int(rs, "ISJIECT", ival);
00761 ival = drms_getkey_int(rsispr, "I_MC_SJI_E_OPEN_TIME", &status);
00762 status = drms_setkey_int(rs, "ISJIEOT", ival);
00763 ival = drms_getkey_int(rsispr, "I_IMG_AEC_TABLE_ID", &status);
00764 status = drms_setkey_int(rs, "IAECTID", ival);
00765 ival = drms_getkey_int(rsispr, "I_IMG_HIST_BIN_1", &status);
00766 status = drms_setkey_int(rs, "IIHIS1", ival);
00767 ival = drms_getkey_int(rsispr, "I_IMG_HIST_BIN_2", &status);
00768 status = drms_setkey_int(rs, "IIHIS2", ival);
00769 ival = drms_getkey_int(rsispr, "I_IMG_HIST_BIN_3", &status);
00770 status = drms_setkey_int(rs, "IIHIS3", ival);
00771 ival = drms_getkey_int(rsispr, "I_IMG_HIST_BIN_4", &status);
00772 status = drms_setkey_int(rs, "IIHIS4", ival);
00773 ival = drms_getkey_int(rsispr, "I_IMG_HIST_BIN_5", &status);
00774 status = drms_setkey_int(rs, "IIHIS5", ival);
00775 ival = drms_getkey_int(rsispr, "I_IMG_HIST_FSN", &status);
00776 status = drms_setkey_int(rs, "IIHISFSN", ival);
00777
00778 ival = drms_getkey_int(rsispr, "I_MC_FM_CMDED_POS", &status);
00779 status = drms_setkey_int(rs, "IFMCPOS", ival);
00780 ival = drms_getkey_int(rsispr, "I_MC_FM_POS", &status);
00781 status = drms_setkey_int(rs, "IFMPOS", ival);
00782 ival = drms_getkey_int(rsispr, "I_MC_FUV_ENCODER", &status);
00783 status = drms_setkey_int(rs, "IFUVENC", ival);
00784 ival = drms_getkey_int(rsispr, "I_MC_FW_CMDED_TGT", &status);
00785 status = drms_setkey_int(rs, "IFWCTGT", ival);
00786 ival = drms_getkey_int(rsispr, "I_MC_FW_ENCODER", &status);
00787 status = drms_setkey_int(rs, "IFWENC", ival);
00788 ival = drms_getkey_int(rsispr, "I_MC_FW_POS", &status);
00789 status = drms_setkey_int(rs, "IFWPOS", ival);
00790 sval = drms_getkey_short(rsispr, "I_GTP_BIAS_OFFSET_X", &status);
00791 status = drms_setkey_short(rs, "IGTPOFFX", sval);
00792 sval = drms_getkey_short(rsispr, "I_GTP_BIAS_OFFSET_Y", &status);
00793 status = drms_setkey_short(rs, "IGTPOFFY", sval);
00794 sval = drms_getkey_short(rsispr, "I_IMG_FRAME_TYPE", &status);
00795 status = drms_setkey_short(rs, "IIFRMTYP", sval);
00796 iname = drms_getkey_string(rsispr, "I_LED1_HW",&status);
00797 status = drms_setkey_string(rs, "ILED1HWS", iname);
00798 iname = drms_getkey_string(rsispr, "I_LED1_SW",&status);
00799 status = drms_setkey_string(rs, "ILED1SWS", iname);
00800 iname = drms_getkey_string(rsispr, "I_LED2_HW",&status);
00801 status = drms_setkey_string(rs, "ILED2HWS", iname);
00802 iname = drms_getkey_string(rsispr, "I_LED2_SW",&status);
00803 status = drms_setkey_string(rs, "ILED2SWS", iname);
00804 iname = drms_getkey_string(rsispr, "I_LED3_HW",&status);
00805 status = drms_setkey_string(rs, "ILED3HWS", iname);
00806 iname = drms_getkey_string(rsispr, "I_LED3_SW",&status);
00807 status = drms_setkey_string(rs, "ILED3SWS", iname);
00808 ival = drms_getkey_int(rsispr, "I_MC_NUV_ENCODER", &status);
00809 status = drms_setkey_int(rs, "INUVENC", ival);
00810 sval = drms_getkey_short(rsispr, "I_RT_PZTOFFA", &status);
00811 status = drms_setkey_short(rs, "IRTPZTA", sval);
00812 sval = drms_getkey_short(rsispr, "I_RT_PZTOFFB", &status);
00813 status = drms_setkey_short(rs, "IRTPZTB", sval);
00814 sval = drms_getkey_short(rsispr, "I_RT_PZTOFFC", &status);
00815 status = drms_setkey_short(rs, "IRTPZTC", sval);
00816 ival = drms_getkey_int(rsispr, "I_MC_SJI_ENCODER", &status);
00817 status = drms_setkey_int(rs, "ISJIENC", ival);
00818 sval = drms_getkey_short(rsispr, "I_HR_BIT_ID", &status);
00819 status = drms_setkey_short(rs, "ISQBITID", sval);
00820 sval = drms_getkey_short(rsispr, "I_HR_COMP_ID", &status);
00821 status = drms_setkey_short(rs, "ISQCMPID", sval);
00822 sval = drms_getkey_short(rsispr, "I_HR_TAP_CODE", &status);
00823 status = drms_setkey_short(rs, "IISQTAP", sval);
00824 sval = drms_getkey_short(rsispr, "I_WB_PZTOFFA", &status);
00825 status = drms_setkey_short(rs, "IWBPZTA", sval);
00826 sval = drms_getkey_short(rsispr, "I_WB_PZTOFFB", &status);
00827 status = drms_setkey_short(rs, "IWBPZTB", sval);
00828 sval = drms_getkey_short(rsispr, "I_WB_PZTOFFC", &status);
00829 status = drms_setkey_short(rs, "IWBPZTC", sval);
00830 ival = drms_getkey_int(rsispr, "I_MC_WM1_CMDED_DELAY", &status);
00831 status = drms_setkey_int(rs, "IWM1CDEL", ival);
00832 ival = drms_getkey_int(rsispr, "I_MC_WM1_POS", &status);
00833 status = drms_setkey_int(rs, "IWM1CPOS", ival);
00834 ival = drms_getkey_int(rsispr, "I_MC_WM1_CMDED_TGT", &status);
00835 status = drms_setkey_int(rs, "IWM1CTGT", ival);
00836 ival = drms_getkey_int(rsispr, "I_MC_WM1_ENCODER", &status);
00837 status = drms_setkey_int(rs, "IWM1ENC", ival);
00838 ival = drms_getkey_int(rsispr, "I_MC_WM2_CMDED_DELAY", &status);
00839 status = drms_setkey_int(rs, "IWM2CDEL", ival);
00840 ival = drms_getkey_int(rsispr, "I_MC_WM2_POS", &status);
00841 status = drms_setkey_int(rs, "IWM2CPOS", ival);
00842 ival = drms_getkey_int(rsispr, "I_MC_WM2_CMDED_TGT", &status);
00843 status = drms_setkey_int(rs, "IWM2CTGT", ival);
00844 ival = drms_getkey_int(rsispr, "I_MC_WM2_ENCODER", &status);
00845 status = drms_setkey_int(rs, "IWM2ENC", ival);
00846 ival = drms_getkey_int(rsispr, "I_TAT_ACS_STATUS", &status);
00847 status = drms_setkey_int(rs, "ITACSSTS", ival);
00848
00849 ival = drms_getkey_int(rsispr, "I_ISS_CONTROL", &status);
00850 status = drms_setkey_int(rs, "IISSCTRL", ival);
00851 sval = drms_getkey_short(rsispr, "I_ISS_DIODES", &status);
00852 status = drms_setkey_short(rs, "IISSDIOD", sval);
00853 sval = drms_getkey_short(rsispr, "I_ISS_OFFSET_RANGE", &status);
00854 status = drms_setkey_short(rs, "IISSOFFR", sval);
00855 sval = drms_getkey_short(rsispr, "I_ISS_SOURCE", &status);
00856 status = drms_setkey_short(rs, "IISS_SRC", sval);
00857 ival = drms_getkey_int(rsispr, "I_ISS_X_ERROR", &status);
00858 status = drms_setkey_int(rs, "ISXER", ival);
00859 ival = drms_getkey_int(rsispr, "I_ISS_X_ERROR_AVG", &status);
00860 status = drms_setkey_int(rs, "ISXERAVG", ival);
00861 ival = drms_getkey_int(rsispr, "I_ISS_X_ERROR_MAX", &status);
00862 status = drms_setkey_int(rs, "ISXERMAX", ival);
00863 ival = drms_getkey_int(rsispr, "I_ISS_X_ERROR_MIN", &status);
00864 status = drms_setkey_int(rs, "ISXERMIN", ival);
00865 ival = drms_getkey_int(rsispr, "I_ISS_Y_ERROR", &status);
00866 status = drms_setkey_int(rs, "ISYER,", ival);
00867 ival = drms_getkey_int(rsispr, "I_ISS_Y_ERROR_AVG", &status);
00868 status = drms_setkey_int(rs, "ISYERAVG", ival);
00869 ival = drms_getkey_int(rsispr, "I_ISS_Y_ERROR_MAX", &status);
00870 status = drms_setkey_int(rs, "ISYERMAX", ival);
00871 ival = drms_getkey_int(rsispr, "I_ISS_Y_ERROR_MIN", &status);
00872 status = drms_setkey_int(rs, "ISYERMIN", ival);
00873 sval = drms_getkey_short(rsispr, "I_MC_FUV_CMDED_DELAY", &status);
00874 status = drms_setkey_short(rs, "IFUVCDEL", sval);
00875 sval = drms_getkey_short(rsispr, "I_MC_FUV_CMDED_EXP", &status);
00876 status = drms_setkey_short(rs, "IFUVCEXP", sval);
00877 sval = drms_getkey_short(rsispr, "I_MC_NUV_CMDED_DELAY", &status);
00878 status = drms_setkey_short(rs, "INUVCDEL", sval);
00879 sval = drms_getkey_short(rsispr, "I_MC_NUV_CMDED_EXP", &status);
00880 status = drms_setkey_short(rs, "INUVCEXP", sval);
00881 sval = drms_getkey_short(rsispr, "I_MC_SJI_CMDED_DELAY", &status);
00882 status = drms_setkey_short(rs, "ISJICDEL", sval);
00883 sval = drms_getkey_short(rsispr, "I_MC_SJI_CMDED_EXP", &status);
00884 status = drms_setkey_short(rs, "ISJICEXP", sval);
00885 ival = drms_getkey_int(rsispr, "I_SQ_FLT_N_REPEAT", &status);
00886 status = drms_setkey_int(rs, "IIFLNRPT", ival);
00887 ival = drms_getkey_int(rsispr, "I_SQ_FLT_REPEAT", &status);
00888 status = drms_setkey_int(rs, "IIFLRPT", ival);
00889 ival = drms_getkey_int(rsispr, "I_SQ_OLT_N_REPEAT", &status);
00890 status = drms_setkey_int(rs, "IIOLNRPT", ival);
00891 ival = drms_getkey_int(rsispr, "I_SQ_OLT_REPEAT", &status);
00892 status = drms_setkey_int(rs, "IIOLRPT", ival);
00893 ival = drms_getkey_int(rsispr, "I_SQ_FUV_FDBT_ID", &status);
00894 status = drms_setkey_int(rs, "IIFUVFDB", ival);
00895 ival = drms_getkey_int(rsispr, "I_SQ_NUV_FDBT_ID", &status);
00896 status = drms_setkey_int(rs, "IINUVFDB", ival);
00897 ival = drms_getkey_int(rsispr, "I_SQ_SJI_FDBT_ID", &status);
00898 status = drms_setkey_int(rs, "IISJIFDB", ival);
00899 ival = drms_getkey_int(rsispr, "I_SQ_FDBT_IDX", &status);
00900 status = drms_setkey_int(rs, "ISQFDBTI", ival);
00901 sval = drms_getkey_short(rsispr, "I_SQ_OWT_ID", &status);
00902 status = drms_setkey_short(rs, "ISQOWTID", sval);
00903 sval = drms_getkey_short(rsispr, "I_SQ_SRT_ID", &status);
00904 status = drms_setkey_short(rs, "ISQSRTID", sval);
00905
00906
00907
00908 iname = drms_getkey_string(rsispr, "I_AEC_FLAG",&status);
00909 status = drms_setkey_string(rs, "IAECFLAG", iname);
00910 iname = drms_getkey_string(rsispr, "I_AEC_EV_FLAG",&status);
00911 status = drms_setkey_string(rs, "IAECEVFL", iname);
00912 iname = drms_getkey_string(rsispr, "I_AEC_FLARE_FLAG",&status);
00913 status = drms_setkey_string(rs, "IAECFLFL", iname);
00914 ival = drms_getkey_int(rsispr, "I_AEC_ENA_MSK", &status);
00915 status = drms_setkey_int(rs, "IAECENAM", ival);
00916 ival = drms_getkey_int(rsispr, "I_AEC_LAPSE_TIME", &status);
00917 status = drms_setkey_int(rs, "IAECLTIM", ival);
00918 ival = drms_getkey_int(rsispr, "I_AEC_EV_LAPSE_TIME", &status);
00919 status = drms_setkey_int(rs, "IAECEVLT", ival);
00920 ival = drms_getkey_int(rsispr, "I_SQ_FLT_IDX", &status);
00921 status = drms_setkey_int(rs, "ISQFLTDX", ival);
00922 ival = drms_getkey_int(rsispr, "I_SQ_FLT_N_IDX", &status);
00923 status = drms_setkey_int(rs, "ISQFLTNX", ival);
00924 ival = drms_getkey_int(rsispr, "I_SQ_OLT_IDX", &status);
00925 status = drms_setkey_int(rs, "ISQOLTDX", ival);
00926 ival = drms_getkey_int(rsispr, "I_SQ_OLT_N_IDX", &status);
00927 status = drms_setkey_int(rs, "ISQOLTNX", ival);
00928 ival = drms_getkey_int(rsispr, "I_SQ_PZT_A", &status);
00929 status = drms_setkey_int(rs, "ISQPZTA", ival);
00930 ival = drms_getkey_int(rsispr, "I_SQ_PZT_B", &status);
00931 status = drms_setkey_int(rs, "ISQPZTB", ival);
00932 ival = drms_getkey_int(rsispr, "I_SQ_PZT_C", &status);
00933 status = drms_setkey_int(rs, "ISQPZTC", ival);
00934 ival = drms_getkey_int(rsispr, "I_SQ_ORB_PERIOD", &status);
00935 status = drms_setkey_int(rs, "ISQORBPD", ival);
00936 ival = drms_getkey_int(rsispr, "I_SQ_ORB_EQ_SEC", &status);
00937 status = drms_setkey_int(rs, "ISQORBSE", ival);
00938 ival = drms_getkey_int(rsispr, "I_SQ_ORB_EQ_SUB", &status);
00939 status = drms_setkey_int(rs, "ISQORBSU", ival);
00940
00941
00942 drms_close_records(rsisp, DRMS_INSERT_RECORD);
00943
00944
00945 }
00946
00947 nnx = img->nx;
00948 nny = img->ny;
00949 npix = nnx * nny;
00950 for(i=0; i < nny; ++i) {
00951 for(j=0; j < nnx; ++j)
00952 tmpdat[i*nnx+j] = img->dat[j*nny+i];
00953 }
00954 memcpy(img->dat, tmpdat, 2*npix);
00955 status = drms_segment_writewithkeys(seg, array, 0);
00956
00957 if (status) {
00958 printk("ERROR: drms_segment_write error=%d for fsn=%u\n", status, fsn);
00959 }
00960 add_small_array(rs, array, 8, 16);
00961
00962 drms_record_directory(rs, recdir, 1);
00963
00964 printf("recdir from ingest_lev0_iris:<%s>\n",recdir);
00965 if(wdlogfp)
00966 {
00967 fprintf(wdlogfp,"%s\n",recdir);
00968 fflush(wdlogfp);
00969 sprintf(Incmd,"/bin/rm -f %s/%09u.fits",Indir,fsn);
00970 system(Incmd);
00971
00972 sprintf(Incmd,"ln -s %s/image.fits %s/%09u.fits",recdir,Indir,fsn);
00973 h0log("%s\n",Incmd);
00974 system(Incmd);
00975 }
00976
00977
00978 array->data = NULL;
00979 if(array) drms_free_array(array);
00980 if((status = drms_close_record(rs, DRMS_INSERT_RECORD))) {
00981 printk("**ERROR: drms_close_record failed for %s fsn=%u\n",
00982 lev0seriesname, fsn);
00983 }
00984 img->initialized = 0;
00985
00986 }
00987
00988
00989 void abortit(int stat)
00990 {
00991 printk("***Abort in progress ...\n");
00992 printk("**Exit ingest_lev0_iris w/ status = %d\n", stat);
00993 if (h0logfp) fclose(h0logfp);
00994 exit(stat);
00995 }
00996
00997
00998 int compare_names(const void *a, const void *b)
00999 {
01000 NAMESORT *x=(NAMESORT *)a, *y=(NAMESORT *)b;
01001 return(strcmp(x->name+4, y->name+4));
01002 }
01003
01004 unsigned short MDI_getshort (unsigned char *c)
01005 {
01006 unsigned short s = 0;
01007
01008 s = (unsigned short) *c++ << 8;
01009 s |= (unsigned short) *c;
01010 return s;
01011 }
01012
01013
01014 int fsn_normal_new_image()
01015 {
01016 int dstatus, i;
01017
01018
01019 Img->initialized = 0;
01020 Img->reopened = 0;
01021 errmsgcnt = 0;
01022 fsn_prev = fsnx;
01023 sprintf(tlmnamekeyfirst, "%s", tlmnamekey);
01024 rs = drms_create_record(drms_env, lev0seriesname, DRMS_PERMANENT, &dstatus);
01025 if(dstatus) {
01026 if(dstatus == DRMS_ERROR_SUMOPEN) {
01027 printk("**ERROR: DRMS can't open w/SUMS. Aborting...\n");
01028 abortit(4);
01029 }
01030 printk("**ERROR: Can't create record for %s fsn=%u\n", lev0seriesname, fsnx);
01031 NextImage.rsN = 0;
01032 return(1);
01033 }
01034 dstatus = drms_setkey_int(rs, "FSN", fsnx);
01035 if(!(segment = drms_segment_lookup(rs, "image"))) {
01036 printk("No drms_segment_lookup(rs, image)\n");
01037 NextImage.rsN = 0;
01038 return(1);
01039 }
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051 #if 0
01052 Img->datavals = 0;
01053 Img->npackets = 0;
01054 Img->nerrors = 0;
01055 Img->last_pix_err = 0;
01056 Img->first_packet_time = UINT64_MAX;
01057 for (i = 0; i < MAXPIXELS; ++i)
01058 Img->dat[i] = BLANK;
01059 for (i = 0; i < MAXHIST; ++i)
01060 Img->hist[i] = 0;
01061 #endif
01062
01063 imgdecode_iris_init_hack(Img);
01064
01065 rdat = Img->dat;
01066
01067
01068
01069
01070
01071 ImgC = Img;
01072
01073 NextImage.rsN = rs;
01074 NextImage.segN = segment;
01075 NextImage.imgN = Img;
01076 NextImage.fsnN = fsnx;
01077 OpenNextImg = 1;
01078 return(0);
01079 }
01080
01081
01082
01083 int fsn_change_normal()
01084 {
01085 int dstatus, rstatus, compid, n, k;
01086 int i, j, nnx, nny;
01087 char reopen_dsname[256];
01088 char *cptr;
01089
01090 printk("*FSN has changed from %u to %u\n", fsn_prev, fsnx);
01091 printflg = 0;
01092 if(fsn_prev == 0) {
01093 errmsgcnt = 0;
01094 errskip = 0;
01095 fsn_prev = fsnx;
01096 if(hmiaiaflg)
01097 sprintf(reopen_dsname, "%s[%u]", LEV0SERIESNAMEAIA, fsnx);
01098 else
01099 sprintf(reopen_dsname, "%s[%u]", LEV0SERIESNAMEHMI, fsnx);
01100 printk("Open normal prev ds: %s\n", reopen_dsname);
01101 rset = drms_open_records(drms_env, reopen_dsname, &rstatus);
01102 if(rstatus) {
01103 printk("Can't do drms_open_records(%s)\n", reopen_dsname);
01104 return(1);
01105 }
01106 if(!rset || (rset->n == 0) || rstatus) {
01107 printk("No prev ds\n");
01108 fsn_normal_new_image();
01109 }
01110 else {
01111 Img->initialized = 1;
01112 Img->reopened = 1;
01113 Img->fsn = fsnx;
01114 Img->apid = appid;
01115 rs_old = rset->records[0];
01116 rs = drms_clone_record(rs_old, DRMS_PERMANENT, DRMS_COPY_SEGMENTS, &rstatus);
01117 if(rstatus || !rs) {
01118 printk("Can't do drms_clone_record()\n");
01119 return(1);
01120 }
01121 drms_close_records(rset, DRMS_FREE_RECORD);
01122 rstatus = drms_setkey_int(rs, "FSN", fsnx);
01123 Img->telnum = drms_getkey_int(rs, "CAMERA", &rstatus);
01124 Img->telnum--;
01125 Img->cropid = drms_getkey_int(rs, "CROPID", &rstatus);
01126 Img->isysn = drms_getkey_int(rs, "ISYSN", &rstatus);
01127 Img->fid = drms_getkey_int(rs, "FID", &rstatus);
01128 Img->luid = drms_getkey_int(rs, "LUTID", &rstatus);
01129 if(rstatus) {
01130 Img->luid = 0;
01131 printk("ERROR on getkey_int for LUTID\n");
01132 }
01133 Img->tap = drms_getkey_int(rs, "TAPCODE", &rstatus);
01134 compid = drms_getkey_int(rs, "COMPID", &rstatus);
01135 if(compid == 0) {
01136 n = 16; k = 0;
01137 }
01138 else {
01139 k = compid & 0x07;
01140 n = compid >> 3;
01141 n = n & 0x1F;
01142 }
01143 Img->N = n;
01144 Img->K = k;
01145 Img->R = drms_getkey_int(rs, "BITSELID", &rstatus);
01146 Img->overflow = drms_getkey_int(rs, "OVERFLOW", &rstatus);
01147 Img->headerr = drms_getkey_int(rs, "HEADRERR", &rstatus);
01148 Img->totalvals = drms_getkey_int(rs, "TOTVALS", &rstatus);
01149 Img->datavals = drms_getkey_int(rs, "DATAVALS", &rstatus);
01150 Img->npackets = drms_getkey_int(rs, "NPACKETS", &rstatus);
01151 Img->nerrors = drms_getkey_int(rs, "NERRORS", &rstatus);
01152 Img->last_pix_err = drms_getkey_int(rs, "EOIERROR", &rstatus);
01153
01154 TIME fpt = drms_getkey_double(rs, "IMGFPT", &rstatus);
01155 Img->first_packet_time = round(65536.0*(fpt - sdo_epoch));
01156 if(Img->first_packet_time == 0)
01157 Img->first_packet_time = UINT64_MAX;
01158 snprintf(oldtlmdsnam, 128, "%s", drms_getkey_string(rs, "TLMDSNAM",&rstatus));
01159 cptr = strstr(oldtlmdsnam, "VC");
01160 if(cptr)
01161 snprintf(tlmnamekeyfirst, 23, "%s", cptr);
01162 else
01163 sprintf(tlmnamekeyfirst, "%s", "UNK");
01164 segment = drms_segment_lookupnum(rs, 0);
01165 if(!segment) {
01166 printk("Can't do drms_segment_lookupnum()\n");
01167 return(1);
01168 }
01169 cArray = drms_segment_read(segment, DRMS_TYPE_SHORT, &rstatus);
01170 if(rstatus || !cArray) {
01171 printk("Can't do drms_segment_read()\n");
01172 return(1);
01173 }
01174 short *adata = (short *)cArray->data;
01175
01176 memcpy(Img->dat, adata, 2*segment->axis[0]*segment->axis[1]);
01177 rdat = Img->dat;
01178
01179 nnx = segment->axis[0];
01180 nny = segment->axis[1];
01181 npix = nnx * nny;
01182 for(i=0; i < nnx; ++i) {
01183 for(j=0; j < nny; ++j)
01184 tmpdat[i*nny+j] = Img->dat[j*nnx+i];
01185 }
01186 memcpy(Img->dat, tmpdat, 2*npix);
01187
01188 segArray = drms_array_create(DRMS_TYPE_SHORT,
01189 segment->info->naxis,
01190 segment->axis,
01191 rdat,
01192 &dstatus);
01193 if(dstatus || !segArray) {
01194 printk("Can't do drms_array_create()\n");
01195 return(1);
01196 }
01197 ImgC = Img;
01198 drms_free_array(cArray);
01199 }
01200 }
01201 else {
01202 if(errskip) {
01203 errskip = 0;
01204 printk("*Skip Closing image for fsn = %u\n", fsn_prev);
01205 }
01206 else {
01207 if(rs && segArray) {
01208 close_image(rs, segment, segArray, Img, fsn_prev);
01209
01210 if(imagecnt++ >= IMAGE_NUM_COMMIT) {
01211 printk("drms_server_end_transaction()\n");
01212 drms_server_end_transaction(drms_env, 0 , 0);
01213 printk("drms_server_begin_transaction()\n");
01214 drms_server_begin_transaction(drms_env);
01215 imagecnt = 0;
01216 }
01217 fileimgcnt++;
01218 }
01219 else {
01220 printk("**ERROR: Null record ptr for an opened image fsn=%u\n",fsn_prev);
01221 }
01222 }
01223 if(fsn_normal_new_image()) {
01224 printk("**ERROR: Can't create new image\n");
01225 return(1);
01226 }
01227 }
01228
01229 return(0);
01230 }
01231
01232
01233
01234 int fsn_change_rexmit()
01235 {
01236 char rexmit_dsname[256];
01237 int rstatus, dstatus, compid, n, k;
01238 int i, j, nnx, nny;
01239 char *cptr;
01240
01241 if(fsn_prev != 0) {
01242 if(rsc) {
01243 close_image(rsc, segmentc, oldArray, ImgO, fsn_prev);
01244 imagecnt++;
01245 fileimgcnt++;
01246 }
01247 else {
01248 printk("**ERROR: Null record ptr for an rexmit image fsn=%u\n",fsn_prev);
01249 }
01250 }
01251 errmsgcnt = 0;
01252 fsn_prev = fsnx;
01253 if(hmiaiaflg)
01254 sprintf(rexmit_dsname, "%s[%u]", LEV0SERIESNAMEAIA, fsnx);
01255 else
01256 sprintf(rexmit_dsname, "%s[%u]", LEV0SERIESNAMEHMI, fsnx);
01257 printk("Open prev ds: %s\n", rexmit_dsname);
01258 rset = drms_open_records(drms_env, rexmit_dsname, &rstatus);
01259 if(rstatus) {
01260 printk("Can't do drms_open_records(%s)\n", rexmit_dsname);
01261 return(1);
01262 }
01263 if(!rset || (rset->n == 0) || rstatus) {
01264 startnew:
01265 printk("No prev ds\n");
01266 ImgO->initialized = 0;
01267 ImgO->reopened = 0;
01268
01269 imgdecode_iris_init_hack(ImgO);
01270 sprintf(tlmnamekeyfirst, "%s", tlmnamekey);
01271 rsc = drms_create_record(drms_env, lev0seriesname, DRMS_PERMANENT, &rstatus);
01272 if(rstatus) {
01273 if(rstatus == DRMS_ERROR_SUMOPEN) {
01274 printk("**ERROR: DRMS can't open w/SUMS. Aborting...\n");
01275 abortit(4);
01276 }
01277 printk("Can't create record for %s fsn=%u\n", lev0seriesname, fsnx);
01278 return(1);
01279 }
01280 rstatus = drms_setkey_int(rsc, "FSN", fsnx);
01281 if(!(segmentc = drms_segment_lookup(rsc, "image"))) {
01282 printk("No drms_segment_lookup(rsc, image)\n");
01283 return(1);
01284 }
01285 rstatus = drms_segment_setdims(segmentc, &DimInfo);
01286 rdat = ImgO->dat;
01287 oldArray = drms_array_create(DRMS_TYPE_SHORT,
01288 segmentc->info->naxis,
01289 segmentc->axis,
01290 rdat,
01291 &dstatus);
01292 if(dstatus || !oldArray) {
01293 printk("Can't do drms_array_create(%s)\n", rexmit_dsname);
01294 return(1);
01295 }
01296 }
01297 else {
01298 ImgO->initialized = 1;
01299 ImgO->reopened = 1;
01300 ImgO->fsn = fsnx;
01301 ImgO->apid = appid;
01302 rs_old = rset->records[0];
01303 rsc = drms_clone_record(rs_old, DRMS_PERMANENT, DRMS_COPY_SEGMENTS, &rstatus);
01304 if(rstatus) {
01305 printk("Can't do drms_clone_record()\n");
01306 printk("Assume this was a temp ds and the segments are now gone...\n");
01307 goto startnew;
01308
01309 }
01310 drms_close_records(rset, DRMS_FREE_RECORD);
01311 rstatus = drms_setkey_int(rsc, "FSN", fsnx);
01312 ImgO->telnum = drms_getkey_int(rsc, "CAMERA", &rstatus);
01313 ImgO->telnum--;
01314 ImgO->cropid = drms_getkey_int(rsc, "CROPID", &rstatus);
01315 ImgO->isysn = drms_getkey_int(rsc, "ISYSN", &rstatus);
01316 ImgO->fid = drms_getkey_int(rsc, "FID", &rstatus);
01317 ImgO->luid = drms_getkey_int(rsc, "LUTID", &rstatus);
01318 ImgO->tap = drms_getkey_int(rsc, "TAPCODE", &rstatus);
01319 compid = drms_getkey_int(rsc, "COMPID", &rstatus);
01320 if(compid == 0) {
01321 n = 16; k = 0;
01322 }
01323 else {
01324 k = compid & 0x07;
01325 n = compid >> 3;
01326 n = n & 0x1F;
01327 }
01328 ImgO->N = n;
01329 ImgO->K = k;
01330 ImgO->R = drms_getkey_int(rsc, "BITSELID", &rstatus);
01331 ImgO->overflow = drms_getkey_int(rsc, "OVERFLOW", &rstatus);
01332 ImgO->headerr = drms_getkey_int(rsc, "HEADRERR", &rstatus);
01333 ImgO->totalvals = drms_getkey_int(rsc, "TOTVALS", &rstatus);
01334 ImgO->datavals = drms_getkey_int(rsc, "DATAVALS", &rstatus);
01335 ImgO->npackets = drms_getkey_int(rsc, "NPACKETS", &rstatus);
01336 ImgO->nerrors = drms_getkey_int(rsc, "NERRORS", &rstatus);
01337 ImgO->last_pix_err = drms_getkey_int(rsc, "EOIERROR", &rstatus);
01338
01339 TIME fpt = drms_getkey_double(rsc, "IMGFPT", &rstatus);
01340 ImgO->first_packet_time = round(65536.0*(fpt - sdo_epoch));
01341 if(ImgO->first_packet_time == 0)
01342 ImgO->first_packet_time = UINT64_MAX;
01343 snprintf(oldtlmdsnam, 128, "%s", drms_getkey_string(rsc, "TLMDSNAM",&rstatus));
01344 cptr = strstr(oldtlmdsnam, "VC");
01345 if(cptr)
01346 snprintf(tlmnamekeyfirst, 23, "%s", cptr);
01347 else
01348 sprintf(tlmnamekeyfirst, "%s", "UNK");
01349 segmentc = drms_segment_lookupnum(rsc, 0);
01350 if(!segmentc) {
01351 printk("Can't do drms_segment_lookupnum()\n");
01352 return(1);
01353 }
01354 cArray = drms_segment_read(segmentc, DRMS_TYPE_SHORT, &rstatus);
01355 if(rstatus) {
01356 printk("Can't do drms_segment_read()\n");
01357 return(1);
01358 }
01359 short *adata = (short *)cArray->data;
01360
01361 memcpy(ImgO->dat, adata, 2*segmentc->axis[0]*segmentc->axis[1]);
01362 rdat = ImgO->dat;
01363
01364 nnx = segmentc->axis[0];
01365 nny = segmentc->axis[1];
01366 npix = nnx * nny;
01367 for(i=0; i < nnx; ++i) {
01368 for(j=0; j < nny; ++j)
01369 tmpdat[i*nny+j] = Img->dat[j*nnx+i];
01370 }
01371 memcpy(ImgO->dat, tmpdat, 2*npix);
01372
01373 oldArray = drms_array_create(DRMS_TYPE_SHORT,
01374 segmentc->info->naxis,
01375 segmentc->axis,
01376 rdat,
01377 &dstatus);
01378 if(dstatus || !oldArray) {
01379 printk("Can't do drms_array_create()\n");
01380 return(1);
01381 }
01382 drms_free_array(cArray);
01383 }
01384 ImgC = ImgO;
01385 return(0);
01386 }
01387
01388
01389 int get_tlm(char *file, int rexmit, int higherver)
01390 {
01391 FILE *fpin;
01392 unsigned char cbuf[PKTSZ];
01393 long long gap_42_cnt;
01394 int status, rstatus, fpkt_cnt, i, j, sync_bad_cnt;
01395 int datval, eflg, firstflg, dstatus, ntmp;
01396 unsigned int cnt1, cnt2, cnt3, gap_24_cnt, nxbits, nybits;
01397 int zero_pn;
01398 unsigned short pksync1, pksync2;
01399 float ftmp;
01400 int decode_status=0;
01401 unsigned int Fsn;
01402
01403 if(!(fpin = fopen(file, "r"))) {
01404 printk("*Can't open tlm file %s\n", file);
01405 return(1);
01406 }
01407 BeginTimer(1);
01408 printk("*Processing tlm file %s\n", file);
01409 fpkt_cnt = sync_bad_cnt = eflg = errmsgcnt = fileimgcnt = 0;
01410 zero_pn = gap_24_cnt = gap_42_cnt = 0;
01411 firstflg = 1;
01412 if(rexmit || higherver) {
01413 if(Img->initialized) {
01414 if(rs) {
01415 close_image(rs, segment, segArray, Img, fsn_prev);
01416 printk("drms_server_end_transaction()\n");
01417 drms_server_end_transaction(drms_env, 0 , 0);
01418 printk("drms_server_begin_transaction()\n");
01419 drms_server_begin_transaction(drms_env);
01420 imagecnt = 0;
01421 }
01422 else
01423 printk("**ERROR: Null record ptr for an opened image fsn=%u\n",fsn_prev);
01424 }
01425 fsn_pre_rexmit = fsn_prev;
01426 fsn_prev = 0;
01427 }
01428
01429 while((status = fread(cbuf,sizeof(char),PKTSZ,fpin) ) == PKTSZ) {
01430 pksync1 = MDI_getshort(cbuf);
01431 pksync2 = MDI_getshort(cbuf+2);
01432 if((pksync1 == 0) && (pksync2 == 0)) {
01433 if(!zero_pn) {
01434 printk("*0 PN code at pkt# %d\n", fpkt_cnt);
01435 printk("*Subsequent ones will be ignored until non-0 again\n");
01436 zero_pn = 1;
01437 }
01438 fpkt_cnt++;
01439 continue;
01440 }
01441 if((pksync1 != 0x1acf) || (pksync2 != 0xfc1d)) {
01442 printk("*Lost sync at VCDU pkt# %d. pksync1=%x pksync2=%x\n",
01443 fpkt_cnt, pksync1, pksync2);
01444 fpkt_cnt++;
01445 eflg++;
01446 if(sync_bad_cnt++ > 4) {
01447 printk("**Too many out of sync packets.\n");
01448
01449 return(0);
01450 }
01451 printk(" Will attempt to press on...\n");
01452 zero_pn = 0;
01453 continue;
01454 }
01455 if(firstflg) {
01456 printk("*VCDU pkt# %d sync = %x %x\n", fpkt_cnt, pksync1, pksync2);
01457 }
01458 fpkt_cnt++;
01459
01460 cnt1 = MDI_getshort(cbuf+6);
01461 cnt2 = MDI_getshort(cbuf+8);
01462 cnt2 = (cnt2 >> 8)& 0xFF;
01463 cnt2 = ((cnt1 << 8)& 0xFF00) + cnt2;
01464 cnt1 = (cnt1 >> 8)& 0xFF;
01465 vcdu_24_cnt = (cnt1*65536) + cnt2;
01466 if(vcdu_24_cnt_next != vcdu_24_cnt) {
01467 printk("*VCDU 24bit seq num out of sequence. exp: %u rec: %u\n",
01468 vcdu_24_cnt_next, vcdu_24_cnt);
01469 if(vcdu_24_cnt_next > vcdu_24_cnt) {
01470 printk("*NOTE: VCDU 24 bit counter retarded\n");
01471 printk("*NOTE: gap report will be inaccurate (tbd)\n");
01472 }
01473 if(!firstflg) {
01474 gap_24_cnt += vcdu_24_cnt - vcdu_24_cnt_next;
01475 }
01476 }
01477 vcdu_24_cnt_next = vcdu_24_cnt + 1;
01478
01479 cnt1 = MDI_getshort(cbuf+10);
01480 cnt2 = MDI_getshort(cbuf+12);
01481 cnt3 = MDI_getshort(cbuf+14);
01482 cnt1 = cnt1 & 0x03ff;
01483 vcdu_seq_num = (cnt1*4294967296) + (cnt2*65536) + cnt3;
01484
01485 if(vcdu_seq_num_next != vcdu_seq_num) {
01486 printk("*IM_PDU seq num out of sequence. exp: %lld rec: %lld\n",
01487 vcdu_seq_num_next, vcdu_seq_num);
01488 if(vcdu_seq_num_next > vcdu_seq_num) {
01489 printk("*NOTE: IM_PDU 42 bit counter retarded\n");
01490 printk("*NOTE: gap report will be inaccurate\n");
01491 }
01492 if(!firstflg) {
01493 gap_42_cnt += vcdu_seq_num - vcdu_seq_num_next;
01494 }
01495 eflg++;
01496 }
01497 firstflg = 0;
01498 vcdu_seq_num_next = vcdu_seq_num + 1;
01499
01500 appid = MDI_getshort(cbuf+18);
01501 appid = appid & 0x07ff;
01502 if(hmiaiaflg) {
01503
01504 testid1 = 507; testid2 = 517;
01505 }
01506 else {
01507
01508 testid1 = 407; testid2 = 417;
01509 }
01510
01511 if((appid == testid1) || (appid == testid2)) {
01512 if(errmsgcnt++ < MAXERRMSGCNT) {
01513 printk("*Test ApID of %0x found for IM_PDU Cntr = %lld\n",
01514 appid, vcdu_seq_num);
01515 for(i=0, j=TESTVALUE; i < 877; i=i+2, j++) {
01516 datval = MDI_getshort(cbuf+32+i);
01517 if(datval != j) {
01518 printk("*Test data value=%0x, expected=%0x for IM_PDU Cntr=%lld\n",
01519 datval, j, vcdu_seq_num);
01520 printk("*File = %s\n", file);
01521 eflg++;
01522 break;
01523 }
01524 }
01525 }
01526 continue;
01527 }
01528
01529
01530
01531
01532
01533 if(appid == APID_IRIS_SCIENCE)
01534 {
01535 cnt1 = MDI_getshort(cbuf+32);
01536 cnt2 = MDI_getshort(cbuf+34);
01537 isysn = (unsigned int)(cnt1<<16)+(unsigned int)(cnt2);
01538 isysn = isysn & 0xc0000000;
01539 isysn = (unsigned int)(isysn >> 30);
01540
01541 cnt1 = MDI_getshort(cbuf+40);
01542 cropid = (unsigned int)(cnt1 >> 4);
01543 cnt1 = MDI_getshort(cbuf+42);
01544 tapcode = (unsigned int)(cnt1 >> 12);
01545
01546 cnt1 = MDI_getshort(cbuf+36);
01547 nxbits = (unsigned int)(cnt1 >> 4) & 0x0f;
01548 nybits = (unsigned int)cnt1 & 0x0f;
01549 sumsptrl = (short)nybits;
01550 sumspat = (short)nxbits;
01551
01552
01553
01554 if((tapcode == 10) || (tapcode == 9) || (tapcode == 0 && cropid>0 && isysn !=
01555 0)) {
01556 nx = nxlookTap[nxbits][nybits];
01557 ny = nylookTap[nxbits][nybits];
01558 if(nx == 0) {
01559 nx = nxlookTapdefault;
01560 ny = nylookTapdefault;
01561 printk("WARNING: nxbits/nybits=%d/%d gave invalid nx of 0 for fsn=%u. Use default\n",
01562 nxbits, nybits, fsnx);
01563 }
01564 if(ny == 0) {
01565 nx = nxlookTapdefault;
01566 ny = nylookTapdefault;
01567 printk("WARNING: nxbits/nybits=%d/%d gave invalid ny of 0 for fsn=%u. Use default\n",
01568 nxbits, nybits, fsnx);
01569 }
01570 }
01571 else {
01572 nx = nxlook[nxbits][nybits];
01573 ny = nylook[nxbits][nybits];
01574 if(nx == 0) {
01575 nx = nxlookdefault;
01576 printk("WARNING: nxbits/nybits=%d/%d gave invalid nx of 0 for fsn=%u. Use default\n",
01577 nxbits, nybits, fsnx);
01578 }
01579 if(ny == 0) {
01580 ny = nylookdefault;
01581 printk("WARNING: nxbits/nybits=%d/%d gave invalid ny of 0 for fsn=%u. Use default\n",
01582 nxbits, nybits, fsnx);
01583 }
01584 }
01585
01586 ntmp = nx;
01587 nx = ny;
01588 ny = ntmp;
01589 if(!printflg) {
01590 printflg = 1;
01591 printk("nx/ny = %d/%d for fsn = %u\n", nx, ny, fsnx);
01592 printk("*FSN %u tapcode=%d cropid=%d\n", fsnx, tapcode, cropid);
01593 }
01594 DimInfo.naxis = 2;
01595 DimInfo.axis[0] = nx;
01596 DimInfo.axis[1] = ny;
01597 cnt1 = MDI_getshort(cbuf+32);
01598 cnt2 = MDI_getshort(cbuf+34);
01599 fsnx = (unsigned int)(cnt1<<16)+(unsigned int)(cnt2);
01600 fsnx = fsnx & 0x3fffffff;
01601 if(fsnx == 0) continue;
01602 if(tapcode == 10) {
01603
01604 fsnx++;
01605 fsnISP = fsnx;
01606 fsnISP_noop = 1;
01607 }
01608 if(OpenNextImg) {
01609 rs = NextImage.rsN;
01610 segment = NextImage.segN;
01611 ImgC = NextImage.imgN;
01612 if(drms_segment_setdims(segment, &DimInfo)) {
01613 printk("No drms_segment_setdims(segment, &DimInfo)\n");
01614 return(1);
01615 }
01616 segArray = drms_array_create(DRMS_TYPE_SHORT,
01617 segment->info->naxis,
01618 segment->axis,
01619 rdat,
01620 &dstatus);
01621 if(dstatus || !segArray) {
01622 printk("Can't do drms_array_create()\n");
01623 return(1);
01624 }
01625 OpenNextImg = 0;
01626 }
01627 if(rexmit || higherver) {
01628 if(fsnx != fsn_prev) {
01629 if(fsn_change_rexmit()) {
01630 printk("***FATAL ERROR in fsn_change_rexmit()\n");
01631 return(1);
01632 }
01633 }
01634 else {
01635 ImgC->apid = appid;
01636 }
01637 }
01638 else {
01639 if(fsnx != fsn_prev) {
01640 if(fsnx < fsn_prev) {
01641 printk("**WARNING: ISP out of order with image data\n");
01642 RSISP = 0;
01643 }
01644 if(fsn_change_normal()) {
01645 printk("***FATAL ERROR in fsn_change_normal()\n");
01646 return(1);
01647 }
01648 }
01649 }
01650
01651 if(errskip) { continue; }
01652 ImgC->nx = nx;
01653 ImgC->ny = ny;
01654 rstatus = imgdecode_iris((unsigned short *)(cbuf+10), ImgC);
01655 switch(rstatus) {
01656 case 0:
01657
01658 break;
01659 case IMGDECODE_DECOMPRESS_ERROR:
01660 if(errmsgcnt++ < MAXERRMSGCNT)
01661 printk("*imgdecode_iris() ret: IMGDECODE_DECOMPRESS_ERROR\n");
01662 break;
01663 case IMGDECODE_TOO_MANY_PIXELS:
01664 if(errmsgcnt++ < MAXERRMSGCNT)
01665 printk("*imgdecode_iris() ret: IMGDECODE_TOO_MANY_PIXELS\n");
01666 break;
01667 case IMGDECODE_BAD_N:
01668 if(errmsgcnt++ < MAXERRMSGCNT)
01669 printk("*imgdecode_iris() ret: IMGDECODE_BAD_N\n");
01670 break;
01671 case IMGDECODE_BAD_APID:
01672 if(errmsgcnt++ < MAXERRMSGCNT)
01673 printk("*imgdecode_iris() ret: IMGDECODE_BAD_APID\n");
01674 break;
01675 case IMGDECODE_NO_LOOKUP_TABLE:
01676 if(errmsgcnt++ < MAXERRMSGCNT)
01677 printk("*imgdecode_iris() ret: IMGDECODE_NO_LOOKUP_TABLE\n");
01678 break;
01679 case IMGDECODE_LOOKUP_ID_MISMATCH:
01680 if(errmsgcnt++ < MAXERRMSGCNT)
01681 printk("*imgdecode_iris() ret: IMGDECODE_LOOKUP_ID_MISMATCH\n");
01682 break;
01683 case IMGDECODE_BAD_LOOKUP_TABLE:
01684 if(errmsgcnt++ < MAXERRMSGCNT)
01685 printk("*imgdecode_iris() ret: IMGDECODE_BAD_LOOKUP_TABLE\n");
01686 break;
01687 case IMGDECODE_NO_CROP_TABLE:
01688 if(errmsgcnt++ < MAXERRMSGCNT)
01689 printk("*imgdecode_iris() ret: IMGDECODE_NO_CROP_TABLE\n");
01690 break;
01691 case IMGDECODE_CROP_ID_MISMATCH:
01692 if(errmsgcnt++ < MAXERRMSGCNT)
01693 printk("*imgdecode_iris() ret: IMGDECODE_CROP_ID_MISMATCH\n");
01694 break;
01695 case IMGDECODE_BAD_CROP_GEOMETRY:
01696 if(errmsgcnt++ < MAXERRMSGCNT)
01697 printk("*imgdecode_iris() ret: IMGDECODE_BAD_CROP_GEOMETRY\n");
01698 break;
01699 case IMGDECODE_BAD_CROP_TABLE:
01700 if(errmsgcnt++ < MAXERRMSGCNT)
01701 printk("*imgdecode_iris() ret: IMGDECODE_BAD_CROP_TABLE\n");
01702 break;
01703 case IMGDECODE_BAD_CROP_SKIP_TAKE:
01704 if(errmsgcnt++ < MAXERRMSGCNT)
01705 printk("*imgdecode_iris() ret: IMGDECODE_BAD_CROP_SKIP_TAKE\n");
01706 break;
01707 case IMGDECODE_BAD_OFFSET:
01708 if(errmsgcnt++ < MAXERRMSGCNT)
01709 printk("*imgdecode_iris() ret: IMGDECODE_BAD_OFFSET\n");
01710 break;
01711 case IMGDECODE_OUT_OF_MEMORY:
01712 if(errmsgcnt++ < MAXERRMSGCNT)
01713 printk("*imgdecode_iris() ret: IMGDECODE_OUT_OF_MEMORY\n");
01714 break;
01715 default:
01716 if(errmsgcnt++ < MAXERRMSGCNT)
01717 printk("*imgdecode_iris() ret: unknown err status = %d:\n", rstatus);
01718 break;
01719 }
01720 if(rstatus) {
01721 if(!conterr) {
01722 errskip = 1;
01723 printk("*FSN imgdecode() error. Skip fsn=%u\n", fsnx);
01724 }
01725 else printk("*FSN imgdecode() error. Continue processing fsn=%u\n", fsnx);
01726 }
01727 }
01728 else {
01729
01730 decode_status = decode_next_hk_vcdu((unsigned short *)(cbuf+10), &Hk, &Fsn);
01731
01732 switch (decode_status) {
01733 case SUCCESS_HK_NEED_TO_WTD_CTD:
01734 printk("*ISP found for fsn = %u\n", Fsn);
01735 fsnISP = fsnISPX;
01736 fsnISPX = Fsn;
01737 fsnx = Fsn;
01738 if(rexmit || higherver) {
01739 if(fsnx != fsn_prev) {
01740 if(fsn_change_rexmit()) {
01741 printk("***FATAL ERROR in fsn_change_rexmit()\n");
01742 return(1);
01743 }
01744 }
01745
01746 HMI_compute_exposure_times(rsc, Hk->keywords, hmiaiaflg);
01747 printk("Call write_hk_to_drms() after SUCCESS_HK_NEED_TO_WTD_CTD for rexmit\n");
01748 whk_status = write_hk_to_drms(rsc, &Hk);
01749
01750
01751
01752
01753
01754 }
01755 else {
01756 if(fsnx != fsn_prev) {
01757 if(fsn_change_normal()) {
01758 printk("***FATAL ERROR in fsn_change_normal()\n");
01759 return(1);
01760 }
01761 }
01762
01763 HMI_compute_exposure_times(rs, Hk->keywords, hmiaiaflg);
01764 printk("Calling write_hk_to_drms() after SUCCESS_HK_NEED_TO_WTD_CTD for normal fsn change\n");
01765 whk_status = write_hk_to_drms(rs, &Hk);
01766
01767
01768
01769
01770
01771 }
01772 hk_ccsds_free(&Hk);
01773 rstatus=0;
01774 break;
01775 case SUCCESS_HK_NEED_TO_CTD:
01776
01777
01778 break;
01779 case SUCCESS_SKIP_IMAGE:
01780 printk("decode_next_hk_vcdu() ret:Warning:SUCCESS_SKIP_IMAGE\n");
01781 break;
01782 case SUCCESS_SKIP_PROCESSING_APID:
01783 printk("decode_next_hk_vcdu() ret:Warning:SUCCESS_SKIP_PROCESSING_APID:\n");
01784 break;
01785 case ERROR_HK_FAILED_GETTING_FSN:
01786 printk("decode_next_hk_vcdu() ret:Warning:ERROR_HK_FAILED_GETTING_FSN:\n");
01787 break;
01788 case ERROR_NODATA:
01789 printk("decode_next_hk_vcdu() ret:Warning:ERROR_NODATA\n");
01790 break;
01791 case ERROR_HK_ENVIRONMENT_VARS_NOT_SET:
01792 printk("decode_next_hk_vcdu() ret:ERROR:ERROR_HK_ENVIRONMENT_VARS_NOT_SET\n");
01793 break;
01794 case ERROR_HK_FAILED_OPEN_DAYFILE:
01795 printk("decode_next_hk_vcdu() ret:ERROR:ERROR_HK_FAILED_OPEN_DAYFILE\n");
01796 break;
01797 default:
01798 printk("decode_next_hk_vcdu() ret:Warning:Unexpected return code for decode_status:<%d>:\n", decode_status);
01799 break;
01800 }
01801 }
01802 }
01803 fclose(fpin);
01804 if(!eflg) {
01805 printk("*No errors in tlm file\n");
01806 }
01807 if(rexmit || higherver) {
01808 if(rsc) {
01809 close_image(rsc, segmentc, oldArray, ImgO, fsnx);
01810 printk("drms_server_end_transaction()\n");
01811 drms_server_end_transaction(drms_env, 0 , 0);
01812 printk("drms_server_begin_transaction()\n\n");
01813 drms_server_begin_transaction(drms_env);
01814 imagecnt = 0;
01815 fileimgcnt++;
01816
01817 fsn_prev = 0;
01818 rsc = 0;
01819 }
01820 }
01821 ftmp = EndTimer(1);
01822 printk("%s\n**Processed %s\n**with %d images and %d VCDUs in %f sec\n\n",
01823 do_datestr(),file, fileimgcnt, fpkt_cnt, ftmp);
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838 if(fpkt_cnt != total_tlm_vcdu) {
01839 printk("**WARNING: Found #vcdu=%d; expected=%d\n", fpkt_cnt, total_tlm_vcdu);
01840 }
01841
01842
01843
01844
01845 if(gap_42_cnt != total_missing_im_pdu) {
01846 printk("**WARNING: IM_PDU 42bit cntr gaps=%lld; expected=%lld\n",
01847 gap_42_cnt, total_missing_im_pdu);
01848 }
01849 ignoresigalrmflg = 1;
01850 return(0);
01851 }
01852
01853
01854
01855
01856 void do_ingest()
01857 {
01858 FILE *fp;
01859 DRMS_Record_t *rs_tlm;
01860 DIR *dfd;
01861 NAMESORT *nameptr;
01862 struct dirent *dp;
01863 int i, j, status, mvstat;
01864 int rexmit, higherversion;
01865 char path[DRMS_MAXPATHLEN];
01866 char name[128], line[128], tlmfile[128], tlmname[96];
01867 char cmd[256], xxname[128], vername[16];
01868 char *token, *filename;
01869
01870 if((dfd=opendir(tlmdir)) == NULL) {
01871 printk("**Can't opendir(%s) to find files\n", tlmdir);
01872 abortit(3);
01873 }
01874 i = 0;
01875 if((nameptr = (NAMESORT *)malloc(MAXFILES * sizeof(NAMESORT))) == NULL) {
01876 printk("***Can't alloc memory for file name sort\n");
01877 abortit(3);
01878 }
01879
01880 while((dp=readdir(dfd)) != NULL) {
01881
01882
01883
01884 if(strstr(dp->d_name, pchan) || strstr(dp->d_name, rchan)) {
01885 nameptr[i++].name = strdup(dp->d_name);
01886 if(i >= MAXFILES) {
01887 printk("***Fatal error. Too many (%d) files in %s\n", MAXFILES, tlmdir);
01888 printf("***Fatal error. Too many (%d) files in %s\n", MAXFILES, tlmdir);
01889 abortit(3);
01890 }
01891 cntsleeps = 0;
01892 if(timeoutclose) {
01893
01894
01895 fsnISP = fsnISPTOCLOSE;
01896 }
01897 }
01898 }
01899 closedir(dfd);
01900 qsort(nameptr, i, sizeof(NAMESORT), &compare_names);
01901 nofiletimeout = atoi(getenv("FLUSH_2SEC_COUNT"));
01902
01903 for(j=0; j < i; j++) {
01904
01905
01906
01907
01908
01909 if(!strcmp(pchan, "VC01") || !strcmp(pchan, "VC02")) {
01910 if(strstr(nameptr[j].name, ".dsf")) {
01911
01912 sprintf(cmd, "/bin/mv -f %s/%s %s/dsf/",tlmdir,nameptr[j].name,tlmdir);
01913 printk("*mv dsf file to %s/dsf/\n", tlmdir);
01914 printk("%s\n", cmd);
01915 if(system(cmd)) {
01916 printk("***Error on: %s\n", cmd);
01917 }
01918 }
01919 }
01920 if(!strstr(nameptr[j].name, ".qac")) {
01921 free(nameptr[j].name);
01922 continue;
01923 }
01924 rexmit = higherversion = 0;
01925 if(strstr(nameptr[j].name, ".qacx")) {
01926 rexmit = 1;
01927 }
01928 sprintf(name, "%s/%s", tlmdir, nameptr[j].name);
01929 printk("%s\n*Found qac file:\n* %s\n", do_datestr(), name);
01930 if(!(fp=fopen(name, "r"))) {
01931 printk("***Can't open %s\n", name);
01932 free(nameptr[j].name);
01933 continue;
01934 }
01935
01936 while(fgets(line, 256, fp)) {
01937 if(line[0] == '#' || line[0] == '\n') continue;
01938 if(strstr(line, "TLM_FILE_NAME=")) {
01939 token = (char *)strtok(line, "=");
01940 token = (char *)strtok(NULL, "\n");
01941 printk("tlm file is %s\n", token);
01942 sprintf(tlmfile, "%s/%s", tlmdir, token);
01943 sprintf(tlmname, "%s", token);
01944 }
01945 else if(strstr(line, "TLM_FILE_SIZE=")) {
01946 token = (char *)strtok(line, "=");
01947 token = (char *)strtok(NULL, "=");
01948 printk("*tlm file size is %s", token);
01949 }
01950 else if((strstr(line, "TOTAL_TLM_IM_PDU=")) || (strstr(line, "TOTAL_VCDU="))) {
01951 token = (char *)strtok(line, "=");
01952 token = (char *)strtok(NULL, "\n");
01953 total_tlm_vcdu = atoi(token);
01954 }
01955 else if(strstr(line, "TOTAL_MISSING_VCDU=")) {
01956 token = (char *)strtok(line, "=");
01957 token = (char *)strtok(NULL, "\n");
01958 total_missing_vcdu = atoi(token);
01959 }
01960 else if(strstr(line, "TOTAL_MISSING_IM_PDU=")) {
01961 token = (char *)strtok(line, "=");
01962 token = (char *)strtok(NULL, "\n");
01963 total_missing_im_pdu = atol(token);
01964 break;
01965 }
01966 }
01967 fclose(fp);
01968
01969 strcpy((char *)tlmnamekey, (char *)tlmname);
01970 filename = (char *)rindex(tlmname, '.');
01971 if(!filename) {
01972 printk("**ERROR: Bad formed tlm name in qac file\n");
01973 printk(" tlm name = %s\n", tlmname);
01974 continue;
01975 }
01976 *filename = 0;
01977 *((char *)tlmnamekey+22) = 0;
01978 rs_tlm = drms_create_record(drms_env, tlmseriesname,
01979 DRMS_PERMANENT, &status);
01980 if(status) {
01981 if(status == DRMS_ERROR_SUMOPEN) {
01982 printk("**ERROR: DRMS can't open w/SUMS. Aborting...\n");
01983 abortit(4);
01984 }
01985 printk("***Can't create record for %s. Status=%d\n", tlmseriesname, status);
01986 continue;
01987 }
01988 if((status = drms_setkey_string(rs_tlm, "filename", tlmnamekey))) {
01989 printk("**ERROR: drms_setkey_string failed for 'filename'\n");
01990 }
01991 drms_record_directory(rs_tlm, path, 0);
01992 if(!*path) {
01993 printk("***ERROR: No path to segment for %s\n", tlmseriesname);
01994 continue;
01995 }
01996 if(outdir) {
01997 sprintf(cmd, "cp -p %s %s", name, outdir);
01998 printk("*cp qac file to %s\n", outdir);
01999 printk("%s\n", cmd);
02000 if(system(cmd)) {
02001 printk("***Error on: %s\n", cmd);
02002 }
02003 sprintf(cmd, "cp -p %s %s", tlmfile, outdir);
02004 printk("*cp tlm file to %s\n", outdir);
02005 printk("%s\n", cmd);
02006 if(system(cmd)) {
02007 printk("***Error on: %s\n", cmd);
02008 }
02009 }
02010 sprintf(cmd, "/bin/mv %s %s", name, path);
02011 printk("*mv qac to %s\n", path);
02012 printk("%s\n", cmd);
02013 if(status = system(cmd)) {
02014 printk("**ERROR: %d errno=%d on: %s\n", status, errno, cmd);
02015 if(WIFEXITED(status)) {
02016 if(mvstat = WEXITSTATUS(status)) {
02017 printk("**ERROR: mv exit status = %d\n", mvstat);
02018 }
02019 }
02020 }
02021 sprintf(cmd, "/bin/mv %s %s", tlmfile, path);
02022 printk("*mv tlm to %s\n", path);
02023 printk("%s\n", cmd);
02024 if(status = system(cmd)) {
02025 printk("**ERROR: %d errno=%d on: %s\n", status, errno, cmd);
02026 if(WIFEXITED(status)) {
02027 if(mvstat = WEXITSTATUS(status)) {
02028 printk("**ERROR: mv exit status = %d\n", mvstat);
02029 }
02030 }
02031 printk("**Continue after ERROR on mv of tlm file\n");
02032 continue;
02033 }
02034 if((status = drms_close_record(rs_tlm, DRMS_INSERT_RECORD))) {
02035 printk("**ERROR: drms_close_record failed for %s\n", tlmseriesname);
02036 }
02037
02038 sprintf(xxname, "%s/%s.tlm", path, tlmname);
02039 filename = (char *)rindex(tlmname, '_');
02040 sprintf(vername, "%s", filename);
02041 if(strcmp(vername, "_00")) {
02042 higherversion = 1;
02043 printk("Higher version tlm found: %s.tlm\n", tlmname);
02044 }
02045 firstfound = 1;
02046 if(get_tlm(xxname, rexmit, higherversion)) {
02047 printk("***Error in lev0 extraction for %s\n", xxname);
02048
02049
02050 }
02051 if((stat(stopfile, &stbuf) == 0) || abortflg) { break; }
02052 }
02053 free(nameptr);
02054 }
02055
02056
02057 void setup()
02058 {
02059 FILE *fp;
02060 int i;
02061 char string[128], cwdbuf[128], idstr[256];
02062 char envfile[100], s1[256],s2[256],s3[256], line[256];
02063 ThreadSigErr_t error = kThreadSigErr_Success;
02064
02065
02066 sdo_epoch = sscan_time("1958.01.01_00:00:00_TAI");
02067 do_datestr();
02068 printk_set(h0log, h0log);
02069 printk("%s\n", datestr);
02070 getcwd(cwdbuf, 126);
02071 sprintf(idstr, "Cwd: %s\nCall: ", cwdbuf);
02072 if(grounddata)
02073 sprintf(string, "ingest_lev0_irisROT -g started as pid=%d user=%s\n", getpid(), username);
02074 else
02075 sprintf(string, "ingest_lev0_irisROT [-A] started as pid=%d user=%s\n", getpid(), username);
02076 strcat(idstr, string);
02077 printk("*%s", idstr);
02078 if(restartflg) printk("-r ");
02079 sprintf(argvc, "vc=%s", vc);
02080 sprintf(argindir, "indir=%s", tlmdir);
02081 sprintf(arglogfile, "logfile=%s", logname);
02082 if(outdir) {
02083 sprintf(argoutdir, "outdir=%s", outdir);
02084 printk("%s %s %s %s\n", argvc, argindir, argoutdir, arglogfile);
02085 } else {
02086 printk("%s %s %s\n", argvc, argindir, arglogfile);
02087 }
02088 strcpy(pchan, vc);
02089 sprintf(stopfile, "/usr/local/logs/lev0/%s_stop", pchan);
02090 sprintf(string, "/bin/rm -f %s", stopfile);
02091 system(string);
02092 for(i=0; ; i++) {
02093 if(!strcmp(p_r_chan_pairs[i].pchan, pchan)) {
02094 strcpy(rchan, p_r_chan_pairs[i].rchan);
02095 hmiaiaflg = p_r_chan_pairs[i].instru;
02096 break;
02097 }
02098 if(!strcmp(p_r_chan_pairs[i].pchan, "n/a")) {
02099 printk("!!ERROR: Invalid VCid (%s) specified\n", pchan);
02100 fprintf(stderr, "!!ERROR: Invalid VCid (%s) specified. Abort\n", pchan);
02101 abortit(1);
02102 }
02103 }
02104 if(hmiaiaflg) {
02105 if(grounddata) {
02106 sprintf(tlmseriesname, "%s", TLMSERIESNAMEAIAGND);
02107 sprintf(lev0seriesname, "%s", LEV0SERIESNAMEAIAGND);
02108 }
02109 else {
02110 sprintf(tlmseriesname, "%s", TLMSERIESNAMEAIA);
02111 sprintf(lev0seriesname, "%s", LEV0SERIESNAMEAIA);
02112 }
02113 }
02114 else {
02115 if(grounddata) {
02116 sprintf(tlmseriesname, "%s", TLMSERIESNAMEHMIGND);
02117 sprintf(lev0seriesname, "%s", LEV0SERIESNAMEHMIGND);
02118 }
02119 else {
02120 if(amesflg) {
02121 sprintf(tlmseriesname, "%s", TLMSERIESNAMEHMIAMES);
02122 sprintf(lev0seriesname, "%s", LEV0SERIESNAMEHMIAMES);
02123 }
02124 else {
02125 sprintf(tlmseriesname, "%s", TLMSERIESNAMEHMI);
02126 sprintf(lev0seriesname, "%s", LEV0SERIESNAMEHMI);
02127 }
02128 }
02129 }
02130 sprintf(bld_vers, "%s", jsoc_version);
02131 umask(002);
02132 Image.initialized = 0;
02133 ImageOld.initialized = 0;
02134 Img = &Image;
02135 ImgO = &ImageOld;
02136
02137
02138 imgdecode_iris_init_hack(Img);
02139 imgdecode_iris_init_hack(ImgO);
02140
02141
02142
02143 if(grounddata) strcpy(envfile, ENVFILE_GND );
02144 else {
02145 if(amesflg) strcpy(envfile, ENVFILEA);
02146 else strcpy(envfile, ENVFILE);
02147 }
02148
02149 if(!(fp=fopen(envfile, "r"))) {
02150 printk("***Can't open %s. Check setting is correct\n", envfile);
02151 exit(0);
02152 }
02153
02154 while( fgets(line, MAXLINE_IN_FILE, fp) != NULL )
02155 {
02156 if (!strncmp(line, "#", 1)) {
02157 continue;
02158 }
02159 else {
02160 sscanf(line, "%s %s %s ", s1,s2,s3);
02161
02162 setenv(s2, s3, 1);
02163 }
02164 }
02165 fclose(fp);
02166 if(!restartflg) {
02167 printk("tlmseriesname=%s\nlev0seriesname=%s\nispseriesname=%s\n",
02168 tlmseriesname, lev0seriesname, getenv("HK_ISP_IRIS_DSNAME"));
02169 }
02170
02171
02172 sprintf(wdlogname,"%s_%s",WDLOGDIR,pchan);
02173 printf("making directory: %s\n", wdlogname);
02174 mkdir(wdlogname,0777);
02175 sprintf(wdlogname,"%s_%s/%s",WDLOGDIR,pchan,WDLOGFILE);
02176 sprintf(oldwdlogname,"%s_%s/%s.old",WDLOGDIR,pchan,WDLOGFILE);
02177 rename(wdlogname,oldwdlogname);
02178 if((wdlogfp=fopen(wdlogname,"w")) == NULL)
02179 {
02180 h0log("Can't open the log file %s\n", wdlogname);
02181 }
02182 else
02183 {
02184 fprintf(wdlogfp, "#image file of lev0 ds by hmi_lev0 %s\n", datestr);
02185 sprintf(Indir,"%s_%s/%s",WDLOGDIR,pchan,datestr);
02186 if(mkdir(Indir,0775))
02187 {
02188 h0log("Can't mkdir %s. Proceed without it\n",Indir);
02189 }
02190 }
02191
02192 }
02193
02194
02195 int DoIt(void)
02196 {
02197 pid_t pid;
02198 int wflg = 1;
02199 char *args[6];
02200 char callcmd[256];
02201
02202 if (nice_intro())
02203 return (0);
02204 if(!(username = (char *)getenv("USER"))) username = "nouser";
02205 vc = cmdparams_get_str(&cmdparams, "vc", NULL);
02206 tlmdir = cmdparams_get_str(&cmdparams, "indir", NULL);
02207 outdir = cmdparams_get_str(&cmdparams, "outdir", NULL);
02208 logfile = cmdparams_get_str(&cmdparams, "logfile", NULL);
02209 if (strcmp(vc, NOTSPECIFIED) == 0) {
02210 fprintf(stderr, "'vc' virt channel must be specified. Abort\n");
02211 return(1);
02212 }
02213 if (strcmp(tlmdir, NOTSPECIFIED) == 0) {
02214 fprintf(stderr, "'indir' must be specified. Abort\n");
02215 return(1);
02216 }
02217 if (strcmp(outdir, NOTSPECIFIED) == 0) {
02218 outdir = NULL;
02219 }
02220 if (strcmp(logfile, NOTSPECIFIED) == 0) {
02221 sprintf(logname, H0LOGFILE, username, vc, gettimetag());
02222 }
02223 else {
02224 sprintf(logname, "%s", logfile);
02225 }
02226 if(restartflg) {
02227
02228 if((h0logfp=fopen(logname, "a")) == NULL)
02229 fprintf(stderr, "**Can't open for append the log file %s\n", logname);
02230 }
02231 else {
02232 if((h0logfp=fopen(logname, "w")) == NULL)
02233 fprintf(stderr, "**Can't open the log file %s\n", logname);
02234 }
02235 setup();
02236 while(wflg) {
02237 do_ingest();
02238 if((stat(stopfile, &stbuf) == 0) || abortflg) {
02239 printk("Abort or Found file: %s. Terminate.\n", stopfile);
02240 if(abortflg) send_mail("Abort for ingest_lev0_iris for %s\n", pchan);
02241
02242 if(Image.initialized) {
02243 if(rs) {
02244 close_image(rs, segment, segArray, &Image, fsn_prev);
02245 }
02246 }
02247 else {
02248 printk("*No image to close on exit\n");
02249 }
02250
02251
02252
02253
02254
02255
02256
02257 sprintf(callcmd, "touch /usr/local/logs/lev0/%s_exit", pchan);
02258 system(callcmd);
02259 wflg = 0;
02260 continue;
02261 }
02262 sleep(sleep_interval);
02263 if(cntsleeps == 0) {
02264 if(paused) {
02265 paused = 0;
02266 send_mail("tlm files seen again for ingest_lev0_iris for %s\n", pchan);
02267 }
02268 }
02269 else {
02270 if(cntsleeps >= nofiletimeout) {
02271
02272 if(Image.initialized) {
02273 if(rs) {
02274 printf("Data flow stopped for %d sec. Closing current image.\n",
02275 nofiletimeout*2);
02276 printk("Data flow stopped for %d sec. Closing current image.\n",
02277 nofiletimeout*2);
02278 RSISP = RSISPTO;
02279 fsnISPTOCLOSE = fsnISP;
02280 fsnISP = fsnISPX;
02281 close_image(rs, segment, segArray, &Image, fsn_prev);
02282 timeoutclose = 1;
02283 drms_server_end_transaction(drms_env, 0 , 0);
02284 drms_server_begin_transaction(drms_env);
02285 fsn_prev = 0;
02286 }
02287 }
02288 else {
02289
02290 }
02291 }
02292 }
02293 cntsleeps++;
02294 if(cntsleeps > 300) {
02295 if(!paused) {
02296 send_mail("No files seen for ingest_lev0_iris for %s for 600sec\n", pchan);
02297 paused = 1;
02298 }
02299 }
02300 }
02301 return(0);
02302 }
02303