comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » How to pass NCDF files name to text files names?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
How to pass NCDF files name to text files names? [message #72660] Wed, 29 September 2010 05:05 Go to next message
d.poreh is currently offline  d.poreh
Messages: 406
Registered: October 2007
Senior Member
Folks
I am reading some NCDF files like this:
pathName="d:\p\"
List = findfile(pathName+"*.nc")
nosFiles=N_ELEMENTS(List)
data = ptrarr(nosFiles)
for i = 0, nosFiles - 1 do begin
ncid = NCDF_OPEN(list[i])
NCDF_VARGET, ncid, 0, lon
NCDF_VARGET, ncid, 1, lat
NCDF_VARGET, ncid, 2, concentration
NCDF_CLOSE, ncid ; Close the NetCDF file
*Here I need to save all of my files (in text format) in arrays with 3
columns and with name of NCDF file that I am reading (for instance:
L3b_20070716.txt, L3b_20070717 and so on)*
Endfor
In another word I need to pass my NCDF files name to text files names.
I don’t know how. Will you please help me?
Cheers,
Dave
Re: How to pass NCDF files name to text files names? [message #72745 is a reply to message #72660] Thu, 30 September 2010 06:36 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Cameron Homeyer writes:

> I do this often and it is pretty easy to accomplish using STRING
> operators. You can use something like this for the code above:
>
> txt_list = STRARR(nosFiles)
>
> FOR i = 0, nosFiles -1 DO $
> txt_list[i] = STRMID(list[i], STRLEN(pathName), STRLEN(list[i]) - $
> STRLEN(pathName) - 2) + 'txt'
>
> Keep in mind, these do not have path names on them, but you can add
> those in the OPENW.

Oh, I see what he was talking about. I usually do this with
FSC_Base_Filename like this:

outputFiles = StrArr(nosFiles)
FOR j=0,nosFiles-1 DO BEGIN
rootname = FSC_Base_Filename(list[i])
outputFiles[j] = Filepath(ROOT_DIR=outputDir, rootname + '.txt')
ENDFOR

You can find FSC_Base_Filename here.

http://www.dfanning.com/programs/fsc_base_filename.pro

You could also use the IDL routine FILE_BASENAME in this case.

rootname = File_Basename(list[i], '.nc')

I just find the features of FSC_Base_Filename more amenable to
what I am trying to do, usually.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to pass NCDF files name to text files names? [message #72746 is a reply to message #72660] Thu, 30 September 2010 06:06 Go to previous message
Cameron Homeyer is currently offline  Cameron Homeyer
Messages: 1
Registered: September 2010
Junior Member
In article
<eed8d361-81dc-4c81-926f-23e78bd74d6f@28g2000yqm.googlegroups.com>,
Dave Poreh <d.poreh@gmail.com> wrote:

> Folks
> I am reading some NCDF files like this:
> pathName="d:\p\"
> List = findfile(pathName+"*.nc")
> nosFiles=N_ELEMENTS(List)
> data = ptrarr(nosFiles)
> for i = 0, nosFiles - 1 do begin
> ncid = NCDF_OPEN(list[i])
> NCDF_VARGET, ncid, 0, lon
> NCDF_VARGET, ncid, 1, lat
> NCDF_VARGET, ncid, 2, concentration
> NCDF_CLOSE, ncid ; Close the NetCDF file
> *Here I need to save all of my files (in text format) in arrays with 3
> columns and with name of NCDF file that I am reading (for instance:
> L3b_20070716.txt, L3b_20070717 and so on)*
> Endfor
> In another word I need to pass my NCDF files name to text files names.
> I don�t know how. Will you please help me?
> Cheers,
> Dave

I do this often and it is pretty easy to accomplish using STRING
operators. You can use something like this for the code above:

txt_list = STRARR(nosFiles)

FOR i = 0, nosFiles -1 DO $
txt_list[i] = STRMID(list[i], STRLEN(pathName), STRLEN(list[i]) - $
STRLEN(pathName) - 2) + 'txt'

Keep in mind, these do not have path names on them, but you can add
those in the OPENW.

Cheers,
Cameron
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Coyote Facts
Next Topic: Accelerating a one-line program doing matrix multiplication

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:14:06 PDT 2025

Total time taken to generate the page: 0.00767 seconds