コード例 #1
0
ファイル: main.c プロジェクト: aldatsa/Cinnamon
int
main (int argc, char **argv)
{
  GOptionContext *ctx;
  GError *error = NULL;
  int ecode;
  g_setenv ("CLUTTER_DISABLE_XINPUT", "1", TRUE);

  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  g_setenv ("GDK_SCALE", "1", TRUE);

  ctx = meta_get_option_context ();
  g_option_context_add_main_entries (ctx, gnome_cinnamon_options, GETTEXT_PACKAGE);
  if (!g_option_context_parse (ctx, &argc, &argv, &error))
    {
      g_printerr ("%s: %s\n", argv[0], error->message);
      exit (1);
    }

  g_option_context_free (ctx);

  meta_plugin_manager_set_plugin_type (gnome_cinnamon_plugin_get_type ());

  /* Prevent meta_init() from causing gtk to load gail and at-bridge */
  g_setenv ("NO_GAIL", "1", TRUE);
  g_setenv ("NO_AT_BRIDGE", "1", TRUE);
  meta_init ();
  g_unsetenv ("NO_GAIL");
  g_unsetenv ("NO_AT_BRIDGE");
  g_unsetenv ("CLUTTER_DISABLE_XINPUT");

  /* FIXME: Add gjs API to set this stuff and don't depend on the
   * environment.  These propagate to child processes.
   */
  g_setenv ("GJS_DEBUG_OUTPUT", "stderr", TRUE);
  g_setenv ("GJS_DEBUG_TOPICS", "JS ERROR;JS LOG", TRUE);

  g_setenv ("CINNAMON_VERSION", VERSION, TRUE);


  center_pointer_on_screen();

  cinnamon_dbus_init (meta_get_replace_current_wm ());
  cinnamon_a11y_init ();
  cinnamon_perf_log_init ();

  g_irepository_prepend_search_path (CINNAMON_PKGLIBDIR);
#if HAVE_BLUETOOTH
  g_irepository_prepend_search_path (BLUETOOTH_DIR);
#endif

  /* Disable debug spew from various libraries */
  g_log_set_handler ("Gvc", G_LOG_LEVEL_DEBUG,
                     muted_log_handler, NULL);
  g_log_set_handler ("AccountsService", G_LOG_LEVEL_DEBUG,
                     muted_log_handler, NULL);
  g_log_set_handler ("Bluetooth", G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_MESSAGE,
                     muted_log_handler, NULL);

  /* Initialize the global object */
  _cinnamon_global_init (NULL);

  queue_register_client ();

  g_unsetenv ("GDK_SCALE");

  ecode = meta_run ();

  if (g_getenv ("CINNAMON_ENABLE_CLEANUP"))
    {
      g_printerr ("Doing final cleanup...\n");
      g_object_unref (cinnamon_global_get ());
    }

  return ecode;
}
コード例 #2
0
ファイル: initialize.c プロジェクト: rafaelbordin/espresso
void on_integration_start()
{
  char *errtext;

  EVENT_TRACE(fprintf(stderr, "%d: on_integration_start\n", this_node));
  INTEG_TRACE(fprintf(stderr,"%d: on_integration_start: reinit_thermo = %d, resort_particles=%d\n",
		      this_node,reinit_thermo,resort_particles));

  /********************************************/
  /* sanity checks                            */
  /********************************************/

  if ( time_step < 0.0 ) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext, "{010 time_step not set} ");
  }
  if ( skin < 0.0 ) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext,"{011 skin not set} ");
  }
  if ( temperature < 0.0 ) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext,"{012 thermostat not initialized} ");
  }
  
#ifdef NPT
  if (integ_switch == INTEG_METHOD_NPT_ISO) {
    if (nptiso.piston <= 0.0) {
      char *errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{014 npt on, but piston mass not set} ");
    }
  
#ifdef ELECTROSTATICS

    switch(coulomb.method) {
    case COULOMB_NONE:  break;
#ifdef P3M
    case COULOMB_P3M:   break;
#endif /*P3M*/
    default: {
      char *errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{014 npt only works with P3M} ");
    }
    }
#endif /*ELECTROSTATICS*/

#ifdef DIPOLES

    switch (coulomb.Dmethod) {
    case DIPOLAR_NONE: break;
#ifdef DP3M
    case DIPOLAR_P3M: break;
#endif
    default: {
      char *errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"NpT does not work with your dipolar method, please use P3M.");
    }
    }
#endif  /* ifdef DIPOLES */
  }
#endif /*NPT*/

  if (!check_obs_calc_initialized()) return;

#ifdef LB
  if(lattice_switch & LATTICE_LB) {
    if (lbpar.agrid <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{098 Lattice Boltzmann agrid not set} ");
    }
    if (lbpar.tau <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{099 Lattice Boltzmann time step not set} ");
    }
    if (lbpar.rho <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{100 Lattice Boltzmann fluid density not set} ");
    }
    if (lbpar.viscosity <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{101 Lattice Boltzmann fluid viscosity not set} ");
    }
    if (dd.use_vList && skin>=lbpar.agrid/2.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext, "{104 LB requires either no Verlet lists or that the skin of the verlet list to be less than half of lattice-Boltzmann grid spacing.} ");
    }
  }
#endif
#ifdef LB_GPU
if(this_node == 0){
  if(lattice_switch & LATTICE_LB_GPU) {
    if (lbpar_gpu.agrid < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{098 Lattice Boltzmann agrid not set} ");
    }
    if (lbpar_gpu.tau < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{099 Lattice Boltzmann time step not set} ");
    }
    if (lbpar_gpu.rho < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{100 Lattice Boltzmann fluid density not set} ");
    }
    if (lbpar_gpu.viscosity < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{101 Lattice Boltzmann fluid viscosity not set} ");
    }
    if (lb_reinit_particles_gpu) {
	lb_realloc_particles_gpu();
	lb_reinit_particles_gpu = 0;
    }
  }
}

#endif

#ifdef METADYNAMICS
  meta_init();
#endif

#ifdef CATALYTIC_REACTIONS
if(reaction.ct_rate != 0.0) {

   if( dd.use_vList == 0 || cell_structure.type != CELL_STRUCTURE_DOMDEC) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{105 The CATALYTIC_REACTIONS feature requires verlet lists and domain decomposition} ");
      check_runtime_errors();
    }

  if(max_cut < reaction.range) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext,"{106 Reaction range of %f exceeds maximum cutoff of %f} ", reaction.range, max_cut);
  }
}
#endif

  /********************************************/
  /* end sanity checks                        */
  /********************************************/


  /* Prepare the thermostat */
  if (reinit_thermo) {
    thermo_init();
    reinit_thermo = 0;
    recalc_forces = 1;
  }

  /* Ensemble preparation: NVT or NPT */
  integrate_ensemble_init();

  /* Update particle and observable information for routines in statistics.c */
  invalidate_obs();
  freePartCfg();

  on_observable_calc();
}
コード例 #3
0
ファイル: main.c プロジェクト: SylvainGarrigues/freebsd
/*-
 * main --
 *	The main function, for obvious reasons. Initializes variables
 *	and a few modules, then parses the arguments give it in the
 *	environment and on the command line. Reads the system makefile
 *	followed by either Makefile, makefile or the file given by the
 *	-f argument. Sets the .MAKEFLAGS PMake variable based on all the
 *	flags it has received by then uses either the Make or the Compat
 *	module to create the initial list of targets.
 *
 * Results:
 *	If -q was given, exits -1 if anything was out-of-date. Else it exits
 *	0.
 *
 * Side Effects:
 *	The program exits when done. Targets are created. etc. etc. etc.
 */
int
main(int argc, char **argv)
{
	Lst targs;	/* target nodes to create -- passed to Make_Init */
	Boolean outOfDate = FALSE; 	/* FALSE if all targets up to date */
	struct stat sb, sa;
	char *p1, *path;
	char mdpath[MAXPATHLEN];
#ifdef FORCE_MACHINE
	const char *machine = FORCE_MACHINE;
#else
    	const char *machine = getenv("MACHINE");
#endif
	const char *machine_arch = getenv("MACHINE_ARCH");
	char *syspath = getenv("MAKESYSPATH");
	Lst sysMkPath;			/* Path of sys.mk */
	char *cp = NULL, *start;
					/* avoid faults on read-only strings */
	static char defsyspath[] = _PATH_DEFSYSPATH;
	char found_path[MAXPATHLEN + 1];	/* for searching for sys.mk */
	struct timeval rightnow;		/* to initialize random seed */
	struct utsname utsname;

	/* default to writing debug to stderr */
	debug_file = stderr;

#ifdef SIGINFO
	(void)bmake_signal(SIGINFO, siginfo);
#endif
	/*
	 * Set the seed to produce a different random sequence
	 * on each program execution.
	 */
	gettimeofday(&rightnow, NULL);
	srandom(rightnow.tv_sec + rightnow.tv_usec);
	
	if ((progname = strrchr(argv[0], '/')) != NULL)
		progname++;
	else
		progname = argv[0];
#if defined(MAKE_NATIVE) || (defined(HAVE_SETRLIMIT) && defined(RLIMIT_NOFILE))
	/*
	 * get rid of resource limit on file descriptors
	 */
	{
		struct rlimit rl;
		if (getrlimit(RLIMIT_NOFILE, &rl) != -1 &&
		    rl.rlim_cur != rl.rlim_max) {
			rl.rlim_cur = rl.rlim_max;
			(void)setrlimit(RLIMIT_NOFILE, &rl);
		}
	}
#endif

	if (uname(&utsname) == -1) {
	    (void)fprintf(stderr, "%s: uname failed (%s).\n", progname,
		strerror(errno));
	    exit(2);
	}

	/*
	 * Get the name of this type of MACHINE from utsname
	 * so we can share an executable for similar machines.
	 * (i.e. m68k: amiga hp300, mac68k, sun3, ...)
	 *
	 * Note that both MACHINE and MACHINE_ARCH are decided at
	 * run-time.
	 */
	if (!machine) {
#ifdef MAKE_NATIVE
	    machine = utsname.machine;
#else
#ifdef MAKE_MACHINE
	    machine = MAKE_MACHINE;
#else
	    machine = "unknown";
#endif
#endif
	}

	if (!machine_arch) {
#if defined(MAKE_NATIVE) && defined(HAVE_SYSCTL) && defined(CTL_HW) && defined(HW_MACHINE_ARCH)
	    static char machine_arch_buf[sizeof(utsname.machine)];
	    int mib[2] = { CTL_HW, HW_MACHINE_ARCH };
	    size_t len = sizeof(machine_arch_buf);
                
	    if (sysctl(mib, __arraycount(mib), machine_arch_buf,
		    &len, NULL, 0) < 0) {
		(void)fprintf(stderr, "%s: sysctl failed (%s).\n", progname,
		    strerror(errno));
		exit(2);
	    }

	    machine_arch = machine_arch_buf;
#else
#ifndef MACHINE_ARCH
#ifdef MAKE_MACHINE_ARCH
            machine_arch = MAKE_MACHINE_ARCH;
#else
	    machine_arch = "unknown";
#endif
#else
	    machine_arch = MACHINE_ARCH;
#endif
#endif
	}

	myPid = getpid();		/* remember this for vFork() */

	/*
	 * Just in case MAKEOBJDIR wants us to do something tricky.
	 */
	Var_Init();		/* Initialize the lists of variables for
				 * parsing arguments */
	Var_Set(".MAKE.OS", utsname.sysname, VAR_GLOBAL, 0);
	Var_Set("MACHINE", machine, VAR_GLOBAL, 0);
	Var_Set("MACHINE_ARCH", machine_arch, VAR_GLOBAL, 0);
#ifdef MAKE_VERSION
	Var_Set("MAKE_VERSION", MAKE_VERSION, VAR_GLOBAL, 0);
#endif
	Var_Set(".newline", "\n", VAR_GLOBAL, 0); /* handy for :@ loops */
	/*
	 * This is the traditional preference for makefiles.
	 */
#ifndef MAKEFILE_PREFERENCE_LIST
# define MAKEFILE_PREFERENCE_LIST "makefile Makefile"
#endif
	Var_Set(MAKEFILE_PREFERENCE, MAKEFILE_PREFERENCE_LIST,
		VAR_GLOBAL, 0);
	Var_Set(MAKE_DEPENDFILE, ".depend", VAR_GLOBAL, 0);

	create = Lst_Init(FALSE);
	makefiles = Lst_Init(FALSE);
	printVars = FALSE;
	debugVflag = FALSE;
	variables = Lst_Init(FALSE);
	beSilent = FALSE;		/* Print commands as executed */
	ignoreErrors = FALSE;		/* Pay attention to non-zero returns */
	noExecute = FALSE;		/* Execute all commands */
	noRecursiveExecute = FALSE;	/* Execute all .MAKE targets */
	keepgoing = FALSE;		/* Stop on error */
	allPrecious = FALSE;		/* Remove targets when interrupted */
	queryFlag = FALSE;		/* This is not just a check-run */
	noBuiltins = FALSE;		/* Read the built-in rules */
	touchFlag = FALSE;		/* Actually update targets */
	debug = 0;			/* No debug verbosity, please. */
	jobsRunning = FALSE;

	maxJobs = DEFMAXLOCAL;		/* Set default local max concurrency */
	maxJobTokens = maxJobs;
	compatMake = FALSE;		/* No compat mode */
	ignorePWD = FALSE;

	/*
	 * Initialize the parsing, directory and variable modules to prepare
	 * for the reading of inclusion paths and variable settings on the
	 * command line
	 */

	/*
	 * Initialize various variables.
	 *	MAKE also gets this name, for compatibility
	 *	.MAKEFLAGS gets set to the empty string just in case.
	 *	MFLAGS also gets initialized empty, for compatibility.
	 */
	Parse_Init();
	if (argv[0][0] == '/' || strchr(argv[0], '/') == NULL) {
	    /*
	     * Leave alone if it is an absolute path, or if it does
	     * not contain a '/' in which case we need to find it in
	     * the path, like execvp(3) and the shells do.
	     */
	    p1 = argv[0];
	} else {
	    /*
	     * A relative path, canonicalize it.
	     */
	    p1 = cached_realpath(argv[0], mdpath);
	    if (!p1 || *p1 != '/' || stat(p1, &sb) < 0) {
		p1 = argv[0];		/* realpath failed */
	    }
	}
	Var_Set("MAKE", p1, VAR_GLOBAL, 0);
	Var_Set(".MAKE", p1, VAR_GLOBAL, 0);
	Var_Set(MAKEFLAGS, "", VAR_GLOBAL, 0);
	Var_Set(MAKEOVERRIDES, "", VAR_GLOBAL, 0);
	Var_Set("MFLAGS", "", VAR_GLOBAL, 0);
	Var_Set(".ALLTARGETS", "", VAR_GLOBAL, 0);
	/* some makefiles need to know this */
	Var_Set(MAKE_LEVEL ".ENV", MAKE_LEVEL_ENV, VAR_CMD, 0);

	/*
	 * Set some other useful macros
	 */
	{
	    char tmp[64], *ep;

	    makelevel = ((ep = getenv(MAKE_LEVEL_ENV)) && *ep) ? atoi(ep) : 0;
	    if (makelevel < 0)
		makelevel = 0;
	    snprintf(tmp, sizeof(tmp), "%d", makelevel);
	    Var_Set(MAKE_LEVEL, tmp, VAR_GLOBAL, 0);
	    snprintf(tmp, sizeof(tmp), "%u", myPid);
	    Var_Set(".MAKE.PID", tmp, VAR_GLOBAL, 0);
	    snprintf(tmp, sizeof(tmp), "%u", getppid());
	    Var_Set(".MAKE.PPID", tmp, VAR_GLOBAL, 0);
	}
	if (makelevel > 0) {
		char pn[1024];
		snprintf(pn, sizeof(pn), "%s[%d]", progname, makelevel);
		progname = bmake_strdup(pn);
	}

#ifdef USE_META
	meta_init();
#endif
	/*
	 * First snag any flags out of the MAKE environment variable.
	 * (Note this is *not* MAKEFLAGS since /bin/make uses that and it's
	 * in a different format).
	 */
#ifdef POSIX
	p1 = explode(getenv("MAKEFLAGS"));
	Main_ParseArgLine(p1);
	free(p1);
#else
	Main_ParseArgLine(getenv("MAKE"));
#endif

	/*
	 * Find where we are (now).
	 * We take care of PWD for the automounter below...
	 */
	if (getcwd(curdir, MAXPATHLEN) == NULL) {
		(void)fprintf(stderr, "%s: getcwd: %s.\n",
		    progname, strerror(errno));
		exit(2);
	}

	MainParseArgs(argc, argv);

	if (enterFlag)
		printf("%s: Entering directory `%s'\n", progname, curdir);

	/*
	 * Verify that cwd is sane.
	 */
	if (stat(curdir, &sa) == -1) {
	    (void)fprintf(stderr, "%s: %s: %s.\n",
		 progname, curdir, strerror(errno));
	    exit(2);
	}

	/*
	 * All this code is so that we know where we are when we start up
	 * on a different machine with pmake.
	 * Overriding getcwd() with $PWD totally breaks MAKEOBJDIRPREFIX
	 * since the value of curdir can vary depending on how we got
	 * here.  Ie sitting at a shell prompt (shell that provides $PWD)
	 * or via subdir.mk in which case its likely a shell which does
	 * not provide it.
	 * So, to stop it breaking this case only, we ignore PWD if
	 * MAKEOBJDIRPREFIX is set or MAKEOBJDIR contains a transform.
	 */
#ifndef NO_PWD_OVERRIDE
	if (!ignorePWD) {
		char *pwd, *ptmp1 = NULL, *ptmp2 = NULL;

		if ((pwd = getenv("PWD")) != NULL &&
		    Var_Value("MAKEOBJDIRPREFIX", VAR_CMD, &ptmp1) == NULL) {
			const char *makeobjdir = Var_Value("MAKEOBJDIR",
			    VAR_CMD, &ptmp2);

			if (makeobjdir == NULL || !strchr(makeobjdir, '$')) {
				if (stat(pwd, &sb) == 0 &&
				    sa.st_ino == sb.st_ino &&
				    sa.st_dev == sb.st_dev)
					(void)strncpy(curdir, pwd, MAXPATHLEN);
			}
		}
		free(ptmp1);
		free(ptmp2);
	}
#endif
	Var_Set(".CURDIR", curdir, VAR_GLOBAL, 0);

	/*
	 * Find the .OBJDIR.  If MAKEOBJDIRPREFIX, or failing that,
	 * MAKEOBJDIR is set in the environment, try only that value
	 * and fall back to .CURDIR if it does not exist.
	 *
	 * Otherwise, try _PATH_OBJDIR.MACHINE, _PATH_OBJDIR, and
	 * finally _PATH_OBJDIRPREFIX`pwd`, in that order.  If none
	 * of these paths exist, just use .CURDIR.
	 */
	Dir_Init(curdir);
	(void)Main_SetObjdir(curdir);

	if ((path = Var_Value("MAKEOBJDIRPREFIX", VAR_CMD, &p1)) != NULL) {
		(void)snprintf(mdpath, MAXPATHLEN, "%s%s", path, curdir);
		(void)Main_SetObjdir(mdpath);
		free(p1);
	} else if ((path = Var_Value("MAKEOBJDIR", VAR_CMD, &p1)) != NULL) {
		(void)Main_SetObjdir(path);
		free(p1);
	} else {
		(void)snprintf(mdpath, MAXPATHLEN, "%s.%s", _PATH_OBJDIR, machine);
		if (!Main_SetObjdir(mdpath) && !Main_SetObjdir(_PATH_OBJDIR)) {
			(void)snprintf(mdpath, MAXPATHLEN, "%s%s", 
					_PATH_OBJDIRPREFIX, curdir);
			(void)Main_SetObjdir(mdpath);
		}
	}

	/*
	 * Initialize archive, target and suffix modules in preparation for
	 * parsing the makefile(s)
	 */
	Arch_Init();
	Targ_Init();
	Suff_Init();
	Trace_Init(tracefile);

	DEFAULT = NULL;
	(void)time(&now);

	Trace_Log(MAKESTART, NULL);
	
	/*
	 * Set up the .TARGETS variable to contain the list of targets to be
	 * created. If none specified, make the variable empty -- the parser
	 * will fill the thing in with the default or .MAIN target.
	 */
	if (!Lst_IsEmpty(create)) {
		LstNode ln;

		for (ln = Lst_First(create); ln != NULL;
		    ln = Lst_Succ(ln)) {
			char *name = (char *)Lst_Datum(ln);

			Var_Append(".TARGETS", name, VAR_GLOBAL);
		}
	} else
		Var_Set(".TARGETS", "", VAR_GLOBAL, 0);


	/*
	 * If no user-supplied system path was given (through the -m option)
	 * add the directories from the DEFSYSPATH (more than one may be given
	 * as dir1:...:dirn) to the system include path.
	 */
	if (syspath == NULL || *syspath == '\0')
		syspath = defsyspath;
	else
		syspath = bmake_strdup(syspath);

	for (start = syspath; *start != '\0'; start = cp) {
		for (cp = start; *cp != '\0' && *cp != ':'; cp++)
			continue;
		if (*cp == ':') {
			*cp++ = '\0';
		}
		/* look for magic parent directory search string */
		if (strncmp(".../", start, 4) != 0) {
			(void)Dir_AddDir(defIncPath, start);
		} else {
			if (Dir_FindHereOrAbove(curdir, start+4, 
			    found_path, sizeof(found_path))) {
				(void)Dir_AddDir(defIncPath, found_path);
			}
		}
	}
	if (syspath != defsyspath)
		free(syspath);

	/*
	 * Read in the built-in rules first, followed by the specified
	 * makefile, if it was (makefile != NULL), or the default
	 * makefile and Makefile, in that order, if it wasn't.
	 */
	if (!noBuiltins) {
		LstNode ln;

		sysMkPath = Lst_Init(FALSE);
		Dir_Expand(_PATH_DEFSYSMK,
			   Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath,
			   sysMkPath);
		if (Lst_IsEmpty(sysMkPath))
			Fatal("%s: no system rules (%s).", progname,
			    _PATH_DEFSYSMK);
		ln = Lst_Find(sysMkPath, NULL, ReadMakefile);
		if (ln == NULL)
			Fatal("%s: cannot open %s.", progname,
			    (char *)Lst_Datum(ln));
	}

	if (!Lst_IsEmpty(makefiles)) {
		LstNode ln;

		ln = Lst_Find(makefiles, NULL, ReadAllMakefiles);
		if (ln != NULL)
			Fatal("%s: cannot open %s.", progname, 
			    (char *)Lst_Datum(ln));
	} else {
	    p1 = Var_Subst(NULL, "${" MAKEFILE_PREFERENCE "}",
		VAR_CMD, VARF_WANTRES);
	    if (p1) {
		(void)str2Lst_Append(makefiles, p1, NULL);
		(void)Lst_Find(makefiles, NULL, ReadMakefile);
		free(p1);
	    }
	}

	/* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */
	if (!noBuiltins || !printVars) {
	    makeDependfile = Var_Subst(NULL, "${.MAKE.DEPENDFILE:T}",
		VAR_CMD, VARF_WANTRES);
	    doing_depend = TRUE;
	    (void)ReadMakefile(makeDependfile, NULL);
	    doing_depend = FALSE;
	}

	if (enterFlagObj)
		printf("%s: Entering directory `%s'\n", progname, objdir);
	
	MakeMode(NULL);

	Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL);
	free(p1);

	if (!forceJobs && !compatMake &&
	    Var_Exists(".MAKE.JOBS", VAR_GLOBAL)) {
	    char *value;
	    int n;

	    value = Var_Subst(NULL, "${.MAKE.JOBS}", VAR_GLOBAL, VARF_WANTRES);
	    n = strtol(value, NULL, 0);
	    if (n < 1) {
		(void)fprintf(stderr, "%s: illegal value for .MAKE.JOBS -- must be positive integer!\n",
		    progname);
		exit(1);
	    }
	    if (n != maxJobs) {
		Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL);
		Var_Append(MAKEFLAGS, value, VAR_GLOBAL);
	    }
	    maxJobs = n;
	    maxJobTokens = maxJobs;
	    forceJobs = TRUE;
	    free(value);
	}

	/*
	 * Be compatible if user did not specify -j and did not explicitly
	 * turned compatibility on
	 */
	if (!compatMake && !forceJobs) {
	    compatMake = TRUE;
	}

	if (!compatMake)
	    Job_ServerStart(maxJobTokens, jp_0, jp_1);
	if (DEBUG(JOB))
	    fprintf(debug_file, "job_pipe %d %d, maxjobs %d, tokens %d, compat %d\n",
		jp_0, jp_1, maxJobs, maxJobTokens, compatMake);

	Main_ExportMAKEFLAGS(TRUE);	/* initial export */

	/*
	 * For compatibility, look at the directories in the VPATH variable
	 * and add them to the search path, if the variable is defined. The
	 * variable's value is in the same format as the PATH envariable, i.e.
	 * <directory>:<directory>:<directory>...
	 */
	if (Var_Exists("VPATH", VAR_CMD)) {
		char *vpath, savec;
		/*
		 * GCC stores string constants in read-only memory, but
		 * Var_Subst will want to write this thing, so store it
		 * in an array
		 */
		static char VPATH[] = "${VPATH}";

		vpath = Var_Subst(NULL, VPATH, VAR_CMD, VARF_WANTRES);
		path = vpath;
		do {
			/* skip to end of directory */
			for (cp = path; *cp != ':' && *cp != '\0'; cp++)
				continue;
			/* Save terminator character so know when to stop */
			savec = *cp;
			*cp = '\0';
			/* Add directory to search path */
			(void)Dir_AddDir(dirSearchPath, path);
			*cp = savec;
			path = cp + 1;
		} while (savec == ':');
		free(vpath);
	}

	/*
	 * Now that all search paths have been read for suffixes et al, it's
	 * time to add the default search path to their lists...
	 */
	Suff_DoPaths();

	/*
	 * Propagate attributes through :: dependency lists.
	 */
	Targ_Propagate();

	/* print the initial graph, if the user requested it */
	if (DEBUG(GRAPH1))
		Targ_PrintGraph(1);

	/* print the values of any variables requested by the user */
	if (printVars) {
		LstNode ln;
		Boolean expandVars;

		if (debugVflag)
			expandVars = FALSE;
		else
			expandVars = getBoolean(".MAKE.EXPAND_VARIABLES", FALSE);
		for (ln = Lst_First(variables); ln != NULL;
		    ln = Lst_Succ(ln)) {
			char *var = (char *)Lst_Datum(ln);
			char *value;
			
			if (strchr(var, '$')) {
			    value = p1 = Var_Subst(NULL, var, VAR_GLOBAL,
						   VARF_WANTRES);
			} else if (expandVars) {
				char tmp[128];
								
				if (snprintf(tmp, sizeof(tmp), "${%s}", var) >= (int)(sizeof(tmp)))
					Fatal("%s: variable name too big: %s",
					      progname, var);
				value = p1 = Var_Subst(NULL, tmp, VAR_GLOBAL,
						       VARF_WANTRES);
			} else {
				value = Var_Value(var, VAR_GLOBAL, &p1);
			}
			printf("%s\n", value ? value : "");
			free(p1);
		}
	} else {
		/*
		 * Have now read the entire graph and need to make a list of
		 * targets to create. If none was given on the command line,
		 * we consult the parsing module to find the main target(s)
		 * to create.
		 */
		if (Lst_IsEmpty(create))
			targs = Parse_MainName();
		else
			targs = Targ_FindList(create, TARG_CREATE);

		if (!compatMake) {
			/*
			 * Initialize job module before traversing the graph
			 * now that any .BEGIN and .END targets have been read.
			 * This is done only if the -q flag wasn't given
			 * (to prevent the .BEGIN from being executed should
			 * it exist).
			 */
			if (!queryFlag) {
				Job_Init();
				jobsRunning = TRUE;
			}

			/* Traverse the graph, checking on all the targets */
			outOfDate = Make_Run(targs);
		} else {
			/*
			 * Compat_Init will take care of creating all the
			 * targets as well as initializing the module.
			 */
			Compat_Run(targs);
		}
	}

