IF KEYWORD_SET(MaxColumn) THEN BEGIN IF (MaxColumn LT 1) Then begin message, 'MaxColumn Must be the positve Integer number.' end MaxCoL=MaxColumn ENDIF else begin MaxCoL=20;最大列默认为20列 END ;----------------------------------------- File="D:\Desktop\drought_characteristic\2022_output\file\1111.txt" FTresult = FILE_TEST(File) if (FTresult NE 1) then begin message, 'File Not Found!' endif ;----------------------------------------- ;初始化数据 Data=make_array(1,1,/DOUBLE);文件中没有数据时就返回此值 ;----------------------------------------- fs=fileread(file) ;----------------------------------------- ;最多MaxCoL列nn行 if (n_elements(fs) GT 0) then begin ;----------------------------------------- FileData=make_array(MaxCoL,n_elements(fs),/DOUBLE) LineCount=make_array(1,n_elements(fs),/UINT) ;=========================================================== for n=0L,n_elements(fs)-1 DO BEGIN LineStr=fs[n]; rbool=StringToDoubleArray(LineStr,DoubleArray,Count); ;----------------------------------------- if ((rbool eq 1) && (Count GT 0))then begin MinColSet=make_array(2,1,/DOUBLE) MinColSet[0]=MaxCoL; MinColSet[1]=Count; ;----------------------------------------- for LC=0L,min(MinColSet)-1 Do begin FileData[LC,n]=DoubleArray[LC]; endfor ;----------------------------------------- LineCount[n]=min(MinColSet) endif ;----------------------------------------- endfor ;=========================================================== validrow=where(LineCount GT 0) ;----------------------------------------- if (max(LineCount) GT 1)AND(n_elements(validrow) GT 1) then begin Data=FileData[0:(max(LineCount)-1),validrow]; endif ;----------------------------------------- endif将这段代码的功能改成转换为字符串数组
时间: 2023-06-26 18:03:11 浏览: 104
C#使用Aspose.Cells控件读取Excel
可以按照以下方式修改代码,将数据转换为字符串数组:
```
IF KEYWORD_SET(MaxColumn) THEN BEGIN
IF (MaxColumn LT 1) Then begin
message, 'MaxColumn Must be the positve Integer number.'
end
MaxCoL=MaxColumn
ENDIF else begin
MaxCoL=20;最大列默认为20列
END
;-----------------------------------------
File="D:\Desktop\drought_characteristic\2022_output\file\1111.txt"
FTresult = FILE_TEST(File)
if (FTresult NE 1) then begin
message, 'File Not Found!'
endif
;-----------------------------------------
;初始化数据
DataStr=make_array(1,1,/STRING) ; 文件中没有数据时就返回此值
;-----------------------------------------
fs=fileread(file)
;-----------------------------------------
;最多MaxCoL列nn行
if (n_elements(fs) GT 0) then begin
;-----------------------------------------
FileData=make_array(MaxCoL,n_elements(fs),/DOUBLE)
LineCount=make_array(1,n_elements(fs),/UINT)
;===========================================================
for n=0L,n_elements(fs)-1 DO BEGIN
LineStr=fs[n]
rbool=StringToDoubleArray(LineStr,DoubleArray,Count)
;-----------------------------------------
if ((rbool eq 1) && (Count GT 0))then begin
MinColSet=make_array(2,1,/DOUBLE)
MinColSet[0]=MaxCoL
MinColSet[1]=Count
;-----------------------------------------
for LC=0L,min(MinColSet)-1 Do begin
FileData[LC,n]=DoubleArray[LC]
endfor
;-----------------------------------------
LineCount[n]=min(MinColSet)
endif
;-----------------------------------------
endfor
;===========================================================
validrow=where(LineCount GT 0)
;-----------------------------------------
if (max(LineCount) GT 1)AND(n_elements(validrow) GT 1) then begin
Data=FileData[0:(max(LineCount)-1),validrow]
;-----------------------------------------
nRows = n_elements(validrow)
nCols = max(LineCount)
DataStr = strarr(nCols, nRows)
for i=0L, nRows-1 do begin
for j=0L, nCols-1 do begin
DataStr[j,i] = string(FileData[j,validrow[i]])
endfor
endfor
;-----------------------------------------
endif
;-----------------------------------------
endif
```
阅读全文