---
name: "medcon"
section: "3"
platform: "linux"
package: "libmdc-dev"
version: "0.25.1-gtk3+dfsg-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/medcon/3"
---

# medcon(3)

(X)MedCon's C Library - Medical Image Conversion Utility

## NAME

medcon - (X)MedCon's C Library - Medical Image Conversion Utility

## LIBRARY

(X)MedCon C library ( **libmdc.a** )

## SYNOPSIS

```
#include "medcon.h"
```

\----------------------------------------------------------------------- Important Global Variables -----------------------------------------------------------------------

```
char prefix[MDC_MAX_PREFIX+1];          /* prefix for new filenames */
/* command-line input data */
char *mdc_arg_files[];                  /* pointers to input files  */
int   mdc_arg_convs[];                  /* conversions selected     */
int   mdc_arg_total[];                  /* total files & conversions*/
/* options set at command-line */
char MDC_INSTITUTION[];                 /* name of institution              */
Int8 MDC_COLOR_MAP;                     /* gray color palette selected      */
Int8 MDC_PADDING_MODE;                  /* resized image padding mode       */
Int8 MDC_ANLZ_SPM;                      /* Analyze/SPM scaling factor       */
Int8 MDC_ANLZ_OPTIONS;                  /* Analyze/SPM request params       */
Int8 MDC_DICOM_MOSAIC_ENABLED;          /* DICOM: mosaic support enabled    */
Int8 MDC_DICOM_MOSAIC_FORCED;           /* DICOM: mosaic preset  forced     */
Int8 MDC_DICOM_MOSAIC_DO_INTERL;        /* DICOM: mosaic forced interlaced  */
Int8 MDC_DICOM_MOSAIC_FIX_VOXEL;        /* DICOM: mosaic fix voxel sizes    */
Int8 MDC_DICOM_WRITE_IMPLICIT;          /* DICOM: write little implicit     */
Int8 MDC_DICOM_WRITE_NOMETA;            /* DICOM: write without meta header */
Int8 MDC_DICOM_WRITE_ENCAP_UNCOMP;      /* DICOM: write encap. uncompressed */
Int8 MDC_FORCE_RESCALE;                 /* user specified slope/intercept   */
Int8 MDC_FORCE_CONTRAST;                /* user specified centre/width      */
Int8 MDC_INFO;                          /* default print header info        */
Int8 MDC_INTERACTIVE;                   /* interactive read of raw file     */
Int8 MDC_CONVERT;                       /* image conversion requested       */
Int8 MDC_EXTRACT;                       /* extract images                   */
Int8 MDC_RENAME;                        /* rename base filename             */
Int8 MDC_ECHO_ALIAS;                    /* echo alias name based on ID's    */
Int8 MDC_EDIT_FI;                       /* edit FILEINFO struct             */
Int8 MDC_PIXELS;                        /* print specified pix values       */
Int8 MDC_PIXELS_PRINT_ALL;              /* print    all    pix values       */
Int8 MDC_NEGATIVE;                      /* allow negative pixel values      */
Int8 MDC_QUANTIFY;                      /* quantitation with one factor     */
Int8 MDC_CALIBRATE;                     /* quantitation with two factors    */
Int8 MDC_CONTRAST_REMAP;                /* apply contrast remapping         */
Int8 MDC_DEBUG;                         /* give debug info                  */
Int8 MDC_VERBOSE;                       /* run in verbose mode              */
Int8 MDC_GIF_OPTIONS;                   /* request for extra GIF options    */
Int8 MDC_MAKE_GRAY;                     /* forced remap color to gray scale */
Int8 MDC_DITHER_COLOR;                  /* apply dither on color reduction  */
Int8 MDC_NORM_OVER_FRAMES;              /* normalize over images in a frame */
                                        /* instead of all images            */
Int8 MDC_SKIP_PREVIEW;                  /* skip the first (preview) slice   */
Int8 MDC_IGNORE_PATH;                   /* ignore path in INTF data fname   */
Int8 MDC_SINGLE_FILE;                   /* write INTF as single file        */
Int8 MDC_FORCE_INT;                     /* force integer pixels             */
Int8 MDC_INT16_BITS_USED;               /* bits to use for Int16 type       */
Int8 MDC_TRUE_GAP;                      /* spacing = true gap/overlap       */
Int8 MDC_ALIAS_NAME;                    /* use  alias name based on ID's    */
Int8 MDC_PREFIX_DISABLED;               /* prevent the prefix in names      */
Int8 MDC_PREFIX_ACQ;                    /* use acquisition number as prefix */
Int8 MDC_PREFIX_SER;                    /* use series      number as prefix */
Int8 MDC_PATIENT_ANON;                  /* make patient anonymous           */
Int8 MDC_PATIENT_IDENT;                 /* give patient identification      */
Int8 MDC_FILE_OVERWRITE;                /* allow file overwriting           */
Int8 MDC_FILE_STDIN;                    /* input from stdin  stream         */
Int8 MDC_FILE_STDOUT;                   /* output  to stdout stream         */
Int8 MDC_FILE_SPLIT;                    /* split up file in parts           */
Int8 MDC_FILE_STACK;                    /* stack up files                   */
Int8 MDC_FLIP_HORIZONTAL;               /* flip horizontal   (x)            */
Int8 MDC_FLIP_VERTICAL;                 /* flip vertical     (y)            */
Int8 MDC_SORT_REVERSE;                  /* reverse   sorting                */
Int8 MDC_SORT_CINE_APPLY;               /* cine apply sorting               */
Int8 MDC_SORT_CINE_UNDO;                /* cine undo  sorting               */
Int8 MDC_MAKE_SQUARE;                   /* make square image                */
Int8 MDC_CROP_IMAGES;                   /* crop image dimensions            */
Int8 MDC_RESLICE;                       /* reslice images (tra, sag, cor)   */
Int8 MDC_FRMT_INPUT;                    /* format used for stdin            */
Int8 MDC_ECAT6_SORT;                    /* ECAT sort order                  */
Int8 MDC_FALLBACK_FRMT;                 /* fallback read format             */
```