#ifdef CLEANUP
	Lst_Destroy(targs, NULL);
	Lst_Destroy(variables, NULL);
	Lst_Destroy(makefiles, NULL);
	Lst_Destroy(create, (FreeProc *)free);
#endif

	/* print the graph now it's been processed if the user requested it */
	if (DEBUG(GRAPH2))
		Targ_PrintGraph(2);

	Trace_Log(MAKEEND, 0);

	if (enterFlagObj)
		printf("%s: Leaving directory `%s'\n", progname, objdir);
	if (enterFlag)
		printf("%s: Leaving directory `%s'\n", progname, curdir);

#ifdef USE_META
	meta_finish();
#endif
	Suff_End();
        Targ_End();
	Arch_End();
	Var_End();
	Parse_End();
	Dir_End();
	Job_End();
	Trace_End();

	return outOfDate ? 1 : 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: prahal/gnome-shell
int
main (int argc, char **argv)
{
  GOptionContext *ctx;
  GError *error = NULL;
  int ecode;
  TpDebugSender *sender;

  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  session_mode = (char *) g_getenv ("GNOME_SHELL_SESSION_MODE");

  ctx = meta_get_option_context ();
  g_option_context_add_main_entries (ctx, gnome_shell_options, GETTEXT_PACKAGE);
  g_option_context_add_group (ctx, g_irepository_get_option_group ());
  if (!g_option_context_parse (ctx, &argc, &argv, &error))
    {
      g_printerr ("%s: %s\n", argv[0], error->message);
      exit (1);
    }

  g_option_context_free (ctx);

  meta_plugin_manager_set_plugin_type (gnome_shell_plugin_get_type ());

  meta_set_wm_name (WM_NAME);
  meta_set_gnome_wm_keybindings (GNOME_WM_KEYBINDINGS);

  meta_init ();

  /* FIXME: Add gjs API to set this stuff and don't depend on the
   * environment.  These propagate to child processes.
   */
  g_setenv ("GJS_DEBUG_OUTPUT", "stderr", TRUE);
  g_setenv ("GJS_DEBUG_TOPICS", "JS ERROR;JS LOG", TRUE);

  shell_init_debug (g_getenv ("SHELL_DEBUG"));

  shell_dbus_init (meta_get_replace_current_wm ());
  shell_a11y_init ();
  shell_perf_log_init ();
  shell_introspection_init ();
  shell_fonts_init ();

  /* Turn on telepathy-glib debugging but filter it out in
   * default_log_handler. This handler also exposes all the logs over D-Bus
   * using TpDebugSender. */
  tp_debug_set_flags ("all");

  sender = tp_debug_sender_dup ();

  g_log_set_default_handler (default_log_handler, sender);

  /* Initialize the global object */
  if (session_mode == NULL)
    session_mode = is_gdm_mode ? "gdm" : "user";

  _shell_global_init ("session-mode", session_mode, NULL);

  shell_prefs_init ();

  ecode = meta_run ();

  if (g_getenv ("GNOME_SHELL_ENABLE_CLEANUP"))
    {
      g_printerr ("Doing final cleanup...\n");
      g_object_unref (shell_global_get ());
    }

  g_object_unref (sender);

  return ecode;
}
コード例 #5
0
ファイル: main.c プロジェクト: Ak-/Cinnamon
int
main (int argc, char **argv)
{
  GOptionContext *ctx;
  GError *error = NULL;
  CinnamonSessionType session_type;
  int ecode;
  TpDebugSender *sender;

  g_type_init ();

  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  ctx = meta_get_option_context ();
  g_option_context_add_main_entries (ctx, gnome_cinnamon_options, GETTEXT_PACKAGE);
  if (!g_option_context_parse (ctx, &argc, &argv, &error))
    {
      g_printerr ("%s: %s\n", argv[0], error->message);
      exit (1);
    }

  g_option_context_free (ctx);

  meta_plugin_type_register (gnome_cinnamon_plugin_get_type ());

  /* Prevent meta_init() from causing gtk to load gail and at-bridge */
  g_setenv ("NO_GAIL", "1", TRUE);
  g_setenv ("NO_AT_BRIDGE", "1", TRUE);
  meta_init ();
  g_unsetenv ("NO_GAIL");
  g_unsetenv ("NO_AT_BRIDGE");

  /* FIXME: Add gjs API to set this stuff and don't depend on the
   * environment.  These propagate to child processes.
   */
  g_setenv ("GJS_DEBUG_OUTPUT", "stderr", TRUE);
  g_setenv ("GJS_DEBUG_TOPICS", "JS ERROR;JS LOG", TRUE);

  cinnamon_dbus_init (meta_get_replace_current_wm ());
  cinnamon_a11y_init ();
  cinnamon_perf_log_init ();
  cinnamon_prefs_init ();

  g_irepository_prepend_search_path (CINNAMON_PKGLIBDIR);
#if HAVE_BLUETOOTH
  g_irepository_prepend_search_path (BLUETOOTH_DIR);
#endif

  /* Disable debug spew from various libraries */
  g_log_set_handler ("Gvc", G_LOG_LEVEL_DEBUG,
                     muted_log_handler, NULL);
  g_log_set_handler ("AccountsService", G_LOG_LEVEL_DEBUG,
                     muted_log_handler, NULL);
  g_log_set_handler ("Bluetooth", G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_MESSAGE,
                     muted_log_handler, NULL);
  g_log_set_handler ("tp-glib/proxy", G_LOG_LEVEL_DEBUG,
                     muted_log_handler, NULL);

  /* Turn on telepathy-glib debugging but filter it out in
   * default_log_handler. This handler also exposes all the logs over D-Bus
   * using TpDebugSender. */
  tp_debug_set_flags ("all");

  sender = tp_debug_sender_dup ();
  g_log_set_default_handler (default_log_handler, sender);

  /* Initialize the global object */
  if (is_gdm_mode)
      session_type = CINNAMON_SESSION_GDM;
  else
      session_type = CINNAMON_SESSION_USER;

  _cinnamon_global_init ("session-type", session_type, NULL);

  ecode = meta_run ();

  if (g_getenv ("CINNAMON_ENABLE_CLEANUP"))
    {
      g_printerr ("Doing final cleanup...\n");
      g_object_unref (cinnamon_global_get ());
    }

  g_object_unref (sender);

  return ecode;
}
コード例 #6
0
ファイル: initialize.cpp プロジェクト: tojb/espresso
void on_integration_start()
{
  EVENT_TRACE(fprintf(stderr, "%d: on_integration_start\n", this_node));
  INTEG_TRACE(fprintf(stderr,"%d: on_integration_start: reinit_thermo = %d, resort_particles=%d\n",
		      this_node,reinit_thermo,resort_particles));

  /********************************************/
  /* sanity checks                            */
  /********************************************/

  integrator_sanity_checks();
#ifdef NPT
  integrator_npt_sanity_checks();
#endif
  interactions_sanity_checks();
#ifdef CATALYTIC_REACTIONS
  reactions_sanity_checks();
#endif
#ifdef LB
  if(lattice_switch & LATTICE_LB) {
    lb_sanity_checks();
  }
#endif
#ifdef LB_GPU
  if(lattice_switch & LATTICE_LB_GPU) {
    lb_GPU_sanity_checks();
  }
#endif

  /********************************************/
  /* end sanity checks                        */
  /********************************************/


#ifdef LB_GPU
  if(this_node == 0){
    if (lb_reinit_particles_gpu) {
      lb_realloc_particles_gpu();
      lb_reinit_particles_gpu = 0;
    }
  }
#endif

#ifdef CUDA
  if (reinit_particle_comm_gpu){
    gpu_change_number_of_part_to_comm();
    reinit_particle_comm_gpu = 0;
  }
  MPI_Bcast(gpu_get_global_particle_vars_pointer_host(), sizeof(CUDA_global_part_vars), MPI_BYTE, 0, comm_cart);
#endif

#ifdef METADYNAMICS
  meta_init();
#endif

  /* Prepare the thermostat */
  if (reinit_thermo) {
    thermo_init();
    reinit_thermo = 0;
    recalc_forces = 1;
  }

  /* Ensemble preparation: NVT or NPT */
  integrate_ensemble_init();

  /* Update particle and observable information for routines in statistics.cpp */
  invalidate_obs();
  freePartCfg();

  on_observable_calc();
}
コード例 #7
0
int tclcommand_metadynamics_parse_load_stat(Tcl_Interp *interp, int argc, char **argv){
  /* Parse free energy profile and biased force that were provided from an 
   * earlier simulation. Allows one to restart from a loaded state, and can 
   * even be used to allow multiple walkers communicating their data through TCL. */
  
  if(meta_switch == META_OFF) {
    Tcl_AppendResult(interp, "Metadynamics hasn't been initialized yet", (char *)NULL);
    return (TCL_ERROR);
  }
							       
  argc -= 1; argv += 1;
  
  // There should be
  if (argc != 3) {
    Tcl_AppendResult(interp, "Incorrect number of arguments: 'metadynamics load_stat <profile_list> <force_list>'", (char *)NULL);
    return (TCL_ERROR);
  }
							       
  // load free energy profile
  int i, tmp_argc, parse_error = 0, empty_line=0;
  char  **tmp_argv;
  DoubleList profile, force;
  
  init_doublelist(&profile);
  Tcl_ResetResult(interp);
  Tcl_SplitList(interp, argv[1], &tmp_argc, (const char ***)&tmp_argv);
  realloc_doublelist(&profile, profile.n = tmp_argc);
  //printf("profile.n %d, meta_xi_num_bins %d\n",profile.n,meta_xi_num_bins);
  /* Now check that the number of items parsed is equal to the number of bins */
  /* If there's one extra line, assume it's an empty line */
  if (profile.n == meta_xi_num_bins+1)
      empty_line = 1;
  else if (profile.n != meta_xi_num_bins) {
      Tcl_AppendResult(interp, "Size of profile list loaded is different than expected from number of bins", (char *)NULL);
      return (TCL_ERROR);
  }
  /* call meta_init() in case it has been loaded yet */
  meta_init();
  
  for(i = 0 ; i < tmp_argc-empty_line; i++) {
    int tmp_argc2;
    char  **tmp_argv2;
    Tcl_SplitList(interp, tmp_argv[i], &tmp_argc2, (const char ***)&tmp_argv2);
    if (tmp_argc2 != 1) {
      Tcl_AppendResult(interp, "data set has to be a list of doubles", (char *) NULL);
      parse_error = 1; break;
    }
    if (Tcl_GetDouble(interp, tmp_argv2[0], &(profile.e[i])) == TCL_ERROR) { parse_error = 1; break; }
    /* Load data into meta_acc_fprofile */
    meta_acc_fprofile[i] = profile.e[i];
    
    Tcl_Free((char *)tmp_argv2);
  }
  Tcl_Free((char *)tmp_argv);
  if (parse_error) return TCL_ERROR;   
 

  // load force
  argc -= 1; argv += 1;
  init_doublelist(&force);
  Tcl_ResetResult(interp);
  Tcl_SplitList(interp, argv[1], &tmp_argc, (const char ***)&tmp_argv);
  realloc_doublelist(&force, force.n = tmp_argc);
  /* Now check that the number of items parsed is equal to the number of bins */
  if (profile.n == meta_xi_num_bins+1)
      empty_line = 1;
  else if (profile.n != meta_xi_num_bins) {
    Tcl_AppendResult(interp, "Size of force list loaded is different than expected from number of bins", (char *)NULL);
    return (TCL_ERROR);
  }
  for(i = 0 ; i < tmp_argc-empty_line; i++) {
    int tmp_argc2;
    char  **tmp_argv2;
    Tcl_SplitList(interp, tmp_argv[i], &tmp_argc2, (const char ***)&tmp_argv2);
    if (tmp_argc2 != 1) {
      Tcl_AppendResult(interp, "data set has to be a list of doubles", (char *) NULL);
      parse_error = 1; break;
    }
    if (Tcl_GetDouble(interp, tmp_argv2[0], &(force.e[i])) == TCL_ERROR) { parse_error = 1; break; }
    /* Load data into meta_acc_fprofile */
    meta_acc_force[i] = -1.*force.e[i];
    
    Tcl_Free((char *)tmp_argv2);
  }
  Tcl_Free((char *)tmp_argv);
  if (parse_error) return TCL_ERROR;   

  return (TCL_OK);
}
コード例 #8
0
ファイル: initialize.c プロジェクト: mingyang/espresso
void on_integration_start()
{
  char *errtext;
  int i;

  EVENT_TRACE(fprintf(stderr, "%d: on_integration_start\n", this_node));
  INTEG_TRACE(fprintf(stderr,"%d: on_integration_start: reinit_thermo = %d, resort_particles=%d\n",
		      this_node,reinit_thermo,resort_particles));

  /********************************************/
  /* sanity checks                            */
  /********************************************/

  if ( time_step < 0.0 ) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext, "{010 time_step not set} ");
  }
  if ( skin < 0.0 ) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext,"{011 skin not set} ");
  }
  if ( temperature < 0.0 ) {
    errtext = runtime_error(128);
    ERROR_SPRINTF(errtext,"{012 thermostat not initialized} ");
  }

  for (i = 0; i < 3; i++)
    if (local_box_l[i] < max_range) {
      errtext = runtime_error(128 + TCL_INTEGER_SPACE);
      ERROR_SPRINTF(errtext,"{013 box_l in direction %d is still too small} ", i);
    }
  
