mightymandel v16

GPU-based Mandelbrot set explorer

parse_sft.c
Go to the documentation of this file.
1 // mightymandel -- GPU-based Mandelbrot Set explorer
2 // Copyright (C) 2012,2013,2014,2015 Claude Heiland-Allen
3 // License GPL3+ http://www.gnu.org/licenses/gpl.html
4 
5 #include <assert.h>
6 #include <stdbool.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <mpfr.h>
11 
12 #include "parse.h"
13 #include "parse_sft.h"
14 
15 bool parse_sft(const char *source, int length, mpfr_t cx, mpfr_t cy, mpfr_t cz) {
16  (void) length;
17  assert(source);
18  char *source2 = strdup(source);
19  assert(source2);
20  char *s = source2;
21  char *sx = 0;
22  char *sy = 0;
23  char *sz = 0;
24  while (s) {
25  char *line = parse_line(&s);
26  if (0 == strncmp(line, "r=", 2)) { sx = line + 2; }
27  if (0 == strncmp(line, "i=", 2)) { sy = line + 2; }
28  if (0 == strncmp(line, "s=", 2)) { sz = line + 2; }
29  }
30  if (sx && sy && sz) {
31  mpfr_set_prec(cz, 53);
32  mpfr_set_str(cz, sz, 10, MPFR_RNDN);
33  if (! radius_is_valid(cz)) {
34  free(source2);
35  return false;
36  }
37  mpfr_prec_t p = precision_for_radius(cz);
38  mpfr_set_prec(cx, p);
39  mpfr_set_prec(cy, p);
40  mpfr_set_str(cx, sx, 10, MPFR_RNDN);
41  mpfr_set_str(cy, sy, 10, MPFR_RNDN);
42  free(source2);
43  return true;
44  } else {
45  free(source2);
46  return false;
47  }
48 }