\----------------------------------------------------------------------- Important Defines -----------------------------------------------------------------------

```
/* representation of supported formats */
#define MDC_FRMT_NONE    0              /* unsupported format       */
#define MDC_FRMT_RAW     1              /* Read  Interactive        */
                                        /* Write RAW Binary         */
#define MDC_FRMT_ASCII   2              /* Write RAW Ascii          */
#define MDC_FRMT_GIF     3              /* GIF89a or GIF87a         */
#define MDC_FRMT_ACR     4              /* Acr/Nema 2.0 (Papyrus)   */
#define MDC_FRMT_INW     5              /* INW (RUG)                */
#define MDC_FRMT_ECAT6   6              /* Siemens/CTI ECAT 6.4     */
#define MDC_FRMT_ECAT7   7              /* Siemens/CTI ECAT 7.2     */
#define MDC_FRMT_INTF    8              /* Interfile v3.3           */
#define MDC_FRMT_ANLZ    9              /* Analyze (SPM)            */
#define MDC_FRMT_DICM   10              /* DICOM 3.0                */
#define MDC_FRMT_PNG    11              /* PNG                      */
#define MDC_FRMT_CONC   12              /* Concorde uPet            */
#define MDC_FRMT_NIFTI  13              /* NIfTI-1                  */
#define MDC_MAX_FMTS    14              /* total + 1                */
/* supported color maps */
#define MDC_MAP_PRESENT  0              /* 256 RGB   colormap       */
#define MDC_MAP_GRAY     1              /* grayscale colormap       */
#define MDC_MAP_INVERTED 2              /* inverted  colormap       */
#define MDC_MAP_RAINBOW  3              /* rainbow   colormap       */
#define MDC_MAP_COMBINED 4              /* combined  colormap       */
#define MDC_MAP_HOTMETAL 5              /* hotmetal  colormap       */
#define MDC_MAP_LOADED   6              /* extern LUT loaded        */
```

\----------------------------------------------------------------------- Important Structures -----------------------------------------------------------------------

