Ejemplo n.º 1
0
main ()
{
    struct flock fl;
    unsigned offset;
    char buf[256];

    for (;;) {
	if (!fgets(buf, sizeof(buf), stdin)) {
	    fprintf(stderr, "__DATA__ not found\n");
	    exit(1);
	}
	if (!strcmp(buf, "__DATA__\n")) break;
    }

    for (;;) {
	if (!fgets(buf, sizeof(buf), stdin)) {
	    fprintf(stderr, "FLOCK_DEFS not found\n");
	    exit(1);
	}
	if (!strcmp(buf, "FLOCK_DEFS\n")) break;
	fputs(buf, stdout);
    }

    memset(&fl, 0, sizeof(fl));
    fl.l_type = F_WRLCK;
    fl.l_whence = SEEK_SET;
    fl.l_start = 0;
    fl.l_len = 0;
    fl.l_pid = 0;

    printf("our $_flock_init = \"");
    for (offset = 0; offset < sizeof(fl); ++offset) {
	printf("\\%o", ((unsigned char *)&fl)[offset]);
    }
    printf("\";\nour $_flock_pid_template = \"x%d", offsetof(struct flock, l_pid));
    if (sizeof(fl.l_pid) == 4) {
	printf("L");
    } else if (sizeof(fl.l_pid) == 2) {
	printf("S");
    } else if (sizeof(fl.l_pid) == 8) {
	printf("Q");
    } else {
	fprinf(stderr, "Unknown pid size\n");
	exit(1);
    }
    printf("\";\n");

    while (fgets(buf, sizeof(buf), stdin)) {
	fputs(buf, stdout);
    }
    exit(0);
}
Ejemplo n.º 2
0
long applyFilters(double *outputData, double *inputData, double *timeData, 
    long rows, FILTER_STAGE *filterStage, long filterStages)
{
    long stage, row, frequencies;
    double *realimagInput, *realimagOutput;
    double length, dfrequency, factor;
    realimagOutput = NULL;
    if (!(realimagInput = (double*)malloc(sizeof(*realimagInput)*(rows+2))) ||
        !(realimagOutput = (double*)malloc(sizeof(*realimagOutput)*(rows+2))) )
        SDDS_Bomb("allocation failure");

    /* input data is real and has "rows" rows */
    /* result is interleaved real and imaginary */
    realFFT2(realimagInput, inputData, rows, 0);
    frequencies = rows/2 + 1;

    /* length is the assumed length of the periodic signal, 
       which is one interval longer that the actual data entered */
    length = ((double)rows)*(timeData[rows-1]-timeData[0])/((double)rows-1.0);
    dfrequency = factor = 1.0/length;
    
    for (stage=0; stage<filterStages; stage++) {
        if (!applyFilterStage(realimagOutput, realimagInput, frequencies, dfrequency, filterStage+stage))
            return 0;
        SWAP_PTR(realimagOutput, realimagInput);
        }
    /* input is still interleaved real and imaginary. The flag
       INVERSE_FFT ensures that the array is interpreted correctly. */
    /* output is interleaved real and imaginary */
#if DEBUG
    for (row=0; row<rows; row++; row++) {
      fprinf(stdout,"Real: %f, Imag: %i\n", realimagInput[row], realimagInput[row+1]);
    }
    
#endif    
    realFFT2(realimagOutput, realimagInput, rows, INVERSE_FFT);

    for (row=0; row<rows; row++)
        outputData[row] = realimagOutput[row];

    free(realimagOutput);
    free(realimagInput);

    return 1;
    }
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	libusb_device **devs;
	libusb_context *context = NULL;
	
	size_t list;
	size_t i;
	int ret;

	ret = libusb_init(&context);

	if(ret < 0)
	{
		perror("libusb_init");
		exit(1);
	}

	list = libusb_get_device_list(context, &devs);

	if(list < 0)
	{
		fprinf(stderr, "Error in getting device list\n");
		libusb_free_device_list(devs,1);
		libusb_exit(context);
		exit(1);
	}

	printf("There are %d devices found", list);

	for(i = 0; i < list; i++)
	{
		print_devices(devs[i]);
	}
	
	libusb_free_device_list(devs, 1);
	libusb_exit(context);

	return 0;
}
Ejemplo n.º 4
0
int main()
{
    FILE *f=fopen("szavazatok.txt","r");

    int i=0;

    while (!feof(f))
    {
        fscanf(f,"%i",&t[i].kerulet);
        fscanf(f,"%i",&t[i].szavazat_szam);
        fscanf(f,"%s",t[i].jelolt[0]);
        fscanf(f,"%s",t[i].jelolt[1]);
        fscanf(f,"%s\r\n",t[i].part_nev);
        i+=1;
    }

    int c;

    for (c=0; c<i; c+=1)
        kiir(&t[c]);

    // 2. feladat
    printf("2. feladat:%i",i);

    // 3. feladat
    printf("Adj meg képviselõt!\r\n");
    char n_vez[100];
    char n_ker[100];
    printf("Vezeteknev:");
    scanf("%s",n_vez);
    printf("\r\nKeresztnev:");
    scanf("%s",n_ker);
    printf("\r\n");

    for (c=0; c<i; c+=1)
    {
        if (!strcmp(n_vez,t[c].jelolt[0]))
            if (!strcmp(n_ker,t[c].jelolt[1]))
            {
                printf("szavazatok szama:%i",t[c].szavazat_szam);
                break;
            }
    }

    if (c>=i)
        printf("Nincs");

    int ossz_szavazatok_szama=0;

    for (c=0; c<i; c+=1)
        ossz_szavazatok_szama +=  t[c].szavazat_szam;

    print("ossz_szavazatok_szama:%i\r\n",ossz_szavazatok_szama);
    print("reszveteli arany:%.2f%%\r\n",(ossz_szavazatok_szama*100.0)/12345.0);

    // 5. feladat
    int t_partok[5]= {0,0,0,0,0};

    // GYEP,HEP,TISZ,ZEP,FUG(-)

    for (c=0; c<i; c+=1)
    {
        if ( !strcmp(t[c].part_nev,"GYEP") )
            t_partok[0]+=t[c].szavazat_szam;
        if ( !strcmp(t[c].part_nev,"HEP") )
            t_partok[1]+=t[c].szavazat_szam;
        if ( !strcmp(t[c].part_nev,"TISZ") )
            t_partok[2]+=t[c].szavazat_szam;
        if ( !strcmp(t[c].part_nev,"ZEP") )
            t_partok[3]+=t[c].szavazat_szam;
        if ( !strcmp(t[c].part_nev,"-") )
            t_partok[4]+=t[c].szavazat_szam;
    }

    printf("GYEP%.2f:",(t_partok[0]*100.0)/ossz_szavazatok_szama);
    printf("HEP%.2f:",(t_partok[1]*100.0)/ossz_szavazatok_szama);
    printf("TISZ%.2f:",(t_partok[2]*100.0)/ossz_szavazatok_szama);
    printf("ZEP%.2f:",(t_partok[3]*100.0)/ossz_szavazatok_szama);
    printf("FUG%.2f:",(t_partok[4]*100.0)/ossz_szavazatok_szama);

    //6. feladat

    int tmp;

    int max_szav=t[0].szavazat_szam;

    for (c=1; c<i; c+=1)
        if (max_szav < t[c].szavazat_szam)
            max_szav=szavazat_szam;

    for (c=0; c<i; c+=1)
        if (t[c].szavazat_szam == max_szav )
            kiir(&t[c]);

    // 7. feladat
    int ker_max[8]= {0,0,0,0,0,0,0,0};

    for (c=0; c<i; c+=1)
        if ( ker_max[ t[c].kerulet-1] < t[c].szavazat_szam )
            ker_max[ t[c].kerulet-1] = t[c].szavazat_szam;
    /*    Jó megoldás, de nem teljesíti a kerület szerinti rendezettséget
        for (c=0; c<i; c+=1)
            if ( ker_max[t[c].kerulet-1] == t[c].szavazat_szam)
                kiir(&t[c]);
                */
    FILE *g=fopen("kepviselo.txt","w");

    int k;

    for (k=1; k<=8; k+=1)
        for (c=0; c<i; c+=1)
            if ( t[c].kerulet == k)
                if ( ker_max[k-1] == t[c].szavazat_szam)
                    if (!strcmp(t[c].part_nev,"-"))
                        fprinf(g,"%i %s %s fuggetlen", k, t[c].jelolt[0],t[c].jelolt[1]);
                    else
                        fprinf(g,"%i %s %s %s", k, t[c].jelolt[0],t[c].jelolt[1],t[c].part_nev);
    fclose(g);

    fclose(f);

    getch();
    return 0;
}