00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
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
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 #define QUICKRUN 0
00206
00207
00208
00209
00210
00211
00212 #define RECTANGL 0
00213
00214
00215
00216 #define NRMLFLTR 1
00217
00218
00219
00220
00221 #define INTBSCLE 1
00222
00223
00224
00225
00226
00227
00228
00229 #define VLOSINIT 0
00230
00231
00232
00233
00234 #define MGSTINIT 0
00235
00236
00237
00238
00239
00240 #define NLEVPIXL 1
00241
00242
00243
00244
00245
00246 #define SKIPBADQ 0
00247
00248
00249
00250
00251
00252 #define EQUIAREA 1
00253
00254
00255
00256
00257
00258
00259 #define CYCLPRLL 1
00260
00261
00262
00263
00264
00265 #define MASKPTCH 0
00266
00267
00268
00269
00270
00271
00272
00273 #define HARPATCH 0
00274
00275
00276 #define HARPBLOB 0
00277
00278
00279
00280 #define MULTHARP 1
00281
00282
00283
00284
00285
00286
00287
00288 #define HANDHARP 0
00289
00290
00291
00292
00293 #define TAKEPREV 0
00294
00295
00296
00297
00298 #define CHNGTREC 0
00299
00300
00301
00302 #define CONFINDX 1
00303
00304
00305
00306
00307
00308 #define ADNEWKWD 1
00309
00310
00311
00312
00313
00314
00315 #define CHCKSKIP 1
00316
00317
00318 #define DIE(msg) {fflush(stdout);fprintf(stderr,"%s, status=%d\n",msg,status); return(status);}
00319
00320
00321 #if HARPATCH == 1
00322 char *module_name = "vfisvcombine FD10 HARP";
00323 #else
00324 char *module_name = "vfisvcombine FD10";
00325 #endif
00326
00327 char *version_id = "2013 Apr. 30";
00328
00329
00330
00331 extern void invert_ (double *, double *, double *, double *, double *, double[*][*], int *, double *);
00332 extern void filt_init_ (int *, double *, int *);
00333 extern void free_init_ (int *);
00334 extern void free_memory_ ();
00335 extern void inv_init_ (int *, double *, double *, double *, double *);
00336 extern void vfisvalloc_ (int *, int *, int *);
00337 extern void lim_init_ (double *);
00338 #if NLEVPIXL == 1
00339 extern void line_init_ (double *, double *, double [4]);
00340 #else
00341 extern void line_init_(double *, double *, double *);
00342 #endif
00343
00344 extern void voigt_init_ ();
00345 extern void wave_init_ (double *, double *, int *);
00346
00347 #include <jsoc_main.h>
00348 #include <math.h>
00349 #include <mpi.h>
00350
00351 ModuleArgs_t module_args[] = {
00352 {ARG_STRING, "in", "hmi.S_720s[2012.02.15_00:00:00_TAI]", "input record"},
00353 {ARG_STRING, "out", "hmi.ME_720s", "output series"},
00354 #if CHNGTREC == 1
00355 {ARG_STRING, "out2", "2020.01.02_03:45:00_TAI", "dummy T_REC"},
00356 #endif
00357 #if TAKEPREV == 1
00358 {ARG_STRING, "in2", "hmi.ME_720s[2011.02.15_00:00:00_TAI]", "reference inversion results"},
00359 #endif
00360 #if HARPATCH == 1
00361 #if MULTHARP == 1
00362 {ARG_STRING, "in3", "hmi.Mharp_720s[][2011.02.15_00:00:00_TAI]", "HARP masking bitmap data"},
00363 #else
00364 {ARG_STRING, "in3", "hmi.Mharp_720s[380][2011.02.15_00:00:00_TAI]", "HARP masking bitmap data"},
00365 #endif
00366 #endif
00367 #if MASKPTCH == 1
00368 {ARG_STRING, "in3", "su_xudong.mask4inv[2010.08.01_12:12:00_TAI]", "some masking bitmap data"},
00369 #endif
00370 #if VLOSINIT == 1
00371 {ARG_STRING, "in4", "hmi.V_720s[2012.02.15_00:00:00_TAI]", "Doppler as initial guess"},
00372 #endif
00373 #if MGSTINIT == 1 || CONFINDX == 1
00374 {ARG_STRING, "in5", "hmi.M_720s[2012.02.15_00:00:00_TAI]", "magnetogram as initial guess"},
00375 #endif
00376
00377 {ARG_INT, "num_iter", "200", "number of iterations(default: 30)"},
00378 {ARG_INT, "num_lambda", "149", "number of ??(default: 33)"},
00379 {ARG_DOUBLE, "Lambda_Min", "-1998.0", "Intensity threshold (default: -432)"},
00380 {ARG_INT, "Num_lambda_filter", "6", "Number of filters accross the wvl (default: 6)"},
00381 {ARG_INT, "Num_tunning", "6", "Number of ??(default: 6)"},
00382 {ARG_INT, "num_lambda_synth", "49", "Number of synthetic filters (default: 6)"},
00383 {ARG_DOUBLE, "Lambda_Min_synth", "-648.0", "Intensity threshold (default: -432)"},
00384 {ARG_DOUBLE, "svd_tolerance", "1.0e-32", "svd tolerance (default: 1.0e-32)"},
00385 {ARG_DOUBLE, "chi2_stop", "1.0e-15", "chisq-stop (default: 1.0e-6)"},
00386 {ARG_DOUBLE, "Polarization_threshold", "1.0e-2", "polarization threshold (default: 0.01)"},
00387 {ARG_DOUBLE, "Percentage_Jump", "10.0", "Percentage Jump (default: 10%)"},
00388 {ARG_DOUBLE, "Lambda_0", "6173.3433", "Wavelength(default:6173.3433 Angstrom )"},
00389 {ARG_DOUBLE, "Lambda_B", "0.044475775", "FWHM?? (default: 0.044475775)"},
00390 {ARG_DOUBLE, "Delta_Lambda", "27.0", "Delta Lambda(default: 27.0)"},
00391 {ARG_DOUBLE, "Lyotfwhm", "424.0", "Lyot filter FWHM (default: 424.0)"},
00392 {ARG_DOUBLE, "Wnarrow", "172.0", "FSR (full spectral range) of the Narrow-Band Michelson"},
00393 {ARG_DOUBLE, "Wspacing", "69.0", "wavelength spacing between the HMI filters"},
00394 {ARG_DOUBLE, "Intensity_Threshold", "1.0e2", "Intensity threshold (default: 0.8)"},
00395 #if NLEVPIXL == 1
00396 {ARG_DOUBLE, "Noise_LEVELFI", "0.118", "Noise Sigma factor for I"},
00397 {ARG_DOUBLE, "Noise_LEVELFQ", "0.204", "Noise Sigma factor for Q"},
00398 {ARG_DOUBLE, "Noise_LEVELFU", "0.204", "Noise Sigma factor for U"},
00399 {ARG_DOUBLE, "Noise_LEVELFV", "0.204", "Noise Sigma factor for V"},
00400 #else
00401 {ARG_DOUBLE, "Noise_LEVEL", "4.9e1", "Intensity threshold (default: 3.0e-3)"},
00402 #endif
00403 {ARG_INT, "Continuum", "0", "Intensity threshold (default: 0)"},
00404
00405 {ARG_FLAG, "v", "", "run verbose"},
00406 {ARG_FLAG, "f", "", "enforce overwritng"},
00407
00408 {}
00409 };
00410
00411 int DoIt (void)
00412 {
00413
00414 CmdParams_t *params = &cmdparams;
00415 DRMS_RecordSet_t *inRS;
00416 DRMS_Record_t *inRec, *outRec;
00417 DRMS_Segment_t *inSeg, *outSeg;
00418 DRMS_Array_t *stokes_array, *invrt_array, *err_array, *flg_array, *qmap_array;
00419
00420
00421 const int NUM_ITERATIONSc = params_get_int(params, "num_iter");
00422 const int NUM_LAMBDAc = params_get_int(params, "num_lambda");
00423 const int NUM_LAMBDA_FILTERc = params_get_int(params, "Num_lambda_filter");
00424 const int NUM_TUNNINGc = params_get_int(params, "Num_tunning");
00425 const int CONTINUUMc = params_get_int(params, "Continuum");
00426 const double SVD_TOLERANCEc = params_get_double(params, "svd_tolerance");
00427 const double CHI2_STOPc = params_get_double(params, "chi2_stop");
00428 const double POLARIZATION_THRESHOLDc = params_get_double(params, "Polarization_threshold");
00429 const double INTENSITY_THRESHOLDc = params_get_double(params, "Intensity_Threshold");
00430 const double PERCENTAGE_JUMPc = params_get_double(params, "Percentage_Jump");
00431 const double LAMBDA_MINc = params_get_double(params, "Lambda_Min");
00432 const double LAMBDA_0c = params_get_double(params, "Lambda_0");
00433 const double LAMBDA_Bc = params_get_double(params, "Lambda_B");
00434 const double DELTA_LAMBDAc = params_get_double(params, "Delta_Lambda");
00435 #if NLEVPIXL == 1
00436 double NOISE_LEVELFIc = params_get_double(params, "Noise_LEVELFI");
00437 double NOISE_LEVELFQc = params_get_double(params, "Noise_LEVELFQ");
00438 double NOISE_LEVELFUc = params_get_double(params, "Noise_LEVELFU");
00439 double NOISE_LEVELFVc = params_get_double(params, "Noise_LEVELFV");
00440 #else
00441 const double NOISE_LEVELc = params_get_double(params, "Noise_LEVEL");
00442 #endif
00443 const double LYOTFWHMc = params_get_double(params, "Lyotfwhm");
00444 const double WNARROWc = params_get_double(params, "Wnarrow");
00445 const double WSPACINGc = params_get_double(params, "Wspacing");
00446 const char *indsdescc = params_get_str(params, "in");
00447 const char *outserc = params_get_str(params, "out");
00448
00449 const int NUM_LAMBDA_synthc = params_get_int(params, "num_lambda_synth");
00450 const double LAMBDA_MIN_synthc = params_get_double(params, "Lambda_Min_synth");
00451
00452 int cameraID;
00453 int rn, rec_ct, sn, seg_ct;
00454 int status;
00455
00456
00457
00458
00459 inRS = drms_open_records (drms_env, indsdescc, &status);
00460 if (status) {DIE("drms_open_records failed.\n");}
00461 if ((rec_ct = inRS->n) == 0){DIE("No records in selected dataset.\n");}
00462 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
00463 inRec = inRS->records[0];
00464 cameraID = drms_getkey_int(inRec,"CAMERA",&status);
00465 drms_close_records(inRS, DRMS_FREE_RECORD);
00466
00467
00468 #if NLEVPIXL == 1
00469 if (cameraID == 3)
00470 {
00471 NOISE_LEVELFIc = 0.083;
00472 NOISE_LEVELFQc = 0.167;
00473 NOISE_LEVELFUc = 0.167;
00474 NOISE_LEVELFVc = 0.118;
00475 }
00476 #endif
00477
00478
00479
00480
00481
00482 #if TAKEPREV == 1
00483 const char *indsdesc2c= params_get_str(params, "in2");
00484 #endif
00485 #if MASKPTCH == 1 || HARPATCH == 1
00486 const char *indsdesc3c= params_get_str(params, "in3");
00487 #endif
00488 #if VLOSINIT == 1
00489 const char *indsdesc4c= params_get_str(params, "in4");
00490 #endif
00491 #if MGSTINIT == 1 || CONFINDX == 1
00492 const char *indsdesc5c= params_get_str(params, "in5");
00493 #endif
00494 #if CHNGTREC == 1
00495 const char *outtrecc = params_get_str(params, "out2");
00496 #endif
00497
00498 const int verbosec = params_isflagset(params, "v");
00499 const int enfdoitc = params_isflagset(params, "f");
00500
00501
00502
00503 char *indsdesc, *outser;
00504 #if CHNGTREC == 1
00505 char *outtrec;
00506 #endif
00507 #if TAKEPREV == 1
00508 char *indsdesc2;
00509 #endif
00510 #if MASKPTCH == 1 || HARPATCH == 1
00511 char *indsdesc3;
00512 #endif
00513 #if VLOSINIT == 1
00514 char *indsdesc4;
00515 #endif
00516 #if MGSTINIT == 1 || CONFINDX == 1
00517 char *indsdesc5;
00518 #endif
00519 int verbose, enfdoit;
00520
00521 int NUM_ITERATIONS, NUM_LAMBDA, NUM_LAMBDA_FILTER, NUM_TUNNING, CONTINUUM;
00522 double SVD_TOLERANCE, CHI2_STOP, POLARIZATION_THRESHOLD, INTENSITY_THRESHOLD, PERCENTAGE_JUMP;
00523 double LAMBDA_0, LAMBDA_B;
00524 #if NLEVPIXL == 1
00525 double NOISE_LEVEL[4];
00526 double NOISE_LEVELFI;
00527 double NOISE_LEVELFQ;
00528 double NOISE_LEVELFU;
00529 double NOISE_LEVELFV;
00530 #else
00531 double NOISE_LEVEL;
00532 #endif
00533 double LAMBDA_MIN, DELTA_LAMBDA;
00534 double LYOTFWHM, WNARROW, WSPACING;
00535 int NUM_LAMBDA_synth;
00536 double LAMBDA_MIN_synth;
00537
00538 NUM_ITERATIONS = NUM_ITERATIONSc;
00539 NUM_LAMBDA = NUM_LAMBDAc;
00540 NUM_LAMBDA_FILTER = NUM_LAMBDA_FILTERc;
00541 NUM_TUNNING = NUM_TUNNINGc;
00542 CONTINUUM = CONTINUUMc;
00543 SVD_TOLERANCE = SVD_TOLERANCEc;
00544 CHI2_STOP = CHI2_STOPc;
00545 POLARIZATION_THRESHOLD = POLARIZATION_THRESHOLDc;
00546 INTENSITY_THRESHOLD = INTENSITY_THRESHOLDc;
00547 PERCENTAGE_JUMP = PERCENTAGE_JUMPc;
00548 LAMBDA_0 = LAMBDA_0c;
00549 LAMBDA_B = LAMBDA_Bc;
00550
00551 #if NLEVPIXL == 1
00552 NOISE_LEVELFI = NOISE_LEVELFIc;
00553 NOISE_LEVELFQ = NOISE_LEVELFQc;
00554 NOISE_LEVELFU = NOISE_LEVELFUc;
00555 NOISE_LEVELFV = NOISE_LEVELFVc;
00556 #else
00557 NOISE_LEVEL = NOISE_LEVELc;
00558 #endif
00559
00560 LAMBDA_MIN = LAMBDA_MINc;
00561 DELTA_LAMBDA = DELTA_LAMBDAc;
00562 LYOTFWHM = LYOTFWHMc;
00563 WNARROW = WNARROWc;
00564 WSPACING = WSPACINGc;
00565
00566 NUM_LAMBDA_synth = NUM_LAMBDA_synthc;
00567 LAMBDA_MIN_synth = LAMBDA_MIN_synthc;
00568
00569 verbose = verbosec;
00570 enfdoit = enfdoitc;
00571
00572 indsdesc = strdup(indsdescc);
00573 #if CHNGTREC == 1
00574 outtrec= strdup(outtrecc);
00575 #endif
00576 #if TAKEPREV == 1
00577 indsdesc2= strdup(indsdesc2c);
00578 #endif
00579 #if MASKPTCH == 1 || HARPATCH == 1
00580 indsdesc3= strdup(indsdesc3c);
00581 #endif
00582 #if VLOSINIT == 1
00583 indsdesc4= strdup(indsdesc4c);
00584 #endif
00585 #if MGSTINIT == 1 || CONFINDX == 1
00586 indsdesc5= strdup(indsdesc5c);
00587 #endif
00588 outser = strdup(outserc);
00589
00590
00591 int list_free_params[10]={1,1,1,0,1,1,1,1,1,0};
00592 double guess[10]= {15.0,90.0,45.0,0.5,50.0,150.0,0.0,0.4*6e3,0.6*6e3,1.0};
00593 int keyfreep;
00594 keyfreep = 0x000003be;
00595
00596
00597 char *Resname[] = {"eta_0", "inclination", "azimuth", "damping", "dop_width", "field",
00598 "vlos_mag", "src_continuum", "src_grad", "alpha_mag",
00599 "field_err","inclination_err","azimuth_err", "vlos_err", "alpha_err",
00600 "field_inclination_err","field_az_err","inclin_azimuth_err", "field_alpha_err",
00601 "inclination_alpha_err", "azimuth_alpha_err", "chisq",
00602 "conv_flag", "qual_map", "confid_map"};
00603 int Err_ct=12;
00604 char segname[16];
00605 char *spname[] = {"I", "Q", "U", "V"};
00606 int spct = (sizeof (spname) / sizeof (char *));
00607 int wlct = NUM_LAMBDA_FILTERc;
00608 int paramct = 10;
00609
00610
00611
00612
00613
00614
00615
00616
00617 double bzero_inv[25] = {0.0,0.0,0.0,0.0,0.0,0.0,
00618 0.0,0.0,0.0,0.0,
00619 0.0,0.0,0.0,0.0,0.0,
00620 0.0,0.0,0.0,0.0,
00621 0.0,0.0,0.0,
00622 0.0,0.0,0.0};
00623 double bscaleinv[25] = {0.01,0.01,0.01,0.0001,0.01,0.01,
00624 50.0,0.1,0.1,0.0001,
00625 0.01,0.01,0.01,50.0,0.01,
00626 0.0001,0.0001,0.0001,0.0001,
00627 0.0001,0.0001,0.0001,
00628 1.0,1.0,1.0};
00629
00630
00631 int *FinalConvFlag;
00632 int *FinalConfidMap;
00633 int *FinalQualMap;
00634 double *FinalRes,*FinalErr;
00635 time_t startime, endtime, starttime1, endtime1;
00636 double *ddat, *res;
00637 double *obs, *scat, *err;
00638 double *weights;
00639 float *data, *data0;
00640 int *nan_map;
00641
00642 int cols, rows, imgpix, imgbytes;
00643 int sp, wl, nvar;
00644 int j,m,i,k,n;
00645
00646 int iquality;
00647 int nharp = 0;
00648 #if RECTANGL == 1 || HARPATCH == 1
00649
00650 int xleftbot = 1885;
00651 int yleftbot = 1410;
00652 int xwidth = 100;
00653 int yheight = 100;
00654 #endif
00655
00656 MPI_Status mpistat;
00657 int mpi_tag, mpi_rank, mpi_size;
00658 int myrank, nprocs, numpix;
00659 int istart, iend;
00660 int *istartall, *iendall;
00661 void para_range(int,int,int,int *,int *);
00662 #if CYCLPRLL == 1
00663 int *jobassignmap;
00664 int jobnum;
00665 #endif
00666
00667 float obs_vr;
00668 float crpixx, crpixy;
00669 float cdeltx, cdelty;
00670 float rsun_ref, dsun_obs;
00671 float sunarc;
00672 float crota2;
00673 float sunradfpix;
00674
00675 char *meinversion_version();
00676
00677
00678 int vfisv_filter(int ,int ,double[*][*],double ,double ,double *,double *,int ,double *,double *,int ,
00679 double, double [4],double [3],double [4],double [3],double *,double *,double *,
00680 int, double ,int ,int ,int ,int);
00681 int initialize_vfisv_filter(double *,double *,int *,double *,double *,int *,double *,double *,
00682 double *,double *,double *,double *,double *,double *,int *,int *,int *,int *,int *,TIME,int *);
00683 double filters[NUM_LAMBDA_FILTERc][NUM_LAMBDAc];
00684 double *wavelengthd=NULL;
00685 double *frontwindowd=NULL;
00686 int nfront;
00687 double *wavelengthbd=NULL;
00688 double *blockerbd=NULL;
00689 int nblocker;
00690 double centerblocker;
00691 double *phaseNT=NULL;
00692 double *phaseT=NULL;
00693 double *contrastNT=NULL;
00694 double *contrastT=NULL;
00695 double *FSR=NULL;
00696 double *lineref=NULL;
00697 double *wavelengthref=NULL;
00698 int referencenlam;
00699 double distance;
00700 double phaseTi[3];
00701 double phaseNTi[4];
00702 double contrastTi[3];
00703 double contrastNTi[4];
00704 int HCME1;
00705 int HCMWB;
00706 int HCMNB;
00707 int HCMPOL;
00708 TIME stokestime;
00709
00710 #if ADNEWKWD == 1
00711 int set_statistics(DRMS_Segment_t *, DRMS_Array_t *, int);
00712 #endif
00713
00714 #if VLOSINIT == 1
00715 float *vlos_init;
00716 int iexistdoppler;
00717 iexistdoppler = 0;
00718 #endif
00719 #if MGSTINIT == 1 || CONFINDX == 1
00720 float *mgst_init;
00721 int iexistmagnetogram;
00722 iexistmagnetogram = 0;
00723 float *blosgram;
00724 #endif
00725 #if TAKEPREV == 1
00726 float *prevdata;
00727 int iexistprev;
00728 #endif
00729 #if MASKPTCH == 1 || HARPATCH == 1
00730 int *patchmask;
00731 int iexistpatchmask;
00732 iexistpatchmask = 0;
00733 #endif
00734
00735
00736 #if MASKPTCH == 1 && HARPATCH == 1
00737 DIE(" Both MASKPTCH and HARPATCH set 1. So terminated !\n");
00738 #endif
00739 #if RECTANGL == 1 && HARPATCH == 1
00740 DIE(" Both RECTANGL and HARPATCH set 1. So terminated !\n");
00741 #endif
00742 #if EQUIAREA != 1 && CYCLPRLL == 1
00743 DIE(" CYCLPRLL cannot work when EQUIAREA is turned off. So terminated !\n");
00744 #endif
00745
00746
00747 time(&startime);
00748
00749
00750 MPI_Status mpi_stat;
00751 status = 0;
00752 MPI_Init (&status, NULL);
00753 MPI_Comm_rank (MPI_COMM_WORLD, &mpi_rank);
00754 MPI_Comm_size (MPI_COMM_WORLD, &mpi_size);
00755
00756 istartall = (int *)malloc(sizeof(int) * mpi_size);
00757 iendall = (int *)malloc(sizeof(int) * mpi_size);
00758
00759 MPI_Barrier(MPI_COMM_WORLD);
00760 if (mpi_rank == 0){printf ("%s Ver. %s\n", module_name, version_id);}
00761
00762 #if CHCKSKIP == 1
00763
00764 {
00765 int idoit;
00766 idoit = 0;
00767 if (enfdoit)
00768 {
00769 if (mpi_rank == 0){printf ("Enforcing running VFISV even when the output destination record exits.\n");}
00770 idoit = 1;
00771 }
00772 else
00773 {
00774 if (mpi_rank == 0)
00775 {
00776
00777 inRS = drms_open_records (drms_env, indsdesc, &status);
00778 if (status) {DIE("drms_open_records failed.\n");}
00779 if ((rec_ct = inRS->n) == 0){DIE("No records in selected dataset.\n");}
00780 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
00781 inRec = inRS->records[0];
00782
00783 TIME t_recl = drms_getkey_time(inRec,"T_REC",&status);
00784 drms_close_records(inRS, DRMS_FREE_RECORD);
00785
00786 DRMS_RecordSet_t *inRS2;
00787 DRMS_Record_t *inRec2;
00788 char timestr2[26];
00789 sprint_time(timestr2,t_recl,"TAI",0);
00790 char stroutdat[80];
00791 sprintf(stroutdat,"%s[%s]",outserc,timestr2);
00792 printf(" destination record : %s ",stroutdat);
00793 char *inQuery2 = stroutdat;
00794 inRS2 = drms_open_records(drms_env, inQuery2, &status);
00795 if (status || inRS2->n == 0)
00796 {
00797 printf("not exist, so ME will start.\n");
00798 idoit = 1;
00799 }
00800 else
00801 {
00802 printf(" exist.:");
00803 idoit = 0;
00804 inRec2= inRS2->records[0];
00805 int nprc2;
00806 nprc2 = drms_getkey_float(inRec2,"INVNPRCS",&status);
00807 if (nprc2 < 1e7)
00808 {
00809 idoit = 1;
00810 printf(" but it seems to be of HARP, so ME VFISV will start.\n");
00811 }
00812 else
00813 {
00814 idoit = 0;
00815 printf(" the existing one seems to be of full-disk, so ME VFISV will be skipped.\n");
00816 }
00817 }
00818 drms_close_records(inRS2, DRMS_FREE_RECORD);
00819 }
00820 MPI_Barrier(MPI_COMM_WORLD);
00821 int *ibuff;
00822 ibuff=(int *)malloc(sizeof(int)*1);
00823 ibuff[0]=idoit;
00824 MPI_Bcast(ibuff,1,MPI_INT,0,MPI_COMM_WORLD);
00825 idoit = ibuff[0];
00826 free(ibuff);
00827 }
00828 if (idoit != 1)
00829 {
00830 if (mpi_rank == 0){printf("ME VFISV run will be skipped. Good bye !\n");}
00831 MPI_Barrier(MPI_COMM_WORLD);
00832 MPI_Finalize();
00833 return 0;
00834 }
00835 }
00836 #endif
00837
00838
00839
00840 if (mpi_rank == 0)
00841 {
00842
00843 if (verbose) printf ("%d CPU/core(s) be used for parallel-inversion. \n", mpi_size);
00844
00845
00846 #if MASKPTCH == 1
00847 {
00848 char segname[100];
00849 char *inData;
00850 DRMS_Array_t *inArray;
00851 DRMS_Segment_t *inSeg;
00852 DRMS_Record_t *inRec;
00853 DRMS_RecordSet_t *inRS;
00854 int nnx, nny;
00855
00856 if (verbose) printf(" now loading mask-data : %s\n",indsdesc3);
00857 inRS = drms_open_records (drms_env, indsdesc3, &status);
00858
00859 if ((status) || ((rec_ct = inRS->n) == 0))
00860 {
00861 iexistpatchmask = 0;
00862 printf(" skip, no data series : %s\n",indsdesc3);
00863 }
00864 else
00865 {
00866 iexistpatchmask = 1;
00867 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
00868 rn = 0;
00869 inRec = inRS->records[rn];
00870 char *Resname[] = {"mask"};
00871 sprintf(segname,"%s",Resname[0]);
00872 inSeg = drms_segment_lookup(inRec,segname);
00873 cols = inSeg->axis[0];
00874 rows = inSeg->axis[1];
00875 imgpix = cols * rows;
00876 patchmask = (int *)malloc (sizeof (int) * imgpix * 1);
00877 int iseg;
00878 for (iseg = 0; iseg < 1; iseg++)
00879 {
00880 sprintf(segname,"%s",Resname[iseg]);
00881 if (verbose) printf(" now loading segment : %-20s",segname);
00882 inSeg = drms_segment_lookup(inRec,segname);
00883 inArray= drms_segment_read(inSeg, DRMS_TYPE_CHAR, &status);
00884 if (status) DIE("Cant read segment!\n");
00885 inData =(char *)inArray->data;
00886 nnx = inArray->axis[0];
00887 nny = inArray->axis[1];
00888 if (verbose) {printf(" Nx Ny are = %d %d\n", nnx, nny);}
00889 for (n = 0; n < nnx * nny; n++){patchmask[n+iseg*imgpix]=inData[n];}
00890 drms_free_array(inArray);
00891 }
00892 drms_close_records (inRS, DRMS_FREE_RECORD);
00893 }
00894 }
00895 #endif
00896
00897
00898
00899
00900
00901 #if HARPATCH == 1 && MULTHARP != 1
00902 {
00903 char segname[100];
00904 char *inData;
00905 DRMS_Array_t *inArray;
00906 DRMS_Segment_t *inSeg;
00907 DRMS_Record_t *inRec;
00908 DRMS_RecordSet_t *inRS;
00909 int nnx, nny;
00910 int colsL, rowsL, imgpixL;
00911
00912 if (verbose) printf(" now loading HARP-data : %s\n",indsdesc3);
00913 inRS = drms_open_records (drms_env, indsdesc3, &status);
00914
00915 if ((status) || ((rec_ct = inRS->n) == 0))
00916 {
00917 iexistpatchmask = 0;
00918 printf(" skip, no data series : %s\n",indsdesc3);
00919 }
00920 else
00921 {
00922 iexistpatchmask = 1;
00923 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
00924 rn = 0;
00925 inRec = inRS->records[rn];
00926
00927 iquality = drms_getkey_int(inRec,"QUALITY",&status);
00928 if (iquality < 0){DIE("No HARP file exist on disk, process terminated.\n");}
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943 char *Resname[] = {"bitmap"};
00944 sprintf(segname,"%s",Resname[0]);
00945 inSeg = drms_segment_lookup(inRec,segname);
00946 colsL = inSeg->axis[0];
00947 rowsL = inSeg->axis[1];
00948 imgpixL = colsL * rowsL;
00949 patchmask = (int *)malloc (sizeof (int) * imgpixL * 1);
00950 int iseg;
00951 for (iseg = 0; iseg < 1; iseg++)
00952 {
00953 sprintf(segname,"%s",Resname[iseg]);
00954 if (verbose) printf(" now loading segment : %-20s",segname);
00955 inSeg = drms_segment_lookup(inRec,segname);
00956 inArray= drms_segment_read(inSeg, DRMS_TYPE_CHAR, &status);
00957 if (status) DIE("Cant read segment!\n");
00958 inData =(char *)inArray->data;
00959 nnx = inArray->axis[0];
00960 nny = inArray->axis[1];
00961 if (verbose) {printf(" Nx Ny are = %d %d\n", nnx, nny);}
00962 for (n = 0; n < nnx * nny; n++){patchmask[n+iseg*imgpixL]=inData[n];}
00963 drms_free_array(inArray);
00964 }
00965 xleftbot = drms_getkey_int(inRec,"CRPIX1",&status);
00966 yleftbot = drms_getkey_int(inRec,"CRPIX2",&status);
00967 xwidth = colsL;
00968 yheight = rowsL;
00969 if (verbose) {printf(" HARP info. xleftbot yleftbot xwidth yheight = %d %d %d %d\n",xleftbot,yleftbot,xwidth,yheight);}
00970 xleftbot = xleftbot - 1;
00971 yleftbot = yleftbot - 1;
00972 if (verbose) {printf(" HARP xleftbot yleftbot were shifted = %d %d\n",xleftbot,yleftbot);}
00973 drms_close_records (inRS, DRMS_FREE_RECORD);
00974 }
00975 }
00976 #endif
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991 #if TAKEPREV == 1
00992 {
00993 char segname[100];
00994 float *inData;
00995 DRMS_Array_t *inArray;
00996 DRMS_Segment_t *inSeg;
00997 DRMS_Record_t *inRec;
00998 DRMS_RecordSet_t *inRS;
00999 int nnx, nny;
01000
01001 if (verbose) printf(" now loading previous results series : %s\n",indsdesc2);
01002 inRS = drms_open_records (drms_env, indsdesc2, &status);
01003
01004
01005
01006 if ((status) || ((rec_ct = inRS->n) == 0))
01007 {
01008 iexistprev=0;
01009 if (verbose) printf(" skip, no data series : %s\n",indsdesc2);
01010 }
01011 else
01012 {
01013 iexistprev=1;
01014 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
01015 rn = 0;
01016 inRec = inRS->records[rn];
01017 inSeg = drms_segment_lookupnum (inRec, 0);
01018 cols = inSeg->axis[0];
01019 rows = inSeg->axis[1];
01020 imgpix = cols * rows;
01021 prevdata = (float *)malloc (sizeof (float) * imgpix * (paramct+Err_ct));
01022 int iseg;
01023 for (iseg = 0; iseg < (paramct+Err_ct); iseg++)
01024 {
01025 sprintf(segname,"%s",Resname[iseg]);
01026 if (verbose) printf(" now loading segment of previous results : %-20s",segname);
01027 inSeg = drms_segment_lookup(inRec,segname);
01028 inArray= drms_segment_read(inSeg, DRMS_TYPE_FLOAT, &status);
01029 if (status) DIE("Cant read segment!\n");
01030 inData =(float *)inArray->data;
01031 nnx = inArray->axis[0];
01032 nny = inArray->axis[1];
01033 if (verbose) {printf(" Nx Ny are = %d %d\n", nnx, nny);}
01034 for (n = 0; n < nnx * nny; n++){prevdata[n+iseg*imgpix]=inData[n];}
01035 drms_free_array(inArray);
01036 }
01037 drms_close_records (inRS, DRMS_FREE_RECORD);
01038 }
01039 }
01040 #endif
01041
01042
01043 inRS = drms_open_records (drms_env, indsdesc, &status);
01044 if (status) {DIE("drms_open_records failed.\n");}
01045 if ((rec_ct = inRS->n) == 0){DIE("No records in selected dataset.\n");}
01046 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
01047
01048 rn = 0;
01049
01050 inRec = inRS->records[rn];
01051
01052
01053 iquality = drms_getkey_int(inRec,"QUALITY",&status);
01054 if (iquality < 0){DIE("No Stokes file exist on disk, process terminated.\n");}
01055
01056 inSeg = drms_segment_lookupnum (inRec, 0);
01057 cols = inSeg->axis[0];
01058 rows = inSeg->axis[1];
01059 imgpix = cols * rows;
01060 imgbytes = imgpix * sizeof (float);
01061 nvar = wlct * spct;
01062
01063 #if TAKEPREV == 1
01064 if (iexistprev==0){prevdata = (float *)malloc (sizeof (float) * imgpix * (paramct+Err_ct));}
01065 #endif
01066
01067 data = data0 = (float *)malloc (sizeof (float) * imgpix * nvar);
01068 nan_map=(int *)calloc(imgpix, sizeof (int));
01069
01070
01071
01072 for (sp = 0; sp < spct; sp++)
01073 {
01074 for (wl = 0; wl < wlct; wl++)
01075 {
01076
01077
01078
01079
01080
01081
01082 if (NUM_LAMBDA_FILTER == 6)
01083 {
01084 sprintf (segname, "%s%d", spname[sp], wl);
01085 }
01086 if (NUM_LAMBDA_FILTER == 8)
01087 {
01088 int idummy;
01089 if (wl == 0){idummy = 7;}else{idummy = wl - 1;}
01090 sprintf (segname, "%s%d",spname[sp],idummy);
01091 }
01092 if (NUM_LAMBDA_FILTER == 10)
01093 {
01094 int idummy;
01095 idummy = wl - 2;
01096 if (wl == 0){idummy = 9;}
01097 if (wl == 1){idummy = 7;}
01098 if (wl == 9){idummy = 8;}
01099 sprintf (segname, "%s%d",spname[sp],idummy);
01100 }
01101 if (verbose){printf("now loading Stokes : %s\n",segname);}
01102
01103 if ((inSeg = drms_segment_lookup (inRec, segname)) == NULL){
01104 fprintf (stderr, "Error reading segment %s of record %d\n", segname, rn);
01105 return 1;
01106 }
01107
01108 stokes_array = drms_segment_read (inSeg, DRMS_TYPE_FLOAT, &status);
01109 if (status) {DIE("Cant read Stokes data !\n");}
01110 memcpy (data, stokes_array->data, imgbytes);
01111 drms_free_array (stokes_array);
01112 data += imgpix;
01113 } }
01114 data = data0;
01115 printf("Imgpix= %d\n",imgpix);
01116
01117
01118 iquality = drms_getkey_int(inRec,"QUALITY",&status);
01119 #if SKIPBADQ == 1
01120 {
01121 char trectmp2[26];
01122 TIME trectmp1 = drms_getkey_time(inRec,"T_REC",&status);
01123 sprint_time(trectmp2,trectmp1,"TAI",0);
01124 printf("QUALITY index at [%s] is %08x\n",trectmp2,iquality);
01125 if (iquality !=0){DIE(" QUALITY index is not zero, so process terminated !");}
01126 }
01127 #endif
01128 #if SKIPBADQ == 2
01129 {
01130 char trectmp2[26];
01131 TIME trectmp1 = drms_getkey_time(inRec,"T_REC",&status);
01132 sprint_time(trectmp2,trectmp1,"TAI",0);
01133 printf("QUALITY index at [%s] is %08x\n",trectmp2,iquality);
01134 if ((iquality !=0) && (iquality !=0x00000400)){DIE(" QUALITY index does not satisfy criteria, so process terminated !");}
01135 }
01136 #endif
01137
01138 obs_vr = drms_getkey_float(inRec,"OBS_VR",&status);
01139 obs_vr = obs_vr * 100.0;
01140 crota2 = drms_getkey_float(inRec,"CROTA2",&status);
01141 crpixx = drms_getkey_float(inRec,"CRPIX1",&status);
01142 crpixy = drms_getkey_float(inRec,"CRPIX2",&status);
01143 cdeltx = drms_getkey_float(inRec,"CDELT1",&status);
01144 cdelty = drms_getkey_float(inRec,"CDELT2",&status);
01145 rsun_ref = drms_getkey_float(inRec,"RSUN_REF",&status);
01146 dsun_obs = drms_getkey_float(inRec,"DSUN_OBS",&status);
01147 sunarc = asin(rsun_ref/dsun_obs)
01148 / 3.14159265358979e0 * 180.0 * 3600.0;
01149 printf("solar radius is %f in arcsec \n",sunarc);
01150 sunradfpix = sunarc / (cdeltx + cdelty) * 2.0;
01151 printf("solar radius is %f in CCD pix.\n",sunradfpix);
01152 if ((isnan(sunarc)) ||((isnan(crpixx)) || isnan(crpixy)))
01153 {
01154 sunarc = (float)(cols+rows) * 0.5;
01155 crpixx = (float)cols * 0.5 + 0.5;
01156 crpixy = (float)rows * 0.5 + 0.5;
01157 }
01158
01159
01160
01161
01162 #if HARPATCH == 1 && MULTHARP == 1
01163 patchmask = (int *)malloc (sizeof (int) * imgpix);
01164 {
01165 int i;
01166 for (i = 0; i < imgpix; i++){patchmask[i]=0;}
01167 char segname[100];
01168 char *inData;
01169 DRMS_Array_t *inArray;
01170 DRMS_Segment_t *inSeg;
01171 DRMS_Record_t *inRec;
01172 DRMS_RecordSet_t *inRS;
01173 int nnx, nny;
01174 int colsL, rowsL, imgpixL;
01175 #if HANDHARP != 1
01176
01177 if (verbose) printf(" now loading HARP-data : %s\n",indsdesc3);
01178 inRS = drms_open_records (drms_env, indsdesc3, &status);
01179
01180 if ((status) || ((rec_ct = inRS->n) == 0))
01181 {
01182 iexistpatchmask = 0;
01183
01184 DIE("terminated due to no HARP data.\n");
01185 }
01186 else
01187 {
01188 rec_ct = inRS->n;
01189 nharp = rec_ct;
01190 printf(" There are %d HARP for %s\n",rec_ct, indsdesc3);
01191 iexistpatchmask = 1;
01192 for (rn = 0; rn < rec_ct; rn++)
01193 {
01194 inRec = inRS->records[rn];
01195
01196
01197 iquality = drms_getkey_int(inRec,"QUALITY",&status);
01198 if (iquality < 0){DIE("No HARP file exist on disk, process terminated.\n");}
01199
01200 char *Resname[] = {"bitmap"};
01201 sprintf(segname,"%s",Resname[0]);
01202 inSeg = drms_segment_lookup(inRec,segname);
01203 colsL = inSeg->axis[0];
01204 rowsL = inSeg->axis[1];
01205 imgpixL = colsL * rowsL;
01206 int *patchmaskL;
01207 patchmaskL = (int *)malloc (sizeof (int) * imgpixL * 1);
01208 int iseg;
01209 for (iseg = 0; iseg < 1; iseg++)
01210 {
01211 sprintf(segname,"%s",Resname[iseg]);
01212 if (verbose) printf(" now loading segment : %-20s",segname);
01213 inSeg = drms_segment_lookup(inRec,segname);
01214 inArray= drms_segment_read(inSeg, DRMS_TYPE_CHAR, &status);
01215
01216 if (status)
01217 {
01218 printf("no valid HARP data, maybe expired ... skip %d th HARP\n", iseg);
01219 }
01220 else
01221 {
01222 inData =(char *)inArray->data;
01223 nnx = inArray->axis[0];
01224 nny = inArray->axis[1];
01225 if (verbose) {printf(" Nx Ny are = %d %d\n", nnx, nny);}
01226 for (n = 0; n < nnx * nny; n++){patchmaskL[n+iseg*imgpixL]=inData[n];}
01227 }
01228 drms_free_array(inArray);
01229 }
01230 int xleftbotL, yleftbotL;
01231 xleftbotL = drms_getkey_int(inRec,"CRPIX1",&status);
01232 yleftbotL = drms_getkey_int(inRec,"CRPIX2",&status);
01233 xwidth = colsL;
01234 yheight = rowsL;
01235 if (verbose) {printf(" HARP info. xleftbot yleftbot xwidth yheight = %d %d %d %d\n",xleftbotL,yleftbotL,xwidth,yheight);}
01236
01237 #if 0
01238
01239 int numharp = drms_getkey_time(inRec,"HARPNUM",&status);
01240 if ((numharp == 2081) || (numharp == 4087))
01241 {
01242 #if 1
01243
01244 int icenter, jcenter;
01245 icenter = xleftbotL + colsL / 2;
01246 jcenter = yleftbotL + rowsL / 2;
01247 if (colsL < 700){xleftbotL = icenter - 350; colsL = 700;}
01248 if (rowsL < 700){yleftbotL = jcenter - 350; rowsL = 700;}
01249 #endif
01250 int i2, j2, n2, m2;
01251 for (i2 = 0; i2 < colsL; i2++)
01252 {
01253 for (j2 = 0; j2 < rowsL; j2++)
01254 {
01255 int iL, jL;
01256 jL = j2 + yleftbotL - 1;
01257 iL = i2 + xleftbotL - 1;
01258 if (iL < 0){iL = 0;}
01259 if (iL > cols - 1){iL = cols-1;}
01260 if (jL < 0){jL = 0;}
01261 if (jL > rows - 1){jL = rows-1;}
01262 m2 = jL * cols + iL;
01263 patchmask[m2] = 600;
01264 } }
01265 }
01266 else
01267 {
01268 printf(" Out of interest this time, thus skipped : RecNum and HARPnum = %d %d\n",rn,numharp);
01269 }
01270 #else
01271
01272 #if 1
01273
01274 int iextendx = 50;
01275 int iextendy = 50;
01276 xleftbotL = xleftbotL - iextendx;
01277 yleftbotL = yleftbotL - iextendy;
01278 colsL = colsL + iextendx * 2;
01279 rowsL = rowsL + iextendy * 2;
01280 #endif
01281 #if 0
01282
01283 {
01284 int icenter, jcenter;
01285 icenter = xleftbotL + colsL / 2;
01286 jcenter = yleftbotL + rowsL / 2;
01287 if (colsL < 700){xleftbotL = icenter - 350; colsL = 700;}
01288 if (rowsL < 700){yleftbotL = jcenter - 350; rowsL = 700;}
01289 }
01290 #endif
01291 int i2, j2, m2;
01292 for (i2 = 0; i2 < colsL; i2++)
01293 {
01294 for (j2 = 0; j2 < rowsL; j2++)
01295 {
01296 int iL, jL;
01297 jL = j2 + yleftbotL - 1;
01298 iL = i2 + xleftbotL - 1;
01299 if (iL < 0){iL = 0;}
01300 if (iL > cols - 1){iL = cols-1;}
01301 if (jL < 0){jL = 0;}
01302 if (jL > rows - 1){jL = rows-1;}
01303 m2 = jL * cols + iL;
01304 patchmask[m2] = 600;
01305 } }
01306 #endif // endif whether the standard use of HAPR or something else.
01307
01308 free(patchmaskL);
01309 }
01310 drms_close_records (inRS, DRMS_FREE_RECORD);
01311 }
01312 #else
01313
01314 iexistpatchmask = 1;
01315 int xleftbotL, yleftbotL;
01316 xleftbotL = 1450;
01317 yleftbotL = 1250;
01318 colsL = 600;
01319 rowsL = 400;
01320 xwidth = colsL;
01321 yheight = rowsL;
01322 if (verbose) {printf(" pseudo-HARP info. xleftbot yleftbot xwidth yheight = %d %d %d %d\n",xleftbotL,yleftbotL,xwidth,yheight);}
01323 int i2, j2, m2;
01324 for (i2 = 0; i2 < colsL; i2++)
01325 {
01326 for (j2 = 0; j2 < rowsL; j2++)
01327 {
01328 int iL, jL;
01329 jL = j2 + yleftbotL - 1;
01330 iL = i2 + xleftbotL - 1;
01331 if (iL < 0){iL = 0;}
01332 if (iL > cols - 1){iL = cols-1;}
01333 if (jL < 0){jL = 0;}
01334 if (jL > rows - 1){jL = rows-1;}
01335 m2 = jL * cols + iL;
01336 patchmask[m2] = 600;
01337 } }
01338 #endif
01339
01340
01341 xwidth = cols;
01342 yheight = rows;
01343 xleftbot = 0;
01344 yleftbot = 0;
01345 }
01346 #endif
01347
01348 #if MASKPTCH == 1 || HARPATCH == 1
01349 if (iexistpatchmask==0){patchmask = (int *)malloc (sizeof (int) * imgpix);}
01350 #endif
01351
01352
01353 #if VLOSINIT == 1
01354 float defvlosinit;
01355 defvlosinit = guess[6];
01356 {
01357 char segname[100];
01358 float *inData;
01359 DRMS_Array_t *inArray;
01360 DRMS_Segment_t *inSeg;
01361 DRMS_Record_t *inRec;
01362 DRMS_RecordSet_t *inRS;
01363 int nnx, nny;
01364 if (verbose) printf(" now loading Doppler : %s\n",indsdesc4);
01365 inRS = drms_open_records (drms_env, indsdesc4, &status);
01366
01367 if ((status) || ((rec_ct = inRS->n) == 0))
01368 {
01369 iexistdoppler = 0;
01370 printf(" no data series : %s\n",indsdesc4);
01371 }
01372 else
01373 {
01374 iexistdoppler = 1;
01375 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
01376 rn = 0;
01377 inRec = inRS->records[rn];
01378
01379
01380 iquality = drms_getkey_int(inRec,"QUALITY",&status);
01381 if (iquality < 0){DIE("No Doppler file exist on disk, process terminated.\n");}
01382
01383 char *Resname[] = {"Dopplergram"};
01384 sprintf(segname,"%s",Resname[0]);
01385 inSeg = drms_segment_lookup(inRec,segname);
01386 cols = inSeg->axis[0];
01387 rows = inSeg->axis[1];
01388 imgpix = cols * rows;
01389 vlos_init = (float *)malloc (sizeof(float) * imgpix);
01390 int iseg;
01391 for (iseg = 0; iseg < 1; iseg++)
01392 {
01393 sprintf(segname,"%s",Resname[iseg]);
01394 if (verbose) printf(" now loading segment : %-20s",segname);
01395 inSeg = drms_segment_lookup(inRec,segname);
01396 inArray= drms_segment_read(inSeg, DRMS_TYPE_FLOAT, &status);
01397 if (status) DIE("Cant read Dopplergram data !\n");
01398 inData =(float *)inArray->data;
01399 nnx = inArray->axis[0];
01400 nny = inArray->axis[1];
01401 if (verbose) {printf(" Nx Ny are = %d %d\n", nnx, nny);}
01402 for (n = 0; n < nnx * nny; n++){vlos_init[n]=inData[n]*100.0;}
01403 drms_free_array(inArray);
01404 }
01405 drms_close_records (inRS, DRMS_FREE_RECORD);
01406 }
01407 }
01408
01409
01410
01411 if (iexistdoppler == 1)
01412 {
01413 for (n = 0; n < imgpix; n++)
01414 {
01415 float fpixdist, fxpix, fypix;
01416 int ix, iy;
01417 ix = n % cols;
01418 iy = n / cols;
01419 fxpix = ((float)(ix) -(crpixx - 1.0)) * cdeltx;
01420 fypix = ((float)(iy) -(crpixy - 1.0)) * cdelty;
01421 fpixdist = fxpix * fxpix + fypix * fypix + 1e-20;
01422 fpixdist = sqrt(fpixdist);
01423 if (fpixdist > sunarc * 0.99)
01424 {
01425 vlos_init[n] = defvlosinit;
01426 }
01427 }
01428 }
01429
01430 if (iexistdoppler == 0)
01431 {
01432 vlos_init = (float *)malloc (sizeof (float) * imgpix * 1);
01433 float cospangle, pangrad;
01434 pangrad = crota2 / 180.0 * 3.14159265358979;
01435 cospangle = cos(pangrad);
01436 for (n = 0; n < imgpix; n++)
01437 {
01438 float fpixdist, fxpix, fypix;
01439 int ix, iy;
01440 ix = n % cols;
01441 iy = n / cols;
01442 fxpix = ((float)(ix) -(crpixx - 1.0)) * cdeltx;
01443 fypix = ((float)(iy) -(crpixy - 1.0)) * cdelty;
01444 fpixdist = fxpix * fxpix + fypix * fypix + 1e-20;
01445 fpixdist = sqrt(fpixdist);
01446 if (fpixdist < sunarc * 0.99)
01447 {
01448 float sinphi, sintheta, costheta;
01449 sintheta = fypix/sunarc;
01450 costheta = 1.0 - sintheta*sintheta;
01451 if (costheta > 0.0){costheta = sqrt(costheta);}else{costheta = 0.0;}
01452 float omega, vlosoldiff;
01453 omega = 14.713 - 2.396 * sintheta * sintheta - 1.787 * sintheta * sintheta * sintheta * sintheta;
01454 omega = omega / (24.0 * 3600.0) * 3.14159265358979 / 180.0 ;
01455 vlosoldiff = rsun_ref * 100.0 * omega;
01456 float fwork;
01457 sinphi = fxpix/ (costheta * sunarc);
01458 fwork = sinphi * cospangle;
01459 vlosoldiff = vlosoldiff * fwork;
01460 vlos_init[n] = -obs_vr + vlosoldiff;
01461 }
01462 else
01463 {
01464 vlos_init[n] = defvlosinit;
01465 }
01466 }
01467 }
01468 #endif // endif VLOSINIT is 1
01469
01470
01471 #if MGSTINIT == 1 || CONFINDX == 1
01472 float defmgstinit;
01473 defmgstinit = guess[5];
01474 {
01475 char segname[100];
01476 float *inData;
01477 DRMS_Array_t *inArray;
01478 DRMS_Segment_t *inSeg;
01479 DRMS_Record_t *inRec;
01480 DRMS_RecordSet_t *inRS;
01481 int nnx, nny;
01482 if (verbose) printf(" now loading magnetogram : %s\n",indsdesc5);
01483 inRS = drms_open_records (drms_env, indsdesc5, &status);
01484
01485 if ((status) || ((rec_ct = inRS->n) == 0))
01486 {
01487 iexistmagnetogram = 0;
01488 printf(" no data series : %s\n",indsdesc5);
01489 }
01490 else
01491 {
01492 iexistmagnetogram = 1;
01493 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
01494 rn = 0;
01495 inRec = inRS->records[rn];
01496
01497
01498 iquality = drms_getkey_int(inRec,"QUALITY",&status);
01499 if (iquality < 0){DIE("No Magnetogram file exist on disk, process terminated.\n");}
01500
01501 char *Resname[] = {"magnetogram"};
01502 sprintf(segname,"%s",Resname[0]);
01503 inSeg = drms_segment_lookup(inRec,segname);
01504 cols = inSeg->axis[0];
01505 rows = inSeg->axis[1];
01506 imgpix = cols * rows;
01507 mgst_init = (float *)malloc (sizeof(float) * imgpix);
01508 blosgram = (float *)malloc (sizeof(float) * imgpix);
01509 int iseg;
01510 for (iseg = 0; iseg < 1; iseg++)
01511 {
01512 sprintf(segname,"%s",Resname[iseg]);
01513 if (verbose) printf(" now loading segment : %-20s",segname);
01514 inSeg = drms_segment_lookup(inRec,segname);
01515 inArray= drms_segment_read(inSeg, DRMS_TYPE_FLOAT, &status);
01516 if (status) DIE("Cant read Magnetogram data !\n");
01517 inData =(float *)inArray->data;
01518 nnx = inArray->axis[0];
01519 nny = inArray->axis[1];
01520 if (verbose) {printf(" Nx Ny are = %d %d\n", nnx, nny);}
01521 for (n = 0; n < nnx * nny; n++){blosgram[n]=inData[n];}
01522 drms_free_array(inArray);
01523 }
01524 drms_close_records (inRS, DRMS_FREE_RECORD);
01525 }
01526 }
01527
01528 if (iexistmagnetogram == 1)
01529 {
01530 for (n = 0; n < imgpix; n++)
01531 {
01532 float fpixdist, fxpix, fypix;
01533 int ix, iy;
01534 ix = n % cols;
01535 iy = n / cols;
01536 fxpix = ((float)(ix) -(crpixx - 1.0)) * cdeltx;
01537 fypix = ((float)(iy) -(crpixy - 1.0)) * cdelty;
01538 fpixdist = fxpix * fxpix + fypix * fypix + 1e-20;
01539 fpixdist = sqrt(fpixdist);
01540 if (fpixdist > sunarc * 0.99)
01541 {
01542 mgst_init[n] = defmgstinit;
01543 }
01544 else
01545 {
01546 float cosmu, ftmp;
01547 cosmu = 1.0e0 - fpixdist*fpixdist/(sunarc*sunarc);
01548 ftmp = fabs(blosgram[n]) / (0.8 * sqrt(cosmu) + 0.2);
01549 if (ftmp > 4.0e3){ftmp = 4.0e3;}
01550 if (ftmp < -4.0e3){ftmp = -4.0e3;}
01551 mgst_init[n] = ftmp;
01552 }
01553 }
01554 }
01555
01556 if (iexistmagnetogram == 0)
01557 {
01558 mgst_init = (float *)malloc (sizeof (float) * imgpix * 1);
01559 blosgram = (float *)malloc (sizeof (float) * imgpix * 1);
01560 for (n = 0; n < imgpix; n++){mgst_init[n]=0.0;}
01561 }
01562 #endif // endif MGSTINIT or CONFINDX is 1
01563
01564
01565 for (n = 0; n < imgpix; n++)
01566 {
01567 nan_map[n] = 0;
01568 double sumsqr;
01569 sumsqr = 0.0;
01570 for (m = 0; m < nvar; m++){sumsqr = sumsqr + data[n + m*imgpix] * data[n + m*imgpix];}
01571 if (sumsqr < 1.0e-2){nan_map[n] = 1;}
01572 if (isnan(sumsqr)) {nan_map[n] = 1;}
01573 float fpixdist, fxpix, fypix;
01574 int ix, iy;
01575 ix = n % cols;
01576 iy = n / cols;
01577 fxpix = ((float)(ix) -(crpixx - 1.0)) * cdeltx;
01578 fypix = ((float)(iy) -(crpixy - 1.0)) * cdelty;
01579 fpixdist = fxpix * fxpix + fypix * fypix + 1e-20;
01580 fpixdist = sqrt(fpixdist);
01581 if (fpixdist > sunarc) {nan_map[n] = 2;}
01582 #if RECTANGL == 1
01583 if ((ix < xleftbot) ||
01584 (ix > xleftbot + xwidth - 1) ||
01585 (iy < yleftbot) ||
01586 (iy > yleftbot + yheight - 1)) {nan_map[n] = 3;}
01587 #endif
01588 #if QUICKRUN == 1
01589
01590 if ((ix < 1997) || (ix > 2097))
01591 {nan_map[n] = 3;}
01592 #endif
01593 #if HARPATCH == 1 && MULTHARP != 1
01594 if ((ix < xleftbot) ||
01595 (ix > xleftbot + xwidth - 1) ||
01596 (iy < yleftbot) ||
01597 (iy > yleftbot + yheight - 1))
01598 {
01599 nan_map[n] = 3;
01600 }
01601 #if HARPBLOB == 1
01602 else
01603 {
01604 int i2, j2, n2;
01605 i2 = ix - xleftbot;
01606 j2 = iy - yleftbot;
01607 n2 = xwidth * j2 + i2;
01608 if (patchmask[n2] < 4) {nan_map[n] = 4;}
01609 }
01610 #endif
01611 #endif // end if HARPATCH is 1 and MULTHARP is NOT 1
01612 #if HARPATCH == 1 && MULTHARP == 1
01613 if (patchmask[n] < 4){nan_map[n] = 4;}
01614 #endif
01615 #if MASKPTCH == 1
01616 if (patchmask[n] < 2){nan_map[n] = 4;}
01617 #endif
01618 }
01619 printf("data is read\n");
01620 #if MASKPTCH == 1 || HARPATCH == 1
01621 free(patchmask);
01622 #endif
01623
01624
01625 int nonnan, numnan, nofdsk, nofrct, nmask;
01626 nonnan = 0;
01627 numnan = 0;
01628 nofdsk = 0;
01629 nofrct = 0;
01630 nmask = 0;
01631 for (n = 0; n < imgpix; n++)
01632 {
01633 if (nan_map[n] == 0) nonnan = nonnan + 1;
01634 if (nan_map[n] == 1) numnan = numnan + 1;
01635 if (nan_map[n] == 2) nofdsk = nofdsk + 1;
01636 if (nan_map[n] == 3) nofrct = nofrct + 1;
01637 if (nan_map[n] == 4) nmask = nmask + 1;
01638 }
01639 printf(" Num of pixel total (4k x 4k or 16 x 2^20) : %8d \n", imgpix);
01640 printf(" Num of pixel out-of-disk : %8d \n", nofdsk);
01641 printf(" Num of pixel out-of-rectangle of interest : %8d \n", nofrct);
01642 printf(" Num of pixel skipped due to all-zero or NaN : %8d \n", numnan);
01643 printf(" Num of pixel skipped due to mask map : %8d \n", nmask);
01644 printf(" Num of pixel to be processed : %8d \n", nonnan);
01645
01646
01647 int irank;
01648 int *itmps;
01649 int *itmpe;
01650 itmps = (int *)malloc(sizeof(int) * mpi_size);
01651 itmpe = (int *)malloc(sizeof(int) * mpi_size);
01652 for(irank = 0; irank < mpi_size; irank++)
01653 {
01654 int myrank, nprocs, numpix;
01655 int istart, iend;
01656 myrank = irank;
01657 nprocs = mpi_size;
01658 numpix = nonnan;
01659 para_range(myrank,nprocs,numpix,&istart,&iend);
01660 itmps[irank] = istart;
01661 itmpe[irank] = iend;
01662 }
01663 int icount;
01664 icount = -1;
01665 for (n = 0; n < imgpix; n++)
01666 {
01667 if (nan_map[n] == 0)
01668 {
01669 icount = icount + 1;
01670 for (m = 0; m < mpi_size; m++)
01671 {
01672 if (itmps[m] == icount){istartall[m]=n;}
01673 if (itmpe[m] == icount){iendall[m]=n;}
01674 }
01675 }
01676 }
01677 free(itmps);
01678 free(itmpe);
01679
01680
01681 #if CYCLPRLL == 1
01682 jobnum = -100000;
01683 {
01684 int modjob;
01685 modjob = nonnan % mpi_size;
01686 if (modjob == 0){jobnum = nonnan / mpi_size;}else{jobnum = nonnan / mpi_size + 1;}
01687 jobassignmap = (int *)malloc(sizeof(int) * jobnum * mpi_size);
01688 int icount, n, nlast;
01689 nlast = -1;
01690 icount = -1;
01691 for (n = 0; n < imgpix; n++)
01692 {
01693 if (nan_map[n] == 0)
01694 {
01695 icount = icount + 1;
01696 int npe, ndo, ntemp;
01697 npe = icount % mpi_size;
01698 ndo = icount / mpi_size;
01699 ntemp = ndo + npe * jobnum;
01700 jobassignmap[ntemp] = n;
01701 nlast = n;
01702 }
01703 }
01704 icount = icount + 1;
01705 if (icount != nonnan){printf("%d %d\n",icount,nonnan); DIE("Mistake at new parallel job assignment, at debug point 13 \n");}
01706 if (icount < 0){DIE("Mistake at new parallel job assignment, at debug point 14 !\n");}
01707 printf(" Modulo JobNum = %d %d \n",modjob, jobnum);
01708 if (modjob > 0)
01709 {
01710 int ntemp, n;
01711 for (ntemp = 0; ntemp < (mpi_size - modjob); ntemp++)
01712 {
01713 int npadding;
01714 npadding = (jobnum * mpi_size - 1) - ntemp * jobnum;
01715 jobassignmap[npadding] = nlast;
01716 }
01717 }
01718 }
01719 #endif // end if CYCLPRLL is 1
01720
01721 }
01722 else
01723 {
01724 drms_server_end_transaction(drms_env, 1, 0);
01725 db_disconnect(&drms_env->session->db_handle);
01726 }
01727
01728 MPI_Barrier(MPI_COMM_WORLD);
01729
01730
01731 int *ibuff;
01732 ibuff=(int *)malloc(sizeof(int)*4);
01733 ibuff[0]=imgpix;
01734 ibuff[1]=nvar;
01735 ibuff[2]=cols;
01736 ibuff[3]=rows;
01737 MPI_Bcast(ibuff,4,MPI_INT,0,MPI_COMM_WORLD);
01738 imgpix = ibuff[0];
01739 nvar = ibuff[1];
01740 cols = ibuff[2];
01741 rows = ibuff[3];
01742 free(ibuff);
01743 #if CYCLPRLL == 1
01744 ibuff=(int *)malloc(sizeof(int)*1);
01745 ibuff[0]=jobnum;
01746 MPI_Bcast(ibuff,1,MPI_INT,0,MPI_COMM_WORLD);
01747 jobnum = ibuff[0];
01748 free(ibuff);
01749 #endif
01750
01751 MPI_Bcast(istartall,mpi_size,MPI_INT,0,MPI_COMM_WORLD);
01752 MPI_Bcast(iendall, mpi_size,MPI_INT,0,MPI_COMM_WORLD);
01753
01754 float *fbuff;
01755 fbuff=(float *)malloc(sizeof(float)*6);
01756 fbuff[0] = crpixx;
01757 fbuff[1] = crpixy;
01758 fbuff[2] = cdeltx;
01759 fbuff[3] = cdelty;
01760 fbuff[4] = rsun_ref;
01761 fbuff[5] = dsun_obs;
01762 MPI_Bcast(fbuff,6,MPI_FLOAT,0,MPI_COMM_WORLD);
01763 crpixx = fbuff[0];
01764 crpixy = fbuff[1];
01765 cdeltx = fbuff[2];
01766 cdelty = fbuff[3];
01767 rsun_ref = fbuff[4];
01768 dsun_obs = fbuff[5];
01769 free(fbuff);
01770
01771 MPI_Barrier(MPI_COMM_WORLD);
01772
01773
01774 if (mpi_rank == 0)
01775 {
01776 FinalErr=(double *)malloc(sizeof(double)*imgpix*Err_ct);
01777 FinalRes=(double *)malloc(sizeof(double)*imgpix*paramct);
01778 FinalConvFlag =(int *)malloc(sizeof(int)*imgpix);
01779 FinalConfidMap=(int *)malloc(sizeof(int)*imgpix);
01780 FinalQualMap =(int *)malloc(sizeof(int)*imgpix);
01781 }
01782
01783
01784 float *dataLocal;
01785 float *vlos_initLocal;
01786 float *mgst_initLocal;
01787 double *FinalResLocal,*FinalErrLocal;
01788 int *FinalConvFlagLocal;
01789 int *FinalQualMapLocal;
01790 int *nan_mapLocal;
01791 myrank = mpi_rank;
01792 nprocs = mpi_size;
01793 numpix = imgpix;
01794 #if CYCLPRLL == 1
01795 istart=0;
01796 iend =jobnum-1;
01797 #else
01798 #if EQUIAREA == 1
01799 istart=istartall[myrank];
01800 iend=iendall[myrank];
01801 #else
01802 para_range(myrank,nprocs,numpix,&istart,&iend);
01803 #endif
01804 #endif
01805 #if CYCLPRLL == 1
01806 if (verbose)
01807 {
01808 printf("Hello, this is %2d th PE of %2d, in charge of %9d pixels, of 0 to %9d.\n",
01809 mpi_rank,mpi_size,jobnum,(imgpix-1));
01810 }
01811 #else
01812 if (verbose)
01813 {
01814 printf("Hello, this is %2d th PE of %2d, in charge of pixels from %9d to %9d of 0 to %9d.\n",
01815 mpi_rank,mpi_size,istart,iend,(imgpix-1));
01816 }
01817 #endif
01818 int imgpixlocal;
01819 imgpixlocal = iend - istart + 1;
01820 FinalConvFlagLocal=(int *)malloc(sizeof(int) *imgpixlocal);
01821 FinalQualMapLocal =(int *)malloc(sizeof(int) *imgpixlocal);
01822 nan_mapLocal = (int *)malloc(sizeof(int) *imgpixlocal);
01823 dataLocal = (float *)malloc(sizeof(float) *imgpixlocal*nvar);
01824 vlos_initLocal= (float *)malloc(sizeof(float) *imgpixlocal);
01825 mgst_initLocal= (float *)malloc(sizeof(float) *imgpixlocal);
01826 FinalErrLocal = (double *)malloc(sizeof(double)*imgpixlocal*Err_ct);
01827 FinalResLocal = (double *)malloc(sizeof(double)*imgpixlocal*paramct);
01828
01829
01830 obs = (double *)malloc (sizeof (double) * nvar);
01831 res = (double *)calloc (paramct, sizeof (double));
01832 scat= (double *)malloc (sizeof (double) * nvar);
01833 err = (double *)calloc (Err_ct,sizeof (double));
01834 weights = (double *)malloc (sizeof (double) * 4);
01835
01836 MPI_Barrier(MPI_COMM_WORLD);
01837
01838 #if TAKEPREV == 1
01839 double *PrevErrLocal, *PrevResLocal, *preverr, *prevres;
01840 PrevErrLocal=(double *)malloc(sizeof(double)*imgpixlocal*Err_ct);
01841 PrevResLocal=(double *)malloc(sizeof(double)*imgpixlocal*paramct);
01842 preverr = (double *)calloc (Err_ct,sizeof (double));
01843 prevres = (double *)malloc (sizeof (double) * paramct);
01844
01845 MPI_Barrier(MPI_COMM_WORLD);
01846 ibuff=(int *)malloc(sizeof(int)*1);
01847 ibuff[0] = iexistprev;
01848 MPI_Bcast(ibuff,1,MPI_INT,0,MPI_COMM_WORLD);
01849 iexistprev = ibuff[0];
01850 free(ibuff);
01851 MPI_Barrier(MPI_COMM_WORLD);
01852 #endif
01853
01854 #if CYCLPRLL == 1
01855 int *jobassignmapLocal;
01856 jobassignmapLocal = (int *)malloc(sizeof(int) * jobnum);
01857
01858 if (mpi_rank == 0)
01859 {
01860 myrank = mpi_rank;
01861 nprocs = mpi_size;
01862 numpix = imgpix;
01863 istart=0;
01864 iend =jobnum-1;
01865
01866 for (n = istart ; n < iend+1 ; n++){jobassignmapLocal[n -istart] = jobassignmap[n];}
01867
01868 if (mpi_size > 1)
01869 {
01870 int irank;
01871 for(irank = 1; irank < mpi_size; irank++)
01872 {
01873 int mpi_dest;
01874 int ibufsize;
01875 int *ibufsend;
01876 mpi_dest = irank;
01877 istart=0;
01878 iend =jobnum-1;
01879 ibufsize = (iend-istart+1) * 1;
01880 ibufsend= (int*)malloc(sizeof(int) * ibufsize);
01881 for (n = istart ; n < iend+1 ; n++){ibufsend[n -istart] = jobassignmap[n+mpi_dest*jobnum];}
01882 mpi_tag = 1000 + irank;
01883 MPI_Send(ibufsend, ibufsize, MPI_INTEGER, mpi_dest, mpi_tag, MPI_COMM_WORLD);
01884 free(ibufsend);
01885 }
01886 }
01887 }
01888 else
01889 {
01890
01891 int mpi_from = 0;
01892 int ibufsize;
01893 int *ibufrecv;
01894 istart=0;
01895 iend =jobnum-1;
01896 ibufsize = (iend-istart+1) * 1;
01897 ibufrecv = (int*)malloc(sizeof(int) * ibufsize);
01898
01899 mpi_tag = 1000 + mpi_rank;
01900 MPI_Recv(ibufrecv, ibufsize, MPI_INTEGER, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
01901 for (n = istart ; n < iend+1 ; n++){jobassignmapLocal[n-istart] = ibufrecv[n-istart];}
01902 free(ibufrecv);
01903 }
01904
01905 MPI_Barrier(MPI_COMM_WORLD);
01906 if (mpi_rank == 0) printf(" job assignment address data had propagated to all PE.\n");
01907 #endif // end-if CYCLPRLL is 1
01908
01909
01910 if (mpi_rank == 0)
01911 {
01912 myrank = mpi_rank;
01913 nprocs = mpi_size;
01914 numpix = imgpix;
01915 #if CYCLPRLL == 1
01916 istart=0;
01917 iend =jobnum-1;
01918 #else
01919 #if EQUIAREA == 1
01920 istart=istartall[myrank];
01921 iend=iendall[myrank];
01922 #else
01923 para_range(myrank,nprocs,numpix,&istart,&iend);
01924 #endif
01925 #endif
01926
01927 #if CYCLPRLL == 1
01928 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < nvar; m++){dataLocal[(n-istart)*nvar+m] = data[jobassignmap[n] + m*imgpix];}}
01929 #else
01930 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < nvar; m++){dataLocal[(n-istart)*nvar+m] = data[n + m*imgpix];}}
01931 #endif
01932
01933 if (mpi_size > 1)
01934 {
01935 int irank;
01936 for(irank = 1; irank < mpi_size; irank++)
01937 {
01938 int mpi_dest;
01939 int ibufsize;
01940 float *fbufsend;
01941 mpi_dest = irank;
01942 #if CYCLPRLL == 1
01943 istart=0;
01944 iend =jobnum-1;
01945 #else
01946 #if EQUIAREA == 1
01947 istart=istartall[mpi_dest];
01948 iend=iendall[mpi_dest];
01949 #else
01950 para_range(mpi_dest,nprocs,numpix,&istart,&iend);
01951 #endif
01952 #endif
01953 ibufsize = (iend-istart+1) * nvar;
01954 fbufsend= (float*)malloc(sizeof(float) * ibufsize);
01955 #if CYCLPRLL == 1
01956 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < nvar; m++){fbufsend[(n-istart)*nvar+m] = data[jobassignmap[n+jobnum*mpi_dest] + m*imgpix];}}
01957 #else
01958 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < nvar; m++){fbufsend[(n-istart)*nvar+m] = data[n + m*imgpix];}}
01959 #endif
01960 mpi_tag = 1400 + irank;
01961 MPI_Send(fbufsend, ibufsize, MPI_REAL, mpi_dest, mpi_tag, MPI_COMM_WORLD);
01962 free(fbufsend);
01963 }
01964 }
01965 }
01966 else
01967 {
01968 int mpi_from = 0;
01969 int ibufsize;
01970 float *fbufrecv;
01971 #if CYCLPRLL == 1
01972 istart=0;
01973 iend =jobnum-1;
01974 #else
01975 #if EQUIAREA == 1
01976 istart=istartall[myrank];
01977 iend=iendall[myrank];
01978 #else
01979 para_range(myrank,nprocs,numpix,&istart,&iend);
01980 #endif
01981 #endif
01982 ibufsize = (iend-istart+1) * nvar;
01983 fbufrecv = (float*)malloc(sizeof(float) * ibufsize);
01984 mpi_tag = 1400 + mpi_rank;
01985 MPI_Recv(fbufrecv, ibufsize, MPI_REAL, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
01986 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < nvar; m++){dataLocal[(n-istart)*nvar+m] = fbufrecv[(n-istart)*nvar+m];}}
01987 free(fbufrecv);
01988 }
01989
01990 MPI_Barrier(MPI_COMM_WORLD);
01991 if (mpi_rank == 0) printf("input data had propagated to all PE.\n");
01992
01993
01994 if (mpi_rank == 0)
01995 {
01996 myrank = mpi_rank;
01997 nprocs = mpi_size;
01998 numpix = imgpix;
01999 #if CYCLPRLL == 1
02000 istart=0;
02001 iend =jobnum-1;
02002 #else
02003 #if EQUIAREA == 1
02004 istart=istartall[myrank];
02005 iend=iendall[myrank];
02006 #else
02007 para_range(myrank,nprocs,numpix,&istart,&iend);
02008 #endif
02009 #endif
02010
02011 #if CYCLPRLL == 1
02012 for (n = istart ; n < iend+1 ; n++){nan_mapLocal[n -istart] = nan_map[jobassignmap[n]];}
02013 #else
02014 for (n = istart ; n < iend+1 ; n++){nan_mapLocal[n -istart] = nan_map[n];}
02015 #endif
02016
02017 if (mpi_size > 1)
02018 {
02019 int irank;
02020 for(irank = 1; irank < mpi_size; irank++)
02021 {
02022 int mpi_dest;
02023 int ibufsize;
02024 int *ibufsend;
02025 mpi_dest = irank;
02026 #if CYCLPRLL == 1
02027 istart=0;
02028 iend =jobnum-1;
02029 #else
02030 #if EQUIAREA == 1
02031 istart=istartall[mpi_dest];
02032 iend=iendall[mpi_dest];
02033 #else
02034 para_range(mpi_dest,nprocs,numpix,&istart,&iend);
02035 #endif
02036 #endif
02037 ibufsize = (iend-istart+1) * 1;
02038 ibufsend= (int*)malloc(sizeof(int) * ibufsize);
02039 #if CYCLPRLL == 1
02040 for (n = istart ; n < iend+1 ; n++){ibufsend[n -istart] = nan_map[jobassignmap[n+jobnum*mpi_dest]];}
02041 #else
02042 for (n = istart ; n < iend+1 ; n++){ibufsend[n -istart] = nan_map[n];}
02043 #endif
02044 mpi_tag = 1500 + irank;
02045 MPI_Send(ibufsend, ibufsize, MPI_INTEGER, mpi_dest, mpi_tag, MPI_COMM_WORLD);
02046 free(ibufsend);
02047 }
02048 }
02049 }
02050 else
02051 {
02052
02053 int mpi_from = 0;
02054 int ibufsize;
02055 int *ibufrecv;
02056 #if CYCLPRLL == 1
02057 istart=0;
02058 iend =jobnum-1;
02059 #else
02060 #if EQUIAREA == 1
02061 istart=istartall[myrank];
02062 iend=iendall[myrank];
02063 #else
02064 para_range(myrank,nprocs,numpix,&istart,&iend);
02065 #endif
02066 #endif
02067 ibufsize = (iend-istart+1) * 1;
02068 ibufrecv = (int*)malloc(sizeof(int) * ibufsize);
02069 mpi_tag = 1500 + mpi_rank;
02070 MPI_Recv(ibufrecv, ibufsize, MPI_INTEGER, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
02071 for (n = istart ; n < iend+1 ; n++){nan_mapLocal[n-istart] = ibufrecv[n-istart];}
02072 free(ibufrecv);
02073 }
02074
02075 MPI_Barrier(MPI_COMM_WORLD);
02076 if (mpi_rank == 0) printf("mask data had propagated to all PE.\n");
02077
02078 #if TAKEPREV == 1
02079
02080 if (mpi_rank == 0)
02081 {
02082 myrank = mpi_rank;
02083 nprocs = mpi_size;
02084 numpix = imgpix;
02085 #if CYCLPRLL == 1
02086 istart=0;
02087 iend =jobnum-1;
02088 #else
02089 #if EQUIAREA == 1
02090 istart=istartall[myrank];
02091 iend=iendall[myrank];
02092 #else
02093 para_range(myrank,nprocs,numpix,&istart,&iend);
02094 #endif
02095 #endif
02096
02097 #if CYCLPRLL == 1
02098 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < paramct; m++){PrevResLocal[(n-istart)*paramct+m] = prevdata[jobassignmap[n] + m *imgpix];}}
02099 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < Err_ct; m++){PrevErrLocal[(n-istart)*Err_ct +m] = prevdata[jobassignmap[n] +(m+paramct)*imgpix];}}
02100 #else
02101 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < paramct; m++){PrevResLocal[(n-istart)*paramct+m] = prevdata[n + m *imgpix];}}
02102 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < Err_ct; m++){PrevErrLocal[(n-istart)*Err_ct +m] = prevdata[n +(m+paramct)*imgpix];}}
02103 #endif
02104
02105 if (mpi_size > 1)
02106 {
02107 int irank;
02108 for(irank = 1; irank < mpi_size; irank++)
02109 {
02110 int mpi_dest;
02111 int ibufsize;
02112 float *fbufsend;
02113 mpi_dest = irank;
02114 #if CYCLPRLL == 1
02115 istart=0;
02116 iend =jobnum-1;
02117 #else
02118 #if EQUIAREA == 1
02119 istart=istartall[mpi_dest];
02120 iend=iendall[mpi_dest];
02121 #else
02122 para_range(mpi_dest,nprocs,numpix,&istart,&iend);
02123 #endif
02124 #endif
02125 ibufsize = (iend-istart+1) * (paramct + Err_ct);
02126 fbufsend= (float*)malloc(sizeof(float) * ibufsize);
02127 #if CYCLPRLL == 1
02128 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < (paramct + Err_ct); m++){fbufsend[(n-istart)*(paramct + Err_ct)+m] = prevdata[jobassignmap[n+jobnum*mpi_dest] + m*imgpix];}}
02129 #else
02130 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < (paramct + Err_ct); m++){fbufsend[(n-istart)*(paramct + Err_ct)+m] = prevdata[n + m*imgpix];}}
02131 #endif
02132 mpi_tag = 1600 + irank;
02133 MPI_Send(fbufsend, ibufsize, MPI_REAL, mpi_dest, mpi_tag, MPI_COMM_WORLD);
02134 free(fbufsend);
02135 }
02136 }
02137 }
02138 else
02139 {
02140 int mpi_from = 0;
02141 int ibufsize;
02142 float *fbufrecv;
02143 #if CYCLPRLL == 1
02144 istart=0;
02145 iend =jobnum-1;
02146 #else
02147 #if EQUIAREA == 1
02148 istart=istartall[myrank];
02149 iend=iendall[myrank];
02150 #else
02151 para_range(myrank,nprocs,numpix,&istart,&iend);
02152 #endif
02153 #endif
02154 ibufsize = (iend-istart+1) * (paramct + Err_ct);
02155 fbufrecv = (float*)malloc(sizeof(float) * ibufsize);
02156 mpi_tag = 1600 + mpi_rank;
02157 MPI_Recv(fbufrecv, ibufsize, MPI_REAL, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
02158 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < paramct; m++){PrevResLocal[(n-istart)*paramct+m] = fbufrecv[(n-istart)*(paramct + Err_ct)+m ];}}
02159 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < Err_ct; m++){PrevErrLocal[(n-istart)*Err_ct +m] = fbufrecv[(n-istart)*(paramct + Err_ct)+m+paramct];}}
02160 free(fbufrecv);
02161 }
02162 MPI_Barrier(MPI_COMM_WORLD);
02163 if (mpi_rank == 0) free(prevdata);
02164 if (mpi_rank == 0) printf("previous inv. data had propagated to all PE.\n");
02165 MPI_Barrier(MPI_COMM_WORLD);
02166 #endif
02167
02168 #if VLOSINIT == 1
02169
02170 if (mpi_rank == 0)
02171 {
02172 myrank = mpi_rank;
02173 nprocs = mpi_size;
02174 numpix = imgpix;
02175 #if CYCLPRLL == 1
02176 istart=0;
02177 iend =jobnum-1;
02178 #else
02179 #if EQUIAREA == 1
02180 istart=istartall[myrank];
02181 iend=iendall[myrank];
02182 #else
02183 para_range(myrank,nprocs,numpix,&istart,&iend);
02184 #endif
02185 #endif
02186
02187 #if CYCLPRLL == 1
02188 for (n = istart ; n < iend+1 ; n++){vlos_initLocal[n-istart] = vlos_init[jobassignmap[n]];}
02189 #else
02190 for (n = istart ; n < iend+1 ; n++){vlos_initLocal[n-istart] = vlos_init[n];}
02191 #endif
02192
02193 if (mpi_size > 1)
02194 {
02195 int irank;
02196 for(irank = 1; irank < mpi_size; irank++)
02197 {
02198 int mpi_dest;
02199 int ibufsize;
02200 float *fbufsend;
02201 mpi_dest = irank;
02202 #if CYCLPRLL == 1
02203 istart=0;
02204 iend =jobnum-1;
02205 #else
02206 #if EQUIAREA == 1
02207 istart=istartall[mpi_dest];
02208 iend=iendall[mpi_dest];
02209 #else
02210 para_range(mpi_dest,nprocs,numpix,&istart,&iend);
02211 #endif
02212 #endif
02213 ibufsize = (iend-istart+1) * 1;
02214 fbufsend= (float*)malloc(sizeof(float) * ibufsize);
02215 #if CYCLPRLL == 1
02216 for (n = istart ; n < iend+1 ; n++){fbufsend[n-istart] = vlos_init[jobassignmap[n+jobnum*mpi_dest]];}
02217 #else
02218 for (n = istart ; n < iend+1 ; n++){fbufsend[n-istart] = vlos_init[n];}
02219 #endif
02220 mpi_tag = 1900 + irank;
02221 MPI_Send(fbufsend, ibufsize, MPI_REAL, mpi_dest, mpi_tag, MPI_COMM_WORLD);
02222 free(fbufsend);
02223 }
02224 }
02225 }
02226 else
02227 {
02228 int mpi_from = 0;
02229 int ibufsize;
02230 float *fbufrecv;
02231 #if CYCLPRLL == 1
02232 istart=0;
02233 iend =jobnum-1;
02234 #else
02235 #if EQUIAREA == 1
02236 istart=istartall[myrank];
02237 iend=iendall[myrank];
02238 #else
02239 para_range(myrank,nprocs,numpix,&istart,&iend);
02240 #endif
02241 #endif
02242 ibufsize = (iend-istart+1) * 1;
02243 fbufrecv = (float*)malloc(sizeof(float) * ibufsize);
02244 mpi_tag = 1900 + mpi_rank;
02245 MPI_Recv(fbufrecv, ibufsize, MPI_REAL, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
02246 for (n = istart ; n < iend+1 ; n++){vlos_initLocal[n-istart] = fbufrecv[n-istart];}
02247 free(fbufrecv);
02248 }
02249 MPI_Barrier(MPI_COMM_WORLD);
02250 if (mpi_rank == 0) free(vlos_init);
02251 if (mpi_rank == 0) printf("VLOS_INIT data had propagated to all PE.\n");
02252 MPI_Barrier(MPI_COMM_WORLD);
02253 #endif
02254
02255 #if MGSTINIT == 1
02256
02257 if (mpi_rank == 0)
02258 {
02259 myrank = mpi_rank;
02260 nprocs = mpi_size;
02261 numpix = imgpix;
02262 #if CYCLPRLL == 1
02263 istart=0;
02264 iend =jobnum-1;
02265 #else
02266 #if EQUIAREA == 1
02267 istart=istartall[myrank];
02268 iend=iendall[myrank];
02269 #else
02270 para_range(myrank,nprocs,numpix,&istart,&iend);
02271 #endif
02272 #endif
02273
02274 #if CYCLPRLL == 1
02275 for (n = istart ; n < iend+1 ; n++){mgst_initLocal[n-istart] = mgst_init[jobassignmap[n]];}
02276 #else
02277 for (n = istart ; n < iend+1 ; n++){mgst_initLocal[n-istart] = mgst_init[n];}
02278 #endif
02279
02280 if (mpi_size > 1)
02281 {
02282 int irank;
02283 for(irank = 1; irank < mpi_size; irank++)
02284 {
02285 int mpi_dest;
02286 int ibufsize;
02287 float *fbufsend;
02288 mpi_dest = irank;
02289 #if CYCLPRLL == 1
02290 istart=0;
02291 iend =jobnum-1;
02292 #else
02293 #if EQUIAREA == 1
02294 istart=istartall[mpi_dest];
02295 iend=iendall[mpi_dest];
02296 #else
02297 para_range(mpi_dest,nprocs,numpix,&istart,&iend);
02298 #endif
02299 #endif
02300 ibufsize = (iend-istart+1) * 1;
02301 fbufsend= (float*)malloc(sizeof(float) * ibufsize);
02302 #if CYCLPRLL == 1
02303 for (n = istart ; n < iend+1 ; n++){fbufsend[n-istart] = mgst_init[jobassignmap[n+jobnum*mpi_dest]];}
02304 #else
02305 for (n = istart ; n < iend+1 ; n++){fbufsend[n-istart] = mgst_init[n];}
02306 #endif
02307 mpi_tag = 2000 + irank;
02308 MPI_Send(fbufsend, ibufsize, MPI_REAL, mpi_dest, mpi_tag, MPI_COMM_WORLD);
02309 free(fbufsend);
02310 }
02311 }
02312 }
02313 else
02314 {
02315 int mpi_from = 0;
02316 int ibufsize;
02317 float *fbufrecv;
02318 #if CYCLPRLL == 1
02319 istart=0;
02320 iend =jobnum-1;
02321 #else
02322 #if EQUIAREA == 1
02323 istart=istartall[myrank];
02324 iend=iendall[myrank];
02325 #else
02326 para_range(myrank,nprocs,numpix,&istart,&iend);
02327 #endif
02328 #endif
02329 ibufsize = (iend-istart+1) * 1;
02330 fbufrecv = (float*)malloc(sizeof(float) * ibufsize);
02331 mpi_tag = 2000 + mpi_rank;
02332 MPI_Recv(fbufrecv, ibufsize, MPI_REAL, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
02333 for (n = istart ; n < iend+1 ; n++){mgst_initLocal[n-istart] = fbufrecv[n-istart];}
02334 free(fbufrecv);
02335 }
02336 MPI_Barrier(MPI_COMM_WORLD);
02337 if (mpi_rank == 0) free(mgst_init);
02338 if (mpi_rank == 0) printf("MGST_INIT data had propagated to all PE.\n");
02339 MPI_Barrier(MPI_COMM_WORLD);
02340 #endif
02341
02342
02343 if (mpi_rank == 0) printf("\n----------- inversion initializations ----------------- \n");
02344
02345 vfisvalloc_(&NUM_LAMBDA_FILTER,&NUM_LAMBDA,&NUM_LAMBDA_synth);
02346
02347
02348 #if NLEVPIXL != 1
02349 line_init_(&LAMBDA_0,&LAMBDA_B,&NOISE_LEVEL);
02350 if (verbose){printf("done line_init for mpi_rank %d\n",mpi_rank);}
02351 wave_init_ (&LAMBDA_MIN_synth,&DELTA_LAMBDA,&NUM_LAMBDA_synth);
02352 if (verbose){printf("done wave_init for mpi_rank %d\n",mpi_rank );}
02353 filt_init_ (&NUM_LAMBDA_FILTER,&WSPACING, &NUM_LAMBDA);
02354 if (verbose){printf("done filt_init for mpi_rank %d\n",mpi_rank);}
02355 #endif
02356
02357
02358
02359
02360
02361
02362 int location,column,row,ratio,x0,y0,x1,y1,loc1,loc2,loc3,loc4;
02363 double xa,xb,ya,yb,X0,Y0,Rsun;
02364 int nx2=128,ny2=128;
02365 int nelemPHASENT =4*nx2*ny2;
02366 int nelemCONTRASTT=3*nx2*ny2;
02367 int FSNREC;
02368 referencenlam=7000;
02369 FSR =(double *)malloc(7 *sizeof(double));
02370 lineref =(double *)malloc(referencenlam *sizeof(double));
02371 wavelengthref=(double *)malloc(referencenlam *sizeof(double));
02372 phaseNT =(double *)malloc(nelemPHASENT *sizeof(double));
02373 contrastNT =(double *)malloc(nelemPHASENT *sizeof(double));
02374 contrastT =(double *)malloc(nelemCONTRASTT*sizeof(double));
02375 wavelengthbd =(double *)malloc(201 *sizeof(double));
02376 blockerbd =(double *)malloc(201 *sizeof(double));
02377 wavelengthd =(double *)malloc(401 *sizeof(double));
02378 frontwindowd =(double *)malloc(401 *sizeof(double));
02379 phaseT =(double *)malloc(nelemCONTRASTT*sizeof(double));
02380
02381 printf("We should be running initialize_vfisv_filter\n");
02382
02383 if (mpi_rank == 0)
02384 {
02385 int ierr, status;
02386 stokestime = drms_getkey_time(inRec,"T_REC",&status);
02387 char timestr[26];
02388 sprint_time(timestr,stokestime,"TAI",0);
02389 printf("Looking for phasemap for T_REC %s \n",timestr);
02390 ierr = initialize_vfisv_filter(
02391 wavelengthd,frontwindowd,&nfront,wavelengthbd,blockerbd,
02392 &nblocker,¢erblocker,phaseNT,phaseT,contrastNT,contrastT,FSR,lineref,wavelengthref,
02393 &referencenlam,&HCME1,&HCMWB,&HCMNB,&HCMPOL,stokestime,&FSNREC);
02394 }
02395
02396
02397 ibuff=(int *)malloc(sizeof(int)*8);
02398 ibuff[0]=nfront;
02399 ibuff[1]=nblocker;
02400 ibuff[2]=centerblocker;
02401 ibuff[3]=referencenlam;
02402 ibuff[4]=HCME1;
02403 ibuff[5]=HCMWB;
02404 ibuff[6]=HCMNB;
02405 ibuff[7]=HCMPOL;
02406 MPI_Bcast(ibuff,8,MPI_INT,0,MPI_COMM_WORLD);
02407 nfront =ibuff[0];
02408 nblocker =ibuff[1];
02409 centerblocker=ibuff[2];
02410 referencenlam=ibuff[3];
02411 HCME1 =ibuff[4];
02412 HCMWB =ibuff[5];
02413 HCMNB =ibuff[6];
02414 HCMPOL =ibuff[7];
02415 free(ibuff);
02416
02417 double *fbigbuf;
02418 int bigbufsize;
02419 bigbufsize=7+referencenlam+referencenlam+nelemPHASENT+nelemPHASENT+nelemCONTRASTT+201+201+401+401+nelemCONTRASTT;
02420 fbigbuf=(double *)malloc(bigbufsize*sizeof(double));
02421 MPI_Barrier(MPI_COMM_WORLD);
02422 if (mpi_rank == 0)
02423 {
02424 int icount;
02425 icount = 0;
02426 for (i=0;i< 7;i++){fbigbuf[icount]=FSR[i] ;icount++;}
02427 for (i=0;i< referencenlam;i++){fbigbuf[icount]=lineref[i] ;icount++;}
02428 for (i=0;i< referencenlam;i++){fbigbuf[icount]=wavelengthref[i];icount++;}
02429 for (i=0;i< nelemPHASENT;i++){fbigbuf[icount]=phaseNT[i] ;icount++;}
02430 for (i=0;i< nelemPHASENT;i++){fbigbuf[icount]=contrastNT[i] ;icount++;}
02431 for (i=0;i<nelemCONTRASTT;i++){fbigbuf[icount]=contrastT[i] ;icount++;}
02432 for (i=0;i< 201;i++){fbigbuf[icount]=wavelengthbd[i] ;icount++;}
02433 for (i=0;i< 201;i++){fbigbuf[icount]=blockerbd[i] ;icount++;}
02434 for (i=0;i< 401;i++){fbigbuf[icount]=wavelengthd[i] ;icount++;}
02435 for (i=0;i< 401;i++){fbigbuf[icount]=frontwindowd[i] ;icount++;}
02436 for (i=0;i<nelemCONTRASTT;i++){fbigbuf[icount]=phaseT[i] ;icount++;}
02437 if (icount != bigbufsize)
02438 {
02439 printf("Icount BigBufSize = %d %d\n",icount,bigbufsize);
02440 DIE("Mistake at large float buffer, at debug point 1 !\n");
02441 }
02442 }
02443 MPI_Barrier(MPI_COMM_WORLD);
02444 MPI_Bcast(fbigbuf,bigbufsize,MPI_DOUBLE,0,MPI_COMM_WORLD);
02445 if (mpi_rank > 0)
02446 {
02447 int icount;
02448 icount = 0;
02449 for (i=0;i< 7;i++){FSR[i] =fbigbuf[icount];icount++;}
02450 for (i=0;i< referencenlam;i++){lineref[i] =fbigbuf[icount];icount++;}
02451 for (i=0;i< referencenlam;i++){wavelengthref[i]=fbigbuf[icount];icount++;}
02452 for (i=0;i< nelemPHASENT;i++){phaseNT[i] =fbigbuf[icount];icount++;}
02453 for (i=0;i< nelemPHASENT;i++){contrastNT[i] =fbigbuf[icount];icount++;}
02454 for (i=0;i<nelemCONTRASTT;i++){contrastT[i] =fbigbuf[icount];icount++;}
02455 for (i=0;i< 201;i++){wavelengthbd[i] =fbigbuf[icount];icount++;}
02456 for (i=0;i< 201;i++){blockerbd[i] =fbigbuf[icount];icount++;}
02457 for (i=0;i< 401;i++){wavelengthd[i] =fbigbuf[icount];icount++;}
02458 for (i=0;i< 401;i++){frontwindowd[i] =fbigbuf[icount];icount++;}
02459 for (i=0;i<nelemCONTRASTT;i++){phaseT[i] =fbigbuf[icount];icount++;}
02460 if (icount != bigbufsize)
02461 {
02462 printf("Icount BigBufSize = %d %d\n",icount,bigbufsize);
02463 DIE("Mistake at large float buffer, at debug point 2 !\n");
02464 }
02465 }
02466 free(fbigbuf);
02467 if (verbose){printf("done initialize_vfisv_filter by S.C., for mpi_rank %d\n",mpi_rank);}
02468 MPI_Barrier(MPI_COMM_WORLD);
02469
02470
02471 double norm_factor;
02472 #if NRMLFLTR == 1
02473 if (mpi_rank == 0)
02474 {
02475
02476 column = 2048;
02477 row = 2048;
02478 ratio = 4096/nx2;
02479
02480 x0 = (column/ratio);
02481 y0 = (row/ratio);
02482 x1 = x0+1;
02483 y1 = y0+1;
02484 if(x1 >= nx2){x0 = x0-1; x1 = x1-1;}
02485 if(y1 >= ny2){y0 = y0-1; y1 = y1-1;}
02486 xa = ((double)x1-(double)(column % ratio)/(double)ratio-(double)x0);
02487 xb = ((double)(column % ratio)/(double)ratio);
02488 ya = ((double)y1-(double)(row % ratio)/(double)ratio-(double)y0);
02489 yb = ((double)(row % ratio)/(double)ratio);
02490 loc1 = x0+y0*nx2;
02491 loc2 = x1+y0*nx2;
02492 loc3 = x0+y1*nx2;
02493 loc4 = x1+y1*nx2;
02494 phaseNTi[0] = ya*(phaseNT[loc1 ]*xa+phaseNT[loc2 ]*xb)
02495 +yb*(phaseNT[loc3 ]*xa+phaseNT[loc4 ]*xb);
02496 phaseNTi[1] = ya*(phaseNT[loc1+ nx2*ny2]*xa+phaseNT[loc2+nx2*ny2 ]*xb)
02497 +yb*(phaseNT[loc3+ nx2*ny2]*xa+phaseNT[loc4+ nx2*ny2]*xb);
02498 phaseNTi[2] = ya*(phaseNT[loc1+2*nx2*ny2]*xa+phaseNT[loc2+2*nx2*ny2]*xb)
02499 +yb*(phaseNT[loc3+2*nx2*ny2]*xa+phaseNT[loc4+2*nx2*ny2]*xb);
02500 phaseNTi[3] = ya*(phaseNT[loc1+3*nx2*ny2]*xa+phaseNT[loc2+3*nx2*ny2]*xb)
02501 +yb*(phaseNT[loc3+3*nx2*ny2]*xa+phaseNT[loc4+3*nx2*ny2]*xb);
02502 phaseTi[0] = ya*(phaseT[loc1*3 ]*xa+phaseT[loc2*3 ]*xb)+yb*(phaseT[loc3*3 ]*xa+phaseT[loc4*3 ]*xb);
02503 phaseTi[1] = ya*(phaseT[loc1*3+1]*xa+phaseT[loc2*3+1]*xb)+yb*(phaseT[loc3*3+1]*xa+phaseT[loc4*3+1]*xb);
02504 phaseTi[2] = ya*(phaseT[loc1*3+2]*xa+phaseT[loc2*3+2]*xb)+yb*(phaseT[loc3*3+2]*xa+phaseT[loc4*3+2]*xb);
02505 contrastNTi[0]= ya*(contrastNT[loc1 ]*xa+contrastNT[loc2 ]*xb)
02506 +yb*(contrastNT[loc3 ]*xa+contrastNT[loc4 ]*xb);
02507 contrastNTi[1]= ya*(contrastNT[loc1+ nx2*ny2]*xa+contrastNT[loc2+ nx2*ny2]*xb)
02508 +yb*(contrastNT[loc3+ nx2*ny2]*xa+contrastNT[loc4+ nx2*ny2]*xb);
02509 contrastNTi[2]= ya*(contrastNT[loc1+2*nx2*ny2]*xa+contrastNT[loc2+2*nx2*ny2]*xb)
02510 +yb*(contrastNT[loc3+2*nx2*ny2]*xa+contrastNT[loc4+2*nx2*ny2]*xb);
02511 contrastNTi[3]= ya*(contrastNT[loc1+3*nx2*ny2]*xa+contrastNT[loc2+3*nx2*ny2]*xb)
02512 +yb*(contrastNT[loc3+3*nx2*ny2]*xa+contrastNT[loc4+3*nx2*ny2]*xb);
02513 contrastTi[0] = ya*(contrastT[loc1 ]*xa+contrastT[loc2 ]*xb)
02514 +yb*(contrastT[loc3 ]*xa+contrastT[loc4 ]*xb);
02515 contrastTi[1] = ya*(contrastT[loc1+ nx2*ny2]*xa+contrastT[loc2+ nx2*ny2]*xb)
02516 +yb*(contrastT[loc3+ nx2*ny2]*xa+contrastT[loc4+ nx2*ny2]*xb);
02517 contrastTi[2] = ya*(contrastT[loc1+2*nx2*ny2]*xa+contrastT[loc2+2*nx2*ny2]*xb)
02518 +yb*(contrastT[loc3+2*nx2*ny2]*xa+contrastT[loc4+2*nx2*ny2]*xb);
02519 X0 = (double)crpixx-1.0;
02520 Y0 = (double)crpixy-1.0;
02521 Rsun = (double)asin(rsun_ref/dsun_obs)/3.14159265358979e0*180.0*3600.0/cdeltx;
02522 distance = sqrt(((double)row-Y0)*((double)row-Y0)+((double)column-X0)*((double)column-X0));
02523 distance = cos(asin(distance/Rsun));
02524 vfisv_filter(NUM_LAMBDA_FILTERc,NUM_LAMBDAc,filters,LAMBDA_MINc,DELTA_LAMBDAc,
02525 wavelengthd,frontwindowd,nfront,wavelengthbd,blockerbd,nblocker,centerblocker,
02526 phaseNTi,phaseTi,contrastNTi,contrastTi,FSR,lineref,wavelengthref,referencenlam,distance,HCME1,HCMWB,HCMNB,HCMPOL);
02527
02528 double *sum_filt;
02529 sum_filt = (double *)malloc (sizeof (double) * NUM_LAMBDA_FILTER);
02530 double sumsum, aveave;
02531 for (i = 0; i < NUM_LAMBDA_FILTER; i++)
02532 {
02533 sum_filt[i] = 0.0;
02534 for (j = 0; j < NUM_LAMBDA; j++){sum_filt[i] = sum_filt[i] + filters[i][j];
02535 } }
02536 sumsum = 0.0;
02537 for (i = 0; i < NUM_LAMBDA_FILTER; i++){sumsum = sumsum + sum_filt[i];}
02538 aveave = sumsum / ((double)NUM_LAMBDA_FILTER);
02539 if (isnan(aveave) || fabs(aveave) < 1e-10){aveave = 1.0;}
02540 norm_factor = aveave;
02541 free(sum_filt);
02542 }
02543
02544 {
02545 MPI_Barrier(MPI_COMM_WORLD);
02546 fbuff=(float *)malloc(sizeof(float)*1);
02547 fbuff[0] = norm_factor;
02548 MPI_Bcast(fbuff,1,MPI_FLOAT,0,MPI_COMM_WORLD);
02549 norm_factor = fbuff[0];
02550 free(fbuff);
02551 if (verbose) {printf(" normalization factor reaching to %d PE is %f\n",mpi_rank,norm_factor);}
02552 MPI_Barrier(MPI_COMM_WORLD);
02553 }
02554 #else
02555 norm_factor = 1.0;
02556 #endif // end if NRMLFLTR is 1 or not
02557 if (mpi_rank == 0){printf(" normalization factor for filter is %f\n", norm_factor);}
02558
02559
02560 inv_init_(&NUM_ITERATIONS,&SVD_TOLERANCE,&CHI2_STOP,&POLARIZATION_THRESHOLD,&INTENSITY_THRESHOLD);
02561 if (verbose){printf("done inv_init\n");}
02562 free_init_(list_free_params);
02563 if (verbose){printf("done list_free_params for mpi_rank %d\n", mpi_rank);}
02564
02565 if (list_free_params[3] == 0) voigt_init_();
02566 for (n=0; n< nvar; n++) scat[n]=0.0;
02567
02568 MPI_Barrier(MPI_COMM_WORLD);
02569 if (mpi_rank == 0) printf("\n----------- inversion initializations done ------------ \n");
02570
02571
02572 if (mpi_rank == 0) printf("\n----------- finally, do inversion in parallel --------- \n");
02573
02574 time(&starttime1);
02575
02576 myrank = mpi_rank;
02577 nprocs = mpi_size;
02578 numpix = imgpix;
02579 #if CYCLPRLL == 1
02580 istart=0;
02581 iend =jobnum-1;
02582 #else
02583 #if EQUIAREA == 1
02584 istart=istartall[myrank];
02585 iend =iendall[myrank];
02586 #else
02587 para_range(myrank,nprocs,numpix,&istart,&iend);
02588 #endif
02589 #endif
02590 int pixdone;
02591 pixdone = 0;
02592 int pix_noconv;
02593 pix_noconv = 0;
02594
02595 for (n = istart; n < iend + 1; n++)
02596 {
02597 #if CYCLPRLL == 1
02598 if (nan_mapLocal[n-istart] != 0){printf("something nasty happened at %9d th pixel on %2d th PE, %9d th pixel of original. Ah.\n",n,myrank,jobassignmapLocal[n]);DIE(" ah...");}
02599 #endif
02600 if (nan_mapLocal[n-istart] == 0)
02601 {
02602
02603 #if TAKEPREV == 1
02604 if (iexistprev == 1)
02605 {
02606 for (m = 0; m < paramct; m++){prevres[m]=PrevResLocal[(n-istart)*paramct+m];}
02607 for (m = 0; m < Err_ct; m++){preverr[m]=PrevErrLocal[(n-istart)*Err_ct +m];}
02608 }
02609 if (iexistprev == 0)
02610 {
02611 for (m = 0; m < paramct; m++){prevres[m]=NAN;}
02612 for (m = 0; m < Err_ct; m++){preverr[m]=NAN;}
02613 }
02614 #endif
02615
02616 for(m = 0; m < nvar; m++){obs[m]=dataLocal[(n-istart)*nvar+m];}
02617
02618
02619
02620
02621
02622
02623
02624
02625
02626
02627
02628
02629 int nccd;
02630 #if CYCLPRLL == 1
02631 nccd = jobassignmapLocal[n];
02632 #else
02633 nccd = n;
02634 #endif
02635
02636
02637
02638 {
02639 int nloc, iloc, jloc;
02640 float filoc, fjloc;
02641 iloc = nccd % cols;
02642 jloc = nccd / cols;
02643 filoc = (float)(iloc) / (float)(cols);
02644 fjloc = (float)(jloc) / (float)(rows);
02645 filoc = filoc * 4096.0 + 0.000000001;
02646 fjloc = fjloc * 4096.0 + 0.000000001;
02647 iloc = (int)(filoc);
02648 jloc = (int)(fjloc);
02649 nloc = iloc + 4096 * jloc;
02650
02651
02652
02653 column =nloc % 4096;
02654 row =nloc / 4096;
02655 ratio =4096 / nx2;
02656 }
02657
02658
02659
02660
02661
02662
02663
02664
02665 x0 = (column/ratio);
02666 y0 = (row/ratio);
02667 x1 = x0+1;
02668 y1 = y0+1;
02669
02670 if(x1 >= nx2)
02671 {
02672 x0 = x0-1;
02673 x1 = x1-1;
02674 }
02675 if(y1 >= ny2)
02676 {
02677 y0 = y0-1;
02678 y1 = y1-1;
02679 }
02680
02681 xa = ((double)x1-(double)(column % ratio)/(double)ratio-(double)x0);
02682 xb = ((double)(column % ratio)/(double)ratio);
02683 ya = ((double)y1-(double)(row % ratio)/(double)ratio-(double)y0);
02684 yb = ((double)(row % ratio)/(double)ratio);
02685
02686
02687 loc1 = x0+y0*nx2;
02688 loc2 = x1+y0*nx2;
02689 loc3 = x0+y1*nx2;
02690 loc4 = x1+y1*nx2;
02691
02692 phaseNTi[0] = ya*(phaseNT[loc1 ]*xa+phaseNT[loc2 ]*xb)
02693 +yb*(phaseNT[loc3 ]*xa+phaseNT[loc4 ]*xb);
02694 phaseNTi[1] = ya*(phaseNT[loc1+ nx2*ny2]*xa+phaseNT[loc2+nx2*ny2 ]*xb)
02695 +yb*(phaseNT[loc3+ nx2*ny2]*xa+phaseNT[loc4+ nx2*ny2]*xb);
02696 phaseNTi[2] = ya*(phaseNT[loc1+2*nx2*ny2]*xa+phaseNT[loc2+2*nx2*ny2]*xb)
02697 +yb*(phaseNT[loc3+2*nx2*ny2]*xa+phaseNT[loc4+2*nx2*ny2]*xb);
02698 phaseNTi[3] = ya*(phaseNT[loc1+3*nx2*ny2]*xa+phaseNT[loc2+3*nx2*ny2]*xb)
02699 +yb*(phaseNT[loc3+3*nx2*ny2]*xa+phaseNT[loc4+3*nx2*ny2]*xb);
02700 phaseTi[0] = ya*(phaseT[loc1*3 ]*xa+phaseT[loc2*3 ]*xb)+yb*(phaseT[loc3*3 ]*xa+phaseT[loc4*3 ]*xb);
02701 phaseTi[1] = ya*(phaseT[loc1*3+1]*xa+phaseT[loc2*3+1]*xb)+yb*(phaseT[loc3*3+1]*xa+phaseT[loc4*3+1]*xb);
02702 phaseTi[2] = ya*(phaseT[loc1*3+2]*xa+phaseT[loc2*3+2]*xb)+yb*(phaseT[loc3*3+2]*xa+phaseT[loc4*3+2]*xb);
02703 contrastNTi[0]= ya*(contrastNT[loc1 ]*xa+contrastNT[loc2 ]*xb)
02704 +yb*(contrastNT[loc3 ]*xa+contrastNT[loc4 ]*xb);
02705 contrastNTi[1]= ya*(contrastNT[loc1+ nx2*ny2]*xa+contrastNT[loc2+ nx2*ny2]*xb)
02706 +yb*(contrastNT[loc3+ nx2*ny2]*xa+contrastNT[loc4+ nx2*ny2]*xb);
02707 contrastNTi[2]= ya*(contrastNT[loc1+2*nx2*ny2]*xa+contrastNT[loc2+2*nx2*ny2]*xb)
02708 +yb*(contrastNT[loc3+2*nx2*ny2]*xa+contrastNT[loc4+2*nx2*ny2]*xb);
02709 contrastNTi[3]= ya*(contrastNT[loc1+3*nx2*ny2]*xa+contrastNT[loc2+3*nx2*ny2]*xb)
02710 +yb*(contrastNT[loc3+3*nx2*ny2]*xa+contrastNT[loc4+3*nx2*ny2]*xb);
02711 contrastTi[0] = ya*(contrastT[loc1 ]*xa+contrastT[loc2 ]*xb)
02712 +yb*(contrastT[loc3 ]*xa+contrastT[loc4 ]*xb);
02713 contrastTi[1] = ya*(contrastT[loc1+ nx2*ny2]*xa+contrastT[loc2+ nx2*ny2]*xb)
02714 +yb*(contrastT[loc3+ nx2*ny2]*xa+contrastT[loc4+ nx2*ny2]*xb);
02715 contrastTi[2] = ya*(contrastT[loc1+2*nx2*ny2]*xa+contrastT[loc2+2*nx2*ny2]*xb)
02716 +yb*(contrastT[loc3+2*nx2*ny2]*xa+contrastT[loc4+2*nx2*ny2]*xb);
02717 X0 = (double)crpixx-1.0;
02718 Y0 = (double)crpixy-1.0;
02719 Rsun = (double)asin(rsun_ref/dsun_obs)/3.14159265358979e0*180.0*3600.0/cdeltx;
02720 distance = sqrt(((double)row-Y0)*((double)row-Y0)+((double)column-X0)*((double)column-X0));
02721 distance = cos(asin(distance/Rsun));
02722
02723
02724 vfisv_filter(NUM_LAMBDA_FILTERc,NUM_LAMBDAc,filters,LAMBDA_MINc,DELTA_LAMBDAc,
02725 wavelengthd,frontwindowd,nfront,wavelengthbd,blockerbd,nblocker,centerblocker,
02726 phaseNTi,phaseTi,contrastNTi,contrastTi,FSR,lineref,wavelengthref,referencenlam,distance,HCME1,HCMWB,HCMNB,HCMPOL);
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745
02746
02747
02748
02749
02750
02751
02752
02753
02754
02755
02756 int iconverge_flag;
02757
02758
02759
02760
02761
02762
02763
02764
02765
02766
02767
02768
02769
02770
02771
02772 weights[0]=1.0; weights[1]=5.0; weights[2]=5.0; weights[3]=3.5;
02773
02774 #if VLOSINIT == 1
02775 guess[6] = vlos_initLocal[n-istart];
02776 #endif
02777 #if MGSTINIT == 1
02778 guess[5] = mgst_initLocal[n-istart];
02779 #endif
02780
02781
02782 #if NLEVPIXL == 1
02783 double ivalmax, ivalave, CONT;
02784 ivalmax = -100.0e0;
02785 ivalave = 0.0e0;
02786 {
02787 int m;
02788 for (m = 0; m < NUM_LAMBDA_FILTER; m++)
02789 {
02790 double tmpval=obs[0*NUM_LAMBDA_FILTER+m];
02791 ivalave = ivalave + tmpval;
02792 if (tmpval > ivalmax){ivalmax = tmpval;}
02793 }
02794 CONT = ivalmax;
02795 ivalave = ivalave / ((double)(NUM_LAMBDA_FILTER));
02796 ivalave = sqrt(ivalave);
02797 ivalmax = sqrt(ivalmax);
02798 }
02799 NOISE_LEVEL[0] = NOISE_LEVELFI * ivalave;
02800 NOISE_LEVEL[1] = NOISE_LEVELFQ * ivalave;
02801 NOISE_LEVEL[2] = NOISE_LEVELFU * ivalave;
02802 NOISE_LEVEL[3] = NOISE_LEVELFV * ivalave;
02803
02804 lim_init_(&CONT);
02805 line_init_(&LAMBDA_0,&LAMBDA_B,NOISE_LEVEL);
02806 wave_init_ (&LAMBDA_MIN_synth,&DELTA_LAMBDA,&NUM_LAMBDA_synth);
02807 filt_init_ (&NUM_LAMBDA_FILTER,&WSPACING, &NUM_LAMBDA);
02808 #endif
02809
02810
02811
02812 #if NRMLFLTR == 1
02813 for (i = 0; i < NUM_LAMBDA_FILTER; i++){for (j = 0; j < NUM_LAMBDA; j++)
02814 {
02815 filters[i][j] = filters[i][j] / norm_factor;
02816 } }
02817 #endif
02818
02819 invert_ (obs, scat, guess, res, err, filters, &iconverge_flag, weights);
02820
02821
02822
02823
02824
02825
02826
02827
02828
02829
02830
02831 if (err[0] > 12000.0) {err[0] = 12000.0;}
02832 if (err[1] > 180.0) {err[1] = 180.0;}
02833 if (err[2] > 180.0) {err[2] = 180.0;}
02834
02835
02836
02837
02838
02839 if ((iconverge_flag == 4) ||
02840 (iconverge_flag == 5) ||
02841 (iconverge_flag == 1))
02842 {
02843 if (verbose){printf("Hello, this is %2d th PE : found iconverge_flag %d at %9d th pixel.\n", mpi_rank, iconverge_flag, nccd);}
02844 for (j=0; j<paramct; j++){res[j]=NAN;}
02845 for (k=0; k<Err_ct; k++){err[k]=NAN;}
02846 }
02847
02848 FinalConvFlagLocal[n-istart]=iconverge_flag;
02849
02850
02851 if (iconverge_flag > 0)
02852 {
02853 pix_noconv = pix_noconv + 1;
02854 FinalQualMapLocal[n-istart]=0x00000002;
02855 }
02856 else
02857 {
02858 FinalQualMapLocal[n-istart]=0x00000000;
02859 }
02860 for (j=0; j<paramct; j++){FinalResLocal[(n-istart)*paramct+j]=res[j];}
02861 for (k=0; k<Err_ct; k++){FinalErrLocal[(n-istart)*Err_ct +k]=err[k];}
02862
02863 pixdone = pixdone + 1;
02864 }
02865 else
02866 {
02867 float aa=NAN;
02868 FinalConvFlagLocal[n-istart]=1;
02869 FinalQualMapLocal [n-istart]=(int)(aa);
02870 for (j=0; j<paramct; j++){FinalResLocal[(n-istart)*paramct+j]=NAN;}
02871 for (k=0; k<Err_ct; k++){FinalErrLocal[(n-istart)*Err_ct +k]=NAN;}
02872 }
02873 }
02874 if (verbose){printf("Hello, this is %2d th PE : inversion done for %9d pixels. \n", mpi_rank, pixdone);}
02875 if (verbose){printf("Hello, this is %2d th PE : Num of pixel at which solution did not converge = %d\n",mpi_rank,pix_noconv);}
02876 time(&endtime1);
02877 if (verbose){printf("Hello, this is %2d th PE : Time spent %ld\n",mpi_rank,endtime1-starttime1);}
02878 MPI_Barrier(MPI_COMM_WORLD);
02879
02880
02881 int sum_pix_noconv;
02882 int sum_pixdone;
02883 {
02884 int *ibufs, *ibufr;
02885 ibufs = (int *)malloc(sizeof(int)*2);
02886 ibufr = (int *)malloc(sizeof(int)*2);
02887 ibufs[0] = pix_noconv;
02888 ibufs[1] = pixdone;
02889 MPI_Reduce(ibufs,ibufr,2,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD);
02890 if (mpi_rank == 0)
02891 {
02892 sum_pix_noconv = ibufr[0];
02893 sum_pixdone = ibufr[1];
02894 printf("Total num. of pixel processed = %d\n",sum_pixdone);
02895 printf("Total num. of pixel at which solution did not converge = %d\n",sum_pix_noconv);
02896 }
02897 }
02898 MPI_Barrier(MPI_COMM_WORLD);
02899
02900
02901 free(FSR);
02902 free(phaseNT);
02903 free(contrastNT);
02904 free(phaseT);
02905 free(contrastT);
02906 free(wavelengthbd);
02907 free(blockerbd);
02908 free(wavelengthd);
02909 free(frontwindowd);
02910 free(lineref);
02911 free(wavelengthref);
02912
02913
02914 if (mpi_rank == 0)
02915 {
02916 myrank = mpi_rank;
02917 nprocs = mpi_size;
02918 numpix = imgpix;
02919 #if CYCLPRLL == 1
02920 istart=0;
02921 iend =jobnum-1;
02922 #else
02923 #if EQUIAREA == 1
02924 istart=istartall[myrank];
02925 iend=iendall[myrank];
02926 #else
02927 para_range(myrank,nprocs,numpix,&istart,&iend);
02928 #endif
02929 #endif
02930
02931 #if CYCLPRLL == 1
02932 for (n = istart ; n < iend+1 ; n++)
02933 {
02934 for (j=0; j<paramct; j++){FinalRes[(jobassignmap[n]*paramct)+j]=FinalResLocal[(n-istart)*paramct+j];}
02935 for (k=0; k<Err_ct ; k++){FinalErr[(jobassignmap[n]*Err_ct) +k]=FinalErrLocal[(n-istart)*Err_ct +k];}
02936 }
02937 #else
02938 for (n = istart ; n < iend+1 ; n++)
02939 {
02940 for (j=0; j<paramct; j++){FinalRes[(n *paramct)+j]=FinalResLocal[(n-istart)*paramct+j];}
02941 for (k=0; k<Err_ct ; k++){FinalErr[(n *Err_ct) +k]=FinalErrLocal[(n-istart)*Err_ct +k];}
02942 }
02943 #endif
02944
02945 if (mpi_size > 1)
02946 {
02947 printf("now collecting float data from PEs : ");
02948 int irecv;
02949 for (irecv = 1; irecv < mpi_size ; irecv++)
02950 {
02951 printf(" %d ",irecv);
02952 int mpi_from;
02953 nprocs = mpi_size;
02954 numpix = imgpix;
02955 #if CYCLPRLL == 1
02956 istart=0;
02957 iend =jobnum-1;
02958 #else
02959 #if EQUIAREA == 1
02960 istart=istartall[irecv];
02961 iend=iendall[irecv];
02962 #else
02963 para_range(irecv,nprocs,numpix,&istart,&iend);
02964 #endif
02965 #endif
02966 int ibufsize;
02967 ibufsize = (iend-istart+1) * (paramct+Err_ct);
02968 double *dbufrecv;
02969 dbufrecv = (double*)malloc(sizeof (double) * ibufsize);
02970 mpi_from = irecv;
02971 mpi_tag = 1200 + irecv;
02972 MPI_Recv(dbufrecv, ibufsize, MPI_DOUBLE, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
02973 #if CYCLPRLL == 1
02974 for (n = istart ; n < iend+1 ; n++)
02975 {
02976 for (j=0; j<paramct; j++){FinalRes[(jobassignmap[n+jobnum*mpi_from]*paramct)+j]=dbufrecv[(n-istart)*(paramct+Err_ct) +j];}
02977 for (k=0; k<Err_ct ; k++){FinalErr[(jobassignmap[n+jobnum*mpi_from]*Err_ct) +k]=dbufrecv[(n-istart)*(paramct+Err_ct)+paramct+k];}
02978 }
02979 #else
02980 for (n = istart ; n < iend+1 ; n++)
02981 {
02982 for (j=0; j<paramct; j++){FinalRes[(n *paramct)+j]=dbufrecv[(n-istart)*(paramct+Err_ct) +j];}
02983 for (k=0; k<Err_ct ; k++){FinalErr[(n *Err_ct) +k]=dbufrecv[(n-istart)*(paramct+Err_ct)+paramct+k];}
02984 }
02985 #endif
02986 free(dbufrecv);
02987 }
02988 printf("done \n");
02989 }
02990 }
02991 else
02992 {
02993 int isend;
02994 int mpi_dest = 0;
02995 nprocs = mpi_size;
02996 numpix = imgpix;
02997 isend = mpi_rank;
02998 #if CYCLPRLL == 1
02999 istart=0;
03000 iend =jobnum-1;
03001 #else
03002 #if EQUIAREA == 1
03003 istart=istartall[isend];
03004 iend=iendall[isend];
03005 #else
03006 para_range(isend,nprocs,numpix,&istart,&iend);
03007 #endif
03008 #endif
03009 int ibufsize;
03010 ibufsize = (iend-istart+1) * (paramct+Err_ct);
03011 double *dbufsend;
03012 dbufsend = (double*)malloc(sizeof (double) * ibufsize);
03013 for (n = istart ; n < iend + 1 ; n++)
03014 {
03015 for (j=0; j<paramct; j++){dbufsend[(n-istart)*(paramct+Err_ct) +j]=FinalResLocal[(n-istart)*paramct+j];}
03016 for (k=0; k<Err_ct; k++){dbufsend[(n-istart)*(paramct+Err_ct)+paramct+k]=FinalErrLocal[(n-istart)*Err_ct +k];}
03017 }
03018 mpi_tag = 1200 + mpi_rank;
03019 MPI_Send(dbufsend, ibufsize, MPI_DOUBLE, mpi_dest, mpi_tag, MPI_COMM_WORLD);
03020 free(dbufsend);
03021 }
03022 MPI_Barrier(MPI_COMM_WORLD);
03023
03024
03025 if (mpi_rank == 0)
03026 {
03027 myrank = mpi_rank;
03028 nprocs = mpi_size;
03029 numpix = imgpix;
03030 #if CYCLPRLL == 1
03031 istart=0;
03032 iend =jobnum-1;
03033 #else
03034 #if EQUIAREA == 1
03035 istart=istartall[myrank];
03036 iend=iendall[myrank];
03037 #else
03038 para_range(myrank,nprocs,numpix,&istart,&iend);
03039 #endif
03040 #endif
03041
03042 #if CYCLPRLL == 1
03043 for (n = istart ; n < iend+1 ; n++)
03044 {
03045 FinalConvFlag[jobassignmap[n]] = FinalConvFlagLocal[n-istart];
03046 FinalQualMap [jobassignmap[n]] = FinalQualMapLocal [n-istart];
03047 }
03048 #else
03049 for (n = istart ; n < iend+1 ; n++)
03050 {
03051 FinalConvFlag[n] = FinalConvFlagLocal[n-istart];
03052 FinalQualMap [n] = FinalQualMapLocal [n-istart];
03053 }
03054 #endif
03055
03056 if (mpi_size > 1)
03057 {
03058 printf("now collecting integer data from PEs : ");
03059 int irecv;
03060 for (irecv = 1; irecv < mpi_size ; irecv++)
03061 {
03062 printf(" %d ",irecv);
03063 int mpi_from;
03064 nprocs = mpi_size;
03065 numpix = imgpix;
03066 #if CYCLPRLL == 1
03067 istart=0;
03068 iend =jobnum-1;
03069 #else
03070 #if EQUIAREA == 1
03071 istart=istartall[irecv];
03072 iend=iendall[irecv];
03073 #else
03074 para_range(irecv,nprocs,numpix,&istart,&iend);
03075 #endif
03076 #endif
03077 int ibufsize;
03078 ibufsize = (iend-istart+1) * 2;
03079 int *ibufrecv;
03080 ibufrecv = (int*)malloc(sizeof(int) * ibufsize);
03081 mpi_from = irecv;
03082 mpi_tag = 1300 + irecv;
03083 MPI_Recv(ibufrecv, ibufsize, MPI_INT, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
03084 #if CYCLPRLL == 1
03085 for (n = istart ; n < iend+1 ; n++)
03086 {
03087 FinalConvFlag[jobassignmap[n+jobnum*mpi_from]] = ibufrecv[n-istart];
03088 FinalQualMap [jobassignmap[n+jobnum*mpi_from]] = ibufrecv[n-istart+(iend-istart+1)];
03089 }
03090 #else
03091 for (n = istart ; n < iend+1 ; n++)
03092 {
03093 FinalConvFlag[n] = ibufrecv[n-istart];
03094 FinalQualMap [n] = ibufrecv[n-istart+(iend-istart+1)];
03095 }
03096 #endif // end if CYCLPRLL is 1 or not
03097 free(ibufrecv);
03098 }
03099 printf("done \n");
03100 }
03101 }
03102 else
03103 {
03104 int isend;
03105 int mpi_dest = 0;
03106 nprocs = mpi_size;
03107 numpix = imgpix;
03108 isend = mpi_rank;
03109 #if CYCLPRLL == 1
03110 istart=0;
03111 iend =jobnum-1;
03112 #else
03113 #if EQUIAREA == 1
03114 istart=istartall[isend];
03115 iend=iendall[isend];
03116 #else
03117 para_range(isend,nprocs,numpix,&istart,&iend);
03118 #endif
03119 #endif
03120 int ibufsize;
03121 ibufsize = (iend-istart+1) * 2;
03122 int *ibufsend;
03123 ibufsend = (int*)malloc(sizeof (int) * ibufsize);
03124 for (n = istart ; n < iend + 1 ; n++)
03125 {
03126 ibufsend[n-istart ]=FinalConvFlagLocal[n-istart];
03127 ibufsend[n-istart+(iend-istart+1)]=FinalQualMapLocal [n-istart];
03128 }
03129 mpi_tag = 1300 + mpi_rank;
03130 MPI_Send(ibufsend, ibufsize, MPI_INT, mpi_dest, mpi_tag, MPI_COMM_WORLD);
03131 free(ibufsend);
03132 }
03133 MPI_Barrier(MPI_COMM_WORLD);
03134
03135
03136 if (mpi_rank == 0)
03137 {
03138 #if CYCLPRLL == 1
03139 for (n = 0 ; n < imgpix; n++)
03140 {
03141 if (nan_map[n] != 0)
03142 {
03143 float aa=NAN;
03144 FinalConvFlag[n] = 1;
03145 FinalQualMap [n] = (int)(aa);
03146 for (j=0; j<paramct; j++){FinalRes[(n*paramct)+j]=NAN;}
03147 for (k=0; k<Err_ct ; k++){FinalErr[(n*Err_ct) +k]=NAN;}
03148 }
03149 }
03150 #else
03151 if (istartall[0] > 0)
03152 {
03153 for (n = 0 ; n < istartall[0]; n++)
03154 {
03155 float aa=NAN;
03156 FinalConvFlag[n] = 1;
03157 FinalQualMap [n] = (int)(aa);
03158 for (j=0; j<paramct; j++){FinalRes[(n*paramct)+j]=NAN;}
03159 for (k=0; k<Err_ct ; k++){FinalErr[(n*Err_ct) +k]=NAN;}
03160 }
03161 }
03162 if (iendall[mpi_size-1] < imgpix - 1)
03163 {
03164 for (n = iendall[mpi_size-1] + 1; n < imgpix; n++)
03165 {
03166 float aa=NAN;
03167 FinalConvFlag[n] = 1;
03168 FinalQualMap [n] = (int)(aa);
03169 for (j=0; j<paramct; j++){FinalRes[(n*paramct)+j]=NAN;}
03170 for (k=0; k<Err_ct ; k++){FinalErr[(n*Err_ct) +k]=NAN;}
03171 }
03172 }
03173 #endif // end if CYCLPRLL is 1 or not
03174 }
03175
03176 MPI_Barrier(MPI_COMM_WORLD);
03177
03178
03179 free(FinalConvFlagLocal);
03180 free(FinalQualMapLocal);
03181 free(FinalResLocal);
03182 free(FinalErrLocal);
03183 free(dataLocal);
03184 free(nan_mapLocal);
03185 #if CYCLPRLL == 1
03186 free(jobassignmapLocal);
03187 #endif
03188 MPI_Barrier(MPI_COMM_WORLD);
03189
03190
03191 #if CONFINDX == 1
03192 if (mpi_rank == 0)
03193 {
03194 #define invCode0 0x0000 // inversion convergence
03195 #define invCode2 0x0002 // reached maximum number of iterations
03196 #define invCode3 0x0003 // finished with too many consecutive non-converging iterations
03197 #define invCode4 0x0004 // NaN in the computation of chi2. exited loop
03198 #define invCode5 0x0005 // NaN in SVDSOL. exited loop
03199 #define invCode1 0x0001 // continuum intensity not above the required threshold. pixel not inverted
03200 #define pixCode0 0x0000 // good pixel
03201 #define pixCode1 0x0008 // bad pixel
03202 #define quCode0 0x0000 // good QU-signal
03203 #define quCode1 0x0010 // low QU-signal
03204 #define vCode0 0x0000 // good V-signal
03205 #define vCode1 0x0020 // low V-signal
03206 #define blosCode0 0x0000 //good Blos value
03207 #define blosCode1 0x0040 //low Blos value
03208 #define missCode0 0x0000 // Not A missing data
03209 #define missCode1 0x0080 // Missing data
03210 #define pixThreshold 500.0 // Threshold value for determining bad pixels
03211
03212
03213
03214
03215
03216
03217 #define losThreshold 1.0 * 6.7 // 1 * sigma of 720s los mags.
03218 #define RADSINDEG 3.14159265358979 / 180.0
03219
03220
03221
03222
03223 float vScale=0.204, quScale=0.204, iScale=0.118;
03224
03225 if (cameraID == 3)
03226 {
03227 vScale = 0.118;
03228 quScale = 0.167;
03229 iScale = 0.083;
03230 }
03231
03232
03233
03234
03235
03236
03237 int yOff = 0, iData = 0;
03238 int invQual, pixQual, quQual, vQual, blosQual, missQual;
03239 int nx = cols;
03240 int ny = rows;
03241 for (iData = 0; iData < imgpix; iData++)
03242 {
03243 float stokesV, stokesU, stokesQ, stokesI;
03244 stokesI = 0.0;
03245 stokesQ = 0.0;
03246 stokesU = 0.0;
03247 stokesV = 0.0;
03248
03249
03250 int m;
03251 for (m = 0; m < NUM_LAMBDA_FILTER; m++)
03252 {
03253 stokesI = stokesI + data[iData +(m+NUM_LAMBDA_FILTER*0)*imgpix];
03254 stokesQ = stokesQ + data[iData +(m+NUM_LAMBDA_FILTER*1)*imgpix];
03255 stokesU = stokesU + data[iData +(m+NUM_LAMBDA_FILTER*2)*imgpix];
03256 stokesV = stokesV + fabs(data[iData +(m+NUM_LAMBDA_FILTER*3)*imgpix]);
03257 }
03258
03259
03260 float bLos = blosgram[ iData];
03261 double bTotal = FinalRes[(iData*paramct)+5];
03262 double bIncl = FinalRes[(iData*paramct)+1];
03263 int bInvFlag = FinalConvFlag[iData];
03264
03265
03266 FinalConfidMap[iData] = 0;
03267 invQual = invCode0;
03268 pixQual = pixCode0;
03269 quQual = quCode0;
03270 vQual = vCode0;
03271 blosQual = blosCode0;
03272 missQual = missCode0;
03273 if (isnan(bTotal) || isnan(bIncl) || isnan(bLos) ||
03274 isnan(stokesI) || isnan(stokesQ) || isnan(stokesU) || isnan(stokesV) || isnan(bInvFlag))
03275 {
03276 missQual = missCode1;
03277 FinalQualMap[iData] = invQual | pixQual | quQual | vQual | blosQual | missQual;
03278 FinalConfidMap[iData] = 6;
03279 }
03280 else
03281 {
03282
03283 float sigmaLP = 0.0, sigmaV = 0.0;
03284 float Qall = 0.0, Uall = 0.0, varQUall = 0.0, varVall = 0.0, LP = 0.0, Vall = 0.0;
03285 Qall = stokesQ;
03286 Uall = stokesU;
03287 Vall = stokesV;
03288 LP = sqrt(Qall * Qall + Uall * Uall);
03289 varQUall = quScale * quScale * stokesI;
03290 varVall = vScale * vScale * stokesI;
03291 sigmaLP = sqrt(varQUall);
03292 sigmaV = sqrt(varVall);
03293
03294 if (bInvFlag == 2) invQual = invCode2;
03295 if (bInvFlag == 3) invQual = invCode3;
03296 if (bInvFlag == 4) invQual = invCode4;
03297 if (bInvFlag == 5) invQual = invCode5;
03298 if (bInvFlag == 1) invQual = invCode1;
03299 if ((fabs(bLos) - fabs(bTotal * cos(bIncl * RADSINDEG)) > pixThreshold)) pixQual = pixCode1;
03300 if (LP < sigmaLP) quQual = quCode1;
03301 if (Vall < sigmaV) vQual = vCode1;
03302 if (fabs(bLos) < losThreshold) blosQual = blosCode1;
03303 FinalQualMap[iData] = invQual | pixQual | quQual | vQual | blosQual | missQual;
03304 if ((pixQual == 0) && (invQual == 0))
03305 {
03306 if ((vQual != 0) && (quQual == 0) && (blosQual == 0)) FinalConfidMap[iData] = 1;
03307 if ((vQual == 0) && (quQual != 0) && (blosQual == 0)) FinalConfidMap[iData] = 1;
03308 if ((vQual == 0) && (quQual == 0) && (blosQual != 0)) FinalConfidMap[iData] = 1;
03309 if ((vQual != 0) && (quQual != 0) && (blosQual == 0)) FinalConfidMap[iData] = 2;
03310 if ((vQual == 0) && (quQual != 0) && (blosQual != 0)) FinalConfidMap[iData] = 2;
03311 if ((vQual != 0) && (quQual == 0) && (blosQual != 0)) FinalConfidMap[iData] = 2;
03312 if ((vQual != 0) && (quQual != 0) && (blosQual != 0)) FinalConfidMap[iData] = 3;
03313 }
03314 if ((pixQual == 0) && (invQual != 0)) FinalConfidMap[iData] = 4;
03315 if (pixQual != 0) FinalConfidMap[iData] = 5;
03316 }
03317 }
03318
03319
03320 for (iData = 0; iData < imgpix; iData++)
03321 {
03322 int ival = FinalQualMap[iData];
03323 if (!isnan(ival)){FinalQualMap[iData] = ival * 256 * 256 * 256;}
03324
03325 }
03326
03327 }
03328 MPI_Barrier(MPI_COMM_WORLD);
03329 #endif // end if CONFINDX is 1 or not
03330
03331
03332 if (mpi_rank == 0)
03333 {
03334 outRec = drms_create_record (drms_env, outser, DRMS_PERMANENT, &status);
03335 if (!outRec) {fprintf (stderr, "Error creating record in series %s; abandoned\n",outser);return 1;}
03336
03337
03338 drms_copykeys(outRec, inRec, 0, kDRMS_KeyClass_Explicit);
03339
03340
03341 double blos_ave=0.0;
03342 double babs_ave=0.0;
03343 double vlos_ave=0.0;
03344 {
03345 int icount1=0;
03346 int icount2=0;
03347 int n, nend;
03348 for(n = 0; n < imgpix ; n++)
03349 {
03350 int inan = nan_map[n];
03351 if (inan == 0)
03352 {
03353 float babs =FinalRes[(n*paramct)+5];
03354 float tht =FinalRes[(n*paramct)+1];
03355 if (!isnan(babs) && !isnan(tht))
03356 {
03357 float costh, thtr, blos;
03358 thtr = tht / 180.0 * 3.14159265358979e0;
03359 costh = cos(thtr);
03360 blos = - babs * costh;
03361 icount1 = icount1 + 1;
03362 babs_ave = babs_ave + babs;
03363 blos_ave = blos_ave + blos;
03364 }
03365 float vlos = FinalRes[(n*paramct)+6];
03366 if (!isnan(vlos))
03367 {
03368 icount2 = icount2 + 1;
03369 vlos_ave = vlos_ave + vlos;
03370 }
03371 } }
03372 if (icount1 > 0)
03373 {
03374 babs_ave=babs_ave/(double)(icount1);
03375 blos_ave=blos_ave/(double)(icount1);
03376 }
03377 else
03378 {
03379 babs_ave=0.0;
03380 blos_ave=0.0;
03381 }
03382 if (icount2 > 0)
03383 {
03384 vlos_ave=vlos_ave/(double)(icount2);
03385 }
03386 else
03387 {
03388 vlos_ave=0.0;
03389 }
03390 }
03391
03392
03393 {
03394
03395
03396 char invcodeversion[256];
03397 char FSNRECs[50];
03398 sprintf(invcodeversion,"%s %s",module_name,version_id);
03399 strcat(invcodeversion,"; uses time-dependent HMI filter phase maps");
03400 drms_setkey_string(outRec,"INVCODEV", invcodeversion);
03401 sprintf(FSNRECs,"%d",FSNREC);
03402
03403 char *sdummy;
03404 sdummy= meinversion_version();
03405 drms_setkey_string(outRec,"CODEVER4", sdummy);
03406
03407 sdummy=" ";
03408 drms_setkey_string(outRec,"HISTORY",sdummy);
03409 sdummy="VFISV ME-inversion optimized for HMI data is described in Solar Phys. (2011) vol.273 pp.267-293, Borrero et.al. The 10 fitting parameters are eta_0,inclination,azimuth,damping,dop_width,field,vlos_mag,src_continuum,src_grad,alpha_mag";
03410 drms_setkey_string(outRec,"COMMENT",sdummy);
03411
03412 sdummy="HMI observable";
03413 drms_setkey_string(outRec,"CONTENT",sdummy);
03414
03415
03416 drms_setkey_int (outRec,"INVFREEP",keyfreep);
03417 drms_setkey_int (outRec,"INVITERA",NUM_ITERATIONS);
03418 drms_setkey_int (outRec,"INVLMBDA",NUM_LAMBDA);
03419 drms_setkey_int (outRec,"INVLMBDF",NUM_LAMBDA_FILTER);
03420 drms_setkey_int (outRec,"INVTUNEN",NUM_TUNNING);
03421 drms_setkey_double(outRec,"INVSVDTL",SVD_TOLERANCE);
03422 drms_setkey_double(outRec,"INVCHIST",CHI2_STOP);
03423 drms_setkey_double(outRec,"INVPOLTH",POLARIZATION_THRESHOLD);
03424 drms_setkey_double(outRec,"INVPJUMP",PERCENTAGE_JUMP);
03425 drms_setkey_double(outRec,"INVLMBDM",LAMBDA_MIN);
03426 drms_setkey_double(outRec,"INVLMBD0",LAMBDA_0);
03427 drms_setkey_double(outRec,"INVLMBDB",LAMBDA_B);
03428 drms_setkey_double(outRec,"INVDLTLA",DELTA_LAMBDA);
03429 drms_setkey_double(outRec,"INVLYOTW",LYOTFWHM);
03430 drms_setkey_double(outRec,"INVWNARW",WNARROW);
03431 drms_setkey_double(outRec,"INVWSPAC",WSPACING);
03432 drms_setkey_double(outRec,"INVINTTH",INTENSITY_THRESHOLD);
03433 #if NLEVPIXL == 1
03434 drms_setkey_double(outRec,"INVNFCTI",NOISE_LEVELFI);
03435 drms_setkey_double(outRec,"INVNFCTQ",NOISE_LEVELFQ);
03436 drms_setkey_double(outRec,"INVNFCTU",NOISE_LEVELFU);
03437 drms_setkey_double(outRec,"INVNFCTV",NOISE_LEVELFV);
03438 #else
03439 drms_setkey_double(outRec,"INVNOISE",NOISE_LEVEL);
03440 #endif
03441 drms_setkey_int (outRec,"INVCONTI",CONTINUUM);
03442 drms_setkey_int (outRec,"INVLMBDS",NUM_LAMBDA_synth);
03443 drms_setkey_double(outRec,"INVLMBMS",LAMBDA_MIN_synth);
03444
03445 double weighti, weightu, weightq, weightv;
03446 weighti = weights[0];
03447 weightq = weights[1];
03448 weightu = weights[2];
03449 weightv = weights[3];
03450 drms_setkey_double(outRec,"INVWGHTI",weighti);
03451 drms_setkey_double(outRec,"INVWGHTQ",weightq);
03452 drms_setkey_double(outRec,"INVWGHTU",weightu);
03453 drms_setkey_double(outRec,"INVWGHTV",weightv);
03454
03455 sdummy="No";
03456 drms_setkey_string(outRec,"INVSTLGT",sdummy);
03457 sdummy=" ";
03458 drms_setkey_string(outRec,"INVFLPRF",sdummy);
03459 sdummy=" ";
03460 drms_setkey_string(outRec,"INVPHMAP",FSNRECs);
03461
03462 drms_setkey_double(outRec,"INVVLAVE",vlos_ave);
03463 drms_setkey_double(outRec,"INVBLAVE",blos_ave);
03464 drms_setkey_double(outRec,"INVBBAVE",babs_ave);
03465 drms_setkey_int (outRec,"INVNPRCS",sum_pixdone);
03466 drms_setkey_int (outRec,"INVNCNVG",sum_pixdone-sum_pix_noconv);
03467
03468 int iqstokes;
03469 iqstokes = drms_getkey_int(inRec,"QUALITY",&status);
03470 drms_setkey_int (outRec,"QUAL_S",iqstokes);
03471 int iqinversion;
03472 iqinversion = iqstokes;
03473
03474 drms_setkey_int (outRec,"QUALITY",iqinversion);
03475
03476 stokestime = drms_getkey_time(inRec,"DATE",&status);
03477 char timestr[26];
03478 sprint_time(timestr,stokestime,"UTC",0);
03479 drms_setkey_string(outRec,"DATE_S",timestr);
03480 sprint_time(timestr,CURRENT_SYSTEM_TIME,"UTC",1);
03481 drms_setkey_string(outRec,"DATE" ,timestr);
03482
03483 sdummy=indsdesc;
03484 drms_setkey_string(outRec,"SOURCE",sdummy);
03485
03486 sdummy="n/a";
03487 drms_setkey_string(outRec,"INVKEYS1",sdummy);
03488 drms_setkey_string(outRec,"INVKEYS2",sdummy);
03489 drms_setkey_string(outRec,"INVKEYS3",sdummy);
03490 int idummy=-666;
03491 drms_setkey_int (outRec,"INVKEYI1",idummy);
03492 drms_setkey_int (outRec,"INVKEYI2",idummy);
03493 drms_setkey_int (outRec,"INVKEYI3",idummy);
03494 double ddummy=NAN;
03495 drms_setkey_double(outRec,"INVKEYD1",ddummy);
03496 drms_setkey_double(outRec,"INVKEYD2",ddummy);
03497 drms_setkey_double(outRec,"INVKEYD3",ddummy);
03498
03499 sdummy="deg";
03500 drms_setkey_string(outRec,"BUNIT_000",sdummy);
03501 drms_setkey_string(outRec,"BUNIT_001",sdummy);
03502 sdummy="Mx/cm^2";
03503 drms_setkey_string(outRec,"BUNIT_002",sdummy);
03504 sdummy="cm/s";
03505 drms_setkey_string(outRec,"BUNIT_003",sdummy);
03506 sdummy="mA";
03507 drms_setkey_string(outRec,"BUNIT_004",sdummy);
03508 sdummy="dimensionless";
03509 drms_setkey_string(outRec,"BUNIT_005",sdummy);
03510 sdummy="length units";
03511 drms_setkey_string(outRec,"BUNIT_006",sdummy);
03512 sdummy="DN/s";
03513 drms_setkey_string(outRec,"BUNIT_007",sdummy);
03514 drms_setkey_string(outRec,"BUNIT_008",sdummy);
03515 sdummy="dimensionless";
03516 drms_setkey_string(outRec,"BUNIT_009",sdummy);
03517 sdummy=" ";
03518 drms_setkey_string(outRec,"BUNIT_010",sdummy);
03519 sdummy="deg";
03520 drms_setkey_string(outRec,"BUNIT_011",sdummy);
03521 drms_setkey_string(outRec,"BUNIT_012",sdummy);
03522 sdummy="Mx/cm^2";
03523 drms_setkey_string(outRec,"BUNIT_013",sdummy);
03524 sdummy="cm/s";
03525 drms_setkey_string(outRec,"BUNIT_014",sdummy);
03526 sdummy="dimensionless";
03527 drms_setkey_string(outRec,"BUNIT_015",sdummy);
03528 sdummy=" ";
03529 drms_setkey_string(outRec,"BUNIT_016",sdummy);
03530 drms_setkey_string(outRec,"BUNIT_017",sdummy);
03531 drms_setkey_string(outRec,"BUNIT_018",sdummy);
03532 drms_setkey_string(outRec,"BUNIT_019",sdummy);
03533 drms_setkey_string(outRec,"BUNIT_020",sdummy);
03534 drms_setkey_string(outRec,"BUNIT_021",sdummy);
03535 drms_setkey_string(outRec,"BUNIT_022",sdummy);
03536 drms_setkey_string(outRec,"BUNIT_023",sdummy);
03537 drms_setkey_string(outRec,"BUNIT_024",sdummy);
03538
03539 #if ADNEWKWD == 1
03540 drms_setkey_int (outRec,"NHARP",nharp);
03541 #endif
03542
03543 #if CHNGTREC == 1
03544 drms_setkey_string(outRec, "T_REC",outtrec);
03545 #endif
03546 }
03547
03548 char trectmp2[26];
03549 TIME trectmp1 = drms_getkey_time(outRec,"T_REC",&status);
03550 sprint_time(trectmp2,trectmp1,"TAI",0);
03551 printf("to-be-created record: %s[%s] \n",outser,trectmp2);
03552
03553 printf("sending output arrays to DRMS\n");
03554
03555 for (j = 0; j < paramct; j++)
03556 {
03557 float *dat1;
03558 int axes[2];
03559
03560 #if RECTANGL == 1 || HARPATCH == 1
03561 dat1 = (float *)calloc(xwidth * yheight, sizeof(float));
03562 int icount;
03563 icount = -1;
03564 for(n = 0; n < imgpix ; n++)
03565 {
03566 int ix, iy;
03567 ix = n % cols - xleftbot; iy = n / cols - yleftbot;
03568 if ((ix >= 0) && (ix < xwidth) && (iy >= 0) && (iy < yheight))
03569 {
03570 icount = icount + 1;
03571 dat1[icount] = FinalRes[(n*paramct)+j];
03572 }
03573 }
03574 axes[0] = xwidth;
03575 axes[1] = yheight;
03576 #else
03577 dat1 = (float *)calloc(imgpix, sizeof(float));
03578 for(n = 0; n < imgpix ; n++){dat1[n] = FinalRes[(n*paramct)+j];}
03579 axes[0] = cols;
03580 axes[1] = rows;
03581 #endif
03582 invrt_array = drms_array_create (DRMS_TYPE_FLOAT, 2, axes, dat1, &status);
03583
03584 #if INTBSCLE == 1
03585 invrt_array->israw = 0;
03586 invrt_array->bzero = bzero_inv[j];
03587 invrt_array->bscale = bscaleinv[j];
03588 #endif
03589 outSeg = drms_segment_lookup (outRec, Resname[j]);
03590 if (!outSeg) {fprintf(stderr, "Error getting data segment %s; abandoned\n", Resname[j]);}
03591
03592 #if ADNEWKWD == 1
03593 set_statistics(outSeg, invrt_array, 1);
03594 #endif
03595 if (drms_segment_write (outSeg, invrt_array, 0))
03596 {
03597 fprintf (stderr, "Error writing segment %d (%s); abandoned\n", j,outSeg->info->name);
03598 return 1;
03599 }
03600 else
03601 {
03602 if (verbose){printf("Results written out to %-s\n", Resname[j]);}
03603 }
03604 free(dat1);
03605 }
03606
03607 printf("sending error arrays to DRMS\n");
03608 for (k = 0; k < Err_ct; k++)
03609 {
03610 float *dat2;
03611 int axes[2];
03612 #if RECTANGL == 1 || HARPATCH == 1
03613 dat2 = (float *)calloc(xwidth * yheight, sizeof(float));
03614 int icount;
03615 icount = -1;
03616 for(n = 0; n < imgpix ; n++)
03617 {
03618 int ix, iy;
03619 ix = n % cols - xleftbot; iy = n / cols - yleftbot;
03620 if ((ix >= 0) && (ix < xwidth) && (iy >= 0) && (iy < yheight))
03621 {
03622 icount = icount + 1;
03623 dat2[icount] = FinalErr[(n*Err_ct)+k];
03624 }
03625 }
03626 axes[0] = xwidth;
03627 axes[1] = yheight;
03628 #else
03629 dat2 = (float *)calloc(imgpix , sizeof(float));
03630 for (n=0; n < imgpix;n++){dat2[n] = FinalErr[(n*Err_ct)+k];}
03631 axes[0] = cols;
03632 axes[1] = rows;
03633 #endif
03634 err_array = drms_array_create (DRMS_TYPE_FLOAT, 2, axes, dat2,&status);
03635 #if INTBSCLE == 1
03636 err_array->israw = 0;
03637 err_array->bzero = bzero_inv[k+paramct];
03638 err_array->bscale = bscaleinv[k+paramct];
03639 #endif
03640 outSeg = drms_segment_lookup (outRec, Resname[k+paramct]);
03641 if (!outSeg)
03642 {
03643 if (verbose){fprintf(stderr, "Error getting data segment %s; abandoned\n", Resname[k+paramct]);}
03644 }
03645 else
03646 {
03647 #if ADNEWKWD == 1
03648 set_statistics(outSeg, err_array, 1);
03649 #endif
03650 if (drms_segment_write (outSeg, err_array, 0))
03651 {
03652 fprintf (stderr, "Error writing to segment %d (%s); abandoned\n", k+paramct, outSeg->info->name);
03653 return 1;
03654 }
03655 else
03656 {
03657 if (verbose){printf("Errors written out to %-s\n", Resname[k+paramct]);}
03658 }
03659 }
03660 free(dat2);
03661 }
03662
03663 printf("sending conv.flag array to DRMS\n");
03664 for (k = Err_ct; k < Err_ct + 1; k++)
03665 {
03666 char *dat3;
03667 int axes[2];
03668 #if RECTANGL == 1 || HARPATCH == 1
03669 dat3 = (char *)calloc(xwidth * yheight, sizeof(char));
03670 int icount;
03671 icount = -1;
03672 for(n = 0; n < imgpix ; n++)
03673 {
03674 int ix, iy;
03675 ix = n % cols - xleftbot; iy = n / cols - yleftbot;
03676 if ((ix >= 0) && (ix < xwidth) && (iy >= 0) && (iy < yheight))
03677 {
03678 icount = icount + 1;
03679 dat3[icount] = (char)FinalConvFlag[n];
03680 }
03681 }
03682 axes[0] = xwidth;
03683 axes[1] = yheight;
03684 #else
03685 dat3 = (char *)calloc(imgpix , sizeof(char));
03686 for (n=0; n < imgpix;n++){dat3[n] = (char)FinalConvFlag[n];}
03687 axes[0] = cols;
03688 axes[1] = rows;
03689 #endif
03690 flg_array = drms_array_create (DRMS_TYPE_CHAR, 2, axes, dat3,&status);
03691 outSeg = drms_segment_lookup (outRec, Resname[k+paramct]);
03692 if (!outSeg)
03693 {
03694 if (verbose){fprintf(stderr, "Error getting data segment %s; abandoned\n", Resname[k+paramct]);}
03695 }
03696 else
03697 {
03698 #if ADNEWKWD == 1
03699 set_statistics(outSeg, flg_array, 1);
03700 #endif
03701 if (drms_segment_write (outSeg, flg_array, 0))
03702 {
03703 fprintf (stderr, "ConvFlag writing to segment %d (%s); abandoned\n", k+paramct, outSeg->info->name);
03704 return 1;
03705 }
03706 else
03707 {
03708 if (verbose){printf("ConvFlag written out to %-s\n", Resname[k+paramct]);}
03709 }
03710 }
03711 free(dat3);
03712 }
03713
03714 printf("sending info. map array to DRMS\n");
03715 for (k = Err_ct + 1; k < Err_ct + 2; k++)
03716 {
03717 int *dat4;
03718 int axes[2];
03719 #if RECTANGL == 1 || HARPATCH == 1
03720 dat4 = (int *)calloc(xwidth * yheight, sizeof(int));
03721 int icount;
03722 icount = -1;
03723 for(n = 0; n < imgpix ; n++)
03724 {
03725 int ix, iy;
03726 ix = n % cols - xleftbot; iy = n / cols - yleftbot;
03727 if ((ix >= 0) && (ix < xwidth) && (iy >= 0) && (iy < yheight))
03728 {
03729 icount = icount + 1;
03730 dat4[icount] = FinalQualMap[n];
03731 }
03732 }
03733 axes[0] = xwidth;
03734 axes[1] = yheight;
03735 #else
03736 dat4 = (int *)calloc(imgpix , sizeof(int));
03737 for (n=0; n < imgpix;n++){dat4[n] = FinalQualMap[n];}
03738 axes[0] = cols;
03739 axes[1] = rows;
03740 #endif
03741 qmap_array = drms_array_create (DRMS_TYPE_INT, 2, axes, dat4,&status);
03742 outSeg = drms_segment_lookup (outRec, Resname[k+paramct]);
03743 if (!outSeg)
03744 {
03745 if (verbose){fprintf(stderr, "Error getting data segment %s; abandoned\n", Resname[k+paramct]);}
03746 }
03747 else
03748 {
03749 #if ADNEWKWD == 1
03750 set_statistics(outSeg, qmap_array, 1);
03751 #endif
03752 if (drms_segment_write (outSeg, qmap_array, 0))
03753 {
03754 fprintf (stderr, "QualMap writing to segment %d (%s); abandoned\n", k+paramct, outSeg->info->name);
03755 return 1;
03756 }
03757 else
03758 {
03759 if (verbose){printf("QualMap written out to %-s\n", Resname[k+paramct]);}
03760 }
03761 }
03762 free(dat4);
03763 }
03764
03765 printf("sending confidence index array to DRMS\n");
03766 for (k = Err_ct + 2; k < Err_ct + 3; k++)
03767 {
03768 char *dat5;
03769 int axes[2];
03770 #if RECTANGL == 1 || HARPATCH == 1
03771 dat5 = (char *)calloc(xwidth * yheight, sizeof(char));
03772 int icount;
03773 icount = -1;
03774 for(n = 0; n < imgpix ; n++)
03775 {
03776 int ix, iy;
03777 ix = n % cols - xleftbot; iy = n / cols - yleftbot;
03778 if ((ix >= 0) && (ix < xwidth) && (iy >= 0) && (iy < yheight))
03779 {
03780 icount = icount + 1;
03781 dat5[icount] = (char)FinalConfidMap[n];
03782 }
03783 }
03784 axes[0] = xwidth;
03785 axes[1] = yheight;
03786 #else
03787 dat5 = (char *)calloc(imgpix , sizeof(char));
03788 for (n=0; n < imgpix;n++){dat5[n] = (char)FinalConfidMap[n];}
03789 axes[0] = cols;
03790 axes[1] = rows;
03791 #endif
03792 flg_array = drms_array_create (DRMS_TYPE_CHAR, 2, axes, dat5,&status);
03793 outSeg = drms_segment_lookup (outRec, Resname[k+paramct]);
03794 if (!outSeg)
03795 {
03796 if (verbose){fprintf(stderr, "Error getting data segment %s; abandoned\n", Resname[k+paramct]);}
03797 }
03798 else
03799 {
03800 #if ADNEWKWD == 1
03801 set_statistics(outSeg, flg_array, 1);
03802 #endif
03803 if (drms_segment_write (outSeg, flg_array, 0))
03804 {
03805 fprintf (stderr, "ConfidenceIndex writing to segment %d (%s); abandoned\n", k+paramct, outSeg->info->name);
03806 return 1;
03807 }
03808 else
03809 {
03810 if (verbose){printf("ConfidenceIndex written out to %-s\n", Resname[k+paramct]);}
03811 }
03812 }
03813 free(dat5);
03814 }
03815
03816 printf("write-out done !\n");
03817
03818 free(FinalErr);
03819 free(FinalRes);
03820 free(FinalConvFlag);
03821 free(FinalQualMap);
03822 free(FinalConfidMap);
03823
03824 printf("so, close all DRMS record(s) !\n");
03825
03826 drms_close_record (outRec, DRMS_INSERT_RECORD);
03827 drms_close_records (inRS, DRMS_FREE_RECORD);
03828
03829
03830 time(&endtime);
03831 printf ("%ld sec for %d profiles\n", endtime - startime, sum_pixdone);
03832 printf ("%.2f profiles per second\n", (float)(sum_pixdone) / (0.01 + (float)(endtime - startime)));
03833
03834 printf("good bye !\n");
03835 }
03836
03837 MPI_Barrier(MPI_COMM_WORLD);
03838
03839
03840 MPI_Finalize();
03841
03842 return 0;
03843 }
03844
03845
03846
03847
03848
03849
03850
03851
03852
03853
03854
03855
03856
03857
03858
03859 void para_range(int myrank, int nprocs, int numpix, int *istart, int *iend)
03860 {
03861 int iwork1, iwork2, imin, idummy, n1, n2;
03862 n1 = 0;
03863 n2 = numpix - 1;
03864
03865 iwork1 = (n2 - n1 + 1) / nprocs;
03866 iwork2 = (n2 - n1 + 1) % nprocs;
03867 if (iwork2 >= myrank){imin = myrank;}else{imin=iwork2;}
03868 *istart = myrank*iwork1 + n1 + imin;
03869 idummy = *istart + iwork1 - 1;
03870 if (iwork2 <= myrank){*iend = idummy;}else{*iend=idummy+1;}
03871 }
03872
03873
03874
03875
03876
03877
03878
03879
03880
03881 void lininterp1f(double *yinterp, double *xv, double *yv, double *x, double ydefault, int m, int minterp)
03882 {
03883 int i, j;
03884 int nrowsinterp, nrowsdata;
03885 nrowsinterp = minterp;
03886 nrowsdata = m;
03887 for (i=0; i<nrowsinterp; i++)
03888 {
03889 if((x[i] < xv[0]) || (x[i] > xv[nrowsdata-1]))
03890 yinterp[i] = ydefault;
03891 else
03892 { for(j=1; j<nrowsdata; j++)
03893 { if(x[i]<=xv[j])
03894 { yinterp[i] = (x[i]-xv[j-1]) / (xv[j]-xv[j-1]) * (yv[j]-yv[j-1]) + yv[j-1];
03895 break;
03896 }
03897 }
03898 }
03899 }
03900 }
03901
03902
03903
03904
03905
03906
03907 int initialize_vfisv_filter(double *wavelengthd,double *frontwindowd,int *nfront,double *wavelengthbd,double *blockerbd,int *nblocker,double *centerblocker,double *phaseNT,double *phaseT,double *contrastNT,double *contrastT,double *FSR,double *lineref,double *wavelengthref,int *referencenlam,int *HCME1,int *HCMWB,int *HCMNB,int *HCMPOL,TIME t_rec,int *FSNREC)
03908 {
03909
03910 printf("INSIDE initialize_vfisv_filter\n");
03911
03912 int status=1;
03913 int nx2=128,ny2=128;
03914 int nelemPHASENT =4*nx2*ny2;
03915 int nelemCONTRASTT=3*nx2*nx2;
03916 int nread,i,ii,jj;
03917 int status2=0;
03918 char inRecQuery[256];
03919 char query[256];
03920 int nRecs;
03921 DRMS_RecordSet_t *data= NULL;
03922 char *keyname="HCAMID";
03923 int keyvalue;
03924 int recofinterest;
03925 FILE *fp=NULL;
03926 int FSNphasemaps=0;
03927 int camera=2;
03928
03929
03930 FILE *filePhaseMaps=NULL;
03931 char line[256];
03932 float tstart=0.0;
03933
03934 filePhaseMaps=fopen("/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/filePhaseMaps.txt", "r");
03935 if(filePhaseMaps == NULL)
03936 {
03937 printf("The file filePhaseMaps.txt does not exist\n");
03938 return 1;
03939 }
03940
03941 while(fgets(line,256,filePhaseMaps) != NULL)
03942 {
03943 sscanf(line,"%f %d",&tstart,&status2);
03944 if(t_rec > tstart) FSNphasemaps=status2;
03945 }
03946 if(FSNphasemaps == 0)
03947 {
03948 printf("Could not find a HMI filter phase map in initialize_vfisv_filter\n");
03949 return 1;
03950 }
03951 status2=0;
03952 fclose(filePhaseMaps);
03953
03954
03955
03956
03957
03958
03959
03960 *FSNREC=FSNphasemaps;
03961
03962
03963 *centerblocker=2.7;
03964 FSR[0]=0.1689;
03965 FSR[1]=0.33685;
03966 FSR[2]=0.695;
03967 FSR[3]=1.417;
03968 FSR[4]=2.779;
03969 FSR[5]=5.682;
03970 FSR[6]=11.354;
03971
03972 *referencenlam=7000;
03973 *nblocker=201;
03974 *nfront=401;
03975
03976 char filephasesnontunable[]="/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/non_tunable_phases_710660_June09_cal_128_2.bin";
03977 char filecontrastsnontunable[]="/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/non_tunable_contrasts_710660_June09_cal_128_2.bin";
03978 char filecontraststunable[]="/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/tunable_contrasts_710660_June09_cal_128.bin";
03979
03980 char referencesolarline[]="/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/ReferenceFeLine.bin";
03981 char referencewavelength[]="/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/ReferenceWavelength.bin" ;
03982
03983
03984 float templineref[*referencenlam];
03985 float tempwavelengthref[*referencenlam];
03986
03987 fp = fopen(referencesolarline,"rb");
03988 fread(templineref,sizeof(float),*referencenlam,fp);
03989 fclose(fp);
03990
03991 fp = fopen(referencewavelength,"rb");
03992 fread(tempwavelengthref,sizeof(float),*referencenlam,fp);
03993 fclose(fp);
03994
03995 for(i=0;i<*referencenlam;++i)
03996 {
03997 lineref[i]=(double)templineref[i];
03998 wavelengthref[i]=(double)tempwavelengthref[i];
03999 }
04000
04001
04002
04003 printf("READ PHASES OF NON-TUNABLE ELEMENTS\n");
04004 fp = fopen(filephasesnontunable,"rb");
04005 if(fp == NULL)
04006 {
04007 printf("Error: CANNOT OPEN FILE OF NON-TUNABLE ELEMENT PHASES\n");
04008 return status;
04009 }
04010
04011 float phaseNTf[nelemPHASENT];
04012 nread=fread(phaseNTf,sizeof(float),nelemPHASENT,fp);
04013 fclose(fp);
04014 for(i=0;i<nelemPHASENT;++i) phaseNT[i] = (double)phaseNTf[i]*M_PI/180.;
04015
04016 printf("READ CONTRASTS OF NON-TUNABLE ELEMENTS\n");
04017 fp = fopen(filecontrastsnontunable,"rb");
04018 if(fp == NULL)
04019 {
04020 printf("Error: CANNOT OPEN FILE OF NON-TUNABLE ELEMENT CONTRASTS\n");
04021 return status;
04022 }
04023
04024 float contrastNTf[nelemPHASENT];
04025 nread=fread(contrastNTf,sizeof(float),nelemPHASENT,fp);
04026 fclose(fp);
04027 for(i=0;i<nelemPHASENT;++i) contrastNT[i]=(double)contrastNTf[i];
04028
04029
04030 printf("READ CONTRASTS OF TUNABLE ELEMENTS\n");
04031 fp = fopen(filecontraststunable,"rb");
04032 if(fp == NULL)
04033 {
04034 printf("Eeror: CANNOT OPEN FILE OF NON-TUNABLE ELEMENT PHASES\n");
04035 return status;
04036 }
04037
04038 float contrastTf[nelemCONTRASTT];
04039 nread=fread(contrastTf,sizeof(float),nelemCONTRASTT,fp);
04040 fclose(fp);
04041 for(i=0;i<nelemCONTRASTT;++i) contrastT[i]=(double)contrastTf[i];
04042
04043
04044
04045
04046 double wbd[201]={6150.00,6150.20,6150.40,6150.60,6150.80,6151.00,6151.20,6151.40,6151.60,6151.80,6152.00,6152.20,6152.40,6152.60,6152.80,6153.00,6153.20,6153.40,6153.60,6153.80,6154.00,6154.20,6154.40,6154.60,6154.80,6155.00,6155.20,6155.40,6155.60,6155.80,6156.00,6156.20,6156.40,6156.60,6156.80,6157.00,6157.20,6157.40,6157.60,6157.80,6158.00,6158.20,6158.40,6158.60,6158.80,6159.00,6159.20,6159.40,6159.60,6159.80,6160.00,6160.20,6160.40,6160.60,6160.80,6161.00,6161.20,6161.40,6161.60,6161.80,6162.00,6162.20,6162.40,6162.60,6162.80,6163.00,6163.20,6163.40,6163.60,6163.80,6164.00,6164.20,6164.40,6164.60,6164.80,6165.00,6165.20,6165.40,6165.60,6165.80,6166.00,6166.20,6166.40,6166.60,6166.80,6167.00,6167.20,6167.40,6167.60,6167.80,6168.00,6168.20,6168.40,6168.60,6168.80,6169.00,6169.20,6169.40,6169.60,6169.80,6170.00,6170.20,6170.40,6170.60,6170.80,6171.00,6171.20,6171.40,6171.60,6171.80,6172.00,6172.20,6172.40,6172.60,6172.80,6173.00,6173.20,6173.40,6173.60,6173.80,6174.00,6174.20,6174.40,6174.60,6174.80,6175.00,6175.20,6175.40,6175.60,6175.80,6176.00,6176.20,6176.40,6176.60,6176.80,6177.00,6177.20,6177.40,6177.60,6177.80,6178.00,6178.20,6178.40,6178.60,6178.80,6179.00,6179.20,6179.40,6179.60,6179.80,6180.00,6180.20,6180.40,6180.60,6180.80,6181.00,6181.20,6181.40,6181.60,6181.80,6182.00,6182.20,6182.40,6182.60,6182.80,6183.00,6183.20,6183.40,6183.60,6183.80,6184.00,6184.20,6184.40,6184.60,6184.80,6185.00,6185.20,6185.40,6185.60,6185.80,6186.00,6186.20,6186.40,6186.60,6186.80,6187.00,6187.20,6187.40,6187.60,6187.80,6188.00,6188.20,6188.40,6188.60,6188.80,6189.00,6189.20,6189.40,6189.60,6189.80,6190.00};
04047
04048 double bld[201]={0.0701790,0.0723149,0.0747684,0.0713996,0.0782131,0.0758304,0.0789970,0.0762436,0.0806648,0.0828427,0.0801553,0.0830996,0.0882834,0.0885202,0.0869452,0.0877748,0.0974292,0.0942963,0.0968998,0.0961026,0.100459,0.104028,0.102757,0.107549,0.111349,0.120277,0.117723,0.127142,0.125108,0.135901,0.146540,0.148481,0.151049,0.161267,0.173912,0.191953,0.204322,0.227430,0.239466,0.255259,0.272536,0.311694,0.341673,0.356651,0.409127,0.452214,0.535866,0.614547,0.667113,0.740491,0.847670,0.958023,1.05927,1.19029,1.33457,1.51771,1.90178,2.28149,2.49949,2.80167,3.20520,3.85124,4.35895,4.98798,5.73421,6.53362,8.32412,9.85849,10.6749,12.2367,13.5532,16.0578,17.5336,19.9408,21.4035,26.3633,28.4878,31.9405,33.4455,36.0767,38.4715,42.1947,44.3560,46.8881,49.1468,51.3640,54.9618,57.0772,58.2497,59.3955,60.7570,62.1459,62.7333,63.6812,64.1301,64.7157,65.1849,65.6286,65.4660,65.5828,65.4650,65.4184,65.0766,64.7526,64.0896,63.4954,62.1029,60.4464,59.8266,58.1582,57.0750,54.6480,53.1968,51.1148,49.0429,46.5159,42.3256,38.8035,37.2384,34.5975,32.0762,28.5152,26.2661,23.6695,21.7173,17.3033,15.3031,13.0296,11.8265,10.3604,9.23128,7.53426,6.70699,5.79359,4.97535,4.35803,3.27063,2.70147,2.42119,2.11748,1.83017,1.53329,1.34299,1.19612,1.02633,0.915612,0.711036,0.622389,0.575185,0.507517,0.450262,0.401576,0.365934,0.322949,0.286864,0.272241,0.232461,0.207537,0.189114,0.173546,0.161978,0.152099,0.134795,0.123677,0.110288,0.108344,0.0948288,0.0818621,0.0804488,0.0753219,0.0693417,0.0643225,0.0620898,0.0559437,0.0540745,0.0485797,0.0486797,0.0432530,0.0439143,0.0401164,0.0367754,0.0359879,0.0343058,0.0336281,0.0330711,0.0339798,0.0271329,0.0281424,0.0299408,0.0264017,0.0278133,0.0250958,0.0248676,0.0223389,0.0238825,0.0259792,0.0226330,0.0204282,0.0209307,0.0207487,0.0209464};
04049
04050 for(i=0;i<201;++i)
04051 {
04052 wavelengthbd[i]=wbd[i];
04053 blockerbd[i]=bld[i];
04054 }
04055
04056
04057
04058
04059 double wd[401]={607.300,607.350,607.400,607.450,607.500,607.550,607.600,607.650,607.700,607.750,607.800,607.850,607.900,607.950,608.000,608.050,608.100,608.150,608.200,608.250,608.300,608.350,608.400,608.450,608.500,608.550,608.600,608.650,608.700,608.750,608.800,608.850,608.900,608.950,609.000,609.050,609.100,609.150,609.200,609.250,609.300,609.350,609.400,609.450,609.500,609.550,609.600,609.650,609.700,609.750,609.800,609.850,609.900,609.950,610.000,610.050,610.100,610.150,610.200,610.250,610.300,610.350,610.400,610.450,610.500,610.550,610.600,610.650,610.700,610.750,610.800,610.850,610.900,610.950,611.000,611.050,611.100,611.150,611.200,611.250,611.300,611.350,611.400,611.450,611.500,611.550,611.600,611.650,611.700,611.750,611.800,611.850,611.900,611.950,612.000,612.050,612.100,612.150,612.200,612.250,612.300,612.350,612.400,612.450,612.500,612.550,612.600,612.650,612.700,612.750,612.800,612.850,612.900,612.950,613.000,613.050,613.100,613.150,613.200,613.250,613.300,613.350,613.400,613.450,613.500,613.550,613.600,613.650,613.700,613.750,613.800,613.850,613.900,613.950,614.000,614.050,614.100,614.150,614.200,614.250,614.300,614.350,614.400,614.450,614.500,614.550,614.600,614.650,614.700,614.750,614.800,614.850,614.900,614.950,615.000,615.050,615.100,615.150,615.200,615.250,615.300,615.350,615.400,615.450,615.500,615.550,615.600,615.650,615.700,615.750,615.800,615.850,615.900,615.950,616.000,616.050,616.100,616.150,616.200,616.250,616.300,616.350,616.400,616.450,616.500,616.550,616.600,616.650,616.700,616.750,616.800,616.850,616.900,616.950,617.000,617.050,617.100,617.150,617.200,617.250,617.300,617.350,617.400,617.450,617.500,617.550,617.600,617.650,617.700,617.750,617.800,617.850,617.900,617.950,618.000,618.050,618.100,618.150,618.200,618.250,618.300,618.350,618.400,618.450,618.500,618.550,618.600,618.650,618.700,618.750,618.800,618.850,618.900,618.950,619.000,619.050,619.100,619.150,619.200,619.250,619.300,619.350,619.400,619.450,619.500,619.550,619.600,619.650,619.700,619.750,619.800,619.850,619.900,619.950,620.000,620.050,620.100,620.150,620.200,620.250,620.300,620.350,620.400,620.450,620.500,620.550,620.600,620.650,620.700,620.750,620.800,620.850,620.900,620.950,621.000,621.050,621.100,621.150,621.200,621.250,621.300,621.350,621.400,621.450,621.500,621.550,621.600,621.650,621.700,621.750,621.800,621.850,621.900,621.950,622.000,622.050,622.100,622.150,622.200,622.250,622.300,622.350,622.400,622.450,622.500,622.550,622.600,622.650,622.700,622.750,622.800,622.850,622.900,622.950,623.000,623.050,623.100,623.150,623.200,623.250,623.300,623.350,623.400,623.450,623.500,623.550,623.600,623.650,623.700,623.750,623.800,623.850,623.900,623.950,624.000,624.050,624.100,624.150,624.200,624.250,624.300,624.350,624.400,624.450,624.500,624.550,624.600,624.650,624.700,624.750,624.800,624.850,624.900,624.950,625.000,625.050,625.100,625.150,625.200,625.250,625.300,625.350,625.400,625.450,625.500,625.550,625.600,625.650,625.700,625.750,625.800,625.850,625.900,625.950,626.000,626.050,626.100,626.150,626.200,626.250,626.300,626.350,626.400,626.450,626.500,626.550,626.600,626.650,626.700,626.750,626.800,626.850,626.900,626.950,627.000,627.050,627.100,627.150,627.200,627.250,627.300};
04060
04061 double fd[401]={0.0824,0.0939,0.0787,0.1035,0.0712,0.0794,0.1009,0.0841,0.0889,0.0439,0.0884,0.1057,0.1161,0.0858,0.0717,0.1085,0.0939,0.1030,0.1027,0.0805,0.0831,0.1088,0.1005,0.0767,0.0920,0.0755,0.0862,0.1045,0.1125,0.1068,0.0964,0.1106,0.1134,0.0919,0.1147,0.1105,0.1171,0.1166,0.0975,0.1113,0.1094,0.1317,0.1379,0.1335,0.1444,0.1323,0.1103,0.1487,0.1564,0.1551,0.1550,0.1705,0.1672,0.1258,0.1330,0.1428,0.1620,0.1656,0.1843,0.1940,0.1811,0.1908,0.1628,0.1760,0.2049,0.1959,0.2186,0.2341,0.2504,0.2322,0.2292,0.2409,0.2355,0.2490,0.2984,0.2840,0.2854,0.2927,0.2823,0.3015,0.3269,0.3337,0.3787,0.3949,0.3853,0.3833,0.4298,0.4670,0.4692,0.4981,0.5129,0.5428,0.5865,0.6077,0.6290,0.6324,0.7459,0.7480,0.8150,0.8657,0.8920,0.9285,1.0100,1.0616,1.1343,1.2479,1.2852,1.3584,1.4890,1.5699,1.6990,1.8128,1.9565,2.1121,2.2822,2.4738,2.6485,2.9025,3.1073,3.3880,3.6499,3.9427,4.3108,4.6652,4.9989,5.5283,5.9813,6.5033,7.1314,7.7739,8.3984,9.1871,10.0736,10.8755,11.9132,13.0402,13.9753,15.3119,16.5884,17.9287,19.5970,21.4054,22.8304,24.9109,27.0054,28.6829,30.9226,33.2495,35.3898,37.8594,40.3831,42.7200,44.9671,47.5569,49.9864,52.2030,54.7069,57.0780,58.8828,60.8594,62.6620,64.4119,66.2320,68.2963,69.4221,70.8045,72.2034,73.4397,74.4796,75.5385,76.0362,76.8120,77.7408,78.4357,78.7422,79.3253,79.8358,80.3452,80.8023,80.7372,81.0416,81.5797,81.9136,82.0703,82.4872,82.4652,82.5696,82.6470,82.7640,82.8444,82.7465,82.4404,82.6908,82.8926,83.1894,83.3542,83.3569,83.2381,83.3289,83.2983,83.3072,83.4495,83.3260,83.3259,83.2807,83.1566,83.0003,82.8881,82.8700,83.2338,83.6685,83.5310,83.3660,83.4200,83.4753,83.5535,83.4297,83.5024,83.3255,83.3739,83.2229,83.0138,82.7990,83.0881,82.8699,82.5380,82.4950,82.2752,81.6813,81.0162,80.4859,79.8935,79.0734,78.1775,77.1055,75.6790,73.7593,72.1025,70.1430,67.8169,65.3109,62.7376,59.8977,56.6526,53.3823,50.7530,47.4383,43.8974,40.5806,37.9460,34.8128,31.9024,29.1972,26.9859,24.4400,22.1973,20.2288,18.4441,16.6123,14.9844,13.5245,12.4264,11.2253,10.1547,9.2421,8.5064,7.7160,6.9712,6.3549,5.8530,5.3515,4.8613,4.4704,4.1431,3.7857,3.4459,3.1822,2.9684,2.7397,2.5416,2.3371,2.1395,2.0216,1.8965,1.7565,1.6370,1.5414,1.4241,1.3505,1.2548,1.1747,1.1431,1.0586,0.9672,0.9421,0.8876,0.8538,0.8146,0.7764,0.7325,0.6940,0.6494,0.6119,0.6018,0.5367,0.5330,0.5568,0.5291,0.4903,0.4759,0.4601,0.4422,0.3874,0.3670,0.3589,0.3565,0.3655,0.3273,0.3272,0.3035,0.3008,0.3135,0.2618,0.2653,0.2760,0.2466,0.2407,0.2260,0.2107,0.2255,0.2064,0.2066,0.1937,0.1648,0.1614,0.1906,0.1738,0.1403,0.1535,0.1480,0.1581,0.1243,0.1326,0.1140,0.1280,0.1621,0.1404,0.1348,0.1110,0.1075,0.1022,0.1140,0.1186,0.1072,0.1250,0.1132,0.1193,0.0794,0.0808,0.0930,0.0886,0.0693,0.0934,0.0827,0.0644,0.0723,0.0732,0.0574,0.0606,0.0555,0.0536,0.0540,0.0625,0.0444,0.0616,0.0663,0.0506,0.0506,0.0492,0.0294,0.0661,0.0511,0.0556,0.0188,0.0257,0.0414,0.0484,0.0167,0.0341,0.0216,0.0269,0.0308,0.0451,0.0700,0.0326,0.0110,0.0288,0.0414,0.0225,0.0119,0.0509};
04062
04063 for(i=0;i<401;++i)
04064 {
04065 wavelengthd[i]=wd[i];
04066 frontwindowd[i]=fd[i];
04067 }
04068
04069
04070
04071 strcpy(inRecQuery,"hmi.phasemaps_corrected[");
04072 sprintf(query,"%d",FSNphasemaps);
04073 strcat(inRecQuery,query);
04074 strcat(inRecQuery,"]");
04075
04076 printf("Phase-map query = %s\n",inRecQuery);
04077
04078 data = drms_open_records(drms_env,inRecQuery,&status2);
04079
04080 if (status2 == DRMS_SUCCESS && data != NULL && data->n > 0)
04081 {
04082 nRecs = data->n;
04083 printf("Number of phase-map satisfying the request= %d \n",nRecs);
04084 }
04085 else
04086 {
04087 printf("Input phase-map series %s doesn't exist\n",inRecQuery);
04088 return status;
04089 }
04090
04091 DRMS_Segment_t *segin = NULL;
04092 DRMS_Array_t *arrin = NULL;
04093 float *tempphase = NULL;
04094
04095
04096 i=0;
04097 while(i<nRecs)
04098 {
04099 keyvalue = drms_getkey_int(data->records[i],keyname,&status2);
04100 if(status2 != 0)
04101 {
04102 printf("Error: unable to read keyword %s\n",keyname);
04103 return status;
04104 }
04105 if(keyvalue == camera)
04106 {
04107 recofinterest=i;
04108 break;
04109 }
04110 i++;
04111 }
04112 if(i == nRecs)
04113 {
04114 printf("Error: no phase-map record was found with the proper FSN_REC and HCAMID\n");
04115 return status;
04116 }
04117
04118 segin = drms_segment_lookupnum(data->records[recofinterest],0);
04119 arrin = drms_segment_read(segin,segin->info->type,&status2);
04120 if(status2 != DRMS_SUCCESS)
04121 {
04122 printf("Error: unable to read a data segment\n");
04123 return status;
04124 }
04125 tempphase = arrin->data;
04126
04127 for(i=0;i<nelemCONTRASTT;++i)
04128 {
04129 ii=i / 3;
04130 jj=i % 3;
04131 phaseT[i] = (double)tempphase[ii*5+jj]*M_PI/180.;
04132 }
04133
04134 *HCMNB=drms_getkey_int(data->records[recofinterest],"HCMNB",&status2);
04135 if(status2 != DRMS_SUCCESS)
04136 {
04137 printf("Error: could not read HMCNB\n");
04138 return status;
04139 }
04140 *HCMWB=drms_getkey_int(data->records[recofinterest],"HCMWB",&status2);
04141 if(status2 != DRMS_SUCCESS)
04142 {
04143 printf("Error: could not read HMCWB\n");
04144 return status;
04145 }
04146 *HCME1=drms_getkey_int(data->records[recofinterest],"HCME1",&status2);
04147 if(status2 != DRMS_SUCCESS)
04148 {
04149 printf("Error: could not read HMCE1\n");
04150 return status;
04151 }
04152 *HCMPOL=0;
04153
04154
04155 drms_free_array(arrin);
04156 drms_close_records(data,DRMS_FREE_RECORD);
04157
04158
04159 status=0;
04160
04161 return status;
04162
04163 }
04164
04165
04166
04167
04168
04169
04170
04171
04172
04173
04174
04175
04176
04177
04178
04179
04180
04181
04182
04183
04184
04185
04186
04187
04188
04189
04190
04191
04192
04193
04194
04195
04196
04197
04198
04199 int vfisv_filter(int Num_lambda_filter,int Num_lambda,double filters[Num_lambda_filter][Num_lambda],double Lambda_Min,double Delta_Lambda,double *wavelengthd,double *frontwindowd,int nfront,double *wavelengthbd,double *blockerbd,int nblocker,double centerblocker,double phaseNTi[4],double phaseTi[3],double contrastNTi[4],double contrastTi[3],double *FSR,double *lineref,double *wavelengthref,int referencenlam,double distance,int HCME1,int HCMWB,int HCMNB,int HCMPOL)
04200 {
04201
04202 int status=1;
04203
04204 if(Num_lambda_filter != 5 && Num_lambda_filter != 6 && Num_lambda_filter != 8 && Num_lambda_filter != 10)
04205 {
04206 printf("Error: the number of wavelengths should be either 5, 6, 8, or 10\n");
04207 return status;
04208 }
04209
04210 double lam0 = 6173.3433;
04211 double lineprofile[Num_lambda],wavelength[Num_lambda];
04212 double lineprofile2[referencenlam],wavelength2[referencenlam];
04213 double ydefault = 1.;
04214 double ydefault2= 0.;
04215 int i,j;
04216
04217 double *HCME1phase=NULL,*HCMWBphase=NULL,*HCMNBphase=NULL;
04218 double frontwindowint[Num_lambda];
04219 double blockerint[Num_lambda];
04220 double lyot[Num_lambda];
04221 double FWHM,minimum;
04222
04223
04224
04225 for(i=0;i<Num_lambda;++i) wavelength[i]= Lambda_Min/1000.0 + (double)i*Delta_Lambda/1000.0;
04226
04227
04228
04229 #if 0
04230 for(i=0;i<nfront;++i)
04231 {
04232 wavelengthd[i]=wavelengthd[i]*10.0-lam0;
04233 frontwindowd[i]=frontwindowd[i]/100.0;
04234 }
04235 for(i=0;i<nblocker;++i)
04236 {
04237 wavelengthbd[i]=wavelengthbd[i]+centerblocker-lam0;
04238 blockerbd[i]=blockerbd[i]/100.0;
04239 }
04240 lininterp1f(frontwindowint,wavelengthd,frontwindowd,wavelength,ydefault2,nfront,Num_lambda);
04241 lininterp1f(blockerint,wavelengthbd,blockerbd,wavelength,ydefault2,nblocker,Num_lambda);
04242 #else
04243
04244
04245 double *wavelengthdtmp, *wavelengthbdtmp, *frontwindowdtmp, *blockerbdtmp;
04246 blockerbdtmp=(double *)malloc(201*sizeof(double));
04247 wavelengthbdtmp=(double *)malloc(201*sizeof(double));
04248 wavelengthdtmp=(double *)malloc(401*sizeof(double));
04249 frontwindowdtmp=(double *)malloc(401*sizeof(double));
04250
04251 for(i=0;i<nfront;++i)
04252 {
04253 wavelengthdtmp[i]=wavelengthd[i]*10.0-lam0;
04254 frontwindowdtmp[i]=frontwindowd[i]/100.0;
04255 }
04256 for(i=0;i<nblocker;++i)
04257 {
04258 wavelengthbdtmp[i]=wavelengthbd[i]+centerblocker-lam0;
04259 blockerbdtmp[i]=blockerbd[i]/100.0;
04260 }
04261
04262
04263 lininterp1f(frontwindowint,wavelengthdtmp, frontwindowdtmp,wavelength,ydefault2,nfront, Num_lambda);
04264 lininterp1f(blockerint, wavelengthbdtmp,blockerbdtmp, wavelength,ydefault2,nblocker,Num_lambda);
04265
04266 free(blockerbdtmp);
04267 free(wavelengthbdtmp);
04268 free(wavelengthdtmp);
04269 free(frontwindowdtmp);
04270 #endif
04271
04272
04273 for(j=0;j<Num_lambda;++j) {
04274 blockerint[j]=blockerint[j]*frontwindowint[j];
04275 }
04276
04277
04278
04279 HCME1phase = (double *) malloc(Num_lambda_filter*sizeof(double));
04280 if(HCME1phase == NULL)
04281 {
04282 printf("Error: no memory allocated to HCME1phase\n");
04283 exit(EXIT_FAILURE);
04284 }
04285 HCMWBphase = (double *) malloc(Num_lambda_filter*sizeof(double));
04286 if(HCMWBphase == NULL)
04287 {
04288 printf("Error: no memory allocated to HCMWBphase\n");
04289 exit(EXIT_FAILURE);
04290 }
04291 HCMNBphase = (double *) malloc(Num_lambda_filter*sizeof(double));
04292 if(HCMNBphase == NULL)
04293 {
04294 printf("Error: no memory allocated to HCMNBphase\n");
04295 exit(EXIT_FAILURE);
04296 }
04297 if(Num_lambda_filter == 6)
04298 {
04299 HCME1phase[5]= (double) ((HCME1+15)*6 % 360)*M_PI/180.0;
04300 HCME1phase[4]= (double) ((HCME1+9 )*6 % 360)*M_PI/180.0;
04301 HCME1phase[3]= (double) ((HCME1+3 )*6 % 360)*M_PI/180.0;
04302 HCME1phase[2]= (double) ((HCME1-3 )*6 % 360)*M_PI/180.0;
04303 HCME1phase[1]= (double) ((HCME1-9 )*6 % 360)*M_PI/180.0;
04304 HCME1phase[0]= (double) ((HCME1-15)*6 % 360)*M_PI/180.0;
04305
04306 HCMWBphase[5]= (double) ((HCMWB-30)*6 % 360)*M_PI/180.0;
04307 HCMWBphase[4]= (double) ((HCMWB-18)*6 % 360)*M_PI/180.0;
04308 HCMWBphase[3]= (double) ((HCMWB-6 )*6 % 360)*M_PI/180.0;
04309 HCMWBphase[2]= (double) ((HCMWB+6 )*6 % 360)*M_PI/180.0;
04310 HCMWBphase[1]= (double) ((HCMWB+18)*6 % 360)*M_PI/180.0;
04311 HCMWBphase[0]= (double) ((HCMWB-30)*6 % 360)*M_PI/180.0;
04312
04313 HCMNBphase[5]= (double) ((HCMNB-0 )*6 % 360)*M_PI/180.0;
04314 HCMNBphase[4]= (double) ((HCMNB+24)*6 % 360)*M_PI/180.0;
04315 HCMNBphase[3]= (double) ((HCMNB-12)*6 % 360)*M_PI/180.0;
04316 HCMNBphase[2]= (double) ((HCMNB+12)*6 % 360)*M_PI/180.0;
04317 HCMNBphase[1]= (double) ((HCMNB-24)*6 % 360)*M_PI/180.0;
04318 HCMNBphase[0]= (double) ((HCMNB+0 )*6 % 360)*M_PI/180.0;
04319 }
04320 if(Num_lambda_filter == 5)
04321 {
04322 HCME1phase[4]= (double) ((HCME1+12)*6 % 360)*M_PI/180.0;
04323 HCME1phase[3]= (double) ((HCME1+6 )*6 % 360)*M_PI/180.0;
04324 HCME1phase[2]= (double) ((HCME1+0 )*6 % 360)*M_PI/180.0;
04325 HCME1phase[1]= (double) ((HCME1-6 )*6 % 360)*M_PI/180.0;
04326 HCME1phase[0]= (double) ((HCME1-12)*6 % 360)*M_PI/180.0;
04327
04328 HCMWBphase[4]= (double) ((HCMWB-24)*6 % 360)*M_PI/180.0;
04329 HCMWBphase[3]= (double) ((HCMWB-12)*6 % 360)*M_PI/180.0;
04330 HCMWBphase[2]= (double) ((HCMWB+0 )*6 % 360)*M_PI/180.0;
04331 HCMWBphase[1]= (double) ((HCMWB+12)*6 % 360)*M_PI/180.0;
04332 HCMWBphase[0]= (double) ((HCMWB+24)*6 % 360)*M_PI/180.0;
04333
04334 HCMNBphase[4]= (double) ((HCMNB+12)*6 % 360)*M_PI/180.0;
04335 HCMNBphase[3]= (double) ((HCMNB-24)*6 % 360)*M_PI/180.0;
04336 HCMNBphase[2]= (double) ((HCMNB+0 )*6 % 360)*M_PI/180.0;
04337 HCMNBphase[1]= (double) ((HCMNB+24)*6 % 360)*M_PI/180.0;
04338 HCMNBphase[0]= (double) ((HCMNB-12)*6 % 360)*M_PI/180.0;
04339 }
04340 if(Num_lambda_filter == 8)
04341 {
04342 HCME1phase[7]= (double) ((HCME1+21)*6 % 360)*M_PI/180.0;
04343 HCME1phase[6]= (double) ((HCME1+15)*6 % 360)*M_PI/180.0;
04344 HCME1phase[5]= (double) ((HCME1+9 )*6 % 360)*M_PI/180.0;
04345 HCME1phase[4]= (double) ((HCME1+3 )*6 % 360)*M_PI/180.0;
04346 HCME1phase[3]= (double) ((HCME1-3 )*6 % 360)*M_PI/180.0;
04347 HCME1phase[2]= (double) ((HCME1-9 )*6 % 360)*M_PI/180.0;
04348 HCME1phase[1]= (double) ((HCME1-15)*6 % 360)*M_PI/180.0;
04349 HCME1phase[0]= (double) ((HCME1-21)*6 % 360)*M_PI/180.0;
04350
04351 HCMWBphase[7]= (double) ((HCMWB+18)*6 % 360)*M_PI/180.0;
04352 HCMWBphase[6]= (double) ((HCMWB-30)*6 % 360)*M_PI/180.0;
04353 HCMWBphase[5]= (double) ((HCMWB-18)*6 % 360)*M_PI/180.0;
04354 HCMWBphase[4]= (double) ((HCMWB-6 )*6 % 360)*M_PI/180.0;
04355 HCMWBphase[3]= (double) ((HCMWB+6 )*6 % 360)*M_PI/180.0;
04356 HCMWBphase[2]= (double) ((HCMWB+18)*6 % 360)*M_PI/180.0;
04357 HCMWBphase[1]= (double) ((HCMWB-30)*6 % 360)*M_PI/180.0;
04358 HCMWBphase[0]= (double) ((HCMWB-18)*6 % 360)*M_PI/180.0;
04359
04360 HCMNBphase[7]= (double) ((HCMNB-24)*6 % 360)*M_PI/180.0;
04361 HCMNBphase[6]= (double) ((HCMNB-0 )*6 % 360)*M_PI/180.0;
04362 HCMNBphase[5]= (double) ((HCMNB+24)*6 % 360)*M_PI/180.0;
04363 HCMNBphase[4]= (double) ((HCMNB-12)*6 % 360)*M_PI/180.0;
04364 HCMNBphase[3]= (double) ((HCMNB+12)*6 % 360)*M_PI/180.0;
04365 HCMNBphase[2]= (double) ((HCMNB-24)*6 % 360)*M_PI/180.0;
04366 HCMNBphase[1]= (double) ((HCMNB+0 )*6 % 360)*M_PI/180.0;
04367 HCMNBphase[0]= (double) ((HCMNB+24 )*6 % 360)*M_PI/180.0;
04368 }
04369 if(Num_lambda_filter == 10)
04370 {
04371 HCME1phase[9]= (double) ((HCME1+27)*6 % 360)*M_PI/180.0;
04372 HCME1phase[8]= (double) ((HCME1+21)*6 % 360)*M_PI/180.0;
04373 HCME1phase[7]= (double) ((HCME1+15)*6 % 360)*M_PI/180.0;
04374 HCME1phase[6]= (double) ((HCME1+9 )*6 % 360)*M_PI/180.0;
04375 HCME1phase[5]= (double) ((HCME1+3 )*6 % 360)*M_PI/180.0;
04376 HCME1phase[4]= (double) ((HCME1-3 )*6 % 360)*M_PI/180.0;
04377 HCME1phase[3]= (double) ((HCME1-9 )*6 % 360)*M_PI/180.0;
04378 HCME1phase[2]= (double) ((HCME1-15)*6 % 360)*M_PI/180.0;
04379 HCME1phase[1]= (double) ((HCME1-21)*6 % 360)*M_PI/180.0;
04380 HCME1phase[0]= (double) ((HCME1-27)*6 % 360)*M_PI/180.0;
04381
04382 HCMWBphase[9]= (double) ((HCMWB+6)*6 % 360)*M_PI/180.0;
04383 HCMWBphase[8]= (double) ((HCMWB+18)*6 % 360)*M_PI/180.0;
04384 HCMWBphase[7]= (double) ((HCMWB-30)*6 % 360)*M_PI/180.0;
04385 HCMWBphase[6]= (double) ((HCMWB-18)*6 % 360)*M_PI/180.0;
04386 HCMWBphase[5]= (double) ((HCMWB-6 )*6 % 360)*M_PI/180.0;
04387 HCMWBphase[4]= (double) ((HCMWB+6 )*6 % 360)*M_PI/180.0;
04388 HCMWBphase[3]= (double) ((HCMWB+18)*6 % 360)*M_PI/180.0;
04389 HCMWBphase[2]= (double) ((HCMWB-30)*6 % 360)*M_PI/180.0;
04390 HCMWBphase[1]= (double) ((HCMWB-18)*6 % 360)*M_PI/180.0;
04391 HCMWBphase[0]= (double) ((HCMWB-6)*6 % 360)*M_PI/180.0;
04392
04393 HCMNBphase[9]= (double) ((HCMNB+12 )*6 % 360)*M_PI/180.0;
04394 HCMNBphase[8]= (double) ((HCMNB-24)*6 % 360)*M_PI/180.0;
04395 HCMNBphase[7]= (double) ((HCMNB-0 )*6 % 360)*M_PI/180.0;
04396 HCMNBphase[6]= (double) ((HCMNB+24)*6 % 360)*M_PI/180.0;
04397 HCMNBphase[5]= (double) ((HCMNB-12)*6 % 360)*M_PI/180.0;
04398 HCMNBphase[4]= (double) ((HCMNB+12)*6 % 360)*M_PI/180.0;
04399 HCMNBphase[3]= (double) ((HCMNB-24)*6 % 360)*M_PI/180.0;
04400 HCMNBphase[2]= (double) ((HCMNB+0 )*6 % 360)*M_PI/180.0;
04401 HCMNBphase[1]= (double) ((HCMNB+24 )*6 % 360)*M_PI/180.0;
04402 HCMNBphase[0]= (double) ((HCMNB-12)*6 % 360)*M_PI/180.0;
04403 }
04404
04405
04406
04407 for(j=0;j<Num_lambda;++j) {
04408 lyot[j]=blockerint[j]*(1.+contrastNTi[0]*cos(2.0*M_PI/FSR[3]*wavelength[j]+phaseNTi[0]))/2.*(1.+contrastNTi[1]*cos(2.0*M_PI/FSR[4]*wavelength[j]+phaseNTi[1]))/2.*(1.+contrastNTi[2]*cos(2.0*M_PI/FSR[5]*wavelength[j]+phaseNTi[2]))/2.*(1.+contrastNTi[3]*cos(2.0*M_PI/FSR[6]*wavelength[j]+phaseNTi[3]))/2.;
04409 }
04410
04411
04412
04413 for(i=0;i<Num_lambda_filter;++i)
04414 {
04415 for(j=0;j<Num_lambda;++j){
04416 filters[i][j] = lyot[j]*(1.+contrastTi[0]*cos(2.0*M_PI/FSR[0]*wavelength[j]+HCMNBphase[i]+phaseTi[0]))/2.*(1.+contrastTi[1]*cos(2.0*M_PI/FSR[1]*wavelength[j]+HCMWBphase[i]+phaseTi[1]))/2.*(1.+contrastTi[2]*cos(2.0*M_PI/FSR[2]*wavelength[j]-HCME1phase[i]+phaseTi[2]))/2.;
04417 }
04418
04419 }
04420
04421 free(HCMNBphase);
04422 free(HCMWBphase);
04423 free(HCME1phase);
04424
04425
04426 status=0;
04427 return status;
04428
04429 }
04430
04431
04432
04433 char *meinversion_version(){return strdup("$Id: vfisv.c,v 1.36 2017/10/20 16:36:12 yliu Exp $");}
04434
04435
04436
04437