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

Home » Public Forums » archive » Re: Is there a work around to save multiple variables with same head but different tails without listing all of them?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Is there a work around to save multiple variables with same head but different tails without listing all of them? [message #77889 is a reply to message #77888] Thu, 29 September 2011 04:50 Go to previous message
Brian Daniel is currently offline  Brian Daniel
Messages: 80
Registered: July 2009
Member
On Sep 29, 5:10 am, voidspace <jhkim...@gmail.com> wrote:
> Hello folks,
>
> I have a question at beginner's level. When I saved multiple variables
> with same head but different tails in IDL, I found it is tedious to
> type all of them in as follows.
>
> SAVE, sst_cccma_cgcm3_1, sst_cnrm_cm3, sst_csiro_mk3_0,
> sst_gfdl_cm2_0, sst_gfdl_cm2_1, $
>            sst_iap_fgoals1_0_g, sst_inmcm3_0, sst_ipsl_cm4,
> sst_miroc3_2_medres, sst_mpi_echam5, $
>            sst_mri_cgcm2_3_2a, sst_ncar_ccsm3_0, sst_ncar_pcm1,
> sst_ukmo_hadcm3, sst_ukmo_hadgem1, $
>            FILENAME='sst_cmip3_20c3m.sav'
>
> The '/All' keyword may help, but there are more variables that I don't
> want to save in. This aroused my curiosity, so I post my question here
> to know whether there is a workaround.
>
> In fact, I tried to find an advanced way by myself, but found it's
> difficult to know without an expert's guidance.
>
> An attempt with my best knowledge is as follows. As all model names
> from 'cccma_cgcm3_1' to 'ukmo_hadgem1' are saved in a string array
> 'model', I considered the 'EXECUTE' command.
>
> One prior step I did was saving 15 variable names in one single string
> array 'sst'.
>
> IDL> sst=STRARR(N_elements(model))
> IDL> FOR i=0, N_elements(model)-1 DO sst[i]='sst_'+model[i]
>
> Now, 'sst' contains 15 different variable names that I want to save
> in. Then, tried the following
>
> IDL> result=EXECUTE("SAVE, FILENAME='sst_cmip3_20c3m.sav', "+sst[i] )
>
> but in stuck because I have no idea how to make an implicit loop for
> 'sst[i]'.
>
> My attempt seems not a right way. I also thought it would be
> convenient if there is implicit do-loop like (sst(i),i=1,15) in
> Fortran, but I immediately got that it's nothing but a stupid idea.
>
> I thought over and googled as well but all were in vain.
>
> Can anybody suggest me a nice way to simplify the tedious command
> aforementioned?
>
> Best,
> John

You've already done the hard part, which is the string manipulation to
create your 'sst' array. The final step is to use StrJoin to bring
the array into one string joined by ', '. See below (UNTESTED).

result=EXECUTE("SAVE, FILENAME='sst_cmip3_20c3m.sav', strJoin(sst,',
',/Single) )
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Using PS_START to create A4 Landscape postscript?
Next Topic: Re: Saving via ImageMagick with Coyote Routines fails

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

Current Time: Wed Oct 08 17:52:29 PDT 2025

Total time taken to generate the page: 0.00414 seconds