示例#1
0
double* extract_coulmn_double(char *str, int col_min, int col_max)	{
	/*
	 return pointer to array of size [(col_max-col_min)+1]
	 array contains floating point numbers range from from col_min to col_max of the given line/string.
	 For example;
	 ---------------------------------------
	 	double *out;
	 	char *line = "    24 U-A       0.07      0.02      0.49     -2.48     -7.63     -0.38";
	 	char *input=NULL;
	 	input = strdup(line);
		out = extract_coulmn_double(input, 3, 5);
		printf("%15.3f%15.3f%15.3f\n",out[0], out[1], out[2]);
	-----------------------------------------
		OUTPUT $          0.070          0.020          0.490
	 */

	double *data=NULL;
	char *buffer=NULL, **str_data=NULL;
	int size = (col_max-col_min)+1;
	int i=0,n=0;

	buffer = strdup(str);
	remove_leading_white_space(buffer);
	str_data = split_by_space(buffer, NULL);

	data = (double *) malloc (sizeof(double)*size);
	for(i=(col_min-1);i<col_max;i++){
		data[n] = strtof(str_data[i],NULL);
		n++;
	}
	free(buffer);
	free(str_data);
	return data;
}
示例#2
0
bool is_first_numerics(char *str)	{
	char *buffer;
	bool inumber=FALSE;
	buffer = strdup(str);
	remove_leading_white_space(buffer);
	if(isdigit(buffer[0]))
		inumber=TRUE;
	if((buffer[0]=='-') && (isdigit(buffer[1])))
			inumber=TRUE;
	free(buffer);
	return inumber;
}
示例#3
0
double get_AtomWCAEnergy(char *line)	{
	double energy;
	char **split_data=NULL;
	int nwords, i;

	remove_leading_white_space(line);
	split_data = split_by_space(line, &nwords);
	energy = strtod(split_data[5], NULL);

	free(split_data);
	return energy;
}
示例#4
0
int* extract_coulmn_integer(char *str, int col_min, int col_max)	{
	/*
	 Similar to extract_coulmn_double but extract integer data.
	 */

	int *data=NULL;
	char *buffer=NULL, **str_data=NULL;
	int size = (col_max-col_min)+1;
	int i=0,n=0;

	buffer = strdup(str);
	remove_leading_white_space(buffer);
	str_data = split_by_space(buffer, NULL);

	data = (int *) malloc (sizeof(int)*size);
	for(i=(col_min-1);i<col_max;i++){
		data[n] = atoi(str_data[i]);
		n++;
	}
	return data;
}