diff --git a/src/xmf.c b/src/xmf.c index d4e66199b4afefdf020952492319114955aa6078..49dfc9936257b667e9b2e13ca8d015f635553a4d 100644 --- a/src/xmf.c +++ b/src/xmf.c @@ -1,6 +1,7 @@ /******************************************************************************* * This file is part of SWIFT. * Copyright (c) 2017 Matthieu Schaller (matthieu.schaller@durham.ac.uk). + * Peter W. Draper (p.w.draper@durham.ac.uk) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published @@ -21,7 +22,9 @@ #include "../config.h" /* Some standard headers. */ +#include <libgen.h> #include <stdio.h> +#include <string.h> /* This object's header. */ #include "xmf.h" @@ -30,6 +33,22 @@ #include "common_io.h" #include "error.h" +/** + * @brief Return the basename of an HDF5 path. + * + * Need basename as XML paths are relative to the container, and XMF file is + * written with the same baseName as the HDF5 snapshots. + * + * @param hdfFileName + * @return the basename part of hdfFileName. + */ +static const char *xmf_basename(const char *hdfFileName) { + static char buffer[FILENAME_BUFFER_SIZE]; + strcpy(buffer, hdfFileName); + return basename(buffer); +} + + /** * @brief Prepare the XMF file corresponding to a snapshot. * @@ -154,6 +173,7 @@ void xmf_write_outputfooter(FILE* xmfFile, int output, float time) { */ void xmf_write_groupheader(FILE* xmfFile, char* hdfFileName, size_t N, enum part_type ptype) { + fprintf(xmfFile, "\n<Grid Name=\"%s\" GridType=\"Uniform\">\n", part_type_names[ptype]); fprintf(xmfFile, @@ -163,7 +183,7 @@ void xmf_write_groupheader(FILE* xmfFile, char* hdfFileName, size_t N, "<DataItem Dimensions=\"%zu 3\" NumberType=\"Double\" " "Precision=\"8\" " "Format=\"HDF\">%s:/PartType%d/Coordinates</DataItem>\n", - N, hdfFileName, (int)ptype); + N, xmf_basename(hdfFileName), (int)ptype); fprintf(xmfFile, "</Geometry>\n <!-- Done geometry for %s, start of particle fields " "list -->\n", @@ -251,13 +271,13 @@ void xmf_write_line(FILE* xmfFile, const char* fileName, fprintf(xmfFile, "<DataItem Dimensions=\"%zu\" NumberType=\"%s\" " "Precision=\"%d\" Format=\"HDF\">%s:%s/%s</DataItem>\n", - N, xmf_type(type), xmf_precision(type), fileName, partTypeGroupName, - name); + N, xmf_type(type), xmf_precision(type), xmf_basename(fileName), + partTypeGroupName, name); else fprintf(xmfFile, "<DataItem Dimensions=\"%zu %d\" NumberType=\"%s\" " "Precision=\"%d\" Format=\"HDF\">%s:%s/%s</DataItem>\n", - N, dim, xmf_type(type), xmf_precision(type), fileName, - partTypeGroupName, name); + N, dim, xmf_type(type), xmf_precision(type), + xmf_basename(fileName), partTypeGroupName, name); fprintf(xmfFile, "</Attribute>\n"); }