mightymandel v16

GPU-based Mandelbrot set explorer

parse_ppar_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_ppar_center.h"
14 #include "logging.h"
15 
16 bool parse_ppar_center(const char *source, int length, mpfr_t cx, mpfr_t cy, mpfr_t cz) {
17  (void) length;
18  char *source2 = strdup(source);
19  char *s = source2;
20  char *centermag = 0; // CENTER-MAG=[Xctr/Yctr/Mag[/Xmagfactor/Rotation/Skew]]
21  while (s) {
22  char *line = parse_line(&s);
23  if (0 == strncmp(line, "center-mag=", 11)) {
24  centermag = line + 11;
25  debug_message("parse_ppar1: center-mag = %s\n", centermag);
26  char *sx = parse_separator(&centermag, '/');
27  char *sy = parse_separator(&centermag, '/');
28  char *sz = centermag;
29  debug_message("parse_ppar1: sx = %s\n", sx);
30  debug_message("parse_ppar1: sy = %s\n", sy);
31  debug_message("parse_ppar1: sz = %s\n", sz);
32  char *extra = strchr(centermag, '/');
33  if (extra) {
34  debug_message("parse_ppar1: warning unsupported extra fields in center-mag: %s\n", extra);
35  *extra = 0;
36  }
37  mpfr_set_str(cz, sz, 10, MPFR_RNDN);
38  mpfr_si_div(cz, 1, cz, MPFR_RNDN);
39  if (! radius_is_valid(cz)) {
40  free(source2);
41  return false;
42  }
43  mpfr_prec_t prec = precision_for_radius(cz);
44  mpfr_set_prec(cx, prec);
45  mpfr_set_prec(cy, prec);
46  mpfr_set_str(cx, sx, 10, MPFR_RNDN);
47  mpfr_set_str(cy, sy, 10, MPFR_RNDN);
48  debug_message("parse_ppar1: cx = %Re\n", cx);
49  debug_message("parse_ppar1: cy = %Re\n", cy);
50  debug_message("parse_ppar1: cz = %Re\n", cz);
51  free(source2);
52  return true;
53  }
54  }
55  free(source2);
56  return false;
57 }