"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "eas3pkg/eas3llc/avg.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 /* ------------------------------------------------------------------------
   23  * project: eas3llc
   24  * file:    avg.c
   25  * author:  David Eller <david.eller@studserv.uni-stuttgart.de>
   26  *          December 1999
   27  *          Daniel Meyer 01/2000
   28  * ------------------------------------------------------------------------
   29  * Beispielprogramm fuer die Verwendung der eas3llc-Routinen:
   30  * Berechnet den Durchschnittswert jedes Parameters ueber alle Zeitschritte
   31  * der Eingabedateien (In Kommandozeile angegeben)
   32  * ------------------------------------------------------------------------ */
   33 
   34 #include <stdlib.h>
   35 #include <stdio.h>
   36 #include <string.h>
   37 #include <math.h>
   38 
   39 #include "eas3llc.h"
   40 
   41 char *calcAvg(const char *path);
   42 
   43 int main(int argc, char *argv[])
   44 {
   45   int n;
   46   char *outf;
   47 
   48   if (argc < 2)
   49     {
   50       puts("Usage: avg datafile1.eas [datafile2.eas ...] \n");
   51       return (EAS3_FAILURE);
   52     }
   53 
   54   puts("*** Parameter - Mittelung ***");
   55   for (n=1; n<argc; n++)
   56     {
   57       printf("Eingabedatei : %s\n", argv[n]);
   58       outf = calcAvg(argv[n]);
   59       printf("Ausgabe in <%s>.\n\n", outf);
   60       free(outf);
   61     }
   62 
   63   return EAS3_SUCCESS;
   64 }
   65 
   66 char *calcAvg(const char *path)
   67 {
   68   /* ---------------------------------------------------------
   69    * Berechnet den Durchschnitts-Zeitschritt der Datei *path
   70    * --------------------------------------------------------- */
   71 
   72    Int32 z, p, i, j, k;
   73    DefaultFloat a, b;
   74    eas3Hdr *ihdr, *ohdr;
   75    eas3Par *iprm, *oprm ;
   76    char *opath;
   77 
   78    const Int32 infile = 0 ;
   79    const Int32 outfile = 1 ;
   80 
   81    /* Dateinamen generieren */
   82    opath = malloc(strlen(path)+5);
   83    strcpy(opath, path);
   84    strcat(opath, ".avg");
   85 
   86    /* Datenfiles erzeugen */
   87    /* ifs = eas3_readHdr(path, EAS3_RO); */
   88    ihdr= eas3_readHdr(infile, path, EAS3_RO);
   89 
   90    eas3_printHdr(ihdr, stdout);
   91 
   92    ohdr = (eas3Hdr *) malloc(sizeof(eas3Hdr));
   93    ohdr->dform = ihdr->dform;
   94    ohdr->bform = ihdr->bform;
   95    ohdr->nzs = 1;
   96    ohdr->npar = ihdr->npar;
   97    ohdr->ndim1 = ihdr->ndim1;
   98    ohdr->ndim2 = ihdr->ndim2;
   99    ohdr->ndim3 = ihdr->ndim3;
  100    ohdr->amode = EAS3_NO_ATTR;
  101    ohdr->umode = EAS3_NO_UDEF;
  102    for (i=0; i<5; i++)
  103      ohdr->gmode[i] = EAS3_NO_G;
  104    /* Kennsatzfelder allokieren */
  105    eas3_newHdr(ohdr);
  106 
  107    /* Kennsatz schreiben */
  108    eas3_writeHdr(outfile, opath, ohdr, EAS3_WO);
  109 
  110    /* Arbeitsschleife */
  111    printf("Bearbeite Parameter ");
  112    for (p=1; p<=ihdr->npar; p++)
  113      {
  114        printf(".");
  115        fflush(stdout);
  116        iprm = eas3_getPar(infile) ;
  117        oprm = eas3_getPar(outfile) ;
  118        for (z=1; z<=ihdr->nzs; z++)
  119          {
  120            iprm = eas3_readPar(infile, z, p);
  121            for (k=1; k<=ihdr->ndim3; k++)
  122              for (j=1; j<=ihdr->ndim2; j++)
  123                for (i=1; i<=ihdr->ndim1; i++)
  124                  {
  125                    a = eas3_getValue(iprm, i, j, k);
  126                    if (p == 1)
  127                      b = 0;
  128                    else
  129                      b = eas3_getValue(oprm, i, j, k);
  130                    eas3_setValue(oprm, (a+b)/ihdr->nzs, i, j, k);
  131                  }
  132          }
  133        eas3_writePar(outfile, oprm, 1, p);
  134      }
  135    puts("");
  136    /* Aufraeumen */
  137    eas3_closeFile(outfile);
  138    eas3_closeFile(infile);
  139 
  140    return opath;
  141 }
  142