示例#1
0
/*--------------------------------------------------------------------------*/
void C2F(mput) (int *fd, double *res, int *n, char *type, int *ierr)
{
    *ierr = 0;
    if (strlen(type) == 0)
    {
        if (getWarningMode())
        {
            sciprint(_("%s: Wrong size for input argument #%d ('%s'): Non-empty string expected.\n"), "mput", 4, type);
        }
        *ierr = 2;
        return;
    }

    types::File *pFile = FileManager::getFile(*fd);
    if (pFile && pFile->getFiledesc())
    {
        mput2(pFile->getFiledesc(), pFile->getFileSwap(), res, *n, type, ierr);
        if (*ierr > 0)
        {
            if (getWarningMode())
            {
                sciprint(_("%s: Wrong value for input argument #%d ('%s'): Format not recognized.\n"), "mput", 4, type);
            }
        }
    }
    else
    {
        if (getWarningMode())
        {
            sciprint(_("%s: No input file associated to logical unit %d.\n"), "mput", *fd);
        }
        *ierr = 3;
    }
}
示例#2
0
/*--------------------------------------------------------------------------*/
void C2F(mput) (int *fd, double *res, int *n, char *type, int *ierr)
{
  int nc = 0,swap2 = 0;
  FILE *fa = NULL;
  *ierr = 0;
  if ((nc = (int)strlen(type)) == 0)
    {
      if ( getWarningMode() ) sciprint(_("%s: Wrong size for input argument #%d ('%s'): Non-empty string expected.\n"),"mput",4,type);
      *ierr = 2;
      return;
    }

  if ( *fd == -1  &&  GetFileOpenedInScilab(*fd) == NULL )
    {
      sciprint(_("%s: No File opened in Scilab.\n") , "mput" ) ;
      *ierr = 3 ;
      return ;
    }

  if ((fa = GetFileOpenedInScilab(*fd)) !=NULL)
    {
      swap2 = GetSwapStatus(*fd);
      mput2(fa,swap2,res,*n,type,ierr);
      if (*ierr > 0) {
	if ( getWarningMode() ) {
	  sciprint(_("%s: Wrong value for input argument #%d ('%s'): Format not recognized.\n"),"mput",4,type);
	}
      }
    }
  else
    {
      if ( getWarningMode() ) {
	sciprint(_("%s: Error while opening, reading or writing '%s'.\n"),"mput", GetFileNameOpenedInScilab(*fd));
      }
      *ierr=3;
    }
}
示例#3
0
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void writec(int *flag, int *nevprt,
                                 double *t, double xd[],
                                 double x[], int *nx,
                                 double z[], int *nz,
                                 double tvec[], int *ntvec,
                                 double rpar[], int *nrpar,
                                 int ipar[], int *nipar,
                                 double *inptr[], int insz[],
                                 int *nin, double *outptr[],
                                 int outsz[], int *nout)
/*
ipar[1]   = lfil : file name length
ipar[2:4] = fmt  : numbers type ascii code
ipar[5]   = n : buffer length in number of records
ipar[6]   = swap
ipar[7:6+lfil] = character codes for file name
*/

