! This program reads two data files and writes out two new files ! containing the data from the times where both files have data. ! It assumes that the files are in date/time order ! Example: ! commonhours -f690070.org -g724916.org -p690070.com -q724916.com integer year(2), mo(2), day(2), hour(2), univtime(2), idx real dir(2), u(2) character*50 argv, name1, name2, name1out, name2out ! function definition integer julday if (iargc() .gt. 0) then do i = 1, iargc() call getarg(i,argv) !command line help prompt if ((argv(2:2).eq.'?').or.(argv(2:2).eq.'h')) then write(*,*) 'Valid command line options:' write(*,*) '-? or -h Display this help screen' write(*,*) '-f' write(*,*) '-g' write(*,*) '-p' write(*,*) '-q' stop else if (argv(2:2) == 'f') then !First input file name read(argv(3:),*) name1 else if (argv(2:2) == 'g') then !Second input file name read(argv(3:),*) name2 else if (argv(2:2) == 'p') then !First output file name read(argv(3:),*) name1out else if (argv(2:2) == 'q') then !Second output file name read(argv(3:),*) name2out end if end do endif open (1, file = name1, status = "old") open (2, file = name2, status = "old") open (10, file = name1out) open (20, file = name2out) ! read from both files read (1,*,end=300) year(1), mo(1), day(1), hour(1), dir(1), u(1) read (2,*,end=300) year(2), mo(2), day(2), hour(2), dir(2), u(2) ! calculate a single value for date and time univtime(1) = julday(day(1), mo(1), year(1))*24 + hour(1) univtime(2) = julday(day(2), mo(2), year(2))*24 + hour(2) do while (2 > 1) !only leave this loop when eof. ! index forward do while ( univtime(1) .lt. univtime(2) ) ! read first file until greater than or equal read (1,*,end=300) year(1), mo(1), day(1), hour(1), dir(1), u(1) univtime(1) = julday(day(1), mo(1), year(1))*24 + hour(1) end do do while ( univtime(2) .lt. univtime(1) ) ! read second file until greater than or equal read (2,*,end=300) year(2), mo(2), day(2), hour(2), dir(2), u(2) univtime(2) = julday(day(2), mo(2), year(2))*24 + hour(2) end do !write data when time is equal if( univtime(2) .eq. univtime(1) ) then write(10,40) year(1), mo(1), day(1), hour(1), dir(1), u(1) write(20,40) year(2), mo(2), day(2), hour(2), dir(2), u(2) 40 format(x, 4i4, 2f6.1) ! read from both files read (1,*,end=300) year(1), mo(1), day(1), hour(1), dir(1), u(1) read (2,*,end=300) year(2), mo(2), day(2), hour(2), dir(2), u(2) ! calculate a single value for date and time univtime(1) = julday(day(1), mo(1), year(1))*24 + hour(1) univtime(2) = julday(day(2), mo(2), year(2))*24 + hour(2) end if end do 300 continue end