Mapper
station_search.c
Go to the documentation of this file.
1 /*****************************************************************************\
2 * bs_hbook5() *
3 *******************************************************************************
4 * Bs_hb5() performs a binary search on a sorted file of handbook5 structures.*
5 * The sorted file of max_recs structures is on the RAMDISK in the *
6 * /tmp/HANDBOOK5.DAT file. Bs_hb5() tries to match a requested id with the *
7 * actual ids that are in the HANDBOOK5.DAT file. The requested ID is the *
8 * hb5_pc argument. Hb5_pc is a contatenation of Handbook 5 ID and Parameter *
9 * Code. If a matching record is found in the HANDBOOK5.DAT file, the matching*
10 * record is returned. Otherwise, the return value is a handbook5 structure *
11 * that contains the value CNOT_USED. *
12 * Andy Morin - CNRFC 10/10/92 *
13 * Converted to QNX 4.2 Wayne Martin - CNRFC 01/30/95 *
14 \*****************************************************************************/
15 
16 #include "prototypes.h"
17 
18 #define NO 0x00
19 #define YES 0x01
20 #define LMAX 17L
21 
22 int station_search(unsigned long index,struct sensor_file *sfile)
23 
24 {
25 
26  size_t rec_size;
27  size_t erv, rv;
28  signed long offset;
29  char error_msg[100];
30  struct error_message err;
31 
32  rec_size = (size_t)sizeof(struct sensor_file);
33  erv = rec_size;
34 
35  offset=(signed long)index * rec_size;
36 
37  rv = dbread(NSENSOR_FILE, offset, rec_size, 1L, &sfile->sid);
38 
39  if(rv != erv) {
40  sprintf(error_msg, "Read error NSENSOR_FILE,offset=%ld", offset);
41  mk_err_msg("station_search", error_msg, &err);
42  offset = dbsize(NERRORLOG);
43  dbwrite(NERRORLOG, offset, sizeof(struct error_message), 1L, &err);
44  exit(EXIT_FAILURE);
45  }
46 
47  return(0);
48 
49  }
unsigned long int dbwrite(unsigned long int file_num, signed long int offset, unsigned long int rec_size, unsigned long int num_recs, void *buf)
Definition: dbwrite.c:22
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 NERRORLOG
Definition: database.h:584
signed long int dbsize(unsigned long int file_num)
Definition: dbsize.c:13
void mk_err_msg(char *pname, char *errmsg, struct error_message *err)
Definition: mk_err_msg.c:29
#define NSENSOR_FILE
Definition: database.h:576
sprintf(fbuf,"/usr/mapper/nexrad/ngrid.%02d-%02d-%02d-%02d", year, month, day, hour)
struct sensor_file * sfile
Definition: mapper.c:126
int station_search(unsigned long index, struct sensor_file *sfile)
unsigned long int sid
Definition: database.h:434