NAMD
Functions | Variables
TestArray.C File Reference
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include "TestArray.h"

Go to the source code of this file.

Functions

int TestArray_write_helper (const char *filename, const char *label, const void *array, int elemsize, int length, int isfp)
 

Variables

static const int LABEL_SIZE = 116
 

Function Documentation

int TestArray_write_helper ( const char *  filename,
const char *  label,
const void array,
int  elemsize,
int  length,
int  isfp 
)

Definition at line 10 of file TestArray.C.

References LABEL_SIZE.

Referenced by TestArray_write().

17  {
18  const char *stype = "unknown";
19  if ( isfp && elemsize==8 ) stype = "double";
20  else if ( isfp && elemsize==4 ) stype = "float";
21  else if ( !isfp && elemsize==8 ) stype = "int64";
22  else if ( !isfp && elemsize==4 ) stype = "int32";
23  else if ( !isfp && elemsize==2 ) stype = "int16";
24  else if ( !isfp && elemsize==1 ) stype = "int8";
25  printf("Writing %s array of length %d to binary file %s\n",
26  stype, length, filename);
27  FILE *fp = fopen(filename, "wb");
28  if ( fp == 0 ) return -1;
29  char padbuf[LABEL_SIZE] = { 0 };
30  strncpy(padbuf, label, LABEL_SIZE-1);
31  fwrite(padbuf, 1, LABEL_SIZE, fp);
32  fwrite(&isfp, sizeof(int), 1, fp);
33  fwrite(&elemsize, sizeof(int), 1, fp);
34  fwrite(&length, sizeof(int), 1, fp);
35  fwrite(array, elemsize, length, fp);
36  fclose(fp);
37  fflush(stdout);
38  return 0;
39 }
static const int LABEL_SIZE
Definition: TestArray.C:8

Variable Documentation

const int LABEL_SIZE = 116
static

Definition at line 8 of file TestArray.C.

Referenced by TestArray_write_helper().