31#if __has_include(<unistd.h>)
45#if defined(__APPLE__) && defined(__MACH__)
46#include <mach-o/dyld.h>
49#if defined(__FreeBSD__)
50#include <sys/sysctl.h>
57void FC_FUNC_(oct_mkdir, OCT_MKDIR)(STR_F_TYPE name STR_ARG1) {
61 TO_C_STR1(name, name_c);
65 if (
stat(name_c, &buf) == 0) {
80 STR_F_TYPE mod_time STR_ARG2) {
81 char *name_c, *mod_time_c;
86 TO_C_STR1(name, name_c);
87 *ierr =
stat(name_c, &statbuf);
90 mtime = statbuf.st_mtime;
91 timeinfo = localtime(&mtime);
92 mod_time_c = asctime(timeinfo);
95 mod_time_c = malloc(
sizeof(
char));
100 TO_F_STR2(mod_time_c, mod_time);
102 printf(
"ierr = %i\n", *ierr);
109int FC_FUNC_(oct_dir_exists, OCT_DIR_EXISTS)(STR_F_TYPE name STR_ARG1) {
114 TO_C_STR1(name, name_c);
115 ierr =
stat(name_c, &statbuf);
125void FC_FUNC_(oct_rm, OCT_RM)(STR_F_TYPE name STR_ARG1) {
128 TO_C_STR1(name, name_c);
133void FC_FUNC_(oct_getcwd, OCT_GETCWD)(STR_F_TYPE name STR_ARG1) {
139void FC_FUNC_(oct_realpath, OCT_REALPATH)(STR_F_TYPE fnam,
140 STR_F_TYPE rnam STR_ARG2) {
141 char *
fn = NULL, *rn = NULL;
143 rn = realpath(
fn, NULL);
154void FC_FUNC_(oct_dirname, OCT_DIRNAME)(STR_F_TYPE fnam,
155 STR_F_TYPE dnam STR_ARG2) {
156 char *
fn = NULL, *dn = NULL;
168void FC_FUNC_(oct_basename, OCT_BASENAME)(STR_F_TYPE fnam,
169 STR_F_TYPE bnam STR_ARG2) {
170 char *
fn = NULL, *bn = NULL;
182void FC_FUNC_(oct_getenv, OCT_GETENV)(STR_F_TYPE var,
183 STR_F_TYPE value STR_ARG2) {
184 char *name_c, *var_c;
186 TO_C_STR1(var, name_c);
187 var_c = getenv(name_c);
191 TO_F_STR2(var_c, value);
193 TO_F_STR2(
"", value);
199void FC_FUNC_(oct_wfs_list, OCT_WFS_LIST)(STR_F_TYPE str,
200 fint l[16384] STR_ARG1) {
202 char c[20], *c1, *str_c, *
s;
204 TO_C_STR1(str, str_c);
208 for (
i = 0;
i < 16384;
i++)
213 for (c1 = c; isdigit(*
s) || isspace(*
s);
s++)
221 for (c1 = c; isdigit(*
s) || isspace(*
s);
s++)
229 for (
i = i1;
i <= i2;
i++)
230 if (
i >= 0 &&
i < 16384)
262 *sec = (int)tv.tv_sec;
263 *usec = (
int)tv.tv_usec;
278double FC_FUNC_(oct_clock, OCT_CLOCK)() {
281 FC_FUNC_(oct_gettimeofday, OCT_GETTIMEOFDAY)(&sec, &usec);
282 return sec + 1.0e-6 * usec;
284 return (
double)
clock() / CLOCKS_PER_SEC;
293 req.tv_nsec = (long)*nsec;
294 nanosleep(&req, NULL);
298void FC_FUNC_(oct_sysname, OCT_SYSNAME)(STR_F_TYPE name STR_ARG1) {
302 TO_F_STR1(name_c, name);
307 OCT_NUMBER_OF_LINES)(STR_F_TYPE name STR_ARG1) {
313 TO_C_STR1(name, name_c);
314 pf = fopen(name_c,
"r");
319 while ((c = getc(pf)) != EOF) {
334 OCT_BREAK_C_STRING)(
char **str,
char **
s,
335 STR_F_TYPE line_f STR_ARG1) {
341 if (*
s == NULL || **
s ==
'\0') {
346 for (c = line; **
s !=
'\0' && **
s !=
'\n'; (*s)++, c++)
352 TO_F_STR1(line, line_f);
375 OCT_SEARCH_FILE_LR)(
double *freq,
const fint *tag,
fint *ierr,
376 STR_F_TYPE dirname STR_ARG1) {
382 char *num_start, *num_end;
383 double read_value, min;
384 int found_something, read_tag;
386 TO_C_STR1(dirname, name_c);
403 num_start = strchr(ent->d_name,
'_');
405 if (num_start != NULL) {
409 read_value = strtod(num_start, &num_end);
411 if (num_end == num_start)
415 if (num_end[0] ==
'_') {
417 num_start = num_end + 1;
418 read_tag = (int)strtol(num_start, &num_end, 10);
419 if (num_end == num_start)
421 if (read_tag != *tag)
428 if (!found_something) {
441 if (found_something) {
449#warning directory search not compiled
450 fprintf(
stderr,
"Warning: Directory search not available since certain C "
451 "functions are not available.\n");
456void *
FC_FUNC_(oct_get_memory_usage, OCT_GET_MEMORY_USAGE)() {
458 static size_t pagesize = 0;
468 sprintf(
s,
"%s%d%s",
"/proc/", pid,
"/statm");
469 if ((
f = fopen(
s,
"r")) == (
FILE *)NULL)
471 fscanf(
f,
"%lu", &mem);
474 return (
void *)(mem * pagesize);
482void FC_FUNC_(oct_executable_path, OCT_EXECUTABLE_PATH)(STR_F_TYPE fpath STR_ARG1) {
484#if defined(__APPLE__) && defined(__MACH__)
488 ret = _NSGetExecutablePath(buf, &bufsize);
490 buf = (
char *)malloc(bufsize);
492 ret = _NSGetExecutablePath(buf, &bufsize);
494 path = realpath(buf, NULL);
496#elif defined(linux) || defined(__linux)
497 path = realpath(
"/proc/self/exe", NULL);
498#elif defined(__NETBSD__) || defined(__NetBSD__)
499 path = realpath(
"/proc/curproc/exe", NULL);
500#elif defined(__DragonFly__)
501 path = realpath(
"/proc/curproc/file", NULL);
502#elif defined(__FreeBSD__)
503 int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
506 ret = sysctl(mib, 4, NULL, &len, NULL, 0);
509 assert(path != NULL);
510 ret = sysctl(mib, 4, path, &len, NULL, 0);
514 path = (
char *)malloc(1);
515 assert(path != NULL);
519 fprintf(
stderr,
"%s:%d: in %s: Something went wrong\n", __FILE__, __LINE__, __func__);
520 path = (
char *)malloc(1);
521 assert(path != NULL);
524 TO_F_STR1(path, fpath);
char * getcwd(char *__buf, size_t __size) __attribute__((__nothrow__
double fabs(double __x) __attribute__((__nothrow__
double fn(const gsl_vector *v, void *params)
real(real64) function s()
long int sysconf(int __name) __attribute__((__nothrow__
void FC_FUNC_(oct_mkdir, OCT_MKDIR)
int mkdir(const char *__path, __mode_t __mode) __attribute__((__nothrow__
int gettimeofday(struct timeval *__restrict __tv, void *__restrict __tz) __attribute__((__nothrow__
DIR DIR struct dirent * readdir(DIR *__dirp) __attribute__((__nonnull__(1)))
DIR * opendir(const char *__name) __attribute__((__nonnull__(1))) __attribute__((__malloc__)) __attribute__((__malloc__(closedir
int closedir(DIR *__dirp) __attribute__((__nonnull__(1)))
int stat(const char *__restrict __file, struct stat *__restrict __buf) __attribute__((__nothrow__
int fclose(FILE *__stream)
void progress_bar(int actual, int max)
static double f(double w, void *p)