#ifdef NPT
  if (integ_switch == INTEG_METHOD_NPT_ISO) {
    if (nptiso.piston <= 0.0) {
      char *errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{014 npt on, but piston mass not set} ");
    }
    if(cell_structure.type!=CELL_STRUCTURE_DOMDEC) {
      char *errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{014 npt requires domain decomposition cellsystem} ");
    }
  
#ifdef ELECTROSTATICS

    switch(coulomb.method) {
      case COULOMB_NONE:  break;
#ifdef ELP3M
      case COULOMB_P3M:   break;
#endif /*ELP3M*/
      case COULOMB_EWALD: break;
      default: {
        char *errtext = runtime_error(128);
        ERROR_SPRINTF(errtext,"{014 npt only works with Ewald sum or P3M} ");
      }
    }
#endif /*ELECTROSTATICS*/
  }
  
#endif /*NPT*/

  if (!check_obs_calc_initialized()) return;

#ifdef LB
  if(lattice_switch & LATTICE_LB) {
    if (lbpar.agrid <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{098 Lattice Boltzmann agrid not set} ");
    }
    if (lbpar.tau <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{099 Lattice Boltzmann time step not set} ");
    }
    if (lbpar.rho <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{100 Lattice Boltzmann fluid density not set} ");
    }
    if (lbpar.viscosity <= 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{101 Lattice Boltzmann fluid viscosity not set} ");
    }
  }
