~ubuntu-branches/ubuntu/maverick/yagiuda/maverick

« back to all changes in this revision

Viewing changes to src/read_header.c

  • Committer: Bazaar Package Importer
  • Author(s): Joop Stakenborg
  • Date: 2005-08-22 20:20:13 UTC
  • Revision ID: james.westby@ubuntu.com-20050822202013-mhhxp4xirdxrdfx1
Tags: upstream-1.19
ImportĀ upstreamĀ versionĀ 1.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifdef HAVE_STDLIB_H
 
2
#include <stdlib.h>
 
3
#endif
 
4
#include <stdio.h>
 
5
#include <sys/types.h>
 
6
#include <unistd.h>
 
7
#include <errno.h>
 
8
#include "yagi.h"
 
9
extern int errno;
 
10
 
 
11
int read_header(FILE *ifp, FILE *ofp, double *min_f, double *max_f,
 
12
         double *step_f, double *f, double *angular_step)
 
13
{
 
14
        int elements, driven, parasitic;
 
15
 
 
16
        fread((char *) &elements, sizeof(elements), 1, ifp);
 
17
        fread((char *) &driven, sizeof(driven), 1, ifp);
 
18
        fread((char *) &parasitic, sizeof(parasitic), 1, ifp);
 
19
        fread((char *) min_f, sizeof(*min_f), 1, ifp);
 
20
        fread((char *) max_f,sizeof(*max_f), 1, ifp);
 
21
        fread((char *) f, sizeof(*f), 1, ifp);
 
22
        fread((char *) step_f, sizeof(*step_f), 1, ifp);
 
23
        fread((char *) angular_step, sizeof(*angular_step), 1, ifp);
 
24
        fseek(ifp, HEADER_SIZE, SEEK_SET);             /* skip rest of header */
 
25
        /* now we make some basic checks on the header, to see nothing is too
 
26
        far wrong. */
 
27
        if( (*max_f < *min_f) || *angular_step==0 || driven+parasitic != elements || (*step_f >  *max_f))
 
28
        {
 
29
                fprintf(stderr,"Error in input file\n");
 
30
                fprintf(stderr,"driven=%d parasitic=%d elements=%d\n",driven,parasitic,elements);
 
31
                fprintf(stderr,"min_f=%f max_f=%f step_f=%f\n",*min_f, *max_f, *step_f);
 
32
                fprintf(stderr,"angular_step=%f \n", *angular_step);
 
33
                exit(19);
 
34
        }
 
35
        fprintf(ofp,"# Driven=%d parasitic=%d total-elements=%d design=%.3fMHz\n", driven, parasitic, elements,  *f/1e6);
 
36
        fprintf(ofp,"# Checked from %.3fMHz to %.3fMHz.\n", *min_f/1e6, *max_f/1e6);
 
37
 
 
38
#ifdef DEBUG
 
39
        if(errno)
 
40
        {
 
41
                fprintf(stderr,"Errno =%d in read_hea.c\n", errno);
 
42
                exit(1);
 
43
        }
 
44
#endif
 
45
        return(elements);
 
46
}