```
/* static related data */
typedef struct Static_Data_t {
  char  label[MDC_MAXSTR];       /* label name of image    */ /* Ant/Post */
  float total_counts;            /* total counts in image  */
  float image_duration;          /* duration of image (ms) */
  Int16 start_time_hour;         /* start time hour        */
  Int16 start_time_minute;       /* start time minute      */
  Int16 start_time_second;       /* start time second      */
} STATIC_DATA;
/* gated SPECT related data */
typedef struct Gated_Data_t {
  Int8  gspect_nesting;          /* gated spect nesting    */
  float nr_projections;          /* number of projections  */
  float extent_rotation;         /* extent of rotation     */
  float study_duration;          /* study duration (ms)    */
  float image_duration;          /* image duration (ms)    */
  float time_per_proj;           /* time per proj  (ms)    */
  float window_low;              /* lower  limit   (ms)    */
  float window_high;             /* higher limit   (ms)    */
  float cycles_observed;         /* cardiac cycles observed*/
  float cycles_acquired;         /* cardiac cycles acquired*/
} GATED_DATA;
/* acquisition data */
typedef struct Acquisition_Data_t {
  Int16 rotation_direction;      /* direction of rotation  */
  Int16 detector_motion;         /* type detector motion   */
  float rotation_offset;         /* centre rotation offset */
  float radial_position;         /* radial position        */
  float angle_start;             /* start angle (interfile)*/ /* 180 - dicom */
  float angle_step;              /* angular step           */
  float scan_arc;                /* angular range          */
} ACQ_DATA;
/* dynamic data */
typedef struct Dynamic_Data_t {
  Uint32 nr_of_slices;           /* images in time frame   */
  float time_frame_start;        /* start time frame (ms)  */
  float time_frame_delay;        /* delay this frame (ms)  */
  float time_frame_duration;     /* duration   frame (ms)  */
  float delay_slices;            /* delay each slice (ms)  */
} DYNAMIC_DATA;
/* bed data */
typedef struct Bed_Data_t {
  float hoffset;                 /* horizon. position (mm) */
  float voffset;                 /* vertical position (mm) */
} BED_DATA;
/* images related data */
typedef struct Image_Data_t {
  /*             **   general data   **                    */
  Uint32 width,height;           /* image dimension        */
  Int16 bits,type;               /* bits/pixel & datatype  */
  Uint16 flags;                  /* extra flag             */
  double min, max;               /* min/max pixelvalue     */
  double qmin, qmax;             /* quantified min/max     */
  double fmin, fmax;             /* min/max in whole frame */
  double qfmin, qfmax;           /* in whole frame (quant) */
  float rescale_slope;           /* rescale slope          */ /* auto filled */
  float rescale_intercept;       /* rescale intercept      */ /* auto filled */
  Uint32 frame_number;           /* part of frame (1-based)*/ /* auto filled */
  float slice_start;             /* start    of slice (ms) */ /* auto filled */
  Uint8 *buf;                    /* pointer to raw image   */
  off_t load_location;           /* load start in file     */
  /*             **  internal items  **                    */
  Int8   rescaled;               /* rescaled image?        */
  double rescaled_min;           /* new rescaled max       */
  double rescaled_max;           /* new rescaled min       */
  double rescaled_fctr;          /* new rescaled fctr      */
  double rescaled_slope;         /* new rescaled slope     */
  double rescaled_intercept;     /* new rescaled intercept */
  /*             **   ecat64 items   **                    */
  Int16 quant_units;             /* quantification units   */
  Int16 calibr_units;            /* calibration units      */
  float quant_scale;             /* quantification scale   */
  float calibr_fctr;             /* calibration factor     */
  float intercept;               /* scale intercept        */
  float pixel_xsize;             /* pixel size X      (mm) */
  float pixel_ysize;             /* pixel size Y      (mm) */
  float slice_width;             /* slice width       (mm) */
  float recon_scale;             /* recon magnification    */
  /*            **  Acr/Nema items   **                    */
  float image_pos_dev[3];        /* image posit  dev  (mm) */
  float image_orient_dev[6];     /* image orient dev  (mm) */
  float image_pos_pat[3];        /* image posit  pat  (mm) */
  float image_orient_pat[6];     /* image orient pat  (mm) */
  float slice_spacing;           /* space btw centres (mm) */
  float ct_zoom_fctr;            /* CT image zoom factor   */
  /*            **  Miscellaneous    **                    */
  STATIC_DATA *sdata;            /* extra static entries   */ /* just one */
  unsigned char *plugb;          /* like to attach here?   */
} IMG_DATA;
/* the file information struct */
typedef struct File_Info_t {
  FILE *ifp;                     /* pointer to input file  */
  FILE *ifp_raw;                 /* pointer to raw input   */
  FILE *ofp;                     /* pointer to output file */
  FILE *ofp_raw;                 /* pointer to raw output  */
  char ipath[MDC_MAX_PATH+1];    /* path to input  file    */
  char opath[MDC_MAX_PATH+1];    /* path to output file    */
  char *idir;                    /* dir to input  file     */
  char *odir;                    /* dir to output file     */
  char *ifname;                  /* name of input file     */
  char *ofname;                  /* name of output file    */
  int  iformat;                  /* format of  input file  */
  int  oformat;                  /* format of output file  */
  int  modality;                 /* modality               */
  Int8 rawconv;                  /* FRMT_RAW | FRMT_ASCII  */
  Int8 endian;                   /* endian of file         */
  Int8 compression;              /* file compression       */
  Int8 truncated;                /* truncated file?        */
  Int8 diff_type;                /* images with diff type? */
  Int8 diff_size;                /* images with diff size? */
  Int8 diff_scale;               /* images with diff scale?*/
  Uint32 number;                 /* total number of images */  /* private */
  Uint32 mwidth,mheight;         /* global max dimensions  */
  Int16 bits, type;              /* global bits & datatype */
  Int16 dim[MDC_MAX_DIMS];       /* [0] = # of dimensions  */
                                 /* [1] = X-dim (pixels)   */
                                 /* [2] = Y-dim (pixels)   */
                                 /* [3] = Z-dim (planes)   */
                                 /* [4] =       (frames)   */
                                 /* [5] =       (gates)    */
                                 /* [6] =       (beds)     */
                                 /* ...                    */
                                 /* values must be 1-based */
  float pixdim[MDC_MAX_DIMS];    /* [0] = # of dimensions  */
                                 /* [1] = X-dim (mm)       */
                                 /* [2] = Y-dim (mm)       */
                                 /* [3] = Z-dim (mm)       */
                                 /* [4] = time  (ms)       */
                                 /* ...                    */
  double glmin, glmax;           /* global min/max value   */
  double qglmin, qglmax;         /* quantified min/max     */
  Int8  contrast_remapped;       /* contrast remap applied */
  float window_centre;           /* contrast window centre */
  float window_width;            /* contrast window width  */
  Int8 slice_projection;         /* projection of images   */
  Int8 pat_slice_orient;         /* combined flag          */
  char pat_pos[MDC_MAXSTR];      /* patient position       */
  char pat_orient[MDC_MAXSTR];   /* patient orientation    */
  char  patient_sex[MDC_MAXSTR]; /* sex of patient         */
  char  patient_name[MDC_MAXSTR];/* name of patient        */
  char  patient_id[MDC_MAXSTR];  /* id   of patient        */
  char  patient_dob[MDC_MAXSTR]; /* birth of patient       */ /* YYYYMMDD */
  float patient_weight;          /* weight of patient (kg) */
  float patient_height;          /* height of patient (m)  */
  char operator_name[MDC_MAXSTR];/* name of scan operator  */
  char study_descr[MDC_MAXSTR];  /* study description      */
  char study_id[MDC_MAXSTR];     /* study id               */
  Int16 study_date_day;          /* day of study   (1-31)  */
  Int16 study_date_month;        /* month of study (1-12)  */
  Int16 study_date_year;         /* year of study          */
  Int16 study_time_hour;         /* hour of study          */
  Int16 study_time_minute;       /* minute of study        */
  Int16 study_time_second;       /* second of study        */
  Int16 dose_time_hour;          /* hour   of dose start   */
  Int16 dose_time_minute;        /* minute of dose start   */
  Int16 dose_time_second;        /* second of dose start   */
  Int32 nr_series;               /* series number          */
  Int32 nr_acquisition;          /* acquisition number     */
  Int32 nr_instance;             /* instance number        */
  Int16 acquisition_type;        /* acquisition type       */
  Int16 planar;                  /* planar or tomo  ?      */
  Int16 decay_corrected;         /* decay corrected ?      */
  Int16 flood_corrected;         /* flood corrected ?      */
  Int16 reconstructed;           /* reconstructed ?        */
  char recon_method[MDC_MAXSTR]; /* reconstruction method  */
  char institution[MDC_MAXSTR];  /* name of institution    */
  char manufacturer[MDC_MAXSTR]; /* name of manufacturer   */
  char series_descr[MDC_MAXSTR]; /* series description     */
  char radiopharma[MDC_MAXSTR];  /* radiopharmaceutical    */
  char filter_type[MDC_MAXSTR];  /* filter type            */
  char organ_code[MDC_MAXSTR];   /* organ                  */
  char isotope_code[MDC_MAXSTR]; /* isotope                */
  float isotope_halflife;        /* isotope halflife (sec) */
  float injected_dose;           /* amount injected  (MBq) */
  float gantry_tilt;             /* gantry tilt            */
  Uint8 map;                     /* indexed 256 colormap   */
  Uint8 palette[768];            /* global palette         */
  char *comment;                 /* whatever comment       */
  Uint32 comm_length;            /* length of comment      */
  Uint32 gatednr;                /* number of gated entries*/ /* now 0 or 1 */
  GATED_DATA *gdata;             /* array of GATED_DATA    */
  Uint32 acqnr;                  /* number acq. entries    */
  ACQ_DATA *acqdata;             /* array ACQ_DATA entries */
  Uint32 dynnr;                  /* number of time frames  */
  DYNAMIC_DATA *dyndata;         /* array of DYNAMIC_DATA  */
  Uint32 bednr;                  /* number bed positions   */
  BED_DATA * beddata;            /* array of BED_DATA      */
  IMG_DATA *image;               /* array IMG_DATA images  */
  MOD_INFO *mod;                 /* modality related info  */
  unsigned char *pluga;          /* want to attach stuff?  */
} FILEINFO;
```

