00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00013
00014 #include <jsoc_main.h>
00015 #include <cmdparams.h>
00016 #include <drms.h>
00017 #include <drms_names.h>
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020 #include <ctype.h>
00021 #include <strings.h>
00022 #include <sys/types.h>
00023 #include <sys/time.h>
00024 #include <sys/stat.h>
00025 #include <unistd.h>
00026 #include <printk.h>
00027 #include <astro.h>
00028 #include <fresize.h>
00029 #include <gapfill.h>
00030
00031 #include "fftw3.h"
00032 #include "imgdecode.h"
00033 #include "lev0lev1.h"
00034 #include "quallev1.h"
00035 #include "limb_fit.h"
00036 #include "cosmic_ray.h"
00037 #include "get_pointing_info.c"
00038
00039
00040
00041
00042 #define LEV0SERIESNAMEHMI "su_production.lev0f_hmi"
00043 #define LEV0SERIESNAMEAIA "su_production.lev0f_aia"
00044
00045 #define LEV1SERIESNAMEHMI "hmi.lev1"
00046 #define LEV1SERIESNAMEAIA "su_production.aia_lev1e" //temp test case
00047
00048 #define DSFFNAMEHMI "su_production.hmi_flatfield" //temp test case
00049 #define DSFFNAMEAIA "su_production.aia_flatfield" //temp test case
00050
00051 #define LEV1LOG_BASEDIR "/usr/local/logs/lev1"
00052 #define H1LOGFILE "/usr/local/logs/lev1/build_lev1.%s.log"
00053 #define NUMTIMERS 8 //number of seperate timers avail
00054 #define NOTSPECIFIED "***NOTSPECIFIED***"
00055 #define LOGTEST 0
00056 #define CAL_HCFTID 17 //image is cal mode
00057
00058 #define kDpath "dpath"
00059 #define kDpathDef "/home/jsoc/cvs/Development/JSOC"
00060
00061 int compare_rptr(const void *a, const void *b);
00062 static TIME SDO_to_DRMS_time(int sdo_s, int sdo_ss);
00063
00064
00065 ModuleArgs_t module_args[] = {
00066 {ARG_STRING, "instru", NOTSPECIFIED, "instrument. either hmi or aia"},
00067 {ARG_STRING, "mode", NOTSPECIFIED, "either recnum or fsn"},
00068 {ARG_STRING, "dsin", NOTSPECIFIED, "dataset of lev0 filtergrams"},
00069 {ARG_STRING, "dsout", NOTSPECIFIED, "dataset of lev1 output"},
00070 {ARG_STRING, "logfile", NOTSPECIFIED, "optional log file name. Will create one if not given"},
00071 {ARG_INTS, "brec", "0", "first lev0 rec# to process. 0=error must be given by build_lev1_mgr"},
00072 {ARG_INTS, "erec", "0", "last lev0 rec# to process. 0=error must be given by build_lev1_mgr"},
00073 {ARG_INTS, "bfsn", "0", "first lev0 fsn# to process. 0=error must be given by build_lev1_mgr"},
00074 {ARG_INTS, "efsn", "0", "last lev0 fsn# to process. 0=error must be given by build_lev1_mgr"},
00075 {ARG_INTS, "quicklook", "1", "1=quick look, 0 = definitive mode"},
00076 {ARG_FLAG, "v", "0", "verbose flag"},
00077 {ARG_FLAG, "h", "0", "help flag"},
00078 {ARG_FLAG, "r", "0", "restart flag"},
00079 {ARG_STRING, kDpath, kDpathDef, "path to the source code tree (the JSOC root directory)"},
00080 {ARG_END}
00081 };
00082
00083 CmdParams_t cmdparams;
00084
00085 char *module_name = "build_lev1";
00086
00087 FILE *h1logfp;
00088
00089
00090
00091 static LEV0LEV1 lev0lev1;
00092 static LEV0LEV1 *l0l1 = &lev0lev1;
00093
00094 static DRMS_Record_t *rs;
00095 static DRMS_Record_t *rs0, *rs1, *rsff, *rsbad_pix;
00096 static DRMS_Record_t *rptr;
00097 static DRMS_Segment_t *segment;
00098 static DRMS_Segment_t *segmentff;
00099 static DRMS_Segment_t *darkseg;
00100 static DRMS_Segment_t *badseg;
00101 static DRMS_Segment_t *badoutpixseg;
00102 static DRMS_Segment_t *spikeseg;
00103 static DRMS_Array_t *segArray;
00104 static DRMS_RecordSet_t *rset0, *rset1, *rsetff;
00105 static DRMS_Array_t *Array0;
00106 static DRMS_Array_t *Arrayff;
00107 static DRMS_Array_t *ArrayDark;
00108 static DRMS_Array_t *ArrayBad;
00109 static DRMS_Array_t *ArraySpike;
00110 static TIME sdo_epoch;
00111 static PTINFO *ptinfo = NULL;
00112 static PTINFO ptdata;
00113 static char bld_vers[16];
00114 static char datestr[32];
00115 static char open_dsname[256];
00116 static char dsffname[128];
00117 static char path[DRMS_MAXPATHLEN], bad_pix_path[DRMS_MAXPATHLEN];
00118 static char rs1_path[DRMS_MAXPATHLEN];
00119 static struct timeval first[NUMTIMERS], second[NUMTIMERS];
00120 static char *orbseries = "sdo.fds_orbit_vectors";
00121
00122
00123 static int nspikes, *oldvalues, *spikelocs, *newvalues;
00124
00125 IORBIT_Info_t *IOinfo = NULL;
00126 IORBIT_Info_t IOdata;
00127 LIBASTRO_Error_t IOstatus;
00128 unsigned int fsnarray[NUMRECLEV1];
00129 unsigned int fsnx = 0;
00130
00131
00132 float data1[MAXPIXELS];
00133 int data1A[MAXPIXELS];
00134
00135 double tgttimes[NUMRECLEV1];
00136
00137 long long brec, erec, bfsn, efsn;
00138 long long bnumx, enumx;
00139 int verbose;
00140 int hmiaiaflg = 0;
00141 int modeflg = 0;
00142 int imagecnt = 0;
00143 int restartflg = 0;
00144 int abortflg = 0;
00145 int sigalrmflg = 0;
00146 int ignoresigalrmflg = 0;
00147 int quicklook;
00148
00149 int flatmiss[NUMRECLEV1];
00150 int orbmiss[NUMRECLEV1];
00151 int asdmiss[NUMRECLEV1];
00152 int mpdmiss[NUMRECLEV1];
00153 int noimage[NUMRECLEV1];
00154 int missflg[NUMRECLEV1];
00155
00156 char logname[128];
00157 char argdsin[128], argdsout[128], arglogfile[128], arginstru[80];
00158 char argbx[80], argex[80], argquick[80], argmode[80];
00159 char timetag[32];
00160 char tlmseriesname[128];
00161 char lev0seriesname[128];
00162 char *username;
00163 char *logfile;
00164 char *instru;
00165 char *mode;
00166 char *dsin;
00167 char *dsout;
00168
00170 typedef struct {
00171 float rsun_lf;
00172 float x0_lf;
00173 float y0_lf;
00174 } LIMB_SOMETHING;
00175
00176
00177
00178 int get_nspikes() { return nspikes; }
00179 int *get_spikelocs() { return spikelocs; }
00180 int *get_oldvalues() { return oldvalues; }
00181 int *get_newvalues() { return newvalues; }
00182 void set_nspikes(int new_nspikes) { nspikes = new_nspikes; }
00183 void set_spikelocs(int *new_spikelocs) { spikelocs = new_spikelocs; }
00184 void set_oldvalues(int *new_oldvalues) { oldvalues = new_oldvalues; }
00185 void set_newvalues(int *new_newvalues) { newvalues = new_newvalues; }
00186
00187
00188 void do_quallev1(DRMS_Record_t *rs0, DRMS_Record_t *rs1, int inx, unsigned int fsn)
00189 {
00190 int quallev1 = 0;
00191 int rstatus;
00192 char *pchar;
00193
00194 quallev1 = missflg[inx];
00195 if(flatmiss[inx]) quallev1 = quallev1 | Q_NOFLAT;
00196 if(orbmiss[inx]) quallev1 = quallev1 | Q_NOORB;
00197 if(asdmiss[inx]) quallev1 = quallev1 | Q_NOASD;
00198 if(mpdmiss[inx]) quallev1 = quallev1 | Q_NOMPD;
00199 if(noimage[inx]) quallev1 = quallev1 | Q_MISSALL;
00200 if(ptinfo) {
00201 ptdata = ptinfo[inx];
00202 if(strcmp(ptdata.acs_mode, "SCIENCE")) {
00203 quallev1 = quallev1 | Q_NOACS_SCI;
00204 }
00205 if(strcmp(ptdata.acs_eclp, "NO")) {
00206 quallev1 = quallev1 | Q_ACS_ECLP;
00207 }
00208 if(strcmp(ptdata.acs_sunp, "YES")) {
00209 quallev1 = quallev1 | Q_ACS_SUNP;
00210 }
00211 if(strcmp(ptdata.acs_safe, "NO")) {
00212 quallev1 = quallev1 | Q_ACS_SAFE;
00213 }
00214 }
00215 pchar = drms_getkey_string(rs0, "IMG_TYPE", &rstatus);
00216 if(rstatus) {
00217 printk("ERROR: in drms_getkey_string(IMG_TYPE) fsn=%u\n", fsn);
00218 }
00219 else {
00220 if(strcmp(pchar, "LIGHT")) {
00221 quallev1 = quallev1 | Q_IMG_TYPE;
00222 }
00223 }
00224 if(hmiaiaflg) {
00225 pchar = drms_getkey_string(rs0, "AISTATE", &rstatus);
00226 }
00227 else {
00228 pchar = drms_getkey_string(rs0, "HWLTNSET", &rstatus);
00229 }
00230 if(rstatus) {
00231 printk("ERROR: in drms_getkey_string(HWLTNSET or AISTATE) fsn=%u\n", fsn);
00232 }
00233 else {
00234 if(!strcmp(pchar, "OPEN")) {
00235 quallev1 = quallev1 | Q_LOOP_OPEN;
00236 }
00237 }
00238
00240
00241 if(quicklook) {
00242 quallev1 = quallev1 | Q_NRT;
00243 }
00244 drms_setkey_int(rs1, "QUALITY", quallev1);
00245 drms_setkey_string(rs, "BLD_VERS", bld_vers);
00246 }
00247
00248 int nice_intro ()
00249 {
00250 int usage = cmdparams_get_int (&cmdparams, "h", NULL);
00251 if (usage)
00252 {
00253 printf ("Usage:\nbuild_lev1 [-vhr] "
00254 "mode=<recnum|fsn> instru=<hmi|aia> dsin=<lev0> dsout=<lev1>\n"
00255 "brec=<rec#>|bfsn=<fsn#> erec=<rec#>|efsn=<fsn#>\n"
00256 "quicklook=<0|1> [logfile=<file>]\n"
00257 " -h: help - show this message then exit\n"
00258 " -v: verbose\n"
00259 " -r: restart. only used when we restart our selves periodically\n"
00260 "mode= recnum: brec and erec have the record # range to process \n"
00261 " fsn: bfsn and efsn have the fsn # range to process\n"
00262 " For safety, the mode and arg name used must be consistent\n"
00263 "instru= instrument. must be 'hmi' or 'aia'\n"
00264 "dsin= data set name of lev0 input\n"
00265 " default hmi=hmi.lev0e aia=aia.lev0e\n"
00266 "dsout= data set name of lev1 output\n"
00267 " default hmi=su_production.hmi_lev1e aia=su_production.aia_lev1e\n"
00268 "brec= first lev0 rec# to process. 0=error must be given by build_lev1_mgr\n"
00269 "erec= last lev0 rec# to process. 0=error must be given by build_lev1_mgr\n"
00270 "bfsn= first fsn# to process. 0=error must be given by build_lev1_mgr\n"
00271 "efsn= last fsn# to process. 0=error must be given by build_lev1_mgr\n"
00272 "quicklook= 1 = quicklook mode, 0 = definitive mode\n"
00273 "logfile= optional log file name. If not given uses:\n"
00274 " /usr/local/logs/lev1/build_lev1.<time_stamp>.log\n");
00275 return(1);
00276 }
00277 verbose = cmdparams_get_int (&cmdparams, "v", NULL);
00278 restartflg = cmdparams_get_int (&cmdparams, "r", NULL);
00279 return (0);
00280 }
00281
00282 TIME SDO_to_DRMS_time(int sdo_s, int sdo_ss)
00283 {
00284 static int firstcall = 1;
00285 if (firstcall)
00286 {
00287 firstcall = 0;
00288 }
00289
00290 return(sdo_epoch + (TIME)sdo_s + (TIME)(sdo_ss)/65536.0);
00291 }
00292
00293
00294 char *do_datestr() {
00295 time_t tval;
00296 struct tm *t_ptr;
00297
00298 tval = time(NULL);
00299 t_ptr = localtime(&tval);
00300 sprintf(datestr, "%d.%02d.%02d_%02d:%02d:%02d",
00301 (t_ptr->tm_year+1900), (t_ptr->tm_mon+1),
00302 t_ptr->tm_mday, t_ptr->tm_hour, t_ptr->tm_min, t_ptr->tm_sec);
00303 return(datestr);
00304 }
00305
00306
00307 char *gettimetag()
00308 {
00309 struct timeval tvalr;
00310 struct tm *t_ptr;
00311
00312 gettimeofday(&tvalr, NULL);
00313 t_ptr = localtime((const time_t *)&tvalr);
00314 sprintf(timetag, "%04d.%02d.%02d.%02d%02d%02d",
00315 (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);
00316 return(timetag);
00317 }
00318
00319
00320 void BeginTimer(int n)
00321 {
00322 gettimeofday (&first[n], NULL);
00323 }
00324
00325 float EndTimer(int n)
00326 {
00327 gettimeofday (&second[n], NULL);
00328 if (first[n].tv_usec > second[n].tv_usec) {
00329 second[n].tv_usec += 1000000;
00330 second[n].tv_sec--;
00331 }
00332 return (float) (second[n].tv_sec-first[n].tv_sec) +
00333 (float) (second[n].tv_usec-first[n].tv_usec)/1000000.0;
00334 }
00335
00336
00337 int h1log(const char *fmt, ...)
00338 {
00339 va_list args;
00340 char string[32768];
00341
00342 va_start(args, fmt);
00343 vsprintf(string, fmt, args);
00344 if(h1logfp) {
00345 fprintf(h1logfp, string);
00346 fflush(h1logfp);
00347 }
00348 else {
00349 printf(string);
00350 fflush(stdout);
00351 }
00352 va_end(args);
00353 return(0);
00354 }
00355
00356 int send_mail(char *fmt, ...)
00357 {
00358 va_list args;
00359 char string[1024], cmd[1024];
00360
00361 va_start(args, fmt);
00362 vsprintf(string, fmt, args);
00363 sprintf(cmd, "echo \"%s\" | Mail -s \"build_lev1 mail\" lev0_user", string);
00364 system(cmd);
00365 va_end(args);
00366 return(0);
00367 }
00368
00369
00370 void abortit(int stat)
00371 {
00372 printk("***Abort in progress ...\n");
00373 printk("**Exit build_lev1 w/ status = %d\n", stat);
00374 if (h1logfp) fclose(h1logfp);
00375 exit(stat);
00376 }
00377
00379 int rdout_mode_correct()
00380 {
00381 return(0);
00382 }
00383
00385 int orbit_calc()
00386 {
00387 return(0);
00388 }
00389
00390
00391 #include "do_flat.c"
00392 #include "get_image_location.c"
00393 #include "limb_fit_function.c"
00394 #include "cosmic_ray.c"
00395
00396
00397 int do_ingest(long long bbrec, long long eerec, const char *dpath)
00398 {
00399
00400 Image_Location *p_imageloc;
00401 Image_Location imageloc[NUMRECLEV1];
00402 TIME t_obs0;
00403 TIME tobs[NUMRECLEV1];
00404 float percentd;
00405 double rsun_lf, x0_lf, y0_lf;
00406 int rstatus, dstatus, ncnt, fcnt, i, j, qualint, nobs;
00407 int hshiexp, hcamid, nbad, n_cosmic;
00408 uint32_t missvals, totvals;
00409 long long recnum0, recnum1, recnumff;
00410 char recrange[128], lev0name[128], flatrec[128];
00411
00412
00413 if(modeflg) sprintf(recrange, ":#%lld-#%lld", bbrec, eerec);
00414 else sprintf(recrange, "%lld-%lld", bbrec, eerec);
00415 sprintf(open_dsname, "%s[%s]", dsin, recrange);
00416 printk("open_dsname = %s\n", open_dsname);
00417 printk("#levnum recnum fsn\n");
00418
00419 rset0 = drms_open_records(drms_env, open_dsname, &rstatus);
00420 if(!rset0 || (rset0->n == 0) || rstatus) {
00421 printk("Can't do drms_open_records(%s)\n", open_dsname);
00422 return(1);
00423 }
00424 ncnt = rset0->n;
00425 rptr = (DRMS_Record_t *)malloc(ncnt * sizeof(DRMS_Record_t));
00426 if(rptr == NULL) {
00427 printk("Can't malloc() for DRMS_Record_t sort\n");
00428 return(1);
00429 }
00430
00431 for(i=0; i < ncnt; i++) {
00432 memcpy(&rptr[i], rset0->records[i], sizeof(DRMS_Record_t));
00433 }
00434
00435 qsort(rptr, ncnt, sizeof(DRMS_Record_t), &compare_rptr);
00436
00437
00438
00439 for(i=0; i < ncnt; i++) {
00440 flatmiss[i] = 0;
00441 orbmiss[i] = 0;
00442 asdmiss[i] = 0;
00443 mpdmiss[i] = 0;
00444 noimage[i] = 0;
00445 missflg[i] = 0;
00446 rs0 = &rptr[i];
00447 recnum0 = rs0->recnum;
00448
00449 fsnx = drms_getkey_int(rs0, "FSN", &rstatus);
00450 fsnarray[i] = fsnx;
00451 printk("*0 %u %u\n", recnum0, fsnx);
00452
00453 tobs[i] = drms_getkey_time(rs0, "t_obs", &rstatus);
00454 if(rstatus) {
00455 printk("Error on drms_getkey_time() fsn=%u. Use DRMS_MISSING_TIME\n",
00456 fsnx);
00457 tobs[i] = DRMS_MISSING_TIME;
00458 }
00459 }
00460 if(rstatus = get_pointing_info(drms_env, tobs, ncnt, &ptinfo)) {
00461 printk("**ERROR: get_pointing_info() status = %d fsn tobs ASD:\n",
00462 rstatus);
00463 for(j=0; j < ncnt; j++) {
00464 printk("%u %10.5f ", fsnarray[j], tobs[j]);
00465 ptdata = ptinfo[j];
00466 printk("%s\n", ptdata.asd_rec);
00467 asdmiss[j] = 1;
00468 }
00469
00470 }
00471 if ((IOstatus = iorbit_getinfo(drms_env,
00472 orbseries,
00473 NULL,
00474 IORBIT_Alg_Quadratic,
00475 tobs,
00476 ncnt,
00477 kIORBIT_CacheAction_DontCache,
00478 &IOinfo)) != kLIBASTRO_Success)
00479 {
00480 if(IOstatus == kLIBASTRO_InsufficientData) {
00481 printk("***ERROR in iorbit_getinfo: kLIBASTRO_InsufficientData\n");
00482 }
00483 else {
00484 printk("***ERROR in iorbit_getinfo() status=%d\n", IOstatus);
00485 }
00486 for(j=0; j < ncnt; j++) {
00487 orbmiss[j] = 1;
00488 }
00489
00490 }
00491 rset1 = drms_create_records(drms_env, ncnt, dsout, DRMS_PERMANENT,&dstatus);
00492 if(dstatus) {
00493 printk("**ERROR: Can't create records for %s\n", dsout);
00494 for(j=0; j < ncnt; j++) {
00495 noimage[j] = 1;
00496 }
00497
00498 }
00499
00500 for(i=0; i < ncnt; i++) {
00501 rs0 = &rptr[i];
00502 imageloc[i].tobs = tobs[i];
00503 imageloc[i].camera = drms_getkey_int(rs0, "CAMERA", &rstatus);
00504 if(rstatus) {
00505 printk("ERROR: in drms_getkey_int(CAMERA) fsn=%u\n", fsnarray[i]);
00506 }
00507 imageloc[i].wavelength = drms_getkey_int(rs0, "WAVELNTH", &rstatus);
00508 if(rstatus) {
00509 printk("ERROR: in drms_getkey_int(WAVELNTH) fsn=%u\n", fsnarray[i]);
00510 }
00511 snprintf(imageloc[i].telescope, 10, "%s",
00512 drms_getkey_string(rs0, "TELESCOP", &rstatus));
00513 if(rstatus) {
00514 printk("ERROR: in drms_getkey_string(TELESCOP) fsn=%u\n", fsnarray[i]);
00515 }
00516 }
00517 p_imageloc = imageloc;
00518 rstatus = get_image_location(drms_env, ncnt, &p_imageloc);
00519 if(rstatus) {
00520 printk("ERROR: get_image_location() returns status=%d\n", rstatus);
00521 for(j=0; j < ncnt; j++) {
00522 mpdmiss[i] = 0;
00523 }
00524
00525 }
00526
00527 for(i=0; i < ncnt; i++) {
00528 rs0 = &rptr[i];
00529 recnum0 = rs0->recnum;
00530 fsnx = fsnarray[i];
00531 sprintf(lev0name, "%s[%u]", dsin, fsnx);
00532 if(drms_getkey_int(rs0, "QUALITY", 0) < 0) {
00533 printk("Bad QUALITY for %s, no lev1 made\n", lev0name);
00534 noimage[i] = 1;
00535 continue;
00536 }
00537 segment = drms_segment_lookupnum(rs0, 0);
00538 Array0 = drms_segment_read(segment, DRMS_TYPE_SHORT, &rstatus);
00539 if(!Array0) {
00540 printk("Can't do drms_segment_read() %s status=%d\n",
00541 lev0name, rstatus);
00542 noimage[i] = 1;
00543
00544 continue;
00545 }
00546 l0l1->adata0 = (short *)Array0->data;
00547 l0l1->rs0 = rs0;
00548 l0l1->recnum0 = recnum0;
00549 l0l1->fsn = fsnx;
00550 if(hmiaiaflg) {
00551 l0l1->dat1.adata1A = &data1A;
00552
00553 l0l1->himgcfid = 90;
00554 }
00555 else {
00556 l0l1->dat1.adata1 = &data1;
00557 l0l1->himgcfid = drms_getkey_int(rs0, "HIMGCFID", &rstatus);
00558 }
00559 if(rstatus) {
00560 printk("Can't do drms_getkey_int(HIMGCFID) for fsn %u\n", fsnx);
00562 l0l1->himgcfid = 104;
00563
00564
00565 }
00566
00567 sprintf(open_dsname, "%s[%u]", dsout, fsnx);
00568 rs = rset1->records[i];
00569 drms_record_directory(rs, rs1_path, 0);
00570 if(!*rs1_path) {
00571 printk("***ERROR: No path to segment for %s\n", open_dsname);
00572 noimage[i] = 1;
00573 continue;
00574 }
00575
00576 dstatus = drms_setkey_int(rs, "FSN", fsnx);
00577 dstatus = drms_setkey_string(rs, "LEV0SERIES", lev0name);
00578 if(!(segment = drms_segment_lookup(rs, "image_lev1"))) {
00579 printk("No drms_segment_lookup(rs, image_lev1) for %s\n", open_dsname);
00580 noimage[i] = 1;
00581 continue;
00582 }
00583 if(hmiaiaflg) {
00584 segArray = drms_array_create(DRMS_TYPE_INT,
00585 segment->info->naxis,
00586 segment->axis,
00587 &data1A,
00588 &dstatus);
00589 }
00590 else {
00591 segArray = drms_array_create(DRMS_TYPE_FLOAT,
00592 segment->info->naxis,
00593 segment->axis,
00594 &data1,
00595 &dstatus);
00596 }
00597
00598 rstatus = drms_copykeys(rs, rs0, 0, kDRMS_KeyClass_Explicit);
00599 if(rstatus != DRMS_SUCCESS) {
00600 printk("Error %d in drms_copykeys() for fsn %u\n", fsnx);
00601
00602 continue;
00603 }
00604 qualint = drms_getkey_int(rs0, "QUALITY", &rstatus);
00605 drms_setkey_int(rs, "QUALLEV0", qualint);
00606
00607 drms_setkey_time(rs, "T_OBS", tobs[i]);
00608 printk("t_obs for lev0 = %10.5f\n", tobs[i]);
00609 drms_setkey_double(rs, "DATE", CURRENT_SYSTEM_TIME);
00610 if(ptinfo) {
00611 ptdata = ptinfo[i];
00612 drms_setkey_float(rs, "SAT_Y0", ptdata.sat_y0);
00613 drms_setkey_float(rs, "SAT_Z0", ptdata.sat_z0);
00614 drms_setkey_float(rs, "SAT_ROT", ptdata.sat_rot);
00615 drms_setkey_string(rs, "ACS_MODE", ptdata.acs_mode);
00616 drms_setkey_string(rs, "ACS_ECLP", ptdata.acs_eclp);
00617 drms_setkey_string(rs, "ACS_SUNP", ptdata.acs_sunp);
00618 drms_setkey_string(rs, "ACS_SAFE", ptdata.acs_safe);
00619 drms_setkey_string(rs, "ASD_REC", ptdata.asd_rec);
00620 drms_setkey_string(rs, "ACS_CGT", ptdata.acs_cgt);
00621 }
00622 if(IOinfo) {
00623 IOdata = IOinfo[i];
00624 drms_setkey_double(rs, "HCIEC_X", IOdata.hciX);
00625 drms_setkey_double(rs, "HCIEC_Y", IOdata.hciY);
00626 drms_setkey_double(rs, "HCIEC_Z", IOdata.hciZ);
00627 drms_setkey_double(rs, "GCIEC_X", IOdata.gciX);
00628 drms_setkey_double(rs, "GCIEC_Y", IOdata.gciY);
00629 drms_setkey_double(rs, "GCIEC_Z", IOdata.gciZ);
00630
00631 drms_setkey_double(rs, "DSUN_OBS", IOdata.dsun_obs);
00632 drms_setkey_double(rs, "OBS_VR", IOdata.obs_vr);
00633 drms_setkey_double(rs, "OBS_VW", IOdata.obs_vw);
00634 drms_setkey_double(rs, "OBS_VN", IOdata.obs_vn);
00635 drms_setkey_double(rs, "RSUN_OBS", IOdata.rsun_obs);
00636 drms_setkey_float(rs, "CRLN_OBS", (float)IOdata.crln_obs);
00637 drms_setkey_float(rs, "CRLT_OBS", (float)IOdata.crlt_obs);
00638 drms_setkey_int(rs, "CAR_ROT", (int)IOdata.car_rot);
00639 drms_setkey_string(rs, "ORB_REC", IOdata.orb_rec);
00640 }
00641 drms_setkey_float(rs, "X0_MP", imageloc[i].x);
00642 drms_setkey_float(rs, "Y0_MP", imageloc[i].y);
00643 drms_setkey_float(rs, "INST_ROT", imageloc[i].instrot);
00644
00645 drms_setkey_float(rs, "IMSCL_MP", imageloc[i].imscale);
00646 drms_setkey_string(rs, "MPO_REC", imageloc[i].mpo_rec);
00647
00648 int camera = drms_getkey_int(rs0, "CAMERA", &rstatus);
00649 if(rstatus) {
00650 printk("Can't do drms_getkey_int() for fsn %u\n", fsnx);
00651 noimage[i] = 1;
00652 goto TEMPSKIP;
00653
00654 }
00655
00656 if(drms_ismissing_time(tobs[i])) {
00657 printk("DRMS_MISSING_TIME for fsn=%u. Continue...\n", fsnx);
00658 noimage[i] = 1;
00659 goto TEMPSKIP;
00660 }
00661 if(!hmiaiaflg) {
00662 if(quicklook) {
00663 sprintf(open_dsname, "%s[? t_start=(select max(t_start) from %s where t_start <= %10.5f and t_stop > %10.5f and CAMERA=%d) and CAMERA=%d ?]",
00664 dsffname, dsffname, tobs[i], tobs[i], camera, camera);
00665 }
00666 else {
00667 sprintf(open_dsname, "%s[? t_start <= %10.5f and t_stop > %10.5f and CAMERA=%d and flatfield_version=(select max(flatfield_version) from %s where t_start <= %10.5f and t_stop > %10.5f and CAMERA=%d) ?]",
00668 dsffname, tobs[i], tobs[i], camera, dsffname, tobs[i], tobs[i], camera);
00669 }
00670 }
00671 else {
00672 char *wavstr = drms_getkey_string(rs0, "WAVE_STR", &rstatus);
00673 if(rstatus) {
00674 printk("Can't do drms_getkey_string() for WAVE_STR\n");
00675 return(1);
00676 }
00677 if(quicklook) {
00678 sprintf(open_dsname, "%s[? t_start=(select max(t_start) from %s where t_start <= %10.5f and t_stop > %10.5f and WAVE_STR='%s') and WAVE_STR='%s' ?]",
00679 dsffname, dsffname, tobs[i], tobs[i], wavstr, wavstr);
00680 }
00681 else {
00682 sprintf(open_dsname, "%s[? t_start <= %10.5f and t_stop > %10.5f and WAVE_STR=%s and flatfield_version=(select max(flatfield_version) from %s where t_start <= %10.5f and t_stop > %10.5f and WAVE_STR='%s') ?]",
00683 dsffname, tobs[i], tobs[i], wavstr, dsffname, tobs[i], tobs[i], wavstr);
00684 }
00685 }
00686
00687 rsetff = drms_open_records(drms_env, open_dsname, &rstatus);
00688 if(!rsetff || (rsetff->n == 0) || rstatus) {
00689 printk("Can't do drms_open_records(%s)\n", open_dsname);
00690 flatmiss[i] = 1; noimage[i] = 1;
00691 goto TEMPSKIP;
00692
00693 }
00694 fcnt = rsetff->n;
00695 if(fcnt > 1) {
00696 printk("More than one FF found for %s?\n", open_dsname);
00697 printk("Use last one of %d found\n", fcnt);
00698
00699 }
00700
00701 rsff = rsetff->records[fcnt-1];
00702 recnumff = rsff->recnum;
00703 sprintf(flatrec, "%s[:#%lld]", dsffname, recnumff);
00704 if(dstatus = drms_setkey_string(rs, "FLAT_REC", flatrec )) {
00705 printk("**ERROR on drms_setkey_string() for %s\n", flatrec);
00706 }
00707 drms_record_directory(rsff, path, 1);
00708 if(!*path) {
00709 printk("***ERROR: No path to segment for %s\n", open_dsname);
00710
00711 return(1);
00712 }
00713
00714 segmentff = drms_segment_lookup(rsff, "flatfield");
00715 Arrayff = drms_segment_read(segmentff, DRMS_TYPE_FLOAT, &rstatus);
00716 if(!Arrayff) {
00717 printk("Can't do drms_segment_read() for Flat Field status=%d\n",
00718 rstatus);
00719 return(1);
00720 }
00721 l0l1->adataff = (float *)Arrayff->data;
00722
00723 darkseg = drms_segment_lookup(rsff, "DARK");
00724 ArrayDark = drms_segment_read(darkseg, DRMS_TYPE_FLOAT, &rstatus);
00725 if(!ArrayDark) {
00726 printk("Can't do drms_segment_read() for DARK. status=%d\n", rstatus);
00727 return(1);
00728 }
00729 l0l1->adatadark = (float *)ArrayDark->data;
00730
00731 badseg = drms_segment_lookup(rsff, "BAD_PIXEL");
00732 ArrayBad = drms_segment_read(badseg, DRMS_TYPE_INT, &rstatus);
00733 nbad = drms_array_size(ArrayBad)/sizeof(int);
00734 if(!ArrayBad) {
00735 printk("Can't do drms_DARKsegment_read() for BAD_PIXEL. status=%d\n",
00736 rstatus);
00737 return(1);
00738 }
00739 l0l1->adatabad = (int *)ArrayBad->data;
00741
00742
00743
00744
00745 if(!hmiaiaflg) {
00746 if(!(badoutpixseg = drms_segment_lookup(rs, "bad_pixel_list"))) {
00747 printk("No drms_segment_lookup(rs, bad_pixel_list) for lev1\n");
00748 return(1);
00749 }
00750 }
00751 else {
00752 if(!(badoutpixseg = drms_segment_lookup(rs, "bad_pixel"))) {
00753 printk("No drms_segment_lookup(rs, bad_pixel) for lev1\n");
00754 return(1);
00755 }
00756 }
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766 l0l1->rs1 = rs;
00767 l0l1->rsff = rsff;
00768 l0l1->recnum1 = rs->recnum;
00769 l0l1->darkflag = 0;
00770 hshiexp = drms_getkey_int(rs, "HSHIEXP", &rstatus);
00771 hcamid = drms_getkey_int(rs, "HCAMID", &rstatus);
00772 if(hmiaiaflg) {
00773 int aimgshce = drms_getkey_int(rs, "AIMGSHCE", &rstatus);
00774 if(aimgshce == 0) l0l1->darkflag = 1;
00775 if(rstatus = do_flat_aia(l0l1)) {
00776 printk("***ERROR in do_flat() status=%d\n", rstatus);
00777 printf("***ERROR in do_flat() status=%d\n", rstatus);
00778 flatmiss[i] = 1; noimage[i] = 1;
00779
00780 goto FLATERR;
00781 }
00782 }
00783 else {
00784 if(hshiexp == 0) l0l1->darkflag = 1;
00785 if(rstatus = do_flat(l0l1)) {
00786 printk("***ERROR in do_flat() status=%d\n", rstatus);
00787 printf("***ERROR in do_flat() status=%d\n", rstatus);
00788 flatmiss[i] = 1; noimage[i] = 1;
00789
00790 goto FLATERR;
00791 }
00792 }
00793
00794
00795
00796
00797
00798 drms_setkey_float(rs, "OSCNMEAN", l0l1->oscnmean);
00799 drms_setkey_float(rs, "OSCNRMS", l0l1->oscnrms);
00800 drms_setkey_int(rs, "DATAMIN", l0l1->datamin);
00801 drms_setkey_int(rs, "DATAMAX", l0l1->datamax);
00802 drms_setkey_int(rs, "DATAMEDN", l0l1->datamedn);
00803 drms_setkey_float(rs, "DATAMEAN", l0l1->datamean);
00804 drms_setkey_float(rs, "DATARMS", l0l1->data_rms);
00805 drms_setkey_float(rs, "DATASKEW", l0l1->dataskew);
00806 drms_setkey_float(rs, "DATAKURT", l0l1->datakurt);
00807 drms_setkey_int(rs, "DATAVALS", l0l1->datavals);
00808 drms_setkey_int(rs, "MISSVALS", l0l1->missvals);
00809 missvals = (uint32_t)l0l1->missvals;
00810 totvals = (uint32_t)l0l1->datavals + missvals;
00811 drms_setkey_int(rs, "TOTVALS", (int)totvals);
00812 percentd = (float)((100.0 * (float)l0l1->datavals)/(float)totvals);
00813 drms_setkey_float(rs, "PERCENTD", percentd);
00814 if(missvals > 0) missflg[i] = missflg[i] | Q_1_MISS0;
00815 if(missvals > (uint32_t)(totvals * 0.01))
00816 missflg[i] = missflg[i] | Q_1_MISS1;
00817 if(missvals > (uint32_t)(totvals * 0.05))
00818 missflg[i] = missflg[i] | Q_1_MISS2;
00819 if(missvals > (uint32_t)(totvals * 0.25))
00820 missflg[i] = missflg[i] | Q_1_MISS3;
00821 if(l0l1->datavals == 0)
00822 missflg[i] = missflg[i] | Q_MISSALL;
00823 if(hmiaiaflg) {
00824
00825 if (spikeseg = drms_segment_lookup(rs,"spikes") ) {
00826 int *spikedata, status, axes[2], nbytes;
00827 nbytes = nspikes*sizeof(int);
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838 axes[0] = nspikes;
00839 axes[1] = 3;
00840 spikedata = (int *) malloc (3*nspikes*sizeof(int));
00841 ArraySpike = drms_array_create(DRMS_TYPE_INT, 2, axes,
00842 (void *) spikedata, &status);
00843 memcpy((void *)spikedata, (void *)spikelocs, nbytes);
00844 memcpy((void *)(spikedata+nspikes), (void *)oldvalues, nbytes);
00845 memcpy((void *)(spikedata+2*nspikes), (void *)newvalues, nbytes);
00846 status = drms_segment_write(spikeseg, ArraySpike, 0);
00847 drms_free_array(ArraySpike);
00848 } else { printf("spikes segment not found\n"); }
00849 }
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865 dstatus = drms_segment_write(badoutpixseg, ArrayBad, 0);
00866 if (dstatus) {
00867 printk("ERROR: drms_segment_write error=%d for lev1 bad_pixel_list\n",
00868 dstatus);
00869 noimage[i] = 1;
00870 }
00871 FLATERR:
00872 drms_close_records(rsetff, DRMS_FREE_RECORD);
00873 free(ArrayDark->data);
00874 free(Arrayff->data);
00875 free(ArrayBad->data);
00876
00877 TEMPSKIP:
00878 if(!hmiaiaflg) {
00879 segArray->type = DRMS_TYPE_FLOAT;
00880 segArray->bscale = 1.0;
00881 segArray->bzero = 0.0;
00882 }
00883 dstatus = drms_segment_write(segment, segArray, 0);
00884 if (dstatus) {
00885 printk("ERROR: drms_segment_write error=%d for fsn=%u\n", dstatus,fsnx);
00886 noimage[i] = 1;
00887 }
00888 recnum1 = rs->recnum;
00889 printk("*1 %u %u\n", recnum1, fsnx);
00890 free(Array0->data);
00891
00892 x0_lf = DRMS_MISSING_DOUBLE;
00893 y0_lf = DRMS_MISSING_DOUBLE;
00894 rsun_lf = DRMS_MISSING_DOUBLE;
00895
00896
00897
00898 int skiplimb = 0;
00899 int hcftid = drms_getkey_int(rs, "HCFTID", &rstatus);
00900 if(hcftid == CAL_HCFTID) {
00901 printk("Cal mode image fsn=%u\n", fsnx);
00902 skiplimb = 1;
00903 }
00904 else {
00905 if(hshiexp == 0) {
00906 if(hcamid == 0 || hcamid == 1) {
00907 printk("Dark image fsn=%u\n", fsnx);
00908 skiplimb = 1;
00909 }
00910 }
00911 }
00912 if(!skiplimb && !hmiaiaflg) {
00913
00914 dstatus = limb_fit(rs,l0l1->dat1.adata1,&rsun_lf,&x0_lf,&y0_lf,4096,4096,0, dpath);
00915 if(dstatus) {
00916 printk("ERROR: limb_fit() %d error for fsn=%u\n", dstatus, fsnx);
00917 noimage[i] = 1;
00918 }
00919 else {
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929 }
00930 }
00931 drms_setkey_float(rs, "RSUN_LF", (float)rsun_lf);
00932 drms_setkey_float(rs, "X0_LF", (float)x0_lf);
00933 drms_setkey_float(rs, "Y0_LF", (float)y0_lf);
00934 if(drms_ismissing_double(rsun_lf)) {
00935 drms_setkey_float(rs, "CDELT1", imageloc[i].imscale);
00936 drms_setkey_float(rs, "CDELT2", imageloc[i].imscale);
00937 drms_setkey_float(rs, "R_SUN",(float)IOdata.rsun_obs/imageloc[i].imscale);
00938 }
00939 else {
00940 drms_setkey_float(rs, "CDELT1", (float)IOdata.rsun_obs/rsun_lf);
00941 drms_setkey_float(rs, "CDELT2", (float)IOdata.rsun_obs/rsun_lf);
00942 drms_setkey_float(rs, "R_SUN", (float)rsun_lf);
00943 }
00944 if(!drms_ismissing_double(x0_lf) && !drms_ismissing_double(y0_lf)) {
00945 drms_setkey_float(rs, "CRPIX1", (float)x0_lf + 1);
00946 drms_setkey_float(rs, "CRPIX2", (float)y0_lf + 1);
00947 }
00948 else {
00949
00950
00952 drms_setkey_float(rs, "CRPIX1", imageloc[i].x + 1);
00953 drms_setkey_float(rs, "CRPIX2", imageloc[i].y + 1);
00954 }
00955 drms_setkey_float(rs, "CROTA2", imageloc[i].instrot + ptdata.sat_rot);
00956
00957
00958 if(hmiaiaflg) {
00959 int wl = drms_getkey_int(rs, "WAVELNTH", &rstatus);
00960 drms_setkey_float(rs, "CDELT1", 0.609);
00961 drms_setkey_float(rs, "CDELT2", 0.609);
00962 switch (wl) {
00963 case 94:
00964 drms_setkey_float(rs, "CRPIX1", 2048.5);
00965 drms_setkey_float(rs, "CRPIX2", 2048.5);
00966 break;
00967 case 131:
00968 drms_setkey_float(rs, "CRPIX1", 2048.5);
00969 drms_setkey_float(rs, "CRPIX2", 2048.5);
00970 break;
00971 case 171:
00972 drms_setkey_float(rs, "CRPIX1", 2048.5);
00973 drms_setkey_float(rs, "CRPIX2", 2048.5);
00974 break;
00975 case 193:
00976 drms_setkey_float(rs, "CRPIX1", 2048.5);
00977 drms_setkey_float(rs, "CRPIX2", 2048.5);
00978 break;
00979 case 211:
00980 drms_setkey_float(rs, "CRPIX1", 2048.5);
00981 drms_setkey_float(rs, "CRPIX2", 2048.5);
00982 break;
00983 case 304:
00984 drms_setkey_float(rs, "CRPIX1", 2048.5);
00985 drms_setkey_float(rs, "CRPIX2", 2048.5);
00986 break;
00987 case 335:
00988 drms_setkey_float(rs, "CRPIX1", 2048.5);
00989 drms_setkey_float(rs, "CRPIX2", 2048.5);
00990 break;
00991 case 1600:
00992 drms_setkey_float(rs, "CRPIX1", 2048.5);
00993 drms_setkey_float(rs, "CRPIX2", 2048.5);
00994 break;
00995 case 1700:
00996 drms_setkey_float(rs, "CRPIX1", 2048.5);
00997 drms_setkey_float(rs, "CRPIX2", 2048.5);
00998 break;
00999 case 4500:
01000 drms_setkey_float(rs, "CRPIX1", 2048.5);
01001 drms_setkey_float(rs, "CRPIX2", 2048.5);
01002 break;
01003 }
01004 drms_setkey_float(rs, "CRVAL1", 0.0);
01005 drms_setkey_float(rs, "CRVAL2", 0.0);
01006 }
01007
01008 do_quallev1(rs0, rs, i, fsnx);
01009
01010 }
01011
01012 drms_close_records(rset0, DRMS_FREE_RECORD);
01013 drms_close_records(rset1, DRMS_INSERT_RECORD);
01014 return(0);
01015 }
01016
01017 int compare_rptr(const void *a, const void *b)
01018 {
01019 TIME t1, t2;
01020 int rstatus;
01021 DRMS_Record_t *x=(DRMS_Record_t *)a, *y=(DRMS_Record_t *)b;
01022
01023 t1 = drms_getkey_time(x, "t_obs", &rstatus);
01024 if(rstatus) t1 = DRMS_MISSING_TIME;
01025 t2 = drms_getkey_time(y, "t_obs", &rstatus);
01026 if(rstatus) t2 = DRMS_MISSING_TIME;
01027 if(t1 < t2) return(-1);
01028 if(t1 > t2) return(1);
01029 return(0);
01030 }
01031
01032
01033 void setup()
01034 {
01035 FILE *fin;
01036 char string[128], cwdbuf[128], idstr[256], lfile[128];
01037 int tpid;
01038
01039 sdo_epoch = sscan_time("1958.01.01_00:00:00_TAI");
01040 do_datestr();
01041 printk_set(h1log, h1log);
01042 printk("%s\n", datestr);
01043 getcwd(cwdbuf, 126);
01044 sprintf(idstr, "Cwd: %s\nCall: ", cwdbuf);
01046 sprintf(string, "build_lev1Y started as pid=%d ppid=%d user=%s\n",
01047 getpid(), getppid(), username);
01048 strcat(idstr, string);
01049 printk("%s", idstr);
01050 printf("%s", idstr);
01051 if(restartflg) printk("-r ");
01052 sprintf(argmode, "mode=%s", mode);
01053 sprintf(arginstru, "instru=%s", instru);
01054 sprintf(argdsin, "dsin=%s", dsin);
01055 sprintf(argdsout, "dsout=%s", dsout);
01056 if(modeflg) {
01057 sprintf(argbx, "brec=%lld", brec);
01058 sprintf(argex, "erec=%lld", erec);
01059 }
01060 else {
01061 sprintf(argbx, "bfsn=%lld", bfsn);
01062 sprintf(argex, "efsn=%lld", efsn);
01063 }
01064 sprintf(argquick, "quicklook=%d", quicklook);
01065 sprintf(arglogfile, "logfile=%s", logname);
01066 printk("%s %s %s %s %s %s %s %s\n",
01067 argmode, arginstru, argdsin, argdsout, argbx, argex, argquick, arglogfile);
01068 printf("%s %s %s %s %s %s %s %s\n",
01069 argmode, arginstru, argdsin, argdsout, argbx, argex, argquick, arglogfile);
01070 if(!restartflg) {
01071
01072
01073 }
01074 sprintf(bld_vers, "%s", jsoc_version);
01075 sprintf(idstr, "ps -ef | grep %s", LEV1VIEWERNAME);
01076 fin = popen(idstr, "r");
01077 while(fgets(string, sizeof string, fin)) {
01078 if(!(strstr(string, "perl"))) continue;
01079 sscanf(string, "%s %d", idstr, &tpid);
01080 sprintf(lfile, "%s/build_lev1_restart_%d.touch", LEV1LOG_BASEDIR, tpid);
01081 sprintf(idstr, "/bin/touch %s", lfile);
01082 printk("%s\n", idstr);
01083 system(idstr);
01084 }
01085 umask(002);
01086
01087
01088
01089
01090
01091
01092 }
01093
01094
01095 int DoIt(void)
01096 {
01097 long long numofrecs, frec, lrec;
01098 int numrec, numofchunks, i;
01099 char line[80];
01100 const char *dpath = NULL;
01101
01102 if (nice_intro())
01103 return (0);
01104 if(!(username = (char *)getenv("USER"))) username = "nouser";
01105 instru = cmdparams_get_str(&cmdparams, "instru", NULL);
01106 if(strcmp(instru, "hmi") && strcmp(instru, "aia")) {
01107 printf("Error: instru= must be given as 'hmi' or 'aia'\n");
01108 return(0);
01109 }
01110 mode = cmdparams_get_str(&cmdparams, "mode", NULL);
01111 if(strcmp(mode, "recnum") && strcmp(mode, "fsn")) {
01112 printf("Error: mode= must be given as 'recnum' or 'fsn'\n");
01113 return(0);
01114 }
01115 if(!strcmp(instru, "aia")) hmiaiaflg = 1;
01116 if(!strcmp(mode, "recnum")) modeflg = 1;
01117 dsin = cmdparams_get_str(&cmdparams, "dsin", NULL);
01118 dsout = cmdparams_get_str(&cmdparams, "dsout", NULL);
01119 brec = cmdparams_get_int(&cmdparams, "brec", NULL);
01120 erec = cmdparams_get_int(&cmdparams, "erec", NULL);
01121 bfsn = cmdparams_get_int(&cmdparams, "bfsn", NULL);
01122 efsn = cmdparams_get_int(&cmdparams, "efsn", NULL);
01123 quicklook = cmdparams_get_int(&cmdparams, "quicklook", NULL);
01124
01125 dpath = cmdparams_get_str(&cmdparams, kDpath, NULL);
01126
01127 if(modeflg) {
01128 if(brec == 0 || erec == 0) {
01129 fprintf(stderr, "brec and erec must be given for recnum mode. 0 not allowed\n");
01130 return(0);
01131 }
01132 if(brec > erec) {
01133 fprintf(stderr, "brec must be <= erec\n");
01134 return(0);
01135 }
01136 bnumx = brec;
01137 enumx = erec;
01138 }
01139 else {
01140 if(bfsn == 0 || efsn == 0) {
01141 fprintf(stderr, "bfsn and efsn must be given for fsn mode. 0 not allowed\n");
01142 return(0);
01143 }
01144 if(bfsn > efsn) {
01145 fprintf(stderr, "bfsn must be <= efsn\n");
01146 return(0);
01147 }
01148 bnumx = bfsn;
01149 enumx = efsn;
01150 }
01151 logfile = cmdparams_get_str(&cmdparams, "logfile", NULL);
01152 if (strcmp(dsin, NOTSPECIFIED) == 0) {
01153 if(hmiaiaflg == 0) dsin = LEV0SERIESNAMEHMI;
01154 else dsin = LEV0SERIESNAMEAIA;
01155 }
01156 if (strcmp(dsout, NOTSPECIFIED) == 0) {
01157 if(hmiaiaflg == 0) dsout = LEV1SERIESNAMEHMI;
01158 else dsout = LEV1SERIESNAMEAIA;
01159 }
01160 if(hmiaiaflg) {
01161 sprintf(dsffname, "%s", DSFFNAMEAIA);
01162 if(strstr(dsin, "hmi") || strstr(dsout, "hmi")) {
01163 printf("Warning: You said instru=aia but have 'hmi' in ds name?\n");
01164 printf("Do you want to abort this [y/n]? ");
01165 if(gets(line) == NULL) { return(0); }
01166 if(strcmp(line, "n")) { return(0); }
01167 }
01168 }
01169 else {
01170 sprintf(dsffname, "%s", DSFFNAMEHMI);
01171 if(strstr(dsin, "aia") || strstr(dsout, "aia")) {
01172 printf("Warning: You said instru=hmi but have 'aia' in ds name?\n");
01173 printf("Do you want to abort this [y/n]? ");
01174 if(gets(line) == NULL) { return(0); }
01175 if(strcmp(line, "n")) { return(0); }
01176 }
01177 }
01178 if (strcmp(logfile, NOTSPECIFIED) == 0) {
01179 sprintf(logname, H1LOGFILE, gettimetag());
01180 }
01181 else {
01182 sprintf(logname, "%s", logfile);
01183 }
01184 if(restartflg || LOGTEST) {
01185 if((h1logfp=fopen(logname, "a")) == NULL)
01186 fprintf(stderr, "**Can't open for append the log file %s\n", logname);
01187 }
01188 else {
01189 if((h1logfp=fopen(logname, "w")) == NULL)
01190 fprintf(stderr, "**Can't open the log file %s\n", logname);
01191 }
01192 setup();
01193 numofrecs = (enumx - bnumx) + 1;
01194 numrec = NUMRECLEV1;
01195 numofchunks = numofrecs/numrec;
01196 if((numofrecs % numrec) != 0) numofchunks++;
01197 lrec = bnumx-1;
01198 for(i = 0; i < numofchunks; i++) {
01199 frec = lrec+1; lrec = (frec + numrec)-1;
01200 if(lrec > enumx) lrec=enumx;
01201 if(do_ingest(frec, lrec, dpath)) {
01202 printf("build_lev1 abort\nSee log: %s\n", logname);
01203 send_mail("build_lev1 abort\nSee log: %s\n", logname);
01204 return(0);
01205 }
01206 }
01207 printf("build_lev1 done last fsn=%u\n", fsnx);
01208 return(0);
01209 }
01210