【发布时间】:2019-07-22 20:38:52
【问题描述】:
我正在尝试编写一个循环来处理整个月的每日数据。我的代码在一次手动执行 1 天时有效,但是当我尝试循环遍历每个月的每一天时,我的循环失败了。
基本上,我循环 n = 1,30 天来读取文件,将数据剪辑到我的研究区域,并将每一天的数据添加到我的数据数组中。我想要一个包含整个月数据的数组。
这些是我循环中的函数:
@mls_choosefile_co.pro --> 这只是给了我“ToOpen”文件路径+名称
@mls_readin_co.pro --> 这使用 file_id 读取 CO 数据并将其剪辑到我的研究区域。输出为 'co_sa_100',对于研究区域中 100 hpa 的 CO,一个 1x700 数组(长度随天而变,可能是 706、720、680...)
^^ 这两个都可以单独工作。
; make array of data for the whole month - CO at 100hpa
; to append each additional day to this on each loop iteration
co_100_all = [ ]
; make array to save how many data points per day. use -9 as a fill value to tell me when the loop has not gone over that day.
len = MAKE_ARRAY(1,ndays, VALUE = -9)
; the loop in question:
FOR n = 0,ndays DO BEGIN &$
@mls_choosefile_co.pro &$
file_id = H5F_OPEN(ToOpen) &$
@mls_readin_co.pro &$
len[n-1] = N_ELEMENTS(co_sa_100) &$
co_100_all = [[co_100_all], [co_sa_100]] &$
END
我将“len”变量设置为测试。这将告诉我每天读取了多少数据点,每天有一个值(通常在 700 左右)。我已将 -9 设置为循环未运行的填充值。它应该是这样的: len = [702, 716, 706]。 但它只保存循环中的最后一个索引,我得到: len = [-9, -9, 706]。
提前致谢!
【问题讨论】: