Re: Controlling program flow across cells

*To*: mathgroup at smc.vnet.net*Subject*: [mg54391] Re: Controlling program flow across cells*From*: David Bailey <dave at Remove_Thisdbailey.co.uk>*Date*: Sun, 20 Feb 2005 00:07:50 -0500 (EST)*References*: <cv6s3v$6l2$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

semiclassical wrote: > Here is the problem: > > I import a large data file - 20 years of hourly observations, which is > used to populate a raw data list of approximately 176,000 rows with > the following structure: > > {year, day, hour, validity_Flag, data_Item1, ... ,data_Item5} > > The list is then parsed, filtered and operated upon in several > different ways. In particular I calculate statistical properties of a > specified 5 year period. The process is encapsulated in a number of > cells- > > Cell_1 : Parse[ Import and filter raw data ]; > > Cell_2a: Parse[ Chip out and sort period of interest ]; > Cell_2b: Calculate[ statistical properties of validity_Flag ]; > Cell_2c: Calculate[ statistical properties of data_Item ]; > Cell_2d: Calculate[ distribution of data_Item ]; > > This is done for most data_Items, additionally calculations are made > for hourly statistics and quartely statistics. Now what I would like > to be able to do is loop over the four 5 year periods within the > complete 20 year span. Here are two questions: > > 1. I would like to set up a For[] loop across Cell_2a-Cell_2d to loop > through the four periods of interest. How can I do this, or should I > actually have built the program in a different way? > > 2. How can I get output from within a For[] loop as it is executing? > For example, I might like to watch some value of a given variable > within the loop as it is calculated (in C I would use a printf). > > Thanks, > > Aaron > semiclassical at hotmail.com > Your question is a little vague, so I am going to guess what I think you mean. I take it each of these four cells contains a calculation. The first step is to change each of these into a function definition: step1[]:= (........) step2[x_]= (........) etc. I will assume that you have set things up so that the output of each calculation is the input to the next, so one turn of your loop would become step4[step3[step2[step1[]]]] Note that step1 does not need an argument since it reads its data from a file. Maybe each of your steps leaves its output in variables, in which case all the functions would be defined with no arguments, and you would use step1[];step2[];step3[];step4[] Here is the loop to repeat the operations. For[i = 1, i < 176000, step4[step3[step2[step1[]]]]; i++] The equivalent of C's printf is Print - you can use any number of arguments including strings, and you dont need to bother with a format. In general, I would say, think in terms of function definitions - as you would in C - not in terms of cells. BTW, I think you would find that a short Mathematica course would help you enormously. David Bailey dbaileyconsultancy.co.uk

**Re: Leading Zeros? (question rephrased)**

**Re: Re: Re: Re: Bug Report - Two numerical values for a same variable**

**Re: Controlling program flow across cells**

**Leading Zeros? (question rephrased)**