00001 /*
00002 ccp4_fortran.h: header file for Fortran APIs
00003 Copyright (C) 2001 Eugene Krissinel
00004
00005 This library is free software and is distributed under the terms and
00006 conditions of the CCP4 licence agreement as `Part 0' (Annex 2)
00007 software, which is version 2.1 of the GNU Lesser General Public
00008 Licence (LGPL) with the following additional clause:
00009
00010 `You may also combine or link a "work that uses the Library" to
00011 produce a work containing portions of the Library, and distribute
00012 that work under terms of your choice, provided that you give
00013 prominent notice with each copy of the work that the specified
00014 version of the Library is used in it, and that you include or
00015 provide public access to the complete corresponding
00016 machine-readable source code for the Library including whatever
00017 changes were used in the work. (i.e. If you make changes to the
00018 Library you must distribute those, but you do not need to
00019 distribute source or object code to those portions of the work
00020 not covered by this licence.)'
00021
00022 Note that this clause grants an additional right and does not impose
00023 any additional restriction, and so does not affect compatibility
00024 with the GNU General Public Licence (GPL). If you wish to negotiate
00025 other terms, please contact the maintainer.
00026
00027 You can redistribute it and/or modify the library under the terms of
00028 the GNU Lesser General Public License as published by the Free Software
00029 Foundation; either version 2.1 of the License, or (at your option) any
00030 later version.
00031
00032 This library is distributed in the hope that it will be useful, but
00033 WITHOUT ANY WARRANTY; without even the implied warranty of
00034 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00035 Lesser General Public License for more details.
00036
00037 You should have received a copy of the CCP4 licence and/or GNU
00038 Lesser General Public License along with this library; if not, write
00039 to the CCP4 Secretary, Daresbury Laboratory, Warrington WA4 4AD, UK.
00040 The GNU Lesser General Public can also be obtained by writing to the
00041 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00042 MA 02111-1307 USA
00043 */
00044
00050 #ifndef __CCP4_FORTRAN
00051 #define __CCP4_FORTRAN
00052
00053 #include "ccp4_types.h"
00054 static char rcsidhh[] = "$Id: ccp4__fortran_8h-source.html,v 1.8 2004/07/05 14:36:54 mdw Exp $";
00055
00056 /* stardent is now obsolete, but we retain this category in case it is useful later */
00057 #ifdef CALL_LIKE_STARDENT
00058 /* SStrParam is used in Ardent-like machines' fortran calls */
00059 /* for passing a string parameter */
00060 DefineStructure(SStrPar)
00061 struct SStrPar {
00062 pstr S;
00063 int len;
00064 int id;
00065 };
00066 #endif
00067
00068 #define _LVTOB(l) ((long) ((l) == 0 ? 0 : 1))
00069 #define _BTOLV(l) ((int) ((l) == 0 ? 0 : 1))
00070 #if defined (__OSF1__) || defined (__osf__)
00071 #undef _BTOLV
00072 #define _BTOLV(l) ((int) ((l) == 0 ? 0 : -1))
00073 #endif
00074
00075 /*
00076 Macro FORTRAN_SUBR(NAME,name,p_send,p_sstruct,p_sflw)
00077 makes function header statements that allow for linking with
00078 programs written in FORTRAN.
00079
00080 Parameters:
00081
00082 NAME name of the FORTRAN subroutine in capital letters
00083 name name of the FORTRAN subroutine in small letters
00084 p_send parameter list (in brackets) with string lengths
00085 attached to the end of it (see below)
00086 p_sstruct parameter list (in brackets) with strings passed
00087 as complex parameters, or structures
00088 p_sflw parameter list (in brackets) with string lengths
00089 following immediately the string parameters
00090 (see below)
00091
00092 All non-string parameters must be passed as pointers, in
00093 the same order as they enter the FORTRAN call. Rules for
00094 the string parameters are as follows.
00095
00096 1. All strings should be specified as of 'fpstr' type.
00097 The 'fpstr' type is defined below and depends on the
00098 platform:
00099
00100 a) whenever length of string is passed as a separate
00101 parameter ( CALL_LIKE_SUN, CALL_LIKE_HPUX,
00102 CALL_LIKE_MVS ) 'fpstr' is identical to 'pstr'.
00103 You may choose arbitrary name for the string,
00104 but you MUST use the same name, appended with
00105 suffix '_len', for its length (see example below).
00106
00107 b) whenever string and its length are passed as
00108 complex parameter, 'fpstr' is identical to the
00109 pointer on the corresponding structure:
00110 CALL_LIKE_STARDENT :
00111 'fpstr' is identical to 'PSStrPar'
00112 CALL_LIKE_VMS :
00113 'fpstr' is identical to 'dsc$descriptor_s *'
00114
00115 With 'fpstr' type, two important macro definition come:
00116
00117 i) FTN_STR(s) - returns pointer to fortran-passed
00118 string s. This pointer is always
00119 of 'pstr' type
00120 ii) FTN_LEN(s) - returns integer length of fortran-
00121 passed string s. For this macro to
00122 work properly with SUN- and MVS-like
00123 machines, always use suffix '_len'
00124 for the string length parameters as
00125 described in a) above.
00126
00127 2. Three parameter lists, each enclosed in brackets, should
00128 be given. These lists retain the general order of
00129 parameters in the corresponding fortran call. Non-string
00130 parameters are passed as pointers. String parameters
00131 and their lengths are passed differently in different
00132 lists:
00133
00134 p_send strings enter their place in the list as in
00135 the corresponding FORTRAN call, having 'fpstr'
00136 parameter type. Their lengths are appended as
00137 'int' to the end of the list. They should
00138 retain the order in which the strings appear
00139 in the list.
00140
00141 p_sstruct strings enter their place in the list as in
00142 the corresponding FORTRAN call, having 'fpstr'
00143 parameter type.
00144
00145 p_sflw strings enter their place in the list as in
00146 the corresponding FORTRAN call, having 'fpstr'
00147 type and being immediately followed by their
00148 lengths as 'int' parameters.
00149
00150
00151
00152 Example:
00153
00154 FORTRAN statement
00155
00156 subroutine SomeSub ( k,s1,a,s2,m )
00157 integer k,m
00158 real a
00159 character*(*) s1,s2
00160
00161 is translated to
00162
00163 FORTRAN_SUBR ( SOMESUB, somesub,
00164 ( int * k, fpstr s1, float * a, fpstr s2, int * m,
00165 int s1_len, int s2_len ),
00166 ( int * k, fpstr s1, float * a, fpstr s2, int * m ),
00167 ( int * k, fpstr s1, int s1_len, float * a,
00168 fpstr s2, int s2_len, int * m ) )
00169
00170
00171 The macro should replace ordinary function header
00172 statements to assure compatibility with FORTRAN links.
00173 In header files, do not forget to add semicolumn:
00174
00175 FORTRAN_SUBR ( .... );
00176
00177 while in source files use simply
00178
00179 FORTRAN_SUBR ( .... ) {
00180 <source body, operators>
00181 }
00182
00183
00184
00185 Macro FORTRAN_CALL(NAME,name,p_send,p_sstruct,p_sflw)
00186 calls function defined with macro FORTRAN_SUBR(...), from
00187 a C/C++ application. Its parameters and their meaning are
00188 exactly identical to those of FORTRAN_SUBR(...).
00189 FORTRAN_CALL(...) should be followed by semicolon. */
00190
00191
00192 #if defined(CALL_LIKE_SUN)
00193
00194 typedef pstr fpstr;
00195
00196 # define FTN_STR(s) s
00197 # define FTN_LEN(s) s##_len
00198
00199 # define char_struct(s) \
00200 pstr s; \
00201 int s##_len;
00202 # define fill_char_struct(s,str) \
00203 s = str; \
00204 s##_len = strlen(str);
00205 # define init_char_struct(s,str,size) \
00206 s = str; \
00207 s##_len = size;
00208
00209 # define FORTRAN_SUBR(NAME,name,p_sun,p_stardent,p_mvs) \
00210 void name##_ p_sun
00211 # define FORTRAN_CALL(NAME,name,p_sun,p_stardent,p_mvs) \
00212 name##_ p_sun
00213 # define FORTRAN_FUN(val,NAME,name,p_sun,p_stardent,p_mvs) \
00214 val name##_ p_sun
00215 #elif defined(CALL_LIKE_HPUX)
00216
00217 typedef pstr fpstr;
00218
00219 # define FTN_STR(s) s
00220 # define FTN_LEN(s) s##_len
00221
00222 # define char_struct(s) \
00223 pstr s; \
00224 int s##_len;
00225 # define fill_char_struct(s,str) \
00226 s = str; \
00227 s##_len = strlen(str);
00228 # define init_char_struct(s,str,size) \
00229 s = str; \
00230 s##_len = size;
00231
00232 # define FORTRAN_SUBR(NAME,name,p_sun,p_stardent,p_mvs) \
00233 void name p_sun
00234 # define FORTRAN_CALL(NAME,name,p_sun,p_stardent,p_mvs) \
00235 name p_sun
00236 # define FORTRAN_FUN(val,NAME,name,p_sun,p_stardent,p_mvs) \
00237 val name p_sun
00238 #elif defined(CALL_LIKE_STARDENT)
00239
00240 typedef PStrPar fpstr;
00241
00242 # define FTN_STR(s) s->Str_pointer
00243 # define FTN_LEN(s) s->Str_length
00244
00245 # define char_struct(s) \
00246 SStrPar s;
00247 # define fill_char_struct(s,str) \
00248 s.S = str; \
00249 s.len = strlen(FName); \
00250 s.id = 0;
00251 # define init_char_struct(s,str,size) \
00252 s.S = str; \
00253 s.len = size; \
00254 s.id = 0;
00255
00256 # define FORTRAN_SUBR(NAME,name,p_send,p_sstruct,p_sflw) \
00257 void NAME p_stardent
00258 # define FORTRAN_CALL(NAME,name,p_send,p_sstruct,p_sflw) \
00259 NAME p_stardent
00260 # define FORTRAN_FUN(val,NAME,name,p_send,p_sstruct,p_sflw) \
00261 val NAME p_stardent
00262
00263 #elif defined(CALL_LIKE_VMS)
00264
00265 typedef dsc$descriptor_s * fpstr;
00266
00267 # define FTN_STR(s) s->dsc$a_pointer;
00268 # define FTN_LEN(s) s->dsc$w_length;
00269
00270 # define char_struct(s) \
00271 dsc$descriptor_s s;
00272 # define fill_char_struct(s,str) \
00273 s.dsc$a_pointer = str; \
00274 s.dsc$w_length = strlen(str); \
00275 s.dsc$b_dtype = DSC$K_DTYPE_T; \
00276 s.dsc$b_class = DSC$K_CLASS_S;
00277 # define init_char_struct(s,str,size) \
00278 s.dsc$a_pointer = str; \
00279 s.dsc$w_length = size; \
00280 s.dsc$b_dtype = DSC$K_DTYPE_T; \
00281 s.dsc$b_class = DSC$K_CLASS_S;
00282
00283 # define FORTRAN_SUBR(NAME,name,p_sun,p_stardent,p_mvs) \
00284 void NAME p_stardent
00285 # define FORTRAN_CALL(NAME,name,p_sun,p_stardent,p_mvs) \
00286 NAME p_stardent
00287 # define FORTRAN_FUN(val,NAME,name,p_sun,p_stardent,p_mvs) \
00288 val NAME p_stardent
00289
00290 #elif defined(CALL_LIKE_MVS)
00291
00292 typedef pstr fpstr;
00293
00294 # define FTN_STR(s) s
00295 # define FTN_LEN(s) s##_len
00296
00297 # define char_struct(s) \
00298 pstr s; \
00299 int s##_len;
00300 # define fill_char_struct(s,str) \
00301 s = str; \
00302 s##_len = strlen(str);
00303 # define init_char_struct(s,str,size) \
00304 s = str; \
00305 s##_len = size;
00306
00307 # define FORTRAN_SUBR(NAME,name,p_sun,p_stardent,p_mvs) \
00308 void __stdcall NAME p_mvs
00309 # define FORTRAN_CALL(NAME,name,p_sun,p_stardent,p_mvs) \
00310 NAME p_mvs
00311 # define FORTRAN_FUN(val,NAME,name,p_sun,p_stardent,p_mvs) \
00312 val __stdcall NAME p_mvs
00313
00314 #else
00315
00316 # error Unknown machine!!!
00317
00318 typedef pstr fpstr;
00319
00320 # define FTN_STR(s) s
00321 # define FTN_LEN(s) s##_len
00322
00323 # define char_struct(s) \
00324 pstr s; \
00325 int s##_len;
00326 # define fill_char_struct(s,str) \
00327 s = str; \
00328 s##_len = strlen(str);
00329 # define init_char_struct(s,str,size) \
00330 s = str; \
00331 s##_len = size;
00332
00341 # define FORTRAN_SUBR(NAME,name,p_sun,p_stardent,p_mvs) \
00342 void name##_ p_sun
00343
00351 # define FORTRAN_CALL(NAME,name,p_sun,p_stardent,p_mvs) \
00352 name##_ p_sun
00353
00363 # define FORTRAN_FUN(val,NAME,name,p_sun,p_stardent,p_mvs) \
00364 val name##_ p_sun
00365
00366 #endif
00367
00368 /* Define Fortran logical */
00369 typedef unsigned int ftn_logical;
00370 #if defined (KNOWN_MACHINE)
00371 # define FORTRAN_LOGICAL_TRUE 1
00372 # define FORTRAN_LOGICAL_FALSE 0
00373 #endif
00374 #if defined (__OSF1__) || defined (__osf__)
00375 # undef FORTRAN_LOGICAL_TRUE
00376 # define FORTRAN_LOGICAL_TRUE -1
00377 #endif
00378
00379 char *ccp4_FtoCString(fpstr str1, int str1_len);
00380 void ccp4_CtoFString(fpstr str1, int str1_len, const char *cstring);
00381
00382 #endif /* __CCP4_FORTRAN */