2

I define a variable like: VAR(t,o) with Dimensions: t=4 and o=11

IERREU = nf90_def_var(ncid, "var", nf90_real, (/ oID, tID /), VarID)

That looks like:

VAR(1,1)=5
VAR(2,1)=2
VAR(3,1)=8
VAR(4,1)=9
VAR(1,2)=5
VAR(2,2)=2
VAR(3,2)=8
VAR(4,2)=9
....
VAR(1,11)=5
VAR(2,11)=2
VAR(3,11)=8
VAR(4,11)=9  

To write the variable in the netcdf file, I do:

IERREU = nf90_put_var(ncid, VarID, VAR)

In the netcdf, I want to have the data of my variable order like:

VAR=5,5,5,5,5,5,5,5,5,5,5,
    2,2,2,2,2,2,2,2,2,2,2,
    8,8,8,8,8,8,8,8,8,8,8,
    9,9,9,9,9,9,9,9,9,9,9;

And I get this:

VAR= 5,2,8,9,5,2,8,9,5,2,8,
     9,5,2,8,9,5,2,8,9,5,2,
     8,9,5,2,8,9,5,2,8,9,5,
     2,8,9,5,2,8,9,5,2,8,9;

How can I define the order of the data ?

4
  • What is the relation between lat and VAR? please clarify your question. Commented Dec 17, 2015 at 15:30
  • Sorry, it is an error... Commented Dec 17, 2015 at 15:36
  • Can you add the line of code that defines your netcdf variable (varID)? What (software) are you using to to visualize your data in the netcdf? Commented Dec 17, 2015 at 15:54
  • I have added the line. I use ncview ... Commented Dec 17, 2015 at 15:56

2 Answers 2

3

If you need to keep the dimension order of your array the same in your program yet transpose it in the netCDF file then you have two options.

Just write the transpose

IERREU = nf90_put_var(ncid, VarID, transpose(VAR))

or use the map vector argument

IERREU = nf90_put_var(ncid, VarID, VAR, map=(/ t,1 /))

This case is covered in the standard netCDF documentation for nf90_put_var

[ 1: http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-f90/NF90_005fPUT_005fVAR.html#NF90_005fPUT_005fVAR1]

Sign up to request clarification or add additional context in comments.

Comments

1

The dimensions must be in the same order for the definition of the variable in the netcdf and in the declaration of the variable that you are saving.

The definition of the variable in the netcdf is right for what you want to achieve. So you should have VAR(o,t), and the order of indexes must change in the initialization of VAR. Since you want have the exact same value in each row of your matrix as seen by ncview, I advise you to initialize the fortran matrix as

var(:,1) = 5
var(:,2) = 2
var(:,3) = 8
var(:,4) = 9

This way, you are sure that everything is done right. Keep in mind that order of dimensions in fortran is not the same in ncview.

I assumed that (/ o, t /) in IERREU = nf90_def_var(ncid, "var", nf90_real, (/ o, t /), VarID) is only a typo, and that you actually have something like IERREU = nf90_def_var(ncid, "var", nf90_real, (/ oid, tid /), VarID) where oid and tid are result from a call to nf90_def_dim. You should edit your post if that is the case.

1 Comment

You are right, it is /oid, tid/ in my code. I have use the same values in my matrix VAR but it was only to illustrate my problem and simplify things.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.