commit 9f1b5968e9ccd2ad020bb158eb4495944c91d676
parent 1dc4b4048d74254e35e36772d47fec4177e23649
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 19 Apr 2017 16:34:35 +0200
Add the spectrum as a first level item in the input fileformat
Diffstat:
4 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/doc/input b/doc/input
@@ -89,10 +89,11 @@
[ - <item> ... ]
<item> ::=
- <geometry>
+ <entity>
+ | <geometry>
| <material>
| <medium>
- | <entity>
+ | <spectrum>
| <template>
#----------------------------------------
diff --git a/src/parser/solparser.c b/src/parser/solparser.c
@@ -148,6 +148,7 @@ parse_item
goto error;
}
+ /* The parsing of the templates/spectraa is deferred to their explicit use */
if(!strcmp((char*)key->data.scalar.value, "material")) {
res = parse_material(parser, doc, val, &mtl2);
} else if(!strcmp((char*)key->data.scalar.value, "medium")) {
@@ -157,14 +158,12 @@ parse_item
if(res == RES_OK) {
res = flush_deferred_target_aliases(parser, item, entity);
}
- } else if(!strcmp((char*)key->data.scalar.value, "template")) {
- /* The parsing of the template data is deferred to its explicit used in the
- * definition of an entity. If the parsing of the template becomes a
- * bottleneck, parse the data only once here and cache them for reuse. */
+ } else if(!strcmp((char*)key->data.scalar.value, "template")) { /* Deferred */
} else if(!strcmp((char*)key->data.scalar.value, "geometry")) {
res = parse_geometry(parser, doc, val, &geometry);
} else if(!strcmp((char*)key->data.scalar.value, "sun")) {
res = parse_sun(parser, doc, val, &sun);
+ } else if(!strcmp((char*)key->data.scalar.value, "spectrum")) { /* Deferred */
} else {
log_err(parser, key, "unknown item `%s'.\n", key->data.scalar.value);
res = RES_BAD_ARG;
diff --git a/src/parser/test_solparser_spectrum.c b/src/parser/test_solparser_spectrum.c
@@ -27,18 +27,19 @@ test_sun(struct solparser* parser)
NCHECK(stream = tmpfile(), NULL);
+ fprintf(stream, "- spectrum: &my_spectrum\n");
+ fprintf(stream, " - { wavelength: 2, data: 2 }\n");
+ fprintf(stream, " - { wavelength: 1, data: 1 }\n");
+ fprintf(stream, " - { wavelength: 8, data: 8 }\n");
+ fprintf(stream, " - { wavelength: 3, data: 3 }\n");
+ fprintf(stream, " - { wavelength: 5, data: 5 }\n");
+ fprintf(stream, " - { wavelength: 9, data: 9 }\n");
+ fprintf(stream, " - { wavelength: 6, data: 6 }\n");
+ fprintf(stream, " - { wavelength: 7, data: 7 }\n");
+ fprintf(stream, " - { wavelength: 4, data: 4 }\n");
fprintf(stream, "- sun:\n");
fprintf(stream, " dni: 123.456\n");
- fprintf(stream, " spectrum:\n");
- fprintf(stream, " - { wavelength: 2, data: 2 }\n");
- fprintf(stream, " - { wavelength: 1, data: 1 }\n");
- fprintf(stream, " - { wavelength: 8, data: 8 }\n");
- fprintf(stream, " - { wavelength: 3, data: 3 }\n");
- fprintf(stream, " - { wavelength: 5, data: 5 }\n");
- fprintf(stream, " - { wavelength: 9, data: 9 }\n");
- fprintf(stream, " - { wavelength: 6, data: 6 }\n");
- fprintf(stream, " - { wavelength: 7, data: 7 }\n");
- fprintf(stream, " - { wavelength: 4, data: 4 }\n");
+ fprintf(stream, " spectrum: *my_spectrum\n");
fprintf(stream, "- material: &matte { matte: { reflectivity: 1 } }\n");
fprintf(stream, "- entity:\n");
fprintf(stream, " name: foo bar\n");
diff --git a/src/parser/yaml/test_ok_0.yaml b/src/parser/yaml/test_ok_0.yaml
@@ -50,8 +50,13 @@
- entity: { name: "hop", primary: 1, geometry: *cuboid }
- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1}] }
---
+- spectrum: &sun_spectrum
+ - { wavelength: 1.1, data: 1.2 }
+ - { wavelength: 2.2, data: 2.3 }
+ - { wavelength: 3.3, data: 3.4 }
+ - { wavelength: 4.4, data: 4.4 }
- material: &lambertian { matte: { reflectivity: 1 } }
-- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1}] }
+- sun: { dni: 1, spectrum: *sun_spectrum }
- entity:
name: hop
primary: 0