00001
00028 #include <string.h>
00029 #include <stdio.h>
00030 #include <fitsio.h>
00031 #include <malloc.h>
00032
00033 #include "mex.h"
00034 #include "matrix.h"
00035 #include "mfitsio.h"
00036
00047 void
00048 mexFunction (int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[])
00049 {
00050 int buflen, status;
00051 char *filename;
00052 mfitsio_header *header;
00053 mfitsio_info *info;
00054 mxArray *headerm = 0;
00055 mxArray *img = 0;
00056
00057
00058 if (nrhs < 2)
00059 mexErrMsgTxt ("At least two inputs required.");
00060 else if (nlhs > 0)
00061 mexErrMsgTxt ("Too many output arguments.");
00062 else if (!mxIsChar (prhs[0]))
00063 mexErrMsgTxt ("Input must be a string (filename).");
00064
00065 if (mxGetM (prhs[0]) != 1)
00066 mexErrMsgTxt ("Input must be a row vector string (filename).");
00067
00068 buflen = (mxGetM (prhs[0]) * mxGetN (prhs[0])) + 1;
00069
00070 filename = mxCalloc (buflen, sizeof (char));
00071 status = mxGetString (prhs[0], filename, buflen);
00072 img = (mxArray *) prhs[1];
00073
00078 if (nrhs == 3)
00079 {
00080 headerm = (mxArray *) prhs[2];
00081 if (mxGetClassID (headerm) != mxSTRUCT_CLASS)
00082 {
00083 mexErrMsgTxt ("The header must be a 1x1 struct array.");
00084 }
00085 }
00086 else
00087 {
00088 int dims[] = { 1, 1 };
00089 int ndims = 2;
00090 int nfields = 1;
00091 const char **fields;
00092 fields = (const char **) malloc (sizeof (char *) * nfields);
00093 fields[0] = "_nil_";
00094 headerm = mxCreateStructArray (ndims, dims, nfields, fields);
00095 }
00096 mfitsio_write_image (filename, headerm, img);
00097
00098 return;
00099 }
00100