46 character(len=*),
intent(in) :: string
47 integer,
intent(inout) :: nlen
48 character(len = (len(string) + 1)) :: cstring
56 nlen = len_trim(string)
57 inull = scan(string, c_null_char)
58 cstring = repeat(
" ", len(cstring))
61 cstring = string(1:nlen)
63 cstring = string(1:nlen)//c_null_char
85 character(len=*),
intent(in) :: cstring
86 integer,
intent(in) :: nlen
87 character(len=nlen) :: string
90 ie = len_trim(cstring)
91 inull = scan(cstring, c_null_char)
93 if (inull > 1) ie = inull-1
94 ie = max(1, min(ie, nlen))
95 string = repeat(
" ", nlen)
96 string(1:ie) = cstring(1:ie)
114 character(len = *),
intent(in) :: path
115 integer,
intent(in) :: mode
116 integer,
intent(inout) :: g2id
119 integer(c_int) :: cmode, cg2id, cstatus
120 character(len = (len(path) + 1)) :: cpath
130 cstatus = g2c_open(cpath(1:ie), cmode, cg2id)
133 if (cstatus .eq. 0)
then
156 character(len=*),
intent(in) :: data_file, index_file
157 integer,
intent(in) :: mode
158 integer,
intent(inout) :: g2cid
161 integer(c_int) :: cmode, cg2cid, cstatus
162 character(len = (len(data_file) + 1)) :: cdata_file
163 character(len = (len(index_file) + 1)) :: cindex_file
174 cstatus = g2c_open_index(cdata_file(1:ie1), cindex_file(1:ie2), cmode, cg2cid)
176 if (cstatus == 0)
then
195 integer,
intent(in) :: g2id
196 integer,
intent(out) :: num_msg
199 integer(c_int) :: cg2id, cnum_msg, cstatus
202 cstatus = g2c_inq(cg2id, cnum_msg)
224 num_local, center, subcenter, master_version, local_version)
result(status)
229 integer,
intent(in) :: g2id, msg_num
230 integer(kind = 1),
intent(out) :: discipline
231 integer,
intent(out) :: num_fields, num_local
232 integer(kind = 2),
intent(out) :: center, subcenter
233 integer(kind = 1),
intent(out) :: master_version, local_version
236 integer(c_int) :: cg2id, cmsg_num, cstatus
237 integer(c_signed_char) :: cdiscipline
238 integer(c_int) :: cnum_fields, cnum_local
239 integer(c_short) :: ccenter, csubcenter
240 integer(c_signed_char) :: cmaster_version, clocal_version
244 cmsg_num = msg_num - 1
245 cstatus = g2c_inq_msg(cg2id, cmsg_num, cdiscipline, cnum_fields, &
246 cnum_local, ccenter, csubcenter, cmaster_version, clocal_version)
247 discipline = cdiscipline
248 num_fields = cnum_fields
249 num_local = cnum_local
251 subcenter = csubcenter
252 master_version = cmaster_version
253 local_version = clocal_version
273 month, day, hour, minute, second)
result(status)
278 integer,
intent(in) :: g2id
279 integer,
intent(in) :: msg_num
280 integer(kind = 1),
intent(out) :: sig_ref_time
281 integer(kind = 2),
intent(out) :: year
282 integer(kind = 1),
intent(out) :: month, day, hour, minute, second
284 integer(c_int) :: g2cid, cmsg_num
285 integer(c_signed_char) :: csig_ref_time
286 integer(c_short) :: cyear
287 integer(c_signed_char) :: cmonth, cday, chour, cminute, csecond
289 integer(c_int) :: cstatus
293 cmsg_num = msg_num - 1
294 cstatus = g2c_inq_msg_time(g2id, cmsg_num, csig_ref_time, cyear, &
295 cmonth, cday, chour, cminute, csecond)
296 sig_ref_time = csig_ref_time
322 function g2cf_inq_prod(g2id, msg_num, prod_num, pds_template_len, pds_template, gds_template_len, &
323 gds_template, drs_template_len, drs_template)
result(status)
328 integer,
intent(in) :: g2id, msg_num, prod_num
329 integer,
intent(out) :: pds_template_len
330 integer(kind = 8),
intent(out) :: pds_template(*)
331 integer,
intent(out) :: gds_template_len
332 integer(kind = 8),
intent(out) :: gds_template(*)
333 integer,
intent(out) :: drs_template_len
334 integer(kind = 8),
intent(out) :: drs_template(*)
336 integer(c_int) :: g2cid, cmsg_num
337 integer(c_int) :: cprod_num, cpds_template_len
339 integer(c_int) :: cgds_template_len
341 integer(c_int) :: cdrs_template_len
344 integer(c_int) :: cstatus
349 cmsg_num = msg_num - 1
350 cprod_num = prod_num - 1
353 cstatus = g2c_inq_prod(g2cid, cmsg_num, cprod_num, cpds_template_len, cpds_template, &
354 cgds_template_len, cgds_template, cdrs_template_len, cdrs_template)
357 pds_template_len = cpds_template_len
358 if (pds_template_len .gt. 0)
then
359 do i = 1, pds_template_len
360 pds_template(i) = cpds_template(i)
363 gds_template_len = cgds_template_len
364 if (gds_template_len .gt. 0)
then
365 do i = 1, gds_template_len
366 gds_template(i) = cgds_template(i)
369 drs_template_len = cdrs_template_len
370 if (drs_template_len .gt. 0)
then
371 do i = 1, drs_template_len
372 drs_template(i) = cdrs_template(i)
392 function g2cf_inq_dim(g2id, msg_num, prod_num, dim_num, dimlen, name, val)
result(status)
397 integer,
intent(in) :: g2id, msg_num, prod_num, dim_num
398 integer(kind = 8),
intent(out) :: dimlen
399 character,
intent(out) :: name(*)
400 real,
intent(out),
optional :: val(*)
402 integer(c_int) :: g2cid, cmsg_num, cprod_num, cdim_num
403 integer(c_size_t) :: cdimlen
404 real(c_float) :: cval(10)
406 character(len = G2_MAX_NAME) :: tmpname
407 integer(kind = 8) :: i
409 integer(c_int) :: cstatus
414 cmsg_num = msg_num - 1
415 cprod_num = prod_num - 1
416 cdim_num = dim_num - 1
420 if (
present(val))
then
421 cstatus = g2c_inq_dim(g2cid, cmsg_num, cprod_num, cdim_num, cdimlen, &
424 cstatus = g2c_inq_dim_info(g2cid, cmsg_num, cprod_num, cdim_num, cdimlen, &
435 if (
present(val))
then
471 integer,
intent(in) :: g2id
474 integer(c_int) :: cg2id, cstatus
477 cstatus = g2c_close(cg2id)
493 integer,
intent(in) :: log_level
496 integer(c_int) :: clog_level, cstatus
498 clog_level = log_level
499 cstatus = g2c_set_log_level(clog_level)
Module for the NCEPLIBS-g2 file-based GRIB2 API.
integer function g2cf_close(g2id)
Close a GRIB2 file.
integer, parameter g2_max_drs_template_len
Maximum number of entries in a DRS template.
integer, parameter g2_max_pds_template_len
Maximum number of entries in a PDS template.
integer function g2cf_inq_dim(g2id, msg_num, prod_num, dim_num, dimlen, name, val)
Learn about a dimension.
character(len=(len(string)+1)) function addcnullchar(string, nlen)
Add a C_NULL_CHAR to a string to create a C compatible string.
integer, parameter g2_max_gds_template_len
Maximum number of entries in a GDS template.
integer function g2cf_open_index(data_file, index_file, mode, g2cid)
Open a GRIB2 file using an exsiting index file (generated by the grb2index utility).
integer function g2cf_set_log_level(log_level)
Turn internal logging on.
integer, parameter g2_max_name
Maximum name length.
integer function g2cf_inq_prod(g2id, msg_num, prod_num, pds_template_len, pds_template, gds_template_len, gds_template, drs_template_len, drs_template)
Learn about a product.
integer function g2cf_inq_msg(g2id, msg_num, discipline, num_fields, num_local, center, subcenter, master_version, local_version)
Learn about a message are in a GRIB2 file.
integer, parameter g2_noerr
Return value from functions when there is no error.
integer function g2cf_open(path, mode, g2id)
Open a GRIB2 file.
character(len=nlen) function stripcnullchar(cstring, nlen)
Check cstring for a c null char, strip it off and return regular string.
integer function g2cf_inq_msg_time(g2id, msg_num, sig_ref_time, year, month, day, hour, minute, second)
Learn about message date/time.
integer function g2cf_inq(g2id, num_msg)
Learn how many messages are in a GRIB2 file.