Question

I am using cdi (climate data interface, https://code.zmaw.de/projects/cdi/wiki ) to create a netcdf file. I made the example in the documentation to write a netcdf file, and it works ok. But when using cdi operatively for the first time, it doesn't create the time axis. See the code:

    ! Now, we create the output file.
        ! We first create the grid.
    gridID = gridCreate(y3D%GridType, NLons * NLats)

    CALL gridDefXsize(gridID, NLons)
    CALL gridDefYsize(gridID, NLats)
    CALL gridDefXvals(gridID, y3D%Lons)
    CALL gridDefYvals(gridID, y3D%Lats)

        ! Now, the z axis to be attached to the variable when created (there is one z axis per variable).
    zaxisID = zaxisCreate(y3D%ZAxisType, 1) ! We only support predictands with one level. 1 creates a surface level.


        ! Now create the variable list
    vlistID = vlistCreate()
        ! And define the variables in the variable list
    Prevision   = vlistDefVar(vlistID, gridID, zaxisID, TIME_VARIABLE)

        ! Now define the variable names
    CALL vlistDefVarName(vlistID, Prevision , "Prevision")


        ! Now the time axis and attach it to the variable list.
    taxisID = taxisCreate(TAXIS_RELATIVE)   !ABSOLUTE)
    write (*,*) "taxisID: ", taxisID
    CALL taxisDefRDate(taxisID, 19000101)
    CALL vlistDefTaxis(vlistID, taxisID)

        ! Now create the file
    streamID = streamOpenWrite(char(ResultsFile), OutType)
    if ( streamID < 0 ) then
        write (*,*) "ERROR while attempting to create the file ", char(ResultsFile), " to store the results."
        write (*,*) cdiStringError(streamID)
        stop
    end if
        ! Assign the variable list to the dataset
    CALL streamDefVlist(streamID, vlistID)

        ! Now we have to loop over the time steps to store the data.
    DO tsID = 0, NDates - 1
        ! Set the verification date
        write (*,*) "Date ", ar_DatesPredicted(tsID+1)
        CALL taxisDefVdate(taxisID, ar_DatesPredicted(tsID+1))
        ! Set the verification time to 12:00:00
        CALL taxisDefVtime(taxisID, 120000)
        ! Define the time step
        status = streamDefTimestep(streamID, tsID)
        write (*,*) "Number of records of the time step: ", status

        ! Write values of each variable
        CALL streamWriteVar(streamID, Prevision, ar_y_2DPrev(tsID+1, c_predictands)%Values, NMiss)

    END DO

    ! Close the output stream
    CALL streamClose(streamID)

    ! Destroy the objects
    CALL vlistDestroy(vlistID)
    CALL taxisDestroy(taxisID)
    CALL zaxisDestroy(zaxisID)
    CALL gridDestroy(gridID)        
Was it helpful?

Solution

Solved!:

The reason for this problem was that I had two versions of the cdi libraries intalled. One was installed using the system package manager, and the other one were installed manually in my home directory. I linked with the first to build some objects, and linked with the other one to build other objects. Once the same version was used everywhere, the problem dissapeared.

So this is a general rule: not to mix different versions of the same library to link to.

Thanks to all of you that tried to help me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top