-
Notifications
You must be signed in to change notification settings - Fork 0
/
eccodes.h
1399 lines (1235 loc) · 56.5 KB
/
eccodes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2005-2018 ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
/*! \file eccodes.h
\brief The ecCodes C header file
This is the only file that must be included to use the ecCodes library
from C.
*/
#ifndef eccodes_H
#define eccodes_H
#ifdef __cplusplus
extern "C" {
#endif
#include "grib_api.h"
#define CODES_VERSION ECCODES_VERSION
/* sections */
#define CODES_SECTION_PRODUCT GRIB_SECTION_PRODUCT
#define CODES_SECTION_GRID GRIB_SECTION_GRID
#define CODES_SECTION_LOCAL GRIB_SECTION_LOCAL
#define CODES_SECTION_DATA GRIB_SECTION_DATA
#define CODES_SECTION_BITMAP GRIB_SECTION_BITMAP
/* LOG MODES
Log mode for information for processing information
*/
#define CODES_LOG_INFO GRIB_LOG_INFO
#define CODES_LOG_WARNING GRIB_LOG_WARNING
#define CODES_LOG_ERROR GRIB_LOG_ERROR
#define CODES_LOG_FATAL GRIB_LOG_FATAL
#define CODES_LOG_DEBUG GRIB_LOG_DEBUG
/* Types */
#define CODES_TYPE_UNDEFINED GRIB_TYPE_UNDEFINED
#define CODES_TYPE_LONG GRIB_TYPE_LONG
#define CODES_TYPE_DOUBLE GRIB_TYPE_DOUBLE
#define CODES_TYPE_STRING GRIB_TYPE_STRING
#define CODES_TYPE_BYTES GRIB_TYPE_BYTES
#define CODES_TYPE_SECTION GRIB_TYPE_SECTION
#define CODES_TYPE_LABEL GRIB_TYPE_LABEL
#define CODES_TYPE_MISSING GRIB_TYPE_MISSING
/* Missing values */
#define CODES_MISSING_LONG GRIB_MISSING_LONG
#define CODES_MISSING_DOUBLE GRIB_MISSING_DOUBLE
/*set spec flags*/
#define CODES_UTIL_SET_SPEC_FLAGS_ONLY_PACKING GRIB_UTIL_SET_SPEC_FLAGS_ONLY_PACKING
/* Dump option flags*/
#define CODES_DUMP_FLAG_READ_ONLY GRIB_DUMP_FLAG_READ_ONLY
#define CODES_DUMP_FLAG_DUMP_OK GRIB_DUMP_FLAG_DUMP_OK
#define CODES_DUMP_FLAG_VALUES GRIB_DUMP_FLAG_VALUES
#define CODES_DUMP_FLAG_CODED GRIB_DUMP_FLAG_CODED
#define CODES_DUMP_FLAG_OCTECT GRIB_DUMP_FLAG_OCTECT
#define CODES_DUMP_FLAG_ALIASES GRIB_DUMP_FLAG_ALIASES
#define CODES_DUMP_FLAG_TYPE GRIB_DUMP_FLAG_TYPE
#define CODES_DUMP_FLAG_HEXADECIMAL GRIB_DUMP_FLAG_HEXADECIMAL
#define CODES_DUMP_FLAG_NO_DATA GRIB_DUMP_FLAG_NO_DATA
#define CODES_DUMP_FLAG_ALL_DATA GRIB_DUMP_FLAG_ALL_DATA
#define CODES_DUMP_FLAG_ALL_ATTRIBUTES GRIB_DUMP_FLAG_ALL_ATTRIBUTES
/* codes_nearest flags */
#define CODES_NEAREST_SAME_GRID GRIB_NEAREST_SAME_GRID
#define CODES_NEAREST_SAME_DATA GRIB_NEAREST_SAME_DATA
#define CODES_NEAREST_SAME_POINT GRIB_NEAREST_SAME_POINT
/*! Iteration is carried out on all the keys available in the message
\ingroup keys_iterator
\see codes_keys_iterator_new
*/
#define CODES_KEYS_ITERATOR_ALL_KEYS GRIB_KEYS_ITERATOR_ALL_KEYS
/*! read only keys are skipped by keys iterator.
\ingroup keys_iterator
\see codes_keys_iterator_new
*/
#define CODES_KEYS_ITERATOR_SKIP_READ_ONLY GRIB_KEYS_ITERATOR_SKIP_READ_ONLY
/*! optional keys are skipped by keys iterator.
\ingroup keys_iterator
\see codes_keys_iterator_new */
#define CODES_KEYS_ITERATOR_SKIP_OPTIONAL GRIB_KEYS_ITERATOR_SKIP_OPTIONAL
/*! edition specific keys are skipped by keys iterator.
\ingroup keys_iterator
\see codes_keys_iterator_new */
#define CODES_KEYS_ITERATOR_SKIP_EDITION_SPECIFIC GRIB_KEYS_ITERATOR_SKIP_EDITION_SPECIFIC
/*! coded keys are skipped by keys iterator.
\ingroup keys_iterator
\see codes_keys_iterator_new */
#define CODES_KEYS_ITERATOR_SKIP_CODED GRIB_KEYS_ITERATOR_SKIP_CODED
/*! computed keys are skipped by keys iterator.
\ingroup keys_iterator
\see codes_keys_iterator_new */
#define CODES_KEYS_ITERATOR_SKIP_COMPUTED GRIB_KEYS_ITERATOR_SKIP_COMPUTED
/*! duplicates of a key are skipped by keys iterator.
\ingroup keys_iterator
\see codes_keys_iterator_new */
#define CODES_KEYS_ITERATOR_SKIP_DUPLICATES GRIB_KEYS_ITERATOR_SKIP_DUPLICATES
/*! function keys are skipped by keys iterator.
\ingroup keys_iterator
\see codes_keys_iterator_new */
#define CODES_KEYS_ITERATOR_SKIP_FUNCTION GRIB_KEYS_ITERATOR_SKIP_FUNCTION
/*! only keys present in the dump
\ingroup keys_iterator
\see codes_keys_iterator_new */
#define CODES_KEYS_ITERATOR_DUMP_ONLY GRIB_KEYS_ITERATOR_DUMP_ONLY
typedef struct grib_values codes_values;
typedef struct grib_key_value_list codes_key_value_list;
/*! Codes handle, structure giving access to parsed values by keys
\ingroup codes_handle
\struct codes_handle
*/
typedef struct grib_handle codes_handle;
/*! GRIB multi field handle, structure used to build multi fields messages.
\ingroup codes_handle
\struct codes_multi_handle
*/
typedef struct grib_multi_handle codes_multi_handle;
/*! Codes context, structure containing the memory methods, the parsers and the formats.
\ingroup codes_context
\struct codes_context
*/
typedef struct grib_context codes_context;
/*! Codes iterator, structure supporting a geographic iteration of values in a GRIB message.
\ingroup iterators
\struct codes_iterator
*/
typedef struct grib_iterator codes_iterator;
/*! Codes nearest, structure used to find the nearest points of a latitude longitude point in a GRIB message.
\ingroup iterators
\struct codes_nearest
*/
typedef struct grib_nearest codes_nearest;
typedef struct grib_box codes_box;
typedef struct grib_points codes_points;
/*! Codes keys iterator. Iterator over keys.
\ingroup keys_iterator
\struct codes_keys_iterator
*/
typedef struct grib_keys_iterator codes_keys_iterator;
typedef struct bufr_keys_iterator codes_bufr_keys_iterator;
typedef struct grib_fieldset codes_fieldset;
typedef struct grib_order_by codes_order_by;
typedef struct grib_where codes_where;
typedef struct grib_sarray codes_sarray;
typedef struct grib_oarray codes_oarray;
typedef struct grib_darray codes_darray;
typedef struct grib_iarray codes_iarray;
typedef struct grib_vdarray codes_vdarray;
typedef struct grib_vsarray codes_vsarray;
typedef struct grib_viarray codes_viarray;
typedef struct grib_string_list codes_string_list;
typedef struct grib_util_packing_spec codes_util_packing_spec;
typedef struct grib_util_grid_spec codes_util_grid_spec;
codes_fieldset *codes_fieldset_new_from_files(codes_context *c, char *filenames[], int nfiles, char **keys, int nkeys, const char *where_string, const char *order_by_string, int *err);
void codes_fieldset_delete(codes_fieldset* set);
void codes_fieldset_rewind(codes_fieldset* set);
int codes_fieldset_apply_order_by(codes_fieldset* set,const char* order_by_string);
codes_handle* codes_fieldset_next_handle(codes_fieldset* set,int* err);
int codes_fieldset_count(codes_fieldset *set);
int codes_values_check(codes_handle* h, codes_values* values, int count);
/*! \defgroup codes_index The indexing feature
The codes_index is the structure giving indexed access to messages in a file.
*/
/*! @{*/
/*! index structure to access messages in a file.
* \ingroup codes_index
* \struct codes_index
*/
typedef struct grib_index codes_index;
/**
* Create a new index form a file. The file is indexed with the keys in argument.
*
* @param c : context (NULL for default context)
* @param filename : name of the file of messages to be indexed
* @param keys : comma separated list of keys for the index.
* The type of the key can be explicitly declared appending :l for long,
* (or alternatively :i)
* :d for double, :s for string to the key name. If the type is not
* declared explicitly, the native type is assumed.
* @param err : 0 if OK, integer value on error
* @return the newly created index
*/
codes_index* codes_index_new_from_file(codes_context* c, char* filename,const char* keys,int *err);
/**
* Create a new index based on a set of keys.
*
* @param c : context (NULL for default context)
* @param keys : comma separated list of keys for the index.
* The type of the key can be explicitly declared appending :l for long,
* (or alternatively :i)
* :d for double, :s for string to the key name. If the type is not
* declared explicitly, the native type is assumed.
* @param err : 0 if OK, integer value on error
* @return the newly created index
*/
codes_index* codes_index_new(codes_context* c, const char* keys,int *err);
/**
* Indexes the file given in argument in the index given in argument.
*
* @param index : index
* @param filename : name of the file of messages to be indexed
* @return 0 if OK, integer value on error
*/
int codes_index_add_file(grib_index *index, const char *filename);
int codes_index_write(codes_index *index, const char *filename);
codes_index* codes_index_read(codes_context* c,const char* filename,int *err);
/**
* Get the number of distinct values of the key in argument contained in the index. The key must belong to the index.
*
* @param index : an index created from a file.
* The index must have been created with the key in argument.
* @param key : key for which the number of values is computed
* @param size : number of distinct values of the key in the index
* @return 0 if OK, integer value on error
*/
int codes_index_get_size(codes_index* index,const char* key,size_t* size);
/**
* Get the distinct values of the key in argument contained in the index. The key must belong to the index. This function is used when the type of the key was explicitly defined as long or when the native type of the key is long.
*
* @param index : an index created from a file.
* The index must have been created with the key in argument.
* @param key : key for which the values are returned
* @param values : array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
* @param size : size of the values array
* @return 0 if OK, integer value on error
*/
int codes_index_get_long(codes_index* index,const char* key,long* values,size_t *size);
/**
* Get the distinct values of the key in argument contained in the index. The key must belong to the index. This function is used when the type of the key was explicitly defined as double or when the native type of the key is double.
*
* @param index : an index created from a file.
* The index must have been created with the key in argument.
* @param key : key for which the values are returned
* @param values : array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
* @param size : size of the values array
* @return 0 if OK, integer value on error
*/
int codes_index_get_double(codes_index* index,const char* key, double* values,size_t *size);
/**
* Get the distinct values of the key in argument contained in the index. The key must belong to the index. This function is used when the type of the key was explicitly defined as string or when the native type of the key is string.
*
* @param index : an index created from a file.
* The index must have been created with the key in argument.
* @param key : key for which the values are returned
* @param values : array of values. The array must be allocated before entering this function and its size must be enough to contain all the values.
* @param size : size of the values array
* @return 0 if OK, integer value on error
*/
int codes_index_get_string(codes_index* index,const char* key,char** values,size_t *size);
/**
* Select the message subset with key==value. The value is a long. The key must have been created with long type or have long as native type if the type was not explicitly defined in the index creation.
*
* @param index : an index created from a file.
* The index must have been created with the key in argument.
* @param key : key to be selected
* @param value : value of the key to select
* @return 0 if OK, integer value on error
*/
int codes_index_select_long(codes_index* index,const char* key,long value);
/**
* Select the message subset with key==value. The value is a double. The key must have been created with double type or have double as native type if the type was not explicitly defined in the index creation.
*
* @param index : an index created from a file.
* The index must have been created with the key in argument.
* @param key : key to be selected
* @param value : value of the key to select
* @return 0 if OK, integer value on error
*/
int codes_index_select_double(codes_index* index,const char* key,double value);
/**
* Select the message subset with key==value. The value is a string. The key must have been created with string type or have string as native type if the type was not explicitly defined in the index creation.
*
* @param index : an index created from a file.
* The index must have been created with the key in argument.
* @param key : key to be selected
* @param value : value of the key to select
* @return 0 if OK, integer value on error
*/
int codes_index_select_string(codes_index* index,const char* key,char* value);
/**
* Create a new handle from an index after having selected the key values.
* All the keys belonging to the index must be selected before calling this function. Successive calls to this function will return all the handles compatible with the constraints defined selecting the values of the index keys.
* When no more handles are available from the index a NULL pointer is returned and the err variable is set to CODES_END_OF_INDEX.
*
* @param index : an index created from a file.
* @param err : 0 if OK, integer value on error. CODES_END_OF_INDEX when no more handles are contained in the index.
* @return grib handle.
*/
codes_handle* codes_handle_new_from_index(codes_index* index,int *err);
/**
* Delete the index.
*
* @param index : index to be deleted.
*/
void codes_index_delete(codes_index* index);
/*! @} */
/*! \defgroup codes_handle The message handle
The codes_handle is the structure giving access to parsed message values by keys.
*/
/*! @{*/
/**
* Counts the messages contained in a file resource.
*
* @param c : the context from which the handle will be created (NULL for default context)
* @param f : the file resource
* @param n : the number of messages in the file
* @return 0 if OK, integer value on error
*/
int codes_count_in_file(codes_context* c, FILE* f,int* n);
/**
* Counts the messages contained in a file.
*
* @param c : the context from which the handle will be created (NULL for default context)
* @param filename : the path to the file
* @param n : the number of messages in the file
* @return 0 if OK, integer value on error
*/
int codes_count_in_filename(codes_context* c, const char* filename, int* n);
/**
* Create a handle from a file resource.
* The file is read until a message is found. The message is then copied.
* Remember always to delete the handle when it is not needed anymore to avoid
* memory leaks.
*
* @param c : the context from which the handle will be created (NULL for default context)
* @param f : the file resource
* @param product : the kind of product e.g. PRODUCT_GRIB, PRODUCT_BUFR
* @param error : error code set if the returned handle is NULL and the end of file is not reached
* @return the new handle, NULL if the resource is invalid or a problem is encountered
*/
grib_handle* codes_handle_new_from_file(grib_context* c, FILE* f, ProductKind product, int* error);
/**
* Create a GRIB handle from a file resource.
* The file is read until a GRIB message is found. The message is then copied.
* Remember always to delete the handle when it is not needed anymore to avoid
* memory leaks.
*
* @param c : the context from which the handle will be created (NULL for default context)
* @param f : the file resource
* @param error : error code set if the returned handle is NULL and the end of file is not reached
* @return the new handle, NULL if the resource is invalid or a problem is encountered
*/
grib_handle* codes_grib_handle_new_from_file(grib_context* c, FILE* f, int* error);
/**
* Create a BUFR handle from a file resource.
* The file is read until a BUFR message is found. The message is then copied.
* Remember always to delete the handle when it is not needed anymore to avoid
* memory leaks.
*
* @param c : the context from which the handle will be created (NULL for default context)
* @param f : the file resource
* @param error : error code set if the returned handle is NULL and the end of file is not reached
* @return the new handle, NULL if the resource is invalid or a problem is encountered
*/
grib_handle* codes_bufr_handle_new_from_file(grib_context* c, FILE* f, int* error);
/**
* Write a coded message to a file.
*
* @param h : codes_handle to be written
* @param file : name of the output file
* @param mode : mode
* @return 0 if OK, integer value on error
*/
int codes_write_message(codes_handle* h,const char* file,const char* mode);
codes_handle* codes_grib_util_sections_copy(codes_handle* hfrom,codes_handle* hto,int what,int *err);
codes_string_list* codes_grib_util_get_param_id(const char* mars_param);
codes_string_list* codes_grib_util_get_mars_param(const char* param_id);
/**
* Create a handle from a user message in memory. The message will not be freed at the end.
* The message will be copied as soon as a modification is needed.
*
* @param c : the context from which the handle will be created (NULL for default context)
* @param data : the actual message
* @param data_len : the length of the message in number of bytes
* @return the new handle, NULL if the message is invalid or a problem is encountered
*/
codes_handle* codes_handle_new_from_message(codes_context* c, const void* data, size_t data_len);
/**
* Create a handle from a user message in memory. The message will not be freed at the end.
* The message will be copied as soon as a modification is needed.
* This function works also with multi field messages.
*
* @param c : the context from which the handle will be created (NULL for default context)
* @param data : the actual message
* @param data_len : the length of the message in number of bytes
* @param error : error code
* @return the new handle, NULL if the message is invalid or a problem is encountered
*/
codes_handle* codes_grib_handle_new_from_multi_message(codes_context* c,void** data,
size_t *data_len,int* error);
/**
* Create a handle from a user message. The message is copied and will be freed with the handle
*
* @param c : the context from which the handle will be created (NULL for default context)
* @param data : the actual message
* @param data_len : the length of the message in number of bytes
* @return the new handle, NULL if the message is invalid or a problem is encountered
*/
codes_handle* codes_handle_new_from_message_copy(codes_context* c, const void* data, size_t data_len);
/**
* Create a handle from a GRIB message contained in the samples directory.
* The message is copied at the creation of the handle
*
* @param c : the context from which the handle will be created (NULL for default context)
* @param sample_name : the name of the sample file (without the .tmpl extension)
* @return the new handle, NULL if the resource is invalid or a problem is encountered
*/
codes_handle* codes_grib_handle_new_from_samples (codes_context* c, const char* sample_name);
/**
* Create a handle from a BUFR message contained in a samples directory.
* The message is copied at the creation of the handle
*
* @param c : the context from which the handle will be created (NULL for default context)
* @param sample_name : the name of the sample file (without the .tmpl extension)
* @return the new handle, NULL if the resource is invalid or a problem is encountered
*/
codes_handle* codes_bufr_handle_new_from_samples (codes_context* c, const char* sample_name);
/**
* Clone an existing handle using the context of the original handle,
* The message is copied and reparsed
*
* @param h : The handle to be cloned
* @return the new handle, NULL if the message is invalid or a problem is encountered
*/
codes_handle* codes_handle_clone(codes_handle* h) ;
/**
* Frees a handle, also frees the message if it is not a user message
* @see codes_handle_new_from_message
* @param h : The handle to be deleted
* @return 0 if OK, integer value on error
*/
int codes_handle_delete(codes_handle* h);
/**
* Create an empty multi-field GRIB handle.
* Remember always to delete the multi-handle when it is not needed any more to avoid
* memory leaks.
*
* @param c : the context from which the handle will be created (NULL for default context)
*/
codes_multi_handle* codes_grib_multi_handle_new(codes_context* c);
/**
* Append the sections starting with start_section of the message pointed by h at
* the end of the multi-field GRIB handle mh.
* Remember always to delete the multi-handle when it is not needed any more to avoid
* memory leaks.
*
* @param h : The handle from which the sections are copied.
* @param start_section : section number. Starting from this section all the sections to the end of the message will be copied.
* @param mh : The multi-field handle on which the sections are appended.
* @return 0 if OK, integer value on error
*/
int codes_grib_multi_handle_append(codes_handle* h,int start_section,codes_multi_handle* mh);
/**
* Delete multi-field GRIB handle.
*
* @param mh : The multi-field handle to be deleted.
* @return 0 if OK, integer value on error
*/
int codes_grib_multi_handle_delete(codes_multi_handle* mh);
/**
* Write a multi-field GRIB handle in a file.
* Remember always to delete the multi-handle when it is not needed any more to avoid
* memory leaks.
*
* @param mh : The multi-field GRIB handle to be written.
* @param f : File on which the file handle is written.
* @return 0 if OK, integer value on error
*/
int codes_grib_multi_handle_write(codes_multi_handle* mh,FILE* f);
/*! @} */
/*! \defgroup handling_coded_messages Handling coded messages */
/*! @{ */
/**
* getting the message attached to a handle
*
* @param h : the handle to which the buffer should be gathered
* @param message : the pointer to be set to the handle's data
* @param message_length : On exit, the message size in number of bytes
* @return 0 if OK, integer value on error
*/
int codes_get_message(codes_handle* h ,const void** message, size_t *message_length );
/**
* getting a copy of the message attached to a handle
*
* @param h : the handle to which the buffer should be returned
* @param message : the pointer to the data buffer to be filled
* @param message_length : On entry, the size in number of bytes of the allocated empty message.
* On exit, the actual message length in number of bytes
* @return 0 if OK, integer value on error
*/
int codes_get_message_copy(codes_handle* h, void* message,size_t *message_length );
/*! @} */
/*! \defgroup iterators Iterating on latitude/longitude/values */
/*! @{ */
/*!
* \brief Create a new iterator from a GRIB handle, using current geometry and values.
*
* \param h : the handle from which the iterator will be created
* \param flags : flags for future use.
* \param error : error code
* \return the new iterator, NULL if no iterator can be created
*/
codes_iterator* codes_grib_iterator_new(codes_handle* h, unsigned long flags, int* error);
/**
* Get latitude/longitude and data values.
* The Latitudes, longitudes and values arrays must be properly allocated by the caller.
* Their required dimension can be obtained by getting the value of the integer key "numberOfPoints".
*
* @param h : handle from which geography and data values are taken
* @param lats : returned array of latitudes
* @param lons : returned array of longitudes
* @param values : returned array of data values
* @return 0 if OK, integer value on error
*/
int codes_grib_get_data(codes_handle *h, double *lats, double *lons, double *values);
/**
* Get the next value from an iterator.
*
* @param i : the iterator
* @param lat : on output latitude in degree
* @param lon : on output longitude in degree
* @param value : on output value of the point
* @return positive value if successful, 0 if no more data are available
*/
int codes_grib_iterator_next(codes_iterator *i, double* lat,double* lon,double* value);
/**
* Get the previous value from an iterator.
*
* @param i : the iterator
* @param lat : on output latitude in degree
* @param lon : on output longitude in degree
* @param value : on output value of the point*
* @return positive value if successful, 0 if no more data are available
*/
int codes_grib_iterator_previous(codes_iterator *i, double* lat,double* lon,double* value);
/**
* Test procedure for values in an iterator.
*
* @param i : the iterator
* @return boolean, 1 if the iterator still nave next values, 0 otherwise
*/
int codes_grib_iterator_has_next(codes_iterator *i);
/**
* Test procedure for values in an iterator.
*
* @param i : the iterator
* @return 0 if OK, integer value on error
*/
int codes_grib_iterator_reset(codes_iterator *i);
/**
* Frees an iterator from memory
*
* @param i : the iterator
* @return 0 if OK, integer value on error
*/
int codes_grib_iterator_delete(codes_iterator *i);
/*!
* \brief Create a new nearest from a handle, using current geometry .
*
* \param h : the handle from which the iterator will be created
* \param error : error code
* \return the new nearest, NULL if no nearest can be created
*/
codes_nearest* codes_grib_nearest_new(codes_handle* h, int* error);
/**
* Find the 4 nearest points of a latitude longitude point.
* The flags are provided to speed up the process of searching. If you are
* sure that the point you are asking for is not changing from a call
* to another you can use CODES_NEAREST_SAME_POINT. The same is valid for
* the grid. Flags can be used together doing a bitwise OR.
* The distances are given in kilometres.
*
* @param nearest : nearest structure
* @param h : handle from which geography and data values are taken
* @param inlat : latitude of the point to search for
* @param inlon : longitude of the point to search for
* @param flags : CODES_NEAREST_SAME_POINT, CODES_NEAREST_SAME_GRID
* @param outlats : returned array of latitudes of the nearest points
* @param outlons : returned array of longitudes of the nearest points
* @param values : returned array of data values of the nearest points
* @param distances : returned array of distances from the nearest points
* @param indexes : returned array of indexes of the nearest points
* @param len : size of the arrays
* @return 0 if OK, integer value on error
*/
int codes_grib_nearest_find(codes_nearest *nearest,codes_handle* h,double inlat,double inlon,
unsigned long flags,double* outlats,double* outlons,
double* values,double* distances,int* indexes,size_t *len);
/**
* Frees an nearest from memory
*
* @param nearest : the nearest
* @return 0 if OK, integer value on error
*/
int codes_grib_nearest_delete(codes_nearest *nearest);
/**
* Find the nearest point of a set of points whose latitudes and longitudes
* are given in the inlats, inlons arrays respectively.
* If the flag is_lsm is 1 the nearest land point is returned and the
* grib passed as handle (h) is considered a land sea mask.
* The land nearest point is the nearest point with land sea mask value>=0.5.
* If no nearest land points are found the nearest value is returned.
* If the flag is_lsm is 0 the nearest point is returned.
* values, distances, indexes (in the "values" array) for the nearest points (ilons,ilats)
* are returned.
* The distances are given in kilometres.
*
* @param h : handle from which geography and data values are taken
* @param is_lsm : lsm flag (1-> nearest land, 0-> nearest)
* @param inlats : latitudes of the points to search for
* @param inlons : longitudes of the points to search for
* @param npoints : number of points (size of the inlats,inlons,outlats,outlons,values,distances,indexes arrays)
* @param outlats : returned array of latitudes of the nearest points
* @param outlons : returned array of longitudes of the nearest points
* @param values : returned array of data values of the nearest points
* @param distances : returned array of distances from the nearest points
* @param indexes : returned array of indexes of the nearest points
* @return 0 if OK, integer value on error
*/
int codes_grib_nearest_find_multiple(codes_handle* h,int is_lsm,
double* inlats,double* inlons,long npoints,
double* outlats,double* outlons,
double* values,double* distances, int* indexes);
/* @} */
/*! \defgroup get_set Accessing header and data values */
/*! @{ */
/**
* Get the number offset of a key, in a message if several keys of the same name
* are present, the offset of the last one is returned
*
* @param h : the handle to get the offset from
* @param key : the key to be searched
* @param offset : the address of a size_t where the offset will be set
* @return 0 if OK, integer value on error
*/
int codes_get_offset(codes_handle* h, const char* key, size_t* offset);
/**
* Get the number of coded value from a key, if several keys of the same name are present, the total sum is returned
*
* @param h : the handle to get the offset from
* @param key : the key to be searched
* @param size : the address of a size_t where the size will be set
* @return 0 if OK, integer value on error
*/
int codes_get_size(codes_handle* h, const char* key,size_t *size);
/**
* Get the length of the string representation of the key, if several keys of the same name are present, the maximum length is returned
*
* @param h : the handle to get the offset from
* @param key : the key to be searched
* @param length : the address of a size_t where the length will be set
* @return 0 if OK, integer value on error
*/
int codes_get_length(codes_handle* h, const char* key,size_t *length);
/**
* Get a long value from a key, if several keys of the same name are present, the last one is returned
* @see codes_set_long
*
* @param h : the handle to get the data from
* @param key : the key to be searched
* @param value : the address of a long where the data will be retrieved
* @return 0 if OK, integer value on error
*/
int codes_get_long(codes_handle* h, const char* key, long* value );
/**
* Get a double value from a key, if several keys of the same name are present, the last one is returned
* @see codes_set_double
*
* @param h : the handle to get the data from
* @param key : the key to be searched
* @param value : the address of a double where the data will be retrieved
* @return 0 if OK, integer value on error
*/
int codes_get_double(codes_handle* h, const char* key, double* value );
/**
* Get as double the i-th element of the "key" array
*
* @param h : the handle to get the data from
* @param key : the key to be searched
* @param i : zero-based index
* @param value : the address of a double where the data will be retrieved
* @return 0 if OK, integer value on error
*/
int codes_get_double_element(codes_handle* h, const char* key, int i, double* value);
/**
* Get as double array the elements of the "key" array whose indexes are listed in the input array i
*
* @param h : the handle to get the data from
* @param key : the key to be searched
* @param i : zero-based array of indexes
* @param size : size of the i and value arrays
* @param value : the double array for the data values
* @return 0 if OK, integer value on error
*/
int codes_get_double_elements(codes_handle* h, const char* key, int* i, long size, double* value);
/**
* Get a string value from a key, if several keys of the same name are present, the last one is returned
* @see codes_set_string
*
* @param h : the handle to get the data from
* @param key : the key to be searched
* @param mesg : the address of a string where the data will be retrieved
* @param length : the address of a size_t that contains allocated length of the string on input, and that contains the actual length of the string on output
* @return 0 if OK, integer value on error
*/
int codes_get_string(codes_handle* h, const char* key, char* mesg, size_t *length );
/**
* Get string array values from a key. If several keys of the same name are present, the last one is returned
* @see codes_set_string_array
*
* @param h : the handle to get the data from
* @param key : the key to be searched
* @param vals : the address of a string array where the data will be retrieved
* @param length : the address of a size_t that contains allocated length of the array on input, and that contains the actual length of the array on output
* @return 0 if OK, integer value on error
*/
int codes_get_string_array(codes_handle* h, const char* key, char** vals, size_t *length);
/**
* Get raw bytes values from a key. If several keys of the same name are present, the last one is returned
* @see codes_set_bytes
*
* @param h : the handle to get the data from
* @param key : the key to be searched
* @param bytes : the address of a byte array where the data will be retrieved
* @param length : the address of a size_t that contains allocated length of the byte array on input, and that contains the actual length of the byte array on output
* @return 0 if OK, integer value on error
*/
int codes_get_bytes(codes_handle* h, const char* key, unsigned char* bytes, size_t *length);
/**
* Get double array values from a key. If several keys of the same name are present, the last one is returned
* @see codes_set_double_array
*
* @param h : the handle to get the data from
* @param key : the key to be searched
* @param vals : the address of a double array where the data will be retrieved
* @param length : the address of a size_t that contains allocated length of the double array on input, and that contains the actual length of the double array on output
* @return 0 if OK, integer value on error
*/
int codes_get_double_array(codes_handle* h, const char* key, double* vals, size_t *length);
/**
* Get long array values from a key. If several keys of the same name are present, the last one is returned
* @see codes_set_long_array
*
* @param h : the handle to get the data from
* @param key : the key to be searched
* @param vals : the address of a long array where the data will be retrieved
* @param length : the address of a size_t that contains allocated length of the long array on input, and that contains the actual length of the long array on output
* @return 0 if OK, integer value on error
*/
int codes_get_long_array(codes_handle* h, const char* key, long* vals, size_t *length);
/* setting data */
/**
* Copy the keys belonging to a given namespace from a source handle to a destination handle
*
*
* @param dest : destination handle
* @param name : namespace
* @param src : source handle
* @return 0 if OK, integer value on error
*/
int codes_copy_namespace(codes_handle* dest, const char* name, codes_handle* src);
/**
* Set a long value from a key. If several keys of the same name are present, the last one is set
* @see codes_get_long
*
* @param h : the handle to set the data to
* @param key : the key to be searched
* @param val : a long where the data will be read
* @return 0 if OK, integer value on error
*/
int codes_set_long(codes_handle* h, const char* key, long val);
/**
* Set a double value from a key. If several keys of the same name are present, the last one is set
* @see codes_get_double
*
* @param h : the handle to set the data to
* @param key : the key to be searched
* @param val : a double where the data will be read
* @return 0 if OK, integer value on error
*/
int codes_set_double(codes_handle* h, const char* key, double val);
/**
* Set a string value from a key. If several keys of the same name are present, the last one is set
* @see codes_get_string
*
* @param h : the handle to set the data to
* @param key : the key to be searched
* @param mesg : the address of a string where the data will be read
* @param length : the address of a size_t that contains the length of the string on input, and that contains the actual packed length of the string on output
* @return 0 if OK, integer value on error
*/
int codes_set_string(codes_handle* h, const char* key , const char* mesg, size_t *length);
/**
* Set a bytes array from a key. If several keys of the same name are present, the last one is set
* @see codes_get_bytes
*
* @param h : the handle to set the data to
* @param key : the key to be searched
* @param bytes : the address of a byte array where the data will be read
* @param length : the address of a size_t that contains the length of the byte array on input, and that contains the actual packed length of the byte array on output
* @return 0 if OK, integer value on error
*/
int codes_set_bytes(codes_handle* h, const char* key, const unsigned char* bytes, size_t *length);
/**
* Set a double array from a key. If several keys of the same name are present, the last one is set
* @see codes_get_double_array
*
* @param h : the handle to set the data to
* @param key : the key to be searched
* @param vals : the address of a double array where the data will be read
* @param length : a size_t that contains the length of the byte array on input
* @return 0 if OK, integer value on error
*/
int codes_set_double_array(codes_handle* h, const char* key, const double* vals, size_t length);
/**
* Same as codes_set_double_array but allows setting of READ-ONLY keys like codedValues.
* Use with great caution!!
*/
int codes_set_force_double_array(codes_handle* h, const char* key, const double* vals, size_t length);
/**
* Set a long array from a key. If several keys of the same name are present, the last one is set
* @see codes_get_long_array
*
* @param h : the handle to set the data to
* @param key : the key to be searched
* @param vals : the address of a long array where the data will be read
* @param length : a size_t that contains the length of the long array on input
* @return 0 if OK, integer value on error
*/
int codes_set_long_array(codes_handle* h, const char* key, const long* vals, size_t length);
/**
* Set a string array from a key. If several keys of the same name are present, the last one is set
* @see codes_get_long_array
*
* @param h : the handle to set the data to
* @param key : the key to be searched
* @param vals : the address of a string array where the data will be read
* @param length : a size_t that contains the length of the array on input
* @return 0 if OK, integer value on error
*/
int codes_set_string_array(codes_handle *h, const char *key, const char **vals, size_t length);
/*! @} */
/**
* Print all keys, with the context print procedure and dump mode to a resource
*
* @param h : the handle to be printed
* @param out : output file handle
* @param mode : Examples of available dump modes: debug wmo
* @param option_flags : all the CODES_DUMP_FLAG_x flags can be used
* @param arg : used to provide a format to output data (experimental)
*/
void codes_dump_content(codes_handle* h,FILE* out,const char* mode, unsigned long option_flags,void* arg);
/**
* Print all keys from the parsed definition files available in a context
*
* @param f : the File used to print the keys on
* @param c : the context that contains the cached definition files to be printed
*/
void codes_dump_action_tree(codes_context* c, FILE* f) ;
/*! \defgroup context The context object
The context is a long life configuration object of eccodes.
It is used to define special allocation and free routines or
to set special eccodes behaviours and variables.
*/
/*! @{ */
/* TODO: function pointers
grib_malloc_proc
grib_realloc_proc
grib_log_proc
grib_print_proc
grib_data_read_proc
grib_data_write_proc
grib_data_tell_proc
grib_data_seek_proc
grib_data_eof_proc
*/
/**
* Get the static default context
*
* @return the default context, NULL it the context is not available
*/
codes_context* codes_context_get_default(void);
/**
* Frees the cached definition files of the context
*