Converting Date Strings to Julian Numbers

QUESTION: I have a rather long array of date strings that I have read out of a file. The format for the date string is YYYY-MM-DD HH:MM:SS.FFFF, where FFFF is fractions of a second. Here is an example of the first two dates in my array:



I can parse this date array and create Julian numbers from the dates with the following code. But the code is quite slow and I have lots of dates to parse. Is there a faster way to parse this date array in IDL?

   juls = DBLARR(N_ELEMENTS(dates))
   FOR i=0, N_ELEMENTS(dates)-1 DO BEGIN
      splitdate = STRSPLIT(dates[i], ': +-', /EXTRACT)
      juls[i] = JULDAY(splitdate[1], splitdate[2], splitdate[0], $
          splitdate[3], splitdate[4], splitdate[5])
   ENDFOR

ANSWER: Pedro Rodrigues Pascual provided this answer in a thread on the IDL Newsgroup.

The C() calendar data format is very useful for doing this kind of thing, and it will allow you to process this string data array in just a single command, without loops. The C() calendar formats provide a simple way of reading years, months, days, etc. directly from a date string. Here is some code to show you how it is done.

   fmt='(C(CYI4, 1X, CMOI2, 1X, CDI2, 1X, CHI2, 1X, CMI2, 1X, CSF7.4))'
   juls = DBLARR(N_ELEMENTS(dates))
   READS, dates, juls, FORMAT=fmt

Google
 
Web Coyote's Guide to IDL Programming