\------------------------------------------------------------------------ Important Functions ------------------------------------------------------------------------

```
void MdcInit              (void);
void MdcFinish            (void);
int  MdcHandleArgs        ( FILEINFO *fi, int argc, char *argv[], int MAXFILES );
void MdcPrintUsage        ( char *pgrname );
int  MdcOpenFile          ( FILEINFO *fi, char *path );
int  MdcReadFile          ( FILEINFO *fi, int filenr, char *(*ReadFunc)(FILEINFO *fi) );
int  MdcWriteFile         ( FILEINFO *fi, int format, int prefixnr, char *(*WriteFunc)(FILEINFO *fi) );
void MdcInitFI            ( FILEINFO *fi, char *path );
void MdcFreeIDs           ( FILEINFO *fi );
void MdcCleanUpFI         ( FILEINFO *fi );
void MdcResetIDs          ( FILEINFO *fi );
void MdcPrintFI           ( FILEINFO *fi );
void MdcCloseFile         ( FILE *fp );
void MdcSplitPath         ( char path[], char **dir, char **fname );
int  MdcGetFrmt           ( FILEINFO *fi );
void MdcGetColorMap       ( int map, Uint8 palette[] );
char *MdcImagesPixelFiddle( FILEINFO *fi);
void MdcPrntMesg          ( char *fmt, ... );
void MdcPrntWarn          ( char *fmt, ... );
void MdcPrntErr           ( int code, char *fmt, ... );
char *MdcReadACR          ( FILEINFO *fi );
char *MdcReadANLZ         ( FILEINFO *fi );
char *MdcReadCONC         ( FILEINFO *fi );
char *MdcReadDICM         ( FILEINFO *fi );
char *MdcReadECAT6        ( FILEINFO *fi );
char *MdcReadECAT7        ( FILEINFO *fi );
char *MdcReadGIF          ( FILEINFO *fi );
char *MdcReadINTF         ( FILEINFO *fi );
char *MdcReadINW          ( FILEINFO *fi );
char *MdcReadNIFTI        ( FILEINFO *fi );
char *MdcReadPNG          ( FILEINFO *fi );
char *MdcReadRAW          ( FILEINFO *fi );
char *MdcWriteACR         ( FILEINFO *fi );
char *MdcWriteANLZ        ( FILEINFO *fi );
char *MdcWriteCONC        ( FILEINFO *fi );
char *MdcWriteDICM        ( FILEINFO *fi );
char *MdcWriteECAT6       ( FILEINFO *fi );
char *MdcWriteECAT7       ( FILEINFO *fi );
char *MdcWriteGIF         ( FILEINFO *fi );
char *MdcWriteINTF        ( FILEINFO *fi );
char *MdcWriteINW         ( FILEINFO *fi );
char *MdcWriteNIFTI       ( FILEINFO *fi );
char *MdcWritePNG         ( FILEINFO *fi );
char *MdcWriteRAW         ( FILEINFO *fi );
```

