Esempio n. 1
0
File: star.c Progetto: andbof/yastg
static void star_init(struct star *s)
{
	s->name = NULL;
	s->cls = star_gencls();
	s->lum = star_genlum();
	s->lumval = star_genlumval(s);
	s->hab = stellar_clshab[s->cls] + stellar_lumhab[s->lum];
	s->temp = star_gentemp(s);
	s->hablow = star_gethablow(s->lum);
	s->habhigh = star_gethabhigh(s->lum);
}
Esempio n. 2
0
File: star.c Progetto: neg/yastg
/*
 * Parses a configuration tree and loads the information
 * into the supplied struct star*
 */
int star_load(struct star *sol, struct config *ctree)
{
	int i;
	int habset = 0;
	int tempset = 0;
	int lumset = 0;
	int lumvalset = 0;
	int clsset = 0;

	sol->temp = 0;
	sol->hab = 0;
	sol->name = NULL;
	while (ctree) {
		if (strcmp(ctree->key, "NAME") == 0) {
			sol->name = strdup(ctree->data);
		} else if (strcmp(ctree->key, "CLASS") == 0) {
			if (strlen(ctree->data) != 1)
				die("invalid stellar class in configuration file: %s\n", ctree->data);
			for (i = 0; i < STELLAR_CLS_N; i++) {
				if (ctree->data[0] == stellar_cls[i]) {
					sol->cls = i;
					clsset = 1;
					break;
				}
			}
			if (!clsset)
				die("invalid stellar class in configuration file: %s\n", ctree->data);
		} else if (strcmp(ctree->key, "LUM") == 0) {
			for (i = 0; i < STELLAR_LUM_N; i++) {
				if (strcmp(ctree->data, stellar_lum[i]) == 0) {
					sol->lum = i;
					lumset = 1;
					break;
				}
			}
			if (!lumset)
				die("invalid stellar luminosity in configuration file: %s\n", ctree->data);
		} else if (strcmp(ctree->key, "LUMVAL") == 0) {
			sscanf(ctree->data, "%u", &(sol->lumval));
			lumvalset = 1;
		} else if (strcmp(ctree->key, "TEMP") == 0) {
			sscanf(ctree->data, "%u", &(sol->temp));
			tempset = 1;
		} else if (strcmp(ctree->key, "HAB") == 0) {
			sscanf(ctree->data, "%u", &(sol->hab));
			habset = 1;
		} else {
			printf("warning: invalid entry in configuration file: %s %s\n", ctree->key, ctree->data);
		}
		ctree = ctree->next;
	}
	if (!habset)
		sol->hab = 0;
	if (!sol->name)
		die("%s", "required attribute missing for predefined star: stellar name");
	if (!clsset)
		die("required attribute missing for predefined star %s: stellar class", sol->name);
	if (!lumset)
		die("required attribute missing for predefined star %s: stellar luminosity", sol->name);
	/* FIXME: */
	if (!lumvalset)
		sol->lumval = star_genlumval(sol);
	sol->hab = stellar_clshab[sol->cls] + stellar_lumhab[sol->lum];
	if (!tempset)
		sol->temp = star_gentemp(sol);
	sol->hablow = star_gethablow(sol->lumval);
	sol->habhigh = star_gethabhigh(sol->lumval);

	return 0;
}