Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error "foreach: Too many arguments." when too many files to be linked #150

Open
IncubatorShokuhou opened this issue Apr 23, 2020 · 0 comments

Comments

@IncubatorShokuhou
Copy link

I met foreach: Too many arguments. while trying to link a whole year of fnl data using link_grib.csh. It seems that there are too many files (according to https://www.experts-exchange.com/questions/10210401/foreach-limit.html).

I simply rewrite the link_grib.csh with python, which has exactly the same usage as link_grib.csh.

#! /usr/bin/python
import sys,glob,os
def link_grib_file(filelist):
    n = 0
    for ifile in filelist:
        if ( ifile != "."):
            file_suffix = file_alphabet(n)
            os.symlink(ifile, "GRIBFILE."+file_suffix)
            n+=1
def file_alphabet(number):
    alpha=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
    if number >= 26*26*26:
        print("RAN OUT OF GRIB FILE SUFFIXES!")
        exit()
    else:
        i1=number%26
        i2=(number-i1)//26%26
        i3=(number-i2*26-i1)//26//26%26
        return alpha[i3]+alpha[i2]+alpha[i1]
if __name__ == "__main__":
    varlist = sys.argv[1:]
    if (len(varlist)==1) or (len(varlist)==2 and varlist[1]=='.'):
        os.system("rm -f GRIBFILE.???")
        filelist=glob.glob(varlist[0])
        link_grib_file(filelist)
    elif (len(varlist)>1):
        os.system("rm -f GRIBFILE.???")
        filelist=varlist
        link_grib_file(filelist)
    elif (len(varlist)==0):
        print(" " ) 
        print(" " ) 
        print("   Please provide some GRIB data to link") 
        print("   usage: ./link_grib.py path_to_grib_data/grib_data_root") 
        print(" " ) 
        print(" " ) 

I'm wondering if it is helpful.
PS. It seems that the python code is about ten times faster than csh (maybe due to using os.symlink instead of ln -sf)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant