Re: Rearranging a data array containing calendrical as well as data entries.
- To: mathgroup at smc.vnet.net
- Subject: [mg54844] Re: Rearranging a data array containing calendrical as well as data entries.
- From: "Valeri Astanoff" <astanoff at yahoo.fr>
- Date: Fri, 4 Mar 2005 05:07:41 -0500 (EST)
- References: <d0614i$krg$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
This is an example of what you could do : In[1]:= <<Miscellaneous`Calendar` getLine[line_String]:= Module[{year,month,n,nbd,days,ld,data}, year = StringTake[line,4] // ToExpression; month = StringTake[line,{5,6}] // ToExpression; n = StringTake[line,{8}] // ToExpression; nbd = DaysBetween[{year,month,1}, {year,month+1,1}]; days=Which[n == 1, Range[8], n == 2, Range[9,16], n == 3, Range[17,24], n == 4, Range[25,nbd], True, Print["error : n = ",n," line = ",line]]; ld = Length[days]; data = Table[StringTake[line,{10+7i, 15+7i}] // ToExpression, {i,0,ld-1}]; {{year,month,#[[1]]}, #[[2]]}& /@ Transpose[{days,data}] ]; getFlow[flowName_String, startDate_List, endDate_List]:= Module[{flo}, flo = Import[flowName,"Lines"]; Select[Flatten[getLine /@ flo,1], And @@ Thread[startDate <= #[[1]] <= endDate]&] ]; In[4]:= getFlow["flow.dat",{2000,02,01},{2000,02,29}] Out[4]= {{{2000,2,1},400.33},{{2000,2,2},379.64},{{2000,2,3},379.64},{{2000,2,4}, 379.64},{{2000,2,5},379.64},{{2000,2,6},379.64},{{2000,2,7}, 368.13},{{2000,2,8},368.13},{{2000,2,9},368.13},{{2000,2,10}, 368.13},{{2000,2,11},368.13},{{2000,2,12},367.02},{{2000,2,13}, 367.02},{{2000,2,14},367.02},{{2000,2,15},367.02},{{2000,2,16}, 367.02},{{2000,2,17},389.48},{{2000,2,18},389.48},{{2000,2,19}, 389.48},{{2000,2,20},389.48},{{2000,2,21},389.48},{{2000,2,22}, 364.36},{{2000,2,23},364.36},{{2000,2,24},364.36},{{2000,2,25}, 364.36},{{2000,2,26},364.36},{{2000,2,27},369.54},{{2000,2,28}, 369.54},{{2000,2,29},369.54}} hth v.a.