#include #include #include "cctk.h" #include "cctk_Parameters.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;idimslab_start[idim]; for (idim=0;idimsdim;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); if (hsizes) { free (hsizes); } 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); } if(CCTK_MyProc(GH) == 0) { AutoColorDataSlice(hsize[0], hsize[1], data, dataout, min, max, colormap_bias, colormap_factor); WriteJPEGToFileRGB(hsize[0], hsize[1], dataout, colormap_quality, fid); } free(dataout); return(1); }