Loading netCDF files

Hi all,

I am trying to load netcdf files from a folder by using the code below. I want to load them one by one as I want to derive different results from each one. I use a string to add the filename at the end of the loadnc string. Then I execute loadnc to load the file:

variable m
newpath/O NC_Path, "C:Data:RadarData:camra21jan09:UniServer:"
string filenames=IndexedFile(NC_Path,-1,".nc")
variable num_of_files=itemsinlist(filenames)

For (m=0;m<num_of_files;m+=1)
string file_to_proc_name =stringfromlist(m, filenames)
string loadnc="Load_NetCDF /P=NC_Path " + file_to_proc_name
execute loadnc
Endfor


If I write
Load_NetCDF /P=NC_Path file_to_proc_name
in the command window it makes it, but when I use the execute command in the code I get an error.

Could anyone help?

For debugging, I recommend that you replace "execute loadnc" with "Print loadnc".

Quote:

but when I use the execute command in the code I get an error.


"An error" is too vague.
It is always very helpful to include a reproducible example to help illustrate the issues.

I think the problem in your case is missing quotation marks. I also think your variable/string declarations were done from the command window which makes them global, otherwise the string file_to_proc_name would not be found from the working command you gave.

Here are some functions to illustrate some of the various ways of constructing a Load command. The LoadTest4() example is similar to your problem. I assume these translate to Load_NetCDF.
Note: this makes a file in your 'My Documents' folder. You will want to delete this once you have finished playing - the function CleanUp() will do this.

Function MakeData()
    // makes a file with some data
    // make a new path
    string sMyPath
    sMyPath =SpecialDirPath("Documents", 0, 0, 0)
    NewPath/Q/O MyPath SpecialDirPath("Documents", 0, 0, 0)
    // make some data
    Make/O/D/N=(10) wData
    wData[] = enoise(10)
    // make a global with the filename
    string/G gsFileName = "MyTestWaveData.ibw"
    // save data
    Save/O/P=MyPath wData as gsFileName
    // remove the data
    KillWaves wData
end

Function LoadTest1() // this works
    SVAR gsFileName
    LoadWave/P=MyPath gsFileName
End

Function LoadTest2() // this works
    SVAR gsFileName
    PathInfo MyPath
    LoadWave S_path + gsFileName
End

Function LoadTest3() // this works
    SVAR gsFileName
    string sCmd
    sCmd = "LoadWave/P=MyPath \"" + gsFileName + "\""
    Execute sCmd
End

Function LoadTest4() // this function fails
    SVAR gsFileName
    string sCmd
    sCmd = "LoadWave/P=MyPath " + gsFileName
    Execute sCmd
End

Function CleanUp()
    // remove file and path
    SVAR gsFileName
    DeleteFile/P=MyPath gsFileName
    KillWaves/Z wData
    KillPath MyPath
End

You will need to Kill the wave wData between running each LoadTest function.

Hope this helps
Kurt