lwrite.c
Go to the documentation of this file.
00001 #include "f2c.h"
00002 #include "fio.h"
00003 #include "fmt.h"
00004 #include "lio.h"
00005 #ifdef __cplusplus
00006 extern "C" {
00007 #endif
00008 
00009 ftnint L_len;
00010 int f__Aquote;
00011 
00012  static VOID
00013 donewrec(Void)
00014 {
00015         if (f__recpos)
00016                 (*f__donewrec)();
00017         }
00018 
00019  static VOID
00020 #ifdef KR_headers
00021 lwrt_I(n) longint n;
00022 #else
00023 lwrt_I(longint n)
00024 #endif
00025 {
00026         char *p;
00027         int ndigit, sign;
00028 
00029         p = f__icvt(n, &ndigit, &sign, 10);
00030         if(f__recpos + ndigit >= L_len)
00031                 donewrec();
00032         PUT(' ');
00033         if (sign)
00034                 PUT('-');
00035         while(*p)
00036                 PUT(*p++);
00037 }
00038  static VOID
00039 #ifdef KR_headers
00040 lwrt_L(n, len) ftnint n; ftnlen len;
00041 #else
00042 lwrt_L(ftnint n, ftnlen len)
00043 #endif
00044 {
00045         if(f__recpos+LLOGW>=L_len)
00046                 donewrec();
00047         wrt_L((Uint *)&n,LLOGW, len);
00048 }
00049  static VOID
00050 #ifdef KR_headers
00051 lwrt_A(p,len) char *p; ftnlen len;
00052 #else
00053 lwrt_A(char *p, ftnlen len)
00054 #endif
00055 {
00056         int a;
00057         char *p1, *pe;
00058 
00059         a = 0;
00060         pe = p + len;
00061         if (f__Aquote) {
00062                 a = 3;
00063                 if (len > 1 && p[len-1] == ' ') {
00064                         while(--len > 1 && p[len-1] == ' ');
00065                         pe = p + len;
00066                         }
00067                 p1 = p;
00068                 while(p1 < pe)
00069                         if (*p1++ == '\'')
00070                                 a++;
00071                 }
00072         if(f__recpos+len+a >= L_len)
00073                 donewrec();
00074         if (a
00075 #ifndef OMIT_BLANK_CC
00076                 || !f__recpos
00077 #endif
00078                 )
00079                 PUT(' ');
00080         if (a) {
00081                 PUT('\'');
00082                 while(p < pe) {
00083                         if (*p == '\'')
00084                                 PUT('\'');
00085                         PUT(*p++);
00086                         }
00087                 PUT('\'');
00088                 }
00089         else
00090                 while(p < pe)
00091                         PUT(*p++);
00092 }
00093 
00094  static int
00095 #ifdef KR_headers
00096 l_g(buf, n) char *buf; double n;
00097 #else
00098 l_g(char *buf, double n)
00099 #endif
00100 {
00101 #ifdef Old_list_output
00102         doublereal absn;
00103         char *fmt;
00104 
00105         absn = n;
00106         if (absn < 0)
00107                 absn = -absn;
00108         fmt = LLOW <= absn && absn < LHIGH ? LFFMT : LEFMT;
00109 #ifdef USE_STRLEN
00110         sprintf(buf, fmt, n);
00111         return strlen(buf);
00112 #else
00113         return sprintf(buf, fmt, n);
00114 #endif
00115 
00116 #else
00117         register char *b, c, c1;
00118 
00119         b = buf;
00120         *b++ = ' ';
00121         if (n < 0) {
00122                 *b++ = '-';
00123                 n = -n;
00124                 }
00125         else
00126                 *b++ = ' ';
00127         if (n == 0) {
00128 #ifdef SIGNED_ZEROS
00129                 if (signbit_f2c(&n))
00130                         *b++ = '-';
00131 #endif
00132                 *b++ = '0';
00133                 *b++ = '.';
00134                 *b = 0;
00135                 goto f__ret;
00136                 }
00137         sprintf(b, LGFMT, n);
00138         switch(*b) {
00139 #ifndef WANT_LEAD_0
00140                 case '0':
00141                         while(b[0] = b[1])
00142                                 b++;
00143                         break;
00144 #endif
00145                 case 'i':
00146                 case 'I':
00147                         /* Infinity */
00148                 case 'n':
00149                 case 'N':
00150                         /* NaN */
00151                         while(*++b);
00152                         break;
00153 
00154                 default:
00155         /* Fortran 77 insists on having a decimal point... */
00156                     for(;; b++)
00157                         switch(*b) {
00158                         case 0:
00159                                 *b++ = '.';
00160                                 *b = 0;
00161                                 goto f__ret;
00162                         case '.':
00163                                 while(*++b);
00164                                 goto f__ret;
00165                         case 'E':
00166                                 for(c1 = '.', c = 'E';  *b = c1;
00167                                         c1 = c, c = *++b);
00168                                 goto f__ret;
00169                         }
00170                 }
00171  f__ret:
00172         return b - buf;
00173 #endif
00174         }
00175 
00176  static VOID
00177 #ifdef KR_headers
00178 l_put(s) register char *s;
00179 #else
00180 l_put(register char *s)
00181 #endif
00182 {
00183 #ifdef KR_headers
00184         register void (*pn)() = f__putn;
00185 #else
00186         register void (*pn)(int) = f__putn;
00187 #endif
00188         register int c;
00189 
00190         while(c = *s++)
00191                 (*pn)(c);
00192         }
00193 
00194  static VOID
00195 #ifdef KR_headers
00196 lwrt_F(n) double n;
00197 #else
00198 lwrt_F(double n)
00199 #endif
00200 {
00201         char buf[LEFBL];
00202 
00203         if(f__recpos + l_g(buf,n) >= L_len)
00204                 donewrec();
00205         l_put(buf);
00206 }
00207  static VOID
00208 #ifdef KR_headers
00209 lwrt_C(a,b) double a,b;
00210 #else
00211 lwrt_C(double a, double b)
00212 #endif
00213 {
00214         char *ba, *bb, bufa[LEFBL], bufb[LEFBL];
00215         int al, bl;
00216 
00217         al = l_g(bufa, a);
00218         for(ba = bufa; *ba == ' '; ba++)
00219                 --al;
00220         bl = l_g(bufb, b) + 1;  /* intentionally high by 1 */
00221         for(bb = bufb; *bb == ' '; bb++)
00222                 --bl;
00223         if(f__recpos + al + bl + 3 >= L_len)
00224                 donewrec();
00225 #ifdef OMIT_BLANK_CC
00226         else
00227 #endif
00228         PUT(' ');
00229         PUT('(');
00230         l_put(ba);
00231         PUT(',');
00232         if (f__recpos + bl >= L_len) {
00233                 (*f__donewrec)();
00234 #ifndef OMIT_BLANK_CC
00235                 PUT(' ');
00236 #endif
00237                 }
00238         l_put(bb);
00239         PUT(')');
00240 }
00241 
00242  int
00243 #ifdef KR_headers
00244 l_write(number,ptr,len,type) ftnint *number,type; char *ptr; ftnlen len;
00245 #else
00246 l_write(ftnint *number, char *ptr, ftnlen len, ftnint type)
00247 #endif
00248 {
00249 #define Ptr ((flex *)ptr)
00250         int i;
00251         longint x;
00252         double y,z;
00253         real *xx;
00254         doublereal *yy;
00255         for(i=0;i< *number; i++)
00256         {
00257                 switch((int)type)
00258                 {
00259                 default: f__fatal(117,"unknown type in lio");
00260                 case TYINT1:
00261                         x = Ptr->flchar;
00262                         goto xint;
00263                 case TYSHORT:
00264                         x=Ptr->flshort;
00265                         goto xint;
00266 #ifdef Allow_TYQUAD
00267                 case TYQUAD:
00268                         x = Ptr->fllongint;
00269                         goto xint;
00270 #endif
00271                 case TYLONG:
00272                         x=Ptr->flint;
00273                 xint:   lwrt_I(x);
00274                         break;
00275                 case TYREAL:
00276                         y=Ptr->flreal;
00277                         goto xfloat;
00278                 case TYDREAL:
00279                         y=Ptr->fldouble;
00280                 xfloat: lwrt_F(y);
00281                         break;
00282                 case TYCOMPLEX:
00283                         xx= &Ptr->flreal;
00284                         y = *xx++;
00285                         z = *xx;
00286                         goto xcomplex;
00287                 case TYDCOMPLEX:
00288                         yy = &Ptr->fldouble;
00289                         y= *yy++;
00290                         z = *yy;
00291                 xcomplex:
00292                         lwrt_C(y,z);
00293                         break;
00294                 case TYLOGICAL1:
00295                         x = Ptr->flchar;
00296                         goto xlog;
00297                 case TYLOGICAL2:
00298                         x = Ptr->flshort;
00299                         goto xlog;
00300                 case TYLOGICAL:
00301                         x = Ptr->flint;
00302                 xlog:   lwrt_L(Ptr->flint, len);
00303                         break;
00304                 case TYCHAR:
00305                         lwrt_A(ptr,len);
00306                         break;
00307                 }
00308                 ptr += len;
00309         }
00310         return(0);
00311 }
00312 #ifdef __cplusplus
00313 }
00314 #endif


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:56