#endif
#ifdef LB_GPU
if(this_node == 0){
  if(lattice_switch & LATTICE_LB_GPU) {
    if (lbpar_gpu.agrid < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{098 Lattice Boltzmann agrid not set} ");
    }
    if (lbpar_gpu.tau < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{099 Lattice Boltzmann time step not set} ");
    }
    if (lbpar_gpu.rho < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{100 Lattice Boltzmann fluid density not set} ");
    }
    if (lbpar_gpu.viscosity < 0.0) {
      errtext = runtime_error(128);
      ERROR_SPRINTF(errtext,"{101 Lattice Boltzmann fluid viscosity not set} ");
    }
    if (lb_reinit_particles_gpu) {
	lb_realloc_particles_gpu();
	lb_reinit_particles_gpu = 0;
    }
  }
}

#endif

#ifdef METADYNAMICS
  meta_init();
#endif

  /********************************************/
  /* end sanity checks                        */
  /********************************************/


  /* Prepare the thermostat */
  if (reinit_thermo) {
    thermo_init();
    reinit_thermo = 0;
    recalc_forces = 1;
  }

  /* Ensemble preparation: NVT or NPT */
  integrate_ensemble_init();

  /* Update particle and observable information for routines in statistics.c */
  invalidate_obs();
  freePartCfg();

  on_observable_calc();
}
コード例 #9
0
ファイル: test-runner.c プロジェクト: whot/mutter
int
main (int argc, char **argv)
{
    GOptionContext *ctx;
    GError *error = NULL;

    /* First parse the arguments that are passed to us */

    ctx = g_option_context_new (NULL);
    g_option_context_add_main_entries (ctx, options, NULL);

    if (!g_option_context_parse (ctx,
                                 &argc, &argv, &error))
    {
        g_printerr ("%s", error->message);
        return 1;
    }

    g_option_context_free (ctx);

    GPtrArray *tests = g_ptr_array_new ();

    if (all_tests)
    {
        GFile *test_dir = g_file_new_for_path (MUTTER_PKGDATADIR "/tests");

        if (!find_metatests_in_directory (test_dir, tests, &error))
        {
            g_printerr ("Error enumerating tests: %s\n", error->message);
            return 1;
        }
    }
    else
    {
        int i;
        char *curdir = g_get_current_dir ();

        for (i = 1; i < argc; i++)
        {
            if (g_path_is_absolute (argv[i]))
                g_ptr_array_add (tests, g_strdup (argv[i]));
            else
                g_ptr_array_add (tests, g_build_filename (curdir, argv[i], NULL));
        }

        g_free (curdir);
    }

    /* Then initalize mutter with a different set of arguments */

    char *fake_args[] = { NULL, (char *)"--wayland" };
    fake_args[0] = argv[0];
    char **fake_argv = fake_args;
    int fake_argc = 2;

    char *basename = g_path_get_basename (argv[0]);
    char *dirname = g_path_get_dirname (argv[0]);
    if (g_str_has_prefix (basename, "lt-"))
        test_client_path = g_build_filename (dirname, "../mutter-test-client", NULL);
    else
        test_client_path = g_build_filename (dirname, "mutter-test-client", NULL);
    g_free (basename);
    g_free (dirname);

    ctx = meta_get_option_context ();
    if (!g_option_context_parse (ctx, &fake_argc, &fake_argv, &error))
    {
        g_printerr ("mutter: %s\n", error->message);
        exit (1);
    }
    g_option_context_free (ctx);

    meta_plugin_manager_load ("default");

    meta_init ();
    meta_register_with_session ();

    RunTestsInfo info;
    info.tests = (char **)tests->pdata;
    info.n_tests = tests->len;

    g_idle_add (run_tests, &info);

    return meta_run ();
}
コード例 #10
0
ファイル: pta.c プロジェクト: DavinSimmons/ASF_MapReady
int main(int argc, char *argv[])
{
  char szImg[255], szImage[255], buffer[1000], crID[10], szCrList[255], szOut[255];
  int ii, kk, size, bigSize=oversampling_factor*srcSize;
  int mainlobe_azimuth_min, mainlobe_azimuth_max, mainlobe_range_min;
  int mainlobe_range_max, sidelobe_azimuth_min, sidelobe_azimuth_max;
  int sidelobe_range_min, sidelobe_range_max, peak_line, peak_sample;
  float azimuth_processing_bandwidth, chirp_rate, pulse_duration, sampling_rate;
  float prf, srcPeakX, srcPeakY, bigPeakX, bigPeakY, clutter_power, peak_power, scr;
  float azimuth_resolution, range_resolution, azimuth_pslr, range_pslr;
  float azimuth_window_size, range_window_size;
  float azimuth_profile[bigSize], range_profile[bigSize];
  static complexFloat *s, *t;
  double lat, lon, elev, posX, posY, look_angle;
  FILE *fpIn, *fpOut, *fp, *fpText;
  meta_parameters *meta, *meta_debug;
  float *original_amplitude, *amplitude, *phase;
  fcpx *src_fft, *trg_fft;
  int debug=FALSE;
  char *text=NULL;
  int overwrite=FALSE;

  if (argc==1) usage();
  if (strcmp(argv[1],"-help")==0) help_page(); /* exits program */
  if (strcmp(argv[1],"-overwrite")==0) overwrite=TRUE;

  int required_args = 4;
  if (overwrite) ++required_args;

  if(argc != required_args)
    usage();/*This exits with a failure*/
  
  /* Fetch required arguments */
  strcpy(szImg, argv[argc - 3]);
  strcpy(szCrList,argv[argc - 2]);
  strcpy(szOut,argv[argc - 1]);

  /* DEFAULT VALUES:
     size of region to oversample - 64 pixels	
     mainlobe width factor - 2.6
     sidelobe width factor - 20.0
     maximum oversampling factor - 8
  */

  // Read metadata
  sprintf(szImage, "%s.img", szImg);
  meta = meta_read(szImage);
  lines = meta->general->line_count;
  samples = meta->general->sample_count;
  text = (char *) MALLOC(255*sizeof(char));

  // Handle input and output file
  fpIn = FOPEN(szCrList, "r");
  fpOut = FOPEN(szOut, "w");
  fprintf(fpOut, "POINT TARGET ANALYSIS RESULTS\n\n");
  fprintf(fpOut, "CR\tLat\tLon\tElev\tAz peak\tRng peak\tLook\t"
	  "Az res\tRng res\tAz PSLR\tRng PSLR\tSCR\n");
  // RCS needs some more coding
  
  // Loop through corner reflector location file
  while (fgets(buffer, 1000, fpIn))
  {
    if (overwrite) {
      sscanf(buffer, "%s\t%lf\t%lf", crID, &posY, &posX);
      printf("  %s: posX = %.2lf, posY = %.2lf\n", crID, posX, posY);
    }
    else {
      sscanf(buffer, "%s\t%lf\t%lf\t%lf", crID, &lat, &lon, &elev);
      meta_get_lineSamp(meta, lat, lon, elev, &posY, &posX);
      printf("  %s: lat = %.4lf, lon = %.4lf, posX = %.2lf, posY = %.2lf\n", 
	     crID, lat, lon, posX, posY);
    }
	  
    // Check bounds - Get average spectra from chip in range direction
    if (!(outOfBounds(posX, posY, srcSize)))
      {
	
	// READ SUBSET FROM THE IMAGE WITH CORNER REFLECTOR IN THE CENTER
	size = srcSize*srcSize*sizeof(float);
	original_amplitude = (float *) MALLOC(size);
	phase = (float *) MALLOC(size);
	s = (complexFloat *) MALLOC(2*size);
	readComplexSubset(szImage, srcSize, srcSize, posX-srcSize/2, 
			  posY-srcSize/2, s);
	my_complex2polar(s, srcSize, srcSize, original_amplitude, phase);

	if (debug) { // Store original image for debugging
	  fp = FOPEN("original.img", "wb");
	  size = bigSize*bigSize*sizeof(float);
	  FWRITE(original_amplitude, size, 1, fp);
	  FCLOSE(fp);
	  meta_debug = meta_init(szImage);
	  meta_debug->general->line_count = 
	    meta_debug->general->sample_count = srcSize;
	  meta_debug->general->data_type = REAL32;
	  meta_debug->general->start_line = posY-srcSize/2;
	  meta_debug->general->start_sample = posX-srcSize/2;
	  meta_debug->general->center_latitude = lat;
	  meta_debug->general->center_longitude = lon;
	  meta_write(meta_debug, "original.meta");
	  meta_free(meta_debug);
	}

	// Find amplitude peak in original image chip
	if (!findPeak(original_amplitude, srcSize, &srcPeakX, &srcPeakY)) {
	  fprintf(fpOut, 
		  "   Could not find amplitude peak in original image chip!\n");
	  goto SKIP;
	}

	// Cut out the subset again around the peak to make sure we have data for
	// the analysis
	readComplexSubset(szImage, srcSize, srcSize, posX-srcSize+srcPeakY, 
			  posY-srcSize+srcPeakX, s);
	my_complex2polar(s, srcSize, srcSize, original_amplitude, phase);
	FREE(phase);
	findPeak(original_amplitude, srcSize, &srcPeakX, &srcPeakY);

	// Determine look angle
	look_angle = 
	  meta_look(meta, srcSize/2, srcSize/2);

	/****************************
        - special ScanSAR case: images are "projected" - need to be rotated back to
          allow analysis in azimuth and range direction (ss_extract.c)
	*********************/

	// BASEBAND THE DATA IN EACH DIMENSION IN THE FREQUENCY DOMAIN

	// Oversample image
	src_fft = forward_fft(s, srcSize, srcSize);
	trg_fft = oversample(src_fft, srcSize, oversampling_factor);

	// Determine azimuth and range window size
	azimuth_processing_bandwidth = 
	  (float) meta->sar->azimuth_processing_bandwidth;
	prf = (float) meta->sar->prf;
	chirp_rate = (float) meta->sar->chirp_rate;
	pulse_duration = (float) meta->sar->pulse_duration;
	sampling_rate = (float) meta->sar->range_sampling_rate;
	azimuth_window_size = azimuth_processing_bandwidth / prf;
	range_window_size = fabs(chirp_rate) * pulse_duration / sampling_rate;
	printf("azimuth window size: %.2f, range window size: %.2f\n",
	       azimuth_window_size, range_window_size);
	asfRequire(azimuth_window_size > 0.0 && azimuth_window_size < 1.0,
		   "azimuth window size out of range (0 to 1)!\n");
	asfRequire(range_window_size > 0.0 && range_window_size < 1.0,
		   "range window size out of range (0 to 1)!\n");
	if (range_window_size < 0.5)
	  range_window_size = 0.5;

	// for ScanSAR both 0.5
	// run debugger to check units are correct!

	// Baseband image in range direction
	//baseband(src_fft, range_window_size);

	/*
	// Transpose matrix to work in azimuth direction
	//transpose(s);

	// Baseband image in azimuth direction
	//	   baseband(s, azimuth_window_size);

	// Transpose matrix back into original orientation
	//transpose(s);

	*/
	t = inverse_fft(trg_fft, bigSize, bigSize);
	amplitude = (float *) MALLOC(sizeof(float)*bigSize*bigSize);
	phase = (float *) MALLOC(sizeof(float)*bigSize*bigSize);
	my_complex2polar(t, bigSize, bigSize, amplitude, phase);
	FREE(phase);

	if (debug) { // Store oversampled image for debugging
	  fp = FOPEN("oversample.img", "wb");
	  size = bigSize*bigSize*sizeof(float);
	  FWRITE(amplitude, size, 1, fp);
	  FCLOSE(fp);
	  meta_debug = meta_init("oversample.meta");
	  meta_debug->general->line_count = 
	    meta_debug->general->sample_count = bigSize;
	  meta_debug->general->data_type = REAL32;
	  meta_write(meta_debug, "oversample.meta");
	  meta_free(meta_debug);
	}

	// Find the amplitude peak in oversampled image
	if (!findPeak(amplitude, bigSize, &bigPeakX, &bigPeakY)) {
	  fprintf(fpOut, 
		  "   Could not find amplitude peak in oversampled image chip!\n");
	  goto SKIP;
	}
	peak_line = (int)(bigPeakX + 0.5);
	peak_sample = (int)(bigPeakY + 0.5);

	// Write text version of oversampled image
	sprintf(text, "%s_%s_chip.txt", szImg, crID);
	fpText = FOPEN(text, "w");
	for (ii=peak_line-32; ii<peak_line+32; ii++) {
	  for (kk=peak_sample-32; kk<peak_sample+32; kk++)
	    fprintf(fpText, "%12.4f\t", amplitude[ii*bigSize+kk]);
	  fprintf(fpText, "\n");
	}
	FCLOSE(fpText);

	// EXTRACTING PROFILES IN AZIMUTH AND RANGE THROUGH PEAK
	for (ii=0; ii<bigSize; ii++) {
	  azimuth_profile[ii] = amplitude[ii*bigSize+peak_sample];
	  range_profile[ii] = amplitude[bigSize*peak_line+ii];
	}

	sprintf(text, "%s_%s_azimuth.txt", szImg, crID);
	fp = FOPEN(text, "w");
	fprintf(fp, "Azimuth profile\n");
	for (ii=0; ii<bigSize; ii++)
	  fprintf(fp, "%.3f\n", azimuth_profile[ii]);
	FCLOSE(fp);
	sprintf(text, "%s_%s_range.txt", szImg, crID);
	fp = FOPEN(text, "w");
	fprintf(fp, "Range profile\n");
	for (ii=0; ii<bigSize; ii++)
	  fprintf(fp, "%.3f\n", range_profile[ii]);
	FCLOSE(fp);

        // FINALLY GET TO THE IMAGE QUALITY PARAMETERS
	clutter_power = 0.0;	

	// Find main lobes in oversampled image
	if (!find_mainlobe(amplitude, azimuth_profile, bigSize, peak_line, 
			   clutter_power, &mainlobe_azimuth_min, 
			   &mainlobe_azimuth_max)) {
	  fprintf(fpOut, "   No mainlobes could be found for %s in azimuth!\n", 
		  crID);
	  goto SKIP;
	}
	//printf("mainlobe azimuth: min = %d, max = %d\n", 
	//       mainlobe_azimuth_min, mainlobe_azimuth_max);
	if (!find_mainlobe(amplitude, range_profile, bigSize, peak_sample, 
			   clutter_power, &mainlobe_range_min, 
			   &mainlobe_range_max)) {
	  fprintf(fpOut, "   No mainlobes could be found for %s in range!\n", crID);
	  goto SKIP;
	}
	//printf("mainlobe range: min = %d, max = %d\n", 
	//       mainlobe_range_min, mainlobe_range_max);

	// Calculate resolution in azimuth and range for profiles 
	if (!calc_resolution(azimuth_profile, mainlobe_azimuth_min, 
			     mainlobe_azimuth_max, peak_line, 
			     meta->general->y_pixel_size, clutter_power, 
			     &azimuth_resolution))
	  fprintf(fpOut, "   Negative azimuth resolution for %s - invalid result!"
		  "\n", crID);
	//printf("azimuth resolution = %.2f\n", azimuth_resolution);
	if (!calc_resolution(range_profile, mainlobe_range_min, 
			     mainlobe_range_max, peak_sample, 
			     meta->general->x_pixel_size, clutter_power, 
			     &range_resolution))
	  fprintf(fpOut, "   Negative range resolution for %s - invalid result!\n",
		  crID);
	//printf("range resolution = %.2f\n", range_resolution);

	// Find peak of original data - thought we had that already: check !!! 

	// Calculate the clutter power
	azimuth_resolution /= meta->general->x_pixel_size;
	range_resolution /= meta->general->y_pixel_size;
	clutter_power = 
	  calc_clutter_power(original_amplitude, srcSize, peak_sample, peak_line, 
			     azimuth_resolution, range_resolution);
	//printf("   Clutter power:      %8.3f\n", clutter_power);

	// Calculate resolution in azimuth and range with estimated clutter power
	if (!calc_resolution(azimuth_profile, mainlobe_azimuth_min, 
			     mainlobe_azimuth_max, peak_line, 
			     meta->general->y_pixel_size, clutter_power, 
			     &azimuth_resolution))
	  fprintf(fpOut, "   Negative azimuth resolution for %s - invalid result!"
		  "\n", crID);
	if (!calc_resolution(range_profile, mainlobe_range_min, 
			     mainlobe_range_max, peak_sample, 
			     meta->general->x_pixel_size, clutter_power, 
			     &range_resolution))
	  fprintf(fpOut, "   Negative range resolution for %s - invalid result!\n",
		  crID);
	//printf("   Azimuth resolution: %.3f\n", azimuth_resolution);
	//printf("   Range resolution: %.3f\n", range_resolution);

	// Find sidelobes in oversampled image and calculate the point-to-sidelobe
	// ratio in azimuth and range direction
	if (find_sidelobe(azimuth_profile, bigSize, 1, peak_line, 
			  mainlobe_azimuth_max, &sidelobe_azimuth_max) &&
	    find_sidelobe(azimuth_profile, bigSize, -1, peak_line, 
			  mainlobe_azimuth_min, &sidelobe_azimuth_min)) {
	  if (!calc_pslr(azimuth_profile, bigSize, peak_line, sidelobe_azimuth_min, 
			 sidelobe_azimuth_max, &azimuth_pslr))
	    //printf("   Azimuth PSLR: %.3f\n", azimuth_pslr);
	    //printf("   No valid PSLR in azimuth could be determined!\n");
	    ;
	}
	else {
	  fprintf(fpOut, "   Problem in finding sidelobes for %s in azimuth - "
		  "invalid PSLR!\n", crID);
	}
	if (find_sidelobe(range_profile, bigSize, 1, peak_sample, 
			  mainlobe_range_max, &sidelobe_range_max) &&
	    find_sidelobe(range_profile, bigSize, -1, peak_sample, 
			  mainlobe_range_min, &sidelobe_range_min)) {
	  if (!calc_pslr(range_profile, bigSize, peak_sample, sidelobe_range_min, 
			 sidelobe_range_max, &range_pslr))
	    //printf("   Range PSLR: %.3f\n", range_pslr);
	    //printf("   No valid PSLR in range could be determined!\n");
	    ;
	}
	else {
	  fprintf(fpOut, "   Problem in finding sidelobes for %s in range -"
		  " invalid PSLR!\n", crID);
	}
	//printf("sidelobe_azimuth: min = %d, max = %d\n",
	//       sidelobe_azimuth_min, sidelobe_azimuth_max);
	//printf("sidelobe_range: min = %d, max = %d\n",
	//       sidelobe_range_min, sidelobe_range_max);

	// Calculate the signal-to-clutter ratio (SCR)
	peak_power = amplitude[peak_line*bigSize+peak_sample] * 
	  amplitude[peak_line*bigSize+peak_sample];
	if (clutter_power>0 && peak_power>clutter_power)
	  scr = 10 * log((peak_power - clutter_power)/clutter_power);
	else 
	  scr = 0.0;
	if (peak_power > 0.0) {
	  peak_power = 10 * log(peak_power);
	  //printf("   Peak power: %.3f\n", peak_power);
	  //printf("   SCR: %.3f\n", scr);
	}
	else 
	  fprintf(fpOut, "   Negative peak power - invalid result!\n");

	FREE(amplitude);
	FREE(original_amplitude);

	// Write values in output files
	fprintf(fpOut, "%s\t%.4lf\t%.4lf\t%.1lf\t%.1lf\t%.1f\t%.3f\t"
		"%.3f\t%.3f\t%.3f\t%.3f\t%.3f\n",
		crID, lat, lon, elev, posX-srcSize+srcPeakY, posY-srcSize+srcPeakX,
		look_angle*R2D, azimuth_resolution, range_resolution, azimuth_pslr, 
		range_pslr, scr);

      SKIP: continue;
      }
    else 
      fprintf(fpOut, "\n   WARNING: Target %s outside the image boundaries!\n", 
	      crID);
  }
  FCLOSE(fpIn);
  FCLOSE(fpOut);
  FREE(meta);

  return(0);
}