コード例 #1
0
ファイル: taeutil.c プロジェクト: E-LLP/VICAR
FUNCTION CODE rrange
(
 TEXT	string[],		/* integer range string		*/
 TAEFLOAT	*rlow,			/* out: lower value		*/
 TAEFLOAT	*rhigh			/* out: high value		*/
 )
    {
    COUNT	i;
    TEXT	lstring[STRINGSIZ+1];
    TAEFLOAT	rtemp;


    *rlow = *rhigh = 0;			/* init incase error		*/
    s_copy(string, lstring);		/* local copy			*/
    i = s_index(string, ':');
    if (i < 0)				/* if no colon present		*/
	{
	if (s_s2r(lstring, rlow) != SUCCESS) return (FAIL);
	*rhigh = *rlow;
	}
    else
        {
        if (s_s2r(&(lstring[i+1]), rhigh) != SUCCESS) return (FAIL);
        lstring[i] = EOS;		/* terminate at colon		*/
        if (s_s2r(lstring, rlow) != SUCCESS) return(FAIL);
	if (*rlow > *rhigh)		/* reverse if out of order	*/
	    {
	    rtemp = *rlow;
	    *rlow = *rhigh;
	    *rhigh = rtemp;
	    }
        }
    return (SUCCESS);
    }
コード例 #2
0
ファイル: NPLCM_CR_Basic_Freq.cpp プロジェクト: cran/LCMCR
void CNPLCM_CR_Basic_Freq::permute_latent_classes_by_nu(){
	//reorder latent classes increasingly according to nuK. 
	std::vector<int> new2old(par->K), old2new(par->K);
	std::vector<_CNPLCM_CR_Basic_Freq_mypair> s_index(par->K);
	for (int k = 0; k < par->K; k++){
		s_index[k].first = 1.0 - par->nuK[k];
		s_index[k].second = k;
	}
	std::sort(s_index.begin(), s_index.end(), _CNPLCM_CR_Basic_Freq_comparator);
	std::vector<int> perm(K);
	for (int k = 0; k < par->K; k++){
		new2old[k] = s_index[k].second;
	} // new2old[a] == b <=> former b-th element is now a-th element.
	for (int k = 0; k < par->K; k++){
		old2new[ new2old[k] ] = k;
	}
	CParams_NPLCM_CR_Basic_Freq *tmp = new CParams_NPLCM_CR_Basic_Freq(*par);
	//for (int i = 0; i < par->n; i++){
	//	tmp->zI[i] = old2new[ par->zI[i] ];
	//}
	for (int m = 0; m < par->M; m++){
		for (int k = 0; k < par->K; k++){
			tmp->count_zIK[m][k] = par->count_zIK[m][ new2old[k] ];
		}
	}	
	for (int j = 0; j < par->J; j++){
		for (int k = 0; k < par->K; k++){
			tmp->lambdaJK[j][k] = par->lambdaJK[j][ new2old[k] ];
			tmp->aux_JK2[j][k][0] = par->aux_JK2[j][ new2old[k] ][0];
			tmp->aux_JK2[j][k][1] = par->aux_JK2[j][ new2old[k] ][1];
		}
	}
	for (int k = 0; k < par->K; k++){
		tmp->nuK[k] = par->nuK[new2old[k]];
		tmp->log_nuK[k] = par->log_nuK[new2old[k]];
		tmp->countK[k] = par->countK[new2old[k]];
		tmp->count0K[k] = par->count0K[new2old[k]];
	}
	//std::copy(tmp->zI, tmp->zI + par->n, par->zI);
	std::copy(tmp->count_zIK[0], tmp->count_zIK[0] + par->M * par->J, par->count_zIK[0]);
	std::copy(tmp->lambdaJK[0], tmp->lambdaJK[0] + par->J * par->K, par->lambdaJK[0]);
	std::copy(tmp->aux_JK2[0][0], tmp->aux_JK2[0][0] + par->J * par->K * 2, par->aux_JK2[0][0]);
	std::copy(tmp->nuK, tmp->nuK + par->K, par->nuK);
	std::copy(tmp->log_nuK, tmp->log_nuK + par->K, par->log_nuK);
	std::copy(tmp->countK, tmp->countK + par->K, par->countK);
	std::copy(tmp->count0K, tmp->count0K + par->K, par->count0K);
	delete tmp;
}
コード例 #3
0
bool ParserColumnAndIndexDeclaraion::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
    ParserKeyword s_index("INDEX");

    ParserIndexDeclaration index_p;
    ParserColumnDeclaration column_p;

    ASTPtr new_node = nullptr;

    if (s_index.ignore(pos, expected))
    {
        if (!index_p.parse(pos, new_node, expected))
            return false;
    }
    else
    {
        if (!column_p.parse(pos, new_node, expected))
            return false;
    }

    node = new_node;
    return true;
}
コード例 #4
0
ファイル: xco.c プロジェクト: E-LLP/VICAR
/*	Co_FindIt.   Find object by name.  Same as Co_Find, except returns
 *			collection type as well. Inheritance would have been
 *			nice here!
 *
 *	This handles composite names, i.e. when a collection is
 *	a collection of collections.
 *
 *	For example, if given "A.B", Co_Find
 *	would find the the collection object "A" and then find the 
 *	object "B" within "A".   If somewhere along the line,
 *	the object type is C_VM, then we call Vm_Find to
 *	find the rest of the name.
 *
 */