## DESCRIPTION

The  *(X)MedCon* library is intended for easy use of read/write routines for the supported medical image formats. Our original testing format was Ecat 6.4. The FILEINFO structure holds all the interesting parameters and pointers to each image. A fast introduction ...

- **MdcInit(), MdcFinish()**

  The very first and very last function to call when using this library. Currently changes occur to the signal handler for floating point exceptions and the program's locale.

- **MdcHandleArgs()**

  Parser for the command-line arguments. Last function argument determines the maximum of input files allowed. The absolute maximum is MDC\_MAX\_FILES defined in the library.

- **MdcPrintUsage()**

  Prints possible (X)MedCon command line options and terminates the program.

- **MdcOpenFile()**

  Initializes FILEINFO struct and opens the file with or without decompression.

- **MdcReadFile()**

  Reads the (decompressed) file with format autodetection or by trying a fallback format, initializes a (grayscale) colormap and does the obligated pixel handling. The last argument enables the use of an external read function.

- **MdcWriteFile()**

  Writes a file in the supplied format. Last argument is a number used in the prefix of the output filename. Give a negative value when a personal prefix was prepared. The last argument enables the use of an external write function.

- **MdcCloseFile()**

  Closes the file and sets the pointer to NULL.

- **MdcInitFI()**

  Initializes the FILEINFO structure.

