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_dcon.c,v 1.5 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 = cmdparams_get_str(&cmdparams, kRecSetIn, NULL);
01134 char *inRecQuery2 = cmdparams_get_str(&cmdparams, kRecSetIn2, NULL);
01135 char *inLev = cmdparams_get_str(&cmdparams, kTypeSetIn, NULL);
01136 char *outLev = 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 = 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 = 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_dcon_nrt" );
01832 strcpy(HMISeriesLev15b,"hmi.M_45s_dcon_nrt" );
01833 strcpy(HMISeriesLev15c,"hmi.Ld_45s_dcon_nrt" );
01834 strcpy(HMISeriesLev15d,"hmi.Lw_45s_dcon_nrt" );
01835 strcpy(HMISeriesLev15e,"hmi.Ic_45s_dcon_nrt" );
01836 }
01837 if(DataCadence == 22.5)
01838 {
01839 strcpy(HMISeriesLev15a,"hmi_test.V_22s_dcon_nrt" );
01840 strcpy(HMISeriesLev15b,"hmi_test.M_22s_dcon_nrt" );
01841 strcpy(HMISeriesLev15c,"hmi_test.Ld_22s_dcon_nrt" );
01842 strcpy(HMISeriesLev15d,"hmi_test.Lw_22s_dcon_nrt" );
01843 strcpy(HMISeriesLev15e,"hmi_test.Ic_22s_dcon_nrt" );
01844 }
01845 if(DataCadence == 60.0)
01846 {
01847 strcpy(HMISeriesLev15a,"hmi.V_60s_dcon_nrt");
01848 strcpy(HMISeriesLev15b,"hmi.M_60s_dcon_nrt");
01849 strcpy(HMISeriesLev15c,"hmi.Ld_60s_dcon_nrt");
01850 strcpy(HMISeriesLev15d,"hmi.Lw_60s_dcon_nrt");
01851 strcpy(HMISeriesLev15e,"hmi.Ic_60s_dcon_nrt");
01852 }
01853 if(DataCadence == 75.0)
01854 {
01855 strcpy(HMISeriesLev15a,"hmi_test.V_75s_dcon_nrt" );
01856 strcpy(HMISeriesLev15b,"hmi_test.M_75s_dcon_nrt" );
01857 strcpy(HMISeriesLev15c,"hmi_test.Ld_75s_dcon_nrt" );
01858 strcpy(HMISeriesLev15d,"hmi_test.Lw_75s_dcon_nrt" );
01859 strcpy(HMISeriesLev15e,"hmi_test.Ic_75s_dcon_nrt" );
01860 }
01861 if(DataCadence == 720.0 && unusual == 0)
01862 {
01863 strcpy(HMISeriesLev15a,"hmi.V_720s_dcon_nrt");
01864 strcpy(HMISeriesLev15b,"hmi.M_720s_dcon_nrt");
01865 strcpy(HMISeriesLev15c,"hmi.Ld_720s_dcon_nrt");
01866 strcpy(HMISeriesLev15d,"hmi.Lw_720s_dcon_nrt");
01867 strcpy(HMISeriesLev15e,"hmi.Ic_720s_dcon_nrt");
01868 }
01869 if(DataCadence == 720.0 && unusual == 1)
01870 {
01871 strcpy(HMISeriesLev15a,"hmi.V2_720s_dcon_nrt");
01872 strcpy(HMISeriesLev15b,"hmi.M2_720s_dcon_nrt");
01873 strcpy(HMISeriesLev15c,"hmi.Ld2_720s_dcon_nrt");
01874 strcpy(HMISeriesLev15d,"hmi.Lw2_720s_dcon_nrt");
01875 strcpy(HMISeriesLev15e,"hmi.Ic2_720s_dcon_nrt");
01876 }
01877 }
01878 else
01879 {
01880 if(DataCadence == 45.0)
01881 {
01882 strcpy(HMISeriesLev15a,"hmi_test.V_45s_dcon");
01883 strcpy(HMISeriesLev15b,"hmi_test.M_45s_dcon" );
01884 strcpy(HMISeriesLev15c,"hmi_test.Ld_45s_dcon" );
01885 strcpy(HMISeriesLev15d,"hmi_test.Lw_45s_dcon" );
01886 strcpy(HMISeriesLev15e,"hmi_test.Ic_45s_dcon" );
01887 }
01888 if(DataCadence == 22.5)
01889 {
01890 strcpy(HMISeriesLev15a,"hmi_test.V_22s" );
01891 strcpy(HMISeriesLev15b,"hmi_test.M_22s" );
01892 strcpy(HMISeriesLev15c,"hmi_test.Ld_22s" );
01893 strcpy(HMISeriesLev15d,"hmi_test.Lw_22s" );
01894 strcpy(HMISeriesLev15e,"hmi_test.Ic_22s" );
01895 }
01896 if(DataCadence == 60.0)
01897 {
01898 strcpy(HMISeriesLev15a,"hmi_test.V_60s");
01899 strcpy(HMISeriesLev15b,"hmi_test.M_60s");
01900 strcpy(HMISeriesLev15c,"hmi_test.Ld_60s");
01901 strcpy(HMISeriesLev15d,"hmi_test.Lw_60s");
01902 strcpy(HMISeriesLev15e,"hmi_test.Ic_60s");
01903 }
01904 if(DataCadence == 75.0)
01905 {
01906 strcpy(HMISeriesLev15a,"hmi_test.V_75s" );
01907 strcpy(HMISeriesLev15b,"hmi_test.M_75s" );
01908 strcpy(HMISeriesLev15c,"hmi_test.Ld_75s" );
01909 strcpy(HMISeriesLev15d,"hmi_test.Lw_75s" );
01910 strcpy(HMISeriesLev15e,"hmi_test.Ic_75s" );
01911 }
01912 if(DataCadence == 135.0)
01913 {
01914 strcpy(HMISeriesLev15a,"hmi.V_135s");
01915 strcpy(HMISeriesLev15b,"hmi.M_135s");
01916 strcpy(HMISeriesLev15c,"hmi.Ld_135s");
01917 strcpy(HMISeriesLev15d,"hmi.Lw_135s");
01918 strcpy(HMISeriesLev15e,"hmi.Ic_135s");
01919 }
01920 if(DataCadence == 720.0 && unusual == 0)
01921 {
01922 strcpy(HMISeriesLev15a,"hmi.V_720s" );
01923 strcpy(HMISeriesLev15b,"hmi.M_720s" );
01924 strcpy(HMISeriesLev15c,"hmi.Ld_720s" );
01925 strcpy(HMISeriesLev15d,"hmi.Lw_720s" );
01926 strcpy(HMISeriesLev15e,"hmi.Ic_720s" );
01927 }
01928 if(DataCadence == 720.0 && unusual == 1)
01929 {
01930 strcpy(HMISeriesLev15a,"hmi_test.V2_720s" );
01931 strcpy(HMISeriesLev15b,"hmi_test.M2_720s" );
01932 strcpy(HMISeriesLev15c,"hmi_test.Ld2_720s" );
01933 strcpy(HMISeriesLev15d,"hmi_test.Lw2_720s" );
01934 strcpy(HMISeriesLev15e,"hmi_test.Ic2_720s" );
01935 }
01936 }
01937
01938
01939
01940
01941
01942 if(QuickLook == 1)
01943 {
01944 if(DataCadence == 22.5) strcpy(HMISeriesLev1pb,"su_couvidat.HMISeriesLev1pb22Q");
01945 if(DataCadence == 45.0) strcpy(HMISeriesLev1pb,"hmi.HMISeriesLev1pb45Q");
01946 if(DataCadence == 60.0) strcpy(HMISeriesLev1pb,"su_couvidat.HMISeriesLev1pb60Q");
01947 if(DataCadence == 75.0) strcpy(HMISeriesLev1pb,"su_couvidat.HMISeriesLev1pb75Q");
01948 }
01949 else
01950 {
01951 if(DataCadence == 22.5) strcpy(HMISeriesLev1pb,"hmi_test.HMISeriesLev1pb22");
01952 if(DataCadence == 45.0) strcpy(HMISeriesLev1pb,"hmi.HMISeriesLev1pb45");
01953 if(DataCadence == 60.0) strcpy(HMISeriesLev1pb,"hmi_test.HMISeriesLev1pb60");
01954 if(DataCadence == 75.0) strcpy(HMISeriesLev1pb,"hmi_test.HMISeriesLev1pb75");
01955 }
01956
01957
01958
01959
01960 if(QuickLook == 1)
01961 {
01962 if( DataCadence == 45.0) strcpy(HMISeriesLev1pa,"hmi.HMISeriesLev1pa45Q");
01963 if( DataCadence == 90.0) strcpy(HMISeriesLev1pa,"hmi.HMISeriesLev1pa90Q");
01964 if( DataCadence == 120.0) strcpy(HMISeriesLev1pa,"su_couvidat.HMISeriesLev1pa120Q");
01965 if( DataCadence == 135.0) strcpy(HMISeriesLev1pa,"hmi.HMISeriesLev1pa135Q");
01966 if( DataCadence == 150.0) strcpy(HMISeriesLev1pa,"su_couvidat.HMISeriesLev1pa150Q");
01967 if( DataCadence == 720.0 && unusual == 0) strcpy(HMISeriesLev1pa,"hmi.S_720s_dcon_nrt");
01968 if( DataCadence == 720.0 && unusual == 1) strcpy(HMISeriesLev1pa,"hmi.S2_720s_dcon_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 CROTA2int =(CROTA2[j]-CROTA2[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+CROTA2[i];
03080 OBSVRint =(OBSVR[j]-OBSVR[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+OBSVR[i];
03081 OBSVWint =(OBSVW[j]-OBSVW[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+OBSVW[i];
03082 OBSVNint =(OBSVN[j]-OBSVN[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+OBSVN[i];
03083 ctime1 =-CRLNOBS[i];
03084 ctime2 =360.0*(float)(CARROT[j]-CARROT[i])-CRLNOBS[j];
03085 CRLNOBSint=(ctime2-ctime1)/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+ctime1;
03086 if(CARROT[j] > CARROT[i])
03087 {
03088 if(CRLNOBSint > 0.0)
03089 {
03090 CRLNOBSint = 360.0 - CRLNOBSint;
03091 CARROTint = CARROT[j];
03092 }
03093 else
03094 {
03095 CRLNOBSint = -CRLNOBSint;
03096 CARROTint = CARROT[i];
03097 }
03098 }
03099 else
03100 {
03101 CRLNOBSint = -CRLNOBSint;
03102 CARROTint = CARROT[i];
03103 }
03104
03105 }
03106 else
03107 {
03108 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]);
03109
03110 DSUNOBSint=DSUNOBS[i];
03111 DSUNOBSint=DSUNOBSint/(double)AstroUnit;
03112 CRLTOBSint=CRLTOBS[i];
03113 CROTA2int =CROTA2[i];
03114 OBSVRint =OBSVR[i];
03115 OBSVWint =OBSVW[i];
03116 OBSVNint =OBSVN[i];
03117 CRLNOBSint=CRLNOBS[i];
03118 CARROTint =CARROT[i];
03119
03120 QUALITY = QUALITY | QUAL_LOWKEYWORDNUM;
03121 }
03122
03123
03124
03125
03126
03127
03128 Mask = (unsigned char *)malloc(Nelem*sizeof(unsigned char));
03129 if(Mask == NULL)
03130 {
03131 printf("Error: cannot allocate memory for Mask\n");
03132 return 1;
03133 }
03134
03135
03136
03137
03138
03139
03140
03141
03142
03143
03144
03145
03146
03147
03148 if(SegmentRead[temp] == 0 && image != NULL)
03149 {
03150
03151 if(inRotationalFlat == 1)
03152 {
03153 if(inLinearity == 1)
03154 {
03155 printf("applying rotational flat field and correcting for non-linearity of camera on record FSN=%d\n",FSN[temp]);
03156 for(i=0;i<axisin[0]*axisin[1];++i)
03157 {
03158
03159 image[i]=(image[i]*pztflat[i])/rotflat[i];
03160
03161 tempvalue = image[i]*EXPTIME[temp];
03162 if(HCAMID[temp] == LIGHT_FRONT) tempvalue = (nonlinf[0]+nonlinf[1]*tempvalue+nonlinf[2]*tempvalue*tempvalue+nonlinf[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
03163 else tempvalue = (nonlins[0]+nonlins[1]*tempvalue+nonlins[2]*tempvalue*tempvalue+nonlins[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
03164 image[i] = tempvalue/EXPTIME[temp];
03165 }
03166 }
03167 else
03168 {
03169 printf("applying rotational flat field on record FSN=%d\n",FSN[temp]);
03170 for(i=0;i<axisin[0]*axisin[1];++i)
03171 {
03172
03173 image[i]=(image[i]*pztflat[i])/rotflat[i];
03174 }
03175 }
03176 }
03177 else
03178 {
03179 if(inLinearity == 1)
03180 {
03181 printf("correcting for non-linearity of camera on record FSN=%d\n",FSN[temp]);
03182 for(i=0;i<axisin[0]*axisin[1];++i)
03183 {
03184
03185 tempvalue = image[i]*EXPTIME[temp];
03186 if(HCAMID[temp] == LIGHT_FRONT) tempvalue = (nonlinf[0]+nonlinf[1]*tempvalue+nonlinf[2]*tempvalue*tempvalue+nonlinf[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
03187 else tempvalue = (nonlins[0]+nonlins[1]*tempvalue+nonlins[2]*tempvalue*tempvalue+nonlins[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
03188 image[i] = tempvalue/EXPTIME[temp];
03189 }
03190 }
03191 }
03192
03193
03194
03195 segin = drms_segment_lookup(recLev1->records[temp],"bad_pixel_list");
03196 printf("READ BAD PIXEL LIST OF TARGET FILTERGRAM FSN = %d\n",FSN[temp]);
03197 BadPixels = NULL;
03198 BadPixels = drms_segment_read(segin,segin->info->type,&status);
03199 if(status != DRMS_SUCCESS || BadPixels == NULL)
03200 {
03201 printf("Error: cannot read the list of bad pixels of level 1 filtergram FSN = %d at target time %s \n",FSN[temp],timeBegin2);
03202 return 1;
03203
03204
03205
03206
03207 }
03208 else
03209 {
03210
03211
03212 strcpy(HMISeriesTemp,CosmicRaySeries);
03213 strcat(HMISeriesTemp,"[][");
03214 sprintf(FSNtemps,"%d",FSN[temp]);
03215 strcat(HMISeriesTemp,FSNtemps);
03216 strcat(HMISeriesTemp,"]");
03217 rectemp=NULL;
03218
03219 rectemp=drms_open_records(drms_env,HMISeriesTemp,&statusA[0]);
03220 if(statusA[0] == DRMS_SUCCESS && rectemp != NULL && rectemp->n != 0)
03221 {
03222 segin = drms_segment_lookupnum(rectemp->records[0],0);
03223 CosmicRays = NULL;
03224
03225 COSMICCOUNT=drms_getkey_int(rectemp->records[0],COUNTS,&status);
03226 if(status != DRMS_SUCCESS || COSMICCOUNT == -1)
03227 {
03228 QUALITY = QUALITY | QUAL_NOCOSMICRAY;
03229 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
03230 }
03231 else
03232 {
03233 CosmicRays = drms_segment_read(segin,segin->info->type,&status);
03234 if(status != DRMS_SUCCESS || CosmicRays == NULL)
03235 {
03236 printf("Error: the list of cosmic-ray hits could not be read for FSN %d\n",FSN[temp]);
03237 return 1;
03238
03239
03240 QUALITY = QUALITY | QUAL_NOCOSMICRAY;
03241 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
03242 CosmicRays = NULL;
03243
03244 }
03245 }
03246
03247 }
03248 else
03249 {
03250 printf("Unable to open the series %s for FSN %d\n",HMISeriesTemp,FSN[temp]);
03251
03252
03253
03254 QUALITY = QUALITY | QUAL_NOCOSMICRAY;
03255 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
03256 CosmicRays = NULL;
03257
03258 }
03259
03260 printf("CREATING MASK FOR GAP-FILLING OF TARGET FILTERGAM\n");
03261 status = MaskCreation(Mask,axisin[0],axisin[1],BadPixels,HIMGCFID[temp],image,CosmicRays,NBADPERM[temp]);
03262 if(status == 1) return 1;
03263
03264 if(BadPixels != NULL)
03265 {
03266 drms_free_array(BadPixels);
03267 BadPixels=NULL;
03268 }
03269 if(CosmicRays != NULL)
03270 {
03271 drms_free_array(CosmicRays);
03272 CosmicRays=NULL;
03273 }
03274 if(rectemp != NULL)
03275 {
03276 drms_close_records(rectemp,DRMS_FREE_RECORD);
03277 rectemp=NULL;
03278 }
03279
03280
03281 if(status != 0)
03282 {
03283 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);
03284 drms_free_array(Segments[temp]);
03285 Segments[temp]=NULL;
03286 SegmentRead[temp]=-1;
03287
03288 }
03289 else
03290 {
03291 Ierror[temp] = drms_array_create(typeEr,2,axisout,NULL,&status);
03292 if(status != DRMS_SUCCESS || Ierror[temp] == NULL)
03293 {
03294 printf("Error: unable to create an array for Ierror at target time %s\n",timeBegin2);
03295 drms_free_array(Segments[temp]);
03296 Segments[temp]=NULL;
03297 Ierror[temp]=NULL;
03298 SegmentRead[temp]=-1;
03299
03300 }
03301 else
03302 {
03303 ierror = Ierror[temp]->data;
03304 printf("GAP FILLING THE TARGET FILTERGRAM\n");
03305 t0=dsecnd();
03306 status = do_gapfill(image,Mask,&const_param,ierror,axisin[0],axisin[1]);
03307 t1=dsecnd();
03308 printf("TIME ELAPSED TO GAPFILL: %f\n",t1-t0);
03309 if(status != 0)
03310 {
03311 printf("Error: gapfilling code did not work on the level 1 filtergram FSN = %d at target time %s\n",FSN[temp],timeBegin2);
03312 QUALITY = QUALITY | QUAL_NOGAPFILL;
03313 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOGAPFILL;
03314 }
03315 SegmentRead[temp]=1;
03316 }
03317 }
03318 }
03319 }
03320
03321
03322
03323
03324
03325
03326 printf("GET INFORMATION ABOUT THE FRAMELIST\n");
03327 framelistSize = framelistInfo(TargetHFLID,TargetHPLTID,TargetHWLTID,WavelengthID,PHWPLPOS,WavelengthIndex,WavelengthLocation,&PolarizationType,CamId,&combine,&npol,MaxNumFiltergrams,&CadenceRead,CameraValues,FIDValues,dpath);
03328 if(framelistSize == 1) return 1;
03329
03330
03331
03332
03333
03334
03335
03336
03337
03338
03339
03340
03341
03342
03343
03344
03345
03346
03347
03348
03349
03350
03351
03352
03353
03354
03355
03356 printf("INFORMATION REGARDING THE FRAMELIST\n");
03357 printf("CamId= %d ; framelistSize= %d ; PolarizationType= %d ; combine cameras= %d ; npol= %d ; cadence=%f\n",CamId,framelistSize,PolarizationType,combine,npol,CadenceRead);
03358 printf("Framelist= ");
03359 for(i=0;i<framelistSize;++i) printf("I%d ",WavelengthIndex[i]);
03360 printf("\nLocation= ");
03361 for(i=0;i<framelistSize;++i) printf(" %d ",WavelengthLocation[i]);
03362 printf("\nPHWPLPOS \n");
03363 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]);
03364 printf("CAMERA ORDER\n");
03365 for(i=0;i<framelistSize;++i) printf(" %d ",CameraValues[i]);
03366 printf("\nFID ORDER\n");
03367 for(i=0;i<framelistSize;++i) printf(" %d ",FIDValues[i]);
03368 printf("\n");
03369
03370 if(framelistSize == 0)
03371 {
03372 printf("Error: cannot obtain information regarding the framelist for the level 1 filtergram FSN = %d at target time %s\n",FSN[temp],timeBegin2);
03373 QUALITY = QUALITY | QUAL_NOFRAMELISTINFO;
03374 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
03375 }
03376
03377 if(CadenceRead != DataCadence)
03378 {
03379 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);
03380 QUALITY = QUALITY | QUAL_WRONGCADENCE;
03381 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
03382 }
03383
03384
03385
03386
03387
03388 if (Lev1dWanted) recLev1d = drms_create_records(drms_env,framelistSize,HMISeriesLev1d,DRMS_PERMANENT,&status);
03389 else recLev1d = drms_create_records(drms_env,framelistSize,HMISeriesLev1d,DRMS_TRANSIENT,&status);
03390
03391 if(status != DRMS_SUCCESS || recLev1d == NULL || recLev1d->n < framelistSize)
03392 {
03393 printf("Error: cannot create records for the level 1d data %s at target time %s\n",HMISeriesLev1d,timeBegin2);
03394
03395
03396 return 1;
03397 }
03398 nRecs1d = framelistSize;
03399 Segments1d= 0;
03400 Segments1p= 0;
03401 TREC_EPOCH= drms_getkey_time(recLev1d->records[0],TRECEPOCHS,&status);
03402 if(status != DRMS_SUCCESS)
03403 {
03404 printf("Error: unable to read the %s keyword for level 1d data at target time %s\n",TRECEPOCHS,timeBegin2);
03405 return 1;
03406 }
03407 TREC_STEP= drms_getkey_time(recLev1d->records[0],TRECSTEPS,&status);
03408 if(status != DRMS_SUCCESS)
03409 {
03410 printf("Error: unable to read the keyword %s for level 1d data at target time %s\n",TRECSTEPS,timeBegin2);
03411 return 1;
03412 }
03413 if(TREC_STEP != DataCadence)
03414 {
03415 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);
03416 return 1;
03417 }
03418 if(TREC_EPOCH != TREC_EPOCH0)
03419 {
03420 printf("Error: TREC_EPOCH= %f is not equal to the expected TREC_EPOCH = %f, at target time %s\n",TREC_EPOCH,TREC_EPOCH0,timeBegin2);
03421 return 1;
03422 }
03423
03424 trec = TargetTime;
03425
03426
03427
03428
03429 temp=-1;
03430 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;
03431 if(temp == -1)
03432 {
03433 printf("Error: the target filtergram does not match any frame of the corresponding framelist\n");
03434 QUALITY = QUALITY | QUAL_WRONGTARGET;
03435 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
03436 }
03437 temp=WavelengthLocation[temp];
03438
03439 OrganizeFramelist =(int *)malloc(framelistSize*sizeof(int));
03440 if(OrganizeFramelist == NULL)
03441 {
03442 printf("Error: memory could not be allocated to OrganizeFramelist\n");
03443 return 1;
03444 }
03445 OrganizeFramelist2=(int *)malloc(framelistSize*sizeof(int));
03446 if(OrganizeFramelist2 == NULL)
03447 {
03448 printf("Error: memory could not be allocated to OrganizeFramelist2\n");
03449 return 1;
03450 }
03451
03452 OrganizeFramelist[0]=WavelengthLocation[0]-temp;
03453 OrganizeFramelist2[0]=-1;
03454 for(i=1;i<framelistSize;++i)
03455 {
03456 OrganizeFramelist[i]=WavelengthLocation[i]-temp;
03457 OrganizeFramelist2[i]=signj(OrganizeFramelist[i]);
03458 for(k=0;k<i;++k) if(WavelengthIndex[i] == WavelengthIndex[k]) OrganizeFramelist2[i]= OrganizeFramelist2[k];
03459 }
03460
03461
03462 printf("ORGANIZE FRAMELIST: \n");
03463 for(i=0;i<framelistSize;++i) printf("%d ",OrganizeFramelist[i]);
03464 printf("\n ORGANIZE FRAMELIST2: \n");
03465 for(i=0;i<framelistSize;++i) printf("%d ",OrganizeFramelist2[i]);
03466 printf("\n");
03467
03468
03469
03470
03471
03472
03473
03474 if(TempIntNum > 2) MaxSearchDistanceL=(TIME)(TempIntNum/2-1)*DataCadence+TimeCaution;
03475 MaxSearchDistanceR=(TIME)(TempIntNum/2) *DataCadence+TimeCaution;
03476 FramelistArray = (int *)malloc(framelistSize*TempIntNum*sizeof(int));
03477 if(FramelistArray == NULL)
03478 {
03479 printf("Error: memory could not be allocated to FramelistArray\n");
03480 return 1;
03481 }
03482
03483 for(i=0;i<framelistSize;++i)
03484 {
03485
03486
03487
03488
03489
03490 camera=CameraValues[i];
03491 fidfilt=FIDValues[i];
03492 printf("FID value in framelist: %d\n",fidfilt);
03493
03494 FiltergramLocation=IndexFiltergram[TargetWavelength]+OrganizeFramelist[i];
03495 k=FiltergramLocation;
03496
03497 if(KeywordMissing[k] == 1)
03498 {
03499 FramelistArray[i]=-1;
03500 printf("Error: the filtergram index %d has missing keywords and the code cannot identify it",k);
03501 }
03502 else
03503 {
03504 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)
03505 {
03506 printf("Warning: a filtergram near the target location is not what it should be. Looking for the correct filtergram\n");
03507 FiltergramLocation=IndexFiltergram[TargetWavelength];
03508 for(ii=1;ii<framelistSize;++ii)
03509 {
03510 if(OrganizeFramelist[i] > 0)
03511 {
03512 k=FiltergramLocation+ii;
03513 if(k < nRecs1 && KeywordMissing[k] != 1)
03514 {
03515 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;
03516 }
03517 }
03518 else
03519 {
03520 k=FiltergramLocation-ii;
03521 if(k > 0 && KeywordMissing[k] != 1)
03522 {
03523 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;
03524 }
03525 }
03526 }
03527 if(ii == framelistSize)
03528 {
03529 FiltergramLocation=IndexFiltergram[TargetWavelength]+OrganizeFramelist[i];
03530 printf("Error: the filtergram FSN = %d is not what it should be\n",FSN[FiltergramLocation]);
03531 FramelistArray[i]=-1;
03532 }
03533 else
03534 {
03535 FramelistArray[i]=k;
03536 FiltergramLocation=k;
03537 }
03538 }
03539 else FramelistArray[i]=k;
03540 }
03541
03542
03543
03544
03545
03546 if(OrganizeFramelist2[i] <= 0)
03547 {
03548
03549 if(TempIntNum > 2)
03550 {
03551 k=FiltergramLocation-1;
03552 for(ii=1;ii<=TempIntNum/2-1;++ii)
03553 {
03554 while(k > 0)
03555 {
03556 if(KeywordMissing[k] != 1)
03557 {
03558 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)
03559 {
03560 if ((internTOBS[k]-TargetTime) >= -MaxSearchDistanceL) --k;
03561 else break;
03562 }
03563 else break;
03564 }
03565 else --k;
03566 }
03567 if(k < 0)
03568 {
03569 FramelistArray[i+framelistSize*ii]=-1;
03570 continue;
03571 }
03572 if(KeywordMissing[k] != 1)
03573 {
03574 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)
03575 {
03576 FramelistArray[i+framelistSize*ii]=k;
03577 }
03578 else FramelistArray[i+framelistSize*ii]=-1;
03579 }
03580 else FramelistArray[i+framelistSize*ii]=-1;
03581 --k;
03582 }
03583 }
03584 k=FiltergramLocation+1;
03585 for(ii=TempIntNum/2;ii<TempIntNum;++ii)
03586 {
03587 while(k < nRecs1-1)
03588 {
03589 if(KeywordMissing[k] != 1)
03590 {
03591 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)
03592 {
03593 if ((internTOBS[k]-TargetTime) <= MaxSearchDistanceR) ++k;
03594 else break;
03595 }
03596 else break;
03597 }
03598 else ++k;
03599 }
03600 if(k > nRecs1-1)
03601 {
03602 FramelistArray[i+framelistSize*ii]=-1;
03603 continue;
03604 }
03605 if(KeywordMissing[k] != 1)
03606 {
03607 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)
03608 {
03609 FramelistArray[i+framelistSize*ii]=k;
03610 }
03611 else FramelistArray[i+framelistSize*ii]=-1;
03612 }
03613 else FramelistArray[i+framelistSize*ii]=-1;
03614 ++k;
03615 }
03616 }
03617 else
03618 {
03619
03620 k=FiltergramLocation-1;
03621 for(ii=1;ii<=TempIntNum/2;++ii)
03622 {
03623 while(k > 0)
03624 {
03625 if(KeywordMissing[k] != 1)
03626 {
03627 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)
03628 {
03629 if ((internTOBS[k]-TargetTime) >= -MaxSearchDistanceR) --k;
03630 else break;
03631 }
03632 else break;
03633 }
03634 else --k;
03635 }
03636 if(k < 0)
03637 {
03638 FramelistArray[i+framelistSize*ii]=-1;
03639 continue;
03640 }
03641 if(KeywordMissing[k] != 1)
03642 {
03643 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)
03644 {
03645 FramelistArray[i+framelistSize*ii]=k;
03646 }
03647 else FramelistArray[i+framelistSize*ii]=-1;
03648 }
03649 else FramelistArray[i+framelistSize*ii]=-1;
03650 --k;
03651 }
03652 if( TempIntNum > 2)
03653 {
03654 k=FiltergramLocation+1;
03655 for(ii=TempIntNum/2+1;ii<TempIntNum;++ii)
03656 {
03657 while(k < nRecs1-1)
03658 {
03659 if(KeywordMissing[k] != 1)
03660 {
03661 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)
03662 {
03663 if ((internTOBS[k]-TargetTime) <= MaxSearchDistanceL) ++k;
03664 else break;
03665 }
03666 else break;
03667 }
03668 else ++k;
03669 }
03670 if(k > nRecs1-1)
03671 {
03672 FramelistArray[i+framelistSize*ii]=-1;
03673 continue;
03674 }
03675 if(KeywordMissing[k] != 1)
03676 {
03677 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)
03678 {
03679 FramelistArray[i+framelistSize*ii]=k;
03680 }
03681 else FramelistArray[i+framelistSize*ii]=-1;
03682 }
03683 else FramelistArray[i+framelistSize*ii]=-1;
03684 ++k;
03685 }
03686 }
03687 }
03688
03689 }
03690
03691
03692 free(OrganizeFramelist);
03693 free(OrganizeFramelist2);
03694 OrganizeFramelist=NULL;
03695 OrganizeFramelist2=NULL;
03696
03697
03698
03699
03700
03701 printf("LOOKING FOR FILTERGRAMS ALREADY IN MEMORY BUT THAT ARE NOT NEEDED ANYMORE\n");
03702 for(ii=0;ii<nRecs1;++ii)
03703 {
03704 if(SegmentRead[ii] == 1)
03705 {
03706 Needed=0;
03707
03708 for(k=0;k<framelistSize*TempIntNum;++k)
03709 {
03710 if (FramelistArray[k] == ii)
03711 {
03712 Needed=1;
03713 break;
03714 }
03715 }
03716
03717 if(Needed == 0)
03718 {
03719 drms_free_array(Segments[ii]);
03720 drms_free_array(Ierror[ii]);
03721 Segments[ii]= NULL;
03722 Ierror[ii] = NULL;
03723 SegmentRead[ii] = 0;
03724 }
03725
03726 }
03727
03728 }
03729
03730
03731
03732
03733
03734
03735
03736 arrLev1d = (DRMS_Array_t **)malloc(nRecs1d*sizeof(DRMS_Array_t *));
03737 if(arrLev1d == NULL)
03738 {
03739 printf("Error: memory could not be allocated to arrLev1d\n");
03740 return 1;
03741 }
03742
03743 for(k=0;k<nRecs1d;++k)
03744 {
03745 arrLev1d[k]= drms_array_create(type1d,2,axisout,NULL,&status);
03746 if(status != DRMS_SUCCESS || arrLev1d[k] == NULL)
03747 {
03748 printf("Error: cannot create a DRMS array for a level 1d filtergram with index %d at target time %s\n",k,timeBegin2);
03749
03750
03751
03752
03753 return 1;
03754 }
03755 }
03756 Segments1d=1;
03757
03758
03759
03760
03761
03762 printf("COMPUTING MEDIAN VALUE OF X0, Y0, AND RSUN\n");
03763 X0ARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03764 Y0ARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03765 RSUNARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03766
03767 for(k=0;k<framelistSize;++k)
03768 {
03769 for(i=0;i<TempIntNum;++i)
03770 {
03771 temp=FramelistArray[k+framelistSize*i];
03772 if(temp != -1)
03773 {
03774 X0ARR[k+framelistSize*i]=X0[temp];
03775 Y0ARR[k+framelistSize*i]=Y0[temp];
03776 RSUNARR[k+framelistSize*i]=RSUN[temp];
03777 }
03778 else
03779 {
03780 X0ARR[k+framelistSize*i] =MISSINGRESULT;
03781 Y0ARR[k+framelistSize*i] =MISSINGRESULT;
03782 RSUNARR[k+framelistSize*i]=MISSINGRESULT;
03783 }
03784
03785 }
03786 }
03787
03788
03789 status=fstats(framelistSize*TempIntNum,X0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03790 printf("VALUES USED TO OBTAIN THE MEDIAN: %d\n",ngood);
03791 X0AVG=median;
03792 X0RMS=sigma;
03793 status=fstats(framelistSize*TempIntNum,Y0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03794 Y0AVG=median;
03795 Y0RMS=sigma;
03796 status=fstats(framelistSize*TempIntNum,RSUNARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03797 RSUNAVG=median;
03798 RSUNRMS=sigma;
03799
03800 free(X0ARR);
03801 free(Y0ARR);
03802 free(RSUNARR);
03803 X0ARR=NULL;
03804 Y0ARR=NULL;
03805 RSUNARR=NULL;
03806
03807 if(combine == 1)
03808 {
03809 printf("COMPUTING MEDIAN VALUE OF X0, Y0, AND RSUN, FOR FRONT CAMERA ONLY\n");
03810 X0ARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03811 Y0ARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03812 RSUNARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03813
03814 for(k=0;k<framelistSize;++k)
03815 {
03816 for(i=0;i<TempIntNum;++i)
03817 {
03818 temp=FramelistArray[k+framelistSize*i];
03819 if(temp != -1)
03820 {
03821 if(HCAMID[temp] == LIGHT_FRONT)
03822 {
03823 X0ARR[k+framelistSize*i]=X0[temp];
03824 Y0ARR[k+framelistSize*i]=Y0[temp];
03825 RSUNARR[k+framelistSize*i]=RSUN[temp];
03826 }
03827 else
03828 {
03829 X0ARR[k+framelistSize*i] =MISSINGRESULT;
03830 Y0ARR[k+framelistSize*i] =MISSINGRESULT;
03831 RSUNARR[k+framelistSize*i]=MISSINGRESULT;
03832 }
03833 }
03834 else
03835 {
03836 X0ARR[k+framelistSize*i] =MISSINGRESULT;
03837 Y0ARR[k+framelistSize*i] =MISSINGRESULT;
03838 RSUNARR[k+framelistSize*i]=MISSINGRESULT;
03839 }
03840
03841 }
03842 }
03843
03844
03845 status=fstats(framelistSize*TempIntNum,X0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03846 printf("VALUES USED TO OBTAIN THE MEDIAN (FRONT CAMERA): %d\n",ngood);
03847 X0AVGF=median;
03848 status=fstats(framelistSize*TempIntNum,Y0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03849 Y0AVGF=median;
03850 status=fstats(framelistSize*TempIntNum,RSUNARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03851 RSUNAVGF=median;
03852
03853 free(X0ARR);
03854 free(Y0ARR);
03855 free(RSUNARR);
03856 X0ARR=NULL;
03857 Y0ARR=NULL;
03858 RSUNARR=NULL;
03859
03860 printf("COMPUTING MEDIAN VALUE OF X0, Y0, AND RSUN, FOR SIDE CAMERA ONLY\n");
03861 X0ARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03862 Y0ARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03863 RSUNARR =(float *)malloc(framelistSize*TempIntNum*sizeof(float));
03864
03865 for(k=0;k<framelistSize;++k)
03866 {
03867 for(i=0;i<TempIntNum;++i)
03868 {
03869 temp=FramelistArray[k+framelistSize*i];
03870 if(temp != -1)
03871 {
03872 if(HCAMID[temp] == LIGHT_SIDE)
03873 {
03874 X0ARR[k+framelistSize*i]=X0[temp];
03875 Y0ARR[k+framelistSize*i]=Y0[temp];
03876 RSUNARR[k+framelistSize*i]=RSUN[temp];
03877 }
03878 else
03879 {
03880 X0ARR[k+framelistSize*i] =MISSINGRESULT;
03881 Y0ARR[k+framelistSize*i] =MISSINGRESULT;
03882 RSUNARR[k+framelistSize*i]=MISSINGRESULT;
03883 }
03884 }
03885 else
03886 {
03887 X0ARR[k+framelistSize*i] =MISSINGRESULT;
03888 Y0ARR[k+framelistSize*i] =MISSINGRESULT;
03889 RSUNARR[k+framelistSize*i]=MISSINGRESULT;
03890 }
03891
03892 }
03893 }
03894
03895
03896 status=fstats(framelistSize*TempIntNum,X0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03897 printf("VALUES USED TO OBTAIN THE MEDIAN (SIDE CAMERA): %d\n",ngood);
03898 X0AVGS=median;
03899 status=fstats(framelistSize*TempIntNum,Y0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03900 Y0AVGS=median;
03901 status=fstats(framelistSize*TempIntNum,RSUNARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03902 RSUNAVGS=median;
03903
03904 free(X0ARR);
03905 free(Y0ARR);
03906 free(RSUNARR);
03907 X0ARR=NULL;
03908 Y0ARR=NULL;
03909 RSUNARR=NULL;
03910
03911 }
03912
03913
03914
03915 for(k=0;k<framelistSize;++k)
03916 {
03917
03918 ActualTempIntNum=TempIntNum;
03919
03920
03921
03922
03923 for(i=0;i<TempIntNum;++i)
03924 {
03925 temp=FramelistArray[k+framelistSize*i];
03926 if(temp != -1)
03927 {
03928
03929
03930 if(SegmentRead[temp] != -1)
03931 {
03932
03933 if(SegmentRead[temp] == 0)
03934 {
03935 printf("segment needs to be read for FSN %d %d\n",FSN[temp],HCAMID[temp]);
03936 segin = drms_segment_lookupnum(recLev1->records[temp], 0);
03937 Segments[temp] = drms_segment_read(segin,type1d, &status);
03938 if (status != DRMS_SUCCESS || Segments[temp] == NULL)
03939 {
03940 printf("Error: could not read the segment of level 1 record FSN = %d at target time %s\n",FSN[temp],timeBegin2);
03941 return 1;
03942
03943
03944
03945
03946
03947
03948 }
03949 else
03950 {
03951 Ierror[temp] = drms_array_create(typeEr,2,axisout,NULL,&status);
03952 if(status != DRMS_SUCCESS || Ierror[temp] == NULL)
03953 {
03954 printf("Error: could not create an array for Ierror at target time %s\n",timeBegin2);
03955 drms_free_array(Segments[temp]);
03956 Segments[temp]=NULL;
03957 Ierror[temp]=NULL;
03958 SegmentRead[temp]=-1;
03959 ActualTempIntNum-=1;
03960 arrin[i] = NULL;
03961 arrerrors[i] = NULL;
03962 }
03963 else
03964 {
03965 arrin[i] = Segments[temp];
03966 arrerrors[i] = Ierror[temp];
03967 if(arrin[i]->axis[0] != axisin[0] || arrin[i]->axis[1] != axisin[1])
03968 {
03969 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]);
03970 drms_free_array(Segments[temp]);
03971 drms_free_array(Ierror[temp]);
03972 ActualTempIntNum-=1;
03973 arrin[i] = NULL;
03974 arrerrors[i] = NULL;
03975 Segments[temp]=NULL;
03976 Ierror[temp]=NULL;
03977 SegmentRead[temp]=-1;
03978 }
03979 else
03980 {
03981 SegmentRead[temp]=1;
03982
03983
03984
03985
03986 segin = drms_segment_lookup(recLev1->records[temp],"bad_pixel_list");
03987 BadPixels = NULL;
03988 BadPixels = drms_segment_read(segin,segin->info->type,&status);
03989 if(status != DRMS_SUCCESS || BadPixels == NULL)
03990 {
03991 printf("Error: cannot read the list of bad pixels of level 1 filtergram FSN= %d\n",FSN[temp]);
03992 return 1;
03993
03994
03995
03996
03997
03998
03999
04000
04001 }
04002 else
04003 {
04004
04005 strcpy(HMISeriesTemp,CosmicRaySeries);
04006 strcat(HMISeriesTemp,"[][");
04007 sprintf(FSNtemps,"%d",FSN[temp]);
04008 strcat(HMISeriesTemp,FSNtemps);
04009 strcat(HMISeriesTemp,"]");
04010 rectemp=NULL;
04011
04012 rectemp=drms_open_records(drms_env,HMISeriesTemp,&statusA[0]);
04013
04014 if(statusA[0] == DRMS_SUCCESS && rectemp != NULL && rectemp->n != 0)
04015 {
04016 segin = drms_segment_lookupnum(rectemp->records[0],0);
04017 CosmicRays = NULL;
04018
04019 COSMICCOUNT=drms_getkey_int(rectemp->records[0],COUNTS,&status);
04020 if(status != DRMS_SUCCESS || COSMICCOUNT == -1)
04021 {
04022 QUALITY = QUALITY | QUAL_NOCOSMICRAY;
04023 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
04024 }
04025 else
04026 {
04027 CosmicRays = drms_segment_read(segin,segin->info->type,&status);
04028 if(status != DRMS_SUCCESS || CosmicRays == NULL)
04029 {
04030 printf("Error: the list of cosmic-ray hits could not be read for FSN %d\n",FSN[temp]);
04031 return 1;
04032
04033
04034 QUALITY = QUALITY | QUAL_NOCOSMICRAY;
04035 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
04036 CosmicRays = NULL;
04037
04038 }
04039 }
04040 }
04041 else
04042 {
04043 printf("Unable to open the series %s for FSN %d\n",HMISeriesTemp,FSN[temp]);
04044
04045
04046
04047 QUALITY = QUALITY | QUAL_NOCOSMICRAY;
04048 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
04049 CosmicRays = NULL;
04050
04051 }
04052
04053 image = Segments[temp]->data;
04054
04055
04056
04057
04058
04059 if(inRotationalFlat == 1)
04060 {
04061
04062 HMIFlatField = (char *)malloc(MaxNString*sizeof(char *));
04063 if(HMIFlatField == NULL)
04064 {
04065 printf("Error: memory could not be allocated to HMIFlatField\n");
04066 return 1;
04067 }
04068 HMIFlatField = drms_getkey_string(recLev1->records[temp],FLATREC,&status);
04069 if (status != DRMS_SUCCESS)
04070 {
04071 printf("Error: could not read the FLAT_REC keyword for the target filtergram FSN= %d",FSN[temp]);
04072 return 1;
04073 }
04074
04075
04076 if(strcmp(HMIFlatField,HMIFlatField0) != 0)
04077 {
04078 printf("Warning: the hmi.flatfield record used to produce the level 1 records changed during the run of the observables code\n");
04079
04080 recflat = drms_open_records(drms_env,HMIFlatField,&status);
04081 if (status != DRMS_SUCCESS || recflat == NULL || recflat->n == 0)
04082 {
04083 printf("Error: record missing or corrupt for the flat field query %s\n",HMIFlatField);
04084 return 1;
04085 }
04086 drms_free_array(flatfield);
04087 strcpy(HMIFlatField0,HMIFlatField);
04088 segin = drms_segment_lookup(recflat->records[0],"flatfield");
04089 flatfield = drms_segment_read(segin,type1d,&status);
04090 if (status != DRMS_SUCCESS || flatfield == NULL)
04091 {
04092 printf("Error: could not read the data segment for the flat field query %s\n",HMIFlatField);
04093 return 1;
04094 }
04095 pztflat = flatfield->data;
04096 status=drms_close_records(recflat,DRMS_FREE_RECORD);
04097 }
04098
04099 if(inLinearity == 1)
04100 {
04101 printf("applying rotational flat field and correcting for non-linearity of camera on record FSN=%d\n",FSN[temp]);
04102 for(iii=0;iii<axisin[0]*axisin[1];++iii)
04103 {
04104
04105 image[iii]=(image[iii]*pztflat[iii])/rotflat[iii];
04106
04107 tempvalue = image[iii]*EXPTIME[temp];
04108 if(HCAMID[temp] == LIGHT_FRONT) tempvalue = (nonlinf[0]+nonlinf[1]*tempvalue+nonlinf[2]*tempvalue*tempvalue+nonlinf[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
04109 else tempvalue = (nonlins[0]+nonlins[1]*tempvalue+nonlins[2]*tempvalue*tempvalue+nonlins[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
04110 image[iii] = tempvalue/EXPTIME[temp];
04111 }
04112 }
04113 else
04114 {
04115 printf("applying rotational flat field on record FSN=%d\n",FSN[temp]);
04116 for(iii=0;iii<axisin[0]*axisin[1];++iii)
04117 {
04118
04119 image[iii]=(image[iii]*pztflat[iii])/rotflat[iii];
04120 }
04121 }
04122
04123 free(HMIFlatField);
04124
04125 }
04126 else
04127 {
04128 if(inLinearity == 1)
04129 {
04130 printf("correcting for non-linearity of camera on record FSN=%d\n",FSN[temp]);
04131 for(iii=0;iii<axisin[0]*axisin[1];++iii)
04132 {
04133
04134 tempvalue = image[iii]*EXPTIME[temp];
04135 if(HCAMID[temp] == LIGHT_FRONT) tempvalue = (nonlinf[0]+nonlinf[1]*tempvalue+nonlinf[2]*tempvalue*tempvalue+nonlinf[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
04136 else tempvalue = (nonlins[0]+nonlins[1]*tempvalue+nonlins[2]*tempvalue*tempvalue+nonlins[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
04137 image[iii] = tempvalue/EXPTIME[temp];
04138 }
04139 }
04140 }
04141
04142
04143
04144 status = MaskCreation(Mask,axisin[0],axisin[1],BadPixels,HIMGCFID[temp],image,CosmicRays,NBADPERM[temp]);
04145 if(status != 0)
04146 {
04147 printf("Error: unable to create a mask for the gap filling function\n");
04148 return 1;
04149 }
04150 if(BadPixels != NULL)
04151 {
04152 drms_free_array(BadPixels);
04153 BadPixels=NULL;
04154 }
04155 if(CosmicRays != NULL)
04156 {
04157 drms_free_array(CosmicRays);
04158 CosmicRays=NULL;
04159 }
04160 if(rectemp != NULL)
04161 {
04162 drms_close_records(rectemp,DRMS_FREE_RECORD);
04163 rectemp=NULL;
04164 }
04165
04166 image = arrin[i]->data;
04167 ierror = arrerrors[i]->data;
04168
04169 t0=dsecnd();
04170 printf("STARTING GAPFILL\n");
04171 status =do_gapfill(image,Mask,&const_param,ierror,axisin[0],axisin[1]);
04172 t1=dsecnd();
04173 printf("TIME ELAPSED TO GAPFILL: %f\n",t1-t0);
04174 if(status != 0)
04175 {
04176 printf("Error: gapfilling code did not work on level 1 filtergram FSN = %d at target time %s\n",FSN[temp],timeBegin2);
04177 QUALITY = QUALITY | QUAL_NOGAPFILL;
04178 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOGAPFILL;
04179 }
04180 }
04181 }
04182 }
04183 }
04184 }
04185 else
04186 {
04187 printf("segment is already in memory for FSN %d %d\n",FSN[temp],HCAMID[temp]);
04188 arrin[i] = Segments[temp];
04189 arrerrors[i] = Ierror[temp];
04190 }
04191
04192 }
04193 else
04194 {
04195 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);
04196 ActualTempIntNum-=1;
04197 arrin[i] = NULL;
04198 arrerrors[i] = NULL;
04199 }
04200 }
04201 else
04202 {
04203 printf("a filtergram close to the target time is missing/corrupted\n");
04204 ActualTempIntNum-=1;
04205 arrin[i] = NULL;
04206 arrerrors[i] = NULL;
04207 }
04208 }
04209
04210
04211
04212
04213 if(QuickLook == 1) ThresholdPol=1;
04214 else ThresholdPol=2;
04215 if(ActualTempIntNum >= ThresholdPol)
04216 {
04217
04218 images = (float **)malloc(ActualTempIntNum*sizeof(float *));
04219 if(images == NULL)
04220 {
04221 printf("Error: memory could not be allocated to images\n");
04222 return 1;
04223 }
04224
04225 ierrors = (char **)malloc(ActualTempIntNum*sizeof(char *));
04226 if(ierrors == NULL)
04227 {
04228 printf("Error: memory could not be allocated to ierrors\n");
04229 return 1;
04230 }
04231
04232
04233 KeyInterp = (struct keyword *)malloc(ActualTempIntNum*sizeof(struct keyword));
04234 if(KeyInterp == NULL)
04235 {
04236 printf("Error: memory could not be allocated to KeyInterp\n");
04237 return 1;
04238 }
04239
04240
04241
04242 ii=0;
04243 for(i=0;i<TempIntNum;++i) if (arrin[i] != NULL && arrerrors[i] != NULL)
04244 {
04245 temp=FramelistArray[k+framelistSize*i];
04246 if(fabs(RSUN[temp]-RSUNAVG) > 1.82*RSUNerr || isnan(RSUN[temp]))
04247 {
04248 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);
04249 ActualTempIntNum-=1;
04250 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04251 continue;
04252 }
04253 if(combine == 0)
04254 {
04255 if(fabs(X0[temp]-X0AVG) > RSUNerr || isnan(X0[temp]))
04256 {
04257 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);
04258 ActualTempIntNum-=1;
04259 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04260 continue;
04261 }
04262 if(fabs(Y0[temp]-Y0AVG) > RSUNerr || isnan(Y0[temp]))
04263 {
04264 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);
04265 ActualTempIntNum-=1;
04266 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04267 continue;
04268 }
04269 }
04270 else
04271 {
04272 if(HCAMID[temp] == LIGHT_FRONT)
04273 {
04274 if(fabs(X0[temp]-X0AVGF) > RSUNerr || isnan(X0[temp]))
04275 {
04276 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);
04277 ActualTempIntNum-=1;
04278 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04279 continue;
04280 }
04281 if(fabs(Y0[temp]-Y0AVGF) > RSUNerr || isnan(Y0[temp]))
04282 {
04283 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);
04284 ActualTempIntNum-=1;
04285 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04286 continue;
04287 }
04288 }
04289 else
04290 {
04291 if(fabs(X0[temp]-X0AVGS) > RSUNerr || isnan(X0[temp]))
04292 {
04293 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);
04294 ActualTempIntNum-=1;
04295 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04296 continue;
04297 }
04298 if(fabs(Y0[temp]-Y0AVGS) > RSUNerr || isnan(Y0[temp]))
04299 {
04300 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);
04301 ActualTempIntNum-=1;
04302 QUALITY = QUALITY | QUAL_LIMBFITISSUE;
04303 continue;
04304 }
04305 }
04306 }
04307 images[ii]=arrin[i]->data;
04308 image=arrin[i]->data;
04309 if( (combine == 1) && (HCAMID[temp] == LIGHT_FRONT)){
04310
04311 for(iii=0;iii<axisin[0]*axisin[1];++iii) image[iii]= image[iii]/iratio;
04312 printf("MOD L intensity correction applied to FSN=%d \n",FSN[temp]);
04313 }
04314 ierrors[ii]=arrerrors[i]->data;
04315 if(HCAMID[temp] == LIGHT_FRONT) KeyInterp[ii].camera=0;
04316 else KeyInterp[ii].camera=1;
04317 if(!strcmp(HWLTNSET[temp],"OPEN")) QUALITY = QUALITY | QUAL_ISSTARGET;
04318 if((QUALITYin[temp] & Q_ACS_ECLP) == Q_ACS_ECLP) QUALITY = QUALITY | QUAL_ECLIPSE;
04319 if((QUALITYin[temp] & Q_ACS_LUNARTRANSIT) == Q_ACS_LUNARTRANSIT) QUALITY = QUALITY | QUAL_POORQUALITY;
04320 if((QUALITYin[temp] & Q_ACS_THERMALRECOVERY) == Q_ACS_THERMALRECOVERY) QUALITY = QUALITY | QUAL_POORQUALITY;
04321 if((QUALITYin[temp] & Q_CAMERA_ANOMALY) == Q_CAMERA_ANOMALY) QUALITY = QUALITY | QUAL_POORQUALITY;
04322 KeyInterp[ii].rsun=RSUNAVG;
04323 if(combine == 1) KeyInterp[ii].rsun=RSUN[temp];
04324 printf("actual solar radius of image in = %f\n",RSUN[temp]);
04325 KeyInterp[ii].xx0=X0[temp];
04326 KeyInterp[ii].yy0=Y0[temp];
04327 KeyInterp[ii].dist=(float)(DSUNOBS[temp]/(double)AstroUnit);
04328 KeyInterp[ii].b0=CRLTOBS[temp]/180.*M_PI;
04329 KeyInterp[ii].p0=CROTA2[temp]/180.*M_PI;
04330 KeyInterp[ii].time=internTOBS[temp];
04331 KeyInterp[ii].focus=CFINDEX[temp];
04332
04333 rec=recLev1->records[temp];
04334 sprintf(recnums,"%ld",rec->recnum);
04335 if(k != 0 || ii != 0) strcat(source,",#");
04336 else strcat(source,"#");
04337 strcat(source,recnums);
04338
04339 QUALITYLEV1 = QUALITYLEV1 | QUALITYin[temp];
04340 QUALITY = QUALITY | QUALITYlev1[temp];
04341
04342 ii+=1;
04343 }
04344
04345
04346
04347 RSUNint=RSUNAVG;
04348 KeyInterpOut.rsun=RSUNint;
04349
04350 if(combine == 0)
04351 {
04352 KeyInterpOut.xx0 =X0AVG;
04353 KeyInterpOut.yy0 =Y0AVG;
04354 }
04355 else
04356 {
04357 if(CamId == LIGHT_FRONT)
04358 {
04359 KeyInterpOut.xx0 =X0AVGF;
04360 KeyInterpOut.yy0 =Y0AVGF;
04361 }
04362 else
04363 {
04364 KeyInterpOut.xx0 =X0AVGS;
04365 KeyInterpOut.yy0 =Y0AVGS;
04366 }
04367 }
04368
04369 KeyInterpOut.dist=(float)DSUNOBSint;
04370 KeyInterpOut.b0 =CRLTOBSint/180.*M_PI;
04371 KeyInterpOut.p0 =CROTA2int/180.*M_PI;
04372 tobs = TargetTime+(DSUNOBSint-1.0)/2.00398880422056639358e-03;
04373 KeyInterpOut.time=tobs;
04374 KeyInterpOut.focus=TargetCFINDEX;
04375
04376
04377
04378 printf("Calling temporal interpolation, de-rotation, and un-distortion code\n");
04379
04380 totalTempIntNum += ActualTempIntNum;
04381 printf("ACTUALTEMPINT= %d, TOTALTEMPINTNUM= %d\n",ActualTempIntNum,totalTempIntNum);
04382 if(ActualTempIntNum != TempIntNum) QUALITY = QUALITY | QUAL_LOWINTERPNUM;
04383 else
04384 {
04385 minimum=KeyInterp[0].time;
04386 maximum=KeyInterp[0].time;
04387 for(ii=1;ii<TempIntNum;++ii)
04388 {
04389 if(KeyInterp[ii].time < minimum) minimum=KeyInterp[ii].time;
04390 if(KeyInterp[ii].time > maximum) maximum=KeyInterp[ii].time;
04391 }
04392 if((maximum-minimum) > (DataCadence*(double)(TempIntNum-1)+DataCadence/(double)framelistSize) ) QUALITY = QUALITY | QUAL_LOWINTERPNUM;
04393 }
04394
04395 if(ActualTempIntNum >= ThresholdPol)
04396 {
04397 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);
04398 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);
04399
04400 t0=dsecnd();
04401 strcpy(dpath2,dpath);
04402 strcat(dpath2,"/../../../");
04403 status=do_interpolate(images,ierrors,arrLev1d[k]->data,KeyInterp,&KeyInterpOut,&const_param,ActualTempIntNum,axisin[0],axisin[1],-1.0,dpath2);
04404 t1=dsecnd();
04405 printf("TIME ELAPSED IN DO_INTERPOLATE: %f\n",t1-t0);
04406 }
04407 else
04408 {
04409 printf("Error: ActualTempIntNum <ThresholdPol\n");
04410 QUALITY = QUALITY | QUAL_NOTENOUGHINTERPOLANTS;
04411 status = 1;
04412 }
04413
04414 printf("End temporal interpolation, de-rotation, and un-distortion\n");
04415 if (status != 0)
04416 {
04417 printf("Error: temporal interpolation, de-rotation, and undistortion subroutine failed at target time %s\n",timeBegin2);
04418 drms_free_array(arrLev1d[k]);
04419 arrLev1d[k] = NULL;
04420 QUALITY = QUALITY | QUAL_INTERPOLATIONFAILED;
04421 }
04422 else
04423 {
04424 for(i=0;i<TempIntNum;++i)
04425 {
04426 temp=FramelistArray[k+framelistSize*i];
04427 if(temp != -1) break;
04428 }
04429
04430
04431
04432
04433 if(combine == 1)camera=3;
04434 if(combine == 0 && CamId == LIGHT_SIDE) camera=1;
04435 if(combine == 0 && CamId == LIGHT_FRONT) camera=2;
04436
04437
04438 cdelt1=1.0/RSUNint*asin(solar_radius/(DSUNOBSint*(double)AstroUnit))*180.*60.*60./M_PI;
04439
04440 statusA[0] = drms_setkey_time(recLev1d->records[k],TRECS,trec);
04441 statusA[1] = drms_setkey_time(recLev1d->records[k],TOBSS,tobs);
04442 statusA[2] = drms_setkey_int(recLev1d->records[k],CAMERAS,camera);
04443 statusA[3] = drms_setkey_string(recLev1d->records[k],HISTORYS,HISTORY);
04444 statusA[4] = drms_setkey_string(recLev1d->records[k],COMMENTS,COMMENT);
04445
04446 statusA[5]=0;
04447 statusA[6] = drms_setkey_int(recLev1d->records[k],HFLIDS,TargetHFLID);
04448 statusA[7] = drms_setkey_int(recLev1d->records[k],HCFTIDS,TargetCFINDEX);
04449
04450 statusA[8]=0;
04451 statusA[9] = drms_setkey_int(recLev1d->records[k],QUALITYS,QUALITY);
04452 statusA[10]= drms_setkey_double(recLev1d->records[k],DSUNOBSS,DSUNOBSint*(double)AstroUnit);
04453 statusA[11]= drms_setkey_float(recLev1d->records[k],CRLTOBSS,KeyInterpOut.b0*180./M_PI);
04454 statusA[12]= drms_setkey_float(recLev1d->records[k],CROTA2S,-KeyInterpOut.p0*180./M_PI);
04455 statusA[13]= drms_setkey_float(recLev1d->records[k],CDELT1S,cdelt1);
04456 statusA[14]= drms_setkey_float(recLev1d->records[k],CDELT2S,cdelt1);
04457 statusA[15]= drms_setkey_float(recLev1d->records[k],CRPIX1S,KeyInterpOut.xx0+1.);
04458 statusA[16]= drms_setkey_float(recLev1d->records[k],CRPIX2S,KeyInterpOut.yy0+1.);
04459 sprintf(jsocverss,"%d",jsoc_vers_num);
04460 statusA[17]= drms_setkey_string(recLev1d->records[k],BLDVERSS,jsocverss);
04461 statusA[18]= drms_setkey_double(recLev1d->records[k],OBSVRS,OBSVRint);
04462 statusA[19]= drms_setkey_double(recLev1d->records[k],OBSVWS,OBSVWint);
04463 statusA[20]= drms_setkey_double(recLev1d->records[k],OBSVNS,OBSVNint);
04464
04465 statusA[21]=0;
04466 statusA[22]= drms_setkey_float(recLev1d->records[k],CRLNOBSS,CRLNOBSint);
04467 statusA[23]= drms_setkey_int(recLev1d->records[k],CARROTS,CARROTint);
04468 statusA[24]= drms_setkey_int(recLev1d->records[k],TINTNUMS,ActualTempIntNum);
04469 statusA[25]= drms_setkey_int(recLev1d->records[k],SINTNUMS,const_param.order_int);
04470 statusA[26]= drms_setkey_string(recLev1d->records[k],CODEVER0S,CODEVERSION);
04471 statusA[27]= drms_setkey_string(recLev1d->records[k],DISTCOEFS,DISTCOEFPATH);
04472 statusA[28]= drms_setkey_string(recLev1d->records[k],ROTCOEFS,ROTCOEFPATH);
04473 statusA[29]= drms_setkey_int(recLev1d->records[k],ODICOEFFS,const_param.order_dist_coef);
04474 statusA[30]= drms_setkey_int(recLev1d->records[k],OROCOEFFS,2*const_param.order2_rot_coef);
04475 statusA[31]= drms_setkey_string(recLev1d->records[k],CODEVER1S,CODEVERSION1);
04476 statusA[32]= drms_setkey_string(recLev1d->records[k],CODEVER2S,CODEVERSION2);
04477 statusA[33]= drms_setkey_int(recLev1d->records[k],HPL1POSS,HPL1POS[temp]);
04478 statusA[34]= drms_setkey_int(recLev1d->records[k],HPL2POSS,HPL2POS[temp]);
04479 statusA[35]= drms_setkey_int(recLev1d->records[k],HPL3POSS,HPL3POS[temp]);
04480 statusA[36]= drms_setkey_int(recLev1d->records[k],HWL1POSS,HWL1POS[temp]);
04481 statusA[37]= drms_setkey_int(recLev1d->records[k],HWL2POSS,HWL2POS[temp]);
04482 statusA[38]= drms_setkey_int(recLev1d->records[k],HWL3POSS,HWL3POS[temp]);
04483 statusA[39]= drms_setkey_int(recLev1d->records[k],HWL4POSS,HWL4POS[temp]);
04484 statusA[40]= drms_setkey_int(recLev1d->records[k],FIDS,FID[temp]);
04485 printf("FID of written record: %d\n",FID[temp]);
04486 statusA[41]= drms_setkey_int(recLev1d->records[k],HCAMIDS,CamId);
04487 sprint_time(DATEOBS,tobs-DataCadence/2.0,"UTC",1);
04488 statusA[42]= drms_setkey_string(recLev1d->records[k],DATEOBSS,DATEOBS);
04489 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
04490 statusA[43]= drms_setkey_string(recLev1d->records[k],DATES,DATEOBS);
04491 statusA[44]= drms_setkey_int(recLev1d->records[k],HWLTIDS,TargetHWLTID);
04492 statusA[45]= drms_setkey_int(recLev1d->records[k],HPLTIDS,TargetHPLTID);
04493 statusA[46]= drms_setkey_int(recLev1d->records[k],WavelengthIDS,WavelengthID);
04494 if(camera == 2) strcpy(DATEOBS,"HMI_FRONT2");
04495 if(camera == 1) strcpy(DATEOBS,"HMI_SIDE1");
04496 if(camera == 3) strcpy(DATEOBS,"HMI_COMBINED");
04497 statusA[47]= drms_setkey_string(recLev1d->records[k],INSTRUMES,DATEOBS);
04498
04499 if(inLinearity == 1) CALVER32[0] = CALVER32[0] | CALVER_LINEARITY;
04500 if(inRotationalFlat == 1) CALVER32[0] = CALVER32[0] | CALVER_ROTATIONAL;
04501 if(inSmoothTables == 1) CALVER32[0] = CALVER32[0] | CALVER_SMOOTH;
04502 if(TargetHFLID == 58312 || TargetHFLID == 1022) {CALVER32[0] = CALVER32[0] | CALVER_MODL;} else CALVER32[0] = CALVER32[0] & CALVER_NOMODL;
04503 statusA[48]= drms_setkey_longlong(recLev1d->records[k],CALVER64S,CALVER32[0]);
04504
04505 TotalStatus=0;
04506 for(i=0;i<49;++i) TotalStatus+=statusA[i];
04507 if(TotalStatus != 0)
04508 {
04509 for(ii=0;ii<49;++ii) if(statusA[ii] != 0) printf(" %d ",ii);
04510 printf("\n");
04511 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);
04512 }
04513
04514
04515 if (Lev1dWanted)
04516 {
04517 segout = drms_segment_lookupnum(recLev1d->records[k],0);
04518 arrLev1d[k]->bzero=segout->bzero;
04519 arrLev1d[k]->bscale=segout->bscale;
04520 arrLev1d[k]->israw=0;
04521 status=drms_segment_write(segout,arrLev1d[k],0);
04522 if(status != DRMS_SUCCESS)
04523 {
04524 printf("Error: a call to drms_segment_write failed\n");
04525 return 1;
04526 }
04527 }
04528
04529 }
04530
04531 free(images);
04532 free(ierrors);
04533 images=NULL;
04534 ierrors=NULL;
04535 free(KeyInterp);
04536 KeyInterp=NULL;
04537 }
04538 else
04539 {
04540 printf("Error: not enough valid level 1 filtergrams to produce a level 1d filtergram at target time %s\n",timeBegin2);
04541 drms_free_array(arrLev1d[k]);
04542 arrLev1d[k]=NULL;
04543 QUALITY = QUALITY | QUAL_NOTENOUGHINTERPOLANTS;
04544
04545 }
04546
04547
04548 }
04549
04550
04551 free(FramelistArray);
04552 FramelistArray=NULL;
04553 }
04554
04555
04556
04557
04558
04559
04560
04561
04562
04563
04564
04565
04566
04567 if (TestLevIn[2]==1)
04568 {
04569
04570
04571
04572
04573
04574
04575
04576
04577
04578
04579
04580 PolarizationType=1;
04581 if(CamId == LIGHT_SIDE) camera=1;
04582 if(CamId == LIGHT_FRONT) camera=2;
04583 if(CamId0 == 3) camera=3;
04584 if(camera == 2)
04585 {
04586 printf("Error: the use of time-averaged IQUV data as input requires CamId = side camera\n");
04587 return 1;
04588 }
04589
04590
04591
04592
04593 if(PolarizationType ==3 || PolarizationType ==2) strcpy(HMISeries,HMISeriesLev1pb);
04594 else strcpy(HMISeries,HMISeriesLev1pa);
04595 strcat(HMISeries,"[");
04596 strcat(HMISeries,timeBegin2);
04597 strcat(HMISeries,"][");
04598 if(DataCadence != 720.0) sprintf(CamIds,"%d",CamId);
04599 else sprintf(CamIds,"%d",camera);
04600 strcat(HMISeries,CamIds);
04601 strcat(HMISeries,"]");
04602
04603 printf("Opening the record %s\n",HMISeries);
04604 recLev1p = drms_open_records(drms_env,HMISeries,&status);
04605
04606 if (status == DRMS_SUCCESS && recLev1p != NULL && recLev1p->n > 0)
04607 {
04608 if(recLev1p->n > 1)
04609 {
04610 printf("Too many records: %d\n",recLev1p->n);
04611 return 1;
04612 }
04613 printf("Number of level 1p records opened= %d\n",recLev1p->n);
04614
04615 nSegs1p = drms_record_numsegments(recLev1p->records[0]);
04616 printf("NUMBER OF DATA SEGMENTS: %d\n",nSegs1p);
04617
04618
04619 if (PolarizationType ==1)
04620 {
04621 nRecs1p = nSegs1p/4;
04622 }
04623 if (PolarizationType ==2 || PolarizationType ==3)
04624 {
04625 nRecs1p = nSegs1p/2;
04626 }
04627 printf("NUMBER OF WAVELENGTHS: %d\n",nRecs1p);
04628
04629 trec = drms_getkey_time(recLev1p->records[0],TRECS,&status);
04630 if(status != DRMS_SUCCESS)
04631 {
04632 printf("Error: cannot read the keyword %s\n",TRECS);
04633
04634 return 1;
04635 }
04636 if(trec != TargetTime)
04637 {
04638 printf("Error: %s of a level 1p record is not equal to the target time %s\n",TRECS,timeBegin2);
04639
04640 return 1;
04641 }
04642 tobs = drms_getkey_time(recLev1p->records[0],TOBSS,&status);
04643 if(status != DRMS_SUCCESS)
04644 {
04645 printf("Error: cannot read the keyword %s\n",TOBSS);
04646 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04647
04648 }
04649
04650
04651
04652
04653
04654 TREC_STEP= drms_getkey_time(recLev1p->records[0],TRECSTEPS,&status);
04655 if(status != DRMS_SUCCESS)
04656 {
04657 printf("Error: cannot read the keyword %s\n",TRECSTEPS);
04658
04659 return 1;
04660 }
04661
04662 if(TREC_STEP != DataCadence)
04663 {
04664 printf("Error: the cadence is not equal to the T_REC_step keyword of the level 1p data\n");
04665
04666 return 1;
04667 }
04668
04669 DRMS_SegmentDimInfo_t di;
04670 segin = drms_segment_lookupnum(recLev1p->records[0],0);
04671 status = drms_segment_getdims(segin,&di);
04672 if(status != DRMS_SUCCESS)
04673 {
04674 printf("Error: cannot read the dimensions of the data segment of level 1p data\n");
04675
04676 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04677 }
04678 axisin[0]= di.axis[0];
04679 axisin[1]= di.axis[1];
04680 axisout[0]=axisin[0];
04681 axisout[1]=axisin[1];
04682
04683 QUALITYLEV1 = drms_getkey_int(recLev1p->records[0],QUALLEV1S,&status);
04684 if(status != DRMS_SUCCESS)
04685 {
04686 printf("Error: cannot read the keyword %s\n",QUALLEV1S);
04687 return 1;
04688 }
04689 strcpy(source,drms_getkey_string(recLev1p->records[0],SOURCES,&status));
04690 if(status != DRMS_SUCCESS)
04691 {
04692 printf("Error: cannot read the keyword %s\n",SOURCES);
04693 return 1;
04694 }
04695 QUALITY = drms_getkey_int(recLev1p->records[0],QUALITYS,&status);
04696 if(status != DRMS_SUCCESS)
04697 {
04698 printf("Error: cannot read the keyword %s\n",QUALITYS);
04699 return 1;
04700 }
04701
04702 CALVER64 = drms_getkey_longlong(recLev1p->records[0],CALVER64S,&status);
04703 if(status != DRMS_SUCCESS)
04704 {
04705 printf("Error: cannot read the keyword %s\n",CALVER64S);
04706 return 1;
04707 }
04708 if(inSmoothTables == 1) CALVER64 = CALVER64 | CALVER_SMOOTH;
04709
04710 Segments1p=0;
04711
04712 }
04713 else
04714 {
04715 printf("Unable to open the series %s, or no record found, for time %s\n",HMISeries,timeBegin2);
04716 if(status == DRMS_SUCCESS) QUALITY = QUALITY | QUAL_MISSINGLEV1P;
04717 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04718 }
04719 }
04720
04721
04722
04723
04724
04725
04726
04727
04728
04729
04730
04731
04732
04733
04734
04735
04736 if (Lev1pWanted == 1 || (Lev15Wanted == 1 && TestLevIn[2]!=1))
04737 {
04738
04739
04740 printf("PRODUCING LEVEL 1P RECORDS\n");
04741
04742 int ActualnSegs1d=0;
04743
04744
04745
04746 if(Segments1d == 0)
04747 {
04748 printf("READING THE LEVEL 1d DATA SEGMENTS\n");
04749
04750
04751 statusA[0]=1;
04752 i=0;
04753 while(statusA[0] != DRMS_SUCCESS)
04754 {
04755 TargetHFLID = drms_getkey_int(recLev1d->records[i],HFLIDS,&statusA[0]);
04756 if(i < nRecs1d-1) ++i;
04757 else break;
04758 }
04759 statusA[1]=1;
04760 i=0;
04761 while(statusA[1] != DRMS_SUCCESS)
04762 {
04763 TargetHPLTID = drms_getkey_int(recLev1d->records[i],HPLTIDS,&statusA[1]);
04764 if(i < nRecs1d-1) ++i;
04765 else break;
04766 }
04767 statusA[2]=1;
04768 i=0;
04769 while(statusA[2] != DRMS_SUCCESS)
04770 {
04771 TargetHWLTID = drms_getkey_int(recLev1d->records[i],HWLTIDS,&statusA[2]);
04772 if(i < nRecs1d-1) ++i;
04773 else break;
04774 }
04775 statusA[3]=1;
04776 i=0;
04777 while(statusA[3] != DRMS_SUCCESS)
04778 {
04779 WavelengthID2 = drms_getkey_int(recLev1d->records[i],WavelengthIDS,&statusA[3]);
04780 if(i < nRecs1d-1) ++i;
04781 else break;
04782 }
04783 if(WavelengthID2 != WavelengthID)
04784 {
04785 printf("Error: WavelengthID2 != WavelengthID\n");
04786 return 1;
04787 }
04788
04789
04790 if( (statusA[0]+statusA[1]+statusA[2]+statusA[3]) != 0)
04791 {
04792 printf("Error: some needed keywords cannot be read on level 1d data at target time %s\n",timeBegin2);
04793 Segments1d = 0;
04794 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1D;
04795 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04796 }
04797 else
04798 {
04799 framelistSize = framelistInfo(TargetHFLID,TargetHPLTID,TargetHWLTID,WavelengthID,PHWPLPOS,WavelengthIndex,WavelengthLocation,&PolarizationType,CamId,&combine,&npol,MaxNumFiltergrams,&CadenceRead,CameraValues,FIDValues,dpath);
04800 if(framelistSize == 1) return 1;
04801 }
04802
04803 if(framelistSize != nRecs1d)
04804 {
04805 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);
04806 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1D;
04807 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04808 }
04809
04810 ActualnSegs1d=nRecs1d;
04811
04812 arrLev1d = (DRMS_Array_t **)malloc(nRecs1d*sizeof(DRMS_Array_t *));
04813 if(arrLev1d == NULL)
04814 {
04815 printf("Error: memory could not be allocated to arrLev1d\n");
04816 return 1;
04817 }
04818
04819 for(i=0;i<nRecs1d;++i)
04820 {
04821
04822
04823
04824
04825
04826
04827
04828
04829 if(recLev1d->records[i] != NULL)
04830 {
04831 segin = drms_segment_lookupnum(recLev1d->records[i], 0);
04832 arrLev1d[i] = drms_segment_read(segin,type1d,&status);
04833 if(status != DRMS_SUCCESS || arrLev1d[i] == NULL)
04834 {
04835 printf("Error: could not read the segment for level 1d data index %d at target time %s \n",i,timeBegin2);
04836 arrLev1d[i] = NULL;
04837 ActualnSegs1d-=1;
04838 }
04839 }
04840 else
04841 {
04842 arrLev1d[i] = NULL;
04843 ActualnSegs1d-=1;
04844 }
04845 }
04846
04847 Segments1d = 1;
04848 }
04849 else
04850 {
04851 ActualnSegs1d=nRecs1d;
04852 for(i=0;i<nRecs1d;++i)
04853 {
04854 if(arrLev1d[i] == NULL) ActualnSegs1d-=1;
04855 }
04856 }
04857
04858
04859
04860
04861
04862
04863 if(ActualnSegs1d != framelistSize)
04864 {
04865 printf("Error: some records for the level 1d filtergrams are missing to produce level 1p data at target time %s\n",timeBegin2);
04866 Segments1d=0;
04867 QUALITY = QUALITY | QUAL_MISSINGLEV1D;
04868 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
04869 }
04870
04871
04872
04873
04874
04875 if(PolarizationType ==3)
04876 {
04877 nRecs1p=ActualnSegs1d/2;
04878 npolout=2;
04879 nSegs1p=npolout*nRecs1p;
04880 Lev1pOffset=40;
04881 if (Lev1pWanted) recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pb,DRMS_PERMANENT,&status);
04882 else recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pb,DRMS_TRANSIENT,&status);
04883 }
04884 if(PolarizationType ==2)
04885 {
04886 nRecs1p=ActualnSegs1d/4;
04887 npolout=2;
04888 nSegs1p=npolout*nRecs1p;
04889 Lev1pOffset=40;
04890 if (Lev1pWanted) recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pb,DRMS_PERMANENT,&status);
04891 else recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pb,DRMS_TRANSIENT,&status);
04892 }
04893 if(PolarizationType ==1)
04894 {
04895 nRecs1p=ActualnSegs1d/npol;
04896 npolout=4;
04897 nSegs1p=npolout*nRecs1p;
04898 Lev1pOffset=0;
04899 if (Lev15Wanted)
04900 {
04901 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");
04902 Lev15Wanted = 0;
04903 }
04904 if (Lev1pWanted) recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pa,DRMS_PERMANENT,&status);
04905 else recLev1p = drms_create_records(drms_env,1,HMISeriesLev1pa,DRMS_TRANSIENT,&status);
04906 }
04907
04908 if (status != DRMS_SUCCESS || recLev1p == NULL)
04909 {
04910 printf("Could not create a record for the level 1p series at target time %s\n",timeBegin2);
04911
04912
04913
04914 return 1;
04915 }
04916
04917
04918
04919
04920 arrLev1p = (DRMS_Array_t **)malloc(nSegs1p*sizeof(DRMS_Array_t *));
04921 if(arrLev1p == NULL)
04922 {
04923 printf("Error: memory could not be allocated to arrLev1p\n");
04924 return 1;
04925 }
04926
04927 for(i=0;i<nSegs1p;++i)
04928 {
04929 arrLev1p[i] = drms_array_create(type1p,2,axisout,NULL,&status);
04930 if(status != DRMS_SUCCESS || arrLev1p[i] == NULL)
04931 {
04932 printf("Error: cannot create an array for a level 1p data at target time %s\n",timeBegin2);
04933
04934
04935
04936
04937
04938
04939
04940
04941
04942
04943
04944
04945 return 1;
04946 }
04947 }
04948
04949 images = (float **)malloc(npol*sizeof(float *));
04950 if(images == NULL)
04951 {
04952 printf("Error: memory could not be allocated to images\n");
04953 return 1;
04954 }
04955
04956 imagesout = (float **)malloc(npolout*sizeof(float *));
04957 if(imagesout == NULL)
04958 {
04959 printf("Error: memory could not be allocated to imagesout\n");
04960 return 1;
04961 }
04962
04963 ps1 = (int *)malloc(npol*sizeof(int *));
04964 if(ps1 == NULL)
04965 {
04966 printf("Error: memory could not be allocated to ps1\n");
04967 return 1;
04968 }
04969 ps2 = (int *)malloc(npol*sizeof(int *));
04970 if(ps2 == NULL)
04971 {
04972 printf("Error: memory could not be allocated to ps2\n");
04973 return 1;
04974 }
04975 ps3 = (int *)malloc(npol*sizeof(int *));
04976 if(ps3 == NULL)
04977 {
04978 printf("Error: memory could not be allocated to ps3\n");
04979 return 1;
04980 }
04981
04982 fid = (int *)malloc(nRecs1d*sizeof(int *));
04983 if(fid == NULL)
04984 {
04985 printf("Error: memory could not be allocated to fid\n");
04986 return 1;
04987 }
04988
04989 Wavelengths = (int *)malloc(nRecs1p*sizeof(int *));
04990 if(Wavelengths == NULL)
04991 {
04992 printf("Error: memory could not be allocated to Wavelengths\n");
04993 return 1;
04994 }
04995
04996
04997
04998 printf("Looking for available level 1d arrays. Number expected: %d\n",nRecs1d);
04999 ii=0;
05000 for(i=0;i<nRecs1d;++i)
05001 {
05002 if (arrLev1d[i] != NULL)
05003 {
05004 fid[i]=drms_getkey_int(recLev1d->records[i],FIDS,&status);
05005 if( status != 0)
05006 {
05007 printf("Error: unable to read the keyword fid in a level 1d record\n");
05008 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1D;
05009 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
05010 }
05011 printf("FID of lev1d data: %d\n",fid[i]);
05012 if(i == 0) Wavelengths[0]=WhichWavelength(fid[0]);
05013 temp=0;
05014 for(k=0;k<=ii;++k) if(WhichWavelength(fid[i]) == Wavelengths[k]) temp=1;
05015 if(temp == 0)
05016 {
05017 ii+=1;
05018 Wavelengths[ii]=WhichWavelength(fid[i]);
05019 }
05020 }
05021 else
05022 {
05023 printf("Error: wavelength index %d is missing\n",i);
05024 QUALITY = QUALITY | QUAL_MISSINGLEV1D;
05025 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
05026 }
05027 }
05028
05029 if(ii+1 != nRecs1p)
05030 {
05031 printf("Error: the number of wavelengths in level 1d data: %d; is not what it should be: %d\n",ii+1,nRecs1p);
05032 QUALITY = QUALITY | QUAL_WRONGWAVELENGTHNUM;
05033 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
05034 }
05035
05036
05037 if(QuickLook == 1)
05038 {
05039 TSEL=20.;
05040 TFRONT=20.;
05041 }
05042 else
05043 {
05044
05045 strcpy(HMISeriesTemp,HMISeriesTemperature);
05046 strcat(HMISeriesTemp,"[");
05047 strcat(HMISeriesTemp,timeBegin2);
05048 strcat(HMISeriesTemp,"]");
05049 rectemp=NULL;
05050 rectemp = drms_open_records(drms_env,HMISeriesTemp,&statusA[0]);
05051 printf("TEMPERATURE QUERY = %s\n",HMISeriesTemp);
05052 if(statusA[0] == DRMS_SUCCESS && rectemp != NULL && rectemp->n != 0) TSEL=drms_getkey_float(rectemp->records[0],TS08,&status);
05053 else status = 1;
05054 if(status != DRMS_SUCCESS || isnan(TSEL))
05055 {
05056 printf("Error: the temperature keyword %s could not be read\n",TS08);
05057 QUALITY = QUALITY | QUAL_NOTEMP;
05058 TSEL=20.;
05059 }
05060 statusA[1]=1;
05061 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;
05062 if(statusA[0] != DRMS_SUCCESS || statusA[1] != DRMS_SUCCESS || isnan(TFRONT))
05063 {
05064 printf("Error: temperature keyword %s and/or %s could not be read\n",TS01,TS02);
05065 QUALITY = QUALITY | QUAL_NOTEMP;
05066 TFRONT=20.;
05067 }
05068 printf("TEMPERATURES = %f %f\n",TSEL,TFRONT);
05069 if(rectemp != NULL)
05070 {
05071 drms_close_records(rectemp,DRMS_FREE_RECORD);
05072 rectemp=NULL;
05073 }
05074 }
05075
05076 printf("WAVELENGTH ORDER = ");
05077 for(i=0;i<nRecs1p;++i) printf(" %d ",Wavelengths[i]);
05078 printf("\n");
05079
05080 printf("CALIBRATION OF POLARIZATION AND SORTING OF THE IMAGES IN THE ORDER I0, I1, I2, I3, I4... \n");
05081
05082 for(k=0;k<nRecs1p;++k)
05083 {
05084
05085 i=0;
05086 for(ii=0;ii<nRecs1d;++ii) if (WhichWavelength(fid[ii]) == k)
05087 {
05088 printf("wavelength=%d, polarization %d\n",k,i);
05089 images[i]=arrLev1d[ii]->data;
05090 ps1[i]=drms_getkey_int(recLev1d->records[ii],HPL1POSS,&statusA[0]);
05091 ps2[i]=drms_getkey_int(recLev1d->records[ii],HPL2POSS,&statusA[1]);
05092 ps3[i]=drms_getkey_int(recLev1d->records[ii],HPL3POSS,&statusA[2]);
05093 printf("Polarization settings: %d %d %d %f %f %d %d\n",ps1[i],ps2[i],ps3[i],TSEL,TFRONT,npolout,PolarizationType);
05094 if( (statusA[0]+statusA[1]+statusA[2]) != 0)
05095 {
05096 printf("Error: unable to read one or several keyword(s) in level 1d data\n");
05097 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1D;
05098 if(Lev15Wanted) CreateEmptyRecord=1; goto NextTargetTime;
05099 }
05100 i+=1;
05101 }
05102
05103 for(i=0;i<npolout;++i) imagesout[i]=arrLev1p[k*npolout+i]->data;
05104
05105
05106
05107
05108
05109 printf("Producing level 1p data\n");
05110 t0=dsecnd();
05111 polcal(&pars,npol,PolarizationType,images,imagesout,ps1,ps2,ps3,TSEL,TFRONT,axisout[0],axisout[1],axisout[1]);
05112 t1=dsecnd();
05113 printf("TIME ELAPSED IN POLCAL: %f\n",t1-t0);
05114
05115
05116
05117
05118 if(Lev1pWanted)
05119 {
05120 t0=dsecnd();
05121 for(i=0;i<npolout;++i)
05122 {
05123 segout = drms_segment_lookup(recLev1p->records[0],Lev1pSegName[i+Lev1pOffset+k*npolout]);
05124 arrLev1p[k*npolout+i]->bzero=segout->bzero;
05125 arrLev1p[k*npolout+i]->bscale=segout->bscale;
05126 arrLev1p[k*npolout+i]->israw=0;
05127 status=drms_segment_write(segout,arrLev1p[k*npolout+i], 0);
05128 if(status != DRMS_SUCCESS)
05129 {
05130 printf("Error: a call to drms_segment_write failed\n");
05131 return 1;
05132 }
05133 }
05134 t1=dsecnd();
05135 printf("TIME ELAPSED TO WRITE THE LEVEL 1p SEGMENTS: %f\n",t1-t0);
05136 }
05137
05138 }
05139
05140
05141
05142
05143
05144 drms_copykeys(recLev1p->records[0],recLev1d->records[0],0, kDRMS_KeyClass_Explicit);
05145
05146
05147 statusA[0] = drms_setkey_float(recLev1p->records[0] ,TFRONTS,TFRONT);
05148 statusA[1] = drms_setkey_float(recLev1p->records[0] ,TSELS,TSEL);
05149 statusA[2] = drms_setkey_int(recLev1p->records[0] ,POLCALMS,method);
05150 statusA[3] = drms_setkey_string(recLev1p->records[0],CODEVER3S,CODEVERSION3);
05151 DSUNOBSint = drms_getkey_double(recLev1d->records[0],DSUNOBSS,&status);
05152 if(status != DRMS_SUCCESS || isnan(DSUNOBSint))
05153 {
05154 printf("Error: %s keyword cannot be read on level 1d data at target time %s\n",DSUNOBSS,timeBegin2);
05155 statusA[4]=1;
05156 }
05157 else
05158 {
05159 ctime1=asin((double)solar_radius/DSUNOBSint)*180.*60.*60./M_PI;
05160 printf("RSUN_OBS = %f\n",ctime1);
05161 statusA[4] = drms_setkey_float(recLev1p->records[0],RSUNOBSS,ctime1);
05162 }
05163 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
05164 statusA[5]= drms_setkey_string(recLev1p->records[0],DATES,DATEOBS);
05165 strcat(source,"]");
05166 statusA[6]= drms_setkey_string(recLev1p->records[0],SOURCES,source);
05167 statusA[7]= drms_setkey_int(recLev1p->records[0],QUALLEV1S,QUALITYLEV1);
05168 statusA[8]= drms_setkey_int(recLev1p->records[0],TINTNUMS,totalTempIntNum);
05169
05170 TotalStatus=0;
05171 for(i=0;i<9;++i) TotalStatus+=statusA[i];
05172 if(TotalStatus != 0)
05173 {
05174 for(i=0;i<9;++i) printf(" %d ",statusA[i]);
05175 printf("\n");
05176 printf("WARNING: could not set some of the keywords for the level 1p data at target time %s\n",timeBegin2);
05177 }
05178
05179
05180
05181
05182 if(Lev1pWanted)
05183 {
05184
05185
05186 X0AVG = (float)drms_getkey_double(recLev1d->records[0],CRPIX1S,&status);
05187 if(status != DRMS_SUCCESS || isnan(X0AVG))
05188 {
05189 printf("Error: %s keyword cannot be read on level 1d data at target time %s\n",CRPIX1S,timeBegin2);
05190 }
05191 X0AVG=X0AVG-1;
05192 printf("X0AVG= %f\n",X0AVG);
05193
05194 Y0AVG = (float)drms_getkey_double(recLev1d->records[0],CRPIX2S,&status);
05195 if(status != DRMS_SUCCESS || isnan(Y0AVG))
05196 {
05197 printf("Error: %s keyword cannot be read on level 1d data at target time %s\n",CRPIX2S,timeBegin2);
05198 }
05199 Y0AVG=Y0AVG-1;
05200 printf("Y0AVG= %f\n",Y0AVG);
05201
05202
05203 for(k=0;k<nRecs1p;++k)
05204 {
05205 for(i=0;i<npolout;++i)
05206 {
05207 strcpy(TOTVALSSS[k*npolout+i],"TOTVALS[");
05208 sprintf(query,"%d",k*npolout+i);
05209 strcat(TOTVALSSS[k*npolout+i],query);
05210 strcat(TOTVALSSS[k*npolout+i],"]");
05211
05212 strcpy(MISSVALSSS[k*npolout+i],"MISSVALS[");
05213 sprintf(query,"%d",k*npolout+i);
05214 strcat(MISSVALSSS[k*npolout+i],query);
05215 strcat(MISSVALSSS[k*npolout+i],"]");
05216
05217 strcpy(DATAVALSSS[k*npolout+i],"DATAVALS[");
05218 sprintf(query,"%d",k*npolout+i);
05219 strcat(DATAVALSSS[k*npolout+i],query);
05220 strcat(DATAVALSSS[k*npolout+i],"]");
05221
05222 strcpy(DATAMEANSS[k*npolout+i],"DATAMEA2[");
05223 sprintf(query,"%d",k*npolout+i);
05224 strcat(DATAMEANSS[k*npolout+i],query);
05225 strcat(DATAMEANSS[k*npolout+i],"]");
05226
05227 strcpy(DATAMINSS[k*npolout+i],"DATAMIN2[");
05228 sprintf(query,"%d",k*npolout+i);
05229 strcat(DATAMINSS[k*npolout+i],query);
05230 strcat(DATAMINSS[k*npolout+i],"]");
05231
05232 strcpy(DATAMAXSS[k*npolout+i],"DATAMAX2[");
05233 sprintf(query,"%d",k*npolout+i);
05234 strcat(DATAMAXSS[k*npolout+i],query);
05235 strcat(DATAMAXSS[k*npolout+i],"]");
05236
05237 strcpy(DATAMEDNSS[k*npolout+i],"DATAMED2[");
05238 sprintf(query,"%d",k*npolout+i);
05239 strcat(DATAMEDNSS[k*npolout+i],query);
05240 strcat(DATAMEDNSS[k*npolout+i],"]");
05241
05242 strcpy(DATARMSSS[k*npolout+i],"DATARMS2[");
05243 sprintf(query,"%d",k*npolout+i);
05244 strcat(DATARMSSS[k*npolout+i],query);
05245 strcat(DATARMSSS[k*npolout+i],"]");
05246
05247 strcpy(DATASKEWSS[k*npolout+i],"DATASKE2[");
05248 sprintf(query,"%d",k*npolout+i);
05249 strcat(DATASKEWSS[k*npolout+i],query);
05250 strcat(DATASKEWSS[k*npolout+i],"]");
05251
05252 strcpy(DATAKURTSS[k*npolout+i],"DATAKUR2[");
05253 sprintf(query,"%d",k*npolout+i);
05254 strcat(DATAKURTSS[k*npolout+i],query);
05255 strcat(DATAKURTSS[k*npolout+i],"]");
05256
05257 strcpy(DATAMINS2S[k*npolout+i],"DATAMIN[");
05258 sprintf(query,"%d",k*npolout+i);
05259 strcat(DATAMINS2S[k*npolout+i],query);
05260 strcat(DATAMINS2S[k*npolout+i],"]");
05261
05262 strcpy(DATAMAXS2S[k*npolout+i],"DATAMAX[");
05263 sprintf(query,"%d",k*npolout+i);
05264 strcat(DATAMAXS2S[k*npolout+i],query);
05265 strcat(DATAMAXS2S[k*npolout+i],"]");
05266
05267 strcpy(DATAMEANS2S[k*npolout+i],"DATAMEAN[");
05268 sprintf(query,"%d",k*npolout+i);
05269 strcat(DATAMEANS2S[k*npolout+i],query);
05270 strcat(DATAMEANS2S[k*npolout+i],"]");
05271
05272 strcpy(DATAMEDNS2S[k*npolout+i],"DATAMEDN[");
05273 sprintf(query,"%d",k*npolout+i);
05274 strcat(DATAMEDNS2S[k*npolout+i],query);
05275 strcat(DATAMEDNS2S[k*npolout+i],"]");
05276
05277 strcpy(DATARMSS2S[k*npolout+i],"DATARMS[");
05278 sprintf(query,"%d",k*npolout+i);
05279 strcat(DATARMSS2S[k*npolout+i],query);
05280 strcat(DATARMSS2S[k*npolout+i],"]");
05281
05282 strcpy(DATASKEWS2S[k*npolout+i],"DATASKEW[");
05283 sprintf(query,"%d",k*npolout+i);
05284 strcat(DATASKEWS2S[k*npolout+i],query);
05285 strcat(DATASKEWS2S[k*npolout+i],"]");
05286
05287 strcpy(DATAKURTS2S[k*npolout+i],"DATAKURT[");
05288 sprintf(query,"%d",k*npolout+i);
05289 strcat(DATAKURTS2S[k*npolout+i],query);
05290 strcat(DATAKURTS2S[k*npolout+i],"]");
05291
05292 image=(float *)arrLev1p[k*npolout+i]->data;
05293
05294
05295 status=fstats(axisout[0]*axisout[1],image,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
05296 if(status != 0)
05297 {
05298 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
05299 }
05300 statusA[6]= drms_setkey_float(recLev1p->records[0],DATAMINSS[k*npolout+i],(float)minimum);
05301 statusA[7]= drms_setkey_float(recLev1p->records[0],DATAMAXSS[k*npolout+i],(float)maximum);
05302 statusA[8]= drms_setkey_float(recLev1p->records[0],DATAMEDNSS[k*npolout+i],(float)median);
05303 statusA[9]= drms_setkey_float(recLev1p->records[0],DATAMEANSS[k*npolout+i],(float)mean);
05304 statusA[10]= drms_setkey_float(recLev1p->records[0],DATARMSSS[k*npolout+i],(float)sigma);
05305 statusA[11]= drms_setkey_float(recLev1p->records[0],DATASKEWSS[k*npolout+i],(float)skewness);
05306 statusA[12]= drms_setkey_float(recLev1p->records[0],DATAKURTSS[k*npolout+i],(float)kurtosis);
05307 statusA[13]= drms_setkey_int(recLev1p->records[0],TOTVALSSS[k*npolout+i],axisout[0]*axisout[1]);
05308 statusA[14]= drms_setkey_int(recLev1p->records[0],DATAVALSSS[k*npolout+i],ngood);
05309 statusA[15]= drms_setkey_int(recLev1p->records[0],MISSVALSSS[k*npolout+i],axisout[0]*axisout[1]-ngood);
05310
05311 for(ii=0;ii<axisout[0]*axisout[1];++ii)
05312 {
05313 row =ii / axisout[0];
05314 column=ii % axisout[0];
05315 distance = sqrt(((float)row-Y0AVG)*((float)row-Y0AVG)+((float)column-X0AVG)*((float)column-X0AVG));
05316 if(distance > 0.99*RSUNint) image[ii]=NAN;
05317 }
05318
05319 status=fstats(axisout[0]*axisout[1],image,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
05320 if(status != 0)
05321 {
05322 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
05323 }
05324 statusA[16]= drms_setkey_float(recLev1p->records[0],DATAMINS2S[k*npolout+i],(float)minimum);
05325 statusA[17]= drms_setkey_float(recLev1p->records[0],DATAMAXS2S[k*npolout+i],(float)maximum);
05326 statusA[18]= drms_setkey_float(recLev1p->records[0],DATAMEDNS2S[k*npolout+i],(float)median);
05327 statusA[19]= drms_setkey_float(recLev1p->records[0],DATAMEANS2S[k*npolout+i],(float)mean);
05328 statusA[20]= drms_setkey_float(recLev1p->records[0],DATARMSS2S[k*npolout+i],(float)sigma);
05329 statusA[21]= drms_setkey_float(recLev1p->records[0],DATASKEWS2S[k*npolout+i],(float)skewness);
05330 statusA[22]= drms_setkey_float(recLev1p->records[0],DATAKURTS2S[k*npolout+i],(float)kurtosis);
05331
05332 TotalStatus=0;
05333 for(ii=6;ii<23;++ii) TotalStatus+=statusA[ii];
05334 if(TotalStatus != 0)
05335 {
05336 for(ii=6;ii<23;++ii) printf(" %d ",statusA[ii]);
05337 printf("\n");
05338 printf("WARNING: could not set some of the keywords for the level 1p data at target time %s\n",timeBegin2);
05339 }
05340
05341 }
05342 }
05343 }
05344
05345 Segments1p=1;
05346
05347 }
05348
05349
05350
05351
05352
05353
05354
05355
05356
05357
05358
05359
05360 if (Lev15Wanted)
05361 {
05362
05363
05364
05365
05366
05367 int ActualnSegs1p=nSegs1p;
05368
05369 if(Segments1p == 0)
05370 {
05371 if(PolarizationType ==2 || PolarizationType ==3) nSegs1p=nRecs1p*2;
05372 if(PolarizationType ==1) nSegs1p=nRecs1p*4;
05373
05374 arrLev1p = (DRMS_Array_t **)malloc(nSegs1p*sizeof(DRMS_Array_t *));
05375 if(arrLev1p == NULL)
05376 {
05377 printf("Error: memory could not be allocated to arrLev1p\n");
05378 return 1;
05379 }
05380
05381
05382
05383
05384
05385
05386
05387
05388
05389
05390 printf("READING %d DATA SEGMENTS OF LEVEL 1p RECORDS\n",nSegs1p);
05391 for(i=0;i<nSegs1p;++i)
05392 {
05393 printf("%d\n",i);
05394 segin = drms_segment_lookupnum(recLev1p->records[0],i);
05395 arrLev1p[i] = drms_segment_read(segin,type1p,&status);
05396 if(status != DRMS_SUCCESS || arrLev1p[i] == NULL)
05397 {
05398 printf("Error: could not read the segment for level 1p data index %d at target time %s \n",i,timeBegin2);
05399 arrLev1p[i] = NULL;
05400 ActualnSegs1p-=1;
05401 }
05402 }
05403
05404
05405
05406 if(PolarizationType == 1)
05407 {
05408 if(ActualnSegs1p != nSegs1p)
05409 {
05410 printf("Error: some level 1p data are missing to produce level 1.5 data: %d\n",ActualnSegs1p);
05411 QUALITY = QUALITY | QUAL_MISSINGLEV1P;
05412 CreateEmptyRecord=1; goto NextTargetTime;
05413 }
05414 else
05415 {
05416 printf("PRODUCING LCP+RCP FROM I,Q,U,V DATA\n");
05417 LCP=(float *)malloc(axisin[0]*axisin[1]*sizeof(float));
05418 RCP=(float *)malloc(axisin[0]*axisin[1]*sizeof(float));
05419 if(LCP == NULL || RCP == NULL)
05420 {
05421 printf("Error: could not create LCP and/or RCP array \n");
05422 return 1;
05423 }
05424 j=0;
05425 for (i=0;i<nRecs1p;++i)
05426 {
05427 temparr1=(float *)arrLev1p[i*4]->data;
05428 temparr2=(float *)arrLev1p[i*4+3]->data;
05429 temparr3=(float *)arrLev1p[j*2]->data;
05430 temparr4=(float *)arrLev1p[j*2+1]->data;
05431 for(ii=0;ii<axisin[0]*axisin[1];++ii)
05432 {
05433 LCP[ii]=temparr1[ii]+temparr2[ii];
05434 RCP[ii]=temparr1[ii]-temparr2[ii];
05435 temparr3[ii]=LCP[ii];
05436 temparr4[ii]=RCP[ii];
05437 }
05438 j+=1;
05439 }
05440 free(LCP);
05441 free(RCP);
05442 LCP=NULL;
05443 RCP=NULL;
05444 PolarizationType=3;
05445 nSegs1p=nRecs1p*2;
05446 ActualnSegs1p = nSegs1p;
05447 for(i=nSegs1p;i<nRecs1p*4;++i) if(arrLev1p[i] != NULL)
05448 {
05449 drms_free_array(arrLev1p[i]);
05450 arrLev1p[i]=NULL;
05451 }
05452 }
05453 }
05454
05455 printf("READING DONE\n");
05456
05457
05458 TargetHFLID = drms_getkey_int(recLev1p->records[0],HFLIDS,&status);
05459 if(status != DRMS_SUCCESS)
05460 {
05461 printf("Error: HFLID keyword cannot be read on level 1p data at target time %s\n",timeBegin2);
05462 CreateEmptyRecord=1; goto NextTargetTime;
05463 }
05464 TargetHPLTID = drms_getkey_int(recLev1p->records[0],HPLTIDS,&status);
05465 if(status != DRMS_SUCCESS)
05466 {
05467 printf("Error: HPLTID keyword cannot be read on level 1p data at target time %s\n",timeBegin2);
05468 CreateEmptyRecord=1; goto NextTargetTime;
05469 }
05470 TargetHWLTID = drms_getkey_int(recLev1p->records[0],HWLTIDS,&status);
05471 if(status != DRMS_SUCCESS)
05472 {
05473 printf("Error: HWLTID keyword cannot be read on level 1p data at target time %s\n",timeBegin2);
05474 CreateEmptyRecord=1; goto NextTargetTime;
05475 }
05476 WavelengthID2 = drms_getkey_int(recLev1p->records[0],WavelengthIDS,&status);
05477 if(status != DRMS_SUCCESS)
05478 {
05479 printf("Error: WavelengthID2 keyword cannot be read on level 1p data at target time %s\n",timeBegin2);
05480 CreateEmptyRecord=1; goto NextTargetTime;
05481 }
05482 if(WavelengthID2 != WavelengthID)
05483 {
05484 printf("Error: WavelengthID2 != WavelengthID\n");
05485 return 1;
05486 }
05487
05488 Segments1p=1;
05489 framelistSize = framelistInfo(TargetHFLID,TargetHPLTID,TargetHWLTID,WavelengthID,PHWPLPOS,WavelengthIndex,WavelengthLocation,&PolarizationType,CamId,&combine,&npol,MaxNumFiltergrams,&CadenceRead,CameraValues,FIDValues,dpath);
05490 if(framelistSize == 1) return 1;
05491 }
05492
05493
05494
05495
05496 if(ActualnSegs1p != nSegs1p)
05497 {
05498 printf("Error: some level 1p data are missing to produce level 1.5 data: %d\n",ActualnSegs1p);
05499 QUALITY = QUALITY | QUAL_MISSINGLEV1P;
05500 CreateEmptyRecord=1; goto NextTargetTime;
05501 }
05502
05503
05504
05505
05506 i=0;
05507 while(WavelengthIndex[i] != 2) i++;
05508 int HCMNBT,HCMWBT,HCMPOLT,HCME1T;
05509
05510 if( (framelistSize/npol == 6) || (framelistSize/npol == 8) || (framelistSize/npol == 10) )
05511 {
05512 HCMNBT = PHWPLPOS[7*i+3]+12;
05513 HCMWBT = PHWPLPOS[7*i+1]+6;
05514 HCMPOLT= PHWPLPOS[7*i+2];
05515 HCME1T = PHWPLPOS[7*i+0]-3;
05516 }
05517 if(framelistSize/npol == 5)
05518 {
05519 HCMNBT = PHWPLPOS[7*i+3];
05520 HCMWBT = PHWPLPOS[7*i+1];
05521 HCMPOLT= PHWPLPOS[7*i+2];
05522 HCME1T = PHWPLPOS[7*i+0];
05523 }
05524 printf("KEYWORD VALUES: %d %d %d %d\n",HCMNBT,HCMWBT,HCME1T,HCMPOLT);
05525
05526 char keylist[]="HWL4POS,HWL3POS,HWL2POS,HWL1POS,NWL,HCAMID,FSN_REC";
05527 int unique=0;
05528 int n0,n1;
05529
05530 int NBC,WBC,E1C,POLC,NC,CAMERAUSED,FSNLOOKUP;
05531
05532 arrayL0 = drms_record_getvector(drms_env,HMISeriesLookup, keylist, typeLO, unique, &status);
05533 if(status != DRMS_SUCCESS)
05534 {
05535 printf("Error: cannot read a list of keywords in the look-up table series\n");
05536 QUALITY = QUALITY | QUAL_NOLOOKUPKEYWORD;
05537 CreateEmptyRecord=1; goto NextTargetTime;
05538 }
05539 printf("DIMENSIONS= %d %d\n",arrayL0->axis[0],arrayL0->axis[1]);
05540 keyL=arrayL0->data;
05541 arrayL1 = drms_record_getvector(drms_env,HMISeriesLookup,TRECS,DRMS_TYPE_DOUBLE , unique, &status);
05542 if(status != DRMS_SUCCESS)
05543 {
05544 printf("Error: cannot read a list of keywords in the look-up table series\n");
05545 QUALITY = QUALITY | QUAL_NOLOOKUPKEYWORD;
05546 CreateEmptyRecord=1; goto NextTargetTime;
05547 }
05548
05549 timeL=arrayL1->data;
05550
05551 n1=arrayL0->axis[1];
05552 n0=arrayL0->axis[0];
05553 if(n1 != arrayL1->axis[1])
05554 {
05555 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");
05556 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05557 CreateEmptyRecord=1; goto NextTargetTime;
05558 }
05559 printf("%d RECORDS FOUND FOR THE LOOK-UP TABLES\n",n1);
05560
05561 count = (double *)malloc(n1*sizeof(double));
05562 if(count == NULL)
05563 {
05564 printf("Error: memory could not be allocated to count\n");
05565 return 1;
05566 }
05567
05568 temptime = 1000000000.0;
05569 temp = 0;
05570
05571 for(i=0;i<n1;++i)
05572 {
05573 count[i] = fabs(timeL[i]-TargetTime);
05574 NBC = abs(keyL[ i]-HCMNBT);
05575 POLC= abs(keyL[ n1+i]-HCMPOLT);
05576 WBC = abs(keyL[2*n1+i]-HCMWBT);
05577 E1C = abs(keyL[3*n1+i]-HCME1T);
05578 NC = abs(keyL[4*n1+i]-framelistSize/npol);
05579 CAMERAUSED = abs(keyL[5*n1+i]-CamId);
05580 if(count[i] < temptime && NBC+WBC+POLC+E1C+NC+CAMERAUSED == 0)
05581 {
05582 temptime=count[i];
05583 temp=i;
05584 }
05585 }
05586 if(temptime == 1000000000.0)
05587 {
05588 printf("Error: could not find a look-up table with the correct keywords to produce level 1.5 data\n");
05589 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05590 CreateEmptyRecord=1; goto NextTargetTime;
05591 }
05592
05593 printf("Index of the retrieved look-up table %d %d\n",temp,n1);
05594 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]);
05595 FSNLOOKUP = keyL[6*n1+temp];
05596
05597
05598 sprintf(query,"%d",FSNLOOKUP);
05599 strcpy(HMILookup,HMISeriesLookup);
05600 strcat(HMILookup,"[");
05601 strcat(HMILookup,query);
05602 strcat(HMILookup,"][][");
05603 if(CamId == 0) strcat(HMILookup,"0");
05604 if(CamId == 1) strcat(HMILookup,"1");
05605 if(CamId == 2) strcat(HMILookup,"2");
05606 if(CamId == 3) strcat(HMILookup,"3");
05607 strcat(HMILookup,"][");
05608 sprintf(query,"%d",HCME1T);
05609 strcat(HMILookup,query);
05610 strcat(HMILookup,"][");
05611 sprintf(query,"%d",HCMWBT);
05612 strcat(HMILookup,query);
05613 strcat(HMILookup,"][");
05614 sprintf(query,"%d",HCMPOLT);
05615 strcat(HMILookup,query);
05616 strcat(HMILookup,"][");
05617 sprintf(query,"%d",HCMNBT);
05618 strcat(HMILookup,query);
05619 strcat(HMILookup,"][");
05620 NC=framelistSize/npol;
05621 sprintf(query,"%d",NC);
05622 strcat(HMILookup,query);
05623 strcat(HMILookup,"]");
05624
05625 printf("QUERY= %s\n",HMILookup);
05626
05627 drms_free_array(arrayL0);
05628 arrayL0=NULL;
05629 drms_free_array(arrayL1);
05630 arrayL1=NULL;
05631 free(count);
05632 count=NULL;
05633
05634 lookup = drms_open_records(drms_env,HMILookup,&status);
05635 if (status == DRMS_SUCCESS && lookup != NULL)
05636 {
05637 if (lookup->n > 1)
05638 {
05639 printf("Error: more than 1 lookup table record was downloaded.\n");
05640 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05641 CreateEmptyRecord=1; goto NextTargetTime;
05642 }
05643 if (lookup->n <= 0)
05644 {
05645 printf("Error:no record for the look-up tables were downloaded.\n");
05646 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05647 CreateEmptyRecord=1; goto NextTargetTime;
05648 }
05649 }
05650 else
05651 {
05652 printf("Error: can't open the look-up table series.\n");
05653 QUALITY = QUALITY | QUAL_NOLOOKUPRECORD;
05654 CreateEmptyRecord=1; goto NextTargetTime;
05655 }
05656
05657 segin = drms_segment_lookupnum(lookup->records[0], 0);
05658 arrintable= drms_segment_read(segin, segin->info->type, &status);
05659 if (status != DRMS_SUCCESS || arrintable == NULL)
05660 {
05661 printf("Error: unable to read the data segment of the look-up table record\n");
05662 return 1;
05663
05664
05665 }
05666 else printf("look-up table record read\n");
05667
05668
05669
05670
05671
05672 int FSNDIFF;
05673 char keylistCoeff[]="COEFF0,COEFF1,COEFF2,COEFF3";
05674
05675 arrayL0 = drms_record_getvector(drms_env,HMISeriesCoeffs, keylistCoeff, DRMS_TYPE_DOUBLE, unique, &status);
05676 if(status != DRMS_SUCCESS)
05677 {
05678 printf("Error: cannot read a list of keywords in the polynomial coefficient series\n");
05679 QUALITY = QUALITY | QUAL_NOCOEFFKEYWORD;
05680 CreateEmptyRecord=1; goto NextTargetTime;
05681 }
05682 TIME *keyt=NULL;
05683 keyt=arrayL0->data;
05684
05685 arrayL1 = drms_record_getvector(drms_env,HMISeriesCoeffs,TRECS,DRMS_TYPE_DOUBLE, unique, &status);
05686 if(status != DRMS_SUCCESS)
05687 {
05688 printf("Error: cannot read a list of keywords in the polynomial coefficient series\n");
05689 QUALITY = QUALITY | QUAL_NOCOEFFKEYWORD;
05690 CreateEmptyRecord=1; goto NextTargetTime;
05691 }
05692 timeL=arrayL1->data;
05693
05694 arrayL2 = drms_record_getvector(drms_env,HMISeriesCoeffs,CALFSNS,DRMS_TYPE_INT, unique, &status);
05695 if(status != DRMS_SUCCESS)
05696 {
05697 printf("Error: cannot read a list of keywords in the polynomial coefficient series\n");
05698 QUALITY = QUALITY | QUAL_NOCOEFFKEYWORD;
05699 CreateEmptyRecord=1; goto NextTargetTime;
05700 }
05701 FSNL=arrayL2->data;
05702
05703 n1=arrayL0->axis[1];
05704 n0=arrayL0->axis[0];
05705 if(n1 != arrayL1->axis[1] || n1 != arrayL2->axis[1])
05706 {
05707 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");
05708 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05709 CreateEmptyRecord=1; goto NextTargetTime;
05710 }
05711 printf("%d RECORDS FOUND FOR THE POLYNOMIAL COEFFICIENTS\n",n1);
05712
05713 count = (double *)malloc(n1*sizeof(double));
05714 if(count == NULL)
05715 {
05716 printf("Error: memory could not be allocated to count\n");
05717 return 1;
05718 }
05719
05720
05721 if(QuickLook != 1)
05722 {
05723 temptime = 1000000000.0;
05724 temp = 0;
05725 temp2= 0;
05726
05727 for(i=0;i<n1;++i)
05728 {
05729 count[i] = fabs(timeL[i]-TargetTime);
05730 FSNDIFF = FSNL[i]-FSNLOOKUP;
05731 if(count[i] < temptime && FSNDIFF == 0 && timeL[i]<TargetTime)
05732 {
05733 temptime=count[i];
05734 temp=i;
05735 }
05736 }
05737 if(temptime > 86400.0)
05738 {
05739 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");
05740 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05741 CreateEmptyRecord=1; goto NextTargetTime;
05742 }
05743
05744 temptime = 1000000000.0;
05745
05746 for(i=0;i<n1;++i)
05747 {
05748 count[i] = fabs(timeL[i]-TargetTime);
05749 FSNDIFF = FSNL[i]-FSNLOOKUP;
05750 if(count[i] < temptime && FSNDIFF == 0 && timeL[i]>=TargetTime)
05751 {
05752 temptime=count[i];
05753 temp2=i;
05754 }
05755 }
05756 if(temptime > 86400.0)
05757 {
05758 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");
05759 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05760 CreateEmptyRecord=1; goto NextTargetTime;
05761 }
05762
05763 }
05764 else
05765 {
05766
05767 temptime = 1000000000.0;
05768 temp = 0;
05769
05770 for(i=0;i<n1;++i)
05771 {
05772 count[i] = fabs(timeL[i]-TargetTime);
05773 if(count[i] < temptime)
05774 {
05775 temptime=count[i];
05776 temp=i;
05777 }
05778 }
05779 temp2=temp;
05780 }
05781
05782 printf("Indeces of the retrieved polynomial record %d %d %d\n",temp,temp2,n1);
05783 printf("Keyword values of the retrieved polynomial record: %d\n",FSNL[temp]-FSNLOOKUP);
05784
05785
05786 sprint_time(query,timeL[temp],"TAI",1);
05787 strcpy(HMICoeffs,HMISeriesCoeffs);
05788 strcat(HMICoeffs,"[");
05789 strcat(HMICoeffs,query);
05790 strcat(HMICoeffs,"]");
05791
05792 printf("QUERY= %s\n",HMICoeffs);
05793
05794 recpoly = drms_open_records(drms_env,HMICoeffs,&status);
05795 if (status == DRMS_SUCCESS && recpoly != NULL && recpoly->n != 0)
05796 {
05797 coeff[0]=drms_getkey_double(recpoly->records[0],COEFF0S,&status);
05798 if(status != DRMS_SUCCESS)
05799 {
05800 printf("Error: could not read a polynomial coefficient\n");
05801 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05802 CreateEmptyRecord=1; goto NextTargetTime;
05803 }
05804 coeff[1]=drms_getkey_double(recpoly->records[0],COEFF1S,&status);
05805 if(status != DRMS_SUCCESS)
05806 {
05807 printf("Error: could not read a polynomial coefficient\n");
05808 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05809 CreateEmptyRecord=1; goto NextTargetTime;
05810 }
05811 coeff[2]=drms_getkey_double(recpoly->records[0],COEFF2S,&status);
05812 if(status != DRMS_SUCCESS)
05813 {
05814 printf("Error: could not read a polynomial coefficient\n");
05815 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05816 CreateEmptyRecord=1; goto NextTargetTime;
05817 }
05818 coeff[3]=drms_getkey_double(recpoly->records[0],COEFF3S,&status);
05819 if(status != DRMS_SUCCESS)
05820 {
05821 printf("Error: could not read a polynomial coefficient\n");
05822 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05823 CreateEmptyRecord=1; goto NextTargetTime;
05824 }
05825 }
05826 else
05827 {
05828 printf("Error: can't open the polynomial coefficients series.\n");
05829 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05830 CreateEmptyRecord=1; goto NextTargetTime;
05831 }
05832
05833
05834 if(QuickLook != 1)
05835 {
05836
05837 sprint_time(query,timeL[temp2],"TAI",1);
05838 strcpy(HMICoeffs,HMISeriesCoeffs);
05839 strcat(HMICoeffs,"[");
05840 strcat(HMICoeffs,query);
05841 strcat(HMICoeffs,"]");
05842
05843 printf("QUERY= %s\n",HMICoeffs);
05844
05845 recpoly2 = drms_open_records(drms_env,HMICoeffs,&status);
05846 if (status == DRMS_SUCCESS && recpoly2 != NULL && recpoly2->n != 0)
05847 {
05848 coeff2[0]=drms_getkey_double(recpoly2->records[0],COEFF0S,&status);
05849 if(status != DRMS_SUCCESS)
05850 {
05851 printf("Error: could not read a polynomial coefficient\n");
05852 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05853 CreateEmptyRecord=1; goto NextTargetTime;
05854 }
05855 coeff2[1]=drms_getkey_double(recpoly2->records[0],COEFF1S,&status);
05856 if(status != DRMS_SUCCESS)
05857 {
05858 printf("Error: could not read a polynomial coefficient\n");
05859 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05860 CreateEmptyRecord=1; goto NextTargetTime;
05861 }
05862 coeff2[2]=drms_getkey_double(recpoly2->records[0],COEFF2S,&status);
05863 if(status != DRMS_SUCCESS)
05864 {
05865 printf("Error: could not read a polynomial coefficient\n");
05866 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05867 CreateEmptyRecord=1; goto NextTargetTime;
05868 }
05869 coeff2[3]=drms_getkey_double(recpoly2->records[0],COEFF3S,&status);
05870 if(status != DRMS_SUCCESS)
05871 {
05872 printf("Error: could not read a polynomial coefficient\n");
05873 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05874 CreateEmptyRecord=1; goto NextTargetTime;
05875 }
05876 }
05877 else
05878 {
05879 printf("Error: can't open the polynomial coefficients series.\n");
05880 QUALITY = QUALITY | QUAL_NOCOEFFPRECORD;
05881 CreateEmptyRecord=1; goto NextTargetTime;
05882 }
05883 }
05884 else recpoly2 = NULL;
05885
05886
05887 printf("Polynomial coefficient values: %e %e %e %e\n",coeff[0],coeff[1],coeff[2],coeff[3]);
05888
05889 if(QuickLook != 1)
05890 {
05891 printf("Polynomial coefficient values: %e %e %e %e\n",coeff2[0],coeff2[1],coeff2[2],coeff2[3]);
05892 coeff[0]=(TargetTime-timeL[temp])*(coeff2[0]-coeff[0])/(timeL[temp2]-timeL[temp])+coeff[0];
05893 coeff[1]=(TargetTime-timeL[temp])*(coeff2[1]-coeff[1])/(timeL[temp2]-timeL[temp])+coeff[1];
05894 coeff[2]=(TargetTime-timeL[temp])*(coeff2[2]-coeff[2])/(timeL[temp2]-timeL[temp])+coeff[2];
05895 coeff[3]=(TargetTime-timeL[temp])*(coeff2[3]-coeff[3])/(timeL[temp2]-timeL[temp])+coeff[3];
05896 }
05897
05898
05899 drms_free_array(arrayL0);
05900 arrayL0=NULL;
05901 drms_free_array(arrayL1);
05902 arrayL1=NULL;
05903 drms_free_array(arrayL2);
05904 arrayL2=NULL;
05905 free(count);
05906 count=NULL;
05907
05908 strcpy(HISTORY,"Polynomial Coefficients used for Doppler velocity correction: ");
05909 sprintf(query,"%e",coeff[0]);
05910 strcat(HISTORY,query);
05911 strcat(HISTORY," ");
05912 sprintf(query,"%e",coeff[1]);
05913 strcat(HISTORY,query);
05914 strcat(HISTORY," ");
05915 sprintf(query,"%e",coeff[2]);
05916 strcat(HISTORY,query);
05917 strcat(HISTORY," ");
05918 sprintf(query,"%e",coeff[3]);
05919 strcat(HISTORY,query);
05920 strcat(HISTORY," ");
05921
05922
05923
05924
05925
05926 nRecs15 = 6;
05927
05928 recLev15a = drms_create_records(drms_env,1,HMISeriesLev15a,DRMS_PERMANENT,&statusA[0]);
05929 recLev15b = drms_create_records(drms_env,1,HMISeriesLev15b,DRMS_PERMANENT,&statusA[1]);
05930 recLev15c = drms_create_records(drms_env,1,HMISeriesLev15c,DRMS_PERMANENT,&statusA[2]);
05931 recLev15d = drms_create_records(drms_env,1,HMISeriesLev15d,DRMS_PERMANENT,&statusA[3]);
05932 recLev15e = drms_create_records(drms_env,1,HMISeriesLev15e,DRMS_PERMANENT,&statusA[4]);
05933 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);
05934
05935
05936 if ( (statusA[0]+statusA[1]+statusA[2]+statusA[3]+statusA[4]) != DRMS_SUCCESS || recLev15a == NULL || recLev15b == NULL || recLev15c == NULL|| recLev15d == NULL || recLev15e == NULL)
05937 {
05938 printf("Could not create a record for one or several level 1.5 data series, at target time %s\n",timeBegin2);
05939
05940
05941
05942
05943
05944
05945
05946 return 1;
05947 }
05948 if(recLev15a->n == 0 || recLev15b->n == 0 || recLev15c->n == 0 || recLev15d->n == 0 || recLev15e->n == 0)
05949 {
05950 printf("Could not create a record for one or several level 1.5 data series, at target time %s\n",timeBegin2);
05951
05952
05953
05954
05955
05956
05957
05958 return 1;
05959 }
05960
05961
05962 arrLev15 = (DRMS_Array_t **)malloc(nRecs15*sizeof(DRMS_Array_t *));
05963 if(arrLev15 == NULL)
05964 {
05965 printf("Error: memory could not be allocated to arrLev15\n");
05966 return 1;
05967 }
05968 for (i=0;i<nRecs15;++i)
05969 {
05970 arrLev15[i] = drms_array_create(type15,2,axisout,NULL,&status);
05971 if(status != DRMS_SUCCESS || arrLev15[i] == NULL)
05972 {
05973 printf("Error: cannot create an array for a level 1.5 data at target time %s\n",timeBegin2);
05974
05975
05976 return 1;
05977 }
05978
05979 }
05980
05981
05982
05983 X0AVG = (float)drms_getkey_double(recLev1p->records[0],CRPIX1S,&status);
05984 if(status != DRMS_SUCCESS || isnan(X0AVG))
05985 {
05986 printf("Error: %s keyword cannot be read on level 1p data at target time %s\n",CRPIX1S,timeBegin2);
05987 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1P;
05988 CreateEmptyRecord=1; goto NextTargetTime;
05989 }
05990 X0AVG=X0AVG-1;
05991
05992 Y0AVG = (float)drms_getkey_double(recLev1p->records[0],CRPIX2S,&status);
05993 if(status != DRMS_SUCCESS || isnan(Y0AVG))
05994 {
05995 printf("Error: %s keyword cannot be read on level 1p data at target time %s\n",CRPIX2S,timeBegin2);
05996 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1P;
05997 CreateEmptyRecord=1; goto NextTargetTime;
05998 }
05999 Y0AVG=Y0AVG-1;
06000
06001 DSUNOBSint = drms_getkey_double(recLev1p->records[0],DSUNOBSS,&status);
06002 if(status != DRMS_SUCCESS || isnan(DSUNOBSint))
06003 {
06004 printf("Error: %s keyword cannot be read on level 1p data at target time %s\n",DSUNOBSS,timeBegin2);
06005 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1P;
06006 CreateEmptyRecord=1; goto NextTargetTime;
06007 }
06008
06009 cdelt1 = (float)drms_getkey_double(recLev1p->records[0],CDELT1S,&status);
06010 if(status != DRMS_SUCCESS || isnan(cdelt1))
06011 {
06012 printf("Error: %s keyword cannot be read on level 1p data at target time %s\n",CDELT1S,timeBegin2);
06013 QUALITY = QUALITY | QUAL_MISSINGKEYWORDLEV1P;
06014 CreateEmptyRecord=1; goto NextTargetTime;
06015 }
06016
06017
06018
06019
06020
06021
06022
06023
06024
06025
06026 RSUNint=1.0/cdelt1*asin((double)solar_radius/DSUNOBSint)*180.*60.*60./M_PI;
06027
06028
06029 DopplerParameters.FSRNB=FSR[0];
06030 DopplerParameters.FSRWB=FSR[1];
06031 DopplerParameters.FSRE1=FSR[2];
06032 DopplerParameters.FSRE2=FSR[3];
06033 DopplerParameters.FSRE3=FSR[4];
06034 DopplerParameters.FSRE4=FSR[5];
06035 DopplerParameters.FSRE5=FSR[6];
06036 DopplerParameters.dlamdv=dlamdv;
06037 DopplerParameters.maxVtest=ntest*2;
06038 DopplerParameters.maxNx=maxNx;
06039 DopplerParameters.ntest=ntest;
06040 DopplerParameters.dvtest=dvtest;
06041 DopplerParameters.MISSINGDATA=MISSINGDATA;
06042 DopplerParameters.MISSINGRESULT=MISSINGRESULT;
06043 DopplerParameters.coeff0=coeff[0];
06044 DopplerParameters.coeff1=coeff[1];
06045 DopplerParameters.coeff2=coeff[2];
06046 DopplerParameters.coeff3=coeff[3];
06047 DopplerParameters.QuickLook=QuickLook;
06048
06049 if(framelistSize/2 == 10 || framelistSize/2 == 8 || framelistSize/2 == 20)
06050 {
06051 ntest=1333;
06052 DopplerParameters.maxVtest=ntest*2;
06053 DopplerParameters.ntest=ntest;
06054 }
06055
06056 t0=dsecnd();
06057
06058 Dopplergram_largercrop(arrLev1p,arrLev15,nSegs1p,arrintable,RSUNint,X0AVG,Y0AVG,DopplerParameters,MISSVALS,&SATVALS,cdelt1,TargetTime);
06059
06060 t1=dsecnd();
06061 printf("TIME ELAPSED IN DOPPLERGRAM(): %f\n",t1-t0);
06062
06063 printf("KEYWORDS OF Dopplergram() %f %f %f\n",RSUNint,X0AVG,Y0AVG);
06064 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);
06065
06066
06067 t0=dsecnd();
06068 segout = drms_segment_lookupnum(recLev15a->records[0], 0);
06069 arrLev15[0]->bzero=segout->bzero;
06070 arrLev15[0]->bscale=segout->bscale;
06071 arrLev15[0]->israw=0;
06072 status=drms_segment_write(segout,arrLev15[0], 0);
06073 if(status != DRMS_SUCCESS)
06074 {
06075 printf("Error: a call to drms_segment_write failed\n");
06076 return 1;
06077 }
06078
06079 segout = drms_segment_lookupnum(recLev15b->records[0], 0);
06080 arrLev15[1]->bzero=segout->bzero;
06081 arrLev15[1]->bscale=segout->bscale;
06082 arrLev15[1]->israw=0;
06083 status=drms_segment_write(segout,arrLev15[1], 0);
06084 if(status != DRMS_SUCCESS)
06085 {
06086 printf("Error: a call to drms_segment_write failed\n");
06087 return 1;
06088 }
06089
06090 segout = drms_segment_lookupnum(recLev15c->records[0], 0);
06091 arrLev15[2]->bzero=segout->bzero;
06092 arrLev15[2]->bscale=segout->bscale;
06093 arrLev15[2]->israw=0;
06094 status=drms_segment_write(segout,arrLev15[2], 0);
06095 if(status != DRMS_SUCCESS)
06096 {
06097 printf("Error: a call to drms_segment_write failed\n");
06098 return 1;
06099 }
06100
06101 segout = drms_segment_lookupnum(recLev15d->records[0], 0);
06102 arrLev15[3]->bzero=segout->bzero;
06103 arrLev15[3]->bscale=segout->bscale;
06104 arrLev15[3]->israw=0;
06105 status=drms_segment_write(segout,arrLev15[3], 0);
06106 if(status != DRMS_SUCCESS)
06107 {
06108 printf("Error: a call to drms_segment_write failed\n");
06109 return 1;
06110 }
06111
06112 segout = drms_segment_lookupnum(recLev15e->records[0], 0);
06113 arrLev15[4]->bzero=segout->bzero;
06114 arrLev15[4]->bscale=segout->bscale;
06115 arrLev15[4]->israw=0;
06116 status=drms_segment_write(segout,arrLev15[4], 0);
06117 if(status != DRMS_SUCCESS)
06118 {
06119 printf("Error: a call to drms_segment_write failed\n");
06120 return 1;
06121 }
06122
06123 t1=dsecnd();
06124 printf("TIME ELAPSED TO WRITE THE LEVEL 1.5 SEGMENTS: %f\n",t1-t0);
06125
06126
06127
06128 image0=(float *)arrLev15[5]->data;
06129
06130 for(i=0;i<axisout[0]*axisout[1];++i)
06131 {
06132 row =i / axisout[0];
06133 column=i % axisout[0];
06134 distance = sqrt(((float)row-Y0AVG)*((float)row-Y0AVG)+((float)column-X0AVG)*((float)column-X0AVG));
06135 if(distance > 0.99*RSUNint)
06136 {
06137 image0[i]=NAN;
06138 }
06139 }
06140 status=fstats(axisout[0]*axisout[1],arrLev15[5]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06141 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06142 statusA[2]= drms_setkey_float(recLev15a->records[0],RAWMEDNS,(float)median);
06143 if(statusA[2] != 0)
06144 {
06145 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);
06146 }
06147
06148
06149
06150 t0=dsecnd();
06151 drms_copykeys(recLev15a->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06152
06153 status=fstats(axisout[0]*axisout[1],arrLev15[0]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06154 if(status != 0)
06155 {
06156 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06157 }
06158
06159 image=arrLev15[0]->data;
06160 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))
06161 {
06162 MISSVALS[0]+=1;
06163 ngood -= 1;
06164 }
06165
06166
06167
06168 statusA[0]= drms_setkey_int(recLev15a->records[0],TOTVALSS,ngood+MISSVALS[0]);
06169 statusA[1]= drms_setkey_int(recLev15a->records[0],DATAVALSS,ngood);
06170
06171 statusA[2]= drms_setkey_int(recLev15a->records[0],MISSVALSS,MISSVALS[0]);
06172 statusA[3]= drms_setkey_float(recLev15a->records[0],DATAMINS,(float)minimum);
06173 statusA[4]= drms_setkey_float(recLev15a->records[0],DATAMAXS,(float)maximum);
06174 statusA[5]= drms_setkey_float(recLev15a->records[0],DATAMEDNS,(float)median);
06175 statusA[6]= drms_setkey_float(recLev15a->records[0],DATAMEANS,(float)mean);
06176 statusA[7]= drms_setkey_float(recLev15a->records[0],DATARMSS,(float)sigma);
06177 statusA[8]= drms_setkey_float(recLev15a->records[0],DATASKEWS,(float)skewness);
06178 statusA[9]= drms_setkey_float(recLev15a->records[0],DATAKURTS,(float)kurtosis);
06179 statusA[10]=drms_setkey_int(recLev15a->records[0],CALFSNS,FSNLOOKUP);
06180 statusA[11]=drms_setkey_string(recLev15a->records[0],LUTQUERYS,HMILookup);
06181 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06182 statusA[12]= drms_setkey_string(recLev15a->records[0],DATES,DATEOBS);
06183 statusA[13]= drms_setkey_int(recLev15a->records[0],QUALITYS,QUALITY);
06184 statusA[14]= drms_setkey_int(recLev15a->records[0],SATVALSS,SATVALS);
06185 statusA[15]= drms_setkey_string(recLev15a->records[0],SOURCES,source);
06186 statusA[16]= drms_setkey_int(recLev15a->records[0],QUALLEV1S,QUALITYLEV1);
06187 statusA[17]= drms_setkey_string(recLev15a->records[0],COMMENTS,COMMENT);
06188 statusA[18]=0;
06189 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15a->records[0],CALVER64S,CALVER64);
06190
06191 TotalStatus=0;
06192 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06193 if(TotalStatus != 0)
06194 {
06195 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the Dopplergram at target time %s\n",timeBegin2);
06196 }
06197
06198
06199
06200 drms_copykeys(recLev15b->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06201
06202 status=fstats(axisout[0]*axisout[1],arrLev15[1]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06203 if(status != 0)
06204 {
06205 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06206 }
06207
06208 image=arrLev15[1]->data;
06209 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))
06210 {
06211 MISSVALS[1]+=1;
06212 ngood -= 1;
06213 }
06214
06215
06216 statusA[0]= drms_setkey_int(recLev15b->records[0],TOTVALSS,ngood+MISSVALS[1]);
06217 statusA[1]= drms_setkey_int(recLev15b->records[0],DATAVALSS,ngood);
06218 statusA[2]= drms_setkey_int(recLev15b->records[0],MISSVALSS,MISSVALS[1]);
06219 statusA[3]= drms_setkey_float(recLev15b->records[0],DATAMINS,(float)minimum);
06220 statusA[4]= drms_setkey_float(recLev15b->records[0],DATAMAXS,(float)maximum);
06221 statusA[5]= drms_setkey_float(recLev15b->records[0],DATAMEDNS,(float)median);
06222 statusA[6]= drms_setkey_float(recLev15b->records[0],DATAMEANS,(float)mean);
06223 statusA[7]= drms_setkey_float(recLev15b->records[0],DATARMSS,(float)sigma);
06224 statusA[8]= drms_setkey_float(recLev15b->records[0],DATASKEWS,(float)skewness);
06225 statusA[9]= drms_setkey_float(recLev15b->records[0],DATAKURTS,(float)kurtosis);
06226 statusA[10]=drms_setkey_int(recLev15b->records[0],CALFSNS,FSNLOOKUP);
06227 statusA[11]=drms_setkey_string(recLev15b->records[0],LUTQUERYS,HMILookup);
06228 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06229 statusA[12]= drms_setkey_string(recLev15b->records[0],DATES,DATEOBS);
06230 statusA[13]= drms_setkey_int(recLev15b->records[0],QUALITYS,QUALITY);
06231 statusA[14]= drms_setkey_int(recLev15b->records[0],SATVALSS,SATVALS);
06232 statusA[15]= drms_setkey_string(recLev15b->records[0],SOURCES,source);
06233 statusA[16]= drms_setkey_int(recLev15b->records[0],QUALLEV1S,QUALITYLEV1);
06234 statusA[17]= drms_setkey_string(recLev15b->records[0],COMMENTS,COMMENT);
06235 statusA[18]=0;
06236 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15b->records[0],CALVER64S,CALVER64);
06237
06238 TotalStatus=0;
06239 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06240 if(TotalStatus != 0)
06241 {
06242 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the magnetogram at target time %s\n",timeBegin2);
06243 }
06244
06245
06246
06247 drms_copykeys(recLev15c->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06248
06249 status=fstats(axisout[0]*axisout[1],arrLev15[2]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06250 if(status != 0)
06251 {
06252 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06253 }
06254
06255 image=arrLev15[2]->data;
06256 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))
06257 {
06258 MISSVALS[2]+=1;
06259 ngood -= 1;
06260 }
06261
06262
06263 statusA[0]= drms_setkey_int(recLev15c->records[0],TOTVALSS,ngood+MISSVALS[2]);
06264 statusA[1]= drms_setkey_int(recLev15c->records[0],DATAVALSS,ngood);
06265 statusA[2]= drms_setkey_int(recLev15c->records[0],MISSVALSS,MISSVALS[2]);
06266 statusA[3]= drms_setkey_float(recLev15c->records[0],DATAMINS,(float)minimum);
06267 statusA[4]= drms_setkey_float(recLev15c->records[0],DATAMAXS,(float)maximum);
06268 statusA[5]= drms_setkey_float(recLev15c->records[0],DATAMEDNS,(float)median);
06269 statusA[6]= drms_setkey_float(recLev15c->records[0],DATAMEANS,(float)mean);
06270 statusA[7]= drms_setkey_float(recLev15c->records[0],DATARMSS,(float)sigma);
06271 statusA[8]= drms_setkey_float(recLev15c->records[0],DATASKEWS,(float)skewness);
06272 statusA[9]= drms_setkey_float(recLev15c->records[0],DATAKURTS,(float)kurtosis);
06273 statusA[10]=drms_setkey_int(recLev15c->records[0],CALFSNS,FSNLOOKUP);
06274 statusA[11]=drms_setkey_string(recLev15c->records[0],LUTQUERYS,HMILookup);
06275 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06276 statusA[12]= drms_setkey_string(recLev15c->records[0],DATES,DATEOBS);
06277 statusA[13]= drms_setkey_int(recLev15c->records[0],QUALITYS,QUALITY);
06278 statusA[14]= drms_setkey_int(recLev15c->records[0],SATVALSS,SATVALS);
06279 statusA[15]= drms_setkey_string(recLev15c->records[0],SOURCES,source);
06280 statusA[16]= drms_setkey_int(recLev15c->records[0],QUALLEV1S,QUALITYLEV1);
06281 statusA[17]= drms_setkey_string(recLev15c->records[0],COMMENTS,COMMENT);
06282 statusA[18]=0;
06283 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15c->records[0],CALVER64S,CALVER64);
06284
06285 TotalStatus=0;
06286 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06287 if(TotalStatus != 0)
06288 {
06289 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the linedepth at target time %s\n",timeBegin2);
06290 }
06291
06292
06293
06294
06295 drms_copykeys(recLev15d->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06296
06297 status=fstats(axisout[0]*axisout[1],arrLev15[3]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06298 if(status != 0)
06299 {
06300 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06301 }
06302
06303
06304 image=arrLev15[3]->data;
06305 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))
06306 {
06307 MISSVALS[3]+=1;
06308 ngood -= 1;
06309 }
06310
06311
06312 statusA[0]= drms_setkey_int(recLev15d->records[0],TOTVALSS,ngood+MISSVALS[3]);
06313 statusA[1]= drms_setkey_int(recLev15d->records[0],DATAVALSS,ngood);
06314 statusA[2]= drms_setkey_int(recLev15d->records[0],MISSVALSS,MISSVALS[3]);
06315 statusA[3]= drms_setkey_float(recLev15d->records[0],DATAMINS,(float)minimum);
06316 statusA[4]= drms_setkey_float(recLev15d->records[0],DATAMAXS,(float)maximum);
06317 statusA[5]= drms_setkey_float(recLev15d->records[0],DATAMEDNS,(float)median);
06318 statusA[6]= drms_setkey_float(recLev15d->records[0],DATAMEANS,(float)mean);
06319 statusA[7]= drms_setkey_float(recLev15d->records[0],DATARMSS,(float)sigma);
06320 statusA[8]= drms_setkey_float(recLev15d->records[0],DATASKEWS,(float)skewness);
06321 statusA[9]= drms_setkey_float(recLev15d->records[0],DATAKURTS,(float)kurtosis);
06322 statusA[10]=drms_setkey_int(recLev15d->records[0],CALFSNS,FSNLOOKUP);
06323 statusA[11]=drms_setkey_string(recLev15d->records[0],LUTQUERYS,HMILookup);
06324 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06325 statusA[12]= drms_setkey_string(recLev15d->records[0],DATES,DATEOBS);
06326 statusA[13]= drms_setkey_int(recLev15d->records[0],QUALITYS,QUALITY);
06327 statusA[14]= drms_setkey_int(recLev15d->records[0],SATVALSS,SATVALS);
06328 statusA[15]= drms_setkey_string(recLev15d->records[0],SOURCES,source);
06329 statusA[16]= drms_setkey_int(recLev15d->records[0],QUALLEV1S,QUALITYLEV1);
06330 statusA[17]= drms_setkey_string(recLev15d->records[0],COMMENTS,COMMENT);
06331 statusA[18]=0;
06332 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15d->records[0],CALVER64S,CALVER64);
06333
06334 TotalStatus=0;
06335 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06336 if(TotalStatus != 0)
06337 {
06338 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the linewidth at target time %s\n",timeBegin2);
06339 }
06340
06341
06342
06343 drms_copykeys(recLev15e->records[0],recLev1p->records[0],1,kDRMS_KeyClass_Explicit);
06344
06345 status=fstats(axisout[0]*axisout[1],arrLev15[4]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06346 if(status != 0)
06347 {
06348 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06349 }
06350
06351 image=arrLev15[4]->data;
06352 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))
06353 {
06354 MISSVALS[4]+=1;
06355 ngood -= 1;
06356 }
06357
06358
06359 statusA[0]= drms_setkey_int(recLev15e->records[0],TOTVALSS,ngood+MISSVALS[4]);
06360 statusA[1]= drms_setkey_int(recLev15e->records[0],DATAVALSS,ngood);
06361 statusA[2]= drms_setkey_int(recLev15e->records[0],MISSVALSS,MISSVALS[4]);
06362 statusA[3]= drms_setkey_float(recLev15e->records[0],DATAMINS,(float)minimum);
06363 statusA[4]= drms_setkey_float(recLev15e->records[0],DATAMAXS,(float)maximum);
06364 statusA[5]= drms_setkey_float(recLev15e->records[0],DATAMEDNS,(float)median);
06365 statusA[6]= drms_setkey_float(recLev15e->records[0],DATAMEANS,(float)mean);
06366 statusA[7]= drms_setkey_float(recLev15e->records[0],DATARMSS,(float)sigma);
06367 statusA[8]= drms_setkey_float(recLev15e->records[0],DATASKEWS,(float)skewness);
06368 statusA[9]= drms_setkey_float(recLev15e->records[0],DATAKURTS,(float)kurtosis);
06369 statusA[10]=drms_setkey_int(recLev15e->records[0],CALFSNS,FSNLOOKUP);
06370 statusA[11]=drms_setkey_string(recLev15e->records[0],LUTQUERYS,HMILookup);
06371 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06372 statusA[12]= drms_setkey_string(recLev15e->records[0],DATES,DATEOBS);
06373 statusA[13]= drms_setkey_int(recLev15e->records[0],QUALITYS,QUALITY);
06374 statusA[14]= drms_setkey_int(recLev15e->records[0],SATVALSS,SATVALS);
06375 statusA[15]= drms_setkey_string(recLev15e->records[0],SOURCES,source);
06376 statusA[16]= drms_setkey_int(recLev15e->records[0],QUALLEV1S,QUALITYLEV1);
06377 statusA[17]= drms_setkey_string(recLev15e->records[0],COMMENTS,COMMENT);
06378 statusA[18]=0;
06379 if(CALVER64 != -11) statusA[18]= drms_setkey_longlong(recLev15e->records[0],CALVER64S,CALVER64);
06380
06381 TotalStatus=0;
06382 for(i=0;i<19;++i) TotalStatus+=statusA[i];
06383 if(TotalStatus != 0)
06384 {
06385 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);
06386 }
06387
06388
06389 image0=(float *)arrLev15[0]->data;
06390 image1=(float *)arrLev15[1]->data;
06391 image2=(float *)arrLev15[2]->data;
06392 image3=(float *)arrLev15[3]->data;
06393 image4=(float *)arrLev15[4]->data;
06394
06395 for(i=0;i<axisout[0]*axisout[1];++i)
06396 {
06397 row =i / axisout[0];
06398 column=i % axisout[0];
06399 distance = sqrt(((float)row-Y0AVG)*((float)row-Y0AVG)+((float)column-X0AVG)*((float)column-X0AVG));
06400 if(distance > 0.99*RSUNint)
06401 {
06402 image0[i]=NAN;
06403 image1[i]=NAN;
06404 image2[i]=NAN;
06405 image3[i]=NAN;
06406 image4[i]=NAN;
06407 }
06408 }
06409
06410
06411
06412
06413 status=fstats(axisout[0]*axisout[1],arrLev15[0]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06414 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06415 statusA[0]= drms_setkey_float(recLev15a->records[0],DATAMINS2,(float)minimum);
06416 statusA[1]= drms_setkey_float(recLev15a->records[0],DATAMAXS2,(float)maximum);
06417 statusA[2]= drms_setkey_float(recLev15a->records[0],DATAMEDNS2,(float)median);
06418 statusA[3]= drms_setkey_float(recLev15a->records[0],DATAMEANS2,(float)mean);
06419 statusA[4]= drms_setkey_float(recLev15a->records[0],DATARMSS2,(float)sigma);
06420 statusA[5]= drms_setkey_float(recLev15a->records[0],DATASKEWS2,(float)skewness);
06421 statusA[6]= drms_setkey_float(recLev15a->records[0],DATAKURTS2,(float)kurtosis);
06422 status=fstats(axisout[0]*axisout[1],arrLev15[1]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06423 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06424 statusA[7]= drms_setkey_float(recLev15b->records[0],DATAMINS2,(float)minimum);
06425 statusA[8]= drms_setkey_float(recLev15b->records[0],DATAMAXS2,(float)maximum);
06426 statusA[9]= drms_setkey_float(recLev15b->records[0],DATAMEDNS2,(float)median);
06427 statusA[10]= drms_setkey_float(recLev15b->records[0],DATAMEANS2,(float)mean);
06428 statusA[11]= drms_setkey_float(recLev15b->records[0],DATARMSS2,(float)sigma);
06429 statusA[12]= drms_setkey_float(recLev15b->records[0],DATASKEWS2,(float)skewness);
06430 statusA[13]= drms_setkey_float(recLev15b->records[0],DATAKURTS2,(float)kurtosis);
06431 status=fstats(axisout[0]*axisout[1],arrLev15[2]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06432 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06433 statusA[14]= drms_setkey_float(recLev15c->records[0],DATAMINS2,(float)minimum);
06434 statusA[15]= drms_setkey_float(recLev15c->records[0],DATAMAXS2,(float)maximum);
06435 statusA[16]= drms_setkey_float(recLev15c->records[0],DATAMEDNS2,(float)median);
06436 statusA[17]= drms_setkey_float(recLev15c->records[0],DATAMEANS2,(float)mean);
06437 statusA[18]= drms_setkey_float(recLev15c->records[0],DATARMSS2,(float)sigma);
06438 statusA[19]= drms_setkey_float(recLev15c->records[0],DATASKEWS2,(float)skewness);
06439 statusA[20]= drms_setkey_float(recLev15c->records[0],DATAKURTS2,(float)kurtosis);
06440 status=fstats(axisout[0]*axisout[1],arrLev15[3]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06441 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06442 statusA[21]= drms_setkey_float(recLev15d->records[0],DATAMINS2,(float)minimum);
06443 statusA[22]= drms_setkey_float(recLev15d->records[0],DATAMAXS2,(float)maximum);
06444 statusA[23]= drms_setkey_float(recLev15d->records[0],DATAMEDNS2,(float)median);
06445 statusA[24]= drms_setkey_float(recLev15d->records[0],DATAMEANS2,(float)mean);
06446 statusA[25]= drms_setkey_float(recLev15d->records[0],DATARMSS2,(float)sigma);
06447 statusA[26]= drms_setkey_float(recLev15d->records[0],DATASKEWS2,(float)skewness);
06448 statusA[27]= drms_setkey_float(recLev15d->records[0],DATAKURTS2,(float)kurtosis);
06449 status=fstats(axisout[0]*axisout[1],arrLev15[4]->data,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
06450 if(status != 0) printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
06451 statusA[28]= drms_setkey_float(recLev15e->records[0],DATAMINS2,(float)minimum);
06452 statusA[29]= drms_setkey_float(recLev15e->records[0],DATAMAXS2,(float)maximum);
06453 statusA[30]= drms_setkey_float(recLev15e->records[0],DATAMEDNS2,(float)median);
06454 statusA[31]= drms_setkey_float(recLev15e->records[0],DATAMEANS2,(float)mean);
06455 statusA[32]= drms_setkey_float(recLev15e->records[0],DATARMSS2,(float)sigma);
06456 statusA[33]= drms_setkey_float(recLev15e->records[0],DATASKEWS2,(float)skewness);
06457 statusA[34]= drms_setkey_float(recLev15e->records[0],DATAKURTS2,(float)kurtosis);
06458
06459 statusA[35]= drms_setkey_string(recLev15a->records[0],HISTORYS,HISTORY);
06460 statusA[36]= drms_setkey_string(recLev15b->records[0],HISTORYS,HISTORY);
06461 statusA[37]= drms_setkey_string(recLev15c->records[0],HISTORYS,HISTORY);
06462 statusA[38]= drms_setkey_string(recLev15d->records[0],HISTORYS,HISTORY);
06463 statusA[39]= drms_setkey_string(recLev15e->records[0],HISTORYS,HISTORY);
06464
06465 TotalStatus=0;
06466 for(i=0;i<35;++i) TotalStatus+=statusA[i];
06467 if(TotalStatus != 0)
06468 {
06469 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the Dopplergram at target time %s\n",timeBegin2);
06470 }
06471 t1=dsecnd();
06472 printf("TIME ELAPSED TO SET LEV 1.5 KEYWORDS AND CALCULATE STATISTICS KEYWORDS: %f\n",t1-t0);
06473
06474 }
06475
06476
06477
06478 NextTargetTime:
06479
06480
06481
06482
06483
06484
06485
06486
06487
06488
06489 printf("FREEING RECORD\n");
06490
06491 if(Mask != NULL)
06492 {
06493 free(Mask);
06494 Mask = NULL;
06495 }
06496
06497 if(recLev1d != NULL)
06498 {
06499 printf("recLev1d != NULL\n");
06500 if(recLev1d->n > 0)
06501 {
06502
06503 if (Lev1dWanted) status=drms_close_records(recLev1d,DRMS_INSERT_RECORD);
06504 else status=drms_close_records(recLev1d,DRMS_FREE_RECORD);
06505 recLev1d=NULL;
06506 if(arrLev1d != NULL)
06507 {
06508 for(i=0;i<nRecs1d;++i) if(arrLev1d[i] != NULL)
06509 {
06510 drms_free_array(arrLev1d[i]);
06511 arrLev1d[i]=NULL;
06512 }
06513 free(arrLev1d);
06514 }
06515 arrLev1d=NULL;
06516 Segments1d=0;
06517 }
06518 }
06519
06520
06521 if(recLev1p != NULL)
06522 {
06523 printf("recLev1p != NULL\n");
06524 if(recLev1p->n > 0)
06525 {
06526 if (Lev1pWanted) status=drms_close_records(recLev1p,DRMS_INSERT_RECORD);
06527 else status=drms_close_records(recLev1p,DRMS_FREE_RECORD);
06528 recLev1p=NULL;
06529 for(i=0;i<nSegs1p;++i) if(arrLev1p[i] != NULL)
06530 {
06531 drms_free_array(arrLev1p[i]);
06532 arrLev1p[i]=NULL;
06533 }
06534 if(arrLev1p != NULL) free(arrLev1p);
06535 arrLev1p=NULL;
06536 if(ps1 != NULL) free(ps1);
06537 if(ps2 != NULL) free(ps2);
06538 if(ps3 != NULL) free(ps3);
06539 if(fid != NULL) free(fid);
06540 if(Wavelengths != NULL) free(Wavelengths);
06541 if(images != NULL) free(images);
06542 if(imagesout != NULL) free(imagesout);
06543 Wavelengths=NULL;
06544 images=NULL;
06545 imagesout=NULL;
06546 ps1=NULL;
06547 ps2=NULL;
06548 ps3=NULL;
06549 fid=NULL;
06550 Segments1p=0;
06551 }
06552 }
06553
06554
06555 if(Lev15Wanted)
06556 {
06557
06558 if(arrintable != NULL)
06559 {
06560 drms_free_array(arrintable);
06561 }
06562 arrintable=NULL;
06563 if(lookup != NULL) status=drms_close_records(lookup,DRMS_FREE_RECORD);
06564 lookup = NULL;
06565 if(recpoly != NULL) status=drms_close_records(recpoly,DRMS_FREE_RECORD);
06566 recpoly= NULL;
06567 if(recpoly2 != NULL) status=drms_close_records(recpoly2,DRMS_FREE_RECORD);
06568 recpoly2= NULL;
06569 if(arrayL0 != NULL)
06570 {
06571 drms_free_array(arrayL0);
06572 arrayL0=NULL;
06573 }
06574 if(arrayL1 != NULL)
06575 {
06576 drms_free_array(arrayL1);
06577 arrayL1=NULL;
06578 }
06579 if(arrayL2 != NULL)
06580 {
06581 drms_free_array(arrayL2);
06582 arrayL2=NULL;
06583 }
06584 if(count != NULL)
06585 {
06586 free(count);
06587 count=NULL;
06588 }
06589
06590 if(recLev15a != NULL)
06591 {
06592 printf("recLev15a != NULL\n");
06593 if(CreateEmptyRecord != 1)
06594 {
06595 printf("Inserting record for the observables\n");
06596 status=drms_close_records(recLev15a,DRMS_INSERT_RECORD);
06597 status=drms_close_records(recLev15b,DRMS_INSERT_RECORD);
06598 status=drms_close_records(recLev15c,DRMS_INSERT_RECORD);
06599 status=drms_close_records(recLev15d,DRMS_INSERT_RECORD);
06600 status=drms_close_records(recLev15e,DRMS_INSERT_RECORD);
06601 recLev15a=NULL;
06602 recLev15b=NULL;
06603 recLev15c=NULL;
06604 recLev15d=NULL;
06605 recLev15e=NULL;
06606 }
06607 else
06608 {
06609 printf("Warning: creating empty lev1.5 record\n");
06610
06611 if(CamId == LIGHT_SIDE) camera=1;
06612 if(CamId == LIGHT_FRONT) camera=2;
06613
06614 QUALITY= QUALITY | QUAL_NODATA;
06615 statusA[0] = drms_setkey_time(recLev15a->records[0],TRECS,TargetTime);
06616
06617 statusA[2] = drms_setkey_int(recLev15a->records[0],CAMERAS,camera);
06618 statusA[3] = drms_setkey_int(recLev15a->records[0],QUALITYS,QUALITY);
06619 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06620 statusA[4]= drms_setkey_string(recLev15a->records[0],DATES,DATEOBS);
06621
06622 statusA[0] = drms_setkey_time(recLev15b->records[0],TRECS,TargetTime);
06623
06624 statusA[2] = drms_setkey_int(recLev15b->records[0],CAMERAS,camera);
06625 statusA[3] = drms_setkey_int(recLev15b->records[0],QUALITYS,QUALITY);
06626 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06627 statusA[4]= drms_setkey_string(recLev15b->records[0],DATES,DATEOBS);
06628
06629 statusA[0] = drms_setkey_time(recLev15c->records[0],TRECS,TargetTime);
06630
06631 statusA[2] = drms_setkey_int(recLev15c->records[0],CAMERAS,camera);
06632 statusA[3] = drms_setkey_int(recLev15c->records[0],QUALITYS,QUALITY);
06633 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06634 statusA[4]= drms_setkey_string(recLev15c->records[0],DATES,DATEOBS);
06635
06636 statusA[0] = drms_setkey_time(recLev15d->records[0],TRECS,TargetTime);
06637
06638 statusA[2] = drms_setkey_int(recLev15d->records[0],CAMERAS,camera);
06639 statusA[3] = drms_setkey_int(recLev15d->records[0],QUALITYS,QUALITY);
06640 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06641 statusA[4]= drms_setkey_string(recLev15d->records[0],DATES,DATEOBS);
06642
06643 statusA[0] = drms_setkey_time(recLev15e->records[0],TRECS,TargetTime);
06644
06645 statusA[2] = drms_setkey_int(recLev15e->records[0],CAMERAS,camera);
06646 statusA[3] = drms_setkey_int(recLev15e->records[0],QUALITYS,QUALITY);
06647 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06648 statusA[4]= drms_setkey_string(recLev15e->records[0],DATES,DATEOBS);
06649
06650
06651 status=drms_close_records(recLev15a,DRMS_INSERT_RECORD);
06652 status=drms_close_records(recLev15b,DRMS_INSERT_RECORD);
06653 status=drms_close_records(recLev15c,DRMS_INSERT_RECORD);
06654 status=drms_close_records(recLev15d,DRMS_INSERT_RECORD);
06655 status=drms_close_records(recLev15e,DRMS_INSERT_RECORD);
06656 recLev15a=NULL;
06657 recLev15b=NULL;
06658 recLev15c=NULL;
06659 recLev15d=NULL;
06660 recLev15e=NULL;
06661 }
06662 for (i=0;i<nRecs15;++i) if(arrLev15[i] != NULL)
06663 {
06664 drms_free_array(arrLev15[i]);
06665 arrLev15[i]=NULL;
06666 }
06667 if(arrLev15 != NULL) free(arrLev15);
06668 arrLev15=NULL;
06669 }
06670 else
06671 {
06672
06673 recLev15a = drms_create_records(drms_env,1,HMISeriesLev15a,DRMS_PERMANENT,&statusA[0]);
06674 recLev15b = drms_create_records(drms_env,1,HMISeriesLev15b,DRMS_PERMANENT,&statusA[1]);
06675 recLev15c = drms_create_records(drms_env,1,HMISeriesLev15c,DRMS_PERMANENT,&statusA[2]);
06676 recLev15d = drms_create_records(drms_env,1,HMISeriesLev15d,DRMS_PERMANENT,&statusA[3]);
06677 recLev15e = drms_create_records(drms_env,1,HMISeriesLev15e,DRMS_PERMANENT,&statusA[4]);
06678
06679 if(CamId == LIGHT_SIDE) camera=1;
06680 if(CamId == LIGHT_FRONT) camera=2;
06681
06682 printf("Warning: creating empty lev1.5 record\n");
06683 QUALITY= QUALITY | QUAL_NODATA;
06684 statusA[0] = drms_setkey_time(recLev15a->records[0],TRECS,TargetTime);
06685
06686 statusA[2] = drms_setkey_int(recLev15a->records[0],CAMERAS,camera);
06687 statusA[3] = drms_setkey_int(recLev15a->records[0],QUALITYS,QUALITY);
06688 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06689 statusA[4]= drms_setkey_string(recLev15a->records[0],DATES,DATEOBS);
06690
06691 statusA[0] = drms_setkey_time(recLev15b->records[0],TRECS,TargetTime);
06692
06693 statusA[2] = drms_setkey_int(recLev15b->records[0],CAMERAS,camera);
06694 statusA[3] = drms_setkey_int(recLev15b->records[0],QUALITYS,QUALITY);
06695 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06696 statusA[4]= drms_setkey_string(recLev15b->records[0],DATES,DATEOBS);
06697
06698 statusA[0] = drms_setkey_time(recLev15c->records[0],TRECS,TargetTime);
06699
06700 statusA[2] = drms_setkey_int(recLev15c->records[0],CAMERAS,camera);
06701 statusA[3] = drms_setkey_int(recLev15c->records[0],QUALITYS,QUALITY);
06702 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06703 statusA[4]= drms_setkey_string(recLev15c->records[0],DATES,DATEOBS);
06704
06705 statusA[0] = drms_setkey_time(recLev15d->records[0],TRECS,TargetTime);
06706
06707 statusA[2] = drms_setkey_int(recLev15d->records[0],CAMERAS,camera);
06708 statusA[3] = drms_setkey_int(recLev15d->records[0],QUALITYS,QUALITY);
06709 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06710 statusA[4]= drms_setkey_string(recLev15d->records[0],DATES,DATEOBS);
06711
06712 statusA[0] = drms_setkey_time(recLev15e->records[0],TRECS,TargetTime);
06713
06714 statusA[2] = drms_setkey_int(recLev15e->records[0],CAMERAS,camera);
06715 statusA[3] = drms_setkey_int(recLev15e->records[0],QUALITYS,QUALITY);
06716 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
06717 statusA[4]= drms_setkey_string(recLev15e->records[0],DATES,DATEOBS);
06718
06719 status=drms_close_records(recLev15a,DRMS_INSERT_RECORD);
06720 status=drms_close_records(recLev15b,DRMS_INSERT_RECORD);
06721 status=drms_close_records(recLev15c,DRMS_INSERT_RECORD);
06722 status=drms_close_records(recLev15d,DRMS_INSERT_RECORD);
06723 status=drms_close_records(recLev15e,DRMS_INSERT_RECORD);
06724 recLev15a=NULL;
06725 recLev15b=NULL;
06726 recLev15c=NULL;
06727 recLev15d=NULL;
06728 recLev15e=NULL;
06729 }
06730
06731 QUALITY=0;
06732 CreateEmptyRecord=0;
06733 }
06734
06735 PreviousTargetTime=TargetTime;
06736 TargetTime+=DataCadence;
06737 initialrun=0;
06738 }
06739
06740
06741 if (TestLevIn[0]==1)
06742 {
06743 printf("FREEING GENERAL ARRAYS\n");
06744 if(recLev1->n > 0)
06745 {
06746 status=drms_close_records(recLev1,DRMS_FREE_RECORD);
06747 recLev1=NULL;
06748 free(internTOBS);
06749 free(HWL1POS);
06750 free(HWL2POS);
06751 free(HWL3POS);
06752 free(HWL4POS);
06753 free(HPL1POS);
06754 free(HPL2POS);
06755 free(HPL3POS);
06756 free(HWLTID);
06757 free(HPLTID);
06758 free(FID);
06759 free(HFLID);
06760 free(HCAMID);
06761 free(RSUN);
06762 free(CROTA2);
06763 free(CRLTOBS);
06764 free(DSUNOBS);
06765 free(X0);
06766 free(Y0);
06767 free(SegmentRead);
06768 free(KeywordMissing);
06769 free(Segments);
06770
06771 if(inRotationalFlat == 1)
06772 {
06773 drms_free_array(flatfield);
06774 drms_free_array(flatfieldrot);
06775 status=drms_close_records(recflatrot,DRMS_FREE_RECORD);
06776 }
06777 free(Ierror);
06778 free(IndexFiltergram);
06779 free(FSN);
06780 free(CFINDEX);
06781 free(HIMGCFID);
06782 for(i=0;i<nRecs1;++i) free(IMGTYPE[i]);
06783 free(IMGTYPE);
06784 free(CDELT1);
06785 for(i=0;i<nRecs1;++i) free(HWLTNSET[i]);
06786 free(HWLTNSET);
06787 free(NBADPERM);
06788 free(QUALITYin);
06789 free(QUALITYlev1);
06790 free(EXPTIME);
06791 free(CALVER32);
06792 free(CAMERA);
06793 }
06794 }
06795
06796 if(TestLevIn[0]==1)
06797 {
06798 free_interpol(&const_param);
06799 }
06800
06801 if(Lev1pWanted || (Lev15Wanted && TestLevIn[2]==0))
06802 {
06803 status = free_polcal(&pars);
06804 }
06805
06806 free(CODEVERSION);
06807 free(CODEVERSION1);
06808 free(CODEVERSION2);
06809 free(CODEVERSION3);
06810 free(DISTCOEFFILEF);
06811 free(DISTCOEFFILES);
06812 free(ROTCOEFFILE);
06813 free(DISTCOEFPATH);
06814 free(ROTCOEFPATH);
06815
06816
06817 status=0;
06818 t1=dsecnd();
06819 printf("TOTAL TIME ELAPSED IN OBSERVABLES CODE: %f\n",t1-tstart);
06820 return status;
06821
06822 }
06823
06824