From ac0606a2be08edbe95fb03267d2534512778ec81 Mon Sep 17 00:00:00 2001 From: tradke Date: Thu, 6 May 2004 11:59:35 +0000 Subject: Fixed filenames for chunked output files. Don't output chunked files for grid scalars. This closes PR IO/1672: "fexio output filenames (and directory names) give '3d' regardless of the dimensionality of the output variable". git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOFlexIO/trunk@314 ebee0441-1374-4afa-a3b5-247f3ba15b9a --- src/DumpVar.c | 29 +++++++++++------------ src/Write.c | 74 +++++++++++++++++++++++++++++------------------------------ 2 files changed, 50 insertions(+), 53 deletions(-) diff --git a/src/DumpVar.c b/src/DumpVar.c index 87d87b5..807f4ec 100644 --- a/src/DumpVar.c +++ b/src/DumpVar.c @@ -260,22 +260,21 @@ static int WriteGS (const cGH *GH, const ioRequest *request, IOFile file) } } - /* only I/O processors write data */ - if (myproc != ioUtilGH->ioproc) + /* only I/O processor 0 writes data */ + retval = 0; + if (! myproc) { - retval = 0; - } - else if (! IOisValid (file)) - { - retval = -1; - } - else - { - /* first dump the data then add the attributes */ - FLEXIO_ERROR (IOwrite (file, IOFlexIO_DataType (request->hdatatype), dim, - &dim, buffer)); - AddCommonAttributes (GH, request, file); - retval = 0; + if (IOisValid (file)) + { + /* first dump the data then add the attributes */ + FLEXIO_ERROR (IOwrite (file, IOFlexIO_DataType (request->hdatatype), dim, + &dim, buffer)); + AddCommonAttributes (GH, request, file); + } + else + { + retval = -1; + } } free (buffer); diff --git a/src/Write.c b/src/Write.c index bf6e9e0..6289c7c 100644 --- a/src/Write.c +++ b/src/Write.c @@ -26,7 +26,8 @@ CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_Write_c) /******************************************************************** ******************** Internal Routines ************************ ********************************************************************/ -static IEEEfile_t *OpenFile (const cGH *GH, const char *alias, int *is_new_file); +static IEEEfile_t *OpenFile (const cGH *GH, int vindex, const char *alias, + int *is_new_file); /*@@ @@ -68,7 +69,7 @@ int IOFlexIO_Write (const cGH *GH, int vindex, const char *alias) { const flexioGH *myGH; const ioGH *ioUtilGH; - int len, is_new_file, retval; + int myproc, len, is_new_file, retval; char buffer[128]; char *fullname; IEEEfile_t *file; @@ -91,12 +92,16 @@ int IOFlexIO_Write (const cGH *GH, int vindex, const char *alias) "alias '%s'", CCTK_VarName (vindex), alias); } + myGH = CCTK_GHExtension (GH, "IOFlexIO"); + ioUtilGH = CCTK_GHExtension (GH, "IO"); + /* get the filename and descriptor for output */ - file = OpenFile (GH, alias, &is_new_file); + file = OpenFile (GH, vindex, alias, &is_new_file); /* nothing to do for an already opened file which is kept open all the time */ - ioUtilGH = (const ioGH *) CCTK_GHExtension (GH, "IO"); - if (CCTK_MyProc (GH) == ioUtilGH->ioproc) + myproc = CCTK_MyProc (GH); + if (myproc == ioUtilGH->ioproc && + (CCTK_GroupTypeFromVarI (vindex) != CCTK_SCALAR || myproc == 0)) { if (is_new_file || reuse_filehandles) { @@ -168,7 +173,6 @@ int IOFlexIO_Write (const cGH *GH, int vindex, const char *alias) } /* output the data */ - myGH = (const flexioGH *) CCTK_GHExtension (GH, "IOFlexIO"); retval = IOFlexIO_DumpVar (GH, myGH->requests[vindex], file->iofile); /* output the GH extensions and parameters */ @@ -220,11 +224,12 @@ int IOFlexIO_Write (const cGH *GH, int vindex, const char *alias) ******************** Internal Routines ************************ ********************************************************************/ /* generate the filename for the given alias and creates/opens the file */ -static IEEEfile_t *OpenFile (const cGH *GH, const char *alias, int *is_new_file) +static IEEEfile_t *OpenFile (const cGH *GH, int vindex, const char *alias, + int *is_new_file) { - ioGH *ioUtilGH; + const ioGH *ioUtilGH; flexioGH *myGH; - int myproc, nprocs, result; + int myproc, nprocs, vdim, result; char extra[256], extradir[256]; char *outputdir, *tmp; IEEEfile_t *file; @@ -232,10 +237,10 @@ static IEEEfile_t *OpenFile (const cGH *GH, const char *alias, int *is_new_file) /* get the GH extensions for IOUtil, and IOFlexIO */ - ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); - myGH = (flexioGH *) CCTK_GHExtension (GH, "IOFlexIO"); + ioUtilGH = CCTK_GHExtension (GH, "IO"); + myGH = CCTK_GHExtension (GH, "IOFlexIO"); - file = (IEEEfile_t *) GetNamedData (myGH->fileList, alias); + file = GetNamedData (myGH->fileList, alias); if (file != NULL) { /* set flag to indicate that file should be opened in append mode */ @@ -243,16 +248,16 @@ static IEEEfile_t *OpenFile (const cGH *GH, const char *alias, int *is_new_file) return (file); } - extra[0] = '\0'; - extradir[0] = '\0'; + extra[0] = extradir[0] = '\0'; nprocs = CCTK_nProcs (GH); myproc = CCTK_MyProc (GH); + vdim = CCTK_GroupDimFromVarI (vindex); if (out_timesteps_per_file > 0) { tmp = extra; - sprintf (extra, "%s.time_%7.3f", extra, GH->cctk_time); + sprintf (extra, ".time_%7.3f", GH->cctk_time); /* be sure to replace any spaces in the filename with an _ */ do @@ -264,23 +269,23 @@ static IEEEfile_t *OpenFile (const cGH *GH, const char *alias, int *is_new_file) } while (*++tmp); } - /* OUTPUT ONE FILE FOR EACH N PROCESSORS + /* + * OUTPUT ONE FILE FOR EACH N PROCESSORS * ------------------------------------- * - * If only one output file, the single file for each GF is written - * in the normal output dir (that is extradir = ""). Otherwise - * a directory is created for each output GF to hold the multiple - * file + * If only one output file, the single file for each GV is written + * in the default output directory (ie. extradir = ""). Otherwise + * a directory is created for each output GV to hold the multiple files. */ - - if (ioUtilGH->ioproc_every < nprocs) + if (ioUtilGH->ioproc_every < nprocs && + CCTK_GroupTypeFromVarI (vindex) != CCTK_SCALAR) { /* 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 */ - outputdir = (char *) malloc (strlen (myGH->out_dir) + strlen (alias) + 5); - sprintf (outputdir, "%s/%s_3d", myGH->out_dir, alias); + outputdir = malloc (strlen (myGH->out_dir) + strlen (alias) + 5); + sprintf (outputdir, "%s/%s_%dd", myGH->out_dir, alias, vdim); result = IOUtil_CreateDirectory (GH, outputdir, ! CCTK_Equals (out_mode, "onefile"), @@ -304,21 +309,22 @@ static IEEEfile_t *OpenFile (const cGH *GH, const char *alias, int *is_new_file) #endif /* extradir is the relative output directory */ - sprintf (extradir, "%s_3d/", alias); + sprintf (extradir, "%s_%dd/", alias, vdim); } /* CREATE THE COMPLETE OUTPUT FILENAME ----------------------------------- */ - file = (IEEEfile_t *) malloc (sizeof (IEEEfile_t)); + file = malloc (sizeof (IEEEfile_t)); - file->filename = (char *) malloc (strlen (myGH->out_dir) + strlen (extradir) + - strlen (alias) + strlen (extra) + - strlen (GH->identity) + 10); - sprintf (file->filename, "%s/%s%s_3d%s%s.ieee", myGH->out_dir, + file->filename = malloc (strlen (myGH->out_dir) + strlen (extradir) + + strlen (alias) + strlen (extra) + + strlen (GH->identity) + 10); + sprintf (file->filename, "%s/%s%s%s%s.ieee", myGH->out_dir, extradir, alias, extra, GH->identity); /* no need to store file info if used only once */ + *is_new_file = 1; if (out_timesteps_per_file < 0) { if (myproc == ioUtilGH->ioproc) @@ -328,17 +334,9 @@ static IEEEfile_t *OpenFile (const cGH *GH, const char *alias, int *is_new_file) file->iofile = IEEEopen (file->filename, "a"); *is_new_file = ! IOisValid (file->iofile); } - else - { - *is_new_file = 1; - } } StoreNamedData (&myGH->fileList, alias, file); } - else - { - *is_new_file = 1; - } return (file); } -- cgit v1.2.3