PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wrfv2_fire/external/io_grib1/MEL_grib1/display_gribhdr.c

http://github.com/jbeezley/wrf-fire
C | 175 lines | 91 code | 12 blank | 72 comment | 23 complexity | a07911f93d7d17cf2bc88b55f92b97e4 MD5 | raw file
Possible License(s): AGPL-1.0
  1. /* FILE: display_gribhdr.c 10-OCT-96 by Alice Nakajima/SAIC */
  2. #include <stdio.h> /* standard I/O header file */
  3. #include <stdlib.h>
  4. #include "dprints.h" /* function prototypes */
  5. #include "gribfuncs.h" /* prototypes */
  6. #define COLS 10 /* # of cols to print per line */
  7. #define HALFWAY COLS/2 /* half of #cols */
  8. /*
  9. **********************************************************************
  10. * A. FUNCTION: display_gribhdr
  11. * do a byte dump for each of the defined GRIB Sections in the
  12. * GRIB message currently stored in the Grib Header struct.
  13. *
  14. * INTERFACE:
  15. * void display_gribhdr (gribhdr)
  16. *
  17. * ARGUMENTS (I=input, O=output, I&O=input and output):
  18. * (I) GRIB_HDR *gribhdr;
  19. * holds Grib header info to be printed to standard output;
  20. *
  21. * RETURNS: nothing;
  22. **********************************************************************
  23. */
  24. #if PROTOTYPE_NEEDED
  25. void display_gribhdr ( GRIB_HDR *hdr)
  26. #else
  27. void display_gribhdr ( hdr)
  28. GRIB_HDR *hdr;
  29. #endif
  30. {
  31. char *func="dislay_gribhr";
  32. unsigned char *ptr, *ptr2;
  33. long i, j, cnt, skip;
  34. char title[200];
  35. fprintf(stdout, "In %s: showing Grib msg in Grib Hdr:\n", func);
  36. /*
  37. *
  38. * A.1 IF (the entire_msg buffer is NULL) THEN
  39. * PRINT error
  40. * RETURN
  41. * ENDIF
  42. */
  43. if (hdr->entire_msg == NULL) {
  44. fprintf(stdout,"Entire Msg Buffer is Null, cannot proceed;\n");
  45. goto RETURN;
  46. }
  47. /*
  48. *
  49. * A.2 IF (sum of section lengths does not equal Total Msg length) THEN
  50. * PRINT warning
  51. * ELSE
  52. * PRINT msg_length
  53. * ENDIF
  54. */
  55. if (hdr->msg_length != (hdr->ids_len + hdr->pds_len + hdr->gds_len
  56. + hdr->bms_len + hdr->bds_len + hdr->eds_len))
  57. fprintf(stdout,"\n*******************************************\n"\
  58. "WARNING: Msg_length=%d but SUM of sect lengths= %d "\
  59. "(%d+%d+%d+%d+%d+%d);\n*******************************************\n",
  60. hdr->msg_length,
  61. hdr->ids_len+hdr->pds_len+hdr->gds_len+hdr->bms_len+
  62. hdr->bds_len+hdr->eds_len,
  63. hdr->ids_len, hdr->pds_len, hdr->gds_len , hdr->bms_len,
  64. hdr->bds_len, hdr->eds_len);
  65. else
  66. fprintf(stdout,"Msg_length=%d; IDS=%ld,"\
  67. "PDS=%ld, GDS=%ld, BMS=%ld, BDS=%ld, EDS=%ld;\n",
  68. hdr->msg_length,
  69. hdr->ids_len, hdr->pds_len, hdr->gds_len , hdr->bms_len,
  70. hdr->bds_len, hdr->eds_len);
  71. fprintf(stdout,"Printing each defined section, upto 100 bytes only\n");
  72. /*
  73. *
  74. * A.3 PRINT Identification Defn Section if defined;
  75. * FUNCTION hdr_print !dump out its content
  76. */
  77. if (hdr->ids_ptr == NULL) fprintf(stdout,"Section 0 is Null, len=%ld;\n",
  78. hdr->ids_len);
  79. else {
  80. cnt= (hdr->ids_len > 100 ? 100 : hdr->ids_len);
  81. sprintf(title,"Section 0 Content Len=%ld (upto 100 bytes)",
  82. hdr->ids_len);
  83. hdr_print (title, hdr->ids_ptr, cnt);
  84. }
  85. /*
  86. *
  87. * A.4 PRINT Product Defn Section if defined;
  88. * FUNCTION hdr_print !dump out its content
  89. */
  90. if (hdr->pds_ptr == NULL) fprintf(stdout,"Product Data Section is Null, "\
  91. "len=%ld;\n", hdr->pds_len);
  92. else {
  93. cnt= (hdr->pds_len > 100 ? 100 : hdr->pds_len);
  94. sprintf(title,"PDS Content (offs=%ld, Len=%ld)",
  95. (long)(hdr->pds_ptr - hdr->entire_msg), hdr->pds_len);
  96. hdr_print (title, hdr->pds_ptr, cnt);
  97. }
  98. /*
  99. *
  100. * A.5 PRINT Grid Defn Section if defined;
  101. * FUNCTION hdr_print !dump out its content
  102. */
  103. if (hdr->gds_ptr == NULL) fprintf(stdout,"Grid Defn Section is Null, "\
  104. "len=%ld;\n", hdr->gds_len);
  105. else {
  106. cnt= (hdr->gds_len > 100 ? 100 : hdr->gds_len);
  107. sprintf(title,"GDS Content (offs=%ld, Len=%ld)",
  108. (long)(hdr->gds_ptr - hdr->entire_msg), hdr->gds_len);
  109. hdr_print (title, hdr->gds_ptr, cnt);
  110. }
  111. /*
  112. *
  113. * A.6 PRINT Bitmap Data Section if defined;
  114. * FUNCTION hdr_print !dump out its content upto 100 bytes
  115. */
  116. if (hdr->bms_ptr == NULL) fprintf(stdout,"Bitmap Section is Null, "\
  117. "len=%ld;\n", hdr->bms_len);
  118. else {
  119. cnt= (hdr->bms_len > 100 ? 100 : hdr->bms_len);
  120. sprintf(title,"BMS Content (offs=%ld, Len=%ld)",
  121. (long)(hdr->bms_ptr - hdr->entire_msg), hdr->bms_len);
  122. hdr_print (title, hdr->bms_ptr, cnt);
  123. }
  124. /*
  125. *
  126. * A.7 PRINT Binary Defn Section if defined;
  127. * FUNCTION hdr_print !dump out its content upto 100 bytes
  128. */
  129. if (hdr->bds_ptr == NULL) fprintf(stdout,"Binary Data Section is Null, "\
  130. "len=%ld;\n", hdr->bds_len);
  131. else {
  132. cnt= (hdr->bds_len > 100 ? 100 : hdr->bds_len);
  133. sprintf(title,"BDS Content (offs=%ld, Len=%ld)",
  134. (long)(hdr->bds_ptr - hdr->entire_msg), hdr->bds_len);
  135. hdr_print (title, hdr->bds_ptr, cnt);
  136. }
  137. /*
  138. *
  139. * A.8 PRINT End Defn Section if defined;
  140. * FUNCTION hdr_print !dump out its content
  141. */
  142. if (hdr->eds_ptr == NULL) fprintf(stdout,"End Data Section is Null, "\
  143. "len=%ld;\n", hdr->eds_len);
  144. else {
  145. cnt= (hdr->eds_len > 100 ? 100 : hdr->eds_len);
  146. sprintf(title, "End Data Section (offs=%ld, size=%ld) ",
  147. (long) (hdr->eds_ptr - hdr->entire_msg), hdr->eds_len);
  148. hdr_print (title, hdr->eds_ptr, cnt);
  149. }
  150. RETURN:
  151. /*
  152. *
  153. * A.9 RETURN to caller !return nothing
  154. */
  155. fprintf(stdout, "%s complete;\n", func);
  156. return;
  157. /*
  158. *
  159. * END OF FUNCTION
  160. *
  161. *
  162. */
  163. }