1 /*
2 * Name:
3 * c2f77.c
4
5 * Purpose:
6 * Implement the interface between the C and FORTRAN 77 languages.
7
8 * Description:
9 * This file implements language-specific functions which support
10 * the FORTRAN 77 interface to the AST library.
11 *
12 * Note that this module is not a class implementation, although it
13 * resembles one.
14
15 * Notes:
16 * - Some of the functions in this module are potentially platform
17 * dependent and may need to be re-implemented when porting the AST
18 * library to new platforms.
19
20 * Copyright:
21 * Copyright (C) 1997-2006 Council for the Central Laboratory of the
22 * Research Councils
23
24 * Licence:
25 * This program is free software: you can redistribute it and/or
26 * modify it under the terms of the GNU Lesser General Public
27 * License as published by the Free Software Foundation, either
28 * version 3 of the License, or (at your option) any later
29 * version.
30 *
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU Lesser General Public License for more details.
35 *
36 * You should have received a copy of the GNU Lesser General
37 * License along with this program. If not, see
38 * <http://www.gnu.org/licenses/>.
39
40 * Authors:
41 * DSB: D.S. Berry (Starlink)
42 * RFWS: R.F. Warren-Smith (Starlink)
43
44 * History:
45 * 15-NOV-1996 (RFWS):
46 * Original version (based on work by DSB and on code from the
47 * Starlink CNF library).
48 */
49
50 /* Define the astCLASS macro (even although this is not a class
51 implementation) to obtain access to protected interfaces. */
52 #define astCLASS
53
54 /* Include files. */
55 /* ============== */
56 /* Interface definitions. */
57 /* ---------------------- */
58 #include "error.h" /* Error reporting facilities */
59 #include "c2f77.h" /* Interface to this module */
60
61 /* Function implementations. */
62 /* ========================= */
astStringExport_(const char * source_c,char * dest_f,int dest_len)63 void astStringExport_( const char *source_c, char *dest_f, int dest_len ) {
64 /*
65 *+
66 * Name:
67 * astStringExport
68
69 * Purpose:
70 * Export a C string to a FORTRAN string.
71
72 * Type:
73 * Protected function.
74
75 * Synopsis:
76 * #include "c2f77.h"
77 * void astStringExport( const char *source_c, char *dest_f, int dest_len )
78
79 * Description:
80 * This function creates a FORTRAN string from a C string, storing
81 * it in the supplied memory. If the C string is shorter than the
82 * space allocated for the FORTRAN string, then it is padded with
83 * blanks. If the C string is longer than the space allocated for
84 * the FORTRAN string, then the string is truncated.
85
86 * Parameters:
87 * source_c
88 * A pointer to the input C string.
89 * dest_f
90 * A pointer to the output FORTRAN string.
91 * dest_len
92 * The length of the output FORTRAN string.
93
94 * Notes:
95 * - This function is potentially platform-specific. For example,
96 * if FORTRAN strings were passed by descriptor, then the
97 * descriptor address would be passed as "dest_f" and this must
98 * then be used to locate the actual FORTRAN character data.
99 * - This function is described as protected but is in fact
100 * available through the public interface so that it may be used in
101 * constructing the FORTRAN 77 public interface.
102 * - This is the UNIX version of this function.
103 *-
104 */
105
106 /* Local Variables:*/
107 int i; /* Loop counter for characters */
108 int *status; /* Pointer to inherited status value */
109
110 /* Get a pointer to the inherited status value. */
111 status = astGetStatusPtr;
112
113 /* Check the global error status. */
114 if ( !astOK ) return;
115
116 /* Copy the characters of the input C string to the output FORTRAN
117 string, taking care not to go beyond the end of the FORTRAN
118 string.*/
119 for ( i = 0; source_c[ i ] && ( i < dest_len ); i++ ) {
120 dest_f[ i ] = source_c[ i ];
121 }
122
123 /* Fill the rest of the output FORTRAN string with blanks. */
124 for ( ; i < dest_len; i++ ) dest_f[ i ] = ' ';
125 }
126