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_135q.c,v 1.3 2016/10/03 17:43:52 arta 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.S_135s");
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) {CALVER32[0] = CALVER32[0] | CALVER_MODL;} else CALVER32[0] = CALVER32[0] & CALVER_NOMODL;
04508 statusA[48]= drms_setkey_longlong(recLev1d->records[k],CALVER64S,CALVER32[0]);
04509
04510 TotalStatus=0;
04511 for(i=0;i<49;++i) TotalStatus+=statusA[i];
04512 if(TotalStatus != 0)
04513 {
04514 for(ii=0;ii<49;++ii) if(statusA[ii] != 0) printf(" %d ",ii);
04515 printf("\n");
04516 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);
04517 }
04518
04519
04520 if (Lev1dWanted)
04521 {
04522 segout = drms_segment_lookupnum(recLev1d->records[k],0);
04523 arrLev1d[k]->bzero=segout->bzero;
04524 arrLev1d[k]->bscale=segout->bscale;
04525 arrLev1d[k]->israw=0;
04526 status=drms_segment_write(segout,arrLev1d[k],0);
04527 if(status != DRMS_SUCCESS)
04528 {
04529 printf("Error: a call to drms_segment_write failed\n");
04530 return 1;
04531 }
04532 }
04533
04534 }
04535
04536 free(images);
04537 free(ierrors);
04538 images=NULL;
04539 ierrors=NULL;
04540 free(KeyInterp);
04541 KeyInterp=NULL;
04542 }
04543 else
04544 {
04545 printf("Error: not enough valid level 1 filtergrams to produce a level 1d filtergram at target time %s\n",timeBegin2);
04546 drms_free_array(arrLev1d[k]);
04547 arrLev1d[k]=NULL;
04548 QUALITY = QUALITY | QUAL_NOTENOUGHINTERPOLANTS;
04549
04550 }
04551
04552
04553 }
04554
04555
04556 free(FramelistArray);
04557 FramelistArray=NULL;
04558 }
04559
04560
04561
04562
04563
04564
04565
04566
04567
04568
04569
04570
04571
04572 if (TestLevIn[2]==1)
04573 {
04574
04575
04576
04577
04578
04579
04580
04581
04582
04583
04584
04585 PolarizationType=1;
04586 if(CamId == LIGHT_SIDE) camera=1;
04587 if(CamId == LIGHT_FRONT) camera=2;
04588 if(CamId0 == 3) camera=3;
04589 if(camera == 2)
04590 {
04591 printf("Error: the use of time-averaged IQUV data as input requires CamId = side camera\n");
04592 return 1;
04593 }
04594
04595
04596
04597
04598 if(PolarizationType ==3 || PolarizationType ==2) strcpy(HMISeries,HMISeriesLev1pb);
04599 else strcpy(HMISeries,HMISeriesLev1pa);
04600 strcat(HMISeries,"[");
04601 strcat(HMISeries,timeBegin2);
04602 strcat(HMISeries,"][");
04603 if(DataCadence != 720.0) sprintf(CamIds,"%d",CamId);
04604 else sprintf(CamIds,"%d",camera);
04605 strcat(HMISeries,CamIds);
04606 strcat(HMISeries,"]");
04607
04608 printf("Opening the record %s\n",HMISeries);
04609 recLev1p = drms_open_records(drms_env,HMISeries,&status);
04610
04611 if (status == DRMS_SUCCESS && recLev1p != NULL && recLev1p->n > 0)
04612 {
04613 if(recLev1p->n > 1)
04614 {
04615 printf("Too many records: %d\n",recLev1p->n);
04616 return 1;
04617 }
04618 printf("Number of level 1p records opened= %d\n",recLev1p->n);
04619
04620 nSegs1p = drms_record_numsegments(recLev1p->records[0]);
04621 printf("NUMBER OF DATA SEGMENTS: %d\n",nSegs1p);
04622
04623
04624 if (PolarizationType ==1)
04625 {
04626 nRecs1p = nSegs1p/4;
04627 }
04628 if (PolarizationType ==2 || PolarizationType ==3)
04629 {
04630 nRecs1p = nSegs1p/2;
04631 }
04632 printf("NUMBER OF WAVELENGTHS: %d\n",nRecs1p);
04633
04634 trec = drms_getkey_time(recLev1p->records[0],TRECS,&status);
04635 if(status != DRMS_SUCCESS)
04636 {
04637 printf("Error: cannot read the keyword %s\n",TRECS);
04638
04639 return 1;
04640 }
04641 if(trec != TargetTime)
04642 {
04643 printf("Error: %s of a level 1p record is not equal to the target time %s\n",TRECS,timeBegin2);
04644
04645 return 1;
04646 }
04647 tobs = drms_getkey_time(recLev1p->records[0],TOBSS,&status);
04648 if(status != DRMS_SUCCESS)
04649 {
04650 printf("Error: cannot read the keyword %s\n",TOBSS);
04651 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04652
04653 }
04654
04655
04656
04657
04658
04659 TREC_STEP= drms_getkey_time(recLev1p->records[0],TRECSTEPS,&status);
04660 if(status != DRMS_SUCCESS)
04661 {
04662 printf("Error: cannot read the keyword %s\n",TRECSTEPS);
04663
04664 return 1;
04665 }
04666
04667 if(TREC_STEP != DataCadence)
04668 {
04669 printf("Error: the cadence is not equal to the T_REC_step keyword of the level 1p data\n");
04670
04671 return 1;
04672 }
04673
04674 DRMS_SegmentDimInfo_t di;
04675 segin = drms_segment_lookupnum(recLev1p->records[0],0);
04676 status = drms_segment_getdims(segin,&di);
04677 if(status != DRMS_SUCCESS)
04678 {
04679 printf("Error: cannot read the dimensions of the data segment of level 1p data\n");
04680
04681 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04682 }
04683 axisin[0]= di.axis[0];
04684 axisin[1]= di.axis[1];
04685 axisout[0]=axisin[0];
04686 axisout[1]=axisin[1];
04687
04688 QUALITYLEV1 = drms_getkey_int(recLev1p->records[0],QUALLEV1S,&status);
04689 if(status != DRMS_SUCCESS)
04690 {
04691 printf("Error: cannot read the keyword %s\n",QUALLEV1S);
04692 return 1;
04693 }
04694 strcpy(source,drms_getkey_string(recLev1p->records[0],SOURCES,&status));
04695 if(status != DRMS_SUCCESS)
04696 {
04697 printf("Error: cannot read the keyword %s\n",SOURCES);
04698 return 1;
04699 }
04700 QUALITY = drms_getkey_int(recLev1p->records[0],QUALITYS,&status);
04701 if(status != DRMS_SUCCESS)
04702 {
04703 printf("Error: cannot read the keyword %s\n",QUALITYS);
04704 return 1;
04705 }
04706
04707 CALVER64 = drms_getkey_longlong(recLev1p->records[0],CALVER64S,&status);
04708 if(status != DRMS_SUCCESS)
04709 {
04710 printf("Error: cannot read the keyword %s\n",CALVER64S);
04711 return 1;
04712 }
04713 if(inSmoothTables == 1) CALVER64 = CALVER64 | CALVER_SMOOTH;
04714
04715 Segments1p=0;
04716
04717 }
04718 else
04719 {
04720 printf("Unable to open the series %s, or no record found, for time %s\n",HMISeries,timeBegin2);
04721 if(status == DRMS_SUCCESS) QUALITY = QUALITY | QUAL_MISSINGLEV1P;
04722 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04723 }
04724 }
04725
04726
04727
04728
04729
04730
04731
04732
04733
04734
04735
04736
04737
04738
04739
04740
04741 if (Lev1pWanted == 1 || (Lev15Wanted == 1 && TestLevIn[2]!=1))
04742 {
04743
04744
04745 printf("PRODUCING LEVEL 1P RECORDS\n");
04746
04747 int ActualnSegs1d=0;
04748
04749
04750
04751 if(Segments1d == 0)
04752 {
04753 printf("READING THE LEVEL 1d DATA SEGMENTS\n");
04754
04755
04756 statusA[0]=1;
04757 i=0;
04758 while(statusA[0] != DRMS_SUCCESS)
04759 {
04760 TargetHFLID = drms_getkey_int(recLev1d->records[i],HFLIDS,&statusA[0]);
04761 if(i < nRecs1d-1) ++i;
04762 else break;
04763 }
04764 statusA[1]=1;
04765 i=0;
04766 while(statusA[1] != DRMS_SUCCESS)
04767 {
04768 TargetHPLTID = drms_getkey_int(recLev1d->records[i],HPLTIDS,&statusA[1]);
04769 if(i < nRecs1d-1) ++i;
04770 else break;
04771 }
04772 statusA[2]=1;
04773 i=0;
04774 while(statusA[2] != DRMS_SUCCESS)
04775 {
04776 TargetHWLTID = drms_getkey_int(recLev1d->records[i],HWLTIDS,&statusA[2]);
04777 if(i < nRecs1d-1) ++i;
04778 else break;
04779 }
04780 statusA[3]=1;
04781 i=0;
04782 while(statusA[3] != DRMS_SUCCESS)
04783 {
04784 WavelengthID2 = drms_getkey_int(recLev1d->records[i],WavelengthIDS,&statusA[3]);
04785 if(i < nRecs1d-1) ++i;
04786 else break;
04787 }
04788 if(WavelengthID2 != WavelengthID)
04789 {
04790 printf("Error: WavelengthID2 != WavelengthID\n");
04791 return 1;
04792 }
04793
04794
04795 if( (statusA[0]+statusA[1]+statusA[2]+statusA[3]) != 0)
04796 {
04797 printf("Error: some needed keywords cannot be read on level 1d data at target time %s\n",timeBegin2);
04798 Segments1d = 0;
04799 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1D;
04800 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04801 }
04802 else
04803 {
04804 framelistSize = framelistInfo(TargetHFLID,TargetHPLTID,TargetHWLTID,WavelengthID,PHWPLPOS,WavelengthIndex,WavelengthLocation,&PolarizationType,CamId,&combine,&npol,MaxNumFiltergrams,&CadenceRead,CameraValues,FIDValues,dpath);
04805 if(framelistSize == 1) return 1;
04806 }
04807
04808 if(framelistSize != nRecs1d)
04809 {
04810 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);
04811 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1D;
04812 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04813 }
04814
04815 ActualnSegs1d=nRecs1d;
04816
04817 arrLev1d = (DRMS_Array_t **)malloc(nRecs1d*sizeof(DRMS_Array_t *));
04818 if(arrLev1d == NULL)
04819 {
04820 printf("Error: memory could not be allocated to arrLev1d\n");
04821 return 1;
04822 }
04823
04824 for(i=0;i<nRecs1d;++i)
04825 {
04826
04827
04828
04829
04830
04831
04832
04833
04834 if(recLev1d->records[i] != NULL)
04835 {
04836 segin = drms_segment_lookupnum(recLev1d->records[i], 0);
04837 arrLev1d[i] = drms_segment_read(segin,type1d,&status);
04838 if(status != DRMS_SUCCESS || arrLev1d[i] == NULL)
04839 {
04840 printf("Error: could not read the segment for level 1d data index %d at target time %s \n",i,timeBegin2);
04841 arrLev1d[i] = NULL;
04842 ActualnSegs1d-=1;
04843 }
04844 }
04845 else
04846 {
04847 arrLev1d[i] = NULL;
04848 ActualnSegs1d-=1;
04849 }
04850 }
04851
04852 Segments1d = 1;
04853 }
04854 else
04855 {
04856 ActualnSegs1d=nRecs1d;
04857 for(i=0;i<nRecs1d;++i)
04858 {
04859 if(arrLev1d[i] == NULL) ActualnSegs1d-=1;
04860 }
04861 }
04862
04863
04864
04865
04866
04867
04868 if(ActualnSegs1d != framelistSize)
04869 {
04870 printf("Error: some records for the level 1d filtergrams are missing to produce level 1p data at target time %s\n",timeBegin2);
04871 Segments1d=0;
04872 QUALITY = QUALITY | QUAL_MISSINGLEV1D;
04873 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04874 }
04875
04876
04877
04878
04879
04880 if(PolarizationType ==3)
04881 {
04882 nRecs1p=ActualnSegs1d/2;
04883 npolout=2;
04884 nSegs1p=npolout*nRecs1p;
04885 Lev1pOffset=40;
04886 if (Lev1pWanted) recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pb,DRMS_PERMANENT,&status);
04887 else recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pb,DRMS_TRANSIENT,&status);
04888 }
04889 if(PolarizationType ==2)
04890 {
04891 nRecs1p=ActualnSegs1d/4;
04892 npolout=2;
04893 nSegs1p=npolout*nRecs1p;
04894 Lev1pOffset=40;
04895 if (Lev1pWanted) recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pb,DRMS_PERMANENT,&status);
04896 else recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pb,DRMS_TRANSIENT,&status);
04897 }
04898 if(PolarizationType ==1)
04899 {
04900 nRecs1p=ActualnSegs1d/npol;
04901 npolout=4;
04902 nSegs1p=npolout*nRecs1p;
04903 Lev1pOffset=0;
04904 if (Lev15Wanted)
04905 {
04906 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");
04907 Lev15Wanted = 0;
04908 }
04909 if (Lev1pWanted) recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pa,DRMS_PERMANENT,&status);
04910 else recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pa,DRMS_TRANSIENT,&status);
04911 }
04912
04913 if (status != DRMS_SUCCESS || recLev1p == NULL)
04914 {
04915 printf("Could not create a record for the level 1p series at target time %s\n",timeBegin2);
04916
04917
04918
04919 return 1;
04920 }
04921
04922
04923
04924
04925 arrLev1p = (DRMS_Array_t **)malloc(nSegs1p*sizeof(DRMS_Array_t *));
04926 if(arrLev1p == NULL)
04927 {
04928 printf("Error: memory could not be allocated to arrLev1p\n");
04929 return 1;
04930 }
04931
04932 for(i=0;i<nSegs1p;++i)
04933 {
04934 arrLev1p[i] = drms_array_create(type1p,2,axisout,NULL,&status);
04935 if(status != DRMS_SUCCESS || arrLev1p[i] == NULL)
04936 {
04937 printf("Error: cannot create an array for a level 1p data at target time %s\n",timeBegin2);
04938
04939
04940
04941
04942
04943
04944
04945
04946
04947
04948
04949
04950 return 1;
04951 }
04952 }
04953
04954 images = (float **)malloc(npol*sizeof(float *));
04955 if(images == NULL)
04956 {
04957 printf("Error: memory could not be allocated to images\n");
04958 return 1;
04959 }
04960
04961 imagesout = (float **)malloc(npolout*sizeof(float *));
04962 if(imagesout == NULL)
04963 {
04964 printf("Error: memory could not be allocated to imagesout\n");
04965 return 1;
04966 }
04967
04968 ps1 = (int *)malloc(npol*sizeof(int *));
04969 if(ps1 == NULL)
04970 {
04971 printf("Error: memory could not be allocated to ps1\n");
04972 return 1;
04973 }
04974 ps2 = (int *)malloc(npol*sizeof(int *));
04975 if(ps2 == NULL)
04976 {
04977 printf("Error: memory could not be allocated to ps2\n");
04978 return 1;
04979 }
04980 ps3 = (int *)malloc(npol*sizeof(int *));
04981 if(ps3 == NULL)
04982 {
04983 printf("Error: memory could not be allocated to ps3\n");
04984 return 1;
04985 }
04986
04987 fid = (int *)malloc(nRecs1d*sizeof(int *));
04988 if(fid == NULL)
04989 {
04990 printf("Error: memory could not be allocated to fid\n");
04991 return 1;
04992 }
04993
04994 Wavelengths = (int *)malloc(nRecs1p*sizeof(int *));
04995 if(Wavelengths == NULL)
04996 {
04997 printf("Error: memory could not be allocated to Wavelengths\n");
04998 return 1;
04999 }
05000
05001
05002
05003 printf("Looking for available level 1d arrays. Number expected: %d\n",nRecs1d);
05004 ii=0;
05005 for(i=0;i<nRecs1d;++i)
05006 {
05007 if (arrLev1d[i] != NULL)
05008 {
05009 fid[i]=drms_getkey_int(recLev1d->records[i],FIDS,&status);
05010 if( status != 0)
05011 {
05012 printf("Error: unable to read the keyword fid in a level 1d record\n");
05013 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1D;
05014 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
05015 }
05016 printf("FID of lev1d data: %d\n",fid[i]);
05017 if(i == 0) Wavelengths[0]=WhichWavelength(fid[0]);
05018 temp=0;
05019 for(k=0;k<=ii;++k) if(WhichWavelength(fid[i]) == Wavelengths[k]) temp=1;
05020 if(temp == 0)
05021 {
05022 ii+=1;
05023 Wavelengths[ii]=WhichWavelength(fid[i]);
05024 }
05025 }
05026 else
05027 {
05028 printf("Error: wavelength index %d is missing\n",i);
05029 QUALITY = QUALITY | QUAL_MISSINGLEV1D;
05030 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
05031 }
05032 }
05033
05034 if(ii+1 != nRecs1p)
05035 {
05036 printf("Error: the number of wavelengths in level 1d data: %d; is not what it should be: %d\n",ii+1,nRecs1p);
05037 QUALITY = QUALITY | QUAL_WRONGWAVELENGTHNUM;
05038 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
05039 }
05040
05041
05042
05043
05044
05045
05046
05047
05048 {
05049
05050 strcpy(HMISeriesTemp,HMISeriesTemperature);
05051 strcat(HMISeriesTemp,"[");
05052 strcat(HMISeriesTemp,timeBegin2);
05053 strcat(HMISeriesTemp,"]");
05054 rectemp=NULL;
05055 rectemp = drms_open_records(drms_env,HMISeriesTemp,&statusA[0]);
05056 printf("TEMPERATURE QUERY = %s\n",HMISeriesTemp);
05057 if(statusA[0] == DRMS_SUCCESS && rectemp != NULL && rectemp->n != 0) TSEL=drms_getkey_float(rectemp->records[0],TS08,&status);
05058 else status = 1;
05059 if(status != DRMS_SUCCESS || isnan(TSEL))
05060 {
05061 printf("Error: the temperature keyword %s could not be read\n",TS08);
05062 QUALITY = QUALITY | QUAL_NOTEMP;
05063 TSEL=20.;
05064 }
05065 statusA[1]=1;
05066 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;
05067 if(statusA[0] != DRMS_SUCCESS || statusA[1] != DRMS_SUCCESS || isnan(TFRONT))
05068 {
05069 printf("Error: temperature keyword %s and/or %s could not be read\n",TS01,TS02);
05070 QUALITY = QUALITY | QUAL_NOTEMP;
05071 TFRONT=20.;
05072 }
05073 printf("TEMPERATURES = %f %f\n",TSEL,TFRONT);
05074 if(rectemp != NULL)
05075 {
05076 drms_close_records(rectemp,DRMS_FREE_RECORD);
05077 rectemp=NULL;
05078 }
05079 }
05080
05081 printf("WAVELENGTH ORDER = ");
05082 for(i=0;i<nRecs1p;++i) printf(" %d ",Wavelengths[i]);
05083 printf("\n");
05084
05085 printf("CALIBRATION OF POLARIZATION AND SORTING OF THE IMAGES IN THE ORDER I0, I1, I2, I3, I4... \n");
05086
05087 for(k=0;k<nRecs1p;++k)
05088 {
05089
05090 i=0;
05091 for(ii=0;ii<nRecs1d;++ii) if (WhichWavelength(fid[ii]) == k)
05092 {
05093 printf("wavelength=%d, polarization %d\n",k,i);
05094 images[i]=arrLev1d[ii]->data;
05095 ps1[i]=drms_getkey_int(recLev1d->records[ii],HPL1POSS,&statusA[0]);
05096 ps2[i]=drms_getkey_int(recLev1d->records[ii],HPL2POSS,&statusA[1]);
05097 ps3[i]=drms_getkey_int(recLev1d->records[ii],HPL3POSS,&statusA[2]);
05098 printf("Polarization settings: %d %d %d %f %f %d %d\n",ps1[i],ps2[i],ps3[i],TSEL,TFRONT,npolout,PolarizationType);
05099 if( (statusA[0]+statusA[1]+statusA[2]) != 0)
05100 {
05101 printf("Error: unable to read one or several keyword(s) in level 1d data\n");
05102 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1D;
05103 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
05104 }
05105 i+=1;
05106 }
05107
05108 for(i=0;i<npolout;++i) imagesout[i]=arrLev1p[k*npolout+i]->data;
05109
05110
05111
05112
05113
05114 printf("Producing level 1p data\n");
05115 t0=dsecnd();
05116 polcal(&pars,npol,PolarizationType,images,imagesout,ps1,ps2,ps3,TSEL,TFRONT,axisout[0],axisout[1],axisout[1]);
05117 t1=dsecnd();
05118 printf("TIME ELAPSED IN POLCAL: %f\n",t1-t0);
05119
05120
05121
05122
05123 if(Lev1pWanted)
05124 {
05125 t0=dsecnd();
05126 for(i=0;i<npolout;++i)
05127 {
05128 segout = drms_segment_lookup(recLev1p->records[0],Lev1pSegName[i+Lev1pOffset+k*npolout]);
05129 arrLev1p[k*npolout+i]->bzero=segout->bzero;
05130 arrLev1p[k*npolout+i]->bscale=segout->bscale;
05131 arrLev1p[k*npolout+i]->israw=0;
05132 status=drms_segment_write(segout,arrLev1p[k*npolout+i], 0);
05133 if(status != DRMS_SUCCESS)
05134 {
05135 printf("Error: a call to drms_segment_write failed\n");
05136 return 1;
05137 }
05138 }
05139 t1=dsecnd();
05140 printf("TIME ELAPSED TO WRITE THE LEVEL 1p SEGMENTS: %f\n",t1-t0);
05141 }
05142
05143 }
05144
05145
05146
05147
05148
05149 drms_copykeys(recLev1p->records[0],recLev1d->records[0],0, kDRMS_KeyClass_Explicit);
05150
05151
05152 statusA[0] = drms_setkey_float(recLev1p->records[0] ,TFRONTS,TFRONT);
05153 statusA[1] = drms_setkey_float(recLev1p->records[0] ,TSELS,TSEL);
05154 statusA[2] = drms_setkey_int(recLev1p->records[0] ,POLCALMS,method);
05155 statusA[3] = drms_setkey_string(recLev1p->records[0],CODEVER3S,CODEVERSION3);
05156 DSUNOBSint = drms_getkey_double(recLev1d->records[0],DSUNOBSS,&status);
05157 if(status != DRMS_SUCCESS || isnan(DSUNOBSint))
05158 {
05159 printf("Error: %s keyword cannot be read on level 1d data at target time %s\n",DSUNOBSS,timeBegin2);
05160 statusA[4]=1;
05161 }
05162 else
05163 {
05164 ctime1=asin((double)solar_radius/DSUNOBSint)*180.*60.*60./M_PI;
05165 printf("RSUN_OBS = %f\n",ctime1);
05166 statusA[4] = drms_setkey_float(recLev1p->records[0],RSUNOBSS,ctime1);
05167 }
05168 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
05169 statusA[5]= drms_setkey_string(recLev1p->records[0],DATES,DATEOBS);
05170 strcat(source,"]");
05171 statusA[6]= drms_setkey_string(recLev1p->records[0],SOURCES,source);
05172 statusA[7]= drms_setkey_int(recLev1p->records[0],QUALLEV1S,QUALITYLEV1);
05173 statusA[8]= drms_setkey_int(recLev1p->records[0],TINTNUMS,totalTempIntNum);
05174
05175 TotalStatus=0;
05176 for(i=0;i<9;++i) TotalStatus+=statusA[i];
05177 if(TotalStatus != 0)
05178 {
05179 for(i=0;i<9;++i) printf(" %d ",statusA[i]);
05180 printf("\n");
05181 printf("WARNING: could not set some of the keywords for the level 1p data at target time %s\n",timeBegin2);
05182 }
05183
05184
05185
05186
05187 if(Lev1pWanted)
05188 {
05189
05190
05191 X0AVG = (float)drms_getkey_double(recLev1d->records[0],CRPIX1S,&status);
05192 if(status != DRMS_SUCCESS || isnan(X0AVG))
05193 {
05194 printf("Error: %s keyword cannot be read on level 1d data at target time %s\n",CRPIX1S,timeBegin2);
05195 }
05196 X0AVG=X0AVG-1;
05197 printf("X0AVG= %f\n",X0AVG);
05198
05199 Y0AVG = (float)drms_getkey_double(recLev1d->records[0],CRPIX2S,&status);
05200 if(status != DRMS_SUCCESS || isnan(Y0AVG))
05201 {
05202 printf("Error: %s keyword cannot be read on level 1d data at target time %s\n",CRPIX2S,timeBegin2);
05203 }
05204 Y0AVG=Y0AVG-1;
05205 printf("Y0AVG= %f\n",Y0AVG);
05206
05207
05208 for(k=0;k<nRecs1p;++k)
05209 {
05210 for(i=0;i<npolout;++i)
05211 {
05212 strcpy(TOTVALSSS[k*npolout+i],"TOTVALS[");
05213 sprintf(query,"%d",k*npolout+i);
05214 strcat(TOTVALSSS[k*npolout+i],query);
05215 strcat(TOTVALSSS[k*npolout+i],"]");
05216
05217 strcpy(MISSVALSSS[k*npolout+i],"MISSVALS[");
05218 sprintf(query,"%d",k*npolout+i);
05219 strcat(MISSVALSSS[k*npolout+i],query);
05220 strcat(MISSVALSSS[k*npolout+i],"]");
05221
05222 strcpy(DATAVALSSS[k*npolout+i],"DATAVALS[");
05223 sprintf(query,"%d",k*npolout+i);
05224 strcat(DATAVALSSS[k*npolout+i],query);
05225 strcat(DATAVALSSS[k*npolout+i],"]");
05226
05227 strcpy(DATAMEANSS[k*npolout+i],"DATAMEA2[");
05228 sprintf(query,"%d",k*npolout+i);
05229 strcat(DATAMEANSS[k*npolout+i],query);
05230 strcat(DATAMEANSS[k*npolout+i],"]");
05231
05232 strcpy(DATAMINSS[k*npolout+i],"DATAMIN2[");
05233 sprintf(query,"%d",k*npolout+i);
05234 strcat(DATAMINSS[k*npolout+i],query);
05235 strcat(DATAMINSS[k*npolout+i],"]");
05236
05237 strcpy(DATAMAXSS[k*npolout+i],"DATAMAX2[");
05238 sprintf(query,"%d",k*npolout+i);
05239 strcat(DATAMAXSS[k*npolout+i],query);
05240 strcat(DATAMAXSS[k*npolout+i],"]");
05241
05242 strcpy(DATAMEDNSS[k*npolout+i],"DATAMED2[");
05243 sprintf(query,"%d",k*npolout+i);
05244 strcat(DATAMEDNSS[k*npolout+i],query);
05245 strcat(DATAMEDNSS[k*npolout+i],"]");
05246
05247 strcpy(DATARMSSS[k*npolout+i],"DATARMS2[");
05248 sprintf(query,"%d",k*npolout+i);
05249 strcat(DATARMSSS[k*npolout+i],query);
05250 strcat(DATARMSSS[k*npolout+i],"]");
05251
05252 strcpy(DATASKEWSS[k*npolout+i],"DATASKE2[");
05253 sprintf(query,"%d",k*npolout+i);
05254 strcat(DATASKEWSS[k*npolout+i],query);
05255 strcat(DATASKEWSS[k*npolout+i],"]");
05256
05257 strcpy(DATAKURTSS[k*npolout+i],"DATAKUR2[");
05258 sprintf(query,"%d",k*npolout+i);
05259 strcat(DATAKURTSS[k*npolout+i],query);
05260 strcat(DATAKURTSS[k*npolout+i],"]");
05261
05262 strcpy(DATAMINS2S[k*npolout+i],"DATAMIN[");
05263 sprintf(query,"%d",k*npolout+i);
05264 strcat(DATAMINS2S[k*npolout+i],query);
05265 strcat(DATAMINS2S[k*npolout+i],"]");
05266
05267 strcpy(DATAMAXS2S[k*npolout+i],"DATAMAX[");
05268 sprintf(query,"%d",k*npolout+i);
05269 strcat(DATAMAXS2S[k*npolout+i],query);
05270 strcat(DATAMAXS2S[k*npolout+i],"]");
05271
05272 strcpy(DATAMEANS2S[k*npolout+i],"DATAMEAN[");
05273 sprintf(query,"%d",k*npolout+i);
05274 strcat(DATAMEANS2S[k*npolout+i],query);
05275 strcat(DATAMEANS2S[k*npolout+i],"]");
05276
05277 strcpy(DATAMEDNS2S[k*npolout+i],"DATAMEDN[");
05278 sprintf(query,"%d",k*npolout+i);
05279 strcat(DATAMEDNS2S[k*npolout+i],query);
05280 strcat(DATAMEDNS2S[k*npolout+i],"]");
05281
05282 strcpy(DATARMSS2S[k*npolout+i],"DATARMS[");
05283 sprintf(query,"%d",k*npolout+i);
05284 strcat(DATARMSS2S[k*npolout+i],query);
05285 strcat(DATARMSS2S[k*npolout+i],"]");
05286
05287 strcpy(DATASKEWS2S[k*npolout+i],"DATASKEW[");
05288 sprintf(query,"%d",k*npolout+i);
05289 strcat(DATASKEWS2S[k*npolout+i],query);
05290 strcat(DATASKEWS2S[k*npolout+i],"]");
05291
05292 strcpy(DATAKURTS2S[k*npolout+i],"DATAKURT[");
05293 sprintf(query,"%d",k*npolout+i);
05294 strcat(DATAKURTS2S[k*npolout+i],query);
05295 strcat(DATAKURTS2S[k*npolout+i],"]");
05296
05297 image=(float *)arrLev1p[k*npolout+i]->data;
05298
05299
05300 status=fstats(axisout[0]*axisout[1],image,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
05301 if(status != 0)
05302 {
05303 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
05304 }
05305 statusA[6]= drms_setkey_float(recLev1p->records[0],DATAMINSS[k*npolout+i],(float)minimum);
05306 statusA[7]= drms_setkey_float(recLev1p->records[0],DATAMAXSS[k*npolout+i],(float)maximum);
05307 statusA[8]= drms_setkey_float(recLev1p->records[0],DATAMEDNSS[k*npolout+i],(float)median);
05308 statusA[9]= drms_setkey_float(recLev1p->records[0],DATAMEANSS[k*npolout+i],(float)mean);
05309 statusA[10]= drms_setkey_float(recLev1p->records[0],DATARMSSS[k*npolout+i],(float)sigma);
05310 statusA[11]= drms_setkey_float(recLev1p->records[0],DATASKEWSS[k*npolout+i],(float)skewness);
05311 statusA[12]= drms_setkey_float(recLev1p->records[0],DATAKURTSS[k*npolout+i],(float)kurtosis);
05312 statusA[13]= drms_setkey_int(recLev1p->records[0],TOTVALSSS[k*npolout+i],axisout[0]*axisout[1]);
05313 statusA[14]= drms_setkey_int(recLev1p->records[0],DATAVALSSS[k*npolout+i],ngood);
05314 statusA[15]= drms_setkey_int(recLev1p->records[0],MISSVALSSS[k*npolout+i],axisout[0]*axisout[1]-ngood);
05315
05316 for(ii=0;ii<axisout[0]*axisout[1];++ii)
05317 {
05318 row =ii / axisout[0];
05319 column=ii % axisout[0];
05320 distance = sqrt(((float)row-Y0AVG)*((float)row-Y0AVG)+((float)column-X0AVG)*((float)column-X0AVG));
05321 if(distance > 0.99*RSUNint) image[ii]=NAN;
05322 }
05323
05324 status=fstats(axisout[0]*axisout[1],image,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
05325 if(status != 0)
05326 {
05327 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
05328 }
05329 statusA[16]= drms_setkey_float(recLev1p->records[0],DATAMINS2S[k*npolout+i],(float)minimum);
05330 statusA[17]= drms_setkey_float(recLev1p->records[0],DATAMAXS2S[k*npolout+i],(float)maximum);
05331 statusA[18]= drms_setkey_float(recLev1p->records[0],DATAMEDNS2S[k*npolout+i],(float)median);
05332 statusA[19]= drms_setkey_float(recLev1p->records[0],DATAMEANS2S[k*npolout+i],(float)mean);
05333 statusA[20]= drms_setkey_float(recLev1p->records[0],DATARMSS2S[k*npolout+i],(float)sigma);
05334 statusA[21]= drms_setkey_float(recLev1p->records[0],DATASKEWS2S[k*npolout+i],(float)skewness);
05335 statusA[22]= drms_setkey_float(recLev1p->records[0],DATAKURTS2S[k*npolout+i],(float)kurtosis);
05336
05337 TotalStatus=0;
05338 for(ii=6;ii<23;++ii) TotalStatus+=statusA[ii];
05339 if(TotalStatus != 0)
05340 {
05341 for(ii=6;ii<23;++ii) printf(" %d ",statusA[ii]);
05342 printf("\n");
05343 printf("WARNING: could not set some of the keywords for the level 1p data at target time %s\n",timeBegin2);
05344 }
05345
05346 }
05347 }
05348 }
05349
05350 Segments1p=1;
05351
05352 }
05353
05354
05355
05356
05357
05358
05359
05360
05361
05362
05363
05364
05365 if (Lev15Wanted)
05366 {
05367
05368
05369
05370
05371
05372 int ActualnSegs1p=nSegs1p;
05373
05374 if(Segments1p == 0)
05375 {
05376 if(PolarizationType ==2 || PolarizationType ==3) nSegs1p=nRecs1p*2;
05377 if(PolarizationType ==1) nSegs1p=nRecs1p*4;
05378
05379 arrLev1p = (DRMS_Array_t **)malloc(nSegs1p*sizeof(DRMS_Array_t *));
05380 if(arrLev1p == NULL)
05381 {
05382 printf("Error: memory could not be allocated to arrLev1p\n");
05383 return 1;
05384 }
05385
05386
05387
05388
05389
05390
05391
05392
05393
05394
05395 printf("READING %d DATA SEGMENTS OF LEVEL 1p RECORDS\n",nSegs1p);
05396 for(i=0;i<nSegs1p;++i)
05397 {
05398 printf("%d\n",i);
05399 segin = drms_segment_lookupnum(recLev1p->records[0],i);
05400 arrLev1p[i] = drms_segment_read(segin,type1p,&status);
05401 if(status != DRMS_SUCCESS || arrLev1p[i] == NULL)
05402 {
05403 printf("Error: could not read the segment for level 1p data index %d at target time %s \n",i,timeBegin2);
05404 arrLev1p[i] = NULL;
05405 ActualnSegs1p-=1;
05406 }
05407 }
05408
05409
05410
05411 if(PolarizationType == 1)
05412 {
05413 if(ActualnSegs1p != nSegs1p)
05414 {
05415 printf("Error: some level 1p data are missing to produce level 1.5 data: %d\n",ActualnSegs1p);
05416 QUALITY = QUALITY | QUAL_MISSINGLEV1P;
05417 CreateEmptyRecord=1; goto NextTargetTime;
05418 }
05419 else
05420 {
05421 printf("PRODUCING LCP+RCP FROM I,Q,U,V DATA\n");
05422 LCP=(float *)malloc(axisin[0]*axisin[1]*sizeof(float));
05423 RCP=(float *)malloc(axisin[0]*axisin[1]*sizeof(float));
05424 if(LCP == NULL || RCP == NULL)
05425 {
05426 printf("Error: could not create LCP and/or RCP array \n");
05427 return 1;
05428 }
05429 j=0;
05430 for (i=0;i<nRecs1p;++i)
05431 {
05432 temparr1=(float *)arrLev1p[i*4]->data;
05433 temparr2=(float *)arrLev1p[i*4+3]->data;
05434 temparr3=(float *)arrLev1p[j*2]->data;
05435 temparr4=(float *)arrLev1p[j*2+1]->data;
05436 for(ii=0;ii<axisin[0]*axisin[1];++ii)
05437 {
05438 LCP[ii]=temparr1[ii]+temparr2[ii];
05439 RCP[ii]=temparr1[ii]-temparr2[ii];
05440 temparr3[ii]=LCP[ii];
05441 temparr4[ii]=RCP[ii];
05442 }
05443 j+=1;
05444 }
05445 free(LCP);
05446 free(RCP);
05447 LCP=NULL;
05448 RCP=NULL;
05449 PolarizationType=3;
05450 nSegs1p=nRecs1p*2;
05451 ActualnSegs1p = nSegs1p;
05452 for(i=nSegs1p;i<nRecs1p*4;++i) if(arrLev1p[i] != NULL)
05453 {
05454 drms_free_array(arrLev1p[i]);
05455 arrLev1p[i]=NULL;
05456 }
05457 }
05458 }
05459
05460 printf("READING DONE\n");
05461
05462
05463 TargetHFLID = drms_getkey_int(recLev1p->records[0],HFLIDS,&status);
05464 if(status != DRMS_SUCCESS)
05465 {
05466 printf("Error: HFLID keyword cannot be read on level 1p data at target time %s\n",timeBegin2);
05467 CreateEmptyRecord=1; goto NextTargetTime;
05468 }
05469 TargetHPLTID = drms_getkey_int(recLev1p->records[0],HPLTIDS,&status);
05470 if(status != DRMS_SUCCESS)
05471 {
05472 printf("Error: HPLTID keyword cannot be read on level 1p data at target time %s\n",timeBegin2);
05473 CreateEmptyRecord=1; goto NextTargetTime;
05474 }
05475 TargetHWLTID = drms_getkey_int(recLev1p->records[0],HWLTIDS,&status);
05476 if(status != DRMS_SUCCESS)
05477 {
05478 printf("Error: HWLTID keyword cannot be read on level 1p data at target time %s\n",timeBegin2);
05479 CreateEmptyRecord=1; goto NextTargetTime;
05480 }
05481 WavelengthID2 = drms_getkey_int(recLev1p->records[0],WavelengthIDS,&status);
05482 if(status != DRMS_SUCCESS)
05483 {
05484 printf("Error: WavelengthID2 keyword cannot be read on level 1p data at target time %s\n",timeBegin2);
05485 CreateEmptyRecord=1; goto NextTargetTime;
05486 }
05487 if(WavelengthID2 != WavelengthID)
05488 {
05489 printf("Error: WavelengthID2 != WavelengthID\n");
05490 return 1;
05491 }
05492
05493 Segments1p=1;
05494 framelistSize = framelistInfo(TargetHFLID,TargetHPLTID,TargetHWLTID,WavelengthID,PHWPLPOS,WavelengthIndex,WavelengthLocation,&PolarizationType,CamId,&combine,&npol,MaxNumFiltergrams,&CadenceRead,CameraValues,FIDValues,dpath);
05495 if(framelistSize == 1) return 1;
05496 }
05497
05498
05499
05500
05501 if(ActualnSegs1p != nSegs1p)
05502 {
05503 printf("Error: some level 1p data are missing to produce level 1.5 data: %d\n",ActualnSegs1p);
05504 QUALITY = QUALITY | QUAL_MISSINGLEV1P;
05505 CreateEmptyRecord=1; goto NextTargetTime;
05506 }
05507
05508
05509
05510
05511 i=0;
05512 while(WavelengthIndex[i] != 2) i++;
05513 int HCMNBT,HCMWBT,HCMPOLT,HCME1T;
05514
05515 if( (framelistSize/npol == 6) || (framelistSize/npol == 8) || (framelistSize/npol == 10) )
05516 {
05517 HCMNBT = PHWPLPOS[7*i+3]+12;
05518 HCMWBT = PHWPLPOS[7*i+1]+6;
05519 HCMPOLT= PHWPLPOS[7*i+2];
05520 HCME1T = PHWPLPOS[7*i+0]-3;
05521 }
05522 if(framelistSize/npol == 5)
05523 {
05524 HCMNBT = PHWPLPOS[7*i+3];
05525 HCMWBT = PHWPLPOS[7*i+1];
05526 HCMPOLT= PHWPLPOS[7*i+2];
05527 HCME1T = PHWPLPOS[7*i+0];
05528 }
05529 printf("KEYWORD VALUES: %d %d %d %d\n",HCMNBT,HCMWBT,HCME1T,HCMPOLT);
05530
05531 char keylist[]="HWL4POS,HWL3POS,HWL2POS,HWL1POS,NWL,HCAMID,FSN_REC";
05532 int unique=0;
05533 int n0,n1;
05534
05535 int NBC,WBC,E1C,POLC,NC,CAMERAUSED,FSNLOOKUP;
05536
05537 arrayL0 = drms_record_getvector(drms_env,HMISeriesLookup, keylist, typeLO, unique, &status);
05538 if(status != DRMS_SUCCESS)
05539 {
05540 printf("Error: cannot read a list of keywords in the look-up table series\n");
05541 QUALITY = QUALITY | QUAL_NOLOOKUPKEYWORD;
05542 CreateEmptyRecord=1; goto NextTargetTime;
05543 }
05544 printf("DIMENSIONS= %d %d\n",arrayL0->axis[0],arrayL0->axis[1]);
05545 keyL=arrayL0->data;
05546 arrayL1 = drms_record_getvector(drms_env,HMISeriesLookup,TRECS,DRMS_TYPE_DOUBLE , unique, &status);
05547 if(status != DRMS_SUCCESS)
05548 {
05549 printf("Error: cannot read a list of keywords in the look-up table series\n");
05550 QUALITY = QUALITY | QUAL_NOLOOKUPKEYWORD;
05551 CreateEmptyRecord=1; goto NextTargetTime;
05552 }
05553
05554 timeL=arrayL1->data;
05555
05556 n1=arrayL0->axis[1];
05557 n0=arrayL0->axis[0];
05558 if(n1 != arrayL1->axis[1])
05559 {
05560 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");
05561 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05562 CreateEmptyRecord=1; goto NextTargetTime;
05563 }
05564 printf("%d RECORDS FOUND FOR THE LOOK-UP TABLES\n",n1);
05565
05566 count = (double *)malloc(n1*sizeof(double));
05567 if(count == NULL)
05568 {
05569 printf("Error: memory could not be allocated to count\n");
05570 return 1;
05571 }
05572
05573 temptime = 1000000000.0;
05574 temp = 0;
05575
05576 for(i=0;i<n1;++i)
05577 {
05578 count[i] = fabs(timeL[i]-TargetTime);
05579 NBC = abs(keyL[ i]-HCMNBT);
05580 POLC= abs(keyL[ n1+i]-HCMPOLT);
05581 WBC = abs(keyL[2*n1+i]-HCMWBT);
05582 E1C = abs(keyL[3*n1+i]-HCME1T);
05583 NC = abs(keyL[4*n1+i]-framelistSize/npol);
05584 CAMERAUSED = abs(keyL[5*n1+i]-CamId);
05585 if(count[i] < temptime && NBC+WBC+POLC+E1C+NC+CAMERAUSED == 0)
05586 {
05587 temptime=count[i];
05588 temp=i;
05589 }
05590 }
05591 if(temptime == 1000000000.0)
05592 {
05593 printf("Error: could not find a look-up table with the correct keywords to produce level 1.5 data\n");
05594 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05595 CreateEmptyRecord=1; goto NextTargetTime;
05596 }
05597
05598 printf("Index of the retrieved look-up table %d %d\n",temp,n1);
05599 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]);
05600 FSNLOOKUP = keyL[6*n1+temp];
05601
05602
05603 sprintf(query,"%d",FSNLOOKUP);
05604 strcpy(HMILookup,HMISeriesLookup);
05605 strcat(HMILookup,"[");
05606 strcat(HMILookup,query);
05607 strcat(HMILookup,"][][");
05608 if(CamId == 0) strcat(HMILookup,"0");
05609 if(CamId == 1) strcat(HMILookup,"1");
05610 if(CamId == 2) strcat(HMILookup,"2");
05611 if(CamId == 3) strcat(HMILookup,"3");
05612 strcat(HMILookup,"][");
05613 sprintf(query,"%d",HCME1T);
05614 strcat(HMILookup,query);
05615 strcat(HMILookup,"][");
05616 sprintf(query,"%d",HCMWBT);
05617 strcat(HMILookup,query);
05618 strcat(HMILookup,"][");
05619 sprintf(query,"%d",HCMPOLT);
05620 strcat(HMILookup,query);
05621 strcat(HMILookup,"][");
05622 sprintf(query,"%d",HCMNBT);
05623 strcat(HMILookup,query);
05624 strcat(HMILookup,"][");
05625 NC=framelistSize/npol;
05626 sprintf(query,"%d",NC);
05627 strcat(HMILookup,query);
05628 strcat(HMILookup,"]");
05629
05630 printf("QUERY= %s\n",HMILookup);
05631
05632 drms_free_array(arrayL0);
05633 arrayL0=NULL;
05634 drms_free_array(arrayL1);
05635 arrayL1=NULL;
05636 free(count);
05637 count=NULL;
05638
05639 lookup = drms_open_records(drms_env,HMILookup,&status);
05640 if (status == DRMS_SUCCESS && lookup != NULL)
05641 {
05642 if (lookup->n > 1)
05643 {
05644 printf("Error: more than 1 lookup table record was downloaded.\n");
05645 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05646 CreateEmptyRecord=1; goto NextTargetTime;
05647 }
05648 if (lookup->n <= 0)
05649 {
05650 printf("Error:no record for the look-up tables were downloaded.\n");
05651 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05652 CreateEmptyRecord=1; goto NextTargetTime;
05653 }
05654 }
05655 else
05656 {
05657 printf("Error: can't open the look-up table series.\n");
05658 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05659 CreateEmptyRecord=1; goto NextTargetTime;
05660 }
05661
05662 segin = drms_segment_lookupnum(lookup->records[0], 0);
05663 arrintable= drms_segment_read(segin, segin->info->type, &status);
05664 if (status != DRMS_SUCCESS || arrintable == NULL)
05665 {
05666 printf("Error: unable to read the data segment of the look-up table record\n");
05667 return 1;
05668
05669
05670 }
05671 else printf("look-up table record read\n");
05672
05673
05674
05675
05676
05677 int FSNDIFF;
05678 char keylistCoeff[]="COEFF0,COEFF1,COEFF2,COEFF3";
05679
05680 arrayL0 = drms_record_getvector(drms_env,HMISeriesCoeffs, keylistCoeff, DRMS_TYPE_DOUBLE, unique, &status);
05681 if(status != DRMS_SUCCESS)
05682 {
05683 printf("Error: cannot read a list of keywords in the polynomial coefficient series\n");
05684 QUALITY = QUALITY | QUAL_NOCOEFFKEYWORD;
05685 CreateEmptyRecord=1; goto NextTargetTime;
05686 }
05687 TIME *keyt=NULL;
05688 keyt=arrayL0->data;
05689
05690 arrayL1 = drms_record_getvector(drms_env,HMISeriesCoeffs,TRECS,DRMS_TYPE_DOUBLE, unique, &status);
05691 if(status != DRMS_SUCCESS)
05692 {
05693 printf("Error: cannot read a list of keywords in the polynomial coefficient series\n");
05694 QUALITY = QUALITY | QUAL_NOCOEFFKEYWORD;
05695 CreateEmptyRecord=1; goto NextTargetTime;
05696 }
05697 timeL=arrayL1->data;
05698
05699 arrayL2 = drms_record_getvector(drms_env,HMISeriesCoeffs,CALFSNS,DRMS_TYPE_INT, unique, &status);
05700 if(status != DRMS_SUCCESS)
05701 {
05702 printf("Error: cannot read a list of keywords in the polynomial coefficient series\n");
05703 QUALITY = QUALITY | QUAL_NOCOEFFKEYWORD;
05704 CreateEmptyRecord=1; goto NextTargetTime;
05705 }
05706 FSNL=arrayL2->data;
05707
05708 n1=arrayL0->axis[1];
05709 n0=arrayL0->axis[0];
05710 if(n1 != arrayL1->axis[1] || n1 != arrayL2->axis[1])
05711 {
05712 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");
05713 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05714 CreateEmptyRecord=1; goto NextTargetTime;
05715 }
05716 printf("%d RECORDS FOUND FOR THE POLYNOMIAL COEFFICIENTS\n",n1);
05717
05718 count = (double *)malloc(n1*sizeof(double));
05719 if(count == NULL)
05720 {
05721 printf("Error: memory could not be allocated to count\n");
05722 return 1;
05723 }
05724
05725
05726 if(QuickLook != 1)
05727 {
05728 temptime = 1000000000.0;
05729 temp = 0;
05730 temp2= 0;
05731
05732 for(i=0;i<n1;++i)
05733 {
05734 count[i] = fabs(timeL[i]-TargetTime);
05735 FSNDIFF = FSNL[i]-FSNLOOKUP;
05736 if(count[i] < temptime && FSNDIFF == 0 && timeL[i]<TargetTime)
05737 {
05738 temptime=count[i];
05739 temp=i;
05740 }
05741 }
05742 if(temptime > 86400.0)
05743 {
05744 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");
05745 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05746 CreateEmptyRecord=1; goto NextTargetTime;
05747 }
05748
05749 temptime = 1000000000.0;
05750
05751 for(i=0;i<n1;++i)
05752 {
05753 count[i] = fabs(timeL[i]-TargetTime);
05754 FSNDIFF = FSNL[i]-FSNLOOKUP;
05755 if(count[i] < temptime && FSNDIFF == 0 && timeL[i]>=TargetTime)
05756 {
05757 temptime=count[i];
05758 temp2=i;
05759 }
05760 }
05761 if(temptime > 86400.0)
05762 {
05763 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");
05764 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05765 CreateEmptyRecord=1; goto NextTargetTime;
05766 }
05767
05768 }
05769 else
05770 {
05771
05772 temptime = 1000000000.0;
05773 temp = 0;
05774
05775 for(i=0;i<n1;++i)
05776 {
05777 count[i] = fabs(timeL[i]-TargetTime);
05778 if(count[i] < temptime)
05779 {
05780 temptime=count[i];
05781 temp=i;
05782 }
05783 }
05784 temp2=temp;
05785 }
05786
05787 printf("Indeces of the retrieved polynomial record %d %d %d\n",temp,temp2,n1);
05788 printf("Keyword values of the retrieved polynomial record: %d\n",FSNL[temp]-FSNLOOKUP);
05789
05790
05791 sprint_time(query,timeL[temp],"TAI",1);
05792 strcpy(HMICoeffs,HMISeriesCoeffs);
05793 strcat(HMICoeffs,"[");
05794 strcat(HMICoeffs,query);
05795 strcat(HMICoeffs,"]");
05796
05797 printf("QUERY= %s\n",HMICoeffs);
05798
05799 recpoly = drms_open_records(drms_env,HMICoeffs,&status);
05800 if (status == DRMS_SUCCESS && recpoly != NULL && recpoly->n != 0)
05801 {
05802 coeff[0]=drms_getkey_double(recpoly->records[0],COEFF0S,&status);
05803 if(status != DRMS_SUCCESS)
05804 {
05805 printf("Error: could not read a polynomial coefficient\n");
05806 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05807 CreateEmptyRecord=1; goto NextTargetTime;
05808 }
05809 coeff[1]=drms_getkey_double(recpoly->records[0],COEFF1S,&status);
05810 if(status != DRMS_SUCCESS)
05811 {
05812 printf("Error: could not read a polynomial coefficient\n");
05813 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05814 CreateEmptyRecord=1; goto NextTargetTime;
05815 }
05816 coeff[2]=drms_getkey_double(recpoly->records[0],COEFF2S,&status);
05817 if(status != DRMS_SUCCESS)
05818 {
05819 printf("Error: could not read a polynomial coefficient\n");
05820 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05821 CreateEmptyRecord=1; goto NextTargetTime;
05822 }
05823 coeff[3]=drms_getkey_double(recpoly->records[0],COEFF3S,&status);
05824 if(status != DRMS_SUCCESS)
05825 {
05826 printf("Error: could not read a polynomial coefficient\n");
05827 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05828 CreateEmptyRecord=1; goto NextTargetTime;
05829 }
05830 }
05831 else
05832 {
05833 printf("Error: can't open the polynomial coefficients series.\n");
05834 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05835 CreateEmptyRecord=1; goto NextTargetTime;
05836 }
05837
05838
05839 if(QuickLook != 1)
05840 {
05841
05842 sprint_time(query,timeL[temp2],"TAI",1);
05843 strcpy(HMICoeffs,HMISeriesCoeffs);
05844 strcat(HMICoeffs,"[");
05845 strcat(HMICoeffs,query);
05846 strcat(HMICoeffs,"]");
05847
05848 printf("QUERY= %s\n",HMICoeffs);
05849
05850 recpoly2 = drms_open_records(drms_env,HMICoeffs,&status);
05851 if (status == DRMS_SUCCESS && recpoly2 != NULL && recpoly2->n != 0)
05852 {
05853 coeff2[0]=drms_getkey_double(recpoly2->records[0],COEFF0S,&status);
05854 if(status != DRMS_SUCCESS)
05855 {
05856 printf("Error: could not read a polynomial coefficient\n");
05857 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05858 CreateEmptyRecord=1; goto NextTargetTime;
05859 }
05860 coeff2[1]=drms_getkey_double(recpoly2->records[0],COEFF1S,&status);
05861 if(status != DRMS_SUCCESS)
05862 {
05863 printf("Error: could not read a polynomial coefficient\n");
05864 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05865 CreateEmptyRecord=1; goto NextTargetTime;
05866 }
05867 coeff2[2]=drms_getkey_double(recpoly2->records[0],COEFF2S,&status);
05868 if(status != DRMS_SUCCESS)
05869 {
05870 printf("Error: could not read a polynomial coefficient\n");
05871 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05872 CreateEmptyRecord=1; goto NextTargetTime;
05873 }
05874 coeff2[3]=drms_getkey_double(recpoly2->records[0],COEFF3S,&status);
05875 if(status != DRMS_SUCCESS)
05876 {
05877 printf("Error: could not read a polynomial coefficient\n");
05878 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05879 CreateEmptyRecord=1; goto NextTargetTime;
05880 }
05881 }
05882 else
05883 {
05884 printf("Error: can't open the polynomial coefficients series.\n");
05885 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05886 CreateEmptyRecord=1; goto NextTargetTime;
05887 }
05888 }
05889 else recpoly2 = NULL;
05890
05891
05892 printf("Polynomial coefficient values: %e %e %e %e\n",coeff[0],coeff[1],coeff[2],coeff[3]);
05893
05894 if(QuickLook != 1)
05895 {
05896 printf("Polynomial coefficient values: %e %e %e %e\n",coeff2[0],coeff2[1],coeff2[2],coeff2[3]);
05897 coeff[0]=(TargetTime-timeL[temp])*(coeff2[0]-coeff[0])/(timeL[temp2]-timeL[temp])+coeff[0];
05898 coeff[1]=(TargetTime-timeL[temp])*(coeff2[1]-coeff[1])/(timeL[temp2]-timeL[temp])+coeff[1];
05899 coeff[2]=(TargetTime-timeL[temp])*(coeff2[2]-coeff[2])/(timeL[temp2]-timeL[temp])+coeff[2];
05900 coeff[3]=(TargetTime-timeL[temp])*(coeff2[3]-coeff[3])/(timeL[temp2]-timeL[temp])+coeff[3];
05901 }
05902
05903
05904 drms_free_array(arrayL0);
05905 arrayL0=NULL;
05906 drms_free_array(arrayL1);
05907 arrayL1=NULL;
05908 drms_free_array(arrayL2);
05909 arrayL2=NULL;
05910 free(count);
05911 count=NULL;
05912
05913 strcpy(HISTORY,"Polynomial Coefficients used for Doppler velocity correction: ");
05914 sprintf(query,"%e",coeff[0]);
05915 strcat(HISTORY,query);
05916 strcat(HISTORY," ");
05917 sprintf(query,"%e",coeff[1]);
05918 strcat(HISTORY,query);
05919 strcat(HISTORY," ");
05920 sprintf(query,"%e",coeff[2]);
05921 strcat(HISTORY,query);
05922 strcat(HISTORY," ");
05923 sprintf(query,"%e",coeff[3]);
05924 strcat(HISTORY,query);
05925 strcat(HISTORY," ");
05926
05927
05928
05929
05930
05931 nRecs15 = 6;
05932
05933 recLev15a = drms_create_records(drms_env,1,HMISeriesLev15a,DRMS_PERMANENT,&statusA[0]);
05934 recLev15b = drms_create_records(drms_env,1,HMISeriesLev15b,DRMS_PERMANENT,&statusA[1]);
05935 recLev15c = drms_create_records(drms_env,1,HMISeriesLev15c,DRMS_PERMANENT,&statusA[2]);
05936 recLev15d = drms_create_records(drms_env,1,HMISeriesLev15d,DRMS_PERMANENT,&statusA[3]);
05937 recLev15e = drms_create_records(drms_env,1,HMISeriesLev15e,DRMS_PERMANENT,&statusA[4]);
05938 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);
05939
05940
05941 if ( (statusA[0]+statusA[1]+statusA[2]+statusA[3]+statusA[4]) != DRMS_SUCCESS || recLev15a == NULL || recLev15b == NULL || recLev15c == NULL|| recLev15d == NULL || recLev15e == NULL)
05942 {
05943 printf("Could not create a record for one or several level 1.5 data series, at target time %s\n",timeBegin2);
05944
05945
05946
05947
05948
05949
05950
05951 return 1;
05952 }
05953 if(recLev15a->n == 0 || recLev15b->n == 0 || recLev15c->n == 0 || recLev15d->n == 0 || recLev15e->n == 0)
05954 {
05955 printf("Could not create a record for one or several level 1.5 data series, at target time %s\n",timeBegin2);
05956
05957
05958
05959
05960
05961
05962
05963 return 1;
05964 }
05965
05966
05967 arrLev15 = (DRMS_Array_t **)malloc(nRecs15*sizeof(DRMS_Array_t *));
05968 if(arrLev15 == NULL)
05969 {
05970 printf("Error: memory could not be allocated to arrLev15\n");
05971 return 1;
05972 }
05973 for (i=0;i<nRecs15;++i)
05974 {
05975 arrLev15[i] = drms_array_create(type15,2,axisout,NULL,&status);
05976 if(status != DRMS_SUCCESS || arrLev15[i] == NULL)
05977 {
05978 printf("Error: cannot create an array for a level 1.5 data at target time %s\n",timeBegin2);
05979
05980
05981 return 1;
05982 }
05983
05984 }
05985
05986
05987
05988 X0AVG = (float)drms_getkey_double(recLev1p->records[0],CRPIX1S,&status);
05989 if(status != DRMS_SUCCESS || isnan(X0AVG))
05990 {
05991 printf("Error: %s keyword cannot be read on level 1p data at target time %s\n",CRPIX1S,timeBegin2);
05992 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1P;
05993 CreateEmptyRecord=1; goto NextTargetTime;
05994 }
05995 X0AVG=X0AVG-1;
05996
05997 Y0AVG = (float)drms_getkey_double(recLev1p->records[0],CRPIX2S,&status);
05998 if(status != DRMS_SUCCESS || isnan(Y0AVG))
05999 {
06000 printf("Error: %s keyword cannot be read on level 1p data at target time %s\n",CRPIX2S,timeBegin2);
06001 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1P;
06002 CreateEmptyRecord=1; goto NextTargetTime;
06003 }
06004 Y0AVG=Y0AVG-1;
06005
06006 DSUNOBSint = drms_getkey_double(recLev1p->records[0],DSUNOBSS,&status);
06007 if(status != DRMS_SUCCESS || isnan(DSUNOBSint))
06008 {
06009 printf("Error: %s keyword cannot be read on level 1p data at target time %s\n",DSUNOBSS,timeBegin2);
06010 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1P;
06011 CreateEmptyRecord=1; goto NextTargetTime;
06012 }
06013
06014 cdelt1 = (float)drms_getkey_double(recLev1p->records[0],CDELT1S,&status);
06015 if(status != DRMS_SUCCESS || isnan(cdelt1))
06016 {
06017 printf("Error: %s keyword cannot be read on level 1p data at target time %s\n",CDELT1S,timeBegin2);
06018 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1P;
06019 CreateEmptyRecord=1; goto NextTargetTime;
06020 }
06021
06022
06023
06024
06025
06026
06027
06028
06029
06030
06031 RSUNint=1.0/cdelt1*asin((double)solar_radius/DSUNOBSint)*180.*60.*60./M_PI;
06032
06033
06034 DopplerParameters.FSRNB=FSR[0];
06035 DopplerParameters.FSRWB=FSR[1];
06036 DopplerParameters.FSRE1=FSR[2];
06037 DopplerParameters.FSRE2=FSR[3];
06038 DopplerParameters.FSRE3=FSR[4];
06039 DopplerParameters.FSRE4=FSR[5];
06040 DopplerParameters.FSRE5=FSR[6];
06041 DopplerParameters.dlamdv=dlamdv;
06042 DopplerParameters.maxVtest=ntest*2;
06043 DopplerParameters.maxNx=maxNx;
06044 DopplerParameters.ntest=ntest;
06045 DopplerParameters.dvtest=dvtest;
06046 DopplerParameters.MISSINGDATA=MISSINGDATA;
06047 DopplerParameters.MISSINGRESULT=MISSINGRESULT;
06048 DopplerParameters.coeff0=coeff[0];
06049 DopplerParameters.coeff1=coeff[1];
06050 DopplerParameters.coeff2=coeff[2];
06051 DopplerParameters.coeff3=coeff[3];
06052 DopplerParameters.QuickLook=QuickLook;
06053
06054 if(framelistSize/2 == 10 || framelistSize/2 == 8 || framelistSize/2 == 20)
06055 {
06056 ntest=1333;
06057 DopplerParameters.maxVtest=ntest*2;
06058 DopplerParameters.ntest=ntest;
06059 }
06060
06061 t0=dsecnd();
06062
06063 Dopplergram_largercrop(arrLev1p,arrLev15,nSegs1p,arrintable,RSUNint,X0AVG,Y0AVG,DopplerParameters,MISSVALS,&SATVALS,cdelt1,TargetTime);
06064
06065 t1=dsecnd();
06066 printf("TIME ELAPSED IN DOPPLERGRAM(): %f\n",t1-t0);
06067
06068 printf("KEYWORDS OF Dopplergram() %f %f %f\n",RSUNint,X0AVG,Y0AVG);
06069 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);
06070
06071
06072 t0=dsecnd();
06073 segout = drms_segment_lookupnum(recLev15a->records[0], 0);
06074 arrLev15[0]->bzero=segout->bzero;
06075 arrLev15[0]->bscale=segout->bscale;
06076 arrLev15[0]->israw=0;
06077 status=drms_segment_write(segout,arrLev15[0], 0);
06078 if(status != DRMS_SUCCESS)
06079 {
06080 printf("Error: a call to drms_segment_write failed\n");
06081 return 1;
06082 }
06083
06084 segout = drms_segment_lookupnum(recLev15b->records[0], 0);
06085 arrLev15[1]->bzero=segout->bzero;
06086 arrLev15[1]->bscale=segout->bscale;
06087 arrLev15[1]->israw=0;
06088 status=drms_segment_write(segout,arrLev15[1], 0);
06089 if(status != DRMS_SUCCESS)
06090 {
06091 printf("Error: a call to drms_segment_write failed\n");
06092 return 1;
06093 }
06094
06095 segout = drms_segment_lookupnum(recLev15c->records[0], 0);
06096 arrLev15[2]->bzero=segout->bzero;
06097 arrLev15[2]->bscale=segout->bscale;
06098 arrLev15[2]->israw=0;
06099 status=drms_segment_write(segout,arrLev15[2], 0);
06100 if(status != DRMS_SUCCESS)
06101 {
06102 printf("Error: a call to drms_segment_write failed\n");
06103 return 1;
06104 }
06105
06106 segout = drms_segment_lookupnum(recLev15d->records[0], 0);
06107 arrLev15[3]->bzero=segout->bzero;
06108 arrLev15[3]->bscale=segout->bscale;
06109 arrLev15[3]->israw=0;
06110 status=drms_segment_write(segout,arrLev15[3], 0);
06111 if(status != DRMS_SUCCESS)
06112 {
06113 printf("Error: a call to drms_segment_write failed\n");
06114 return 1;
06115 }
06116
06117 segout = drms_segment_lookupnum(recLev15e->records[0], 0);
06118 arrLev15[4]->bzero=segout->bzero;
06119 arrLev15[4]->bscale=segout->bscale;
06120 arrLev15[4]->israw=0;
06121 status=drms_segment_write(segout,arrLev15[4], 0);
06122 if(status != DRMS_SUCCESS)
06123 {
06124 printf("Error: a call to drms_segment_write failed\n");
06125 return 1;
06126 }
06127
06128 t1=dsecnd();
06129 printf("TIME ELAPSED TO WRITE THE LEVEL 1.5 SEGMENTS: %f\n",t1-t0);
06130
06131
06132
06133 image0=(float *)arrLev15[5]->data;
06134
06135 for(i=0;i<axisout[0]*axisout[1];++i)
06136 {
06137 row =i / axisout[0];
06138 column=i % axisout[0];
06139 distance = sqrt(((float)row-Y0AVG)*((float)row-Y0AVG)+((float)column-X0AVG)*((float)column-X0AVG));
06140 if(distance > 0.99*RSUNint)
06141 {
06142 image0[i]=NAN;
06143 }
06144 }
06145 status=fstats(axisout[0]*axisout[1],arrLev15[5]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06146 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06147 statusA[2]= drms_setkey_float(recLev15a->records[0],RAWMEDNS,(float)median);
06148 if(statusA[2] != 0)
06149 {
06150 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);
06151 }
06152
06153
06154
06155 t0=dsecnd();
06156 drms_copykeys(recLev15a->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06157
06158 status=fstats(axisout[0]*axisout[1],arrLev15[0]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06159 if(status != 0)
06160 {
06161 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06162 }
06163
06164 image=arrLev15[0]->data;
06165 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))
06166 {
06167 MISSVALS[0]+=1;
06168 ngood -= 1;
06169 }
06170
06171
06172
06173 statusA[0]= drms_setkey_int(recLev15a->records[0],TOTVALSS,ngood+MISSVALS[0]);
06174 statusA[1]= drms_setkey_int(recLev15a->records[0],DATAVALSS,ngood);
06175
06176 statusA[2]= drms_setkey_int(recLev15a->records[0],MISSVALSS,MISSVALS[0]);
06177 statusA[3]= drms_setkey_float(recLev15a->records[0],DATAMINS,(float)minimum);
06178 statusA[4]= drms_setkey_float(recLev15a->records[0],DATAMAXS,(float)maximum);
06179 statusA[5]= drms_setkey_float(recLev15a->records[0],DATAMEDNS,(float)median);
06180 statusA[6]= drms_setkey_float(recLev15a->records[0],DATAMEANS,(float)mean);
06181 statusA[7]= drms_setkey_float(recLev15a->records[0],DATARMSS,(float)sigma);
06182 statusA[8]= drms_setkey_float(recLev15a->records[0],DATASKEWS,(float)skewness);
06183 statusA[9]= drms_setkey_float(recLev15a->records[0],DATAKURTS,(float)kurtosis);
06184 statusA[10]=drms_setkey_int(recLev15a->records[0],CALFSNS,FSNLOOKUP);
06185 statusA[11]=drms_setkey_string(recLev15a->records[0],LUTQUERYS,HMILookup);
06186 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06187 statusA[12]= drms_setkey_string(recLev15a->records[0],DATES,DATEOBS);
06188 statusA[13]= drms_setkey_int(recLev15a->records[0],QUALITYS,QUALITY);
06189 statusA[14]= drms_setkey_int(recLev15a->records[0],SATVALSS,SATVALS);
06190 statusA[15]= drms_setkey_string(recLev15a->records[0],SOURCES,source);
06191 statusA[16]= drms_setkey_int(recLev15a->records[0],QUALLEV1S,QUALITYLEV1);
06192 statusA[17]= drms_setkey_string(recLev15a->records[0],COMMENTS,COMMENT);
06193 statusA[18]=0;
06194 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15a->records[0],CALVER64S,CALVER64);
06195
06196 TotalStatus=0;
06197 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06198 if(TotalStatus != 0)
06199 {
06200 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the Dopplergram at target time %s\n",timeBegin2);
06201 }
06202
06203
06204
06205 drms_copykeys(recLev15b->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06206
06207 status=fstats(axisout[0]*axisout[1],arrLev15[1]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06208 if(status != 0)
06209 {
06210 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06211 }
06212
06213 image=arrLev15[1]->data;
06214 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))
06215 {
06216 MISSVALS[1]+=1;
06217 ngood -= 1;
06218 }
06219
06220
06221 statusA[0]= drms_setkey_int(recLev15b->records[0],TOTVALSS,ngood+MISSVALS[1]);
06222 statusA[1]= drms_setkey_int(recLev15b->records[0],DATAVALSS,ngood);
06223 statusA[2]= drms_setkey_int(recLev15b->records[0],MISSVALSS,MISSVALS[1]);
06224 statusA[3]= drms_setkey_float(recLev15b->records[0],DATAMINS,(float)minimum);
06225 statusA[4]= drms_setkey_float(recLev15b->records[0],DATAMAXS,(float)maximum);
06226 statusA[5]= drms_setkey_float(recLev15b->records[0],DATAMEDNS,(float)median);
06227 statusA[6]= drms_setkey_float(recLev15b->records[0],DATAMEANS,(float)mean);
06228 statusA[7]= drms_setkey_float(recLev15b->records[0],DATARMSS,(float)sigma);
06229 statusA[8]= drms_setkey_float(recLev15b->records[0],DATASKEWS,(float)skewness);
06230 statusA[9]= drms_setkey_float(recLev15b->records[0],DATAKURTS,(float)kurtosis);
06231 statusA[10]=drms_setkey_int(recLev15b->records[0],CALFSNS,FSNLOOKUP);
06232 statusA[11]=drms_setkey_string(recLev15b->records[0],LUTQUERYS,HMILookup);
06233 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06234 statusA[12]= drms_setkey_string(recLev15b->records[0],DATES,DATEOBS);
06235 statusA[13]= drms_setkey_int(recLev15b->records[0],QUALITYS,QUALITY);
06236 statusA[14]= drms_setkey_int(recLev15b->records[0],SATVALSS,SATVALS);
06237 statusA[15]= drms_setkey_string(recLev15b->records[0],SOURCES,source);
06238 statusA[16]= drms_setkey_int(recLev15b->records[0],QUALLEV1S,QUALITYLEV1);
06239 statusA[17]= drms_setkey_string(recLev15b->records[0],COMMENTS,COMMENT);
06240 statusA[18]=0;
06241 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15b->records[0],CALVER64S,CALVER64);
06242
06243 TotalStatus=0;
06244 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06245 if(TotalStatus != 0)
06246 {
06247 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the magnetogram at target time %s\n",timeBegin2);
06248 }
06249
06250
06251
06252 drms_copykeys(recLev15c->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06253
06254 status=fstats(axisout[0]*axisout[1],arrLev15[2]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06255 if(status != 0)
06256 {
06257 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06258 }
06259
06260 image=arrLev15[2]->data;
06261 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))
06262 {
06263 MISSVALS[2]+=1;
06264 ngood -= 1;
06265 }
06266
06267
06268 statusA[0]= drms_setkey_int(recLev15c->records[0],TOTVALSS,ngood+MISSVALS[2]);
06269 statusA[1]= drms_setkey_int(recLev15c->records[0],DATAVALSS,ngood);
06270 statusA[2]= drms_setkey_int(recLev15c->records[0],MISSVALSS,MISSVALS[2]);
06271 statusA[3]= drms_setkey_float(recLev15c->records[0],DATAMINS,(float)minimum);
06272 statusA[4]= drms_setkey_float(recLev15c->records[0],DATAMAXS,(float)maximum);
06273 statusA[5]= drms_setkey_float(recLev15c->records[0],DATAMEDNS,(float)median);
06274 statusA[6]= drms_setkey_float(recLev15c->records[0],DATAMEANS,(float)mean);
06275 statusA[7]= drms_setkey_float(recLev15c->records[0],DATARMSS,(float)sigma);
06276 statusA[8]= drms_setkey_float(recLev15c->records[0],DATASKEWS,(float)skewness);
06277 statusA[9]= drms_setkey_float(recLev15c->records[0],DATAKURTS,(float)kurtosis);
06278 statusA[10]=drms_setkey_int(recLev15c->records[0],CALFSNS,FSNLOOKUP);
06279 statusA[11]=drms_setkey_string(recLev15c->records[0],LUTQUERYS,HMILookup);
06280 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06281 statusA[12]= drms_setkey_string(recLev15c->records[0],DATES,DATEOBS);
06282 statusA[13]= drms_setkey_int(recLev15c->records[0],QUALITYS,QUALITY);
06283 statusA[14]= drms_setkey_int(recLev15c->records[0],SATVALSS,SATVALS);
06284 statusA[15]= drms_setkey_string(recLev15c->records[0],SOURCES,source);
06285 statusA[16]= drms_setkey_int(recLev15c->records[0],QUALLEV1S,QUALITYLEV1);
06286 statusA[17]= drms_setkey_string(recLev15c->records[0],COMMENTS,COMMENT);
06287 statusA[18]=0;
06288 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15c->records[0],CALVER64S,CALVER64);
06289
06290 TotalStatus=0;
06291 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06292 if(TotalStatus != 0)
06293 {
06294 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the linedepth at target time %s\n",timeBegin2);
06295 }
06296
06297
06298
06299
06300 drms_copykeys(recLev15d->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06301
06302 status=fstats(axisout[0]*axisout[1],arrLev15[3]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06303 if(status != 0)
06304 {
06305 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06306 }
06307
06308
06309 image=arrLev15[3]->data;
06310 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))
06311 {
06312 MISSVALS[3]+=1;
06313 ngood -= 1;
06314 }
06315
06316
06317 statusA[0]= drms_setkey_int(recLev15d->records[0],TOTVALSS,ngood+MISSVALS[3]);
06318 statusA[1]= drms_setkey_int(recLev15d->records[0],DATAVALSS,ngood);
06319 statusA[2]= drms_setkey_int(recLev15d->records[0],MISSVALSS,MISSVALS[3]);
06320 statusA[3]= drms_setkey_float(recLev15d->records[0],DATAMINS,(float)minimum);
06321 statusA[4]= drms_setkey_float(recLev15d->records[0],DATAMAXS,(float)maximum);
06322 statusA[5]= drms_setkey_float(recLev15d->records[0],DATAMEDNS,(float)median);
06323 statusA[6]= drms_setkey_float(recLev15d->records[0],DATAMEANS,(float)mean);
06324 statusA[7]= drms_setkey_float(recLev15d->records[0],DATARMSS,(float)sigma);
06325 statusA[8]= drms_setkey_float(recLev15d->records[0],DATASKEWS,(float)skewness);
06326 statusA[9]= drms_setkey_float(recLev15d->records[0],DATAKURTS,(float)kurtosis);
06327 statusA[10]=drms_setkey_int(recLev15d->records[0],CALFSNS,FSNLOOKUP);
06328 statusA[11]=drms_setkey_string(recLev15d->records[0],LUTQUERYS,HMILookup);
06329 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06330 statusA[12]= drms_setkey_string(recLev15d->records[0],DATES,DATEOBS);
06331 statusA[13]= drms_setkey_int(recLev15d->records[0],QUALITYS,QUALITY);
06332 statusA[14]= drms_setkey_int(recLev15d->records[0],SATVALSS,SATVALS);
06333 statusA[15]= drms_setkey_string(recLev15d->records[0],SOURCES,source);
06334 statusA[16]= drms_setkey_int(recLev15d->records[0],QUALLEV1S,QUALITYLEV1);
06335 statusA[17]= drms_setkey_string(recLev15d->records[0],COMMENTS,COMMENT);
06336 statusA[18]=0;
06337 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15d->records[0],CALVER64S,CALVER64);
06338
06339 TotalStatus=0;
06340 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06341 if(TotalStatus != 0)
06342 {
06343 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the linewidth at target time %s\n",timeBegin2);
06344 }
06345
06346
06347
06348 drms_copykeys(recLev15e->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06349
06350 status=fstats(axisout[0]*axisout[1],arrLev15[4]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06351 if(status != 0)
06352 {
06353 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06354 }
06355
06356 image=arrLev15[4]->data;
06357 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))
06358 {
06359 MISSVALS[4]+=1;
06360 ngood -= 1;
06361 }
06362
06363
06364 statusA[0]= drms_setkey_int(recLev15e->records[0],TOTVALSS,ngood+MISSVALS[4]);
06365 statusA[1]= drms_setkey_int(recLev15e->records[0],DATAVALSS,ngood);
06366 statusA[2]= drms_setkey_int(recLev15e->records[0],MISSVALSS,MISSVALS[4]);
06367 statusA[3]= drms_setkey_float(recLev15e->records[0],DATAMINS,(float)minimum);
06368 statusA[4]= drms_setkey_float(recLev15e->records[0],DATAMAXS,(float)maximum);
06369 statusA[5]= drms_setkey_float(recLev15e->records[0],DATAMEDNS,(float)median);
06370 statusA[6]= drms_setkey_float(recLev15e->records[0],DATAMEANS,(float)mean);
06371 statusA[7]= drms_setkey_float(recLev15e->records[0],DATARMSS,(float)sigma);
06372 statusA[8]= drms_setkey_float(recLev15e->records[0],DATASKEWS,(float)skewness);
06373 statusA[9]= drms_setkey_float(recLev15e->records[0],DATAKURTS,(float)kurtosis);
06374 statusA[10]=drms_setkey_int(recLev15e->records[0],CALFSNS,FSNLOOKUP);
06375 statusA[11]=drms_setkey_string(recLev15e->records[0],LUTQUERYS,HMILookup);
06376 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06377 statusA[12]= drms_setkey_string(recLev15e->records[0],DATES,DATEOBS);
06378 statusA[13]= drms_setkey_int(recLev15e->records[0],QUALITYS,QUALITY);
06379 statusA[14]= drms_setkey_int(recLev15e->records[0],SATVALSS,SATVALS);
06380 statusA[15]= drms_setkey_string(recLev15e->records[0],SOURCES,source);
06381 statusA[16]= drms_setkey_int(recLev15e->records[0],QUALLEV1S,QUALITYLEV1);
06382 statusA[17]= drms_setkey_string(recLev15e->records[0],COMMENTS,COMMENT);
06383 statusA[18]=0;
06384 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15e->records[0],CALVER64S,CALVER64);
06385
06386 TotalStatus=0;
06387 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06388 if(TotalStatus != 0)
06389 {
06390 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);
06391 }
06392
06393
06394 image0=(float *)arrLev15[0]->data;
06395 image1=(float *)arrLev15[1]->data;
06396 image2=(float *)arrLev15[2]->data;
06397 image3=(float *)arrLev15[3]->data;
06398 image4=(float *)arrLev15[4]->data;
06399
06400 for(i=0;i<axisout[0]*axisout[1];++i)
06401 {
06402 row =i / axisout[0];
06403 column=i % axisout[0];
06404 distance = sqrt(((float)row-Y0AVG)*((float)row-Y0AVG)+((float)column-X0AVG)*((float)column-X0AVG));
06405 if(distance > 0.99*RSUNint)
06406 {
06407 image0[i]=NAN;
06408 image1[i]=NAN;
06409 image2[i]=NAN;
06410 image3[i]=NAN;
06411 image4[i]=NAN;
06412 }
06413 }
06414
06415
06416
06417
06418 status=fstats(axisout[0]*axisout[1],arrLev15[0]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06419 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06420 statusA[0]= drms_setkey_float(recLev15a->records[0],DATAMINS2,(float)minimum);
06421 statusA[1]= drms_setkey_float(recLev15a->records[0],DATAMAXS2,(float)maximum);
06422 statusA[2]= drms_setkey_float(recLev15a->records[0],DATAMEDNS2,(float)median);
06423 statusA[3]= drms_setkey_float(recLev15a->records[0],DATAMEANS2,(float)mean);
06424 statusA[4]= drms_setkey_float(recLev15a->records[0],DATARMSS2,(float)sigma);
06425 statusA[5]= drms_setkey_float(recLev15a->records[0],DATASKEWS2,(float)skewness);
06426 statusA[6]= drms_setkey_float(recLev15a->records[0],DATAKURTS2,(float)kurtosis);
06427 status=fstats(axisout[0]*axisout[1],arrLev15[1]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06428 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06429 statusA[7]= drms_setkey_float(recLev15b->records[0],DATAMINS2,(float)minimum);
06430 statusA[8]= drms_setkey_float(recLev15b->records[0],DATAMAXS2,(float)maximum);
06431 statusA[9]= drms_setkey_float(recLev15b->records[0],DATAMEDNS2,(float)median);
06432 statusA[10]= drms_setkey_float(recLev15b->records[0],DATAMEANS2,(float)mean);
06433 statusA[11]= drms_setkey_float(recLev15b->records[0],DATARMSS2,(float)sigma);
06434 statusA[12]= drms_setkey_float(recLev15b->records[0],DATASKEWS2,(float)skewness);
06435 statusA[13]= drms_setkey_float(recLev15b->records[0],DATAKURTS2,(float)kurtosis);
06436 status=fstats(axisout[0]*axisout[1],arrLev15[2]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06437 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06438 statusA[14]= drms_setkey_float(recLev15c->records[0],DATAMINS2,(float)minimum);
06439 statusA[15]= drms_setkey_float(recLev15c->records[0],DATAMAXS2,(float)maximum);
06440 statusA[16]= drms_setkey_float(recLev15c->records[0],DATAMEDNS2,(float)median);
06441 statusA[17]= drms_setkey_float(recLev15c->records[0],DATAMEANS2,(float)mean);
06442 statusA[18]= drms_setkey_float(recLev15c->records[0],DATARMSS2,(float)sigma);
06443 statusA[19]= drms_setkey_float(recLev15c->records[0],DATASKEWS2,(float)skewness);
06444 statusA[20]= drms_setkey_float(recLev15c->records[0],DATAKURTS2,(float)kurtosis);
06445 status=fstats(axisout[0]*axisout[1],arrLev15[3]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06446 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06447 statusA[21]= drms_setkey_float(recLev15d->records[0],DATAMINS2,(float)minimum);
06448 statusA[22]= drms_setkey_float(recLev15d->records[0],DATAMAXS2,(float)maximum);
06449 statusA[23]= drms_setkey_float(recLev15d->records[0],DATAMEDNS2,(float)median);
06450 statusA[24]= drms_setkey_float(recLev15d->records[0],DATAMEANS2,(float)mean);
06451 statusA[25]= drms_setkey_float(recLev15d->records[0],DATARMSS2,(float)sigma);
06452 statusA[26]= drms_setkey_float(recLev15d->records[0],DATASKEWS2,(float)skewness);
06453 statusA[27]= drms_setkey_float(recLev15d->records[0],DATAKURTS2,(float)kurtosis);
06454 status=fstats(axisout[0]*axisout[1],arrLev15[4]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06455 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06456 statusA[28]= drms_setkey_float(recLev15e->records[0],DATAMINS2,(float)minimum);
06457 statusA[29]= drms_setkey_float(recLev15e->records[0],DATAMAXS2,(float)maximum);
06458 statusA[30]= drms_setkey_float(recLev15e->records[0],DATAMEDNS2,(float)median);
06459 statusA[31]= drms_setkey_float(recLev15e->records[0],DATAMEANS2,(float)mean);
06460 statusA[32]= drms_setkey_float(recLev15e->records[0],DATARMSS2,(float)sigma);
06461 statusA[33]= drms_setkey_float(recLev15e->records[0],DATASKEWS2,(float)skewness);
06462 statusA[34]= drms_setkey_float(recLev15e->records[0],DATAKURTS2,(float)kurtosis);
06463
06464 statusA[35]= drms_setkey_string(recLev15a->records[0],HISTORYS,HISTORY);
06465 statusA[36]= drms_setkey_string(recLev15b->records[0],HISTORYS,HISTORY);
06466 statusA[37]= drms_setkey_string(recLev15c->records[0],HISTORYS,HISTORY);
06467 statusA[38]= drms_setkey_string(recLev15d->records[0],HISTORYS,HISTORY);
06468 statusA[39]= drms_setkey_string(recLev15e->records[0],HISTORYS,HISTORY);
06469
06470 TotalStatus=0;
06471 for(i=0;i<35;++i) TotalStatus+=statusA[i];
06472 if(TotalStatus != 0)
06473 {
06474 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the Dopplergram at target time %s\n",timeBegin2);
06475 }
06476 t1=dsecnd();
06477 printf("TIME ELAPSED TO SET LEV 1.5 KEYWORDS AND CALCULATE STATISTICS KEYWORDS: %f\n",t1-t0);
06478
06479 }
06480
06481
06482
06483 NextTargetTime:
06484
06485
06486
06487
06488
06489
06490
06491
06492
06493
06494 printf("FREEING RECORD\n");
06495
06496 if(Mask != NULL)
06497 {
06498 free(Mask);
06499 Mask = NULL;
06500 }
06501
06502 if(recLev1d != NULL)
06503 {
06504 printf("recLev1d != NULL\n");
06505 if(recLev1d->n > 0)
06506 {
06507
06508 if (Lev1dWanted) status=drms_close_records(recLev1d,DRMS_INSERT_RECORD);
06509 else status=drms_close_records(recLev1d,DRMS_FREE_RECORD);
06510 recLev1d=NULL;
06511 if(arrLev1d != NULL)
06512 {
06513 for(i=0;i<nRecs1d;++i) if(arrLev1d[i] != NULL)
06514 {
06515 drms_free_array(arrLev1d[i]);
06516 arrLev1d[i]=NULL;
06517 }
06518 free(arrLev1d);
06519 }
06520 arrLev1d=NULL;
06521 Segments1d=0;
06522 }
06523 }
06524
06525
06526 if(recLev1p != NULL)
06527 {
06528 printf("recLev1p != NULL\n");
06529 if(recLev1p->n > 0)
06530 {
06531 if (Lev1pWanted) status=drms_close_records(recLev1p,DRMS_INSERT_RECORD);
06532 else status=drms_close_records(recLev1p,DRMS_FREE_RECORD);
06533 recLev1p=NULL;
06534 for(i=0;i<nSegs1p;++i) if(arrLev1p[i] != NULL)
06535 {
06536 drms_free_array(arrLev1p[i]);
06537 arrLev1p[i]=NULL;
06538 }
06539 if(arrLev1p != NULL) free(arrLev1p);
06540 arrLev1p=NULL;
06541 if(ps1 != NULL) free(ps1);
06542 if(ps2 != NULL) free(ps2);
06543 if(ps3 != NULL) free(ps3);
06544 if(fid != NULL) free(fid);
06545 if(Wavelengths != NULL) free(Wavelengths);
06546 if(images != NULL) free(images);
06547 if(imagesout != NULL) free(imagesout);
06548 Wavelengths=NULL;
06549 images=NULL;
06550 imagesout=NULL;
06551 ps1=NULL;
06552 ps2=NULL;
06553 ps3=NULL;
06554 fid=NULL;
06555 Segments1p=0;
06556 }
06557 }
06558
06559
06560 if(Lev15Wanted)
06561 {
06562
06563 if(arrintable != NULL)
06564 {
06565 drms_free_array(arrintable);
06566 }
06567 arrintable=NULL;
06568 if(lookup != NULL) status=drms_close_records(lookup,DRMS_FREE_RECORD);
06569 lookup = NULL;
06570 if(recpoly != NULL) status=drms_close_records(recpoly,DRMS_FREE_RECORD);
06571 recpoly= NULL;
06572 if(recpoly2 != NULL) status=drms_close_records(recpoly2,DRMS_FREE_RECORD);
06573 recpoly2= NULL;
06574 if(arrayL0 != NULL)
06575 {
06576 drms_free_array(arrayL0);
06577 arrayL0=NULL;
06578 }
06579 if(arrayL1 != NULL)
06580 {
06581 drms_free_array(arrayL1);
06582 arrayL1=NULL;
06583 }
06584 if(arrayL2 != NULL)
06585 {
06586 drms_free_array(arrayL2);
06587 arrayL2=NULL;
06588 }
06589 if(count != NULL)
06590 {
06591 free(count);
06592 count=NULL;
06593 }
06594
06595 if(recLev15a != NULL)
06596 {
06597 printf("recLev15a != NULL\n");
06598 if(CreateEmptyRecord != 1)
06599 {
06600 printf("Inserting record for the observables\n");
06601 status=drms_close_records(recLev15a,DRMS_INSERT_RECORD);
06602 status=drms_close_records(recLev15b,DRMS_INSERT_RECORD);
06603 status=drms_close_records(recLev15c,DRMS_INSERT_RECORD);
06604 status=drms_close_records(recLev15d,DRMS_INSERT_RECORD);
06605 status=drms_close_records(recLev15e,DRMS_INSERT_RECORD);
06606 recLev15a=NULL;
06607 recLev15b=NULL;
06608 recLev15c=NULL;
06609 recLev15d=NULL;
06610 recLev15e=NULL;
06611 }
06612 else
06613 {
06614 printf("Warning: creating empty lev1.5 record\n");
06615
06616 if(CamId == LIGHT_SIDE) camera=1;
06617 if(CamId == LIGHT_FRONT) camera=2;
06618
06619 QUALITY= QUALITY | QUAL_NODATA;
06620 statusA[0] = drms_setkey_time(recLev15a->records[0],TRECS,TargetTime);
06621
06622 statusA[2] = drms_setkey_int(recLev15a->records[0],CAMERAS,camera);
06623 statusA[3] = drms_setkey_int(recLev15a->records[0],QUALITYS,QUALITY);
06624 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06625 statusA[4]= drms_setkey_string(recLev15a->records[0],DATES,DATEOBS);
06626
06627 statusA[0] = drms_setkey_time(recLev15b->records[0],TRECS,TargetTime);
06628
06629 statusA[2] = drms_setkey_int(recLev15b->records[0],CAMERAS,camera);
06630 statusA[3] = drms_setkey_int(recLev15b->records[0],QUALITYS,QUALITY);
06631 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06632 statusA[4]= drms_setkey_string(recLev15b->records[0],DATES,DATEOBS);
06633
06634 statusA[0] = drms_setkey_time(recLev15c->records[0],TRECS,TargetTime);
06635
06636 statusA[2] = drms_setkey_int(recLev15c->records[0],CAMERAS,camera);
06637 statusA[3] = drms_setkey_int(recLev15c->records[0],QUALITYS,QUALITY);
06638 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06639 statusA[4]= drms_setkey_string(recLev15c->records[0],DATES,DATEOBS);
06640
06641 statusA[0] = drms_setkey_time(recLev15d->records[0],TRECS,TargetTime);
06642
06643 statusA[2] = drms_setkey_int(recLev15d->records[0],CAMERAS,camera);
06644 statusA[3] = drms_setkey_int(recLev15d->records[0],QUALITYS,QUALITY);
06645 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06646 statusA[4]= drms_setkey_string(recLev15d->records[0],DATES,DATEOBS);
06647
06648 statusA[0] = drms_setkey_time(recLev15e->records[0],TRECS,TargetTime);
06649
06650 statusA[2] = drms_setkey_int(recLev15e->records[0],CAMERAS,camera);
06651 statusA[3] = drms_setkey_int(recLev15e->records[0],QUALITYS,QUALITY);
06652 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06653 statusA[4]= drms_setkey_string(recLev15e->records[0],DATES,DATEOBS);
06654
06655
06656 status=drms_close_records(recLev15a,DRMS_INSERT_RECORD);
06657 status=drms_close_records(recLev15b,DRMS_INSERT_RECORD);
06658 status=drms_close_records(recLev15c,DRMS_INSERT_RECORD);
06659 status=drms_close_records(recLev15d,DRMS_INSERT_RECORD);
06660 status=drms_close_records(recLev15e,DRMS_INSERT_RECORD);
06661 recLev15a=NULL;
06662 recLev15b=NULL;
06663 recLev15c=NULL;
06664 recLev15d=NULL;
06665 recLev15e=NULL;
06666 }
06667 for (i=0;i<nRecs15;++i) if(arrLev15[i] != NULL)
06668 {
06669 drms_free_array(arrLev15[i]);
06670 arrLev15[i]=NULL;
06671 }
06672 if(arrLev15 != NULL) free(arrLev15);
06673 arrLev15=NULL;
06674 }
06675 else
06676 {
06677
06678 recLev15a = drms_create_records(drms_env,1,HMISeriesLev15a,DRMS_PERMANENT,&statusA[0]);
06679 recLev15b = drms_create_records(drms_env,1,HMISeriesLev15b,DRMS_PERMANENT,&statusA[1]);
06680 recLev15c = drms_create_records(drms_env,1,HMISeriesLev15c,DRMS_PERMANENT,&statusA[2]);
06681 recLev15d = drms_create_records(drms_env,1,HMISeriesLev15d,DRMS_PERMANENT,&statusA[3]);
06682 recLev15e = drms_create_records(drms_env,1,HMISeriesLev15e,DRMS_PERMANENT,&statusA[4]);
06683
06684 if(CamId == LIGHT_SIDE) camera=1;
06685 if(CamId == LIGHT_FRONT) camera=2;
06686
06687 printf("Warning: creating empty lev1.5 record\n");
06688 QUALITY= QUALITY | QUAL_NODATA;
06689 statusA[0] = drms_setkey_time(recLev15a->records[0],TRECS,TargetTime);
06690
06691 statusA[2] = drms_setkey_int(recLev15a->records[0],CAMERAS,camera);
06692 statusA[3] = drms_setkey_int(recLev15a->records[0],QUALITYS,QUALITY);
06693 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06694 statusA[4]= drms_setkey_string(recLev15a->records[0],DATES,DATEOBS);
06695
06696 statusA[0] = drms_setkey_time(recLev15b->records[0],TRECS,TargetTime);
06697
06698 statusA[2] = drms_setkey_int(recLev15b->records[0],CAMERAS,camera);
06699 statusA[3] = drms_setkey_int(recLev15b->records[0],QUALITYS,QUALITY);
06700 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06701 statusA[4]= drms_setkey_string(recLev15b->records[0],DATES,DATEOBS);
06702
06703 statusA[0] = drms_setkey_time(recLev15c->records[0],TRECS,TargetTime);
06704
06705 statusA[2] = drms_setkey_int(recLev15c->records[0],CAMERAS,camera);
06706 statusA[3] = drms_setkey_int(recLev15c->records[0],QUALITYS,QUALITY);
06707 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06708 statusA[4]= drms_setkey_string(recLev15c->records[0],DATES,DATEOBS);
06709
06710 statusA[0] = drms_setkey_time(recLev15d->records[0],TRECS,TargetTime);
06711
06712 statusA[2] = drms_setkey_int(recLev15d->records[0],CAMERAS,camera);
06713 statusA[3] = drms_setkey_int(recLev15d->records[0],QUALITYS,QUALITY);
06714 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06715 statusA[4]= drms_setkey_string(recLev15d->records[0],DATES,DATEOBS);
06716
06717 statusA[0] = drms_setkey_time(recLev15e->records[0],TRECS,TargetTime);
06718
06719 statusA[2] = drms_setkey_int(recLev15e->records[0],CAMERAS,camera);
06720 statusA[3] = drms_setkey_int(recLev15e->records[0],QUALITYS,QUALITY);
06721 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06722 statusA[4]= drms_setkey_string(recLev15e->records[0],DATES,DATEOBS);
06723
06724 status=drms_close_records(recLev15a,DRMS_INSERT_RECORD);
06725 status=drms_close_records(recLev15b,DRMS_INSERT_RECORD);
06726 status=drms_close_records(recLev15c,DRMS_INSERT_RECORD);
06727 status=drms_close_records(recLev15d,DRMS_INSERT_RECORD);
06728 status=drms_close_records(recLev15e,DRMS_INSERT_RECORD);
06729 recLev15a=NULL;
06730 recLev15b=NULL;
06731 recLev15c=NULL;
06732 recLev15d=NULL;
06733 recLev15e=NULL;
06734 }
06735
06736 QUALITY=0;
06737 CreateEmptyRecord=0;
06738 }
06739
06740 PreviousTargetTime=TargetTime;
06741 TargetTime+=DataCadence;
06742 initialrun=0;
06743 }
06744
06745
06746 if (TestLevIn[0]==1)
06747 {
06748 printf("FREEING GENERAL ARRAYS\n");
06749 if(recLev1->n > 0)
06750 {
06751 status=drms_close_records(recLev1,DRMS_FREE_RECORD);
06752 recLev1=NULL;
06753 free(internTOBS);
06754 free(HWL1POS);
06755 free(HWL2POS);
06756 free(HWL3POS);
06757 free(HWL4POS);
06758 free(HPL1POS);
06759 free(HPL2POS);
06760 free(HPL3POS);
06761 free(HWLTID);
06762 free(HPLTID);
06763 free(FID);
06764 free(HFLID);
06765 free(HCAMID);
06766 free(RSUN);
06767 free(CROTA2);
06768 free(CRLTOBS);
06769 free(DSUNOBS);
06770 free(X0);
06771 free(Y0);
06772 free(SegmentRead);
06773 free(KeywordMissing);
06774 free(Segments);
06775
06776 if(inRotationalFlat == 1)
06777 {
06778 drms_free_array(flatfield);
06779 drms_free_array(flatfieldrot);
06780 status=drms_close_records(recflatrot,DRMS_FREE_RECORD);
06781 }
06782 free(Ierror);
06783 free(IndexFiltergram);
06784 free(FSN);
06785 free(CFINDEX);
06786 free(HIMGCFID);
06787 for(i=0;i<nRecs1;++i) free(IMGTYPE[i]);
06788 free(IMGTYPE);
06789 free(CDELT1);
06790 for(i=0;i<nRecs1;++i) free(HWLTNSET[i]);
06791 free(HWLTNSET);
06792 free(NBADPERM);
06793 free(QUALITYin);
06794 free(QUALITYlev1);
06795 free(EXPTIME);
06796 free(CALVER32);
06797 free(CAMERA);
06798 }
06799 }
06800
06801 if(TestLevIn[0]==1)
06802 {
06803 free_interpol(&const_param);
06804 }
06805
06806 if(Lev1pWanted || (Lev15Wanted && TestLevIn[2]==0))
06807 {
06808 status = free_polcal(&pars);
06809 }
06810
06811 free(CODEVERSION);
06812 free(CODEVERSION1);
06813 free(CODEVERSION2);
06814 free(CODEVERSION3);
06815 free(DISTCOEFFILEF);
06816 free(DISTCOEFFILES);
06817 free(ROTCOEFFILE);
06818 free(DISTCOEFPATH);
06819 free(ROTCOEFPATH);
06820
06821
06822 status=0;
06823 t1=dsecnd();
06824 printf("TOTAL TIME ELAPSED IN OBSERVABLES CODE: %f\n",t1-tstart);
06825 return status;
06826
06827 }
06828
06829