v5d.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /* Vis5D version 5.0 */
  2. /*
  3. Vis5D system for visualizing five dimensional gridded data sets
  4. Copyright (C) 1990 - 1996 Bill Hibbard, Brian Paul, Dave Santek,
  5. and Andre Battaiola.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef V5D_H
  19. #define V5D_H
  20. #include <sys/types.h>
  21. /*
  22. * A numeric version number which we can test for in utility programs which
  23. * use the v5d functions. For example, we can do tests like this:
  24. * #if V5D_VERSION > 42
  25. * do something
  26. * #else
  27. * do something else
  28. * #endif
  29. *
  30. * If V5D_VERSION is not defined, then its value is considered to be zero.
  31. */
  32. #define V5D_VERSION 42
  33. /*
  34. * Define our own 1 and 2-byte data types. We use these names to avoid
  35. * collisions with types defined by the OS include files.
  36. */
  37. typedef unsigned char V5Dubyte; /* Must be 1 byte, except for cray */
  38. typedef unsigned short V5Dushort; /* Must be 2 byte, except for cray */
  39. #define MISSING 1.0e35
  40. #define IS_MISSING(X) ( (X) >= 1.0e30 )
  41. /* Limits on 5-D grid size: (must match those in v5df.h!!!) */
  42. #define MAXVARS 30
  43. #define MAXTIMES 400
  44. #define MAXROWS 400
  45. #define MAXCOLUMNS 800
  46. #define MAXLEVELS 100
  47. /************************************************************************/
  48. /*** ***/
  49. /*** Functions for writing v5d files. See README file for details. ***/
  50. /*** These are the functions user's will want for writing file ***/
  51. /*** converters, etc. ***/
  52. /*** ***/
  53. /************************************************************************/
  54. extern int v5dCreateSimple(const char *name,
  55. int numtimes, int numvars,
  56. int nr, int nc, int nl,
  57. const char varname[MAXVARS][10],
  58. const int timestamp[],
  59. const int datestamp[],
  60. float northlat, float latinc,
  61. float westlon, float loninc,
  62. float bottomhgt, float hgtinc);
  63. extern int v5dCreate(const char *name,
  64. int numtimes, int numvars,
  65. int nr, int nc, const int nl[],
  66. const char varname[MAXVARS][10],
  67. const int timestamp[],
  68. const int datestamp[],
  69. int compressmode,
  70. int projection,
  71. const float proj_args[],
  72. int vertical, const float vert_args[]);
  73. extern int v5dWrite(int time, int var, const float data[]);
  74. extern int v5dClose(void);
  75. extern int v5dSetLowLev(int lowlev[]);
  76. extern int v5dSetUnits(int var, const char *units);
  77. /************************************************************************/
  78. /*** ***/
  79. /*** Definition of v5d struct and function prototypes. ***/
  80. /*** These functions are used by vis5d and advanced v5d utilities. ***/
  81. /*** ***/
  82. /************************************************************************/
  83. #define MAXPROJARGS 100
  84. #define MAXVERTARGS (MAXLEVELS+1)
  85. /*
  86. * This struct describes the structure of a .v5d file.
  87. */
  88. typedef struct
  89. {
  90. /* PUBLIC (user can freely read, sometimes write, these fields) */
  91. int NumTimes; /* Number of time steps */
  92. int NumVars; /* Number of variables */
  93. int Nr; /* Number of rows */
  94. int Nc; /* Number of columns */
  95. int Nl[MAXVARS]; /* Number of levels per variable */
  96. int LowLev[MAXVARS]; /* Lowest level per variable */
  97. char VarName[MAXVARS][10]; /* 9-character variable names */
  98. char Units[MAXVARS][20]; /* 19-character units for variables */
  99. int TimeStamp[MAXTIMES]; /* Time in HHMMSS format */
  100. int DateStamp[MAXTIMES]; /* Date in YYDDD format */
  101. float MinVal[MAXVARS]; /* Minimum variable data values */
  102. float MaxVal[MAXVARS]; /* Maximum variable data values */
  103. /* This info is used for external function computation */
  104. short McFile[MAXTIMES][MAXVARS]; /* McIDAS file number in 1..9999 */
  105. short McGrid[MAXTIMES][MAXVARS]; /* McIDAS grid number in 1..? */
  106. int VerticalSystem; /* Which vertical coordinate system */
  107. float VertArgs[MAXVERTARGS]; /* Vert. Coord. Sys. arguments... */
  108. /*
  109. IF VerticalSystem==0 THEN
  110. -- Linear scale, equally-spaced levels in generic units
  111. VertArgs[0] = Height of bottom-most grid level in generic units
  112. VertArgs[1] = Increment between levels in generic units
  113. ELSE IF VerticalSystem==1 THEN
  114. -- Linear scale, equally-spaced levels in km
  115. VertArgs[0] = Height of bottom grid level in km
  116. VertArgs[1] = Increment between levels in km
  117. ELSE IF VerticalSystem==2 THEN
  118. -- Linear scale, Unequally spaced levels in km
  119. VertArgs[0] = Height of grid level 0 (bottom) in km
  120. ... ...
  121. VertArgs[n] = Height of grid level n in km
  122. ELSE IF VerticalSystem==3 THEN
  123. -- Linear scale, Unequally spaced levels in mb
  124. VertArgs[0] = Pressure of grid level 0 (bottom) in mb
  125. ... ...
  126. VertArgs[n] = Pressure of grid level n in mb
  127. ENDIF
  128. */
  129. int Projection; /* Which map projection */
  130. float ProjArgs[MAXPROJARGS]; /* Map projection arguments... */
  131. /*
  132. IF Projection==0 THEN
  133. -- Rectilinear grid, generic units
  134. ProjArgs[0] = North bound, Y coordinate of grid row 0
  135. ProjArgs[1] = West bound, X coordiante of grid column 0
  136. ProjArgs[2] = Increment between rows
  137. ProjArgs[3] = Increment between columns
  138. NOTES: X coordinates increase to the right, Y increase upward.
  139. NOTES: Coordinate system is right-handed.
  140. ELSE IF Projection==1 THEN
  141. -- Cylindrical equidistant (Old VIS-5D)
  142. -- Rectilinear grid in lat/lon
  143. ProjArgs[0] = Latitude of grid row 0, north bound, in degrees
  144. ProjArgs[1] = Longitude of grid column 0, west bound, in deg.
  145. ProjArgs[2] = Increment between rows in degrees
  146. ProjArgs[3] = Increment between rows in degrees
  147. NOTES: Coordinates (degrees) increase to the left and upward.
  148. ELSE IF Projection==2 THEN
  149. -- Lambert conformal
  150. ProjArgs[0] = Standared Latitude 1 of conic projection
  151. ProjArgs[1] = Standared Latitude 2 of conic projection
  152. ProjArgs[2] = Row of North/South pole
  153. ProjArgs[3] = Column of North/South pole
  154. ProjArgs[4] = Longitude which is parallel to columns
  155. ProjArgs[5] = Increment between grid columns in km
  156. ELSE IF Projection==3 THEN
  157. -- Polar Stereographic
  158. ProjArgs[0] = Latitude of center of projection
  159. ProjArgs[1] = Longitude of center of projection
  160. ProjArgs[2] = Grid row of center of projection
  161. ProjArgs[3] = Grid column of center of projection
  162. ProjArgs[4] = Increment between grid columns at center in km
  163. ELSE IF Projection==4 THEN
  164. -- Rotated
  165. ProjArgs[0] = Latitude on rotated globe of grid row 0
  166. ProjArgs[1] = Longitude on rotated globe of grid column 0
  167. ProjArgs[2] = Degrees of latitude on rotated globe between
  168. grid rows
  169. ProjArgs[3] = Degrees of longitude on rotated globe between
  170. grid columns
  171. ProjArgs[4] = Earth latitude of (0, 0) on rotated globe
  172. ProjArgs[5] = Earth longitude of (0, 0) on rotated globe
  173. ProjArgs[6] = Clockwise rotation of rotated globe in degrees
  174. ENDIF
  175. */
  176. int CompressMode; /* 1, 2 or 4 = # bytes per grid point */
  177. char FileVersion[10]; /* 9-character version number */
  178. /* PRIVATE (not to be touched by user code) */
  179. unsigned int FileFormat; /* COMP5D file version or 0 if .v5d */
  180. int FileDesc; /* Unix file descriptor */
  181. char Mode; /* 'r' = read, 'w' = write */
  182. off_t CurPos; /* current position of file pointer */
  183. off_t FirstGridPos; /* position of first grid in file */
  184. off_t GridSize[MAXVARS]; /* size of each grid */
  185. off_t SumGridSizes; /* sum of GridSize[0..NumVars-1] */
  186. } v5dstruct;
  187. extern float pressure_to_height(float pressure);
  188. extern float height_to_pressure(float height);
  189. extern int v5dYYDDDtoDays(int yyddd);
  190. extern int v5dHHMMSStoSeconds(int hhmmss);
  191. extern int v5dDaysToYYDDD(int days);
  192. extern int v5dSecondsToHHMMSS(int seconds);
  193. extern void v5dPrintStruct(const v5dstruct * v);
  194. extern v5dstruct *v5dNewStruct(void);
  195. extern void v5dFreeStruct(v5dstruct * v);
  196. extern void v5dInitStruct(v5dstruct * v);
  197. extern int v5dVerifyStruct(const v5dstruct * v);
  198. extern void v5dCompressGrid(int nr, int nc, int nl, int compressmode,
  199. const float data[], void *compdata,
  200. float ga[], float gb[],
  201. float *minval, float *maxval);
  202. extern void v5dDecompressGrid(int nr, int nc, int nl, int compressmode,
  203. void *compdata,
  204. float ga[], float gb[], float data[]);
  205. extern int v5dSizeofGrid(const v5dstruct * v, int time, int var);
  206. extern v5dstruct *v5dOpenFile(const char *filename, v5dstruct * v);
  207. extern int v5dCreateFile(const char *filename, v5dstruct * v);
  208. extern v5dstruct *v5dUpdateFile(const char *filename, v5dstruct * v);
  209. extern int v5dCloseFile(v5dstruct * v);
  210. extern int v5dReadCompressedGrid(v5dstruct * v,
  211. int time, int var,
  212. float *ga, float *gb, void *compdata);
  213. extern int v5dReadGrid(v5dstruct * v, int time, int var, float data[]);
  214. extern int v5dWriteCompressedGrid(const v5dstruct * v,
  215. int time, int var,
  216. const float *ga, const float *gb,
  217. const void *compdata);
  218. extern int v5dWriteGrid(v5dstruct * v, int time, int var, const float data[]);
  219. #endif