diff options
Diffstat (limited to 'src/Write2D.c')
-rw-r--r-- | src/Write2D.c | 114 |
1 files changed, 56 insertions, 58 deletions
diff --git a/src/Write2D.c b/src/Write2D.c index 6260c89..f0f0ee0 100644 --- a/src/Write2D.c +++ b/src/Write2D.c @@ -1,7 +1,7 @@ #include "cctk.h" #include "cctk_Parameters.h" -#include "CactusBase/IOUtil/src/ioGH.h" +#include "CactusBase/IOUtil/src/ioutil_AdvertisedFiles.h" #include "IOJpeg.h" #include <stdio.h> @@ -18,7 +18,6 @@ int IOJpeg_Write2D (cGH *GH, int index, const char *alias) { DECLARE_CCTK_PARAMETERS int timelevel; - ioGH *ioUtilGH; IOJpegGH *ssGH; IOJpegGeo_t geo; FILE **fdset_2D; /* array of output file pointers */ @@ -27,7 +26,6 @@ int IOJpeg_Write2D (cGH *GH, int index, const char *alias) int ierr=0; /* Get the handle for IO extensions */ - ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; ssGH = (IOJpegGH *) GH->extensions [CCTK_GHExtensionHandle ("IOJpeg")]; /* The dimension of the slab - HARDCODED */ @@ -70,7 +68,7 @@ int IOJpeg_Write2D (cGH *GH, int index, const char *alias) fdset_2D = (FILE **) malloc (max_slabs * sizeof (FILE *)); } fname = (char *) malloc ((strlen (ssGH->outdir2D) + - strlen (alias) + 20)*sizeof(char)); + strlen (alias) + 20)*sizeof(char)); /* Set flags for remembering if files have been advertised */ if (!advertised) @@ -79,11 +77,11 @@ int IOJpeg_Write2D (cGH *GH, int index, const char *alias) advertised = (int **)malloc(max_slabs*sizeof(int *)); for (si=0;si<max_slabs;si++) { - advertised[si] = (int *)malloc(CCTK_NumVars()*sizeof(int)); - for (i=0;i<CCTK_NumVars();i++) - { - advertised[si][i] = 0; - } + advertised[si] = (int *)malloc(CCTK_NumVars()*sizeof(int)); + for (i=0;i<CCTK_NumVars();i++) + { + advertised[si][i] = 0; + } } } @@ -92,57 +90,57 @@ int IOJpeg_Write2D (cGH *GH, int index, const char *alias) /* Get the next set of slab directions */ if (IOJpeg_SetDirection(geo.vdim, SDIM, si, geo.direction)<0) { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Cannot set direction for slab (#%d) in given volume (%d).\n", - si, geo.vdim); - continue; + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Cannot set direction for slab (#%d) in given volume (%d).\n", + si, geo.vdim); + continue; } /* ********************************************** - 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 - ********************************************** */ + 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) { - IOUtil_AdvertisedFileDesc_t 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, "w"); - if (! fdset_2D [si]) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Cannot open 2D output file '%s'", fname); - return; - } - - /* 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); - } + 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, "w"); + 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); + } } /* store file desriptors in database */ @@ -155,13 +153,13 @@ int IOJpeg_Write2D (cGH *GH, int index, const char *alias) 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); + "IOJpeg_DumpVar failed for GF index: %d\n", + index); /* ********************************************** - File close procedures which are more complex, - like for HDF5 can go here. - ********************************************** */ + File close procedures which are more complex, + like for HDF5 can go here. + ********************************************** */ /* Close the file */ fclose (fdset_2D [si]); |