Because you are using the same loop variable (i)
in two different loops, one of which happens to be inside the other...
xiao wrote:
> Hi~ everyone, I have a short program like this. But there are some
> bugs in it that I cannot open all the files in the loop. Anyone got an
> idea why is that? Thank you very much :)
>
> pro read_rams,fulnam,vname,nvars,data,kx,ky,kz
>
> vname =['UP','VP','WP','THETA']
> hh=
> ['00','01','02','03','04','05','06','07','08','09','10','11' ,'12','13','14','15','16','17','18','19','20','21','22','23' ]
> mm=['00','15','30','45']
> ss='00'
>
> ; timestep
>
> nvars=4 ; number of varible
>
> dirnm='test8/anal/' ;/* print to string 'dirnm' */
> filehd='a-A-A-2005-12-'
> filend='-g4.h5'
>
> for j=0,23 do begin ; ---------------This loop this loop works
> here, all the file names are correct :(
> for k=0,3 do begin ; ---------------This loop this loop works
> here, all the file names are correct :(
>
> fulnam=dirnm+filehd+'17-'+hh(j)+mm(k)+ss+filend
>
> openw,3,'data.txt'
>
> file_id = H5F_open(fulnam)
>
> if file_id ge 0 then begin
> for iv=0, nvars-1 do begin
>
>
> dataset_id = H5D_open(file_id, vname(iv)) ;/* Open existing
> dataset. but only opend one file*/
> print,file_id
> rdata = H5D_read(dataset_id)
> dataspace_id = H5D_GET_SPACE(dataset_id)
> dimensions = H5S_GET_SIMPLE_EXTENT_DIMS(dataspace_id)
> simspc = H5S_IS_SIMPLE(Dataspace_id)
>
> if iv eq 0 then begin
> kz=dimensions(0)
> ky=dimensions(1)
> kx=dimensions(2)
> data=fltarr(kx,ky,kz,nvars)
>
> endif
>
> ntot=long(kx)*ky*kz
> a=fltarr(ntot) ;introduce "a" to redistribute the data
> a(*)=rdata
>
> ii=-1L
> for k=0,kz-1 do begin
> for j=0,ky-1 do begin
> for i=0,kx-1 do begin
> ii=ii+1
> data(i,j,k,iv)=a(ii)
> endfor
> endfor
> endfor
> print,'pocessing varible is ',vname(iv)
> printf,3,data
>
> H5S_CLOSE, dataspace_id
> H5D_close,dataset_id ;/* Close the dataset. */
> endfor
> H5F_close,file_id ;/* Close the file. */
> endif
> print,'finishing process file ',fulnam
>
> endfor ; ---------------This loop does not work, only processed
> the first file :(
> endfor ; ---------------This loop does not work, only processed
> the first file :(
>
> close,3
> a=0.
> end
|