Hello Markus,
I modified your code as follows:-
;==================================
file='downloads\ps_200605.txt'
n_lines =file_lines(file)
lines=strarr(n_lines)
openr, lun, file,/get_lun
readf, lun, lines
free_lun, lun
var_k=['xlon','xlat','Ps']
posi=lonarr(3)
for i=0L, n_elements(Var_k) - 1L do begin
semicolon = where(stregex(lines,'.* *; *',/boolean)) ; this command is correct
posi[i] = where(stregex(lines,' *'+var_k[i]+' *= *',/boolean))
endfor
n_semicolon=n_elements(semicolon)
Inv_Ind_semicolom= (n_semicolon-1)-Indgen(n_semicolon)
print, posi[0]+1, semicolon[Inv_Ind_semicolom[2]]
print, posi[1]+1, semicolon[Inv_Ind_semicolom[1]]
print, posi[2]+1, semicolon[Inv_Ind_semicolom[0]]
xlon = extract_value(lines, posi[0]+1, semicolon[Inv_Ind_semicolom[2]])
xlat = extract_value(lines, posi[1]+1, semicolon[Inv_Ind_semicolom[1]])
ps = extract_value(lines, posi[2]+1, semicolon[Inv_Ind_semicolom[0]])
print, xlon.val
print, xlat.val
print, ps.val
end
function extract_value, lines, start, ends
val = strsplit(lines[start:ends],' ,;',/extract)
val = val.map('float')
dims = Image_Dimensions(Val, XSize=XSize, YSize=YSize, TrueIndex=trueindex)
return, val.reduce(lambda('x,y:[x,y]'))
end
;====================
I still have some errors in my code such as.
STRTOK: Expression must be a scalar or 1 element array in this context: STRINGIN. related to Xlon, xlat, and Ps
what means val.map('float') in the subroutine.
In addition, I need an alternative statements of reduce(lambda('x,y:[x,y]')).
Best regards
Khaled