Example #1
0
/**
 * \brief Parse a spinning command [Level 2]
 * \param tokens Command tokens.
 * \param cmd Cmd structure.
 * \return The error result.
 */
static TuxDrvError
parse_tux_spinning_command(tokens_t tokens, delay_cmd_t *cmd)
{
    TuxDrvError ret =  E_TUXDRV_INVALIDCOMMAND;

    if (strcmp(tokens[2], "LEFT_ON") == 0)
    {
        cmd->sub_command = LEFT_ON;
        if (str_to_uint8(tokens[3], &cmd->spinning_on_parameters.nr_qturns))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    else if (strcmp(tokens[2], "LEFT_ON_DURING") == 0)
    {
        cmd->sub_command = LEFT_ON_DURING;
        if (str_to_float(tokens[3], &cmd->spinning_on_during_parameters.duration))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    else if (strcmp(tokens[2], "RIGHT_ON") == 0)
    {
        cmd->sub_command = RIGHT_ON;
        if (str_to_uint8(tokens[3], &cmd->spinning_on_parameters.nr_qturns))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    else if (strcmp(tokens[2], "RIGHT_ON_DURING") == 0)
    {
        cmd->sub_command = RIGHT_ON_DURING;
        if (str_to_float(tokens[3], &cmd->spinning_on_during_parameters.duration))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    else if (strcmp(tokens[2], "OFF") == 0)
    {
        cmd->sub_command = OFF;
        ret = E_TUXDRV_NOERROR;
    }
    else if (strcmp(tokens[2], "SPEED") == 0)
    {
        cmd->sub_command = SPEED;
        if (str_to_uint8(tokens[3], &cmd->spinning_speed_parameters.speed))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    return ret;
}
Example #2
0
/**
 * \brief Parse a led command [Level 2]
 * \param tokens Command tokens.
 * \param cmd Cmd structure.
 * \return The error result.
 */
static TuxDrvError
parse_tux_led_command(tokens_t tokens, delay_cmd_t *cmd)
{
    TuxDrvError ret =  E_TUXDRV_INVALIDCOMMAND;
    if (strcmp(tokens[2], "BLINK") == 0)
    {
        cmd->sub_command = BLINK;
        if (str_to_leds_t(tokens[3], &cmd->led_blink_parameters.leds) &&
            str_to_uint8(tokens[4], &cmd->led_blink_parameters.pulse_count) &&
            str_to_float(tokens[5], &cmd->led_blink_parameters.pulse_period))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    else if (strcmp(tokens[2], "OFF") == 0)
    {
        cmd->sub_command = OFF;
        if (str_to_leds_t(tokens[3], &cmd->led_off_parameters.leds))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    else if (strcmp(tokens[2], "ON") == 0)
    {
        cmd->sub_command = ON;
        if (str_to_leds_t(tokens[3], &cmd->led_on_parameters.leds) &&
            str_to_float(tokens[4], &cmd->led_on_parameters.intensity))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    else if (strcmp(tokens[2], "PULSE") == 0)
    {
        cmd->sub_command = PULSE;
        if (str_to_leds_t(tokens[3], &cmd->led_pulse_parameters.leds) &&
            str_to_float(tokens[4], &cmd->led_pulse_parameters.min_intensity) &&
            str_to_float(tokens[5], &cmd->led_pulse_parameters.max_intensity) &&
            str_to_uint8(tokens[6], &cmd->led_pulse_parameters.pulse_count) &&
            str_to_float(tokens[7], &cmd->led_pulse_parameters.pulse_period) &&
            str_to_effect_type(tokens[8], &cmd->led_pulse_parameters.effect_type) &&
            str_to_float(tokens[9], &cmd->led_pulse_parameters.effect_speed) &&
            str_to_uint8(tokens[10], &cmd->led_pulse_parameters.effect_step))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    else if (strcmp(tokens[2], "SET") == 0)
    {
        cmd->sub_command = SET;
        if (str_to_leds_t(tokens[3], &cmd->led_set_parameters.leds) &&
            str_to_float(tokens[4], &cmd->led_set_parameters.intensity) &&
            str_to_effect_type(tokens[5], &cmd->led_set_parameters.effect_type) &&
            str_to_float(tokens[6], &cmd->led_set_parameters.effect_speed) &&
            str_to_uint8(tokens[7], &cmd->led_set_parameters.effect_step))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    return ret;
}
Example #3
0
float ini_read_float(STRING *filename, char* section, STRING *entry, float defaultValue)
{
	STRING *tmp = "#64";
	STRING *def = "#64";
	ini_read(tmp, filename, section, entry, str_for_float(def, defaultValue));
	return str_to_float(tmp);
}
int main (void)
{
	char remove_string (char string[], int index_num);
	bool has_decimal (char string[], int decimal_at, int count );
	float decimal_convert (int decimal_at, int count);
	float str_to_float (char string[]);
	//char number[] = "10.221";
	
	printf ("%f", str_to_float("-10.18"));
	//printf ("%f", str_to_float("10.221"));
	
	/*
	printf ("%f", decimal_convert (2, 5));

	int decimal_at, count = 0, test;
	test = has_decimal(number, decimal_at, count);
	printf ("%i\t%s", test, number);
	
	remove_string(number, 2, 1 );
	printf ("%s", number);
	
	float str_to_float (char string[]);
	
	printf ("%f\n", str_to_float("245"));
	printf ("%f\n", str_to_float("100") + 25);
	printf ("%f\n", str_to_float("13x5"));
	printf ("%f\n", str_to_float("-356"));
	printf ("%f\n", str_to_float("10.221"));
	*/
	return 0;
}
Example #5
0
gint get_statpt(gchar *keyword, struct model_pak *model)
{
int len, tmp;

if (g_ascii_strncasecmp(GMS_METHOD_TXT, keyword, len=strlen(GMS_METHOD_TXT)) == 0)
  {
  tmp = model->gamess.opt_type;
  if (read_keyword(&keyword[len], method_types, &tmp) > 0)
    {
    gui_text_show(ERROR, " unknown method ");
    gui_text_show(ERROR, &keyword[len]);
    gui_text_show(ERROR, " ");
    return(1);
    }
  return(0);
  }
else if (g_ascii_strncasecmp(keyword, GMS_NSTEP_TXT, len=strlen(GMS_NSTEP_TXT)) == 0)
  model->gamess.nstep = str_to_float(&keyword[len]);
else
  {
  gui_text_show(ERROR, " unknown keyword ");
  gui_text_show(ERROR, keyword);
  gui_text_show(ERROR, " ");
  return(1);
  }
return(0);
}
Example #6
0
gint get_system(gchar *keyword, struct model_pak *model)
{
int len;

if (g_ascii_strncasecmp(keyword, GMS_TIMLIM_TXT, len=strlen(GMS_TIMLIM_TXT)) == 0)
  model->gamess.time_limit = (gint) (str_to_float(&keyword[len]));
else if (g_ascii_strncasecmp(keyword, GMS_MWORDS_TXT, len=strlen(GMS_MWORDS_TXT)) == 0)
  model->gamess.mwords = (gint) (str_to_float(&keyword[len]));
else 
  {
  gui_text_show(ERROR, " unknown keyword ");
  gui_text_show(ERROR, keyword);
  gui_text_show(ERROR, " ");
  return(1);
  }
return(0);
}
Example #7
0
static void conf_get_float (s_p_hashtbl_t *t, char *name, float *fp)
{
	char *str;
	if (!s_p_get_string(&str, name, t))
		return;
	if (str_to_float (str, fp) < 0)
		fatal ("cgroup.conf: Invalid value '%s' for %s", str, name);
	xfree(str);
}
Example #8
0
void gui_animate_range_get(gint *range, struct model_pak *model)
{
gint i, max;

range[0] = str_to_float(entry_frame_start);
range[1] = str_to_float(entry_frame_stop);
range[2] = str_to_float(entry_frame_step);

//printf("gui: %d-%d , %d\n", range[0], range[1], range[2]);

/* get current model and check */
if (model)
  {
  max = g_list_length(model->animate_list);

/* following the convention of 1 as first frame ... */
  if (range[0] > 0)
    range[0]--;
  if (range[1] > 0)
    range[1]--;
  else
    range[1] = max-1;

/* check nothing is greater than actual number of frames */
  for (i=3 ; i-- ; )
    {
    if (range[i] > max-1)
      range[i] = max-1;
    }

/* max >= min check */
  if (range[1] < range[0])
    range[1] = max-1;
  }

/* undefined defaults */
if (range[1] < 1)
  range[1] = 1;
if (range[2] < 1)
  range[2] = 1;

//printf("gui_animate_range(): %d-%d , %d\n", range[0], range[1], range[2]);

}
Example #9
0
void xml_parse_shell(const gchar **names, const gchar **values)
{
gint i, n;
gchar **buff;

g_assert(xml_model != NULL);
g_assert(xml_core != NULL);

/* init structure */
if (!xml_shell)
  {
  xml_shell = new_shell(xml_core->atom_label, xml_model);
  xml_model->shels = g_slist_prepend(xml_model->shels, xml_shell);
  }

/* process attributes (if any) */
i=0;
while (*(names+i))
  {
  if (g_ascii_strncasecmp(*(names+i), "xyzf", 4) == 0)
    {
    buff = tokenize(*(values+i), &n);
    if (n > 2)
      {
      xml_core->x[0] = str_to_float(*(buff+0));
      xml_core->x[1] = str_to_float(*(buff+1));
      xml_core->x[2] = str_to_float(*(buff+2));
      xml_model->fractional = TRUE;
      }
    }
  if (g_ascii_strncasecmp(*(names+i), "xf", 2) == 0)
    {
    xml_core->x[0] = str_to_float(*(values+i));
/* FIXME - inefficient to repeat this for all atoms */
/* but may be necessary if every atom is allowed to be cart or fract */
    xml_model->fractional = TRUE;
    }
  if (g_ascii_strncasecmp(*(names+i), "x3", 2) == 0)
    {
    xml_core->x[0] = str_to_float(*(values+i));
/* FIXME - inefficient to repeat this for all atoms */
/* but may be necessary if every atom is allowed to be cart or fract */
    xml_model->fractional = FALSE;
    }

  if (g_ascii_strncasecmp(*(names+i), "yf", 2) == 0 ||
      g_ascii_strncasecmp(*(names+i), "y3", 2) == 0) 
    {
    xml_core->x[1] = str_to_float(*(values+i));
    }
  if (g_ascii_strncasecmp(*(names+i), "zf", 2) == 0 ||
      g_ascii_strncasecmp(*(names+i), "z3", 2) == 0) 
    {
    xml_core->x[2] = str_to_float(*(values+i));
    }
  i++;
  }
}
int main (void)
{
	float str_to_float (char string[]);
		
	printf ("TEST 1 s/b    -10.18   = %8.2f\n", str_to_float ("-10.18"));
	printf ("TEST 2 s/b    245.00   = %8.2f\n", str_to_float ("245"));
	printf ("TEST 3 s/b    125.00   = %8.2f\n", str_to_float ("100") + 25);
	printf ("TEST 4 s/b     13.00   = %8.2f\n", str_to_float ("13x5"));
	printf ("TEST 5 s/b   -356.00   = %8.2f\n", str_to_float ("-356"));
	printf ("TEST 6 s/b     10.22   = %8.3f\n", str_to_float ("10.221"));
	printf ("TEST 7 s/b    101.00   = %8.2f\n", str_to_float ("25.25") * 4);
	printf ("TEST 8 s/b   -867.6921 = %8.4f\n", str_to_float ("-867.6921"));
	printf ("TEST 8 s/b -1,735.3842 = %8.4f\n", str_to_float ("-867.6921") * 2);
	
	return 0;
}
Example #11
0
void zmat_core_add(const gchar *line, gpointer data)
{
gint i, j, num_tokens;
gchar **buff;
struct zmat_pak *zmat = data;
struct zval_pak *zval;

buff = tokenize(line, &num_tokens);

g_assert(num_tokens > 8);

zval = zval_new(); 
zmat->zlines = g_slist_append(zmat->zlines, zval);

/* 1st column atom label */
zval->type = str_to_float(*buff);

/* zmatrix connectivity data */
for (i=1 ; i<4 ; i++)
  zval->connect[i-1] = str_to_float(*(buff+i));

/* zmatrix coordinate data */
j=0;
for (i=4 ; i<7 ; i++)
  {
/* if it's a number -> value, else stored as variable name */
  if (str_is_float(*(buff+i)))
    zval->value[j] = str_to_float(*(buff+i));
  else
    zval->name[j] = g_strdup(*(buff+i));
  j++;
  }

/* zmatrix fitting flags */
for (i=7 ; i<10 ; i++)
  zval->fitting[i-7] = str_to_float(*(buff+i));

g_strfreev(buff);
}
Example #12
0
/**
 * \brief Parse a flippers command [Level 2]
 * \param tokens Command tokens.
 * \param cmd Cmd structure.
 * \return The error result.
 */
static TuxDrvError
parse_tux_flippers_command(tokens_t tokens, delay_cmd_t *cmd)
{
    TuxDrvError ret =  E_TUXDRV_INVALIDCOMMAND;

    if (strcmp(tokens[2], "DOWN") == 0)
    {
        cmd->sub_command = DOWN;
        ret = E_TUXDRV_NOERROR;
    }
    else if (strcmp(tokens[2], "OFF") == 0)
    {
        cmd->sub_command = OFF;
        ret = E_TUXDRV_NOERROR;
    }
    else if (strcmp(tokens[2], "ON") == 0)
    {
        cmd->sub_command = ON;
        if (str_to_uint8(tokens[3], &cmd->flippers_on_parameters.nr_movements) &&
            str_to_state_t(tokens[4], &cmd->flippers_on_parameters.state))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    else if (strcmp(tokens[2], "ON_DURING") == 0)
    {
        cmd->sub_command = ON_DURING;
        if (str_to_float(tokens[3], &cmd->flippers_on_during_parameters.duration) &&
            str_to_state_t(tokens[4], &cmd->flippers_on_during_parameters.state))
        {
            ret = E_TUXDRV_NOERROR;
        }
        cmd->sub_command = ON_DURING;
        ret = E_TUXDRV_NOERROR;
    }
    else if (strcmp(tokens[2], "UP") == 0)
    {
        cmd->sub_command = UP;
        ret = E_TUXDRV_NOERROR;
    }
    else if (strcmp(tokens[2], "SPEED") == 0)
    {
        cmd->sub_command = SPEED;
        if (str_to_uint8(tokens[3], &cmd->flippers_speed_parameters.speed))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    return ret;
}
Example #13
0
gint get_basis(gchar *keyword, struct model_pak *model)
{
gint len, basis;

if (g_ascii_strncasecmp(GMS_BASIS_TXT, keyword, len=strlen(GMS_BASIS_TXT)) == 0)
  {
  if (read_keyword(&keyword[len], basis_types, &basis) > 0)
    {
    gui_text_show(ERROR, " unknown basis ");
    gui_text_show(ERROR, &keyword[len]);
    gui_text_show(ERROR, " ");
    return(1);
    }
  model->gamess.basis = basis;
  return(0);
  }
else if (g_ascii_strncasecmp(keyword, GMS_NGAUSS_TXT, len=strlen(GMS_NGAUSS_TXT)) == 0)
  model->gamess.ngauss = (gint) (str_to_float(&keyword[len]));
else if (g_ascii_strncasecmp(keyword, GMS_NUM_P_TXT, len=strlen(GMS_NUM_P_TXT)) == 0)
  model->gamess.num_p = str_to_float(&keyword[len]);
else if (g_ascii_strncasecmp(keyword, GMS_NUM_D_TXT, len=strlen(GMS_NUM_D_TXT)) == 0)
  model->gamess.num_d = str_to_float(&keyword[len]);
else if (g_ascii_strncasecmp(keyword, GMS_NUM_F_TXT, len=strlen(GMS_NUM_F_TXT)) == 0)
  model->gamess.num_f = str_to_float(&keyword[len]);
else if (g_ascii_strncasecmp(keyword, GMS_DIFFSP_TXT, len=strlen(GMS_DIFFSP_TXT)) == 0)
  model->gamess.have_heavy_diffuse = TRUE;
else if (g_ascii_strncasecmp(keyword, GMS_DIFFS_TXT, len=strlen(GMS_DIFFS_TXT)) == 0)
  model->gamess.have_hydrogen_diffuse = TRUE;
else 
  {
  gui_text_show(ERROR, " unknown keyword ");
  gui_text_show(ERROR, keyword);
  gui_text_show(ERROR, " ");
  return(1);
  }
return(0);
}
Example #14
0
int xml_config_get_float(const xml_config_t *config, const char *pattern,
						 float *val)
{
	char *str;
	int ret;

	if (!(str = xml_config_get_str(config, pattern))) {
		return -1;
	}

	ret = str_to_float(str, val);
	free(str);

	return ret;
}
Example #15
0
gdouble zmat_table_lookup(const gchar *name, gpointer data)
{
const gchar *value;
struct zmat_pak *zmat = data;

g_assert(data != NULL);

value = g_hash_table_lookup(zmat->vars, name);
if (!value)
  value = g_hash_table_lookup(zmat->consts, name);

if (value)
  return(str_to_float(value));

return(0.0);
}
Example #16
0
/**
 * \brief Parse a sound flash command [Level 2]
 * \param tokens Command tokens.
 * \param cmd Cmd structure.
 * \return The error result.
 */
static TuxDrvError
parse_tux_sound_flash_command(tokens_t tokens, delay_cmd_t *cmd)
{
    TuxDrvError ret =  E_TUXDRV_INVALIDCOMMAND;

    if (strcmp(tokens[2], "PLAY") == 0)
    {
        cmd->sub_command = PLAY;
        if (str_to_uint8(tokens[3], &cmd->sound_flash_play_parameters.track) &&
            str_to_float(tokens[4], &cmd->sound_flash_play_parameters.volume))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    return ret;
}
Example #17
0
void xml_parse_spatial(const gchar **names, const gchar **values)
{
gint i, periodic=-1;

g_assert(xml_model != NULL);

i=0;
while (*(names+i))
  {
  if (g_ascii_strncasecmp(*(names+i), "periodic", 8) == 0)
    periodic = str_to_float(*(values+i));
/* TODO - more details */
  i++;
  }

xml_spatial = spatial_new(NULL, SPATIAL_GENERIC, 0, periodic, xml_model);
}
Example #18
0
void xml_parse_vertex(const gchar **names, const gchar **values)
{
gint i=0;
gdouble x[3], n[3], c[3];

g_assert(xml_spatial != NULL);

VEC3SET(x, 0.0, 0.0, 0.0);
VEC3SET(n, 0.0, 0.0, 0.0);
VEC3SET(c, 0.0, 0.0, 0.0);

while (*(names+i))
  {
  if (g_ascii_strncasecmp(*(names+i), "red", 3) == 0)
    c[0] = str_to_float(*(values+i));
  if (g_ascii_strncasecmp(*(names+i), "green", 5) == 0)
    c[1] = str_to_float(*(values+i));
  if (g_ascii_strncasecmp(*(names+i), "blue", 4) == 0)
    c[2] = str_to_float(*(values+i));

  if (g_ascii_strncasecmp(*(names+i), "x3", 2) == 0)
    x[0] = str_to_float(*(values+i));
  if (g_ascii_strncasecmp(*(names+i), "y3", 2) == 0)
    x[1] = str_to_float(*(values+i));
  if (g_ascii_strncasecmp(*(names+i), "z3", 2) == 0)
    x[2] = str_to_float(*(values+i));

  if (g_ascii_strncasecmp(*(names+i), "nx", 2) == 0)
    n[0] = str_to_float(*(values+i));
  if (g_ascii_strncasecmp(*(names+i), "ny", 2) == 0)
    n[1] = str_to_float(*(values+i));
  if (g_ascii_strncasecmp(*(names+i), "nz", 2) == 0)
    n[2] = str_to_float(*(values+i));

  i++;
  }
spatial_vnorm_add(x, n, c, xml_spatial);
}
Example #19
0
void show_phonon_components(struct model_pak *model)
{
gdouble f, lc, lf, xc[3], xf[3];
gpointer ptr;
GSList *list;
struct core_pak *core;

/* checks */
if (!model)
  return;

/* get required mode to analyse */
ptr = g_slist_nth_data(model->phonons, model->current_phonon-1);
if (!ptr)
  return;
f = str_to_float(ptr);

printf("--------------------------------------------------------------------------\n");
printf("Mode: %d, Frequency = %f\n", model->current_phonon, f);
printf("--------------------------------------------------------------------------\n");
printf("  atom  |   len   |     x        y        z    |      a        b        c\n");
printf("--------------------------------------------------------------------------\n");

for (list=model->selection ; list; list=g_slist_next(list))
  {
  core = (struct core_pak *) list->data;

/* get eigen-vector components */
  xc[0] = *((gdouble *) g_slist_nth_data(core->vibx_list, model->current_phonon-1));
  xc[1] = *((gdouble *) g_slist_nth_data(core->viby_list, model->current_phonon-1));
  xc[2] = *((gdouble *) g_slist_nth_data(core->vibz_list, model->current_phonon-1));
  ARR3SET(xf, xc);
  vecmat(model->ilatmat, xf);

  lc = VEC3MAG(xc);
  lf = VEC3MAG(xf);

  VEC3MUL(xc, 1.0/lc);
  VEC3MUL(xf, 1.0/lf);

  printf("%6s  | %7.4f | %7.2f  %7.2f  %7.2f  |  %7.2f  %7.2f  %7.2f\n",
          core->atom_label, lc, xc[0], xc[1], xc[2], xf[0], xf[1], xf[2]);

  }
}
Example #20
0
extern float attr_get_float(attr attrs, const char *name, float def)
{
	float res;
	int rc;

	const char *str_val = attr_get_str(attrs,name, NULL);

	if(!str_val) {
		return def;
	}

	rc = str_to_float(str_val, &res);

	if(rc) {
		/* format error? */
		return def;
	} else {
		return res;
	}
}
Example #21
0
void show_active(GSList *list, struct model_pak *model)
{
gint n;
gchar *freq;
gdouble intensity;
GSList *item;

n = 0;
for (item=list ; item ; item=g_slist_next(item))
  {
  intensity = str_to_float(item->data);

  if (intensity > 0.001)
    {
    freq = g_slist_nth_data(model->phonons, n);
    if (freq)
      printf(" %6d | %13s | %f\n", n+1, freq, intensity);
    }
  n++;
  } 
}
Example #22
0
/**
 * \brief Parse a mouth command [Level 2]
 * \param tokens Command tokens.
 * \param cmd Cmd structure.
 * \return The error result.
 */
static TuxDrvError
parse_tux_mouth_command(tokens_t tokens, delay_cmd_t *cmd)
{
    TuxDrvError ret =  E_TUXDRV_INVALIDCOMMAND;

    if (strcmp(tokens[2], "CLOSE") == 0)
    {
        cmd->sub_command = CLOSE;
        ret = E_TUXDRV_NOERROR;
    }
    else if (strcmp(tokens[2], "OFF") == 0)
    {
        cmd->sub_command = OFF;
        ret = E_TUXDRV_NOERROR;
    }
    else if (strcmp(tokens[2], "ON") == 0)
    {
        cmd->sub_command = ON;
        if (str_to_uint8(tokens[3], &cmd->mouth_on_parameters.nr_movements) &&
            str_to_state_t(tokens[4], &cmd->mouth_on_parameters.state))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    else if (strcmp(tokens[2], "ON_DURING") == 0)
    {
        cmd->sub_command = ON_DURING;
        if (str_to_float(tokens[3], &cmd->mouth_on_during_parameters.duration) &&
            str_to_state_t(tokens[4], &cmd->mouth_on_during_parameters.state))
        {
            ret = E_TUXDRV_NOERROR;
        }
    }
    else if (strcmp(tokens[2], "OPEN") == 0)
    {
        cmd->sub_command = OPEN;
        ret = E_TUXDRV_NOERROR;
    }
    return ret;
}
Example #23
0
void xml_parse_text(GMarkupParseContext *context,
                    const gchar *text,
                    gsize text_len,  
                    gpointer user_data,
                    GError **error)
{
switch (xml_context)
  {
/* specific cell contexts */
  case XML_CELL_A:
    xml_model->pbc[0] = str_to_float(text);
/* revert to general cell value context */
    xml_context = XML_CELL;
    break;
  case XML_CELL_B:
    xml_model->pbc[1] = str_to_float(text);
/* revert to general cell value context */
    xml_context = XML_CELL;
    break;
  case XML_CELL_C:
    xml_model->pbc[2] = str_to_float(text);
/* revert to general cell value context */
    xml_context = XML_CELL;
    break;
  case XML_CELL_ALPHA:
    xml_model->pbc[3] = D2R * str_to_float(text);
/* revert to general cell value context */
    xml_context = XML_CELL;
    break;
  case XML_CELL_BETA:
    xml_model->pbc[4] = D2R * str_to_float(text);
/* revert to general cell value context */
    xml_context = XML_CELL;
    break;
  case XML_CELL_GAMMA:
    xml_model->pbc[5] = D2R * str_to_float(text);
/* revert to general cell value context */
    xml_context = XML_CELL;
    break;

  case XML_PICTURE:
    xml_model->picture_list = g_slist_append(xml_model->picture_list,
                                         g_strstrip(g_strdup(text)));
    break;
  }
}
Example #24
0
int  dev_gen_sen_oper_sen_value (INT16S u16_inst_id, INT8U u8_oper, void *ptr_value)
{
  int total_len;
  FRACTION f_value;
  if (u8_oper == LWM2M_RESOURCE_OPERATION_READ)
  {
    #if  FIXED_POINT
	{
	  q2a(ptr_value, f_gen_sen );
	} 
    #endif
    #if FLOAT_POINT
	{
      (*(FRACTION *)ptr_value) = f_gen_sen; 
	} 
    #endif
  }
  else if (u8_oper == LWM2M_RESOURCE_OPERATION_WRITE)
  {
    #if  FIXED_POINT
    {
      f_value = a2q((FRACTION *)ptr_value);
	  f_gen_sen = f_value;
	  return 0;
	}
	#endif  
    #if  FLOAT_POINT
	{ 
	  total_len = strlen(( INT8U*)ptr_value);
      f_value = str_to_float(ptr_value, total_len);
	  f_gen_sen = f_value;
	  return 0;
	}
    #endif     
  }
  return 0;
}
Example #25
0
/* TEMP - parse diffax sfc data */
void parse_sfc(FILE *fp)
{
gint i, n;
gchar *line, *type, **buff;
gdouble *sfc;
GSList *list;

while ((line = file_read_line(fp)))
  {
  type = g_strstrip(g_strndup(line, 6));

  if (elem_symbol_test(type))
    {
/* tokenize everything after the atom type */
    buff = tokenize(&line[6], &n);

printf("[%s] ", type);
    list = NULL;
    for (i=0 ; i<n ; i++)
      {
      sfc = g_malloc(sizeof(gdouble));
      *sfc = str_to_float(*(buff+i));

printf("[%f] ", *sfc);
      list = g_slist_prepend(list, sfc);
      }
    list = g_slist_reverse(list);
printf("\n");

    g_hash_table_insert(sysenv.sfc_table, type, list);

    g_strfreev(buff);
    }
  g_free(line);
  }
}
Example #26
0
gint read_aims(gchar *filename, struct model_pak *model)
{
gint i, num_tokens;
gchar **buff;
gpointer scan;
struct core_pak *core;

g_assert(model != NULL);

scan = scan_new(filename);
if (!scan) return(1);

while (!scan_complete(scan)) {

  buff = scan_get_tokens(scan, &num_tokens);

/* 
   for debugging purposes 
   produces a compiler warning about an
	implicit declaration of function 'g_printf'
   though this is a valid glib function since 2.2
	http://library.gnome.org/devel/glib/2.18/glib-String-Utility-Functions.html#g-printf
*/
/*
  for (i=0; i<num_tokens; i++) {
	g_printf(" %s ", buff[i]);
  }
  printf("\n");
*/

  if (!buff) break;

  /* read cell vectors */
  if ( g_strrstr(*buff, "lattice_vector") != NULL ) {
     for (i=0 ; i<3 ; i++) {
         if (num_tokens >= 3) {
            model->latmat[i] = str_to_float(*(buff+1));
            model->latmat[i+3] = str_to_float(*(buff+2));
            model->latmat[i+6] = str_to_float(*(buff+3));
         }
         else { 
            gui_text_show(ERROR, "error reading AIMS lattice vectors \n"); 
            return(2);
         }
         g_strfreev(buff);
         buff = scan_get_tokens(scan, &num_tokens);
     }
     model->periodic = 3;
     model->construct_pbc = TRUE;
  }

  /* read coordinates */
  if ( g_strrstr(*buff, "atom") != NULL ) {
     if ( ( num_tokens >= 4 ) && ( elem_symbol_test(*(buff+4)) ) ) {
        core = new_core(*(buff+4), model);
        core->x[0] = str_to_float(*(buff+1));
        core->x[1] = str_to_float(*(buff+2));
        core->x[2] = str_to_float(*(buff+3));
        model->cores = g_slist_prepend(model->cores, core);
     }
     else {
        gui_text_show(ERROR, "error reading AIMS lattice vectors \n"); 
        return(2);
     }
  }

  g_strfreev(buff);
}

/* done reading */
scan_free(scan);

/* model setup */
g_free(model->filename);
model->filename = g_strdup(filename);

g_free(model->basename);
model->basename = g_path_get_basename(filename);

model->fractional = FALSE;
model_prep(model);

return(0);
}
Example #27
0
File: parse.c Project: CodeMonk/fio
static int __handle_option(struct fio_option *o, const char *ptr, void *data,
			   int first, int more, int curr)
{
	int il=0, *ilp;
	fio_fp64_t *flp;
	long long ull, *ullp;
	long ul1, ul2;
	double uf;
	char **cp = NULL;
	int ret = 0, is_time = 0;
	const struct value_pair *vp;
	struct value_pair posval[PARSE_MAX_VP];
	int i, all_skipped = 1;

	dprint(FD_PARSE, "__handle_option=%s, type=%d, ptr=%s\n", o->name,
							o->type, ptr);

	if (!ptr && o->type != FIO_OPT_STR_SET && o->type != FIO_OPT_STR) {
		log_err("Option %s requires an argument\n", o->name);
		return 1;
	}

	switch (o->type) {
	case FIO_OPT_STR:
	case FIO_OPT_STR_MULTI: {
		fio_opt_str_fn *fn = o->cb;

		posval_sort(o, posval);

		ret = 1;
		for (i = 0; i < PARSE_MAX_VP; i++) {
			vp = &posval[i];
			if (!vp->ival || vp->ival[0] == '\0')
				continue;
			all_skipped = 0;
			if (!strncmp(vp->ival, ptr, str_match_len(vp, ptr))) {
				ret = 0;
				if (o->off1)
					val_store(ilp, vp->oval, o->off1, vp->orval, data, o);
				continue;
			}
		}

		if (ret && !all_skipped)
			show_option_values(o);
		else if (fn)
			ret = fn(data, ptr);
		break;
	}
	case FIO_OPT_STR_VAL_TIME:
		is_time = 1;
	case FIO_OPT_INT:
	case FIO_OPT_STR_VAL: {
		fio_opt_str_val_fn *fn = o->cb;
		char tmp[128], *p;

		if (!is_time && o->is_time)
			is_time = o->is_time;

		tmp[sizeof(tmp) - 1] = '\0';
		strncpy(tmp, ptr, sizeof(tmp) - 1);
		p = strchr(tmp, ',');
		if (p)
			*p = '\0';

		if (is_time)
			ret = check_str_time(tmp, &ull, o->is_seconds);
		else
			ret = check_str_bytes(tmp, &ull, data);

		dprint(FD_PARSE, "  ret=%d, out=%llu\n", ret, ull);

		if (ret)
			break;

		if (o->maxval && ull > o->maxval) {
			log_err("max value out of range: %llu"
					" (%u max)\n", ull, o->maxval);
			return 1;
		}
		if (o->minval && ull < o->minval) {
			log_err("min value out of range: %llu"
					" (%u min)\n", ull, o->minval);
			return 1;
		}
		if (o->posval[0].ival) {
			posval_sort(o, posval);

			ret = 1;
			for (i = 0; i < PARSE_MAX_VP; i++) {
				vp = &posval[i];
				if (!vp->ival || vp->ival[0] == '\0')
					continue;
				if (vp->oval == ull) {
					ret = 0;
					break;
				}
			}
			if (ret) {
				log_err("fio: value %llu not allowed:\n", ull);
				show_option_values(o);
				return 1;
			}
		}

		if (fn)
			ret = fn(data, &ull);
		else {
			if (o->type == FIO_OPT_INT) {
				if (first)
					val_store(ilp, ull, o->off1, 0, data, o);
				if (curr == 1) {
					if (o->off2)
						val_store(ilp, ull, o->off2, 0, data, o);
				}
				if (curr == 2) {
					if (o->off3)
						val_store(ilp, ull, o->off3, 0, data, o);
				}
				if (!more) {
					if (curr < 1) {
						if (o->off2)
							val_store(ilp, ull, o->off2, 0, data, o);
					}
					if (curr < 2) {
						if (o->off3)
							val_store(ilp, ull, o->off3, 0, data, o);
					}
				}
			} else {
				if (first)
					val_store(ullp, ull, o->off1, 0, data, o);
				if (!more) {
					if (o->off2)
						val_store(ullp, ull, o->off2, 0, data, o);
				}
			}
		}
		break;
	}
	case FIO_OPT_FLOAT_LIST: {
		char *cp2;

		if (first) {
			/*
			** Initialize precision to 0 and zero out list
			** in case specified list is shorter than default
			*/
			if (o->off2) {
				ul2 = 0;
				ilp = td_var(data, o, o->off2);
				*ilp = ul2;
			}

			flp = td_var(data, o, o->off1);
			for(i = 0; i < o->maxlen; i++)
				flp[i].u.f = 0.0;
		}
		if (curr >= o->maxlen) {
			log_err("the list exceeding max length %d\n",
					o->maxlen);
			return 1;
		}
		if (!str_to_float(ptr, &uf, 0)) { /* this breaks if we ever have lists of times */
			log_err("not a floating point value: %s\n", ptr);
			return 1;
		}
		if (uf > o->maxfp) {
			log_err("value out of range: %f"
				" (range max: %f)\n", uf, o->maxfp);
			return 1;
		}
		if (uf < o->minfp) {
			log_err("value out of range: %f"
				" (range min: %f)\n", uf, o->minfp);
			return 1;
		}

		flp = td_var(data, o, o->off1);
		flp[curr].u.f = uf;

		dprint(FD_PARSE, "  out=%f\n", uf);

		/*
		** Calculate precision for output by counting
		** number of digits after period. Find first
		** period in entire remaining list each time
		*/
		cp2 = strchr(ptr, '.');
		if (cp2 != NULL) {
			int len = 0;

			while (*++cp2 != '\0' && *cp2 >= '0' && *cp2 <= '9')
				len++;

			if (o->off2) {
				ilp = td_var(data, o, o->off2);
				if (len > *ilp)
					*ilp = len;
			}
		}

		break;
	}
	case FIO_OPT_STR_STORE: {
		fio_opt_str_fn *fn = o->cb;

		if (!strlen(ptr))
			return 1;

		if (o->off1) {
			cp = td_var(data, o, o->off1);
			*cp = strdup(ptr);
		}

		if (fn)
			ret = fn(data, ptr);
		else if (o->posval[0].ival) {
			posval_sort(o, posval);

			ret = 1;
			for (i = 0; i < PARSE_MAX_VP; i++) {
				vp = &posval[i];
				if (!vp->ival || vp->ival[0] == '\0' || !cp)
					continue;
				all_skipped = 0;
				if (!strncmp(vp->ival, ptr, str_match_len(vp, ptr))) {
					char *rest;

					ret = 0;
					if (vp->cb)
						fn = vp->cb;
					rest = strstr(*cp ?: ptr, ":");
					if (rest) {
						if (*cp)
							*rest = '\0';
						ptr = rest + 1;
					} else
						ptr = NULL;
					break;
				}
			}
		}

		if (!all_skipped) {
			if (ret && !*cp)
				show_option_values(o);
			else if (ret && *cp)
				ret = 0;
			else if (fn && ptr)
				ret = fn(data, ptr);
		}

		break;
	}
Example #28
0
gint read_gms_out(gchar *filename, struct model_pak *model)
{
gint flag, frame, num_tokens, len, i, index, bad_andrew;
gchar **buff, line[LINELEN], *keyword, *option;
GString *property_string;
FILE *fp;

fp = fopen(filename, "rt");
if (!fp)
  {
  sprintf(line, "Unable to open file %s\n", filename);
  gui_text_show(ERROR, line);
  return(1);
  }

model->periodic = 0;
flag=frame=0;

/* read in BASIS OPTIONS */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, "     BASIS OPTIONS", 18) == 0)
    {
    /* skip line */
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading basis options\n");
      return(2);
      }
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading basis options\n");
      return(2);
      }
    /* get first line of options i.e. basis set */
    buff = tokenize(line, &num_tokens); 
    /* GBASIS=STO          IGAUSS=       3      POLAR=NONE */
    keyword = *(buff+0);
    if (g_ascii_strncasecmp(keyword, GMS_BASIS_TXT, len = strlen(GMS_BASIS_TXT)) == 0)
      {
      if (read_keyword(&keyword[len], basis_types, &bad_andrew) > 0)
        {
        sprintf(line, "invalid basis %s\n", &keyword[len]);
        gui_text_show(ERROR, line);
        return(3);
        }
      model->gamess.basis = bad_andrew;
      }
    model->gamess.ngauss = (gint) str_to_float(*(buff+2));
    g_strfreev(buff);
    
    /* get 2nd line of options i.e. NDFUNC and DIFFSP */
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading basis options\n");
      return(2);
      }
    buff = tokenize(line, &num_tokens);
    /* NDFUNC=       0     DIFFSP=       F */
    model->gamess.num_d = str_to_float(*(buff+1));
    if (g_ascii_strncasecmp(*(buff+3), "F", 1) == 0)
      model->gamess.have_heavy_diffuse = FALSE;
    else
      model->gamess.have_heavy_diffuse = TRUE;
    g_strfreev(buff);
      
    /* get 3rd line of options i.e. MULT and ICHARG */
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading basis options\n");
      return(2);
      }
    buff = tokenize(line, &num_tokens);
    /* NPFUNC=       0      DIFFS=       F */
    model->gamess.num_p = (gint) str_to_float(*(buff+1));
    if (g_ascii_strncasecmp(*(buff+3), "F", 1) == 0)
      model->gamess.have_hydrogen_diffuse = FALSE;
    else
      model->gamess.have_hydrogen_diffuse = TRUE;
    g_strfreev(buff);
      
    /* TODO f functions */
	flag++;
	break;
	}
  }

if (!flag)
  {
   /* no basis present so set to user defined and rewind file */
   model->gamess.basis = GMS_USER;
   rewind(fp);
  }
flag=0;

/* read in RUN TITLE */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, "     RUN TITLE", 14) == 0)
    {
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading title\n");
      return(2);
      }
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading title\n");
      return(2);
      }
    model->gamess.title = g_strdup(g_strstrip(line));
    flag++;
    break;
    }
  }

if (!flag)
  {
   gui_text_show(ERROR, "RUN TITLE not found\n");
   return(2);
  }
flag=0;

/* read in $CONTRL OPTIONS */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, "     $CONTRL OPTIONS", 20) == 0)
    {
    flag++;
    if (fgetline(fp, line))
      /* skip line of dashes */
      {
      gui_text_show(ERROR, "unexpected end of file reading contrl options\n");
      return(3);
      }
    while (TRUE)
      {
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading contrl options\n");
        return(3);
        }
      /* is the line the blank line signalling end of control options? */
      if (strlen(g_strchug(line)) == 0)
        break;
      /* break up line into option pairs */
      /* each pair takes 15 characters with 5 characters between them */
      /* note that we have already removed the single space in front of the lines with the g_strchug */
      index = 0;
      while (index+15 <= strlen(line))
        {
        option = g_strndup(line+index, 15);
        /* split into pair */
        buff = g_strsplit(option, "=", 2);
        g_free(option);
        /* remove whitespace */
        g_strstrip(buff[0]);
        g_strstrip(buff[1]);
        /* the compare strings end in = which we have stripped off so compare on strlen-1 */
        if (g_ascii_strncasecmp(buff[0], GMS_SCFTYPE_TXT, strlen(GMS_SCFTYPE_TXT) - 1) == 0)
          {
          if (read_keyword(buff[1], scf_types, &bad_andrew) > 0)
            {
            sprintf(line, "invalid scf type %s\n", buff[1]);
            gui_text_show(ERROR, line);
            return(3);
            }
          model->gamess.scf_type = bad_andrew;
          }
        else if (g_ascii_strncasecmp(buff[0], GMS_RUNTYPE_TXT, strlen(GMS_RUNTYPE_TXT) - 1) == 0)
          {
          if (read_keyword(buff[1], run_types, &bad_andrew) > 0)
            {
            sprintf(line, "invalid run type %s\n", buff[1]);
            gui_text_show(ERROR, line);
            return(3);
            }
          model->gamess.run_type = bad_andrew;
            property_string = g_string_new("");
            i=0;
            while (run_types[i].label)
              {
              if (model->gamess.run_type == run_types[i].id)
                g_string_append_printf(property_string, "%s", run_types[i].label);
              i++;
              }
            property_string->str[0] = g_ascii_toupper(property_string->str[0]);
            property_add_ranked(2, "Calculation", property_string->str, model);
            g_string_free(property_string, TRUE); 
          }
        else if (g_ascii_strncasecmp(buff[0], GMS_EXETYPE_TXT, strlen(GMS_EXETYPE_TXT) - 1) == 0)
          {
          if (read_keyword(buff[1], exe_types, &bad_andrew) > 0)
            {
            sprintf(line, "invalid execution type %s\n", buff[1]);
            gui_text_show(ERROR, line);
            return(3);
            }
          model->gamess.exe_type = bad_andrew;
          }
        else if (g_ascii_strncasecmp(buff[0], GMS_MPLEVEL_TXT, strlen(GMS_MPLEVEL_TXT) - 1) == 0)
        	model->gamess.MP_level = (gint) str_to_float(buff[1]);
        else if (g_ascii_strncasecmp(buff[0], GMS_CITYP_TXT, strlen(GMS_CITYP_TXT) - 1) == 0)
          if (g_ascii_strncasecmp(buff[1], "none", 4) == 0)
            model->gamess.have_CI = FALSE;
          else
            model->gamess.have_CI = TRUE;
        else if (g_ascii_strncasecmp(buff[0], GMS_CCTYP_TXT, strlen(GMS_CCTYP_TXT) - 1) == 0)
          if (g_ascii_strncasecmp(buff[1], "none", 4) == 0)
            model->gamess.have_CC = FALSE;
          else
            model->gamess.have_CC = TRUE;
        else if (g_ascii_strncasecmp(buff[0], GMS_TOTAL_Q_TXT, strlen(GMS_TOTAL_Q_TXT) - 1) == 0)
          model->gamess.total_charge = (gint) str_to_float(buff[1]);
        else if (g_ascii_strncasecmp(buff[0], GMS_MULT_TXT, strlen(GMS_MULT_TXT) - 1) == 0)
          model->gamess.multiplicity = (gint) str_to_float(buff[1]);
        else if (g_ascii_strncasecmp(buff[0], GMS_MAXIT_TXT, strlen(GMS_MAXIT_TXT) - 1) == 0)
          model->gamess.maxit = ((gint) str_to_float(buff[1]));
        else if (g_ascii_strncasecmp(buff[0], GMS_WIDE_OUTPUT_TXT, strlen(GMS_WIDE_OUTPUT_TXT) - 1) == 0)   
         model->gamess.wide_output = ((gint) str_to_float(buff[1]) == 6);

        g_strfreev(buff);
        index += 20;
        }
      }
      break;
    }
  }

if (!flag)
  {
/* don't return... model_prep() needs to be called to avoid crashing */
   gui_text_show(WARNING, "$CONTRL OPTIONS not found\n");
  }
flag=0;

/* read in $SYSTEM OPTIONS */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, "     $SYSTEM OPTIONS", 20) == 0)
    {
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading system options\n");
      return(4);
      }
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading system options\n");
      return(4);
      }
    buff = tokenize(line, &num_tokens);
    model->gamess.mwords = (gint) (str_to_float(*(buff+2))/1000000);
    g_strfreev(buff);
    
    for (i=0; i<4; i++)
      {
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading system options\n");
        return(4);
        }
      }
    buff = tokenize(line, &num_tokens);
    model->gamess.time_limit = (gint) (str_to_float(*(buff+1))/60.0);
    g_strfreev(buff);
    flag++;
    break;
    }
  }

