Beispiel #1
0
IDL_VPTR pgsql_query(int argc, IDL_VPTR *argv, char *argk)
{

    IDL_VPTR queryVptr;
    char *query;
    char *connect_info;

    IDL_VPTR resultVptr;

    int async = 1;

    int status;


    (void) IDL_KWProcessByOffset(argc, argv, argk, kw_pars, 
            (IDL_VPTR *) 0, 1, &kw);


    if (kw.nrows_there)
        IDL_StoreScalarZero(kw.nrows, IDL_TYP_ULONG64);

    /* Check number of input parameters */
    if (pgsql_query_nparams(argc) < 1)
    {
        IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_INFO, 
                "-Syntax: result=pgsql_query(query, nrows=, connect_info=, file=, /append, /nointerrupt, /verbose, status=)\nIf there are results for the query, a structure is returned.  Otherwise the result is -1");
        return(IDL_GettmpInt(-1));
    }

    /* Get the input query */
    queryVptr = argv[0];
    query = IDL_VarGetString(queryVptr);



    /* The user may have input connection information */
    if (kw.connect_info_there)
        connect_info=IDL_STRING_STR(&kw.connect_info);
    else
        connect_info="";

    /* Should we query asynchronously?  This would allow cancel through ^C */
    if (kw.nointerrupt_there)
        if (kw.nointerrupt) 
            async = 0;

    if (async) 
        status = pgsql_query_send_async(query, connect_info, &resultVptr);
    else 
        status = pgsql_query_send(query, connect_info, &resultVptr);

    setStatus(status);

    IDL_KW_FREE;
    if (status == MYPG_SUCCESS)
        return(resultVptr);
    else
        return(IDL_GettmpInt(-1));
}
Beispiel #2
0
void pvcam_set_gain(int argc, IDL_VPTR argv[], char *argk)
{
    /* Parameter Variables */
    int16 hcam;                         /* A pointer to the camera's handle. */
    int16 gain;
    char error = 0;

    /* Point parameter variables to the actual IDL values. */
    hcam = (int16)IDL_LongScalar(argv[0]);
    gain = (int16)IDL_LongScalar(argv[1]);
    error = !ccd_set_gain(hcam, gain);

    /* Handling the error keyword */
    KW_RESULT kw;
    argc = IDL_KWProcessByOffset(argc,argv,argk,kw_pars,(IDL_VPTR *)0,1,&kw);
    if (kw.iError) {
        IDL_StoreScalar(kw.iError, IDL_TYP_BYTE, (IDL_ALLTYPES*) &error);
    }
    IDL_KW_FREE;
}
Beispiel #3
0
static void IDL_CDECL IDL_mg_print(int argc, IDL_VPTR *argv, char *argk) {
  int nargs;
  char *format, *cformat;
  IDL_VPTR origFormat, vcformat;

  typedef struct {
    IDL_KW_RESULT_FIRST_FIELD;
    IDL_VPTR format;
    int format_present;
  } KW_RESULT;

  static IDL_KW_PAR kw_pars[] = {
    { "FORMAT", IDL_TYP_STRING, 1, IDL_KW_VIN,
      IDL_KW_OFFSETOF(format_present), IDL_KW_OFFSETOF(format) },
    { NULL }
  };

  KW_RESULT kw;

  nargs = IDL_KWProcessByOffset(argc, argv, argk, kw_pars, NULL, 1, &kw);

  if (kw.format_present) {
    origFormat = argv[argc - 1];
    format = IDL_VarGetString(origFormat);
    cformat = (char *) calloc(strlen(format) + 5 + 1, sizeof(char));
    sprintf(cformat, "(%%\"%s\")", format);
    vcformat = IDL_StrToSTRING(cformat);
    argv[argc - 1] = vcformat;
  }

  IDL_Print(argc, argv, argk);

  if (kw.format_present) {
    argv[argc - 1] = origFormat;
    IDL_Deltmp(vcformat);
    free(cformat);
  }

  IDL_KW_FREE;
}
Beispiel #4
0
IDL_VPTR rdObjmask(int argc, IDL_VPTR *argv, char *argk) {

    /* the desired atlas image. */
    ATLAS_IMAGE *ai;

    /* The fits file */
    FITS *fits;

    char *atlasFileName;  // The input file name

    IDL_VPTR idlistVptr; // optional idlist input keyword
    IDL_MEMINT* idlist;
    IDL_MEMINT nid=0;
    int idiscopy=0;

    IDL_MEMINT nrows=0;  // actual number of rows in file
    IDL_MEMINT i=0, j=0;
  
    IDL_VPTR result;  // The result and temporary copies
    char* resptr;
    char* rowptr;
    char* elptr;
    IDL_LONG elval;
    int elsize;

    // Structure definition
    void* sdef;

    // offsets structure
    offsetstruct os;



    // First make sure IDL_LONG is 4-byte int
    elsize=sizeof(IDL_LONG);
    if (elsize != 4)
    {
        IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_LONGJMP, "sizeof(IDL_LONG) must be 4");
    }


    /* Get the keywords */
    (void) IDL_KWProcessByOffset(argc, argv, argk, kw_pars, 
            (IDL_VPTR *) 0, 1, &kw);

    /* Check arguments */
    if (nParams(argc) < 1)
    {
        IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_INFO,
                "Syntax: struct = rdObjmask(atlasFile, idlist=, status=)");
        setStatus(FAILURE);
        return(IDL_GettmpInt(-1));   
    }




    /* get file name and open fits file */
    atlasFileName = getFileNameVal(argv[0]);

    if((fits = open_fits_table(atlasFileName, 1)) == NULL) {
        /* Memory is cleaned up in open_fits_table() */
        setStatus(FAILURE);
        return(IDL_GettmpInt(-1));   
    }
    nrows = fits->naxis2;




    // See if idlist was sent, else generate a list of all
    if (kw.idlist_there)
    {
        /* make sure it is a MEMINT. Copy if needed */
        idlistVptr = getAsMEMINT(argv[1], &idiscopy);
        IDL_VarGetData(idlistVptr, &nid, (char **) &idlist, IDL_TRUE);
    } 
    else
    {
        idiscopy=1;
        nid=nrows;
        idlist = (IDL_MEMINT *) calloc(nrows, sizeof(IDL_MEMINT));
        for (i=1;i<=nrows;i++)
            idlist[i-1] = i;
    }



    /* structure definition and create output */ 
    sdef = IDL_MakeStruct(0, stags);
    resptr = IDL_MakeTempStructVector(sdef, nid, &result, IDL_TRUE); 
    os = GetOffsets(sdef);




    /* Copy in the info */
    for (i=0;i<nid;i++)
    {
        // Point to the appropriate row in output data
        rowptr = (char *) result->value.s.arr->data + i*( result->value.arr->elt_len );

        // Copy id.  Do it here since if the object has no atlas image
        // it wouldn't be copied
        elval = (IDL_LONG) idlist[i];
        elptr = rowptr + os.id;
        memcpy(elptr, &elval, elsize);


        // Read the atlas image
        ai = read_atlas_image(fits, (int) idlist[i]);


        // In what follows, copy -1 if the ai is invalid
        if (ai != NULL)
        {
            // Copy run
            elval = (IDL_LONG) ai->run;
            elptr = rowptr + os.run;
            memcpy(elptr, &elval, elsize);
            // Copy rerun
            elval = (IDL_LONG) ai->rerun;
            elptr = rowptr + os.rerun;
            memcpy(elptr, &elval, elsize);
            // Copy camcol 
            elval = (IDL_LONG) ai->camCol;
            elptr = rowptr + os.camcol;
            memcpy(elptr, &elval, elsize);
            // Copy field
            elval = (IDL_LONG) ai->field;
            elptr = rowptr + os.field;
            memcpy(elptr, &elval, elsize);
            // Copy id
            //elval = (IDL_LONG) ai->id;
            //elptr = rowptr + os.id;
            //memcpy(elptr, &elval, elsize);
            // Copy parent 
            elval = (IDL_LONG) ai->parent;
            elptr = rowptr + os.parent;
            memcpy(elptr, &elval, elsize);


            // copy row0 
            elptr = rowptr + os.row0;
            for (j=0;j<5;j++)
            {
                if (ai->id > 0)
                    elval = (IDL_LONG) (ai->master_mask->rmin + ai->drow[j]);
                else
                    elval=-1;
                memcpy(elptr, &elval, elsize);
                elptr+=elsize;
            }
            // copy col0 
            elptr = rowptr + os.col0;
            for (j=0;j<5;j++)
            {
                if (ai->id > 0)
                    elval = (IDL_LONG) (ai->master_mask->cmin + ai->dcol[j]);
                else
                    elval=-1;
                memcpy(elptr, &elval, elsize);
                elptr+=elsize;
            }
            // copy rowmax
            elptr = rowptr + os.rowmax;
            for (j=0;j<5;j++)
            {
                if (ai->id > 0)
                    elval = (IDL_LONG) (ai->master_mask->rmax + ai->drow[j]);
                else
                    elval=-1;
                memcpy(elptr, &elval, elsize);
                elptr+=elsize;
            }
            // copy colmax 
            elptr = rowptr + os.colmax;
            for (j=0;j<5;j++)
            {
                if (ai->id > 0)
                    elval = (IDL_LONG) (ai->master_mask->cmax + ai->dcol[j]);
                else
                    elval=-1;
                memcpy(elptr, &elval, elsize);
                elptr+=elsize;
            }


            // copy drow
            elptr = rowptr + os.drow;
            for (j=0;j<5;j++)
            {
                if (ai->id > 0)
                    elval = (IDL_LONG) (ai->drow[j]);
                else
                    elval = -1;
                memcpy(elptr, &elval, elsize);
                elptr+=elsize;
            }
            // copy dcol 
            elptr = rowptr + os.dcol;
            for (j=0;j<5;j++)
            {
                if (ai->id > 0)
                    elval = (IDL_LONG) (ai->dcol[j]);
                else
                    elval = -1;
                memcpy(elptr, &elval, elsize);
                elptr+=elsize;
            }

            phAtlasImageDel(ai,1);
        }
    }

    /* clean up */
    phFitsDel(fits);  

    if (kw.idlist_there & idiscopy)
        IDL_Deltmp(idlistVptr);
    else
        free(idlist);

    /* Clean up the keyword info */
    IDL_KW_FREE;

    setStatus(SUCCESS);
    //return(IDL_GettmpInt(-1));   
    return(result);

}
IDL_VPTR p3d_idlGetMaxVolumeBlob(int argc, IDL_VPTR argv[], char* argk) {

    typedef struct {
        IDL_KW_RESULT_FIRST_FIELD; // Must be first entry in structure
        IDL_LONG conn;
        int cn_there;
    } KW_RESULT;

    // Alphabetical order is crucial:
    static IDL_KW_PAR kw_pars[] = {
        IDL_KW_FAST_SCAN,
        { "CONN", IDL_TYP_LONG, 1, 0, (int*) IDL_KW_OFFSETOF(cn_there), (char*) IDL_KW_OFFSETOF(conn)},
        { NULL}
    };

    KW_RESULT kw;

    IDL_VPTR idl_out_rev, idl_in_rev;
    unsigned char *in_rev8, *out_rev8;
    int keywords_ct = 0;

    int conn2D = CONN4;
    int conn3D = CONN6;

    int err_code;

    // Process keywords:
    IDL_KWProcessByOffset(argc, argv, argk, kw_pars, NULL, 1, &kw);


    // Get input data in IDL format:
    idl_in_rev = argv[0];

    IDL_ENSURE_SIMPLE(idl_in_rev);
    IDL_ENSURE_ARRAY(idl_in_rev);


    // Get the CONN input argument:
    if (kw.cn_there) {
        if (idl_in_rev->value.arr->n_dim == 2) {
            // Check values:
            if ((kw.conn != 4) && (kw.conn != 8))
                _p3d_idlPrintNamedError("CONN must be a value of the set {4,8}.");

            // Get values:
            if (kw.conn == 4)
                conn2D = CONN4;
            else if (kw.conn == 8)
                conn2D = CONN8;
        } else if (idl_in_rev->value.arr->n_dim == 3) {
            // Check values:
            if ((kw.conn != 6) && (kw.conn != 18) && (kw.conn != 26))
                _p3d_idlPrintNamedError("CONN must be a value of the set {6,18,26}.");

            // Get values:
            if (kw.conn == 6)
                conn3D = CONN6;
            else if (kw.conn == 18)
                conn3D = CONN18;
            else if (kw.conn == 26)
                conn3D = CONN26;
        }
        // else: error on input arguments with further handling.

        keywords_ct++;
    }


    // Call Pore3D depending on input arguments:
	if (idl_in_rev->value.arr->n_dim == 3) {
        // Extract first input (volume to filter) in C format:
        if (idl_in_rev->type == IDL_TYP_BYTE) {
            in_rev8 = (unsigned char *) idl_in_rev->value.arr->data;

            // Allocate memory for output:
            if (!(idl_in_rev->flags & IDL_V_TEMP))
                out_rev8 = (unsigned char *) IDL_MakeTempArray(
                    IDL_TYP_BYTE,
                    idl_in_rev->value.arr->n_dim,
                    idl_in_rev->value.arr->dim,
                    IDL_ARR_INI_NOP,
                    &idl_out_rev
                    );


            // Call Pore3D:
            err_code = p3dGetMaxVolumeBlob3D(
                    in_rev8,
                    out_rev8,
                    (unsigned int) idl_in_rev->value.arr->dim[0],
                    (unsigned int) idl_in_rev->value.arr->dim[1],
                    (unsigned int) idl_in_rev->value.arr->dim[2],
                    conn3D,
                    _p3d_idlPrintInfo
                    );

            // On exception print error:
            if (err_code == P3D_ERROR)
                _p3d_idlPrintNamedError("Error on code execution.");
        }
        else {
            _p3d_idlPrintNamedError("Input argument IMAGE must be of type BYTE.");
        }
    } else {
        _p3d_idlPrintNamedError("Input argument IMAGE must be a 2D or 3D matrix.");
    }


    // Free resources:
    IDL_KW_FREE;

    // Return output in IDL Format
    return (idl_out_rev);
}
IDL_VPTR p3d_idlGaussianFilter(int argc, IDL_VPTR argv[], char* argk) {

	typedef struct {
		IDL_KW_RESULT_FIRST_FIELD; // Must be first entry in structure
		double sigma;
		int si_there;
		IDL_LONG nsize;
		int ns_there;
	} KW_RESULT;

	// Alphabetical order is crucial:
	static IDL_KW_PAR kw_pars[] = {
		IDL_KW_FAST_SCAN,
		{ "SIGMA", IDL_TYP_DOUBLE, 1, 0, (int*) IDL_KW_OFFSETOF(si_there), (char*) IDL_KW_OFFSETOF(sigma)},
		{ "WIDTH", IDL_TYP_LONG, 1, 0, (int*) IDL_KW_OFFSETOF(ns_there), (char*) IDL_KW_OFFSETOF(nsize)},
		{ NULL}
	};

	KW_RESULT kw;

	IDL_VPTR idl_out_rev, idl_in_rev;
	unsigned char *in_rev8, *out_rev8;
	unsigned short *in_rev16, *out_rev16;
	int keywords_ct = 0;

	int    width = 3;   // default
	double sigma = 1.0; // default

	int err_code;

	// Process keywords:
	IDL_KWProcessByOffset(argc, argv, argk, kw_pars, NULL, 1, &kw);


	// Get input data in IDL format:
	idl_in_rev = argv[0];

	IDL_ENSURE_SIMPLE(idl_in_rev);
	IDL_ENSURE_ARRAY(idl_in_rev);


	// Get the WIDTH input argument:
	if (kw.ns_there) {
		// Check values:
		if ((kw.nsize < 3) || (kw.nsize > 51))
			_p3d_idlPrintNamedError("WIDTH must be an odd value within the range [3,51].");

		if ((kw.nsize % 2) == 0)
			_p3d_idlPrintNamedError("WIDTH must be an odd value within the range [3,51].");

		// Get values:
		width = (int) kw.nsize;

		keywords_ct++;
	}

	// Get the SIGMA input argument:
	if (kw.si_there) {
		// Check values:
		if (kw.sigma < 0)
			_p3d_idlPrintNamedError("SIGMA must be greater than zero.");

		// Get values:
		sigma = (double) kw.sigma;

		keywords_ct++;
	}


	// Call Pore3D depending on input arguments:
	if (idl_in_rev->value.arr->n_dim == 3) {
		// Extract first input (volume to filter) in C format:
		if (idl_in_rev->type == IDL_TYP_BYTE) {
			in_rev8 = (unsigned char *) idl_in_rev->value.arr->data;

			// Allocate memory for output:
			if (!(idl_in_rev->flags & IDL_V_TEMP))
				out_rev8 = (unsigned char *) IDL_MakeTempArray(
				IDL_TYP_BYTE,
				idl_in_rev->value.arr->n_dim,
				idl_in_rev->value.arr->dim,
				IDL_ARR_INI_NOP,
				&idl_out_rev
				);



			// Call Pore3D:
			err_code = p3dGaussianFilter3D_8(
				in_rev8,
				out_rev8,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				(int) idl_in_rev->value.arr->dim[2],
				width,
				sigma,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");

		} else if (idl_in_rev->type == IDL_TYP_UINT) {
			in_rev16 = (unsigned short *) idl_in_rev->value.arr->data;

			// Allocate memory for output:
			if (!(idl_in_rev->flags & IDL_V_TEMP))
				out_rev16 = (unsigned short *) IDL_MakeTempArray(
				IDL_TYP_UINT,
				idl_in_rev->value.arr->n_dim,
				idl_in_rev->value.arr->dim,
				IDL_ARR_INI_NOP,
				&idl_out_rev
				);


			// Call Pore3D:
			err_code = p3dGaussianFilter3D_16(
				in_rev16,
				out_rev16,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				(int) idl_in_rev->value.arr->dim[2],
				width,
				sigma,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");

		} else {
			_p3d_idlPrintNamedError("Input argument IMAGE must be of type BYTE or UINT.");
		}
	} else {
		_p3d_idlPrintNamedError("Input argument IMAGE must be a 2D or 3D matrix.");
	}


	// Free resources:
	IDL_KW_FREE;

	// Return output in IDL Format
	return (idl_out_rev);
}
Beispiel #7
0
void rdAtlas(int argc, IDL_VPTR *argv, char *argk) {

  /* the desired atlas image. */
  ATLAS_IMAGE *ai;		

  /* The fits file */
  FITS *fits;

  /* The input file name and object id */
  char *atlasFileName;
  int id;

  /* Get the keywords */
  (void) IDL_KWProcessByOffset(argc, argv, argk, kw_pars, 
			       (IDL_VPTR *) 0, 1, &kw);

  /* Check arguments */
  if (nParams(argc) != 2)
    {
      IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_INFO,
		  "Syntax: rdAtlas, atlasFile, id, imu=, img=, imr=, imi=, imz=, row0=, col0=, drow=, dcol=, nrow=, ncol=, status=");
      setStatus(FAILURE);
      return;
    }
  

  /* Get the argument values */
  atlasFileName = getFileNameVal(argv[0]);
  id            = getIdVal(argv[1]);

  /* Open the fits file */
  if((fits = open_fits_table(atlasFileName, 1)) == NULL) {
    /* Memory is cleaned up in open_fits_table() */
    setStatus(FAILURE);
    return;
  }

  /* call code to read ai, the atlas image */
  ai = readAtlasRow(fits, id);

  /* clean up */
  phFitsDel(fits);  

  if (ai == NULL) {
    setStatus(FAILURE);
    return;
  }

  
  /* Copy the images and statistics into our output keywords */
  copyAtlasImages(ai);
  copyStatsFromAtlas(ai);

  /* Clean up the atlas image memory */
  phAtlasImageDel(ai,1);

  /* Clean up the keyword info */
  IDL_KW_FREE;

  setStatus(SUCCESS);
  return;

}
void p3d_idlWriteRaw(int argc, IDL_VPTR argv[], char* argk) {

	typedef struct {
		IDL_KW_RESULT_FIRST_FIELD; // Must be first entry in structure
		IDL_LONG endian;
		IDL_LONG sign;
	} KW_RESULT;

	// Alphabetical order is crucial:
	static IDL_KW_PAR kw_pars[] = {
		IDL_KW_FAST_SCAN,
		{ "BIG_ENDIAN", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, (char*) IDL_KW_OFFSETOF(endian)},
		{ "UNSIGNED", IDL_TYP_LONG, 1, IDL_KW_ZERO, 0, (char*) IDL_KW_OFFSETOF(sign)},
		{ NULL}
	};

	KW_RESULT kw;
	IDL_VPTR idl_in_rev;

	char* filename;
	int err_code;

	int little_endian;
	int is_signed;

	unsigned char* in_rev8;
	unsigned short* in_rev16;
	unsigned int* in_rev32;
	float* in_rev32f;


	// Process keywords:
	IDL_KWProcessByOffset(argc, argv, argk, kw_pars, (IDL_VPTR *) 0, 1, &kw);

	little_endian = (kw.endian == 0) ? P3D_TRUE : P3D_FALSE;
	is_signed = (kw.sign == 0) ? P3D_TRUE : P3D_FALSE;

	// Get input data in IDL format:
	idl_in_rev = argv[0];

	IDL_ENSURE_SIMPLE(idl_in_rev);
	IDL_ENSURE_ARRAY(idl_in_rev);


	if (argv[1]->type == IDL_TYP_STRING)
		filename = IDL_VarGetString(argv[1]);
	else
		_p3d_idlPrintNamedError("Input argument FILENAME must be a string.");


	// Check if user wants to write a 8-bit or 16-bit format image:
	if (idl_in_rev->type == IDL_TYP_BYTE) {
		// Extract input in C format
		in_rev8 = (unsigned char *) idl_in_rev->value.arr->data;


		// Check if user wants to write a 2D image or a 3D volume:
		if (idl_in_rev->value.arr->n_dim == 2) {
			// Call Pore3D:
			err_code = p3dWriteRaw8(
				in_rev8,
				filename,
				(int) (idl_in_rev->value.arr->dim[0]),
				(int) (idl_in_rev->value.arr->dim[1]),
				1,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		} else if (idl_in_rev->value.arr->n_dim == 3) {


			// Call Pore3D:
			err_code = p3dWriteRaw8(
				in_rev8,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				(int) idl_in_rev->value.arr->dim[2],
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		} else {
			_p3d_idlPrintNamedError("Input argument IMAGE must be a 2D or 3D matrix.");
		}
	} else if (idl_in_rev->type == IDL_TYP_UINT) {
		// Extract input in C format
		in_rev16 = (unsigned short *) idl_in_rev->value.arr->data;

		// Check if user wants to write a 2D image or a 3D volume:
		if (idl_in_rev->value.arr->n_dim == 2) {


			// Call Pore3D:
			err_code = p3dWriteRaw16(
				in_rev16,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				1,
				little_endian,
				is_signed,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		} else if (idl_in_rev->value.arr->n_dim == 3) {


			// Call Pore3D:
			err_code = p3dWriteRaw16(
				in_rev16,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				(int) idl_in_rev->value.arr->dim[2],
				little_endian,
				is_signed,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");

		} else {
			_p3d_idlPrintNamedError("Input argument IMAGE must be a 2D or 3D matrix."); 
		}
	} else if (idl_in_rev->type == IDL_TYP_ULONG) {
		// Extract input in C format
		in_rev32 = (unsigned int *) idl_in_rev->value.arr->data;

		// Check if user wants to write a 2D image or a 3D volume:
		if (idl_in_rev->value.arr->n_dim == 2) {


			// Call Pore3D:
			err_code = p3dWriteRaw32(
				in_rev32,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				1,
				little_endian,
				is_signed,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		} else if (idl_in_rev->value.arr->n_dim == 3) {


			// Call Pore3D:
			err_code = p3dWriteRaw32(
				in_rev32,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				(int) idl_in_rev->value.arr->dim[2],
				little_endian,
				is_signed,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		}
		else {
			_p3d_idlPrintNamedError("Input argument IMAGE must be a 2D or 3D matrix.");
		}	
	} else if (idl_in_rev->type == IDL_TYP_FLOAT) {
		// Extract input in C format
		in_rev32f = (float *) idl_in_rev->value.arr->data;

		// Check if user wants to write a 2D image or a 3D volume:
		if (idl_in_rev->value.arr->n_dim == 2) {


			// Call Pore3D:
			err_code = p3dWriteRaw32f(
				in_rev32f,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				1,
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		} else if (idl_in_rev->value.arr->n_dim == 3) {


			// Call Pore3D:
			err_code = p3dWriteRaw32f(
				in_rev32f,
				filename,
				(int) idl_in_rev->value.arr->dim[0],
				(int) idl_in_rev->value.arr->dim[1],
				(int) idl_in_rev->value.arr->dim[2],
				_p3d_idlPrintInfo,
				NULL
				);

			// On exception print error:
			if ((err_code == P3D_IO_ERROR) || (err_code == P3D_ERROR))
				_p3d_idlPrintNamedError("Error on code execution.");
		}
		else {
			_p3d_idlPrintNamedError("Input argument IMAGE must be a 2D or 3D matrix.");
		}

	} else {
		_p3d_idlPrintNamedError("Input argument IMAGE must be a BYTE, UINT, ULONG or FLOAT matrix.");
	}


	// Free keywords resources:
	IDL_KW_FREE;
}