1 |
|
/* |
2 |
< |
* sharp.c |
2 |
> |
* sharp.c |
3 |
|
* |
4 |
|
* This module creates the pipeline Space Weather Active Region Patches (SHARPs). |
5 |
|
* It is a hard-coded strip-down version of bmap.c. |
13 |
|
* Series 2: Sharp_cutout: |
14 |
|
* cutouts of magnetogram, bitmap, continuum, doppler (HARP defined, various sizes in CCD pixels) |
15 |
|
* cutouts of all vector data segments (same as above) |
16 |
< |
* |
16 |
> |
* |
17 |
|
* Author: |
18 |
|
* Xudong Sun; Monica Bobra |
19 |
|
* |
110 |
|
// Nyqvist rate at disk center is 0.03 degree. Oversample above 0.015 degree |
111 |
|
#define NYQVIST (0.015) |
112 |
|
|
113 |
+ |
// Maximum variation of LONDTMAX-LONDTMIN |
114 |
+ |
#define MAXLONDIFF (1.2e-4) |
115 |
+ |
|
116 |
|
// Some other things |
117 |
|
#ifndef MIN |
118 |
|
#define MIN(a,b) (((a)<(b)) ? (a) : (b)) |
148 |
|
struct swIndex { |
149 |
|
float mean_vf; |
150 |
|
float count_mask; |
151 |
< |
float absFlux; |
152 |
< |
float mean_hf; |
153 |
< |
float mean_gamma; |
154 |
< |
float mean_derivative_btotal; |
155 |
< |
float mean_derivative_bh; |
156 |
< |
float mean_derivative_bz; |
157 |
< |
float mean_jz; |
158 |
< |
float us_i; |
159 |
< |
float mean_alpha; |
151 |
> |
float absFlux; |
152 |
> |
float mean_hf; |
153 |
> |
float mean_gamma; |
154 |
> |
float mean_derivative_btotal; |
155 |
> |
float mean_derivative_bh; |
156 |
> |
float mean_derivative_bz; |
157 |
> |
float mean_jz; |
158 |
> |
float us_i; |
159 |
> |
float mean_alpha; |
160 |
|
float mean_ih; |
161 |
|
float total_us_ih; |
162 |
|
float total_abs_ih; |
183 |
|
float totpot_err; |
184 |
|
float meanshear_angle_err; |
185 |
|
float Rparam; |
186 |
+ |
float totfx; |
187 |
+ |
float totfy; |
188 |
+ |
float totfz; |
189 |
+ |
float totbsq; |
190 |
+ |
float epsx; |
191 |
+ |
float epsy; |
192 |
+ |
float epsz; |
193 |
|
}; |
194 |
|
|
195 |
|
// Mapping method |
1052 |
|
float disk_lonc = drms_getkey_float(inRec, "CRLN_OBS", &status); |
1053 |
|
|
1054 |
|
/* Center coord */ |
1055 |
+ |
// Changed into double Jun 16 2014 XS |
1056 |
|
|
1057 |
< |
float minlon = drms_getkey_float(inRec, "LONDTMIN", &status); if (status) return 1; // Stonyhurst lon |
1058 |
< |
float maxlon = drms_getkey_float(inRec, "LONDTMAX", &status); if (status) return 1; |
1059 |
< |
float minlat = drms_getkey_float(inRec, "LATDTMIN", &status); if (status) return 1; |
1060 |
< |
float maxlat = drms_getkey_float(inRec, "LATDTMAX", &status); if (status) return 1; |
1057 |
> |
double minlon = drms_getkey_double(inRec, "LONDTMIN", &status); if (status) return 1; // Stonyhurst lon |
1058 |
> |
double maxlon = drms_getkey_double(inRec, "LONDTMAX", &status); if (status) return 1; |
1059 |
> |
double minlat = drms_getkey_double(inRec, "LATDTMIN", &status); if (status) return 1; |
1060 |
> |
double maxlat = drms_getkey_double(inRec, "LATDTMAX", &status); if (status) return 1; |
1061 |
|
|
1062 |
|
// A bug fixer for HARP (per M. Turmon) |
1063 |
|
// When AR is below threshold, "LONDTMIN", "LONDTMAX" will be wrong |
1088 |
|
mInfo->yc = (maxlat + minlat) / 2.; |
1089 |
|
|
1090 |
|
/* Size */ |
1091 |
< |
|
1092 |
< |
mInfo->ncol = round((maxlon - minlon) / mInfo->xscale); |
1091 |
> |
// Rounded to 1.d3 precision first. Jun 16 2014 XS |
1092 |
> |
// The previous fix does not work. LONDTMAX-LONDTMIN varies from frame to frame |
1093 |
> |
// Need to find out the maximum possible difference, MAXLONDIFF (1.2e-4) |
1094 |
> |
// Now, ncol = (maxlon-minlon)/xscale, if the decimal part is outside 0.5 \pm (MAXLONDIFF/xscale) |
1095 |
> |
// proceed as it is. else, all use floor on ncol |
1096 |
> |
|
1097 |
> |
float dpix = (MAXLONDIFF / mInfo->xscale) * 1.5; // "danger zone" |
1098 |
> |
float ncol = (maxlon - minlon) / mInfo->xscale; |
1099 |
> |
float d_ncol = fabs(ncol - floor(ncol) - 0.5); // distance to 0.5 |
1100 |
> |
if (d_ncol < dpix) { |
1101 |
> |
mInfo->ncol = floor(ncol); |
1102 |
> |
} else { |
1103 |
> |
mInfo->ncol = round(ncol); |
1104 |
> |
} |
1105 |
> |
|
1106 |
|
mInfo->nrow = round((maxlat - minlat) / mInfo->yscale); |
1107 |
|
|
1108 |
+ |
printf("xcol=%f, ncol=%d, nrow=%d\n", ncol, mInfo->ncol, mInfo->nrow); |
1109 |
+ |
|
1110 |
|
return 0; |
1111 |
|
|
1112 |
|
} |
1932 |
|
DRMS_Array_t *bzArray = drms_segment_read(bzSeg, DRMS_TYPE_FLOAT, &status); |
1933 |
|
float *bz = (float *) bzArray->data; // bz |
1934 |
|
|
1935 |
< |
//Use magnetogram map to compute R |
1936 |
< |
DRMS_Segment_t *losSeg = drms_segment_lookup(inRec, "magnetogram"); |
1937 |
< |
DRMS_Array_t *losArray = drms_segment_read(losSeg, DRMS_TYPE_FLOAT, &status); |
1938 |
< |
float *los = (float *) losArray->data; // los |
1935 |
> |
//Use magnetogram map to compute R |
1936 |
> |
DRMS_Segment_t *losSeg = drms_segment_lookup(inRec, "magnetogram"); |
1937 |
> |
DRMS_Array_t *losArray = drms_segment_read(losSeg, DRMS_TYPE_FLOAT, &status); |
1938 |
> |
float *los = (float *) losArray->data; // los |
1939 |
|
|
1940 |
|
DRMS_Segment_t *bz_errSeg = drms_segment_lookup(inRec, BR_ERR_SEG_CEA); |
1941 |
|
DRMS_Array_t *bz_errArray = drms_segment_read(bz_errSeg, DRMS_TYPE_FLOAT, &status); |
1960 |
|
float crpix1 = drms_getkey_float(inRec, "CRPIX1", &status); |
1961 |
|
float crpix2 = drms_getkey_float(inRec, "CRPIX2", &status); |
1962 |
|
|
1963 |
< |
// convert cdelt1_orig from degrees to arcsec |
1964 |
< |
float cdelt1 = (atan((rsun_ref*cdelt1_orig*RADSINDEG)/(dsun_obs)))*(1/RADSINDEG)*(3600.); |
1965 |
< |
int nx1 = nx*cdelt1/2; |
1966 |
< |
int ny1 = ny*cdelt1/2; |
1963 |
> |
// convert cdelt1_orig from degrees to arcsec |
1964 |
> |
float cdelt1 = (atan((rsun_ref*cdelt1_orig*RADSINDEG)/(dsun_obs)))*(1/RADSINDEG)*(3600.); |
1965 |
> |
|
1966 |
> |
//if (nx1 > floor((nx-1)/scale + 1) ) |
1967 |
> |
// DIE("X-dimension of output array in fsample() is too large."); |
1968 |
> |
//if (ny1 > floor((ny-1)/scale + 1) ) |
1969 |
> |
// DIE("Y-dimension of output array in fsample() is too large."); |
1970 |
|
|
1971 |
|
// Temp arrays |
1972 |
|
float *bh = (float *) (malloc(nxny * sizeof(float))); |
1986 |
|
float *dery_bz = (float *) (malloc(nxny * sizeof(float))); |
1987 |
|
float *bt_err = (float *) (malloc(nxny * sizeof(float))); |
1988 |
|
float *bh_err = (float *) (malloc(nxny * sizeof(float))); |
1989 |
< |
float *jz_err = (float *) (malloc(nxny * sizeof(float))); |
1990 |
< |
float *jz_err_squared = (float *) (malloc(nxny * sizeof(float))); |
1991 |
< |
float *jz_err_squared_smooth = (float *) (malloc(nxny * sizeof(float))); |
1992 |
< |
float *jz_rms_err = (float *) (malloc(nxny * sizeof(float))); |
1993 |
< |
|
1994 |
< |
// malloc some arrays for the R parameter calculation |
1995 |
< |
float *rim = (float *)malloc(nx1*ny1*sizeof(float)); |
1996 |
< |
float *p1p0 = (float *)malloc(nx1*ny1*sizeof(float)); |
1997 |
< |
float *p1n0 = (float *)malloc(nx1*ny1*sizeof(float)); |
1998 |
< |
float *p1p = (float *)malloc(nx1*ny1*sizeof(float)); |
1999 |
< |
float *p1n = (float *)malloc(nx1*ny1*sizeof(float)); |
2000 |
< |
float *p1 = (float *)malloc(nx1*ny1*sizeof(float)); |
2001 |
< |
float *pmap = (float *)malloc(nx1*ny1*sizeof(float)); |
1989 |
> |
float *jz_err = (float *) (malloc(nxny * sizeof(float))); |
1990 |
> |
float *jz_err_squared = (float *) (malloc(nxny * sizeof(float))); |
1991 |
> |
float *jz_err_squared_smooth = (float *) (malloc(nxny * sizeof(float))); |
1992 |
> |
float *jz_rms_err = (float *) (malloc(nxny * sizeof(float))); |
1993 |
> |
float *err_term1 = (float *) (calloc(nxny, sizeof(float))); |
1994 |
> |
float *err_term2 = (float *) (calloc(nxny, sizeof(float))); |
1995 |
> |
float *err_termA = (float *) (calloc(nxny, sizeof(float))); |
1996 |
> |
float *err_termB = (float *) (calloc(nxny, sizeof(float))); |
1997 |
> |
float *err_termAt = (float *) (calloc(nxny, sizeof(float))); |
1998 |
> |
float *err_termBt = (float *) (calloc(nxny, sizeof(float))); |
1999 |
> |
float *err_termAh = (float *) (calloc(nxny, sizeof(float))); |
2000 |
> |
float *err_termBh = (float *) (calloc(nxny, sizeof(float))); |
2001 |
> |
|
2002 |
> |
// define some values for the R calculation |
2003 |
> |
int scale = round(2.0/cdelt1); |
2004 |
> |
int nx1 = nx/scale; |
2005 |
> |
int ny1 = ny/scale; |
2006 |
> |
int nxp = nx1+40; |
2007 |
> |
int nyp = ny1+40; |
2008 |
> |
float *rim = (float *)malloc(nx1*ny1*sizeof(float)); |
2009 |
> |
float *p1p0 = (float *)malloc(nx1*ny1*sizeof(float)); |
2010 |
> |
float *p1n0 = (float *)malloc(nx1*ny1*sizeof(float)); |
2011 |
> |
float *p1p = (float *)malloc(nx1*ny1*sizeof(float)); |
2012 |
> |
float *p1n = (float *)malloc(nx1*ny1*sizeof(float)); |
2013 |
> |
float *p1 = (float *)malloc(nx1*ny1*sizeof(float)); |
2014 |
> |
float *pmap = (float *)malloc(nxp*nyp*sizeof(float)); |
2015 |
> |
float *p1pad = (float *)malloc(nxp*nyp*sizeof(float)); |
2016 |
> |
float *pmapn = (float *)malloc(nx1*ny1*sizeof(float)); |
2017 |
> |
|
2018 |
> |
// define some arrays for the lorentz force calculation |
2019 |
> |
float *fx = (float *) (malloc(nxny * sizeof(float))); |
2020 |
> |
float *fy = (float *) (malloc(nxny * sizeof(float))); |
2021 |
> |
float *fz = (float *) (malloc(nxny * sizeof(float))); |
2022 |
|
|
2023 |
+ |
|
2024 |
|
//spaceweather quantities computed |
2025 |
|
if (computeAbsFlux(bz_err, bz , dims, &(swKeys_ptr->absFlux), &(swKeys_ptr->mean_vf), &(swKeys_ptr->mean_vf_err), |
2026 |
< |
&(swKeys_ptr->count_mask), mask, bitmask, cdelt1, rsun_ref, rsun_obs)) |
2027 |
< |
{ |
2026 |
> |
&(swKeys_ptr->count_mask), mask, bitmask, cdelt1, rsun_ref, rsun_obs)) |
2027 |
> |
{ |
2028 |
|
swKeys_ptr->absFlux = DRMS_MISSING_FLOAT; // If fail, fill in NaN |
2029 |
|
swKeys_ptr->mean_vf = DRMS_MISSING_FLOAT; |
2030 |
< |
swKeys_ptr->mean_vf_err = DRMS_MISSING_FLOAT; |
2031 |
< |
swKeys_ptr->count_mask = DRMS_MISSING_INT; |
2030 |
> |
swKeys_ptr->mean_vf_err = DRMS_MISSING_FLOAT; |
2031 |
> |
swKeys_ptr->count_mask = DRMS_MISSING_INT; |
2032 |
|
} |
2033 |
|
|
2034 |
|
for (int i = 0; i < nxny; i++) bpz[i] = bz[i]; |
2038 |
|
|
2039 |
|
if (computeGamma(bz_err, bh_err, bx, by, bz, bh, dims, &(swKeys_ptr->mean_gamma), &(swKeys_ptr->mean_gamma_err),mask, bitmask)) |
2040 |
|
{ |
2041 |
< |
swKeys_ptr->mean_gamma = DRMS_MISSING_FLOAT; |
2042 |
< |
swKeys_ptr->mean_gamma_err = DRMS_MISSING_FLOAT; |
2043 |
< |
} |
2041 |
> |
swKeys_ptr->mean_gamma = DRMS_MISSING_FLOAT; |
2042 |
> |
swKeys_ptr->mean_gamma_err = DRMS_MISSING_FLOAT; |
2043 |
> |
} |
2044 |
|
|
2045 |
|
computeB_total(bx_err, by_err, bz_err, bt_err, bx, by, bz, bt, dims, mask, bitmask); |
2046 |
|
|
2047 |
< |
if (computeBtotalderivative(bt, dims, &(swKeys_ptr->mean_derivative_btotal), mask, bitmask, derx_bt, dery_bt, bt_err, &(swKeys_ptr->mean_derivative_btotal_err))) |
2048 |
< |
{ |
2047 |
> |
if (computeBtotalderivative(bt, dims, &(swKeys_ptr->mean_derivative_btotal), mask, bitmask, derx_bt, |
2048 |
> |
dery_bt, bt_err, &(swKeys_ptr->mean_derivative_btotal_err), err_termAt, err_termBt)) |
2049 |
> |
{ |
2050 |
|
swKeys_ptr->mean_derivative_btotal = DRMS_MISSING_FLOAT; |
2051 |
|
swKeys_ptr->mean_derivative_btotal_err = DRMS_MISSING_FLOAT; |
2052 |
< |
} |
2052 |
> |
} |
2053 |
|
|
2054 |
< |
if (computeBhderivative(bh, bh_err, dims, &(swKeys_ptr->mean_derivative_bh), &(swKeys_ptr->mean_derivative_bh_err), mask, bitmask, derx_bh, dery_bh)) |
2055 |
< |
{ |
2054 |
> |
if (computeBhderivative(bh, bh_err, dims, &(swKeys_ptr->mean_derivative_bh), |
2055 |
> |
&(swKeys_ptr->mean_derivative_bh_err), mask, bitmask, derx_bh, dery_bh, err_termAh, err_termBh)) |
2056 |
> |
{ |
2057 |
|
swKeys_ptr->mean_derivative_bh = DRMS_MISSING_FLOAT; |
2058 |
< |
swKeys_ptr->mean_derivative_bh_err = DRMS_MISSING_FLOAT; |
2058 |
> |
swKeys_ptr->mean_derivative_bh_err = DRMS_MISSING_FLOAT; |
2059 |
|
} |
2060 |
|
|
2061 |
< |
if (computeBzderivative(bz, bz_err, dims, &(swKeys_ptr->mean_derivative_bz), &(swKeys_ptr->mean_derivative_bz_err), mask, bitmask, derx_bz, dery_bz)) |
2062 |
< |
{ |
2061 |
> |
if (computeBzderivative(bz, bz_err, dims, &(swKeys_ptr->mean_derivative_bz), &(swKeys_ptr->mean_derivative_bz_err), |
2062 |
> |
mask, bitmask, derx_bz, dery_bz, err_termA, err_termB)) |
2063 |
> |
{ |
2064 |
|
swKeys_ptr->mean_derivative_bz = DRMS_MISSING_FLOAT; // If fail, fill in NaN |
2065 |
< |
swKeys_ptr->mean_derivative_bz_err = DRMS_MISSING_FLOAT; |
2066 |
< |
} |
2065 |
> |
swKeys_ptr->mean_derivative_bz_err = DRMS_MISSING_FLOAT; |
2066 |
> |
} |
2067 |
|
|
2068 |
|
computeJz(bx_err, by_err, bx, by, dims, jz, jz_err, jz_err_squared, mask, bitmask, cdelt1, rsun_ref, rsun_obs, |
2069 |
< |
derx, dery); |
2069 |
> |
derx, dery, err_term1, err_term2); |
2070 |
|
|
2071 |
|
|
2072 |
< |
if(computeJzsmooth(bx, by, dims, jz, jz_smooth, jz_err, jz_rms_err, jz_err_squared_smooth, &(swKeys_ptr->mean_jz), |
2072 |
> |
if(computeJzsmooth(bx, by, dims, jz, jz_smooth, jz_err, jz_rms_err, jz_err_squared_smooth, &(swKeys_ptr->mean_jz), |
2073 |
|
&(swKeys_ptr->mean_jz_err), &(swKeys_ptr->us_i), &(swKeys_ptr->us_i_err), mask, bitmask, cdelt1, |
2074 |
|
rsun_ref, rsun_obs, derx, dery)) |
2075 |
< |
{ |
2076 |
< |
swKeys_ptr->mean_jz = DRMS_MISSING_FLOAT; |
2075 |
> |
{ |
2076 |
> |
swKeys_ptr->mean_jz = DRMS_MISSING_FLOAT; |
2077 |
|
swKeys_ptr->us_i = DRMS_MISSING_FLOAT; |
2078 |
< |
swKeys_ptr->mean_jz_err = DRMS_MISSING_FLOAT; |
2079 |
< |
swKeys_ptr->us_i_err = DRMS_MISSING_FLOAT; |
2078 |
> |
swKeys_ptr->mean_jz_err = DRMS_MISSING_FLOAT; |
2079 |
> |
swKeys_ptr->us_i_err = DRMS_MISSING_FLOAT; |
2080 |
|
} |
2081 |
|
|
2082 |
< |
if (computeAlpha(jz_err, bz_err, bz, dims, jz, jz_smooth, &(swKeys_ptr->mean_alpha), &(swKeys_ptr->mean_alpha_err), mask, bitmask, cdelt1, rsun_ref, rsun_obs)) |
2083 |
< |
{ |
2082 |
> |
if (computeAlpha(jz_err, bz_err, bz, dims, jz, jz_smooth, &(swKeys_ptr->mean_alpha), &(swKeys_ptr->mean_alpha_err), |
2083 |
> |
mask, bitmask, cdelt1, rsun_ref, rsun_obs)) |
2084 |
> |
{ |
2085 |
|
swKeys_ptr->mean_alpha = DRMS_MISSING_FLOAT; |
2086 |
< |
swKeys_ptr->mean_alpha_err = DRMS_MISSING_FLOAT; |
2087 |
< |
} |
2086 |
> |
swKeys_ptr->mean_alpha_err = DRMS_MISSING_FLOAT; |
2087 |
> |
} |
2088 |
|
|
2089 |
< |
if (computeHelicity(jz_err, jz_rms_err, bz_err, bz, dims, jz, &(swKeys_ptr->mean_ih), &(swKeys_ptr->mean_ih_err), &(swKeys_ptr->total_us_ih), &(swKeys_ptr->total_abs_ih), |
2090 |
< |
&(swKeys_ptr->total_us_ih_err), &(swKeys_ptr->total_abs_ih_err), mask, bitmask, cdelt1, rsun_ref, rsun_obs)) |
2091 |
< |
{ |
2089 |
> |
if (computeHelicity(jz_err, jz_rms_err, bz_err, bz, dims, jz, &(swKeys_ptr->mean_ih), &(swKeys_ptr->mean_ih_err), |
2090 |
> |
&(swKeys_ptr->total_us_ih), &(swKeys_ptr->total_abs_ih), |
2091 |
> |
&(swKeys_ptr->total_us_ih_err), &(swKeys_ptr->total_abs_ih_err), mask, bitmask, cdelt1, rsun_ref, rsun_obs)) |
2092 |
> |
{ |
2093 |
|
swKeys_ptr->mean_ih = DRMS_MISSING_FLOAT; |
2094 |
|
swKeys_ptr->total_us_ih = DRMS_MISSING_FLOAT; |
2095 |
|
swKeys_ptr->total_abs_ih = DRMS_MISSING_FLOAT; |
2096 |
< |
swKeys_ptr->mean_ih_err = DRMS_MISSING_FLOAT; |
2097 |
< |
swKeys_ptr->total_us_ih_err = DRMS_MISSING_FLOAT; |
2098 |
< |
swKeys_ptr->total_abs_ih_err = DRMS_MISSING_FLOAT; |
2096 |
> |
swKeys_ptr->mean_ih_err = DRMS_MISSING_FLOAT; |
2097 |
> |
swKeys_ptr->total_us_ih_err = DRMS_MISSING_FLOAT; |
2098 |
> |
swKeys_ptr->total_abs_ih_err = DRMS_MISSING_FLOAT; |
2099 |
|
} |
2100 |
|
|
2101 |
|
if (computeSumAbsPerPolarity(jz_err, bz_err, bz, jz, dims, &(swKeys_ptr->totaljz), &(swKeys_ptr->totaljz_err), |
2102 |
< |
mask, bitmask, cdelt1, rsun_ref, rsun_obs)) |
2103 |
< |
{ |
2102 |
> |
mask, bitmask, cdelt1, rsun_ref, rsun_obs)) |
2103 |
> |
{ |
2104 |
|
swKeys_ptr->totaljz = DRMS_MISSING_FLOAT; |
2105 |
< |
swKeys_ptr->totaljz_err = DRMS_MISSING_FLOAT; |
2105 |
> |
swKeys_ptr->totaljz_err = DRMS_MISSING_FLOAT; |
2106 |
|
} |
2107 |
|
|
2108 |
|
if (computeFreeEnergy(bx_err, by_err, bx, by, bpx, bpy, dims, |
2109 |
< |
&(swKeys_ptr->meanpot), &(swKeys_ptr->meanpot_err), &(swKeys_ptr->totpot), &(swKeys_ptr->totpot_err), |
2110 |
< |
mask, bitmask, cdelt1, rsun_ref, rsun_obs)) |
2111 |
< |
{ |
2109 |
> |
&(swKeys_ptr->meanpot), &(swKeys_ptr->meanpot_err), &(swKeys_ptr->totpot), &(swKeys_ptr->totpot_err), |
2110 |
> |
mask, bitmask, cdelt1, rsun_ref, rsun_obs)) |
2111 |
> |
{ |
2112 |
|
swKeys_ptr->meanpot = DRMS_MISSING_FLOAT; // If fail, fill in NaN |
2113 |
|
swKeys_ptr->totpot = DRMS_MISSING_FLOAT; |
2114 |
< |
swKeys_ptr->meanpot_err = DRMS_MISSING_FLOAT; |
2115 |
< |
swKeys_ptr->totpot_err = DRMS_MISSING_FLOAT; |
2114 |
> |
swKeys_ptr->meanpot_err = DRMS_MISSING_FLOAT; |
2115 |
> |
swKeys_ptr->totpot_err = DRMS_MISSING_FLOAT; |
2116 |
|
} |
2117 |
|
|
2118 |
|
|
2119 |
|
if (computeShearAngle(bx_err, by_err, bz_err, bx, by, bz, bpx, bpy, bpz, dims, |
2120 |
< |
&(swKeys_ptr->meanshear_angle), &(swKeys_ptr->meanshear_angle_err), &(swKeys_ptr->area_w_shear_gt_45), |
2121 |
< |
mask, bitmask)) { |
2120 |
> |
&(swKeys_ptr->meanshear_angle), &(swKeys_ptr->meanshear_angle_err), &(swKeys_ptr->area_w_shear_gt_45), |
2121 |
> |
mask, bitmask)) |
2122 |
> |
{ |
2123 |
|
swKeys_ptr->meanshear_angle = DRMS_MISSING_FLOAT; // If fail, fill in NaN |
2124 |
|
swKeys_ptr->area_w_shear_gt_45 = DRMS_MISSING_FLOAT; |
2125 |
< |
swKeys_ptr->meanshear_angle_err= DRMS_MISSING_FLOAT; |
2125 |
> |
swKeys_ptr->meanshear_angle_err= DRMS_MISSING_FLOAT; |
2126 |
|
} |
2127 |
|
|
2072 |
– |
/* |
2128 |
|
if (computeR(bz_err, los , dims, &(swKeys_ptr->Rparam), cdelt1, rim, p1p0, p1n0, |
2129 |
< |
p1p, p1n, p1, pmap, nx1, ny1)) |
2130 |
< |
{ |
2129 |
> |
p1p, p1n, p1, pmap, nx1, ny1, scale, p1pad, nxp, nyp, pmapn)) |
2130 |
> |
{ |
2131 |
|
swKeys_ptr->Rparam = DRMS_MISSING_FLOAT; // If fail, fill in NaN |
2132 |
+ |
} |
2133 |
+ |
|
2134 |
+ |
|
2135 |
+ |
if (computeLorentz(bx, by, bz, fx, fy, fz, dims, &(swKeys_ptr->totfx), &(swKeys_ptr->totfy), &(swKeys_ptr->totfz), &(swKeys_ptr->totbsq), |
2136 |
+ |
&(swKeys_ptr->epsx), &(swKeys_ptr->epsy), &(swKeys_ptr->epsz), mask, bitmask, cdelt1, rsun_ref, rsun_obs)) |
2137 |
+ |
{ |
2138 |
+ |
swKeys_ptr->totfx = DRMS_MISSING_FLOAT; |
2139 |
+ |
swKeys_ptr->totfy = DRMS_MISSING_FLOAT; |
2140 |
+ |
swKeys_ptr->totfz = DRMS_MISSING_FLOAT; |
2141 |
+ |
swKeys_ptr->totbsq = DRMS_MISSING_FLOAT; |
2142 |
+ |
swKeys_ptr->epsx = DRMS_MISSING_FLOAT; |
2143 |
+ |
swKeys_ptr->epsy = DRMS_MISSING_FLOAT; |
2144 |
+ |
swKeys_ptr->epsz = DRMS_MISSING_FLOAT; |
2145 |
+ |
|
2146 |
|
} |
2078 |
– |
*/ |
2147 |
|
|
2148 |
|
// Clean up the arrays |
2149 |
|
|
2152 |
|
drms_free_array(bxArray); |
2153 |
|
drms_free_array(byArray); |
2154 |
|
drms_free_array(bzArray); |
2155 |
< |
drms_free_array(losArray); // Mar 7 |
2156 |
< |
drms_free_array(bx_errArray); |
2155 |
> |
drms_free_array(losArray); // Mar 7 |
2156 |
> |
drms_free_array(bx_errArray); |
2157 |
|
drms_free_array(by_errArray); |
2158 |
|
drms_free_array(bz_errArray); |
2159 |
|
|
2164 |
|
free(derx_bz); free(dery_bz); |
2165 |
|
free(derx_bh); free(dery_bh); |
2166 |
|
free(bt_err); free(bh_err); free(jz_err); |
2167 |
< |
free(jz_err_squared); free(jz_rms_err); |
2168 |
< |
free(jz_err_squared_smooth); |
2169 |
< |
|
2170 |
< |
free(rim); |
2171 |
< |
free(p1p0); |
2172 |
< |
free(p1n0); |
2173 |
< |
free(p1p); |
2174 |
< |
free(p1n); |
2175 |
< |
free(p1); |
2176 |
< |
free(pmap); |
2177 |
< |
|
2167 |
> |
free(jz_err_squared); free(jz_rms_err); |
2168 |
> |
free(jz_err_squared_smooth); |
2169 |
> |
|
2170 |
> |
// free the arrays that are related to the numerical derivatives |
2171 |
> |
free(err_term2); |
2172 |
> |
free(err_term1); |
2173 |
> |
free(err_termB); |
2174 |
> |
free(err_termA); |
2175 |
> |
free(err_termBt); |
2176 |
> |
free(err_termAt); |
2177 |
> |
free(err_termBh); |
2178 |
> |
free(err_termAh); |
2179 |
> |
|
2180 |
> |
// free the arrays that are related to the r calculation |
2181 |
> |
free(rim); |
2182 |
> |
free(p1p0); |
2183 |
> |
free(p1n0); |
2184 |
> |
free(p1p); |
2185 |
> |
free(p1n); |
2186 |
> |
free(p1); |
2187 |
> |
free(pmap); |
2188 |
> |
free(p1pad); |
2189 |
> |
free(pmapn); |
2190 |
> |
|
2191 |
> |
// free the arrays that are related to the lorentz calculation |
2192 |
> |
free(fx); free(fy); free(fz); |
2193 |
|
} |
2194 |
|
|
2195 |
|
/* |
2199 |
|
|
2200 |
|
void setSWIndex(DRMS_Record_t *outRec, struct swIndex *swKeys_ptr) |
2201 |
|
{ |
2202 |
< |
drms_setkey_float(outRec, "USFLUX", swKeys_ptr->mean_vf); |
2203 |
< |
drms_setkey_float(outRec, "MEANGAM", swKeys_ptr->mean_gamma); |
2204 |
< |
drms_setkey_float(outRec, "MEANGBT", swKeys_ptr->mean_derivative_btotal); |
2205 |
< |
drms_setkey_float(outRec, "MEANGBH", swKeys_ptr->mean_derivative_bh); |
2206 |
< |
drms_setkey_float(outRec, "MEANGBZ", swKeys_ptr->mean_derivative_bz); |
2207 |
< |
drms_setkey_float(outRec, "MEANJZD", swKeys_ptr->mean_jz); |
2208 |
< |
drms_setkey_float(outRec, "TOTUSJZ", swKeys_ptr->us_i); |
2209 |
< |
drms_setkey_float(outRec, "MEANALP", swKeys_ptr->mean_alpha); |
2210 |
< |
drms_setkey_float(outRec, "MEANJZH", swKeys_ptr->mean_ih); |
2211 |
< |
drms_setkey_float(outRec, "TOTUSJH", swKeys_ptr->total_us_ih); |
2212 |
< |
drms_setkey_float(outRec, "ABSNJZH", swKeys_ptr->total_abs_ih); |
2213 |
< |
drms_setkey_float(outRec, "SAVNCPP", swKeys_ptr->totaljz); |
2214 |
< |
drms_setkey_float(outRec, "MEANPOT", swKeys_ptr->meanpot); |
2215 |
< |
drms_setkey_float(outRec, "TOTPOT", swKeys_ptr->totpot); |
2216 |
< |
drms_setkey_float(outRec, "MEANSHR", swKeys_ptr->meanshear_angle); |
2217 |
< |
drms_setkey_float(outRec, "SHRGT45", swKeys_ptr->area_w_shear_gt_45); |
2202 |
> |
drms_setkey_float(outRec, "USFLUX", swKeys_ptr->mean_vf); |
2203 |
> |
drms_setkey_float(outRec, "MEANGAM", swKeys_ptr->mean_gamma); |
2204 |
> |
drms_setkey_float(outRec, "MEANGBT", swKeys_ptr->mean_derivative_btotal); |
2205 |
> |
drms_setkey_float(outRec, "MEANGBH", swKeys_ptr->mean_derivative_bh); |
2206 |
> |
drms_setkey_float(outRec, "MEANGBZ", swKeys_ptr->mean_derivative_bz); |
2207 |
> |
drms_setkey_float(outRec, "MEANJZD", swKeys_ptr->mean_jz); |
2208 |
> |
drms_setkey_float(outRec, "TOTUSJZ", swKeys_ptr->us_i); |
2209 |
> |
drms_setkey_float(outRec, "MEANALP", swKeys_ptr->mean_alpha); |
2210 |
> |
drms_setkey_float(outRec, "MEANJZH", swKeys_ptr->mean_ih); |
2211 |
> |
drms_setkey_float(outRec, "TOTUSJH", swKeys_ptr->total_us_ih); |
2212 |
> |
drms_setkey_float(outRec, "ABSNJZH", swKeys_ptr->total_abs_ih); |
2213 |
> |
drms_setkey_float(outRec, "SAVNCPP", swKeys_ptr->totaljz); |
2214 |
> |
drms_setkey_float(outRec, "MEANPOT", swKeys_ptr->meanpot); |
2215 |
> |
drms_setkey_float(outRec, "TOTPOT", swKeys_ptr->totpot); |
2216 |
> |
drms_setkey_float(outRec, "MEANSHR", swKeys_ptr->meanshear_angle); |
2217 |
> |
drms_setkey_float(outRec, "SHRGT45", swKeys_ptr->area_w_shear_gt_45); |
2218 |
|
drms_setkey_float(outRec, "CMASK", swKeys_ptr->count_mask); |
2219 |
|
drms_setkey_float(outRec, "ERRBT", swKeys_ptr->mean_derivative_btotal_err); |
2220 |
|
drms_setkey_float(outRec, "ERRVF", swKeys_ptr->mean_vf_err); |
2232 |
|
drms_setkey_float(outRec, "ERRTPOT", swKeys_ptr->totpot_err); |
2233 |
|
drms_setkey_float(outRec, "ERRMSHA", swKeys_ptr->meanshear_angle_err); |
2234 |
|
drms_setkey_float(outRec, "R_VALUE", swKeys_ptr->Rparam); |
2235 |
+ |
drms_setkey_float(outRec, "TOTFX", swKeys_ptr->totfx); |
2236 |
+ |
drms_setkey_float(outRec, "TOTFY", swKeys_ptr->totfy); |
2237 |
+ |
drms_setkey_float(outRec, "TOTFZ", swKeys_ptr->totfz); |
2238 |
+ |
drms_setkey_float(outRec, "TOTBSQ", swKeys_ptr->totbsq); |
2239 |
+ |
drms_setkey_float(outRec, "EPSX", swKeys_ptr->epsx); |
2240 |
+ |
drms_setkey_float(outRec, "EPSY", swKeys_ptr->epsy); |
2241 |
+ |
drms_setkey_float(outRec, "EPSZ", swKeys_ptr->epsz); |
2242 |
|
}; |
2243 |
|
|
2244 |
|
/* |
2323 |
|
|
2324 |
|
|
2325 |
|
} |
2326 |
+ |
|
2327 |
+ |
// Mar 19 XS |
2328 |
+ |
if (fullDisk) { |
2329 |
+ |
drms_setkey_int(outRec, "AMBPATCH", 0); |
2330 |
+ |
drms_setkey_int(outRec, "AMBWEAK", 2); |
2331 |
+ |
} else { |
2332 |
+ |
drms_setkey_int(outRec, "AMBPATCH", 1); |
2333 |
+ |
} |
2334 |
|
|
2335 |
|
TIME val, trec, tnow, UNIX_epoch = -220924792.000; /* 1970.01.01_00:00:00_UTC */ |
2336 |
|
tnow = (double)time(NULL); |
2367 |
|
|
2368 |
|
} |
2369 |
|
|
2370 |
+ |
|
2371 |
|
/* ################## Wrapper for Jesper's rebin code ################## */ |
2372 |
|
|
2373 |
|
void frebin (float *image_in, float *image_out, int nx, int ny, int nbin, int gauss) |