IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 1, 2008, 4:25:00 AM (18 years ago)
Author:
eugene
Message:

finish imextract conversion to SQL style syntax

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20081124/Ohana/src/opihi/dvo/dbExtractImages.c

    r20861 r20862  
    11# include "dvoshell.h"
     2
     3/* time concepts */
     4static time_t TimeReference;
     5static int TimeFormat;
    26
    37static CoordTransform *celestial_to_galactic = NULL;
     
    1115static double ELON = 0.0;
    1216static double ELAT = 0.0;
     17
     18static int haveCelestial = FALSE;
     19static double RAo = 0.0;
     20static double DECo = 0.0;
    1321
    1422// define a locally-static transform
     
    3442
    3543int dbExtractImagesInit () {
    36   haveGalactic = FALSE;
    37   haveEcliptic = FALSE;
     44  GetTimeFormat (&TimeReference, &TimeFormat);
    3845  return (TRUE);
    3946}
    4047
     48int dbExtractImagesReset () {
     49  haveGalactic  = FALSE;
     50  haveEcliptic  = FALSE;
     51  haveCelestial = FALSE;
     52  return (TRUE);
     53}
     54
    4155/* return image.field based on the selection */
    42 dbValue dbExtractImages (Image *image, dbField *field) {
    43 
     56dbValue dbExtractImages (Image *image, int Nimage, int N, dbField *field) {
     57
     58  double x, y;
     59  time_t t;
    4460  int i, Nsec;
    4561  dbValue value;
     
    5167  switch (field->ID) {
    5268    case IMAGE_RA:
    53       XXX : need a better implementation of this...
    54         if (!FindMosaicForImage (image, Nimage, j)) continue;
    55       x = 0.5*image[0].NX;
    56       y = 0.5*image[0].NY;
    57       XY_to_RD (&ra, &dec, x, y, &image[0].coords);
    58       value.Flt = ra;
     69      if (!haveCelestial) {
     70        if (!FindMosaicForImage (image, Nimage, N)) return value;
     71        x = 0.5*image[N].NX;
     72        y = 0.5*image[N].NY;
     73        XY_to_RD (&RAo, &DECo, x, y, &image[N].coords);
     74        haveCelestial = TRUE;
     75      }
     76      value.Flt = RAo;
    5977      break;
    6078    case IMAGE_DEC:
    61       if (!FindMosaicForImage (image, Nimage, j)) continue;
    62       x = 0.5*image[0].NX;
    63       y = 0.5*image[0].NY;
    64       XY_to_RD (&ra, &dec, x, y, &image[0].coords);
    65       value.Flt = dec;
     79      if (!haveCelestial) {
     80        if (!FindMosaicForImage (image, Nimage, N)) return value;
     81        x = 0.5*image[N].NX;
     82        y = 0.5*image[N].NY;
     83        XY_to_RD (&RAo, &DECo, x, y, &image[N].coords);
     84        haveCelestial = TRUE;
     85      }
     86      value.Flt = DECo;
    6687      break;
    6788    case IMAGE_GLON:
    6889      if (!haveGalactic) {
     90        if (!haveCelestial) {
     91          if (!FindMosaicForImage (image, Nimage, N)) return value;
     92          x = 0.5*image[N].NX;
     93          y = 0.5*image[N].NY;
     94          XY_to_RD (&RAo, &DECo, x, y, &image[N].coords);
     95          haveCelestial = TRUE;
     96        }
    6997        ApplyTransform (&GLON, &GLAT, RAo, DECo, celestial_to_galactic);
    7098        haveGalactic = TRUE;
     
    74102    case IMAGE_GLAT:
    75103      if (!haveGalactic) {
     104        if (!haveCelestial) {
     105          if (!FindMosaicForImage (image, Nimage, N)) return value;
     106          x = 0.5*image[N].NX;
     107          y = 0.5*image[N].NY;
     108          XY_to_RD (&RAo, &DECo, x, y, &image[N].coords);
     109          haveCelestial = TRUE;
     110        }
    76111        ApplyTransform (&GLON, &GLAT, RAo, DECo, celestial_to_galactic);
    77112        haveGalactic = TRUE;
     
    81116    case IMAGE_ELON:
    82117      if (!haveEcliptic) {
     118        if (!haveCelestial) {
     119          if (!FindMosaicForImage (image, Nimage, N)) return value;
     120          x = 0.5*image[N].NX;
     121          y = 0.5*image[N].NY;
     122          XY_to_RD (&RAo, &DECo, x, y, &image[N].coords);
     123          haveCelestial = TRUE;
     124        }
    83125        ApplyTransform (&ELON, &ELAT, RAo, DECo, celestial_to_ecliptic);
    84126        haveEcliptic = TRUE;
     
    88130    case IMAGE_ELAT:
    89131      if (!haveEcliptic) {
     132        if (!haveCelestial) {
     133          if (!FindMosaicForImage (image, Nimage, N)) return value;
     134          x = 0.5*image[N].NX;
     135          y = 0.5*image[N].NY;
     136          XY_to_RD (&RAo, &DECo, x, y, &image[N].coords);
     137          haveCelestial = TRUE;
     138        }
    90139        ApplyTransform (&ELON, &ELAT, RAo, DECo, celestial_to_ecliptic);
    91140        haveEcliptic = TRUE;
     
    93142      value.Flt = ELAT;
    94143      break;
    95     case IMAGE_Xm:
    96       value.Flt = pow(10.0, 0.01*image[0].Xm);
     144    case IMAGE_XM:
     145      value.Flt = pow(10.0, 0.01*image[N].Xm);
    97146      break;
    98147    case IMAGE_AIRMASS:
    99       value.Flt = image[0].secz;
     148      value.Flt = image[N].secz;
    100149      break;
    101150    case IMAGE_MCAL:
    102       value.Flt = image[0].Mcal;
     151      value.Flt = image[N].Mcal;
    103152      break;
    104153    case IMAGE_dMCAL:
    105       value.Flt = image[0].dMcal;
     154      value.Flt = image[N].dMcal;
    106155      break;
    107156    case IMAGE_PHOTCODE:
    108       value.Flt = image[0].photcode;
     157      value.Flt = image[N].photcode;
    109158      break;
    110159    case IMAGE_TIME:
    111       t = image[0].tzero + 0.5*image[0].NY * image[0].trate / 10000;
     160      t = image[N].tzero + 0.5*image[N].NY * image[N].trate / 10000;
    112161      value.Flt = TimeValue (t, TimeReference, TimeFormat);
    113162      break;
    114163    case IMAGE_FWHM:
    115       value.Flt = image[0].fwhm_x / 25.0;
     164      value.Flt = image[N].fwhm_x / 25.0;
    116165      break;
    117166    case IMAGE_EXPTIME:
    118       value.Flt = image[0].exptime;
     167      value.Flt = image[N].exptime;
    119168      break;
    120169    case IMAGE_NSTAR:
    121       value.Flt = image[0].nstar;
     170      value.Flt = image[N].nstar;
    122171      break;
    123172    case IMAGE_NCAL:
    124       value.Flt = image[0].Mxxxx;
     173      value.Flt = image[N].Mxxxx;
    125174      break;
    126175    case IMAGE_SKY:
    127       value.Flt = image[0].Myyyy + 0x8000;
     176      value.Flt = image[N].Myyyy + 0x8000;
    128177      break;
    129178    case IMAGE_FLAG:
    130       value.Flt = image[0].code;
     179      value.Flt = image[N].code;
    131180      break;
    132181    case IMAGE_NX_PIX:
    133       value.Flt = image[0].NX;
     182      value.Flt = image[N].NX;
    134183      break;
    135184    case IMAGE_NY_PIX:
    136       value.Flt = image[0].NY;
     185      value.Flt = image[N].NY;
    137186      break;
    138187    case IMAGE_IMAGE_ID:
    139       value.Flt = image[0].imageID;
     188      value.Flt = image[N].imageID;
    140189      break;
    141190    case IMAGE_THETA: {
    142191      double theta1, theta2, s1, s2;
    143       s1 = SIGN(image[0].coords.pc1_1);
    144       s2 = SIGN(image[0].coords.pc2_2);
    145       theta1 = DEG_RAD*atan2 (+s1*image[0].coords.pc1_2, s1*image[0].coords.pc1_1);
    146       theta2 = DEG_RAD*atan2 (-s2*image[0].coords.pc2_1, s2*image[0].coords.pc2_2);
     192      s1 = SIGN(image[N].coords.pc1_1);
     193      s2 = SIGN(image[N].coords.pc2_2);
     194      theta1 = DEG_RAD*atan2 (+s1*image[N].coords.pc1_2, s1*image[N].coords.pc1_1);
     195      theta2 = DEG_RAD*atan2 (-s2*image[N].coords.pc2_1, s2*image[N].coords.pc2_2);
    147196      value.Flt = 0.5*(theta1+theta2);
    148197      break; }
    149198    case IMAGE_SKEW: {
    150199      double theta1, theta2, s1, s2;
    151       s1 = SIGN(image[0].coords.pc1_1);
    152       s2 = SIGN(image[0].coords.pc2_2);
    153       theta1 = DEG_RAD*atan2 (+s1*image[0].coords.pc1_2, s1*image[0].coords.pc1_1);
    154       theta2 = DEG_RAD*atan2 (-s2*image[0].coords.pc2_1, s2*image[0].coords.pc2_2);
     200      s1 = SIGN(image[N].coords.pc1_1);
     201      s2 = SIGN(image[N].coords.pc2_2);
     202      theta1 = DEG_RAD*atan2 (+s1*image[N].coords.pc1_2, s1*image[N].coords.pc1_1);
     203      theta2 = DEG_RAD*atan2 (-s2*image[N].coords.pc2_1, s2*image[N].coords.pc2_2);
    155204      value.Flt = (theta1-theta2);
    156205      break; }
    157206    case IMAGE_SCALE: {
    158207      double scale1, scale2;
    159       scale1 = fabs(image[0].coords.cdelt1);
    160       scale2 = fabs(image[0].coords.cdelt2);
     208      scale1 = fabs(image[N].coords.cdelt1);
     209      scale2 = fabs(image[N].coords.cdelt2);
    161210      value.Flt = 0.5*(scale1+scale2);
    162211      break; }
    163212    case IMAGE_DSCALE: {
    164213      double scale1, scale2;
    165       scale1 = fabs(image[0].coords.cdelt1);
    166       scale2 = fabs(image[0].coords.cdelt2);
     214      scale1 = fabs(image[N].coords.cdelt1);
     215      scale2 = fabs(image[N].coords.cdelt2);
    167216      value.Flt = (scale1-scale2);
    168217      break; }
     
    177226    case IMAGE_X_LR_CHIP:
    178227    case IMAGE_X_UR_CHIP:
    179       value.Flt = image[0].NX;
     228      value.Flt = image[N].NX;
    180229      break;
    181230    case IMAGE_Y_UL_CHIP:
    182231    case IMAGE_Y_UR_CHIP:
    183       value.Flt = image[0].NX;
     232      value.Flt = image[N].NX;
    184233      break;
    185234
    186235    case IMAGE_X_LL_FP:
    187236    case IMAGE_Y_LL_FP:
    188       XY_to_LM (&x, &y, 0.0, 0.0, &image[0].coords);
    189       value.Flt = (mode == X_LL_FP) ? x : y;
     237      XY_to_LM (&x, &y, 0.0, 0.0, &image[N].coords);
     238      value.Flt = (field->ID == IMAGE_X_LL_FP) ? x : y;
    190239      break;
    191240    case IMAGE_X_LR_FP:
    192241    case IMAGE_Y_LR_FP:
    193       XY_to_LM (&x, &y, image[0].NX, 0.0, &image[0].coords);
    194       value.Flt = (mode == X_LR_FP) ? x : y;
     242      XY_to_LM (&x, &y, image[N].NX, 0.0, &image[N].coords);
     243      value.Flt = (field->ID == IMAGE_X_LR_FP) ? x : y;
    195244      break;
    196245    case IMAGE_X_UL_FP:
    197246    case IMAGE_Y_UL_FP:
    198       XY_to_LM (&x, &y, 0.0, image[0].NY, &image[0].coords);
    199       value.Flt = (mode == X_UL_FP) ? x : y;
     247      XY_to_LM (&x, &y, 0.0, image[N].NY, &image[N].coords);
     248      value.Flt = (field->ID == IMAGE_X_UL_FP) ? x : y;
    200249      break;
    201250    case IMAGE_X_UR_FP:
    202251    case IMAGE_Y_UR_FP:
    203       XY_to_LM (&x, &y, image[0].NX, image[0].NY, &image[0].coords);
    204       value.Flt = (mode == X_UR_FP) ? x : y;
     252      XY_to_LM (&x, &y, image[N].NX, image[N].NY, &image[N].coords);
     253      value.Flt = (field->ID == IMAGE_X_UR_FP) ? x : y;
    205254      break;
    206255  }
Note: See TracChangeset for help on using the changeset viewer.