Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I want to write the data of a 3D variable calculated by Fortran routines into a NetCDF file. I have written the code to write the variable data but it is creating an empty NetCDF file after the execution.

stat = NF90_CREATE( '/home/sachin/output.nc', NF90_CLOBBER, ncid_user)
stat = NF90_DEF_DIM( ncid_user, i, NF90_UNLIMITED, i_id )
stat = NF90_DEF_DIM( ncid_user, j, NF90_UNLIMITED, j_id )
stat = NF90_DEF_DIM( ncid_user, k, NF90_UNLIMITED, k_id )
    e_id=(/i_id,j_id,k_id/)     
stat = NF90_DEF_VAR( ncid_user, ene, NF90_INT, e_id, ev_id )
stat1 = NF90_OPEN('/home/sachin/output.nc', NF90_WRITE, ncid_user)
stat1 = NF90_PUT_VAR(ncid_user, ev_id, start = (/ 1,1,1 /), count = (/ 10,10,0 /), stride = (/ 10,10,0 /) )

When I am printing stat1 variable, it is printing -51 as the return value of the NF90_PUT_VAR function.

You can use the NF90_STRERROR routine to translate an error code into a more useful string. In this case, -51 means "Unknown File Format" – chw21 Dec 19, 2016 at 23:08 But here's what I'm wondering: Are you closing the file before re-opening it again? I can't see that from your snippet. – chw21 Dec 19, 2016 at 23:08 Heaps of problems here. Which value of stat1 are you referring to? Also the call to NF90_PUT_VAR is incorrect. There's no values array in the call. Further, you have defined your file to be in netCDF classic format. You can't have multiple unlimited dimensions in that format. Please check all your status values like Mark says above. Writing a short error handling routine will help immensely. – RussF Dec 20, 2016 at 0:31 Sir, up to NF90_DEF_VAR function call it is executing correctly, Since I am printing stat values and it is giving output 0 (zero). But I am unable to execute my NF90_PUT_VAR(ncid_user,ev_id,e) function correctly. – Sachin Shinde Dec 21, 2016 at 5:09

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.