HDF를 생성하는 코드를 작성하고 있으며 특성에 문제가 있습니다. 이러한 속성은 텍스트 파일에서 읽는 모든 가변 길이 문자열이지만 256자를 꽤 많이 사용합니다.HDF5 특성 : 문자열은 한 문자 만입니다.
내 코드가 컴파일되지 않고 오류없이 실행됩니다. HDFView에서 파일을 열 때 속성의 이름은 모두 정확하지만 문자열의 첫 번째 문자 만 표시됩니다.
단일 문자열 또는 문자열 배열로 속성을 허용하도록 코드를 작성하기 시작했습니다. 나는 그 부분을 끝내지 않았기 때문에 문자열 배열에 대해서는 아무 것도하지 않습니다. 여기
는 입력 파일입니다year 2013
julian_date 23
start_time_utc 13:54:03
end_time_utc 14:32:05
pixels_per_degree 1000
latitude_corners 34.988644 35.503284 35.960529 36.364529
longitude_corners -119.571877 -118.467979 -120.158424 -119.004395
을 그리고 여기에 코드입니다 : 여기, 마지막으로
Making top level attributes...
Making single attribute: year: 2013
Making single attribute: julian_date: 23
Making single attribute: start_time_utc: 13:54:03
Making single attribute: end_time_utc: 14:32:05
Making single attribute: pixels_per_degree: 1000
Making array of 4 attributes with name latitude_corners:
0: 34.988644
1: 35.503284
2: 35.960529
3: 36.364529
Making array of 4 attributes with name longitude_corners:
0: -119.571877
1: -118.467979
2: -120.158424
3: -119.004395
Finished making top level attributes.
: 여기
#define FIELDSTRINGLENGTH 256
/*...*/
while(fgets(line, ATTRSTRINGLENGTH, topattributefile)!=NULL) {
//parse line into individual words
field=strtok(line," \n");
strncpy(attributename, field, FIELDSTRINGLENGTH);
numfields=0;
field=strtok(NULL," \n");
while(field!=NULL) {
strncpy(attributevalue[numfields++], field, FIELDSTRINGLENGTH);
field=strtok(NULL," \n");
}
if(numfields==0) {printf("ERROR: Attribute %s had no value; skipping\n", attributename);}
else if(numfields>1) {
if(verboseflag) {printf("Making array of %d attributes with name %s:\n",
numfields, attributename);}
for(i=0;i<numfields;i++) {
if(verboseflag) {printf("\t%d: %s\n", i, attributevalue[i]);}
}
}
else {
printf("Making single attribute: %s: %s\n",
attributename, attributevalue[0]);}
//make single attribute
attrdataspaceid = H5Screate(H5S_SCALAR);
attrdatatypeid = H5Tcopy(H5T_C_S1);
status = H5Tset_size(attrdatatypeid, FIELDSTRINGLENGTH);
status = H5Tset_strpad(attrdatatypeid, H5T_STR_NULLTERM);
attributeid = H5Acreate2(fileid, attributename, attrdatatypeid, attrdataspaceid, H5P_DEFAULT, H5P_DEFAULT);
status = H5Awrite(attributeid, H5T_C_S1, attributevalue[0]);
}
}
은 관련 조각의 표준 출력이다 HDFView에서 읽은 HDF의 메타 데이터입니다.
XXXX.XXXXXX.XXXXXX.hdf (0)
Group size = 1
Number of attributes = 5
year = 2
julian_date = 2
start_time_utc = 1
end_time_utc = 1
pixels_per_degree = 1
여기에 이상한 점이 있습니까?
문제를 요청한 공간이 아닌가요? 'attrdataspaceid = H5Screate (H5S_SCALAR); '이 줄을 뜻합니다. 나는 그것이'H5T_C_S1'이어야한다고 생각한다. 확실하지. – Mathias711