pro SUB_add_attributes_NetCDF, file_list, data, publisher=publisher, mission=mission, is_STARwet=is_STARwet, is_undulation=is_undulation if ~keyword_set(mission) then begin path=strsplit(file_dirname(file_list[0]),'/',/extract) mission=path[-3] endif if keyword_set(is_undulation) then begin ; ----------- array = fltarr(3,259200) lat_2d=fltarr(720,360) lon_2d=fltarr(720,360) undulation_2d=fltarr(720,360) openr,6,'./codes/Undulation/global_undulation.txt' readf,6, array ; lat, lon, undulation close,6 ;lat_1d = array[0,*] ;lon_1d = array[1,*] ;undulation_1d = array[2,*] lat_2d[*,*]=array[0,*] lon_2d[*,*]=array[1,*] undulation_2d[*,*]=array[2,*] lat_single=reform(lat_2d[0,*]) ; reform to remove “degenerate” leading dimensions lon_single=lon_2d[*,0] ; no need reform the non-leading dimension print, 'Undulation inserting:' endif bad_new_all = [] ;print, 'n_elements(file_list):',n_elements(file_list) for file_loop = 0, n_elements(file_list)-1 do begin ;for file_loop = 0, 1 do begin input_file = file_list[file_loop] print, input_file ncfileid = NCDF_OPEN(input_file, /WRITE ) ; get the file info if keyword_set(is_STARwet) then begin NCdF_attget, ncfileid, 'year',year, /global NCDF_attget, ncfileid, 'month',month, /global NCDF_attget, ncfileid, 'day',day, /global NCDF_attget, ncfileid, 'hour',hour, /global NCDF_attget, ncfileid, 'minute',minute, /global NCDF_attget, ncfileid, 'second',second, /global & second=floor(second) agency='STARwet' fileStamp_array=strsplit(file_basename(input_file),'_.',/extract) gps_1=strlowcase(fileStamp_array[6]) gps_2=strlowcase(fileStamp_array[7]) if strupcase(strmid(gps_1, 0, 1)) eq 'G' or $ strupcase(strmid(gps_1, 0, 1)) eq 'R' or $ strupcase(strmid(gps_1, 0, 1)) eq 'E' $ then gps = gps_1 else gps= gps_2 leo=fileStamp_array[1] endif else begin NCdF_varget, ncfileid, 'year',year NCDF_varget, ncfileid, 'month',month NCDF_varget, ncfileid, 'day',day NCDF_varget, ncfileid, 'hour',hour NCDF_varget, ncfileid, 'minute',minute NCDF_varget, ncfileid, 'second',second & second=floor(second) agency=publisher NCDF_varget, ncfileid, 'leo_id', leo_id & leo=string(leo_id) NCDF_varget, ncfileid, 'gns_id', gns_id & gps=strlowcase(string(gns_id)) if strlen(gps) eq 4 then gps=strmid(gps, 0, 1)+strmid(gps, 2, 2) ; g006 -> g06 endelse if keyword_set(is_undulation) then begin NCDF_varget, ncfileid, 'lat',lat NCDF_varget, ncfileid, 'lon',lon SUB_interpolate_model_latlon, lat, lon, $ lat_single, lon_single, $ lat_location, lon_location, $ lat_loc2=lat_location2, lon_loc2=lon_location2 undulation = -1 * mean(undulation_2d[lon_location2, lat_location2]) NCDF_VARPUT, ncfileid, 'undulation', undulation endif ; --- if leo eq 'UMD' then leo=fileStamp_array[2] if leo eq 'C001' then leo_full = 'COSMIC-1' $ else if leo eq 'C002' then leo_full = 'COSMIC-2' $ else if leo eq 'C003' then leo_full = 'COSMIC-3' $ else if leo eq 'C004' then leo_full = 'COSMIC-4' $ else if leo eq 'C005' then leo_full = 'COSMIC-5' $ else if leo eq 'C006' then leo_full = 'COSMIC-6' $ else if leo eq 'KOM5' then leo_full = 'KOMPSAT5' $ else if leo eq 'CHAM' then leo_full = 'CHAMP' $ else if leo eq 'MTPA' then leo_full = 'MetopA' $ else if leo eq 'MTPB' then leo_full = 'MetopB' $ else if leo eq 'MTPC' then leo_full = 'MetopC' $ else if leo eq 'META' then leo_full = 'MetopA' $ else if leo eq 'METB' then leo_full = 'MetopB' $ else if leo eq 'METC' then leo_full = 'MetopC' $ else if leo eq 'TSRX' then leo_full = 'TerraSAR-X' $ else if leo eq 'TDMX' then leo_full = 'TanDem-X' $ else if leo eq 'GRC1' then leo_full = 'GRACE-A' $ else if leo eq 'GRC2' then leo_full = 'GRACE-B' $ else if leo eq 'CNFS' then leo_full = 'C-NOFS' $ else if leo eq 'CI85' then leo_full = 'GO01' $ else if leo eq 'CI87' then leo_full = 'GO03' $ else if leo eq 'CI88' then leo_full = 'GO04' $ else if leo eq 'PAZ1' then leo_full = 'PAZ' $ else if (mission eq 'spire' and strlen(leo) eq 4) then leo_full = strmid(leo, 1) $ ; S112 else if (mission eq 'spire' and strlen(leo) eq 5) then leo_full = strmid(leo, 2) $ ; FM112 else leo_full = leo ; C2E1_2023-01-01T00:00:00_r19_STARwet_cosmic2 ; C2E1_2022-12-31T23:56:20_r19_ROPP_cosmic2 ; 117_2022-09-01T00:00:21_r18_ROPP_spire ; nss-ro_2022-09-01T00:00:21_fm117_ROPP_spire title= leo_full+'_'+$ string(year,format='(i4)') +'-'+$ string(month,format='(i2.2)') +'-'+$ string(day,format='(i2.2)') +'T'+$ string(hour,format='(i2.2)') +':'+$ string(minute,format='(i2.2)')+':'+$ string(second,format='(i2.2)')+'_'+$ gps+'_'+$ agency+'_'+mission ; print, title ; print, data[0].title ; some NetCDF files are not included in .sav file if total(strupcase(tag_names(data)) eq 'FILENAME') then begin ;print, 'Using Filename' this_id = where(data.filename eq file_basename(input_file), this_num) if this_num ne 1 then print, 'matched number is not 1(', this_num,') for ', input_file endif else begin this_id = where(data.title eq title, this_num) endelse if this_num gt 0 then begin ; bad = string(data[this_id[0]].is_bad, format='(i1)') bad = strtrim(string(data[this_id[0]].is_bad),2) endif else begin bad = '9' ;print, '(SUB_add_attributes_NetCDF.pro) No matched title: '+title endelse NCDF_CONTROL, ncfileid, /redef if keyword_set(is_STARwet) then begin if this_num gt 0 then begin view = data[this_id[0]].view endif else view=-999. NCDF_ATTPUT, ncfileid, /global, 'bad', bad, /char NCDF_ATTPUT, ncfileid, /global, 'view', view endif else begin NCDF_ATTPUT, ncfileid, /global, 'bad', bad endelse NCDF_CONTROL, ncfileid, /ENDEF ncdf_close, ncfileid ; --- double check the QF --- ncfileid = NCDF_OPEN(input_file) NCDF_ATTGET, ncfileid, /global, 'bad', bad_new bad_new_all = [bad_new_all, fix(string(bad_new))] ncdf_close, ncfileid endfor print, string(10B)+'--- double check the QF ---' print, 'SUB_add_attributes_NetCDF.pro :' print, 'n_elements(bad_new_all)',n_elements(bad_new_all) print, 'total(bad_new_all eq 0) ',total(bad_new_all eq 0, /INTEGER) print, 'total(bad_new_all eq 1) ',total(bad_new_all eq 1, /INTEGER) print, 'total(bad_new_all eq 2) ',total(bad_new_all eq 2, /INTEGER) print, 'total(bad_new_all eq 3) ',total(bad_new_all eq 3, /INTEGER) print, 'total(bad_new_all eq 4) ',total(bad_new_all eq 4, /INTEGER) print, 'total(bad_new_all eq 5) ',total(bad_new_all eq 5, /INTEGER) print, 'total(bad_new_all eq 6) ',total(bad_new_all eq 6, /INTEGER) print, 'total(bad_new_all eq 7) ',total(bad_new_all eq 7, /INTEGER) print, 'total(bad_new_all eq 8) ',total(bad_new_all eq 8, /INTEGER) print, 'total(bad_new_all eq 9) ',total(bad_new_all eq 9, /INTEGER) print, 'total(bad_new_all eq 10)',total(bad_new_all eq 10, /INTEGER) if total(bad_new_all eq 0) eq 0 then stop ;stop end