mightymandel v16

GPU-based Mandelbrot set explorer

parse_mdz_center.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_mdz_center.h"
14 
15 bool parse_mdz_center(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 *sa = 0;
22  char *sx = 0;
23  char *sy = 0;
24  char *sz = 0;
25  while (s) {
26  char *line = parse_line(&s);
27  if (0 == strncmp(line, "aspect ", 7)) { sa = line + 7; }
28  if (0 == strncmp(line, "cx ", 3)) { sx = line + 3; }
29  if (0 == strncmp(line, "cy ", 3)) { sy = line + 3; }
30  if (0 == strncmp(line, "size ", 5)) { sz = line + 5; }
31  }
32  if (sa && sx && sy && sz) {
33  double a = atof(sa);
34  mpfr_set_prec(cz, 53);
35  mpfr_set_str(cz, sz, 10, MPFR_RNDN);
36  mpfr_div_d(cz, cz, 2 * a, MPFR_RNDN);
37  mpfr_abs(cz, cz, MPFR_RNDN);
38  if (! radius_is_valid(cz)) {
39  free(source2);
40  return false;
41  }
42  mpfr_prec_t p = precision_for_radius(cz);
43  mpfr_set_prec(cx, p);
44  mpfr_set_prec(cy, p);
45  mpfr_set_str(cx, sx, 10, MPFR_RNDN);
46  mpfr_set_str(cy, sy, 10, MPFR_RNDN);
47  free(source2);
48  return true;
49  } else {
50  free(source2);
51  return false;
52  }
53 }