Re: Why this loop does not work? [message #63828] |
Thu, 20 November 2008 14:34 |
xiao zhang
Messages: 81 Registered: June 2008
|
Member |
|
|
On Nov 20, 3:50 pm, Vince Hradil <vincehra...@gmail.com> wrote:
> On Nov 20, 3:30 pm, xiao <littledd...@gmail.com> wrote:
>
>
>
>> On Nov 20, 2:55 pm, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>>> On Nov 20, 3:45 pm, Paolo <pgri...@gmail.com> wrote:
>
>>>> 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
>
>>> Actually, i is fine, it's j and k that duplicated. :-)=
>
>> I changed the j,k to a,b at the beginning but it still does not
>> work.And the error changed to :
>
>> H5F_OPEN: Expression must be a scalar or 1 element array in this
>> context: FULNAM.
>> % Execution halted at: READ_RAMS 34 /nas/rstor6/xzhang/
>> read_rams.pro
>> % $MAIN$
>> :(
>
> You use a later on in the code, too... a=fltarr()
THANKS ALL ~ IT WORKS NOW~~ :)
|
|
|
Re: Why this loop does not work? [message #63831 is a reply to message #63828] |
Thu, 20 November 2008 13:50  |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Nov 20, 3:30 pm, xiao <littledd...@gmail.com> wrote:
> On Nov 20, 2:55 pm, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>
>
>> On Nov 20, 3:45 pm, Paolo <pgri...@gmail.com> wrote:
>
>>> 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
>
>> Actually, i is fine, it's j and k that duplicated. :-)=
>
> I changed the j,k to a,b at the beginning but it still does not
> work.And the error changed to :
>
> H5F_OPEN: Expression must be a scalar or 1 element array in this
> context: FULNAM.
> % Execution halted at: READ_RAMS 34 /nas/rstor6/xzhang/
> read_rams.pro
> % $MAIN$
> :(
You use a later on in the code, too... a=fltarr()
|
|
|
Re: Why this loop does not work? [message #63832 is a reply to message #63831] |
Thu, 20 November 2008 13:46  |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
Because you are giving an array to something that want a scalar...
You know, actually *reading* the error message may be useful...
Paolo
xiao wrote:
> On Nov 20, 2:55�pm, Jeremy Bailin <astroco...@gmail.com> wrote:
>> On Nov 20, 3:45�pm, Paolo <pgri...@gmail.com> wrote:
>>
>>
>>
>>> 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
>>
>> Actually, i is fine, it's j and k that duplicated. :-)=
>
> I changed the j,k to a,b at the beginning but it still does not
> work.And the error changed to :
>
> H5F_OPEN: Expression must be a scalar or 1 element array in this
> context: FULNAM.
> % Execution halted at: READ_RAMS 34 /nas/rstor6/xzhang/
> read_rams.pro
> % $MAIN$
> :(
|
|
|
Re: Why this loop does not work? [message #63833 is a reply to message #63832] |
Thu, 20 November 2008 13:30  |
xiao zhang
Messages: 81 Registered: June 2008
|
Member |
|
|
On Nov 20, 2:55 pm, Jeremy Bailin <astroco...@gmail.com> wrote:
> On Nov 20, 3:45 pm, Paolo <pgri...@gmail.com> wrote:
>
>
>
>> 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
>
> Actually, i is fine, it's j and k that duplicated. :-)=
I changed the j,k to a,b at the beginning but it still does not
work.And the error changed to :
H5F_OPEN: Expression must be a scalar or 1 element array in this
context: FULNAM.
% Execution halted at: READ_RAMS 34 /nas/rstor6/xzhang/
read_rams.pro
% $MAIN$
:(
|
|
|
Re: Why this loop does not work? [message #63834 is a reply to message #63833] |
Thu, 20 November 2008 12:55  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Nov 20, 3:45 pm, Paolo <pgri...@gmail.com> wrote:
> 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
>
>
Actually, i is fine, it's j and k that duplicated. :-)=
|
|
|
Re: Why this loop does not work? [message #63836 is a reply to message #63834] |
Thu, 20 November 2008 12:45  |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
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
|
|
|