Re: shell code+ nearest point question [message #80469] |
Thu, 14 June 2012 13:30 |
anil
Messages: 34 Registered: August 2009
|
Member |
|
|
On Jun 14, 4:56 pm, Mats Löfdahl <mats.lofd...@gmail.com> wrote:
> Den torsdagen den 14:e juni 2012 kl. 15:18:43 UTC+2 skrev anil:
>
>
>
>
>
>
>
>
>
>> Hi
>> I do have a single data file namely 'lonlat.dat' , which contains
>> longitude,latitude and filename data, like:
>> ( longitude latitude filename)
>> 30.4000 42.2900 2002252.s04d1pfv50-sst.hdf
>> 30.5300 42.3300 2002260.s04d1pfv50-sst.hdf
>> and so on... I do have some hdf files which are named just like in
>> column 3 of this lonlat.dat file.
>
>> What i want to do is to open every file listed in this 3rd column. and
>> for this file, i want to find the closest /nearest point to my
>> longitude and latitude (column1&2) and read the corresponding value of
>> my desired variable(sst, sea surface temperature for this case.) I can
>> read hdf data files like this :
>
>> files=findfile('*.hdf',count=numfiles)
>> for k=0,numfiles-1 do begin
>> file=hdf_sd_start(files(k))
>
>> indexa=hdf_sd_nametoindex(file,'lon')
>> indexb=hdf_sd_nametoindex(file,'lat')
>> indexc=hdf_sd_nametoindex(file,'sst')
>> varida=hdf_sd_select(file,indexa)
>> varidb=hdf_sd_select(file,indexb)
>> varidc=hdf_sd_select(file,indexc)
>
>> hdf_sd_getdata,varida,loni
>> hdf_sd_getdata,varidb,lati
>> hdf_sd_getdata,varidc,ssti
>> hdf_sd_endaccess,varida
>> hdf_sd_endaccess,varidb
>> hdf_sd_endaccess,varidc
>> hdf_sd_end,file
>> endfor
>
>> I could not read the 'lonlat.dat' file into idl as variables, so i
>> wanted to write a short shell script to read in this 'lonlat.dat' file
>> and run idl within this script. below is this script. it may be wrong,
>> but here is what i do. i just could not figure out, how to read these
>> variables into IDL. I have to read in the 3rd column and assign it as
>> the filenames of the files to be opened and read. 1st and 2nd columns
>> as the desired longitudes and latitudes.
>
>> while read line
>> do
>> lon=`echo $line |awk '{print $1}'`
>> lat=`echo $line |awk '{print $2}'`
>> filename=`echo $line |awk '{print $3}'`
>
>> echo $lon $lat $filename
>> idl <<EOF
>> .r nearest.pro $filename $lon $lat
>> exit
>> EOF
>> done <lonlat.dat
>
>> So i should somehow read this $filename into idl and use it to read
>> the files.
>> And use the $lon and $lat to find the closest point to them within
>> that hdf file and read the corresponding sst.
>
>> My 2nd question is how to find the closest point to my lat and lon?
>
>> I hope it is clear. need help ,urgently
>
> Here is a useful routine for reading tabulated data from a text file:http://www.astro.washington.edu/docs/idl/cgi-bin/getpro /library32.htm...
>
> With lonlat.data containing the two lines of data you posted, you can do this:
>
> IDL> data=rd_tfile('lonlat.dat',/auto)
> IDL> print,data
> 30.4000 42.2900 2002252.s04d1pfv50-sst.hdf
> 30.5300 42.3300 2002260.s04d1pfv50-sst.hdf
> IDL> help,data
> DATA STRING = Array[3, 2]
>
> The longitudes and latitudes are then available as float(data[0:1,*]) and the file names as data[2,*].
Thank you.It seems useful but did not work on my computer :( .
|
|
|
Re: shell code+ nearest point question [message #80473 is a reply to message #80469] |
Thu, 14 June 2012 06:56  |
Mats Löfdahl
Messages: 263 Registered: January 2012
|
Senior Member |
|
|
Den torsdagen den 14:e juni 2012 kl. 15:18:43 UTC+2 skrev anil:
> Hi
> I do have a single data file namely 'lonlat.dat' , which contains
> longitude,latitude and filename data, like:
> ( longitude latitude filename)
> 30.4000 42.2900 2002252.s04d1pfv50-sst.hdf
> 30.5300 42.3300 2002260.s04d1pfv50-sst.hdf
> and so on... I do have some hdf files which are named just like in
> column 3 of this lonlat.dat file.
>
> What i want to do is to open every file listed in this 3rd column. and
> for this file, i want to find the closest /nearest point to my
> longitude and latitude (column1&2) and read the corresponding value of
> my desired variable(sst, sea surface temperature for this case.) I can
> read hdf data files like this :
>
> files=findfile('*.hdf',count=numfiles)
> for k=0,numfiles-1 do begin
> file=hdf_sd_start(files(k))
>
> indexa=hdf_sd_nametoindex(file,'lon')
> indexb=hdf_sd_nametoindex(file,'lat')
> indexc=hdf_sd_nametoindex(file,'sst')
> varida=hdf_sd_select(file,indexa)
> varidb=hdf_sd_select(file,indexb)
> varidc=hdf_sd_select(file,indexc)
>
> hdf_sd_getdata,varida,loni
> hdf_sd_getdata,varidb,lati
> hdf_sd_getdata,varidc,ssti
> hdf_sd_endaccess,varida
> hdf_sd_endaccess,varidb
> hdf_sd_endaccess,varidc
> hdf_sd_end,file
> endfor
>
> I could not read the 'lonlat.dat' file into idl as variables, so i
> wanted to write a short shell script to read in this 'lonlat.dat' file
> and run idl within this script. below is this script. it may be wrong,
> but here is what i do. i just could not figure out, how to read these
> variables into IDL. I have to read in the 3rd column and assign it as
> the filenames of the files to be opened and read. 1st and 2nd columns
> as the desired longitudes and latitudes.
>
> while read line
> do
> lon=`echo $line |awk '{print $1}'`
> lat=`echo $line |awk '{print $2}'`
> filename=`echo $line |awk '{print $3}'`
>
> echo $lon $lat $filename
> idl <<EOF
> .r nearest.pro $filename $lon $lat
> exit
> EOF
> done <lonlat.dat
>
> So i should somehow read this $filename into idl and use it to read
> the files.
> And use the $lon and $lat to find the closest point to them within
> that hdf file and read the corresponding sst.
>
> My 2nd question is how to find the closest point to my lat and lon?
>
>
> I hope it is clear. need help ,urgently
Here is a useful routine for reading tabulated data from a text file: http://www.astro.washington.edu/docs/idl/cgi-bin/getpro/libr ary32.html?RD_TFILE
With lonlat.data containing the two lines of data you posted, you can do this:
IDL> data=rd_tfile('lonlat.dat',/auto)
IDL> print,data
30.4000 42.2900 2002252.s04d1pfv50-sst.hdf
30.5300 42.3300 2002260.s04d1pfv50-sst.hdf
IDL> help,data
DATA STRING = Array[3, 2]
The longitudes and latitudes are then available as float(data[0:1,*]) and the file names as data[2,*].
|
|
|