Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Rearranging a data array containing calendrical as well as data entries.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg54872] Re: Rearranging a data array containing calendrical as well as data entries.
  • From: "Michel, Hans J.I." <HMiche at LSUHSC.EDU>
  • Date: Fri, 4 Mar 2005 05:08:10 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Gilmar:

Here's my take. You will need Mathematica version 5.1 and up, using one new
function StringSplit. The Calendar package takes care of all your date needs
(Leap year etc). The key function is FindList and the key search pattern is
findwhattext. With these two things you get the range of text you need from
your flow.dat file. The rest is clean up, and date logic.

I leave the final output up to the user. MatrixForm is good enough for me. I
leave error checking up to the user; i.e., Integer checking, start date less
than end date, that the file is there, and that the date range is in the
file. So this solution assumes you know what is in the file and that it
follows said format.

<< Miscellaneous`Calendar`

parseUSGSData[{year1_, month1_, day1_}, {year2_, month2_, day2_},
datafileName_] := Module[
	{days, datelist, findwhattext, fromfile, returnList, repstr},
	days = DaysBetween[{year1, month1, day1}, {year2, month2, day2}];
	datelist = Table[DaysPlus[{year1, month1, day1}, i], {i, 0, days}];
	findwhattext = Map[StringJoin, Map[ToString, Union[Drop[datelist,
{}, {3}]], {2}] /. {"1" -> " 1", "2" -> " 2", "3" -> " 3", "4" -> " 4", "5"
-> " 5", "6" ->  " 6", "7" -> " 7", "8" -> " 8", "9" -> " 9"}, {1}];
	repstr = Outer[StringJoin, findwhattext, {" 1 ", " 2 ", " 3 ", " 4
"}];
	fromfile = FindList[datafileName, findwhattext];
	returnList = Take[Drop[Flatten[StringSplit[StringReplace[fromfile,
repstr -> ""]]], If[day1 > 1, (day1 - 1), 0]], days + 1 ];
    	Table[{datelist[[i]], returnList[[i]]}, {i, (days + 1)}]
    ]

parseUSGSData[{1998, 9, 2}, {1998, 9, 30}, "C:\\flow.dat"]

% //MatrixForm

Hans Michel


  • Prev by Date: Why does mathematica randomly rewrite notebooks?
  • Next by Date: Re: Free variables in an expression
  • Previous by thread: Re: Rearranging a data array containing calendrical as well as data entries.
  • Next by thread: Re: Rearranging a data array containing calendrical as well as data entries.