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