void name2cstr( const char * source,
char * target,
FSTR_L slen,
FSTR_L tlen ) ;
void fstr2cstr( const char * source,
char * target,
FSTR_L slen,
FSTR_L tlen ) ;
void cstr2fstr( const char * source,
char * target,
FSTR_L tlen ) ;
For Cray version, see include-file iodecl3.h—Cray data structures for Fortran strings are very different!.
fstr2cstr(): Construct a C string
for a general Fortran string (i.e., one with embedded blanks, like
description-lines in a file description.
Truncates if the target-length argument is too short.
name2cstr(): Construct a C string
for a Fortran "name" string (i.e., one without embedded
blanks, like variable-names or file-names.
Truncates if the target-length argument is too short.
cstr2fstr(): Construct a (blank
padded) Fortran string for a (null terminated) C string.
Truncates if the target-length argument is too short, pads with
blanks on the right if the target-length argument is too long.
These are most useful for C programmers needing to interact with the Fortran strings for variable names, units, and variable descriptions in file description data structures, since these latter are defined to use blank-padded, fixed-length Fortran-style strings instead of null terminated C strings. Note that generally the C bindings of the I/O API already use these routines internally to convert their arguments from C strings to the Fortran strings needed of their callees.
#include "iodecl3.h" for C.
...
#include "iodecl3.h"
...
char varname[ NAMLEN3+1 ] ;
char varunit[ NAMLEN3+1 ] ;
char vardesc[ MXDLEN3+1 ] ;
IOAPI_Bdesc3 bdesc;
IOAPI_Cdesc3 cdesc;
...
if ( ! desc3c( "INFILE", &bdesc, &cdesc) ) /* Get information from file header */
{
m3exitc( "TESTREAD", 0,0, "Error getting file description", 1 );
}
name2cstr( cdesc.vname[0], varname, (FSTR_L)NAMLEN3, (FSTR_L)(NAMLEN3+1) ) ;
name2cstr( cdesc.units[0], varunit, (FSTR_L)NAMLEN3, (FSTR_L)(NAMLEN3+1) ) ;
fstr2cstr( cdesc.vdesc[0], vardesc, (FSTR_L)MXDLEN3, (FSTR_L)(MXDLEN3+1) ) ;
printf( "First variable \"%s\" (%s): %s", varname, varunit, vardesc ) ;
...
cstr2fstr( "TA", cdesc.vname[0], (FSTR_L)(NAMLEN3) ) ;
cstr2fstr( "K", cdesc.units[0], (FSTR_L)(NAMLEN3) ) ;
cstr2fstr( "air temperature", cdesc.vdesc[0], (FSTR_L)(MXDLEN3) ) ;
...
if ( !open3c( "OUTFILE", & bdesc, & cdesc, FSUNKN3, "MY_PROGRAM" ) )
...
To: Models-3/EDSS I/O API: The Help Pages