Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
wnl90to77.c
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001, Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2.1 of the GNU Lesser General Public License 
00007   as published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU Lesser General Public 
00021   License along with this program; if not, write the Free Software 
00022   Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 
00023   USA.
00024 
00025   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00026   Mountain View, CA 94043, or:
00027 
00028   http://www.sgi.com
00029 
00030   For further information regarding this notice, see:
00031 
00032   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00033 
00034 */
00035 
00036 
00037 
00038 #pragma ident "@(#) libf/fio/wnl90to77.c        92.2    06/21/99 10:37:55"
00039 
00040 #include <stdio.h>
00041 #include <errno.h>
00042 #include <cray/nassert.h>
00043 #include <liberrno.h>
00044 #include "fio.h"
00045 #include "namelist.h"
00046 #include "wnl90def.h"
00047 
00048 /*
00049  *      _wnl90to77 - called by library routine wnl90.c to write a cf77
00050  *                      namelist output file.
00051  *
00052  *      Synopsis
00053  *              int _wnl90to77( css,
00054  *                              unit *cup,
00055  *                              nmlist_group *namlist,
00056  *                              void *stck,
00057  *                              int errf);
00058  *
00059  *              Where
00060  *                      css     pointer to css
00061  *                      cup     pointer to the unit information
00062  *                      namlist pointer to the namelist table.
00063  *                      stck    pointer to stack space which is passed
00064  *                              to each call to _FWN for a particular
00065  *                              statement.  This is used by the library.
00066  *                      errf    Error processing flag.
00067  *
00068  *      Return value
00069  *              errn
00070  */
00071 
00072 int
00073 _wnl90to77(
00074         FIOSPTR         css,
00075         unit            *cup,
00076         nmlist_group    *namlist,
00077         void            *stck,
00078         int             errf)
00079 {
00080         register int    errn;           /* Error number                 */
00081         char            *wptr;          /* pointer to group name        */
00082         unsigned long   wlen;           /* group name length            */
00083         unsigned        wcount;         /* count of namelist items      */
00084         int             icnt;
00085         char            *varptr;        /* ptr to group_obj_list_item   */
00086         unsigned long   varlen;         /* len to group_obj_list_item   */
00087         nmlist_goli_t   *nlvar;         /* ptr to next variable entry   */
00088         long            eqlchr;         /* hold nl equal character      */
00089         long            sepchr;         /* hold nl delimiter character  */
00090         long            nlchr;          /* hold nl group character      */
00091         long            trmchr;         /* hold nl terminator character */
00092         int             trmsize;        /* size of terminator character */
00093 
00094 /****************************************************************************
00095  *      Data Transfer Section
00096  ***************************************************************************/
00097 
00098         errn    = 0;
00099         wcount  = namlist->icount;              /* count of list items  */
00100 
00101         /* set up one set of variables to use where f77 mode */
00102 
00103         eqlchr  = OUT_EQ;
00104         sepchr  = OUT_SEP;
00105         nlchr   = OUT_CHAR;
00106         trmchr  = OUT_CHAR; 
00107         trmsize = 6;
00108         NLCHAR(OUT_ECHO);               /* blank or echo char   */
00109         NLCHAR(nlchr);                  /* ampersand or WNLDELM */
00110 
00111         wptr    = _fcdtocp(namlist->group_name); /* ptr to groupname    */
00112         wlen    = _fcdlen(namlist->group_name); /* len of groupname     */
00113 
00114         /* If length of groupname exceeds recl, put out an error */
00115 
00116         if ((wlen + 4) > cup->unmlsize) {
00117                 errn    = FENLNMSZ;
00118                 ERROR0(errf, css, errn);
00119         }
00120 
00121         /* Move namelist group name to output buffer    */
00122 
00123         for (icnt = 0; icnt < wlen; icnt++) {
00124                 *cup->ulineptr++        = *wptr++;
00125                 cup->ulinemax++;
00126         }
00127 
00128         NLCHAR(' ');                    /* write blank          */
00129         NLCHAR(' ');                    /* write blank          */
00130 
00131         /* WNLLINE specifies one variable per record            */
00132 
00133         NLINE();                        /* new line             */
00134 
00135         nlvar   = namlist->goli;                /* group object pointer */
00136 
00137         while (wcount-- && (errn == 0)) {
00138                 varptr  = _fcdtocp(nlvar->goli_name);
00139                 varlen  = _fcdlen(nlvar->goli_name);
00140 
00141                 /* If length of variable name exceeds recl, issue an err */
00142 
00143                 if (varlen > cup->unmlsize) {
00144                         /* error: group object name too big for rec size */
00145                         errn    = FENLNMSZ;
00146                         ERROR0(errf, css, errn);
00147                 }
00148                 else
00149                         if (varlen > (cup->unmlsize - cup->ulinemax)) {
00150                                 NLWFLUSH();
00151                                 NLCHAR(' ');            /* write blank  */
00152                                 NLCHAR(' ');            /* write blank  */
00153                         }
00154 
00155                 /* Write namelist group object name to output buffer */
00156 
00157                 for (icnt = 0; icnt < varlen; icnt++) {
00158                         *cup->ulineptr++        = varptr[icnt];
00159                         cup->ulinemax++;
00160                 }
00161 
00162                 /* Flush output buffer if blank=blank will not fit */
00163 
00164                 if ((cup->unmlsize - cup->ulinemax) < 3) {
00165                         NLWFLUSH();
00166                         NLCHAR(' ');                    /* write blank  */
00167                 }
00168 
00169                 /* Write equal size or replacement character after name */
00170 
00171                 NLCHAR(' ');                    /* write blank          */
00172                 NLCHAR(eqlchr);                 /* write equal sign     */
00173                 NLCHAR(' ');                    /* write blank          */
00174 
00175                 /* Setting ldwinit is needed before first call to _ld_write */
00176 
00177                 css->u.fmt.u.le.ldwinit = 1;
00178 
00179                 /* Write the value of the namelist group object */
00180 
00181                 switch (nlvar->valtype) {
00182 
00183                 case IO_SCALAR:
00184                 {
00185                         void            *vaddr;
00186                         type_packet     tip;    /* Type information packet */
00187                         nmlist_scalar_t *nlscalar; /* nmlist scalar entry */
00188 
00189                         nlscalar        = nlvar->goli_addr.ptr;
00190                         tip.type90      = nlscalar->tinfo.type;
00191                         tip.type77      = -1;
00192                         tip.intlen      = nlscalar->tinfo.int_len;
00193                         tip.extlen      = tip.intlen;
00194                         tip.elsize      = tip.intlen >> 3;
00195                         tip.cnvindx     = 0;
00196                         tip.count       = 1;
00197                         tip.stride      = 1;
00198 
00199                         /* Assertions */
00200 
00201                         assert (tip.type90 >= DVTYPE_TYPELESS &&
00202                                 tip.type90 <= DVTYPE_ASCII);
00203                         assert (tip.intlen > 0);
00204 
00205                         if (tip.type90 == DVTYPE_ASCII) {
00206                                 vaddr           = _fcdtocp(nlscalar->scal_addr.charptr);
00207 
00208                                 tip.elsize      = tip.elsize *
00209                                                 _fcdlen(nlscalar->scal_addr.charptr);
00210                         }
00211                         else
00212                                 vaddr   = nlscalar->scal_addr.ptr;
00213 
00214                         /* Do not allow double complex for 77 mode */
00215 
00216                         if ((tip.type90 == DVTYPE_COMPLEX &&
00217                              tip.elsize == (sizeof(_f_dble) * 2)))
00218                                 errn    = FENLDBCP;
00219                         else /* Use list-directed write */
00220                                 errn    = _ld_write(css, cup, vaddr, &tip, 0);
00221 
00222                         break;
00223                 }
00224 
00225                 case IO_DOPEVEC:
00226                 {
00227                         register short  nc;
00228                         register long   extent;
00229                         void            *vaddr;
00230                         type_packet     tip;
00231                         DopeVectorType  *nldv;
00232 
00233                         nldv    = nlvar->goli_addr.dv; /* ptr to dope vec */
00234 
00235                         /* Assertions */
00236 
00237                         assert (nldv != NULL);
00238                         assert (nldv->type_lens.int_len > 0);
00239 
00240                         tip.type90      = nldv->type_lens.type;
00241                         tip.type77      = -1;
00242                         tip.intlen      = nldv->type_lens.int_len;
00243                         tip.extlen      = tip.intlen;
00244                         tip.elsize      = tip.intlen >> 3;
00245                         tip.cnvindx     = 0;
00246                         tip.stride      = 1;
00247 
00248                         if (tip.type90 == DVTYPE_ASCII) {
00249                                 vaddr           = _fcdtocp(nldv->base_addr.charptr);
00250                                 tip.elsize      = tip.elsize *
00251                                                 _fcdlen(nldv->base_addr.charptr);
00252                         }
00253                         else
00254                                 vaddr   = nldv->base_addr.a.ptr;
00255 
00256                         extent  = 1;
00257 
00258                         for (nc = 0; nc < nldv->n_dim; nc++)
00259                                 extent  = extent * nldv->dimension[nc].extent;
00260 
00261                         tip.count       = extent;
00262 
00263                         /* Assertions */
00264 
00265                         assert (tip.elsize > 0 && extent > 0);
00266 
00267                         /* Do not allow double complex for 77 mode */
00268 
00269                         if ((tip.type90 == DVTYPE_COMPLEX &&
00270                              tip.elsize == (sizeof(_f_dble) * 2)))
00271                                 errn    = FENLDBCP;
00272                         else /* Use list-directed write */
00273                                 errn    = _ld_write(css, cup, vaddr, &tip, 0);
00274 
00275                         break;
00276                 }
00277 
00278                 case IO_STRUC_A:
00279                 case IO_STRUC_S:
00280                 {
00281                         /* Do not allow structures for 77 mode */
00282                         errn    = FENLSTCT;
00283                 }
00284 
00285                 default:
00286                         errn    = FEINTUNK;     /* Internal error */
00287                 } /* switch */
00288 
00289                 if (errn != 0) {
00290                         ERROR0(errf, css, errn);
00291                 }
00292 
00293                 /* Flush out last item to record buffer */
00294 
00295                 errn    = _ld_write(css, cup, (void *) NULL, &__tip_null, 0);
00296 
00297                 if (errn != 0) {
00298                         ERROR0(errf, css, errn);
00299                 }
00300 
00301                 if (wcount > 0) {
00302                         if ((cup->unmlsize - cup->ulinemax) < 2) {
00303                                 NLWFLUSH();
00304                                 NLCHAR(' ');    /* write delimiter */
00305                                 NLCHAR(' ');    /* write delimiter */
00306                                 css->u.fmt.u.le.ldwinit = 1;/* suppress comma */
00307                         }
00308                         else {
00309                                 NLCHAR(sepchr); /* write comma */
00310                                 NLCHAR(' ');    /* write delimiter */
00311                                 css->u.fmt.u.le.ldwinit = 1;/* suppress comma */
00312                                 NLINE();         /* new line    */
00313                         }
00314                 }
00315 
00316 #if     defined(__mips) && (_MIPS_SZLONG == 32)
00317                 nlvar   = (nmlist_goli_t*)((long *)nlvar + 3 +
00318                                 (sizeof(_fcd))/(sizeof(long)));
00319 #else
00320                 nlvar   = (nmlist_goli_t*)((long *)nlvar + 2 +
00321                                 (sizeof(_fcd))/(sizeof(long)));
00322 #endif
00323         }
00324 
00325         if (cup->ulinemax > 2) {
00326                 NLINE();         /* new line    */
00327         }
00328 
00329         if ((cup->unmlsize - cup->ulinemax) < trmsize) {
00330                 NLWFLUSH();
00331                 NLCHAR(' ');                    /* write blank  */
00332         }
00333 
00334         /* CF77 ends namelist with compat character (does accept slash) */
00335 
00336         NLCHAR(' ');                    /* write blank  */
00337         NLCHAR(trmchr);                 /* write ending slash   */
00338         NLCHAR('E');                    /* write END            */
00339         NLCHAR('N');
00340         NLCHAR('D');
00341         NLWFLUSH();
00342 
00343         if (errn != 0)
00344                 cup->uflag      = cup->uflag | _UERRC;  /* Set error status */
00345 
00346 /****************************************************************************
00347  *
00348  *      Statement Finalization Section
00349  *
00350  ***************************************************************************/
00351 finalization:
00352         return(errn);
00353 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines