From f1b8a99aedc1107f098cbea071e6f02e11829e08 Mon Sep 17 00:00:00 2001 From: tradke Date: Mon, 25 Sep 2000 14:03:36 +0000 Subject: Initialize flags for advertised files. git-svn-id: http://svn.cactuscode.org/arrangements/CactusIO/IOJpeg/trunk@19 eff87b29-5268-4891-90a3-a07138403961 --- src/DumpVar.c | 26 +++--- src/GHExtension.c | 11 ++- src/ParseGeometry.c | 93 +++++++++------------ src/Write2D.c | 235 +++++++++++++++++++++++----------------------------- 4 files changed, 163 insertions(+), 202 deletions(-) (limited to 'src') diff --git a/src/DumpVar.c b/src/DumpVar.c index caafb13..35920bb 100644 --- a/src/DumpVar.c +++ b/src/DumpVar.c @@ -87,22 +87,24 @@ int IOJpeg_DumpVar (cGH *GH, int index, int timelevel, IOJpegGeo_t *geo, FILE *f return (-1); } - /* Output routine for valid fid (was set in Write nD) */ - if (fid) + /* Output the hyperslab data */ + if (IOJpeg_Output (GH, index, timelevel, data, geo->sdim, hsizes, + vtype, fid)<0) { - if (IOJpeg_Output(GH, index, timelevel, data, - geo->sdim, hsizes, vtype, fid)<0) { - char *fullname = CCTK_FullName (index); - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "IOJpeg_Output failed for variable '%s'", fullname); - free (fullname); - return (-1); - } + char *fullname = CCTK_FullName (index); + + + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOJpeg_Output failed for variable '%s'", fullname); + free (fullname); + return (-1); } + /* free allocated resources */ if (data) + { free (data); - + } if (hsizes) { free (hsizes); @@ -139,7 +141,7 @@ int IOJpeg_Output(cGH *GH, int index, int timelevel, CCTK_REAL *data, CCTK_VARIABLE_REAL,&min, 1, index); } - if(CCTK_MyProc(GH) == 0) + if(fid) { AutoColorDataSlice(hsize[0], hsize[1], diff --git a/src/GHExtension.c b/src/GHExtension.c index e04724f..00c19e6 100644 --- a/src/GHExtension.c +++ b/src/GHExtension.c @@ -78,8 +78,6 @@ int IOJpeg_InitGH (cGH *GH) } } - myGH->fileList_2D = NULL; - return (0); } @@ -89,22 +87,29 @@ void IOJpeg_SliceCenterSetup(CCTK_ARGUMENTS) { DECLARE_CCTK_PARAMETERS int inum,idim; + int numvars; IOJpegGeo_t geo_default; IOJpegGH *myGH; myGH = (IOJpegGH *) cctkGH->extensions [CCTK_GHExtensionHandle ("IOJpeg")]; + numvars = CCTK_NumVars (); + /* Loop over all slab dimension */ for (idim = 0; idim < SLABSKEL_MAXDIM; idim++) { IOJpeg_DefaultGeo(cctkGH, idim, &geo_default); /* Set the default HDF5 slab geometry for slab with dimension -idim-*/ - for (inum = 0; inum < CCTK_NumVars (); inum++) + for (inum = 0; inum < numvars; inum++) { myGH->out_geo[inum][idim] = geo_default; + myGH->out_geo[inum][idim].vdim = CCTK_GroupDimFromVarI (inum); } + + /* allocate the flags array for every possible 2D hyperslab */ + myGH->advertised[idim] = (char *) calloc (numvars, 1); } } diff --git a/src/ParseGeometry.c b/src/ParseGeometry.c index b060708..ad003f9 100644 --- a/src/ParseGeometry.c +++ b/src/ParseGeometry.c @@ -22,7 +22,7 @@ void IOJpeg_DefaultGeo(cGH *GH, int sdim, IOJpegGeo_t *geo) { [CCTK_GHExtensionHandle ("IOASCII")]; geo->vdim = -1; - geo->sdim = -1; + geo->sdim = sdim; for (idim=0;idimdirection[idim] = idim; @@ -75,68 +75,51 @@ void IOJpeg_DefaultGeo(cGH *GH, int sdim, IOJpegGeo_t *geo) { } -int IOJpeg_NumDirection(int sdim, int vdim) +int IOJpeg_SetDirection (IOJpegGeo_t *geometry, int direction) { - int numdir=-1; - if (vdim==3) { - switch (sdim) { - case 1: return(3); - case 2: return(3); - case 3: return(1); - } - } else if (vdim==2) { - switch (sdim) { - case 1: return(2); - case 2: return(1); - } - } - else if (vdim==1) { - switch (sdim) { - case 1: return(1); - } - } - else printf("Bad dimension: %d \n",vdim); - return(numdir); -} + int retval = 0; -int IOJpeg_SetDirection(int vdim, int sdim, int ci, int *direction) -{ - int retval=0; - if (sdim>vdim) { - printf("SetDirection: slabdim gt vdim"); - return(-1); - } - - if (vdim==3) { - if (sdim==2) { - switch (ci) { - case 0: direction[0]=0; direction[1]=1; break; - case 1: direction[0]=0; direction[1]=2; break; - case 2: direction[0]=1; direction[1]=2; break; + if (geometry->vdim == 3) + { + if (geometry->sdim == 2) + { + switch (direction) + { + case 0: geometry->direction[0]=0; geometry->direction[1]=1; break; + case 1: geometry->direction[0]=0; geometry->direction[1]=2; break; + case 2: geometry->direction[0]=1; geometry->direction[1]=2; break; } } - else if (sdim==1) { - switch (ci) { - case 0: direction[0]=0; break; - case 1: direction[0]=1; break; - case 2: direction[0]=2; break; + else if (geometry->sdim == 1) + { + switch (direction) + { + case 0: geometry->direction[0]=0; break; + case 1: geometry->direction[0]=1; break; + case 2: geometry->direction[0]=2; break; } } } - else if (vdim==2) { - if (sdim==2) { - direction[0]=0; direction[1]=1; - } else if (sdim==1) { - switch (ci) { - case 0: direction[0]=0; break; - case 1: direction[0]=1; break; + else if (geometry->vdim==2) + { + if (geometry->sdim == 2) + { + geometry->direction[0]=0; geometry->direction[1]=1; + } + else if (geometry->sdim == 1) + { + switch (direction) + { + case 0: geometry->direction[0]=0; break; + case 1: geometry->direction[0]=1; break; } } - } else retval = -1; - return(retval); + } + else + { + retval = -1; + } + + return (retval); } - - - - diff --git a/src/Write2D.c b/src/Write2D.c index a5cec02..55cdc99 100644 --- a/src/Write2D.c +++ b/src/Write2D.c @@ -20,14 +20,15 @@ #include "cctk_Parameters.h" #include "CactusBase/IOUtil/src/ioutil_AdvertisedFiles.h" - - #include "IOJpeg.h" static char *rcsid = "$Header$"; CCTK_FILEVERSION(DevThorns_IOJpeg_Write2D_c) +/* The dimension of the Jpeg hyperslabs */ +#define JPEG_SLABDIM 2 + /******************************************************************** ********************* Local Data Types *********************** ********************************************************************/ @@ -36,8 +37,7 @@ CCTK_FILEVERSION(DevThorns_IOJpeg_Write2D_c) ********************* Local Routine Prototypes ********************* ********************************************************************/ -int IOJpeg_NumDirection(int sdim, int vdim); -int IOJpeg_SetDirection(int vdim, int sdim, int ci, int *direction); +int IOJpeg_SetDirection (IOJpegGeo_t *geometry, int direction); /******************************************************************** ********************* Other Routine Prototypes ********************* @@ -79,163 +79,134 @@ int IOJpeg_Write2D (cGH *GH, int index, const char *alias) DECLARE_CCTK_PARAMETERS int timelevel; IOJpegGH *ssGH; - IOJpegGeo_t geo; - FILE **fdset_2D; /* array of output file pointers */ - int SDIM; + IOJpegGeo_t *geo; + FILE *file; /* output file descriptor */ int si,max_slabs; - int ierr=0; + char *filename; + char *fullname; + char slice[20]; + ioAdvertisedFileDesc advertised_file; + int myproc; + int retval; - /* Get the handle for IO extensions */ - ssGH = (IOJpegGH *) GH->extensions [CCTK_GHExtensionHandle ("IOJpeg")]; - /* The dimension of the slab - HARDCODED */ - SDIM = 2; + /* the return code for success */ + retval = 0; - /* Get the slab geometry for 2D slabs */ - geo = ssGH->out_geo[index][SDIM]; - /* Set geo.sdim to announce 2D output */ - geo.sdim = SDIM; - /* get the dimension of the variable */ - geo.vdim = CCTK_GroupDimFromVarI(index); + /* get the processor ID */ + myproc = CCTK_MyProc (0); - if (!CCTK_Equals(verbose,"no")) - CCTK_VInfo (CCTK_THORNSTRING, "IOJpeg %dD-output of variable '%s', " - "downsampling parameters (%d, %d, %d)", SDIM, alias, - geo.downs[0], geo.downs [1], geo.downs [2]); - - /* get the current timelevel */ + /* get the variable's full name and the current timelevel */ + fullname = CCTK_FullName (index); timelevel = CCTK_NumTimeLevelsFromVarI (index) - 1; if (timelevel > 0) + { timelevel--; + } + + /* Get the handle for Jpeg's IO extensions */ + ssGH = (IOJpegGH *) GH->extensions[CCTK_GHExtensionHandle ("IOJpeg")]; + + /* Get this variable's slab geometry for 2D slabs */ + geo = &ssGH->out_geo[index][JPEG_SLABDIM]; - /* Maximal number of slabs (dimension sdim) in - given volume (dimension vdim) */ - if ((max_slabs=IOJpeg_NumDirection(SDIM, geo.vdim))<0) + /* Maximal number of 2D slabs in given volume (dimension vdim) */ + max_slabs = (geo->vdim * (geo->vdim - 1)) / 2; + if (max_slabs <= 0) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Cannot get valid number of slabs (%d) for given volume (%d).\n", - SDIM, geo.vdim); - return(-1); + "No 2D jpeg output available for variable '%s' alias '%s' " + "(dim %d)", fullname, alias, geo->vdim); + free (fullname); + return (-1); } - /* see if output file for this alias name was already created */ - fdset_2D = (FILE **) GetNamedData (ssGH->fileList_2D, alias); + if (! CCTK_Equals (verbose, "no")) { - char *fname; + CCTK_VInfo (CCTK_THORNSTRING, "IOJpeg 2D-output of variable '%s' " + "alias '%s'", fullname, alias); + } + + /* allocate memory for building the filename */ + filename = (char *) malloc (strlen (ssGH->outdir2D) + strlen (alias) + 50); - if (!fdset_2D) + /* Loop over all possible hyperslabs */ + for (si = 0; si < max_slabs; si++) + { + + /* Get the next set of slab directions */ + if (IOJpeg_SetDirection (geo, si) < 0) { - fdset_2D = (FILE **) malloc (max_slabs * sizeof (FILE *)); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Cannot set direction for slab (#%d) in given volume (%d).", + si, geo->vdim); + continue; } - fname = (char *) malloc ((strlen (ssGH->outdir2D) + - strlen (alias) + 20)*sizeof(char)); - /* Set flags for remembering if files have been advertised */ - if (!advertised) + /* set the slice string */ + sprintf (slice, "%d_%d", si, geo->vdim); + + /* processor 0 opens the output file */ + if (myproc == 0) { - int i; - advertised = (int **)malloc(max_slabs*sizeof(int *)); - for (si=0;sioutdir2D, alias, slice); } - } - - /* Loop over all possible choices */ - for (si=0;sioutdir2D, alias, slice, + GH->cctk_iteration); } - - /* ********************************************** - File open procedures which are more complex, - like for HDF5 can go here and you would pass - the file ID through to DumpVar. He we set fid=1 - for proc0 and make it available as a flag - ********************************************** */ - - if (CCTK_MyProc (GH) == 0) + file = fopen (filename, FILEOPENSTRING); + if (! file) { - ioAdvertisedFileDesc advertised_file; - const char *extensions [3] = {"yz", "xz", "xy"}; - - if (CCTK_Equals(mode,"remove")) - { - sprintf (fname, "%s/%s_2d_%s.jpeg", ssGH->outdir2D,alias, - extensions [si]); - } - else - { - sprintf (fname, "%s/%s_2d_%s.%d.jpeg", ssGH->outdir2D,alias, - extensions [si],GH->cctk_iteration); - } - - fdset_2D [si] = fopen (fname, FILEOPENSTRING); - if (! fdset_2D [si]) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Cannot open 2D output file '%s'", fname); - return (-1); - } - - /* advertise the file for downloading */ - if (CCTK_Equals(mode,"remove") && advertised[si][index]==0) - { - advertised_file.slice = (char *) extensions [si]; - advertised_file.thorn = CCTK_THORNSTRING; - advertised_file.varname = CCTK_FullName (index); - advertised_file.description = "Jpegs of slices"; - advertised_file.mimetype = "image/jpeg"; - - IOUtil_AdvertiseFile (GH, fname, &advertised_file); - advertised[si][index] = 1; - free (advertised_file.varname); - } + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Cannot open 2D jpeg output file '%s'", filename); } + } + else + { + file = NULL; + } + + /* now output the actual data */ + if (IOJpeg_DumpVar (GH, index, timelevel, geo, file) < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOJpeg_DumpVar failed for variable '%s'", fullname); + retval--; + } - /* store file desriptors in database */ - StoreNamedData (&ssGH->fileList_2D, alias, fdset_2D); - - /* ********************************************** - The call to the actual data collection and - lowlevel output routine. - ********************************************** */ - - ierr = IOJpeg_DumpVar(GH, index, timelevel, &geo, fdset_2D[si]); - if (ierr<0) CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "IOJpeg_DumpVar failed for GF index: %d\n", - index); - - /* ********************************************** - File close procedures which are more complex, - like for HDF5 can go here. - ********************************************** */ - - if(CCTK_MyProc(GH) == 0) + /* close the output file and advertise it */ + if (file) + { + /* Close the file */ + fclose (file); + + /* advertise the file for downloading */ + if (CCTK_Equals (mode, "remove") && ! advertised[si][index]) { - /* Close the file */ - fclose (fdset_2D [si]); + /* Set flag for remembering if file has been advertised */ + advertised[si][index] = 1; + + advertised_file.slice = slice; + advertised_file.thorn = CCTK_THORNSTRING; + advertised_file.varname = fullname; + advertised_file.description = "Jpegs of slices"; + advertised_file.mimetype = "image/jpeg"; + + IOUtil_AdvertiseFile (GH, filename, &advertised_file); } } - free(fname); + } /* end of loop over all 2D hyperslabs */ - } - - return(ierr); -} - -/******************************************************************** - ********************* Local Routines ************************* - ********************************************************************/ + /* free allocated resources */ + free (filename); + free (fullname); + return (retval); +} -- cgit v1.2.3