⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cfortran.h

📁 Cfortran is useful for mixing language programing when you want call some C function in your FORTRAN
💻 H
📖 第 1 页 / 共 5 页
字号:
#ifdef sunFortran#if defined(sun) || defined(__sun)#include <math.h>     /* Sun's FLOATFUNCTIONTYPE, ASSIGNFLOAT, RETURNFLOAT.  */#else#include "math.h"     /* i.e. if crosscompiling assume user has file. */#endif/* At least starting with the default C compiler SC3.0.1 of SunOS 5.3, * FLOATFUNCTIONTYPE, ASSIGNFLOAT, RETURNFLOAT are not required and not in * <math.h>, since sun C no longer promotes C float return values to doubles. * Therefore, only use them if defined. * Even if gcc is being used, assume that it exhibits the Sun C compiler * behavior in order to be able to use *.o from the Sun C compiler. * i.e. If FLOATFUNCTIONTYPE, etc. are in math.h, they required by gcc. */#endif#ifndef apolloFortran#define COMMON_BLOCK_DEF(DEFINITION, NAME) extern DEFINITION NAME#define CF_NULL_PROTO#else                                         /* HP doesn't understand #elif. *//* Without ANSI prototyping, Apollo promotes float functions to double.    *//* Note that VAX/VMS, IBM, Mips choke on 'type function(...);' prototypes. */#define CF_NULL_PROTO ...#ifndef __CF__APOLLO67#define COMMON_BLOCK_DEF(DEFINITION, NAME) \ DEFINITION NAME __attribute((__section(NAME)))#else#define COMMON_BLOCK_DEF(DEFINITION, NAME) \ DEFINITION NAME #attribute[section(NAME)]#endif#endif#ifdef __cplusplus#undef  CF_NULL_PROTO#define CF_NULL_PROTO  ...#endif#ifndef USE_NEW_DELETE#ifdef __cplusplus#define USE_NEW_DELETE 1#else#define USE_NEW_DELETE 0#endif#endif#if USE_NEW_DELETE#define _cf_malloc(N) new char[N]#define _cf_free(P)   delete[] P#else#define _cf_malloc(N) (char *)malloc(N)#define _cf_free(P)   free(P)#endif#ifdef mipsFortran#define CF_DECLARE_GETARG         int f77argc; char **f77argv#define CF_SET_GETARG(ARGC,ARGV)  f77argc = ARGC; f77argv = ARGV#else#define CF_DECLARE_GETARG#define CF_SET_GETARG(ARGC,ARGV)#endif#ifdef OLD_VAXC                          /* Allow %CC-I-PARAMNOTUSED.         */#pragma standard                         #endif#define AcfCOMMA ,#define AcfCOLON ;/*-------------------------------------------------------------------------*//*               UTILITIES USED WITHIN CFORTRAN.H                          */#define _cfMIN(A,B) (A<B?A:B)/* 970211 - XIX.145:   firstindexlength  - better name is all_but_last_index_lengths   secondindexlength - better name is         last_index_length */#define  firstindexlength(A) (sizeof(A[0])==1 ? 1 : (sizeof(A) / sizeof(A[0])) )#define secondindexlength(A) (sizeof(A[0])==1 ?      sizeof(A) : sizeof(A[0])  )/* Behavior of FORTRAN LOGICAL. All machines' LOGICAL is same size as C's int.Conversion is automatic except for arrays which require F2CLOGICALV/C2FLOGICALV.f2c, MIPS f77 [DECstation, SGI], VAX Ultrix f77,HP-UX f77                                        : as in C.VAX/VMS FORTRAN, VAX Ultrix fort,Absoft Unix Fortran, IBM RS/6000 xlf             : LS Bit = 0/1 = TRUE/FALSE.Apollo                                           : neg.   = TRUE, else FALSE. [Apollo accepts -1 as TRUE for function values, but NOT all other neg. values.][DECFortran for Ultrix RISC is also called f77 but is the same as VAX/VMS.]   [MIPS f77 treats .eqv./.neqv. as .eq./.ne. and hence requires LOGICAL_STRICT.]*/#if defined(NAGf90Fortran) || defined(f2cFortran) || defined(mipsFortran) || defined(PowerStationFortran) || defined(hpuxFortran800) || defined(AbsoftUNIXFortran) || defined(AbsoftProFortran) || defined(SXFortran)/* SX/PowerStationFortran have 0 and 1 defined, others are neither T nor F.   *//* hpuxFortran800 has 0 and 0x01000000 defined. Others are unknown.           */#define LOGICAL_STRICT      /* Other Fortran have .eqv./.neqv. == .eq./.ne.   */#endif#define C2FLOGICALV(A,I) \ do {int __i; for(__i=0;__i<I;__i++) A[__i]=C2FLOGICAL(A[__i]); } while (0)#define F2CLOGICALV(A,I) \ do {int __i; for(__i=0;__i<I;__i++) A[__i]=F2CLOGICAL(A[__i]); } while (0)#if defined(apolloFortran)#define C2FLOGICAL(L) ((L)?-1:(L)&~((unsigned)1<<sizeof(int)*8-1))#define F2CLOGICAL(L) ((L)<0?(L):0) #else#if defined(CRAYFortran)#define C2FLOGICAL(L) _btol(L)#define F2CLOGICAL(L) _ltob(&(L))     /* Strangely _ltob() expects a pointer. */#else#if defined(IBMR2Fortran) || defined(vmsFortran) || defined(DECFortran) || defined(AbsoftUNIXFortran)/* How come no AbsoftProFortran ? */#define C2FLOGICAL(L) ((L)?(L)|1:(L)&~(int)1)#define F2CLOGICAL(L) ((L)&1?(L):0)#else#if defined(CONVEXFortran)#define C2FLOGICAL(L) ((L) ? ~0 : 0 )#define F2CLOGICAL(L) (L)#else   /* others evaluate LOGICALs as for C. */#define C2FLOGICAL(L) (L)#define F2CLOGICAL(L) (L)#ifndef LOGICAL_STRICT#undef  C2FLOGICALV#undef  F2CLOGICALV#define C2FLOGICALV(A,I)#define F2CLOGICALV(A,I)#endif  /* LOGICAL_STRICT                     */#endif  /* CONVEXFortran || All Others        */#endif  /* IBMR2Fortran vmsFortran DECFortran AbsoftUNIXFortran */#endif  /* CRAYFortran                        */#endif  /* apolloFortran                      *//* 970514 - In addition to CRAY, there may be other machines            for which LOGICAL_STRICT makes no sense. */#if defined(LOGICAL_STRICT) && !defined(CRAYFortran)/* Force C2FLOGICAL to generate only the values for either .TRUE. or .FALSE.   SX/PowerStationFortran only have 0 and 1 defined.   Elsewhere, only needed if you want to do:     logical lvariable     if (lvariable .eq.  .true.) then       ! (1)   instead of     if (lvariable .eqv. .true.) then       ! (2)   - (1) may not even be FORTRAN/77 and that Apollo's f77 and IBM's xlf     refuse to compile (1), so you are probably well advised to stay away from      (1) and from LOGICAL_STRICT.   - You pay a (slight) performance penalty for using LOGICAL_STRICT. */#undef  C2FLOGICAL#ifdef hpuxFortran800#define C2FLOGICAL(L) ((L)?0x01000000:0)#else#if defined(apolloFortran) || defined(vmsFortran) || defined(DECFortran)#define C2FLOGICAL(L) ((L)?-1:0) /* These machines use -1/0 for .true./.false.*/#else#define C2FLOGICAL(L) ((L)? 1:0) /* All others     use +1/0 for .true./.false.*/#endif#endif#endif /* LOGICAL_STRICT *//* Convert a vector of C strings into FORTRAN strings. */#ifndef __CF__KnRstatic char *c2fstrv(char* cstr, char *fstr, int elem_len, int sizeofcstr)#elsestatic char *c2fstrv(      cstr,       fstr,     elem_len,     sizeofcstr)                     char* cstr; char *fstr; int elem_len; int sizeofcstr;#endif{ int i,j;/* elem_len includes \0 for C strings. Fortran strings don't have term. \0.   Useful size of string must be the same in both languages. */for (i=0; i<sizeofcstr/elem_len; i++) {  for (j=1; j<elem_len && *cstr; j++) *fstr++ = *cstr++;  cstr += 1+elem_len-j;  for (; j<elem_len; j++) *fstr++ = ' ';} /* 95109 - Seems to be returning the original fstr. */return fstr-sizeofcstr+sizeofcstr/elem_len; }/* Convert a vector of FORTRAN strings into C strings. */#ifndef __CF__KnRstatic char *f2cstrv(char *fstr, char* cstr, int elem_len, int sizeofcstr)#elsestatic char *f2cstrv(      fstr,       cstr,     elem_len,     sizeofcstr)                     char *fstr; char* cstr; int elem_len; int sizeofcstr; #endif{ int i,j;/* elem_len includes \0 for C strings. Fortran strings don't have term. \0.   Useful size of string must be the same in both languages. */cstr += sizeofcstr;fstr += sizeofcstr - sizeofcstr/elem_len;for (i=0; i<sizeofcstr/elem_len; i++) {  *--cstr = '\0';  for (j=1; j<elem_len; j++) *--cstr = *--fstr;} return cstr; }/* kill the trailing char t's in string s. */#ifndef __CF__KnRstatic char *kill_trailing(char *s, char t)#elsestatic char *kill_trailing(      s,      t) char *s; char t;#endif{char *e; e = s + strlen(s);if (e>s) {                           /* Need this to handle NULL string.*/  while (e>s && *--e==t);            /* Don't follow t's past beginning. */  e[*e==t?0:1] = '\0';               /* Handle s[0]=t correctly.       */} return s; }/* kill_trailingn(s,t,e) will kill the trailing t's in string s. e normally points to the terminating '\0' of s, but may actually point to anywhere in s.s's new '\0' will be placed at e or earlier in order to remove any trailing t's.If e<s string s is left unchanged. */ #ifndef __CF__KnRstatic char *kill_trailingn(char *s, char t, char *e)#elsestatic char *kill_trailingn(      s,      t,       e) char *s; char t; char *e;#endif{ if (e==s) *e = '\0';                 /* Kill the string makes sense here.*/else if (e>s) {                      /* Watch out for neg. length string.*/  while (e>s && *--e==t);            /* Don't follow t's past beginning. */  e[*e==t?0:1] = '\0';               /* Handle s[0]=t correctly.       */} return s; }/* Note the following assumes that any element which has t's to be chopped off,does indeed fill the entire element. */#ifndef __CF__KnRstatic char *vkill_trailing(char* cstr, int elem_len, int sizeofcstr, char t)#elsestatic char *vkill_trailing(      cstr,     elem_len,     sizeofcstr,      t)                            char* cstr; int elem_len; int sizeofcstr; char t;#endif{ int i;for (i=0; i<sizeofcstr/elem_len; i++) /* elem_len includes \0 for C strings. */  kill_trailingn(cstr+elem_len*i,t,cstr+elem_len*(i+1)-1);return cstr; }#ifdef vmsFortrantypedef struct dsc$descriptor_s fstring;#define DSC$DESCRIPTOR_A(DIMCT)  		                               \struct {                                                                       \  unsigned short dsc$w_length;	        unsigned char	 dsc$b_dtype;	       \  unsigned char	 dsc$b_class;	                 char	*dsc$a_pointer;	       \           char	 dsc$b_scale;	        unsigned char	 dsc$b_digits;         \  struct {                                                                     \    unsigned		       : 3;	  unsigned dsc$v_fl_binscale : 1;      \    unsigned dsc$v_fl_redim    : 1;       unsigned dsc$v_fl_column   : 1;      \    unsigned dsc$v_fl_coeff    : 1;       unsigned dsc$v_fl_bounds   : 1;      \  } dsc$b_aflags;	                                                       \  unsigned char	 dsc$b_dimct;	        unsigned long	 dsc$l_arsize;	       \           char	*dsc$a_a0;	                 long	 dsc$l_m [DIMCT];      \  struct {                                                                     \    long dsc$l_l;                         long dsc$l_u;                        \  } dsc$bounds [DIMCT];                                                        \}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -