UNICOS utilities for FORTRAN/C character variable interaction

The FORTRAN CHARACTER variable descriptor holds three items of information about the variable:
  1. The word address
  2. The bit offset
  3. The bit length
The corresponding C character pointer has only the word address and bit length. There are some routines available in the UNICOS C library fortran.h that allow you to convert FORTRAN character variables to C character variables properly. If you use these routines, you will also need to use the data type _fcd (for fortran character descriptor).
_fcdtocp
Is a conversion utility that converts a FORTRAN character descriptor to a C character point.

_fcdlen
Extracts the length from a FORTRAN character descriptor.

_cptofcd
Converts a C character pointer to a FORTRAN character descriptor.

More information is available in the Cray C reference manual, SG-2024.

A sample C routine that requires a FORTRAN character variable as input might be:

#include 
int fd;
void OPENIT(fcd)
_fcd fcd;
{
  char *malloc();
  char *cpp = _fcdtocp(fcd);
  unsigned len = _fcdlen(fcd);
  char *cp = malloc(len+1);
  strncpy(cp,cpp,len)
  cp[len] = '\0';
  fd = creat(cp,6777);
}
while the FORTRAN program that calls OPENIT might look like
  PROGRAM FRED
  CHARACTER FILE*20
  FILE='MYDATA.DAT'
  CALL OPENIT(FILE)
  STOP
  END