示例#1
0
int sci_create_list(char * fname)
{
    int m_list_out, n_list_out;
    int m_var1,     n_var1,     l_var1,  l_list_var1;
    int m_var2,     n_var2,     l_var2,  l_list_var2;
    int m_mlist,    n_mlist,    l_mlist;

    // The labels of our mlist
    static const char * ListLabels [] = {"mylist", "var1", "var2"};

    // First, we create the variables using a classical way
    // The size of the Scilab variables
    m_var1  = 1;
    n_var1  = strlen("a string") + 1; // a null terminated string
    m_var2  = 2;
    n_var2  = 2; // A 2x2 double matrix
    m_mlist = 3;
    n_mlist = 1; // A mlist with 3 elements

    // Creation of the Scilab variables
    // A('var1')
    CreateVar(1, "c", &m_var1,  &n_var1,  &l_var1);
    // A('var2')
    CreateVar(2, "d", &m_var2,  &n_var2,  &l_var2);
    // A
    CreateVar(3, "m", &m_mlist, &n_mlist, &l_mlist);

    // We store values in the create variables
    // The matrix will be stored in A('var2')
    *stk(l_var2 + 0) = 1;
    *stk(l_var2 + 1) = 2;
    *stk(l_var2 + 2) = 3;
    *stk(l_var2 + 3) = 4;

    // The string will be stored in A('var1')
    strncpy(cstk(l_var1), "a string\0", n_var1);

    m_list_out = 3;
    n_list_out = 1;

    // now, affect the variable  to the mlist
    // The labels (it corresponds to A = mlist(['mylist','var1','var2'], ...
    CreateListVarFromPtr(3, 1, "S", &m_list_out, &n_list_out, ListLabels);
    // The value stored in A('var1') (it corresponds to A = ...,'a string', ...
    CreateListVarFrom(3, 2, "c", &m_var1, &n_var1, &l_list_var1, &l_var1);
    // The value stored in A('var2') (it corresponds to A = ...,[1 2,3 4]);
    CreateListVarFrom(3, 3, "d", &m_var2, &n_var2, &l_list_var2, &l_var2);

    // We return only the mlist which has been created at position 3
    LhsVar(1) = 3;

    return 0;
}
示例#2
0
static int cre_hmat(int pos, HyperMat *H)
{
    /*  dans cette version, seuls les champs dimsize, size et it sont definis
     *  et on alloue alors la memoire des champs dims, R (et I si it=1) dans
     *  la pile scilab (juste � la place occupee par la variable).
     */
    static char *Str[] = { "hm", "dims", "entries"};
    int m1 = 1, n1 = 3;
    int mL = 3, nL = 1, lL, one = 1, lr, lc, lar, lac;
    CreateVar(pos, MATRIX_ORIENTED_TYPED_LIST_DATATYPE, &mL, &nL, &lL);
    CreateListVarFromPtr(pos, 1, MATRIX_OF_STRING_DATATYPE, &m1, &n1, Str);
    lr = 4;
    lar = -1;
    CreateListVarFrom(pos, 2, MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE, &one, &H->dimsize, &lr, &lar);
    H->dims = istk(lr);

    lar = -1;
    lac = -1;

    switch (H->type)
    {
        case (sci_matrix):
            CreateListCVarFrom(pos, 3, MATRIX_OF_DOUBLE_DATATYPE, &H->it, &H->size, &one , &lr, &lc, &lar, &lac);
            H->R = stk(lr);
            if ( H->it == 1)
            {
                H->I = stk(lc);
            }
            return 1;

        case (sci_boolean):
            CreateListVarFrom(pos, 3, MATRIX_OF_BOOLEAN_DATATYPE, &H->size, &one, &lr, &lar);
            H->P = (void *) istk(lr);
            return 1;

        case (sci_ints):
            lr = H->it;
            CreateListVarFrom(pos, 3, MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE, &H->size, &one, &lr, &lar);
            H->P = (void *) istk(lr);
            return 1;
    }

    /* Ajout Allan CORNET Correction Warning */
    /* warning C4715: 'cre_hmat' : not all control paths return a value */
    return 1;


}
示例#3
0
/*--------------------------------------------------------------------------*/
int sci_buildouttb(char *fname,unsigned long fname_len)
{
	static int l1 = 0, m1 = 0,   n1 = 0;
	static int l2 = 0, m2 = 0,   n2 = 0;
	static int l3 = 0, n3 = 1;
	SciIntMat M1,M2,M3;

	int n_lnksz = 0, n_lnktyp = 0;
	int *lnksz = NULL,*lnktyp = NULL;

	double *ptr_d = NULL;
	double *ptr_dc = NULL;
	int *ptr_i = NULL;
	short *ptr_s = NULL;
	char *ptr_c = NULL;
	int *ptr_ui = NULL;
	short *ptr_us = NULL;
	char *ptr_uc = NULL;

	int nm = 0,i = 0,j = 0,ierr = 0;

	static int minlhs=1, maxlhs=1;
	static int minrhs=2, maxrhs=2;

	/*check number of lhs/rhs*/
	CheckLhs(minlhs, maxlhs);
	CheckRhs(minrhs, maxrhs);

	/*check type of Rhs 1*/
	if (VarType(1) == 1)
	{
		GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1);
	}
	else if (VarType(1) == sci_ints)
	{
		GetRhsVar(1, MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE, &m1, &n1, &M1);
	}
	else
	{
		Scierror(888, _("%s : lnksz argument must be double or integer.\n"),fname);
		return 0;
	}

	/*check type of Rhs 2*/
	if (VarType(2) == 1)
	{
		GetRhsVar(2, MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, &l2);
	}
	else if (VarType(2) == sci_ints)
	{
		GetRhsVar(2, MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE, &m2, &n2, &M2);
	}
	else
	{
		Scierror(888,_("%s : lnktyp argument must be double or integer.\n"),fname);
		if (lnksz!=NULL) FREE(lnksz);
		return 0;
	}

	/*check size of Rhs 1*/
	if (m1 == 2) n_lnksz = n1;
	else if (n1==2) n_lnksz = m1;
	/*void double input give void list output*/
	else if ((n1==0)||(m1==0))
	{
		if ((n2==0)||(m2==0))
		{
			/*manually code a void list on rhs(1)*/
			ptr_i = (int*)GetData(1);
			ptr_i[0] = sci_list;
			ptr_i[1] = 0;
			ptr_i[2] = 1;
			LhsVar(1) = 1;
			PutLhsVar();
			return 0;
		}
		else
		{
			Scierror(888, _("%s : inconsistent dimension between lnksz and lnktyp.\n"), fname);
			return 0;
		}
	}
	else
	{
		Scierror(888, _("%s : bad dimension for lnksz argument.\n"), fname);
		return 0;
	}

	/*check size of Rhs 2*/
	if (m2 == 1) n_lnktyp = n2;
	else if (n2 == 1) n_lnktyp = m2;
	else if ((n2 == 0)||(m2 == 0))
	{
		if ( (n1 != 0) && (m1 != 0) )
		{
			Scierror(888, _("%s : inconsistent dimension between lnksz and lnktyp.\n"),fname);
			return 0;
		}
	}
	else
	{
		Scierror(888, _("%s : bad dimension for lnktyp argument.\n"),fname);
		return 0;
	}

	/*cross size checking*/
	if (n_lnksz!=n_lnktyp)
	{
		Scierror(888, _("%s : lnksz and lnktyp argument must have the same length.\n"),fname);
		return 0;
	}

	/*allocate lnksz*/
	if ((lnksz=MALLOC(2*n_lnksz*sizeof(int)))==NULL)
	{
		Scierror(999, _("%s : No more free memory.\n"),fname);
		return 0;
	}

	/* Allocate lnktyp*/
	if ((lnktyp=MALLOC(n_lnktyp*sizeof(int)))==NULL)
	{
		Scierror(999, _("%s : No more free memory.\n"),fname);
		if (lnksz!=NULL) FREE(lnksz);
		return 0;
	}

	/*store rhs 1 in lnksz */
	if ((m1 == n1)&&(m2 == m1)) m1 = -1; /* this is done for matrix 2,2 */
	if (VarType(1) == 8)
	{
		switch (M1.it)
		{
		case I_CHAR   : if (m1==2)
						{
							for(j=0;j<n_lnksz;j++)
							{
								lnksz[j]=(int) IC_CHAR(M1.D)[j*2];
								lnksz[n_lnksz+j]=(int) IC_CHAR(M1.D)[2*j+1];
							}
						}
						else
						{
							for(j=0;j<2*n_lnksz;j++)
								lnksz[j]=(int) IC_CHAR(M1.D)[j];
						}
						break;

		case I_INT16  : if (m1==2)
						{
							for(j=0;j<n_lnksz;j++)
							{
								lnksz[j]=(int) IC_INT16(M1.D)[j*2];
								lnksz[n_lnksz+j]=(int) IC_INT16(M1.D)[2*j+1];
							}
						}
						else
						{
							for(j=0;j<2*n_lnksz;j++)
								lnksz[j]=(int) IC_INT16(M1.D)[j];
						}
						break;

		case I_INT32  : if (m1==2)
						{
							for(j=0;j<n_lnksz;j++)
							{
								lnksz[j]=(int) IC_INT32(M1.D)[j*2];
								lnksz[n_lnksz+j]=(int) IC_INT32(M1.D)[2*j+1];
							}
						}
						else
						{
							for(j=0;j<2*n_lnksz;j++)
								lnksz[j]=(int) IC_INT32(M1.D)[j];
						}
						break;

		case I_UCHAR  : if (m1==2)
						{
							for(j=0;j<n_lnksz;j++)
							{
								lnksz[j]=(int) IC_UCHAR(M1.D)[j*2];
								lnksz[n_lnksz+j]=(int) IC_UCHAR(M1.D)[2*j+1];
							}
						}
						else
						{
							for(j=0;j<2*n_lnksz;j++)
								lnksz[j]=(int) IC_UCHAR(M1.D)[j];
						}
						break;

		case I_UINT16 : if (m1==2)
						{
							for(j=0;j<n_lnksz;j++)
							{
								lnksz[j]=(int) IC_UINT16(M1.D)[j*2];
								lnksz[n_lnksz+j]=(int) IC_UINT16(M1.D)[2*j+1];
							}
						}
						else
						{
							for(j=0;j<2*n_lnksz;j++)
								lnksz[j]=(int) IC_UINT16(M1.D)[j];
						}
						break;

		case I_UINT32 : if (m1==2)
						{
							for(j=0;j<n_lnksz;j++)
							{
								lnksz[j]=(int) IC_UINT32(M1.D)[j*2];
								lnksz[n_lnksz+j]=(int) IC_UINT32(M1.D)[2*j+1];
							}
						}
						else
						{
							for(j=0;j<2*n_lnksz;j++)
								lnksz[j]=(int) IC_UINT32(M1.D)[j];
						}
						break;
		}
	}
	else
	{
		if (m1==2)
		{
			for(j=0;j<n_lnksz;j++)
			{
				lnksz[j]=(int) ((double *) stk(l1))[j*2];
				lnksz[n_lnksz+j]=(int) ((double *) stk(l1))[2*j+1];
			}
		}
		else
		{
			for(j=0;j<2*n_lnksz;j++)
				lnksz[j]=(int) ((double *) stk(l1))[j];
		}
	}

	/*store rhs 2 in lnktyp */
	if (VarType(2) == sci_ints)
	{
		switch (M2.it)
		{
		case I_CHAR   : for(j=0;j<n_lnktyp;j++)
							lnktyp[j]=(int) IC_CHAR(M2.D)[j];
			break;

		case I_INT16  : for(j=0;j<n_lnktyp;j++)
							lnktyp[j]=(int) IC_INT16(M2.D)[j];
			break;

		case I_INT32  : for(j=0;j<n_lnktyp;j++)
							lnktyp[j]=(int) IC_INT32(M2.D)[j];
			break;

		case I_UCHAR  : for(j=0;j<n_lnktyp;j++)
							lnktyp[j]=(int) IC_UCHAR(M2.D)[j];
			break;

		case I_UINT16 : for(j=0;j<n_lnktyp;j++)
							lnktyp[j]=(int) IC_UINT16(M2.D)[j];
			break;

		case I_UINT32 : for(j=0;j<n_lnktyp;j++)
							lnktyp[j]=(int) IC_UINT32(M2.D)[j];
			break;
		}
	}
	else
	{
		for(j=0;j<n_lnktyp;j++)
			lnktyp[j]=(int) ((double *) stk(l2))[j];
	}

	/* build output list */
	CreateVar(3,LIST_DATATYPE,&n_lnktyp,&n3,&l3);

	for(i=0;i<n_lnktyp;i++)
	{
		nm=lnksz[i]*lnksz[i+n_lnktyp];
		switch (lnktyp[i])
		{
		case 1  : if ((ptr_d=MALLOC(nm*sizeof(double)))==NULL)
				  {
					  ierr=-1;
					  break;
				  }
				  for (j=0;j<nm;j++) ptr_d[j]=0;
				  CreateListVarFromPtr(3,i+1,MATRIX_OF_DOUBLE_DATATYPE,&lnksz[i],&lnksz[i+n_lnktyp], &ptr_d);
				  FREE(ptr_d);
				  break;

		case 2  : if ((ptr_d=MALLOC(2*nm*sizeof(double)))==NULL)
				  {
					  ierr=-1;
					  break;
				  }
				  for (j=0;j<2*nm;j++) ptr_d[j]=0;
				  ptr_dc = &ptr_d[nm];
				  CreateListCVarFromPtr(3,i+1,MATRIX_OF_DOUBLE_DATATYPE,(j=1,&j),&lnksz[i],&lnksz[i+n_lnktyp],&ptr_d,&ptr_dc);
				  FREE(ptr_d);
				  break;

		case 3  : if ((ptr_i=MALLOC(nm*sizeof(int)))==NULL)
				  {
					  ierr=-1;
					  break;
				  }
				  for (j=0;j<nm;j++) ptr_i[j]=0;
				  M3.m = lnksz[i];
				  M3.n = lnksz[i+n_lnktyp];
				  M3.it = 4;
				  M3.l = -1;
				  M3.D = ptr_i;
				  CreateListVarFromPtr(3,i+1,MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE,&M3.m,&M3.n,&M3);
				  FREE(ptr_i);
				  break;

		case 4  : if ((ptr_s=MALLOC(nm*sizeof(short)))==NULL)
				  {
					  ierr=-1;
					  break;
				  }
				  for (j=0;j<nm;j++) ptr_s[j]=0;
				  M3.m = lnksz[i];
				  M3.n = lnksz[i+n_lnktyp];
				  M3.it = 2;
				  M3.l = -1;
				  M3.D = ptr_s;
				  CreateListVarFromPtr(3,i+1,MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE,&M3.m,&M3.n,&M3);
				  FREE(ptr_s);
				  break;

		case 5  : if ((ptr_c=MALLOC(nm*sizeof(char)))==NULL)
				  {
					  ierr=-1;
					  break;
				  }
				  for (j=0;j<nm;j++) ptr_c[j]=0;
				  M3.m = lnksz[i];
				  M3.n = lnksz[i+n_lnktyp];
				  M3.it = 1;
				  M3.l = -1;
				  M3.D = ptr_c;
				  CreateListVarFromPtr(3,i+1,MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE,&M3.m,&M3.n,&M3);
				  FREE(ptr_c);
				  break;

		case 6  : if ((ptr_ui=MALLOC(nm*sizeof(unsigned int)))==NULL)
				  {
					  ierr=-1;
					  break;
				  }
				  for (j=0;j<nm;j++) ptr_ui[j]=0;
				  M3.m = lnksz[i];
				  M3.n = lnksz[i+n_lnktyp];
				  M3.it = 14;
				  M3.l = -1;
				  M3.D = ptr_ui;
				  CreateListVarFromPtr(3,i+1,MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE,&M3.m,&M3.n,&M3);
				  FREE(ptr_ui);
				  break;

		case 7  : if ((ptr_us=MALLOC(nm*sizeof(unsigned short)))==NULL)
				  {
					  ierr=-1;
					  break;
				  }
				  for (j=0;j<nm;j++) ptr_us[j]=0;
				  M3.m = lnksz[i];
				  M3.n = lnksz[i+n_lnktyp];
				  M3.it = 12;
				  M3.l = -1;
				  M3.D = ptr_us;
				  CreateListVarFromPtr(3,i+1,MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE,&M3.m,&M3.n,&M3);
				  FREE(ptr_us);
				  break;

		case 8  : if ((ptr_uc=MALLOC(nm*sizeof(unsigned char)))==NULL)
				  {
					  ierr=-1;
					  break;
				  }
				  for (j=0;j<nm;j++) ptr_uc[j]=0;
				  M3.m = lnksz[i];
				  M3.n = lnksz[i+n_lnktyp];
				  M3.it = 11;
				  M3.l = -1;
				  M3.D = ptr_uc;
				  CreateListVarFromPtr(3,i+1,MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE,&M3.m,&M3.n,&M3);
				  FREE(ptr_uc);
				  break;

		default : if ((ptr_d=MALLOC(nm*sizeof(double)))==NULL)
				  {
					  ierr=-1;
					  break;
				  }
				  for (j=0;j<nm;j++) ptr_d[j]=0;
				  CreateListVarFromPtr(3,i+1,MATRIX_OF_DOUBLE_DATATYPE,&lnksz[i],&lnksz[i+n_lnktyp], &ptr_d);
				  FREE(ptr_d);
				  break;
		}

		if (ierr==-1)
		{
			Scierror(999,_("%s : No more free memory.\n"),fname);
			FREE(lnksz);
			FREE(lnktyp);
			return 0;
		}
	}

	LhsVar(1) = 3;
	FREE(lnksz);
	FREE(lnktyp);
    PutLhsVar();
	return 0;
}
示例#4
0
/*----------------------------------------------------------
 * int_imfinfo: 
 *     interface for imfinfo function.
 *     should provide  type=imfinfo(name)  at Scilab level 
 * $Revision: 1.3 $ $Date: 2009-04-14 14:02:45 $
 *----------------------------------------------------------*/
SipExport int 
int_imfinfo(char *fname)
{
   /* Interface variables */ 
   int   mC, nC, lC,  /* for name input  arg */
         mV, nV, lV,  /* for "verbose" optional input arg */
         mL=12, nL=1, lL,  /* for list output arg */
         mS=1, nS=12,
         mFileName, nFileName=1, 
         mFileSize=1, nFileSize=1,
         mFormat, nFormat=1, 
         mWidth=1, nWidth=1, 
         mHeight=1, nHeight=1, 
         mDepth=1, nDepth=1, 
         mStorageType, nStorageType=1, 
         mNumberOfColors=1, nNumberOfColors=1, 
         mResolutionUnit, nResolutionUnit=1, 
         mXResolution=1, nXResolution=1, 
         mYResolution=1, nYResolution=1, 
         pos,
         minlhs=1, maxlhs=1, minrhs=1, maxrhs=2, i;
   unsigned long int *lWidth, *lHeight, *lDepth, *lNumberOfColors,
                     *lFileSize, fsize;
   char *lFileName, *lStorageType, *lFormat, *lResolutionUnit, *arg2;
   double *lXResolution, *lYResolution;
   static char 
      *Str[]= {   "type", "FileName", "FileSize", "Format", 
                  "Width", "Height", "Depth", "StorageType", 
                  "NumberOfColors", "ResolutionUnit", "XResolution", 
                  "YResolution" }; 

   /* ImageMagick variables */
   ExceptionInfo  exception;
   Image          *image;
   ImageInfo      *image_info;

   CheckRhs(minrhs, maxrhs);
   CheckLhs(minlhs, maxlhs);


   /* Get name (#1) and "verbose" optional arg (#2)*/
   GetRhsVar(1, "c", &mC, &nC, &lC);  
   if (Rhs == 2) {
      GetRhsVar(2, "c", &mV, &nV, &lV);
      arg2 = (char *)calloc(strlen(cstk(lV))+1, sizeof(char));
      if (!arg2)
         sip_error("unable to alloc memory");
      strcpy(arg2,cstk(lV));
   }

   InitializeMagick(NULL);
   GetExceptionInfo(&exception);
   image_info=CloneImageInfo((ImageInfo *) NULL);
   (void) strcpy(image_info->filename,cstk(lC));

   image = PingImage(image_info, &exception);
   if (image == (Image *) NULL) {
      /* clean up */
      if (Rhs==2)
        free(arg2);
      if(exception.reason != NULL) {
         char errmsg[50];
         for (i=0; i<49; i++)
            errmsg[i]=' ';
         errmsg[49]='\0';
         strncpy(errmsg,GetLocaleExceptionMessage(exception.severity,exception.reason),50);
         DestroyImageInfo(image_info);
         DestroyExceptionInfo(&exception);
         DestroyMagick();
         sip_error(errmsg);
      }
      DestroyImageInfo(image_info);
      DestroyExceptionInfo(&exception);
      DestroyMagick();
      sip_error("unknown reason");
   }

   pos =1;
   CreateVar(1, "t", &mL, &nL, &lL);
   CreateListVarFromPtr(1,pos++,"S", &mS, &nS, Str);

   lFileName = image->filename;
   mFileName = strlen(image->filename);
   CreateListVarFromPtr(1,pos++,"c", &mFileName, &nFileName, &lFileName);

   fsize = SizeBlob(image);
   lFileSize = &fsize;
   CreateListVarFromPtr(1,pos++,"i", &mFileSize, &nFileSize, &lFileSize);

   lFormat = image->magick;
   mFormat = strlen(image->magick);
   CreateListVarFromPtr(1,pos++,"c", &mFormat, &nFormat, &lFormat);

   lWidth = &(image->columns);
   CreateListVarFromPtr(1,pos++,"i", &mWidth, &nWidth, &lWidth);

   lHeight = &(image->rows);
   CreateListVarFromPtr(1,pos++,"i", &mHeight, &nHeight, &lHeight);

   lDepth = &(image->depth);
   CreateListVarFromPtr(1,pos++,"i", &mDepth, &nDepth, &lDepth);

   lStorageType = (image->storage_class == DirectClass)? "truecolor":"indexed";
   mStorageType = strlen(lStorageType);
   CreateListVarFromPtr(1,pos++,"c", &mStorageType, &nStorageType, &lStorageType);

   lNumberOfColors = &(image->colors);
   CreateListVarFromPtr(1,pos++,"i", &mNumberOfColors, \
                                     &nNumberOfColors, &lNumberOfColors);

   /*
   lComments = image->comments;
   mComments = strlen(image->comments);
   CreateListVarFromPtr(1,pos++,"c", &mComments, &nComments, &lComments);
   */

   lResolutionUnit = (image->units == PixelsPerInchResolution)?"inch":"centimeter";
   mResolutionUnit = strlen(lResolutionUnit);
   CreateListVarFromPtr(1,pos++,"c", &mResolutionUnit, \
                                     &nResolutionUnit, &lResolutionUnit);

   lXResolution = &(image->x_resolution);
   CreateListVarFromPtr(1,pos++,"i", &mXResolution, &nXResolution, &lXResolution);

   lYResolution = &(image->y_resolution);
   CreateListVarFromPtr(1,pos++,"i", &mYResolution, &nYResolution, &lYResolution);

   if (Rhs==2) {
      if (strcmp(arg2,"verbose") != 0)
         sip_error("invalid 2nd argument");
      sciprint("       FileName: %s\n\r", image->filename);
      sciprint("       FileSize: %d\n\r", fsize);
      sciprint("         Format: %s\n\r", image->magick);
      sciprint("          Width: %d\n\r", image->columns);
      sciprint("         Height: %d\n\r", image->rows);
      sciprint("          Depth: %d\n\r", image->depth);
      sciprint("    StorageType: %s\n\r", lStorageType);
      sciprint(" NumberOfColors: %d\n\r", image->colors);
      sciprint(" ResolutionUnit: %s\n\r", lResolutionUnit);
      sciprint("    XResolution: %f\n\r", image->x_resolution);
      sciprint("    YResolution: %f\n\r", image->y_resolution);
      free(arg2);
   }

   /* Terminate Imagemagick */
   DestroyImageInfo(image_info);
   DestroyImage(image);
   DestroyExceptionInfo(&exception);
   DestroyMagick();

   /*  Return variables  */
   LhsVar(1) = 1;
   return true;
}
示例#5
0
/*--------------------------------------------------------------------------*/
int intsplin3d(char * fname,unsigned long fname_len)
{
    /*
    *   [tlist] = splin3d(x, y, z, v [,orderxyz])
    */
    static char *Str[] = {"tensbs3d", "tx", "ty", "tz", "order", "bcoef", "xyzminmax"};

    int minrhs = 4, maxrhs = 5, minlhs = 1, maxlhs = 1;

    int mx = 0, nx = 0, lx = 0, my = 0, ny = 0, ly = 0, mz = 0, nz = 0, lz = 0, mo = 0;
    int no = 0, lo = 0, kx = 0, ky = 0, kz = 0;
    int ntx = 0, nty = 0, ntz = 0, ltx = 0, lty = 0, ltz = 0, lbcoef = 0, lxyzminmax = 0;
    int mwk = 0, mwkx = 0, mwky = 0, mwkz = 0;
    int flag = 0, one = 1, three = 3, six = 6, seven = 7, ltlist = 0, nxyz = 0, lwork = 0;
    int lar = 0, lorder = 0, *order = NULL;
    double *x = NULL, *y = NULL, *z = NULL, *xyzminmax = NULL;
    int i = 0;
    RealHyperMat V;

    CheckRhs(minrhs, maxrhs);
    CheckLhs(minlhs, maxlhs);

    GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &mx, &nx, &lx);
    CheckVector(1, mx, nx); 
    x = stk(lx);
    GetRhsVar(2,MATRIX_OF_DOUBLE_DATATYPE, &my, &ny, &ly);
    CheckVector(2, my, ny); 
    y = stk(ly);
    GetRhsVar(3,MATRIX_OF_DOUBLE_DATATYPE, &mz, &nz, &lz);
    CheckVector(2, mz, nz); 
    z = stk(lz);

    for (i = 1; i <= minrhs - 1; i++)
    {
        SciErr sciErr;
        int *piAddressVar = NULL;
        sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddressVar);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, i);
            return 0;
        }

        if (isVarComplex(pvApiCtx, piAddressVar))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: Real matrix expected.\n"), fname, i);
            return 0;
        }
    }

    nx = mx * nx; 
    ny = my * ny; 
    nz = mz * nz;

    if (nx < 3  ||  ny < 3  ||  nz < 3)
    {
        Scierror(999,_("%s: Wrong size for input arguments: x, y and z grids must have at least %d points.\n"), fname, 3);
        return 0;
    }

    GetRhsRealHMat(4, &V);
    if ( V.dimsize != 3 )
    {
        Scierror(999,_("%s: Wrong size for input argument #%d: A real 3-dimension hypermatrix expected.\n"),fname,4);
        return 0;
    }
    if ( V.dims[0] != nx  ||  V.dims[1] != ny  ||  V.dims[2] != nz  )
    {
        Scierror(999,"%s: Wrong value for input argument: Size incompatibility between grid points and grid values.\n", fname);
        return 0;
    }

    if ( Rhs == 5 )
    {
        GetRhsVar(5,MATRIX_OF_DOUBLE_DATATYPE, &mo, &no, &lo);
        if ( (mo != 1 && no != 1)  ||  mo*no != 3 )
        {
            Scierror(999,_("%s: Wrong value for input argument #%d: Vector with %d components expected.\n"),fname,4,3);
            return 0;
        }
        kx = (int)*stk(lo); 
        ky = (int)*stk(lo+1); 
        kz = (int)*stk(lo+2);
        if ( kx < 2  ||  kx >= nx  ||  ky < 2  ||  ky >= ny  ||  kz < 2  ||  kz >= nz )
        {
            Scierror(999,_("%s: Wrong values for input argument #%d.\n"), fname, 5);
            return 0;
        }
    }
    else
    {
        kx = 4;
        ky = 4;
        kz = 4;
    }

    ntx = nx + kx;
    nty = ny + ky;
    ntz = nz + kz;
    mwkx = kx*(nx+1); mwky = ky*(ny+1); mwkz = kz*(nz+1);
    mwkx = Max(mwkx, mwky);
    mwk = nx*ny*nz + 2*(Max(mwkx, mwkz));
    nxyz = nx*ny*nz;

    CreateVar(Rhs+1,TYPED_LIST_DATATYPE, &seven, &one, &ltlist);
    CreateListVarFromPtr(Rhs+1, 1,MATRIX_OF_STRING_DATATYPE, &one,  &seven, Str);
    lar = -1; CreateListVarFrom(Rhs+1, 2,MATRIX_OF_DOUBLE_DATATYPE, &ntx, &one, &ltx, &lar);
    lar = -1; CreateListVarFrom(Rhs+1, 3,MATRIX_OF_DOUBLE_DATATYPE, &nty, &one, &lty, &lar);
    lar = -1; CreateListVarFrom(Rhs+1, 4,MATRIX_OF_DOUBLE_DATATYPE, &ntz, &one, &ltz, &lar);
    lorder = 4;
    lar = -1; CreateListVarFrom(Rhs+1, 5,MATRIX_OF_VARIABLE_SIZE_INTEGER_DATATYPE, &three, &one, &lorder, &lar);
    order = istk(lorder); order[0] = kx; order[1] = ky; order[2] = kz;
    lar = -1; CreateListVarFrom(Rhs+1, 6,MATRIX_OF_DOUBLE_DATATYPE, &nxyz,  &one, &lbcoef, &lar);
    lar = -1; CreateListVarFrom(Rhs+1, 7,MATRIX_OF_DOUBLE_DATATYPE, &six,  &one, &lxyzminmax, &lar);
    xyzminmax = stk(lxyzminmax);
    xyzminmax[0] = x[0];
    xyzminmax[1] = x[nx - 1];
    xyzminmax[2] = y[0];
    xyzminmax[3] = y[ny - 1];
    xyzminmax[4] = z[0];
    xyzminmax[5] = z[nz - 1];
    CreateVar(Rhs + 2, MATRIX_OF_DOUBLE_DATATYPE, &mwk, &one, &lwork); 

    flag = 0;
    C2F(db3ink) ( stk(lx), &nx, stk(ly), &ny, stk(lz), &nz, V.R,
        &nx, &ny, &kx, &ky, &kz, stk(ltx), stk(lty), stk(ltz),
        stk(lbcoef), stk(lwork), &flag);

    if ( flag != 1 )
    {
        Scierror(999, _("%s: Problem with 'flag' = %d\n"), fname, flag);
        return 0;
    }

    /*  Return only the tlist  */
    LhsVar(1) = Rhs+1;
    PutLhsVar();
    return 0;
}