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 #include <stdio.h>
00131 #include <stdlib.h>
00132 #include <string.h>
00133 #include <math.h>
00134 #include <complex.h>
00135 #include <omp.h>
00136 #include "interpol_code.h"
00137 #include "polcal.h"
00138 #include "HMIparam.h"
00139 #include "fstats.h"
00140
00141
00142 #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
00143
00144 char *module_name = "HMI_IQUV_averaging";
00145
00146 #define kRecSetIn "begin" //beginning time for which an output is wanted. MANDATORY PARAMETER.
00147 #define kRecSetIn2 "end" //end time for which an output is wanted. MANDATORY PARAMETER.
00148
00149 #define WaveLengthIn "wavelength" //filtergram name Ii starting the framelist (i ranges from 0 to 5). MANDATORY PARAMETER.
00150 #define CamIDIn "camid" //front camera (camid=1) or side camera (camid=0)?
00151
00152
00153
00154 #define DataCadenceIn "cadence" //cadence (45, 90, 120, 135, or 150 seconds)
00155 #define NpolIn "npol" //number of polarizations in observable framelist
00156 #define FramelistSizeIn "size" //size of the framelist
00157 #define SeriesIn "lev1" //series name for the lev1 filtergrams
00158 #define QuickLookIn "quicklook" //quicklook data (yes=1,no=0)? 0 BY DEFAULT
00159 #define Average "average" //average over 12 or 96 minutes? (12 by default)
00160 #define RotationalFlat "rotational" //force the use of rotational flat fields?
00161 #define Linearity "linearity" //force the correction for non-linearity of cameras
00162
00163 #define minval(x,y) (((x) < (y)) ? (x) : (y))
00164 #define maxval(x,y) (((x) < (y)) ? (y) : (x))
00165
00166
00167 #define LIGHT_SIDE 2 //SIDE CAMERA
00168 #define LIGHT_FRONT 3 //FRONT CAMERA
00169 #define DARK_SIDE 0 //SIDE CAMERA
00170 #define DARK_FRONT 1 //FRONT CAMERA
00171
00172 #define Q_ACS_ECLP 0x2000 //eclipse keyword for the lev1 data
00173 #define Q_ACS_ISSLOOP 0x20000 //ISS loop OPEN for lev1
00174 #define Q_ACS_NOLIMB 0x10 //limbfinder error for lev1
00175 #define Q_MISSING_SEGMENT 0x80000000 //missing image segment for lev1 record
00176 #define Q_ACS_LUNARTRANSIT 0x800000 //lunar transit
00177 #define Q_ACS_THERMALRECOVERY 0x400000//therma recovery after eclipses
00178 #define Q_CAMERA_ANOMALY 0x00000080 //camera issue with HMI (e.g. DATAMIN=0): resulting images might be usable, but most likely bad
00179
00180 #define CALVER_DEFAULT 0 // both the default and missing value of CALVER64
00181
00182 #define CALVER_LINEARITY 0x2000 //bitmask for CALVER64 to indicate the use of non-linearity correction //VALUE USED AFTER JANUARY 15, 2014
00183 #define CALVER_ROTATIONAL 0x10000 //bitmask for CALVER64 to indicate the use of rotational flat fields
00184 #define CALVER_MODL 0x40000 //bitmask for CALVER64 to indicate the use of a mod L observables sequence
00185 #define CALVER_NOMODL 0xFFFFFFFFFFF1FFFF //to reset the mask
00186
00187
00188
00189
00190 #define QUAL_NODATA (0x80000000) //not all the IQUV images at all the wavelengths were produced (SOME OR ALL DATA SEGMENTS ARE MISSING)
00191 #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
00192 #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 level 1 records are missing or corrupted
00193 #define QUAL_NOFRAMELISTINFO (0x10000000) //could not figure out which observables framelist was used, or the framelist run for the required dates is not an observables framelist
00194 #define QUAL_WRONGCADENCE (0x8000000) //the cadence corresponding to the framelist run at required times does not match the expected value provided by user (could be an error from user, or an issue with the framelist)
00195 #define QUAL_WRONGFRAMELISTSIZE (0x4000000) //the current framelist size does not match the value from the command line
00196 #define QUAL_WRONGNPOL (0x2000000) //the current framelist npol does not match the value from the command line
00197 #define QUAL_WRONGPOLTYPE (0x1000000) //the current framelist does not allow for the production of I,Q,U, and V data
00198 #define QUAL_WRONGTARGET (0x800000) //the target filtergram does not belong to the current framelist (there is something wrong either with the framelist or the target filtergram)
00199 #define QUAL_ERRORFRAMELIST (0x400000) //the filtergrams are not where they should be in the framelist
00200 #define QUAL_WRONGWAVELENGTHNUM (0x200000) //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)
00201 #define QUAL_NOLOOKUPRECORD (0x100000) //could not find a record for the look-up tables for the MDI-like algorithm (the MDI-like algorithm cannot be used)
00202 #define QUAL_NOLOOKUPKEYWORD (0x80000) //could not read the keywords of the look-up tables for the MDI-like algorithm (the MDI-like algorithm cannot be used)
00203 #define QUAL_NOTENOUGHINTERPOLANTS (0x40000) //not enough interpolation points for the temporal interpolation at a given wavelength and polarization (too many lev 1 records were missing or corrupted)
00204 #define QUAL_INTERPOLATIONFAILED (0x20000) //the temporal interpolation routine failed
00205
00206
00207 #define QUAL_LOWINTERPNUM (0x10000) //the number of averaging points is lower than TempIntNum, AND/OR 2 interpolation points were separated by more than the cadence
00208 #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 was used
00209 #define QUAL_ISSTARGET (0x4000) //the ISS loop was OPEN for one or several filtergrams used to produce the observable
00210 #define QUAL_NOTEMP (0x2000) //cannot read the temperatures needed for polarization calibration (default temperature used)
00211 #define QUAL_NOGAPFILL (0x1000) //the code could not properly gap-fill all the lev 1 filtergrams
00212 #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)
00213 #define QUAL_NOCOSMICRAY (0x400) //some cosmic-ray hit lists could not be read for the level 1 filtergrams
00214 #define QUAL_ECLIPSE (0x200) //at least one lev1 record was taken during an eclipse
00215 #define QUAL_LARGEFTSID (0x100) //HFTSACID of target filtergram > 4000, which adds noise to observables
00216 #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...
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 ModuleArgs_t module_args[] =
00230 {
00231 {ARG_STRING, kRecSetIn, "" , "beginning time for which an output is wanted"},
00232 {ARG_STRING, kRecSetIn2, "" , "end time for which an output is wanted"},
00233 {ARG_INT , WaveLengthIn,"3" , "Index of the wavelength starting the framelist. FROM 0 TO 5"},
00234 {ARG_INT , CamIDIn , "0" , "Front (1) or side (0) camera?"},
00235 {ARG_DOUBLE, DataCadenceIn,"135.0" ,"Cadence: 45, 90, 120, 135, or 150 seconds"},
00236 {ARG_INT, NpolIn,"4", "Number of polarizations in framelist"},
00237 {ARG_INT, FramelistSizeIn,"36", "size of framelist"},
00238 {ARG_STRING, SeriesIn, "hmi.lev1", "Name of the lev1 series"},
00239 {ARG_INT , QuickLookIn, "0" , "Quicklook data? No=0; Yes=1"},
00240 {ARG_INT , Average, "12" , "Average over 12 or 96 minutes? (12 by default)"},
00241 {ARG_INT , RotationalFlat, "0", "Use rotational flat fields? yes=1, no=0 (default)"},
00242 {ARG_STRING, "dpath", "/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/", "directory where the source code is located"},
00243 {ARG_INT , Linearity, "0", "Correct for non-linearity of cameras? yes=1, no=0 (default)"},
00244 {ARG_END}
00245 };
00246
00247
00248
00249
00250
00251
00252
00253
00254 int needtochangeFID(int HFLID)
00255 {
00256 int need;
00257
00258 switch(HFLID)
00259 {
00260 case 58312: need=1;
00261 break;
00262 case 1022: need=1;
00263 break;
00264
00265 case 2042: need=1;
00266 break;
00267
00268 case 2043: need=1;
00269 break;
00270
00271 case 1002: need=1;
00272 break;
00273
00274 case 3042: need=1;
00275 break;
00276
00277 case 3040: need=1;
00278 break;
00279
00280 case 3041: need=1;
00281 break;
00282
00283 case 3043: need=1;
00284 break;
00285
00286 default: need=0;
00287 }
00288
00289 return need;
00290 }
00291
00292
00293
00294
00295
00296
00297
00298
00299 int signj(int v)
00300 {
00301 return v > 0 ? 1 : (v < 0 ? -1 : 0);
00302 }
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 int WhichWavelength(int FID)
00317 {
00318 int result;
00319 int temp;
00320 if(FID < 100000) temp=(FID/10) % 20;
00321 else
00322 {
00323 temp = ((FID-100000)/10) % 20;
00324 }
00325 switch (temp)
00326 {
00327 case 19: result=9;
00328 break;
00329 case 17: result=7;
00330 break;
00331 case 15: result=0;
00332 break;
00333 case 14: result=0;
00334 break;
00335 case 13: result=1;
00336 break;
00337 case 12: result=1;
00338 break;
00339 case 11: result=2;
00340 break;
00341 case 10: result=2;
00342 break;
00343 case 9: result=3;
00344 break;
00345 case 8: result=3;
00346 break;
00347 case 7: result=4;
00348 break;
00349 case 6: result=4;
00350 break;
00351 case 5: result=5;
00352 break;
00353 case 3: result=6;
00354 break;
00355 case 1: result=8;
00356 break;
00357 default: result=-101;
00358 }
00359
00360 return result;
00361
00362 }
00363
00364
00365
00366
00367
00368
00369
00370
00371 int framelistCombine(int HFLID, int CamIdIn,int *Pcombine, char *dpath)
00372 {
00373 int HFLIDread,FIDread,i,j,compteur;
00374 FILE *sequencefile;
00375
00376 char *filename=NULL;
00377 char *filename2=NULL;
00378 char *filename3=NULL;
00379
00380 char dpath2[256];
00381 strcpy(dpath2,dpath);
00382 filename =strdup(strcat(dpath2,"/../Sequences3.txt"));
00383 strcpy(dpath2,dpath);
00384 filename2=strdup(strcat(dpath2,"/../../tables/hmi_mech/std_flight.w"));
00385 strcpy(dpath2,dpath);
00386 filename3=strdup(strcat(dpath2,"/../../tables/hmi_mech/std_flight.p"));
00387
00388
00389 char line[256];
00390 int found=0;
00391
00392 int combinef,combines,npolf,npols,framelistSizef,framelistSizes,PolarizationTypef,PolarizationTypes,CAMERA;
00393 float DataCadencef,DataCadences;
00394
00395
00396 printf("HFLID OF FRAMELIST = %d\n",HFLID);
00397 sequencefile = fopen(filename,"r");
00398 if(sequencefile == NULL)
00399 {
00400 printf("The file %s does not exist or cannot be read\n",filename);
00401 free(filename);
00402 free(filename2);
00403 free(filename3);
00404 filename=NULL;
00405 filename2=NULL;
00406 filename3=NULL;
00407 return 1;
00408 }
00409 while (fgets(line,256,sequencefile) != NULL)
00410 {
00411 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);
00412 if(HFLIDread == HFLID)
00413 {
00414 if(CamIdIn == LIGHT_FRONT) *Pcombine=combinef;
00415 if(CamIdIn == LIGHT_SIDE) *Pcombine=combines;
00416 found=1;
00417 }
00418 }
00419 fclose(sequencefile);
00420
00421 return found;
00422 }
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451 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)
00452 {
00453 int framelistSize=0,HFLIDread,FIDread,i,j,compteur, ij;
00454 int PLINDEX,WLINDEX;
00455 FILE *sequencefile;
00456
00457
00458
00459
00460
00461
00462
00463 char *filename=NULL;
00464 char *filename2=NULL;
00465 char *filename3=NULL;
00466
00467 char dpath2[256];
00468 strcpy(dpath2,dpath);
00469 filename =strdup(strcat(dpath2,"/../Sequences3.txt"));
00470 strcpy(dpath2,dpath);
00471 filename2=strdup(strcat(dpath2,"/../../tables/hmi_mech/std_flight.w"));
00472 strcpy(dpath2,dpath);
00473 filename3=strdup(strcat(dpath2,"/../../tables/hmi_mech/std_flight.p"));
00474
00475
00476 char line[256];
00477 int PL_Index[MaxNumFiltergrams],WL_Index[MaxNumFiltergrams];
00478 int WT1P,WT2P,WT3P,WT4P,PS1P,PS2P,PS3P;
00479 int found=0;
00480
00481 int combinef,combines,npolf,npols,framelistSizef,framelistSizes,PolarizationTypef,PolarizationTypes,CAMERA;
00482 float DataCadencef,DataCadences;
00483
00484
00485
00486
00487
00488 printf("HFLID OF FRAMELIST = %d\n",HFLID);
00489 sequencefile = fopen(filename,"r");
00490 if(sequencefile == NULL)
00491 {
00492 printf("The file %s does not exist or cannot be read\n",filename);
00493 free(filename);
00494 free(filename2);
00495 free(filename3);
00496 filename=NULL;
00497 filename2=NULL;
00498 filename3=NULL;
00499 return 1;
00500 }
00501
00502 i=0;
00503 compteur=0;
00504 while (fgets(line,256,sequencefile) != NULL)
00505 {
00506 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);
00507 if(HFLIDread == HFLID)
00508 {
00509
00510 if(CamIdIn == LIGHT_FRONT)
00511 {
00512 *Pcombine=combinef;
00513 *Pnpol=npolf;
00514 *PDataCadence=DataCadencef;
00515 *PPolarizationType=PolarizationTypef;
00516 framelistSize=framelistSizef;
00517 if(combinef == 0)
00518 {
00519 if(CAMERA == 3)
00520 {
00521 FID[i]=j;
00522 WavelengthLocation[i]=compteur;
00523 CameraValues[i]=LIGHT_FRONT;
00524 i+=1;
00525 }
00526 }
00527 else
00528 {
00529 FID[i]=j;
00530 WavelengthLocation[i]=compteur;
00531 if(CAMERA == 3) CameraValues[i]=LIGHT_FRONT;
00532 else CameraValues[i]=LIGHT_SIDE;
00533 i+=1;
00534 }
00535 }
00536 if(CamIdIn == LIGHT_SIDE)
00537 {
00538 *Pcombine=combines;
00539 *Pnpol=npols;
00540 *PDataCadence=DataCadences;
00541 *PPolarizationType=PolarizationTypes;
00542 framelistSize=framelistSizes;
00543
00544 ij = needtochangeFID(HFLID);
00545 if(ij == 1 && CAMERA == 3)
00546 {
00547 if( (i%72)/24 == 1)
00548 {
00549 j=j+100000;
00550
00551 }
00552 }
00553
00554
00555 if(combines == 0)
00556 {
00557 if(CAMERA == 2)
00558 {
00559 FID[i]=j;
00560 WavelengthLocation[i]=compteur;
00561 CameraValues[i]=LIGHT_SIDE;
00562 i+=1;
00563 }
00564 }
00565 else
00566 {
00567 FID[i]=j;
00568 WavelengthLocation[i]=compteur;
00569 if(CAMERA == 3) CameraValues[i]=LIGHT_FRONT;
00570 else CameraValues[i]=LIGHT_SIDE;
00571 i+=1;
00572 }
00573
00574 }
00575 found=1;
00576 compteur+=1;
00577 }
00578 }
00579 fclose(sequencefile);
00580
00581
00582
00583 int baseindexW,baseindexP;
00584
00585
00586 if((framelistSize == 12) || (framelistSize == 24) || (framelistSize == 36) || (framelistSize == 48) || (framelistSize == 16) || (framelistSize == 32) || (framelistSize == 20) || (framelistSize == 40))
00587 {
00588 switch(WavelengthID)
00589 {
00590 case 9: baseindexW=HWLTID-19;
00591 break;
00592 case 7: baseindexW=HWLTID-17;
00593 break;
00594 case 0: baseindexW=HWLTID-15;
00595 break;
00596 case 1: baseindexW=HWLTID-13;
00597 break;
00598 case 2: baseindexW=HWLTID-11;
00599 break;
00600 case 3: baseindexW=HWLTID-9;
00601 break;
00602 case 4: baseindexW=HWLTID-7;
00603 break;
00604 case 5: baseindexW=HWLTID-5;
00605 break;
00606 case 6: baseindexW=HWLTID-3;
00607 break;
00608 case 8: baseindexW=HWLTID-1;
00609 break;
00610 }
00611 }
00612 if( (framelistSize == 10) )
00613 {
00614 switch(WavelengthID)
00615 {
00616 case 0: baseindexW=HWLTID-14;
00617 break;
00618 case 1: baseindexW=HWLTID-12;
00619 break;
00620 case 2: baseindexW=HWLTID-10;
00621 break;
00622 case 3: baseindexW=HWLTID-8;
00623 break;
00624 case 4: baseindexW=HWLTID-6;
00625 break;
00626 }
00627 }
00628
00629 baseindexP=(HPLTID/10)*10;
00630
00631 for(i=0;i<framelistSize;++i)
00632 {
00633 WLINDEX=(FID[i]/10) % 20;
00634 WL_Index[i]=WLINDEX+baseindexW;
00635 PLINDEX=FID[i]%10;
00636 PL_Index[i]=PLINDEX+baseindexP;
00637 switch(WLINDEX)
00638 {
00639 case 19: WavelengthIndex[i]=9;
00640 break;
00641 case 17: WavelengthIndex[i]=7;
00642 break;
00643 case 15: WavelengthIndex[i]=0;
00644 break;
00645 case 14: WavelengthIndex[i]=0;
00646 break;
00647 case 13: WavelengthIndex[i]=1;
00648 break;
00649 case 12: WavelengthIndex[i]=1;
00650 break;
00651 case 11: WavelengthIndex[i]=2;
00652 break;
00653 case 10: WavelengthIndex[i]=2;
00654 break;
00655 case 9: WavelengthIndex[i]=3;
00656 break;
00657 case 8: WavelengthIndex[i]=3;
00658 break;
00659 case 7: WavelengthIndex[i]=4;
00660 break;
00661 case 6: WavelengthIndex[i]=4;
00662 break;
00663 case 5: WavelengthIndex[i]=5;
00664 break;
00665 case 3: WavelengthIndex[i]=6;
00666 break;
00667 case 1: WavelengthIndex[i]=8;
00668 break;
00669 default: WavelengthIndex[i]=-101;
00670 }
00671 if(WavelengthIndex[i] == -101)
00672 {
00673 printf("Error: WavelengthIndex[i]=-101 \n");
00674 free(filename);
00675 free(filename2);
00676 free(filename3);
00677 filename=NULL;
00678 filename2=NULL;
00679 filename3=NULL;
00680 return 1;
00681 }
00682 }
00683
00684
00685
00686
00687
00688
00689
00690 sequencefile = fopen(filename2,"r");
00691 if(sequencefile == NULL)
00692 {
00693 printf("The file %s does not exist or cannot be read\n",filename2);
00694 free(filename);
00695 free(filename2);
00696 free(filename3);
00697 filename=NULL;
00698 filename2=NULL;
00699 filename3=NULL;
00700 return 1;
00701 }
00702
00703 for(j=0;j<6;++j) fgets(line,256,sequencefile);
00704 while (fgets(line,256,sequencefile) != NULL)
00705 {
00706 if(line[0] != '#')
00707 {
00708 sscanf(line,"%d %d %d %d %d",&j,&WT1P,&WT2P,&WT3P,&WT4P);
00709 for(i=0;i<framelistSize;++i)
00710 {
00711 if(j == WL_Index[i])
00712 {
00713 PHWPLPOS[i*7 ]=WT1P;
00714 PHWPLPOS[i*7+1]=WT2P;
00715 PHWPLPOS[i*7+2]=WT3P;
00716 PHWPLPOS[i*7+3]=WT4P;
00717 }
00718 }
00719 }
00720 }
00721 fclose(sequencefile);
00722
00723 sequencefile = fopen(filename3,"r");
00724 if(sequencefile == NULL)
00725 {
00726 printf("The file %s does not exist or cannot be read\n",filename3);
00727 free(filename);
00728 free(filename2);
00729 free(filename3);
00730 filename=NULL;
00731 filename2=NULL;
00732 filename3=NULL;
00733 return 1;
00734 }
00735
00736 for(j=0;j<6;++j) fgets(line,256,sequencefile);
00737 while (fgets(line,256,sequencefile) != NULL)
00738 {
00739 if(line[0] != '#')
00740 {
00741 sscanf(line,"%d %d %d %d",&j,&PS1P,&PS2P,&PS3P);
00742 for(i=0;i<framelistSize;++i)
00743 {
00744 if(j == PL_Index[i])
00745 {
00746 PHWPLPOS[i*7+4]=PS1P;
00747 PHWPLPOS[i*7+5]=PS2P;
00748 PHWPLPOS[i*7+6]=PS3P;
00749 }
00750 }
00751 }
00752 }
00753 fclose(sequencefile);
00754
00755
00756 if(found == 0)
00757 {
00758 framelistSize=0;
00759 }
00760
00761 free(filename);
00762 free(filename2);
00763 free(filename3);
00764 filename=NULL;
00765 filename2=NULL;
00766 filename3=NULL;
00767
00768 return framelistSize;
00769 }
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782 int MaskCreation(unsigned char *Mask, int nx, int ny, DRMS_Array_t *BadPixels, int HIMGCFID, float *image, DRMS_Array_t *CosmicRays, int nbadperm)
00783 {
00784
00785 int status=2;
00786
00787 if(nx != 4096 || ny != 4096) return status;
00788
00789 char *filename="/home/production/img_cnfg_ids";
00790 const int minid=80;
00791 const int maxid=124;
00792 const int n_tables=1;
00793 const int maxtab=256;
00794
00795 int *badpixellist=BadPixels->data;
00796 int nBadPixels=BadPixels->axis[0];
00797 int *cosmicraylist=NULL;
00798 int ncosmic=0;
00799 if(CosmicRays != NULL)
00800 {
00801 cosmicraylist=CosmicRays->data;
00802 ncosmic=CosmicRays->axis[0];
00803 }
00804 else ncosmic = -1;
00805
00806 int x_orig,y_orig,x_dir,y_dir;
00807 int skip, take, skip_x, skip_y;
00808 int datum, nsx, nss, nlin,nq,nqq,nsy;
00809 int idn=-1;
00810
00811 int *id=NULL, *tab=NULL, *nrows=NULL, *ncols=NULL, *rowstr=NULL, *colstr=NULL, *config=NULL;
00812 id =(int *)(malloc(maxtab*sizeof(int)));
00813 if(id == NULL)
00814 {
00815 printf("Error: memory could not be allocated to id\n");
00816 return 1;
00817 }
00818 tab =(int *)(malloc(maxtab*sizeof(int)));
00819 if(tab == NULL)
00820 {
00821 printf("Error: memory could not be allocated to tab\n");
00822 return 1;
00823 }
00824 nrows =(int *)(malloc(maxtab*sizeof(int)));
00825 if(nrows == NULL)
00826 {
00827 printf("Error: memory could not be allocated to nrows\n");
00828 return 1;
00829 }
00830 ncols =(int *)(malloc(maxtab*sizeof(int)));
00831 if(ncols == NULL)
00832 {
00833 printf("Error: memory could not be allocated to ncols\n");
00834 return 1;
00835 }
00836 rowstr=(int *)(malloc(maxtab*sizeof(int)));
00837 if(rowstr == NULL)
00838 {
00839 printf("Error: memory could not be allocated to rowstr\n");
00840 return 1;
00841 }
00842 colstr=(int *)(malloc(maxtab*sizeof(int)));
00843 if(colstr == NULL)
00844 {
00845 printf("Error: memory could not be allocated to colstr\n");
00846 return 1;
00847 }
00848 config=(int *)(malloc(maxtab*sizeof(int)));
00849 if(config == NULL)
00850 {
00851 printf("Error: memory could not be allocated to config\n");
00852 return 1;
00853 }
00854
00855 int skipt[4*2048];
00856 int taket[4*2048];
00857
00858 int **kx=NULL;
00859 int *kkx=NULL;
00860
00861 kx=(int **)(malloc(9*sizeof(int *)));
00862 if(kx == NULL)
00863 {
00864 printf("Error: memory could not be allocated to kx\n");
00865 return 1;
00866 }
00867
00868
00869 int kx0[11]={4,0,0,1,0,1,1,0,1,1,1};
00870 kx[0]=kx0;
00871 int kx1[7]={2,1,0,1,1,1,2};
00872 kx[2]=kx1;
00873 int kx2[7]={2,0,1,0,0,1,2} ;
00874 kx[4]=kx2;
00875 int kx3[7]={2,0,0,1,0,2,1};
00876 kx[1]=kx3;
00877 int kx4[7]={2,1,1,0,1,2,1};
00878 kx[3]=kx4;
00879 int kx5[7]={1,0,0,2,2};
00880 kx[5]=kx5;
00881 int kx6[5]={1,1,0,2,2};
00882 kx[6]=kx6;
00883 int kx7[5]={1,1,1,2,2};
00884 kx[7]=kx7;
00885 int kx8[5]={1,0,1,2,2};
00886 kx[8]=kx8;
00887
00888 char **filename_table=NULL;
00889 filename_table=(char **)(malloc(n_tables*sizeof(char *)));
00890 if(filename_table == NULL)
00891 {
00892 printf("Error: memory could not be allocated to filename_table\n");
00893 return 1;
00894 }
00895
00896 char *filename_croptable="/home/cvsuser/cvsroot/EGSE/tables/crop/crop6";
00897 filename_table[0]=filename_croptable;
00898
00899 int i,j,k;
00900 int ix, jx;
00901 int n_config;
00902 char string[256];
00903 char strng[5];
00904
00905
00906 FILE *config_file=NULL;
00907 FILE *crop_table=NULL;
00908
00909
00910 config_file=fopen(filename, "r");
00911
00912 if (config_file != NULL){
00913 fgets(string, 256, config_file);
00914 fgets(string, 256, config_file);
00915 fgets(string, 256, config_file);
00916
00917
00918 n_config=0;
00919 fscanf(config_file, "%d", &datum);
00920 id[n_config]=datum;
00921
00922 do {
00923
00924 fscanf(config_file, "%s", string);
00925
00926 config[n_config]=0;
00927 if (string[0] == '4')config[n_config]=0;
00928 if (string[0] == '2') if (string[7] == 'E')config[n_config]=1;
00929 if (string[0] == '2') if (string[7] == 'F')config[n_config]=2;
00930 if (string[0] == '2') if (string[7] == 'G')config[n_config]=3;
00931 if (string[0] == '2') if (string[7] == 'H')config[n_config]=4;
00932 if (string[0] == '1') if (string[7] == 'E')config[n_config]=5;
00933 if (string[0] == '1') if (string[7] == 'F')config[n_config]=6;
00934 if (string[0] == '1') if (string[7] == 'G')config[n_config]=7;
00935 if (string[0] == '1') if (string[7] == 'H')config[n_config]=8;
00936
00937
00938 fscanf(config_file, "%s", string);
00939
00940 fscanf(config_file, "%s", string);
00941
00942 fscanf(config_file, "%s", string);
00943
00944 if (string[0] == 'N') tab[n_config]=-1;
00945 if (string[0] == 'c') tab[n_config]=0;
00946
00947 fscanf(config_file, "%s", string);
00948
00949 fscanf(config_file, "%d", &datum);
00950
00951 fscanf(config_file, "%d", &datum);
00952
00953 fscanf(config_file, "%s", string);
00954
00955 fscanf(config_file, "%d", &datum);
00956 nrows[n_config]=datum;
00957
00958 fscanf(config_file, "%d", &datum);
00959 ncols[n_config]=datum;
00960
00961 fscanf(config_file, "%d", &datum);
00962 rowstr[n_config]=datum;
00963
00964 fscanf(config_file, "%d", &datum);
00965 colstr[n_config]=datum;
00966
00967 fscanf(config_file, "%d", &datum);
00968
00969 fscanf(config_file, "%d", &datum);
00970
00971
00972
00973 ++n_config;
00974 fscanf(config_file, "%d", &datum);
00975 id[n_config]=datum;
00976
00977
00978
00979
00980 }
00981 while (!feof(config_file) && n_config < maxtab);
00982
00983 fclose(config_file);
00984 }
00985
00986
00987
00988 for (i=0; i<n_config; ++i) if (id[i] == HIMGCFID) idn=i;
00989
00990 skip_x=ncols[idn]/2;
00991 skip_y=nrows[idn]/2;
00992
00993
00994
00995 kkx=kx[config[idn]];
00996 nq=kkx[0];
00997 nlin=kkx[2*nq+3-2]*ny/2;
00998 nss=kkx[2*nq+3-1]*nx/2;
00999
01000
01001
01002 if (idn == -1)
01003 {printf("Error: invalid HIMGCFID\n"); status=2;}
01004 else
01005 {
01006 if (tab[idn] != -1)
01007 {
01008 filename_croptable=filename_table[tab[idn]];
01009 crop_table=fopen(filename_croptable, "r");
01010
01011
01012 fscanf(crop_table, "%d", &datum);
01013
01014 fscanf(crop_table, "%d", &datum);
01015 fscanf(crop_table, "%d", &nqq);
01016
01017 for (j=0; j<nqq; ++j)
01018 {
01019 fscanf(crop_table, "%d", &skip);
01020 fscanf(crop_table, "%d", &take);
01021 skipt[j]=skip;
01022 taket[j]=take;
01023 }
01024
01025 fclose(crop_table);
01026 }
01027 else
01028 {
01029 printf("no crop table\n");
01030
01031 for (k=0; k<nq; ++k)
01032 for (j=0; j<nlin; ++j)
01033 {
01034 skipt[k*nss+j]=0;
01035 taket[k*nss+j]=nss;
01036 }
01037 }
01038
01039 nsx=nss-skip_x;
01040 nsy=nlin-skip_y;
01041
01042
01043
01044 for (k=0; k<nq; ++k)
01045 {
01046 x_orig=kkx[k*2+1]*nx - kkx[k*2+1];
01047 y_orig=kkx[k*2+2]*ny - kkx[k*2+2];
01048 x_dir=-(kkx[k*2+1])*2+1;
01049 y_dir=-(kkx[k*2+2])*2+1;
01050
01051
01052 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;
01053 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;
01054
01055
01056 for (j=0; j<nsy; ++j)
01057 {
01058 jx=j+skip_y;
01059
01060 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;}
01061 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;}
01062 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;}
01063 }
01064 }
01065
01066
01067
01068 for(k=0;k<nx*ny;++k)
01069 {
01070 if(Mask[k] == 0)
01071 {
01072 if(isnan(image[k])) Mask[k] = 1;
01073 }
01074 }
01075
01076
01077
01078 if(ncosmic != -1 && nbadperm != -1) nBadPixels = nbadperm;
01079 if(nBadPixels > 0)
01080 {
01081 for (k=0;k<nBadPixels;++k)
01082 {
01083 if(Mask[badpixellist[k]] == 0) Mask[badpixellist[k]] = 1;
01084 }
01085 }
01086
01087
01088 if(ncosmic > 0)
01089 {
01090 for (k=0;k<ncosmic;++k)
01091 {
01092 if(Mask[cosmicraylist[k]] == 0) Mask[cosmicraylist[k]] = 1;
01093 }
01094 }
01095
01096 status=0;
01097
01098 }
01099
01100 free(id);
01101 free(nrows);
01102 free(ncols);
01103 free(rowstr);
01104 free(colstr);
01105 free(config);
01106 free(kx);
01107 free(filename_table);
01108 id=NULL;
01109 nrows=NULL;
01110 ncols=NULL;
01111 rowstr=NULL;
01112 colstr=NULL;
01113 config=NULL;
01114 kx=NULL;
01115 filename_table=NULL;
01116
01117 return status;
01118 }
01119
01120
01121
01122 char *iquv_version()
01123 {
01124 return strdup("$Id: HMI_IQUV_averaging.c,v 1.55 2017/10/11 16:40:58 yliu Exp $");
01125 }
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144 int DoIt(void)
01145 {
01146
01147 #define MaxNString 512 //maximum length of strings in character number
01148 int errbufstat =setvbuf(stderr, NULL, _IONBF, BUFSIZ);
01149 int outbufstat =setvbuf(stdout, NULL, _IONBF, BUFSIZ);
01150
01151
01152
01153
01154 char *inRecQuery = cmdparams_get_str(&cmdparams, kRecSetIn, NULL);
01155 char *inRecQuery2 = cmdparams_get_str(&cmdparams, kRecSetIn2, NULL);
01156 int WavelengthID = cmdparams_get_int(&cmdparams,WaveLengthIn , NULL);
01157 int CamId = cmdparams_get_int(&cmdparams,CamIDIn, NULL);
01158 TIME DataCadence = cmdparams_get_double(&cmdparams,DataCadenceIn,NULL);
01159 int Npolin = cmdparams_get_int(&cmdparams,NpolIn, NULL);
01160 int Framelistsizein = cmdparams_get_int(&cmdparams,FramelistSizeIn,NULL);
01161 char *inLev1Series = cmdparams_get_str(&cmdparams,SeriesIn, NULL);
01162 int QuickLook = cmdparams_get_int(&cmdparams,QuickLookIn, NULL);
01163 int Averaging = cmdparams_get_int(&cmdparams,Average, NULL);
01164 int inRotationalFlat = cmdparams_get_int(&cmdparams,RotationalFlat, NULL);
01165 char *dpath = cmdparams_get_str(&cmdparams,"dpath", NULL);
01166 int inLinearity = cmdparams_get_int(&cmdparams,Linearity, NULL);
01167
01168
01169 char *CODEVERSION =NULL;
01170 CODEVERSION=iquv_version();
01171 char *CODEVERSION1=NULL;
01172 CODEVERSION1=interpol_version();
01173 char *CODEVERSION2=NULL;
01174 CODEVERSION2=interpol_version();
01175 char *CODEVERSION3=NULL;
01176 CODEVERSION3=polcal_version();
01177
01178
01179 char *DISTCOEFPATH=NULL;
01180 char *ROTCOEFPATH =NULL;
01181
01182
01183 char HISTORY[MaxNString];
01184
01185 char COMMENT[MaxNString];
01186 strcpy(COMMENT,"De-rotation: ON; Un-distortion: ON; Re-centering: ON; Re-sizing: OFF; correction for cosmic-ray hits; RSUNerr=5.0 pixels; correction front/side intensity implemented for mod L; dpath=");
01187 strcat(COMMENT,dpath);
01188 if(inLinearity == 1) strcat(COMMENT,"; linearity=1 with coefficients updated on 2014/01/15");
01189 if(inRotationalFlat == 1) strcat(COMMENT,"; rotational=1");
01190 strcat(COMMENT,"; propagate eclipse bit from level 1");
01191
01192 struct init_files initfiles;
01193
01194
01195
01196
01197
01198
01199
01200 char *DISTCOEFFILEF=NULL;
01201 char *DISTCOEFFILES=NULL;
01202 char *ROTCOEFFILE=NULL;
01203
01204 char dpath2[MaxNString];
01205 strcpy(dpath2,dpath);
01206 DISTCOEFFILEF=strdup(strcat(dpath2,"/../libs/lev15/distmodel_front_o6_100624.txt"));
01207 strcpy(dpath2,dpath);
01208 DISTCOEFFILES=strdup(strcat(dpath2,"/../libs/lev15/distmodel_side_o6_100624.txt"));
01209 strcpy(dpath2,dpath);
01210 ROTCOEFFILE =strdup(strcat(dpath2,"/../libs/lev15/rotcoef_file.txt"));
01211 strcpy(dpath2,dpath);
01212 DISTCOEFPATH =strdup(strcat(dpath2,"/../libs/lev15/"));
01213 strcpy(dpath2,dpath);
01214 ROTCOEFPATH =strdup(strcat(dpath2,"/../libs/lev15/"));
01215
01216
01217
01218 initfiles.dist_file_front=DISTCOEFFILEF;
01219 initfiles.dist_file_side=DISTCOEFFILES;
01220 initfiles.diffrot_coef=ROTCOEFFILE;
01221
01222
01223 if(CamId == 0) CamId = LIGHT_SIDE;
01224 else CamId = LIGHT_FRONT;
01225
01226 if(QuickLook != 0 && QuickLook != 1)
01227 {
01228 printf("The parameter quicklook must be either 0 or 1\n");
01229 return 1;
01230
01231 }
01232
01233
01234 printf("COMMAND LINE PARAMETERS= %s %s %d %d %f %d %d %d %d %s %d\n",inRecQuery,inRecQuery2,WavelengthID,CamId,DataCadence,Npolin,QuickLook,Averaging,inRotationalFlat,dpath,inLinearity);
01235
01236
01237
01238
01239 TIME AverageTime;
01240 if(Averaging == 12) AverageTime=720.;
01241 else AverageTime=5760.;
01242
01243
01244 int NumWavelengths=10;
01245 int MaxNumFiltergrams=72;
01246 int TempIntNum;
01247 TIME TimeCaution = DataCadence;
01248 const int nRecmax = 23040;
01249 char HMISeriesLev1[MaxNString];
01250 char HMISeriesLev1p[MaxNString];
01251 char HMISeriesLev10[MaxNString];
01252
01253 TIME CadenceRead;
01254 int nWavelengths;
01255
01256
01257
01258 TempIntNum=ceil((AverageTime*1.5+90.)/DataCadence);
01259
01260 if(TempIntNum % 2 != 0) TempIntNum+=1;
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273 DRMS_RecordSet_t *recLev1 = NULL;
01274 DRMS_RecordSet_t *recLev1p = NULL;
01275 DRMS_RecordSet_t *rectemp = NULL;
01276 DRMS_RecordSet_t *recflat = NULL;
01277 DRMS_RecordSet_t *recflatrot= NULL;
01278
01279 char CosmicRaySeries[MaxNString]= "hmi.cosmic_rays";
01280 char HMISeries[MaxNString];
01281 char timeBegin[MaxNString] ="2000.12.25_00:00:00";
01282 char timeEnd[MaxNString] ="2000.12.25_00:00:00";
01283 char timeBegin2[MaxNString]="2000.12.25_00:00:00";
01284 char timeEnd2[MaxNString] ="2000.12.25_00:00:00";
01285 char **IMGTYPE=NULL;
01286 char HMISeriesTemp[MaxNString];
01287 char HMISeriesTemperature[MaxNString]= "hmi.temperature_summary_300s";
01288 char DATEOBS[MaxNString];
01289 char jsocverss[MaxNString];
01290 char **HWLTNSET=NULL;
01291 char TargetISS[]="CLOSED";
01292 char FSNtemps[]="00000000000000";
01293 char **source;
01294 char recnums[MaxNString];
01295 char HMIRotationalFlats[MaxNString]= "hmi.flatfield_update";
01296 char HMIFlatField0[MaxNString];
01297 char *HMIFlatField;
01298
01299 TIME MaxSearchDistanceL,MaxSearchDistanceR;
01300
01301
01302
01303 TIME TREC_EPOCH = sscan_time("1993.01.01_00:00:00_TAI");
01304 TIME TREC_EPOCH0= sscan_time("1993.01.01_00:00:00_TAI");
01305
01306 TIME TREC_STEP = AverageTime;
01307 TIME temptime=0.0, temptime2=0.0;
01308 TIME TimeBegin,TimeEnd,TimeBegin2,TimeEnd2,TargetTime,PreviousTargetTime;
01309 TIME *internTOBS=NULL ;
01310 TIME tobs;
01311
01312 int combine;
01313 int combineornot, combineYesNo;
01314 int ThresholdPol=TempIntNum-2;
01315 int npol=Npolin;
01316 int npolout=4;
01317 int fsn;
01318 int method=1;
01319 int *ps1=NULL,*ps2=NULL,*ps3=NULL;
01320 int axisin[2] ;
01321 int axisout[2];
01322 int nTime=0;
01323 int PHWPLPOS[MaxNumFiltergrams*7];
01324 int WavelengthIndex[MaxNumFiltergrams], WavelengthLocation[MaxNumFiltergrams], OrganizeFramelist=0, OrganizeFramelist2=0, *FramelistArray=NULL, *SegmentStatus=NULL;
01325 int FiltergramLocation, Needed;
01326 int TargetWavelength=0;
01327 int *IndexFiltergram=NULL;
01328 int nIndexFiltergram;
01329 int TargetHFLID=0;
01330 int TargetHWLPOS[4];
01331 int TargetHPLPOS[3];
01332 int TargetCFINDEX;
01333 int TargetFID;
01334 int nRecs1;
01335 int ActualTempIntNum;
01336 int framelistSize=Framelistsizein;
01337 int PolarizationType;
01338 int i,temp,temp2,k,ii,iii,it,it2,timeindex,j;
01339 int status = DRMS_SUCCESS, status2 = DRMS_SUCCESS, statusA[54], TotalStatus;
01340 int *HWL1POS=NULL;
01341 int *HWL2POS=NULL;
01342 int *HWL3POS=NULL;
01343 int *HWL4POS=NULL;
01344 int *HPL1POS=NULL;
01345 int *HPL2POS=NULL;
01346 int *HPL3POS=NULL;
01347 int *FID=NULL;
01348 int *HFLID=NULL;
01349 int *CFINDEX=NULL;
01350 int *FSN=NULL;
01351 int *HIMGCFID=NULL;
01352 int *HWLTID=NULL;
01353 int *HPLTID=NULL;
01354 int WavelengthID2;
01355 int *KeywordMissing=NULL;
01356 int *SegmentRead=NULL;
01357
01358
01359
01360 int *Badkeyword=NULL;
01361 int *HCAMID=NULL;
01362 int ngood;
01363 int camera;
01364 int *CARROTint=NULL;
01365 int *CARROT=NULL;
01366 int *NBADPERM=NULL;
01367 int fidfilt;
01368 int TargetHWLTID;
01369 int TargetHPLTID;
01370 int CreateEmptyRecord=0;
01371 int *QUALITY=NULL;
01372 int FIDValues[MaxNumFiltergrams];
01373 int CameraValues[MaxNumFiltergrams];
01374 int *CAMAVG=NULL;
01375 int wl=0;
01376 int row,column;
01377 int *QUALITYin=NULL;
01378 int *QUALITYlev1=NULL;
01379 int *QUALITYLEV1=NULL;
01380 int COSMICCOUNT=0;
01381 int initialrun=0;
01382 int *totalTempIntNum;
01383 int *CAMERA=NULL;
01384
01385 long long *CALVER32=NULL;
01386
01387 float *image=NULL;
01388 float **images=NULL;
01389 float **imagesi=NULL;
01390 float **imagesout=NULL;
01391 float *RSUN=NULL;
01392 float *CROTA2=NULL;
01393 float *CRLTOBS=NULL;
01394 double *DSUNOBS=NULL;
01395 float *X0=NULL;
01396 float *Y0=NULL;
01397 float *X0AVG=NULL,*Y0AVG=NULL,*RSUNAVG=NULL;
01398 float *X0ARR=NULL,*Y0ARR=NULL,*RSUNARR=NULL;
01399 float *X0RMS=NULL,*Y0RMS=NULL,*RSUNRMS=NULL;
01400 float TSEL;
01401 float TFRONT;
01402 float *CRLNOBSint=NULL,*CRLTOBSint=NULL,*CROTA2int=NULL,*RSUNint=NULL,ctime1,ctime2;
01403 double *OBSVRint=NULL,*OBSVWint=NULL,*OBSVNint=NULL,*DSUNOBSint=NULL;
01404 float X0AVGT,Y0AVGT;
01405 float cdelt1;
01406 double *OBSVR=NULL;
01407 double *OBSVW=NULL;
01408 double *OBSVN=NULL;
01409 float *CRLNOBS=NULL;
01410
01411 float *CDELT1=NULL;
01412 float RSUNerr=5.0;
01413 float diffXfs= 6.14124;
01414 float diffYfs=-4.28992;
01415 float correction,correction2;
01416 float distance;
01417 float X0LF=0.0,Y0LF=0.0;
01418 float *pztflat;
01419 float *rotflat;
01420 float *EXPTIME=NULL;
01421 float tempvalue=0.0;
01422 float *DATAMEAN=NULL;
01423
01424
01425 char *FSNS = "FSN";
01426 char *TOBSS = "T_OBS";
01427 char *HWL1POSS = "HWL1POS";
01428 char *HWL2POSS = "HWL2POS";
01429 char *HWL3POSS = "HWL3POS";
01430 char *HWL4POSS = "HWL4POS";
01431 char *HPL1POSS = "HPL1POS";
01432 char *HPL2POSS = "HPL2POS";
01433 char *HPL3POSS = "HPL3POS";
01434 char *FIDS = "FID";
01435 char *HFLIDS = "HFLID";
01436 char *HIMGCFIDS = "HIMGCFID";
01437 char *IMGTYPES = "IMG_TYPE";
01438 char *RSUNS = "R_SUN";
01439 char *CROTA2S = "CROTA2";
01440 char *CRLTOBSS = "CRLT_OBS";
01441 char *DSUNOBSS = "DSUN_OBS";
01442 char *CRPIX1S = "CRPIX1";
01443 char *CRPIX2S = "CRPIX2";
01444 char *HCAMIDS = "HCAMID";
01445 char *HCFTIDS = "HCFTID";
01446 char *CDELT1S = "CDELT1";
01447 char *CDELT2S = "CDELT2";
01448 char *CSYSER1S = "CSYSER1";
01449 char *CSYSER2S = "CSYSER2";
01450 char *WCSNAMES = "WCSNAME";
01451 char *OBSVRS = "OBS_VR";
01452 char *OBSVWS = "OBS_VW";
01453 char *OBSVNS = "OBS_VN";
01454 char *CRLNOBSS = "CRLN_OBS";
01455 char *CARROTS = "CAR_ROT";
01456
01457 char *RSUNOBSS = "RSUN_OBS";
01458 char *HWLTIDS = "HWLTID";
01459 char *HPLTIDS = "HPLTID";
01460 char *WavelengthIDS = "WAVELNID";
01461 char *HWLTNSETS = "HWLTNSET";
01462 char *NBADPERMS = "NBADPERM";
01463 char *X0LFS = "X0_LF";
01464 char *Y0LFS = "Y0_LF";
01465 char *COUNTS = "COUNT";
01466 char *FLATREC = "FLAT_REC";
01467 char *CALVER32S = "CALVER32";
01468 char *CALVER64S = "CALVER64";
01469
01470
01471 char *TRECS = "T_REC";
01472 char *TRECEPOCHS = "T_REC_epoch";
01473 char *TRECSTEPS = "T_REC_step";
01474 char *CADENCES = "CADENCE";
01475 char *DATES = "DATE";
01476 char *DATEOBSS = "DATE__OBS";
01477 char *INSTRUMES = "INSTRUME";
01478 char *CAMERAS = "CAMERA";
01479 char *QUALITYS = "QUALITY";
01480 char *HISTORYS = "HISTORY";
01481 char *COMMENTS = "COMMENT";
01482 char *BLDVERSS = "BLD_VERS";
01483 char **TOTVALSS = NULL;
01484 char **DATAVALSS = NULL;
01485 char **MISSVALSS = NULL;
01486 char **DATAMINS = NULL;
01487 char **DATAMAXS = NULL;
01488 char **DATAMEDNS = NULL;
01489 char **DATAMEANS = NULL;
01490 char **DATARMSS = NULL;
01491 char **DATASKEWS = NULL;
01492 char **DATAKURTS = NULL;
01493 char **DATAMINS2 = NULL;
01494 char **DATAMAXS2 = NULL;
01495 char **DATAMEDNS2 = NULL;
01496 char **DATAMEANS2 = NULL;
01497 char **DATARMSS2 = NULL;
01498 char **DATASKEWS2 = NULL;
01499 char **DATAKURTS2 = NULL;
01500 char *TSELS = "TSEL";
01501 char *TFRONTS = "TFRONT";
01502 char *TINTNUMS = "TINTNUM";
01503 char *SINTNUMS = "SINTNUM";
01504 char *DISTCOEFS = "DISTCOEF";
01505 char *ROTCOEFS = "ROTCOEF";
01506 char *ODICOEFFS = "ODICOEFF";
01507 char *OROCOEFFS = "OROCOEFF";
01508 char *POLCALMS = "POLCALM";
01509 char *CODEVER0S = "CODEVER0";
01510 char *CODEVER1S = "CODEVER1";
01511 char *CODEVER2S = "CODEVER2";
01512 char *CODEVER3S = "CODEVER3";
01513 char *TS08 = "T08_PSASM_MEAN";
01514 char *TS01 = "T01_FWMR1_MEAN";
01515 char *TS02 = "T02_FWMR2_MEAN";
01516 char query[MaxNString];
01517 char *ierror = NULL;
01518 char **ierrors = NULL;
01519 char *SOURCES = "SOURCE";
01520 char *QUALLEV1S = "QUALLEV1";
01521 char *ROTFLAT = "ROT_FLAT";
01522 char QueryFlatField[MaxNString];
01523 strcpy(QueryFlatField,"");
01524
01525 DRMS_Array_t **Segments=NULL;
01526 DRMS_Array_t **Ierror=NULL;
01527 DRMS_Array_t *arrin[TempIntNum];
01528 DRMS_Array_t *arrerrors[TempIntNum];
01529 DRMS_Array_t *BadPixels= NULL;
01530 DRMS_Array_t *CosmicRays= NULL;
01531 DRMS_Array_t **arrLev1d= NULL;
01532 DRMS_Array_t **arrLev1p= NULL;
01533 DRMS_Array_t *flatfield=NULL;
01534 DRMS_Array_t *flatfieldrot=NULL;
01535 DRMS_Array_t *rotationalflats=NULL;
01536
01537 DRMS_Segment_t *segin = NULL;
01538 DRMS_Segment_t *segout = NULL;
01539
01540 struct initial const_param;
01541
01542 unsigned char *Mask =NULL;
01543
01544 DRMS_Type_t type1d = DRMS_TYPE_FLOAT;
01545 DRMS_Type_t type1p = DRMS_TYPE_FLOAT;
01546 DRMS_Type_t typet = DRMS_TYPE_TIME;
01547 DRMS_Type_t typeEr = DRMS_TYPE_CHAR;
01548
01549 struct keyword *KeyInterp=NULL;
01550 struct keyword KeyInterpOut;
01551 struct polcal_struct pars;
01552
01553 double minimum,maximum,median,mean,sigma,skewness,kurtosis;
01554 double *keyF=NULL;
01555 double TSTARTFLAT=0.0, TSTOPFLAT=0.0;
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567 double nonlins[]={0.0,0.025409177,-4.0088672e-06,1.0615198e-10};
01568
01569 double nonlinf[]={0.0,0.020677687,-3.1873243e-06,8.7536678e-11};
01570
01571
01572 char Lev1pSegName[40][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"};
01573
01574
01575 DRMS_Record_t *rec = NULL;
01576
01577 float totalfront=0.0;
01578 float totalside=0.0;
01579 int countfront=0;
01580 int countside=0;
01581 float iratio=0.0;
01582
01583
01584
01585
01586 int nthreads;
01587
01588
01589 nthreads=omp_get_max_threads();
01590 printf("NUMBER OF THREADS USED BY OPENMP= %d\n",nthreads);
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604 if(WavelengthID > NumWavelengths-1 || WavelengthID < 0)
01605 {
01606 printf("The parameter WaveLengthIn is not in the range 0-9\n");
01607 return 1;
01608 }
01609
01610
01611
01612 if(DataCadence != 45.0 && DataCadence != 90.0 && DataCadence != 120.0 && DataCadence != 135.0 && DataCadence != 150.0)
01613 {
01614 printf("The parameter cadence should be 45, 90, 120, 135, or 150 seconds\n");
01615 return 1;
01616 }
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634 printf("BEGINNING TIME: %s\n",inRecQuery);
01635 printf("ENDING TIME: %s\n",inRecQuery2);
01636 TimeBegin=sscan_time(inRecQuery);
01637 TimeEnd =sscan_time(inRecQuery2);
01638 printf("TimeBegin= %f\n",TimeBegin);
01639 printf("TimeEnd= %f\n",TimeEnd);
01640
01641
01642 temptime = (TIME)floor((TimeBegin-TREC_EPOCH+TREC_STEP/2.0)/TREC_STEP)*TREC_STEP+TREC_EPOCH;
01643 if(temptime < TimeBegin) temptime += TREC_STEP;
01644
01645 nTime =floor((TimeEnd-temptime)/AverageTime+1.0);
01646 printf("nTime = %d\n",nTime);
01647
01648 if(TimeBegin > TimeEnd)
01649 {
01650 printf("Error: the ending time must be later than the beginning time!\n");
01651 return 1;
01652 }
01653
01654
01655
01656
01657 strcpy(dpath2,dpath);
01658 strcat(dpath2,"/../../../");
01659 status = initialize_interpol(&const_param,&initfiles,4096,4096,dpath2);
01660 if(status != 0)
01661 {
01662 printf("Error: could not initialize the gapfilling, derotation, and temporal interpolation routines\n");
01663 return 1;
01664 }
01665
01666
01667 status = init_polcal(&pars,method);
01668 if(status != 0)
01669 {
01670 printf("Error: could not initialize the polarization calibration routine\n");
01671 return 1;
01672 }
01673
01674
01675
01676
01677 strcpy(HMISeriesLev1,inLev1Series);
01678
01679 strcpy(HMISeriesLev10,HMISeriesLev1);
01680
01681
01682
01683
01684 if(QuickLook == 1)
01685 {
01686 if(AverageTime == 720.0 && (DataCadence == 90.0 || DataCadence == 135.0)) strcpy(HMISeriesLev1p,"hmi.S_720s_nrt");
01687 else
01688 {
01689 if(AverageTime == 720.0 && (DataCadence == 120.0 || DataCadence == 150.0)) strcpy(HMISeriesLev1p,"hmi.S2_720s_nrt");
01690 else
01691 {
01692 printf("No output series exists for your command-line parameters %f %f %s\n",AverageTime,DataCadence,HMISeriesLev1p);
01693 return 1;
01694 }
01695 }
01696
01697
01698 }
01699 else
01700 {
01701 if(AverageTime == 720.0 && DataCadence == 90.0) strcpy(HMISeriesLev1p,"hmi.S_720s");
01702 if(AverageTime == 720.0 && DataCadence == 135.0) strcpy(HMISeriesLev1p,"hmi.S_720s");
01703 if(AverageTime == 720.0 && DataCadence == 120.0) strcpy(HMISeriesLev1p,"hmi.S2_720s");
01704 if(AverageTime == 720.0 && DataCadence == 150.0) strcpy(HMISeriesLev1p,"hmi.S2_720s");
01705
01706 if(AverageTime == 5760.0)strcpy(HMISeriesLev1p,"hmi.S_5760s");
01707 if(AverageTime != 5760.0 && AverageTime != 720.0)
01708 {
01709 printf("No output series exists for your command-line parameters\n");
01710 return 1;
01711 }
01712 }
01713
01714
01715
01716
01717
01718
01719
01720 TimeBegin2=TimeBegin-(TIME)TempIntNum*DataCadence/2.-TimeCaution;
01721 TimeEnd2 =TimeEnd +(TIME)TempIntNum*DataCadence/2.+TimeCaution;
01722 sprint_time(timeBegin2,TimeBegin2,"TAI",0);
01723 sprint_time(timeEnd2,TimeEnd2,"TAI",0);
01724 strcat(HMISeriesLev1,"[");
01725 strcat(HMISeriesLev1,timeBegin2);
01726 strcat(HMISeriesLev1,"-");
01727 strcat(HMISeriesLev1,timeEnd2);
01728 strcat(HMISeriesLev1,"]");
01729
01730
01731
01732
01733 printf("LEVEL 1 SERIES QUERY = %s\n",HMISeriesLev1);
01734 recLev1 = drms_open_records(drms_env,HMISeriesLev1,&status);
01735 if (status == DRMS_SUCCESS && recLev1 != NULL && recLev1->n > 0)
01736 {
01737 nRecs1 = recLev1->n;
01738
01739 if(nRecs1 >= nRecmax)
01740 {
01741 printf("Too many records requested\n");
01742 return 1;
01743 }
01744
01745 printf("Number of level 1 records opened: %d\n",nRecs1);
01746
01747
01748 FSN = (int *)malloc(nRecs1*sizeof(int));
01749 if(FSN == NULL)
01750 {
01751 printf("Error: memory could not be allocated to FSN\n");
01752 return 1;
01753 }
01754 internTOBS = (TIME *)malloc(nRecs1*sizeof(TIME));
01755 if(internTOBS == NULL)
01756 {
01757 printf("Error: memory could not be allocated to internTOBS\n");
01758 return 1;
01759 }
01760 HWL1POS = (int *)malloc(nRecs1*sizeof(int));
01761 if(HWL1POS == NULL)
01762 {
01763 printf("Error: memory could not be allocated to HWL1POS\n");
01764 return 1;
01765 }
01766 HWL2POS = (int *)malloc(nRecs1*sizeof(int));
01767 if(HWL2POS == NULL)
01768 {
01769 printf("Error: memory could not be allocated to HWL2POS\n");
01770 return 1;
01771 }
01772 HWL3POS = (int *)malloc(nRecs1*sizeof(int));
01773 if(HWL3POS == NULL)
01774 {
01775 printf("Error: memory could not be allocated to HWL3POS\n");
01776 return 1;
01777 }
01778 HWL4POS = (int *)malloc(nRecs1*sizeof(int));
01779 if(HWL4POS == NULL)
01780 {
01781 printf("Error: memory could not be allocated to HWL4POS\n");
01782 return 1;
01783 }
01784 HPL1POS = (int *)malloc(nRecs1*sizeof(int));
01785 if(HPL1POS == NULL)
01786 {
01787 printf("Error: memory could not be allocated to HPL1POS\n");
01788 return 1;
01789 }
01790 HPL2POS = (int *)malloc(nRecs1*sizeof(int));
01791 if(HPL2POS == NULL)
01792 {
01793 printf("Error: memory could not be allocated to HPL2POS\n");
01794 return 1;
01795 }
01796 HPL3POS = (int *)malloc(nRecs1*sizeof(int));
01797 if(HPL3POS == NULL)
01798 {
01799 printf("Error: memory could not be allocated to HPL3POS\n");
01800 return 1;
01801 }
01802 FID = (int *)malloc(nRecs1*sizeof(int));
01803 if(FID == NULL)
01804 {
01805 printf("Error: memory could not be allocated to FID\n");
01806 return 1;
01807 }
01808 HFLID = (int *)malloc(nRecs1*sizeof(int));
01809 if(HFLID == NULL)
01810 {
01811 printf("Error: memory could not be allocated to HFLID\n");
01812 return 1;
01813 }
01814 HCAMID = (int *)malloc(nRecs1*sizeof(int));
01815 if(HCAMID == NULL)
01816 {
01817 printf("Error: memory could not be allocated to HCAMID\n");
01818 return 1;
01819 }
01820 RSUN = (float *)malloc(nRecs1*sizeof(float));
01821 if(RSUN == NULL)
01822 {
01823 printf("Error: memory could not be allocated to RSUN\n");
01824 return 1;
01825 }
01826 CROTA2 = (float *)malloc(nRecs1*sizeof(float));
01827 if(CROTA2 == NULL)
01828 {
01829 printf("Error: memory could not be allocated to CROTA2\n");
01830 return 1;
01831 }
01832 CRLTOBS = (float *)malloc(nRecs1*sizeof(float));
01833 if(CRLTOBS == NULL)
01834 {
01835 printf("Error: memory could not be allocated to CRLTOBS\n");
01836 return 1;
01837 }
01838 DSUNOBS = (double *)malloc(nRecs1*sizeof(double));
01839 if(DSUNOBS == NULL)
01840 {
01841 printf("Error: memory could not be allocated to DSUNOBS\n");
01842 return 1;
01843 }
01844 X0 = (float *)malloc(nRecs1*sizeof(float));
01845 if(X0 == NULL)
01846 {
01847 printf("Error: memory could not be allocated to X0\n");
01848 return 1;
01849 }
01850 Y0 = (float *)malloc(nRecs1*sizeof(float));
01851 if(Y0 == NULL)
01852 {
01853 printf("Error: memory could not be allocated to Y0\n");
01854 return 1;
01855 }
01856 SegmentRead= (int *)malloc(nRecs1*sizeof(int));
01857 if(SegmentRead == NULL)
01858 {
01859 printf("Error: memory could not be allocated to SegmentRead\n");
01860 return 1;
01861 }
01862 KeywordMissing= (int *)malloc(nRecs1*sizeof(int));
01863 if(KeywordMissing == NULL)
01864 {
01865 printf("Error: memory could not be allocated to KeywordMissing\n");
01866 return 1;
01867 }
01868 Segments = (DRMS_Array_t **)malloc(nRecs1*sizeof(DRMS_Array_t *));
01869 if(Segments == NULL)
01870 {
01871 printf("Error: memory could not be allocated to Segments\n");
01872 return 1;
01873 }
01874 for(i=0;i<nRecs1;i++) Segments[i]=NULL;
01875 Ierror = (DRMS_Array_t **)malloc(nRecs1*sizeof(DRMS_Array_t *));
01876 if(Ierror == NULL)
01877 {
01878 printf("Error: memory could not be allocated to Ierror\n");
01879 return 1;
01880 }
01881 for(i=0;i<nRecs1;i++) Ierror[i]=NULL;
01882 IndexFiltergram = (int *)malloc(nRecs1*sizeof(int));
01883 if(IndexFiltergram == NULL)
01884 {
01885 printf("Error: memory could not be allocated to IndexFiltergram\n");
01886 return 1;
01887 }
01888 CFINDEX = (int *)malloc(nRecs1*sizeof(int));
01889 if(CFINDEX == NULL)
01890 {
01891 printf("Error: memory could not be allocated to CFINDEX\n");
01892 return 1;
01893 }
01894 HIMGCFID = (int *)malloc(nRecs1*sizeof(int));
01895 if(HIMGCFID == NULL)
01896 {
01897 printf("Error: memory could not be allocated to HIMGCFID\n");
01898 return 1;
01899 }
01900 IMGTYPE = (char **)malloc(nRecs1*sizeof(char *));
01901 if(IMGTYPE == NULL)
01902 {
01903 printf("Error: memory could not be allocated to IMGTYPE\n");
01904 return 1;
01905 }
01906 for(i=0;i<nRecs1;i++) IMGTYPE[i]=NULL;
01907 CDELT1 = (float *)malloc(nRecs1*sizeof(float));
01908 if(CDELT1 == NULL)
01909 {
01910 printf("Error: memory could not be allocated to CDELT1\n");
01911 return 1;
01912 }
01913 OBSVR = (double *)malloc(nRecs1*sizeof(double));
01914 if(OBSVR == NULL)
01915 {
01916 printf("Error: memory could not be allocated to OBSVR\n");
01917 return 1;
01918 }
01919 OBSVW = (double *)malloc(nRecs1*sizeof(double));
01920 if(OBSVW == NULL)
01921 {
01922 printf("Error: memory could not be allocated to OBSVW\n");
01923 return 1;
01924 }
01925 OBSVN = (double *)malloc(nRecs1*sizeof(double));
01926 if(OBSVN == NULL)
01927 {
01928 printf("Error: memory could not be allocated to OBSVN\n");
01929 return 1;
01930 }
01931 CRLNOBS = (float *)malloc(nRecs1*sizeof(float));
01932 if(CRLNOBS == NULL)
01933 {
01934 printf("Error: memory could not be allocated to CRLNOBS\n");
01935 return 1;
01936 }
01937
01938
01939
01940
01941
01942
01943 CARROT = (int *)malloc(nRecs1*sizeof(int));
01944 if(CARROT == NULL)
01945 {
01946 printf("Error: memory could not be allocated to CARROT\n");
01947 return 1;
01948 }
01949 HWLTID = (int *)malloc(nRecs1*sizeof(int));
01950 if(HWLTID == NULL)
01951 {
01952 printf("Error: memory could not be allocated to HWLTID\n");
01953 return 1;
01954 }
01955 HPLTID = (int *)malloc(nRecs1*sizeof(int));
01956 if(HPLTID == NULL)
01957 {
01958 printf("Error: memory could not be allocated to HPLTID\n");
01959 return 1;
01960 }
01961 HWLTNSET = (char **)malloc(nRecs1*sizeof(char *));
01962 if(HWLTNSET == NULL)
01963 {
01964 printf("Error: memory could not be allocated to HWLTNSET\n");
01965 return 1;
01966 }
01967 NBADPERM = (int *)malloc(nRecs1*sizeof(int));
01968 if(NBADPERM == NULL)
01969 {
01970 printf("Error: memory could not be allocated to NBADPERM\n");
01971 return 1;
01972 }
01973 QUALITYin = (int *)malloc(nRecs1*sizeof(int));
01974 if(QUALITYin == NULL)
01975 {
01976 printf("Error: memory could not be allocated to QUALITYin\n");
01977 return 1;
01978 }
01979 QUALITYlev1 = (int *)malloc(nRecs1*sizeof(int));
01980 if(QUALITYlev1 == NULL)
01981 {
01982 printf("Error: memory could not be allocated to QUALITYlev1\n");
01983 return 1;
01984 }
01985 for(i=0;i<nRecs1;++i) QUALITYlev1[i]=0;
01986 EXPTIME = (float *)malloc(nRecs1*sizeof(float));
01987 if(EXPTIME == NULL)
01988 {
01989 printf("Error: memory could not be allocated to EXPTIME\n");
01990 return 1;
01991 }
01992 CALVER32 = (long long *)malloc(nRecs1*sizeof(long long));
01993 if(CALVER32 == NULL)
01994 {
01995 printf("Error: memory could not be allocated to CALVER32\n");
01996 return 1;
01997 }
01998 CAMERA = (int *)malloc(nRecs1*sizeof(int));
01999 if(CAMERA == NULL)
02000 {
02001 printf("Error: memory could not be allocated to CAMERA\n");
02002 return 1;
02003 }
02004 DATAMEAN = (float *)malloc(nRecs1*sizeof(float));
02005 if(DATAMEAN == NULL)
02006 {
02007 printf("Error: memory could not be allocated to DATAMEAN\n");
02008 return 1;
02009 }
02010
02011
02012
02013
02014
02015 k=0;
02016 int CamYesNo=0, FIDshow;
02017
02018 for(i=0;i<nRecs1;++i)
02019 {
02020 FSN[i] = drms_getkey_int(recLev1->records[i] ,FSNS ,&statusA[0]);
02021 internTOBS[i] = drms_getkey_time(recLev1->records[i],TOBSS ,&statusA[1]);
02022 HWL1POS[i] = drms_getkey_int(recLev1->records[i] ,HWL1POSS ,&statusA[2]);
02023 HWL2POS[i] = drms_getkey_int(recLev1->records[i] ,HWL2POSS ,&statusA[3]);
02024 HWL3POS[i] = drms_getkey_int(recLev1->records[i] ,HWL3POSS ,&statusA[4]);
02025 HWL4POS[i] = drms_getkey_int(recLev1->records[i] ,HWL4POSS ,&statusA[5]);
02026 HPL1POS[i] = drms_getkey_int(recLev1->records[i] ,HPL1POSS ,&statusA[6]);
02027 HPL2POS[i] = drms_getkey_int(recLev1->records[i] ,HPL2POSS ,&statusA[7]);
02028 HPL3POS[i] = drms_getkey_int(recLev1->records[i] ,HPL3POSS ,&statusA[8]);
02029 FID[i] = drms_getkey_int(recLev1->records[i] ,FIDS ,&statusA[9]);
02030 HFLID[i] = drms_getkey_int(recLev1->records[i] ,"HFTSACID" ,&statusA[10]);
02031
02032 CamYesNo = drms_getkey_int(recLev1->records[i] ,"CAMERA" ,&status);
02033 FIDshow = drms_getkey_int(recLev1->records[i] ,"FID" ,&status);
02034
02035
02036
02037
02038
02039 if (CamYesNo == 2)
02040 {
02041 iii=needtochangeFID(HFLID[i]);
02042 if(iii == 1)
02043 {
02044 ii = drms_getkey_int(recLev1->records[i],"HFLPSITN",&status);
02045 if( (ii%72)/24 == 1)
02046 {
02047 FID[i]=FID[i]+100000;
02048
02049 }
02050 }
02051
02052 }
02053
02054 HCAMID[i] = drms_getkey_int(recLev1->records[i] ,HCAMIDS ,&statusA[11]);
02055 if(HCAMID[i] != LIGHT_SIDE && HCAMID[i] != LIGHT_FRONT) statusA[11]=1;
02056 CFINDEX[i] = drms_getkey_int(recLev1->records[i] ,HCFTIDS ,&statusA[12]);
02057 IMGTYPE[i] = (char *)malloc(6*sizeof(char *));
02058 if(IMGTYPE[i] == NULL)
02059 {
02060 printf("Error: memory could not be allocated to IMGTYPE[%d]\n",i);
02061 return 1;
02062 }
02063 IMGTYPE[i] = drms_getkey_string(recLev1->records[i],IMGTYPES ,&statusA[13]);
02064 X0[i] = (float)drms_getkey_double(recLev1->records[i],CRPIX1S, &statusA[14]);
02065 if(statusA[14] == DRMS_SUCCESS && !isnan(X0[i])) X0[i]=X0[i]-1.0;
02066 else statusA[14] = 1;
02067 Y0[i] = (float)drms_getkey_double(recLev1->records[i],CRPIX2S,&statusA[15]);
02068 if(statusA[15] == DRMS_SUCCESS && !isnan(Y0[i])) Y0[i]=Y0[i]-1.0;
02069 else statusA[15] = 1;
02070
02071
02072 X0LF = (float)drms_getkey_double(recLev1->records[i],X0LFS, &status);
02073 Y0LF = (float)drms_getkey_double(recLev1->records[i],Y0LFS, &status2);
02074 if(status != DRMS_SUCCESS || status2 != DRMS_SUCCESS || isnan(X0LF) || isnan(Y0LF))
02075 {
02076 statusA[14]=1;
02077 statusA[15]=1;
02078 X0[i]=sqrt(-1);
02079 Y0[i]=sqrt(-1);
02080 KeywordMissing[i]=1;
02081 }
02082
02083
02084 RSUN[i] = (float)drms_getkey_double(recLev1->records[i],RSUNS ,&statusA[16]);
02085 if(isnan(RSUN[i])) statusA[16]=1;
02086 CROTA2[i] = (float)drms_getkey_double(recLev1->records[i],CROTA2S ,&statusA[17]);
02087
02088
02089 if(statusA[17] == DRMS_SUCCESS && !isnan(CROTA2[i]))
02090 {
02091 if(CROTA2[i] > 362. || CROTA2[i] < -362.) statusA[17] = 1;
02092 }
02093
02094 if(statusA[17] == DRMS_SUCCESS && !isnan(CROTA2[i])) CROTA2[i]=-CROTA2[i];
02095 else statusA[17] = 1;
02096 CRLTOBS[i] = (float)drms_getkey_double(recLev1->records[i],CRLTOBSS,&statusA[18]);
02097 if(isnan(CRLTOBS[i])) statusA[18] = 1;
02098 DSUNOBS[i] = drms_getkey_double(recLev1->records[i],DSUNOBSS,&statusA[19]);
02099 if(isnan(DSUNOBS[i])) statusA[19] = 1;
02100 HIMGCFID[i] = drms_getkey_int(recLev1->records[i] ,HIMGCFIDS ,&statusA[20]);
02101 if(isnan(HIMGCFID[i])) statusA[20] = 1;
02102 CDELT1[i] = (float)drms_getkey_double(recLev1->records[i] ,CDELT1S,&statusA[21]);
02103 if(isnan(CDELT1[i])) statusA[21] = 1;
02104 OBSVR[i] = drms_getkey_double(recLev1->records[i] ,OBSVRS ,&statusA[22]);
02105 if(isnan(OBSVR[i])) statusA[22] = 1;
02106 OBSVW[i] = drms_getkey_double(recLev1->records[i] ,OBSVWS ,&statusA[23]);
02107 if(isnan(OBSVW[i])) statusA[23] = 1;
02108 OBSVN[i] = drms_getkey_double(recLev1->records[i] ,OBSVNS ,&statusA[24]);
02109 if(isnan(OBSVN[i])) statusA[24] = 1;
02110 CARROT[i] = drms_getkey_int(recLev1->records[i] ,CARROTS ,&statusA[25]);
02111 SegmentRead[i]= 0;
02112 KeywordMissing[i]=0;
02113 CRLNOBS[i] = (float)drms_getkey_double(recLev1->records[i] ,CRLNOBSS,&statusA[26]);
02114 if(isnan(CRLNOBS[i])) statusA[26] = 1;
02115
02116
02117
02118 statusA[27]=0;
02119
02120
02121 HWLTID[i] = drms_getkey_int(recLev1->records[i] ,HWLTIDS ,&statusA[28]);
02122 HPLTID[i] = drms_getkey_int(recLev1->records[i] ,HPLTIDS ,&statusA[29]);
02123 HWLTNSET[i] = (char *)malloc(7*sizeof(char *));
02124 if(HWLTNSET[i] == NULL)
02125 {
02126 printf("Error: memory could not be allocated to HWLTNSET[%d]\n",i);
02127 return 1;
02128 }
02129 HWLTNSET[i] = drms_getkey_string(recLev1->records[i] ,HWLTNSETS ,&statusA[30]);
02130 EXPTIME[i] = (float)drms_getkey_double(recLev1->records[i],"EXPTIME",&statusA[31]);
02131
02132 NBADPERM[i] = drms_getkey_int(recLev1->records[i] ,NBADPERMS ,&statusA[32]);
02133 if(statusA[32] != DRMS_SUCCESS) NBADPERM[i]=-1;
02134 QUALITYin[i] = drms_getkey_int(recLev1->records[i] ,QUALITYS ,&statusA[33]);
02135 if(statusA[33] != DRMS_SUCCESS) KeywordMissing[i]=1;
02136
02137 if( (QUALITYin[i] & Q_MISSING_SEGMENT) == Q_MISSING_SEGMENT)
02138 {
02139 statusA[33]=1;
02140 SegmentRead[i]= -1;
02141 KeywordMissing[i]=1;
02142 }
02143
02144 CALVER32[i] = (long long)drms_getkey_int(recLev1->records[i] ,CALVER32S ,&statusA[34]);
02145 if(statusA[34] != DRMS_SUCCESS)
02146 {
02147 CALVER32[i]=CALVER_DEFAULT;
02148 KeywordMissing[i]=1;
02149 }
02150 if( CALVER32[i] != CALVER32[0] )
02151 {
02152 printf("Error: CALVER32[%d] is different from CALVER32[0]\n",i);
02153 return 1;
02154 }
02155 CAMERA[i] = drms_getkey_int(recLev1->records[i],CAMERAS,&statusA[35]);
02156 if(CAMERA[i] == -2147483648 || statusA[35] != DRMS_SUCCESS) KeywordMissing[i]=1;
02157
02158 DATAMEAN[i] = (float)drms_getkey_double(recLev1->records[i],"DATAMEAN",&statusA[36]);
02159 if(statusA[36] != DRMS_SUCCESS) KeywordMissing[i]=1;
02160
02161
02162
02163
02164
02165
02166
02167
02168
02169
02170
02171
02172
02173
02174
02175
02176 TotalStatus=0;
02177 for(ii=0;ii<=13;++ii) TotalStatus+=statusA[ii];
02178 for(ii=16;ii<=31;++ii) TotalStatus+=statusA[ii];
02179 if(TotalStatus != 0 || !strcmp(IMGTYPE[i],"DARK") )
02180 {
02181 printf("Error: the level 1 filtergram index %d is missing at least one keyword, or is a dark frame\n",i);
02182 for(iii=0;iii<=36;++iii) printf(" %d ",statusA[iii]);
02183 printf("\n");
02184
02185 FID[i] = MISSINGKEYWORDINT;
02186 FSN[i] = MISSINGKEYWORDINT;
02187 internTOBS[i] = MISSINGKEYWORD;
02188 HWL1POS[i] = MISSINGKEYWORDINT;
02189 HWL2POS[i] = MISSINGKEYWORDINT;
02190 HWL3POS[i] = MISSINGKEYWORDINT;
02191 HWL4POS[i] = MISSINGKEYWORDINT;
02192 HPL1POS[i] = MISSINGKEYWORDINT;
02193 HPL2POS[i] = MISSINGKEYWORDINT;
02194 HPL3POS[i] = MISSINGKEYWORDINT;
02195 X0[i] = MISSINGKEYWORD;
02196 Y0[i] = MISSINGKEYWORD;
02197 RSUN[i] = MISSINGKEYWORD;
02198 CROTA2[i] = MISSINGKEYWORD;
02199 CRLTOBS[i] = MISSINGKEYWORD;
02200 DSUNOBS[i] = MISSINGKEYWORD;
02201 HIMGCFID[i] = MISSINGKEYWORD;
02202 CDELT1[i] = MISSINGKEYWORD;
02203 OBSVR[i] = MISSINGKEYWORD;
02204 OBSVW[i] = MISSINGKEYWORD;
02205 OBSVN[i] = MISSINGKEYWORD;
02206 CARROT[i] = MISSINGKEYWORDINT;
02207 HCAMID[i] = MISSINGKEYWORDINT;
02208 CRLNOBS[i] = MISSINGKEYWORD;
02209
02210 HWLTID[i] = MISSINGKEYWORD;
02211 HPLTID[i] = MISSINGKEYWORD;
02212 strcpy(HWLTNSET[i],"NONE");
02213 EXPTIME[i] = MISSINGKEYWORD;
02214 DATAMEAN[i] = MISSINGKEYWORD;
02215
02216 KeywordMissing[i]=1;
02217 }
02218 else
02219 {
02220 if(WhichWavelength(FID[i]) == WavelengthID && HCAMID[i] == CamId)
02221 {
02222 IndexFiltergram[k]=i;
02223 ++k;
02224 }
02225 }
02226 }
02227
02228 nIndexFiltergram=k;
02229 if(nIndexFiltergram == 0)
02230 {
02231 printf("Error: no filtergram was found with the wavelength %d in the requested level 1 records %s\n",WavelengthID,HMISeriesLev1);
02232
02233 }
02234
02235 }
02236 else
02237 {
02238
02239
02240 printf("Error: no level 1 records in the time interval requested %s\n",HMISeriesLev1);
02241 return 1;
02242 }
02243
02244
02245
02246 for(i=0;i<nRecs1;++i)
02247 {
02248 if( (KeywordMissing[i] !=1) && (HCAMID[i] == LIGHT_FRONT) && (WhichWavelength(FID[i]) == 5) )
02249 {totalfront += DATAMEAN[i];
02250 countfront += 1;
02251 }
02252 if( (KeywordMissing[i] !=1) && (HCAMID[i] == LIGHT_SIDE) && (WhichWavelength(FID[i]) == 5) )
02253 {totalside += DATAMEAN[i];
02254 countside += 1;
02255 }
02256 }
02257 if(countfront != 0 && countside !=0)
02258 {
02259 totalfront = totalfront/(float)countfront;
02260 totalside = totalside/(float)countside;
02261 iratio = totalfront/totalside;
02262
02263 }
02264 else
02265 {
02266 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");
02267 iratio = 1.05;
02268 }
02269
02270
02271
02272
02273 printf("CREATE %d LEVEL 1p RECORDS\n",nTime);
02274 recLev1p = drms_create_records(drms_env,nTime,HMISeriesLev1p,DRMS_PERMANENT,&status);
02275 if (status != DRMS_SUCCESS || recLev1p == NULL || recLev1p->n == 0)
02276 {
02277 printf("Could not create records for the level 1p series\n");
02278 return 1;
02279 }
02280 TREC_EPOCH=drms_getkey_time(recLev1p->records[0],TRECEPOCHS,&status);
02281 if(status != DRMS_SUCCESS)
02282 {
02283 printf("Error: unable to read the %s keyword\n",TRECEPOCHS);
02284 return 1;
02285 }
02286 if(TREC_EPOCH != TREC_EPOCH0)
02287 {
02288 printf("Error: TREC_EPOCH should be equal to TREC_EPOCH0 and not %f\n",TREC_EPOCH);
02289 return 1;
02290 }
02291 TREC_STEP= drms_getkey_time(recLev1p->records[0],TRECSTEPS,&status);
02292 if(status != DRMS_SUCCESS)
02293 {
02294 printf("Error: cannot read the keyword %s\n",TRECSTEPS);
02295 return 1;
02296 }
02297 if(TREC_STEP != AverageTime)
02298 {
02299 printf("Error: the AverageTime is not equal to the T_REC_step keyword of the level 1p data\n");
02300 return 1;
02301 }
02302
02303 axisin[0] = 4096;
02304 axisin[1] = 4096;
02305 axisout[0]= axisin[0];
02306 axisout[1]= axisin[1];
02307
02308
02309
02310 Mask = (unsigned char *)malloc(axisin[0]*axisin[1]*sizeof(unsigned char));
02311 if(Mask == NULL)
02312 {
02313 printf("Error: cannot allocate memory for Mask\n");
02314 return 1;
02315 }
02316
02317 MaxSearchDistanceL=(TIME)(TempIntNum/2-1)*DataCadence+TimeCaution;
02318 MaxSearchDistanceR=(TIME)(TempIntNum/2) *DataCadence+TimeCaution;
02319 FramelistArray = (int *)malloc(TempIntNum*sizeof(int));
02320 if(FramelistArray == NULL)
02321 {
02322 printf("Error: memory could not be allocated to FramelistArray\n");
02323 return 1;
02324 }
02325
02326
02327 nWavelengths = Framelistsizein/Npolin;
02328 printf("number of wavelengths = %d\n",nWavelengths);
02329 if(nWavelengths != 5 && nWavelengths != 6 && nWavelengths != 8 && nWavelengths != 10)
02330 {
02331 printf("Error: the number of wavelengths should be 5, 6, 8, or 10 but is %d\n",nWavelengths);
02332 return 1;
02333 }
02334
02335 int PolarizationArray[3][Npolin];
02336 int WavelengthArray[4];
02337 int IndexTargetFiltergramId;
02338
02339
02340
02341 QUALITY =(int *)malloc(nTime*sizeof(int));
02342 if(QUALITY == NULL)
02343 {
02344 printf("Error: memory could not be allocated to QUALITY\n");
02345 return 1;
02346 }
02347 for(i=0;i<nTime;i++) QUALITY[i]=0;
02348 QUALITYLEV1 =(int *)malloc(nTime*sizeof(int));
02349 if(QUALITYLEV1 == NULL)
02350 {
02351 printf("Error: memory could not be allocated to QUALITYLEV1\n");
02352 return 1;
02353 }
02354 for(i=0;i<nTime;i++) QUALITYLEV1[i]=0;
02355 X0AVG =(float *)malloc(nTime*sizeof(float));
02356 if(X0AVG == NULL)
02357 {
02358 printf("Error: memory could not be allocated to X0AVG\n");
02359 return 1;
02360 }
02361 Y0AVG =(float *)malloc(nTime*sizeof(float));
02362 if(Y0AVG == NULL)
02363 {
02364 printf("Error: memory could not be allocated to Y0AVG\n");
02365 return 1;
02366 }
02367 CAMAVG =(int *)malloc(nTime*sizeof(int));
02368 if(CAMAVG == NULL)
02369 {
02370 printf("Error: memory could not be allocated to CAMAVG\n");
02371 return 1;
02372 }
02373 X0RMS =(float *)malloc(nTime*sizeof(float));
02374 if(X0RMS == NULL)
02375 {
02376 printf("Error: memory could not be allocated to X0RMS\n");
02377 return 1;
02378 }
02379 Y0RMS =(float *)malloc(nTime*sizeof(float));
02380 if(Y0RMS == NULL)
02381 {
02382 printf("Error: memory could not be allocated to Y0RMS\n");
02383 return 1;
02384 }
02385 RSUNAVG =(float *)malloc(nTime*sizeof(float));
02386 if(RSUNAVG == NULL)
02387 {
02388 printf("Error: memory could not be allocated to RSUNAVG\n");
02389 return 1;
02390 }
02391 RSUNRMS =(float *)malloc(nTime*sizeof(float));
02392 if(RSUNRMS == NULL)
02393 {
02394 printf("Error: memory could not be allocated to RSUNRMS\n");
02395 return 1;
02396 }
02397 OBSVRint =(double *)malloc(nTime*sizeof(double));
02398 if(OBSVRint == NULL)
02399 {
02400 printf("Error: memory could not be allocated to OBSVRint\n");
02401 return 1;
02402 }
02403 OBSVWint =(double *)malloc(nTime*sizeof(double));
02404 if(OBSVWint == NULL)
02405 {
02406 printf("Error: memory could not be allocated to OBSVWint\n");
02407 return 1;
02408 }
02409 OBSVNint =(double *)malloc(nTime*sizeof(double));
02410 if(OBSVNint == NULL)
02411 {
02412 printf("Error: memory could not be allocated to OBSVNint\n");
02413 return 1;
02414 }
02415 CRLNOBSint =(float *)malloc(nTime*sizeof(float));
02416 if(CRLNOBSint == NULL)
02417 {
02418 printf("Error: memory could not be allocated to CRLNOBSint\n");
02419 return 1;
02420 }
02421
02422
02423
02424
02425
02426
02427 CRLTOBSint =(float *)malloc(nTime*sizeof(float));
02428 if(CRLTOBSint == NULL)
02429 {
02430 printf("Error: memory could not be allocated to CRLTOBSint\n");
02431 return 1;
02432 }
02433 DSUNOBSint =(double *)malloc(nTime*sizeof(double));
02434 if(DSUNOBSint == NULL)
02435 {
02436 printf("Error: memory could not be allocated to DSUNOBSint\n");
02437 return 1;
02438 }
02439 CROTA2int =(float *)malloc(nTime*sizeof(float));
02440 if(CROTA2int == NULL)
02441 {
02442 printf("Error: memory could not be allocated to CROTA2int\n");
02443 return 1;
02444 }
02445 RSUNint =(float *)malloc(nTime*sizeof(float));
02446 if(RSUNint == NULL)
02447 {
02448 printf("Error: memory could not be allocated to RSUNint\n");
02449 return 1;
02450 }
02451 CARROTint =(int *)malloc(nTime*sizeof(int));
02452 if(CARROTint == NULL)
02453 {
02454 printf("Error: memory could not be allocated to CARROTint\n");
02455 return 1;
02456 }
02457 source =(char **)malloc(nTime*sizeof(char *));
02458 if(source == NULL)
02459 {
02460 printf("Error: memory could not be allocated to source\n");
02461 return 1;
02462 }
02463 for(i=0;i<nTime;++i)
02464 {
02465 source[i] = (char *)malloc(64000*sizeof(char));
02466 if(source[i] == NULL)
02467 {
02468 printf("Error: memory could not be allocated to source[%d]\n",i);
02469 return 1;
02470 }
02471 strcpy(source[i],HMISeriesLev10);
02472 strcat(source[i],"[:");
02473 }
02474 totalTempIntNum =(int *)malloc(nTime*sizeof(int));
02475 if(totalTempIntNum == NULL)
02476 {
02477 printf("Error: memory could not be allocated to totalTempIntNum\n");
02478 return 1;
02479 }
02480 for(i=0;i<nTime;++i) totalTempIntNum[i]=0;
02481
02482
02483 TOTVALSS =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02484 if(TOTVALSS == NULL)
02485 {
02486 printf("Error: memory could not be allocated to TOTVALSS\n");
02487 return 1;
02488 }
02489 DATAVALSS =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02490 if(DATAVALSS == NULL)
02491 {
02492 printf("Error: memory could not be allocated to DATAVALSS\n");
02493 return 1;
02494 }
02495 MISSVALSS =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02496 if(MISSVALSS == NULL)
02497 {
02498 printf("Error: memory could not be allocated to MISSVALSS\n");
02499 return 1;
02500 }
02501 DATAMINS =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02502 if(DATAMINS == NULL)
02503 {
02504 printf("Error: memory could not be allocated to DATAMINS\n");
02505 return 1;
02506 }
02507 DATAMAXS =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02508 if(DATAMAXS == NULL)
02509 {
02510 printf("Error: memory could not be allocated to DATAMAXS\n");
02511 return 1;
02512 }
02513 DATAMEDNS =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02514 if(DATAMEDNS == NULL)
02515 {
02516 printf("Error: memory could not be allocated to DATAMEDNS\n");
02517 return 1;
02518 }
02519 DATAMEANS =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02520 if(DATAMEANS == NULL)
02521 {
02522 printf("Error: memory could not be allocated to DATAMEANS\n");
02523 return 1;
02524 }
02525 DATARMSS =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02526 if(DATARMSS == NULL)
02527 {
02528 printf("Error: memory could not be allocated to DATARMSS\n");
02529 return 1;
02530 }
02531 DATASKEWS =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02532 if(DATASKEWS == NULL)
02533 {
02534 printf("Error: memory could not be allocated to DATASKEWS\n");
02535 return 1;
02536 }
02537 DATAKURTS =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02538 if(DATAKURTS == NULL)
02539 {
02540 printf("Error: memory could not be allocated to DATAKURTS\n");
02541 return 1;
02542 }
02543 DATAMINS2 =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02544 if(DATAMINS2 == NULL)
02545 {
02546 printf("Error: memory could not be allocated to DATAMINS2\n");
02547 return 1;
02548 }
02549 DATAMAXS2 =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02550 if(DATAMAXS2 == NULL)
02551 {
02552 printf("Error: memory could not be allocated to DATAMAXS2\n");
02553 return 1;
02554 }
02555 DATAMEDNS2 =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02556 if(DATAMEDNS2 == NULL)
02557 {
02558 printf("Error: memory could not be allocated to DATAMEDNS2\n");
02559 return 1;
02560 }
02561 DATAMEANS2 =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02562 if(DATAMEANS2 == NULL)
02563 {
02564 printf("Error: memory could not be allocated to DATAMEANS2\n");
02565 return 1;
02566 }
02567 DATARMSS2 =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02568 if(DATARMSS2 == NULL)
02569 {
02570 printf("Error: memory could not be allocated to DATARMSS2\n");
02571 return 1;
02572 }
02573 DATASKEWS2 =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02574 if(DATASKEWS2 == NULL)
02575 {
02576 printf("Error: memory could not be allocated to DATASKEWS2\n");
02577 return 1;
02578 }
02579 DATAKURTS2 =(char **)malloc(nWavelengths*npolout*sizeof(char *));
02580 if(DATAKURTS2 == NULL)
02581 {
02582 printf("Error: memory could not be allocated to DATAKURTS2\n");
02583 return 1;
02584 }
02585
02586 for(i=0;i<nWavelengths*npolout;i++)
02587 {
02588 TOTVALSS[i] = (char *)malloc(13*sizeof(char));
02589 if(TOTVALSS[i] == NULL)
02590 {
02591 printf("Error: memory could not be allocated to TOTVALSS[%d]\n",i);
02592 return 1;
02593 }
02594 strcpy(TOTVALSS[i],"TOTVALS[");
02595 sprintf(query,"%d",i);
02596 strcat(TOTVALSS[i],query);
02597 strcat(TOTVALSS[i],"]");
02598
02599 MISSVALSS[i] = (char *)malloc(13*sizeof(char));
02600 if(MISSVALSS[i] == NULL)
02601 {
02602 printf("Error: memory could not be allocated to MISSVALSS[%d]\n",i);
02603 return 1;
02604 }
02605 strcpy(MISSVALSS[i],"MISSVALS[");
02606 sprintf(query,"%d",i);
02607 strcat(MISSVALSS[i],query);
02608 strcat(MISSVALSS[i],"]");
02609
02610 DATAVALSS[i] = (char *)malloc(13*sizeof(char));
02611 if(DATAVALSS[i] == NULL)
02612 {
02613 printf("Error: memory could not be allocated to DATAVALSS[%d]\n",i);
02614 return 1;
02615 }
02616 strcpy(DATAVALSS[i],"DATAVALS[");
02617 sprintf(query,"%d",i);
02618 strcat(DATAVALSS[i],query);
02619 strcat(DATAVALSS[i],"]");
02620
02621 DATAMEANS[i] = (char *)malloc(13*sizeof(char));
02622 if(DATAMEANS[i] == NULL)
02623 {
02624 printf("Error: memory could not be allocated to DATAMEANS[%d]\n",i);
02625 return 1;
02626 }
02627 strcpy(DATAMEANS[i],"DATAMEA2[");
02628 sprintf(query,"%d",i);
02629 strcat(DATAMEANS[i],query);
02630 strcat(DATAMEANS[i],"]");
02631
02632 DATAMINS[i] = (char *)malloc(13*sizeof(char));
02633 if(DATAMINS[i] == NULL)
02634 {
02635 printf("Error: memory could not be allocated to DATAMINS[%d]\n",i);
02636 return 1;
02637 }
02638 strcpy(DATAMINS[i],"DATAMIN2[");
02639 sprintf(query,"%d",i);
02640 strcat(DATAMINS[i],query);
02641 strcat(DATAMINS[i],"]");
02642
02643 DATAMAXS[i] = (char *)malloc(13*sizeof(char));
02644 if(DATAMAXS[i] == NULL)
02645 {
02646 printf("Error: memory could not be allocated to DATAMAXS[%d]\n",i);
02647 return 1;
02648 }
02649 strcpy(DATAMAXS[i],"DATAMAX2[");
02650 sprintf(query,"%d",i);
02651 strcat(DATAMAXS[i],query);
02652 strcat(DATAMAXS[i],"]");
02653
02654
02655 DATAMEDNS[i] = (char *)malloc(13*sizeof(char));
02656 if(DATAMEDNS[i] == NULL)
02657 {
02658 printf("Error: memory could not be allocated to DATAMEDNS[%d]\n",i);
02659 return 1;
02660 }
02661 strcpy(DATAMEDNS[i],"DATAMED2[");
02662 sprintf(query,"%d",i);
02663 strcat(DATAMEDNS[i],query);
02664 strcat(DATAMEDNS[i],"]");
02665
02666 DATARMSS[i] = (char *)malloc(13*sizeof(char));
02667 if(DATARMSS[i] == NULL)
02668 {
02669 printf("Error: memory could not be allocated to DATARMSS[%d]\n",i);
02670 return 1;
02671 }
02672 strcpy(DATARMSS[i],"DATARMS2[");
02673 sprintf(query,"%d",i);
02674 strcat(DATARMSS[i],query);
02675 strcat(DATARMSS[i],"]");
02676
02677 DATASKEWS[i] = (char *)malloc(13*sizeof(char));
02678 if(DATASKEWS[i] == NULL)
02679 {
02680 printf("Error: memory could not be allocated to DATASKEWS[%d]\n",i);
02681 return 1;
02682 }
02683 strcpy(DATASKEWS[i],"DATASKE2[");
02684 sprintf(query,"%d",i);
02685 strcat(DATASKEWS[i],query);
02686 strcat(DATASKEWS[i],"]");
02687
02688 DATAKURTS[i] = (char *)malloc(13*sizeof(char));
02689 if(DATAKURTS[i] == NULL)
02690 {
02691 printf("Error: memory could not be allocated to DATAKURTS[%d]\n",i);
02692 return 1;
02693 }
02694 strcpy(DATAKURTS[i],"DATAKUR2[");
02695 sprintf(query,"%d",i);
02696 strcat(DATAKURTS[i],query);
02697 strcat(DATAKURTS[i],"]");
02698
02699
02700 DATAMINS2[i] = (char *)malloc(13*sizeof(char));
02701 if(DATAMINS2[i] == NULL)
02702 {
02703 printf("Error: memory could not be allocated to DATAMINS2[%d]\n",i);
02704 return 1;
02705 }
02706 strcpy(DATAMINS2[i],"DATAMIN[");
02707 sprintf(query,"%d",i);
02708 strcat(DATAMINS2[i],query);
02709 strcat(DATAMINS2[i],"]");
02710
02711 DATAMAXS2[i] = (char *)malloc(13*sizeof(char));
02712 if(DATAMAXS2[i] == NULL)
02713 {
02714 printf("Error: memory could not be allocated to DATAMAXS2[%d]\n",i);
02715 return 1;
02716 }
02717 strcpy(DATAMAXS2[i],"DATAMAX[");
02718 sprintf(query,"%d",i);
02719 strcat(DATAMAXS2[i],query);
02720 strcat(DATAMAXS2[i],"]");
02721
02722 DATAMEANS2[i] = (char *)malloc(13*sizeof(char));
02723 if(DATAMEANS2[i] == NULL)
02724 {
02725 printf("Error: memory could not be allocated to DATAMEANS2[%d]\n",i);
02726 return 1;
02727 }
02728 strcpy(DATAMEANS2[i],"DATAMEAN[");
02729 sprintf(query,"%d",i);
02730 strcat(DATAMEANS2[i],query);
02731 strcat(DATAMEANS2[i],"]");
02732
02733 DATAMEDNS2[i] = (char *)malloc(13*sizeof(char));
02734 if(DATAMEDNS2[i] == NULL)
02735 {
02736 printf("Error: memory could not be allocated to DATAMEDNS2[%d]\n",i);
02737 return 1;
02738 }
02739 strcpy(DATAMEDNS2[i],"DATAMEDN[");
02740 sprintf(query,"%d",i);
02741 strcat(DATAMEDNS2[i],query);
02742 strcat(DATAMEDNS2[i],"]");
02743
02744 DATARMSS2[i] = (char *)malloc(13*sizeof(char));
02745 if(DATARMSS2[i] == NULL)
02746 {
02747 printf("Error: memory could not be allocated to DATARMSS2[%d]\n",i);
02748 return 1;
02749 }
02750 strcpy(DATARMSS2[i],"DATARMS[");
02751 sprintf(query,"%d",i);
02752 strcat(DATARMSS2[i],query);
02753 strcat(DATARMSS2[i],"]");
02754
02755 DATASKEWS2[i] = (char *)malloc(13*sizeof(char));
02756 if(DATASKEWS2[i] == NULL)
02757 {
02758 printf("Error: memory could not be allocated to DATASKEWS2[%d]\n",i);
02759 return 1;
02760 }
02761 strcpy(DATASKEWS2[i],"DATASKEW[");
02762 sprintf(query,"%d",i);
02763 strcat(DATASKEWS2[i],query);
02764 strcat(DATASKEWS2[i],"]");
02765
02766 DATAKURTS2[i] = (char *)malloc(13*sizeof(char));
02767 if(DATAKURTS2[i] == NULL)
02768 {
02769 printf("Error: memory could not be allocated to DATAKURTS2[%d]\n",i);
02770 return 1;
02771 }
02772 strcpy(DATAKURTS2[i],"DATAKURT[");
02773 sprintf(query,"%d",i);
02774 strcat(DATAKURTS2[i],query);
02775 strcat(DATAKURTS2[i],"]");
02776
02777 }
02778
02779
02780 imagesi = (float **)malloc(TempIntNum*sizeof(float *));
02781 if(imagesi == NULL)
02782 {
02783 printf("Error: memory could not be allocated to imagesi\n");
02784 return 1;
02785 }
02786
02787 ierrors = (char **)malloc(TempIntNum*sizeof(char *));
02788 if(ierrors == NULL)
02789 {
02790 printf("Error: memory could not be allocated to ierrors\n");
02791 return 1;
02792 }
02793
02794 KeyInterp = (struct keyword *)malloc(TempIntNum*sizeof(struct keyword));
02795 if(KeyInterp == NULL)
02796 {
02797 printf("Error: memory could not be allocated to KeyInterp\n");
02798 return 1;
02799 }
02800
02801
02802 images = (float **)malloc(Npolin*sizeof(float *));
02803 if(images == NULL)
02804 {
02805 printf("Error: memory could not be allocated to images\n");
02806 return 1;
02807 }
02808
02809 imagesout = (float **)malloc(npolout*sizeof(float *));
02810 if(imagesout == NULL)
02811 {
02812 printf("Error: memory could not be allocated to imagesout\n");
02813 return 1;
02814 }
02815
02816 ps1 = (int *)malloc(Npolin*sizeof(int *));
02817 if(ps1 == NULL)
02818 {
02819 printf("Error: memory could not be allocated to ps1\n");
02820 return 1;
02821 }
02822 ps2 = (int *)malloc(Npolin*sizeof(int *));
02823 if(ps2 == NULL)
02824 {
02825 printf("Error: memory could not be allocated to ps2\n");
02826 return 1;
02827 }
02828 ps3 = (int *)malloc(Npolin*sizeof(int *));
02829 if(ps3 == NULL)
02830 {
02831 printf("Error: memory could not be allocated to ps3\n");
02832 return 1;
02833 }
02834
02835
02836
02837
02838
02839
02840
02841
02842
02843
02844 initialrun=1;
02845
02846 for(it=0;it<nWavelengths;++it)
02847
02848
02849 {
02850 printf("----------------------------------------------------------------------------------------\n");
02851 printf("CURRENT WAVELENGTH/FILTER NUMBER = %d\n",it);
02852 printf("----------------------------------------------------------------------------------------\n");
02853
02854
02855
02856
02857
02858
02859
02860
02861
02862 temptime = (TIME)floor((TimeBegin-TREC_EPOCH+TREC_STEP/2.0)/TREC_STEP)*TREC_STEP+TREC_EPOCH;
02863 if(temptime < TimeBegin) temptime += TREC_STEP;
02864 TargetTime = temptime;
02865 timeindex = 0;
02866 PreviousTargetTime=TargetTime;
02867
02868 while(TargetTime <= TimeEnd)
02869 {
02870
02871
02872 if(inRotationalFlat == 1)
02873 {
02874
02875
02876 if(floor(TargetTime/86400.0) != floor(PreviousTargetTime/86400.0) )
02877 {
02878 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");
02879 return 1;
02880 }
02881
02882
02883 if(initialrun != 1)
02884 {
02885 if(TargetTime < TSTARTFLAT || TargetTime > TSTOPFLAT)
02886 {
02887 printf("Error: the target time is not within the time range for which the rotation flat field used is valid\n");
02888 return 1;
02889 }
02890 }
02891
02892 }
02893
02894
02895 sprint_time(timeBegin2,TargetTime,"TAI",0);
02896 printf("TARGET TIME= %s %f\n",timeBegin2,TargetTime);
02897
02898 if(nIndexFiltergram == 0)
02899 {
02900 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_TARGETFILTERGRAMMISSING;
02901 CreateEmptyRecord = 1;
02902 goto NextTargetTime;
02903 }
02904
02905
02906
02907 arrLev1d = (DRMS_Array_t **)malloc(Npolin*sizeof(DRMS_Array_t *));
02908 if(arrLev1d == NULL)
02909 {
02910 printf("Error: memory could not be allocated to arrLev1d\n");
02911 return 1;
02912 }
02913
02914 for(k=0;k<Npolin;++k)
02915 {
02916 arrLev1d[k] = drms_array_create(type1d,2,axisout,NULL,&status);
02917 if(status != DRMS_SUCCESS || arrLev1d[k] == NULL)
02918 {
02919 printf("Error: cannot create a DRMS array for a level 1d filtergram with index %d at target time %s\n",k,timeBegin2);
02920 return 1;
02921 }
02922 }
02923
02924
02925
02926
02927
02928
02929
02930
02931
02932
02933
02934 int *CameraID;
02935
02936 CameraID = (int *)malloc(Npolin * sizeof(int *));
02937
02938 for(it2=0;it2<Npolin;++it2)
02939 {
02940 int CamID_tmp;
02941 printf("CURRENT POLARIZATION INDEX = %d\n",it2);
02942 printf("--------------------------------\n");
02943 printf("QUALITY KEYWORD VALUE: %d\n",QUALITY[timeindex]);
02944
02945 if(recLev1->n == 0)
02946 {
02947 CreateEmptyRecord=1;
02948 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_TARGETFILTERGRAMMISSING;
02949 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_NODATA;
02950 goto NextTargetTime;
02951 }
02952
02953
02954
02955
02956 temptime = 100000000.0;
02957 i=0;
02958 while(fabs(internTOBS[IndexFiltergram[i]]-TargetTime) <= temptime)
02959 {
02960
02961 temptime=fabs(internTOBS[IndexFiltergram[i]]-TargetTime);
02962 if(i <= nIndexFiltergram-2) ++i;
02963 else break;
02964 }
02965 if(temptime > DataCadence/2.0 )
02966 {
02967 printf("Error: could not find a filtergram with wavelength %d at time %s\n",WavelengthID,timeBegin2);
02968 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_TARGETFILTERGRAMMISSING;
02969 CreateEmptyRecord=1; goto NextTargetTime;
02970 }
02971 TargetWavelength= i-1;
02972 temp = IndexFiltergram[TargetWavelength];
02973
02974
02975 if(TargetTime > 1145850460.469931 && TargetTime < 1146422026.006866)
02976 {
02977 printf("Warning: target time is within 6 days of the accidental reboot of HMI on April 24, 2013\n");
02978 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_POORQUALITY;
02979 }
02980
02981
02982 if((QUALITYin[temp] & Q_ACS_ISSLOOP) == Q_ACS_ISSLOOP)
02983 {
02984 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_ISSTARGET ;
02985 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_POORQUALITY;
02986 }
02987 if((QUALITYin[temp] & Q_ACS_ECLP) == Q_ACS_ECLP)
02988 {
02989 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_ECLIPSE;
02990 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_POORQUALITY;
02991 }
02992 if((QUALITYin[temp] & Q_ACS_NOLIMB) == Q_ACS_NOLIMB) QUALITY[timeindex] = QUALITY[timeindex] | QUAL_LIMBFITISSUE;
02993 if((QUALITYin[temp] & Q_ACS_LUNARTRANSIT) == Q_ACS_LUNARTRANSIT) QUALITY[timeindex] = QUALITY[timeindex] | QUAL_POORQUALITY;
02994 if((QUALITYin[temp] & Q_ACS_THERMALRECOVERY) == Q_ACS_THERMALRECOVERY) QUALITY[timeindex] = QUALITY[timeindex] | QUAL_POORQUALITY;
02995 if((QUALITYin[temp] & Q_CAMERA_ANOMALY) == Q_CAMERA_ANOMALY) QUALITY[timeindex] = QUALITY[timeindex] | QUAL_POORQUALITY;
02996
02997
02998
02999
03000
03001
03002
03003
03004
03005
03006
03007
03008 TargetHFLID = HFLID[temp];
03009 if(TargetHFLID >= 4000) QUALITY[timeindex] = QUALITY[timeindex] | QUAL_LARGEFTSID;
03010 TargetHWLPOS[0] = HWL1POS[temp];
03011 TargetHWLPOS[1] = HWL2POS[temp];
03012 TargetHWLPOS[2] = HWL3POS[temp];
03013 TargetHWLPOS[3] = HWL4POS[temp];
03014 TargetHPLPOS[0] = HPL1POS[temp];
03015 TargetHPLPOS[1] = HPL2POS[temp];
03016 TargetHPLPOS[2] = HPL3POS[temp];
03017 TargetHWLTID = HWLTID[temp];
03018 TargetHPLTID = HPLTID[temp];
03019 TargetCFINDEX = CFINDEX[temp];
03020 TargetFID = FID[temp];
03021
03022
03023 combineornot = framelistCombine(TargetHFLID, CamId, &combineYesNo, dpath);
03024 printf("combineornot=%d, combine=%d\n", combineornot, combineYesNo);
03025
03026
03027
03028 if(isnan(X0[temp]) || isnan(Y0[temp]))
03029 {
03030 printf("Error: target filtergram FSN[%d] does not have valid X0_LF and/or Y0_LF keywords\n",FSN[temp]);
03031 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_LIMBFITISSUE;
03032 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_TARGETFILTERGRAMMISSING;
03033 CreateEmptyRecord=1; goto NextTargetTime;
03034 }
03035
03036
03037
03038 strcpy(TargetISS,HWLTNSET[temp]);
03039 if(!strcmp(TargetISS,"OPEN")) QUALITY[timeindex] = QUALITY[timeindex] | QUAL_ISSTARGET;
03040
03041
03042
03043
03044
03045 if(inRotationalFlat == 1)
03046 {
03047
03048 HMIFlatField = (char *)malloc(MaxNString*sizeof(char *));
03049 if(HMIFlatField == NULL)
03050 {
03051 printf("Error: memory could not be allocated to HMIFlatField\n");
03052 return 1;
03053 }
03054
03055 HMIFlatField = drms_getkey_string(recLev1->records[temp],FLATREC,&status);
03056 if (status != DRMS_SUCCESS)
03057 {
03058 printf("Error: could not read the FLAT_REC keyword for the target filtergram FSN= %d",FSN[temp]);
03059 return 1;
03060 }
03061 else
03062 {
03063 printf("PZT FLAT FIELD USED ON TARGET FILTERGRAM= %s\n",HMIFlatField);
03064 if(initialrun == 1)
03065 {
03066 strcpy(HMIFlatField0,HMIFlatField);
03067
03068
03069 recflat = drms_open_records(drms_env,HMIFlatField,&status);
03070 if (status != DRMS_SUCCESS || recflat == NULL || recflat->n == 0)
03071 {
03072 printf("Error: record missing or corrupt for the flat field query %s\n",HMIFlatField);
03073 return 1;
03074 }
03075 segin = drms_segment_lookup(recflat->records[0],"flatfield");
03076 flatfield = drms_segment_read(segin,type1d,&status);
03077 if (status != DRMS_SUCCESS || flatfield == NULL)
03078 {
03079 printf("Error: could not read the data segment for the flat field query %s\n",HMIFlatField);
03080 return 1;
03081 }
03082 pztflat = flatfield->data;
03083 status=drms_close_records(recflat,DRMS_FREE_RECORD);
03084
03085
03086 char keylist[]="T_START,T_STOP";
03087 int unique = 0;
03088 rotationalflats = drms_record_getvector(drms_env,HMIRotationalFlats,keylist,DRMS_TYPE_DOUBLE,unique,&status);
03089 if(status != DRMS_SUCCESS)
03090 {
03091 printf("Error: cannot read a list of keywords in the rotation flat-field series\n");
03092 return 1;
03093 }
03094 printf("DIMENSIONS OF ROTATIONAL FLAT-FIELD SERIES= %d %d\n",rotationalflats->axis[0],rotationalflats->axis[1]);
03095 int n0,n1;
03096 n1 =rotationalflats->axis[1];
03097 n0 =rotationalflats->axis[0];
03098 keyF=rotationalflats->data;
03099
03100 i=0;
03101 while(TargetTime > keyF[i] && TargetTime > keyF[n1+i])
03102 {
03103 i++;
03104 }
03105
03106 if(TargetTime >= keyF[i] && TargetTime <= keyF[n1+i])
03107 {
03108
03109 TSTARTFLAT=keyF[i];
03110 TSTOPFLAT =keyF[n1+i];
03111 sprint_time(query,keyF[i],"TAI",1);
03112 strcpy(QueryFlatField,HMIRotationalFlats);
03113 strcat(QueryFlatField,"[");
03114 if(CamId == LIGHT_SIDE) strcat(QueryFlatField,"1");
03115 if(CamId == LIGHT_FRONT) strcat(QueryFlatField,"2");
03116 strcat(QueryFlatField,"][");
03117 strcat(QueryFlatField,query);
03118 strcat(QueryFlatField,"]");
03119 printf("QUERY FOR ROTATIONAL FLAT FIELD= %s\n",QueryFlatField);
03120
03121
03122 recflatrot = drms_open_records(drms_env,QueryFlatField,&status);
03123 if (status != DRMS_SUCCESS || recflatrot == NULL || recflatrot->n == 0)
03124 {
03125 printf("Error: record missing or corrupt for the rotational flat field query %s\n",QueryFlatField);
03126 return 1;
03127 }
03128 segin = drms_segment_lookup(recflatrot->records[0],"flatfield");
03129 flatfieldrot = drms_segment_read(segin,type1d,&status);
03130 if (status != DRMS_SUCCESS || flatfieldrot == NULL)
03131 {
03132 printf("Error: could not read the data segment for the rotational flat field query %s\n",QueryFlatField);
03133 return 1;
03134 }
03135 rotflat = flatfieldrot->data;
03136
03137 }
03138 else
03139 {
03140 printf("Error: no rotational flat field record exists for the target time %s\n",timeBegin2);
03141 return 1;
03142 }
03143
03144 drms_free_array(rotationalflats);
03145 rotationalflats=NULL;
03146 }
03147 else if(strcmp(HMIFlatField,HMIFlatField0) != 0)
03148 {
03149 printf("Warning: the hmi.flatfield record used to produce the level 1 records changed during the run of the observables code\n");
03150 printf("The new hmi,flatfield record used is: %s\n",HMIFlatField);
03151
03152 recflat = drms_open_records(drms_env,HMIFlatField,&status);
03153 if (status != DRMS_SUCCESS || recflat == NULL || recflat->n == 0)
03154 {
03155 printf("Error: record missing or corrupt for the flat field query %s\n",HMIFlatField);
03156 return 1;
03157 }
03158 drms_free_array(flatfield);
03159 strcpy(HMIFlatField0,HMIFlatField);
03160 segin = drms_segment_lookup(recflat->records[0],"flatfield");
03161 flatfield = drms_segment_read(segin,type1d,&status);
03162 if (status != DRMS_SUCCESS || flatfield == NULL)
03163 {
03164 printf("Error: could not read the data segment for the flat field query %s\n",HMIFlatField);
03165 return 1;
03166 }
03167 pztflat = flatfield->data;
03168 status=drms_close_records(recflat,DRMS_FREE_RECORD);
03169 }
03170
03171 }
03172 free(HMIFlatField);
03173 }
03174
03175
03176
03177 framelistSize = framelistInfo(TargetHFLID,TargetHPLTID,TargetHWLTID,WavelengthID,PHWPLPOS,WavelengthIndex,WavelengthLocation,&PolarizationType,CamId,&combine,&npol,MaxNumFiltergrams,&CadenceRead,CameraValues,FIDValues,dpath);
03178 if(framelistSize == 1) return 1;
03179
03180 if(framelistSize != Framelistsizein)
03181 {
03182 printf("Error: the current framelist does not match what is expected from the command line, at target time %s\n",timeBegin2);
03183 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_WRONGFRAMELISTSIZE;
03184 CreateEmptyRecord=1; goto NextTargetTime;
03185 }
03186 if(CadenceRead != DataCadence)
03187 {
03188 printf("Error: the cadence from the current framelist is %f and does not match the cadence entered on the command line %f, at target time %s\n",CadenceRead,DataCadence,timeBegin2);
03189 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_WRONGCADENCE;
03190 CreateEmptyRecord=1; goto NextTargetTime;
03191 }
03192 if(PolarizationType != 1)
03193 {
03194 printf("Error: this program produces only I,Q,U, and V data and does not work on LCP+RCP data \n");
03195 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_WRONGPOLTYPE;
03196 CreateEmptyRecord=1; goto NextTargetTime;
03197 }
03198 if(npol != Npolin)
03199 {
03200 printf("Error: npol does not match the value entered on the command line, at target time %s\n",timeBegin2);
03201 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_WRONGNPOL;
03202 CreateEmptyRecord=1; goto NextTargetTime;
03203 }
03204
03205 k=0;
03206 for(i=0;i<Framelistsizein;++i) if(WavelengthIndex[i] == it)
03207 {
03208
03209 PolarizationArray[0][k]=PHWPLPOS[i*7+4];
03210 PolarizationArray[1][k]=PHWPLPOS[i*7+5];
03211 PolarizationArray[2][k]=PHWPLPOS[i*7+6];
03212
03213 WavelengthArray[0] =PHWPLPOS[i*7+0];
03214 WavelengthArray[1] =PHWPLPOS[i*7+1];
03215 WavelengthArray[2] =PHWPLPOS[i*7+2];
03216 WavelengthArray[3] =PHWPLPOS[i*7+3];
03217 k+=1;
03218 }
03219 if(k != Npolin)
03220 {
03221 printf("Error: k is different from NpolIn %d %d\n",k,Npolin);
03222 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_WRONGNPOL;
03223 CreateEmptyRecord=1; goto NextTargetTime;
03224 }
03225
03226
03227
03228
03229
03230
03231
03232
03233
03234 ii=-1;
03235 for(i=0;i<framelistSize;++i) if(PHWPLPOS[i*7+0] == TargetHWLPOS[0] && PHWPLPOS[i*7+1] == TargetHWLPOS[1] && PHWPLPOS[i*7+2] == TargetHWLPOS[2] && PHWPLPOS[i*7+3] == TargetHWLPOS[3] && PHWPLPOS[i*7+4] == TargetHPLPOS[0] && PHWPLPOS[i*7+5] == TargetHPLPOS[1] && PHWPLPOS[i*7+6] == TargetHPLPOS[2] && FIDValues[i] == TargetFID) ii=i;
03236
03237
03238
03239 if(ii == -1)
03240 {
03241 printf("Error: the target filtergram %d %d %d %d does not match any frame of the corresponding framelist\n",WavelengthID,TargetHPLPOS[0],TargetHPLPOS[1],TargetHPLPOS[2]);
03242 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_WRONGTARGET;
03243 CreateEmptyRecord=1; goto NextTargetTime;
03244 }
03245 IndexTargetFiltergramId=WavelengthLocation[ii];
03246
03247
03248
03249
03250 if (combineYesNo == 1 && (it2 == 4 || it2 == 6)) {
03251 for(i=0;i<framelistSize;++i) if(WavelengthIndex[i] == it && PHWPLPOS[i*7+4] == PolarizationArray[0][it2] && PHWPLPOS[i*7+5] == PolarizationArray[1][it2] && PHWPLPOS[i*7+6] == PolarizationArray[2][it2] && FIDValues[i]/100000 == 1)
03252 {
03253 OrganizeFramelist = WavelengthLocation[i]-IndexTargetFiltergramId;
03254 OrganizeFramelist2 = signj(OrganizeFramelist);
03255 break;
03256 }
03257 }
03258 else {
03259 for(i=0;i<framelistSize;++i) if(WavelengthIndex[i] == it && PHWPLPOS[i*7+4] == PolarizationArray[0][it2] && PHWPLPOS[i*7+5] == PolarizationArray[1][it2] && PHWPLPOS[i*7+6] == PolarizationArray[2][it2] && FIDValues[i]/100000 != 1)
03260 {
03261 OrganizeFramelist = WavelengthLocation[i]-IndexTargetFiltergramId;
03262 OrganizeFramelist2 = signj(OrganizeFramelist);
03263 break;
03264 }
03265 }
03266
03267
03268
03269
03270
03271
03272
03273
03274
03275
03276
03277 if(WavelengthIndex[i] == WavelengthID)
03278 {
03279 if(PHWPLPOS[i*7+4] == TargetHPLPOS[0] && PHWPLPOS[i*7+5] == TargetHPLPOS[1] && PHWPLPOS[i*7+6] == TargetHPLPOS[2])
03280 {
03281 OrganizeFramelist = 0;
03282 OrganizeFramelist2 = 0;
03283 }
03284 else if(abs(WavelengthLocation[i]-IndexTargetFiltergramId) <= 3)
03285 {
03286 OrganizeFramelist = 0;
03287 OrganizeFramelist2 = 0;
03288 }
03289 }
03290 printf("GROUPING OF FILTERGRAMS: %d %d FID=%d,FIDTarget=%d, ii=%d\n",OrganizeFramelist,OrganizeFramelist2,FIDValues[ii], TargetFID, ii);
03291
03292
03293
03294
03295
03296 printf("CURRENT TARGET FILTERGRAM INFORMATION. Index = %d; FSN = %d; %d %d %d %d %d %d %d \n",temp,FSN[temp],HWL1POS[temp],HWL2POS[temp],HWL3POS[temp],HWL4POS[temp],HPL1POS[temp],HPL2POS[temp],HPL3POS[temp]);
03297
03298
03299 ii=-1;
03300
03301
03302
03303 if (combineYesNo == 1 && (it2 == 4 || it2 == 6)) {
03304 for(i=0;i<framelistSize;++i) if(WavelengthIndex[i] == it && PHWPLPOS[i*7+4] == PolarizationArray[0][it2] && PHWPLPOS[i*7+5] == PolarizationArray[1][it2] && PHWPLPOS[i*7+6] == PolarizationArray[2][it2] && FIDValues[i]/100000 == 1) ii=i;}
03305
03306 else {
03307 for(i=0;i<framelistSize;++i) if(WavelengthIndex[i] == it && PHWPLPOS[i*7+4] == PolarizationArray[0][it2] && PHWPLPOS[i*7+5] == PolarizationArray[1][it2] && PHWPLPOS[i*7+6] == PolarizationArray[2][it2] && FIDValues[i]/100000 != 1) ii=i;}
03308
03309
03310
03311
03312
03313
03314 if(ii == -1)
03315 {
03316 printf("Error: the filtergram %d %d %d %d does not match any frame of the corresponding framelist\n",WavelengthID,PolarizationArray[0][it2],PolarizationArray[1][it2],PolarizationArray[2][it2]);
03317 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_ERRORFRAMELIST;
03318 CreateEmptyRecord=1; goto NextTargetTime;
03319 }
03320
03321
03322 camera=CameraValues[ii];
03323 fidfilt=FIDValues[ii];
03324
03325
03326 FramelistArray[0] =WavelengthLocation[ii]-IndexTargetFiltergramId+temp;
03327 FiltergramLocation=FramelistArray[0];
03328
03329
03330
03331
03332
03333 if(KeywordMissing[FiltergramLocation] == 1)
03334 {
03335 FramelistArray[0]=-1;
03336 printf("Error: the filtergram index %d has missing keywords and the code cannot identify it",FiltergramLocation);
03337 }
03338
03339 else
03340 {
03341
03342
03343 if(HWL1POS[FiltergramLocation] != WavelengthArray[0] || HWL2POS[FiltergramLocation] != WavelengthArray[1] || HWL3POS[FiltergramLocation] != WavelengthArray[2] || HWL4POS[FiltergramLocation] != WavelengthArray[3] || HPL1POS[FiltergramLocation] != PolarizationArray[0][it2] || HPL2POS[FiltergramLocation] != PolarizationArray[1][it2] || HPL3POS[FiltergramLocation] != PolarizationArray[2][it2] || CFINDEX[FiltergramLocation] != TargetCFINDEX || HCAMID[FiltergramLocation] != camera || FID[FiltergramLocation] != fidfilt)
03344 {
03345 printf("Warning: filtergram FSN= %d near the target location is not what it should be. Looking for the correct filtergram\n",FSN[FiltergramLocation]);
03346 FiltergramLocation=temp;
03347 for(ii=1;ii<framelistSize;++ii)
03348 {
03349 if(OrganizeFramelist > 0)
03350 {
03351 k=FiltergramLocation+ii;
03352 if(k < nRecs1 && KeywordMissing[k] != 1)
03353 {
03354
03355 if(HWL1POS[k] == WavelengthArray[0] && HWL2POS[k] == WavelengthArray[1] && HWL3POS[k] == WavelengthArray[2] && HWL4POS[k] == WavelengthArray[3] && HPL1POS[k] == PolarizationArray[0][it2] && HPL2POS[k] == PolarizationArray[1][it2] && HPL3POS[k] == PolarizationArray[2][it2] && CFINDEX[k] == TargetCFINDEX && HCAMID[k] == camera && FID[k] == fidfilt) break;
03356 }
03357 }
03358 else
03359 {
03360 k=FiltergramLocation-ii;
03361 if(k > 0 && KeywordMissing[k] != 1)
03362 {
03363
03364
03365 if(HWL1POS[k] == WavelengthArray[0] && HWL2POS[k] == WavelengthArray[1] && HWL3POS[k] == WavelengthArray[2] && HWL4POS[k] == WavelengthArray[3] && HPL1POS[k] == PolarizationArray[0][it2] && HPL2POS[k] == PolarizationArray[1][it2] && HPL3POS[k] == PolarizationArray[2][it2] && CFINDEX[k] == TargetCFINDEX && HCAMID[k] == camera && FID[k] == fidfilt) break;
03366 }
03367 }
03368 }
03369 if(ii == framelistSize)
03370 {
03371 FramelistArray[0]=-1;
03372
03373 ii=-1;
03374
03375 for(i=0;i<framelistSize;++i) if(WavelengthIndex[i] == it && PHWPLPOS[i*7+4] == PolarizationArray[0][it2] && PHWPLPOS[i*7+5] == PolarizationArray[1][it2] && PHWPLPOS[i*7+6] == PolarizationArray[2][it2] ) ii=i;
03376 FiltergramLocation=WavelengthLocation[ii]-IndexTargetFiltergramId+temp;
03377 printf("Error: the filtergram FSN = %d is not what it should be\n",FSN[FiltergramLocation]);
03378 }
03379 else
03380 {
03381 FramelistArray[0]=k;
03382 FiltergramLocation=k;
03383 }
03384 }
03385 }
03386
03387
03388
03389
03390
03391 if(OrganizeFramelist2 <= 0)
03392 {
03393
03394 k=FiltergramLocation-1;
03395 for(ii=1;ii<=TempIntNum/2-1;++ii)
03396 {
03397 while(k > 0)
03398 {
03399 if(KeywordMissing[k] != 1)
03400 {
03401 if(HWL1POS[k] != WavelengthArray[0] || HWL2POS[k] != WavelengthArray[1] || HWL3POS[k] != WavelengthArray[2] || HWL4POS[k] != WavelengthArray[3] || HPL1POS[k] != PolarizationArray[0][it2] || HPL2POS[k] != PolarizationArray[1][it2] || HPL3POS[k] != PolarizationArray[2][it2] || HCAMID[k] != camera || CFINDEX[k] != TargetCFINDEX || FID[k] != fidfilt)
03402 {
03403 if ((internTOBS[k]-TargetTime) >= -MaxSearchDistanceL) --k;
03404 else break;
03405 }
03406 else break;
03407 }
03408 else --k;
03409 }
03410 if(k < 0)
03411 {
03412 FramelistArray[ii]=-1;
03413 continue;
03414 }
03415 if(KeywordMissing[k] != 1)
03416 {
03417
03418 if(HWL1POS[k] == WavelengthArray[0] && HWL2POS[k] == WavelengthArray[1] && HWL3POS[k] == WavelengthArray[2] && HWL4POS[k] == WavelengthArray[3] && HPL1POS[k] == PolarizationArray[0][it2] && HPL2POS[k] == PolarizationArray[1][it2] && HPL3POS[k] == PolarizationArray[2][it2] && HCAMID[k] == camera && CFINDEX[k] == TargetCFINDEX && (internTOBS[k]-TargetTime) >= -MaxSearchDistanceL && FID[k] == fidfilt)
03419
03420
03421 {
03422 FramelistArray[ii]=k;
03423 }
03424 else FramelistArray[ii]=-1;
03425 }
03426 else FramelistArray[ii]=-1;
03427 --k;
03428 }
03429
03430 k=FiltergramLocation+1;
03431 for(ii=TempIntNum/2;ii<TempIntNum;++ii)
03432 {
03433 while(k < nRecs1-1)
03434 {
03435 if(KeywordMissing[k] != 1)
03436 {
03437 if(HWL1POS[k] != WavelengthArray[0] || HWL2POS[k] != WavelengthArray[1] || HWL3POS[k] != WavelengthArray[2] || HWL4POS[k] != WavelengthArray[3] || HPL1POS[k] != PolarizationArray[0][it2] || HPL2POS[k] != PolarizationArray[1][it2] || HPL3POS[k] != PolarizationArray[2][it2] || HCAMID[k] != camera || CFINDEX[k] != TargetCFINDEX || FID[k] != fidfilt)
03438 {
03439 if ((internTOBS[k]-TargetTime) <= MaxSearchDistanceR) ++k;
03440 else break;
03441 }
03442 else break;
03443 }
03444 else ++k;
03445 }
03446 if(k > nRecs1-1)
03447 {
03448 FramelistArray[ii]=-1;
03449 continue;
03450 }
03451 if(KeywordMissing[k] != 1)
03452 {
03453
03454
03455 if(HWL1POS[k] == WavelengthArray[0] && HWL2POS[k] == WavelengthArray[1] && HWL3POS[k] == WavelengthArray[2] && HWL4POS[k] == WavelengthArray[3] && HPL1POS[k] == PolarizationArray[0][it2] && HPL2POS[k] == PolarizationArray[1][it2] && HPL3POS[k] == PolarizationArray[2][it2] && HCAMID[k] == camera && CFINDEX[k] == TargetCFINDEX && (internTOBS[k]-TargetTime) <= MaxSearchDistanceR && FID[k] == fidfilt)
03456
03457
03458 {
03459 FramelistArray[ii]=k;
03460 }
03461 else FramelistArray[ii]=-1;
03462 }
03463 else FramelistArray[ii]=-1;
03464 ++k;
03465 }
03466 }
03467 else
03468 {
03469
03470 k=FiltergramLocation-1;
03471 for(ii=1;ii<=TempIntNum/2;++ii)
03472 {
03473 while(k > 0)
03474 {
03475 if(KeywordMissing[k] != 1)
03476 {
03477 if(HWL1POS[k] != WavelengthArray[0] || HWL2POS[k] != WavelengthArray[1] || HWL3POS[k] != WavelengthArray[2] || HWL4POS[k] != WavelengthArray[3] || HPL1POS[k] != PolarizationArray[0][it2] || HPL2POS[k] != PolarizationArray[1][it2] || HPL3POS[k] != PolarizationArray[2][it2] || HCAMID[k] != camera || CFINDEX[k] != TargetCFINDEX || FID[k] != fidfilt)
03478 {
03479 if ((internTOBS[k]-TargetTime) >= -MaxSearchDistanceR) --k;
03480 else break;
03481 }
03482 else break;
03483 }
03484 else --k;
03485 }
03486 if(k < 0)
03487 {
03488 FramelistArray[ii]=-1;
03489 continue;
03490 }
03491 if(KeywordMissing[k] != 1)
03492 {
03493 if(HWL1POS[k] == WavelengthArray[0] && HWL2POS[k] == WavelengthArray[1] && HWL3POS[k] == WavelengthArray[2] && HWL4POS[k] == WavelengthArray[3] && HPL1POS[k] == PolarizationArray[0][it2] && HPL2POS[k] == PolarizationArray[1][it2] && HPL3POS[k] == PolarizationArray[2][it2] && HCAMID[k] == camera && CFINDEX[k] == TargetCFINDEX && (internTOBS[k]-TargetTime) >= -MaxSearchDistanceR && FID[k] == fidfilt)
03494 {
03495 FramelistArray[ii]=k;
03496 }
03497 else FramelistArray[ii]=-1;
03498 }
03499 else FramelistArray[ii]=-1;
03500 --k;
03501 }
03502 k=FiltergramLocation+1;
03503 for(ii=TempIntNum/2+1;ii<TempIntNum;++ii)
03504 {
03505 while(k < nRecs1-1)
03506 {
03507 if(KeywordMissing[k] != 1)
03508 {
03509 if(HWL1POS[k] != WavelengthArray[0] || HWL2POS[k] != WavelengthArray[1] || HWL3POS[k] != WavelengthArray[2] || HWL4POS[k] != WavelengthArray[3] || HPL1POS[k] != PolarizationArray[0][it2] || HPL2POS[k] != PolarizationArray[1][it2] || HPL3POS[k] != PolarizationArray[2][it2] || HCAMID[k] != camera || CFINDEX[k] != TargetCFINDEX || FID[k] != fidfilt)
03510 {
03511 if ((internTOBS[k]-TargetTime) <= MaxSearchDistanceL) ++k;
03512 else break;
03513 }
03514 else break;
03515 }
03516 else ++k;
03517 }
03518 if(k > nRecs1-1)
03519 {
03520 FramelistArray[ii]=-1;
03521 continue;
03522 }
03523 if(KeywordMissing[k] != 1)
03524 {
03525 if(HWL1POS[k] == WavelengthArray[0] && HWL2POS[k] == WavelengthArray[1] && HWL3POS[k] == WavelengthArray[2] && HWL4POS[k] == WavelengthArray[3] && HPL1POS[k] == PolarizationArray[0][it2] && HPL2POS[k] == PolarizationArray[1][it2] && HPL3POS[k] == PolarizationArray[2][it2] && HCAMID[k] == camera && CFINDEX[k] == TargetCFINDEX && (internTOBS[k]-TargetTime) <= MaxSearchDistanceL && FID[k] == fidfilt)
03526 {
03527 FramelistArray[ii]=k;
03528 }
03529 else FramelistArray[ii]=-1;
03530 }
03531 else FramelistArray[ii]=-1;
03532 ++k;
03533 }
03534 }
03535 printf("FRAMELIST = %d",FramelistArray[0]);
03536 for(ii=1;ii<TempIntNum;++ii)printf(" %d ",FramelistArray[ii]);
03537 printf("\n");
03538
03539
03540
03541
03542
03543
03544 for(ii=0;ii<nRecs1;++ii)
03545 {
03546 if(SegmentRead[ii] == 1)
03547 {
03548 Needed=0;
03549 for(i=0;i<TempIntNum;++i) if (FramelistArray[i] == ii) Needed=1;
03550 if(Needed == 0)
03551 {
03552 drms_free_array(Segments[ii]);
03553 drms_free_array(Ierror[ii]);
03554 Segments[ii]=NULL;
03555 Ierror[ii]=NULL;
03556 SegmentRead[ii] = 0;
03557 }
03558
03559 }
03560
03561 }
03562
03563
03564 if(it2 == 0 && it == 0)
03565 {
03566
03567
03568
03569
03570
03571 i=IndexFiltergram[TargetWavelength];
03572 j=i;
03573
03574 if(internTOBS[IndexFiltergram[TargetWavelength]] < TargetTime && TargetWavelength < nIndexFiltergram-1)
03575 {
03576 j=TargetWavelength;
03577 while(internTOBS[IndexFiltergram[j]] < TargetTime && j < nIndexFiltergram-1 && fabs(internTOBS[IndexFiltergram[j]]-internTOBS[i]) <= 2.1*DataCadence) j++;
03578 if(fabs(internTOBS[IndexFiltergram[j]]-internTOBS[i]) > 2.1*DataCadence) j=i;
03579 else j=IndexFiltergram[j];
03580 }
03581 if(internTOBS[IndexFiltergram[TargetWavelength]] >= TargetTime && TargetWavelength > 0)
03582 {
03583 j=TargetWavelength;
03584 while(internTOBS[IndexFiltergram[j]] >= TargetTime && j > 0 && fabs(internTOBS[IndexFiltergram[j]]-internTOBS[i]) <= 2.1*DataCadence) --j;
03585 if(fabs(internTOBS[IndexFiltergram[j]]-internTOBS[i]) > 2.1*DataCadence) j=i;
03586 else
03587 {
03588 i=IndexFiltergram[j];
03589 j=IndexFiltergram[TargetWavelength];
03590 }
03591 }
03592
03593 if(i == j)
03594 {
03595 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_LOWKEYWORDNUM;
03596 if(TargetWavelength>=1 && TargetWavelength<nIndexFiltergram-1)
03597 {
03598 i=IndexFiltergram[TargetWavelength-1];
03599 j=IndexFiltergram[TargetWavelength+1];
03600 }
03601 if(TargetWavelength>=1 && TargetWavelength == nIndexFiltergram-1 )
03602 {
03603 i=IndexFiltergram[TargetWavelength-1];
03604 j=IndexFiltergram[TargetWavelength];
03605 }
03606 if(TargetWavelength<nIndexFiltergram-1 && TargetWavelength == 0)
03607 {
03608 i=IndexFiltergram[TargetWavelength];
03609 j=IndexFiltergram[TargetWavelength+1];
03610 }
03611 }
03612
03613
03614
03615 if(KeywordMissing[j] == 1 || KeywordMissing[i] == 1)
03616 {
03617 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);
03618 if(SegmentRead[temp])
03619 {
03620 drms_free_array(Segments[temp]);
03621 Segments[temp]=NULL;
03622 if(Ierror[temp] != NULL) drms_free_array(Ierror[temp]);
03623 Ierror[temp]=NULL;
03624 SegmentRead[temp]=0;
03625 }
03626 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_NOINTERPOLATEDKEYWORDS;
03627 CreateEmptyRecord=1; goto NextTargetTime;
03628 }
03629
03630
03631 if(i != j)
03632 {
03633 DSUNOBSint[timeindex]=(DSUNOBS[j]-DSUNOBS[i])/(internTOBS[j]-internTOBS[i])*(TargetTime-internTOBS[i])+DSUNOBS[i];
03634 DSUNOBSint[timeindex]=DSUNOBSint[timeindex]/(double)AstroUnit;
03635 }
03636 else
03637 {
03638 DSUNOBSint[timeindex]=DSUNOBS[i];
03639 DSUNOBSint[timeindex]=DSUNOBSint[timeindex]/(double)AstroUnit;
03640 }
03641
03642
03643 tobs = TargetTime+(DSUNOBSint[timeindex]-1.0)/2.00398880422056639358e-03;
03644
03645
03646
03647 if(i != j)
03648 {
03649 printf("FSNs used for interpolation of OBS_VR, OBS_VW, OBS_VN, CRLN_OBS, CROTA2, and CAR_ROT: %d %d\n",FSN[j],FSN[i]);
03650
03651 DSUNOBSint[timeindex]=(DSUNOBS[j]-DSUNOBS[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+DSUNOBS[i];
03652 DSUNOBSint[timeindex]=DSUNOBSint[timeindex]/(double)AstroUnit;
03653 CRLTOBSint[timeindex]=(CRLTOBS[j]-CRLTOBS[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+CRLTOBS[i];
03654 CROTA2int[timeindex] =(CROTA2[j]-CROTA2[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+CROTA2[i];
03655 OBSVRint[timeindex] =(OBSVR[j]-OBSVR[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+OBSVR[i];
03656 OBSVWint[timeindex] =(OBSVW[j]-OBSVW[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+OBSVW[i];
03657 OBSVNint[timeindex] =(OBSVN[j]-OBSVN[i])/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+OBSVN[i];
03658 ctime1 =-CRLNOBS[i];
03659 ctime2 =360.0*(float)(CARROT[j]-CARROT[i])-CRLNOBS[j];
03660 CRLNOBSint[timeindex]=(ctime2-ctime1)/(internTOBS[j]-internTOBS[i])*(tobs-internTOBS[i])+ctime1;
03661 if(CARROT[j] > CARROT[i])
03662 {
03663 if(CRLNOBSint[timeindex] > 0.0)
03664 {
03665 CRLNOBSint[timeindex] = 360.0 - CRLNOBSint[timeindex];
03666 CARROTint[timeindex] = CARROT[j];
03667 }
03668 else
03669 {
03670 CRLNOBSint[timeindex] = -CRLNOBSint[timeindex];
03671 CARROTint[timeindex] = CARROT[i];
03672 }
03673 }
03674 else
03675 {
03676 CRLNOBSint[timeindex] = -CRLNOBSint[timeindex];
03677 CARROTint[timeindex] = CARROT[i];
03678 }
03679
03680 }
03681 else
03682 {
03683 printf("FSN used for interpolation of OBS_VR, OBS_VW, OBS_VN, CRLN_OBS, CROTA2, and CAR_ROT: %d\n",FSN[i]);
03684
03685 DSUNOBSint[timeindex]=DSUNOBS[i];
03686 DSUNOBSint[timeindex]=DSUNOBSint[timeindex]/(double)AstroUnit;
03687 CRLTOBSint[timeindex]=CRLTOBS[i];
03688 CROTA2int[timeindex] =CROTA2[i];
03689 OBSVRint[timeindex] =OBSVR[i];
03690 OBSVWint[timeindex] =OBSVW[i];
03691 OBSVNint[timeindex] =OBSVN[i];
03692 CRLNOBSint[timeindex]=CRLNOBS[i];
03693 CARROTint[timeindex] =CARROT[i];
03694
03695 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_LOWKEYWORDNUM;
03696 }
03697
03698
03699
03700
03701
03702
03703 X0ARR =(float *)malloc(TempIntNum*sizeof(float));
03704 Y0ARR =(float *)malloc(TempIntNum*sizeof(float));
03705 RSUNARR =(float *)malloc(TempIntNum*sizeof(float));
03706
03707 for(i=0;i<TempIntNum;++i)
03708 {
03709 temp=FramelistArray[i];
03710 if(temp != -1)
03711 {
03712 X0ARR[i]=X0[temp];
03713 Y0ARR[i]=Y0[temp];
03714 RSUNARR[i]=RSUN[temp];
03715 CAMAVG[timeindex]=HCAMID[temp];
03716 }
03717 else
03718 {
03719 X0ARR[i] =MISSINGRESULT;
03720 Y0ARR[i] =MISSINGRESULT;
03721 RSUNARR[i]=MISSINGRESULT;
03722 }
03723
03724 }
03725
03726
03727 status=fstats(TempIntNum,X0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03728 X0AVG[timeindex]=median;
03729 X0RMS[timeindex]=sigma;
03730 status=fstats(TempIntNum,Y0ARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03731 Y0AVG[timeindex]=median;
03732 Y0RMS[timeindex]=sigma;
03733 status=fstats(TempIntNum,RSUNARR,&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
03734 RSUNAVG[timeindex]=median;
03735 RSUNRMS[timeindex]=sigma;
03736
03737 free(X0ARR);
03738 free(Y0ARR);
03739 free(RSUNARR);
03740 X0ARR=NULL;
03741 Y0ARR=NULL;
03742 RSUNARR=NULL;
03743
03744 }
03745
03746
03747
03748
03749
03750
03751 ActualTempIntNum=TempIntNum;
03752
03753
03754
03755
03756 for(i=0;i<TempIntNum;++i)
03757 {
03758 temp=FramelistArray[i];
03759 if(temp != -1)
03760 {
03761 if(SegmentRead[temp] != -1)
03762 {
03763
03764 if(SegmentRead[temp] == 0)
03765 {
03766
03767 segin = drms_segment_lookupnum(recLev1->records[temp], 0);
03768 Segments[temp] = drms_segment_read(segin,type1d, &status);
03769 if (status != DRMS_SUCCESS || Segments[temp] == NULL)
03770 {
03771 printf("Error: could not read the segment of level 1 record index %d at target time %s\n",temp,timeBegin2);
03772 return 1;
03773
03774
03775
03776
03777
03778
03779 }
03780 else
03781 {
03782 Ierror[temp] = drms_array_create(typeEr,2,axisout,NULL,&status);
03783 if(status != DRMS_SUCCESS || Ierror[temp] == NULL)
03784 {
03785 printf("Error: could not create an array for Ierror at target time %s\n",timeBegin2);
03786 drms_free_array(Segments[temp]);
03787 Segments[temp]=NULL;
03788 Ierror[temp]=NULL;
03789 SegmentRead[temp]=-1;
03790 ActualTempIntNum-=1;
03791 arrin[i] = NULL;
03792 arrerrors[i] = NULL;
03793 }
03794 else
03795 {
03796 arrin[i] = Segments[temp];
03797 arrerrors[i] = Ierror[temp];
03798 if( arrin[i]->axis[0] != axisin[0] || arrin[i]->axis[1] != axisin[1])
03799 {
03800 printf("Error: level 1 record index %d at target time %s has a segment with dimensions %d x %d instead of %d x %d\n",temp,timeBegin2,arrin[i]->axis[0],arrin[i]->axis[1],axisin[0],axisin[1]);
03801 drms_free_array(Segments[temp]);
03802 drms_free_array(Ierror[temp]);
03803 ActualTempIntNum-=1;
03804 arrin[i] = NULL;
03805 arrerrors[i] = NULL;
03806 Segments[temp]=NULL;
03807 Ierror[temp]=NULL;
03808 SegmentRead[temp]=-1;
03809 }
03810 else
03811 {
03812 SegmentRead[temp]=1;
03813
03814
03815
03816 segin = drms_segment_lookup(recLev1->records[temp],"bad_pixel_list");
03817 BadPixels = NULL;
03818 BadPixels = drms_segment_read(segin,segin->info->type,&status);
03819 if(status != DRMS_SUCCESS || BadPixels == NULL)
03820 {
03821 printf("Error: cannot read the list of bad pixels of level 1 filtergram FSN= %d\n",FSN[temp]);
03822 return 1;
03823
03824
03825
03826
03827
03828
03829
03830
03831 }
03832 else
03833 {
03834
03835 strcpy(HMISeriesTemp,CosmicRaySeries);
03836 strcat(HMISeriesTemp,"[][");
03837 sprintf(FSNtemps,"%d",FSN[temp]);
03838 strcat(HMISeriesTemp,FSNtemps);
03839 strcat(HMISeriesTemp,"]");
03840 rectemp=NULL;
03841
03842 rectemp=drms_open_records(drms_env,HMISeriesTemp,&statusA[0]);
03843 if(statusA[0] == DRMS_SUCCESS && rectemp != NULL && rectemp->n != 0)
03844 {
03845 segin = drms_segment_lookupnum(rectemp->records[0],0);
03846 CosmicRays = NULL;
03847
03848 COSMICCOUNT=drms_getkey_int(rectemp->records[0],COUNTS,&status);
03849 if(status != DRMS_SUCCESS || COSMICCOUNT == -1)
03850 {
03851 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_NOCOSMICRAY;
03852 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
03853 }
03854 else
03855 {
03856 CosmicRays = drms_segment_read(segin,segin->info->type,&status);
03857 if(status != DRMS_SUCCESS || CosmicRays == NULL)
03858 {
03859 printf("Error: the list of cosmic-ray hits could not be read for FSN %d\n",FSN[temp]);
03860 return 1;
03861
03862
03863 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_NOCOSMICRAY;
03864 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
03865 CosmicRays = NULL;
03866
03867 }
03868 }
03869
03870
03871 }
03872 else
03873 {
03874 printf("Unable to open the series %s for FSN %d\n",HMISeriesTemp,FSN[temp]);
03875
03876
03877
03878 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_NOCOSMICRAY;
03879 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOCOSMICRAY;
03880 CosmicRays = NULL;
03881
03882 }
03883
03884 image = Segments[temp]->data;
03885
03886
03887
03888
03889
03890 if(inRotationalFlat == 1)
03891 {
03892
03893 HMIFlatField = (char *)malloc(MaxNString*sizeof(char *));
03894 if(HMIFlatField == NULL)
03895 {
03896 printf("Error: memory could not be allocated to HMIFlatField\n");
03897 return 1;
03898 }
03899 HMIFlatField = drms_getkey_string(recLev1->records[temp],FLATREC,&status);
03900 if (status != DRMS_SUCCESS)
03901 {
03902 printf("Error: could not read the FLAT_REC keyword for the target filtergram FSN= %d",FSN[temp]);
03903 return 1;
03904 }
03905
03906
03907 if(strcmp(HMIFlatField,HMIFlatField0) != 0)
03908 {
03909 printf("Warning: the hmi.flatfield record used to produce the level 1 records changed during the run of the observables code\n");
03910
03911 recflat = drms_open_records(drms_env,HMIFlatField,&status);
03912 if (status != DRMS_SUCCESS || recflat == NULL || recflat->n == 0)
03913 {
03914 printf("Error: record missing or corrupt for the flat field query %s\n",HMIFlatField);
03915 return 1;
03916 }
03917 drms_free_array(flatfield);
03918 strcpy(HMIFlatField0,HMIFlatField);
03919 segin = drms_segment_lookup(recflat->records[0],"flatfield");
03920 flatfield = drms_segment_read(segin,type1d,&status);
03921 if (status != DRMS_SUCCESS || flatfield == NULL)
03922 {
03923 printf("Error: could not read the data segment for the flat field query %s\n",HMIFlatField);
03924 return 1;
03925 }
03926 pztflat = flatfield->data;
03927 status=drms_close_records(recflat,DRMS_FREE_RECORD);
03928 }
03929
03930 if(inLinearity == 1)
03931 {
03932
03933 for(iii=0;iii<axisin[0]*axisin[1];++iii)
03934 {
03935
03936 image[iii]=(image[iii]*pztflat[iii])/rotflat[iii];
03937
03938 tempvalue = image[iii]*EXPTIME[temp];
03939 if(HCAMID[temp] == LIGHT_FRONT)tempvalue = (nonlinf[0]+nonlinf[1]*tempvalue+nonlinf[2]*tempvalue*tempvalue+nonlinf[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
03940 else tempvalue = (nonlins[0]+nonlins[1]*tempvalue+nonlins[2]*tempvalue*tempvalue+nonlins[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
03941 image[iii] = tempvalue/EXPTIME[temp];
03942 }
03943 }
03944 else
03945 {
03946
03947 for(iii=0;iii<axisin[0]*axisin[1];++iii)
03948 {
03949
03950 image[iii]=(image[iii]*pztflat[iii])/rotflat[iii];
03951 }
03952 }
03953
03954 free(HMIFlatField);
03955
03956 }
03957 else
03958 {
03959 if(inLinearity == 1)
03960 {
03961
03962 for(iii=0;iii<axisin[0]*axisin[1];++iii)
03963 {
03964
03965 tempvalue = image[iii]*EXPTIME[temp];
03966 if(HCAMID[temp] == LIGHT_FRONT) tempvalue = (nonlinf[0]+nonlinf[1]*tempvalue+nonlinf[2]*tempvalue*tempvalue+nonlinf[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
03967 else tempvalue = (nonlins[0]+nonlins[1]*tempvalue+nonlins[2]*tempvalue*tempvalue+nonlins[3]*tempvalue*tempvalue*tempvalue)+tempvalue;
03968 image[iii] = tempvalue/EXPTIME[temp];
03969 }
03970 }
03971
03972 }
03973
03974
03975
03976
03977
03978 status = MaskCreation(Mask,axisin[0],axisin[1],BadPixels,HIMGCFID[temp],image,CosmicRays,NBADPERM[temp]);
03979 if(status != 0)
03980 {
03981 printf("Error: unable to create a mask for the gap filling function\n");
03982 return 1;
03983 }
03984 if(BadPixels != NULL)
03985 {
03986 drms_free_array(BadPixels);
03987 BadPixels=NULL;
03988 }
03989 if(CosmicRays != NULL)
03990 {
03991 drms_free_array(CosmicRays);
03992 CosmicRays=NULL;
03993 }
03994 if(rectemp != NULL)
03995 {
03996 drms_close_records(rectemp,DRMS_FREE_RECORD);
03997 rectemp=NULL;
03998 }
03999
04000 image = arrin[i]->data;
04001 ierror = arrerrors[i]->data;
04002
04003
04004 status =do_gapfill(image,Mask,&const_param,ierror,axisin[0],axisin[1]);
04005
04006
04007 if(status != 0)
04008 {
04009 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_NOGAPFILL;
04010 QUALITYlev1[temp] = QUALITYlev1[temp] | QUAL_NOGAPFILL;
04011 printf("Error: gapfilling code did not work on a level 1 filtergram at target time %s\n",timeBegin2);
04012 }
04013 }
04014 }
04015 }
04016 }
04017 }
04018 else
04019 {
04020 arrin[i] = Segments[temp];
04021 arrerrors[i] = Ierror[temp];
04022 }
04023
04024 }
04025 else
04026 {
04027 printf("Error: at least one of the keyword needed by the temporal interpolation function is missing, at target time %s\n",timeBegin2);
04028 ActualTempIntNum-=1;
04029 arrin[i] = NULL;
04030 arrerrors[i] = NULL;
04031 }
04032 }
04033 else
04034 {
04035 ActualTempIntNum-=1;
04036 arrin[i] = NULL;
04037 arrerrors[i] = NULL;
04038 }
04039 }
04040
04041
04042
04043
04044 printf("NUMBER OF LEVEL 1 FILTERGRAMS AVAILABLE FOR THE TEMPORAL AVERAGING: %d\n",ActualTempIntNum);
04045
04046 if(ActualTempIntNum >= ThresholdPol)
04047 {
04048
04049
04050
04051 ii=0;
04052 for(i=0;i<TempIntNum;++i) if (arrin[i] != NULL && arrerrors[i] != NULL)
04053 {
04054 temp=FramelistArray[i];
04055 if(fabs(RSUN[temp]-RSUNAVG[timeindex]) > 1.82*RSUNerr || isnan(RSUN[temp]))
04056 {
04057 printf("Warning: image %d passed to do_interpolate has a RSUN value %f too different from the median value and will be rejected\n",i,RSUN[temp]);
04058 ActualTempIntNum-=1;
04059 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_LIMBFITISSUE;
04060 continue;
04061 }
04062 if(combine == 0)
04063 {
04064 if(fabs(X0[temp]-X0AVG[timeindex]) > RSUNerr || isnan(X0[temp]))
04065 {
04066 printf("Warning: image %d passed to do_interpolate has a X0 value %f too different from the median value and will be rejected\n",i,X0[temp]);
04067 ActualTempIntNum-=1;
04068 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_LIMBFITISSUE;
04069 continue;
04070 }
04071 if(fabs(Y0[temp]-Y0AVG[timeindex]) > RSUNerr || isnan(Y0[temp]))
04072 {
04073 printf("Warning: image %d passed to do_interpolate has a Y0 value %f too different from the median value and will be rejected\n",i,Y0[temp]);
04074 ActualTempIntNum-=1;
04075 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_LIMBFITISSUE;
04076 continue;
04077 }
04078 }
04079 else
04080 {
04081 if(CAMAVG[timeindex] == LIGHT_FRONT && HCAMID[temp] == LIGHT_FRONT)
04082 {
04083 X0AVGT=X0AVG[timeindex];
04084 Y0AVGT=Y0AVG[timeindex];
04085 }
04086 if(CAMAVG[timeindex] == LIGHT_SIDE && HCAMID[temp] == LIGHT_FRONT)
04087 {
04088 X0AVGT=X0AVG[timeindex]+diffXfs;
04089 Y0AVGT=Y0AVG[timeindex]+diffYfs;
04090 }
04091 if(CAMAVG[timeindex] == LIGHT_FRONT && HCAMID[temp] == LIGHT_SIDE)
04092 {
04093 X0AVGT=X0AVG[timeindex]-diffXfs;
04094 Y0AVGT=Y0AVG[timeindex]-diffYfs;
04095 }
04096 if(CAMAVG[timeindex] == LIGHT_SIDE && HCAMID[temp] == LIGHT_SIDE)
04097 {
04098 X0AVGT=X0AVG[timeindex];
04099 Y0AVGT=Y0AVG[timeindex];
04100 }
04101
04102 if(fabs(X0[temp]-X0AVGT) > RSUNerr || isnan(X0[temp]))
04103 {
04104 printf("Warning: image %d passed to do_interpolate has a X0 value %f too different from the median value and will be rejected\n",i,X0[temp]);
04105 ActualTempIntNum-=1;
04106 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_LIMBFITISSUE;
04107 continue;
04108 }
04109 if(fabs(Y0[temp]-Y0AVGT) > RSUNerr || isnan(Y0[temp]))
04110 {
04111 printf("Warning: image %d passed to do_interpolate has a Y0 value %f too different from the median value and will be rejected\n",i,Y0[temp]);
04112 ActualTempIntNum-=1;
04113 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_LIMBFITISSUE;
04114 continue;
04115 }
04116
04117 }
04118 imagesi[ii]=arrin[i]->data;
04119 image=arrin[i]->data;
04120
04121
04122 CamID_tmp = HCAMID[temp];
04123
04124
04125
04126
04127
04128
04129
04130
04131 ierrors[ii]=arrerrors[i]->data;
04132 printf("FSN filtergram used: %d %d %f %f %f %f %f %f %f\n",FSN[temp],HCAMID[temp],RSUN[temp],X0[temp],Y0[temp],DSUNOBS[temp]/AstroUnit,CRLTOBS[temp],CROTA2[temp],internTOBS[temp]);
04133 if(HCAMID[temp] == LIGHT_FRONT) KeyInterp[ii].camera=0;
04134 else KeyInterp[ii].camera=1;
04135 if(!strcmp(HWLTNSET[temp],"OPEN")) QUALITY[timeindex] = QUALITY[timeindex] | QUAL_ISSTARGET;
04136 if((QUALITYin[temp] & Q_ACS_ECLP) == Q_ACS_ECLP) QUALITY[timeindex] = QUALITY[timeindex] | QUAL_ECLIPSE;
04137 if((QUALITYin[temp] & Q_ACS_LUNARTRANSIT) == Q_ACS_LUNARTRANSIT) QUALITY[timeindex] = QUALITY[timeindex] | QUAL_POORQUALITY;
04138 if((QUALITYin[temp] & Q_ACS_THERMALRECOVERY) == Q_ACS_THERMALRECOVERY) QUALITY[timeindex] = QUALITY[timeindex] | QUAL_POORQUALITY;
04139 if((QUALITYin[temp] & Q_CAMERA_ANOMALY) == Q_CAMERA_ANOMALY) QUALITY[timeindex] = QUALITY[timeindex] | QUAL_POORQUALITY;
04140 KeyInterp[ii].rsun=RSUNAVG[timeindex];
04141 KeyInterp[ii].xx0=X0[temp];
04142 KeyInterp[ii].yy0=Y0[temp];
04143 KeyInterp[ii].dist=(float)(DSUNOBS[temp]/(double)AstroUnit);
04144 KeyInterp[ii].b0=CRLTOBS[temp]/180.*M_PI;
04145 KeyInterp[ii].p0=CROTA2[temp]/180.*M_PI;
04146 KeyInterp[ii].time=internTOBS[temp];
04147 KeyInterp[ii].focus=CFINDEX[temp];
04148
04149 rec=recLev1->records[temp];
04150 sprintf(recnums,"%ld",rec->recnum);
04151 if(it != 0 || it2 != 0 || ii != 0) strcat(source[timeindex],",#");
04152 else strcat(source[timeindex],"#");
04153 strcat(source[timeindex],recnums);
04154
04155 QUALITYLEV1[timeindex] = QUALITYLEV1[timeindex] | QUALITYin[temp];
04156 QUALITY[timeindex] = QUALITY[timeindex] | QUALITYlev1[temp];
04157
04158 ii+=1;
04159 }
04160
04161
04162 RSUNint[timeindex]=RSUNAVG[timeindex];
04163 KeyInterpOut.rsun=RSUNint[timeindex];
04164 KeyInterpOut.xx0=X0AVG[timeindex];
04165 KeyInterpOut.yy0=Y0AVG[timeindex];
04166 KeyInterpOut.dist=(float)DSUNOBSint[timeindex];
04167 KeyInterpOut.b0=CRLTOBSint[timeindex]/180.*M_PI;
04168 KeyInterpOut.p0=CROTA2int[timeindex]/180.*M_PI;
04169
04170
04171
04172 tobs = TargetTime+(DSUNOBSint[timeindex]-1.0)/2.00398880422056639358e-03;
04173 KeyInterpOut.time=tobs;
04174 KeyInterpOut.focus=TargetCFINDEX;
04175
04176
04177 printf("Calling temporal averaging, de-rotation, and un-distortion code\n");
04178
04179 totalTempIntNum[timeindex] += ActualTempIntNum;
04180 if(ActualTempIntNum != TempIntNum) QUALITY[timeindex] = QUALITY[timeindex] | QUAL_LOWINTERPNUM;
04181 else
04182 {
04183 minimum=KeyInterp[0].time;
04184 maximum=KeyInterp[0].time;
04185 for(ii=1;ii<TempIntNum;++ii)
04186 {
04187 if(KeyInterp[ii].time < minimum) minimum=KeyInterp[ii].time;
04188 if(KeyInterp[ii].time > maximum) maximum=KeyInterp[ii].time;
04189 }
04190 if((maximum-minimum) > (DataCadence*(double)(TempIntNum-1)+DataCadence/(double)framelistSize) ) QUALITY[timeindex] = QUALITY[timeindex] | QUAL_LOWINTERPNUM;
04191 }
04192
04193 if(ActualTempIntNum >= ThresholdPol)
04194 {
04195 printf("KEYWORDS OUT: %f %f %f %f %f %f %f %d\n",KeyInterpOut.rsun,KeyInterpOut.xx0,KeyInterpOut.yy0,KeyInterpOut.dist,KeyInterpOut.b0,KeyInterpOut.p0,KeyInterpOut.time,KeyInterpOut.focus);
04196
04197
04198
04199
04200 status=do_interpolate(imagesi,ierrors,arrLev1d[it2]->data,KeyInterp,&KeyInterpOut,&const_param,ActualTempIntNum,axisin[0],axisin[1],AverageTime,dpath2);
04201
04202
04203
04204
04205
04206 printf("End temporal interpolation\n");
04207 }
04208 else
04209 {
04210 printf("Error: ActualTempIntNum < ThresholdPol\n");
04211 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_NOTENOUGHINTERPOLANTS;
04212 status = 1;
04213 }
04214
04215 if (status != 0)
04216 {
04217 printf("Error: temporal interpolation failed at target time %s\n",timeBegin2);
04218 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_INTERPOLATIONFAILED;
04219 CreateEmptyRecord=1; goto NextTargetTime;
04220 }
04221
04222 }
04223 else
04224 {
04225 printf("Error: not enough valid level 1 filtergrams to produce a level 1d filtergram at target time %s\n",timeBegin2);
04226 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_NOTENOUGHINTERPOLANTS;
04227 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_LOWINTERPNUM;
04228 CreateEmptyRecord=1; goto NextTargetTime;
04229
04230 }
04231
04232 CameraID [it2] = CamID_tmp;
04233 }
04234
04235
04236
04237
04238
04239
04240
04241
04242
04243
04244
04245
04246
04247 printf("Creating level 1p arrays\n");
04248 arrLev1p = (DRMS_Array_t **)malloc(npolout*sizeof(DRMS_Array_t *));
04249 if(arrLev1p == NULL)
04250 {
04251 printf("Error: memory could not be allocated to arrLev1p\n");
04252
04253 return 1;
04254 }
04255
04256 for(i=0;i<npolout;++i)
04257 {
04258 arrLev1p[i] = drms_array_create(type1p,2,axisout,NULL,&status);
04259 if(status != DRMS_SUCCESS || arrLev1p[i] == NULL)
04260 {
04261 printf("Error: cannot create an array for a level 1p data at target time %s\n",timeBegin2);
04262 return 1;
04263 }
04264 }
04265
04266
04267
04268 printf("Peopling the images with level 1d arrays\n");
04269
04270
04271
04272 int Ixdim, Iydim;
04273 float *Icamera_FRONT, *Icamera_SIDE, *Iratio_F2S, I_front, I_side;
04274 int Ncamera_FRONT, Ncamera_SIDE, ix, jy, ijxy;
04275 Ixdim = 4096; Iydim = 4096; Ncamera_FRONT = 0; Ncamera_SIDE = 0;
04276 Icamera_FRONT = (float *)malloc(Ixdim * Iydim * sizeof(float *));
04277 Icamera_SIDE = (float *)malloc(Ixdim * Iydim * sizeof(float *));
04278 Iratio_F2S = (float *)malloc(Ixdim * Iydim * sizeof(float *));
04279
04280 for (jy=0;jy<Iydim;jy++)
04281 {
04282 for (ix=0;ix<Ixdim;ix++)
04283 {
04284 ijxy = jy*Ixdim+ix;
04285 Icamera_FRONT[ijxy] = 0.0;
04286 Icamera_SIDE[ijxy] = 0.0;
04287 Iratio_F2S[ijxy] = 1.0;
04288 }
04289 }
04290
04291
04292 if (combine == 1)
04293 {
04294 for(it2=0;it2<npol;++it2)
04295 {
04296 image = arrLev1d[it2]->data;
04297 if (CameraID[it2] == LIGHT_FRONT)
04298 {
04299 Ncamera_FRONT += 1;
04300 for (jy=0;jy<Iydim;jy++)
04301 {
04302 for (ix=0;ix<Ixdim;ix++)
04303 {
04304 ijxy = jy*Ixdim+ix;
04305 Icamera_FRONT[ijxy] += image[ijxy];
04306 }
04307 }
04308 }
04309 if (CameraID[it2] == LIGHT_SIDE)
04310 {
04311 Ncamera_SIDE += 1;
04312 for (jy=0;jy<Iydim;jy++)
04313 {
04314 for (ix=0;ix<Ixdim;ix++)
04315 {
04316 ijxy = jy*Ixdim+ix;
04317 Icamera_SIDE[ijxy] += image[ijxy];
04318 }
04319 }
04320 }
04321 }
04322 for (jy=0;jy<Iydim;jy++)
04323 {
04324 for (ix=0;ix<Ixdim;ix++)
04325 {
04326 ijxy = jy*Ixdim+ix;
04327 if (!isnan(Icamera_FRONT[ijxy]) && !isnan(Icamera_SIDE[ijxy]))
04328 I_front = Icamera_FRONT[ijxy]/(float)Ncamera_FRONT;
04329 I_side = Icamera_SIDE[ijxy]/(float)Ncamera_SIDE;
04330 Iratio_F2S[ijxy] = I_front/I_side;
04331 }
04332 }
04333 }
04334 free(Icamera_FRONT);
04335 free(Icamera_SIDE);
04336
04337
04338 for(it2=0;it2<npol;++it2)
04339 {
04340 images[it2]=arrLev1d[it2]->data;
04341
04342
04343
04344 if (combine == 1 && CameraID[it2] == LIGHT_FRONT)
04345 {
04346 image = arrLev1d[it2]->data;
04347 for (jy=0;jy<Iydim;jy++)
04348 {
04349 for (ix=0;ix<Ixdim;ix++)
04350 {
04351 ijxy = jy*Ixdim+ix;
04352 if (!isnan(image[ijxy])) image[ijxy] /= Iratio_F2S[ijxy];
04353 }
04354 }
04355 }
04356
04357
04358
04359
04360
04361
04362
04363
04364
04365
04366
04367
04368
04369
04370
04371
04372
04373
04374
04375
04376 ps1[it2]=PolarizationArray[0][it2];
04377 ps2[it2]=PolarizationArray[1][it2];
04378 ps3[it2]=PolarizationArray[2][it2];
04379 printf("ps1 = %d, ps2 = %d, ps3 = %d\n",ps1[it2],ps2[it2],ps3[it2]);
04380 }
04381
04382
04383 printf("I-ratio at [2048, 2048] = %f\n", Iratio_F2S[2048*4096 + 2048]);
04384 free(Iratio_F2S);
04385
04386 printf("Setting keywords for level 1p\n");
04387 KeyInterpOut.rsun=RSUNint[timeindex];
04388 KeyInterpOut.xx0=X0AVG[timeindex];
04389 KeyInterpOut.yy0=Y0AVG[timeindex];
04390 KeyInterpOut.dist=(float)DSUNOBSint[timeindex];
04391 KeyInterpOut.b0=CRLTOBSint[timeindex]/180.*M_PI;
04392 KeyInterpOut.p0=CROTA2int[timeindex]/180.*M_PI;
04393 tobs=TargetTime+(DSUNOBSint[timeindex]-1.0)/2.00398880422056639358e-03;
04394 KeyInterpOut.time=tobs;
04395
04396
04397 if(QuickLook == 1)
04398 {
04399 TSEL=20.;
04400 TFRONT=20.;
04401 }
04402 else
04403 {
04404
04405 strcpy(HMISeriesTemp,HMISeriesTemperature);
04406 strcat(HMISeriesTemp,"[");
04407 strcat(HMISeriesTemp,timeBegin2);
04408 strcat(HMISeriesTemp,"]");
04409 rectemp=NULL;
04410 rectemp = drms_open_records(drms_env,HMISeriesTemp,&status);
04411 printf("TEMPERATURE QUERY = %s\n",HMISeriesTemp);
04412 if(statusA[0] == DRMS_SUCCESS && rectemp != NULL && rectemp->n != 0) TSEL=drms_getkey_float(rectemp->records[0],TS08,&status);
04413 else status = 1;
04414 if(status != DRMS_SUCCESS || isnan(TSEL))
04415 {
04416 printf("Error: the temperature keyword %s could not be read\n",TS08);
04417 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_NOTEMP;
04418 TSEL=20.;
04419 }
04420 statusA[1]=1;
04421 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;
04422 if(statusA[0] != DRMS_SUCCESS || statusA[1] != DRMS_SUCCESS || isnan(TFRONT))
04423 {
04424 printf("Error: temperature keyword %s and/or %s could not be read\n",TS01,TS02);
04425 QUALITY[timeindex] = QUALITY[timeindex] | QUAL_NOTEMP;
04426 TFRONT=20.;
04427 }
04428 printf("TEMPERATURES = %f %f\n",TSEL,TFRONT);
04429 if(rectemp != NULL)
04430 {
04431 drms_close_records(rectemp,DRMS_FREE_RECORD);
04432 rectemp=NULL;
04433 }
04434 }
04435
04436
04437 statusA[8] = drms_setkey_int(recLev1p->records[timeindex],QUALITYS,QUALITY[timeindex]);
04438 statusA[44]= drms_setkey_int(recLev1p->records[timeindex],QUALLEV1S,QUALITYLEV1[timeindex]);
04439 statusA[23]= drms_setkey_int(recLev1p->records[timeindex],TINTNUMS,totalTempIntNum[timeindex]);
04440 if(statusA[8] != 0 || statusA[44] != 0 || statusA[23] != 0) printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the level 1p data at target time %s\n",timeBegin2);
04441
04442 if(it == 0)
04443 {
04444
04445
04446 printf("SET KEYWORDS FOR LEVEL 1p AT TARGET TIME: %f %s\n",TargetTime,timeBegin2);
04447
04448
04449
04450
04451
04452 if(combine == 1)camera=3;
04453 if(combine == 0 && CamId == LIGHT_SIDE) camera=1;
04454 if(combine == 0 && CamId == LIGHT_FRONT) camera=2;
04455
04456
04457 cdelt1=1.0/RSUNint[timeindex]*asin(solar_radius/(DSUNOBSint[timeindex]*(double)AstroUnit))*180.*60.*60./M_PI;
04458 statusA[0] = drms_setkey_time(recLev1p->records[timeindex],TRECS,TargetTime);
04459 statusA[1] = drms_setkey_time(recLev1p->records[timeindex],TOBSS,tobs);
04460 statusA[2] = drms_setkey_int(recLev1p->records[timeindex],CAMERAS,camera);
04461 statusA[3] = drms_setkey_string(recLev1p->records[timeindex],HISTORYS,HISTORY);
04462 statusA[4] = drms_setkey_string(recLev1p->records[timeindex],COMMENTS,COMMENT);
04463 statusA[5] = drms_setkey_float(recLev1p->records[timeindex],CADENCES,DataCadence);
04464 statusA[6] = drms_setkey_int(recLev1p->records[timeindex],HFLIDS,TargetHFLID);
04465 statusA[7] = drms_setkey_int(recLev1p->records[timeindex],HCFTIDS,TargetCFINDEX);
04466
04467 statusA[9] = drms_setkey_double(recLev1p->records[timeindex],DSUNOBSS,DSUNOBSint[timeindex]*(double)AstroUnit);
04468 statusA[10]= drms_setkey_float(recLev1p->records[timeindex],CRLTOBSS,KeyInterpOut.b0*180./M_PI);
04469 statusA[11]= drms_setkey_float(recLev1p->records[timeindex],CROTA2S,-KeyInterpOut.p0*180./M_PI);
04470 statusA[12]= drms_setkey_float(recLev1p->records[timeindex],CDELT1S,cdelt1);
04471 statusA[13]= drms_setkey_float(recLev1p->records[timeindex],CDELT2S,cdelt1);
04472 statusA[14]= drms_setkey_float(recLev1p->records[timeindex],CRPIX1S,KeyInterpOut.xx0+1.);
04473 statusA[15]= drms_setkey_float(recLev1p->records[timeindex],CRPIX2S,KeyInterpOut.yy0+1.);
04474 sprintf(jsocverss,"%d",jsoc_vers_num);
04475 statusA[16]= drms_setkey_string(recLev1p->records[timeindex],BLDVERSS,jsocverss);
04476 statusA[17]= drms_setkey_double(recLev1p->records[timeindex],OBSVRS,OBSVRint[timeindex]);
04477 statusA[18]= drms_setkey_double(recLev1p->records[timeindex],OBSVWS,OBSVWint[timeindex]);
04478 statusA[19]= drms_setkey_double(recLev1p->records[timeindex],OBSVNS,OBSVNint[timeindex]);
04479
04480 statusA[20]=0;
04481 statusA[21]= drms_setkey_float(recLev1p->records[timeindex],CRLNOBSS,CRLNOBSint[timeindex]);
04482 statusA[22]= drms_setkey_int(recLev1p->records[timeindex],CARROTS,CARROTint[timeindex]);
04483 statusA[24]= drms_setkey_int(recLev1p->records[timeindex],SINTNUMS,const_param.order_int);
04484 statusA[25]= drms_setkey_string(recLev1p->records[timeindex],CODEVER0S,CODEVERSION);
04485 statusA[26]= drms_setkey_string(recLev1p->records[timeindex],DISTCOEFS,DISTCOEFPATH);
04486 statusA[27]= drms_setkey_string(recLev1p->records[timeindex],ROTCOEFS,ROTCOEFPATH);
04487 statusA[28]= drms_setkey_int(recLev1p->records[timeindex],ODICOEFFS,const_param.order_dist_coef);
04488 statusA[29]= drms_setkey_int(recLev1p->records[timeindex],OROCOEFFS,2*const_param.order2_rot_coef);
04489 statusA[30]= drms_setkey_string(recLev1p->records[timeindex],CODEVER1S,CODEVERSION1);
04490 statusA[31]= drms_setkey_string(recLev1p->records[timeindex],CODEVER2S,CODEVERSION2);
04491 statusA[32]= drms_setkey_float(recLev1p->records[timeindex] ,TFRONTS,TFRONT);
04492 statusA[33]= drms_setkey_float(recLev1p->records[timeindex] ,TSELS,TSEL);
04493 statusA[34]= drms_setkey_int(recLev1p->records[timeindex] ,POLCALMS,method);
04494 statusA[35]= drms_setkey_string(recLev1p->records[timeindex],CODEVER3S,CODEVERSION3);
04495 statusA[36]= drms_setkey_float(recLev1p->records[timeindex],RSUNOBSS,asin(solar_radius/(KeyInterpOut.dist*AstroUnit))*180.*60.*60./M_PI);
04496 sprint_time(DATEOBS,tobs-DataCadence/2.0,"UTC",1);
04497 statusA[37]= drms_setkey_string(recLev1p->records[timeindex],DATEOBSS,DATEOBS);
04498 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
04499 statusA[38]= drms_setkey_string(recLev1p->records[timeindex],DATES,DATEOBS);
04500 statusA[39]= drms_setkey_int(recLev1p->records[timeindex],HWLTIDS,TargetHWLTID);
04501 statusA[40]= drms_setkey_int(recLev1p->records[timeindex],HPLTIDS,TargetHPLTID);
04502 statusA[41]= drms_setkey_int(recLev1p->records[timeindex],WavelengthIDS,WavelengthID);
04503 if(camera == 2) strcpy(DATEOBS,"HMI_FRONT2");
04504 if(camera == 1) strcpy(DATEOBS,"HMI_SIDE1");
04505 if(camera == 3) strcpy(DATEOBS,"HMI_COMBINED");
04506 statusA[42]= drms_setkey_string(recLev1p->records[timeindex],INSTRUMES,DATEOBS);
04507 statusA[43]= drms_setkey_int(recLev1p->records[timeindex],HCAMIDS,CamId);
04508
04509 if(inLinearity == 1) CALVER32[0] = CALVER32[0] | CALVER_LINEARITY;
04510 if(inRotationalFlat == 1) CALVER32[0] = CALVER32[0] | CALVER_ROTATIONAL;
04511 if(TargetHFLID == 58312 || TargetHFLID == 1022 || TargetHFLID == 2032
04512 || TargetHFLID == 2042 || TargetHFLID == 2043 || TargetHFLID == 3040
04513 || TargetHFLID == 3041 || TargetHFLID == 3042 || TargetHFLID == 3043
04514 || TargetHFLID == 3048) {
04515 CALVER32[0] = CALVER32[0] | CALVER_MODL;} else CALVER32[0] = CALVER32[0] & CALVER_NOMODL;
04516 statusA[45]= drms_setkey_longlong(recLev1p->records[timeindex],CALVER64S,CALVER32[0]);
04517
04518 TotalStatus=0;
04519 for(i=0;i<46;++i)
04520 if(TotalStatus != 0)
04521 {
04522 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the level 1p data at target time %s\n",timeBegin2);
04523 }
04524 }
04525
04526
04527 if(it != nWavelengths-1) statusA[44]= drms_setkey_string(recLev1p->records[timeindex],SOURCES,source[timeindex]);
04528 else statusA[44]= drms_setkey_string(recLev1p->records[timeindex],SOURCES,strcat(source[timeindex],"]"));
04529
04530 printf("Peopling imagesout arrays\n");
04531 for(i=0;i<npolout;++i) imagesout[i]=arrLev1p[i]->data;
04532
04533
04534
04535
04536 printf("Producing level 1p data, npol= %d; polarization type= %d; npolout= %d; %d %d %d \n",npol,PolarizationType,npolout,axisout[0],axisout[1],axisout[1]);
04537 polcal(&pars,npol,PolarizationType,images,imagesout,ps1,ps2,ps3,TSEL,TFRONT,axisout[0],axisout[1],axisout[1]);
04538
04539
04540
04541
04542
04543 for(i=0;i<npolout;++i)
04544 {
04545 printf("writing segment %d out of %d\n",i,npolout);
04546 segout = drms_segment_lookup(recLev1p->records[timeindex],Lev1pSegName[it*npolout+i]);
04547 arrLev1p[i]->bzero=segout->bzero;
04548 arrLev1p[i]->bscale=segout->bscale;
04549 arrLev1p[i]->israw=0;
04550 status=drms_segment_write(segout,arrLev1p[i],0);
04551 if(status != DRMS_SUCCESS)
04552 {
04553 printf("Error: a call to drms_segment_write failed\n");
04554 return 1;
04555 }
04556
04557
04558
04559 status=fstats(axisout[0]*axisout[1],imagesout[i],&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
04560 if(status != 0)
04561 {
04562 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
04563 }
04564 statusA[0]= drms_setkey_float(recLev1p->records[timeindex],DATAMINS[it*npolout+i],(float)minimum);
04565 statusA[1]= drms_setkey_float(recLev1p->records[timeindex],DATAMAXS[it*npolout+i],(float)maximum);
04566 statusA[2]= drms_setkey_float(recLev1p->records[timeindex],DATAMEDNS[it*npolout+i],(float)median);
04567 statusA[3]= drms_setkey_float(recLev1p->records[timeindex],DATAMEANS[it*npolout+i],(float)mean);
04568 statusA[4]= drms_setkey_float(recLev1p->records[timeindex],DATARMSS[it*npolout+i],(float)sigma);
04569 statusA[5]= drms_setkey_float(recLev1p->records[timeindex],DATASKEWS[it*npolout+i],(float)skewness);
04570 statusA[6]= drms_setkey_float(recLev1p->records[timeindex],DATAKURTS[it*npolout+i],(float)kurtosis);
04571 statusA[7]= drms_setkey_int(recLev1p->records[timeindex],TOTVALSS[it*npolout+i],axisout[0]*axisout[1]);
04572 statusA[8]= drms_setkey_int(recLev1p->records[timeindex],DATAVALSS[it*npolout+i],ngood);
04573 statusA[9]= drms_setkey_int(recLev1p->records[timeindex],MISSVALSS[it*npolout+i],axisout[0]*axisout[1]-ngood);
04574
04575 image=arrLev1p[i]->data;
04576 for(ii=0;ii<axisout[0]*axisout[1];++ii)
04577 {
04578 row =ii / axisout[0];
04579 column=ii % axisout[0];
04580 distance = sqrt(((float)row-Y0AVG[timeindex])*((float)row-Y0AVG[timeindex])+((float)column-X0AVG[timeindex])*((float)column-X0AVG[timeindex]));
04581 if(distance > 0.99*RSUNint[timeindex]) image[ii]=NAN;
04582 }
04583
04584 status=fstats(axisout[0]*axisout[1],imagesout[i],&minimum,&maximum,&median,&mean,&sigma,&skewness,&kurtosis,&ngood);
04585 if(status != 0)
04586 {
04587 printf("Error: the statistics function did not run properly at target time %s\n",timeBegin2);
04588 }
04589 statusA[0]= drms_setkey_float(recLev1p->records[timeindex],DATAMINS2[it*npolout+i],(float)minimum);
04590 statusA[1]= drms_setkey_float(recLev1p->records[timeindex],DATAMAXS2[it*npolout+i],(float)maximum);
04591 statusA[2]= drms_setkey_float(recLev1p->records[timeindex],DATAMEDNS2[it*npolout+i],(float)median);
04592 statusA[3]= drms_setkey_float(recLev1p->records[timeindex],DATAMEANS2[it*npolout+i],(float)mean);
04593 statusA[4]= drms_setkey_float(recLev1p->records[timeindex],DATARMSS2[it*npolout+i],(float)sigma);
04594 statusA[5]= drms_setkey_float(recLev1p->records[timeindex],DATASKEWS2[it*npolout+i],(float)skewness);
04595 statusA[6]= drms_setkey_float(recLev1p->records[timeindex],DATAKURTS2[it*npolout+i],(float)kurtosis);
04596
04597 TotalStatus=0;
04598 for(ii=0;ii<10;++ii) TotalStatus+=statusA[ii];
04599 if(TotalStatus != 0)
04600 {
04601 for(ii=0;ii<10;++ii) printf(" %d ",statusA[ii]);
04602 printf("\n");
04603 printf("WARNING: could not set some of the keywords modified by the temporal interpolation subroutine for the level 1p data at target time %s\n",timeBegin2);
04604 }
04605
04606 }
04607
04608 NextTargetTime:
04609
04610
04611
04612
04613
04614
04615
04616
04617
04618 printf("FREEING RECORD\n");
04619 if(nIndexFiltergram != 0)
04620 {
04621 printf("free arrLev1d\n");
04622 for(i=0;i<Npolin;++i)
04623 {
04624 drms_free_array(arrLev1d[i]);
04625 arrLev1d[i]=NULL;
04626 }
04627 free(arrLev1d);
04628 arrLev1d=NULL;
04629
04630 if(arrLev1p != NULL)
04631 {
04632 for(i=0;i<npolout;++i) if(arrLev1p[i] != NULL)
04633 {
04634 drms_free_array(arrLev1p[i]);
04635 arrLev1p[i]=NULL;
04636 }
04637 }
04638 }
04639
04640 if(CreateEmptyRecord)
04641 {
04642 printf("Warning: creating/updating empty lev1p record\n");
04643 QUALITY[timeindex]= QUALITY[timeindex] | QUAL_NODATA;
04644
04645
04646
04647
04648 if(CamId == LIGHT_SIDE) camera=1;
04649 if(CamId == LIGHT_FRONT) camera=2;
04650 if(combineYesNo == 1) camera=3;
04651
04652
04653 statusA[0] = drms_setkey_time(recLev1p->records[timeindex],TRECS,TargetTime);
04654
04655 statusA[2] = drms_setkey_int(recLev1p->records[timeindex],CAMERAS,camera);
04656 statusA[3] = drms_setkey_int(recLev1p->records[timeindex],QUALITYS,QUALITY[timeindex]);
04657 sprint_time(DATEOBS,CURRENT_SYSTEM_TIME,"UTC",1);
04658 statusA[4]= drms_setkey_string(recLev1p->records[timeindex],DATES,DATEOBS);
04659
04660 CreateEmptyRecord=0;
04661 }
04662
04663
04664 printf("TIME= %f\n",TargetTime);
04665 PreviousTargetTime=TargetTime;
04666 TargetTime+=AverageTime;
04667 printf("TIME= %f\n",TargetTime);
04668 printf("END TIME= %f\n",TimeEnd);
04669 timeindex+=1;
04670 initialrun=0;
04671 }
04672
04673 }
04674
04675
04676 printf("END LOOP OVER WAVELENGTHS\n");
04677
04678 printf("INSERT LEVEL 1p RECORDS IN DRMS\n");
04679 if(recLev1p != NULL && recLev1p->n != 0)
04680 {
04681 status=drms_close_records(recLev1p,DRMS_INSERT_RECORD);
04682 recLev1p=NULL;
04683 }
04684
04685 if(nIndexFiltergram != 0)
04686 {
04687
04688 free(FramelistArray);
04689 FramelistArray=NULL;
04690
04691 if(recLev1->n > 0)
04692 {
04693 status=drms_close_records(recLev1,DRMS_FREE_RECORD);
04694 recLev1=NULL;
04695 free(internTOBS);
04696 free(HWL1POS);
04697 free(HWL2POS);
04698 free(HWL3POS);
04699 free(HWL4POS);
04700 free(HPL1POS);
04701 free(HPL2POS);
04702 free(HPL3POS);
04703 free(HWLTID);
04704 free(HPLTID);
04705 free(FID);
04706 free(HFLID);
04707 free(HCAMID);
04708 free(RSUN);
04709 free(CROTA2);
04710 free(CRLTOBS);
04711 free(DSUNOBS);
04712 free(X0);
04713 free(Y0);
04714 free(SegmentRead);
04715 free(KeywordMissing);
04716 free(Segments);
04717
04718 if(inRotationalFlat == 1)
04719 {
04720 drms_free_array(flatfield);
04721 drms_free_array(flatfieldrot);
04722 status=drms_close_records(recflatrot,DRMS_FREE_RECORD);
04723 }
04724 free(Badkeyword);
04725 free(Ierror);
04726 free(IndexFiltergram);
04727 free(FSN);
04728 free(CFINDEX);
04729 free(HIMGCFID);
04730 for(i=0;i<nRecs1;++i) free(IMGTYPE[i]);
04731 free(IMGTYPE);
04732 free(CDELT1);
04733 for(i=0;i<nRecs1;++i) free(HWLTNSET[i]);
04734 free(HWLTNSET);
04735 free(NBADPERM);
04736 free(QUALITYin);
04737 free(EXPTIME);
04738 free(CAMERA);
04739 free(CALVER32);
04740 }
04741
04742 for(i=0;i<nTime;++i) free(source[i]);
04743 free(source);
04744 free(totalTempIntNum);
04745 free(images);
04746 free(imagesout);
04747 free(ps1);
04748 free(ps2);
04749 free(ps3);
04750 free(imagesi);
04751 free(ierrors);
04752 images=NULL;
04753 ierrors=NULL;
04754 free(KeyInterp);
04755 KeyInterp=NULL;
04756 free(X0AVG);
04757 free(Y0AVG);
04758 free(CAMAVG);
04759 free(RSUNAVG);
04760 free(X0RMS);
04761 free(Y0RMS);
04762 free(RSUNRMS);
04763 free(OBSVRint);
04764 free(OBSVWint);
04765 free(OBSVNint);
04766 free(CRLNOBSint);
04767 free(CRLTOBSint);
04768
04769 free(DSUNOBSint);
04770 free(CROTA2int);
04771 free(RSUNint);
04772 free(CARROTint);
04773 free(QUALITY);
04774 free(QUALITYLEV1);
04775 free(QUALITYlev1);
04776 for(i=0;i<nWavelengths*npolout;i++)
04777 {
04778 free(DATAMINS[i]);
04779 free(DATAMAXS[i]);
04780 free(DATAMEDNS[i]);
04781 free(DATAMEANS[i]);
04782 free(DATARMSS[i]);
04783 free(DATASKEWS[i]);
04784 free(DATAMINS2[i]);
04785 free(DATAMAXS2[i]);
04786 free(DATAMEDNS2[i]);
04787 free(DATAMEANS2[i]);
04788 free(DATARMSS2[i]);
04789 free(DATASKEWS2[i]);
04790 free(TOTVALSS[i]);
04791 free(MISSVALSS[i]);
04792 free(DATAVALSS[i]);
04793 }
04794 free(DATAMINS);
04795 free(DATAMAXS);
04796 free(DATAMEDNS);
04797 free(DATAMEANS);
04798 free(DATARMSS);
04799 free(DATASKEWS);
04800 free(DATAMINS2);
04801 free(DATAMAXS2);
04802 free(DATAMEDNS2);
04803 free(DATAMEANS2);
04804 free(DATARMSS2);
04805 free(DATASKEWS2);
04806 free(TOTVALSS);
04807 free(MISSVALSS);
04808 free(DATAVALSS);
04809
04810 free_interpol(&const_param);
04811 status = free_polcal(&pars);
04812 free(Mask);
04813 }
04814
04815 free(CODEVERSION);
04816 free(CODEVERSION1);
04817 free(CODEVERSION2);
04818 free(CODEVERSION3);
04819 free(DISTCOEFFILEF);
04820 free(DISTCOEFFILES);
04821 free(ROTCOEFFILE);
04822 free(DISTCOEFPATH);
04823 free(ROTCOEFPATH);
04824
04825 printf("END PROGRAM\n");
04826
04827 status=0;
04828 return status;
04829
04830 }
04831
04832