]> Pileus Git - ~andy/rsl/blob - wsr88d_get_site.c
Initial import
[~andy/rsl] / wsr88d_get_site.c
1 /*
2     NASA/TRMM, Code 910.1.
3     This is the TRMM Office Radar Software Library.
4     Copyright (C) 1996, 1997
5             John H. Merritt
6             Space Applications Corporation
7             Vienna, Virginia
8
9     This library is free software; you can redistribute it and/or
10     modify it under the terms of the GNU Library General Public
11     License as published by the Free Software Foundation; either
12     version 2 of the License, or (at your option) any later version.
13
14     This library is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17     Library General Public License for more details.
18
19     You should have received a copy of the GNU Library General Public
20     License along with this library; if not, write to the Free
21     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23 /*
24  * get_site - fills structure containing radar site info
25  * parameters: 
26  * char *in_sitenm - ptr to radar site name
27  * returns: struct radar_site *currsite->- ptr to current site structure
28  * Returns NULL on failure of 'in_sitenm' lookup.
29  * calls from: Proc_file
30 */
31
32 #include <stdio.h>
33 #include <string.h>
34 int strcasecmp(const char *s1, const char *s2);
35 #include <stdlib.h>
36 #include "wsr88d.h"
37
38 Wsr88d_site_info *wsr88d_get_site(char *in_sitenm)
39 {
40         /* variable declarations         */
41         char line[100];
42         int scan_count,i;
43         int in_number,in_latd,in_latm,in_lats,in_lond,in_lonm,in_lons;
44         int in_height;
45         char in_site[5],in_city[16],in_state[4]; /* One extra for \0 */
46         struct radar_site *currsite=NULL;
47         FILE *in_file;
48
49         if((in_file=fopen(WSR88D_SITE_INFO_FILE, "r")) !=NULL)
50         {
51         /* read each line */
52                 while (fgets(line,sizeof(line),in_file) != NULL)
53                 {
54                         scan_count=sscanf(line,"%d %s %s %s %d %d %d %d %d %d %d",&in_number,in_site,in_city,in_state,&in_latd,&in_latm,&in_lats,&in_lond,&in_lonm,&in_lons,&in_height);
55                         if(scan_count != 11 && scan_count != 0)
56                                 fprintf(stderr,"get_site: sitedb read");
57                         else
58                         {
59                         /* get the radar site info */
60
61                                 /* check for the matching site name*/
62                                 if(strcasecmp(in_sitenm,in_site)== 0)
63                                   {
64                                         if((currsite=(struct radar_site *)malloc(sizeof(struct radar_site)))==NULL) {
65                                           perror("wsr88d_get_site");
66                                           return NULL;
67                                         }
68                                     currsite->number = in_number;
69                                     for(i=0;i<4;i++)
70                                         currsite->name[i]   = in_site[i];
71                                         for(i=0;i<15;i++)
72                                                 currsite->city[i]   = in_city[i];
73                                         for(i=0;i<2;i++)
74                                                 currsite->state[i]  = in_state[i];
75                                         currsite->latd   = in_latd;
76                                         currsite->latm   = in_latm;
77                                         currsite->lats   = in_lats;
78                                         currsite->lond   = in_lond;
79                                         currsite->lonm   = in_lonm;
80                                         currsite->lons   = in_lons;
81                                         currsite->height = in_height;
82                                         currsite->bwidth = -999;
83                                         currsite->spulse = 1530;
84                                         currsite->lpulse = 4630;
85                                         break;
86                                 }
87                         }
88                 }
89         /* close the file */
90         (void)fclose(in_file);
91         }
92         else
93           perror(WSR88D_SITE_INFO_FILE);
94         
95
96         return(currsite);
97 }
98