Exemplo n.º 1
0
/*--------------------------------------------------------------------------*/
int get_optional_int_arg(void* _pvCtx, char* fname, int pos, char* name, int** value, int sz, rhs_opts opts[])
{
    int m, n, first_opt = FirstOpt(_pvCtx), kopt;

    if (pos < first_opt)
    {
        int* piAddr = 0;
        int iType = 0;
        int* piData = NULL;
        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
        getVarType(_pvCtx, piAddr, &iType);

        if (iType)
        {
            getMatrixOfDoubleAsInteger(_pvCtx, piAddr, &m, &n, &piData);
            if (m * n != sz)
            {
                return 1;
            }
            *value = piData;
        }
    }
    else if ((kopt = FindOpt(_pvCtx, name, opts)) >= 0)
    {
        int* piData = NULL;

        getMatrixOfDoubleAsInteger(_pvCtx, opts[kopt].piAddr, &m, &n, &piData);
        if (m * n < 1)
        {
            return 1;
        }
        *value = piData;
    }
    return 1;
}
Exemplo n.º 2
0
/*--------------------------------------------------------------------------*/
int get_colminmax_arg(char *fname,int pos,rhs_opts opts[], int ** colminmax )
{
  int m,n,l,first_opt=FirstOpt(),kopt;

  if (pos < first_opt)
    {
      if (VarType(pos))
	{
	  GetRhsVar(pos,MATRIX_OF_INTEGER_DATATYPE, &m, &n, &l);
	  CheckLength(pos,m*n,2);
	  *colminmax=istk(l);
	}
      else
	{
	  /** global value can be modified  **/
    int zeros[2] = { 0, 0 } ;
    setDefColMinMax( zeros ) ;
	  *colminmax = getDefColMinMax() ;
	}
    }
  else if ((kopt=FindOpt("colminmax",opts)))
    {
      GetRhsVar(kopt,MATRIX_OF_INTEGER_DATATYPE, &m, &n, &l);
      CheckLength(kopt,m*n,2);
      *colminmax=istk(l);
    }
  else
    {
      /** global value can be modified  **/
      int zeros[2] = { 0, 0 } ;
      setDefColMinMax( zeros ) ;
      *colminmax = getDefColMinMax() ;
    }
  return 1;
}
Exemplo n.º 3
0
/*--------------------------------------------------------------------------*/
int get_legend_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], char ** legend)
{
    int first_opt = FirstOpt(_pvCtx), kopt;

    if (pos < first_opt)
    {
        int* piAddr = 0;
        int iType = 0;
        char* pstData = NULL;
        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
        getVarType(_pvCtx, piAddr, &iType);

        if (iType)
        {
            getAllocatedSingleString(_pvCtx, piAddr, &pstData);
            *legend = pstData;
        }
        else
        {
            *legend = getDefLegend();
        }
    }
    else if ((kopt = FindOpt(_pvCtx, "leg", opts)) >= 0)
    {
        char* pstData = NULL;
        getAllocatedSingleString(_pvCtx, opts[kopt].piAddr, &pstData);
        *legend = pstData;
    }
    else
    {
        *legend = getDefLegend();
    }
    return 1;
}
Exemplo n.º 4
0
/*--------------------------------------------------------------------------*/
int get_with_mesh_arg(char *fname,int pos,rhs_opts opts[], BOOL * withMesh)
{
  int m,n,l,first_opt=FirstOpt(),kopt;

  if (pos < first_opt)
    {
      if (VarType(pos))
	{
	  GetRhsVar(pos,MATRIX_OF_BOOLEAN_DATATYPE, &m, &n, &l);
	  CheckLength(pos,m*n,1);
	  *withMesh = *(istk(l));
	}
      else
	{
	  /** global value can be modified  **/
	  setDefWithMesh( FALSE );
	  *withMesh = getDefWithMesh() ;
	}
    }
  else if ((kopt=FindOpt("mesh",opts)))
    {
      GetRhsVar(kopt,MATRIX_OF_BOOLEAN_DATATYPE, &m, &n, &l);
      CheckLength(kopt,m*n,1);
      *withMesh = *(istk(l));
    }
  else
    {
      /** global value can be modified  **/
      setDefWithMesh( FALSE );
      *withMesh = getDefWithMesh() ;
    }
  return 1;
}
Exemplo n.º 5
0
/*--------------------------------------------------------------------------*/
int get_legend_arg(char *fname,int pos,rhs_opts opts[], char ** legend )
{
  int m,n,l,first_opt=FirstOpt(),kopt;

  if (pos < first_opt)
    {
      if (VarType(pos)) {
	GetRhsVar(pos,STRING_DATATYPE, &m, &n, &l);
	*legend = cstk(l);
      }
      else
	{
	  *legend = getDefLegend() ;
	}
    }
  else if ((kopt=FindOpt("leg",opts))) {
    GetRhsVar(kopt,STRING_DATATYPE, &m, &n, &l);
    *legend = cstk(l);
  }
  else
    {
      *legend = getDefLegend() ;
    }
  return 1;
}
Exemplo n.º 6
0
/*--------------------------------------------------------------------------*/
int get_colout_arg(char *fname,int pos,rhs_opts opts[], int ** colout )
{
  int m,n,l,first_opt=FirstOpt(),kopt;

  if (pos < first_opt)
    {
      if (VarType(pos))
	{
	  GetRhsVar(pos,MATRIX_OF_INTEGER_DATATYPE, &m, &n, &l);
	  CheckLength(pos,m*n,2);
	  *colout = istk(l);
	}
      else
	{
	  /** global value can be modified  **/
    int newDefCO[2] = { -1, -1 } ;
    setDefColOut( newDefCO ) ;
	  *colout = getDefColOut() ;
	}
    }
  else if ((kopt=FindOpt("colout",opts)))
    {
      GetRhsVar(kopt,MATRIX_OF_INTEGER_DATATYPE, &m, &n, &l);
      CheckLength(kopt,m*n,2);
      *colout=istk(l);
    }
  else
    {
      /** global value can be modified  **/
      int newDefCO[2] = { -1, -1 } ;
      setDefColOut( newDefCO ) ;
      *colout = getDefColOut() ;
    }
  return 1;
}
Exemplo n.º 7
0
/*--------------------------------------------------------------------------*/
int get_nax_arg(void* _pvCtx, int pos, rhs_opts opts[], int ** nax, BOOL * flagNax)
{
    int i, m, n, first_opt = FirstOpt(_pvCtx), kopt;

    if (pos < first_opt)
    {
        int* piAddr = 0;
        int iType = 0;
        int* piData = NULL;
        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
        getVarType(_pvCtx, piAddr, &iType);

        if (iType)
        {
            getMatrixOfDoubleAsInteger(_pvCtx, piAddr, &m, &n, &piData);
            if (n * m != 4)
            {
                return 1;
            }

            for (i = 0 ; i < 4; ++i)
            {
                // When i = 1 or 3 we talk about the number of ticks, this value can be -1 to say 'AutoTicks'
                piData[i] = Max(piData[i], -(i % 2));
            }
            *nax = piData;
            *flagNax = TRUE;
        }
        else
        {
            *nax = getDefNax();
            *flagNax = FALSE;
        }
    }
    else if ((kopt = FindOpt(_pvCtx, "nax", opts)) >= 0)
    {
        int* piData = NULL;

        getMatrixOfDoubleAsInteger(_pvCtx, opts[kopt].piAddr, &m, &n, &piData);
        if (m * n != 4)
        {
            return 1;
        }

        for (i = 0 ; i < 4; ++i)
        {
            // When i = 1 or 3 we talk about the number of ticks, this value can be -1 to say 'AutoTicks'
            piData[i] = Max(piData[i], -(i % 2));
        }
        *nax = piData;
        *flagNax = TRUE;
    }
    else
    {
        *nax = getDefNax();
        *flagNax = FALSE;
    }
    return 1;
}
Exemplo n.º 8
0
inline ValuePtr Object::GetOpt<ValuePtr>(const std::string &key, const ValuePtr &defaultObject) const
{
	auto value = FindOpt(key);
	if(!value)
		return defaultObject;

	return value;
}
Exemplo n.º 9
0
inline Type Object::GetType(const std::string &key) const
{
	auto value = FindOpt(key);
	if(!value)
		return Type_Null;

	return value->GetType();
}
Exemplo n.º 10
0
static void
Do(int which, int ac, char *av[], Options opt, ConfInfo list)
{
  const int	scold = !(which & NO_SCOLD);

  which &= ~NO_SCOLD;
  for ( ; ac > 0; av++, ac--)
  {
    const int	index = FindOpt(list, *av);

    switch (index)
    {
      case -1:
	Log(LG_ERR, ("option \"%s\" unknown", *av));
	break;
      case -2:
	Log(LG_ERR, ("option \"%s\" ambiguous", *av));
	break;
      default:
	{
	  ConfInfo	const c = &list[index];

	  switch (which)
	  {
	    case ENABLE:
	      Enable(opt, c->option);
	      break;
	    case DISABLE:
	      Disable(opt, c->option);
	      break;
	    case ACCEPT:
	      if (!c->peered)
	      {
		if (scold)
		  Log(LG_ERR, ("'%s %s' is not applicable",
		    "accept", c->name));
	      }
	      else
		Accept(opt, c->option);
	      break;
	    case DENY:
	      if (!c->peered)
	      {
		if (scold)
		  Log(LG_ERR, ("'%s %s' is not applicable", "deny", c->name));
	      }
	      else
		Deny(opt, c->option);
	      break;
	    default:
	      assert(0);
	  }
	}
	break;
    }
  }
}
Exemplo n.º 11
0
inline std::string Object::GetOpt<std::string>(const std::string &key, const std::string &defaultValue) const
{
	auto value = FindOpt(key);

	if(!value)
		return defaultValue;

	return value->AsString();
}
Exemplo n.º 12
0
/**
 * retrieve the labels from the command line and store them into labels
 */
int get_labels_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], char ** labels)
{
    int first_opt = FirstOpt(), kopt;

    if (pos < first_opt)
    {
        int* piAddr = 0;
        int iType = 0;
        char* pstData = NULL;
        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
        getVarType(_pvCtx, piAddr, &iType);

        if (iType)
        {
            getAllocatedSingleString(_pvCtx, piAddr, &pstData);
            *labels = pstData;
        }
        else
        {
            /* jb silvy 03/2006 */
            /* do not change the legend if one already exists */
            char * pSubWinUID = (char*)getOrCreateDefaultSubwin();
            if (sciGetLegendDefined(pSubWinUID))
            {
                *labels = NULL;
            }
            else
            {
                *labels = getDefLegend();
            }
        }
    }
    else if ((kopt = FindOpt("leg", opts)))
    {
        int* piAddr = 0;
        char* pstData = NULL;
        getVarAddressFromPosition(_pvCtx, kopt, &piAddr);
        getAllocatedSingleString(_pvCtx, piAddr, &pstData);
        *labels = pstData;
    }
    else
    {
        /* jb silvy 03/2006 */
        /* do not change the legend if one already exists */
        char* pSubWinUID = (char*)getOrCreateDefaultSubwin();

        if (sciGetLegendDefined(pSubWinUID))
        {
            *labels = NULL;
        }
        else
        {
            *labels = getDefLegend();
        }
    }
    return 1;
}
Exemplo n.º 13
0
/*--------------------------------------------------------------------------*/
int get_strf_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], char ** strf)
{
    int first_opt = FirstOpt(_pvCtx), kopt;

    if (pos < first_opt)
    {
        int* piAddr = 0;
        int iType = 0;
        char* pstData = NULL;
        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
        getVarType(_pvCtx, piAddr, &iType);
        if (iType != 10)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, pos);
            return 0;
        }

        getAllocatedSingleString(_pvCtx, piAddr, &pstData);
        if ((int)strlen(pstData) != 3)
        {
            freeAllocatedSingleString(pstData);
            Scierror(999, _("%s: Wrong size for input argument #%d: String of %d characters expected.\n"), fname, pos, 3);
            return 0;
        }
        *strf = pstData;
    }
    else if ((kopt = FindOpt(_pvCtx, "strf", opts)) >= 0)
    {
        char* pstData = NULL;
        int iType = 0;
        getVarType(_pvCtx, opts[kopt].piAddr, &iType);
        if (iType != 10)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, pos);
            return 0;
        }

        getAllocatedSingleString(_pvCtx, opts[kopt].piAddr, &pstData);
        if ((int)strlen(pstData) != 3)
        {
            freeAllocatedSingleString(pstData);
            Scierror(999, _("%s: Wrong size for input argument #%d: String of %d characters expected.\n"), fname, kopt, 3);
            return 0;
        }
        *strf = pstData;
    }
    else
    {
        /* def value can be changed */
        reinitDefStrfN();
        *strf = getDefStrf();
    }
    return 1;
}
Exemplo n.º 14
0
/*--------------------------------------------------------------------------*/
int get_zminmax_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], double ** zminmax)
{
    int m, n, first_opt = FirstOpt(), kopt;

    if (pos < first_opt)
    {
        int* piAddr = 0;
        int iType = 0;
        double* pdblData = NULL;
        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
        getVarType(_pvCtx, piAddr, &iType);

        if (iType)
        {
            getMatrixOfDouble(_pvCtx, piAddr, &m, &n, &pdblData);
            if (m * n != 2)
            {
                Scierror(999, "%s: Wrong size for input argument #%d: %d expected\n", fname, pos, 2);
                return 0;
            }
            *zminmax = pdblData;
        }
        else
        {
            /** global value can be modified  **/
            double zeros[2] = { 0.0, 0.0 };
            setDefZminMax(zeros);
            *zminmax = getDefZminMax();
        }
    }
    else if ((kopt = FindOpt("zminmax", opts))) /* named argument: rect=value */
    {
        int* piAddr = 0;
        double* pdblData = NULL;
        getVarAddressFromPosition(_pvCtx, kopt, &piAddr);
        getMatrixOfDouble(_pvCtx, piAddr, &m, &n, &pdblData);
        if (m * n != 2)
        {
            Scierror(999, "%s: Wrong size for input argument #%d: %d expected\n", fname, kopt, 2);
            return 0;
        }
        *zminmax = pdblData;
    }
    else
    {
        /** global value can be modified  **/
        double zeros[2] = { 0.0, 0.0 };
        setDefZminMax(zeros);
        *zminmax = getDefZminMax();
    }

    return 1;
}
Exemplo n.º 15
0
/*--------------------------------------------------------------------------*/
int get_rect_arg(char *fname,int pos,rhs_opts opts[], double ** rect )
{
	int m,n,l,first_opt=FirstOpt(),kopt,i;

	if (pos < first_opt)
		{
			if (VarType(pos)) {
				GetRhsVar(pos,MATRIX_OF_DOUBLE_DATATYPE, &m, &n, &l);
				if (m * n != 4) {
					Scierror(999,"%s: Wrong size for input argument #%d: %d expected\n",fname,pos,4);
					return 0;
				}
				*rect = stk(l);

				for(i=0;i<4;i++)
					if(finite((*rect)[i]) == 0){
						Scierror(999,"%s: Wrong values (Nan or Inf) for input argument: %d finite values expected\n",fname,4);
						return 0;
					}
			}
			else
				{
					/** global value can be modified  **/
					double zeros[4] = { 0.0, 0.0, 0.0, 0.0 } ;
					setDefRect( zeros ) ;
					*rect = getDefRect() ;
				}
		}
	else if ((kopt=FindOpt("rect",opts))) {/* named argument: rect=value */
		GetRhsVar(kopt,MATRIX_OF_DOUBLE_DATATYPE, &m, &n, &l);
		if (m * n != 4) {
			Scierror(999,"%s: Wrong size for input argument #%d: %d expected\n",fname,kopt,4);
			return 0;
		}
		*rect = stk(l);

		for(i=0;i<4;i++)
			if(finite((*rect)[i]) == 0){
				Scierror(999,"%s: Wrong values (Nan or Inf) for input argument: %d finite values expected\n",fname,4);
				return 0;
			}
	}
	else
		{
			/** global value can be modified  **/
			double zeros[4] = { 0.0, 0.0, 0.0, 0.0 } ;
			setDefRect( zeros ) ;
			*rect = getDefRect() ;
		}

	return 1;
}
Exemplo n.º 16
0
/*--------------------------------------------------------------------------*/
int get_colout_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], int ** colout)
{
    int m, n, first_opt = FirstOpt(), kopt;

    if (pos < first_opt)
    {
        int* piAddr = 0;
        int iType = 0;
        int* piData = NULL;
        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
        getVarType(_pvCtx, piAddr, &iType);

        if (iType)
        {
            getMatrixOfDoubleAsInteger(_pvCtx, piAddr, &m, &n, &piData);
            if (m * n != 2)
            {
                return 1;
            }
            *colout = piData;
        }
        else
        {
            /** global value can be modified  **/
            int newDefCO[2] = { -1, -1 };
            setDefColOut(newDefCO);
            *colout = getDefColOut();
        }
    }
    else if ((kopt = FindOpt("colout", opts)))
    {
        int* piAddr = 0;
        int* piData = NULL;

        getVarAddressFromPosition(_pvCtx, kopt, &piAddr);
        getMatrixOfDoubleAsInteger(_pvCtx, piAddr, &m, &n, &piData);
        if (m * n != 2)
        {
            return 1;
        }
        *colout = piData;
    }
    else
    {
        /** global value can be modified  **/
        int newDefCO[2] = { -1, -1 };
        setDefColOut(newDefCO);
        *colout = getDefColOut();
    }
    return 1;
}
Exemplo n.º 17
0
/*--------------------------------------------------------------------------*/
int get_colminmax_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], int ** colminmax)
{
    int m, n, first_opt = FirstOpt(_pvCtx), kopt;

    if (pos < first_opt)
    {
        int* piAddr = 0;
        int iType = 0;
        int* piData = NULL;
        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
        getVarType(_pvCtx, piAddr, &iType);

        if (iType)
        {
            getMatrixOfDoubleAsInteger(_pvCtx, piAddr, &m, &n, &piData);
            if (m * n != 2)
            {
                return 1;
            }
            *colminmax = piData;
        }
        else
        {
            /** global value can be modified  **/
            int zeros[2] = { 0, 0 };
            setDefColMinMax(zeros);
            *colminmax = getDefColMinMax();
        }
    }
    else if ((kopt = FindOpt(_pvCtx, "colminmax", opts)) >= 0)
    {
        int* piData = NULL;

        getMatrixOfDoubleAsInteger(_pvCtx, opts[kopt].piAddr, &m, &n, &piData);
        if (m * n != 2)
        {
            return 1;
        }
        *colminmax = piData;
    }
    else
    {
        /** global value can be modified  **/
        int zeros[2] = { 0, 0 };
        setDefColMinMax(zeros);
        *colminmax = getDefColMinMax();
    }
    return 1;
}
Exemplo n.º 18
0
inline Object Object::GetOpt<Object>(const std::string &key, const Object &defaultObject) const
{
	auto value = FindOpt(key);
	if(!value)
		return defaultObject;

	try
	{
		return value->AsObject();
	}
	catch(std::exception &)
	{
		return defaultObject;
	}
}
Exemplo n.º 19
0
inline double Object::GetOpt<double>(const std::string &key, const double &defaultValue) const
{
	auto value = FindOpt(key);
	if(!value || (!value->IsNumber() && !value->IsString()))
		return defaultValue;

	try
	{
		return std::stod(value->AsString());
	}
	catch(std::exception &)
	{
		return defaultValue;
	}
}
Exemplo n.º 20
0
/**
 * retrieve the labels from the command line and store them into labels
 */
int get_labels_arg(char *fname, int pos, rhs_opts opts[], char ** labels)
{
    int m,n,l,first_opt=FirstOpt(),kopt;

    if (pos < first_opt)
    {
        if (VarType(pos))
        {
            GetRhsVar(pos,STRING_DATATYPE, &m, &n, &l);
            *labels = cstk(l);
        }
        else
        {
            /* jb silvy 03/2006 */
            /* do not change the legend if one already exists */
            char * pSubWinUID = getOrCreateDefaultSubwin();
            if (sciGetLegendDefined(pSubWinUID))
            {
                *labels = NULL;
            }
            else
            {
                *labels = getDefLegend();
            }
        }
    }
    else if ((kopt=FindOpt("leg",opts)))
    {
        GetRhsVar(kopt,STRING_DATATYPE, &m, &n, &l);
        *labels = cstk(l);
    }
    else
    {
        /* jb silvy 03/2006 */
        /* do not change the legend if one already exists */
        char* pSubWinUID = getOrCreateDefaultSubwin();

        if (sciGetLegendDefined(pSubWinUID))
        {
            *labels = NULL;
        }
        else
        {
            *labels = getDefLegend();
        }
    }
    return 1;
}
Exemplo n.º 21
0
inline uint64_t Object::GetOpt<uint64_t>(const std::string &key, const uint64_t &defaultValue) const
{
	auto value = FindOpt(key);
	if(!value || (!value->IsNumber() && !value->IsString()))
		return defaultValue;

	if(value->IsString() && value->AsString().empty())
		return defaultValue;

	try
	{
		return value->IsNumber() ? static_cast<uint32_t>(value->AsNumber()) 
			: std::stoll(value->AsString());
	}
	catch(std::exception &)
	{
		return defaultValue;
	}
}
Exemplo n.º 22
0
/*--------------------------------------------------------------------------*/
int get_strf_arg(char *fname,int pos,rhs_opts opts[], char ** strf )
{
  int m,n,l,first_opt=FirstOpt(),kopt;

  if (pos < first_opt)
  {
    if (VarType(pos))
    {
	    GetRhsVar(pos,STRING_DATATYPE, &m, &n, &l);
	    if ( m * n != 3 )
      {
		  Scierror(999,_("%s: Wrong size for input argument #%d: String of %d characters expected.\n"),fname,pos, 3);
	      return 0;
	    }
	  *strf = cstk(l);
    }
    else
	  {
	    /* def value can be changed */
      reinitDefStrf() ;
      *strf = getDefStrf() ;
	  }
  }
  else if ((kopt=FindOpt("strf",opts)))
  {
    GetRhsVar(kopt,STRING_DATATYPE, &m, &n, &l);
    if (m * n != 3)
    {
		Scierror(999,_("%s: Wrong size for input argument #%d: String of %d characters expected.\n"),fname,kopt,3);
		return 0;
    }
    *strf = cstk(l);
  }
  else
  {
    /* def value can be changed */

    reinitDefStrfN() ;
    *strf = getDefStrf() ;

  }
  return 1;
}
Exemplo n.º 23
0
/*--------------------------------------------------------------------------*/
int get_nax_arg(int pos,rhs_opts opts[], int ** nax, BOOL * flagNax )
{
  int i,m,n,l,first_opt=FirstOpt(),kopt;

  if (pos < first_opt)
  {
    if (VarType(pos))
    {
      GetRhsVar(pos,MATRIX_OF_INTEGER_DATATYPE, &m, &n, &l);
      CheckLength(pos,m*n,4);
      for (i = 0 ; i < 4; ++i)
      {
        // When i = 1 or 3 we talk about the number of ticks, this value can be -1 to say 'AutoTicks'
        *istk(l+i) = Max((int)  *istk(l+i),-(i%2));
      }
      *nax=istk(l);
      *flagNax = TRUE;
    }
    else
    {
	    *nax = getDefNax() ;
	    *flagNax = FALSE;
    }
  }
  else if ((kopt=FindOpt("nax",opts)))
  {
    GetRhsVar(kopt,MATRIX_OF_INTEGER_DATATYPE, &m, &n, &l);
    CheckLength(kopt,m*n,4);
    for (i = 0 ; i < 4; ++i)
    {
      // When i = 1 or 3 we talk about the number of ticks, this value can be -1 to say 'AutoTicks'
      *istk(l+i) = Max((int)  *istk(l+i),-(i%2));
    }
    *nax=istk(l);
    *flagNax = TRUE;
  }
  else
  {
    *nax = getDefNax() ;
    *flagNax = FALSE;
  }
  return 1;
}
Exemplo n.º 24
0
/*--------------------------------------------------------------------------*/
int get_with_mesh_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], BOOL * withMesh)
{
    int first_opt = FirstOpt(), kopt;

    if (pos < first_opt)
    {
        int* piAddr = 0;
        int iType = 0;
        int iData = 0;
        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
        getVarType(_pvCtx, piAddr, &iType);

        if (iType)
        {
            getScalarBoolean(_pvCtx, piAddr, &iData);
            *withMesh = iData;
        }
        else
        {
            /** global value can be modified  **/
            setDefWithMesh(FALSE);
            *withMesh = getDefWithMesh();
        }
    }
    else if ((kopt = FindOpt("mesh", opts)))
    {
        int* piAddr = 0;
        int iData = 0;
        getVarAddressFromPosition(_pvCtx, kopt, &piAddr);

        getScalarBoolean(_pvCtx, piAddr, &iData);
        *withMesh = iData;
    }
    else
    {
        /** global value can be modified  **/
        setDefWithMesh(FALSE);
        *withMesh = getDefWithMesh();
    }
    return 1;
}
Exemplo n.º 25
0
/*--------------------------------------------------------------------------*/
int get_zminmax_arg(char *fname,int pos,rhs_opts opts[], double ** zminmax )
{
  int m,n,l,first_opt=FirstOpt(),kopt;

  if (pos < first_opt)
    {
      if (VarType(pos)) {
        GetRhsVar(pos,MATRIX_OF_DOUBLE_DATATYPE, &m, &n, &l);
	if (m * n != 2) {
      Scierror(999,"%s: Wrong size for input argument #%d: %d expected\n",fname,pos,2);
	  return 0;
	}
	*zminmax = stk(l);
      }
      else
	{
	  /** global value can be modified  **/
    double zeros[2] = { 0.0, 0.0 } ;
    setDefZminMax( zeros ) ;
	  *zminmax = getDefZminMax() ;
	}
    }
  else if ((kopt=FindOpt("zminmax",opts))) {/* named argument: rect=value */
    GetRhsVar(kopt,MATRIX_OF_DOUBLE_DATATYPE, &m, &n, &l);
    if (m * n != 2) {
      Scierror(999,"%s: Wrong size for input argument #%d: %d expected\n",fname,kopt,2);
      return 0;
    }
    *zminmax = stk(l);
  }
  else
    {
      /** global value can be modified  **/
      double zeros[2] = { 0.0, 0.0 } ;
      setDefZminMax( zeros ) ;
      *zminmax = getDefZminMax() ;
    }

  return 1;
}
Exemplo n.º 26
0
/*--------------------------------------------------------------------------*/
int get_optional_double_arg(void* _pvCtx, char* fname, int pos, char* name, double** value, int sz, rhs_opts opts[])
{
    int m, n, first_opt = FirstOpt(), kopt;

    if (pos < first_opt)
    {
        int* piAddr = 0;
        int iType = 0;
        double* pdblData = NULL;
        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
        getVarType(_pvCtx, piAddr, &iType);

        if (iType)
        {
            getMatrixOfDouble(_pvCtx, piAddr, &m, &n, &pdblData);
            if (m * n != sz)
            {
                return 1;
            }
            *value = pdblData;
        }
    }
    else if ((kopt = FindOpt(name, opts)))
    {
        int* piAddr = 0;
        double* pdblData = NULL;
        getVarAddressFromPosition(_pvCtx, kopt, &piAddr);
        getMatrixOfDouble(_pvCtx, piAddr, &m, &n, &pdblData);
        if (m * n != sz)
        {
            Scierror(999, "%s: Wrong size for input argument #%d: %d expected\n", fname, kopt, 4);
            return 0;
        }

        *value = pdblData;
    }
    return 1;
}
Exemplo n.º 27
0
/*--------------------------------------------------------------------------*/
int get_optional_int_arg(     char  * fname,
                               int    pos  ,
                              char  * name ,
                               int ** value,
                               int    sz   ,
                          rhs_opts    opts[] )
{
  int m,n,l,first_opt=FirstOpt(),kopt;

  if (pos < first_opt)
    {
      if (VarType(pos)) {
	GetRhsVar(pos,MATRIX_OF_INTEGER_DATATYPE, &m, &n, &l);
	CheckLength(pos,m*n,sz)
	  *value = istk(l);
      }
    }
  else if ((kopt=FindOpt(name,opts))) {
    GetRhsVar(kopt,MATRIX_OF_INTEGER_DATATYPE, &m, &n, &l);
    CheckLength(kopt,m*n,sz)
      *value = istk(l);
  }
  return 1;
}
Exemplo n.º 28
0
main (int argc, char *argv[])
/*----------------------------------------------------------------------------->
/ purpose:  Dump Contents of any Level 1 product
/
/ coded by: Gerhard L.H. Kruizinga                08/23/00
/
<-----------------------------------------------------------------------------*/

