PRO save_supermag ; convert supermag ASCII file to multiple ASCII files, one per station supermag_file = '*.txt' ; find all the station names, so we can create file names station_names = 'AAE' ; to be expanded later close, 1 openr, 1, supermag_file line = '' i=0 ; skip to the data ;WHILE data ne '================================================' DO READF, 1, data ;WHILE (stregex(line, 'Selected parameters:') lt 0) do READF, 1, line WHILE (stregex(line, 'Stations Selected:') lt 0) do READF, 1, line ;READF, 1, line cols = strsplit(strcompress(line), ' ',/extract) station_names = strsplit(STRCOMPRESS(cols(n_elements(cols)-1)), ',',/extract) ;WHILE (stregex(line, '=============================') lt 0) do READF, 1, line WHILE (stregex(line, 'Parameters: IAGA Station ID') lt 0) do READF, 1, line READF, 1, line cols = strsplit(strcompress(line), ' ',/extract) year = cols(0) month = cols(1) day = cols(2) nstat = n_elements(station_names) ntime = 24*60L data = fltarr(nstat,ntime,9) data(*,*,6:8) = 999999. ;STOP ; START READING supermag_file FROM THE TOP AGAIN, TO PUT THE DATA IN TO THE FILES close, 1 openr, 1, supermag_file ;WHILE strdata ne '==============================================' DO READF, 1, data ;WHILE (stregex(line, '=============================') lt 0) DO READF, 1, line WHILE (stregex(line, 'Parameters: IAGA Station ID') lt 0) do READF, 1, line fmt = '(i4, 5i3, 3i7)' fmt = '(i4, 5i3, 3f9.1)' ; WRITE DATA nn = 0 READF, 1, line ;cols = str_sep(STRCOMPRESS(data), ' ') cols = strsplit(strcompress(line), ' ',/extract) ;IF n_elements(cols) EQ 7 THEN BEGIN IF n_elements(cols) EQ 8 THEN BEGIN time_str = cols(0) + ' ' + cols(1) + ' ' + cols(2) + ' ' + cols(3) + ' ' + cols(4) + ' ' + cols(5) time = cols(0:5) print,'nn, time = ',nn, time endif done = 0 WHILE ~EOF(1) DO BEGIN READF, 1, line cols = strsplit(strcompress(line), ' ',/extract) IF n_elements(cols) eq 8 then begin done = 1 time = cols(0:5) ;print,'nn, time = ',nn, time nn = nn + 1 endif else begin for is=0,nstat -1 do begin for ii=0,5 do data(is,nn,ii) = fix(time(ii)) if (cols(0) eq station_names(is)) then begin ;for ii=0,5 do data(is,nn,ii) = fix(time(ii)) ;data(is,nn,6) = float(cols(1)) ;data(is,nn,7) = float(cols(2)) ;data(is,nn,8) = float(cols(3)) data(is,nn,6) = float(cols(9)) data(is,nn,7) = float(cols(10)) data(is,nn,8) = float(cols(11)) endif ;print,'Find the right station: will stop',cols(0) endfor endelse done = 0 ENDWHILE print,'ntime,nn = ',ntime,nn ;if (ntime ne nn) then stop nnn = ntime if (nn lt ntime) then nnn=nn ; MAKE FILES AND WRITE HEADERS FOR i = 0, N_ELEMENTS(station_names) - 1 do begin close, 2 openw, 2, station_names(i) + '_' + year + month + day + '.txt' print, 'making ' + station_names(i) + '_' + year + month + day + '.txt' printf, 2, station_names(i) + '_' + year + month + day printf, 2, 'yyyy month day hr mn H(mag N) E(mag E) Z ' ;for nn=0,ntime-1 DO printf, 2, format = fmt, data(i,nn,0:8) for nn=0,nnn DO printf, 2, format = fmt, data(i,nn,0:8) if (nnn < ntime-1) then begin time = reform(data(i,nnn,0:5)) time(4) = time(4)+1 printf, 2, format = fmt, time(0:5), data(i,nnn,6:8) print,'nn,Statation, time = ',nn,station_names(i),time endif ENDFOR CLOSE, /ALL stop END