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