X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 31 Mar 2011 08:21 PM by  anon
how to read date variable using idl
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
31 Mar 2011 08:21 PM
    anyone could help me out? now, I am wondering how to read the date variable such as "11:00/04/01/2011" in a Excell file, and how to plot it in coordinates system. Best wishes, Donald

    Deleted User



    New Member


    Posts:
    New Member


    --
    20 Jun 2011 04:34 PM
    First, you can save the excel file as a txt/csv file. Then, you can read the dates in as strings using the the READF function. From there you can parse the date strings into separate variables using the STRSPLIT function. For example with the date you provided, you can parse the date using the code below: split1 = strsplit("11:00/04/01/2001", '/', /EXTRACT) ;creates new array 'split1', '/' indicates separation of elements split2 = strsplit(split1[0], ':', /EXTRACT) ;creates new array 'split2', ':' indicates separation of elements hour=split2[0] minute=split2[1] month=split1[1] day=split1[2] year=split1[3] second=0L After that, you can use the JULDAY function to get the Julday number for each of the dates. The LABEL_DATE function can then be used to specify how you want the date labeled on your plot. Then, you can plot your a data set against the Julday numbers with the keyword XTICKFORMAT='LABEL_DATE'. This should produce a plot with the dates appearing on the x-axis in the format you specified using the LABEL_DATE function.

    Deleted User



    New Member


    Posts:
    New Member


    --
    22 Aug 2011 04:57 PM
    Here is an example program that shows a new graphics plot with the date a long the x-axis. The program is called "date_plotter.pro". The programs reads dates stored in the file "test_dates.txt", which is shown below: test_dates.txt : 11:00/04/01/2011 11:00/04/02/2011 12:12/04/04/2011 12:00/04/15/2011 10:00/05/01/2011 10:00/06/02/2011 date_plotter.pro: pro date_plotter COMPILE_OPT IDL2 array='' line='' file=FILE_WHICH('test_dates.txt') openr, u, file, /get_lun While NOT EOF(u) Do Begin & $ readf, u, line & array=[array, line] & $ ENDWHILE FREE_LUN, u jul_array=findgen(N_elements(array)-1) FOR i=1, N_elements(array)-1 DO BEGIN split1 = strsplit(array[i], '/', /EXTRACT) split2 = strsplit(split1[0], ':', /EXTRACT) hour=split2[0] minute=split2[1] month=split1[1] day=split1[2] year=split1[3] second=0L j=JULDAY(month,day,year,hour,minute,second) jul_array[i-1]=j print, j ENDFOR print, jul_array data=dindgen(N_elements(array)-1) date_label=LABEL_DATE(DATE_FORMAT = ['%M %D']) p=plot(jul_array, data, XTICKFORMAT=['LABEL_DATE'],$ xtickunits=['Day']) end
    You are not authorized to post a reply.