pro task40,iout ; itask=40 Generate a newair.json file for pure air with multiple cases based upon ; a template file. Calculate for two wavelength bands (300-700 nm), (700 - 5000 nm). ; This assumes that you can use the same surface reflectance values for all calculations ; This may not apply for Cox-Munk case where you need to read in separate surface file for each sensorzen case ; ****************************** ; Specify the template file (for one case) ; You read in the file and save each line. ; Then you write out to a new json file ; by changing several of the original lines ; Be sure to specify solar zenith angles(s) at this line below ; Need to specify the solar zenith angle(s) here !! ; To create a json file for Bruce put ibruce=1 ; The subdirectory (output for Steve) is not appended to the file path name) ibruce=0 ; ****************************** ; Write out to the new json file ; Note use of air at start of the output file pathname ; Note use of air in the output json file filenew='newair_steve_mlos.json' if (ibruce eq 1) then begin filenew='newair_bruce_mlos.json' endif printf,iout,' ' printf,iout,' task40: will write out to filenew ' printf,iout,' ',filenew ; Open the output json file idat=50 openw,idat,filenew ; ******* ; At the start of the json file wordstr1='{' wordstr2=' "MODTRAN": [' printf,idat,wordstr1 printf,idat,wordstr2 ; ******* ; Careful (do this at end of the 2nd calculation ; At the close of the json file wordstr3=' ]' wordstr4='}' ; ********************************************************** ; Loop over the 2 wavelength bands ; ncase is 0 based ncase=-1 ; nc is 1 based nc=0 for iband=0,1 do begin ; ****************************** ; For 300 to 700 nm if (iband eq 0) then begin ; Note that you cp this file from your desktop, deleted the first 2 lines, ; deleted the last two lines, and added a , to the last line finput='libera_300_700_onecase_air_mlos.json' nlines=96 wavestr='300700' endif if (iband eq 1) then begin ; Note that you cp this file from your desktop, deleted the first 2 lines, ; deleted the last two lines, and added a , to the last line finput='libera_700_5000_onecase_air_mlos.json' nlines=96 wavestr='7005000' endif print,' ' print,' iband ',iband print,' finput ',finput print,' nlines ',nlines printf,iout,' ' printf,iout,' task40: iband ',iband printf,iout,' task40: finput ',finput printf,iout,' task40: nlines ',nlines ; ****************************** ; Specify the character strings datastrinput=strarr(nlines) datastrnew=strarr(nlines) linedat=strarr(1) ; ****************************** ; Read in the file idat2=60 openr,idat2,finput ; Special write ; This allows you to specify line numbers for which you can ; alter the json line specifics for each calculation iwrsp=1 if (iwrsp eq 1) then begin printf,iout,' ' printf,iout,' task40: i,datastrinput(i)' endif ; Read in the nlines lines for i=0,nlines-1 do begin readf,idat2,linedat ; input datastrinput(i)=linedat ; will change below datastrnew(i)=linedat if (iwrsp eq 1) then begin printf,iout,i,' ',datastrinput(i) endif endfor ; Close the input file close,idat2 ; stop ; ****************************** ; Specify the calculations to do icalc=1 if (icalc eq 1) then begin ; specify the output directory that the MODTRAN6 output files go to foutputdir='\\\\lasp-store\\home\\massiest\\Documents\\MODTRAN6\\output\\' ilinedir=2 ; the case ilinecase=4 ; specify the number of streams nstrstr='16' ilinenstr=12 ; The template will have 9 NLOS sensorzen values ; So you do not specify sensorzen here ; PARM1 ; solar azimuth ilinesunaz=26 ; PARM2 ; solar zenith angle ilinesunsza=27 ; 79 "V1": 440.0, ; 80 "V2": 1700.0, ; 81 "DV": 5.0, ; 82 "FWHM": 5.0, if (iband eq 0) then begin v1str='300.0' endif if (iband eq 1) then begin v1str='700.0' endif ilinev1=79 if (iband eq 0) then begin v2str='700.0' endif if (iband eq 1) then begin v2str='5000.0' endif ilinev2=80 dvstr='5.0' ilinedv=81 if (iband eq 0) then begin fwhmstr='5.0' endif if (iband eq 1) then begin fwhmstr='40.0' endif ilinefwhm=82 ; 95 }, lastlinestr='}' ilastline=95 ; ******* ; Specify the cases to work with ; Will loop over solar zenith angle ; You can specify nsolarzen=8 and do all solar zenith angles ; Should take about 12 hours or so to do all calculations nsolarzen=8 solarzen=fltarr(nsolarzen) ; Need to specify the solar zenith angle(s) here !! solarzen=[15.0, 25.0, 35.0, 45.0, 55.0, 65.0, 75.0, 85.0] ; Will loop over solar azimuth nrelaz=18 relaz=fltarr(nrelaz) for i=0,nrelaz-1 do begin relaz(i)=0.0+(20.0*i) endfor print,'relaz ',relaz ; ******* endif ; icalc=1 ; ******* ; Will note when you have the last case ; Will compare nlast to nc nlast=0 for m1=0,nsolarzen-1 do begin for m3=0,nrelaz-1 do begin nlast=nlast+1 endfor endfor ; Since you have 2 bands, double nlast nlast=(nlast*2) print,' total number of cases ',nlast printf,iout,' ' printf,iout,' task40: total number of cases ',nlast ; stop ; ******* ; Loop over cases ; Cases go from 0 to nlast for m1=0,nsolarzen-1 do begin solarzenstr=strcompress(string(solarzen(m1))) for m3=0,nrelaz-1 do begin relazstr=strcompress(string(relaz(m3))) ; ****** ; Specify datastrnew again for each case for i=0,nlines-1 do begin datastrnew(i)=datastrinput(i) endfor ; ****** ; Output directory str1=strcompress(string(fix(solarzen(m1)))) noprd=0 task10delete,noprd,iout,str1 str3=strcompress(string(fix(relaz(m3)))) task10delete,noprd,iout,str3 ; Note use of air at start of the output file pathname str4=strcompress('air'+wavestr+'solarzen'+str1+'solaraz'+str3) filestr=strcompress(foutputdir+str4) if (ibruce eq 1) then begin filestr=strcompress(str4) endif ; printf,iout,' ' ; printf,iout,str1 ; printf,iout,filestr ; ****** ; Modify various lines ; Be sure the number of first blank spaces is correct ; Case ncase=ncase+1 nc=nc+1 casestr=strcompress(string(fix(ncase))) ; printf,iout,casestr ; stop ; ****** ; Write out to the new file ; '1' strblank1=' ' ; '1234' strblank4=' ' ; '1234567' strblank7=' ' ; '12345678' strblank8=' ' ; '12345678901' strblank11=' ' ; '123456789012' strblank12=' ' strp='"' strc=':' strcomma=',' ; ****** ; The output directory datastrnew(ilinedir)=string(strblank8+strp+'NAME'+strp+strc+strblank1+strp+filestr+strp+strcomma) ; The case ; "CASE": 0, datastrnew(ilinecase)=string(strblank8+strp+'CASE'+strp+strc+casestr+strcomma) ; The number of streams ; "NSTR": 4, datastrnew(ilinenstr)=string(strblank11+strp+'NSTR'+strp+strc+nstrstr+strcomma) ; **** ; Solar azimuth ; "PARM1": 70.0, datastrnew(ilinesunaz)=string(strblank11+strp+'PARM1'+strp+strc+relazstr+strcomma) ; Solar zenith angle ; "PARM2": 30.0, datastrnew(ilinesunsza)=string(strblank11+strp+'PARM2'+strp+strc+solarzenstr+strcomma) ; **** ; The lower wavelength in nm ; "V1": 440.0, ; datastrnew(ilinev1)=string(strblank11+strp+'V1'+strp+strc+v1str+strcomma) ; The upper wavelength in nm ; "V2": 1700.0, ; datastrnew(ilinev2)=string(strblank11+strp+'V2'+strp+strc+v2str+strcomma) ; The output is in dv (hmmmm, MODTRAN6 has a mind of its own, whatever). ; "DV": 5.0, datastrnew(ilinedv)=string(strblank11+strp+'DV'+strp+strc+dvstr+strcomma) ; fwhm of traiangular filter function ; "FWHM": 5.0, datastrnew(ilinefwhm)=string(strblank11+strp+'FWHM'+strp+strc+fwhmstr+strcomma) ; **** ; Last line (does not have a comma) if ((nc eq nlast) and (iband eq 1)) then begin datastrnew(ilastline)=string(strblank4+lastlinestr) print,' last case, do not add comma' endif ; ****** ; Write out to the new json file for i=0,nlines-1 do begin printf,idat,datastrnew(i) endfor ; ****** endfor ; loop over nrelaz (solar azimuth) endfor ; loop over nsolarzen (solar zenith) endfor ; Loop over the iband=0,1 wavelength bands ; ****************************** ; At the end of the new json file printf,idat,wordstr3 printf,idat,wordstr4 ; ****************************** ntotal=ncase+1 printf,iout,' ' printf,iout,' task40: the json files has ntotal ',ntotal printf,iout,' task40: cases, labeled case=0,1,2,..ntotal-1 ' printf,iout,' task40: should be equal to nc ',nc ; Close the output file print,filenew close,idat printf,iout,' ' printf,iout,' task40: wrote out to filenew ' printf,iout,' ',filenew ; ****************************** return end