h5_private.h 2.5 KB
Newer Older
1
/*
2
  Copyright (c) 2006-2016, The Regents of the University of California,
3 4 5 6 7 8 9 10 11 12 13 14 15
  through Lawrence Berkeley National Laboratory (subject to receipt of any
  required approvals from the U.S. Dept. of Energy) and the Paul Scherrer
  Institut (Switzerland).  All rights reserved.

  License: see file COPYING in top level of source distribution.
*/

#ifndef __FORTRAN_H5_PRIVATE_H
#define __FORTRAN_H5_PRIVATE_H

#include <stdlib.h>
#include <string.h>

16
#include "h5core/h5_types.h"
17

gsell's avatar
gsell committed
18 19 20 21 22 23 24 25 26 27 28 29
#if defined(FC_MANGLING_LOWERCASE_NO_UNDERSCORE)
#    define FC_MANGLING(a,b) a
#elif defined(FC_MANGLING_LOWERCASE_SINGLE_UNDERSCORE)
#    define FC_MANGLING(a,b) a ## _
#elif defined(FC_MANGLING_LOWERCASE_DOUBLE_UNDERSCORE)
#    define FC_MANGLING(a,b) a ## __
#elif defined(FC_MANGLING_UPPERCASE_NO_UNDERSCORE)
#    define FC_MANGLING(a,b) b
#elif defined(FC_MANGLING_UPPERCASE_SINGLE_UNDERSCORE)
#    define FC_MANGLING(a,b) b ## _
#elif defined(FC_MANGLING_UPPERCASE_DOUBLE_UNDERSCORE)
#    define FC_MANGLING(a,b) b ## __
30
#else
gsell's avatar
gsell committed
31
#  error "Unknown Fortran symbol mangling"
32 33
#endif

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#define convert_type2for(type)				    \
        if (*type == H5_STRING) {			    \
                *type = 1;				    \
        } else if (*type == H5_INT16) {			    \
                *type = 2;				    \
        } else if (*type == H5_INT32) {			    \
                *type = 3;				    \
        } else if (*type == H5_INT64) {			    \
                *type = 4;				    \
        } else if (*type == H5_FLOAT32) {		    \
                *type = 5;				    \
        } else if (*type == H5_FLOAT64) {		    \
                *type = 6;				    \
        } else {					    \
                H5_API_LEAVE (				    \
                        h5_error (			    \
                                H5_ERR_H5,		    \
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
                                "Unknown attribute type")); \
        }

static inline char*
h5_strdupfor2c (
	const char* s,
	const ssize_t len
	) {
        // :FIXME: error handling
	char* dup = (char*)malloc (len + 1);
	strncpy (dup, s, len);
	dup[len] = '\0';
	for (int i = len-1; i >= 0; i--) {
		if (dup[i] == ' ') dup[i] = '\0';
		else break;
	}
	return dup;
}

static inline char*
h5_strc2for (
	char* const str,
	const ssize_t l_str
	) {
	size_t len = strlen (str);
	memset (str+len, ' ', l_str-len);

	return str;
}

static inline h5_file_t
h5_filehandlefor2c (
	const h5_int64_t* ptr
	) {
	return (h5_file_t)*ptr;
}
gsell's avatar
gsell committed
87 88 89 90 91 92 93 94 95 96 97

static inline
int strlenf (
        const char* s,
        int len
        ) {
        if (len == 0) return 0;
        while (s[--len] == ' ');
        return ++len;
}

98
#endif