Dear People,
I have been struggling with the following problem for about a week allready, which spans several C and Java programs (i believe the problem is in the final C program however) which i will try to distill in readable segments below.
1. The true first input is a file containg a varying number of lines, where each line contains 2 floats seperated by a space.
2. The first program compresses and encodes this file using the following code:
Code:
/* mz values */
error=compress2(comp_buffer, &comp_length,(const Bytef*)data.mz ,(uLongf)length,Z_DEFAULT_COMPRESSION); /* compression */
if (error != Z_OK) {fprintf(stderr,"zlib error..exiting"); exit(EXIT_FAILURE);}
printf("Computational (m/z) length is %i\n",(int)comp_length); /* Length needed for uncompress later */
mz_binary=g_base64_encode (comp_buffer,comp_length); /* encoding */
mz_length=strlen(mz_binary);
printf("mz: %s\n",mz_binary);
printf("mz encoded length: %d\n",mz_length);
3. This data is entered in a DB and a subsequent Java program retrieves specific data yielding a file that has a XML-like formatting with <something>value</something>. Important aspect here is that the length of the computational_buffer is printed in the XML-like file like
Code:
<decoded mz length>value</decoded mz length>
.
4. The C program i am struggling with attempts to restore the original data and so far i have come up with the following code (yielding a segmentation fault):
Code:
sscanf(spectral_buffer,"<decoded mz length>%i</decoded length>\n",&(glycan+teller)->decoded_mz_length);
if (p_str=(char*)strstr(spectral_buffer,"<m/z>")) {
p_begin=p_str+5;
p_end=(char*)strstr(spectral_buffer,"</m/z>");
length=p_end-p_begin;
((glycan+teller)->mz)=(char*)malloc(sizeof(char)*MAX_SIZE1);
gchar *decoded_result; /* pointer to memory for result in decoding */
decoded_result=(char*)malloc(sizeof(char)*MAX_SIZE1); /* allocating memory to the result 'block' */
gsize decoded_mz_length; /* variable for result length in decoding */
strncpy(((glycan+teller)->mz),p_begin,length);
*((glycan+teller)->mz+length)='\0';
decoded_result = g_base64_decode((glycan+teller)->mz, &decoded_mz_length); /* decoding */
printf("length of decoded mz string is %i\n",decoded_mz_length);
guchar *uncompressed_result; /* pointer to memory for result of uncompress */
uncompressed_result=(char*)malloc(sizeof(char)*MAX_SIZE1); /* allocating memory to the result 'block' */
uncompress(uncompressed_result,((glycan+teller)->decoded_mz_length),decoded_result,decoded_mz_length); /* MAGIC */
printf("decoded & uncompressed string is %s\n",uncompressed_result);
}
The header for this program is:
Code:
#ifndef SPECTRAL_MATCHER
#define SPECTRAL_MATCHER
#define MAX_SIZE1 5120
#define MAX_SIZE2 512
char spectral_buffer[MAX_SIZE1];
/* structure to store spectral data GOES into header file */
typedef struct {
float prec;
int decoded_mz_length;
int decoded_int_length;
char* desc;
char* mz;
char* intensity;
} glycopeptide;
#endif
Could anyone point me to where i am going wrong? I think that i am giving the correct length of the uncompressed/decoded string to uncompress (printed the value in the first C program) but somehow, something goes wrong
Any help would be greatly appreciated.
Kind Regards,
Bas Jansen
(C-Newbie)