mightymandel v16

GPU-based Mandelbrot set explorer

parse_mdz_corners.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_corners.h"
14 
15 bool parse_mdz_corners(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 *sp = 0;
22  char *sa = 0;
23  char *sx0 = 0;
24  char *sx1 = 0;
25  char *sy1 = 0;
26  while (s) {
27  char *line = parse_line(&s);
28  if (0 == strncmp(line, "precision ", 10)) { sp = line + 10; }
29  if (0 == strncmp(line, "aspect ", 7)) { sa = line + 7; }
30  if (0 == strncmp(line, "xmin ", 5)) { sx0 = line + 5; }
31  if (0 == strncmp(line, "xmax ", 5)) { sx1 = line + 5; }
32  if (0 == strncmp(line, "ymax ", 5)) { sy1 = line + 5; }
33  }
34  if (sp && sa && sx0 && sx1 && sy1) {
35  int p = atoi(sp);
36  mpfr_set_prec(cx, p);
37  mpfr_set_prec(cy, p);
38  mpfr_set_prec(cz, 53);
39  double a = atof(sa);
40  mpfr_t x0, x1, y1;
41  mpfr_inits2(p, x0, x1, y1, (mpfr_ptr) 0);
42  mpfr_set_str(x0, sx0, 10, MPFR_RNDN);
43  mpfr_set_str(x1, sx1, 10, MPFR_RNDN);
44  mpfr_set_str(y1, sy1, 10, MPFR_RNDN);
45  mpfr_add(cx, x0, x1, MPFR_RNDN);
46  mpfr_div_2ui(cx, cx, 1, MPFR_RNDN);
47  mpfr_sub(x1, x1, x0, MPFR_RNDN);
48  mpfr_div_d(cz, x1, a * 2, MPFR_RNDN);
49  mpfr_sub(cy, y1, cz, MPFR_RNDN);
50  mpfr_clears(x0, x1, y1, (mpfr_ptr) 0);
51  free(source2);
52  return true;
53  } else {
54  free(source2);
55  return false;
56  }
57 }