This is a bit of a shot in the dark (I don't currently have easy access to a copy of IDL, hopefully that'll change in the next couple days) but this reminds me of when I forget to use free_lun when opening files in a loop. Could it be possible that IDL is storing the history of the modes (i.e. def and data) and simply runs out of reference space?
You might try using 'ncdf_control, cdfid, /sync' to update the file on the disk before you use 'ncdf_control, cdfid, /redef'. When I've made netcdf files in the past I've always defined everything before moving on to store the data, so I've never run into this sort of situation myself. I look forward to hearing Exelis' explaination.
Cheers,
Chip
On Thursday, November 15, 2012 5:57:17 PM UTC-5, neleh.mac wrote:
> So I am using IDL to read in ncdf data, and write out (to a new file) the processed data. So I go to define mode, set up the variable, add some attributes, switch to data mode, stick in the data, and then go back to define for the next one.
>
>
>
> e.g.
>
> ncid = ncdf_create(file_name, /CLOBBER)
>
> londim = ncdf_dimdef(ncid, 'longitude_dim', 144)
>
> latdim = ncdf_dimdef(ncid, 'latitude_dim', 91)
>
>
>
> vid = ncdf_vardef(ncid, 'emission', [londim,latdim], /float)
>
> ncdf_attput, ncid, vid, 'long_name', "Some emissions"
>
> ncdf_control, ncid, /ENDEF
>
> ncdf_varput, ncid, vid, emiss_dat
>
> ncdf_control, ncid, /REDEF
>
>
>
> vid = ncdf_vardef(ncid, 'emission2', [londim,latdim], /float)
>
> ncdf_attput, ncid, vid, 'long_name', "Some emissions 2"
>
> ncdf_control, ncid, /ENDEF
>
> ncdf_varput, ncid, vid, emiss_dat2
>
> ncdf_control, ncid, /REDEF
>
>
>
> ... etc.
>
>
>
> This works fine for several variables, over and over, until a certain point in the code and then at it will not get out of define mode. I commented out that particular part of the code where it was falling over, and got it to work fine (but my output file now has one less variable).
>
>
>
> Now the weird part.
>
>
>
> If I take the chunk of code for the variable that it falls at, and copy it back in further up the code, it works through it fine. It only fails when it gets to that line again, this time on a variable it wrote fine first time round.
>
>
>
> It's like it's failing after going into define mode a certain number of times, it's not specific to any variable I'm trying to write, it just always fails on the nth one, regardless of what it is. I've swopped round the order it writes them to the file, and they all get written, just not if they happen to be at a certain point in the order. I have tried removing attributes from the variables but this doesn't seem to have any effect. I am very confused by this, please can you help?
|