!------------------------------------------------------------------------ ! ! Subroutine for - reading in the satellite magnetometer data from a file ! !------------------------------------------------------------------------ subroutine read_currents use ModAMIE use ModFiles use ModData use ModConductance use ModIndices implicit none integer :: iLunCurrent, iyr, imon, iday, ihr, minute, isec, ierr integer :: nlines_to_read, i, j, n, k, ll, l, ifile, npt, iNC real*8 :: time_start, time, dt_magfile, time_before_all, ctime real :: alon, alat, hp character (len=100) :: line integer, dimension(7) :: itime iLunCurrent = lun_current ifile = 1 do ifile = 1, ncurrent_files call merge_str(current_dir, current_file(ifile)) iLunCurrent = iLunCurrent + ifile - 1 open(iLunCurrent, file = current_file(ifile), status='old', iostat = ierr) if (ierr /= 0) then write(6,*) 'Error opening E-field file :',current_file endif read(iLunCurrent,*) line read(iLunCurrent,*) line if (timelist(1) > -1.0e32) then ctime = timelist(1) else ctime = currenttime endif itime(7) = 0 if (DebugLevel > 2) & write(*,*) " ===> read_currents, n = ", ifile, ntimes time = 0.0 ctime = ctime - window_dt/2.0 do while (time < ctime) read(iLunCurrent,"(i4,5i3)", iostat = ierr) itime(1:6) if (ierr /= 0) then time = 1.0e32 else call time_int_to_real(itime, time) endif enddo if (time < 1.0e32) backspace(iLunCurrent) npts_current(ifile) = 1 if (timelist(ntimes) > -1.0e32) then ctime = timelist(ntimes) else ctime = currenttime + dt * (ntimes-1) endif ctime = ctime + window_dt/2.0 do while (time < ctime) itime = 0 iNC = npts_current(ifile) read(iLunCurrent,"(i4,5i3,f6.2,f7.2,f6.2,i5,f7.2,2f9.2,4f7.2,43x,4f7.2)", & iostat = ierr) itime(1:6), & CurrentLocations(ifile, iNC, mag_lat_), & alon, CurrentLocations(ifile, iNC, mlt_), npt,& CurrentAngle(ifile,iNC), CurrentDalat(ifile,iNC), CurrentDalon(ifile,iNC),& CurrentData(ifile, iNC, ddby_), CurrentDataError(ifile, iNC, ddby_), & CurrentData(ifile, iNC, ddbz_), CurrentDataError(ifile, iNC, ddbz_), & CurrentData(ifile, iNC, dby_), CurrentDataError(ifile, iNC, dby_), & CurrentData(ifile, iNC, dbz_), CurrentDataError(ifile, iNC, dbz_) !\ ! There are 2 possible reasons why ierr /= 0: ! (1) EOF was reached. ! (2) a data value was missing from the row. ! Therefore, we have to check to see which is true. !/ !\ ! This is option 2 above !/ if (ierr /= 0 .and. itime(1) /= 0) ierr = 0 if (ierr /= 0) then !\ ! This is option 1 above !/ time = ctime + 1.0 else alat = CurrentLocations(ifile, iNC, mag_lat_) if (ihsoln*alat > 0) then call time_int_to_real(itime, time) CurrentTimes(ifile, iNC) = time ! ! this implies iNC = iNC + 1 ! npts_current(ifile) = npts_current(ifile) + 1 endif endif enddo close(iLunCurrent) npts_current(ifile) = npts_current(ifile) - 1 if (DebugLevel > 1) write(*,*) " ==> ",npts_current(ifile), & " points read from file ",current_file(ifile) enddo end subroutine read_currents