[HDF]hdf-4.2.6类库的使用
HDF文件包括科學(xué)數(shù)據(jù)和VData部分。讀取HDF格式的calipso數(shù)據(jù),用GDAL可以方便的讀取其中的子數(shù)據(jù)集,但是沒(méi)有發(fā)現(xiàn)GDAL中提供讀取Vdata的方法。所以只好考慮借助hdf-4.2.6類庫(kù)本身。畢竟GDAL也是采用的hdf-4.2.6類庫(kù)進(jìn)行了一次封裝。
首先從HdfGroup網(wǎng)站下載一個(gè)編譯好的安裝包。解壓后目錄如下:
新建一個(gè)Win32控制臺(tái)項(xiàng)目。
添加包含和引用的lib,注意安裝目錄文件夾下的lib文件夾中的.lib文件應(yīng)該是relese版本的,我這里引用了dll文件夾下的.lib文件。
從Hdf4.2.6源碼中找到VD_create_onefield_vdatas.c文件。我這里修改為VD_create_onefield_vdatas.cpp,添加到項(xiàng)目中,把項(xiàng)目中的HdfFirst.cpp直接排除掉,因?yàn)槔锩嬗袀€(gè)Main函數(shù)。
同時(shí)在VD_create_onefield_vdatas.cpp添加
#include "stdafx.h"
完整代碼:
1 #include "stdafx.h" 2 #include "hdf.h" 3 4 #define FILE_NAME "General_Vdatas.hdf" 5 #define CLASS1_NAME "5x1 Array" 6 #define CLASS2_NAME "6x4 Array" 7 #define VDATA1_NAME "First Vdata" 8 #define VDATA2_NAME "Second Vdata" 9 #define FIELD1_NAME "Single-component Field" 10 #define FIELD2_NAME "Multi-component Field" 11 #define N_RECORDS_1 5 /* number of records the first vdata contains */ 12 #define N_RECORDS_2 6 /* number of records the second vdata contains */ 13 #define ORDER_2 4 /* order of the field in the second vdata */ 14 /* Note that the order of the field in the first vdata is 1 */ 15 16 int main( ) 17 { 18 /************************* Variable declaration **************************/ 19 20 intn status_n; /* returned status for functions returning an intn */ 21 int32 status_32; /* returned status for functions returning an int32 */ 22 int32 file_id, vdata1_ref, vdata2_ref; 23 24 /* 25 * Define an array to buffer the data of the first vdata. 26 */ 27 char8 vdata1_buf [N_RECORDS_1] = {'V', 'D', 'A', 'T', 'A'}; 28 29 /* 30 * Define an array to buffer the data of the second vdata. 31 */ 32 int32 vdata2_buf [N_RECORDS_2][ORDER_2] = {{1, 2, 3, 4}, {2, 4, 6, 8}, 33 {3, 6, 9, 12}, {4, 8, 12, 16}, 34 {5, 10, 15, 20}, {6, 12, 18, 24}}; 35 36 /********************** End of variable declaration **********************/ 37 38 /* 39 * Open the HDF file for writing. 40 */ 41 file_id = Hopen (FILE_NAME, DFACC_WRITE, 0); 42 43 /* 44 * Initialize the VS interface. 45 */ 46 status_n = Vstart (file_id); 47 48 /* 49 * Create the first vdata and populate it with data from the vdata1_buf 50 * array. Note that the buffer vdata1_buf is cast to (uint8 *) for the 51 * benefit of generic data type. 52 */ 53 vdata1_ref = VHstoredata (file_id, FIELD1_NAME, (uint8 *)vdata1_buf, 54 N_RECORDS_1, DFNT_CHAR8, VDATA1_NAME, CLASS1_NAME); 55 56 /* 57 * Create the second vdata and populate it with data from the vdata2_buf 58 * array. 59 */ 60 vdata2_ref = VHstoredatam (file_id, FIELD2_NAME, (uint8 *)vdata2_buf, 61 N_RECORDS_2, DFNT_INT32, VDATA2_NAME, CLASS2_NAME, ORDER_2); 62 63 /* 64 * Terminate access to the VS interface and close the HDF file. 65 */ 66 status_n = Vend (file_id); 67 status_32 = Hclose (file_id); 68 return 0; 69 } View Code將Dll文件拷貝到Debug目錄下,運(yùn)行,發(fā)現(xiàn)目錄下生成了General_Vdatas.hdf文件。在Matlab中查看:
轉(zhuǎn)載于:https://www.cnblogs.com/yhlx125/p/4447229.html
總結(jié)
以上是生活随笔為你收集整理的[HDF]hdf-4.2.6类库的使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【Android开发】图形图像处理技术-
- 下一篇: 这些你都了解么------程序员跳槽法则