struct OBJECT_INFO	/* for comm to callback function thru Co_ForEach  */
    {
    CODE	type;			/* output of searchIt*/
    TEXT	*name;			/* input to searchIt*/
    BOOL	first;		 	/* input to searchIt*/
    };

#define C_COLLECTION  0xcccc     /* type of collect object */
#define C_VM          0xaaaa     /* type of Vm object      */
    UNSUPPORTED Id Co_FindIt
    (
     Id			colid,		/* in: collection id	*/
     TEXT		name[],		/* in: name to find	*/
    CODE		*type		/* out: type of collection */
     )
    {
    TEXT		loc_name[STRINGSIZ+1];    
    Id			object;
    struct OBJECT_INFO	objectInfo;		/* context block	*/
    COUNT		period;
    
    s_bcopy (name, loc_name, STRINGSIZ);	/* local copy 		*/
    period = s_index (loc_name, '.');		/* composite name?	*/
    if (period >= 0)
	loc_name[period] = EOS;			/* clip at first name   */
    objectInfo.name = loc_name;
    object = (Id) Co_ForEach ((struct COLLECTION*) colid, searchIt, 
			      (GENPTR) &objectInfo); 	
    *type = objectInfo.type;
    if (period < 0 || object == NULL)  		/* if simple name...	*/
	return (object);			/* finished		*/
    if (objectInfo.type == C_VM)
         return ((Id)Vm_Find (object, &loc_name[period+1]));
    else if (objectInfo.type == C_COLLECTION) {
	  // This is actually *broken* on 64-bit systems, a 32 bit
	  // integer can't be cast to a 64 bit pointer. Leave this
	  // in place to get a clean compile, but trigger an error
	  // if this is actually called.

	  printf("Calling a broken function. This can't be fixed on a 64 bit system");
	  abort();
//         return (Co_FindIt (object, &loc_name[period+1], *type));
    } else
         return (NULL);
    }