if (!flag)
  {
/* don't return... model_prep() needs to be called to avoid crashing */
   gui_text_show(WARNING, "$SYSTEM OPTIONS not found\n");
  }
flag=0;

/* anything else to find ? */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, "                         GRADIENT OF THE ENERGY", 47) == 0)
    {
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading gradient\n");
      return(5);
      }
    while (g_ascii_strncasecmp(line, "                   MAXIMUM GRADIENT", 35) != 0) 
      {
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading gradient\n");
        return(5);
        }
      }
      buff = tokenize(line, &num_tokens);
      model->gamess.max_grad = str_to_float(*(buff+3));
      model->gamess.have_max_grad = TRUE;
      g_strfreev(buff);
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading gradient\n");
        return(5);
        }
      buff = tokenize(line, &num_tokens);
      model->gamess.rms_grad = str_to_float(*(buff+3));
      model->gamess.have_rms_grad = TRUE;
      g_strfreev(buff);
    }
  }

rewind(fp);

/* Read the input coordinates - single frame has different format to multiframe */
if (model->gamess.run_type < GMS_OPTIMIZE) { /* is it a single frame job? */
  while (!fgetline(fp, line))
    {
    if (g_ascii_strncasecmp(line, " ATOM      ATOMIC                      COORDINATES (BOHR)", 57) == 0)
      {
      read_gms_out_block(fp, model, 1, TRUE);
      flag++;
      break;
      }
    }
  }

