00001
00002
00003
00004
00005
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 #include <stdio.h>
00135 #include <stdlib.h>
00136 #include <string.h>
00137 #include <math.h>
00138 #include <complex.h>
00139 #include <omp.h>
00140
00141 #include "interpol_code.h"
00142 #include "polcal.h"
00143 #include "HMIparam.h"
00144 #include "fstats.h"
00145 #include "drms_defs.h"
00146
00147 #undef I //I is the complex number (0,1) in complex.h. We un-define it to avoid confusion with the loop iterative variable i
00148
00149 char *module_name= "HMI_observables_90q";
00150
00151 #define kRecSetIn "begin" //beginning time for which an output is wanted. MANDATORY PARAMETER.
00152 #define kRecSetIn2 "end" //end time for which an output is wanted. MANDATORY PARAMETER.
00153
00154 #define kTypeSetIn "levin" //data level of the input filtergrams (lev1,lev1d,lev1p) LEV1 BY DEFAULT
00155 #define kTypeSetOut "levout" //data level of the output series (lev1d,lev1p, or lev1.5) LEV1.5 BY DEFAULT
00156 #define WaveLengthIn "wavelength" //filtergram name Ii starting the framelist (i ranges from 0 to 5). MANDATORY PARAMETER.
00157 #define QuickLookIn "quicklook" //quicklook data (yes=1,no=0)? 0 BY DEFAULT
00158 #define CamIDIn "camid" //front camera (camid=1), side camera (camid=0), or both cameras (camid=3)?
00159
00160
00161
00162 #define DataCadenceIn "cadence" //cadence
00163 #define SeriesIn "lev1" //series name for the lev1 filtergrams
00164 #define SmoothTables "smooth" //Use smooth look-up tables for the MDI-like algorithm?
00165 #define RotationalFlat "rotational" //force the use of rotational flat fields?
00166 #define Linearity "linearity" //force the correction for non-linearity of cameras
00167 #define Unusual "unusual" //unusual sequences (more than 6 wavelengths)? yes=1, no=0. Use only when trying to produce side camera observables
00168
00169 #define minval(x,y) (((x) < (y)) ? (x) : (y))
00170 #define maxval(x,y) (((x) < (y)) ? (y) : (x))
00171
00172
00173 #define LIGHT_SIDE 2 //SIDE CAMERA
00174 #define LIGHT_FRONT 3 //FRONT CAMERA
00175 #define DARK_SIDE 0 //SIDE CAMERA
00176 #define DARK_FRONT 1 //FRONT CAMERA
00177
00178 #define Q_ACS_ECLP 0x2000 //eclipse keyword for the lev1 data
00179 #define Q_ACS_ISSLOOP 0x20000 //ISS loop OPEN for lev1
00180 #define Q_ACS_NOLIMB 0x10 //limbfinder error for lev1
00181 #define Q_MISSING_SEGMENT 0x80000000 //missing image segment for lev1 record
00182 #define Q_ACS_LUNARTRANSIT 0x800000 //lunar transit
00183 #define Q_ACS_THERMALRECOVERY 0x400000//thermal recovery after eclipses
00184 #define CALVER_DEFAULT 0 //both default and missing values of CALVER64
00185 #define CALVER_SMOOTH 0x100 //bitmask for CALVER64 to indicate the use of smooth look-up tables
00186
00187 #define CALVER_LINEARITY 0x2000 //bitmask for CALVER64 to indicate the use of non-linearity correction //VALUE USED AFTER JANUARY 15, 2014
00188 #define CALVER_ROTATIONAL 0x10000 //bitmask for CALVER64 to indicate the use of rotational flat fields
00189 #define CALVER_MODL 0x40000 //bitmask for CALVER64 to indicate the use of a mod L observables sequence
00190 #define CALVER_NOMODL 0xFFFFFFFFFFF1FFFF //to reset the mask
00191 #define Q_CAMERA_ANOMALY 0x00000080 //camera issue with HMI (e.g. DATAMIN=0): resulting images might be usable, but most likely bad
00192
00193
00194
00195
00196 #define QUAL_NODATA (0x80000000) //no l.o.s. observables (Dopplergram, magnetogram, etc...) image was produced (record created, but NO DATA SEGMENT. Most keywords have default value)
00197 #define QUAL_TARGETFILTERGRAMMISSING (0x40000000) //no target filtergram was found near target time (the target filtergram is the filtergram used to identify the framelist): could be due to missing filtergrams or because no observable sequence was run at that time
00198 #define QUAL_NOINTERPOLATEDKEYWORDS (0x20000000) //could not interpolate some keywords at target time (CROTA2, DSUN_OBS, and CRLT_OBS are required by do_interpolate()), because some lev 1 records are missing/corrupted
00199 #define QUAL_NOFRAMELISTINFO (0x10000000) //could not figure out which observables framelist was used, or the framelist run for the required time range is not an observables framelist
00200 #define QUAL_WRONGCADENCE (0x8000000) //the cadence corresponding to the framelist run at the required time does not match the expected value provided by user (could be an error from user, or an issue with the framelist)
00201 #define QUAL_WRONGTARGET (0x4000000) //the target filtergram does not belong to the current framelist (there is something wrong either with the framelist or the target filtergram)
00202 #define QUAL_MISSINGLEV1D (0x2000000) //not enough lev1d filtergrams to produce an observable (too many lev 1 records were missing or corrupted)
00203 #define QUAL_MISSINGKEYWORDLEV1D (0x1000000) //could not read some needed keywords (like FID) in the lev1d data (too many lev 1 records were missing or corrupted and the corresponding lev 1d record is unusable)
00204 #define QUAL_WRONGWAVELENGTHNUM (0x800000) //the number of wavelengths in the lev1d records is not correct (issue with the framelist, or too many lev 1 records were missing or corrupted)
00205 #define QUAL_MISSINGKEYWORDLEV1P (0x400000) //could not read some needed keywords in the lev1p data (too many lev 1 records were missing or corrupted and the corresponding lev 1p record is unusable)
00206 #define QUAL_NOLOOKUPRECORD (0x200000) //could not find a record for the look-up tables for the MDI-like algorithm (the MDI-like algorithm cannot be used)
00207 #define QUAL_NOLOOKUPKEYWORD (0x100000) //could not read the keywords of the look-up tables for the MDI-like algorithm (the MDI-like algorithm cannot be used)
00208 #define QUAL_NOTENOUGHINTERPOLANTS (0x80000) //not enough interpolation points for the temporal interpolation at a given wavelength and polarization (too many lev 1 records were missing or corrupted)
00209 #define QUAL_INTERPOLATIONFAILED (0x40000) //the temporal interpolation routine failed (no lev1d record was produced)
00210 #define QUAL_MISSINGLEV1P (0x20000) //not enough lev1p records to produce an observable (too many lev 1 records were missing or corrupted)
00211 #define QUAL_NOCOEFFKEYWORD (0x200) //could not read the keywords of the polynomial coefficient series
00212 #define QUAL_NOCOEFFPRECORD (0x80) //could not find a record for the polynomial coefficient for the correction of the MDI-like algorithm, or could not access the keywords of a specific record
00213
00214
00215 #define QUAL_LOWINTERPNUM (0x10000) //the number of interpolation points (for temporal interpolation) was not always as high as expected, AND/OR 2 interpolation points were separated by more than the cadence
00216 #define QUAL_LOWKEYWORDNUM (0x8000) //some keywords (especially CROTA2, DSUN_OBS, and CRLT_OBS) could not be interpolated properly at target time, but a closest-neighbour approximation or an extrapolation was used
00217 #define QUAL_ISSTARGET (0x4000) //the ISS loop was OPEN for one or several filtergrams used to produce the observable
00218 #define QUAL_NOTEMP (0x2000) //cannot read the temperatures needed for polarization calibration (default temperature used)
00219 #define QUAL_NOGAPFILL (0x1000) //the code could not properly gap-fill all the lev 1 filtergrams
00220 #define QUAL_LIMBFITISSUE (0x800) //some lev1 records were discarded because R_SUN, and/or CRPIX1/CRPIX2 were missing or too different from the median value of the other lev 1 records (too much jitter for instance)
00221 #define QUAL_NOCOSMICRAY (0x400) //some cosmic-ray hit lists could not be read for the level 1 filtergrams
00222 #define QUAL_ECLIPSE (0x100) //at least one lev1 record was taken during an eclipse
00223 #define QUAL_LARGEFTSID (0x40) //HFTSACID of target filtergram > 4000, which adds noise to observables
00224 #define QUAL_POORQUALITY (0x20) //poor quality: careful when using these observables due to eclipse, or lunar transit, or thermal recovery, or open ISS, or other issues...
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 ModuleArgs_t module_args[] =
00237 {
00238 {ARG_STRING, kRecSetIn, "" , "beginning time for which an output is wanted"},
00239 {ARG_STRING, kRecSetIn2, "" , "end time for which an output is wanted"},
00240 {ARG_STRING, kTypeSetIn, "lev1.0", "Level of input series: 1.0,1d,1p"},
00241 {ARG_STRING, kTypeSetOut,"lev1.5", "Level of output series, combination of: 1d,1p,1.5. For example: 1p,1.5"},
00242 {ARG_INT , WaveLengthIn,"3" , "Index (0 to 5) of the wavelength starting the framelist"},
00243 {ARG_INT , QuickLookIn, "0" , "Quicklook data? No=0; Yes=1"},
00244 {ARG_INT , CamIDIn , "1" , "Front (1), side (0), or both (3) cameras?"},
00245 {ARG_DOUBLE, DataCadenceIn,"45.0" ,"Cadence (in seconds)"},
00246 {ARG_STRING, SeriesIn, "hmi.lev1", "Name of the lev1 series"},
00247 {ARG_INT , SmoothTables, "0", "Use smooth look-up tables? yes=1, no=0 (default)"},
00248 {ARG_INT , RotationalFlat, "0", "Use rotational flat fields? yes=1, no=0 (default)"},
00249 {ARG_STRING, "dpath", "/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/", "directory where the source code is located"},
00250 {ARG_INT , Linearity, "0", "Correct for non-linearity of cameras? yes=1, no=0 (default)"},
00251 {ARG_INT , Unusual, "0", "unusual sequences (more than 6 wavelengths)? yes=1, no=0. Use only when trying to produce side camera observables"},
00252 {ARG_END}
00253 };
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264 int needtochangeFID(int HFLID)
00265 {
00266 int need;
00267
00268 switch(HFLID)
00269 {
00270 case 58312: need=1;
00271 break;
00272 case 1022: need=1;
00273 break;
00274
00275 case 2042: need=1;
00276 break;
00277
00278 case 2043: need=1;
00279 break;
00280
00281 case 1002: need=1;
00282 break;
00283
00284 case 3042: need=1;
00285 break;
00286
00287 case 3040: need=1;
00288 break;
00289
00290 case 3041: need=1;
00291 break;
00292
00293 case 3043: need=1;
00294 break;
00295
00296
00297 default: need=0;
00298 }
00299
00300 return need;
00301 }
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 int signj(int v)
00312 {
00313 return v > 0 ? 1 : (v < 0 ? -1 : 0);
00314 }
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328 int WhichWavelength(int FID)
00329 {
00330 int result;
00331 int temp;
00332 if(FID < 100000) temp=(FID/10) % 20;
00333 else
00334 {
00335 temp = ((FID-100000)/10) % 20;
00336 }
00337 switch (temp)
00338 {
00339 case 19: result=9;
00340 break;
00341 case 17: result=7;
00342 break;
00343 case 15: result=0;
00344 break;
00345 case 14: result=0;
00346 break;
00347 case 13: result=1;
00348 break;
00349 case 12: result=1;
00350 break;
00351 case 11: result=2;
00352 break;
00353 case 10: result=2;
00354 break;
00355 case 9: result=3;
00356 break;
00357 case 8: result=3;
00358 break;
00359 case 7: result=4;
00360 break;
00361 case 6: result=4;
00362 break;
00363 case 5: result=5;
00364 break;
00365 case 3: result=6;
00366 break;
00367 case 1: result=8;
00368 break;
00369 default: result=-101;
00370 }
00371
00372 return result;
00373
00374 }
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384 int framelistCombine(int HFLID, int CamIdIn,int *Pcombine, char *dpath)
00385 {
00386 int HFLIDread,FIDread,i,j,compteur;
00387 FILE *sequencefile;
00388
00389 char *filename=NULL;
00390 char *filename2=NULL;
00391 char *filename3=NULL;
00392
00393 char dpath2[256];
00394 strcpy(dpath2,dpath);
00395 filename =strdup(strcat(dpath2,"/../Sequences3.txt"));
00396 strcpy(dpath2,dpath);
00397 filename2=strdup(strcat(dpath2,"/../../tables/hmi_mech/std_flight.w"));
00398 strcpy(dpath2,dpath);
00399 filename3=strdup(strcat(dpath2,"/../../tables/hmi_mech/std_flight.p"));
00400
00401
00402 char line[256];
00403 int found=0;
00404
00405 int combinef,combines,npolf,npols,framelistSizef,framelistSizes,PolarizationTypef,PolarizationTypes,CAMERA;
00406 float DataCadencef,DataCadences;
00407
00408
00409 printf("HFLID OF FRAMELIST = %d\n",HFLID);
00410 sequencefile = fopen(filename,"r");
00411 if(sequencefile == NULL)
00412 {
00413 printf("The file %s does not exist or cannot be read\n",filename);
00414 free(filename);
00415 free(filename2);
00416 free(filename3);
00417 filename=NULL;
00418 filename2=NULL;
00419 filename3=NULL;
00420 return 1;
00421 }
00422
00423 while (fgets(line,256,sequencefile) != NULL)
00424 {
00425 sscanf(line,"%d %d %d %f %f %d %d %d %d %d %d %d %d",&HFLIDread,&PolarizationTypef,&PolarizationTypes,&DataCadencef,&DataCadences,&npolf,&npols,&combinef,&combines,&framelistSizef,&framelistSizes,&j,&CAMERA);
00426 if(HFLIDread == HFLID)
00427 {
00428 if(CamIdIn == LIGHT_FRONT) *Pcombine=combinef;
00429 if(CamIdIn == LIGHT_SIDE) *Pcombine=combines;
00430 found=1;
00431 }
00432 }
00433 fclose(sequencefile);
00434
00435 return found;
00436 }
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465 int framelistInfo(int HFLID,int HPLTID,int HWLTID,int WavelengthID,int *PHWPLPOS,int *WavelengthIndex,int *WavelengthLocation, int *PPolarizationType,int CamIdIn,int *Pcombine,int *Pnpol,int MaxNumFiltergrams,TIME *PDataCadence,int *CameraValues,int *FID,char *dpath)
00466 {
00467 int framelistSize=0,HFLIDread,FIDread,i,j,compteur, ij;
00468 int PLINDEX,WLINDEX;
00469 FILE *sequencefile;
00470
00471
00472
00473
00474
00475
00476
00477 char *filename=NULL;
00478 char *filename2=NULL;
00479 char *filename3=NULL;
00480
00481 char dpath2[256];
00482 strcpy(dpath2,dpath);
00483 filename =strdup(strcat(dpath2,"/../Sequences3.txt"));
00484 strcpy(dpath2,dpath);
00485 filename2=strdup(strcat(dpath2,"/../../tables/hmi_mech/std_flight.w"));
00486 strcpy(dpath2,dpath);
00487 filename3=strdup(strcat(dpath2,"/../../tables/hmi_mech/std_flight.p"));
00488
00489 char line[256];
00490 int PL_Index[MaxNumFiltergrams],WL_Index[MaxNumFiltergrams];
00491 int WT1P,WT2P,WT3P,WT4P,PS1P,PS2P,PS3P;
00492 int found=0;
00493
00494 int combinef,combines,npolf,npols,framelistSizef,framelistSizes,PolarizationTypef,PolarizationTypes,CAMERA;
00495 float DataCadencef,DataCadences;
00496
00497
00498
00499
00500
00501 printf("HFLID OF FRAMELIST = %d\n",HFLID);
00502 sequencefile = fopen(filename,"r");
00503 if(sequencefile == NULL)
00504 {
00505 printf("The file %s does not exist or cannot be read\n",filename);
00506 free(filename);
00507 free(filename2);
00508 free(filename3);
00509 filename=NULL;
00510 filename2=NULL;
00511 filename3=NULL;
00512 return 1;
00513
00514 }
00515
00516 i=0;
00517 compteur=0;
00518 while (fgets(line,256,sequencefile) != NULL)
00519 {
00520 sscanf(line,"%d %d %d %f %f %d %d %d %d %d %d %d %d",&HFLIDread,&PolarizationTypef,&PolarizationTypes,&DataCadencef,&DataCadences,&npolf,&npols,&combinef,&combines,&framelistSizef,&framelistSizes,&j,&CAMERA);
00521 if(HFLIDread == HFLID)
00522 {
00523
00524 if(CamIdIn == LIGHT_FRONT)
00525 {
00526 *Pcombine=combinef;
00527 *Pnpol=npolf;
00528 *PDataCadence=DataCadencef;
00529 *PPolarizationType=PolarizationTypef;
00530 framelistSize=framelistSizef;
00531 if(combinef == 0)
00532 {
00533 if(CAMERA == 3)
00534 {
00535 FID[i]=j;
00536 WavelengthLocation[i]=compteur;
00537 CameraValues[i]=LIGHT_FRONT;
00538 i+=1;
00539 }
00540 }
00541 else
00542 {
00543 FID[i]=j;
00544 WavelengthLocation[i]=compteur;
00545 if(CAMERA == 3) CameraValues[i]=LIGHT_FRONT;
00546 else CameraValues[i]=LIGHT_SIDE;
00547 i+=1;
00548 }
00549 }
00550 if(CamIdIn == LIGHT_SIDE)
00551 {
00552 *Pcombine=combines;
00553 *Pnpol=npols;
00554 *PDataCadence=DataCadences;
00555 *PPolarizationType=PolarizationTypes;
00556 framelistSize=framelistSizes;
00557
00558 ij = needtochangeFID(HFLID);
00559 if(ij == 1 && CAMERA == 3)
00560 {
00561 if( (i%72)/24 == 1)
00562 {
00563 j=j+100000;
00564 printf("in subroutine change i= %d, FID=%d\n", i, j);
00565 }
00566 }
00567
00568
00569
00570 if(combines == 0)
00571 {
00572 if(CAMERA == 2)
00573 {
00574 FID[i]=j;
00575 WavelengthLocation[i]=compteur;
00576 CameraValues[i]=LIGHT_SIDE;
00577 i+=1;
00578 }
00579 }
00580 else
00581 {
00582 FID[i]=j;
00583 WavelengthLocation[i]=compteur;
00584 if(CAMERA == 3) CameraValues[i]=LIGHT_FRONT;
00585 else CameraValues[i]=LIGHT_SIDE;
00586 i+=1;
00587 }
00588
00589 }
00590 found=1;
00591 compteur+=1;
00592 }
00593 }
00594 fclose(sequencefile);
00595
00596
00597
00598
00599 int baseindexW,baseindexP;
00600
00601 if((framelistSize == 12) || (framelistSize == 24) || (framelistSize == 36) || (framelistSize == 48) || (framelistSize == 16) || (framelistSize == 32) || (framelistSize == 20) || (framelistSize == 40))
00602 {
00603 switch(WavelengthID)
00604 {
00605 case 9: baseindexW=HWLTID-19;
00606 break;
00607 case 7: baseindexW=HWLTID-17;
00608 break;
00609 case 0: baseindexW=HWLTID-15;
00610 break;
00611 case 1: baseindexW=HWLTID-13;
00612 break;
00613 case 2: baseindexW=HWLTID-11;
00614 break;
00615 case 3: baseindexW=HWLTID-9;
00616 break;
00617 case 4: baseindexW=HWLTID-7;
00618 break;
00619 case 5: baseindexW=HWLTID-5;
00620 break;
00621 case 6: baseindexW=HWLTID-3;
00622 break;
00623 case 8: baseindexW=HWLTID-1;
00624 break;
00625 }
00626 }
00627 if( (framelistSize == 10) )
00628 {
00629 switch(WavelengthID)
00630 {
00631 case 0: baseindexW=HWLTID-14;
00632 break;
00633 case 1: baseindexW=HWLTID-12;
00634 break;
00635 case 2: baseindexW=HWLTID-10;
00636 break;
00637 case 3: baseindexW=HWLTID-8;
00638 break;
00639 case 4: baseindexW=HWLTID-6;
00640 break;
00641 }
00642 }
00643
00644 baseindexP=(HPLTID/10)*10;
00645
00646
00647 for(i=0;i<framelistSize;++i)
00648 {
00649 WLINDEX=(FID[i]/10) % 20;
00650 WL_Index[i]=WLINDEX+baseindexW;
00651 PLINDEX=FID[i]%10;
00652 PL_Index[i]=PLINDEX+baseindexP;
00653 switch(WLINDEX)
00654 {
00655 case 19: WavelengthIndex[i]=9;
00656 break;
00657 case 17: WavelengthIndex[i]=7;
00658 break;
00659 case 15: WavelengthIndex[i]=0;
00660 break;
00661 case 14: WavelengthIndex[i]=0;
00662 break;
00663 case 13: WavelengthIndex[i]=1;
00664 break;
00665 case 12: WavelengthIndex[i]=1;
00666 break;
00667 case 11: WavelengthIndex[i]=2;
00668 break;
00669 case 10: WavelengthIndex[i]=2;
00670 break;
00671 case 9: WavelengthIndex[i]=3;
00672 break;
00673 case 8: WavelengthIndex[i]=3;
00674 break;
00675 case 7: WavelengthIndex[i]=4;
00676 break;
00677 case 6: WavelengthIndex[i]=4;
00678 break;
00679 case 5: WavelengthIndex[i]=5;
00680 break;
00681 case 3: WavelengthIndex[i]=6;
00682 break;
00683 case 1: WavelengthIndex[i]=8;
00684 break;
00685 default: WavelengthIndex[i]=-101;
00686 }
00687 if(WavelengthIndex[i] == -101)
00688 {
00689 printf("Error: WavelengthIndex[i]=-1 \n");
00690 free(filename);
00691 free(filename2);
00692 free(filename3);
00693 filename=NULL;
00694 filename2=NULL;
00695 filename3=NULL;
00696 return 1;
00697
00698 }
00699 }
00700
00701
00702
00703
00704 sequencefile = fopen(filename2,"r");
00705 if(sequencefile == NULL)
00706 {
00707 printf("The file %s does not exist or cannot be read\n",filename2);
00708 free(filename);
00709 free(filename2);
00710 free(filename3);
00711 filename=NULL;
00712 filename2=NULL;
00713 filename3=NULL;
00714 return 1;
00715
00716 }
00717
00718 for(j=0;j<6;++j) fgets(line,256,sequencefile);
00719 while (fgets(line,256,sequencefile) != NULL)
00720 {
00721 if(line[0] != '#')
00722 {
00723 sscanf(line,"%d %d %d %d %d",&j,&WT1P,&WT2P,&WT3P,&WT4P);
00724 for(i=0;i<framelistSize;++i)
00725 {
00726 if(j == WL_Index[i])
00727 {
00728 PHWPLPOS[i*7 ]=WT1P;
00729 PHWPLPOS[i*7+1]=WT2P;
00730 PHWPLPOS[i*7+2]=WT3P;
00731 PHWPLPOS[i*7+3]=WT4P;
00732 }
00733 }
00734 }
00735 }
00736 fclose(sequencefile);
00737
00738 sequencefile = fopen(filename3,"r");
00739 if(sequencefile == NULL)
00740 {
00741 printf("The file %s does not exist or cannot be read\n",filename3);
00742 free(filename);
00743 free(filename2);
00744 free(filename3);
00745 filename=NULL;
00746 filename2=NULL;
00747 filename3=NULL;
00748 return 1;
00749
00750 }
00751
00752 for(j=0;j<6;++j) fgets(line,256,sequencefile);
00753 while (fgets(line,256,sequencefile) != NULL)
00754 {
00755 if(line[0] != '#')
00756 {
00757 sscanf(line,"%d %d %d %d",&j,&PS1P,&PS2P,&PS3P);
00758 for(i=0;i<framelistSize;++i)
00759 {
00760 if(j == PL_Index[i])
00761 {
00762 PHWPLPOS[i*7+4]=PS1P;
00763 PHWPLPOS[i*7+5]=PS2P;
00764 PHWPLPOS[i*7+6]=PS3P;
00765 }
00766 }
00767 }
00768 }
00769 fclose(sequencefile);
00770
00771
00772 if(found == 0)
00773 {
00774 framelistSize=0;
00775 }
00776
00777 free(filename);
00778 free(filename2);
00779 free(filename3);
00780 filename=NULL;
00781 filename2=NULL;
00782 filename3=NULL;
00783 return framelistSize;
00784 }
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795 int StringLocate(const char *s1,const char *s2)
00796 {
00797 int i=0,result=0;
00798 char *ptr;
00799 char temp[2]="a\0";
00800
00801 while(s2[i] != '\0')
00802 {
00803 temp[0]=s2[i];
00804 ptr = strpbrk(s1,temp);
00805 if(ptr == NULL) result=1;
00806 ++i;
00807 }
00808
00809 return result;
00810 }
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824 int MaskCreation(unsigned char *Mask, int nx, int ny, DRMS_Array_t *BadPixels, int HIMGCFID, float *image, DRMS_Array_t *CosmicRays, int nbadperm)
00825 {
00826
00827 int status=2;
00828
00829 if(nx != 4096 || ny != 4096) return status;
00830
00831 char *filename="/home/production/img_cnfg_ids";
00832 const int minid=80;
00833 const int maxid=124;
00834 const int n_tables=1;
00835 const int maxtab=256;
00836
00837 int *badpixellist=BadPixels->data;
00838 int nBadPixels=BadPixels->axis[0];
00839 int *cosmicraylist=NULL;
00840 int ncosmic=0;
00841
00842 if(CosmicRays != NULL)
00843 {
00844 cosmicraylist=CosmicRays->data;
00845 ncosmic=CosmicRays->axis[0];
00846 }
00847 else ncosmic = -1;
00848
00849 int x_orig,y_orig,x_dir,y_dir;
00850 int skip, take, skip_x, skip_y;
00851 int datum, nsx, nss, nlin,nq,nqq,nsy;
00852 int idn=-1;
00853
00854 int *id=NULL, *tab=NULL, *nrows=NULL, *ncols=NULL, *rowstr=NULL, *colstr=NULL, *config=NULL;
00855 id =(int *)(malloc(maxtab*sizeof(int)));
00856 if(id == NULL)
00857 {
00858 printf("Error: memory could not be allocated to id\n");
00859 return 1;
00860
00861 }
00862 tab =(int *)(malloc(maxtab*sizeof(int)));
00863 if(tab == NULL)
00864 {
00865 printf("Error: memory could not be allocated to tab\n");
00866 return 1;
00867
00868 }
00869 nrows =(int *)(malloc(maxtab*sizeof(int)));
00870 if(nrows == NULL)
00871 {
00872 printf("Error: memory could not be allocated to nrows\n");
00873 return 1;
00874
00875 }
00876 ncols =(int *)(malloc(maxtab*sizeof(int)));
00877 if(ncols == NULL)
00878 {
00879 printf("Error: memory could not be allocated to ncols\n");
00880 return 1;
00881
00882 }
00883 rowstr=(int *)(malloc(maxtab*sizeof(int)));
00884 if(rowstr == NULL)
00885 {
00886 printf("Error: memory could not be allocated to rowstr\n");
00887 return 1;
00888
00889 }
00890 colstr=(int *)(malloc(maxtab*sizeof(int)));
00891 if(colstr == NULL)
00892 {
00893 printf("Error: memory could not be allocated to colstr\n");
00894 return 1;
00895
00896 }
00897 config=(int *)(malloc(maxtab*sizeof(int)));
00898 if(config == NULL)
00899 {
00900 printf("Error: memory could not be allocated to config\n");
00901 return 1;
00902
00903 }
00904
00905
00906 int skipt[4*2048];
00907 int taket[4*2048];
00908
00909 int **kx=NULL;
00910 int *kkx=NULL;
00911
00912 kx=(int **)(malloc(9*sizeof(int *)));
00913 if(kx == NULL)
00914 {
00915 printf("Error: memory could not be allocated to kx\n");
00916 return 1;
00917
00918 }
00919
00920
00921 int kx0[11]={4,0,0,1,0,1,1,0,1,1,1};
00922 kx[0]=kx0;
00923 int kx1[7]={2,1,0,1,1,1,2};
00924 kx[2]=kx1;
00925 int kx2[7]={2,0,1,0,0,1,2} ;
00926 kx[4]=kx2;
00927 int kx3[7]={2,0,0,1,0,2,1};
00928 kx[1]=kx3;
00929 int kx4[7]={2,1,1,0,1,2,1};
00930 kx[3]=kx4;
00931 int kx5[7]={1,0,0,2,2};
00932 kx[5]=kx5;
00933 int kx6[5]={1,1,0,2,2};
00934 kx[6]=kx6;
00935 int kx7[5]={1,1,1,2,2};
00936 kx[7]=kx7;
00937 int kx8[5]={1,0,1,2,2};
00938 kx[8]=kx8;
00939
00940 char **filename_table=NULL;
00941 filename_table=(char **)(malloc(n_tables*sizeof(char *)));
00942 if(filename_table == NULL)
00943 {
00944 printf("Error: memory could not be allocated to filename_table\n");
00945 return 1;
00946
00947 }
00948
00949 char *filename_croptable="/home/cvsuser/cvsroot/EGSE/tables/crop/crop6";
00950 filename_table[0]=filename_croptable;
00951
00952 int i,j,k;
00953 int ix, jx;
00954 int n_config;
00955 char string[256];
00956 char strng[5];
00957
00958
00959 FILE *config_file=NULL;
00960 FILE *crop_table=NULL;
00961
00962
00963 config_file=fopen(filename, "r");
00964
00965 if (config_file != NULL){
00966 fgets(string, 256, config_file);
00967 fgets(string, 256, config_file);
00968 fgets(string, 256, config_file);
00969
00970
00971 n_config=0;
00972 fscanf(config_file, "%d", &datum);
00973 id[n_config]=datum;
00974
00975
00976 do {
00977
00978 fscanf(config_file, "%s", string);
00979
00980 config[n_config]=0;
00981 if (string[0] == '4')config[n_config]=0;
00982 if (string[0] == '2') if (string[7] == 'E')config[n_config]=1;
00983 if (string[0] == '2') if (string[7] == 'F')config[n_config]=2;
00984 if (string[0] == '2') if (string[7] == 'G')config[n_config]=3;
00985 if (string[0] == '2') if (string[7] == 'H')config[n_config]=4;
00986 if (string[0] == '1') if (string[7] == 'E')config[n_config]=5;
00987 if (string[0] == '1') if (string[7] == 'F')config[n_config]=6;
00988 if (string[0] == '1') if (string[7] == 'G')config[n_config]=7;
00989 if (string[0] == '1') if (string[7] == 'H')config[n_config]=8;
00990
00991
00992 fscanf(config_file, "%s", string);
00993
00994 fscanf(config_file, "%s", string);
00995
00996 fscanf(config_file, "%s", string);
00997
00998 if (string[0] == 'N') tab[n_config]=-1;
00999 if (string[0] == 'c') tab[n_config]=0;
01000
01001 fscanf(config_file, "%s", string);
01002
01003 fscanf(config_file, "%d", &datum);
01004
01005 fscanf(config_file, "%d", &datum);
01006
01007 fscanf(config_file, "%s", string);
01008
01009 fscanf(config_file, "%d", &datum);
01010 nrows[n_config]=datum;
01011
01012 fscanf(config_file, "%d", &datum);
01013 ncols[n_config]=datum;
01014
01015 fscanf(config_file, "%d", &datum);
01016 rowstr[n_config]=datum;
01017
01018 fscanf(config_file, "%d", &datum);
01019 colstr[n_config]=datum;
01020
01021 fscanf(config_file, "%d", &datum);
01022
01023 fscanf(config_file, "%d", &datum);
01024
01025
01026
01027 ++n_config;
01028 fscanf(config_file, "%d", &datum);
01029 id[n_config]=datum;
01030
01031
01032
01033
01034 }
01035 while (!feof(config_file) && n_config < maxtab);
01036
01037 fclose(config_file);
01038 }
01039
01040
01041
01042
01043 for (i=0; i<n_config; ++i) if (id[i] == HIMGCFID) idn=i;
01044
01045 skip_x=ncols[idn]/2;
01046 skip_y=nrows[idn]/2;
01047
01048
01049
01050 kkx=kx[config[idn]];
01051 nq=kkx[0];
01052 nlin=kkx[2*nq+3-2]*ny/2;
01053 nss=kkx[2*nq+3-1]*nx/2;
01054
01055
01056
01057 if (idn == -1)
01058 {printf("Error: invalid HIMGCFID\n"); status=2;}
01059 else
01060 {
01061 if (tab[idn] != -1)
01062 {
01063 filename_croptable=filename_table[tab[idn]];
01064 crop_table=fopen(filename_croptable, "r");
01065
01066
01067 fscanf(crop_table, "%d", &datum);
01068
01069 fscanf(crop_table, "%d", &datum);
01070 fscanf(crop_table, "%d", &nqq);
01071
01072 for (j=0; j<nqq; ++j)
01073 {
01074 fscanf(crop_table, "%d", &skip);
01075 fscanf(crop_table, "%d", &take);
01076 skipt[j]=skip;
01077 taket[j]=take;
01078 }
01079 fclose(crop_table);
01080 }
01081 else
01082 {
01083 printf("no crop table\n");
01084
01085 for (k=0; k<nq; ++k)
01086 for (j=0; j<nlin; ++j)
01087 {
01088 skipt[k*nss+j]=0;
01089 taket[k*nss+j]=nss;
01090 }
01091 }
01092
01093 nsx=nss-skip_x;
01094 nsy=nlin-skip_y;
01095
01096
01097
01098 for (k=0; k<nq; ++k)
01099 {
01100 x_orig=kkx[k*2+1]*nx - kkx[k*2+1];
01101 y_orig=kkx[k*2+2]*ny - kkx[k*2+2];
01102 x_dir=-(kkx[k*2+1])*2+1;
01103 y_dir=-(kkx[k*2+2])*2+1;
01104
01105
01106 for (j=0; j<skip_y; ++j) for (i=0; i<nss; ++i) Mask[(y_orig+y_dir*j)*nx+x_orig+x_dir*i]=2;
01107 for (j=0; j<nlin; ++j) for (i=0; i<skip_x; ++i) Mask[(y_orig+y_dir*j)*nx+x_orig+x_dir*i]=2;
01108
01109
01110 for (j=0; j<nsy; ++j)
01111 {
01112 jx=j+skip_y;
01113
01114 for (i=0; i<minval(skipt[k*nss+j],nss); ++i){ix=i+skip_x; Mask[(y_orig+y_dir*jx)*nx+x_orig+x_dir*ix]=2;}
01115 for (i=skipt[k*nss+j]; i<minval(skipt[k*nss+j]+taket[k*nss+j],nss); ++i){ix=i+skip_x; Mask[(y_orig+y_dir*jx)*nx+x_orig+x_dir*ix]=0;}
01116 for (i=(skipt[k*nss+j]+taket[k*nss+j]); i<nss; ++i){ix=i+skip_x; Mask[(y_orig+y_dir*jx)*nx+x_orig+x_dir*ix]=2;}
01117 }
01118 }
01119
01120
01121 for(k=0;k<nx*ny;++k)
01122 {
01123 if(Mask[k] == 0)
01124 {
01125 if(isnan(image[k])) Mask[k] = 1;
01126 }
01127 }
01128
01129
01130 if(ncosmic != -1 && nbadperm != -1) nBadPixels = nbadperm;
01131 if(nBadPixels > 0)
01132 {
01133 for (k=0;k<nBadPixels;++k)
01134 {
01135 if(Mask[badpixellist[k]] == 0) Mask[badpixellist[k]] = 1;
01136 }
01137 }
01138
01139
01140
01141 if(ncosmic > 0)
01142 {
01143 for (k=0;k<ncosmic;++k)
01144 {
01145 if(Mask[cosmicraylist[k]] == 0) Mask[cosmicraylist[k]] = 1;
01146 }
01147 }
01148
01149 status=0;
01150
01151 }
01152
01153 free(id);
01154 free(nrows);
01155 free(ncols);
01156 free(rowstr);
01157 free(colstr);
01158 free(config);
01159 free(kx);
01160 free(filename_table);
01161 id=NULL;
01162 nrows=NULL;
01163 ncols=NULL;
01164 rowstr=NULL;
01165 colstr=NULL;
01166 config=NULL;
01167 kx=NULL;
01168 filename_table=NULL;
01169
01170 return status;
01171 }
01172
01173
01174
01175
01176 int heightformation(int FID, double OBSVR, float *CDELT1, float *RSUN, float *CRPIX1, float *CRPIX2, float CROTA2)
01177 {
01178 int wl=0;
01179 int status=0;
01180 float correction=0.0,correction2=0.0;
01181
01182 wl = (FID/10)%20;
01183
01184 if( (wl >= 0) && (wl < 20) )
01185 {
01186 correction = 0.445*exp(-(wl-10.-(float)OBSVR/(0.690/6173.*3.e8/20.)-0.25)*(wl-10.-(float)OBSVR/(0.690/6173.*3.e8/20.)-0.25)/7.1);
01187 correction2 = 0.39*(-2.0*(wl-10.- (float)OBSVR/(0.690/6173.*3.e8/20.)-0.35)/6.15)*exp(-(wl-10.-(float)OBSVR/(0.690/6173.*3.e8/20.)-0.35)*(wl-10.-(float)OBSVR/(0.690/6173.*3.e8/20.)-0.35)/6.15);
01188
01189 *CDELT1 = *CDELT1*(*RSUN)/((*RSUN)-correction);
01190 *RSUN = *RSUN-correction;
01191 *CRPIX1 = *CRPIX1-cos(M_PI-CROTA2*M_PI/180.)*correction2;
01192 *CRPIX2 = *CRPIX2-sin(M_PI-CROTA2*M_PI/180.)*correction2;
01193 }
01194 else status=1;
01195
01196 return status;
01197
01198 }
01199
01200
01201
01202
01203 char *observables_version()
01204 {
01205 return strdup("$Id: HMI_observables_90q.c,v 1.2 2018/02/05 23:05:55 yliu Exp $");
01206 }
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223 int DoIt(void)
01224 {
01225 #define MaxNString 512 //maximum length of strings in character number
01226 double tstart=dsecnd();
01227
01228
01229
01230
01231 char *inRecQuery = (char *)cmdparams_get_str(&cmdparams, kRecSetIn, NULL);
01232 char *inRecQuery2 = (char *)cmdparams_get_str(&cmdparams, kRecSetIn2, NULL);
01233 char *inLev = (char *)cmdparams_get_str(&cmdparams, kTypeSetIn, NULL);
01234 char *outLev = (char *)cmdparams_get_str(&cmdparams, kTypeSetOut, NULL);
01235 int WavelengthID = cmdparams_get_int(&cmdparams,WaveLengthIn , NULL);
01236 int QuickLook = cmdparams_get_int(&cmdparams,QuickLookIn, NULL);
01237 int CamId = cmdparams_get_int(&cmdparams,CamIDIn, NULL);
01238 TIME DataCadence = cmdparams_get_double(&cmdparams,DataCadenceIn,NULL);
01239 char *inLev1Series = (char *)cmdparams_get_str(&cmdparams,SeriesIn, NULL);
01240 int inSmoothTables = cmdparams_get_int(&cmdparams,SmoothTables, NULL);
01241 int inRotationalFlat = cmdparams_get_int(&cmdparams,RotationalFlat, NULL);
01242 char *dpath = (char *)cmdparams_get_str(&cmdparams,"dpath", NULL);
01243 int inLinearity = cmdparams_get_int(&cmdparams,Linearity, NULL);
01244 int unusual = cmdparams_get_int(&cmdparams,Unusual, NULL);
01245
01246
01247 char *CODEVERSION =NULL;
01248 CODEVERSION=observables_version();
01249 char *CODEVERSION1=NULL;
01250 CODEVERSION1=interpol_version();
01251 char *CODEVERSION2=NULL;
01252 CODEVERSION2=interpol_version();
01253 char *CODEVERSION3=NULL;
01254 CODEVERSION3=polcal_version();
01255
01256
01257 char *DISTCOEFPATH=NULL;
01258 char *ROTCOEFPATH =NULL;
01259
01260 char HISTORY[MaxNString];
01261
01262 char COMMENT[MaxNString];
01263 strcpy(COMMENT,"De-rotation: ON; Un-distortion: ON; Re-centering: ON; Re-sizing: OFF; correction for cosmic-ray hits; correction front/side intensity implemented for mod L; RSUNerr=5.0 pixels; dpath=");
01264 strcat(COMMENT,dpath);
01265 if(inLinearity == 1) strcat(COMMENT,"; linearity=1 with coefficients updated on 2014/01/15");
01266 if(inRotationalFlat == 1) strcat(COMMENT,"; rotational=1");
01267 if(inSmoothTables == 1) strcat(COMMENT,"; smooth=1");
01268 strcat(COMMENT,"; propagate eclipse bit from level 1; use of larger crop radius look-up tables");
01269
01270 struct init_files initfiles;
01271
01272
01273
01274
01275
01276 char *DISTCOEFFILEF=NULL;
01277 char *DISTCOEFFILES=NULL;
01278 char *ROTCOEFFILE=NULL;
01279
01280 char dpath2[MaxNString];
01281 strcpy(dpath2,dpath);
01282 DISTCOEFFILEF=strdup(strcat(dpath2,"/../libs/lev15/distmodel_front_o6_100624.txt"));
01283 strcpy(dpath2,dpath);
01284 DISTCOEFFILES=strdup(strcat(dpath2,"/../libs/lev15/distmodel_side_o6_100624.txt"));
01285 strcpy(dpath2,dpath);
01286 ROTCOEFFILE =strdup(strcat(dpath2,"/../libs/lev15/rotcoef_file.txt"));
01287 strcpy(dpath2,dpath);
01288 DISTCOEFPATH =strdup(strcat(dpath2,"/../libs/lev15/"));
01289 strcpy(dpath2,dpath);
01290 ROTCOEFPATH =strdup(strcat(dpath2,"/../libs/lev15/"));
01291
01292
01293
01294
01295
01296 initfiles.dist_file_front=DISTCOEFFILEF;
01297 initfiles.dist_file_side =DISTCOEFFILES;
01298 initfiles.diffrot_coef =ROTCOEFFILE;
01299
01300 int CamId0=CamId;
01301 if(CamId == 0)
01302 {CamId = LIGHT_SIDE;}
01303 else
01304 {if(CamId == 1)
01305 {CamId = LIGHT_FRONT;}
01306 else if(CamId == 3) CamId = LIGHT_SIDE;
01307 }
01308
01309 if(QuickLook != 0 && QuickLook != 1)
01310 {
01311 printf("The parameter quicklook must be either 0 or 1\n");
01312 return 1;
01313
01314 }
01315
01316 printf("COMMAND LINE PARAMETERS:\n inRecquery = %s \n inRecquery2 = %s \ninLev = %s \n outLev = %s \n WavelengthID = %d \n QuickLook = %d \n CamId = %d \n DataCadence = %f \n smooth= %d \n rotational = %d \n dpath = %s linearity = %d\n",inRecQuery,inRecQuery2,inLev,outLev,WavelengthID,QuickLook,CamId,DataCadence,inSmoothTables,inRotationalFlat,dpath,inLinearity);
01317
01318
01319
01320
01321 int NumWavelengths=10;
01322 int MaxNumFiltergrams=72;
01323 int TempIntNum;
01324 int nRecmax = 23040;
01325 char HMISeriesLev1[MaxNString];
01326 char HMISeriesLev10[MaxNString];
01327 char HMISeriesLev1d[MaxNString];
01328 char HMISeriesLev1pa[MaxNString];
01329 char HMISeriesLev1pb[MaxNString];
01330 char HMISeriesLev15a[MaxNString];
01331 char HMISeriesLev15b[MaxNString];
01332 char HMISeriesLev15c[MaxNString];
01333 char HMISeriesLev15d[MaxNString];
01334 char HMISeriesLev15e[MaxNString];
01335 char HMISeriesLookup[MaxNString];
01336 if(inSmoothTables == 1) strcpy(HMISeriesLookup,"hmi.lookup_corrected_expanded"); else strcpy(HMISeriesLookup,"hmi.lookup_expanded");
01337
01338 printf("Series used for the look-up tables: %s\n",HMISeriesLookup);
01339
01340 char CosmicRaySeries[MaxNString]= "hmi.cosmic_rays";
01341 char HMISeriesTemperature[MaxNString]= "hmi.temperature_summary_300s";
01342 char HMISeriesCoeffs[MaxNString]= "hmi.coefficients";
01343 char HMIRotationalFlats[MaxNString]= "hmi.flatfield_update";
01344
01345 if(QuickLook == 0) TempIntNum=6; else TempIntNum=2;
01346
01347
01348
01349
01350 TIME CadenceRead;
01351 TIME TimeCaution = DataCadence;
01352 TIME MaxSearchDistanceL,MaxSearchDistanceR;
01353 TIME TREC_EPOCH = sscan_time("1993.01.01_00:00:00_TAI");
01354 TIME TREC_STEP = 0.;
01355 TIME TREC_EPOCH0= sscan_time("1993.01.01_00:00:00_TAI");
01356 TIME temptime=0.0, temptime2=0.0;
01357 TIME TimeBegin,TimeEnd,TimeBegin2,TimeEnd2,TargetTime,PreviousTargetTime;
01358 TIME *internTOBS=NULL;
01359 TIME trec;
01360 TIME tobs;
01361 TIME *timeL;
01362
01363 char HMISeries[MaxNString];
01364 char HMILookup[MaxNString];
01365 char HMICoeffs[MaxNString];
01366 char HMISeriesTemp[MaxNString];
01367 char DATEOBS[MaxNString];
01368 char AcceptedLev[16][4] = {"0","d","p","5","dp","pd","d5","5d","dp5","d5p","pd5","p5d","5dp","5pd","p5","5p"};
01369 char timeBegin[MaxNString] ="2000.12.25_00:00:00";
01370 char timeEnd[MaxNString] ="2000.12.25_00:00:00";
01371 char timeBegin2[MaxNString]="2000.12.25_00:00:00";
01372 char timeEnd2[MaxNString] ="2000.12.25_00:00:00";
01373 char **IMGTYPE=NULL;
01374 char CamIds[]="000";
01375 char FSNtemps[]="00000000000000";
01376 char jsocverss[MaxNString];
01377 char **HWLTNSET=NULL;
01378 char TargetISS[]="CLOSED";
01379 char source[64000];
01380 char recnums[MaxNString];
01381 char HMIFlatField0[MaxNString];
01382 char *HMIFlatField;
01383
01384 int *keyL=NULL;
01385 int TestLevIn[3], TestLevOut[15];
01386 int i,temp,temp2,TotalIn,TotalOut,observables,k,ii,iii,j;
01387 int status = DRMS_SUCCESS, status2 = DRMS_SUCCESS, statusA[51], TotalStatus, CreateEmptyRecord=0;
01388 int PolarizationType=-1;
01389 int nRecs1,nRecs1d,nRecs1p,nRecs15;
01390 int ActualTempIntNum;
01391 int framelistSize=0;
01392 int *HWL1POS=NULL;
01393 int *HWL2POS=NULL;
01394 int *HWL3POS=NULL;
01395 int *HWL4POS=NULL;
01396 int *HPL1POS=NULL;
01397 int *HPL2POS=NULL;
01398 int *HPL3POS=NULL;
01399 int *FID=NULL;
01400 int *HFLID=NULL;
01401 int *CFINDEX=NULL;
01402 int *FSN=NULL;
01403 int *HWLTID=NULL;
01404 int *HPLTID=NULL;
01405 int *HIMGCFID=NULL;
01406 int *KeywordMissing=NULL;
01407 int *SegmentRead=NULL;
01408
01409
01410
01411 int *HCAMID=NULL;
01412 int TargetWavelength=0;
01413 int *IndexFiltergram=NULL;
01414 int nIndexFiltergram;
01415 int TargetHFLID=0;
01416 int TargetHWLPOS[4];
01417 int TargetHPLPOS[3];
01418 int TargetHPLTID;
01419 int TargetHWLTID;
01420 int TargetCFINDEX;
01421 int TargetFID;
01422 int *CARROT=NULL;
01423 int *NBADPERM=NULL;
01424 int axisin[2] ;
01425 int axisout[2];
01426 int Nelem=0;
01427 int PHWPLPOS[MaxNumFiltergrams*7];
01428 int WavelengthIndex[MaxNumFiltergrams], WavelengthLocation[MaxNumFiltergrams], *OrganizeFramelist=NULL, *OrganizeFramelist2=NULL, *FramelistArray=NULL, *SegmentStatus=NULL;
01429 int FIDValues[MaxNumFiltergrams];
01430 int CameraValues[MaxNumFiltergrams];
01431 int FiltergramLocation, Needed;
01432 int Lev1pWanted=0;
01433 int Lev1dWanted=0;
01434 int Lev15Wanted=0;
01435 int Segments1d=0;
01436 int Segments1p=0;
01437 int *ps1=NULL,*ps2=NULL,*ps3=NULL,*fid=NULL,*Wavelengths=NULL;
01438 int method=1;
01439 int npol;
01440 int npolout;
01441 int nSegs1p;
01442 int Lev1pOffset;
01443 int combine;
01444 int combineornot, combineYesNo;
01445 int ThresholdPol;
01446 int nthreads;
01447 int CARROTint;
01448 int camera,fidfilt;
01449 int ngood;
01450 int MISSVALS[5];
01451 int SATVALS=0;
01452 int WavelengthID2;
01453 int QUALITY=0;
01454 int QUALITYLEV1=0;
01455 int wl=0;
01456 int row,column;
01457 int *FSNL=NULL;
01458 int *QUALITYin=NULL;
01459 int *QUALITYlev1=NULL;
01460 int COSMICCOUNT=0;
01461 int initialrun=0;
01462 int totalTempIntNum;
01463 int *CAMERA=NULL;
01464
01465 long long *CALVER32=NULL;
01466 long long CALVER64=-11;
01467
01468 DRMS_RecordSet_t *recLev1 = NULL;
01469 DRMS_RecordSet_t *recLev1d = NULL;
01470 DRMS_RecordSet_t *recLev1p = NULL;
01471 DRMS_RecordSet_t *recLev15a= NULL;
01472 DRMS_RecordSet_t *recLev15b= NULL;
01473 DRMS_RecordSet_t *recLev15c= NULL;
01474 DRMS_RecordSet_t *recLev15d= NULL;
01475 DRMS_RecordSet_t *recLev15e= NULL;
01476 DRMS_RecordSet_t *lookup = NULL;
01477 DRMS_RecordSet_t *rectemp = NULL;
01478 DRMS_RecordSet_t *recpoly = NULL;
01479 DRMS_RecordSet_t *recpoly2 = NULL;
01480 DRMS_RecordSet_t *recflat = NULL;
01481 DRMS_RecordSet_t *recflatrot= NULL;
01482
01483 DRMS_Array_t *arrayL0=NULL;
01484 DRMS_Array_t *arrayL1=NULL;
01485 DRMS_Array_t *arrayL2=NULL;
01486 DRMS_Array_t *rotationalflats=NULL;
01487
01488 double diftime=0.0;
01489 double coeff[4],coeff2[4];
01490 double *count=NULL;
01491
01492 float *RSUN=NULL;
01493 float *CROTA2=NULL;
01494 float *CRLTOBS=NULL;
01495 float *X0=NULL;
01496 float *Y0=NULL;
01497 float *CDELT1=NULL;
01498 double *DSUNOBS=NULL;
01499 float *image =NULL;
01500 float *image0=NULL,*image1=NULL,*image2=NULL,*image3=NULL,*image4=NULL;
01501 float **images =NULL;
01502 float **imagesout=NULL;
01503 double *OBSVR=NULL;
01504 double *OBSVW=NULL;
01505 double *OBSVN=NULL;
01506 float *CRLNOBS=NULL;
01507
01508 float TSEL;
01509 float TFRONT;
01510 float X0AVG,Y0AVG,RSUNAVG;
01511 float X0RMS,Y0RMS,RSUNRMS;
01512 float X0AVGF,Y0AVGF,RSUNAVGF,X0AVGS,Y0AVGS,RSUNAVGS;
01513 float CRLNOBSint,CRLTOBSint,CROTA2int,RSUNint,ctime1,ctime2;
01514 double OBSVRint,OBSVWint,OBSVNint,DSUNOBSint;
01515 float cdelt1;
01516 float *X0ARR=NULL, *Y0ARR=NULL, *RSUNARR=NULL;
01517 float RSUNerr=5.0;
01518 float correction,correction2;
01519 float *temparr1=NULL,*temparr2=NULL,*temparr3=NULL,*temparr4=NULL,*LCP=NULL,*RCP=NULL;
01520 float distance;
01521 float obsvr;
01522 float X0LF=0.0,Y0LF=0.0;
01523 float *pztflat;
01524 float *rotflat;
01525 float *EXPTIME=NULL;
01526 float tempvalue=0.0;
01527 float *DATAMEAN=NULL;
01528
01529
01530 char *FSNS = "FSN";
01531 char *TOBSS = "T_OBS";
01532 char *HWL1POSS = "HWL1POS";
01533 char *HWL2POSS = "HWL2POS";
01534 char *HWL3POSS = "HWL3POS";
01535 char *HWL4POSS = "HWL4POS";
01536 char *HPL1POSS = "HPL1POS";
01537 char *HPL2POSS = "HPL2POS";
01538 char *HPL3POSS = "HPL3POS";
01539 char *FIDS = "FID";
01540 char *HFLIDS = "HFLID";
01541 char *HIMGCFIDS = "HIMGCFID";
01542 char *IMGTYPES = "IMG_TYPE";
01543 char *RSUNS = "R_SUN";
01544 char *CROTA2S = "CROTA2";
01545 char *CRLTOBSS = "CRLT_OBS";
01546 char *DSUNOBSS = "DSUN_OBS";
01547 char *CRPIX1S = "CRPIX1";
01548 char *CRPIX2S = "CRPIX2";
01549 char *X0LFS = "X0_LF";
01550 char *Y0LFS = "Y0_LF";
01551 char *HCAMIDS = "HCAMID";
01552 char *HCFTIDS = "HCFTID";
01553 char *CDELT1S = "CDELT1";
01554 char *CDELT2S = "CDELT2";
01555 char *CSYSER1S = "CSYSER1";
01556 char *CSYSER2S = "CSYSER2";
01557 char *WCSNAMES = "WCSNAME";
01558 char *OBSVRS = "OBS_VR";
01559 char *OBSVWS = "OBS_VW";
01560 char *OBSVNS = "OBS_VN";
01561 char *CRLNOBSS = "CRLN_OBS";
01562 char *CARROTS = "CAR_ROT";
01563
01564 char *TS08 = "T08_PSASM_MEAN";
01565 char *TS01 = "T01_FWMR1_MEAN";
01566 char *TS02 = "T02_FWMR2_MEAN";
01567 char *RSUNOBSS = "RSUN_OBS";
01568 char *HWLTIDS = "HWLTID";
01569 char *HPLTIDS = "HPLTID";
01570 char *WavelengthIDS = "WAVELNID";
01571 char *HWLTNSETS = "HWLTNSET";
01572 char *NBADPERMS = "NBADPERM";
01573 char *COEFF0S = "COEFF0";
01574 char *COEFF1S = "COEFF1";
01575 char *COEFF2S = "COEFF2";
01576 char *COEFF3S = "COEFF3";
01577 char *COUNTS = "COUNT";
01578 char *FLATREC = "FLAT_REC";
01579 char *CALVER32S = "CALVER32";
01580 char *CALVER64S = "CALVER64";
01581
01582
01583 char *TRECS = "T_REC";
01584 char *TRECEPOCHS = "T_REC_epoch";
01585 char *TRECSTEPS = "T_REC_step";
01586 char *CADENCES = "CADENCE";
01587 char *DATES = "DATE";
01588 char *DATEOBSS = "DATE__OBS";
01589 char *INSTRUMES = "INSTRUME";
01590 char *CAMERAS = "CAMERA";
01591 char *QUALITYS = "QUALITY";
01592 char *HISTORYS = "HISTORY";
01593 char *COMMENTS = "COMMENT";
01594 char *BLDVERSS = "BLD_VERS";
01595 char *TOTVALSS = "TOTVALS";
01596 char *DATAVALSS = "DATAVALS";
01597 char *MISSVALSS = "MISSVALS";
01598 char *DATAMINS = "DATAMIN2";
01599 char *DATAMAXS = "DATAMAX2";
01600 char *DATAMEDNS = "DATAMED2";
01601 char *DATAMEANS = "DATAMEA2";
01602 char *DATARMSS = "DATARMS2";
01603 char *DATASKEWS = "DATASKE2";
01604 char *DATAKURTS = "DATAKUR2";
01605 char *DATAMINS2 = "DATAMIN";
01606 char *DATAMAXS2 = "DATAMAX";
01607 char *DATAMEDNS2 = "DATAMEDN";
01608 char *DATAMEANS2 = "DATAMEAN";
01609 char *DATARMSS2 = "DATARMS";
01610 char *DATASKEWS2 = "DATASKEW";
01611 char *DATAKURTS2 = "DATAKURT";
01612 char *QLOOKS = "QLOOK";
01613 char *CALFSNS = "CAL_FSN";
01614 char *LUTQUERYS = "LUTQUERY";
01615 char *TSELS = "TSEL";
01616 char *TFRONTS = "TFRONT";
01617 char *TINTNUMS = "TINTNUM";
01618 char *SINTNUMS = "SINTNUM";
01619 char *DISTCOEFS = "DISTCOEF";
01620 char *ROTCOEFS = "ROTCOEF";
01621 char *ODICOEFFS = "ODICOEFF";
01622 char *OROCOEFFS = "OROCOEFF";
01623 char *POLCALMS = "POLCALM";
01624 char *CODEVER0S = "CODEVER0";
01625 char *CODEVER1S = "CODEVER1";
01626 char *CODEVER2S = "CODEVER2";
01627 char *CODEVER3S = "CODEVER3";
01628 char *SATVALSS = "SATVALS";
01629 char *SOURCES = "SOURCE";
01630 char *ierror = NULL;
01631 char **ierrors = NULL;
01632 char *RAWMEDNS = "RAWMEDN";
01633 char *QUALLEV1S = "QUALLEV1";
01634 char TOTVALSSS[80][13] ;
01635 char DATAVALSSS[80][13] ;
01636 char MISSVALSSS[80][13] ;
01637 char DATAMINSS[80][13] ;
01638 char DATAMAXSS[80][13] ;
01639 char DATAMEDNSS[80][13] ;
01640 char DATAMEANSS[80][13] ;
01641 char DATARMSSS[80][13] ;
01642 char DATASKEWSS[80][13] ;
01643 char DATAKURTSS[80][13] ;
01644 char DATAMINS2S[80][13] ;
01645 char DATAMAXS2S[80][13] ;
01646 char DATAMEDNS2S[80][13] ;
01647 char DATAMEANS2S[80][13] ;
01648 char DATARMSS2S[80][13] ;
01649 char DATASKEWS2S[80][13] ;
01650 char DATAKURTS2S[80][13] ;
01651 char *ROTFLAT = "ROT_FLAT";
01652 char query[MaxNString]="QUERY";
01653 char QueryFlatField[MaxNString];
01654 strcpy(QueryFlatField,"");
01655
01656 double minimum,maximum,median,mean,sigma,skewness,kurtosis;
01657
01658 struct initial const_param;
01659 struct keyword *KeyInterp=NULL;
01660 struct keyword KeyInterpOut;
01661 struct parameterDoppler DopplerParameters;
01662 struct polcal_struct pars;
01663
01664 unsigned char *Mask =NULL;
01665
01666 DRMS_Array_t *BadPixels= NULL;
01667 DRMS_Array_t *CosmicRays= NULL;
01668 DRMS_Array_t *arrin[TempIntNum];
01669 DRMS_Array_t *arrerrors[TempIntNum];
01670 DRMS_Array_t **Segments=NULL;
01671 DRMS_Array_t **Ierror=NULL;
01672 DRMS_Array_t **arrLev1d= NULL;
01673 DRMS_Array_t **arrLev1p= NULL;
01674 DRMS_Array_t **arrLev15= NULL;
01675 DRMS_Array_t *arrintable= NULL;
01676 DRMS_Array_t *flatfield=NULL;
01677 DRMS_Array_t *flatfieldrot=NULL;
01678
01679
01680 DRMS_Type_t type1d = DRMS_TYPE_FLOAT;
01681 DRMS_Type_t type1p = DRMS_TYPE_FLOAT;
01682 DRMS_Type_t type15 = DRMS_TYPE_FLOAT;
01683 DRMS_Type_t typeLO = DRMS_TYPE_INT;
01684 DRMS_Type_t typet = DRMS_TYPE_TIME;
01685 DRMS_Type_t typeEr = DRMS_TYPE_CHAR;
01686
01687 DRMS_Segment_t *segin = NULL;
01688 DRMS_Segment_t *segout = NULL;
01689
01690 DRMS_Record_t *rec = NULL;
01691
01692 double t0,t1;
01693 double *keyF=NULL;
01694 double TSTARTFLAT=0.0, TSTOPFLAT=0.0;
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706 double nonlins[]={0.0,0.025409177,-4.0088672e-06,1.0615198e-10};
01707
01708 double nonlinf[]={0.0,0.020677687,-3.1873243e-06,8.7536678e-11};
01709
01710
01711
01712
01713
01714
01715 char Lev1pSegName[60][5]={"I0","Q0","U0","V0","I1","Q1","U1","V1","I2","Q2","U2","V2","I3","Q3","U3","V3","I4","Q4","U4","V4","I5","Q5","U5","V5","I6","Q6","U6","V6","I7","Q7","U7","V7","I8","Q8","U8","V8","I9","Q9","U9","V9","LCP0","RCP0","LCP1","RCP1","LCP2","RCP2","LCP3","RCP3","LCP4","RCP4","LCP5","RCP5","LCP6","RCP6","LCP7","RCP7","LCP8","RCP8","LCP9","RCP9"};
01716
01717 float totalfront=0.0;
01718 float totalside=0.0;
01719 int countfront=0;
01720 int countside=0;
01721 float iratio=0.0;
01722
01723
01724 int *CameraID, CamID_tmp;
01725
01726
01727
01728
01729
01730
01731
01732 nthreads=omp_get_max_threads();
01733 printf("NUMBER OF THREADS USED BY OPEN MP= %d\n",nthreads);
01734
01735
01736
01737
01738 TotalIn=0;
01739 for(i=0;i<=2;++i)
01740 {
01741 temp = StringLocate(inLev,AcceptedLev[i]);
01742
01743 if(temp == 0) TestLevIn[i]=1; else TestLevIn[i]=0;
01744 TotalIn+=TestLevIn[i];
01745 }
01746
01747 TotalOut=0;
01748 for(i=0;i<=14;++i)
01749 {
01750 temp = StringLocate(outLev,AcceptedLev[i+1]);
01751 if(temp == 0) TestLevOut[i]=1; else TestLevOut[i]=0;
01752 TotalOut+=TestLevOut[i];
01753 }
01754
01755
01756
01757
01758
01759 if(TotalIn != 1)
01760 {
01761 if(StringLocate(inLev,"1") == 0)
01762 {
01763 TestLevIn[0]=1;
01764 TotalIn=1;
01765 }
01766 else
01767 {
01768 printf("The parameter levin must be one of the following strings (select only one): lev1, lev1d, or lev1p\n");
01769 return 1;
01770
01771 }
01772 }
01773
01774 if(TotalOut == 0)
01775 {
01776 printf("The parameter levout must be a combination of the following strings: lev1d, lev1p, or lev1.5\n");
01777 return 1;
01778 }
01779
01780
01781 if(TestLevIn[1]==1 && TestLevOut[13]==0 && TestLevOut[14]==0 && TestLevOut[1]==0 && TestLevOut[2]==0)
01782 {
01783 printf("The parameter levin is the string lev1d, therefore levout can only be a combination of the strings lev1p and lev1.5\n");
01784 return 1;
01785 }
01786 if(TestLevIn[2]==1 && TestLevOut[2]==0)
01787 {
01788 printf("The parameter levin is the string lev1p, therefore levout can only be the string lev1.5\n");
01789 return 1;
01790 }
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800 if(WavelengthID > NumWavelengths-1 || WavelengthID < 0)
01801 {
01802 printf("The parameter WaveLengthIn is not in the range 0-9\n");
01803 return 1;
01804 }
01805
01806
01807
01808 if(DataCadence != 22.5 && DataCadence != 45.0 && DataCadence != 60.0 && DataCadence != 90.0 && DataCadence != 135.0 && DataCadence != 75.0 && DataCadence != 150.0 && DataCadence != 720.0)
01809 {
01810 printf("The command-line parameter cadence is not an accepted value\n");
01811 return 1;
01812 }
01813
01814
01815
01816
01817
01818
01819
01820 if(TestLevIn[0]==1) printf("Input data are level 1.0\n");
01821 if(TestLevIn[1]==1) printf("Input data are level 1d\n");
01822 if(TestLevIn[2]==1) printf("Input data are level 1p\n");
01823 if(TestLevOut[0]==1 || TestLevOut[3]==1 || TestLevOut[4]==1 || TestLevOut[5]==1 || TestLevOut[6]==1 || TestLevOut[7]==1 || TestLevOut[8]==1 || TestLevOut[9]==1 || TestLevOut[10]==1 || TestLevOut[11]==1 || TestLevOut[12]==1)
01824 {
01825 printf("Output data are level 1d\n");
01826 Lev1dWanted=1;
01827 }
01828 if(TestLevOut[1]==1 || TestLevOut[3]==1 || TestLevOut[4]==1 || TestLevOut[7]==1 || TestLevOut[8]==1 || TestLevOut[9]==1 || TestLevOut[10]==1 || TestLevOut[11]==1 || TestLevOut[12]==1 || TestLevOut[13]==1 || TestLevOut[14]==1)
01829 {
01830 printf("Output data are level 1p\n");
01831 Lev1pWanted=1;
01832 }
01833 if(TestLevOut[2]==1 || TestLevOut[5]==1 || TestLevOut[6]==1 || TestLevOut[7]==1 || TestLevOut[8]==1 || TestLevOut[9]==1 || TestLevOut[10]==1 || TestLevOut[11]==1 || TestLevOut[12]==1 || TestLevOut[13]==1 || TestLevOut[14]==1)
01834 {
01835 printf("Output data are level 1.5\n");
01836 Lev15Wanted=1;
01837 }
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852 printf("BEGINNING TIME: %s\n",inRecQuery);
01853 printf("ENDING TIME: %s\n",inRecQuery2);
01854
01855
01856
01857
01858 TimeBegin=sscan_time(inRecQuery);
01859 TimeEnd =sscan_time(inRecQuery2);
01860
01861
01862 if(TimeBegin > TimeEnd)
01863 {
01864 printf("Error: the ending time must be later than the beginning time!\n");
01865 return 1;
01866 }
01867
01868
01869
01870
01871
01872 if(TestLevIn[0]==1)
01873 {
01874 strcpy(dpath2,dpath);
01875 strcat(dpath2,"/../../../");
01876 status = initialize_interpol(&const_param,&initfiles,4096,4096,dpath2);
01877 if(status != 0)
01878 {
01879 printf("Error: could not initialize the gapfilling, derotation, and temporal interpolation routines\n");
01880 return 1;
01881 }
01882
01883
01884 }
01885 if(Lev1pWanted || (Lev15Wanted && TestLevIn[2]==0))
01886 {
01887
01888
01889 status = init_polcal(&pars, method);
01890 if(status != 0)
01891 {
01892 printf("Error: could not initialize the polarization calibration routine\n");
01893 return 1;
01894 }
01895 }
01896
01897
01898
01899 strcpy(HMISeriesLev1,inLev1Series);
01900
01901
01902 strcpy(HMISeriesLev10,HMISeriesLev1);
01903
01904
01905
01906
01907 if( QuickLook == 1)
01908 {
01909 if(DataCadence == 22.5) strcpy(HMISeriesLev1d,"su_couvidat.HMISeriesLev1d22Q");
01910 if(DataCadence == 45.0) strcpy(HMISeriesLev1d,"hmi_test.HMISeriesLev1d45Q");
01911 if(DataCadence == 60.0) strcpy(HMISeriesLev1d,"su_couvidat.HMISeriesLev1d60Q");
01912 if(DataCadence == 75.0) strcpy(HMISeriesLev1d,"su_couvidat.HMISeriesLev1d75Q");
01913 if(DataCadence == 90.0) strcpy(HMISeriesLev1d,"hmi.HMISeriesLev1d90Q");
01914 if(DataCadence == 120.0) strcpy(HMISeriesLev1d,"su_couvidat.HMISeriesLev1d120Q");
01915 if(DataCadence == 135.0) strcpy(HMISeriesLev1d,"hmi_test.HMISeriesLev1d135Q");
01916 if(DataCadence == 150.0) strcpy(HMISeriesLev1d,"su_couvidat.HMISeriesLev1d150Q");
01917 }
01918 else
01919 {
01920 if(DataCadence == 22.5) strcpy(HMISeriesLev1d,"hmi_test.HMISeriesLev1d22");
01921 if(DataCadence == 45.0) strcpy(HMISeriesLev1d,"hmi_test.HMISeriesLev1d45");
01922 if(DataCadence == 60.0) strcpy(HMISeriesLev1d,"hmi_test.HMISeriesLev1d60");
01923 if(DataCadence == 75.0) strcpy(HMISeriesLev1d,"hmi_test.HMISeriesLev1d75");
01924 if(DataCadence == 90.0) strcpy(HMISeriesLev1d,"hmi.HMISeriesLev1d90");
01925 if(DataCadence == 120.0) strcpy(HMISeriesLev1d,"su_couvidat.HMISeriesLev1d120");
01926 if(DataCadence == 135.0) strcpy(HMISeriesLev1d,"hmi_test.HMISeriesLev1d135");
01927 if(DataCadence == 150.0) strcpy(HMISeriesLev1d,"su_couvidat.HMISeriesLev1d150");
01928 }
01929
01930
01931
01932
01933 if(QuickLook == 1)
01934 {
01935 if(DataCadence == 45.0)
01936 {
01937 strcpy(HMISeriesLev15a,"hmi_test.V_45s_nrt" );
01938 strcpy(HMISeriesLev15b,"hmi_test.M_45s_nrt" );
01939 strcpy(HMISeriesLev15c,"hmi_test.Ld_45s_nrt" );
01940 strcpy(HMISeriesLev15d,"hmi_test.Lw_45s_nrt" );
01941 strcpy(HMISeriesLev15e,"hmi_test.Ic_45s_nrt" );
01942 }
01943 if(DataCadence == 22.5)
01944 {
01945 strcpy(HMISeriesLev15a,"hmi_test.V_22s_nrt" );
01946 strcpy(HMISeriesLev15b,"hmi_test.M_22s_nrt" );
01947 strcpy(HMISeriesLev15c,"hmi_test.Ld_22s_nrt" );
01948 strcpy(HMISeriesLev15d,"hmi_test.Lw_22s_nrt" );
01949 strcpy(HMISeriesLev15e,"hmi_test.Ic_22s_nrt" );
01950 }
01951 if(DataCadence == 60.0)
01952 {
01953 strcpy(HMISeriesLev15a,"hmi_test.V_60s_nrt");
01954 strcpy(HMISeriesLev15b,"hmi_test.M_60s_nrt");
01955 strcpy(HMISeriesLev15c,"hmi_test.Ld_60s_nrt");
01956 strcpy(HMISeriesLev15d,"hmi_test.Lw_60s_nrt");
01957 strcpy(HMISeriesLev15e,"hmi_test.Ic_60s_nrt");
01958 }
01959 if(DataCadence == 75.0)
01960 {
01961 strcpy(HMISeriesLev15a,"hmi_test.V_75s_nrt" );
01962 strcpy(HMISeriesLev15b,"hmi_test.M_75s_nrt" );
01963 strcpy(HMISeriesLev15c,"hmi_test.Ld_75s_nrt" );
01964 strcpy(HMISeriesLev15d,"hmi_test.Lw_75s_nrt" );
01965 strcpy(HMISeriesLev15e,"hmi_test.Ic_75s_nrt" );
01966 }
01967 if(DataCadence == 720.0 && unusual == 0)
01968 {
01969 strcpy(HMISeriesLev15a,"hmi_test.V_720s_nrt");
01970 strcpy(HMISeriesLev15b,"hmi_test.M_720s_nrt");
01971 strcpy(HMISeriesLev15c,"hmi_test.Ld_720s_nrt");
01972 strcpy(HMISeriesLev15d,"hmi_test.Lw_720s_nrt");
01973 strcpy(HMISeriesLev15e,"hmi_test.Ic_720s_nrt");
01974 }
01975 if(DataCadence == 720.0 && unusual == 1)
01976 {
01977 strcpy(HMISeriesLev15a,"hmi_test.V2_720s_nrt");
01978 strcpy(HMISeriesLev15b,"hmi_test.M2_720s_nrt");
01979 strcpy(HMISeriesLev15c,"hmi_test.Ld2_720s_nrt");
01980 strcpy(HMISeriesLev15d,"hmi_test.Lw2_720s_nrt");
01981 strcpy(HMISeriesLev15e,"hmi_test.Ic2_720s_nrt");
01982 }
01983 }
01984 else
01985 {
01986 if(DataCadence == 45.0)
01987 {
01988 strcpy(HMISeriesLev15a,"hmi_test.V_45s");
01989 strcpy(HMISeriesLev15b,"hmi_test.M_45s" );
01990 strcpy(HMISeriesLev15c,"hmi_test.Ld_45s" );
01991 strcpy(HMISeriesLev15d,"hmi_test.Lw_45s" );
01992 strcpy(HMISeriesLev15e,"hmi_test.Ic_45s" );
01993 }
01994 if(DataCadence == 22.5)
01995 {
01996 strcpy(HMISeriesLev15a,"hmi_test.V_22s" );
01997 strcpy(HMISeriesLev15b,"hmi_test.M_22s" );
01998 strcpy(HMISeriesLev15c,"hmi_test.Ld_22s" );
01999 strcpy(HMISeriesLev15d,"hmi_test.Lw_22s" );
02000 strcpy(HMISeriesLev15e,"hmi_test.Ic_22s" );
02001 }
02002 if(DataCadence == 60.0)
02003 {
02004 strcpy(HMISeriesLev15a,"hmi_test.V_60s");
02005 strcpy(HMISeriesLev15b,"hmi_test.M_60s");
02006 strcpy(HMISeriesLev15c,"hmi_test.Ld_60s");
02007 strcpy(HMISeriesLev15d,"hmi_test.Lw_60s");
02008 strcpy(HMISeriesLev15e,"hmi_test.Ic_60s");
02009 }
02010 if(DataCadence == 75.0)
02011 {
02012 strcpy(HMISeriesLev15a,"hmi_test.V_75s" );
02013 strcpy(HMISeriesLev15b,"hmi_test.M_75s" );
02014 strcpy(HMISeriesLev15c,"hmi_test.Ld_75s" );
02015 strcpy(HMISeriesLev15d,"hmi_test.Lw_75s" );
02016 strcpy(HMISeriesLev15e,"hmi_test.Ic_75s" );
02017 }
02018 if(DataCadence == 135.0)
02019 {
02020 strcpy(HMISeriesLev15a,"hmi_test.V_135s");
02021 strcpy(HMISeriesLev15b,"hmi_test.M_135s");
02022 strcpy(HMISeriesLev15c,"hmi_test.Ld_135s");
02023 strcpy(HMISeriesLev15d,"hmi_test.Lw_135s");
02024 strcpy(HMISeriesLev15e,"hmi_test.Ic_135s");
02025 }
02026 if(DataCadence == 720.0 && unusual == 0)
02027 {
02028 strcpy(HMISeriesLev15a,"hmi_test.V_720s" );
02029 strcpy(HMISeriesLev15b,"hmi_test.M_720s" );
02030 strcpy(HMISeriesLev15c,"hmi_test.Ld_720s" );
02031 strcpy(HMISeriesLev15d,"hmi_test.Lw_720s" );
02032 strcpy(HMISeriesLev15e,"hmi_test.Ic_720s" );
02033 }
02034 if(DataCadence == 720.0 && unusual == 1)
02035 {
02036 strcpy(HMISeriesLev15a,"hmi_test.V2_720s" );
02037 strcpy(HMISeriesLev15b,"hmi_test.M2_720s" );
02038 strcpy(HMISeriesLev15c,"hmi_test.Ld2_720s" );
02039 strcpy(HMISeriesLev15d,"hmi_test.Lw2_720s" );
02040 strcpy(HMISeriesLev15e,"hmi_test.Ic2_720s" );
02041 }
02042 }
02043
02044
02045
02046
02047
02048 if(QuickLook == 1)
02049 {
02050 if(DataCadence == 22.5) strcpy(HMISeriesLev1pb,"su_couvidat.HMISeriesLev1pb22Q");
02051 if(DataCadence == 45.0) strcpy(HMISeriesLev1pb,"hmi_test.HMISeriesLev1pb45Q");
02052 if(DataCadence == 60.0) strcpy(HMISeriesLev1pb,"su_couvidat.HMISeriesLev1pb60Q");
02053 if(DataCadence == 75.0) strcpy(HMISeriesLev1pb,"su_couvidat.HMISeriesLev1pb75Q");
02054 }
02055 else
02056 {
02057 if(DataCadence == 22.5) strcpy(HMISeriesLev1pb,"hmi_test.HMISeriesLev1pb22");
02058 if(DataCadence == 45.0) strcpy(HMISeriesLev1pb,"hmi_test.HMISeriesLev1pb45");
02059 if(DataCadence == 60.0) strcpy(HMISeriesLev1pb,"hmi_test.HMISeriesLev1pb60");
02060 if(DataCadence == 75.0) strcpy(HMISeriesLev1pb,"hmi_test.HMISeriesLev1pb75");
02061 }
02062
02063
02064
02065
02066 if(QuickLook == 1)
02067 {
02068 if( DataCadence == 45.0) strcpy(HMISeriesLev1pa,"hmi_test.HMISeriesLev1pa45Q");
02069 if( DataCadence == 90.0) strcpy(HMISeriesLev1pa,"hmi.S_90s");
02070 if( DataCadence == 120.0) strcpy(HMISeriesLev1pa,"su_couvidat.HMISeriesLev1pa120Q");
02071 if( DataCadence == 135.0) strcpy(HMISeriesLev1pa,"hmi_test.HMISeriesLev1pa135Q");
02072 if( DataCadence == 150.0) strcpy(HMISeriesLev1pa,"su_couvidat.HMISeriesLev1pa150Q");
02073 if( DataCadence == 720.0 && unusual == 0) strcpy(HMISeriesLev1pa,"hmi_test.S_720s_nrt");
02074 if( DataCadence == 720.0 && unusual == 1) strcpy(HMISeriesLev1pa,"hmi_test.S2_720s_nrt");
02075 }
02076 else
02077 {
02078 if( DataCadence == 45.0) strcpy(HMISeriesLev1pa,"hmi_test.HMISeriesLev1pa45");
02079 if( DataCadence == 90.0) strcpy(HMISeriesLev1pa,"hmi.HMISeriesLev1pa90");
02080 if( DataCadence == 120.0) strcpy(HMISeriesLev1pa,"su_couvidat.HMISeriesLev1pa120");
02081 if( DataCadence == 135.0) strcpy(HMISeriesLev1pa,"hmi_test.HMISeriesLev1pa135");
02082 if( DataCadence == 150.0) strcpy(HMISeriesLev1pa,"su_couvidat.HMISeriesLev1pa150");
02083 if( DataCadence == 720.0 && unusual == 0) strcpy(HMISeriesLev1pa,"hmi_test.S_720s");
02084 if( DataCadence == 720.0 && unusual == 1) strcpy(HMISeriesLev1pa,"hmi_test.S2_720s");
02085 }
02086
02087
02088
02089
02090
02091
02092
02093
02094
02095
02096
02097 if ( TestLevIn[0]==1 )
02098 {
02099
02100
02101
02102
02103
02104
02105
02106 TimeBegin2=TimeBegin-(TIME)TempIntNum*DataCadence/2.-TimeCaution;
02107 TimeEnd2 =TimeEnd +(TIME)TempIntNum*DataCadence/2.+TimeCaution;
02108 sprint_time(timeBegin2,TimeBegin2,"TAI",0);
02109 sprint_time(timeEnd2,TimeEnd2,"TAI",0);
02110 strcat(HMISeriesLev1,"[");
02111 strcat(HMISeriesLev1,timeBegin2);
02112 strcat(HMISeriesLev1,"-");
02113 strcat(HMISeriesLev1,timeEnd2);
02114 strcat(HMISeriesLev1,"]");
02115
02116
02117
02118
02119 printf("LEVEL 1 SERIES QUERY = %s\n",HMISeriesLev1);
02120 recLev1 = drms_open_records(drms_env,HMISeriesLev1,&status);
02121 if (status == DRMS_SUCCESS && recLev1 != NULL && recLev1->n > 0)
02122 {
02123 nRecs1 = recLev1->n;
02124
02125 if(nRecs1 >= nRecmax)
02126 {
02127 printf("Too many records requested\n");
02128 return 1;
02129 }
02130
02131 printf("Number of level 1 records opened: %d\n",nRecs1);
02132
02133
02134 FSN = (int *)malloc(nRecs1*sizeof(int));
02135 if(FSN == NULL)
02136 {
02137 printf("Error: memory could not be allocated to FSN\n");
02138 return 1;
02139 }
02140 internTOBS = (TIME *)malloc(nRecs1*sizeof(TIME));
02141 if(internTOBS == NULL)
02142 {
02143 printf("Error: memory could not be allocated to internTOBS\n");
02144 return 1;
02145 }
02146 HWL1POS = (int *)malloc(nRecs1*sizeof(int));
02147 if(HWL1POS == NULL)
02148 {
02149 printf("Error: memory could not be allocated to HWL1POS\n");
02150 return 1;
02151 }
02152 HWL2POS = (int *)malloc(nRecs1*sizeof(int));
02153 if(HWL2POS == NULL)
02154 {
02155 printf("Error: memory could not be allocated to HWL2POS\n");
02156 return 1;
02157 }
02158 HWL3POS = (int *)malloc(nRecs1*sizeof(int));
02159 if(HWL3POS == NULL)
02160 {
02161 printf("Error: memory could not be allocated to HWL3POS\n");
02162 return 1;
02163 }
02164 HWL4POS = (int *)malloc(nRecs1*sizeof(int));
02165 if(HWL4POS == NULL)
02166 {
02167 printf("Error: memory could not be allocated to HWL4POS\n");
02168 return 1;
02169 }
02170 HPL1POS = (int *)malloc(nRecs1*sizeof(int));
02171 if(HPL1POS == NULL)
02172 {
02173 printf("Error: memory could not be allocated to HPL1POS\n");
02174 return 1;
02175 }
02176 HPL2POS = (int *)malloc(nRecs1*sizeof(int));
02177 if(HPL2POS == NULL)
02178 {
02179 printf("Error: memory could not be allocated to HPL2POS\n");
02180 return 1;
02181 }
02182 HPL3POS = (int *)malloc(nRecs1*sizeof(int));
02183 if(HPL3POS == NULL)
02184 {
02185 printf("Error: memory could not be allocated to HPL3POS\n");
02186 return 1;
02187 }
02188 FID = (int *)malloc(nRecs1*sizeof(int));
02189 if(FID == NULL)
02190 {
02191 printf("Error: memory could not be allocated to FID\n");
02192 return 1;
02193 }
02194 HFLID = (int *)malloc(nRecs1*sizeof(int));
02195 if(HFLID == NULL)
02196 {
02197 printf("Error: memory could not be allocated to HFLID\n");
02198 return 1;
02199 }
02200 HCAMID = (int *)malloc(nRecs1*sizeof(int));
02201 if(HCAMID == NULL)
02202 {
02203 printf("Error: memory could not be allocated to HCAMID\n");
02204 return 1;
02205 }
02206 RSUN = (float *)malloc(nRecs1*sizeof(float));
02207 if(RSUN == NULL)
02208 {
02209 printf("Error: memory could not be allocated to RSUN\n");
02210 return 1;
02211 }
02212 CROTA2 = (float *)malloc(nRecs1*sizeof(float));
02213 if(CROTA2 == NULL)
02214 {
02215 printf("Error: memory could not be allocated to CROTA2\n");
02216 return 1;
02217 }
02218 CRLTOBS = (float *)malloc(nRecs1*sizeof(float));
02219 if(CRLTOBS == NULL)
02220 {
02221 printf("Error: memory could not be allocated to CRLTOBS\n");
02222 return 1;
02223 }
02224 DSUNOBS = (double *)malloc(nRecs1*sizeof(double));
02225 if(DSUNOBS == NULL)
02226 {
02227 printf("Error: memory could not be allocated to DSUNOBS\n");
02228 return 1;
02229 }
02230 X0 = (float *)malloc(nRecs1*sizeof(float));
02231 if(X0 == NULL)
02232 {
02233 printf("Error: memory could not be allocated to X0\n");
02234 return 1;
02235 }
02236 Y0 = (float *)malloc(nRecs1*sizeof(float));
02237 if(Y0 == NULL)
02238 {
02239 printf("Error: memory could not be allocated to Y0\n");
02240 return 1;
02241 }
02242 SegmentRead= (int *)malloc(nRecs1*sizeof(int));
02243 if(SegmentRead == NULL)
02244 {
02245 printf("Error: memory could not be allocated to SegmentRead\n");
02246 return 1;
02247 }
02248 KeywordMissing= (int *)malloc(nRecs1*sizeof(int));
02249 if(KeywordMissing == NULL)
02250 {
02251 printf("Error: memory could not be allocated to KeywordMissing\n");
02252 return 1;
02253 }
02254 Segments = (DRMS_Array_t **)malloc(nRecs1*sizeof(DRMS_Array_t *));
02255 if(Segments == NULL)
02256 {
02257 printf("Error: memory could not be allocated to Segments\n");
02258 return 1;
02259 }
02260 for(i=0;i<nRecs1;i++) Segments[i]=NULL;
02261 Ierror = (DRMS_Array_t **)malloc(nRecs1*sizeof(DRMS_Array_t *));
02262 if(Ierror == NULL)
02263 {
02264 printf("Error: memory could not be allocated to Ierror\n");
02265 return 1;
02266 }
02267 for(i=0;i<nRecs1;i++) Ierror[i]=NULL;
02268 IndexFiltergram = (int *)malloc(nRecs1*sizeof(int));
02269 if(IndexFiltergram == NULL)
02270 {
02271 printf("Error: memory could not be allocated to IndexFiltergram\n");
02272 return 1;
02273 }
02274 CFINDEX = (int *)malloc(nRecs1*sizeof(int));
02275 if(CFINDEX == NULL)
02276 {
02277 printf("Error: memory could not be allocated to CFINDEX\n");
02278 return 1;
02279 }
02280 HIMGCFID = (int *)malloc(nRecs1*sizeof(int));
02281 if(HIMGCFID == NULL)
02282 {
02283 printf("Error: memory could not be allocated to HIMGCFID\n");
02284 return 1;
02285 }
02286 IMGTYPE = (char **)malloc(nRecs1*sizeof(char *));
02287 if(IMGTYPE == NULL)
02288 {
02289 printf("Error: memory could not be allocated to IMGTYPE\n");
02290 return 1;
02291 }
02292 for(i=0;i<nRecs1;i++) IMGTYPE[i]=NULL;
02293 CDELT1 = (float *)malloc(nRecs1*sizeof(float));
02294 if(CDELT1 == NULL)
02295 {
02296 printf("Error: memory could not be allocated to CDELT1\n");
02297 return 1;
02298 }
02299 OBSVR = (double *)malloc(nRecs1*sizeof(double));
02300 if(OBSVR == NULL)
02301 {
02302 printf("Error: memory could not be allocated to OBSVR\n");
02303 return 1;
02304 }
02305 OBSVW = (double *)malloc(nRecs1*sizeof(double));
02306 if(OBSVW == NULL)
02307 {
02308 printf("Error: memory could not be allocated to OBSVW\n");
02309 return 1;
02310 }
02311 OBSVN = (double *)malloc(nRecs1*sizeof(double));
02312 if(OBSVN == NULL)
02313 {
02314 printf("Error: memory could not be allocated to OBSVN\n");
02315 return 1;
02316 }
02317 CRLNOBS = (float *)malloc(nRecs1*sizeof(float));
02318 if(CRLNOBS == NULL)
02319 {
02320 printf("Error: memory could not be allocated to CRLNOBS\n");
02321 return 1;
02322 }
02323
02324
02325
02326
02327
02328
02329 CARROT = (int *)malloc(nRecs1*sizeof(int));
02330 if(CARROT == NULL)
02331 {
02332 printf("Error: memory could not be allocated to CARROT\n");
02333 return 1;
02334 }
02335 HWLTID = (int *)malloc(nRecs1*sizeof(int));
02336 if(HWLTID == NULL)
02337 {
02338 printf("Error: memory could not be allocated to HWLTID\n");
02339 return 1;
02340 }
02341 HPLTID = (int *)malloc(nRecs1*sizeof(int));
02342 if(HPLTID == NULL)
02343 {
02344 printf("Error: memory could not be allocated to HPLTID\n");
02345 return 1;
02346 }
02347 HWLTNSET = (char **)malloc(nRecs1*sizeof(char *));
02348 if(HWLTNSET == NULL)
02349 {
02350 printf("Error: memory could not be allocated to HWLTNSET\n");
02351 return 1;
02352 }
02353 NBADPERM = (int *)malloc(nRecs1*sizeof(int));
02354 if(NBADPERM == NULL)
02355 {
02356 printf("Error: memory could not be allocated to NBADPERM\n");
02357 return 1;
02358 }
02359 QUALITYlev1 = (int *)malloc(nRecs1*sizeof(int));
02360 if(QUALITYlev1 == NULL)
02361 {
02362 printf("Error: memory could not be allocated to QUALITYlev1\n");
02363 return 1;
02364 }
02365 for(i=0;i<nRecs1;++i) QUALITYlev1[i]=0;
02366 QUALITYin = (int *)malloc(nRecs1*sizeof(int));
02367 if(QUALITYin == NULL)
02368 {
02369 printf("Error: memory could not be allocated to QUALITYin\n");
02370 return 1;
02371 }
02372 EXPTIME = (float *)malloc(nRecs1*sizeof(float));
02373 if(EXPTIME == NULL)
02374 {
02375 printf("Error: memory could not be allocated to EXPTIME\n");
02376 return 1;
02377 }
02378 CALVER32 = (long long *)malloc(nRecs1*sizeof(long long));
02379 if(CALVER32 == NULL)
02380 {
02381 printf("Error: memory could not be allocated to CALVER32\n");
02382 return 1;
02383 }
02384 CAMERA = (int *)malloc(nRecs1*sizeof(int));
02385 if(CAMERA == NULL)
02386 {
02387 printf("Error: memory could not be allocated to CAMERA\n");
02388 return 1;
02389 }
02390 DATAMEAN = (float *)malloc(nRecs1*sizeof(float));
02391 if(DATAMEAN == NULL)
02392 {
02393 printf("Error: memory could not be allocated to DATAMEAN\n");
02394 return 1;
02395 }
02396
02397
02398
02399
02400
02401
02402
02403 t0=dsecnd();
02404
02405 k=0;
02406 int CamYesNo=0, FIDshow;
02407
02408 for(i=0;i<nRecs1;++i)
02409 {
02410 FSN[i] = drms_getkey_int(recLev1->records[i] ,FSNS ,&statusA[0]);
02411
02412
02413 internTOBS[i] = drms_getkey_time(recLev1->records[i],TOBSS ,&statusA[1]);
02414 HWL1POS[i] = drms_getkey_int(recLev1->records[i] ,HWL1POSS ,&statusA[2]);
02415 HWL2POS[i] = drms_getkey_int(recLev1->records[i] ,HWL2POSS ,&statusA[3]);
02416 HWL3POS[i] = drms_getkey_int(recLev1->records[i] ,HWL3POSS ,&statusA[4]);
02417 HWL4POS[i] = drms_getkey_int(recLev1->records[i] ,HWL4POSS ,&statusA[5]);
02418 HPL1POS[i] = drms_getkey_int(recLev1->records[i] ,HPL1POSS ,&statusA[6]);
02419 HPL2POS[i] = drms_getkey_int(recLev1->records[i] ,HPL2POSS ,&statusA[7]);
02420 HPL3POS[i] = drms_getkey_int(recLev1->records[i] ,HPL3POSS ,&statusA[8]);
02421 FID[i] = drms_getkey_int(recLev1->records[i] ,FIDS ,&statusA[9]);
02422 HCAMID[i] = drms_getkey_int(recLev1->records[i] ,HCAMIDS ,&statusA[10]);
02423 if(HCAMID[i] != LIGHT_SIDE && HCAMID[i] != LIGHT_FRONT) statusA[11]=1;
02424 CFINDEX[i] = drms_getkey_int(recLev1->records[i] ,HCFTIDS ,&statusA[11]);
02425
02426
02427
02428 HFLID[i] = drms_getkey_int(recLev1->records[i] ,"HFTSACID" ,&statusA[12]);
02429
02430
02431 CamYesNo = drms_getkey_int(recLev1->records[i] ,"CAMERA" ,&status);
02432 FIDshow = drms_getkey_int(recLev1->records[i] ,"FID" ,&status);
02433
02434
02435
02436
02437
02438
02439 if (CamYesNo == 2)
02440 {
02441 iii=needtochangeFID(HFLID[i]);
02442 if(iii == 1)
02443 {
02444 ii = drms_getkey_int(recLev1->records[i],"HFLPSITN",&status);
02445 if( (ii%72)/24 == 1)
02446 {
02447 FID[i]=FID[i]+100000;
02448
02449 }
02450 }
02451
02452 }
02453
02454
02455 IMGTYPE[i] = (char *)malloc(6*sizeof(char *));
02456 if(IMGTYPE[i] == NULL)
02457 {
02458 printf("Error: memory could not be allocated to IMGTYPE[%d]\n",i);
02459 return 1;
02460 }
02461 IMGTYPE[i] = drms_getkey_string(recLev1->records[i],IMGTYPES ,&statusA[13]);
02462
02463 X0[i] = (float)drms_getkey_double(recLev1->records[i],CRPIX1S, &statusA[14]);
02464 if(statusA[14] == DRMS_SUCCESS && !isnan(X0[i])) X0[i]=X0[i]-1.0;
02465 else statusA[14] = 1;
02466
02467 Y0[i] = (float)drms_getkey_double(recLev1->records[i],CRPIX2S,&statusA[15]);
02468 if(statusA[15] == DRMS_SUCCESS && !isnan(Y0[i])) Y0[i]=Y0[i]-1.0;
02469 else statusA[15] = 1;
02470
02471 X0LF = (float)drms_getkey_double(recLev1->records[i],X0LFS, &status);
02472 Y0LF = (float)drms_getkey_double(recLev1->records[i],Y0LFS, &status2);
02473 if(status != DRMS_SUCCESS || status2 != DRMS_SUCCESS || isnan(X0LF) || isnan(Y0LF))
02474 {
02475 statusA[14]=1;
02476 statusA[15]=1;
02477 X0[i]=sqrt(-1);
02478 Y0[i]=sqrt(-1);
02479 KeywordMissing[i]=1;
02480 }
02481
02482
02483 RSUN[i] = (float)drms_getkey_double(recLev1->records[i],RSUNS ,&statusA[16]);
02484
02485 CROTA2[i] = (float)drms_getkey_double(recLev1->records[i],CROTA2S ,&statusA[17]);
02486
02487
02488
02489 if(statusA[17] == DRMS_SUCCESS && !isnan(CROTA2[i]))
02490 {
02491 if(CROTA2[i] > 362. || CROTA2[i] < -362.) statusA[17] = 1;
02492 }
02493
02494
02495
02496 if(statusA[17] == DRMS_SUCCESS && !isnan(CROTA2[i])) CROTA2[i]=-CROTA2[i];
02497 else statusA[17] = 1;
02498
02499 CRLTOBS[i] = (float)drms_getkey_double(recLev1->records[i],CRLTOBSS,&statusA[18]);
02500 if(isnan(CRLTOBS[i])) statusA[18] = 1;
02501 DSUNOBS[i] = drms_getkey_double(recLev1->records[i],DSUNOBSS,&statusA[19]);
02502 if(isnan(DSUNOBS[i])) statusA[19] = 1;
02503 HIMGCFID[i] = drms_getkey_int(recLev1->records[i] ,HIMGCFIDS ,&statusA[20]);
02504 if(isnan(HIMGCFID[i])) statusA[20] = 1;
02505 CDELT1[i] = (float)drms_getkey_double(recLev1->records[i] ,CDELT1S,&statusA[21]);
02506 if(isnan(CDELT1[i])) statusA[21] = 1;
02507 OBSVR[i] = drms_getkey_double(recLev1->records[i] ,OBSVRS ,&statusA[22]);
02508 if(isnan(OBSVR[i])) statusA[22] = 1;
02509 OBSVW[i] = drms_getkey_double(recLev1->records[i] ,OBSVWS ,&statusA[23]);
02510 if(isnan(OBSVW[i])) statusA[23] = 1;
02511 OBSVN[i] = drms_getkey_double(recLev1->records[i] ,OBSVNS ,&statusA[24]);
02512 if(isnan(OBSVN[i])) statusA[24] = 1;
02513 CARROT[i] = drms_getkey_int(recLev1->records[i] ,CARROTS ,&statusA[25]);
02514 SegmentRead[i]= 0;
02515 KeywordMissing[i]=0;
02516 CRLNOBS[i] = (float)drms_getkey_double(recLev1->records[i] ,CRLNOBSS,&statusA[26]);
02517 if(isnan(CRLNOBS[i])) statusA[26] = 1;
02518 statusA[27]=0;
02519 HWLTID[i] = drms_getkey_int(recLev1->records[i] ,HWLTIDS ,&statusA[28]);
02520 HPLTID[i] = drms_getkey_int(recLev1->records[i] ,HPLTIDS ,&statusA[29]);
02521 HWLTNSET[i] = (char *)malloc(7*sizeof(char *));
02522 if(HWLTNSET[i] == NULL)
02523 {
02524 printf("Error: memory could not be allocated to HWLTNSET[%d]\n",i);
02525 return 1;
02526 }
02527 HWLTNSET[i] = drms_getkey_string(recLev1->records[i] ,HWLTNSETS ,&statusA[30]);
02528 EXPTIME[i] = (float)drms_getkey_double(recLev1->records[i],"EXPTIME",&statusA[31]);
02529
02530 NBADPERM[i] = drms_getkey_int(recLev1->records[i] ,NBADPERMS ,&statusA[32]);
02531 if(statusA[32] != DRMS_SUCCESS) NBADPERM[i]=-1;
02532 QUALITYin[i] = drms_getkey_int(recLev1->records[i] ,QUALITYS ,&statusA[33]);
02533 if(statusA[33] != DRMS_SUCCESS) KeywordMissing[i]=1;
02534
02535 if( (QUALITYin[i] & Q_MISSING_SEGMENT) == Q_MISSING_SEGMENT)
02536 {
02537 statusA[33]=1;
02538 SegmentRead[i]= -1;
02539 KeywordMissing[i]=1;
02540 }
02541
02542 CALVER32[i] = (long long)drms_getkey_int(recLev1->records[i] ,CALVER32S,&statusA[34]);
02543 if(statusA[34] != DRMS_SUCCESS)
02544 {
02545 CALVER32[i]=CALVER_DEFAULT;
02546 KeywordMissing[i]=1;
02547 }
02548 if( CALVER32[i] != CALVER32[0] )
02549 {
02550 printf("Error: CALVER32[%d] is different from CALVER32[0]\n",i);
02551 return 1;
02552 }
02553 CAMERA[i] = drms_getkey_int(recLev1->records[i],CAMERAS,&statusA[35]);
02554 if(CAMERA[i] == -2147483648 || statusA[35] != DRMS_SUCCESS) KeywordMissing[i]=1;
02555
02556 DATAMEAN[i] = (float)drms_getkey_double(recLev1->records[i],"DATAMEAN",&statusA[36]);
02557 if(statusA[36] != DRMS_SUCCESS) KeywordMissing[i]=1;
02558
02559
02560
02561
02562
02563
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581 TotalStatus=0;
02582 for(ii=0;ii<=13;++ii) TotalStatus+=statusA[ii];
02583 for(ii=16;ii<=31;++ii) TotalStatus+=statusA[ii];
02584 if(TotalStatus != 0 || !strcmp(IMGTYPE[i],"DARK"))
02585 {
02586 printf("Error: the level 1 filtergram index %d is missing at least one keyword\n",i);
02587
02588 internTOBS[i] = MISSINGKEYWORD;
02589 HWL1POS[i] = MISSINGKEYWORDINT;
02590 HWL2POS[i] = MISSINGKEYWORDINT;
02591 HWL3POS[i] = MISSINGKEYWORDINT;
02592 HWL4POS[i] = MISSINGKEYWORDINT;
02593 HPL1POS[i] = MISSINGKEYWORDINT;
02594 HPL2POS[i] = MISSINGKEYWORDINT;
02595 HPL3POS[i] = MISSINGKEYWORDINT;
02596 FID[i] = MISSINGKEYWORDINT;
02597 HCAMID[i] = MISSINGKEYWORDINT;
02598 CFINDEX[i] = MISSINGKEYWORDINT;
02599
02600 FSN[i] = MISSINGKEYWORDINT;
02601 X0[i] = MISSINGKEYWORD;
02602 Y0[i] = MISSINGKEYWORD;
02603 RSUN[i] = MISSINGKEYWORD;
02604 CROTA2[i] = MISSINGKEYWORD;
02605 CRLTOBS[i] = MISSINGKEYWORD;
02606 DSUNOBS[i] = MISSINGKEYWORD;
02607 HIMGCFID[i] = MISSINGKEYWORD;
02608 CDELT1[i] = MISSINGKEYWORD;
02609 OBSVR[i] = MISSINGKEYWORD;
02610 OBSVW[i] = MISSINGKEYWORD;
02611 OBSVN[i] = MISSINGKEYWORD;
02612 CARROT[i] = MISSINGKEYWORDINT;
02613 CRLNOBS[i] = MISSINGKEYWORD;
02614 HWLTID[i] = MISSINGKEYWORD;
02615 strcpy(HWLTNSET[i],"NONE");
02616 EXPTIME[i] = MISSINGKEYWORD;
02617 DATAMEAN[i] = MISSINGKEYWORD;
02618
02619 KeywordMissing[i]=1;
02620 }
02621 else
02622 {
02623 if(WhichWavelength(FID[i]) == WavelengthID && HCAMID[i] == CamId)
02624 {
02625 IndexFiltergram[k]=i;
02626 ++k;
02627 }
02628 }
02629
02630 }
02631 t1=dsecnd();
02632 printf("TIME ELAPSED TO READ THE KEYWORDS OF ALL LEVEL 1 RECORDS: %f\n",t1-t0);
02633
02634 nIndexFiltergram=k;
02635 if(nIndexFiltergram == 0)
02636 {
02637 printf("Error: no filtergram was found with the wavelength %d in the requested level 1 records %s\n",WavelengthID,HMISeriesLev1);
02638
02639 }
02640 else printf("number of target filtergrams: %d \n",nIndexFiltergram);
02641
02642 }
02643 else
02644 {
02645
02646
02647 printf("Error: no level 1 records in the time interval requested %s\n",HMISeriesLev1);
02648 return 1;
02649 }
02650
02651
02652 for(i=0;i<nRecs1;++i)
02653 {
02654 if( (KeywordMissing[i] !=1) && (HCAMID[i] == LIGHT_FRONT) && (WhichWavelength(FID[i]) == 5) )
02655 {totalfront += DATAMEAN[i];
02656 countfront += 1;
02657 }
02658 if( (KeywordMissing[i] !=1) && (HCAMID[i] == LIGHT_SIDE) && (WhichWavelength(FID[i]) == 5) )
02659 {totalside += DATAMEAN[i];
02660 countside += 1;
02661 }
02662 }
02663 if(countfront != 0 && countside !=0)
02664 {
02665 totalfront = totalfront/(float)countfront;
02666 totalside = totalside/(float)countside;
02667 iratio = totalfront/totalside;
02668 printf("INTENSITY RATIO FRONT/SIDE CAMERAS = %f BASED ON %d FRONT and %d SIDE IMAGES \n",iratio,countfront,countside);
02669 }
02670 else
02671 {
02672 printf("WARNING: THERE WAS NOT ENOUGH LEV1 AT WAVELENGTH INDEX 5 TO COMPUTE AN INTENSITY RATIO BETWEEN FRONT AND SIDE CAMERAS: THE CODE WILL USE THE VALUE 1.05 IF CAMERAS HAVE TO BE COMBINED \n");
02673 iratio = 1.05;
02674 }
02675 }
02676
02677
02678
02679
02680
02681
02682
02683
02684
02685
02686
02687
02688
02689
02690
02691 TREC_STEP = DataCadence;
02692
02693 TargetTime = (TIME)floor((TimeBegin-TREC_EPOCH0+TREC_STEP/2.0)/TREC_STEP)*TREC_STEP+TREC_EPOCH0;
02694 if(TargetTime < TimeBegin) TargetTime+=TREC_STEP;
02695 initialrun=1;
02696 PreviousTargetTime=TargetTime;
02697
02698
02699
02700 while(TargetTime <= TimeEnd)
02701 {
02702
02703
02704 if(inRotationalFlat == 1)
02705 {
02706
02707
02708 if(floor(TargetTime/86400.0) != floor(PreviousTargetTime/86400.0) )
02709 {
02710 printf("Error: the new target time is for a different day than the previous target time: you are not allowed to change day when applying a rotational flat field\n");
02711 return 1;
02712 }
02713
02714
02715 if(initialrun != 1)
02716 {
02717 if(TargetTime < TSTARTFLAT || TargetTime > TSTOPFLAT)
02718 {
02719 printf("Error: the target time is not within the time range for which the rotation flat field used is valid\n");
02720 sprint_time(timeBegin2,TSTARTFLAT,"TAI",0);
02721 printf("\n TSTART OF FLAT FIELD = %s\n",timeBegin2);
02722 sprint_time(timeBegin2,TSTOPFLAT,"TAI",0);
02723 printf("\n TSTOP OF FLAT FIELD = %s\n",timeBegin2);
02724 sprint_time(timeBegin2,TargetTime,"TAI",0);
02725 printf("\n TARGET TIME = %s\n",timeBegin2);
02726 return 1;
02727 }
02728 }
02729
02730 }
02731
02732
02733 sprint_time(timeBegin2,TargetTime,"TAI",0);
02734 printf("\n TARGET TIME = %s\n",timeBegin2);
02735 printf("-----------------------------------------------------------------------------------\n");
02736
02737 if(nIndexFiltergram == 0 && TestLevIn[0] == 1 )
02738 {
02739 QUALITY = QUALITY | QUAL_TARGETFILTERGRAMMISSING;
02740 CreateEmptyRecord = 1;
02741 goto NextTargetTime;
02742 }
02743
02744 QUALITY = 0;
02745 QUALITYLEV1 = 0;
02746 strcpy(HISTORY,"");
02747 totalTempIntNum = 0;
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757 if (TestLevIn[1]==1)
02758 {
02759
02760 strcpy(source,"[RECORDS USED: NOT REPORTED");
02761
02762 strcpy(HMISeries,HMISeriesLev1d);
02763 strcat(HMISeries,"[");
02764 strcat(HMISeries,timeBegin2);
02765 strcat(HMISeries,"][][");
02766 sprintf(CamIds,"%d",CamId);
02767 strcat(HMISeries,CamIds);
02768 strcat(HMISeries,"]");
02769
02770 printf("LEVEL 1d QUERY= %s\n",HMISeries);
02771 recLev1d = drms_open_records(drms_env,HMISeries,&status);
02772
02773 if (status == DRMS_SUCCESS && recLev1d != NULL && recLev1d->n > 0)
02774 {
02775 nRecs1d = recLev1d->n;
02776
02777 if(nRecs1d >= MaxNumFiltergrams)
02778 {
02779 printf("Number of open record is larger than %d\n",MaxNumFiltergrams);
02780 return 1;
02781 }
02782 printf("Number of level 1d records opened= %d\n",nRecs1d);
02783
02784 trec = drms_getkey_time(recLev1d->records[0],TRECS,&status);
02785 if(status != DRMS_SUCCESS)
02786 {
02787 printf("Error: unable to read the %s keyword of level 1d data at target time %s\n",TRECS,timeBegin2);
02788 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
02789 }
02790 if(trec != TargetTime)
02791 {
02792 printf("Error: %s of a level 1d record is not equal to the target time %s\n",TRECS,timeBegin2);
02793 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
02794 }
02795 tobs = drms_getkey_time(recLev1d->records[0],TOBSS,&status);
02796 if(status != DRMS_SUCCESS)
02797 {
02798 printf("Error: unable to read the %s keyword of level 1d data at target time %s\n",TOBSS,timeBegin2);
02799 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
02800 }
02801
02802
02803
02804
02805
02806 TREC_EPOCH=drms_getkey_time(recLev1d->records[0],TRECEPOCHS,&status);
02807 if(TREC_EPOCH != TREC_EPOCH0)
02808 {
02809 printf("Error: TREC_EPOCH of level 1d data is not equal to the expected TREC_EPOCH: %f, at target time %s\n",TREC_EPOCH0,timeBegin2);
02810 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
02811 }
02812 TREC_STEP= drms_getkey_time(recLev1d->records[0],TRECSTEPS,&status);
02813 if(TREC_STEP != DataCadence)
02814 {
02815 printf("Error: the cadence is not equal to the T_REC_step keyword of the level 1d data, at target time %s\n",timeBegin2);
02816 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
02817 }
02818
02819 DRMS_SegmentDimInfo_t di;
02820 segin = drms_segment_lookupnum(recLev1d->records[0],0);
02821 status = drms_segment_getdims(segin,&di);
02822 if(status != DRMS_SUCCESS)
02823 {
02824 printf("Error: unable to read the dimensions of the data segment of level 1d data at target time %s\n",timeBegin2);
02825 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
02826 }
02827 axisin[0]= di.axis[0];
02828 axisin[1]= di.axis[1];
02829 axisout[0]=axisin[0];
02830 axisout[1]=axisin[1];
02831
02832 Segments1d=0;
02833 Segments1p=0;
02834 }
02835 else
02836 {
02837 printf("Unable to open the series %s for target time %s\n",HMISeries,timeBegin2);
02838 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
02839 }
02840 }
02841
02842
02843
02844
02845
02846
02847
02848
02849
02850
02851
02852 if ( TestLevIn[0]==1 )
02853 {
02854
02855 strcpy(source,HMISeriesLev10);
02856 strcat(source,"[:");
02857
02858
02859
02860
02861
02862 temptime = 100000000.0;
02863 i=TargetWavelength;
02864 while(fabs(internTOBS[IndexFiltergram[i]]-TargetTime) <= temptime)
02865 {
02866
02867 temptime=fabs(internTOBS[IndexFiltergram[i]]-TargetTime);
02868 if(i <= nIndexFiltergram-2) ++i;
02869 else break;
02870 }
02871 if(temptime > DataCadence/2.0 )
02872 {
02873 printf("Error: could not find a filtergram with the correct wavelength and close to the target time\n");
02874 QUALITY = QUALITY | QUAL_TARGETFILTERGRAMMISSING;
02875 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
02876 }
02877 TargetWavelength= i-1;
02878 temp = IndexFiltergram[TargetWavelength];
02879
02880
02881 if(TargetTime > 1145850460.469931 && TargetTime < 1146422026.006866)
02882 {
02883 printf("Warning: target time is within 6 days of the accidental reboot of HMI on April 24, 2013\n");
02884 QUALITY = QUALITY | QUAL_POORQUALITY;
02885 }
02886
02887
02888
02889 if((QUALITYin[temp] & Q_ACS_ISSLOOP) == Q_ACS_ISSLOOP)
02890 {
02891 QUALITY = QUALITY | QUAL_ISSTARGET ;
02892 QUALITY = QUALITY | QUAL_POORQUALITY;
02893 }
02894 if((QUALITYin[temp] & Q_ACS_ECLP) == Q_ACS_ECLP)
02895 {
02896 QUALITY = QUALITY | QUAL_ECLIPSE;
02897 QUALITY = QUALITY | QUAL_POORQUALITY;
02898 }
02899 if((QUALITYin[temp] & Q_ACS_NOLIMB) == Q_ACS_NOLIMB) QUALITY = QUALITY | QUAL_LIMBFITISSUE;
02900 if((QUALITYin[temp] & Q_ACS_LUNARTRANSIT) == Q_ACS_LUNARTRANSIT) QUALITY = QUALITY | QUAL_POORQUALITY;
02901 if((QUALITYin[temp] & Q_ACS_THERMALRECOVERY) == Q_ACS_THERMALRECOVERY) QUALITY = QUALITY | QUAL_POORQUALITY;
02902 if((QUALITYin[temp] & Q_CAMERA_ANOMALY) == Q_CAMERA_ANOMALY) QUALITY = QUALITY | QUAL_POORQUALITY;
02903 if(isnan(X0[temp]) || isnan(Y0[temp]))
02904 {
02905 printf("Error: target filtergram FSN[%d] does not have valid X0_LF and/or Y0_LF keywords\n",FSN[temp]);
02906 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
02907 QUALITY = QUALITY | QUAL_TARGETFILTERGRAMMISSING;
02908 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
02909 }
02910
02911
02912 if(SegmentRead[temp] == 0)
02913 {
02914
02915
02916
02917
02918
02919 if(inRotationalFlat == 1)
02920 {
02921
02922 HMIFlatField = (char *)malloc(MaxNString*sizeof(char *));
02923 if(HMIFlatField == NULL)
02924 {
02925 printf("Error: memory could not be allocated to HMIFlatField\n");
02926 return 1;
02927 }
02928
02929 HMIFlatField = drms_getkey_string(recLev1->records[temp],FLATREC,&status);
02930 if (status != DRMS_SUCCESS)
02931 {
02932 printf("Error: could not read the FLAT_REC keyword for the target filtergram FSN= %d",FSN[temp]);
02933 return 1;
02934 }
02935 else
02936 {
02937 printf("PZT FLAT FIELD USED ON TARGET FILTERGRAM= %s\n",HMIFlatField);
02938 if(initialrun == 1)
02939 {
02940 strcpy(HMIFlatField0,HMIFlatField);
02941
02942
02943 recflat = drms_open_records(drms_env,HMIFlatField,&status);
02944 if (status != DRMS_SUCCESS || recflat == NULL || recflat->n == 0)
02945 {
02946 printf("Error: record missing or corrupt for the flat field query %s\n",HMIFlatField);
02947 return 1;
02948 }
02949 segin = drms_segment_lookup(recflat->records[0],"flatfield");
02950 flatfield = drms_segment_read(segin,type1d,&status);
02951 if (status != DRMS_SUCCESS || flatfield == NULL)
02952 {
02953 printf("Error: could not read the data segment for the flat field query %s\n",HMIFlatField);
02954 return 1;
02955 }
02956 pztflat = flatfield->data;
02957 status=drms_close_records(recflat,DRMS_FREE_RECORD);
02958
02959
02960 char keylist[]="T_START,T_STOP";
02961 int unique = 0;
02962 rotationalflats = drms_record_getvector(drms_env,HMIRotationalFlats,keylist,DRMS_TYPE_DOUBLE,unique,&status);
02963 if(status != DRMS_SUCCESS)
02964 {
02965 printf("Error: cannot read a list of keywords in the rotation flat-field series\n");
02966 return 1;
02967 }
02968 printf("DIMENSIONS OF ROTATIONAL FLAT-FIELD SERIES= %d %d\n",rotationalflats->axis[0],rotationalflats->axis[1]);
02969 int n0,n1;
02970 n1 =rotationalflats->axis[1];
02971 n0 =rotationalflats->axis[0];
02972 keyF=rotationalflats->data;
02973
02974 i=0;
02975 while(TargetTime > keyF[i] && TargetTime > keyF[n1+i])
02976 {
02977 i++;
02978 }
02979
02980 if(TargetTime >= keyF[i] && TargetTime <= keyF[n1+i])
02981 {
02982
02983 TSTARTFLAT=keyF[i];
02984 TSTOPFLAT =keyF[n1+i];
02985 sprint_time(query,keyF[i],"TAI",1);
02986 strcpy(QueryFlatField,HMIRotationalFlats);
02987 strcat(QueryFlatField,"[");
02988 if(CamId == LIGHT_SIDE) strcat(QueryFlatField,"1");
02989 if(CamId == LIGHT_FRONT) strcat(QueryFlatField,"2");
02990 strcat(QueryFlatField,"][");
02991 strcat(QueryFlatField,query);
02992 strcat(QueryFlatField,"]");
02993 printf("QUERY FOR ROTATIONAL FLAT FIELD= %s\n",QueryFlatField);
02994
02995 recflatrot = drms_open_records(drms_env,QueryFlatField,&status);
02996 if (status != DRMS_SUCCESS || recflatrot == NULL || recflatrot->n == 0)
02997 {
02998 printf("Error: record missing or corrupt for the rotational flat field query %s\n",QueryFlatField);
02999 return 1;
03000 }
03001 segin = drms_segment_lookup(recflatrot->records[0],"flatfield");
03002 flatfieldrot = drms_segment_read(segin,type1d,&status);
03003 if (status != DRMS_SUCCESS || flatfieldrot == NULL)
03004 {
03005 printf("Error: could not read the data segment for the rotational flat field query %s\n",QueryFlatField);
03006 return 1;
03007 }
03008 rotflat = flatfieldrot->data;
03009
03010 }
03011 else
03012 {
03013 printf("Error: no rotational flat field record exists for the target time %s\n",timeBegin2);
03014 return 1;
03015 }
03016
03017 drms_free_array(rotationalflats);
03018 rotationalflats=NULL;
03019 }
03020 else if(strcmp(HMIFlatField,HMIFlatField0) != 0)
03021 {
03022 printf("Warning: the hmi.flatfield record used to produce the level 1 records changed during the run of the observables code\n");
03023 printf("The new hmi,flatfield record used is: %s\n",HMIFlatField);
03024
03025 recflat = drms_open_records(drms_env,HMIFlatField,&status);
03026 if (status != DRMS_SUCCESS || recflat == NULL || recflat->n == 0)
03027 {
03028 printf("Error: record missing or corrupt for the flat field query %s\n",HMIFlatField);
03029 return 1;
03030 }
03031 drms_free_array(flatfield);
03032 strcpy(HMIFlatField0,HMIFlatField);
03033 segin = drms_segment_lookup(recflat->records[0],"flatfield");
03034 flatfield = drms_segment_read(segin,type1d,&status);
03035 if (status != DRMS_SUCCESS || flatfield == NULL)
03036 {
03037 printf("Error: could not read the data segment for the flat field query %s\n",HMIFlatField);
03038 return 1;
03039 }
03040 pztflat = flatfield->data;
03041 status=drms_close_records(recflat,DRMS_FREE_RECORD);
03042 }
03043
03044 }
03045 free(HMIFlatField);
03046 }
03047
03048
03049
03050
03051
03052 printf("READ SEGMENT OF TARGET FILTERGRAM\n");
03053 segin = drms_segment_lookupnum(recLev1->records[temp],0);
03054 Segments[temp] = drms_segment_read(segin,type1d, &status);
03055 if (status != DRMS_SUCCESS || Segments[temp] == NULL)
03056 {
03057 printf("Error: the code could not read the segment of the level 1 filtergram %d\n",FSN[temp]);
03058 return 1;
03059
03060
03061
03062
03063 }
03064 }
03065
03066 if(SegmentRead[temp] == -1)
03067 {
03068
03069 image = NULL;
03070 }
03071 else
03072 {
03073 image = Segments[temp]->data;
03074 }
03075
03076 printf("FSN OF TARGET FILTERGRAM = %d %d\n",FSN[temp],HCAMID[temp]);
03077 if(internTOBS[temp] > TargetTime) printf("Target filtergram is after target time\n");
03078 else printf("Target filtergram is before target time\n");
03079
03080 TargetHFLID = HFLID[temp];
03081 if(TargetHFLID >= 4000) QUALITY = QUALITY | QUAL_LARGEFTSID;
03082 TargetHWLPOS[0] = HWL1POS[temp];
03083 TargetHWLPOS[1] = HWL2POS[temp];
03084 TargetHWLPOS[2] = HWL3POS[temp];
03085 TargetHWLPOS[3] = HWL4POS[temp];
03086 TargetHPLPOS[0] = HPL1POS[temp];
03087 TargetHPLPOS[1] = HPL2POS[temp];
03088 TargetHPLPOS[2] = HPL3POS[temp];
03089 TargetCFINDEX = CFINDEX[temp];
03090 TargetHWLTID = HWLTID[temp];
03091 TargetHPLTID = HPLTID[temp];
03092 TargetFID = FID[temp];
03093
03094
03095 combineornot = framelistCombine(TargetHFLID, CamId, &combineYesNo, dpath);
03096 printf("combineornot=%d, combine=%d\n", combineornot, combineYesNo);
03097
03098
03099
03100 if(isnan(X0[temp]) || isnan(Y0[temp]))
03101 {
03102 printf("Error: target filtergram FSN[%d] does not have valid X0_LF and/or Y0_LF keywords\n",FSN[temp]);
03103 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
03104 QUALITY = QUALITY | QUAL_TARGETFILTERGRAMMISSING;
03105 CreateEmptyRecord=1; goto NextTargetTime;
03106 }
03107
03108
03109
03110 strcpy(TargetISS,HWLTNSET[temp]);
03111 printf("ISS STATUS OF TARGET FILTERGRAM: %s\n",TargetISS);
03112 if(!strcmp(TargetISS,"OPEN")) QUALITY = QUALITY | QUAL_ISSTARGET;
03113 if( (QUALITYin[temp] & Q_ACS_ECLP) == Q_ACS_ECLP) QUALITY = QUALITY | QUAL_ECLIPSE;
03114
03115 axisin[0] = 4096;
03116 axisin[1] = 4096;
03117 axisout[0] = axisin[0];
03118 axisout[1] = axisin[1];
03119 Nelem = axisin[0]*axisin[1];
03120
03121
03122
03123
03124
03125
03126 i=IndexFiltergram[TargetWavelength];
03127 j=i;
03128
03129 if(internTOBS[IndexFiltergram[TargetWavelength]] < TargetTime && TargetWavelength < nIndexFiltergram-1)
03130 {
03131 j=TargetWavelength;
03132 while(internTOBS[IndexFiltergram[j]] < TargetTime && j < nIndexFiltergram-1 && fabs(internTOBS[IndexFiltergram[j]]-internTOBS[i]) <= 2.1*DataCadence) j++;
03133 if(fabs(internTOBS[IndexFiltergram[j]]-internTOBS[i]) > 2.1*DataCadence) j=i;
03134 else j=IndexFiltergram[j];
03135 }
03136 if(internTOBS[IndexFiltergram[TargetWavelength]] >= TargetTime && TargetWavelength > 0)
03137 {
03138 j=TargetWavelength;
03139 while(internTOBS[IndexFiltergram[j]] >= TargetTime && j > 0 && fabs(internTOBS[IndexFiltergram[j]]-internTOBS[i]) <= 2.1*DataCadence) --j;
03140 if(fabs(internTOBS[IndexFiltergram[j]]-internTOBS[i]) > 2.1*DataCadence) j=i;
03141 else
03142 {
03143 i=IndexFiltergram[j];
03144 j=IndexFiltergram[TargetWavelength];
03145 }
03146 }
03147
03148
03149 if(i == j)
03150 {
03151 QUALITY = QUALITY | QUAL_LOWKEYWORDNUM;
03152 if(TargetWavelength>=1 && TargetWavelength<nIndexFiltergram-1)
03153 {
03154 i=IndexFiltergram[TargetWavelength-1];
03155 j=IndexFiltergram[TargetWavelength+1];
03156 }
03157 if(TargetWavelength>=1 && TargetWavelength == nIndexFiltergram-1 )
03158 {
03159 i=IndexFiltergram[TargetWavelength-1];
03160 j=IndexFiltergram[TargetWavelength];
03161 }
03162 if(TargetWavelength<nIndexFiltergram-1 && TargetWavelength == 0)
03163 {
03164 i=IndexFiltergram[TargetWavelength];
03165 j=IndexFiltergram[TargetWavelength+1];
03166 }
03167 }
03168
03169
03170 if(KeywordMissing[j] == 1 || KeywordMissing[i] == 1)
03171 {
03172 printf("Error: some keywords are missing/corrupted to interpolate OBS_VR, OBS_VW, OBS_VN, CRLN_OBS, CROTA2, and CAR_ROT at target time %s \n",timeBegin2);
03173 if(SegmentRead[temp])
03174 {
03175 drms_free_array(Segments[temp]);
03176 Segments[temp]=NULL;
03177 if(Ierror[temp] != NULL) drms_free_array(Ierror[temp]);
03178 Ierror[temp]=NULL;
03179 SegmentRead[temp]=0;
03180 }
03181 QUALITY = QUALITY | QUAL_NOINTERPOLATEDKEYWORDS;
03182 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
03183 }
03184
03185
03186
03187
03188
03189 if(i != j)
03190 {
03191 DSUNOBSint=(DSUNOBS[j]-DSUNOBS[i])/(internTOBS[j]-internTOBS[i])*(TargetTime-internTOBS[i])+DSUNOBS[i];
03192 DSUNOBSint=DSUNOBSint/(double)AstroUnit;
03193 }
03194 else
03195 {
03196 DSUNOBSint=DSUNOBS[i];
03197 DSUNOBSint=DSUNOBSint/(double)AstroUnit;
03198 }
03199
03200
03201 tobs = TargetTime+(DSUNOBSint-1.0)/2.00398880422056639358e-03;
03202
03203
03204
03205 if(i != j)
03206 {
03207 printf("FSNs used for interpolation of OBS_VR, OBS_VW, OBS_VN, CRLN_OBS, CROTA2, and CAR_ROT: %d %d %d %d\n",FSN[j],FSN[i],HCAMID[j],HCAMID[i]);
03208
03209 DSUNOBSint=(DSUNOBS[j]-DSUNOBS[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+DSUNOBS[i];
03210 DSUNOBSint=DSUNOBSint/(double)AstroUnit;
03211 CRLTOBSint=(CRLTOBS[j]-CRLTOBS[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+CRLTOBS[i];
03212
03213
03214 CROTA2int = atan2(sin((CROTA2[j]-CROTA2[i])/180.0*M_PI), cos((CROTA2[j]-CROTA2[i])/180.0*M_PI)) /
03215 (internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])*180.0/M_PI+CROTA2[i];
03216 CROTA2int = fmod(CROTA2int, 360.0);
03217
03218 OBSVRint =(OBSVR[j]-OBSVR[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+OBSVR[i];
03219 OBSVWint =(OBSVW[j]-OBSVW[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+OBSVW[i];
03220 OBSVNint =(OBSVN[j]-OBSVN[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+OBSVN[i];
03221 ctime1 =-CRLNOBS[i];
03222 ctime2 =360.0*(float)(CARROT[j]-CARROT[i])-CRLNOBS[j];
03223 CRLNOBSint=(ctime2-ctime1)/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+ctime1;
03224 if(CARROT[j] > CARROT[i])
03225 {
03226 if(CRLNOBSint > 0.0)
03227 {
03228 CRLNOBSint = 360.0 - CRLNOBSint;
03229 CARROTint = CARROT[j];
03230 }
03231 else
03232 {
03233 CRLNOBSint = -CRLNOBSint;
03234 CARROTint = CARROT[i];
03235 }
03236 }
03237 else
03238 {
03239 CRLNOBSint = -CRLNOBSint;
03240 CARROTint = CARROT[i];
03241 }
03242
03243 }
03244 else
03245 {
03246 printf("FSN used for interpolation of OBS_VR, OBS_VW, OBS_VN, CRLN_OBS, CROTA2, and CAR_ROT: %d %d\n",FSN[i],HCAMID[i]);
03247
03248 DSUNOBSint=DSUNOBS[i];
03249 DSUNOBSint=DSUNOBSint/(double)AstroUnit;
03250 CRLTOBSint=CRLTOBS[i];
03251 CROTA2int =CROTA2[i];
03252 OBSVRint =OBSVR[i];
03253 OBSVWint =OBSVW[i];
03254 OBSVNint =OBSVN[i];
03255 CRLNOBSint=CRLNOBS[i];
03256 CARROTint =CARROT[i];
03257
03258 QUALITY = QUALITY | QUAL_LOWKEYWORDNUM;
03259 }
03260
03261
03262
03263
03264
03265
03266 Mask = (unsigned char *)malloc(Nelem*sizeof(unsigned char));
03267 if(Mask == NULL)
03268 {
03269 printf("Error: cannot allocate memory for Mask\n");
03270 return 1;
03271 }
03272
03273
03274
03275
03276
03277
03278
03279
03280
03281
03282
03283
03284
03285
03286 if(SegmentRead[temp] == 0 && image != NULL)
03287 {
03288
03289 if(inRotationalFlat == 1)
03290 {
03291 if(inLinearity == 1)
03292 {
03293 printf("applying rotational flat field and correcting for non-linearity of camera on record FSN=%d\n",FSN[temp]);
03294 for(i=0;i<axisin[0]*axisin[1];++i)
03295 {
03296
03297 image[i]=(image[i]*pztflat[i])/rotflat[i];
03298
03299 tempvalue = image[i]*EXPTIME[temp];
03300 if(HCAMID[temp] == LIGHT_FRONT) tempvalue = (nonlinf[0]+nonlinf[1]*tempvalue+nonlinf[2]*tempvalue*tempvalue+nonlinf[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
03301 else tempvalue = (nonlins[0]+nonlins[1]*tempvalue+nonlins[2]*tempvalue*tempvalue+nonlins[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
03302 image[i] = tempvalue/EXPTIME[temp];
03303 }
03304 }
03305 else
03306 {
03307 printf("applying rotational flat field on record FSN=%d\n",FSN[temp]);
03308 for(i=0;i<axisin[0]*axisin[1];++i)
03309 {
03310
03311 image[i]=(image[i]*pztflat[i])/rotflat[i];
03312 }
03313 }
03314 }
03315 else
03316 {
03317 if(inLinearity == 1)
03318 {
03319 printf("correcting for non-linearity of camera on record FSN=%d\n",FSN[temp]);
03320 for(i=0;i<axisin[0]*axisin[1];++i)
03321 {
03322
03323 tempvalue = image[i]*EXPTIME[temp];
03324 if(HCAMID[temp] == LIGHT_FRONT) tempvalue = (nonlinf[0]+nonlinf[1]*tempvalue+nonlinf[2]*tempvalue*tempvalue+nonlinf[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
03325 else tempvalue = (nonlins[0]+nonlins[1]*tempvalue+nonlins[2]*tempvalue*tempvalue+nonlins[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
03326 image[i] = tempvalue/EXPTIME[temp];
03327 }
03328 }
03329 }
03330
03331
03332
03333 segin = drms_segment_lookup(recLev1->records[temp],"bad_pixel_list");
03334 printf("READ BAD PIXEL LIST OF TARGET FILTERGRAM FSN = %d\n",FSN[temp]);
03335 BadPixels = NULL;
03336 BadPixels = drms_segment_read(segin,segin->info->type,&status);
03337 if(status != DRMS_SUCCESS || BadPixels == NULL)
03338 {
03339 printf("Error: cannot read the list of bad pixels of level 1 filtergram FSN = %d at target time %s \n",FSN[temp],timeBegin2);
03340 return 1;
03341
03342
03343
03344
03345 }
03346 else
03347 {
03348
03349
03350 strcpy(HMISeriesTemp,CosmicRaySeries);
03351 strcat(HMISeriesTemp,"[][");
03352 sprintf(FSNtemps,"%d",FSN[temp]);
03353 strcat(HMISeriesTemp,FSNtemps);
03354 strcat(HMISeriesTemp,"]");
03355 rectemp=NULL;
03356
03357 rectemp=drms_open_records(drms_env,HMISeriesTemp,&statusA[0]);
03358 if(statusA[0] == DRMS_SUCCESS && rectemp != NULL && rectemp->n != 0)
03359 {
03360 segin = drms_segment_lookupnum(rectemp->records[0],0);
03361 CosmicRays = NULL;
03362
03363 COSMICCOUNT=drms_getkey_int(rectemp->records[0],COUNTS,&status);
03364 if(status != DRMS_SUCCESS || COSMICCOUNT == -1)
03365 {
03366 QUALITY = QUALITY | QUAL_NOCOSMICRAY;
03367 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
03368 }
03369 else
03370 {
03371 CosmicRays = drms_segment_read(segin,segin->info->type,&status);
03372 if(status != DRMS_SUCCESS || CosmicRays == NULL)
03373 {
03374 printf("Error: the list of cosmic-ray hits could not be read for FSN %d\n",FSN[temp]);
03375 return 1;
03376
03377
03378 QUALITY = QUALITY | QUAL_NOCOSMICRAY;
03379 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
03380 CosmicRays = NULL;
03381
03382 }
03383 }
03384
03385 }
03386 else
03387 {
03388 printf("Unable to open the series %s for FSN %d\n",HMISeriesTemp,FSN[temp]);
03389
03390
03391
03392 QUALITY = QUALITY | QUAL_NOCOSMICRAY;
03393 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
03394 CosmicRays = NULL;
03395
03396 }
03397
03398 printf("CREATING MASK FOR GAP-FILLING OF TARGET FILTERGAM\n");
03399 status = MaskCreation(Mask,axisin[0],axisin[1],BadPixels,HIMGCFID[temp],image,CosmicRays,NBADPERM[temp]);
03400 if(status == 1) return 1;
03401
03402 if(BadPixels != NULL)
03403 {
03404 drms_free_array(BadPixels);
03405 BadPixels=NULL;
03406 }
03407 if(CosmicRays != NULL)
03408 {
03409 drms_free_array(CosmicRays);
03410 CosmicRays=NULL;
03411 }
03412 if(rectemp != NULL)
03413 {
03414 drms_close_records(rectemp,DRMS_FREE_RECORD);
03415 rectemp=NULL;
03416 }
03417
03418
03419 if(status != 0)
03420 {
03421 printf("Error: unable to create a mask for the gap filling function for level 1 filtergram FSN = %d at target time %s\n",FSN[temp],timeBegin2);
03422 drms_free_array(Segments[temp]);
03423 Segments[temp]=NULL;
03424 SegmentRead[temp]=-1;
03425
03426 }
03427 else
03428 {
03429 Ierror[temp] = drms_array_create(typeEr,2,axisout,NULL,&status);
03430 if(status != DRMS_SUCCESS || Ierror[temp] == NULL)
03431 {
03432 printf("Error: unable to create an array for Ierror at target time %s\n",timeBegin2);
03433 drms_free_array(Segments[temp]);
03434 Segments[temp]=NULL;
03435 Ierror[temp]=NULL;
03436 SegmentRead[temp]=-1;
03437
03438 }
03439 else
03440 {
03441 ierror = Ierror[temp]->data;
03442 printf("GAP FILLING THE TARGET FILTERGRAM\n");
03443 t0=dsecnd();
03444 status = do_gapfill(image,Mask,&const_param,ierror,axisin[0],axisin[1]);
03445 t1=dsecnd();
03446 printf("TIME ELAPSED TO GAPFILL: %f\n",t1-t0);
03447 if(status != 0)
03448 {
03449 printf("Error: gapfilling code did not work on the level 1 filtergram FSN = %d at target time %s\n",FSN[temp],timeBegin2);
03450 QUALITY = QUALITY | QUAL_NOGAPFILL;
03451 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOGAPFILL;
03452 }
03453 SegmentRead[temp]=1;
03454 }
03455 }
03456 }
03457 }
03458
03459
03460
03461
03462
03463
03464 printf("GET INFORMATION ABOUT THE FRAMELIST\n");
03465 framelistSize = framelistInfo(TargetHFLID,TargetHPLTID,TargetHWLTID,WavelengthID,PHWPLPOS,WavelengthIndex,WavelengthLocation,&PolarizationType,CamId,&combine,&npol,MaxNumFiltergrams,&CadenceRead,CameraValues,FIDValues,dpath);
03466 if(framelistSize == 1) return 1;
03467
03468 printf("INFORMATION REGARDING THE FRAMELIST\n");
03469 printf("CamId= %d ; framelistSize= %d ; PolarizationType= %d ; combine cameras= %d ; npol= %d ; cadence=%f\n",CamId,framelistSize,PolarizationType,combine,npol,CadenceRead);
03470 printf("Framelist= ");
03471 for(i=0;i<framelistSize;++i) printf("I%d ",WavelengthIndex[i]);
03472 printf("\nLocation= ");
03473 for(i=0;i<framelistSize;++i) printf(" %d ",WavelengthLocation[i]);
03474 printf("\nPHWPLPOS \n");
03475 for(i=0;i<framelistSize;++i) printf("%d %d %d %d %d %d %d \n",PHWPLPOS[i*7],PHWPLPOS[i*7+1],PHWPLPOS[i*7+2],PHWPLPOS[i*7+3],PHWPLPOS[i*7+4],PHWPLPOS[i*7+5],PHWPLPOS[i*7+6]);
03476 printf("CAMERA ORDER\n");
03477 for(i=0;i<framelistSize;++i) printf(" %d ",CameraValues[i]);
03478 printf("\nFID ORDER\n");
03479 for(i=0;i<framelistSize;++i) printf(" %d ",FIDValues[i]);
03480 printf("\n");
03481
03482 if(framelistSize == 0)
03483 {
03484 printf("Error: cannot obtain information regarding the framelist for the level 1 filtergram FSN = %d at target time %s\n",FSN[temp],timeBegin2);
03485 QUALITY = QUALITY | QUAL_NOFRAMELISTINFO;
03486 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
03487 }
03488
03489 if(CadenceRead != DataCadence)
03490 {
03491 printf("Error: the cadence from the current framelist for the level 1 filtergram FSN = %d at target time %s is %f and does not match the cadence entered on the command line %f \n",FSN[temp],timeBegin2,CadenceRead,DataCadence);
03492 QUALITY = QUALITY | QUAL_WRONGCADENCE;
03493 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
03494 }
03495
03496
03497
03498
03499
03500 if (Lev1dWanted) recLev1d = drms_create_records(drms_env,framelistSize,HMISeriesLev1d,DRMS_PERMANENT,&status);
03501 else recLev1d = drms_create_records(drms_env,framelistSize,HMISeriesLev1d,DRMS_TRANSIENT,&status);
03502
03503 if(status != DRMS_SUCCESS || recLev1d == NULL || recLev1d->n < framelistSize)
03504 {
03505 printf("Error: cannot create records for the level 1d data %s at target time %s\n",HMISeriesLev1d,timeBegin2);
03506
03507
03508 return 1;
03509 }
03510 nRecs1d = framelistSize;
03511 Segments1d= 0;
03512 Segments1p= 0;
03513
03514
03515 CameraID = (int *)malloc(framelistSize * sizeof(int *));
03516
03517
03518 TREC_EPOCH= drms_getkey_time(recLev1d->records[0],TRECEPOCHS,&status);
03519 if(status != DRMS_SUCCESS)
03520 {
03521 printf("Error: unable to read the %s keyword for level 1d data at target time %s\n",TRECEPOCHS,timeBegin2);
03522 return 1;
03523 }
03524 TREC_STEP= drms_getkey_time(recLev1d->records[0],TRECSTEPS,&status);
03525 if(status != DRMS_SUCCESS)
03526 {
03527 printf("Error: unable to read the keyword %s for level 1d data at target time %s\n",TRECSTEPS,timeBegin2);
03528 return 1;
03529 }
03530 if(TREC_STEP != DataCadence)
03531 {
03532 printf("Error: the cadence = %f is not equal to the T_REC_step = %f keyword of the level 1d data at target time %s\n",DataCadence,TREC_STEP,timeBegin2);
03533 return 1;
03534 }
03535 if(TREC_EPOCH != TREC_EPOCH0)
03536 {
03537 printf("Error: TREC_EPOCH= %f is not equal to the expected TREC_EPOCH = %f, at target time %s\n",TREC_EPOCH,TREC_EPOCH0,timeBegin2);
03538 return 1;
03539 }
03540
03541 trec = TargetTime;
03542
03543
03544
03545
03546 temp=-1;
03547
03548
03549 for(i=0;i<framelistSize;++i) if(WavelengthIndex[i] == WavelengthID && PHWPLPOS[i*7+4] == TargetHPLPOS[0] && PHWPLPOS[i*7+5] == TargetHPLPOS[1] && PHWPLPOS[i*7+6] == TargetHPLPOS[2] && FIDValues[i] == TargetFID) temp=i;
03550 if(temp == -1)
03551 {
03552 printf("Error: the target filtergram does not match any frame of the corresponding framelist\n");
03553 QUALITY = QUALITY | QUAL_WRONGTARGET;
03554 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
03555 }
03556 temp=WavelengthLocation[temp];
03557
03558 OrganizeFramelist =(int *)malloc(framelistSize*sizeof(int));
03559 if(OrganizeFramelist == NULL)
03560 {
03561 printf("Error: memory could not be allocated to OrganizeFramelist\n");
03562 return 1;
03563 }
03564 OrganizeFramelist2=(int *)malloc(framelistSize*sizeof(int));
03565 if(OrganizeFramelist2 == NULL)
03566 {
03567 printf("Error: memory could not be allocated to OrganizeFramelist2\n");
03568 return 1;
03569 }
03570
03571 OrganizeFramelist[0]=WavelengthLocation[0]-temp;
03572 OrganizeFramelist2[0]=-1;
03573 for(i=1;i<framelistSize;++i)
03574 {
03575 OrganizeFramelist[i]=WavelengthLocation[i]-temp;
03576 OrganizeFramelist2[i]=signj(OrganizeFramelist[i]);
03577 for(k=0;k<i;++k) if(WavelengthIndex[i] == WavelengthIndex[k]) OrganizeFramelist2[i]= OrganizeFramelist2[k];
03578 }
03579
03580
03581 printf("ORGANIZE FRAMELIST: \n");
03582 for(i=0;i<framelistSize;++i) printf("%d ",OrganizeFramelist[i]);
03583 printf("\n ORGANIZE FRAMELIST2: \n");
03584 for(i=0;i<framelistSize;++i) printf("%d ",OrganizeFramelist2[i]);
03585 printf("\n");
03586
03587
03588
03589
03590
03591
03592
03593 if(TempIntNum > 2) MaxSearchDistanceL=(TIME)(TempIntNum/2-1)*DataCadence+TimeCaution;
03594 MaxSearchDistanceR=(TIME)(TempIntNum/2) *DataCadence+TimeCaution;
03595 FramelistArray = (int *)malloc(framelistSize*TempIntNum*sizeof(int));
03596 if(FramelistArray == NULL)
03597 {
03598 printf("Error: memory could not be allocated to FramelistArray\n");
03599 return 1;
03600 }
03601
03602 for(i=0;i<framelistSize;++i)
03603 {
03604
03605
03606
03607
03608
03609 camera=CameraValues[i];
03610 fidfilt=FIDValues[i];
03611 printf("FID value in framelist: %d\n",fidfilt);
03612
03613 FiltergramLocation=IndexFiltergram[TargetWavelength]+OrganizeFramelist[i];
03614 k=FiltergramLocation;
03615
03616 if(KeywordMissing[k] == 1)
03617 {
03618 FramelistArray[i]=-1;
03619 printf("Error: the filtergram index %d has missing keywords and the code cannot identify it",k);
03620 }
03621 else
03622 {
03623
03624 if(HWL1POS[k] != PHWPLPOS[i*7] || HWL2POS[k] != PHWPLPOS[i*7+1] || HWL3POS[k] != PHWPLPOS[i*7+2] || HWL4POS[k] != PHWPLPOS[i*7+3] || HPL1POS[k] != PHWPLPOS[i*7+4] || HPL2POS[k] != PHWPLPOS[i*7+5] || HPL3POS[k] != PHWPLPOS[i*7+6] || HCAMID[k] != camera || CFINDEX[k] != TargetCFINDEX || FID[k] != fidfilt)
03625
03626
03627 {
03628 printf("Warning: a filtergram near the target location is not what it should be. Looking for the correct filtergram\n");
03629 FiltergramLocation=IndexFiltergram[TargetWavelength];
03630 for(ii=1;ii<framelistSize;++ii)
03631 {
03632 if(OrganizeFramelist[i] > 0)
03633 {
03634 k=FiltergramLocation+ii;
03635 if(k < nRecs1 && KeywordMissing[k] != 1)
03636 {
03637 if(HWL1POS[k] == PHWPLPOS[i*7] && HWL2POS[k] == PHWPLPOS[i*7+1] && HWL3POS[k] == PHWPLPOS[i*7+2] && HWL4POS[k] == PHWPLPOS[i*7+3] && HPL1POS[k] == PHWPLPOS[i*7+4] && HPL2POS[k] == PHWPLPOS[i*7+5] && HPL3POS[k] == PHWPLPOS[i*7+6] && HCAMID[k] == camera && CFINDEX[k] == TargetCFINDEX && FID[k] == fidfilt) break;
03638
03639 }
03640 }
03641 else
03642 {
03643 k=FiltergramLocation-ii;
03644 if(k > 0 && KeywordMissing[k] != 1)
03645 {
03646
03647 if(HWL1POS[k] == PHWPLPOS[i*7] && HWL2POS[k] == PHWPLPOS[i*7+1] && HWL3POS[k] == PHWPLPOS[i*7+2] && HWL4POS[k] == PHWPLPOS[i*7+3] && HPL1POS[k] == PHWPLPOS[i*7+4] && HPL2POS[k] == PHWPLPOS[i*7+5] && HPL3POS[k] == PHWPLPOS[i*7+6] && HCAMID[k] == camera && CFINDEX[k] == TargetCFINDEX && FID[k] == fidfilt) break;
03648 }
03649 }
03650 }
03651 if(ii == framelistSize)
03652 {
03653 FiltergramLocation=IndexFiltergram[TargetWavelength]+OrganizeFramelist[i];
03654 printf("Error: the filtergram FSN = %d is not what it should be\n",FSN[FiltergramLocation]);
03655 FramelistArray[i]=-1;
03656 }
03657 else
03658 {
03659 FramelistArray[i]=k;
03660 FiltergramLocation=k;
03661 }
03662 }
03663 else FramelistArray[i]=k;
03664 }
03665
03666
03667
03668
03669
03670 if(OrganizeFramelist2[i] <= 0)
03671 {
03672
03673 if(TempIntNum > 2)
03674 {
03675 k=FiltergramLocation-1;
03676 for(ii=1;ii<=TempIntNum/2-1;++ii)
03677 {
03678 while(k > 0)
03679 {
03680 if(KeywordMissing[k] != 1)
03681 {
03682
03683 if(HWL1POS[k] != PHWPLPOS[i*7] || HWL2POS[k] != PHWPLPOS[i*7+1] || HWL3POS[k] != PHWPLPOS[i*7+2] || HWL4POS[k] != PHWPLPOS[i*7+3] || HPL1POS[k] != PHWPLPOS[i*7+4] || HPL2POS[k] != PHWPLPOS[i*7+5] || HPL3POS[k] != PHWPLPOS[i*7+6] || HCAMID[k] != camera || CFINDEX[k] != TargetCFINDEX || FID[k] != fidfilt)
03684 {
03685 if ((internTOBS[k]-TargetTime) >= -MaxSearchDistanceL) --k;
03686 else break;
03687 }
03688 else break;
03689 }
03690 else --k;
03691 }
03692 if(k < 0)
03693 {
03694 FramelistArray[i+framelistSize*ii]=-1;
03695 continue;
03696 }
03697 if(KeywordMissing[k] != 1)
03698 {
03699
03700 if(HWL1POS[k] == PHWPLPOS[i*7] && HWL2POS[k] == PHWPLPOS[i*7+1] && HWL3POS[k] == PHWPLPOS[i*7+2] && HWL4POS[k] == PHWPLPOS[i*7+3] && HPL1POS[k] == PHWPLPOS[i*7+4] && HPL2POS[k] == PHWPLPOS[i*7+5] && HPL3POS[k] == PHWPLPOS[i*7+6] && HCAMID[k] == camera && CFINDEX[k] == TargetCFINDEX && (internTOBS[k]-TargetTime) >= -MaxSearchDistanceL && FID[k] == fidfilt)
03701 {
03702 FramelistArray[i+framelistSize*ii]=k;
03703 }
03704 else FramelistArray[i+framelistSize*ii]=-1;
03705 }
03706 else FramelistArray[i+framelistSize*ii]=-1;
03707 --k;
03708 }
03709 }
03710 k=FiltergramLocation+1;
03711 for(ii=TempIntNum/2;ii<TempIntNum;++ii)
03712 {
03713 while(k < nRecs1-1)
03714 {
03715 if(KeywordMissing[k] != 1)
03716 {
03717
03718 if(HWL1POS[k] != PHWPLPOS[i*7] || HWL2POS[k] != PHWPLPOS[i*7+1] || HWL3POS[k] != PHWPLPOS[i*7+2] || HWL4POS[k] != PHWPLPOS[i*7+3] || HPL1POS[k] != PHWPLPOS[i*7+4] || HPL2POS[k] != PHWPLPOS[i*7+5] || HPL3POS[k] != PHWPLPOS[i*7+6] || HCAMID[k] != camera || CFINDEX[k] != TargetCFINDEX || FID[k] != fidfilt)
03719 {
03720 if ((internTOBS[k]-TargetTime) <= MaxSearchDistanceR) ++k;
03721 else break;
03722 }
03723 else break;
03724 }
03725 else ++k;
03726 }
03727 if(k > nRecs1-1)
03728 {
03729 FramelistArray[i+framelistSize*ii]=-1;
03730 continue;
03731 }
03732 if(KeywordMissing[k] != 1)
03733 {
03734
03735 if(HWL1POS[k] == PHWPLPOS[i*7] && HWL2POS[k] == PHWPLPOS[i*7+1] && HWL3POS[k] == PHWPLPOS[i*7+2] && HWL4POS[k] == PHWPLPOS[i*7+3] && HPL1POS[k] == PHWPLPOS[i*7+4] && HPL2POS[k] == PHWPLPOS[i*7+5] && HPL3POS[k] == PHWPLPOS[i*7+6] && HCAMID[k] == camera && CFINDEX[k] == TargetCFINDEX && (internTOBS[k]-TargetTime) <= MaxSearchDistanceR && FID[k] == fidfilt)
03736 {
03737 FramelistArray[i+framelistSize*ii]=k;
03738 }
03739 else FramelistArray[i+framelistSize*ii]=-1;
03740 }
03741 else FramelistArray[i+framelistSize*ii]=-1;
03742 ++k;
03743 }
03744 }
03745 else
03746 {
03747
03748 k=FiltergramLocation-1;
03749 for(ii=1;ii<=TempIntNum/2;++ii)
03750 {
03751 while(k > 0)
03752 {
03753 if(KeywordMissing[k] != 1)
03754 {
03755
03756 if(HWL1POS[k] != PHWPLPOS[i*7] || HWL2POS[k] != PHWPLPOS[i*7+1] || HWL3POS[k] != PHWPLPOS[i*7+2] || HWL4POS[k] != PHWPLPOS[i*7+3] || HPL1POS[k] != PHWPLPOS[i*7+4] || HPL2POS[k] != PHWPLPOS[i*7+5] || HPL3POS[k] != PHWPLPOS[i*7+6] || HCAMID[k] != camera || CFINDEX[k] != TargetCFINDEX || FID[k] != fidfilt)
03757 {
03758 if ((internTOBS[k]-TargetTime) >= -MaxSearchDistanceR) --k;
03759 else break;
03760 }
03761 else break;
03762 }
03763 else --k;
03764 }
03765 if(k < 0)
03766 {
03767 FramelistArray[i+framelistSize*ii]=-1;
03768 continue;
03769 }
03770 if(KeywordMissing[k] != 1)
03771 {
03772
03773 if(HWL1POS[k] == PHWPLPOS[i*7] && HWL2POS[k] == PHWPLPOS[i*7+1] && HWL3POS[k] == PHWPLPOS[i*7+2] && HWL4POS[k] == PHWPLPOS[i*7+3] && HPL1POS[k] == PHWPLPOS[i*7+4] && HPL2POS[k] == PHWPLPOS[i*7+5] && HPL3POS[k] == PHWPLPOS[i*7+6] && HCAMID[k] == camera && CFINDEX[k] == TargetCFINDEX && (internTOBS[k]-TargetTime) >= -MaxSearchDistanceR && FID[k] == fidfilt)
03774 {
03775 FramelistArray[i+framelistSize*ii]=k;
03776 }
03777 else FramelistArray[i+framelistSize*ii]=-1;
03778 }
03779 else FramelistArray[i+framelistSize*ii]=-1;
03780 --k;
03781 }
03782 if( TempIntNum > 2)
03783 {
03784 k=FiltergramLocation+1;
03785 for(ii=TempIntNum/2+1;ii<TempIntNum;++ii)
03786 {
03787 while(k < nRecs1-1)
03788 {
03789 if(KeywordMissing[k] != 1)
03790 {
03791
03792 if(HWL1POS[k] != PHWPLPOS[i*7] || HWL2POS[k] != PHWPLPOS[i*7+1] || HWL3POS[k] != PHWPLPOS[i*7+2] || HWL4POS[k] != PHWPLPOS[i*7+3] || HPL1POS[k] != PHWPLPOS[i*7+4] || HPL2POS[k] != PHWPLPOS[i*7+5] || HPL3POS[k] != PHWPLPOS[i*7+6] || HCAMID[k] != camera || CFINDEX[k] != TargetCFINDEX || FID[k] != fidfilt)
03793 {
03794 if ((internTOBS[k]-TargetTime) <= MaxSearchDistanceL) ++k;
03795 else break;
03796 }
03797 else break;
03798 }
03799 else ++k;
03800 }
03801 if(k > nRecs1-1)
03802 {
03803 FramelistArray[i+framelistSize*ii]=-1;
03804 continue;
03805 }
03806 if(KeywordMissing[k] != 1)
03807 {
03808
03809 if(HWL1POS[k] == PHWPLPOS[i*7] && HWL2POS[k] == PHWPLPOS[i*7+1] && HWL3POS[k] == PHWPLPOS[i*7+2] && HWL4POS[k] == PHWPLPOS[i*7+3] && HPL1POS[k] == PHWPLPOS[i*7+4] && HPL2POS[k] == PHWPLPOS[i*7+5] && HPL3POS[k] == PHWPLPOS[i*7+6] && HCAMID[k] == camera && CFINDEX[k] == TargetCFINDEX && (internTOBS[k]-TargetTime) <= MaxSearchDistanceL && FID[k] == fidfilt)
03810 {
03811 FramelistArray[i+framelistSize*ii]=k;
03812 }
03813 else FramelistArray[i+framelistSize*ii]=-1;
03814 }
03815 else FramelistArray[i+framelistSize*ii]=-1;
03816 ++k;
03817 }
03818 }
03819 }
03820
03821 }
03822
03823
03824 free(OrganizeFramelist);
03825 free(OrganizeFramelist2);
03826 OrganizeFramelist=NULL;
03827 OrganizeFramelist2=NULL;
03828
03829
03830
03831
03832
03833 printf("LOOKING FOR FILTERGRAMS ALREADY IN MEMORY BUT THAT ARE NOT NEEDED ANYMORE\n");
03834 for(ii=0;ii<nRecs1;++ii)
03835 {
03836 if(SegmentRead[ii] == 1)
03837 {
03838 Needed=0;
03839
03840 for(k=0;k<framelistSize*TempIntNum;++k)
03841 {
03842 if (FramelistArray[k] == ii)
03843 {
03844 Needed=1;
03845 break;
03846 }
03847 }
03848
03849 if(Needed == 0)
03850 {
03851 drms_free_array(Segments[ii]);
03852 drms_free_array(Ierror[ii]);
03853 Segments[ii]= NULL;
03854 Ierror[ii] = NULL;
03855 SegmentRead[ii] = 0;
03856 }
03857
03858 }
03859
03860 }
03861
03862
03863
03864
03865
03866
03867
03868 arrLev1d = (DRMS_Array_t **)malloc(nRecs1d*sizeof(DRMS_Array_t *));
03869 if(arrLev1d == NULL)
03870 {
03871 printf("Error: memory could not be allocated to arrLev1d\n");
03872 return 1;
03873 }
03874
03875 for(k=0;k<nRecs1d;++k)
03876 {
03877 arrLev1d[k]= drms_array_create(type1d,2,axisout,NULL,&status);
03878 if(status != DRMS_SUCCESS || arrLev1d[k] == NULL)
03879 {
03880 printf("Error: cannot create a DRMS array for a level 1d filtergram with index %d at target time %s\n",k,timeBegin2);
03881
03882
03883
03884
03885 return 1;
03886 }
03887 }
03888 Segments1d=1;
03889
03890
03891
03892
03893
03894 printf("COMPUTING MEDIAN VALUE OF X0, Y0, AND RSUN\n");
03895 X0ARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03896 Y0ARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03897 RSUNARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03898
03899 for(k=0;k<framelistSize;++k)
03900 {
03901 for(i=0;i<TempIntNum;++i)
03902 {
03903 temp=FramelistArray[k+framelistSize*i];
03904 if(temp != -1)
03905 {
03906 X0ARR[k+framelistSize*i]=X0[temp];
03907 Y0ARR[k+framelistSize*i]=Y0[temp];
03908 RSUNARR[k+framelistSize*i]=RSUN[temp];
03909 }
03910 else
03911 {
03912 X0ARR[k+framelistSize*i] =MISSINGRESULT;
03913 Y0ARR[k+framelistSize*i] =MISSINGRESULT;
03914 RSUNARR[k+framelistSize*i]=MISSINGRESULT;
03915 }
03916
03917 }
03918 }
03919
03920
03921 status=fstats(framelistSize*TempIntNum,X0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03922 printf("VALUES USED TO OBTAIN THE MEDIAN: %d\n",ngood);
03923 X0AVG=median;
03924 X0RMS=sigma;
03925 status=fstats(framelistSize*TempIntNum,Y0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03926 Y0AVG=median;
03927 Y0RMS=sigma;
03928 status=fstats(framelistSize*TempIntNum,RSUNARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03929 RSUNAVG=median;
03930 RSUNRMS=sigma;
03931
03932 free(X0ARR);
03933 free(Y0ARR);
03934 free(RSUNARR);
03935 X0ARR=NULL;
03936 Y0ARR=NULL;
03937 RSUNARR=NULL;
03938
03939 if(combine == 1)
03940 {
03941 printf("COMPUTING MEDIAN VALUE OF X0, Y0, AND RSUN, FOR FRONT CAMERA ONLY\n");
03942 X0ARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03943 Y0ARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03944 RSUNARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03945
03946 for(k=0;k<framelistSize;++k)
03947 {
03948 for(i=0;i<TempIntNum;++i)
03949 {
03950 temp=FramelistArray[k+framelistSize*i];
03951 if(temp != -1)
03952 {
03953 if(HCAMID[temp] == LIGHT_FRONT)
03954 {
03955 X0ARR[k+framelistSize*i]=X0[temp];
03956 Y0ARR[k+framelistSize*i]=Y0[temp];
03957 RSUNARR[k+framelistSize*i]=RSUN[temp];
03958 }
03959 else
03960 {
03961 X0ARR[k+framelistSize*i] =MISSINGRESULT;
03962 Y0ARR[k+framelistSize*i] =MISSINGRESULT;
03963 RSUNARR[k+framelistSize*i]=MISSINGRESULT;
03964 }
03965 }
03966 else
03967 {
03968 X0ARR[k+framelistSize*i] =MISSINGRESULT;
03969 Y0ARR[k+framelistSize*i] =MISSINGRESULT;
03970 RSUNARR[k+framelistSize*i]=MISSINGRESULT;
03971 }
03972
03973 }
03974 }
03975
03976
03977 status=fstats(framelistSize*TempIntNum,X0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03978 printf("VALUES USED TO OBTAIN THE MEDIAN (FRONT CAMERA): %d\n",ngood);
03979 X0AVGF=median;
03980 status=fstats(framelistSize*TempIntNum,Y0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03981 Y0AVGF=median;
03982 status=fstats(framelistSize*TempIntNum,RSUNARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03983 RSUNAVGF=median;
03984
03985 free(X0ARR);
03986 free(Y0ARR);
03987 free(RSUNARR);
03988 X0ARR=NULL;
03989 Y0ARR=NULL;
03990 RSUNARR=NULL;
03991
03992 printf("COMPUTING MEDIAN VALUE OF X0, Y0, AND RSUN, FOR SIDE CAMERA ONLY\n");
03993 X0ARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03994 Y0ARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03995 RSUNARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03996
03997 for(k=0;k<framelistSize;++k)
03998 {
03999 for(i=0;i<TempIntNum;++i)
04000 {
04001 temp=FramelistArray[k+framelistSize*i];
04002 if(temp != -1)
04003 {
04004 if(HCAMID[temp] == LIGHT_SIDE)
04005 {
04006 X0ARR[k+framelistSize*i]=X0[temp];
04007 Y0ARR[k+framelistSize*i]=Y0[temp];
04008 RSUNARR[k+framelistSize*i]=RSUN[temp];
04009 }
04010 else
04011 {
04012 X0ARR[k+framelistSize*i] =MISSINGRESULT;
04013 Y0ARR[k+framelistSize*i] =MISSINGRESULT;
04014 RSUNARR[k+framelistSize*i]=MISSINGRESULT;
04015 }
04016 }
04017 else
04018 {
04019 X0ARR[k+framelistSize*i] =MISSINGRESULT;
04020 Y0ARR[k+framelistSize*i] =MISSINGRESULT;
04021 RSUNARR[k+framelistSize*i]=MISSINGRESULT;
04022 }
04023
04024 }
04025 }
04026
04027
04028 status=fstats(framelistSize*TempIntNum,X0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
04029 printf("VALUES USED TO OBTAIN THE MEDIAN (SIDE CAMERA): %d\n",ngood);
04030 X0AVGS=median;
04031 status=fstats(framelistSize*TempIntNum,Y0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
04032 Y0AVGS=median;
04033 status=fstats(framelistSize*TempIntNum,RSUNARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
04034 RSUNAVGS=median;
04035
04036 free(X0ARR);
04037 free(Y0ARR);
04038 free(RSUNARR);
04039 X0ARR=NULL;
04040 Y0ARR=NULL;
04041 RSUNARR=NULL;
04042
04043 }
04044
04045
04046
04047 for(k=0;k<framelistSize;++k)
04048 {
04049
04050 ActualTempIntNum=TempIntNum;
04051
04052
04053
04054
04055 for(i=0;i<TempIntNum;++i)
04056 {
04057 temp=FramelistArray[k+framelistSize*i];
04058 if(temp != -1)
04059 {
04060
04061
04062 if(SegmentRead[temp] != -1)
04063 {
04064
04065 if(SegmentRead[temp] == 0)
04066 {
04067 printf("segment needs to be read for FSN %d %d\n",FSN[temp],HCAMID[temp]);
04068 segin = drms_segment_lookupnum(recLev1->records[temp], 0);
04069 Segments[temp] = drms_segment_read(segin,type1d, &status);
04070 if (status != DRMS_SUCCESS || Segments[temp] == NULL)
04071 {
04072 printf("Error: could not read the segment of level 1 record FSN = %d at target time %s\n",FSN[temp],timeBegin2);
04073 return 1;
04074
04075
04076
04077
04078
04079
04080 }
04081 else
04082 {
04083 Ierror[temp] = drms_array_create(typeEr,2,axisout,NULL,&status);
04084 if(status != DRMS_SUCCESS || Ierror[temp] == NULL)
04085 {
04086 printf("Error: could not create an array for Ierror at target time %s\n",timeBegin2);
04087 drms_free_array(Segments[temp]);
04088 Segments[temp]=NULL;
04089 Ierror[temp]=NULL;
04090 SegmentRead[temp]=-1;
04091 ActualTempIntNum-=1;
04092 arrin[i] = NULL;
04093 arrerrors[i] = NULL;
04094 }
04095 else
04096 {
04097 arrin[i] = Segments[temp];
04098 arrerrors[i] = Ierror[temp];
04099 if(arrin[i]->axis[0] != axisin[0] || arrin[i]->axis[1] != axisin[1])
04100 {
04101 printf("Error: level 1 record FSN = %d at target time %s has a segment with dimensions %d x %d instead of %d x %d\n",FSN[temp],timeBegin2,arrin[i]->axis[0],arrin[i]->axis[1],axisin[0],axisin[1]);
04102 drms_free_array(Segments[temp]);
04103 drms_free_array(Ierror[temp]);
04104 ActualTempIntNum-=1;
04105 arrin[i] = NULL;
04106 arrerrors[i] = NULL;
04107 Segments[temp]=NULL;
04108 Ierror[temp]=NULL;
04109 SegmentRead[temp]=-1;
04110 }
04111 else
04112 {
04113 SegmentRead[temp]=1;
04114
04115
04116
04117
04118 segin = drms_segment_lookup(recLev1->records[temp],"bad_pixel_list");
04119 BadPixels = NULL;
04120 BadPixels = drms_segment_read(segin,segin->info->type,&status);
04121 if(status != DRMS_SUCCESS || BadPixels == NULL)
04122 {
04123 printf("Error: cannot read the list of bad pixels of level 1 filtergram FSN= %d\n",FSN[temp]);
04124 return 1;
04125
04126
04127
04128
04129
04130
04131
04132
04133 }
04134 else
04135 {
04136
04137 strcpy(HMISeriesTemp,CosmicRaySeries);
04138 strcat(HMISeriesTemp,"[][");
04139 sprintf(FSNtemps,"%d",FSN[temp]);
04140 strcat(HMISeriesTemp,FSNtemps);
04141 strcat(HMISeriesTemp,"]");
04142 rectemp=NULL;
04143
04144 rectemp=drms_open_records(drms_env,HMISeriesTemp,&statusA[0]);
04145
04146 if(statusA[0] == DRMS_SUCCESS && rectemp != NULL && rectemp->n != 0)
04147 {
04148 segin = drms_segment_lookupnum(rectemp->records[0],0);
04149 CosmicRays = NULL;
04150
04151 COSMICCOUNT=drms_getkey_int(rectemp->records[0],COUNTS,&status);
04152 if(status != DRMS_SUCCESS || COSMICCOUNT == -1)
04153 {
04154 QUALITY = QUALITY | QUAL_NOCOSMICRAY;
04155 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
04156 }
04157 else
04158 {
04159 CosmicRays = drms_segment_read(segin,segin->info->type,&status);
04160 if(status != DRMS_SUCCESS || CosmicRays == NULL)
04161 {
04162 printf("Error: the list of cosmic-ray hits could not be read for FSN %d\n",FSN[temp]);
04163 return 1;
04164
04165
04166 QUALITY = QUALITY | QUAL_NOCOSMICRAY;
04167 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
04168 CosmicRays = NULL;
04169
04170 }
04171 }
04172 }
04173 else
04174 {
04175 printf("Unable to open the series %s for FSN %d\n",HMISeriesTemp,FSN[temp]);
04176
04177
04178
04179 QUALITY = QUALITY | QUAL_NOCOSMICRAY;
04180 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
04181 CosmicRays = NULL;
04182
04183 }
04184
04185 image = Segments[temp]->data;
04186
04187
04188
04189
04190
04191 if(inRotationalFlat == 1)
04192 {
04193
04194 HMIFlatField = (char *)malloc(MaxNString*sizeof(char *));
04195 if(HMIFlatField == NULL)
04196 {
04197 printf("Error: memory could not be allocated to HMIFlatField\n");
04198 return 1;
04199 }
04200 HMIFlatField = drms_getkey_string(recLev1->records[temp],FLATREC,&status);
04201 if (status != DRMS_SUCCESS)
04202 {
04203 printf("Error: could not read the FLAT_REC keyword for the target filtergram FSN= %d",FSN[temp]);
04204 return 1;
04205 }
04206
04207
04208 if(strcmp(HMIFlatField,HMIFlatField0) != 0)
04209 {
04210 printf("Warning: the hmi.flatfield record used to produce the level 1 records changed during the run of the observables code\n");
04211
04212 recflat = drms_open_records(drms_env,HMIFlatField,&status);
04213 if (status != DRMS_SUCCESS || recflat == NULL || recflat->n == 0)
04214 {
04215 printf("Error: record missing or corrupt for the flat field query %s\n",HMIFlatField);
04216 return 1;
04217 }
04218 drms_free_array(flatfield);
04219 strcpy(HMIFlatField0,HMIFlatField);
04220 segin = drms_segment_lookup(recflat->records[0],"flatfield");
04221 flatfield = drms_segment_read(segin,type1d,&status);
04222 if (status != DRMS_SUCCESS || flatfield == NULL)
04223 {
04224 printf("Error: could not read the data segment for the flat field query %s\n",HMIFlatField);
04225 return 1;
04226 }
04227 pztflat = flatfield->data;
04228 status=drms_close_records(recflat,DRMS_FREE_RECORD);
04229 }
04230
04231 if(inLinearity == 1)
04232 {
04233 printf("applying rotational flat field and correcting for non-linearity of camera on record FSN=%d\n",FSN[temp]);
04234 for(iii=0;iii<axisin[0]*axisin[1];++iii)
04235 {
04236
04237 image[iii]=(image[iii]*pztflat[iii])/rotflat[iii];
04238
04239 tempvalue = image[iii]*EXPTIME[temp];
04240 if(HCAMID[temp] == LIGHT_FRONT) tempvalue = (nonlinf[0]+nonlinf[1]*tempvalue+nonlinf[2]*tempvalue*tempvalue+nonlinf[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
04241 else tempvalue = (nonlins[0]+nonlins[1]*tempvalue+nonlins[2]*tempvalue*tempvalue+nonlins[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
04242 image[iii] = tempvalue/EXPTIME[temp];
04243 }
04244 }
04245 else
04246 {
04247 printf("applying rotational flat field on record FSN=%d\n",FSN[temp]);
04248 for(iii=0;iii<axisin[0]*axisin[1];++iii)
04249 {
04250
04251 image[iii]=(image[iii]*pztflat[iii])/rotflat[iii];
04252 }
04253 }
04254
04255 free(HMIFlatField);
04256
04257 }
04258 else
04259 {
04260 if(inLinearity == 1)
04261 {
04262 printf("correcting for non-linearity of camera on record FSN=%d\n",FSN[temp]);
04263 for(iii=0;iii<axisin[0]*axisin[1];++iii)
04264 {
04265
04266 tempvalue = image[iii]*EXPTIME[temp];
04267 if(HCAMID[temp] == LIGHT_FRONT) tempvalue = (nonlinf[0]+nonlinf[1]*tempvalue+nonlinf[2]*tempvalue*tempvalue+nonlinf[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
04268 else tempvalue = (nonlins[0]+nonlins[1]*tempvalue+nonlins[2]*tempvalue*tempvalue+nonlins[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
04269 image[iii] = tempvalue/EXPTIME[temp];
04270 }
04271 }
04272 }
04273
04274
04275
04276 status = MaskCreation(Mask,axisin[0],axisin[1],BadPixels,HIMGCFID[temp],image,CosmicRays,NBADPERM[temp]);
04277 if(status != 0)
04278 {
04279 printf("Error: unable to create a mask for the gap filling function\n");
04280 return 1;
04281 }
04282 if(BadPixels != NULL)
04283 {
04284 drms_free_array(BadPixels);
04285 BadPixels=NULL;
04286 }
04287 if(CosmicRays != NULL)
04288 {
04289 drms_free_array(CosmicRays);
04290 CosmicRays=NULL;
04291 }
04292 if(rectemp != NULL)
04293 {
04294 drms_close_records(rectemp,DRMS_FREE_RECORD);
04295 rectemp=NULL;
04296 }
04297
04298 image = arrin[i]->data;
04299 ierror = arrerrors[i]->data;
04300
04301 t0=dsecnd();
04302 printf("STARTING GAPFILL\n");
04303 status =do_gapfill(image,Mask,&const_param,ierror,axisin[0],axisin[1]);
04304 t1=dsecnd();
04305 printf("TIME ELAPSED TO GAPFILL: %f\n",t1-t0);
04306 if(status != 0)
04307 {
04308 printf("Error: gapfilling code did not work on level 1 filtergram FSN = %d at target time %s\n",FSN[temp],timeBegin2);
04309 QUALITY = QUALITY | QUAL_NOGAPFILL;
04310 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOGAPFILL;
04311 }
04312 }
04313 }
04314 }
04315 }
04316 }
04317 else
04318 {
04319 printf("segment is already in memory for FSN %d %d\n",FSN[temp],HCAMID[temp]);
04320 arrin[i] = Segments[temp];
04321 arrerrors[i] = Ierror[temp];
04322 }
04323
04324 }
04325 else
04326 {
04327 printf("Error: the filtergram FSN = %d has corrupted/missing keyword(s), or a corrupted/missing data segment, at target time %s\n",FSN[temp],timeBegin2);
04328 ActualTempIntNum-=1;
04329 arrin[i] = NULL;
04330 arrerrors[i] = NULL;
04331 }
04332 }
04333 else
04334 {
04335 printf("a filtergram close to the target time is missing/corrupted\n");
04336 ActualTempIntNum-=1;
04337 arrin[i] = NULL;
04338 arrerrors[i] = NULL;
04339 }
04340 }
04341
04342
04343
04344
04345 if(QuickLook == 1) ThresholdPol=1;
04346 else ThresholdPol=2;
04347 if(ActualTempIntNum >= ThresholdPol)
04348 {
04349
04350 images = (float **)malloc(ActualTempIntNum*sizeof(float *));
04351 if(images == NULL)
04352 {
04353 printf("Error: memory could not be allocated to images\n");
04354 return 1;
04355 }
04356
04357 ierrors = (char **)malloc(ActualTempIntNum*sizeof(char *));
04358 if(ierrors == NULL)
04359 {
04360 printf("Error: memory could not be allocated to ierrors\n");
04361 return 1;
04362 }
04363
04364
04365 KeyInterp = (struct keyword *)malloc(ActualTempIntNum*sizeof(struct keyword));
04366 if(KeyInterp == NULL)
04367 {
04368 printf("Error: memory could not be allocated to KeyInterp\n");
04369 return 1;
04370 }
04371
04372
04373
04374 ii=0;
04375 for(i=0;i<TempIntNum;++i) if (arrin[i] != NULL && arrerrors[i] != NULL)
04376 {
04377 temp=FramelistArray[k+framelistSize*i];
04378 if(fabs(RSUN[temp]-RSUNAVG) > 1.82*RSUNerr || isnan(RSUN[temp]))
04379 {
04380 printf("Warning: image %d passed to do_interpolate has a RSUN value too different from the median value and will be rejected: %f %f\n",FSN[temp],RSUN[temp],RSUNAVG);
04381 ActualTempIntNum-=1;
04382 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04383 continue;
04384 }
04385 if(combine == 0)
04386 {
04387 if(fabs(X0[temp]-X0AVG) > RSUNerr || isnan(X0[temp]))
04388 {
04389 printf("Warning: image %d passed to do_interpolate has a X0 value too different from the median value and will be rejected: %f %f\n",FSN[temp],X0[temp],X0AVG);
04390 ActualTempIntNum-=1;
04391 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04392 continue;
04393 }
04394 if(fabs(Y0[temp]-Y0AVG) > RSUNerr || isnan(Y0[temp]))
04395 {
04396 printf("Warning: image %d passed to do_interpolate has a Y0 value too different from the median value and will be rejected: %f %f\n",FSN[temp],Y0[temp],Y0AVG);
04397 ActualTempIntNum-=1;
04398 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04399 continue;
04400 }
04401 }
04402 else
04403 {
04404 if(HCAMID[temp] == LIGHT_FRONT)
04405 {
04406 if(fabs(X0[temp]-X0AVGF) > RSUNerr || isnan(X0[temp]))
04407 {
04408 printf("Warning: image %d passed to do_interpolate has a X0 value too different from the median value and will be rejected: %f %f\n",FSN[temp],X0[temp],X0AVG);
04409 ActualTempIntNum-=1;
04410 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04411 continue;
04412 }
04413 if(fabs(Y0[temp]-Y0AVGF) > RSUNerr || isnan(Y0[temp]))
04414 {
04415 printf("Warning: image %d passed to do_interpolate has a Y0 value too different from the median value and will be rejected: %f %f\n",FSN[temp],Y0[temp],Y0AVG);
04416 ActualTempIntNum-=1;
04417 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04418 continue;
04419 }
04420 }
04421 else
04422 {
04423 if(fabs(X0[temp]-X0AVGS) > RSUNerr || isnan(X0[temp]))
04424 {
04425 printf("Warning: image %d passed to do_interpolate has a X0 value too different from the median value and will be rejected: %f %f\n",FSN[temp],X0[temp],X0AVG);
04426 ActualTempIntNum-=1;
04427 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04428 continue;
04429 }
04430 if(fabs(Y0[temp]-Y0AVGS) > RSUNerr || isnan(Y0[temp]))
04431 {
04432 printf("Warning: image %d passed to do_interpolate has a Y0 value too different from the median value and will be rejected: %f %f\n",FSN[temp],Y0[temp],Y0AVG);
04433 ActualTempIntNum-=1;
04434 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04435 continue;
04436 }
04437 }
04438 }
04439 images[ii]=arrin[i]->data;
04440 image=arrin[i]->data;
04441
04442
04443 CamID_tmp = HCAMID[temp];
04444
04445
04446
04447
04448
04449
04450
04451
04452
04453 ierrors[ii]=arrerrors[i]->data;
04454 if(HCAMID[temp] == LIGHT_FRONT) KeyInterp[ii].camera=0;
04455 else KeyInterp[ii].camera=1;
04456 if(!strcmp(HWLTNSET[temp],"OPEN")) QUALITY = QUALITY | QUAL_ISSTARGET;
04457 if((QUALITYin[temp] & Q_ACS_ECLP) == Q_ACS_ECLP) QUALITY = QUALITY | QUAL_ECLIPSE;
04458 if((QUALITYin[temp] & Q_ACS_LUNARTRANSIT) == Q_ACS_LUNARTRANSIT) QUALITY = QUALITY | QUAL_POORQUALITY;
04459 if((QUALITYin[temp] & Q_ACS_THERMALRECOVERY) == Q_ACS_THERMALRECOVERY) QUALITY = QUALITY | QUAL_POORQUALITY;
04460 if((QUALITYin[temp] & Q_CAMERA_ANOMALY) == Q_CAMERA_ANOMALY) QUALITY = QUALITY | QUAL_POORQUALITY;
04461 KeyInterp[ii].rsun=RSUNAVG;
04462 if(combine == 1) KeyInterp[ii].rsun=RSUN[temp];
04463 printf("actual solar radius of image in = %f\n",RSUN[temp]);
04464 KeyInterp[ii].xx0=X0[temp];
04465 KeyInterp[ii].yy0=Y0[temp];
04466 KeyInterp[ii].dist=(float)(DSUNOBS[temp]/(double)AstroUnit);
04467 KeyInterp[ii].b0=CRLTOBS[temp]/180.*M_PI;
04468 KeyInterp[ii].p0=CROTA2[temp]/180.*M_PI;
04469 KeyInterp[ii].time=internTOBS[temp];
04470 KeyInterp[ii].focus=CFINDEX[temp];
04471
04472 rec=recLev1->records[temp];
04473 sprintf(recnums,"%ld",rec->recnum);
04474 if(k != 0 || ii != 0) strcat(source,",#");
04475 else strcat(source,"#");
04476 strcat(source,recnums);
04477
04478 QUALITYLEV1 = QUALITYLEV1 | QUALITYin[temp];
04479 QUALITY = QUALITY | QUALITYlev1[temp];
04480
04481 ii+=1;
04482 }
04483
04484
04485
04486 RSUNint=RSUNAVG;
04487 KeyInterpOut.rsun=RSUNint;
04488
04489 if(combine == 0)
04490 {
04491 KeyInterpOut.xx0 =X0AVG;
04492 KeyInterpOut.yy0 =Y0AVG;
04493 }
04494 else
04495 {
04496 if(CamId == LIGHT_FRONT)
04497 {
04498 KeyInterpOut.xx0 =X0AVGF;
04499 KeyInterpOut.yy0 =Y0AVGF;
04500 }
04501 else
04502 {
04503 KeyInterpOut.xx0 =X0AVGS;
04504 KeyInterpOut.yy0 =Y0AVGS;
04505 }
04506 }
04507
04508 KeyInterpOut.dist=(float)DSUNOBSint;
04509 KeyInterpOut.b0 =CRLTOBSint/180.*M_PI;
04510 KeyInterpOut.p0 =CROTA2int/180.*M_PI;
04511 tobs = TargetTime+(DSUNOBSint-1.0)/2.00398880422056639358e-03;
04512 KeyInterpOut.time=tobs;
04513 KeyInterpOut.focus=TargetCFINDEX;
04514
04515
04516
04517 printf("Calling temporal interpolation, de-rotation, and un-distortion code\n");
04518
04519 totalTempIntNum += ActualTempIntNum;
04520 printf("ACTUALTEMPINT= %d, TOTALTEMPINTNUM= %d\n",ActualTempIntNum,totalTempIntNum);
04521 if(ActualTempIntNum != TempIntNum) QUALITY = QUALITY | QUAL_LOWINTERPNUM;
04522 else
04523 {
04524 minimum=KeyInterp[0].time;
04525 maximum=KeyInterp[0].time;
04526 for(ii=1;ii<TempIntNum;++ii)
04527 {
04528 if(KeyInterp[ii].time < minimum) minimum=KeyInterp[ii].time;
04529 if(KeyInterp[ii].time > maximum) maximum=KeyInterp[ii].time;
04530 }
04531 if((maximum-minimum) > (DataCadence*(double)(TempIntNum-1)+DataCadence/(double)framelistSize) ) QUALITY = QUALITY | QUAL_LOWINTERPNUM;
04532 }
04533
04534 if(ActualTempIntNum >= ThresholdPol)
04535 {
04536 for(ii=0;ii<ActualTempIntNum;++ii) printf("KEYWORDS IN: %f %f %f %f %f %f %f %d %d\n",KeyInterp[ii].rsun,KeyInterp[ii].xx0,KeyInterp[ii].yy0,KeyInterp[ii].dist,KeyInterp[ii].b0,KeyInterp[ii].p0,KeyInterp[ii].time,KeyInterp[ii].focus, KeyInterp[ii].camera);
04537 printf("KEYWORDS OUT: %f %f %f %f %f %f %f %d %d\n",KeyInterpOut.rsun,KeyInterpOut.xx0,KeyInterpOut.yy0,KeyInterpOut.dist,KeyInterpOut.b0,KeyInterpOut.p0,KeyInterpOut.time,KeyInterpOut.focus,KeyInterpOut.camera);
04538
04539 t0=dsecnd();
04540 strcpy(dpath2,dpath);
04541 strcat(dpath2,"/../../../");
04542 status=do_interpolate(images,ierrors,arrLev1d[k]->data,KeyInterp,&KeyInterpOut,&const_param,ActualTempIntNum,axisin[0],axisin[1],-1.0,dpath2);
04543 t1=dsecnd();
04544 printf("TIME ELAPSED IN DO_INTERPOLATE: %f\n",t1-t0);
04545 }
04546 else
04547 {
04548 printf("Error: ActualTempIntNum <ThresholdPol\n");
04549 QUALITY = QUALITY | QUAL_NOTENOUGHINTERPOLANTS;
04550 status = 1;
04551 }
04552
04553 printf("End temporal interpolation, de-rotation, and un-distortion\n");
04554 if (status != 0)
04555 {
04556 printf("Error: temporal interpolation, de-rotation, and undistortion subroutine failed at target time %s\n",timeBegin2);
04557 drms_free_array(arrLev1d[k]);
04558 arrLev1d[k] = NULL;
04559 QUALITY = QUALITY | QUAL_INTERPOLATIONFAILED;
04560 }
04561 else
04562 {
04563 for(i=0;i<TempIntNum;++i)
04564 {
04565 temp=FramelistArray[k+framelistSize*i];
04566 if(temp != -1) break;
04567 }
04568
04569
04570
04571
04572 if(combine == 1)camera=3;
04573 if(combine == 0 && CamId == LIGHT_SIDE) camera=1;
04574 if(combine == 0 && CamId == LIGHT_FRONT) camera=2;
04575
04576
04577 cdelt1=1.0/RSUNint*asin(solar_radius/(DSUNOBSint*(double)AstroUnit))*180.*60.*60./M_PI;
04578
04579 statusA[0] = drms_setkey_time(recLev1d->records[k],TRECS,trec);
04580 statusA[1] = drms_setkey_time(recLev1d->records[k],TOBSS,tobs);
04581 statusA[2] = drms_setkey_int(recLev1d->records[k],CAMERAS,camera);
04582 statusA[3] = drms_setkey_string(recLev1d->records[k],HISTORYS,HISTORY);
04583 statusA[4] = drms_setkey_string(recLev1d->records[k],COMMENTS,COMMENT);
04584
04585 statusA[5]=0;
04586 statusA[6] = drms_setkey_int(recLev1d->records[k],HFLIDS,TargetHFLID);
04587 statusA[7] = drms_setkey_int(recLev1d->records[k],HCFTIDS,TargetCFINDEX);
04588
04589 statusA[8]=0;
04590 statusA[9] = drms_setkey_int(recLev1d->records[k],QUALITYS,QUALITY);
04591 statusA[10]= drms_setkey_double(recLev1d->records[k],DSUNOBSS,DSUNOBSint*(double)AstroUnit);
04592 statusA[11]= drms_setkey_float(recLev1d->records[k],CRLTOBSS,KeyInterpOut.b0*180./M_PI);
04593 statusA[12]= drms_setkey_float(recLev1d->records[k],CROTA2S,-KeyInterpOut.p0*180./M_PI);
04594 statusA[13]= drms_setkey_float(recLev1d->records[k],CDELT1S,cdelt1);
04595 statusA[14]= drms_setkey_float(recLev1d->records[k],CDELT2S,cdelt1);
04596 statusA[15]= drms_setkey_float(recLev1d->records[k],CRPIX1S,KeyInterpOut.xx0+1.);
04597 statusA[16]= drms_setkey_float(recLev1d->records[k],CRPIX2S,KeyInterpOut.yy0+1.);
04598 sprintf(jsocverss,"%d",jsoc_vers_num);
04599 statusA[17]= drms_setkey_string(recLev1d->records[k],BLDVERSS,jsocverss);
04600 statusA[18]= drms_setkey_double(recLev1d->records[k],OBSVRS,OBSVRint);
04601 statusA[19]= drms_setkey_double(recLev1d->records[k],OBSVWS,OBSVWint);
04602 statusA[20]= drms_setkey_double(recLev1d->records[k],OBSVNS,OBSVNint);
04603
04604 statusA[21]=0;
04605 statusA[22]= drms_setkey_float(recLev1d->records[k],CRLNOBSS,CRLNOBSint);
04606 statusA[23]= drms_setkey_int(recLev1d->records[k],CARROTS,CARROTint);
04607 statusA[24]= drms_setkey_int(recLev1d->records[k],TINTNUMS,ActualTempIntNum);
04608 statusA[25]= drms_setkey_int(recLev1d->records[k],SINTNUMS,const_param.order_int);
04609 statusA[26]= drms_setkey_string(recLev1d->records[k],CODEVER0S,CODEVERSION);
04610 statusA[27]= drms_setkey_string(recLev1d->records[k],DISTCOEFS,DISTCOEFPATH);
04611 statusA[28]= drms_setkey_string(recLev1d->records[k],ROTCOEFS,ROTCOEFPATH);
04612 statusA[29]= drms_setkey_int(recLev1d->records[k],ODICOEFFS,const_param.order_dist_coef);
04613 statusA[30]= drms_setkey_int(recLev1d->records[k],OROCOEFFS,2*const_param.order2_rot_coef);
04614 statusA[31]= drms_setkey_string(recLev1d->records[k],CODEVER1S,CODEVERSION1);
04615 statusA[32]= drms_setkey_string(recLev1d->records[k],CODEVER2S,CODEVERSION2);
04616 statusA[33]= drms_setkey_int(recLev1d->records[k],HPL1POSS,HPL1POS[temp]);
04617 statusA[34]= drms_setkey_int(recLev1d->records[k],HPL2POSS,HPL2POS[temp]);
04618 statusA[35]= drms_setkey_int(recLev1d->records[k],HPL3POSS,HPL3POS[temp]);
04619 statusA[36]= drms_setkey_int(recLev1d->records[k],HWL1POSS,HWL1POS[temp]);
04620 statusA[37]= drms_setkey_int(recLev1d->records[k],HWL2POSS,HWL2POS[temp]);
04621 statusA[38]= drms_setkey_int(recLev1d->records[k],HWL3POSS,HWL3POS[temp]);
04622 statusA[39]= drms_setkey_int(recLev1d->records[k],HWL4POSS,HWL4POS[temp]);
04623 statusA[40]= drms_setkey_int(recLev1d->records[k],FIDS,FID[temp]);
04624 printf("FID of written record: %d\n",FID[temp]);
04625 statusA[41]= drms_setkey_int(recLev1d->records[k],HCAMIDS,CamId);
04626 sprint_time(DATEOBS,tobs-DataCadence/2.0,"UTC",1);
04627 statusA[42]= drms_setkey_string(recLev1d->records[k],DATEOBSS,DATEOBS);
04628 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
04629 statusA[43]= drms_setkey_string(recLev1d->records[k],DATES,DATEOBS);
04630 statusA[44]= drms_setkey_int(recLev1d->records[k],HWLTIDS,TargetHWLTID);
04631 statusA[45]= drms_setkey_int(recLev1d->records[k],HPLTIDS,TargetHPLTID);
04632 statusA[46]= drms_setkey_int(recLev1d->records[k],WavelengthIDS,WavelengthID);
04633 if(camera == 2) strcpy(DATEOBS,"HMI_FRONT2");
04634 if(camera == 1) strcpy(DATEOBS,"HMI_SIDE1");
04635 if(camera == 3) strcpy(DATEOBS,"HMI_COMBINED");
04636 statusA[47]= drms_setkey_string(recLev1d->records[k],INSTRUMES,DATEOBS);
04637
04638 if(inLinearity == 1) CALVER32[0] = CALVER32[0] | CALVER_LINEARITY;
04639 if(inRotationalFlat == 1) CALVER32[0] = CALVER32[0] | CALVER_ROTATIONAL;
04640 if(inSmoothTables == 1) CALVER32[0] = CALVER32[0] | CALVER_SMOOTH;
04641 if(TargetHFLID == 58312 || TargetHFLID == 1022) {CALVER32[0] = CALVER32[0] | CALVER_MODL;} else CALVER32[0] = CALVER32[0] & CALVER_NOMODL;
04642 statusA[48]= drms_setkey_longlong(recLev1d->records[k],CALVER64S,CALVER32[0]);
04643
04644 TotalStatus=0;
04645 for(i=0;i<49;++i) TotalStatus+=statusA[i];
04646 if(TotalStatus != 0)
04647 {
04648 for(ii=0;ii<49;++ii) if(statusA[ii] != 0) printf(" %d ",ii);
04649 printf("\n");
04650 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the level 1d data at target time %s\n",timeBegin2);
04651 }
04652
04653
04654 if (Lev1dWanted)
04655 {
04656 segout = drms_segment_lookupnum(recLev1d->records[k],0);
04657 arrLev1d[k]->bzero=segout->bzero;
04658 arrLev1d[k]->bscale=segout->bscale;
04659 arrLev1d[k]->israw=0;
04660 status=drms_segment_write(segout,arrLev1d[k],0);
04661 if(status != DRMS_SUCCESS)
04662 {
04663 printf("Error: a call to drms_segment_write failed\n");
04664 return 1;
04665 }
04666 }
04667
04668 }
04669
04670 free(images);
04671 free(ierrors);
04672 images=NULL;
04673 ierrors=NULL;
04674 free(KeyInterp);
04675 KeyInterp=NULL;
04676 }
04677 else
04678 {
04679 printf("Error: not enough valid level 1 filtergrams to produce a level 1d filtergram at target time %s\n",timeBegin2);
04680 drms_free_array(arrLev1d[k]);
04681 arrLev1d[k]=NULL;
04682 QUALITY = QUALITY | QUAL_NOTENOUGHINTERPOLANTS;
04683
04684 }
04685
04686
04687 CameraID [k] = CamID_tmp;
04688
04689 }
04690
04691
04692 free(FramelistArray);
04693 FramelistArray=NULL;
04694 }
04695
04696
04697
04698
04699
04700
04701
04702
04703
04704
04705
04706
04707
04708 if (TestLevIn[2]==1)
04709 {
04710
04711
04712
04713
04714
04715
04716
04717
04718
04719
04720
04721 PolarizationType=1;
04722 if(CamId == LIGHT_SIDE) camera=1;
04723 if(CamId == LIGHT_FRONT) camera=2;
04724 if(CamId0 == 3) camera=3;
04725 if(camera == 2)
04726 {
04727 printf("Error: the use of time-averaged IQUV data as input requires CamId = side camera\n");
04728 return 1;
04729 }
04730
04731
04732
04733
04734 if(PolarizationType ==3 || PolarizationType ==2) strcpy(HMISeries,HMISeriesLev1pb);
04735 else strcpy(HMISeries,HMISeriesLev1pa);
04736 strcat(HMISeries,"[");
04737 strcat(HMISeries,timeBegin2);
04738 strcat(HMISeries,"][");
04739 if(DataCadence != 720.0) sprintf(CamIds,"%d",CamId);
04740 else sprintf(CamIds,"%d",camera);
04741 strcat(HMISeries,CamIds);
04742 strcat(HMISeries,"]");
04743
04744 printf("Opening the record %s\n",HMISeries);
04745 recLev1p = drms_open_records(drms_env,HMISeries,&status);
04746
04747 if (status == DRMS_SUCCESS && recLev1p != NULL && recLev1p->n > 0)
04748 {
04749 if(recLev1p->n > 1)
04750 {
04751 printf("Too many records: %d\n",recLev1p->n);
04752 return 1;
04753 }
04754 printf("Number of level 1p records opened= %d\n",recLev1p->n);
04755
04756 nSegs1p = drms_record_numsegments(recLev1p->records[0]);
04757 printf("NUMBER OF DATA SEGMENTS: %d\n",nSegs1p);
04758
04759
04760 if (PolarizationType ==1)
04761 {
04762 nRecs1p = nSegs1p/4;
04763 }
04764 if (PolarizationType ==2 || PolarizationType ==3)
04765 {
04766 nRecs1p = nSegs1p/2;
04767 }
04768 printf("NUMBER OF WAVELENGTHS: %d\n",nRecs1p);
04769
04770 trec = drms_getkey_time(recLev1p->records[0],TRECS,&status);
04771 if(status != DRMS_SUCCESS)
04772 {
04773 printf("Error: cannot read the keyword %s\n",TRECS);
04774
04775 return 1;
04776 }
04777 if(trec != TargetTime)
04778 {
04779 printf("Error: %s of a level 1p record is not equal to the target time %s\n",TRECS,timeBegin2);
04780
04781 return 1;
04782 }
04783 tobs = drms_getkey_time(recLev1p->records[0],TOBSS,&status);
04784 if(status != DRMS_SUCCESS)
04785 {
04786 printf("Error: cannot read the keyword %s\n",TOBSS);
04787 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04788
04789 }
04790
04791
04792
04793
04794
04795 TREC_STEP= drms_getkey_time(recLev1p->records[0],TRECSTEPS,&status);
04796 if(status != DRMS_SUCCESS)
04797 {
04798 printf("Error: cannot read the keyword %s\n",TRECSTEPS);
04799
04800 return 1;
04801 }
04802
04803 if(TREC_STEP != DataCadence)
04804 {
04805 printf("Error: the cadence is not equal to the T_REC_step keyword of the level 1p data\n");
04806
04807 return 1;
04808 }
04809
04810 DRMS_SegmentDimInfo_t di;
04811 segin = drms_segment_lookupnum(recLev1p->records[0],0);
04812 status = drms_segment_getdims(segin,&di);
04813 if(status != DRMS_SUCCESS)
04814 {
04815 printf("Error: cannot read the dimensions of the data segment of level 1p data\n");
04816
04817 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04818 }
04819 axisin[0]= di.axis[0];
04820 axisin[1]= di.axis[1];
04821 axisout[0]=axisin[0];
04822 axisout[1]=axisin[1];
04823
04824 QUALITYLEV1 = drms_getkey_int(recLev1p->records[0],QUALLEV1S,&status);
04825 if(status != DRMS_SUCCESS)
04826 {
04827 printf("Error: cannot read the keyword %s\n",QUALLEV1S);
04828 return 1;
04829 }
04830 strcpy(source,drms_getkey_string(recLev1p->records[0],SOURCES,&status));
04831 if(status != DRMS_SUCCESS)
04832 {
04833 printf("Error: cannot read the keyword %s\n",SOURCES);
04834 return 1;
04835 }
04836 QUALITY = drms_getkey_int(recLev1p->records[0],QUALITYS,&status);
04837 if(status != DRMS_SUCCESS)
04838 {
04839 printf("Error: cannot read the keyword %s\n",QUALITYS);
04840 return 1;
04841 }
04842
04843 CALVER64 = drms_getkey_longlong(recLev1p->records[0],CALVER64S,&status);
04844 if(status != DRMS_SUCCESS)
04845 {
04846 printf("Error: cannot read the keyword %s\n",CALVER64S);
04847 return 1;
04848 }
04849 if(inSmoothTables == 1) CALVER64 = CALVER64 | CALVER_SMOOTH;
04850
04851 Segments1p=0;
04852
04853 }
04854 else
04855 {
04856 printf("Unable to open the series %s, or no record found, for time %s\n",HMISeries,timeBegin2);
04857 if(status == DRMS_SUCCESS) QUALITY = QUALITY | QUAL_MISSINGLEV1P;
04858 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04859 }
04860 }
04861
04862
04863
04864
04865
04866
04867
04868
04869
04870
04871
04872
04873
04874
04875
04876 if (Lev1pWanted == 1 || (Lev15Wanted == 1 && TestLevIn[2]!=1))
04877 {
04878
04879
04880 printf("PRODUCING LEVEL 1P RECORDS\n");
04881
04882 int ActualnSegs1d=0;
04883
04884
04885
04886 if(Segments1d == 0)
04887 {
04888 printf("READING THE LEVEL 1d DATA SEGMENTS\n");
04889
04890
04891 statusA[0]=1;
04892 i=0;
04893 while(statusA[0] != DRMS_SUCCESS)
04894 {
04895 TargetHFLID = drms_getkey_int(recLev1d->records[i],HFLIDS,&statusA[0]);
04896 if(i < nRecs1d-1) ++i;
04897 else break;
04898 }
04899 statusA[1]=1;
04900 i=0;
04901 while(statusA[1] != DRMS_SUCCESS)
04902 {
04903 TargetHPLTID = drms_getkey_int(recLev1d->records[i],HPLTIDS,&statusA[1]);
04904 if(i < nRecs1d-1) ++i;
04905 else break;
04906 }
04907 statusA[2]=1;
04908 i=0;
04909 while(statusA[2] != DRMS_SUCCESS)
04910 {
04911 TargetHWLTID = drms_getkey_int(recLev1d->records[i],HWLTIDS,&statusA[2]);
04912 if(i < nRecs1d-1) ++i;
04913 else break;
04914 }
04915 statusA[3]=1;
04916 i=0;
04917 while(statusA[3] != DRMS_SUCCESS)
04918 {
04919 WavelengthID2 = drms_getkey_int(recLev1d->records[i],WavelengthIDS,&statusA[3]);
04920 if(i < nRecs1d-1) ++i;
04921 else break;
04922 }
04923 if(WavelengthID2 != WavelengthID)
04924 {
04925 printf("Error: WavelengthID2 != WavelengthID\n");
04926 return 1;
04927 }
04928
04929
04930 if( (statusA[0]+statusA[1]+statusA[2]+statusA[3]) != 0)
04931 {
04932 printf("Error: some needed keywords cannot be read on level 1d data at target time %s\n",timeBegin2);
04933 Segments1d = 0;
04934 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1D;
04935 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04936 }
04937 else
04938 {
04939 framelistSize = framelistInfo(TargetHFLID,TargetHPLTID,TargetHWLTID,WavelengthID,PHWPLPOS,WavelengthIndex,WavelengthLocation,&PolarizationType,CamId,&combine,&npol,MaxNumFiltergrams,&CadenceRead,CameraValues,FIDValues,dpath);
04940 if(framelistSize == 1) return 1;
04941 }
04942
04943 if(framelistSize != nRecs1d)
04944 {
04945 printf("Error: there are %d level 1d records open at target time %s, but the expected number of records is %d\n",nRecs1d,timeBegin2,framelistSize);
04946 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1D;
04947 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04948 }
04949
04950 ActualnSegs1d=nRecs1d;
04951
04952 arrLev1d = (DRMS_Array_t **)malloc(nRecs1d*sizeof(DRMS_Array_t *));
04953 if(arrLev1d == NULL)
04954 {
04955 printf("Error: memory could not be allocated to arrLev1d\n");
04956 return 1;
04957 }
04958
04959 for(i=0;i<nRecs1d;++i)
04960 {
04961
04962
04963
04964
04965
04966
04967
04968
04969 if(recLev1d->records[i] != NULL)
04970 {
04971 segin = drms_segment_lookupnum(recLev1d->records[i], 0);
04972 arrLev1d[i] = drms_segment_read(segin,type1d,&status);
04973 if(status != DRMS_SUCCESS || arrLev1d[i] == NULL)
04974 {
04975 printf("Error: could not read the segment for level 1d data index %d at target time %s \n",i,timeBegin2);
04976 arrLev1d[i] = NULL;
04977 ActualnSegs1d-=1;
04978 }
04979 }
04980 else
04981 {
04982 arrLev1d[i] = NULL;
04983 ActualnSegs1d-=1;
04984 }
04985 }
04986
04987 Segments1d = 1;
04988 }
04989 else
04990 {
04991 ActualnSegs1d=nRecs1d;
04992 for(i=0;i<nRecs1d;++i)
04993 {
04994 if(arrLev1d[i] == NULL) ActualnSegs1d-=1;
04995 }
04996 }
04997
04998
04999
05000
05001
05002
05003 if(ActualnSegs1d != framelistSize)
05004 {
05005 printf("Error: some records for the level 1d filtergrams are missing to produce level 1p data at target time %s\n",timeBegin2);
05006 Segments1d=0;
05007 QUALITY = QUALITY | QUAL_MISSINGLEV1D;
05008 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
05009 }
05010
05011
05012
05013
05014
05015 if(PolarizationType ==3)
05016 {
05017 nRecs1p=ActualnSegs1d/2;
05018 npolout=2;
05019 nSegs1p=npolout*nRecs1p;
05020 Lev1pOffset=40;
05021 if (Lev1pWanted) recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pb,DRMS_PERMANENT,&status);
05022 else recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pb,DRMS_TRANSIENT,&status);
05023 }
05024 if(PolarizationType ==2)
05025 {
05026 nRecs1p=ActualnSegs1d/4;
05027 npolout=2;
05028 nSegs1p=npolout*nRecs1p;
05029 Lev1pOffset=40;
05030 if (Lev1pWanted) recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pb,DRMS_PERMANENT,&status);
05031 else recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pb,DRMS_TRANSIENT,&status);
05032 }
05033 if(PolarizationType ==1)
05034 {
05035 nRecs1p=ActualnSegs1d/npol;
05036 npolout=4;
05037 nSegs1p=npolout*nRecs1p;
05038 Lev1pOffset=0;
05039 if (Lev15Wanted)
05040 {
05041 printf("Warning: you asked for a lev1.5 output but the code can only produce lev1p data from this framelist and the camera selected\n");
05042 Lev15Wanted = 0;
05043 }
05044 if (Lev1pWanted) recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pa,DRMS_PERMANENT,&status);
05045 else recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pa,DRMS_TRANSIENT,&status);
05046 }
05047
05048 if (status != DRMS_SUCCESS || recLev1p == NULL)
05049 {
05050 printf("Could not create a record for the level 1p series at target time %s\n",timeBegin2);
05051
05052
05053
05054 return 1;
05055 }
05056
05057
05058
05059
05060 arrLev1p = (DRMS_Array_t **)malloc(nSegs1p*sizeof(DRMS_Array_t *));
05061 if(arrLev1p == NULL)
05062 {
05063 printf("Error: memory could not be allocated to arrLev1p\n");
05064 return 1;
05065 }
05066
05067 for(i=0;i<nSegs1p;++i)
05068 {
05069 arrLev1p[i] = drms_array_create(type1p,2,axisout,NULL,&status);
05070 if(status != DRMS_SUCCESS || arrLev1p[i] == NULL)
05071 {
05072 printf("Error: cannot create an array for a level 1p data at target time %s\n",timeBegin2);
05073
05074
05075
05076
05077
05078
05079
05080
05081
05082
05083
05084
05085 return 1;
05086 }
05087 }
05088
05089 images = (float **)malloc(npol*sizeof(float *));
05090 if(images == NULL)
05091 {
05092 printf("Error: memory could not be allocated to images\n");
05093 return 1;
05094 }
05095
05096 imagesout = (float **)malloc(npolout*sizeof(float *));
05097 if(imagesout == NULL)
05098 {
05099 printf("Error: memory could not be allocated to imagesout\n");
05100 return 1;
05101 }
05102
05103 ps1 = (int *)malloc(npol*sizeof(int *));
05104 if(ps1 == NULL)
05105 {
05106 printf("Error: memory could not be allocated to ps1\n");
05107 return 1;
05108 }
05109 ps2 = (int *)malloc(npol*sizeof(int *));
05110 if(ps2 == NULL)
05111 {
05112 printf("Error: memory could not be allocated to ps2\n");
05113 return 1;
05114 }
05115 ps3 = (int *)malloc(npol*sizeof(int *));
05116 if(ps3 == NULL)
05117 {
05118 printf("Error: memory could not be allocated to ps3\n");
05119 return 1;
05120 }
05121
05122 fid = (int *)malloc(nRecs1d*sizeof(int *));
05123 if(fid == NULL)
05124 {
05125 printf("Error: memory could not be allocated to fid\n");
05126 return 1;
05127 }
05128
05129 Wavelengths = (int *)malloc(nRecs1p*sizeof(int *));
05130 if(Wavelengths == NULL)
05131 {
05132 printf("Error: memory could not be allocated to Wavelengths\n");
05133 return 1;
05134 }
05135
05136
05137
05138 printf("Looking for available level 1d arrays. Number expected: %d\n",nRecs1d);
05139 ii=0;
05140 for(i=0;i<nRecs1d;++i)
05141 {
05142 if (arrLev1d[i] != NULL)
05143 {
05144 fid[i]=drms_getkey_int(recLev1d->records[i],FIDS,&status);
05145 if( status != 0)
05146 {
05147 printf("Error: unable to read the keyword fid in a level 1d record\n");
05148 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1D;
05149 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
05150 }
05151 printf("FID of lev1d data: %d\n",fid[i]);
05152 if(i == 0) Wavelengths[0]=WhichWavelength(fid[0]);
05153 temp=0;
05154 for(k=0;k<=ii;++k) if(WhichWavelength(fid[i]) == Wavelengths[k]) temp=1;
05155 if(temp == 0)
05156 {
05157 ii+=1;
05158 Wavelengths[ii]=WhichWavelength(fid[i]);
05159 }
05160 }
05161 else
05162 {
05163 printf("Error: wavelength index %d is missing\n",i);
05164 QUALITY = QUALITY | QUAL_MISSINGLEV1D;
05165 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
05166 }
05167 }
05168
05169 if(ii+1 != nRecs1p)
05170 {
05171 printf("Error: the number of wavelengths in level 1d data: %d; is not what it should be: %d\n",ii+1,nRecs1p);
05172 QUALITY = QUALITY | QUAL_WRONGWAVELENGTHNUM;
05173 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
05174 }
05175
05176
05177
05178
05179
05180
05181
05182
05183 {
05184
05185 strcpy(HMISeriesTemp,HMISeriesTemperature);
05186 strcat(HMISeriesTemp,"[");
05187 strcat(HMISeriesTemp,timeBegin2);
05188 strcat(HMISeriesTemp,"]");
05189 rectemp=NULL;
05190 rectemp = drms_open_records(drms_env,HMISeriesTemp,&statusA[0]);
05191 printf("TEMPERATURE QUERY = %s\n",HMISeriesTemp);
05192 if(statusA[0] == DRMS_SUCCESS && rectemp != NULL && rectemp->n != 0) TSEL=drms_getkey_float(rectemp->records[0],TS08,&status);
05193 else status = 1;
05194 if(status != DRMS_SUCCESS || isnan(TSEL))
05195 {
05196 printf("Error: the temperature keyword %s could not be read\n",TS08);
05197 QUALITY = QUALITY | QUAL_NOTEMP;
05198 TSEL=20.;
05199 }
05200 statusA[1]=1;
05201 if(statusA[0] == DRMS_SUCCESS && rectemp != NULL && rectemp->n != 0) TFRONT=(drms_getkey_float(rectemp->records[0],TS01,&statusA[0])+drms_getkey_float(rectemp->records[0],TS02,&statusA[1]))/2.0;
05202 if(statusA[0] != DRMS_SUCCESS || statusA[1] != DRMS_SUCCESS || isnan(TFRONT))
05203 {
05204 printf("Error: temperature keyword %s and/or %s could not be read\n",TS01,TS02);
05205 QUALITY = QUALITY | QUAL_NOTEMP;
05206 TFRONT=20.;
05207 }
05208 printf("TEMPERATURES = %f %f\n",TSEL,TFRONT);
05209 if(rectemp != NULL)
05210 {
05211 drms_close_records(rectemp,DRMS_FREE_RECORD);
05212 rectemp=NULL;
05213 }
05214 }
05215
05216 printf("WAVELENGTH ORDER = ");
05217 for(i=0;i<nRecs1p;++i) printf(" %d ",Wavelengths[i]);
05218 printf("\n");
05219
05220 printf("CALIBRATION OF POLARIZATION AND SORTING OF THE IMAGES IN THE ORDER I0, I1, I2, I3, I4... \n");
05221
05222 for(k=0;k<nRecs1p;++k)
05223 {
05224
05225
05226
05227 int Ixdim, Iydim;
05228 float *Icamera_FRONT, *Icamera_SIDE, *Iratio_F2S, I_front, I_side;
05229 int Ncamera_FRONT, Ncamera_SIDE, ix, jy, ijxy;
05230 Ixdim = 4096; Iydim = 4096; Ncamera_FRONT = 0; Ncamera_SIDE = 0;
05231 Icamera_FRONT = (float *)malloc(Ixdim * Iydim * sizeof(float *));
05232 Icamera_SIDE = (float *)malloc(Ixdim * Iydim * sizeof(float *));
05233 Iratio_F2S = (float *)malloc(Ixdim * Iydim * sizeof(float *));
05234
05235 for (jy=0;jy<Iydim;jy++)
05236 {
05237 for (ix=0;ix<Ixdim;ix++)
05238 {
05239 ijxy = jy*Ixdim+ix;
05240 Icamera_FRONT[ijxy] = 0.0;
05241 Icamera_SIDE[ijxy] = 0.0;
05242 Iratio_F2S[ijxy] = 1.0;
05243 }
05244 }
05245
05246
05247
05248 if (combine == 1)
05249 {
05250 for(ii=0;ii<nRecs1d;++ii) if (WhichWavelength(fid[ii]) == k)
05251 {
05252 image=arrLev1d[ii]->data;
05253 if (CameraID[ii] == LIGHT_FRONT)
05254 {
05255 Ncamera_FRONT += 1;
05256 for (jy=0;jy<Iydim;jy++)
05257 {
05258 for (ix=0;ix<Ixdim;ix++)
05259 {
05260 ijxy = jy*Ixdim+ix;
05261 Icamera_FRONT[ijxy] += image[ijxy];
05262 }
05263 }
05264 }
05265 if (CameraID[ii] == LIGHT_SIDE)
05266 {
05267 Ncamera_SIDE += 1;
05268 for (jy=0;jy<Iydim;jy++)
05269 {
05270 for (ix=0;ix<Ixdim;ix++)
05271 {
05272 ijxy = jy*Ixdim+ix;
05273 Icamera_SIDE[ijxy] += image[ijxy];
05274 }
05275 }
05276 }
05277 }
05278
05279 for (jy=0;jy<Iydim;jy++)
05280 {
05281 for (ix=0;ix<Ixdim;ix++)
05282 {
05283 ijxy = jy*Ixdim+ix;
05284 if (!isnan(Icamera_FRONT[ijxy]) && !isnan(Icamera_SIDE[ijxy]))
05285 I_front = Icamera_FRONT[ijxy]/(float)Ncamera_FRONT;
05286 I_side = Icamera_SIDE[ijxy]/(float)Ncamera_SIDE;
05287 Iratio_F2S[ijxy] = I_front/I_side;
05288 }
05289 }
05290 }
05291 free(Icamera_FRONT);
05292 free(Icamera_SIDE);
05293
05294
05295 i=0;
05296 for(ii=0;ii<nRecs1d;++ii) if (WhichWavelength(fid[ii]) == k)
05297 {
05298
05299
05300
05301
05302
05303 if (combine == 1 && CameraID[ii] == LIGHT_FRONT)
05304 {
05305 image = arrLev1d[ii]->data;
05306 for (jy=0;jy<Iydim;jy++)
05307 {
05308 for (ix=0;ix<Ixdim;ix++)
05309 {
05310 ijxy = jy*Ixdim+ix;
05311 if (!isnan(image[ijxy])) image[ijxy] /= Iratio_F2S[ijxy];
05312 }
05313 }
05314 }
05315
05316
05317
05318 printf("wavelength=%d, polarization %d\n",k,i);
05319 images[i]=arrLev1d[ii]->data;
05320
05321 ps1[i]=drms_getkey_int(recLev1d->records[ii],HPL1POSS,&statusA[0]);
05322 ps2[i]=drms_getkey_int(recLev1d->records[ii],HPL2POSS,&statusA[1]);
05323 ps3[i]=drms_getkey_int(recLev1d->records[ii],HPL3POSS,&statusA[2]);
05324 printf("Polarization settings: %d %d %d %f %f %d %d\n",ps1[i],ps2[i],ps3[i],TSEL,TFRONT,npolout,PolarizationType);
05325 if( (statusA[0]+statusA[1]+statusA[2]) != 0)
05326 {
05327 printf("Error: unable to read one or several keyword(s) in level 1d data\n");
05328 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1D;
05329 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
05330 }
05331 i+=1;
05332 }
05333
05334
05335 printf("I-ratio at [2048, 2048] = %f\n", Iratio_F2S[2048*4096 + 2048]);
05336 free(Iratio_F2S);
05337
05338 for(i=0;i<npolout;++i) imagesout[i]=arrLev1p[k*npolout+i]->data;
05339
05340
05341
05342
05343
05344 printf("Producing level 1p data\n");
05345 t0=dsecnd();
05346 polcal(&pars,npol,PolarizationType,images,imagesout,ps1,ps2,ps3,TSEL,TFRONT,axisout[0],axisout[1],axisout[1]);
05347 t1=dsecnd();
05348 printf("TIME ELAPSED IN POLCAL: %f\n",t1-t0);
05349
05350
05351
05352
05353 if(Lev1pWanted)
05354 {
05355 t0=dsecnd();
05356 for(i=0;i<npolout;++i)
05357 {
05358 segout = drms_segment_lookup(recLev1p->records[0],Lev1pSegName[i+Lev1pOffset+k*npolout]);
05359 arrLev1p[k*npolout+i]->bzero=segout->bzero;
05360 arrLev1p[k*npolout+i]->bscale=segout->bscale;
05361 arrLev1p[k*npolout+i]->israw=0;
05362 status=drms_segment_write(segout,arrLev1p[k*npolout+i], 0);
05363 if(status != DRMS_SUCCESS)
05364 {
05365 printf("Error: a call to drms_segment_write failed\n");
05366 return 1;
05367 }
05368 }
05369 t1=dsecnd();
05370 printf("TIME ELAPSED TO WRITE THE LEVEL 1p SEGMENTS: %f\n",t1-t0);
05371 }
05372
05373 }
05374
05375
05376
05377
05378
05379 drms_copykeys(recLev1p->records[0],recLev1d->records[0],0, kDRMS_KeyClass_Explicit);
05380
05381
05382 statusA[0] = drms_setkey_float(recLev1p->records[0] ,TFRONTS,TFRONT);
05383 statusA[1] = drms_setkey_float(recLev1p->records[0] ,TSELS,TSEL);
05384 statusA[2] = drms_setkey_int(recLev1p->records[0] ,POLCALMS,method);
05385 statusA[3] = drms_setkey_string(recLev1p->records[0],CODEVER3S,CODEVERSION3);
05386 DSUNOBSint = drms_getkey_double(recLev1d->records[0],DSUNOBSS,&status);
05387 if(status != DRMS_SUCCESS || isnan(DSUNOBSint))
05388 {
05389 printf("Error: %s keyword cannot be read on level 1d data at target time %s\n",DSUNOBSS,timeBegin2);
05390 statusA[4]=1;
05391 }
05392 else
05393 {
05394 ctime1=asin((double)solar_radius/DSUNOBSint)*180.*60.*60./M_PI;
05395 printf("RSUN_OBS = %f\n",ctime1);
05396 statusA[4] = drms_setkey_float(recLev1p->records[0],RSUNOBSS,ctime1);
05397 }
05398 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
05399 statusA[5]= drms_setkey_string(recLev1p->records[0],DATES,DATEOBS);
05400 strcat(source,"]");
05401 statusA[6]= drms_setkey_string(recLev1p->records[0],SOURCES,source);
05402 statusA[7]= drms_setkey_int(recLev1p->records[0],QUALLEV1S,QUALITYLEV1);
05403 statusA[8]= drms_setkey_int(recLev1p->records[0],TINTNUMS,totalTempIntNum);
05404
05405 TotalStatus=0;
05406 for(i=0;i<9;++i) TotalStatus+=statusA[i];
05407 if(TotalStatus != 0)
05408 {
05409 for(i=0;i<9;++i) printf(" %d ",statusA[i]);
05410 printf("\n");
05411 printf("WARNING: could not set some of the keywords for the level 1p data at target time %s\n",timeBegin2);
05412 }
05413
05414
05415
05416
05417 if(Lev1pWanted)
05418 {
05419
05420
05421 X0AVG = (float)drms_getkey_double(recLev1d->records[0],CRPIX1S,&status);
05422 if(status != DRMS_SUCCESS || isnan(X0AVG))
05423 {
05424 printf("Error: %s keyword cannot be read on level 1d data at target time %s\n",CRPIX1S,timeBegin2);
05425 }
05426 X0AVG=X0AVG-1;
05427 printf("X0AVG= %f\n",X0AVG);
05428
05429 Y0AVG = (float)drms_getkey_double(recLev1d->records[0],CRPIX2S,&status);
05430 if(status != DRMS_SUCCESS || isnan(Y0AVG))
05431 {
05432 printf("Error: %s keyword cannot be read on level 1d data at target time %s\n",CRPIX2S,timeBegin2);
05433 }
05434 Y0AVG=Y0AVG-1;
05435 printf("Y0AVG= %f\n",Y0AVG);
05436
05437
05438 for(k=0;k<nRecs1p;++k)
05439 {
05440 for(i=0;i<npolout;++i)
05441 {
05442 strcpy(TOTVALSSS[k*npolout+i],"TOTVALS[");
05443 sprintf(query,"%d",k*npolout+i);
05444 strcat(TOTVALSSS[k*npolout+i],query);
05445 strcat(TOTVALSSS[k*npolout+i],"]");
05446
05447 strcpy(MISSVALSSS[k*npolout+i],"MISSVALS[");
05448 sprintf(query,"%d",k*npolout+i);
05449 strcat(MISSVALSSS[k*npolout+i],query);
05450 strcat(MISSVALSSS[k*npolout+i],"]");
05451
05452 strcpy(DATAVALSSS[k*npolout+i],"DATAVALS[");
05453 sprintf(query,"%d",k*npolout+i);
05454 strcat(DATAVALSSS[k*npolout+i],query);
05455 strcat(DATAVALSSS[k*npolout+i],"]");
05456
05457 strcpy(DATAMEANSS[k*npolout+i],"DATAMEA2[");
05458 sprintf(query,"%d",k*npolout+i);
05459 strcat(DATAMEANSS[k*npolout+i],query);
05460 strcat(DATAMEANSS[k*npolout+i],"]");
05461
05462 strcpy(DATAMINSS[k*npolout+i],"DATAMIN2[");
05463 sprintf(query,"%d",k*npolout+i);
05464 strcat(DATAMINSS[k*npolout+i],query);
05465 strcat(DATAMINSS[k*npolout+i],"]");
05466
05467 strcpy(DATAMAXSS[k*npolout+i],"DATAMAX2[");
05468 sprintf(query,"%d",k*npolout+i);
05469 strcat(DATAMAXSS[k*npolout+i],query);
05470 strcat(DATAMAXSS[k*npolout+i],"]");
05471
05472 strcpy(DATAMEDNSS[k*npolout+i],"DATAMED2[");
05473 sprintf(query,"%d",k*npolout+i);
05474 strcat(DATAMEDNSS[k*npolout+i],query);
05475 strcat(DATAMEDNSS[k*npolout+i],"]");
05476
05477 strcpy(DATARMSSS[k*npolout+i],"DATARMS2[");
05478 sprintf(query,"%d",k*npolout+i);
05479 strcat(DATARMSSS[k*npolout+i],query);
05480 strcat(DATARMSSS[k*npolout+i],"]");
05481
05482 strcpy(DATASKEWSS[k*npolout+i],"DATASKE2[");
05483 sprintf(query,"%d",k*npolout+i);
05484 strcat(DATASKEWSS[k*npolout+i],query);
05485 strcat(DATASKEWSS[k*npolout+i],"]");
05486
05487 strcpy(DATAKURTSS[k*npolout+i],"DATAKUR2[");
05488 sprintf(query,"%d",k*npolout+i);
05489 strcat(DATAKURTSS[k*npolout+i],query);
05490 strcat(DATAKURTSS[k*npolout+i],"]");
05491
05492 strcpy(DATAMINS2S[k*npolout+i],"DATAMIN[");
05493 sprintf(query,"%d",k*npolout+i);
05494 strcat(DATAMINS2S[k*npolout+i],query);
05495 strcat(DATAMINS2S[k*npolout+i],"]");
05496
05497 strcpy(DATAMAXS2S[k*npolout+i],"DATAMAX[");
05498 sprintf(query,"%d",k*npolout+i);
05499 strcat(DATAMAXS2S[k*npolout+i],query);
05500 strcat(DATAMAXS2S[k*npolout+i],"]");
05501
05502 strcpy(DATAMEANS2S[k*npolout+i],"DATAMEAN[");
05503 sprintf(query,"%d",k*npolout+i);
05504 strcat(DATAMEANS2S[k*npolout+i],query);
05505 strcat(DATAMEANS2S[k*npolout+i],"]");
05506
05507 strcpy(DATAMEDNS2S[k*npolout+i],"DATAMEDN[");
05508 sprintf(query,"%d",k*npolout+i);
05509 strcat(DATAMEDNS2S[k*npolout+i],query);
05510 strcat(DATAMEDNS2S[k*npolout+i],"]");
05511
05512 strcpy(DATARMSS2S[k*npolout+i],"DATARMS[");
05513 sprintf(query,"%d",k*npolout+i);
05514 strcat(DATARMSS2S[k*npolout+i],query);
05515 strcat(DATARMSS2S[k*npolout+i],"]");
05516
05517 strcpy(DATASKEWS2S[k*npolout+i],"DATASKEW[");
05518 sprintf(query,"%d",k*npolout+i);
05519 strcat(DATASKEWS2S[k*npolout+i],query);
05520 strcat(DATASKEWS2S[k*npolout+i],"]");
05521
05522 strcpy(DATAKURTS2S[k*npolout+i],"DATAKURT[");
05523 sprintf(query,"%d",k*npolout+i);
05524 strcat(DATAKURTS2S[k*npolout+i],query);
05525 strcat(DATAKURTS2S[k*npolout+i],"]");
05526
05527 image=(float *)arrLev1p[k*npolout+i]->data;
05528
05529
05530 status=fstats(axisout[0]*axisout[1],image,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
05531 if(status != 0)
05532 {
05533 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
05534 }
05535 statusA[6]= drms_setkey_float(recLev1p->records[0],DATAMINSS[k*npolout+i],(float)minimum);
05536 statusA[7]= drms_setkey_float(recLev1p->records[0],DATAMAXSS[k*npolout+i],(float)maximum);
05537 statusA[8]= drms_setkey_float(recLev1p->records[0],DATAMEDNSS[k*npolout+i],(float)median);
05538 statusA[9]= drms_setkey_float(recLev1p->records[0],DATAMEANSS[k*npolout+i],(float)mean);
05539 statusA[10]= drms_setkey_float(recLev1p->records[0],DATARMSSS[k*npolout+i],(float)sigma);
05540 statusA[11]= drms_setkey_float(recLev1p->records[0],DATASKEWSS[k*npolout+i],(float)skewness);
05541 statusA[12]= drms_setkey_float(recLev1p->records[0],DATAKURTSS[k*npolout+i],(float)kurtosis);
05542 statusA[13]= drms_setkey_int(recLev1p->records[0],TOTVALSSS[k*npolout+i],axisout[0]*axisout[1]);
05543 statusA[14]= drms_setkey_int(recLev1p->records[0],DATAVALSSS[k*npolout+i],ngood);
05544 statusA[15]= drms_setkey_int(recLev1p->records[0],MISSVALSSS[k*npolout+i],axisout[0]*axisout[1]-ngood);
05545
05546 for(ii=0;ii<axisout[0]*axisout[1];++ii)
05547 {
05548 row =ii / axisout[0];
05549 column=ii % axisout[0];
05550 distance = sqrt(((float)row-Y0AVG)*((float)row-Y0AVG)+((float)column-X0AVG)*((float)column-X0AVG));
05551 if(distance > 0.99*RSUNint) image[ii]=NAN;
05552 }
05553
05554 status=fstats(axisout[0]*axisout[1],image,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
05555 if(status != 0)
05556 {
05557 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
05558 }
05559 statusA[16]= drms_setkey_float(recLev1p->records[0],DATAMINS2S[k*npolout+i],(float)minimum);
05560 statusA[17]= drms_setkey_float(recLev1p->records[0],DATAMAXS2S[k*npolout+i],(float)maximum);
05561 statusA[18]= drms_setkey_float(recLev1p->records[0],DATAMEDNS2S[k*npolout+i],(float)median);
05562 statusA[19]= drms_setkey_float(recLev1p->records[0],DATAMEANS2S[k*npolout+i],(float)mean);
05563 statusA[20]= drms_setkey_float(recLev1p->records[0],DATARMSS2S[k*npolout+i],(float)sigma);
05564 statusA[21]= drms_setkey_float(recLev1p->records[0],DATASKEWS2S[k*npolout+i],(float)skewness);
05565 statusA[22]= drms_setkey_float(recLev1p->records[0],DATAKURTS2S[k*npolout+i],(float)kurtosis);
05566
05567 TotalStatus=0;
05568 for(ii=6;ii<23;++ii) TotalStatus+=statusA[ii];
05569 if(TotalStatus != 0)
05570 {
05571 for(ii=6;ii<23;++ii) printf(" %d ",statusA[ii]);
05572 printf("\n");
05573 printf("WARNING: could not set some of the keywords for the level 1p data at target time %s\n",timeBegin2);
05574 }
05575
05576 }
05577 }
05578 }
05579
05580 Segments1p=1;
05581
05582 }
05583
05584
05585
05586
05587
05588
05589
05590
05591
05592
05593
05594
05595 if (Lev15Wanted)
05596 {
05597
05598
05599
05600
05601
05602 int ActualnSegs1p=nSegs1p;
05603
05604 if(Segments1p == 0)
05605 {
05606 if(PolarizationType ==2 || PolarizationType ==3) nSegs1p=nRecs1p*2;
05607 if(PolarizationType ==1) nSegs1p=nRecs1p*4;
05608
05609 arrLev1p = (DRMS_Array_t **)malloc(nSegs1p*sizeof(DRMS_Array_t *));
05610 if(arrLev1p == NULL)
05611 {
05612 printf("Error: memory could not be allocated to arrLev1p\n");
05613 return 1;
05614 }
05615
05616
05617
05618
05619
05620
05621
05622
05623
05624
05625 printf("READING %d DATA SEGMENTS OF LEVEL 1p RECORDS\n",nSegs1p);
05626 for(i=0;i<nSegs1p;++i)
05627 {
05628 printf("%d\n",i);
05629 segin = drms_segment_lookupnum(recLev1p->records[0],i);
05630 arrLev1p[i] = drms_segment_read(segin,type1p,&status);
05631 if(status != DRMS_SUCCESS || arrLev1p[i] == NULL)
05632 {
05633 printf("Error: could not read the segment for level 1p data index %d at target time %s \n",i,timeBegin2);
05634 arrLev1p[i] = NULL;
05635 ActualnSegs1p-=1;
05636 }
05637 }
05638
05639
05640
05641 if(PolarizationType == 1)
05642 {
05643 if(ActualnSegs1p != nSegs1p)
05644 {
05645 printf("Error: some level 1p data are missing to produce level 1.5 data: %d\n",ActualnSegs1p);
05646 QUALITY = QUALITY | QUAL_MISSINGLEV1P;
05647 CreateEmptyRecord=1; goto NextTargetTime;
05648 }
05649 else
05650 {
05651 printf("PRODUCING LCP+RCP FROM I,Q,U,V DATA\n");
05652 LCP=(float *)malloc(axisin[0]*axisin[1]*sizeof(float));
05653 RCP=(float *)malloc(axisin[0]*axisin[1]*sizeof(float));
05654 if(LCP == NULL || RCP == NULL)
05655 {
05656 printf("Error: could not create LCP and/or RCP array \n");
05657 return 1;
05658 }
05659 j=0;
05660 for (i=0;i<nRecs1p;++i)
05661 {
05662 temparr1=(float *)arrLev1p[i*4]->data;
05663 temparr2=(float *)arrLev1p[i*4+3]->data;
05664 temparr3=(float *)arrLev1p[j*2]->data;
05665 temparr4=(float *)arrLev1p[j*2+1]->data;
05666 for(ii=0;ii<axisin[0]*axisin[1];++ii)
05667 {
05668 LCP[ii]=temparr1[ii]+temparr2[ii];
05669 RCP[ii]=temparr1[ii]-temparr2[ii];
05670 temparr3[ii]=LCP[ii];
05671 temparr4[ii]=RCP[ii];
05672 }
05673 j+=1;
05674 }
05675 free(LCP);
05676 free(RCP);
05677 LCP=NULL;
05678 RCP=NULL;
05679 PolarizationType=3;
05680 nSegs1p=nRecs1p*2;
05681 ActualnSegs1p = nSegs1p;
05682 for(i=nSegs1p;i<nRecs1p*4;++i) if(arrLev1p[i] != NULL)
05683 {
05684 drms_free_array(arrLev1p[i]);
05685 arrLev1p[i]=NULL;
05686 }
05687 }
05688 }
05689
05690 printf("READING DONE\n");
05691
05692
05693 TargetHFLID = drms_getkey_int(recLev1p->records[0],HFLIDS,&status);
05694 if(status != DRMS_SUCCESS)
05695 {
05696 printf("Error: HFLID keyword cannot be read on level 1p data at target time %s\n",timeBegin2);
05697 CreateEmptyRecord=1; goto NextTargetTime;
05698 }
05699 TargetHPLTID = drms_getkey_int(recLev1p->records[0],HPLTIDS,&status);
05700 if(status != DRMS_SUCCESS)
05701 {
05702 printf("Error: HPLTID keyword cannot be read on level 1p data at target time %s\n",timeBegin2);
05703 CreateEmptyRecord=1; goto NextTargetTime;
05704 }
05705 TargetHWLTID = drms_getkey_int(recLev1p->records[0],HWLTIDS,&status);
05706 if(status != DRMS_SUCCESS)
05707 {
05708 printf("Error: HWLTID keyword cannot be read on level 1p data at target time %s\n",timeBegin2);
05709 CreateEmptyRecord=1; goto NextTargetTime;
05710 }
05711 WavelengthID2 = drms_getkey_int(recLev1p->records[0],WavelengthIDS,&status);
05712 if(status != DRMS_SUCCESS)
05713 {
05714 printf("Error: WavelengthID2 keyword cannot be read on level 1p data at target time %s\n",timeBegin2);
05715 CreateEmptyRecord=1; goto NextTargetTime;
05716 }
05717 if(WavelengthID2 != WavelengthID)
05718 {
05719 printf("Error: WavelengthID2 != WavelengthID\n");
05720 return 1;
05721 }
05722
05723 Segments1p=1;
05724 framelistSize = framelistInfo(TargetHFLID,TargetHPLTID,TargetHWLTID,WavelengthID,PHWPLPOS,WavelengthIndex,WavelengthLocation,&PolarizationType,CamId,&combine,&npol,MaxNumFiltergrams,&CadenceRead,CameraValues,FIDValues,dpath);
05725 if(framelistSize == 1) return 1;
05726 }
05727
05728
05729
05730
05731 if(ActualnSegs1p != nSegs1p)
05732 {
05733 printf("Error: some level 1p data are missing to produce level 1.5 data: %d\n",ActualnSegs1p);
05734 QUALITY = QUALITY | QUAL_MISSINGLEV1P;
05735 CreateEmptyRecord=1; goto NextTargetTime;
05736 }
05737
05738
05739
05740
05741 i=0;
05742 while(WavelengthIndex[i] != 2) i++;
05743 int HCMNBT,HCMWBT,HCMPOLT,HCME1T;
05744
05745 if( (framelistSize/npol == 6) || (framelistSize/npol == 8) || (framelistSize/npol == 10) )
05746 {
05747 HCMNBT = PHWPLPOS[7*i+3]+12;
05748 HCMWBT = PHWPLPOS[7*i+1]+6;
05749 HCMPOLT= PHWPLPOS[7*i+2];
05750 HCME1T = PHWPLPOS[7*i+0]-3;
05751 }
05752 if(framelistSize/npol == 5)
05753 {
05754 HCMNBT = PHWPLPOS[7*i+3];
05755 HCMWBT = PHWPLPOS[7*i+1];
05756 HCMPOLT= PHWPLPOS[7*i+2];
05757 HCME1T = PHWPLPOS[7*i+0];
05758 }
05759 printf("KEYWORD VALUES: %d %d %d %d\n",HCMNBT,HCMWBT,HCME1T,HCMPOLT);
05760
05761 char keylist[]="HWL4POS,HWL3POS,HWL2POS,HWL1POS,NWL,HCAMID,FSN_REC";
05762 int unique=0;
05763 int n0,n1;
05764
05765 int NBC,WBC,E1C,POLC,NC,CAMERAUSED,FSNLOOKUP;
05766
05767 arrayL0 = drms_record_getvector(drms_env,HMISeriesLookup, keylist, typeLO, unique, &status);
05768 if(status != DRMS_SUCCESS)
05769 {
05770 printf("Error: cannot read a list of keywords in the look-up table series\n");
05771 QUALITY = QUALITY | QUAL_NOLOOKUPKEYWORD;
05772 CreateEmptyRecord=1; goto NextTargetTime;
05773 }
05774 printf("DIMENSIONS= %d %d\n",arrayL0->axis[0],arrayL0->axis[1]);
05775 keyL=arrayL0->data;
05776 arrayL1 = drms_record_getvector(drms_env,HMISeriesLookup,TRECS,DRMS_TYPE_DOUBLE , unique, &status);
05777 if(status != DRMS_SUCCESS)
05778 {
05779 printf("Error: cannot read a list of keywords in the look-up table series\n");
05780 QUALITY = QUALITY | QUAL_NOLOOKUPKEYWORD;
05781 CreateEmptyRecord=1; goto NextTargetTime;
05782 }
05783
05784 timeL=arrayL1->data;
05785
05786 n1=arrayL0->axis[1];
05787 n0=arrayL0->axis[0];
05788 if(n1 != arrayL1->axis[1])
05789 {
05790 printf("Error: The number of look-up table records identified by T_REC is not the same as the number of records identified by HWL4POS,HWL3POS,HWL2POS,HWL1POS, and NWL\n");
05791 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05792 CreateEmptyRecord=1; goto NextTargetTime;
05793 }
05794 printf("%d RECORDS FOUND FOR THE LOOK-UP TABLES\n",n1);
05795
05796 count = (double *)malloc(n1*sizeof(double));
05797 if(count == NULL)
05798 {
05799 printf("Error: memory could not be allocated to count\n");
05800 return 1;
05801 }
05802
05803 temptime = 1000000000.0;
05804 temp = 0;
05805
05806 for(i=0;i<n1;++i)
05807 {
05808 count[i] = fabs(timeL[i]-TargetTime);
05809 NBC = abs(keyL[ i]-HCMNBT);
05810 POLC= abs(keyL[ n1+i]-HCMPOLT);
05811 WBC = abs(keyL[2*n1+i]-HCMWBT);
05812 E1C = abs(keyL[3*n1+i]-HCME1T);
05813 NC = abs(keyL[4*n1+i]-framelistSize/npol);
05814 CAMERAUSED = abs(keyL[5*n1+i]-CamId);
05815 if(count[i] < temptime && NBC+WBC+POLC+E1C+NC+CAMERAUSED == 0)
05816 {
05817 temptime=count[i];
05818 temp=i;
05819 }
05820 }
05821 if(temptime == 1000000000.0)
05822 {
05823 printf("Error: could not find a look-up table with the correct keywords to produce level 1.5 data\n");
05824 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05825 CreateEmptyRecord=1; goto NextTargetTime;
05826 }
05827
05828 printf("Index of the retrieved look-up table %d %d\n",temp,n1);
05829 printf("Keyword values of the retrieved look-up table: %d %d %d %d %d %d %d\n",keyL[temp]-HCMNBT,keyL[n1+temp]-HCMPOLT,keyL[2*n1+temp]-HCMWBT,keyL[3*n1+temp]-HCME1T,keyL[4*n1+temp]-framelistSize/npol,keyL[5*n1+temp]-CamId,keyL[6*n1+temp]);
05830 FSNLOOKUP = keyL[6*n1+temp];
05831
05832
05833 sprintf(query,"%d",FSNLOOKUP);
05834 strcpy(HMILookup,HMISeriesLookup);
05835 strcat(HMILookup,"[");
05836 strcat(HMILookup,query);
05837 strcat(HMILookup,"][][");
05838 if(CamId == 0) strcat(HMILookup,"0");
05839 if(CamId == 1) strcat(HMILookup,"1");
05840 if(CamId == 2) strcat(HMILookup,"2");
05841 if(CamId == 3) strcat(HMILookup,"3");
05842 strcat(HMILookup,"][");
05843 sprintf(query,"%d",HCME1T);
05844 strcat(HMILookup,query);
05845 strcat(HMILookup,"][");
05846 sprintf(query,"%d",HCMWBT);
05847 strcat(HMILookup,query);
05848 strcat(HMILookup,"][");
05849 sprintf(query,"%d",HCMPOLT);
05850 strcat(HMILookup,query);
05851 strcat(HMILookup,"][");
05852 sprintf(query,"%d",HCMNBT);
05853 strcat(HMILookup,query);
05854 strcat(HMILookup,"][");
05855 NC=framelistSize/npol;
05856 sprintf(query,"%d",NC);
05857 strcat(HMILookup,query);
05858 strcat(HMILookup,"]");
05859
05860 printf("QUERY= %s\n",HMILookup);
05861
05862 drms_free_array(arrayL0);
05863 arrayL0=NULL;
05864 drms_free_array(arrayL1);
05865 arrayL1=NULL;
05866 free(count);
05867 count=NULL;
05868
05869 lookup = drms_open_records(drms_env,HMILookup,&status);
05870 if (status == DRMS_SUCCESS && lookup != NULL)
05871 {
05872 if (lookup->n > 1)
05873 {
05874 printf("Error: more than 1 lookup table record was downloaded.\n");
05875 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05876 CreateEmptyRecord=1; goto NextTargetTime;
05877 }
05878 if (lookup->n <= 0)
05879 {
05880 printf("Error:no record for the look-up tables were downloaded.\n");
05881 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05882 CreateEmptyRecord=1; goto NextTargetTime;
05883 }
05884 }
05885 else
05886 {
05887 printf("Error: can't open the look-up table series.\n");
05888 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05889 CreateEmptyRecord=1; goto NextTargetTime;
05890 }
05891
05892 segin = drms_segment_lookupnum(lookup->records[0], 0);
05893 arrintable= drms_segment_read(segin, segin->info->type, &status);
05894 if (status != DRMS_SUCCESS || arrintable == NULL)
05895 {
05896 printf("Error: unable to read the data segment of the look-up table record\n");
05897 return 1;
05898
05899
05900 }
05901 else printf("look-up table record read\n");
05902
05903
05904
05905
05906
05907 int FSNDIFF;
05908 char keylistCoeff[]="COEFF0,COEFF1,COEFF2,COEFF3";
05909
05910 arrayL0 = drms_record_getvector(drms_env,HMISeriesCoeffs, keylistCoeff, DRMS_TYPE_DOUBLE, unique, &status);
05911 if(status != DRMS_SUCCESS)
05912 {
05913 printf("Error: cannot read a list of keywords in the polynomial coefficient series\n");
05914 QUALITY = QUALITY | QUAL_NOCOEFFKEYWORD;
05915 CreateEmptyRecord=1; goto NextTargetTime;
05916 }
05917 TIME *keyt=NULL;
05918 keyt=arrayL0->data;
05919
05920 arrayL1 = drms_record_getvector(drms_env,HMISeriesCoeffs,TRECS,DRMS_TYPE_DOUBLE, unique, &status);
05921 if(status != DRMS_SUCCESS)
05922 {
05923 printf("Error: cannot read a list of keywords in the polynomial coefficient series\n");
05924 QUALITY = QUALITY | QUAL_NOCOEFFKEYWORD;
05925 CreateEmptyRecord=1; goto NextTargetTime;
05926 }
05927 timeL=arrayL1->data;
05928
05929 arrayL2 = drms_record_getvector(drms_env,HMISeriesCoeffs,CALFSNS,DRMS_TYPE_INT, unique, &status);
05930 if(status != DRMS_SUCCESS)
05931 {
05932 printf("Error: cannot read a list of keywords in the polynomial coefficient series\n");
05933 QUALITY = QUALITY | QUAL_NOCOEFFKEYWORD;
05934 CreateEmptyRecord=1; goto NextTargetTime;
05935 }
05936 FSNL=arrayL2->data;
05937
05938 n1=arrayL0->axis[1];
05939 n0=arrayL0->axis[0];
05940 if(n1 != arrayL1->axis[1] || n1 != arrayL2->axis[1])
05941 {
05942 printf("Error: The number of polynomial coefficient records identified by T_REC is not the same as the number of records identified by COEFF0, COEFF1, COEFF2, and COEFF3, or by FSN_REC\n");
05943 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05944 CreateEmptyRecord=1; goto NextTargetTime;
05945 }
05946 printf("%d RECORDS FOUND FOR THE POLYNOMIAL COEFFICIENTS\n",n1);
05947
05948 count = (double *)malloc(n1*sizeof(double));
05949 if(count == NULL)
05950 {
05951 printf("Error: memory could not be allocated to count\n");
05952 return 1;
05953 }
05954
05955
05956 if(QuickLook != 1)
05957 {
05958 temptime = 1000000000.0;
05959 temp = 0;
05960 temp2= 0;
05961
05962 for(i=0;i<n1;++i)
05963 {
05964 count[i] = fabs(timeL[i]-TargetTime);
05965 FSNDIFF = FSNL[i]-FSNLOOKUP;
05966 if(count[i] < temptime && FSNDIFF == 0 && timeL[i]<TargetTime)
05967 {
05968 temptime=count[i];
05969 temp=i;
05970 }
05971 }
05972 if(temptime > 86400.0)
05973 {
05974 printf("Error: could not find polynomial coefficients with the correct keywords and within 24 hours of the target time to produce level 1.5 data\n");
05975 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05976 CreateEmptyRecord=1; goto NextTargetTime;
05977 }
05978
05979 temptime = 1000000000.0;
05980
05981 for(i=0;i<n1;++i)
05982 {
05983 count[i] = fabs(timeL[i]-TargetTime);
05984 FSNDIFF = FSNL[i]-FSNLOOKUP;
05985 if(count[i] < temptime && FSNDIFF == 0 && timeL[i]>=TargetTime)
05986 {
05987 temptime=count[i];
05988 temp2=i;
05989 }
05990 }
05991 if(temptime > 86400.0)
05992 {
05993 printf("Error: could not find polynomial coefficients with the correct keywords and within 12 hours of the target time to produce level 1.5 data\n");
05994 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05995 CreateEmptyRecord=1; goto NextTargetTime;
05996 }
05997
05998 }
05999 else
06000 {
06001
06002 temptime = 1000000000.0;
06003 temp = 0;
06004
06005 for(i=0;i<n1;++i)
06006 {
06007 count[i] = fabs(timeL[i]-TargetTime);
06008 if(count[i] < temptime)
06009 {
06010 temptime=count[i];
06011 temp=i;
06012 }
06013 }
06014 temp2=temp;
06015 }
06016
06017 printf("Indeces of the retrieved polynomial record %d %d %d\n",temp,temp2,n1);
06018 printf("Keyword values of the retrieved polynomial record: %d\n",FSNL[temp]-FSNLOOKUP);
06019
06020
06021 sprint_time(query,timeL[temp],"TAI",1);
06022 strcpy(HMICoeffs,HMISeriesCoeffs);
06023 strcat(HMICoeffs,"[");
06024 strcat(HMICoeffs,query);
06025 strcat(HMICoeffs,"]");
06026
06027 printf("QUERY= %s\n",HMICoeffs);
06028
06029 recpoly = drms_open_records(drms_env,HMICoeffs,&status);
06030 if (status == DRMS_SUCCESS && recpoly != NULL && recpoly->n != 0)
06031 {
06032 coeff[0]=drms_getkey_double(recpoly->records[0],COEFF0S,&status);
06033 if(status != DRMS_SUCCESS)
06034 {
06035 printf("Error: could not read a polynomial coefficient\n");
06036 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
06037 CreateEmptyRecord=1; goto NextTargetTime;
06038 }
06039 coeff[1]=drms_getkey_double(recpoly->records[0],COEFF1S,&status);
06040 if(status != DRMS_SUCCESS)
06041 {
06042 printf("Error: could not read a polynomial coefficient\n");
06043 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
06044 CreateEmptyRecord=1; goto NextTargetTime;
06045 }
06046 coeff[2]=drms_getkey_double(recpoly->records[0],COEFF2S,&status);
06047 if(status != DRMS_SUCCESS)
06048 {
06049 printf("Error: could not read a polynomial coefficient\n");
06050 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
06051 CreateEmptyRecord=1; goto NextTargetTime;
06052 }
06053 coeff[3]=drms_getkey_double(recpoly->records[0],COEFF3S,&status);
06054 if(status != DRMS_SUCCESS)
06055 {
06056 printf("Error: could not read a polynomial coefficient\n");
06057 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
06058 CreateEmptyRecord=1; goto NextTargetTime;
06059 }
06060 }
06061 else
06062 {
06063 printf("Error: can't open the polynomial coefficients series.\n");
06064 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
06065 CreateEmptyRecord=1; goto NextTargetTime;
06066 }
06067
06068
06069 if(QuickLook != 1)
06070 {
06071
06072 sprint_time(query,timeL[temp2],"TAI",1);
06073 strcpy(HMICoeffs,HMISeriesCoeffs);
06074 strcat(HMICoeffs,"[");
06075 strcat(HMICoeffs,query);
06076 strcat(HMICoeffs,"]");
06077
06078 printf("QUERY= %s\n",HMICoeffs);
06079
06080 recpoly2 = drms_open_records(drms_env,HMICoeffs,&status);
06081 if (status == DRMS_SUCCESS && recpoly2 != NULL && recpoly2->n != 0)
06082 {
06083 coeff2[0]=drms_getkey_double(recpoly2->records[0],COEFF0S,&status);
06084 if(status != DRMS_SUCCESS)
06085 {
06086 printf("Error: could not read a polynomial coefficient\n");
06087 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
06088 CreateEmptyRecord=1; goto NextTargetTime;
06089 }
06090 coeff2[1]=drms_getkey_double(recpoly2->records[0],COEFF1S,&status);
06091 if(status != DRMS_SUCCESS)
06092 {
06093 printf("Error: could not read a polynomial coefficient\n");
06094 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
06095 CreateEmptyRecord=1; goto NextTargetTime;
06096 }
06097 coeff2[2]=drms_getkey_double(recpoly2->records[0],COEFF2S,&status);
06098 if(status != DRMS_SUCCESS)
06099 {
06100 printf("Error: could not read a polynomial coefficient\n");
06101 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
06102 CreateEmptyRecord=1; goto NextTargetTime;
06103 }
06104 coeff2[3]=drms_getkey_double(recpoly2->records[0],COEFF3S,&status);
06105 if(status != DRMS_SUCCESS)
06106 {
06107 printf("Error: could not read a polynomial coefficient\n");
06108 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
06109 CreateEmptyRecord=1; goto NextTargetTime;
06110 }
06111 }
06112 else
06113 {
06114 printf("Error: can't open the polynomial coefficients series.\n");
06115 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
06116 CreateEmptyRecord=1; goto NextTargetTime;
06117 }
06118 }
06119 else recpoly2 = NULL;
06120
06121
06122 printf("Polynomial coefficient values: %e %e %e %e\n",coeff[0],coeff[1],coeff[2],coeff[3]);
06123
06124 if(QuickLook != 1)
06125 {
06126 printf("Polynomial coefficient values: %e %e %e %e\n",coeff2[0],coeff2[1],coeff2[2],coeff2[3]);
06127 coeff[0]=(TargetTime-timeL[temp])*(coeff2[0]-coeff[0])/(timeL[temp2]-timeL[temp])+coeff[0];
06128 coeff[1]=(TargetTime-timeL[temp])*(coeff2[1]-coeff[1])/(timeL[temp2]-timeL[temp])+coeff[1];
06129 coeff[2]=(TargetTime-timeL[temp])*(coeff2[2]-coeff[2])/(timeL[temp2]-timeL[temp])+coeff[2];
06130 coeff[3]=(TargetTime-timeL[temp])*(coeff2[3]-coeff[3])/(timeL[temp2]-timeL[temp])+coeff[3];
06131 }
06132
06133
06134 drms_free_array(arrayL0);
06135 arrayL0=NULL;
06136 drms_free_array(arrayL1);
06137 arrayL1=NULL;
06138 drms_free_array(arrayL2);
06139 arrayL2=NULL;
06140 free(count);
06141 count=NULL;
06142
06143 strcpy(HISTORY,"Polynomial Coefficients used for Doppler velocity correction: ");
06144 sprintf(query,"%e",coeff[0]);
06145 strcat(HISTORY,query);
06146 strcat(HISTORY," ");
06147 sprintf(query,"%e",coeff[1]);
06148 strcat(HISTORY,query);
06149 strcat(HISTORY," ");
06150 sprintf(query,"%e",coeff[2]);
06151 strcat(HISTORY,query);
06152 strcat(HISTORY," ");
06153 sprintf(query,"%e",coeff[3]);
06154 strcat(HISTORY,query);
06155 strcat(HISTORY," ");
06156
06157
06158
06159
06160
06161 nRecs15 = 6;
06162
06163 recLev15a = drms_create_records(drms_env,1,HMISeriesLev15a,DRMS_PERMANENT,&statusA[0]);
06164 recLev15b = drms_create_records(drms_env,1,HMISeriesLev15b,DRMS_PERMANENT,&statusA[1]);
06165 recLev15c = drms_create_records(drms_env,1,HMISeriesLev15c,DRMS_PERMANENT,&statusA[2]);
06166 recLev15d = drms_create_records(drms_env,1,HMISeriesLev15d,DRMS_PERMANENT,&statusA[3]);
06167 recLev15e = drms_create_records(drms_env,1,HMISeriesLev15e,DRMS_PERMANENT,&statusA[4]);
06168 printf("Observables will be saved in the following series:\n %s \n %s \n %s \n %s \n %s \n",HMISeriesLev15a,HMISeriesLev15b,HMISeriesLev15c,HMISeriesLev15d,HMISeriesLev15e);
06169
06170
06171 if ( (statusA[0]+statusA[1]+statusA[2]+statusA[3]+statusA[4]) != DRMS_SUCCESS || recLev15a == NULL || recLev15b == NULL || recLev15c == NULL|| recLev15d == NULL || recLev15e == NULL)
06172 {
06173 printf("Could not create a record for one or several level 1.5 data series, at target time %s\n",timeBegin2);
06174
06175
06176
06177
06178
06179
06180
06181 return 1;
06182 }
06183 if(recLev15a->n == 0 || recLev15b->n == 0 || recLev15c->n == 0 || recLev15d->n == 0 || recLev15e->n == 0)
06184 {
06185 printf("Could not create a record for one or several level 1.5 data series, at target time %s\n",timeBegin2);
06186
06187
06188
06189
06190
06191
06192
06193 return 1;
06194 }
06195
06196
06197 arrLev15 = (DRMS_Array_t **)malloc(nRecs15*sizeof(DRMS_Array_t *));
06198 if(arrLev15 == NULL)
06199 {
06200 printf("Error: memory could not be allocated to arrLev15\n");
06201 return 1;
06202 }
06203 for (i=0;i<nRecs15;++i)
06204 {
06205 arrLev15[i] = drms_array_create(type15,2,axisout,NULL,&status);
06206 if(status != DRMS_SUCCESS || arrLev15[i] == NULL)
06207 {
06208 printf("Error: cannot create an array for a level 1.5 data at target time %s\n",timeBegin2);
06209
06210
06211 return 1;
06212 }
06213
06214 }
06215
06216
06217
06218 X0AVG = (float)drms_getkey_double(recLev1p->records[0],CRPIX1S,&status);
06219 if(status != DRMS_SUCCESS || isnan(X0AVG))
06220 {
06221 printf("Error: %s keyword cannot be read on level 1p data at target time %s\n",CRPIX1S,timeBegin2);
06222 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1P;
06223 CreateEmptyRecord=1; goto NextTargetTime;
06224 }
06225 X0AVG=X0AVG-1;
06226
06227 Y0AVG = (float)drms_getkey_double(recLev1p->records[0],CRPIX2S,&status);
06228 if(status != DRMS_SUCCESS || isnan(Y0AVG))
06229 {
06230 printf("Error: %s keyword cannot be read on level 1p data at target time %s\n",CRPIX2S,timeBegin2);
06231 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1P;
06232 CreateEmptyRecord=1; goto NextTargetTime;
06233 }
06234 Y0AVG=Y0AVG-1;
06235
06236 DSUNOBSint = drms_getkey_double(recLev1p->records[0],DSUNOBSS,&status);
06237 if(status != DRMS_SUCCESS || isnan(DSUNOBSint))
06238 {
06239 printf("Error: %s keyword cannot be read on level 1p data at target time %s\n",DSUNOBSS,timeBegin2);
06240 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1P;
06241 CreateEmptyRecord=1; goto NextTargetTime;
06242 }
06243
06244 cdelt1 = (float)drms_getkey_double(recLev1p->records[0],CDELT1S,&status);
06245 if(status != DRMS_SUCCESS || isnan(cdelt1))
06246 {
06247 printf("Error: %s keyword cannot be read on level 1p data at target time %s\n",CDELT1S,timeBegin2);
06248 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1P;
06249 CreateEmptyRecord=1; goto NextTargetTime;
06250 }
06251
06252
06253
06254
06255
06256
06257
06258
06259
06260
06261 RSUNint=1.0/cdelt1*asin((double)solar_radius/DSUNOBSint)*180.*60.*60./M_PI;
06262
06263
06264 DopplerParameters.FSRNB=FSR[0];
06265 DopplerParameters.FSRWB=FSR[1];
06266 DopplerParameters.FSRE1=FSR[2];
06267 DopplerParameters.FSRE2=FSR[3];
06268 DopplerParameters.FSRE3=FSR[4];
06269 DopplerParameters.FSRE4=FSR[5];
06270 DopplerParameters.FSRE5=FSR[6];
06271 DopplerParameters.dlamdv=dlamdv;
06272 DopplerParameters.maxVtest=ntest*2;
06273 DopplerParameters.maxNx=maxNx;
06274 DopplerParameters.ntest=ntest;
06275 DopplerParameters.dvtest=dvtest;
06276 DopplerParameters.MISSINGDATA=MISSINGDATA;
06277 DopplerParameters.MISSINGRESULT=MISSINGRESULT;
06278 DopplerParameters.coeff0=coeff[0];
06279 DopplerParameters.coeff1=coeff[1];
06280 DopplerParameters.coeff2=coeff[2];
06281 DopplerParameters.coeff3=coeff[3];
06282 DopplerParameters.QuickLook=QuickLook;
06283
06284 if(framelistSize/2 == 10 || framelistSize/2 == 8 || framelistSize/2 == 20)
06285 {
06286 ntest=1333;
06287 DopplerParameters.maxVtest=ntest*2;
06288 DopplerParameters.ntest=ntest;
06289 }
06290
06291 t0=dsecnd();
06292
06293 Dopplergram_largercrop(arrLev1p,arrLev15,nSegs1p,arrintable,RSUNint,X0AVG,Y0AVG,DopplerParameters,MISSVALS,&SATVALS,cdelt1,TargetTime);
06294
06295 t1=dsecnd();
06296 printf("TIME ELAPSED IN DOPPLERGRAM(): %f\n",t1-t0);
06297
06298 printf("KEYWORDS OF Dopplergram() %f %f %f\n",RSUNint,X0AVG,Y0AVG);
06299 printf("%f %f %f %f %f %f %f %f %d %d %d %f %f %f \n", DopplerParameters.FSRNB,DopplerParameters.FSRWB,DopplerParameters.FSRE1,DopplerParameters.FSRE2,DopplerParameters.FSRE3,DopplerParameters.FSRE4,DopplerParameters.FSRE5,DopplerParameters.dlamdv,DopplerParameters.maxVtest,DopplerParameters.maxNx,DopplerParameters.ntest,DopplerParameters.dvtest,DopplerParameters.MISSINGDATA,DopplerParameters.MISSINGRESULT);
06300
06301
06302 t0=dsecnd();
06303 segout = drms_segment_lookupnum(recLev15a->records[0], 0);
06304 arrLev15[0]->bzero=segout->bzero;
06305 arrLev15[0]->bscale=segout->bscale;
06306 arrLev15[0]->israw=0;
06307 status=drms_segment_write(segout,arrLev15[0], 0);
06308 if(status != DRMS_SUCCESS)
06309 {
06310 printf("Error: a call to drms_segment_write failed\n");
06311 return 1;
06312 }
06313
06314 segout = drms_segment_lookupnum(recLev15b->records[0], 0);
06315 arrLev15[1]->bzero=segout->bzero;
06316 arrLev15[1]->bscale=segout->bscale;
06317 arrLev15[1]->israw=0;
06318 status=drms_segment_write(segout,arrLev15[1], 0);
06319 if(status != DRMS_SUCCESS)
06320 {
06321 printf("Error: a call to drms_segment_write failed\n");
06322 return 1;
06323 }
06324
06325 segout = drms_segment_lookupnum(recLev15c->records[0], 0);
06326 arrLev15[2]->bzero=segout->bzero;
06327 arrLev15[2]->bscale=segout->bscale;
06328 arrLev15[2]->israw=0;
06329 status=drms_segment_write(segout,arrLev15[2], 0);
06330 if(status != DRMS_SUCCESS)
06331 {
06332 printf("Error: a call to drms_segment_write failed\n");
06333 return 1;
06334 }
06335
06336 segout = drms_segment_lookupnum(recLev15d->records[0], 0);
06337 arrLev15[3]->bzero=segout->bzero;
06338 arrLev15[3]->bscale=segout->bscale;
06339 arrLev15[3]->israw=0;
06340 status=drms_segment_write(segout,arrLev15[3], 0);
06341 if(status != DRMS_SUCCESS)
06342 {
06343 printf("Error: a call to drms_segment_write failed\n");
06344 return 1;
06345 }
06346
06347 segout = drms_segment_lookupnum(recLev15e->records[0], 0);
06348 arrLev15[4]->bzero=segout->bzero;
06349 arrLev15[4]->bscale=segout->bscale;
06350 arrLev15[4]->israw=0;
06351 status=drms_segment_write(segout,arrLev15[4], 0);
06352 if(status != DRMS_SUCCESS)
06353 {
06354 printf("Error: a call to drms_segment_write failed\n");
06355 return 1;
06356 }
06357
06358 t1=dsecnd();
06359 printf("TIME ELAPSED TO WRITE THE LEVEL 1.5 SEGMENTS: %f\n",t1-t0);
06360
06361
06362
06363 image0=(float *)arrLev15[5]->data;
06364
06365 for(i=0;i<axisout[0]*axisout[1];++i)
06366 {
06367 row =i / axisout[0];
06368 column=i % axisout[0];
06369 distance = sqrt(((float)row-Y0AVG)*((float)row-Y0AVG)+((float)column-X0AVG)*((float)column-X0AVG));
06370 if(distance > 0.99*RSUNint)
06371 {
06372 image0[i]=NAN;
06373 }
06374 }
06375 status=fstats(axisout[0]*axisout[1],arrLev15[5]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06376 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06377 statusA[2]= drms_setkey_float(recLev15a->records[0],RAWMEDNS,(float)median);
06378 if(statusA[2] != 0)
06379 {
06380 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the Dopplergram at target time %s %f\n",timeBegin2,(float)median);
06381 }
06382
06383
06384
06385 t0=dsecnd();
06386 drms_copykeys(recLev15a->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06387
06388 status=fstats(axisout[0]*axisout[1],arrLev15[0]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06389 if(status != 0)
06390 {
06391 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06392 }
06393
06394 image=arrLev15[0]->data;
06395 for(i=0;i<axisout[0]*axisout[1];i++) if (image[i] > (32767.*arrLev15[0]->bscale+arrLev15[0]->bzero) || image[i] < (-32768.*arrLev15[0]->bscale+arrLev15[0]->bzero))
06396 {
06397 MISSVALS[0]+=1;
06398 ngood -= 1;
06399 }
06400
06401
06402
06403 statusA[0]= drms_setkey_int(recLev15a->records[0],TOTVALSS,ngood+MISSVALS[0]);
06404 statusA[1]= drms_setkey_int(recLev15a->records[0],DATAVALSS,ngood);
06405
06406 statusA[2]= drms_setkey_int(recLev15a->records[0],MISSVALSS,MISSVALS[0]);
06407 statusA[3]= drms_setkey_float(recLev15a->records[0],DATAMINS,(float)minimum);
06408 statusA[4]= drms_setkey_float(recLev15a->records[0],DATAMAXS,(float)maximum);
06409 statusA[5]= drms_setkey_float(recLev15a->records[0],DATAMEDNS,(float)median);
06410 statusA[6]= drms_setkey_float(recLev15a->records[0],DATAMEANS,(float)mean);
06411 statusA[7]= drms_setkey_float(recLev15a->records[0],DATARMSS,(float)sigma);
06412 statusA[8]= drms_setkey_float(recLev15a->records[0],DATASKEWS,(float)skewness);
06413 statusA[9]= drms_setkey_float(recLev15a->records[0],DATAKURTS,(float)kurtosis);
06414 statusA[10]=drms_setkey_int(recLev15a->records[0],CALFSNS,FSNLOOKUP);
06415 statusA[11]=drms_setkey_string(recLev15a->records[0],LUTQUERYS,HMILookup);
06416 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06417 statusA[12]= drms_setkey_string(recLev15a->records[0],DATES,DATEOBS);
06418 statusA[13]= drms_setkey_int(recLev15a->records[0],QUALITYS,QUALITY);
06419 statusA[14]= drms_setkey_int(recLev15a->records[0],SATVALSS,SATVALS);
06420 statusA[15]= drms_setkey_string(recLev15a->records[0],SOURCES,source);
06421 statusA[16]= drms_setkey_int(recLev15a->records[0],QUALLEV1S,QUALITYLEV1);
06422 statusA[17]= drms_setkey_string(recLev15a->records[0],COMMENTS,COMMENT);
06423 statusA[18]=0;
06424 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15a->records[0],CALVER64S,CALVER64);
06425
06426 TotalStatus=0;
06427 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06428 if(TotalStatus != 0)
06429 {
06430 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the Dopplergram at target time %s\n",timeBegin2);
06431 }
06432
06433
06434
06435 drms_copykeys(recLev15b->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06436
06437 status=fstats(axisout[0]*axisout[1],arrLev15[1]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06438 if(status != 0)
06439 {
06440 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06441 }
06442
06443 image=arrLev15[1]->data;
06444 for(i=0;i<axisout[0]*axisout[1];i++) if (image[i] > (2147483647.*arrLev15[1]->bscale+arrLev15[1]->bzero) || image[i] < (-2147483648.*arrLev15[1]->bscale+arrLev15[1]->bzero))
06445 {
06446 MISSVALS[1]+=1;
06447 ngood -= 1;
06448 }
06449
06450
06451 statusA[0]= drms_setkey_int(recLev15b->records[0],TOTVALSS,ngood+MISSVALS[1]);
06452 statusA[1]= drms_setkey_int(recLev15b->records[0],DATAVALSS,ngood);
06453 statusA[2]= drms_setkey_int(recLev15b->records[0],MISSVALSS,MISSVALS[1]);
06454 statusA[3]= drms_setkey_float(recLev15b->records[0],DATAMINS,(float)minimum);
06455 statusA[4]= drms_setkey_float(recLev15b->records[0],DATAMAXS,(float)maximum);
06456 statusA[5]= drms_setkey_float(recLev15b->records[0],DATAMEDNS,(float)median);
06457 statusA[6]= drms_setkey_float(recLev15b->records[0],DATAMEANS,(float)mean);
06458 statusA[7]= drms_setkey_float(recLev15b->records[0],DATARMSS,(float)sigma);
06459 statusA[8]= drms_setkey_float(recLev15b->records[0],DATASKEWS,(float)skewness);
06460 statusA[9]= drms_setkey_float(recLev15b->records[0],DATAKURTS,(float)kurtosis);
06461 statusA[10]=drms_setkey_int(recLev15b->records[0],CALFSNS,FSNLOOKUP);
06462 statusA[11]=drms_setkey_string(recLev15b->records[0],LUTQUERYS,HMILookup);
06463 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06464 statusA[12]= drms_setkey_string(recLev15b->records[0],DATES,DATEOBS);
06465 statusA[13]= drms_setkey_int(recLev15b->records[0],QUALITYS,QUALITY);
06466 statusA[14]= drms_setkey_int(recLev15b->records[0],SATVALSS,SATVALS);
06467 statusA[15]= drms_setkey_string(recLev15b->records[0],SOURCES,source);
06468 statusA[16]= drms_setkey_int(recLev15b->records[0],QUALLEV1S,QUALITYLEV1);
06469 statusA[17]= drms_setkey_string(recLev15b->records[0],COMMENTS,COMMENT);
06470 statusA[18]=0;
06471 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15b->records[0],CALVER64S,CALVER64);
06472
06473 TotalStatus=0;
06474 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06475 if(TotalStatus != 0)
06476 {
06477 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the magnetogram at target time %s\n",timeBegin2);
06478 }
06479
06480
06481
06482 drms_copykeys(recLev15c->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06483
06484 status=fstats(axisout[0]*axisout[1],arrLev15[2]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06485 if(status != 0)
06486 {
06487 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06488 }
06489
06490 image=arrLev15[2]->data;
06491 for(i=0;i<axisout[0]*axisout[1];i++) if (image[i] > (32767.*arrLev15[2]->bscale+arrLev15[2]->bzero) || image[i] < (-32768.*arrLev15[2]->bscale+arrLev15[2]->bzero))
06492 {
06493 MISSVALS[2]+=1;
06494 ngood -= 1;
06495 }
06496
06497
06498 statusA[0]= drms_setkey_int(recLev15c->records[0],TOTVALSS,ngood+MISSVALS[2]);
06499 statusA[1]= drms_setkey_int(recLev15c->records[0],DATAVALSS,ngood);
06500 statusA[2]= drms_setkey_int(recLev15c->records[0],MISSVALSS,MISSVALS[2]);
06501 statusA[3]= drms_setkey_float(recLev15c->records[0],DATAMINS,(float)minimum);
06502 statusA[4]= drms_setkey_float(recLev15c->records[0],DATAMAXS,(float)maximum);
06503 statusA[5]= drms_setkey_float(recLev15c->records[0],DATAMEDNS,(float)median);
06504 statusA[6]= drms_setkey_float(recLev15c->records[0],DATAMEANS,(float)mean);
06505 statusA[7]= drms_setkey_float(recLev15c->records[0],DATARMSS,(float)sigma);
06506 statusA[8]= drms_setkey_float(recLev15c->records[0],DATASKEWS,(float)skewness);
06507 statusA[9]= drms_setkey_float(recLev15c->records[0],DATAKURTS,(float)kurtosis);
06508 statusA[10]=drms_setkey_int(recLev15c->records[0],CALFSNS,FSNLOOKUP);
06509 statusA[11]=drms_setkey_string(recLev15c->records[0],LUTQUERYS,HMILookup);
06510 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06511 statusA[12]= drms_setkey_string(recLev15c->records[0],DATES,DATEOBS);
06512 statusA[13]= drms_setkey_int(recLev15c->records[0],QUALITYS,QUALITY);
06513 statusA[14]= drms_setkey_int(recLev15c->records[0],SATVALSS,SATVALS);
06514 statusA[15]= drms_setkey_string(recLev15c->records[0],SOURCES,source);
06515 statusA[16]= drms_setkey_int(recLev15c->records[0],QUALLEV1S,QUALITYLEV1);
06516 statusA[17]= drms_setkey_string(recLev15c->records[0],COMMENTS,COMMENT);
06517 statusA[18]=0;
06518 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15c->records[0],CALVER64S,CALVER64);
06519
06520 TotalStatus=0;
06521 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06522 if(TotalStatus != 0)
06523 {
06524 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the linedepth at target time %s\n",timeBegin2);
06525 }
06526
06527
06528
06529
06530 drms_copykeys(recLev15d->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06531
06532 status=fstats(axisout[0]*axisout[1],arrLev15[3]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06533 if(status != 0)
06534 {
06535 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06536 }
06537
06538
06539 image=arrLev15[3]->data;
06540 for(i=0;i<axisout[0]*axisout[1];i++) if (image[i] > (32767.*arrLev15[3]->bscale+arrLev15[3]->bzero) || image[i] < (-32768.*arrLev15[3]->bscale+arrLev15[3]->bzero))
06541 {
06542 MISSVALS[3]+=1;
06543 ngood -= 1;
06544 }
06545
06546
06547 statusA[0]= drms_setkey_int(recLev15d->records[0],TOTVALSS,ngood+MISSVALS[3]);
06548 statusA[1]= drms_setkey_int(recLev15d->records[0],DATAVALSS,ngood);
06549 statusA[2]= drms_setkey_int(recLev15d->records[0],MISSVALSS,MISSVALS[3]);
06550 statusA[3]= drms_setkey_float(recLev15d->records[0],DATAMINS,(float)minimum);
06551 statusA[4]= drms_setkey_float(recLev15d->records[0],DATAMAXS,(float)maximum);
06552 statusA[5]= drms_setkey_float(recLev15d->records[0],DATAMEDNS,(float)median);
06553 statusA[6]= drms_setkey_float(recLev15d->records[0],DATAMEANS,(float)mean);
06554 statusA[7]= drms_setkey_float(recLev15d->records[0],DATARMSS,(float)sigma);
06555 statusA[8]= drms_setkey_float(recLev15d->records[0],DATASKEWS,(float)skewness);
06556 statusA[9]= drms_setkey_float(recLev15d->records[0],DATAKURTS,(float)kurtosis);
06557 statusA[10]=drms_setkey_int(recLev15d->records[0],CALFSNS,FSNLOOKUP);
06558 statusA[11]=drms_setkey_string(recLev15d->records[0],LUTQUERYS,HMILookup);
06559 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06560 statusA[12]= drms_setkey_string(recLev15d->records[0],DATES,DATEOBS);
06561 statusA[13]= drms_setkey_int(recLev15d->records[0],QUALITYS,QUALITY);
06562 statusA[14]= drms_setkey_int(recLev15d->records[0],SATVALSS,SATVALS);
06563 statusA[15]= drms_setkey_string(recLev15d->records[0],SOURCES,source);
06564 statusA[16]= drms_setkey_int(recLev15d->records[0],QUALLEV1S,QUALITYLEV1);
06565 statusA[17]= drms_setkey_string(recLev15d->records[0],COMMENTS,COMMENT);
06566 statusA[18]=0;
06567 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15d->records[0],CALVER64S,CALVER64);
06568
06569 TotalStatus=0;
06570 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06571 if(TotalStatus != 0)
06572 {
06573 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the linewidth at target time %s\n",timeBegin2);
06574 }
06575
06576
06577
06578 drms_copykeys(recLev15e->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06579
06580 status=fstats(axisout[0]*axisout[1],arrLev15[4]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06581 if(status != 0)
06582 {
06583 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06584 }
06585
06586 image=arrLev15[4]->data;
06587 for(i=0;i<axisout[0]*axisout[1];i++) if (image[i] > (32767.*arrLev15[4]->bscale+arrLev15[4]->bzero) || image[i] < (-32768.*arrLev15[4]->bscale+arrLev15[4]->bzero))
06588 {
06589 MISSVALS[4]+=1;
06590 ngood -= 1;
06591 }
06592
06593
06594 statusA[0]= drms_setkey_int(recLev15e->records[0],TOTVALSS,ngood+MISSVALS[4]);
06595 statusA[1]= drms_setkey_int(recLev15e->records[0],DATAVALSS,ngood);
06596 statusA[2]= drms_setkey_int(recLev15e->records[0],MISSVALSS,MISSVALS[4]);
06597 statusA[3]= drms_setkey_float(recLev15e->records[0],DATAMINS,(float)minimum);
06598 statusA[4]= drms_setkey_float(recLev15e->records[0],DATAMAXS,(float)maximum);
06599 statusA[5]= drms_setkey_float(recLev15e->records[0],DATAMEDNS,(float)median);
06600 statusA[6]= drms_setkey_float(recLev15e->records[0],DATAMEANS,(float)mean);
06601 statusA[7]= drms_setkey_float(recLev15e->records[0],DATARMSS,(float)sigma);
06602 statusA[8]= drms_setkey_float(recLev15e->records[0],DATASKEWS,(float)skewness);
06603 statusA[9]= drms_setkey_float(recLev15e->records[0],DATAKURTS,(float)kurtosis);
06604 statusA[10]=drms_setkey_int(recLev15e->records[0],CALFSNS,FSNLOOKUP);
06605 statusA[11]=drms_setkey_string(recLev15e->records[0],LUTQUERYS,HMILookup);
06606 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06607 statusA[12]= drms_setkey_string(recLev15e->records[0],DATES,DATEOBS);
06608 statusA[13]= drms_setkey_int(recLev15e->records[0],QUALITYS,QUALITY);
06609 statusA[14]= drms_setkey_int(recLev15e->records[0],SATVALSS,SATVALS);
06610 statusA[15]= drms_setkey_string(recLev15e->records[0],SOURCES,source);
06611 statusA[16]= drms_setkey_int(recLev15e->records[0],QUALLEV1S,QUALITYLEV1);
06612 statusA[17]= drms_setkey_string(recLev15e->records[0],COMMENTS,COMMENT);
06613 statusA[18]=0;
06614 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15e->records[0],CALVER64S,CALVER64);
06615
06616 TotalStatus=0;
06617 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06618 if(TotalStatus != 0)
06619 {
06620 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the continuum intensity at target time %s\n",timeBegin2);
06621 }
06622
06623
06624 image0=(float *)arrLev15[0]->data;
06625 image1=(float *)arrLev15[1]->data;
06626 image2=(float *)arrLev15[2]->data;
06627 image3=(float *)arrLev15[3]->data;
06628 image4=(float *)arrLev15[4]->data;
06629
06630 for(i=0;i<axisout[0]*axisout[1];++i)
06631 {
06632 row =i / axisout[0];
06633 column=i % axisout[0];
06634 distance = sqrt(((float)row-Y0AVG)*((float)row-Y0AVG)+((float)column-X0AVG)*((float)column-X0AVG));
06635 if(distance > 0.99*RSUNint)
06636 {
06637 image0[i]=NAN;
06638 image1[i]=NAN;
06639 image2[i]=NAN;
06640 image3[i]=NAN;
06641 image4[i]=NAN;
06642 }
06643 }
06644
06645
06646
06647
06648 status=fstats(axisout[0]*axisout[1],arrLev15[0]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06649 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06650 statusA[0]= drms_setkey_float(recLev15a->records[0],DATAMINS2,(float)minimum);
06651 statusA[1]= drms_setkey_float(recLev15a->records[0],DATAMAXS2,(float)maximum);
06652 statusA[2]= drms_setkey_float(recLev15a->records[0],DATAMEDNS2,(float)median);
06653 statusA[3]= drms_setkey_float(recLev15a->records[0],DATAMEANS2,(float)mean);
06654 statusA[4]= drms_setkey_float(recLev15a->records[0],DATARMSS2,(float)sigma);
06655 statusA[5]= drms_setkey_float(recLev15a->records[0],DATASKEWS2,(float)skewness);
06656 statusA[6]= drms_setkey_float(recLev15a->records[0],DATAKURTS2,(float)kurtosis);
06657 status=fstats(axisout[0]*axisout[1],arrLev15[1]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06658 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06659 statusA[7]= drms_setkey_float(recLev15b->records[0],DATAMINS2,(float)minimum);
06660 statusA[8]= drms_setkey_float(recLev15b->records[0],DATAMAXS2,(float)maximum);
06661 statusA[9]= drms_setkey_float(recLev15b->records[0],DATAMEDNS2,(float)median);
06662 statusA[10]= drms_setkey_float(recLev15b->records[0],DATAMEANS2,(float)mean);
06663 statusA[11]= drms_setkey_float(recLev15b->records[0],DATARMSS2,(float)sigma);
06664 statusA[12]= drms_setkey_float(recLev15b->records[0],DATASKEWS2,(float)skewness);
06665 statusA[13]= drms_setkey_float(recLev15b->records[0],DATAKURTS2,(float)kurtosis);
06666 status=fstats(axisout[0]*axisout[1],arrLev15[2]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06667 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06668 statusA[14]= drms_setkey_float(recLev15c->records[0],DATAMINS2,(float)minimum);
06669 statusA[15]= drms_setkey_float(recLev15c->records[0],DATAMAXS2,(float)maximum);
06670 statusA[16]= drms_setkey_float(recLev15c->records[0],DATAMEDNS2,(float)median);
06671 statusA[17]= drms_setkey_float(recLev15c->records[0],DATAMEANS2,(float)mean);
06672 statusA[18]= drms_setkey_float(recLev15c->records[0],DATARMSS2,(float)sigma);
06673 statusA[19]= drms_setkey_float(recLev15c->records[0],DATASKEWS2,(float)skewness);
06674 statusA[20]= drms_setkey_float(recLev15c->records[0],DATAKURTS2,(float)kurtosis);
06675 status=fstats(axisout[0]*axisout[1],arrLev15[3]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06676 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06677 statusA[21]= drms_setkey_float(recLev15d->records[0],DATAMINS2,(float)minimum);
06678 statusA[22]= drms_setkey_float(recLev15d->records[0],DATAMAXS2,(float)maximum);
06679 statusA[23]= drms_setkey_float(recLev15d->records[0],DATAMEDNS2,(float)median);
06680 statusA[24]= drms_setkey_float(recLev15d->records[0],DATAMEANS2,(float)mean);
06681 statusA[25]= drms_setkey_float(recLev15d->records[0],DATARMSS2,(float)sigma);
06682 statusA[26]= drms_setkey_float(recLev15d->records[0],DATASKEWS2,(float)skewness);
06683 statusA[27]= drms_setkey_float(recLev15d->records[0],DATAKURTS2,(float)kurtosis);
06684 status=fstats(axisout[0]*axisout[1],arrLev15[4]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06685 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06686 statusA[28]= drms_setkey_float(recLev15e->records[0],DATAMINS2,(float)minimum);
06687 statusA[29]= drms_setkey_float(recLev15e->records[0],DATAMAXS2,(float)maximum);
06688 statusA[30]= drms_setkey_float(recLev15e->records[0],DATAMEDNS2,(float)median);
06689 statusA[31]= drms_setkey_float(recLev15e->records[0],DATAMEANS2,(float)mean);
06690 statusA[32]= drms_setkey_float(recLev15e->records[0],DATARMSS2,(float)sigma);
06691 statusA[33]= drms_setkey_float(recLev15e->records[0],DATASKEWS2,(float)skewness);
06692 statusA[34]= drms_setkey_float(recLev15e->records[0],DATAKURTS2,(float)kurtosis);
06693
06694 statusA[35]= drms_setkey_string(recLev15a->records[0],HISTORYS,HISTORY);
06695 statusA[36]= drms_setkey_string(recLev15b->records[0],HISTORYS,HISTORY);
06696 statusA[37]= drms_setkey_string(recLev15c->records[0],HISTORYS,HISTORY);
06697 statusA[38]= drms_setkey_string(recLev15d->records[0],HISTORYS,HISTORY);
06698 statusA[39]= drms_setkey_string(recLev15e->records[0],HISTORYS,HISTORY);
06699
06700 TotalStatus=0;
06701 for(i=0;i<35;++i) TotalStatus+=statusA[i];
06702 if(TotalStatus != 0)
06703 {
06704 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the Dopplergram at target time %s\n",timeBegin2);
06705 }
06706 t1=dsecnd();
06707 printf("TIME ELAPSED TO SET LEV 1.5 KEYWORDS AND CALCULATE STATISTICS KEYWORDS: %f\n",t1-t0);
06708
06709 }
06710
06711
06712
06713 NextTargetTime:
06714
06715
06716
06717
06718
06719
06720
06721
06722
06723
06724 printf("FREEING RECORD\n");
06725
06726 if(Mask != NULL)
06727 {
06728 free(Mask);
06729 Mask = NULL;
06730 }
06731
06732 if(recLev1d != NULL)
06733 {
06734 printf("recLev1d != NULL\n");
06735 if(recLev1d->n > 0)
06736 {
06737
06738 if (Lev1dWanted) status=drms_close_records(recLev1d,DRMS_INSERT_RECORD);
06739 else status=drms_close_records(recLev1d,DRMS_FREE_RECORD);
06740 recLev1d=NULL;
06741 if(arrLev1d != NULL)
06742 {
06743 for(i=0;i<nRecs1d;++i) if(arrLev1d[i] != NULL)
06744 {
06745 drms_free_array(arrLev1d[i]);
06746 arrLev1d[i]=NULL;
06747 }
06748 free(arrLev1d);
06749 }
06750 arrLev1d=NULL;
06751 Segments1d=0;
06752 }
06753 }
06754
06755
06756 if(recLev1p != NULL)
06757 {
06758 printf("recLev1p != NULL\n");
06759 if(recLev1p->n > 0)
06760 {
06761 if (Lev1pWanted) status=drms_close_records(recLev1p,DRMS_INSERT_RECORD);
06762 else status=drms_close_records(recLev1p,DRMS_FREE_RECORD);
06763 recLev1p=NULL;
06764 for(i=0;i<nSegs1p;++i) if(arrLev1p[i] != NULL)
06765 {
06766 drms_free_array(arrLev1p[i]);
06767 arrLev1p[i]=NULL;
06768 }
06769 if(arrLev1p != NULL) free(arrLev1p);
06770 arrLev1p=NULL;
06771 if(ps1 != NULL) free(ps1);
06772 if(ps2 != NULL) free(ps2);
06773 if(ps3 != NULL) free(ps3);
06774 if(fid != NULL) free(fid);
06775 if(Wavelengths != NULL) free(Wavelengths);
06776 if(images != NULL) free(images);
06777 if(imagesout != NULL) free(imagesout);
06778 Wavelengths=NULL;
06779 images=NULL;
06780 imagesout=NULL;
06781 ps1=NULL;
06782 ps2=NULL;
06783 ps3=NULL;
06784 fid=NULL;
06785 Segments1p=0;
06786 }
06787 }
06788
06789
06790 if(Lev15Wanted)
06791 {
06792
06793 if(arrintable != NULL)
06794 {
06795 drms_free_array(arrintable);
06796 }
06797 arrintable=NULL;
06798 if(lookup != NULL) status=drms_close_records(lookup,DRMS_FREE_RECORD);
06799 lookup = NULL;
06800 if(recpoly != NULL) status=drms_close_records(recpoly,DRMS_FREE_RECORD);
06801 recpoly= NULL;
06802 if(recpoly2 != NULL) status=drms_close_records(recpoly2,DRMS_FREE_RECORD);
06803 recpoly2= NULL;
06804 if(arrayL0 != NULL)
06805 {
06806 drms_free_array(arrayL0);
06807 arrayL0=NULL;
06808 }
06809 if(arrayL1 != NULL)
06810 {
06811 drms_free_array(arrayL1);
06812 arrayL1=NULL;
06813 }
06814 if(arrayL2 != NULL)
06815 {
06816 drms_free_array(arrayL2);
06817 arrayL2=NULL;
06818 }
06819 if(count != NULL)
06820 {
06821 free(count);
06822 count=NULL;
06823 }
06824
06825 if(recLev15a != NULL)
06826 {
06827 printf("recLev15a != NULL\n");
06828 if(CreateEmptyRecord != 1)
06829 {
06830 printf("Inserting record for the observables\n");
06831 status=drms_close_records(recLev15a,DRMS_INSERT_RECORD);
06832 status=drms_close_records(recLev15b,DRMS_INSERT_RECORD);
06833 status=drms_close_records(recLev15c,DRMS_INSERT_RECORD);
06834 status=drms_close_records(recLev15d,DRMS_INSERT_RECORD);
06835 status=drms_close_records(recLev15e,DRMS_INSERT_RECORD);
06836 recLev15a=NULL;
06837 recLev15b=NULL;
06838 recLev15c=NULL;
06839 recLev15d=NULL;
06840 recLev15e=NULL;
06841 }
06842 else
06843 {
06844 printf("Warning: creating empty lev1.5 record\n");
06845
06846 if(CamId == LIGHT_SIDE) camera=1;
06847 if(CamId == LIGHT_FRONT) camera=2;
06848
06849 QUALITY= QUALITY | QUAL_NODATA;
06850 statusA[0] = drms_setkey_time(recLev15a->records[0],TRECS,TargetTime);
06851
06852 statusA[2] = drms_setkey_int(recLev15a->records[0],CAMERAS,camera);
06853 statusA[3] = drms_setkey_int(recLev15a->records[0],QUALITYS,QUALITY);
06854 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06855 statusA[4]= drms_setkey_string(recLev15a->records[0],DATES,DATEOBS);
06856
06857 statusA[0] = drms_setkey_time(recLev15b->records[0],TRECS,TargetTime);
06858
06859 statusA[2] = drms_setkey_int(recLev15b->records[0],CAMERAS,camera);
06860 statusA[3] = drms_setkey_int(recLev15b->records[0],QUALITYS,QUALITY);
06861 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06862 statusA[4]= drms_setkey_string(recLev15b->records[0],DATES,DATEOBS);
06863
06864 statusA[0] = drms_setkey_time(recLev15c->records[0],TRECS,TargetTime);
06865
06866 statusA[2] = drms_setkey_int(recLev15c->records[0],CAMERAS,camera);
06867 statusA[3] = drms_setkey_int(recLev15c->records[0],QUALITYS,QUALITY);
06868 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06869 statusA[4]= drms_setkey_string(recLev15c->records[0],DATES,DATEOBS);
06870
06871 statusA[0] = drms_setkey_time(recLev15d->records[0],TRECS,TargetTime);
06872
06873 statusA[2] = drms_setkey_int(recLev15d->records[0],CAMERAS,camera);
06874 statusA[3] = drms_setkey_int(recLev15d->records[0],QUALITYS,QUALITY);
06875 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06876 statusA[4]= drms_setkey_string(recLev15d->records[0],DATES,DATEOBS);
06877
06878 statusA[0] = drms_setkey_time(recLev15e->records[0],TRECS,TargetTime);
06879
06880 statusA[2] = drms_setkey_int(recLev15e->records[0],CAMERAS,camera);
06881 statusA[3] = drms_setkey_int(recLev15e->records[0],QUALITYS,QUALITY);
06882 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06883 statusA[4]= drms_setkey_string(recLev15e->records[0],DATES,DATEOBS);
06884
06885
06886 status=drms_close_records(recLev15a,DRMS_INSERT_RECORD);
06887 status=drms_close_records(recLev15b,DRMS_INSERT_RECORD);
06888 status=drms_close_records(recLev15c,DRMS_INSERT_RECORD);
06889 status=drms_close_records(recLev15d,DRMS_INSERT_RECORD);
06890 status=drms_close_records(recLev15e,DRMS_INSERT_RECORD);
06891 recLev15a=NULL;
06892 recLev15b=NULL;
06893 recLev15c=NULL;
06894 recLev15d=NULL;
06895 recLev15e=NULL;
06896 }
06897 for (i=0;i<nRecs15;++i) if(arrLev15[i] != NULL)
06898 {
06899 drms_free_array(arrLev15[i]);
06900 arrLev15[i]=NULL;
06901 }
06902 if(arrLev15 != NULL) free(arrLev15);
06903 arrLev15=NULL;
06904 }
06905 else
06906 {
06907
06908 recLev15a = drms_create_records(drms_env,1,HMISeriesLev15a,DRMS_PERMANENT,&statusA[0]);
06909 recLev15b = drms_create_records(drms_env,1,HMISeriesLev15b,DRMS_PERMANENT,&statusA[1]);
06910 recLev15c = drms_create_records(drms_env,1,HMISeriesLev15c,DRMS_PERMANENT,&statusA[2]);
06911 recLev15d = drms_create_records(drms_env,1,HMISeriesLev15d,DRMS_PERMANENT,&statusA[3]);
06912 recLev15e = drms_create_records(drms_env,1,HMISeriesLev15e,DRMS_PERMANENT,&statusA[4]);
06913
06914 if(CamId == LIGHT_SIDE) camera=1;
06915 if(CamId == LIGHT_FRONT) camera=2;
06916
06917 printf("Warning: creating empty lev1.5 record\n");
06918 QUALITY= QUALITY | QUAL_NODATA;
06919 statusA[0] = drms_setkey_time(recLev15a->records[0],TRECS,TargetTime);
06920
06921 statusA[2] = drms_setkey_int(recLev15a->records[0],CAMERAS,camera);
06922 statusA[3] = drms_setkey_int(recLev15a->records[0],QUALITYS,QUALITY);
06923 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06924 statusA[4]= drms_setkey_string(recLev15a->records[0],DATES,DATEOBS);
06925
06926 statusA[0] = drms_setkey_time(recLev15b->records[0],TRECS,TargetTime);
06927
06928 statusA[2] = drms_setkey_int(recLev15b->records[0],CAMERAS,camera);
06929 statusA[3] = drms_setkey_int(recLev15b->records[0],QUALITYS,QUALITY);
06930 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06931 statusA[4]= drms_setkey_string(recLev15b->records[0],DATES,DATEOBS);
06932
06933 statusA[0] = drms_setkey_time(recLev15c->records[0],TRECS,TargetTime);
06934
06935 statusA[2] = drms_setkey_int(recLev15c->records[0],CAMERAS,camera);
06936 statusA[3] = drms_setkey_int(recLev15c->records[0],QUALITYS,QUALITY);
06937 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06938 statusA[4]= drms_setkey_string(recLev15c->records[0],DATES,DATEOBS);
06939
06940 statusA[0] = drms_setkey_time(recLev15d->records[0],TRECS,TargetTime);
06941
06942 statusA[2] = drms_setkey_int(recLev15d->records[0],CAMERAS,camera);
06943 statusA[3] = drms_setkey_int(recLev15d->records[0],QUALITYS,QUALITY);
06944 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06945 statusA[4]= drms_setkey_string(recLev15d->records[0],DATES,DATEOBS);
06946
06947 statusA[0] = drms_setkey_time(recLev15e->records[0],TRECS,TargetTime);
06948
06949 statusA[2] = drms_setkey_int(recLev15e->records[0],CAMERAS,camera);
06950 statusA[3] = drms_setkey_int(recLev15e->records[0],QUALITYS,QUALITY);
06951 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06952 statusA[4]= drms_setkey_string(recLev15e->records[0],DATES,DATEOBS);
06953
06954 status=drms_close_records(recLev15a,DRMS_INSERT_RECORD);
06955 status=drms_close_records(recLev15b,DRMS_INSERT_RECORD);
06956 status=drms_close_records(recLev15c,DRMS_INSERT_RECORD);
06957 status=drms_close_records(recLev15d,DRMS_INSERT_RECORD);
06958 status=drms_close_records(recLev15e,DRMS_INSERT_RECORD);
06959 recLev15a=NULL;
06960 recLev15b=NULL;
06961 recLev15c=NULL;
06962 recLev15d=NULL;
06963 recLev15e=NULL;
06964 }
06965
06966 QUALITY=0;
06967 CreateEmptyRecord=0;
06968 }
06969
06970 PreviousTargetTime=TargetTime;
06971 TargetTime+=DataCadence;
06972 initialrun=0;
06973 }
06974
06975
06976 if (TestLevIn[0]==1)
06977 {
06978 printf("FREEING GENERAL ARRAYS\n");
06979 free(CameraID);
06980 if(recLev1->n > 0)
06981 {
06982 status=drms_close_records(recLev1,DRMS_FREE_RECORD);
06983 recLev1=NULL;
06984 free(internTOBS);
06985 free(HWL1POS);
06986 free(HWL2POS);
06987 free(HWL3POS);
06988 free(HWL4POS);
06989 free(HPL1POS);
06990 free(HPL2POS);
06991 free(HPL3POS);
06992 free(HWLTID);
06993 free(HPLTID);
06994 free(FID);
06995 free(HFLID);
06996 free(HCAMID);
06997 free(RSUN);
06998 free(CROTA2);
06999 free(CRLTOBS);
07000 free(DSUNOBS);
07001 free(X0);
07002 free(Y0);
07003 free(SegmentRead);
07004 free(KeywordMissing);
07005 free(Segments);
07006
07007 if(inRotationalFlat == 1)
07008 {
07009 drms_free_array(flatfield);
07010 drms_free_array(flatfieldrot);
07011 status=drms_close_records(recflatrot,DRMS_FREE_RECORD);
07012 }
07013 free(Ierror);
07014 free(IndexFiltergram);
07015 free(FSN);
07016 free(CFINDEX);
07017 free(HIMGCFID);
07018 for(i=0;i<nRecs1;++i) free(IMGTYPE[i]);
07019 free(IMGTYPE);
07020 free(CDELT1);
07021 for(i=0;i<nRecs1;++i) free(HWLTNSET[i]);
07022 free(HWLTNSET);
07023 free(NBADPERM);
07024 free(QUALITYin);
07025 free(QUALITYlev1);
07026 free(EXPTIME);
07027 free(CALVER32);
07028 free(CAMERA);
07029 }
07030 }
07031
07032 if(TestLevIn[0]==1)
07033 {
07034 free_interpol(&const_param);
07035 }
07036
07037 if(Lev1pWanted || (Lev15Wanted && TestLevIn[2]==0))
07038 {
07039 status = free_polcal(&pars);
07040 }
07041
07042 free(CODEVERSION);
07043 free(CODEVERSION1);
07044 free(CODEVERSION2);
07045 free(CODEVERSION3);
07046 free(DISTCOEFFILEF);
07047 free(DISTCOEFFILES);
07048 free(ROTCOEFFILE);
07049 free(DISTCOEFPATH);
07050 free(ROTCOEFPATH);
07051
07052
07053 status=0;
07054 t1=dsecnd();
07055 printf("TOTAL TIME ELAPSED IN OBSERVABLES CODE: %f\n",t1-tstart);
07056 return status;
07057
07058 }
07059
07060