Example #1
0
/*
 * Look for and handle any -mca options on the command line
 */
int pmix_mca_base_cmd_line_process_args(pmix_cmd_line_t *cmd,
                                        char ***context_env, char ***global_env)
{
    int i, num_insts, rc;
    char **params;
    char **values;

    /* If no relevant parameters were given, just return */

    if (!pmix_cmd_line_is_taken(cmd, PMIX_MCA_CMD_LINE_ID) &&
        !pmix_cmd_line_is_taken(cmd, "g"PMIX_MCA_CMD_LINE_ID)) {
        return PMIX_SUCCESS;
    }

    /* Handle app context-specific parameters */

    num_insts = pmix_cmd_line_get_ninsts(cmd, PMIX_MCA_CMD_LINE_ID);
    params = values = NULL;
    for (i = 0; i < num_insts; ++i) {
        if (PMIX_SUCCESS != (rc = process_arg(pmix_cmd_line_get_param(cmd, PMIX_MCA_CMD_LINE_ID, i, 0),
                                              pmix_cmd_line_get_param(cmd, PMIX_MCA_CMD_LINE_ID, i, 1),
                                              &params, &values))) {
            return rc;
        }
    }
    if (NULL != params) {
        add_to_env(params, values, context_env);
        pmix_argv_free(params);
        pmix_argv_free(values);
    }

    /* Handle global parameters */

    num_insts = pmix_cmd_line_get_ninsts(cmd, "g"PMIX_MCA_CMD_LINE_ID);
    params = values = NULL;
    for (i = 0; i < num_insts; ++i) {
        if (PMIX_SUCCESS != (rc = process_arg(pmix_cmd_line_get_param(cmd, "g"PMIX_MCA_CMD_LINE_ID, i, 0),
                                              pmix_cmd_line_get_param(cmd, "g"PMIX_MCA_CMD_LINE_ID, i, 1),
                                              &params, &values))) {
            return rc;
        }
    }
    if (NULL != params) {
        add_to_env(params, values, global_env);
        pmix_argv_free(params);
        pmix_argv_free(values);
    }

    /* All done */

    return PMIX_SUCCESS;
}
Example #2
0
/*
 * Look for and handle any -mca options on the command line
 */
int mca_base_cmd_line_process_args(opal_cmd_line_t *cmd,
                                   char ***context_env, char ***global_env)
{
    int i, num_insts;
    char **params;
    char **values;

    /* If no relevant parameters were given, just return */

    if (!opal_cmd_line_is_taken(cmd, "mca") &&
            !opal_cmd_line_is_taken(cmd, "gmca")) {
        return OPAL_SUCCESS;
    }

    /* Handle app context-specific parameters */

    num_insts = opal_cmd_line_get_ninsts(cmd, "mca");
    params = values = NULL;
    for (i = 0; i < num_insts; ++i) {
        process_arg(opal_cmd_line_get_param(cmd, "mca", i, 0),
                    opal_cmd_line_get_param(cmd, "mca", i, 1),
                    &params, &values);
    }
    if (NULL != params) {
        add_to_env(params, values, context_env);
        opal_argv_free(params);
        opal_argv_free(values);
    }

    /* Handle global parameters */

    num_insts = opal_cmd_line_get_ninsts(cmd, "gmca");
    params = values = NULL;
    for (i = 0; i < num_insts; ++i) {
        process_arg(opal_cmd_line_get_param(cmd, "gmca", i, 0),
                    opal_cmd_line_get_param(cmd, "gmca", i, 1),
                    &params, &values);
    }
    if (NULL != params) {
        add_to_env(params, values, global_env);
        opal_argv_free(params);
        opal_argv_free(values);
    }

    /* All done */

    return OPAL_SUCCESS;
}
Example #3
0
int main(int argc, char* argv[])
{
    process_arg(argc,argv);
    tcpudp_fd=open_socket();
    assert(tcpudp_fd>0);
    if(server)
        server_accept(NULL);
    tun_fd=tun_alloc(tun_name,IFF_TAP);
    assert(tun_fd>0);
    get_macaddr();
    write_n(tcpudp_fd,tun_mac,6);
    getack();
    if(pthread_create(&pt_read_from_if,NULL,read_from_if,NULL)!=0){
        perror("pthread_create");
        exit(-1);
    }
    if(pthread_create(&pt_read_from_sock,NULL,read_from_sock,NULL)!=0){
        perror("pthread_create");
        exit(-1);
    }
    printf("engin started, main() going to sleep\n");
    pthread_join(pt_read_from_if,NULL);
    pthread_join(pt_read_from_sock,NULL);
    return 0;
}
Example #4
0
void				prog_parse_args(t_prog *prog, char **argv)
{
	char			getopt_c;

	g_twl_optsign_active = true;
	while ((getopt_c = twl_getopt(twl_arr_len(argv), argv,
		FTSH_VALID_ALL_OPTS)) > 0)
	{
		if (getopt_c == '?')
		{
			print_help(g_twl_optopt);
			shenv_utils_exit(2);
		}
		else
		{
			process_arg(prog, g_twl_optsign, getopt_c, g_twl_optarg);
		}
	}
	if (g_twl_optind < (int)twl_arr_len(argv))
		shenv_singleton()->shenv_argv_remainder = twl_arr_to_lst(argv
			+ g_twl_optind);
	else
		shenv_singleton()->shenv_argv_remainder = twl_lst_new();
	g_twl_optind = 0;
	g_twl_optsign_active = false;
}
Example #5
0
static int process_arglist(int argc, char **argv)
{
    int option;
    int count = 0;

    fpin = stdin;
    fpo  = stdout;
    dbgout = stderr;

#ifdef __EMX__
    _response (&argc, &argv);	/* expand response files (@filename) */
    _wildcard (&argc, &argv);	/* expand wildcards (*.*) */
#endif

    /* default: no token length checking */
    max_token_len = 0;

    while (1)
    {
	int option_index = 0;
	int this_option_optind = optind ? optind : 1;
	const char *name;

	option = getopt_long_chk(argc, argv, OPTIONS,
			     longopts_bogoutil, &option_index);

	if (option == -1)
 	    break;

	name = (option_index == 0) ? argv[this_option_optind] : longopts_bogoutil[option_index].name;
	count += process_arg(option, name, optarg, PR_NONE, PASS_1_CLI);
    }

    if (max_token_len != 0 && max_multi_token_len == 0) {
	/* token length checking ... */
	if (multi_token_count == 1)
	    max_multi_token_len = max_token_len + MAX_PREFIX_LEN;
	else
	    max_multi_token_len = max_token_len = (max_token_len+1) * multi_token_count + MAX_PREFIX_LEN;
    }

    if (count != 1)
    {
	usage(stderr);
	fprintf(stderr, "%s: Exactly one of the file or directory commands must be present.\n", progname);
	exit(EX_ERROR);
    }

    return count;
}
Example #6
0
static int process_arglist(int argc, char **argv)
{
    int  count = 1;

    bulk_mode = B_CMDLINE;

#ifdef __EMX__
    _response (&argc, &argv);	/* expand response files (@filename) */
    _wildcard (&argc, &argv);	/* expand wildcards (*.*) */
#endif

#define	OPTIONS	":-:c:Cd:DeEM:n:qr:s:tT:vVx:"

    while (1)
    {
	int option;
	int option_index = 0;
	const char *val;

	option = getopt_long_chk(argc, argv, OPTIONS,
			     longopts_bogotune, &option_index);

	if (option == -1)
 	    break;

	val = optarg;
	process_arg(option, NULL, val, PR_NONE, PASS_1_CLI);
    }

    if (ds_flag == DS_NONE)	/* default is "wordlist on disk" */
	ds_flag = DS_DSK;

    if (ds_flag == DS_ERR) {
	fprintf(stderr, "Only one '-d dir' or '-D' option is allowed.\n");
	exit(EX_ERROR);
    }

    if (bogolex_file == NULL &&
	(spam_files->count == 0 || ham_files->count == 0)) {
	fprintf(stderr,
		"Bogotune needs both non-spam and spam message sets for its parameter testing.\n");
	exit(EX_ERROR);
    }

    if (!suppress_config_file)
	process_config_files(false, longopts_bogotune);

    return count;
}
Example #7
0
static void  process_env_string (char const* name)
{
char *s= getenv(name);
if (s == NULL) return;
for (;;) {
   char *p, save;
   while (*s==' ') s++;                           /* skip whitespace */
   if (*s == '\0') return;                       /* all done */
   p= s+1;
   while (*p != ' ' && *p != '\0') p++;          /* find end of parameter */
   save= *p;
   *p= '\0';                                    /* mark as end of string */
   process_arg (s);                             /* feed it in */
   *p= save;
   s= p;
   }
}
Example #8
0
int main(int argc, char **argv) {
    ensure_perror(argc == 2, "Usage: rshd <port_number>");

    int listenning_port = process_arg(argv[1]);

    become_daemon();

    openlog("rshd", LOG_PID | LOG_CONS, LOG_DAEMON);

    int server_socket = get_server_socket(listenning_port);
    listen(server_socket, 7);

    int epoll_fd = epoll_create1(EPOLL_CLOEXEC);
    add_server_socket_to_epoll(epoll_fd, server_socket);

    service_epoll_events(epoll_fd, server_socket);

    return 0;
}
Example #9
0
static void process_arglist(int argc, char **argv)
{
    int option;

    fpin = stdin;
    dbgout = stderr;

#ifdef __EMX__
    _response (&argc, &argv);	/* expand response files (@filename) */
    _wildcard (&argc, &argv);	/* expand wildcards (*.*) */
#endif

    while (1)
    {
	int option_index = 0;
	int this_option_optind = optind ? optind : 1;
	const char *name;

#ifdef __EMX__
	if (optind == 1) optind = 0;
#endif

	option = getopt_long_chk(argc, argv, OPTIONS,
			     longopts_bogolexer, &option_index);

	if (option == -1)
	    break;

	name = (option_index == 0) ? argv[this_option_optind] : longopts_bogolexer[option_index].name;
	process_arg(option, name, optarg, PR_COMMAND, PASS_1_CLI);
    }

    if (optind < argc) {
	fprintf(stderr, "Extra arguments given, first: %s. Aborting.\n",
		argv[optind]);
	exit(EX_ERROR);
    }
}
Example #10
0
int main(int argc, char* argv[])
{
	//.. file i/o names
	std::string finBaseName;
	std::string foutBaseName;

	//.. special stuff needed for entirety of calculation
	float * x0 = { 0 };
	float * y0 = { 0 };
	float * xTot = { 0 };
	float * yTot = { 0 };
	int		startFileId = 1;
	int		endFileId = 1;
	int		numFrame = 0;
	std::vector<int> targetList;

	//.. process command line arguments
	process_arg(finBaseName, foutBaseName, argc, argv, targetList, startFileId, endFileId);

	//.. create output file for each target
	std::vector<std::ofstream*> fout;
	const unsigned int numTargets = targetList.size();
	for (int i = 0; i < numTargets; i++)
	{
		std::ostringstream ofname;
		ofname << foutBaseName << targetList[i] << ".csv";
		fout.push_back(new std::ofstream(ofname.str(), std::ios::out));
	}

	//.. confirm sizes match
	if (numTargets != fout.size())
	{
		std::cerr << "Error linking targets to files\n";
		return 10;
	}

	//.. loop through all files
	for (int fid = startFileId; fid <= endFileId; fid++)
	{
		//.. make sure it's open first
		std::ostringstream ifname;
		ifname << finBaseName << fid << ".xyz";
		std::ifstream fin(ifname.str(), std::ios::in);
		if (!fin.is_open())
		{
			std::cerr << "Error opening file" << std::endl
				<< "Check for correct input name and directory\n" << std::endl;
			show_usage(argv[0]);
			return 20;
		}

		//.. stuff
		int		numParticles;
		int		numPerWorm;
		int		numWorms;
		double	numWorms2;
		char	charTrash;
		float	k2spring;
		float	hx;
		float	hy;
		float	floatTrash;

		//.. each frame loop
		while (!fin.eof())
		{
			numParticles = 4; // Deals with case of black line at end of file.
			fin >> numParticles;
			fin >> numPerWorm >> k2spring >> hx >> hy;
			numParticles -= 4;

			if (numParticles == 0) break;

			numWorms = numParticles / numPerWorm;
			numWorms2 = numWorms*numWorms;

			float * x = new float[numTargets];
			float * y = new float[numTargets];

			// Read in X,Y,Z positions for frame
			std::cout << "\nReading frame " << numFrame << " from " << ifname.str() << std::endl;
			int t = 0;
			for (int i = 0; i < numParticles; i++)
			{
				//.. is i in targets list?
				bool found = false;
				for (int c = 0; c < numTargets; c++)
				{
					if (targetList[c] == i) found = true;
				}

				if (found)
				{
					fin >> charTrash >> x[t] >> y[t] >> floatTrash;
					std::cout << "\nTarget # " << t << " found at { " << x[t] << "," << y[t] << " }";
					t++;
				}
				else
					fin >> charTrash >> floatTrash >> floatTrash >> floatTrash;
			}

			// Dump corner particles at end of file to trash
			for (int t = 0; t < 4; t++)
				fin >> charTrash >> floatTrash >> floatTrash >> floatTrash;

			//.. alloc only at first frame
			if (numFrame == 0)
			{
				x0 = new float[numTargets];
				y0 = new float[numTargets];
				xTot = new float[numTargets];
				yTot = new float[numTargets];
				for (int i = 0; i < numTargets; i++)
				{
					x0[i] = x[i];
					y0[i] = y[i];
					xTot[i] = 0.0f;
					yTot[i] = 0.0f;
  				}
			}

			// Calculate Average Properties
			for (int p = 0; p < numTargets; p++)
			{
				//.. raw distance travelled
				float dx = x[p] - x0[p];
				float dy = y[p] - y0[p];

				//.. boundary conditions
				if (dx > hx / 2.0f) dx -= hx;
				if (dx < -hx / 2.0f) dx += hx;
				if (dy > hy / 2.0f) dy -= hy;
				if (dy < -hy / 2.0f) dy += hy;

				//.. add to cummulative distance vector
				xTot[p] += dx;
				yTot[p] += dy;
			}

			//.. print to output files
			for (int i = 0; i < numTargets; i++)
			{
				*(fout[i]) << xTot[i] << ", " << yTot[i] << std::endl;
			}

			//.. store for next frame
			for (int i = 0; i < numTargets; i++)
			{
				x0[i] = x[i];
				y0[i] = y[i];
			}

			delete[] x;
			delete[] y;
			numFrame++;
		}
		fin.close();
	}
Example #11
0
int main(int argc, char* argv[]){

	//.. i/o things ************************************************************************

	std::string finBaseName;
	std::ofstream fout;

	//.. user input parameters *************************************************************

	int		startFileId = 1;
	int		endFileId	= 1;
	int     numFrame	= 0;
	int		numBoxSize	= 25;
	float	minBoxSize	= 1.0f;
	float	maxBoxSize	= 25.0f;
	process_arg(finBaseName, fout, argc, argv, minBoxSize, maxBoxSize, numBoxSize, startFileId, endFileId);

	//.. calc box sizes ******************************************************************

	float dSize = (maxBoxSize - minBoxSize) / float(numBoxSize);

	std::vector<float> boxSize;
	boxSize.push_back(minBoxSize);
	std::cout << "\tBox Sizes:\n";
	for (int i = 1; i < numBoxSize; i++)
	{
		float prevSize = boxSize.back();
		boxSize.push_back(prevSize + dSize);
		std::cout << "\t" << boxSize.back();
	}
	std::cout << std::endl << std::endl;

	//.. total average stuff *************************************************************

	std::vector<float> totalDN;
	std::vector<float> totalAveN;
	totalDN.resize(numBoxSize, 0.0f);
	totalAveN.resize(numBoxSize, 0.0f);

	//.. loop through all input files ******************************************************

	for (int fid = startFileId; fid <= endFileId; fid++)
	{
		//.. make ifstream and open ********************************************************
		std::ostringstream ifname;
		ifname << finBaseName << fid << ".xyz";
		std::ifstream fin(ifname.str(), std::ios::in);
		if (!fin.is_open()){
			std::cerr << "Error opening file '" << ifname.str() << "'\n"
				<< "Check for correct input name and/or directory\n" << std::endl;
			continue;
		}

		// Simulation parameters **********************************************************

		int		numParticles;
		int		numPerWorm;
		int		numWorms;
		float	numWorms2;
		char	charTrash;
		float	k2spring;
		float	hx;
		float	hy;
		float	floatTrash;

		//.. loop through entire file *****************************************************

		while (!fin.eof())
		{
			numParticles = 4; // Deals with case of black line at end of file.
			fin >> numParticles;
			fin >> numPerWorm >> k2spring >> hx >> hy;
			numParticles -= 4;

			if (numParticles == 0) break;

			numWorms = numParticles / numPerWorm;
			numWorms2 = numWorms*numWorms;
			float hxo2 = hx / 2.0;
			float hyo2 = hy / 2.0;

			// Allocate Containers *******************************************************

			float * x = new float[numParticles];
			float * y = new float[numParticles];

			// Read in X,Y,Z positions for frame and set linked list *********************
			std::cout << "Reading frame " << numFrame++ << " from " << ifname.str() << std::endl;
			for (int i = 0; i < numParticles; i++)
				fin >> charTrash >> x[i] >> y[i] >> floatTrash;
			
			// Dump corner particles at end of file to trash *****************************

			for (int t = 0; t < 4; t++)
				fin >> charTrash >> floatTrash >> floatTrash >> floatTrash;

			// Components of calculation *************************************************

			std::vector<float> DN;
			std::vector<float> aveN;

			//.. calculate ***************************************************************

			for (int i = 0; i < numBoxSize; i++)
			{
				int xbox = int(hx / boxSize[i]);
				int ybox = int(hy / boxSize[i]);
				int nbox = xbox*ybox;
				int * counts = new int[nbox];

				for (int b = 0; b < nbox; b++)
					counts[b] = 0;

				for (int j = 0; j < numParticles; j++)
				{
					int ibox = int(x[j] / boxSize[i]);
					int jbox = int(y[j] / boxSize[i]);
					if (ibox >= xbox || jbox >= ybox) continue;

					int sbox = jbox*xbox + ibox;
					if (sbox >= 0 && sbox < nbox)
					{
						counts[sbox]++;
					}
				}

				//.. calculate sum
				int sum = 0;
				for (int b = 0; b < nbox; b++)
				{
					sum += counts[b];
				}

				float nbar = float(sum) / float(nbox);
				aveN.push_back(nbar);

				float sqrtSum = 0.0f;
				for (int b = 0; b < nbox; b++)
				{
					float dn = float(counts[b]) - nbar;
					sqrtSum += dn*dn;
				}

				DN.push_back(sqrtf(sqrtSum / float(nbox - 1)));
			}
			
			//.. make printable vector
			const int numOfXValues = 25;
			//std::vector<float> xValues;
			std::vector<float> yValues;
			std::vector<float> nums;
			
			//xValues.resize(numOfXValues, 0.0f);
			yValues.resize(numOfXValues, 0.0f);
			nums.resize(numOfXValues, 0.0f);

			//.. get max and min N
			float NMax = 0;
			float NMin = 100;
			for (int j = 0; j < aveN.size(); j++)
			{
				if (aveN[j] > NMax) NMax = aveN[j];
				if (aveN[j] < NMin) NMin = aveN[j];
			}

			float dx = (NMax - NMin) / float(numOfXValues);
			for (int j = 0; j < aveN.size(); j++)
			{
				int xbin = int(aveN[j] / dx);
				if (xbin >= numOfXValues || xbin < 0) continue;

				nums[xbin] += 1.0f;
				yValues[xbin] += DN[j];
			}

			fout << "0";
			for (int j = 1; j < numOfXValues; j++)
			{
				fout << "," << j*dx;
			}
			fout << std::endl;

			if (nums[0] != 0.0f) fout << yValues[0] / nums[0];
			else fout << 0.0f;
			for (int j = 1; j < numOfXValues; j++)
			{
				if (nums[j] != 0.0f) fout << "," << yValues[j] / nums[j];
				else fout << 0.0f;
			}
			fout << std::endl << std::endl;

			//.. eliminate dynamic memory ************************************************
			delete[] x;
			delete[] y;
		} // End of File

		fin.close();
	}
	fout.close();
	return EXIT_SUCCESS;
}
Example #12
0
int
main(int argc, char **argv)
{
//MANAGEMENT OF ARGUMENTS
  options_help = options;
  int arg_num=1;
  if (argc < 2)
    return poclcc_error("Invalid argument!\n");

  while (arg_num < argc-1)
    if (process_arg(&arg_num, argv, argc))
      return -1;

  if (arg_num >= argc && list_devices)
    list_devices_only = 1;
  else if (arg_num >= argc)
    poclcc_error("Invalid arguments!\n");
  else
    {
      int current_process = search_process(argv[arg_num]);
      if (current_process == -1 && process_kernel_file(arg_num, argv, argc))
        return -1;
      else if (current_process != -1)
        {
          process_arg(&arg_num, argv, argc);
          list_devices_only = 1;
        }
    }

//OPENCL STUFF
  cl_platform_id cpPlatform;
  cl_device_id device_ids[NUM_OF_DEVICE_ID];
  cl_context context;
  cl_program program;
  cl_int err;
  cl_uint num_devices, i;

  CHECK_CL_ERROR(clGetPlatformIDs(1, &cpPlatform, NULL));

  CHECK_CL_ERROR(clGetDeviceIDs(cpPlatform, opencl_device,
                                NUM_OF_DEVICE_ID, device_ids, &num_devices));

  if (opencl_device_id >= num_devices)
    return poclcc_error("Invalid opencl device_id!\n");

  if (list_devices)
    {
      context = clCreateContext(0, num_devices, device_ids, NULL, NULL, &err);
      CHECK_CL_ERROR2(err, clCreateContext);

      printf("LIST OF DEVICES:\n");
      for (i=0; i<num_devices; i++)
        {
          char str[DEVICE_INFO_MAX_LENGTH];
          CHECK_CL_ERROR(clGetDeviceInfo(device_ids[i], CL_DEVICE_VENDOR,
                                         DEVICE_INFO_MAX_LENGTH, str, NULL));

          printf("%i: %s --- ", i, str);

          CHECK_CL_ERROR(clGetDeviceInfo(device_ids[i], CL_DEVICE_NAME,
                                         DEVICE_INFO_MAX_LENGTH, str, NULL));
          printf("%s\n", str);
        }

      clReleaseContext(context);
    }
  if (list_devices_only)
    return 0;

  context = clCreateContext(0, 1, &device_ids[opencl_device_id], NULL, NULL, &err);
  CHECK_CL_ERROR2(err, clCreateContext);

  program = clCreateProgramWithSource(context, 1, (const char **)&kernel_source, NULL, &err);
  CHECK_CL_ERROR2(err, clCreateProgramWithSource);

  CHECK_CL_ERROR(clBuildProgram(program, 0, NULL, build_options, NULL, NULL));

  size_t binary_sizes;
  char *binary;

  CHECK_CL_ERROR(clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES,
                                  sizeof(size_t), &binary_sizes, NULL));

  binary = malloc(sizeof(char)*binary_sizes);
  if (!binary)
    {
      printf("malloc(binary) failed\n");
      exit(1);
    }

  CHECK_CL_ERROR(clGetProgramInfo(program, CL_PROGRAM_BINARIES,
                                  sizeof(unsigned char*), &binary, NULL));

  CHECK_CL_ERROR(clReleaseProgram(program));
  CHECK_CL_ERROR(clReleaseContext(context));

  if (poclu_write_file(output_file, binary, binary_sizes))
    ERRNO_EXIT(output_file);

  free(binary);

  return 0;
}
Example #13
0
/*
*-----------------------------------------------------------------------------
*								parse_argv
*-----------------------------------------------------------------------------
* Dscr:  parse argv list and call process_arg for each option
*        fill object_name object_argv, object_argc values   
*-----------------------------------------------------------------------------
* Input : argc, argv 
* Output: 0 - continue
*		  <0 - error code to exit 
*         >0 - code to exit
* Notes : call exit(1) in case of cmd line error  
*-----------------------------------------------------------------------------
*/
int parse_argv( int my_argc, char** my_argv, int options_n )
{
	int i,i2,len;
	int rc;
	char* equ_ptr = 0;

	/*
	* Parse command line untill object name found
	*/
	for( i=1; i<my_argc; i++ )
	{
		if( my_argv[i][0] != '-' )
		{
			printf( "Wrong parameter \"%s\"\n", my_argv[i] );
			usage( 0, options_n );
			return -1;
		}

		equ_ptr = 0;

		if( my_argv[i][1] != '-' )	/* option in short form "-x" */
		{
			for( i2=0; i2<options_n; i2++ )
				if( my_argv[i][1] == usage_descriptor[i2].m_option )
				{
                    /* Determine option value */
					if( usage_descriptor[i2].equ_alias[0] != '\0' )
					{
						if( my_argv[i][2] != '\0' )
						{
							equ_ptr = &my_argv[i][2];	/* -xVALUE */
							if( *equ_ptr == '=' )
								equ_ptr++;				/* -x=VALUE */
						}
						else
						{								/* -x VALUE */
							/* Take next argument as value */
							if( (i+1 == my_argc) || (my_argv[i+1][0] == '-') )
							{
								/* This was last argument or next argument starts with '-' */
								printf( "Option %s is not complete\n", my_argv[i] );
								usage( 0, options_n );
								return -1;
							}

							i++;
							equ_ptr = my_argv[i];
						}
					}
					rc = process_arg( i2, equ_ptr );
					if( rc )
						return rc;
					break;
				}
		}
		else	/* option in verbose form "--option" */
		{
			for( i2=0; i2<options_n; i2++ )
			{
				len = (int)strlen( usage_descriptor[i2].mm_option );
				if( !strncmp(usage_descriptor[i2].mm_option, &my_argv[i][2], len) )
				{
					if( (my_argv[i][2+len]=='\0') || (my_argv[i][2+len]=='=') )
					{

						/* Split argument to option=value if needed */

						if( usage_descriptor[i2].equ_alias[0] != '\0' )
						{
							equ_ptr = strchr( my_argv[i], '=' );
							if( !equ_ptr || !strlen( equ_ptr+1 ) )
							{
								/* format option=value not found */
								printf( "Option %s is not complete\n", my_argv[i] );
								usage( 0, options_n );
								return -1;
							}
							equ_ptr++;
						}

						rc = process_arg( i2, equ_ptr );
						if( rc )
							return rc;
						break;
					}
				}
			}
		}

		if( i2 == options_n )
		{
			printf( "Unknown option %s\n", my_argv[i] );
			usage( 0, options_n );
			return -1;
		}
	}/*end for*/

	return 0;
}
Example #14
0
int main(int argc, char* argv[]){

	//.. i/o things ************************************************************************

	std::string finBaseName;
	std::ofstream fout;

	//.. user input parameters *************************************************************

	float intRange = 10.0f;
	int	   startFileId = 1;
	int	   endFileId = 1;
	int     numFrame = 1;
	float	binWidth = 1.0f;
	process_arg(finBaseName, fout, argc, argv, intRange, binWidth, startFileId, endFileId);

	//.. number of bins and first line of data file ****************************************

	int numBin = int(ceil(intRange / binWidth));
	fout << "bins";
	for (int i = 1; i <= numBin; i++)
		fout << ", " << float(i)*binWidth;
	fout << std::endl;

	//.. linked list parameters (for worms COM, not particles) *****************************

	float dcell = float(intRange);
	int nxcell, nycell, ncell;
	const int ddx[5] = { 0, -1, 0, 1, 1 };
	const int ddy[5] = { 0, 1, 1, 1, 0 };

	//.. loop through all input files ******************************************************

	for (int fid = startFileId; fid <= endFileId; fid++)
	{
		//.. make ifstream and open ********************************************************
		std::ostringstream ifname;
		ifname << finBaseName << fid << ".xyz";
		std::ifstream fin(ifname.str(), std::ios::in);
		if (!fin.is_open()){
			std::cerr << "Error opening file '" << ifname.str() << "'\n"
				<< "Check for correct input name and/or directory\n" << std::endl;
			continue;
		}

		// Simulation parameters **********************************************************

		int		numParticles;
		int		numPerWorm;
		int		numWorms;
		float	numWorms2;
		char	charTrash;
		float	k2spring;
		float	hx;
		float	hy;
		float	floatTrash;
		float	intRange2 = intRange * intRange;

		//.. loop through entire file *****************************************************

		while (!fin.eof())
		{
			numParticles = 4; // Deals with case of black line at end of file.
			fin >> numParticles;
			fin >> numPerWorm >> k2spring >> hx >> hy;
			numParticles -= 4;

			if (numParticles == 0) break;

			numWorms = numParticles / numPerWorm;
			numWorms2 = numWorms*numWorms;
			const float hxo2 = hx / 2.0;
			const float hyo2 = hy / 2.0;

			//.. make linked list ********************************************************
			nxcell = int(ceil(hx / dcell));
			nycell = int(ceil(hy / dcell));
			ncell = nxcell*nycell;

			// Allocate Containers *******************************************************

			float * x = new float[numParticles];
			float * y = new float[numParticles];
			int * ptz = new int[numParticles];
			int * heads = new int[ncell];

			//.. init heads **************************************************************

			for (int i = 0; i < ncell; i++)
				heads[i] = -1;

			// Read in X,Y,Z positions for frame and set linked list *********************
			std::cout << "Reading frame " << numFrame << " from " << ifname.str() << std::endl;
			for (int i = 0; i < numParticles; i++)
			{
				fin >> charTrash >> x[i] >> y[i] >> floatTrash;

				//.. put into linked list
				int icell = int(x[i] / dcell);
				int jcell = int(y[i] / dcell);
				int scell = jcell*nxcell + icell;
				ptz[i] = heads[scell];
				heads[scell] = i;
			}

			// Dump corner particles at end of file to trash *****************************
			
			for (int t = 0; t < 4; t++)
				fin >> charTrash >> floatTrash >> floatTrash >> floatTrash;

			// Components of calculation *************************************************

			std::vector<float> G;
			float aveOver = 1;
			for (int i = 0; i <= numBin; i++)
				G.push_back(0.0f);

			//.. calculate using linked list *********************************************

			std::cout << "Calculating ... \n";
			for (int ic = 0; ic < nxcell; ic++)
			{
				for (int jc = 0; jc < nycell; jc++)
				{
					//.. scalar add of cell
					int scell = jc*nxcell + ic;

					//.. look for stop flag
					if (heads[scell] == -1) continue;

					//.. loop over adjacent cells
					for (int dir = 0; dir < 5; dir++)
					{
						//.. neighbor cell scalor address
						int icnab = (ic + ddx[dir]) % nxcell;
						int jcnab = (jc + ddy[dir]) % nycell;
						if (icnab < 0) icnab += nxcell;
						if (jcnab < 0) jcnab += nycell;
						int scnab = jcnab * nxcell + icnab;

						//.. loop for stop flag
						if (heads[scnab] == -1) continue;

						int ii = heads[scell];
						while (ii >= 0)
						{
							int jj = heads[scnab];
							while (jj >= 0)
							{
								//.. calculate distance
								float dx = x[ii] - x[jj];
								float dy = y[ii] - y[jj];
								if (dx > hxo2) dx -= hx;
								if (dx < -hxo2) dx += hx;
								if (dy > hyo2) dy -= hy;
								if (dy < -hyo2) dy += hy;
								float r2 = dx*dx + dy*dy;

								//.. MAIN CALCULATION ************************************

								if (r2 <= intRange2)
								{
									//.. find bin
									float r = sqrtf(r2);
									int b = int(r / binWidth);
									if ((b >= 0) && (b <= numBin))
									{
										//.. count
										aveOver += 1;
										G.at(b) += 1;
									}
								}
								jj = ptz[jj];
							}
							ii = ptz[ii];
						}
					}
				}
			}

			//.. Average G(r) and print to out file *************************************

			fout << numFrame++;
			for (int i = 0; i < numBin; i++)
			{
				float r1 = float(i)*binWidth;
				float r2 = float(i + 1)*binWidth;
				float area = _PI*(r2*r2 - r1*r1);
				G[i] /= aveOver;
				G[i] *= 2.0f;
				G[i] /= area;
				fout << ", " << G[i];
			}
			fout << std::endl;

			//.. eliminate dynamic memory ***********************************************
			delete[] x;
			delete[] y;
			delete[] ptz;
			delete[] heads;
		} // End of File

		fin.close();
	}
	fout.close();
	return EXIT_SUCCESS;
}
Example #15
0
int main(int argc, char* argv[]){

	//std::vector<std::ifstream*> fin;
	std::string finBaseName;
	std::ofstream fout;
	std::ofstream fout2("test_counts.csv");

	//.. user input parameters
	double	intRange	= 5.0;
	int		startFileId = 1;
	int		endFileId	= 1;
	int		numFrame	= 1;
	float	binWidth	= 0.001f;
	int		maxNumBin = 0;
	process_arg(finBaseName, fout, argc, argv, intRange, startFileId, endFileId);

	//.. linked list parameters (for worms COM, not particles)
	float dcell		 = float(intRange);
	int nxcell, nycell, ncell;
	const int ddx[5] = { 0, -1, 0, 1, 1 };
	const int ddy[5] = { 0, 1, 1, 1, 0 };
	int * ptz		 = { 0 };
	int * heads		 = { 0 };

	for (int fid = startFileId; fid <= endFileId; fid++)
	{
		//.. make ifstream and open
		std::ostringstream ifname;
		ifname << finBaseName << fid << ".xyz";
		std::ifstream fin(ifname.str(), std::ios::in);

		if (!fin.is_open()){
			std::cerr << "Error opening file '" << ifname.str() << "'\n"
				<< "Check for correct input name and/or directory\n" << std::endl;
			continue;
		}
		// Simulation parameters
		int		numParticles;
		int		numPerWorm;
		int		numWorms;
		double	numWorms2;
		char	charTrash;
		float	k2spring;
		float	hx;
		float	hy;
		float	floatTrash;
		float	intRange2 = intRange * intRange;
		float	intArea = _PI * intRange2;

		//.. loop through entire file
		while (!fin.eof())
		{
			numParticles = 4; // Deals with case of black line at end of file.
			fin >> numParticles;
			fin >> numPerWorm >> k2spring >> hx >> hy;
			numParticles -= 4;

			if (numParticles == 0) break;

			numWorms = numParticles / numPerWorm;
			numWorms2 = numWorms*numWorms;
			float hxo2 = hx / 2.0;
			float hyo2 = hy / 2.0;

			//.. make linked list
			nxcell = int(ceil(hx / dcell));
			nycell = int(ceil(hy / dcell));
			ncell = nxcell*nycell;

			// Allocate Containers
			float* comx = new float[numWorms];
			float* comy = new float[numWorms];
			float* theta = new float[numWorms];
			ptz = new int[numWorms];
			heads = new int[ncell];

			//.. init heads
			for (int i = 0; i < ncell; i++)
				heads[i] = -1;

			// Read in X,Y,Z positions for frame
			//.. and set linked list
			std::cout << "Reading frame " << numFrame << " from " << ifname.str() << std::endl;
			for (int w = 0; w < numWorms; w++)
			{
				//.. read in particles for worm w
				float * x = new float[numPerWorm];
				float * y = new float[numPerWorm];
				for (int p = 0; p < numPerWorm; p++)
					fin >> charTrash >> x[p] >> y[p] >> floatTrash;

				//.. get COM for w
				float x1 = x[0];
				float y1 = y[0];
				float x2 = x[numPerWorm - 1];
				float y2 = y[numPerWorm - 1];

				delete[] x;
				delete[] y;

				float dx = x1 - x2;
				float dy = y1 - y2;
				if (dx > hxo2){
					dx -= hx;
					x1 -= hx;
				}
				if (dx < -hxo2){
					dx += hx;
					x1 += hx;
				}
				if (dy > hyo2){
					dy -= hy;
					y1 -= hy;
				}
				if (dy < -hyo2){
					dy += hy;
					y1 += hy;
				}
				//.. calculate theta for worm w
				theta[w] = std::atan2(dy, dx);

				// Periodic Boundaries on COM
				float Xcom = (x1 + x2) / 2.0;
				float Ycom = (y1 + y2) / 2.0;
				if (Xcom > hx) Xcom -= hx;
				if (Xcom < 0)  Xcom += hx;
				if (Ycom > hy) Ycom -= hy;
				if (Ycom < 0)  Ycom += hy;

				//.. add to linked list and store COM
				int icell = int(floor(Xcom / dcell));
				int jcell = int(floor(Ycom / dcell));
				int scell = jcell*nxcell + icell;
				ptz[w] = heads[scell];
				heads[scell] = w;
				comx[w] = Xcom;
				comy[w] = Ycom;
			}

			// Dump corner particles at end of file to trash
			for (int t = 0; t < 4; t++)
				fin >> charTrash >> floatTrash >> floatTrash >> floatTrash;

			// Components of calculation
			float totalOrderParameter = 0;
			float totalCos2Sum = 0;
			float totalCosSinSum = 0;
			float totalAveOver = 0;

			//.. histogram for frame
			std::vector<float> svd;
			std::vector<int> numInBin;

			//.. calculate using linked list
			std::cout << "Calculating ... \n";
			for (int ic = 0; ic < nxcell; ic++)
			{
				for (int jc = 0; jc < nycell; jc++)
				{
					//.. scalar add of cell
					int scell = jc*nxcell + ic;
					//std::cout << scell << "\t";

					//.. look for stop flag
					if (heads[scell] == -1) continue;

					//.. loop over adjacent cells
					for (int dir = 0; dir < 5; dir++)
					{
						//.. neighbor cell scalor address
						int icnab = (ic + ddx[dir]) % nxcell;
						int jcnab = (jc + ddy[dir]) % nycell;
						if (icnab < 0) icnab += nxcell;
						if (jcnab < 0) jcnab += nycell;
						int scnab = jcnab * nxcell + icnab;

						//.. loop for stop flag
						if (heads[scnab] == -1) continue;

						int iw = heads[scell];
						while (iw >= 0)
						{
							// Components of calculation
							float orderParameter = 0;
							float cos2Sum = 0;
							float cosSinSum = 0;
							float aveOver = 0;

							int jw = heads[scnab];
							while (jw >= 0)
							{
								//std::cout << iw << ", " << jw << std::endl;

								// Boundary conditions on Xcoms
								float dXcom = comx[iw] - comx[jw];
								float dYcom = comy[iw] - comy[jw];
								if (dXcom > hxo2) dXcom -= hx;
								if (dXcom < -hxo2) dXcom += hx;
								if (dYcom > hyo2) dYcom -= hy;
								if (dYcom < -hyo2) dYcom += hy;

								//.. only if close enough
								const float R2com = dXcom*dXcom + dYcom*dYcom;
								if (R2com <= intRange2)
								{
									//.. relative angle between worms
									float dtheta = theta[iw] - theta[jw];

									//.. 2pi boundary conditons
									if (dtheta > _PI) dtheta -= _2PI;
									if (dtheta < -_PI) dtheta += _2PI;

									cos2Sum += std::cos(dtheta)*std::cos(dtheta);
									cosSinSum += std::cos(dtheta)*std::sin(dtheta);
									totalCos2Sum += cos2Sum;
									totalCosSinSum += cosSinSum;
									totalAveOver += 1;
									aveOver += 1;
								}
								jw = ptz[jw];
							}

							//.. add to histogram of S vs Density
							// Form Averages and calculate OrderParameter for Frame
							const float aveCos2 = cos2Sum / aveOver;
							const float aveCosSin = cosSinSum / aveOver;
							orderParameter = 2 * std::sqrt((aveCos2 - 0.5f)*(aveCos2 - 0.5f) + aveCosSin*aveCosSin);

							//.. find bin and resize if necessary
							int b = int((aveOver / intArea)/binWidth);
							//std::cout << b << "," << svd.size() << "\t";
							
							while (svd.size() <= b)
							{
								//std::cout << "in\t";
								svd.push_back(0.0f);
								numInBin.push_back(0);
							}
							
							//float stop;
							//std::cout << b << "," << svd.size() << "\t";
							//std::cin >> stop;

							//.. add S to bin b
							svd[b] += orderParameter;
							numInBin[b]++;

							//std::cin >> stop;

							//.. move to next particle
							iw = ptz[iw];
						}
					}
				}
			}
			/*
			//.. loop through all worms
			for (int w1 = 0; w1 < numWorms; w1++)
			{
			//.. get head to tail vector
			float x1 = x[w1][0];
			float y1 = y[w1][0];
			float x2 = x[w1][numPerWorm - 1];
			float y2 = y[w1][numPerWorm - 1];
			float dx = x1 - x2;
			float dy = y1 - y2;
			if (dx > hxo2){
			dx -= hx;
			x1 -= hx;
			}
			if (dx < -hxo2){
			dx += hx;
			x1 += hx;
			}
			if (dy > hyo2){
			dy -= hy;
			y1 -= hy;
			}
			if (dy < -hyo2){
			dy += hy;
			y1 += hy;
			}
			// Periodic Boundaries
			float Xcom1 = (x1 + x2) / 2.0;
			float Ycom1 = (y1 + y2) / 2.0;
			if (Xcom1 > hx) Xcom1 -= hx;
			if (Xcom1 < 0)  Xcom1 += hx;
			if (Ycom1 > hy) Ycom1 -= hy;
			if (Ycom1 < 0)  Ycom1 += hy;

			//.. loop through all other unconsidered pairs
			for (int w2 = w1 + 1; w2 < numWorms; w2++)
			{
			float _x1 = x[w2][0];
			float _x2 = x[w2][numPerWorm - 1];
			float _y1 = y[w2][0];
			float _y2 = y[w2][numPerWorm - 1];
			float _dx = _x1 - _x2;
			float _dy = _y1 - _y2;
			if (_dx > hxo2){
			_dx -= hx;
			_x1 -= hx;
			}
			if (_dx < -hxo2){
			_dx += hx;
			_x1 += hx;
			}
			if (_dy > hyo2){
			_dy -= hy;
			_y1 -= hy;
			}
			if (_dy < -hyo2){
			_dy += hy;
			_y1 += hy;
			}
			// Periodic Boundaries
			float Xcom2 = (_x1 + _x2) / 2.0;
			float Ycom2 = (_y1 + _y2) / 2.0;
			if (Xcom2 > hx) Xcom2 -= hx;
			if (Xcom2 < 0)  Xcom2 += hx;
			if (Ycom2 > hy) Ycom2 -= hy;
			if (Ycom2 < 0)  Ycom2 += hy;

			// Boundary conditions on Xcoms
			float dXcom = Xcom1 - Xcom2;
			float dYcom = Ycom1 - Ycom2;
			if (dXcom > hxo2) dXcom -= hx;
			if (dXcom < -hxo2) dXcom += hx;
			if (dYcom > hyo2) dYcom -= hy;
			if (dYcom < -hyo2) dYcom += hy;

			//.. check for close enough
			const float R2com = dXcom*dXcom + dYcom*dYcom;
			if (R2com > intRange2) continue;

			//.. update properties
			const float theta1 = std::atan2(dy, dx);
			const float theta2 = std::atan2(_dy, _dx);
			const float dtheta = theta1 - theta2;
			cos2Sum += std::cos(dtheta)*std::cos(dtheta);
			cosSinSum += std::cos(dtheta)*std::sin(dtheta);
			aveOver += 1;

			}
			}*/

			//.. print to file
			const int numBin = svd.size();
			fout2 << numFrame;
			fout << numFrame++;
			for (int i = 0; i < numBin; i++)
			{
				float printVal;
				if (numInBin.at(i) > 0)
				{
					printVal = svd[i] / float(numInBin.at(i));

				}
				else
				{
					printVal = 0.0f;
				}
				fout << ", " << printVal;
				fout2 << ", " << numInBin.at(i);
			}
			fout << std::endl;
			fout2 << std::endl;

			//.. store for printing bin labels
			if (numBin > maxNumBin) maxNumBin = numBin;

			//.. print to console
			totalOrderParameter = 2 * std::sqrtf(std::powf((totalCos2Sum / totalAveOver - 0.5f), 2.0f) + std::powf(totalCosSinSum / totalAveOver, 2.0f));
			std::cout << "S = " << totalOrderParameter << std::endl;
			fout.flush();
			//fout << numFrame++ << ", " << totalOrderParameter << std::endl;

			// Handle Dynamic Arrays
			delete[] comx;
			delete[] comy;
			delete[] theta;
			delete[] ptz;
			delete[] heads;
		} // End of File

		fin.close();

		//totalOrderParameter /= float(numFrame);
		//std::cout << "S_ave = " << totalOrderParameter << std::endl;

	}

	//.. print bin labels
	fout << "bins";
	for (int i = 1; i <= maxNumBin; i++)
		fout << ", " << i*binWidth;
	fout << std::endl;

	fout.close();
	fout2.close();
	return EXIT_SUCCESS;
}
Example #16
0
void _cdecl main (SHORT argc, char *argv[])
{
//  bool ok = FALSE;
//  char test[5];       // test for trap 05 errors
ULONG ulTimes;          // need for Trap Ctrl-Break Signal

#ifdef TESTING
  if(!dout) {
    DosBeep(500,300);
  }
  if(!memout) {
    DosBeep(1000,300);
  }
#endif

#ifdef ERR_HAND
rc = set_int24();
  if(rc != 0) {
     err_exit("Error initializing error handler", 3);
  }

MYEXCEPTIONREGISTRATIONRECORD myExceptionRegRecord;
myExceptionRegRecord.prev_structure = NULL;
myExceptionRegRecord.ExceptionHandler = MyExceptionHandler;
DosSetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD) &myExceptionRegRecord);
DosSetSignalExceptionFocus(SIG_SETFOCUS, &ulTimes);