- **MdcFreeIDs()**

  Cleans the IMG\_DATA structures by freeing all allocated memory.

- **MdcCleanUpFI()**

  Cleans the FILEINFO structure. The routine makes use of FreeIDs().

- **MdcResetIDs()**

  Resets the IMG\_DATA structures. This is necessary after each conversion.

- **MdcPrintFI()**

  Prints the content of the FILEINFO structure. Useful for debug purposes.

- **MdcSplitPath()**

  Splits the path in a string into directory and filename.

- **MdcGetFrmt()**

  Checks the format of the file. For the return value, see the representation of the supported formats under the section \`Important Defines'. With the MDC\_INTERACTIVE variable ON, the function returns MDC\_FRMT\_RAW; see also MdcReadRAW().

- **MdcGetColorMap()**

  Fills a 256 byte RGB palette with the requested grayscale colormap.

- **MdcImagesPixelFiddle()**

  Performs all the pixel by pixel processes such as swapping bytes, make positive values, quantification, rescaling, filling the FILEINFO structure with global & image variables and check some important parameters. This function is required after a file was read!

- **MdcPrntMesg()**

  Prints a message. Argument is a variable parameter list.

- **MdcPrntWarn()**

  Prints a warning. Argument is a variable parameter list.

- **MdcPrntErr()**

  Prints an error and quits the program. The first argument is the error code.

- **MdcReadACR() - MdcWriteACR()**

  Reads and writes Acr/Nema files.

- **MdcReadANLZ() - MdcWriteANLZ()**

  Reads and writes Analyze (SPM) files.

- **MdcReadCONC() - MdcWriteCONC()**

  Reads and writes Concorde microPET.

- **MdcReadDICM() - MdcWriteDICM()**

  Reads and writes DICOM files.

- **MdcReadECAT6() - MdcWriteECAT6()**

  Reads and writes ECAT 6.4 files.

- **MdcReadECAT7() - MdcWriteECAT7()**

  Reads and writes ECAT 7.2 files.

- **MdcReadGIF() - MdcWriteGIF()**

  Reads GIF87a & GIF89a, writes annimated GIF89a files.

- **MdcReadINTF() - MdcWriteINTF()**

  Reads and writes Interfile 3.3 files.

- **MdcReadINW() - MdcWriteINW()**

  Reads and writes RUG INW files.

- **MdcReadNIFTI() - MdcWriteNIFTI()**

  Reads and writes NIfTI-1 files.

- **MdcReadPNG() - MdcWritePNG()**

  Reads and writes PNG files.

- **MdcReadRAW() - MdcWriteRAW()**

  Reads files of an unknown format interactively and writes raw image arrays without header in binary or ascii.

## EXAMPLE

A sample C-source code to show the usage of the functions. Please, look into the project source code for more details.

```
-----------------------------------------------------------------------
/* filename: testit.c */
#include <stdio.h>
#include "medcon.h"
#define PROG_VERSION "TestIt v2.4"
void NewPrefix(int n)
{
  sprintf(prefix,"my%02d-",n); /* max of MDC_MAX_PREFIX chars (5) */
}
int main(int argc, char *argv[])
{
  FILEINFO fi;
  int   *total = mdc_arg_total;  /* total arguments of files & conversions  */
  int   *convs = mdc_arg_convs;  /* counter for each conversion format      */
  char **files = mdc_arg_files;  /* array of pointers to input filenames    */
  int    f, c;                   /* some counters                           */
  int    t=0;                    /* counter for the output name prefix      */
  int    convert, err=MDC_OK;    /* some variables                          */
/* check arguments */
  if (argc < 2) {
    printf("%s - %s0,PROG_VERSION,MdcGetLibLongVersion());
    printf("0urpose: a simplified example program0);
    MdcPrintUsage(argv[0]);
  }
/* init library */
  MdcInit();
/* handle MedCon arguments, last argument determines max inputfiles */
  if (MdcHandleArgs(&fi,argc,argv,MDC_MAX_FILES) != MDC_OK)
    MdcPrintUsage(argv[0]);
/* check output/conversion formats */
  if (total[MDC_CONVS] == 0) {
    printf("0s: ERROR : No output format specified0n",argv[0]);
    return(MDC_BAD_CODE);
  }
/* do the stuff for each input file */
  for (f=0; f<total[MDC_FILES]; f++) {
     if ((err = MdcOpenFile(&fi, files[f]))  != MDC_OK) return(err);
     if ((err = MdcReadFile(&fi, f+1, NULL)) != MDC_OK) return(err);
/* do the conversions */
     if (total[MDC_CONVS] > 0) {
/* go through conversion formats */
       for (c=1; c<MDC_MAX_FRMTS; c++) {
          convert = convs[c];
/* write output format when selected */
          while (convert -- > 0) {
               if ((err = MdcWriteFile(&fi, c, t++, NULL)) != MDC_OK) {
                 MdcCleanUpFI(&fi);
                 return(err);
               }
          }
       }
     }
/* clean up FILEINFO struct */
     MdcCleanUpFI(&fi);
  }
/* finish library */
  MdcFinish();
  return(err);
}
-----------------------------------------------------------------------
```

Example \`Makefile' for compiling \`testit.c':

```
-----------------------------------------------------------------------
# filename: Makefile
CC = gcc
CCOPTS = -Wall -g
CFLAGS = $(CCOPTS)
INCS = `xmedcon-config --cflags`
LIBS = `xmedcon-config --libs`
testit: testit.c
        $(CC) $(CFLAGS) $(INCS) -o testit testit.c $(LIBS)
# don't forget a <tab> before $(CC). You can lose this with copy/paste
-----------------------------------------------------------------------
```

## FILES

| | |
| --- | --- |
| /usr/local/xmedcon/include/ | Directory with header files.. |
| /usr/local/xmedcon/lib/ | Directory with libraries. |
| /usr/local/xmedcon/bin/ | Directory with executables. |
| /usr/local/xmedcon/man/ | Directory with man-pages. |
| /usr/local/xmedcon/etc/ | Directory with rcfiles. |

## SEE ALSO

[medcon(1)](/medcon/1.md), [xmedcon(1)](/xmedcon/1.md), [xmedcon-config(1)](/xmedcon-config/1.md)

[m-acr(4)](/m-acr/4.md), [m-anlz(4)](/m-anlz/4.md), [m-gif(4)](/m-gif/4.md), [m-intf(4)](/m-intf/4.md), [m-ecat(4)](/m-ecat/4.md), [m-inw(4)](/m-inw/4.md)

## AUTHOR

*(X)MedCon* project was originally written by Erik Nolf (eNlf) for the former PET-Centre at Ghent University (Belgium).

| | | | |
| --- | --- | --- | --- |
| **e-mail:** | enlf-at-users.sourceforge.net | **www:** | http://xmedcon.sourceforge.net |
