Mapper
values_search.c
Go to the documentation of this file.
1 
2 #include "prototypes.h"
3 
4 int values_search(unsigned long index,struct database *dbase,
5  int report_limit,struct stim btim,struct stim etim,
6  char *qualifier,struct stn_values *stn_values)
7 
8 {
9 
10  extern struct sensor_type *stype;
11  int icnt,jcnt,kcnt,j,m,break_flag,restart,pstart,jtver,itver,lmer,kk,mer,ier;
12  int wflag,aflag;
13  float fdata,gdata[5];
14  double dif,okdif[5];
15  signed int sdx_index,i,next,sloop,end;
16  unsigned int rv;
17  extern unsigned int sensortype;
18  unsigned int rec_size, num_recs, db_slot,report_num;
19  signed long offset;
20  unsigned long first_overload;
21  struct databank dbk;
22  char qu[10],sbuf[100],*p,dbuf[100],*q;
23  FILE *fp;
24  time_t told,tnew;
25  struct tm tm;
26  struct tm *gm;
27  time_t secs;
28  int is;
29 
31 
33 
34 
35  tnew=tnew+7200;
36 
37  /* initialize variables */
38 
39  report_num = 0;
40  strcpy(qu,qualifier);
41 
42  db_slot=index;
43 
44  for( sloop=0; sloop < 12; sloop++) {
45 
46  num_recs = 0x01;
47  rec_size = sizeof(struct databank);
48 
49  if(sloop==0) {
50 
51  /* read first record*/
52 
53  offset = (signed long)db_slot * rec_size;
54  rv=dbread(NDATABANK, offset, rec_size, num_recs, &dbk);
55  if(rv != rec_size * num_recs)
56  return(-8);
57 
58 
59  for(is=0;is<dbase->sensor_types;is++)
60  if(stype[is].number==dbk.stype)
61  break;
62 
63  if(is==dbase->sensor_types)
64  is=0;
65 
66  sensortype=is;
67  next = dbk.next;
68  end=365;
69 
70  }
71 
72  else if(sloop==1) {
73 
74  /* stop here if no more reports exist in primary data file */
75 
76  if(dbk.prior == ONOT_USED)
77  goto finish;
78 
79  /* check remainder of reports in primary data block */
80 
81  next=-1;
82  end=dbk.next + 1;
83 
84  }
85 
86  else if(sloop==2) {
87 
88  /*check non-redundant reports in first overload */
89 
90  next = dbk.next;
91  first_overload = dbk.prior;
92  offset = (signed long)dbk.prior * rec_size;
93  rv=dbread(NOVERLOAD, offset, rec_size, num_recs, &dbk);
94  if(rv != rec_size * num_recs)
95  return(-9);
96  end=365;
97 
98  }
99 
100  else {
101 
102  if( first_overload != dbk.prior && dbk.prior != ONOT_USED ){
103 
104  offset = (signed long)dbk.prior * rec_size;
105  rv=dbread(NOVERLOAD, offset, rec_size, num_recs, &dbk);
106  if(rv != rec_size * num_recs)
107  return(-10);
108 
109  next=0;
110  end=365;
111 
112  }
113  else
114  goto finish;
115 
116  }
117 
118  for(i=next+1; i<end; i++) {
119 
120  /* if requesting a specific number of reports */
121 
122  if(dbk.rpt[i].data <= -9989.0)
123  continue;
124 
125  /* no more reports */
126 
127  if(report_num == report_limit)
128  goto finish;
129 
130  stn_values[report_num].value = dbk.rpt[i].data;
131 
132  /* same value as previous report */
133 
134  if(report_num > 0 &&
135  stn_values[report_num-1].clock==dbk.rpt[i].clock)
136  continue;
137 
138  secs = dbk.rpt[i].clock;
139  gm=gmtime(&secs);
140 
141  stn_values[report_num].zdate=(gm->tm_year+1900)*10000+(gm->tm_mon+1)*100+gm->tm_mday;
142  stn_values[report_num].ztime=gm->tm_hour*10000+gm->tm_min*100;
143  stn_values[report_num].qual = dbk.rpt[i].dqr;
144  stn_values[report_num].clock = secs;
145 
146  /* just get a certain number of reports without time bounds*/
147 
148  if(tnew==0L && told==0L) {
149 
150  if(qu[0]==0 || dbk.rpt[i].dqr==0 ||
151  strchr(qu,dbk.rpt[i].dqr)!=NULL)
152  report_num++;
153 
154  continue;
155 
156  }
157 
158  /* check if report is within bounds */
159 
160  if((dbk.rpt[i].clock <= tnew) && (dbk.rpt[i].clock >= told)) {
161 
162  if(qu[0]==0 || dbk.rpt[i].dqr==0 ||
163  strchr(qu,dbk.rpt[i].dqr)!=NULL)
164  report_num++;
165 
166  continue;
167 
168  }
169 
170  /* if report is newer than newest time */
171 
172  else if(dbk.rpt[i].clock > tnew)
173  continue;
174 
175  else
176  goto finish;
177 
178  }
179 
180  }
181 
182 finish:
183 return(report_num);
184 
185 }
static int i
#define ONOT_USED
Definition: database.h:313
unsigned long int dbread(unsigned long int file_num, signed long int offset, unsigned long int rec_size, unsigned long int num_recs, void *buf)
Definition: dbread.c:22
#define NDATABANK
Definition: database.h:574
#define NOVERLOAD
Definition: database.h:588
long ouptime(int year, int month, int day, int hour, int minute, int second)
Definition: ouptime.c:10
int values_search(char *hb5, char *parm, struct stim begin_date, struct stim end_date, struct stn_values *stn_values)
fp
Definition: make_NEXRAD.c:339
int j
Definition: mapp2h.h:48
unsigned int sensortype
Definition: mapper.c:113
struct sensor_type * stype
Definition: mapper.c:120
struct database dbase
Definition: mapper.c:121
void restart()
Definition: send_afos.c:56
unsigned long int prior
Definition: database.h:156
unsigned long int stype
Definition: database.h:154
signed long int next
Definition: database.h:155
struct report rpt[RPTS_PER_REC]
Definition: database.h:181
unsigned long int sensor_types
Definition: database.h:225
Definition: misc.h:23
Definition: misc.h:564
unsigned char dqr
Definition: database.h:145
time_t clock
Definition: database.h:144
float data
Definition: database.h:143
Definition: misc.h:93
int minute
Definition: misc.h:99
int day
Definition: misc.h:97
int year
Definition: misc.h:95
int hour
Definition: misc.h:98
int month
Definition: misc.h:96
char qual
Definition: hydro_data.h:36
time_t clock
Definition: hydro_data.h:32
float value
Definition: hydro_data.h:35
struct stim btim
Definition: subdisplay.c:30
int report_limit
Definition: subdisplay.c:53
struct stim etim
Definition: subdisplay.c:31