Ejemplo n.º 1
0
int main(int argc, const char * argv[]) //main takes in the argument count and argument vector
{

    int iNumChans=0;
    // extract nb of channels argument
    if (argc < 2) { //if there are less than two arguemtns (ie number of channels not provided) exit the program
        printf("\r\nUsage: %s <numChannels>\n", argv[0]); // numChannels?
        exit(EXIT_FAILURE);
    }
    
    if ((sscanf(argv[1], "%d", &iNumChans) !=1)|| (iNumChans<1) ) { //assigns iNumChans to argv1 ... || redundant?
        printf("Require number of channels as argument\n");
        exit(EXIT_FAILURE);
    }
    
    //allocate buffer for 1 sample
    int buffersize=sizeof(uint64_t)+iNumChans*sizeof(uint32_t);
    uint8_t* buffer=(uint8_t*)malloc(buffersize);
    if (buffer==NULL)
    {
        fprintf(stderr,"Not enough memory.");
        exit(EXIT_FAILURE);
    }
    
    
    // read stdin and output in stdout
    
    while (feof(stdin)==0)
    {
        size_t sizeread=fread(buffer,sizeof(uint8_t),buffersize,stdin);
        if (ferror(stdin))
        {
            fprintf(stderr,"Error reading.");
            exit(EXIT_FAILURE);
        }
        if (sizeread==buffersize)
        {
            process_timestamp(buffer);
            
        
        
        for (int k=0;k<iNumChans;k++)
        {
    
            fprintf(stdout,"\t%.4f", byte_array_to_float(buffer+sizeof(uint64_t)+k*sizeof(uint32_t)));
        }
            fprintf(stdout,"\r\n");
        }
        
    }
    
    free(buffer);
    
    return 0;
}
Ejemplo n.º 2
0
My402TransData * parse_file(char * str)
{
	// Data structure to store one line of file
	My402TransData * data;

	if(str[MAX_LINE_LENGTH] != '\0')
		print_error("one line in the file is too long");
	else
	{
		char type, timestamp[MAX_TIMESTAMP_LENGTH + 1];
		int amount;
		// status indicate which kind data currently read, 0:type; 1:timestamp; 2:amount; 3:description
		int i = 0;
		enum readStatus status = 0;

		while(str[i] != '\0')
		{
			switch(status)
			{
				case Type: // read type
					data = (My402TransData *)malloc(sizeof(My402TransData));
					if(!data)
						print_error("malloc space failed");
					i = process_type(str, i, &type);
					status++;
					data -> type = type;
					break;
				case Timestamp: // read timestamp
					i = process_timestamp(str, i, timestamp);
					status++;
					unsigned int time_value = atoi(timestamp);
					check_time(time_value);
					data -> timestamp = time_value;
					break;
				case Amount: // read amount
					i = process_amount(str, i, &amount);
					status++;
					data -> amount = amount;
					break;
				case Description: // read description
					i = process_description(str, i, data -> description);
					status++;
					break;
				default:
					print_error("parse file error");
					break;
			}
		}
	}
	return data;
}
Ejemplo n.º 3
0
static void
process_dense(OSMPBF__PrimitiveBlock *primitive_block, OSMPBF__DenseNodes *dense, struct maptool_osm *osm)
{
	int i,j=0,has_tags;
	long long id=0,lat=0,lon=0,changeset=0,timestamp=0;
	int user_sid=0,uid=0;

	if (!dense)
		return;

	for (i = 0 ; i < dense->n_id ; i++) {
		id+=dense->id[i];
		lat+=dense->lat[i];
		lon+=dense->lon[i];
		changeset+=dense->denseinfo->changeset[i];
		user_sid+=dense->denseinfo->user_sid[i];
		uid+=dense->denseinfo->uid[i];
		timestamp+=dense->denseinfo->timestamp[i];
		has_tags=dense->keys_vals && dense->keys_vals[j];
		osm_add_node(id, lat/latlon_scale,lon/latlon_scale);
#if 0
		printf("\t<node id=\"%Ld\" lat=\"%.7f\" lon=\"%.7f\" version=\"%d\" changeset=\"%Ld\"",id,lat/latlon_scale,lon/latlon_scale,dense->denseinfo->version[i],changeset);
		process_user(primitive_block, user_sid, uid, 0);
		process_timestamp(timestamp);
#endif
		if (has_tags) {
#if 0
			printf(">\n");
#endif
			while (dense->keys_vals[j]) {
				process_tag(primitive_block, dense->keys_vals[j], dense->keys_vals[j+1]);
				j+=2;
			}
#if 0
			printf("\t</node>\n");
		} else
			printf("/>\n");
#else
		}
#endif
		osm_end_node(osm);
		j++;
	}