else
  {
  /* get optimisation parameters */
  while (!fgetline(fp, line))
    {
    if (g_ascii_strncasecmp(line, "          STATIONARY POINT LOCATION RUN", 39) == 0)
      {
      for (i=0; i<7; i++)
        {
        if (fgetline(fp, line))
          {
          gui_text_show(ERROR, "unexpected end of file reading optimizer options\n");
          return(5);
          }
        }
      if (model->gamess.exe_type == GMS_CHECK)
        if (fgetline(fp, line))
          {
          gui_text_show(ERROR, "unexpected end of file reading optimizer options\n");
          return(5);
          }
      buff = tokenize(line, &num_tokens);
      if (read_keyword(&(*(buff+1))[1], method_types, &bad_andrew) > 0)
        {
        sprintf(line, "invalid method %s\n",&(*(buff+1))[1]);
        gui_text_show(ERROR, line);
        return(5);
        }
      model->gamess.opt_type = bad_andrew;
      g_strfreev(buff);
      flag++;
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading optimizer options\n");
        return(5);
        }
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading optimizer options\n");
        return(5);
        }
      buff = tokenize(line, &num_tokens);
      model->gamess.nstep = str_to_float(*(buff+2));
      g_strfreev(buff);
      flag++;
      break;
      }
    }
  if (!flag)
    {
    gui_text_show(ERROR, "optimizer options not found\n");
    return(5);
    }
  /* Are there any coordinates from a minimisation? */
  flag=0;
  while (!fgetline(fp, line) && !model->gamess.converged)
    {
    /* coordinates */
    if (g_ascii_strncasecmp(line, " COORDINATES OF ALL ATOMS ARE", 29) == 0)
      {
      /* go through all frames to count them */
      add_frame_offset(fp, model);
      read_gms_out_block(fp, model, 2, FALSE);
      flag++;
      frame++;
      }
    }
  }

