vtk rendering satellite data from netcdf file in c++ error

Im trying to render a netcdf satellite data file but when i open it i keep getting
this error how do i fix this erorr

2023-07-11 12:15:04.205 (   0.663s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable a_h_NRTH dimensions (number_of_harmonization_coefficients) are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.234 (   0.692s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable algorithm_dynamic_input_data_container dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.251 (   0.709s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable algorithm_product_version_container dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.267 (   0.724s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable b_h_NRTH dimensions (number_of_harmonization_coefficients) are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.286 (   0.744s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable band_id dimensions (band) are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.315 (   0.772s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable band_wavelength dimensions (band) are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.335 (   0.793s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable band_wavelength_star_look dimensions (num_star_looks) are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.374 (   0.831s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable channel_gain_field dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.404 (   0.862s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable channel_integration_time dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.442 (   0.899s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable earth_sun_distance_anomaly_in_AU dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.491 (   0.948s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable esun dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.521 (   0.979s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable focal_plane_temperature_threshold_decreasing dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.555 (   1.012s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable focal_plane_temperature_threshold_exceeded_count dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.600 (   1.058s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable focal_plane_temperature_threshold_increasing dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.641 (   1.098s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable geospatial_lat_lon_extent dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.682 (   1.139s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable goes_imager_projection dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.722 (   1.180s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable kappa0 dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.758 (   1.216s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable max_radiance_value_of_valid_pixels dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.799 (   1.256s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable maximum_focal_plane_temperature dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.841 (   1.299s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable mean_radiance_value_of_valid_pixels dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.889 (   1.346s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable min_radiance_value_of_valid_pixels dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.940 (   1.398s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable missing_pixel_count dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:04.984 (   1.442s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable nominal_satellite_height dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.024 (   1.481s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable nominal_satellite_subpoint_lat dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.067 (   1.524s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable nominal_satellite_subpoint_lon dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.113 (   1.570s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable percent_uncorrectable_L0_errors dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.160 (   1.617s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable planck_bc1 dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.204 (   1.662s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable planck_bc2 dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.254 (   1.712s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable planck_fk1 dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.298 (   1.755s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable planck_fk2 dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.337 (   1.794s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable processing_parm_version_container dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.376 (   1.834s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable saturated_pixel_count dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.414 (   1.872s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable star_id dimensions (num_star_looks) are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.461 (   1.918s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable std_dev_radiance_value_of_valid_pixels dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.503 (   1.960s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable t dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.538 (   1.995s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable t_star_look dimensions (num_star_looks) are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.582 (   2.039s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable time_bounds dimensions (number_of_time_bounds) are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.624 (   2.081s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable undersaturated_pixel_count dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.669 (   2.127s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable valid_pixel_count dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.715 (   2.172s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable x_image dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.747 (   2.205s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable x_image_bounds dimensions (number_of_image_bounds) are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.792 (   2.250s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable y_image dimensions () are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.828 (   2.286s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable y_image_bounds dimensions (number_of_image_bounds) are different than the other variable dimensions (y x).  Skipping
2023-07-11 12:15:05.871 (   2.328s) [                ]    vtkNetCDFReader.cxx:834   WARN| vtkNetCDFCFReader (0000028CBF898AD0): Variable yaw_flip_flag 

and here is the code to load the netcdf file

    vtkSmartPointer<vtkNetCDFCFReader> reader = vtkSmartPointer<vtkNetCDFCFReader>::New();
    reader->SetFileName("C:/Users/----/Desktop/BOLTgui/BOLT/cs.nc");

    reader->Update();

    vtkDataObject* dataObject = reader->GetOutput();
    vtkDataSet* dataSet = vtkDataSet::SafeDownCast(dataObject);
    vtkPointData* pointData = dataSet->GetPointData();

    vtkSmartPointer<vtkContourFilter> contourFilter = vtkSmartPointer<vtkContourFilter>::New();
    contourFilter->SetInputConnection(reader->GetOutputPort());
    contourFilter->SetValue(0, 20); // set iso-value
    contourFilter->Update();

    vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
    lookupTable->SetNumberOfTableValues(256);
    lookupTable->Build();
    lookupTable->SetTableRange(contourFilter->GetOutput()->GetScalarRange());

    vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = vtkSmartPointer<vtkColorTransferFunction>::New();
    colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 1.0); // blue
    colorTransferFunction->AddRGBPoint(20.0, 0.0, 1.0, 0.0); // green
    colorTransferFunction->AddRGBPoint(40.0, 1.0, 1.0, 0.0); // yellow
    colorTransferFunction->AddRGBPoint(60.0, 1.0, 0.0, 0.0); // red

    vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputConnection(contourFilter->GetOutputPort());
    mapper->SetLookupTable(lookupTable);
    mapper->UseLookupTableScalarRangeOn();

    mapper->ScalarVisibilityOn();
    mapper->SetScalarModeToUsePointData();
    mapper->SetLookupTable(lookupTable);
    mapper->SetLookupTable(colorTransferFunction);

    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);

    vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer < vtkRenderer>::New();
    renderer->AddActor(actor);

    vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->AddRenderer(renderer);

    vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    interactor->SetRenderWindow(renderWindow);

    sf::WindowHandle handle = window.getSystemHandle();
    renderWindow->SetWindowInfo(reinterpret_cast<char*>(handle));
    interactor->Start();

and this is what im trying to get


the image is taken from panoply

The error indicates that the variables in your data are all not the same length. I can see in the mock image you shared that the variable only spans over a portion of the whole region. I don’t know much about the netcdf spec but if this use-case is valid, the reader needs to be changed to accommodate it.

@sankhesh What do i need to change?

@Cave1212 My guess is that the dataset you’re trying to load has more points than scalars. The warning you see originates from https://gitlab.kitware.com/vtk/vtk/-/blob/master/IO/NetCDF/vtkNetCDFReader.cxx#L838-858

which essentially means that there is a mismatch between number of points and point scalars. If your use case allows for this, the reader would have to set 0 values to the points where there are no scalars.

@sankhesh also do you know how to get the noise data from a netcdf file i do have color mapping but the colors and the color positon is always the same for different netcdf files but when i open the file in panoply the colors and color position are different
this is the code i have

        float scalingFactor = 1.0f / 2.122f;

        glEnable(GL_QUADS);
        glShadeModel(GL_SMOOTH);

        vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();

        vtkSmartPointer<vtkDataSet> data = vtkDataSet::SafeDownCast(reader->GetOutput());

        glPushMatrix();
        glRotatef(-90.0f, -10.0f, -10.0f, -43.0f);

        double minNoiseValue = std::numeric_limits<double>::max();
        double maxNoiseValue = std::numeric_limits<double>::lowest();

        for (vtkIdType i = 0; i < data->GetNumberOfCells(); i++) {
            vtkCell* cell = data->GetCell(i);
            vtkPoints* points = cell->GetPoints();

            if (cell->GetNumberOfPoints() == 4) {

                for (int j = 0; j < cell->GetNumberOfPoints(); j++) {
                    double noise[3];
                    points->GetPoint(j, noise);
                    double noiseValue = noise[0];

                    minNoiseValue = std::min(minNoiseValue, noiseValue);
                    maxNoiseValue = std::max(maxNoiseValue, noiseValue);
                }
            }
        }

        vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = vtkSmartPointer<vtkColorTransferFunction>::New();

        double noiseRange = maxNoiseValue - minNoiseValue;

        double color1[3] = { 0.0, 0.0, 1.0 }; // Blue
        double color2[3] = { 1.0, 1.0, 0.0 }; // Yellow
        double color3[3] = { 1.0, 0.0, 0.0 }; // Red
        double color4[3] = { 1.0, 1.0, 0.0 }; // Yellow
        double color5[3] = { 0.0, 0.0, 1.0 }; // Blue

        double noiseValue1 = minNoiseValue;
        double noiseValue2 = minNoiseValue + noiseRange * 0.25;
        double noiseValue3 = (minNoiseValue + maxNoiseValue) / 2.0;
        double noiseValue4 = minNoiseValue + noiseRange * 0.75;
        double noiseValue5 = maxNoiseValue;

        colorTransferFunction->AddRGBPoint(noiseValue1, color1[0], color1[1], color1[2]);
        colorTransferFunction->AddRGBPoint(noiseValue2, color2[0], color2[1], color2[2]);
        colorTransferFunction->AddRGBPoint(noiseValue3, color3[0], color3[1], color3[2]);
        colorTransferFunction->AddRGBPoint(noiseValue4, color4[0], color4[1], color4[2]);
        colorTransferFunction->AddRGBPoint(noiseValue5, color5[0], color5[1], color5[2]);

        for (vtkIdType i = 0; i < data->GetNumberOfCells(); i++) {
            vtkCell* cell = data->GetCell(i);
            vtkPoints* points = cell->GetPoints();

            if (cell->GetNumberOfPoints() == 4) {
                glBegin(GL_QUADS);

                for (int j = 0; j < cell->GetNumberOfPoints(); j++) {
                    double noise[3];
                    points->GetPoint(j, noise);

                    double noiseValue = noise[0];

                    double color[3];
                    colorTransferFunction->GetColor(noiseValue, color);

                    glColor4f(color[0], color[1], color[2], 0.5);

                    float lon = points->GetPoint(j)[0];
                    float lat = points->GetPoint(j)[1];
                    float altitude = points->GetPoint(j)[2];

                    glVertex3f(lon * scalingFactor, lat * scalingFactor, altitude * scalingFactor);
                }
                glEnd();
            }
        }

        glPopMatrix();

@Cave1212 In the code you posted, you are just using the X coordinate of the points as noise. To get the range of values in the data, you can just do something like

double* noiseRange = data->GetPointData->GetArrayByName("<noise>")->GetRange();

Change <noise> to the name of the variable that represents noise in your dataset. Hth