mightymandel v16

GPU-based Mandelbrot set explorer

parse_kfr.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_kfr.h"
14 
15 bool parse_kfr(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, "Re: ", 4)) { sx = line + 4; }
27  if (0 == strncmp(line, "Im: ", 4)) { sy = line + 4; }
28  if (0 == strncmp(line, "Zoom: ", 6)) { sz = line + 6; }
29  }
30  if (sx && sy && sz) {
31  mpfr_set_prec(cz, 53);
32  mpfr_set_str(cz, sz, 10, MPFR_RNDN);
33  mpfr_d_div(cz, 2.0, cz, MPFR_RNDN);
34  if (! radius_is_valid(cz)) {
35  free(source2);
36  return false;
37  }
38  mpfr_prec_t p = precision_for_radius(cz);
39  mpfr_set_prec(cx, p);
40  mpfr_set_prec(cy, p);
41  mpfr_set_str(cx, sx, 10, MPFR_RNDN);
42  mpfr_set_str(cy, sy, 10, MPFR_RNDN);
43  mpfr_neg(cy, cy, MPFR_RNDN);
44  free(source2);
45  return true;
46  } else {
47  free(source2);
48  return false;
49  }
50 }