(file) Return to sharp.c CVS log (file) (dir) Up to [Development] / JSOC / proj / sharp / apps

Diff for /JSOC/proj/sharp/apps/sharp.c between version 1.8 and 1.10

version 1.8, 2013/01/07 22:03:47 version 1.10, 2013/01/23 21:48:26
Line 22 
Line 22 
  *              v0.2    Sep 04 2012  *              v0.2    Sep 04 2012
  *              v0.3    Dec 18 2012  *              v0.3    Dec 18 2012
  *              v0.4    Jan 02 2013  *              v0.4    Jan 02 2013
    *              v0.5    Jam 23 2012
  *  *
  *      Notes:  *      Notes:
  *              v0.0  *              v0.0
Line 39 
Line 40 
  *              Fixed memory leakage of 0.15G per rec; denoted with "Dec 18"  *              Fixed memory leakage of 0.15G per rec; denoted with "Dec 18"
  *              v0.4  *              v0.4
  *              Took out convert_inplace(). Was causing all the images to be int  *              Took out convert_inplace(). Was causing all the images to be int
    *              v0.5
    *              Corrected ephemeris keywords, added argument mInfo for setKeys()
  *  *
  *      Example:  *      Example:
  *      sharp "mharp=hmi.Mharp_720s[1404][2012.02.20_10:00]" \  *      sharp "mharp=hmi.Mharp_720s[1404][2012.02.20_10:00]" \
