ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/sharp/apps/sharp.c
(Generate patch)

Comparing proj/sharp/apps/sharp.c (file contents):
Revision 1.13 by xudong, Thu May 9 19:40:54 2013 UTC vs.
Revision 1.14 by mbobra, Tue May 21 17:06:32 2013 UTC

# Line 22 | Line 22
22   *              v0.2    Sep 04 2012
23   *              v0.3    Dec 18 2012    
24   *              v0.4    Jan 02 2013
25 *              v0.5    Jam 23 2012
25   *
26   *      Notes:
27   *              v0.0
# Line 40 | Line 39
39   *              Fixed memory leakage of 0.15G per rec; denoted with "Dec 18"
40   *              v0.4
41   *              Took out convert_inplace(). Was causing all the images to be int
42 < *              v0.5
44 < *              Corrected ephemeris keywords, added argument mInfo for setKeys()
42 >
43   *
44   *      Example:
45   *      sharp "mharp=hmi.Mharp_720s[1404][2012.02.20_10:00]" \
# Line 73 | Line 71
71   #include "errorprop.c"
72   #include "sw_functions.c"
73  
74 + //#include <mkl.h> // Comment out mkl.h, which can only run on solar3
75   #include <mkl_blas.h>
76   #include <mkl_service.h>
77   #include <mkl_lapack.h>
# Line 123 | Line 122
122   // Space weather keywords
123   struct swIndex {
124          float mean_vf;
125 +        float count_mask;
126          float absFlux;
127          float mean_hf;
128          float mean_gamma;
# Line 142 | Line 142 | struct swIndex {
142          float meanshear_angle;
143          float area_w_shear_gt_45h;
144          float meanshear_angleh;
145 < };
145 >        float mean_derivative_btotal_err;
146 >        float mean_vf_err;
147 >        float mean_gamma_err;
148 >        float mean_derivative_bh_err;
149 >        float mean_derivative_bz_err;
150 >        float mean_jz_err;
151 >        float us_i_err;
152 >        float mean_alpha_err;
153 >        float mean_ih_err;
154 >        float total_us_ih_err;
155 >        float total_abs_ih_err;
156 >        float totaljz_err;
157 >        float meanpot_err;
158 >        float totpot_err;
159 >        float meanshear_angle_err;
160 > };                                                                                                                                              
161  
162   // Mapping method
163   enum projection {
# Line 158 | Line 173 | enum projection {
173          lambert
174   };
175  
176 < // WSC code
162 < char *wcsCode[] = {"CAR", "CAS", "MER", "CEA", "GLS", "TAN", "ARC", "STG",
163 <        "SIN", "ZEA"};
164 <
165 < // Ephemeris
176 > // Ephemeris information
177   struct ephemeris {
178          double disk_lonc, disk_latc;
179          double disk_xc, disk_yc;
# Line 196 | Line 207 | int getInputRS_aux(DRMS_RecordSet_t **in
207   /* Find record from record set with given T_rec */
208   int getInputRec_aux(DRMS_Record_t **inRec_ptr, DRMS_RecordSet_t *inRS, TIME trec);
209  
199 // ===================
200
210   /* Create CEA record */
211   int createCeaRecord(DRMS_Record_t *mharpRec, DRMS_Record_t *bharpRec,
212                                          DRMS_Record_t *dopRec, DRMS_Record_t *contRec,
# Line 260 | Line 269 | void computeSWIndex(struct swIndex *swKe
269   void setSWIndex(DRMS_Record_t *outRec, struct swIndex *swKeys_ptr);
270  
271   /* Set all keywords, no error checking for now */
272 < void setKeys(DRMS_Record_t *outRec, DRMS_Record_t *inRec, struct mapInfo *mInfo);
272 > void setKeys(DRMS_Record_t *outRec, DRMS_Record_t *inRec);
273  
274   // ===================
275  
# Line 304 | Line 313 | char *CEASegs[] = {"magnetogram", "bitma
313          BR_SEG_CEA, BT_SEG_CEA, BP_SEG_CEA, BR_ERR_SEG_CEA, BT_ERR_SEG_CEA, BP_ERR_SEG_CEA};
314   /* ========================================================================================================== */
315  
307
308
316   char *module_name = "sharp";
317   char *version_id = "2012 Dec 18";  /* Version number */
318 + int seed;
319  
320   ModuleArgs_t module_args[] =
321   {
# Line 317 | Line 325 | ModuleArgs_t module_args[] =
325          {ARG_STRING, "cont", kNotSpecified, "Input Continuum series."},
326          {ARG_STRING, "sharp_cea", kNotSpecified, "Output Sharp CEA series."},
327          {ARG_STRING, "sharp_cut", kNotSpecified, "Output Sharp cutout series."},
328 +        {ARG_INT,    "seed", "987654", "Seed for the random number generator."},
329          {ARG_END}
330   };
331  
332   int DoIt(void)                    
333   {
334 <        
334 >        int errbufstat=setvbuf(stderr, NULL, _IONBF, BUFSIZ);
335 >        int outbufstat=setvbuf(stdout, NULL, _IONBF, BUFSIZ);
336 >
337          int status = DRMS_SUCCESS;
338          int nrecs, irec;
339          
# Line 341 | Line 352 | int DoIt(void)
352          contQuery = (char *) params_get_str(&cmdparams, "cont");
353          sharpCeaQuery = (char *) params_get_str(&cmdparams, "sharp_cea");
354          sharpCutQuery = (char *) params_get_str(&cmdparams, "sharp_cut");
355 +        sharpCutQuery = (char *) params_get_str(&cmdparams, "sharp_cut");
356 +
357 +        seed = params_get_int(&cmdparams, "seed");
358          
359          /* Get input data, check everything */
360          
# Line 617 | Line 631 | int createCeaRecord(DRMS_Record_t *mharp
631                  return 1;
632          }
633          printf("Magnetogram mapping done.\n");
620        
634          if (mapScaler(sharpRec, dopRec, mharpRec, &mInfo, "Dopplergram")) {
635                  SHOW("CEA: mapping dopplergram error\n");
636                  return 1;
# Line 662 | Line 675 | int createCeaRecord(DRMS_Record_t *mharp
675          DRMS_Link_t *bHarpLink = hcon_lookup_lower(&sharpRec->links, "BHARP");
676          if (bHarpLink) drms_link_set("BHARP", sharpRec, bharpRec);
677          
678 <        setKeys(sharpRec, bharpRec, &mInfo);            // Set all other keywords
678 >        setKeys(sharpRec, bharpRec);            // Set all other keywords
679          drms_copykey(sharpRec, mharpRec, "QUALITY");            // copied from los records
680          
681          // Space weather
# Line 1548 | Line 1561 | int createCutRecord(DRMS_Record_t *mharp
1561          if (bHarpLink) drms_link_set("BHARP", sharpRec, bharpRec);
1562          
1563          setSWIndex(sharpRec, swKeys_ptr);       // Set space weather indices
1564 <        setKeys(sharpRec, bharpRec, NULL);              // Set all other keywords, NULL specifies cutout
1564 >        setKeys(sharpRec, bharpRec);            // Set all other keywords
1565          
1566          // Stats
1567          
# Line 1663 | Line 1676 | void computeSWIndex(struct swIndex *swKe
1676          int nx = mInfo->ncol, ny = mInfo->nrow;
1677          int nxny = nx * ny;
1678          int dims[2] = {nx, ny};
1679 +        
1680          // Get bx, by, bz, mask
1681          
1682          // Use HARP (Turmon) bitmap as a threshold on spaceweather quantities
# Line 1687 | Line 1701 | void computeSWIndex(struct swIndex *swKe
1701          DRMS_Segment_t *bzSeg = drms_segment_lookup(inRec, BR_SEG_CEA);
1702          DRMS_Array_t *bzArray = drms_segment_read(bzSeg, DRMS_TYPE_FLOAT, &status);
1703          float *bz = (float *) bzArray->data;            // bz
1704 +
1705 +        DRMS_Segment_t *bz_errSeg = drms_segment_lookup(inRec, BR_ERR_SEG_CEA);
1706 +        DRMS_Array_t *bz_errArray = drms_segment_read(bz_errSeg, DRMS_TYPE_FLOAT, &status);
1707 +        float *bz_err = (float *) bz_errArray->data;            // bz_err
1708 +
1709 +        DRMS_Segment_t *by_errSeg = drms_segment_lookup(inRec, BT_ERR_SEG_CEA);
1710 +        DRMS_Array_t *by_errArray = drms_segment_read(by_errSeg, DRMS_TYPE_FLOAT, &status);
1711 +        float *by_err = (float *) by_errArray->data;            // by_err
1712 +        //for (int i = 0; i < nxny; i++) by_err[i] *= -1;
1713 +
1714 +        DRMS_Segment_t *bx_errSeg = drms_segment_lookup(inRec, BP_ERR_SEG_CEA);
1715 +        DRMS_Array_t *bx_errArray = drms_segment_read(bx_errSeg, DRMS_TYPE_FLOAT, &status);
1716 +        float *bx_err = (float *) bx_errArray->data;            // bx_err
1717          
1718          // Get emphemeris
1719          
# Line 1700 | Line 1727 | void computeSWIndex(struct swIndex *swKe
1727          float crpix1      = drms_getkey_float(inRec, "CRPIX1", &status);
1728          float crpix2      = drms_getkey_float(inRec, "CRPIX2", &status);
1729          
1730 <        //float cdelt1=( (rsun_ref*cdelt1_orig*PI/180.) / (dsun_obs) )*(180./PI)*(3600.); //convert cdelt1 from degrees to arcsec (approximately)
1730 >        // Temp arrays
1731          
1732 <        printf("cdelt1=%f\n",cdelt1);
1733 <        printf("rsun_ref=%f\n",rsun_ref);
1734 <        printf("rsun_obs=%f\n",rsun_obs);
1708 <        printf("dsun_obs=%f\n",dsun_obs);
1709 <        
1710 <        // Temp arrays                
1711 <        
1712 <        float *bh = (float *) (malloc(nxny * sizeof(float)));
1713 <        float *bt = (float *) (malloc(nxny * sizeof(float)));
1714 <        float *jz = (float *) (malloc(nxny * sizeof(float)));
1732 >        float *bh      = (float *) (malloc(nxny * sizeof(float)));
1733 >        float *bt      = (float *) (malloc(nxny * sizeof(float)));
1734 >        float *jz      = (float *) (malloc(nxny * sizeof(float)));
1735          float *jz_smooth = (float *) (malloc(nxny * sizeof(float)));
1736 <        float *bpx = (float *) (malloc(nxny * sizeof(float)));
1737 <        float *bpy = (float *) (malloc(nxny * sizeof(float)));
1738 <        float *bpz = (float *) (malloc(nxny * sizeof(float)));
1739 <        float *derx = (float *) (malloc(nxny * sizeof(float)));
1740 <        float *dery = (float *) (malloc(nxny * sizeof(float)));
1736 >        float *bpx     = (float *) (malloc(nxny * sizeof(float)));
1737 >        float *bpy     = (float *) (malloc(nxny * sizeof(float)));
1738 >        float *bpz     = (float *) (malloc(nxny * sizeof(float)));
1739 >        float *derx    = (float *) (malloc(nxny * sizeof(float)));
1740 >        float *dery    = (float *) (malloc(nxny * sizeof(float)));
1741          float *derx_bt = (float *) (malloc(nxny * sizeof(float)));
1742          float *dery_bt = (float *) (malloc(nxny * sizeof(float)));
1743          float *derx_bh = (float *) (malloc(nxny * sizeof(float)));
1744          float *dery_bh = (float *) (malloc(nxny * sizeof(float)));
1745          float *derx_bz = (float *) (malloc(nxny * sizeof(float)));
1746          float *dery_bz = (float *) (malloc(nxny * sizeof(float)));
1747 +        float *bt_err  = (float *) (malloc(nxny * sizeof(float)));
1748 +        float *bh_err  = (float *) (malloc(nxny * sizeof(float)));
1749 +        float *jz_err  = (float *) (malloc(nxny * sizeof(float)));
1750 +        float *jz_err_squared = (float *) (malloc(nxny * sizeof(float)));
1751 +        float *jz_err_squared_smooth = (float *) (malloc(nxny * sizeof(float)));
1752 +        float *jz_rms_err = (float *) (malloc(nxny * sizeof(float)));
1753 +        //spaceweather quantities computed    
1754 +      
1755  
1756 <        // The Computations  
1757 <        
1758 <        if (computeAbsFlux(bz, dims, &(swKeys_ptr->absFlux), &(swKeys_ptr->mean_vf),
1731 <                                           mask, bitmask, cdelt1, rsun_ref, rsun_obs)){
1756 >        if (computeAbsFlux(bz_err, bz , dims, &(swKeys_ptr->absFlux), &(swKeys_ptr->mean_vf),  &(swKeys_ptr->mean_vf_err),
1757 >                           &(swKeys_ptr->count_mask), mask, bitmask, cdelt1, rsun_ref, rsun_obs))
1758 >        {
1759                  swKeys_ptr->absFlux = DRMS_MISSING_FLOAT;               // If fail, fill in NaN
1760                  swKeys_ptr->mean_vf = DRMS_MISSING_FLOAT;
1761 +                swKeys_ptr->mean_vf_err = DRMS_MISSING_FLOAT;
1762 +                swKeys_ptr->count_mask  = DRMS_MISSING_INT;
1763          }
1764 <        
1764 >    
1765          for (int i = 0; i < nxny; i++) bpz[i] = bz[i];
1766          greenpot(bpx, bpy, bpz, nx, ny);                      
1767          
1768 <        computeBh(bx, by, bz, bh, dims, &(swKeys_ptr->mean_hf), mask, bitmask);
1769 <        
1770 <        if (computeGamma(bx, by, bz, bh, dims, &(swKeys_ptr->mean_gamma), mask, bitmask))
1771 <                swKeys_ptr->mean_gamma = DRMS_MISSING_FLOAT;
1768 >        computeBh(bx_err, by_err, bh_err, bx, by, bz, bh, dims, &(swKeys_ptr->mean_hf), mask, bitmask);
1769 >
1770 >        if (computeGamma(bz_err, bh_err, bx, by, bz, bh, dims, &(swKeys_ptr->mean_gamma), &(swKeys_ptr->mean_gamma_err),mask, bitmask))
1771 >        {      
1772 >                swKeys_ptr->mean_gamma     =  DRMS_MISSING_FLOAT;
1773 >                swKeys_ptr->mean_gamma_err =  DRMS_MISSING_FLOAT;
1774 >        }
1775          
1776 <        computeB_total(bx, by, bz, bt, dims, mask, bitmask);
1776 >        computeB_total(bx_err, by_err, bz_err, bt_err, bx, by, bz, bt, dims, mask, bitmask);
1777          
1778 <        if (computeBtotalderivative(bt, dims, &(swKeys_ptr->mean_derivative_btotal), mask, bitmask, derx_bt, dery_bt))
1778 >        if (computeBtotalderivative(bt, dims, &(swKeys_ptr->mean_derivative_btotal), mask, bitmask, derx_bt, dery_bt, bt_err, &(swKeys_ptr->mean_derivative_btotal_err)))
1779 >        {
1780                  swKeys_ptr->mean_derivative_btotal = DRMS_MISSING_FLOAT;
1781 +                swKeys_ptr->mean_derivative_btotal_err = DRMS_MISSING_FLOAT;
1782 +        }
1783          
1784 <        if (computeBhderivative(bh, dims, &(swKeys_ptr->mean_derivative_bh), mask, bitmask, derx_bh, dery_bh))
1784 >        if (computeBhderivative(bh, bh_err, dims, &(swKeys_ptr->mean_derivative_bh), &(swKeys_ptr->mean_derivative_bh_err), mask, bitmask, derx_bh, dery_bh))
1785 >        {
1786                  swKeys_ptr->mean_derivative_bh = DRMS_MISSING_FLOAT;
1787 <        
1788 <        if (computeBzderivative(bz, dims, &(swKeys_ptr->mean_derivative_bz), mask, bitmask, derx_bz, dery_bz))
1787 >                swKeys_ptr->mean_derivative_bh_err = DRMS_MISSING_FLOAT;
1788 >        }
1789 >
1790 >        if (computeBzderivative(bz, bz_err, dims, &(swKeys_ptr->mean_derivative_bz), &(swKeys_ptr->mean_derivative_bz_err), mask, bitmask, derx_bz, dery_bz))
1791 >        {
1792                  swKeys_ptr->mean_derivative_bz = DRMS_MISSING_FLOAT; // If fail, fill in NaN
1793 +                swKeys_ptr->mean_derivative_bz_err = DRMS_MISSING_FLOAT;
1794 +        }
1795          
1796 <        computeJz(bx, by, dims, jz, mask, bitmask, cdelt1, rsun_ref, rsun_obs, derx, dery);
1796 >        computeJz(bx_err, by_err, bx, by, dims, jz, jz_err, jz_err_squared, mask, bitmask, cdelt1, rsun_ref, rsun_obs,
1797 >                  derx, dery);
1798  
1799 <        struct fresize_struct convolution_array;
1800 <        init_fresize_gaussian(&convolution_array, 4.0f, 12, 1);
1801 <        fresize(&convolution_array, jz, jz_smooth, nx, ny, nx, nx, ny, nx, 0, 0, 0.0f);
1802 <        
1761 <        if(computeJzsmooth(bx, by, dims, jz_smooth, &(swKeys_ptr->mean_jz), &(swKeys_ptr->us_i), mask, bitmask,
1762 <                                 cdelt1, rsun_ref, rsun_obs, derx, dery))
1799 >
1800 >        if(computeJzsmooth(bx, by, dims, jz, jz_smooth, jz_err, jz_rms_err, jz_err_squared_smooth, &(swKeys_ptr->mean_jz),
1801 >                           &(swKeys_ptr->mean_jz_err), &(swKeys_ptr->us_i), &(swKeys_ptr->us_i_err), mask, bitmask, cdelt1,
1802 >                           rsun_ref, rsun_obs, derx, dery))
1803          {
1804 <                swKeys_ptr->mean_jz = DRMS_MISSING_FLOAT;
1805 <                swKeys_ptr->us_i = DRMS_MISSING_FLOAT;
1804 >                swKeys_ptr->mean_jz            = DRMS_MISSING_FLOAT;
1805 >                swKeys_ptr->us_i               = DRMS_MISSING_FLOAT;
1806 >                swKeys_ptr->mean_jz_err        = DRMS_MISSING_FLOAT;
1807 >                swKeys_ptr->us_i_err           = DRMS_MISSING_FLOAT;
1808          }
1767        printf("swKeys_ptr->mean_jz=%f\n",swKeys_ptr->mean_jz);
1809  
1810 <        
1811 <        if (computeAlpha(bz, dims, jz_smooth, &(swKeys_ptr->mean_alpha), mask, bitmask, cdelt1, rsun_ref, rsun_obs))
1812 <                swKeys_ptr->mean_alpha = DRMS_MISSING_FLOAT;
1813 <        
1814 <        if (computeHelicity(bz, dims, jz_smooth, &(swKeys_ptr->mean_ih),
1815 <                                                &(swKeys_ptr->total_us_ih), &(swKeys_ptr->total_abs_ih),
1816 <                                                mask, bitmask, cdelt1, rsun_ref, rsun_obs)) {  
1817 <                swKeys_ptr->mean_ih = DRMS_MISSING_FLOAT;
1818 <                swKeys_ptr->total_us_ih = DRMS_MISSING_FLOAT;
1819 <                swKeys_ptr->total_abs_ih = DRMS_MISSING_FLOAT;
1810 >        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))
1811 >        {
1812 >                swKeys_ptr->mean_alpha         = DRMS_MISSING_FLOAT;
1813 >                swKeys_ptr->mean_alpha_err     = DRMS_MISSING_FLOAT;
1814 >        }
1815 >        
1816 >        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),
1817 >                            &(swKeys_ptr->total_us_ih_err), &(swKeys_ptr->total_abs_ih_err), mask, bitmask, cdelt1, rsun_ref, rsun_obs))
1818 >        {  
1819 >                swKeys_ptr->mean_ih            = DRMS_MISSING_FLOAT;
1820 >                swKeys_ptr->total_us_ih        = DRMS_MISSING_FLOAT;
1821 >                swKeys_ptr->total_abs_ih       = DRMS_MISSING_FLOAT;
1822 >                swKeys_ptr->mean_ih_err        = DRMS_MISSING_FLOAT;
1823 >                swKeys_ptr->total_us_ih_err    = DRMS_MISSING_FLOAT;
1824 >                swKeys_ptr->total_abs_ih_err   = DRMS_MISSING_FLOAT;
1825          }
1826 <        
1827 <        if (computeSumAbsPerPolarity(bz, jz_smooth, dims, &(swKeys_ptr->totaljz),
1826 >
1827 >        if (computeSumAbsPerPolarity(jz_err, bz_err, bz, jz, dims, &(swKeys_ptr->totaljz), &(swKeys_ptr->totaljz_err),
1828                                                                   mask, bitmask, cdelt1, rsun_ref, rsun_obs))
1829 <                swKeys_ptr->totaljz = DRMS_MISSING_FLOAT;
1830 <        
1829 >        {
1830 >                swKeys_ptr->totaljz            = DRMS_MISSING_FLOAT;
1831 >                swKeys_ptr->totaljz_err        = DRMS_MISSING_FLOAT;
1832 >        }
1833          
1834 <        if (computeFreeEnergy(bx, by, bpx, bpy, dims,
1835 <                                                  &(swKeys_ptr->meanpot), &(swKeys_ptr->totpot),
1836 <                                                  mask, bitmask, cdelt1, rsun_ref, rsun_obs)) {
1837 <                swKeys_ptr->meanpot = DRMS_MISSING_FLOAT; // If fail, fill in NaN
1838 <                swKeys_ptr->totpot = DRMS_MISSING_FLOAT;
1834 >        if (computeFreeEnergy(bx_err, by_err, bx, by, bpx, bpy, dims,
1835 >                                                  &(swKeys_ptr->meanpot), &(swKeys_ptr->meanpot_err), &(swKeys_ptr->totpot), &(swKeys_ptr->totpot_err),
1836 >                                                  mask, bitmask, cdelt1, rsun_ref, rsun_obs))
1837 >        {
1838 >                swKeys_ptr->meanpot            = DRMS_MISSING_FLOAT; // If fail, fill in NaN
1839 >                swKeys_ptr->totpot             = DRMS_MISSING_FLOAT;
1840 >                swKeys_ptr->meanpot_err        = DRMS_MISSING_FLOAT;
1841 >                swKeys_ptr->totpot_err         = DRMS_MISSING_FLOAT;
1842          }
1843                        
1844 <        if (computeShearAngle(bx, by, bz, bpx, bpy, bpz, dims,
1845 <                                                  &(swKeys_ptr->meanshear_angle), &(swKeys_ptr->area_w_shear_gt_45),
1795 <                                                  &(swKeys_ptr->meanshear_angleh), &(swKeys_ptr->area_w_shear_gt_45h),
1844 >        if (computeShearAngle(bx_err, by_err, bh_err, bx, by, bz, bpx, bpy, bpz, dims,
1845 >                                                  &(swKeys_ptr->meanshear_angle), &(swKeys_ptr->meanshear_angle_err), &(swKeys_ptr->area_w_shear_gt_45),  
1846                                                    mask, bitmask)) {
1847 <                swKeys_ptr->meanshear_angle = DRMS_MISSING_FLOAT; // If fail, fill in NaN
1847 >                swKeys_ptr->meanshear_angle    = DRMS_MISSING_FLOAT; // If fail, fill in NaN
1848                  swKeys_ptr->area_w_shear_gt_45 = DRMS_MISSING_FLOAT;
1849 <                swKeys_ptr->meanshear_angleh = DRMS_MISSING_FLOAT; // If fail, fill in NaN
1800 <                swKeys_ptr->area_w_shear_gt_45h = DRMS_MISSING_FLOAT;
1849 >                swKeys_ptr->meanshear_angle_err= DRMS_MISSING_FLOAT;
1850          }
1851          
1852 <        // Clean up
1852 >        // Clean up the arrays
1853          
1854          drms_free_array(bitmaskArray);          // Dec 18 2012 Xudong
1855          drms_free_array(maskArray);
# Line 1814 | Line 1863 | void computeSWIndex(struct swIndex *swKe
1863          free(derx_bt); free(dery_bt);  
1864          free(derx_bz); free(dery_bz);  
1865          free(derx_bh); free(dery_bh);
1866 <        
1867 <        free_fresize(&convolution_array);
1866 >        free(bt_err); free(bh_err);  free(jz_err);
1867 >        free(jz_err_squared); free(jz_rms_err);
1868 >        free(jz_err_squared_smooth);
1869   }
1870  
1821
1871   /*
1872   * Set space weather indices, no error checking for now
1873   *
# Line 1826 | Line 1875 | void computeSWIndex(struct swIndex *swKe
1875  
1876   void setSWIndex(DRMS_Record_t *outRec, struct swIndex *swKeys_ptr)
1877   {
1878 <        drms_setkey_float(outRec, "USFLUX", swKeys_ptr->mean_vf);
1878 >        drms_setkey_float(outRec, "USFLUX",  swKeys_ptr->mean_vf);
1879          drms_setkey_float(outRec, "MEANGAM", swKeys_ptr->mean_gamma);
1880          drms_setkey_float(outRec, "MEANGBT", swKeys_ptr->mean_derivative_btotal);
1881          drms_setkey_float(outRec, "MEANGBH", swKeys_ptr->mean_derivative_bh);
# Line 1839 | Line 1888 | void setSWIndex(DRMS_Record_t *outRec, s
1888          drms_setkey_float(outRec, "ABSNJZH", swKeys_ptr->total_abs_ih);
1889          drms_setkey_float(outRec, "SAVNCPP", swKeys_ptr->totaljz);
1890          drms_setkey_float(outRec, "MEANPOT", swKeys_ptr->meanpot);
1891 <        drms_setkey_float(outRec, "TOTPOT", swKeys_ptr->totpot);
1891 >        drms_setkey_float(outRec, "TOTPOT",  swKeys_ptr->totpot);
1892          drms_setkey_float(outRec, "MEANSHR", swKeys_ptr->meanshear_angle);
1893          drms_setkey_float(outRec, "SHRGT45", swKeys_ptr->area_w_shear_gt_45);
1894 +        drms_setkey_float(outRec, "CMASK",   swKeys_ptr->count_mask);
1895 +        drms_setkey_float(outRec, "ERRBT",   swKeys_ptr->mean_derivative_btotal_err);
1896 +        drms_setkey_float(outRec, "ERRVF",   swKeys_ptr->mean_vf_err);
1897 +        drms_setkey_float(outRec, "ERRGAM",  swKeys_ptr->mean_gamma_err);
1898 +        drms_setkey_float(outRec, "ERRBH",   swKeys_ptr->mean_derivative_bh_err);
1899 +        drms_setkey_float(outRec, "ERRBZ",   swKeys_ptr->mean_derivative_bz_err);
1900 +        drms_setkey_float(outRec, "ERRJZ",   swKeys_ptr->mean_jz_err);
1901 +        drms_setkey_float(outRec, "ERRUSI",  swKeys_ptr->us_i_err);
1902 +        drms_setkey_float(outRec, "ERRALP",  swKeys_ptr->mean_alpha_err);
1903 +        drms_setkey_float(outRec, "ERRMIH",  swKeys_ptr->mean_ih_err);
1904 +        drms_setkey_float(outRec, "ERRTUI",  swKeys_ptr->total_us_ih_err);
1905 +        drms_setkey_float(outRec, "ERRTAI",  swKeys_ptr->total_abs_ih_err);
1906 +        drms_setkey_float(outRec, "ERRJHT",  swKeys_ptr->totaljz_err);
1907 +        drms_setkey_float(outRec, "ERRMPOT", swKeys_ptr->meanpot_err);
1908 +        drms_setkey_float(outRec, "ERRTPOT", swKeys_ptr->totpot_err);
1909 +        drms_setkey_float(outRec, "ERRMSHA", swKeys_ptr->meanshear_angle_err);
1910   };
1911  
1847
1912   /*
1913   * Set all keywords, no error checking for now
1914   *
1915   */
1916  
1917 < void setKeys(DRMS_Record_t *outRec, DRMS_Record_t *inRec, struct mapInfo *mInfo)
1917 > void setKeys(DRMS_Record_t *outRec, DRMS_Record_t *inRec)
1918   {
1919          copy_me_keys(inRec, outRec);
1920          copy_patch_keys(inRec, outRec);
1921          copy_geo_keys(inRec, outRec);
1922          copy_ambig_keys(inRec, outRec);
1923          
1860        int status = 0;
1861        
1862        // Change a few geometry keywords for CEA records
1863        if (mInfo != NULL) {
1864        
1865          drms_setkey_float(outRec, "CRPIX1", mInfo->ncol/2. + 0.5);
1866                drms_setkey_float(outRec, "CRPIX2", mInfo->nrow/2. + 0.5);
1867                
1868                drms_setkey_float(outRec, "CRVAL1", mInfo->xc);
1869                drms_setkey_float(outRec, "CRVAL2", mInfo->yc);
1870                drms_setkey_float(outRec, "CDELT1", mInfo->xscale);
1871                drms_setkey_float(outRec, "CDELT2", mInfo->yscale);
1872                drms_setkey_string(outRec, "CUNIT1", "degree");
1873                drms_setkey_string(outRec, "CUNIT2", "degree");
1874                
1875                char key[64];
1876                snprintf (key, 64, "CRLN-%s", wcsCode[(int) mInfo->proj]);
1877                drms_setkey_string(outRec, "CTYPE1", key);
1878                snprintf (key, 64, "CRLT-%s", wcsCode[(int) mInfo->proj]);
1879                drms_setkey_string(outRec, "CTYPE2", key);
1880                drms_setkey_float(outRec, "CROTA2", 0.0);
1881                
1882        } else {
1883        
1884          float disk_xc = drms_getkey_float(inRec, "IMCRPIX1", &status);
1885          float disk_yc = drms_getkey_float(inRec, "IMCRPIX2", &status);
1886          float x_ll = drms_getkey_float(inRec, "CRPIX1", &status);
1887          float y_ll = drms_getkey_float(inRec, "CRPIX2", &status);
1888          // Defined as disk center's pixel address wrt lower-left of cutout
1889          drms_setkey_float(outRec, "CRPIX1", disk_xc - x_ll + 1.);
1890                drms_setkey_float(outRec, "CRPIX2", disk_yc - y_ll + 1.);
1891                // Always 0.
1892                drms_setkey_float(outRec, "CRVAL1", 0);
1893                drms_setkey_float(outRec, "CRVAL2", 0);
1894                
1895        }
1896        
1924          char timebuf[1024];
1925          float UNIX_epoch = -220924792.000; /* 1970.01.01_00:00:00_UTC */
1926          double val;
1927 <        status = 0;
1928 <                
1927 >        int status = DRMS_SUCCESS;
1928 >        
1929          val = drms_getkey_double(inRec, "DATE",&status);
1930          drms_setkey_double(outRec, "DATE_B", val);
1931          sprint_time(timebuf, (double)time(NULL) + UNIX_epoch, "ISO", 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines