Esempio n. 1
0
vm_value vm_value::as(int32_t new_type) const {
  if (new_type == type) {
    return *this;
  }

  switch (new_type) {
  case SIGNED: // want signed
    switch (type) {
    case UNSIGNED: return vm_value { static_cast<uint64_t>(s64_) };
    case SIGNED:   return *this;
    case FLOAT:    return vm_value { static_cast<double>(s64_) };
    default:       return undefined();
    }

  case UNSIGNED:
    switch (type) {
    case UNSIGNED: return *this;
    case SIGNED:   return vm_value { static_cast<int64_t>(u64_) };
    case FLOAT:    return vm_value { static_cast<uint64_t>(u64_) };
    default:       return undefined();
    }

  case FLOAT:
    switch (type) {
    case UNSIGNED: return vm_value { static_cast<double>(u64_) };
    case SIGNED:   return vm_value { static_cast<double>(s64_) };
    case FLOAT:    return *this;
    default:       return undefined();
    }

  default:
    return undefined();
  } // new_type
}
Esempio n. 2
0
static void
fillCineonImageInfo(CineonFile* cineon, CineonImageInformation* imageInfo) {

	imageInfo->orientation = 0;
	imageInfo->channels_per_image = cineon->depth;

	if (cineon->depth == 1) {
		fillCineonChannelInfo(cineon, &imageInfo->channel[0], 0);

	} else if (cineon->depth == 3) {
		fillCineonChannelInfo(cineon, &imageInfo->channel[0], 1);
		fillCineonChannelInfo(cineon, &imageInfo->channel[1], 2);
		fillCineonChannelInfo(cineon, &imageInfo->channel[2], 3);
	}

	imageInfo->white_point_x = htonf(undefined());
	imageInfo->white_point_y = htonf(undefined());
	imageInfo->red_primary_x = htonf(undefined());
	imageInfo->red_primary_y = htonf(undefined());
	imageInfo->green_primary_x = htonf(undefined());
	imageInfo->green_primary_y = htonf(undefined());
	imageInfo->blue_primary_x = htonf(undefined());
	imageInfo->blue_primary_y = htonf(undefined());

	strcpy(imageInfo->label, "David's Cineon writer.");

}
Esempio n. 3
0
DenseSet Router::find_defined() const {
    POMAGMA_INFO("Finding defined obs");
    DenseSet defined(m_carrier.item_dim());
    DenseSet undefined(m_carrier.item_dim());
    undefined = m_carrier.support();

    bool changed = true;
    while (changed) {
        changed = false;

        POMAGMA_DEBUG("accumulating route probabilities");

        undefined -= defined;
        for (auto iter = undefined.iter(); iter.ok(); iter.next()) {
            Ob ob = *iter;
            if (defines(defined, ob)) {
                defined.insert(ob);
                changed = true;
                break;
            }
        }
    }

    return defined;
}
Esempio n. 4
0
FRAGMENT(jsval, simple) {
  JS::Rooted<jsval> fortytwo(cx, INT_TO_JSVAL(42));
  JS::Rooted<jsval> negone(cx, INT_TO_JSVAL(-1));
  JS::Rooted<jsval> undefined(cx, JSVAL_VOID);
  JS::Rooted<jsval> null(cx, JSVAL_NULL);
  JS::Rooted<jsval> js_true(cx, JSVAL_TRUE);
  JS::Rooted<jsval> js_false(cx, JSVAL_FALSE);
  JS::Rooted<jsval> elements_hole(cx, js::MagicValue(JS_ELEMENTS_HOLE));

  JS::Rooted<jsval> empty_string(cx);
  empty_string.setString(JS_NewStringCopyZ(cx, ""));
  JS::Rooted<jsval> friendly_string(cx);
  friendly_string.setString(JS_NewStringCopyZ(cx, "Hello!"));

  JS::Rooted<jsval> global(cx);
  global.setObject(*JS_GetGlobalObject(cx));

  // Some interesting value that floating-point won't munge.
  JS::Rooted<jsval> onehundredthirtysevenonehundredtwentyeighths(cx, DOUBLE_TO_JSVAL(137.0 / 128.0));

  breakpoint();

  (void) fortytwo;
  (void) negone;
  (void) undefined;
  (void) js_true;
  (void) js_false;
  (void) null;
  (void) elements_hole;
  (void) empty_string;
  (void) friendly_string;
  (void) global;
}
Esempio n. 5
0
//Read all member data.
void MGFog::ReadMembers(MGIfstream& buf){
	MGGLAttrib::ReadMembers(buf);
	if(undefined()) return;
	buf>>m_density;
	buf>>m_start;
	buf>>m_end;
	float* color=m_color.color();
	for(size_t i=0; i<4; i++) buf>>color[i];
}
Esempio n. 6
0
//Write all member data
void MGFog::WriteMembers(MGOfstream& buf)const{
	MGGLAttrib::WriteMembers(buf);
	if(undefined()) return;
	buf<<m_density;
	buf<<m_start;
	buf<<m_end;
	const float* color=m_color.color();
	for(size_t i=0; i<4; i++) buf<<color[i];
}
Esempio n. 7
0
static void
fillCineonOriginationInfo(CineonFile* cineon,
	CineonOriginationInformation* originInfo, CineonFileInformation* fileInfo) {
	
	(void)cineon; /* unused */

	originInfo->x_offset = htonl(0);
	originInfo->y_offset = htonl(0);
	strcpy(originInfo->file_name, fileInfo->file_name);
	strcpy(originInfo->create_date, fileInfo->create_date);
	strcpy(originInfo->create_time, fileInfo->create_time);
	strncpy(originInfo->input_device, "David's Cineon writer", 64);
	strncpy(originInfo->model_number, "Software", 32);
	strncpy(originInfo->serial_number, "001", 32);
	originInfo->x_input_samples_per_mm = htonf(undefined());
	originInfo->y_input_samples_per_mm =	htonf(undefined());
	/* this should probably be undefined, too */
	originInfo->input_device_gamma = htonf(1.0);
}
Esempio n. 8
0
static void
print_ifsizeof(char *prefix, char *type)
{
    if (streq(type, "bool")) {
	f_print(fout, ", sizeof(bool_t), (xdrproc_t) xdr_bool");
    } else {
	f_print(fout, ", sizeof(");
	if (undefined(type) && prefix) {
	    f_print(fout, "%s ", prefix);
	}
	f_print(fout, "%s), (xdrproc_t) xdr_%s", type, type);
    }
}
Esempio n. 9
0
//render GLAttribute process.
void MGFog::exec()const{
	if(undefined()) return;
	if(disabled()){
		glDisable(GL_FOG);
		return;
	}
	glEnable(GL_FOG);
	glFogi(GL_FOG_MODE,GLfog_mode());
	glFogf(GL_FOG_START,m_start);
	glFogf(GL_FOG_END,m_end);
	glFogf(GL_FOG_DENSITY,m_density);
	const float* color=m_color.color();
	glFogfv(GL_COLOR,color);
}
Esempio n. 10
0
static void
print_ifsizeof(int indent, const char *prefix, const char *type)
{
	if (indent) {
		f_print(fout, ",\n");
		tabify(fout, indent);
	} else  {
		f_print(fout, ", ");
	}
	if (streq(type, "bool")) {
		f_print(fout, "sizeof (bool_t), (xdrproc_t) xdr_bool");
	} else {
		f_print(fout, "sizeof (");
		if (undefined(type) && prefix)
			f_print(fout, "%s ", prefix);
		f_print(fout, "%s), (xdrproc_t) xdr_%s", type, type);
	}
}
Esempio n. 11
0
int
cond(int n, u32int instr)
{
	switch(n){
	case 0: return (cpsr & FLAGZ) != 0;
	case 1: return (cpsr & FLAGZ) == 0;
	case 2: return (cpsr & FLAGC) != 0;
	case 3: return (cpsr & FLAGC) == 0;
	case 4: return (cpsr & FLAGN) != 0;
	case 5: return (cpsr & FLAGN) == 0;
	case 6: return (cpsr & FLAGV) != 0;
	case 7: return (cpsr & FLAGV) == 0;
	case 8: return (cpsr & (FLAGC|FLAGZ)) == FLAGC;
	case 9: return (cpsr & (FLAGC|FLAGZ)) != FLAGC;
	case 10: return ((cpsr ^ cpsr << 3) & FLAGN) == 0;
	case 11: return ((cpsr ^ cpsr << 3) & FLAGN) != 0;
	case 12: return ((cpsr ^ cpsr << 3) & (FLAGN|FLAGZ)) == 0;
	case 13: return ((cpsr ^ cpsr << 3) & (FLAGN|FLAGZ)) != 0;
	case 14: return 1;
	}
	undefined(instr);
	return 0;
}
Esempio n. 12
0
BEGIN_NAMESPACE_MW


ScopedVariableContext::ScopedVariableContext(ScopedVariableEnvironment *env) {
    
	if(env == NULL){
		merror(M_SYSTEM_MESSAGE_DOMAIN,
			   "Attempt to create a context with an invalid environmnet");
		return;
	}
	environment = env;
	
	int nfields = environment->getNVariables();
	
	transparency = map<int, Transparency>();
	data = map<int, shared_ptr<Datum> >();
	
	shared_ptr<Datum> undefined(new Datum());
    for(int j = 0; j < nfields; j++){
        transparency[j] = M_TRANSPARENT;
		data[j] = undefined;
	}
}
Esempio n. 13
0
File: wcshdr.c Progetto: MQQ/astropy
int wcshdo(int relax, struct wcsprm *wcs, int *nkeyrec, char **header)

/* ::: CUBEFACE and STOKES handling? */

{
    static const char *function = "wcshdo";

    char alt, comment[72], keyvalue[72], keyword[16], obsg[8] = "OBSG?",
            obsgeo[8] = "OBSGEO-?", ptype, xtype, xyz[] = "XYZ";
    int  bintab, col0, *colax, colnum, i, j, k, naxis, pixlist, primage,
         status = 0;
    struct wcserr **err;

    *nkeyrec = 0;
    *header  = 0x0;

    if (wcs == 0x0) return WCSHDRERR_NULL_POINTER;
    err = &(wcs->err);

    if (wcs->flag != WCSSET) {
        if ((status = wcsset(wcs))) return status;
    }

    if ((naxis = wcs->naxis) == 0) {
        return 0;
    }


    /* These are mainly for convenience. */
    alt = wcs->alt[0];
    if (alt == ' ') alt = '\0';
    colnum = wcs->colnum;
    colax  = wcs->colax;

    primage = 0;
    bintab  = 0;
    pixlist = 0;
    if (colnum) {
        bintab  = 1;
        col0 = colnum;
    } else if (colax[0]) {
        pixlist = 1;
        col0 = colax[0];
    } else {
        primage = 1;
    }


    /* WCS dimension. */
    if (!pixlist) {
        sprintf(keyvalue, "%20d", naxis);
        wcshdo_util(relax, "WCSAXES", "WCAX", 0, 0x0, 0, 0, 0, alt, colnum, colax,
                    keyvalue, "Number of coordinate axes", nkeyrec, header, &status);
    }

    /* Reference pixel coordinates. */
    for (j = 0; j < naxis; j++) {
        wcsutil_double2str(keyvalue, "%20.12G", wcs->crpix[j]);
        wcshdo_util(relax, "CRPIX", "CRP", WCSHDO_CRPXna, "CRPX", 0, j+1, 0, alt,
                    colnum, colax, keyvalue, "Pixel coordinate of reference point", nkeyrec,
                    header, &status);
    }

    /* Linear transformation matrix. */
    k = 0;
    for (i = 0; i < naxis; i++) {
        for (j = 0; j < naxis; j++, k++) {
            if (i == j) {
                if (wcs->pc[k] == 1.0) continue;
            } else {
                if (wcs->pc[k] == 0.0) continue;
            }

            wcsutil_double2str(keyvalue, "%20.12G", wcs->pc[k]);
            wcshdo_util(relax, "PC", bintab ? "PC" : "P", WCSHDO_TPCn_ka,
                        bintab ? 0x0 : "PC", i+1, j+1, 0, alt, colnum, colax,
                        keyvalue, "Coordinate transformation matrix element",
                        nkeyrec, header, &status);
        }
    }

    /* Coordinate increment at reference point. */
    for (i = 0; i < naxis; i++) {
        wcsutil_double2str(keyvalue, "%20.12G", wcs->cdelt[i]);
        comment[0] = '\0';
        if (wcs->cunit[i][0]) sprintf(comment, "[%s] ", wcs->cunit[i]);
        strcat(comment, "Coordinate increment at reference point");
        wcshdo_util(relax, "CDELT", "CDE", WCSHDO_CRPXna, "CDLT", i+1, 0, 0, alt,
                    colnum, colax, keyvalue, comment, nkeyrec, header, &status);
    }

    /* Units of coordinate increment and reference value. */
    for (i = 0; i < naxis; i++) {
        if (wcs->cunit[i][0] == '\0') continue;

        sprintf(keyvalue, "'%s'", wcs->cunit[i]);
        wcshdo_util(relax, "CUNIT", "CUN", WCSHDO_CRPXna, "CUNI", i+1, 0, 0, alt,
                    colnum, colax, keyvalue, "Units of coordinate increment and value",
                    nkeyrec, header, &status);
    }

    /* Coordinate type. */
    for (i = 0; i < naxis; i++) {
        if (wcs->ctype[i][0] == '\0') continue;

        sprintf(keyvalue, "'%s'", wcs->ctype[i]);
        strcpy(comment, "Coordinate type code");
        if (i == wcs->lng || i == wcs->lat) {
            if (strncmp(wcs->ctype[i], "RA--", 4) == 0) {
                strcpy(comment, "Right ascension, ");
            } else if (strncmp(wcs->ctype[i], "DEC-", 4) == 0) {
                strcpy(comment, "Declination, ");
            } else if (strncmp(wcs->ctype[i]+1, "LON", 3) == 0 ||
                       strncmp(wcs->ctype[i]+1, "LAT", 3) == 0) {
                switch (wcs->ctype[i][0]) {
                case 'G':
                    strcpy(comment, "galactic ");
                    break;
                case 'E':
                    strcpy(comment, "ecliptic ");
                case 'H':
                    strcpy(comment, "helioecliptic ");
                case 'S':
                    strcpy(comment, "supergalactic ");
                }

                if (i == wcs->lng) {
                    strcat(comment, "longitude, ");
                } else {
                    strcat(comment, "latitude, ");
                }

                wcs->ctype[i][0] = toupper(wcs->ctype[i][0]);
            }

            strcat(comment, wcs->cel.prj.name);
            strcat(comment, " projection");

        } else if (i == wcs->spec) {
            spctyp(wcs->ctype[i], 0x0, 0x0, comment, 0x0, &ptype, &xtype, 0x0);
            if (ptype == xtype) {
                strcat(comment, " (linear)");
            } else {
                switch (xtype) {
                case 'F':
                    strcat(comment, " (linear in frequency)");
                    break;
                case 'V':
                    strcat(comment, " (linear in velocity)");
                    break;
                case 'W':
                    strcat(comment, " (linear in wavelength)");
                    break;
                }
            }
        }

        wcshdo_util(relax, "CTYPE", "CTY", WCSHDO_CRPXna, "CTYP", i+1, 0, 0, alt,
                    colnum, colax, keyvalue, comment, nkeyrec, header, &status);
    }

    /* Coordinate value at reference point. */
    for (i = 0; i < naxis; i++) {
        wcsutil_double2str(keyvalue, "%20.12G", wcs->crval[i]);
        comment[0] = '\0';
        if (wcs->cunit[i][0]) sprintf(comment, "[%s] ", wcs->cunit[i]);
        strcat(comment, "Coordinate value at reference point");
        wcshdo_util(relax, "CRVAL", "CRV", WCSHDO_CRPXna, "CRVL", i+1, 0, 0, alt,
                    colnum, colax, keyvalue, comment, nkeyrec, header, &status);
    }

    /* Parameter values. */
    for (k = 0; k < wcs->npv; k++) {
        wcsutil_double2str(keyvalue, "%20.12G", (wcs->pv[k]).value);
        if ((wcs->pv[k]).i == (wcs->lng + 1)) {
            switch ((wcs->pv[k]).m) {
            case 1:
                strcpy(comment, "[deg] Native longitude of the reference point");
                break;
            case 2:
                strcpy(comment, "[deg] Native latitude  of the reference point");
                break;
            case 3:
                if (primage) {
                    sprintf(keyword, "LONPOLE%c", alt);
                } else if (bintab) {
                    sprintf(keyword, "LONP%d%c", colnum, alt);
                } else {
                    sprintf(keyword, "LONP%d%c", colax[(wcs->pv[k]).i - 1], alt);
                }
                sprintf(comment, "[deg] alias for %s (has precedence)", keyword);
                break;
            case 4:
                if (primage) {
                    sprintf(keyword, "LATPOLE%c", alt);
                } else if (bintab) {
                    sprintf(keyword, "LATP%d%c", colnum, alt);
                } else {
                    sprintf(keyword, "LATP%d%c", colax[(wcs->pv[k]).i - 1], alt);
                }
                sprintf(comment, "[deg] alias for %s (has precedence)", keyword);
                break;
            }
        } else if ((wcs->pv[k]).i == (wcs->lat + 1)) {
            sprintf(comment, "%s projection parameter", wcs->cel.prj.code);
        } else {
            strcpy(comment, "Coordinate transformation parameter");
        }

        wcshdo_util(relax, "PV", "V", WCSHDO_PVn_ma, "PV", wcs->pv[k].i, -1,
                    wcs->pv[k].m, alt, colnum, colax, keyvalue, comment,
                    nkeyrec, header, &status);
    }

    for (k = 0; k < wcs->nps; k++) {
        sprintf(keyvalue, "'%s'", (wcs->ps[k]).value);

        wcshdo_util(relax, "PS", "S", WCSHDO_PVn_ma, "PS", wcs->ps[k].i, -1,
                    wcs->ps[k].m, alt, colnum, colax, keyvalue,
                    "Coordinate transformation parameter",
                    nkeyrec, header, &status);
    }

    /* Celestial and spectral transformation parameters. */
    if (!undefined(wcs->lonpole)) {
        wcsutil_double2str(keyvalue, "%20.12G", wcs->lonpole);
        wcshdo_util(relax, "LONPOLE", "LONP", 0, 0x0, 0, 0, 0, alt,
                    colnum, colax, keyvalue, "[deg] Native longitude of celestial pole",
                    nkeyrec, header, &status);
    }

    if (!undefined(wcs->latpole)) {
        wcsutil_double2str(keyvalue, "%20.12G", wcs->latpole);
        wcshdo_util(relax, "LATPOLE", "LATP", 0, 0x0, 0, 0, 0, alt,
                    colnum, colax, keyvalue, "[deg] Native latitude of celestial pole",
                    nkeyrec, header, &status);
    }

    if (!undefined(wcs->restfrq)) {
        wcsutil_double2str(keyvalue, "%20.12G", wcs->restfrq);
        wcshdo_util(relax, "RESTFRQ", "RFRQ", 0, 0x0, 0, 0, 0, alt,
                    colnum, colax, keyvalue, "[Hz] Line rest frequency",
                    nkeyrec, header, &status);
    }

    if (!undefined(wcs->restwav)) {
        wcsutil_double2str(keyvalue, "%20.12G", wcs->restwav);
        wcshdo_util(relax, "RESTWAV", "RWAV", 0, 0x0, 0, 0, 0, alt,
                    colnum, colax, keyvalue, "[Hz] Line rest wavelength",
                    nkeyrec, header, &status);
    }

    /* Coordinate system title. */
    if (wcs->wcsname[0]) {
        sprintf(keyvalue, "'%s'", wcs->wcsname);
        if (bintab) {
            wcshdo_util(relax, "WCSNAME", "WCSN", 0, 0x0, 0, 0, 0, alt,
                        colnum, colax, keyvalue, "Coordinate system title",
                        nkeyrec, header, &status);
        } else {
            /* TWCS was a mistake. */
            wcshdo_util(relax, "WCSNAME", "TWCS", WCSHDO_WCSNna, "WCSN", 0, 0, 0,
                        alt, colnum, colax, keyvalue, "Coordinate system title",
                        nkeyrec, header, &status);
        }
    }

    /* Coordinate axis title. */
    if (wcs->cname) {
        for (i = 0; i < naxis; i++) {
            if (wcs->cname[i][0] == '\0') continue;

            sprintf(keyvalue, "'%s'", wcs->cname[i]);
            wcshdo_util(relax, "CNAME", "CNA", WCSHDO_CNAMna, "CNAM", i+1, 0, 0,
                        alt, colnum, colax, keyvalue, "Axis name for labelling purposes",
                        nkeyrec, header, &status);
        }
    }

    /* Random error in coordinate. */
    if (wcs->crder) {
        for (i = 0; i < naxis; i++) {
            if (undefined(wcs->crder[i])) continue;

            wcsutil_double2str(keyvalue, "%20.12G", wcs->crder[i]);
            comment[0] = '\0';
            if (wcs->cunit[i][0]) sprintf(comment, "[%s] ", wcs->cunit[i]);
            strcat(comment, "Random error in coordinate");
            wcshdo_util(relax, "CRDER", "CRD", WCSHDO_CNAMna, "CRDE", i+1, 0, 0,
                        alt, colnum, colax, keyvalue, comment, nkeyrec, header, &status);
        }
    }

    /* Systematic error in coordinate. */
    if (wcs->csyer) {
        for (i = 0; i < naxis; i++) {
            if (undefined(wcs->csyer[i])) continue;

            wcsutil_double2str(keyvalue, "%20.12G", wcs->csyer[i]);
            comment[0] = '\0';
            if (wcs->cunit[i][0]) sprintf(comment, "[%s] ", wcs->cunit[i]);
            strcat(comment, "Systematic error in coordinate");
            wcshdo_util(relax, "CSYER", "CSY", WCSHDO_CNAMna, "CSYE", i+1, 0, 0,
                        alt, colnum, colax, keyvalue, comment, nkeyrec, header, &status);
        }
    }

    /* Equatorial coordinate system type. */
    if (wcs->radesys[0]) {
        sprintf(keyvalue, "'%s'", wcs->radesys);
        wcshdo_util(relax, "RADESYS", "RADE", 0, 0x0, 0, 0, 0, alt,
                    colnum, colax, keyvalue, "Equatorial coordinate system",
                    nkeyrec, header, &status);
    }

    /* Equinox of equatorial coordinate system. */
    if (!undefined(wcs->equinox)) {
        wcsutil_double2str(keyvalue, "%20.12G", wcs->equinox);
        wcshdo_util(relax, "EQUINOX", "EQUI", 0, 0x0, 0, 0, 0, alt,
                    colnum, colax, keyvalue, "[yr] Equinox of equatorial coordinates",
                    nkeyrec, header, &status);
    }

    /* Reference frame of spectral coordinates. */
    if (wcs->specsys[0]) {
        sprintf(keyvalue, "'%s'", wcs->specsys);
        wcshdo_util(relax, "SPECSYS", "SPEC", 0, 0x0, 0, 0, 0, alt,
                    colnum, colax, keyvalue, "Reference frame of spectral coordinates",
                    nkeyrec, header, &status);
    }

    /* Reference frame of spectral observation. */
    if (wcs->ssysobs[0]) {
        sprintf(keyvalue, "'%s'", wcs->ssysobs);
        wcshdo_util(relax, "SSYSOBS", "SOBS", 0, 0x0, 0, 0, 0, alt,
                    colnum, colax, keyvalue, "Reference frame of spectral observation",
                    nkeyrec, header, &status);
    }

    /* Observer's velocity towards source. */
    if (!undefined(wcs->velosys)) {
        wcsutil_double2str(keyvalue, "%20.12G", wcs->velosys);
        wcshdo_util(relax, "VELOSYS", "VSYS", 0, 0x0, 0, 0, 0, alt,
                    colnum, colax, keyvalue, "[m/s] Velocity towards source",
                    nkeyrec, header, &status);
    }

    /* Reference frame of source redshift. */
    if (wcs->ssyssrc[0]) {
        sprintf(keyvalue, "'%s'", wcs->ssyssrc);
        wcshdo_util(relax, "SSYSSRC", "SSRC", 0, 0x0, 0, 0, 0, alt,
                    colnum, colax, keyvalue, "Reference frame of source redshift",
                    nkeyrec, header, &status);
    }

    /* Redshift of the source. */
    if (!undefined(wcs->zsource)) {
        wcsutil_double2str(keyvalue, "%20.12G", wcs->zsource);
        wcshdo_util(relax, "ZSOURCE", "ZSOU", 0, 0x0, 0, 0, 0, alt,
                    colnum, colax, keyvalue, "Redshift of the source",
                    nkeyrec, header, &status);
    }

    /* Observatory coordinates. */
    for (k = 0; k < 3; k++) {
        if (undefined(wcs->obsgeo[k])) continue;

        wcsutil_double2str(keyvalue, "%20.12G", wcs->obsgeo[k]);
        sprintf(comment, "[m] ITRF observatory %c-coordinate", xyz[k]);
        obsgeo[7] = xyz[k];
        obsg[4]   = xyz[k];
        wcshdo_util(relax, obsgeo, obsg, 0, 0x0, 0, 0, 0, ' ',
                    colnum, colax, keyvalue, comment, nkeyrec, header, &status);
    }

    /* MJD of observation. */
    if (!undefined(wcs->mjdobs)) {
        wcsutil_double2str(keyvalue, "%20.12G", wcs->mjdobs);

        strcpy(comment, "[d] MJD of observation");
        if (wcs->dateobs[0]) {
            if (primage || (relax & 1) == 0) {
                sprintf(comment+22, " matching DATE-OBS");
            } else {
                sprintf(comment+22, " matching DOBS%d", col0);
            }
        }

        wcshdo_util(relax, "MJD-OBS", "MJDOB", 0, 0x0, 0, 0, 0, ' ',
                    colnum, colax, keyvalue, comment, nkeyrec, header, &status);
    }

    /* MJD mid-observation time. */
    if (!undefined(wcs->mjdavg)) {
        wcsutil_double2str(keyvalue, "%20.12G", wcs->mjdavg);

        strcpy(comment, "[d] MJD mid-observation");
        if (wcs->dateavg[0]) {
            if (primage) {
                sprintf(comment+23, " matching DATE-AVG");
            } else {
                sprintf(comment+23, " matching DAVG%d", col0);
            }
        }

        wcshdo_util(relax, "MJD-AVG", "MJDA", 0, 0x0, 0, 0, 0, ' ',
                    colnum, colax, keyvalue, comment, nkeyrec, header, &status);
    }

    /* ISO-8601 date corresponding to MJD-OBS. */
    if (wcs->dateobs[0]) {
        sprintf(keyvalue, "'%s'", wcs->dateobs);

        strcpy(comment, "ISO-8601 observation date");
        if (!undefined(wcs->mjdobs)) {
            if (primage) {
                sprintf(comment+25, " matching MJD-OBS");
            } else {
                sprintf(comment+25, " matching MJDOB%d", col0);
            }
        }

        if (relax & 1) {
            /* Allow DOBSn. */
            wcshdo_util(relax, "DATE-OBS", "DOBS", WCSHDO_DOBSn, 0x0, 0, 0, 0,
                        ' ', colnum, colax, keyvalue, comment, nkeyrec, header, &status);
        } else {
            /* Force DATE-OBS. */
            wcshdo_util(relax, "DATE-OBS", 0x0, 0, 0x0, 0, 0, 0, ' ', 0,
                        0x0, keyvalue, comment, nkeyrec, header, &status);
        }
    }

    /* ISO-8601 date corresponding to MJD-OBS. */
    if (wcs->dateavg[0]) {
        sprintf(keyvalue, "'%s'", wcs->dateavg);

        strcpy(comment, "ISO-8601 mid-observation date");
        if (!undefined(wcs->mjdavg)) {
            if (primage) {
                sprintf(comment+29, " matching MJD-AVG");
            } else {
                sprintf(comment+29, " matching MJDA%d", col0);
            }
        }

        wcshdo_util(relax, "DATE-AVG", "DAVG", 0, 0x0, 0, 0, 0, ' ',
                    colnum, colax, keyvalue, comment, nkeyrec, header, &status);
    }

    if (status == WCSHDRERR_MEMORY) {
        wcserr_set(WCSHDR_ERRMSG(status));
    }
    return status;
}
Esempio n. 14
0
int spcset(struct spcprm *spc)

{
  static const char *function = "spcset";

  char   ctype[9], ptype, xtype;
  int    restreq, status;
  double alpha, beta_r, crvalX, dn_r, dXdS, epsilon, G, m, lambda_r, n_r,
         t, restfrq, restwav, theta;
  struct wcserr **err;

  if (spc == 0x0) return SPCERR_NULL_POINTER;
  err = &(spc->err);

  if (undefined(spc->crval)) {
    return wcserr_set(WCSERR_SET(SPCERR_BAD_SPEC_PARAMS),
      "Spectral crval is undefined");
  }

  memset((spc->type)+4, 0, 4);
  spc->code[3] = '\0';
  wcsutil_blank_fill(4, spc->type);
  wcsutil_blank_fill(3, spc->code);
  spc->w[0] = 0.0;


  /* Analyse the spectral axis type. */
  memset(ctype, 0, 9);
  strncpy(ctype, spc->type, 4);
  if (*(spc->code) != ' ') {
    sprintf(ctype+4, "-%s", spc->code);
  }
  restfrq = spc->restfrq;
  restwav = spc->restwav;
  if ((status = spcspxe(ctype, spc->crval, restfrq, restwav, &ptype, &xtype,
                        &restreq, &crvalX, &dXdS, &(spc->err)))) {
    return status;
  }

  /* Satisfy rest frequency/wavelength requirements. */
  if (restreq) {
    if (restreq == 3 && restfrq == 0.0 && restwav == 0.0) {
      /* VRAD-V2F, VOPT-V2W, and ZOPT-V2W require the rest frequency or */
      /* wavelength for the S-P and P-X transformations but not for S-X */
      /* so supply a phoney value. */
      restwav = 1.0;
    }

    if (restfrq == 0.0) {
      restfrq = C/restwav;
    } else {
      restwav = C/restfrq;
    }

    if (ptype == 'F') {
      spc->w[0] = restfrq;
    } else if (ptype != 'V') {
      spc->w[0] = restwav;
    } else {
      if (xtype == 'F') {
        spc->w[0] = restfrq;
      } else {
        spc->w[0] = restwav;
      }
    }
  }

  spc->w[1] = crvalX;
  spc->w[2] = dXdS;


  /* Set pointers-to-functions for the linear part of the transformation. */
  if (ptype == 'F') {
    if (strcmp(spc->type, "FREQ") == 0) {
      /* Frequency. */
      spc->flag = FREQ;
      spc->spxP2S = 0x0;
      spc->spxS2P = 0x0;

    } else if (strcmp(spc->type, "AFRQ") == 0) {
      /* Angular frequency. */
      spc->flag = AFRQ;
      spc->spxP2S = freqafrq;
      spc->spxS2P = afrqfreq;

    } else if (strcmp(spc->type, "ENER") == 0) {
      /* Photon energy. */
      spc->flag = ENER;
      spc->spxP2S = freqener;
      spc->spxS2P = enerfreq;

    } else if (strcmp(spc->type, "WAVN") == 0) {
      /* Wave number. */
      spc->flag = WAVN;
      spc->spxP2S = freqwavn;
      spc->spxS2P = wavnfreq;

    } else if (strcmp(spc->type, "VRAD") == 0) {
      /* Radio velocity. */
      spc->flag = VRAD;
      spc->spxP2S = freqvrad;
      spc->spxS2P = vradfreq;
    }

  } else if (ptype == 'W') {
    if (strcmp(spc->type, "WAVE") == 0) {
      /* Vacuum wavelengths. */
      spc->flag = WAVE;
      spc->spxP2S = 0x0;
      spc->spxS2P = 0x0;

    } else if (strcmp(spc->type, "VOPT") == 0) {
      /* Optical velocity. */
      spc->flag = VOPT;
      spc->spxP2S = wavevopt;
      spc->spxS2P = voptwave;

    } else if (strcmp(spc->type, "ZOPT") == 0) {
      /* Redshift. */
      spc->flag = ZOPT;
      spc->spxP2S = wavezopt;
      spc->spxS2P = zoptwave;
    }

  } else if (ptype == 'A') {
    if (strcmp(spc->type, "AWAV") == 0) {
      /* Air wavelengths. */
      spc->flag = AWAV;
      spc->spxP2S = 0x0;
      spc->spxS2P = 0x0;
    }

  } else if (ptype == 'V') {
    if (strcmp(spc->type, "VELO") == 0) {
      /* Relativistic velocity. */
      spc->flag = VELO;
      spc->spxP2S = 0x0;
      spc->spxS2P = 0x0;

    } else if (strcmp(spc->type, "BETA") == 0) {
      /* Velocity ratio (v/c). */
      spc->flag = BETA;
      spc->spxP2S = velobeta;
      spc->spxS2P = betavelo;
    }
  }


  /* Set pointers-to-functions for the non-linear part of the spectral */
  /* transformation.                                                   */
  spc->isGrism = 0;
  if (xtype == 'F') {
    /* Axis is linear in frequency. */
    if (ptype == 'F') {
      spc->spxX2P = 0x0;
      spc->spxP2X = 0x0;

    } else if (ptype == 'W') {
      spc->spxX2P = freqwave;
      spc->spxP2X = wavefreq;

    } else if (ptype == 'A') {
      spc->spxX2P = freqawav;
      spc->spxP2X = awavfreq;

    } else if (ptype == 'V') {
      spc->spxX2P = freqvelo;
      spc->spxP2X = velofreq;
    }

    spc->flag += F2S;

  } else if (xtype == 'W' || xtype == 'w') {
    /* Axis is linear in vacuum wavelengths. */
    if (ptype == 'F') {
      spc->spxX2P = wavefreq;
      spc->spxP2X = freqwave;

    } else if (ptype == 'W') {
      spc->spxX2P = 0x0;
      spc->spxP2X = 0x0;

    } else if (ptype == 'A') {
      spc->spxX2P = waveawav;
      spc->spxP2X = awavwave;

    } else if (ptype == 'V') {
      spc->spxX2P = wavevelo;
      spc->spxP2X = velowave;
    }

    if (xtype == 'W') {
      spc->flag += W2S;
    } else {
      /* Grism in vacuum. */
      spc->isGrism = 1;
      spc->flag += GRI;
    }

  } else if (xtype == 'A' || xtype == 'a') {
    /* Axis is linear in air wavelengths. */
    if (ptype == 'F') {
      spc->spxX2P = awavfreq;
      spc->spxP2X = freqawav;

    } else if (ptype == 'W') {
      spc->spxX2P = awavwave;
      spc->spxP2X = waveawav;

    } else if (ptype == 'A') {
      spc->spxX2P = 0x0;
      spc->spxP2X = 0x0;

    } else if (ptype == 'V') {
      spc->spxX2P = awavvelo;
      spc->spxP2X = veloawav;
    }

    if (xtype == 'A') {
      spc->flag += A2S;
    } else {
      /* Grism in air. */
      spc->isGrism = 2;
      spc->flag += GRA;
    }

  } else if (xtype == 'V') {
    /* Axis is linear in relativistic velocity. */
    if (ptype == 'F') {
      spc->spxX2P = velofreq;
      spc->spxP2X = freqvelo;

    } else if (ptype == 'W') {
      spc->spxX2P = velowave;
      spc->spxP2X = wavevelo;

    } else if (ptype == 'A') {
      spc->spxX2P = veloawav;
      spc->spxP2X = awavvelo;

    } else if (ptype == 'V') {
      spc->spxX2P = 0x0;
      spc->spxP2X = 0x0;
    }

    spc->flag += V2S;
  }


  /* Check for grism axes. */
  if (spc->isGrism) {
    /* Axis is linear in "grism parameter"; work in wavelength. */
    lambda_r = crvalX;

    /* Set defaults. */
    if (undefined(spc->pv[0])) spc->pv[0] = 0.0;
    if (undefined(spc->pv[1])) spc->pv[1] = 0.0;
    if (undefined(spc->pv[2])) spc->pv[2] = 0.0;
    if (undefined(spc->pv[3])) spc->pv[3] = 1.0;
    if (undefined(spc->pv[4])) spc->pv[4] = 0.0;
    if (undefined(spc->pv[5])) spc->pv[5] = 0.0;
    if (undefined(spc->pv[6])) spc->pv[6] = 0.0;

    /* Compute intermediaries. */
    G       = spc->pv[0];
    m       = spc->pv[1];
    alpha   = spc->pv[2];
    n_r     = spc->pv[3];
    dn_r    = spc->pv[4];
    epsilon = spc->pv[5];
    theta   = spc->pv[6];

    t = G*m/cosd(epsilon);
    beta_r = asind(t*lambda_r - n_r*sind(alpha));

    t -= dn_r*sind(alpha);

    spc->w[1] = -tand(theta);
    spc->w[2] *= t / (cosd(beta_r)*cosd(theta)*cosd(theta));
    spc->w[3] = beta_r + theta;
    spc->w[4] = (n_r - dn_r*lambda_r)*sind(alpha);
    spc->w[5] = 1.0 / t;
  }

  return 0;
}
Esempio n. 15
0
int spcprt(const struct spcprm *spc)

{
  char hext[32];
  int  i;

  if (spc == 0x0) return SPCERR_NULL_POINTER;

  wcsprintf("       flag: %d\n", spc->flag);
  wcsprintf("       type: \"%s\"\n", spc->type);
  wcsprintf("       code: \"%s\"\n", spc->code);
  if (undefined(spc->crval)) {
    wcsprintf("      crval: UNDEFINED\n");
  } else {
    wcsprintf("      crval: %#- 11.5g\n", spc->crval);
  }
  wcsprintf("    restfrq: %f\n", spc->restfrq);
  wcsprintf("    restwav: %f\n", spc->restwav);

  wcsprintf("         pv:");
  if (spc->isGrism) {
    for (i = 0; i < 5; i++) {
      if (undefined(spc->pv[i])) {
        wcsprintf("  UNDEFINED   ");
      } else {
        wcsprintf("  %#- 11.5g", spc->pv[i]);
      }
    }
    wcsprintf("\n            ");
    for (i = 5; i < 7; i++) {
      if (undefined(spc->pv[i])) {
        wcsprintf("  UNDEFINED   ");
      } else {
        wcsprintf("  %#- 11.5g", spc->pv[i]);
      }
    }
    wcsprintf("\n");

  } else {
    wcsprintf(" (not used)\n");
  }

  wcsprintf("          w:");
  for (i = 0; i < 3; i++) {
    wcsprintf("  %#- 11.5g", spc->w[i]);
  }
  if (spc->isGrism) {
    wcsprintf("\n            ");
    for (i = 3; i < 6; i++) {
      wcsprintf("  %#- 11.5g", spc->w[i]);
    }
    wcsprintf("\n");
  } else {
    wcsprintf("  (remainder unused)\n");
  }

  wcsprintf("    isGrism: %d\n", spc->isGrism);

  WCSPRINTF_PTR("        err: ", spc->err, "\n");
  if (spc->err) {
    wcserr_prt(spc->err, "             ");
  }

  wcsprintf("     spxX2P: %s\n",
    wcsutil_fptr2str((int (*)(void))spc->spxX2P, hext));
  wcsprintf("     spxP2S: %s\n",
    wcsutil_fptr2str((int (*)(void))spc->spxP2S, hext));
  wcsprintf("     spxS2P: %s\n",
    wcsutil_fptr2str((int (*)(void))spc->spxS2P, hext));
  wcsprintf("     spxP2X: %s\n",
    wcsutil_fptr2str((int (*)(void))spc->spxP2X, hext));

  return 0;
}
Esempio n. 16
0
  mu__long(int lb, int ub, int size, const char *n, int os)
 :mu__int(lb, ub, size, n, os) {
   undefined();
 };
Esempio n. 17
0
	constexpr const T & operator[](std::size_t index) const {
		return (index == 0) ? x : (index == 1) ? y : (index == 2) ? z : (index == 3) ? w : undefined(x);
	}
Esempio n. 18
0
void FieldNewCalcUniDlg::Apply()
{
	if (m_result->GetSelection() == wxNOT_FOUND) {
		wxString msg("Please choose a Result field.");
		wxMessageDialog dlg (this, msg, "Error", wxOK | wxICON_ERROR);
		dlg.ShowModal();
		return;
	}
	int result_col = col_id_map[m_result->GetSelection()];

	int var_col = wxNOT_FOUND;
	if (m_var_sel != wxNOT_FOUND) {
		var_col = col_id_map[m_var_sel];
	}	
	if (var_col == wxNOT_FOUND && !m_valid_const) {
		wxString msg("Operation requires a valid field name or constant.");
		wxMessageDialog dlg (this, msg, "Error", wxOK | wxICON_ERROR);
		dlg.ShowModal();
		return;
	}
	
	if (is_space_time && var_col != wxNOT_FOUND &&
		!IsAllTime(result_col, m_result_tm->GetSelection()) &&
		IsAllTime(var_col, m_var_tm->GetSelection())) {
		wxString msg("When \"all times\" selected for variable, result "
					 "field must also be \"all times.\"");
		wxMessageDialog dlg (this, msg, "Error", wxOK | wxICON_ERROR);
		dlg.ShowModal();
		return;
	}
	
	TableState* ts = project->GetTableState();
	wxString grp_nm = table_int->GetColName(result_col);
	if (!GenUtils::CanModifyGrpAndShowMsgIfNot(ts, grp_nm)) return;

	
	// Mersenne Twister random number generator, randomly seeded
	// with current time in seconds since Jan 1 1970.
	static boost::mt19937 rng(std::time(0));
	
	std::vector<int> time_list;
	if (IsAllTime(result_col, m_result_tm->GetSelection())) {
		int ts = project->GetTableInt()->GetTimeSteps();
		time_list.resize(ts);
		for (int i=0; i<ts; i++) time_list[i] = i;
	} else {
		int tm = IsTimeVariant(result_col) ? m_result_tm->GetSelection() : 0;
		time_list.resize(1);
		time_list[0] = tm;
	}
	
	int rows = table_int->GetNumberRows();
	std::vector<double> data(rows, 0);
	std::vector<bool> undefined(rows, false);
	if (var_col != wxNOT_FOUND &&
		!IsAllTime(var_col, m_var_tm->GetSelection())) {
		int tm = IsTimeVariant(var_col) ? m_var_tm->GetSelection() : 0;
		table_int->GetColData(var_col,tm, data);
		table_int->GetColUndefined(var_col, tm, undefined);
	} else {
		for (int i=0; i<rows; i++) data[i] = m_const;
	}
	std::vector<double> r_data(table_int->GetNumberRows(), 0);
	std::vector<bool> r_undefined(table_int->GetNumberRows(), false);
	
	for (int t=0; t<time_list.size(); t++) {
		if (var_col != wxNOT_FOUND &&
			IsAllTime(var_col, m_var_tm->GetSelection()))
		{
			table_int->GetColData(var_col, time_list[t], data);
			table_int->GetColUndefined(var_col, time_list[t], undefined);
		}
		for (int i=0; i<rows; i++) {
			r_data[i] = data[i];
			r_undefined[i] = undefined[i];
		}
		switch (m_op->GetSelection()) {
			case assign_op:
			{
			}
				break;
			case negate_op:
			{
				for (int i=0; i<rows; i++) {
					if (!undefined[i]) r_data[i] = -data[i];
				}
			}
				break;
			case invert_op:
			{
				for (int i=0; i<rows; i++) {
					if (!undefined[i] && data[i] != 0) {
						r_data[i] = 1.0 / data[i];
					} else {
						r_data[i] = 0;
						r_undefined[i] = true;
					}
				}
			}
				break;
			case sqrt_op:
			{
				for (int i=0; i<rows; i++) {
					if (!undefined[i] && data[i] >= 0) {
						r_data[i] = sqrt(data[i]);
					} else {
						r_data[i] = 0;
						r_undefined[i] = true;
					}
				}
			}
				break;
			case log_10_op:
			{
				for (int i=0; i<rows; i++) {
					if (!undefined[i] && data[i] > 0) {
						r_data[i] = log10(data[i]);
					} else {
						r_data[i] = 0;
						r_undefined[i] = true;
					}
				}
			}
				break;			
			case log_e_op:
			{
				for (int i=0; i<rows; i++) {
					if (!undefined[i] && data[i] > 0) {
						r_data[i] = log(data[i]);
					} else {
						r_data[i] = 0;
						r_undefined[i] = true;
					}
				}
			}
				break;
			case dev_from_mean_op:
			{
				for (int i=0; i<rows; i++) {
					if (undefined[i]) {
						wxString msg;
						msg << "Observation " << i;
						msg << " is undefined. ";
						msg << "Operation aborted.";
						wxMessageDialog dlg (this, msg, "Error",
											 wxOK | wxICON_ERROR);
						dlg.ShowModal();
						return;
					}
					r_data[i] = data[i];
				}
				GenUtils::DeviationFromMean(r_data);
			}
				break;
			case standardize_op:
			{
				for (int i=0; i<rows; i++) {
					if (undefined[i]) {
						wxString msg;
						msg << "Observation ";
						msg << i << " is undefined. ";
						msg << "Operation aborted.";
						wxMessageDialog dlg (this, msg, "Error",
											 wxOK | wxICON_ERROR);
						dlg.ShowModal();
						return;
					}
					r_data[i] = data[i];
				}
				double ssum = 0.0;
				for (int i=0; i<rows; i++) ssum += r_data[i] * r_data[i];
				if (ssum == 0) {
					wxString msg("Standard deviation is 0, operation aborted.");
					wxMessageDialog dlg (this, msg, "Error", wxOK|wxICON_ERROR);
					dlg.ShowModal();
					return;
				}
				GenUtils::StandardizeData(r_data);
			}
				break;
			case shuffle_op:
			{
				for (int i=0; i<rows; i++) {
					r_data[i] = data[i];
					r_undefined[i] = undefined[i];
				}
				static boost::random::uniform_int_distribution<> X(0, rows-1);
				// X(rng) -> returns a uniform random number from 0 to rows-1;
				for (int i=0; i<rows; i++) {
					// swap each item in data with a random position in data.
					// This will produce a random permutation
					int r = X(rng);
					double d_t = r_data[r];
					bool u_t = r_undefined[r];
					r_data[r] = r_data[i];
					r_undefined[r] = r_undefined[i];
					r_data[i] = d_t;
					r_undefined[i] = u_t;
					if (undefined[i]) r_data[i] = 0;
					if (undefined[r]) r_data[r] = 0;
				}
			}
				break;
			default:
				return;
				break;
		}
		table_int->SetColData(result_col, time_list[t], r_data);
		table_int->SetColUndefined(result_col, time_list[t], r_undefined);

	}
}
Esempio n. 19
0
void CalculatorDlg::AssignOrSelect(bool assign)
{
	bool select = !assign;
	
	if (!all_init || !project) return;
	ValidateExpression();
	if (!expr_valid) {
		msg_s_txt->SetLabelText("Error: invalid expression");
		Refresh();
		return;
	}
	// we will now do a full evaluation and will print out
	// preview values.
	full_parser_table.clear();
	std::set<wxString>::iterator it;
	for (it = active_ident_set.begin(); it!=active_ident_set.end(); ++it) {
		int col = table_int->FindColId(*it);
		if (col < 0) continue;
		GdaFVSmtPtr val(new GdaFlexValue());
		table_int->GetColData(col, (*val));
		full_parser_table[*it] = val;
		size_t val_obs = (*val).GetObs();
		LOG(val_obs);
	}
	
	GdaParser parser;
	WeightsManInterface* wmi = 0;
	if (project && project->GetWManInt()) wmi = project->GetWManInt();
	bool parser_success = parser.eval(tokens, &full_parser_table, wmi);
	if (!parser_success) {
		wxString s(parser.GetErrorMsg());
		msg_s_txt->SetLabelText(s);
		Refresh();
		return;
	}
	GdaFVSmtPtr v = parser.GetEvalVal();
	
	int targ_col = -1;
	size_t targ_tms = -1;
	if (assign) {
		// Ensure dimensions are compatiable.
		targ_col = table_int->FindColId(target_choice->GetStringSelection());
		if (targ_col < 0) {
			msg_s_txt->SetLabelText("Error: Target choice not found");
			Refresh();
			return;
		}
		targ_tms = table_int->GetColTimeSteps(targ_col);
	}
	std::valarray<double>& V = (*v).GetValArrayRef();
	size_t V_tms = (*v).GetTms();
	size_t V_obs = (*v).GetObs();
	if (assign && targ_tms < V_tms) {
		msg_s_txt->SetLabelText("Error: Target has too few time periods.");
		Refresh();
		return;
	}
	size_t V_sz = V.size();
	double V_first = V[0];
	LOG(V_tms);
	LOG(V_obs);
	LOG(V_first);
	size_t obs = table_int->GetNumberRows();
	
	if (assign) {
		std::vector<double> t_vec(obs);
		std::vector<bool> undefined(obs);
		// MMM must consider case of [1 2 3 4 5 ... tms]
		if (V_obs == 1 && V_tms == 1) {
			double val = (*v).GetDouble();
			bool undef = false;
			if (!Gda::IsFinite(val)) {
				val = 0;
				undef = true;
			}
			for (size_t i=0; i<obs; ++i) {
				t_vec[i] = val;
				undefined[i] = undef;
			}
		} else if (V_tms == 1) {
			// fill t_vec from V.
			for (size_t i=0; i<obs; ++i) {
				double val = V[i];
				if (Gda::IsFinite(val)) {
					t_vec[i] = val;
					undefined[i] = false;
				} else {
					t_vec[i] = 0;
					undefined[i] = true;
				}
			}
		}
		for (size_t t=0; t<targ_tms; ++t) {
			if (V_tms > 1) {
				// fill t_vec from V for each time period.
				//std::slice sl(t,obs,Vtms);
				for (size_t i=0; i<obs; ++i) {
					double val = V[t+i*V_tms];
					if (Gda::IsFinite(val)) {
						t_vec[i] = val;
						undefined[i] = false;
					} else {
						t_vec[i] = 0;
						undefined[i] = true;
					}
				}
			}
			table_int->SetColData(targ_col, t, t_vec);
			table_int->SetColUndefined(targ_col, t, undefined);
		}
		
		
		wxString s("Success. First obs. and time value = ");
		s << (*v).GetDouble();
		msg_s_txt->SetLabelText(s);
	} else {
		int t=0;
		wxString t_str = "";
		if (V_tms > 1) {
			// will use current time period
			t = project->GetTimeState()->GetCurrTime();
			t_str = project->GetTimeState()->GetCurrTimeString();
		}
		int num_obs_sel = 0;
		vector<bool> selected(obs);
		if (V_obs == 1) {
			bool val = (bool) V[t];
			for (size_t i=0; i<obs; ++i) {
				selected[i] = val;
			}
			if (val) num_obs_sel = obs;
		} else {
			// fill t_vec from V for time period t.
			for (size_t i=0; i<obs; ++i) {
				selected[i] = (bool) V[t+i*V_tms];
				if (selected[i]) ++num_obs_sel;
			}
		}
		
		HighlightState& hs = *project->GetHighlightState();
		std::vector<bool>& h = hs.GetHighlight();
        bool selection_changed = false;
        
		for (size_t i=0; i<obs; i++) {
			bool sel = selected[i];
			if (sel && !h[i]) {
                h[i] = true;
                selection_changed = true;
			} else if (!sel && h[i]) {
                h[i] = false;
                selection_changed = true;

			}
		}
		hs.SetEventType(HLStateInt::delta);
		hs.notifyObservers();
		
		wxString s;
		s << num_obs_sel << " observation" << (num_obs_sel != 1 ? "s" : "");
		s << " selected";
		if (V_tms == 1) {
			s << ".";
		} else {
			s << " for time period " << t_str << " of result.";
		}
		msg_s_txt->SetLabelText(s);
	}
	Refresh();
}
Esempio n. 20
0
int spcprt(const struct spcprm *spc)

{
   int i;

   if (spc == 0) return 1;

   printf("       flag: %d\n", spc->flag);
   printf("       type: \"%s\"\n", spc->type);
   printf("       code: \"%s\"\n", spc->code);
   if (undefined(spc->crval)) {
      printf("      crval: UNDEFINED\n");
   } else {
      printf("      crval: %- 11.4g\n", spc->crval);
   }
   printf("    restfrq: %f\n", spc->restfrq);
   printf("    restwav: %f\n", spc->restwav);

   printf("         pv:");
   if (spc->isGrism) {
      for (i = 0; i < 5; i++) {
         if (undefined(spc->pv[i])) {
            printf("  UNDEFINED   ");
         } else {
            printf("  %- 11.4g", spc->pv[i]);
         }
      }
      printf("\n            ");
      for (i = 5; i < 7; i++) {
         if (undefined(spc->pv[i])) {
            printf("  UNDEFINED   ");
         } else {
            printf("  %- 11.4g", spc->pv[i]);
         }
      }
      printf("\n");

   } else {
      printf(" (not used)\n");
   }

   printf("          w:");
   for (i = 0; i < 3; i++) {
      printf("  %- 11.4g", spc->w[i]);
   }
   if (spc->isGrism) {
      printf("\n            ");
      for (i = 3; i < 6; i++) {
         printf("  %- 11.4g", spc->w[i]);
      }
      printf("\n");
   } else {
      printf("  (remainder unused)\n");
   }

   printf("    isGrism: %d\n", spc->isGrism);
   printf("     spxX2P: 0x%x\n", (int)spc->spxX2P);
   printf("     spxP2S: 0x%x\n", (int)spc->spxP2S);
   printf("     spxS2P: 0x%x\n", (int)spc->spxS2P);
   printf("     spxP2X: 0x%x\n", (int)spc->spxP2X);

   return 0;
}
Esempio n. 21
0
int datfix(struct wcsprm *wcs)

{
   char *dateobs;
   int  day, dd, hour = 0, jd, minute = 0, month, msec, n4, year;
   double mjdobs, sec = 0.0, t;

   if (wcs == 0x0) return 1;

   dateobs = wcs->dateobs;
   if (dateobs[0] == '\0') {
      if (undefined(wcs->mjdobs)) {
         /* No date information was provided. */
         return -1;

      } else {
         /* Calendar date from MJD. */
         jd = 2400001 + (int)wcs->mjdobs;

         n4 =  4*(jd + ((2*((4*jd - 17918)/146097)*3)/4 + 1)/2 - 37);
         dd = 10*(((n4-237)%1461)/4) + 5;

         year  = n4/1461 - 4712;
         month = (2 + dd/306)%12 + 1;
         day   = (dd%306)/10 + 1;
         sprintf(dateobs, "%.4d-%.2d-%.2d", year, month, day);

         /* Write time part only if non-zero. */
         if ((t = wcs->mjdobs - (int)wcs->mjdobs) > 0.0) {
            t *= 24.0;
            hour = (int)t;
            t = 60.0 * (t - hour);
            minute = (int)t;
            sec    = 60.0 * (t - minute);

            /* Round to 1ms. */
            dd = 60000*(60*hour + minute) + (int)(1000*(sec+0.0005));
            hour = dd / 3600000;
            dd -= 3600000 * hour;
            minute = dd / 60000;
            msec = dd - 60000 * minute;
            sprintf(dateobs+10, "T%.2d:%.2d:%.2d", hour, minute, msec/1000);

            /* Write fractions of a second only if non-zero. */
            if (msec%1000) {
               sprintf(dateobs+19, ".%.3d", msec%1000);
            }
         }

         return 0;
      }

   } else {
      if (strlen(dateobs) < 8) {
         /* Can't be a valid date. */
         return 5;
      }

      /* Identify the date format. */
      if (dateobs[4] == '-' && dateobs[7] == '-') {
         /* Standard year-2000 form: CCYY-MM-DD[Thh:mm:ss[.sss...]] */
         if (sscanf(dateobs, "%4d-%2d-%2d", &year, &month, &day) < 3) {
            return 5;
         }

         if (dateobs[10] == 'T') {
            if (sscanf(dateobs+11, "%2d:%2d:%lf", &hour, &minute, &sec) < 3) {
               return 5;
            }
         } else if (dateobs[10] == ' ') {
            if (sscanf(dateobs+11, "%2d:%2d:%lf", &hour, &minute, &sec) == 3) {
               dateobs[10] = 'T';
            } else {
               hour = 0;
               minute = 0;
               sec = 0.0;
            }
         }

      } else if (dateobs[4] == '/' && dateobs[7] == '/') {
         /* Also allow CCYY/MM/DD[Thh:mm:ss[.sss...]] */
         if (sscanf(dateobs, "%4d/%2d/%2d", &year, &month, &day) < 3) {
            return 5;
         }

         if (dateobs[10] == 'T') {
            if (sscanf(dateobs+11, "%2d:%2d:%lf", &hour, &minute, &sec) < 3) {
               return 5;
            }
         } else if (dateobs[10] == ' ') {
            if (sscanf(dateobs+11, "%2d:%2d:%lf", &hour, &minute, &sec) == 3) {
               dateobs[10] = 'T';
            } else {
               hour = 0;
               minute = 0;
               sec = 0.0;
            }
         }

         /* Looks ok, fix it up. */
         dateobs[4]  = '-';
         dateobs[7]  = '-';

      } else {
         if (dateobs[2] == '/' && dateobs[5] == '/') {
            /* Old format date: DD/MM/YY, also allowing DD/MM/CCYY. */
            if (sscanf(dateobs, "%2d/%2d/%4d", &day, &month, &year) < 3) {
               return 5;
            }

         } else if (dateobs[2] == '-' && dateobs[5] == '-') {
            /* Also recognize DD-MM-YY and DD-MM-CCYY */
            if (sscanf(dateobs, "%2d-%2d-%4d", &day, &month, &year) < 3) {
               return 5;
            }

         } else {
            /* Not a valid date format. */
            return 5;
         }

         if (year < 100) year += 1900;

         /* Doesn't have a time. */
         sprintf(dateobs, "%.4d-%.2d-%.2d", year, month, day);
      }

      /* Compute MJD. */
      mjdobs = (double)((1461*(year - (12-month)/10 + 4712))/4
               + (306*((month+9)%12) + 5)/10
               - (3*((year - (12-month)/10 + 4900)/100))/4
               + day - 2399904)
               + (hour + (minute + sec/60.0)/60.0)/24.0;

      if (undefined(wcs->mjdobs)) {
         wcs->mjdobs = mjdobs;
      } else {
         /* Check for consistency. */
         if (fabs(mjdobs - wcs->mjdobs) > 0.5) {
            return 5;
         }
      }
   }

   return 0;
}
Esempio n. 22
0
 inline void undefine() {
   undefined();
   initialized = TRUE;
 };
Esempio n. 23
0
 inline void reset()		// make variable be uninitialized
 {
   undefined();
   initialized = FALSE;
 };
Esempio n. 24
0
 mu__long(int lb, int ub, int size)
 :mu__int(lb, ub, size) {
   undefined();
 };
Esempio n. 25
0
	T & operator[](std::size_t index) {
		return (index == 0) ? x : (index == 1) ? y : (index == 2) ? z : undefined(x);
	}
Esempio n. 26
0
 inline void reset() {
   undefined();
   initialized = FALSE;
 };
Esempio n. 27
0
File: wcsfix.c Progetto: MQQ/astropy
int datfix(struct wcsprm *wcs)

{
  static const char *function = "datfix";

  char orig_dateobs[72];
  char ctmp[72], ctmp2[72];
  char *dateobs;
  int  day, dd, hour = 0, jd, minute = 0, month, msec, n4, year;
  double mjdobs, sec = 0.0, t;
  struct wcserr **err;

  if (wcs == 0x0) return FIXERR_NULL_POINTER;
  err = &(wcs->err);

  dateobs = wcs->dateobs;
  strncpy(orig_dateobs, dateobs, 72);
  if (dateobs[0] == '\0') {
    if (undefined(wcs->mjdobs)) {
     /* No date information was provided. */
      return FIXERR_NO_CHANGE;

    } else {
      /* Calendar date from MJD. */
      jd = 2400001 + (int)wcs->mjdobs;

      n4 =  4*(jd + ((2*((4*jd - 17918)/146097)*3)/4 + 1)/2 - 37);
      dd = 10*(((n4-237)%1461)/4) + 5;

      year  = n4/1461 - 4712;
      month = (2 + dd/306)%12 + 1;
      day   = (dd%306)/10 + 1;
      sprintf(dateobs, "%.4d-%.2d-%.2d", year, month, day);

      /* Write time part only if non-zero. */
      if ((t = wcs->mjdobs - (int)wcs->mjdobs) > 0.0) {
        t *= 24.0;
        hour = (int)t;
        t = 60.0 * (t - hour);
        minute = (int)t;
        sec    = 60.0 * (t - minute);

        /* Round to 1ms. */
        dd = 60000*(60*hour + minute) + (int)(1000*(sec+0.0005));
        hour = dd / 3600000;
        dd -= 3600000 * hour;
        minute = dd / 60000;
        msec = dd - 60000 * minute;
        sprintf(dateobs+10, "T%.2d:%.2d:%.2d", hour, minute, msec/1000);

        /* Write fractions of a second only if non-zero. */
        if (msec%1000) {
          sprintf(dateobs+19, ".%.3d", msec%1000);
        }
      }
    }

  } else {
    if (strlen(dateobs) < 8) {
      /* Can't be a valid date. */
      return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
        "Invalid parameter value: date string too short '%s'", dateobs);
    }

    /* Identify the date format. */
    if (dateobs[4] == '-' && dateobs[7] == '-') {
      /* Standard year-2000 form: CCYY-MM-DD[Thh:mm:ss[.sss...]] */
      if (sscanf(dateobs, "%4d-%2d-%2d", &year, &month, &day) < 3) {
        return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
          "Invalid parameter value: invalid date '%s'", dateobs);
      }

      if (dateobs[10] == 'T') {
        if (parse_date(dateobs+11, &hour, &minute, &sec)) {
          return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
            "Invalid parameter value: invalid time '%s'", dateobs+11);
        }
      } else if (dateobs[10] == ' ') {
        hour = 0;
        minute = 0;
        sec = 0.0;
        if (parse_date(dateobs+11, &hour, &minute, &sec)) {
          write_date(dateobs+10, hour, minute, sec);
        } else {
          dateobs[10] = 'T';
        }
      }

    } else if (dateobs[4] == '/' && dateobs[7] == '/') {
      /* Also allow CCYY/MM/DD[Thh:mm:ss[.sss...]] */
      if (sscanf(dateobs, "%4d/%2d/%2d", &year, &month, &day) < 3) {
        return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
          "Invalid parameter value: invalid date '%s'", dateobs);
      }

      if (dateobs[10] == 'T') {
        if (parse_date(dateobs+11, &hour, &minute, &sec)) {
          return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
            "Invalid parameter value: invalid time '%s'", dateobs+11);
        }
      } else if (dateobs[10] == ' ') {
        hour = 0;
        minute = 0;
        sec = 0.0;
        if (parse_date(dateobs+11, &hour, &minute, &sec)) {
          write_date(dateobs+10, hour, minute, sec);
        } else {
          dateobs[10] = 'T';
        }
      }

      /* Looks ok, fix it up. */
      dateobs[4]  = '-';
      dateobs[7]  = '-';

    } else {
      if (dateobs[2] == '/' && dateobs[5] == '/') {
        /* Old format date: DD/MM/YY, also allowing DD/MM/CCYY. */
        if (sscanf(dateobs, "%2d/%2d/%4d", &day, &month, &year) < 3) {
          return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
            "Invalid parameter value: invalid date '%s'", dateobs);
        }

      } else if (dateobs[2] == '-' && dateobs[5] == '-') {
        /* Also recognize DD-MM-YY and DD-MM-CCYY */
        if (sscanf(dateobs, "%2d-%2d-%4d", &day, &month, &year) < 3) {
          return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
            "Invalid parameter value: invalid date '%s'", dateobs);
        }

      } else {
        /* Not a valid date format. */
        return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
          "Invalid parameter value: invalid date '%s'", dateobs);
      }

      if (year < 100) year += 1900;

      /* Doesn't have a time. */
      sprintf(dateobs, "%.4d-%.2d-%.2d", year, month, day);
    }

    /* Compute MJD. */
    mjdobs = (double)((1461*(year - (12-month)/10 + 4712))/4
             + (306*((month+9)%12) + 5)/10
             - (3*((year - (12-month)/10 + 4900)/100))/4
             + day - 2399904)
             + (hour + (minute + sec/60.0)/60.0)/24.0;

    if (undefined(wcs->mjdobs)) {
      wcs->mjdobs = mjdobs;
    } else {
      /* Check for consistency. */
      if (fabs(mjdobs - wcs->mjdobs) > 0.5) {
        return wcserr_set(WCSERR_SET(FIXERR_BAD_PARAM),
          "Invalid parameter value: inconsistent date '%s'", dateobs);
      }
    }
  }

  if (strncmp(orig_dateobs, dateobs, 72)) {
    wcserr_set(WCSERR_SET(FIXERR_DATE_FIX),
      "Changed '%s' to '%s'", orig_dateobs, dateobs);

    return FIXERR_SUCCESS;
  }

  return FIXERR_NO_CHANGE;
}
Esempio n. 28
0
	T & operator[](std::size_t index) {
		return (index == 0) ? x : undefined(x);
	}
Esempio n. 29
0
void FieldNewCalcLagDlg::Apply()
{
	if (m_result->GetSelection() == wxNOT_FOUND) {
		wxString msg("Please select a Result field.");
		wxMessageDialog dlg (this, msg, "Error", wxOK | wxICON_ERROR);
		dlg.ShowModal();
		return;
	}
	
	if (m_weight->GetSelection() == wxNOT_FOUND) {
		wxString msg("Please specify a Weights matrix.");
		wxMessageDialog dlg (this, msg, "Error", wxOK | wxICON_ERROR);
		dlg.ShowModal();
		return;
	}
	
	if (m_var->GetSelection() == wxNOT_FOUND) {
		wxString msg("Please select an Variable field.");
		wxMessageDialog dlg (this, msg, "Error", wxOK | wxICON_ERROR);
		dlg.ShowModal();
		return;
	}
	
	int result_col = col_id_map[m_result->GetSelection()];
	int var_col = col_id_map[m_var->GetSelection()];
	
	TableState* ts = project->GetTableState();
	wxString grp_nm = table_int->GetColName(result_col);
	if (!GenUtils::CanModifyGrpAndShowMsgIfNot(ts, grp_nm)) return;
	
	if (is_space_time &&
		!IsAllTime(result_col, m_result_tm->GetSelection()) &&
		IsAllTime(var_col, m_var_tm->GetSelection())) {
		wxString msg("When \"all times\" selected for variable, result "
					 "field must also be \"all times.\"");
		wxMessageDialog dlg (this, msg, "Error", wxOK | wxICON_ERROR);
		dlg.ShowModal();
		return;
	}
	
	std::vector<int> time_list;
	if (IsAllTime(result_col, m_result_tm->GetSelection())) {
		int ts = project->GetTableInt()->GetTimeSteps();
		time_list.resize(ts);
		for (int i=0; i<ts; i++) time_list[i] = i;
	} else {
		int tm = IsTimeVariant(result_col) ? m_result_tm->GetSelection() : 0;
		time_list.resize(1);
		time_list[0] = tm;
	}
	
	std::vector<double> data(table_int->GetNumberRows(), 0);
	std::vector<bool> undefined(table_int->GetNumberRows(), false);
	if (!IsAllTime(var_col, m_var_tm->GetSelection())) {
		int tm = IsTimeVariant(var_col) ? m_var_tm->GetSelection() : 0;
		table_int->GetColData(var_col, tm, data);
		table_int->GetColUndefined(var_col, tm, undefined);
	}
	
	int rows = table_int->GetNumberRows();
	std::vector<double> r_data(table_int->GetNumberRows(), 0);
	std::vector<bool> r_undefined(table_int->GetNumberRows(), false);
	
	GalWeight* gal_w = w_manager->GetGalWeight(m_weight->GetSelection());
	if (gal_w == NULL) return;
	GalElement* W = gal_w->gal;
	
	for (int t=0; t<time_list.size(); t++) {
		for (int i=0; i<rows; i++) {
			r_data[i] = 0;
			r_undefined[i] = false;
		}
		if (IsAllTime(var_col, m_var_tm->GetSelection())) {
			table_int->GetColData(var_col, time_list[t], data);
			table_int->GetColUndefined(var_col, time_list[t], undefined);
		}
		// Row-standardized lag calculation.
		for (int i=0, iend=table_int->GetNumberRows(); i<iend; i++) {
			double lag = 0;
			if (W[i].size == 0) r_undefined[i] = true;
			for (int j=0; j<W[i].size && !r_undefined[i]; j++) {
				if (undefined[W[i].data[j]]) {
					r_undefined[i] = true;
				} else {
					lag += data[W[i].data[j]];
				}
			}
			r_data[i] = r_undefined[i] ? 0 : lag /= W[i].size;
		}
		table_int->SetColData(result_col, time_list[t], r_data);
		table_int->SetColUndefined(result_col, time_list[t], r_undefined);

	}
}
Esempio n. 30
0
	constexpr const T & operator[](std::size_t index) const {
		return (index == 0) ? x : undefined(x);
	}