Line 156  enum projection {
Line 158  enum projection {
         lambert         lambert
 }; };
  
   // WSC code
   char *wcsCode[] = {"CAR", "CAS", "MER", "CEA", "GLS", "TAN", "ARC", "STG",
           "SIN", "ZEA"};
   
 // Ephemeris // Ephemeris
 struct ephemeris { struct ephemeris {
         double disk_lonc, disk_latc;         double disk_lonc, disk_latc;
Line 254  void computeSWIndex(struct swIndex *swKe
Line 260  void computeSWIndex(struct swIndex *swKe
 void setSWIndex(DRMS_Record_t *outRec, struct swIndex *swKeys_ptr); void setSWIndex(DRMS_Record_t *outRec, struct swIndex *swKeys_ptr);
  
 /* Set all keywords, no error checking for now */ /* Set all keywords, no error checking for now */
 void setKeys(DRMS_Record_t *outRec, DRMS_Record_t *inRec);  void setKeys(DRMS_Record_t *outRec, DRMS_Record_t *inRec, struct mapInfo *mInfo);
  
 // =================== // ===================
  
Line 656  int createCeaRecord(DRMS_Record_t *mharp
Line 662  int createCeaRecord(DRMS_Record_t *mharp
         DRMS_Link_t *bHarpLink = hcon_lookup_lower(&sharpRec->links, "BHARP");         DRMS_Link_t *bHarpLink = hcon_lookup_lower(&sharpRec->links, "BHARP");
         if (bHarpLink) drms_link_set("BHARP", sharpRec, bharpRec);         if (bHarpLink) drms_link_set("BHARP", sharpRec, bharpRec);
  
         setKeys(sharpRec, bharpRec);            // Set all other keywords          setKeys(sharpRec, bharpRec, &mInfo);            // Set all other keywords
         drms_copykey(sharpRec, mharpRec, "QUALITY");            // copied from los records         drms_copykey(sharpRec, mharpRec, "QUALITY");            // copied from los records
  
         // Space weather         // Space weather
Line 1540  int createCutRecord(DRMS_Record_t *mharp
Line 1546  int createCutRecord(DRMS_Record_t *mharp
         if (bHarpLink) drms_link_set("BHARP", sharpRec, bharpRec);         if (bHarpLink) drms_link_set("BHARP", sharpRec, bharpRec);
  
         setSWIndex(sharpRec, swKeys_ptr);       // Set space weather indices         setSWIndex(sharpRec, swKeys_ptr);       // Set space weather indices
         setKeys(sharpRec, bharpRec);            // Set all other keywords          setKeys(sharpRec, bharpRec, NULL);              // Set all other keywords, NULL specifies cutout
  
         // Stats         // Stats
  
Line 1704  void computeSWIndex(struct swIndex *swKe
Line 1710  void computeSWIndex(struct swIndex *swKe
         float *bh = (float *) (malloc(nxny * sizeof(float)));         float *bh = (float *) (malloc(nxny * sizeof(float)));
         float *bt = (float *) (malloc(nxny * sizeof(float)));         float *bt = (float *) (malloc(nxny * sizeof(float)));
         float *jz = (float *) (malloc(nxny * sizeof(float)));         float *jz = (float *) (malloc(nxny * sizeof(float)));
           float *jz_smooth = (float *) (malloc(nxny * sizeof(float)));
         float *bpx = (float *) (malloc(nxny * sizeof(float)));         float *bpx = (float *) (malloc(nxny * sizeof(float)));
         float *bpy = (float *) (malloc(nxny * sizeof(float)));         float *bpy = (float *) (malloc(nxny * sizeof(float)));
         float *bpz = (float *) (malloc(nxny * sizeof(float)));         float *bpz = (float *) (malloc(nxny * sizeof(float)));
Line 1716  void computeSWIndex(struct swIndex *swKe
Line 1723  void computeSWIndex(struct swIndex *swKe
         float *derx_bz = (float *) (malloc(nxny * sizeof(float)));         float *derx_bz = (float *) (malloc(nxny * sizeof(float)));
         float *dery_bz = (float *) (malloc(nxny * sizeof(float)));         float *dery_bz = (float *) (malloc(nxny * sizeof(float)));
  
         // Compute          // The Computations
  
         if (computeAbsFlux(bz, dims, &(swKeys_ptr->absFlux), &(swKeys_ptr->mean_vf),         if (computeAbsFlux(bz, dims, &(swKeys_ptr->absFlux), &(swKeys_ptr->mean_vf),
                                            mask, bitmask, cdelt1, rsun_ref, rsun_obs)){                                            mask, bitmask, cdelt1, rsun_ref, rsun_obs)){
Line 1743  void computeSWIndex(struct swIndex *swKe
Line 1750  void computeSWIndex(struct swIndex *swKe
         if (computeBzderivative(bz, dims, &(swKeys_ptr->mean_derivative_bz), mask, bitmask, derx_bz, dery_bz))         if (computeBzderivative(bz, dims, &(swKeys_ptr->mean_derivative_bz), mask, bitmask, derx_bz, dery_bz))
                 swKeys_ptr->mean_derivative_bz = DRMS_MISSING_FLOAT; // If fail, fill in NaN                 swKeys_ptr->mean_derivative_bz = DRMS_MISSING_FLOAT; // If fail, fill in NaN
  
           computeJz(bx, by, dims, jz, mask, bitmask, cdelt1, rsun_ref, rsun_obs, derx, dery);
  
           struct fresize_struct convolution_array;
           init_fresize_gaussian(&convolution_array, 4.0f, 12, 1);
           fresize(&convolution_array, jz, jz_smooth, nx, ny, nx, nx, ny, nx, 0, 0, 0.0f);
  
         if(computeJz(bx, by, dims, jz, &(swKeys_ptr->mean_jz), &(swKeys_ptr->us_i), mask, bitmask,          if(computeJzsmooth(bx, by, dims, jz_smooth, &(swKeys_ptr->mean_jz), &(swKeys_ptr->us_i), mask, bitmask,
                                  cdelt1, rsun_ref, rsun_obs, derx, dery)) {                                   cdelt1, rsun_ref, rsun_obs, derx, dery))
           {
                 swKeys_ptr->mean_jz = DRMS_MISSING_FLOAT;                 swKeys_ptr->mean_jz = DRMS_MISSING_FLOAT;
                 swKeys_ptr->us_i = DRMS_MISSING_FLOAT;                 swKeys_ptr->us_i = DRMS_MISSING_FLOAT;
         }         }
   
         printf("swKeys_ptr->mean_jz=%f\n",swKeys_ptr->mean_jz);         printf("swKeys_ptr->mean_jz=%f\n",swKeys_ptr->mean_jz);
  
         if (computeAlpha(bz, dims, jz, &(swKeys_ptr->mean_alpha), mask, bitmask, cdelt1, rsun_ref, rsun_obs))  
           if (computeAlpha(bz, dims, jz_smooth, &(swKeys_ptr->mean_alpha), mask, bitmask, cdelt1, rsun_ref, rsun_obs))
                 swKeys_ptr->mean_alpha = DRMS_MISSING_FLOAT;                 swKeys_ptr->mean_alpha = DRMS_MISSING_FLOAT;
  
         if (computeHelicity(bz, dims, jz, &(swKeys_ptr->mean_ih),          if (computeHelicity(bz, dims, jz_smooth, &(swKeys_ptr->mean_ih),
                                                 &(swKeys_ptr->total_us_ih), &(swKeys_ptr->total_abs_ih),                                                 &(swKeys_ptr->total_us_ih), &(swKeys_ptr->total_abs_ih),
                                                 mask, bitmask, cdelt1, rsun_ref, rsun_obs)) {                                                 mask, bitmask, cdelt1, rsun_ref, rsun_obs)) {
                 swKeys_ptr->mean_ih = DRMS_MISSING_FLOAT;                 swKeys_ptr->mean_ih = DRMS_MISSING_FLOAT;
Line 1764  void computeSWIndex(struct swIndex *swKe
Line 1776  void computeSWIndex(struct swIndex *swKe
                 swKeys_ptr->total_abs_ih = DRMS_MISSING_FLOAT;                 swKeys_ptr->total_abs_ih = DRMS_MISSING_FLOAT;
         }         }
  
         if (computeSumAbsPerPolarity(bz, jz, dims, &(swKeys_ptr->totaljz),          if (computeSumAbsPerPolarity(bz, jz_smooth, dims, &(swKeys_ptr->totaljz),
                                                                  mask, bitmask, cdelt1, rsun_ref, rsun_obs))                                                                  mask, bitmask, cdelt1, rsun_ref, rsun_obs))
                 swKeys_ptr->totaljz = DRMS_MISSING_FLOAT;                 swKeys_ptr->totaljz = DRMS_MISSING_FLOAT;
  
Line 1794  void computeSWIndex(struct swIndex *swKe
Line 1806  void computeSWIndex(struct swIndex *swKe
         drms_free_array(byArray);         drms_free_array(byArray);
         drms_free_array(bzArray);         drms_free_array(bzArray);
  
         free(bh); free(bt); free(jz);          free(bh); free(bt); free(jz); free(jz_smooth);
         free(bpx); free(bpy); free(bpz);         free(bpx); free(bpy); free(bpz);
         free(derx); free(dery);         free(derx); free(dery);
         free(derx_bt); free(dery_bt);         free(derx_bt); free(dery_bt);
         free(derx_bz); free(dery_bz);         free(derx_bz); free(dery_bz);
         free(derx_bh); free(dery_bh);         free(derx_bh); free(dery_bh);
  
           free_fresize(&convolution_array);
 } }
  
  
Line 1835  void setSWIndex(DRMS_Record_t *outRec, s
Line 1848  void setSWIndex(DRMS_Record_t *outRec, s
  *  *
  */  */
  
 void setKeys(DRMS_Record_t *outRec, DRMS_Record_t *inRec)  void setKeys(DRMS_Record_t *outRec, DRMS_Record_t *inRec, struct mapInfo *mInfo)
 { {
         copy_me_keys(inRec, outRec);         copy_me_keys(inRec, outRec);
         copy_patch_keys(inRec, outRec);         copy_patch_keys(inRec, outRec);
         copy_geo_keys(inRec, outRec);         copy_geo_keys(inRec, outRec);
         copy_ambig_keys(inRec, outRec);         copy_ambig_keys(inRec, outRec);
  
           int status = 0;
   
           // Change a few geometry keywords for CEA records
           if (mInfo != NULL) {
   
             drms_setkey_float(outRec, "CRPIX1", mInfo->ncol/2. + 0.5);
                   drms_setkey_float(outRec, "CRPIX2", mInfo->nrow/2. + 0.5);
   
                   drms_setkey_float(outRec, "CRVAL1", mInfo->xc);
                   drms_setkey_float(outRec, "CRVAL2", mInfo->yc);
                   drms_setkey_float(outRec, "CDELT1", mInfo->xscale);
                   drms_setkey_float(outRec, "CDELT2", mInfo->yscale);
                   drms_setkey_string(outRec, "CUNIT1", "degree");
                   drms_setkey_string(outRec, "CUNIT2", "degree");
   
                   char key[64];
                   snprintf (key, 64, "CRLN-%s", wcsCode[(int) mInfo->proj]);
                   drms_setkey_string(outRec, "CTYPE1", key);
                   snprintf (key, 64, "CRLT-%s", wcsCode[(int) mInfo->proj]);
                   drms_setkey_string(outRec, "CTYPE2", key);
                   drms_setkey_float(outRec, "CROTA2", 0.0);
   
           } else {
   
             float disk_xc = drms_getkey_float(inRec, "IMCRPIX1", &status);
             float disk_yc = drms_getkey_float(inRec, "IMCRPIX2", &status);
             float x_ll = drms_getkey_float(inRec, "CRPIX1", &status);
             float y_ll = drms_getkey_float(inRec, "CRPIX2", &status);
             // Defined as disk center's pixel address wrt lower-left of cutout
             drms_setkey_float(outRec, "CRPIX1", disk_xc - x_ll + 1.);
                   drms_setkey_float(outRec, "CRPIX2", disk_yc - y_ll + 1.);
                   // Always 0.
                   drms_setkey_float(outRec, "CRVAL1", 0);
                   drms_setkey_float(outRec, "CRVAL2", 0);
   
           }
   
         char timebuf[1024];         char timebuf[1024];
         float UNIX_epoch = -220924792.000; /* 1970.01.01_00:00:00_UTC */         float UNIX_epoch = -220924792.000; /* 1970.01.01_00:00:00_UTC */
         double val;         double val;
         int status = DRMS_SUCCESS;          status = 0;
  
         val = drms_getkey_double(inRec, "DATE",&status);         val = drms_getkey_double(inRec, "DATE",&status);
         drms_setkey_double(outRec, "DATE_B", val);         drms_setkey_double(outRec, "DATE_B", val);


Legend:
Removed from v.1.8  
changed lines
  Added in v.1.10

Karen Tian
Powered by
ViewCVS 0.9.4