/*  property_string = g_string_new("");
  g_string_append_printf(property_string, "%.0f", model->gamess.total_charge);
  property_add_ranked(2, "Total Charge", property_string->str, model);
  g_string_free(property_string, TRUE); 
  property_string = g_string_new("");
  g_string_append_printf(property_string, "%.0f", model->gamess.multiplicity);
  property_add_ranked(3, "Multiplicity", property_string->str, model);
  g_string_free(property_string, TRUE); */

  property_string = g_string_new("");
  i=0;
  while (basis_sets[i].label)
    {
    if ((basis_sets[i].basis == model->gamess.basis) && (basis_sets[i].ngauss == model->gamess.ngauss))
      g_string_append_printf(property_string, "%s", basis_sets[i].label);
    i++;
    }
  property_add_ranked(7, "Basis", property_string->str, model);
  g_string_free(property_string, TRUE); 

/* done */

if (flag)
  {
  /* set frame if don't want last? */
  strcpy(model->filename, filename);
  g_free(model->basename);
  model->basename = parse_strip(filename);

  model->num_frames = model->cur_frame = frame;
  model->cur_frame--;
  
  model_prep(model);
  }
else
  return(2);

return(0);
}
Example #29
0
gint read_gms_out_block(FILE *fp, struct model_pak *model, gint num_skip, gint bohr)
{
gint i, num_tokens;
gchar **buff, line[LINELEN];
GString *title, *energy_string, *grad_string;
GSList *clist;
struct core_pak *core;

clist = model->cores;

/* ignore first num_skip lines */
for (i=0 ; i<num_skip; i++)
  if (fgetline(fp, line))
    {
    gui_text_show(ERROR, "unexpected end of file reading coordinates\n");
    return(11);
    }

model->construct_pbc = FALSE;
model->fractional = FALSE;

/* get 1st line of coords */
if (fgetline(fp, line))
    {
    gui_text_show(ERROR, "unexpected end of file reading coordinates\n");
    return(11);
    }
buff = tokenize(line, &num_tokens);

while (num_tokens > 4)
  {
  if (clist)
    {
    core = clist->data;
    clist = g_slist_next(clist);
    }
  else
    {
    core = new_core(elements[(int) str_to_float(*(buff+1))].symbol, model);
    model->cores = g_slist_append(model->cores, core);
    }

  if (bohr)
    {
    core->x[0] = BOHR_TO_ANGS*str_to_float(*(buff+2));
    core->x[1] = BOHR_TO_ANGS*str_to_float(*(buff+3));
    core->x[2] = BOHR_TO_ANGS*str_to_float(*(buff+4));
    }
  else
    {
    core->x[0] = str_to_float(*(buff+2));
    core->x[1] = str_to_float(*(buff+3));
    core->x[2] = str_to_float(*(buff+4));
    }

/* get next line */
  g_strfreev(buff);
  if (fgetline(fp, line))
    {
    gui_text_show(ERROR, "unexpected end of file reading coordinates\n");
    return(11);
    }
  buff = tokenize(line, &num_tokens);
  }
g_strfreev(buff);
  
/* search for energy */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, " FINAL", 6) == 0)
    {
    buff = tokenize(line, &num_tokens);
    if (g_ascii_strncasecmp(*(buff+1), "ENERGY", 6) == 0)
      model->gamess.energy = str_to_float(*(buff+3));
    else
      model->gamess.energy = str_to_float(*(buff+4));
    model->gamess.have_energy = TRUE;
    g_strfreev(buff);
    break;
    }
  }

