mod_read_obs.F90:51:39: 51 | istat=nf_get_var_real(ncid,varid,temp1(1,:)) | 1 ...... 118 | istat=nf_get_var_real(ncid,varid,temp1) | 2 Error: Rank mismatch between actual argument at (1) and actual argument at (2) (scalar and rank-1)
时间: 2024-02-15 17:27:58 浏览: 166
这个错误提示是在Fortran代码中使用了 nf_get_var_real 函数,并且在第51行和第118行两次调用,但是在第51行调用时使用了一个2D数组temp1(1,:)作为参数,而在第118行调用时使用了一个1D数组temp1作为参数。这导致了实际参数的秩(rank)不匹配,从而导致编译器报错。
解决这个问题的方法是,在调用 nf_get_var_real 函数时,确保实际参数的秩与函数声明中的形式参数的秩匹配。在这个例子中,可以修改第51行的代码,将temp1(1,:)改为temp1,使其与第118行的代码保持一致。这样就能避免实际参数的秩不匹配的问题。
相关问题
/usr/bin/ld: CMakeFiles/global_planning_node.dir/src/global_planning_node.cpp.o: in function main.cold': global_planning_node.cpp:(.text.unlikely+0x273): undefined reference to tf::TransformListener::~TransformListener()' /usr/bin/ld: CMakeFiles/global_planning_node.dir/src/global_planning_node.cpp.o: in function main': global_planning_node.cpp:(.text.startup+0xc64): undefined reference to tf::Transformer::DEFAULT_CACHE_TIME' /usr/bin/ld: global_planning_node.cpp:(.text.startup+0xc92): undefined reference to tf::TransformListener::TransformListener(ros::Duration, bool)' /usr/bin/ld: global_planning_node.cpp:(.text.startup+0xd7a): undefined reference to tf::Transformer::lookupTransform(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ros::Time const&, tf::StampedTransform&) const' /usr/bin/ld: global_planning_node.cpp:(.text.startup+0xe74): undefined reference to tf::TransformListener::~TransformListener()' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/global_planning_node.dir/build.make:246: /home/juan/catkin_ws/devel/.private/putn/lib/putn/global_planning_node] Error 1 make[1]: *** [CMakeFiles/Makefile2:207: CMakeFiles/global_planning_node.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... /usr/bin/ld: CMakeFiles/local_obs_node.dir/src/local_obs.cpp.o: in function rcvVelodyneCallBack(sensor_msgs::PointCloud2<std::allocator<void> > const&)': local_obs.cpp:(.text+0xa0b): undefined reference to tf::Transformer::waitForTransform(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ros::Time const&, ros::Duration const&, ros::Duration const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) const' /usr/bin/ld: local_obs.cpp:(.text+0xc74): undefined reference to tf::TransformListener::transformPoint(std::cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, geometry_msgs::PointStamped<std::allocator<void> > const&, geometry_msgs::PointStamped<std::allocator<void> >&) const' /usr/bin/ld: CMakeFiles/local_obs_node.dir/src/local_obs.cpp.o: in function main.cold': local_obs.cpp:(.text.unlikely+0x37d): undefined reference to tf::TransformListener::~TransformListener()' /usr/bin/ld: CMakeFiles/local_obs_node.dir/src/local_obs.cpp.o: in function main':local_obs.cpp:(.text.startup+0x62a): undefined reference to tf::Transformer::DEFAULT_CACHE_TIME' /usr/bin/ld: local_obs.cpp:(.text.startup+0x64d): undefined reference to tf::TransformListener::TransformListener(ros::Duration, bool)' /usr/bin/ld: local_obs.cpp:(.text.startup+0x6dc): undefined reference to tf::TransformListener::~TransformListener()' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/local_obs_node.dir/build.make:246: /home/juan/catkin_ws/devel/.private/putn/lib/putn/local_obs_node] Error 1 make[1]: *** [CMakeFiles/Makefile2:612: CMakeFiles/local_obs_node.dir/all] Error 2 make: *** [Makefile:141: all] Error 2解释编译时出现这个问题的原因,并说说如何解决
这个编译错误是因为链接器找不到tf库的符号引用。tf库是一个用于处理坐标变换的库,它提供了TransformListener和Transformer等类。
要解决这个问题,你需要确保tf库正确地链接到你的项目中。以下是一些可能的解决方法:
1. 确保tf库已经正确地安装在你的系统中。如果你使用的是ROS,可以通过运行以下命令来安装tf库:
```
sudo apt-get install ros-<distro>-tf
```
这里的 `<distro>` 是你正在使用的ROS发行版,例如`melodic`或`noetic`。
2. 确保在你的CMakeLists.txt文件中正确地添加了tf库的依赖项。你可以在`find_package`命令后添加以下行来链接tf库:
```
target_link_libraries(your_target_name ${catkin_LIBRARIES} tf)
```
这里的 `your_target_name` 是你的目标可执行文件的名称。
3. 如果你的项目使用了其他依赖项,例如tf2或tf2_ros,你可能还需要添加它们的链接库。例如:
```
target_link_libraries(your_target_name ${catkin_LIBRARIES} tf tf2 tf2_ros)
```
4. 确保你的源代码文件中包含了正确的头文件引用。对于tf库,你可能需要包含`<tf/transform_listener.h>`和`<tf/transform_broadcaster.h>`。
尝试以上方法后,重新编译你的项目,应该能够解决链接错误。如果问题仍然存在,请确保在编译过程中没有其他错误或警告,并仔细检查你的代码和编译配置。
转matlab: n_points_total = numpy.int(noisy_sensor_measured_total.shape[1]/(n_obs_in_sensor_array + 1)) intrinsic_process_total_reshaped = numpy.reshape(intrinsic_process_total, [dim_intrinsic, n_points_total, n_obs_in_sensor_array + 1], order='C') noisy_sensor_measured_total_reshaped = numpy.reshape(noisy_sensor_measured_total, [dim_measurement, n_points_total, n_obs_in_sensor_array + 1], order='C') intrinsic_process_base_total = intrinsic_process_total_reshaped[:, :, 0] intrinsic_process_step_total = intrinsic_process_total_reshaped[:, :, 1:] noisy_sensor_base_total = noisy_sensor_measured_total_reshaped[:, :, 0] n_obs_used_in_each_cluster = min(n_obs_used_in_cluster, n_obs_in_sensor_array) obs_used_in_each_cluster_indexes = numpy.random.choice(n_obs_in_sensor_array, size=n_obs_used_in_each_cluster, replace=False) sensor_array_matrix = sensor_array_matrix_dense[:, obs_used_in_each_cluster_indexes] noisy_sensor_step_total = noisy_sensor_measured_total_reshaped[:, :, 1:]
在Matlab中,您可以将以下Python代码转换为对应的Matlab代码:
```matlab
n_points_total = int(size(noisy_sensor_measured_total, 2) / (n_obs_in_sensor_array + 1));
intrinsic_process_total_reshaped = reshape(intrinsic_process_total, [dim_intrinsic, n_points_total, n_obs_in_sensor_array + 1]);
noisy_sensor_measured_total_reshaped = reshape(noisy_sensor_measured_total, [dim_measurement, n_points_total, n_obs_in_sensor_array + 1]);
intrinsic_process_base_total = intrinsic_process_total_reshaped(:, :, 1);
intrinsic_process_step_total = intrinsic_process_total_reshaped(:, :, 2:end);
noisy_sensor_base_total = noisy_sensor_measured_total_reshaped(:, :, 1);
n_obs_used_in_each_cluster = min(n_obs_used_in_cluster, n_obs_in_sensor_array);
obs_used_in_each_cluster_indexes = datasample(1:n_obs_in_sensor_array, n_obs_used_in_each_cluster, 'Replace', false);
sensor_array_matrix = sensor_array_matrix_dense(:, obs_used_in_each_cluster_indexes);
noisy_sensor_step_total = noisy_sensor_measured_total_reshaped(:, :, 2:end);
```
请注意,上述代码中的 `datasample` 函数用于在 `1:n_obs_in_sensor_array` 中随机选择 `n_obs_used_in_each_cluster` 个索引,并且不允许重复。如果您的Matlab版本不支持 `datasample` 函数,可以使用以下代码替代:
```matlab
obs_used_in_each_cluster_indexes = randsample(1:n_obs_in_sensor_array, n_obs_used_in_each_cluster, false);
```
这里使用了 `randsample` 函数来实现相同的功能。
阅读全文