Esempio n. 1
0
void usage(void) {
	const char *s1 = "Ecosystem water simulation model SOILWAT2\n"
			"More details at https://github.com/Burke-Lauenroth-Lab/SOILWAT2\n"
			"Usage: soilwat [-d startdir] [-f files.in] [-e] [-q]\n"
			"  -d : operate (chdir) in startdir (default=.)\n"
			"  -f : supply list of input files (default=files.in)\n"
			"       a preceeding path applies to all input files\n"
			"  -e : echo initial values from site and estab to logfile\n"
			"  -q : quiet mode, don't print message to check logfile.\n";
  sw_error(0, "%s", s1);
}
Esempio n. 2
0
File: msg_sw.c Progetto: taysom/tau
int sw_register (const char *name)
{
	sw_msg_s	msg;
	int		rc;
	size_t		len;

	len = strnlen(name, TAU_NAME);
	if (len < TAU_NAME) ++len;
	msg.sw_name.nm_length = len;
	memcpy(msg.sw_name.nm_name, name, len);

	msg.sw_method = SW_REGISTER;
	rc = call_tau(SW_STD_KEY, &msg);
	if (rc) return sw_error("call_tau", rc);

	destroy_key_tau(SW_STD_KEY);
	rc = change_index_tau(msg.q.q_passed_key, SW_STD_KEY);
	if (rc) return sw_error("change_index_tau", rc);

	return 0;
}
Esempio n. 3
0
File: msg_sw.c Progetto: taysom/tau
int sw_post_v (unint len, const void *name, ki_t key)
{
	sw_msg_s	msg;
	int		rc;

	if (len > TAU_NAME) return ETOOBIG;
	msg.sw_name.nm_length = len;
	memcpy(msg.sw_name.nm_name, name, len);

	msg.sw_method = SW_POST;
	msg.q.q_passed_key = key;
	rc = send_key_tau(SW_STD_KEY, &msg);
	if (rc) return sw_error("send_key_tau", rc);

	return rc;
}
Esempio n. 4
0
File: msg_sw.c Progetto: taysom/tau
int sw_any_v (unint len, const void *name, ki_t *key)
{
	sw_msg_s	msg;
	int		rc;

	if (len > TAU_NAME) return ETOOBIG;
	msg.sw_name.nm_length = len;
	memcpy(msg.sw_name.nm_name, name, len);

	msg.sw_method  = SW_GET;
	msg.sw_request = SW_ALL;
	rc = call_tau(SW_STD_KEY, &msg);
	if (rc) return sw_error("call_tau", rc);

	*key = msg.q.q_passed_key;
	return rc;
}
void onSet_SW_SWC_hist(void) {
  sw_error(-1, "'onSet_SW_SWC_hist' is currently not functional.\n");

	int i, j = 0;
	SW_SOILWAT *v = &SW_Soilwat;
	RealD *p_lyrs;
	SEXP lyrs = VECTOR_ELT(VECTOR_ELT(VECTOR_ELT(InputData,7),4),swcdataIndex);
	swcdataIndex++;

	p_lyrs = REAL(lyrs);
  //TODO: variable j is used as index but not incremented
	for (i = 0; i < MAX_DAYS * MAX_LAYERS; i++) {
		v->hist.swc[(int) (i / MAX_LAYERS)][(int) (j % MAX_LAYERS)] = p_lyrs[i + MAX_DAYS * MAX_LAYERS * 2];
		v->hist.std_err[(int) (i / MAX_LAYERS)][(int) (j % MAX_LAYERS)] = p_lyrs[i + MAX_DAYS * MAX_LAYERS * 3];
	}

}
Esempio n. 6
0
File: msg_sw.c Progetto: taysom/tau
int sw_post (const char *name, ki_t key)
{
	sw_msg_s	msg;
	int		rc;
	size_t		len;

	len = strnlen(name, TAU_NAME);
	if (len < TAU_NAME) ++len;
	msg.sw_name.nm_length = len;
	memcpy(msg.sw_name.nm_name, name, len);

	msg.sw_method = SW_POST;
	msg.q.q_passed_key = key;
	rc = send_key_tau(SW_STD_KEY, &msg);
	if (rc) return sw_error("send_key_tau", rc);

	return rc;
}
Esempio n. 7
0
File: msg_sw.c Progetto: taysom/tau
int sw_any (const char *name, ki_t *key)
{
	sw_msg_s	msg;
	int		rc;
	size_t		len;

	len = strnlen(name, TAU_NAME);
	if (len < TAU_NAME) ++len;
	msg.sw_name.nm_length = len;
	memcpy(msg.sw_name.nm_name, name, len);

	msg.sw_method  = SW_GET;
	msg.sw_request = SW_ALL;
	rc = call_tau(SW_STD_KEY, &msg);
	if (rc) return sw_error("call_tau", rc);

	*key = msg.q.q_passed_key;
	return rc;
}
Esempio n. 8
0
File: msg_sw.c Progetto: taysom/tau
int sw_next (const char *name, ki_t *key, u64 start, u64 *next)
{
	sw_msg_s	msg;
	int		rc;
	size_t		len;

	len = strnlen(name, TAU_NAME);
	if (len < TAU_NAME) ++len;
	msg.sw_name.nm_length = len;
	memcpy(msg.sw_name.nm_name, name, len);

	msg.sw_method = SW_NEXT;
	msg.sw_sequence = start;
	rc = call_tau(SW_STD_KEY, &msg);
	if (rc == DESTROYED) {
		*key = 0;
		return rc;
	}
	if (rc) return sw_error("call_tau", rc);

	*key  = msg.q.q_passed_key;
	*next = msg.sw_sequence;
	return rc;
}
SEXP onGet_SW_SWC_hist(TimeInt year) {
  sw_error(-1, "'onGet_SW_SWC_hist' is currently not functional.\n");

	int i, j = 0;
	SW_SOILWAT *v = &SW_Soilwat;
	SEXP swSWC_hist;
	SEXP hist;
	char *cSWC_hist[] = { "doy", "lyr", "swc", "st_err" };
	SEXP lyrs, lyrs_names, lyrs_names_y;
	RealD *p_lyrs;

	PROTECT(swSWC_hist = MAKE_CLASS("swSWC_hist"));
	PROTECT(hist = NEW_OBJECT(swSWC_hist));

	PROTECT(lyrs = allocMatrix(REALSXP, MAX_LAYERS*MAX_DAYS, 4));
	p_lyrs = REAL(lyrs);

  //TODO: variable j is used as index but not incremented
	for (i = 0; i < MAX_DAYS * MAX_LAYERS; i++) {
		p_lyrs[i + MAX_DAYS * MAX_LAYERS * 0] = (int) (i / MAX_LAYERS);
		p_lyrs[i + MAX_DAYS * MAX_LAYERS * 1] = (int) (j % MAX_LAYERS);
		p_lyrs[i + MAX_DAYS * MAX_LAYERS * 2] = v->hist.swc[(int) (i / MAX_LAYERS)][(int) (j % MAX_LAYERS)];
		p_lyrs[i + MAX_DAYS * MAX_LAYERS * 3] = v->hist.std_err[(int) (i / MAX_LAYERS)][(int) (j % MAX_LAYERS)];
	}
	PROTECT(lyrs_names = allocVector(VECSXP,2));
	PROTECT(lyrs_names_y = allocVector(STRSXP,4));
	for (i = 0; i < 4; i++)
		SET_STRING_ELT(lyrs_names_y, i, mkChar(cSWC_hist[i]));
	SET_VECTOR_ELT(lyrs_names, 1, lyrs_names_y);
	setAttrib(lyrs, R_DimNamesSymbol, lyrs_names);

	SET_SLOT(hist,install("data"),lyrs);

	UNPROTECT(5);
	return lyrs;
}
Esempio n. 10
0
void init_args(int argc, char **argv) {
	/* =================================================== */
	/* to add an option:
	 *  - include it in opts[]
	 *  - set a flag in valopts indicating no value (0),
	 *    value required (1), or value optional (-1),
	 *  - then tell us what to do in the switch statement
	 *
	 * 3/1/03 - cwb - Current options are
	 *                -d=chg to work dir <opt=dir_name>
	 *                -f=chg deflt first file <opt=file.in>
	 *                -q=quiet, don't print "Check logfile"
	 *                   at end of program.
	 */
	char str[1024];
	char const *opts[] = { "-d", "-f", "-e", "-q" }; /* valid options */
	int valopts[] = { 1, 1, 0, 0 }; /* indicates options with values */
	/* 0=none, 1=required, -1=optional */
	int i, /* looper through all cmdline arguments */
	a, /* current valid argument-value position */
	op, /* position number of found option */
	nopts = sizeof(opts) / sizeof(char *);

	/* Defaults */
	strcpy(_firstfile, DFLT_FIRSTFILE);
	QuietMode = EchoInits = swFALSE;

	a = 1;
	for (i = 1; i <= nopts; i++) {
		if (a >= argc)
			break;

		/* figure out which option by its position 0-(nopts-1) */
		for (op = 0; op < nopts; op++) {
			if (strncmp(opts[op], argv[a], 2) == 0)
				break; /* found it, move on */
		}
		if (op == nopts) {
      usage();
      sw_error(-1, "Invalid option %s\n", argv[a]);
		}

		*str = '\0';
		/* extract value part of option-value pair */
		if (valopts[op]) {
			if ('\0' != argv[a][2]) { /* no space betw opt-value */
				strcpy(str, (argv[a] + 2));

			} else if ('-' != *argv[a + 1]) { /* space betw opt-value */
				strcpy(str, argv[++a]);

			} else if (0 < valopts[op]) { /* required opt-val not found */
        usage();
        sw_error(-1, "Incomplete option %s\n", opts[op]);
			} /* opt-val not required */
		}

		/* tell us what to do here                   */
		/* set indicators/variables based on results */
		switch (op) {
		case 0: /* -d */
			if (!ChDir(str)) {
				LogError(logfp, LOGFATAL, "Invalid project directory (%s)", str);
			}
			break;
		case 1:
			strcpy(_firstfile, str);
			break; /* -f */
		case 2:
			EchoInits = swTRUE;
			break; /* -e */
		case 3:
			QuietMode = swTRUE;
			break; /* -q */
		default:
			LogError(logfp, LOGFATAL, "Programmer: bad option in main:init_args:switch");
		}

		a++; /* move to next valid arg-value position */

	} /* end for(i) */

}