/* update for MP? */
if (model->gamess.MP_level > 0)
  {
  while (!fgetline(fp, line))
    {
    if (g_strrstr(line ,"E(MP2)") != NULL)
      {
      buff = tokenize(line, &num_tokens);
      model->gamess.energy = str_to_float(*(buff+1));
      model->gamess.have_energy = TRUE;
      g_strfreev(buff);
      break;
      }
    }
  }

/* search for gradient and read any properties */
while (!fgetline(fp, line))
  {
  if (g_ascii_strncasecmp(line, " NET CHARGES:", 13) == 0)
    {
    clist = model->cores;
    /* skip forward four lines */
    for (i=0 ; i<4; i++)
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading fitted charges\n");
        return(11);
        }
    while (clist != NULL)
      {
      buff = tokenize(line, &num_tokens);
      core = clist->data;
      core->lookup_charge = FALSE;
      core->charge = str_to_float(*(buff+1));
      g_strfreev(buff);
      clist = g_slist_next(clist);
      if (fgetline(fp, line))
        {
        gui_text_show(ERROR, "unexpected end of file reading fitted charges\n");
        return(11);
        }
      }
    }
  if (g_ascii_strncasecmp(line, "          MAXIMUM GRADIENT", 26) == 0)
    {
    buff = tokenize(line, &num_tokens);
    model->gamess.max_grad = str_to_float(*(buff+3));
    model->gamess.have_max_grad = TRUE;
    model->gamess.rms_grad = str_to_float(*(buff+7));
    model->gamess.have_rms_grad = TRUE;
    g_strfreev(buff);
    /* check next line to see if converged */
    if (fgetline(fp, line))
      {
      gui_text_show(ERROR, "unexpected end of file reading equilibrium status\n");
      return(11);
      }
    if (g_ascii_strncasecmp(line, "1     ***** EQUILIBRIUM GEOMETRY LOCATED *****", 46) == 0)
      model->gamess.converged = TRUE;
    break;
    }
  }
