einsteintoolkit / CactusIO_IOJpeg.json
xinshuo's picture
Upload folder using huggingface_hub
10a2580 verified
{
"thorn_name": "CactusIO/IOJpeg",
"url": "https://bitbucket.org/cactuscode/cactusio.git",
"configuration": "# Configuration definitions for thorn IOJpeg\n\nREQUIRES libjpeg\n",
"interface": "# Interface definition for thorn IOJpeg\n# $Header$\n\nimplements: IOJpeg\ninherits: IO\n\nCCTK_INT FUNCTION \\\n Hyperslab_Get (CCTK_POINTER_TO_CONST IN cctkGH, \\\n CCTK_INT IN mapping_handle, \\\n CCTK_INT IN proc, \\\n CCTK_INT IN vindex, \\\n CCTK_INT IN timelevel, \\\n CCTK_INT IN hdatatype, \\\n CCTK_POINTER IN hdata)\n\nCCTK_INT FUNCTION \\\n Hyperslab_GlobalMappingByIndex (CCTK_POINTER_TO_CONST IN cctkGH, \\\n CCTK_INT IN vindex, \\\n CCTK_INT IN hdim, \\\n CCTK_INT ARRAY IN direction, \\\n CCTK_INT ARRAY IN origin, \\\n CCTK_INT ARRAY IN extent, \\\n CCTK_INT ARRAY IN downsample, \\\n CCTK_INT IN table_handle, \\\n CCTK_INT CCTK_FPOINTER IN \\\n conversion_fn (CCTK_INT IN nelems, \\\n CCTK_INT IN src_stride,\\\n CCTK_INT IN dst_stride,\\\n CCTK_INT IN src_type, \\\n CCTK_INT IN dst_type, \\\n CCTK_POINTER_TO_CONST IN src, \\\n CCTK_POINTER IN dst), \\\n CCTK_INT ARRAY OUT hsize)\n\nCCTK_INT FUNCTION Hyperslab_FreeMapping (CCTK_INT IN mapping_handle)\n\n\nREQUIRES FUNCTION Hyperslab_Get\nREQUIRES FUNCTION Hyperslab_GlobalMappingByIndex\nREQUIRES FUNCTION Hyperslab_FreeMapping\n",
"param": "# Parameter definitions for thorn IOJpeg\n# $Header$\n\n#############################################################################\n### declare IOJpeg parameters\n#############################################################################\nprivate:\n\n########################\n# The basic parameters:\n# how often to do output\n# for which variables\n# into which output directory\n########################\nINT out_every \"How often to do IOJpeg output, overrides IO::out_every\" STEERABLE = ALWAYS\n{\n 1:* :: \"Every so many iterations\"\n 0: :: \"Disable IOJpeg output\"\n -1: :: \"Choose the default from IO::out_every\"\n} -1\n\nSTRING out_vars \"Variables to output by IOJpeg\" STEERABLE = ALWAYS\n{\n \".+\" :: \"Space-separated list of fully qualified variable/group names\"\n \"^$\" :: \"An empty string to output nothing\"\n} \"\"\n\nSTRING out_dir \"Output directory for IOJpeg files, overrides IO::out_dir\" STEERABLE = RECOVER\n{\n \".+\" :: \"A valid directory name\"\n \"^$\" :: \"An empty string to choose the default from IO::out_dir\"\n} \"\"\n\nKEYWORD mode \"Output mode to use\" STEERABLE = ALWAYS\n{\n \"remove\" :: \"Remove files from old timesteps\"\n \"standard\" :: \"Generate a file for each out_every timesteps\"\n} \"standard\"\n\nKEYWORD gridpoints \"How to access grid points\" STEERABLE = RECOVER\n{\n \"hyperslab\" :: \"use locations of grid points\"\n \"interpolate\" :: \"interpolate to arbitrary points\"\n} \"hyperslab\"\n\n\n########################\n# Specific to jpegs\n########################\nREAL colormap_bias \"Bias automatic colormap generation towards red (low) or blue (high)\" STEERABLE = ALWAYS\n{\n -1:1 :: \"Could be unrestricted\"\n} 0.5\n\nINT colormap_quality \"JPEG quality of level\" STEERABLE = ALWAYS\n{\n 0:100 :: \"Percentage of full quality\"\n} 75\n\nINT colormap_factor \"How to scale float values to rgb color\" STEERABLE = ALWAYS\n{\n 2:256 :: \"Positive scaling\"\n} 32\n\nKEYWORD colormap \"How to set the colormap\" STEERABLE = ALWAYS\n{\n \"auto\" :: \"Set automatically using min/max of grid variables\"\n \"auto-old\" :: \"Set automatically using min/max of grid variables, using the old reduction interface which is still used by Carpet\"\n \"custom\" :: \"Set min/max manually\"\n} \"custom\"\n\nREAL colormap_min \"minimum value to be mapped to colors\" STEERABLE = ALWAYS\n{\n *:* :: \"Only for custom colormap scale\"\n} -1.0\nREAL colormap_max \"maximum value to be mapped to colors\" STEERABLE = ALWAYS\n{\n *:* :: \"Only for custom colormap scale\"\n} +1.0\n\nINT refinement_factor \"Refine each 2D slice by a certain factor (using interpolation) ?\" STEERABLE = ALWAYS\n{\n 1:* :: \"A factor greater 0\"\n} 1\n\n\n###################################################\n# Choosing what planes to output when hyperslabbing\n###################################################\nREAL out2D_yzplane_x \"x-coord for 2D planes in yz\" STEERABLE = RECOVER\n{\n *:* :: \"A value between [xmin, xmax]\"\n -424242: :: \"Default to IO::out_yzplane_x\"\n} -424242\nREAL out2D_xzplane_y \"y-coord for 2D planes in xz\" STEERABLE = RECOVER\n{\n *:* :: \"A value between [ymin, ymax]\"\n -424242: :: \"Default to IO::out_xzplane_y\"\n} -424242\nREAL out2D_xyplane_z \"z-coord for 2D planes in xy\" STEERABLE = RECOVER\n{\n *:* :: \"A value between [zmin, zmax]\"\n -424242: :: \"Default to IO::out_xyplane_z\"\n} -424242\n\nINT out2D_yzplane_xi \"x-index (from 0) for 2D planes in yz\" STEERABLE = RECOVER\n{\n 0:* :: \"An index between [0, nx)\"\n -1: :: \"Choose the default from IO::out_yzplane_xi\"\n} -1\nINT out2D_xzplane_yi \"y-index (from 0) for 2D planes in xz\" STEERABLE = RECOVER\n{\n 0:* :: \"An index between [0, ny)\"\n -1: :: \"Choose the default from IO::out_xzplane_yi\"\n} -1\nINT out2D_xyplane_zi \"z-index (from 0) for 2D planes in xy\" STEERABLE = RECOVER\n{\n 0:* :: \"An index between [0, nz)\"\n -1: :: \"Choose the default from IO::out_xyplane_zi\"\n} -1\n\n\n###################################################\n# Choosing what region to output when interpolating\n###################################################\n\nSTRING interpolator_name \"Name of the interpolator\" STEERABLE=always\n{\n \".*\" :: \"must be a registered interpolator\"\n} \"Lagrange polynomial interpolation\"\n\nSTRING interpolator_options \"Options for the interpolator\" STEERABLE=always\n{\n \".*\" :: \"must be a valid option specification\"\n} \"order=2\"\n\nSTRING interpolator_coordinates \"Coordinate system\" STEERABLE=always\n{\n \".*\" :: \"must be a registered coordinate system\"\n} \"cart3d\"\n\nBOOLEAN multiply_by_radius \"Multiply valus by r\" STEERABLE=always\n{\n} \"no\"\n\n\n\nREAL array2d_x0 \"Origin\" STEERABLE=always\n{\n *:* :: \"\"\n} 0.0\n\nREAL array2d_y0 \"Origin\" STEERABLE=always\n{\n *:* :: \"\"\n} 0.0\n\nREAL array2d_z0 \"Origin\" STEERABLE=always\n{\n *:* :: \"\"\n} 0.0\n\nINT array2d_npoints_i \"Number of grid points for the 2D grid arrays in the i direction\"\n{\n 0:* :: \"\"\n} 10\n\nREAL array2d_dx_i \"Spacing\" STEERABLE=always\n{\n 0.0:* :: \"\"\n} 0.0\n\nREAL array2d_dy_i \"Spacing\" STEERABLE=always\n{\n 0.0:* :: \"\"\n} 0.0\n\nREAL array2d_dz_i \"Spacing\" STEERABLE=always\n{\n 0.0:* :: \"\"\n} 0.0\n\nINT array2d_npoints_j \"Number of grid points for the 2D grid arrays in the j direction\"\n{\n 0:* :: \"\"\n} 10\n\nREAL array2d_dx_j \"Spacing\" STEERABLE=always\n{\n 0.0:* :: \"\"\n} 0.0\n\nREAL array2d_dy_j \"Spacing\" STEERABLE=always\n{\n 0.0:* :: \"\"\n} 0.0\n\nREAL array2d_dz_j \"Spacing\" STEERABLE=always\n{\n 0.0:* :: \"\"\n} 0.0\n\n\n#############################################################################\n### import IOUtil parameters\n#############################################################################\nshares: IO\n\nUSES STRING out_dir AS io_out_dir\nUSES INT out_every AS io_out_every\nUSES KEYWORD verbose\nUSES BOOLEAN strict_io_parameter_check\nUSES REAL out_yzplane_x\nUSES REAL out_xzplane_y\nUSES REAL out_xyplane_z\nUSES INT out_yzplane_xi\nUSES INT out_xzplane_yi\nUSES INT out_xyplane_zi\n",
"schedule": "# Schedule definitions for thorn IOJpeg\n# $Header$\n\n########################################################################\n### register IOJpeg routines\n########################################################################\nschedule IOJpeg_Startup at STARTUP after IOUtil_Startup\n{\n LANG:C\n} \"Startup routine\"\n\nschedule IOJpeg_ChooseOutput at BASEGRID after SpatialCoordinates\n{\n LANG:C\n} \"Choose 2D output planes\"\n",
"src": {
"ioJpegGH.h": " /*@@\n @header ioJpegGH.h\n @date Thu 18 April 2002\n @author Thomas Radke\n @desc\n The extensions to the GH structure from IOJpeg.\n @enddesc\n @version $Header$\n @@*/\n\n#ifndef IOJPEG_IOJPEGGH_H_\n#define IOJPEG_IOJPEGGH_H_ 1\n\n#include <stdio.h>\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\ntypedef struct IOJpegGH\n{\n /* default number of times to output */\n int out_every_default;\n\n /* number of times to output every variable */\n CCTK_INT *out_every;\n\n /* the last iteration output for every variable */\n int *out_last;\n\n /* list of variables to output */\n char *out_vars;\n\n /* directories in which to output */ \n char *out_dir;\n\n /* for 2D planes, we define the index where to locate the plane\n sp2xyz[maxdim][perpendicular direction] */\n int **sp2xyz;\n\n /* stop on I/O parameter parsing errors ? */\n int stop_on_parse_errors;\n\n} ioJpegGH;\n\n\n/* prototypes of functions to be registered as I/O method */\nint IOJpeg_OutputGH (const cGH *GH);\nint IOJpeg_OutputVarAs (const cGH *GH, const char *fullname, const char *alias);\nint IOJpeg_TimeFor (const cGH *GH, int vindex);\nint IOJpeg_TriggerOutput (const cGH *GH, int vindex);\n\n/* other function prototypes */\nint IOJpeg_Write (const cGH *GH, CCTK_INT vindex, const char *alias);\nvoid IOJpeg_CheckSteerableParameters (ioJpegGH *myGH);\n\n/* routines called from JPEG.c */\nint WriteJPEGToFileRGB (int nx, int ny, void *data, int Quality, FILE* outfile);\nint WriteJPEGToMemoryRGB (int nx, int ny, void *data, int Quality, char *buffer,\n int buffersize);\nvoid AutoColorDataSlice (int nx, int ny, const CCTK_REAL *datain,\n unsigned char *dataout, CCTK_REAL min, CCTK_REAL max,\n CCTK_REAL bias, int rdfac);\n\n#ifdef __cplusplus\n} // extern \"C\"\n#endif\n\n#endif /* IOJPEG_IOJPEGGH_H_ */\n",
"make.code.defn": "# Main make.code.defn file for thorn IOJpeg\n# $Header$\n\n# Source files in this directory\nSRCS = Startup.c Output.c Write.c ChooseOutput.c JPEG.c\n",
"JPEG.c": "#include \"cctk.h\"\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <math.h> \n\n#include \"ioJpegGH.h\"\n\n#include \"jconfig.h\"\n#include \"jpeglib.h\"\n\nstatic const char *rcsid = \"$Header$\";\n\nCCTK_FILEVERSION(CactusIO_IOJpeg_JPEG_c)\n\ntypedef struct jpeg_compress_struct JpgComp;\n\n#ifndef JpgErr\ntypedef struct jpeg_error_mgr JpgErr;\n#endif\n\n/* prototypes of routines defined in this source file */\nGLOBAL(void)\njpeg_memory_dest (j_compress_ptr cinfo, JOCTET *buffer,int bufsize);\n\n\n/*\n Image data is an array of unsigned character array of\n RGB data. The data is stored in interleaved order.\n IE, the first three elements are a byte of Red followed\n by a byte of Green and then a byte of Blue for the first\n pixel. Data is stored in fortran order (ie. x is fastest\n moving dimension).\n */\nint WriteJPEGToFileRGB(int nx, /* width of image in pixels */\n int ny, /* height of the image in pixels */\n void *data, /* buffer containing image data */\n int Quality, /* Integer from 0 to 100 */\n FILE* outfile){ /* name of file to store in */\n JpgComp cinfo;\n JpgErr jerr; \n /* FILE * outfile;*/\n unsigned char *dataRGB = (unsigned char *)data;\n JSAMPROW row_pointer=(JSAMPROW)dataRGB;\n \n memset (&cinfo,0,sizeof(cinfo));\n cinfo.err = jpeg_std_error(&jerr);\n jpeg_create_compress(&cinfo);\n \n /* Setup JPEG */\n cinfo.image_width = nx ; /* image width and height, in pixels */\n cinfo.image_height = ny;\n cinfo.input_components = 3; /* # of color components per pixel=3 RGB */\n cinfo.in_color_space = JCS_RGB;\n /* if ((outfile = fopen(FileName, \"wb\")) == NULL) {\n printf(\"Cannot open file [%s]\\n\",FileName);\n return 0; \n } */\n jpeg_stdio_dest(&cinfo, outfile);\n jpeg_set_defaults(&cinfo);\n jpeg_set_quality (&cinfo,Quality,TRUE);\n /* Starting compress */\n jpeg_start_compress(&cinfo, TRUE);\n /* Now compress everything one scanline at-a-time */\n while (cinfo.next_scanline < cinfo.image_height) {\n row_pointer = (JSAMPROW)(dataRGB+(cinfo.next_scanline*3*nx)); /* in bytes or words? */\n jpeg_write_scanlines(&cinfo, &row_pointer, 1);\n }\n jpeg_finish_compress(&cinfo);\n jpeg_destroy_compress(&cinfo);\n /* All done! */\n /* fclose(outfile);*/\n return 1;\n}\n\n/*--------------\n A hack to hijack JPEG's innards to write into a memory buffer\n----------------\n/ this defines a new destination manager to store images in memory\n/ derived by jdatadst.c */\ntypedef struct {\n struct jpeg_destination_mgr pub; /* public fields */\n JOCTET *buffer; /* start of buffer */\n int bufsize; /* buffer size */\n int datacount; /* finale data size */\n} memory_destination_mgr;\n\ntypedef memory_destination_mgr *mem_dest_ptr;\n\n/*----------------------------------------------------------------------------\n / Initialize destination --- called by jpeg_start_compress before any data is actually written. */\n\nMETHODDEF(void)\ninit_destination (j_compress_ptr cinfo)\n{\n mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest;\n\n dest->pub.next_output_byte = dest->buffer;\n dest->pub.free_in_buffer = dest->bufsize;\n dest->datacount=0;\n}\n\n\n\n/*----------------------------------------------------------------------------\n / Empty the output buffer --- called whenever buffer fills up. */\nMETHODDEF(boolean)\nempty_output_buffer (j_compress_ptr cinfo)\n{\n mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest;\n\n dest->pub.next_output_byte = dest->buffer;\n dest->pub.free_in_buffer = dest->bufsize;\n\n return TRUE;\n}\n\n\n/*----------------------------------------------------------------------------\n\n / Terminate destination --- called by jpeg_finish_compress\n / after all data has been written. Usually needs to flush buffer. */\nMETHODDEF(void)\nterm_destination (j_compress_ptr cinfo)\n{\n /* expose the finale compressed image size */\n \n mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest;\n dest->datacount = dest->bufsize - dest->pub.free_in_buffer;\n \n}\n\n/*----------------------------------------------------------------------------\n/ Prepare for output to a memory buffer. The caller must have allocate memory\n/ to store the compressed image, and supply its size */\nGLOBAL(void)\njpeg_memory_dest (j_compress_ptr cinfo, JOCTET *buffer,int bufsize)\n{\n mem_dest_ptr dest;\n if (cinfo->dest == NULL) { /* first time for this JPEG object? */\n cinfo->dest = (struct jpeg_destination_mgr *)\n (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,\n sizeof(memory_destination_mgr));\n }\n\n dest = (mem_dest_ptr) cinfo->dest;\n dest->bufsize=bufsize;\n dest->buffer=buffer;\n dest->pub.init_destination = init_destination;\n dest->pub.empty_output_buffer = empty_output_buffer;\n dest->pub.term_destination = term_destination;\n}\n\n/********************************************\nIdentical in nearly every way to WriteJPEGToFileRGB(), but\nit writes into the memory buffer specified. To be safe, its\ngood to make the memorybuffer the same size as the input image\n+ 1024 bytes. It is guaranteed that the image will be less\nthan this size. In fact, if you use a typical \"quality\" level\nof 75, you can get away with an image which is one quarter that\nsize.\n\n ******************************************** */\nint WriteJPEGToMemoryRGB(int nx,int ny, void *data, int Quality, char *memorybuffer,int bufsize){ \n JpgComp cinfo;\n JpgErr jerr; \n unsigned char *dataRGB = (unsigned char *)data;\n JSAMPROW row_pointer=(JSAMPROW)dataRGB;\n JOCTET *jpgbuff;\n mem_dest_ptr dest;\n int csize=0;\n\n /* zero out the compresion info structures and\n allocate a new compressor handle */\n memset (&cinfo,0,sizeof(cinfo));\n cinfo.err = jpeg_std_error(&jerr);\n jpeg_create_compress(&cinfo);\n \n /* Setup JPEG datastructures */\n cinfo.image_width = nx ; /* image width and height, in pixels */\n cinfo.image_height = ny;\n cinfo.input_components = 3; /* # of color components per pixel=3 RGB */\n cinfo.in_color_space = JCS_RGB; \n jpgbuff = (JOCTET*)memorybuffer;\n\n /* Setup compression and do it */\n jpeg_memory_dest(&cinfo,jpgbuff,bufsize);\n jpeg_set_defaults(&cinfo);\n jpeg_set_quality (&cinfo,Quality,TRUE);\n jpeg_start_compress(&cinfo, TRUE);\n /* compress each scanline one-at-a-time */\n while (cinfo.next_scanline < cinfo.image_height) {\n row_pointer = (JSAMPROW)(dataRGB+(cinfo.next_scanline*3*nx));\n jpeg_write_scanlines(&cinfo, &row_pointer, 1);\n }\n jpeg_finish_compress(&cinfo);\n /* Now extract the size of the compressed buffer */\n dest=(mem_dest_ptr)cinfo.dest;\n csize=dest->datacount; /* the actual compressed datasize */\n /* destroy the compressor handle */\n jpeg_destroy_compress(&cinfo);\n return csize;\n}\n\n#define ClampToByte(f) (unsigned char)(f=(f>255)?255:f)\n/* Werner's nifty non-linear red-to-blue auto-colormap.\n I faked a CCTK_REAL, you can make it the right thing\n when integrated with cactus.\n\n Anyways, the \"rdfac\" concentrates the colormap when you\n use higher values. Typical default value is 32 based\n on the current JPEG thorn.\n\n Next step is to embed some IDL colormaps into the\n program. I can do that a bit later.\n*/\n\nvoid AutoColorDataSlice(int nx,int ny, /* size of the image x & y */\n const CCTK_REAL *datain, /* 2D slice of data input */\n unsigned char *dataout, /* RGB image data output */\n CCTK_REAL min,CCTK_REAL max, /* range of the entire 3D dataset\n This could be ranged based \n on the values of the slice,\n but then that would be a\n bit untrustworthy. Its\n best to pass in the \n range for the entire \n dataset or a pre-defined\n fixed range. It does\n handle clamping of the\n range. */\n CCTK_REAL bias,\n int rdfac){\n /* Bias allows you to move the spectrum from the Red to the\n Blue. A value of 0.5 is the median. So 0.4 biases towards\n the Red and 0.6 would bias a little towards the blue.\n The range for this parameter would be -1.0 to +1.0. */\n /* CCTK_REAL bias=0.4;*/\n int i,last;\n CCTK_REAL F=(CCTK_REAL)rdfac; /* cast to CCTK_REAL... don't know how the original worked at all without a cast */\n for(i=0,last=nx*ny;i<last;i++,dataout+=3){\n CCTK_REAL f;\n\n /* check for division by 0 */\n if (min == max)\n {\n f = bias;\n }\n else\n {\n f = bias-(*datain++ - min)/(max-min);\n }\n /* f-=(max-min); zero-center it */\n /* well it can't be less than 0 */\n if(f>0){\n f*=F;\n /* Color components biased towards blue */\n dataout[0]=ClampToByte(f);\n f*=F;\n dataout[1]=ClampToByte(f);\n f*=F;\n dataout[2]=ClampToByte(f);\n }\n else { /* f<0 */\n f=-f;\n f*=F;\n /* reverse color components to bias towards red */\n dataout[2]=ClampToByte(f);\n f*=F;\n dataout[1]=ClampToByte(f);\n f*=F;\n dataout[0]=ClampToByte(f);\n }\n }\n}\n\n#if 0\nint main(int argc,char *argv[]){\n /* OK, lets create a bogus image */\n int nx=512,ny=512;\n unsigned char *datargb=(unsigned char *)malloc(3*nx*ny);\n CCTK_REAL *data= (CCTK_REAL*)malloc(nx*ny*sizeof(CCTK_REAL));\n int i,j,idx=0;\n CCTK_REAL radius=((CCTK_REAL)(nx/4));\n CCTK_REAL min=(CCTK_REAL)(nx*ny),max=-1.0;\n int bufsize = nx*ny*3+1024;\n char *memorybuffer=(char *)malloc(bufsize); /* safe size for membuf */\n int compressed_size=0;\n FILE *outfile;\n /* compute a circle by the most inefficient means possible */\n for(j=0,idx=0;j<ny;j++){\n CCTK_REAL y=((CCTK_REAL)(j-ny/2));\n y*=y;\n /* fprintf(stderr,\"\\n\"); */\n for(i=0;i<nx;i++,idx++){\n CCTK_REAL x = ((CCTK_REAL)(i-nx/2));\n CCTK_REAL val;\n x*=x;\n data[idx]= val=sqrt(x+y);\n \n if(val>max) max=val;\n if(val<min) min=val;\n }\n }\n printf(\"Slice Data Min=%g Max=%g\\n\",min,max);\n /* Autocolor extracted from Werner's JPEG thorn */\n AutoColorDataSlice(nx,ny,data,datargb,min,max,32);\n WriteJPEGToFileRGB(nx,ny, datargb,75, \"write2file.jpg\");\n /* write to mem: It returns the size of the compressed image \n cdntained in the memorybuffer */\n compressed_size = WriteJPEGToMemoryRGB(nx,ny, datargb,75, memorybuffer,bufsize);\n if ((outfile = fopen(\"write2mem.jpg\", \"wb\")) == NULL) {\n printf(\"Cannot open file write2mem.jpg\\n\");\n return 0; /* failure */\n } \n fwrite(memorybuffer,1,compressed_size,outfile);\n fclose(outfile);\n return 1;\n}\n#endif\n",
"ChooseOutput.c": "/*@@\n @file ChooseOutput.c\n @date Thu 18 April 2002\n @author Thomas Radke\n @desc\n Choose what 2D planes to output by IOJpeg.\n @enddesc\n\n @version $Id$\n @@*/\n\n#include <stdlib.h>\n#include <string.h>\n\n#include \"cctk.h\"\n#include \"cctk_Arguments.h\"\n#include \"cctk_Parameters.h\"\n#include \"CactusBase/IOUtil/src/ioutil_Utils.h\"\n#include \"ioJpegGH.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusIO_IOJpeg_ChooseOutput_c)\n\n\n/********************************************************************\n ******************** Macro Definitions ************************\n ********************************************************************/\n/* macro to choose origin according actual parameter settings:\n 1. Indices from IOJpeg\n 2. Indices from IOUtil\n 3. Coords from IOJpeg\n 4. Coords from IOUtil\n */\n#define GET_SLICE(IOJpeg_param, IOUtil_param, index, coord) \\\n { \\\n index = IOJpeg_param##i >= 0 ? IOJpeg_param##i : IOUtil_param##i; \\\n coord = IOJpeg_param != -424242 ? IOJpeg_param : IOUtil_param; \\\n }\n\n\n/********************************************************************\n ******************** External Routines ************************\n ********************************************************************/\n\n/*@@\n @routine IOJpeg_ChooseOutput\n @date Thu 18 April 2002\n @author Thomas Radke\n @desc\n Use parameters to choose the 2D slices through the output data.\n @enddesc\n\n @calls IOUtil_2DPlanes\n\n @var GH\n @vdesc Pointer to CCTK grid hierarchy\n @vtype const cGH *\n @vio in\n @endvar\n @@*/\nvoid IOJpeg_ChooseOutput (CCTK_ARGUMENTS)\n{\n int i, maxdim;\n ioJpegGH *myGH;\n int origin_index[3];\n CCTK_REAL origin_phys[3];\n DECLARE_CCTK_ARGUMENTS;\n DECLARE_CCTK_PARAMETERS;\n\n\n GET_SLICE (out2D_xyplane_z, out_xyplane_z, origin_index[0], origin_phys[0]);\n GET_SLICE (out2D_xzplane_y, out_xzplane_y, origin_index[1], origin_phys[1]);\n GET_SLICE (out2D_yzplane_x, out_yzplane_x, origin_index[2], origin_phys[2]);\n\n maxdim = CCTK_MaxDim ();\n myGH = (ioJpegGH *) CCTK_GHExtension (cctkGH, \"IOJpeg\");\n myGH->sp2xyz = (int **) malloc (3 * sizeof (int *));\n\n for (i = 0; i < maxdim; i++)\n {\n myGH->sp2xyz[i] = (int *) calloc (i + 1, sizeof (int));\n\n if (i > 0 && i < 3)\n {\n IOUtil_2DPlanes (cctkGH, i + 1, origin_index, origin_phys, myGH->sp2xyz[i]);\n }\n }\n}\n",
"Output.c": " /*@@\n @file Output.c\n @date Thu May 11 2000\n @author Thomas Radke\n @desc\n Functions to deal with Jpeg output of variables.\n @enddesc\n @version $Id$\n @@*/\n\n#include <stdlib.h>\n#include <string.h>\n\n#include \"cctk.h\"\n#include \"cctk_Parameters.h\"\n#include \"util_String.h\"\n#include \"CactusBase/IOUtil/src/ioutil_Utils.h\"\n#include \"ioJpegGH.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusIO_IOJpeg_Output_c)\n\n/* define this if you want debug output */\n/* #define IOJPEG_DEBUG 1 */\n\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\nstatic int CheckOutputVar (int vindex);\nstatic void SetOutputFlag (int vindex, const char *optstring, void *arg);\n\n\n/*@@\n @routine IOJpeg_OutputGH\n @date Thu 18 April 2002\n @author Thomas Radke\n @desc\n Loops over all variables and outputs them if necessary\n @enddesc\n @calls IOJpeg_TimeFor\n IOJpeg_Write\n\n @var GH\n @vdesc pointer to CCTK GH\n @vtype const cGH *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n the number of variables which were output at this iteration\n (or 0 if it wasn't time to output yet)\n @endreturndesc\n@@*/\nint IOJpeg_OutputGH (const cGH *GH)\n{\n int vindex, retval;\n const ioJpegGH *myGH;\n\n\n retval = 0;\n myGH = CCTK_GHExtension (GH, \"IOJpeg\");\n\n /* loop over all variables */\n for (vindex = CCTK_NumVars () - 1; vindex >= 0; vindex--)\n {\n if (IOJpeg_TimeFor (GH, vindex) &&\n IOJpeg_Write (GH, vindex, CCTK_VarName (vindex)) == 0)\n {\n /* register variable as having output this iteration */\n myGH->out_last[vindex] = GH->cctk_iteration;\n retval++;\n }\n }\n\n return (retval);\n}\n\n\n/*@@\n @routine IOJpeg_OutputVarAs\n @date Thu 18 April 2002\n @author Thomas Radke\n @desc\n Unconditional output of a variable using the IOJpeg I/O method.\n @enddesc\n @calls IOJpeg_Write\n\n @var GH\n @vdesc pointer to CCTK GH\n @vtype const cGH *\n @vio in\n @endvar\n @var fullname\n @vdesc complete name of variable to output\n @vtype const char *\n @vio in\n @endvar\n @var alias\n @vdesc alias name of variable to output\n (used to generate output filename)\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine IOJpeg_Write, or<BR>\n -1 if variable cannot be output by IOJpeg\n @endreturndesc\n@@*/\nint IOJpeg_OutputVarAs (const cGH *GH, const char *fullname, const char *alias)\n{\n int vindex, retval;\n\n\n retval = -1;\n vindex = CCTK_VarIndex (fullname);\n\n if (CheckOutputVar (vindex) == 0)\n {\n retval = IOJpeg_Write (GH, vindex, alias);\n }\n\n return (retval);\n}\n\n\n /*@@\n @routine IOJpeg_TimeFor\n @date Thu 18 April 2002\n @author Thomas Radke\n @desc\n Decides if it is time to output a variable\n using the IOJpeg I/O method.\n @enddesc\n\n @var GH\n @vdesc pointer to CCTK GH\n @vtype const cGH *\n @vio in\n @endvar\n @var vindex\n @vdesc index of variable\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n 1 if output should take place at this iteration, or<BR>\n 0 if not\n @endreturndesc\n@@*/\nint IOJpeg_TimeFor (const cGH *GH, int vindex)\n{\n int result;\n char *fullname;\n ioJpegGH *myGH;\n\n\n myGH = CCTK_GHExtension (GH, \"IOJpeg\");\n IOJpeg_CheckSteerableParameters (myGH);\n\n /* check if this variable should be output */\n result = myGH->out_every[vindex] > 0 &&\n GH->cctk_iteration % myGH->out_every[vindex] == 0;\n if (result)\n {\n /* check if variable wasn't already output this iteration */\n if (myGH->out_last[vindex] == GH->cctk_iteration)\n {\n fullname = CCTK_FullName (vindex);\n CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Already done IOJpeg output for '%s' in current \"\n \"iteration (probably via triggers)\", fullname);\n free (fullname);\n result = 0;\n }\n }\n\n return (result);\n}\n\n\n/*@@\n @routine IOJpeg_TriggerOutput\n @date Thu 18 April 2002\n @author Thomas Radke\n @desc\n Triggers the output of a variable using the IOJpeg I/O method.\n @enddesc\n @calls IOJpeg_Write\n\n @var GH\n @vdesc pointer to CCTK GH\n @vtype const cGH *\n @vio in\n @endvar\n @var vindex\n @vdesc index of variable to output\n @vtype int\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n return code of @seeroutine IOJpeg_Write\n @endreturndesc\n@@*/\nint IOJpeg_TriggerOutput (const cGH *GH, int vindex)\n{\n int retval;\n const ioJpegGH *myGH;\n\n\n /* do the output */\n retval = IOJpeg_Write (GH, vindex, CCTK_VarName (vindex));\n if (retval == 0)\n {\n /* register variable as having output this iteration */\n myGH = CCTK_GHExtension (GH, \"IOJpeg\");\n myGH->out_last[vindex] = GH->cctk_iteration;\n }\n\n return (retval);\n}\n\n\n/*@@\n @routine IOJpeg_CheckSteerableParameters\n @date Mon Oct 10 2000\n @author Thomas Radke\n @desc\n Checks if IOJpeg steerable parameters were changed\n and does appropriate re-evaluation.\n @enddesc\n\n @calls CCTK_TraverseString\n\n @var myGH\n @vdesc pointer to IOJpeg grid hierarchy\n @vtype ioJpegG *\n @vio inout\n @endvar\n@@*/\nvoid IOJpeg_CheckSteerableParameters (ioJpegGH *myGH)\n{\n int i, num_vars;\n char *fullname, *msg;\n DECLARE_CCTK_PARAMETERS\n\n\n /* how often to output */\n i = myGH->out_every_default;\n myGH->out_every_default = out_every >= 0 ? out_every : io_out_every;\n\n /* report if frequency changed */\n if (myGH->out_every_default != i && ! CCTK_Equals (verbose, \"none\"))\n {\n if (myGH->out_every_default > 0)\n {\n CCTK_VInfo (CCTK_THORNSTRING, \"Periodic IOJpeg output every %d \"\n \"iterations\", myGH->out_every_default);\n }\n else\n {\n CCTK_INFO (\"Periodic IOJpeg output turned off\");\n }\n }\n\n /* re-parse the 'IOJpeg::out_vars' parameter if it was changed */\n if (strcmp (out_vars, myGH->out_vars) || myGH->out_every_default != i)\n {\n num_vars = CCTK_NumVars ();\n memset (myGH->out_every, 0, num_vars * sizeof (CCTK_INT));\n if (CCTK_TraverseString (out_vars, SetOutputFlag, myGH,\n CCTK_GROUP_OR_VAR) < 0)\n {\n CCTK_WARN (myGH->stop_on_parse_errors ? 0 : 1,\n \"error while parsing parameter 'IOJpeg::out_vars'\");\n }\n\n if (myGH->out_every_default == i || ! CCTK_Equals (verbose, \"none\"))\n {\n msg = NULL;\n for (i = 0; i < num_vars; i++)\n {\n if (myGH->out_every[i] > 0)\n {\n fullname = CCTK_FullName (i);\n if (! msg)\n {\n Util_asprintf (&msg, \"Periodic IOJpeg output requested for '%s'\",\n fullname);\n }\n else\n {\n char *tmp = msg;\n Util_asprintf (&msg, \"%s, '%s'\", msg, fullname);\n free (tmp);\n }\n free (fullname);\n }\n }\n if (msg)\n {\n CCTK_INFO (msg);\n free (msg);\n }\n }\n\n /* save the last setting of 'IOJpeg::out_vars' parameter */\n free (myGH->out_vars);\n myGH->out_vars = strdup (out_vars);\n }\n}\n\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\n/* check if this variable can be output (static conditions) */\nstatic int CheckOutputVar (int vindex)\n{\n int groupindex;\n cGroup groupinfo;\n char *fullname;\n const char *errormsg;\n\n\n /* get the variable group information */\n groupindex = CCTK_GroupIndexFromVarI (vindex);\n CCTK_GroupData (groupindex, &groupinfo);\n\n errormsg = NULL;\n if (groupinfo.dim < 2 || groupinfo.dim > 3)\n {\n errormsg = \"dim != [2,3]\";\n }\n else if (groupinfo.grouptype != CCTK_GF && groupinfo.grouptype != CCTK_ARRAY)\n {\n errormsg = \"not a grid function or array\";\n }\n else if (! strncmp (CCTK_VarTypeName (groupinfo.vartype), \"CCTK_COMPLEX\", 12))\n {\n errormsg = \"CCTK_COMPLEX variables cannot be dealt with\";\n }\n\n if (errormsg)\n {\n fullname = CCTK_FullName (vindex);\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"No IOJpeg output for '%s': %s\", fullname, errormsg);\n free (fullname);\n }\n\n return (errormsg != NULL);\n}\n\n\n/* callback for CCTK_TraverseString() to set the output flag\n for the given variable */\nstatic void SetOutputFlag (int vindex, const char *optstring, void *arg)\n{\n const ioJpegGH *myGH = (const ioJpegGH *) arg;\n\n\n if (CheckOutputVar (vindex) == 0)\n {\n myGH->out_every[vindex] = myGH->out_every_default;\n\n if (optstring)\n {\n IOUtil_ParseOutputFrequency (CCTK_THORNSTRING, \"IOJpeg::out_vars\",\n myGH->stop_on_parse_errors,\n vindex, optstring,\n &myGH->out_every[vindex], NULL);\n }\n }\n}\n",
"Write.c": "/*@@\n @file Write.c\n @date Thu 18 April 2002\n @author Thomas Radke\n @desc\n Output two-dimensional slices in Jpeg image format.\n @enddesc\n @version $Id$\n @@*/\n\n\n#include <assert.h>\n#include <limits.h>\n#include <math.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"cctk.h\"\n#include \"cctk_Parameters.h\"\n#include \"util_Table.h\"\n#include \"CactusBase/IOUtil/src/ioutil_AdvertisedFiles.h\"\n#include \"ioJpegGH.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusIO_IOJpeg_Write_c)\n\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\nstatic void WriteData (const cGH *GH, int vindex, const char *alias, int dim,\n int dir, CCTK_REAL min, CCTK_REAL max,\n const CCTK_INT hsize[2], const void *hdata);\nstatic void *RefineData (CCTK_INT input_dims[2], const void *input_data);\n\n\n/*@@\n @routine IOJpeg_Write\n @date Thu 18 April 2002\n @author Thomas Radke\n @desc\n Writes the slices of a variable into separate Jpeg files.\n @enddesc\n @calls Hyperslab_GlobalMappingByIndex\n Hyperslab_FreeMapping\n Hyperslab_GetList\n OpenFile\n WriteData\n\n @var GH\n @vdesc pointer to CCTK GH\n @vtype const cGH *\n @vio in\n @endvar\n @var vindex\n @vdesc index of variable to output\n @vtype CCTK_INT\n @vio in\n @endvar\n @var alias\n @vdesc alias name of variable to output\n @vtype const char *\n @vio in\n @endvar\n\n @returntype int\n @returndesc\n 0 for success, or<BR>\n -1 if variable has no storage assigned<BR>\n -2 if output file couldn't be opened<BR>\n -3 if hyperslab for coordinates and/or variable couldn't be\n extracted\n @endreturndesc\n@@*/\nint IOJpeg_Write (const cGH *GH, CCTK_INT vindex, const char *alias)\n{\n const ioJpegGH *myGH;\n int mapping, total_hsize;\n int dir_i, dir_j, maxdir, myproc, groupindex;\n cGroup gdata;\n char *fullname;\n CCTK_INT origin[3], direction[6], hsize[2];\n const CCTK_INT extent[2] = {-1, -1};\n void *hdata;\n CCTK_REAL min, max;\n const CCTK_INT htype = CCTK_VARIABLE_REAL;\n DECLARE_CCTK_PARAMETERS\n \n /* Reduction variables */\n CCTK_INT input_array[1];\n CCTK_INT input_array_type_codes[1];\n void* value_min[1], *value_max[1];\n\n input_array_type_codes[0] = CCTK_VARIABLE_REAL;\n input_array[0] = vindex;\n value_min[0] = &min;\n value_max[0] = &max;\n\n /* get the variable name and group information */\n fullname = CCTK_FullName (vindex);\n groupindex = CCTK_GroupIndexFromVarI (vindex);\n CCTK_GroupData (groupindex, &gdata);\n\n /* check if variable has storage assigned */\n if (! CCTK_QueryGroupStorageI (GH, groupindex))\n {\n CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"No IOJpeg output for '%s' (no storage)\", fullname);\n free (fullname);\n return (-1);\n }\n\n /* get the handle for IOJpeg extensions */\n myproc = CCTK_MyProc (GH);\n myGH = (const ioJpegGH *) CCTK_GHExtension (GH, \"IOJpeg\");\n\n /* set the minimum/maximum for the colormap */\n if (CCTK_Equals (colormap, \"custom\"))\n {\n min = colormap_min;\n max = colormap_max;\n }\n else if (CCTK_Equals (colormap, \"auto\"))\n {\n int i = CCTK_LocalArrayReductionHandle (\"minimum\");\n CCTK_ReduceGridArrays (GH, 0, i, -1, 1, input_array , 1, input_array_type_codes, value_min);\n i = CCTK_LocalArrayReductionHandle (\"maximum\");\n CCTK_ReduceGridArrays (GH, 0, i, -1, 1, input_array , 1, input_array_type_codes, value_max);\n }\n else if (CCTK_Equals (colormap, \"auto-old\"))\n {\n int i = CCTK_ReductionHandle (\"minimum\");\n CCTK_Reduce (GH, 0, i, 1, CCTK_VARIABLE_REAL, &min, 1, vindex);\n i = CCTK_ReductionHandle (\"maximum\");\n CCTK_Reduce (GH, 0, i, 1, CCTK_VARIABLE_REAL, &max, 1, vindex);\n }\n else\n {\n CCTK_WARN (CCTK_WARN_ABORT, \"Setting for parameter IOpjeg::colormap not recognised\");\n }\n\n /* get the number of slices to output */\n /* in general: maxdir = gdata.dim * (gdata.dim - 1) / 2; */\n maxdir = gdata.dim == 2 ? 1 : 3;\n\n if (CCTK_EQUALS(gridpoints, \"hyperslab\"))\n {\n \n /* now do the actual I/O looping over all directions */\n for (int dir = 0; dir < maxdir; dir++)\n {\n /* get the directions to span the hyperslab */\n if (dir == 0)\n {\n dir_i = 0; dir_j = 1; /* xy */\n if(GH->cctk_gsh[0]==1 || GH->cctk_gsh[1]==1)\n \tcontinue;\n }\n else if (dir == 1)\n {\n dir_i = 0; dir_j = 2; /* xz */\n if(GH->cctk_gsh[0]==1 || GH->cctk_gsh[2]==1)\n \tcontinue;\n }\n else\n {\n dir_i = 1; dir_j = 2; /* yz */\n if(GH->cctk_gsh[1]==1 || GH->cctk_gsh[2]==1)\n \tcontinue;\n }\n \n /* set the origin using the slice center from IOUtil */\n memset (origin, 0, sizeof (origin));\n if (gdata.grouptype == CCTK_GF)\n {\n origin[maxdir-dir-1] = myGH->sp2xyz[gdata.dim - 1][dir];\n }\n \n /* set the direction vector */\n memset (direction, 0, sizeof (direction));\n direction[dir_i] = direction[gdata.dim + dir_j] = 1;\n \n mapping = Hyperslab_GlobalMappingByIndex (GH, vindex, 2,\n direction, origin, extent,\n NULL, -1, NULL, hsize);\n if (mapping < 0)\n {\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Failed to define hyperslab mapping for variable '%s'\",\n fullname);\n continue;\n }\n {\n // Sanity check\n // (if this fails, we requested an insane number of grid points)\n int imax = INT_MAX;\n int d;\n for (d=0; d<2; ++d) {\n assert (hsize[d] >= 0 && hsize[d] <= imax);\n if (hsize[d] > 0) imax /= hsize[d];\n }\n assert (CCTK_VarTypeSize (gdata.vartype) <= imax);\n }\n total_hsize = hsize[0] * hsize[1] * CCTK_VarTypeSize (htype);\n assert (total_hsize >= 0);\n if (total_hsize <= 0)\n {\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Selected hyperslab has zero size for variable '%s' \"\n \"direction %d\", fullname, dir);\n Hyperslab_FreeMapping (mapping);\n continue;\n }\n \n /* allocate hyperslab buffer */\n hdata = myproc == 0 ? malloc (total_hsize) : NULL;\n \n /* get the hyperslab */\n int i = Hyperslab_Get (GH, mapping, 0, vindex, 0, htype, hdata);\n if (i)\n {\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Failed to extract hyperslab for variable '%s'\", fullname);\n }\n \n /* release the mapping structure */\n Hyperslab_FreeMapping (mapping);\n \n /* and dump the data to file */\n if (myproc == 0)\n {\n if (i == 0)\n {\n /* refine the 2D slice if requested */\n void *outdata;\n outdata = refinement_factor > 1 ? RefineData (hsize, hdata) : hdata;\n if (! outdata)\n {\n CCTK_WARN (1, \"Failed to refine 2D array\");\n outdata = hdata;\n }\n WriteData (GH, vindex, alias, gdata.dim, dir, min, max, hsize, outdata);\n if (outdata != hdata)\n {\n free (outdata);\n }\n }\n \n /* clean up */\n free (hdata);\n }\n } /* end of looping through xyz directions */\n\n }\n else if (CCTK_EQUALS(gridpoints, \"interpolate\"))\n {\n \n int interpolator;\n int options_table;\n int coord_handle;\n \n CCTK_REAL * restrict coordsx;\n CCTK_REAL * restrict coordsy;\n CCTK_REAL * restrict coordsz;\n CCTK_POINTER_TO_CONST coords[3];\n CCTK_INT * restrict inputs;\n CCTK_INT * restrict output_types;\n CCTK_POINTER * restrict outputs;\n \n const int nvars = 1;\n int npoints;\n \n int n;\n int i, j;\n int ierr;\n \n CCTK_REAL *outdata;\n \n \n \n interpolator = CCTK_InterpHandle (interpolator_name);\n assert (interpolator >= 0);\n \n options_table = Util_TableCreateFromString (interpolator_options);\n assert (options_table >= 0);\n \n coord_handle = CCTK_CoordSystemHandle (interpolator_coordinates);\n assert (coord_handle >= 0);\n \n \n \n {\n ierr = Util_TableSetInt (options_table, 1, \"want_global_mode\");\n assert (! ierr);\n }\n \n \n \n /* 2D Arrays */\n npoints = myproc==0 ? array2d_npoints_i * array2d_npoints_j : 0;\n \n coordsx = malloc (npoints * sizeof * coordsx);\n assert (npoints==0 || coordsx);\n coordsy = malloc (npoints * sizeof * coordsy);\n assert (npoints==0 || coordsy);\n coordsz = malloc (npoints * sizeof * coordsz);\n assert (npoints==0 || coordsz);\n coords[0] = coordsx;\n coords[1] = coordsy;\n coords[2] = coordsz;\n \n if (myproc==0) {\n n = 0;\n for (j=0; j<array2d_npoints_j; ++j) {\n for (i=0; i<array2d_npoints_i; ++i) {\n assert (n <= npoints);\n coordsx[n] = array2d_x0 + i * array2d_dx_i + j * array2d_dx_j;\n coordsy[n] = array2d_y0 + i * array2d_dy_i + j * array2d_dy_j;\n coordsz[n] = array2d_z0 + i * array2d_dz_i + j * array2d_dz_j;\n ++n;\n }\n }\n assert (n == npoints);\n }\n \n inputs = malloc (nvars * sizeof * inputs);\n assert (inputs);\n \n for (n=0; n<nvars; ++n) {\n inputs[n] = vindex;\n if (inputs[n] < 0) {\n inputs[n] = -1;\n }\n }\n \n output_types = malloc (nvars * sizeof * output_types);\n assert (output_types);\n \n for (n=0; n<nvars; ++n) {\n output_types[n] = CCTK_VARIABLE_REAL;\n }\n \n outputs = malloc (nvars * sizeof * outputs);\n assert (outputs);\n \n outdata = malloc (npoints * sizeof * outdata);\n assert (npoints==0 || outdata);\n \n for (n=0; n<nvars; ++n) {\n outputs[n] = outdata;\n }\n \n ierr = CCTK_InterpGridArrays\n (GH, 3, interpolator, options_table, coord_handle,\n npoints, CCTK_VARIABLE_REAL, coords,\n nvars, inputs,\n nvars, output_types, outputs);\n assert (! ierr);\n \n \n \n /* Multiply values by r */\n if (myproc==0) {\n for (n=0; n<npoints; ++n) {\n const CCTK_REAL x = coordsx[n];\n const CCTK_REAL y = coordsy[n];\n const CCTK_REAL z = coordsz[n];\n const CCTK_REAL r = sqrt (pow (x, 2) + pow (y, 2) + pow (z, 2));\n outdata[n] *= r;\n }\n }\n \n \n\n free (coordsx);\n free (coordsy);\n free (coordsz);\n free (inputs);\n free (output_types);\n free (outputs);\n \n \n \n ierr = Util_TableDestroy (options_table);\n assert (! ierr);\n \n \n \n if (myproc==0) {\n const int dir = 0;\n hsize[0] = array2d_npoints_i;\n hsize[1] = array2d_npoints_j;\n \n assert (CCTK_VarTypeI(vindex) == CCTK_VARIABLE_REAL);\n \n WriteData (GH, vindex, alias, gdata.dim, dir,\n min, max, hsize, outdata);\n }\n \n free (outdata);\n \n }\n else\n {\n CCTK_WARN (CCTK_WARN_ABORT, \"unknown setting for parameter IOJpeg::gridpoints\");\n }\n\n free (fullname);\n\n return (0);\n}\n\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\n/*@@\n @routine RefineData\n @date Thu 4 November 2004\n @author Thomas Radke\n @desc\n Refines a given 2D input array by a certain factor\n @enddesc\n\n @returntype void *\n @returndesc\n a pointer to the allocated refined output array (must be freed\n by the caller), or NULL in case of an error\n @endreturndesc\n @@*/\nstatic void *RefineData (CCTK_INT input_dims[2], const void *input_data)\n{\n const CCTK_REAL coord_origin[2] = {0.0, 0.0};\n CCTK_REAL coord_delta[2];\n const CCTK_INT array_type_codes[2] = {CCTK_VARIABLE_REAL, CCTK_VARIABLE_REAL};\n CCTK_REAL *interp_coords[2], *refined_data;\n int i, j, interp_handle, table_handle, N_interp_points;\n CCTK_INT output_dims[2];\n DECLARE_CCTK_PARAMETERS\n\n\n interp_handle = CCTK_InterpHandle (\"uniform cartesian\");\n if (interp_handle < 0)\n {\n CCTK_WARN (1, \"Couldn't get handle for interpolation operator 'uniform \"\n \"cartesian'. Did you forget to activate a thorn providing \"\n \"CCTK_InterpLocalUniform() ?\");\n return (NULL);\n }\n\n table_handle = Util_TableCreateFromString (\"order = 1\");\n coord_delta[0] = coord_delta[1] = refinement_factor;\n\n /* leave one grid point at the boundary as interpolation stencil */\n output_dims[0] = refinement_factor * (input_dims[0] - 1) - 2;\n output_dims[1] = refinement_factor * (input_dims[1] - 1) - 2;\n N_interp_points = output_dims[0] * output_dims[1];\n\n interp_coords[0] = malloc (2 * N_interp_points * sizeof (CCTK_REAL));\n interp_coords[1] = interp_coords[0] + N_interp_points;\n for (j = 0; j < output_dims[1]; j++)\n {\n for (i = 0; i < output_dims[0]; i++)\n {\n *interp_coords[0]++ = i + 1;\n *interp_coords[1]++ = j + 1;\n }\n }\n interp_coords[0] -= N_interp_points;\n interp_coords[1] -= N_interp_points;\n\n refined_data = malloc (N_interp_points * sizeof (CCTK_REAL));\n if (CCTK_InterpLocalUniform (2, interp_handle, table_handle,\n coord_origin, coord_delta, N_interp_points,\n CCTK_VARIABLE_REAL,\n (const void *const *) interp_coords,\n 1, input_dims, array_type_codes,\n &input_data, 1, array_type_codes,\n (void *const *) &refined_data) != 0)\n {\n CCTK_WARN (1, \"Failed to interpolate 2D array\");\n free (refined_data);\n refined_data = NULL;\n }\n else\n {\n input_dims[0] = output_dims[0];\n input_dims[1] = output_dims[1];\n }\n\n free (interp_coords[0]);\n Util_TableDestroy (table_handle);\n\n return (refined_data);\n}\n\n\n/*@@\n @routine WriteData\n @date Thu 18 April 2002\n @author Thomas Radke\n @desc\n Writes the given hyperslab into a Jpeg output file.\n @enddesc\n @@*/\nstatic void WriteData (const cGH *GH, int vindex, const char *alias, int dim,\n int dir, CCTK_REAL min, CCTK_REAL max,\n const CCTK_INT hsize[2], const void *hdata)\n{\n FILE *file;\n unsigned char *dataout;\n const ioJpegGH *myGH;\n ioAdvertisedFileDesc advertised_file;\n char *filename, *tmpfilename, *fullname;\n char slicename[30];\n const char *extensions[] = {\"xy\", \"xz\", \"yz\"};\n DECLARE_CCTK_PARAMETERS\n\n\n myGH = (const ioJpegGH *) CCTK_GHExtension (GH, \"IOJpeg\");\n\n /* allocate the RGB image buffer */\n dataout = (unsigned char *) malloc (3 * hsize[0] * hsize[1]);\n\n AutoColorDataSlice (hsize[0], hsize[1], hdata, dataout, min, max,\n colormap_bias, colormap_factor);\n\n /* open the file */\n if (dim == 2)\n {\n strcpy (slicename, \"2D\");\n }\n else\n {\n /* give the slice origin as range [1 .. n] */\n sprintf (slicename, \"%s_[%d]\", extensions[dir], myGH->sp2xyz[dim-1][dir]);\n }\n\n filename = malloc (strlen (myGH->out_dir) + strlen (alias) +\n sizeof (slicename) + 20);\n\n if (CCTK_Equals (mode, \"remove\"))\n {\n sprintf (filename, \"%s%s_%s.jpeg\", myGH->out_dir, alias, slicename);\n tmpfilename = malloc (strlen (filename) + 5);\n sprintf (tmpfilename, \"%s.tmp\", filename);\n }\n else\n {\n sprintf (filename, \"%s%s_%s.it_%d.jpeg\", myGH->out_dir, alias, slicename,\n GH->cctk_iteration);\n tmpfilename = NULL;\n }\n\n /* Write a JPEG file to be advertised to a temporary file first\n and rename it later.\n This fixes a racing problem with HTTPD when running with pthreads support:\n a file could be downloaded (through the HTTPD thread) while is was still\n being written to (in the main simulation thread).\n Now the JPEG is written to a temporary file first and then (atomically)\n renamed. */\n file = fopen (tmpfilename ? tmpfilename : filename, \"w\");\n if (file)\n {\n /* write the data */\n WriteJPEGToFileRGB (hsize[0], hsize[1], dataout, colormap_quality, file);\n\n /* close the file */\n fclose (file);\n\n /* in \"remove\" mode: rename and advertise the file for downloading */\n if (tmpfilename)\n {\n if (rename (tmpfilename, filename))\n {\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Cannot rename temporary output file '%s' into '%s'\",\n tmpfilename, filename);\n }\n else\n {\n fullname = CCTK_FullName (vindex);\n advertised_file.slice = slicename;\n advertised_file.thorn = CCTK_THORNSTRING;\n advertised_file.varname = fullname;\n advertised_file.description = \"Jpegs of slices\";\n advertised_file.mimetype = \"image/jpeg\";\n\n IOUtil_AdvertiseFile (GH, filename, &advertised_file);\n\n free (fullname);\n }\n }\n }\n else\n {\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Cannot open IOJpeg %s output file '%s'\",\n tmpfilename ? \"temporary\" : \"\",\n tmpfilename ? tmpfilename : filename);\n }\n\n /* clean up */\n free (dataout);\n free (tmpfilename);\n free (filename);\n}\n",
"Startup.c": " /*@@\n @file Startup.c\n @date Thu 18 April 2002\n @author Thomas Radke\n @desc\n Startup routines for IOJpeg.\n @enddesc\n @version $Id$\n @@*/\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n#include \"cctk.h\"\n#include \"cctk_IOMethods.h\"\n#include \"cctk_Parameters.h\"\n#include \"CactusBase/IOUtil/src/ioutil_Utils.h\"\n#include \"ioJpegGH.h\"\n\n/* the rcs ID and its dummy function to use it */\nstatic const char *rcsid = \"$Header$\";\nCCTK_FILEVERSION(CactusIO_IOJpeg_Startup_c)\n\n\n/********************************************************************\n ******************** External Routines ************************\n ********************************************************************/\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\nstatic void *SetupGH (tFleshConfig *config, int conv_level, cGH *GH);\n\n\n /*@@\n @routine IOJpeg_Startup\n @date Thu 18 April 2002\n @author Thomas Radke\n @desc\n The startup registration routine for IOJpeg.\n Registers the GH extensions needed for IOJpeg,\n along with its setup routine, if there are grid variables\n of at least dimensionality of 2.\n @enddesc\n @calls CCTK_RegisterGHExtension\n CCTK_RegisterGHExtensionSetupGH\n@@*/\nint IOJpeg_Startup (void)\n{\n if (CCTK_MaxDim () >= 2)\n {\n CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension (\"IOJpeg\"),\n SetupGH);\n }\n\n return 0;\n}\n\n\n/********************************************************************\n ******************** Internal Routines ************************\n ********************************************************************/\n /*@@\n @routine SetupGH\n @date Thu 18 April 2002\n @author Thomas Radke\n @desc\n Allocates and sets up IOJpeg's GH extension structure\n @enddesc\n\n @calls CCTK_RegisterIOMethod\n CCTK_RegisterIOMethodOutputGH\n CCTK_RegisterIOMethodOutputVarAs\n CCTK_RegisterIOMethodTimeToOutput\n CCTK_RegisterIOMethodTriggerOutput\n\n @var config\n @vdesc the CCTK configuration as provided by the flesh\n @vtype tFleshConfig *\n @vio unused\n @endvar\n @var conv_level\n @vdesc the convergence level\n @vtype int\n @vio unused\n @endvar\n @var GH\n @vdesc pointer to CCTK grid hierarchy\n @vtype cGH *\n @vio in\n @endvar\n\n @returntype void *\n @returndesc\n pointer to the allocated GH extension structure\n @endreturndesc\n@@*/\nstatic void *SetupGH (tFleshConfig *config, int conv_level, cGH *GH)\n{\n int i, numvars;\n ioJpegGH *myGH;\n const char *my_out_dir;\n DECLARE_CCTK_PARAMETERS\n\n\n /* suppress compiler warnings about unused variables */\n (void) (config + 0);\n (void) (conv_level + 0);\n\n /* allocate the GH extension and its components */\n myGH = (ioJpegGH *) malloc (sizeof (ioJpegGH));\n if (! myGH)\n {\n CCTK_WARN (0, \"Unable to allocate memory for GH\");\n }\n\n /* register the IOJpeg routines as I/O method \"IOJpeg\" */\n i = CCTK_RegisterIOMethod (\"IOJpeg\");\n CCTK_RegisterIOMethodOutputGH (i, IOJpeg_OutputGH);\n CCTK_RegisterIOMethodOutputVarAs (i, IOJpeg_OutputVarAs);\n CCTK_RegisterIOMethodTimeToOutput (i, IOJpeg_TimeFor);\n CCTK_RegisterIOMethodTriggerOutput (i, IOJpeg_TriggerOutput);\n\n numvars = CCTK_NumVars ();\n myGH->out_every = malloc (numvars * sizeof (CCTK_INT));\n myGH->out_last = malloc (numvars * sizeof (int));\n\n for (i = 0; i < numvars; i++)\n {\n myGH->out_last[i] = -1;\n }\n\n myGH->out_vars = strdup (\"\");\n myGH->out_every_default = out_every - 1;\n\n /* get the name for IOJpeg's output directory */\n my_out_dir = *out_dir ? out_dir : io_out_dir;\n\n /* omit the directory if it's the current working dir */\n if (strcmp (my_out_dir, \".\") == 0)\n {\n myGH->out_dir = strdup (\"\");\n }\n else\n {\n myGH->out_dir = (char *) malloc (strlen (my_out_dir) + 2);\n sprintf (myGH->out_dir, \"%s/\", my_out_dir);\n }\n\n /* create the output dir */\n i = IOUtil_CreateDirectory (GH, myGH->out_dir, 0, 0);\n if (i < 0)\n {\n CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,\n \"Problem creating IOJpeg output directory '%s'\",\n myGH->out_dir);\n }\n else if (i >= 0 && CCTK_Equals (verbose, \"full\"))\n {\n CCTK_VInfo (CCTK_THORNSTRING, \"IOJpeg: Output to directory '%s'\",\n myGH->out_dir);\n }\n\n myGH->stop_on_parse_errors = strict_io_parameter_check;\n if (! CCTK_Equals (verbose, \"none\"))\n {\n CCTK_INFO (\"I/O Method 'IOJpeg' registered: output of 2D jpeg images of \"\n \"grid functions/arrays\");\n }\n IOJpeg_CheckSteerableParameters (myGH);\n myGH->stop_on_parse_errors = 0;\n\n return (myGH);\n}\n"
},
"test": {},
"doc": {
"documentation.tex": "\\documentclass{article}\n\n% Use the Cactus ThornGuide style file\n% (Automatically used from Cactus distribution, if you have a \n% thorn without the Cactus Flesh download this from the Cactus\n% homepage at www.cactuscode.org)\n\\usepackage{../../../../doc/latex/cactus}\n\n\\begin{document}\n\n\\title{IOJpeg}\n\\author{Gabrielle Allen, Thomas Radke}\n\\date{$ $Date$ $}\n\n\\maketitle\n\n% Do not delete next line\n% START CACTUS THORNGUIDE\n\n\\begin{abstract}\nOutput method using the jpeg format\n\\end{abstract}\n\n\\section{Use}\n\nThorn IOJpeg provides 2D images from grid functions in jpeg format, these\nimages are currently intended to be used for two purposes:\n\n\\begin{itemize}\n\n\\item{Monitoring from Web Server} Jpeg images can be directly visualised\nin the {\\it viewport} provided by thorn {\\tt CactusConnect/HTTPDExtra}. For \nthe images to be advertised to the Web Server the parameter {\\tt iojpeg::mode = ``remove''} must be used.\n\n\\item{Constructing Movies} A series of jpeg movies can easily\n be used to construct a time series movie (e.g. using the Unix utilities\n{\\tt convert} or {\\tt xanim}). In this case the parameter {\\tt iojpeg::mode = ``standard''} must be used.\n\n\\end{itemize}\n\nNote that the parameter {\\tt iojpeg::mode} determines whether a jpeg image is ccreated and kept for individual timesteps, or whether only the image from the current data is kept. Only in the second case is the jpeg file {\\tt advertised} (otherwise there are potentially thousands of files advertised to e.g. the {\\tt HTTPD} thorn). Also note that using the standard mode and creating jpegs every iteration can quite quickly lead to {\\it inode} problems on a machine.\n\nThe steerable parameter {\\tt IOJpeg::refinement\\_factor} determines whether the\nresulting JPEG images (of same size as the underlying grid) should be refined\nby a certain factor. If refinement is enabled ({\\tt IOJpeg::refinement\\_factor} $>$ 1) an interpolation will be done to enlarge the images to the requested size. For this case, a thorn providing local interpolation operators must be activated (eg. thorn {\\tt CactusBase/LocalInterp}).\n\nWe are planning to develop this thorn more to provide more features (eg \na range of 2D images from a 3D dataset, add possibility to save images for a movie and advertise current image).\n\n% Do not delete next line\n% END CACTUS THORNGUIDE\n\n\\end{document}\n"
}
}