コード例 #5
0
ファイル: oldcoll.c プロジェクト: E-LLP/VICAR
    FUNCTION CODE old_Co_ReadFile (

    	Id 			c,		/* in: existing collection  */
        TEXT			*filespec,	/* in: name of file to read */
	CODE			mode		/* in: mode for the vm objs */
    )
    {
    struct SFILE	f;
    union {
          struct PARHDR	ph;			/* standard header          */	
	  TEXT		padding[300];		/* in case reading new file */
	  } headBuffer;
    CODE		code;
    COUNT		recsize;
    Id			vm;
    TEXT		record [STRINGSIZ+2];
    BOOL		archive;
    TEXT		fullSpec[STRINGSIZ+1];
    struct	FSBLOCK fsblock;		/* to dig out file name     */
    TEXT		errstr[STRINGSIZ+1];
    COUNT		islash;

#ifdef UNIX
    union 
        {
	TEXT record [STRINGSIZ+1];		/* padding for long records */
	struct ar_hdr header;			/* the real archive header  */
	} hdrRecord;
#endif


    code = f_opnspc (&f, 1, filespec, "", "", "res", F_READ);
    if (code != SUCCESS)
	{
        x_error(mode, "Unable to open resource file '%s'.  %s.", "TAE-PFOPN",
	    (uintptr_t)filespec, (uintptr_t)f.errmsg, 0);
        return (FAIL);	
	}

    /*	determine whether file is concatenated or archive format */
    code = f_read (&f, record);
    if (code == SUCCESS  &&  s_equal (record, AR_SENTINEL)) 
	archive = TRUE;
    else
	{
	archive = FALSE;	
	f_rewind (&f);				/* re-start at beginning  */
	}

    /*	read each Vm object from the file */

    while (FOREVER)
	{
	if (archive)					/* skip header 	    */
	    {
#ifdef UNIX
	    code = f_read (&f, (TEXT *)&hdrRecord);	/* read hdr or pad  */
	    if (code == SUCCESS  &&  hdrRecord.record[0] == EOS)
		code = f_read (&f, (TEXT *)&hdrRecord);	/* skip EOF padding */
	    if (code == F_EOF)
	   	{
		code = SUCCESS;
		break;
		}
	    else if (code != SUCCESS)
		{
	        f_close(&f, F_KEEP);
	        x_error (mode, "File '%s' not correctly formatted.",
			 "TAE-RESFORMAT", (uintptr_t)filespec, 0, 0);
	        return (FAIL);
		}
#ifdef AIX
	    s_bcopy (hdrRecord.header._ar_name.ar_name, fullSpec,
                               sizeof(hdrRecord.header._ar_name.ar_name));
#else
	    s_bcopy (hdrRecord.header.ar_name, fullSpec, 
				sizeof(hdrRecord.header.ar_name));
#endif
	    s_strip (fullSpec);		/* remove trailing blanks */
	    islash = s_index (fullSpec, '/');		/*  HP (and others?)  */
	    if (islash >= 0)				/* term with slash    */
		fullSpec[islash] = EOS;			/* clip at slash      */
	    f_crack (fullSpec, "", "", "", &fsblock, errstr);     /* dig name */
#else
	    x_error (mode, "File '%s' not correctly formatted.",
			"TAE-RESFORMAT", filespec, 0, 0);
	    return (FAIL);
#endif
	    }
	code = f_bread (&f, (GENPTR)&headBuffer, sizeof (headBuffer), &recsize);
	if (code == F_EOF)
	    {
	    code = SUCCESS;			/* normal end-of-file	*/
	    break;
	    }
	else if (code == SUCCESS && 
		s_equal (headBuffer.ph.sentinel, "<<new par-file>>"))
	    {
	    f_close(&f, F_KEEP);
	    x_error(mode, "Resource file '%s' has already been converted.", 
		"TAE-VNEWFORMAT", (uintptr_t)filespec, 0, 0);
	    return (FAIL);
	    }
	else if(code != SUCCESS || !s_equal(headBuffer.ph.sentinel, P_SENTINEL))
            {
	    f_close(&f, F_KEEP);
	    x_error(mode, "Error reading resource file '%s'.  %s.", "TAE-PFRD",
		(uintptr_t)filespec, (uintptr_t)f.errmsg, 0);
	    return (FAIL);
            }
	vm = Vm_New (mode);			/* create new vm object   */
	code = Vm_ReadVm ((struct VM_STRUCT *)vm, &f); 		/* read parblk records    */
	if (code != SUCCESS)
	    break;				/* x_error already called */
	if (archive)
	    old_Co_Add ((struct COLLECTION *)c, vm, fsblock.name, C_VM);
	else	
	    old_Co_Add ((struct COLLECTION *)c, vm, headBuffer.ph.filename, C_VM);
	}    
    f_close (&f, F_KEEP);
    return (code);
    }