; $Id: //_IQ_XML_TIMS.pro $ ; Copyright (c) 2009, Feng XU, NOAA/NESDIS/STAR. ; All rights reserved. Unauthorized reproduction is prohibited. ; ;+ ; NAME: ; _IQ_XML_TIMS ; ; PURPOSE: ; prepare xml file for TIMS (time-series of statistics) ; ; CATEGORY: ; Quality monitoring & Web Presentation ; ; CALLING SEQUENCE: ; _IQ_XML_TIMS, tims_file, data_file, XML_DIR ; ; INPUTS: ; tims_file - tims buffer file, tims.sav ; data_file - file path to the IQUAM statistics working file: STAT.IQUAM.NCEP.????.??.sav ; XML_DIR - file path where output XML file ; ; OUTPUTS: ; Updated TIMS file ; Updated XML file ; ; DEPENDENCIES: ; calling YUIChartStyle, DATA2XML ; called by IQUAM_QM ; ; MODIFICATION HISTORY: ; Feb 11, 2010 - included in IQUAM lib ; Dec 1, 2012 - modified to include Argo (type=6) ; Jan 5, 2013 - include inherited flag (IF) in QC checks ; ; ; caldat,( LL/24/3600/1000+julday(1,1,1970)),m,d,y&print,m,d,y ;- Function _array_to_string, var_input, tims_date, var_list, aggregation, type=type, _norm=_norm if aggregation eq 'monthly' then begin pointInterval=' "pointIntervalUnit": "month",' endif else if aggregation eq 'daily' then begin pointInterval=' "pointInterval": 86400000,' endif else if aggregation eq 'hourly' then begin pointInterval=' "pointInterval": 3600000,' endif ; qc: ; {"name": "DR", "pointStart": 1356998400000, "pointIntervalUnit": "month", ; "data":[ 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 49.91, 49.42, 81.69]}, ; stat: ; {"name": "HR-Drifter", "pointStart": 1356998400000, "pointIntervalUnit": "month", ; "data":[157620,143664,157729,158886,163358,155815,158560,155086,153332,150891,144087,129127,134034,123654,139598]}, ;types_list = ['Argo', 'Drifter', 'HR-Drifter', 'T-Mooring','C-Mooring','CRW','Ship','IMOS'] ;qc_list = ['DR','GL','TS','SG','RS','XP','PH','XQ','AL'] size_input = size(var_input, /dim) ;print, 'size_input:',size_input ;print,'n_elements(size_input)',n_elements(size_input) n_tim = size_input[0] if(n_elements(size_input) gt 1) then n_var = size_input[1] else n_var = 1 if(n_elements(size_input) gt 2) then n_ref = size_input[2] else n_ref = 1 tims_output = strarr(n_var, n_ref) ; two lines for each stat/qc, one for name, one for data for ref_loop = 0, n_ref-1 do begin ; each files for var_loop = 0, n_var-1 do begin ; each lines tims_output[var_loop, ref_loop] = ' {"name": "'+var_list[var_loop]+'", "pointStart": replacehere,'+pointInterval+string(10B)+' "data":[' ii = 0 for tim_loop = 0, n_tim-1 do begin if ii eq 0 and (var_input[tim_loop, var_loop, ref_loop] lt -990 or ~finite(var_input[tim_loop, var_loop, ref_loop]))then begin ; no valid point yet continue endif else if ii eq 0 and var_input[tim_loop, var_loop, ref_loop] gt -990. then begin ; come in only once ii = 1 ;print,'tims_output[var_loop, ref_loop]:', tims_output[var_loop, ref_loop] ;print,'tims_date[tim_loop]:',tims_date[tim_loop] tims_output[var_loop, ref_loop] = StrJoin(StrSplit(tims_output[var_loop, ref_loop], 'replacehere', /Regex,/Extract,/Preserve_Null), tims_date[tim_loop]) ;print,'tims_output[var_loop, ref_loop]:', tims_output[var_loop, ref_loop] endif if type eq 'float' and ~keyword_set(_norm) then begin this_string = string(var_input[tim_loop, var_loop, ref_loop],format='(f7.3)') if strpos(strlowcase(this_string), 'nan') ge 0 or $ strpos(strlowcase(this_string), 'inf') ge 0 or $ strpos( this_string , '*' ) ge 0 or $ var_input[tim_loop, var_loop, ref_loop] lt -990 then this_string='null' endif else if type eq 'float' and keyword_set(_norm) then begin this_string = string(100.*var_input[tim_loop, var_loop, ref_loop]/max(var_input[*, var_loop, ref_loop]),format='(f7.3)') if strpos(strlowcase(this_string), 'nan') ge 0 or $ strpos(strlowcase(this_string), 'inf') ge 0 or $ strpos( this_string , '*' ) ge 0 or $ var_input[tim_loop, var_loop, ref_loop] lt -990 then this_string='0.0' endif else if type eq 'integer' then begin this_string = finite(var_input[tim_loop, var_loop, ref_loop])?strtrim(string(long64(var_input[tim_loop, var_loop, ref_loop])),2):'0' if strpos(strlowcase(this_string), 'nan') ge 0 or $ strpos(strlowcase(this_string), 'inf') ge 0 or $ strpos( this_string , '*' ) ge 0 or $ var_input[tim_loop, var_loop, ref_loop] lt -990 then this_string='0' endif ;if type eq 'integer' then begin ; print, var_input[tim_loop, var_loop, ref_loop] ; print, this_string ;endif if tim_loop eq n_tim-1 then tims_output[var_loop, ref_loop] = tims_output[var_loop, ref_loop] + this_string $ else tims_output[var_loop, ref_loop] = tims_output[var_loop, ref_loop] + this_string + ',' endfor tims_output[var_loop, ref_loop] = tims_output[var_loop, ref_loop] + ']}' ;if var_loop eq n_var-1 then tims_output[var_loop, ref_loop] = tims_output[var_loop, ref_loop] + ']}' $ ;else tims_output[var_loop, ref_loop] = tims_output[var_loop, ref_loop] + ']},' endfor endfor return, tims_output END