1 /*
2 * ***************************************************************************
3 * MALOC = < Minimal Abstraction Layer for Object-oriented C >
4 * Copyright (C) 1994-- Michael Holst
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * rcsid="$Id: ziofb.c,v 1.17 2010/08/12 05:40:35 fetk Exp $"
21 * ***************************************************************************
22 */
23
24 /*
25 * ***************************************************************************
26 * File: ziofb.c
27 *
28 * Purpose: FORTRAN bindings for the Vio class methods.
29 *
30 * Notes: We provide FORTRAN stubs for the following manglings:
31 *
32 * vrnd --> no underscore, lowercase (default)
33 * VRND --> no underscore, uppercase
34 * vrnd_ --> single underscore, lowercase
35 * VRND_ --> single underscore, uppercase
36 * vrnd__ --> double underscore, lowercase
37 * VRND__ --> double underscore, uppercase
38 *
39 * Author: Michael Holst
40 * ***************************************************************************
41 */
42
43 #include "vio_p.h"
44
45 VEMBED(rcsid="$Id: ziofb.c,v 1.17 2010/08/12 05:40:35 fetk Exp $")
46
47 /*
48 * ***************************************************************************
49 * Class Vio FORTRAN binding prototypes (default: no underscore, lowercase)
50 * ***************************************************************************
51 */
52
53 VEXTERNC void ziosta(void);
54 VEXTERNC void ziostp(void);
55 VEXTERNC void zioctr(Vio *sock,
56 char type[4], char frmt[3],
57 char *host, int *lenh, char *file, int *lenf,
58 char mode[1], int *iflag);
59 VEXTERNC void ziodtr(Vio *sock, int *iflag);
60 VEXTERNC void zioutl(Vio *sock, char mode[1], int *iflag);
61 VEXTERNC void zioint(Vio *sock, int *ival, int *len);
62 VEXTERNC void zioflt(Vio *sock, float *fval, int *len);
63 VEXTERNC void ziodbl(Vio *sock, double *dval, int *len);
64 VEXTERNC void ziostr(Vio *sock, char *sval, int *len);
65
66 /*
67 * ***************************************************************************
68 * Class Vio FORTRAN bindings
69 * ***************************************************************************
70 */
71
72 /*
73 * ***************************************************************************
74 * Routine: ziosta
75 *
76 * Purpose: Start the Vio communication layer.
77 *
78 * Author: Michael Holst
79 * ***************************************************************************
80 */
ziosta(void)81 VPUBLIC void ziosta(void)
82 {
83 Vio_start();
84 }
85
86 /*
87 * ***************************************************************************
88 * Routine: ziostp
89 *
90 * Purpose: Stop the Vio communication layer.
91 *
92 * Author: Michael Holst
93 * ***************************************************************************
94 */
ziostp(void)95 VPUBLIC void ziostp(void)
96 {
97 Vio_stop();
98 }
99
100 /*
101 * ***************************************************************************
102 * Routine: zioctr
103 *
104 * Purpose: Construct the Vio object.
105 *
106 * Author: Michael Holst
107 * ***************************************************************************
108 */
zioctr(Vio * sock,char type[4],char frmt[3],char * host,int * lenh,char * file,int * lenf,char mode[1],int * iflag)109 VPUBLIC void zioctr(Vio *sock,
110 char type[4], char frmt[3],
111 char *host, int *lenh, char *file, int *lenf,
112 char mode[1], int *iflag)
113 {
114 int i;
115 char phost[VMAX_ARGLEN], pfile[VMAX_ARGLEN], ptype[VMAX_ARGLEN];
116 char pfrmt[VMAX_ARGLEN], pmode[VMAX_ARGLEN];
117
118 #if 0
119 Vio sockSize;
120 fprintf(stderr,"zioctr: Vio structure size is exactly <%d> bytes.\n",
121 sizeof(sockSize) );
122 #endif
123
124 for (i=0; i<4; i++) ptype[i] = type[i];
125 ptype[4] = '\0';
126 for (i=0; i<3; i++) pfrmt[i] = frmt[i];
127 pfrmt[3] = '\0';
128 for (i=0; i<*lenh; i++) phost[i] = host[i];
129 phost[*lenh] = '\0';
130 for (i=0; i<*lenf; i++) pfile[i] = file[i];
131 pfile[*lenf] = '\0';
132 pmode[0] = mode[0];
133 pmode[1] = '\0';
134
135 VJMPERR1(0 != Vio_ctor2(sock, ptype, pfrmt, phost, pfile, pmode));
136
137 *iflag = 0;
138 return;
139
140 VERROR1:
141 *iflag = 1;
142 return;
143 }
144
145 /*
146 * ***************************************************************************
147 * Routine: ziodtr
148 *
149 * Purpose: Destruct the Vio object.
150 *
151 * Author: Michael Holst
152 * ***************************************************************************
153 */
ziodtr(Vio * sock,int * iflag)154 VPUBLIC void ziodtr(Vio *sock, int *iflag)
155 {
156 Vio_dtor2(sock);
157 *iflag = 0;
158 return;
159 }
160
161 /*
162 * ***************************************************************************
163 * Routine: zioutl
164 *
165 * Purpose: Vio state utility.
166 *
167 * Author: Michael Holst
168 * ***************************************************************************
169 */
zioutl(Vio * sock,char mode[1],int * iflag)170 VPUBLIC void zioutl(Vio *sock, char mode[1], int *iflag)
171 {
172 char pmode[VMAX_ARGLEN];
173
174 pmode[0] = mode[0];
175 pmode[1] = '\0';
176
177 if ( !strcmp(pmode,"o") ) {
178
179 if ( sock->rwkey == VIO_R ) {
180 /* BLOCKING READ (blocking accept) */
181 VJMPERR1( 0 <= Vio_accept(sock,0) );
182 } else if ( sock->rwkey == VIO_W ) {
183 /* BLOCKING WRITE (blocking connect) */
184 VJMPERR1( 0 <= Vio_connect(sock,0) );
185 } else { VJMPERR1(0); }
186
187 *iflag = 0;
188 return;
189
190 } else if (!strcmp(pmode,"c")) {
191
192 if ( sock->rwkey == VIO_R ) {
193 Vio_acceptFree(sock);
194 } else if ( sock->rwkey == VIO_W ) {
195 Vio_connectFree(sock);
196 } else { VJMPERR1(0); }
197
198 *iflag = 0;
199 return;
200
201 } else { VJMPERR1(0); }
202
203 VERROR1:
204 *iflag = 1;
205 return;
206 }
207
208 /*
209 * ***************************************************************************
210 * Routine: zioint
211 *
212 * Purpose: Integer READ/WRITE.
213 *
214 * Author: Michael Holst
215 * ***************************************************************************
216 */
zioint(Vio * sock,int * ival,int * len)217 VPUBLIC void zioint(Vio *sock, int *ival, int *len)
218 {
219 int i;
220
221 if ( sock->rwkey == VIO_R ) {
222 for (i=0; i<*len; i++)
223 Vio_scanf(sock,"%d",&(ival[i]));
224 } else if ( sock->rwkey == VIO_W ) {
225 for (i=0; i<*len; i++)
226 Vio_printf(sock,"%d ",ival[i]);
227 Vio_printf(sock,"\n");
228 }
229 }
230
231 /*
232 * ***************************************************************************
233 * Routine: zioflt
234 *
235 * Purpose: Float READ/WRITE.
236 *
237 * Author: Michael Holst
238 * ***************************************************************************
239 */
zioflt(Vio * sock,float * fval,int * len)240 VPUBLIC void zioflt(Vio *sock, float *fval, int *len)
241 {
242 int i;
243
244 if ( sock->rwkey == VIO_R ) {
245 for (i=0; i<*len; i++)
246 Vio_scanf(sock,"%e",&(fval[i]));
247 } else if ( sock->rwkey == VIO_W ) {
248 for (i=0; i<*len; i++)
249 Vio_printf(sock,"%e ",fval[i]);
250 Vio_printf(sock,"\n");
251 }
252 }
253
254 /*
255 * ***************************************************************************
256 * Routine: ziodbl
257 *
258 * Purpose: Double READ/WRITE.
259 *
260 * Author: Michael Holst
261 * ***************************************************************************
262 */
ziodbl(Vio * sock,double * dval,int * len)263 VPUBLIC void ziodbl(Vio *sock, double *dval, int *len)
264 {
265 int i;
266
267 if ( sock->rwkey == VIO_R ) {
268 for (i=0; i<*len; i++)
269 Vio_scanf(sock,"%le",&(dval[i]));
270 } else if ( sock->rwkey == VIO_W ) {
271 for (i=0; i<*len; i++)
272 Vio_printf(sock,"%le ",dval[i]);
273 Vio_printf(sock,"\n");
274 }
275 }
276
277 /*
278 * ***************************************************************************
279 * Routine: ziostr
280 *
281 * Purpose: String READ/WRITE.
282 *
283 * Author: Michael Holst
284 * ***************************************************************************
285 */
ziostr(Vio * sock,char * sval,int * len)286 VPUBLIC void ziostr(Vio *sock, char *sval, int *len)
287 {
288 int i;
289 char buf[VMAX_BUFSIZE];
290
291 if ( sock->rwkey == VIO_R ) {
292 Vio_scanf(sock,"%s",buf);
293 VASSERT( (int)strlen(buf) == *len );
294 for (i=0; i<*len; i++) sval[i] = buf[i];
295 } else if ( sock->rwkey == VIO_W ) {
296 for (i=0; i<*len; i++) buf[i] = sval[i];
297 buf[*len] = '\0';
298 Vio_printf(sock,"%s\n",buf);
299 }
300 }
301
302 /*
303 * ***************************************************************************
304 * Class Vio FORTRAN binding STUBS (no underscore, uppercase)
305 * ***************************************************************************
306 */
307
ZIOSTA(void)308 VPUBLIC void ZIOSTA(void)
309 {
310 ziosta();
311 }
312
ZIOSTP(void)313 VPUBLIC void ZIOSTP(void)
314 {
315 ziostp();
316 }
317
ZIOCTR(Vio * sock,char type[4],char frmt[3],char * host,int * lenh,char * file,int * lenf,char mode[1],int * iflag)318 VPUBLIC void ZIOCTR(Vio *sock,
319 char type[4], char frmt[3],
320 char *host, int *lenh, char *file, int *lenf,
321 char mode[1], int *iflag)
322 {
323 zioctr(sock, type, frmt, host, lenh, file, lenf, mode, iflag);
324 }
325
ZIODTR(Vio * sock,int * iflag)326 VPUBLIC void ZIODTR(Vio *sock, int *iflag)
327 {
328 ziodtr(sock, iflag);
329 }
330
ZIOUTL(Vio * sock,char mode[1],int * iflag)331 VPUBLIC void ZIOUTL(Vio *sock, char mode[1], int *iflag)
332 {
333 zioutl(sock, mode, iflag);
334 }
335
ZIOINT(Vio * sock,int * ival,int * len)336 VPUBLIC void ZIOINT(Vio *sock, int *ival, int *len)
337 {
338 zioint(sock, ival, len);
339 }
340
ZIOFLT(Vio * sock,float * fval,int * len)341 VPUBLIC void ZIOFLT(Vio *sock, float *fval, int *len)
342 {
343 zioflt(sock, fval, len);
344 }
345
ZIODBL(Vio * sock,double * dval,int * len)346 VPUBLIC void ZIODBL(Vio *sock, double *dval, int *len)
347 {
348 ziodbl(sock, dval, len);
349 }
350
ZIOSTR(Vio * sock,char * sval,int * len)351 VPUBLIC void ZIOSTR(Vio *sock, char *sval, int *len)
352 {
353 ziostr(sock, sval, len);
354 }
355
356 /*
357 * ***************************************************************************
358 * Class Vio FORTRAN binding STUBS (single underscore, lowercase)
359 * ***************************************************************************
360 */
361
ziosta_(void)362 VPUBLIC void ziosta_(void)
363 {
364 ziosta();
365 }
366
ziostp_(void)367 VPUBLIC void ziostp_(void)
368 {
369 ziostp();
370 }
371
zioctr_(Vio * sock,char type[4],char frmt[3],char * host,int * lenh,char * file,int * lenf,char mode[1],int * iflag)372 VPUBLIC void zioctr_(Vio *sock,
373 char type[4], char frmt[3],
374 char *host, int *lenh, char *file, int *lenf,
375 char mode[1], int *iflag)
376 {
377 zioctr(sock, type, frmt, host, lenh, file, lenf, mode, iflag);
378 }
379
ziodtr_(Vio * sock,int * iflag)380 VPUBLIC void ziodtr_(Vio *sock, int *iflag)
381 {
382 ziodtr(sock, iflag);
383 }
384
zioutl_(Vio * sock,char mode[1],int * iflag)385 VPUBLIC void zioutl_(Vio *sock, char mode[1], int *iflag)
386 {
387 zioutl(sock, mode, iflag);
388 }
389
zioint_(Vio * sock,int * ival,int * len)390 VPUBLIC void zioint_(Vio *sock, int *ival, int *len)
391 {
392 zioint(sock, ival, len);
393 }
394
zioflt_(Vio * sock,float * fval,int * len)395 VPUBLIC void zioflt_(Vio *sock, float *fval, int *len)
396 {
397 zioflt(sock, fval, len);
398 }
399
ziodbl_(Vio * sock,double * dval,int * len)400 VPUBLIC void ziodbl_(Vio *sock, double *dval, int *len)
401 {
402 ziodbl(sock, dval, len);
403 }
404
ziostr_(Vio * sock,char * sval,int * len)405 VPUBLIC void ziostr_(Vio *sock, char *sval, int *len)
406 {
407 ziostr(sock, sval, len);
408 }
409
410 /*
411 * ***************************************************************************
412 * Class Vio FORTRAN binding STUBS (single underscore, uppercase)
413 * ***************************************************************************
414 */
415
ZIOSTA_(void)416 VPUBLIC void ZIOSTA_(void)
417 {
418 ziosta();
419 }
420
ZIOSTP_(void)421 VPUBLIC void ZIOSTP_(void)
422 {
423 ziostp();
424 }
425
ZIOCTR_(Vio * sock,char type[4],char frmt[3],char * host,int * lenh,char * file,int * lenf,char mode[1],int * iflag)426 VPUBLIC void ZIOCTR_(Vio *sock,
427 char type[4], char frmt[3],
428 char *host, int *lenh, char *file, int *lenf,
429 char mode[1], int *iflag)
430 {
431 zioctr(sock, type, frmt, host, lenh, file, lenf, mode, iflag);
432 }
433
ZIODTR_(Vio * sock,int * iflag)434 VPUBLIC void ZIODTR_(Vio *sock, int *iflag)
435 {
436 ziodtr(sock, iflag);
437 }
438
ZIOUTL_(Vio * sock,char mode[1],int * iflag)439 VPUBLIC void ZIOUTL_(Vio *sock, char mode[1], int *iflag)
440 {
441 zioutl(sock, mode, iflag);
442 }
443
ZIOINT_(Vio * sock,int * ival,int * len)444 VPUBLIC void ZIOINT_(Vio *sock, int *ival, int *len)
445 {
446 zioint(sock, ival, len);
447 }
448
ZIOFLT_(Vio * sock,float * fval,int * len)449 VPUBLIC void ZIOFLT_(Vio *sock, float *fval, int *len)
450 {
451 zioflt(sock, fval, len);
452 }
453
ZIODBL_(Vio * sock,double * dval,int * len)454 VPUBLIC void ZIODBL_(Vio *sock, double *dval, int *len)
455 {
456 ziodbl(sock, dval, len);
457 }
458
ZIOSTR_(Vio * sock,char * sval,int * len)459 VPUBLIC void ZIOSTR_(Vio *sock, char *sval, int *len)
460 {
461 ziostr(sock, sval, len);
462 }
463
464 /*
465 * ***************************************************************************
466 * Class Vio FORTRAN binding STUBS (double underscore, lowercase)
467 * ***************************************************************************
468 */
469
ziosta__(void)470 VPUBLIC void ziosta__(void)
471 {
472 ziosta();
473 }
474
ziostp__(void)475 VPUBLIC void ziostp__(void)
476 {
477 ziostp();
478 }
479
zioctr__(Vio * sock,char type[4],char frmt[3],char * host,int * lenh,char * file,int * lenf,char mode[1],int * iflag)480 VPUBLIC void zioctr__(Vio *sock,
481 char type[4], char frmt[3],
482 char *host, int *lenh, char *file, int *lenf,
483 char mode[1], int *iflag)
484 {
485 zioctr(sock, type, frmt, host, lenh, file, lenf, mode, iflag);
486 }
487
ziodtr__(Vio * sock,int * iflag)488 VPUBLIC void ziodtr__(Vio *sock, int *iflag)
489 {
490 ziodtr(sock, iflag);
491 }
492
zioutl__(Vio * sock,char mode[1],int * iflag)493 VPUBLIC void zioutl__(Vio *sock, char mode[1], int *iflag)
494 {
495 zioutl(sock, mode, iflag);
496 }
497
zioint__(Vio * sock,int * ival,int * len)498 VPUBLIC void zioint__(Vio *sock, int *ival, int *len)
499 {
500 zioint(sock, ival, len);
501 }
502
zioflt__(Vio * sock,float * fval,int * len)503 VPUBLIC void zioflt__(Vio *sock, float *fval, int *len)
504 {
505 zioflt(sock, fval, len);
506 }
507
ziodbl__(Vio * sock,double * dval,int * len)508 VPUBLIC void ziodbl__(Vio *sock, double *dval, int *len)
509 {
510 ziodbl(sock, dval, len);
511 }
512
ziostr__(Vio * sock,char * sval,int * len)513 VPUBLIC void ziostr__(Vio *sock, char *sval, int *len)
514 {
515 ziostr(sock, sval, len);
516 }
517
518 /*
519 * ***************************************************************************
520 * Class Vio FORTRAN binding STUBS (double underscore, uppercase)
521 * ***************************************************************************
522 */
523
ZIOSTA__(void)524 VPUBLIC void ZIOSTA__(void)
525 {
526 ziosta();
527 }
528
ZIOSTP__(void)529 VPUBLIC void ZIOSTP__(void)
530 {
531 ziostp();
532 }
533
ZIOCTR__(Vio * sock,char type[4],char frmt[3],char * host,int * lenh,char * file,int * lenf,char mode[1],int * iflag)534 VPUBLIC void ZIOCTR__(Vio *sock,
535 char type[4], char frmt[3],
536 char *host, int *lenh, char *file, int *lenf,
537 char mode[1], int *iflag)
538 {
539 zioctr(sock, type, frmt, host, lenh, file, lenf, mode, iflag);
540 }
541
ZIODTR__(Vio * sock,int * iflag)542 VPUBLIC void ZIODTR__(Vio *sock, int *iflag)
543 {
544 ziodtr(sock, iflag);
545 }
546
ZIOUTL__(Vio * sock,char mode[1],int * iflag)547 VPUBLIC void ZIOUTL__(Vio *sock, char mode[1], int *iflag)
548 {
549 zioutl(sock, mode, iflag);
550 }
551
ZIOINT__(Vio * sock,int * ival,int * len)552 VPUBLIC void ZIOINT__(Vio *sock, int *ival, int *len)
553 {
554 zioint(sock, ival, len);
555 }
556
ZIOFLT__(Vio * sock,float * fval,int * len)557 VPUBLIC void ZIOFLT__(Vio *sock, float *fval, int *len)
558 {
559 zioflt(sock, fval, len);
560 }
561
ZIODBL__(Vio * sock,double * dval,int * len)562 VPUBLIC void ZIODBL__(Vio *sock, double *dval, int *len)
563 {
564 ziodbl(sock, dval, len);
565 }
566
ZIOSTR__(Vio * sock,char * sval,int * len)567 VPUBLIC void ZIOSTR__(Vio *sock, char *sval, int *len)
568 {
569 ziostr(sock, sval, len);
570 }
571
572