[PHP] Binary Data File reading
Hi there- Does anyone have any clue as to what may be causing this problem. I am trying to read from a binary data value that has temperature values stored in it in short integer format. So basically, for every 2 bytes of binary data, that value in short integer is the temperature value. I have written a simple C program to read in the values from the out.bin binary data file I have, and echo them back to the console: It prints out the correct values, here is the C program that I used: #include void main(void) { FILE *fin; short buffer[1]; int num_read; fin = fopen("out.bin","r"); num_read=1; while(num_read>0) { num_read = fread(buffer, sizeof(short), 1, fin); printf("%d,",buffer[0]); } fclose(fin); return(1); } I am trying to write a php file to do the exact same thing, except instead of printing out the values, I'm going to store them in an array. Anyways, the php script I've written looks like this: The output I get from the php script is complete garble(a whole bunch of 0's, some 1's, some random int values, etc. I know that PHP doesn't exactly have a short int type, i know that their integers are actually stored in the C LONG_INT type, which are 8 byte integers. Do you think that this may be affecting my script, and if it is, does anyone know of any workarounds? Your help would be greatly appreciated. Thanks in advance. ------- Chris Mattmann Science Data Management and Archiving [EMAIL PROTECTED] NASA-JPLPasadena, CA 91109-8099 Office: 300-324C Phone: 818-354-8810
[PHP] php unpack function
Hi there- I am using the PHP unpack function to take a binary formatted file with 10's of thousands of signed short integers stored in it, to take the file (which is in PHP STRING form) and extract the short integer values from it. The problem I am having is when reading all the documentation for the pack/unpack function, I have been unable to figure out a way to only take a small subset of the data. For instance, my file is basically just thousands of temperature values, taken 4 times a day, over a period of 20 years. Let's say I wanted to get a year's worth of temperatures, from the 10th year into the file (so I would need the 4x365x10) th temperature value from the file. How would I use the unpack function to just select the (4x365x10)th through the (4x365x10)+(4x365)th value (basically year 10's entire temperature range). I see in the documentation I can specify how many shorts to extract STARTING from the first one, how would I specify, or is it even possible to specify a different starting location to begin extraction from. I cannot write the string to a file, and then use fseek while reading the file back in to skip to a postion and unpack from there. The way that the application is structured, I have to begin my extraction at the point where I already have the file in terms of a binary encoded string. So if anyone has any suggestions, I would greatly appreciate it. Please reply back to my account here at work if you are posting a reply on the forum: Thanks for your time. --- Chris Mattmann Science Data Management and Archiving [EMAIL PROTECTED] NASA-JPLPasadena, CA 91109-8099 Office: 300-324C Phone: 818-354-8810