"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "eas3pkg/eas3/coviseio.c" of archive eas3pkg_v1.6.3.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 /*-------------------------------------------------------------------------------------------------------*/
    2 /* EAS3 License                                                                                          */
    3 /*                                                                                                       */
    4 /* Copyright (c) 2006 Institut fuer Aerodynamik und Gasdynamik, Universitaet Stuttgart                   */
    5 /*                                                                                                       */
    6 /* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and     */
    7 /* associated documentation files (the "Software"), to deal in the Software without restriction,         */
    8 /* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, */
    9 /* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, */
   10 /* subject to the following conditions:                                                                  */
   11 /*                                                                                                       */
   12 /* The above copyright notice and this permission notice shall be included in all copies or substantial  */
   13 /* portions of the Software.										 */
   14 /*                                                                                                       */
   15 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT */
   16 /* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   */
   17 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER          */
   18 /* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION */
   19 /* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                       */
   20 /*-------------------------------------------------------------------------------------------------------*/
   21 /* ----------------------------------------------------------------------
   22  * project: coviseio (EAS3)
   23  * file:    coviseio.c
   24  * author:  Kai Augustin <augustin@iag.uni-stuttgart.de>
   25  *          Juli 2000
   26  * ----------------------------------------------------------------------
   27  * IO-Subroutinen der coviseio-Bibliothek <libcovise.a>
   28  * ----------------------------------------------------------------------
   29  */
   30 
   31 #include <stdlib.h>
   32 #include <stdio.h>
   33 #include <string.h>
   34 #include <stdarg.h>
   35 #include <limits.h>
   36 #include <math.h>
   37 #include <errno.h>
   38 #include <sys/types.h>
   39 #include <sys/stat.h>
   40 #include <fcntl.h>
   41 
   42 #include "coviseio.h"
   43 
   44 /************************************************************************
   45  * C_COV : FELD mit Information ueber jede offene Datei                 *
   46  ************************************************************************/
   47 dathead* datinfo[MAXFILES] ;
   48 
   49 /* Funktionen von libcovise.a */
   50 
   51 /************************************************************************
   52  * C_COV : C_COVOPEN                                                    *
   53  * Anlegen der zu schreibenden COVISE Dateien                           *
   54  ************************************************************************/
   55 void C_COVOPEN(const Int64 *buf, const char *fname, const Int64 *nzs,
   56 	       const Int64 *ftype, const Int64 *writegrid, Int64 *status)
   57 {
   58   int         bnr ;                 /* Uebersetzte Puffernummer       */
   59   char        *covisepos ;          /* Position von .covise im Namen  */
   60   static char *setele = "SETELE" ;  /* Keyword fuer mehr als ein      */
   61                                     /* Zeitschritt                    */
   62 
   63   bnr = (int)(*buf) ;
   64 
   65   /* Filepuffer anlegen */
   66   datinfo[bnr] = (dathead*)cov_calloc(1,sizeof(dathead),
   67 				       __FILE__, __LINE__) ;
   68 
   69   /* Daten in das Infofeld uebertragen */
   70   datinfo[bnr]->nzs       = (int)*nzs ;
   71   datinfo[bnr]->ftype     = (int)*ftype ;
   72   datinfo[bnr]->writegrid = (int)*writegrid ;
   73   datinfo[bnr]->datfile   = NULL ;
   74   datinfo[bnr]->gridfile  = NULL ;
   75   datinfo[bnr]->wdat      = -1 ;
   76   datinfo[bnr]->wgrid     = -1 ;
   77   datinfo[bnr]->fpdat     = 0 ;
   78   datinfo[bnr]->fpgrid    = 0 ;
   79 
   80   /* Haengt ein .covise am Dateinamen ? */
   81   covisepos = strstr(fname,".covise") ;
   82 
   83   /* Wenn gewuenscht (writegrid == 1) Griddatei anlegen ! */
   84   if (datinfo[bnr]->writegrid)
   85     {
   86       if (covisepos != NULL)
   87 	{
   88 	  datinfo[bnr]->gridfile=(char *)cov_calloc(
   89 				  (int)(strlen(fname)+6),
   90 				  sizeof(char),__FILE__, __LINE__) ;
   91 	  strncpy(datinfo[bnr]->gridfile,fname,
   92 		  (size_t)(strlen(fname)-strlen(covisepos))) ;
   93 	  datinfo[bnr]->gridfile[strlen(fname)-strlen(covisepos)]='\0';
   94 	  strcat(datinfo[bnr]->gridfile,".grid.covise") ;
   95 	}
   96       else
   97 	{
   98 	  datinfo[bnr]->gridfile=(char*)cov_calloc(
   99 				  (int)(strlen(fname)+13),
  100 			          sizeof(char),__FILE__, __LINE__) ;
  101 	  strcpy(datinfo[bnr]->gridfile,fname) ;
  102 	  strcat(datinfo[bnr]->gridfile,".grid.covise") ;
  103 	}
  104 
  105       cov_debug(5,__FILE__, __LINE__,
  106 		"C_COVOPEN() : Oeffne Gitterdatei ",
  107 		datinfo[bnr]->gridfile,"\n") ;
  108 
  109       /* Fileptr bestimmen fuer die Datendatei */
  110       if ((datinfo[bnr]->fpgrid = open(datinfo[bnr]->gridfile,
  111 				     O_WRONLY|O_CREAT|O_TRUNC,FMODE)) <0)
  112 	{
  113 	  cov_debug(6,__FILE__, __LINE__,
  114 		    "C_COVOPEN() : Fataler Fehler beim ",
  115 		    "Anlegen der Gitterdatei ",
  116 		    datinfo[bnr]->gridfile,"\n") ;
  117 	  *status = -2 ;
  118           return ;
  119       }
  120       /* Datinfo auf geoffnet setzen */
  121       datinfo[bnr]->wgrid = 0 ;
  122 
  123       /* Falls mehr als ein Zeitschritt (nzs > 1) in die Datei soll.. */
  124       if (datinfo[bnr]->nzs > 1)
  125 	{
  126 	  if (cov_writetofile(datinfo[bnr]->fpgrid,
  127 			      COV_ISSTRING,setele,6) == -1)
  128 	    {
  129 	      cov_debug(4,__FILE__, __LINE__,
  130 			"C_COVOPEN() : Fataler Fehler beim Schreiben \n",
  131 			"von SETELE in die Gitterdatei\n") ;
  132 	      *status = -4 ;
  133 	      return ;
  134 	      }
  135 	  if (cov_writetofile(datinfo[bnr]->fpgrid,
  136 			      COV_ISINT,&datinfo[bnr]->nzs,1) == -1)
  137 	    {
  138 	      cov_debug(4,__FILE__, __LINE__,
  139 			"C_COVOPEN() : Fataler Fehler beim Schreiben \n",
  140 			"der Zeitschrittzahl in die Gitterdatei\n") ;
  141 	      *status = -4 ;
  142 	      return ;
  143 	    }
  144 	}
  145     }
  146 
  147   /* Datendatei anlegen */
  148   switch (datinfo[bnr]->ftype)
  149     {
  150     case 0:
  151       if (covisepos != NULL)
  152 	{
  153 	  datinfo[bnr]->datfile=(char *)cov_calloc(
  154                                       (int)(strlen(fname)+6),
  155 				      sizeof(char),__FILE__, __LINE__) ;
  156 	  strncpy(datinfo[bnr]->datfile,fname,
  157 		  (size_t)(strlen(fname)-strlen(covisepos))) ;
  158 	  datinfo[bnr]->datfile[strlen(fname)-strlen(covisepos)]='\0';
  159 	  strcat(datinfo[bnr]->datfile,".scal.covise") ;
  160 	}
  161       else
  162 	{
  163 	  datinfo[bnr]->datfile=(char*)cov_calloc(
  164 			         (int)(strlen(fname)+13),
  165 			         sizeof(char),__FILE__, __LINE__) ;
  166 	  strcpy(datinfo[bnr]->datfile,fname) ;
  167 	  strcat(datinfo[bnr]->datfile,".scal.covise") ;
  168 	}
  169       cov_debug(5,__FILE__, __LINE__,
  170 		"C_COVOPEN() : Oeffne Skalardatei ",
  171 		datinfo[bnr]->datfile,"\n") ;
  172       break ;
  173     case 1:
  174       if (covisepos != NULL)
  175 	{
  176 	  datinfo[bnr]->datfile=(char *)cov_calloc(
  177                                  (int)(strlen(fname)+5),
  178 				 sizeof(char),__FILE__, __LINE__) ;
  179 	  strncpy(datinfo[bnr]->datfile,fname,
  180 		  (size_t)(strlen(fname)-strlen(covisepos))) ;
  181 	  datinfo[bnr]->datfile[strlen(fname)-strlen(covisepos)+1]='\0';
  182 	  strcat(datinfo[bnr]->datfile,".vec.covise") ;
  183 	}
  184       else
  185 	{
  186 	  datinfo[bnr]->datfile=(char*)cov_calloc(
  187 				 (int)(strlen(fname)+12),
  188 			         sizeof(char),__FILE__, __LINE__) ;
  189 	  strcpy(datinfo[bnr]->datfile,fname) ;
  190 	  strcat(datinfo[bnr]->datfile,".vec.covise") ;
  191 	}
  192       cov_debug(5,__FILE__, __LINE__,
  193 		"C_COVOPEN() : Oeffne Vektordatei ",
  194 		datinfo[bnr]->datfile,"\n") ;
  195       break ;
  196     default:
  197       cov_debug(4,__FILE__, __LINE__,
  198 		"C_COVOPEN() : Fataler Fehler - ",
  199                 "COVISE Datentyp unbekannt (Skalar/Vektor)\n") ;
  200       *status = -1 ;
  201       return ;
  202     }
  203 
  204   /* Fileptr bestimmen fuer die Datendatei */
  205   if ((datinfo[bnr]->fpdat = open(datinfo[bnr]->datfile,
  206 				   O_WRONLY|O_CREAT|O_TRUNC,FMODE)) <0)
  207       {
  208         cov_debug(6,__FILE__, __LINE__,
  209 		"C_COVOPEN() : Fataler Fehler beim ",
  210                 "Anlegen der Datendatei ",datinfo[bnr]->datfile,"\n") ;
  211 	*status = -3 ;
  212         return ;
  213       }
  214   /* Datinfo auf geoffnet setzen */
  215   datinfo[bnr]->wdat = 0 ;
  216 
  217   /* Falls mehr als ein Zeitschritt (nzs > 1) in die Datei soll.. */
  218   if (datinfo[bnr]->nzs > 1)
  219     {
  220       if (cov_writetofile(datinfo[bnr]->fpdat,
  221 			  COV_ISSTRING,setele,6) == -1)
  222 	{
  223 	  cov_debug(4,__FILE__, __LINE__,
  224 		    "C_COVOPEN() : Fataler Fehler beim Schreiben von\n",
  225 		    "SETELE in die Datendatei\n") ;
  226 	  *status = -5 ;
  227 	  return ;
  228 	}
  229       if (cov_writetofile(datinfo[bnr]->fpdat,
  230 			  COV_ISINT,&datinfo[bnr]->nzs,1) == -1)
  231 	{
  232 	  cov_debug(4,__FILE__, __LINE__,
  233 		    "C_COVOPEN() : Fataler Fehler beim Schreiben der\n",
  234 		    "Zeitschrittzahl in die Datendatei\n") ;
  235 	  *status = -5 ;
  236 	  return ;
  237 	}
  238     }
  239 
  240   /* Analysieren des Dateinamens */
  241   *status = 0 ;
  242   return ;
  243 }
  244 
  245 /************************************************************************
  246  * C_COV : C_COVGRID                                                    *
  247  * Schreibe ein Gitter nzs-mal in die geoffnete Gitterdatei             *
  248  ************************************************************************/
  249 void C_COVGRID(const Int64 *buf,
  250 	       const Int64 *dim1, const Int64 *dim2, const Int64 *dim3,
  251 	       const Float64 *xcoord, const Float64 *ycoord,
  252 	       const Float64 *zcoord, Int64 *status)
  253 {
  254 
  255   int         bnr ;                /* Uebersetzte Puffernummer */
  256   header      s_h ;                /* COVISE Header         */
  257   float       *xco, *yco, *zco ;   /* Zu schreibende Felder */
  258   int         l ;                  /* Zaehlvariable         */
  259   static char *gitter = "RCTGRD" ; /* COVISE Datentyp rectarlineares */
  260                                    /* Gitter */
  261   const int   attrib    = 0  ;     /* Attribut fuer Covise ab 4.01a */
  262   int         convertstatus ;      /* Floating Point Exception beim */
  263 				   /* Umwandeln ? */
  264   char        outstr[80] ;         /* Ausgabestring fuer debug */
  265 
  266   bnr = (int)(*buf) ;
  267 
  268   if (! datinfo[bnr]->writegrid)
  269     {
  270       cov_debug(4,__FILE__, __LINE__,
  271 		"C_COVGRID() : Versuche unerlaubterweise ",
  272 		"Gitterdatei zu schreiben! \n") ;
  273       *status = -7 ;
  274       return ;
  275     }
  276 
  277   if (datinfo[bnr]->wgrid == -1)
  278     {
  279       cov_debug(3,__FILE__, __LINE__,
  280 		"C_COVGRID() : Gitterdatei nicht geoeffnet\n") ;
  281       *status = -7 ;
  282       return ;
  283     }
  284 
  285   /* Covise Header setzen */
  286   s_h.xs = (int)(*dim1) ;
  287   s_h.ys = (int)(*dim2) ;
  288   s_h.zs = (int)(*dim3) ;
  289 
  290   /* Single Precision Felder erzeugen */
  291   xco=cov_getsingle(xcoord,s_h.xs,__FILE__, __LINE__,&convertstatus);
  292   yco=cov_getsingle(ycoord,s_h.ys,__FILE__, __LINE__,&convertstatus);
  293   zco=cov_getsingle(zcoord,s_h.zs,__FILE__, __LINE__,&convertstatus);
  294 
  295   /* Schreibe die Gitterdatensaetze fuer jeden Zeitschritt */
  296   for (l=0;l<datinfo[bnr]->nzs;l++)
  297     {
  298       sprintf(outstr,"%d",datinfo[bnr]->wgrid+1) ;
  299       cov_debug(5,__FILE__, __LINE__,
  300 		"C_COVGRID() : Schreibe Zeitschritt Nr.  ",outstr,
  301 		" in Gitterdatei\n") ;
  302 
  303       /* Schreibe Datenheader */
  304       if (cov_writetofile(datinfo[bnr]->fpgrid,
  305 			  COV_ISSTRING,gitter,6) == -1)
  306 	{
  307 	  cov_debug(4,__FILE__, __LINE__,
  308 		    "C_COVGRID() : Fataler Fehler beim Schreiben ",
  309 		    "der Gitterdaten\n") ;
  310 	  *status = -6 ;
  311 	  return ;
  312 	}
  313       /* Schreibe Dimensionen */
  314       if (cov_writetofile(datinfo[bnr]->fpgrid,
  315 			  COV_ISINT,&s_h,3) == -1)
  316 	{
  317 	  cov_debug(4,__FILE__, __LINE__,
  318 		    "C_COVGRID() : Fataler Fehler beim Schreiben ",
  319 		    "der Gitterdaten\n") ;
  320 	  *status = -6 ;
  321 	  return ;
  322 	}
  323       /* Schreibe X-Koordinatenfeld */
  324       if (cov_writetofile(datinfo[bnr]->fpgrid,
  325 			  COV_ISFLOAT,xco,s_h.xs) == -1)
  326 	{
  327 	  cov_debug(4,__FILE__, __LINE__,
  328 		    "C_COVGRID() : Fataler Fehler beim Schreiben ",
  329 		    "der Gitterdaten\n") ;
  330 	  *status = -6 ;
  331 	  return ;
  332 	  }
  333       /* Schreibe Y-Koordinatenfeld */
  334       if (cov_writetofile(datinfo[bnr]->fpgrid,
  335 			  COV_ISFLOAT,yco,s_h.ys) == -1)
  336 	{
  337 	  cov_debug(4,__FILE__, __LINE__,
  338 		    "C_COVGRID() : Fataler Fehler beim Schreiben ",
  339 		    "der Gitterdaten\n") ;
  340 	  *status = -6 ;
  341 	  return ;
  342 	  }
  343       /* Schreibe Z-Koordinatenfeld */
  344       if (cov_writetofile(datinfo[bnr]->fpgrid,
  345 			  COV_ISFLOAT,zco,s_h.zs) == -1)
  346 	{
  347 	  cov_debug(4,__FILE__, __LINE__,
  348 		    "C_COVGRID() : Fataler Fehler beim Schreiben ",
  349 		    "der Gitterdaten\n") ;
  350 	  *status = -6 ;
  351 	  return ;
  352 	  }
  353       /* Schreibe Datenattribute (Hier Null) */
  354       if (cov_writetofile(datinfo[bnr]->fpgrid,
  355 			  COV_ISINT,&attrib,1) == -1)
  356 	{
  357 	  cov_debug(4,__FILE__, __LINE__,
  358 		    "C_COVGRID() : Fataler Fehler beim Schreiben ",
  359 		    "der Gitterdaten\n") ;
  360 	  *status = -6 ;
  361 	  return ;
  362 	}
  363       if (cov_writetofile(datinfo[bnr]->fpgrid,
  364 			  COV_ISINT,&attrib,1) == -1)
  365 	{
  366 	  cov_debug(4,__FILE__, __LINE__,
  367 		    "C_COVGRID() : Fataler Fehler beim Schreiben ",
  368 		    "der Gitterdaten\n") ;
  369 	  *status = -6 ;
  370 	  return ;
  371 	}
  372       /* Zahl der geschriebenen Felder im Header um eins Hochsetzen */
  373       datinfo[bnr]->wgrid++ ;
  374     }
  375 
  376   /* Zusaetzlich allokierte Felder wieder freigeben */
  377   free(xco) ;
  378   free(yco) ;
  379   free(zco) ;
  380 
  381   /* Alles in Ordnung... Hat es vielleicht Floating Point Probleme
  382      gegeben ? */
  383   if (convertstatus != 0) *status=(Int64)convertstatus ;
  384   else *status = 0 ;
  385   return ;
  386 }
  387 
  388 /************************************************************************
  389  * C_COV : C_COVSCAL                                                    *
  390  * Schreibe ein einziges Skalardatenfeld in die Datendatei              *
  391  ************************************************************************/
  392 void C_COVSCAL(const Int64 *buf,
  393 	       const Int64 *dim1, const Int64 *dim2, const Int64 *dim3,
  394 	       const Float64 *data, Int64 *status)
  395 {
  396   int         bnr ;                /* Uebersetzte Puffernummer */
  397   header      s_h ;                /* COVISE Header         */
  398   float       *fdata ;             /* Zu schreibendes Feld */
  399   static char *daten = "STRSDT" ;  /* COVISE Datentyp Skalardaten */
  400   const int   attrib    = 0  ;     /* Attribut fuer Covise ab 4.01a */
  401   int         convertstatus ;      /* Floating Point Exception beim */
  402                                    /* Umwandeln ? */
  403   char        outstr[80] ;         /* Ausgabestring fuer debug */
  404 
  405   bnr = (int)(*buf) ;
  406 
  407   if (datinfo[bnr]->ftype != 0 )
  408     {
  409       cov_debug(4,__FILE__, __LINE__,
  410 		"C_COVSCAL() : Versuche ",
  411 		"Skalardaten in Vektordatei zu schreiben! \n") ;
  412       *status = -7 ;
  413       return ;
  414     }
  415 
  416   if (datinfo[bnr]->wdat == -1)
  417     {
  418       cov_debug(3,__FILE__, __LINE__,
  419 		"C_COVSCAL() : Gitterdatei nicht geoeffnet\n") ;
  420       *status = -7 ;
  421       return ;
  422     }
  423 
  424   /* Covise Header setzen */
  425   s_h.xs = (int)(*dim1) ;
  426   s_h.ys = (int)(*dim2) ;
  427   s_h.zs = (int)(*dim3) ;
  428 
  429   /* Single Precision Felder erzeugen */
  430   fdata=cov_getsingle(data,s_h.xs*s_h.ys*s_h.zs,
  431 		      __FILE__, __LINE__,&convertstatus);
  432 
  433   sprintf(outstr,"%d",datinfo[bnr]->wdat+1) ;
  434   cov_debug(5,__FILE__, __LINE__,
  435 	    "C_COVSCAL() : Schreibe Zeitschritt Nr.  ",outstr,
  436 	    " in Skalardaten-Datei\n") ;
  437 
  438   /* Schreibe Datenheader */
  439   if (cov_writetofile(datinfo[bnr]->fpdat,
  440 			  COV_ISSTRING,daten,6) == -1)
  441     {
  442       cov_debug(4,__FILE__, __LINE__,
  443 		"C_COVSCAL() : Fataler Fehler beim Schreiben ",
  444 		"der Skalardaten\n") ;
  445       *status = -8 ;
  446       return ;
  447     }
  448   /* Schreibe Dimensionen */
  449   if (cov_writetofile(datinfo[bnr]->fpdat,
  450 			  COV_ISINT,&s_h,3) == -1)
  451     {
  452       cov_debug(4,__FILE__, __LINE__,
  453 		"C_COVSCAL() : Fataler Fehler beim Schreiben ",
  454 		"der Skalardaten\n") ;
  455       *status = -8 ;
  456       return ;
  457     }
  458   /* Schreibe Datenfeld */
  459   if (cov_writetofile(datinfo[bnr]->fpdat,
  460 			  COV_ISFLOAT,fdata,s_h.xs*s_h.ys*s_h.zs) == -1)
  461     {
  462       cov_debug(4,__FILE__, __LINE__,
  463 		"C_COVSCAL() : Fataler Fehler beim Schreiben ",
  464 		"der Skalardaten\n") ;
  465       *status = -8 ;
  466       return ;
  467     }
  468   /* Schreibe Datenattribute (Hier Null) */
  469   if (cov_writetofile(datinfo[bnr]->fpdat,
  470 			  COV_ISINT,&attrib,1) == -1)
  471     {
  472       cov_debug(4,__FILE__, __LINE__,
  473 		"C_COVSCAL() : Fataler Fehler beim Schreiben ",
  474 		"der Skalardaten\n") ;
  475       *status = -8 ;
  476       return ;
  477     }
  478   if (cov_writetofile(datinfo[bnr]->fpdat,
  479 			  COV_ISINT,&attrib,1) == -1)
  480     {
  481       cov_debug(4,__FILE__, __LINE__,
  482 		"C_COVSCAL() : Fataler Fehler beim Schreiben ",
  483 		"der Skalardaten\n") ;
  484       *status = -8 ;
  485       return ;
  486     }
  487   /* Zahl der geschriebenen Felder im Header um eins Hochsetzen */
  488   datinfo[bnr]->wdat++ ;
  489 
  490   /* Zusaetzlich allokierte Felder wieder freigeben */
  491   free(fdata) ;
  492 
  493   /* Alles in Ordnung... Hat es vielleicht Floating Point Probleme
  494      gegeben ? */
  495   if (convertstatus != 0) *status=(Int64)convertstatus ;
  496   else *status = 0 ;
  497   return ;
  498 
  499 }
  500 
  501 /************************************************************************
  502  * C_COV : C_COVVEC                                                     *
  503  * Schreibt die drei Komponenten eines Vektordatenfeldes                *
  504  ************************************************************************/
  505 void C_COVVEC(const Int64 *buf,
  506 	      const Int64 *dim1, const Int64 *dim2, const Int64 *dim3,
  507 	      const Float64 *xvec, const Float64 *yvec,
  508 	      const Float64 *zvec, Int64 *status)
  509 {
  510   int         bnr ;                /* Uebersetzte Puffernummer */
  511   header      s_h ;                /* COVISE Header         */
  512   float       *xv, *yv, *zv ;      /* Zu schreibende Vektorkomponenten */
  513   static char *daten = "STRVDT" ;  /* COVISE Datentyp Skalardaten */
  514   const int   attrib    = 0  ;     /* Attribut fuer Covise ab 4.01a */
  515   int         convertstatus ;      /* Floating Point Exception beim */
  516                                    /* Umwandeln ? */
  517   char        outstr[80] ;         /* Ausgabestring fuer debug */
  518 
  519   bnr = (int)(*buf) ;
  520 
  521   if (datinfo[bnr]->ftype != 1 )
  522     {
  523       cov_debug(4,__FILE__, __LINE__,
  524 		"C_COVSCAL() : Versuche ",
  525 		"Vektordaten in Skalardatei zu schreiben! \n") ;
  526       *status = -7 ;
  527       return ;
  528     }
  529 
  530   if (datinfo[bnr]->wdat == -1)
  531     {
  532       cov_debug(3,__FILE__, __LINE__,
  533 		"C_COVSCAL() : Gitterdatei nicht geoeffnet\n") ;
  534       *status = -7 ;
  535       return ;
  536     }
  537 
  538   /* Covise Header setzen */
  539   s_h.xs = (int)(*dim1) ;
  540   s_h.ys = (int)(*dim2) ;
  541   s_h.zs = (int)(*dim3) ;
  542 
  543   /* Single Precision Felder erzeugen */
  544   xv=cov_getsingle(xvec,s_h.xs*s_h.ys*s_h.zs,
  545 		      __FILE__, __LINE__,&convertstatus);
  546   yv=cov_getsingle(yvec,s_h.xs*s_h.ys*s_h.zs,
  547 		      __FILE__, __LINE__,&convertstatus);
  548   zv=cov_getsingle(zvec,s_h.xs*s_h.ys*s_h.zs,
  549 		      __FILE__, __LINE__,&convertstatus);
  550 
  551   sprintf(outstr,"%d",datinfo[bnr]->wdat+1) ;
  552   cov_debug(5,__FILE__, __LINE__,
  553 	    "C_COVVEC() : Schreibe Zeitschritt Nr.  ",outstr,
  554 	    " in Vektordaten-Datei\n") ;
  555 
  556   /* Schreibe Datenheader */
  557   if (cov_writetofile(datinfo[bnr]->fpdat,
  558 			  COV_ISSTRING,daten,6) == -1)
  559     {
  560       cov_debug(4,__FILE__, __LINE__,
  561 		"C_COVVEC() : Fataler Fehler beim Schreiben ",
  562 		"der Vektordaten\n") ;
  563       *status = -9 ;
  564       return ;
  565     }
  566   /* Schreibe Dimensionen */
  567   if (cov_writetofile(datinfo[bnr]->fpdat,
  568 			  COV_ISINT,&s_h,3) == -1)
  569     {
  570       cov_debug(4,__FILE__, __LINE__,
  571 		"C_COVVEC() : Fataler Fehler beim Schreiben ",
  572 		"der Vektordaten\n") ;
  573       *status = -9 ;
  574       return ;
  575     }
  576   /* Schreibe Datenfeld */
  577   if (cov_writetofile(datinfo[bnr]->fpdat,
  578 			  COV_ISFLOAT,xv,s_h.xs*s_h.ys*s_h.zs) == -1)
  579     {
  580       cov_debug(4,__FILE__, __LINE__,
  581 		"C_COVVEC() : Fataler Fehler beim Schreiben ",
  582 		"der X-Vektordaten\n") ;
  583       *status = -9 ;
  584       return ;
  585     }
  586   if (cov_writetofile(datinfo[bnr]->fpdat,
  587 			  COV_ISFLOAT,yv,s_h.xs*s_h.ys*s_h.zs) == -1)
  588     {
  589       cov_debug(4,__FILE__, __LINE__,
  590 		"C_COVVEC() : Fataler Fehler beim Schreiben ",
  591 		"der Y-Vektordaten\n") ;
  592       *status = -9 ;
  593       return ;
  594     }
  595   if (cov_writetofile(datinfo[bnr]->fpdat,
  596 			  COV_ISFLOAT,zv,s_h.xs*s_h.ys*s_h.zs) == -1)
  597     {
  598       cov_debug(4,__FILE__, __LINE__,
  599 		"C_COVVEC() : Fataler Fehler beim Schreiben ",
  600 		"der Z-Vektordaten\n") ;
  601       *status = -9 ;
  602       return ;
  603     }
  604   /* Schreibe Datenattribute (Hier Null) */
  605   if (cov_writetofile(datinfo[bnr]->fpdat,
  606 			  COV_ISINT,&attrib,1) == -1)
  607     {
  608       cov_debug(4,__FILE__, __LINE__,
  609 		"C_COVVEC() : Fataler Fehler beim Schreiben ",
  610 		"der Vektordaten\n") ;
  611       *status = -9 ;
  612       return ;
  613     }
  614   if (cov_writetofile(datinfo[bnr]->fpdat,
  615 			  COV_ISINT,&attrib,1) == -1)
  616     {
  617       cov_debug(4,__FILE__, __LINE__,
  618 		"C_COVVEC() : Fataler Fehler beim Schreiben ",
  619 		"der Vektordaten\n") ;
  620       *status = -9 ;
  621       return ;
  622     }
  623   /* Zahl der geschriebenen Felder im Header um eins Hochsetzen */
  624   datinfo[bnr]->wdat++ ;
  625 
  626   /* Zusaetzlich allokierte Felder wieder freigeben */
  627   free(xv) ;
  628   free(yv) ;
  629   free(zv) ;
  630 
  631   /* Alles in Ordnung... Hat es vielleicht Floating Point Probleme
  632      gegeben ? */
  633   if (convertstatus != 0) *status=(Int64)convertstatus ;
  634   else *status = 0 ;
  635   return ;
  636 
  637 }
  638 
  639 /************************************************************************
  640  * C_COV : C_COVCLOSE                                                   *
  641  * Anlegen der zu schreibenden COVISE Dateien                           *
  642  ************************************************************************/
  643 void C_COVCLOSE(const Int64 *buf, Int64 *status)
  644 {
  645   int         bnr ;                /* Uebersetzte Puffernummer */
  646   int         j ;                  /* Byteinformation fuer COVISE */
  647   static char *timestep = "TIMESTEP\0XX\0" ;
  648                        /* Bezeichner fuer mehr als einen Zeitschritt */
  649 
  650   bnr = (int)(*buf) ;
  651 
  652   /* Gehen wir mal davon aus, dass alles klar geht ! */
  653   *status = 0 ;
  654 
  655   if (datinfo[bnr]->writegrid)
  656     {
  657       /* Gitterdatei geoeffnet ? */
  658       if (datinfo[bnr]->fpgrid != 0)
  659 	{
  660 	  /* genuegend Datensaetze in Datei geschrieben ? */
  661           if (datinfo[bnr]->wgrid != datinfo[bnr]->nzs)
  662 	    {
  663 	      cov_debug(4,__FILE__, __LINE__,
  664 			"C_COVCLOSE() : Nicht genuegend Zeitschritte ",
  665 			"in Gitterdatei geschrieben\n") ;
  666 	      *status = -10 ;
  667 	    }
  668 	  /* Schreibe abschliessende Daten (falls nzs > 1) */
  669 	  if (datinfo[bnr]->nzs > 1)
  670 	    {
  671 	      j=16;
  672 	      if(cov_writetofile(datinfo[bnr]->fpgrid,
  673 			  COV_ISINT,&j,1) == -1)
  674 		{
  675 		  cov_debug(5,__FILE__, __LINE__,
  676 			    "C_COVCLOSE() : Fataler Fehler "
  677 			    "beim Schreiben ",
  678 			    "der Gitterdaten\n") ;
  679 		  *status = -6 ;
  680 		}
  681 	      j=1;
  682 	      if(cov_writetofile(datinfo[bnr]->fpgrid,
  683 			  COV_ISINT,&j,1) == -1)
  684 		{
  685 		  cov_debug(5,__FILE__, __LINE__,
  686 			    "C_COVCLOSE() : Fataler Fehler "
  687 			    "beim Schreiben ",
  688 			    "der Gitterdaten\n") ;
  689 		  *status = -6 ;
  690 		}
  691 	      if(cov_writetofile(datinfo[bnr]->fpgrid,
  692 			  COV_ISSTRING,timestep,12) == -1)
  693 		{
  694 		  cov_debug(5,__FILE__, __LINE__,
  695 			    "C_COVCLOSE() : Fataler Fehler "
  696 			    "beim Schreiben ",
  697 			    "der Gitterdaten\n") ;
  698 		  *status = -6 ;
  699 		}
  700 	    }
  701 	  /* schliesse Gitterdatei */
  702 	  if (close(datinfo[bnr]->fpgrid) != 0)
  703 	    {
  704 	      cov_debug(4,__FILE__, __LINE__,
  705 			"C_COVCLOSE() : Fehler beim Schliessen der",
  706 			"Gitterdatei\n") ;
  707 	      *status = -11 ;
  708 	    }
  709 	  else
  710 	    {
  711 	      cov_debug(5,__FILE__, __LINE__,
  712 			"C_COVCLOSE() : Gitterdatei ",
  713 			datinfo[bnr]->gridfile,
  714 			" erfolgreich geschlossen\n") ;
  715 	    }
  716 	}
  717       else
  718 	{
  719 	  cov_debug(4,__FILE__, __LINE__,
  720 		    "C_COVCLOSE() : Versuche nicht geoeffnete COVISE-",
  721 		    "Gitterdatei zu schliessen\n") ;
  722           *status = -12 ;
  723 	}
  724     }
  725 
  726   /* Falls was schief gegangen ist, Gitterdatei loeschen ! */
  727   if (*status != 0)
  728     {
  729       unlink(datinfo[bnr]->gridfile) ;
  730       cov_debug(5,__FILE__, __LINE__,
  731 		"C_COVCLOSE() : Loesche Gitterdatei ",
  732 		datinfo[bnr]->gridfile," wegen Fehlern\n") ;
  733     }
  734 
  735   /* Versuche Datendatei zu schliessen */
  736 
  737   /* Datendatei geoffnet ? */
  738   if (datinfo[bnr]->fpdat != 0)
  739     {
  740       /* genuegend Datensaetze in Datei geschrieben ? */
  741       if (datinfo[bnr]->wdat != datinfo[bnr]->nzs)
  742 	{
  743 	  cov_debug(4,__FILE__, __LINE__,
  744 		    "C_COVCLOSE() : Nicht genuegend Zeitschritte ",
  745 		    "in Datendatei geschrieben\n") ;
  746 	  *status = -13 ;
  747 	}
  748       /* Schreibe abschliessende Daten (falls nzs > 1) */
  749       if (datinfo[bnr]->nzs > 1)
  750 	{
  751 	  j=16;
  752 	  if(cov_writetofile(datinfo[bnr]->fpdat,
  753 			  COV_ISINT,&j,1) == -1)
  754 	    {
  755 	      cov_debug(5,__FILE__, __LINE__,
  756 			"C_COVCLOSE() : Fataler Fehler "
  757 			"beim Schreiben ",
  758 			"der Daten\n") ;
  759 	      *status = -17 ;
  760 	    }
  761 	  j=1;
  762 	  if(cov_writetofile(datinfo[bnr]->fpdat,
  763 			  COV_ISINT,&j,1) == -1)
  764 	    {
  765 	      cov_debug(5,__FILE__, __LINE__,
  766 			"C_COVCLOSE() : Fataler Fehler "
  767 			"beim Schreiben ",
  768 			"der Daten\n") ;
  769 	      *status = -17 ;
  770 	    }
  771 	  if(cov_writetofile(datinfo[bnr]->fpdat,
  772 			  COV_ISSTRING,timestep,12) == -1)
  773 	    {
  774 	      cov_debug(5,__FILE__, __LINE__,
  775 			"C_COVCLOSE() : Fataler Fehler "
  776 			"beim Schreiben ",
  777 			"der Daten\n") ;
  778 	      *status = -17 ;
  779 	    }
  780 	}
  781       /* schliesse Datendatei */
  782       if (close(datinfo[bnr]->fpdat) != 0)
  783 	{
  784 	  cov_debug(4,__FILE__, __LINE__,
  785 		    "C_COVCLOSE() : Fehler beim Schliessen der",
  786 		    "Datendatei\n") ;
  787 	  *status = -14 ;
  788 	}
  789       else
  790 	{
  791 	  cov_debug(5,__FILE__, __LINE__,
  792 		    "C_COVCLOSE() : Datendatei ",
  793 		    datinfo[bnr]->datfile," erfolgreich geschlossen\n") ;
  794 	}
  795     }
  796   else
  797     {
  798       cov_debug(4,__FILE__, __LINE__,
  799 		"C_COVCLOSE() : Versuche nicht geoeffnete COVISE-",
  800 		"Datendatei zu schliessen\n") ;
  801       *status = -15 ;
  802     }
  803 
  804   /* Falls was schief gegangen ist, Datendatei loeschen ! */
  805   if (*status != 0)
  806     {
  807       unlink(datinfo[bnr]->datfile) ;
  808       cov_debug(5,__FILE__, __LINE__,