feat/api #46
3 changed files with 46 additions and 29 deletions
|
@ -368,8 +368,7 @@
|
|||
float *f;
|
||||
} field;
|
||||
|
||||
span *aux;
|
||||
|
||||
// TODO: implement aux as queue
|
||||
uchar *uchar_aux;
|
||||
uint32 aux_pos;
|
||||
uint32 aux_len;
|
||||
|
|
|
@ -253,6 +253,16 @@ eas3_init_stream(uchar* memory, uint32 size, char instr)
|
|||
aux_pos += chunck_len; \
|
||||
}
|
||||
|
||||
#define aux_dequeue(aux, aux_pos, aux_len, chunck, chunck_len) \
|
||||
{ \
|
||||
if(aux_pos + chunck_len <= aux_len) { \
|
||||
memcpy(chunck, aux + aux_pos, chunck_len); \
|
||||
aux_pos += chunck_len; \
|
||||
} else { \
|
||||
fprintf(stderr, MEMERROR); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------------------------------------*\
|
||||
! FUNCTION NAME: void *test(void) !
|
||||
! -------------- !
|
||||
|
@ -442,16 +452,16 @@ eas3_free_data(eas3_data* data)
|
|||
{
|
||||
if(data)
|
||||
{
|
||||
if(data->aux)
|
||||
{
|
||||
free(data->aux->memory);
|
||||
data->aux->access = NULL;
|
||||
data->aux->position = 0;
|
||||
data->aux->size = 0;
|
||||
//if(data->aux)
|
||||
//{
|
||||
//free(data->aux->memory);
|
||||
//data->aux->access = NULL;
|
||||
//data->aux->position = 0;
|
||||
//data->aux->size = 0;
|
||||
// TODO: remove
|
||||
data->aux->L = 0;
|
||||
}
|
||||
free(data->aux);
|
||||
//data->aux->L = 0;
|
||||
//}
|
||||
//free(data->aux);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
@ -617,18 +627,6 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------*\
|
||||
! Allocate the auxiliary information packed stream. !
|
||||
\*--------------------------------------------------------*/
|
||||
data->aux = calloc(1, sizeof(span));
|
||||
if(!data->aux)
|
||||
{
|
||||
// memory allocation error
|
||||
fprintf(stderr, MEMERROR);
|
||||
free(buffer_char);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------*\
|
||||
! Initialize the stream for the auxiliary information mem- !
|
||||
! ory block. The initial size of the auxiliary memory !
|
||||
|
@ -949,13 +947,25 @@ write_eas3_header(FILE *const fp, eas3_data *const data)
|
|||
/*--------------------------------------------------------*\
|
||||
! Initialize the auxiliary information stream. !
|
||||
\*--------------------------------------------------------*/
|
||||
aux = eas3_init_stream(data->aux->memory, data->aux->size, 'd');
|
||||
aux = eas3_init_stream(data->uchar_aux, data->aux_len, 'd');
|
||||
|
||||
// Rewind aux
|
||||
data->aux_pos = 0;
|
||||
|
||||
/*--------------------------------------------------------*\
|
||||
! Get the standard parameters from the auxiliary informa- !
|
||||
! memory block and write them to the file stream. !
|
||||
\*--------------------------------------------------------*/
|
||||
params = (eas3_std_params*)eas3_get_chunck(aux, 176);
|
||||
params = calloc(1, sizeof(eas3_std_params));
|
||||
if(!params)
|
||||
{
|
||||
// memory allocation error
|
||||
fprintf(stderr, MEMERROR);
|
||||
free(params);
|
||||
return 1;
|
||||
}
|
||||
aux_dequeue(data->uchar_aux, data->aux_pos, data->aux_len,
|
||||
params, sizeof(eas3_std_params));
|
||||
|
||||
if(fwrite(params, sizeof(uint64), 22, fp) != 22)
|
||||
{
|
||||
|
@ -983,7 +993,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data)
|
|||
! the timestep array from the auxiliary information block !
|
||||
! and write it to the file stream. !
|
||||
\*--------------------------------------------------------*/
|
||||
buffer_char = eas3_get_chunck(aux, data->params.nts * sizeof(uint64));
|
||||
buffer_char = calloc(data->params.nts * sizeof(uint64), sizeof(uchar));
|
||||
if(!buffer_char)
|
||||
{
|
||||
// memory allocation error
|
||||
|
@ -991,6 +1001,8 @@ write_eas3_header(FILE *const fp, eas3_data *const data)
|
|||
free(buffer_char);
|
||||
return 1;
|
||||
}
|
||||
aux_dequeue(data->uchar_aux, data->aux_pos, data->aux_len,
|
||||
buffer_char, data->params.nts * sizeof(uint64));
|
||||
|
||||
if(fwrite(buffer_char, sizeof(uint64), data->params.nts, fp) != data->params.nts)
|
||||
{
|
||||
|
@ -1012,7 +1024,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data)
|
|||
! the timestep attribute array from the auxiliary informa- !
|
||||
! tion block and write it to the file stream. !
|
||||
\*--------------------------------------------------------*/
|
||||
buffer_char = eas3_get_chunck(aux, data->params.nts * ATTRLEN);
|
||||
buffer_char = calloc(data->params.nts * ATTRLEN, sizeof(uchar));
|
||||
if(!buffer_char)
|
||||
{
|
||||
// memory allocation error
|
||||
|
@ -1020,6 +1032,8 @@ write_eas3_header(FILE *const fp, eas3_data *const data)
|
|||
free(buffer_char);
|
||||
return 1;
|
||||
}
|
||||
aux_dequeue(data->uchar_aux, data->aux_pos, data->aux_len,
|
||||
buffer_char, data->params.nts * ATTRLEN);
|
||||
|
||||
if(fwrite(buffer_char, sizeof(uchar), data->params.nts * ATTRLEN, fp) != (data->params.nts * ATTRLEN))
|
||||
{
|
||||
|
@ -1076,7 +1090,7 @@ write_eas3_header(FILE *const fp, eas3_data *const data)
|
|||
! the remaining eas header bytes from the auxiliary infor- !
|
||||
! mation block and write it to the file stream. !
|
||||
\*--------------------------------------------------------*/
|
||||
buffer_char = eas3_get_chunck(aux, Lwrite);
|
||||
buffer_char = calloc(Lwrite, sizeof(uchar));
|
||||
if(!buffer_char)
|
||||
{
|
||||
// memory allocation error
|
||||
|
@ -1084,6 +1098,8 @@ write_eas3_header(FILE *const fp, eas3_data *const data)
|
|||
free(buffer_char);
|
||||
return 1;
|
||||
}
|
||||
aux_dequeue(data->uchar_aux, data->aux_pos, data->aux_len,
|
||||
buffer_char, Lwrite);
|
||||
|
||||
if(fwrite(buffer_char, sizeof(uchar), Lwrite, fp) != Lwrite)
|
||||
{
|
||||
|
|
|
@ -705,7 +705,9 @@ int main(int argc, char *argv[])
|
|||
// TODO: implement I/O of bwc file
|
||||
// TODO: bwc_header_info
|
||||
|
||||
//write_eas3(data, "output2.eas");
|
||||
write_eas3(data, "output.eas");
|
||||
data = read_eas3("output.eas");
|
||||
write_eas3(data, "output2.eas");
|
||||
|
||||
eas3_free_data(data);
|
||||
free(output);
|
||||
|
|
Loading…
Reference in a new issue