diff options
author | allen <allen@eff87b29-5268-4891-90a3-a07138403961> | 2000-09-20 10:58:58 +0000 |
---|---|---|
committer | allen <allen@eff87b29-5268-4891-90a3-a07138403961> | 2000-09-20 10:58:58 +0000 |
commit | ff5c80e7f3d2d2d3f8ca612488aa229c27bbdd89 (patch) | |
tree | 7ae01c14349fe8782c95facb9951f9d365470d89 /src/DumpVar.c | |
parent | 8297f44fc3400c0e6ed380c35db318a18bf89c47 (diff) |
This commit was generated by cvs2svn to compensate for changes in r2, which
included commits to RCS files with non-trunk default branches.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusIO/IOJpeg/trunk@3 eff87b29-5268-4891-90a3-a07138403961
Diffstat (limited to 'src/DumpVar.c')
-rw-r--r-- | src/DumpVar.c | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/src/DumpVar.c b/src/DumpVar.c new file mode 100644 index 0000000..96613da --- /dev/null +++ b/src/DumpVar.c @@ -0,0 +1,155 @@ + +#include <stdio.h> +#include <stdlib.h> + +#include "cctk.h" +#include "cctk_Parameters.h" +#include "CactusBase/IOUtil/src/ioGH.h" +#include "CactusPUGH/PUGHSlab/src/PUGHSlab.h" +#include "IOJpeg.h" + +int IOJpeg_Output(cGH *GH, int index, int timelevel, CCTK_REAL *data, + int sdim, int *hsize, int vtype, FILE *fid); + + +int IOJpeg_DumpVar (cGH *GH, int index, int timelevel, IOJpegGeo_t *geo, FILE *fid) +{ + DECLARE_CCTK_PARAMETERS + void *data=NULL; + int *hsizes, slabstart[SLABSKEL_MAXDIM]; + IOJpegGH *ssGH; + int vtype; + int idim, vdim; + + int sdir[3] = {0,0,0}; + + /* Get the handle for StreamedHDF5 extensions */ + ssGH = (IOJpegGH *) GH->extensions [CCTK_GHExtensionHandle ("IOJpeg")]; + + /* Allocate buffer to hold actual slab sizes */ + hsizes = (int*)malloc(geo->sdim*sizeof(int)); + + vdim= geo->vdim; + + /* Checks for vartype can go here */ + vtype = CCTK_VarTypeI (index); + + /* TEMPORARY FIX DUE TO INCONSISTENT DIR SPECIFICATION */ + /* direction vector of 1d line in 3d volume */ + if (geo->sdim==1) { + sdir[0] = (geo->direction[0]==0) ? 1:0; + sdir[1] = (geo->direction[0]==1) ? 1:0; + sdir[2] = (geo->direction[0]==2) ? 1:0; + } + /* norm vector of 2d surface in 3d volume */ + else if (geo->sdim==2) + { + sdir[0] = ((geo->direction[0]==1)&&(geo->direction[1]==2)) ? 1:0; + sdir[1] = ((geo->direction[0]==0)&&(geo->direction[1]==2)) ? 1:0; + sdir[2] = ((geo->direction[0]==0)&&(geo->direction[1]==1)) ? 1:0; + } + /* spanning directions for 3d */ + else if (geo->sdim==3) + { + sdir[0] = geo->direction[0]; + sdir[1] = geo->direction[1]; + sdir[2] = geo->direction[2]; + } + else + { + char *fullname = CCTK_FullName (index); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "No 0-dim extraction possible: '%s'", fullname); + free (fullname); + return (-1); + } + + /* Get the start indices for the slab from slab_start. */ + /* Slab_start from the geo structure is not a true start index, it is currently + used as the intersection point of n surfaces , that's why two entries + have to be set to zero in the case of a surface (one entry for line) FIXME */ + for (idim=0;idim<vdim;idim++) + slabstart[idim] = geo->slab_start[idim]; + for (idim=0;idim<geo->sdim;idim++) + slabstart[geo->direction[idim]]=0; + + /* Data Extraction takes place, data will be gathered onto processor 0 + hyperslab data will be in data, + hyperslab sizes: hsizes[SLAB_DIM]. + */ + if (Hyperslab_GetHyperslab (GH, 0, index, timelevel, geo->sdim, slabstart, + sdir, geo->length, geo->downs, + &data, hsizes) < 0) + { + char *fullname = CCTK_FullName (index); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Failed to extract hyperslab for variable '%s'", fullname); + free (fullname); + return (-1); + } + + /* Output routine for valid fid (was set in Write nD) */ + if (fid) + { + 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); + } + } + + if (data) + free (data); + + return (0); +} + + + +int IOJpeg_Output(cGH *GH, int index, int timelevel, CCTK_REAL *data, + int sdim, int *hsize, int vtype, FILE *fid) +{ + DECLARE_CCTK_PARAMETERS + + unsigned char *dataout=(unsigned char *)malloc(3*hsize[0]*hsize[1]); + CCTK_REAL min,max; + + if (sdim!=2) return(-1); + + if (CCTK_Equals(colormap,"custom")) + { + min = colormap_min; + max = colormap_max; + } + else + { + int reduction_handle,ierr; + reduction_handle = CCTK_ReductionHandle ("maximum"); + ierr = CCTK_Reduce (GH, 0, reduction_handle, 1, + CCTK_VARIABLE_REAL,&max, 1, index); + reduction_handle = CCTK_ReductionHandle ("minimum"); + ierr = CCTK_Reduce (GH, 0, reduction_handle, 1, + CCTK_VARIABLE_REAL,&min, 1, index); + } + + AutoColorDataSlice(hsize[0], + hsize[1], + data, + dataout, + min, + max, + colormap_bias, + colormap_factor); + + WriteJPEGToFileRGB(hsize[0], + hsize[1], + dataout, + colormap_quality, + fid); + + return(1); +} + |