Пример #1
0
uint8_t* hex2bin(const char* in)
{
    size_t len = strlen(in);
    uint8_t* out = malloc((len / 2) * sizeof(uint8_t));
    int i;
    for (i = 0; i < len; i += 2)
    {
        out[i / 2] = c2i(in[i]) * 16 + c2i(in[i + 1]);
    }
    return out;
}
Пример #2
0
/**
 * Calculates connections
 *
 * swcube convention for server ports is that ui<uip iff u is on port 0
 * and up is on port 1.
 */
tuple_t connection_swcube(long node, long port)
{
	tuple_t res;
	long * thing;
	long i,j,ujp,uj;
	if(node<switches) {
		//build server label from port number and switch label, then rank
		//it.  note that if we are connecting to ujp in jth dimension,
		//then port== get_port_to_server(u,j,ujp)
		j=get_j_from_port(port);
		uj=label[node][j];
		ujp=get_ujp_from_port(port,uj);
		thing=malloc((param_k+2)*sizeof(long));
		for(i=0; i<param_k; i++)
			thing[i]=label[node][i];
		//externalise this if we use it a lot later
		thing[i++]=j;
		thing[i]=ujp;
		if(uj<ujp)
			res.port=0;
		else { //change to canonical label
			res.port=1;
			thing[i]=uj;
			thing[j]=ujp;
		}
		res.node=c2i(thing,1);
	} else {
		unrank(&thing,node);//always unranks to (u,j,ujp), where u is the
		//server on port 0, so uj<ujp
		ujp=thing[param_k+1];
		j=thing[param_k];
		uj=thing[j];
		if(port==1) {
			thing[j]=ujp;
			thing[param_k+1]=uj;
		}
		res.node=c2i(thing,0);
		res.port=get_port_to_server(res.node,j,thing[param_k+1]);
	}
	free(thing);
	return res;
}
Пример #3
0
void* D2MatchTreeBase::basegeteq(char const* str)
{
  Node* node = root->next[0];
  for (int i = 0; str[i] && node; i++)
  {
    int chr = c2i(str[i]);
    if (chr < 0) continue;
    node = node->nexteq[chr];
  }
  return (node ? node + 1 : NULL);
}
Пример #4
0
void seq_fwritenib(FILE *fp, unsigned const char *s, uint32_t len)
{
	uint32_t i;

	i = NIB_SIG;
	ckfputc(i & 0xFF, fp); i >>= 8;
	ckfputc(i & 0xFF, fp); i >>= 8;
 	ckfputc(i & 0xFF, fp); i >>= 8;
	ckfputc(i & 0xFF, fp); i >>= 8;
	i = len;
	ckfputc(i & 0xFF, fp); i >>= 8;
	ckfputc(i & 0xFF, fp); i >>= 8;
 	ckfputc(i & 0xFF, fp); i >>= 8;
	ckfputc(i & 0xFF, fp); i >>= 8;

	for (i=0; i<len; ) {
		int        n  = c2i(s[i++]) << 4;
		if (i<len) n |= c2i(s[i++]) << 0;
		ckfputc(n, fp);
	}
}
Пример #5
0
DWORD get_fattime (void)
{
  union {
    struct {
      DWORD second       : 5;
      DWORD minute       : 6;
      DWORD hour         : 5;
      DWORD day_in_month : 5;
      DWORD month        : 4;
      DWORD year         : 7;
    };

    DWORD value;
  } timestamp;

  //------------- Date is compiled date-------------//
  char compile_date[] = __DATE__; // eg. "Sep 26 2013"
  char* p_ch;

  p_ch = strtok (compile_date, " ");
  timestamp.month = month2number(p_ch);

  p_ch = strtok (NULL, " ");
  timestamp.day_in_month = 10*c2i(p_ch[0])+ c2i(p_ch[1]);

  p_ch = strtok (NULL, " ");
  timestamp.year = 1000*c2i(p_ch[0]) + 100*c2i(p_ch[1]) + 10*c2i(p_ch[2]) + c2i(p_ch[3]) - 1980;

  //------------- Time each time this function call --> sec ++ -------------//
  static uint8_t sec = 0;
  static uint8_t min = 0;
  static uint8_t hour = 0;

  if (++sec >= 60)
  {
    sec = 0;
    if (++min >= 60)
    {
      min = 0;
      if (++hour >= 24)
      {
        hour = 0; // assume demo wont call this function more than 24*60*60 times
      }
    }
  }

  timestamp.hour   = hour;
  timestamp.minute = min;
  timestamp.second = sec;

  return timestamp.value;
}
Пример #6
0
void* D2MatchTreeBase::baseget(char const* str, bool matchOf, Pair<int, int>* info)
{
  int len = strlen(str);
  void* bestval = NULL;
  int bestpos = -1;
  int bestlen = 0;
  void* bestof = NULL;
  int bestofpos = -1;
  int bestoflen = 0;
  Node* node = root->next[0];
  for (int i = 0; i <= len; i++)
  {
    int chr = c2i(str[i]);
    if (chr < 0) continue;
    if (chr == 0 && node->len > bestlen)
    {
      bestval = node + 1;
      bestpos = i - node->len;
      bestlen = node->len;
    }
    if (matchOf && (!str[i] || !strncmp(str + i, " of ", 4)) && node->len > bestoflen)
    {
      bestof = node + 1;
      bestofpos = i - node->len;
      bestoflen = node->len;
    }
    node = node->next[chr];
  }
  if (bestof)
  {
    bestval = bestof;
    bestpos = bestofpos;
    bestlen = bestoflen;
  }
  if (info)
  {
    info->first = bestpos;
    if (bestpos >= 0) info->second = bestpos + bestlen;
  }
  return bestval;
}
Пример #7
0
void* D2MatchTreeBase::baseadd(char const* str)
{
  int len;
  int alen = 0;
  Node* node = root->next[0];
  for (len = 0; str[len]; len++)
  {
    int chr = c2i(str[len]);
    if (chr < 0) continue;
    alen++;
    if (node->next[chr] == NULL)
    {
      Node* temp = (Node*) pool.alloc();
      memset(temp, 0, sizeof(Node) + dataSize);
      temp->parent = node;
      temp->chr = chr;
      node->nexteq[chr] = node->next[chr] = temp;
    }
    node = node->next[chr];
  }
  node->len = alen;
  return node + 1;
}
Пример #8
0
asn1_error_code
k5_asn1_decode_generaltime(const unsigned char *asn1, size_t len,
                           time_t *time_out)
{
    const char *s = (char *)asn1;
    struct tm ts;
    time_t t;

    *time_out = 0;
    if (len != 15)
        return ASN1_BAD_LENGTH;
    /* Time encoding: YYYYMMDDhhmmssZ */
    if (s[14] != 'Z')
        return ASN1_BAD_FORMAT;
    if (memcmp(s, "19700101000000Z", 15) == 0) {
        *time_out = 0;
        return 0;
    }
#define c2i(c) ((c) - '0')
    ts.tm_year = 1000 * c2i(s[0]) + 100 * c2i(s[1]) + 10 * c2i(s[2]) +
                 c2i(s[3]) - 1900;
    ts.tm_mon = 10 * c2i(s[4]) + c2i(s[5]) - 1;
    ts.tm_mday = 10 * c2i(s[6]) + c2i(s[7]);
    ts.tm_hour = 10 * c2i(s[8]) + c2i(s[9]);
    ts.tm_min = 10 * c2i(s[10]) + c2i(s[11]);
    ts.tm_sec = 10 * c2i(s[12]) + c2i(s[13]);
    ts.tm_isdst = -1;
    t = krb5int_gmt_mktime(&ts);
    if (t == -1)
        return ASN1_BAD_TIMEFORMAT;
    *time_out = t;
    return 0;
}
Пример #9
0
char *persnr(char *orgbuf)
{
	/* Mottar peker til en buffer med plass til minst 12 tegn der de første 10 er fylt ut. Returnerer komplett nummer. {{{ */
	int x, y, j, k, qfunc = 0;
	static char buf[12];

	strncpy(buf, orgbuf, 11);

	x = c2i(buf[0])*3 + c2i(buf[1])*7 + c2i(buf[2])*6 + c2i(buf[3])*1 + \
	    c2i(buf[4])*8 + c2i(buf[5])*9 + c2i(buf[6])*4 + c2i(buf[7])*5 + \
	    c2i(buf[8])*2;
	j = 11 - x % 11;
	y = c2i(buf[0])*5 + c2i(buf[1])*4 + c2i(buf[2])*3 + c2i(buf[3])*2 + \
	    c2i(buf[4])*7 + c2i(buf[5])*6 + c2i(buf[6])*5 + c2i(buf[7])*4 + \
	    c2i(buf[8])*3 + j*2;
	k = 11 - y % 11;

	if (j == 10 || k == 10) { /* Hvis j eller k == 10 er nummeret falskt */
		strcpy(buf, ""); /* Returnerer tom streng hvis ulovlig */
		qfunc = 1;
	}

	if (!qfunc) {
		if (j == 11)
			j = 0;
		if (k == 11)
			k = 0;

		buf[9] = j + '0';
		buf[10] = k + '0';
		buf[11] = '\0';
	}

	return(buf);
	/* }}} */
} /* persnr() */
Пример #10
0
asn1_error_code asn1_decode_generaltime(asn1buf *buf, time_t *val)
{
    setup();
    char *s;
    struct tm ts;
    time_t t;

    tag(ASN1_GENERALTIME);

    if (length != 15) return ASN1_BAD_LENGTH;
    retval = asn1buf_remove_charstring(buf,15,&s);
    if (retval) return retval;
    /* Time encoding: YYYYMMDDhhmmssZ */
    if (s[14] != 'Z') {
        free(s);
        return ASN1_BAD_FORMAT;
    }
    if (s[0] == '1' && !memcmp("19700101000000Z", s, 15)) {
        t = 0;
        free(s);
        goto done;
    }
#define c2i(c) ((c)-'0')
    ts.tm_year = 1000*c2i(s[0]) + 100*c2i(s[1]) + 10*c2i(s[2]) + c2i(s[3])
        - 1900;
    ts.tm_mon = 10*c2i(s[4]) + c2i(s[5]) - 1;
    ts.tm_mday = 10*c2i(s[6]) + c2i(s[7]);
    ts.tm_hour = 10*c2i(s[8]) + c2i(s[9]);
    ts.tm_min = 10*c2i(s[10]) + c2i(s[11]);
    ts.tm_sec = 10*c2i(s[12]) + c2i(s[13]);
    ts.tm_isdst = -1;
    t = krb5int_gmt_mktime(&ts);
    free(s);

    if (t == -1) return ASN1_BAD_TIMEFORMAT;

done:
    *val = t;
    cleanup();
}
Пример #11
0
int main(int argc, char *argv[])
{
  meta_parameters *meta, *meta_old, *meta_stat;
	char fnm1[BUF],fnm2[BUF],fnm3[BUF],fnm4[BUF];
	char imgfile[BUF],metaFile[BUF],cmd[BUF],metaIn[BUF],metaOut[BUF];
	FILE *fiamp, *fiphase, *foamp, *fophase, *flas;
	int ll=0, ls=1;   /* look line and sample */
	int sl=STEPLINE, ss=STEPSAMPLE;   /* step line and sample */
	int i,line, sample;
	int row, col, ampFlag = 0;
	long long nitems, newitems, inWid, inLen, outWid, outLen;
	long long ds/*,samplesRead*/;       /* input data size, number of samples read so far.*/
	long long red_offset, grn_offset, blu_offset;
	register float *ampIn, *phaseIn, ampScale;
	float *ampOut, *phaseOut,*ampBuf,Sin[256],Cos[256];
	float avg, percent=5.0;
	RGBDATA *table, *imgData;
	Uchar *redPtr, *grnPtr, *bluPtr;
	complexFloat z;
	struct DDR newddr;
	register float tmp,zImag,zReal,ampI;
	register int index,offset;
	const float convers=256.0/(2*3.14159265358979);
   
	logflag = 0;

  /* parse command line */
  while (currArg < (argc-2)) {
    char *key = argv[currArg++];
    if (strmatch(key,"-log")) {
      CHECK_ARG(1);
      strcpy(logFile,GET_ARG(1));
      fLog = FOPEN(logFile, "a");
      logflag = 1;
    }
    else if (strmatch(key,"-look")) {
      CHECK_ARG(1);
      if (2!=sscanf(GET_ARG(1),"%dx%d",&ll,&ls)) {
        printf("   ***ERROR: -look '%s' does not look like line x sample (e.g. '10x2').\n",GET_ARG(1));
        usage(argv[0]);
      }
    }
    else if (strmatch(key,"-step")) {
      CHECK_ARG(1);
      if (2!=sscanf(GET_ARG(1),"%dx%d",&sl,&ss)) {
        printf("   ***ERROR: -step '%s' does not look like line x sample (e.g. '5x1').\n",GET_ARG(1));
        usage(argv[0]);
      }
    }
    else if (strmatch(key,"-meta")) {
      CHECK_ARG(1);
      if (1!=sscanf(GET_ARG(1),"%s",metaFile)) {
        printf("   ***ERROR: Could not open '%s'.\n",GET_ARG(1));
        usage(argv[0]);
      }
      strcat(metaFile, "");
      ls = ss = 1;
      ll = sl = lzInt(metaFile, "sar.look_count:", NULL);
    }
    else if (strmatch(key,"-amplitude")) {
      printf("   Will remove amplitude part of color image\n");
      ampFlag = 1;
    }
    else {printf("\n   ***Invalid option:  %s\n",argv[currArg-1]); usage(argv[0]);}
  }
  if ((argc-currArg) < 2) {printf("   Insufficient arguments.\n"); usage(argv[0]);}

	system("date");
	printf("Program: multilook\n\n");
	if (logflag) {
	  StartWatchLog(fLog);
	  printLog("Program: multilook\n\n");
	}

	/* Create filenames and open files for reading */
  	create_name(fnm1,argv[currArg],"_amp.img");
  	create_name(fnm2,argv[currArg],"_phase.img");
	meta_stat = meta_read(fnm1);
	meta_old = meta_read(fnm2);
	meta = meta_read(fnm2);
  	create_name(fnm3,argv[++currArg],"_amp.img");
  	create_name(fnm4,argv[currArg],"_phase.img");
  	create_name(imgfile,argv[currArg],"_rgb.img");
	create_name(metaOut,argv[currArg],"_rgb.meta");
 	
	inWid = meta->general->sample_count;
	inLen = meta->general->line_count;
  	meta->general->sample_count /= ss;
  	meta->general->line_count /= sl;
	outWid = meta->general->sample_count;
	outLen = meta->general->line_count;
  
	/* Create new metadata file for the amplitude and phase.*/
	meta->sar->line_increment = 1;
	meta->sar->sample_increment = 1;
	meta->sar->azimuth_time_per_pixel *= sl;
	meta->general->x_pixel_size *= ss;
	meta->general->y_pixel_size *= sl;
	create_name(metaIn,argv[currArg],"_amp.meta");
	meta_write(meta, metaIn);
	create_name(metaIn,argv[currArg],"_phase.meta");
	meta_write(meta, metaIn);

        meta2ddr(meta, &newddr);

	/* Create 3-band image's DDR.
	   Currently metadata file don't know anything about multiband imagery.
	   We will need to convert the current version for single band amplitude
	   image back to metadata version 0.9 and change a couple of values 
	sprintf(cmd, "convert_meta %s 1.3 %s 0.9", metaIn, metaOut);
	asfSystem(cmd);
        */
	
	newddr.dtype=EBYTE;
	newddr.nbands=3;
	c_putddr(imgfile,&newddr);
  
	fiamp = fopenImage(fnm1,"rb");
	fiphase = fopenImage(fnm2,"rb");
	foamp = fopenImage(fnm3,"wb");
	fophase = fopenImage(fnm4,"wb");
	flas = fopenImage(imgfile,"wb");

	/*
	* create data buffers 
	*/
	for (i=0;i<256;i++)
	{
		float phas=((float)i)/256.0*(2*3.14159265358979);
		Sin[i]=sin(phas);
		Cos[i]=cos(phas);
	}
  
	/* set data variables */
	ampScale = 1.0/(ll*ls);
	nitems   = (ll-sl)*inWid;
	newitems = sl*inWid;
  
	ds       = sizeof(float);
	ampIn    = (float *)MALLOC(ds*(newitems+nitems+ls));
	phaseIn  = (float *)MALLOC(ds*(newitems+nitems+ls));
	ampOut   = (float *)MALLOC(ds*outWid);
	ampBuf   = (float *)MALLOC(ds*outWid);
	phaseOut = (float *)MALLOC(ds*outWid);
	table    = (RGBDATA *)MALLOC(sizeof(RGBDATA)*MAXENTRIES);
	imgData  = (RGBDATA *)MALLOC(sizeof(RGBDATA)*outWid);
	redPtr   = (Uchar *)MALLOC(sizeof(Uchar)*outWid);
	grnPtr   = (Uchar *)MALLOC(sizeof(Uchar)*outWid);
	bluPtr   = (Uchar *)MALLOC(sizeof(Uchar)*outWid);
	
        /* calculate mean value */
        if (meta_stat->stats)
          avg = meta_stat->stats->band_stats[0].mean;
        else {
          sprintf(cmd, "stats -overmeta -overstat \"%s\"\n", fnm1);
          asfSystem(cmd);
          meta_free(meta_stat);
          meta_stat = meta_read(fnm1);
          avg = meta_stat->stats->band_stats[0].mean;
        }

	/* create a colortable to be used with c2i */
	colortable(table);
  
	/* start conversion */
/*	printf("   Skipping every %d col and %d row\n",ss,sl);
	printf("   Looking at every %d col and %d row\n",ls,ll);*/
  	printf("   Input is %lld lines by %lld samples\n",inLen,inWid);
	printf("   Ouput is %lld lines by %lld samples\n\n",outLen,outWid);
	if (logflag) {
  	  sprintf(logbuf, "   Input is %lld lines by %lld samples\n",inLen,inWid);
	  printLog(logbuf);
	  sprintf(logbuf, "   Ouput is %lld lines by %lld samples\n\n",outLen,outWid);
	  printLog(logbuf);
	}
 	
	/*
	* Run through all lines in which data needs to be read so that
	* amount of data will be equal to ll * inWid.
	*/
	for(line=0; line<outLen; line++)
	{

		/* Read in a ll*inWid size chunk */
		get_float_lines(fiamp, meta_old, line*sl, ll, ampIn);
		get_float_lines(fiphase, meta_old, line*sl, ll, phaseIn);

		/* begin adding data */
		for (sample=0; sample<outWid; sample++)
		{ 
			tmp = 0.0, zReal=0.0, zImag=0.0;
			/* add up looking area */
			for (col=0;col<ls;col++)
			{
				offset=sample*ss+col;
				for (row=0;row<ll;row++)
				{
					ampI=ampIn[offset];
					index=0xFF&((int)(phaseIn[offset]*convers));
					tmp += ampI * ampI;
					zReal += ampI * Cos[index];
					zImag += ampI * Sin[index];
					offset+=inWid;
 				}
			}
     
			/* get phase from complex values */
			z.real=zReal;
			z.imag=zImag;
			/* place in output buffer */
		/*	ampOut[sample] = sqrt(tmp*ampScale); */
			ampOut[sample] = Cabs(z)*ampScale; 
			phaseOut[sample] = Cphase(z);
			if(!ampFlag)
				ampBuf[sample]=ampOut[sample];
			else
				ampBuf[sample]=avg*1.5;		
		}
    
		/* convert amp & phase to RGB. */
		if (!c2i(ampBuf,phaseOut,imgData,table,outWid,avg))
			Exit("ml: Error in c2i()");

		/* write out data to file */
		put_float_line(foamp, meta, line, ampOut);
		put_float_line(fophase, meta, line, phaseOut);

		if ((line*100/outLen)>percent) {
			printf("   Completed %3.0f percent\n", percent);
			percent+=5.0;
		}
		
		for (i=0;i<outWid;i++)
		{
			redPtr[i] = imgData[i].red;
			grnPtr[i] = imgData[i].green;
			bluPtr[i] = imgData[i].blue;
		} 
		red_offset=(long long)(line*outWid);
		grn_offset=(long long)(line*outWid+outWid*outLen);
		blu_offset=(long long)(line*outWid+(2*outWid*outLen));

		FSEEK64(flas,red_offset,SEEK_SET);
		ASF_FWRITE(redPtr,1,outWid,flas);
		FSEEK64(flas,grn_offset,SEEK_SET);
		ASF_FWRITE(grnPtr,1,outWid,flas);
		FSEEK64(flas,blu_offset,SEEK_SET);
		ASF_FWRITE(bluPtr,1,outWid,flas);
    
		/* reposition data for next read */
		for (i=0;i<nitems;i++)
		{
			ampIn[i] = ampIn[i + newitems];
			phaseIn[i] = phaseIn[i + newitems];
		}
		
	}
  
	/* 
	* free up unneeded memory and prepare to write 
	* a 3 sequential band image
	*/
/*	printf("\n\tdone with multilook\n");
	printf("writing out LAS/RGB image file\n");*
	printf("   Completed 100 percent\n\n   Wrote %lld bytes of data\n\n", 
	       (long long)(outLen*outWid*4));
	if (logflag) {
	  sprintf(logbuf, "   Wrote %lld bytes of data\n\n", 
		  (long long)(outLen*outWid*4));
	  printLog(logbuf);
	  StopWatchLog(fLog);
	  FCLOSE(fLog);
	}
*/

	FREE(ampIn);
	FREE(phaseIn);
	FREE(ampOut);
        FREE(ampBuf);
	FREE(phaseOut);
	FREE(table);
	FCLOSE(fiamp);
	FCLOSE(fiphase);
	FCLOSE(foamp);
	FCLOSE(fophase);
  
	/* free all memory, close files, print out time elapsed */
	FREE(redPtr);
	FREE(grnPtr);
	FREE(bluPtr);
	FREE(imgData);
	FCLOSE(flas);

        meta_free(meta);
        meta_free(meta_stat);
        meta_free(meta_old);

	return 0;
}
Пример #12
0
_Bool isC_C(char c1, char c2) {
 int i1 = c2i(c1), i2 = c2i(c2);
 return i1 != -1 && i2 != -1 && consPairs[i1][i2] != srera;
}
Пример #13
0
_Bool isCC(char c1, char c2) {
 int i1 = c2i(c1), i2 = c2i(c2);
 return i1 != -1 && i2 != -1 && consPairs[i1][i2] == lidne;
}
Пример #14
0
int getsym()
{
    int  k;
    t = 0;
    while (isspace(ch))
        getch1();
    if(ch == EOF)
        return -1;
    if (isalpha(ch))
    {
        getch1();
        while (isalnum(ch))
        {
            getch1();
        }
        k = searchident();
        //	printf("%s %d\n",sym,k);
        if (k == 0)
            symtype = T_IDENT;
        else
            symtype = k;
    }
    else if (isdigit(ch))
    {
        num = c2i(ch);
        getch1();
        while (isdigit(ch))
        {
            num = num * 10 + c2i(ch);
            getch1();
        }
        symtype = T_CONST;
    }
    else if (ch =='\'')
    {
        getch1();
        num = ch;
        getch1();
        if (ch !='\'')// missing '
            my_error(1);
        getch1();
        symtype = T_CHAR;
    }
    else if (ch == '\"')
    {
        getch1();
        while(iss(ch))
            getch2();
        if(!(ch =='\"'))
            my_error(2);	// missing "
        symtype = T_STRING;
        getch1();
    }
    else if(ch == ':')
    {
        getch1();
        if(ch == '=')
        {
            symtype = BECOME;
            getch1();
        }
        else
            symtype = COLON;
    }
    else if (ch == '<')
    {
        getch1();
        if(ch == '>')
        {
            symtype = NEQ;
            getch1(); 
        }
        else if( ch =='=')
        {
            symtype = SMOE;
            getch1();
        }
        else
            symtype = SMO;
    }
    else if (ch == '>')
    {
        getch1();
        if(ch == '=')
        {
            symtype = BIGE;
            getch1();
        }
        else
            symtype = BIG;
    }
    else
    {
        symtype = symnumber[ch];
        getch1();
    }
    //	printf("%s\n",sym);
    return 0;
}
Пример #15
0
static void unrank(long **res, long i)
{
	long remainder,j;
	if(i<switches) {
		*res=malloc((param_k)*sizeof(long));
		remainder = i;
		for(j=0; j<param_k; j++) {
			(*res)[j] = remainder%param_n;
			remainder/=param_n;
		}
#ifdef SHOWLABELS
		printf("rank %ld switch: ",i);
		printarray(*res,param_k);
#endif
#ifdef DEBUG
		if(i != c2i(*res,0)) {
			printf("c2i not working for switch %ld.  outputs %ld\n",i,c2i(*res,0));
			printarray(*res,param_k);
		}
#endif
		return;
	} else {
		//label the servers with (k+2)-tuples.  for switches u, up which
		//are dimension r neighbours, the server x is labelled,
		//u,label[k],label[k+1], where label[k]=r, and label[k+1]=up[r]
		//note that in swcube, up,r,u[r] is the same server, but the
		//canonical label has u[r]<up[r]
		*res=malloc((param_k+2)*sizeof(long));
		remainder = i-switches;
		//swcube: k*(n choose 2) servers for each of n^(k-1) (k-1)-tuples in lex order:
		// for a given (k-1)-tuple, and dimensions in order from 0 to k we have pairs
		// (0,1), (0,2), ..., (0,n-1),(1,2),(1,3), ..., (1,n-1)

		//first find out which (k-1)-tuple it is

		//    (*res)[param_k+1] = remainder%(param_n-1);

		//this is an intermediate value for getting the K_n pair
		long tmp = remainder%(n_choose_2);
		remainder /= n_choose_2;
		//now we can discover dimension r of this server's edge
		(*res)[param_k] = remainder%(param_k);
		remainder /= param_k;
		//now remainder unranks to the (k-1)-tuple
		//(u[0],u[1],...,u[r-1],u[r+1], ..., u[k]) but we want the
		//switch's k-tuple after inserting either u[r] encoded in the K_n
		//pair.  It's easiest just to build the switch label again.
		for(j=0; j<(*res)[param_k]; j++) {
			(*res)[j] = remainder%param_n;
			remainder/=param_n;
		}
		//unrank the K_2 pair.  Note that
		//(*res)[j]=uj<ujp=(*res)[param_k+1]
		(*res)[j]=0;
		(*res)[param_k+1]=0;
		unrank_n_choose_2(&((*res)[j]),
		                  &((*res)[param_k+1]),
		                  tmp,param_n);
#ifdef DEBUG
		if((*res)[j]>=(*res)[param_k+1])
			printf("ERROR in unrank: (*res)[j]>=(*res)[param_k+1] for ((*res)[j],j,(*res)[param_k+1])=(%ld,%ld,%ld)\n",(*res)[j],j,(*res)[param_k+1]);
#endif
		j++;
		for(; j<param_k; j++) {
			(*res)[j] = remainder%param_n;
			remainder/=param_n;
			//      (*res)[j] = label[remainder][j];
		}
#ifdef SHOWLABELS
		printf("rank %ld server: ",i);
		printarray(*res,param_k+2);
		printf("server reranked as %ld\n",c2i(*res,1));
#endif
#ifdef DEBUG
		// check that this here "unrank" function is consistent with our
		// "rank" function, c2i
		if(i != c2i(*res,1)) {
			printf("c2i not working for server %ld. outputs %ld\n",i,c2i(*res,1));
			printarray(*res,param_k+2);
		}
#endif

	}
}