Skip to content

Instantly share code, notes, and snippets.

@GCBallesteros
Last active February 16, 2018 12:14
Show Gist options
  • Save GCBallesteros/e2dc967ffc4e843abfb3e2efc5601159 to your computer and use it in GitHub Desktop.
Save GCBallesteros/e2dc967ffc4e843abfb3e2efc5601159 to your computer and use it in GitHub Desktop.
How to add attributes to an h5 file from within a Meep control file.
; HDF5 METADATA helpers
(define (attr->string attr-pair)
(string-append " -attr " (car attr-pair) " " (number->string (exact->inexact (second attr-pair)))))
(define (add-attributes fname attributes)
(let
((command (string-append "./add_attr.py -fname " (get-filename-prefix) "-" fname ".h5 "))
(attribute-string (string-join (map attr->string attributes))))
(string-append command attribute-string)))
; After running the simulation we run a python script that is in charge of the actual work
; The python script expects to be called with the name of the h5 file followed by a set of
; command line arguments of the form "-attr var_name var_value"
; For example: ./add_attr.py -fname my_monitor.h5 -attr distance 3 -attr freq 5
; Add attributes to "freq-monitor.h5"
(system (add-attributes "freq-monitor" (list (list "xmin" (/ sx -2))
(list "xmax" (/ sx 2))
(list "ymin" mirror-top)
(list "ymax" (+ mirror-top (* h-slab 1.5)))
(list "dt" dt-monitor)
(list "minfreq" min-freq)
(list "maxfreq" max-freq)
(list "res" resolution))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment