福衛多個檔案分析
(使用Octave)

福衛號的大氣觀測資料

pkg load netcdf


#設定要分析的檔案名稱,並打開

filename = 'C:\fs7data\fs3_2015036\wetPrf_C001.2015.036.00.54.G29_2014.2860_nc';

ncid = netcdf.open(filename, 'NC_NOWRITE');


#資料參數的代號、格式

more

ncdisp(filename);



pkg load netcdf


% 設定檔案名稱

ncid = netcdf.open('C:\fs7data\fs3_2015036\wetPrf_C001.2015.036.00.54.G29_2014.2860_nc', 'NC_NOWRITE');

% 設定變數名稱

temp_varid = netcdf.inqVarID(ncid, 'Temp');

height_varid = netcdf.inqVarID(ncid, 'MSL_alt');

% 讀取溫度和高度數據

temperature = netcdf.getVar(ncid, temp_varid);

height = netcdf.getVar(ncid, height_varid);

% 關閉 NetCDF 文件,可以先不要有這個功能,持續開啟檔案、以便繼續處理內容

% netcdf.close(ncid); 

% 繪製圖表

plot(temperature, height, '-o', 'LineWidth', 2);

% 增加標題

xlabel('溫度(℃)');

ylabel('高度(km)');

title('溫度與高度關係圖');


pkg load netcdf


% 設定檔案名稱

ncid = netcdf.open('C:\fs7data\fs3_2015036\wetPrf_C001.2015.036.00.54.G29_2014.2860_nc', 'NC_NOWRITE');


% 設定變數名稱

temp_varid = netcdf.inqVarID(ncid, 'Temp');

height_varid = netcdf.inqVarID(ncid, 'MSL_alt');


% 讀取溫度和高度數據

temperature = netcdf.getVar(ncid, temp_varid);

height = netcdf.getVar(ncid, height_varid);


% 關閉 NetCDF 文件,可以先不要有這個功能,持續開啟檔案、以便繼續處理內容

% netcdf.close(ncid); 


% 選取 MSL_alt > 5 的資料

valid_indices = find(height > 5);

filtered_temperature = temperature(valid_indices);

filtered_height = height(valid_indices);


% 繪製圖表

figure;

plot(filtered_temperature, filtered_height, '-o', 'LineWidth', 2);


% 增加標題

xlabel('溫度(℃)');

ylabel('高度(km)');

title('溫度與高度關係圖 (MSL_alt > 5)');


pkg load netcdf


folder_path = 'C:\fs7data\fs3_2015036'; % 替換為你的資料夾路徑

file_list = dir(fullfile(folder_path, '*_nc'));


results = struct('FileName', {}, 'MinTemp', {}, 'MinMSLAlt', {}, 'Lon', {}, 'Lat', {}); % 用於存儲結果的結構體數組


for i = 1:length(file_list)

    file_path = fullfile(folder_path, file_list(i).name);

    ncid = netcdf.open(file_path, 'NC_NOWRITE');

    

    % 列出所有變量名

    [ndims, nvars, ngatts, unlimdimid] = netcdf.inq(ncid);

    var_names = cell(nvars, 1);

    for varid = 0:nvars-1

        [var_names{varid+1}, xtype, dimids, natts] = netcdf.inqVar(ncid, varid);

    end

    

    % 確認變量是否存在

    required_vars = {'Temp', 'MSL_alt', 'Lon', 'Lat'};

    missing_vars = required_vars(~ismember(required_vars, var_names));

    

    if isempty(missing_vars)

        % 讀取變量

        temp = netcdf.getVar(ncid, netcdf.inqVarID(ncid, 'Temp'));

        msl_alt = netcdf.getVar(ncid, netcdf.inqVarID(ncid, 'MSL_alt'));

        lon = netcdf.getVar(ncid, netcdf.inqVarID(ncid, 'Lon'));

        lat = netcdf.getVar(ncid, netcdf.inqVarID(ncid, 'Lat'));

        

        % 找到 MSL_alt 大於 5 的索引

        valid_indices = find(msl_alt > 5);

        

        if ~isempty(valid_indices)

            % 只处理满足条件的记录

            temp = temp(valid_indices);

            msl_alt = msl_alt(valid_indices);

            lon = lon(valid_indices);

            lat = lat(valid_indices);

            

            % 找到溫度的最小值及其索引

            [min_temp, min_temp_idx] = min(temp);

            

            if min_temp > -100

                min_msl_alt = msl_alt(min_temp_idx);

                min_lon = lon(min_temp_idx);

                min_lat = lat(min_temp_idx);

                

                % 添加結果到結構體數組

                results(end+1) = struct('FileName', file_list(i).name, 'MinTemp', min_temp, 'MinMSLAlt', min_msl_alt, 'Lon', min_lon, 'Lat', min_lat);

            end

        end

    else

        warning(['Variables not found in ', file_list(i).name, ': ', strjoin(missing_vars, ', ')]);

    end

    

    % 關閉NetCDF文件

    netcdf.close(ncid);

end


% 顯示結果

%for i = 1:length(results)

%    disp(results(i));

%end


% 選擇性地將結果保存到檔

fileID = fopen('c:\fs7data\results.csv', 'w');

fprintf(fileID, 'FileName,MinTemp,MinMSLAlt,Lon,Lat\n');

for i = 1:length(results)

    fprintf(fileID, '%s,%f,%f,%f,%f\n', results(i).FileName, results(i).MinTemp, results(i).MinMSLAlt, results(i).Lon, results(i).Lat);

end

fclose(fileID);


pkg load io % 載入 IO 包以讀取 CSV 檔

 

% 讀取 CSV 文件,跳過第一行(標題行)

file_path = 'c:\fs7data\results.csv';

data = csvread(file_path, 1, 0); % 從第二行開始讀取

 

% 提取經度、緯度和高度資料

lon = data(:, 4); % 假設經度在第四列

lat = data(:, 5); % 假設緯度在第五列

height = data(:, 3); % 假設高度在第三列

 

% 繪製二維散點圖,使用高度進行著色

figure;

scatter(lon, lat, 36, height, 'filled'); % 36 是點的大小

xlabel('Longitude');

ylabel('Latitude');

title('Scatter Plot of Longitude, Latitude, and Height');

colorbar; % 添加顏色條


pkg load io % 載入 IO 包以讀取 CSV 檔

pkg load mapping % 載入 Mapping 包以讀取 Shapefile 檔

 

% 讀取 CSV 文件,跳過第一行(標題行)

file_path = 'c:\fs7data\results.csv';

data = csvread(file_path, 1, 0); % 從第二行開始讀取

 

% 提取經度、緯度和高度資料

lon = data(:, 4); % 假設經度在第四列

lat = data(:, 5); % 假設緯度在第五列

height = data(:, 3); % 假設高度在第三列

 

% 創建更密集的經度和緯度網格

lon_dense = linspace(min(lon), max(lon), 100); % 創建 100 個均勻分佈的經度值

lat_dense = linspace(min(lat), max(lat), 100); % 創建 100 個均勻分佈的緯度值

[lon_grid, lat_grid] = meshgrid(lon_dense, lat_dense); % 創建經緯度的二維網格

 

% 使用 griddata 進行插值

interpolated_height = griddata(lon, lat, height, lon_grid,

lat_grid);

 

% 繪製填充後的資料

% 使用 pcolor 函數繪製填充圖,並設置邊界線為不可見

figure;

pcolor(lon_grid, lat_grid, interpolated_height);

shading interp; % 平滑渲染

colorbar; % 添加顏色條

title('Interpolated Height Data');

xlabel('Longitude');

ylabel('Latitude');

hold on;

 

% 讀取 Shapefile 文件

coastline = shaperead('c:\fs7data\ne_110m_coastline.shp');

 

% 繪製海岸線

for k = 1:length(coastline)

    plot(coastline(k).X,

coastline(k).Y, 'k'); % 使用黑色繪製海岸線

end

 

hold off;

 

% 設置 x 軸和 y 軸比例相同

axis equal;