g_free(model->title);
title = g_string_new("");
if (model->gamess.have_energy)
  {
  energy_string = g_string_new("");
  g_string_append_printf(energy_string, "%.5f H", model->gamess.energy);
  property_add_ranked(3, "Energy", energy_string->str, model);
  g_string_free(energy_string, TRUE); 
  g_string_append_printf(title, "E");
  if (model->gamess.MP_level > 0)
    g_string_append_printf(title, "(MP%d)", model->gamess.MP_level);
  g_string_append_printf(title, " = %.5f H", model->gamess.energy);
  }
if (model->gamess.have_rms_grad)
  {
  grad_string = g_string_new("");
  g_string_append_printf(grad_string, "%.4f H/B", model->gamess.rms_grad);
  property_add_ranked(4, "RMS Gradient", grad_string->str, model);
  g_string_free(grad_string, TRUE); 
  g_string_append_printf(title, ", grad = %.5f", model->gamess.rms_grad);
  }
if (model->gamess.have_max_grad)
  {
  grad_string = g_string_new("");
  g_string_append_printf(grad_string, "%.4f H/B", model->gamess.max_grad);
  property_add_ranked(4, "Maximum Gradient", grad_string->str, model);
  g_string_free(grad_string, TRUE); 
  }
model->title = g_strdup(title->str);
g_string_free(title, TRUE);

return(0);
}
Example #30
0
gint get_control(gchar *keyword, struct model_pak *model)
{
gint len, bad_andrew;

if (g_ascii_strncasecmp(GMS_UNITS_TXT, keyword, len=strlen(GMS_UNITS_TXT)) == 0)
  {
  if (read_keyword(&keyword[len], units, &bad_andrew) > 0)
    {
    gui_text_show(ERROR, " unknown units ");
    gui_text_show(ERROR, &keyword[len]);
    gui_text_show(ERROR, " ");
    return(1);
    }
  model->gamess.units = bad_andrew;
  return(0);
  }
if (g_ascii_strncasecmp(GMS_EXETYPE_TXT, keyword, len=strlen(GMS_EXETYPE_TXT)) == 0)
  {
  if (read_keyword(&keyword[len], exe_types, &bad_andrew) > 0)
    {
    gui_text_show(ERROR, " unknown exetyp ");
    gui_text_show(ERROR, &keyword[len]);
    gui_text_show(ERROR, " ");
    return(1);
    }
  model->gamess.exe_type = bad_andrew;
  return(0);
  }

if (g_ascii_strncasecmp(GMS_RUNTYPE_TXT, keyword, len=strlen(GMS_RUNTYPE_TXT)) == 0)
  {
  if (read_keyword(&keyword[len], run_types, &bad_andrew) > 0)
    {
    gui_text_show(ERROR, " unknown runtyp ");
    gui_text_show(ERROR, &keyword[len]);
    gui_text_show(ERROR, " ");
    return(1);
    }
  model->gamess.run_type = bad_andrew;
  return(0);
  }

if (g_ascii_strncasecmp(GMS_SCFTYPE_TXT, keyword, len=strlen(GMS_SCFTYPE_TXT)) == 0)
  {
  if (read_keyword(&keyword[len], scf_types, &bad_andrew) > 0)
    {
    gui_text_show(ERROR, " unknown scftyp ");
    gui_text_show(ERROR, &keyword[len]);
    gui_text_show(ERROR, " ");
    return(1);
    }
  model->gamess.scf_type = bad_andrew;
  return(0);
  }

else if (g_ascii_strncasecmp(keyword, GMS_MAXIT_TXT, len=strlen(GMS_MAXIT_TXT)) == 0)
  model->gamess.maxit = (gint) (str_to_float(&keyword[len]));
else if (g_ascii_strncasecmp(keyword, GMS_TOTAL_Q_TXT, len=strlen(GMS_TOTAL_Q_TXT)) == 0)
  model->gamess.total_charge = (gint) (str_to_float(&keyword[len]));
else if (g_ascii_strncasecmp(keyword, GMS_MULT_TXT, len=strlen(GMS_MULT_TXT)) == 0)
  model->gamess.multiplicity = (gint) (str_to_float(&keyword[len]));
else if (g_ascii_strncasecmp(keyword, GMS_WIDE_OUTPUT_TXT, len=strlen(GMS_WIDE_OUTPUT_TXT)) == 0)
  model->gamess.wide_output = (((gint) (str_to_float(&keyword[len]))) == 6);
else if (g_ascii_strncasecmp(keyword, GMS_COORD_TXT, len=strlen(GMS_COORD_TXT)) == 0)
  ; /* TODO handle different coordinate types */
else 
  {
  gui_text_show(ERROR, " unknown keyword ");
  gui_text_show(ERROR, keyword);
  gui_text_show(ERROR, " ");
  return(1);
  }
return(0);
}