#include <stdinc.h> #include <filestruct.h> #include <image.h>
x.w.c. = SCALE * i + OFFSETwhere i runs from 0 to N-1, the dimension of the matrix in any of its coordinates.
Image files are used in 2D and 3D images, i.e. a matrix of values of any kind (intensity, velocity etc.). The output format of image(3NEMO) files is the general binary structured fileformat as described in filestruct(3NEMO) .
The data is stored on disk in Fortran (column-major) or C (row-major) fashion, as in Data(row,column,plane) depending on a compile switch or #define in the image.h module, which must be included in every program using images. The default compilation is using the FORDEF, i.e. x coordinate running fastest in memory (compatibility with existing contour and FITS routines).
There is some experimental code in image.c to compile with -DUSE_IARRAY (Iliffe vectors).
NAXISi nx,ny,nz CRVALi xmin,ymin,zmin CDELTi dx,dy,dz CRPIXi xref,yref,xref CTYPEi namex,namey,namez CUNITi unitx,unity,unitz BUNIT unit BMAJ beamx BMIN beamy
typedef struct { real *frame; /* pointer to datablock */ real **matrix; /* 2D special case: pointers to pointers */ real ***cube; /* 3D special case: ptr to ptr to ptr’s */ int axis; /* axis type (0=old, no ref pixel; 1=with Xref */ int nx; /* number of pixels along x-axis NAXIS1 */ int ny; /* number of pixels along y-axis NAXIS2 */ int nz; /* number of pixels along z-axis NAXIS3 */ real xmin; /* x-value belonging to reference x-pixel CRVAL1 */ real ymin; /* y-value belonging to reference y-pixel CRVAL2 */ real zmin; /* z-value belonging to reference z-pixel CRVAL3 */ real dx; /* step in x-pixel CDELT1 */ real dy; /* step in y_pixel CDELT2 */ real dz; /* step in z_pixel CDELT3 */ real xref; /* reference pixel in X (0 the first) CRPIX1 */ real yref; /* reference pixel in Y CRPIX2 */ real zref; /* reference pixel in Z CRPIX3 */ real map_min; /* minimum map value */ real map_max; /* maximum map value */ int beamtype; /* type of beam used for beam smoothing */ real beamx; /* beamwidth along x (if used) */ real beamy; /* beamwidth along y (if used) */ real beamz; /* beamwidth along z (if used) */ string namex; /* pointer to x-axis name string CTYPE1 */ string namey; /* pointer to y-axis name string CTYPE2 */ string namez; /* pointer to z-axis name string CTYPE3 */ string unitx; /* pointer to x-axis unit string CUNIT1 */ string unity; /* pointer to y-axis unit string CUNIT2 */ string unitz; /* pointer to z-axis unit string CUNIT3 */ string unit; /* BUNIT */ real time; string storage; /* pointer to storage fashion string */ } image, *imageptr;
#define Frame(iptr) ((iptr)->frame) #define Nx(iptr) ((iptr)->nx) #define Ny(iptr) ((iptr)->ny) #define Nz(iptr) ((iptr)->nz) #define Axis(iptr) ((iptr)->axis) #define Xmin(iptr) ((iptr)->xmin) #define Ymin(iptr) ((iptr)->ymin) #define Zmin(iptr) ((iptr)->zmin) #define Dx(iptr) ((iptr)->dx) #define Dy(iptr) ((iptr)->dy) #define Dz(iptr) ((iptr)->dz) #define Xref(iptr) ((iptr)->xref) #define Yref(iptr) ((iptr)->yref) #define Zref(iptr) ((iptr)->zref) #define MapMin(iptr) ((iptr)->map_min) #define MapMax(iptr) ((iptr)->map_max) #define BeamType(iptr) ((iptr)->beamtype) #define Beamx(iptr) ((iptr)->beamx) #define Beamy(iptr) ((iptr)->beamy) #define Beamz(iptr) ((iptr)->beamz) #define Namex(iptr) ((iptr)->namex) #define Namey(iptr) ((iptr)->namey) #define Namez(iptr) ((iptr)->namez) #define Unit(iptr) ((iptr)->unit) #define Storage(iptr) ((iptr)->storage) /* row major */ #if defined(CDEF) #define MapValue(iptr,ix,iy) (*( (iptr)->frame + iy + ix*Ny(iptr) )) #define CubeValue(iptr,ix,iy,iz) (*( (iptr)->frame + iz + Nz(iptr)*(iy + Ny(iptr)*ix))) #endif /* column major */ #if defined(FORDEF) #define MapValue(iptr,ix,iy) (*( (iptr)->frame + ix + Nx(iptr)*iy) ) #define CubeValue(iptr,ix,iy,iz) (*( (iptr)->frame + ix + Nx(iptr)*(iy+Ny(iptr)*iz))) #endif
image *iptr = open_image(....); real **a = map2_image(iptr); for (i=0; i<nx; i++) for (j=0; j<nx; j++) a[i][j] = 0.0;
The following example creates a simple cube by which you can test the row-major and column-major implementations.
In CDef mode:
% ccdmath "" cube0 "%x+10*%y+100*%z" 4,3,2 % tsf cube0 double MapValues[4][3][2] 0.00000 100.000 10.0000 110.000 20.0000 120.000 ... 123.000In ForDef mode:
% tsf cube0 double MapValues[4][3][2] 0.00000 1.00000 2.00000 3.00000 10.0000 11.0000 ... 123.000
https://en.wikipedia.org/wiki/Row-_and_column-major_order https://en.wikipedia.org/wiki/Iliffe_vector
~/src/pjt/image image.c image.h image.3 image.5
29-Jun-87 V1.0: Original created PJT 30-Jun-87 V2.0: use struct as interface PJT 22-May-88 comment to use dynamem(3NEMO) PJT 23-dec-88 V2.3: velocity added to header PJT 18-jan-89 V3.0: 3D added PJT 1-feb-89 V4.0: compile switch for FORDEF and CDEF matrix storage PJT 21-feb-00 A[i][j] usage PJT 19-may-03 improved documentation PJT 8-may-04 V5.0: added reference pixel for axis type 1 PJT 7-may-13 added benchmark example 27-jan-2021 noted axis=1 now becoming standard PJT