/*** this code is to generate various hdf files to test h4toh5 converter and h4toh5 lib API. The code itself is NOT optimizied but try to consider various cases that examine how converter works. */ #include "hdf.h" #include "mfhdf.h" #include #define FILESDS1 "sds_typ_test.hdf" #define FILESDS2 "sds_dim_test.hdf" #define FILESDS3 "sds_attr_test.hdf" #define FILEGR "gr_typ_test.hdf" #define FILERAS8 "ras_8_test.hdf" #define FILERAS24 "ras_24_test.hdf" #define FILEGRPAL "image_attr_test.hdf" #define FILEVD "vdata_test.hdf" #define FILECLASHVG "vgnameclash_test.hdf" #define FILECLASHSDS "sdsnameclash_test.hdf" #define FILECLASHVD "vdnameclash_test.hdf" #define FILECLASHGR "grnameclash_test.hdf" #define FILELOOP "vg_loop_test.hdf" #define FILEHL "vg_hl_test.hdf" #define FILEVG "vg_all_test.hdf" #define FILEANNO "anno_test.hdf" /* for testing sds*/ #define TYP_RANK 3 #define TYP_DIMSIZE 4 #define INT8_UPLIMIT 0x7E #define UINT8_UPLIMIT 0xFC #define INT16_UPLIMIT 0x7FFE #define UINT16_UPLIMIT 0xFFFC #define INT32_UPLIMIT 0x7FFFFFFE #define UINT32_UPLIMIT 0xFFFFFFFC #define ATT_SIZE 10 /* for testing image*/ #define X_LENGTH 10 #define Y_LENGTH 5 #define NUM_COLORS 256 #define F_ATT1_NAME "File Attribute" #define RI_ATT1_NAME "Image Attribute" #define F_ATT1_VAL "Contents of First FILE Attribute" #define F_ATT1_N_VALUES 32 #define RI_ATT1_VAL "Contents of IMAGE's First Attribute" #define RI_ATT1_N_VALUES 35 /* for testing vdata*/ #define NRECORDS 10 #define FIELD_1 "Temp" #define FIELD_2 "Height" #define FIELD_3 "Speed" #define FIELD_4 "Ident" #define FIELD_5 "Position" #define FIELD_NAMES "Temp,Height,Speed,Ident,Position" #define FIELD_VDNAMES "Temp,Height" /*for testing vgroup*/ #define VGATTR_NAME "Vgroup attribute 1" int test_sdstyp(void); int test_sdsdim(void); int test_sdsattr(void); int test_grtyp(void); int test_ras8(void); int test_ras24(void); int test_imageattr(void); int test_vdata(void); int test_vgnameclash(void); int test_sdsnameclash(void); int test_grnameclash(void); int test_vdnameclash(void); int test_vgloop(void); int test_vghl(void); int test_vgall(void); int test_anno(void); int main(void) { if(test_sdstyp()== FAIL) { printf("failed to create sds_typ_test.hdf file.\n"); return FAIL; } if(test_sdsdim()== FAIL) { printf("failed to create sds_dim_test.hdf file. \n"); return FAIL; } if(test_sdsattr()== FAIL) { printf("failed to create sds_attr_test.hdf file. \n"); return FAIL; } if(test_grtyp()==FAIL) { printf("failed to create gr_typ_test.hdf file. \n"); return FAIL; } if(test_ras8()==FAIL) { printf("failed to create ras8_test.hdf file.\n"); return FAIL; } if(test_ras24()==FAIL) { printf("failed to create ras24_test.hdf file.\n"); return FAIL; } if(test_imageattr()== FAIL) { printf("failed to create image_attr_test.hdf file.\n"); return FAIL; } if(test_vdata()== FAIL) { printf("failed to create vdata_test.hdf file.\n"); return FAIL; } if(test_vgnameclash()==FAIL) { printf("failed to create vg_nameclash.hdf file.\n"); return FAIL; } if(test_sdsnameclash()==FAIL) { printf("failed to create sds_nameclash.hdf file.\n"); return FAIL; } if(test_grnameclash()==FAIL) { printf("failed to create gr_nameclash.hdf file. \n"); return FAIL; } if(test_vdnameclash()==FAIL) { printf("failed to create vd_nameclash.hdf file.\n"); return FAIL; } if(test_vgloop()==FAIL) { printf("failed to create vg_loop.hdf file. \n"); return FAIL; } if(test_vghl()==FAIL) { printf("failed to create vg_hl.hdf file. \n"); return FAIL; } if(test_vgall()==FAIL) { printf("failed to create vg_all.hdf file. \n"); return FAIL; } if(test_anno()==FAIL) { printf("failed to create vg_anno.hdf file. \n"); return FAIL; } return 0; } /* this subroutine will hdf file with typical sds objects, The rank is TYP_RANK, each dimensional size is TYP_DIMSIZE. Datatype we are testing is: char, int8, int16, int32, uint16, uint32, lint16, lint32, luint32, float32, float64, */ int test_sdstyp(){ int32 file_id,sds_id; int32 i,j,k; int32 typ_start[TYP_RANK],typ_edges[TYP_RANK],typ_stride[TYP_RANK]; char8 typchar_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE]; int8 typint8_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE]; int16 typint16_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE]; int32 typint32_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE]; uint16 typuint16_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE]; int32 typlint32_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE]; uint32 typluint32_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE]; float32 typfloat32_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE]; float64 typfloat64_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE]; float64 typlfloat64_array[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE]; int32 typ_dims[TYP_RANK]; int32 CUB_SIZE; int istat; /* TYPICAL sds array, we limit the dimensional size for testing purpose. */ CUB_SIZE = (TYP_DIMSIZE-1)*(TYP_DIMSIZE-1)*(TYP_DIMSIZE-1); /* 1. data type is char */ for (i=0;ivb and vb->va */ int test_vgloop() { int32 file_id, vgroupa_ref, vgroupa_id, vgroupb_ref,vgroupb_id; int32 istat,dims[TYP_RANK]; int i,j,k; /*2. for sds */ int32 sd_id,sds_id; int32 sds_ref; int32 array_data[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE]; int32 start[TYP_RANK],edges[TYP_RANK],stride[TYP_RANK]; for (i=0;igc ga | / \ | gd gb | / -ge This file includes vdata,image and sds. 1) GROUP MEMBERS ga: name groupA: groupB and one Image gb: name groupB: one SDS gc: name groupA: groupD gd: name groupD: groupE one SDS and one Image ge: name groupE: groupC(named groupA) 2) Independent Vdata,SDS, images SDS: sds2 (the same name as another SDS) Image: Image_1 Vdata: Example Vdata */ int test_vgall() { typedef struct { float32 temp; int16 height; float32 speed; char ident; float32 position[2]; } source_t; source_t source[NRECORDS]; int32 file_id, vgroupa_ref, vgroupa_id,istat; int32 vgroupc_ref, vgroupc_id,vgroupb_ref,vgroupb_id; int32 vgroupd_ref, vgroupd_id,vgroupe_ref,vgroupe_id; int32 vdata_id,values[4]={32, 16, 32, 8}; intn i, j,k; uint8 *databuf, *pntr; int bufsize, recsize; VOIDP fldbufpt[5]; /*2. for sds */ int32 sd_id,sds_id,dim_id; int32 sds_ref; int32 fill_value; int32 array_data[TYP_DIMSIZE][TYP_DIMSIZE][TYP_DIMSIZE]; int32 dim_sca0[TYP_DIMSIZE],dim_sca1[TYP_DIMSIZE]; int32 dim_sca2[TYP_DIMSIZE]; int32 dim_sizes[TYP_RANK]; int32 start[TYP_RANK],edges[TYP_RANK],stride[TYP_RANK]; float64 cal; float64 cal_err; float64 offset; float64 offset_err; /*3. for image. */ int32 gr_id, ri_id, il,pal_id; int32 image_ncomp,image_data_type; int32 image_start[2], image_edges[2],image_dims[2]; int16 image_data[Y_LENGTH][X_LENGTH][3]; uint8 palette_data[NUM_COLORS*3]; int32 image_num_comp; int32 image_num_entries; int32 image_ref; char* attr_value; /*4. for annotation. */ int32 an_id,ann_id; int32 group_tag,group_ref; static char file_label[] = "This is a file label."; static char file_desc[] = "This is a file description."; static char data_label[] = "This is a data label."; static char data_desc[] = "This is a data description."; char label[] = "sds.label"; char unit[] = "sds.unit"; char format[] = "sds.format"; char coordsys[] = "sds.coord"; char dim_name0[] ="dim0"; char dim_name1[] ="dim1"; char dim_name2[] ="dim2"; char dim_label[] ="dim.label"; char dim_unit[] ="dim.unit"; char dim_format[] ="dim.format"; /**** initial setting. ****/ cal = 1.0; cal_err = 0.0; offset = 0.0; offset_err = 0.0; fill_value = 999; attr_value = malloc(ATT_SIZE*sizeof(char)); if(attr_value == NULL) { printf("fail to allocate memory.\n"); return FAIL; } strcpy(attr_value,"test attr"); for (i=0;i