#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>

//#define YSIZE 
//#define XSIZE 
//#define ZSIZE 8
#define CONCURRENT_THREADS 15680
#define LOOKUP_GAP 2
#define Coord(x,y,z) ((ulong)z*(y ## SIZE)*(x ## SIZE)+y*(x ## SIZE)+x)
#define CO Coord(z,x,y)

int main(int argc, char **argv){
	const uint32_t nfact = 1024;
	const uint32_t zSIZE = 8;
	const uint32_t bufsize = (nfact/LOOKUP_GAP)*zSIZE;
    const uint32_t ySIZE = (nfact/LOOKUP_GAP+(nfact%LOOKUP_GAP>0));
    const uint32_t xSIZE = CONCURRENT_THREADS;
	//uint32_t buf[bufsize];
	uint32_t num1 = 0;
	uint32_t x, y, z;
    uint64_t idx[bufsize];

	x = 0;

	char *filename = "test.txt";
	FILE* fp;
    //for(uint y=0; y<(nfact/LOOKUP_GAP); ++y){
    //    for(uint z=0; z<zSIZE; ++z)
    //        idx[] = z + x*threads + y*(nfactdivlg+(nfactormodlg>0))*threads;
    //}

    for(y=0; y<(nfact/LOOKUP_GAP); ++y){
        for(z=0; z<zSIZE; ++z){
			idx[((y*zSIZE)+z)] = CO;
            //idx[((y<<z)+z)] = z+x*CONCURRENT_THREADS+y*(nfact/LOOKUP_GAP+(nfact%LOOKUP_GAP>0))*CONCURRENT_THREADS;
            //buf[] = X[z];
        }
	}

        if( (fp = fopen(filename, "w")) ){
 
			fprintf(fp, "idx[%u] = {\n", bufsize);
           for(num1=0; num1<(bufsize-1); num1++){
				if(num1%20 == 0){
					fprintf(fp, "\t\t");
					//fprintf(fp, "\n");
					fprintf(fp, "%llu, ", (unsigned long long)idx[num1]);
				}else
					fprintf(fp, "%llu, ", (unsigned long long)idx[num1]);
                //fprintf(fp, "%d\n", PLevels->aLevels[perf_id].iMemoryClock);
                //fprintf(fp, "%d\n", PLevels->aLevels[perf_id].iVddc);
            }
			fprintf(fp, "%llu\n", (unsigned long long)idx[num1]);
			fprintf(fp, "};\n", bufsize);
        }else{
            printf("Error opening file!\n");
        }
        //g_free(filename);
        fclose(fp);


	return 0;
}