2
* ADIOS is freely available under the terms of the BSD license described
3
* in the COPYING file in the top level directory of this source distribution.
5
* Copyright (c) 2008 - 2009. UT-BATTELLE, LLC. All rights reserved.
11
#include "bp_utils.h" // error()
12
#include "adios_error.h" // err_no_memory
18
static int called_from_fortran = 0; // set to 1 when called from Fortran API
19
void futils_called_from_fortran_set(void) {called_from_fortran = 1;}
20
void futils_called_from_fortran_unset(void) {called_from_fortran = 0;}
21
int futils_is_called_from_fortran(void) {return called_from_fortran;}
23
/** Copy a C string into a Fortran CHARACTER array */
24
void futils_cstr_to_fstr(const char *cs, char *fs, int flen)
26
int clen = strlen(cs);
29
strncpy(fs, cs, clen); /* does not copy the '\0' */
30
memset(fs+clen, ' ', flen-clen); /* right pad with spaces the CHARACTER array */
33
/** Trim a Fortran string and allocate a C string and copy content to it and add '\0'
34
* Need to free() the string later.
36
char * futils_fstr_to_cstr(const char * fs, int flen)
40
while (clen > 0 && fs[clen-1] == ' ')
42
cs = (char*) malloc ((size_t) (clen + 1));
44
adios_error (err_no_memory, "ERROR: Cannot allocate %d bytes for a C string in ADIOS API", clen+1);
47
strncpy (cs, fs, clen);