{
    char str[100], type[4];
    int job = 1, three = 3;
    FILE *fd = NULL;
    int n = 0, k = 0, i = 0, ierr = 0;
    double *buffer = NULL, *record = NULL;

    --ipar;
    --z;
    fd = (FILE *)(long)z[2];
    buffer = (z + 3);
    ierr = 0;
    /*
    k    : record counter within the buffer
    */

    if (*flag == 2 && *nevprt > 0) /* add a new record to the buffer */
    {
        n    = ipar[5];
        k    = (int)z[1];
        /* copy current record to output */
        record = buffer + (k - 1) * (insz[0]);

        for (i = 0; i < insz[0]; i++)
        {
            record[i] = *(inptr[0] + i);
        }
        if (k < n)
        {
            z[1] = z[1] + 1.0;
        }
        else  /* buffer is full write it to the file */
        {
            for (i = 0; i < three; ++i)
            {
                type[i] = (char) ipar[i + 2];
            }
            for (i = 2; i >= 0; i--)
                if (type[i] != ' ')
                {
                    type[i + 1] = '\0';
                    break;
                }
            mput2(fd, ipar[6], buffer, ipar[5]*insz[0], type, &ierr);
            if (ierr != 0)
            {
                *flag = -3;
                return;
            }
            z[1] = 1.0;
        }
    }
    else if (*flag == 4)
    {
        for (i = 0; i < ipar[1]; ++i)
        {
            str[i] = (char) ipar[i + 7];
        }
        str[ipar[1]] = '\0';
        wcfopen(fd, str, "wb");
        if (!fd )
        {
            scicos_print(_("Could not open the file!\n"));
            *flag = -3;
            return;
        }
        z[2] = (long)fd;
        z[1] = 1.0;
    }
    else if (*flag == 5)
    {
        if (z[2] == 0)
        {
            return;
        }
        k    = (int) z[1];
        if (k >= 1) /* flush rest of buffer */
        {
            for (i = 0; i < three; ++i)
            {
                type[i] = (char) ipar[i + 2];
            }
            for (i = 2; i >= 0; i--)
                if (type[i] != ' ')
                {
                    type[i + 1] = '\0';
                    break;
                }
            mput2(fd, ipar[6], buffer, (k - 1)*insz[0], type, &ierr);
            if (ierr != 0)
            {
                *flag = -3;
                return;
            }
        }
        fclose(fd);
        z[2] = 0.0;
    }
    return;
}
示例#4
0
文件: writeau.c 项目: rfabbri/scilab
/*--------------------------------------------------------------------------*/
SCICOS_BLOCKS_IMPEXP void writeau(int *flag, int *nevprt,
                                  double *t, double xd[],
                                  double x[], int *nx,
                                  double z[], int *nz,
                                  double tvec[], int *ntvec,
                                  double rpar[], int *nrpar,
                                  int ipar[], int *nipar,
                                  double *inptr[], int insz[],
                                  int *nin, double *outptr[],
                                  int outsz[], int *nout)
/*
ipar[1]   = lfil : file name length
ipar[2:4] = fmt  : numbers type ascii code
ipar[5]   = n : buffer length in number of records
ipar[6]   = swap
ipar[7:6+lfil] = character codes for file name
*/
{
    FILE *fd = NULL;
    int n = 0, k = 0, i = 0, ierr = 0;
    double *buffer = NULL, *record = NULL;
    /*  long offset;*/
    int SCALE  = 32768;
    int BIAS   =   132;
    int CLIP   = 32635;
    int OFFSET =   335;
    double y = 0.;
    int sig = 0;
    int e = 0;
    double f = 0.;


    --ipar;
    --z;
    fd = (FILE *)(long)z[2];
    buffer = (z + 3);
    ierr = 0;
    /*
    k    : record counter within the buffer
    */

    if (*flag == 2 && *nevprt > 0)
    {
        /* add a new record to the buffer */
        n    = ipar[5];
        k    = (int)z[1];
        /* copy current record to output
        printf("%i\n",k);*/
        record = buffer + (k - 1) * (*nin);

        for (i = 0; i < *nin; i++)
        {
            y = *inptr[i];
            y = SCALE * y;
            if (y < 0.0)
            {
                y = -y;
                sig = -1;
            }
            else
            {
                sig = 1;
            }
            if (y > CLIP)
            {
                y = CLIP;
            }
            y = y + BIAS;
            f = frexp(y, &e);
            y = 64 * sig - 16 * e - (int) (32 * f) + OFFSET;
            record[i] = y;
        }
        if (k < n)
        {
            z[1] = z[1] + 1.0;
        }
        else
        {
            mput2(fd, ipar[6], buffer, ipar[5] * (*nin), "uc", &ierr);
            if (ierr != 0)
            {
                *flag = -3;
                return;
            }
            z[1] = 1.0;

        }

    }
    else if (*flag == 4)
    {
        wcfopen(fd, "/dev/audio", "wb");
        if (!fd )
        {
            sciprint(_("Could not open /dev/audio!\n"));
            *flag = -3;
            return;
        }
        z[2] = (double)(long)fd;
        z[1] = 1.0;
    }
    else if (*flag == 5)
    {
        if (z[2] == 0)
        {
            return;
        }
        k    = (int) z[1];
        if (k > 1) /* flush rest of buffer */
        {
            mput2(fd, ipar[6], buffer, (k - 1) * (*nin), "uc", &ierr);
            if (ierr != 0)
            {
                *flag = -3;
                return;
            }
        }
        fclose(fd);
        z[2] = 0.0;
    }
    return;
}