{
  FILE         *src,*dst;

  FileHeader_t header;

  double       Acc1aZbias;

  char         BinFilename[HEADERMAXCHAR];
  char         AscFilename[HEADERMAXCHAR];
  char         TimeTag[HEADERMAXCHAR];
  char         file_format[HEADERMAXCHAR];
  char         NobsChar[HEADERMAXCHAR];
  char         FileTypeName[HEADERMAXCHAR];
  char         LinkTimeLabel[HEADERMAXCHAR];
  char         NrBytes[HEADERMAXCHAR];

  long         i,ShowHeader,arg_ndx,DumpNrec,AscFileDefined,HeaderOnly;
  long         MassTnk,MassThr,Ksnr;
  long         PresTnk,TempTnk,RegTnk,AdapTnk,TempRedTnk,ACC1A_count,AHK1A_vp;
  long         RmGdel,ACC1A_ang,ACC1A_lin;
  long         Ka_phase_only,K_phase_only;

/*----------------------------------------------------------------------------->
/ check usage
<-----------------------------------------------------------------------------*/

  if (argc < 2)
  {
   fprintf(stderr,
           "\n usage: %s -binfile Level1_Bin_File [-ascfile Level1_Asc_File] [-nohead] [-nrec] [-head_only]\n\n",
           argv[0]);
   fprintf(stderr,"         [-masstnk tnk_id (3=both tanks,0=none)] [-massthr tnk_id (3=both tanks,0=none)]\n");
   fprintf(stderr,"         [-pres_tnk tnk_id] [-temp_tnk tnk_id]\n");
   fprintf(stderr,"         [-reg_tnk tnk_id] [-adap_tnk tnk_id] [-tempred_tnk tnk_id]\n");
   fprintf(stderr,"         [-tstart Tstart] [-tfinal Tfinal] [-acc1a_count] [-acc1a_ang] [-acc1a_lin] [-ahk1a_vp]\n");
   fprintf(stderr,"         [-acc1a_zbias Acc1aZbias (def 0)] [-ksnr] [-ka] [-k] [-rm_gdel]\n");
   fprintf(stderr,"         If -ascfile is not defined then output will go to standard out\n");
   fprintf(stderr,"\n");
   exit(1);
  }

/*----------------------------------------------------------------------------->
/ Intialize Header information and other relevant info
<-----------------------------------------------------------------------------*/

  InitializeHeaders();

  LinkTime(LinkTimeLabel);

  MassTnk = 4;
  arg_ndx = FindOpt(argc,argv, "-masstnk");
  if (arg_ndx != -1) MassTnk  = GetLongArgv(argc,argv,"-masstnk");

  MassThr = 4;
  arg_ndx = FindOpt(argc,argv, "-massthr");
  if (arg_ndx != -1) MassThr  = GetLongArgv(argc,argv,"-massthr");

  PresTnk = 0;
  arg_ndx = FindOpt(argc,argv, "-pres_tnk");
  if (arg_ndx != -1) PresTnk  = GetLongArgv(argc,argv,"-pres_tnk");

  TempTnk = 0;
  arg_ndx = FindOpt(argc,argv, "-temp_tnk");
  if (arg_ndx != -1) TempTnk  = GetLongArgv(argc,argv,"-temp_tnk");

  TempRedTnk = 0;
  arg_ndx = FindOpt(argc,argv, "-tempred_tnk");
  if (arg_ndx != -1) TempRedTnk  = GetLongArgv(argc,argv,"-tempred_tnk");

  RegTnk = 0;
  arg_ndx = FindOpt(argc,argv, "-reg_tnk");
  if (arg_ndx != -1) RegTnk  = GetLongArgv(argc,argv,"-reg_tnk");

  AdapTnk = 0;
  arg_ndx = FindOpt(argc,argv, "-adap_tnk");
  if (arg_ndx != -1) AdapTnk  = GetLongArgv(argc,argv,"-adap_tnk");

  ShowHeader = 1;
  arg_ndx = FindOpt(argc,argv, "-nohead");
  if (arg_ndx != -1) ShowHeader  = 0;

  Ksnr = 0;
  arg_ndx = FindOpt(argc,argv, "-ksnr");
  if (arg_ndx != -1) Ksnr  = 1;

  Ka_phase_only = 0;
  arg_ndx = FindOpt(argc,argv, "-ka");
  if (arg_ndx != -1) Ka_phase_only  = 1;

  K_phase_only = 0;
  arg_ndx = FindOpt(argc,argv, "-k");
  if (arg_ndx != -1) K_phase_only  = 1;

  RmGdel = 0;
  arg_ndx = FindOpt(argc,argv, "-rm_gdel");
  if (arg_ndx != -1) RmGdel  = 1;

  HeaderOnly = 0;
  arg_ndx = FindOpt(argc,argv, "-head_only");
  if (arg_ndx != -1) HeaderOnly  = 1;

  DumpNrec = DUMPALL;
  arg_ndx = FindOpt(argc,argv, "-nrec");
  if (arg_ndx != -1) DumpNrec  = GetLongArgv(argc,argv,"-nrec");

  Tstart = -1.0e32;
  arg_ndx = FindOpt(argc,argv, "-tstart");
  if (arg_ndx != -1) Tstart  = GetDoubleArgv(argc,argv,"-tstart");

  Tfinal = 1.0e32;
  arg_ndx = FindOpt(argc,argv, "-tfinal");
  if (arg_ndx != -1) Tfinal  = GetDoubleArgv(argc,argv,"-tfinal");

  Acc1aZbias = 0.0;
  arg_ndx = FindOpt(argc,argv, "-acc1a_zbias");
  if (arg_ndx != -1) Acc1aZbias  = GetDoubleArgv(argc,argv,"-acc1a_zbias");

  AscFileDefined = 0;
  arg_ndx = FindOpt(argc,argv, "-ascfile");
  if (arg_ndx != -1) AscFileDefined = 1;

  ACC1A_count = 0;
  arg_ndx = FindOpt(argc,argv, "-acc1a_count");
  if (arg_ndx != -1) ACC1A_count = 1;

  ACC1A_ang = 0;
  arg_ndx = FindOpt(argc,argv, "-acc1a_ang");
  if (arg_ndx != -1) ACC1A_ang = 1;

  ACC1A_lin = 0;
  arg_ndx = FindOpt(argc,argv, "-acc1a_lin");
  if (arg_ndx != -1) ACC1A_lin = 1;

  AHK1A_vp = 0;
  arg_ndx = FindOpt(argc,argv, "-ahk1a_vp");
  if (arg_ndx != -1) AHK1A_vp = 1;

/*----------------------------------------------------------------------------->
/ Open files
<-----------------------------------------------------------------------------*/

  strcpy (BinFilename,GetStrArgv(argc,argv,"-binfile"));

  src = fopen(BinFilename,"r");
  if (src == NULL)
  {
   fprintf(stderr," Level 1 Product file  %s cannot be opened !! \n",
           BinFilename);
   exit(1);
  }


  if (AscFileDefined == 1)
  {
    strcpy (AscFilename,GetStrArgv(argc,argv,"-ascfile"));
    dst = fopen(AscFilename,"w");
    if (dst == NULL)
    {
     fprintf(stderr," Level 1 Product file  %s cannot be opened !! \n",
             AscFilename);
     exit(1);
    }
  }
  else
  {
    strcpy(AscFilename,"Standard_Out");
    dst = stdout;
  }

/*----------------------------------------------------------------------------->
/ Read Header information and write updated header to Ascii file
<-----------------------------------------------------------------------------*/

  if (ReadFileHeader(src,&header) == false)
  {   
    fprintf(stderr,"\n Problem reading file header for file %s\n",BinFilename);
    fprintf(stderr," See message above for problem\n\n");
    exit(1);
  }

  GetUTCTimeTag(TimeTag);
  strcat(TimeTag," by ");
  strcat(TimeTag,getenv("LOGNAME"));
 
  header.formattype = 1;
  strcpy(NrBytes,"Not Determined because output is stdout");

  if (!HeaderOnly)
  {
    sprintf(file_format,"%d",header.formattype);
    ModifyFileHeader(&header,GetHeaderLabel("iphFileFormat"),file_format);
    ModifyFileHeader(&header,GetHeaderLabel("iphFileName"),AscFilename);
    ModifyFileHeader(&header,GetHeaderLabel("iphNumberBytes")           , NrBytes);
  }

  if (ShowHeader != 0 ) WriteFileHeader(dst,&header);

  if (HeaderOnly) exit(0);

/*----------------------------------------------------------------------------->
/ Based on header information Dump Records
<-----------------------------------------------------------------------------*/

  if (header.filetype == GetFileType("ipGFD1XF"))  
    DumpGFD1XF(src,dst,DumpNrec,Ksnr,K_phase_only,Ka_phase_only);
  else if (header.filetype == GetFileType("ipACC1AF"))  
    DumpACC1AF(src,dst,DumpNrec,ACC1A_count,AHK1A_vp,RmGdel,ACC1A_ang,ACC1A_lin,Acc1aZbias);
  else if (header.filetype == GetFileType("ipACC1BF"))  
    DumpACC1BF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipGNV1AF"))  
    DumpGNV1AF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipGNV1BF"))  
    DumpGNV1BF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipKBR1BF"))  
    DumpKBR1BF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipSCA1AF"))  
    DumpSCA1AF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipSCA1BF"))  
    DumpSCA1BF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipPCI1AF"))  
    DumpPCI1AF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipXXXVOF"))  
    DumpXXXVOF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipIOA1BF"))  
    DumpIOA1BF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipOSCFQF"))  
    DumpOSCFQF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipMAG1XF"))  
    DumpMAG1XF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipHRT1XF"))  
    DumpHRT1XF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipTHR1XF"))  
    DumpTHR1XF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipIHK1XF"))  
    DumpIHK1XF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipCLK1BF"))  
    DumpCLK1BF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipTNK1XF"))  
    DumpTNK1XF(src,dst,DumpNrec, PresTnk,TempTnk,RegTnk,AdapTnk,TempRedTnk);
  else if (header.filetype == GetFileType("ipMAS1XF"))  
    DumpMAS1XF(src,dst,DumpNrec,MassTnk,MassThr);
  else if (header.filetype == GetFileType("ipILG1XF"))  
    DumpILG1XF(src,dst,DumpNrec);
  else if (header.filetype == GetFileType("ipTIM1XF"))  
    DumpTIM1XF(src,dst,DumpNrec);
  else  
  {  
    GetFileTypeName(header.filetype,FileTypeName);
    if (strcmp(FileTypeName,"NOT_DEFINED") != 0)
    {
      fprintf(stderr,"File Type %s can not be converted into ascii format!!\n\n",
                      FileTypeName);
    }
    else
    {
      fprintf(stderr," FileTypePointer = %d is not defined or filetype pointer refers to Level1A data!!\n",  
                       header.filetype);  
      fprintf(stderr," Check Header of input File!\n\n");  
      exit(1);  
    }
  }

  if (DumpNrec != DUMPALL)
  {
    sprintf(NobsChar,"%d",DumpNrec);
    ModifyFileHeader(&header,GetHeaderLabel("iphNumberObs"), NobsChar);
  }
  GetUTCTimeTag(TimeTag);
  strcat(TimeTag," by ");
  strcat(TimeTag,getenv("LOGNAME"));

  sprintf(NrBytes,"%d",ftell(dst));

  ModifyFileHeader(&header,GetHeaderLabel("iphNumberBytes")           , NrBytes);

  if (ShowHeader != 0 && dst != stdout) WriteFileHeader(dst,&header);

  fclose(src);
  fclose(dst);

  exit(0);

}
Exemplo n.º 29
0
/*--------------------------------------------------------------------------*/
int get_logflags_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], char ** logFlags)
{
    int kopt = 0;
    int* piAddr = NULL;

    int iLog = 0;
    char* pstLog = NULL;
    if (pos < FirstOpt(_pvCtx)) //input argument  */
    {
        //no idea of the real goal of this, how input var can have type == 0 Oo
        if (getInputArgumentType(_pvCtx, pos) == 0)
        {
            *logFlags = getDefLogFlags();
            return 1;
        }

        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
    }
    else if ((kopt = FindOpt(_pvCtx, "logflag", opts)) >= 0)//optional argument
    {
        piAddr = opts[kopt].piAddr;
    }
    else
    {
        //take default value
        *logFlags = getDefLogFlags();
        return 1;
    }

    getAllocatedSingleString(_pvCtx, piAddr, &pstLog);
    iLog = (int)strlen(pstLog);
    if (iLog != 2 && iLog != 3)
    {
        Scierror(999, "%s: Wrong size for input argument #%d: %d or %d expected\n", fname, pos, 2, 3);
        return 0;
    }

    if (iLog == 2)
    {
        if ((pstLog[0] != 'l' && pstLog[0] != 'n') || (pstLog[1] != 'l' && pstLog[1] != 'n'))
        {
            //Err = pos;
            SciError(116);
            return 0;
        }

        logFlagsCpy[0] = 'g';
        logFlagsCpy[1] = pstLog[0];
        logFlagsCpy[2] = pstLog[1];
        *logFlags = logFlagsCpy;
    }
    else //iLog == 3
    {
        if (((pstLog[0] != 'g') && (pstLog[0] != 'e') && (pstLog[0] != 'o')) ||
                (pstLog[1] != 'l' && pstLog[1] != 'n') ||
                (pstLog[2] != 'l' && pstLog[2] != 'n'))
        {
            //Err = pos;
            SciError(116);
            return 0;
        }

        *logFlags = pstLog;
    }

    return 1;
}
Exemplo n.º 30
0
/*--------------------------------------------------------------------------*/
int get_style_arg(void* _pvCtx, char *fname, int pos, int n1, rhs_opts opts[], int ** style)
{
    int m = 0, n = 0, first_opt = FirstOpt(_pvCtx), kopt = 0, un = 1, ix = 0, i = 0, l1 = 0;

    if ( pos < first_opt ) /* regular argument  */
    {
        int* piAddr = 0;
        int iType = 0;
        int* piData = NULL;
        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
        getVarType(_pvCtx, piAddr, &iType);

        if (iType)
        {
            getMatrixOfDoubleAsInteger(_pvCtx, piAddr, &m, &n, &piData);
            if (m * n < n1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: %d < %d expected.\n"), fname, pos, m * n, n1);
                return 0;
            }

            if ( n1 == 1 && m * n == 1 )
            {
                *style = (int*)MALLOC(2 * sizeof(int));
                (*style)[0] = piData[0];
                (*style)[1] = 1;
            }
            else
            {
                *style = (int*)MALLOC(m * n * sizeof(int));
                for (i = 0; i < m * n; i++)
                {
                    (*style)[i] = piData[i];
                }
            }
        }
        else /* zero type argument --> default value */
        {
            ix = Max(n1, 2);
            *style = (int*)MALLOC(ix * sizeof(int));
            (*style)[1] = 1;

            for ( i = 0 ; i < n1 ; ++i )
            {
                (*style)[i] = i + 1;
            }
        }
    }
    else if ((kopt = FindOpt(_pvCtx, "style", opts)) >= 0)
    {
        /* optinal argument: style=value */
        int* piData = NULL;

        getMatrixOfDoubleAsInteger(_pvCtx, opts[kopt].piAddr, &m, &n, &piData);
        if (m * n < n1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: %d < %d expected.\n"), fname, kopt, m * n, n1);
            return 0;
        }

        if (n1 == 1 && m * n == 1)
        {
            *style = (int*)MALLOC(2 * sizeof(int));
            (*style)[0] = piData[0];
            (*style)[1] = 1;
        }
        else
        {
            *style = (int*)MALLOC(m * n * sizeof(int));
            for (i = 0; i < m * n; i++)
            {
                (*style)[i] = piData[i];
            }
        }
    }
    else /* unspecified argument --> default value */
    {
        ix = Max(n1, 2);
        *style = (int*)MALLOC(ix * sizeof(int));
        (*style)[1] = 1;

        for (i = 0 ; i < n1 ; ++i)
        {
            (*style)[i] = i + 1;
        }
    }

    return 1;
}