FUNCTION LISA,source_in$,date$,ts,INFO$=info$ ;PRINT,'Baseline removal version of UITMAG loader. This version of the loader does not make or use cached SAV files.' ;Latitude and longitude of magnetic North Pole as given to us by Dag Lorentzen. magNPlat = 82.26 magNPlon = 277.23 source$ = source_in$ source$ = STRSPLIT(source$,':',/EXTRACT) CASE source$[0] OF 'query': retData = '^lisa' ELSE : BEGIN startdate = TIME_DOUBLE(date$) enddate = startdate + (ts * 60.) fileName$ = source$[1] PRINT,fileName$ savFName$ = fileName$ + '.sav' files = FINDFILE(savFName$, count=numFiles) ; numFiles=0 IF numFiles EQ 0 THEN BEGIN ; PRINT,'No previous saveset file found; creating saveset file from ASCII file.' ;Load data in from file. OPENR, unit, fileName$, /GET_LUN header$ = '' baseDec$ = '' baseInc$ = '' baseTot$ = '' latLon$ = '' ; READF,unit,header$ ; READF,unit,year,month,day,hour,min,second ; IF year LE 90 THEN year = year + 2000 ELSE year = year + 1900 ; READF,unit,header$ READF,unit,latLon$ ; baseDec = FLOAT(STRMID(baseDec$,16)) ; baseInc = FLOAT(STRMID(baseInc$,16)) ; baseTot = FLOAT(STRMID(baseTot$,16)) latLon$ = STRSPLIT(latLon$,',',/EXTRACT) lat = FLOAT(latLon$[7]) lon = FLOAT(latLon$[8]) c = 0LL sec = 0D bx = 0D by = 0D bz = 0D REPEAT BEGIN line$='' READF,unit,line$ dataVec = STRSPLIT(line$,',',/EXTRACT) ;DD/MM/YYYY HH:MM:SS Dec Horiz Vert Incl Total ;0 1 2 3 4 5 6 7 8 9 10 IF (c NE 0 ) THEN retData = [[retData], [dataVec]] ELSE retData = dataVec ++c ; print,c,' ',line$ ENDREP UNTIL EOF(unit) FREE_LUN,unit ;Transform time vector into epoch time. ;time0 = TIMEYMDHMSTOEPOCH(LONG(year),LONG(month),LONG(day),LONG(hour),LONG(min),LONG(second)) time$ = $ retData[0,*] + '-' + $ retData[1,*] + '-' + $ retData[2,*] + '/' + $ retData[3,*] + ':' + $ retData[4,*] + ':' + $ retData[5,*] timeVec = TIME_DOUBLE(time$) ; ; Bx = retData[7,*] * COS(retData[6,*] * !DTOR) - (baseTot * COS(baseInc * !DTOR) * COS(baseDec * !DTOR)) ; By = retData[7,*] * SIN(retData[6,*] * !DTOR) - (baseTot * COS(baseInc * !DTOR) * SIN(baseDec * !DTOR)) ; Bz = retData[8,*] Bx = retData[6,*] By = retData[7,*] Bz = retData[8,*] ;retData = TRANSPOSE([[timeVec], [Bx], [By], [Bz]]) retData = TRANSPOSE([timeVec, Bx, By, Bz]) ; ;Create a 4 column array containing: ; ; [TimeVector Bx By Bz] ; retData[*,0] = retData[*,0] + time0 ;Create Information Vector type$ = 'mag' name$ = STRUPCASE(source$[1]) + ' Lisa Mag (' + source$[2] + ')' unit$ = 'nT' shortID$ = STRUPCASE(source$[1]) + ':' + source$[2] info$ = [source_in$, type$, name$, unit$, shortID$ ] SAVE,file=savFName$,retData,info$,lat,lon ENDIF ELSE BEGIN RESTORE,file=savFName$ ENDELSE ;Ensure that the array only contains data within the specified time range. upper = WHERE(retData[*,0] GE startdate) retData = retData[upper,*] lower = WHERE(retData[*,0] LE enddate) retData = retData[lower,*] ;Rotate so that Bx points towards geomagnetic North. ;IF STRMID(STRUPCASE(source$[2]),0,1) EQ 'M' THEN BEGIN IF (STRMID(STRUPCASE(source$[2]),0,1) EQ 'M') && (STRMID(STRUPCASE(source$[2]),0,1,/REVERSE_OFFSET) NE 'G') THEN BEGIN sub_sphazm,lon,lat,magNPlon,magNPlat,azm,rn PRINT,'Rotating geopraphic magnetometer data to magnetic.' PRINT,'Geomagnetic North is at: ',magNPlat,magNPlon PRINT,'Declination for ',source$[1],' is ',NUMSTR(azm,2),' degrees.' retData[*,1] = retData[*,1] * COS(azm *!dtor) retData[*,2] = retData[*,2] * COS(azm *!dtor) ENDIF ;Select Magnetometer Component comp$ = STRMID(source$[2],0,1,/REVERSE_OFFSET) retData = comp(retData,comp$) ;Redo the info vector. type$ = 'mag' name$ = STRUPCASE(source$[1]) + ' Lisa Mag (' + source$[2] + ')' type$ = 'mag' unit$ = 'nT' ;IF (STRMID(STRUPCASE(source$[2]),0,1) EQ 'D') THEN unit$ = 'Deg' IF (STRMID(STRUPCASE(source$[2]),0,1) EQ 'I') THEN unit$ = 'Deg' shortID$ = STRUPCASE(source$[1]) + ':' + source$[2] info$ = [source_in$, type$, name$, unit$, shortID$ ] END ENDCASE RETURN, retData END