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().

00017       {
00018   const char *stype = "unknown";
00019   if      (  isfp && elemsize==8 ) stype = "double";
00020   else if (  isfp && elemsize==4 ) stype = "float";
00021   else if ( !isfp && elemsize==8 ) stype = "int64";
00022   else if ( !isfp && elemsize==4 ) stype = "int32";
00023   else if ( !isfp && elemsize==2 ) stype = "int16";
00024   else if ( !isfp && elemsize==1 ) stype = "int8";
00025   printf("Writing %s array of length %d to binary file %s\n",
00026       stype, length, filename);
00027   FILE *fp = fopen(filename, "wb");
00028   if ( fp == 0 ) return -1;
00029   char padbuf[LABEL_SIZE] = { 0 };
00030   strncpy(padbuf, label, LABEL_SIZE-1);
00031   fwrite(padbuf, 1, LABEL_SIZE, fp);
00032   fwrite(&isfp, sizeof(int), 1, fp);
00033   fwrite(&elemsize, sizeof(int), 1, fp);
00034   fwrite(&length, sizeof(int), 1, fp);
00035   fwrite(array, elemsize, length, fp);
00036   fclose(fp);
00037   fflush(stdout);
00038   return 0;
00039 }


Variable Documentation

const int LABEL_SIZE = 116 [static]

Definition at line 8 of file TestArray.C.

Referenced by TestArray_write_helper().


Generated on 21 Sep 2020 for NAMD by  doxygen 1.6.1