#include "cctk.h" #include "cctk_Parameters.h" #include "StoreNamedData.h" #include "CactusPUGH/PUGH/src/include/pugh.h" #include "CactusBase/IOUtil/src/ioGH.h" #include "ioHDF5GH.h" #include #include #include /*@@ @routine IOHDF5_Get_filename_ND @author Paul Walker @date Feb 1997 @desc Returns the filename for output The names of all output files are stored in the filenames database. The routine first searches in this database if there is already registered a filename for alias. If so, this name is returned. Otherwise it builds the filename from alias and stores it in the database. NOTE: Filenames are never stored if "out2D_septimefiles = true" since they are used only once. Generalized for Hyperslab extraction (GL) @enddesc @var GH @vdesc Pointer to CCTK GH @vtype cGH @vio in @endvar @var index @vdesc index of variable to output @vtype int @vio in @endvar @var name @vdesc alias name of variable to output @vtype const char * @vio in @endvar @var isNewFile @vdesc flag indicating if the file is to be created @vtype int @vio out @endvar @@*/ char *IOHDF5_Get_filename_ND (cGH *GH, int index, ioHDF5Geo_t *slab_geo, const char *varname, int *isNewFile) { DECLARE_CCTK_PARAMETERS ioGH *ioUtilGH; /* handle for IOUtil extensions */ ioHDF5GH *myGH; /* handle for IOHDF5 extensions */ pGH *pughGH; /* handle for PUGH extensions */ int myproc; char extra [256]; /* Extra stuff in fname based on mode */ char extradir [256]; /* Extra stuff for an output dir */ char *extrageo; /* Extra stuff for geometry information */ char *filename; /* the return value */ int idim; char name[128]; /* get GH extensions for PUGH and IOUtil */ pughGH = PUGH_pGH (GH); ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; myGH = (ioHDF5GH *) GH->extensions [CCTK_GHExtensionHandle ("IOHDF5")]; /* To identify the slab in a volume (if sdimsdimvdim) { extrageo = (char*) malloc((slab_geo->sdim+1)*sizeof(char)); sprintf(extrageo,"%d",slab_geo->direction[0]); for (idim=1;idimsdim;idim++) sprintf(extrageo,"%s%d",extrageo,slab_geo->direction[idim]); sprintf(name,"%s_s%s_%dd",varname,extrageo,slab_geo->vdim); free(extrageo); } /* If sdim==vdim, make it simple: e.g. phi_3d */ else if (slab_geo->sdim==slab_geo->vdim) { sprintf(name,"%s_%dd",varname,slab_geo->vdim); } else { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Inconsitent dimensions for >%s<: slab (%dD), variable (%dD)\n", varname, slab_geo->sdim,slab_geo->vdim); return(NULL); } filename = (char *) GetNamedData (myGH->filenameList, name); if (filename != NULL) { /* set flag to indicate that file should be opened in append mode */ *isNewFile = 0; return (filename); } extra[0] = '\0'; extradir[0]= '\0'; myproc = CCTK_MyProc (GH); if (out2D_septimefiles) { char *tmp = extra; sprintf (extra, "%s.time_%7.3f", extra, GH->cctk_time); /* And be sure to replace any spaces in the filename with an _ */ do if (*tmp == ' ') *tmp = '_'; while (*++tmp); } /* OUTPUT ONE FILE FOR EACH N PROCESSORS FIXME * ------------------------------------- * * If only one output file, the single file for each variable is written * in the normal output dir (that is extradir = ""). Otherwise * a directory is created for each output variable to hold the multiple * files. */ if (! ioUtilGH->unchunked && ioUtilGH->ioproc_every < CCTK_nProcs (GH)) { /* Add the output processor number to the extra string */ sprintf (extra, "%s.file_%d", extra, myproc / ioUtilGH->ioproc_every); /* If necessary create the output directory */ if (myproc == 0) { int result; char *outputdir = (char *) malloc (strlen (myGH->outdir3D) + strlen (name) + 5); sprintf (outputdir, "%s/%s_3d", myGH->outdir3D, name); result = CCTK_CreateDirectory (0755, outputdir); if (result < 0) CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Problem creating 3D output directory '%s'", outputdir); if (result > 0) CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "3D output directory '%s' already exists", outputdir); free (outputdir); } #ifdef CCTK_MPI /* Wait for all processors to catch up */ CCTK_Barrier (GH); #endif /* extradir is the relative output directory */ sprintf (extradir, "%s_3d/", name); } /* CREATE THE COMPLETE OUTPUT FILENAME ----------------------------------- */ filename = (char *) malloc (strlen (myGH->outdir2D) + strlen (extradir) + strlen (name) + strlen (extra) + (pughGH->identity_string ? strlen (pughGH->identity_string) : 0) + 8); sprintf (filename, "%s/%s%s%s%s.h5", myGH->outdir2D, extradir, name, extra, (pughGH->identity_string ? pughGH->identity_string : "")); /* no need to store filenames if used only once */ if (! out2D_septimefiles) { if (myproc == ioUtilGH->ioproc) { if (ioUtilGH->recovered) { CACTUS_IOHDF5_ERROR (H5Eset_auto (NULL, NULL)); *isNewFile = H5Fis_hdf5 (filename) <= 0; H5Eset_auto (myGH->printErrorFn, myGH->printErrorFnArg); if (! *isNewFile) myGH->checkForExistingObjects [index] = 1; } else { *isNewFile = 1; } } StoreNamedData (&myGH->filenameList, name, filename); } else { *isNewFile = 1; } return (filename); }