Re: asciiread

From: Mateus Teixeira <mateus.teixeira_at_nyahnyahspammersnyahnyah>
Date: Mon, 29 Jun 2009 19:20:39 -0300

Dear Hong,

You can use sprinti function, like the following line

fileNameString = "MOD_Terra_AODv401_2007"+sprinti("%0.3i",n)
g1 = asciiread( "/usr/rmt_share/scratch79/jam/MODIS_aerosol/2007/" +
fileNameString, -1, "float" )

The code %0.3i in sprinti function create string with 3 numbers and with
leading zeros, like 001 ... 010 ... 099 100 ...
I only split your original line in two to enter in this email.

I hope that it helps you.

Best regards

Mateus

2009/6/29 jam hong <cumarporn_at_hotmail.com>

> Dear Mary
> I want to use asciiread to read many files.
> I used the do loop to change the file name but I think I did not get the
> format right.
> What is the format when I want to change the file name following n (which
> is numbers from 101 - 365)
>
> My code is
> begin
> ; Create variables to contain data.
> i = 0
> j = 1
> do i = 1,265
> n = 101
> g1 =
> asciiread("/usr/rmt_share/scratch79/jam/MODIS_aerosol/2007/MOD_Terra_AODv401_2007"
> + n", -1,"float")
> n11 = dimsizes(g1)
> print(g1)
> v1 = new(256,float)
> j = 0
> do k = 0, n11-1
> if g1(k) .eq. 310550052
> v1(i) = g1(k+2)
> else
> v1(i) = -999
> end if
> end do
> n = n + 1
> end do
> print(v1)
> end
> Thanks
> Jam
> > Date: Mon, 29 Jun 2009 07:49:02 -0600
> > From: haley_at_ucar.edu
> > To: ncl-talk_at_ucar.edu
> > Subject: Re: Order of function load matters ??
> >
> >
> > Dave B will need to weig h in here, but I wanted to say that with
> > python, the functions can be listed in any order, but they have to be
> > listed before any main code that references them.
> >
> > Here's an example:
> >
> > def two(y):
> > y2 = one(y) + 2
> > return y2
> >
> > def one(x):
> > x2 = x + 1
> > return x2
> >
> > z = 5
> > z2 = one(z) + two(z)
> > print z2
> >
> > Note that function "two" (defined first) references function "one",
> > but python doesn't complain about this. If you moved function "one"
> > and/or "two" after the main code, it would complain.
> >
> > So, yes, it would be nice if you could do something similar in NCL and
> > not have to worry about function ordering. I don't know what the
> > expense would be for speed however. Arindam makes a good point on
> > this.
> >
> >
> > --Mary
> >
> >
> > On Sun, 28 Jun 2009, Arinda m Chakraborty wrote:
> >
> > > Hello All,
> > > probably 'load' of NCL defines all the functions in memory including
> their
> > > dependencies and therefore the functions being used have to be
> predefined. One
> > > way out could be just to list the functions, which are defined within
> the
> > > files, on to the memory while 'load'-ing (say, after syntax checking,
> note the
> > > file name and line number where the function starts). A function can be
> loaded
> > > to the memory only when it is called. This way the dependency to a
> function
> > > which is being 'load'-ed later can be avoided. A possible drawback of
> this
> > > could be decrease of performance since NCL needs to do more work during
> > > execution of the job.
> > >
> > > regards,
> > >
> > > arindam
> > > --
> > >
> > > ---------- Original Message -----------
> > > From: "Saji N. Hameed" <saji_at_apcc21.net>
> > > To: Dennis Shea <shea_at_ucar.edu>
> > > Cc: ncl-talk_at_ucar.edu
> > > Sent: Sat, 27 Jun 2009 22:57:47 +0900
> > > Subject: Re: Order of function load matters ??
> > >
> > >> Hi Dennis,
> > >>
> > >>> Unlike a language like (say) fortran which has a compile/link/load
> > >>> sequence where the linker sets up pointers to any callable
> > >>> functions, NCL does not.
> > >>
> > >>> I think languages like python work th same way.
> > >>
> > >> Maybe not, this order dependency is not there in Ruby and I guess
> > >> not in Python as well. Within a script I could load two libraries
> > >> lib_a and lib_b in any order, even when lib_b is dependent on lib_a
> > >>
> > >> saji
> > >>
> > >>>
> > >>>
> > >>>
> > > >>
> http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclStatements.shtml
> > >>>
> > >>> Jack Glendening wrote:
> > >>>> Using NCL 5.0.0, I have sets of functions in two files which I load
> > >>>> immediately one after the other ala
> > >>>>
> > >>>> load "FunctionsFile_A"
> > >>>> load "FunctionsFile_B"
> > >>>> NCL COMMANDS WHICH CALL FUNCTIONS IN THE ABOVE FILES
> > >>>>
> > >>>> I just altered one of the functions in "FucntionsFile_A" to utilize
> a
> > >>>> new function "nintspan". When I placed the new function at the top
> of
> > >>>> "FunctionsFile_A" it worked. But if I moved the new function to
> > >>>> "FunctionsFile_B" I got the message "fatal:Undefined identifier:
> > >>>> (nintspan) is undefined". So apparently the the ordering of the*>
> >>>> function definitions matters ?! This does not make sense to me, since
> > >>>> one cannot always know the ordering of the function calls.
> > >>>>
> > >>>> Jack Glendening
> > >>>>
> > >>>> _______________________________________________
> > >>>> ncl-talk mailing list
> > >>>> List instructions, subscriber options, unsubscribe:
> > >>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> > >>> _______________________________________________
> > >>> ncl-talk mailing list
> > >>> List instructions, subscriber options, unsubscribe:
> > >>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> > >>>
> > >>
> > >> --
> > >> Saji N. Hameed
> > >>
> > >> APEC Climate Center
> > >> 1463 U-dong, Haeun dae-gu, +82 51 745 3951
> > >> BUSAN 612-020, KOREA saji_at_apcc21.net
> > >> Fax: +82-51-745-3999
> > >>
> > >> _______________________________________________
> > >> ncl-talk mailing list
> > >> List instructions, subscriber options, unsubscribe:
> > >> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> > >>
> > >> --
> > >> This message has been scanned for viruses and
> > >> dangerous content by MailScanner, and is
> > >> believed to be clean.
> > > ------- End of Original Message -------
> > >
> > >
> > > --
> > > This message has been scanned for viruses and
> > > dangerous content by MailScanner, and is
> > > believed to be clean.
> > >
> > > _______________________________________________
> > > ncl-talk mailing list
> > > Li st instructions, subscriber options, unsubscribe:
> > > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> > >
> > _______________________________________________
> > ncl-talk mailing list
> > List instructions, subscriber options, unsubscribe:
> > http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> *
> ------------------------------
> *Windows Live™: Keep your life in sync. Check it out!<http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009>
> *
> ------------------------------
> What can you do with the new Windows Live? Find out<http://www.microsoft.com/windows/windowslive/default.aspx>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

-- 
Mateus da Silva Teixeira
Registered Linux User #466740
Received on Mon Jun 29 2009 - 16:20:39 MDT

This archive was generated by hypermail 2.2.0 : Wed Jul 01 2009 - 06:11:45 MDT