if(setjmp(myExceptionRegRecord.env))
   goto OnException;
#endif

  DBG_INI(dout<<"file "<<__FILE__<<" line "<<__LINE__<<" settings.numlock_on = "<<settings.numlock_on<<endl);

filesys_init();
get_current_directory(cwd);               // init cur dir
Mem::vmem_setup();
strcpy(exe_dir, *argv);    // assume loaded via X:\subdir\KED.EXE

DBG_FILE(dout << "EXE_DIR =  " << exe_dir <<endl);
DBG_MEM(memout<< " main after except setup "<< checkmem2 << endl);

assure_windows_ready();

if(!thread_init()) {
   err_exit("Error creating initial threads", 5);
}
process_env_string ("EDITOR");  /* do parameters from environment string */
strcpy (progname,*argv);
argc--;                         /* don't count program name */
argv++;
while (argc--) {                /* process each parameter */
   process_arg (*argv);
   argv++;
   }
if (!*settings.help_path) {     /* help is usually in same dir as program */
    delta_filename (settings.help_path, progname, "*.HLP");
   }

//#ifdef TESTING
//if(!debug_on) {
//   dout.close();
//   memout.close();
//}
//#endif


  assure_1_view();
  DBG_INI(dout<<"edit.cpp line "<<__LINE__<<" shell_command.s = °"<<settings.shell_command.s<<"°"<<endl);
  DBG_INI(dout<<"file "<<__FILE__<<" line "<<__LINE__<<" settings.numlock_on = "<<settings.numlock_on<<endl);
//  ok = load_keys();        //  Version 2.08 
//  if(!ok)
//    err_exit("Failed to load Keyboard driver", 10);

  edit_loop();
//  test[5000] = 'A';                    // test trap array bounds

  goto Ked_Exit;

OnException:
#ifdef ERR_HAND
DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD) &myExceptionRegRecord);
//  Screen.term_mess = "application trapped";
  err_exit(" application trapped", 20);
#endif

Ked_Exit:
#ifdef ERR_HAND
if(ORG_NUMLOCK) {
   DBG_NUML(dout<<" exit - setting NUMLOCK    on"<<endl);
   numlock_set(TRUE);
}
else {
   DBG_NUML(dout<<" exit - setting NUMLOCK    off"<<endl);
   numlock_set(FALSE);   
}
DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD) &myExceptionRegRecord);
#endif

DBG_MEM(memout<< " main after except setup "<< checkmem2 << endl);
DBG_BUGS(dout<<'\n'<<"    Normal Closedown in LOGFILE "<<endl);
}