Skip to content
Snippets Groups Projects

Use the basename for the HDF5 files

Merged Peter W. Draper requested to merge xmf-fixes into master
+ 25
5
Compare changes
  • Side-by-side
  • Inline
+ 25
5
/*******************************************************************************
* 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"
@@ -31,6 +34,22 @@
#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.
*
* @param baseName The common part of the file name.
@@ -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");
}
Loading