2004-09-05 02:02:18 +04:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-09-05 02:02:18 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2005-02-23 04:58:01 +03:00
|
|
|
#include <stdio.h>
|
2004-09-05 02:02:18 +04:00
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "ompi/constants.h"
|
2005-07-04 04:13:44 +04:00
|
|
|
#include "opal/util/argv.h"
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "ompi/mpi/f77/strings.h"
|
2004-09-05 02:02:18 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* creates a C string from an F77 string
|
|
|
|
*/
|
|
|
|
int ompi_fortran_string_f2c(char *fstr, int len, char **cstr)
|
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Leading and trailing blanks are discarded. */
|
|
|
|
|
|
|
|
end = fstr + len - 1;
|
|
|
|
|
|
|
|
for (i = 0; (i < len) && (' ' == *fstr); ++i, ++fstr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= len) {
|
2005-05-18 19:54:24 +04:00
|
|
|
len = 0;
|
2004-09-05 02:02:18 +04:00
|
|
|
} else {
|
2005-05-18 19:54:24 +04:00
|
|
|
for (; (end > fstr) && (' ' == *end); --end) {
|
2004-09-05 02:02:18 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-05-18 19:54:24 +04:00
|
|
|
len = end - fstr + 1;
|
2004-09-05 02:02:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate space for the C string. */
|
|
|
|
|
|
|
|
if (NULL == (*cstr = malloc(len + 1))) {
|
2005-05-18 19:54:24 +04:00
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
2004-09-05 02:02:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy F77 string into C string and NULL terminate it. */
|
|
|
|
|
|
|
|
if (len > 0) {
|
2005-05-18 19:54:24 +04:00
|
|
|
strncpy(*cstr, fstr, len);
|
2004-09-05 02:02:18 +04:00
|
|
|
}
|
|
|
|
(*cstr)[len] = '\0';
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-08-24 23:11:39 +04:00
|
|
|
* Copy a C string into a Fortran string. Note that when Fortran
|
|
|
|
* copies strings, even if it operates on subsets of the strings, it
|
|
|
|
* is expected to zero out the rest of the string with spaces. Hence,
|
|
|
|
* when calling this function, the "len" parameter should be the
|
|
|
|
* compiler-passed length of the entire string, even if you're copying
|
|
|
|
* over less than the full string. Specifically:
|
|
|
|
*
|
|
|
|
* http://www.ibiblio.org/pub/languages/fortran/ch2-13.html
|
|
|
|
*
|
|
|
|
* "Whole operations 'using' only 'part' of it, e.g. assignment of a
|
|
|
|
* shorter string, or reading a shorter record, automatically pads the
|
|
|
|
* rest of the string with blanks."
|
2004-09-05 02:02:18 +04:00
|
|
|
*/
|
|
|
|
int ompi_fortran_string_c2f(char *cstr, char *fstr, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
strncpy(fstr, cstr, len);
|
|
|
|
for (i = strlen(cstr); i < len; ++i) {
|
2005-05-18 19:54:24 +04:00
|
|
|
fstr[i] = ' ';
|
2004-09-05 02:02:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* creates a C argument vector from an F77 array of strings
|
|
|
|
* (terminated by a blank string)
|
|
|
|
*/
|
|
|
|
int ompi_fortran_argv_f2c(char *array, int len, char ***argv)
|
|
|
|
{
|
|
|
|
int err, argc = 0;
|
|
|
|
char *cstr;
|
|
|
|
|
|
|
|
/* Fortran lines up strings in memory, each delimited by \0. So
|
|
|
|
just convert them until we hit an extra \0. */
|
|
|
|
|
|
|
|
*argv = NULL;
|
|
|
|
while (1) {
|
|
|
|
if (OMPI_SUCCESS != (err = ompi_fortran_string_f2c(array, len,
|
|
|
|
&cstr))) {
|
2005-07-04 04:13:44 +04:00
|
|
|
opal_argv_free(*argv);
|
2004-09-05 02:02:18 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('\0' == *cstr) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-07-04 04:13:44 +04:00
|
|
|
if (OMPI_SUCCESS != (err = opal_argv_append(&argc, argv, cstr))) {
|
|
|
|
opal_argv_free(*argv);
|
2004-09-05 02:02:18 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(cstr);
|
|
|
|
array += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
2004-09-09 23:42:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* creates a C argument vector from an F77 array of argvs. The
|
|
|
|
* returned array needs to be freed by the caller
|
|
|
|
*/
|
|
|
|
int ompi_fortran_multiple_argvs_f2c(int count, char *array, int len,
|
|
|
|
char ****argv)
|
|
|
|
{
|
|
|
|
char ***argv_array;
|
|
|
|
int i;
|
2004-09-16 23:54:13 +04:00
|
|
|
char *current_array = array;
|
2004-09-09 23:42:07 +04:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
argv_array = (char ***) malloc (count * sizeof(char **));
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
2005-05-18 19:54:24 +04:00
|
|
|
ret = ompi_fortran_argv_f2c(current_array, len, &argv_array[i]);
|
|
|
|
if (OMPI_SUCCESS != ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
current_array += len * i;
|
2004-09-09 23:42:07 +04:00
|
|
|
}
|
|
|
|
*argv = argv_array;
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|