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 1
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 = "vfisv FD10 HARP";
00323 #else
00324 char *module_name = "vfisv 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.118;
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 LAMBDA_MIN = LAMBDA_MINc;
00560 DELTA_LAMBDA = DELTA_LAMBDAc;
00561 LYOTFWHM = LYOTFWHMc;
00562 WNARROW = WNARROWc;
00563 WSPACING = WSPACINGc;
00564
00565 NUM_LAMBDA_synth = NUM_LAMBDA_synthc;
00566 LAMBDA_MIN_synth = LAMBDA_MIN_synthc;
00567
00568 verbose = verbosec;
00569 enfdoit = enfdoitc;
00570
00571 indsdesc = strdup(indsdescc);
00572 #if CHNGTREC == 1
00573 outtrec= strdup(outtrecc);
00574 #endif
00575 #if TAKEPREV == 1
00576 indsdesc2= strdup(indsdesc2c);
00577 #endif
00578 #if MASKPTCH == 1 || HARPATCH == 1
00579 indsdesc3= strdup(indsdesc3c);
00580 #endif
00581 #if VLOSINIT == 1
00582 indsdesc4= strdup(indsdesc4c);
00583 #endif
00584 #if MGSTINIT == 1 || CONFINDX == 1
00585 indsdesc5= strdup(indsdesc5c);
00586 #endif
00587 outser = strdup(outserc);
00588
00589
00590 int list_free_params[10]={1,1,1,0,1,1,1,1,1,0};
00591 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};
00592 int keyfreep;
00593 keyfreep = 0x000003be;
00594
00595
00596 char *Resname[] = {"eta_0", "inclination", "azimuth", "damping", "dop_width", "field",
00597 "vlos_mag", "src_continuum", "src_grad", "alpha_mag",
00598 "field_err","inclination_err","azimuth_err", "vlos_err", "alpha_err",
00599 "field_inclination_err","field_az_err","inclin_azimuth_err", "field_alpha_err",
00600 "inclination_alpha_err", "azimuth_alpha_err", "chisq",
00601 "conv_flag", "qual_map", "confid_map"};
00602 int Err_ct=12;
00603 char segname[16];
00604 char *spname[] = {"I", "Q", "U", "V"};
00605 int spct = (sizeof (spname) / sizeof (char *));
00606 int wlct = NUM_LAMBDA_FILTERc;
00607 int paramct = 10;
00608
00609
00610
00611
00612
00613
00614
00615
00616 double bzero_inv[25] = {0.0,0.0,0.0,0.0,0.0,0.0,
00617 0.0,0.0,0.0,0.0,
00618 0.0,0.0,0.0,0.0,0.0,
00619 0.0,0.0,0.0,0.0,
00620 0.0,0.0,0.0,
00621 0.0,0.0,0.0};
00622 double bscaleinv[25] = {0.01,0.01,0.01,0.0001,0.01,0.01,
00623 50.0,0.1,0.1,0.0001,
00624 0.01,0.01,0.01,50.0,0.01,
00625 0.0001,0.0001,0.0001,0.0001,
00626 0.0001,0.0001,0.0001,
00627 1.0,1.0,1.0};
00628
00629
00630 int *FinalConvFlag;
00631 int *FinalConfidMap;
00632 int *FinalQualMap;
00633 double *FinalRes,*FinalErr;
00634 time_t startime, endtime, starttime1, endtime1;
00635 double *ddat, *res;
00636 double *obs, *scat, *err;
00637 double *weights;
00638 float *data, *data0;
00639 int *nan_map;
00640
00641 int cols, rows, imgpix, imgbytes;
00642 int sp, wl, nvar;
00643 int j,m,i,k,n;
00644
00645 int iquality;
00646 int nharp = 0;
00647 #if RECTANGL == 1 || HARPATCH == 1
00648
00649 int xleftbot = 1885;
00650 int yleftbot = 1410;
00651 int xwidth = 100;
00652 int yheight = 100;
00653 #endif
00654
00655 MPI_Status mpistat;
00656 int mpi_tag, mpi_rank, mpi_size;
00657 int myrank, nprocs, numpix;
00658 int istart, iend;
00659 int *istartall, *iendall;
00660 void para_range(int,int,int,int *,int *);
00661 #if CYCLPRLL == 1
00662 int *jobassignmap;
00663 int jobnum;
00664 #endif
00665
00666 float obs_vr;
00667 float crpixx, crpixy;
00668 float cdeltx, cdelty;
00669 float rsun_ref, dsun_obs;
00670 float sunarc;
00671 float crota2;
00672 float sunradfpix;
00673
00674 char *meinversion_version();
00675
00676
00677 int vfisv_filter(int ,int ,double[*][*],double ,double ,double *,double *,int ,double *,double *,int ,
00678 double, double [4],double [3],double [4],double [3],double *,double *,double *,
00679 int, double ,int ,int ,int ,int);
00680 int initialize_vfisv_filter(double *,double *,int *,double *,double *,int *,double *,double *,
00681 double *,double *,double *,double *,double *,double *,int *,int *,int *,int *,int *,TIME,int *);
00682 double filters[NUM_LAMBDA_FILTERc][NUM_LAMBDAc];
00683 double *wavelengthd=NULL;
00684 double *frontwindowd=NULL;
00685 int nfront;
00686 double *wavelengthbd=NULL;
00687 double *blockerbd=NULL;
00688 int nblocker;
00689 double centerblocker;
00690 double *phaseNT=NULL;
00691 double *phaseT=NULL;
00692 double *contrastNT=NULL;
00693 double *contrastT=NULL;
00694 double *FSR=NULL;
00695 double *lineref=NULL;
00696 double *wavelengthref=NULL;
00697 int referencenlam;
00698 double distance;
00699 double phaseTi[3];
00700 double phaseNTi[4];
00701 double contrastTi[3];
00702 double contrastNTi[4];
00703 int HCME1;
00704 int HCMWB;
00705 int HCMNB;
00706 int HCMPOL;
00707 TIME stokestime;
00708
00709 #if ADNEWKWD == 1
00710 int set_statistics(DRMS_Segment_t *, DRMS_Array_t *, int);
00711 #endif
00712
00713 #if VLOSINIT == 1
00714 float *vlos_init;
00715 int iexistdoppler;
00716 iexistdoppler = 0;
00717 #endif
00718 #if MGSTINIT == 1 || CONFINDX == 1
00719 float *mgst_init;
00720 int iexistmagnetogram;
00721 iexistmagnetogram = 0;
00722 float *blosgram;
00723 #endif
00724 #if TAKEPREV == 1
00725 float *prevdata;
00726 int iexistprev;
00727 #endif
00728 #if MASKPTCH == 1 || HARPATCH == 1
00729 int *patchmask;
00730 int iexistpatchmask;
00731 iexistpatchmask = 0;
00732 #endif
00733
00734
00735 #if MASKPTCH == 1 && HARPATCH == 1
00736 DIE(" Both MASKPTCH and HARPATCH set 1. So terminated !\n");
00737 #endif
00738 #if RECTANGL == 1 && HARPATCH == 1
00739 DIE(" Both RECTANGL and HARPATCH set 1. So terminated !\n");
00740 #endif
00741 #if EQUIAREA != 1 && CYCLPRLL == 1
00742 DIE(" CYCLPRLL cannot work when EQUIAREA is turned off. So terminated !\n");
00743 #endif
00744
00745
00746 time(&startime);
00747
00748
00749 MPI_Status mpi_stat;
00750 status = 0;
00751 MPI_Init (&status, NULL);
00752 MPI_Comm_rank (MPI_COMM_WORLD, &mpi_rank);
00753 MPI_Comm_size (MPI_COMM_WORLD, &mpi_size);
00754
00755 istartall = (int *)malloc(sizeof(int) * mpi_size);
00756 iendall = (int *)malloc(sizeof(int) * mpi_size);
00757
00758 MPI_Barrier(MPI_COMM_WORLD);
00759 if (mpi_rank == 0){printf ("%s Ver. %s\n", module_name, version_id);}
00760
00761 #if CHCKSKIP == 1
00762
00763 {
00764 int idoit;
00765 idoit = 0;
00766 if (enfdoit)
00767 {
00768 if (mpi_rank == 0){printf ("Enforcing running VFISV even when the output destination record exits.\n");}
00769 idoit = 1;
00770 }
00771 else
00772 {
00773 if (mpi_rank == 0)
00774 {
00775
00776 inRS = drms_open_records (drms_env, indsdesc, &status);
00777 if (status) {DIE("drms_open_records failed.\n");}
00778 if ((rec_ct = inRS->n) == 0){DIE("No records in selected dataset.\n");}
00779 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
00780 inRec = inRS->records[0];
00781
00782 TIME t_recl = drms_getkey_time(inRec,"T_REC",&status);
00783 drms_close_records(inRS, DRMS_FREE_RECORD);
00784
00785 DRMS_RecordSet_t *inRS2;
00786 DRMS_Record_t *inRec2;
00787 char timestr2[26];
00788 sprint_time(timestr2,t_recl,"TAI",0);
00789 char stroutdat[80];
00790 sprintf(stroutdat,"%s[%s]",outserc,timestr2);
00791 printf(" destination record : %s ",stroutdat);
00792 char *inQuery2 = stroutdat;
00793 inRS2 = drms_open_records(drms_env, inQuery2, &status);
00794 if (status || inRS2->n == 0)
00795 {
00796 printf("not exist, so ME will start.\n");
00797 idoit = 1;
00798 }
00799 else
00800 {
00801 printf(" exist.:");
00802 idoit = 0;
00803 inRec2= inRS2->records[0];
00804 int nprc2;
00805 nprc2 = drms_getkey_float(inRec2,"INVNPRCS",&status);
00806 if (nprc2 < 1e7)
00807 {
00808 idoit = 1;
00809 printf(" but it seems to be of HARP, so ME VFISV will start.\n");
00810 }
00811 else
00812 {
00813 idoit = 0;
00814 printf(" the existing one seems to be of full-disk, so ME VFISV will be skipped.\n");
00815 }
00816 }
00817 drms_close_records(inRS2, DRMS_FREE_RECORD);
00818 }
00819 MPI_Barrier(MPI_COMM_WORLD);
00820 int *ibuff;
00821 ibuff=(int *)malloc(sizeof(int)*1);
00822 ibuff[0]=idoit;
00823 MPI_Bcast(ibuff,1,MPI_INT,0,MPI_COMM_WORLD);
00824 idoit = ibuff[0];
00825 free(ibuff);
00826 }
00827 if (idoit != 1)
00828 {
00829 if (mpi_rank == 0){printf("ME VFISV run will be skipped. Good bye !\n");}
00830 MPI_Barrier(MPI_COMM_WORLD);
00831 MPI_Finalize();
00832 return 0;
00833 }
00834 }
00835 #endif
00836
00837
00838
00839 if (mpi_rank == 0)
00840 {
00841
00842 if (verbose) printf ("%d CPU/core(s) be used for parallel-inversion. \n", mpi_size);
00843
00844
00845 #if MASKPTCH == 1
00846 {
00847 char segname[100];
00848 char *inData;
00849 DRMS_Array_t *inArray;
00850 DRMS_Segment_t *inSeg;
00851 DRMS_Record_t *inRec;
00852 DRMS_RecordSet_t *inRS;
00853 int nnx, nny;
00854
00855 if (verbose) printf(" now loading mask-data : %s\n",indsdesc3);
00856 inRS = drms_open_records (drms_env, indsdesc3, &status);
00857
00858 if ((status) || ((rec_ct = inRS->n) == 0))
00859 {
00860 iexistpatchmask = 0;
00861 printf(" skip, no data series : %s\n",indsdesc3);
00862 }
00863 else
00864 {
00865 iexistpatchmask = 1;
00866 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
00867 rn = 0;
00868 inRec = inRS->records[rn];
00869 char *Resname[] = {"mask"};
00870 sprintf(segname,"%s",Resname[0]);
00871 inSeg = drms_segment_lookup(inRec,segname);
00872 cols = inSeg->axis[0];
00873 rows = inSeg->axis[1];
00874 imgpix = cols * rows;
00875 patchmask = (int *)malloc (sizeof (int) * imgpix * 1);
00876 int iseg;
00877 for (iseg = 0; iseg < 1; iseg++)
00878 {
00879 sprintf(segname,"%s",Resname[iseg]);
00880 if (verbose) printf(" now loading segment : %-20s",segname);
00881 inSeg = drms_segment_lookup(inRec,segname);
00882 inArray= drms_segment_read(inSeg, DRMS_TYPE_CHAR, &status);
00883 if (status) DIE("Cant read segment!\n");
00884 inData =(char *)inArray->data;
00885 nnx = inArray->axis[0];
00886 nny = inArray->axis[1];
00887 if (verbose) {printf(" Nx Ny are = %d %d\n", nnx, nny);}
00888 for (n = 0; n < nnx * nny; n++){patchmask[n+iseg*imgpix]=inData[n];}
00889 drms_free_array(inArray);
00890 }
00891 drms_close_records (inRS, DRMS_FREE_RECORD);
00892 }
00893 }
00894 #endif
00895
00896
00897
00898
00899
00900 #if HARPATCH == 1 && MULTHARP != 1
00901 {
00902 char segname[100];
00903 char *inData;
00904 DRMS_Array_t *inArray;
00905 DRMS_Segment_t *inSeg;
00906 DRMS_Record_t *inRec;
00907 DRMS_RecordSet_t *inRS;
00908 int nnx, nny;
00909 int colsL, rowsL, imgpixL;
00910
00911 if (verbose) printf(" now loading HARP-data : %s\n",indsdesc3);
00912 inRS = drms_open_records (drms_env, indsdesc3, &status);
00913
00914 if ((status) || ((rec_ct = inRS->n) == 0))
00915 {
00916 iexistpatchmask = 0;
00917 printf(" skip, no data series : %s\n",indsdesc3);
00918 }
00919 else
00920 {
00921 iexistpatchmask = 1;
00922 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
00923 rn = 0;
00924 inRec = inRS->records[rn];
00925
00926 iquality = drms_getkey_int(inRec,"QUALITY",&status);
00927 if (iquality < 0){DIE("No HARP file exist on disk, process terminated.\n");}
00928
00929 char *Resname[] = {"bitmap"};
00930 sprintf(segname,"%s",Resname[0]);
00931 inSeg = drms_segment_lookup(inRec,segname);
00932 colsL = inSeg->axis[0];
00933 rowsL = inSeg->axis[1];
00934 imgpixL = colsL * rowsL;
00935 patchmask = (int *)malloc (sizeof (int) * imgpixL * 1);
00936 int iseg;
00937 for (iseg = 0; iseg < 1; iseg++)
00938 {
00939 sprintf(segname,"%s",Resname[iseg]);
00940 if (verbose) printf(" now loading segment : %-20s",segname);
00941 inSeg = drms_segment_lookup(inRec,segname);
00942 inArray= drms_segment_read(inSeg, DRMS_TYPE_CHAR, &status);
00943 if (status) DIE("Cant read segment!\n");
00944 inData =(char *)inArray->data;
00945 nnx = inArray->axis[0];
00946 nny = inArray->axis[1];
00947 if (verbose) {printf(" Nx Ny are = %d %d\n", nnx, nny);}
00948 for (n = 0; n < nnx * nny; n++){patchmask[n+iseg*imgpixL]=inData[n];}
00949 drms_free_array(inArray);
00950 }
00951 xleftbot = drms_getkey_int(inRec,"CRPIX1",&status);
00952 yleftbot = drms_getkey_int(inRec,"CRPIX2",&status);
00953 xwidth = colsL;
00954 yheight = rowsL;
00955 if (verbose) {printf(" HARP info. xleftbot yleftbot xwidth yheight = %d %d %d %d\n",xleftbot,yleftbot,xwidth,yheight);}
00956 xleftbot = xleftbot - 1;
00957 yleftbot = yleftbot - 1;
00958 if (verbose) {printf(" HARP xleftbot yleftbot were shifted = %d %d\n",xleftbot,yleftbot);}
00959 drms_close_records (inRS, DRMS_FREE_RECORD);
00960 }
00961 }
00962 #endif
00963
00964 #if TAKEPREV == 1
00965 {
00966 char segname[100];
00967 float *inData;
00968 DRMS_Array_t *inArray;
00969 DRMS_Segment_t *inSeg;
00970 DRMS_Record_t *inRec;
00971 DRMS_RecordSet_t *inRS;
00972 int nnx, nny;
00973
00974 if (verbose) printf(" now loading previous results series : %s\n",indsdesc2);
00975 inRS = drms_open_records (drms_env, indsdesc2, &status);
00976
00977
00978
00979 if ((status) || ((rec_ct = inRS->n) == 0))
00980 {
00981 iexistprev=0;
00982 if (verbose) printf(" skip, no data series : %s\n",indsdesc2);
00983 }
00984 else
00985 {
00986 iexistprev=1;
00987 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
00988 rn = 0;
00989 inRec = inRS->records[rn];
00990 inSeg = drms_segment_lookupnum (inRec, 0);
00991 cols = inSeg->axis[0];
00992 rows = inSeg->axis[1];
00993 imgpix = cols * rows;
00994 prevdata = (float *)malloc (sizeof (float) * imgpix * (paramct+Err_ct));
00995 int iseg;
00996 for (iseg = 0; iseg < (paramct+Err_ct); iseg++)
00997 {
00998 sprintf(segname,"%s",Resname[iseg]);
00999 if (verbose) printf(" now loading segment of previous results : %-20s",segname);
01000 inSeg = drms_segment_lookup(inRec,segname);
01001 inArray= drms_segment_read(inSeg, DRMS_TYPE_FLOAT, &status);
01002 if (status) DIE("Cant read segment!\n");
01003 inData =(float *)inArray->data;
01004 nnx = inArray->axis[0];
01005 nny = inArray->axis[1];
01006 if (verbose) {printf(" Nx Ny are = %d %d\n", nnx, nny);}
01007 for (n = 0; n < nnx * nny; n++){prevdata[n+iseg*imgpix]=inData[n];}
01008 drms_free_array(inArray);
01009 }
01010 drms_close_records (inRS, DRMS_FREE_RECORD);
01011 }
01012 }
01013 #endif
01014
01015
01016 inRS = drms_open_records (drms_env, indsdesc, &status);
01017 if (status) {DIE("drms_open_records failed.\n");}
01018 if ((rec_ct = inRS->n) == 0){DIE("No records in selected dataset.\n");}
01019 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
01020
01021 rn = 0;
01022
01023 inRec = inRS->records[rn];
01024
01025
01026 iquality = drms_getkey_int(inRec,"QUALITY",&status);
01027 if (iquality < 0){DIE("No Stokes file exist on disk, process terminated.\n");}
01028
01029 inSeg = drms_segment_lookupnum (inRec, 0);
01030 cols = inSeg->axis[0];
01031 rows = inSeg->axis[1];
01032 imgpix = cols * rows;
01033 imgbytes = imgpix * sizeof (float);
01034 nvar = wlct * spct;
01035
01036 #if TAKEPREV == 1
01037 if (iexistprev==0){prevdata = (float *)malloc (sizeof (float) * imgpix * (paramct+Err_ct));}
01038 #endif
01039
01040 data = data0 = (float *)malloc (sizeof (float) * imgpix * nvar);
01041 nan_map=(int *)calloc(imgpix, sizeof (int));
01042
01043
01044
01045 for (sp = 0; sp < spct; sp++)
01046 {
01047 for (wl = 0; wl < wlct; wl++)
01048 {
01049
01050
01051
01052
01053
01054
01055 if (NUM_LAMBDA_FILTER == 6)
01056 {
01057 sprintf (segname, "%s%d", spname[sp], wl);
01058 }
01059 if (NUM_LAMBDA_FILTER == 8)
01060 {
01061 int idummy;
01062 if (wl == 0){idummy = 7;}else{idummy = wl - 1;}
01063 sprintf (segname, "%s%d",spname[sp],idummy);
01064 }
01065 if (NUM_LAMBDA_FILTER == 10)
01066 {
01067 int idummy;
01068 idummy = wl - 2;
01069 if (wl == 0){idummy = 9;}
01070 if (wl == 1){idummy = 7;}
01071 if (wl == 9){idummy = 8;}
01072 sprintf (segname, "%s%d",spname[sp],idummy);
01073 }
01074 if (verbose){printf("now loading Stokes : %s\n",segname);}
01075
01076 if ((inSeg = drms_segment_lookup (inRec, segname)) == NULL){
01077 fprintf (stderr, "Error reading segment %s of record %d\n", segname, rn);
01078 return 1;
01079 }
01080
01081 stokes_array = drms_segment_read (inSeg, DRMS_TYPE_FLOAT, &status);
01082 if (status) {DIE("Cant read Stokes data !\n");}
01083 memcpy (data, stokes_array->data, imgbytes);
01084 drms_free_array (stokes_array);
01085 data += imgpix;
01086 } }
01087 data = data0;
01088 printf("Imgpix= %d\n",imgpix);
01089
01090
01091 iquality = drms_getkey_int(inRec,"QUALITY",&status);
01092 #if SKIPBADQ == 1
01093 {
01094 char trectmp2[26];
01095 TIME trectmp1 = drms_getkey_time(inRec,"T_REC",&status);
01096 sprint_time(trectmp2,trectmp1,"TAI",0);
01097 printf("QUALITY index at [%s] is %08x\n",trectmp2,iquality);
01098 if (iquality !=0){DIE(" QUALITY index is not zero, so process terminated !");}
01099 }
01100 #endif
01101 #if SKIPBADQ == 2
01102 {
01103 char trectmp2[26];
01104 TIME trectmp1 = drms_getkey_time(inRec,"T_REC",&status);
01105 sprint_time(trectmp2,trectmp1,"TAI",0);
01106 printf("QUALITY index at [%s] is %08x\n",trectmp2,iquality);
01107 if ((iquality !=0) && (iquality !=0x00000400)){DIE(" QUALITY index does not satisfy criteria, so process terminated !");}
01108 }
01109 #endif
01110
01111 obs_vr = drms_getkey_float(inRec,"OBS_VR",&status);
01112 obs_vr = obs_vr * 100.0;
01113 crota2 = drms_getkey_float(inRec,"CROTA2",&status);
01114 crpixx = drms_getkey_float(inRec,"CRPIX1",&status);
01115 crpixy = drms_getkey_float(inRec,"CRPIX2",&status);
01116 cdeltx = drms_getkey_float(inRec,"CDELT1",&status);
01117 cdelty = drms_getkey_float(inRec,"CDELT2",&status);
01118 rsun_ref = drms_getkey_float(inRec,"RSUN_REF",&status);
01119 dsun_obs = drms_getkey_float(inRec,"DSUN_OBS",&status);
01120 sunarc = asin(rsun_ref/dsun_obs)
01121 / 3.14159265358979e0 * 180.0 * 3600.0;
01122 printf("solar radius is %f in arcsec \n",sunarc);
01123 sunradfpix = sunarc / (cdeltx + cdelty) * 2.0;
01124 printf("solar radius is %f in CCD pix.\n",sunradfpix);
01125 if ((isnan(sunarc)) ||((isnan(crpixx)) || isnan(crpixy)))
01126 {
01127 sunarc = (float)(cols+rows) * 0.5;
01128 crpixx = (float)cols * 0.5 + 0.5;
01129 crpixy = (float)rows * 0.5 + 0.5;
01130 }
01131
01132
01133
01134
01135 #if HARPATCH == 1 && MULTHARP == 1
01136 patchmask = (int *)malloc (sizeof (int) * imgpix);
01137 {
01138 int i;
01139 for (i = 0; i < imgpix; i++){patchmask[i]=0;}
01140 char segname[100];
01141 char *inData;
01142 DRMS_Array_t *inArray;
01143 DRMS_Segment_t *inSeg;
01144 DRMS_Record_t *inRec;
01145 DRMS_RecordSet_t *inRS;
01146 int nnx, nny;
01147 int colsL, rowsL, imgpixL;
01148 #if HANDHARP != 1
01149
01150 if (verbose) printf(" now loading HARP-data : %s\n",indsdesc3);
01151 inRS = drms_open_records (drms_env, indsdesc3, &status);
01152
01153 if ((status) || ((rec_ct = inRS->n) == 0))
01154 {
01155 iexistpatchmask = 0;
01156
01157 DIE("terminated due to no HARP data.\n");
01158 }
01159 else
01160 {
01161 rec_ct = inRS->n;
01162 nharp = rec_ct;
01163 printf(" There are %d HARP for %s\n",rec_ct, indsdesc3);
01164 iexistpatchmask = 1;
01165 for (rn = 0; rn < rec_ct; rn++)
01166 {
01167 inRec = inRS->records[rn];
01168
01169
01170 iquality = drms_getkey_int(inRec,"QUALITY",&status);
01171 if (iquality < 0){DIE("No HARP file exist on disk, process terminated.\n");}
01172
01173 char *Resname[] = {"bitmap"};
01174 sprintf(segname,"%s",Resname[0]);
01175 inSeg = drms_segment_lookup(inRec,segname);
01176 colsL = inSeg->axis[0];
01177 rowsL = inSeg->axis[1];
01178 imgpixL = colsL * rowsL;
01179 int *patchmaskL;
01180 patchmaskL = (int *)malloc (sizeof (int) * imgpixL * 1);
01181 int iseg;
01182 for (iseg = 0; iseg < 1; iseg++)
01183 {
01184 sprintf(segname,"%s",Resname[iseg]);
01185 if (verbose) printf(" now loading segment : %-20s",segname);
01186 inSeg = drms_segment_lookup(inRec,segname);
01187 inArray= drms_segment_read(inSeg, DRMS_TYPE_CHAR, &status);
01188
01189 if (status)
01190 {
01191 printf("no valid HARP data, maybe expired ... skip %d th HARP\n", iseg);
01192 }
01193 else
01194 {
01195 inData =(char *)inArray->data;
01196 nnx = inArray->axis[0];
01197 nny = inArray->axis[1];
01198 if (verbose) {printf(" Nx Ny are = %d %d\n", nnx, nny);}
01199 for (n = 0; n < nnx * nny; n++){patchmaskL[n+iseg*imgpixL]=inData[n];}
01200 }
01201 drms_free_array(inArray);
01202 }
01203 int xleftbotL, yleftbotL;
01204 xleftbotL = drms_getkey_int(inRec,"CRPIX1",&status);
01205 yleftbotL = drms_getkey_int(inRec,"CRPIX2",&status);
01206 xwidth = colsL;
01207 yheight = rowsL;
01208 if (verbose) {printf(" HARP info. xleftbot yleftbot xwidth yheight = %d %d %d %d\n",xleftbotL,yleftbotL,xwidth,yheight);}
01209
01210 #if 0
01211
01212 int numharp = drms_getkey_time(inRec,"HARPNUM",&status);
01213 if ((numharp == 2081) || (numharp == 4087))
01214 {
01215 #if 1
01216
01217 int icenter, jcenter;
01218 icenter = xleftbotL + colsL / 2;
01219 jcenter = yleftbotL + rowsL / 2;
01220 if (colsL < 700){xleftbotL = icenter - 350; colsL = 700;}
01221 if (rowsL < 700){yleftbotL = jcenter - 350; rowsL = 700;}
01222 #endif
01223 int i2, j2, n2, m2;
01224 for (i2 = 0; i2 < colsL; i2++)
01225 {
01226 for (j2 = 0; j2 < rowsL; j2++)
01227 {
01228 int iL, jL;
01229 jL = j2 + yleftbotL - 1;
01230 iL = i2 + xleftbotL - 1;
01231 if (iL < 0){iL = 0;}
01232 if (iL > cols - 1){iL = cols-1;}
01233 if (jL < 0){jL = 0;}
01234 if (jL > rows - 1){jL = rows-1;}
01235 m2 = jL * cols + iL;
01236 patchmask[m2] = 600;
01237 } }
01238 }
01239 else
01240 {
01241 printf(" Out of interest this time, thus skipped : RecNum and HARPnum = %d %d\n",rn,numharp);
01242 }
01243 #else
01244
01245 #if 1
01246
01247 int iextendx = 50;
01248 int iextendy = 50;
01249 xleftbotL = xleftbotL - iextendx;
01250 yleftbotL = yleftbotL - iextendy;
01251 colsL = colsL + iextendx * 2;
01252 rowsL = rowsL + iextendy * 2;
01253 #endif
01254 #if 0
01255
01256 {
01257 int icenter, jcenter;
01258 icenter = xleftbotL + colsL / 2;
01259 jcenter = yleftbotL + rowsL / 2;
01260 if (colsL < 700){xleftbotL = icenter - 350; colsL = 700;}
01261 if (rowsL < 700){yleftbotL = jcenter - 350; rowsL = 700;}
01262 }
01263 #endif
01264 int i2, j2, m2;
01265 for (i2 = 0; i2 < colsL; i2++)
01266 {
01267 for (j2 = 0; j2 < rowsL; j2++)
01268 {
01269 int iL, jL;
01270 jL = j2 + yleftbotL - 1;
01271 iL = i2 + xleftbotL - 1;
01272 if (iL < 0){iL = 0;}
01273 if (iL > cols - 1){iL = cols-1;}
01274 if (jL < 0){jL = 0;}
01275 if (jL > rows - 1){jL = rows-1;}
01276 m2 = jL * cols + iL;
01277 patchmask[m2] = 600;
01278 } }
01279 #endif // endif whether the standard use of HAPR or something else.
01280
01281 free(patchmaskL);
01282 }
01283 drms_close_records (inRS, DRMS_FREE_RECORD);
01284 }
01285 #else
01286
01287 iexistpatchmask = 1;
01288 int xleftbotL, yleftbotL;
01289 xleftbotL = 1450;
01290 yleftbotL = 1250;
01291 colsL = 600;
01292 rowsL = 400;
01293 xwidth = colsL;
01294 yheight = rowsL;
01295 if (verbose) {printf(" pseudo-HARP info. xleftbot yleftbot xwidth yheight = %d %d %d %d\n",xleftbotL,yleftbotL,xwidth,yheight);}
01296 int i2, j2, m2;
01297 for (i2 = 0; i2 < colsL; i2++)
01298 {
01299 for (j2 = 0; j2 < rowsL; j2++)
01300 {
01301 int iL, jL;
01302 jL = j2 + yleftbotL - 1;
01303 iL = i2 + xleftbotL - 1;
01304 if (iL < 0){iL = 0;}
01305 if (iL > cols - 1){iL = cols-1;}
01306 if (jL < 0){jL = 0;}
01307 if (jL > rows - 1){jL = rows-1;}
01308 m2 = jL * cols + iL;
01309 patchmask[m2] = 600;
01310 } }
01311 #endif
01312
01313
01314 xwidth = cols;
01315 yheight = rows;
01316 xleftbot = 0;
01317 yleftbot = 0;
01318 }
01319 #endif
01320
01321 #if MASKPTCH == 1 || HARPATCH == 1
01322 if (iexistpatchmask==0){patchmask = (int *)malloc (sizeof (int) * imgpix);}
01323 #endif
01324
01325
01326 #if VLOSINIT == 1
01327 float defvlosinit;
01328 defvlosinit = guess[6];
01329 {
01330 char segname[100];
01331 float *inData;
01332 DRMS_Array_t *inArray;
01333 DRMS_Segment_t *inSeg;
01334 DRMS_Record_t *inRec;
01335 DRMS_RecordSet_t *inRS;
01336 int nnx, nny;
01337 if (verbose) printf(" now loading Doppler : %s\n",indsdesc4);
01338 inRS = drms_open_records (drms_env, indsdesc4, &status);
01339
01340 if ((status) || ((rec_ct = inRS->n) == 0))
01341 {
01342 iexistdoppler = 0;
01343 printf(" no data series : %s\n",indsdesc4);
01344 }
01345 else
01346 {
01347 iexistdoppler = 1;
01348 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
01349 rn = 0;
01350 inRec = inRS->records[rn];
01351
01352
01353 iquality = drms_getkey_int(inRec,"QUALITY",&status);
01354 if (iquality < 0){DIE("No Doppler file exist on disk, process terminated.\n");}
01355
01356 char *Resname[] = {"Dopplergram"};
01357 sprintf(segname,"%s",Resname[0]);
01358 inSeg = drms_segment_lookup(inRec,segname);
01359 cols = inSeg->axis[0];
01360 rows = inSeg->axis[1];
01361 imgpix = cols * rows;
01362 vlos_init = (float *)malloc (sizeof(float) * imgpix);
01363 int iseg;
01364 for (iseg = 0; iseg < 1; iseg++)
01365 {
01366 sprintf(segname,"%s",Resname[iseg]);
01367 if (verbose) printf(" now loading segment : %-20s",segname);
01368 inSeg = drms_segment_lookup(inRec,segname);
01369 inArray= drms_segment_read(inSeg, DRMS_TYPE_FLOAT, &status);
01370 if (status) DIE("Cant read Dopplergram data !\n");
01371 inData =(float *)inArray->data;
01372 nnx = inArray->axis[0];
01373 nny = inArray->axis[1];
01374 if (verbose) {printf(" Nx Ny are = %d %d\n", nnx, nny);}
01375 for (n = 0; n < nnx * nny; n++){vlos_init[n]=inData[n]*100.0;}
01376 drms_free_array(inArray);
01377 }
01378 drms_close_records (inRS, DRMS_FREE_RECORD);
01379 }
01380 }
01381
01382
01383
01384 if (iexistdoppler == 1)
01385 {
01386 for (n = 0; n < imgpix; n++)
01387 {
01388 float fpixdist, fxpix, fypix;
01389 int ix, iy;
01390 ix = n % cols;
01391 iy = n / cols;
01392 fxpix = ((float)(ix) -(crpixx - 1.0)) * cdeltx;
01393 fypix = ((float)(iy) -(crpixy - 1.0)) * cdelty;
01394 fpixdist = fxpix * fxpix + fypix * fypix + 1e-20;
01395 fpixdist = sqrt(fpixdist);
01396 if (fpixdist > sunarc * 0.99)
01397 {
01398 vlos_init[n] = defvlosinit;
01399 }
01400 }
01401 }
01402
01403 if (iexistdoppler == 0)
01404 {
01405 vlos_init = (float *)malloc (sizeof (float) * imgpix * 1);
01406 float cospangle, pangrad;
01407 pangrad = crota2 / 180.0 * 3.14159265358979;
01408 cospangle = cos(pangrad);
01409 for (n = 0; n < imgpix; n++)
01410 {
01411 float fpixdist, fxpix, fypix;
01412 int ix, iy;
01413 ix = n % cols;
01414 iy = n / cols;
01415 fxpix = ((float)(ix) -(crpixx - 1.0)) * cdeltx;
01416 fypix = ((float)(iy) -(crpixy - 1.0)) * cdelty;
01417 fpixdist = fxpix * fxpix + fypix * fypix + 1e-20;
01418 fpixdist = sqrt(fpixdist);
01419 if (fpixdist < sunarc * 0.99)
01420 {
01421 float sinphi, sintheta, costheta;
01422 sintheta = fypix/sunarc;
01423 costheta = 1.0 - sintheta*sintheta;
01424 if (costheta > 0.0){costheta = sqrt(costheta);}else{costheta = 0.0;}
01425 float omega, vlosoldiff;
01426 omega = 14.713 - 2.396 * sintheta * sintheta - 1.787 * sintheta * sintheta * sintheta * sintheta;
01427 omega = omega / (24.0 * 3600.0) * 3.14159265358979 / 180.0 ;
01428 vlosoldiff = rsun_ref * 100.0 * omega;
01429 float fwork;
01430 sinphi = fxpix/ (costheta * sunarc);
01431 fwork = sinphi * cospangle;
01432 vlosoldiff = vlosoldiff * fwork;
01433 vlos_init[n] = -obs_vr + vlosoldiff;
01434 }
01435 else
01436 {
01437 vlos_init[n] = defvlosinit;
01438 }
01439 }
01440 }
01441 #endif // endif VLOSINIT is 1
01442
01443
01444 #if MGSTINIT == 1 || CONFINDX == 1
01445 float defmgstinit;
01446 defmgstinit = guess[5];
01447 {
01448 char segname[100];
01449 float *inData;
01450 DRMS_Array_t *inArray;
01451 DRMS_Segment_t *inSeg;
01452 DRMS_Record_t *inRec;
01453 DRMS_RecordSet_t *inRS;
01454 int nnx, nny;
01455 if (verbose) printf(" now loading magnetogram : %s\n",indsdesc5);
01456 inRS = drms_open_records (drms_env, indsdesc5, &status);
01457
01458 if ((status) || ((rec_ct = inRS->n) == 0))
01459 {
01460 iexistmagnetogram = 0;
01461 printf(" no data series : %s\n",indsdesc5);
01462 }
01463 else
01464 {
01465 iexistmagnetogram = 1;
01466 if ((rec_ct = inRS->n) > 1){fprintf (stderr, "Warning: only first record in selected set processed\n");}
01467 rn = 0;
01468 inRec = inRS->records[rn];
01469
01470
01471 iquality = drms_getkey_int(inRec,"QUALITY",&status);
01472 if (iquality < 0){DIE("No Magnetogram file exist on disk, process terminated.\n");}
01473
01474 char *Resname[] = {"magnetogram"};
01475 sprintf(segname,"%s",Resname[0]);
01476 inSeg = drms_segment_lookup(inRec,segname);
01477 cols = inSeg->axis[0];
01478 rows = inSeg->axis[1];
01479 imgpix = cols * rows;
01480 mgst_init = (float *)malloc (sizeof(float) * imgpix);
01481 blosgram = (float *)malloc (sizeof(float) * imgpix);
01482 int iseg;
01483 for (iseg = 0; iseg < 1; iseg++)
01484 {
01485 sprintf(segname,"%s",Resname[iseg]);
01486 if (verbose) printf(" now loading segment : %-20s",segname);
01487 inSeg = drms_segment_lookup(inRec,segname);
01488 inArray= drms_segment_read(inSeg, DRMS_TYPE_FLOAT, &status);
01489 if (status) DIE("Cant read Magnetogram data !\n");
01490 inData =(float *)inArray->data;
01491 nnx = inArray->axis[0];
01492 nny = inArray->axis[1];
01493 if (verbose) {printf(" Nx Ny are = %d %d\n", nnx, nny);}
01494 for (n = 0; n < nnx * nny; n++){blosgram[n]=inData[n];}
01495 drms_free_array(inArray);
01496 }
01497 drms_close_records (inRS, DRMS_FREE_RECORD);
01498 }
01499 }
01500
01501 if (iexistmagnetogram == 1)
01502 {
01503 for (n = 0; n < imgpix; n++)
01504 {
01505 float fpixdist, fxpix, fypix;
01506 int ix, iy;
01507 ix = n % cols;
01508 iy = n / cols;
01509 fxpix = ((float)(ix) -(crpixx - 1.0)) * cdeltx;
01510 fypix = ((float)(iy) -(crpixy - 1.0)) * cdelty;
01511 fpixdist = fxpix * fxpix + fypix * fypix + 1e-20;
01512 fpixdist = sqrt(fpixdist);
01513 if (fpixdist > sunarc * 0.99)
01514 {
01515 mgst_init[n] = defmgstinit;
01516 }
01517 else
01518 {
01519 float cosmu, ftmp;
01520 cosmu = 1.0e0 - fpixdist*fpixdist/(sunarc*sunarc);
01521 ftmp = fabs(blosgram[n]) / (0.8 * sqrt(cosmu) + 0.2);
01522 if (ftmp > 4.0e3){ftmp = 4.0e3;}
01523 if (ftmp < -4.0e3){ftmp = -4.0e3;}
01524 mgst_init[n] = ftmp;
01525 }
01526 }
01527 }
01528
01529 if (iexistmagnetogram == 0)
01530 {
01531 mgst_init = (float *)malloc (sizeof (float) * imgpix * 1);
01532 blosgram = (float *)malloc (sizeof (float) * imgpix * 1);
01533 for (n = 0; n < imgpix; n++){mgst_init[n]=0.0;}
01534 }
01535 #endif // endif MGSTINIT or CONFINDX is 1
01536
01537
01538 for (n = 0; n < imgpix; n++)
01539 {
01540 nan_map[n] = 0;
01541 double sumsqr;
01542 sumsqr = 0.0;
01543 for (m = 0; m < nvar; m++){sumsqr = sumsqr + data[n + m*imgpix] * data[n + m*imgpix];}
01544 if (sumsqr < 1.0e-2){nan_map[n] = 1;}
01545 if (isnan(sumsqr)) {nan_map[n] = 1;}
01546 float fpixdist, fxpix, fypix;
01547 int ix, iy;
01548 ix = n % cols;
01549 iy = n / cols;
01550 fxpix = ((float)(ix) -(crpixx - 1.0)) * cdeltx;
01551 fypix = ((float)(iy) -(crpixy - 1.0)) * cdelty;
01552 fpixdist = fxpix * fxpix + fypix * fypix + 1e-20;
01553 fpixdist = sqrt(fpixdist);
01554 if (fpixdist > sunarc) {nan_map[n] = 2;}
01555 #if RECTANGL == 1
01556 if ((ix < xleftbot) ||
01557 (ix > xleftbot + xwidth - 1) ||
01558 (iy < yleftbot) ||
01559 (iy > yleftbot + yheight - 1)) {nan_map[n] = 3;}
01560 #endif
01561 #if QUICKRUN == 1
01562
01563 if ((ix < 1997) || (ix > 2097))
01564 {nan_map[n] = 3;}
01565 #endif
01566 #if HARPATCH == 1 && MULTHARP != 1
01567 if ((ix < xleftbot) ||
01568 (ix > xleftbot + xwidth - 1) ||
01569 (iy < yleftbot) ||
01570 (iy > yleftbot + yheight - 1))
01571 {
01572 nan_map[n] = 3;
01573 }
01574 #if HARPBLOB == 1
01575 else
01576 {
01577 int i2, j2, n2;
01578 i2 = ix - xleftbot;
01579 j2 = iy - yleftbot;
01580 n2 = xwidth * j2 + i2;
01581 if (patchmask[n2] < 4) {nan_map[n] = 4;}
01582 }
01583 #endif
01584 #endif // end if HARPATCH is 1 and MULTHARP is NOT 1
01585 #if HARPATCH == 1 && MULTHARP == 1
01586 if (patchmask[n] < 4){nan_map[n] = 4;}
01587 #endif
01588 #if MASKPTCH == 1
01589 if (patchmask[n] < 2){nan_map[n] = 4;}
01590 #endif
01591 }
01592 printf("data is read\n");
01593 #if MASKPTCH == 1 || HARPATCH == 1
01594 free(patchmask);
01595 #endif
01596
01597
01598 int nonnan, numnan, nofdsk, nofrct, nmask;
01599 nonnan = 0;
01600 numnan = 0;
01601 nofdsk = 0;
01602 nofrct = 0;
01603 nmask = 0;
01604 for (n = 0; n < imgpix; n++)
01605 {
01606 if (nan_map[n] == 0) nonnan = nonnan + 1;
01607 if (nan_map[n] == 1) numnan = numnan + 1;
01608 if (nan_map[n] == 2) nofdsk = nofdsk + 1;
01609 if (nan_map[n] == 3) nofrct = nofrct + 1;
01610 if (nan_map[n] == 4) nmask = nmask + 1;
01611 }
01612 printf(" Num of pixel total (4k x 4k or 16 x 2^20) : %8d \n", imgpix);
01613 printf(" Num of pixel out-of-disk : %8d \n", nofdsk);
01614 printf(" Num of pixel out-of-rectangle of interest : %8d \n", nofrct);
01615 printf(" Num of pixel skipped due to all-zero or NaN : %8d \n", numnan);
01616 printf(" Num of pixel skipped due to mask map : %8d \n", nmask);
01617 printf(" Num of pixel to be processed : %8d \n", nonnan);
01618
01619
01620 int irank;
01621 int *itmps;
01622 int *itmpe;
01623 itmps = (int *)malloc(sizeof(int) * mpi_size);
01624 itmpe = (int *)malloc(sizeof(int) * mpi_size);
01625 for(irank = 0; irank < mpi_size; irank++)
01626 {
01627 int myrank, nprocs, numpix;
01628 int istart, iend;
01629 myrank = irank;
01630 nprocs = mpi_size;
01631 numpix = nonnan;
01632 para_range(myrank,nprocs,numpix,&istart,&iend);
01633 itmps[irank] = istart;
01634 itmpe[irank] = iend;
01635 }
01636 int icount;
01637 icount = -1;
01638 for (n = 0; n < imgpix; n++)
01639 {
01640 if (nan_map[n] == 0)
01641 {
01642 icount = icount + 1;
01643 for (m = 0; m < mpi_size; m++)
01644 {
01645 if (itmps[m] == icount){istartall[m]=n;}
01646 if (itmpe[m] == icount){iendall[m]=n;}
01647 }
01648 }
01649 }
01650 free(itmps);
01651 free(itmpe);
01652
01653
01654 #if CYCLPRLL == 1
01655 jobnum = -100000;
01656 {
01657 int modjob;
01658 modjob = nonnan % mpi_size;
01659 if (modjob == 0){jobnum = nonnan / mpi_size;}else{jobnum = nonnan / mpi_size + 1;}
01660 jobassignmap = (int *)malloc(sizeof(int) * jobnum * mpi_size);
01661 int icount, n, nlast;
01662 nlast = -1;
01663 icount = -1;
01664 for (n = 0; n < imgpix; n++)
01665 {
01666 if (nan_map[n] == 0)
01667 {
01668 icount = icount + 1;
01669 int npe, ndo, ntemp;
01670 npe = icount % mpi_size;
01671 ndo = icount / mpi_size;
01672 ntemp = ndo + npe * jobnum;
01673 jobassignmap[ntemp] = n;
01674 nlast = n;
01675 }
01676 }
01677 icount = icount + 1;
01678 if (icount != nonnan){printf("%d %d\n",icount,nonnan); DIE("Mistake at new parallel job assignment, at debug point 13 \n");}
01679 if (icount < 0){DIE("Mistake at new parallel job assignment, at debug point 14 !\n");}
01680 printf(" Modulo JobNum = %d %d \n",modjob, jobnum);
01681 if (modjob > 0)
01682 {
01683 int ntemp, n;
01684 for (ntemp = 0; ntemp < (mpi_size - modjob); ntemp++)
01685 {
01686 int npadding;
01687 npadding = (jobnum * mpi_size - 1) - ntemp * jobnum;
01688 jobassignmap[npadding] = nlast;
01689 }
01690 }
01691 }
01692 #endif // end if CYCLPRLL is 1
01693
01694 }
01695 else
01696 {
01697 drms_server_end_transaction(drms_env, 1, 0);
01698 db_disconnect(&drms_env->session->db_handle);
01699 }
01700
01701 MPI_Barrier(MPI_COMM_WORLD);
01702
01703
01704 int *ibuff;
01705 ibuff=(int *)malloc(sizeof(int)*4);
01706 ibuff[0]=imgpix;
01707 ibuff[1]=nvar;
01708 ibuff[2]=cols;
01709 ibuff[3]=rows;
01710 MPI_Bcast(ibuff,4,MPI_INT,0,MPI_COMM_WORLD);
01711 imgpix = ibuff[0];
01712 nvar = ibuff[1];
01713 cols = ibuff[2];
01714 rows = ibuff[3];
01715 free(ibuff);
01716 #if CYCLPRLL == 1
01717 ibuff=(int *)malloc(sizeof(int)*1);
01718 ibuff[0]=jobnum;
01719 MPI_Bcast(ibuff,1,MPI_INT,0,MPI_COMM_WORLD);
01720 jobnum = ibuff[0];
01721 free(ibuff);
01722 #endif
01723
01724 MPI_Bcast(istartall,mpi_size,MPI_INT,0,MPI_COMM_WORLD);
01725 MPI_Bcast(iendall, mpi_size,MPI_INT,0,MPI_COMM_WORLD);
01726
01727 float *fbuff;
01728 fbuff=(float *)malloc(sizeof(float)*6);
01729 fbuff[0] = crpixx;
01730 fbuff[1] = crpixy;
01731 fbuff[2] = cdeltx;
01732 fbuff[3] = cdelty;
01733 fbuff[4] = rsun_ref;
01734 fbuff[5] = dsun_obs;
01735 MPI_Bcast(fbuff,6,MPI_FLOAT,0,MPI_COMM_WORLD);
01736 crpixx = fbuff[0];
01737 crpixy = fbuff[1];
01738 cdeltx = fbuff[2];
01739 cdelty = fbuff[3];
01740 rsun_ref = fbuff[4];
01741 dsun_obs = fbuff[5];
01742 free(fbuff);
01743
01744 MPI_Barrier(MPI_COMM_WORLD);
01745
01746
01747 if (mpi_rank == 0)
01748 {
01749 FinalErr=(double *)malloc(sizeof(double)*imgpix*Err_ct);
01750 FinalRes=(double *)malloc(sizeof(double)*imgpix*paramct);
01751 FinalConvFlag =(int *)malloc(sizeof(int)*imgpix);
01752 FinalConfidMap=(int *)malloc(sizeof(int)*imgpix);
01753 FinalQualMap =(int *)malloc(sizeof(int)*imgpix);
01754 }
01755
01756
01757 float *dataLocal;
01758 float *vlos_initLocal;
01759 float *mgst_initLocal;
01760 double *FinalResLocal,*FinalErrLocal;
01761 int *FinalConvFlagLocal;
01762 int *FinalQualMapLocal;
01763 int *nan_mapLocal;
01764 myrank = mpi_rank;
01765 nprocs = mpi_size;
01766 numpix = imgpix;
01767 #if CYCLPRLL == 1
01768 istart=0;
01769 iend =jobnum-1;
01770 #else
01771 #if EQUIAREA == 1
01772 istart=istartall[myrank];
01773 iend=iendall[myrank];
01774 #else
01775 para_range(myrank,nprocs,numpix,&istart,&iend);
01776 #endif
01777 #endif
01778 #if CYCLPRLL == 1
01779 if (verbose)
01780 {
01781 printf("Hello, this is %2d th PE of %2d, in charge of %9d pixels, of 0 to %9d.\n",
01782 mpi_rank,mpi_size,jobnum,(imgpix-1));
01783 }
01784 #else
01785 if (verbose)
01786 {
01787 printf("Hello, this is %2d th PE of %2d, in charge of pixels from %9d to %9d of 0 to %9d.\n",
01788 mpi_rank,mpi_size,istart,iend,(imgpix-1));
01789 }
01790 #endif
01791 int imgpixlocal;
01792 imgpixlocal = iend - istart + 1;
01793 FinalConvFlagLocal=(int *)malloc(sizeof(int) *imgpixlocal);
01794 FinalQualMapLocal =(int *)malloc(sizeof(int) *imgpixlocal);
01795 nan_mapLocal = (int *)malloc(sizeof(int) *imgpixlocal);
01796 dataLocal = (float *)malloc(sizeof(float) *imgpixlocal*nvar);
01797 vlos_initLocal= (float *)malloc(sizeof(float) *imgpixlocal);
01798 mgst_initLocal= (float *)malloc(sizeof(float) *imgpixlocal);
01799 FinalErrLocal = (double *)malloc(sizeof(double)*imgpixlocal*Err_ct);
01800 FinalResLocal = (double *)malloc(sizeof(double)*imgpixlocal*paramct);
01801
01802
01803 obs = (double *)malloc (sizeof (double) * nvar);
01804 res = (double *)calloc (paramct, sizeof (double));
01805 scat= (double *)malloc (sizeof (double) * nvar);
01806 err = (double *)calloc (Err_ct,sizeof (double));
01807 weights = (double *)malloc (sizeof (double) * 4);
01808
01809 MPI_Barrier(MPI_COMM_WORLD);
01810
01811 #if TAKEPREV == 1
01812 double *PrevErrLocal, *PrevResLocal, *preverr, *prevres;
01813 PrevErrLocal=(double *)malloc(sizeof(double)*imgpixlocal*Err_ct);
01814 PrevResLocal=(double *)malloc(sizeof(double)*imgpixlocal*paramct);
01815 preverr = (double *)calloc (Err_ct,sizeof (double));
01816 prevres = (double *)malloc (sizeof (double) * paramct);
01817
01818 MPI_Barrier(MPI_COMM_WORLD);
01819 ibuff=(int *)malloc(sizeof(int)*1);
01820 ibuff[0] = iexistprev;
01821 MPI_Bcast(ibuff,1,MPI_INT,0,MPI_COMM_WORLD);
01822 iexistprev = ibuff[0];
01823 free(ibuff);
01824 MPI_Barrier(MPI_COMM_WORLD);
01825 #endif
01826
01827 #if CYCLPRLL == 1
01828 int *jobassignmapLocal;
01829 jobassignmapLocal = (int *)malloc(sizeof(int) * jobnum);
01830
01831 if (mpi_rank == 0)
01832 {
01833 myrank = mpi_rank;
01834 nprocs = mpi_size;
01835 numpix = imgpix;
01836 istart=0;
01837 iend =jobnum-1;
01838
01839 for (n = istart ; n < iend+1 ; n++){jobassignmapLocal[n -istart] = jobassignmap[n];}
01840
01841 if (mpi_size > 1)
01842 {
01843 int irank;
01844 for(irank = 1; irank < mpi_size; irank++)
01845 {
01846 int mpi_dest;
01847 int ibufsize;
01848 int *ibufsend;
01849 mpi_dest = irank;
01850 istart=0;
01851 iend =jobnum-1;
01852 ibufsize = (iend-istart+1) * 1;
01853 ibufsend= (int*)malloc(sizeof(int) * ibufsize);
01854 for (n = istart ; n < iend+1 ; n++){ibufsend[n -istart] = jobassignmap[n+mpi_dest*jobnum];}
01855 mpi_tag = 1000 + irank;
01856 MPI_Send(ibufsend, ibufsize, MPI_INTEGER, mpi_dest, mpi_tag, MPI_COMM_WORLD);
01857 free(ibufsend);
01858 }
01859 }
01860 }
01861 else
01862 {
01863
01864 int mpi_from = 0;
01865 int ibufsize;
01866 int *ibufrecv;
01867 istart=0;
01868 iend =jobnum-1;
01869 ibufsize = (iend-istart+1) * 1;
01870 ibufrecv = (int*)malloc(sizeof(int) * ibufsize);
01871
01872 mpi_tag = 1000 + mpi_rank;
01873 MPI_Recv(ibufrecv, ibufsize, MPI_INTEGER, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
01874 for (n = istart ; n < iend+1 ; n++){jobassignmapLocal[n-istart] = ibufrecv[n-istart];}
01875 free(ibufrecv);
01876 }
01877
01878 MPI_Barrier(MPI_COMM_WORLD);
01879 if (mpi_rank == 0) printf(" job assignment address data had propagated to all PE.\n");
01880 #endif // end-if CYCLPRLL is 1
01881
01882
01883 if (mpi_rank == 0)
01884 {
01885 myrank = mpi_rank;
01886 nprocs = mpi_size;
01887 numpix = imgpix;
01888 #if CYCLPRLL == 1
01889 istart=0;
01890 iend =jobnum-1;
01891 #else
01892 #if EQUIAREA == 1
01893 istart=istartall[myrank];
01894 iend=iendall[myrank];
01895 #else
01896 para_range(myrank,nprocs,numpix,&istart,&iend);
01897 #endif
01898 #endif
01899
01900 #if CYCLPRLL == 1
01901 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < nvar; m++){dataLocal[(n-istart)*nvar+m] = data[jobassignmap[n] + m*imgpix];}}
01902 #else
01903 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < nvar; m++){dataLocal[(n-istart)*nvar+m] = data[n + m*imgpix];}}
01904 #endif
01905
01906 if (mpi_size > 1)
01907 {
01908 int irank;
01909 for(irank = 1; irank < mpi_size; irank++)
01910 {
01911 int mpi_dest;
01912 int ibufsize;
01913 float *fbufsend;
01914 mpi_dest = irank;
01915 #if CYCLPRLL == 1
01916 istart=0;
01917 iend =jobnum-1;
01918 #else
01919 #if EQUIAREA == 1
01920 istart=istartall[mpi_dest];
01921 iend=iendall[mpi_dest];
01922 #else
01923 para_range(mpi_dest,nprocs,numpix,&istart,&iend);
01924 #endif
01925 #endif
01926 ibufsize = (iend-istart+1) * nvar;
01927 fbufsend= (float*)malloc(sizeof(float) * ibufsize);
01928 #if CYCLPRLL == 1
01929 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];}}
01930 #else
01931 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < nvar; m++){fbufsend[(n-istart)*nvar+m] = data[n + m*imgpix];}}
01932 #endif
01933 mpi_tag = 1400 + irank;
01934 MPI_Send(fbufsend, ibufsize, MPI_REAL, mpi_dest, mpi_tag, MPI_COMM_WORLD);
01935 free(fbufsend);
01936 }
01937 }
01938 }
01939 else
01940 {
01941 int mpi_from = 0;
01942 int ibufsize;
01943 float *fbufrecv;
01944 #if CYCLPRLL == 1
01945 istart=0;
01946 iend =jobnum-1;
01947 #else
01948 #if EQUIAREA == 1
01949 istart=istartall[myrank];
01950 iend=iendall[myrank];
01951 #else
01952 para_range(myrank,nprocs,numpix,&istart,&iend);
01953 #endif
01954 #endif
01955 ibufsize = (iend-istart+1) * nvar;
01956 fbufrecv = (float*)malloc(sizeof(float) * ibufsize);
01957 mpi_tag = 1400 + mpi_rank;
01958 MPI_Recv(fbufrecv, ibufsize, MPI_REAL, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
01959 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < nvar; m++){dataLocal[(n-istart)*nvar+m] = fbufrecv[(n-istart)*nvar+m];}}
01960 free(fbufrecv);
01961 }
01962
01963 MPI_Barrier(MPI_COMM_WORLD);
01964 if (mpi_rank == 0) printf("input data had propagated to all PE.\n");
01965
01966
01967 if (mpi_rank == 0)
01968 {
01969 myrank = mpi_rank;
01970 nprocs = mpi_size;
01971 numpix = imgpix;
01972 #if CYCLPRLL == 1
01973 istart=0;
01974 iend =jobnum-1;
01975 #else
01976 #if EQUIAREA == 1
01977 istart=istartall[myrank];
01978 iend=iendall[myrank];
01979 #else
01980 para_range(myrank,nprocs,numpix,&istart,&iend);
01981 #endif
01982 #endif
01983
01984 #if CYCLPRLL == 1
01985 for (n = istart ; n < iend+1 ; n++){nan_mapLocal[n -istart] = nan_map[jobassignmap[n]];}
01986 #else
01987 for (n = istart ; n < iend+1 ; n++){nan_mapLocal[n -istart] = nan_map[n];}
01988 #endif
01989
01990 if (mpi_size > 1)
01991 {
01992 int irank;
01993 for(irank = 1; irank < mpi_size; irank++)
01994 {
01995 int mpi_dest;
01996 int ibufsize;
01997 int *ibufsend;
01998 mpi_dest = irank;
01999 #if CYCLPRLL == 1
02000 istart=0;
02001 iend =jobnum-1;
02002 #else
02003 #if EQUIAREA == 1
02004 istart=istartall[mpi_dest];
02005 iend=iendall[mpi_dest];
02006 #else
02007 para_range(mpi_dest,nprocs,numpix,&istart,&iend);
02008 #endif
02009 #endif
02010 ibufsize = (iend-istart+1) * 1;
02011 ibufsend= (int*)malloc(sizeof(int) * ibufsize);
02012 #if CYCLPRLL == 1
02013 for (n = istart ; n < iend+1 ; n++){ibufsend[n -istart] = nan_map[jobassignmap[n+jobnum*mpi_dest]];}
02014 #else
02015 for (n = istart ; n < iend+1 ; n++){ibufsend[n -istart] = nan_map[n];}
02016 #endif
02017 mpi_tag = 1500 + irank;
02018 MPI_Send(ibufsend, ibufsize, MPI_INTEGER, mpi_dest, mpi_tag, MPI_COMM_WORLD);
02019 free(ibufsend);
02020 }
02021 }
02022 }
02023 else
02024 {
02025
02026 int mpi_from = 0;
02027 int ibufsize;
02028 int *ibufrecv;
02029 #if CYCLPRLL == 1
02030 istart=0;
02031 iend =jobnum-1;
02032 #else
02033 #if EQUIAREA == 1
02034 istart=istartall[myrank];
02035 iend=iendall[myrank];
02036 #else
02037 para_range(myrank,nprocs,numpix,&istart,&iend);
02038 #endif
02039 #endif
02040 ibufsize = (iend-istart+1) * 1;
02041 ibufrecv = (int*)malloc(sizeof(int) * ibufsize);
02042 mpi_tag = 1500 + mpi_rank;
02043 MPI_Recv(ibufrecv, ibufsize, MPI_INTEGER, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
02044 for (n = istart ; n < iend+1 ; n++){nan_mapLocal[n-istart] = ibufrecv[n-istart];}
02045 free(ibufrecv);
02046 }
02047
02048 MPI_Barrier(MPI_COMM_WORLD);
02049 if (mpi_rank == 0) printf("mask data had propagated to all PE.\n");
02050
02051 #if TAKEPREV == 1
02052
02053 if (mpi_rank == 0)
02054 {
02055 myrank = mpi_rank;
02056 nprocs = mpi_size;
02057 numpix = imgpix;
02058 #if CYCLPRLL == 1
02059 istart=0;
02060 iend =jobnum-1;
02061 #else
02062 #if EQUIAREA == 1
02063 istart=istartall[myrank];
02064 iend=iendall[myrank];
02065 #else
02066 para_range(myrank,nprocs,numpix,&istart,&iend);
02067 #endif
02068 #endif
02069
02070 #if CYCLPRLL == 1
02071 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < paramct; m++){PrevResLocal[(n-istart)*paramct+m] = prevdata[jobassignmap[n] + m *imgpix];}}
02072 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];}}
02073 #else
02074 for (n = istart ; n < iend+1 ; n++){for (m = 0; m < paramct; m++){PrevResLocal[(n-istart)*paramct+m] = prevdata[n + m *imgpix];}}
02075 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];}}
02076 #endif
02077
02078 if (mpi_size > 1)
02079 {
02080 int irank;
02081 for(irank = 1; irank < mpi_size; irank++)
02082 {
02083 int mpi_dest;
02084 int ibufsize;
02085 float *fbufsend;
02086 mpi_dest = irank;
02087 #if CYCLPRLL == 1
02088 istart=0;
02089 iend =jobnum-1;
02090 #else
02091 #if EQUIAREA == 1
02092 istart=istartall[mpi_dest];
02093 iend=iendall[mpi_dest];
02094 #else
02095 para_range(mpi_dest,nprocs,numpix,&istart,&iend);
02096 #endif
02097 #endif
02098 ibufsize = (iend-istart+1) * (paramct + Err_ct);
02099 fbufsend= (float*)malloc(sizeof(float) * ibufsize);
02100 #if CYCLPRLL == 1
02101 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];}}
02102 #else
02103 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];}}
02104 #endif
02105 mpi_tag = 1600 + irank;
02106 MPI_Send(fbufsend, ibufsize, MPI_REAL, mpi_dest, mpi_tag, MPI_COMM_WORLD);
02107 free(fbufsend);
02108 }
02109 }
02110 }
02111 else
02112 {
02113 int mpi_from = 0;
02114 int ibufsize;
02115 float *fbufrecv;
02116 #if CYCLPRLL == 1
02117 istart=0;
02118 iend =jobnum-1;
02119 #else
02120 #if EQUIAREA == 1
02121 istart=istartall[myrank];
02122 iend=iendall[myrank];
02123 #else
02124 para_range(myrank,nprocs,numpix,&istart,&iend);
02125 #endif
02126 #endif
02127 ibufsize = (iend-istart+1) * (paramct + Err_ct);
02128 fbufrecv = (float*)malloc(sizeof(float) * ibufsize);
02129 mpi_tag = 1600 + mpi_rank;
02130 MPI_Recv(fbufrecv, ibufsize, MPI_REAL, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
02131 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 ];}}
02132 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];}}
02133 free(fbufrecv);
02134 }
02135 MPI_Barrier(MPI_COMM_WORLD);
02136 if (mpi_rank == 0) free(prevdata);
02137 if (mpi_rank == 0) printf("previous inv. data had propagated to all PE.\n");
02138 MPI_Barrier(MPI_COMM_WORLD);
02139 #endif
02140
02141 #if VLOSINIT == 1
02142
02143 if (mpi_rank == 0)
02144 {
02145 myrank = mpi_rank;
02146 nprocs = mpi_size;
02147 numpix = imgpix;
02148 #if CYCLPRLL == 1
02149 istart=0;
02150 iend =jobnum-1;
02151 #else
02152 #if EQUIAREA == 1
02153 istart=istartall[myrank];
02154 iend=iendall[myrank];
02155 #else
02156 para_range(myrank,nprocs,numpix,&istart,&iend);
02157 #endif
02158 #endif
02159
02160 #if CYCLPRLL == 1
02161 for (n = istart ; n < iend+1 ; n++){vlos_initLocal[n-istart] = vlos_init[jobassignmap[n]];}
02162 #else
02163 for (n = istart ; n < iend+1 ; n++){vlos_initLocal[n-istart] = vlos_init[n];}
02164 #endif
02165
02166 if (mpi_size > 1)
02167 {
02168 int irank;
02169 for(irank = 1; irank < mpi_size; irank++)
02170 {
02171 int mpi_dest;
02172 int ibufsize;
02173 float *fbufsend;
02174 mpi_dest = irank;
02175 #if CYCLPRLL == 1
02176 istart=0;
02177 iend =jobnum-1;
02178 #else
02179 #if EQUIAREA == 1
02180 istart=istartall[mpi_dest];
02181 iend=iendall[mpi_dest];
02182 #else
02183 para_range(mpi_dest,nprocs,numpix,&istart,&iend);
02184 #endif
02185 #endif
02186 ibufsize = (iend-istart+1) * 1;
02187 fbufsend= (float*)malloc(sizeof(float) * ibufsize);
02188 #if CYCLPRLL == 1
02189 for (n = istart ; n < iend+1 ; n++){fbufsend[n-istart] = vlos_init[jobassignmap[n+jobnum*mpi_dest]];}
02190 #else
02191 for (n = istart ; n < iend+1 ; n++){fbufsend[n-istart] = vlos_init[n];}
02192 #endif
02193 mpi_tag = 1900 + irank;
02194 MPI_Send(fbufsend, ibufsize, MPI_REAL, mpi_dest, mpi_tag, MPI_COMM_WORLD);
02195 free(fbufsend);
02196 }
02197 }
02198 }
02199 else
02200 {
02201 int mpi_from = 0;
02202 int ibufsize;
02203 float *fbufrecv;
02204 #if CYCLPRLL == 1
02205 istart=0;
02206 iend =jobnum-1;
02207 #else
02208 #if EQUIAREA == 1
02209 istart=istartall[myrank];
02210 iend=iendall[myrank];
02211 #else
02212 para_range(myrank,nprocs,numpix,&istart,&iend);
02213 #endif
02214 #endif
02215 ibufsize = (iend-istart+1) * 1;
02216 fbufrecv = (float*)malloc(sizeof(float) * ibufsize);
02217 mpi_tag = 1900 + mpi_rank;
02218 MPI_Recv(fbufrecv, ibufsize, MPI_REAL, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
02219 for (n = istart ; n < iend+1 ; n++){vlos_initLocal[n-istart] = fbufrecv[n-istart];}
02220 free(fbufrecv);
02221 }
02222 MPI_Barrier(MPI_COMM_WORLD);
02223 if (mpi_rank == 0) free(vlos_init);
02224 if (mpi_rank == 0) printf("VLOS_INIT data had propagated to all PE.\n");
02225 MPI_Barrier(MPI_COMM_WORLD);
02226 #endif
02227
02228 #if MGSTINIT == 1
02229
02230 if (mpi_rank == 0)
02231 {
02232 myrank = mpi_rank;
02233 nprocs = mpi_size;
02234 numpix = imgpix;
02235 #if CYCLPRLL == 1
02236 istart=0;
02237 iend =jobnum-1;
02238 #else
02239 #if EQUIAREA == 1
02240 istart=istartall[myrank];
02241 iend=iendall[myrank];
02242 #else
02243 para_range(myrank,nprocs,numpix,&istart,&iend);
02244 #endif
02245 #endif
02246
02247 #if CYCLPRLL == 1
02248 for (n = istart ; n < iend+1 ; n++){mgst_initLocal[n-istart] = mgst_init[jobassignmap[n]];}
02249 #else
02250 for (n = istart ; n < iend+1 ; n++){mgst_initLocal[n-istart] = mgst_init[n];}
02251 #endif
02252
02253 if (mpi_size > 1)
02254 {
02255 int irank;
02256 for(irank = 1; irank < mpi_size; irank++)
02257 {
02258 int mpi_dest;
02259 int ibufsize;
02260 float *fbufsend;
02261 mpi_dest = irank;
02262 #if CYCLPRLL == 1
02263 istart=0;
02264 iend =jobnum-1;
02265 #else
02266 #if EQUIAREA == 1
02267 istart=istartall[mpi_dest];
02268 iend=iendall[mpi_dest];
02269 #else
02270 para_range(mpi_dest,nprocs,numpix,&istart,&iend);
02271 #endif
02272 #endif
02273 ibufsize = (iend-istart+1) * 1;
02274 fbufsend= (float*)malloc(sizeof(float) * ibufsize);
02275 #if CYCLPRLL == 1
02276 for (n = istart ; n < iend+1 ; n++){fbufsend[n-istart] = mgst_init[jobassignmap[n+jobnum*mpi_dest]];}
02277 #else
02278 for (n = istart ; n < iend+1 ; n++){fbufsend[n-istart] = mgst_init[n];}
02279 #endif
02280 mpi_tag = 2000 + irank;
02281 MPI_Send(fbufsend, ibufsize, MPI_REAL, mpi_dest, mpi_tag, MPI_COMM_WORLD);
02282 free(fbufsend);
02283 }
02284 }
02285 }
02286 else
02287 {
02288 int mpi_from = 0;
02289 int ibufsize;
02290 float *fbufrecv;
02291 #if CYCLPRLL == 1
02292 istart=0;
02293 iend =jobnum-1;
02294 #else
02295 #if EQUIAREA == 1
02296 istart=istartall[myrank];
02297 iend=iendall[myrank];
02298 #else
02299 para_range(myrank,nprocs,numpix,&istart,&iend);
02300 #endif
02301 #endif
02302 ibufsize = (iend-istart+1) * 1;
02303 fbufrecv = (float*)malloc(sizeof(float) * ibufsize);
02304 mpi_tag = 2000 + mpi_rank;
02305 MPI_Recv(fbufrecv, ibufsize, MPI_REAL, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
02306 for (n = istart ; n < iend+1 ; n++){mgst_initLocal[n-istart] = fbufrecv[n-istart];}
02307 free(fbufrecv);
02308 }
02309 MPI_Barrier(MPI_COMM_WORLD);
02310 if (mpi_rank == 0) free(mgst_init);
02311 if (mpi_rank == 0) printf("MGST_INIT data had propagated to all PE.\n");
02312 MPI_Barrier(MPI_COMM_WORLD);
02313 #endif
02314
02315
02316 if (mpi_rank == 0) printf("\n----------- inversion initializations ----------------- \n");
02317
02318 vfisvalloc_(&NUM_LAMBDA_FILTER,&NUM_LAMBDA,&NUM_LAMBDA_synth);
02319
02320
02321 #if NLEVPIXL != 1
02322 line_init_(&LAMBDA_0,&LAMBDA_B,&NOISE_LEVEL);
02323 if (verbose){printf("done line_init for mpi_rank %d\n",mpi_rank);}
02324 wave_init_ (&LAMBDA_MIN_synth,&DELTA_LAMBDA,&NUM_LAMBDA_synth);
02325 if (verbose){printf("done wave_init for mpi_rank %d\n",mpi_rank );}
02326 filt_init_ (&NUM_LAMBDA_FILTER,&WSPACING, &NUM_LAMBDA);
02327 if (verbose){printf("done filt_init for mpi_rank %d\n",mpi_rank);}
02328 #endif
02329
02330
02331
02332
02333
02334
02335 int location,column,row,ratio,x0,y0,x1,y1,loc1,loc2,loc3,loc4;
02336 double xa,xb,ya,yb,X0,Y0,Rsun;
02337 int nx2=128,ny2=128;
02338 int nelemPHASENT =4*nx2*ny2;
02339 int nelemCONTRASTT=3*nx2*ny2;
02340 int FSNREC;
02341 referencenlam=7000;
02342 FSR =(double *)malloc(7 *sizeof(double));
02343 lineref =(double *)malloc(referencenlam *sizeof(double));
02344 wavelengthref=(double *)malloc(referencenlam *sizeof(double));
02345 phaseNT =(double *)malloc(nelemPHASENT *sizeof(double));
02346 contrastNT =(double *)malloc(nelemPHASENT *sizeof(double));
02347 contrastT =(double *)malloc(nelemCONTRASTT*sizeof(double));
02348 wavelengthbd =(double *)malloc(201 *sizeof(double));
02349 blockerbd =(double *)malloc(201 *sizeof(double));
02350 wavelengthd =(double *)malloc(401 *sizeof(double));
02351 frontwindowd =(double *)malloc(401 *sizeof(double));
02352 phaseT =(double *)malloc(nelemCONTRASTT*sizeof(double));
02353
02354 printf("We should be running initialize_vfisv_filter\n");
02355
02356 if (mpi_rank == 0)
02357 {
02358 int ierr, status;
02359 stokestime = drms_getkey_time(inRec,"T_REC",&status);
02360 char timestr[26];
02361 sprint_time(timestr,stokestime,"TAI",0);
02362 printf("Looking for phasemap for T_REC %s \n",timestr);
02363 ierr = initialize_vfisv_filter(
02364 wavelengthd,frontwindowd,&nfront,wavelengthbd,blockerbd,
02365 &nblocker,¢erblocker,phaseNT,phaseT,contrastNT,contrastT,FSR,lineref,wavelengthref,
02366 &referencenlam,&HCME1,&HCMWB,&HCMNB,&HCMPOL,stokestime,&FSNREC);
02367 }
02368
02369
02370 ibuff=(int *)malloc(sizeof(int)*8);
02371 ibuff[0]=nfront;
02372 ibuff[1]=nblocker;
02373 ibuff[2]=centerblocker;
02374 ibuff[3]=referencenlam;
02375 ibuff[4]=HCME1;
02376 ibuff[5]=HCMWB;
02377 ibuff[6]=HCMNB;
02378 ibuff[7]=HCMPOL;
02379 MPI_Bcast(ibuff,8,MPI_INT,0,MPI_COMM_WORLD);
02380 nfront =ibuff[0];
02381 nblocker =ibuff[1];
02382 centerblocker=ibuff[2];
02383 referencenlam=ibuff[3];
02384 HCME1 =ibuff[4];
02385 HCMWB =ibuff[5];
02386 HCMNB =ibuff[6];
02387 HCMPOL =ibuff[7];
02388 free(ibuff);
02389
02390 double *fbigbuf;
02391 int bigbufsize;
02392 bigbufsize=7+referencenlam+referencenlam+nelemPHASENT+nelemPHASENT+nelemCONTRASTT+201+201+401+401+nelemCONTRASTT;
02393 fbigbuf=(double *)malloc(bigbufsize*sizeof(double));
02394 MPI_Barrier(MPI_COMM_WORLD);
02395 if (mpi_rank == 0)
02396 {
02397 int icount;
02398 icount = 0;
02399 for (i=0;i< 7;i++){fbigbuf[icount]=FSR[i] ;icount++;}
02400 for (i=0;i< referencenlam;i++){fbigbuf[icount]=lineref[i] ;icount++;}
02401 for (i=0;i< referencenlam;i++){fbigbuf[icount]=wavelengthref[i];icount++;}
02402 for (i=0;i< nelemPHASENT;i++){fbigbuf[icount]=phaseNT[i] ;icount++;}
02403 for (i=0;i< nelemPHASENT;i++){fbigbuf[icount]=contrastNT[i] ;icount++;}
02404 for (i=0;i<nelemCONTRASTT;i++){fbigbuf[icount]=contrastT[i] ;icount++;}
02405 for (i=0;i< 201;i++){fbigbuf[icount]=wavelengthbd[i] ;icount++;}
02406 for (i=0;i< 201;i++){fbigbuf[icount]=blockerbd[i] ;icount++;}
02407 for (i=0;i< 401;i++){fbigbuf[icount]=wavelengthd[i] ;icount++;}
02408 for (i=0;i< 401;i++){fbigbuf[icount]=frontwindowd[i] ;icount++;}
02409 for (i=0;i<nelemCONTRASTT;i++){fbigbuf[icount]=phaseT[i] ;icount++;}
02410 if (icount != bigbufsize)
02411 {
02412 printf("Icount BigBufSize = %d %d\n",icount,bigbufsize);
02413 DIE("Mistake at large float buffer, at debug point 1 !\n");
02414 }
02415 }
02416 MPI_Barrier(MPI_COMM_WORLD);
02417 MPI_Bcast(fbigbuf,bigbufsize,MPI_DOUBLE,0,MPI_COMM_WORLD);
02418 if (mpi_rank > 0)
02419 {
02420 int icount;
02421 icount = 0;
02422 for (i=0;i< 7;i++){FSR[i] =fbigbuf[icount];icount++;}
02423 for (i=0;i< referencenlam;i++){lineref[i] =fbigbuf[icount];icount++;}
02424 for (i=0;i< referencenlam;i++){wavelengthref[i]=fbigbuf[icount];icount++;}
02425 for (i=0;i< nelemPHASENT;i++){phaseNT[i] =fbigbuf[icount];icount++;}
02426 for (i=0;i< nelemPHASENT;i++){contrastNT[i] =fbigbuf[icount];icount++;}
02427 for (i=0;i<nelemCONTRASTT;i++){contrastT[i] =fbigbuf[icount];icount++;}
02428 for (i=0;i< 201;i++){wavelengthbd[i] =fbigbuf[icount];icount++;}
02429 for (i=0;i< 201;i++){blockerbd[i] =fbigbuf[icount];icount++;}
02430 for (i=0;i< 401;i++){wavelengthd[i] =fbigbuf[icount];icount++;}
02431 for (i=0;i< 401;i++){frontwindowd[i] =fbigbuf[icount];icount++;}
02432 for (i=0;i<nelemCONTRASTT;i++){phaseT[i] =fbigbuf[icount];icount++;}
02433 if (icount != bigbufsize)
02434 {
02435 printf("Icount BigBufSize = %d %d\n",icount,bigbufsize);
02436 DIE("Mistake at large float buffer, at debug point 2 !\n");
02437 }
02438 }
02439 free(fbigbuf);
02440 if (verbose){printf("done initialize_vfisv_filter by S.C., for mpi_rank %d\n",mpi_rank);}
02441 MPI_Barrier(MPI_COMM_WORLD);
02442
02443
02444 double norm_factor;
02445 #if NRMLFLTR == 1
02446 if (mpi_rank == 0)
02447 {
02448
02449 column = 2048;
02450 row = 2048;
02451 ratio = 4096/nx2;
02452
02453 x0 = (column/ratio);
02454 y0 = (row/ratio);
02455 x1 = x0+1;
02456 y1 = y0+1;
02457 if(x1 >= nx2){x0 = x0-1; x1 = x1-1;}
02458 if(y1 >= ny2){y0 = y0-1; y1 = y1-1;}
02459 xa = ((double)x1-(double)(column % ratio)/(double)ratio-(double)x0);
02460 xb = ((double)(column % ratio)/(double)ratio);
02461 ya = ((double)y1-(double)(row % ratio)/(double)ratio-(double)y0);
02462 yb = ((double)(row % ratio)/(double)ratio);
02463 loc1 = x0+y0*nx2;
02464 loc2 = x1+y0*nx2;
02465 loc3 = x0+y1*nx2;
02466 loc4 = x1+y1*nx2;
02467 phaseNTi[0] = ya*(phaseNT[loc1 ]*xa+phaseNT[loc2 ]*xb)
02468 +yb*(phaseNT[loc3 ]*xa+phaseNT[loc4 ]*xb);
02469 phaseNTi[1] = ya*(phaseNT[loc1+ nx2*ny2]*xa+phaseNT[loc2+nx2*ny2 ]*xb)
02470 +yb*(phaseNT[loc3+ nx2*ny2]*xa+phaseNT[loc4+ nx2*ny2]*xb);
02471 phaseNTi[2] = ya*(phaseNT[loc1+2*nx2*ny2]*xa+phaseNT[loc2+2*nx2*ny2]*xb)
02472 +yb*(phaseNT[loc3+2*nx2*ny2]*xa+phaseNT[loc4+2*nx2*ny2]*xb);
02473 phaseNTi[3] = ya*(phaseNT[loc1+3*nx2*ny2]*xa+phaseNT[loc2+3*nx2*ny2]*xb)
02474 +yb*(phaseNT[loc3+3*nx2*ny2]*xa+phaseNT[loc4+3*nx2*ny2]*xb);
02475 phaseTi[0] = ya*(phaseT[loc1*3 ]*xa+phaseT[loc2*3 ]*xb)+yb*(phaseT[loc3*3 ]*xa+phaseT[loc4*3 ]*xb);
02476 phaseTi[1] = ya*(phaseT[loc1*3+1]*xa+phaseT[loc2*3+1]*xb)+yb*(phaseT[loc3*3+1]*xa+phaseT[loc4*3+1]*xb);
02477 phaseTi[2] = ya*(phaseT[loc1*3+2]*xa+phaseT[loc2*3+2]*xb)+yb*(phaseT[loc3*3+2]*xa+phaseT[loc4*3+2]*xb);
02478 contrastNTi[0]= ya*(contrastNT[loc1 ]*xa+contrastNT[loc2 ]*xb)
02479 +yb*(contrastNT[loc3 ]*xa+contrastNT[loc4 ]*xb);
02480 contrastNTi[1]= ya*(contrastNT[loc1+ nx2*ny2]*xa+contrastNT[loc2+ nx2*ny2]*xb)
02481 +yb*(contrastNT[loc3+ nx2*ny2]*xa+contrastNT[loc4+ nx2*ny2]*xb);
02482 contrastNTi[2]= ya*(contrastNT[loc1+2*nx2*ny2]*xa+contrastNT[loc2+2*nx2*ny2]*xb)
02483 +yb*(contrastNT[loc3+2*nx2*ny2]*xa+contrastNT[loc4+2*nx2*ny2]*xb);
02484 contrastNTi[3]= ya*(contrastNT[loc1+3*nx2*ny2]*xa+contrastNT[loc2+3*nx2*ny2]*xb)
02485 +yb*(contrastNT[loc3+3*nx2*ny2]*xa+contrastNT[loc4+3*nx2*ny2]*xb);
02486 contrastTi[0] = ya*(contrastT[loc1 ]*xa+contrastT[loc2 ]*xb)
02487 +yb*(contrastT[loc3 ]*xa+contrastT[loc4 ]*xb);
02488 contrastTi[1] = ya*(contrastT[loc1+ nx2*ny2]*xa+contrastT[loc2+ nx2*ny2]*xb)
02489 +yb*(contrastT[loc3+ nx2*ny2]*xa+contrastT[loc4+ nx2*ny2]*xb);
02490 contrastTi[2] = ya*(contrastT[loc1+2*nx2*ny2]*xa+contrastT[loc2+2*nx2*ny2]*xb)
02491 +yb*(contrastT[loc3+2*nx2*ny2]*xa+contrastT[loc4+2*nx2*ny2]*xb);
02492 X0 = (double)crpixx-1.0;
02493 Y0 = (double)crpixy-1.0;
02494 Rsun = (double)asin(rsun_ref/dsun_obs)/3.14159265358979e0*180.0*3600.0/cdeltx;
02495 distance = sqrt(((double)row-Y0)*((double)row-Y0)+((double)column-X0)*((double)column-X0));
02496 distance = cos(asin(distance/Rsun));
02497 vfisv_filter(NUM_LAMBDA_FILTERc,NUM_LAMBDAc,filters,LAMBDA_MINc,DELTA_LAMBDAc,
02498 wavelengthd,frontwindowd,nfront,wavelengthbd,blockerbd,nblocker,centerblocker,
02499 phaseNTi,phaseTi,contrastNTi,contrastTi,FSR,lineref,wavelengthref,referencenlam,distance,HCME1,HCMWB,HCMNB,HCMPOL);
02500
02501 double *sum_filt;
02502 sum_filt = (double *)malloc (sizeof (double) * NUM_LAMBDA_FILTER);
02503 double sumsum, aveave;
02504 for (i = 0; i < NUM_LAMBDA_FILTER; i++)
02505 {
02506 sum_filt[i] = 0.0;
02507 for (j = 0; j < NUM_LAMBDA; j++){sum_filt[i] = sum_filt[i] + filters[i][j];
02508 } }
02509 sumsum = 0.0;
02510 for (i = 0; i < NUM_LAMBDA_FILTER; i++){sumsum = sumsum + sum_filt[i];}
02511 aveave = sumsum / ((double)NUM_LAMBDA_FILTER);
02512 if (isnan(aveave) || fabs(aveave) < 1e-10){aveave = 1.0;}
02513 norm_factor = aveave;
02514 free(sum_filt);
02515 }
02516
02517 {
02518 MPI_Barrier(MPI_COMM_WORLD);
02519 fbuff=(float *)malloc(sizeof(float)*1);
02520 fbuff[0] = norm_factor;
02521 MPI_Bcast(fbuff,1,MPI_FLOAT,0,MPI_COMM_WORLD);
02522 norm_factor = fbuff[0];
02523 free(fbuff);
02524 if (verbose) {printf(" normalization factor reaching to %d PE is %f\n",mpi_rank,norm_factor);}
02525 MPI_Barrier(MPI_COMM_WORLD);
02526 }
02527 #else
02528 norm_factor = 1.0;
02529 #endif // end if NRMLFLTR is 1 or not
02530 if (mpi_rank == 0){printf(" normalization factor for filter is %f\n", norm_factor);}
02531
02532
02533 inv_init_(&NUM_ITERATIONS,&SVD_TOLERANCE,&CHI2_STOP,&POLARIZATION_THRESHOLD,&INTENSITY_THRESHOLD);
02534 if (verbose){printf("done inv_init\n");}
02535 free_init_(list_free_params);
02536 if (verbose){printf("done list_free_params for mpi_rank %d\n", mpi_rank);}
02537
02538 if (list_free_params[3] == 0) voigt_init_();
02539 for (n=0; n< nvar; n++) scat[n]=0.0;
02540
02541 MPI_Barrier(MPI_COMM_WORLD);
02542 if (mpi_rank == 0) printf("\n----------- inversion initializations done ------------ \n");
02543
02544
02545 if (mpi_rank == 0) printf("\n----------- finally, do inversion in parallel --------- \n");
02546
02547 time(&starttime1);
02548
02549 myrank = mpi_rank;
02550 nprocs = mpi_size;
02551 numpix = imgpix;
02552 #if CYCLPRLL == 1
02553 istart=0;
02554 iend =jobnum-1;
02555 #else
02556 #if EQUIAREA == 1
02557 istart=istartall[myrank];
02558 iend =iendall[myrank];
02559 #else
02560 para_range(myrank,nprocs,numpix,&istart,&iend);
02561 #endif
02562 #endif
02563 int pixdone;
02564 pixdone = 0;
02565 int pix_noconv;
02566 pix_noconv = 0;
02567
02568 for (n = istart; n < iend + 1; n++)
02569 {
02570 #if CYCLPRLL == 1
02571 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...");}
02572 #endif
02573 if (nan_mapLocal[n-istart] == 0)
02574 {
02575
02576 #if TAKEPREV == 1
02577 if (iexistprev == 1)
02578 {
02579 for (m = 0; m < paramct; m++){prevres[m]=PrevResLocal[(n-istart)*paramct+m];}
02580 for (m = 0; m < Err_ct; m++){preverr[m]=PrevErrLocal[(n-istart)*Err_ct +m];}
02581 }
02582 if (iexistprev == 0)
02583 {
02584 for (m = 0; m < paramct; m++){prevres[m]=NAN;}
02585 for (m = 0; m < Err_ct; m++){preverr[m]=NAN;}
02586 }
02587 #endif
02588
02589 for(m = 0; m < nvar; m++){obs[m]=dataLocal[(n-istart)*nvar+m];}
02590
02591
02592
02593
02594
02595
02596
02597
02598
02599
02600
02601
02602 int nccd;
02603 #if CYCLPRLL == 1
02604 nccd = jobassignmapLocal[n];
02605 #else
02606 nccd = n;
02607 #endif
02608
02609
02610
02611 {
02612 int nloc, iloc, jloc;
02613 float filoc, fjloc;
02614 iloc = nccd % cols;
02615 jloc = nccd / cols;
02616 filoc = (float)(iloc) / (float)(cols);
02617 fjloc = (float)(jloc) / (float)(rows);
02618 filoc = filoc * 4096.0 + 0.000000001;
02619 fjloc = fjloc * 4096.0 + 0.000000001;
02620 iloc = (int)(filoc);
02621 jloc = (int)(fjloc);
02622 nloc = iloc + 4096 * jloc;
02623
02624
02625
02626 column =nloc % 4096;
02627 row =nloc / 4096;
02628 ratio =4096 / nx2;
02629 }
02630
02631
02632
02633
02634
02635
02636
02637
02638 x0 = (column/ratio);
02639 y0 = (row/ratio);
02640 x1 = x0+1;
02641 y1 = y0+1;
02642
02643 if(x1 >= nx2)
02644 {
02645 x0 = x0-1;
02646 x1 = x1-1;
02647 }
02648 if(y1 >= ny2)
02649 {
02650 y0 = y0-1;
02651 y1 = y1-1;
02652 }
02653
02654 xa = ((double)x1-(double)(column % ratio)/(double)ratio-(double)x0);
02655 xb = ((double)(column % ratio)/(double)ratio);
02656 ya = ((double)y1-(double)(row % ratio)/(double)ratio-(double)y0);
02657 yb = ((double)(row % ratio)/(double)ratio);
02658
02659
02660 loc1 = x0+y0*nx2;
02661 loc2 = x1+y0*nx2;
02662 loc3 = x0+y1*nx2;
02663 loc4 = x1+y1*nx2;
02664
02665 phaseNTi[0] = ya*(phaseNT[loc1 ]*xa+phaseNT[loc2 ]*xb)
02666 +yb*(phaseNT[loc3 ]*xa+phaseNT[loc4 ]*xb);
02667 phaseNTi[1] = ya*(phaseNT[loc1+ nx2*ny2]*xa+phaseNT[loc2+nx2*ny2 ]*xb)
02668 +yb*(phaseNT[loc3+ nx2*ny2]*xa+phaseNT[loc4+ nx2*ny2]*xb);
02669 phaseNTi[2] = ya*(phaseNT[loc1+2*nx2*ny2]*xa+phaseNT[loc2+2*nx2*ny2]*xb)
02670 +yb*(phaseNT[loc3+2*nx2*ny2]*xa+phaseNT[loc4+2*nx2*ny2]*xb);
02671 phaseNTi[3] = ya*(phaseNT[loc1+3*nx2*ny2]*xa+phaseNT[loc2+3*nx2*ny2]*xb)
02672 +yb*(phaseNT[loc3+3*nx2*ny2]*xa+phaseNT[loc4+3*nx2*ny2]*xb);
02673 phaseTi[0] = ya*(phaseT[loc1*3 ]*xa+phaseT[loc2*3 ]*xb)+yb*(phaseT[loc3*3 ]*xa+phaseT[loc4*3 ]*xb);
02674 phaseTi[1] = ya*(phaseT[loc1*3+1]*xa+phaseT[loc2*3+1]*xb)+yb*(phaseT[loc3*3+1]*xa+phaseT[loc4*3+1]*xb);
02675 phaseTi[2] = ya*(phaseT[loc1*3+2]*xa+phaseT[loc2*3+2]*xb)+yb*(phaseT[loc3*3+2]*xa+phaseT[loc4*3+2]*xb);
02676 contrastNTi[0]= ya*(contrastNT[loc1 ]*xa+contrastNT[loc2 ]*xb)
02677 +yb*(contrastNT[loc3 ]*xa+contrastNT[loc4 ]*xb);
02678 contrastNTi[1]= ya*(contrastNT[loc1+ nx2*ny2]*xa+contrastNT[loc2+ nx2*ny2]*xb)
02679 +yb*(contrastNT[loc3+ nx2*ny2]*xa+contrastNT[loc4+ nx2*ny2]*xb);
02680 contrastNTi[2]= ya*(contrastNT[loc1+2*nx2*ny2]*xa+contrastNT[loc2+2*nx2*ny2]*xb)
02681 +yb*(contrastNT[loc3+2*nx2*ny2]*xa+contrastNT[loc4+2*nx2*ny2]*xb);
02682 contrastNTi[3]= ya*(contrastNT[loc1+3*nx2*ny2]*xa+contrastNT[loc2+3*nx2*ny2]*xb)
02683 +yb*(contrastNT[loc3+3*nx2*ny2]*xa+contrastNT[loc4+3*nx2*ny2]*xb);
02684 contrastTi[0] = ya*(contrastT[loc1 ]*xa+contrastT[loc2 ]*xb)
02685 +yb*(contrastT[loc3 ]*xa+contrastT[loc4 ]*xb);
02686 contrastTi[1] = ya*(contrastT[loc1+ nx2*ny2]*xa+contrastT[loc2+ nx2*ny2]*xb)
02687 +yb*(contrastT[loc3+ nx2*ny2]*xa+contrastT[loc4+ nx2*ny2]*xb);
02688 contrastTi[2] = ya*(contrastT[loc1+2*nx2*ny2]*xa+contrastT[loc2+2*nx2*ny2]*xb)
02689 +yb*(contrastT[loc3+2*nx2*ny2]*xa+contrastT[loc4+2*nx2*ny2]*xb);
02690 X0 = (double)crpixx-1.0;
02691 Y0 = (double)crpixy-1.0;
02692 Rsun = (double)asin(rsun_ref/dsun_obs)/3.14159265358979e0*180.0*3600.0/cdeltx;
02693 distance = sqrt(((double)row-Y0)*((double)row-Y0)+((double)column-X0)*((double)column-X0));
02694 distance = cos(asin(distance/Rsun));
02695
02696
02697 vfisv_filter(NUM_LAMBDA_FILTERc,NUM_LAMBDAc,filters,LAMBDA_MINc,DELTA_LAMBDAc,
02698 wavelengthd,frontwindowd,nfront,wavelengthbd,blockerbd,nblocker,centerblocker,
02699 phaseNTi,phaseTi,contrastNTi,contrastTi,FSR,lineref,wavelengthref,referencenlam,distance,HCME1,HCMWB,HCMNB,HCMPOL);
02700
02701
02702
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721
02722
02723
02724
02725
02726
02727
02728
02729 int iconverge_flag;
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745 weights[0]=1.0; weights[1]=5.0; weights[2]=5.0; weights[3]=3.5;
02746
02747 #if VLOSINIT == 1
02748 guess[6] = vlos_initLocal[n-istart];
02749 #endif
02750 #if MGSTINIT == 1
02751 guess[5] = mgst_initLocal[n-istart];
02752 #endif
02753
02754
02755 #if NLEVPIXL == 1
02756 double ivalmax, ivalave, CONT;
02757 ivalmax = -100.0e0;
02758 ivalave = 0.0e0;
02759 {
02760 int m;
02761 for (m = 0; m < NUM_LAMBDA_FILTER; m++)
02762 {
02763 double tmpval=obs[0*NUM_LAMBDA_FILTER+m];
02764 ivalave = ivalave + tmpval;
02765 if (tmpval > ivalmax){ivalmax = tmpval;}
02766 }
02767 CONT = ivalmax;
02768 ivalave = ivalave / ((double)(NUM_LAMBDA_FILTER));
02769 ivalave = sqrt(ivalave);
02770 ivalmax = sqrt(ivalmax);
02771 }
02772 NOISE_LEVEL[0] = NOISE_LEVELFI * ivalave;
02773 NOISE_LEVEL[1] = NOISE_LEVELFQ * ivalave;
02774 NOISE_LEVEL[2] = NOISE_LEVELFU * ivalave;
02775 NOISE_LEVEL[3] = NOISE_LEVELFV * ivalave;
02776
02777 lim_init_(&CONT);
02778 line_init_(&LAMBDA_0,&LAMBDA_B,NOISE_LEVEL);
02779 wave_init_ (&LAMBDA_MIN_synth,&DELTA_LAMBDA,&NUM_LAMBDA_synth);
02780 filt_init_ (&NUM_LAMBDA_FILTER,&WSPACING, &NUM_LAMBDA);
02781 #endif
02782
02783
02784
02785 #if NRMLFLTR == 1
02786 for (i = 0; i < NUM_LAMBDA_FILTER; i++){for (j = 0; j < NUM_LAMBDA; j++)
02787 {
02788 filters[i][j] = filters[i][j] / norm_factor;
02789 } }
02790 #endif
02791
02792 invert_ (obs, scat, guess, res, err, filters, &iconverge_flag, weights);
02793
02794
02795
02796
02797
02798
02799
02800
02801
02802
02803
02804 if (err[0] > 12000.0) {err[0] = 12000.0;}
02805 if (err[1] > 180.0) {err[1] = 180.0;}
02806 if (err[2] > 180.0) {err[2] = 180.0;}
02807
02808
02809
02810
02811
02812 if ((iconverge_flag == 4) ||
02813 (iconverge_flag == 5) ||
02814 (iconverge_flag == 1))
02815 {
02816 if (verbose){printf("Hello, this is %2d th PE : found iconverge_flag %d at %9d th pixel.\n", mpi_rank, iconverge_flag, nccd);}
02817 for (j=0; j<paramct; j++){res[j]=NAN;}
02818 for (k=0; k<Err_ct; k++){err[k]=NAN;}
02819 }
02820
02821 FinalConvFlagLocal[n-istart]=iconverge_flag;
02822
02823
02824 if (iconverge_flag > 0)
02825 {
02826 pix_noconv = pix_noconv + 1;
02827 FinalQualMapLocal[n-istart]=0x00000002;
02828 }
02829 else
02830 {
02831 FinalQualMapLocal[n-istart]=0x00000000;
02832 }
02833 for (j=0; j<paramct; j++){FinalResLocal[(n-istart)*paramct+j]=res[j];}
02834 for (k=0; k<Err_ct; k++){FinalErrLocal[(n-istart)*Err_ct +k]=err[k];}
02835
02836 pixdone = pixdone + 1;
02837 }
02838 else
02839 {
02840 float aa=NAN;
02841 FinalConvFlagLocal[n-istart]=1;
02842 FinalQualMapLocal [n-istart]=(int)(aa);
02843 for (j=0; j<paramct; j++){FinalResLocal[(n-istart)*paramct+j]=NAN;}
02844 for (k=0; k<Err_ct; k++){FinalErrLocal[(n-istart)*Err_ct +k]=NAN;}
02845 }
02846 }
02847 if (verbose){printf("Hello, this is %2d th PE : inversion done for %9d pixels. \n", mpi_rank, pixdone);}
02848 if (verbose){printf("Hello, this is %2d th PE : Num of pixel at which solution did not converge = %d\n",mpi_rank,pix_noconv);}
02849 time(&endtime1);
02850 if (verbose){printf("Hello, this is %2d th PE : Time spent %ld\n",mpi_rank,endtime1-starttime1);}
02851 MPI_Barrier(MPI_COMM_WORLD);
02852
02853
02854 int sum_pix_noconv;
02855 int sum_pixdone;
02856 {
02857 int *ibufs, *ibufr;
02858 ibufs = (int *)malloc(sizeof(int)*2);
02859 ibufr = (int *)malloc(sizeof(int)*2);
02860 ibufs[0] = pix_noconv;
02861 ibufs[1] = pixdone;
02862 MPI_Reduce(ibufs,ibufr,2,MPI_INT,MPI_SUM,0,MPI_COMM_WORLD);
02863 if (mpi_rank == 0)
02864 {
02865 sum_pix_noconv = ibufr[0];
02866 sum_pixdone = ibufr[1];
02867 printf("Total num. of pixel processed = %d\n",sum_pixdone);
02868 printf("Total num. of pixel at which solution did not converge = %d\n",sum_pix_noconv);
02869 }
02870 }
02871 MPI_Barrier(MPI_COMM_WORLD);
02872
02873
02874 free(FSR);
02875 free(phaseNT);
02876 free(contrastNT);
02877 free(phaseT);
02878 free(contrastT);
02879 free(wavelengthbd);
02880 free(blockerbd);
02881 free(wavelengthd);
02882 free(frontwindowd);
02883 free(lineref);
02884 free(wavelengthref);
02885
02886
02887 if (mpi_rank == 0)
02888 {
02889 myrank = mpi_rank;
02890 nprocs = mpi_size;
02891 numpix = imgpix;
02892 #if CYCLPRLL == 1
02893 istart=0;
02894 iend =jobnum-1;
02895 #else
02896 #if EQUIAREA == 1
02897 istart=istartall[myrank];
02898 iend=iendall[myrank];
02899 #else
02900 para_range(myrank,nprocs,numpix,&istart,&iend);
02901 #endif
02902 #endif
02903
02904 #if CYCLPRLL == 1
02905 for (n = istart ; n < iend+1 ; n++)
02906 {
02907 for (j=0; j<paramct; j++){FinalRes[(jobassignmap[n]*paramct)+j]=FinalResLocal[(n-istart)*paramct+j];}
02908 for (k=0; k<Err_ct ; k++){FinalErr[(jobassignmap[n]*Err_ct) +k]=FinalErrLocal[(n-istart)*Err_ct +k];}
02909 }
02910 #else
02911 for (n = istart ; n < iend+1 ; n++)
02912 {
02913 for (j=0; j<paramct; j++){FinalRes[(n *paramct)+j]=FinalResLocal[(n-istart)*paramct+j];}
02914 for (k=0; k<Err_ct ; k++){FinalErr[(n *Err_ct) +k]=FinalErrLocal[(n-istart)*Err_ct +k];}
02915 }
02916 #endif
02917
02918 if (mpi_size > 1)
02919 {
02920 printf("now collecting float data from PEs : ");
02921 int irecv;
02922 for (irecv = 1; irecv < mpi_size ; irecv++)
02923 {
02924 printf(" %d ",irecv);
02925 int mpi_from;
02926 nprocs = mpi_size;
02927 numpix = imgpix;
02928 #if CYCLPRLL == 1
02929 istart=0;
02930 iend =jobnum-1;
02931 #else
02932 #if EQUIAREA == 1
02933 istart=istartall[irecv];
02934 iend=iendall[irecv];
02935 #else
02936 para_range(irecv,nprocs,numpix,&istart,&iend);
02937 #endif
02938 #endif
02939 int ibufsize;
02940 ibufsize = (iend-istart+1) * (paramct+Err_ct);
02941 double *dbufrecv;
02942 dbufrecv = (double*)malloc(sizeof (double) * ibufsize);
02943 mpi_from = irecv;
02944 mpi_tag = 1200 + irecv;
02945 MPI_Recv(dbufrecv, ibufsize, MPI_DOUBLE, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
02946 #if CYCLPRLL == 1
02947 for (n = istart ; n < iend+1 ; n++)
02948 {
02949 for (j=0; j<paramct; j++){FinalRes[(jobassignmap[n+jobnum*mpi_from]*paramct)+j]=dbufrecv[(n-istart)*(paramct+Err_ct) +j];}
02950 for (k=0; k<Err_ct ; k++){FinalErr[(jobassignmap[n+jobnum*mpi_from]*Err_ct) +k]=dbufrecv[(n-istart)*(paramct+Err_ct)+paramct+k];}
02951 }
02952 #else
02953 for (n = istart ; n < iend+1 ; n++)
02954 {
02955 for (j=0; j<paramct; j++){FinalRes[(n *paramct)+j]=dbufrecv[(n-istart)*(paramct+Err_ct) +j];}
02956 for (k=0; k<Err_ct ; k++){FinalErr[(n *Err_ct) +k]=dbufrecv[(n-istart)*(paramct+Err_ct)+paramct+k];}
02957 }
02958 #endif
02959 free(dbufrecv);
02960 }
02961 printf("done \n");
02962 }
02963 }
02964 else
02965 {
02966 int isend;
02967 int mpi_dest = 0;
02968 nprocs = mpi_size;
02969 numpix = imgpix;
02970 isend = mpi_rank;
02971 #if CYCLPRLL == 1
02972 istart=0;
02973 iend =jobnum-1;
02974 #else
02975 #if EQUIAREA == 1
02976 istart=istartall[isend];
02977 iend=iendall[isend];
02978 #else
02979 para_range(isend,nprocs,numpix,&istart,&iend);
02980 #endif
02981 #endif
02982 int ibufsize;
02983 ibufsize = (iend-istart+1) * (paramct+Err_ct);
02984 double *dbufsend;
02985 dbufsend = (double*)malloc(sizeof (double) * ibufsize);
02986 for (n = istart ; n < iend + 1 ; n++)
02987 {
02988 for (j=0; j<paramct; j++){dbufsend[(n-istart)*(paramct+Err_ct) +j]=FinalResLocal[(n-istart)*paramct+j];}
02989 for (k=0; k<Err_ct; k++){dbufsend[(n-istart)*(paramct+Err_ct)+paramct+k]=FinalErrLocal[(n-istart)*Err_ct +k];}
02990 }
02991 mpi_tag = 1200 + mpi_rank;
02992 MPI_Send(dbufsend, ibufsize, MPI_DOUBLE, mpi_dest, mpi_tag, MPI_COMM_WORLD);
02993 free(dbufsend);
02994 }
02995 MPI_Barrier(MPI_COMM_WORLD);
02996
02997
02998 if (mpi_rank == 0)
02999 {
03000 myrank = mpi_rank;
03001 nprocs = mpi_size;
03002 numpix = imgpix;
03003 #if CYCLPRLL == 1
03004 istart=0;
03005 iend =jobnum-1;
03006 #else
03007 #if EQUIAREA == 1
03008 istart=istartall[myrank];
03009 iend=iendall[myrank];
03010 #else
03011 para_range(myrank,nprocs,numpix,&istart,&iend);
03012 #endif
03013 #endif
03014
03015 #if CYCLPRLL == 1
03016 for (n = istart ; n < iend+1 ; n++)
03017 {
03018 FinalConvFlag[jobassignmap[n]] = FinalConvFlagLocal[n-istart];
03019 FinalQualMap [jobassignmap[n]] = FinalQualMapLocal [n-istart];
03020 }
03021 #else
03022 for (n = istart ; n < iend+1 ; n++)
03023 {
03024 FinalConvFlag[n] = FinalConvFlagLocal[n-istart];
03025 FinalQualMap [n] = FinalQualMapLocal [n-istart];
03026 }
03027 #endif
03028
03029 if (mpi_size > 1)
03030 {
03031 printf("now collecting integer data from PEs : ");
03032 int irecv;
03033 for (irecv = 1; irecv < mpi_size ; irecv++)
03034 {
03035 printf(" %d ",irecv);
03036 int mpi_from;
03037 nprocs = mpi_size;
03038 numpix = imgpix;
03039 #if CYCLPRLL == 1
03040 istart=0;
03041 iend =jobnum-1;
03042 #else
03043 #if EQUIAREA == 1
03044 istart=istartall[irecv];
03045 iend=iendall[irecv];
03046 #else
03047 para_range(irecv,nprocs,numpix,&istart,&iend);
03048 #endif
03049 #endif
03050 int ibufsize;
03051 ibufsize = (iend-istart+1) * 2;
03052 int *ibufrecv;
03053 ibufrecv = (int*)malloc(sizeof(int) * ibufsize);
03054 mpi_from = irecv;
03055 mpi_tag = 1300 + irecv;
03056 MPI_Recv(ibufrecv, ibufsize, MPI_INT, mpi_from, mpi_tag, MPI_COMM_WORLD, &mpistat);
03057 #if CYCLPRLL == 1
03058 for (n = istart ; n < iend+1 ; n++)
03059 {
03060 FinalConvFlag[jobassignmap[n+jobnum*mpi_from]] = ibufrecv[n-istart];
03061 FinalQualMap [jobassignmap[n+jobnum*mpi_from]] = ibufrecv[n-istart+(iend-istart+1)];
03062 }
03063 #else
03064 for (n = istart ; n < iend+1 ; n++)
03065 {
03066 FinalConvFlag[n] = ibufrecv[n-istart];
03067 FinalQualMap [n] = ibufrecv[n-istart+(iend-istart+1)];
03068 }
03069 #endif // end if CYCLPRLL is 1 or not
03070 free(ibufrecv);
03071 }
03072 printf("done \n");
03073 }
03074 }
03075 else
03076 {
03077 int isend;
03078 int mpi_dest = 0;
03079 nprocs = mpi_size;
03080 numpix = imgpix;
03081 isend = mpi_rank;
03082 #if CYCLPRLL == 1
03083 istart=0;
03084 iend =jobnum-1;
03085 #else
03086 #if EQUIAREA == 1
03087 istart=istartall[isend];
03088 iend=iendall[isend];
03089 #else
03090 para_range(isend,nprocs,numpix,&istart,&iend);
03091 #endif
03092 #endif
03093 int ibufsize;
03094 ibufsize = (iend-istart+1) * 2;
03095 int *ibufsend;
03096 ibufsend = (int*)malloc(sizeof (int) * ibufsize);
03097 for (n = istart ; n < iend + 1 ; n++)
03098 {
03099 ibufsend[n-istart ]=FinalConvFlagLocal[n-istart];
03100 ibufsend[n-istart+(iend-istart+1)]=FinalQualMapLocal [n-istart];
03101 }
03102 mpi_tag = 1300 + mpi_rank;
03103 MPI_Send(ibufsend, ibufsize, MPI_INT, mpi_dest, mpi_tag, MPI_COMM_WORLD);
03104 free(ibufsend);
03105 }
03106 MPI_Barrier(MPI_COMM_WORLD);
03107
03108
03109 if (mpi_rank == 0)
03110 {
03111 #if CYCLPRLL == 1
03112 for (n = 0 ; n < imgpix; n++)
03113 {
03114 if (nan_map[n] != 0)
03115 {
03116 float aa=NAN;
03117 FinalConvFlag[n] = 1;
03118 FinalQualMap [n] = (int)(aa);
03119 for (j=0; j<paramct; j++){FinalRes[(n*paramct)+j]=NAN;}
03120 for (k=0; k<Err_ct ; k++){FinalErr[(n*Err_ct) +k]=NAN;}
03121 }
03122 }
03123 #else
03124 if (istartall[0] > 0)
03125 {
03126 for (n = 0 ; n < istartall[0]; n++)
03127 {
03128 float aa=NAN;
03129 FinalConvFlag[n] = 1;
03130 FinalQualMap [n] = (int)(aa);
03131 for (j=0; j<paramct; j++){FinalRes[(n*paramct)+j]=NAN;}
03132 for (k=0; k<Err_ct ; k++){FinalErr[(n*Err_ct) +k]=NAN;}
03133 }
03134 }
03135 if (iendall[mpi_size-1] < imgpix - 1)
03136 {
03137 for (n = iendall[mpi_size-1] + 1; n < imgpix; n++)
03138 {
03139 float aa=NAN;
03140 FinalConvFlag[n] = 1;
03141 FinalQualMap [n] = (int)(aa);
03142 for (j=0; j<paramct; j++){FinalRes[(n*paramct)+j]=NAN;}
03143 for (k=0; k<Err_ct ; k++){FinalErr[(n*Err_ct) +k]=NAN;}
03144 }
03145 }
03146 #endif // end if CYCLPRLL is 1 or not
03147 }
03148
03149 MPI_Barrier(MPI_COMM_WORLD);
03150
03151
03152 free(FinalConvFlagLocal);
03153 free(FinalQualMapLocal);
03154 free(FinalResLocal);
03155 free(FinalErrLocal);
03156 free(dataLocal);
03157 free(nan_mapLocal);
03158 #if CYCLPRLL == 1
03159 free(jobassignmapLocal);
03160 #endif
03161 MPI_Barrier(MPI_COMM_WORLD);
03162
03163
03164 #if CONFINDX == 1
03165 if (mpi_rank == 0)
03166 {
03167 #define invCode0 0x0000 // inversion convergence
03168 #define invCode2 0x0002 // reached maximum number of iterations
03169 #define invCode3 0x0003 // finished with too many consecutive non-converging iterations
03170 #define invCode4 0x0004 // NaN in the computation of chi2. exited loop
03171 #define invCode5 0x0005 // NaN in SVDSOL. exited loop
03172 #define invCode1 0x0001 // continuum intensity not above the required threshold. pixel not inverted
03173 #define pixCode0 0x0000 // good pixel
03174 #define pixCode1 0x0008 // bad pixel
03175 #define quCode0 0x0000 // good QU-signal
03176 #define quCode1 0x0010 // low QU-signal
03177 #define vCode0 0x0000 // good V-signal
03178 #define vCode1 0x0020 // low V-signal
03179 #define blosCode0 0x0000 //good Blos value
03180 #define blosCode1 0x0040 //low Blos value
03181 #define missCode0 0x0000 // Not A missing data
03182 #define missCode1 0x0080 // Missing data
03183 #define pixThreshold 500.0 // Threshold value for determining bad pixels
03184 #define quvScale 0.204 // scaling factor for the Stokes quv noise; sigma(Q,U,V) = 0.204 * sqrt(I)
03185 #define iScale 0.118 // scaling factor for Stokes I noise; sigma(I) = 0.118 * sqrt(I)
03186
03187
03188
03189 #define losThreshold 1.0 * 6.7 // 1 * sigma of 720s los mags.
03190 #define RADSINDEG 3.14159265358979 / 180.0
03191 int yOff = 0, iData = 0;
03192 int invQual, pixQual, quQual, vQual, blosQual, missQual;
03193 int nx = cols;
03194 int ny = rows;
03195 for (iData = 0; iData < imgpix; iData++)
03196 {
03197 float stokesV, stokesU, stokesQ, stokesI;
03198 stokesI = 0.0;
03199 stokesQ = 0.0;
03200 stokesU = 0.0;
03201 stokesV = 0.0;
03202
03203
03204 int m;
03205 for (m = 0; m < NUM_LAMBDA_FILTER; m++)
03206 {
03207 stokesI = stokesI + data[iData +(m+NUM_LAMBDA_FILTER*0)*imgpix];
03208 stokesQ = stokesQ + data[iData +(m+NUM_LAMBDA_FILTER*1)*imgpix];
03209 stokesU = stokesU + data[iData +(m+NUM_LAMBDA_FILTER*2)*imgpix];
03210 stokesV = stokesV + fabs(data[iData +(m+NUM_LAMBDA_FILTER*3)*imgpix]);
03211 }
03212
03213
03214 float bLos = blosgram[ iData];
03215 double bTotal = FinalRes[(iData*paramct)+5];
03216 double bIncl = FinalRes[(iData*paramct)+1];
03217 int bInvFlag = FinalConvFlag[iData];
03218
03219
03220 FinalConfidMap[iData] = 0;
03221 invQual = invCode0;
03222 pixQual = pixCode0;
03223 quQual = quCode0;
03224 vQual = vCode0;
03225 blosQual = blosCode0;
03226 missQual = missCode0;
03227 if (isnan(bTotal) || isnan(bIncl) || isnan(bLos) ||
03228 isnan(stokesI) || isnan(stokesQ) || isnan(stokesU) || isnan(stokesV) || isnan(bInvFlag))
03229 {
03230 missQual = missCode1;
03231 FinalQualMap[iData] = invQual | pixQual | quQual | vQual | blosQual | missQual;
03232 FinalConfidMap[iData] = 6;
03233 }
03234 else
03235 {
03236
03237 float sigmaLP = 0.0, sigmaV = 0.0;
03238 float Qall = 0.0, Uall = 0.0, varQUVall = 0.0, LP = 0.0, Vall = 0.0;
03239 Qall = stokesQ;
03240 Uall = stokesU;
03241 Vall = stokesV;
03242 LP = sqrt(Qall * Qall + Uall * Uall);
03243 varQUVall = quvScale * quvScale * stokesI;
03244 sigmaLP = sqrt(varQUVall);
03245 sigmaV = sqrt(varQUVall);
03246
03247 if (bInvFlag == 2) invQual = invCode2;
03248 if (bInvFlag == 3) invQual = invCode3;
03249 if (bInvFlag == 4) invQual = invCode4;
03250 if (bInvFlag == 5) invQual = invCode5;
03251 if (bInvFlag == 1) invQual = invCode1;
03252 if ((fabs(bLos) - fabs(bTotal * cos(bIncl * RADSINDEG)) > pixThreshold)) pixQual = pixCode1;
03253 if (LP < sigmaLP) quQual = quCode1;
03254 if (Vall < sigmaV) vQual = vCode1;
03255 if (fabs(bLos) < losThreshold) blosQual = blosCode1;
03256 FinalQualMap[iData] = invQual | pixQual | quQual | vQual | blosQual | missQual;
03257 if ((pixQual == 0) && (invQual == 0))
03258 {
03259 if ((vQual != 0) && (quQual == 0) && (blosQual == 0)) FinalConfidMap[iData] = 1;
03260 if ((vQual == 0) && (quQual != 0) && (blosQual == 0)) FinalConfidMap[iData] = 1;
03261 if ((vQual == 0) && (quQual == 0) && (blosQual != 0)) FinalConfidMap[iData] = 1;
03262 if ((vQual != 0) && (quQual != 0) && (blosQual == 0)) FinalConfidMap[iData] = 2;
03263 if ((vQual == 0) && (quQual != 0) && (blosQual != 0)) FinalConfidMap[iData] = 2;
03264 if ((vQual != 0) && (quQual == 0) && (blosQual != 0)) FinalConfidMap[iData] = 2;
03265 if ((vQual != 0) && (quQual != 0) && (blosQual != 0)) FinalConfidMap[iData] = 3;
03266 }
03267 if ((pixQual == 0) && (invQual != 0)) FinalConfidMap[iData] = 4;
03268 if (pixQual != 0) FinalConfidMap[iData] = 5;
03269 }
03270 }
03271
03272
03273 for (iData = 0; iData < imgpix; iData++)
03274 {
03275 int ival = FinalQualMap[iData];
03276 if (!isnan(ival)){FinalQualMap[iData] = ival * 256 * 256 * 256;}
03277
03278 }
03279
03280 }
03281 MPI_Barrier(MPI_COMM_WORLD);
03282 #endif // end if CONFINDX is 1 or not
03283
03284
03285 if (mpi_rank == 0)
03286 {
03287 outRec = drms_create_record (drms_env, outser, DRMS_PERMANENT, &status);
03288 if (!outRec) {fprintf (stderr, "Error creating record in series %s; abandoned\n",outser);return 1;}
03289
03290
03291 drms_copykeys(outRec, inRec, 0, kDRMS_KeyClass_Explicit);
03292
03293
03294 double blos_ave=0.0;
03295 double babs_ave=0.0;
03296 double vlos_ave=0.0;
03297 {
03298 int icount1=0;
03299 int icount2=0;
03300 int n, nend;
03301 for(n = 0; n < imgpix ; n++)
03302 {
03303 int inan = nan_map[n];
03304 if (inan == 0)
03305 {
03306 float babs =FinalRes[(n*paramct)+5];
03307 float tht =FinalRes[(n*paramct)+1];
03308 if (!isnan(babs) && !isnan(tht))
03309 {
03310 float costh, thtr, blos;
03311 thtr = tht / 180.0 * 3.14159265358979e0;
03312 costh = cos(thtr);
03313 blos = - babs * costh;
03314 icount1 = icount1 + 1;
03315 babs_ave = babs_ave + babs;
03316 blos_ave = blos_ave + blos;
03317 }
03318 float vlos = FinalRes[(n*paramct)+6];
03319 if (!isnan(vlos))
03320 {
03321 icount2 = icount2 + 1;
03322 vlos_ave = vlos_ave + vlos;
03323 }
03324 } }
03325 if (icount1 > 0)
03326 {
03327 babs_ave=babs_ave/(double)(icount1);
03328 blos_ave=blos_ave/(double)(icount1);
03329 }
03330 else
03331 {
03332 babs_ave=0.0;
03333 blos_ave=0.0;
03334 }
03335 if (icount2 > 0)
03336 {
03337 vlos_ave=vlos_ave/(double)(icount2);
03338 }
03339 else
03340 {
03341 vlos_ave=0.0;
03342 }
03343 }
03344
03345
03346 {
03347
03348
03349 char invcodeversion[256];
03350 char FSNRECs[50];
03351 sprintf(invcodeversion,"%s %s",module_name,version_id);
03352 strcat(invcodeversion,"; uses time-dependent HMI filter phase maps");
03353 drms_setkey_string(outRec,"INVCODEV", invcodeversion);
03354 sprintf(FSNRECs,"%d",FSNREC);
03355
03356 char *sdummy;
03357 sdummy= meinversion_version();
03358 drms_setkey_string(outRec,"CODEVER4", sdummy);
03359
03360 sdummy=" ";
03361 drms_setkey_string(outRec,"HISTORY",sdummy);
03362 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";
03363 drms_setkey_string(outRec,"COMMENT",sdummy);
03364
03365 sdummy="HMI observable";
03366 drms_setkey_string(outRec,"CONTENT",sdummy);
03367
03368
03369 drms_setkey_int (outRec,"INVFREEP",keyfreep);
03370 drms_setkey_int (outRec,"INVITERA",NUM_ITERATIONS);
03371 drms_setkey_int (outRec,"INVLMBDA",NUM_LAMBDA);
03372 drms_setkey_int (outRec,"INVLMBDF",NUM_LAMBDA_FILTER);
03373 drms_setkey_int (outRec,"INVTUNEN",NUM_TUNNING);
03374 drms_setkey_double(outRec,"INVSVDTL",SVD_TOLERANCE);
03375 drms_setkey_double(outRec,"INVCHIST",CHI2_STOP);
03376 drms_setkey_double(outRec,"INVPOLTH",POLARIZATION_THRESHOLD);
03377 drms_setkey_double(outRec,"INVPJUMP",PERCENTAGE_JUMP);
03378 drms_setkey_double(outRec,"INVLMBDM",LAMBDA_MIN);
03379 drms_setkey_double(outRec,"INVLMBD0",LAMBDA_0);
03380 drms_setkey_double(outRec,"INVLMBDB",LAMBDA_B);
03381 drms_setkey_double(outRec,"INVDLTLA",DELTA_LAMBDA);
03382 drms_setkey_double(outRec,"INVLYOTW",LYOTFWHM);
03383 drms_setkey_double(outRec,"INVWNARW",WNARROW);
03384 drms_setkey_double(outRec,"INVWSPAC",WSPACING);
03385 drms_setkey_double(outRec,"INVINTTH",INTENSITY_THRESHOLD);
03386 #if NLEVPIXL == 1
03387 drms_setkey_double(outRec,"INVNFCTI",NOISE_LEVELFI);
03388 drms_setkey_double(outRec,"INVNFCTQ",NOISE_LEVELFQ);
03389 drms_setkey_double(outRec,"INVNFCTU",NOISE_LEVELFU);
03390 drms_setkey_double(outRec,"INVNFCTV",NOISE_LEVELFV);
03391 #else
03392 drms_setkey_double(outRec,"INVNOISE",NOISE_LEVEL);
03393 #endif
03394 drms_setkey_int (outRec,"INVCONTI",CONTINUUM);
03395 drms_setkey_int (outRec,"INVLMBDS",NUM_LAMBDA_synth);
03396 drms_setkey_double(outRec,"INVLMBMS",LAMBDA_MIN_synth);
03397
03398 double weighti, weightu, weightq, weightv;
03399 weighti = weights[0];
03400 weightq = weights[1];
03401 weightu = weights[2];
03402 weightv = weights[3];
03403 drms_setkey_double(outRec,"INVWGHTI",weighti);
03404 drms_setkey_double(outRec,"INVWGHTQ",weightq);
03405 drms_setkey_double(outRec,"INVWGHTU",weightu);
03406 drms_setkey_double(outRec,"INVWGHTV",weightv);
03407
03408 sdummy="No";
03409 drms_setkey_string(outRec,"INVSTLGT",sdummy);
03410 sdummy=" ";
03411 drms_setkey_string(outRec,"INVFLPRF",sdummy);
03412 sdummy=" ";
03413 drms_setkey_string(outRec,"INVPHMAP",FSNRECs);
03414
03415 drms_setkey_double(outRec,"INVVLAVE",vlos_ave);
03416 drms_setkey_double(outRec,"INVBLAVE",blos_ave);
03417 drms_setkey_double(outRec,"INVBBAVE",babs_ave);
03418 drms_setkey_int (outRec,"INVNPRCS",sum_pixdone);
03419 drms_setkey_int (outRec,"INVNCNVG",sum_pixdone-sum_pix_noconv);
03420
03421 int iqstokes;
03422 iqstokes = drms_getkey_int(inRec,"QUALITY",&status);
03423 drms_setkey_int (outRec,"QUAL_S",iqstokes);
03424 int iqinversion;
03425 iqinversion = iqstokes;
03426
03427 drms_setkey_int (outRec,"QUALITY",iqinversion);
03428
03429 stokestime = drms_getkey_time(inRec,"DATE",&status);
03430 char timestr[26];
03431 sprint_time(timestr,stokestime,"UTC",0);
03432 drms_setkey_string(outRec,"DATE_S",timestr);
03433 sprint_time(timestr,CURRENT_SYSTEM_TIME,"UTC",1);
03434 drms_setkey_string(outRec,"DATE" ,timestr);
03435
03436 sdummy=indsdesc;
03437 drms_setkey_string(outRec,"SOURCE",sdummy);
03438
03439 sdummy="n/a";
03440 drms_setkey_string(outRec,"INVKEYS1",sdummy);
03441 drms_setkey_string(outRec,"INVKEYS2",sdummy);
03442 drms_setkey_string(outRec,"INVKEYS3",sdummy);
03443 int idummy=-666;
03444 drms_setkey_int (outRec,"INVKEYI1",idummy);
03445 drms_setkey_int (outRec,"INVKEYI2",idummy);
03446 drms_setkey_int (outRec,"INVKEYI3",idummy);
03447 double ddummy=NAN;
03448 drms_setkey_double(outRec,"INVKEYD1",ddummy);
03449 drms_setkey_double(outRec,"INVKEYD2",ddummy);
03450 drms_setkey_double(outRec,"INVKEYD3",ddummy);
03451
03452 sdummy="deg";
03453 drms_setkey_string(outRec,"BUNIT_000",sdummy);
03454 drms_setkey_string(outRec,"BUNIT_001",sdummy);
03455 sdummy="Mx/cm^2";
03456 drms_setkey_string(outRec,"BUNIT_002",sdummy);
03457 sdummy="cm/s";
03458 drms_setkey_string(outRec,"BUNIT_003",sdummy);
03459 sdummy="mA";
03460 drms_setkey_string(outRec,"BUNIT_004",sdummy);
03461 sdummy="dimensionless";
03462 drms_setkey_string(outRec,"BUNIT_005",sdummy);
03463 sdummy="length units";
03464 drms_setkey_string(outRec,"BUNIT_006",sdummy);
03465 sdummy="DN/s";
03466 drms_setkey_string(outRec,"BUNIT_007",sdummy);
03467 drms_setkey_string(outRec,"BUNIT_008",sdummy);
03468 sdummy="dimensionless";
03469 drms_setkey_string(outRec,"BUNIT_009",sdummy);
03470 sdummy=" ";
03471 drms_setkey_string(outRec,"BUNIT_010",sdummy);
03472 sdummy="deg";
03473 drms_setkey_string(outRec,"BUNIT_011",sdummy);
03474 drms_setkey_string(outRec,"BUNIT_012",sdummy);
03475 sdummy="Mx/cm^2";
03476 drms_setkey_string(outRec,"BUNIT_013",sdummy);
03477 sdummy="cm/s";
03478 drms_setkey_string(outRec,"BUNIT_014",sdummy);
03479 sdummy="dimensionless";
03480 drms_setkey_string(outRec,"BUNIT_015",sdummy);
03481 sdummy=" ";
03482 drms_setkey_string(outRec,"BUNIT_016",sdummy);
03483 drms_setkey_string(outRec,"BUNIT_017",sdummy);
03484 drms_setkey_string(outRec,"BUNIT_018",sdummy);
03485 drms_setkey_string(outRec,"BUNIT_019",sdummy);
03486 drms_setkey_string(outRec,"BUNIT_020",sdummy);
03487 drms_setkey_string(outRec,"BUNIT_021",sdummy);
03488 drms_setkey_string(outRec,"BUNIT_022",sdummy);
03489 drms_setkey_string(outRec,"BUNIT_023",sdummy);
03490 drms_setkey_string(outRec,"BUNIT_024",sdummy);
03491
03492 #if ADNEWKWD == 1
03493 drms_setkey_int (outRec,"NHARP",nharp);
03494 #endif
03495
03496 #if CHNGTREC == 1
03497 drms_setkey_string(outRec, "T_REC",outtrec);
03498 #endif
03499 }
03500
03501 char trectmp2[26];
03502 TIME trectmp1 = drms_getkey_time(outRec,"T_REC",&status);
03503 sprint_time(trectmp2,trectmp1,"TAI",0);
03504 printf("to-be-created record: %s[%s] \n",outser,trectmp2);
03505
03506 printf("sending output arrays to DRMS\n");
03507
03508 for (j = 0; j < paramct; j++)
03509 {
03510 float *dat1;
03511 int axes[2];
03512
03513 #if RECTANGL == 1 || HARPATCH == 1
03514 dat1 = (float *)calloc(xwidth * yheight, sizeof(float));
03515 int icount;
03516 icount = -1;
03517 for(n = 0; n < imgpix ; n++)
03518 {
03519 int ix, iy;
03520 ix = n % cols - xleftbot; iy = n / cols - yleftbot;
03521 if ((ix >= 0) && (ix < xwidth) && (iy >= 0) && (iy < yheight))
03522 {
03523 icount = icount + 1;
03524 dat1[icount] = FinalRes[(n*paramct)+j];
03525 }
03526 }
03527 axes[0] = xwidth;
03528 axes[1] = yheight;
03529 #else
03530 dat1 = (float *)calloc(imgpix, sizeof(float));
03531 for(n = 0; n < imgpix ; n++){dat1[n] = FinalRes[(n*paramct)+j];}
03532 axes[0] = cols;
03533 axes[1] = rows;
03534 #endif
03535 invrt_array = drms_array_create (DRMS_TYPE_FLOAT, 2, axes, dat1, &status);
03536
03537 #if INTBSCLE == 1
03538 invrt_array->israw = 0;
03539 invrt_array->bzero = bzero_inv[j];
03540 invrt_array->bscale = bscaleinv[j];
03541 #endif
03542 outSeg = drms_segment_lookup (outRec, Resname[j]);
03543 if (!outSeg) {fprintf(stderr, "Error getting data segment %s; abandoned\n", Resname[j]);}
03544
03545 #if ADNEWKWD == 1
03546 set_statistics(outSeg, invrt_array, 1);
03547 #endif
03548 if (drms_segment_write (outSeg, invrt_array, 0))
03549 {
03550 fprintf (stderr, "Error writing segment %d (%s); abandoned\n", j,outSeg->info->name);
03551 return 1;
03552 }
03553 else
03554 {
03555 if (verbose){printf("Results written out to %-s\n", Resname[j]);}
03556 }
03557 free(dat1);
03558 }
03559
03560 printf("sending error arrays to DRMS\n");
03561 for (k = 0; k < Err_ct; k++)
03562 {
03563 float *dat2;
03564 int axes[2];
03565 #if RECTANGL == 1 || HARPATCH == 1
03566 dat2 = (float *)calloc(xwidth * yheight, sizeof(float));
03567 int icount;
03568 icount = -1;
03569 for(n = 0; n < imgpix ; n++)
03570 {
03571 int ix, iy;
03572 ix = n % cols - xleftbot; iy = n / cols - yleftbot;
03573 if ((ix >= 0) && (ix < xwidth) && (iy >= 0) && (iy < yheight))
03574 {
03575 icount = icount + 1;
03576 dat2[icount] = FinalErr[(n*Err_ct)+k];
03577 }
03578 }
03579 axes[0] = xwidth;
03580 axes[1] = yheight;
03581 #else
03582 dat2 = (float *)calloc(imgpix , sizeof(float));
03583 for (n=0; n < imgpix;n++){dat2[n] = FinalErr[(n*Err_ct)+k];}
03584 axes[0] = cols;
03585 axes[1] = rows;
03586 #endif
03587 err_array = drms_array_create (DRMS_TYPE_FLOAT, 2, axes, dat2,&status);
03588 #if INTBSCLE == 1
03589 err_array->israw = 0;
03590 err_array->bzero = bzero_inv[k+paramct];
03591 err_array->bscale = bscaleinv[k+paramct];
03592 #endif
03593 outSeg = drms_segment_lookup (outRec, Resname[k+paramct]);
03594 if (!outSeg)
03595 {
03596 if (verbose){fprintf(stderr, "Error getting data segment %s; abandoned\n", Resname[k+paramct]);}
03597 }
03598 else
03599 {
03600 #if ADNEWKWD == 1
03601 set_statistics(outSeg, err_array, 1);
03602 #endif
03603 if (drms_segment_write (outSeg, err_array, 0))
03604 {
03605 fprintf (stderr, "Error writing to segment %d (%s); abandoned\n", k+paramct, outSeg->info->name);
03606 return 1;
03607 }
03608 else
03609 {
03610 if (verbose){printf("Errors written out to %-s\n", Resname[k+paramct]);}
03611 }
03612 }
03613 free(dat2);
03614 }
03615
03616 printf("sending conv.flag array to DRMS\n");
03617 for (k = Err_ct; k < Err_ct + 1; k++)
03618 {
03619 char *dat3;
03620 int axes[2];
03621 #if RECTANGL == 1 || HARPATCH == 1
03622 dat3 = (char *)calloc(xwidth * yheight, sizeof(char));
03623 int icount;
03624 icount = -1;
03625 for(n = 0; n < imgpix ; n++)
03626 {
03627 int ix, iy;
03628 ix = n % cols - xleftbot; iy = n / cols - yleftbot;
03629 if ((ix >= 0) && (ix < xwidth) && (iy >= 0) && (iy < yheight))
03630 {
03631 icount = icount + 1;
03632 dat3[icount] = (char)FinalConvFlag[n];
03633 }
03634 }
03635 axes[0] = xwidth;
03636 axes[1] = yheight;
03637 #else
03638 dat3 = (char *)calloc(imgpix , sizeof(char));
03639 for (n=0; n < imgpix;n++){dat3[n] = (char)FinalConvFlag[n];}
03640 axes[0] = cols;
03641 axes[1] = rows;
03642 #endif
03643 flg_array = drms_array_create (DRMS_TYPE_CHAR, 2, axes, dat3,&status);
03644 outSeg = drms_segment_lookup (outRec, Resname[k+paramct]);
03645 if (!outSeg)
03646 {
03647 if (verbose){fprintf(stderr, "Error getting data segment %s; abandoned\n", Resname[k+paramct]);}
03648 }
03649 else
03650 {
03651 #if ADNEWKWD == 1
03652 set_statistics(outSeg, flg_array, 1);
03653 #endif
03654 if (drms_segment_write (outSeg, flg_array, 0))
03655 {
03656 fprintf (stderr, "ConvFlag writing to segment %d (%s); abandoned\n", k+paramct, outSeg->info->name);
03657 return 1;
03658 }
03659 else
03660 {
03661 if (verbose){printf("ConvFlag written out to %-s\n", Resname[k+paramct]);}
03662 }
03663 }
03664 free(dat3);
03665 }
03666
03667 printf("sending info. map array to DRMS\n");
03668 for (k = Err_ct + 1; k < Err_ct + 2; k++)
03669 {
03670 int *dat4;
03671 int axes[2];
03672 #if RECTANGL == 1 || HARPATCH == 1
03673 dat4 = (int *)calloc(xwidth * yheight, sizeof(int));
03674 int icount;
03675 icount = -1;
03676 for(n = 0; n < imgpix ; n++)
03677 {
03678 int ix, iy;
03679 ix = n % cols - xleftbot; iy = n / cols - yleftbot;
03680 if ((ix >= 0) && (ix < xwidth) && (iy >= 0) && (iy < yheight))
03681 {
03682 icount = icount + 1;
03683 dat4[icount] = FinalQualMap[n];
03684 }
03685 }
03686 axes[0] = xwidth;
03687 axes[1] = yheight;
03688 #else
03689 dat4 = (int *)calloc(imgpix , sizeof(int));
03690 for (n=0; n < imgpix;n++){dat4[n] = FinalQualMap[n];}
03691 axes[0] = cols;
03692 axes[1] = rows;
03693 #endif
03694 qmap_array = drms_array_create (DRMS_TYPE_INT, 2, axes, dat4,&status);
03695 outSeg = drms_segment_lookup (outRec, Resname[k+paramct]);
03696 if (!outSeg)
03697 {
03698 if (verbose){fprintf(stderr, "Error getting data segment %s; abandoned\n", Resname[k+paramct]);}
03699 }
03700 else
03701 {
03702 #if ADNEWKWD == 1
03703 set_statistics(outSeg, qmap_array, 1);
03704 #endif
03705 if (drms_segment_write (outSeg, qmap_array, 0))
03706 {
03707 fprintf (stderr, "QualMap writing to segment %d (%s); abandoned\n", k+paramct, outSeg->info->name);
03708 return 1;
03709 }
03710 else
03711 {
03712 if (verbose){printf("QualMap written out to %-s\n", Resname[k+paramct]);}
03713 }
03714 }
03715 free(dat4);
03716 }
03717
03718 printf("sending confidence index array to DRMS\n");
03719 for (k = Err_ct + 2; k < Err_ct + 3; k++)
03720 {
03721 char *dat5;
03722 int axes[2];
03723 #if RECTANGL == 1 || HARPATCH == 1
03724 dat5 = (char *)calloc(xwidth * yheight, sizeof(char));
03725 int icount;
03726 icount = -1;
03727 for(n = 0; n < imgpix ; n++)
03728 {
03729 int ix, iy;
03730 ix = n % cols - xleftbot; iy = n / cols - yleftbot;
03731 if ((ix >= 0) && (ix < xwidth) && (iy >= 0) && (iy < yheight))
03732 {
03733 icount = icount + 1;
03734 dat5[icount] = (char)FinalConfidMap[n];
03735 }
03736 }
03737 axes[0] = xwidth;
03738 axes[1] = yheight;
03739 #else
03740 dat5 = (char *)calloc(imgpix , sizeof(char));
03741 for (n=0; n < imgpix;n++){dat5[n] = (char)FinalConfidMap[n];}
03742 axes[0] = cols;
03743 axes[1] = rows;
03744 #endif
03745 flg_array = drms_array_create (DRMS_TYPE_CHAR, 2, axes, dat5,&status);
03746 outSeg = drms_segment_lookup (outRec, Resname[k+paramct]);
03747 if (!outSeg)
03748 {
03749 if (verbose){fprintf(stderr, "Error getting data segment %s; abandoned\n", Resname[k+paramct]);}
03750 }
03751 else
03752 {
03753 #if ADNEWKWD == 1
03754 set_statistics(outSeg, flg_array, 1);
03755 #endif
03756 if (drms_segment_write (outSeg, flg_array, 0))
03757 {
03758 fprintf (stderr, "ConfidenceIndex writing to segment %d (%s); abandoned\n", k+paramct, outSeg->info->name);
03759 return 1;
03760 }
03761 else
03762 {
03763 if (verbose){printf("ConfidenceIndex written out to %-s\n", Resname[k+paramct]);}
03764 }
03765 }
03766 free(dat5);
03767 }
03768
03769 printf("write-out done !\n");
03770
03771 free(FinalErr);
03772 free(FinalRes);
03773 free(FinalConvFlag);
03774 free(FinalQualMap);
03775 free(FinalConfidMap);
03776
03777 printf("so, close all DRMS record(s) !\n");
03778
03779 drms_close_record (outRec, DRMS_INSERT_RECORD);
03780 drms_close_records (inRS, DRMS_FREE_RECORD);
03781
03782
03783 time(&endtime);
03784 printf ("%ld sec for %d profiles\n", endtime - startime, sum_pixdone);
03785 printf ("%.2f profiles per second\n", (float)(sum_pixdone) / (0.01 + (float)(endtime - startime)));
03786
03787 printf("good bye !\n");
03788 }
03789
03790 MPI_Barrier(MPI_COMM_WORLD);
03791
03792
03793 MPI_Finalize();
03794
03795 return 0;
03796 }
03797
03798
03799
03800
03801
03802
03803
03804
03805
03806
03807
03808
03809
03810
03811
03812 void para_range(int myrank, int nprocs, int numpix, int *istart, int *iend)
03813 {
03814 int iwork1, iwork2, imin, idummy, n1, n2;
03815 n1 = 0;
03816 n2 = numpix - 1;
03817
03818 iwork1 = (n2 - n1 + 1) / nprocs;
03819 iwork2 = (n2 - n1 + 1) % nprocs;
03820 if (iwork2 >= myrank){imin = myrank;}else{imin=iwork2;}
03821 *istart = myrank*iwork1 + n1 + imin;
03822 idummy = *istart + iwork1 - 1;
03823 if (iwork2 <= myrank){*iend = idummy;}else{*iend=idummy+1;}
03824 }
03825
03826
03827
03828
03829
03830
03831
03832
03833
03834 void lininterp1f(double *yinterp, double *xv, double *yv, double *x, double ydefault, int m, int minterp)
03835 {
03836 int i, j;
03837 int nrowsinterp, nrowsdata;
03838 nrowsinterp = minterp;
03839 nrowsdata = m;
03840 for (i=0; i<nrowsinterp; i++)
03841 {
03842 if((x[i] < xv[0]) || (x[i] > xv[nrowsdata-1]))
03843 yinterp[i] = ydefault;
03844 else
03845 { for(j=1; j<nrowsdata; j++)
03846 { if(x[i]<=xv[j])
03847 { yinterp[i] = (x[i]-xv[j-1]) / (xv[j]-xv[j-1]) * (yv[j]-yv[j-1]) + yv[j-1];
03848 break;
03849 }
03850 }
03851 }
03852 }
03853 }
03854
03855
03856
03857
03858
03859
03860 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)
03861 {
03862
03863 printf("INSIDE initialize_vfisv_filter\n");
03864
03865 int status=1;
03866 int nx2=128,ny2=128;
03867 int nelemPHASENT =4*nx2*ny2;
03868 int nelemCONTRASTT=3*nx2*nx2;
03869 int nread,i,ii,jj;
03870 int status2=0;
03871 char inRecQuery[256];
03872 char query[256];
03873 int nRecs;
03874 DRMS_RecordSet_t *data= NULL;
03875 char *keyname="HCAMID";
03876 int keyvalue;
03877 int recofinterest;
03878 FILE *fp=NULL;
03879 int FSNphasemaps=0;
03880 int camera=2;
03881
03882
03883 FILE *filePhaseMaps=NULL;
03884 char line[256];
03885 float tstart=0.0;
03886
03887 filePhaseMaps=fopen("/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/filePhaseMaps.txt", "r");
03888 if(filePhaseMaps == NULL)
03889 {
03890 printf("The file filePhaseMaps.txt does not exist\n");
03891 return 1;
03892 }
03893
03894 while(fgets(line,256,filePhaseMaps) != NULL)
03895 {
03896 sscanf(line,"%f %d",&tstart,&status2);
03897 if(t_rec > tstart) FSNphasemaps=status2;
03898 }
03899 if(FSNphasemaps == 0)
03900 {
03901 printf("Could not find a HMI filter phase map in initialize_vfisv_filter\n");
03902 return 1;
03903 }
03904 status2=0;
03905 fclose(filePhaseMaps);
03906
03907
03908
03909
03910
03911
03912
03913 *FSNREC=FSNphasemaps;
03914
03915
03916 *centerblocker=2.7;
03917 FSR[0]=0.1689;
03918 FSR[1]=0.33685;
03919 FSR[2]=0.695;
03920 FSR[3]=1.417;
03921 FSR[4]=2.779;
03922 FSR[5]=5.682;
03923 FSR[6]=11.354;
03924
03925 *referencenlam=7000;
03926 *nblocker=201;
03927 *nfront=401;
03928
03929 char filephasesnontunable[]="/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/non_tunable_phases_710660_June09_cal_128_2.bin";
03930 char filecontrastsnontunable[]="/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/non_tunable_contrasts_710660_June09_cal_128_2.bin";
03931 char filecontraststunable[]="/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/tunable_contrasts_710660_June09_cal_128.bin";
03932
03933 char referencesolarline[]="/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/ReferenceFeLine.bin";
03934 char referencewavelength[]="/home/jsoc/cvs/Development/JSOC/proj/lev1.5_hmi/apps/ReferenceWavelength.bin" ;
03935
03936
03937 float templineref[*referencenlam];
03938 float tempwavelengthref[*referencenlam];
03939
03940 fp = fopen(referencesolarline,"rb");
03941 fread(templineref,sizeof(float),*referencenlam,fp);
03942 fclose(fp);
03943
03944 fp = fopen(referencewavelength,"rb");
03945 fread(tempwavelengthref,sizeof(float),*referencenlam,fp);
03946 fclose(fp);
03947
03948 for(i=0;i<*referencenlam;++i)
03949 {
03950 lineref[i]=(double)templineref[i];
03951 wavelengthref[i]=(double)tempwavelengthref[i];
03952 }
03953
03954
03955
03956 printf("READ PHASES OF NON-TUNABLE ELEMENTS\n");
03957 fp = fopen(filephasesnontunable,"rb");
03958 if(fp == NULL)
03959 {
03960 printf("Error: CANNOT OPEN FILE OF NON-TUNABLE ELEMENT PHASES\n");
03961 return status;
03962 }
03963
03964 float phaseNTf[nelemPHASENT];
03965 nread=fread(phaseNTf,sizeof(float),nelemPHASENT,fp);
03966 fclose(fp);
03967 for(i=0;i<nelemPHASENT;++i) phaseNT[i] = (double)phaseNTf[i]*M_PI/180.;
03968
03969 printf("READ CONTRASTS OF NON-TUNABLE ELEMENTS\n");
03970 fp = fopen(filecontrastsnontunable,"rb");
03971 if(fp == NULL)
03972 {
03973 printf("Error: CANNOT OPEN FILE OF NON-TUNABLE ELEMENT CONTRASTS\n");
03974 return status;
03975 }
03976
03977 float contrastNTf[nelemPHASENT];
03978 nread=fread(contrastNTf,sizeof(float),nelemPHASENT,fp);
03979 fclose(fp);
03980 for(i=0;i<nelemPHASENT;++i) contrastNT[i]=(double)contrastNTf[i];
03981
03982
03983 printf("READ CONTRASTS OF TUNABLE ELEMENTS\n");
03984 fp = fopen(filecontraststunable,"rb");
03985 if(fp == NULL)
03986 {
03987 printf("Eeror: CANNOT OPEN FILE OF NON-TUNABLE ELEMENT PHASES\n");
03988 return status;
03989 }
03990
03991 float contrastTf[nelemCONTRASTT];
03992 nread=fread(contrastTf,sizeof(float),nelemCONTRASTT,fp);
03993 fclose(fp);
03994 for(i=0;i<nelemCONTRASTT;++i) contrastT[i]=(double)contrastTf[i];
03995
03996
03997
03998
03999 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};
04000
04001 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};
04002
04003 for(i=0;i<201;++i)
04004 {
04005 wavelengthbd[i]=wbd[i];
04006 blockerbd[i]=bld[i];
04007 }
04008
04009
04010
04011
04012 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};
04013
04014 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};
04015
04016 for(i=0;i<401;++i)
04017 {
04018 wavelengthd[i]=wd[i];
04019 frontwindowd[i]=fd[i];
04020 }
04021
04022
04023
04024 strcpy(inRecQuery,"hmi.phasemaps_corrected[");
04025 sprintf(query,"%d",FSNphasemaps);
04026 strcat(inRecQuery,query);
04027 strcat(inRecQuery,"]");
04028
04029 printf("Phase-map query = %s\n",inRecQuery);
04030
04031 data = drms_open_records(drms_env,inRecQuery,&status2);
04032
04033 if (status2 == DRMS_SUCCESS && data != NULL && data->n > 0)
04034 {
04035 nRecs = data->n;
04036 printf("Number of phase-map satisfying the request= %d \n",nRecs);
04037 }
04038 else
04039 {
04040 printf("Input phase-map series %s doesn't exist\n",inRecQuery);
04041 return status;
04042 }
04043
04044 DRMS_Segment_t *segin = NULL;
04045 DRMS_Array_t *arrin = NULL;
04046 float *tempphase = NULL;
04047
04048
04049 i=0;
04050 while(i<nRecs)
04051 {
04052 keyvalue = drms_getkey_int(data->records[i],keyname,&status2);
04053 if(status2 != 0)
04054 {
04055 printf("Error: unable to read keyword %s\n",keyname);
04056 return status;
04057 }
04058 if(keyvalue == camera)
04059 {
04060 recofinterest=i;
04061 break;
04062 }
04063 i++;
04064 }
04065 if(i == nRecs)
04066 {
04067 printf("Error: no phase-map record was found with the proper FSN_REC and HCAMID\n");
04068 return status;
04069 }
04070
04071 segin = drms_segment_lookupnum(data->records[recofinterest],0);
04072 arrin = drms_segment_read(segin,segin->info->type,&status2);
04073 if(status2 != DRMS_SUCCESS)
04074 {
04075 printf("Error: unable to read a data segment\n");
04076 return status;
04077 }
04078 tempphase = arrin->data;
04079
04080 for(i=0;i<nelemCONTRASTT;++i)
04081 {
04082 ii=i / 3;
04083 jj=i % 3;
04084 phaseT[i] = (double)tempphase[ii*5+jj]*M_PI/180.;
04085 }
04086
04087 *HCMNB=drms_getkey_int(data->records[recofinterest],"HCMNB",&status2);
04088 if(status2 != DRMS_SUCCESS)
04089 {
04090 printf("Error: could not read HMCNB\n");
04091 return status;
04092 }
04093 *HCMWB=drms_getkey_int(data->records[recofinterest],"HCMWB",&status2);
04094 if(status2 != DRMS_SUCCESS)
04095 {
04096 printf("Error: could not read HMCWB\n");
04097 return status;
04098 }
04099 *HCME1=drms_getkey_int(data->records[recofinterest],"HCME1",&status2);
04100 if(status2 != DRMS_SUCCESS)
04101 {
04102 printf("Error: could not read HMCE1\n");
04103 return status;
04104 }
04105 *HCMPOL=0;
04106
04107
04108 drms_free_array(arrin);
04109 drms_close_records(data,DRMS_FREE_RECORD);
04110
04111
04112 status=0;
04113
04114 return status;
04115
04116 }
04117
04118
04119
04120
04121
04122
04123
04124
04125
04126
04127
04128
04129
04130
04131
04132
04133
04134
04135
04136
04137
04138
04139
04140
04141
04142
04143
04144
04145
04146
04147
04148
04149
04150
04151
04152 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)
04153 {
04154
04155 int status=1;
04156
04157 if(Num_lambda_filter != 5 && Num_lambda_filter != 6 && Num_lambda_filter != 8 && Num_lambda_filter != 10)
04158 {
04159 printf("Error: the number of wavelengths should be either 5, 6, 8, or 10\n");
04160 return status;
04161 }
04162
04163 double lam0 = 6173.3433;
04164 double lineprofile[Num_lambda],wavelength[Num_lambda];
04165 double lineprofile2[referencenlam],wavelength2[referencenlam];
04166 double ydefault = 1.;
04167 double ydefault2= 0.;
04168 int i,j;
04169
04170 double *HCME1phase=NULL,*HCMWBphase=NULL,*HCMNBphase=NULL;
04171 double frontwindowint[Num_lambda];
04172 double blockerint[Num_lambda];
04173 double lyot[Num_lambda];
04174 double FWHM,minimum;
04175
04176
04177
04178 for(i=0;i<Num_lambda;++i) wavelength[i]= Lambda_Min/1000.0 + (double)i*Delta_Lambda/1000.0;
04179
04180
04181
04182 #if 0
04183 for(i=0;i<nfront;++i)
04184 {
04185 wavelengthd[i]=wavelengthd[i]*10.0-lam0;
04186 frontwindowd[i]=frontwindowd[i]/100.0;
04187 }
04188 for(i=0;i<nblocker;++i)
04189 {
04190 wavelengthbd[i]=wavelengthbd[i]+centerblocker-lam0;
04191 blockerbd[i]=blockerbd[i]/100.0;
04192 }
04193 lininterp1f(frontwindowint,wavelengthd,frontwindowd,wavelength,ydefault2,nfront,Num_lambda);
04194 lininterp1f(blockerint,wavelengthbd,blockerbd,wavelength,ydefault2,nblocker,Num_lambda);
04195 #else
04196
04197
04198 double *wavelengthdtmp, *wavelengthbdtmp, *frontwindowdtmp, *blockerbdtmp;
04199 blockerbdtmp=(double *)malloc(201*sizeof(double));
04200 wavelengthbdtmp=(double *)malloc(201*sizeof(double));
04201 wavelengthdtmp=(double *)malloc(401*sizeof(double));
04202 frontwindowdtmp=(double *)malloc(401*sizeof(double));
04203
04204 for(i=0;i<nfront;++i)
04205 {
04206 wavelengthdtmp[i]=wavelengthd[i]*10.0-lam0;
04207 frontwindowdtmp[i]=frontwindowd[i]/100.0;
04208 }
04209 for(i=0;i<nblocker;++i)
04210 {
04211 wavelengthbdtmp[i]=wavelengthbd[i]+centerblocker-lam0;
04212 blockerbdtmp[i]=blockerbd[i]/100.0;
04213 }
04214
04215
04216 lininterp1f(frontwindowint,wavelengthdtmp, frontwindowdtmp,wavelength,ydefault2,nfront, Num_lambda);
04217 lininterp1f(blockerint, wavelengthbdtmp,blockerbdtmp, wavelength,ydefault2,nblocker,Num_lambda);
04218
04219 free(blockerbdtmp);
04220 free(wavelengthbdtmp);
04221 free(wavelengthdtmp);
04222 free(frontwindowdtmp);
04223 #endif
04224
04225
04226 for(j=0;j<Num_lambda;++j) {
04227 blockerint[j]=blockerint[j]*frontwindowint[j];
04228 }
04229
04230
04231
04232 HCME1phase = (double *) malloc(Num_lambda_filter*sizeof(double));
04233 if(HCME1phase == NULL)
04234 {
04235 printf("Error: no memory allocated to HCME1phase\n");
04236 exit(EXIT_FAILURE);
04237 }
04238 HCMWBphase = (double *) malloc(Num_lambda_filter*sizeof(double));
04239 if(HCMWBphase == NULL)
04240 {
04241 printf("Error: no memory allocated to HCMWBphase\n");
04242 exit(EXIT_FAILURE);
04243 }
04244 HCMNBphase = (double *) malloc(Num_lambda_filter*sizeof(double));
04245 if(HCMNBphase == NULL)
04246 {
04247 printf("Error: no memory allocated to HCMNBphase\n");
04248 exit(EXIT_FAILURE);
04249 }
04250 if(Num_lambda_filter == 6)
04251 {
04252 HCME1phase[5]= (double) ((HCME1+15)*6 % 360)*M_PI/180.0;
04253 HCME1phase[4]= (double) ((HCME1+9 )*6 % 360)*M_PI/180.0;
04254 HCME1phase[3]= (double) ((HCME1+3 )*6 % 360)*M_PI/180.0;
04255 HCME1phase[2]= (double) ((HCME1-3 )*6 % 360)*M_PI/180.0;
04256 HCME1phase[1]= (double) ((HCME1-9 )*6 % 360)*M_PI/180.0;
04257 HCME1phase[0]= (double) ((HCME1-15)*6 % 360)*M_PI/180.0;
04258
04259 HCMWBphase[5]= (double) ((HCMWB-30)*6 % 360)*M_PI/180.0;
04260 HCMWBphase[4]= (double) ((HCMWB-18)*6 % 360)*M_PI/180.0;
04261 HCMWBphase[3]= (double) ((HCMWB-6 )*6 % 360)*M_PI/180.0;
04262 HCMWBphase[2]= (double) ((HCMWB+6 )*6 % 360)*M_PI/180.0;
04263 HCMWBphase[1]= (double) ((HCMWB+18)*6 % 360)*M_PI/180.0;
04264 HCMWBphase[0]= (double) ((HCMWB-30)*6 % 360)*M_PI/180.0;
04265
04266 HCMNBphase[5]= (double) ((HCMNB-0 )*6 % 360)*M_PI/180.0;
04267 HCMNBphase[4]= (double) ((HCMNB+24)*6 % 360)*M_PI/180.0;
04268 HCMNBphase[3]= (double) ((HCMNB-12)*6 % 360)*M_PI/180.0;
04269 HCMNBphase[2]= (double) ((HCMNB+12)*6 % 360)*M_PI/180.0;
04270 HCMNBphase[1]= (double) ((HCMNB-24)*6 % 360)*M_PI/180.0;
04271 HCMNBphase[0]= (double) ((HCMNB+0 )*6 % 360)*M_PI/180.0;
04272 }
04273 if(Num_lambda_filter == 5)
04274 {
04275 HCME1phase[4]= (double) ((HCME1+12)*6 % 360)*M_PI/180.0;
04276 HCME1phase[3]= (double) ((HCME1+6 )*6 % 360)*M_PI/180.0;
04277 HCME1phase[2]= (double) ((HCME1+0 )*6 % 360)*M_PI/180.0;
04278 HCME1phase[1]= (double) ((HCME1-6 )*6 % 360)*M_PI/180.0;
04279 HCME1phase[0]= (double) ((HCME1-12)*6 % 360)*M_PI/180.0;
04280
04281 HCMWBphase[4]= (double) ((HCMWB-24)*6 % 360)*M_PI/180.0;
04282 HCMWBphase[3]= (double) ((HCMWB-12)*6 % 360)*M_PI/180.0;
04283 HCMWBphase[2]= (double) ((HCMWB+0 )*6 % 360)*M_PI/180.0;
04284 HCMWBphase[1]= (double) ((HCMWB+12)*6 % 360)*M_PI/180.0;
04285 HCMWBphase[0]= (double) ((HCMWB+24)*6 % 360)*M_PI/180.0;
04286
04287 HCMNBphase[4]= (double) ((HCMNB+12)*6 % 360)*M_PI/180.0;
04288 HCMNBphase[3]= (double) ((HCMNB-24)*6 % 360)*M_PI/180.0;
04289 HCMNBphase[2]= (double) ((HCMNB+0 )*6 % 360)*M_PI/180.0;
04290 HCMNBphase[1]= (double) ((HCMNB+24)*6 % 360)*M_PI/180.0;
04291 HCMNBphase[0]= (double) ((HCMNB-12)*6 % 360)*M_PI/180.0;
04292 }
04293 if(Num_lambda_filter == 8)
04294 {
04295 HCME1phase[7]= (double) ((HCME1+21)*6 % 360)*M_PI/180.0;
04296 HCME1phase[6]= (double) ((HCME1+15)*6 % 360)*M_PI/180.0;
04297 HCME1phase[5]= (double) ((HCME1+9 )*6 % 360)*M_PI/180.0;
04298 HCME1phase[4]= (double) ((HCME1+3 )*6 % 360)*M_PI/180.0;
04299 HCME1phase[3]= (double) ((HCME1-3 )*6 % 360)*M_PI/180.0;
04300 HCME1phase[2]= (double) ((HCME1-9 )*6 % 360)*M_PI/180.0;
04301 HCME1phase[1]= (double) ((HCME1-15)*6 % 360)*M_PI/180.0;
04302 HCME1phase[0]= (double) ((HCME1-21)*6 % 360)*M_PI/180.0;
04303
04304 HCMWBphase[7]= (double) ((HCMWB+18)*6 % 360)*M_PI/180.0;
04305 HCMWBphase[6]= (double) ((HCMWB-30)*6 % 360)*M_PI/180.0;
04306 HCMWBphase[5]= (double) ((HCMWB-18)*6 % 360)*M_PI/180.0;
04307 HCMWBphase[4]= (double) ((HCMWB-6 )*6 % 360)*M_PI/180.0;
04308 HCMWBphase[3]= (double) ((HCMWB+6 )*6 % 360)*M_PI/180.0;
04309 HCMWBphase[2]= (double) ((HCMWB+18)*6 % 360)*M_PI/180.0;
04310 HCMWBphase[1]= (double) ((HCMWB-30)*6 % 360)*M_PI/180.0;
04311 HCMWBphase[0]= (double) ((HCMWB-18)*6 % 360)*M_PI/180.0;
04312
04313 HCMNBphase[7]= (double) ((HCMNB-24)*6 % 360)*M_PI/180.0;
04314 HCMNBphase[6]= (double) ((HCMNB-0 )*6 % 360)*M_PI/180.0;
04315 HCMNBphase[5]= (double) ((HCMNB+24)*6 % 360)*M_PI/180.0;
04316 HCMNBphase[4]= (double) ((HCMNB-12)*6 % 360)*M_PI/180.0;
04317 HCMNBphase[3]= (double) ((HCMNB+12)*6 % 360)*M_PI/180.0;
04318 HCMNBphase[2]= (double) ((HCMNB-24)*6 % 360)*M_PI/180.0;
04319 HCMNBphase[1]= (double) ((HCMNB+0 )*6 % 360)*M_PI/180.0;
04320 HCMNBphase[0]= (double) ((HCMNB+24 )*6 % 360)*M_PI/180.0;
04321 }
04322 if(Num_lambda_filter == 10)
04323 {
04324 HCME1phase[9]= (double) ((HCME1+27)*6 % 360)*M_PI/180.0;
04325 HCME1phase[8]= (double) ((HCME1+21)*6 % 360)*M_PI/180.0;
04326 HCME1phase[7]= (double) ((HCME1+15)*6 % 360)*M_PI/180.0;
04327 HCME1phase[6]= (double) ((HCME1+9 )*6 % 360)*M_PI/180.0;
04328 HCME1phase[5]= (double) ((HCME1+3 )*6 % 360)*M_PI/180.0;
04329 HCME1phase[4]= (double) ((HCME1-3 )*6 % 360)*M_PI/180.0;
04330 HCME1phase[3]= (double) ((HCME1-9 )*6 % 360)*M_PI/180.0;
04331 HCME1phase[2]= (double) ((HCME1-15)*6 % 360)*M_PI/180.0;
04332 HCME1phase[1]= (double) ((HCME1-21)*6 % 360)*M_PI/180.0;
04333 HCME1phase[0]= (double) ((HCME1-27)*6 % 360)*M_PI/180.0;
04334
04335 HCMWBphase[9]= (double) ((HCMWB+6)*6 % 360)*M_PI/180.0;
04336 HCMWBphase[8]= (double) ((HCMWB+18)*6 % 360)*M_PI/180.0;
04337 HCMWBphase[7]= (double) ((HCMWB-30)*6 % 360)*M_PI/180.0;
04338 HCMWBphase[6]= (double) ((HCMWB-18)*6 % 360)*M_PI/180.0;
04339 HCMWBphase[5]= (double) ((HCMWB-6 )*6 % 360)*M_PI/180.0;
04340 HCMWBphase[4]= (double) ((HCMWB+6 )*6 % 360)*M_PI/180.0;
04341 HCMWBphase[3]= (double) ((HCMWB+18)*6 % 360)*M_PI/180.0;
04342 HCMWBphase[2]= (double) ((HCMWB-30)*6 % 360)*M_PI/180.0;
04343 HCMWBphase[1]= (double) ((HCMWB-18)*6 % 360)*M_PI/180.0;
04344 HCMWBphase[0]= (double) ((HCMWB-6)*6 % 360)*M_PI/180.0;
04345
04346 HCMNBphase[9]= (double) ((HCMNB+12 )*6 % 360)*M_PI/180.0;
04347 HCMNBphase[8]= (double) ((HCMNB-24)*6 % 360)*M_PI/180.0;
04348 HCMNBphase[7]= (double) ((HCMNB-0 )*6 % 360)*M_PI/180.0;
04349 HCMNBphase[6]= (double) ((HCMNB+24)*6 % 360)*M_PI/180.0;
04350 HCMNBphase[5]= (double) ((HCMNB-12)*6 % 360)*M_PI/180.0;
04351 HCMNBphase[4]= (double) ((HCMNB+12)*6 % 360)*M_PI/180.0;
04352 HCMNBphase[3]= (double) ((HCMNB-24)*6 % 360)*M_PI/180.0;
04353 HCMNBphase[2]= (double) ((HCMNB+0 )*6 % 360)*M_PI/180.0;
04354 HCMNBphase[1]= (double) ((HCMNB+24 )*6 % 360)*M_PI/180.0;
04355 HCMNBphase[0]= (double) ((HCMNB-12)*6 % 360)*M_PI/180.0;
04356 }
04357
04358
04359
04360 for(j=0;j<Num_lambda;++j) {
04361 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.;
04362 }
04363
04364
04365
04366 for(i=0;i<Num_lambda_filter;++i)
04367 {
04368 for(j=0;j<Num_lambda;++j){
04369 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.;
04370 }
04371
04372 }
04373
04374 free(HCMNBphase);
04375 free(HCMWBphase);
04376 free(HCME1phase);
04377
04378
04379 status=0;
04380 return status;
04381
04382 }
04383
04384
04385
04386 char *meinversion_version(){return strdup("$Id: vfisv_harp.c,v 1.21 2016/04/18 18:19:15 yliu Exp $");}
04387
04388
04389
04390