Client examples

Simple cpp example showing how to get the header information and the raw image data from a saved binary file.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main () {
  FILE * pFile;
  float temperature;
  int result;  
  long slength;
  long plength;
  long exposure_time;
  unsigned short *data;
  char *comment;

  pFile = fopen ( "bild1217326639-515160.bin" , "rb" );
  if (pFile==NULL) {fputs ("File error",stderr); exit (1);}

  cout << "sizeof(float) " << sizeof(float) << endl;
  cout << "sizeof(long) " << sizeof(long) << endl;
  cout << "sizeof(unsigned short) " << sizeof(unsigned short) << endl;

  result = fread (&temperature,sizeof(float),1,pFile);
  cout << "Temperature : " << temperature << endl;
 
  result = fread (&slength,sizeof(long),1,pFile);
  cout << "sLength : " << slength << endl;

  result = fread (&plength,sizeof(long),1,pFile);
  cout << "pLength : " << plength << endl;

  result = fread (&exposure_time,sizeof(long),1,pFile);
  cout << "Exposure Time : " << exposure_time << endl;

  comment = (char*) malloc(sizeof(char)*200);
  result = fread (comment,sizeof(char),200,pFile);
  cout << "Comment : " << comment << endl;

  data = (unsigned short *) malloc(sizeof(unsigned short)*slength*plength);

  result = fread(data,sizeof(unsigned short),slength*plength,pFile);

  cout << " data[2] " << data[20] << " data[21] " << data[21] << " data[22] " << data[22] << endl;

  fclose(pFile);

  return 0;
}