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