示例#1
0
文件: gabufrtbl.c 项目: cjg/grads
gaint gabufr_read_tbls(gabufr_tbl_inf * tbl_inf) {
  gaint base_path_len;
  char * tbl_b_path, * tbl_d_path;

  gabufr_reset_tbls();
  
  base_path_len = strlen(base_path);

  tbl_b_path = (char *) malloc(base_path_len + GABUFR_TBL_NAME_LEN + 1);
  if (tbl_b_path == NULL) {
    printf("Memory allocation failed during parsing\n");
    return GABUFR_ERR;
  }
  strncpy(tbl_b_path, base_path, base_path_len);
  tbl_b_path[base_path_len] = '/';
  sprintf((tbl_b_path + base_path_len + 1), "B%dM-%.3d-%.3d-B", 
	  tbl_inf->bufr_edition, 
	  tbl_inf->master_tbl_num,
	  tbl_inf->master_tbl_version);
  if (GABUFR_TBL_DEBUG) printf("reading from table B file %s\n", tbl_b_path);

  tbl_d_path = (char *) malloc(strlen(base_path) + GABUFR_TBL_NAME_LEN + 1);
  if (tbl_d_path == NULL) {
    printf("Memory allocation failed during parsing\n");
    return GABUFR_ERR;
  }
  strncpy(tbl_d_path, base_path, base_path_len);
  tbl_d_path[base_path_len] = '/';
  sprintf((tbl_d_path + base_path_len + 1), "B%dM-%.3d-%.3d-D", 
	  tbl_inf->bufr_edition, 
	  tbl_inf->master_tbl_num,
	  tbl_inf->master_tbl_version);
  if (GABUFR_TBL_DEBUG) printf("reading from table D file %s\n", tbl_d_path);

  if (gabufr_read_tbl_b(tbl_b_path) == GABUFR_ERR
      || gabufr_read_tbl_d(tbl_d_path) == GABUFR_ERR) {
    gabufr_reset_tbls();
    return GABUFR_ERR;
  }

  free(tbl_b_path);
  free(tbl_d_path);
  return GABUFR_OK;
}
示例#2
0
gabufr_dset * gabufr_scan(const char * path) {
  gabufr_dset * dset;

  dset = (gabufr_dset *) malloc(sizeof(gabufr_dset));
  if (dset == NULL) {
    printf("Memory allocation failed during parsing\n");
    return NULL;
  }
  gabufr_reset_tbls();
  if (gabufr_load2mem(path, dset) == GABUFR_ERR) {
    return NULL;
  }
  if (gabufr_decode(dset, GABUFR_NO_PARSE_DATA) == GABUFR_ERR) {
    free(dset->buf);
    free(dset);    
    return NULL;
  }
  free(dset->buf);
  dset->buf = NULL;
  return dset;
}