File: sidlfortran.h

package info (click to toggle)
babel 0.10.2-1
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 43,932 kB
  • ctags: 29,707
  • sloc: java: 74,695; ansic: 73,142; cpp: 40,649; sh: 18,411; f90: 10,062; fortran: 6,727; python: 6,406; makefile: 3,866; xml: 118; perl: 48
file content (327 lines) | stat: -rw-r--r-- 10,270 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*
 * File:        sidlfortran.h
 * Revision:    @(#) $Revision: 4434 $
 * Date:        $Date: 2005-03-17 09:05:29 -0800 (Thu, 17 Mar 2005) $
 * Description: Macros for FORTRAN interoperability
 *
 * Copyright (c) 2000-2002, The Regents of the University of Calfornia.
 * Produced at the Lawrence Livermore National Laboratory.
 * Written by the Components Team <components@llnl.gov>
 * UCRL-CODE-2002-054
 * All rights reserved.
 * 
 * This file is part of Babel. For more information, see
 * http://www.llnl.gov/CASC/components/. Please read the COPYRIGHT file
 * for Our Notice and the LICENSE file for the GNU Lesser General Public
 * License.
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License (as published by
 * the Free Software Foundation) version 2.1 dated February 1999.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
 * conditions of the GNU Lesser General Public License for more details.
 * 
 * You should have recieved a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef included_sidlfortran_h
#define included_sidlfortran_h

#ifndef included_babel_config_h
#include "babel_config.h"
#endif
#ifdef FORTRAN77_DISABLED
#ifdef FORTRAN90_DISABLED
#error This installation of Babel Runtime was configured without any Fortran support.
#endif
#endif


#ifndef FORTRAN77_DISABLED
/*
 * The SIDLFortran77Ending macro should be defined to add the appropriate
 * characters to the end of a symbol.  Normally, this means adding zero, 
 * one or two underscores.
 */
#ifdef SIDL_F77_ZERO_UNDERSCORE
#define SIDLFortran77Ending(sym) sym
#else
#ifdef SIDL_F77_ONE_UNDERSCORE
#define SIDLFortran77Ending(sym) sym ## _
#else
#ifdef SIDL_F77_TWO_UNDERSCORE
#define SIDLFortran77Ending(sym) sym ## __
#else
#error one of SIDL_F77_(ZERO,ONE,TWO)_UNDERSCORE must be defined
#endif
#endif
#endif

/*
 * The SIDLFortran77Symbol macro should be defined to choose between
 * a lower case form of the symbol, an upper case form of the symbol and
 * a mixed case form of the symbol.  It should apply SIDLFortran77Ending
 * to its choice.
 */
#ifdef SIDL_F77_LOWER_CASE
#define SIDLFortran77Symbol(lcase,ucase,mcase) SIDLFortran77Ending(lcase)
#else
#ifdef SIDL_F77_UPPER_CASE
#define SIDLFortran77Symbol(lcase,ucase,mcase) SIDLFortran77Ending(ucase)
#else
#ifdef SIDL_F77_MIXED_CASE
#define SIDLFortran77Symbol(lcase,ucase,mcase) SIDLFortran77Ending(mcase)
#else
#error one of SIDL_F77_(LOWER,UPPER,MIXED)_CASE must be defined
#endif
#endif
#endif

/*
 * String handling
 */
#if defined(SIDL_F77_STR_LEN_NEAR) || defined(SIDL_F77_STR_LEN_FAR)
typedef char *SIDL_F77_String;
#define SIDL_F77_STR(strvar) (strvar)
#define SIDL_F77_STR_LOCAL_ARG(strvar) strvar
#define SIDL_F77_STR_LOCAL_STR(strvar) strvar
#define SIDL_F77_STR_LOCAL_LEN(strvar) strvar ## _len
#define SIDL_F77_STR_LEN(strvar) strvar ## _len
#define SIDL_F77_STR_LOCAL(strvar) \
SIDL_F77_String strvar = NULL;\
int SIDL_F77_STR_LOCAL_LEN(strvar) = 0
#ifdef SIDL_F77_STR_LEN_NEAR
#define SIDL_F77_STR_NEAR_LEN_DECL(strvar) , int SIDL_F77_STR_LEN(strvar)
#define SIDL_F77_STR_NEAR_LEN(strvar) , SIDL_F77_STR_LOCAL_LEN(strvar)
#define SIDL_F77_STR_FAR_LEN_DECL(strvar) 
#define SIDL_F77_STR_FAR_LEN(strvar)
#else
#define SIDL_F77_STR_NEAR_LEN_DECL(strvar)
#define SIDL_F77_STR_NEAR_LEN(strvar)
#define SIDL_F77_STR_FAR_LEN_DECL(strvar) , int SIDL_F77_STR_LEN(strvar)
#define SIDL_F77_STR_FAR_LEN(strvar) , SIDL_F77_STR_LOCAL_LEN(strvar)
#endif
#else
#if defined(SIDL_F77_STR_STRUCT_STR_LEN) || defined(SIDL_F77_STR_STRUCT_LEN_STR)
struct SIDL_F77_String_t;
typdef struct SIDL_F77_String_t *SIDL_F77_String;
#define SIDL_F77_STR(strvar) ((*strvar).str)
#define SIDL_F77_STR_LOCAL(strvar) struct SIDL_F77_String_t strvar = \
  { NULL, 0 }
#define SIDL_F77_STR_LOCAL_ARG(strvar) &strvar
#define SIDL_F77_STR_LOCAL_STR(strvar) ((strvar).str)
#define SIDL_F77_STR_LOCAL_LEN(strvar) ((strvar).len)
#define SIDL_F77_STR_LEN(strvar) ((*strvar).len)
#define SIDL_F77_STR_NEAR_LEN_DECL(strvar)
#define SIDL_F77_STR_FAR_LEN_DECL(strvar)
#else
#ifdef SIDL_F77_STR_STRUCT_STR_LEN
struct SIDL_F77_String_t {
  char *str;
  int  len;
};
#else
struct SIDL_F77_String_t {
  int  len;
  char *str;
};
#endif
#endif
#endif
#define SIDL_F77_STR_COPY(localvar,argvar,minsize) \
  sidl_copy_ior_str(&(SIDL_F77_STR_LOCAL_STR(localvar)), \
                    &(SIDL_F77_STR_LOCAL_LEN(localvar)), \
                    (argvar), (minsize))

#ifndef SIDL_F77_STR_MINSIZE
#define SIDL_F77_STR_MINSIZE 512
#endif

typedef int SIDL_F77_Bool;
#ifndef SIDL_F77_TRUE
#define SIDL_F77_TRUE 1
#endif
#ifndef SIDL_F77_FALSE 
#define SIDL_F77_FALSE 0
#endif

#endif /* not FORTRAN77_DISABLED */


#ifndef FORTRAN90_DISABLED
/*
 * The SIDLFortran90Ending macro should be defined to add the appropriate
 * characters to the end of a symbol.  Normally, this means adding zero, 
 * one or two underscores.
 */
#ifdef SIDL_F90_ZERO_UNDERSCORE
#define SIDLFortran90Ending(sym) sym
#else
#ifdef SIDL_F90_ONE_UNDERSCORE
#define SIDLFortran90Ending(sym) sym ## _
#else
#ifdef SIDL_F90_TWO_UNDERSCORE
#define SIDLFortran90Ending(sym) sym ## __
#else
#error one of SIDL_F90_(ZERO,ONE,TWO)_UNDERSCORE must be defined
#endif
#endif
#endif

/*
 * The SIDLFortran90Symbol macro should be defined to choose between
 * a lower case form of the symbol, an upper case form of the symbol and
 * a mixed case form of the symbol.  It should apply SIDLFortran90Ending
 * to its choice.
 */
#ifdef SIDL_F90_LOWER_CASE
#define SIDLFortran90Symbol(lcase,ucase,mcase) SIDLFortran90Ending(lcase)
#else
#ifdef SIDL_F90_UPPER_CASE
#define SIDLFortran90Symbol(lcase,ucase,mcase) SIDLFortran90Ending(ucase)
#else
#ifdef SIDL_F90_MIXED_CASE
#define SIDLFortran90Symbol(lcase,ucase,mcase) SIDLFortran90Ending(mcase)
#else
#error one of SIDL_F90_(LOWER,UPPER,MIXED)_CASE must be defined
#endif
#endif
#endif

/*
 * String handling
 */
#if defined(SIDL_F90_STR_LEN_NEAR) || defined(SIDL_F90_STR_LEN_FAR)
typedef char *SIDL_F90_String;
#define SIDL_F90_STR(strvar) (strvar)
#define SIDL_F90_STR_LOCAL_ARG(strvar) strvar
#define SIDL_F90_STR_LOCAL_STR(strvar) strvar
#define SIDL_F90_STR_LOCAL_LEN(strvar) strvar ## _len
#define SIDL_F90_STR_LEN(strvar) strvar ## _len
#define SIDL_F90_STR_LOCAL(strvar) \
SIDL_F90_String strvar = NULL;\
int SIDL_F90_STR_LOCAL_LEN(strvar) = 0
#ifdef SIDL_F90_STR_LEN_NEAR
#define SIDL_F90_STR_NEAR_LEN_DECL(strvar) , int SIDL_F90_STR_LEN(strvar)
#define SIDL_F90_STR_NEAR_LEN(strvar) , SIDL_F90_STR_LOCAL_LEN(strvar)
#define SIDL_F90_STR_FAR_LEN_DECL(strvar) 
#define SIDL_F90_STR_FAR_LEN(strvar)
#else
#define SIDL_F90_STR_NEAR_LEN_DECL(strvar)
#define SIDL_F90_STR_NEAR_LEN(strvar)
#define SIDL_F90_STR_FAR_LEN_DECL(strvar) , int SIDL_F90_STR_LEN(strvar)
#define SIDL_F90_STR_FAR_LEN(strvar) , SIDL_F90_STR_LOCAL_LEN(strvar)
#endif
#else
#if defined(SIDL_F90_STR_STRUCT_STR_LEN) || defined(SIDL_F90_STR_STRUCT_LEN_STR)
struct SIDL_F90_String_t;
typdef struct SIDL_F90_String_t *SIDL_F90_String;
#define SIDL_F90_STR(strvar) ((*strvar).str)
#define SIDL_F90_STR_LOCAL(strvar) struct SIDL_F90_String_t strvar = \
  { NULL, 0 }
#define SIDL_F90_STR_LOCAL_ARG(strvar) &strvar
#define SIDL_F90_STR_LOCAL_STR(strvar) ((strvar).str)
#define SIDL_F90_STR_LOCAL_LEN(strvar) ((strvar).len)
#define SIDL_F90_STR_LEN(strvar) ((*strvar).len)
#define SIDL_F90_STR_NEAR_LEN_DECL(strvar)
#define SIDL_F90_STR_FAR_LEN_DECL(strvar)
#else
#ifdef SIDL_F90_STR_STRUCT_STR_LEN
struct SIDL_F90_String_t {
  char *str;
  int  len;
};
#else
struct SIDL_F90_String_t {
  int  len;
  char *str;
};
#endif
#endif
#endif
#define SIDL_F90_STR_COPY(localvar,argvar,minsize) \
  sidl_copy_ior_str(&(SIDL_F90_STR_LOCAL_STR(localvar)), \
                    &(SIDL_F90_STR_LOCAL_LEN(localvar)), \
                    (argvar), (minsize))

#ifndef SIDL_F90_STR_MINSIZE
#define SIDL_F90_STR_MINSIZE 512
#endif

typedef int SIDL_F90_Bool;
#ifndef SIDL_F90_TRUE
#define SIDL_F90_TRUE 1
#endif
#ifndef SIDL_F90_FALSE 
#define SIDL_F90_FALSE 0
#endif

#endif /* not FORTRAN90_DISABLED */


#ifdef __cplusplus
extern "C" { /*}*/
#endif


/*
 * Convert a FORTRAN string to a nul terminated C string.  The
 * returned pointer is a dynamically allocated copy of fstr.  Any
 * trailing space characters in fstr are left out of the copy.
 */
char *
sidl_copy_fortran_str(const char *fstr,
                      int         flen);

/*
 * Convert a C string into a FORTRAN string.  If the C string is
 * shorter than the fstr, fstr will be padded with space characters.
 * If the C string is longer than fstr, the first flen characters of
 * the C string are copied.
 */
void
sidl_copy_c_str(char       *fstr,
                int         flen,
                const char *cstr);

/*
 * Provide a block of memory and the length for a FORTRAN string.
 * This will dynamically allocate a string with max(strlen(iorstr),
 * minsize)+1 characters.  The last character in the buffer is
 * initialized to '\0'.
 * 
 * The pointer to the allocated space is stored in *newfstr, and the length
 * of the space is stored in *newflen.  If iorstr is not null, the contents
 * are copied into the allocated space.  Any uninitialized characters in
 * *newfstr are initialized to space characters.
 *
 * The intent is that the FORTRAN client will only use characters 0 through
 * minsize - 1 leaving the nul character untouched.
 */
void
sidl_copy_ior_str(char      **newfstr, 
                  int        *newflen,
                  const char *iorstr,
                  const int   minsize);

/*
 * Remove trailing space characters.  This
 * routine will store a nul character in index 0 to
 * buflen (inclusive) (i.e. a full string causes
 * the assignment buffer[buflen] = '\0'). This means
 * that buffer is actually buflen + 1 bytes long.
 * It returns buffer.
 */
char *
sidl_trim_trailing_space(char *buffer,
                         int   buflen);

#ifdef __cplusplus
}
#endif
#endif /* included_sidlfortran_h */